[asterisk-commits] file: branch file/pimp_sip_location r382614 - in /team/file/pimp_sip_location...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Mar 7 11:32:10 CST 2013


Author: file
Date: Thu Mar  7 11:32:07 2013
New Revision: 382614

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=382614
Log:
Make the location work conform to the end result of the discussion on the asterisk-dev mailing list.

This still needs more testing mind you but should be up for review in the next day or two!

Modified:
    team/file/pimp_sip_location/channels/chan_gulp.c
    team/file/pimp_sip_location/include/asterisk/res_sip_session.h
    team/file/pimp_sip_location/res/res_sip.c
    team/file/pimp_sip_location/res/res_sip_sdp_audio.c
    team/file/pimp_sip_location/res/res_sip_session.c
    team/file/pimp_sip_location/res/res_sip_session.exports.in

Modified: team/file/pimp_sip_location/channels/chan_gulp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/channels/chan_gulp.c?view=diff&rev=382614&r1=382613&r2=382614
==============================================================================
--- team/file/pimp_sip_location/channels/chan_gulp.c (original)
+++ team/file/pimp_sip_location/channels/chan_gulp.c Thu Mar  7 11:32:07 2013
@@ -252,16 +252,10 @@
 static struct ast_channel *gulp_new(struct ast_sip_session *session, int state, const char *exten, const char *title, const char *linkedid, const char *cid_name)
 {
 	struct ast_channel *chan;
-	RAII_VAR(struct ast_uuid *, uuid, ast_uuid_generate(), ast_free_ptr);
-	char uuid_str[AST_UUID_STR_LEN];
 	struct ast_format fmt;
 
-	if (!uuid) {
-		return NULL;
-	}
-
-	if (!(chan = ast_channel_alloc(1, state, "", S_OR(cid_name, ""), "", "", "", linkedid, 0, "Gulp/%s-%s", ast_sorcery_object_get_id(session->endpoint),
-		ast_uuid_to_str(uuid, uuid_str, AST_UUID_STR_LEN)))) {
+	if (!(chan = ast_channel_alloc(1, state, "", S_OR(cid_name, ""), "", "", "", linkedid, 0, "Gulp/%s-%.*s", ast_sorcery_object_get_id(session->endpoint),
+		(int)session->inv_session->dlg->call_id->id.slen, session->inv_session->dlg->call_id->id.ptr))) {
 		return NULL;
 	}
 
@@ -608,8 +602,13 @@
 static int call(void *data)
 {
 	struct ast_sip_session *session = data;
-
-	ast_sip_session_call(session);
+	pjsip_tx_data *packet;
+
+	if (pjsip_inv_invite(session->inv_session, &packet) != PJ_SUCCESS) {
+		return -1;
+	}
+
+	ast_sip_session_send_request(session, packet);
 
 	ao2_ref(session, -1);
 	return 0;
@@ -701,12 +700,20 @@
 
 static int hangup(void *data)
 {
+	pj_status_t status;
+	pjsip_tx_data *packet = NULL;
 	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;
 
-	ast_sip_session_end(session, 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) {
+			ast_sip_session_send_response(session, packet);
+		} else {
+			ast_sip_session_send_request(session, packet);
+		}
+	}
 
 	session->channel = NULL;
 	ast_channel_tech_pvt_set(ast, NULL);

Modified: team/file/pimp_sip_location/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/include/asterisk/res_sip_session.h?view=diff&rev=382614&r1=382613&r2=382614
==============================================================================
--- team/file/pimp_sip_location/include/asterisk/res_sip_session.h (original)
+++ team/file/pimp_sip_location/include/asterisk/res_sip_session.h Thu Mar  7 11:32:07 2013
@@ -82,8 +82,6 @@
 	struct ao2_container *datastores;
 	/* Media streams */
 	struct ast_sip_session_media media[AST_SIP_MEDIA_SIZE];
-	/* Active invite session legs */
-	struct ao2_container *legs;
 	/* Serializer for tasks relating to this SIP session */
 	struct ast_taskprocessor *serializer;
 };
@@ -193,7 +191,7 @@
 	 * \retval <0 There was an error encountered. No further operation will take place and the current SDP negotiation will be abandoned.
 	 * \retval >0 The handler has a stream to be added to the SDP. No further handler of this stream type will be called.
 	 */
-	int (*create_outgoing_sdp_stream)(struct ast_sip_session *session, pjsip_inv_session *inv_session, struct pjmedia_sdp_session *sdp);
+	int (*create_outgoing_sdp_stream)(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp);
 	/*!
 	 * \brief Apply a negotiated SDP media stream
 	 * \param session The session for which media is being applied
@@ -240,21 +238,6 @@
 struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *location, const char *request_user);
 
 /*!
- * \brief Send the initial INVITE for all outgoing legs of a SIP session
- *
- * \param session A pointer to the SIP session
- */
-void ast_sip_session_call(struct ast_sip_session *session);
-
-/*!
- * \brief End a SIP session, this may in turn end all outgoing legs
- *
- * \param session A pointer to the SIP session
- * \param reason Specific reason code to end with if possible
- */
-void ast_sip_session_end(struct ast_sip_session *session, int reason);
-
-/*!
  * \brief Register an SDP handler
  *
  * An SDP handler is responsible for parsing incoming SDP streams and ensuring that
@@ -402,9 +385,8 @@
  * call into any registered supplements' outgoing_request callback.
  *
  * \param session The session to which to send the request
- * \param inv_session Optional specific invite session to send request on, if not specified the active session will be used
  * \param tdata The request to send
  */
-void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_inv_session *inv_session, pjsip_tx_data *tdata);
+void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata);
 
 #endif /* _RES_SIP_SESSION_H */

