pacemaker  2.1.5-b7adf64e51
Scalable High-Availability cluster resource manager
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/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 XML_DOC_PRIVATE_MAGIC   0x81726354UL
 
#define XML_NODE_PRIVATE_MAGIC   0x54637281UL
 
#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 (const xmlNode *xml, enum xml_private_flags ignore_if_set)
 
xmlNode * pcmk__xml_match (const xmlNode *haystack, const 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 (const xmlNode *root, const char *search_path, gboolean must_find)
 
xmlNode * pcmk__xe_match (const 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)
 Parse integer assignment statements on this node and all its child nodes. More...
 
void expand_plus_plus (xmlNode *target, const char *name, const char *value)
 Update current XML attribute value per parsed integer assignment statement. More...
 
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)
 Replace special characters with their XML escape sequences. More...
 
void pcmk__xml_log (int log_level, const char *file, const char *function, int line, const char *prefix, const xmlNode *data, int depth, int options)
 
void log_data_element (int log_level, const char *file, const char *function, int line, const char *prefix, const xmlNode *data, int depth, int options)
 
void pcmk__xml2text (xmlNodePtr data, int options, GString *buffer, int depth)
 
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 (const xmlNode *root, const 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)
 Initialize the CRM XML subsystem. More...
 
void crm_xml_cleanup (void)
 
xmlNode * expand_idref (xmlNode *input, xmlNode *top)
 
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,...)
 
int pcmk__xe_foreach_child (xmlNode *xml, const char *child_element_name, int(*handler)(xmlNode *xml, void *userdata), void *userdata)
 
xmlNode * find_entity (xmlNode *parent, const char *node_name, const char *id)
 
void crm_destroy_xml (gpointer data)
 

Macro Definition Documentation

◆ attr_matches

#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:517

Definition at line 503 of file xml.c.

◆ PCMK__XML_PARSE_OPTS

#define PCMK__XML_PARSE_OPTS   (XML_PARSE_NOBLANKS | XML_PARSE_RECOVER)

Definition at line 46 of file xml.c.

◆ PCMK__XMLDUMP_STATS

#define PCMK__XMLDUMP_STATS   0

Definition at line 1970 of file xml.c.

◆ XML_DOC_PRIVATE_MAGIC

#define XML_DOC_PRIVATE_MAGIC   0x81726354UL

Definition at line 173 of file xml.c.

◆ XML_NODE_PRIVATE_MAGIC

#define XML_NODE_PRIVATE_MAGIC   0x54637281UL

Definition at line 174 of file xml.c.

◆ XML_PARSER_DEBUG

#define XML_PARSER_DEBUG   0

Definition at line 33 of file xml.c.

◆ XPATH_MAX

#define XPATH_MAX   512

Definition at line 2999 of file xml.c.

Function Documentation

◆ add_node_copy()

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

Definition at line 727 of file xml.c.

◆ add_node_nocopy()

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

Definition at line 741 of file xml.c.

◆ can_prune_leaf()

gboolean can_prune_leaf ( xmlNode *  xml_node)

Definition at line 2526 of file xml.c.

◆ copy_in_properties()

void copy_in_properties ( xmlNode *  target,
xmlNode *  src 
)

Definition at line 545 of file xml.c.

◆ copy_xml()

xmlNode* copy_xml ( xmlNode *  src)

Definition at line 891 of file xml.c.

◆ create_xml_node()

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

Definition at line 749 of file xml.c.

◆ crm_destroy_xml()

void crm_destroy_xml ( gpointer  data)
Deprecated:
Do not use (will be removed in a future release)

Definition at line 3147 of file xml.c.

◆ crm_next_same_xml()

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 2956 of file xml.c.

◆ crm_xml_cleanup()

void crm_xml_cleanup ( void  )

Definition at line 2993 of file xml.c.

◆ crm_xml_escape()

char* crm_xml_escape ( const char *  text)

Replace special characters with their XML escape sequences.

