pacemaker  2.0.1-9e909a5bdd
Scalable High-Availability cluster resource manager
nvpair.h
Go to the documentation of this file.
1 /*
2  * Copyright 2004-2019 Andrew Beekhof <andrew@beekhof.net>
3  *
4  * This source code is licensed under the GNU Lesser General Public License
5  * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
6  */
7 
8 #ifndef CRM_COMMON_NVPAIR__H
9 # define CRM_COMMON_NVPAIR__H
10 
11 # ifdef __cplusplus
12 extern "C" {
13 # endif
14 
21 # include <sys/time.h> // struct timeval
22 # include <glib.h> // gpointer, gboolean, guint
23 # include <libxml/tree.h> // xmlNode
24 # include <crm/crm.h>
25 
26 typedef struct pcmk_nvpair_s {
27  char *name;
28  char *value;
30 
31 GSList *pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value);
32 void pcmk_free_nvpairs(GSList *nvpairs);
33 GSList *pcmk_sort_nvpairs(GSList *list);
34 GSList *pcmk_xml_attrs2nvpairs(xmlNode *xml);
35 void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml);
36 
37 xmlNode *crm_create_nvpair_xml(xmlNode *parent, const char *id,
38  const char *name, const char *value);
39 void hash2nvpair(gpointer key, gpointer value, gpointer user_data);
40 void hash2field(gpointer key, gpointer value, gpointer user_data);
41 void hash2metafield(gpointer key, gpointer value, gpointer user_data);
42 void hash2smartfield(gpointer key, gpointer value, gpointer user_data);
43 GHashTable *xml2list(xmlNode *parent);
44 
45 const char *crm_xml_add(xmlNode *node, const char *name, const char *value);
46 const char *crm_xml_replace(xmlNode *node, const char *name, const char *value);
47 const char *crm_xml_add_int(xmlNode *node, const char *name, int value);
48 const char *crm_xml_add_ms(xmlNode *node, const char *name, guint ms);
49 
50 const char *crm_element_value(const xmlNode *data, const char *name);
51 int crm_element_value_int(const xmlNode *data, const char *name, int *dest);
52 int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest);
53 int crm_element_value_timeval(const xmlNode *data, const char *name_sec,
54  const char *name_usec, struct timeval *dest);
55 char *crm_element_value_copy(const xmlNode *data, const char *name);
56 
66 static inline const char *
67 crm_copy_xml_element(xmlNode *obj1, xmlNode *obj2, const char *element)
68 {
69  const char *value = crm_element_value(obj1, element);
70 
71  crm_xml_add(obj2, element, value);
72  return value;
73 }
74 
87 static inline const char *
88 crm_xml_add_boolean(xmlNode *node, const char *name, gboolean value)
89 {
90  return crm_xml_add(node, name, (value? "true" : "false"));
91 }
92 
93 # ifdef __cplusplus
94 }
95 # endif
96 
97 #endif // CRM_COMMON_NVPAIR__H
A dumping ground.
GSList * pcmk_sort_nvpairs(GSList *list)
Sort a list of name/value pairs.
Definition: nvpair.c:139
char * name
Definition: nvpair.h:27
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
Definition: nvpair.c:551
void pcmk_free_nvpairs(GSList *nvpairs)
Free a list of name/value pairs.
Definition: nvpair.c:95
const char * crm_xml_add_ms(xmlNode *node, const char *name, guint ms)
Create an XML attribute with specified name and unsigned value.
Definition: nvpair.c:342
char * value
Definition: nvpair.h:28
const char * crm_xml_add_int(xmlNode *node, const char *name, int value)
Create an XML attribute with specified name and integer value.
Definition: nvpair.c:320
const char * crm_xml_add(xmlNode *node, const char *name, const char *value)
Create an XML attribute with specified name and value.
Definition: nvpair.c:212
GSList * pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value)
Prepend a name/value pair to a list.
Definition: nvpair.c:84
GSList * pcmk_xml_attrs2nvpairs(xmlNode *xml)
Create a list of name/value pairs from an XML node&#39;s attributes.
Definition: nvpair.c:154
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Definition: nvpair.c:395
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
Add hash table entry to XML as (possibly legacy) name/value.
Definition: nvpair.c:517
void hash2nvpair(gpointer key, gpointer value, gpointer user_data)
Add XML nvpair element based on hash table entry.
Definition: nvpair.c:652
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
Definition: nvpair.c:420
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
Definition: nvpair.c:492
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:360
int crm_element_value_timeval(const xmlNode *data, const char *name_sec, const char *name_usec, struct timeval *dest)
Retrieve the value of XML second/microsecond attributes as time.
Definition: nvpair.c:444
const char * crm_xml_replace(xmlNode *node, const char *name, const char *value)
Replace an XML attribute with specified name and (possibly NULL) value.
Definition: nvpair.c:269
void hash2metafield(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry, as meta-attribute name.
Definition: nvpair.c:579
char data[0]
Definition: internal.h:90
GHashTable * xml2list(xmlNode *parent)
Retrieve XML attributes as a hash table.
Definition: nvpair.c:677
void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml)
Add XML attributes based on a list of name/value pairs.
Definition: nvpair.c:194
xmlNode * crm_create_nvpair_xml(xmlNode *parent, const char *id, const char *name, const char *value)
Create an XML name/value pair.
Definition: nvpair.c:614
struct pcmk_nvpair_s pcmk_nvpair_t