]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Un-revert the following:
authorMichael Jerris <mike@jerris.com>
Sun, 25 May 2008 03:00:54 +0000 (03:00 +0000)
committerMichael Jerris <mike@jerris.com>
Sun, 25 May 2008 03:00:54 +0000 (03:00 +0000)
Tue Feb 26 11:09:37 EST 2008  Pekka.Pessi@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@nokia.com>
  * nua_client_request: keep own reference to nua handle

Mon May 12 18:58:38 EDT 2008  Pekka Pessi <first.last@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@nokia.com>
  * nua_session.c: fix crash if session was terminated while INVITE was in progress

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@8589 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/sofia-sip/libsofia-sip-ua/nua/nua_dialog.c
libs/sofia-sip/libsofia-sip-ua/nua/nua_session.c
libs/sofia-sip/libsofia-sip-ua/nua/nua_stack.c

index ba3b9f788cfb4d5f2eb13c5d1c0ebeaee40aaf1a..2e0f8931aba9b3ee28781d3207ed5adbca03ec52 100644 (file)
@@ -379,8 +379,12 @@ void nua_dialog_usage_remove_at(nua_owner_t *own,
     /* 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);
     }
 
index 9a0427597f1a5dd2bd01396c21d9266d19d25e61..237996ac1174e96dc8b74c17fc9b436d97bb7b07 100644 (file)
@@ -245,10 +245,12 @@ void nua_session_usage_remove(nua_handle_t *nh,
 {
   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 @@ void nua_session_usage_remove(nua_handle_t *nh,
     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 @@ void nua_session_usage_remove(nua_handle_t *nh,
     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 @@ static int nua_invite_client_init(nua_client_request_t *cr,
   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 @@ static int nua_invite_client_init(nua_client_request_t *cr,
                            NH_PGET(nh, refresher),
                            NH_PGET(nh, min_se));
 
-  cr->cr_neutral = 0;
-
   return 0;
 }
 
@@ -755,6 +768,9 @@ static int nua_invite_client_request(nua_client_request_t *cr,
   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 @@ int nua_stack_ack(nua_t *nua, nua_handle_t *nh, nua_event_t e,
   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 @@ int nua_invite_client_ack(nua_client_request_t *cr, tagi_t const *tags)
   char const *invite_branch;
 
   assert(cr->cr_orq);
+  assert(cr->cr_method == sip_method_invite);
 
 
   if (!ds->ds_leg) {
@@ -1675,6 +1692,8 @@ static int nua_prack_client_request(nua_client_request_t *cr,
   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 @@ int process_ack(nua_server_request_t *sr,
       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 @@ int process_timeout(nua_server_request_t *sr,
   /* 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 @@ static int nua_update_client_request(nua_client_request_t *cr,
   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 @@ static int nua_bye_client_init(nua_client_request_t *cr,
 
   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 @@ static int nua_bye_client_request(nua_client_request_t *cr,
   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 @@ static int nua_bye_client_report(nua_client_request_t *cr,
   }
   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);
     }
   }
 
index 6749fb604135f3c36ef82d81d237549ec92031bb..c3ec045cd8c2d5878c13627090bc2157d9088c60 100644 (file)
@@ -2010,7 +2010,6 @@ int nua_client_create(nua_handle_t *nh,
                           NULL);
   }
 
-  cr->cr_owner = nh;
   cr->cr_methods = methods;
   cr->cr_event = event;
   cr->cr_method = method;
@@ -2020,17 +2019,25 @@ int nua_client_create(nua_handle_t *nh,
   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 @@ nua_client_request_t *nua_client_request_remove(nua_client_request_t *cr)
 
 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 @@ void nua_client_request_destroy(nua_client_request_t *cr)
 
   nua_destroy_signal(cr->cr_signal);
 
-  nua_client_request_remove(cr);
   nua_client_bind(cr, NULL);
   
   if (cr->cr_msg)
@@ -2125,7 +2132,6 @@ void nua_client_request_destroy(nua_client_request_t *cr)
 
   if (cr->cr_orq)
     nta_outgoing_destroy(cr->cr_orq);
-
   cr->cr_orq = NULL;
 
   if (cr->cr_timer)
@@ -2135,6 +2141,8 @@ void nua_client_request_destroy(nua_client_request_t *cr)
     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 @@ int nua_base_client_response(nua_client_request_t *cr,
   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 @@ int nua_base_client_response(nua_client_request_t *cr,
   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 */