1
0
Fork 0

Added some error checking

This commit is contained in:
shawarma 2005-03-19 00:45:53 +00:00
parent d59559f0fc
commit eacef28de6
1 changed files with 13 additions and 9 deletions

View File

@ -8,6 +8,7 @@ Octstr *script;
static int mms_detokenizer_init(char *settings)
{
script = octstr_create(settings);
info(0, "Detokenizer script set to \"%s\"", settings);
return 0;
}
@ -18,21 +19,24 @@ static int mms_detokenizer_fini(void)
static Octstr *mms_detokenize(Octstr * token)
{
Octstr *s;
Octstr *cmd = NULL, *msisdn = NULL;
FILE *fp;
char buf[4096];
if (script == NULL || octstr_len(script) == 0)
return NULL;
s = octstr_format("%s '%s'", octstr_get_cstr(script), octstr_get_cstr(token));
fp = popen(octstr_get_cstr(s), "r");
octstr_destroy(s);
fgets(buf, 4096, fp);
s = octstr_create(buf);
octstr_strip_crlfs(s);
pclose(fp);
return s;
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, 4096, fp) == buf) {
msisdn = octstr_create(buf);
octstr_strip_crlfs(msisdn);
}
pclose(fp);
}
octstr_destroy(cmd);
return msisdn;
}
/* The function itself. */