FreeSWITCH API Documentation  1.7.0
Data Structures | Macros | Enumerations | Functions
XML Library Functions
+ Collaboration diagram for XML Library Functions:

Data Structures

struct  switch_xml
 A representation of an XML tree. More...
 

Macros

#define SWITCH_XML_BUFSIZE   1024
 
#define switch_xml_parse_str_dup(x)   switch_xml_parse_str_dynamic(x, SWITCH_TRUE)
 Parses a string into a switch_xml_t. More...
 
#define switch_xml_next(xml)   ((xml) ? xml->next : NULL)
 returns the next tag of the same name in the same section and depth or NULL \ if not found More...
 
#define switch_xml_name(xml)   ((xml) ? xml->name : NULL)
 returns the name of the given tag More...
 
#define switch_xml_txt(xml)   ((xml) ? xml->txt : "")
 returns the given tag's character content or empty string if none More...
 
#define switch_xml_new_d(name)   switch_xml_set_flag(switch_xml_new(strdup(name)), SWITCH_XML_NAMEM)
 wrapper for switch_xml_new() that strdup()s name More...
 
#define switch_xml_add_child_d(xml, name, off)   switch_xml_set_flag(switch_xml_add_child(xml, strdup(name), off), SWITCH_XML_NAMEM)
 wrapper for switch_xml_add_child() that strdup()s name More...
 
#define switch_xml_set_txt_d(xml, txt)   switch_xml_set_flag(switch_xml_set_txt(xml, strdup(txt)), SWITCH_XML_TXTM)
 wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag and returns the tag More...
 
#define switch_xml_set_attr_d(xml, name, value)   switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(switch_str_nil(value)))
 Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL. More...
 
#define switch_xml_set_attr_d_buf(xml, name, value)   switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(value))
 
#define switch_xml_move(xml, dest, off)   switch_xml_insert(switch_xml_cut(xml), dest, off)
 Moves an existing tag to become a subtag of dest at the given offset from \ the start of dest's character content. Returns the moved tag. More...
 
#define switch_xml_remove(xml)   switch_xml_free(switch_xml_cut(xml))
 removes a tag along with all its subtags More...
 
#define switch_xml_bind_search_function(_f, _s, _u)   switch_xml_bind_search_function_ret(_f, _s, _u, NULL)
 

Enumerations

enum  switch_xml_flag_t { SWITCH_XML_ROOT = (1 << 0), SWITCH_XML_NAMEM = (1 << 1), SWITCH_XML_TXTM = (1 << 2), SWITCH_XML_DUP = (1 << 3) }
 

Functions

switch_xml_t switch_xml_parse_str_dynamic (_In_z_ char *s, _In_ switch_bool_t dup)
 Parses a string into a switch_xml_t, ensuring the memory will be freed with switch_xml_free. More...
 
switch_xml_t switch_xml_parse_str (_In_z_ char *s, _In_ switch_size_t len)
 Given a string of xml data and its length, parses it and creates an switch_xml \ structure. For efficiency, modifies the data by adding null terminators \ and decoding ampersand sequences. If you don't want this, copy the data and \ pass in the copy. Returns NULL on failure. More...
 
switch_xml_t switch_xml_parse_fd (int fd)
 A wrapper for switch_xml_parse_str() that accepts a file descriptor. First \ attempts to mem map the file. Failing that, reads the file into memory. \ Returns NULL on failure. More...
 
switch_xml_t switch_xml_parse_file (_In_z_ const char *file)
 a wrapper for switch_xml_parse_fd() that accepts a file name More...
 
switch_xml_t switch_xml_parse_file_simple (_In_z_ const char *file)
 
switch_xml_t switch_xml_parse_fp (_In_ FILE *fp)
 Wrapper for switch_xml_parse_str() that accepts a file stream. Reads the entire \ stream into memory and then parses it. For xml files, use switch_xml_parse_file() \ or switch_xml_parse_fd() More...
 
switch_xml_t switch_xml_child (_In_ switch_xml_t xml, _In_z_ const char *name)
 returns the first child tag (one level deeper) with the given name or NULL \ if not found More...
 
switch_xml_t switch_xml_find_child (_In_ switch_xml_t node, _In_z_ const char *childname, _In_opt_z_ const char *attrname, _In_opt_z_ const char *value)
 find a child tag in a node called 'childname' with an attribute 'attrname' which equals 'value' More...
 
switch_xml_t switch_xml_find_child_multi (_In_ switch_xml_t node, _In_z_ const char *childname,...)
 
switch_xml_t switch_xml_idx (_In_ switch_xml_t xml, _In_ int idx)
 Returns the Nth tag with the same name in the same section at the same depth \ or NULL if not found. An index of 0 returns the tag given. More...
 
const char * switch_xml_attr (_In_opt_ switch_xml_t xml, _In_opt_z_ const char *attr)
 returns the value of the requested tag attribute, or NULL if not found More...
 
const char * switch_xml_attr_soft (_In_ switch_xml_t xml, _In_z_ const char *attr)
 returns the value of the requested tag attribute, or "" if not found More...
 
switch_xml_t switch_xml_get (_In_ switch_xml_t xml,...)
 Traverses the switch_xml structure to retrieve a specific subtag. Takes a \ variable length list of tag names and indexes. The argument list must be \ terminated by either an index of -1 or an empty string tag name. Example: \ title = switch_xml_get(library, "shelf", 0, "book", 2, "title", -1); \ This retrieves the title of the 3rd book on the 1st shelf of library. \ Returns NULL if not found. More...
 
char * switch_xml_toxml (_In_ switch_xml_t xml, _In_ switch_bool_t prn_header)
 Converts an switch_xml structure back to xml in html format. Returns a string of html data that \ must be freed. More...
 
char * switch_xml_toxml_nolock (switch_xml_t xml, _In_ switch_bool_t prn_header)
 
char * switch_xml_tohtml (_In_ switch_xml_t xml, _In_ switch_bool_t prn_header)
 
char * switch_xml_toxml_buf (_In_ switch_xml_t xml, _In_z_ char *buf, _In_ switch_size_t buflen, _In_ switch_size_t offset, _In_ switch_bool_t prn_header)
 Converts an switch_xml structure back to xml using the buffer passed in the parameters. More...
 
const char ** switch_xml_pi (_In_ switch_xml_t xml, _In_z_ const char *target)
 returns a NULL terminated array of processing instructions for the given \ target More...
 
void switch_xml_free (_In_opt_ switch_xml_t xml)
 frees the memory allocated for an switch_xml structure More...
 
void switch_xml_free_in_thread (_In_ switch_xml_t xml, _In_ int stacksize)
 
const char * switch_xml_error (_In_ switch_xml_t xml)
 returns parser error message or empty string if none More...
 
switch_xml_t switch_xml_new (_In_opt_z_ const char *name)
 returns a new empty switch_xml structure with the given root tag name More...
 
