2005-03-23 05:55:16 +00:00
|
|
|
/*
|
|
|
|
* Mbuni - Open Source MMS Gateway
|
|
|
|
*
|
|
|
|
* Resolving MSISDNs to local/remote MMSCs - calling shell scripts
|
|
|
|
*
|
2008-07-10 09:46:58 +00:00
|
|
|
* Copyright (C) 2003 - 2008, Digital Solutions Ltd. - http://www.dsmagic.com
|
2005-03-23 05:55:16 +00:00
|
|
|
*
|
|
|
|
* Paul Bagyenda <bagyenda@dsmagic.com>
|
|
|
|
*
|
|
|
|
* This program is free software, distributed under the terms of
|
|
|
|
* the GNU General Public License, with a few exceptions granted (see LICENSE)
|
|
|
|
*/
|
2005-03-11 20:29:10 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include "mms_resolve.h"
|
|
|
|
#include "mms_util.h"
|
|
|
|
|
|
|
|
static Octstr *script = NULL;
|
|
|
|
|
|
|
|
static void *mms_resolvermodule_init(char *settings)
|
|
|
|
{
|
|
|
|
script = octstr_imm(settings);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int mms_resolvermodule_fini(void *module_data)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-10-14 03:36:32 +00:00
|
|
|
static Octstr *mms_resolve(Octstr *phonenum, char *src_int, char *src_id,
|
|
|
|
void *module_data, void *settings_p, void *proxyrelays_p)
|
2005-03-11 20:29:10 +00:00
|
|
|
{
|
|
|
|
Octstr *s;
|
|
|
|
FILE *fp;
|
|
|
|
char buf[4096];
|
|
|
|
|
|
|
|
if (script == NULL || octstr_len(script) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2009-10-14 03:36:32 +00:00
|
|
|
s = octstr_format("%s '%s' '%s' '%s'",
|
|
|
|
octstr_get_cstr(script), octstr_get_cstr(phonenum) ,
|
|
|
|
src_int ? src_int : "", src_id ? src_id : "");
|
2005-03-11 20:29:10 +00:00
|
|
|
fp = popen(octstr_get_cstr(s), "r");
|
|
|
|
octstr_destroy(s);
|
|
|
|
|
2008-09-11 09:03:59 +00:00
|
|
|
fgets(buf, sizeof buf, fp);
|
2005-03-11 20:29:10 +00:00
|
|
|
s = octstr_create(buf);
|
|
|
|
octstr_strip_crlfs(s);
|
|
|
|
|
|
|
|
pclose(fp);
|
2006-04-12 07:14:45 +00:00
|
|
|
|
|
|
|
if (octstr_len(s) == 0) {
|
|
|
|
octstr_destroy(s);
|
|
|
|
return NULL;
|
|
|
|
}
|
2005-03-11 20:29:10 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* The function itself. */
|
2006-10-27 14:27:30 +00:00
|
|
|
MmsResolverFuncStruct mms_resolvefuncs_shell = {
|
2005-03-11 20:29:10 +00:00
|
|
|
mms_resolvermodule_init,
|
|
|
|
mms_resolve,
|
|
|
|
mms_resolvermodule_fini
|
|
|
|
};
|