RTS API Documentation  1.10.11
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_toxml(xml, prn_header)   switch_xml_toxml_ex(xml, prn_header, USE_UTF_8_ENCODING)
 Converts an switch_xml structure back to xml in html format. Returns a string of html data that \ must be freed. More...
 
#define switch_xml_toxml_nolock(xml, prn_header)   switch_xml_toxml_nolock_ex(xml, prn_header, USE_UTF_8_ENCODING)
 
#define switch_xml_tohtml(xml, prn_header)   switch_xml_tohtml_ex(xml, prn_header, USE_UTF_8_ENCODING)
 
#define switch_xml_toxml_buf(xml, buf, buflen, offset, prn_header)   switch_xml_toxml_buf_ex(xml, buf, buflen, offset, prn_header, USE_UTF_8_ENCODING);
 Converts an switch_xml structure back to xml using the buffer passed in the parameters. 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_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),
  SWITCH_XML_CDATA = (1 << 4)
}
 

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_ex (_In_ switch_xml_t xml, _In_ switch_bool_t prn_header, switch_bool_t use_utf8_encoding)
 
char * switch_xml_toxml_nolock_ex (switch_xml_t xml, _In_ switch_bool_t prn_header, switch_bool_t use_utf8_encoding)
 
char * switch_xml_tohtml_ex (_In_ switch_xml_t xml, _In_ switch_bool_t prn_header, switch_bool_t use_utf8_encoding)
 
char * switch_xml_toxml_buf_ex (_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, switch_bool_t use_utf8_encoding)
 
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_add_child_d (_In_ switch_xml_t xml, _In_z_ const char *name, _In_ switch_size_t off)
 wrapper for switch_xml_add_child() that strdup()s name 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_txt_d (switch_xml_t xml, const char *txt)
 wrapper for switch_xml_set_txt() that strdup()s 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_attr_d (switch_xml_t xml, const char *name, const char *value)
 Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL. More...
 
switch_xml_t switch_xml_set_attr_d_buf (switch_xml_t xml, const char *name, const char *value)
 Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL. 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

◆ switch_xml_bind_search_function

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

Definition at line 431 of file switch_xml.h.

◆ SWITCH_XML_BUFSIZE

#define SWITCH_XML_BUFSIZE   1024

◆ switch_xml_move

#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 336 of file switch_xml.h.

◆ switch_xml_name

#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 189 of file switch_xml.h.

◆ switch_xml_new_d

#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 270 of file switch_xml.h.

◆ switch_xml_next

#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 177 of file switch_xml.h.

Referenced by switch_nat_republish().

◆ switch_xml_parse_str_dup

#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 124 of file switch_xml.h.

Referenced by switch_nat_republish().

◆ switch_xml_remove

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

removes a tag along with all its subtags

Definition at line 339 of file switch_xml.h.

◆ switch_xml_tohtml

#define switch_xml_tohtml (   xml,
  prn_header 
)    switch_xml_tohtml_ex(xml, prn_header, USE_UTF_8_ENCODING)

Definition at line 226 of file switch_xml.h.

◆ switch_xml_toxml

#define switch_xml_toxml (   xml,
  prn_header 
)    switch_xml_toxml_ex(xml, prn_header, USE_UTF_8_ENCODING)

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
use_utf8_encodingencoding into ampersand entities for UTF-8 chars
Returns
the ampersanded html text string to display xml

Definition at line 224 of file switch_xml.h.

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

◆ switch_xml_toxml_buf

#define switch_xml_toxml_buf (   xml,
  buf,
  buflen,
  offset,
  prn_header 
)    switch_xml_toxml_buf_ex(xml, buf, buflen, offset, prn_header, USE_UTF_8_ENCODING);

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
use_utf8_encodingencoding into ampersand entities for UTF-8 chars
Returns
the xml text string

Definition at line 240 of file switch_xml.h.

◆ switch_xml_toxml_nolock

#define switch_xml_toxml_nolock (   xml,
  prn_header 
)    switch_xml_toxml_nolock_ex(xml, prn_header, USE_UTF_8_ENCODING)

Definition at line 225 of file switch_xml.h.

Referenced by switch_core_recovery_track().

◆ switch_xml_txt

#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 194 of file switch_xml.h.

Enumeration Type Documentation

◆ switch_xml_flag_t

Enumerator
SWITCH_XML_ROOT 
SWITCH_XML_NAMEM 
SWITCH_XML_TXTM 
SWITCH_XML_DUP 
SWITCH_XML_CDATA 

Definition at line 70 of file switch_xml.h.

