Fix mime parsing by re-adding support for passing headers to callback functions
authorTerry Wilson <twilson@digium.com>
Fri, 1 Aug 2008 21:56:07 +0000 (21:56 +0000)
committerTerry Wilson <twilson@digium.com>
Fri, 1 Aug 2008 21:56:07 +0000 (21:56 +0000)
git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@135235 65c4cc65-6c06-0410-ace0-fbb531ad65f3

main/http.c
res/res_http_post.c

index e6256b3..bb6ae61 100644 (file)
@@ -657,6 +657,7 @@ static void *httpd_helper_thread(void *data)
        int status = 200, contentlength = 0;
        struct ast_str *out = NULL;
        unsigned int static_content = 0;
+       struct ast_variable *tail = headers;
 
        if (!fgets(buf, sizeof(buf), ser->f)) {
                goto done;
@@ -686,6 +687,24 @@ static void *httpd_helper_thread(void *data)
                }
                if (!strncasecmp(cookie, "Cookie: ", 8)) {
                        vars = parse_cookies(cookie);
+               } else {
+                       char *name, *val;
+
+                       val = cookie;
+                       name = strsep(&val, ":");
+                       if (ast_strlen_zero(name) || ast_strlen_zero(val)) {
+                               continue;
+                       }
+                       ast_trim_blanks(name);
+                       val = ast_skip_blanks(val);
+
+                       if (!headers) {
+                               headers = ast_variable_new(name, val, __FILE__);
+                               tail = headers;
+                       } else {
+                               tail->next = ast_variable_new(name, val, __FILE__);
+                               tail = tail->next;
+                       }
                }
        }
 
index d065365..f1ae7a7 100644 (file)
@@ -203,6 +203,8 @@ static struct ast_str *http_post_callback(struct ast_tcptls_session_instance *se
        }
 
        for (var = headers; var; var = var->next) {
+               fprintf(f, "%s: %s\r\n", var->name, var->value);
+
                if (!strcasecmp(var->name, "Content-Length")) {
                        if ((sscanf(var->value, "%u", &content_len)) != 1) {
                                ast_log(LOG_ERROR, "Invalid Content-Length in POST request!\n");
@@ -211,11 +213,11 @@ static struct ast_str *http_post_callback(struct ast_tcptls_session_instance *se
                                return NULL;
                        }
                        ast_debug(1, "Got a Content-Length of %d\n", content_len);
-               } else if (!strcasecmp(var->name, "Content-Type")) {
-                       fprintf(f, "Content-Type: %s\r\n\r\n", var->value);
                }
        }
 
+       fprintf(f, "\r\n");
+
        for (res = sizeof(buf); content_len; content_len -= res) {
                if (content_len < res) {
                        res = content_len;