1
0
Fork 0

added retries to DLR URL calling in mmsbox

master
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>
* Minor fix for base64 decoding in URI with data: schema
2008-10-16 P. A. Bagyenda <bayenda@dsmagic.com>

View File

@ -1,6 +1,6 @@
dnl Mbuni - Open Source MMS Gateway
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 Paul Bagyenda <bagyenda@dsmagic.com>
dnl

View File

@ -34,7 +34,7 @@ CREATE VIEW mms_messages_view AS SELECT
-- Table for envelope headers.
CREATE TABLE mms_message_headers (
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,
value text NOT NULL

View File

@ -78,58 +78,34 @@ done:
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,
time_t uaprof_tstamp)
static Octstr *get_dlr_notify_url(Octstr *msgid, char *report_type, Octstr *mmc_gid, Octstr *mmc_id,
Octstr *status,
Octstr **transid)
{
Octstr *url = NULL;
List *rh = NULL, *rph = NULL;
Octstr *rb = NULL;
Octstr *xtransid = NULL;
if (dlr_url)
url = octstr_duplicate(dlr_url);
Octstr *xtransid = NULL, *url = NULL;
mms_dlr_url_get(msgid, report_type, mmc_gid, &url, &xtransid);
if (transid)
*transid = xtransid;
else
mms_dlr_url_get(msgid, report_type, mmc_gid, &url, &xtransid);
octstr_destroy(xtransid);
if (octstr_len(url) == 0) {
if (url)
mms_info(0, "MM7", NULL,
"Sending delivery-report skipped: `url' is empty, `group_id'=[%s], `msgid'=[%s]",
octstr_get_cstr(mmc_gid), octstr_get_cstr(msgid));
octstr_destroy(url);
url = NULL;
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;
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,
* 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("Forwarded")) != 0))
mms_dlr_url_remove(msgid, report_type, mmc_gid);
done:
done:
octstr_destroy(rb);
octstr_destroy(url);
octstr_destroy(xtransid);
http_destroy_headers(rph);
http_destroy_headers(rh);
return 0;
return url;
}
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. */
switch (mm7_msgtype(mreq)) {
Octstr *value;
Octstr *value, *value2;
List *hdr;
case MM7_TAG_DeliverReq:
m = mm7_soap_to_mmsmsg(mreq, from);
if (m) {
@ -281,84 +252,113 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h)
case MM7_TAG_DeliveryReportReq:
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. */
m = mm7_soap_to_mmsmsg(mreq, from);
if (m) {
if (m)
fixup_relayed_report(m, h->m, "delivery-report",
value); /* fix it up if it is relayed. */
qf = qfs->mms_queue_add(from, to, NULL,
h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, 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"));
hdr = NULL;
value2 = NULL;
} else { /* routing to URL -- get it. */
Octstr *transid = NULL;
msgid = mm7_soap_header_value(mreq, octstr_imm("MessageID"));
mms_info(0, "MM7", h->m->id, "Sending delivery-report [FROM:%s] [VALUE:%s] [DESC:%s] [MSGID:%s]",
octstr_get_cstr(from), octstr_get_cstr(value), octstr_get_cstr(desc),
octstr_get_cstr(h->m->id));
mmsbox_send_report(from, "delivery-report", NULL,
value, msgid, NULL, h->m->id, h->m->group_id, NULL, uaprof, uaprof_tstamp);
mms_log("DeliveryReport",
from, NULL, -1, msgid, value, h->m->id, "MMSBox", h->ua, NULL);
octstr_destroy(desc);
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));
if (transid) {
http_header_add(hdr, "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));
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);
octstr_destroy(value);
octstr_destroy(value2);
http_destroy_headers(hdr);
break;
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(""));
qf = qfs->mms_queue_add(from, to, NULL,
h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, 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 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"));
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));
if (transid) {
http_header_add(hdr, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
octstr_destroy(transid);
}
mmsbox_send_report(from,
"read-report", NULL, value, msgid, NULL,
h->m->id, h->m->group_id, NULL, uaprof, uaprof_tstamp);
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);
}
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);
octstr_destroy(value);
octstr_destroy(value2);
http_destroy_headers(hdr);
break;
default:
@ -395,6 +395,7 @@ static int mm7soap_receive(MmsBoxHTTPClientInfo *h)
return MM7_SOAP_STATUS_OK(status) ? 0 : -1;
}
#if 0
/* Helper func to avoid code duplication below. */
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(value3);
}
#endif
/* helper function for queueing delivery reports. */
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);
List *lto = gwlist_create();
int ret;
Octstr *qf, *rr_uri = NULL;
List *rqh = http_create_empty_headers();
gwlist_append(lto, octstr_duplicate(to));
qdir = get_mmsbox_queue_dir(from, lto, mmc, &mmc_id); /* get routing info. */
if (mmc_id != NULL) { /* internal routing. */
Octstr *qf;
if (mmc_id != NULL) /* internal routing. */
fixup_relayed_report(m, mmc, "delivery-report", status); /* fix it up if it is relayed. */
qf = qfs->mms_queue_add(from, lto, NULL,
mmc->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
NULL, NULL,
NULL,
0,
octstr_get_cstr(qdir),
interf,
NULL);
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"));
else {
Octstr *transid = NULL;
rr_uri = get_dlr_notify_url(msgid, "delivery-report",
mmc->group_id, mmc->id,
status, &transid);
http_header_add(rqh, "X-Mbuni-Mmsc-GroupID", octstr_get_cstr(mmc->group_id));
if (transid) {
http_header_add(rqh, "X-Mbuni-TransactionID", octstr_get_cstr(transid));
octstr_destroy(transid);
}
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);
octstr_destroy(mmc_id);
mms_destroy(m);
@ -461,11 +473,12 @@ static int mm7eaif_receive(MmsBoxHTTPClientInfo *h)
List *mh = NULL;
int hstatus = HTTP_NO_CONTENT;
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;
Octstr *subject = NULL, *otransid = NULL, *msgid = NULL;
Octstr *hfrom = NULL;
Octstr *hfrom = NULL, *rr_uri = NULL;
time_t expiryt = -1, deliveryt = -1;
Octstr *qf = NULL, *xver, *mmc_id = NULL, *qdir = NULL;
int msize = h->body ? octstr_len(h->body) : 0;
@ -578,56 +591,92 @@ static int mm7eaif_receive(MmsBoxHTTPClientInfo *h)
hstatus = HTTP_NO_CONTENT;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
octstr_destroy(value);
octstr_destroy(value2);
break;
case MMS_MSGTYPE_DELIVERY_IND:
if (mmc_id != NULL) { /* internal routing. */
Octstr *svalue = 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. */
qf = qfs->mms_queue_add(hfrom, to, NULL,
h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
NULL, NULL,
NULL,
0,
octstr_get_cstr(qdir),
"MM7/EAIF-IN",
NULL);
if (qf) {
/* Log to access log */
mms_log("DeliveryReport", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL);
hstatus = HTTP_NO_CONTENT;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
octstr_destroy(svalue);
} else
handle_report_dispatch(h->m, hfrom, "delivery-report", mh, octstr_imm("X-Mms-Status"));
msgid = mms_get_header_value(m, octstr_imm("Message-ID"));
value = mms_get_header_value(m, octstr_imm("X-Mms-Status"));
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;
rr_uri = get_dlr_notify_url(msgid, "delivery-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,
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;
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. */
qf = qfs->mms_queue_add(hfrom, to, NULL,
h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
NULL, NULL,
NULL,
0,
octstr_get_cstr(qdir),
"MM7/EAIF-IN",
NULL);
if (qf) {
/* Log to access log */
mms_log("Received RR", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL);
hstatus = HTTP_NO_CONTENT;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
} else
handle_report_dispatch(h->m, hfrom, "read-report", mh, octstr_imm("X-Mms-Read-Status"));
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,
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;
}
@ -640,6 +689,7 @@ static int mm7eaif_receive(MmsBoxHTTPClientInfo *h)
http_send_reply(h->client, hstatus, rh, octstr_imm(""));
http_destroy_headers(hto);
http_destroy_headers(rqh);
gwlist_destroy(to, (gwlist_item_destructor_t *)octstr_destroy);
octstr_destroy(hfrom);
octstr_destroy(subject);
@ -660,7 +710,7 @@ static int mm7http_receive(MmsBoxHTTPClientInfo *h)
List *mh = NULL;
int hstatus = HTTP_OK;
List *rh = http_create_empty_headers();
Octstr *reply_body = NULL, *value;
Octstr *reply_body = NULL;
List *to = 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. */
switch(mtype) {
Octstr *value, *value2;
case MMS_MSGTYPE_SEND_REQ:
case MMS_MSGTYPE_RETRIEVE_CONF:
@ -805,56 +856,89 @@ static int mm7http_receive(MmsBoxHTTPClientInfo *h)
hstatus = HTTP_INTERNAL_SERVER_ERROR;
break;
case MMS_MSGTYPE_DELIVERY_IND:
if (mmc_id != NULL) { /* internal routing. */
Octstr *svalue = 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. */
msgid = mms_get_header_value(m, octstr_imm("Message-ID"));
value = mms_get_header_value(m, octstr_imm("X-Mms-Status"));
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,
h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
NULL, NULL,
rqh,
0,
octstr_get_cstr(qdir),
"MM7/HTTP-IN",
NULL);
if (qf) {
/* Log to access log */
mms_log("DeliveryReport", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL);
hstatus = HTTP_OK;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
octstr_destroy(svalue);
} else
handle_report_dispatch(h->m, hfrom, "delivery-report", mh, octstr_imm("X-Mms-Status"));
rr_uri = get_dlr_notify_url(msgid, "delivery-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,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
rr_uri, NULL,
rqh,
0,
octstr_get_cstr(qdir),
"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;
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(""));
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,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
NULL, NULL,
rqh,
0,
octstr_get_cstr(qdir),
"MM7/HTTP-IN",
NULL);
if (qf) {
/* Log to access log */
mms_log("Received RR", hfrom, to, -1, NULL, NULL, h->m->id, "MMSBox", h->ua, NULL);
hstatus = HTTP_NO_CONTENT;
} else
hstatus = HTTP_INTERNAL_SERVER_ERROR;
} else
handle_report_dispatch(h->m, hfrom, "read-report", mh, octstr_imm("X-Mms-Read-Status"));
}
qf = qfs->mms_queue_add(hfrom, to, NULL,
h->m->id, mmc_id,
0, time(NULL) + default_msgexpiry, m, NULL,
NULL, NULL,
rr_uri, NULL,
rqh,
0,
octstr_get_cstr(qdir),
"MM7/HTTP-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;
octstr_destroy(value);
octstr_destroy(value2);
break;
}

View File

@ -493,6 +493,57 @@ done:
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)
{
MmsMsg *msg = NULL;
@ -503,8 +554,11 @@ static int mmsbox_service_dispatch(MmsEnvelope *e)
MmsService *ms;
MmsEnvelopeTo *xto;
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) {
err = octstr_format("Failed to read message for queue entry %s!",
@ -525,7 +579,52 @@ static int mmsbox_service_dispatch(MmsEnvelope *e)
mmsbox_maxsendattempts);
res = -1;
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;
goto done;
}