diff --git a/src/include/switch_console.h b/src/include/switch_console.h index 075f7e4c42..806459cb47 100644 --- a/src/include/switch_console.h +++ b/src/include/switch_console.h @@ -74,6 +74,8 @@ SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_raw_write(switch_st 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: diff --git a/src/include/switch_core.h b/src/include/switch_core.h index 53bc92835f..2f987ef3b4 100644 --- a/src/include/switch_core.h +++ b/src/include/switch_core.h @@ -134,7 +134,7 @@ SWITCH_DECLARE(void) switch_core_session_disable_heartbeat(switch_core_session_t \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 diff --git a/src/include/switch_xml_config.h b/src/include/switch_xml_config.h index 9f791f38d1..eac9da0763 100644 --- a/src/include/switch_xml_config.h +++ b/src/include/switch_xml_config.h @@ -81,21 +81,21 @@ typedef enum { 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 @@ struct switch_xml_config_item { #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(_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) -#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 +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 diff --git a/src/mod/applications/mod_limit/mod_limit.c b/src/mod/applications/mod_limit/mod_limit.c index 4e6b341a90..bde5a9eacb 100644 --- a/src/mod/applications/mod_limit/mod_limit.c +++ b/src/mod/applications/mod_limit/mod_limit.c @@ -376,7 +376,6 @@ static switch_status_t hash_state_handler(switch_core_session_t *session) /* Remove handler */ switch_core_event_hook_remove_state_change(session, hash_state_handler); - switch_mutex_unlock(globals.limit_hash_mutex); } diff --git a/src/switch_console.c b/src/switch_console.c index 06dd0be18d..76dc68bfdf 100644 --- a/src/switch_console.c +++ b/src/switch_console.c @@ -162,6 +162,30 @@ SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream 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; diff --git a/src/switch_ivr_async.c b/src/switch_ivr_async.c index cb2cc2b1e2..90692ad60b 100644 --- a/src/switch_ivr_async.c +++ b/src/switch_ivr_async.c @@ -392,10 +392,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_ 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; } diff --git a/src/switch_xml_config.c b/src/switch_xml_config.c index a013e34921..d2ce9e6d24 100644 --- a/src/switch_xml_config.c +++ b/src/switch_xml_config.c @@ -142,8 +142,9 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev } } 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev } } else { /* Dynamically allocated buffer */ - char **dest = (char**)item->ptr; + char **dest = (char**)ptr; if (newstring) { if (!*dest || strcmp(*dest, newstring)) { @@ -277,7 +278,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev 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 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev } if (callback) { - callback(item, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed); + callback(item, value, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed); } } @@ -418,7 +419,7 @@ SWITCH_DECLARE(void) switch_xml_config_cleanup(switch_xml_config_item_t *instruc } if (callback) { - callback(item, CONFIG_SHUTDOWN, SWITCH_FALSE); + callback(item, NULL, CONFIG_SHUTDOWN, SWITCH_FALSE); } }