switch_xml_config.h File Reference

#include <switch.h>

Include dependency graph for switch_xml_config.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  switch_xml_config_enum_item_t
struct  switch_xml_config_string_options_t
struct  switch_xml_config_int_options_t
struct  switch_xml_config_item
 A configuration instruction read by switch_xml_config_parse. More...

Defines

#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_STRING_STRDUP(_key, _flags, _ptr, _defaultvalue, _syntax, _helptext)   { (_key), SWITCH_CONFIG_STRING, (_flags), (_ptr), ((void*)_defaultvalue), (NULL), (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)   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)

Typedefs

typedef switch_xml_config_item switch_xml_config_item_t
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)

Enumerations

enum  switch_xml_config_type_t {
  SWITCH_CONFIG_INT, SWITCH_CONFIG_STRING, SWITCH_CONFIG_BOOL, SWITCH_CONFIG_CUSTOM,
  SWITCH_CONFIG_ENUM, SWITCH_CONFIG_FLAG, SWITCH_CONFIG_FLAGARRAY, SWITCH_CONFIG_LAST
}
 Type of value to parse. More...
enum  switch_config_callback_type_t { CONFIG_LOAD, CONFIG_RELOAD, CONFIG_SHUTDOWN }
enum  switch_config_flags_t { CONFIG_RELOADABLE = (1 << 0), CONFIG_REQUIRED = (1 << 1) }

Functions

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)
switch_status_t switch_xml_config_enum_str2int (switch_xml_config_enum_item_t *enum_options, const char *value, int *out)
 Gets the int representation of an enum.
const char * switch_xml_config_enum_int2str (switch_xml_config_enum_item_t *enum_options, int value)
 Gets the string representation of an enum.
void switch_xml_config_item_print_doc (int level, switch_xml_config_item_t *item)
 Prints out an item's documentation on the console.
switch_status_t switch_xml_config_parse (switch_xml_t xml, switch_bool_t reload, switch_xml_config_item_t *instructions)
 Parses all the xml elements, following a ruleset defined by an array of switch_xml_config_item_t.
switch_status_t switch_xml_config_parse_module_settings (const char *file, switch_bool_t reload, switch_xml_config_item_t *instructions)
 Parses a module's settings.
switch_status_t switch_xml_config_parse_event (switch_event_t *event, int count, switch_bool_t reload, switch_xml_config_item_t *instructions)
 Parses all of an event's elements, following a ruleset defined by an array of switch_xml_config_item_t.
switch_size_t switch_event_import_xml (switch_xml_t xml, const char *keyname, const char *valuename, switch_event_t **event)
 Parses a list of xml elements into an event.
void switch_xml_config_cleanup (switch_xml_config_item_t *instructions)
 Free any memory allocated by the configuration.

Variables

switch_xml_config_string_options_t switch_config_string_strdup


Define Documentation

#define SWITCH_CONFIG_ITEM ( _key,
_type,
_flags,
_ptr,
_defaultvalue,
_data,
_syntax,
_helptext   )     { _key, _type, _flags, _ptr, (void*)_defaultvalue, (void*)_data, NULL, _syntax, _helptext }

Definition at line 105 of file switch_xml_config.h.

#define SWITCH_CONFIG_ITEM_CALLBACK ( _key,
_type,
_flags,
_ptr,
_defaultvalue,
_function,
_functiondata,
_syntax,
_helptext   )     { _key, _type, _flags, _ptr, (void*)_defaultvalue, _functiondata, _function, _syntax, _helptext }

Definition at line 107 of file switch_xml_config.h.

 
#define SWITCH_CONFIG_ITEM_END (  )     { NULL, SWITCH_CONFIG_LAST, 0, NULL, NULL, NULL, NULL, NULL, NULL }

Definition at line 108 of file switch_xml_config.h.

#define SWITCH_CONFIG_ITEM_STRING_STRDUP ( _key,
_flags,
_ptr,
_defaultvalue,
_syntax,
_helptext   )     { (_key), SWITCH_CONFIG_STRING, (_flags), (_ptr), ((void*)_defaultvalue), (NULL), (NULL), (_syntax), (_helptext) }

Definition at line 106 of file switch_xml_config.h.

#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)

Definition at line 110 of file switch_xml_config.h.

#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)

Definition at line 111 of file switch_xml_config.h.


Typedef Documentation

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)

