static int tryexec_exec(struct ast_channel *chan, void *data) { int res=0; struct ast_module_user *u; char *s, *appname, *endargs, args[MAXRESULT] = ""; struct ast_app *app; u = ast_module_user_add(chan); /* Check and parse arguments */ if (data) { s = ast_strdupa(data); appname = strsep(&s, "("); if (s) { endargs = strrchr(s, ')'); if (endargs) *endargs = '\0'; pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); } if (appname) { app = pbx_findapp(appname); if (app) { res = pbx_exec(chan, app, args); pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); } else { ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); } } } ast_module_user_remove(u); return 0; }
/*! \brief SpeechCreate() Dialplan Application */ static int speech_create(struct ast_channel *chan, const char *data) { struct ast_speech *speech = NULL; struct ast_datastore *datastore = NULL; /* Request a speech object */ speech = ast_speech_new(data, ast_channel_nativeformats(chan)); if (speech == NULL) { /* Not available */ pbx_builtin_setvar_helper(chan, "ERROR", "1"); return 0; } datastore = ast_datastore_alloc(&speech_datastore, NULL); if (datastore == NULL) { ast_speech_destroy(speech); pbx_builtin_setvar_helper(chan, "ERROR", "1"); return 0; } pbx_builtin_setvar_helper(chan, "ERROR", NULL); datastore->data = speech; ast_channel_lock(chan); ast_channel_datastore_add(chan, datastore); ast_channel_unlock(chan); return 0; }
/*! \brief SpeechCreate() Dialplan Application */ static int speech_create(struct ast_channel *chan, void *data) { struct ast_module_user *u = NULL; struct ast_speech *speech = NULL; struct ast_datastore *datastore = NULL; u = ast_module_user_add(chan); /* Request a speech object */ speech = ast_speech_new(data, AST_FORMAT_SLINEAR); if (speech == NULL) { /* Not available */ pbx_builtin_setvar_helper(chan, "ERROR", "1"); ast_module_user_remove(u); return 0; } datastore = ast_channel_datastore_alloc(&speech_datastore, NULL); if (datastore == NULL) { ast_speech_destroy(speech); pbx_builtin_setvar_helper(chan, "ERROR", "1"); ast_module_user_remove(u); return 0; } datastore->data = speech; ast_channel_datastore_add(chan, datastore); pbx_builtin_setvar_helper(chan, "ERROR", NULL); ast_module_user_remove(u); return 0; }
static int tryexec_exec(struct ast_channel *chan, void *data) { int res = 0; char *s, *appname, *endargs, args[MAXRESULT]; struct ast_app *app; if (ast_strlen_zero(data)) return 0; s = ast_strdupa(data); args[0] = 0; appname = strsep(&s, "("); if (s) { endargs = strrchr(s, ')'); if (endargs) *endargs = '\0'; pbx_substitute_variables_helper(chan, s, args, MAXRESULT - 1); } if (appname) { app = pbx_findapp(appname); if (app) { res = pbx_exec(chan, app, args); pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); } else { ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); } } return 0; }
static int steal_channel(struct ast_channel *chan, void *pattern) { int ret = 0; struct ast_module_user *u; struct ast_channel *cur; u = ast_module_user_add(chan); cur = find_matching_channel(chan, pattern, AST_STATE_UP); if (cur) { ast_verbose(VERBOSE_PREFIX_3 "Channel %s stole channel %s\n", chan->name, cur->name); pbx_builtin_setvar_helper(chan, "STEAL_CHANNEL", cur->name); if (chan->_state != AST_STATE_UP) { ast_answer(chan); } if (cur->_bridge) { if (!ast_mutex_lock(&cur->_bridge->lock)) { ast_moh_stop(cur->_bridge); ast_mutex_unlock(&cur->_bridge->lock); } } if (ast_channel_masquerade(cur, chan)) { ast_log(LOG_ERROR, "unable to masquerade\n"); ret = -1; } ast_mutex_unlock(&cur->lock); ast_mutex_unlock(&chan->lock); } else { pbx_builtin_setvar_helper(chan, "STEAL_CHANNEL", ""); } ast_module_user_remove(u); return(ret); }
static int reload_module(void) { struct ast_flags flags = { CONFIG_FLAG_NOREALTIME }; struct ast_config *cfg; struct ast_variable *var; if (!(cfg = ast_config_load("res_curl.conf", flags))) { return 0; } else if (cfg == CONFIG_STATUS_FILEINVALID) { ast_log(LOG_WARNING, "res_curl.conf could not be parsed!\n"); return 0; } if (!(var = ast_variable_browse(cfg, "globals")) && !(var = ast_variable_browse(cfg, "global")) && !(var = ast_variable_browse(cfg, "general"))) { ast_log(LOG_WARNING, "[globals] not found in res_curl.conf\n"); ast_config_destroy(cfg); return 0; } for (; var; var = var->next) { if (strncmp(var->name, "CURLOPT(", 8)) { char name[256]; snprintf(name, sizeof(name), "CURLOPT(%s)", var->name); pbx_builtin_setvar_helper(NULL, name, var->value); } else { pbx_builtin_setvar_helper(NULL, var->name, var->value); } } ast_config_destroy(cfg); return 0; }
static int tryexec_exec(struct ast_channel *chan, const char *data) { int res = 0; char *s, *appname, *endargs; struct ast_app *app; struct ast_str *args = NULL; if (ast_strlen_zero(data)) return 0; s = ast_strdupa(data); appname = strsep(&s, "("); if (s) { endargs = strrchr(s, ')'); if (endargs) *endargs = '\0'; if ((args = ast_str_create(16))) { ast_str_substitute_variables(&args, 0, chan, s); } } if (appname) { app = pbx_findapp(appname); if (app) { res = pbx_exec(chan, app, args ? ast_str_buffer(args) : NULL); pbx_builtin_setvar_helper(chan, "TRYSTATUS", res ? "FAILED" : "SUCCESS"); } else { ast_log(LOG_WARNING, "Could not find application (%s)\n", appname); pbx_builtin_setvar_helper(chan, "TRYSTATUS", "NOAPP"); } } ast_free(args); return 0; }
static int sendtext_exec(struct ast_channel *chan, const char *data) { char *status = "UNSUPPORTED"; struct ast_str *str; /* NOT ast_strlen_zero, because some protocols (e.g. SIP) MUST be able to * send a zero-length message. */ if (!data) { ast_log(LOG_WARNING, "SendText requires an argument (text)\n"); return -1; } if (!(str = ast_str_alloca(strlen(data) + 1))) { return -1; } ast_str_get_encoded_str(&str, -1, data); ast_channel_lock(chan); if (!chan->tech->send_text) { ast_channel_unlock(chan); /* Does not support transport */ pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status); return 0; } status = "FAILURE"; if (!ast_sendtext(chan, ast_str_buffer(str))) { status = "SUCCESS"; } ast_channel_unlock(chan); pbx_builtin_setvar_helper(chan, "SENDTEXTSTATUS", status); return 0; }
static int waituntil_exec(struct ast_channel *chan, void *data) { int res; double fraction; struct timeval future = { 0, }; struct timeval tv = ast_tvnow(); int msec; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "WaitUntil requires an argument(epoch)\n"); pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE"); return 0; } if (sscanf(data, "%ld%lf", (long *)&future.tv_sec, &fraction) == 0) { ast_log(LOG_WARNING, "WaitUntil called with non-numeric argument\n"); pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "FAILURE"); return 0; } future.tv_usec = fraction * 1000000; if ((msec = ast_tvdiff_ms(future, tv)) < 0) { ast_log(LOG_NOTICE, "WaitUntil called in the past (now %ld, arg %ld)\n", (long)tv.tv_sec, (long)future.tv_sec); pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "PAST"); return 0; } if ((res = ast_safe_sleep(chan, msec))) pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "HANGUP"); else pbx_builtin_setvar_helper(chan, "WAITUNTILSTATUS", "OK"); return res; }
static int transmit(fax_session *s) { int res = 0; /* Clear all channel variables which to be set by the application. Pre-set status to error so in case of any problems we can just leave */ pbx_builtin_setvar_helper(s->chan, "FAXSTATUS", "FAILED"); pbx_builtin_setvar_helper(s->chan, "FAXERROR", "Channel problems"); pbx_builtin_setvar_helper(s->chan, "FAXMODE", NULL); pbx_builtin_setvar_helper(s->chan, "REMOTESTATIONID", NULL); pbx_builtin_setvar_helper(s->chan, "FAXPAGES", "0"); pbx_builtin_setvar_helper(s->chan, "FAXRESOLUTION", NULL); pbx_builtin_setvar_helper(s->chan, "FAXBITRATE", NULL); if (ast_channel_state(s->chan) != AST_STATE_UP) { /* Shouldn't need this, but checking to see if channel is already answered * Theoretically asterisk should already have answered before running the app */ res = ast_answer(s->chan); if (res) { ast_log(LOG_WARNING, "Could not answer channel '%s'\n", ast_channel_name(s->chan)); return res; } } s->t38state = ast_channel_get_t38_state(s->chan); if (s->t38state != T38_STATE_NEGOTIATED) { /* T38 is not negotiated on the channel yet. First start regular transmission. If it switches to T38, follow */ pbx_builtin_setvar_helper(s->chan, "FAXMODE", "audio"); res = transmit_audio(s); if (res > 0) { /* transmit_audio reports switchover to T38. Update t38state */ s->t38state = ast_channel_get_t38_state(s->chan); if (s->t38state != T38_STATE_NEGOTIATED) { ast_log(LOG_ERROR, "Audio loop reports T38 switchover but t38state != T38_STATE_NEGOTIATED\n"); } } } if (s->t38state == T38_STATE_NEGOTIATED) { pbx_builtin_setvar_helper(s->chan, "FAXMODE", "T38"); res = transmit_t38(s); } if (res) { ast_log(LOG_WARNING, "Transmission error\n"); res = -1; } else if (s->finished < 0) { ast_log(LOG_WARNING, "Transmission failed\n"); } else if (s->finished > 0) { ast_debug(1, "Transmission finished Ok\n"); } return res; }
static int system_exec_helper(struct ast_channel *chan, const char *data, int failmode) { int res = 0; struct ast_str *buf = ast_str_thread_get(&buf_buf, 16); char *cbuf; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "System requires an argument(command)\n"); pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); return failmode; } ast_autoservice_start(chan); /* Do our thing here */ ast_str_get_encoded_str(&buf, 0, (char *) data); cbuf = ast_str_buffer(buf); if (strchr("\"'", cbuf[0]) && cbuf[ast_str_strlen(buf) - 1] == cbuf[0]) { cbuf[ast_str_strlen(buf) - 1] = '\0'; cbuf++; ast_log(LOG_NOTICE, "It is not necessary to quote the argument to the System application.\n"); } res = ast_safe_system(cbuf); if ((res < 0) && (errno != ECHILD)) { ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); res = failmode; } else if (res == 127) { ast_log(LOG_WARNING, "Unable to execute '%s'\n", (char *)data); pbx_builtin_setvar_helper(chan, chanvar, "FAILURE"); res = failmode; } else { if (res < 0) res = 0; if (res != 0) pbx_builtin_setvar_helper(chan, chanvar, "APPERROR"); else pbx_builtin_setvar_helper(chan, chanvar, "SUCCESS"); res = 0; } ast_autoservice_stop(chan); return res; }
static char *function_db_exists(struct cw_channel *chan, int argc, char **argv, char *buf, size_t len) { char *key; if (argc != 1 || !argv[0][0] || !(key = strchr(argv[0], '/'))) { cw_log(LOG_ERROR, "Syntax: %s\n", db_exists_func_syntax); return NULL; } if (len < 2) { cw_log(LOG_ERROR, "Out of space in return buffer\n"); return NULL; } *(key++) = '\0'; if (cw_db_get(argv[0], key, buf, len-1)) buf[0] = '0'; else { pbx_builtin_setvar_helper(chan, "DB_RESULT", buf); buf[0] = '1'; } buf[1] = '\0'; return buf; }
/*--- count_exec: The MeetmeCount application */ static int count_exec(struct ast_channel *chan, void *data) { struct localuser *u; int res = 0; struct ast_conference *conf; int count; char *confnum, *localdata; char val[80] = "0"; if (!data || ast_strlen_zero(data)) { ast_log(LOG_WARNING, "MeetMeCount requires an argument (conference number)\n"); return -1; } localdata = ast_strdupa(data); LOCAL_USER_ADD(u); confnum = strsep(&localdata,"|"); conf = find_conf(chan, confnum, 0, 0, NULL); if (conf) count = conf->users; else count = 0; if (localdata && !ast_strlen_zero(localdata)){ /* have var so load it and exit */ snprintf(val,sizeof(val), "%i",count); pbx_builtin_setvar_helper(chan, localdata,val); } else { if (chan->_state != AST_STATE_UP) ast_answer(chan); res = ast_say_number(chan, count, "", chan->language, (char *) NULL); /* Needs gender */ } LOCAL_USER_REMOVE(u); return res; }
/*! * \internal * \brief Setup the caller features for when that channel is dialed. * \since 12.0.0 * * \param chan Parked channel leaving the parking lot. * \param cfg Parking lot configuration. * * \return Nothing */ static void parking_timeout_set_caller_features(struct ast_channel *chan, struct parking_lot_cfg *cfg) { char features[5]; char *pos; /* * We are setting the callee Dial flag values because in the * timeout case, the caller is who is being called back. */ pos = features; if (cfg->parkedcalltransfers & AST_FEATURE_FLAG_BYCALLER) { *pos++ = 't'; } if (cfg->parkedcallreparking & AST_FEATURE_FLAG_BYCALLER) { *pos++ = 'k'; } if (cfg->parkedcallhangup & AST_FEATURE_FLAG_BYCALLER) { *pos++ = 'h'; } if (cfg->parkedcallrecording & AST_FEATURE_FLAG_BYCALLER) { *pos++ = 'x'; } *pos = '\0'; pbx_builtin_setvar_helper(chan, "BRIDGE_FEATURES", features); }
/*! * \internal * \brief Used to determine what action to take when DTMF is received while recording * \since 13.0.0 * * \param chan channel being recorded * \param flags option flags in use by the record application * \param dtmf_integer the integer value of the DTMF key received * \param terminator key currently set to be pressed for normal termination * * \retval 0 do not exit * \retval -1 do exit */ static int record_dtmf_response(struct ast_channel *chan, struct ast_flags *flags, int dtmf_integer, int terminator) { if ((dtmf_integer == OPERATOR_KEY) && (ast_test_flag(flags, OPTION_OPERATOR_EXIT))) { pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "OPERATOR"); return -1; } if ((dtmf_integer == terminator) || (ast_test_flag(flags, OPTION_ANY_TERMINATE))) { pbx_builtin_setvar_helper(chan, "RECORD_STATUS", "DTMF"); return -1; } return 0; }
/*! * \brief [lua_CFunction] Used to set the value of a variable or dialplan * function (for access from lua, don't call directly) * * This function is the 'set()' function in the following example as would be * seen in extensions.lua. * * \code * channel.variable:set("value") * \endcode */ static int lua_set_variable_value(lua_State *L) { const char *name, *value; struct ast_channel *chan; int autoservice; if (!lua_istable(L, 1)) { lua_pushstring(L, "User probably used '.' instead of ':' for setting a channel variable"); return lua_error(L); } lua_getfield(L, 1, "name"); name = ast_strdupa(lua_tostring(L, -1)); lua_pop(L, 1); value = luaL_checkstring(L, 2); lua_getfield(L, LUA_REGISTRYINDEX, "channel"); chan = lua_touserdata(L, -1); lua_pop(L, 1); lua_getfield(L, LUA_REGISTRYINDEX, "autoservice"); autoservice = lua_toboolean(L, -1); lua_pop(L, 1); if (autoservice) ast_autoservice_stop(chan); pbx_builtin_setvar_helper(chan, name, value); if (autoservice) ast_autoservice_start(chan); return 0; }
static int eval_exec(struct cw_channel *chan, int argc, char **argv) { static int dep_warning = 0; char tmp[MAXRESULT]; struct localuser *u; char *newvar = NULL; int res = 0; if (!dep_warning) { cw_log(LOG_WARNING, "This application has been deprecated in favor of the dialplan function, EVAL\n"); dep_warning = 1; } LOCAL_USER_ADD(u); /* Check and parse arguments */ if (argv[0]) { newvar = strsep(&argv[0], "="); if (newvar && (newvar[0] != '\0')) { pbx_substitute_variables_helper(chan, argv[0], tmp, sizeof(tmp)); pbx_builtin_setvar_helper(chan, newvar, tmp); } } LOCAL_USER_REMOVE(u); return res; }
static int eval_exec(struct ast_channel *chan, void *data) { int res=0; struct localuser *u; char *s, *newvar=NULL, tmp[MAXRESULT]; static int dep_warning = 0; LOCAL_USER_ADD(u); if (!dep_warning) { ast_log(LOG_WARNING, "This application has been deprecated in favor of the dialplan function, EVAL\n"); dep_warning = 1; } /* Check and parse arguments */ if (data) { s = ast_strdupa((char *)data); if (s) { newvar = strsep(&s, "="); if (newvar && (newvar[0] != '\0')) { memset(tmp, 0, MAXRESULT); pbx_substitute_variables_helper(chan, s, tmp, MAXRESULT - 1); pbx_builtin_setvar_helper(chan, newvar, tmp); } } else { ast_log(LOG_ERROR, "Out of memory\n"); res = -1; } } LOCAL_USER_REMOVE(u); return res; }
static enum ast_test_result_state test_chan_variable(struct ast_test *test, struct ast_channel *c, const char *varname) { const char *values[] = { "one", "three", "reallylongdinosaursoundingthingwithwordsinit" }; int i, okay = 1; char workspace[4096]; struct ast_str *str = ast_str_create(16); struct ast_str *var = ast_str_create(16); ast_str_set(&var, 0, "${%s}", varname); for (i = 0; i < ARRAY_LEN(values); i++) { pbx_builtin_setvar_helper(c, varname, values[i]); ast_str_substitute_variables(&str, 0, c, ast_str_buffer(var)); pbx_substitute_variables_helper(c, ast_str_buffer(var), workspace, sizeof(workspace)); ast_test_status_update(test, "Testing '%s' . . . . . %s\n", ast_str_buffer(var), okay ? "passed" : "FAILED"); if (strcmp(values[i], ast_str_buffer(str)) != 0 || strcmp(values[i], workspace) != 0) { ast_test_status_update(test, "%s != %s != %s\n", values[i], ast_str_buffer(str), workspace); okay = 0; } } ast_free(str); ast_free(var); return okay ? AST_TEST_PASS : AST_TEST_FAIL; }
/*! * \brief [lua_CFunction] Set the value of a channel variable or dialplan * function (for access from lua, don't call directly) * * This function is called to set a variable or dialplan function. It would be * called in the following example as would be seen in extensions.lua. * * \code * channel.variable = "value" * \endcode */ static int lua_set_variable(lua_State *L) { struct ast_channel *chan; int autoservice; const char *name = luaL_checkstring(L, 2); const char *value = luaL_checkstring(L, 3); lua_getfield(L, LUA_REGISTRYINDEX, "channel"); chan = lua_touserdata(L, -1); lua_pop(L, 1); lua_getfield(L, LUA_REGISTRYINDEX, "autoservice"); autoservice = lua_toboolean(L, -1); lua_pop(L, 1); if (autoservice) ast_autoservice_stop(chan); pbx_builtin_setvar_helper(chan, name, value); if (autoservice) ast_autoservice_start(chan); return 0; }
static int lookupblacklist_exec (struct ast_channel *chan, void *data) { char blacklist[1]; struct ast_module_user *u; int bl = 0; int priority_jump = 0; static int dep_warning = 0; u = ast_module_user_add(chan); if (!dep_warning) { dep_warning = 1; ast_log(LOG_WARNING, "LookupBlacklist is deprecated. Please use ${BLACKLIST()} instead.\n"); } if (!ast_strlen_zero(data)) { if (strchr(data, 'j')) priority_jump = 1; } if (chan->cid.cid_num) { if (!ast_db_get("blacklist", chan->cid.cid_num, blacklist, sizeof (blacklist))) { if (option_verbose > 2) ast_log(LOG_NOTICE, "Blacklisted number %s found\n",chan->cid.cid_num); bl = 1; } } if (chan->cid.cid_name) { if (!ast_db_get("blacklist", chan->cid.cid_name, blacklist, sizeof (blacklist))) { if (option_verbose > 2) ast_log (LOG_NOTICE,"Blacklisted name \"%s\" found\n",chan->cid.cid_name); bl = 1; } } if (bl) { if (priority_jump || ast_opt_priority_jumping) ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101); pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "FOUND"); } else pbx_builtin_setvar_helper(chan, "LOOKUPBLSTATUS", "NOTFOUND"); ast_module_user_remove(u); return 0; }
static int aPGSQL_query(struct cw_channel *chan, void *data) { char *s1,*s2,*s3,*s4; char s[100] = ""; char *querystring; char *var; int l; int res,nres; PGconn *karoto; PGresult *PGSQLres; int id,id1; char *stringp=NULL; res=0; l=strlen(data)+2; s1=malloc(l); s2=malloc(l); strncpy(s1, data, l - 1); stringp=s1; strsep(&stringp," "); /* eat the first token, we already know it :P */ s3=strsep(&stringp," "); while (1) { /* ugly trick to make branches with break; */ var=s3; s4=strsep(&stringp," "); id=atoi(s4); querystring=strsep(&stringp,"\n"); if ((karoto=find_identifier(id,CW_PGSQL_ID_CONNID))==NULL) { cw_log(LOG_WARNING,"Invalid connection identifier %d passed in aPGSQL_query\n",id); res=-1; break; } PGSQLres=PQexec(karoto,querystring); if (PGSQLres==NULL) { cw_log(LOG_WARNING,"aPGSQL_query: Connection Error (connection identifier = %d, error message : %s)\n",id,PQerrorMessage(karoto)); res=-1; break; } if (PQresultStatus(PGSQLres) == PGRES_BAD_RESPONSE || PQresultStatus(PGSQLres) == PGRES_NONFATAL_ERROR || PQresultStatus(PGSQLres) == PGRES_FATAL_ERROR) { cw_log(LOG_WARNING,"aPGSQL_query: Query Error (connection identifier : %d, error message : %s)\n",id,PQcmdStatus(PGSQLres)); res=-1; break; } nres=PQnfields(PGSQLres); id1=add_identifier(CW_PGSQL_ID_RESID,PGSQLres); snprintf(s, sizeof(s), "%d", id1); pbx_builtin_setvar_helper(chan,var,s); break; } free(s1); free(s2); return(res); }
static int app_control_set_channel_var(struct stasis_app_control *control, struct ast_channel *chan, void *data) { struct chanvar *var = data; pbx_builtin_setvar_helper(control->channel, var->name, var->value); return 0; }
static int app_callback(void *pArg, int argc, char **argv, char **columnNames){ int x=0; struct ast_channel *chan = pArg; if (chan) { for(x=0;x<argc;x++) pbx_builtin_setvar_helper(chan,columnNames[x],argv[x]); } return 0; }
static int controlplayback_exec(struct cw_channel *chan, int argc, char **argv) { int res = 0; int skipms = 0; struct localuser *u; int i; if (argc < 1 || argc > 7) { cw_log(LOG_ERROR, "Syntax: %s\n", controlplayback_syntax); pbx_builtin_setvar_helper(chan, controlplayback_chanvar, "ERROR"); return 0; } LOCAL_USER_ADD(u); skipms = (argc > 1 && argv[1] ? atoi(argv[1]) : 3000); if (!skipms) skipms = 3000; for (i = 2; i < 6; i++) { if (i >= argc || !argv[i] || !is_on_phonepad(argv[i][0])) argv[i] = NULL; } if (!argv[2]) argv[2] = "#"; if (!argv[3]) argv[2] = "*"; res = cw_control_streamfile(chan, argv[0], argv[2], argv[3], argv[4], argv[5], argv[6], skipms); /* If we stopped on one of our stop keys, return 0 */ if (argv[4] && strchr(argv[4], res)) res = 0; if (res < 0) { pbx_builtin_setvar_helper(chan, controlplayback_chanvar, "ERROR"); return 0; } pbx_builtin_setvar_helper(chan, controlplayback_chanvar, "OK"); LOCAL_USER_REMOVE(u); return 0; }
static int pickdown_channel(struct ast_channel *chan, void *pattern) { int ret = 0; struct ast_module_user *u; struct ast_channel *cur; u = ast_module_user_add(chan); cur = find_matching_channel(chan, pattern, AST_STATE_RINGING); if (cur) { ast_verbose(VERBOSE_PREFIX_3 "Channel %s hung up ringing channel %s\n", chan->name, cur->name); pbx_builtin_setvar_helper(chan, "PICKDOWN_CHANNEL", cur->name); ast_softhangup_nolock(cur, AST_SOFTHANGUP_DEV); ast_mutex_unlock(&cur->lock); } else { pbx_builtin_setvar_helper(chan, "PICKDOWN_CHANNEL", ""); } ast_module_user_remove(u); return(ret); }
static int manager_park(struct mansession *s, const struct message *m) { const char *channel = astman_get_header(m, "Channel"); const char *timeout_channel = S_OR(astman_get_header(m, "TimeoutChannel"), astman_get_header(m, "Channel2")); const char *timeout = astman_get_header(m, "Timeout"); const char *parkinglot = astman_get_header(m, "Parkinglot"); char buf[BUFSIZ]; int timeout_override = -1; RAII_VAR(struct ast_channel *, chan, NULL, ao2_cleanup); RAII_VAR(struct ast_bridge *, parking_bridge, NULL, ao2_cleanup); if (ast_strlen_zero(channel)) { astman_send_error(s, m, "Channel not specified"); return 0; } if (!ast_strlen_zero(timeout)) { if (sscanf(timeout, "%30d", &timeout_override) != 1 || timeout < 0) { astman_send_error(s, m, "Invalid Timeout value."); return 0; } if (timeout_override > 0) { /* If greater than zero, convert to seconds for internal use. Must be >= 1 second. */ timeout_override = MAX(1, timeout_override / 1000); } } if (!(chan = ast_channel_get_by_name(channel))) { snprintf(buf, sizeof(buf), "Channel does not exist: %s", channel); astman_send_error(s, m, buf); return 0; } ast_channel_lock(chan); if (!ast_strlen_zero(timeout_channel)) { pbx_builtin_setvar_helper(chan, "BLINDTRANSFER", timeout_channel); } ast_channel_unlock(chan); if (!(parking_bridge = park_common_setup(chan, chan, parkinglot, NULL, 0, 0, timeout_override, 0))) { astman_send_error(s, m, "Park action failed\n"); return 0; } if (ast_bridge_add_channel(parking_bridge, chan, NULL, 0, NULL)) { astman_send_error(s, m, "Park action failed\n"); return 0; } astman_send_ack(s, m, "Park successful\n"); return 0; }
static int set_callweaver_int(struct cw_channel *chan, char *varname, int id) { if( id>=0 ) { char s[100] = ""; snprintf(s, sizeof(s)-1, "%d", id); #if EXTRA_LOG cw_log(LOG_WARNING,"MYSQL: setting var '%s' to value '%s'\n",varname,s); #endif pbx_builtin_setvar_helper(chan,varname,s); } return id; }
static int sendimage_exec(struct ast_channel *chan, void *data) { int res = 0; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "SendImage requires an argument (filename)\n"); return -1; } if (!ast_supports_images(chan)) { /* Does not support transport */ pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "NOSUPPORT"); return 0; } if (!(res = ast_send_image(chan, data))) pbx_builtin_setvar_helper(chan, "SENDIMAGESTATUS", "OK"); return res; }
static void phase_e_handler(t30_state_t *s, void *user_data, int result) { struct ast_channel *chan; char far_ident[21]; chan = (struct ast_channel *) user_data; if (result == T30_ERR_OK) { t30_get_far_ident(s, far_ident); pbx_builtin_setvar_helper(chan, "REMOTESTATIONID", far_ident); pbx_builtin_setvar_helper(chan, "TXFAXRESULT", "SUCCESS"); } else { ast_log(LOG_DEBUG, "==============================================================================\n"); ast_log(LOG_DEBUG, "Fax send not successful - result (%d) %s.\n", result, t30_completion_code_to_str(result)); ast_log(LOG_DEBUG, "==============================================================================\n"); pbx_builtin_setvar_helper(chan, "TXFAXRESULT", "ERROR"); } }