[asterisk-commits] mmichelson: branch group/pimp_my_sip r379388 - in /team/group/pimp_my_sip: in...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Jan 17 16:10:52 CST 2013


Author: mmichelson
Date: Thu Jan 17 16:10:48 2013
New Revision: 379388

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379388
Log:
Add SDP handling for incoming INVITEs.

This now will visit the registered SDP handlers
so that they may update the session as needed.

I updated the incoming SDP handler callback to take
the SDP session in addition to the media stream so
that global SDP information could be obtained.


Modified:
    team/group/pimp_my_sip/include/asterisk/res_sip_session.h
    team/group/pimp_my_sip/res/res_sip_sdp_audio.c
    team/group/pimp_my_sip/res/res_sip_session.c

Modified: team/group/pimp_my_sip/include/asterisk/res_sip_session.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip_session.h?view=diff&rev=379388&r1=379387&r2=379388
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip_session.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip_session.h Thu Jan 17 16:10:48 2013
@@ -106,15 +106,17 @@
     /*!
      * \brief Set session details based on a stream in an incoming SDP offer or answer
      * \param session The session for which the media is being negotiated
+	 * \param sdp The entire SDP. Useful for getting "global" information, such as connections or attributes
      * \param stream The stream on which to operate
      * \retval 0 The stream was not handled by this handler. If there are other registered handlers for this stream type, they will be called.
      * \retval <0 There was an error encountered. No further operation will take place and the current negotiation will be abandoned.
      * \retval >0 The stream was handled by this handler. No further handler of this stream type will be called.
      */
-    int (*handle_incoming_sdp_stream_offer)(struct ast_sip_session *session, struct pjmedia_sdp_media *stream);
+    int (*handle_incoming_sdp_stream)(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream);
     /*!
      * \brief Create an SDP media stream and add it to the outgoing SDP offer or answer
      * \param session The session for which media is being added
+	 * \param sdp The entire SDP as currently built
      * \param[out] stream The stream to be added to the SDP
      * \retval 0 This handler has no stream to add. If there are other registered handlers for this stream type, they will be called.
      * \retval <0 There was an error encountered. No further operation will take place and the current SDP negotiation will be abandoned.

Modified: team/group/pimp_my_sip/res/res_sip_sdp_audio.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_sdp_audio.c?view=diff&rev=379388&r1=379387&r2=379388
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_sdp_audio.c (original)
+++ team/group/pimp_my_sip/res/res_sip_sdp_audio.c Thu Jan 17 16:10:48 2013
@@ -54,13 +54,13 @@
 static struct ast_sched_context *sched;
 
 /*! \brief Forward declarations for SDP handler functions */
-static int audio_handle_incoming_sdp_stream_offer(struct ast_sip_session *session, struct pjmedia_sdp_media *stream);
+static int audio_handle_incoming_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream);
 static int audio_create_outgoing_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp);
 
 /*! \brief SDP handler for 'audio' media stream */
 static struct ast_sip_session_sdp_handler audio_sdp_handler = {
 	.id = "audio",
-	.handle_incoming_sdp_stream_offer = audio_handle_incoming_sdp_stream_offer,
+	.handle_incoming_sdp_stream = audio_handle_incoming_sdp_stream,
 	.create_outgoing_sdp_stream = audio_create_outgoing_sdp_stream,
 };
 
@@ -87,7 +87,7 @@
 }
 
 /*! \brief Function which handles an incoming 'audio' stream */
-static int audio_handle_incoming_sdp_stream_offer(struct ast_sip_session *session, struct pjmedia_sdp_media *stream)
+static int audio_handle_incoming_sdp_stream(struct ast_sip_session *session, struct pjmedia_sdp_session *sdp, struct pjmedia_sdp_media *stream)
 {
 	int res = 1, addrs_cnt, format, othercapability = 0;
 	char host[NI_MAXHOST];

Modified: team/group/pimp_my_sip/res/res_sip_session.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip_session.c?view=diff&rev=379388&r1=379387&r2=379388
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Thu Jan 17 16:10:48 2013
@@ -32,6 +32,7 @@
 #include "asterisk/astobj2.h"
 #include "asterisk/lock.h"
 #include "asterisk/uuid.h"
+#include "asterisk/pbx.h"
 
 #define SDP_HANDLER_BUCKETS 11
 
@@ -142,6 +143,37 @@
 	 * then it will iterate over the streams and pass them off to the appropriate
 	 * SDP handlers.
 	 */
+	int i;
+	pjsip_rdata_sdp_info *sdp_info = pjsip_rdata_get_sdp_info(rdata);
+	if (!sdp_info || !sdp_info->sdp || sdp_info->sdp_err) {
+		return -1;
+	}
+	for (i = 0; i < sdp_info->sdp->media_count; ++i) {
+		/* See if there are registered handlers for this media stream type */
+		pj_str_t media;
+		struct ast_sip_session_sdp_handler *handler;
+		RAII_VAR(struct sdp_handler_list *, handler_list, NULL, ao2_cleanup);
+
+		/* We need a null-terminated version of the media string */
+		pj_strdup_with_null(rdata->tp_info.pool, &media, &sdp_info->sdp->media[i]->desc.media);
+		handler_list = ao2_find(sdp_handlers, pj_strbuf(&media), OBJ_KEY);
+		if (!handler_list) {
+			ast_debug(1, "No registered SDP handlers for media type '%s'\n", pj_strbuf(&media));
+		}
+		AST_LIST_TRAVERSE(&handler_list->list, handler, next) {
+			int res = handler->handle_incoming_sdp_stream(session, sdp_info->sdp, sdp_info->sdp->media[i]);
+			if (res < 0) {
+				/* Catastrophic failure. Abort! */
+				return -1;
+			} else if (res == 0) {
+				/* Not handled yet. Move to the next handler */
+				continue;
+			} else {
+				/* Handled by this handler. Move to the next stream */
+				break;
+			}
+		}
+	}
 	return 0;
 }
 
@@ -447,7 +479,7 @@
 	sip_ruri = pjsip_uri_get_uri(ruri);
 	/* This sucks. If there's a better way to do this, please inform me. */
 	chars_to_copy = MIN(pj_strlen(&sip_ruri->user), sizeof(session->exten) - 1);
-	memcpy(session->exten, pj_strbuf(&sip_ruri->user) chars_to_copy);
+	memcpy(session->exten, pj_strbuf(&sip_ruri->user), chars_to_copy);
 	session->exten[chars_to_copy] = '\0';
 	if (ast_exists_extension(NULL, session->endpoint->context, session->exten, 1, NULL)) {
 		return SIP_GET_DEST_EXTEN_FOUND;




More information about the asterisk-commits mailing list