int cw_app_getdata(struct cw_channel *c, char *prompt, char *s, int maxlen, int timeout) { int res,to,fto; /* XXX Merge with full version? XXX */ if (maxlen) s[0] = '\0'; if (prompt) { res = cw_streamfile(c, prompt, c->language); if (res < 0) return res; } fto = c->pbx ? c->pbx->rtimeout * 1000 : 6000; to = c->pbx ? c->pbx->dtimeout * 1000 : 2000; if (timeout > 0) fto = to = timeout; if (timeout < 0) fto = to = 1000000000; res = cw_readstring(c, s, maxlen, to, fto, "#"); return res; }
static int do_directory(struct cw_channel *chan, struct cw_config *cfg, char *context, char *dialcontext, char digit, int last) { /* Read in the first three digits.. "digit" is the first digit, already read */ char ext[NUMDIGITS + 1]; char name[80] = ""; struct cw_variable *v; int res; int found=0; int lastuserchoice = 0; char *start, *pos, *conv,*stringp=NULL; if (cw_strlen_zero(context)) { cw_log(LOG_WARNING, "Directory must be called with an argument " "(context in which to interpret extensions)\n"); return -1; } if (digit == '0') { if (!cw_goto_if_exists(chan, chan->context, "o", 1) || (!cw_strlen_zero(chan->proc_context) && !cw_goto_if_exists(chan, chan->proc_context, "o", 1))) { return 0; } else { cw_log(LOG_WARNING, "Can't find extension 'o' in current context. " "Not Exiting the Directory!\n"); res = 0; } } if (digit == '*') { if (!cw_goto_if_exists(chan, chan->context, "a", 1) || (!cw_strlen_zero(chan->proc_context) && !cw_goto_if_exists(chan, chan->proc_context, "a", 1))) { return 0; } else { cw_log(LOG_WARNING, "Can't find extension 'a' in current context. " "Not Exiting the Directory!\n"); res = 0; } } memset(ext, 0, sizeof(ext)); ext[0] = digit; res = 0; if (cw_readstring(chan, ext + 1, NUMDIGITS - 1, 3000, 3000, "#") < 0) res = -1; if (!res) { /* Search for all names which start with those digits */ v = cw_variable_browse(cfg, context); while(v && !res) { /* Find all candidate extensions */ while(v) { /* Find a candidate extension */ start = strdup(v->value); if (start && !strcasestr(start, "hidefromdir=yes")) { stringp=start; strsep(&stringp, ","); pos = strsep(&stringp, ","); if (pos) { cw_copy_string(name, pos, sizeof(name)); /* Grab the last name */ if (last && strrchr(pos,' ')) pos = strrchr(pos, ' ') + 1; conv = convert(pos); if (conv) { if (!strcmp(conv, ext)) { /* Match! */ found++; free(conv); free(start); break; } free(conv); } } free(start); } v = v->next; } if (v) { /* We have a match -- play a greeting if they have it */ res = play_mailbox_owner(chan, context, dialcontext, v->name, name); switch (res) { case -1: /* user pressed '1' but extension does not exist, or * user hungup */ lastuserchoice = 0; break; case '1': /* user pressed '1' and extensions exists; play_mailbox_owner will already have done a goto() on the channel */ lastuserchoice = res; break; case '*': /* user pressed '*' to skip something found */ lastuserchoice = res; res = 0; break; default: break; } v = v->next; } } if (lastuserchoice != '1') { if (found) res = cw_streamfile(chan, "dir-nomore", chan->language); else res = cw_streamfile(chan, "dir-nomatch", chan->language); if (!res) res = 1; return res; } return 0; } return res; }