[Freeswitch-svn] [commit] r12469 - in freeswitch/trunk/src: . include mod/applications/mod_skel

FreeSWITCH SVN mrene at freeswitch.org
Thu Mar 5 12:18:27 PST 2009


Author: mrene
Date: Thu Mar  5 14:18:27 2009
New Revision: 12469

Log:
replace reloadable bool by a flags structure and add required flag

Modified:
   freeswitch/trunk/src/include/switch_xml_config.h
   freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c
   freeswitch/trunk/src/switch_xml_config.c

Modified: freeswitch/trunk/src/include/switch_xml_config.h
==============================================================================
--- freeswitch/trunk/src/include/switch_xml_config.h	(original)
+++ freeswitch/trunk/src/include/switch_xml_config.h	Thu Mar  5 14:18:27 2009
@@ -58,6 +58,8 @@
 	char *validation_regex;			/*< Enforce validation using this regular expression */
 } switch_xml_config_string_options_t;
 
+extern switch_xml_config_string_options_t switch_config_string_strdup; 	/*< String options structure for strdup, no validation */
+
 typedef struct {
 	switch_bool_t enforce_min;
 	int min;
@@ -74,6 +76,11 @@
 	CONFIG_SHUTDOWN
 } switch_config_callback_type_t;
 
+typedef enum {
+	CONFIG_RELOADABLE = (1 << 0),
+	CONFIG_REQUIRED = (1 << 1)
+} switch_config_flags_t;
+
 typedef switch_status_t (*switch_xml_config_callback_t)(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed);
 
 /*!
@@ -82,16 +89,16 @@
 struct switch_xml_config_item {
 	char *key;					   			/*< The key of the element, or NULL to indicate the end of the list */
 	switch_xml_config_type_t type; 			/*< The type of variable */
-	switch_bool_t reloadable; 	   			/*< True if the var can be changed on reload */
+	switch_config_flags_t flags; 	   		/*< True if the var can be changed on reload */
 	void *ptr;					   			/*< Ptr to the var to be changed */
 	void *defaultvalue; 		   			/*< Default value */
 	void *data; 				   			/*< Custom data (depending on the type) */
 	switch_xml_config_callback_t function;	/*< Callback to be called after the var is parsed */
-} ;
-
+};
 
-#define SWITCH_CONFIG_ITEM(_key, _type, _reloadable, _ptr, _defaultvalue, _data)	{ _key, _type, _reloadable, _ptr, _defaultvalue, _data, NULL }
-#define SWITCH_CONFIG_ITEM_CALLBACK(_key, _type, _reloadable, _ptr, _defaultvalue, _data, _functiondata)	{ _key, _type, _reloadable, _ptr, _defaultvalue, _functiondata, _data }
+#define SWITCH_CONFIG_ITEM(_key, _type, _flags, _ptr, _defaultvalue, _data)	{ _key, _type, _flags, _ptr, _defaultvalue, _data, NULL }
+#define SWITCH_CONFIG_ITEM_STRING_STRDUP(_key, _flags, _ptr, _defaultvalue)	{ _key, SWITCH_CONFIG_STRING, _flags, _ptr, _defaultvalue, &switch_config_string_strdup, NULL }
+#define SWITCH_CONFIG_ITEM_CALLBACK(_key, _type, _flags, _ptr, _defaultvalue, _data, _functiondata)	{ _key, _type, _flags, _ptr, _defaultvalue, _functiondata, _data }
 #define SWITCH_CONFIG_ITEM_END() { NULL, SWITCH_CONFIG_LAST, 0, NULL ,NULL, NULL, NULL }
 
 /*! 

Modified: freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_skel/mod_skel.c	Thu Mar  5 14:18:27 2009
@@ -83,10 +83,10 @@
 
 static switch_xml_config_item_t instructions[] = {
 	/* parameter name        type                 reloadable   pointer                         default value     options structure */
-	SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, SWITCH_TRUE, &globals.codec_negotiation_str, "greedy", &config_opt_codec_negotiation),
-	SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, SWITCH_TRUE, &globals.codec_negotiation,  (void*)CODEC_NEGOTIATION_GREEDY, &config_opt_codec_negotiation_enum),
-	SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, SWITCH_TRUE, &globals.sip_trace,  (void*)SWITCH_FALSE,  config_callback_siptrace, NULL ),
-	SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, SWITCH_FALSE, &globals.integer, (void*)100, &config_opt_integer),
+	SWITCH_CONFIG_ITEM("codec-negotiation-str", SWITCH_CONFIG_STRING, CONFIG_RELOADABLE, &globals.codec_negotiation_str, "greedy", &config_opt_codec_negotiation),
+	SWITCH_CONFIG_ITEM("codec-negotiation", SWITCH_CONFIG_ENUM, CONFIG_RELOADABLE, &globals.codec_negotiation,  (void*)CODEC_NEGOTIATION_GREEDY, &config_opt_codec_negotiation_enum),
+	SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.sip_trace,  (void*)SWITCH_FALSE,  config_callback_siptrace, NULL ),
+	SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE | CONFIG_REQUIRED, &globals.integer, (void*)100, &config_opt_integer),
 	SWITCH_CONFIG_ITEM_END()
 };
 

Modified: freeswitch/trunk/src/switch_xml_config.c
==============================================================================
--- freeswitch/trunk/src/switch_xml_config.c	(original)
+++ freeswitch/trunk/src/switch_xml_config.c	Thu Mar  5 14:18:27 2009
@@ -32,6 +32,8 @@
 
 #include <switch.h>
 
+switch_xml_config_string_options_t switch_config_string_strdup = { NULL, 0, NULL };
+
 SWITCH_DECLARE(switch_size_t) switch_event_import_xml(switch_xml_t xml, const char *keyname, const char *valuename, switch_event_t **event)
 {
 	switch_xml_t node;
@@ -79,10 +81,15 @@
 		switch_bool_t changed = SWITCH_FALSE;
 		switch_xml_config_callback_t callback = (switch_xml_config_callback_t)item->function;
 		
-		if (reload && !item->reloadable) {
+		if (reload && !switch_test_flag(item, CONFIG_RELOADABLE)) {
 			continue;
 		}
 		
+		if (!value && switch_test_flag(item, CONFIG_REQUIRED)) {
+			switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Required parameter [%s] is missing\n", item->key);
+			return SWITCH_STATUS_FALSE;
+		}
+		
 		switch(item->type) {
 			case SWITCH_CONFIG_INT:
 				{



More information about the Freeswitch-svn mailing list