Modified: team/file/pimp_sip_location/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/res/res_sip.c?view=diff&rev=382614&r1=382613&r2=382614
==============================================================================
--- team/file/pimp_sip_location/res/res_sip.c (original)
+++ team/file/pimp_sip_location/res/res_sip.c Thu Mar  7 11:32:07 2013
@@ -257,11 +257,17 @@
 
 pjsip_dialog *ast_sip_create_dialog(const struct ast_sip_endpoint *endpoint, const char *uri, const char *request_user)
 {
-	pj_str_t local_uri = pj_str("sip:temp at localhost"), remote_uri;
+	RAII_VAR(struct ast_uuid *, uuid, ast_uuid_generate(), ast_free_ptr);
+	char uuid_str[AST_UUID_STR_LEN];
+	pj_str_t local_uri = pj_str("sip:temp at temp"), remote_uri;
 	pjsip_dialog *dlg = NULL;
 	const char *transport_name = endpoint->transport, *outbound_proxy = endpoint->outbound_proxy;
 	pjsip_tpselector selector = { .type = PJSIP_TPSELECTOR_NONE, };
 	const pj_str_t HCONTACT = { "Contact", 7 };
+
+	if (!uuid) {
+		return NULL;
+	}
 
 	pj_cstr(&remote_uri, uri);
 
@@ -289,7 +295,7 @@
 		}
 	}
 
-	if (sip_dialog_create_from(dlg->pool, &local_uri, "temp", &remote_uri, &selector)) {
+	if (sip_dialog_create_from(dlg->pool, &local_uri, ast_uuid_to_str(uuid, uuid_str, AST_UUID_STR_LEN), &remote_uri, &selector)) {
 		pjsip_dlg_terminate(dlg);
 		return NULL;
 	}

Modified: team/file/pimp_sip_location/res/res_sip_sdp_audio.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/res/res_sip_sdp_audio.c?view=diff&rev=382614&r1=382613&r2=382614
==============================================================================
--- team/file/pimp_sip_location/res/res_sip_sdp_audio.c (original)
+++ team/file/pimp_sip_location/res/res_sip_sdp_audio.c Thu Mar  7 11:32:07 2013
@@ -55,7 +55,7 @@
 
 /*! \brief Forward declarations for SDP handler functions */
 static int audio_negotiate_incoming_sdp_stream(struct ast_sip_session *session, const struct pjmedia_sdp_session *sdp, const struct pjmedia_sdp_media *stream);
-static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, pjsip_inv_session *inv_session, struct pjmedia_sdp_session *sdp);
+static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp);
 static int audio_apply_negotiated_sdp_stream(struct ast_sip_session *session, const struct pjmedia_sdp_session *local, const struct pjmedia_sdp_media *local_stream,
 	const struct pjmedia_sdp_session *remote, const struct pjmedia_sdp_media *remote_stream);
 
