[asterisk-commits] mmichelson: branch 11 r374842 - in /branches/11: channels/ include/asterisk/ ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Thu Oct 11 10:31:15 CDT 2012


Author: mmichelson
Date: Thu Oct 11 10:31:10 2012
New Revision: 374842

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=374842
Log:
Don't make chan_sip export global symbols.

During testing, it was discovered that having chan_sip
export global symbols was problematic.

The biggest problem was that load order was affected.
Trying to use realtime could be problematic since in
all likelihood the necessary realtime driver(s) would
not be loaded before chan_sip.

In addition, it was found that it was impossible to
use the Digium Phone Module for Asterisk since it
must be loaded before chan_sip since it must hook
into chan_sip's configuration parsing.

The solution is to use a virtual table in the same
manner that other modules in Asterisk do, like
app_voicemail.


Added:
    branches/11/main/sip_api.c   (with props)
Removed:
    branches/11/channels/chan_sip.exports.in
Modified:
    branches/11/channels/chan_sip.c
    branches/11/include/asterisk/sip_api.h

Modified: branches/11/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/channels/chan_sip.c?view=diff&rev=374842&r1=374841&r2=374842
==============================================================================
--- branches/11/channels/chan_sip.c (original)
+++ branches/11/channels/chan_sip.c Thu Oct 11 10:31:10 2012
@@ -7299,7 +7299,8 @@
 	return 0;
 }
 
-int ast_sipinfo_send(
+
+static int sipinfo_send(
 		struct ast_channel *chan,
 		struct ast_variable *headers,
 		const char *content_type,
@@ -33174,12 +33175,22 @@
 	AST_DATA_ENTRY("asterisk/channel/sip/peers", &peers_data_provider),
 };
 
+static const struct ast_sip_api_tech chan_sip_api_provider = {
+	.version = AST_SIP_API_VERSION,
+	.name = "chan_sip",
+	.sipinfo_send = sipinfo_send,
+};
+
 /*! \brief PBX load module - initialization */
 static int load_module(void)
 {
 	ast_verbose("SIP channel loading...\n");
 
 	if (!(sip_tech.capabilities = ast_format_cap_alloc())) {
+		return AST_MODULE_LOAD_FAILURE;
+	}
+
+	if (ast_sip_api_provider_register(&chan_sip_api_provider)) {
 		return AST_MODULE_LOAD_FAILURE;
 	}
 
@@ -33344,6 +33355,8 @@
 	struct ao2_iterator i;
 	int wait_count;
 
+	ast_sip_api_provider_unregister();
+
 	ast_websocket_remove_protocol("sip", sip_websocket_callback);
 
 	network_change_event_unsubscribe();
@@ -33519,7 +33532,7 @@
 	return 0;
 }
 
-AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Session Initiation Protocol (SIP)",
+AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_LOAD_ORDER, "Session Initiation Protocol (SIP)",
 		.load = load_module,
 		.unload = unload_module,
 		.reload = reload,

Modified: branches/11/include/asterisk/sip_api.h
URL: http://svnview.digium.com/svn/asterisk/branches/11/include/asterisk/sip_api.h?view=diff&rev=374842&r1=374841&r2=374842
==============================================================================
--- branches/11/include/asterisk/sip_api.h (original)
+++ branches/11/include/asterisk/sip_api.h Thu Oct 11 10:31:10 2012
@@ -26,6 +26,16 @@
 #include "asterisk/optional_api.h"
 #include "asterisk/config.h"
 
+#define AST_SIP_API_VERSION 1
+
+struct ast_sip_api_tech {
+	const int version;
+	const char *name;
+	int (*sipinfo_send)(struct ast_channel *chan,
+			struct ast_variable *headers, const char *content_type,
+			const char *content, const char *useragent_filter);
+};
+
 /*!
  * \brief Send a customized SIP INFO request
  *
@@ -44,6 +54,23 @@
 		const char *content,
 		const char *useragent_filter);
 
+/*!
+ * \brief Register a SIP API provider
+ *
+ * This will fail if a provider has already registered or if the
+ * provider is using an incorrect version.
+ *
+ * \param provider The provider to register
+ * \retval 0 Success
+ * \retval -1 Failure
+ */
+int ast_sip_api_provider_register(const struct ast_sip_api_tech *provider);
+
+/*!
+ * \brief Unregister a SIP API provider
+ */
+void ast_sip_api_provider_unregister(void);
+
 #if defined(__cplusplus) || defined(c_plusplus)
 }
 #endif

Added: branches/11/main/sip_api.c
URL: http://svnview.digium.com/svn/asterisk/branches/11/main/sip_api.c?view=auto&rev=374842
==============================================================================
--- branches/11/main/sip_api.c (added)
+++ branches/11/main/sip_api.c Thu Oct 11 10:31:10 2012
@@ -1,0 +1,60 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2012, 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 "asterisk/sip_api.h"
+#include "asterisk/logger.h"
+
+static const struct ast_sip_api_tech *api_provider;
+
+int ast_sipinfo_send(struct ast_channel *chan,
+		struct ast_variable *headers,
+		const char *content_type,
+		const char *content,
+		const char *useragent_filter)
+{
+	if (!api_provider) {
+		ast_log(LOG_WARNING, "Unable to send custom SIP INFO. No API provider registered\n");
+		return -1;
+	}
+
+	return api_provider->sipinfo_send(chan, headers, content_type, content, useragent_filter);
+}
+
+int ast_sip_api_provider_register(const struct ast_sip_api_tech *provider)
+{
+	if (api_provider) {
+		ast_log(LOG_WARNING, "SIP provider %s has already registered. Not registering provider %s\n",
+				api_provider->name, provider->name);
+		return -1;
+	}
+
+	if (provider->version != AST_SIP_API_VERSION) {
+		ast_log(LOG_WARNING, "SIP API provider version mismatch: Current version is %d but provider "
+				"uses version %d\n", AST_SIP_API_VERSION, provider->version);
+		return -1;
+	}
+
+	api_provider = provider;
+	return 0;
+}
+
+void ast_sip_api_provider_unregister(void)
+{
+	api_provider = NULL;
+}

Propchange: branches/11/main/sip_api.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/11/main/sip_api.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: branches/11/main/sip_api.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain




More information about the asterisk-commits mailing list