Parameters
[in]textText to escape
Returns
Newly allocated string equivalent to text but with special characters replaced with XML escape sequences (or NULL if text is NULL)

Definition at line 1406 of file xml.c.

◆ crm_xml_init()

void crm_xml_init ( void  )

Initialize the CRM XML subsystem.

This method sets global XML settings and loads pacemaker schemas into the cache.

Definition at line 2971 of file xml.c.

◆ crm_xml_sanitize_id()

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 1190 of file xml.c.

◆ crm_xml_set_id()

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 1212 of file xml.c.

◆ dump_xml_formatted()

char* dump_xml_formatted ( xmlNode *  an_xml_node)

Definition at line 2106 of file xml.c.

◆ dump_xml_formatted_with_text()

char* dump_xml_formatted_with_text ( xmlNode *  an_xml_node)

Definition at line 2089 of file xml.c.

◆ dump_xml_unformatted()

char* dump_xml_unformatted ( xmlNode *  an_xml_node)

Definition at line 2121 of file xml.c.

◆ expand_idref()

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

Definition at line 3002 of file xml.c.

◆ expand_plus_plus()

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

Update current XML attribute value per parsed integer assignment statement.

Parameters
[in,out]targetan XML node, containing a XML attribute that is initialized to some numeric value, to be processed
[in]namename of the XML attribute, e.g. X, whose value should be updated
[in]valueassignment statement, e.g. "X++" or "X+=5", to be applied to the initialized value.
Note
The original XML attribute value is treated as 0 if non-numeric and truncated to be an integer if decimal-point-containing.
The final XML attribute value is truncated to not exceed 1000000.
Undefined behavior if unexpected input.

Definition at line 612 of file xml.c.

◆ filename2xml()

xmlNode* filename2xml ( const char *  filename)

Definition at line 1106 of file xml.c.

◆ find_entity()

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 3140 of file xml.c.

◆ find_xml_children()

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

Definition at line 2783 of file xml.c.

◆ find_xml_node()

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

Definition at line 470 of file xml.c.

◆ first_named_child()

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

Definition at line 2930 of file xml.c.

◆ fix_plus_plus_recursive()

void fix_plus_plus_recursive ( xmlNode *  target)

Parse integer assignment statements on this node and all its child nodes.

Parameters
[in,out]targetRoot XML node to be processed
Note
This function is recursive

Definition at line 578 of file xml.c.

◆ free_xml()

void free_xml ( xmlNode *  child)

Definition at line 885 of file xml.c.

◆ getDocPtr()

xmlDoc* getDocPtr ( xmlNode *  node)

Definition at line 711 of file xml.c.

◆ log_data_element()

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

Definition at line 1743 of file xml.c.

◆ pcmk__mark_xml_attr_dirty()

void pcmk__mark_xml_attr_dirty ( xmlAttr *  a)

Definition at line 163 of file xml.c.

◆ pcmk__mark_xml_created()

void pcmk__mark_xml_created ( xmlNode *  xml)

Definition at line 145 of file xml.c.

◆ pcmk__set_xml_doc_flag()

void pcmk__set_xml_doc_flag ( xmlNode *  xml,
enum xml_private_flags  flag 
)

Definition at line 108 of file xml.c.

◆ pcmk__strip_xml_text()

void pcmk__strip_xml_text ( xmlNode *  xml)

Definition at line 1078 of file xml.c.

◆ pcmk__tracking_xml_changes()

bool pcmk__tracking_xml_changes ( xmlNode *  xml,
bool  lazy 
)

Definition at line 49 of file xml.c.

◆ pcmk__xc_match()

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

Definition at line 2569 of file xml.c.

◆ pcmk__xc_update()

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

Definition at line 2618 of file xml.c.

◆ pcmk__xe_add_last_written()

const char* pcmk__xe_add_last_written ( xmlNode *  xe)

Definition at line 1176 of file xml.c.

◆ pcmk__xe_foreach_child()

