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 }
#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
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;
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++;
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)) {
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)) {
}
} else if (string_options->pool) {
/* Pool-allocated buffer */
- char **dest = (char**)item->ptr;
+ char **dest = (char**)ptr;
if (newstring) {
if (!*dest || strcmp(*dest, newstring)) {
}
} else {
/* Dynamically allocated buffer */
- char **dest = (char**)item->ptr;
+ char **dest = (char**)ptr;
if (newstring) {
if (!*dest || strcmp(*dest, newstring)) {
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)) {
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;
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;
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) {
}
if (callback) {
- callback(item, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed);
+ callback(item, value, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed);
}
}
}
if (callback) {
- callback(item, CONFIG_SHUTDOWN, SWITCH_FALSE);
+ callback(item, NULL, CONFIG_SHUTDOWN, SWITCH_FALSE);
}
}