]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
Lets make the parser free its stuff on shutdown, and let the callbacks do something...
authorMathieu Rene <mrene@avgs.ca>
Thu, 5 Mar 2009 16:57:26 +0000 (16:57 +0000)
committerMathieu Rene <mrene@avgs.ca>
Thu, 5 Mar 2009 16:57:26 +0000 (16:57 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@12467 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 719d45bc348e78c9c5d8f1cbbbecf0713099b562..83c6af75e1888e275b3681569be3d57d57698c89 100644 (file)
@@ -68,7 +68,13 @@ typedef struct {
 struct switch_xml_config_item;
 typedef struct switch_xml_config_item switch_xml_config_item_t;
 
-typedef switch_status_t (*switch_xml_config_callback_t)(switch_xml_config_item_t *data, switch_bool_t changed);
+typedef enum {
+       CONFIG_LOAD,
+       CONFIG_RELOAD,
+       CONFIG_SHUTDOWN
+} switch_config_callback_type_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);
 
 /*!
  * \brief A configuration instruction read by switch_xml_config_parse 
@@ -114,6 +120,13 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
  * \param event [out] event (if *event is NOT NULL, the headers will be appended to the existing event)
  */
 SWITCH_DECLARE(switch_size_t) switch_event_import_xml(switch_xml_t xml, const char *keyname, const char *valuename, switch_event_t **event);
+
+
+/*!
+ * \brief Free any memory allocated by the configuration
+ * \param instructions instrutions on how to parse the elements
+ */
+SWITCH_DECLARE(void) switch_xml_config_cleanup(switch_xml_config_item_t *instructions);
 #endif /* !defined(SWITCH_XML_CONFIG_H) */
 
 /* For Emacs:
index f796d6291b7d461d9b446bacc6ba14bf59a2ef90..af4ea0bbb5cb4847a4d4694b72f2af3d8d1c5953 100644 (file)
@@ -55,14 +55,15 @@ static struct {
        int integer;
 } globals;
 
-static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_bool_t changed) 
+static switch_status_t config_callback_siptrace(switch_xml_config_item_t *data, switch_config_callback_type_t callback_type, switch_bool_t changed) 
 {
        switch_bool_t value = *(switch_bool_t*)data->ptr;
        switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "In siptrace callback: value %s changed %s\n",
                value ? "true" : "false", changed ? "true" : "false");
        
+       
        /*
-       if (changed) {
+       if ((callback_type == CONFIG_LOG || callback_type == CONFIG_RELOAD) && changed) {
                nua_set_params(((sofia_profile_t*)data->functiondata)->nua, TPTAG_LOG(value), TAG_END());
        } 
        */
@@ -143,6 +144,8 @@ SWITCH_MODULE_LOAD_FUNCTION(mod_skel_load)
   Macro expands to: switch_status_t mod_skel_shutdown() */
 SWITCH_MODULE_SHUTDOWN_FUNCTION(mod_skel_shutdown)
 {
+       /* Cleanup dynamically allocated config settings */
+       switch_xml_config_cleanup(instructions);
        return SWITCH_STATUS_SUCCESS;
 }
 
index ed9e2f20a383518211ffd64e73ddd31a07f25d21..8b00540c18299f01badebc9d43e382023eccb366 100644 (file)
@@ -273,7 +273,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
                }
                
                if (callback) {
-                       callback(item, changed);
+                       callback(item, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed);
                }
        }
        
@@ -299,6 +299,36 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
        return SWITCH_STATUS_SUCCESS;
 }
 
+
+SWITCH_DECLARE(void) switch_xml_config_cleanup(switch_xml_config_item_t *instructions)
+{
+       switch_xml_config_item_t *item;
+       
+       for (item = instructions; item->key; item++) {
+               switch_xml_config_callback_t callback = (switch_xml_config_callback_t)item->function;
+               
+               switch (item->type) {
+                       case SWITCH_CONFIG_STRING:
+                               {
+                                       char **ptr = (char**)item->ptr;
+                                       switch_xml_config_string_options_t *string_options = (switch_xml_config_string_options_t*)item->data;
+                                       /* if (using_strdup) */
+                                       if (string_options && !string_options->pool && !string_options->length) {
+                                               switch_safe_free(*ptr);
+                                       }
+                               }
+                               break;
+                       default:
+                               break;
+               }
+               
+               if (callback) {
+                       callback(item, CONFIG_SHUTDOWN, SWITCH_FALSE);
+               }
+               
+       }
+}
+
 /* For Emacs:
  * Local Variables:
  * mode:c