int pcmk__xe_foreach_child ( xmlNode *  xml,
const char *  child_element_name,
int(*)(xmlNode *xml, void *userdata)  handler,
void *  userdata 
)

Definition at line 3112 of file xml.c.

◆ pcmk__xe_match()

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

Definition at line 520 of file xml.c.

◆ pcmk__xe_remove_matching_attrs()

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

Definition at line 682 of file xml.c.

◆ pcmk__xe_set_props()

void pcmk__xe_set_props ( xmlNodePtr  node,
  ... 
)

Definition at line 3103 of file xml.c.

◆ pcmk__xe_set_propv()

void pcmk__xe_set_propv ( xmlNodePtr  node,
va_list  pairs 
)

Definition at line 3085 of file xml.c.

◆ pcmk__xml2text()

void pcmk__xml2text ( xmlNodePtr  data,
int  options,
GString *  buffer,
int  depth 
)

Definition at line 1982 of file xml.c.

◆ pcmk__xml_artefact_path()

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

Definition at line 3063 of file xml.c.

◆ pcmk__xml_artefact_root()

char* pcmk__xml_artefact_root ( enum pcmk__xml_artefact_ns  ns)

Definition at line 3035 of file xml.c.

◆ pcmk__xml_log()

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

Definition at line 1623 of file xml.c.

◆ pcmk__xml_match()

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

Definition at line 394 of file xml.c.

◆ pcmk__xml_position()

int pcmk__xml_position ( const xmlNode *  xml,
enum xml_private_flags  ignore_if_set 
)

Definition at line 340 of file xml.c.

◆ pcmk__xml_update()

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

Definition at line 2649 of file xml.c.

◆ pcmk_create_html_node()

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

Definition at line 786 of file xml.c.

◆ pcmk_create_xml_text_node()

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

Definition at line 774 of file xml.c.

◆ pcmk_free_xml_subtree()

void pcmk_free_xml_subtree ( xmlNode *  xml)

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

Parameters
[in,out]xmlXML element to free

Definition at line 808 of file xml.c.

◆ replace_xml_child()

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

Definition at line 2816 of file xml.c.

◆ save_xml_to_file()

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

Definition at line 2163 of file xml.c.

◆ sorted_xml()

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

Definition at line 2898 of file xml.c.

◆ stdin2xml()

xmlNode* stdin2xml ( void  )

Definition at line 991 of file xml.c.

◆ string2xml()

xmlNode* string2xml ( const char *  input)

Definition at line 930 of file xml.c.

◆ update_xml_child()

gboolean update_xml_child ( xmlNode *  child,
xmlNode *  to_update 
)

Definition at line 2749 of file xml.c.

◆ write_xml_fd()

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 1333 of file xml.c.

◆ write_xml_file()

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 1361 of file xml.c.

◆ xml_accept_changes()

void xml_accept_changes ( xmlNode *  xml)

Definition at line 445 of file xml.c.

◆ xml_calculate_changes()

void xml_calculate_changes ( xmlNode *  old_xml,
xmlNode *  new_xml 
)

Definition at line 2512 of file xml.c.

◆ xml_calculate_significant_changes()

void xml_calculate_significant_changes ( xmlNode *  old_xml,
xmlNode *  new_xml 
)

Definition at line 2505 of file xml.c.

◆ xml_document_dirty()

bool xml_document_dirty ( xmlNode *  xml)

Definition at line 323 of file xml.c.

◆ xml_has_children()

gboolean xml_has_children ( const xmlNode *  xml_root)

Definition at line 2136 of file xml.c.

◆ xml_log_changes()

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

Definition at line 410 of file xml.c.

◆ xml_remove_prop()

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

Definition at line 2145 of file xml.c.

◆ xml_track_changes()

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

Definition at line 301 of file xml.c.

◆ xml_tracking_changes()

bool xml_tracking_changes ( xmlNode *  xml)

Definition at line 316 of file xml.c.