add metadata col to internal registrations table

This commit is contained in:
Anthony Minessale 2012-05-30 13:05:05 -05:00
parent 82b00ecbc8
commit 192030c578
4 changed files with 46 additions and 18 deletions

View File

@ -2300,10 +2300,12 @@ SWITCH_DECLARE(uint32_t) switch_default_ptime(const char *name, uint32_t number)
\param [in] network_ip
\param [in] network_port
\param [in] network_proto - one of tls, tcp, udp
\param [in] metadata - generic metadata supplied by module
\param [out] err - Error if it exists
*/
SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires,
const char *network_ip, const char *network_port, const char *network_proto);
const char *network_ip, const char *network_port, const char *network_proto,
const char *metadata);
/*!
\brief Delete user registration
\param [in] user

View File

@ -1007,6 +1007,7 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
const char *value = switch_xml_attr_soft(xbutton, "value");
if(type == SKINNY_BUTTON_LINE) {
const char *caller_name = switch_xml_attr_soft(xbutton, "caller-name");
const char *reg_metadata = switch_xml_attr_soft(xbutton, "registration-metadata");
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"));
@ -1030,7 +1031,7 @@ switch_status_t skinny_handle_register(listener_t *listener, skinny_message_t *r
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_core_add_registration(value, profile->domain, token, url, 0, network_ip, network_port_c, "tcp", reg_metadata);
switch_safe_free(token);
switch_safe_free(url);
}

View File

@ -1028,6 +1028,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
sip_contact_t const *contact = NULL;
char *sql;
switch_event_t *s_event;
const char *reg_meta = NULL;
const char *to_user = NULL;
const char *to_host = NULL;
char *mwi_account = NULL;
@ -1485,6 +1486,10 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
to_user = var;
}
if (v_event && *v_event && (var = switch_event_get_header(*v_event, "registration_metadata"))) {
reg_meta = var;
}
if (v_event && *v_event && (mwi_account = switch_event_get_header(*v_event, "mwi-account"))) {
dup_mwi_account = strdup(mwi_account);
switch_assert(dup_mwi_account != NULL);
@ -1559,7 +1564,7 @@ uint8_t sofia_reg_handle_register(nua_t *nua, sofia_profile_t *profile, nua_hand
url = switch_mprintf("sofia/%q/sip:%q", profile->name, sofia_glue_strip_proto(contact));
switch_core_add_registration(to_user, reg_host, call_id, url, (long) switch_epoch_time_now(NULL) + (long) exptime + 60,
network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp");
network_ip, network_port_c, is_tls ? "tls" : is_tcp ? "tcp" : "udp", reg_meta);
switch_safe_free(url);
switch_safe_free(contact);

View File

@ -1713,7 +1713,8 @@ static char create_registrations_sql[] =
" network_ip VARCHAR(256),\n"
" network_port VARCHAR(256),\n"
" network_proto VARCHAR(256),\n"
" hostname VARCHAR(256)\n"
" hostname VARCHAR(256),\n"
" metadata VARCHAR(256)\n"
");\n";
@ -1843,7 +1844,8 @@ static char basic_calls_sql[] =
SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, const char *realm, const char *token, const char *url, uint32_t expires,
const char *network_ip, const char *network_port, const char *network_proto)
const char *network_ip, const char *network_port, const char *network_proto,
const char *metadata)
{
char *sql;
@ -1860,19 +1862,35 @@ SWITCH_DECLARE(switch_status_t) switch_core_add_registration(const char *user, c
}
switch_queue_push(sql_manager.sql_queue[0], sql);
sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) "
"values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')",
switch_str_nil(user),
switch_str_nil(realm),
switch_str_nil(token),
switch_str_nil(url),
expires,
switch_str_nil(network_ip),
switch_str_nil(network_port),
switch_str_nil(network_proto),
switch_core_get_switchname()
);
if ( !zstr(metadata) ) {
sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname,metadata) "
"values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q','%q')",
switch_str_nil(user),
switch_str_nil(realm),
switch_str_nil(token),
switch_str_nil(url),
expires,
switch_str_nil(network_ip),
switch_str_nil(network_port),
switch_str_nil(network_proto),
switch_core_get_switchname(),
metadata
);
} else {
sql = switch_mprintf("insert into registrations (reg_user,realm,token,url,expires,network_ip,network_port,network_proto,hostname) "
"values ('%q','%q','%q','%q',%ld,'%q','%q','%q','%q')",
switch_str_nil(user),
switch_str_nil(realm),
switch_str_nil(token),
switch_str_nil(url),
expires,
switch_str_nil(network_ip),
switch_str_nil(network_port),
switch_str_nil(network_proto),
switch_core_get_switchname()
);
}
switch_queue_push(sql_manager.sql_queue[0], sql);
@ -2007,6 +2025,8 @@ switch_status_t switch_core_sqldb_start(switch_memory_pool_t *pool, switch_bool_
switch_cache_db_test_reactive(dbh, "delete from registrations where reg_user='' or network_proto='tcp' or network_proto='tls'",
"DROP TABLE registrations", create_registrations_sql);
switch_cache_db_test_reactive(dbh, "select metadata from registrations", NULL, "ALTER TABLE registrations ADD COLUMN metadata VARCHAR(256)");
switch (dbh->type) {
case SCDB_TYPE_ODBC: