[asterisk-commits] russell: branch group/http_mods r60262 -
/team/group/http_mods/main/http.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Apr 5 08:38:57 MST 2007
Author: russell
Date: Thu Apr 5 10:38:57 2007
New Revision: 60262
URL: http://svn.digium.com/view/asterisk?view=rev&rev=60262
Log:
Update http.c mods to the current minimime API
Modified:
team/group/http_mods/main/http.c
Modified: team/group/http_mods/main/http.c
URL: http://svn.digium.com/view/asterisk/team/group/http_mods/main/http.c?view=diff&rev=60262&r1=60261&r2=60262
==============================================================================
--- team/group/http_mods/main/http.c (original)
+++ team/group/http_mods/main/http.c Thu Apr 5 10:38:57 2007
@@ -319,45 +319,16 @@
return NULL;
}
-static int get_mimepart_header(struct mm_mimepart *part, const char *header,
- char *hdr_buf, size_t hdr_buf_len)
-{
- const char *body;
- const char *val_begin, *val_end;
- size_t copy_len;
-
- if (!(body = mm_mimepart_getbody(part, 1))) {
- ast_log(LOG_DEBUG, "Can't get message part body\n");
+static int get_filename(struct mm_mimepart *part, char *fn, size_t fn_len)
+{
+ const char *filename;
+
+ filename = mm_content_getdispositionparambyname(part->type, "filename");
+
+ if (ast_strlen_zero(filename))
return -1;
- }
-
- if (!(val_begin = strcasestr(body, header))) {
- ast_log(LOG_DEBUG, "Can't find the header %s in the opaque body\n", header);
- return -1;
- }
- val_begin += strlen(header);
- val_begin = ast_skip_blanks(val_begin);
-
- if (!(val_end = strstr(val_begin, "\r\n"))) {
- ast_log(LOG_DEBUG, "Can't find the end of the %s header\n", header);
- return -1;
- }
-
- copy_len = val_end - val_begin + 1;
- if (copy_len > hdr_buf_len)
- copy_len = hdr_buf_len;
-
- ast_copy_string(hdr_buf, val_begin, copy_len);
-
- return 0;
-}
-
-static int get_filename(struct mm_mimepart *part, char *fn, size_t fn_len)
-{
- if (ast_strlen_zero(part->filename))
- return -1;
-
- ast_copy_string(fn, part->filename, fn_len);
+
+ ast_copy_string(fn, filename, fn_len);
return 0;
}
@@ -370,6 +341,8 @@
size_t body_len;
snprintf(filename, sizeof(filename), "%s/%s", post_dir, fn);
+
+ ast_log(LOG_DEBUG, "Posting raw data to %s\n", filename);
if (!(f = fopen(filename, "w"))) {
ast_log(LOG_WARNING, "Unable to open %s for writing file from a POST!\n", filename);
@@ -382,7 +355,7 @@
return;
}
body_len = mm_mimepart_getlength(part);
- ast_log(LOG_DEBUG, "Body length is %d\n", body_len);
+ ast_log(LOG_DEBUG, "Body length is %ld\n", body_len);
fwrite(body, 1, body_len, f);
@@ -403,20 +376,21 @@
const char *post_dir;
ast_log(LOG_DEBUG, "uri: %s\n", uri);
+
*status = 404;
*title = ast_strdup("Not Found");
+ /* XXX Switch to a random temp file */
if (!(f = fopen("/tmp/ast_postdata", "w")))
return ast_http_error(404, "Not Found", NULL, "The requested URL was not found on this server.");
for (var = headers; var; var = var->next) {
- ast_log(LOG_DEBUG, "Name: %s Value: %s\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");
return ast_http_error(404, "Not Found", NULL, "The requested URL was not found on this server.");
}
- ast_log(LOG_DEBUG, "Got Content-Length of %d\n", content_len);
+ ast_log(LOG_DEBUG, "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);
}
@@ -461,27 +435,29 @@
if (mm_context_iscomposite(ctx))
ast_log(LOG_DEBUG, "Found %d MIME parts\n", mm_res - 1);
else
- ast_log(LOG_DEBUG, "We have a flag (not multi-part) message\n");
+ ast_log(LOG_DEBUG, "We have a flat (not multi-part) message\n");
for (i = 1; i < mm_res; i++) {
struct mm_mimepart *part;
char fn[PATH_MAX];
- char content_type[1024];
if (!(part = mm_context_getpart(ctx, i))) {
ast_log(LOG_DEBUG, "Failed to get mime part num %d\n", i);
continue;
}
- if (get_filename(part, fn, sizeof(fn)))
+ if (get_filename(part, fn, sizeof(fn))) {
+ ast_log(LOG_DEBUG, "Failed to retrieve a filename for part num %d\n", i);
continue;
- if (get_mimepart_header(part, "Content-Type:", content_type, sizeof(content_type)))
+ }
+
+ if (!part->type) {
+ ast_log(LOG_DEBUG, "This part has no content struct?\n");
continue;
-
- if (!strcasecmp(content_type, "application/octet-stream"))
- post_raw(part, post_dir, fn);
- else
- ast_log(LOG_WARNING, "Don't know how to handle Content-Type '%s'\n", content_type);
+ }
+
+ /* XXX This assumes the MIME part body is not encoded! */
+ post_raw(part, post_dir, fn);
}
mm_context_free(ctx);
@@ -585,7 +561,6 @@
time_t t;
if (fgets(buf, sizeof(buf), ser->f)) {
- ast_log(LOG_DEBUG, "Read line (1): %s\n", buf);
/* Skip method */
uri = buf;
while(*uri && (*uri > 32))
@@ -609,7 +584,6 @@
}
while (fgets(cookie, sizeof(cookie), ser->f)) {
- ast_log(LOG_DEBUG, "Read line (2): %s\n", cookie);
/* Trim trailing characters */
while(!ast_strlen_zero(cookie) && (cookie[strlen(cookie) - 1] < 33)) {
cookie[strlen(cookie) - 1] = '\0';
@@ -666,8 +640,6 @@
} else {
char *name, *value;
- ast_log(LOG_DEBUG, "Other Header: %s\n", cookie);
-
value = ast_strdupa(cookie);
name = strsep(&value, ":");
if (!value)
More information about the asterisk-commits
mailing list