[Freeswitch-svn] [commit] r8589 - freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua

Freeswitch SVN mikej at freeswitch.org
Sat May 24 23:00:54 EDT 2008


Author: mikej
Date: Sat May 24 23:00:54 2008
New Revision: 8589

Modified:
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c
   freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c

Log:
Un-revert the following:

Tue Feb 26 11:09:37 EST 2008  Pekka.Pessi at nokia.com
* nua: initial fix for sf.net bug #1827511

BYE can now be challenged.

Add the fixes to segfault issue caused by this patch:

Wed May 21 10:40:06 EDT 2008  Pekka Pessi <first.last at nokia.com>
  * nua_client_request: keep own reference to nua handle

Mon May 12 18:58:38 EDT 2008  Pekka Pessi <first.last at nokia.com>
  * nua_session.c: sanitized BYE handling

  Terminate or cancel other session-related transactions when session gets
  terminated.

Fri May 16 10:28:26 EDT 2008  Pekka Pessi <first.last at nokia.com>
  * nua_session.c: fix crash if session was terminated while INVITE was in progress



Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c	Sat May 24 23:00:54 2008
@@ -379,8 +379,12 @@
     /* Destroy saved client request */
     if (cr0 != du->du_cr && nua_client_is_bound(du->du_cr)) {
       nua_client_bind(cr = du->du_cr, NULL);
-      if (!nua_client_is_queued(cr) &&
-	  !nua_client_is_reporting(cr))
+
+      if (nua_client_is_queued(cr))
+	nua_client_request_complete(cr);
+      else if (nua_client_is_reporting(cr))
+	;
+      else
 	nua_client_request_destroy(cr);
     }
 

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c	Sat May 24 23:00:54 2008
@@ -245,10 +245,12 @@
 {
   nua_session_usage_t *ss = nua_dialog_usage_private(du);
   nua_client_request_t *cr, *cr_next;
+  nua_server_request_t *sr;
 
   cr = du->du_cr;
 
-  if (cr != cr0 && cr && cr->cr_orq && cr->cr_status >= 200) {
+  if (cr != cr0 && cr && cr->cr_orq && cr->cr_status >= 200 && 
+      cr->cr_method == sip_method_invite) {
     ss->ss_reporting = 1;
     nua_invite_client_ack(cr, NULL);
     ss->ss_reporting = 0;
@@ -267,11 +269,13 @@
     if (cr == du->du_cr && cr->cr_orq)
       continue;
 
-    nua_stack_event(nh->nh_nua, nh, 
-   	      NULL,
-          cr->cr_event,
-	      SIP_481_NO_TRANSACTION,
-		  NULL);
+    if (cr->cr_status < 200) {
+      nua_stack_event(nh->nh_nua, nh, 
+		      NULL,
+		      cr->cr_event,
+		      SIP_481_NO_TRANSACTION,
+		      NULL);
+    }
 
     nua_client_request_destroy(cr);
 
@@ -291,6 +295,12 @@
     signal_call_state_change(nh, ss, status, phrase, nua_callstate_terminated);
   }
 
+  /* Application can respond to BYE after the session usage has terminated */
+  for (sr = ds->ds_sr; sr; sr = sr->sr_next) {
+    if (sr->sr_usage == du && sr->sr_method == sip_method_bye)
+      sr->sr_usage = NULL;
+  }
+
   ds->ds_has_session = 0;
   nh->nh_has_invite = 0;
   nh->nh_active_call = 0;
@@ -724,10 +734,15 @@
   if (!du)
     return -1;
 
+  ss = nua_dialog_usage_private(du);
+
+  if (ss->ss_state >= nua_callstate_terminating)
+    return nua_client_return(cr, 900, "Session is terminating", msg);
+
   if (nua_client_bind(cr, du) < 0)
     return nua_client_return(cr, 900, "INVITE already in progress", msg);
 
-  ss = nua_dialog_usage_private(du);
+  cr->cr_neutral = 0;
 
   session_timer_preferences(ss->ss_timer,
 			    sip,
@@ -737,8 +752,6 @@
 			    NH_PGET(nh, refresher),
 			    NH_PGET(nh, min_se));
 
-  cr->cr_neutral = 0;
-
   return 0;
 }
 
@@ -755,6 +768,9 @@
   if (du == NULL)		/* Call terminated */ 
     return nua_client_return(cr, SIP_481_NO_TRANSACTION, msg);
 
+  if (ss->ss_state >= nua_callstate_terminating)
+    return nua_client_return(cr, 900, "Session is terminating", msg);
+
   assert(ss);
 
   invite_timeout = NH_PGET(nh, invite_timeout);
@@ -1167,7 +1183,7 @@
   if (error < 0) {
     if (ss->ss_reason == NULL)
       ss->ss_reason = "SIP;cause=500;text=\"Internal Error\"";
-    ss->ss_reporting = 1;	/* We report state here if BYE fails */
+    ss->ss_reporting = 1;	/* We report terminated state here if BYE fails */
     error = nua_client_create(nh, nua_r_bye, &nua_bye_client_methods, NULL);
     ss->ss_reporting = 0;
     signal_call_state_change(nh, ss, 500, "Internal Error", 
@@ -1212,6 +1228,7 @@
   char const *invite_branch;
 
   assert(cr->cr_orq);
+  assert(cr->cr_method == sip_method_invite);
 
 
   if (!ds->ds_leg) {
@@ -1675,6 +1692,8 @@
   if (du == NULL)		/* Call terminated */
     return nua_client_return(cr, SIP_481_NO_TRANSACTION, msg);
   assert(ss);
+  if (ss->ss_state >= nua_callstate_terminating)
+    return nua_client_return(cr, 900, "Session is terminating", msg);
 
   cri = du->du_cr;
 
@@ -2465,7 +2484,7 @@
       nua_stack_event(nh->nh_nua, nh, NULL,
 		      nua_i_media_error, status, phrase, NULL);
 
-      ss->ss_reporting = 1;	/* We report state here if BYE fails */
+      ss->ss_reporting = 1;	/* We report terminated state here if BYE fails */
       error = nua_client_create(nh, nua_r_bye, &nua_bye_client_methods, NULL);
       ss->ss_reporting = 0;
 
@@ -2562,7 +2581,7 @@
   /* send BYE, too, if 200 OK (or 183 to re-INVITE) timeouts  */
   ss->ss_reason = reason;
 
-  ss->ss_reporting = 1;		/* We report state here if BYE fails */
+  ss->ss_reporting = 1;		/* We report terminated state here if BYE fails */
   error = nua_client_create(nh, nua_r_bye, &nua_bye_client_methods, NULL);
   ss->ss_reporting = 0;
 
@@ -3134,6 +3153,8 @@
   if (du == NULL)		/* Call terminated */
     return nua_client_return(cr, SIP_481_NO_TRANSACTION, msg);
   assert(ss);
+  if (ss->ss_state >= nua_callstate_terminating)
+    return nua_client_return(cr, 900, "Session is terminating", msg);
 
   cri = du->du_cr;
 
@@ -3592,7 +3613,9 @@
 
   if (nh->nh_soa)
     soa_terminate(nh->nh_soa, 0);
-  cr->cr_usage = du;
+
+  du->du_cr = NULL;
+  nua_client_bind(cr, du);
 
   return 0;
 }
@@ -3605,15 +3628,34 @@
   nua_session_usage_t *ss;
   char const *reason = NULL;
 
+  int error;
+  nua_server_request_t *sr;
+
   if (du == NULL)
     return nua_client_return(cr, SIP_481_NO_TRANSACTION, msg);
 
   ss = nua_dialog_usage_private(du);
   reason = ss->ss_reason;
 
-  return nua_base_client_trequest(cr, msg, sip,
-				  SIPTAG_REASON_STR(reason),
-				  TAG_NEXT(tags));
+  error = nua_base_client_trequest(cr, msg, sip,
+				    SIPTAG_REASON_STR(reason),
+				    TAG_NEXT(tags));
+
+  if (error == 0) {
+    nua_dialog_usage_reset_refresh(du);
+    ss->ss_timer->timer_set = 0;
+
+    /* Terminate server transactions associated with session, too. */
+    for (sr = du->du_dialog->ds_sr; sr; sr = sr->sr_next) {
+      if (sr->sr_usage == du && nua_server_request_is_pending(sr) &&
+	  sr->sr_method != sip_method_bye) {
+	sr_status(sr, SIP_486_BUSY_HERE);
+	nua_server_respond(sr, 0);
+      }
+    }
+  }
+
+  return error;
 }
 
 /** @NUA_EVENT nua_r_bye
@@ -3663,18 +3705,28 @@
   }
   else {
     nua_session_usage_t *ss = nua_dialog_usage_private(du);
+    nua_client_request_t *cri;
+
+    if (ss->ss_reporting) {
+      return 1;			/* Somebody else's problem */
+    }
+    else if (cr->cr_waiting) {
+      return 1; /* Application problem */
+    }
+
+    nua_client_bind(cr, NULL);
 
     signal_call_state_change(nh, ss, status, "to BYE", 
 			     nua_callstate_terminated);
 
-    if (ss && !ss->ss_reporting) {
-      if (du->du_cr == NULL ||
-	  !nua_client_is_queued(du->du_cr) ||
-	  du->du_cr->cr_status >= 200) {
-	/* INVITE is completed, we can zap the session... */;
-	cr->cr_usage = NULL;
-	nua_session_usage_destroy(nh, ss);
-      }
+    for (cri = du->du_dialog->ds_cr; cri; cri = cri->cr_next) {
+      if (cri->cr_method == sip_method_invite)
+	break;
+    }
+
+    if (!cri || cri->cr_status >= 200) {
+      /* INVITE is completed, we can zap the session... */;
+      nua_session_usage_destroy(nh, ss);
     }
   }
 

Modified: freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c
==============================================================================
--- freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c	(original)
+++ freeswitch/trunk/libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c	Sat May 24 23:00:54 2008
@@ -2010,7 +2010,6 @@
 			   NULL);
   }
 
