/src/pacemaker/include/crm/common/xpath_internal.h
Line | Count | Source |
1 | | /* |
2 | | * Copyright 2022-2026 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__INCLUDED_CRM_COMMON_INTERNAL_H |
11 | | #error "Include <crm/common/internal.h> instead of <xpath_internal.h> directly" |
12 | | #endif |
13 | | |
14 | | #ifndef PCMK__CRM_COMMON_XPATH_INTERNAL__H |
15 | | #define PCMK__CRM_COMMON_XPATH_INTERNAL__H |
16 | | |
17 | | #include <stdint.h> // uint8_t |
18 | | |
19 | | #include <glib.h> // GString |
20 | | #include <libxml/tree.h> // xmlDoc, xmlNode |
21 | | #include <libxml/xpath.h> // xmlXPathObject, etc. |
22 | | #include <qb/qbdefs.h> // QB_MAX() |
23 | | |
24 | | #include <crm/common/options.h> // PCMK_META_*, PCMK_VALUE_* |
25 | | #include <crm/common/output_internal.h> // pcmk__output_t |
26 | | #include <crm/common/xml_names.h> // PCMK_XE_*, PCMK_XA_*, etc. |
27 | | #include <crm/common/xml_names_internal.h> // PCMK__XE_* |
28 | | |
29 | | /* |
30 | | * Internal-only wrappers for and extensions to libxml2 XPath utilities |
31 | | */ |
32 | | |
33 | | //! XPath expression matching CIB node elements for cluster nodes |
34 | | #define PCMK__XP_MEMBER_NODE_CONFIG \ |
35 | | "//" PCMK_XE_CIB "/" PCMK_XE_CONFIGURATION "/" PCMK_XE_NODES \ |
36 | | "/" PCMK_XE_NODE \ |
37 | | "[not(@" PCMK_XA_TYPE ") or @" PCMK_XA_TYPE "='" PCMK_VALUE_MEMBER "']" |
38 | | |
39 | | //! XPath expression matching CIB primitive meta-attribute defining a guest node |
40 | | #define PCMK__XP_GUEST_NODE_CONFIG \ |
41 | | "//" PCMK_XE_CIB "//" PCMK_XE_CONFIGURATION "//" PCMK_XE_PRIMITIVE \ |
42 | | "//" PCMK_XE_META_ATTRIBUTES "//" PCMK_XE_NVPAIR \ |
43 | | "[@" PCMK_XA_NAME "='" PCMK_META_REMOTE_NODE "']" |
44 | | |
45 | | //! XPath expression matching CIB Pacemaker Remote connection resource |
46 | | #define PCMK__XP_REMOTE_NODE_CONFIG \ |
47 | | "//" PCMK_XE_CIB "//" PCMK_XE_CONFIGURATION "//" PCMK_XE_PRIMITIVE \ |
48 | | "[@" PCMK_XA_TYPE "='" PCMK_VALUE_REMOTE "']" \ |
49 | | "[@" PCMK_XA_PROVIDER "='pacemaker']" |
50 | | |
51 | | //! XPath expression matching CIB node state elements for Pacemaker Remote nodes |
52 | | #define PCMK__XP_REMOTE_NODE_STATUS \ |
53 | | "//" PCMK_XE_CIB "//" PCMK_XE_STATUS "//" PCMK__XE_NODE_STATE \ |
54 | | "[@" PCMK_XA_REMOTE_NODE "='" PCMK_VALUE_TRUE "']" |
55 | | |
56 | | /*! |
57 | | * \internal |
58 | | * \brief Get the number of nodes in an XPath object's node set |
59 | | * |
60 | | * In other words, this is the number of results from evaluating an XPath |
61 | | * expression. |
62 | | * |
63 | | * \param[in] xpath_obj XPath object |
64 | | * |
65 | | * \return Number of nodes in <tt>xpath_obj->nodesetval</tt> (guaranteed |
66 | | * nonnegative) |
67 | | */ |
68 | | static inline int |
69 | | pcmk__xpath_num_results(const xmlXPathObject *xpath_obj) |
70 | 0 | { |
71 | 0 | int num_results = 0; |
72 | |
|
73 | 0 | if (xpath_obj != NULL) { |
74 | 0 | num_results = xmlXPathNodeSetGetLength(xpath_obj->nodesetval); |
75 | 0 | } |
76 | | |
77 | | // Negative num_results doesn't make sense |
78 | | return QB_MAX(num_results, 0); |
79 | 0 | } Unexecuted instantiation: scores_fuzzer.c:pcmk__xpath_num_results Unexecuted instantiation: results.c:pcmk__xpath_num_results Unexecuted instantiation: scores.c:pcmk__xpath_num_results Unexecuted instantiation: strings.c:pcmk__xpath_num_results Unexecuted instantiation: utils.c:pcmk__xpath_num_results Unexecuted instantiation: iso8601.c:pcmk__xpath_num_results Unexecuted instantiation: logging.c:pcmk__xpath_num_results Unexecuted instantiation: mainloop.c:pcmk__xpath_num_results Unexecuted instantiation: options.c:pcmk__xpath_num_results Unexecuted instantiation: output.c:pcmk__xpath_num_results Unexecuted instantiation: output_log.c:pcmk__xpath_num_results Unexecuted instantiation: output_text.c:pcmk__xpath_num_results Unexecuted instantiation: output_xml.c:pcmk__xpath_num_results Unexecuted instantiation: patchset_display.c:pcmk__xpath_num_results Unexecuted instantiation: schemas.c:pcmk__xpath_num_results Unexecuted instantiation: xml.c:pcmk__xpath_num_results Unexecuted instantiation: xml_attr.c:pcmk__xpath_num_results Unexecuted instantiation: xml_comment.c:pcmk__xpath_num_results Unexecuted instantiation: xml_display.c:pcmk__xpath_num_results Unexecuted instantiation: xml_element.c:pcmk__xpath_num_results Unexecuted instantiation: xml_idref.c:pcmk__xpath_num_results Unexecuted instantiation: xml_io.c:pcmk__xpath_num_results Unexecuted instantiation: xpath.c:pcmk__xpath_num_results Unexecuted instantiation: acl.c:pcmk__xpath_num_results Unexecuted instantiation: actions.c:pcmk__xpath_num_results Unexecuted instantiation: agents.c:pcmk__xpath_num_results Unexecuted instantiation: cmdline.c:pcmk__xpath_num_results Unexecuted instantiation: digest.c:pcmk__xpath_num_results Unexecuted instantiation: health.c:pcmk__xpath_num_results Unexecuted instantiation: io.c:pcmk__xpath_num_results Unexecuted instantiation: ipc_client.c:pcmk__xpath_num_results Unexecuted instantiation: ipc_common.c:pcmk__xpath_num_results Unexecuted instantiation: ipc_controld.c:pcmk__xpath_num_results Unexecuted instantiation: ipc_pacemakerd.c:pcmk__xpath_num_results Unexecuted instantiation: ipc_schedulerd.c:pcmk__xpath_num_results Unexecuted instantiation: ipc_server.c:pcmk__xpath_num_results Unexecuted instantiation: messages.c:pcmk__xpath_num_results Unexecuted instantiation: nodes.c:pcmk__xpath_num_results Unexecuted instantiation: nvpair.c:pcmk__xpath_num_results Unexecuted instantiation: options_display.c:pcmk__xpath_num_results Unexecuted instantiation: patchset.c:pcmk__xpath_num_results Unexecuted instantiation: procfs.c:pcmk__xpath_num_results Unexecuted instantiation: rules.c:pcmk__xpath_num_results Unexecuted instantiation: servers.c:pcmk__xpath_num_results Unexecuted instantiation: cib.c:pcmk__xpath_num_results Unexecuted instantiation: ipc_attrd.c:pcmk__xpath_num_results Unexecuted instantiation: pid.c:pcmk__xpath_num_results Unexecuted instantiation: attrs.c:pcmk__xpath_num_results Unexecuted instantiation: strings_fuzzer.c:pcmk__xpath_num_results Unexecuted instantiation: cib_file_fuzzer.c:pcmk__xpath_num_results Unexecuted instantiation: cib_client.c:pcmk__xpath_num_results Unexecuted instantiation: cib_file.c:pcmk__xpath_num_results Unexecuted instantiation: cib_native.c:pcmk__xpath_num_results Unexecuted instantiation: cib_ops.c:pcmk__xpath_num_results Unexecuted instantiation: cib_remote.c:pcmk__xpath_num_results Unexecuted instantiation: cib_utils.c:pcmk__xpath_num_results Unexecuted instantiation: remote.c:pcmk__xpath_num_results Unexecuted instantiation: tls.c:pcmk__xpath_num_results Unexecuted instantiation: watchdog.c:pcmk__xpath_num_results Unexecuted instantiation: iso8601_fuzzer.c:pcmk__xpath_num_results |
80 | | |
81 | | GString *pcmk__element_xpath(const xmlNode *xml); |
82 | | char *pcmk__xpath_node_id(const char *xpath, const char *node); |
83 | | |
84 | | xmlXPathObject *pcmk__xpath_search(xmlDoc *doc, const char *path); |
85 | | xmlNode *pcmk__xpath_result(xmlXPathObject *xpath_obj, int index); |
86 | | xmlNode *pcmk__xpath_match_element(xmlNode *match); |
87 | | void pcmk__xpath_foreach_result(xmlDoc *doc, const char *path, |
88 | | void (*fn)(xmlNode *, void *), void *user_data); |
89 | | xmlNode *pcmk__xpath_find_one(xmlDoc *doc, const char *path, uint8_t level); |
90 | | |
91 | | void pcmk__warn_multiple_name_matches(pcmk__output_t *out, xmlNode *search, |
92 | | const char *name); |
93 | | |
94 | | #endif // PCMK__CRM_COMMON_XPATH_INTERNAL__H |