70  {
71  SWITCH_XML_ROOT = (1 << 0), // root
72  SWITCH_XML_NAMEM = (1 << 1), // name is malloced
73  SWITCH_XML_TXTM = (1 << 2), // txt is malloced
74  SWITCH_XML_DUP = (1 << 3), // attribute name and value are strduped
75  SWITCH_XML_CDATA = (1 << 4) // body is in CDATA
switch_xml_flag_t
Definition: switch_xml.h:70

Function Documentation

◆ switch_xml_add_child()

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

◆ switch_xml_add_child_d()

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

◆ switch_xml_attr()

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().

◆ switch_xml_attr_soft()

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(), load_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_xml_bind_search_function_ret()

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_child()

switch_xml_t switch_xml_child ( _In_ switch_xml_t  xml,
_In_z_ const char *  name 
)

◆ switch_xml_clear_user_cache()

uint32_t switch_xml_clear_user_cache ( const char *  key,
const char *  user_name,
const char *  domain_name 
)

Definition at line 2028 of file switch_xml.c.

References switch_core_get_variable(), 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().

2029 {
2030  switch_hash_index_t *hi = NULL;
2031  void *val;
2032  const void *var;
2033  char mega_key[1024];
2034  int r = 0;
2035  switch_xml_t lookup;
2036  char *expires_val = NULL;
2037 
2039 
2040  if (key && user_name && !domain_name) {
2041  domain_name = switch_core_get_variable("domain");
2042  }
2043 
2044  if (key && user_name && domain_name) {
2045  switch_snprintf(mega_key, sizeof(mega_key), "%s%s%s", key, user_name, domain_name);
2046 
2047  if ((lookup = switch_core_hash_find(CACHE_HASH, mega_key))) {
2049  if ((expires_val = switch_core_hash_find(CACHE_EXPIRES_HASH, mega_key))) {
2051  free(expires_val);
2052  expires_val = NULL;
2053  }
2054  switch_xml_free(lookup);
2055  r++;
2056  }
2057 
2058  } else {
2059 
2060  while ((hi = switch_core_hash_first_iter( CACHE_HASH, hi))) {
2061  switch_core_hash_this(hi, &var, NULL, &val);
2062  switch_xml_free(val);
2064  r++;
2065  }
2066 
2067  while ((hi = switch_core_hash_first_iter( CACHE_EXPIRES_HASH, hi))) {
2068  switch_core_hash_this(hi, &var, NULL, &val);
2069  switch_safe_free(val);
2071  }
2072 
2073  switch_safe_free(hi);
2074  }
2075 
2077 
2078  return r;
2079 
2080 }
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:79
static switch_hash_t * CACHE_HASH
Definition: switch_xml.c:244
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:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
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.
char * switch_core_get_variable(_In_z_ const char *varname)
Retrieve a global variable from the core.
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:245
char * key
Definition: switch_msrp.c:64
static switch_mutex_t * CACHE_MUTEX
Definition: switch_xml.c:235
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2815
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_cut()

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_xml_destroy()

switch_status_t switch_xml_destroy ( void  )

Definition at line 2473 of file switch_xml.c.

References 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().

2474 {
2476 
2477 
2480 
2481  if (MAIN_XML_ROOT) {
2483  MAIN_XML_ROOT = NULL;
2484  switch_xml_free(xml);
2485  status = SWITCH_STATUS_SUCCESS;
2486  }
2487 
2490 
2491  switch_xml_clear_user_cache(NULL, NULL, NULL);
2492 
2495 
2496  return status;
2497 }
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:236
A representation of an XML tree.
Definition: switch_xml.h:79
static switch_hash_t * CACHE_HASH
Definition: switch_xml.c:244
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_xml_t MAIN_XML_ROOT
Definition: switch_xml.c:230
uint32_t switch_xml_clear_user_cache(const char *key, const char *user_name, const char *domain_name)
Definition: switch_xml.c:2028
static switch_hash_t * CACHE_EXPIRES_HASH
Definition: switch_xml.c:245
switch_status_t
Common return values.
static switch_mutex_t * XML_LOCK
Definition: switch_xml.c:234
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2815

◆ switch_xml_dup()

switch_xml_t switch_xml_dup ( switch_xml_t  xml)

Definition at line 1970 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().

1971 {
1972  char *x = switch_xml_toxml(xml, SWITCH_FALSE);
1974 }
switch_xml_t switch_xml_parse_str_dynamic(char *s, switch_bool_t dup)
Definition: switch_xml.c:1033
#define switch_xml_toxml(xml, prn_header)
Converts an switch_xml structure back to xml in html format. Returns a string of html data that \ mus...
Definition: switch_xml.h:224

◆ switch_xml_error()

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_find_child()

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_find_child_multi()

switch_xml_t switch_xml_find_child_multi ( _In_ switch_xml_t  node,
_In_z_ const char *  childname,
  ... 
)

◆ switch_xml_free()

void switch_xml_free ( _In_opt_ switch_xml_t  xml)

◆ switch_xml_free_in_thread()

void switch_xml_free_in_thread ( _In_ switch_xml_t  xml,
_In_ int  stacksize 
)

◆ switch_xml_get()

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_get_binding_sections()

switch_xml_section_t switch_xml_get_binding_sections ( _In_ switch_xml_binding_t binding)

◆ switch_xml_get_binding_user_data()

void* switch_xml_get_binding_user_data ( _In_ switch_xml_binding_t binding)

◆ switch_xml_idx()

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_xml_init()

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_insert()

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_xml_locate()

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_xml_locate_domain()

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_xml_locate_group()

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_xml_locate_language()

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 3356 of file switch_xml.c.

References memset(), name, path, pool, switch_assert, SWITCH_CHANNEL_LOG, switch_event_add_header_string(), switch_log_printf(), SWITCH_LOG_WARNING, switch_must_malloc(), switch_must_realloc(), switch_safe_free, SWITCH_STACK_BOTTOM, SWITCH_STATUS_SUCCESS, switch_xml_locate_language_ex(), and while().

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

3356  {
3357  switch_status_t status;
3358 
3359  if ((status = switch_xml_locate_language_ex(root, node, params, language, phrases, macros, str_language)) != SWITCH_STATUS_SUCCESS) {
3360  char *str_language_dup = strdup(str_language);
3361  char *secondary;
3362  switch_assert(str_language_dup);
3363  if ((secondary = strchr(str_language_dup, '-'))) {
3364  *secondary++ = '\0';
3366  "language %s not found. trying %s by removing %s\n", str_language, str_language_dup, secondary);
3367  switch_event_add_header_string(params, SWITCH_STACK_BOTTOM, "lang", str_language_dup);
3368  status = switch_xml_locate_language_ex(root, node, params, language, phrases, macros, str_language_dup);
3369  }
3370  switch_safe_free(str_language_dup);
3371  }
3372 
3373  return status;
3374 }
#define SWITCH_CHANNEL_LOG
switch_status_t switch_xml_locate_language_ex(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: switch_xml.c:3299
switch_status_t switch_event_add_header_string(switch_event_t *event, switch_stack_t stack, const char *header_name, const char *data)
Add a string header to an event.
#define switch_safe_free(it)
Free a pointer and set it to NULL unless it already is NULL.
Definition: switch_utils.h:885
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.
#define switch_assert(expr)

◆ switch_xml_locate_user()

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_xml_locate_user_in_domain()

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_xml_locate_user_merged()

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 2145 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_extended().

2147 {
2148  switch_xml_t xml, domain, group, x_user, x_user_dup;
2150  char *kdup = NULL;
2151  char *keys[10] = {0};
2152  int i, nkeys;
2153 
2154  if (strchr(key, ':')) {
2155  kdup = switch_must_strdup(key);
2156  nkeys = switch_split(kdup, ':', keys);
2157  } else {
2158  keys[0] = (char *)key;
2159  nkeys = 1;
2160  }
2161 
2162  for(i = 0; i < nkeys; i++) {
2163  if ((status = switch_xml_locate_user_cache(keys[i], user_name, domain_name, &x_user)) == SWITCH_STATUS_SUCCESS) {
2164  *user = x_user;
2165  break;
2166  } else if ((status = switch_xml_locate_user(keys[i], user_name, domain_name, ip, &xml, &domain, &x_user, &group, params)) == SWITCH_STATUS_SUCCESS) {
2167  const char *cacheable = NULL;
2168 
2169  x_user_dup = switch_xml_dup(x_user);
2170  switch_xml_merge_user(x_user_dup, domain, group);
2171 
2172  cacheable = switch_xml_attr(x_user_dup, "cacheable");
2173  if (!zstr(cacheable)) {
2174  switch_time_t expires = 0;
2175  switch_time_t time_now = 0;
2176 
2177  if (switch_is_number(cacheable)) {
2178  int cache_ms = atol(cacheable);
2179  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s for %d milliseconds\n",
2180  user_name, domain_name, cache_ms);
2181  time_now = switch_micro_time_now();
2182  expires = time_now + (cache_ms * 1000);
2183  } else {
2184  switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_DEBUG, "caching lookup for user %s@%s indefinitely\n", user_name, domain_name);
2185  }
2186  switch_xml_user_cache(keys[i], user_name, domain_name, x_user_dup, expires);
2187  }
2188  *user = x_user_dup;
2189  switch_xml_free(xml);
2190  break;
2191  }
2192  }
2193 
2194  switch_safe_free(kdup);
2195 
2196  return status;
2197 
2198 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
#define SWITCH_CHANNEL_LOG
const char * switch_xml_attr(switch_xml_t xml, const char *attr)
Definition: switch_xml.c:490
static switch_time_t time_now(int64_t offset)
Definition: switch_time.c:540
#define switch_split(_data, _delim, _array)
Definition: switch_utils.h:375
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:2117
switch_bool_t switch_is_number(const char *str)
A representation of an XML tree.
Definition: switch_xml.h:79
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:2082
#define zstr(x)
Definition: switch_utils.h:314
switch_xml_t switch_xml_dup(switch_xml_t xml)
Definition: switch_xml.c:1970
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:885
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:2200
char * switch_must_strdup(const char *_s)
char * ip
Definition: switch_msrp.c:60
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:2012
char * key
Definition: switch_msrp.c:64
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:2815

