/*****************************************************************************/
static char devices_sql[] =
"CREATE TABLE skinny_devices (\n"
- " name VARCHAR(16),\n"
+ " name VARCHAR(16),\n"
" user_id INTEGER,\n"
" instance INTEGER,\n"
- " ip VARCHAR(255),\n"
+ " ip VARCHAR(15),\n"
" type INTEGER,\n"
" max_streams INTEGER,\n"
" port INTEGER,\n"
" codec_string VARCHAR(255)\n"
");\n";
+static char lines_sql[] =
+ "CREATE TABLE skinny_lines (\n"
+ " device_name VARCHAR(16),\n"
+ " device_instance INTEGER,\n"
+ " position INTEGER,\n"
+ " label VARCHAR(40),\n"
+ " value VARCHAR(24),\n"
+ " caller_name VARCHAR(44),\n"
+ " ring_on_idle INTEGER,\n"
+ " ring_on_active INTEGER,\n"
+ " busy_trigger INTEGER,\n"
+ " forward_all VARCHAR(255),\n"
+ " forward_busy VARCHAR(255),\n"
+ " forward_noanswer VARCHAR(255),\n"
+ " noanswer_duration INTEGER\n"
+ ");\n";
+
static char buttons_sql[] =
"CREATE TABLE skinny_buttons (\n"
" device_name VARCHAR(16),\n"
+ " device_instance INTEGER,\n"
" position INTEGER,\n"
" type INTEGER,\n"
" label VARCHAR(40),\n"
- " value VARCHAR(24),\n"
+ " value VARCHAR(255),\n"
" settings VARCHAR(44)\n"
");\n";
helper.profile = profile;
if ((sql = switch_mprintf("SELECT device_name, position, "
- "(SELECT count(*) from skinny_buttons sb2 "
- "WHERE sb2.device_name= sb1.device_name AND sb2.type='line' AND sb2.position <= sb1.position) AS relative_position "
- "FROM skinny_buttons sb1 WHERE type='line' and value='%s'",
+ "(SELECT count(*) from skinny_lines sl2 "
+ "WHERE sl2.device_name= sl1.device_name AND sl2.device_instance= sl1.device_instance AND sl2.position <= sl1.position) AS relative_position "
+ "FROM skinny_lines sl1 WHERE value='%s'",
dest))) {
skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_profile_find_listener_callback, &helper);
switch_safe_free(sql);
if ((sql = switch_mprintf(
"DELETE FROM skinny_devices "
- "WHERE name='%s'",
- listener->device_name))) {
+ "WHERE name='%s' and instance=%d",
+ listener->device_name, listener->device_instance))) {
+ skinny_execute_sql(profile, sql, profile->listener_mutex);
+ switch_safe_free(sql);
+ }
+
+ if ((sql = switch_mprintf(
+ "DELETE FROM skinny_lines "
+ "WHERE device_name='%s' and device_instance=%d",
+ listener->device_name, listener->device_instance))) {
skinny_execute_sql(profile, sql, profile->listener_mutex);
switch_safe_free(sql);
}
if ((sql = switch_mprintf(
"DELETE FROM skinny_buttons "
- "WHERE device_name='%s'",
- listener->device_name))) {
+ "WHERE device_name='%s' and device_instance=%d",
+ listener->device_name, listener->device_instance))) {
skinny_execute_sql(profile, sql, profile->listener_mutex);
switch_safe_free(sql);
}
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_INFO, "Connected ODBC DSN: %s\n", profile->odbc_dsn);
switch_odbc_handle_exec(profile->master_odbc, devices_sql, NULL, NULL);
+ switch_odbc_handle_exec(profile->master_odbc, lines_sql, NULL, NULL);
switch_odbc_handle_exec(profile->master_odbc, buttons_sql, NULL, NULL);
} else {
if ((db = switch_core_db_open_file(profile->dbname))) {
switch_core_db_test_reactive(db, "SELECT * FROM skinny_devices", NULL, devices_sql);
+ switch_core_db_test_reactive(db, "SELECT * FROM skinny_lines", NULL, lines_sql);
switch_core_db_test_reactive(db, "SELECT * FROM skinny_buttons", NULL, buttons_sql);
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Cannot Open SQL Database!\n");
}
skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_devices", NULL, NULL);
+ skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_lines", NULL, NULL);
skinny_execute_sql_callback(profile, profile->listener_mutex, "DELETE FROM skinny_buttons", NULL, NULL);
switch_core_hash_insert(globals.profile_hash, profile->name, profile);
SKINNY_DECLARE_STR2ID(skinny_str2ring_mode, SKINNY_RING_MODES, -1)
struct skinny_table SKINNY_BUTTONS[] = {
+ {"Unknown", SKINNY_BUTTON_UNKNOWN},
{"LastNumberRedial", SKINNY_BUTTON_LAST_NUMBER_REDIAL},
{"SpeedDial", SKINNY_BUTTON_SPEED_DIAL},
{"Line", SKINNY_BUTTON_LINE},
switch_event_create_subclass(&event, event_id, subclass_name);
switch_assert(event);
- if ((sql = switch_mprintf("SELECT * FROM skinny_devices WHERE name='%s'", listener->device_name))) {
+ if ((sql = switch_mprintf("SELECT * FROM skinny_devices WHERE name='%s' AND instance=%d", listener->device_name, listener->device_instance))) {
skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_device_event_callback, event);
switch_safe_free(sql);
}
channel = switch_core_session_get_channel(session);
- snprintf(name, sizeof(name), "SKINNY/%s/%s/%d", listener->profile->name, listener->device_name, tech_pvt->line);
+ snprintf(name, sizeof(name), "SKINNY/%s/%s:%d/%d", listener->profile->name, listener->device_name, listener->device_instance, tech_pvt->line);
switch_channel_set_name(channel, name);
if (switch_core_session_thread_launch(session) != SWITCH_STATUS_SUCCESS) {
helper->button->number = helper->pos;
strncpy(helper->button->name, argv[2], 24); /* label */
strncpy(helper->button->shortname, argv[3], 40); /* value */
- strncpy(helper->button->displayname, argv[4], 44); /* settings */
+ strncpy(helper->button->displayname, argv[4], 44); /* caller_name */
}
return 0;
}
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, settings "
- "FROM skinny_buttons "
- "WHERE device_name='%s' AND type=%d "
+ "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,
- SKINNY_BUTTON_LINE
+ listener->device_name, listener->device_instance
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_line_get_callback, &helper);
switch_safe_free(sql);
if ((sql = switch_mprintf(
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
- "WHERE device_name='%s' AND type=%d "
+ "WHERE device_name='%s' AND device_instance=%d AND type=%d "
"ORDER BY position",
instance,
- listener->device_name,
+ listener->device_name, listener->device_instance,
SKINNY_BUTTON_SPEED_DIAL
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_speed_dial_get_callback, &helper);
if ((sql = switch_mprintf(
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
- "WHERE device_name='%s' AND type=%d "
+ "WHERE device_name='%s' AND device_instance=%d AND type=%d "
"ORDER BY position",
instance,
listener->device_name,
+ listener->device_instance,
SKINNY_BUTTON_SERVICE_URL
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_service_url_get_callback, &helper);
if ((sql = switch_mprintf(
"SELECT '%d' AS wanted_position, position, label, value, settings "
"FROM skinny_buttons "
- "WHERE device_name='%s' AND NOT (type=%d OR type=%d OR type=%d) "
+ "WHERE device_name='%s' AND device_instance=%d AND NOT (type=%d OR type=%d) "
"ORDER BY position",
instance,
listener->device_name,
- SKINNY_BUTTON_LINE, SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
+ listener->device_instance,
+ SKINNY_BUTTON_SPEED_DIAL, SKINNY_BUTTON_SERVICE_URL
))) {
skinny_execute_sql_callback(listener->profile, listener->profile->listener_mutex, sql, skinny_feature_get_callback, &helper);
switch_safe_free(sql);
strcpy(listener->device_name, request->data.reg.device_name);
+ listener->device_instance = request->data.reg.instance;
xskinny = switch_xml_child(xuser, "skinny");
if (xskinny) {
uint32_t type = skinny_str2button(switch_xml_attr_soft(xbutton, "type"));
const char *label = switch_xml_attr_soft(xbutton, "label");
const char *value = switch_xml_attr_soft(xbutton, "value");
- const char *settings = switch_xml_attr_soft(xbutton, "settings");
- if ((sql = switch_mprintf(
- "INSERT INTO skinny_buttons "
- "(device_name, position, type, label, value, settings) "
- "VALUES('%s', %d, %d, '%s', '%s', '%s')",
- request->data.reg.device_name,
- position,
- type,
- label,
- value,
- settings))) {
- skinny_execute_sql(profile, sql, profile->listener_mutex);
- switch_safe_free(sql);
+ if(type == SKINNY_BUTTON_LINE) {
+ const char *caller_name = switch_xml_attr_soft(xbutton, "caller-name");
+ uint32_t ring_on_idle = atoi(switch_xml_attr_soft(xbutton, "ring-on-idle"));
+ uint32_t ring_on_active = atoi(switch_xml_attr_soft(xbutton, "ring-on-active"));
+ uint32_t busy_trigger = atoi(switch_xml_attr_soft(xbutton, "busy-trigger"));
+ const char *forward_all = switch_xml_attr_soft(xbutton, "forward-all");
+ const char *forward_busy = switch_xml_attr_soft(xbutton, "forward-busy");
+ const char *forward_noanswer = switch_xml_attr_soft(xbutton, "forward-noanswer");
+ uint32_t noanswer_duration = atoi(switch_xml_attr_soft(xbutton, "noanswer-duration"));
+ if ((sql = switch_mprintf(
+ "INSERT INTO skinny_lines "
+ "(device_name, device_instance, position, "
+ "label, value, caller_name, "
+ "ring_on_idle, ring_on_active, busy_trigger, "
+ "forward_all, forward_busy, forward_noanswer, noanswer_duration) "
+ "VALUES('%s', %d, %d, '%s', '%s', '%s', %d, %d, %d, '%s', '%s', '%s', %d)",
+ request->data.reg.device_name, request->data.reg.instance, position,
+ label, value, caller_name,
+ ring_on_idle, ring_on_active, busy_trigger,
+ forward_all, forward_busy, forward_noanswer, noanswer_duration))) {
+ skinny_execute_sql(profile, sql, profile->listener_mutex);
+ switch_safe_free(sql);
+ }
+ } else {
+ const char *settings = switch_xml_attr_soft(xbutton, "settings");
+ if ((sql = switch_mprintf(
+ "INSERT INTO skinny_buttons "
+ "(device_name, device_instance, position, type, label, value, settings) "
+ "VALUES('%s', %d, %d, %d, '%s', '%s', '%s')",
+ request->data.reg.device_name,
+ request->data.reg.instance,
+ position,
+ type,
+ label,
+ value,
+ settings))) {
+ skinny_execute_sql(profile, sql, profile->listener_mutex);
+ switch_safe_free(sql);
+ }
}
}
}
if ((sql = switch_mprintf(
"SELECT name, user_id, instance, '' AS user_name, '' AS server_name, "
- "(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type=%d) AS number_lines, "
- "(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND type=%d) AS number_speed_dials "
+ "(SELECT COUNT(*) FROM skinny_lines WHERE device_name='%s' AND device_instance=%d) AS number_lines, "
+ "(SELECT COUNT(*) FROM skinny_buttons WHERE device_name='%s' AND device_instance=%d AND type=%d) AS number_speed_dials "
"FROM skinny_devices WHERE name='%s' ",
listener->device_name,
- SKINNY_BUTTON_LINE,
+ listener->device_instance,
listener->device_name,
+ listener->device_instance,
SKINNY_BUTTON_SPEED_DIAL,
listener->device_name
))) {
skinny_check_data_length(request, sizeof(request->data.as_uint16));
if ((sql = switch_mprintf(
- "UPDATE skinny_devices SET port='%d' WHERE name='%s'",
+ "UPDATE skinny_devices SET port=%d WHERE name='%s' and instance=%d",
request->data.as_uint16,
- listener->device_name
+ listener->device_name,
+ listener->device_instance
))) {
skinny_execute_sql(profile, sql, profile->listener_mutex);
switch_safe_free(sql);
struct button_template_helper {
skinny_message_t *message;
int count[SKINNY_BUTTON_UNDEFINED+1];
+ int max_position;
};
int skinny_handle_button_template_request_callback(void *pArg, int argc, char **argv, char **columnNames)
struct button_template_helper *helper = pArg;
skinny_message_t *message = helper->message;
/* char *device_name = argv[0]; */
- int position = atoi(argv[1]);
- uint32_t type = atoi(argv[2]);
- int i;
-
- if(type > SKINNY_BUTTON_UNDEFINED) {
- type = SKINNY_BUTTON_UNDEFINED;
- }
- /* fill buttons between previous one and current one */
- for(i = message->data.button_template.button_count; i+1 < position; i++) {
- message->data.button_template.btn[i].instance_number = ++helper->count[SKINNY_BUTTON_UNDEFINED];
- message->data.button_template.btn[i].button_definition = SKINNY_BUTTON_UNDEFINED;
- message->data.button_template.button_count++;
- message->data.button_template.total_button_count++;
- }
+ /* uint32_t device_instance = argv[1]; */
+ int position = atoi(argv[2]);
+ uint32_t type = atoi(argv[3]);
+ /* int relative_position = atoi(argv[4]); */
- message->data.button_template.btn[i].instance_number = ++helper->count[type];
+ message->data.button_template.btn[position-1].instance_number = ++helper->count[type];
message->data.button_template.btn[position-1].button_definition = type;
message->data.button_template.button_count++;
message->data.button_template.total_button_count++;
+ if(position > helper->max_position) {
+ helper->max_position = position;
+ }
return 0;
}
message->data.button_template.total_button_count = 0;
helper.message = message;
+
/* Add buttons */
if ((sql = switch_mprintf(
- "SELECT device_name, position, type "
- "FROM skinny_buttons WHERE device_name='%s' ORDER BY position",
- listener->device_name
+ "SELECT device_name, device_instance, position, MIN(type, %d) AS type "
+ "FROM skinny_buttons "
+ "WHERE device_name='%s' AND device_instance=%d "
+ "ORDER BY position",
+ SKINNY_BUTTON_UNDEFINED,
+ listener->device_name, listener->device_instance
))) {
skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_handle_button_template_request_callback, &helper);
switch_safe_free(sql);
}
+ /* Add lines */
+ if ((sql = switch_mprintf(
+ "SELECT device_name, device_instance, position, %d AS type "
+ "FROM skinny_lines "
+ "WHERE device_name='%s' AND device_instance=%d "
+ "ORDER BY position",
+ SKINNY_BUTTON_LINE,
+ listener->device_name, listener->device_instance
+ ))) {
+ skinny_execute_sql_callback(profile, profile->listener_mutex, sql, skinny_handle_button_template_request_callback, &helper);
+ switch_safe_free(sql);
+ }
+
+ /* Fill remaining buttons with Undefined */
+ for(int i = 0; i+1 < helper.max_position; i++) {
+ if(message->data.button_template.btn[i].button_definition == SKINNY_BUTTON_UNKNOWN) {
+ message->data.button_template.btn[i].instance_number = ++helper.count[SKINNY_BUTTON_UNDEFINED];
+ message->data.button_template.btn[i].button_definition = SKINNY_BUTTON_UNDEFINED;
+ message->data.button_template.button_count++;
+ message->data.button_template.total_button_count++;
+ }
+ }
+
skinny_send_reply(listener, message);
return SWITCH_STATUS_SUCCESS;