[asterisk-commits] mmichelson: branch group/pimp_my_sip r379387 - in /team/group/pimp_my_sip: in...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Thu Jan 17 15:14:35 CST 2013
Author: mmichelson
Date: Thu Jan 17 15:14:31 2013
New Revision: 379387
URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=379387
Log:
Add method for determining where in the dialplan to send incoming calls.
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=379387&r1=379386&r2=379387
==============================================================================
--- 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 15:14:31 2013
@@ -20,6 +20,8 @@
#define _RES_SIP_SESSION_H
#include "asterisk/linkedlists.h"
+/* Needed for AST_MAX_EXTENSION constant */
+#include "asterisk/channel.h"
/* Forward declarations */
struct ast_sip_endpoint;
@@ -47,6 +49,8 @@
* \brief A structure describing a SIP session
*/
struct ast_sip_session {
+ /* Dialplan extension where incoming call is destined */
+ char exten[AST_MAX_EXTENSION];
/* The endpoint with which Asterisk is communicating */
struct ast_sip_endpoint *endpoint;
/* The PJSIP details of the session, which includes the dialog */
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=379387&r1=379386&r2=379387
==============================================================================
--- team/group/pimp_my_sip/res/res_sip_session.c (original)
+++ team/group/pimp_my_sip/res/res_sip_session.c Thu Jan 17 15:14:31 2013
@@ -415,6 +415,50 @@
return session;
}
+enum sip_get_destination_result {
+ /*! The extension was successfully found */
+ SIP_GET_DEST_EXTEN_FOUND,
+ /*! The extension specified in the RURI was not found */
+ SIP_GET_DEST_EXTEN_NOT_FOUND,
+ /*! The extension specified in the RURI was a partial match */
+ SIP_GET_DEST_EXTEN_PARTIAL,
+ /*! The RURI is of an unsupported scheme */
+ SIP_GET_DEST_UNSUPPORTED_URI,
+};
+
+/*!
+ * \brief Determine where in the dialplan a call should go
+ *
+ * This uses the username in the request URI to try to match
+ * an extension in the endpoint's configured context in order
+ * to route the call.
+ *
+ * \param session The inbound SIP session
+ * \param rdata The SIP INVITE
+ */
+static enum sip_get_destination_result get_destination(struct ast_sip_session *session, pjsip_rx_data *rdata)
+{
+ pjsip_uri *ruri = rdata->msg_info.msg->line.req.uri;
+ pjsip_sip_uri *sip_ruri;
+ size_t chars_to_copy;
+ if (!PJSIP_URI_SCHEME_IS_SIP(ruri) && !PJSIP_URI_SCHEME_IS_SIPS(ruri)) {
+ return SIP_GET_DEST_UNSUPPORTED_URI;
+ }
+ 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);
+ session->exten[chars_to_copy] = '\0';
+ if (ast_exists_extension(NULL, session->endpoint->context, session->exten, 1, NULL)) {
+ return SIP_GET_DEST_EXTEN_FOUND;
+ }
+ /* XXX In reality, we'll likely have further options so that partial matches
+ * can be indicated here, but for getting something up and running, we're going
+ * to return a "not exists" error here.
+ */
+ return SIP_GET_DEST_EXTEN_NOT_FOUND;
+}
+
static void handle_new_invite(pjsip_rx_data *rdata)
{
/* The goal here is to create SIP work and throw it into
@@ -500,6 +544,33 @@
}
return;
}
+
+ switch (get_destination(session, rdata)) {
+ case SIP_GET_DEST_EXTEN_FOUND:
+ /* Things worked. Keep going */
+ break;
+ case SIP_GET_DEST_UNSUPPORTED_URI:
+ if (pjsip_inv_end_session(inv_session, 416, 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, 416, PJ_FALSE);
+ }
+ return;
+ case SIP_GET_DEST_EXTEN_NOT_FOUND:
+ case SIP_GET_DEST_EXTEN_PARTIAL:
+ default:
+ if (pjsip_inv_end_session(inv_session, 404, 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, 404, PJ_FALSE);
+ }
+ return;
+ };
+
AST_LIST_TRAVERSE(&session->supplements, supplement, next) {
if (!supplement->method || !strcmp(supplement->method, "INVITE")) {
supplement->incoming_request(session, rdata);
More information about the asterisk-commits
mailing list