1
0
Fork 0

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.
This commit is contained in:
bagyenda 2005-07-04 12:53:53 +00:00
parent 6f7e3ea12d
commit f3fff0f45e
5 changed files with 95 additions and 57 deletions

View File

@ -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;

View File

@ -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);

View File

@ -18,6 +18,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <ctype.h>
#include <dirent.h>
@ -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; i<n; i++) {
MmsEnvelopeTo *t = gw_malloc(sizeof *t);
Octstr *a = list_get(to, i);
t->rcpt = a;
t->process = 1;
list_append(e->to, t);
}
for (i = 0, n = to ? list_len(to) : 0; i<n; i++)
if ((r = list_get(to, i)) != NULL &&
(r = copy_and_clean_address(r)) != NULL) {
MmsEnvelopeTo *t = gw_malloc(sizeof *t);
t->rcpt = 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); i<n; i++) {
MmsEnvelopeTo *to = list_get(e->to, 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;
}

View File

@ -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. */
}

View File

@ -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)