From e1c18c07a4c466569ac8bc39baa90ad3c74ec57a Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Mon, 5 May 2008 19:29:49 +0000 Subject: [PATCH] Added strip-prefixes config param --- mbuni/ChangeLog | 2 ++ mbuni/doc/examples/mmsc.conf | 1 + mbuni/doc/userguide.shtml | 23 +++++++++++++++++++++++ mbuni/extras/pgsql-queue/Readme.txt | 2 +- mbuni/mmlib/mms_cfg.def | 1 + mbuni/mmlib/mms_queue.c | 4 ++-- mbuni/mmlib/mms_util.c | 25 +++++++++++++++++++++++-- mbuni/mmlib/mms_util.h | 5 ++++- mbuni/mmsbox/mmsbox.c | 7 ++++--- mbuni/mmsbox/mmsbox_cfg.c | 18 ++++++++++++------ mbuni/mmsbox/mmsbox_cfg.h | 1 + mbuni/mmsc/mmsc_cfg.c | 11 ++++++++--- mbuni/mmsc/mmsc_cfg.h | 3 +++ mbuni/mmsc/mmsfromemail.c | 6 ++++++ mbuni/mmsc/mmsglobalsender.c | 9 +++++++-- mbuni/mmsc/mmsmobilesender.c | 6 ++++++ mbuni/mmsc/mmsproxy.c | 6 ++++++ mbuni/mmsc/mmssend.c | 6 ++++-- 18 files changed, 114 insertions(+), 22 deletions(-) diff --git a/mbuni/ChangeLog b/mbuni/ChangeLog index 483fe21..b241eca 100644 --- a/mbuni/ChangeLog +++ b/mbuni/ChangeLog @@ -1,3 +1,5 @@ +2008-05-05 P. A. Bagyenda + * Added strip-prefixes config parameter 2008-04-18 P. A. Bagyenda * Various memory leak fixes (thanks to Monachin Eric @ Skycore) 2008-04-11 P. A. Bagyenda diff --git a/mbuni/doc/examples/mmsc.conf b/mbuni/doc/examples/mmsc.conf index 198d765..9744621 100644 --- a/mbuni/doc/examples/mmsc.conf +++ b/mbuni/doc/examples/mmsc.conf @@ -35,6 +35,7 @@ mms-to-email-txt = "This is a multimedia message (HTML suppressed)" mms-to-email-html = "This is a multimedia message powered by Digital Solutions" mms-to-email-default-subject = "This is a multimedia message" mms-message-too-large-txt = "You have received a multimedia message from %S that is too large for your phone. Go to xxx to view it" +strip-prefixes = "1;2" group = mms-vasp vasp-id = newscorp diff --git a/mbuni/doc/userguide.shtml b/mbuni/doc/userguide.shtml index e832927..956254e 100644 --- a/mbuni/doc/userguide.shtml +++ b/mbuni/doc/userguide.shtml @@ -821,6 +821,28 @@ lists all the configuration directives. The column Mode after variable substitution, hence parameter quoting is not necessary.)     + + + strip-prefixes + +     + + + ALL +     + + + + Number list +     + + A semi-colon (;) separated string of prefixes that should (if + found) be stripped of the phone number prior to number + normalisation as described below. Only the first prefix that matches + will be stripped. +     + + unified-prefix @@ -845,6 +867,7 @@ lists all the configuration directives. The column Mode there are several unified prefixes, separate their rules with semicolon (';')     + maximum-send-attempts diff --git a/mbuni/extras/pgsql-queue/Readme.txt b/mbuni/extras/pgsql-queue/Readme.txt index 5e1f0fc..8bd5e00 100644 --- a/mbuni/extras/pgsql-queue/Readme.txt +++ b/mbuni/extras/pgsql-queue/Readme.txt @@ -2,7 +2,7 @@ This module provides Queue management for mbuni using PostgreSQL as the storage To use it, you need only add two lines to the mbuni config 'mbuni' group: queue-manager-module = "/path_to/libmms_pgsql_queue.so" -queue-module-init-data = "number_of_db_connections:host=dbhost user=db_user passwowrd=dbpassword dbname=dbname" +queue-module-init-data = "number_of_db_connections:host=dbhost user=db_user password=dbpassword dbname=dbname" Make sure the database you are trying to connect to has already been created and the relevant tables created using the supplied file "tables.sql". diff --git a/mbuni/mmlib/mms_cfg.def b/mbuni/mmlib/mms_cfg.def index 8509026..1305cfb 100644 --- a/mbuni/mmlib/mms_cfg.def +++ b/mbuni/mmlib/mms_cfg.def @@ -50,6 +50,7 @@ SINGLE_GROUP(mbuni, OCTSTR(max-send-threads) OCTSTR(send-mail-prog) OCTSTR(unified-prefix) + OCTSTR(strip-prefixes) OCTSTR(maximum-send-attempts) OCTSTR(default-message-expiry) OCTSTR(queue-run-interval) diff --git a/mbuni/mmlib/mms_queue.c b/mbuni/mmlib/mms_queue.c index 9a7b8f2..8f7e7fa 100644 --- a/mbuni/mmlib/mms_queue.c +++ b/mbuni/mmlib/mms_queue.c @@ -264,7 +264,7 @@ static MmsEnvelope *mms_queue_readenvelope(char *qf, char *mms_queuedir, int sho if (mms_validate_address(e->from) != 0) { warning(0, "mms_queueread: Mal-formed address [%s] in file %s! " "Attempting fixup.", res, xqf); - _mms_fixup_address(&e->from, NULL, 1); + _mms_fixup_address(&e->from, NULL, NULL, 1); } break; case 'R': @@ -273,7 +273,7 @@ static MmsEnvelope *mms_queue_readenvelope(char *qf, char *mms_queuedir, int sho if (mms_validate_address(t) != 0) { warning(0, "mms_queueread: Mal-formed address [%s] in file %s! " "Attempting fixup.", res, xqf); - _mms_fixup_address(&t, NULL, 1); + _mms_fixup_address(&t, NULL, NULL, 1); } to = gw_malloc(sizeof *to); to->rcpt = t; diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index fb56cc7..7fbd5e2 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -982,8 +982,29 @@ int isphonenum(Octstr *s) return 1; } +void mms_normalize_phonenum(Octstr **num, char *unified_prefix, List *strip_prefixes) +{ + int i, n; + + if (num == NULL || + *num == NULL) + return; + + /* stip prefix first. */ + for (i = 0, n = gwlist_len(strip_prefixes); immsbox_resolve(xfrom,fto,octstr_get_cstr(m->id), rfs_data, rfs_settings); @@ -543,7 +549,7 @@ Octstr *get_mmsbox_queue_dir(Octstr *from, List *to, MmscGrp *m, octstr_destroy(fto); } else { if (unified_prefix) - _mms_fixup_address(&fto, octstr_get_cstr(unified_prefix), 1); + _mms_fixup_address(&fto, octstr_get_cstr(unified_prefix), strip_prefixes, 1); gwlist_insert(to, 0, fto); octstr_destroy(xto); } diff --git a/mbuni/mmsbox/mmsbox_cfg.h b/mbuni/mmsbox/mmsbox_cfg.h index 6878676..226492f 100644 --- a/mbuni/mmsbox/mmsbox_cfg.h +++ b/mbuni/mmsbox/mmsbox_cfg.h @@ -94,6 +94,7 @@ extern List *mms_services; /* list of MMS Services */ extern List *mmscs; /* MMSC list. Perhaps turn into a Dict instead? */ extern Octstr *incoming_qdir, *outgoing_qdir, *dlr_dir; extern Octstr *unified_prefix; +extern List *strip_prefixes; extern long mmsbox_maxsendattempts, mmsbox_send_back_off, default_msgexpiry; extern long maxthreads; extern double queue_interval; diff --git a/mbuni/mmsc/mmsc_cfg.c b/mbuni/mmsc/mmsc_cfg.c index 4ab9314..52c26e3 100644 --- a/mbuni/mmsc/mmsc_cfg.c +++ b/mbuni/mmsc/mmsc_cfg.c @@ -64,8 +64,13 @@ MmscSettings *mms_load_mmsc_settings(mCfg *cfg, List **proxyrelays) m->unified_prefix = _mms_cfg_getx(grp, octstr_imm("unified-prefix")); m->local_prefix = _mms_cfg_getx(grp, octstr_imm("local-prefixes")); - - + + if ((s = mms_cfg_get(grp, octstr_imm("strip-prefixes"))) != NULL) { + m->strip_prefixes = octstr_split(s, octstr_imm(";")); + octstr_destroy(s); + } else + m->strip_prefixes = NULL; + if (m->hostname == NULL || octstr_len(m->hostname) == 0) m->hostname = octstr_create("localhost"); @@ -324,7 +329,7 @@ MmscSettings *mms_load_mmsc_settings(mCfg *cfg, List **proxyrelays) m->mms2mobile = mv; } - if ((s = _mms_cfg_getx(grp, octstr_imm("send-uaprof"))) != NULL){ + if ((s = mms_cfg_get(grp, octstr_imm("send-uaprof"))) != NULL){ if (octstr_str_case_compare(s, "url") == 0) mv->send_uaprof = UAProf_URL; else if (octstr_str_case_compare(s, "ua") == 0) diff --git a/mbuni/mmsc/mmsc_cfg.h b/mbuni/mmsc/mmsc_cfg.h index ffceebc..3d9cb94 100644 --- a/mbuni/mmsc/mmsc_cfg.h +++ b/mbuni/mmsc/mmsc_cfg.h @@ -40,6 +40,9 @@ typedef struct MmscSettings { Octstr *system_user; Octstr *name, *hostname, *host_alias; Octstr *unified_prefix, *local_prefix; + + List *strip_prefixes; + Octstr *sendmail; Octstr *global_queuedir, *mm1_queuedir; diff --git a/mbuni/mmsc/mmsfromemail.c b/mbuni/mmsc/mmsfromemail.c index b12a0a6..a9d1786 100644 --- a/mbuni/mmsc/mmsfromemail.c +++ b/mbuni/mmsc/mmsfromemail.c @@ -521,7 +521,13 @@ static void fixup_recipient(void) /* XXX may be we should use fixup function in mmlib/mms_util.c ?? */ if (isphonenum(xto) && (!typ || octstr_str_compare(typ, "TYPE=PLMN") == 0)) { /* A phone number. */ +#if 0 normalize_number(octstr_get_cstr(settings->unified_prefix), &xto); +#else + mms_normalize_phonenum(&xto, + octstr_get_cstr(settings->unified_prefix), + settings->strip_prefixes); +#endif ttype = TPLMN; } else { /* For now everything else is email. */ ttype = TEMAIL; diff --git a/mbuni/mmsc/mmsglobalsender.c b/mbuni/mmsc/mmsglobalsender.c index b3c437d..8cac658 100644 --- a/mbuni/mmsc/mmsglobalsender.c +++ b/mbuni/mmsc/mmsglobalsender.c @@ -79,7 +79,7 @@ static int sendMsg(MmsEnvelope *e) MmsEnvelopeTo *to = gwlist_get(e->to, i); Octstr *s = octstr_duplicate(to->rcpt); - _mms_fixup_address(&s, octstr_get_cstr(settings->unified_prefix), 1); + _mms_fixup_address(&s, octstr_get_cstr(settings->unified_prefix), settings->strip_prefixes, 1); gwlist_append(l, s); } @@ -244,8 +244,13 @@ static int sendMsg(MmsEnvelope *e) if (sent != 1) { /* Not yet, sent, find the receiver MMSC. */ /* Normalise the number, then see if we can resolve home MMSC for this recipient. */ +#if 0 normalize_number(octstr_get_cstr(settings->unified_prefix), &phonenum); - +#else + mms_normalize_phonenum(&phonenum, + octstr_get_cstr(settings->unified_prefix), + settings->strip_prefixes); +#endif if ((mmsc = settings->mms_resolvefuncs->mms_resolve(phonenum, settings->mms_resolver_module_data, settings, proxyrelays))) { diff --git a/mbuni/mmsc/mmsmobilesender.c b/mbuni/mmsc/mmsmobilesender.c index dd229de..cfd97d0 100644 --- a/mbuni/mmsc/mmsmobilesender.c +++ b/mbuni/mmsc/mmsmobilesender.c @@ -285,7 +285,13 @@ static int sendNotify(MmsEnvelope *e) if (j > 0 && j - 1 + sizeof "/TYPE=PLMN" == len) { /* A proper number. */ phonenum = octstr_copy(to, 0, j); +#if 0 normalize_number(octstr_get_cstr(settings->unified_prefix), &phonenum); +#else + mms_normalize_phonenum(&phonenum, + octstr_get_cstr(settings->unified_prefix), + settings->strip_prefixes); +#endif } else if (k > 0 && k + sizeof "/TYPE=IPv" == len) rcpt_ip = octstr_copy(to, 0, k); else { diff --git a/mbuni/mmsc/mmsproxy.c b/mbuni/mmsc/mmsproxy.c index 767e28f..ef0e296 100644 --- a/mbuni/mmsc/mmsproxy.c +++ b/mbuni/mmsc/mmsproxy.c @@ -182,7 +182,13 @@ int main(int argc, char *argv[]) else h.client_addr = octstr_duplicate(h.base_client_addr); } else { /* A bare number, normalise it. */ +#if 0 normalize_number(octstr_get_cstr(settings->unified_prefix), &h.base_client_addr); +#else + mms_normalize_phonenum(&h.base_client_addr, + octstr_get_cstr(settings->unified_prefix), + settings->strip_prefixes); +#endif if (octstr_case_search(h.base_client_addr, octstr_imm("TYPE="),0) < 0) h.client_addr = octstr_format("%S/TYPE=PLMN", h.base_client_addr); else diff --git a/mbuni/mmsc/mmssend.c b/mbuni/mmsc/mmssend.c index a6310ee..9bb4b96 100644 --- a/mbuni/mmsc/mmssend.c +++ b/mbuni/mmsc/mmssend.c @@ -110,7 +110,8 @@ int main(int argc, char *argv[]) while ((x = gwlist_extract_first(to)) != NULL) { octstr_strip_blanks(x); _mms_fixup_address(&x, - settings->unified_prefix ? octstr_get_cstr(settings->unified_prefix) : NULL, 1); + settings->unified_prefix ? octstr_get_cstr(settings->unified_prefix) : NULL, + settings->strip_prefixes, 1); gwlist_append(l, x); } gwlist_destroy(to, NULL); @@ -119,7 +120,8 @@ int main(int argc, char *argv[]) /* fix from address. */ _mms_fixup_address(&from, - settings->unified_prefix ? octstr_get_cstr(settings->unified_prefix) : NULL, 1); + settings->unified_prefix ? octstr_get_cstr(settings->unified_prefix) : NULL, + settings->strip_prefixes, 1); #if 0 mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir));