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