From f3fff0f45e6dbc1c92b44b2105f622a4156ad993 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Mon, 4 Jul 2005 12:53:53 +0000 Subject: [PATCH] Fixed mis-counting of send attempts in mmsrelay Improved handling of email addresses in queue module Removed WSP_QUOTE patch to kannel's wap/wsp_headers.c -- it appears it is not needed. --- mbuni/misc-patches/mbuni-kannel-patch-full | 12 ---- mbuni/mmlib/mms_msg.h | 1 + mbuni/mmlib/mms_queue.c | 78 +++++++++++++++++----- mbuni/mmsc/mmsglobalsender.c | 25 ++++--- mbuni/mmsc/mmssend.c | 36 +++++----- 5 files changed, 95 insertions(+), 57 deletions(-) diff --git a/mbuni/misc-patches/mbuni-kannel-patch-full b/mbuni/misc-patches/mbuni-kannel-patch-full index 5d77bec..e61b473 100644 --- a/mbuni/misc-patches/mbuni-kannel-patch-full +++ b/mbuni/misc-patches/mbuni-kannel-patch-full @@ -914,15 +914,3 @@ diff -Naur gateway-1.4.0/test/test_ppg.c gateway-1.4.0-patched/test/test_ppg.c wait_seconds = atof(optarg); break; -diff -Naur gateway-1.4.0/wap/wsp_headers.c gateway-1.4.0-patched/wap/wsp_headers.c ---- gateway-1.4.0/wap/wsp_headers.c 2004-08-08 23:39:56.000000000 +0300 -+++ gateway-1.4.0-patched/wap/wsp_headers.c 2005-05-30 12:30:46.000000000 +0300 -@@ -122,7 +122,7 @@ - } else if (val > 127) { - *well_known_value = val - 128; - return WSP_FIELD_VALUE_ENCODED; -- } else if (val == WSP_QUOTE) { /* 127 */ -+ } else if (val == WSP_QUOTE || val == '"') { /* 127 */ - *well_known_value = -1; - /* We already consumed the Quote */ - return WSP_FIELD_VALUE_NUL_STRING; diff --git a/mbuni/mmlib/mms_msg.h b/mbuni/mmlib/mms_msg.h index a36b3f5..e29a04a 100644 --- a/mbuni/mmlib/mms_msg.h +++ b/mbuni/mmlib/mms_msg.h @@ -30,6 +30,7 @@ extern int mms_validate_address(Octstr *s); * mms_frombinary: Parse MMS binary representation, return a Message or NULL. * errors are reported in errors string. * Takes from param which is put in if insert-address is requested. + * NOTE: function may modify 'msg' argument as it parses. */ extern MmsMsg *mms_frombinary(Octstr *msg, Octstr *from); diff --git a/mbuni/mmlib/mms_queue.c b/mbuni/mmlib/mms_queue.c index 987bf83..6f74c27 100644 --- a/mbuni/mmlib/mms_queue.c +++ b/mbuni/mmlib/mms_queue.c @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -554,6 +555,48 @@ static int writemmsdata(Octstr *ms, char *df, char subdir[], char *mms_queuedir) } +static Octstr *copy_and_clean_address(Octstr *addr) +{ + Octstr *s = octstr_duplicate(addr); + int k, i; + + octstr_strip_blanks(s); + /* Only clean up email addresses for now. */ + if ((k = octstr_search_char(s, '@',0)) < 0) + goto done; + + /* Find '<' if any, then find last one and remove everything else. */ + + i = octstr_search_char(s, '<',0); + if (i >= 0) { + int j; + + octstr_delete(s, 0, i+1); /* strip first part off. */ + + j = octstr_search_char(s, '>',0); + if (j >= 0) + octstr_delete(s, j, octstr_len(s)); + } else { + /* remove everything after the domain. */ + int n = octstr_len(s); + char *p = octstr_get_cstr(s); + + + for (i = k+1; i < n; i++) + if (isspace(p[i])) { /* there can't be space in domain, so this marks end of address. */ + octstr_delete(s, i, n); + break; + } + } + +done: + if (octstr_len(s) == 0) { + octstr_destroy(s); + s = NULL; + } + return s; +} + Octstr *mms_queue_add(Octstr *from, List *to, Octstr *subject, Octstr *fromproxy, Octstr *viaproxy, @@ -565,8 +608,8 @@ Octstr *mms_queue_add(Octstr *from, List *to, char qf[QFNAMEMAX], subdir[64]; int fd, i, n; MmsEnvelope *e; - Octstr *msgid, *s = NULL; - Octstr *ms, *res = NULL; + Octstr *msgid, *s = NULL, *r = NULL; + Octstr *ms, *res = NULL, *xfrom = NULL; fd = mkqf(qf, subdir, directory); @@ -581,7 +624,8 @@ Octstr *mms_queue_add(Octstr *from, List *to, ms = mms_tobinary(m); /* Convert message to string. */ msgid = mms_maketransid(octstr_get_cstr(res), mmscname); - + xfrom = copy_and_clean_address(from); + e = gw_malloc(sizeof *e); /* Make envelope, clear it. */ memset(e, 0, sizeof *e); @@ -592,7 +636,7 @@ Octstr *mms_queue_add(Octstr *from, List *to, e->qf.fd = fd; e->msgtype = mms_messagetype(m); - e->from = from; + e->from = xfrom; e->created = time(NULL); e->sendt = senddate; e->expiryt = expirydate; @@ -619,15 +663,16 @@ Octstr *mms_queue_add(Octstr *from, List *to, else if (s) octstr_destroy(s); - for (i = 0, n = to ? list_len(to) : 0; ircpt = a; - t->process = 1; - - list_append(e->to, t); - } + for (i = 0, n = to ? list_len(to) : 0; ircpt = r; + t->process = 1; + + list_append(e->to, t); + } /* Write queue data. */ if (writeenvelope(e, 1) < 0) { @@ -650,16 +695,19 @@ Octstr *mms_queue_add(Octstr *from, List *to, close(fd); /* Close queue file, thereby letting go of locks. */ done: - /* Free the envelope stuff since we do not need it any more, then free e */ + /* Free the envelope stuff since we do not need it any more, then free 'e' */ for (i = 0, n = list_len(e->to); ito, i); + octstr_destroy(to->rcpt); gw_free(to); } list_destroy(e->to, NULL); gw_free(e); octstr_destroy(ms); octstr_destroy(msgid); - + if (xfrom) + octstr_destroy(xfrom); + return res; } diff --git a/mbuni/mmsc/mmsglobalsender.c b/mbuni/mmsc/mmsglobalsender.c index f1e6579..8aed1bd 100644 --- a/mbuni/mmsc/mmsglobalsender.c +++ b/mbuni/mmsc/mmsglobalsender.c @@ -134,8 +134,9 @@ static int sendMsg(MmsEnvelope *e) goto done; } else if (e->attempts >= settings->maxsendattempts) { - err = octstr_format("MMSC error: Failed to deliver to %S after %ld attempts!", - to->rcpt, e->attempts); + err = octstr_format("MMSC error: Failed to deliver to %S after %ld attempts. (max attempts allowed is %ld)!", + to->rcpt, e->attempts, + settings->maxsendattempts); res = MMS_SEND_ERROR_FATAL; goto done; } @@ -284,12 +285,10 @@ static int sendMsg(MmsEnvelope *e) list_produce(cdr_list, cdr); /* Put it on list so sending thread sends it. */ } - - e->lasttry = tnow; - e->attempts++; - e->sendt = e->lasttry + settings->send_back_off * e->attempts; - if (mms_queue_update(e) == 1) { + /* Update queue entry so that we know which ones have been processed. */ + e->lasttry = tnow; + if (mms_queue_update(e) == 1) { e = NULL; break; /* Queue entry gone. */ } @@ -298,9 +297,15 @@ static int sendMsg(MmsEnvelope *e) done2: if (msg) mms_destroy(msg); - if (e) - mms_queue_free_env(e); - + + if (e) { /* Update the queue if it is still valid (e.g. recipients not handled) XXX can this happen here??... */ + e->lasttry = time(NULL); + e->attempts++; /* Update count of number of delivery attempts. */ + e->sendt = e->lasttry + settings->send_back_off * e->attempts; + + if (mms_queue_update(e) != 1) + mms_queue_free_env(e); + } return 1; /* Always deletes the queue entry. */ } diff --git a/mbuni/mmsc/mmssend.c b/mbuni/mmsc/mmssend.c index a24184d..3f4814d 100644 --- a/mbuni/mmsc/mmssend.c +++ b/mbuni/mmsc/mmssend.c @@ -18,9 +18,10 @@ #include "mms_util.h" #include "mms_mmbox.h" -static Octstr *data; + static Octstr *from; static List *to; +static Octstr *data; static MmsMsg *m; static int savetommbox; Octstr *mmbox; @@ -51,24 +52,8 @@ static int find_own(int i, int argc, char *argv[]) } else return -1; else if (argv[i][1] == 'm') - if (i + 1 < argc) { - int ch; + if (i + 1 < argc) { data = octstr_read_file(argv[i+1]); - - /* try and detect if we are looking at plain text (mime-encoded) or binary encoded message. */ - ch = octstr_get_char(data, 0); - if (isprint(ch)) { - MIMEEntity *mime = mime_octstr_to_entity(data); - MmsMsg *mm = NULL; - if (mime && (mm = mms_frommime(mime)) != NULL) { - octstr_destroy(data); - data = mms_tobinary(mm); - } - if (mime) - mime_entity_destroy(mime); - if (mm) - mms_destroy(mm); - } return 1; } else return -1; @@ -128,10 +113,21 @@ int main(int argc, char *argv[]) mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir)); if (data) { - m = mms_frombinary(data, from ? from : octstr_imm("anon@anon")); + /* try and detect if we are looking at plain text (mime-encoded) or binary encoded message. */ + int ch = octstr_get_char(data, 0); + if (isprint(ch)) { + MIMEEntity *mime = mime_octstr_to_entity(data); + + if (mime) { + m = mms_frommime(mime); + mime_entity_destroy(mime); + } + } else + m = mms_frombinary(data, from ? from : octstr_imm("anon@anon")); if (m) - mms_msgdump(m,1); + mms_msgdump(m,1); msize = octstr_len(data); + octstr_destroy(data); } else msize = 0; if (!m)