root/include/crm/common/nvpair.h

/* [previous][next][first][last][top][bottom][index][help] */

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. crm_copy_xml_element
  2. crm_xml_add_boolean

   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
  14 extern "C" {
  15 #  endif
  16 
  17 /**
  18  * \file
  19  * \brief Functionality for manipulating name/value pairs
  20  * \ingroup core
  21  */
  22 
  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 
  28 typedef struct pcmk_nvpair_s {
  29     char *name;
  30     char *value;
  31 } pcmk_nvpair_t;
  32 
  33 GSList *pcmk_prepend_nvpair(GSList *nvpairs, const char *name, const char *value);
  34 void pcmk_free_nvpairs(GSList *nvpairs);
  35 GSList *pcmk_sort_nvpairs(GSList *list);
  36 GSList *pcmk_xml_attrs2nvpairs(xmlNode *xml);
  37 void pcmk_nvpairs2xml_attrs(GSList *list, xmlNode *xml);
  38 
  39 xmlNode *crm_create_nvpair_xml(xmlNode *parent, const char *id,
  40                                const char *name, const char *value);
  41 void hash2nvpair(gpointer key, gpointer value, gpointer user_data);
  42 void hash2field(gpointer key, gpointer value, gpointer user_data);
  43 void hash2metafield(gpointer key, gpointer value, gpointer user_data);
  44 void hash2smartfield(gpointer key, gpointer value, gpointer user_data);
  45 GHashTable *xml2list(xmlNode *parent);
  46 
  47 const char *crm_xml_add(xmlNode *node, const char *name, const char *value);
  48 const char *crm_xml_replace(xmlNode *node, const char *name, const char *value);
  49 const char *crm_xml_add_int(xmlNode *node, const char *name, int value);
  50 const char *crm_xml_add_ll(xmlNode *node, const char *name, long long value);
  51 const char *crm_xml_add_ms(xmlNode *node, const char *name, guint ms);
  52 const char *crm_xml_add_timeval(xmlNode *xml, const char *name_sec,
  53                                 const char *name_usec,
  54                                 const struct timeval *value);
  55 
  56 const char *crm_element_value(const xmlNode *data, const char *name);
  57 int crm_element_value_int(const xmlNode *data, const char *name, int *dest);
  58 int crm_element_value_ll(const xmlNode *data, const char *name, long long *dest);
  59 int crm_element_value_ms(const xmlNode *data, const char *name, guint *dest);
  60 int crm_element_value_epoch(const xmlNode *xml, const char *name, time_t *dest);
  61 int crm_element_value_timeval(const xmlNode *data, const char *name_sec,
  62                               const char *name_usec, struct timeval *dest);
  63 char *crm_element_value_copy(const xmlNode *data, const char *name);
  64 
  65 /*!
  66  * \brief Copy an element from one XML object to another
  67  *
  68  * \param[in]     obj1     Source XML
  69  * \param[in,out] obj2     Destination XML
  70  * \param[in]     element  Name of element to copy
  71  *
  72  * \return Pointer to copied value (from source)
  73  */
  74 static inline const char *
  75 crm_copy_xml_element(xmlNode *obj1, xmlNode *obj2, const char *element)
     /* [previous][next][first][last][top][bottom][index][help] */
  76 {
  77     const char *value = crm_element_value(obj1, element);
  78 
  79     crm_xml_add(obj2, element, value);
  80     return value;
  81 }
  82 
  83 /*!
  84  * \brief Add a boolean attribute to an XML object
  85  *
  86  * Add an attribute with the value \c XML_BOOLEAN_TRUE or \c XML_BOOLEAN_FALSE
  87  * as appropriate to an XML object.
  88  *
  89  * \param[in,out] node   XML object to add attribute to
  90  * \param[in]     name   Name of attribute to add
  91  * \param[in]     value  Boolean whose value will be tested
  92  *
  93  * \return Pointer to newly created XML attribute's content, or \c NULL on error
  94  */
  95 static inline const char *
  96 crm_xml_add_boolean(xmlNode *node, const char *name, gboolean value)
     /* [previous][next][first][last][top][bottom][index][help] */
  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

/* [previous][next][first][last][top][bottom][index][help] */