[asterisk-commits] mmichelson: branch mmichelson/res_sip r378706 - in /team/mmichelson/res_sip: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Jan 8 18:24:05 CST 2013


Author: mmichelson
Date: Tue Jan  8 18:24:02 2013
New Revision: 378706

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=378706
Log:
Add some initial res_sip code.


Added:
    team/mmichelson/res_sip/res/res_sip.c   (with props)
Modified:
    team/mmichelson/res_sip/include/asterisk/res_sip.h

Modified: team/mmichelson/res_sip/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/res_sip/include/asterisk/res_sip.h?view=diff&rev=378706&r1=378705&r2=378706
==============================================================================
--- team/mmichelson/res_sip/include/asterisk/res_sip.h (original)
+++ team/mmichelson/res_sip/include/asterisk/res_sip.h Tue Jan  8 18:24:02 2013
@@ -18,6 +18,13 @@
 
 #ifndef _RES_SIP_H
 #define _RES_SIP_H
+
+
+/* Forward declarations of PJSIP stuff */
+struct pjsip_rx_data;
+struct pjsip_module;
+struct pjsip_tx_data;
+struct pjsip_dialog;
 
 /*!
  * \brief Opaque structure representing related SIP tasks
@@ -100,7 +107,7 @@
     /*!
      * \brief Get digest authentication details
      * See ast_sip_get_authentication_credentials for more details
-     */
+    */
     int (*get_authentication_credentials)(struct ast_sip_endpoint *endpoint, struct sip_digest_challenge_data *challenge);
 };
  
@@ -112,7 +119,7 @@
      * \brief Callback used to identify the source of a message.
      * See ast_sip_identify_endpoint for more details
      */
-    struct ast_sip_endpoint *(*identify_endpoint)(struct pjsip_rx_data *data);
+    struct ast_sip_endpoint *(*identify_endpoint)(struct pjsip_rx_data *rdata);
 };
 
 /*!
@@ -232,7 +239,6 @@
  * \retval -1 Failure
  */
 int ast_sip_push_task(struct ast_sip_work *work, int (*sip_task)(void *), void *task_data);
-
 
 /*!
  * \brief General purpose method for sending a SIP request

Added: team/mmichelson/res_sip/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/mmichelson/res_sip/res/res_sip.c?view=auto&rev=378706
==============================================================================
--- team/mmichelson/res_sip/res/res_sip.c (added)
+++ team/mmichelson/res_sip/res/res_sip.c Tue Jan  8 18:24:02 2013
@@ -1,0 +1,145 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2013, Digium, Inc.
+ *
+ * Mark Michelson <mmichelson at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include "asterisk.h"
+#include "pjsip.h"
+#include "pjlib.h"
+
+#include "asterisk/res_sip.h"
+
+static pjsip_endpoint *ast_pjsip_endpoint;
+
+int ast_sip_register_service(pjsip_module *module)
+{
+	if (!ast_pjsip_endpoint) {
+		ast_log(LOG_ERROR, "There is no PJSIP endpoint. Unable to register services\n");
+		return -1;
+	}
+	if (pjsip_endpt_register_module(ast_pjsip_endpoint, module) != PJ_SUCCESS) {
+		ast_log(LOG_ERROR, "Unable to register module %s\n", pj_strbuf(module->name));
+		return -1;
+	}
+	return 0;
+}
+
+void ast_sip_unregister_service(pjsip_module *module)
+{
+	if (!ast_pjsip_endpoint) {
+		return;
+	}
+	pjsip_endpt_unregister_module(ast_pjsip_endpoint, module);
+}
+
+static struct ast_sip_authenticator *registered_authenticator;
+
+int ast_sip_register_authenticator(struct ast_sip_authenticator *auth)
+{
+	if (registered_authenticator) {
+		ast_log(LOG_WARNING, "Authenticator %p is already registered. Cannot register a new one\n",
+				registered_authenticator);
+		return -1;
+	}
+	registered_authenticator = auth;
+	ast_debug(1, "Registered SIP authenticator module %p\n", auth);
+	return 0;
+}
+
+void ast_sip_unregister_authenticator(struct ast_sip_authenticator *auth)
+{
+	if (auth != registered_authenticator) {
+		ast_log(LOG_WARNING, "Trying to unregister authenticator %p but authenticator %p registered\n",
+				auth, registered_authenticator);
+		return;
+	}
+	registered_authenticator = NULL;
+	ast_debug(1, "Unregistered SIP authenticator %p\n", auth);
+}
+
+int ast_sip_requires_authentication(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata)
+{
+	if (!registered_authenticator) {
+		ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming authentication is not required\n");
+		return 0;
+	}
+
+	return registered_authenticator->requires_authentication(endpoint, rdata);
+}
+
+int ast_sip_authenticate_request(struct ast_sip_endpoint *endpoint, struct pjsip_rx_data *rdata)
+{
+	if (!registered_authenticator) {
+		ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming request authenticated properly\n");
+		return 0;
+	}
+
+	return registered_authenticator->authenticate_request(endpoint, rdata);
+}
+
+int ast_sip_get_authentication_credentials(struct ast_sip_endpoint *endpoint,
+		struct sip_digest_challenge_data *challenge)
+{
+	if (!registered_authenticator) {
+		ast_log(LOG_WARNING, "No SIP authenticator registered. Assuming no authentication credentials\n");
+		return -1;
+	}
+
+	return registered_authenticator->authenticate_request(endpoint, rdata);
+}
+
+struct endpoint_identifier_list {
+	struct ast_sip_endpoint_identifier *identifier;
+	AST_LIST_ENTRY(endpoint_identifier_list) list;
+}
+
+AST_LIST_HEAD(, endpoint_identifier_list) endpoint_identifiers;
+
+int ast_sip_register_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
+{
+	SCOPED_LOCK(lock, &endpoint_identifiers, AST_LIST_LOCK, AST_LIST_UNLOCK);
+	AST_LIST_INSERT_TAIL(&endpoint_identifiers);
+	ast_debug(1, "Registered endpoint identifier %p\n", identifier);
+}
+
+void ast_sip_unregister_endpoint_identifier(struct ast_sip_endpoint_identifier *identifier)
+{
+	struct endpoint_identifier_list *iter;
+	SCOPED_LOCK(lock, &endpoint_identifiers, AST_LIST_LOCK, AST_LIST_UNLOCK);
+	AST_LIST_TRAVERSE_SAFE_BEGIN(&endpoint_identifiers, iter, list) {
+		if (iter->identifier == identifier) {
+			AST_LIST_REMOVE_CURRENT(list);
+			ast_debug(1, "Unregistered endpoint identifier %p\n", identifier);
+			break;
+		}
+	}
+	AST_LIST_TRAVERSE_SAFE_END;
+}
+
+struct ast_sip_endpoint *ast_sip_identify_endpoint(struct pjsip_rx_data *rdata)
+{
+	struct endpoint_identifier_list *iter;
+	struct ast_sip_endpoint *endpoint;
+	SCOPED_LOCK(lock, &endpoint_identifiers, AST_LIST_LOCK, AST_LIST_UNLOCK);
+	AST_LIST_TRAVERSE(&endpoint_identifiers, iter, list) {
+		ast_assert(iter->identifier->identify_endpoint != NULL);
+		endpoint = iter->identifier->identify_endpoint(rdata);
+		if (endpoint) {
+			break;
+		}
+	}
+	return endpoint;
+}

Propchange: team/mmichelson/res_sip/res/res_sip.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/mmichelson/res_sip/res/res_sip.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: team/mmichelson/res_sip/res/res_sip.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list