[asterisk-commits] mmichelson: branch mmichelson/pool_shark r380289 - /team/mmichelson/pool_shar...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 28 16:03:03 CST 2013


Author: mmichelson
Date: Mon Jan 28 16:02:59 2013
New Revision: 380289

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380289
Log:
This takes care of gulp_hangup.

gulp_request is next.


Modified:
    team/mmichelson/pool_shark/channels/chan_gulp.c

Modified: team/mmichelson/pool_shark/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/pool_shark/channels/chan_gulp.c?view=diff&rev=380289&r1=380288&r2=380289
==============================================================================
--- team/mmichelson/pool_shark/channels/chan_gulp.c (original)
+++ team/mmichelson/pool_shark/channels/chan_gulp.c Mon Jan 28 16:02:59 2013
@@ -537,15 +537,36 @@
 	return 0;
 }
 
-/*! \brief Function called by core to hang up a Gulp session */
-static int gulp_hangup(struct ast_channel *ast)
-{
-	struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+struct hangup_data {
+	int cause;
+	struct ast_channel *chan;
+};
+
+static void hangup_data_destroy(void *obj)
+{
+	struct hangup_data *h_data = obj;
+	h_data->chan = ast_channel_unref(h_data->chan);
+}
+
+static struct hangup_data *hangup_data_alloc(int cause, struct ast_channel *chan)
+{
+	struct hangup_data *h_data = ao2_alloc(sizeof(*h_data), hangup_data_destroy);
+	if (!h_data) {
+		return NULL;
+	}
+	h_data->cause = cause;
+	h_data->chan = ast_channel_ref(chan);
+	return h_data;
+}
+
+static int hangup(void *data)
+{
 	pj_status_t status;
 	pjsip_tx_data *packet = NULL;
-	int cause = hangup_cause2sip(ast_channel_hangupcause(session->channel));
-
-	pj_thread_register_check();
+	struct hangup_data *h_data = data;
+	struct ast_channel *ast = h_data->chan;
+	struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+	int cause = h_data->cause;
 
 	if (((status = pjsip_inv_end_session(session->inv_session, cause ? cause : 603, NULL, &packet)) == PJ_SUCCESS) && packet) {
 		if (packet->msg->type == PJSIP_RESPONSE_MSG) {
@@ -559,8 +580,34 @@
 	ast_channel_tech_pvt_set(ast, NULL);
 
 	ao2_cleanup(session);
-
-	return (status == PJ_SUCCESS) ? 0 : -1;
+	ao2_cleanup(h_data);
+	return 0;
+}
+
+/*! \brief Function called by core to hang up a Gulp session */
+static int gulp_hangup(struct ast_channel *ast)
+{
+	struct ast_sip_session *session = ast_channel_tech_pvt(ast);
+	int cause = hangup_cause2sip(ast_channel_hangupcause(session->channel));
+	struct hangup_data *h_data = hangup_data_alloc(cause, ast);
+	if (!h_data) {
+		goto failure;
+	}
+
+	if (ast_sip_push_task(session->work, hangup, h_data)) {
+		goto failure;
+	}
+	return 0;
+
+failure:
+	/* Go ahead and do our cleanup of the session and channel even if we're not going
+	 * to be able to send our SIP request/response
+	 */
+	session->channel = NULL;
+	ast_channel_tech_pvt_set(ast, NULL);
+
+	ao2_cleanup(session);
+	return -1;
 }
 
 /*! \brief Function called by core to create a new outgoing Gulp session */




More information about the asterisk-commits mailing list