switch_xml_t switch_xml_add_child (_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
 Adds a child tag. off is the offset of the child tag relative to the start \ of the parent tag's character content. Returns the child tag. More...
 
switch_xml_t switch_xml_set_txt (switch_xml_t xml, const char *txt)
 sets the character content for the given tag and returns the tag More...
 
switch_xml_t switch_xml_set_attr (switch_xml_t xml, const char *name, const char *value)
 Sets the given tag attribute or adds a new attribute if not found. A value \ of NULL will remove the specified attribute. More...
 
switch_xml_t switch_xml_set_flag (switch_xml_t xml, switch_xml_flag_t flag)
 sets a flag for the given tag and returns the tag More...
 
switch_xml_t switch_xml_cut (_In_ switch_xml_t xml)
 removes a tag along with its subtags without freeing its memory More...
 
switch_xml_t switch_xml_insert (_In_ switch_xml_t xml, _In_ switch_xml_t dest, _In_ switch_size_t off)
 inserts an existing tag into an ezxml structure More...
 
switch_status_t switch_xml_set_root (switch_xml_t new_main)
 set new core xml root More...
 
switch_status_t switch_xml_set_open_root_function (switch_xml_open_root_function_t func, void *user_data)
 Set and alternate function for opening xml root. More...
 
switch_xml_t switch_xml_open_root (_In_ uint8_t reload, _Out_ const char **err)
 open the Core xml root More...
 
switch_status_t switch_xml_init (_In_ switch_memory_pool_t *pool, _Out_ const char **err)
 initilize the core XML backend More...
 
switch_status_t switch_xml_reload (const char **err)
 
switch_status_t switch_xml_destroy (void)
 
switch_xml_t switch_xml_root (void)
 retrieve the core XML root node More...
 
switch_status_t switch_xml_locate (_In_z_ const char *section, _In_opt_z_ const char *tag_name, _In_opt_z_ const char *key_name, _In_opt_z_ const char *key_value, _Out_ switch_xml_t *root, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params, _In_ switch_bool_t clone)
 locate an xml pointer in the core registry More...
 
switch_status_t switch_xml_locate_domain (_In_z_ const char *domain_name, _In_opt_ switch_event_t *params, _Out_ switch_xml_t *root, _Out_ switch_xml_t *domain)
 
switch_status_t switch_xml_locate_group (_In_z_ const char *group_name, _In_z_ const char *domain_name, _Out_ switch_xml_t *root, _Out_ switch_xml_t *domain, _Out_ switch_xml_t *group, _In_opt_ switch_event_t *params)
 
switch_status_t switch_xml_locate_user (_In_z_ const char *key, _In_z_ const char *user_name, _In_z_ const char *domain_name, _In_opt_z_ const char *ip, _Out_ switch_xml_t *root, _Out_ switch_xml_t *domain, _Out_ switch_xml_t *user, _Out_opt_ switch_xml_t *ingroup, _In_opt_ switch_event_t *params)
 
switch_status_t switch_xml_locate_user_in_domain (_In_z_ const char *user_name, _In_ switch_xml_t domain, _Out_ switch_xml_t *user, _Out_opt_ switch_xml_t *ingroup)
 
switch_status_t switch_xml_locate_user_merged (const char *key, const char *user_name, const char *domain_name, const char *ip, switch_xml_t *user, switch_event_t *params)
 
uint32_t switch_xml_clear_user_cache (const char *key, const char *user_name, const char *domain_name)
 
void switch_xml_merge_user (switch_xml_t user, switch_xml_t domain, switch_xml_t group)
 
switch_xml_t switch_xml_dup (switch_xml_t xml)
 
switch_xml_t switch_xml_open_cfg (_In_z_ const char *file_path, _Out_ switch_xml_t *node, _In_opt_ switch_event_t *params)
 open a config in the core registry More...
 
void switch_xml_set_binding_sections (_In_ switch_xml_binding_t *binding, _In_ switch_xml_section_t sections)
 bind a search function to an external gateway More...
 
void switch_xml_set_binding_user_data (_In_ switch_xml_binding_t *binding, _In_opt_ void *user_data)
 
switch_xml_section_t switch_xml_get_binding_sections (_In_ switch_xml_binding_t *binding)
 
void * switch_xml_get_binding_user_data (_In_ switch_xml_binding_t *binding)
 
switch_status_t switch_xml_bind_search_function_ret (_In_ switch_xml_search_function_t function, _In_ switch_xml_section_t sections, _In_opt_ void *user_data, switch_xml_binding_t **ret_binding)
 
switch_status_t switch_xml_unbind_search_function (_In_ switch_xml_binding_t **binding)
 
switch_status_t switch_xml_unbind_search_function_ptr (_In_ switch_xml_search_function_t function)
 
switch_xml_section_t switch_xml_parse_section_string (_In_opt_z_ const char *str)
 parse a string for a list of sections More...
 
int switch_xml_std_datetime_check (switch_xml_t xcond, int *offset, const char *tzname)
 
switch_status_t switch_xml_locate_language (switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_xml_t *language, switch_xml_t *phrases, switch_xml_t *macros, const char *str_language)
 

Detailed Description

Macro Definition Documentation

#define switch_xml_add_child_d (   xml,
  name,
  off 
)    switch_xml_set_flag(switch_xml_add_child(xml, strdup(name), off), SWITCH_XML_NAMEM)

wrapper for switch_xml_add_child() that strdup()s name

Parameters
xmlthe xml node
namethe name of the child
offthe offset

Definition at line 269 of file switch_xml.h.

Referenced by add_xml_header(), comp_callback(), do_merge(), switch_console_complete(), switch_event_xmlize(), switch_ivr_generate_xml_cdr(), switch_ivr_set_xml_call_stats(), switch_ivr_set_xml_chan_var(), and switch_ivr_set_xml_profile_data().

#define switch_xml_bind_search_function (   _f,
  _s,
  _u 
)    switch_xml_bind_search_function_ret(_f, _s, _u, NULL)

Definition at line 415 of file switch_xml.h.

#define SWITCH_XML_BUFSIZE   1024
#define switch_xml_move (   xml,
  dest,
  off 
)    switch_xml_insert(switch_xml_cut(xml), dest, off)

Moves an existing tag to become a subtag of dest at the given offset from \ the start of dest's character content. Returns the moved tag.

Definition at line 320 of file switch_xml.h.

#define switch_xml_name (   xml)    ((xml) ? xml->name : NULL)

returns the name of the given tag

Parameters
xmlthe xml node
Returns
the name

Definition at line 182 of file switch_xml.h.

#define switch_xml_new_d (   name)    switch_xml_set_flag(switch_xml_new(strdup(name)), SWITCH_XML_NAMEM)

wrapper for switch_xml_new() that strdup()s name

Parameters
namethe name of the root
Returns
an xml node or NULL

Definition at line 255 of file switch_xml.h.

#define switch_xml_next (   xml)    ((xml) ? xml->next : NULL)

returns the next tag of the same name in the same section and depth or NULL \ if not found

Parameters
xmlan xml node
Returns
an xml node or NULL

Definition at line 170 of file switch_xml.h.

Referenced by switch_nat_republish().

#define switch_xml_parse_str_dup (   x)    switch_xml_parse_str_dynamic(x, SWITCH_TRUE)

Parses a string into a switch_xml_t.

Parameters
sThe string to parse
Returns
the switch_xml_t or NULL if an error occured

Definition at line 117 of file switch_xml.h.

Referenced by switch_nat_republish().

#define switch_xml_remove (   xml)    switch_xml_free(switch_xml_cut(xml))

removes a tag along with all its subtags

Definition at line 323 of file switch_xml.h.

#define switch_xml_set_attr_d (   xml,
  name,
  value 
)    switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(switch_str_nil(value)))

Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.

Parameters
xmlthe xml node
namethe attribute name
valuethe attribute value
Returns
an xml node or NULL

Definition at line 299 of file switch_xml.h.

Referenced by do_merge(), switch_ivr_generate_xml_cdr(), and switch_xml_merge_user().

#define switch_xml_set_attr_d_buf (   xml,
  name,
  value 
)    switch_xml_set_attr(switch_xml_set_flag(xml, SWITCH_XML_DUP), strdup(name), strdup(value))

Definition at line 302 of file switch_xml.h.

Referenced by switch_console_complete(), and switch_ivr_generate_xml_cdr().

#define switch_xml_set_txt_d (   xml,
  txt 
)    switch_xml_set_flag(switch_xml_set_txt(xml, strdup(txt)), SWITCH_XML_TXTM)

wrapper for switch_xml_set_txt() that strdup()s txt \ sets the character content for the given tag and returns the tag

Parameters
xmlthe xml node
txtthe text
Returns
an xml node or NULL

