]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
replace reloadable bool by a flags structure and add required flag
authorMathieu Rene <mrene@avgs.ca>
Thu, 5 Mar 2009 20:18:27 +0000 (20:18 +0000)
committerMathieu Rene <mrene@avgs.ca>
Thu, 5 Mar 2009 20:18:27 +0000 (20:18 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12469 d0543943-73ff-0310-b7d9-9358b9ac24b2

src/include/switch_xml_config.h
src/mod/applications/mod_skel/mod_skel.c
src/switch_xml_config.c

index 83c6af75e1888e275b3681569be3d57d57698c89..6e4317b4cf670816b6c34c8eeb56c73d7547ab8c 100644 (file)
@@ -58,6 +58,8 @@ typedef struct {
        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 @@ typedef enum {
        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 @@ typedef switch_status_t (*switch_xml_config_callback_t)(switch_xml_config_item_t
 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 }
 
 /*! 
index af4ea0bbb5cb4847a4d4694b72f2af3d8d1c5953..39293f03b29195d87a5d5fc9fc41e649195542ae 100644 (file)
@@ -83,10 +83,10 @@ static switch_xml_config_enum_item_t config_opt_codec_negotiation_enum[] = {
 
 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()
 };
 
index 8b00540c18299f01badebc9d43e382023eccb366..898933faa0639b4b68826ef7a215341b23f78c21 100644 (file)
@@ -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_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
                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:
                                {