Definition at line 87 of file switch_xml_config.h.

typedef struct switch_xml_config_item switch_xml_config_item_t

Definition at line 74 of file switch_xml_config.h.


Enumeration Type Documentation

enum switch_config_callback_type_t

Enumerator:
CONFIG_LOAD 
CONFIG_RELOAD 
CONFIG_SHUTDOWN 

Definition at line 76 of file switch_xml_config.h.

enum switch_config_flags_t

Enumerator:
CONFIG_RELOADABLE 
CONFIG_REQUIRED 

Definition at line 82 of file switch_xml_config.h.

00082              {
00083         CONFIG_RELOADABLE = (1 << 0),
00084         CONFIG_REQUIRED = (1 << 1)
00085 } switch_config_flags_t;

enum switch_xml_config_type_t

Type of value to parse.

Enumerator:
SWITCH_CONFIG_INT 
SWITCH_CONFIG_STRING 
SWITCH_CONFIG_BOOL 
SWITCH_CONFIG_CUSTOM 
SWITCH_CONFIG_ENUM 
SWITCH_CONFIG_FLAG 
SWITCH_CONFIG_FLAGARRAY 
SWITCH_CONFIG_LAST 

Definition at line 40 of file switch_xml_config.h.

00040                      {
00041         SWITCH_CONFIG_INT,                      /*< (ptr=int* default=int data=NULL) Integer */
00042         SWITCH_CONFIG_STRING,           /*< (ptr=[char* or char ** (for alloc)] default=char* data=switch_xml_config_string_options_t*) Zero-terminated C-string */
00043         SWITCH_CONFIG_BOOL,                     /*< (ptr=switch_bool_t* default=switch_bool_t data=NULL) Yes and no */
00044         SWITCH_CONFIG_CUSTOM,           /*< (ptr=<custom function data> default=<custom function data> data=switch_xml_config_callback_t) Custom, get value through function pointer  */
00045         SWITCH_CONFIG_ENUM,                     /*< (ptr=int* default=int data=switch_xml_config_enum_item_t*) */
00046         SWITCH_CONFIG_FLAG,                     /*< (ptr=int32_t* default=switch_bool_t data=int (flag index) */
00047         SWITCH_CONFIG_FLAGARRAY,        /*< (ptr=int8_t* default=switch_bool_t data=int (flag index) */
00048 
00049         /* No more past that line */
00050         SWITCH_CONFIG_LAST
00051 } switch_xml_config_type_t;


Function Documentation

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 
)

Definition at line 434 of file switch_xml_config.c.

00437 {
00438         item->key = key;
00439         item->type = type;
00440         item->flags = flags;
00441         item->ptr = ptr;
00442         item->defaultvalue = defaultvalue;
00443         item->data = data;
00444         item->function = function;
00445         item->syntax = syntax;
00446         item->helptext = helptext;
00447 }

switch_size_t switch_event_import_xml ( switch_xml_t  xml,
const char *  keyname,
const char *  valuename,
switch_event_t **  event 
)

Parses a list of xml elements into an event.

Parameters:
xml First element of the xml list to parse
keyname Name of the key attribute
keyvalue Name of the value attribute
event [out] event (if *event is NOT NULL, the headers will be appended to the existing event)

Definition at line 48 of file switch_xml_config.c.

References switch_xml::next, switch_assert, switch_event_add_header_string(), SWITCH_EVENT_CLONE, switch_event_create, SWITCH_STACK_BOTTOM, and switch_xml_attr_soft().

Referenced by switch_xml_config_parse().

00049 {
00050         switch_xml_t node;
00051         switch_size_t count = 0;
00052 
00053         if (!*event) {
00054                 /* SWITCH_EVENT_CLONE will not insert any generic event headers */
00055                 switch_event_create(event, SWITCH_EVENT_CLONE);
00056                 switch_assert(*event);
00057         }
00058 
00059         for (node = xml; node; node = node->next) {
00060                 const char *key = switch_xml_attr_soft(node, keyname);
00061                 const char *value = switch_xml_attr_soft(node, valuename);
00062                 if (key && value) {
00063                         switch_event_add_header_string(*event, SWITCH_STACK_BOTTOM, key, value);
00064                         count++;
00065                 }
00066         }
00067 
00068         return count;
00069 }

void switch_xml_config_cleanup ( switch_xml_config_item_t instructions  ) 

Free any memory allocated by the configuration.

