[sr-dev] git:admorten/sca: modules/sca: clear appearance on t_reply with error after receiving 18x.

Andrew Mortensen admorten at isc.upenn.edu
Fri Apr 12 04:38:00 CEST 2013


Module: sip-router
Branch: admorten/sca
Commit: b906a1e4c3d36a8dd007dabd1934c7a625ffdd6a
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=b906a1e4c3d36a8dd007dabd1934c7a625ffdd6a

Author: Andrew Mortensen <admorten at isc.upenn.edu>
Committer: Andrew Mortensen <admorten at isc.upenn.edu>
Date:   Thu Apr 11 22:34:10 2013 -0400

modules/sca: clear appearance on t_reply with error after receiving 18x.

- Receiving a 18x provisional reply triggers line-seize subscription
  termination. Releasing the seized appearance while processing a t_reply
  with an error status *after* getting a 18x would fail because
  sca_subscription_terminate could not find a matching line-seize
  subscription. In that case, look up appearance by tags and release it.

---

 modules/sca/sca_call_info.c |   33 ++++++++++++++++++++++++++++-----
 modules/sca/sca_subscribe.c |    8 +++++++-
 2 files changed, 35 insertions(+), 6 deletions(-)

diff --git a/modules/sca/sca_call_info.c b/modules/sca/sca_call_info.c
index 8f681fd..6766553 100644
--- a/modules/sca/sca_call_info.c
+++ b/modules/sca/sca_call_info.c
@@ -877,8 +877,10 @@ sca_call_info_local_error_reply_handler( sip_msg_t *msg, int status )
 {
     struct to_body	*from;
     struct to_body	*to;
+    sca_appearance	*app;
     str			aor = STR_NULL;
     str			contact_uri = STR_NULL;
+    int			rc;
 
     if ( sca_get_msg_from_header( msg, &from ) < 0 ) {
 	LM_ERR( "sca_call_info_sl_reply_cb: failed to get From header from "
@@ -909,15 +911,36 @@ sca_call_info_local_error_reply_handler( sip_msg_t *msg, int status )
 	return;
     }
 
-    if ( sca_subscription_terminate( sca, &aor,
+    /*
+     * two typical cases to handle. in the first case, we haven't dropped
+     * our line-seize subscription because a transaction exists but we
+     * never got a provisional 18x response before calling t_reply. calling
+     * sca_subscription_terminate will drop the subscription and release
+     * the seized appearance.
+     *
+     * in the second case, we got a 18x response and terminated the
+     * line-seize subscription, so we need to look up the appearance by
+     * tags in order to release it.
+     */
+    rc = sca_subscription_terminate( sca, &aor,
 		SCA_EVENT_TYPE_LINE_SEIZE, &contact_uri,
 		SCA_SUBSCRIPTION_STATE_TERMINATED_NORESOURCE,
-		SCA_SUBSCRIPTION_TERMINATE_OPT_DEFAULT ) < 0 ) {
+		SCA_SUBSCRIPTION_TERMINATE_OPT_DEFAULT );
+    if ( rc < 0 ) {
 	LM_ERR( "sca_call_info_sl_reply_cb: failed to terminate "
 		"line-seize subscription for %.*s", STR_FMT( &contact_uri ));
-    } else if ( sca_notify_call_info_subscribers( sca, &aor ) < 0 ) {
-	LM_ERR( "Failed to call-info NOTIFY %.*s subscribers",
-		STR_FMT( &aor ));
+    } else if ( rc == 0 ) {
+	/* no line-seize subscription found */
+	app = sca_appearance_unlink_by_tags( sca, &aor,
+		    &msg->callid->body, &from->tag_value, &to->tag_value );
+	if ( app ) {
+	    sca_appearance_free( app );
+	    if ( sca_notify_call_info_subscribers( sca, &aor ) < 0 ) {
+		LM_ERR( "sca_call_info_local_error_reply: failed to send "
+			"call-info NOTIFY to %.*s subscribers",
+			STR_FMT( &aor ));
+	    }
+	}
     }
 }
 
diff --git a/modules/sca/sca_subscribe.c b/modules/sca/sca_subscribe.c
index f30386a..d62e7bf 100644
--- a/modules/sca/sca_subscribe.c
+++ b/modules/sca/sca_subscribe.c
@@ -1350,6 +1350,12 @@ sca_subscription_reply( sca_mod *scam, int status_code, char *status_msg,
     return( sca_reply( scam, status_code, status_msg, &extra_headers, msg ));
 }
 
+/*
+ * return values:
+ *	-1: error
+ *	 0: no subscription found to terminate
+ *	 1: subscription terminated
+ */
     int
 sca_subscription_terminate( sca_mod *scam, str *aor, int event,
 	str *subscriber, int termination_state, int opts )
@@ -1395,7 +1401,7 @@ sca_subscription_terminate( sca_mod *scam, str *aor, int event,
     if ( ent == NULL ) {
 	LM_DBG( "No %s subscription for %.*s", event_name,
 		STR_FMT( subscriber ));
-	return( 1 );
+	return( 0 );
     }
 
     sub = (sca_subscription *)ent->value;




More information about the sr-dev mailing list