static switch_status_t skinny_api_list_devices(const char *line, const char *cursor, switch_console_callback_match_t **matches) { struct match_helper h = { 0 }; switch_status_t status = SWITCH_STATUS_FALSE; skinny_profile_t *profile = NULL; char *sql; char *myline; char *argv[1024] = { 0 }; int argc = 0; if (!(myline = strdup(line))) { status = SWITCH_STATUS_MEMERR; return status; } if (!(argc = switch_separate_string(myline, ' ', argv, (sizeof(argv) / sizeof(argv[0])))) || argc < 4) { return status; } if(!strcasecmp(argv[1], "profile")) {/* skinny profile <profile_name> ... */ profile = skinny_find_profile(argv[2]); } else if(!strcasecmp(argv[2], "profile")) {/* skinny status profile <profile_name> ... */ profile = skinny_find_profile(argv[3]); } if(profile) { if ((sql = switch_mprintf("SELECT name FROM skinny_devices"))) { skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_api_list_devices_callback, &h); switch_safe_free(sql); } } if (h.my_matches) { *matches = h.my_matches; status = SWITCH_STATUS_SUCCESS; } return status; }
static switch_status_t skinny_api_cmd_profile_kill_all(const char *profile_name, switch_stream_handle_t *stream) { skinny_profile_t *profile; if ((profile = skinny_find_profile(profile_name))) { profile_walk_listeners(profile, kill_listener, NULL); stream->write_function(stream, "+OK\n"); } else { stream->write_function(stream, "Profile not found!\n"); } return SWITCH_STATUS_SUCCESS; }
static switch_status_t skinny_api_cmd_profile_set(const char *profile_name, const char *name, const char *value, switch_stream_handle_t *stream) { skinny_profile_t *profile; if ((profile = skinny_find_profile(profile_name))) { if (skinny_profile_set(profile, name, value) == SWITCH_STATUS_SUCCESS) { skinny_profile_respawn(profile, 0); stream->write_function(stream, "+OK\n"); } else { stream->write_function(stream, "Unable to set skinny setting '%s'. Does it exists?\n", name); } } else { stream->write_function(stream, "Profile not found!\n"); } return SWITCH_STATUS_SUCCESS; }
static switch_status_t skinny_api_cmd_profile_device_send_reset_message(const char *profile_name, const char *device_name, const char *reset_type, switch_stream_handle_t *stream) { skinny_profile_t *profile; if ((profile = skinny_find_profile(profile_name))) { listener_t *listener = NULL; skinny_profile_find_listener_by_device_name(profile, device_name, &listener); if(listener) { send_reset(listener, skinny_str2device_reset_type(reset_type)); } else { stream->write_function(stream, "Listener not found!\n"); } } else { stream->write_function(stream, "Profile not found!\n"); } return SWITCH_STATUS_SUCCESS; }
static switch_status_t skinny_api_cmd_profile_device_send_call_state_message(const char *profile_name, const char *device_name, const char *call_state, const char *line_instance, const char *call_id, switch_stream_handle_t *stream) { skinny_profile_t *profile; if ((profile = skinny_find_profile(profile_name))) { listener_t *listener = NULL; skinny_profile_find_listener_by_device_name(profile, device_name, &listener); if(listener) { send_call_state(listener, skinny_str2call_state(call_state), atoi(line_instance), atoi(call_id)); } else { stream->write_function(stream, "Listener not found!\n"); } } else { stream->write_function(stream, "Profile not found!\n"); } return SWITCH_STATUS_SUCCESS; }
static switch_status_t skinny_api_cmd_profile_device_send_lamp_message(const char *profile_name, const char *device_name, const char *stimulus, const char *instance, const char *lamp_mode, switch_stream_handle_t *stream) { skinny_profile_t *profile; if ((profile = skinny_find_profile(profile_name))) { listener_t *listener = NULL; skinny_profile_find_listener_by_device_name(profile, device_name, &listener); if(listener) { send_set_lamp(listener, skinny_str2button(stimulus), atoi(instance), skinny_str2lamp_mode(lamp_mode)); } else { stream->write_function(stream, "Listener not found!\n"); } } else { stream->write_function(stream, "Profile not found!\n"); } return SWITCH_STATUS_SUCCESS; }
static switch_status_t skinny_api_cmd_profile_device_kill(const char *profile_name, const char *device_name, switch_stream_handle_t *stream) { skinny_profile_t *profile; if ((profile = skinny_find_profile(profile_name))) { listener_t *listener = NULL; skinny_profile_find_listener_by_device_name(profile, device_name, &listener); if(listener) { kill_listener(listener, NULL); stream->write_function(stream, "+OK\n"); } else { stream->write_function(stream, "Listener not found!\n"); } } else { stream->write_function(stream, "Profile not found!\n"); } return SWITCH_STATUS_SUCCESS; }
static switch_status_t skinny_api_set_dnd(switch_stream_handle_t *stream, const char *profile_name, const char* state, const char *device_name) { skinny_profile_t *profile = skinny_find_profile(profile_name); listener_t *listener = NULL; if(profile) { skinny_profile_find_listener_by_device_name(profile, device_name, &listener); if(listener) { if(!strcasecmp(state, "ON")) { listener->dnd = 1; send_display_prompt_status(listener, 0, "DND ON", 0, 0); } else if (!strcasecmp(state, "OFF")) { listener->dnd = 0; send_display_prompt_status(listener, 2, "DND OFF", 0, 0); } } } return SWITCH_STATUS_SUCCESS; }