diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index 7b551d6..89aa493 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,6 @@ +2007-12-15 P. A. Bagyenda + * Added allowed-sender-prefix/denied-sender-prefix for mmsc group of mmsbox config + * Added allowed-receiver-prefix/denied-receiver-prefix to mms-service group of mmsbox config 2007-11-27 P. A. Bagyenda * Bug fix in mime convertor module 2007-11-07 P. A. Bagyenda diff --git a/mbuni/doc/userguide.shtml b/mbuni/doc/userguide.shtml index db9bd6c..9bb7d7e 100644 --- a/mbuni/doc/userguide.shtml +++ b/mbuni/doc/userguide.shtml @@ -2327,6 +2327,32 @@ string + + + allowed-sender-prefix + + + Number list + + + List of + sender number prefixes that can use this MMSC + + + + + + denied-sender-prefix + + + Number list + + + List of + sender number prefixes that cannot use this MMSC + + + max-throughput @@ -2964,6 +2990,35 @@ A detailed list of configuration parameters for MMS Services is given below. + + + accepted-receiver-prefix + + + Strings + + + Colon-separated strings: List of receiver short code prefixes + allowed to use + this MMS Service. + + + + + + denied-receiver-prefix + + +Strings + + + Colon-separated strings: List of receiver short code prefixes not + allowed to use + this MMS Service. + + + + get-url diff --git a/mbuni/mmlib/mms_cfg.def b/mbuni/mmlib/mms_cfg.def index 8acec65..7c89388 100644 --- a/mbuni/mmlib/mms_cfg.def +++ b/mbuni/mmlib/mms_cfg.def @@ -133,6 +133,8 @@ MULTI_GROUP(mmsc, OCTSTR(deny-ip) OCTSTR(allowed-prefix) OCTSTR(denied-prefix) + OCTSTR(denied-sender-prefix) + OCTSTR(accepted-sender-prefix) OCTSTR(incoming-port-ssl) OCTSTR(max-throughput) OCTSTR(type) @@ -163,6 +165,8 @@ MULTI_GROUP(mms-service, OCTSTR(assume-plain-text) OCTSTR(accepted-mmscs) OCTSTR(denied-mmscs) + OCTSTR(denied-receiver-prefix) + OCTSTR(accepted-receiver-prefix) OCTSTR(keyword) OCTSTR(aliases) OCTSTR(http-post-parameters) diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index 962696e..72461fb 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -1718,3 +1718,20 @@ void *_mms_load_module(mCfgGrp *grp, char *config_key, char *symbolname, return retval; } + +Octstr *extract_phonenum(Octstr *num, Octstr *unified_prefix) +{ + Octstr *phonenum; + int j = octstr_case_search(num, octstr_imm("/TYPE=PLMN"), 0); + + if (j > 0 && j - 1 + sizeof "/TYPE=PLMN" == octstr_len(num)) + phonenum = octstr_copy(num, 0, j); + else + phonenum = octstr_duplicate(num); + + if (unified_prefix) + normalize_number(octstr_get_cstr(unified_prefix), &phonenum); + + return phonenum; + +} diff --git a/mbuni/mmlib/mms_util.h b/mbuni/mmlib/mms_util.h index 8474650..9f5953c 100644 --- a/mbuni/mmlib/mms_util.h +++ b/mbuni/mmlib/mms_util.h @@ -198,6 +198,9 @@ int has_node_children(xmlNodePtr node); /* strip non-essential headers from top-level */ void strip_non_essential_headers(MIMEEntity *mime); +/* Get phone number out of mms formatted one, and unify. */ +Octstr *extract_phonenum(Octstr *num, Octstr *unified_prefix); + /* load a shared object, then load a symbol from it. */ void *_mms_load_module(mCfgGrp *grp, char *config_key, char *symbolname, void *shell_builtin); diff --git a/mbuni/mmsbox/bearerbox.c b/mbuni/mmsbox/bearerbox.c index 09a5493..18f4346 100644 --- a/mbuni/mmsbox/bearerbox.c +++ b/mbuni/mmsbox/bearerbox.c @@ -930,7 +930,7 @@ static int sendMsg(MmsEnvelope *e) goto done; } - if ((mmc = get_handler_mmc(e->viaproxy, to->rcpt)) == NULL) { + if ((mmc = get_handler_mmc(e->viaproxy, to->rcpt, e->from)) == NULL) { err = octstr_format("MMSBox error: Failed to deliver to " "%S. Don't know how to route!", to->rcpt); diff --git a/mbuni/mmsbox/mmsbox.c b/mbuni/mmsbox/mmsbox.c index a3a2f11..74ff1a5 100644 --- a/mbuni/mmsbox/mmsbox.c +++ b/mbuni/mmsbox/mmsbox.c @@ -135,10 +135,11 @@ static int _x_octstr_comp(Octstr *x, Octstr *y) return (octstr_case_compare(x,y) == 0); } -static MmsService *get_service(Octstr *keyword, Octstr *mmc_id) +static MmsService *get_service(Octstr *keyword, Octstr *mmc_id, Octstr *receiver) { int i, n; MmsService *catch_all = NULL; + Octstr *phonenum = receiver ? extract_phonenum(receiver, unified_prefix) : NULL; for (i = 0, n = gwlist_len(mms_services); i < n; i++) { MmsService *ms = gwlist_get(mms_services,i); @@ -154,16 +155,27 @@ static MmsService *get_service(Octstr *keyword, Octstr *mmc_id) if (ms->allowed_mmscs && gwlist_search(ms->allowed_mmscs, mmc_id, (gwlist_item_matches_t *)octstr_compare) == NULL) continue; - + + if (ms->denied_receiver_prefix && phonenum && + does_prefix_match(ms->denied_receiver_prefix, phonenum) != 0) + continue; + + if (ms->allowed_receiver_prefix && phonenum && + does_prefix_match(ms->denied_receiver_prefix, phonenum) == 0) + continue; + if (keyword && gwlist_search(ms->keywords, keyword, - (gwlist_item_matches_t *)_x_octstr_comp) != NULL) + (gwlist_item_matches_t *)_x_octstr_comp) != NULL) { + octstr_destroy(phonenum); return ms; + } if (ms->isdefault && catch_all == NULL) /* We also find the catch-all for this sender. */ catch_all = ms; } + octstr_destroy(phonenum); return catch_all; } @@ -482,7 +494,8 @@ static int mmsbox_service_dispatch(MmsEnvelope *e) time_t tnow = time(NULL); Octstr *err = NULL, *keyword = NULL; MmsService *ms; - + MmsEnvelopeTo *xto; + gw_assert(e->msgtype == MMS_MSGTYPE_SEND_REQ || e->msgtype == MMS_MSGTYPE_RETRIEVE_CONF); @@ -512,8 +525,9 @@ static int mmsbox_service_dispatch(MmsEnvelope *e) me = mms_tomime(msg, 0); keyword = get_keyword(me); - - ms = get_service(keyword, e->fromproxy); + + xto = gwlist_get(e->to, 0); + ms = get_service(keyword, e->fromproxy, xto ? xto->rcpt : NULL); if (!ms) { err = octstr_format("No Service to handle %S (keyword %S)!", diff --git a/mbuni/mmsbox/mmsbox_cfg.c b/mbuni/mmsbox/mmsbox_cfg.c index f926018..46d078b 100644 --- a/mbuni/mmsbox/mmsbox_cfg.c +++ b/mbuni/mmsbox/mmsbox_cfg.c @@ -193,6 +193,9 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func) m->allowed_prefix = mms_cfg_get(x, octstr_imm("allowed-prefix")); m->denied_prefix = mms_cfg_get(x, octstr_imm("denied-prefix")); + m->allowed_sender_prefix = mms_cfg_get(x, octstr_imm("allowed-sender-prefix")); + m->denied_sender_prefix = mms_cfg_get(x, octstr_imm("denied-sender-prefix")); + m->incoming.allow_ip = mms_cfg_get(x, octstr_imm("allow-ip")); m->incoming.deny_ip = mms_cfg_get(x, octstr_imm("deny-ip")); @@ -361,6 +364,9 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func) octstr_destroy(s); } else m->denied_mmscs = NULL; /* means allow all. */ + + m->allowed_receiver_prefix = mms_cfg_get(x, octstr_imm("allowed-receiver-prefix")); + m->denied_receiver_prefix = mms_cfg_get(x, octstr_imm("denied-receiver-prefix")); /* Get key words. Start with aliases to make life easier. */ if ((s = mms_cfg_get(x, octstr_imm("aliases"))) != NULL) { @@ -446,42 +452,52 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func) } /* Get the MMC that should handler this recipient. */ -MmscGrp *get_handler_mmc(Octstr *id, Octstr *to) +MmscGrp *get_handler_mmc(Octstr *id, Octstr *to, Octstr *from) { - MmscGrp *mmc = NULL; - int i, j, n; - Octstr *phonenum = NULL; + MmscGrp *mmc = NULL, *res = NULL; + int i, n; + Octstr *phonenum = NULL, *xfrom = NULL; if (id) for (i = 0, n = gwlist_len(mmscs); i < n; i++) if ((mmc = gwlist_get(mmscs, i)) != NULL && - mmc->id && octstr_compare(mmc->id, id) == 0) + mmc->id && octstr_compare(mmc->id, id) == 0) return mmc; if (octstr_search_char(to, '@', 0) > 0 || octstr_case_search(to, octstr_imm("/TYPE=IPv"), 0) > 0) /* For emails, or ip take first mmsc. */ return gwlist_get(mmscs, 0); - j = octstr_case_search(to, octstr_imm("/TYPE=PLMN"), 0); - - if (j > 0 && j - 1 + sizeof "/TYPE=PLMN" == octstr_len(to)) - phonenum = octstr_copy(to, 0, j); - else - phonenum = octstr_duplicate(to); - - normalize_number(octstr_get_cstr(unified_prefix), &phonenum); - - for (i = 0, n = gwlist_len(mmscs); i < n; i++) - if ((mmc = gwlist_get(mmscs, i)) != NULL && - (mmc->allowed_prefix == NULL || - does_prefix_match(mmc->allowed_prefix, phonenum)) && - (mmc->denied_prefix == NULL || - !does_prefix_match(mmc->denied_prefix, phonenum))) - return mmc; + phonenum = extract_phonenum(to, unified_prefix); + xfrom = extract_phonenum(from, unified_prefix); + + for (i = 0, n = gwlist_len(mmscs); i < n; i++) { + if ((mmc = gwlist_get(mmscs, i)) == NULL) + continue; + + if (mmc->allowed_prefix && + does_prefix_match(mmc->allowed_prefix, phonenum) == 0) + continue; /* does not match. */ + + if (mmc->denied_prefix && + does_prefix_match(mmc->denied_prefix, phonenum) != 0) + continue; /* matches. */ - if (phonenum) - octstr_destroy(phonenum); - return NULL; + if (mmc->allowed_sender_prefix && + does_prefix_match(mmc->allowed_sender_prefix, xfrom) == 0) + continue; /* does not match. */ + + if (mmc->denied_sender_prefix && + does_prefix_match(mmc->denied_sender_prefix, xfrom) != 0) + continue; /* matches. */ + + res = mmc; /* otherwise it matches, so go away. */ + break; + } + + octstr_destroy(phonenum); + octstr_destroy(xfrom); + return res; } /* handle message routing. */ diff --git a/mbuni/mmsbox/mmsbox_cfg.h b/mbuni/mmsbox/mmsbox_cfg.h index 9075649..239c703 100644 --- a/mbuni/mmsbox/mmsbox_cfg.h +++ b/mbuni/mmsbox/mmsbox_cfg.h @@ -30,6 +30,7 @@ typedef struct MmscGrp { long port; } incoming; /* user, pass, port (and whether SSL) that MMSC uses to connect to us. */ Octstr *allowed_prefix, *denied_prefix; + Octstr *allowed_sender_prefix, *denied_sender_prefix; enum {UNKNOWN_MMSC = -1, CUSTOM_MMSC, SOAP_MMSC, EAIF_MMSC} type; /* type of connection. */ long throughput; /* Max send rate. */ long threadid; /* handler thread. */ @@ -77,6 +78,8 @@ typedef struct MmsService { List *allowed_mmscs; /* List of MMSCs allowed to access this service (by ID). */ List *denied_mmscs; /* List of MMSCs allowed to access this service (by ID). */ Octstr *service_code; /* Service code (MM7/SOAP only) */ + + Octstr *allowed_receiver_prefix, *denied_receiver_prefix; } MmsService; typedef struct SendMmsUser { @@ -110,7 +113,7 @@ extern Octstr *rfs_settings; extern int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func); -extern MmscGrp *get_handler_mmc(Octstr *id, Octstr *to); +extern MmscGrp *get_handler_mmc(Octstr *id, Octstr *to, Octstr *from); extern Octstr *get_mmsbox_queue_dir(Octstr *from, List *to, MmscGrp *m, Octstr **mmc_id);