Parameters:
instructions instrutions on how to parse the elements

Definition at line 404 of file switch_xml_config.c.

References switch_xml_config_item::data, switch_xml_config_item::function, switch_xml_config_item::key, switch_xml_config_string_options_t::length, switch_xml_config_string_options_t::pool, switch_xml_config_item::ptr, SWITCH_CONFIG_STRING, switch_safe_free, and switch_xml_config_item::type.

00405 {
00406         switch_xml_config_item_t *item;
00407 
00408         for (item = instructions; item->key; item++) {
00409                 switch_xml_config_callback_t callback = (switch_xml_config_callback_t) item->function;
00410 
00411                 switch (item->type) {
00412                 case SWITCH_CONFIG_STRING:
00413                         {
00414                                 char **ptr = (char **) item->ptr;
00415                                 switch_xml_config_string_options_t *string_options = (switch_xml_config_string_options_t *) item->data;
00416                                 /* if (using_strdup) */
00417                                 if (string_options && !string_options->pool && !string_options->length) {
00418                                         switch_safe_free(*ptr);
00419                                 }
00420                         }
00421                         break;
00422                 default:
00423                         break;
00424                 }
00425 
00426                 if (callback) {
00427                         callback(item, NULL, CONFIG_SHUTDOWN, SWITCH_FALSE);
00428                 }
00429 
00430         }
00431 }

const char* switch_xml_config_enum_int2str ( switch_xml_config_enum_item_t enum_options,
int  value 
)

Gets the string representation of an enum.

Parameters:
enum_options the switch_xml_config_enum_item_t array for this enum
value int value to search

Definition at line 126 of file switch_xml_config.c.

Referenced by switch_xml_config_item_print_doc().

00127 {
00128         for (; enum_options->key; enum_options++) {
00129                 if (value == enum_options->value) {
00130                         return enum_options->key;
00131                 }
00132         }
00133         return NULL;
00134 }

switch_status_t switch_xml_config_enum_str2int ( switch_xml_config_enum_item_t enum_options,
const char *  value,
int *  out 
)

Gets the int representation of an enum.

Parameters:
enum_options the switch_xml_config_enum_item_t array for this enum
value string value to search

Definition at line 114 of file switch_xml_config.c.

References SWITCH_STATUS_SUCCESS.

00115 {
00116         for (; enum_options->key; enum_options++) {
00117                 if (!strcasecmp(value, enum_options->key)) {
00118                         *out = enum_options->value;
00119                         return SWITCH_STATUS_SUCCESS;
00120                 }
00121         }
00122 
00123         return SWITCH_STATUS_FALSE;
00124 }

void switch_xml_config_item_print_doc ( int  level,
switch_xml_config_item_t item 
)

Prints out an item's documentation on the console.

Parameters:
level loglevel to use
item item which the doc should be printed

Definition at line 90 of file switch_xml_config.c.

References CONFIG_REQUIRED, SWITCH_CHANNEL_LOG_CLEAN, switch_config_types_enum, switch_log_printf(), switch_test_flag, and switch_xml_config_enum_int2str().

00091 {
00092         if (item->syntax && item->helptext) {
00093                 switch_log_printf(SWITCH_CHANNEL_LOG_CLEAN, level, "Item name: [%s]\nType: %s (%s)\nSyntax: %s\nHelp: %s\n\n",
00094                                                   item->key, switch_xml_config_enum_int2str(switch_config_types_enum, item->type),
00095                                                   switch_test_flag(item, CONFIG_REQUIRED) ? "required" : "optional", item->syntax, item->helptext);
00096         }
00097 }

switch_status_t switch_xml_config_parse ( switch_xml_t  xml,
switch_bool_t  reload,
switch_xml_config_item_t instructions 
)

Parses all the xml elements, following a ruleset defined by an array of switch_xml_config_item_t.

Parameters:
xml The first element of the list to parse
reload true to skip all non-reloadable options
instructions instrutions on how to parse the elements
See also:
switch_xml_config_item_t

Definition at line 99 of file switch_xml_config.c.

References switch_event_destroy(), switch_event_import_xml(), and switch_xml_config_parse_event().

Referenced by switch_xml_config_parse_module_settings().