◆ switch_xml_merge_user()

void switch_xml_merge_user ( switch_xml_t  user,
switch_xml_t  domain,
switch_xml_t  group 
)

Definition at line 2012 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().

2013 {
2014  const char *domain_name = switch_xml_attr(domain, "name");
2015 
2016  do_merge(user, group, "params", "param");
2017  do_merge(user, group, "variables", "variable");
2018  do_merge(user, group, "profile-variables", "variable");
2019  do_merge(user, domain, "params", "param");
2020  do_merge(user, domain, "variables", "variable");
2021  do_merge(user, domain, "profile-variables", "variable");
2022 
2023  if (!zstr(domain_name)) {
2024  switch_xml_set_attr_d(user, "domain-name", domain_name);
2025  }
2026 }
const char * switch_xml_attr(switch_xml_t xml, const char *attr)
Definition: switch_xml.c:490
switch_xml_t switch_xml_set_attr_d(switch_xml_t xml, const char *name, const char *value)
Wrapper for switch_xml_set_attr() that strdup()s name/value. Value cannot be NULL.
Definition: switch_xml.c:3077
#define zstr(x)
Definition: switch_utils.h:314
static void do_merge(switch_xml_t in, switch_xml_t src, const char *container, const char *tag_name)
Definition: switch_xml.c:1977

