From 35e33941c7f88e3f43fb229b5c42d3d2f39613d3 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Fri, 24 Feb 2006 05:15:26 +0000 Subject: [PATCH] Added gw_assert() calls and better error checking in mms_msg module --- mbuni/mmlib/mms_cfg.c | 9 ++---- mbuni/mmlib/mms_msg.c | 69 ++++++++++++++++++++++++++++++++----------- 2 files changed, 55 insertions(+), 23 deletions(-) diff --git a/mbuni/mmlib/mms_cfg.c b/mbuni/mmlib/mms_cfg.c index 4688ccd..d7364a6 100644 --- a/mbuni/mmlib/mms_cfg.c +++ b/mbuni/mmlib/mms_cfg.c @@ -245,10 +245,8 @@ void mms_cfg_destroy(mCfg *cfg) mCfgGrp *mms_cfg_get_single(mCfg *cfg, Octstr *name) { - gw_assert(name); - - if (is_multigroup(name)) - gw_assert("Can't call this function with a multi-group name!" && 0); + gw_assert(name); + gw_assert(is_multigroup(name) == 0); return dict_get(cfg->grps, name); } @@ -259,8 +257,7 @@ List *mms_cfg_get_multi(mCfg *cfg, Octstr *name) int i; gw_assert(name); - if (!is_multigroup(name)) - gw_assert("Can't call this function with a single-group name!" && 0); + gw_assert(is_multigroup(name) == 1); r = dict_get(cfg->grps, name); diff --git a/mbuni/mmlib/mms_msg.c b/mbuni/mmlib/mms_msg.c index d7facf1..7b88fe6 100644 --- a/mbuni/mmlib/mms_msg.c +++ b/mbuni/mmlib/mms_msg.c @@ -1036,6 +1036,7 @@ static int fixup_msg(MmsMsg *m, Octstr *from) mms_encoding mms_message_enc(MmsMsg *msg) { + gw_assert(msg); return msg->enc; } @@ -1043,9 +1044,13 @@ MmsMsg *mms_frombinary(Octstr *msg, Octstr *from) { int res = 0; MmsMsg _m = {0}, *m = NULL; - ParseContext *p = parse_context_create(msg); + ParseContext *p; Octstr *s; + if (!msg) + return NULL; + + p = parse_context_create(msg); mms_strings_init(); /* Just in case. */ _m.headers = list_create(); @@ -1120,6 +1125,8 @@ void mms_msgdump(MmsMsg *m, int headers_only) { int i, n; + gw_assert(m); + http_header_dump(m->headers); debug("mms.dump", 0, "Dumping MMS message body (%s) [%ld parts] --> ", @@ -1140,8 +1147,11 @@ void mms_msgdump(MmsMsg *m, int headers_only) Octstr *mms_tobinary(MmsMsg *msg) { - Octstr *s = octstr_create(""); + Octstr *s; + if (!msg) + return NULL; + s = octstr_create(""); encode_msgheaders(s, msg->headers); if (msg->body.s) @@ -1151,7 +1161,8 @@ Octstr *mms_tobinary(MmsMsg *msg) int mms_messagetype(MmsMsg *msg) { - return msg->message_type; + gw_assert(msg); + return msg->message_type; } @@ -1250,9 +1261,13 @@ static void unconvert_mime_msg(MIMEEntity *m) MIMEEntity *mms_tomime(MmsMsg *msg, int base64) { - MIMEEntity *m = gw_malloc(sizeof *m); + MIMEEntity *m; int i, n; + if (!msg) + return NULL; + + m = gw_malloc(sizeof *m); memset(m, 0, sizeof *m); m->body = NULL; m->multiparts = NULL; @@ -1276,10 +1291,14 @@ MIMEEntity *mms_tomime(MmsMsg *msg, int base64) MmsMsg *mms_frommime(MIMEEntity *mime) { - MmsMsg *m = gw_malloc(sizeof *m); + MmsMsg *m; Octstr *s; MIMEEntity *mx; + if (!mime) + return NULL; + + m = gw_malloc(sizeof *m); memset(m, 0, sizeof *m); mx = mime_entity_duplicate(mime); @@ -1379,6 +1398,8 @@ static void mm_destroy(MIMEEntity *mx) void mms_destroy(MmsMsg *msg) { + if (!msg) + return; if (msg->ismultipart) list_destroy(msg->body.l, (list_item_destructor_t *)mm_destroy); else if (msg->body.s) @@ -1392,16 +1413,18 @@ void mms_destroy(MmsMsg *msg) List *mms_message_headers(MmsMsg *msg) { + gw_assert(msg); return http_header_duplicate(msg->headers); } MmsMsg *mms_readreport(Octstr *msgid, Octstr *from, Octstr *to, time_t date, Octstr *status) { - MmsMsg *m = gw_malloc(sizeof *m); + MmsMsg *m; Octstr *s; - + + m = gw_malloc(sizeof *m); m->ismultipart = 0; m->headers = http_create_empty_headers(); @@ -1584,8 +1607,8 @@ MmsMsg *mms_retrieveconf(MmsMsg *msg, Octstr *transactionid, int mms_remove_headers(MmsMsg *m, char *name) { + gw_assert(m); http_header_remove_all(m->headers, name); - return 0; } @@ -1625,16 +1648,18 @@ MmsMsg *mms_sendconf(char *errstr, char *msgid, char *transid, int isforward, in int mms_replace_header_value(MmsMsg *msg, char *hname, char *value) { - + gw_assert(msg); http_header_remove_all(msg->headers, hname); - http_header_add(msg->headers, hname, value); return 0; } int mms_add_missing_headers(MmsMsg *msg, List *headers) { - List *h = http_header_duplicate(headers); + List *h; + + gw_assert(msg); + h = http_header_duplicate(headers); http_header_combine(h, msg->headers); http_destroy_headers(msg->headers); @@ -1645,6 +1670,8 @@ int mms_add_missing_headers(MmsMsg *msg, List *headers) int mms_replace_header_values(MmsMsg *msg, char *hname, List *value) { int i; + + gw_assert(msg); http_header_remove_all(msg->headers, hname); for (i = 0; i < list_len(value); i++) { @@ -1656,7 +1683,7 @@ int mms_replace_header_values(MmsMsg *msg, char *hname, List *value) Octstr *mms_get_header_value(MmsMsg *msg, Octstr *header) { - + gw_assert(msg); return http_header_value(msg->headers, header); } @@ -1664,10 +1691,13 @@ Octstr *mms_get_header_value(MmsMsg *msg, Octstr *header) List *mms_get_header_values(MmsMsg *msg, Octstr *header) { - List *h = http_header_find_all(msg->headers, octstr_get_cstr(header)); - List *l = list_create(); - int i; + List *h; + List *l; + int i; + gw_assert(msg); + l = list_create(); + h = http_header_find_all(msg->headers, octstr_get_cstr(header)); for (i = 0; i < list_len(h); i++) { Octstr *hname, *value; @@ -1686,6 +1716,7 @@ int mms_convert_readrec2readorig(MmsMsg *msg) Octstr *s; + gw_assert(msg); if (msg->message_type != MMS_MSGTYPE_READ_REC_IND) return -1; @@ -1755,9 +1786,12 @@ MmsMsg *mms_deleteconf(int menc, char *transid) static int mms_msgsize(MmsMsg *m) { - Octstr *s = mms_tobinary(m); /* Dirty, but works... */ - int n = octstr_len(s); + Octstr *s; + int n; + gw_assert(m); + s = mms_tobinary(m); /* Dirty, but works... */ + n = octstr_len(s); octstr_destroy(s); return n; } @@ -1988,6 +2022,7 @@ int mms_clearbody(MmsMsg *msg) int mms_putbody(MmsMsg *msg, void *body, int ismultipart) { + gw_assert(msg); mms_clearbody(msg); msg->ismultipart = ismultipart;