[asterisk-commits] kharwell: trunk r398140 - in /trunk: ./ include/asterisk/ main/ res/ res/res_...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Aug 30 14:55:58 CDT 2013


Author: kharwell
Date: Fri Aug 30 14:55:56 2013
New Revision: 398140

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=398140
Log:
Add a reloadable option for sorcery type objects

Some configuration objects currently won't place nice if reloaded.
Specifically, in this case the pjsip transport objects.  Now when
registering an object in sorcery one may specify that the object is
allowed to be reloaded or not.  If the object is set to not reload
then upon reloading of the configuration the objects of that type
will not be reloaded.  The initially loaded objects of that type
however will remain.

While the transport objects will not longer be reloaded it is still
possible for a user to configure an endpoint to an invalid transport.
A couple of log messages were added to help diagnose this problem if
it occurs.

(closes issue ASTERISK-22382)
Reported by: Rusty Newton
(closes issue ASTERISK-22384)
Reported by: Rusty Newton
Review: https://reviewboard.asterisk.org/r/2807/
........

Merged revisions 398139 from http://svn.asterisk.org/svn/asterisk/branches/12

Modified:
    trunk/   (props changed)
    trunk/include/asterisk/sorcery.h
    trunk/main/sorcery.c
    trunk/res/res_pjsip.c
    trunk/res/res_pjsip/config_transport.c
    trunk/res/res_pjsip_outbound_registration.c

Propchange: trunk/
------------------------------------------------------------------------------
--- branch-12-merged (original)
+++ branch-12-merged Fri Aug 30 14:55:56 2013
@@ -1,1 +1,1 @@
-/branches/12:1-397989,398002,398016,398020,398023,398025,398062,398068,398100,398116
+/branches/12:1-397989,398002,398016,398020,398023,398025,398062,398068,398100,398116,398139

Modified: trunk/include/asterisk/sorcery.h
URL: http://svnview.digium.com/svn/asterisk/trunk/include/asterisk/sorcery.h?view=diff&rev=398140&r1=398139&r2=398140
==============================================================================
--- trunk/include/asterisk/sorcery.h (original)
+++ trunk/include/asterisk/sorcery.h Fri Aug 30 14:55:56 2013
@@ -356,7 +356,7 @@
  * \retval 0 success
  * \retval -1 failure
  */
-int __ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, unsigned int hidden, aco_type_item_alloc alloc, sorcery_transform_handler transform, sorcery_apply_handler apply);
+int __ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, unsigned int hidden, unsigned int reloadable, aco_type_item_alloc alloc, sorcery_transform_handler transform, sorcery_apply_handler apply);
 
 /*!
  * \brief Register an object type
@@ -371,10 +371,10 @@
  * \retval -1 failure
  */
 #define ast_sorcery_object_register(sorcery, type, alloc, transform, apply) \
-	__ast_sorcery_object_register((sorcery), (type), 0, (alloc), (transform), (apply))
-
-/*!
- * \brief Register an internal, hidden object type
+	__ast_sorcery_object_register((sorcery), (type), 0, 1, (alloc), (transform), (apply))
+
+/*!
+ * \brief Register an object type that is not reloadable
  *
  * \param sorcery Pointer to a sorcery structure
  * \param type Type of object
@@ -385,8 +385,23 @@
  * \retval 0 success
  * \retval -1 failure
  */
+#define ast_sorcery_object_register_no_reload(sorcery, type, alloc, transform, apply) \
+	__ast_sorcery_object_register((sorcery), (type), 0, 0, (alloc), (transform), (apply))
+
+/*!
+ * \brief Register an internal, hidden object type
+ *
+ * \param sorcery Pointer to a sorcery structure
+ * \param type Type of object
+ * \param alloc Required object allocation callback
+ * \param transform Optional transformation callback
+ * \param apply Optional object set apply callback
+ *
+ * \retval 0 success
+ * \retval -1 failure
+ */
 #define ast_sorcery_internal_object_register(sorcery, type, alloc, transform, apply) \
-	__ast_sorcery_object_register((sorcery), (type), 1, (alloc), (transform), (apply))
+	__ast_sorcery_object_register((sorcery), (type), 1, 1, (alloc), (transform), (apply))
 
 /*!
  * \brief Set the copy handler for an object type

Modified: trunk/main/sorcery.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/sorcery.c?view=diff&rev=398140&r1=398139&r2=398140
==============================================================================
--- trunk/main/sorcery.c (original)
+++ trunk/main/sorcery.c Fri Aug 30 14:55:56 2013
@@ -110,6 +110,9 @@
 
 	/*! \brief Serializer for observers */
 	struct ast_taskprocessor *serializer;
