|
|
|
@ -514,7 +514,7 @@ void base64_mimeparts(MIMEEntity *m, int all)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static void addmmscname(Octstr *s, Octstr *myhostname)
|
|
|
|
|
void addmmscname(Octstr *s, char *myhostname)
|
|
|
|
|
{
|
|
|
|
|
int j;
|
|
|
|
|
int len = octstr_len(s);
|
|
|
|
@ -524,7 +524,7 @@ static void addmmscname(Octstr *s, Octstr *myhostname)
|
|
|
|
|
|
|
|
|
|
j = octstr_case_search(s, octstr_imm("/TYPE=PLMN"), 0);
|
|
|
|
|
if (j > 0 && j - 1 + sizeof "/TYPE=PLMN" == len) /* A proper number. */
|
|
|
|
|
octstr_format_append(s, "@%S", myhostname);
|
|
|
|
|
octstr_format_append(s, "@%s", myhostname);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
@ -554,7 +554,7 @@ static int send2email(List *xto, Octstr *from, Octstr *subject,
|
|
|
|
|
List *lcc = http_header_find_all(headers, "Cc");
|
|
|
|
|
|
|
|
|
|
if (xfrom) {
|
|
|
|
|
addmmscname(xfrom, myhostname);
|
|
|
|
|
addmmscname(xfrom, octstr_get_cstr(myhostname));
|
|
|
|
|
http_header_add(l, "From", octstr_get_cstr(xfrom));
|
|
|
|
|
octstr_destroy(xfrom);
|
|
|
|
|
}
|
|
|
|
@ -569,7 +569,7 @@ static int send2email(List *xto, Octstr *from, Octstr *subject,
|
|
|
|
|
octstr_case_compare(name, octstr_imm("To")) != 0)
|
|
|
|
|
goto loop;
|
|
|
|
|
|
|
|
|
|
addmmscname(value, myhostname);
|
|
|
|
|
addmmscname(value, octstr_get_cstr(myhostname));
|
|
|
|
|
http_header_add(l, "To", octstr_get_cstr(value));
|
|
|
|
|
loop:
|
|
|
|
|
octstr_destroy(value);
|
|
|
|
@ -588,7 +588,7 @@ static int send2email(List *xto, Octstr *from, Octstr *subject,
|
|
|
|
|
octstr_case_compare(name, octstr_imm("Cc")) != 0)
|
|
|
|
|
goto loop2;
|
|
|
|
|
|
|
|
|
|
addmmscname(value, myhostname);
|
|
|
|
|
addmmscname(value, octstr_get_cstr(myhostname));
|
|
|
|
|
http_header_add(l, "Cc", octstr_get_cstr(value));
|
|
|
|
|
loop2:
|
|
|
|
|
octstr_destroy(value);
|
|
|
|
@ -643,7 +643,7 @@ static int send2email(List *xto, Octstr *from, Octstr *subject,
|
|
|
|
|
case 'f':
|
|
|
|
|
if (append_hostname) {
|
|
|
|
|
Octstr *xfrom = octstr_duplicate(from);
|
|
|
|
|
addmmscname(xfrom, myhostname);
|
|
|
|
|
addmmscname(xfrom, octstr_get_cstr(myhostname));
|
|
|
|
|
escape_shell_chars(xfrom);
|
|
|
|
|
|
|
|
|
|
octstr_append(cmd, xfrom);
|
|
|
|
@ -757,7 +757,7 @@ static int smtp_send(char *relay_host, int port, Octstr *from, List *to, Octstr
|
|
|
|
|
if (code != (val) && !(cont)) \
|
|
|
|
|
goto done; \
|
|
|
|
|
} while (0) \
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SANDC("HELO %s\r\n", tbuf, 250,0);
|
|
|
|
|
SANDC("MAIL FROM:<%S>\r\n", from, 250,0);
|
|
|
|
|
|
|
|
|
@ -2677,3 +2677,484 @@ done:
|
|
|
|
|
octstr_destroy(q);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* little dirty method to see if file begins with url scheme. */
|
|
|
|
|
static int has_url_scheme(char *url, int *supported_scheme)
|
|
|
|
|
{
|
|
|
|
|
char *p = strstr(url, "://");
|
|
|
|
|
|
|
|
|
|
*supported_scheme = 1;
|
|
|
|
|
|
|
|
|
|
if (strstr(url, "data:") == url || /* data: url scheme */
|
|
|
|
|
strstr(url, "http://") == url ||
|
|
|
|
|
#ifdef HAVE_LIBSSL
|
|
|
|
|
strstr(url, "https://") == url ||
|
|
|
|
|
#endif
|
|
|
|
|
strstr(url, "file://") == url)
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
if (p) {
|
|
|
|
|
|
|
|
|
|
for (p--; p >= url; p--)
|
|
|
|
|
if (!isalpha(*p))
|
|
|
|
|
break;
|
|
|
|
|
if (p < url) {
|
|
|
|
|
*supported_scheme = 0; /* we don't support this one. */
|
|
|
|
|
return 1;
|
|
|
|
|
} else
|
|
|
|
|
return 0;
|
|
|
|
|
} else
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int add_msg_part(MIMEEntity *res, xmlNodePtr node, Octstr *base_url,
|
|
|
|
|
Octstr *top_url,
|
|
|
|
|
int type, Octstr *svc_name,
|
|
|
|
|
Octstr *mmc_id,
|
|
|
|
|
Dict *url_map, Octstr *xmhdr, Octstr *xmhdr_val,
|
|
|
|
|
int (*filter)(MIMEEntity **msg, Octstr *loc_url, Octstr *mmc_id))
|
|
|
|
|
{
|
|
|
|
|
Octstr *curl = NULL, *ctype = NULL, *body = NULL, *xcid = NULL;
|
|
|
|
|
char *src = NULL;
|
|
|
|
|
int isurl, slash_prefix;
|
|
|
|
|
Octstr *cid = NULL;
|
|
|
|
|
int supported_url_scheme = 0;
|
|
|
|
|
|
|
|
|
|
/* For each node in the smil doc, if it has an src attribute, then:
|
|
|
|
|
* - if our type of base_url is FILE *and the src attribute does not look
|
|
|
|
|
* like a url, then file the file referenced, load it into the message and go
|
|
|
|
|
* - if our type is URL and the url scheme is http/https (or has no scheme)
|
|
|
|
|
* then fetch it and put into message.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
if (!node || node->type != XML_ELEMENT_NODE ||
|
|
|
|
|
(src = (char *)xmlGetProp(node, (unsigned char *)"src")) == NULL)
|
|
|
|
|
return 0; /* Nothing to do. */
|
|
|
|
|
|
|
|
|
|
if (src[0] == '\\') { /* User can escape url to prevent substitution. */
|
|
|
|
|
xmlSetProp(node, (xmlChar *)"src", (xmlChar *)(src + 1));
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isurl = has_url_scheme(src, &supported_url_scheme);
|
|
|
|
|
slash_prefix = (src[0] == '/');
|
|
|
|
|
|
|
|
|
|
if (isurl && !supported_url_scheme)
|
|
|
|
|
goto done;
|
|
|
|
|
else if (isurl)
|
|
|
|
|
curl = octstr_create(src);
|
|
|
|
|
else if (slash_prefix) {
|
|
|
|
|
if (type == URL_TYPE)
|
|
|
|
|
curl = octstr_format("%S%s",
|
|
|
|
|
top_url, src);
|
|
|
|
|
else
|
|
|
|
|
curl = octstr_create(src);
|
|
|
|
|
} else
|
|
|
|
|
curl = octstr_format("%S/%s",base_url, src);
|
|
|
|
|
|
|
|
|
|
if ((cid = dict_get(url_map, curl)) != NULL) { /* We've seen it before. */
|
|
|
|
|
xmlSetProp(node, (xmlChar *)"src", (xmlChar *)octstr_get_cstr(cid));
|
|
|
|
|
/* Don't delete cid! */
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isurl |= (type == URL_TYPE); /* From now on, this flag tells us whether we are fetching a url.*/
|
|
|
|
|
|
|
|
|
|
if (isurl) {
|
|
|
|
|
List *rh = http_create_empty_headers(), *rph = NULL;
|
|
|
|
|
|
|
|
|
|
http_header_add(rh, "User-Agent", MM_NAME "/" VERSION);
|
|
|
|
|
if (mms_url_fetch_content(HTTP_METHOD_GET, curl, rh, NULL, &rph, &body) == HTTP_OK) {
|
|
|
|
|
ctype = http_header_value(rph, octstr_imm("Content-Type"));
|
|
|
|
|
xcid = http_header_value(rph, octstr_imm("Content-ID"));
|
|
|
|
|
} else
|
|
|
|
|
mms_error(0, "mmsbox", NULL, "Failed to load url %s within SMIL content from service %s!",
|
|
|
|
|
octstr_get_cstr(curl),
|
|
|
|
|
svc_name ? octstr_get_cstr(svc_name) : "unknown");
|
|
|
|
|
if (rph)
|
|
|
|
|
http_destroy_headers(rph);
|
|
|
|
|
http_destroy_headers(rh);
|
|
|
|
|
} else {
|
|
|
|
|
body = octstr_read_file(octstr_get_cstr(curl));
|
|
|
|
|
ctype = filename2content_type(src);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ctype && body) { /* If we got it, put it in. */
|
|
|
|
|
static int cntr; /* For generating cids */
|
|
|
|
|
char _fext[5] = {0}, *fext = make_file_ext(curl, ctype, _fext);
|
|
|
|
|
Octstr *attr = xcid ? octstr_format("cid:%S", xcid) : octstr_format("cid:%06d.%s", ++cntr,fext);
|
|
|
|
|
char *p = octstr_get_cstr(attr) + 4;
|
|
|
|
|
Octstr *cid_header_val = octstr_format("<%s>", p);
|
|
|
|
|
MIMEEntity *x = mime_entity_create();
|
|
|
|
|
List *headers = http_create_empty_headers();
|
|
|
|
|
|
|
|
|
|
http_header_add(headers, "Content-Type", octstr_get_cstr(ctype));
|
|
|
|
|
http_header_add(headers, "Content-ID", octstr_get_cstr(cid_header_val));
|
|
|
|
|
http_header_add(headers, "Content-Location", p);
|
|
|
|
|
|
|
|
|
|
if (xmhdr)
|
|
|
|
|
http_header_add(headers, octstr_get_cstr(xmhdr), octstr_get_cstr(xmhdr_val));
|
|
|
|
|
|
|
|
|
|
mime_replace_headers(x, headers);
|
|
|
|
|
mime_entity_set_body(x, body);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (filter && mmc_id)
|
|
|
|
|
filter(&x, curl, mmc_id);
|
|
|
|
|
|
|
|
|
|
mime_entity_add_part(res, x);
|
|
|
|
|
mime_entity_destroy(x);
|
|
|
|
|
|
|
|
|
|
dict_put_once(url_map, curl, octstr_duplicate(attr)); /* Store the cid. */
|
|
|
|
|
|
|
|
|
|
xmlSetProp(node, (xmlChar *)"src", (xmlChar *)octstr_get_cstr(attr));
|
|
|
|
|
|
|
|
|
|
octstr_destroy(attr);
|
|
|
|
|
octstr_destroy(cid_header_val);
|
|
|
|
|
http_destroy_headers(headers);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
|
|
|
|
|
octstr_destroy(curl);
|
|
|
|
|
octstr_destroy(ctype);
|
|
|
|
|
octstr_destroy(body);
|
|
|
|
|
octstr_destroy(xcid);
|
|
|
|
|
xmlFree(src);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Traverse the tree doing the above. */
|
|
|
|
|
static void add_msg_parts(MIMEEntity *res, xmlNodePtr node, Octstr *base_url,
|
|
|
|
|
Octstr *top_url,
|
|
|
|
|
int type, Octstr *svc_name,
|
|
|
|
|
Octstr *mmc_id,
|
|
|
|
|
Dict *url_map, Octstr *xmhdr, Octstr *xmhdr_val,
|
|
|
|
|
int (*filter)(MIMEEntity **msg, Octstr *loc_url, Octstr *mmc_id))
|
|
|
|
|
{
|
|
|
|
|
xmlNodePtr n;
|
|
|
|
|
/* Do all the children recursively, then come back and do parent. */
|
|
|
|
|
for (n = node; n; n = n->next)
|
|
|
|
|
if (n->type != XML_COMMENT_NODE) {
|
|
|
|
|
add_msg_part(res, n, base_url, top_url, type, svc_name, mmc_id, url_map, xmhdr,
|
|
|
|
|
xmhdr_val, filter);
|
|
|
|
|
add_msg_parts(res, n->xmlChildrenNode, base_url, top_url, type,
|
|
|
|
|
svc_name, mmc_id, url_map, xmhdr, xmhdr_val, filter);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
/* Get's just the host:port part, leaving out UrI */
|
|
|
|
|
static Octstr *get_toplevel_url(Octstr *url)
|
|
|
|
|
{
|
|
|
|
|
int i, len = octstr_len(url);
|
|
|
|
|
char *p = octstr_get_cstr(url);
|
|
|
|
|
|
|
|
|
|
i = octstr_search(url, octstr_imm("://"),0);
|
|
|
|
|
|
|
|
|
|
if (i > 0)
|
|
|
|
|
i += 3;
|
|
|
|
|
else
|
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
|
|
for ( ; i < len; i++)
|
|
|
|
|
if (p[i] == '/')
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
return octstr_copy(url, 0, i);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static Octstr *url_path_prefix(Octstr *url, int type)
|
|
|
|
|
{
|
|
|
|
|
int i, j, len = octstr_len(url);
|
|
|
|
|
char *p = octstr_get_cstr(url);
|
|
|
|
|
|
|
|
|
|
/* Set lower/upper limit of search. */
|
|
|
|
|
if (type == URL_TYPE) { /* then skip first slashes. */
|
|
|
|
|
char *x;
|
|
|
|
|
i = octstr_search(url, octstr_imm("://"),0);
|
|
|
|
|
if (i > 0)
|
|
|
|
|
i += 3;
|
|
|
|
|
else
|
|
|
|
|
i = 0;
|
|
|
|
|
x = rindex(p, '#'); /* look for fragment if any. */
|
|
|
|
|
|
|
|
|
|
if (x)
|
|
|
|
|
j = x - p - 1;
|
|
|
|
|
else
|
|
|
|
|
j = len - 1;
|
|
|
|
|
} else {
|
|
|
|
|
i = 0;
|
|
|
|
|
j = len - 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Now search backwards for the last '/'.
|
|
|
|
|
* if you don't find one, set to end of string.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
for (;j > i; j--)
|
|
|
|
|
if (p[j] == '/')
|
|
|
|
|
break;
|
|
|
|
|
if (j <= i)
|
|
|
|
|
j = len;
|
|
|
|
|
|
|
|
|
|
return octstr_copy(url, 0, j);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void get_content_from_sendmms_request(Octstr *body, List *headers, List *cgivars, List *cgivar_ctypes,
|
|
|
|
|
List **rh, Octstr **ctype, Octstr **data,
|
|
|
|
|
Octstr **rb,
|
|
|
|
|
Octstr **base_url, Octstr **data_url)
|
|
|
|
|
{
|
|
|
|
|
Octstr *s;
|
|
|
|
|
/* Now get the data. */
|
|
|
|
|
if ((*data = http_cgi_variable(cgivars, "text")) != NULL) { /* text. */
|
|
|
|
|
Octstr *charset = http_cgi_variable(cgivars, "charset");
|
|
|
|
|
|
|
|
|
|
*ctype = octstr_format("text/plain");
|
|
|
|
|
if (charset)
|
|
|
|
|
octstr_format_append(*ctype, "; charset=%S", charset);
|
|
|
|
|
} else if ((s = http_cgi_variable(cgivars, "smil")) != NULL) { /* smil. */
|
|
|
|
|
*ctype = octstr_create("application/smil");
|
|
|
|
|
*data = octstr_duplicate(s);
|
|
|
|
|
} else if ((s = http_cgi_variable(cgivars, "content-url")) != NULL) { /* arbitrary content. */
|
|
|
|
|
List *reqh = http_create_empty_headers(), *rph = NULL;
|
|
|
|
|
Octstr *reply = NULL, *params = NULL;
|
|
|
|
|
|
|
|
|
|
http_header_add(reqh, "User-Agent", MM_NAME "/" VERSION);
|
|
|
|
|
|
|
|
|
|
if (mms_url_fetch_content(HTTP_METHOD_GET, s, reqh, NULL, &rph, &reply) == HTTP_OK)
|
|
|
|
|
get_content_type(rph, ctype, ¶ms);
|
|
|
|
|
else
|
|
|
|
|
*rb = octstr_format("failed to fetch content from url [%S]!", s);
|
|
|
|
|
*base_url = url_path_prefix(s, URL_TYPE);
|
|
|
|
|
|
|
|
|
|
*data_url = octstr_duplicate(s); /* the URL of the message. */
|
|
|
|
|
*data = reply;
|
|
|
|
|
|
|
|
|
|
http_destroy_headers(reqh);
|
|
|
|
|
http_destroy_headers(*rh);
|
|
|
|
|
*rh = rph ? rph : http_create_empty_headers(); /* replace as real reply headers. */
|
|
|
|
|
*ctype = http_header_value(*rh, octstr_imm("Content-Type"));
|
|
|
|
|
octstr_destroy(params);
|
|
|
|
|
} else if ((s = http_cgi_variable(cgivars, "content")) != NULL) { /* any content. */
|
|
|
|
|
Octstr *_xctype = NULL; /* ... because cgi var stuff is destroyed elsewhere, we must dup it !! */
|
|
|
|
|
|
|
|
|
|
*data = octstr_duplicate(s);
|
|
|
|
|
/* If the user sent us a content element, then they should have
|
|
|
|
|
* sent us its type either as part of the HTTP POST (multipart/form-data)
|
|
|
|
|
* or as CGI VAR called content_type
|
|
|
|
|
*/
|
|
|
|
|
if ((_xctype = http_cgi_variable(cgivars, "content_type")) == NULL)
|
|
|
|
|
if (cgivar_ctypes)
|
|
|
|
|
_xctype = http_cgi_variable(cgivar_ctypes, "content");
|
|
|
|
|
if (_xctype)
|
|
|
|
|
*ctype = octstr_duplicate(_xctype);
|
|
|
|
|
else
|
|
|
|
|
*ctype = octstr_create("application/octet-stream");
|
|
|
|
|
} else if (body) { /* if all above fails,
|
|
|
|
|
use send-mms msg body if any. */
|
|
|
|
|
*data = octstr_duplicate(body);
|
|
|
|
|
*ctype = http_header_value(headers, octstr_imm("Content-Type"));
|
|
|
|
|
} else
|
|
|
|
|
*rb = octstr_create("Missing content");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MmsMsg *make_msg_from_sendmms_request(Octstr *from, List *to,
|
|
|
|
|
Octstr *msgId,
|
|
|
|
|
Octstr *subject,
|
|
|
|
|
Octstr *data, Octstr *ctype,
|
|
|
|
|
List *reply_headers,
|
|
|
|
|
Octstr *msg_url,
|
|
|
|
|
Octstr *base_url, int type,
|
|
|
|
|
Octstr *mmc,
|
|
|
|
|
Octstr *svc_name,
|
|
|
|
|
time_t expiryt,
|
|
|
|
|
int do_multipart,
|
|
|
|
|
int do_rr,
|
|
|
|
|
int do_dlr,
|
|
|
|
|
char *allow_adaptations,
|
|
|
|
|
int (*filter)(MIMEEntity **msg, Octstr *loc_url, Octstr *mmc_id),
|
|
|
|
|
Octstr **err)
|
|
|
|
|
{
|
|
|
|
|
Octstr *mclass = http_header_value(reply_headers, octstr_imm("X-Mbuni-MessageClass"));
|
|
|
|
|
Octstr *prio = http_header_value(reply_headers, octstr_imm("X-Mbuni-Priority"));
|
|
|
|
|
Octstr *turl = get_toplevel_url(base_url);
|
|
|
|
|
MmsMsg *m = NULL;
|
|
|
|
|
MIMEEntity *me = mime_entity_create();
|
|
|
|
|
Octstr *xmhdr = NULL, *xmhdr_val = NULL;
|
|
|
|
|
List *xheaders = NULL;
|
|
|
|
|
int i, n;
|
|
|
|
|
|
|
|
|
|
if (octstr_str_case_compare(ctype, "application/vnd.wap.mms-message") == 0)
|
|
|
|
|
m = mms_frombinary(data, from);
|
|
|
|
|
else if (octstr_case_search(ctype, octstr_imm("multipart/"), 0) == 0) { /* treat it differently. */
|
|
|
|
|
MIMEEntity *mime = mime_http_to_entity(reply_headers, data);
|
|
|
|
|
if (mime) {
|
|
|
|
|
mime_entity_destroy(me);
|
|
|
|
|
me = mime;
|
|
|
|
|
}
|
|
|
|
|
} else if (octstr_case_search(ctype,
|
|
|
|
|
octstr_imm(MBUNI_MULTIPART_TYPE), 0) == 0) { /* Mbuni multipart.*/
|
|
|
|
|
List *l = octstr_split_words(data);
|
|
|
|
|
MIMEEntity *mime = multipart_from_urls(l);
|
|
|
|
|
|
|
|
|
|
if (mime) {
|
|
|
|
|
mime_entity_destroy(me);
|
|
|
|
|
me = mime;
|
|
|
|
|
}
|
|
|
|
|
gwlist_destroy(l, (void *)octstr_destroy);
|
|
|
|
|
} else if (octstr_case_search(ctype, octstr_imm("application/smil"), 0) == 0) {
|
|
|
|
|
xmlDocPtr smil;
|
|
|
|
|
xmlChar *buf = NULL;
|
|
|
|
|
int bsize = 0;
|
|
|
|
|
Dict *url_map = dict_create(97, (void (*)(void *))octstr_destroy);
|
|
|
|
|
List *xh = http_create_empty_headers();
|
|
|
|
|
|
|
|
|
|
/* This is the hard bit: Fetch each external reference in smil, add it to message! */
|
|
|
|
|
http_header_add(xh, "Content-Type", "multipart/related; "
|
|
|
|
|
"type=\"application/smil\"; start=\"<presentation>\"");
|
|
|
|
|
mime_replace_headers(me,xh);
|
|
|
|
|
http_destroy_headers(xh);
|
|
|
|
|
|
|
|
|
|
/* Parse the smil as XML. */
|
|
|
|
|
smil = xmlParseMemory(octstr_get_cstr(data), octstr_len(data));
|
|
|
|
|
if (!smil || !smil->xmlChildrenNode) {
|
|
|
|
|
*err = octstr_format("MMSBox: Error parsing SMIL response from service[%s], "
|
|
|
|
|
" msgid %s!", octstr_get_cstr(svc_name),
|
|
|
|
|
msgId ? octstr_get_cstr(msgId) : "(none)");
|
|
|
|
|
dict_destroy(url_map);
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
add_msg_parts(me, smil->xmlChildrenNode,
|
|
|
|
|
base_url, turl, type, svc_name,
|
|
|
|
|
mmc, url_map, xmhdr, xmhdr_val,
|
|
|
|
|
filter);
|
|
|
|
|
|
|
|
|
|
dict_destroy(url_map);
|
|
|
|
|
/* SMIL has been modified, convert it to text, put it in. */
|
|
|
|
|
xmlDocDumpFormatMemory(smil, &buf, &bsize, 1);
|
|
|
|
|
xmlFreeDoc(smil);
|
|
|
|
|
if (buf) {
|
|
|
|
|
MIMEEntity *sm = mime_entity_create();
|
|
|
|
|
List *xh = http_create_empty_headers();
|
|
|
|
|
Octstr *s;
|
|
|
|
|
|
|
|
|
|
http_header_add(xh, "Content-Type", "application/smil");
|
|
|
|
|
http_header_add(xh, "Content-ID", "<presentation>"); /* identify it as start element. */
|
|
|
|
|
if (xmhdr)
|
|
|
|
|
http_header_add(xh, octstr_get_cstr(xmhdr), octstr_get_cstr(xmhdr_val));
|
|
|
|
|
s = octstr_create_from_data((char *)buf, bsize);
|
|
|
|
|
|
|
|
|
|
mime_replace_headers(sm, xh);
|
|
|
|
|
mime_entity_set_body(sm, s);
|
|
|
|
|
|
|
|
|
|
mime_entity_add_part(me, sm);
|
|
|
|
|
|
|
|
|
|
mime_entity_destroy(sm);
|
|
|
|
|
http_destroy_headers(xh);
|
|
|
|
|
octstr_destroy(s);
|
|
|
|
|
|
|
|
|
|
xmlFree(buf);
|
|
|
|
|
} else {
|
|
|
|
|
*err = octstr_format("MMSBox: Error writing converted SMIL "
|
|
|
|
|
"for response from service[%s], "
|
|
|
|
|
" msgid %s!",
|
|
|
|
|
octstr_get_cstr(svc_name),
|
|
|
|
|
(msgId) ? octstr_get_cstr(msgId) : "(none)");
|
|
|
|
|
goto done;
|
|
|
|
|
}
|
|
|
|
|
} else { /* all others, make the message as-is and hope for the best! */
|
|
|
|
|
List *xh = http_create_empty_headers();
|
|
|
|
|
|
|
|
|
|
if (do_multipart) { /* if it's going to be multi-part, add some headers. */
|
|
|
|
|
static int cntr = 0;
|
|
|
|
|
char _fext[5] = {0}, *fext = make_file_ext(msg_url, ctype, _fext);
|
|
|
|
|
Octstr *attr = octstr_format("%06d.%s", ++cntr,fext);
|
|
|
|
|
Octstr *cid_header_val = octstr_format("<%S>", attr);
|
|
|
|
|
|
|
|
|
|
http_header_add(xh, "Content-ID", octstr_get_cstr(cid_header_val));
|
|
|
|
|
http_header_add(xh, "Content-Location", octstr_get_cstr(attr));
|
|
|
|
|
|
|
|
|
|
octstr_destroy(attr);
|
|
|
|
|
octstr_destroy(cid_header_val);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
http_header_add(xh, "Content-Type", octstr_get_cstr(ctype));
|
|
|
|
|
if (xmhdr)
|
|
|
|
|
http_header_add(xh, octstr_get_cstr(xmhdr), octstr_get_cstr(xmhdr_val));
|
|
|
|
|
|
|
|
|
|
mime_replace_headers(me, xh);
|
|
|
|
|
|
|
|
|
|
http_destroy_headers(xh);
|
|
|
|
|
mime_entity_set_body(me, data);
|
|
|
|
|
|
|
|
|
|
if (filter && mmc) /* filter it too. */
|
|
|
|
|
filter(&me, msg_url, mmc);
|
|
|
|
|
|
|
|
|
|
if (do_multipart &&
|
|
|
|
|
octstr_case_search(ctype, octstr_imm("multipart/"), 0) != 0) { /* requires multipart but this one is not, wrap it */
|
|
|
|
|
MIMEEntity *xm = mime_entity_create();
|
|
|
|
|
List *h1 = http_create_empty_headers();
|
|
|
|
|
|
|
|
|
|
http_header_add(h1, "Content-Type", "multipart/related");
|
|
|
|
|
mime_replace_headers(xm, h1);
|
|
|
|
|
mime_entity_add_part(xm, me);
|
|
|
|
|
|
|
|
|
|
http_destroy_headers(h1);
|
|
|
|
|
|
|
|
|
|
me = xm;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Add some nice headers. */
|
|
|
|
|
xheaders = mime_entity_headers(me);
|
|
|
|
|
http_header_add(xheaders, "From", octstr_get_cstr(from));
|
|
|
|
|
|
|
|
|
|
for (i = 0, n = gwlist_len(to); i < n; i++) {
|
|
|
|
|
Octstr *v;
|
|
|
|
|
v = gwlist_get(to, i);
|
|
|
|
|
http_header_add(xheaders, "To", octstr_get_cstr(v));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (do_dlr)
|
|
|
|
|
http_header_add(xheaders, "X-Mms-Delivery-Report", "Yes");
|
|
|
|
|
if (do_rr)
|
|
|
|
|
http_header_add(xheaders, "X-Mms-Read-Report", "Yes");
|
|
|
|
|
if (allow_adaptations)
|
|
|
|
|
http_header_add(xheaders, "X-Mms-Allow-Adaptations",
|
|
|
|
|
(strcasecmp(allow_adaptations, "true") == 0) ? "true" : "false");
|
|
|
|
|
|
|
|
|
|
if (mclass)
|
|
|
|
|
http_header_add(xheaders, "X-Mms-Message-Class", octstr_get_cstr(mclass));
|
|
|
|
|
|
|
|
|
|
if (prio)
|
|
|
|
|
http_header_add(xheaders, "X-Mms-Priority", octstr_get_cstr(prio));
|
|
|
|
|
|
|
|
|
|
if (subject)
|
|
|
|
|
http_header_add(xheaders, "Subject", octstr_get_cstr(subject));
|
|
|
|
|
|
|
|
|
|
if (expiryt > 0) {
|
|
|
|
|
Octstr *x = date_format_http(expiryt);
|
|
|
|
|
http_header_add(xheaders, "X-Mms-Expiry", octstr_get_cstr(x));
|
|
|
|
|
octstr_destroy(x);
|
|
|
|
|
}
|
|
|
|
|
mime_replace_headers(me, xheaders);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (me && !m) /* Set m if it hasn't been set yet. */
|
|
|
|
|
m = mms_frommime(me);
|
|
|
|
|
if (!m)
|
|
|
|
|
*err = octstr_format("MMSBox: Failed to convert Mms Message from service %s!",
|
|
|
|
|
octstr_get_cstr(svc_name));
|
|
|
|
|
|
|
|
|
|
done:
|
|
|
|
|
octstr_destroy(mclass);
|
|
|
|
|
octstr_destroy(prio);
|
|
|
|
|
if (me)
|
|
|
|
|
mime_entity_destroy(me);
|
|
|
|
|
octstr_destroy(xmhdr_val);
|
|
|
|
|
octstr_destroy(turl);
|
|
|
|
|
http_destroy_headers(xheaders);
|
|
|
|
|
return m;
|
|
|
|
|
}
|
|
|
|
|