diff --git a/mbuni/doc/examples/mmsbox.conf b/mbuni/doc/examples/mmsbox.conf index 7a99d02..647766b 100644 --- a/mbuni/doc/examples/mmsbox.conf +++ b/mbuni/doc/examples/mmsbox.conf @@ -1,10 +1,10 @@ group = core -log-file = /tmp/log/mbuni-mmmsbox.log -access-log = /tmp/log/mmsbox-access.log +log-file = /var/log/mmsbox.log +access-log = /var/log/mmsbox-access.log log-level = 0 group = mbuni -storage-directory = /tmp/spool +storage-directory = /var/spool/mbuni max-send-threads = 5 maximum-send-attempts = 50 default-message-expiry = 360000 @@ -34,7 +34,7 @@ service-code = regular group = mms-service name = fullmessage -get-url = http://localhost/~bagyenda/images/apache_pb.gif +get-url = http://localhost/images/apache_pb.gif # http-post-parameters = fx=true&image=%i&text=%t accept-x-mbuni-headers = true keyword = thixs diff --git a/mbuni/mmlib/mms_mm7soap.h b/mbuni/mmlib/mms_mm7soap.h index 3073d02..205dc46 100644 --- a/mbuni/mmlib/mms_mm7soap.h +++ b/mbuni/mmlib/mms_mm7soap.h @@ -18,7 +18,7 @@ #define MM7_SOAP_FORMAT_CORRUPT 2007 #define MM7_SOAP_COMMAND_REJECTED 3005 #define MM7_SOAP_UNSUPPORTED_OPERATION 4003 -#define MM7_SOAP_STATUS_OK(e) ((e) / 1000 == 1) +#define MM7_SOAP_STATUS_OK(e) (((e) / 1000) == 1) #if 0 #define MM7_DEFAULT_VERSION MMS_3GPP_VERSION diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index af73943..cbd0a30 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -1195,6 +1195,50 @@ void strip_boundary_element(List *headers, char *s) octstr_destroy(value); } + +/* Mapping file extensions to content types. */ +static struct { + char *ctype, *file_ext; +} exts[] = { + {"text/plain", "txt"}, + {"image/jpeg", "jpg"}, + {"image/jpeg", "jpeg"}, + {"image/png", "png"}, + {"image/tiff", "tiff"}, + {"image/gif", "gif"}, + {"image/bmp", "bmp"}, + {"image/vnd.wap.wbmp", "wbmp"}, + {"image/x-bmp", "bmp"}, + {"image/x-wmf", "bmp"}, + {"image/vnd.wap.wpng", "png"}, + {"image/x-up-wpng", "png"}, + {"audio/mpeg", "mp3"}, + {"audio/wav", "wav"}, + {"audio/x-wav", "wav"}, + {"audio/basic", "au"}, + {"audio/amr", "amr"}, + {"audio/x-amr", "amr"}, + {"audio/amr-wb", "amr"}, + {"audio/midi", "mid"}, + {"audio/sp-midi", "mid"}, + {"application/smil", "smil"}, + {"application/vnd.wap.mms-message", "mms"}, + {NULL, NULL} +}; + +Octstr *filename2content_type(char *fname) +{ + char *p = strrchr(fname, '.'); + int i; + + if (p) + for (i = 0; exts[i].file_ext; i++) + if (strcasecmp(p+1, exts[i].file_ext) == 0) + return octstr_imm(exts[i].ctype); + + return octstr_imm("application/octet-stream"); +} + static int fetch_url_with_auth(HTTPCaller *c, int method, Octstr *url, List *request_headers, Octstr *body, Octstr *auth_hdr, List **reply_headers, Octstr **reply_body); @@ -1253,6 +1297,17 @@ int mms_url_fetch_content(int method, Octstr *url, List *request_headers, octstr_destroy(ctype); status = HTTP_OK; + } else if (octstr_search(url, octstr_imm("file://"), 0) == 0) { + char *file = octstr_get_cstr(url) + 6; + Octstr *ctype = filename2content_type(file); + Octstr *data = octstr_read_file(file); + + *reply_body = data; + *reply_headers = http_create_empty_headers(); + http_header_add(*reply_headers, "Content-Type", octstr_get_cstr(ctype)); + + status = data ? HTTP_OK : HTTP_NOT_FOUND; + octstr_destroy(ctype); } else { HTTPCaller *c = http_caller_create(); http_start_request(c, method, url, request_headers, body, 1, NULL, NULL); diff --git a/mbuni/mmlib/mms_util.h b/mbuni/mmlib/mms_util.h index 81bfafb..747d3c8 100644 --- a/mbuni/mmlib/mms_util.h +++ b/mbuni/mmlib/mms_util.h @@ -180,6 +180,9 @@ int mms_url_fetch_content(int method, Octstr *url, List *request_headers, /* check that the token is valid. */ int mms_is_token(Octstr *token); + +/* try to guess content type from file name extension. */ +Octstr *filename2content_type(char *fname); #define MAXQTRIES 100 #define BACKOFF_FACTOR 5*60 /* In seconds */ #define QUEUERUN_INTERVAL 1*60 /* 1 minutes. */ diff --git a/mbuni/mmsbox/mmsbox.c b/mbuni/mmsbox/mmsbox.c index c02893f..1398724 100644 --- a/mbuni/mmsbox/mmsbox.c +++ b/mbuni/mmsbox/mmsbox.c @@ -287,7 +287,7 @@ done: enum _xurltype {FILE_TYPE, URL_TYPE}; static Octstr *url_path_prefix(Octstr *url, int type); -static Octstr *filename2content_type(char *fname); + static int make_and_queue_msg(Octstr *data, Octstr *ctype, List *reply_headers, Octstr *base_url, int type, MmsEnvelope *e, Octstr *svc_name, Octstr *faked_sender, Octstr *service_code, @@ -574,48 +574,6 @@ int main(int argc, char *argv[]) } -/* Mapping file extensions to content types. */ -static struct { - char *ctype, *file_ext; -} exts[] = { - {"text/plain", "txt"}, - {"image/jpeg", "jpg"}, - {"image/jpeg", "jpeg"}, - {"image/png", "png"}, - {"image/tiff", "tiff"}, - {"image/gif", "gif"}, - {"image/bmp", "bmp"}, - {"image/vnd.wap.wbmp", "wbmp"}, - {"image/x-bmp", "bmp"}, - {"image/x-wmf", "bmp"}, - {"image/vnd.wap.wpng", "png"}, - {"image/x-up-wpng", "png"}, - {"audio/mpeg", "mp3"}, - {"audio/wav", "wav"}, - {"audio/x-wav", "wav"}, - {"audio/basic", "au"}, - {"audio/amr", "amr"}, - {"audio/x-amr", "amr"}, - {"audio/amr-wb", "amr"}, - {"audio/midi", "mid"}, - {"audio/sp-midi", "mid"}, - {"application/smil", "smil"}, - {"application/vnd.wap.mms-message", "mms"}, - {NULL, NULL} -}; - -static Octstr *filename2content_type(char *fname) -{ - char *p = strrchr(fname, '.'); - int i; - - if (p) - for (i = 0; exts[i].file_ext; i++) - if (strcasecmp(p+1, exts[i].file_ext) == 0) - return octstr_imm(exts[i].ctype); - - return octstr_imm("application/octet-stream"); -} /* Return the prefix part of a url or file. */ static Octstr *url_path_prefix(Octstr *url, int type) @@ -721,8 +679,10 @@ static int add_msg_part(MIMEEntity *res, xmlNodePtr node, Octstr *base_url, isurl = has_url_scheme(src); slash_prefix = (src[0] == '/'); +#if 0 /* we now support file:// */ if (isurl && strstr(src, "http") != src) /* Only http and https allowed! */ goto done; +#endif if (isurl) curl = octstr_create(src);