From 17fc190e295e729185f7c8e96626e69df38300e1 Mon Sep 17 00:00:00 2001 From: bagyenda <> Date: Mon, 4 Apr 2005 13:47:03 +0000 Subject: [PATCH] fixes to detokenizer, added detonizer func + adding of token to url sent in notification fixed issue with dlsym when using fink's dlopen removed token comparison in fetch (i.e. rationalised use of fetch url parameters) --- mbuni/mmlib/mms_detokenize.c | 7 +++ mbuni/mmlib/mms_detokenize.h | 5 +++ mbuni/mmlib/mms_detokenize_shell.c | 11 +++++ mbuni/mmlib/mms_util.c | 70 ++++++++++++++++++++---------- mbuni/mmlib/mms_util.h | 3 +- mbuni/mmsc/mmsmobilesender.c | 1 + mbuni/mmsc/mmsproxy.c | 50 +++++++++++---------- 7 files changed, 101 insertions(+), 46 deletions(-) diff --git a/mbuni/mmlib/mms_detokenize.c b/mbuni/mmlib/mms_detokenize.c index 0eb8305..54b1f3d 100644 --- a/mbuni/mmlib/mms_detokenize.c +++ b/mbuni/mmlib/mms_detokenize.c @@ -31,9 +31,16 @@ static Octstr *mms_detokenize(Octstr * token) return octstr_create("+45xxxxxx"); } +static Octstr *mms_gettoken(Octstr *msisdn) +{ + /* Return the MSISDN matching the token as a new Octstr */ + return octstr_create("yy"); +} + /* The function itself. */ MmsTokenize mms_detokenizefuncs = { mms_detokenizer_init, mms_detokenize, + mms_gettoken, mms_detokenize_fini }; diff --git a/mbuni/mmlib/mms_detokenize.h b/mbuni/mmlib/mms_detokenize.h index b44be2f..12cf2c5 100644 --- a/mbuni/mmlib/mms_detokenize.h +++ b/mbuni/mmlib/mms_detokenize.h @@ -33,6 +33,11 @@ typedef struct MmsDetokenizerFuncStruct { */ Octstr *(*mms_detokenize)(Octstr * token); +/* Given an msisdn, returns the token associated + * Return NULL on error, otherwise an Octstr + */ + Octstr *(*mms_gettoken)(Octstr *msisdn); + int (*mms_detokenizer_fini)(void); } MmsDetokenizerFuncStruct; diff --git a/mbuni/mmlib/mms_detokenize_shell.c b/mbuni/mmlib/mms_detokenize_shell.c index fb22f03..65c59dc 100644 --- a/mbuni/mmlib/mms_detokenize_shell.c +++ b/mbuni/mmlib/mms_detokenize_shell.c @@ -48,13 +48,24 @@ static Octstr *mms_detokenize(Octstr * token) } pclose(fp); } + info(0, "%s \"%s\", returned msisdn = %s", + fp ? "Called" : "Failed to call", + octstr_get_cstr(cmd), + msisdn ? octstr_get_cstr(msisdn) : "null"); octstr_destroy(cmd); return msisdn; } +static Octstr *mms_gettoken(Octstr *msisdn) +{ + /* Dummy. */ + return octstr_create("y"); +} + /* The function itself. */ MmsDetokenizerFuncStruct mms_detokenizefuncs = { mms_detokenizer_init, mms_detokenize, + mms_gettoken, mms_detokenizer_fini }; diff --git a/mbuni/mmlib/mms_util.c b/mbuni/mmlib/mms_util.c index a1caa0b..be8983c 100644 --- a/mbuni/mmlib/mms_util.c +++ b/mbuni/mmlib/mms_util.c @@ -38,6 +38,13 @@ static Octstr *cfg_getx(CfgGroup *grp, Octstr *item) return v ? v : octstr_create(""); } +/* We seem to require this on OSX */ +#ifdef __APPLE__ +#define SYMPREFIX "" +#else +#define SYMPREFIX "" +#endif + static void *load_module(CfgGroup *grp, char *config_key, char *symbolname) { Octstr *s; @@ -47,8 +54,16 @@ static void *load_module(CfgGroup *grp, char *config_key, char *symbolname) if (s) { void *x = dlopen(octstr_get_cstr(s), RTLD_LAZY); void *y = NULL; +#ifdef __APPLE__ + char sbuf[512]; - if (x == NULL || (y = dlsym(x, symbolname)) == NULL) + sprintf(sbuf, "_%s", symbolname); +#endif; + if (x == NULL || ((y = dlsym(x, symbolname)) == NULL +#ifdef __APPLE__ /* fink version of dlsym has issues it seems. */ + && (y = dlsym(x, sbuf)) == NULL +#endif + )) panic(0, "Error, unable to load dynamic libary (%s): " @@ -181,7 +196,7 @@ MmsBoxSettings *mms_load_mmsbox_settings(Cfg *cfg) octstr_imm("billing-module-parameters")); /* Get and load the billing lib if any. */ - if ((m->mms_billfuncs = load_module(grp, "billing-library", "mms_billfuncs"))) { + if ((m->mms_billfuncs = load_module(grp, "billing-library", SYMPREFIX "mms_billfuncs"))) { if (m->mms_billfuncs->mms_billingmodule_init == NULL || m->mms_billfuncs->mms_billmsg == NULL || m->mms_billfuncs->mms_billingmodule_fini == NULL || @@ -196,7 +211,7 @@ MmsBoxSettings *mms_load_mmsbox_settings(Cfg *cfg) octstr_imm("resolver-module-parameters")); /* Get and load the resolver lib if any. */ - if ((m->mms_resolvefuncs = load_module(grp, "resolver-library", "mms_resolvefuncs"))) { + if ((m->mms_resolvefuncs = load_module(grp, "resolver-library", SYMPREFIX "mms_resolvefuncs"))) { if (m->mms_resolvefuncs->mms_resolvermodule_init == NULL || m->mms_resolvefuncs->mms_resolve == NULL || m->mms_resolvefuncs->mms_resolvermodule_fini == NULL) @@ -209,9 +224,10 @@ MmsBoxSettings *mms_load_mmsbox_settings(Cfg *cfg) m->detokenizer_params = cfg_getx(grp, octstr_imm("detokenizer-module-parameters")); /* Get and load the detokenizer lib if any. */ - if ((m->mms_detokenizefuncs = load_module(grp, "detokenizer-library", "mms_detokenizefuncs"))) { + if ((m->mms_detokenizefuncs = load_module(grp, "detokenizer-library", SYMPREFIX "mms_detokenizefuncs"))) { if (m->mms_detokenizefuncs->mms_detokenizer_init == NULL || m->mms_detokenizefuncs->mms_detokenize == NULL || + m->mms_detokenizefuncs->mms_gettoken == NULL || m->mms_detokenizefuncs->mms_detokenizer_fini == NULL) panic(0, "Missing or NULL functions in detokenizer module!"); if (m->mms_detokenizefuncs->mms_detokenizer_init(octstr_get_cstr(m->detokenizer_params))) @@ -254,57 +270,65 @@ List *mms_proxy_relays(Cfg *cfg) Octstr *mms_makefetchurl(char *qf, Octstr *token, int loc, + Octstr *to, MmsBoxSettings *settings) { Octstr *url = octstr_create(""); Octstr *host_alias = settings->host_alias; Octstr *hstr; + Octstr *endtoken, *x; + MmsDetokenizerFuncStruct *tfs = settings->mms_detokenizefuncs; + if (host_alias && octstr_len(host_alias) > 0) hstr = octstr_duplicate(host_alias); else hstr = octstr_format("%S:%d", settings->hostname, settings->port); - octstr_format_append(url, "http://%S/%s@%d/%S", + octstr_format_append(url, "http://%S/%s@%d", hstr, - qf, loc, - token ? token : octstr_imm("x")); + qf, loc); + + if (tfs && tfs->mms_gettoken) { /* we append the recipient token or we append the message token. */ + endtoken = tfs->mms_gettoken(to); + if (!endtoken) endtoken = octstr_create("x"); + } else { + if (!token) + token = octstr_create("x"); + else + endtoken = octstr_duplicate(token); + } + + x = octstr_duplicate(endtoken); /* might be immutable, so we duplicate it. */ + octstr_url_encode(x); + octstr_format_append(url, "/%S", x); + + octstr_destroy(endtoken); + octstr_destroy(x); octstr_destroy(hstr); return url; } -Octstr *mms_find_sender_msisdn(Octstr **send_url, List *request_hdrs, Octstr *msisdn_header, MmsDetokenizerFuncStruct* detokenizerfuncs) +Octstr *mms_find_sender_msisdn(Octstr *send_url, List *request_hdrs, Octstr *msisdn_header, + MmsDetokenizerFuncStruct* detokenizerfuncs) { /* Either we have a WAP gateway header as defined, or we look for - * last part of url as our number. + * last part of url, pass it to detokenizer lib if defined, and back comes our number. */ - Octstr *xsend_url = *send_url; Octstr *phonenum = http_header_value(request_hdrs, msisdn_header); if (!phonenum || octstr_len(phonenum) == 0) { - List *l = octstr_split(xsend_url, octstr_imm("/")); + List *l = octstr_split(send_url, octstr_imm("/")); if (l && list_len(l) > 1) { int i, n = list_len(l); Octstr *s; - if (detokenizerfuncs) phonenum = detokenizerfuncs->mms_detokenize(list_get(l, list_len(l) - 1)); - else - phonenum = octstr_duplicate(list_get(l, list_len(l) - 1)); - - /* After getting it, remove it from the end... */ - for (i = 0, s = octstr_create(""); i < n-1; i++) { - Octstr *p = list_get(l, i); - if (octstr_len(p) > 0) - octstr_format_append(s, "/%S", p); - } - octstr_destroy(*send_url); - *send_url = s; } if (l) list_destroy(l, (list_item_destructor_t *)octstr_destroy); diff --git a/mbuni/mmlib/mms_util.h b/mbuni/mmlib/mms_util.h index 4fb31a9..92f74ff 100644 --- a/mbuni/mmlib/mms_util.h +++ b/mbuni/mmlib/mms_util.h @@ -118,6 +118,7 @@ MmsBoxSettings *mms_load_mmsbox_settings(Cfg *cfg); extern List *mms_proxy_relays(Cfg *cfg); extern Octstr *mms_makefetchurl(char *qf, Octstr *token, int loc, + Octstr *to, MmsBoxSettings *settings); extern Octstr *mms_maketransid(char *qf, Octstr *mmscname); @@ -127,7 +128,7 @@ extern Octstr *mms_getqf_fromtransid(Octstr *transid); extern int mms_decodefetchurl(Octstr *fetch_url, Octstr **qf, Octstr **token, int *loc); -Octstr *mms_find_sender_msisdn(Octstr **send_url, List *request_hdrs, Octstr *msisdn_header, MmsDetokenizerFuncStruct *detokenizerfuncs); +Octstr *mms_find_sender_msisdn(Octstr *send_url, List *request_hdrs, Octstr *msisdn_header, MmsDetokenizerFuncStruct *detokenizerfuncs); Octstr *mms_find_sender_ip(List *request_hdrs, Octstr *ip_header, Octstr *ip, int *isv6); extern Octstr *mms_isodate(time_t t); diff --git a/mbuni/mmsc/mmsmobilesender.c b/mbuni/mmsc/mmsmobilesender.c index 022e810..97e6910 100644 --- a/mbuni/mmsc/mmsmobilesender.c +++ b/mbuni/mmsc/mmsmobilesender.c @@ -365,6 +365,7 @@ static int sendNotify(MmsEnvelope *e) /* To get here means we can send Ind. */ url = mms_makefetchurl(e->qf.name, e->token, MMS_LOC_MQUEUE, + to, settings); transid = mms_maketransid(e->qf.name, settings->host_alias); diff --git a/mbuni/mmsc/mmsproxy.c b/mbuni/mmsc/mmsproxy.c index 6b4fe7d..0399301 100644 --- a/mbuni/mmsc/mmsproxy.c +++ b/mbuni/mmsc/mmsproxy.c @@ -143,7 +143,7 @@ int main(int argc, char *argv[]) /* Get the sender address. */ - h.base_client_addr = mms_find_sender_msisdn(&h.url, h.headers, settings->wap_gw_msisdn_header, settings->mms_detokenizefuncs); + h.base_client_addr = mms_find_sender_msisdn(h.url, h.headers, settings->wap_gw_msisdn_header, settings->mms_detokenizefuncs); if (!h.base_client_addr) { /* Set to IP sender... XXXX assumes ipv4 only for now*/ if (settings->allow_ip_type) { @@ -156,11 +156,28 @@ int main(int argc, char *argv[]) } else h.client_addr = NULL; - } else { + } else if (octstr_search_char(h.base_client_addr, '.', 0) >= 0 || + octstr_search_char(h.base_client_addr, ':', 0) >= 0) { /* We got back an IP address above, so normalise. */ + if (octstr_case_search(h.base_client_addr, octstr_imm("TYPE="),0) < 0) + h.client_addr = octstr_format("%S/TYPE=IPv%s", h.base_client_addr, + octstr_search_char(h.base_client_addr, ':', 0) >= 0 ? "6" : "4"); + else + h.client_addr = octstr_duplicate(h.base_client_addr); + } else { /* A bare number, normalise it. */ normalize_number(octstr_get_cstr(settings->unified_prefix), &h.base_client_addr); - h.client_addr = octstr_format("%S/TYPE=PLMN", h.base_client_addr); + 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 + h.client_addr = octstr_duplicate(h.base_client_addr); } + + debug("mmsproxy", 0, + " Request, ip=%s, base_client_addr=%s, client_addr=%s ", + h.ip ? octstr_get_cstr(h.ip) : "", + h.base_client_addr ? octstr_get_cstr(h.base_client_addr) : "", + h.client_addr ? octstr_get_cstr(h.client_addr) : ""); + /* Dump headers, url etc. */ #if 0 http_header_dump(h.headers); @@ -296,17 +313,6 @@ void fetchmms_proxy(MmsHTTPClientInfo *h) (e) ? e->from : h->client_addr, menc); s = mms_tobinary(mr); - if (loc == MMS_LOC_MQUEUE) - if ((token == NULL && e->token != NULL) || - (e->token == NULL && token != NULL) || - (octstr_compare(e->token, token) != 0)) { - error(0, "MMS Fetch interface: token mismatch, did client mod the fetch url?? " - " env=%s for request url (%s) from %s!", - octstr_get_cstr(qf), octstr_get_cstr(h->url), octstr_get_cstr(h->ip)); - goto failed; - } - - if (!m) { error(0, "MMS Fetch interface: Failed to get message, url=%s, loc=%d from %s!", octstr_get_cstr(h->url), loc, octstr_get_cstr(h->ip)); @@ -499,7 +505,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) goto done; } - m = mms_frombinary(h->body, h->client_addr ? h->client_addr : octstr_imm("") ); + m = mms_frombinary(h->body, h->client_addr ? h->client_addr : octstr_imm("anon@anon")); if (!m) { http_header_add(rh, "Content-Type", "text/plain"); @@ -566,7 +572,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) /* XXX perhaps qualify errors better? */ mmbox_store_status = sdf ? "Success" : "Error-permanent-failure"; if (sdf) - mmbox_loc = mms_makefetchurl(octstr_get_cstr(sdf), NULL, MMS_LOC_MMBOX, settings); + mmbox_loc = mms_makefetchurl(octstr_get_cstr(sdf), NULL, MMS_LOC_MMBOX, from, settings); } if (x) @@ -799,7 +805,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) mmbox_store_status = sdf ? "Success" : "Error-permanent-failure"; if (sdf) mmbox_loc = mms_makefetchurl(octstr_get_cstr(sdf), NULL, - MMS_LOC_MMBOX, settings); + MMS_LOC_MMBOX, from, settings); } else { /* otherwise simply mod it. */ int xret; @@ -812,7 +818,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) mmbox_store_status = (xret == 0) ? "Success" : "Error-permanent-failure"; if (xret == 0) mmbox_loc = mms_makefetchurl(octstr_get_cstr(qf), NULL, - MMS_LOC_MMBOX, settings); + MMS_LOC_MMBOX, from, settings); } } @@ -1110,7 +1116,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) mmbox_store_status = sdf ? "Success" : "Error-permanent-failure"; if (sdf) mmbox_loc = mms_makefetchurl(octstr_get_cstr(sdf), NULL, - MMS_LOC_MMBOX, settings); + MMS_LOC_MMBOX, h->client_addr, settings); } else { /* it is in mmbox, just update. */ int xret; @@ -1124,7 +1130,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) mmbox_store_status = (xret == 0) ? "Success" : "Error-permanent-failure"; if (xret == 0) mmbox_loc = mms_makefetchurl(octstr_get_cstr(qf), NULL, - MMS_LOC_MMBOX, settings); + MMS_LOC_MMBOX, h->client_addr, settings); } @@ -1226,7 +1232,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) mmbox_store_status = sdf ? "Success" : "Error-permanent-failure"; if (sdf) mmbox_loc = mms_makefetchurl(octstr_get_cstr(sdf), NULL, - MMS_LOC_MMBOX, settings); + MMS_LOC_MMBOX, h->client_addr, settings); if (mmbox_loc) { mresp = mms_storeconf("Success", @@ -1446,7 +1452,7 @@ static void sendmms_proxy(MmsHTTPClientInfo *h) Octstr *sdf = list_get(msgrefs, i); list_append(msglocs, mms_makefetchurl(octstr_get_cstr(sdf), - NULL, MMS_LOC_MMBOX, settings)); + NULL, MMS_LOC_MMBOX, h->client_addr, settings)); } } else /* Profile not loaded... */ err = "Error-transient-network-problem";