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

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Wed Jan 16 14:40:36 CST 2013


Author: mmichelson
Date: Wed Jan 16 14:40:32 2013
New Revision: 379274

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379274
Log:
More work towards getting all of the fun INVITE handling complete.

We now will create a session and iterate over its supplements on an
incoming INVITE.


Modified:
    team/group/pimp_my_sip/include/asterisk/res_sip_session.h
    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=379274&r1=379273&r2=379274
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip_session.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip_session.h Wed Jan 16 14:40:32 2013
@@ -122,6 +122,16 @@
 };
 
 /*!
+ * \brief Allocate a new SIP session
+ *
+ * This will take care of allocating the datastores container on the session as well
+ * as placing all registered supplements onto the session.
+ * \param endpoint The endpoint that this session communicates with
+ * \param inv_session The PJSIP INVITE session data
+ */
+struct ast_sip_session *ast_sip_session_alloc(struct ast_sip_endpoint *endpoint, pjsip_inv_session *inv);
+
+/*!
  * \brief Register an SDP handler
  *
  * An SDP handler is responsible for parsing incoming SDP streams and ensuring that

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=379274&r1=379273&r2=379274
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Wed Jan 16 14:40:32 2013
@@ -135,6 +135,16 @@
 	ao2_callback_data(sdp_handlers, OBJ_KEY | OBJ_UNLINK | OBJ_NODATA, remove_handler, (void *)stream_type, handler);
 }
 
+static int handle_sdp(pjsip_rx_data *rdata)
+{
+	/*XXX STUB
+	 * This function will need to first check if there is an SDP. If so,
+	 * then it will iterate over the streams and pass them off to the appropriate
+	 * SDP handlers.
+	 */
+	return 0;
+}
+
 AST_RWLIST_HEAD_STATIC(session_supplements, ast_sip_session_supplement);
 
 int ast_sip_session_register_supplement(struct ast_sip_session_supplement *supplement)
@@ -156,6 +166,8 @@
 	}
 	AST_RWLIST_TRAVERSE_SAFE_END;
 }
+
+#define DATASTORE_BUCKETS 53
 
 static void session_datastore_destroy(void *obj)
 {
@@ -319,6 +331,66 @@
 	return PJ_SUCCESS;
 }
 
+static int datastore_hash(const void *obj, int flags)
+{
+	const struct ast_datastore *datastore = obj;
+	const char *uid = flags & OBJ_KEY ? obj : datastore->uid;
+
+	ast_assert(uid != NULL);
+
+	return ast_str_hash(uid);
+}
+
+static int datastore_cmp(void *obj, void *arg, int flags)
+{
+	const struct ast_datastore *datastore1 = obj;
+	const struct ast_datastore *datastore2 = arg;
+	const char *uid2 = flags & OBJ_KEY ? arg : datastore2->uid;
+
+	ast_assert(datastore1->uid != NULL);
+	ast_assert(uid2 != NULL);
+
+	return strcmp(datastore1->uid, uid2) ? 0 : CMP_MATCH | CMP_STOP;
+}
+
+static void session_destructor(void *obj)
+{
+	struct ast_sip_session *session = obj;
+	struct ast_sip_session_supplement *supplement;
+	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
+		supplement->session_end(session);
+	}
+	ao2_cleanup(session->datastores);
+	AST_LIST_HEAD_DESTROY(&session->supplements);
+}
+
+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);
+	struct ast_sip_session_supplement *iter;
+	if (!session) {
+		return NULL;
+	}
+	session->datastores = ao2_container_alloc(DATASTORE_BUCKETS, datastore_hash, datastore_cmp);
+	if (!session->datastores) {
+		return NULL;
+	}
+	session->endpoint = endpoint;
+	session->inv_session = inv_session;
+	AST_LIST_HEAD_INIT(&session->supplements);
+	/* XXX There is probably a better way of doing this */
+	AST_RWLIST_RDLOCK(&session_supplements);
+	AST_RWLIST_TRAVERSE(&session_supplements, iter, next) {
+		AST_LIST_INSERT_TAIL(&session->supplements, iter, next);
+	}
+	AST_RWLIST_UNLOCK(&session_supplements);
+	AST_LIST_TRAVERSE(&session->supplements, iter, next) {
+		iter->session_begin(session);
+	}
+	inv_session->mod_data[session_module.id] = session;
+	return session;
+}
+
 static void handle_new_invite(pjsip_rx_data *rdata)
 {
 	/* The goal here is to create SIP work and throw it into
@@ -332,6 +404,8 @@
 	pjsip_dialog *dlg = NULL;
 	pjsip_inv_session *inv_session = NULL;
 	struct ast_sip_endpoint *endpoint = NULL;
+	struct ast_sip_session *session = NULL;
+	struct ast_sip_session_supplement *supplement = NULL;
 
 	if (pjsip_inv_verify_request(rdata, NULL, NULL, NULL, ast_sip_get_pjsip_endpoint(), &tdata) != PJ_SUCCESS) {
 		if (tdata) {
@@ -391,7 +465,31 @@
 			pjsip_inv_send_msg(inv_session, tdata);
 		}
 	}
-	return;
+	session = ast_sip_session_alloc(endpoint, inv_session);
+	if (!session) {
+        if (pjsip_inv_end_session(inv_session, 403, NULL, &tdata) == PJ_SUCCESS) {
+			/*XXX Should replace this with res_sip or res_sip_session call */
+			pjsip_inv_send_msg(inv_session, tdata);
+		} else {
+			/*XXX Should replace this with res_sip or res_sip_session call */
+			pjsip_inv_terminate(inv_session, 403, PJ_FALSE);
+		}
+		return;
+	}
+	AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
+		supplement->incoming_request(session, rdata);
+	}
+	if (handle_sdp(rdata)) {
+		/* Dangit. After all that, we have to reject the call */
+		if (pjsip_inv_end_session(inv_session, 403, NULL, &tdata) == PJ_SUCCESS) {
+			/*XXX Should replace this with res_sip or res_sip_session call */
+			pjsip_inv_send_msg(inv_session, tdata);
+		} else {
+			/*XXX Should replace this with res_sip or res_sip_session call */
+			pjsip_inv_terminate(inv_session, 403, PJ_FALSE);
+		}
+		return;
+	}
 }
 
 /*!




More information about the asterisk-commits mailing list