void ast_ari_device_states_get(struct ast_variable *headers, struct ast_ari_device_states_get_args *args, struct ast_ari_response *response) { struct ast_json *json; if (!(json = stasis_app_device_state_to_json( args->device_name, ast_device_state(args->device_name)))) { ast_ari_response_error(response, 500, "Internal Server Error", "Error building response"); return; } ast_ari_response_ok(response, json); }
static int devstate_read(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t len) { ast_copy_string(buf, ast_devstate_str(ast_device_state(data)), len); return 0; }
static int chanavail_exec(struct ast_channel *chan, void *data) { int res=-1, inuse=-1, option_state=0, priority_jump=0; int status; struct localuser *u; char *info, tmp[512], trychan[512], *peers, *tech, *number, *rest, *cur, *options, *stringp; struct ast_channel *tempchan; if (ast_strlen_zero(data)) { ast_log(LOG_WARNING, "ChanIsAvail requires an argument (Zap/1&Zap/2)\n"); return -1; } LOCAL_USER_ADD(u); info = ast_strdupa(data); stringp = info; strsep(&stringp, "|"); options = strsep(&stringp, "|"); if (options) { if (strchr(options, 's')) option_state = 1; if (strchr(options, 'j')) priority_jump = 1; } peers = info; if (peers) { cur = peers; do { /* remember where to start next time */ rest = strchr(cur, '&'); if (rest) { *rest = 0; rest++; } tech = cur; number = strchr(tech, '/'); if (!number) { ast_log(LOG_WARNING, "ChanIsAvail argument takes format ([technology]/[device])\n"); LOCAL_USER_REMOVE(u); return -1; } *number = '\0'; number++; if (option_state) { /* If the pbx says in use then don't bother trying further. This is to permit testing if someone's on a call, even if the channel can permit more calls (ie callwaiting, sip calls, etc). */ snprintf(trychan, sizeof(trychan), "%s/%s",cur,number); status = inuse = ast_device_state(trychan); } if ((inuse <= 1) && (tempchan = ast_request(tech, chan->nativeformats, number, &status))) { pbx_builtin_setvar_helper(chan, "AVAILCHAN", tempchan->name); /* Store the originally used channel too */ snprintf(tmp, sizeof(tmp), "%s/%s", tech, number); pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", tmp); snprintf(tmp, sizeof(tmp), "%d", status); pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); ast_hangup(tempchan); tempchan = NULL; res = 1; break; } else { snprintf(tmp, sizeof(tmp), "%d", status); pbx_builtin_setvar_helper(chan, "AVAILSTATUS", tmp); } cur = rest; } while (cur); } if (res < 1) { pbx_builtin_setvar_helper(chan, "AVAILCHAN", ""); pbx_builtin_setvar_helper(chan, "AVAILORIGCHAN", ""); if (priority_jump || option_priority_jumping) { if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) { LOCAL_USER_REMOVE(u); return -1; } } } LOCAL_USER_REMOVE(u); return 0; }