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

FreeSWITCH SVN mrene at freeswitch.org
Fri Jun 19 20:32:29 PDT 2009


Author: mrene
Date: Fri Jun 19 22:32:29 2009
New Revision: 13878

Log:
Implement new config parser in mod_voicemail

Modified:
   freeswitch/trunk/src/include/switch_console.h
   freeswitch/trunk/src/include/switch_core.h
   freeswitch/trunk/src/include/switch_xml_config.h
   freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c
   freeswitch/trunk/src/switch_console.c
   freeswitch/trunk/src/switch_ivr_async.c
   freeswitch/trunk/src/switch_xml_config.c

Modified: freeswitch/trunk/src/include/switch_console.h
==============================================================================
--- freeswitch/trunk/src/include/switch_console.h	(original)
+++ freeswitch/trunk/src/include/switch_console.h	Fri Jun 19 22:32:29 2009
@@ -74,6 +74,8 @@
 SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt, ...) PRINTF_FUNCTION(2, 3);
 #endif
 
+SWITCH_DECLARE(switch_status_t) switch_stream_write_file_contents(switch_stream_handle_t *stream, const char *path);
+
 SWITCH_END_EXTERN_C
 #endif
 /* For Emacs:

Modified: freeswitch/trunk/src/include/switch_core.h
==============================================================================
--- freeswitch/trunk/src/include/switch_core.h	(original)
+++ freeswitch/trunk/src/include/switch_core.h	Fri Jun 19 22:32:29 2009
@@ -134,7 +134,7 @@
   \param session the session to add the bug to
   \param callback a callback for events
   \param user_data arbitrary user data
-  \param stop_time absolute time at which the bug is automatically removed
+  \param stop_time absolute time at which the bug is automatically removed (or 0)
   \param flags flags to choose the stream
   \param new_bug pointer to assign new bug to
   \return SWITCH_STATUS_SUCCESS if the operation was a success

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	Fri Jun 19 22:32:29 2009
@@ -81,21 +81,21 @@
 	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);
+typedef switch_status_t (*switch_xml_config_callback_t)(switch_xml_config_item_t *item, const char *newvalue, switch_config_callback_type_t callback_type, switch_bool_t changed);
 
 /*!
  * \brief A configuration instruction read by switch_xml_config_parse 
 */
 struct switch_xml_config_item {
-	const char *key;					   			/*< The key of the element, or NULL to indicate the end of the list */
+	const 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 */
-	int flags; 	   		/*< True if the var can be changed on reload */
+	int flags; 	   							/*< True if the var can be changed on reload */
 	void *ptr;					   			/*< Ptr to the var to be changed */
-	const void *defaultvalue; 		   			/*< Default value */
+	const 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 */
-	const char *syntax;							/*< Optional syntax documentation for this setting */
-	const char *helptext;							/*< Optional documentation text for this setting */
+	const char *syntax;						/*< Optional syntax documentation for this setting */
+	const char *helptext;					/*< Optional documentation text for this setting */
 };
 
 #define SWITCH_CONFIG_ITEM(_key, _type, _flags, _ptr, _defaultvalue, _data, _syntax, _helptext)	{ _key, _type, _flags, _ptr, (void*)_defaultvalue, (void*)_data, NULL, _syntax, _helptext }
@@ -103,26 +103,22 @@
 #define SWITCH_CONFIG_ITEM_CALLBACK(_key, _type, _flags, _ptr, _defaultvalue, _function, _functiondata, _syntax, _helptext)	{ _key, _type, _flags, _ptr, (void*)_defaultvalue, _functiondata, _function, _syntax, _helptext }
 #define SWITCH_CONFIG_ITEM_END() { NULL, SWITCH_CONFIG_LAST, 0, NULL, NULL, NULL, NULL, NULL, NULL }
 
