[Freeswitch-svn] [commit] r5074 - freeswitch/trunk/src/mod/endpoints/mod_sofia
Freeswitch SVN
anthm at freeswitch.org
Wed May 2 21:55:25 EDT 2007
Author: anthm
Date: Wed May 2 21:55:25 2007
New Revision: 5074
Modified:
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
Log:
improvement towards stable mod_sofia that can start/stop profiles (see i told ya this kind of thing is a slippery slope)
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c Wed May 2 21:55:25 2007
@@ -1022,7 +1022,7 @@
stream->write_function(stream, "%s\n", line);
- switch_thread_rwlock_unlock(profile->rwlock);
+ sofia_glue_release_profile(profile);
} else {
stream->write_function(stream, "Invalid Profile!\n");
}
@@ -1047,8 +1047,8 @@
ac++;
stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", vvar, " alias", profile->name, "ALIASED");
} else {
- stream->write_function(stream, "%25s\t%s\t %32s\t%s\n", profile->name, "profile", profile->url,
- sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN");
+ stream->write_function(stream, "%25s\t%s\t %32s\t%s (%u)\n", profile->name, "profile", profile->url,
+ sofia_test_pflag(profile, PFLAG_RUNNING) ? "RUNNING" : "DOWN", profile->inuse);
c++;
for (gp = profile->gateways; gp; gp = gp->next) {
@@ -1072,24 +1072,21 @@
{
sofia_profile_t *profile = NULL;
char *profile_name = argv[0];
+ const char *err;
+ switch_xml_t xml_root;
if (argc < 2) {
stream->write_function(stream, "Invalid Args!\n");
return SWITCH_STATUS_SUCCESS;
}
- if (argc > 2 && !strcasecmp(argv[2], "reloadxml")) {
- const char *err;
- switch_xml_t xml_root;
-
- if ((xml_root = switch_xml_open_root(1, &err))) {
- switch_xml_free(xml_root);
- }
-
- stream->write_function(stream, "Reload XML [%s]\n", err);
- }
-
if (!strcasecmp(argv[1], "start")) {
+ if (argc > 2 && !strcasecmp(argv[2], "reloadxml")) {
+ if ((xml_root = switch_xml_open_root(1, &err))) {
+ switch_xml_free(xml_root);
+ }
+ stream->write_function(stream, "Reload XML [%s]\n", err);
+ }
if (config_sofia(1, argv[0]) == SWITCH_STATUS_SUCCESS) {
stream->write_function(stream, "%s started successfully\n", argv[0]);
} else {
@@ -1103,23 +1100,35 @@
return SWITCH_STATUS_SUCCESS;
}
- if (!strcasecmp(argv[1], "stop")) {
- sofia_clear_pflag_locked(profile, PFLAG_RUNNING);
- stream->write_function(stream, "stopping: %s", profile->name);
- } else if (!strcasecmp(argv[1], "restart")) {
+ if (!strcasecmp(argv[1], "stop") || !strcasecmp(argv[1], "restart")) {
int rsec = 30;
-
- if (time(NULL) - profile->started < rsec) {
- stream->write_function(stream, "Profile %s must be up for at least %d seconds to restart\n", rsec, profile->name);
+ int diff = (int) (time(NULL) - profile->started);
+ int remain = rsec - diff;
+ if (diff < rsec) {
+ stream->write_function(stream, "Profile %s must be up for at least %d seconds to stop/restart.\nPlease wait %d second%s\n",
+ profile->name, rsec, remain, remain == 1 ? "" : "s");
} else {
- sofia_set_pflag_locked(profile, PFLAG_RESPAWN);
- sofia_clear_pflag_locked(profile, PFLAG_RUNNING);
- stream->write_function(stream, "restarting: %s", profile->name);
+
+ if (argc > 2 && !strcasecmp(argv[2], "reloadxml")) {
+ if ((xml_root = switch_xml_open_root(1, &err))) {
+ switch_xml_free(xml_root);
+ }
+ stream->write_function(stream, "Reload XML [%s]\n", err);
+ }
+
+ if (!strcasecmp(argv[1], "stop")) {
+ sofia_clear_pflag_locked(profile, PFLAG_RUNNING);
+ stream->write_function(stream, "stopping: %s", profile->name);
+ } else {
+ sofia_set_pflag_locked(profile, PFLAG_RESPAWN);
+ sofia_clear_pflag_locked(profile, PFLAG_RUNNING);
+ stream->write_function(stream, "restarting: %s", profile->name);
+ }
}
}
if (profile) {
- switch_thread_rwlock_unlock(profile->rwlock);
+ sofia_glue_release_profile(profile);
}
return SWITCH_STATUS_SUCCESS;
@@ -1328,7 +1337,6 @@
tech_pvt->dest = switch_core_session_sprintf(nsession, "sip:%s", dest);
}
tech_pvt->invite_contact = switch_core_session_strdup(nsession, gateway_ptr->register_contact);
- sofia_reg_release_gateway(gateway_ptr);
} else {
if (!(dest = strchr(profile_name, '/'))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid URL\n");
@@ -1416,7 +1424,7 @@
done:
if (profile) {
- switch_thread_rwlock_unlock(profile->rwlock);
+ sofia_glue_release_profile(profile);
}
return cause;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h Wed May 2 21:55:25 2007
@@ -439,15 +439,13 @@
char const *phrase,
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);
-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);
-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);
@@ -469,5 +467,20 @@
void *pdata);
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);
+
+switch_status_t sofia_glue_add_profile(char *key, sofia_profile_t *profile);
+void sofia_glue_release_profile__(const char *file, const char *func, int line, sofia_profile_t *profile);
+#define sofia_glue_release_profile(x) sofia_glue_release_profile__(__FILE__, __SWITCH_FUNC__, __LINE__, x)
+
+sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, int line, char *key);
+#define sofia_glue_find_profile(x) sofia_glue_find_profile__(__FILE__, __SWITCH_FUNC__, __LINE__, x)
+
+
+switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway);
+sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, char *key);
+#define sofia_reg_find_gateway(x) sofia_reg_find_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__, x)
+
+
+void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway);
+#define sofia_reg_release_gateway(x) sofia_reg_release_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__, x);
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c Wed May 2 21:55:25 2007
@@ -237,7 +237,7 @@
}
if (profile) {
- switch_thread_rwlock_unlock(profile->rwlock);
+ sofia_glue_release_profile(profile);
}
}
}
@@ -615,7 +615,7 @@
if (!switch_strlen_zero(profile_name) && (profile = sofia_glue_find_profile(profile_name))) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile [%s] Already exists.\n", switch_str_nil(profile_name));
status = SWITCH_STATUS_FALSE;
- switch_thread_rwlock_unlock(profile->rwlock);
+ sofia_glue_release_profile(profile);
return status;
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c Wed May 2 21:55:25 2007
@@ -1418,29 +1418,44 @@
return url;
}
-
-sofia_profile_t *sofia_glue_find_profile(char *key)
+sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, int line, char *key)
{
sofia_profile_t *profile;
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if ((profile = (sofia_profile_t *) switch_core_hash_find(mod_sofia_globals.profile_hash, key))) {
- if (!sofia_test_pflag(profile, PFLAG_RUNNING)) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is not running\n", profile->name);
- profile = NULL;
- } else if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", profile->name);
+ if (switch_thread_rwlock_tryrdlock(profile->rwlock) != SWITCH_STATUS_SUCCESS) {
+#ifdef SOFIA_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "Profile %s is locked\n", profile->name);
+#endif
profile = NULL;
- }
+ }
} else {
- switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is not in the hash\n", profile->name);
+#ifdef SOFIA_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "Profile %s is not in the hash\n", key);
+#endif
}
-
+#ifdef SOFIA_DEBUG_RWLOCKS
+ if (profile) {
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX LOCK %s\n", profile->name);
+ }
+#endif
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
return profile;
}
+
+void sofia_glue_release_profile__(const char *file, const char *func, int line, sofia_profile_t *profile)
+{
+ if (profile) {
+#ifdef SOFIA_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX UNLOCK %s\n", profile->name);
+#endif
+ switch_thread_rwlock_unlock(profile->rwlock);
+ }
+}
+
switch_status_t sofia_glue_add_profile(char *key, sofia_profile_t *profile)
{
switch_status_t status = SWITCH_STATUS_FALSE;
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_presence.c Wed May 2 21:55:25 2007
@@ -234,11 +234,9 @@
switch_safe_free(sql);
switch_safe_free(dup_account);
-
if (profile) {
- switch_thread_rwlock_unlock(profile->rwlock);
+ sofia_glue_release_profile(profile);
}
-
}
void sofia_presence_event_handler(switch_event_t *event)
@@ -374,7 +372,7 @@
profile);
- switch_thread_rwlock_unlock(profile->rwlock);
+ sofia_glue_release_profile(profile);
switch_safe_free(sql);
}
@@ -619,9 +617,8 @@
switch_safe_free(id);
switch_safe_free(exp);
- if (profile) {
- switch_thread_rwlock_unlock(profile->rwlock);
- }
+ sofia_glue_release_profile(profile);
+
return 0;
}
Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c
==============================================================================
--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (original)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c Wed May 2 21:55:25 2007
@@ -553,7 +553,7 @@
}
if (profile) {
- sofia_gateway_t *gateway_ptr;
+ sofia_gateway_t *gateway_ptr = NULL;
if ((duprealm = strdup(realm))) {
qrealm = duprealm;
@@ -585,28 +585,37 @@
&& !strcasecmp(gateway_ptr->register_realm, qrealm)) {
gateway = gateway_ptr;
- if (!switch_test_flag(gateway->profile, PFLAG_RUNNING)) {
+ if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
+#ifdef SOFIA_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
+#endif
gateway = NULL;
- } else if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
- gateway = NULL;
- }
+ }
+#ifdef SOFIA_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW LOCK %s\n", gateway->profile->name);
+#endif
break;
}
}
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
}
-
+
if (!gateway) {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "No Match for Scheme [%s] Realm [%s]\n", scheme, qrealm);
- goto cancel;
}
+
switch_safe_free(duprealm);
+
+ if (!gateway) {
+ goto cancel;
+ }
+
} else {
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Memory Error!\n");
goto cancel;
}
}
-
+
snprintf(authentication, sizeof(authentication), "%s:%s:%s:%s", scheme, realm, gateway->register_username, gateway->register_password);
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "Authenticating '%s' with '%s'.\n", profile->username, authentication);
@@ -617,10 +626,16 @@
tl_gets(tags, NUTAG_CALLSTATE_REF(ss_state), SIPTAG_WWW_AUTHENTICATE_REF(authenticate), TAG_END());
nua_authenticate(nh, SIPTAG_EXPIRES_STR(gateway->expires_str), NUTAG_AUTH(authentication), TAG_END());
- sofia_reg_release_gateway(gateway);
+ if (gateway) {
+ sofia_reg_release_gateway(gateway);
+ gateway = NULL;
+ }
return;
cancel:
+ if (gateway) {
+ sofia_reg_release_gateway(gateway);
+ }
if (session) {
switch_channel_t *channel = switch_core_session_get_channel(session);
switch_channel_hangup(channel, SWITCH_CAUSE_MANDATORY_IE_MISSING);
@@ -816,26 +831,32 @@
}
-sofia_gateway_t *sofia_reg_find_gateway(char *key)
+sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, char *key)
{
sofia_gateway_t *gateway = NULL;
switch_mutex_lock(mod_sofia_globals.hash_mutex);
if ((gateway = (sofia_gateway_t *) switch_core_hash_find(mod_sofia_globals.gateway_hash, key))) {
- if (!sofia_test_pflag(gateway->profile, PFLAG_RUNNING)) {
- gateway = NULL;
- } else if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
+ if (switch_thread_rwlock_tryrdlock(gateway->profile->rwlock) != SWITCH_STATUS_SUCCESS) {
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "Profile %s is locked\n", gateway->profile->name);
gateway = NULL;
}
}
-
+ if (gateway) {
+#ifdef SOFIA_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW LOCK %s\n", gateway->profile->name);
+#endif
+ }
switch_mutex_unlock(mod_sofia_globals.hash_mutex);
return gateway;
}
-void sofia_reg_release_gateway(sofia_gateway_t *gateway)
+void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway)
{
switch_thread_rwlock_unlock(gateway->profile->rwlock);
+#ifdef SOFIA_DEBUG_RWLOCKS
+ switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, "XXXXXXXXXXXXXX GW UNLOCK %s\n", gateway->profile->name);
+#endif
}
switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway)
More information about the Freeswitch-svn
mailing list