[svn-commits] mmichelson: branch group/pimp_my_sip r379161 - /team/group/pimp_my_sip/res/

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jan 15 18:22:29 CST 2013


Author: mmichelson
Date: Tue Jan 15 18:22:26 2013
New Revision: 379161

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379161
Log:
Start on a method for handling incoming INVITEs.

The big hold-up at the moment is not having an ast_sip_endpoint
structure defined. I'm going to add one into res_sip.h based on
sorcery wiki documentation and my own intuition. It is incredibly
likely to change as things evolve, but having something will
be useful.


Modified:
    team/group/pimp_my_sip/res/res_sip_session.c

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=379161&r1=379160&r2=379161
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Tue Jan 15 18:22:26 2013
@@ -34,6 +34,7 @@
 #include "asterisk/uuid.h"
 
 #define SDP_HANDLER_BUCKETS 11
+
 /*!
  * \brief Registered SDP stream handlers
  *
@@ -256,6 +257,24 @@
 	return 0;
 }
 
+static pj_status_t session_load(pjsip_endpoint *endpt);
+static pj_status_t session_start(void);
+static pj_status_t session_stop(void);
+static pj_status_t session_unload(void);
+static pj_bool_t session_on_rx_request(pjsip_rx_data *rdata);
+static void session_on_tsx_state(pjsip_transaction *tsx, pjsip_event *event);
+
+static pjsip_module session_module = {
+	.name = {"Session Module", 14},
+	.priority = PJSIP_MOD_PRIORITY_APPLICATION,
+	.load = session_load,
+	.unload = session_unload,
+	.start = session_start,
+	.stop = session_stop,
+	.on_rx_request = session_on_rx_request,
+	.on_tsx_state = session_on_tsx_state,
+};
+
 /*!
  * \brief Called when the PJSIP core loads us
  *
@@ -305,9 +324,76 @@
 	/* The goal here is to create SIP work and throw it into
 	 * the threadpool. The threadpool callback will deal with
 	 * actually creating a new session and all the other bells
-	 * and whistles
+	 * and whistles. Since threadpool support is not in this
+	 * branch at this point, we'll just handle this in PJSIP's
+	 * endpoint thread.
 	 */
-	/* XXX STUB */
+	pjsip_tx_data *tdata = NULL;
+	pjsip_dialog *dlg = NULL;
+	pjsip_inv_session *inv_session = NULL;
+	/* XXX ast_sip_endpoint doesn't exist yet :( */
+	/* ast_sip_endpoint *endpoint = NULL; */
+
+	if (pjsip_inv_verify_request(rdata, NULL, NULL, NULL, ast_sip_get_pjsip_endpoint(), &tdata) != PJ_SUCCESS) {
+		if (tdata) {
+			/*XXX Should replace this with res_sip or res_sip_session call */
+			pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
+		} else {
+			/*XXX Should replace this with res_sip or res_sip_session call */
+			pjsip_endpt_respond_stateless(ast_sip_get_pjsip_endpoint(), rdata, 500, NULL, NULL, NULL);
+		}
+		return;
+	}
+	if (pjsip_dlg_create_uas(pjsip_ua_instance(), rdata, NULL, &dlg) != PJ_SUCCESS) {
+		/*XXX Should replace this with res_sip or res_sip_session call */
+		pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
+        return;
+	}
+	if (pjsip_inv_create_uas(dlg, rdata, NULL, 0, &inv_session) != PJ_SUCCESS) {
+		/*XXX Should replace this with res_sip or res_sip_session call */
+		pjsip_endpt_send_response2(ast_sip_get_pjsip_endpoint(), rdata, tdata, NULL, NULL);
+		pjsip_dlg_terminate(dlg);
+		return;
+	}
+	if (pjsip_dlg_add_usage(dlg, &session_module, NULL) != PJ_SUCCESS) {
+		/*XXX Should replace this with res_sip or res_sip_session call */
+		pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+		return;
+	}
+	if (pjsip_inv_initial_answer(inv_session, rdata, 100, NULL, NULL, &tdata) != PJ_SUCCESS)
+	{
+		/*XXX Should replace this with res_sip or res_sip_session call */
+	    pjsip_inv_terminate(inv_session, 500, PJ_FALSE);
+	    return;
+	}
+	/* XXX ast_sip_endpoint doesn't exist yet :( */
+#if 0
+	endpoint = ast_sip_identify_endpoint(rdata);
+	if (!endpoint) {
+        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);
+		}
+	}
+	if (ast_sip_requires_authentication(endpoint, rdata)) {
+		if (ast_sip_authenticate_request(endpoint, rdata)) {
+			struct ast_sip_digest_challenge_data challenge_data;
+			if (pjsip_inv_end_session(inv_session, 401, NULL, &tdata) != PJ_SUCCESS) {
+				/* CRAP */
+			}
+			memset(&challenge_data, 0, sizeof(challenge_data));
+			if (ast_sip_get_authentication_credentials(endpoint, &challenge_data)) {
+				/* CRAP */
+			}
+			ast_sip_add_digest_to_challenge(&challenge_data, tdata);
+			/*XXX Should replace this with res_sip or res_sip_session call */
+			pjsip_inv_send_msg(inv_session, tdata);
+		}
+	}
+#endif
 	return;
 }
 
@@ -357,17 +443,6 @@
 	/* XXX STUB */
 }
 
-static pjsip_module session_module = {
-	.name = {"Session Module", 14},
-	.priority = PJSIP_MOD_PRIORITY_APPLICATION,
-	.load = session_load,
-	.unload = session_unload,
-	.start = session_start,
-	.stop = session_stop,
-	.on_rx_request = session_on_rx_request,
-	.on_tsx_state = session_on_tsx_state,
-};
-
 static void session_inv_on_state_changed(pjsip_inv_session *inv, pjsip_event *e)
 {
 	/* XXX STUB */




More information about the svn-commits mailing list