pacemaker 2.1.5-a3f44794f94
Scalable High-Availability cluster resource manager
nvpair.h
Go to the documentation of this file.
1/*
2 * Copyright 2004-2022 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 PCMK__CRM_COMMON_NVPAIR__H
11# define PCMK__CRM_COMMON_NVPAIR__H
12
13# include <sys/time.h> // struct timeval
14# include <glib.h> // gpointer, gboolean, guint
15# include <libxml/tree.h> // xmlNode
16# include <crm/crm.h>
17
18
19# ifdef __cplusplus
20extern "C" {
21# endif
22
29typedef struct pcmk_nvpair_s {
30 char *name;
31 char *value;
33
34GSList *pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value);
35void pcmk_free_nvpairs(GSList *nvpairs);
36GSList *pcmk_sort_nvpairs(GSList *list);
37GSList *pcmk_xml_attrs2nvpairs(const xmlNode *xml);
38void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml);
39
40xmlNode *crm_create_nvpair_xml(xmlNode *parent, const char *id,
41 const char *name, const char *value);
42void hash2nvpair(gpointer key, gpointer value, gpointer user_data);
43void hash2field(gpointer key, gpointer value, gpointer user_data);
44void hash2metafield(gpointer key, gpointer value, gpointer user_data);
45void hash2smartfield(gpointer key, gpointer value, gpointer user_data);
46GHashTable *xml2list(const xmlNode *parent);
47
48const char *crm_xml_add(xmlNode *node, const char *name, const char *value);
49const char *crm_xml_replace(xmlNode *node, const char *name, const char *value);
50const char *crm_xml_add_int(xmlNode *node, const char *name, int value);
51const char *crm_xml_add_ll(xmlNode *node, const char *name, long long value);
52const char *crm_xml_add_ms(xmlNode *node, const char *name, guint ms);
53const char *crm_xml_add_timeval(xmlNode *xml, const char *name_sec,
54 const char *name_usec,
55 const struct timeval *value);
56
57const char *crm_element_value(const xmlNode *data, const char *name);
58int crm_element_value_int(const xmlNode *data, const char *name, int *dest);
59int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest);
60int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest);
61int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest);
62int crm_element_value_timeval(const xmlNode *data, const char *name_sec,
63 const char *name_usec, struct timeval *dest);
64char *crm_element_value_copy(const xmlNode *data, const char *name);
65
75static inline const char *
76crm_copy_xml_element(const xmlNode *obj1, xmlNode *obj2, const char *element)
77{
78 const char *value = crm_element_value(obj1, element);
79
80 crm_xml_add(obj2, element, value);
81 return value;
82}
83
84# ifdef __cplusplus
85}
86# endif
87
88#endif // PCMK__CRM_COMMON_NVPAIR__H
const char * parent
Definition: cib.c:25
const char * name
Definition: cib.c:24
char data[0]
Definition: cpg.c:10
A dumping ground.
GHashTable * xml2list(const xmlNode *parent)
Retrieve XML attributes as a hash table.
Definition: nvpair.c:896
const char * crm_element_value(const xmlNode *data, const char *name)
Retrieve the value of an XML attribute.
Definition: nvpair.c:517
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:493
void hash2nvpair(gpointer key, gpointer value, gpointer user_data)
Add XML nvpair element based on hash table entry.
Definition: nvpair.c:871
int crm_element_value_int(const xmlNode *data, const char *name, int *dest)
Retrieve the integer value of an XML attribute.
Definition: nvpair.c:553
GSList * pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value)
Prepend a name/value pair to a list.
Definition: nvpair.c:91
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:833
void hash2metafield(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry, as meta-attribute name.
Definition: nvpair.c:798
GSList * pcmk_sort_nvpairs(GSList *list)
Sort a list of name/value pairs.
Definition: nvpair.c:146
void hash2field(gpointer key, gpointer value, gpointer user_data)
Set XML attribute based on hash table entry.
Definition: nvpair.c:770
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:419
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:368
void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml)
Add XML attributes based on a list of name/value pairs.
Definition: nvpair.c:201
void pcmk_free_nvpairs(GSList *nvpairs)
Free a list of name/value pairs.
Definition: nvpair.c:102
int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest)
Retrieve the millisecond value of an XML attribute.
Definition: nvpair.c:610
char * crm_element_value_copy(const xmlNode *data, const char *name)
Retrieve a copy of the value of an XML attribute.
Definition: nvpair.c:714
void hash2smartfield(gpointer key, gpointer value, gpointer user_data)
Add hash table entry to XML as (possibly legacy) name/value.
Definition: nvpair.c:736
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:667
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:585
GSList * pcmk_xml_attrs2nvpairs(const xmlNode *xml)
Create a list of name/value pairs from an XML node's attributes.
Definition: nvpair.c:161
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:469
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:638
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:323
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:441
char * value
Definition: nvpair.h:31
char * name
Definition: nvpair.h:30