1
0
Fork 0

added retries to DLR URL calling in mmsbox

This commit is contained in:
bagyenda 2008-11-12 10:30:30 +00:00
parent 39f5cccee4
commit e370a86566
5 changed files with 415 additions and 230 deletions

View File

@ -1,3 +1,5 @@
2008-11-12 P. A. Bagyenda <bagyenda@dsmagic.com>
* Improved DLR delivery to external URL (retries) in mmsbox
2008-11-04 P. A. Bagyenda <bagyenda@dsmagic.com> 2008-11-04 P. A. Bagyenda <bagyenda@dsmagic.com>
* Minor fix for base64 decoding in URI with data: schema * Minor fix for base64 decoding in URI with data: schema
2008-10-16 P. A. Bagyenda <bayenda@dsmagic.com> 2008-10-16 P. A. Bagyenda <bayenda@dsmagic.com>

View File

@ -1,6 +1,6 @@
dnl Mbuni - Open Source MMS Gateway dnl Mbuni - Open Source MMS Gateway
dnl dnl
dnl Copyright (C) 2003 - 2007, Digital Solutions Ltd. - http://www.dsmagic.com dnl Copyright (C) 2003 - 2008, Digital Solutions Ltd. - http://www.dsmagic.com
dnl dnl
dnl Paul Bagyenda <bagyenda@dsmagic.com> dnl Paul Bagyenda <bagyenda@dsmagic.com>
dnl dnl

View File

