1
0
Fork 0

Added strip-prefixes config param

This commit is contained in:
bagyenda 2008-05-05 19:29:49 +00:00
parent b31790def4
commit e1c18c07a4
18 changed files with 114 additions and 22 deletions

View File

@ -1,3 +1,5 @@
2008-05-05 P. A. Bagyenda <bagyenda@dsmagic.com>
* Added strip-prefixes config parameter
2008-04-18 P. A. Bagyenda <bagyenda@dsmagic.com> 2008-04-18 P. A. Bagyenda <bagyenda@dsmagic.com>
* Various memory leak fixes (thanks to Monachin Eric @ Skycore) * Various memory leak fixes (thanks to Monachin Eric @ Skycore)
2008-04-11 P. A. Bagyenda <bagyenda@dsmagic.com> 2008-04-11 P. A. Bagyenda <bagyenda@dsmagic.com>

View File

@ -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 <emph>Digital Solutions</emph>" mms-to-email-html = "This is a multimedia message powered by <emph>Digital Solutions</emph>"
mms-to-email-default-subject = "This is a multimedia message" 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" 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 group = mms-vasp
vasp-id = newscorp vasp-id = newscorp

View File

@ -821,6 +821,28 @@ lists all the configuration directives. The column <b>Mode</b>
after variable substitution, hence parameter quoting is not necessary.) after variable substitution, hence parameter quoting is not necessary.)
&nbsp; &nbsp;</td> &nbsp; &nbsp;</td>
</tr> </tr>
<tr>
<td valign=top >
<tt>strip-prefixes
&nbsp; &nbsp;</td>
<td valign=top >
<i>ALL</i>
&nbsp; &nbsp;
</td>
<td valign=top >
Number list
&nbsp; &nbsp;</td>
<td valign=top >
A semi-colon (;) separated string of prefixes that should (if
found) be stripped of the phone number <i>prior</i> to number
normalisation as described below. Only the first prefix that matches
will be stripped.
&nbsp; &nbsp;</td>
</tr>
<tr> <tr>
<td valign=top > <td valign=top >
<tt>unified-prefix <tt>unified-prefix
@ -845,6 +867,7 @@ lists all the configuration directives. The column <b>Mode</b>
there are several unified prefixes, separate their rules with semicolon (';') there are several unified prefixes, separate their rules with semicolon (';')
&nbsp; &nbsp;</td> &nbsp; &nbsp;</td>
</tr> </tr>
<tr> <tr>
<td valign=top > <td valign=top >
<tt>maximum-send-attempts <tt>maximum-send-attempts

View File

@ -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: 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-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 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". and the relevant tables created using the supplied file "tables.sql".

View File

