mirror of
https://github.com/signalwire/freeswitch.git
synced 2025-04-17 09:12:25 +00:00
Implement new config parser in mod_voicemail
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@13878 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
parent
786c7710f1
commit
ca5bc07f48
@ -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);
|
SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream_handle_t *handle, const char *fmt, ...) PRINTF_FUNCTION(2, 3);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
SWITCH_DECLARE(switch_status_t) switch_stream_write_file_contents(switch_stream_handle_t *stream, const char *path);
|
||||||
|
|
||||||
SWITCH_END_EXTERN_C
|
SWITCH_END_EXTERN_C
|
||||||
#endif
|
#endif
|
||||||
/* For Emacs:
|
/* For Emacs:
|
||||||
|
@ -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 session the session to add the bug to
|
||||||
\param callback a callback for events
|
\param callback a callback for events
|
||||||
\param user_data arbitrary user data
|
\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 flags flags to choose the stream
|
||||||
\param new_bug pointer to assign new bug to
|
\param new_bug pointer to assign new bug to
|
||||||
\return SWITCH_STATUS_SUCCESS if the operation was a success
|
\return SWITCH_STATUS_SUCCESS if the operation was a success
|
||||||
|
@ -81,21 +81,21 @@ typedef enum {
|
|||||||
CONFIG_REQUIRED = (1 << 1)
|
CONFIG_REQUIRED = (1 << 1)
|
||||||
} switch_config_flags_t;
|
} 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
|
* \brief A configuration instruction read by switch_xml_config_parse
|
||||||
*/
|
*/
|
||||||
struct switch_xml_config_item {
|
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 */
|
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 */
|
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) */
|
void *data; /*< Custom data (depending on the type) */
|
||||||
switch_xml_config_callback_t function; /*< Callback to be called after the var is parsed */
|
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 *syntax; /*< Optional syntax documentation for this setting */
|
||||||
const char *helptext; /*< Optional documentation text 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 }
|
#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_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_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) \
|
#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)
|
||||||
_item.key = _key; \
|
#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)
|
||||||
_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) \
|
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,
|
||||||
_item.key = _key; \
|
const void* defaultvalue, void *data, switch_xml_config_callback_t function, const char *syntax, const char *helptext)
|
||||||
_item.type = _type; \
|
{
|
||||||
_item.flags = _flags; \
|
item->key = key;
|
||||||
_item.ptr = ptr; \
|
item->type = type;
|
||||||
_item.defaultvalue = (void*)_defaultvalue; \
|
item->flags = flags;
|
||||||
_item.data = (void*)_data; \
|
item->ptr = ptr;
|
||||||
_item.function = _function \
|
item->defaultvalue = defaultvalue;
|
||||||
_item.syntax = _syntax; \
|
item->data = data;
|
||||||
_item.helptext = _helptext
|
item->function = function;
|
||||||
|
item->syntax = syntax;
|
||||||
|
item->helptext = helptext;
|
||||||
|
}
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* \brief Gets the int representation of an enum
|
* \brief Gets the int representation of an enum
|
||||||
|
@ -376,7 +376,6 @@ static switch_status_t hash_state_handler(switch_core_session_t *session)
|
|||||||
|
|
||||||
/* Remove handler */
|
/* Remove handler */
|
||||||
switch_core_event_hook_remove_state_change(session, hash_state_handler);
|
switch_core_event_hook_remove_state_change(session, hash_state_handler);
|
||||||
|
|
||||||
|
|
||||||
switch_mutex_unlock(globals.limit_hash_mutex);
|
switch_mutex_unlock(globals.limit_hash_mutex);
|
||||||
}
|
}
|
||||||
|
@ -162,6 +162,30 @@ SWITCH_DECLARE_NONSTD(switch_status_t) switch_console_stream_write(switch_stream
|
|||||||
return ret ? SWITCH_STATUS_FALSE : SWITCH_STATUS_SUCCESS;
|
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)
|
static int alias_callback(void *pArg, int argc, char **argv, char **columnNames)
|
||||||
{
|
{
|
||||||
char **r = (char **) pArg;
|
char **r = (char **) pArg;
|
||||||
|
@ -392,10 +392,6 @@ SWITCH_DECLARE(switch_status_t) switch_ivr_displace_session(switch_core_session_
|
|||||||
return SWITCH_STATUS_GENERR;
|
return SWITCH_STATUS_GENERR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (switch_channel_pre_answer(channel) != SWITCH_STATUS_SUCCESS) {
|
|
||||||
return SWITCH_STATUS_FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (limit) {
|
if (limit) {
|
||||||
to = switch_epoch_time_now(NULL) + limit;
|
to = switch_epoch_time_now(NULL) + limit;
|
||||||
}
|
}
|
||||||
|
@ -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);
|
const char *value = switch_event_get_header(event, item->key);
|
||||||
switch_bool_t changed = SWITCH_FALSE;
|
switch_bool_t changed = SWITCH_FALSE;
|
||||||
switch_xml_config_callback_t callback = (switch_xml_config_callback_t)item->function;
|
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) {
|
if (value) {
|
||||||
matched_count++;
|
matched_count++;
|
||||||
@ -162,7 +163,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
|
|||||||
case SWITCH_CONFIG_INT:
|
case SWITCH_CONFIG_INT:
|
||||||
{
|
{
|
||||||
switch_xml_config_int_options_t *int_options = (switch_xml_config_int_options_t*)item->data;
|
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;
|
int intval;
|
||||||
if (value) {
|
if (value) {
|
||||||
if (switch_is_number(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) {
|
if (string_options->length > 0) {
|
||||||
/* We have a preallocated buffer */
|
/* We have a preallocated buffer */
|
||||||
char *dest = (char*)item->ptr;
|
char *dest = (char*)ptr;
|
||||||
|
|
||||||
if (newstring) {
|
if (newstring) {
|
||||||
if (strncasecmp(dest, newstring, string_options->length)) {
|
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) {
|
} else if (string_options->pool) {
|
||||||
/* Pool-allocated buffer */
|
/* Pool-allocated buffer */
|
||||||
char **dest = (char**)item->ptr;
|
char **dest = (char**)ptr;
|
||||||
|
|
||||||
if (newstring) {
|
if (newstring) {
|
||||||
if (!*dest || strcmp(*dest, 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 {
|
} else {
|
||||||
/* Dynamically allocated buffer */
|
/* Dynamically allocated buffer */
|
||||||
char **dest = (char**)item->ptr;
|
char **dest = (char**)ptr;
|
||||||
|
|
||||||
if (newstring) {
|
if (newstring) {
|
||||||
if (!*dest || strcmp(*dest, 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;
|
break;
|
||||||
case SWITCH_CONFIG_BOOL:
|
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;
|
switch_bool_t newval = SWITCH_FALSE;
|
||||||
|
|
||||||
if (value && switch_true(value)) {
|
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:
|
case SWITCH_CONFIG_ENUM:
|
||||||
{
|
{
|
||||||
switch_xml_config_enum_item_t *enum_options = (switch_xml_config_enum_item_t*)item->data;
|
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;
|
int newval = 0;
|
||||||
switch_status_t lookup_result = SWITCH_STATUS_SUCCESS;
|
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;
|
break;
|
||||||
case SWITCH_CONFIG_FLAG:
|
case SWITCH_CONFIG_FLAG:
|
||||||
{
|
{
|
||||||
int32_t *dest = (int32_t*)item->ptr;
|
int32_t *dest = (int32_t*)ptr;
|
||||||
int index = (int)(intptr_t)item->data;
|
int index = (int)(intptr_t)item->data;
|
||||||
int8_t currentval = (int8_t)!!(*dest & index);
|
int8_t currentval = (int8_t)!!(*dest & index);
|
||||||
int8_t newval = 0;
|
int8_t newval = 0;
|
||||||
@ -352,7 +353,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
|
|||||||
break;
|
break;
|
||||||
case SWITCH_CONFIG_FLAGARRAY:
|
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;
|
unsigned int index = (unsigned int)(intptr_t)item->data;
|
||||||
int8_t newval = value ? !!switch_true(value) : (int8_t)((intptr_t)item->defaultvalue);
|
int8_t newval = value ? !!switch_true(value) : (int8_t)((intptr_t)item->defaultvalue);
|
||||||
if (dest[index] != newval) {
|
if (dest[index] != newval) {
|
||||||
@ -368,7 +369,7 @@ SWITCH_DECLARE(switch_status_t) switch_xml_config_parse_event(switch_event_t *ev
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (callback) {
|
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) {
|
if (callback) {
|
||||||
callback(item, CONFIG_SHUTDOWN, SWITCH_FALSE);
|
callback(item, NULL, CONFIG_SHUTDOWN, SWITCH_FALSE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user