pacemaker  2.1.0-7c3f660
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
xml.c File Reference
#include <crm_internal.h>
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <stdarg.h>
#include <bzlib.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xmlIO.h>
#include <crm/crm.h>
#include <crm/msg_xml.h>
#include <crm/common/iso8601_internal.h>
#include <crm/common/xml.h>
#include <crm/common/xml_internal.h>
#include "crmcommon_private.h"
#include <crm/common/xml_compat.h>
Include dependency graph for xml.c:

Go to the source code of this file.

Macros

#define XML_PARSER_DEBUG   0
 
#define PCMK__XML_PARSE_OPTS   (XML_PARSE_NOBLANKS | XML_PARSE_RECOVER)
 
#define CHUNK_SIZE   1024
 
#define buffer_print(buffer, max, offset, fmt, args...)
 
#define XML_PRIVATE_MAGIC   (long) 0x81726354
 
#define attr_matches(c, n, v)
 
#define PCMK__XMLDUMP_STATS   0
 
#define XPATH_MAX   512
 

Functions

bool pcmk__tracking_xml_changes (xmlNode *xml, bool lazy)
 
void pcmk__set_xml_doc_flag (xmlNode *xml, enum xml_private_flags flag)
 
void pcmk__mark_xml_created (xmlNode *xml)
 
void pcmk__mark_xml_attr_dirty (xmlAttr *a)
 
