From 60be3311ca568ea05cd5d72eccfb3c4606a26a1c Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Tue, 26 Oct 2010 17:40:49 +0000 Subject: [PATCH] misc bug fixes --- mbuni/ChangeLog | 2 ++ mbuni/configure.ac | 4 ++-- mbuni/mmlib/mms_util.c | 46 +++++++++++++++++++++++++-------------- mbuni/mmsbox/bearerbox.c | 41 ++++++++++++++++++++-------------- mbuni/mmsbox/dlr.c | 2 +- mbuni/mmsbox/mmsbox_cdr.c | 5 ++--- mbuni/mmsbox/mmsbox_cfg.c | 2 +- 7 files changed, 63 insertions(+), 39 deletions(-) diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index ba98d8b..ce0450b 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2010-10-26 P. A. Bagyenda + * Misc bug fixes 2010-10-25 P. A. Bagyenda * Added MM4 incoming handler for mmsbox 2010-10-22 P. A. Bagyenda diff --git a/mbuni/configure.ac b/mbuni/configure.ac index a4886f0..c8319ff 100644 --- a/mbuni/configure.ac +++ b/mbuni/configure.ac @@ -78,11 +78,11 @@ case "$host" in EXE_EXT=".exe" ;; *apple-darwin*) - CFLAGS="$CFLAGS -DDARWIN=1 -O4 -Wall" + CFLAGS="$CFLAGS -DDARWIN=1 -O4 -Wall -D_REENTRANT=1" LIB_EXT="dylib" ;; *-linux*) - CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -O4 -Wall" + CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600 -D_BSD_SOURCE -O4 -Walli -D_REENTRANT=1" LDFLAGS="$LDFLAGS -rdynamic" ;; *-*-openbsd*) diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index 2c6d08b..04b05f4 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -534,9 +534,13 @@ static int send2email(Octstr *to, Octstr *from, Octstr *subject, Octstr *s; FILE *f; int ret = MMS_SEND_OK, i, n; + char fname[L_tmpnam]; + Octstr *cmd = octstr_create(""); List *headers = mime_entity_headers(m); /* we don't want the mime version header removed. */ + fname[0] = 0; + if (append_hostname) { /* Add our hostname to all phone numbers. */ List *l = http_create_empty_headers(); Octstr *xfrom = http_header_value(headers, octstr_imm("From")); @@ -661,33 +665,44 @@ static int send2email(Octstr *to, Octstr *from, Octstr *subject, } i += 2; } - - - debug("mms.sendtoemail", 0, "preparing to execute %s to send to email: ", octstr_get_cstr(cmd)); - if ((f = popen(octstr_get_cstr(cmd), "w")) == NULL) { - *error = octstr_format("popen failed for %S: %d: %s", - cmd, errno, strerror(errno)); + if (tmpnam(fname) == NULL) { + *error = octstr_format("tmpnam: Failed to create temporary file: %s", + strerror(errno)); ret = MMS_SEND_ERROR_TRANSIENT; goto done; } - - if (octstr_print(f, s) < 0) { - *error = octstr_format("send email failed in octstr_print %d: %s", - errno, strerror(errno)); - pclose(f); - ret = MMS_SEND_ERROR_TRANSIENT; + if ((f = fopen(fname, "w")) == NULL) { + *error = octstr_format("fopen failed for %s: %s", + fname, strerror(errno)); + ret = MMS_SEND_ERROR_TRANSIENT; goto done; } - if ((ret = pclose(f)) != 0) { - *error = octstr_format("Send email command returned non-zero %d: errno=%s", - ret, strerror(errno)); + if (octstr_print(f, s) < 0) { + *error = octstr_format("send email failed in write temp file %d: %s", + errno, strerror(errno)); + fclose(f); ret = MMS_SEND_ERROR_TRANSIENT; + goto done; + } else + fclose(f); + + octstr_format_append(cmd, " < '%s'", fname); + + debug("mms.sendtoemail", 0, "preparing to execute %s to send to email: ", octstr_get_cstr(cmd)); + + if (system(octstr_get_cstr(cmd)) != 0) { + *error = octstr_format("system(%S) failed: %d: %s", + cmd, errno, strerror(errno)); + ret = MMS_SEND_ERROR_TRANSIENT; + goto done; } else ret = MMS_SEND_QUEUED; done: + if (fname[0]) + unlink(fname); http_destroy_headers(headers); octstr_destroy(cmd); octstr_destroy(s); @@ -715,7 +730,6 @@ int mms_sendtoemail(Octstr *from, Octstr *to, char *transid, List *extra_headers) { - MIMEEntity *m = NULL; List *headers = NULL; List *newhdrs = http_create_empty_headers(); diff --git a/mbuni/mmsbox/bearerbox.c b/mbuni/mmsbox/bearerbox.c index 9059ed5..c6a4b68 100644 --- a/mbuni/mmsbox/bearerbox.c +++ b/mbuni/mmsbox/bearerbox.c @@ -467,7 +467,7 @@ static int queue_dlr(MmscGrp *mmc, Octstr *from, Octstr *to, Octstr *msgid, Octs rr_uri = mmsbox_get_report_info(m, mmc, mmc_id, "delivery-report", status, rqh, NULL, 0, msgid); - mmsbox_event_cb(mmc->id, MM7_TAG_DeliveryReportReq, 0,octstr_imm("5.3.0"), 200, + mmsbox_event_cb(mmc ? mmc->id : NULL, MM7_TAG_DeliveryReportReq, 0,octstr_imm("5.3.0"), 200, 0, 0, from, lto && gwlist_len(lto) > 0 ? gwlist_get(lto,0) : NULL, msgid, NULL, NULL, status); @@ -539,7 +539,7 @@ static int mm7eaif_receive(MmsBoxHTTPClientInfo *h) /* XXXX handle delivery reports differently. */ mtype = mms_messagetype(m); - mm7type = mm7_msgtype_to_soaptype(mtype, 1); + mm7type = mm7_msgtype_to_soaptype(mtype, 0); mh = mms_message_headers(m); /* Now get sender and receiver data. * for now we ignore adaptation flags. @@ -803,7 +803,7 @@ static int mm7http_receive(MmsBoxHTTPClientInfo *h) to = octstr_split_words(hto); mtype = mms_messagetype(m); - mm7type = mm7_msgtype_to_soaptype(mtype, 1); + mm7type = mm7_msgtype_to_soaptype(mtype, 0); mh = mms_message_headers(m); /* find interesting headers. */ @@ -1631,12 +1631,13 @@ static int sendMsg(MmsEnvelope *e) "", "", 0, e->xqfname, - e->hdrs); - if (res == MMS_SEND_OK || res == MMS_SEND_QUEUED) + e->hdrs); + if (res == MMS_SEND_OK || res == MMS_SEND_QUEUED) { + new_msgid = e->msgId ? octstr_duplicate(e->msgId) : octstr_create("00001"); /* Fake it */ mmsbox_event_cb(NULL, MM7_TAG_SubmitReq, 1, octstr_imm("1.0"), 200, mms_msgsize(msg), e->attempts, pfrom, to->rcpt,NULL, NULL, e->hdrs, NULL); - + } octstr_destroy(pfrom); octstr_destroy(xto); } else { @@ -1657,14 +1658,7 @@ static int sendMsg(MmsEnvelope *e) octstr_destroy(x); } } - if (mmc) { - if (res == MMS_SEND_OK) - mmc->mt_pdus++; - else - mmc->mt_errors++; - mmc->last_pdu = time(NULL); - return_mmsc_conn(mmc); /* important. */ - } + done: if (res == MMS_SEND_OK || res == MMS_SEND_QUEUED) { to->process = 0; @@ -1680,6 +1674,16 @@ static int sendMsg(MmsEnvelope *e) octstr_imm("Expired") : octstr_imm("Rejected"), "MM7-Out", errl); } + + if (mmc) { + if (res == MMS_SEND_OK || res == MMS_SEND_QUEUED) + mmc->mt_pdus++; + else + mmc->mt_errors++; + mmc->last_pdu = time(NULL); + return_mmsc_conn(mmc); /* important. */ + } + if (res == MMS_SEND_ERROR_FATAL) to->process = 0; /* No more attempts. */ @@ -1949,6 +1953,7 @@ static Octstr *handle_msg(MIMEEntity *mm, Octstr *from, List *to, MmscGrp *mmc) } else msg = NULL; + mm7type = mm7_msgtype_to_soaptype(mm1_type,0); me = octstr_format("system-user@%S", myhostname); qdir = get_mmsbox_queue_dir(from, to, mmc, &mmc_id); /* get routing info. */ @@ -2085,7 +2090,7 @@ static Octstr *handle_msg(MIMEEntity *mm, Octstr *from, List *to, MmscGrp *mmc) break; } - mm7type = mm7_msgtype_to_soaptype(mm1_type,1); + if (mm7type >= 0) /* Issue event call back */ mmsbox_event_cb(mmc->id, mm7type, 1, octstr_imm("1.0"), 200, mms_msgsize(msg), 0, from, @@ -2101,7 +2106,11 @@ static Octstr *handle_msg(MIMEEntity *mm, Octstr *from, List *to, MmscGrp *mmc) mmsbox_event_cb(mmc->id, mm7type >= 0 ? mm7type + 1 : MM7_TAG_VASPErrorRsp, 1, octstr_imm("1.0"), 200, size, 0, me, orig_sys, res, NULL, NULL, NULL); - } + } else if (mtype == MM4_FORWARD_REQ) /* Or straight up SMTP */ + mmsbox_event_cb(mmc->id, mm7type >= 0 ? mm7type + 1 : MM7_TAG_VASPErrorRsp, + 1, octstr_imm("1.0"), 200, + 0, 0, me, orig_sys, res, NULL, NULL, NULL); + octstr_destroy(mm4_type); octstr_destroy(transid); octstr_destroy(orig_sys); diff --git a/mbuni/mmsbox/dlr.c b/mbuni/mmsbox/dlr.c index 601c6c6..eabcd3b 100644 --- a/mbuni/mmsbox/dlr.c +++ b/mbuni/mmsbox/dlr.c @@ -47,7 +47,7 @@ static int dlr_entry_fname(char *msgid, char *rtype, Octstr *mmc_gid, Octstr **e d2[2] = '\0'; /* Try and create the next level dir (first level was created by root_init) */ - sprintf(fbuf, "%s/%s/%s", octstr_get_cstr(dlr_dir), d1, d2); + sprintf(fbuf, "%.128s/%s/%s", octstr_get_cstr(dlr_dir), d1, d2); if (mkdir(fbuf, S_IRWXU|S_IRWXG) < 0 && errno != EEXIST) { diff --git a/mbuni/mmsbox/mmsbox_cdr.c b/mbuni/mmsbox/mmsbox_cdr.c index 844c98c..48c69a0 100644 --- a/mbuni/mmsbox/mmsbox_cdr.c +++ b/mbuni/mmsbox/mmsbox_cdr.c @@ -135,8 +135,7 @@ static void fill_cdr_struct(MmsBoxCdrStruct *cdr, cdr->sdate = sdate; -#define COPY_CDR_FIELD(fld) if (fld) \ - strncpy(cdr->fld, fld, sizeof cdr->fld) +#define COPY_CDR_FIELD(fld) if (fld) strncpy(cdr->fld, fld, sizeof cdr->fld) COPY_CDR_FIELD(from); COPY_CDR_FIELD(to); @@ -164,7 +163,7 @@ static int cdr_module_logcdr(time_t sdate, char *from, char *to, char *msgid, char *status, int dlr, int rr) { - MmsBoxCdrStruct *xcdr = gw_malloc(sizeof *xcdr); + MmsBoxCdrStruct *xcdr = gw_malloc(sizeof xcdr[0]); gw_assert(req_list); diff --git a/mbuni/mmsbox/mmsbox_cfg.c b/mbuni/mmsbox/mmsbox_cfg.c index 197023d..9379e1a 100644 --- a/mbuni/mmsbox/mmsbox_cfg.c +++ b/mbuni/mmsbox/mmsbox_cfg.c @@ -549,10 +549,10 @@ static void mmsbox_stop_mmsc_conn_real(MmscGrp *mmc) else if (mmc->incoming.port > 0) { http_close_port(mmc->incoming.port); hmon->unregister_port(mmc->incoming.port); - MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_HTTP_DOWN, 1); if (mmc->threadid >= 0) gwthread_join(mmc->threadid); mmc->threadid = -1; + MMSC_ISSUE_ALARM(mmc, MMSBOX_ALARM_HTTP_DOWN, 1); } mms_info(0, "mmsbox", NULL,"Shutdown for mmsc [%s] complete", octstr_get_cstr(mmc->id)); }