◆ switch_xml_new()

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_open_cfg()

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_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_open_root()

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_parse_fd()

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 1241 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().

1242 {
1243  switch_xml_root_t root;
1244  struct stat st;
1245  switch_ssize_t l;
1246  void *m;
1247 
1248  if (fd < 0)
1249  return NULL;
1250 
1251  if (fstat(fd, &st) == -1 || !st.st_size) {
1252  return NULL;
1253  }
1254 
1255  m = switch_must_malloc(st.st_size);
1256 
1257  if (!(0<(l = read(fd, m, st.st_size)))
1258  || !(root = (switch_xml_root_t) switch_xml_parse_str((char *) m, l))) {
1259  free(m);
1260 
1261  return NULL;
1262  }
1263 
1264  root->dynamic = 1; /* so we know to free s in switch_xml_free() */
1265 
1266  return &root->xml;
1267 }
static void * switch_must_malloc(size_t _b)
Definition: switch_core.h:233
intptr_t switch_ssize_t
struct switch_xml xml
Definition: switch_xml.c:204
switch_xml_t switch_xml_parse_str(char *s, switch_size_t len)
Definition: switch_xml.c:1053
uint8_t dynamic
Definition: switch_xml.c:208

◆ switch_xml_parse_file()

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_parse_file_simple()

switch_xml_t switch_xml_parse_file_simple ( _In_z_ const char *  file)

◆ switch_xml_parse_fp()

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_parse_section_string()

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_parse_str()

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_parse_str_dynamic()

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().

◆ switch_xml_pi()

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_xml_reload()

switch_status_t switch_xml_reload ( const char **  err)

Definition at line 2436 of file switch_xml.c.

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

2437 {
2438  switch_xml_t xml_root;
2439 
2440  if ((xml_root = switch_xml_open_root(1, err))) {
2441  switch_xml_free(xml_root);
2442  return SWITCH_STATUS_SUCCESS;
2443  }
2444 
2445  return SWITCH_STATUS_GENERR;
2446 }
switch_xml_t switch_xml_open_root(uint8_t reload, const char **err)
Definition: switch_xml.c:2371
A representation of an XML tree.
Definition: switch_xml.h:79
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2815

◆ switch_xml_root()

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 2281 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().