Definition at line 283 of file switch_xml.h.

Referenced by add_xml_header(), comp_callback(), switch_console_complete(), switch_event_xmlize(), switch_ivr_generate_xml_cdr(), switch_ivr_set_xml_call_stats(), switch_ivr_set_xml_chan_var(), and switch_ivr_set_xml_profile_data().

#define switch_xml_txt (   xml)    ((xml) ? xml->txt : "")

returns the given tag's character content or empty string if none

Parameters
xmlthe xml node
Returns
the content

Definition at line 187 of file switch_xml.h.

Enumeration Type Documentation

Enumerator
SWITCH_XML_ROOT 
SWITCH_XML_NAMEM 
SWITCH_XML_TXTM 
SWITCH_XML_DUP 

Definition at line 68 of file switch_xml.h.

68  {
69  SWITCH_XML_ROOT = (1 << 0), // root
70  SWITCH_XML_NAMEM = (1 << 1), // name is malloced
71  SWITCH_XML_TXTM = (1 << 2), // txt is malloced
72  SWITCH_XML_DUP = (1 << 3) // attribute name and value are strduped
switch_xml_flag_t
Definition: switch_xml.h:68

Function Documentation

switch_xml_t switch_xml_add_child ( _In_ switch_xml_t  xml,
_In_z_ const char *  name,
_In_ switch_size_t  off 
)

Adds a child tag. off is the offset of the child tag relative to the start \ of the parent tag's character content. Returns the child tag.

Parameters
xmlthe xml node
namethe name of the tag
offthe offset
Returns
an xml node or NULL
const char* switch_xml_attr ( _In_opt_ switch_xml_t  xml,
_In_opt_z_ const char *  attr 
)

returns the value of the requested tag attribute, or NULL if not found

Parameters
xmlthe xml node
attrthe attribute
Returns
the value

Referenced by load_configuration(), switch_ivr_check_presence_mapping(), switch_ivr_menu_stack_xml_build(), switch_ivr_phrase_macro_event(), switch_ivr_say(), switch_ivr_say_string(), switch_ivr_set_user_xml(), switch_load_network_lists(), and switch_load_timezones().

const char* switch_xml_attr_soft ( _In_ switch_xml_t  xml,
_In_z_ const char *  attr 
)

returns the value of the requested tag attribute, or "" if not found

Parameters
xmlthe xml node
attrthe attribute
Returns
the value

Referenced by console_xml_config(), recover_callback(), switch_event_import_xml(), switch_ivr_menu_stack_xml_build(), switch_ivr_phrase_macro_event(), switch_load_core_config(), and switch_loadable_module_init().

switch_status_t switch_xml_bind_search_function_ret ( _In_ switch_xml_search_function_t  function,
_In_ switch_xml_section_t  sections,
_In_opt_ void *  user_data,
switch_xml_binding_t **  ret_binding 
)
switch_xml_t switch_xml_child ( _In_ switch_xml_t  xml,
_In_z_ const char *  name 
)
uint32_t switch_xml_clear_user_cache ( const char *  key,
const char *  user_name,
const char *  domain_name 
)

Definition at line 1920 of file switch_xml.c.

References CACHE_EXPIRES_HASH, CACHE_HASH, switch_core_hash_delete(), switch_core_hash_find(), switch_core_hash_first_iter(), switch_core_hash_this(), switch_mutex_lock(), switch_mutex_unlock(), switch_safe_free, switch_snprintf(), and switch_xml_free().

Referenced by switch_xml_destroy().

1921 {
1922  switch_hash_index_t *hi = NULL;
1923  void *val;
1924  const void *var;
1925  char mega_key[1024];
1926  int r = 0;
1927  switch_xml_t lookup;
1928  char *expires_val = NULL;
1929 
1931 
1932  if (key && user_name && domain_name) {
1933  switch_snprintf(mega_key, sizeof(mega_key), "%s%s%s", key, user_name, domain_name);
1934 
1935  if ((lookup = switch_core_hash_find(CACHE_HASH, mega_key))) {
1937  if ((expires_val = switch_core_hash_find(CACHE_EXPIRES_HASH, mega_key))) {
1939  free(expires_val);
1940  expires_val = NULL;
1941  }
1942  switch_xml_free(lookup);
1943  r++;
1944  }
1945 
1946  } else {
1947 
1948  while ((hi = switch_core_hash_first_iter( CACHE_HASH, hi))) {
1949  switch_core_hash_this(hi, &var, NULL, &val);
1950  switch_xml_free(val);
1952  r++;
1953  }
1954 
1955  while ((hi = switch_core_hash_first_iter( CACHE_EXPIRES_HASH, hi))) {
1956  switch_core_hash_this(hi, &var, NULL, &val);
1957  switch_safe_free(val);
1959  }
1960 
1961  switch_safe_free(hi);
1962  }
1963 
1965 
1966  return r;
1967 
1968 }
void * switch_core_hash_find(_In_ switch_hash_t *hash, _In_z_ const char *key)
Retrieve data from a given hash.
A representation of an XML tree.
Definition: switch_xml.h:76
static switch_hash_t * CACHE_HASH
Definition: switch_xml.c:188
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
void switch_core_hash_this(_In_ switch_hash_index_t *hi, _Out_opt_ptrdiff_cap_(klen) const void **key, _Out_opt_ switch_ssize_t *klen, _Out_ void **val)
Gets the key and value of the current hash element.
void * switch_core_hash_delete(_In_ switch_hash_t *hash, _In_z_ const char *key)
Delete data from a hash based on desired key.
static switch_hash_t * CACHE_EXPIRES_HASH
Definition: switch_xml.c:189
static switch_mutex_t * CACHE_MUTEX
Definition: switch_xml.c:179
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2701
switch_hash_index_t * switch_core_hash_first_iter(_In_ switch_hash_t *hash, switch_hash_index_t *hi)
Gets the first element of a hashtable.
switch_xml_t switch_xml_cut ( _In_ switch_xml_t  xml)

removes a tag along with its subtags without freeing its memory

Parameters
xmlthe xml node
switch_status_t switch_xml_destroy ( void  )

Definition at line 2358 of file switch_xml.c.

References CACHE_HASH, MAIN_XML_ROOT, switch_core_hash_destroy(), switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_xml_clear_user_cache(), switch_xml_free(), and destroy_xml::xml.

Referenced by switch_core_destroy().

2359 {
2361 
2362 
2365 
2366  if (MAIN_XML_ROOT) {
2368  MAIN_XML_ROOT = NULL;
2369  switch_xml_free(xml);
2370  status = SWITCH_STATUS_SUCCESS;
2371  }
2372 
2375 
2376  switch_xml_clear_user_cache(NULL, NULL, NULL);
2377 
2379 
2380  return status;
2381 }
switch_status_t switch_core_hash_destroy(_Inout_ switch_hash_t **hash)
Destroy an existing hash table.
static switch_mutex_t * REFLOCK
Definition: switch_xml.c:180
A representation of an XML tree.
Definition: switch_xml.h:76
static switch_hash_t * CACHE_HASH
Definition: switch_xml.c:188
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static switch_xml_t MAIN_XML_ROOT
Definition: switch_xml.c:174
uint32_t switch_xml_clear_user_cache(const char *key, const char *user_name, const char *domain_name)
Definition: switch_xml.c:1920
switch_status_t
Common return values.
static switch_mutex_t * XML_LOCK
Definition: switch_xml.c:178
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2701
switch_xml_t switch_xml_dup ( switch_xml_t  xml)

Definition at line 1862 of file switch_xml.c.

References SWITCH_FALSE, switch_xml_parse_str_dynamic(), and switch_xml_toxml().

Referenced by switch_xml_locate_user_cache(), switch_xml_locate_user_merged(), and switch_xml_user_cache().

1863 {
1864  char *x = switch_xml_toxml(xml, SWITCH_FALSE);
1866 }
switch_xml_t switch_xml_parse_str_dynamic(char *s, switch_bool_t dup)
Definition: switch_xml.c:962
char * switch_xml_toxml(switch_xml_t xml, switch_bool_t prn_header)
Definition: switch_xml.c:2616
const char* switch_xml_error ( _In_ switch_xml_t  xml)

returns parser error message or empty string if none

Parameters
xmlthe xml node
Returns
the error string or nothing
switch_xml_t switch_xml_find_child ( _In_ switch_xml_t  node,
_In_z_ const char *  childname,
_In_opt_z_ const char *  attrname,
_In_opt_z_ const char *  value 
)

find a child tag in a node called 'childname' with an attribute 'attrname' which equals 'value'

Parameters
nodethe xml node
childnamethe child tag name
attrnamethe attribute name
valuethe value
Returns
an xml node or NULL

Referenced by switch_ivr_menu_stack_xml_build(), switch_ivr_phrase_macro_event(), and switch_nat_republish().

switch_xml_t switch_xml_find_child_multi ( _In_ switch_xml_t  node,
_In_z_ const char *  childname,
  ... 
)
void switch_xml_free ( _In_opt_ switch_xml_t  xml)
void switch_xml_free_in_thread ( _In_ switch_xml_t  xml,
_In_ int  stacksize 
)
switch_xml_t switch_xml_get ( _In_ switch_xml_t  xml,
  ... 
)

Traverses the switch_xml structure to retrieve a specific subtag. Takes a \ variable length list of tag names and indexes. The argument list must be \ terminated by either an index of -1 or an empty string tag name. Example: \ title = switch_xml_get(library, "shelf", 0, "book", 2, "title", -1); \ This retrieves the title of the 3rd book on the 1st shelf of library. \ Returns NULL if not found.

Parameters
xmlthe xml node
Returns
an xml node or NULL
switch_xml_section_t switch_xml_get_binding_sections ( _In_ switch_xml_binding_t binding)
void* switch_xml_get_binding_user_data ( _In_ switch_xml_binding_t binding)
switch_xml_t switch_xml_idx ( _In_ switch_xml_t  xml,
_In_ int  idx 
)

Returns the Nth tag with the same name in the same section at the same depth \ or NULL if not found. An index of 0 returns the tag given.

Parameters
xmlthe xml node
idxthe index
Returns
an xml node or NULL
switch_status_t switch_xml_init ( _In_ switch_memory_pool_t pool,
_Out_ const char **  err 
)

initilize the core XML backend

Parameters
poola memory pool to use
erra pointer to set error strings
Returns
SWITCH_STATUS_SUCCESS if successful

Referenced by switch_core_init().

switch_xml_t switch_xml_insert ( _In_ switch_xml_t  xml,
_In_ switch_xml_t  dest,
_In_ switch_size_t  off 
)

inserts an existing tag into an ezxml structure

switch_status_t switch_xml_locate ( _In_z_ const char *  section,
_In_opt_z_ const char *  tag_name,
_In_opt_z_ const char *  key_name,
_In_opt_z_ const char *  key_value,
_Out_ switch_xml_t root,
_Out_ switch_xml_t node,
_In_opt_ switch_event_t params,
_In_ switch_bool_t  clone 
)

locate an xml pointer in the core registry

Parameters
sectionthe section to look in
tag_namethe type of tag in that section
key_namethe name of the key
key_valuethe value of the key
roota pointer to point at the root node
nodea pointer to the requested node
paramsoptional URL formatted params to pass to external gateways
Returns
SWITCH_STATUS_SUCCESS if successful root and node will be assigned
switch_status_t switch_xml_locate_domain ( _In_z_ const char *  domain_name,
_In_opt_ switch_event_t params,
_Out_ switch_xml_t root,
_Out_ switch_xml_t domain 
)
switch_status_t switch_xml_locate_group ( _In_z_ const char *  group_name,
_In_z_ const char *  domain_name,
_Out_ switch_xml_t root,
_Out_ switch_xml_t domain,
_Out_ switch_xml_t group,
_In_opt_ switch_event_t params 
)
switch_status_t switch_xml_locate_language ( switch_xml_t root,
switch_xml_t node,
switch_event_t params,
switch_xml_t language,
switch_xml_t phrases,
switch_xml_t macros,
const char *  str_language 
)

Definition at line 3147 of file switch_xml.c.

References SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, switch_log_printf(), SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, SWITCH_TRUE, switch_xml_child(), switch_xml_find_child(), switch_xml_free(), and switch_xml_locate().

Referenced by switch_ivr_phrase_macro_event(), switch_ivr_say(), and switch_ivr_say_string().

3147  {
3149 
3150  if (switch_xml_locate("languages", NULL, NULL, NULL, root, node, params, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
3151  switch_xml_t sub_macros;
3152 
3153  if (switch_xml_locate("phrases", NULL, NULL, NULL, root, node, params, SWITCH_TRUE) != SWITCH_STATUS_SUCCESS) {
3154  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Open of languages and phrases failed.\n");
3155  goto done;
3156  }
3157  if (!(sub_macros = switch_xml_child(*node, "macros"))) {
3158  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find macros tag.\n");
3159  switch_xml_free(*root);
3160  *root = NULL;
3161  *node = NULL;
3162  goto done;
3163  }
3164  if (!(*language = switch_xml_find_child(sub_macros, "language", "name", str_language))) {
3165  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find language %s.\n", str_language);
3166  switch_xml_free(*root);
3167  *root = NULL;
3168  *node = NULL;
3169  goto done;
3170  }
3171  *macros = *language;
3172  } else {
3173  if (!(*language = switch_xml_find_child(*node, "language", "name", str_language))) {
3174  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find language %s.\n", str_language);
3175  switch_xml_free(*root);
3176  *root = NULL;
3177  goto done;
3178  }
3179  if (!(*phrases = switch_xml_child(*language, "phrases"))) {
3180  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find phrases tag.\n");
3181  switch_xml_free(*root);
3182  *root = NULL;
3183  *node = NULL;
3184  *language = NULL;
3185  goto done;
3186  }
3187 
3188  if (!(*macros = switch_xml_child(*phrases, "macros"))) {
3189  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Can't find macros tag.\n");
3190  switch_xml_free(*root);
3191  *root = NULL;
3192  *node = NULL;
3193  *language = NULL;
3194  *phrases = NULL;
3195  goto done;
3196  }
3197  }
3198  status = SWITCH_STATUS_SUCCESS;
3199 
3200 done:
3201  return status;
3202 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_xml_locate(const char *section, const char *tag_name, const char *key_name, const char *key_value, switch_xml_t *root, switch_xml_t *node, switch_event_t *params, switch_bool_t clone)
Definition: switch_xml.c:1655
A representation of an XML tree.
Definition: switch_xml.h:76
switch_status_t
Common return values.
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2701
switch_xml_t switch_xml_find_child(switch_xml_t node, const char *childname, const char *attrname, const char *value)
Definition: switch_xml.c:334
switch_xml_t switch_xml_child(switch_xml_t xml, const char *name)
Definition: switch_xml.c:409
switch_status_t switch_xml_locate_user ( _In_z_ const char *  key,
_In_z_ const char *  user_name,
_In_z_ const char *  domain_name,
_In_opt_z_ const char *  ip,
_Out_ switch_xml_t root,
_Out_ switch_xml_t domain,
_Out_ switch_xml_t user,
_Out_opt_ switch_xml_t ingroup,
_In_opt_ switch_event_t params 
)
switch_status_t switch_xml_locate_user_in_domain ( _In_z_ const char *  user_name,
_In_ switch_xml_t  domain,
_Out_ switch_xml_t user,
_Out_opt_ switch_xml_t ingroup 
)
switch_status_t switch_xml_locate_user_merged ( const char *  key,
const char *  user_name,
const char *  domain_name,
const char *  ip,
switch_xml_t user,
switch_event_t params 
)

Definition at line 2034 of file switch_xml.c.

References SWITCH_CHANNEL_LOG, switch_is_number(), SWITCH_LOG_DEBUG, switch_log_printf(), switch_micro_time_now(), switch_must_strdup(), switch_safe_free, switch_split, SWITCH_STATUS_FALSE, SWITCH_STATUS_SUCCESS, switch_xml_attr(), switch_xml_dup(), switch_xml_free(), switch_xml_locate_user(), switch_xml_locate_user_cache(), switch_xml_merge_user(), switch_xml_user_cache(), time_now(), and zstr.

Referenced by switch_ivr_set_user().

2036 {
2037  switch_xml_t xml, domain, group, x_user, x_user_dup;
2039  char *kdup = NULL;
2040  char *keys[10] = {0};
2041  int i, nkeys;
2042 
2043  if (strchr(key, ':')) {
2044  kdup = switch_must_strdup(key);
2045  nkeys = switch_split(kdup, ':', keys);
2046  } else {
2047  keys[0] = (char *)key;
2048  nkeys = 1;
2049  }
2050 
2051  for(i = 0; i < nkeys; i++) {
2052  if ((status = switch_xml_locate_user_cache(keys[i], user_name, domain_name, &x_user)) == SWITCH_STATUS_SUCCESS) {
2053  *user = x_user;
2054  break;
2055  } else if ((status = switch_xml_locate_user(keys[i], user_name, domain_name, ip, &xml, &domain, &x_user, &group, params)) == SWITCH_STATUS_SUCCESS) {
2056  const char *cacheable = NULL;
2057 
2058  x_user_dup = switch_xml_dup(x_user);
2059  switch_xml_merge_user(x_user_dup, domain, group);
2060 
2061  cacheable = switch_xml_attr(x_user_dup, "cacheable");
2062  if (!zstr(cacheable)) {
2063  switch_time_t expires = 0;
2064  switch_time_t time_now = 0;
2065 
2066  if (switch_is_number(cacheable)) {
2067  int cache_ms = atol(cacheable);
2068  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s for %d milliseconds\n",
2069  user_name, domain_name, cache_ms);
2070  time_now = switch_micro_time_now();
2071  expires = time_now + (cache_ms * 1000);
2072  } else {
2073  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s indefinitely\n", user_name, domain_name);
2074  }
2075  switch_xml_user_cache(keys[i], user_name, domain_name, x_user_dup, expires);
2076  }
2077  *user = x_user_dup;
2078  switch_xml_free(xml);
2079  break;
2080  }
2081  }
2082 
2083  switch_safe_free(kdup);
2084 
2085  return status;
2086 
2087 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
#define SWITCH_CHANNEL_LOG
const char * switch_xml_attr(switch_xml_t xml, const char *attr)
Definition: switch_xml.c:434
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:520
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:342
static void switch_xml_user_cache(const char *key, const char *user_name, const char *domain_name, switch_xml_t user, switch_time_t expires)
Definition: switch_xml.c:2005
switch_bool_t switch_is_number(const char *str)
A representation of an XML tree.
Definition: switch_xml.h:76
static switch_status_t switch_xml_locate_user_cache(const char *key, const char *user_name, const char *domain_name, switch_xml_t *user)
Definition: switch_xml.c:1970
#define zstr(x)
Definition: switch_utils.h:281
switch_xml_t switch_xml_dup(switch_xml_t xml)
Definition: switch_xml.c:1862
int64_t switch_time_t
Definition: switch_apr.h:188
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:789
switch_status_t switch_xml_locate_user(const char *key, const char *user_name, const char *domain_name, const char *ip, switch_xml_t *root, switch_xml_t *domain, switch_xml_t *user, switch_xml_t *ingroup, switch_event_t *params)
Definition: switch_xml.c:2089
static char * switch_must_strdup(const char *_s)
Definition: switch_core.h:245
switch_status_t
Common return values.
void switch_xml_merge_user(switch_xml_t user, switch_xml_t domain, switch_xml_t group)
Definition: switch_xml.c:1904
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2701
void switch_xml_merge_user ( switch_xml_t  user,
switch_xml_t  domain,
switch_xml_t  group 
)

Definition at line 1904 of file switch_xml.c.

References do_merge(), switch_xml_attr(), switch_xml_set_attr_d, and zstr.

Referenced by switch_xml_locate_user_merged().

1905 {
1906  const char *domain_name = switch_xml_attr(domain, "name");
1907 
1908  do_merge(user, group, "params", "param");
1909  do_merge(user, group, "variables", "variable");
1910  do_merge(user, group, "profile-variables", "variable");
1911  do_merge(user, domain, "params", "param");
1912  do_merge(user, domain, "variables", "variable");
1913  do_merge(user, domain, "profile-variables", "variable");
1914 
1915  if (!zstr(domain_name)) {
1916  switch_xml_set_attr_d(user, "domain-name", domain_name);
1917  }
1918 }
const char * switch_xml_attr(switch_xml_t xml, const char *attr)
Definition: switch_xml.c:434
#define zstr(x)
Definition: switch_utils.h:281
static void do_merge(switch_xml_t in, switch_xml_t src, const char *container, const char *tag_name)
Definition: switch_xml.c:1869
#define switch_xml_set_attr_d(xml, name, value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
Definition: switch_xml.h:299
switch_xml_t switch_xml_new ( _In_opt_z_ const char *  name)

returns a new empty switch_xml structure with the given root tag name

Parameters
namethe name of the new root tag

Referenced by switch_event_xmlize(), and switch_ivr_generate_xml_cdr().

switch_xml_t switch_xml_open_cfg ( _In_z_ const char *  file_path,
_Out_ switch_xml_t node,
_In_opt_ switch_event_t params 
)

open a config in the core registry

Parameters
file_paththe name of the config section e.g. modules.conf
nodea pointer to point to the node if it is found
paramsoptional URL formatted params to pass to external gateways
Returns
the root xml node associated with the current request or NULL

Referenced by console_xml_config(), load_configuration(), switch_ivr_check_presence_mapping(), switch_load_core_config(), switch_load_network_lists(), switch_load_timezones(), switch_loadable_module_init(), and switch_xml_config_parse_module_settings().

switch_xml_t switch_xml_open_root ( _In_ uint8_t  reload,
_Out_ const char **  err 
)

open the Core xml root

Parameters
reloadif it's is already open close it and open it again as soon as permissable (blocking)
erra pointer to set error strings
Returns
the xml root node or NULL
switch_xml_t switch_xml_parse_fd ( int  fd)

A wrapper for switch_xml_parse_str() that accepts a file descriptor. First \ attempts to mem map the file. Failing that, reads the file into memory. \ Returns NULL on failure.

Parameters
fd
Returns
a formated xml node or NULL

Definition at line 1157 of file switch_xml.c.

References switch_xml_root::dynamic, switch_must_malloc(), switch_xml_parse_str(), and switch_xml_root::xml.

Referenced by switch_xml_parse_file().

1158 {
1159  switch_xml_root_t root;
1160  struct stat st;
1161  switch_ssize_t l;
1162  void *m;
1163 
1164  if (fd < 0)
1165  return NULL;
1166  fstat(fd, &st);
1167 
1168  if (!st.st_size) {
1169  return NULL;
1170  }
1171 
1172  m = switch_must_malloc(st.st_size);
1173 
1174  if (!(0<(l = read(fd, m, st.st_size)))
1175  || !(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) {
1176  free(m);
1177  return NULL;
1178  }
1179  root->dynamic = 1; /* so we know to free s in switch_xml_free() */
1180 
1181  return &root->xml;
1182 }
static void * switch_must_malloc(size_t _b)
Definition: switch_core.h:231
intptr_t switch_ssize_t
struct switch_xml xml
Definition: switch_xml.c:148
switch_xml_t switch_xml_parse_str(char *s, switch_size_t len)
Definition: switch_xml.c:982
uint8_t dynamic
Definition: switch_xml.c:152
switch_xml_t switch_xml_parse_file ( _In_z_ const char *  file)

a wrapper for switch_xml_parse_fd() that accepts a file name

Parameters
filea file to parse
Returns
a formated xml node or NULL
switch_xml_t switch_xml_parse_file_simple ( _In_z_ const char *  file)
switch_xml_t switch_xml_parse_fp ( _In_ FILE *  fp)

Wrapper for switch_xml_parse_str() that accepts a file stream. Reads the entire \ stream into memory and then parses it. For xml files, use switch_xml_parse_file() \ or switch_xml_parse_fd()

Parameters
fpa FILE pointer to parse
Returns
an xml node or NULL
switch_xml_section_t switch_xml_parse_section_string ( _In_opt_z_ const char *  str)

parse a string for a list of sections

Parameters
stra | delimited list of section names
Returns
the section mask
switch_xml_t switch_xml_parse_str ( _In_z_ char *  s,
_In_ switch_size_t  len 
)

Given a string of xml data and its length, parses it and creates an switch_xml \ structure. For efficiency, modifies the data by adding null terminators \ and decoding ampersand sequences. If you don't want this, copy the data and \ pass in the copy. Returns NULL on failure.

Parameters
sa string
lenthe length of the string
Returns
a formated xml node or NULL
switch_xml_t switch_xml_parse_str_dynamic ( _In_z_ char *  s,
_In_ switch_bool_t  dup 
)

Parses a string into a switch_xml_t, ensuring the memory will be freed with switch_xml_free.

Parameters
sThe string to parse
duptrue if you want the string to be strdup()'d automatically
Returns
the switch_xml_t or NULL if an error occured

Referenced by recover_callback().

const char** switch_xml_pi ( _In_ switch_xml_t  xml,
_In_z_ const char *  target 
)

returns a NULL terminated array of processing instructions for the given \ target

Parameters
xmlthe xml node
targetthe instructions
Returns
the array
switch_status_t switch_xml_reload ( const char **  err)

Definition at line 2321 of file switch_xml.c.

References SWITCH_STATUS_GENERR, SWITCH_STATUS_SUCCESS, switch_xml_free(), and switch_xml_open_root().

2322 {
2323  switch_xml_t xml_root;
2324 
2325  if ((xml_root = switch_xml_open_root(1, err))) {
2326  switch_xml_free(xml_root);
2327  return SWITCH_STATUS_SUCCESS;
2328  }
2329 
2330  return SWITCH_STATUS_GENERR;
2331 }
switch_xml_t switch_xml_open_root(uint8_t reload, const char **err)
Definition: switch_xml.c:2256
A representation of an XML tree.
Definition: switch_xml.h:76
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2701

retrieve the core XML root node

Returns
the xml root node
Note
this will cause a readlock on the root until it's released with
See also
switch_xml_free

Definition at line 2166 of file switch_xml.c.

References MAIN_XML_ROOT, switch_xml::refs, switch_mutex_lock(), and switch_mutex_unlock().

Referenced by __switch_xml_open_root(), and switch_xml_locate().

2167 {
2168  switch_xml_t xml;
2169 
2171  xml = MAIN_XML_ROOT;
2172  xml->refs++;
2174 
2175  return xml;
2176 }
uint32_t refs
Definition: switch_xml.h:101
static switch_mutex_t * REFLOCK
Definition: switch_xml.c:180
A representation of an XML tree.
Definition: switch_xml.h:76
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static switch_xml_t MAIN_XML_ROOT
Definition: switch_xml.c:174
switch_xml_t switch_xml_set_attr ( switch_xml_t  xml,
const char *  name,
const char *  value 
)

Sets the given tag attribute or adds a new attribute if not found. A value \ of NULL will remove the specified attribute.

Parameters
xmlthe xml node
namethe attribute name
valuethe attribute value
Returns
the tag given

Definition at line 2884 of file switch_xml.c.

References switch_xml::attr, switch_must_malloc(), switch_must_realloc(), switch_must_strdup(), SWITCH_XML_DUP, SWITCH_XML_NAMEM, SWITCH_XML_TXTM, and destroy_xml::xml.

2885 {
2886  int l = 0, c;
2887 
2888  if (!xml)
2889  return NULL;
2890  while (xml->attr[l] && strcmp(xml->attr[l], name))
2891  l += 2;
2892  if (!xml->attr[l]) { /* not found, add as new attribute */
2893  if (!value)
2894  return xml; /* nothing to do */
2895  if (xml->attr == SWITCH_XML_NIL) { /* first attribute */
2896  xml->attr = (char **) switch_must_malloc(4 * sizeof(char *));
2897  xml->attr[1] = switch_must_strdup(""); /* empty list of malloced names/vals */
2898  } else {
2899  xml->attr = (char **) switch_must_realloc(xml->attr, (l + 4) * sizeof(char *));
2900  }
2901 
2902  xml->attr[l] = (char *) name; /* set attribute name */
2903  xml->attr[l + 2] = NULL; /* null terminate attribute list */
2904  xml->attr[l + 3] = (char *) switch_must_realloc(xml->attr[l + 1], (c = (int) strlen(xml->attr[l + 1])) + 2);
2905  strcpy(xml->attr[l + 3] + c, " "); /* set name/value as not malloced */
2906  if (xml->flags & SWITCH_XML_DUP)
2907  xml->attr[l + 3][c] = SWITCH_XML_NAMEM;
2908  } else if (xml->flags & SWITCH_XML_DUP)
2909  free((char *) name); /* name was strduped */
2910 
2911  for (c = l; xml->attr[c]; c += 2); /* find end of attribute list */
2912  if (xml->attr[c + 1][l / 2] & SWITCH_XML_TXTM)
2913  free(xml->attr[l + 1]); /* old val */
2914  if (xml->flags & SWITCH_XML_DUP)
2915  xml->attr[c + 1][l / 2] |= SWITCH_XML_TXTM;
2916  else
2917  xml->attr[c + 1][l / 2] &= ~SWITCH_XML_TXTM;
2918 
2919  if (value)
2920  xml->attr[l + 1] = (char *) value; /* set attribute value */
2921  else { /* remove attribute */
2922  if (xml->attr[c + 1][l / 2] & SWITCH_XML_NAMEM)
2923  free(xml->attr[l]);
2924  memmove(xml->attr + l, xml->attr + l + 2, (c - l + 2) * sizeof(char *));
2925  xml->attr = (char **) switch_must_realloc(xml->attr, (c + 2) * sizeof(char *));
2926  memmove(xml->attr[c + 1] + (l / 2), xml->attr[c + 1] + (l / 2) + 1, (c / 2) - (l / 2)); /* fix list of which name/vals are malloced */
2927  }
2928  xml->flags &= ~SWITCH_XML_DUP; /* clear strdup() flag */
2929 
2930  return xml;
2931 }
static void * switch_must_malloc(size_t _b)
Definition: switch_core.h:231
static void * switch_must_realloc(void *_b, size_t _z)
Definition: switch_core.h:238
static char * switch_must_strdup(const char *_s)
Definition: switch_core.h:245
char ** attr
Definition: switch_xml.h:80
uint32_t flags
Definition: switch_xml.h:98
char * SWITCH_XML_NIL[]
Definition: switch_xml.c:163
void switch_xml_set_binding_sections ( _In_ switch_xml_binding_t binding,
_In_ switch_xml_section_t  sections 
)

bind a search function to an external gateway

Parameters
functionthe search function to bind
sectionsa bitmask of sections you wil service
user_dataa pointer to private data to be used during the callback
Returns
SWITCH_STATUS_SUCCESS if successful
Note
gateway functions will be executed in the order they were binded until a success is found else the root registry will be used
void switch_xml_set_binding_user_data ( _In_ switch_xml_binding_t binding,
_In_opt_ void *  user_data 
)
switch_xml_t switch_xml_set_flag ( switch_xml_t  xml,
switch_xml_flag_t  flag 
)

sets a flag for the given tag and returns the tag

Parameters
xmlthe xml node
flagthe flag to set
Returns
an xml node or NULL

Definition at line 2934 of file switch_xml.c.

References switch_xml::flags, and destroy_xml::xml.

Referenced by switch_xml_char_content().

2935 {
2936  if (xml)
2937  xml->flags |= flag;
2938  return xml;
2939 }
uint32_t flags
Definition: switch_xml.h:98
switch_status_t switch_xml_set_open_root_function ( switch_xml_open_root_function_t  func,
void *  user_data 
)

Set and alternate function for opening xml root.

Definition at line 2241 of file switch_xml.c.

References switch_mutex_lock(), switch_mutex_unlock(), SWITCH_STATUS_SUCCESS, XML_OPEN_ROOT_FUNCTION, and XML_OPEN_ROOT_FUNCTION_USER_DATA.

2242 {
2243  if (XML_LOCK) {
2245  }
2246 
2247  XML_OPEN_ROOT_FUNCTION = func;
2249 
2250  if (XML_LOCK) {
2252  }
2253  return SWITCH_STATUS_SUCCESS;
2254 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static void * XML_OPEN_ROOT_FUNCTION_USER_DATA
Definition: switch_xml.c:186
static switch_xml_open_root_function_t XML_OPEN_ROOT_FUNCTION
Definition: switch_xml.c:185
static switch_mutex_t * XML_LOCK
Definition: switch_xml.c:178
switch_status_t switch_xml_set_root ( switch_xml_t  new_main)

set new core xml root

Definition at line 2215 of file switch_xml.c.

References MAIN_XML_ROOT, switch_xml::refs, switch_mutex_lock(), switch_mutex_unlock(), switch_set_flag, SWITCH_STATUS_SUCCESS, switch_xml_free(), and SWITCH_XML_ROOT.

Referenced by __switch_xml_open_root().

2216 {
2217  switch_xml_t old_root = NULL;
2218 
2220 
2221  old_root = MAIN_XML_ROOT;
2222  MAIN_XML_ROOT = new_main;
2224  MAIN_XML_ROOT->refs++;
2225 
2226  if (old_root) {
2227  if (old_root->refs) {
2228  old_root->refs--;
2229  }
2230 
2231  if (!old_root->refs) {
2232  switch_xml_free(old_root);
2233  }
2234  }
2235 
2237 
2238  return SWITCH_STATUS_SUCCESS;
2239 }
uint32_t refs
Definition: switch_xml.h:101
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:631
static switch_mutex_t * REFLOCK
Definition: switch_xml.c:180
A representation of an XML tree.
Definition: switch_xml.h:76
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:290
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:285
static switch_xml_t MAIN_XML_ROOT
Definition: switch_xml.c:174
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2701
switch_xml_t switch_xml_set_txt ( switch_xml_t  xml,
const char *  txt 
)

sets the character content for the given tag and returns the tag

Parameters
xmlthe xml node
txtthe text
Returns
an xml node or NULL

Definition at line 2871 of file switch_xml.c.

References SWITCH_XML_TXTM, and destroy_xml::xml.

2872 {
2873  if (!xml)
2874  return NULL;
2875  if (xml->flags & SWITCH_XML_TXTM)
2876  free(xml->txt); /* existing txt was malloced */
2877  xml->flags &= ~SWITCH_XML_TXTM;
2878  xml->txt = (char *) txt;
2879  return xml;
2880 }
char * txt
Definition: switch_xml.h:82
uint32_t flags
Definition: switch_xml.h:98
int switch_xml_std_datetime_check ( switch_xml_t  xcond,
int *  offset,
const char *  tzname 
)

Definition at line 2980 of file switch_xml.c.

References SWITCH_CHANNEL_LOG, switch_dow_cmp(), switch_dow_int2str(), switch_fulldate_cmp(), switch_is_number(), SWITCH_LOG_DEBUG, SWITCH_LOG_DEBUG9, switch_log_printf(), switch_micro_time_now(), switch_number_cmp(), switch_snprintf(), switch_strftime(), switch_time_exp_lt(), switch_time_exp_tz(), switch_time_exp_tz_name(), switch_tod_cmp(), switch_true(), switch_xml_attr(), switch_time_exp_t::tm_gmtoff, switch_time_exp_t::tm_hour, switch_time_exp_t::tm_isdst, switch_time_exp_t::tm_mday, switch_time_exp_t::tm_min, switch_time_exp_t::tm_mon, switch_time_exp_t::tm_sec, switch_time_exp_t::tm_wday, switch_time_exp_t::tm_yday, switch_time_exp_t::tm_year, and zstr.

2981 {
2982 
2983  const char *xdt = switch_xml_attr(xcond, "date-time");
2984  const char *xyear = switch_xml_attr(xcond, "year");
2985  const char *xyday = switch_xml_attr(xcond, "yday");
2986  const char *xmon = switch_xml_attr(xcond, "mon");
2987  const char *xmday = switch_xml_attr(xcond, "mday");
2988  const char *xweek = switch_xml_attr(xcond, "week");
2989  const char *xmweek = switch_xml_attr(xcond, "mweek");
2990  const char *xwday = switch_xml_attr(xcond, "wday");
2991  const char *xhour = switch_xml_attr(xcond, "hour");
2992  const char *xminute = switch_xml_attr(xcond, "minute");
2993  const char *xminday = switch_xml_attr(xcond, "minute-of-day");
2994  const char *xtod = switch_xml_attr(xcond, "time-of-day");
2995  const char *tzoff = switch_xml_attr(xcond, "tz-offset");
2996  const char *isdst = switch_xml_attr(xcond, "dst");
2997 
2998  int loffset = -1000;
2999  int eoffset = -1000;
3000  int dst = -1000;
3002  int time_match = -1;
3003  switch_time_exp_t tm, tm2;
3004 
3005  if (!zstr(isdst)) {
3006  dst = switch_true(isdst);
3007  }
3008 
3009  if (!zstr(tzoff) && switch_is_number(tzoff)) {
3010  loffset = atoi(tzoff);
3011  }
3012 
3013  switch_time_exp_lt(&tm2, ts);
3014 
3015  if (offset) {
3016  eoffset = *offset;
3017  switch_time_exp_tz(&tm, ts, *offset * 3600);
3018  } else if (!zstr(tzname)) {
3019  switch_time_exp_tz_name(tzname, &tm, ts);
3020  } else {
3021  tm = tm2;
3022  }
3023 
3024  if (eoffset == -1000) {
3025  eoffset = tm.tm_gmtoff / 3600;
3026  }
3027 
3028  if (loffset == -1000) {
3029  loffset = eoffset;
3030  }
3031 
3032 
3033  if (time_match && tzoff) {
3034  time_match = loffset == eoffset;
3036  "XML DateTime Check: TZOFFSET[%d] == %d (%s)\n", eoffset, loffset, time_match ? "PASS" : "FAIL");
3037 
3038  }
3039 
3040  if (time_match && dst > -1) {
3041  time_match = (tm2.tm_isdst > 0 && dst > 0);
3043  "XML DateTime Check: DST[%s] == %s (%s)\n",
3044  tm2.tm_isdst > 0 ? "true" : "false", dst > 0 ? "true" : "false", time_match ? "PASS" : "FAIL");
3045 
3046  }
3047 
3048  if (time_match && xdt) {
3049  char tmpdate[80];
3050  switch_size_t retsize;
3051  switch_strftime(tmpdate, &retsize, sizeof(tmpdate), "%Y-%m-%d %H:%M:%S", &tm);
3052  time_match = switch_fulldate_cmp(xdt, &ts);
3054  "XML DateTime Check: date time[%s] =~ %s (%s)\n", tmpdate, xdt, time_match ? "PASS" : "FAIL");
3055  }
3056 
3057  if (time_match && xyear) {
3058  int test = tm.tm_year + 1900;
3059  time_match = switch_number_cmp(xyear, test);
3061  "XML DateTime Check: year[%d] =~ %s (%s)\n", test, xyear, time_match ? "PASS" : "FAIL");
3062  }
3063 
3064  if (time_match && xyday) {
3065  int test = tm.tm_yday + 1;
3066  time_match = switch_number_cmp(xyday, test);
3068  "XML DateTime Check: day of year[%d] =~ %s (%s)\n", test, xyday, time_match ? "PASS" : "FAIL");
3069  }
3070 
3071  if (time_match && xmon) {
3072  int test = tm.tm_mon + 1;
3073  time_match = switch_number_cmp(xmon, test);
3075  "XML DateTime Check: month[%d] =~ %s (%s)\n", test, xmon, time_match ? "PASS" : "FAIL");
3076  }
3077 
3078  if (time_match && xmday) {
3079  int test = tm.tm_mday;
3080  time_match = switch_number_cmp(xmday, test);
3082  "XML DateTime Check: day of month[%d] =~ %s (%s)\n", test, xmday, time_match ? "PASS" : "FAIL");
3083  }
3084 
3085  if (time_match && xweek) {
3086  int test = (int) (tm.tm_yday / 7 + 1);
3087  time_match = switch_number_cmp(xweek, test);
3089  "XML DateTime Check: week of year[%d] =~ %s (%s)\n", test, xweek, time_match ? "PASS" : "FAIL");
3090  }
3091  if (time_match && xweek) {
3092  int test = (int) (tm.tm_yday / 7 + 1);
3093  time_match = switch_number_cmp(xweek, test);
3095  "XML DateTime Check: week of year[%d] =~ %s (%s)\n", test, xweek, time_match ? "PASS" : "FAIL");
3096  }
3097 
3098  if (time_match && xmweek) {
3099  /* calculate the day of the week of the first of the month (0-6) */
3100  int firstdow = (int) (7 - (tm.tm_mday - (tm.tm_wday + 1)) % 7) % 7;
3101  /* calculate the week of the month (1-6)*/
3102  int test = (int) ceil((tm.tm_mday + firstdow) / 7.0);
3103  time_match = switch_number_cmp(xmweek, test);
3105  "XML DateTime: week of month[%d] =~ %s (%s)\n", test, xmweek, time_match ? "PASS" : "FAIL");
3106  }
3107 
3108  if (time_match && xwday) {
3109  int test = tm.tm_wday + 1;
3110  time_match = switch_dow_cmp(xwday, test);
3112  "XML DateTime Check: day of week[%s] =~ %s (%s)\n", switch_dow_int2str(test), xwday, time_match ? "PASS" : "FAIL");
3113  }
3114  if (time_match && xhour) {
3115  int test = tm.tm_hour;
3116  time_match = switch_number_cmp(xhour, test);
3118  "XML DateTime Check: hour[%d] =~ %s (%s)\n", test, xhour, time_match ? "PASS" : "FAIL");
3119  }
3120 
3121  if (time_match && xminute) {
3122  int test = tm.tm_min;
3123  time_match = switch_number_cmp(xminute, test);
3125  "XML DateTime Check: minute[%d] =~ %s (%s)\n", test, xminute, time_match ? "PASS" : "FAIL");
3126  }
3127 
3128  if (time_match && xminday) {
3129  int test = (tm.tm_hour * 60) + (tm.tm_min + 1);
3130  time_match = switch_number_cmp(xminday, test);
3132  "XML DateTime Check: minute of day[%d] =~ %s (%s)\n", test, xminday, time_match ? "PASS" : "FAIL");
3133  }
3134 
3135  if (time_match && xtod) {
3136  int test = (tm.tm_hour * 60 * 60) + (tm.tm_min * 60) + tm.tm_sec;
3137  char tmpdate[10];
3138  switch_snprintf(tmpdate, 10, "%d:%d:%d", tm.tm_hour, tm.tm_min, tm.tm_sec);
3139  time_match = switch_tod_cmp(xtod, test);
3141  "XML DateTime Check: time of day[%s] =~ %s (%s)\n", tmpdate, xtod, time_match ? "PASS" : "FAIL");
3142  }
3143 
3144  return time_match;
3145 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:310
#define SWITCH_CHANNEL_LOG
const char * switch_xml_attr(switch_xml_t xml, const char *attr)
Definition: switch_xml.c:434
switch_bool_t switch_is_number(const char *str)
switch_status_t switch_time_exp_lt(switch_time_exp_t *result, switch_time_t input)
Definition: switch_apr.c:323
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
static int switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:450
#define zstr(x)
Definition: switch_utils.h:281
switch_bool_t switch_dow_cmp(const char *exp, int val)
int64_t switch_time_t
Definition: switch_apr.h:188
uintptr_t switch_size_t
switch_status_t switch_time_exp_tz(switch_time_exp_t *result, switch_time_t input, switch_int32_t offs)
Definition: switch_apr.c:328
const char * switch_dow_int2str(int val)
int switch_tod_cmp(const char *exp, int val)
int switch_number_cmp(const char *exp, int val)
void switch_log_printf(_In_ switch_text_channel_t channel, _In_z_ const char *file, _In_z_ const char *func, _In_ int line, _In_opt_z_ const char *userdata, _In_ switch_log_level_t level, _In_z_ _Printf_format_string_ const char *fmt,...) PRINTF_FUNCTION(7
Write log data to the logging engine.
switch_status_t switch_strftime(char *s, switch_size_t *retsize, switch_size_t max, const char *format, switch_time_exp_t *tm)
Definition: switch_apr.c:127
switch_status_t switch_time_exp_tz_name(const char *tz, switch_time_exp_t *tm, switch_time_t thetime)
Definition: switch_time.c:1427
int switch_fulldate_cmp(const char *exp, switch_time_t *ts)
char* switch_xml_tohtml ( _In_ switch_xml_t  xml,
_In_ switch_bool_t  prn_header 
)
char* switch_xml_toxml ( _In_ switch_xml_t  xml,
_In_ switch_bool_t  prn_header 
)

Converts an switch_xml structure back to xml in html format. Returns a string of html data that \ must be freed.

Parameters
xmlthe xml node
prn_headeradd <?xml version..> header too
Returns
the ampersanded html text string to display xml

Referenced by CoreSession::getXMLCDR(), Event::serialize(), switch_core_session_reporting_state(), switch_ivr_multi_threaded_bridge(), and switch_ivr_originate().

char* switch_xml_toxml_buf ( _In_ switch_xml_t  xml,
_In_z_ char *  buf,
_In_ switch_size_t  buflen,
_In_ switch_size_t  offset,
_In_ switch_bool_t  prn_header 
)

Converts an switch_xml structure back to xml using the buffer passed in the parameters.

Parameters
xmlthe xml node
bufbuffer to use
buflensize of buffer
offsetoffset to start at
prn_headeradd <?xml version..> header too
Returns
the xml text string
char* switch_xml_toxml_nolock ( switch_xml_t  xml,
_In_ switch_bool_t  prn_header 
)
switch_status_t switch_xml_unbind_search_function ( _In_ switch_xml_binding_t **  binding)
switch_status_t switch_xml_unbind_search_function_ptr ( _In_ switch_xml_search_function_t  function)