1
0
Fork 0

- Further fixes to detokenizer module usage

- Code movement (from mmlib to more specific mmsc where it is used)
This commit is contained in:
bagyenda 2006-05-08 11:19:38 +00:00
parent 0f38817669
commit 11574bb88e
5 changed files with 154 additions and 132 deletions

View File

@ -124,81 +124,6 @@ int mms_load_core_settings(mCfgGrp *cgrp)
return 0;
}
Octstr *mms_find_sender_ip(List *request_hdrs, Octstr *ip_header, Octstr *ip, int *isv6)
{
Octstr *xip;
/* Look in the headers, if none is defined, return actual IP */
Octstr *client_ip = http_header_value(request_hdrs, ip_header);
char *s;
xip = client_ip ? client_ip : octstr_duplicate(ip);
s = octstr_get_cstr(xip);
/* Crude test for ipv6 */
*isv6 = (index(s, ':') != NULL);
return xip;
}
int mms_decodefetchurl(Octstr *fetch_url,
Octstr **qf, Octstr **token, int *loc)
{
Octstr *xfurl = octstr_duplicate(fetch_url);
int i, j, n;
char *s, *p;
for (i = 0, n = 0, s = octstr_get_cstr(xfurl);
i < octstr_len(xfurl); i++)
if (s[i] == '/')
n++;
if (n < 2) /* We need at least two slashes. */
octstr_append_char(xfurl, '/');
i = 0;
n = octstr_len(xfurl);
s = octstr_get_cstr(xfurl);
p = strrchr(s, '/'); /* Find last slash. */
if (p)
i = (p - s) - 1;
else
i = n-1;
if (i < 0)
i = 0;
while (i>0 && s[i] != '/')
i--; /* Go back, find first slash */
if (i>=0 && s[i] == '/')
i++;
/* Now we have qf, find its end. */
j = i;
while (j<n && s[j] != '/')
j++; /* Skip to next slash. */
*qf = octstr_copy(fetch_url, i, j-i);
if (j<n)
*token = octstr_copy(fetch_url, j + 1, n - (j+1));
else
*token = octstr_create("");
octstr_destroy(xfurl);
/* Now get loc out of qf. */
*loc = MMS_LOC_MQUEUE;
i = octstr_search_char(*qf, '@', 0);
if (i >= 0) {
long l;
int j = octstr_parse_long(&l, *qf, i+1, 10);
if (j > 0)
*loc = l;
octstr_delete(*qf, i, octstr_len(*qf));
}
return 0;
}
Octstr *mms_maketransid(char *qf, Octstr *mmscname)
{
@ -498,51 +423,7 @@ void base64_mimeparts(MIMEEntity *m)
}
}
void notify_prov_server(char *cmd, char *from, char *event, char *arg)
{
Octstr *s;
if (cmd == NULL || cmd[0] == '\0')
return;
s = octstr_format("%s '%s' '%s' '%s'", cmd, event, from, arg);
if (s) {
system(octstr_get_cstr(s));
octstr_destroy(s);
}
}
int mms_ind_send(Octstr *prov_cmd, Octstr *to)
{
Octstr *s;
int res = 1;
if (prov_cmd == NULL ||
octstr_len(prov_cmd) == 0)
return 1;
s = octstr_format("%S %S", prov_cmd, to);
if (s) {
int x = system(octstr_get_cstr(s));
int y = WEXITSTATUS(x);
if (x < 0) {
error(0, "Checking MMS Ind.Send: Failed to run command %s!",
octstr_get_cstr(s));
res = 1;
} else if (y != 0 && y != 1)
res = -1;
else
res = y;
octstr_destroy(s);
} else
warning(0, "Checking MMS Ind.Send: Failed call to compose command [%s] ",
octstr_get_cstr(prov_cmd));
return res;
}
static void addmmscname(Octstr *s, Octstr *myhostname)
{

View File

@ -56,11 +56,6 @@ extern Octstr *mms_maketransid(char *qf, Octstr *mmscname);
extern Octstr *mms_getqf_fromtransid(Octstr *transid);
extern int mms_decodefetchurl(Octstr *fetch_url,
Octstr **qf, Octstr **token, int *loc);
Octstr *mms_find_sender_ip(List *request_hdrs, Octstr *ip_header, Octstr *ip, int *isv6);
extern Octstr *mms_isodate(time_t t);
void mms_lib_init(void);
void mms_lib_shutdown(void);
@ -84,8 +79,6 @@ void unbase64_mimeparts(MIMEEntity *m);
/* Where element contains binary data, encode it base64. */
void base64_mimeparts(MIMEEntity *m);
void notify_prov_server(char *cmd, char *from, char *event, char *arg);
int mms_ind_send(Octstr *prov_cmd, Octstr *to);
/* Send this message to email recipient: Returns 0 on success 1 or 2 on profile error
* (negate to get right one), -ve on some other error

View File

@ -385,7 +385,9 @@ Octstr *mms_makefetchurl(char *qf, Octstr *token, int loc,
}
Octstr *mms_find_sender_msisdn(Octstr *send_url, List *request_hdrs,
Octstr *mms_find_sender_msisdn(Octstr *send_url,
Octstr *ip,
List *request_hdrs,
Octstr *msisdn_header,
Octstr *requestip_header,
MmsDetokenizerFuncStruct* detokenizerfuncs)
@ -399,16 +401,150 @@ Octstr *mms_find_sender_msisdn(Octstr *send_url, List *request_hdrs,
if (!phonenum || octstr_len(phonenum) == 0) {
List *l = octstr_split(send_url, octstr_imm("/"));
Octstr *ip = http_header_value(request_hdrs,
Octstr *xip = http_header_value(request_hdrs,
requestip_header);
if (xip == NULL)
xip = ip ? octstr_duplicate(ip) : NULL;
if (l && list_len(l) > 1) {
if (detokenizerfuncs)
phonenum = detokenizerfuncs->mms_detokenize(list_get(l, list_len(l) - 1), ip);
phonenum = detokenizerfuncs->mms_detokenize(list_get(l, list_len(l) - 1), xip);
}
if (l)
list_destroy(l, (list_item_destructor_t *)octstr_destroy);
if (xip)
octstr_destroy(xip);
}
return phonenum;
}
Octstr *mms_find_sender_ip(List *request_hdrs, Octstr *ip_header, Octstr *ip, int *isv6)
{
Octstr *xip;
/* Look in the headers, if none is defined, return actual IP */
Octstr *client_ip = http_header_value(request_hdrs, ip_header);
char *s;
xip = client_ip ? client_ip : octstr_duplicate(ip);
s = octstr_get_cstr(xip);
/* Crude test for ipv6 */
*isv6 = (index(s, ':') != NULL);
return xip;
}
int mms_decodefetchurl(Octstr *fetch_url,
Octstr **qf, Octstr **token, int *loc)
{
Octstr *xfurl = octstr_duplicate(fetch_url);
int i, j, n;
char *s, *p;
for (i = 0, n = 0, s = octstr_get_cstr(xfurl);
i < octstr_len(xfurl); i++)
if (s[i] == '/')
n++;
if (n < 2) /* We need at least two slashes. */
octstr_append_char(xfurl, '/');
i = 0;
n = octstr_len(xfurl);
s = octstr_get_cstr(xfurl);
p = strrchr(s, '/'); /* Find last slash. */
if (p)
i = (p - s) - 1;
else
i = n-1;
if (i < 0)
i = 0;
while (i>0 && s[i] != '/')
i--; /* Go back, find first slash */
if (i>=0 && s[i] == '/')
i++;
/* Now we have qf, find its end. */
j = i;
while (j<n && s[j] != '/')
j++; /* Skip to next slash. */
*qf = octstr_copy(fetch_url, i, j-i);
if (j<n)
*token = octstr_copy(fetch_url, j + 1, n - (j+1));
else
*token = octstr_create("");
octstr_destroy(xfurl);
/* Now get loc out of qf. */
*loc = MMS_LOC_MQUEUE;
i = octstr_search_char(*qf, '@', 0);
if (i >= 0) {
long l;
int j = octstr_parse_long(&l, *qf, i+1, 10);
if (j > 0)
*loc = l;
octstr_delete(*qf, i, octstr_len(*qf));
}
return 0;
}
int mms_ind_send(Octstr *prov_cmd, Octstr *to)
{
Octstr *tmp;
Octstr *s;
int res = 1;
if (prov_cmd == NULL ||
octstr_len(prov_cmd) == 0)
return 1;
tmp = octstr_duplicate(to);
escape_shell_chars(tmp);
s = octstr_format("%S %S", prov_cmd, tmp);
octstr_destroy(tmp);
if (s) {
int x = system(octstr_get_cstr(s));
int y = WEXITSTATUS(x);
if (x < 0) {
error(0, "Checking MMS Ind.Send: Failed to run command %s!",
octstr_get_cstr(s));
res = 1;
} else if (y != 0 && y != 1)
res = -1;
else
res = y;
octstr_destroy(s);
} else
warning(0, "Checking MMS Ind.Send: Failed call to compose command [%s] ",
octstr_get_cstr(prov_cmd));
return res;
}
void notify_prov_server(char *cmd, char *from, char *event, char *arg)
{
Octstr *s;
Octstr *tmp;
if (cmd == NULL || cmd[0] == '\0')
return;
tmp = octstr_create(from);
escape_shell_chars(tmp);
s = octstr_format("%s '%s' '%s' '%s'", cmd, event, octstr_get_cstr(tmp), arg);
octstr_destroy(tmp);
if (s) {
system(octstr_get_cstr(s));
octstr_destroy(s);
}
}

