root/include/crm/common/xpath_internal.h

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

INCLUDED FROM


DEFINITIONS

This source file includes following definitions.
  1. pcmk__xpath_num_results

   1 /*
   2  * Copyright 2022-2025 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_XPATH_INTERNAL__H
  11 #define PCMK__CRM_COMMON_XPATH_INTERNAL__H
  12 
  13 #include <stdint.h>                     // uint8_t
  14 
  15 #include <glib.h>                       // GString
  16 #include <libxml/tree.h>                // xmlDoc, xmlNode
  17 #include <libxml/xpath.h>               // xmlXPathObject, etc.
  18 #include <qb/qbdefs.h>                      // QB_MAX()
  19 
  20 #include <crm/common/options.h>             // PCMK_META_*, PCMK_VALUE_*
  21 #include <crm/common/output_internal.h>     // pcmk__output_t
  22 #include <crm/common/xml_names.h>           // PCMK_XE_*, PCMK_XA_*, etc.
  23 #include <crm/common/xml_names_internal.h>  // PCMK__XE_*
  24 
  25 /*
  26  * Internal-only wrappers for and extensions to libxml2 XPath utilities
  27  */
  28 
  29 //! XPath expression matching CIB node elements for cluster nodes
  30 #define PCMK__XP_MEMBER_NODE_CONFIG                                 \
  31     "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_NODES    \
  32     "/" PCMK_XE_NODE                                                \
  33     "[not(@" PCMK_XA_TYPE ") or @" PCMK_XA_TYPE "='" PCMK_VALUE_MEMBER "']"
  34 
  35 //! XPath expression matching CIB primitive meta-attribute defining a guest node
  36 #define PCMK__XP_GUEST_NODE_CONFIG \
  37     "//" PCMK_XE_CIB "//" PCMK_XE_CONFIGURATION "//" PCMK_XE_PRIMITIVE  \
  38     "//" PCMK_XE_META_ATTRIBUTES "//" PCMK_XE_NVPAIR                    \
  39     "[@" PCMK_XA_NAME "='" PCMK_META_REMOTE_NODE "']"
  40 
  41 //! XPath expression matching CIB Pacemaker Remote connection resource
  42 #define PCMK__XP_REMOTE_NODE_CONFIG                                     \
  43     "//" PCMK_XE_CIB "//" PCMK_XE_CONFIGURATION "//" PCMK_XE_PRIMITIVE  \
  44     "[@" PCMK_XA_TYPE "='" PCMK_VALUE_REMOTE "']"                       \
  45     "[@" PCMK_XA_PROVIDER "='pacemaker']"
  46 
  47 //! XPath expression matching CIB node state elements for Pacemaker Remote nodes
  48 #define PCMK__XP_REMOTE_NODE_STATUS                                 \
  49     "//" PCMK_XE_CIB "//" PCMK_XE_STATUS "//" PCMK__XE_NODE_STATE   \
  50     "[@" PCMK_XA_REMOTE_NODE "='" PCMK_VALUE_TRUE "']"
  51 
  52 /*!
  53  * \internal
  54  * \brief Get the number of nodes in an XPath object's node set
  55  *
  56  * In other words, this is the number of results from evaluating an XPath
  57  * expression.
  58  *
  59  * \param[in] xpath_obj  XPath object
  60  *
  61  * \return Number of nodes in <tt>xpath_obj->nodesetval</tt> (guaranteed
  62  *         nonnegative)
  63  */
  64 static inline int
  65 pcmk__xpath_num_results(const xmlXPathObject *xpath_obj)
     /* [previous][next][first][last][top][bottom][index][help] */
  66 {
  67     int num_results = 0;
  68 
  69     if (xpath_obj != NULL) {
  70         num_results = xmlXPathNodeSetGetLength(xpath_obj->nodesetval);
  71     }
  72 
  73     // Negative num_results doesn't make sense
  74     return QB_MAX(num_results, 0);
  75 }
  76 
  77 GString *pcmk__element_xpath(const xmlNode *xml);
  78 char *pcmk__xpath_node_id(const char *xpath, const char *node);
  79 
  80 xmlXPathObject *pcmk__xpath_search(xmlDoc *doc, const char *path);
  81 xmlNode *pcmk__xpath_result(xmlXPathObject *xpath_obj, int index);
  82 xmlNode *pcmk__xpath_match_element(xmlNode *match);
  83 void pcmk__xpath_foreach_result(xmlDoc *doc, const char *path,
  84                                 void (*fn)(xmlNode *, void *), void *user_data);
  85 xmlNode *pcmk__xpath_find_one(xmlDoc *doc, const char *path, uint8_t level);
  86 
  87 void pcmk__warn_multiple_name_matches(pcmk__output_t *out, xmlNode *search,
  88                                       const char *name);
  89 
  90 #endif  // PCMK__CRM_COMMON_XPATH_INTERNAL__H

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