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);
129 if (sscanf(
input,
"%m[^=]=%m[^\n]",
name, value) <= 0) {
137 sep = strstr(optarg,
"=");
151 if (*(sep+1) !=
'\0') {
152 *value = strdup(sep+1);
154 if (*value == NULL) {
160 if (*
name != NULL && *value != NULL) {
162 }
else if (*
name != NULL || *value != NULL) {
217 const char *
name = key;
218 const char *s_value = value;
220 xmlNode *xml_node = user_data;
222 if (isdigit(
name[0])) {
251 const char *
name = key;
252 const char *s_value = value;
254 xmlNode *xml_node = user_data;
279 char *crm_name = NULL;
281 if (key == NULL || value == NULL) {
288 for (crm_name = key; *crm_name; ++crm_name) {
289 if ((*crm_name ==
'#') || (*crm_name ==
':')) {
352 xmlNode *child = NULL;
353 xmlAttrPtr pIter = NULL;
354 xmlNode *nvpair_list = NULL;
360 if (nvpair_list == NULL) {
367 for (pIter = pcmk__xe_first_attr(nvpair_list); pIter != NULL;
368 pIter = pIter->next) {
370 const char *p_name = (
const char *)pIter->name;
371 const char *p_value = pcmk__xml_attr_value(pIter);
373 crm_trace(
"Added %s=%s", p_name, p_value);
385 if (key != NULL && value != NULL) {
409 char *env_name = NULL;
414 for (
char *c = env_name; *c !=
'\0'; ++c) {
437 if ((meta != NULL) && (attr_name != NULL)) {
439 const char *value = g_hash_table_lookup(meta, key);
466 const xmlNode *pair_a = a;
467 const xmlNode *pair_b = b;
479 const gint a_is_higher = ((unpack_data != NULL)
481 const gint b_is_higher = -a_is_higher;
487 return (b == NULL)? 0 : b_is_higher;
489 }
else if (b == NULL) {
498 if ((unpack_data != NULL) && (unpack_data->
first_id != NULL)) {
499 if (pcmk__str_eq(pcmk__xe_id(pair_a), unpack_data->
first_id,
503 }
else if (pcmk__str_eq(pcmk__xe_id(pair_b), unpack_data->
first_id,
514 "is not a valid score: %s",
523 "is not a valid score: %s",
529 if (score_a < score_b) {
532 }
else if (score_a > score_b) {
544 pcmk__compare_nvpair(gconstpointer a, gconstpointer b)
551 && (pair_b != NULL) && (pair_b->
name != NULL));
553 rc = strcmp(pair_a->
name, pair_b->
name);
565 return g_slist_sort(list, pcmk__compare_nvpair);
573 for (xmlAttrPtr iter = pcmk__xe_first_attr(xml); iter != NULL;
577 (
const char *) iter->name,
578 (
const char *) pcmk__xml_attr_value(iter));
584 pcmk__nvpair_add_xml_attr(gpointer
data, gpointer user_data)
587 xmlNode *
parent = user_data;
595 g_slist_foreach(list, pcmk__nvpair_add_xml_attr, xml);
601 const char *
name = key;
602 const char *s_value = value;
603 xmlNode *xml_node = user_data;
#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.
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 pcmk__config_warn(fmt...)
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.
GSList * pcmk_xml_attrs2nvpairs(const xmlNode *xml)
#define PCMK__XE_ATTRIBUTES
const char * pcmk_rc_str(int rc)
Get a user-friendly description of a return code.
Deprecated Pacemaker name-value pair API.
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
xmlNode * pcmk__xe_create(xmlNode *parent, 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.
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)
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
#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.
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 hash2nvpair(gpointer key, gpointer value, gpointer user_data)
#define pcmk__str_copy(str)
GSList * pcmk_sort_nvpairs(GSList *list)
xmlNode * pcmk__xe_next(const xmlNode *node, const char *element_name)
const char * crm_meta_value(GHashTable *meta, const char *attr_name)
Get the value of a meta-attribute.
#define pcmk__assert(expr)
void int pcmk__xe_get_score(const xmlNode *xml, const char *name, int *score, int default_score)
GHashTable * pcmk__strkey_table(GDestroyNotify key_destroy_func, GDestroyNotify value_destroy_func)
pcmk__action_result_t result
void pcmk__xe_set_id(xmlNode *xml, const char *format,...) G_GNUC_PRINTF(2
#define crm_log_xml_trace(xml, text)
#define pcmk__assert_alloc(nmemb, size)
#define pcmk_err_bad_nvpair
gint pcmk__cmp_nvpair_blocks(gconstpointer a, gconstpointer b, gpointer user_data)
void pcmk__insert_dup(GHashTable *table, const char *name, const char *value)
char * crm_strdup_printf(char const *format,...) G_GNUC_PRINTF(1
int pcmk__scan_nvpair(const char *input, char **name, char **value)