2282 {
2283  switch_xml_t xml;
2284 
2286  xml = MAIN_XML_ROOT;
2287  xml->refs++;
2289 
2290  return xml;
2291 }
uint32_t refs
Definition: switch_xml.h:104
static switch_mutex_t * REFLOCK
Definition: switch_xml.c:236
A representation of an XML tree.
Definition: switch_xml.h:79
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_xml_t MAIN_XML_ROOT
Definition: switch_xml.c:230

◆ switch_xml_set_attr()

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 3013 of file switch_xml.c.

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

Referenced by switch_xml_set_attr_d(), and switch_xml_set_attr_d_buf().

3014 {
3015  int l = 0, c;
3016 
3017  if (!xml)
3018  return NULL;
3019  while (xml->attr[l] && strcmp(xml->attr[l], name))
3020  l += 2;
3021  if (!xml->attr[l]) { /* not found, add as new attribute */
3022  if (!value)
3023  return xml; /* nothing to do */
3024  if (xml->attr == SWITCH_XML_NIL) { /* first attribute */
3025  xml->attr = (char **) switch_must_malloc(4 * sizeof(char *));
3026  xml->attr[l + 1] = switch_must_strdup(""); /* empty list of malloced names/vals */
3027  } else {
3028  xml->attr = (char **) switch_must_realloc(xml->attr, (l + 4) * sizeof(char *));
3029  }
3030 
3031  xml->attr[l] = (char *) name; /* set attribute name */
3032  xml->attr[l + 2] = NULL; /* null terminate attribute list */
3033  xml->attr[l + 3] = (char *) switch_must_realloc(xml->attr[l + 1], (c = (int) strlen(xml->attr[l + 1])) + 2);
3034  strcpy(xml->attr[l + 3] + c, " "); /* set name/value as not malloced */
3035  if (xml->flags & SWITCH_XML_DUP)
3036  xml->attr[l + 3][c] = SWITCH_XML_NAMEM;
3037  c = l + 2; /* end of attribute list */
3038  } else {
3039  for (c = l; xml->attr[c]; c += 2); /* find end of attribute list */
3040 
3041  if (xml->flags & SWITCH_XML_DUP)
3042  free((char*)name); /* name was strduped */
3043  if (xml->attr[c + 1][l / 2] & SWITCH_XML_TXTM)
3044  free(xml->attr[l + 1]); /* old val */
3045  }
3046 
3047  if (xml->flags & SWITCH_XML_DUP)
3048  xml->attr[c + 1][l / 2] |= SWITCH_XML_TXTM;
3049  else
3050  xml->attr[c + 1][l / 2] &= ~SWITCH_XML_TXTM;
3051 
3052  if (value)
3053  xml->attr[l + 1] = (char *) value; /* set attribute value */
3054  else { /* remove attribute */
3055  if (xml->attr[c + 1][l / 2] & SWITCH_XML_NAMEM)
3056  free(xml->attr[l]);
3057  c -= 2;
3058  if (c > 0) {
3059  memmove(xml->attr + l, xml->attr + l + 2, (c - l + 2) * sizeof(char*));
3060  xml->attr = (char**)switch_must_realloc(xml->attr, (c + 2) * sizeof(char*));
3061  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 */
3062  xml->attr[c + 1][c / 2] = '\0';
3063  } else {
3064  /* last attribute removed, reset attribute list */
3065  free(xml->attr[3]);
3066  free(xml->attr);
3067  xml->attr = SWITCH_XML_NIL;
3068  }
3069  }
3070  xml->flags &= ~SWITCH_XML_DUP; /* clear strdup() flag */
3071 
3072  return xml;
3073 }
const char *const const char *const const cJSON *const value
static void * switch_must_malloc(size_t _b)
Definition: switch_core.h:233
static void * switch_must_realloc(void *_b, size_t _z)
Definition: switch_core.h:240
char * switch_must_strdup(const char *_s)
char ** attr
Definition: switch_xml.h:83
uint32_t flags
Definition: switch_xml.h:101
const char *const name
Definition: switch_cJSON.h:250
char * SWITCH_XML_NIL[]
Definition: switch_xml.c:219

◆ switch_xml_set_attr_d()