-  cr->cr_owner = nh;
   cr->cr_methods = methods;
   cr->cr_event = event;
   cr->cr_method = method;
@@ -2020,17 +2019,25 @@
   cr->cr_auto = 1;
 
   if (su_msg_is_non_null(nh->nh_nua->nua_signal)) {
-    nua_event_data_t const *e = su_msg_data(nh->nh_nua->nua_signal)->ee_data;
+    nua_event_data_t *e = su_msg_data(nh->nh_nua->nua_signal)->ee_data;
 
     if (tags == e->e_tags && event == e->e_event) {
       cr->cr_auto = 0;
+
       if (tags) {
 	nua_move_signal(cr->cr_signal, nh->nh_nua->nua_signal);
-	cr->cr_tags = tags;
+	if (cr->cr_signal) {
+	  /* Steal reference from signal */
+	  cr->cr_owner = e->e_nh, e->e_nh = NULL;
+	  cr->cr_tags = tags;
+	}
       }
     }
   }
 
+  if (cr->cr_owner == NULL)
+    cr->cr_owner = nua_handle_ref(nh);
+
   if (tags && cr->cr_tags == NULL)
     cr->cr_tags = tl_tlist(nh->nh_home, TAG_NEXT(tags));
 
@@ -2099,6 +2106,7 @@
 
 void nua_client_request_complete(nua_client_request_t *cr)
 {
+  nua_client_request_remove(cr);
   if (cr && cr->cr_methods->crm_complete)
     cr->cr_methods->crm_complete(cr);
 }