@@ -134,9 +134,9 @@
 }
 
 /*! \brief Function which creates an outgoing 'audio' stream */
-static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, pjsip_inv_session *inv_session, struct pjmedia_sdp_session *sdp)
-{
-	pj_pool_t *pool = inv_session->pool_active;
+static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp)
+{
+	pj_pool_t *pool = session->inv_session->pool_active;
 	static const pj_str_t STR_AUDIO = { "audio", 5};
 	static const pj_str_t STR_IN = { "IN", 2 };
 	static const pj_str_t STR_IP4 = { "IP4", 3};

Modified: team/file/pimp_sip_location/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/res/res_sip_session.c?view=diff&rev=382614&r1=382613&r2=382614
==============================================================================
--- team/file/pimp_sip_location/res/res_sip_session.c (original)
+++ team/file/pimp_sip_location/res/res_sip_session.c Thu Mar  7 11:32:07 2013
@@ -45,7 +45,7 @@
 
 /* Some forward declarations */
 static void handle_incoming_request(struct ast_sip_session *session, pjsip_rx_data *rdata);
-static void handle_incoming_response(struct ast_sip_session *session, pjsip_inv_session *inv_session, pjsip_rx_data *rdata);
+static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata);
 static int handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata);
 static void handle_outgoing_request(struct ast_sip_session *session, pjsip_tx_data *tdata);
 static void handle_outgoing_response(struct ast_sip_session *session, pjsip_tx_data *tdata);
@@ -68,14 +68,6 @@
 	AST_LIST_HEAD_NOLOCK(, ast_sip_session_sdp_handler) list;
 	/* The handlers in this list handle streams of this type */
 	char stream_type[1];
-};
-
-/*!
- * \brief Wrapper structure for invite session
- */
-struct sip_session_leg {
-	/* The invite session for the leg */
-	pjsip_inv_session *inv_session;
 };
 
 static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer);
@@ -370,10 +362,10 @@
 	return;
 }
 
-void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_inv_session *inv_session, pjsip_tx_data *tdata)
+void ast_sip_session_send_request(struct ast_sip_session *session, pjsip_tx_data *tdata)
 {
 	handle_outgoing_request(session, tdata);
-	pjsip_inv_send_msg(inv_session ? inv_session : session->inv_session, tdata);
+	pjsip_inv_send_msg(session->inv_session, tdata);
 	return;
 }
 
@@ -474,7 +466,6 @@
 		ast_free(supplement);
 	}
 	ast_taskprocessor_unreference(session->serializer);
-	ao2_cleanup(session->legs);
 	ao2_cleanup(session->datastores);
 	AST_LIST_HEAD_DESTROY(&session->supplements);
 	ao2_cleanup(session->endpoint);
@@ -495,22 +486,6 @@
 	return 0;
 }
 
-/*! \brief Internal function which adds an invite session leg to a session */
-static int sip_session_add_leg(struct ast_sip_session *session, pjsip_inv_session *inv_session)
-{
-	struct sip_session_leg *leg = ao2_alloc(sizeof(*leg), NULL);
-
-	if (!leg) {
-		return -1;
-	}
-
-	leg->inv_session = inv_session;
-	ao2_link_flags(session->legs, leg, OBJ_NOLOCK);
-	inv_session->mod_data[session_module.id] = session;
-
-	return 0;
-}
-
 struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv_session)
 {
 	RAII_VAR(struct ast_sip_session *, session, ao2_alloc(sizeof(*session), session_destructor), ao2_cleanup);
@@ -529,18 +504,9 @@
 	}
 	ast_sip_dialog_set_serializer(inv_session->dlg, session->serializer);
 	ao2_ref(endpoint, +1);