View File

@ -106,8 +106,18 @@ extern Octstr *mms_makefetchurl(char *qf, Octstr *token, int loc,
Octstr *to,
MmscSettings *settings);
Octstr *mms_find_sender_msisdn(Octstr *send_url, List *request_hdrs,
Octstr *mms_find_sender_msisdn(Octstr *send_url,
Octstr *ip,
List *request_hdrs,
Octstr *msisdn_header,
Octstr *requestip_header,
MmsDetokenizerFuncStruct *detokenizerfuncs);
extern int mms_decodefetchurl(Octstr *fetch_url,
Octstr **qf, Octstr **token, int *loc);
Octstr *mms_find_sender_ip(List *request_hdrs, Octstr *ip_header, Octstr *ip, int *isv6);
void notify_prov_server(char *cmd, char *from, char *event, char *arg);
int mms_ind_send(Octstr *prov_cmd, Octstr *to);
#endif

View File

@ -138,6 +138,7 @@ int main(int argc, char *argv[])
/* Get the sender address. */
h.base_client_addr = mms_find_sender_msisdn(h.url,
h.ip,
h.headers,
settings->wap_gw_msisdn_header,
settings->wap_gw_ip_header,
@ -233,7 +234,8 @@ void fetchmms_proxy(MmsHTTPClientInfo *h)
int loc, menc = MS_1_1;
MmsUaProfile *prof = NULL;
debug("proxy.fetchinterface", 0, " ---> Entered fetch interface <---");
debug("proxy.fetchinterface", 0, " ---> Entered fetch interface: url=%s <---",
h->url ? octstr_get_cstr(h->url) : "none");
rh = http_create_empty_headers();
http_header_add(rh, "Pragma", "no-cache");