]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
xml_config: Fix issue where default NULL strings were ignored on reload
authorMathieu Rene <mrene@avgs.ca>
Thu, 16 Apr 2009 02:26:32 +0000 (02:26 +0000)
committerMathieu Rene <mrene@avgs.ca>
Thu, 16 Apr 2009 02:26:32 +0000 (02:26 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13052 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 92cb7b4e342fed92bbc407503f46632a1585b4a1..35bb0d7e75102a19c84f3f8ee5d5ba4136854133 100644 (file)
@@ -100,8 +100,8 @@ struct switch_xml_config_item {
 
 #define SWITCH_CONFIG_ITEM(_key, _type, _flags, _ptr, _defaultvalue, _data, _syntax, _helptext)        { _key, _type, _flags, _ptr, _defaultvalue, _data, NULL, _syntax, _helptext }
 #define SWITCH_CONFIG_ITEM_STRING_STRDUP(_key, _flags, _ptr, _defaultvalue, _syntax, _helptext)        { _key, SWITCH_CONFIG_STRING, _flags, _ptr, _defaultvalue, &switch_config_string_strdup, NULL, _helptext}
-#define SWITCH_CONFIG_ITEM_CALLBACK(_key, _type, _flags, _ptr, _defaultvalue, _data, _functiondata, _syntax, _helptext)        { _key, _type, _flags, _ptr, _defaultvalue, _functiondata, _data, _helptext}
-#define SWITCH_CONFIG_ITEM_END() { NULL, SWITCH_CONFIG_LAST, 0, NULL ,NULL, NULL, NULL, NULL, NULL }
+#define SWITCH_CONFIG_ITEM_CALLBACK(_key, _type, _flags, _ptr, _defaultvalue, _data, _functiondata, _syntax, _helptext)        { _key, _type, _flags, _ptr, _defaultvalue, _functiondata, _data, _syntax, _helptext }
+#define SWITCH_CONFIG_ITEM_END() { NULL, SWITCH_CONFIG_LAST, 0, NULLNULL, NULL, NULL, NULL, NULL }
 
 /*! 
  * \brief Gets the int representation of an enum
index a96204e7a21a733ed42a034a4caed75f3856ac0b..a9041407055e15b80e3b06fbf4756f01278edbc1 100644 (file)
@@ -89,7 +89,7 @@ static switch_xml_config_item_t instructions[] = {
                "greedy|generous|evil", "Specifies the codec negotiation scheme to be used."),
        SWITCH_CONFIG_ITEM_CALLBACK("sip-trace", SWITCH_CONFIG_BOOL, CONFIG_RELOADABLE, &globals.sip_trace,  (void*)SWITCH_FALSE,  config_callback_siptrace, NULL ,
                "yes|no", "If enabled, print out sip messages on the console."),
-       SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE | CONFIG_REQUIRED, &globals.integer, (void*)100, &config_opt_integer,
+       SWITCH_CONFIG_ITEM("integer", SWITCH_CONFIG_INT, CONFIG_RELOADABLE, &globals.integer, (void*)100, &config_opt_integer,
                NULL, NULL),
        SWITCH_CONFIG_ITEM_END()
 };
@@ -108,8 +108,8 @@ static switch_status_t do_config(switch_bool_t reload)
 
 SWITCH_STANDARD_API(skel_function)
 {
-       stream->write_function(stream, "+OK Reloading\n");
        do_config(SWITCH_TRUE);
+       
        return SWITCH_STATUS_SUCCESS;
 }
 
index 44266707b0f8dbea466915492fd606ba6aebbb13..79ea0082798dc9f1344b7bd81ab9902e47156a23 100644 (file)
@@ -232,27 +232,49 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
                                                newstring = (char*)item->defaultvalue;
                                        }
 
-                                       
-                                       if (newstring) {
-                                               if (string_options->length > 0) {
-                                                       /* We have a preallocated buffer */
-                                                       char *dest = (char*)item->ptr;
+                                       if (string_options->length > 0) {
+                                               /* We have a preallocated buffer */
+                                               char *dest = (char*)item->ptr;
                                                
+                                               if (newstring) {
                                                        if (strncasecmp(dest, newstring, string_options->length)) {
                                                                switch_copy_string(dest, newstring, string_options->length);
                                                                changed = SWITCH_TRUE;
                                                        }
                                                } else {
-                                                       char **dest = (char**)item->ptr;
+                                                       if (*dest != '\0') {
+                                                               *dest = '\0';
+                                                               changed = SWITCH_TRUE;
+                                                       }
+                                               }
+                                       } else if (string_options->pool) {
+                                               /* Pool-allocated buffer */
+                                               char **dest = (char**)item->ptr;
                                                
-                                                       if (!*dest || strcasecmp(*dest, newstring)) {
-                                                               if (string_options->pool) {
-                                                                       *dest = switch_core_strdup(string_options->pool, newstring);
-                                                               } else {
-                                                                       switch_safe_free(*dest);
-                                                                       *dest = strdup(newstring);
-                                                               }
-                                                               changed = SWITCH_TRUE;                                                          
+                                               if (newstring) {
+                                                       if (!*dest || strcmp(*dest, newstring)) {
+                                                               *dest = switch_core_strdup(string_options->pool, newstring);
+                                                       }
+                                               } else {
+                                                       if (*dest) {
+                                                               changed = SWITCH_TRUE;
+                                                               *dest = NULL;
+                                                       }
+                                               }
+                                       } else {
+                                               /* Dynamically allocated buffer */
+                                               char **dest = (char**)item->ptr;
+                                               
+                                               if (newstring) {
+                                                       if (!*dest || strcmp(*dest, newstring)) {
+                                                               switch_safe_free(*dest);
+                                                               *dest = strdup(newstring);
+                                                               changed = SWITCH_TRUE;                                          
+                                                       }       
+                                               } else {
+                                                       if (*dest) {
+                                                               switch_safe_free(*dest);
+                                                               changed = SWITCH_TRUE;
                                                        }
                                                }
                                        }