00100 {
00101         switch_event_t *event = NULL;
00102         switch_status_t result;
00103         int count = switch_event_import_xml(xml, "name", "value", &event);
00104 
00105         result = switch_xml_config_parse_event(event, count, reload, instructions);
00106 
00107         if (event) {
00108                 switch_event_destroy(&event);
00109         }
00110 
00111         return result;
00112 }

switch_status_t switch_xml_config_parse_event ( switch_event_t event,
int  count,
switch_bool_t  reload,
switch_xml_config_item_t instructions 
)

Parses all of an event's elements, following a ruleset defined by an array of switch_xml_config_item_t.

Parameters:
event The event structure containing the key and values to parse
reload true to skip all non-reloadable options
instructions instrutions on how to parse the elements
See also:
switch_xml_config_item_t

Definition at line 136 of file switch_xml_config.c.

References CONFIG_RELOADABLE, CONFIG_REQUIRED, switch_xml_config_item::data, switch_xml_config_item::defaultvalue, switch_xml_config_item::function, switch_xml_config_item::key, switch_xml_config_item::ptr, SWITCH_CHANNEL_LOG, SWITCH_CONFIG_INT, switch_event_get_header, SWITCH_FALSE, switch_is_number(), SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, switch_test_flag, and switch_xml_config_item::type.

Referenced by switch_xml_config_parse().

