13 #include <sys/types.h> 17 #include <libxml/tree.h> 47 pcmk__new_nvpair(
const char *
name,
const char *value)
68 pcmk__free_nvpair(gpointer
data)
93 return g_slist_prepend(nvpairs, pcmk__new_nvpair(
name, value));
104 g_slist_free_full(nvpairs, pcmk__free_nvpair);
117 pcmk__compare_nvpair(gconstpointer a, gconstpointer b)
129 rc = strcmp(pair_a->
name, pair_b->
name);
148 return g_slist_sort(list, pcmk__compare_nvpair);
165 for (xmlAttrPtr iter = pcmk__xe_first_attr(xml); iter != NULL;
169 (
const char *) iter->name,
170 (
const char *) pcmk__xml_attr_value(iter));
186 pcmk__nvpair_add_xml_attr(gpointer
data, gpointer user_data)
189 xmlNode *
parent = user_data;
203 g_slist_foreach(list, pcmk__nvpair_add_xml_attr, xml);
226 if (sscanf(
input,
"%m[^=]=%m[^\n]",
name, value) <= 0) {
234 sep = strstr(optarg,
"=");
248 if (*(sep+1) !=
'\0') {
249 *value = strdup(sep+1);
251 if (*value == NULL) {
257 if (*
name != NULL && *value != NULL) {
259 }
else if (*
name != NULL || *value != NULL) {
305 xmlAttr *attr = NULL;
317 if (old == NULL || value == NULL || strcmp(old, value) != 0) {
323 crm_trace(
"Cannot add %s=%s to %s",
name, value, node->name);
332 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
333 return (
char *)attr->children->content;
351 char *number = pcmk__itoa(value);
424 const struct timeval *value)
426 const char *added = NULL;
428 if (xml && name_sec && value) {
430 if (added && name_usec) {
449 xmlAttr *attr = NULL;
456 }
else if (
name == NULL) {
465 if (!attr || !attr->children) {
468 return (
const char *) attr->children->content;
485 const char *value = NULL;
493 || (value_ll < INT_MIN) || (value_ll > INT_MAX)) {
496 *dest = (int) value_ll;
517 const char *value = NULL;
542 const char *value = NULL;
549 || (value_ll < 0) || (value_ll > G_MAXUINT)) {
552 *dest = (guint) value_ll;
570 long long value_ll = 0;
579 *dest = (time_t) value_ll;
598 const char *name_usec,
struct timeval *dest)
600 long long value_i = 0;
621 dest->tv_sec = (time_t) value_i;
627 dest->tv_usec = (suseconds_t) value_i;
646 char *value_copy = NULL;
668 const char *
name = key;
669 const char *s_value = value;
671 xmlNode *xml_node = user_data;
673 if (isdigit(
name[0])) {
702 const char *
name = key;
703 const char *s_value = value;
705 xmlNode *xml_node = user_data;
730 char *crm_name = NULL;
732 if (key == NULL || value == NULL) {
739 for (crm_name = key; *crm_name; ++crm_name) {
740 if ((*crm_name ==
'#') || (*crm_name ==
':')) {
803 const char *
name = key;
804 const char *s_value = value;
805 xmlNode *xml_node = user_data;
828 xmlNode *child = NULL;
829 xmlAttrPtr pIter = NULL;
830 xmlNode *nvpair_list = NULL;
836 if (nvpair_list == NULL) {
843 for (pIter = pcmk__xe_first_attr(nvpair_list); pIter != NULL;
844 pIter = pIter->next) {
846 const char *p_name = (
const char *)pIter->name;
847 const char *p_value = pcmk__xml_attr_value(pIter);
849 crm_trace(
"Added %s=%s", p_name, p_value);
851 g_hash_table_insert(nvpair_hash, strdup(p_name), strdup(p_value));
854 for (child = pcmk__xml_first_child(nvpair_list); child != NULL;
855 child = pcmk__xml_next(child)) {
862 if (key != NULL && value != NULL) {
863 g_hash_table_insert(nvpair_hash, strdup(key), strdup(value));
880 const char *xml_value = NULL;
885 }
else if (
name == NULL || value == NULL) {
891 if (xml_value == NULL) {
946 xmlAttr *attr = NULL;
947 const char *old_value = NULL;
955 CRM_CHECK(old_value != value,
return value);
959 crm_trace(
"Cannot replace %s=%s to %s",
name, value, node->name);
962 }
else if (old_value && !value) {
968 if (!old_value || !value || !strcmp(old_value, value)) {
977 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
978 return (
char *) attr->children->content;
#define CRM_CHECK(expr, failure_action)
GSList * pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value)
Prepend a name/value pair to a list.
int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest)
Retrieve the long long integer value of an XML attribute.
char * pcmk__format_nvpair(const char *name, const char *value, const char *units)
G_GNUC_INTERNAL void pcmk__mark_xml_attr_dirty(xmlAttr *a)
#define XML_BOOLEAN_FALSE
GHashTable * xml2list(const xmlNode *parent)
Retrieve XML attributes as a hash table.
xmlNode * find_xml_node(const xmlNode *root, const char *search_path, gboolean must_find)
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
GSList * pcmk_xml_attrs2nvpairs(const xmlNode *xml)
Create a list of name/value pairs from an XML node's attributes.
#define XML_NVPAIR_ATTR_NAME
#define CRM_LOG_ASSERT(expr)
#define XML_CIB_TAG_NVPAIR
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
bool pcmk__xe_attr_is_true(const xmlNode *node, const char *name)
char * crm_meta_name(const char *field)
int crm_element_value_timeval(const xmlNode *xml, const char *name_sec, const char *name_usec, struct timeval *dest)
Retrieve the value of XML second/microsecond attributes as time.
#define PCMK__PARSE_INT_DEFAULT
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
void hash2metafield(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry, as meta-attribute name.
void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml)
Add XML attributes based on a list of name/value pairs.
void pcmk__xe_set_bool_attr(xmlNodePtr node, const char *name, bool value)
char * pcmk_format_nvpair(const char *name, const char *value, const char *units)
#define crm_trace(fmt, args...)
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
void pcmk_free_nvpairs(GSList *nvpairs)
Free a list of name/value pairs.
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
void crm_xml_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
Add hash table entry to XML as (possibly legacy) name/value.
void pcmk__str_update(char **str, const char *value)
Wrappers for and extensions to libxml2.
char * pcmk_format_named_time(const char *name, time_t epoch_time)
xmlNode * create_xml_node(xmlNode *parent, const char *name)
void hash2nvpair(gpointer key, gpointer value, gpointer user_data)
Add XML nvpair element based on hash table entry.
int pcmk__xe_get_bool_attr(const xmlNode *node, const char *name, bool *value)
GSList * pcmk_sort_nvpairs(GSList *list)
Sort a list of name/value pairs.
const xmlChar * pcmkXmlStr
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
int crm_str_to_boolean(const char *s, int *ret)
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
pcmk__action_result_t result
#define crm_err(fmt, args...)
char * pcmk__epoch2str(const time_t *source, uint32_t flags)
Deprecated Pacemaker utilities.
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
bool pcmk__check_acl(xmlNode *xml, const char *name, enum xml_private_flags mode)
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
void xml_remove_prop(xmlNode *obj, const char *name)
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
#define XML_NVPAIR_ATTR_VALUE
const char * crm_xml_add_ll(xmlNode *xml, const char *name, long long value)
Create an XML attribute with specified name and long long int value.
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
const char * crm_xml_add_timeval(xmlNode *xml, const char *name_sec, const char *name_usec, const struct timeval *value)
Create XML attributes for seconds and microseconds.
#define crm_log_xml_trace(xml, text)
const char * crm_xml_add_ms(xmlNode *node, const char *name, guint ms)
Create an XML attribute with specified name and unsigned value.
G_GNUC_INTERNAL bool pcmk__tracking_xml_changes(xmlNode *xml, bool lazy)
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
int pcmk_scan_nvpair(const char *input, char **name, char **value)
#define pcmk_err_bad_nvpair
int pcmk__scan_nvpair(const char *input, char **name, char **value)