@ -50,6 +50,7 @@ SINGLE_GROUP(mbuni,
OCTSTR(max-send-threads) OCTSTR(max-send-threads)
OCTSTR(send-mail-prog) OCTSTR(send-mail-prog)
OCTSTR(unified-prefix) OCTSTR(unified-prefix)
OCTSTR(strip-prefixes)
OCTSTR(maximum-send-attempts) OCTSTR(maximum-send-attempts)
OCTSTR(default-message-expiry) OCTSTR(default-message-expiry)
OCTSTR(queue-run-interval) OCTSTR(queue-run-interval)

View File

@ -264,7 +264,7 @@ static MmsEnvelope *mms_queue_readenvelope(char *qf, char *mms_queuedir, int sho
if (mms_validate_address(e->from) != 0) { if (mms_validate_address(e->from) != 0) {
warning(0, "mms_queueread: Mal-formed address [%s] in file %s! " warning(0, "mms_queueread: Mal-formed address [%s] in file %s! "
"Attempting fixup.", res, xqf); "Attempting fixup.", res, xqf);
_mms_fixup_address(&e->from, NULL, 1); _mms_fixup_address(&e->from, NULL, NULL, 1);
} }
break; break;
case 'R': case 'R':
@ -273,7 +273,7 @@ static MmsEnvelope *mms_queue_readenvelope(char *qf, char *mms_queuedir, int sho
if (mms_validate_address(t) != 0) { if (mms_validate_address(t) != 0) {
warning(0, "mms_queueread: Mal-formed address [%s] in file %s! " warning(0, "mms_queueread: Mal-formed address [%s] in file %s! "
"Attempting fixup.", res, xqf); "Attempting fixup.", res, xqf);
_mms_fixup_address(&t, NULL, 1); _mms_fixup_address(&t, NULL, NULL, 1);
} }
to = gw_malloc(sizeof *to); to = gw_malloc(sizeof *to);
to->rcpt = t; to->rcpt = t;

View File

@ -982,8 +982,29 @@ int isphonenum(Octstr *s)
return 1; 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); i<n;i++) {
Octstr *x = gwlist_get(strip_prefixes, i);
if (octstr_search(*num, x, 0) == 0) {
octstr_delete(*num, 0, octstr_len(x));
break;
}
}
if (unified_prefix)
normalize_number(unified_prefix, num);
}
/* Doesn't handle IP addresses very well */ /* Doesn't handle IP addresses very well */
void _mms_fixup_address(Octstr **address, char *unified_prefix, int keep_suffix) void _mms_fixup_address(Octstr **address, char *unified_prefix, List *strip_prefixes, int keep_suffix)
{ {
int i; int i;
Octstr *typ; Octstr *typ;
@ -1002,7 +1023,7 @@ void _mms_fixup_address(Octstr **address, char *unified_prefix, int keep_suffix)
if (isphonenum(*address) || (typ && octstr_str_compare(typ, "/TYPE=PLMN") == 0)) { if (isphonenum(*address) || (typ && octstr_str_compare(typ, "/TYPE=PLMN") == 0)) {
if (unified_prefix) if (unified_prefix)
normalize_number(unified_prefix, address); mms_normalize_phonenum(address, unified_prefix, strip_prefixes);
octstr_append(*address, keep_suffix ? octstr_imm("/TYPE=PLMN") : octstr_imm("")); octstr_append(*address, keep_suffix ? octstr_imm("/TYPE=PLMN") : octstr_imm(""));
} else if (typ) } else if (typ)
octstr_append(*address, keep_suffix ? typ : octstr_imm("")); octstr_append(*address, keep_suffix ? typ : octstr_imm(""));

View File

@ -154,7 +154,10 @@ unsigned long _mshash(char *s);
/* Tell us whether address is a phone number. */ /* Tell us whether address is a phone number. */
int isphonenum(Octstr *s); int isphonenum(Octstr *s);
/* Fixup an address: Normalize number (if prefix given), Add type (if keep_suffix is set), etc. */ /* Fixup an address: Normalize number (if prefix given), Add type (if keep_suffix is set), etc. */
void _mms_fixup_address(Octstr **address, char *unified_prefix, int keep_suffix); void _mms_fixup_address(Octstr **address, char *unified_prefix, List *strip_prefixes, int keep_suffix);
/* normalize a phone number: Strip any prefixes, then normalize. */
void mms_normalize_phonenum(Octstr **num, char *unified_prefix, List *strip_prefixes);
/* Check that host is one of hosts in semi-colon separated list in host_list */ /* Check that host is one of hosts in semi-colon separated list in host_list */
int is_allowed_host(Octstr *host, Octstr *host_list); int is_allowed_host(Octstr *host, Octstr *host_list);

View File

@ -887,7 +887,8 @@ static int make_and_queue_msg(Octstr *data, Octstr *ctype, List *reply_headers,
for (j = 0; j < gwlist_len(hv); j++) { for (j = 0; j < gwlist_len(hv); j++) {
Octstr *v = gwlist_get(hv, j); Octstr *v = gwlist_get(hv, j);
/* Fix the address. */ /* Fix the address. */
_mms_fixup_address(&v, unified_prefix ? octstr_get_cstr(unified_prefix) : NULL, 1); _mms_fixup_address(&v, unified_prefix ? octstr_get_cstr(unified_prefix) : NULL,
strip_prefixes, 1);
gwlist_append(xto, v); gwlist_append(xto, v);
} }
octstr_destroy(v); octstr_destroy(v);
@ -944,7 +945,7 @@ static int make_and_queue_msg(Octstr *data, Octstr *ctype, List *reply_headers,
xservice_code = octstr_duplicate(hsvc_code); xservice_code = octstr_duplicate(hsvc_code);
if (from) if (from)
_mms_fixup_address(&from, NULL, 1); /* Don't normalise. */ _mms_fixup_address(&from, NULL, NULL, 1); /* Don't normalise. */
/* Now get the data. */ /* Now get the data. */
if (octstr_case_compare(ctype, octstr_imm("application/vnd.wap.mms-message")) == 0) if (octstr_case_compare(ctype, octstr_imm("application/vnd.wap.mms-message")) == 0)
@ -1292,7 +1293,7 @@ static void sendmms_func(void *unused)
if ((from = http_cgi_variable(cgivars, "from")) != NULL) { if ((from = http_cgi_variable(cgivars, "from")) != NULL) {
from = octstr_duplicate(from); from = octstr_duplicate(from);
_mms_fixup_address(&from, NULL, 1); _mms_fixup_address(&from, NULL, NULL, 1);
if (from) if (from)
HTTP_REPLACE_HEADER(rh, "X-Mbuni-From", octstr_get_cstr(from)); HTTP_REPLACE_HEADER(rh, "X-Mbuni-From", octstr_get_cstr(from));
octstr_destroy(from); octstr_destroy(from);

View File

@ -32,6 +32,8 @@ long mmsbox_maxsendattempts, mmsbox_send_back_off, default_msgexpiry;
long maxthreads = 0; long maxthreads = 0;
double queue_interval = -1; double queue_interval = -1;
Octstr *unified_prefix = NULL; Octstr *unified_prefix = NULL;
List *strip_prefixes = NULL;
int mt_multipart = 0; int mt_multipart = 0;
MmsQueueHandlerFuncs *qfs; /* queue functions. */ MmsQueueHandlerFuncs *qfs; /* queue functions. */
MmsBoxResolverFuncStruct *rfs; /* resolver functions. */ MmsBoxResolverFuncStruct *rfs; /* resolver functions. */
@ -122,11 +124,15 @@ int mms_load_mmsbox_settings(mCfg *cfg, gwthread_func_t *mmsc_handler_func)
} }
if (queue_interval <= 0) if (queue_interval <= 0)
queue_interval = QUEUERUN_INTERVAL; queue_interval = QUEUERUN_INTERVAL;
unified_prefix = _mms_cfg_getx(grp, octstr_imm("unified-prefix")); unified_prefix = _mms_cfg_getx(grp, octstr_imm("unified-prefix"));
if ((s = mms_cfg_get(grp, octstr_imm("strip-prefixes"))) != NULL) {
strip_prefixes = octstr_split(s, octstr_imm(";"));
octstr_destroy(s);
} else
strip_prefixes = NULL;
mms_cfg_get_int(grp, octstr_imm("sendmms-port"), &sendmms_port.port); mms_cfg_get_int(grp, octstr_imm("sendmms-port"), &sendmms_port.port);
#ifdef HAVE_LIBSSL #ifdef HAVE_LIBSSL
mms_cfg_get_bool(grp, octstr_imm("sendmms-port-ssl"), &send_port_ssl); mms_cfg_get_bool(grp, octstr_imm("sendmms-port-ssl"), &send_port_ssl);
@ -531,9 +537,9 @@ Octstr *get_mmsbox_queue_dir(Octstr *from, List *to, MmscGrp *m,
if (unified_prefix) if (unified_prefix)
_mms_fixup_address(&xfrom, octstr_get_cstr(unified_prefix), 0); _mms_fixup_address(&xfrom, octstr_get_cstr(unified_prefix), strip_prefixes, 0);
if (unified_prefix) if (unified_prefix)
_mms_fixup_address(&fto, octstr_get_cstr(unified_prefix), 0); _mms_fixup_address(&fto, octstr_get_cstr(unified_prefix), strip_prefixes, 0);
_mcid = rfs->mmsbox_resolve(xfrom,fto,octstr_get_cstr(m->id), rfs_data, rfs_settings); _mcid = rfs->mmsbox_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); octstr_destroy(fto);
} else { } else {
if (unified_prefix) 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); gwlist_insert(to, 0, fto);
octstr_destroy(xto); octstr_destroy(xto);
} }

View File

@ -94,6 +94,7 @@ extern List *mms_services; /* list of MMS Services */
extern List *mmscs; /* MMSC list. Perhaps turn into a Dict instead? */ extern List *mmscs; /* MMSC list. Perhaps turn into a Dict instead? */
extern Octstr *incoming_qdir, *outgoing_qdir, *dlr_dir; extern Octstr *incoming_qdir, *outgoing_qdir, *dlr_dir;
extern Octstr *unified_prefix; extern Octstr *unified_prefix;
extern List *strip_prefixes;
extern long mmsbox_maxsendattempts, mmsbox_send_back_off, default_msgexpiry; extern long mmsbox_maxsendattempts, mmsbox_send_back_off, default_msgexpiry;
extern long maxthreads; extern long maxthreads;
extern double queue_interval; extern double queue_interval;

View File

@ -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->unified_prefix = _mms_cfg_getx(grp, octstr_imm("unified-prefix"));
m->local_prefix = _mms_cfg_getx(grp, octstr_imm("local-prefixes")); 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) if (m->hostname == NULL || octstr_len(m->hostname) == 0)
m->hostname = octstr_create("localhost"); m->hostname = octstr_create("localhost");
@ -324,7 +329,7 @@ MmscSettings *mms_load_mmsc_settings(mCfg *cfg, List **proxyrelays)
m->mms2mobile = mv; 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) if (octstr_str_case_compare(s, "url") == 0)
mv->send_uaprof = UAProf_URL; mv->send_uaprof = UAProf_URL;
else if (octstr_str_case_compare(s, "ua") == 0) else if (octstr_str_case_compare(s, "ua") == 0)