00138 {
00139         switch_xml_config_item_t *item;
00140         int matched_count = 0;
00141 
00142         for (item = instructions; item->key; item++) {
00143                 const char *value = switch_event_get_header(event, item->key);
00144                 switch_bool_t changed = SWITCH_FALSE;
00145                 switch_xml_config_callback_t callback = (switch_xml_config_callback_t) item->function;
00146                 void *ptr = item->ptr;
00147 
00148                 //switch_assert(ptr);
00149 
00150                 if (value) {
00151                         matched_count++;
00152                 }
00153 
00154                 if (reload && !switch_test_flag(item, CONFIG_RELOADABLE)) {
00155                         continue;
00156                 }
00157 
00158                 if (!value && switch_test_flag(item, CONFIG_REQUIRED)) {
00159                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Required parameter [%s] is missing\n", item->key);
00160                         return SWITCH_STATUS_FALSE;
00161                 }
00162 
00163                 switch (item->type) {
00164                 case SWITCH_CONFIG_INT:
00165                         {
00166                                 switch_xml_config_int_options_t *int_options = (switch_xml_config_int_options_t *) item->data;
00167                                 int *dest = (int *) ptr;
00168                                 int intval;
00169                                 if (value) {
00170                                         if (switch_is_number(value)) {
00171                                                 intval = atoi(value);
00172                                         } else {
00173                                                 intval = (int) (intptr_t) item->defaultvalue;
00174                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%d]\n",
00175                                                                                   value, item->key, intval);
00176                                         }
00177 
00178                                         if (int_options) {
00179                                                 /* Enforce validation options */
00180                                                 if ((int_options->enforce_min && !(intval >= int_options->min)) || (int_options->enforce_max && !(intval <= int_options->max))) {
00181                                                         /* Validation failed, set default */
00182                                                         intval = (int) (intptr_t) item->defaultvalue;
00183                                                         /* Then complain */
00184                                                         if (int_options->enforce_min && int_options->enforce_max) {
00185                                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
00186                                                                                                   "Invalid value [%s] for parameter [%s], should be between [%d] and [%d], setting default [%d]\n", value,
00187                                                                                                   item->key, int_options->min, int_options->max, intval);
00188                                                         } else {
00189                                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR,
00190                                                                                                   "Invalid value [%s] for parameter [%s], should be %s [%d], setting default [%d]\n", value, item->key,
00191                                                                                                   int_options->enforce_min ? "at least" : "at max",
00192                                                                                                   int_options->enforce_min ? int_options->min : int_options->max, intval);
00193                                                         }
00194                                                 }
00195                                         }
00196                                 } else {
00197                                         intval = (int) (intptr_t) item->defaultvalue;
00198                                 }
00199 
00200                                 if (*dest != intval) {
00201                                         *dest = intval;
00202                                         changed = SWITCH_TRUE;
00203                                 }
00204                         }
00205                         break;
00206                 case SWITCH_CONFIG_STRING:
00207                         {
00208                                 switch_xml_config_string_options_t string_options_default = { 0 };
00209                                 switch_xml_config_string_options_t *string_options =
00210                                         item->data ? (switch_xml_config_string_options_t *) item->data : &string_options_default;
00211                                 const char *newstring = NULL;
00212 
00213                                 /* Perform validation */
00214                                 if (value) {
00215                                         if (!zstr(string_options->validation_regex)) {
00216                                                 if (switch_regex_match(value, string_options->validation_regex) == SWITCH_STATUS_SUCCESS) {
00217                                                         newstring = value;      /* Regex match, accept value */
00218                                                 } else {
00219                                                         newstring = (char *) item->defaultvalue;        /* Regex failed */
00220                                                         if (newstring) {
00221                                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n",
00222                                                                                                   value, item->key, newstring);
00223                                                         } else {
00224                                                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key);
00225                                                         }
00226                                                         switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
00227                                                 }
00228                                         } else {
00229                                                 newstring = value;      /* No validation */
00230                                         }
00231                                 } else {
00232                                         newstring = (char *) item->defaultvalue;
00233                                 }
00234 
00235                                 if (string_options->length > 0) {
00236                                         /* We have a preallocated buffer */
00237                                         char *dest = (char *) ptr;
00238 
00239                                         if (newstring) {
00240                                                 if (strncasecmp(dest, newstring, string_options->length)) {
00241                                                         switch_copy_string(dest, newstring, string_options->length);
00242                                                         changed = SWITCH_TRUE;
00243                                                 }
00244                                         } else {
00245                                                 if (*dest != '\0') {
00246                                                         *dest = '\0';
00247                                                         changed = SWITCH_TRUE;
00248                                                 }
00249                                         }
00250                                 } else if (string_options->pool) {
00251                                         /* Pool-allocated buffer */
00252                                         char **dest = (char **) ptr;
00253 
00254                                         if (newstring) {
00255                                                 if (!*dest || strcmp(*dest, newstring)) {
00256                                                         *dest = switch_core_strdup(string_options->pool, newstring);
00257                                                 }
00258                                         } else {
00259                                                 if (*dest) {
00260                                                         changed = SWITCH_TRUE;
00261                                                         *dest = NULL;
00262                                                 }
00263                                         }
00264                                 } else {
00265                                         /* Dynamically allocated buffer */
00266                                         char **dest = (char **) ptr;
00267 
00268                                         if (newstring) {
00269                                                 if (!*dest || strcmp(*dest, newstring)) {
00270                                                         switch_safe_free(*dest);
00271                                                         *dest = strdup(newstring);
00272                                                         changed = SWITCH_TRUE;
00273                                                 }
00274                                         } else {
00275                                                 if (*dest) {
00276                                                         switch_safe_free(*dest);
00277                                                         changed = SWITCH_TRUE;
00278                                                 }
00279                                         }
00280                                 }
00281                         }
00282                         break;
00283                 case SWITCH_CONFIG_BOOL:
00284                         {
00285                                 switch_bool_t *dest = (switch_bool_t *) ptr;
00286                                 switch_bool_t newval = SWITCH_FALSE;
00287 
00288                                 if (value && switch_true(value)) {
00289                                         newval = SWITCH_TRUE;
00290                                 } else if (value && switch_false(value)) {
00291                                         newval = SWITCH_FALSE;
00292                                 } else if (value) {
00293                                         /* Value isnt true or false */
00294                                         newval = (switch_bool_t) (intptr_t) item->defaultvalue;
00295                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s], setting default [%s]\n",
00296                                                                           value, item->key, newval ? "true" : "false");
00297                                         switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
00298                                 } else {
00299                                         newval = (switch_bool_t) (intptr_t) item->defaultvalue;
00300                                 }
00301 
00302                                 if (*dest != newval) {
00303                                         *dest = newval;
00304                                         changed = SWITCH_TRUE;
00305                                 }
00306                         }
00307                         break;
00308                 case SWITCH_CONFIG_CUSTOM:
00309                         break;
00310                 case SWITCH_CONFIG_ENUM:
00311                         {
00312                                 switch_xml_config_enum_item_t *enum_options = (switch_xml_config_enum_item_t *) item->data;
00313                                 int *dest = (int *) ptr;
00314                                 int newval = 0;
00315                                 switch_status_t lookup_result = SWITCH_STATUS_SUCCESS;
00316 
00317                                 if (value) {
00318                                         lookup_result = switch_xml_config_enum_str2int(enum_options, value, &newval);
00319                                 } else {
00320                                         newval = (int) (intptr_t) item->defaultvalue;
00321                                 }
00322 
00323                                 if (lookup_result != SWITCH_STATUS_SUCCESS) {
00324                                         newval = (int) (intptr_t) item->defaultvalue;
00325                                         switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Invalid value [%s] for parameter [%s]\n", value, item->key);
00326                                         switch_xml_config_item_print_doc(SWITCH_LOG_ERROR, item);
00327                                 }
00328 
00329                                 if (*dest != newval) {
00330                                         changed = SWITCH_TRUE;
00331                                         *dest = newval;
00332                                 }
00333                         }
00334                         break;
00335                 case SWITCH_CONFIG_FLAG:
00336                         {
00337                                 int32_t *dest = (int32_t *) ptr;
00338                                 int index = (int) (intptr_t) item->data;
00339                                 int8_t currentval = (int8_t) ! !(*dest & index);
00340                                 int newval = 0;
00341 
00342                                 if (value) {
00343                                         newval = switch_true(value);
00344                                 } else {
00345                                         newval = (switch_bool_t) (intptr_t) item->defaultvalue;
00346                                 }
00347 
00348                                 if (newval != currentval) {
00349                                         changed = SWITCH_TRUE;
00350                                         if (newval) {
00351                                                 *dest |= (1 << index);
00352                                         } else {
00353                                                 *dest &= ~(1 << index);
00354                                         }
00355                                 }
00356                         }
00357                         break;
00358                 case SWITCH_CONFIG_FLAGARRAY:
00359                         {
00360                                 int8_t *dest = (int8_t *) ptr;
00361                                 unsigned int index = (unsigned int) (intptr_t) item->data;
00362                                 int8_t newval = value ? !!switch_true(value) : (int8_t) ((intptr_t) item->defaultvalue);
00363                                 if (dest[index] != newval) {
00364                                         changed = SWITCH_TRUE;
00365                                         dest[index] = newval;
00366                                 }
00367                         }
00368                         break;
00369                 case SWITCH_CONFIG_LAST:
00370                         break;
00371                 default:
00372                         break;
00373                 }
00374 
00375                 if (callback) {
00376                         callback(item, value, (reload ? CONFIG_RELOAD : CONFIG_LOAD), changed);
00377                 }
00378         }
00379 
00380         if (count != matched_count) {
00381                 /* User made a mistake, find it */
00382                 switch_event_header_t *header;
00383                 for (header = event->headers; header; header = header->next) {
00384                         switch_bool_t found = SWITCH_FALSE;
00385                         for (item = instructions; item->key; item++) {
00386                                 if (!strcasecmp(header->name, item->key)) {
00387                                         found = SWITCH_TRUE;
00388                                         break;
00389                                 }
00390                         }
00391 
00392                         if (!found) {
00393                                 /* Tell the user */
00394                                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_WARNING,
00395                                                                   "Configuration parameter [%s] is unfortunately not valid, you might want to double-check that.\n", header->name);
00396                         }
00397                 }
00398         }
00399 
00400         return SWITCH_STATUS_SUCCESS;
00401 }

