|
|
|
@ -2801,6 +2801,34 @@ const char *astman_get_header(const struct message *m, char *var)
|
|
|
|
|
return __astman_get_header(m, var, GET_HEADER_FIRST_MATCH);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Append additional headers into the message structure from params.
|
|
|
|
|
*
|
|
|
|
|
* \note You likely want to initialize m->hdrcount to 0 before calling this.
|
|
|
|
|
*/
|
|
|
|
|
static void astman_append_headers(struct message *m, const struct ast_variable *params)
|
|
|
|
|
{
|
|
|
|
|
const struct ast_variable *v;
|
|
|
|
|
|
|
|
|
|
for (v = params; v && m->hdrcount < ARRAY_LEN(m->headers); v = v->next) {
|
|
|
|
|
if (ast_asprintf((char**)&m->headers[m->hdrcount], "%s: %s", v->name, v->value) > -1) {
|
|
|
|
|
++m->hdrcount;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \brief Free headers inside message structure, but not the message structure itself.
|
|
|
|
|
*/
|
|
|
|
|
static void astman_free_headers(struct message *m)
|
|
|
|
|
{
|
|
|
|
|
while (m->hdrcount) {
|
|
|
|
|
--m->hdrcount;
|
|
|
|
|
ast_free((void *) m->headers[m->hdrcount]);
|
|
|
|
|
m->headers[m->hdrcount] = NULL;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/*!
|
|
|
|
|
* \internal
|
|
|
|
|
* \brief Process one "Variable:" header value string.
|
|
|
|
@ -6649,7 +6677,6 @@ static int do_message(struct mansession *s)
|
|
|
|
|
struct message m = { 0 };
|
|
|
|
|
char header_buf[sizeof(s->session->inbuf)] = { '\0' };
|
|
|
|
|
int res;
|
|
|
|
|
int idx;
|
|
|
|
|
int hdr_loss;
|
|
|
|
|
time_t now;
|
|
|
|
|
|
|
|
|
@ -6717,10 +6744,8 @@ static int do_message(struct mansession *s)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free AMI request headers. */
|
|
|
|
|
for (idx = 0; idx < m.hdrcount; ++idx) {
|
|
|
|
|
ast_free((void *) m.headers[idx]);
|
|
|
|
|
}
|
|
|
|
|
astman_free_headers(&m);
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -7714,13 +7739,10 @@ static int generic_http_callback(struct ast_tcptls_session_instance *ser,
|
|
|
|
|
uint32_t ident;
|
|
|
|
|
int fd;
|
|
|
|
|
int blastaway = 0;
|
|
|
|
|
struct ast_variable *v;
|
|
|
|
|
struct ast_variable *params = get_params;
|
|
|
|
|
char template[] = "/tmp/ast-http-XXXXXX"; /* template for temporary file */
|
|
|
|
|
struct ast_str *http_header = NULL, *out = NULL;
|
|
|
|
|
struct message m = { 0 };
|
|
|
|
|
unsigned int idx;
|
|
|
|
|
size_t hdrlen;
|
|
|
|
|
|
|
|
|
|
if (method != AST_HTTP_GET && method != AST_HTTP_HEAD && method != AST_HTTP_POST) {
|
|
|
|
|
ast_http_error(ser, 501, "Not Implemented", "Attempt to use unimplemented / unsupported method");
|
|
|
|
@ -7803,17 +7825,7 @@ static int generic_http_callback(struct ast_tcptls_session_instance *ser,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (v = params; v && m.hdrcount < ARRAY_LEN(m.headers); v = v->next) {
|
|
|
|
|
hdrlen = strlen(v->name) + strlen(v->value) + 3;
|
|
|
|
|
m.headers[m.hdrcount] = ast_malloc(hdrlen);
|
|
|
|
|
if (!m.headers[m.hdrcount]) {
|
|
|
|
|
/* Allocation failure */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
snprintf((char *) m.headers[m.hdrcount], hdrlen, "%s: %s", v->name, v->value);
|
|
|
|
|
ast_debug(1, "HTTP Manager add header %s\n", m.headers[m.hdrcount]);
|
|
|
|
|
++m.hdrcount;
|
|
|
|
|
}
|
|
|
|
|
astman_append_headers(&m, params);
|
|
|
|
|
|
|
|
|
|
if (process_message(&s, &m)) {
|
|
|
|
|
if (session->authenticated) {
|
|
|
|
@ -7828,11 +7840,7 @@ static int generic_http_callback(struct ast_tcptls_session_instance *ser,
|
|
|
|
|
session->needdestroy = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free request headers. */
|
|
|
|
|
for (idx = 0; idx < m.hdrcount; ++idx) {
|
|
|
|
|
ast_free((void *) m.headers[idx]);
|
|
|
|
|
m.headers[idx] = NULL;
|
|
|
|
|
}
|
|
|
|
|
astman_free_headers(&m);
|
|
|
|
|
|
|
|
|
|
ast_str_append(&http_header, 0,
|
|
|
|
|
"Content-type: text/%s\r\n"
|
|
|
|
@ -7943,8 +7951,6 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
|
|
|
|
|
struct ast_str *http_header = NULL, *out = NULL;
|
|
|
|
|
size_t result_size;
|
|
|
|
|
struct message m = { 0 };
|
|
|
|
|
unsigned int idx;
|
|
|
|
|
size_t hdrlen;
|
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
|
|
time_t time_now = time(NULL);
|
|
|
|
@ -8167,17 +8173,7 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for (v = params; v && m.hdrcount < ARRAY_LEN(m.headers); v = v->next) {
|
|
|
|
|
hdrlen = strlen(v->name) + strlen(v->value) + 3;
|
|
|
|
|
m.headers[m.hdrcount] = ast_malloc(hdrlen);
|
|
|
|
|
if (!m.headers[m.hdrcount]) {
|
|
|
|
|
/* Allocation failure */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
snprintf((char *) m.headers[m.hdrcount], hdrlen, "%s: %s", v->name, v->value);
|
|
|
|
|
ast_verb(4, "HTTP Manager add header %s\n", m.headers[m.hdrcount]);
|
|
|
|
|
++m.hdrcount;
|
|
|
|
|
}
|
|
|
|
|
astman_append_headers(&m, params);
|
|
|
|
|
|
|
|
|
|
if (process_message(&s, &m)) {
|
|
|
|
|
if (u_displayconnects) {
|
|
|
|
@ -8187,11 +8183,7 @@ static int auth_http_callback(struct ast_tcptls_session_instance *ser,
|
|
|
|
|
session->needdestroy = 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Free request headers. */
|
|
|
|
|
for (idx = 0; idx < m.hdrcount; ++idx) {
|
|
|
|
|
ast_free((void *) m.headers[idx]);
|
|
|
|
|
m.headers[idx] = NULL;
|
|
|
|
|
}
|
|
|
|
|
astman_free_headers(&m);
|
|
|
|
|
|
|
|
|
|
result_size = lseek(ast_iostream_get_fd(s.stream), 0, SEEK_CUR); /* Calculate approx. size of result */
|
|
|
|
|
|
|
|
|
|