diff --git a/conf/directory.xml b/conf/directory.xml index fcab8d3592..4355fe0ccf 100644 --- a/conf/directory.xml +++ b/conf/directory.xml @@ -2,61 +2,35 @@ + + + + + + + + + + + + + + + + + + + + + - - - - Peter Saint-Andre - - Saint-Andre - Peter - - - stpeter - http://www.jabber.org/people/stpeter.php - 1966-08-06 - - Jabber Software Foundation - Jabber Software Foundation - - Executive Director - Patron Saint - 303-308-3282 - - - - - Suite 600 - 1899 Wynkoop Street - Denver - CO - 80202 - USA - - 303-555-1212 - - - - - - - Denver - CO - 80209 - USA - - stpeter@jabber.org - stpeter@jabber.org - - More information about me is located on my - personal website: http://www.saint-andre.com/ - + + - diff --git a/conf/sofia.conf.xml b/conf/sofia.conf.xml index afcfd6900c..13bd817ea3 100644 --- a/conf/sofia.conf.xml +++ b/conf/sofia.conf.xml @@ -1,6 +1,10 @@ + + + + @@ -22,6 +26,12 @@ + + + + + + diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.c b/src/mod/endpoints/mod_sofia/mod_sofia.c index dfdde83db0..e25d2b8c7c 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.c +++ b/src/mod/endpoints/mod_sofia/mod_sofia.c @@ -893,19 +893,35 @@ static switch_status_t cmd_status(char **argv, int argc, switch_stream_handle_t sofia_profile_t *profile = NULL; switch_hash_index_t *hi; void *val; + const void *vvar; int c = 0; + int ac = 0; + const char *line = "================================================================================"; + + + stream->write_function(stream, "%25s\t%s\t %32s\n", "Name", " Type", "Data"); + stream->write_function(stream, "%s\n", line); switch_mutex_lock(mod_sofia_globals.hash_mutex); for (hi = switch_hash_first(switch_hash_pool_get(mod_sofia_globals.profile_hash), mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { - switch_hash_this(hi, NULL, NULL, &val); + switch_hash_this(hi, &vvar, NULL, &val); profile = (sofia_profile_t *) val; if (sofia_test_pflag(profile, PFLAG_RUNNING)) { - stream->write_function(stream, "Profile %s\n", profile->name); - c++; + + if (strcmp(vvar, profile->name)) { + ac++; + stream->write_function(stream, "%25s\t%s\t %32s\n", vvar, " alias", profile->name); + } else { + stream->write_function(stream, "%25s\t%s\t %32s\n", profile->name, "profile", profile->url); + c++; + } + + } } switch_mutex_unlock(mod_sofia_globals.hash_mutex); - stream->write_function(stream, "%d profiles\n", c); + stream->write_function(stream, "%s\n", line); + stream->write_function(stream, "%d profiles %d aliases\n", c, ac); return SWITCH_STATUS_SUCCESS; } diff --git a/src/mod/endpoints/mod_sofia/mod_sofia.h b/src/mod/endpoints/mod_sofia/mod_sofia.h index 3bfbc3bab1..c42c5f83e4 100644 --- a/src/mod/endpoints/mod_sofia/mod_sofia.h +++ b/src/mod/endpoints/mod_sofia/mod_sofia.h @@ -437,14 +437,14 @@ void sofia_presence_handle_sip_i_subscribe(int status, nua_t *nua, sofia_profile_t *profile, nua_handle_t *nh, sofia_private_t *sofia_private, sip_t const *sip, tagi_t tags[]); sofia_profile_t *sofia_glue_find_profile(char *key); -void sofia_glue_add_profile(char *key, sofia_profile_t *profile); +switch_status_t sofia_glue_add_profile(char *key, sofia_profile_t *profile); void sofia_glue_execute_sql(sofia_profile_t *profile, switch_bool_t master, char *sql, switch_mutex_t *mutex); void sofia_reg_check_expire(sofia_profile_t *profile, time_t now); void sofia_reg_check_gateway(sofia_profile_t *profile, time_t now); void sofia_reg_unregister(sofia_profile_t *profile); switch_status_t sofia_glue_ext_address_lookup(char **ip, switch_port_t *port, char *sourceip, switch_memory_pool_t *pool); sofia_gateway_t *sofia_reg_find_gateway(char *key); -void sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway); +switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway); void sofia_glue_pass_sdp(private_object_t *tech_pvt, char *sdp); int sofia_glue_get_user_host(char *in, char **user, char **host); switch_call_cause_t sofia_glue_sip_cause_to_freeswitch(int status); @@ -467,3 +467,4 @@ switch_bool_t sofia_glue_execute_sql_callback(sofia_profile_t *profile, char *sofia_glue_execute_sql2str(sofia_profile_t *profile, switch_mutex_t *mutex, char *sql, char *resbuf, size_t len); void sofia_glue_check_video_codecs(private_object_t *tech_pvt); void sofia_reg_release_gateway(sofia_gateway_t *gateway); +void sofia_glue_del_profile(sofia_profile_t *profile); diff --git a/src/mod/endpoints/mod_sofia/sofia.c b/src/mod/endpoints/mod_sofia/sofia.c index 66472f9da4..cb5533fbd6 100644 --- a/src/mod/endpoints/mod_sofia/sofia.c +++ b/src/mod/endpoints/mod_sofia/sofia.c @@ -380,9 +380,8 @@ void *SWITCH_THREAD_FUNC sofia_profile_thread_run(switch_thread_t *thread, void su_root_destroy(profile->s_root); pool = profile->pool; - switch_mutex_lock(mod_sofia_globals.hash_mutex); - switch_core_hash_delete(mod_sofia_globals.profile_hash, profile->name); - switch_mutex_unlock(mod_sofia_globals.hash_mutex); + + sofia_glue_del_profile(profile); switch_thread_rwlock_unlock(profile->rwlock); @@ -436,14 +435,148 @@ static void logger(void *logarg, char const *fmt, va_list ap) } +static void parse_gateways(sofia_profile_t *profile, switch_xml_t gateways_tag) +{ + switch_xml_t gateway_tag, param; + sofia_gateway_t *gp; + + for (gateway_tag = switch_xml_child(gateways_tag, "gateway"); gateway_tag; gateway_tag = gateway_tag->next) { + char *name = (char *) switch_xml_attr_soft(gateway_tag, "name"); + sofia_gateway_t *gateway; + + if (switch_strlen_zero(name)) { + name = "anonymous"; + } + + if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) { + char *register_str = "true", *scheme = "Digest", + *realm = NULL, + *username = NULL, + *password = NULL, + *caller_id_in_from = "false", + *extension = NULL, + *proxy = NULL, + *context = "default", + *expire_seconds = "3600"; + + gateway->pool = profile->pool; + gateway->profile = profile; + gateway->name = switch_core_strdup(gateway->pool, name); + gateway->freq = 0; + + + for (param = switch_xml_child(gateway_tag, "param"); param; param = param->next) { + char *var = (char *) switch_xml_attr_soft(param, "name"); + char *val = (char *) switch_xml_attr_soft(param, "value"); + + if (!strcmp(var, "register")) { + register_str = val; + } else if (!strcmp(var, "scheme")) { + scheme = val; + } else if (!strcmp(var, "realm")) { + realm = val; + } else if (!strcmp(var, "username")) { + username = val; + } else if (!strcmp(var, "password")) { + password = val; + } else if (!strcmp(var, "caller-id-in-from")) { + caller_id_in_from = val; + } else if (!strcmp(var, "extension")) { + extension = val; + } else if (!strcmp(var, "proxy")) { + proxy = val; + } else if (!strcmp(var, "context")) { + context = val; + } else if (!strcmp(var, "expire-seconds")) { + expire_seconds = val; + } + } + + if (switch_strlen_zero(realm)) { + realm = name; + } + + if (switch_strlen_zero(username)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: username param is REQUIRED!\n"); + goto skip; + } + + if (switch_strlen_zero(password)) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: password param is REQUIRED!\n"); + goto skip; + } + + if (switch_strlen_zero(extension)) { + extension = username; + } + + if (switch_strlen_zero(proxy)) { + proxy = realm; + } + + if (!switch_true(register_str)) { + gateway->state = REG_STATE_NOREG; + } + gateway->register_scheme = switch_core_strdup(gateway->pool, scheme); + gateway->register_context = switch_core_strdup(gateway->pool, context); + gateway->register_realm = switch_core_strdup(gateway->pool, realm); + gateway->register_username = switch_core_strdup(gateway->pool, username); + gateway->register_password = switch_core_strdup(gateway->pool, password); + if (switch_true(caller_id_in_from)) { + switch_set_flag(gateway, REG_FLAG_CALLERID); + } + gateway->register_from = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, realm); + gateway->register_contact = switch_core_sprintf(gateway->pool, "sip:%s@%s:%d", extension, profile->sipip, profile->sip_port); + + if (!strncasecmp(proxy, "sip:", 4)) { + gateway->register_proxy = switch_core_strdup(gateway->pool, proxy); + gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4); + } else { + gateway->register_proxy = switch_core_sprintf(gateway->pool, "sip:%s", proxy); + gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy); + } + + gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds); + + if ((gateway->freq = atoi(gateway->expires_str)) < 5) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, + "Invalid Freq: %d. Setting Register-Frequency to 3600\n", gateway->freq); + gateway->freq = 3600; + } + gateway->freq -= 2; + + gateway->next = profile->gateways; + profile->gateways = gateway; + + if ((gp = sofia_reg_find_gateway(gateway->name))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", gateway->name); + sofia_reg_release_gateway(gp); + } else if ((gp=sofia_reg_find_gateway(gateway->register_from))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate uri '%s'\n", gateway->register_from); + sofia_reg_release_gateway(gp); + } else if ((gp=sofia_reg_find_gateway(gateway->register_contact))) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate contact '%s'\n", gateway->register_from); + sofia_reg_release_gateway(gp); + } else { + sofia_reg_add_gateway(gateway->name, gateway); + sofia_reg_add_gateway(gateway->register_from, gateway); + sofia_reg_add_gateway(gateway->register_contact, gateway); + } + } + + skip: + assert(gateway_tag); + } + +} + switch_status_t config_sofia(int reload, char *profile_name) { char *cf = "sofia.conf"; - switch_xml_t cfg, xml = NULL, xprofile, param, settings, profiles, gateway_tag, gateways_tag; + switch_xml_t cfg, xml = NULL, xprofile, param, settings, profiles, gateways_tag, domain_tag, domains_tag; switch_status_t status = SWITCH_STATUS_SUCCESS; sofia_profile_t *profile = NULL; char url[512] = ""; - sofia_gateway_t *gp; int profile_found = 0; if (!reload) { @@ -713,142 +846,51 @@ switch_status_t config_sofia(int reload, char *profile_name) } } if (profile) { + switch_xml_t aliases_tag, alias_tag; + if ((gateways_tag = switch_xml_child(xprofile, "registrations"))) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "The syntax has been discontinued, please see the new syntax in the default configuration examples\n"); + } else if ((gateways_tag = switch_xml_child(xprofile, "gateways"))) { + parse_gateways(profile, gateways_tag); } - if ((gateways_tag = switch_xml_child(xprofile, "gateways"))) { - for (gateway_tag = switch_xml_child(gateways_tag, "gateway"); gateway_tag; gateway_tag = gateway_tag->next) { - char *name = (char *) switch_xml_attr_soft(gateway_tag, "name"); - sofia_gateway_t *gateway; + if ((domains_tag = switch_xml_child(xprofile, "domains"))) { + for (domain_tag = switch_xml_child(domains_tag, "domain"); domain_tag; domain_tag = domain_tag->next) { + switch_xml_t droot, actual_domain_tag, ut; + char *dname = (char *) switch_xml_attr_soft(domain_tag, "name"); + char *parse = (char *) switch_xml_attr_soft(domain_tag, "parse"); - if (switch_strlen_zero(name)) { - name = "anonymous"; - } - - if ((gateway = switch_core_alloc(profile->pool, sizeof(*gateway)))) { - char *register_str = "true", *scheme = "Digest", - *realm = NULL, - *username = NULL, - *password = NULL, - *caller_id_in_from = "false", - *extension = NULL, - *proxy = NULL, - *context = "default", - *expire_seconds = "3600"; - - gateway->pool = profile->pool; - gateway->profile = profile; - gateway->name = switch_core_strdup(gateway->pool, name); - gateway->freq = 0; - - - for (param = switch_xml_child(gateway_tag, "param"); param; param = param->next) { - char *var = (char *) switch_xml_attr_soft(param, "name"); - char *val = (char *) switch_xml_attr_soft(param, "value"); - - if (!strcmp(var, "register")) { - register_str = val; - } else if (!strcmp(var, "scheme")) { - scheme = val; - } else if (!strcmp(var, "realm")) { - realm = val; - } else if (!strcmp(var, "username")) { - username = val; - } else if (!strcmp(var, "password")) { - password = val; - } else if (!strcmp(var, "caller-id-in-from")) { - caller_id_in_from = val; - } else if (!strcmp(var, "extension")) { - extension = val; - } else if (!strcmp(var, "proxy")) { - proxy = val; - } else if (!strcmp(var, "context")) { - context = val; - } else if (!strcmp(var, "expire-seconds")) { - expire_seconds = val; + if (!switch_strlen_zero(dname)) { + if (switch_true(parse)) { + if (switch_xml_locate_domain(dname, NULL, &droot, &actual_domain_tag) == SWITCH_STATUS_SUCCESS) { + for (ut = switch_xml_child(actual_domain_tag, "user"); ut; ut = ut->next) { + if (((gateways_tag = switch_xml_child(ut, "gateways")))) { + parse_gateways(profile, gateways_tag); + } + } } } - - if (switch_strlen_zero(realm)) { - realm = name; - } - - if (switch_strlen_zero(username)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: username param is REQUIRED!\n"); - switch_xml_free(xml); - goto skip; - } - - if (switch_strlen_zero(password)) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "ERROR: password param is REQUIRED!\n"); - switch_xml_free(xml); - goto skip; - } - - if (switch_strlen_zero(extension)) { - extension = username; - } - - if (switch_strlen_zero(proxy)) { - proxy = realm; - } - - if (!switch_true(register_str)) { - gateway->state = REG_STATE_NOREG; - } - gateway->register_scheme = switch_core_strdup(gateway->pool, scheme); - gateway->register_context = switch_core_strdup(gateway->pool, context); - gateway->register_realm = switch_core_strdup(gateway->pool, realm); - gateway->register_username = switch_core_strdup(gateway->pool, username); - gateway->register_password = switch_core_strdup(gateway->pool, password); - if (switch_true(caller_id_in_from)) { - switch_set_flag(gateway, REG_FLAG_CALLERID); - } - gateway->register_from = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, realm); - gateway->register_contact = switch_core_sprintf(gateway->pool, "sip:%s@%s:%d", extension, profile->sipip, profile->sip_port); - - if (!strncasecmp(proxy, "sip:", 4)) { - gateway->register_proxy = switch_core_strdup(gateway->pool, proxy); - gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy + 4); - } else { - gateway->register_proxy = switch_core_sprintf(gateway->pool, "sip:%s", proxy); - gateway->register_to = switch_core_sprintf(gateway->pool, "sip:%s@%s", username, proxy); - } - - gateway->expires_str = switch_core_strdup(gateway->pool, expire_seconds); - - if ((gateway->freq = atoi(gateway->expires_str)) < 5) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, - "Invalid Freq: %d. Setting Register-Frequency to 3600\n", gateway->freq); - gateway->freq = 3600; - } - gateway->freq -= 2; - - gateway->next = profile->gateways; - profile->gateways = gateway; - - if ((gp = sofia_reg_find_gateway(gateway->name))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate gateway '%s'\n", gateway->name); - sofia_reg_release_gateway(gp); - } else if ((gp=sofia_reg_find_gateway(gateway->register_from))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate uri '%s'\n", gateway->register_from); - sofia_reg_release_gateway(gp); - } else if ((gp=sofia_reg_find_gateway(gateway->register_contact))) { - switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING, "Ignoring duplicate contact '%s'\n", gateway->register_from); - sofia_reg_release_gateway(gp); - } else { - sofia_reg_add_gateway(gateway->name, gateway); - sofia_reg_add_gateway(gateway->register_from, gateway); - sofia_reg_add_gateway(gateway->register_contact, gateway); - } + sofia_glue_add_profile(switch_core_strdup(profile->pool, dname), profile); } - - skip: - assert(gateway_tag); } } + + if ((aliases_tag = switch_xml_child(xprofile, "aliases"))) { + for (alias_tag = switch_xml_child(aliases_tag, "alias"); alias_tag; alias_tag = alias_tag->next) { + char *aname = (char *) switch_xml_attr_soft(alias_tag, "name"); + if (!switch_strlen_zero(aname)) { + + if (sofia_glue_add_profile(switch_core_strdup(profile->pool, aname), profile) == SWITCH_STATUS_SUCCESS) { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Adding Alias [%s] for profile [%s]\n", aname, profile->name); + } else { + switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Adding Alias [%s] for profile [%s] (name in use)\n", + aname, profile->name); + } + } + } + } + if (profile->sipip) { switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Started Profile %s [%s]\n", profile->name, url); diff --git a/src/mod/endpoints/mod_sofia/sofia_glue.c b/src/mod/endpoints/mod_sofia/sofia_glue.c index dd8c58ec7a..76ca768f59 100644 --- a/src/mod/endpoints/mod_sofia/sofia_glue.c +++ b/src/mod/endpoints/mod_sofia/sofia_glue.c @@ -1437,11 +1437,48 @@ sofia_profile_t *sofia_glue_find_profile(char *key) return profile; } -void sofia_glue_add_profile(char *key, sofia_profile_t *profile) +switch_status_t sofia_glue_add_profile(char *key, sofia_profile_t *profile) { + switch_status_t status = SWITCH_STATUS_FALSE; + switch_mutex_lock(mod_sofia_globals.hash_mutex); - switch_core_hash_insert(mod_sofia_globals.profile_hash, key, profile); + if (!switch_core_hash_find(mod_sofia_globals.profile_hash, key)) { + status = switch_core_hash_insert(mod_sofia_globals.profile_hash, key, profile); + } switch_mutex_unlock(mod_sofia_globals.hash_mutex); + + return status; +} + +void sofia_glue_del_profile(sofia_profile_t *profile) +{ + switch_hash_index_t *hi; + void *vval; + const void *vvar; + sofia_profile_t *this_profile; + sofia_gateway_t *gp, *this_gateway; + + + switch_mutex_lock(mod_sofia_globals.hash_mutex); + for (hi = switch_hash_first(switch_hash_pool_get(mod_sofia_globals.profile_hash), mod_sofia_globals.profile_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &vvar, NULL, &vval); + this_profile = (sofia_profile_t *) vval; + if (this_profile == profile) { + switch_core_hash_delete(mod_sofia_globals.profile_hash, vvar); + } + } + for (hi = switch_hash_first(switch_hash_pool_get(mod_sofia_globals.gateway_hash), mod_sofia_globals.gateway_hash); hi; hi = switch_hash_next(hi)) { + switch_hash_this(hi, &vvar, NULL, &vval); + this_gateway = (sofia_gateway_t *) vval; + + for (gp = profile->gateways; gp; gp = gp->next) { + if (gp == this_gateway) { + switch_core_hash_delete(mod_sofia_globals.gateway_hash, vvar); + } + } + } + switch_mutex_unlock(mod_sofia_globals.hash_mutex); + } int sofia_glue_init_sql(sofia_profile_t *profile) diff --git a/src/mod/endpoints/mod_sofia/sofia_reg.c b/src/mod/endpoints/mod_sofia/sofia_reg.c index ba5c0ea457..b3e77a4e75 100644 --- a/src/mod/endpoints/mod_sofia/sofia_reg.c +++ b/src/mod/endpoints/mod_sofia/sofia_reg.c @@ -838,13 +838,18 @@ void sofia_reg_release_gateway(sofia_gateway_t *gateway) switch_thread_rwlock_unlock(gateway->profile->rwlock); } -void sofia_reg_add_gateway(char *key, sofia_gateway_t * gateway) +switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway) { + switch_status_t status = SWITCH_STATUS_FALSE; + switch_mutex_lock(mod_sofia_globals.hash_mutex); - switch_core_hash_insert(mod_sofia_globals.gateway_hash, key, gateway); + if (!switch_core_hash_find(mod_sofia_globals.gateway_hash, key)) { + status = switch_core_hash_insert(mod_sofia_globals.gateway_hash, key, gateway); + } switch_mutex_unlock(mod_sofia_globals.hash_mutex); + + return status; } - diff --git a/src/switch_xml.c b/src/switch_xml.c index d5525e73f8..d1580b6701 100644 --- a/src/switch_xml.c +++ b/src/switch_xml.c @@ -1176,6 +1176,13 @@ SWITCH_DECLARE(switch_status_t) switch_xml_locate(const char *section, SWITCH_DECLARE(switch_status_t) switch_xml_locate_domain(char *domain_name, char *params, switch_xml_t *root, switch_xml_t *domain) { *domain = NULL; + char my_params[512]; + + if (!params) { + snprintf(my_params, sizeof(my_params), "domain=%s", domain_name); + params = my_params; + } + return switch_xml_locate("directory", "domain", "name", domain_name, root, domain, params); }