void skinny_feature_get(listener_t *listener, uint32_t instance, struct feature_stat_res_message **button) { struct feature_get_helper helper = {0}; char *sql; switch_assert(listener); switch_assert(listener->profile); switch_assert(listener->device_name); helper.button = switch_core_alloc(listener->pool, sizeof(struct feature_stat_res_message)); if ((sql = switch_mprintf( "SELECT '%d' AS wanted_position, position, label, value, settings " "FROM skinny_buttons " "WHERE device_name='%s' AND device_instance=%d AND NOT (type=%d OR type=%d) " "ORDER BY position", instance, listener->device_name, listener->device_instance, SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL ))) { skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_feature_get_callback, &helper); switch_safe_free(sql); } *button = helper.button; }
static switch_status_t skinny_device_status_show(switch_stream_handle_t *stream, const char *profile_name) { struct device_show_helper h = { 0 }; char *sql; const int ind = 4; // temporary - suppose to be changed - number of values from DB int i; skinny_profile_t *profile = NULL; switch_console_callback_device_node_t *it; listener_t *listener = NULL; char *fmt[] = {"|%-30s", "|%-14s", "|%-5s", "|%-16s", "|%-5s|\n"}; profile = skinny_find_profile(profile_name); if(profile) { if((sql = switch_mprintf("SELECT skinny_lines.caller_name, skinny_devices.ip, " "skinny_devices.port, skinny_devices.name from skinny_lines " "LEFT JOIN skinny_devices " "ON skinny_lines.device_name = skinny_devices.name"))) { skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_api_list_devices_show_callback, &h); switch_safe_free(sql); } } if(h.my_devices != NULL) // Print values received from sql { stream->write_function(stream, fmt[0], "Caller"); stream->write_function(stream, fmt[1], "IP"); stream->write_function(stream, fmt[2], "Port"); stream->write_function(stream, fmt[3], "MAC"); stream->write_function(stream, fmt[4], "DND"); stream->write_function(stream, "----------------------------------------------------------------------------\n"); for(it = h.my_devices->head, i = 1; it != NULL; it = it->next, i++) { stream->write_function(stream, fmt[i-1], it->val); if(i%ind == 0) { skinny_profile_find_listener_by_device_name(profile, (const char*)(it->val), &listener); if(listener) stream->write_function(stream, fmt[i++], listener->dnd?"Y":"N"); else stream->write_function(stream, "|listener not found|\n"); i = 0; } } } else { stream->write_function(stream, "*** No phones registered! ***\n"); } return SWITCH_STATUS_SUCCESS; }
switch_status_t skinny_session_walk_lines_by_call_id(skinny_profile_t *profile, uint32_t call_id, switch_core_db_callback_func_t callback, void *data) { char *sql; if ((sql = switch_mprintf( "SELECT skinny_lines.*, channel_uuid, call_id, call_state " "FROM skinny_active_lines " "INNER JOIN skinny_lines " "ON skinny_active_lines.device_name = skinny_lines.device_name " "AND skinny_active_lines.device_instance = skinny_lines.device_instance " "AND skinny_active_lines.line_instance = skinny_lines.line_instance " "WHERE call_id='%d'", call_id))) { skinny_execute_sql_callback(profile, profile->sql_mutex, sql, callback, data); switch_safe_free(sql); } return SWITCH_STATUS_SUCCESS; }
switch_status_t skinny_device_event(listener_t *listener, switch_event_t **ev, switch_event_types_t event_id, const char *subclass_name) { switch_event_t *event = NULL; char *sql; skinny_profile_t *profile; assert(listener->profile); profile = listener->profile; switch_event_create_subclass(&event, event_id, subclass_name); switch_assert(event); if ((sql = switch_mprintf("SELECT '%s', name, user_id, instance, ip, type, max_streams, port, codec_string " "FROM skinny_devices " "WHERE name='%s' AND instance=%d", listener->profile->name, listener->device_name, listener->device_instance))) { skinny_execute_sql_callback(profile, profile->sql_mutex, sql, skinny_device_event_callback, event); switch_safe_free(sql); } *ev = event; return SWITCH_STATUS_SUCCESS; }
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; }
void skinny_line_get(listener_t *listener, uint32_t instance, struct line_stat_res_message **button) { struct line_get_helper helper = {0}; char *sql; switch_assert(listener); switch_assert(listener->profile); switch_assert(listener->device_name); helper.button = switch_core_alloc(listener->pool, sizeof(struct line_stat_res_message)); if ((sql = switch_mprintf( "SELECT '%d' AS wanted_position, position, label, value, caller_name " "FROM skinny_lines " "WHERE device_name='%s' AND device_instance=%d " "ORDER BY position", instance, listener->device_name, listener->device_instance ))) { skinny_execute_sql_callback(listener->profile, listener->profile->sql_mutex, sql, skinny_line_get_callback, &helper); switch_safe_free(sql); } *button = helper.button; }