+	inv_session->mod_data[session_module.id] = session;
 	session->endpoint = endpoint;
-	ao2_ref(endpoint, +1);
-	session->legs = ao2_container_alloc_options(AO2_ALLOC_OPT_LOCK_NOLOCK, 1, NULL, NULL);
-	if (!session->legs) {
-		return NULL;
-	}
-	if (inv_session) {
-		if (sip_session_add_leg(session, inv_session)) {
-			return NULL;
-		}
-		session->inv_session = inv_session;
-	}
+	session->inv_session = inv_session;
 	if (add_supplements(session)) {
 		return NULL;
 	}
@@ -553,167 +519,79 @@
 	return session;
 }
 
-static int sip_session_create_leg(const struct ast_sip_endpoint *endpoint, struct ast_sip_session *session, const char *uri, pjsip_timer_setting *timer, const char *request_user)
-{
+/*! \brief Simple callback function which returns immediately, used to grab the first contact of an AOR */
+static int contact_find_first(void *obj, void *arg, int flags)
+{
+	return CMP_MATCH | CMP_STOP;
+}
+
+struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *location, const char *request_user)
+{
+	char *aor_name, *rest;
+	const char *uri = NULL;
+	RAII_VAR(struct ast_sip_contact *, contact, NULL, ao2_cleanup);
+	pjsip_timer_setting timer;
 	pjsip_dialog *dlg;
 	struct pjsip_inv_session *inv_session;
+	RAII_VAR(struct ast_sip_session *, session, NULL, ao2_cleanup);
 	pjmedia_sdp_session *offer;
-	RAII_VAR(struct sip_session_leg *, leg, NULL, ao2_cleanup);
+
+	/* If no location has been provided use the AOR list from the endpoint itself */
+	if (ast_strlen_zero(location)) {
+		location = endpoint->aors;
+	}
+
+	/* If the location is still empty we have nowhere to go */
+	if (ast_strlen_zero(location) || !(rest = ast_strdupa(location))) {
+		return NULL;
+	}
+
+	while ((aor_name = strsep(&rest, ","))) {
+		RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
+		RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
+
+		/* If a valid contact is available use its URI for dialing */
+		if (aor && (contacts = ast_sip_location_retrieve_aor_contacts(aor)) &&
+			(contact = ao2_callback(contacts, OBJ_NOLOCK, contact_find_first, NULL))) {
+			uri = contact->uri;
+			break;
+		}
+
+	}
+
+	/* If no URI was found using the provided AORs then use the location as provided as a last resort */
+	if (ast_strlen_zero(uri)) {
+		uri = location;
+	}
+
+	/* If we still have no URI to dial fail to create the session */
+	if (ast_strlen_zero(uri)) {
+		return NULL;
+	}
 
 	if (!(dlg = ast_sip_create_dialog(endpoint, uri, request_user))) {
-		return -1;
-	}
-
-	if (pjsip_inv_create_uac(dlg, NULL, endpoint->extensions, &inv_session) != PJ_SUCCESS) {
+		return NULL;
+	} else if (pjsip_inv_create_uac(dlg, NULL, endpoint->extensions, &inv_session) != PJ_SUCCESS) {
 		pjsip_dlg_terminate(dlg);
-		return -1;
-	}
-
-	pjsip_timer_init_session(inv_session, timer);
-
-	if (pjsip_dlg_add_usage(dlg, &session_module, NULL) != PJ_SUCCESS) {
-		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
-		return -1;
-	}
-
-	if ((offer = create_local_sdp(inv_session, session, NULL))) {
-		pjsip_inv_set_local_sdp(inv_session, offer);
-	} else {
-		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
-		return -1;
-	}
-
-	if (sip_session_add_leg(session, inv_session)) {
-		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
-		return -1;
-	}
-
-	return 0;
-}
-
-/*! \brief Internal function which adds an AOR with container of contacts as outgoing legs on a session */
-static int sip_session_leg_add_aor(struct ast_sip_endpoint *endpoint, struct ast_sip_session *session, pjsip_timer_setting *timer, const char *aor_name, const char *request_user)
-{
-	RAII_VAR(struct ast_sip_aor *, aor, ast_sip_location_retrieve_aor(aor_name), ao2_cleanup);
-	RAII_VAR(struct ao2_container *, contacts, NULL, ao2_cleanup);
-	struct ao2_iterator it_contacts;
-	struct ast_sip_contact *contact;
-
-	if (!aor) {
-		return -1;
-	} else if (!(contacts = ast_sip_location_retrieve_aor_contacts(aor))) {
-		/* The AOR is valid so we don't want to try this as a straight up URI */
-		return 0;
-	}
-
-	it_contacts = ao2_iterator_init(contacts, 0);
-	for (; (contact = ao2_iterator_next(&it_contacts)); ao2_ref(contact, -1)) {
-		sip_session_create_leg(endpoint, session, contact->uri, timer, request_user);
-	}
-	ao2_iterator_destroy(&it_contacts);
-
-	return 0;
-}
-
-struct ast_sip_session *ast_sip_session_create_outgoing(struct ast_sip_endpoint *endpoint, const char *location, const char *request_user)
-{
-	struct ast_sip_session *session;
-	pjsip_timer_setting timer;
-	char *aor_name, *rest;
-
-	/* Create an outgoing session with no default inv_session, multiple may get added later */
-	if (!(session = ast_sip_session_alloc(endpoint, NULL))) {
 		return NULL;
 	}
 
 	pjsip_timer_setting_default(&timer);
 	timer.min_se = endpoint->min_se;
 	timer.sess_expires = endpoint->sess_expires;
-
-	/* If no location has been provided use the AOR list from the endpoint itself */
-	if (ast_strlen_zero(location)) {
-		location = endpoint->aors;
-	}
-
-	/* If the location is still empty we have nowhere to go */
-	if (ast_strlen_zero(location) || !(rest = ast_strdupa(location))) {
-		ao2_ref(session, -1);
-		return NULL;
-	}
-
-	while ((aor_name = strsep(&rest, ","))) {
-		/* If adding based on AOR fails try adding it straight up as a URI */
-		if (sip_session_leg_add_aor(endpoint, session, &timer, aor_name, request_user)) {
-			sip_session_create_leg(endpoint, session, aor_name, &timer, request_user);
-		}
-	}
-
-	/* If the end result of this attempt is no outgoing legs then kill the session */
-	if (!ao2_container_count(session->legs)) {
-		ao2_ref(session, -1);
-		return NULL;
-	}
-
+	pjsip_timer_init_session(inv_session, &timer);
+
+	if (!(session = ast_sip_session_alloc(endpoint, inv_session)) ||
+		(pjsip_dlg_add_usage(dlg, &session_module, NULL) != PJ_SUCCESS) ||
+		!(offer = create_local_sdp(inv_session, session, NULL))) {
+		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+		return NULL;
+	}
+
+	pjsip_inv_set_local_sdp(inv_session, offer);
+
+	ao2_ref(session, +1);
 	return session;
-}
-
-/*! \brief Internal callback function which creates an initial INVITE and sends it for a call leg */
-static int sip_session_leg_call(void *obj, void *arg, int flags)
-{
-	struct sip_session_leg *leg = obj;
-	struct ast_sip_session *session = arg;
-	pjsip_tx_data *packet;
-
-	if (pjsip_inv_invite(leg->inv_session, &packet) == PJ_SUCCESS) {
-		ast_sip_session_send_request(session, leg->inv_session, packet);
-	}
-
-	return 0;
-}
-
-void ast_sip_session_call(struct ast_sip_session *session)
-{
-	ao2_callback(session->legs, OBJ_NOLOCK | OBJ_NODATA, sip_session_leg_call, session);
-}
-
-
-/*! \brief Internal structure used for ending all session legs */
-struct sip_session_leg_end_details {
-	/*! \brief Session the leg belongs to */
-	struct ast_sip_session *session;
-	/*! \brief Reason for ending */
-	int reason;
-	/*! \brief Optional invite session to ignore */
-	pjsip_inv_session *inv_session;
-};
-
-/*! \brief Internal callback function which ends an invite session with a given reason */
-static int sip_session_leg_end(void *obj, void *arg, int flags)
-{
-	struct sip_session_leg *leg = obj;
-	struct sip_session_leg_end_details *details = arg;
-	pjsip_tx_data *packet = NULL;
-
-	if ((leg->inv_session != details->inv_session) &&
-		(pjsip_inv_end_session(leg->inv_session, details->reason ? details->reason : 603, NULL, &packet) == PJ_SUCCESS) && packet) {
-		if (packet->msg->type == PJSIP_RESPONSE_MSG) {
-			ast_sip_session_send_response(details->session, packet);
-		} else {
-			ast_sip_session_send_request(details->session, leg->inv_session, packet);
-		}
-	}
-
-	return 0;
-}
-
-void ast_sip_session_end(struct ast_sip_session *session, int reason)
-{
-	struct sip_session_leg_end_details details = {
-		.session = session,
-		.reason = reason,
-	};
-
-	ao2_callback(session->legs, OBJ_NOLOCK | OBJ_NODATA, sip_session_leg_end, &details);
 }
 
 enum sip_get_destination_result {
@@ -946,35 +824,13 @@
 	}
 }
 