@@ -2116,7 +2124,6 @@
 
   nua_destroy_signal(cr->cr_signal);
 
-  nua_client_request_remove(cr);
   nua_client_bind(cr, NULL);
   
   if (cr->cr_msg)
@@ -2125,7 +2132,6 @@
 
   if (cr->cr_orq)
     nta_outgoing_destroy(cr->cr_orq);
-
   cr->cr_orq = NULL;
 
   if (cr->cr_timer)
@@ -2135,6 +2141,8 @@
     su_free(nh->nh_home, cr->cr_target);
 
   su_free(nh->nh_home, cr);
+
+  nua_handle_unref(nh);
 }
 
 /** Bind client request to a dialog usage */ 
@@ -3075,6 +3083,7 @@
   nua_handle_t *nh = cr->cr_owner;
   sip_method_t method = cr->cr_method;
   nua_dialog_usage_t *du;
+  nua_client_request_t *cr_next;
 
   cr->cr_reporting = 1, nh->nh_ds->ds_reporting = 1;
 
@@ -3132,14 +3141,15 @@
   cr->cr_phrase = NULL;
   cr->cr_reporting = 0, nh->nh_ds->ds_reporting = 0;
 
+  cr_next = nh->nh_ds->ds_cr;
+
   if (!nua_client_is_queued(cr) && !nua_client_is_bound(cr))
     nua_client_request_destroy(cr);
 
   if (method == sip_method_cancel)
     return 1;
 
-  return
-    nua_client_next_request(nh->nh_ds->ds_cr, method == sip_method_invite);
+  return nua_client_next_request(cr_next, method == sip_method_invite);
 }
 
 /** Send event, zap transaction but leave cr in list */



More information about the Freeswitch-svn mailing list