void xml_track_changes (xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
 
bool xml_tracking_changes (xmlNode *xml)
 
bool xml_document_dirty (xmlNode *xml)
 
int pcmk__xml_position (xmlNode *xml, enum xml_private_flags ignore_if_set)
 
xmlNode * pcmk__xml_match (xmlNode *haystack, xmlNode *needle, bool exact)
 
void xml_log_changes (uint8_t log_level, const char *function, xmlNode *xml)
 
void xml_accept_changes (xmlNode *xml)
 
xmlNode * find_xml_node (xmlNode *root, const char *search_path, gboolean must_find)
 
xmlNode * pcmk__xe_match (xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
 
void copy_in_properties (xmlNode *target, xmlNode *src)
 
void fix_plus_plus_recursive (xmlNode *target)
 
void expand_plus_plus (xmlNode *target, const char *name, const char *value)
 
void pcmk__xe_remove_matching_attrs (xmlNode *element, bool(*match)(xmlAttrPtr, void *), void *user_data)
 
xmlDoc * getDocPtr (xmlNode *node)
 
xmlNode * add_node_copy (xmlNode *parent, xmlNode *src_node)
 
int add_node_nocopy (xmlNode *parent, const char *name, xmlNode *child)
 
xmlNode * create_xml_node (xmlNode *parent, const char *name)
 
xmlNode * pcmk_create_xml_text_node (xmlNode *parent, const char *name, const char *content)
 
xmlNode * pcmk_create_html_node (xmlNode *parent, const char *element_name, const char *id, const char *class_name, const char *text)
 
void pcmk_free_xml_subtree (xmlNode *xml)
 
void free_xml (xmlNode *child)
 
xmlNode * copy_xml (xmlNode *src)
 
xmlNode * string2xml (const char *input)
 
xmlNode * stdin2xml (void)
 
void pcmk__strip_xml_text (xmlNode *xml)
 
xmlNode * filename2xml (const char *filename)
 
const char * pcmk__xe_add_last_written (xmlNode *xe)
 
void crm_xml_sanitize_id (char *id)
 Sanitize a string so it is usable as an XML ID. More...
 
void crm_xml_set_id (xmlNode *xml, const char *format,...)
 Set the ID of an XML element using a format. More...
 
int write_xml_fd (xmlNode *xml_node, const char *filename, int fd, gboolean compress)
 Write XML to a file descriptor. More...
 
int write_xml_file (xmlNode *xml_node, const char *filename, gboolean compress)
 Write XML to a file. More...
 
char * crm_xml_escape (const char *text)
 
void pcmk__xe_log (int log_level, const char *file, const char *function, int line, const char *prefix, xmlNode *data, int depth, int options)
 
void log_data_element (int log_level, const char *file, const char *function, int line, const char *prefix, xmlNode *data, int depth, int options)
 
void pcmk__xml2text (xmlNode *data, int options, char **buffer, int *offset, int *max, int depth)
 
void pcmk__buffer_add_char (char **buffer, int *offset, int *max, char c)
 
char * dump_xml_formatted_with_text (xmlNode *an_xml_node)
 
char * dump_xml_formatted (xmlNode *an_xml_node)
 
char * dump_xml_unformatted (xmlNode *an_xml_node)
 
gboolean xml_has_children (const xmlNode *xml_root)
 
void xml_remove_prop (xmlNode *obj, const char *name)
 
void save_xml_to_file (xmlNode *xml, const char *desc, const char *filename)
 
void xml_calculate_significant_changes (xmlNode *old_xml, xmlNode *new_xml)
 
void xml_calculate_changes (xmlNode *old_xml, xmlNode *new_xml)
 
gboolean can_prune_leaf (xmlNode *xml_node)
 
xmlNode * pcmk__xc_match (xmlNode *root, xmlNode *search_comment, bool exact)
 
void pcmk__xc_update (xmlNode *parent, xmlNode *target, xmlNode *update)
 
void pcmk__xml_update (xmlNode *parent, xmlNode *target, xmlNode *update, bool as_diff)
 
gboolean update_xml_child (xmlNode *child, xmlNode *to_update)
 
int find_xml_children (xmlNode **children, xmlNode *root, const char *tag, const char *field, const char *value, gboolean search_matches)
 
gboolean replace_xml_child (xmlNode *parent, xmlNode *child, xmlNode *update, gboolean delete_only)
 
xmlNode * sorted_xml (xmlNode *input, xmlNode *parent, gboolean recursive)
 
xmlNode * first_named_child (const xmlNode *parent, const char *name)
 
xmlNode * crm_next_same_xml (const xmlNode *sibling)
 Get next instance of same XML tag. More...
 
void crm_xml_init (void)
 
void crm_xml_cleanup (void)
 
xmlNode * expand_idref (xmlNode *input, xmlNode *top)
 
void crm_destroy_xml (gpointer data)
 xmlNode destructor which can be used in glib collections More...
 
char * pcmk__xml_artefact_root (enum pcmk__xml_artefact_ns ns)
 
char * pcmk__xml_artefact_path (enum pcmk__xml_artefact_ns ns, const char *filespec)
 
void pcmk__xe_set_propv (xmlNodePtr node, va_list pairs)
 
void pcmk__xe_set_props (xmlNodePtr node,...)
 
xmlNode * find_entity (xmlNode *parent, const char *node_name, const char *id)
 

Macro Definition Documentation

#define attr_matches (   c,
  n,
 
)
Value:
pcmk__str_eq(crm_element_value((c), (n)), \
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:530

Definition at line 479 of file xml.c.

#define buffer_print (   buffer,
  max,
  offset,
  fmt,
  args... 
)
Value:
do { \
int rc = (max); \
if(buffer) { \
rc = snprintf((buffer) + (offset), (max) - (offset), fmt, ##args); \
} \
if(buffer && rc < 0) { \
crm_perror(LOG_ERR, "snprintf failed at offset %d", offset); \
(buffer)[(offset)] = 0; \
break; \
} else if(rc >= ((max) - (offset))) { \
char *tmp = NULL; \
(max) = QB_MAX(CHUNK_SIZE, (max) * 2); \
tmp = pcmk__realloc((buffer), (max)); \
CRM_ASSERT(tmp); \
(buffer) = tmp; \
} else { \
offset += rc; \
break; \
} \
} while(1);
#define CHUNK_SIZE
Definition: xml.c:49
int rc
Definition: pcmk_fence.c:35
#define crm_perror(level, fmt, args...)
Send a system error message to both the log and stderr.
Definition: logging.h:301
#define CRM_ASSERT(expr)
Definition: results.h:42

Definition at line 66 of file xml.c.

#define CHUNK_SIZE   1024

Definition at line 49 of file xml.c.

#define PCMK__XML_PARSE_OPTS   (XML_PARSE_NOBLANKS | XML_PARSE_RECOVER)

Definition at line 47 of file xml.c.

#define PCMK__XMLDUMP_STATS   0

Definition at line 1857 of file xml.c.

#define XML_PARSER_DEBUG   0

Definition at line 34 of file xml.c.

#define XML_PRIVATE_MAGIC   (long) 0x81726354

Definition at line 185 of file xml.c.

#define XPATH_MAX   512

Definition at line 2860 of file xml.c.

Function Documentation

xmlNode* add_node_copy ( xmlNode *  parent,
xmlNode *  src_node 
)

Definition at line 674 of file xml.c.

int add_node_nocopy ( xmlNode *  parent,
const char *  name,
xmlNode *  child 
)

Definition at line 688 of file xml.c.

gboolean can_prune_leaf ( xmlNode *  xml_node)

Definition at line 2388 of file xml.c.

void copy_in_properties ( xmlNode *  target,
xmlNode *  src 
)

Definition at line 521 of file xml.c.

xmlNode* copy_xml ( xmlNode *  src)

Definition at line 829 of file xml.c.

xmlNode* create_xml_node ( xmlNode *  parent,
const char *  name 
)

Definition at line 696 of file xml.c.

void crm_destroy_xml ( gpointer  data)

xmlNode destructor which can be used in glib collections

Definition at line 2896 of file xml.c.

xmlNode* crm_next_same_xml ( const xmlNode *  sibling)

Get next instance of same XML tag.

Parameters
[in]siblingXML tag to start from
Returns
Next sibling XML tag with same name

Definition at line 2816 of file xml.c.

void crm_xml_cleanup ( void  )

Definition at line 2853 of file xml.c.

char* crm_xml_escape ( const char *  text)

Definition at line 1335 of file xml.c.

void crm_xml_init ( void  )

Definition at line 2831 of file xml.c.

void crm_xml_sanitize_id ( char *  id)

Sanitize a string so it is usable as an XML ID.

Parameters
[in,out]idString to sanitize

Definition at line 1127 of file xml.c.

void crm_xml_set_id ( xmlNode *  xml,
const char *  format,
  ... 
)

Set the ID of an XML element using a format.

Parameters
[in,out]xmlXML element
[in]fmtprintf-style format
[in]...any arguments required by format

Definition at line 1149 of file xml.c.

char* dump_xml_formatted ( xmlNode *  an_xml_node)

Definition at line 2006 of file xml.c.

char* dump_xml_formatted_with_text ( xmlNode *  an_xml_node)

Definition at line 1994 of file xml.c.

char* dump_xml_unformatted ( xmlNode *  an_xml_node)

Definition at line 2017 of file xml.c.

xmlNode* expand_idref ( xmlNode *  input,
xmlNode *  top 
)

Definition at line 2863 of file xml.c.

void expand_plus_plus ( xmlNode *  target,
const char *  name,
const char *  value 
)

Definition at line 560 of file xml.c.

xmlNode* filename2xml ( const char *  filename)

Definition at line 1043 of file xml.c.

xmlNode* find_entity ( xmlNode *  parent,
const char *  node_name,
const char *  id 
)
Deprecated:
This function will be removed in a future release

Definition at line 2985 of file xml.c.

int find_xml_children ( xmlNode **  children,
xmlNode *  root,
const char *  tag,
const char *  field,
const char *  value,
gboolean  search_matches 
)

Definition at line 2643 of file xml.c.

xmlNode* find_xml_node ( xmlNode *  root,
const char *  search_path,
gboolean  must_find 
)

Definition at line 446 of file xml.c.

xmlNode* first_named_child ( const xmlNode *  parent,
const char *  name 
)

Definition at line 2790 of file xml.c.

void fix_plus_plus_recursive ( xmlNode *  target)

Definition at line 542 of file xml.c.

void free_xml ( xmlNode *  child)

Definition at line 823 of file xml.c.

xmlDoc* getDocPtr ( xmlNode *  node)

Definition at line 658 of file xml.c.

void log_data_element ( int  log_level,
const char *  file,
const char *  function,
int  line,
const char *  prefix,
xmlNode *  data,
int  depth,
int  options 
)

Definition at line 1645 of file xml.c.

void pcmk__buffer_add_char ( char **  buffer,
int *  offset,
int *  max,
char  c 
)

Definition at line 1988 of file xml.c.

void pcmk__mark_xml_attr_dirty ( xmlAttr *  a)

Definition at line 174 of file xml.c.

void pcmk__mark_xml_created ( xmlNode *  xml)

Definition at line 156 of file xml.c.

void pcmk__set_xml_doc_flag ( xmlNode *  xml,
enum xml_private_flags  flag 
)

Definition at line 118 of file xml.c.

void pcmk__strip_xml_text ( xmlNode *  xml)

Definition at line 1015 of file xml.c.

bool pcmk__tracking_xml_changes ( xmlNode *  xml,
bool  lazy 
)

Definition at line 52 of file xml.c.

xmlNode* pcmk__xc_match ( xmlNode *  root,
xmlNode *  search_comment,
bool  exact 
)

Definition at line 2431 of file xml.c.

void pcmk__xc_update ( xmlNode *  parent,
xmlNode *  target,
xmlNode *  update 
)

Definition at line 2480 of file xml.c.

const char* pcmk__xe_add_last_written ( xmlNode *  xe)

Definition at line 1113 of file xml.c.

void pcmk__xe_log ( int  log_level,
const char *  file,
const char *  function,
int  line,
const char *  prefix,
xmlNode *  data,
int  depth,
int  options 
)

Definition at line 1444 of file xml.c.

xmlNode* pcmk__xe_match ( xmlNode *  parent,
const char *  node_name,
const char *  attr_n,
const char *  attr_v 
)

Definition at line 496 of file xml.c.

void pcmk__xe_remove_matching_attrs ( xmlNode *  element,
bool(*)(xmlAttrPtr, void *)  match,
void *  user_data 
)

Definition at line 630 of file xml.c.

void pcmk__xe_set_props ( xmlNodePtr  node,
  ... 
)

Definition at line 2972 of file xml.c.

void pcmk__xe_set_propv ( xmlNodePtr  node,
va_list  pairs 
)

Definition at line 2952 of file xml.c.

void pcmk__xml2text ( xmlNode *  data,
int  options,
char **  buffer,
int *  offset,
int *  max,
int  depth 
)

Definition at line 1871 of file xml.c.

char* pcmk__xml_artefact_path ( enum pcmk__xml_artefact_ns  ns,
const char *  filespec 
)

Definition at line 2930 of file xml.c.

char* pcmk__xml_artefact_root ( enum pcmk__xml_artefact_ns  ns)

Definition at line 2902 of file xml.c.

xmlNode* pcmk__xml_match ( xmlNode *  haystack,
xmlNode *  needle,
bool  exact 
)

Definition at line 370 of file xml.c.

int pcmk__xml_position ( xmlNode *  xml,
enum xml_private_flags  ignore_if_set 
)

Definition at line 315 of file xml.c.

void pcmk__xml_update ( xmlNode *  parent,
xmlNode *  target,
xmlNode *  update,
bool  as_diff 
)

Definition at line 2511 of file xml.c.

xmlNode* pcmk_create_html_node ( xmlNode *  parent,
const char *  element_name,
const char *  id,
const char *  class_name,
const char *  text 
)

Definition at line 733 of file xml.c.

xmlNode* pcmk_create_xml_text_node ( xmlNode *  parent,
const char *  name,
const char *  content 
)

Definition at line 721 of file xml.c.

void pcmk_free_xml_subtree ( xmlNode *  xml)

Free an XML element and all of its children, removing it from its parent

Parameters
[in]xmlXML element to free

Definition at line 755 of file xml.c.

gboolean replace_xml_child ( xmlNode *  parent,
xmlNode *  child,
xmlNode *  update,
gboolean  delete_only 
)

Definition at line 2676 of file xml.c.

void save_xml_to_file ( xmlNode *  xml,
const char *  desc,
const char *  filename 
)

Definition at line 2055 of file xml.c.

xmlNode* sorted_xml ( xmlNode *  input,
xmlNode *  parent,
gboolean  recursive 
)

Definition at line 2758 of file xml.c.

xmlNode* stdin2xml ( void  )

Definition at line 929 of file xml.c.

xmlNode* string2xml ( const char *  input)

Definition at line 868 of file xml.c.

gboolean update_xml_child ( xmlNode *  child,
xmlNode *  to_update 
)

Definition at line 2609 of file xml.c.

int write_xml_fd ( xmlNode *  xml_node,
const char *  filename,
int  fd,
gboolean  compress 
)

Write XML to a file descriptor.

Parameters
[in]xml_nodeXML to write
[in]filenameName of file being written (for logging only)
[in]fdOpen file descriptor corresponding to filename
[in]compressWhether to compress XML before writing
Returns
Number of bytes written on success, -errno otherwise

Definition at line 1270 of file xml.c.

int write_xml_file ( xmlNode *  xml_node,
const char *  filename,
gboolean  compress 
)

Write XML to a file.

Parameters
[in]xml_nodeXML to write
[in]filenameName of file to write
[in]compressWhether to compress XML before writing
Returns
Number of bytes written on success, -errno otherwise

Definition at line 1298 of file xml.c.

void xml_accept_changes ( xmlNode *  xml)

Definition at line 421 of file xml.c.

void xml_calculate_changes ( xmlNode *  old_xml,
xmlNode *  new_xml 
)

Definition at line 2374 of file xml.c.

void xml_calculate_significant_changes ( xmlNode *  old_xml,
xmlNode *  new_xml 
)

Definition at line 2367 of file xml.c.

bool xml_document_dirty ( xmlNode *  xml)

Definition at line 298 of file xml.c.

gboolean xml_has_children ( const xmlNode *  xml_root)

Definition at line 2027 of file xml.c.

void xml_log_changes ( uint8_t  log_level,
const char *  function,
xmlNode *  xml 
)

Definition at line 386 of file xml.c.

void xml_remove_prop ( xmlNode *  obj,
const char *  name 
)

Definition at line 2036 of file xml.c.

void xml_track_changes ( xmlNode *  xml,
const char *  user,
xmlNode *  acl_source,
bool  enforce_acls 
)

Definition at line 276 of file xml.c.

bool xml_tracking_changes ( xmlNode *  xml)

Definition at line 291 of file xml.c.