-/*! \brief Internal function which cancels all outgoing legs except the one that has answered */
-static void sip_session_leg_answered(struct ast_sip_session *session, pjsip_inv_session *answered)
-{
-	struct sip_session_leg_end_details details = {
-		.session = session,
-		.reason = 603,
-		.inv_session = answered,
-	};
-
-	ao2_callback(session->legs, OBJ_NOLOCK | OBJ_NODATA, sip_session_leg_end, &details);
-	session->inv_session = answered;
-}
-
-static void handle_incoming_response(struct ast_sip_session *session, pjsip_inv_session *inv_session, pjsip_rx_data *rdata)
+static void handle_incoming_response(struct ast_sip_session *session, pjsip_rx_data *rdata)
 {
 	struct ast_sip_session_supplement *supplement;
 	struct pjsip_status_line status = rdata->msg_info.msg->line.status;
 
 	ast_debug(3, "Response is %d %.*s\n", status.code, (int) pj_strlen(&status.reason),
 			pj_strbuf(&status.reason));
-
-	/* If the remote side has answered end all other legs and treat this as the main invite session */
-	if (status.code == 200) {
-		/* If the session has already been answered drop this response and don't send it to any supplements */
-		if (session->inv_session) {
-			return;
-		}
-		sip_session_leg_answered(session, inv_session);
-	}
 
 	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
 		if (supplement->incoming_response && (
@@ -984,62 +840,15 @@
 	}
 }
 
-<<<<<<< .working
-struct handle_incoming_data {
-	struct ast_sip_session *session;
-	pjsip_rx_data *rdata;
-	pjsip_inv_session *inv_session;
-};
-
-static void handle_incoming_data_destroy(void *obj)
-=======
 static int handle_incoming(struct ast_sip_session *session, pjsip_rx_data *rdata)
->>>>>>> .merge-right.r382591
-{
-<<<<<<< .working
-	struct handle_incoming_data *hid = obj;
-	if (hid->rdata) {
-		pjsip_rx_data_free_cloned(hid->rdata);
-	}
-	if (hid->session) {
-		ao2_ref(hid->session, -1);
-	}
-}
-
-static struct handle_incoming_data *handle_incoming_data_alloc(struct ast_sip_session *session, pjsip_rx_data *rdata, pjsip_inv_session *inv_session)
-{
-	struct handle_incoming_data *hid = ao2_alloc(sizeof(*hid), handle_incoming_data_destroy);
-	if (!hid) {
-		return NULL;
-	}
-	if (rdata) {
-		pjsip_rx_data_clone(rdata, 0, &hid->rdata);
-		if (!hid->rdata) {
-			ao2_ref(hid, -1);
-			return NULL;
-		}
-	}
-	ao2_ref(session, +1);
-	hid->session = session;
-	hid->inv_session = inv_session;
-	return hid;
-}
-
-static int handle_incoming(void *data)
-{
-	struct handle_incoming_data *hid = data;
-	struct ast_sip_session *session = hid->session;
-	pjsip_rx_data *rdata = hid->rdata;
-=======
->>>>>>> .merge-right.r382591
-	pjsip_inv_session *inv_session = hid->inv_session;
+{
 	ast_debug(3, "Received %s\n", rdata->msg_info.msg->type == PJSIP_REQUEST_MSG ?
 			"request" : "response");
 
 	if (rdata->msg_info.msg->type == PJSIP_REQUEST_MSG) {
 		handle_incoming_request(session, rdata);
 	} else {
-		handle_incoming_response(session, inv_session, rdata);
+		handle_incoming_response(session, rdata);
 	}
 
 	return 0;
@@ -1088,43 +897,20 @@
 	}
 }
 
-/*! \brief Internal callback function which removes an invite session call leg if present */
-static int sip_session_leg_match(void *obj, void *arg, int flags)
-{
-	struct sip_session_leg *leg = obj;
-	return (leg->inv_session == arg) ? CMP_MATCH | CMP_STOP : 0;
-}
-
-static int session_end(void *data)
-{
-	struct handle_incoming_data *hid = data;
-	struct ast_sip_session *session = hid->session;
-	pjsip_inv_session *inv_session = hid->inv_session;
-
-	ao2_callback(session->legs, OBJ_NOLOCK | OBJ_NODATA | OBJ_UNLINK, sip_session_leg_match, inv_session);
-
-	if (!ao2_container_count(session->legs)) {
-		struct ast_sip_session_supplement *iter;
-
-		/* Session is dead. Let's get rid of the reference to the session */
-		AST_LIST_TRAVERSE(&session->supplements, iter, next) {
-			if (iter->session_end) {
-				iter->session_end(session);
-			}
-		}
-
-		ao2_cleanup(session);
-	}
-
-<<<<<<< .working
-	inv_session->mod_data[session_module.id] = NULL;
-
-	ao2_ref(hid, -1);
-=======
+static int session_end(struct ast_sip_session *session)
+{
+	struct ast_sip_session_supplement *iter;
+
+	/* Session is dead. Let's get rid of the reference to the session */
+	AST_LIST_TRAVERSE(&session->supplements, iter, next) {
+		if (iter->session_end) {
+			iter->session_end(session);
+		}
+	}
+
 	session->inv_session->mod_data[session_module.id] = NULL;
 	ast_sip_dialog_set_serializer(session->inv_session->dlg, NULL);
 	ao2_cleanup(session);
->>>>>>> .merge-right.r382591
 	return 0;
 }
 
@@ -1139,17 +925,7 @@
 		handle_outgoing(session, e->body.tx_msg.tdata);
 		break;
 	case PJSIP_EVENT_RX_MSG:
-<<<<<<< .working
-		hid = handle_incoming_data_alloc(session, e->body.rx_msg.rdata, inv);
-		if (hid) {
-			if (ast_sip_push_task(session->serializer, handle_incoming, hid)) {
-				ast_log(LOG_WARNING, "Failed to pass in-dialog request to threadpool\n");
-				ao2_cleanup(hid);
-			}
-		}
-=======
 		handle_incoming(session, e->body.rx_msg.rdata);
->>>>>>> .merge-right.r382591
 		break;
 	case PJSIP_EVENT_TSX_STATE:
 		ast_debug(3, "Source of transaction state change is %s\n", pjsip_event_str(e->body.tsx_state.type));
@@ -1159,17 +935,7 @@
 			handle_outgoing(session, e->body.tsx_state.src.tdata);
 			break;
 		case PJSIP_EVENT_RX_MSG:
-<<<<<<< .working
-			hid = handle_incoming_data_alloc(session, e->body.tsx_state.src.rdata, inv);
-			if (hid) {
-				if (ast_sip_push_task(session->serializer, handle_incoming, hid)) {
-					ast_log(LOG_WARNING, "Failed to pass in-dialog request to threadpool\n");
-					ao2_cleanup(hid);
-				}
-			}
-=======
 			handle_incoming(session, e->body.tsx_state.src.rdata);
->>>>>>> .merge-right.r382591
 			break;
 		case PJSIP_EVENT_TRANSPORT_ERROR:
 		case PJSIP_EVENT_TIMER:
@@ -1189,17 +955,7 @@
 	}
 
 	if (inv->state == PJSIP_INV_STATE_DISCONNECTED) {
-<<<<<<< .working
-		hid = handle_incoming_data_alloc(session, NULL, inv);
-		if (hid) {
-			if (ast_sip_push_task(session->serializer, session_end, hid)) {
-				ast_log(LOG_WARNING, "Failed to push session end task to threadpool. Ending session in-thread\n");
-				session_end(session);
-			}
-		}
-=======
 		session_end(session);
->>>>>>> .merge-right.r382591
 	}
 }
 
