From 7967dcc45f38b45d86a343d50f371fcbbf9b00f2 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Fri, 8 Apr 2005 10:29:08 +0000 Subject: [PATCH] Minor fixes to mmbox code, more mm7 --- mbuni/mmlib/mms_mm7soap.c | 132 ++++++++++++++++++++++++++++++++++++-- mbuni/mmlib/mms_mm7soap.h | 13 ++-- mbuni/mmlib/mms_msg.c | 24 ++++++- mbuni/mmsc/mmsproxy.c | 8 ++- 4 files changed, 163 insertions(+), 14 deletions(-) diff --git a/mbuni/mmlib/mms_mm7soap.c b/mbuni/mmlib/mms_mm7soap.c index 3def890..f3eaf4a 100644 --- a/mbuni/mmlib/mms_mm7soap.c +++ b/mbuni/mmlib/mms_mm7soap.c @@ -6,6 +6,7 @@ #define content(n) ((n)->xmlChildrenNode ? dfltstr(((n)->xmlChildrenNode)->content) : dfltstr((n)->content)) + static Octstr *parse_time(char *s) { time_t t = time(NULL); @@ -187,20 +188,81 @@ static int parse_headers(xmlNodePtr start, List *h, int sigparent) return 0; } -List *parse_soapmsg(Octstr *xml) +MSoapMsg_t *mm7_parse_soap(List *headers, Octstr *body) { - xmlDocPtr doc = xmlParseMemory(octstr_get_cstr(xml), octstr_len(xml)); + MIMEEntity *mime = mime_http_to_entity(headers, body); + Octstr *xml = NULL, *cloc; + xmlDocPtr doc; + MmsMsg *msg = NULL; List *h; - int s = -1; - if (!doc || !doc->xmlChildrenNode) + int s = -1; + MSoapMsg_t *smsg = NULL; + + if (!mime) return NULL; + /* Find the start element: + * - either the mime entity is multipart and has start param ... + * - or entity is multipart and start element is (implicitly) first element + * - or entity is not multipart, so body is xml + */ + + if (mime->start) + xml = mime->start->body; + else if (mime->multiparts && list_len(mime->multiparts) > 0) { + MIMEEntity *x = list_get(mime->multiparts,0); + xml = x->body; + } else + xml = mime->body; + + if (!xml) + goto done; + + doc = xmlParseMemory(octstr_get_cstr(xml), octstr_len(xml)); + if (!doc || !doc->xmlChildrenNode) + goto done; h = http_create_empty_headers(); parse_headers(doc->xmlChildrenNode, h, s); + xmlFreeDoc(doc); - /* Free the doc! */ - return h; + if (!h) + goto done; + + cloc = http_header_value(h, octstr_imm("Content")); + + if (cloc) { + /* XXXX only support content that is inline. easy to add external. */ + MIMEEntity *c = NULL; + int i, n; + char *loc = octstr_get_cstr(cloc) + 4; /* skip 'cid:' part. */ + for (i = 0, n = list_len(mime->multiparts); imultiparts, i); + Octstr *y = x ? http_header_value(x->headers, octstr_imm("Content-ID")) : NULL; + + if (y && octstr_str_compare(y, loc) == 0) + c = x; + + if (y) + octstr_destroy(y); + if (c) + break; + } + if (c) + msg = mms_frommime(c); + + octstr_destroy(cloc); + } + smsg = gw_malloc(sizeof *smsg); + smsg->envelope = h; + smsg->msg = msg; + + done: + if (mime) + mime_entity_destroy(mime); + if (xml) + octstr_destroy(xml); + return smsg; } static void output_rcpt(char *hdr, List *hdrs, Octstr *p) @@ -413,3 +475,61 @@ Octstr *headers_to_soapxml(List *hdrs) return s; } + +int mm7_soapmsg_to_httpmsg(MSoapMsg_t *m, List **hdrs, Octstr **body) +{ + MIMEEntity *mime; + Octstr *ctype; + + mime = mime_entity_create(); + + if (m->msg) { + MIMEEntity *c = mms_tomime(m->msg); + Octstr *cloc = octstr_format("cid:", + time(NULL), random(), + 'A' + random() % 26, + 'a' + random() % 26); + Octstr *envloc = octstr_format("", + time(NULL), random(), + 'A' + random() % 26, + 'a' + random() % 26); + MIMEEntity *xml = mime_entity_create(); + List *hh = http_header_duplicate(m->envelope); + + /* Replace in envelope. */ + http_header_remove_all(hh, "Content-ID"); + http_header_add(hh, "Content-ID", octstr_get_cstr(cloc)); + + /* Replace content location in msg part. */ + http_header_remove_all(c->headers, "Content-ID"); + http_header_add(c->headers, "Content-ID", octstr_get_cstr(cloc) + 4); + + http_header_add(xml->headers, "Content-Type", "text/xml; charset=\"utf-8\""); + http_header_add(xml->headers, "Content-ID", octstr_get_cstr(envloc)); + xml->body = headers_to_soapxml(hh); + + list_append(mime->multiparts, xml); + list_append(mime->multiparts, c); + + http_destroy_headers(hh); + + ctype = octstr_format("multipart/related; start=\"%S\"; type=text/xml", + envloc); + + octstr_destroy(envloc); + octstr_destroy(cloc); + } else { + ctype = octstr_imm("text/xml; charset=\"utf-8\""); + mime->body = headers_to_soapxml(m->envelope); + } + + http_header_add(mime->headers, "Content-Type", octstr_get_cstr(ctype)); + http_header_add(mime->headers, "SOAPAction", "\"\""); + + *hdrs = mime_entity_headers(mime); + *body = mime_entity_body(mime); + + mime_entity_destroy(mime); + + return 0; +} diff --git a/mbuni/mmlib/mms_mm7soap.h b/mbuni/mmlib/mms_mm7soap.h index 3ce07e6..e80ac70 100644 --- a/mbuni/mmlib/mms_mm7soap.h +++ b/mbuni/mmlib/mms_mm7soap.h @@ -1,10 +1,15 @@ #ifndef __MMS_MM7SOAP_INCLUDED__ #define __MMS_MM7SOAP_INCLUDED__ #include "mms_util.h" -typedef struct Mm7Soap_t *Mm7Soap_t; -extern Mm7Soap_t *mms_mm7soap_from_mime(Octstr *text); +typedef struct MSoapMsg_t { + List *envelope; /* of http headers. */ + MmsMsg *msg; +} MSoapMsg_t; + +extern MSoapMsg_t *mm7_parse_soap(List *headers, Octstr *body); +extern int mm7_soapmsg_to_httpmsg(MSoapMsg_t *m, List **hdrs, Octstr **body); + +extern MmsMsg *mm7_soapmsg_to_mmsmsg(MSoapMsg_t *m); -extern List *parse_soapmsg(Octstr *xml); -extern Octstr *headers_to_soapxml(List *hdrs); #endif diff --git a/mbuni/mmlib/mms_msg.c b/mbuni/mmlib/mms_msg.c index 0c5a600..c041f2b 100644 --- a/mbuni/mmlib/mms_msg.c +++ b/mbuni/mmlib/mms_msg.c @@ -985,7 +985,8 @@ static int fixup_msg(MmsMsg *m, Octstr *from) else if (octstr_str_compare(ver, "1.2") <= 0) m->enc = MS_1_2; - if (m->message_type == MMS_MSGTYPE_SEND_REQ) { + if (m->message_type == MMS_MSGTYPE_SEND_REQ || + m->message_type == MMS_MSGTYPE_RETRIEVE_CONF) { Octstr *s = NULL; /* Check for from. */ @@ -1002,6 +1003,12 @@ static int fixup_msg(MmsMsg *m, Octstr *from) octstr_destroy(t); } else octstr_destroy(s); + + /* Check for msgid, put in if missing. */ + if ((s = http_header_value(m->headers, octstr_imm("MessageID"))) == NULL) + http_header_add(m->headers, "MessageID", "00000"); + else + octstr_destroy(s); } @@ -1713,7 +1720,7 @@ static int mms_convert_to_mboxdescr(MmsMsg *mm, Octstr *cloc, List *reqhdrs, int i, n; List *mh, *xh; Octstr *xstate; - int addcontent = 0; + int addcontent = 0, hasmsgid = 0; if (!mm) return -1; @@ -1724,6 +1731,7 @@ static int mms_convert_to_mboxdescr(MmsMsg *mm, Octstr *cloc, List *reqhdrs, http_header_add(mh, "X-Mms-Message-Type", "m-mbox-descr"); http_header_add(mh, "X-Mms-MMS-Version", "1.2"); + http_header_add(mh, "X-Mms-Content-Location", octstr_get_cstr(cloc)); /* Add only those headers requested. */ for (i = 0, n = list_len(reqhdrs); i < n; i++) { @@ -1740,7 +1748,8 @@ static int mms_convert_to_mboxdescr(MmsMsg *mm, Octstr *cloc, List *reqhdrs, sprintf(yy, "%lu", msize); http_header_add(mh, "X-Mms-Message-Size", yy); goto loop; - } + } else if (octstr_case_compare(header, octstr_imm("Message-ID")) == 0) + hasmsgid = 1; for (j = 0; j < list_len(h); j++) { Octstr *hname, *value; @@ -1757,6 +1766,15 @@ static int mms_convert_to_mboxdescr(MmsMsg *mm, Octstr *cloc, List *reqhdrs, /* We ignore the extra attributes request. */ } + if (!hasmsgid) { + Octstr *v = http_header_value(mm->headers, octstr_imm("Message-ID")); + if (v) { + http_header_add(mh, "Message-ID", + octstr_get_cstr(v)); + octstr_destroy(v); + } + } + /* Copy over the MM-State and MM-flags headers. */ xh = http_header_find_all(mm->headers, "X-Mms-MM-Flags"); if (xh) { diff --git a/mbuni/mmsc/mmsproxy.c b/mbuni/mmsc/mmsproxy.c index 0399301..0ad78df 100644 --- a/mbuni/mmsc/mmsproxy.c +++ b/mbuni/mmsc/mmsproxy.c @@ -1264,6 +1264,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) if (sdf) octstr_destroy(sdf); + reply_body = mms_tobinary(mresp); notify_cmd = "uploaded"; } @@ -1350,6 +1351,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) if (otransid) octstr_destroy(otransid); + reply_body = mms_tobinary(mresp); notify_cmd = "deleted"; } @@ -1469,7 +1471,6 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) mms_ua_maxmsgsize(h->prof), MS_1_2, otherhdrs); - reply_body = mms_tobinary(mresp); notify_cmd = "deleted"; @@ -1517,6 +1518,11 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) done: +#if 1 + if (mresp) + mms_msgdump(mresp, 0); +#endif + if (mresp) mms_destroy(mresp); if (!ctype_set)