Skinny: centralized registration

This commit is contained in:
Mathieu Parent 2011-02-23 00:57:19 +01:00
parent ea29a1dfcc
commit e7a8189b2b
2 changed files with 37 additions and 0 deletions

View File

@ -1243,6 +1243,21 @@ static void walk_listeners(skinny_listener_callback_func_t callback, void *pvt)
switch_mutex_unlock(globals.mutex);
}
static int flush_listener_callback(void *pArg, int argc, char **argv, char **columnNames)
{
char *profile_name = argv[0];
char *value = argv[1];
char *domain_name = argv[2];
char *device_name = argv[3];
char *device_instance = argv[4];
char *token = switch_mprintf("skinny/%q/%q/%q:%q", profile_name, value, device_name, device_instance);
switch_core_del_registration(value, domain_name, token);
switch_safe_free(token);
return 0;
}
static void flush_listener(listener_t *listener)
{
@ -1250,6 +1265,18 @@ static void flush_listener(listener_t *listener)
skinny_profile_t *profile = listener->profile;
char *sql;
if ((sql = switch_mprintf(
"SELECT '%q', value, '%q', '%q', '%d' "
"FROM skinny_lines "
"WHERE device_name='%s' AND device_instance=%d "
"ORDER BY position",
profile->name, profile->domain, listener->device_name, listener->device_instance,
listener->device_name, listener->device_instance
))) {
skinny_execute_sql_callback(profile, profile->sql_mutex, sql, flush_listener_callback, NULL);
switch_safe_free(sql);
}
if ((sql = switch_mprintf(
"DELETE FROM skinny_devices "
"WHERE name='%s' and instance=%d",

View File

@ -1006,6 +1006,10 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
}
if ((xbuttons = switch_xml_child(xskinny, "buttons"))) {
uint32_t line_instance = 1;
char *network_ip = inet_ntoa(request->data.reg.ip);
int network_port = 0;
char network_port_c[6];
snprintf(network_port_c, sizeof(network_port_c), "%d", network_port);
for (xbutton = switch_xml_child(xbuttons, "button"); xbutton; xbutton = xbutton->next) {
uint32_t position = atoi(switch_xml_attr_soft(xbutton, "position"));
uint32_t type = skinny_str2button(switch_xml_attr_soft(xbutton, "type"));
@ -1031,8 +1035,14 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
label, value, caller_name,
ring_on_idle, ring_on_active, busy_trigger,
forward_all, forward_busy, forward_noanswer, noanswer_duration))) {
char *token, *url;
skinny_execute_sql(profile, sql, profile->sql_mutex);
switch_safe_free(sql);
token = switch_mprintf("skinny/%q/%q/%q:%d", profile->name, value, request->data.reg.device_name, request->data.reg.instance);
url = switch_mprintf("skinny/%q/%q", profile->name, value);
switch_core_add_registration(value, profile->domain, token, url, 0, network_ip, network_port_c, "tcp");
switch_safe_free(token);
switch_safe_free(url);
}
if (line_instance == 1) {
switch_event_t *message_query_event = NULL;