From 0cb66263390e22b9da59746b5aa37d6c2cff5267 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Wed, 9 Jul 2008 04:40:35 +0000 Subject: [PATCH] fix for DLR in MM4 --- mbuni/ChangeLog | 2 ++ mbuni/extras/pgsql-queue/mms_pgsql_queue.c | 18 +++++++++++------- mbuni/mmlib/mms_util.c | 13 ++++++++----- mbuni/mmsc/mmsmobilesender.c | 18 ++++++++++-------- mbuni/mmsc/mmsproxy.c | 2 +- 5 files changed, 32 insertions(+), 21 deletions(-) diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index 6aed452..7cc6671 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2008-07-09 P. A. Bagyenda + * Fix for FROM address in MM4_delivery_report.REQ packet 2008-07-07 P. A. Bagyenda * Move to compile against Kannel-CVS 2008-07-07 P. A. Bagyenda diff --git a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c index cf4a373..7df8389 100644 --- a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c +++ b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c @@ -60,6 +60,7 @@ static int pgq_cleanup_module(void) gw_assert(free_conns); gwlist_remove_producer(free_conns); + sleep(2); gwlist_destroy(free_conns, (void *)PQfinish); free_conns = NULL; @@ -71,19 +72,22 @@ static PGconn *get_conn(void) { PGconn *c; PGresult *r; - gw_assert(free_conns); + + if (free_conns == NULL) return NULL; c = gwlist_consume(free_conns); - - r = PQexec(c, "BEGIN"); /* start a transaction. */ - PQclear(r); + if (c) { /* might fail if we are shutting down. */ + r = PQexec(c, "BEGIN"); /* start a transaction. */ + PQclear(r); + } return c; } static void return_conn(PGconn *c) { PGresult *r; - gw_assert(free_conns); + + if (free_conns == NULL) return; /* commit or destroy transaction. */ if (PQtransactionStatus(c) == PQTRANS_INERROR) @@ -432,7 +436,7 @@ static int _puthdr(PGconn *c, int64_t qid, char *hname, char *val) static int writeenvelope(MmsEnvelope *e, int newenv) { char *s, buf[512], cmd[QFNAMEMAX*4 + 1], lastt[128], sendt[128], expiryt[128], *xfrom; - int i, n, res = 0; + int i, n; struct pgfile_t *qfs = e ? e->qfs_data : NULL; PGresult *r; @@ -573,7 +577,7 @@ static int writeenvelope(MmsEnvelope *e, int newenv) _puthdr(qfs->conn, qfs->qid,"b", buf); } - return res; + return 0; } diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index 9481595..dc07f7b 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -751,9 +751,8 @@ int mms_sendtoemail(Octstr *from, Octstr *to, } else { char *x, tmp[32]; Octstr *xsender = octstr_format("system-user@%S", myhostname); - Octstr *y; - + if (msgid) { y = (octstr_get_char(msgid, 0) == '"') ? octstr_duplicate(msgid) : octstr_format("\"%S\"", msgid); @@ -787,7 +786,9 @@ int mms_sendtoemail(Octstr *from, Octstr *to, else if (mtype == MMS_MSGTYPE_DELIVERY_IND) { Octstr *s = http_header_value(headers, octstr_imm("X-Mms-Status")); x = "MM4_delivery_report.REQ"; - + + /* insert FROM address as recipient as per spec */ + http_header_add(newhdrs, "From", octstr_get_cstr(to)); /* rename status header. */ http_header_remove_all(headers, "X-Mms-Status"); http_header_add(newhdrs, "X-Mms-MM-Status-Code", @@ -795,9 +796,11 @@ int mms_sendtoemail(Octstr *from, Octstr *to, if (!s) warning(0, "MMS Delivery report with missing Status!"); octstr_destroy(s); - } else if (mtype == MMS_MSGTYPE_READ_REC_IND) + } else if (mtype == MMS_MSGTYPE_READ_REC_IND) { x = "MM4_read_reply_report.REQ"; - else { + /* insert FROM address as recipient as per spec */ + http_header_add(newhdrs, "From", octstr_get_cstr(to)); + } else { *error = octstr_format("Invalid message type %s on MM4 outgoing interface!", mms_message_type_to_cstr(mtype)); x = ""; diff --git a/mbuni/mmsc/mmsmobilesender.c b/mbuni/mmsc/mmsmobilesender.c index 7c42f73..85a1041 100644 --- a/mbuni/mmsc/mmsmobilesender.c +++ b/mbuni/mmsc/mmsmobilesender.c @@ -12,6 +12,8 @@ * the GNU General Public License, with a few exceptions granted (see LICENSE) */ #include "mmsrelay.h" +#include +#include #define WAPPUSH_PORT 2948 @@ -138,7 +140,7 @@ static void start_push(Octstr *rcpt_to, int isphonenum, MmsEnvelope *e, MmsMsg * e = update_env_success(e, xto); } else { e = update_env_failed(e); - error(0, "push to %s:%d failed, no reason found", octstr_get_cstr(to), WAPPUSH_PORT); + error(0, "push to %s:%d failed: %s", octstr_get_cstr(to), WAPPUSH_PORT, strerror(errno)); } octstr_destroy(addr); if (e) @@ -462,15 +464,15 @@ static int sendNotify(MmsEnvelope *e) e ? e->msgId : NULL, NULL, NULL); if (msg) mms_destroy(msg); - if (phonenum) - octstr_destroy(phonenum); - if (rcpt_ip) - octstr_destroy(rcpt_ip); + + octstr_destroy(phonenum); + + octstr_destroy(rcpt_ip); octstr_destroy(to); - if (msgId) octstr_destroy(msgId); - if (fromproxy) octstr_destroy(fromproxy); + octstr_destroy(msgId); + octstr_destroy(fromproxy); octstr_destroy(from); - if (err) octstr_destroy(err); + octstr_destroy(err); return 1; } diff --git a/mbuni/mmsc/mmsproxy.c b/mbuni/mmsc/mmsproxy.c index ef0126a..4340eb1 100644 --- a/mbuni/mmsc/mmsproxy.c +++ b/mbuni/mmsc/mmsproxy.c @@ -983,7 +983,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) || octstr_case_compare(allow_report, octstr_imm("Yes")) == 0) && e->dlr) { Octstr *x; - Octstr *from = h->client_addr ? h->client_addr : settings->system_user; + Octstr *from = h->client_addr ? h->client_addr : settings->system_user; List *l = gwlist_create(); mrpt = mms_deliveryreport(e->msgId, h->client_addr, time(NULL), status);