[asterisk-commits] file: branch group/pimp_my_sip r379115 - /team/group/pimp_my_sip/channels/

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 15 10:44:34 CST 2013


Author: file
Date: Tue Jan 15 10:44:31 2013
New Revision: 379115

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379115
Log:
Tada! gulp_hangup

Modified:
    team/group/pimp_my_sip/channels/chan_gulp.c

Modified: team/group/pimp_my_sip/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/channels/chan_gulp.c?view=diff&rev=379115&r1=379114&r2=379115
==============================================================================
--- team/group/pimp_my_sip/channels/chan_gulp.c (original)
+++ team/group/pimp_my_sip/channels/chan_gulp.c Tue Jan 15 10:44:31 2013
@@ -136,6 +136,8 @@
 		return 0;
 	}
 
+	ast_setstate(ast, AST_STATE_UP);
+
 	if ((status = pjsip_inv_answer(session->inv_session, 200, NULL, NULL, &packet)) == PJ_SUCCESS) {
 		pjsip_inv_send_msg(session->inv_session, packet);
 	}
@@ -185,10 +187,70 @@
 	return -1;
 }
 
+/*! \brief Internal function which translates from Asterisk cause codes to SIP response codes */
+static int hangup_cause2sip(int cause)
+{
+	switch (cause) {
+	case AST_CAUSE_UNALLOCATED:             /* 1 */
+	case AST_CAUSE_NO_ROUTE_DESTINATION:    /* 3 IAX2: Can't find extension in context */
+	case AST_CAUSE_NO_ROUTE_TRANSIT_NET:    /* 2 */
+		return 404;
+	case AST_CAUSE_CONGESTION:              /* 34 */
+	case AST_CAUSE_SWITCH_CONGESTION:       /* 42 */
+		return 503;
+	case AST_CAUSE_NO_USER_RESPONSE:        /* 18 */
+		return 408;
+	case AST_CAUSE_NO_ANSWER:               /* 19 */
+	case AST_CAUSE_UNREGISTERED:        /* 20 */
+		return 480;
+	case AST_CAUSE_CALL_REJECTED:           /* 21 */
+		return 403;
+	case AST_CAUSE_NUMBER_CHANGED:          /* 22 */
+		return 410;
+	case AST_CAUSE_NORMAL_UNSPECIFIED:      /* 31 */
+		return 480;
+	case AST_CAUSE_INVALID_NUMBER_FORMAT:
+		return 484;
+	case AST_CAUSE_USER_BUSY:
+		return 486;
+	case AST_CAUSE_FAILURE:
+		return 500;
+	case AST_CAUSE_FACILITY_REJECTED:       /* 29 */
+		return 501;
+	case AST_CAUSE_CHAN_NOT_IMPLEMENTED:
+		return 503;
+	case AST_CAUSE_DESTINATION_OUT_OF_ORDER:
+		return 502;
+	case AST_CAUSE_BEARERCAPABILITY_NOTAVAIL:       /* Can't find codec to connect to host */
+		return 488;
+	case AST_CAUSE_INTERWORKING:    /* Unspecified Interworking issues */
+		return 500;
+	case AST_CAUSE_NOTDEFINED:
+	default:
+		ast_debug(1, "AST hangup cause %d (no match found in PJSIP)\n", cause);
+		return 0;
+	}
+
+	/* Never reached */
+	return 0;
+}
+
 /*! \brief Function called by core to hang up a Gulp session */
 static int gulp_hangup(struct ast_channel *ast)
 {
-	return -1;
+	struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+	pj_status_t status;
+	pjsip_tx_data *packet = NULL;
+	int cause = hangup_cause2sip(ast_channel_hangupcause(session->channel));
+
+	if (((status = pjsip_inv_end_session(session->inv_session, cause ? cause : 603, NULL, &packet)) == PJ_SUCCESS) && packet) {
+		pjsip_inv_send_msg(session->inv_session, packet);
+	}
+
+	session->channel = NULL;
+	ast_channel_tech_pvt_set(ast, NULL);
+
+	return (status == PJ_SUCCESS) ? 0 : -1;
 }
 
 /*! \brief Function called by core to create a new outgoing Gulp session */




More information about the asterisk-commits mailing list