pacemaker 2.1.1-77db578727
Scalable High-Availability cluster resource manager
Loading...
Searching...
No Matches
nvpair.h
Go to the documentation of this file.
1/*
2 * Copyright 2004-2019 the Pacemaker project contributors
3 *
4 * The version control history for this file may have further details.
5 *
6 * This source code is licensed under the GNU Lesser General Public License
7 * version 2.1 or later (LGPLv2.1+) WITHOUT ANY WARRANTY.
8 */
9
10#ifndef CRM_COMMON_NVPAIR__H
11# define CRM_COMMON_NVPAIR__H
12
13# ifdef __cplusplus
14extern "C" {
15# endif
16
23# include <sys/time.h> // struct timeval
24# include <glib.h> // gpointer, gboolean, guint
25# include <libxml/tree.h> // xmlNode
26# include <crm/crm.h>
27
28typedef struct pcmk_nvpair_s {
29 char *name;
30 char *value;
32
33GSList *pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value);
34void pcmk_free_nvpairs(GSList *nvpairs);
35GSList *pcmk_sort_nvpairs(GSList *list);
36GSList *pcmk_xml_attrs2nvpairs(xmlNode *xml);
37void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml);
38
39xmlNode *crm_create_nvpair_xml(xmlNode *parent, const char *id,
40 const char *name, const char *value);
41void hash2nvpair(gpointer key, gpointer value, gpointer user_data);
42void hash2field(gpointer key, gpointer value, gpointer user_data);
43void hash2metafield(gpointer key, gpointer value, gpointer user_data);
44void hash2smartfield(gpointer key, gpointer value, gpointer user_data);
45GHashTable *xml2list(xmlNode *parent);
46
47const char *crm_xml_add(xmlNode *node, const char *name, const char *value);
48const char *crm_xml_replace(xmlNode *node, const char *name, const char *value);
49const char *crm_xml_add_int(xmlNode *node, const char *name, int value);
50const char *crm_xml_add_ll(xmlNode *node, const char *name, long long value);
51const char *crm_xml_add_ms(xmlNode *node, const char *name, guint ms);
52const char *crm_xml_add_timeval(xmlNode *xml, const char *name_sec,
53 const char *name_usec,
54 const struct timeval *value);
55
56const char *crm_element_value(const xmlNode *data, const char *name);
57int crm_element_value_int(const xmlNode *data, const char *name, int *dest);
58int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest);
59int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest);
60int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest);
61int crm_element_value_timeval(const xmlNode *data, const char *name_sec,
62 const char *name_usec, struct timeval *dest);
63char *crm_element_value_copy(const xmlNode *data, const char *name);
64
74static inline const char *
75crm_copy_xml_element(xmlNode *obj1, xmlNode *obj2, const char *element)
76{
77 const char *value = crm_element_value(obj1, element);
78
79 crm_xml_add(obj2, element, value);
80 return value;
81}
82
95static inline const char *
96crm_xml_add_boolean(xmlNode *node, const char *name, gboolean value)
97{
98 return crm_xml_add(node, name, (value? "true" : "false"));
99}
100
101# ifdef __cplusplus
102}
103# endif
104
105#endif // CRM_COMMON_NVPAIR__H
char data[0]
Definition cpg.c:10
A dumping ground.
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition nvpair.c:530
struct pcmk_nvpair_s pcmk_nvpair_t
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.
Definition nvpair.c:506
void hash2nvpair(gpointer key, gpointer value, gpointer user_data)
Add XML nvpair element based on hash table entry.
Definition nvpair.c:887
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Definition nvpair.c:566
GSList * pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value)
Prepend a name/value pair to a list.
Definition nvpair.c:92
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:849
void hash2metafield(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry, as meta-attribute name.
Definition nvpair.c:814
GSList * pcmk_sort_nvpairs(GSList *list)
Sort a list of name/value pairs.
Definition nvpair.c:147
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
Definition nvpair.c:786
GHashTable * xml2list(xmlNode *parent)
Retrieve XML attributes as a hash table.
Definition nvpair.c:912
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:432
GSList * pcmk_xml_attrs2nvpairs(xmlNode *xml)
Create a list of name/value pairs from an XML node's attributes.
Definition nvpair.c:162
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:381
void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml)
Add XML attributes based on a list of name/value pairs.
Definition nvpair.c:202
void pcmk_free_nvpairs(GSList *nvpairs)
Free a list of name/value pairs.
Definition nvpair.c:103
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
Definition nvpair.c:623
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
Definition nvpair.c:727
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
Add hash table entry to XML as (possibly legacy) name/value.
Definition nvpair.c:752
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:680
int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest)
Retrieve the long long integer value of an XML attribute.
Definition nvpair.c:598
const char * crm_xml_add_ll(xmlNode *node, const char *name, long long value)
Create an XML attribute with specified name and long long int value.
Definition nvpair.c:482
int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest)
Retrieve the seconds-since-epoch value of an XML attribute.
Definition nvpair.c:651
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:324
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:454
char * name
Definition pcmk_fence.c:31
char * value
Definition nvpair.h:30
char * name
Definition nvpair.h:29