15 #include <sys/types.h> 19 #include <libxml/tree.h> 49 pcmk__new_nvpair(
const char *
name,
const char *value)
69 pcmk__free_nvpair(gpointer
data)
94 return g_slist_prepend(nvpairs, pcmk__new_nvpair(
name, value));
105 g_slist_free_full(nvpairs, pcmk__free_nvpair);
118 pcmk__compare_nvpair(gconstpointer a, gconstpointer b)
125 && (pair_b != NULL) && (pair_b->
name != NULL));
127 rc = strcmp(pair_a->
name, pair_b->
name);
146 return g_slist_sort(list, pcmk__compare_nvpair);
163 for (xmlAttrPtr iter = pcmk__xe_first_attr(xml); iter != NULL;
167 (
const char *) iter->name,
168 (
const char *) pcmk__xml_attr_value(iter));
184 pcmk__nvpair_add_xml_attr(gpointer
data, gpointer user_data)
187 xmlNode *
parent = user_data;
201 g_slist_foreach(list, pcmk__nvpair_add_xml_attr, xml);
224 if (sscanf(
input,
"%m[^=]=%m[^\n]",
name, value) <= 0) {
232 sep = strstr(optarg,
"=");
246 if (*(sep+1) !=
'\0') {
247 *value = strdup(sep+1);
249 if (*value == NULL) {
255 if (*
name != NULL && *value != NULL) {
257 }
else if (*
name != NULL || *value != NULL) {
316 xmlAttr *attr = NULL;
328 if (old == NULL || value == NULL || strcmp(old, value) != 0) {
334 crm_trace(
"Cannot add %s=%s to %s",
name, value, node->name);
343 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
344 return (
char *)attr->children->content;
362 char *number = pcmk__itoa(value);
435 const struct timeval *value)
437 const char *added = NULL;
439 if (xml && name_sec && value) {
441 if (added && name_usec) {
460 xmlAttr *attr = NULL;
467 }
else if (
name == NULL) {
476 if (!attr || !attr->children) {
479 return (
const char *) attr->children->content;
496 const char *value = NULL;
507 "because '%s' is not a valid integer: %s",
509 }
else if ((value_ll < INT_MIN) || (value_ll > INT_MAX)) {
510 crm_warn(
"Using default for %s because '%s' is out of range",
513 *dest = (int) value_ll;
536 uint32_t default_value)
538 const char *value = NULL;
539 long long value_ll = 0LL;
543 *dest = default_value;
558 if ((value_ll < 0) || (value_ll > UINT32_MAX)) {
559 value_ll = default_value;
566 *dest = (uint32_t) value_ll;
585 const char *value = NULL;
596 "because '%s' is not a valid integer: %s",
616 const char *value = NULL;
626 "because '%s' is not valid milliseconds: %s",
630 if ((value_ll < 0) || (value_ll > G_MAXUINT)) {
631 crm_warn(
"Using default for %s because '%s' is out of range",
635 *dest = (guint) value_ll;
653 long long value_ll = 0;
662 *dest = (time_t) value_ll;
681 const char *name_usec,
struct timeval *dest)
683 long long value_i = 0;
704 dest->tv_sec = (time_t) value_i;
710 dest->tv_usec = (suseconds_t) value_i;
730 const char *value = NULL;
732 if ((t == NULL) || (*t != NULL) || (xml == NULL) || (attr == NULL)) {
788 const char *
name = key;
789 const char *s_value = value;
791 xmlNode *xml_node = user_data;
793 if (isdigit(
name[0])) {
822 const char *
name = key;
823 const char *s_value = value;
825 xmlNode *xml_node = user_data;
850 char *crm_name = NULL;
852 if (key == NULL || value == NULL) {
859 for (crm_name = key; *crm_name; ++crm_name) {
860 if ((*crm_name ==
'#') || (*crm_name ==
':')) {
920 const char *
name = key;
921 const char *s_value = value;
922 xmlNode *xml_node = user_data;
945 xmlNode *child = NULL;
946 xmlAttrPtr pIter = NULL;
947 xmlNode *nvpair_list = NULL;
953 if (nvpair_list == NULL) {
960 for (pIter = pcmk__xe_first_attr(nvpair_list); pIter != NULL;
961 pIter = pIter->next) {
963 const char *p_name = (
const char *)pIter->name;
964 const char *p_value = pcmk__xml_attr_value(pIter);
966 crm_trace(
"Added %s=%s", p_name, p_value);
978 if (key != NULL && value != NULL) {
995 const char *xml_value = NULL;
1000 }
else if (
name == NULL || value == NULL) {
1006 if (xml_value == NULL) {
1045 char *env_name = NULL;
1050 for (
char *c = env_name; *c !=
'\0'; ++c) {
1073 if ((meta != NULL) && (attr_name != NULL)) {
1075 const char *value = g_hash_table_lookup(meta, key);
1115 xmlAttr *attr = NULL;
1116 const char *old_value = NULL;
1124 CRM_CHECK(old_value != value,
return value);
1128 crm_trace(
"Cannot replace %s=%s to %s",
name, value, node->name);
1131 }
else if (old_value && !value) {
1137 if (!old_value || !value || !strcmp(old_value, value)) {
1146 CRM_CHECK(attr && attr->children && attr->children->content,
return NULL);
1147 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.
struct crm_time_s crm_time_t
char * pcmk__format_nvpair(const char *name, const char *value, const char *units)
G_GNUC_INTERNAL void pcmk__mark_xml_attr_dirty(xmlAttr *a)
char * crm_meta_name(const char *attr_name)
Get the environment variable equivalent of a meta-attribute name.
GHashTable * xml2list(const xmlNode *parent)
Retrieve XML attributes as a hash table.
int pcmk__xe_get_flags(const xmlNode *xml, const char *name, uint32_t *dest, uint32_t default_value)
Retrieve a flag group from an XML attribute value.
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 PCMK__XE_ATTRIBUTES
#define CRM_LOG_ASSERT(expr)
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
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)
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.
int pcmk__xe_get_datetime(const xmlNode *xml, const char *attr, crm_time_t **t)
#define PCMK__PARSE_INT_DEFAULT
int pcmk__scan_ll(const char *text, long long *result, long long default_value)
#define crm_warn(fmt, args...)
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)
G_GNUC_INTERNAL void pcmk__xml_new_private_data(xmlNode *xml)
xmlNode * pcmk__xe_first_child(const xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
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)
Safely add hash table entry to XML as attribute or name-value pair.
Wrappers for and extensions to libxml2.
void pcmk__xe_remove_attr(xmlNode *element, const char *name)
char * pcmk_format_named_time(const char *name, time_t epoch_time)
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)
#define pcmk__str_copy(str)
GSList * pcmk_sort_nvpairs(GSList *list)
Sort a list of name/value pairs.
const xmlChar * pcmkXmlStr
const char * crm_meta_value(GHashTable *meta, const char *attr_name)
Get the value of a meta-attribute.
#define pcmk__assert(expr)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
xmlAttr * pcmk__xe_set_attr_force(xmlNode *node, const char *name, const char *value)
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.
crm_time_t * crm_time_new(const char *string)
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.
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and 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.
xmlNode * pcmk__xe_create(xmlNode *parent, const char *name)
#define pcmk__assert_alloc(nmemb, size)
int pcmk_scan_nvpair(const char *input, char **name, char **value)
xmlNode * pcmk__xe_next_same(const xmlNode *node)
#define pcmk_err_bad_nvpair
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
int pcmk__scan_nvpair(const char *input, char **name, char **value)