View File

@ -40,6 +40,9 @@ typedef struct MmscSettings {
Octstr *system_user; Octstr *system_user;
Octstr *name, *hostname, *host_alias; Octstr *name, *hostname, *host_alias;
Octstr *unified_prefix, *local_prefix; Octstr *unified_prefix, *local_prefix;
List *strip_prefixes;
Octstr *sendmail; Octstr *sendmail;
Octstr *global_queuedir, *mm1_queuedir; Octstr *global_queuedir, *mm1_queuedir;

View File

@ -521,7 +521,13 @@ static void fixup_recipient(void)
/* XXX may be we should use fixup function in mmlib/mms_util.c ?? */ /* XXX may be we should use fixup function in mmlib/mms_util.c ?? */
if (isphonenum(xto) && if (isphonenum(xto) &&
(!typ || octstr_str_compare(typ, "TYPE=PLMN") == 0)) { /* A phone number. */ (!typ || octstr_str_compare(typ, "TYPE=PLMN") == 0)) { /* A phone number. */
#if 0
normalize_number(octstr_get_cstr(settings->unified_prefix), &xto); 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; ttype = TPLMN;
} else { /* For now everything else is email. */ } else { /* For now everything else is email. */
ttype = TEMAIL; ttype = TEMAIL;

View File

@ -79,7 +79,7 @@ static int sendMsg(MmsEnvelope *e)
MmsEnvelopeTo *to = gwlist_get(e->to, i); MmsEnvelopeTo *to = gwlist_get(e->to, i);
Octstr *s = octstr_duplicate(to->rcpt); 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); gwlist_append(l, s);
} }
@ -244,8 +244,13 @@ static int sendMsg(MmsEnvelope *e)
if (sent != 1) { /* Not yet, sent, find the receiver MMSC. */ if (sent != 1) { /* Not yet, sent, find the receiver MMSC. */
/* Normalise the number, then see if we can resolve home MMSC for this recipient. */ /* 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); 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, if ((mmsc = settings->mms_resolvefuncs->mms_resolve(phonenum,
settings->mms_resolver_module_data, settings->mms_resolver_module_data,
settings, proxyrelays))) { settings, proxyrelays))) {

View File

@ -285,7 +285,13 @@ static int sendNotify(MmsEnvelope *e)
if (j > 0 && j - 1 + sizeof "/TYPE=PLMN" == len) { /* A proper number. */ if (j > 0 && j - 1 + sizeof "/TYPE=PLMN" == len) { /* A proper number. */
phonenum = octstr_copy(to, 0, j); phonenum = octstr_copy(to, 0, j);
#if 0
normalize_number(octstr_get_cstr(settings->unified_prefix), &phonenum); 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) } else if (k > 0 && k + sizeof "/TYPE=IPv" == len)
rcpt_ip = octstr_copy(to, 0, k); rcpt_ip = octstr_copy(to, 0, k);
else { else {

View File

@ -182,7 +182,13 @@ int main(int argc, char *argv[])
else else
h.client_addr = octstr_duplicate(h.base_client_addr); h.client_addr = octstr_duplicate(h.base_client_addr);
} else { /* A bare number, normalise it. */ } else { /* A bare number, normalise it. */
#if 0
normalize_number(octstr_get_cstr(settings->unified_prefix), &h.base_client_addr); 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) 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); h.client_addr = octstr_format("%S/TYPE=PLMN", h.base_client_addr);
else else

View File

@ -110,7 +110,8 @@ int main(int argc, char *argv[])
while ((x = gwlist_extract_first(to)) != NULL) { while ((x = gwlist_extract_first(to)) != NULL) {
octstr_strip_blanks(x); octstr_strip_blanks(x);
_mms_fixup_address(&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_append(l, x);
} }
gwlist_destroy(to, NULL); gwlist_destroy(to, NULL);
@ -119,7 +120,8 @@ int main(int argc, char *argv[])
/* fix from address. */ /* fix from address. */
_mms_fixup_address(&from, _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 #if 0
mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir)); mms_start_profile_engine(octstr_get_cstr(settings->ua_profile_cache_dir));