switch_status_t switch_xml_config_parse_module_settings ( const char *  file,
switch_bool_t  reload,
switch_xml_config_item_t instructions 
)

Parses a module's settings.

Parameters:
reload true to skip all non-reloadable options
file the configuration file to look for
instructions the instructions

Definition at line 71 of file switch_xml_config.c.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_xml_child(), switch_xml_config_parse(), switch_xml_free(), and switch_xml_open_cfg().

00072 {
00073         switch_xml_t cfg, xml, settings;
00074         switch_status_t status = SWITCH_STATUS_SUCCESS;
00075 
00076         if (!(xml = switch_xml_open_cfg(file, &cfg, NULL))) {
00077                 switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Could not open %s\n", file);
00078                 return SWITCH_STATUS_FALSE;
00079         }
00080 
00081         if ((settings = switch_xml_child(cfg, "settings"))) {
00082                 status = switch_xml_config_parse(switch_xml_child(settings, "param"), reload, instructions);
00083         }
00084 
00085         switch_xml_free(xml);
00086 
00087         return status;
00088 }


Variable Documentation

switch_xml_config_string_options_t switch_config_string_strdup

Definition at line 35 of file switch_xml_config.c.


Generated on Sun May 20 04:00:16 2012 for FreeSWITCH API Documentation by  doxygen 1.4.7