<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[Freeswitch-trunk][16654] </title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<div id="header">FreeSWITCH Subversion</div>
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://fisheye.freeswitch.org/changelog/FreeSWITCH?cs=16654">16654</a></dd>
<dt>Author</dt> <dd>mrene</dd>
<dt>Date</dt> <dd>2010-02-15 18:07:50 -0600 (Mon, 15 Feb 2010)</dd>
</dl>

<h3>Log Message</h3>
<pre><a href="http://jira.freeswitch.org/browse/MODSOFIA-57">MODSOFIA-57</a> fix edge case if a session is blocked during a sip profile shutdown</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah">freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofiac">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c</a></li>
<li><a href="#freeswitchtrunksrcmodendpointsmod_sofiasofia_regc">freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c (16653 => 16654)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2010-02-15 23:59:36 UTC (rev 16653)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.c        2010-02-16 00:07:50 UTC (rev 16654)
</span><span class="lines">@@ -362,6 +362,10 @@
</span><span class="cx">                 switch_mutex_unlock(tech_pvt-&gt;profile-&gt;flag_mutex);
</span><span class="cx"> 
</span><span class="cx">                 sofia_glue_deactivate_rtp(tech_pvt);
</span><ins>+                
+                if (sofia_test_pflag(tech_pvt-&gt;profile, PFLAG_DESTROY) &amp;&amp; !tech_pvt-&gt;profile-&gt;inuse) {
+                        sofia_profile_destroy(tech_pvt-&gt;profile);
+                }
</ins><span class="cx">         }
</span><span class="cx"> 
</span><span class="cx">         return SWITCH_STATUS_SUCCESS;
</span><span class="lines">@@ -376,6 +380,10 @@
</span><span class="cx">         switch_call_cause_t cause = switch_channel_get_cause(channel);
</span><span class="cx">         int sip_cause = hangup_cause_to_sip(cause);
</span><span class="cx">         const char *ps_cause = NULL, *use_my_cause;
</span><ins>+        
+        if (sofia_test_pflag(tech_pvt-&gt;profile, PFLAG_DESTROY)) {
+                return SWITCH_STATUS_SUCCESS;
+        }
</ins><span class="cx"> 
</span><span class="cx">         switch_mutex_lock(tech_pvt-&gt;sofia_mutex);
</span><span class="cx"> 
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiamod_sofiah"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h (16653 => 16654)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-02-15 23:59:36 UTC (rev 16653)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/mod_sofia.h        2010-02-16 00:07:50 UTC (rev 16654)
</span><span class="lines">@@ -206,6 +206,7 @@
</span><span class="cx">         PFLAG_PASS_CALLEE_ID,
</span><span class="cx">         PFLAG_LOG_AUTH_FAIL,
</span><span class="cx">         PFLAG_TRACK_CALLS,
</span><ins>+        PFLAG_DESTROY,
</ins><span class="cx">         /* No new flags below this line */
</span><span class="cx">         PFLAG_MAX
</span><span class="cx"> } PFLAGS;
</span><span class="lines">@@ -837,6 +838,9 @@
</span><span class="cx"> sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, int line, const char *key);
</span><span class="cx"> #define sofia_glue_find_profile(x) sofia_glue_find_profile__(__FILE__, __SWITCH_FUNC__, __LINE__,  x)
</span><span class="cx"> 
</span><ins>+#define sofia_glue_profile_rdlock(x) sofia_glue_profile_rdlock__(__FILE__, __SWITCH_FUNC__, __LINE__, x)
+switch_status_t sofia_glue_profile_rdlock__(const char *file, const char *func, int line, sofia_profile_t *profile);
+
</ins><span class="cx"> switch_status_t sofia_reg_add_gateway(char *key, sofia_gateway_t *gateway);
</span><span class="cx"> sofia_gateway_t *sofia_reg_find_gateway__(const char *file, const char *func, int line, const char *key);
</span><span class="cx"> #define sofia_reg_find_gateway(x) sofia_reg_find_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__,  x)
</span><span class="lines">@@ -846,6 +850,9 @@
</span><span class="cx"> 
</span><span class="cx"> sofia_gateway_subscription_t *sofia_find_gateway_subscription(sofia_gateway_t *gateway_ptr, const char *event);
</span><span class="cx"> 
</span><ins>+#define sofia_reg_gateway_rdlock(x) sofia_reg_gateway_rdlock__(__FILE__, __SWITCH_FUNC__, __LINE__,  x)
+switch_status_t sofia_reg_gateway_rdlock__(const char *file, const char *func, int line, sofia_gateway_t *gateway);
+
</ins><span class="cx"> void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway);
</span><span class="cx"> #define sofia_reg_release_gateway(x) sofia_reg_release_gateway__(__FILE__, __SWITCH_FUNC__, __LINE__, x);
</span><span class="cx"> 
</span><span class="lines">@@ -964,3 +971,4 @@
</span><span class="cx"> void sofia_glue_tech_untrack(sofia_profile_t *profile, switch_core_session_t *session, switch_bool_t force);
</span><span class="cx"> void sofia_glue_tech_track(sofia_profile_t *profile, switch_core_session_t *session);
</span><span class="cx"> int sofia_glue_recover(switch_bool_t flush);
</span><ins>+void sofia_profile_destroy(sofia_profile_t *profile);
</ins></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofiac"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c (16653 => 16654)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-02-15 23:59:36 UTC (rev 16653)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia.c        2010-02-16 00:07:50 UTC (rev 16654)
</span><span class="lines">@@ -682,6 +682,8 @@
</span><span class="cx">         int locked = 0;
</span><span class="cx">         int check_destroy = 1;
</span><span class="cx"> 
</span><ins>+        /* sofia_private will be == &amp;mod_sofia_globals.keep_private whenever a request is done with a new handle that has to be 
+          freed whenever the request is done */
</ins><span class="cx">         if (nh &amp;&amp; sofia_private == &amp;mod_sofia_globals.keep_private) {
</span><span class="cx">                 if (status &gt;= 300) {
</span><span class="cx">                         nua_handle_bind(nh, NULL);
</span><span class="lines">@@ -689,11 +691,12 @@
</span><span class="cx">                         return;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><ins>+        
</ins><span class="cx"> 
</span><span class="cx">         if (sofia_private &amp;&amp; sofia_private != &amp;mod_sofia_globals.destroy_private &amp;&amp; sofia_private != &amp;mod_sofia_globals.keep_private) {
</span><span class="cx">                 if ((gateway = sofia_private-&gt;gateway)) {
</span><del>-                        if (switch_thread_rwlock_tryrdlock(gateway-&gt;profile-&gt;rwlock) != SWITCH_STATUS_SUCCESS) {
-                                switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, &quot;Profile %s is locked\n&quot;, gateway-&gt;profile-&gt;name);
</del><ins>+                        /* Released in sofia_reg_release_gateway() */
+                        if (sofia_reg_gateway_rdlock(gateway) != SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                                 return;
</span><span class="cx">                         }
</span><span class="cx">                 } else if (!zstr(sofia_private-&gt;uuid)) {
</span><span class="lines">@@ -733,7 +736,8 @@
</span><span class="cx">                         }
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-
</del><ins>+        
+        
</ins><span class="cx">         if (sofia_test_pflag(profile, PFLAG_AUTH_ALL) &amp;&amp; tech_pvt &amp;&amp; tech_pvt-&gt;key &amp;&amp; sip) {
</span><span class="cx">                 sip_authorization_t const *authorization = NULL;
</span><span class="cx"> 
</span><span class="lines">@@ -1527,9 +1531,9 @@
</span><span class="cx">         if (sofia_test_pflag(profile, PFLAG_RESPAWN)) {
</span><span class="cx">                 config_sofia(1, profile-&gt;name);
</span><span class="cx">         }
</span><ins>+        
+        sofia_profile_destroy(profile);
</ins><span class="cx"> 
</span><del>-        switch_core_destroy_memory_pool(&amp;pool);
-
</del><span class="cx">   end:
</span><span class="cx">         switch_mutex_lock(mod_sofia_globals.mutex);
</span><span class="cx">         mod_sofia_globals.threads--;
</span><span class="lines">@@ -1538,6 +1542,16 @@
</span><span class="cx">         return NULL;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+void sofia_profile_destroy(sofia_profile_t *profile) 
+{
+        if (!profile-&gt;inuse) {
+                switch_memory_pool_t *pool = profile-&gt;pool;
+                switch_core_destroy_memory_pool(&amp;pool);
+        } else {
+                sofia_set_pflag(profile, PFLAG_DESTROY);
+        }
+}
+
</ins><span class="cx"> void launch_sofia_profile_thread(sofia_profile_t *profile)
</span><span class="cx"> {
</span><span class="cx">         switch_thread_t *thread;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_gluec"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c (16653 => 16654)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2010-02-15 23:59:36 UTC (rev 16653)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_glue.c        2010-02-16 00:07:50 UTC (rev 16654)
</span><span class="lines">@@ -3776,6 +3776,19 @@
</span><span class="cx">         return url;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+switch_status_t sofia_glue_profile_rdlock__(const char *file, const char *func, int line, sofia_profile_t *profile)
+{
+        switch_status_t status = switch_thread_rwlock_tryrdlock(profile-&gt;rwlock);
+        if (status != SWITCH_STATUS_SUCCESS) {
+                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, &quot;Profile %s is locked\n&quot;, profile-&gt;name);
+                return status;
+        }
+#ifdef SOFIA_DEBUG_RWLOCKS
+        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, &quot;XXXXXXXXXXXXXX LOCK %s\n&quot;, profile-&gt;name);
+#endif
+        return status;
+}
+
</ins><span class="cx"> sofia_profile_t *sofia_glue_find_profile__(const char *file, const char *func, int line, const char *key)
</span><span class="cx"> {
</span><span class="cx">         sofia_profile_t *profile;
</span><span class="lines">@@ -3789,10 +3802,7 @@
</span><span class="cx">                         profile = NULL;
</span><span class="cx">                         goto done;
</span><span class="cx">                 }
</span><del>-                if (switch_thread_rwlock_tryrdlock(profile-&gt;rwlock) != SWITCH_STATUS_SUCCESS) {
-#ifdef SOFIA_DEBUG_RWLOCKS
-                        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, &quot;Profile %s is locked\n&quot;, profile-&gt;name);
-#endif
</del><ins>+                if (sofia_glue_profile_rdlock__(file, func, line, profile) != SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                         profile = NULL;
</span><span class="cx">                 }
</span><span class="cx">         } else {
</span><span class="lines">@@ -3800,13 +3810,8 @@
</span><span class="cx">                 switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, &quot;Profile %s is not in the hash\n&quot;, key);
</span><span class="cx"> #endif
</span><span class="cx">         }
</span><del>-#ifdef SOFIA_DEBUG_RWLOCKS
-        if (profile) {
-                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, &quot;XXXXXXXXXXXXXX LOCK %s\n&quot;, profile-&gt;name);
-        }
-#endif
</del><span class="cx"> 
</span><del>-  done:
</del><ins>+done:
</ins><span class="cx">         switch_mutex_unlock(mod_sofia_globals.hash_mutex);
</span><span class="cx"> 
</span><span class="cx">         return profile;
</span></span></pre></div>
<a id="freeswitchtrunksrcmodendpointsmod_sofiasofia_regc"></a>
<div class="modfile"><h4>Modified: freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c (16653 => 16654)</h4>
<pre class="diff"><span>
<span class="info">--- freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2010-02-15 23:59:36 UTC (rev 16653)
+++ freeswitch/trunk/src/mod/endpoints/mod_sofia/sofia_reg.c        2010-02-16 00:07:50 UTC (rev 16654)
</span><span class="lines">@@ -320,8 +320,9 @@
</span><span class="cx">                         gateway_ptr-&gt;status = SOFIA_GATEWAY_DOWN;
</span><span class="cx">                         gateway_ptr-&gt;retry = 0;
</span><span class="cx"> 
</span><del>-                        if (!gateway_ptr-&gt;nh)
</del><ins>+                        if (!gateway_ptr-&gt;nh) {
</ins><span class="cx">                                 sofia_reg_new_handle(gateway_ptr, now ? 1 : 0);
</span><ins>+                        }
</ins><span class="cx"> 
</span><span class="cx">                         if (sofia_glue_check_nat(gateway_ptr-&gt;profile, gateway_ptr-&gt;register_proxy)) {
</span><span class="cx">                                 user_via = sofia_glue_create_external_via(NULL, gateway_ptr-&gt;profile, gateway_ptr-&gt;register_transport);
</span><span class="lines">@@ -2340,16 +2341,10 @@
</span><span class="cx">                         gateway = NULL;
</span><span class="cx">                         goto done;
</span><span class="cx">                 }
</span><del>-                if (switch_thread_rwlock_tryrdlock(gateway-&gt;profile-&gt;rwlock) != SWITCH_STATUS_SUCCESS) {
-                        switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, NULL, SWITCH_LOG_ERROR, &quot;Profile %s is locked\n&quot;, gateway-&gt;profile-&gt;name);
</del><ins>+                if (sofia_reg_gateway_rdlock__(file, func, line, gateway) != SWITCH_STATUS_SUCCESS) {
</ins><span class="cx">                         gateway = NULL;
</span><span class="cx">                 }
</span><span class="cx">         }
</span><del>-        if (gateway) {
-#ifdef SOFIA_DEBUG_RWLOCKS
-                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, &quot;XXXXXXXXXXXXXX GW LOCK %s\n&quot;, gateway-&gt;profile-&gt;name);
-#endif
-        }
</del><span class="cx"> 
</span><span class="cx">   done:
</span><span class="cx">         switch_mutex_unlock(mod_sofia_globals.hash_mutex);
</span><span class="lines">@@ -2397,7 +2392,20 @@
</span><span class="cx">         return gateway;
</span><span class="cx"> }
</span><span class="cx"> 
</span><ins>+switch_status_t sofia_reg_gateway_rdlock__(const char *file, const char *func, int line, sofia_gateway_t *gateway)
+{
+        switch_status_t status = sofia_glue_profile_rdlock__(file, func, line, gateway-&gt;profile);
</ins><span class="cx"> 
</span><ins>+#ifdef SOFIA_DEBUG_RWLOCKS
+        if (status != SWITCH_STATUS_SUCCESS) {
+                switch_log_printf(SWITCH_CHANNEL_ID_LOG, file, func, line, SWITCH_LOG_ERROR, &quot;XXXXXXXXXXXXXX GW LOCK %s\n&quot;, gateway-&gt;profile-&gt;name);                
+        }
+#endif
+
+        return status;
+}
+
+
</ins><span class="cx"> void sofia_reg_release_gateway__(const char *file, const char *func, int line, sofia_gateway_t *gateway)
</span><span class="cx"> {
</span><span class="cx">         switch_thread_rwlock_unlock(gateway-&gt;profile-&gt;rwlock);
</span></span></pre>
</div>
</div>
<div id="footer">See you at ClueCon</div>

</body>
</html>