+
+	/*! \brief Specifies if object type is reloadable or not */
+	unsigned int reloadable:1;
 };
 
 /*! \brief Structure for registered object type observer */
@@ -575,7 +578,7 @@
 	return 0;
 }
 
-int __ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, unsigned int hidden, aco_type_item_alloc alloc, sorcery_transform_handler transform, sorcery_apply_handler apply)
+int __ast_sorcery_object_register(struct ast_sorcery *sorcery, const char *type, unsigned int hidden, unsigned int reloadable, aco_type_item_alloc alloc, sorcery_transform_handler transform, sorcery_apply_handler apply)
 {
 	RAII_VAR(struct ast_sorcery_object_type *, object_type, ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
 
@@ -589,6 +592,7 @@
 	object_type->type.item_alloc = alloc;
 	object_type->type.hidden = hidden;
 
+	object_type->reloadable = reloadable;
 	object_type->transform = transform;
 	object_type->apply = apply;
 	object_type->file->types[0] = &object_type->type;
@@ -695,11 +699,25 @@
 	return 0;
 }
 
+/*! \brief Retrieves whether or not the type is reloadable */
+static int sorcery_reloadable(const struct ast_sorcery *sorcery, const char *type)
+{
+	RAII_VAR(struct ast_sorcery_object_type *, object_type,
+		 ao2_find(sorcery->types, type, OBJ_KEY), ao2_cleanup);
+	return object_type && object_type->reloadable;
+}
+
 static int sorcery_wizard_load(void *obj, void *arg, int flags)
 {
 	struct ast_sorcery_object_wizard *wizard = obj;
 	struct sorcery_load_details *details = arg;
 	void (*load)(void *data, const struct ast_sorcery *sorcery, const char *type);
+
+	if (details->reload && !sorcery_reloadable(details->sorcery, details->type)) {
+		ast_log(LOG_NOTICE, "Type '%s' is not reloadable, "
+			"maintaining previous values\n", details->type);
+		return 0;
+	}
 
 	load = !details->reload ? wizard->wizard->load : wizard->wizard->reload;
 

Modified: trunk/res/res_pjsip.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip.c?view=diff&rev=398140&r1=398139&r2=398140
==============================================================================
--- trunk/res/res_pjsip.c (original)
+++ trunk/res/res_pjsip.c Fri Aug 30 14:55:56 2013
@@ -1290,6 +1290,8 @@
 	transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_name);
 
 	if (!transport || !transport->state) {
+		ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport '%s' for endpoint '%s'\n",
+			transport_name, ast_sorcery_object_get_id(endpoint));
 		return -1;
 	}
 

Modified: trunk/res/res_pjsip/config_transport.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip/config_transport.c?view=diff&rev=398140&r1=398139&r2=398140
==============================================================================
--- trunk/res/res_pjsip/config_transport.c (original)
+++ trunk/res/res_pjsip/config_transport.c Fri Aug 30 14:55:56 2013
@@ -309,7 +309,7 @@
 {
 	ast_sorcery_apply_default(sorcery, "transport", "config", "pjsip.conf,criteria=type=transport");
 
-	if (ast_sorcery_object_register(sorcery, "transport", transport_alloc, NULL, transport_apply)) {
+	if (ast_sorcery_object_register_no_reload(sorcery, "transport", transport_alloc, NULL, transport_apply)) {
 		return -1;
 	}
 

Modified: trunk/res/res_pjsip_outbound_registration.c
URL: http://svnview.digium.com/svn/asterisk/trunk/res/res_pjsip_outbound_registration.c?view=diff&rev=398140&r1=398139&r2=398140
==============================================================================
--- trunk/res/res_pjsip_outbound_registration.c (original)
+++ trunk/res/res_pjsip_outbound_registration.c Fri Aug 30 14:55:56 2013
@@ -602,6 +602,8 @@
 		RAII_VAR(struct ast_sip_transport *, transport, ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", registration->transport), ao2_cleanup);
 
 		if (!transport || !transport->state) {
+			ast_log(LOG_ERROR, "Unable to retrieve PJSIP transport '%s' "
+				" for outbound registration", registration->transport);
 			return -1;
 		}
 




More information about the asterisk-commits mailing list