/* * Mbuni - Open Source MMS Gateway * * Mbuni MSISDN mapper shell caller * * Copyright (C) 2003 - 2005, Digital Solutions Ltd. - http://www.dsmagic.com * * Paul Bagyenda * * This program is free software, distributed under the terms of * the GNU General Public License, with a few exceptions granted (see LICENSE) */ #include #include #include "mms_detokenize.h" #include "mms_util.h" Octstr *script; static int mms_detokenizer_init(char *settings) { script = octstr_create(settings); info(0, "Detokenizer script set to \"%s\"", settings); return 0; } static int mms_detokenizer_fini(void) { return 0; } static Octstr *mms_detokenize(Octstr * token, Octstr *request_ip) { Octstr *cmd = NULL, *msisdn = NULL; FILE *fp; char buf[4096]; if (script == NULL || octstr_len(script) == 0) return NULL; cmd = octstr_format("%s '%s'", octstr_get_cstr(script), octstr_get_cstr(token)); info(0, "Calling \"%s\"", octstr_get_cstr(cmd)); if ((fp = popen(octstr_get_cstr(cmd), "r"))) { if (fgets(buf, sizeof buf, fp) != NULL) { msisdn = octstr_create(buf); octstr_strip_crlfs(msisdn); } 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 };