18 #ifndef CRM_COMMON_XML__H
19 # define CRM_COMMON_XML__H
28 # include <sys/types.h>
37 # include <libxml/tree.h>
38 # include <libxml/xpath.h>
48 # define CRM_BZ2_BLOCKS 4
49 # define CRM_BZ2_WORK 20
50 # define CRM_BZ2_THRESHOLD 128 * 1024
52 # define XML_PARANOIA_CHECKS 0
54 gboolean
add_message_xml(xmlNode * msg,
const char *field, xmlNode * xml);
56 GHashTable *
xml2list(xmlNode * parent);
59 const char *name,
const char *value);
61 void hash2nvpair(gpointer key, gpointer value, gpointer user_data);
62 void hash2field(gpointer key, gpointer value, gpointer user_data);
63 void hash2metafield(gpointer key, gpointer value, gpointer user_data);
78 void expand_plus_plus(xmlNode * target,
const char *name,
const char *value);
101 const char *
crm_xml_add(xmlNode * node,
const char *name,
const char *value);
103 const char *
crm_xml_replace(xmlNode * node,
const char *name,
const char *value);
105 const char *
crm_xml_add_int(xmlNode * node,
const char *name,
int value);
119 static inline const char *
120 crm_xml_add_boolean(xmlNode *node,
const char *name, gboolean value)
122 return crm_xml_add(node, name, (value?
"true" :
"false"));
140 xmlNode *
copy_xml(xmlNode * src_node);
145 xmlNode *
add_node_copy(xmlNode * new_parent, xmlNode * xml_node);
147 int add_node_nocopy(xmlNode * parent,
const char *name, xmlNode * child);
160 int write_xml_fd(xmlNode * xml_node,
const char *filename,
int fd, gboolean compress);
161 int write_xml_file(xmlNode * xml_node,
const char *filename, gboolean compress);
172 xmlNode *
diff_xml_object(xmlNode * left, xmlNode * right, gboolean suppress);
175 gboolean full, gboolean * changed,
const char *marker);
181 gboolean
apply_xml_diff(xmlNode * old, xmlNode * diff, xmlNode **
new);
186 xmlNode *
find_xml_node(xmlNode * cib,
const char *node_path, gboolean must_find);
188 xmlNode *
find_entity(xmlNode * parent,
const char *node_name,
const char *
id);
193 gboolean delete_only);
198 const char *tag,
const char *field,
const char *value,
199 gboolean search_matches);
205 xmlNode *
get_xpath_object(
const char *xpath, xmlNode * xml_obj,
int error_level);
208 static inline const char *
209 crm_element_name(xmlNode *xml)
211 return xml? (
const char *)(xml->name) : NULL;
225 static inline const char *
226 crm_copy_xml_element(xmlNode *obj1, xmlNode *obj2,
const char *element)
244 gboolean
validate_xml(xmlNode * xml_blob,
const char *validation, gboolean to_logs);
285 gboolean transform, gboolean to_logs);
295 static inline xmlNode *
296 __xml_first_child(xmlNode * parent)
298 xmlNode *child = NULL;
301 child = parent->children;
302 while (child && child->type == XML_TEXT_NODE) {
309 static inline xmlNode *
310 __xml_next(xmlNode * child)
314 while (child && child->type == XML_TEXT_NODE) {
321 static inline xmlNode *
322 __xml_first_child_element(xmlNode * parent)
324 xmlNode *child = NULL;
327 child = parent->children;
331 if(child->type == XML_ELEMENT_NODE) {
339 static inline xmlNode *
340 __xml_next_element(xmlNode * child)
344 if(child && child->type == XML_ELEMENT_NODE) {
356 xmlNode *
sorted_xml(xmlNode * input, xmlNode * parent, gboolean recursive);
357 xmlXPathObjectPtr
xpath_search(xmlNode * xml_top,
const char *path);
359 void (*helper)(xmlNode*,
void*),
void *user_data);
366 static inline int numXpathResults(xmlXPathObjectPtr xpathObj)
368 if(xpathObj == NULL || xpathObj->nodesetval == NULL) {
371 return xpathObj->nodesetval->nodeNr;
381 void xml_track_changes(xmlNode * xml,
const char *user, xmlNode *acl_source,
bool enforce_acls);
389 int format, xmlNode *source, xmlNode *target,
bool *config,
bool manage_version);
394 void save_xml_to_file(xmlNode * xml,
const char *desc,
const char *filename);
xmlNode * find_xml_node(xmlNode *cib, const char *node_path, gboolean must_find)
xmlNode * get_xpath_object_relative(const char *xpath, xmlNode *xml_obj, int error_level)
void unlink_xml_node(xmlNode *node)
xmlNode * get_message_xml(xmlNode *msg, const char *field)
GHashTable * xml2list(xmlNode *parent)
void xml_validate(const xmlNode *root)
int crm_element_value_const_int(const xmlNode *data, const char *name, int *dest)
void xml_calculate_changes(xmlNode *old, xmlNode *new)
void crm_xml_cleanup(void)
xmlNode * find_entity(xmlNode *parent, const char *node_name, const char *id)
void xml_track_changes(xmlNode *xml, const char *user, xmlNode *acl_source, bool enforce_acls)
bool xml_acl_denied(xmlNode *xml)
int write_xml_file(xmlNode *xml_node, const char *filename, gboolean compress)
char * crm_element_value_copy(xmlNode *data, const char *name)
int get_schema_version(const char *name)
void print_xml_diff(FILE *where, xmlNode *diff)
void copy_in_properties(xmlNode *target, xmlNode *src)
void xml_accept_changes(xmlNode *xml)
xmlNode * filename2xml(const char *filename)
void dedupXpathResults(xmlXPathObjectPtr xpathObj)
void purge_diff_markers(xmlNode *a_node)
xmlNode * get_xpath_object(const char *xpath, xmlNode *xml_obj, int error_level)
xmlNode * string2xml(const char *input)
void crm_xml_sanitize_id(char *id)
Sanitize a string so it is usable as an XML ID.
gboolean validate_xml(xmlNode *xml_blob, const char *validation, gboolean to_logs)
xmlDoc * getDocPtr(xmlNode *node)
bool xml_acl_enabled(xmlNode *xml)
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
gboolean validate_xml_verbose(xmlNode *xml_blob)
void expand_plus_plus(xmlNode *target, const char *name, const char *value)
bool xml_tracking_changes(xmlNode *xml)
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
xmlNode * copy_xml(xmlNode *src_node)
void hash2field(gpointer key, gpointer value, gpointer user_data)
char * calculate_operation_digest(xmlNode *local_cib, const char *version)
Calculate and return digest of XML operation.
xmlNode * stdin2xml(void)
int xml_apply_patchset(xmlNode *xml, xmlNode *patchset, bool check_version)
gboolean update_xml_child(xmlNode *child, xmlNode *to_update)
enum crm_proc_flag __attribute__
xmlNode * add_node_copy(xmlNode *new_parent, xmlNode *xml_node)
const char * crm_element_value_const(const xmlNode *data, const char *name)
xmlNode * expand_idref(xmlNode *input, xmlNode *top)
bool xml_document_dirty(xmlNode *xml)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
int crm_element_value_int(xmlNode *data, const char *name, int *dest)
char * dump_xml_formatted(xmlNode *msg)
const char * crm_element_value(xmlNode *data, const char *name)
xmlNode * crm_next_same_xml(xmlNode *sibling)
Get next instance of same XML tag.
void xml_acl_disable(xmlNode *xml)
void void crm_destroy_xml(gpointer data)
xmlNode destructor which can be used in glib collections
gboolean add_message_xml(xmlNode *msg, const char *field, xmlNode *xml)
void free_xml(xmlNode *child)
gboolean xml_has_children(const xmlNode *root)
char * calculate_on_disk_digest(xmlNode *local_cib)
Calculate and return digest of XML tree, suitable for storing on disk.
xmlNode * sorted_xml(xmlNode *input, xmlNode *parent, gboolean recursive)
const char * xml_latest_schema(void)
void patchset_process_digest(xmlNode *patch, xmlNode *source, xmlNode *target, bool with_digest)
void hash2metafield(gpointer key, gpointer value, gpointer user_data)
int find_xml_children(xmlNode **children, xmlNode *root, const char *tag, const char *field, const char *value, gboolean search_matches)
bool xml_patch_versions(xmlNode *patchset, int add[3], int del[3])
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
void xml_log_changes(uint8_t level, const char *function, xmlNode *xml)
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
gboolean apply_xml_diff(xmlNode *old, xmlNode *diff, xmlNode **new)
xmlXPathObjectPtr xpath_search(xmlNode *xml_top, const char *path)
void crm_xml_set_id(xmlNode *xml, const char *format,...) __attribute__((__format__(__printf__
void xml_remove_prop(xmlNode *obj, const char *name)
xmlNode * getXpathResult(xmlXPathObjectPtr xpathObj, int index)
char * calculate_xml_versioned_digest(xmlNode *input, gboolean sort, gboolean do_filter, const char *version)
Calculate and return digest of XML tree.
gboolean can_prune_leaf(xmlNode *xml_node)
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
char * xml_get_path(xmlNode *xml)
char * dump_xml_unformatted(xmlNode *msg)
bool xml_acl_filtered_copy(const char *user, xmlNode *acl_source, xmlNode *xml, xmlNode **result)
void save_xml_to_file(xmlNode *xml, const char *desc, const char *filename)
void crm_foreach_xpath_result(xmlNode *xml, const char *xpath, void(*helper)(xmlNode *, void *), void *user_data)
Run a supplied function for each result of an xpath search.
int update_validation(xmlNode **xml_blob, int *best, int max, gboolean transform, gboolean to_logs)
Update CIB XML to most recent schema version.
xmlNode * diff_xml_object(xmlNode *left, xmlNode *right, gboolean suppress)
int add_node_nocopy(xmlNode *parent, const char *name, xmlNode *child)
xmlNode * first_named_child(xmlNode *parent, const char *name)
xmlNode * subtract_xml_object(xmlNode *parent, xmlNode *left, xmlNode *right, gboolean full, gboolean *changed, const char *marker)
void xml_log_patchset(uint8_t level, const char *function, xmlNode *xml)
int write_xml_fd(xmlNode *xml_node, const char *filename, int fd, gboolean compress)
char * crm_xml_escape(const char *text)
gboolean cli_config_update(xmlNode **xml, int *best_version, gboolean to_logs)
void hash2nvpair(gpointer key, gpointer value, gpointer user_data)
void fix_plus_plus_recursive(xmlNode *target)
void freeXpathObject(xmlXPathObjectPtr xpathObj)
xmlNode * xml_create_patchset(int format, xmlNode *source, xmlNode *target, bool *config, bool manage_version)
char * dump_xml_formatted_with_text(xmlNode *msg)
gboolean replace_xml_child(xmlNode *parent, xmlNode *child, xmlNode *update, gboolean delete_only)
const char * get_schema_name(int version)