@ -34,7 +34,7 @@ CREATE VIEW mms_messages_view AS SELECT
-- Table for envelope headers. -- Table for envelope headers.
CREATE TABLE mms_message_headers ( CREATE TABLE mms_message_headers (
id bigserial PRIMARY KEY, id bigserial PRIMARY KEY,
qid int REFERENCES mms_messages ON UPDATE CASCADE ON DELETE CASCADE, qid bigint REFERENCES mms_messages ON UPDATE CASCADE ON DELETE CASCADE,
item varchar(64) NOT NULL, item varchar(64) NOT NULL,
value text NOT NULL value text NOT NULL

View File

@ -78,58 +78,34 @@ done:
return res; return res;
} }
static int mmsbox_send_report(Octstr *from, char *report_type, static Octstr *get_dlr_notify_url(Octstr *msgid, char *report_type, Octstr *mmc_gid, Octstr *mmc_id,
Octstr *dlr_url, Octstr *status, Octstr *status,
Octstr *msgid, Octstr *orig_msgid, Octstr **transid)
Octstr *mmc_id, Octstr *mmc_gid,
Octstr *orig_transid, Octstr *uaprof,
time_t uaprof_tstamp)
{ {
Octstr *url = NULL;
List *rh = NULL, *rph = NULL;
Octstr *rb = NULL;
Octstr *xtransid = NULL;
if (dlr_url) Octstr *xtransid = NULL, *url = NULL;
url = octstr_duplicate(dlr_url);
mms_dlr_url_get(msgid, report_type, mmc_gid, &url, &xtransid);
if (transid)
*transid = xtransid;
else else
mms_dlr_url_get(msgid, report_type, mmc_gid, &url, &xtransid); octstr_destroy(xtransid);
if (octstr_len(url) == 0) { if (octstr_len(url) == 0) {
if (url) if (url)
mms_info(0, "MM7", NULL, mms_info(0, "MM7", NULL,
"Sending delivery-report skipped: `url' is empty, `group_id'=[%s], `msgid'=[%s]", "Sending delivery-report skipped: `url' is empty, `group_id'=[%s], `msgid'=[%s]",
octstr_get_cstr(mmc_gid), octstr_get_cstr(msgid)); octstr_get_cstr(mmc_gid), octstr_get_cstr(msgid));
octstr_destroy(url);
url = NULL;
goto done; goto done;
} else if (octstr_search(url, octstr_imm("msgid:"), 0) == 0) /* a fake one, skip it. */ } else if (octstr_search(url, octstr_imm("msgid:"), 0) == 0) { /* a fake one, skip it. */
octstr_destroy(url);
url = NULL;
goto done; goto done;
rh = http_create_empty_headers();
http_header_add(rh, "X-Mbuni-Report-Type", report_type);
http_header_add(rh, "X-Mbuni-MM-Status", octstr_get_cstr(status));
http_header_add(rh, "X-Mbuni-MMSC-ID", octstr_get_cstr(mmc_id));
http_header_add(rh, "X-Mbuni-MMSC-GID", octstr_get_cstr(mmc_gid));
http_header_add(rh, "X-Mbuni-From", octstr_get_cstr(from));
if (xtransid || orig_transid)
http_header_add(rh, "X-Mbuni-TransactionID",
octstr_get_cstr(xtransid ? xtransid : orig_transid));
if (msgid)
http_header_add(rh, "X-Mbuni-Message-ID", octstr_get_cstr(msgid));
if (orig_msgid)
http_header_add(rh, "X-Mbuni-Orig-Message-ID", octstr_get_cstr(orig_msgid));
if (uaprof) {
Octstr *sx = date_format_http(uaprof_tstamp);
http_header_add(rh, "X-Mbuni-UAProf", octstr_get_cstr(uaprof));
http_header_add(rh, "X-Mbuni-Timestamp", octstr_get_cstr(sx));
octstr_destroy(sx);
} }
mms_url_fetch_content(HTTP_METHOD_GET, url, rh, octstr_imm(""), &rph, &rb);
/* At what point do we delete it? For now, when we get a read report, /* At what point do we delete it? For now, when we get a read report,
* and also when we get a delivery report that is not 'deferred' or sent or forwarded * and also when we get a delivery report that is not 'deferred' or sent or forwarded
*/ */
@ -137,18 +113,12 @@ static int mmsbox_send_report(Octstr *from, char *report_type,
(octstr_case_compare(status, octstr_imm("Deferred")) != 0 && (octstr_case_compare(status, octstr_imm("Deferred")) != 0 &&
octstr_case_compare(status, octstr_imm("Forwarded")) != 0)) octstr_case_compare(status, octstr_imm("Forwarded")) != 0))
mms_dlr_url_remove(msgid, report_type, mmc_gid); mms_dlr_url_remove(msgid, report_type, mmc_gid);
done:
done: return url;
octstr_destroy(rb);
octstr_destroy(url);
octstr_destroy(xtransid);
http_destroy_headers(rph);
http_destroy_headers(rh);
return 0;
} }
static void fixup_relayed_report(MmsMsg *m, MmscGrp *mmc, char *rtype, Octstr *status) static void fixup_relayed_report(MmsMsg *m, MmscGrp *mmc, char *rtype, Octstr *status)
{ {
@ -220,7 +190,8 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h)
qdir = get_mmsbox_queue_dir(from, to, h->m, &mmc_id); /* get routing info. */ qdir = get_mmsbox_queue_dir(from, to, h->m, &mmc_id); /* get routing info. */
switch (mm7_msgtype(mreq)) { switch (mm7_msgtype(mreq)) {
Octstr *value; Octstr *value, *value2;
List *hdr;
case MM7_TAG_DeliverReq: case MM7_TAG_DeliverReq:
m = mm7_soap_to_mmsmsg(mreq, from); m = mm7_soap_to_mmsmsg(mreq, from);
if (m) { if (m) {
@ -281,84 +252,113 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h)
case MM7_TAG_DeliveryReportReq: case MM7_TAG_DeliveryReportReq:
value = mm7_soap_header_value(mreq, octstr_imm("MMStatus")); value = mm7_soap_header_value(mreq, octstr_imm("MMStatus"));
msgid = mm7_soap_header_value(mreq, octstr_imm("MessageID"));
m = mm7_soap_to_mmsmsg(mreq, from);
if (mmc_id != NULL) { /* internal routing. */ if (mmc_id != NULL) { /* internal routing. */
m = mm7_soap_to_mmsmsg(mreq, from); if (m)
if (m) {
fixup_relayed_report(m, h->m, "delivery-report", fixup_relayed_report(m, h->m, "delivery-report",
value); /* fix it up if it is relayed. */ value); /* fix it up if it is relayed. */
qf = qfs->mms_queue_add(from, to, NULL, hdr = NULL;
h->m->id, mmc_id, value2 = NULL;
0, time(NULL) + default_msgexpiry, m, NULL, } else { /* routing to URL -- get it. */
NULL, NULL, Octstr *transid = NULL;
NULL, NULL,
NULL,
0,
octstr_get_cstr(qdir),
"MM7/SOAP-IN",
NULL);
} else
qf = NULL;
if (qf)
/* Log to access log */
mms_log("Received DLR", from, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL);
else
status = 4000;
} else {
Octstr *desc = mm7_soap_header_value(mreq, octstr_imm("StatusText"));
msgid = mm7_soap_header_value(mreq, octstr_imm("MessageID")); value2 = get_dlr_notify_url(msgid, "delivery-report",h->m->group_id, h->m->id,
value, &transid);
mms_info(0, "MM7", h->m->id, "Sending delivery-report [FROM:%s] [VALUE:%s] [DESC:%s] [MSGID:%s]", hdr = http_create_empty_headers();
octstr_get_cstr(from), octstr_get_cstr(value), octstr_get_cstr(desc), http_header_add(hdr, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id));
octstr_get_cstr(h->m->id));
mmsbox_send_report(from, "delivery-report", NULL, if (transid) {
value, msgid, NULL, h->m->id, h->m->group_id, NULL, uaprof, uaprof_tstamp); http_header_add(hdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
octstr_destroy(transid);
mms_log("DeliveryReport", }
from, NULL, -1, msgid, value, h->m->id, "MMSBox", h->ua, NULL);
octstr_destroy(desc); 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));
octstr_destroy(sx);
}
} }
qf = qfs->mms_queue_add(from, to, NULL,
h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
value2, NULL,
hdr,
0,
octstr_get_cstr(qdir),
"MM7/SOAP-IN",
NULL);
if (qf)
/* Log to access log */
mms_log("Received DLR", from, to, -1, msgid, value, h->m->id, "MMSBox", h->ua, NULL);
else
status = 4000;
mresp = mm7_make_resp(mreq, status, NULL,1); mresp = mm7_make_resp(mreq, status, NULL,1);
octstr_destroy(value); octstr_destroy(value);
octstr_destroy(value2);
http_destroy_headers(hdr);
break; break;
case MM7_TAG_ReadReplyReq: case MM7_TAG_ReadReplyReq:
if (mmc_id != NULL) { /* internal routing. */
m = mm7_soap_to_mmsmsg(mreq, from);
if (m) { m = mm7_soap_to_mmsmsg(mreq, from);
value = mm7_soap_header_value(mreq, octstr_imm("MMStatus"));
msgid = mm7_soap_header_value(mreq, octstr_imm("MessageID"));
if (mmc_id != NULL) { /* internal routing. */
if (m)
fixup_relayed_report(m, h->m, "read-report", octstr_imm("")); fixup_relayed_report(m, h->m, "read-report", octstr_imm(""));
qf = qfs->mms_queue_add(from, to, NULL, hdr = NULL;
h->m->id, mmc_id, value2 = NULL;
0, time(NULL) + default_msgexpiry, m, NULL, } else {
NULL, NULL, Octstr *transid = NULL;
NULL, NULL,
NULL, value2 = get_dlr_notify_url(msgid, "read-report",h->m->group_id, h->m->id,
0, value, &transid);
octstr_get_cstr(qdir), hdr = http_create_empty_headers();
"MM7/SOAP-IN", http_header_add(hdr, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id));
NULL);
} else if (transid) {
qf = NULL; http_header_add(hdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
if (qf) octstr_destroy(transid);
/* Log to access log */ }
mms_log("Received RR", from, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL);
else
status = 4000;
} else {
Octstr *value = mm7_soap_header_value(mreq, octstr_imm("MMStatus"));
msgid = mm7_soap_header_value(mreq, octstr_imm("MessageID"));
mmsbox_send_report(from, if (uaprof) {
"read-report", NULL, value, msgid, NULL, Octstr *sx = date_format_http(uaprof_tstamp);
h->m->id, h->m->group_id, NULL, uaprof, uaprof_tstamp); http_header_add(hdr, "X-Mbuni-UAProf", octstr_get_cstr(uaprof));
http_header_add(hdr, "X-Mbuni-Timestamp", octstr_get_cstr(sx));
octstr_destroy(sx);
}
octstr_destroy(value); }
mms_log("ReadReport",
from, NULL, -1, msgid, NULL, h->m->id, "MMSBox", h->ua, NULL); qf = qfs->mms_queue_add(from, to, NULL,
} h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
value2, NULL,
hdr,
0,
octstr_get_cstr(qdir),
"MM7/SOAP-IN",
NULL);
if (qf)
/* Log to access log */
mms_log("Received RR", from, to, -1, msgid, value, h->m->id, "MMSBox", h->ua, NULL);
else
status = 4000;
mresp = mm7_make_resp(mreq, status, NULL,1); mresp = mm7_make_resp(mreq, status, NULL,1);
octstr_destroy(value);
octstr_destroy(value2);
http_destroy_headers(hdr);
break; break;
default: default:
@ -395,6 +395,7 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h)
return MM7_SOAP_STATUS_OK(status) ? 0 : -1; return MM7_SOAP_STATUS_OK(status) ? 0 : -1;
} }
#if 0
/* Helper func to avoid code duplication below. */ /* Helper func to avoid code duplication below. */
static void handle_report_dispatch(MmscGrp *m, Octstr *hfrom, char *rtype, List *mh, Octstr *status_hdr) static void handle_report_dispatch(MmscGrp *m, Octstr *hfrom, char *rtype, List *mh, Octstr *status_hdr)
{ {
@ -408,6 +409,7 @@ static void handle_report_dispatch(MmscGrp *m, Octstr *hfrom, char *rtype, List
octstr_destroy(value2); octstr_destroy(value2);
octstr_destroy(value3); octstr_destroy(value3);
} }
#endif
/* helper function for queueing delivery reports. */ /* 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)
@ -416,38 +418,48 @@ static int queue_dlr(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *msgid, Octs
MmsMsg *m = mms_deliveryreport(msgid, from, to, time(NULL), status); MmsMsg *m = mms_deliveryreport(msgid, from, to, time(NULL), status);
List *lto = gwlist_create(); List *lto = gwlist_create();
int ret; int ret;
Octstr *qf, *rr_uri = NULL;
List *rqh = http_create_empty_headers();
gwlist_append(lto, octstr_duplicate(to)); gwlist_append(lto, octstr_duplicate(to));
qdir = get_mmsbox_queue_dir(from, lto, mmc, &mmc_id); /* get routing info. */ qdir = get_mmsbox_queue_dir(from, lto, mmc, &mmc_id); /* get routing info. */
if (mmc_id != NULL) { /* internal routing. */ if (mmc_id != NULL) /* internal routing. */
Octstr *qf;
fixup_relayed_report(m, mmc, "delivery-report", status); /* fix it up if it is relayed. */ fixup_relayed_report(m, mmc, "delivery-report", status); /* fix it up if it is relayed. */
qf = qfs->mms_queue_add(from, lto, NULL, else {
mmc->id, mmc_id, Octstr *transid = NULL;
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL, rr_uri = get_dlr_notify_url(msgid, "delivery-report",
NULL, NULL, mmc->group_id, mmc->id,
NULL, status, &transid);
0, http_header_add(rqh, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(mmc->group_id));
octstr_get_cstr(qdir), if (transid) {
interf, http_header_add(rqh, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
NULL); octstr_destroy(transid);
if (qf) { }
/* Log to access log */
mms_log("Received DLR", from, lto, -1, NULL, NULL, mmc->id, "MMSBox", NULL, NULL);
ret = 0;
} else
ret = -1;
octstr_destroy(qf);
} else {
List *mh = mms_message_headers(m);
handle_report_dispatch(mmc, from, "delivery-report", mh, octstr_imm("X-Mms-Status"));
http_destroy_headers(mh);
ret = 0;
} }
qf = qfs->mms_queue_add(from, lto, NULL,
mmc->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
rr_uri, NULL,
rqh,
0,
octstr_get_cstr(qdir),
interf,
NULL);
if (qf) {
/* Log to access log */
mms_log("Received DLR", from, lto, -1, msgid, status, mmc->id, "MMSBox", NULL, NULL);
ret = 0;
} else
ret = -1;
octstr_destroy(qf);
http_destroy_headers(rqh);
gwlist_destroy(lto, (void *)octstr_destroy); gwlist_destroy(lto, (void *)octstr_destroy);
octstr_destroy(mmc_id); octstr_destroy(mmc_id);
mms_destroy(m); mms_destroy(m);
@ -461,11 +473,12 @@ static int mm7eaif_receive(MmsBoxHTTPClientInfo *h)
List *mh = NULL; List *mh = NULL;
int hstatus = HTTP_NO_CONTENT; int hstatus = HTTP_NO_CONTENT;
List *rh = http_create_empty_headers(); List *rh = http_create_empty_headers();
Octstr *reply_body = NULL, *value; List *rqh = http_create_empty_headers();
Octstr *reply_body = NULL, *value = NULL, *value2 = NULL;
List *to = gwlist_create(), *hto = NULL; List *to = gwlist_create(), *hto = NULL;
Octstr *subject = NULL, *otransid = NULL, *msgid = NULL; Octstr *subject = NULL, *otransid = NULL, *msgid = NULL;
Octstr *hfrom = NULL; Octstr *hfrom = NULL, *rr_uri = NULL;
time_t expiryt = -1, deliveryt = -1; time_t expiryt = -1, deliveryt = -1;
Octstr *qf = NULL, *xver, *mmc_id = NULL, *qdir = NULL; Octstr *qf = NULL, *xver, *mmc_id = NULL, *qdir = NULL;
int msize = h->body ? octstr_len(h->body) : 0; int msize = h->body ? octstr_len(h->body) : 0;
@ -578,56 +591,92 @@ static int mm7eaif_receive(MmsBoxHTTPClientInfo *h)
hstatus = HTTP_NO_CONTENT; hstatus = HTTP_NO_CONTENT;
} else } else
hstatus = HTTP_INTERNAL_SERVER_ERROR; hstatus = HTTP_INTERNAL_SERVER_ERROR;
octstr_destroy(value);
octstr_destroy(value2);
break; break;
case MMS_MSGTYPE_DELIVERY_IND: case MMS_MSGTYPE_DELIVERY_IND:
if (mmc_id != NULL) { /* internal routing. */ msgid = mms_get_header_value(m, octstr_imm("Message-ID"));
Octstr *svalue = mms_get_header_value(m, octstr_imm("X-Mms-Status")); value = mms_get_header_value(m, octstr_imm("X-Mms-Status"));
fixup_relayed_report(m, h->m, "delivery-report", svalue); /* fix it up if it is relayed. */ value2 = mms_get_header_value(m, octstr_imm("X-Mbuni-Orig-Message-ID"));
qf = qfs->mms_queue_add(hfrom, to, NULL,
h->m->id, mmc_id, if (mmc_id != NULL) /* internal routing. */
0, time(NULL) + default_msgexpiry, m, NULL, fixup_relayed_report(m, h->m, "delivery-report", value); /* fix it up if it is relayed. */
NULL, NULL, else {
NULL, NULL, Octstr *transid = NULL;
NULL,
0, rr_uri = get_dlr_notify_url(msgid, "delivery-report",
octstr_get_cstr(qdir), h->m->group_id, h->m->id,
"MM7/EAIF-IN", value, &transid);
NULL); http_header_add(rqh, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id));
if (qf) { if (transid) {
/* Log to access log */ http_header_add(rqh, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
mms_log("DeliveryReport", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL); octstr_destroy(transid);
}
hstatus = HTTP_NO_CONTENT; if (value2)
} else http_header_add(rqh, "X-Mbuni-Orig-Message-ID", octstr_get_cstr(value2));
hstatus = HTTP_INTERNAL_SERVER_ERROR; }
octstr_destroy(svalue);
} else qf = qfs->mms_queue_add(hfrom, to, NULL,
handle_report_dispatch(h->m, hfrom, "delivery-report", mh, octstr_imm("X-Mms-Status")); h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
rr_uri, NULL,
rqh,
0,
octstr_get_cstr(qdir),
"MM7/EAIF-IN",
NULL);
if (qf) {
/* Log to access log */
mms_log("DeliveryReport", hfrom, to, -1, msgid, value, h->m->id, "MMSBox", h->ua, NULL);
hstatus = HTTP_NO_CONTENT;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
octstr_destroy(value);
octstr_destroy(value2);
break; break;
case MMS_MSGTYPE_READ_ORIG_IND: case MMS_MSGTYPE_READ_ORIG_IND:
msgid = mms_get_header_value(m, octstr_imm("Message-ID"));
value = mms_get_header_value(m, octstr_imm("X-Mms-Read-Status"));
value2 = mms_get_header_value(m, octstr_imm("X-Mbuni-Orig-Message-ID"));
if (mmc_id != NULL) { /* internal routing. */ if (mmc_id != NULL) /* internal routing. */
fixup_relayed_report(m, h->m, "read-report", octstr_imm("")); /* fix it up if it is relayed. */ fixup_relayed_report(m, h->m, "read-report", octstr_imm("")); /* fix it up if it is relayed. */
qf = qfs->mms_queue_add(hfrom, to, NULL, else {
h->m->id, mmc_id, Octstr *transid = NULL;
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL, rr_uri = get_dlr_notify_url(msgid, "read-report",
NULL, NULL, h->m->group_id, h->m->id,
NULL, value, &transid);
0, http_header_add(rqh, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id));
octstr_get_cstr(qdir), if (transid) {
"MM7/EAIF-IN", http_header_add(rqh, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
NULL); octstr_destroy(transid);
if (qf) { }
/* Log to access log */ if (value2)
mms_log("Received RR", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL); http_header_add(rqh, "X-Mbuni-Orig-Message-ID", octstr_get_cstr(value2));
hstatus = HTTP_NO_CONTENT;
} else }
hstatus = HTTP_INTERNAL_SERVER_ERROR;
} else qf = qfs->mms_queue_add(hfrom, to, NULL,
handle_report_dispatch(h->m, hfrom, "read-report", mh, octstr_imm("X-Mms-Read-Status")); h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
rr_uri, NULL,
rqh,
0,
octstr_get_cstr(qdir),
"MM7/EAIF-IN",
NULL);
if (qf) {
/* Log to access log */
mms_log("Received RR", hfrom, to, -1, msgid, value, h->m->id, "MMSBox", h->ua, NULL);
hstatus = HTTP_NO_CONTENT;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
break; break;
} }
@ -640,6 +689,7 @@ static int mm7eaif_receive(MmsBoxHTTPClientInfo *h)
http_send_reply(h->client, hstatus, rh, octstr_imm("")); http_send_reply(h->client, hstatus, rh, octstr_imm(""));
http_destroy_headers(hto); http_destroy_headers(hto);
http_destroy_headers(rqh);
gwlist_destroy(to, (gwlist_item_destructor_t *)octstr_destroy); gwlist_destroy(to, (gwlist_item_destructor_t *)octstr_destroy);
octstr_destroy(hfrom); octstr_destroy(hfrom);
octstr_destroy(subject); octstr_destroy(subject);
@ -660,7 +710,7 @@ static int mm7http_receive(MmsBoxHTTPClientInfo *h)
List *mh = NULL; List *mh = NULL;
int hstatus = HTTP_OK; int hstatus = HTTP_OK;
List *rh = http_create_empty_headers(); List *rh = http_create_empty_headers();
Octstr *reply_body = NULL, *value; Octstr *reply_body = NULL;
List *to = NULL; List *to = NULL;
Octstr *hto = NULL, *subject = NULL, *msgid = NULL; Octstr *hto = NULL, *subject = NULL, *msgid = NULL;
@ -733,6 +783,7 @@ static int mm7http_receive(MmsBoxHTTPClientInfo *h)
qdir = get_mmsbox_queue_dir(hfrom, to, h->m, &mmc_id); /* get routing info. */ qdir = get_mmsbox_queue_dir(hfrom, to, h->m, &mmc_id); /* get routing info. */
switch(mtype) { switch(mtype) {
Octstr *value, *value2;
case MMS_MSGTYPE_SEND_REQ: case MMS_MSGTYPE_SEND_REQ:
case MMS_MSGTYPE_RETRIEVE_CONF: case MMS_MSGTYPE_RETRIEVE_CONF:
@ -805,56 +856,89 @@ static int mm7http_receive(MmsBoxHTTPClientInfo *h)
hstatus = HTTP_INTERNAL_SERVER_ERROR; hstatus = HTTP_INTERNAL_SERVER_ERROR;
break; break;
case MMS_MSGTYPE_DELIVERY_IND: case MMS_MSGTYPE_DELIVERY_IND:
if (mmc_id != NULL) { /* internal routing. */ msgid = mms_get_header_value(m, octstr_imm("Message-ID"));
Octstr *svalue = mms_get_header_value(m, octstr_imm("X-Mms-Status")); value = mms_get_header_value(m, octstr_imm("X-Mms-Status"));
fixup_relayed_report(m, h->m, "delivery-report", svalue); /* fix it up if it is relayed. */ value2 = mms_get_header_value(m, octstr_imm("X-Mbuni-Orig-Message-ID"));
if (mmc_id != NULL) /* internal routing. */
fixup_relayed_report(m, h->m, "delivery-report", value); /* fix it up if it is relayed. */
else {
Octstr *transid = NULL;
qf = qfs->mms_queue_add(hfrom, to, NULL, rr_uri = get_dlr_notify_url(msgid, "delivery-report",
h->m->id, mmc_id, h->m->group_id, h->m->id,
0, time(NULL) + default_msgexpiry, m, NULL, value, &transid);
NULL, NULL, http_header_add(rqh, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id));
NULL, NULL, if (transid) {
rqh, http_header_add(rqh, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
0, octstr_destroy(transid);
octstr_get_cstr(qdir), }
"MM7/HTTP-IN", if (value2)
NULL); http_header_add(rqh, "X-Mbuni-Orig-Message-ID", octstr_get_cstr(value2));
if (qf) { }
/* Log to access log */
mms_log("DeliveryReport", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL); qf = qfs->mms_queue_add(hfrom, to, NULL,
h->m->id, mmc_id,
hstatus = HTTP_OK; 0, time(NULL) + default_msgexpiry, m, NULL,
} else NULL, NULL,
hstatus = HTTP_INTERNAL_SERVER_ERROR; rr_uri, NULL,
rqh,
octstr_destroy(svalue); 0,
} else octstr_get_cstr(qdir),
handle_report_dispatch(h->m, hfrom, "delivery-report", mh, octstr_imm("X-Mms-Status")); "MM7/HTTP-IN",
NULL);
if (qf) {
/* Log to access log */
mms_log("DeliveryReport", hfrom, to, -1, msgid,value, h->m->id, "MMSBox", h->ua, NULL);
hstatus = HTTP_OK;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
octstr_destroy(value);
octstr_destroy(value2);
break; break;
case MMS_MSGTYPE_READ_ORIG_IND: case MMS_MSGTYPE_READ_ORIG_IND:
msgid = mms_get_header_value(m, octstr_imm("Message-ID"));
value = mms_get_header_value(m, octstr_imm("X-Mms-Read-Status"));
value2 = mms_get_header_value(m, octstr_imm("X-Mbuni-Orig-Message-ID"));
if (mmc_id != NULL) { /* internal routing. */ if (mmc_id != NULL) /* internal routing. */
fixup_relayed_report(m, h->m, "read-report", octstr_imm("")); fixup_relayed_report(m, h->m, "read-report", octstr_imm(""));
else {
Octstr *transid = NULL;
rr_uri = get_dlr_notify_url(msgid, "read-report",
h->m->group_id, h->m->id,
value, &transid);
http_header_add(rqh, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(h->m->group_id));
if (transid) {
http_header_add(rqh, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
octstr_destroy(transid);
}
if (value2)
http_header_add(rqh, "X-Mbuni-Orig-Message-ID", octstr_get_cstr(value2));
qf = qfs->mms_queue_add(hfrom, to, NULL, }
h->m->id, mmc_id, qf = qfs->mms_queue_add(hfrom, to, NULL,
0, time(NULL) + default_msgexpiry, m, NULL, h->m->id, mmc_id,
NULL, NULL, 0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL, NULL, NULL,
rqh, rr_uri, NULL,
0, rqh,
octstr_get_cstr(qdir), 0,
"MM7/HTTP-IN", octstr_get_cstr(qdir),
NULL); "MM7/HTTP-IN",
if (qf) { NULL);
/* Log to access log */ if (qf) {
mms_log("Received RR", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL); /* Log to access log */
hstatus = HTTP_NO_CONTENT; mms_log("Received RR", hfrom, to, -1, msgid, value, h->m->id, "MMSBox", h->ua, NULL);
} else hstatus = HTTP_NO_CONTENT;
hstatus = HTTP_INTERNAL_SERVER_ERROR; } else
} else hstatus = HTTP_INTERNAL_SERVER_ERROR;
handle_report_dispatch(h->m, hfrom, "read-report", mh, octstr_imm("X-Mms-Read-Status")); octstr_destroy(value);
octstr_destroy(value2);
break; break;
} }

View File

@ -493,6 +493,57 @@ done:
return res; return res;
} }
static int mmsbox_send_report(Octstr *from, char *report_type,
Octstr *dlr_url, Octstr *status,
Octstr *msgid, Octstr *orig_msgid,
Octstr *mmc_id, Octstr *mmc_gid,
Octstr *orig_transid, Octstr *uaprof,
Octstr* uaprof_tstamp)
{
List *rh = NULL, *rph = NULL;
Octstr *rb = NULL, *xfrom = from ? octstr_duplicate(from) : NULL;
int ret = HTTP_NOT_FOUND;
if (xfrom)
_mms_fixup_address(&xfrom, unified_prefix ? octstr_get_cstr(unified_prefix) : NULL,
strip_prefixes, 0);
rh = http_create_empty_headers();
http_header_add(rh, "X-Mbuni-Report-Type", report_type);
http_header_add(rh, "X-Mbuni-MM-Status", octstr_get_cstr(status));
if (mmc_gid)
http_header_add(rh, "X-Mbuni-MMSC-GID", octstr_get_cstr(mmc_gid));
http_header_add(rh, "X-Mbuni-MMSC-ID", octstr_get_cstr(mmc_id));
if (xfrom)
http_header_add(rh, "X-Mbuni-From", octstr_get_cstr(xfrom));
if (orig_transid)
http_header_add(rh, "X-Mbuni-TransactionID",
octstr_get_cstr(orig_transid));
if (msgid)
http_header_add(rh, "X-Mbuni-Message-ID", octstr_get_cstr(msgid));
if (orig_msgid)
http_header_add(rh, "X-Mbuni-Orig-Message-ID", octstr_get_cstr(orig_msgid));
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));
}
ret = mms_url_fetch_content(HTTP_METHOD_GET, dlr_url, rh, octstr_imm(""), &rph, &rb);
octstr_destroy(rb);
octstr_destroy(xfrom);
http_destroy_headers(rph);
http_destroy_headers(rh);
return ret == HTTP_OK ? 0 : -1;
}
static int mmsbox_service_dispatch(MmsEnvelope *e) static int mmsbox_service_dispatch(MmsEnvelope *e)
{ {
MmsMsg *msg = NULL; MmsMsg *msg = NULL;
@ -503,8 +554,11 @@ static int mmsbox_service_dispatch(MmsEnvelope *e)
MmsService *ms; MmsService *ms;
MmsEnvelopeTo *xto; MmsEnvelopeTo *xto;
gw_assert(e->msgtype == MMS_MSGTYPE_SEND_REQ || gw_assert(e->msgtype == MMS_MSGTYPE_SEND_REQ ||
e->msgtype == MMS_MSGTYPE_RETRIEVE_CONF); e->msgtype == MMS_MSGTYPE_RETRIEVE_CONF ||
e->msgtype == MMS_MSGTYPE_DELIVERY_IND ||
e->msgtype == MMS_MSGTYPE_READ_ORIG_IND);
if ((msg = qfs->mms_queue_getdata(e)) == NULL) { if ((msg = qfs->mms_queue_getdata(e)) == NULL) {
err = octstr_format("Failed to read message for queue entry %s!", err = octstr_format("Failed to read message for queue entry %s!",
@ -525,7 +579,52 @@ static int mmsbox_service_dispatch(MmsEnvelope *e)
mmsbox_maxsendattempts); mmsbox_maxsendattempts);
res = -1; res = -1;
goto done; goto done;
} else if (gwlist_len(e->to) == 0) { /* nothing to do. odd XXX */ }
if (e->msgtype == MMS_MSGTYPE_DELIVERY_IND ||
e->msgtype == MMS_MSGTYPE_READ_ORIG_IND) {
char *report_type = (e->msgtype == MMS_MSGTYPE_DELIVERY_IND) ? "delivery-report" : "read-report";
Octstr *msgid = mms_get_header_value(msg, octstr_imm("Message-ID"));
Octstr *orig_msgid = e->hdrs ?
http_header_value(e->hdrs, octstr_imm("X-Mbuni-Orig-Message-ID")) : NULL;
Octstr *status = mms_get_header_value(msg,
e->msgtype == MMS_MSGTYPE_DELIVERY_IND ?
octstr_imm("X-Mms-Status") :
octstr_imm("X-Mms-Read-Status"));
Octstr *orig_transid = e->hdrs ?
http_header_value(e->hdrs, octstr_imm("X-Mbuni-TransactionID")) : NULL;
Octstr *uaprof = e->hdrs ?
http_header_value(e->hdrs, octstr_imm("X-Mbuni-UAProf")) : NULL;
Octstr *tstamp = e->hdrs ?
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;
if (e->url1)
res = mmsbox_send_report(e->from, report_type,
e->url1, status, msgid, orig_msgid,
e->fromproxy, gid, orig_transid,
uaprof,tstamp);
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));
res = 0;
}
octstr_destroy(msgid);
octstr_destroy(orig_msgid);
octstr_destroy(status);
octstr_destroy(orig_transid);
octstr_destroy(uaprof);
octstr_destroy(tstamp);
octstr_destroy(gid);
goto done; /* No more processing. */
}
if (gwlist_len(e->to) == 0) { /* nothing to do. odd XXX */
res = 0; res = 0;
goto done; goto done;
} }