switch_xml_t switch_xml_set_attr_d ( switch_xml_t  xml,
const char *  name,
const char *  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 3077 of file switch_xml.c.

References switch_must_strdup(), switch_str_nil, SWITCH_XML_DUP, switch_xml_set_attr(), and switch_xml_set_flag().

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

3078 {
3079  if (!xml) return NULL;
3081 }
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 ...
Definition: switch_xml.c:3013
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
Definition: switch_xml.c:3092
const char *const const char *const const cJSON *const value
char * switch_must_strdup(const char *_s)
#define switch_str_nil(s)
Make a null string a blank string instead.
Definition: switch_utils.h:993
const char *const name
Definition: switch_cJSON.h:250

◆ switch_xml_set_attr_d_buf()

switch_xml_t switch_xml_set_attr_d_buf ( switch_xml_t  xml,
const char *  name,
const char *  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 3085 of file switch_xml.c.

References switch_must_strdup(), SWITCH_XML_DUP, switch_xml_set_attr(), and switch_xml_set_flag().

Referenced by switch_console_complete(), and switch_ivr_generate_xml_cdr().

3086 {
3087  if (!xml) return NULL;
3089 }
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 ...
Definition: switch_xml.c:3013
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
Definition: switch_xml.c:3092
const char *const const char *const const cJSON *const value
char * switch_must_strdup(const char *_s)
const char *const name
Definition: switch_cJSON.h:250

◆ switch_xml_set_binding_sections()

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

◆ switch_xml_set_binding_user_data()

void switch_xml_set_binding_user_data ( _In_ switch_xml_binding_t binding,
_In_opt_ void *  user_data 
)

◆ switch_xml_set_flag()

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 3092 of file switch_xml.c.

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

Referenced by switch_xml_add_child_d(), switch_xml_char_content(), switch_xml_set_attr_d(), switch_xml_set_attr_d_buf(), and switch_xml_set_txt_d().

3093 {
3094  if (xml)
3095  xml->flags |= flag;
3096  return xml;
3097 }
uint32_t flags
Definition: switch_xml.h:101

◆ switch_xml_set_open_root_function()

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 2356 of file switch_xml.c.

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

2357 {
2358  if (XML_LOCK) {
2360  }
2361 
2362  XML_OPEN_ROOT_FUNCTION = func;
2364 
2365  if (XML_LOCK) {
2367  }
2368  return SWITCH_STATUS_SUCCESS;
2369 }
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static void * XML_OPEN_ROOT_FUNCTION_USER_DATA
Definition: switch_xml.c:242
static switch_xml_open_root_function_t XML_OPEN_ROOT_FUNCTION
Definition: switch_xml.c:241
static switch_mutex_t * XML_LOCK
Definition: switch_xml.c:234

◆ switch_xml_set_root()

switch_status_t switch_xml_set_root ( switch_xml_t  new_main)

set new core xml root

Definition at line 2330 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().

2331 {
2332  switch_xml_t old_root = NULL;
2333 
2335 
2336  old_root = MAIN_XML_ROOT;
2337  MAIN_XML_ROOT = new_main;
2339  MAIN_XML_ROOT->refs++;
2340 
2341  if (old_root) {
2342  if (old_root->refs) {
2343  old_root->refs--;
2344  }
2345 
2346  if (!old_root->refs) {
2347  switch_xml_free(old_root);
2348  }
2349  }
2350 
2352 
2353  return SWITCH_STATUS_SUCCESS;
2354 }
uint32_t refs
Definition: switch_xml.h:104
#define switch_set_flag(obj, flag)
Set a flag on an arbitrary object.
Definition: switch_utils.h:700
static switch_mutex_t * REFLOCK
Definition: switch_xml.c:236
A representation of an XML tree.
Definition: switch_xml.h:79
switch_status_t switch_mutex_unlock(switch_mutex_t *lock)
Definition: switch_apr.c:313
switch_status_t switch_mutex_lock(switch_mutex_t *lock)
Definition: switch_apr.c:308
static switch_xml_t MAIN_XML_ROOT
Definition: switch_xml.c:230
void switch_xml_free(switch_xml_t xml)
Definition: switch_xml.c:2815

◆ switch_xml_set_txt()

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 2993 of file switch_xml.c.

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

Referenced by switch_xml_set_txt_d().

2994 {
2995  if (!xml)
2996  return NULL;
2997  if (xml->flags & SWITCH_XML_TXTM)
2998  free(xml->txt); /* existing txt was malloced */
2999  xml->flags &= ~SWITCH_XML_TXTM;
3000  xml->txt = (char *) txt;
3001  return xml;
3002 }
char * txt
Definition: switch_xml.h:85
uint32_t flags
Definition: switch_xml.h:101

◆ switch_xml_set_txt_d()

switch_xml_t switch_xml_set_txt_d ( switch_xml_t  xml,
const char *  txt 
)

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 3005 of file switch_xml.c.

References switch_xml_set_flag(), switch_xml_set_txt(), and SWITCH_XML_TXTM.

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().

3006 {
3007  if (!xml) return NULL;
3008  return switch_xml_set_flag(switch_xml_set_txt(xml, strdup(txt)), SWITCH_XML_TXTM);
3009 }
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
Definition: switch_xml.c:3092
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
Definition: switch_xml.c:2993

◆ switch_xml_std_datetime_check()

int switch_xml_std_datetime_check ( switch_xml_t  xcond,
int *  offset,
const char *  tzname 
)

Definition at line 3138 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.

3139 {
3140 
3141  const char *xdt = switch_xml_attr(xcond, "date-time");
3142  const char *xyear = switch_xml_attr(xcond, "year");
3143  const char *xyday = switch_xml_attr(xcond, "yday");
3144  const char *xmon = switch_xml_attr(xcond, "mon");
3145  const char *xmday = switch_xml_attr(xcond, "mday");
3146  const char *xweek = switch_xml_attr(xcond, "week");
3147  const char *xmweek = switch_xml_attr(xcond, "mweek");
3148  const char *xwday = switch_xml_attr(xcond, "wday");
3149  const char *xhour = switch_xml_attr(xcond, "hour");
3150  const char *xminute = switch_xml_attr(xcond, "minute");
3151  const char *xminday = switch_xml_attr(xcond, "minute-of-day");
3152  const char *xtod = switch_xml_attr(xcond, "time-of-day");
3153  const char *tzoff = switch_xml_attr(xcond, "tz-offset");
3154  const char *isdst = switch_xml_attr(xcond, "dst");
3155 
3156  int loffset = -1000;
3157  int eoffset = -1000;
3158  int dst = -1000;
3160  int time_match = -1;
3161  switch_time_exp_t tm, tm2;
3162 
3163  if (!zstr(isdst)) {
3164  dst = switch_true(isdst);
3165  }
3166 
3167  if (!zstr(tzoff) && switch_is_number(tzoff)) {
3168  loffset = atoi(tzoff);
3169  }
3170 
3171  switch_time_exp_lt(&tm2, ts);
3172 
3173  if (offset) {
3174  eoffset = *offset;
3175  switch_time_exp_tz(&tm, ts, *offset * 3600);
3176  } else if (!zstr(tzname)) {
3177  switch_time_exp_tz_name(tzname, &tm, ts);
3178  } else {
3179  tm = tm2;
3180  }
3181 
3182  if (eoffset == -1000) {
3183  eoffset = tm.tm_gmtoff / 3600;
3184  }
3185 
3186  if (loffset == -1000) {
3187  loffset = eoffset;
3188  }
3189 
3190 
3191  if (time_match && tzoff) {
3192  time_match = loffset == eoffset;
3194  "XML DateTime Check: TZOFFSET[%d] == %d (%s)\n", eoffset, loffset, time_match ? "PASS" : "FAIL");
3195 
3196  }
3197 
3198  if (time_match && dst > -1) {
3199  time_match = (tm2.tm_isdst > 0 && dst > 0);
3201  "XML DateTime Check: DST[%s] == %s (%s)\n",
3202  tm2.tm_isdst > 0 ? "true" : "false", dst > 0 ? "true" : "false", time_match ? "PASS" : "FAIL");
3203 
3204  }
3205 
3206  if (time_match && xdt) {
3207  char tmpdate[80];
3208  switch_size_t retsize;
3209  switch_strftime(tmpdate, &retsize, sizeof(tmpdate), "%Y-%m-%d %H:%M:%S", &tm);
3210  time_match = switch_fulldate_cmp(xdt, &ts);
3212  "XML DateTime Check: date time[%s] =~ %s (%s)\n", tmpdate, xdt, time_match ? "PASS" : "FAIL");
3213  }
3214 
3215  if (time_match && xyear) {
3216  int test = tm.tm_year + 1900;
3217  time_match = switch_number_cmp(xyear, test);
3219  "XML DateTime Check: year[%d] =~ %s (%s)\n", test, xyear, time_match ? "PASS" : "FAIL");
3220  }
3221 
3222  if (time_match && xyday) {
3223  int test = tm.tm_yday + 1;
3224  time_match = switch_number_cmp(xyday, test);
3226  "XML DateTime Check: day of year[%d] =~ %s (%s)\n", test, xyday, time_match ? "PASS" : "FAIL");
3227  }
3228 
3229  if (time_match && xmon) {
3230  int test = tm.tm_mon + 1;
3231  time_match = switch_number_cmp(xmon, test);
3233  "XML DateTime Check: month[%d] =~ %s (%s)\n", test, xmon, time_match ? "PASS" : "FAIL");
3234  }
3235 
3236  if (time_match && xmday) {
3237  int test = tm.tm_mday;
3238  time_match = switch_number_cmp(xmday, test);
3240  "XML DateTime Check: day of month[%d] =~ %s (%s)\n", test, xmday, time_match ? "PASS" : "FAIL");
3241  }
3242 
3243  if (time_match && xweek) {
3244  int test = (int) (tm.tm_yday / 7 + 1);
3245  time_match = switch_number_cmp(xweek, test);
3247  "XML DateTime Check: week of year[%d] =~ %s (%s)\n", test, xweek, time_match ? "PASS" : "FAIL");
3248  }
3249 
3250  if (time_match && xmweek) {
3251  /* calculate the day of the week of the first of the month (0-6) */
3252  int firstdow = (int) (7 - (tm.tm_mday - (tm.tm_wday + 1)) % 7) % 7;
3253  /* calculate the week of the month (1-6)*/
3254  int test = (int) ceil((tm.tm_mday + firstdow) / 7.0);
3255  time_match = switch_number_cmp(xmweek, test);
3257  "XML DateTime: week of month[%d] =~ %s (%s)\n", test, xmweek, time_match ? "PASS" : "FAIL");
3258  }
3259 
3260  if (time_match && xwday) {
3261  int test = tm.tm_wday + 1;
3262  time_match = switch_dow_cmp(xwday, test);
3264  "XML DateTime Check: day of week[%s] =~ %s (%s)\n", switch_dow_int2str(test), xwday, time_match ? "PASS" : "FAIL");
3265  }
3266  if (time_match && xhour) {
3267  int test = tm.tm_hour;
3268  time_match = switch_number_cmp(xhour, test);
3270  "XML DateTime Check: hour[%d] =~ %s (%s)\n", test, xhour, time_match ? "PASS" : "FAIL");
3271  }
3272 
3273  if (time_match && xminute) {
3274  int test = tm.tm_min;
3275  time_match = switch_number_cmp(xminute, test);
3277  "XML DateTime Check: minute[%d] =~ %s (%s)\n", test, xminute, time_match ? "PASS" : "FAIL");
3278  }
3279 
3280  if (time_match && xminday) {
3281  int test = (tm.tm_hour * 60) + (tm.tm_min + 1);
3282  time_match = switch_number_cmp(xminday, test);
3284  "XML DateTime Check: minute of day[%d] =~ %s (%s)\n", test, xminday, time_match ? "PASS" : "FAIL");
3285  }
3286 
3287  if (time_match && xtod) {
3288  int test = (tm.tm_hour * 60 * 60) + (tm.tm_min * 60) + tm.tm_sec;
3289  char tmpdate[10];
3290  switch_snprintf(tmpdate, 10, "%d:%d:%d", tm.tm_hour, tm.tm_min, tm.tm_sec);
3291  time_match = switch_tod_cmp(xtod, test);
3293  "XML DateTime Check: time of day[%s] =~ %s (%s)\n", tmpdate, xtod, time_match ? "PASS" : "FAIL");
3294  }
3295 
3296  return time_match;
3297 }
switch_time_t switch_micro_time_now(void)
Get the current epoch time in microseconds.
Definition: switch_time.c:311
static switch_bool_t switch_true(const char *expr)
Evaluate the truthfullness of a string expression.
Definition: switch_utils.h:519
#define SWITCH_CHANNEL_LOG
const char * switch_xml_attr(switch_xml_t xml, const char *attr)
Definition: switch_xml.c:490
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:346
int switch_snprintf(_Out_z_cap_(len) char *buf, _In_ switch_size_t len, _In_z_ _Printf_format_string_ const char *format,...)
#define zstr(x)
Definition: switch_utils.h:314
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:351
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:150
switch_status_t switch_time_exp_tz_name(const char *tz, switch_time_exp_t *tm, switch_time_t thetime)
Definition: switch_time.c:1445
int switch_fulldate_cmp(const char *exp, switch_time_t *ts)

◆ switch_xml_tohtml_ex()

char* switch_xml_tohtml_ex ( _In_ switch_xml_t  xml,
_In_ switch_bool_t  prn_header,
switch_bool_t  use_utf8_encoding 
)

◆ switch_xml_toxml_buf_ex()

char* switch_xml_toxml_buf_ex ( _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,
switch_bool_t  use_utf8_encoding 
)

◆ switch_xml_toxml_ex()

char* switch_xml_toxml_ex ( _In_ switch_xml_t  xml,
_In_ switch_bool_t  prn_header,
switch_bool_t  use_utf8_encoding 
)

◆ switch_xml_toxml_nolock_ex()

char* switch_xml_toxml_nolock_ex ( switch_xml_t  xml,
_In_ switch_bool_t  prn_header,
switch_bool_t  use_utf8_encoding 
)

◆ switch_xml_unbind_search_function()

switch_status_t switch_xml_unbind_search_function ( _In_ switch_xml_binding_t **  binding)

◆ switch_xml_unbind_search_function_ptr()

switch_status_t switch_xml_unbind_search_function_ptr ( _In_ switch_xml_search_function_t  function)