[asterisk-commits] file: branch group/pimp_my_sip r380083 - in /team/group/pimp_my_sip: include/...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jan 25 08:44:41 CST 2013


Author: file
Date: Fri Jan 25 08:44:38 2013
New Revision: 380083

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=380083
Log:
Use sorcery to read configured endpoints from res_sip.conf and make them available.

Modified:
    team/group/pimp_my_sip/include/asterisk/res_sip.h
    team/group/pimp_my_sip/res/res_sip.c

Modified: team/group/pimp_my_sip/include/asterisk/res_sip.h
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/include/asterisk/res_sip.h?view=diff&rev=380083&r1=380082&r2=380083
==============================================================================
--- team/group/pimp_my_sip/include/asterisk/res_sip.h (original)
+++ team/group/pimp_my_sip/include/asterisk/res_sip.h Fri Jan 25 08:44:38 2013
@@ -26,6 +26,8 @@
 #include "asterisk/linkedlists.h"
 /* Needed for ast_party_id */
 #include "asterisk/channel.h"
+/* Needed for ast_sorcery */
+#include "asterisk/sorcery.h"
 
 /* Forward declarations of PJSIP stuff */
 struct pjsip_rx_data;
@@ -140,6 +142,7 @@
  * \brief An entity with which Asterisk communicates
  */
 struct ast_sip_endpoint {
+	SORCERY_OBJECT(details);
 	AST_DECLARE_STRING_FIELDS(
 		/*! Name of the endpoint */
 		AST_STRING_FIELD(name);
@@ -348,7 +351,7 @@
  * \retval NULL Endpoint allocation failed
  * \retval non-NULL The newly allocated endpoint
  */
-struct ast_sip_endpoint *ast_sip_endpoint_alloc(const char *name);
+void *ast_sip_endpoint_alloc(const char *name);
 
 /*!
  * \brief Get a pointer to the PJSIP endpoint.
@@ -359,6 +362,14 @@
  * \retval non-NULL PJSIP endpoint.
  */
 pjsip_endpoint *ast_sip_get_pjsip_endpoint(void);
+
+/*!
+ * \brief Get a pointer to the SIP sorcery structure.
+ *
+ * \retval NULL sorcery has not been initialized
+ * \retval non-NULL sorcery structure
+ */
+struct ast_sorcery *ast_sip_get_sorcery(void);
 
 /*!
  * \brief Create a new SIP work structure

Modified: team/group/pimp_my_sip/res/res_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/group/pimp_my_sip/res/res_sip.c?view=diff&rev=380083&r1=380082&r2=380083
==============================================================================
--- team/group/pimp_my_sip/res/res_sip.c (original)
+++ team/group/pimp_my_sip/res/res_sip.c Fri Jan 25 08:44:38 2013
@@ -34,6 +34,7 @@
 #include "asterisk/threadpool.h"
 #include "asterisk/taskprocessor.h"
 #include "asterisk/uuid.h"
+#include "asterisk/sorcery.h"
 
 /*** MODULEINFO
 	<support_level>core</support_level>
@@ -42,6 +43,31 @@
 static pjsip_endpoint *ast_pjsip_endpoint;
 
 static struct ast_threadpool *sip_threadpool;
+
+static struct ast_sorcery *sip_sorcery;
+
+static int sip_initialize_sorcery(void)
+{
+	if (!(sip_sorcery = ast_sorcery_open())) {
+		return -1;
+	}
+
+	ast_sorcery_apply_config(sip_sorcery, "res_sip");
+	ast_sorcery_apply_default(sip_sorcery, "endpoint", "config", "res_sip.conf,criteria=type=endpoint");
+
+	if (ast_sorcery_object_register(sip_sorcery, "endpoint", ast_sip_endpoint_alloc, NULL, NULL)) {
+		ast_sorcery_unref(sip_sorcery);
+		sip_sorcery = NULL;
+		return -1;
+	}
+
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "type", "", OPT_NOOP_T, 0, 0);
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "context", "default", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, context));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "disallow", "", OPT_CODEC_T, 0, FLDSET(struct ast_sip_endpoint, prefs, codecs));
+	ast_sorcery_object_field_register(sip_sorcery, "endpoint", "allow", "", OPT_CODEC_T, 1, FLDSET(struct ast_sip_endpoint, prefs, codecs));
+
+	return 0;
+}
 
 int ast_sip_register_service(pjsip_module *module)
 {
@@ -226,7 +252,7 @@
 	 */
 }
 
-struct ast_sip_endpoint *ast_sip_endpoint_alloc(const char *name)
+void *ast_sip_endpoint_alloc(const char *name)
 {
 	struct ast_sip_endpoint *endpoint = ao2_alloc(sizeof(*endpoint), endpoint_destructor);
 	if (!endpoint) {
@@ -247,6 +273,11 @@
 pjsip_endpoint *ast_sip_get_pjsip_endpoint(void)
 {
 	return ast_pjsip_endpoint;
+}
+
+struct ast_sorcery *ast_sip_get_sorcery(void)
+{
+	return sip_sorcery;
 }
 
 /* PJSIP doesn't know about the INFO method, so we have to define it ourselves */
@@ -577,6 +608,14 @@
 		ast_log(LOG_ERROR, "Failed to start SIP monitor thread. Aborting load\n");
 		goto error;
 	}
+
+	if (sip_initialize_sorcery()) {
+		ast_log(LOG_ERROR, "Failed to initialize SIP sorcery. Aborting load\n");
+		goto error;
+	}
+
+	ast_sorcery_load(sip_sorcery);
+
 	if (start_transports()) {
 		ast_log(LOG_ERROR, "Failed to start SIP transports. Aborting load\n");
 		goto error;
@@ -584,6 +623,8 @@
 	return AST_MODULE_LOAD_SUCCESS;
 
 error:
+	ast_sorcery_unref(sip_sorcery);
+
 	if (monitor_thread) {
 		stop_monitor_thread();
 	}
@@ -598,8 +639,17 @@
 	return AST_MODULE_LOAD_DECLINE;
 }
 
+static int reload_module(void)
+{
+	if (sip_sorcery) {
+		ast_sorcery_reload(sip_sorcery);
+	}
+	return 0;
+}
+
 static int unload_module(void)
 {
+	ast_sorcery_unref(sip_sorcery);
 	if (monitor_thread) {
 		stop_monitor_thread();
 	}
@@ -616,5 +666,6 @@
 AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_GLOBAL_SYMBOLS | AST_MODFLAG_LOAD_ORDER, "Basic SIP resource",
 		.load = load_module,
 		.unload = unload_module,
+		.reload = reload_module,
 		.load_pri = AST_MODPRI_APP_DEPEND,
 	       );




More information about the asterisk-commits mailing list