-#define SWITCH_CONFIG_SET_ITEM(_item, _key, _type, _flags, _ptr, _defaultvalue, _data, _syntax, _helptext)  \
-	_item.key = _key; \
-	_item.type = _type; \
-	_item.flags = _flags; \
-	_item.ptr = _ptr; \
-	_item.defaultvalue = (void*)_defaultvalue; \
-	_item.data = (void*)_data; \
-	_item.syntax = _syntax; \
-	_item.helptext = _helptext
-
-#define SWITCH_CONFIG_SET_ITEM_CALLBACK(_item, _key, _type, _flags, _ptr, _defaultvalue, _function, _syntax, _helptext)  \
-	_item.key = _key; \
-	_item.type = _type; \
-	_item.flags = _flags; \
-	_item.ptr = ptr; \
-	_item.defaultvalue = (void*)_defaultvalue; \
-	_item.data = (void*)_data; \
-	_item.function = _function \
-	_item.syntax = _syntax; \
-	_item.helptext = _helptext
+#define SWITCH_CONFIG_SET_ITEM(_item, _key, _type, _flags, _ptr, _defaultvalue, _data, _syntax, _helptext)  switch_config_perform_set_item(&(_item), _key, _type, _flags, _ptr, (void*)(_defaultvalue), _data, NULL, _syntax, _helptext)
+#define SWITCH_CONFIG_SET_ITEM_CALLBACK(_item, _key, _type, _flags, _ptr, _defaultvalue, _data, _function, _syntax, _helptext)  switch_config_perform_set_item(&(_item), _key, _type, _flags, _ptr, (void*)(_defaultvalue), _data, _function, _syntax, _helptext)
+
+inline void switch_config_perform_set_item(switch_xml_config_item_t *item, const char *key, switch_xml_config_type_t type, int flags, void *ptr, 	
+										const void* defaultvalue, void *data, switch_xml_config_callback_t function, const char *syntax, const char *helptext)
+{
+	item->key = key;
+	item->type = type;
+	item->flags = flags;
+	item->ptr = ptr;
+	item->defaultvalue = defaultvalue;
+	item->data = data;
+	item->function = function;
+	item->syntax = syntax;
+	item->helptext = helptext;
+}
 
 /*! 
  * \brief Gets the int representation of an enum

Modified: freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c
==============================================================================
--- freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	(original)
+++ freeswitch/trunk/src/mod/applications/mod_limit/mod_limit.c	Fri Jun 19 22:32:29 2009
@@ -376,7 +376,6 @@
 		
 		/* Remove handler */
 		switch_core_event_hook_remove_state_change(session, hash_state_handler);
-
 		
 		switch_mutex_unlock(globals.limit_hash_mutex);
 	}

Modified: freeswitch/trunk/src/switch_console.c
==============================================================================
--- freeswitch/trunk/src/switch_console.c	(original)
+++ freeswitch/trunk/src/switch_console.c	Fri Jun 19 22:32:29 2009
@@ -162,6 +162,30 @@
 	return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
 }
 
+SWITCH_DECLARE(switch_status_t) switch_stream_write_file_contents(switch_stream_handle_t *stream, const char *path)
+{
+	char *dpath = NULL;
+	int fd;
+	switch_status_t status = SWITCH_STATUS_FALSE;
+	
+	if (!switch_is_file_path(path)) {
+		dpath = switch_mprintf("%s%s%s", SWITCH_GLOBAL_dirs.conf_dir, SWITCH_PATH_SEPARATOR, path);
+		path = dpath;
+	}
+	
+	if ((fd = open(path, O_RDONLY)) > -1) {
+		char buf[2048] = { 0 };
+		while (switch_fd_read_line(fd, buf, sizeof(buf))) {
+			stream->write_function(stream, "%s", buf);
+		}
+		close(fd);
+		status = SWITCH_STATUS_SUCCESS;
+	}
+	
+	switch_safe_free(dpath);
+	return status;
+}
+
 static int alias_callback(void *pArg, int argc, char **argv, char **columnNames)
 {
 	char **r = (char **) pArg;

Modified: freeswitch/trunk/src/switch_ivr_async.c
==============================================================================
--- freeswitch/trunk/src/switch_ivr_async.c	(original)
+++ freeswitch/trunk/src/switch_ivr_async.c	Fri Jun 19 22:32:29 2009
@@ -392,10 +392,6 @@
 		return SWITCH_STATUS_GENERR;
 	}
 
-	if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
-		return SWITCH_STATUS_FALSE;
-	}
-
 	if (limit) {
 		to = switch_epoch_time_now(NULL) + limit;
 	}

