static int execif_exec(struct ast_channel *chan, void *data) { int res=0; struct localuser *u; char *myapp = NULL; char *mydata = NULL; char *expr = NULL; struct ast_app *app = NULL; LOCAL_USER_ADD(u); expr = ast_strdupa(data); if (!expr) { ast_log(LOG_ERROR, "Out of memory\n"); LOCAL_USER_REMOVE(u); return -1; } if ((myapp = strchr(expr,'|'))) { *myapp = '\0'; myapp++; if ((mydata = strchr(myapp,'|'))) { *mydata = '\0'; mydata++; } else mydata = ""; if (pbx_checkcondition(expr)) { if ((app = pbx_findapp(myapp))) { res = pbx_exec(chan, app, mydata, 1); } else { ast_log(LOG_WARNING, "Count not find application! (%s)\n", myapp); res = -1; } } } else { ast_log(LOG_ERROR,"Invalid Syntax.\n"); res = -1; } ALL_DONE(u,res); }
static int execif_exec(struct cw_channel *chan, int argc, char **argv) { int res=0; struct localuser *u; struct cw_app *app = NULL; if (argc < 2 || !argv[0][0] || !argv[1][0]) { cw_log(LOG_ERROR, "Syntax: %s\n", execif_syntax); return -1; } LOCAL_USER_ADD(u); if (cw_true(argv[0])) { if ((app = pbx_findapp(argv[1]))) { res = pbx_exec_argv(chan, app, argc - 2, argv + 2); } else { cw_log(LOG_WARNING, "Count not find application! (%s)\n", argv[1]); res = -1; } } ALL_DONE(u,res); }
static int _while_exec(struct cw_channel *chan, int argc, char **argv, int end) { int res=0; struct localuser *u; char *while_pri = NULL; char *goto_str = NULL, *my_name = NULL; char *label = NULL; char varname[VAR_SIZE], end_varname[VAR_SIZE]; const char *prefix = "WHILE"; size_t size=0; int used_index_i = -1, x=0; char used_index[VAR_SIZE] = "0", new_index[VAR_SIZE] = "0"; if (!end && argc != 1) { cw_log(LOG_ERROR, "Syntax: %s\n", while_syntax); return -1; } if (!chan) { /* huh ? */ return -1; } LOCAL_USER_ADD(u); /* dont want run away loops if the chan isn't even up this is up for debate since it slows things down a tad ...... */ if (cw_waitfordigit(chan,1) < 0) ALL_DONE(u,-1); for (x=0;;x++) { if (get_index(chan, prefix, x)) { used_index_i = x; } else break; } snprintf(used_index, VAR_SIZE, "%d", used_index_i); snprintf(new_index, VAR_SIZE, "%d", used_index_i + 1); size = strlen(chan->context) + strlen(chan->exten) + 32; my_name = alloca(size); snprintf(my_name, size, "%s_%s_%d", chan->context, chan->exten, chan->priority); if (cw_strlen_zero(label)) { if (end) label = used_index; else if (!(label = pbx_builtin_getvar_helper(chan, my_name))) { label = new_index; pbx_builtin_setvar_helper(chan, my_name, label); } } snprintf(varname, VAR_SIZE, "%s_%s", prefix, label); while_pri = pbx_builtin_getvar_helper(chan, varname); if ((while_pri = pbx_builtin_getvar_helper(chan, varname)) && !end) { snprintf(end_varname, VAR_SIZE, "END_%s", varname); } if (!end && !cw_true(argv[0])) { /* Condition Met (clean up helper vars) */ pbx_builtin_setvar_helper(chan, varname, NULL); pbx_builtin_setvar_helper(chan, my_name, NULL); snprintf(end_varname, VAR_SIZE, "END_%s", varname); if ((goto_str=pbx_builtin_getvar_helper(chan, end_varname))) { pbx_builtin_setvar_helper(chan, end_varname, NULL); cw_parseable_goto(chan, goto_str); } else { int pri = find_matching_endwhile(chan); if (pri > 0) { if (option_verbose > 2) cw_verbose(VERBOSE_PREFIX_3 "Jumping to priority %d\n", pri); chan->priority = pri; } else { cw_log(LOG_WARNING, "Couldn't find matching EndWhile? (While at %s@%s priority %d)\n", chan->context, chan->exten, chan->priority); } } ALL_DONE(u,res); } if (!end && !while_pri) { size = strlen(chan->context) + strlen(chan->exten) + 32; goto_str = alloca(size); snprintf(goto_str, size, "%s,%s,%d", chan->context, chan->exten, chan->priority); pbx_builtin_setvar_helper(chan, varname, goto_str); } else if (end && while_pri) { /* END of loop */ snprintf(end_varname, VAR_SIZE, "END_%s", varname); if (! pbx_builtin_getvar_helper(chan, end_varname)) { size = strlen(chan->context) + strlen(chan->exten) + 32; goto_str = alloca(size); snprintf(goto_str, size, "%s,%s,%d", chan->context, chan->exten, chan->priority+1); pbx_builtin_setvar_helper(chan, end_varname, goto_str); } cw_parseable_goto(chan, while_pri); } ALL_DONE(u, res); }
static int chanspy_exec(struct ast_channel *chan, void *data) { struct localuser *u; struct ast_channel *peer=NULL, *prev=NULL; char name[AST_NAME_STRLEN], peer_name[AST_NAME_STRLEN + 5], *args, *ptr = NULL, *options = NULL, *spec = NULL, *argv[5], *mygroup = NULL, *recbase = NULL; int res = -1, volfactor = 0, silent = 0, argc = 0, bronly = 0, chosen = 0, count=0, waitms = 100, num = 0, oldrf = 0, oldwf = 0, fd = 0; struct ast_flags flags; signed char zero_volume = 0; if (!(args = ast_strdupa((char *)data))) { ast_log(LOG_ERROR, "Out of memory!\n"); return -1; } LOCAL_USER_ADD(u); oldrf = chan->readformat; oldwf = chan->writeformat; if (ast_set_read_format(chan, AST_FORMAT_SLINEAR) < 0) { ast_log(LOG_ERROR, "Could Not Set Read Format.\n"); LOCAL_USER_REMOVE(u); return -1; } if (ast_set_write_format(chan, AST_FORMAT_SLINEAR) < 0) { ast_log(LOG_ERROR, "Could Not Set Write Format.\n"); LOCAL_USER_REMOVE(u); return -1; } ast_answer(chan); ast_set_flag(chan, AST_FLAG_SPYING); /* so nobody can spy on us while we are spying */ if ((argc = ast_app_separate_args(args, '|', argv, sizeof(argv) / sizeof(argv[0])))) { spec = argv[0]; if ( argc > 1) { options = argv[1]; } if (ast_strlen_zero(spec) || !strcmp(spec, "all")) { spec = NULL; } } if (options) { char *opts[OPT_ARG_ARRAY_SIZE]; ast_app_parse_options(chanspy_opts, &flags, opts, options); if (ast_test_flag(&flags, OPTION_GROUP)) { mygroup = opts[OPT_ARG_GROUP]; } if (ast_test_flag(&flags, OPTION_RECORD)) { if (!(recbase = opts[OPT_ARG_RECORD])) { recbase = "chanspy"; } } silent = ast_test_flag(&flags, OPTION_QUIET); bronly = ast_test_flag(&flags, OPTION_BRIDGED); if (ast_test_flag(&flags, OPTION_VOLUME) && opts[OPT_ARG_VOLUME]) { int vol; if ((sscanf(opts[OPT_ARG_VOLUME], "%d", &vol) != 1) || (vol > 4) || (vol < -4)) ast_log(LOG_NOTICE, "Volume factor must be a number between -4 and 4\n"); else volfactor = vol; } } else ast_clear_flag(&flags, AST_FLAGS_ALL); if (recbase) { char filename[512]; snprintf(filename,sizeof(filename),"%s/%s.%d.raw",ast_config_AST_MONITOR_DIR, recbase, (int)time(NULL)); if ((fd = open(filename, O_CREAT | O_WRONLY, O_TRUNC, 0644)) <= 0) { ast_log(LOG_WARNING, "Cannot open %s for recording\n", filename); fd = 0; } } for(;;) { if (!silent) { res = ast_streamfile(chan, "beep", chan->language); if (!res) res = ast_waitstream(chan, ""); if (res < 0) { ast_clear_flag(chan, AST_FLAG_SPYING); break; } } count = 0; res = ast_waitfordigit(chan, waitms); if (res < 0) { ast_clear_flag(chan, AST_FLAG_SPYING); break; } peer = local_channel_walk(NULL); prev=NULL; while(peer) { if (peer != chan) { char *group = NULL; int igrp = 1; if (peer == prev && !chosen) { break; } chosen = 0; group = pbx_builtin_getvar_helper(peer, "SPYGROUP"); if (mygroup) { if (!group || strcmp(mygroup, group)) { igrp = 0; } } if (igrp && (!spec || ((strlen(spec) <= strlen(peer->name) && !strncasecmp(peer->name, spec, strlen(spec)))))) { if (peer && (!bronly || ast_bridged_channel(peer)) && !ast_check_hangup(peer) && !ast_test_flag(peer, AST_FLAG_SPYING)) { int x = 0; strncpy(peer_name, "spy-", 5); strncpy(peer_name + strlen(peer_name), peer->name, AST_NAME_STRLEN); ptr = strchr(peer_name, '/'); *ptr = '\0'; ptr++; for (x = 0 ; x < strlen(peer_name) ; x++) { if (peer_name[x] == '/') { break; } peer_name[x] = tolower(peer_name[x]); } if (!silent) { if (ast_fileexists(peer_name, NULL, NULL) != -1) { res = ast_streamfile(chan, peer_name, chan->language); if (!res) res = ast_waitstream(chan, ""); if (res) break; } else res = ast_say_character_str(chan, peer_name, "", chan->language); if ((num=atoi(ptr))) ast_say_digits(chan, atoi(ptr), "", chan->language); } count++; prev = peer; res = channel_spy(chan, peer, &volfactor, fd); if (res == -1) { break; } else if (res > 1 && spec) { snprintf(name, AST_NAME_STRLEN, "%s/%d", spec, res); if ((peer = local_get_channel_begin_name(name))) { chosen = 1; } continue; } } } } if ((peer = local_channel_walk(peer)) == NULL) { break; } } waitms = count ? 100 : 5000; } if (fd > 0) { close(fd); } if (oldrf && ast_set_read_format(chan, oldrf) < 0) { ast_log(LOG_ERROR, "Could Not Set Read Format.\n"); } if (oldwf && ast_set_write_format(chan, oldwf) < 0) { ast_log(LOG_ERROR, "Could Not Set Write Format.\n"); } ast_clear_flag(chan, AST_FLAG_SPYING); ast_channel_setoption(chan, AST_OPTION_TXGAIN, &zero_volume, sizeof(zero_volume), 0); ALL_DONE(u, res); }