int cw_osp_validate(char *provider, char *token, int *handle, unsigned int *timelimit, char *callerid, struct in_addr addr, char *extension) { char tmp[256]="", *l, *n; char iabuf[INET_ADDRSTRLEN]; char source[OSP_MAX] = ""; /* Same length as osp->source */ char *token2; int tokenlen; struct osp_provider *osp; int res = 0; unsigned int authorised, dummy; if (!provider || !strlen(provider)) provider = "default"; token2 = cw_strdupa(token); tokenlen = cw_base64decode(token2, token, strlen(token)); *handle = -1; if (!callerid) callerid = ""; cw_copy_string(tmp, callerid, sizeof(tmp)); cw_callerid_parse(tmp, &n, &l); if (!l) l = ""; else { cw_shrink_phone_number(l); if (!cw_isphonenumber(l)) l = ""; } callerid = l; cw_mutex_lock(&osplock); cw_inet_ntoa(iabuf, sizeof(iabuf), addr); osp = providers; while(osp) { if (!strcasecmp(osp->name, provider)) { if (OSPPTransactionNew(osp->handle, handle)) { cw_log(LOG_WARNING, "Unable to create OSP Transaction handle!\n"); } else { cw_copy_string(source, osp->source, sizeof(source)); res = 1; } break; } osp = osp->next; } cw_mutex_unlock(&osplock); if (res) { res = 0; dummy = 0; if (!OSPPTransactionValidateAuthorisation(*handle, iabuf, source, NULL, NULL, callerid, OSPC_E164, extension, OSPC_E164, 0, "", tokenlen, token2, &authorised, timelimit, &dummy, NULL, tokenformat)) { if (authorised) { cw_log(LOG_DEBUG, "Validated token for '%s' from '%s@%s'\n", extension, callerid, iabuf); res = 1; } } } return res; }
static int MYSQL_exec(struct cw_channel *chan, int argc, char **argv) { struct localuser *u; int result; char sresult[10]; if (argc == 0 || !argv[0][0]) { cw_log(LOG_WARNING, "APP_MYSQL requires an argument (see manual)\n"); return -1; } #if EXTRA_LOG fprintf(stderr,"MYSQL_exec: arg=%s\n", argv[0]); #endif LOCAL_USER_ADD(u); result=0; cw_mutex_lock(&_mysql_mutex); if (strncasecmp("connect",argv[0],strlen("connect"))==0) { result=aMYSQL_connect(chan,cw_strdupa(argv[0])); } else if (strncasecmp("query",argv[0],strlen("query"))==0) { result=aMYSQL_query(chan,cw_strdupa(argv[0])); } else if (strncasecmp("fetch",argv[0],strlen("fetch"))==0) { result=aMYSQL_fetch(chan,cw_strdupa(argv[0])); } else if (strncasecmp("clear",argv[0],strlen("clear"))==0) { result=aMYSQL_clear(chan,cw_strdupa(argv[0])); } else if (strncasecmp("disconnect",argv[0],strlen("disconnect"))==0) { result=aMYSQL_disconnect(chan,cw_strdupa(argv[0])); } else { cw_log(LOG_WARNING, "Unknown argument to MYSQL application : %s\n", argv[0]); result=-1; } cw_mutex_unlock(&_mysql_mutex); LOCAL_USER_REMOVE(u); snprintf(sresult, sizeof(sresult), "%d", result); pbx_builtin_setvar_helper(chan, "MYSQL_STATUS", sresult); return 0; }
int cw_callerid_split(const char *buf, char *name, int namelen, char *num, int numlen) { char *tmp; char *l = NULL; char *n = NULL; tmp = cw_strdupa(buf); cw_callerid_parse(tmp, &n, &l); if (n) cw_copy_string(name, n, namelen); else name[0] = '\0'; if (l) { cw_shrink_phone_number(l); cw_copy_string(num, l, numlen); } else num[0] = '\0'; return 0; }
int cw_playtones_start(struct cw_channel *chan, int vol, const char *playlst, int interruptible) { char *s; char *data = cw_strdupa(playlst); struct playtones_def d = { vol, -1, 0, 1, NULL}; char *stringp = NULL; char *separator; if (vol >= 0) d.vol = -13; else d.vol = vol; d.interruptible = interruptible; stringp = data; /* the stringp/data is not null here */ /* check if the data is separated with '|' or with ',' by default */ if (strchr(stringp,'|')) separator = "|"; else separator = ","; s = strsep(&stringp,separator); while (s && *s) { int freq1, freq2, time, modulate=0, moddepth=90, midinote=0; if (s[0] == '!') s++; else if (d.reppos == -1) d.reppos = d.nitems; if (sscanf(s, "%d+%d/%d", &freq1, &freq2, &time) == 3) { /* f1+f2/time format */ } else if (sscanf(s, "%d+%d", &freq1, &freq2) == 2) { /* f1+f2 format */ time = 0; } else if (sscanf(s, "%d*%d/%d", &freq1, &freq2, &time) == 3) { /* f1*f2/time format */ modulate = 1; } else if (sscanf(s, "%d*%d@%d/%d", &freq1, &freq2, &moddepth, &time) == 4) { /* f1*f2@md/time format */ modulate = 1; } else if (sscanf(s, "%d*%d", &freq1, &freq2) == 2) { /* f1*f2 format */ time = 0; modulate = 1; } else if (sscanf(s, "%d*%d@%d", &freq1, &freq2, &moddepth) == 3) { /* f1*f2@md format */ time = 0; modulate = 1; } else if (sscanf(s, "%d/%d", &freq1, &time) == 2) { /* f1/time format */ freq2 = 0; } else if (sscanf(s, "%d", &freq1) == 1) { /* f1 format */ freq2 = 0; time = 0; } else if (sscanf(s, "M%d+M%d/%d", &freq1, &freq2, &time) == 3) { /* Mf1+Mf2/time format */ midinote = 1; } else if (sscanf(s, "M%d+M%d", &freq1, &freq2) == 2) { /* Mf1+Mf2 format */ time = 0; midinote = 1; } else if (sscanf(s, "M%d*M%d/%d", &freq1, &freq2, &time) == 3) { /* Mf1*Mf2/time format */ modulate = 1; midinote = 1; } else if (sscanf(s, "M%d*M%d", &freq1, &freq2) == 2) { /* Mf1*Mf2 format */ time = 0; modulate = 1; midinote = 1; } else if (sscanf(s, "M%d/%d", &freq1, &time) == 2) { /* Mf1/time format */ freq2 = -1; midinote = 1; } else if (sscanf(s, "M%d", &freq1) == 1) { /* Mf1 format */ freq2 = -1; time = 0; midinote = 1; } else { cw_log(LOG_WARNING,"%s: tone component '%s' of '%s' is no good\n",chan->name,s,playlst); return -1; } if (midinote) { /* midi notes must be between 0 and 127 */ if ((freq1 >= 0) && (freq1 <= 127)) freq1 = midi_to_hz[freq1]; else freq1 = 0; if ((freq2 >= 0) && (freq2 <= 127)) freq2 = midi_to_hz[freq2]; else freq2 = 0; } if ((d.items = realloc(d.items,(d.nitems + 1)*sizeof(struct playtones_item))) == NULL) { cw_log(LOG_WARNING, "Realloc failed!\n"); return -1; } d.items[d.nitems].freq1 = freq1; d.items[d.nitems].freq2 = freq2; d.items[d.nitems].duration = time; d.items[d.nitems].modulate = modulate; d.items[d.nitems].modulation_depth = moddepth; d.nitems++; s = strsep(&stringp, separator); } if (cw_generator_activate(chan, &playtones, &d)) return -1; return 0; }
int cw_play_and_prepend(struct cw_channel *chan, char *playfile, char *recordfile, int maxtime, char *fmt, int *duration, int beep, int silencethreshold, int maxsilence) { int d = 0; char *fmts; char comment[256]; int x, fmtcnt=1, res=-1,outmsg=0; struct cw_frame *f; struct cw_filestream *others[MAX_OTHER_FORMATS]; struct cw_filestream *realfiles[MAX_OTHER_FORMATS]; char *sfmt[MAX_OTHER_FORMATS]; char *stringp=NULL; time_t start, end; struct cw_dsp *sildet; /* silence detector dsp */ int totalsilence = 0; int dspsilence = 0; int gotsilence = 0; /* did we timeout for silence? */ int rfmt=0; char prependfile[80]; if (silencethreshold < 0) silencethreshold = global_silence_threshold; if (maxsilence < 0) maxsilence = global_maxsilence; /* barf if no pointer passed to store duration in */ if (duration == NULL) { cw_log(LOG_WARNING, "Error play_and_prepend called without duration pointer\n"); return -1; } cw_log(LOG_DEBUG,"play_and_prepend: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt); snprintf(comment,sizeof(comment),"Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name); if (playfile || beep) { if (!beep) d = cw_play_and_wait(chan, playfile); if (d > -1) d = cw_streamfile(chan, "beep",chan->language); if (!d) d = cw_waitstream(chan,""); if (d < 0) return -1; } cw_copy_string(prependfile, recordfile, sizeof(prependfile)); strncat(prependfile, "-prepend", sizeof(prependfile) - strlen(prependfile) - 1); fmts = cw_strdupa(fmt); stringp=fmts; strsep(&stringp, "|,"); cw_log(LOG_DEBUG,"Recording Formats: sfmts=%s\n", fmts); sfmt[0] = cw_strdupa(fmts); while((fmt = strsep(&stringp, "|,"))) { if (fmtcnt > MAX_OTHER_FORMATS - 1) { cw_log(LOG_WARNING, "Please increase MAX_OTHER_FORMATS in app_voicemail.c\n"); break; } sfmt[fmtcnt++] = cw_strdupa(fmt); } time(&start); end=start; /* pre-initialize end to be same as start in case we never get into loop */ for (x=0;x<fmtcnt;x++) { others[x] = cw_writefile(prependfile, sfmt[x], comment, O_TRUNC, 0, 0700); cw_verbose( VERBOSE_PREFIX_3 "x=%d, open writing: %s format: %s, %p\n", x, prependfile, sfmt[x], others[x]); if (!others[x]) { break; } } sildet = cw_dsp_new(); /* Create the silence detector */ if (!sildet) { cw_log(LOG_WARNING, "Unable to create silence detector :(\n"); return -1; } cw_dsp_set_threshold(sildet, silencethreshold); if (maxsilence > 0) { rfmt = chan->readformat; res = cw_set_read_format(chan, CW_FORMAT_SLINEAR); if (res < 0) { cw_log(LOG_WARNING, "Unable to set to linear mode, giving up\n"); return -1; } } if (x == fmtcnt) { /* Loop forever, writing the packets we read to the writer(s), until we read a # or get a hangup */ f = NULL; for(;;) { res = cw_waitfor(chan, 2000); if (!res) { cw_log(LOG_DEBUG, "One waitfor failed, trying another\n"); /* Try one more time in case of masq */ res = cw_waitfor(chan, 2000); if (!res) { cw_log(LOG_WARNING, "No audio available on %s??\n", chan->name); res = -1; } } if (res < 0) { f = NULL; break; } f = cw_read(chan); if (!f) break; if (f->frametype == CW_FRAME_VOICE) { /* write each format */ for (x=0;x<fmtcnt;x++) { if (!others[x]) break; res = cw_writestream(others[x], f); } /* Silence Detection */ if (maxsilence > 0) { dspsilence = 0; cw_dsp_silence(sildet, f, &dspsilence); if (dspsilence) totalsilence = dspsilence; else totalsilence = 0; if (totalsilence > maxsilence) { /* Ended happily with silence */ if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000); cw_fr_free(f); gotsilence = 1; outmsg=2; break; } } /* Exit on any error */ if (res) { cw_log(LOG_WARNING, "Error writing frame\n"); cw_fr_free(f); break; } } else if (f->frametype == CW_FRAME_VIDEO) { /* Write only once */ cw_writestream(others[0], f); } else if (f->frametype == CW_FRAME_DTMF) { /* stop recording with any digit */ if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "User ended message by pressing %c\n", f->subclass); res = 't'; outmsg = 2; cw_fr_free(f); break; } if (maxtime) { time(&end); if (maxtime < (end - start)) { if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "Took too long, cutting it short...\n"); res = 't'; outmsg=2; cw_fr_free(f); break; } } cw_fr_free(f); } if (end == start) time(&end); if (!f) { if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "User hung up\n"); res = -1; outmsg=1; #if 0 /* delete all the prepend files */ for (x=0;x<fmtcnt;x++) { if (!others[x]) break; cw_closestream(others[x]); cw_filedelete(prependfile, sfmt[x]); } #endif } } else { cw_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", prependfile, sfmt[x]); } *duration = end - start; #if 0 if (outmsg > 1) { #else if (outmsg) { #endif struct cw_frame *fr; for (x=0;x<fmtcnt;x++) { snprintf(comment, sizeof(comment), "Opening the real file %s.%s\n", recordfile, sfmt[x]); realfiles[x] = cw_readfile(recordfile, sfmt[x], comment, O_RDONLY, 0, 0); if (!others[x] || !realfiles[x]) break; if (totalsilence) cw_stream_rewind(others[x], totalsilence-200); else cw_stream_rewind(others[x], 200); cw_truncstream(others[x]); /* add the original file too */ while ((fr = cw_readframe(realfiles[x]))) { cw_writestream(others[x],fr); } cw_closestream(others[x]); cw_closestream(realfiles[x]); cw_filerename(prependfile, recordfile, sfmt[x]); #if 0 cw_verbose("Recording Format: sfmts=%s, prependfile %s, recordfile %s\n", sfmt[x],prependfile,recordfile); #endif cw_filedelete(prependfile, sfmt[x]); } } if (rfmt) { if (cw_set_read_format(chan, rfmt)) { cw_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", cw_getformatname(rfmt), chan->name); } } if (outmsg) { if (outmsg > 1) { /* Let them know it worked */ cw_streamfile(chan, "auth-thankyou", chan->language); cw_waitstream(chan, ""); } } return res; } /* Channel group core functions */ int cw_app_group_split_group(char *data, char *group, int group_max, char *category, int category_max) { int res=0; char tmp[256]; char *grp=NULL, *cat=NULL; if (!cw_strlen_zero(data)) { cw_copy_string(tmp, data, sizeof(tmp)); grp = tmp; cat = strchr(tmp, '@'); if (cat) { *cat = '\0'; cat++; } } if (!cw_strlen_zero(grp)) cw_copy_string(group, grp, group_max); else res = -1; if (cat) snprintf(category, category_max, "%s_%s", GROUP_CATEGORY_PREFIX, cat); else cw_copy_string(category, GROUP_CATEGORY_PREFIX, category_max); return res; }
int cw_play_and_record(struct cw_channel *chan, const char *playfile, const char *recordfile, int maxtime, const char *fmt, int *duration, int silencethreshold, int maxsilence, const char *path) { int d; char *fmts; char comment[256]; int x, fmtcnt=1, res=-1,outmsg=0; struct cw_frame *f; struct cw_filestream *others[MAX_OTHER_FORMATS]; char *sfmt[MAX_OTHER_FORMATS]; char *stringp=NULL; time_t start, end; struct cw_dsp *sildet=NULL; /* silence detector dsp */ int totalsilence = 0; int dspsilence = 0; int gotsilence = 0; /* did we timeout for silence? */ int rfmt=0; if (silencethreshold < 0) silencethreshold = global_silence_threshold; if (maxsilence < 0) maxsilence = global_maxsilence; /* barf if no pointer passed to store duration in */ if (duration == NULL) { cw_log(LOG_WARNING, "Error play_and_record called without duration pointer\n"); return -1; } cw_log(LOG_DEBUG,"play_and_record: %s, %s, '%s'\n", playfile ? playfile : "<None>", recordfile, fmt); snprintf(comment,sizeof(comment),"Playing %s, Recording to: %s on %s\n", playfile ? playfile : "<None>", recordfile, chan->name); if (playfile) { d = cw_play_and_wait(chan, playfile); if (d > -1) d = cw_streamfile(chan, "beep",chan->language); if (!d) d = cw_waitstream(chan,""); if (d < 0) return -1; } fmts = cw_strdupa(fmt); stringp=fmts; strsep(&stringp, "|,"); cw_log(LOG_DEBUG,"Recording Formats: sfmts=%s\n", fmts); sfmt[0] = cw_strdupa(fmts); while((fmt = strsep(&stringp, "|,"))) { if (fmtcnt > MAX_OTHER_FORMATS - 1) { cw_log(LOG_WARNING, "Please increase MAX_OTHER_FORMATS in app_voicemail.c\n"); break; } sfmt[fmtcnt++] = cw_strdupa(fmt); } time(&start); end=start; /* pre-initialize end to be same as start in case we never get into loop */ for (x=0;x<fmtcnt;x++) { others[x] = cw_writefile(recordfile, sfmt[x], comment, O_TRUNC, 0, 0700); cw_verbose( VERBOSE_PREFIX_3 "x=%d, open writing: %s format: %s, %p\n", x, recordfile, sfmt[x], others[x]); if (!others[x]) { break; } } if (path) cw_unlock_path(path); if (maxsilence > 0) { sildet = cw_dsp_new(); /* Create the silence detector */ if (!sildet) { cw_log(LOG_WARNING, "Unable to create silence detector :(\n"); return -1; } cw_dsp_set_threshold(sildet, silencethreshold); rfmt = chan->readformat; res = cw_set_read_format(chan, CW_FORMAT_SLINEAR); if (res < 0) { cw_log(LOG_WARNING, "Unable to set to linear mode, giving up\n"); cw_dsp_free(sildet); return -1; } } /* Request a video update */ cw_indicate(chan, CW_CONTROL_VIDUPDATE); if (x == fmtcnt) { /* Loop forever, writing the packets we read to the writer(s), until we read a # or get a hangup */ f = NULL; for(;;) { res = cw_waitfor(chan, 2000); if (!res) { cw_log(LOG_DEBUG, "One waitfor failed, trying another\n"); /* Try one more time in case of masq */ res = cw_waitfor(chan, 2000); if (!res) { cw_log(LOG_WARNING, "No audio available on %s??\n", chan->name); res = -1; } } if (res < 0) { f = NULL; break; } f = cw_read(chan); if (!f) break; if (f->frametype == CW_FRAME_VOICE) { /* write each format */ for (x=0;x<fmtcnt;x++) { res = cw_writestream(others[x], f); } /* Silence Detection */ if (maxsilence > 0) { dspsilence = 0; cw_dsp_silence(sildet, f, &dspsilence); if (dspsilence) totalsilence = dspsilence; else totalsilence = 0; if (totalsilence > maxsilence) { /* Ended happily with silence */ if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "Recording automatically stopped after a silence of %d seconds\n", totalsilence/1000); cw_fr_free(f); gotsilence = 1; outmsg=2; break; } } /* Exit on any error */ if (res) { cw_log(LOG_WARNING, "Error writing frame\n"); cw_fr_free(f); break; } } else if (f->frametype == CW_FRAME_VIDEO) { /* Write only once */ cw_writestream(others[0], f); } else if (f->frametype == CW_FRAME_DTMF) { if (f->subclass == '#') { if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "User ended message by pressing %c\n", f->subclass); res = '#'; outmsg = 2; cw_fr_free(f); break; } if (f->subclass == '0') { /* Check for a '0' during message recording also, in case caller wants operator */ if (option_verbose > 2) cw_verbose(VERBOSE_PREFIX_3 "User cancelled by pressing %c\n", f->subclass); res = '0'; outmsg = 0; cw_fr_free(f); break; } } if (maxtime) { time(&end); if (maxtime < (end - start)) { if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "Took too long, cutting it short...\n"); outmsg = 2; res = 't'; cw_fr_free(f); break; } } cw_fr_free(f); } if (end == start) time(&end); if (!f) { if (option_verbose > 2) cw_verbose( VERBOSE_PREFIX_3 "User hung up\n"); res = -1; outmsg=1; } } else { cw_log(LOG_WARNING, "Error creating writestream '%s', format '%s'\n", recordfile, sfmt[x]); } *duration = end - start; for (x=0;x<fmtcnt;x++) { if (!others[x]) break; if (res > 0) { if (totalsilence) cw_stream_rewind(others[x], totalsilence-200); else cw_stream_rewind(others[x], 200); } cw_truncstream(others[x]); cw_closestream(others[x]); } if (rfmt) { if (cw_set_read_format(chan, rfmt)) { cw_log(LOG_WARNING, "Unable to restore format %s to channel '%s'\n", cw_getformatname(rfmt), chan->name); } } if (outmsg > 1) { /* Let them know recording is stopped */ if(!cw_streamfile(chan, "auth-thankyou", chan->language)) cw_waitstream(chan, ""); } if (sildet) cw_dsp_free(sildet); return res; }
static int ivr_dispatch(struct cw_channel *chan, struct cw_ivr_option *option, char *exten, void *cbdata) { int res; int (*ivr_func)(struct cw_channel *, void *); char *c; char *n; switch(option->action) { case CW_ACTION_UPONE: return RES_UPONE; case CW_ACTION_EXIT: return RES_EXIT | (((unsigned long)(option->adata)) & 0xffff); case CW_ACTION_REPEAT: return RES_REPEAT | (((unsigned long)(option->adata)) & 0xffff); case CW_ACTION_RESTART: return RES_RESTART ; case CW_ACTION_NOOP: return 0; case CW_ACTION_BACKGROUND: res = cw_streamfile(chan, (char *)option->adata, chan->language); if (!res) { res = cw_waitstream(chan, CW_DIGIT_ANY); } else { cw_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); res = 0; } return res; case CW_ACTION_PLAYBACK: res = cw_streamfile(chan, (char *)option->adata, chan->language); if (!res) { res = cw_waitstream(chan, ""); } else { cw_log(LOG_NOTICE, "Unable to find file '%s'!\n", (char *)option->adata); res = 0; } return res; case CW_ACTION_MENU: res = cw_ivr_menu_run_internal(chan, (struct cw_ivr_menu *)option->adata, cbdata); /* Do not pass entry errors back up, treat as though it was an "UPONE" */ if (res == -2) res = 0; return res; case CW_ACTION_WAITOPTION: res = cw_waitfordigit(chan, 1000 * (chan->pbx ? chan->pbx->rtimeout : 10)); if (!res) return 't'; return res; case CW_ACTION_CALLBACK: ivr_func = option->adata; res = ivr_func(chan, cbdata); return res; case CW_ACTION_TRANSFER: res = cw_parseable_goto(chan, option->adata); return 0; case CW_ACTION_PLAYLIST: case CW_ACTION_BACKLIST: res = 0; c = cw_strdupa(option->adata); while((n = strsep(&c, ";"))) if ((res = cw_streamfile(chan, n, chan->language)) || (res = cw_waitstream(chan, (option->action == CW_ACTION_BACKLIST) ? CW_DIGIT_ANY : ""))) break; cw_stopstream(chan); return res; default: cw_log(LOG_NOTICE, "Unknown dispatch function %d, ignoring!\n", option->action); return 0; }; return -1; }
static int originate_cli(int fd, int argc, char *argv[]) { char *chan_name_1,*context,*exten,*tech,*data,*callerid; int pri=0,to=60000; struct fast_originate_helper *in; pthread_t thread; pthread_attr_t attr; int result; char *num = NULL; if(argc < 3) { cw_cli(fd,USAGE); return -1; } chan_name_1 = argv[1]; exten = cw_strdupa(argv[2]); if((context = strchr(exten,'@'))) { *context = 0; context++; } if(! (context && exten)) { cw_cli(fd,CGUSAGE); return -1; } pri = argv[3] ? atoi(argv[3]) : 1; if(!pri) pri = 1; tech = cw_strdupa(chan_name_1); if((data = strchr(tech,'/'))) { *data = '\0'; data++; } if(!(tech && data)) { cw_cli(fd,USAGE); return -1; } in = malloc(sizeof(struct fast_originate_helper)); if(!in) { cw_cli(fd,"No Memory!\n"); return -1; } memset(in,0,sizeof(struct fast_originate_helper)); callerid = (argc > 4) ? argv[4] : NULL; to = (argc > 5) ? atoi(argv[5]) : 60000; strncpy(in->tech,tech,sizeof(in->tech)); strncpy(in->data,data,sizeof(in->data)); in->timeout=to; if(callerid) { if((num = strchr(callerid,':'))) { *num = '\0'; num++; strncpy(in->cid_num,num,sizeof(in->cid_num)); } strncpy(in->cid_name,callerid,sizeof(in->cid_name)); } strncpy(in->context,context,sizeof(in->context)); strncpy(in->exten,exten,sizeof(in->exten)); in->priority = pri; cw_cli(fd,"Originating Call %s/%s %s %s %d\n",in->tech,in->data,in->context,in->exten,in->priority); result = pthread_attr_init(&attr); pthread_attr_setschedpolicy(&attr, SCHED_RR); pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); result = cw_pthread_create(&thread, &attr,originate,in); result = pthread_attr_destroy(&attr); return 0; }
static int changrab_cli(int fd, int argc, char *argv[]) { char *chan_name_1, *chan_name_2 = NULL, *context,*exten,*flags=NULL; char *pria = NULL; struct cw_channel *xferchan_1, *xferchan_2; int pri=0,x=1; if(argc < 3) { cw_cli(fd,CGUSAGE); return -1; } chan_name_1 = argv[x++]; if(chan_name_1[0] == '-') { flags = cw_strdupa(chan_name_1); if (strchr(flags,'h')) { chan_name_1 = argv[x++]; if((xferchan_1 = my_cw_get_channel_by_name_locked(chan_name_1))) { cw_mutex_unlock(&xferchan_1->lock); cw_hangup(xferchan_1); cw_verbose("OK, good luck!\n"); return 0; } else return -1; } else if (strchr(flags,'m') || strchr(flags,'M')) { chan_name_1 = argv[x++]; if((xferchan_1 = my_cw_get_channel_by_name_locked(chan_name_1))) { cw_mutex_unlock(&xferchan_1->lock); strchr(flags,'m') ? cw_moh_start(xferchan_1,NULL) : cw_moh_stop(xferchan_1); } else return 1; return 0; } if(argc < 4) { cw_cli(fd,CGUSAGE); return -1; } chan_name_1 = argv[x++]; } exten = cw_strdupa(argv[x++]); if((context = strchr(exten,'@'))) { *context = 0; context++; if(!(context && exten)) { cw_cli(fd,CGUSAGE); return -1; } if((pria = strchr(context,':'))) { *pria = '\0'; pria++; pri = atoi(pria); } else { pri = argv[x] ? atoi(argv[x++]) : 1; } if(!pri) pri = 1; } else if (strchr(exten,'/')) { chan_name_2 = exten; } xferchan_1 = my_cw_get_channel_by_name_locked(chan_name_1); if(!xferchan_1) { cw_log(LOG_WARNING, "No Such Channel: %s\n",chan_name_1); return -1; } cw_mutex_unlock(&xferchan_1->lock); if(flags && strchr(flags,'b')) { if(cw_bridged_channel(xferchan_1)) { xferchan_1 = cw_bridged_channel(xferchan_1); } } if(chan_name_2) { struct cw_frame *f; struct cw_channel *newchan_1, *newchan_2; if (!(newchan_1 = cw_channel_alloc(0))) { cw_log(LOG_WARNING, "Memory Error!\n"); cw_hangup(newchan_1); return -1; } else { snprintf(newchan_1->name, sizeof (newchan_1->name), "ChanGrab/%s", xferchan_1->name); newchan_1->readformat = xferchan_1->readformat; newchan_1->writeformat = xferchan_1->writeformat; cw_channel_masquerade(newchan_1, xferchan_1); if ((f = cw_read(newchan_1))) { cw_fr_free(f); } else { cw_hangup(newchan_1); return -1; } } if(!(xferchan_2 = my_cw_get_channel_by_name_locked(chan_name_2))) { cw_log(LOG_WARNING, "No Such Channel: %s\n",chan_name_2); cw_hangup(newchan_1); return -1; } cw_mutex_unlock(&xferchan_2->lock); if(flags && strchr(flags, 'B')) { if(cw_bridged_channel(xferchan_2)) { xferchan_2 = cw_bridged_channel(xferchan_2); } } if(!(newchan_2 = cw_channel_alloc(0))) { cw_log(LOG_WARNING, "Memory Error!\n"); cw_hangup(newchan_1); return -1; } else { snprintf(newchan_2->name, sizeof (newchan_2->name), "ChanGrab/%s", xferchan_2->name); newchan_2->readformat = xferchan_2->readformat; newchan_2->writeformat = xferchan_2->writeformat; cw_channel_masquerade(newchan_2, xferchan_2); if ((f = cw_read(newchan_2))) { cw_fr_free(f); } else { cw_hangup(newchan_1); cw_hangup(newchan_2); return -1; } } cw_bridge_call_thread_launch(newchan_1, newchan_2); } else { cw_verbose("Transferring_to context %s, extension %s, priority %d\n", context, exten, pri); cw_async_goto(xferchan_1, context, exten, pri); if(xferchan_1) cw_mutex_unlock(&xferchan_1->lock); } return 0; }