@@ -1212,23 +968,16 @@
 {
 	/* XXX STUB */
 }
-
-struct on_create_local_sdp_data {
-	struct ast_sip_session *session;
-	pjsip_inv_session *inv_session;
-};
 
 static int add_sdp_streams(void *obj, void *arg, void *data, int flags)
 {
 	pjmedia_sdp_session *answer = arg;
 	struct sdp_handler_list *handler_list = obj;
 	struct ast_sip_session_sdp_handler *handler;
-	struct on_create_local_sdp_data *sdp_data = data;
-	struct ast_sip_session *session = sdp_data->session;
-	pjsip_inv_session *inv_session = sdp_data->inv_session;
+	struct ast_sip_session *session = data;
 
 	AST_LIST_TRAVERSE(&handler_list->list, handler, next) {
-		int res = handler->create_outgoing_sdp_stream(session, inv_session, answer);
+		int res = handler->create_outgoing_sdp_stream(session, answer);
 		if (res < 0) {
 			/* Catastrophic failure. Completely stop processing */
 			return CMP_STOP;
@@ -1242,10 +991,6 @@
 
 static struct pjmedia_sdp_session *create_local_sdp(pjsip_inv_session *inv, struct ast_sip_session *session, const pjmedia_sdp_session *offer)
 {
-	struct on_create_local_sdp_data data = {
-		.session = session,
-		.inv_session = inv,
-	};
 	static const pj_str_t STR_ASTERISK = { "Asterisk", 8 };
 	static const pj_str_t STR_IN = { "IN", 2 };
 	static const pj_str_t STR_IP4 = { "IP4", 3 };
@@ -1270,7 +1015,7 @@
 	local->name = local->origin.user;
 
 	/* Now let the handlers add streams of various types, pjmedia will automatically reorder the media streams for us */
-	ao2_callback_data(sdp_handlers, 0, add_sdp_streams, local, &data);
+	ao2_callback_data(sdp_handlers, 0, add_sdp_streams, local, session);
 
 	/* Use the connection details of the first media stream if possible for SDP level */
 	if (local->media_count) {

Modified: team/file/pimp_sip_location/res/res_sip_session.exports.in
URL: http://svnview.digium.com/svn/asterisk/team/file/pimp_sip_location/res/res_sip_session.exports.in?view=diff&rev=382614&r1=382613&r2=382614
==============================================================================
--- team/file/pimp_sip_location/res/res_sip_session.exports.in (original)
+++ team/file/pimp_sip_location/res/res_sip_session.exports.in Thu Mar  7 11:32:07 2013
@@ -12,8 +12,6 @@
 		LINKER_SYMBOL_PREFIXast_sip_session_send_response;
 		LINKER_SYMBOL_PREFIXast_sip_session_send_request;
 		LINKER_SYMBOL_PREFIXast_sip_session_create_outgoing;
-		LINKER_SYMBOL_PREFIXast_sip_session_call;
-		LINKER_SYMBOL_PREFIXast_sip_session_end;
 		LINKER_SYMBOL_PREFIXpjsip_inv_*;
 	local:
 		*;




More information about the asterisk-commits mailing list