From be8dc0ee28879744a8edd0d6a24ceabd836b56ac Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Mon, 16 Dec 2013 09:22:49 +0000 Subject: [PATCH] Added Fix from Jacek Raczkiewicz --- mbuni/ChangeLog | 2 + mbuni/doc/userguide.shtml | 17 ++++++- mbuni/extras/pgsql-queue/mms_pgsql_queue.c | 2 +- mbuni/mmlib/mms_cfg.def | 1 + mbuni/mmsbox/bearerbox.c | 58 ++++++++++++++++++++-- mbuni/mmsbox/mmsbox_cfg.c | 9 ++++ mbuni/mmsbox/mmsbox_cfg.h | 2 + 7 files changed, 86 insertions(+), 5 deletions(-) diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index 6c3183d..b3d1a7b 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2013-12-16 P. A. Bagyenda + * Misc speed-ups and patches thanks to Jacek Raczkiewicz (jacek at skycore.com) 2012-04-10 P. A. Bagyenda * Added ability to receive carrier ID info via special HTTP header in SOAP request to mmsbox (a la OpenMarket) 2011-10-11 P. A. Bagyenda diff --git a/mbuni/doc/userguide.shtml b/mbuni/doc/userguide.shtml index b06ac1e..1693dd9 100644 --- a/mbuni/doc/userguide.shtml +++ b/mbuni/doc/userguide.shtml @@ -3257,7 +3257,22 @@ string in a X-Mbuni-CarrierID header. -1 + + + + retry-statuses + +     + + + String + + + + Optional. Semicolon separated list of HTTP and MM7 statuses that makes MBUNI to retry sending to MMSC. + MM7 statuses are checked only when HTTP 200 is received from MMSC (HTTP 200 is always assumed as retry status). + + diff --git a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c index e91738f..9125a2f 100644 --- a/mbuni/extras/pgsql-queue/mms_pgsql_queue.c +++ b/mbuni/extras/pgsql-queue/mms_pgsql_queue.c @@ -1166,7 +1166,7 @@ static void pgdeliver(struct PGDeliverData_t *pgdata) /* we're done, exit. */ mms_info(0, "pgdeliver", NULL, "Shutdown on queue [%s]", pgdata->dir); } -#define MAX_QLEN 10 /* we don't allow more than this number pending per thread. */ +#define MAX_QLEN 10000 /* we don't allow more than this number pending per thread. */ static void pgq_queue_run(char *dir, int (*deliver)(MmsEnvelope *), double sleepsecs, int num_threads, volatile sig_atomic_t *rstop) diff --git a/mbuni/mmlib/mms_cfg.def b/mbuni/mmlib/mms_cfg.def index fcdb5c0..2b47891 100644 --- a/mbuni/mmlib/mms_cfg.def +++ b/mbuni/mmlib/mms_cfg.def @@ -198,6 +198,7 @@ MULTI_GROUP(mmsc, OCTSTR(max-recipients) OCTSTR(strip-prefixes) + OCTSTR(retry-statuses) OCTSTR(mm1-http-proxy) OCTSTR(mm1-gprs-on-command) OCTSTR(mm1-gprs-off-command) diff --git a/mbuni/mmsbox/bearerbox.c b/mbuni/mmsbox/bearerbox.c index 1bda800..2cbd46d 100644 --- a/mbuni/mmsbox/bearerbox.c +++ b/mbuni/mmsbox/bearerbox.c @@ -1112,6 +1112,30 @@ void mmsc_receive_func(MmscGrp *m) } +/* This function check if there is custom retry statuses list setup for mmc, + * if not it returns -1, + * if it is set check if current status should be retried (returns 1) or not (returns 0) + */ + +int check_custom_retry_statuses(MmscGrp *mmc, int hstatus) { + int retry_sending = -1, i, n; + Octstr *res_str = octstr_format("%d", hstatus); + if (mmc && mmc->retry_statuses != NULL) { + retry_sending = 0; + for (i = 0, n = gwlist_len(mmc->retry_statuses); iretry_statuses, i); + if (octstr_compare(res_str, retry_status) == 0) { + retry_sending = 1; + break; + } + } + } + octstr_destroy(res_str); + + return retry_sending; +} + + /* XXX Returns msgid in mmsc or NULL if error. Caller uses this for DLR issues. * Caller must make sure throughput issues * are observed! @@ -1137,6 +1161,7 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, List *lto, Octstr *s, *r, *status_details = NULL; char *xvasid = vasid ? vasid : (mmc->default_vasid ? octstr_get_cstr(mmc->default_vasid) : NULL); Octstr *to; + int retry_sending = -1; LINEARISE_STR_LIST(to,lto,", "); @@ -1173,6 +1198,10 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, List *lto, mmc->mmsc_url, hstatus); if (hstatus < 0) MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_SOCKET_CONNECT_FAILED, 3); + + /* Now check if we should retry */ + retry_sending = check_custom_retry_statuses(mmc, hstatus); + MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_MM7_NON_200_RESULT, 3); goto done1; } else { @@ -1227,6 +1256,9 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, List *lto, tstatus = MM7_SOAP_FORMAT_CORRUPT; } + /* Now check if we should retry */ + retry_sending = check_custom_retry_statuses(mmc, tstatus); + if (!MM7_SOAP_STATUS_OK(tstatus) && tstatus != MM7_SOAP_COMMAND_REJECTED) { char *tmp = (char *)mms_soap_status_to_cstr(tstatus); @@ -1263,7 +1295,10 @@ static Octstr *mm7soap_send(MmscGrp *mmc, Octstr *from, List *lto, if (ret) mms_log2("Sent", from, to, -1, ret, NULL, mmc->id, "MMSBox", NULL, NULL); done1: - *retry = (ret == NULL && (!MM7_SOAP_CLIENT_ERROR(tstatus) || tstatus < 0)); + //DEFAULT when retry_sending < 0 + //otherwise we rely on retry_status list + if (retry_sending < 0) *retry = (ret == NULL && (!MM7_SOAP_CLIENT_ERROR(tstatus) || tstatus < 0)); + else *retry = retry_sending; mm7_soap_destroy(mreq); mm7_soap_destroy(mresp); @@ -1295,6 +1330,7 @@ static Octstr *mm7eaif_send(MmscGrp *mmc, Octstr *from, List *lto, MmsMsg *mresp = NULL; int mresp_type = -1, i; Octstr *to; + int retry_sending = -1; LINEARISE_STR_LIST(to,lto,", "); @@ -1351,6 +1387,10 @@ static Octstr *mm7eaif_send(MmscGrp *mmc, Octstr *from, List *lto, mmc->mmsc_url, hstatus); if (hstatus < 0) MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_SOCKET_CONNECT_FAILED, 3); + + /* Now check if we should retry */ + retry_sending = check_custom_retry_statuses(mmc, hstatus); + MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_MM7_NON_200_RESULT, 3); } else { MMSC_CLEAR_ALARM(mmc, MMSBOX_ALARM_MM7_NON_200_RESULT); @@ -1377,7 +1417,11 @@ static Octstr *mm7eaif_send(MmscGrp *mmc, Octstr *from, List *lto, else if (!ret) ret = http_header_value(ph, octstr_imm("X-Nokia-MMSC-Message-Id")); } - *retry = (ret == NULL && (hstatus == HTTP_STATUS_SERVER_ERROR || hstatus < 0)); + + //DEFAULT when retry_sending < 0 + //otherwise we rely on retry_status list + if (retry_sending < 0) *retry = (ret == NULL && (hstatus == HTTP_STATUS_SERVER_ERROR || hstatus < 0)); + else *retry = retry_sending; mmsbox_event_cb(mmc->id, mm7_msgtype_to_soaptype(mresp_type,1), 0, xver, hstatus, @@ -1423,6 +1467,7 @@ static Octstr *mm7http_send(MmscGrp *mmc, Octstr *transid = e ? octstr_create(e->xqfname) : NULL; int mm7type = mm7_msgtype_to_soaptype(mtype,1); Octstr *to; + int retry_sending = -1; LINEARISE_STR_LIST(to,lto," "); @@ -1453,6 +1498,10 @@ static Octstr *mm7http_send(MmscGrp *mmc, mmc->mmsc_url, hstatus); if (hstatus < 0) MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_SOCKET_CONNECT_FAILED, 3); + + /* Now check if we should retry */ + retry_sending = check_custom_retry_statuses(mmc, hstatus); + MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_MM7_NON_200_RESULT, 3); } else { ret = rbody ? octstr_duplicate(rbody) : NULL; @@ -1467,7 +1516,10 @@ static Octstr *mm7http_send(MmscGrp *mmc, 0, e->attempts, e->from, to, ret, transid, hdrs, NULL); - *retry = (ret == NULL && (http_status_class(hstatus) == HTTP_STATUS_SERVER_ERROR || hstatus < 0)); + //DEFAULT when retry_sending < 0 + //otherwise we rely on retry_status list + if (retry_sending < 0) *retry = (ret == NULL && (http_status_class(hstatus) == HTTP_STATUS_SERVER_ERROR || hstatus < 0)); + else *retry = retry_sending; if (ret) mms_log2("Sent", from, to, -1, ret, NULL, mmc->id, "MMSBox", NULL, NULL); diff --git a/mbuni/mmsbox/mmsbox_cfg.c b/mbuni/mmsbox/mmsbox_cfg.c index 43d4de5..1d38697 100644 --- a/mbuni/mmsbox/mmsbox_cfg.c +++ b/mbuni/mmsbox/mmsbox_cfg.c @@ -635,6 +635,14 @@ static MmscGrp *start_mmsc_from_conf(mCfg *cfg, mCfgGrp *x, List *warnings, List octstr_destroy(s); } else m->strip_prefixes = NULL; + + if ((s = mms_cfg_get(cfg, x, octstr_imm("retry-statuses"))) != NULL) { + m->retry_statuses = octstr_split(s, octstr_imm(";")); + octstr_destroy(s); + } else + m->retry_statuses = NULL; + + if (mms_cfg_get_int(cfg,x, octstr_imm("maximum-request-size"), &m->max_pkt_size) < 0 || m->max_pkt_size <= 0) @@ -1299,6 +1307,7 @@ static void free_mmsc_struct (MmscGrp *m) octstr_destroy(m->settings); mutex_destroy(m->mutex); gwlist_destroy(m->strip_prefixes, (void *)octstr_destroy); + gwlist_destroy(m->retry_statuses, (void *)octstr_destroy); octstr_destroy(m->mm1.proxy); octstr_destroy(m->mm1.gprs_on); diff --git a/mbuni/mmsbox/mmsbox_cfg.h b/mbuni/mmsbox/mmsbox_cfg.h index fe817cb..86857cb 100644 --- a/mbuni/mmsbox/mmsbox_cfg.h +++ b/mbuni/mmsbox/mmsbox_cfg.h @@ -89,6 +89,8 @@ typedef struct MmscGrp { List *strip_prefixes; /* List of prefixes to be stripped before sending out*/ + List *retry_statuses; /* List of HTTP/MM7 statuses we do retry on, MM7 statuses are checked only on HTTP 200 - they do not overlap*/ + struct MM1Info_t { /* Stuff used only by the MM1 MMSC */ Octstr *proxy; /* Proxy within the operator network, form of host:port */ Octstr *gprs_on; /* Command to start GPRS link. Must not exit. */