From b064ee14f01893f44b1af9c6d275aba681d24783 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Thu, 20 Nov 2008 08:43:52 +0000 Subject: [PATCH] Minor mmsbox fixes --- mbuni/ChangeLog | 3 + mbuni/extras/pgsql-queue/mms_pgsql_queue.c | 11 ++- mbuni/mmlib/mms_mm7soap.c | 3 +- mbuni/mmsbox/bearerbox.c | 103 ++++++++++++++------- mbuni/mmsbox/mmsbox.c | 28 +++++- 5 files changed, 109 insertions(+), 39 deletions(-) diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index 25e1d52..ad4736e 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,6 @@ +2008-11-20 P. A. Bagyenda + * Improved DLR status messages in mmsbox + * Minor memory leak fixed in MM7/SOAP processing 2008-11-14 P. A. Bagyenda * PSQL Queue module changes: optionally move message storage to file to improve performance 2008-11-12 P. A. Bagyenda diff --git a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c index e983a56..30bd2ad 100644 --- a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c +++ b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c @@ -1104,14 +1104,17 @@ static void pgq_queue_run(char *dir, mms_info(0, "pgsql_queue", NULL, "Queue runner on [%s] shutdown, started...", dir); gwlist_remove_producer(items_list); +#if 0 for (i=0;ienvelope, octstr_imm("MMStatus")); + r = http_header_value(m->envelope, octstr_imm("MMStatus")); if (msgtype == MM7_TAG_DeliveryReportReq && p) { Octstr *status = r && (mms_string_to_status(r) >= 0) ? r : octstr_imm("Indeterminate"); msg = mms_deliveryreport(s ? s : octstr_imm("0000"), from, p, t, status); @@ -979,6 +979,7 @@ MmsMsg *mm7_soap_to_mmsmsg(MSoapMsg_t *m, Octstr *from) octstr_destroy(p); octstr_destroy(r); octstr_destroy(f); + octstr_destroy(q); break; default: break; diff --git a/mbuni/mmsbox/bearerbox.c b/mbuni/mmsbox/bearerbox.c index aaf0a20..2fcc956 100644 --- a/mbuni/mmsbox/bearerbox.c +++ b/mbuni/mmsbox/bearerbox.c @@ -165,7 +165,8 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) int status = 1000; unsigned char *msgtype = (unsigned char *)""; Octstr *qf = NULL, *mmc_id = NULL, *qdir = NULL; - + List *qhdr = http_create_empty_headers(); + if (h->body) mreq = mm7_parse_soap(h->headers, h->body); if (mreq) @@ -191,7 +192,7 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) switch (mm7_msgtype(mreq)) { Octstr *value, *value2; - List *hdr; + case MM7_TAG_DeliverReq: m = mm7_soap_to_mmsmsg(mreq, from); if (m) { @@ -263,31 +264,43 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) value = mm7_soap_header_value(mreq, octstr_imm("MMStatus")); msgid = mm7_soap_header_value(mreq, octstr_imm("MessageID")); + if ((value2 = mm7_soap_header_value(mreq, octstr_imm("StatusText"))) != NULL) { + + http_header_add(qhdr, "X-Mbuni-StatusText", octstr_get_cstr(value2)); + octstr_destroy(value2); + value2 = NULL; + } + + if ((value2 = mm7_soap_header_value(mreq, octstr_imm("Details"))) != NULL) { + + http_header_add(qhdr, "X-Mbuni-StatusDetails", octstr_get_cstr(value2)); + octstr_destroy(value2); + value2 = NULL; + } + m = mm7_soap_to_mmsmsg(mreq, from); if (mmc_id != NULL) { /* internal routing. */ if (m) fixup_relayed_report(m, h->m, "delivery-report", value); /* fix it up if it is relayed. */ - hdr = NULL; value2 = NULL; } else { /* routing to URL -- get it. */ Octstr *transid = NULL; value2 = get_dlr_notify_url(msgid, "delivery-report",h->m->group_id, h->m->id, value, &transid); - hdr = http_create_empty_headers(); - http_header_add(hdr, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id)); + http_header_add(qhdr, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id)); if (transid) { - http_header_add(hdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid)); + http_header_add(qhdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid)); octstr_destroy(transid); } if (uaprof) { Octstr *sx = date_format_http(uaprof_tstamp); - http_header_add(hdr, "X-Mbuni-UAProf", octstr_get_cstr(uaprof)); - http_header_add(hdr, "X-Mbuni-Timestamp", octstr_get_cstr(sx)); + http_header_add(qhdr, "X-Mbuni-UAProf", octstr_get_cstr(uaprof)); + http_header_add(qhdr, "X-Mbuni-Timestamp", octstr_get_cstr(sx)); octstr_destroy(sx); } } @@ -297,7 +310,7 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) 0, time(NULL) + default_msgexpiry, m, NULL, NULL, NULL, value2, NULL, - hdr, + qhdr, 0, octstr_get_cstr(qdir), "MM7/SOAP-IN", @@ -311,7 +324,6 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) octstr_destroy(value); octstr_destroy(value2); - http_destroy_headers(hdr); break; case MM7_TAG_ReadReplyReq: @@ -323,25 +335,23 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) if (mmc_id != NULL) { /* internal routing. */ if (m) fixup_relayed_report(m, h->m, "read-report", octstr_imm("")); - hdr = NULL; value2 = NULL; } else { Octstr *transid = NULL; value2 = get_dlr_notify_url(msgid, "read-report",h->m->group_id, h->m->id, value, &transid); - hdr = http_create_empty_headers(); - http_header_add(hdr, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id)); + http_header_add(qhdr, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id)); if (transid) { - http_header_add(hdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid)); + http_header_add(qhdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid)); octstr_destroy(transid); } if (uaprof) { Octstr *sx = date_format_http(uaprof_tstamp); - http_header_add(hdr, "X-Mbuni-UAProf", octstr_get_cstr(uaprof)); - http_header_add(hdr, "X-Mbuni-Timestamp", octstr_get_cstr(sx)); + http_header_add(qhdr, "X-Mbuni-UAProf", octstr_get_cstr(uaprof)); + http_header_add(qhdr, "X-Mbuni-Timestamp", octstr_get_cstr(sx)); octstr_destroy(sx); } @@ -352,7 +362,7 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) 0, time(NULL) + default_msgexpiry, m, NULL, NULL, NULL, value2, NULL, - hdr, + qhdr, 0, octstr_get_cstr(qdir), "MM7/SOAP-IN", @@ -367,7 +377,6 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) octstr_destroy(value); octstr_destroy(value2); - http_destroy_headers(hdr); break; default: @@ -400,6 +409,7 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h) mm7_soap_destroy(mreq); gwlist_destroy(to, (gwlist_item_destructor_t *)octstr_destroy); octstr_destroy(mmc_id); + http_destroy_headers(qhdr); return MM7_SOAP_STATUS_OK(status) ? 0 : -1; } @@ -421,7 +431,7 @@ static void handle_report_dispatch(MmscGrp *m, Octstr *hfrom, char *rtype, List #endif /* helper function for queueing delivery reports. */ -static int queue_dlr(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *msgid, Octstr *status, char *interf) +static int queue_dlr(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *msgid, Octstr *status, char *interf, List *errl) { Octstr *mmc_id = NULL, *qdir; MmsMsg *m = mms_deliveryreport(msgid, from, to, time(NULL), status); @@ -430,6 +440,9 @@ static int queue_dlr(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *msgid, Octs Octstr *qf, *rr_uri = NULL; List *rqh = http_create_empty_headers(); + if (errl) + http_header_combine(rqh, errl); /* add status stuff. */ + gwlist_append(lto, octstr_duplicate(to)); qdir = get_mmsbox_queue_dir(from, lto, mmc, &mmc_id); /* get routing info. */ @@ -468,6 +481,7 @@ static int queue_dlr(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *msgid, Octs octstr_destroy(qf); http_destroy_headers(rqh); + octstr_destroy(rr_uri); gwlist_destroy(lto, (void *)octstr_destroy); octstr_destroy(mmc_id); @@ -1095,6 +1109,7 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *service_code, List *hdrs, MmsMsg *m, Octstr **error, + List **errl, int *retry) { Octstr *ret = NULL; @@ -1105,8 +1120,7 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, Octstr *to, List *rh = NULL, *ph = NULL; Octstr *body = NULL, *rbody = NULL, *url = NULL; Octstr *s, *distrib = NULL; - char *xvasid = vasid ? vasid : - (mmc->default_vasid ? octstr_get_cstr(mmc->default_vasid) : NULL); + char *xvasid = vasid ? vasid : (mmc->default_vasid ? octstr_get_cstr(mmc->default_vasid) : NULL); mms_info(0, "MM7", mmc->id, "MMSBox: Send[soap] to MMSC[%s], msg type [%s], from %s, to %s", mmc->id ? octstr_get_cstr(mmc->id) : "", @@ -1148,7 +1162,21 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, Octstr *to, mmc->mmsc_url, mmc->id); goto done1; } - + + if (errl) { /* Pick up status stuff -- for DLR */ + if (*errl == NULL) + *errl = http_create_empty_headers(); + if ((s = mm7_soap_header_value(mresp, octstr_imm("StatusText"))) != NULL) { + http_header_add(*errl, "X-Mbuni-StatusText", octstr_get_cstr(s)); + octstr_destroy(s); + } + + if ((s = mm7_soap_header_value(mresp, octstr_imm("Details"))) != NULL) { + http_header_add(*errl, "X-Mbuni-StatusDetails", octstr_get_cstr(s)); + octstr_destroy(s); + } + } + /* Now look at response code and use it to tell you what you want. */ if ((s = mm7_soap_header_value(mresp, octstr_imm("StatusCode"))) != NULL) { tstatus = atoi(octstr_get_cstr(s)); @@ -1159,6 +1187,7 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, Octstr *to, } else tstatus = MM7_SOAP_FORMAT_CORRUPT; + if (!MM7_SOAP_STATUS_OK(tstatus) && tstatus != MM7_SOAP_COMMAND_REJECTED) { Octstr *detail = mm7_soap_header_value(mresp, octstr_imm("Details")); char *tmp = (char *)mms_soap_status_to_cstr(tstatus); @@ -1361,23 +1390,24 @@ static int mms_sendtommsc(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *transi MmsMsg *m, Octstr *dlr_url, Octstr *rr_url, List *hdrs, Octstr **new_msgid, - Octstr **err) + List **errhdrs) { Octstr *id = NULL, *groupid = NULL; int ret = 0, retry = 0; double throughput = 0; mutex_lock(mmc->mutex); { /* Grab a lock on it. */ + Octstr *err = NULL; if (mmc->type == SOAP_MMSC) - id = mm7soap_send(mmc, from, to, transid, linkedid, vasid, service_code, hdrs, m, err, &retry); + id = mm7soap_send(mmc, from, to, transid, linkedid, vasid, service_code, hdrs, m, &err, errhdrs, &retry); else if (mmc->type == EAIF_MMSC) - id = mm7eaif_send(mmc, from, to, transid, vasid, hdrs, m, err, &retry); + id = mm7eaif_send(mmc, from, to, transid, vasid, hdrs, m, &err, &retry); else if (mmc->type == HTTP_MMSC) - id = mm7http_send(mmc, from, to, m, err, &retry); + id = mm7http_send(mmc, from, to, m, &err, &retry); else if (mmc->type == CUSTOM_MMSC && mmc->custom_started) id = mmc->fns->send_msg(mmc->data, from, to, transid, linkedid, vasid, - service_code, m, hdrs, err, &retry); + service_code, m, hdrs, &err, &retry); else mms_error_ex("MT", 0, "MM7", mmc->id, "MMC[%s] of unknown type, can't send!", mmc->id ? octstr_get_cstr(mmc->id) : ""); @@ -1385,6 +1415,12 @@ static int mms_sendtommsc(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *transi throughput = mmc->throughput; groupid = mmc->group_id ? octstr_duplicate(mmc->group_id) : NULL; + if (err && errhdrs) { + if (*errhdrs == NULL) + *errhdrs = http_create_empty_headers(); + http_header_add(*errhdrs, "X-Mbuni-Error", octstr_get_cstr(err)); + } + octstr_destroy(err); } mutex_unlock(mmc->mutex); /* release lock */ if (id) { @@ -1423,6 +1459,7 @@ static int sendMsg(MmsEnvelope *e) time_t tnow = time(NULL); MmscGrp *mmc = NULL; Octstr *new_msgid = NULL; + List *errl = NULL; if (!to || !to->process) continue; @@ -1476,7 +1513,7 @@ static int sendMsg(MmsEnvelope *e) e->xqfname, e->hdrs); octstr_destroy(pfrom); - } else + } else { res = mms_sendtommsc(mmc, e->from, to->rcpt, e->msgId, otransid, @@ -1487,7 +1524,10 @@ static int sendMsg(MmsEnvelope *e) e->url1, e->url2, e->hdrs, &new_msgid, - &err); + &errl); + if (errl) + err = http_header_value(errl, octstr_imm("X-Mbuni-Error")); + } if (res == MMS_SEND_OK) mmc->mt_pdus++; else @@ -1500,7 +1540,7 @@ static int sendMsg(MmsEnvelope *e) if (e->msgtype == MMS_MSGTYPE_SEND_REQ || e->msgtype == MMS_MSGTYPE_RETRIEVE_CONF) /* queue dlr as needed. */ - queue_dlr(mmc, e->from, to->rcpt, new_msgid, octstr_imm("Forwarded"), "MM7-Out"); + queue_dlr(mmc, e->from, to->rcpt, new_msgid, octstr_imm("Forwarded"), "MM7-Out", errl); #if 0 mmsbox_send_report(to->rcpt, "delivery-report", e->url1, octstr_imm("Forwarded"), new_msgid, NULL, @@ -1512,7 +1552,7 @@ static int sendMsg(MmsEnvelope *e) queue_dlr(mmc, e->from, to->rcpt, e->msgId, (e->expiryt != 0 && e->expiryt < tnow) ? octstr_imm("Expired") : octstr_imm("Rejected"), - "MM7-Out"); + "MM7-Out", errl); #if 0 mmsbox_send_report(to->rcpt, "delivery-report", e->url1, @@ -1558,6 +1598,7 @@ static int sendMsg(MmsEnvelope *e) octstr_destroy(new_msgid); octstr_destroy(err); + http_destroy_headers(errl); e->lasttry = tnow; if (qfs->mms_queue_update(e) == 1) { diff --git a/mbuni/mmsbox/mmsbox.c b/mbuni/mmsbox/mmsbox.c index a951cf8..fafb987 100644 --- a/mbuni/mmsbox/mmsbox.c +++ b/mbuni/mmsbox/mmsbox.c @@ -499,7 +499,9 @@ static int mmsbox_send_report(Octstr *from, char *report_type, Octstr *msgid, Octstr *orig_msgid, Octstr *mmc_id, Octstr *mmc_gid, Octstr *orig_transid, Octstr *uaprof, - Octstr* uaprof_tstamp) + Octstr* uaprof_tstamp, + Octstr *err, + Octstr *statustxt, Octstr *details) { List *rh = NULL, *rph = NULL; Octstr *rb = NULL, *xfrom = from ? octstr_duplicate(from) : NULL; @@ -529,6 +531,16 @@ static int mmsbox_send_report(Octstr *from, char *report_type, if (orig_msgid) http_header_add(rh, "X-Mbuni-Orig-Message-ID", octstr_get_cstr(orig_msgid)); + + if (err) + http_header_add(rh, "X-Mbuni-MM-Error", octstr_get_cstr(err)); + + if (statustxt) + http_header_add(rh, "X-Mbuni-MM-StatusText", octstr_get_cstr(statustxt)); + + if (details) + http_header_add(rh, "X-Mbuni-MM-StatusDetails", octstr_get_cstr(details)); + if (uaprof) { http_header_add(rh, "X-Mbuni-UAProf", octstr_get_cstr(uaprof)); http_header_add(rh, "X-Mbuni-Timestamp", octstr_get_cstr(uaprof_tstamp)); @@ -602,11 +614,19 @@ static int mmsbox_service_dispatch(MmsEnvelope *e) http_header_value(e->hdrs, octstr_imm("X-Mbuni-Timestamp")) : NULL; Octstr *gid = e->hdrs ? http_header_value(e->hdrs, octstr_imm("X-Mbuni-Mmsc-GroupID")) : NULL; + + Octstr *err = e->hdrs ? + http_header_value(e->hdrs, octstr_imm("X-Mbuni-Error")) : NULL; + Octstr *statustxt = e->hdrs ? + http_header_value(e->hdrs, octstr_imm("X-Mbuni-StatusText")) : NULL; + Octstr *details = e->hdrs ? + http_header_value(e->hdrs, octstr_imm("X-Mbuni-StatusDetails")) : NULL; + if (e->url1) res = mmsbox_send_report(e->from, report_type, e->url1, status, msgid, orig_msgid, e->fromproxy, gid, orig_transid, - uaprof,tstamp); + uaprof,tstamp, err, statustxt, details); else { mms_info(0, "MM7", e->fromproxy, "MMSBox: Skipped %s URL call for [%s]. Empty URL, from [%s]", report_type, octstr_get_cstr(msgid), octstr_get_cstr(e->from)); @@ -620,7 +640,9 @@ static int mmsbox_service_dispatch(MmsEnvelope *e) octstr_destroy(uaprof); octstr_destroy(tstamp); octstr_destroy(gid); - + octstr_destroy(err); + octstr_destroy(statustxt); + octstr_destroy(details); goto done; /* No more processing. */ }