Modified: freeswitch/trunk/src/switch_xml_config.c
==============================================================================
--- freeswitch/trunk/src/switch_xml_config.c	(original)
+++ freeswitch/trunk/src/switch_xml_config.c	Fri Jun 19 22:32:29 2009
@@ -142,8 +142,9 @@
 		const char *value = switch_event_get_header(event, item->key);
 		switch_bool_t changed = SWITCH_FALSE;
 		switch_xml_config_callback_t callback = (switch_xml_config_callback_t)item->function;
+		void *ptr = item->ptr;
 		
-		switch_assert(item->ptr);
+		//switch_assert(ptr);
 		
 		if (value) {
 			matched_count++;
@@ -162,7 +163,7 @@
 			case SWITCH_CONFIG_INT:
 				{
 					switch_xml_config_int_options_t *int_options = (switch_xml_config_int_options_t*)item->data;
-					int *dest = (int*)item->ptr;
+					int *dest = (int*)ptr;
 					int intval;
 					if (value) {
 						if (switch_is_number(value)) {
@@ -229,7 +230,7 @@
 
 					if (string_options->length > 0) {
 						/* We have a preallocated buffer */
-						char *dest = (char*)item->ptr;
+						char *dest = (char*)ptr;
 						
 						if (newstring) {
 							if (strncasecmp(dest, newstring, string_options->length)) {
@@ -244,7 +245,7 @@
 						}
 					} else if (string_options->pool) {
 						/* Pool-allocated buffer */
-						char **dest = (char**)item->ptr;
+						char **dest = (char**)ptr;
 						
 						if (newstring) {
 							if (!*dest || strcmp(*dest, newstring)) {
@@ -258,7 +259,7 @@
 						}
 					} else {
 						/* Dynamically allocated buffer */
-						char **dest = (char**)item->ptr;
+						char **dest = (char**)ptr;
 						
 						if (newstring) {
 							if (!*dest || strcmp(*dest, newstring)) {
@@ -277,7 +278,7 @@
 				break;
 			case SWITCH_CONFIG_BOOL:
 				{
-					switch_bool_t *dest = (switch_bool_t*)item->ptr;
+					switch_bool_t *dest = (switch_bool_t*)ptr;
 					switch_bool_t newval = SWITCH_FALSE;
 					
 					if (value && switch_true(value)) {
@@ -305,7 +306,7 @@
 			case SWITCH_CONFIG_ENUM:
 				{
 					switch_xml_config_enum_item_t *enum_options = (switch_xml_config_enum_item_t*)item->data;
-					int *dest = (int*)item->ptr;
+					int *dest = (int*)ptr;
 					int newval = 0;
 					switch_status_t lookup_result = SWITCH_STATUS_SUCCESS;
 					
@@ -329,7 +330,7 @@
 				break;
 			case SWITCH_CONFIG_FLAG:
 				{
-					int32_t *dest = (int32_t*)item->ptr;
+					int32_t *dest = (int32_t*)ptr;
 					int index = (int)(intptr_t)item->data;
 					int8_t currentval = (int8_t)!!(*dest & index);
 					int8_t newval = 0;
@@ -352,7 +353,7 @@
 				break;
 			case SWITCH_CONFIG_FLAGARRAY:
 				{
-					int8_t *dest = (int8_t*)item->ptr;
+					int8_t *dest = (int8_t*)ptr;
 					unsigned int index = (unsigned int)(intptr_t)item->data;
 					int8_t newval = value ? !!switch_true(value) : (int8_t)((intptr_t)item->defaultvalue);
 					if (dest[index] != newval) {
@@ -368,7 +369,7 @@
 		}
 		
 		if (callback) {
-			callback(item, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed);
+			callback(item, value, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed);
 		}
 	}
 
@@ -418,7 +419,7 @@
 		}
 		
 		if (callback) {
-			callback(item, CONFIG_SHUTDOWN, SWITCH_FALSE);
+			callback(item, NULL, CONFIG_SHUTDOWN, SWITCH_FALSE);
 		}
 		
 	}



More information about the Freeswitch-svn mailing list