This source file includes following definitions.
- pcmk_cib_xpath_for
- pcmk__cib_abs_xpath_for
- pcmk_cib_parent_name_for
- pcmk_find_cib_element
1
2
3
4
5
6
7
8
9
10
11 #include <crm_internal.h>
12
13 #include <stdio.h>
14 #include <libxml/tree.h>
15
16 #include <crm/msg_xml.h>
17 #include <crm/common/cib.h>
18 #include <crm/common/cib_internal.h>
19
20
21
22
23
24
25 static struct {
26 const char *name;
27 const char *parent;
28 const char *path;
29 } cib_sections[] = {
30 {
31
32 XML_TAG_CIB,
33 NULL,
34 "//" XML_TAG_CIB
35 },
36 {
37 XML_CIB_TAG_STATUS,
38 "/" XML_TAG_CIB,
39 "//" XML_TAG_CIB "/" XML_CIB_TAG_STATUS
40 },
41 {
42 XML_CIB_TAG_CONFIGURATION,
43 "/" XML_TAG_CIB,
44 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION
45 },
46 {
47 XML_CIB_TAG_CRMCONFIG,
48 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
49 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_CRMCONFIG
50 },
51 {
52 XML_CIB_TAG_NODES,
53 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
54 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES
55 },
56 {
57 XML_CIB_TAG_RESOURCES,
58 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
59 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RESOURCES
60 },
61 {
62 XML_CIB_TAG_CONSTRAINTS,
63 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
64 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_CONSTRAINTS
65 },
66 {
67 XML_CIB_TAG_OPCONFIG,
68 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
69 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_OPCONFIG
70 },
71 {
72 XML_CIB_TAG_RSCCONFIG,
73 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
74 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_RSCCONFIG
75 },
76 {
77 XML_CIB_TAG_ACLS,
78 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
79 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_ACLS
80 },
81 {
82 XML_TAG_FENCING_TOPOLOGY,
83 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
84 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_TAG_FENCING_TOPOLOGY
85 },
86 {
87 XML_CIB_TAG_TAGS,
88 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
89 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_TAGS
90 },
91 {
92 XML_CIB_TAG_ALERTS,
93 "/" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION,
94 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_ALERTS
95 },
96 {
97 XML_CIB_TAG_SECTION_ALL,
98 NULL,
99 "//" XML_TAG_CIB
100 },
101 };
102
103
104
105
106
107
108
109
110
111 const char *
112 pcmk_cib_xpath_for(const char *element_name)
113 {
114 for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
115
116 if (pcmk__str_eq(element_name, cib_sections[lpc].name,
117 pcmk__str_null_matches)) {
118 return cib_sections[lpc].path;
119 }
120 }
121 return NULL;
122 }
123
124
125
126
127
128
129
130
131
132 const char *
133 pcmk__cib_abs_xpath_for(const char *element)
134 {
135 const char *xpath = pcmk_cib_xpath_for(element);
136
137
138 return ((xpath != NULL)? (xpath + 1) : NULL);
139 }
140
141
142
143
144
145
146
147
148
149 const char *
150 pcmk_cib_parent_name_for(const char *element_name)
151 {
152 for (int lpc = 0; lpc < PCMK__NELEM(cib_sections); lpc++) {
153
154 if (pcmk__str_eq(element_name, cib_sections[lpc].name,
155 pcmk__str_null_matches)) {
156 return cib_sections[lpc].parent;
157 }
158 }
159 return NULL;
160 }
161
162
163
164
165
166
167
168
169
170
171 xmlNode *
172 pcmk_find_cib_element(xmlNode *cib, const char *element_name)
173 {
174 return get_xpath_object(pcmk_cib_xpath_for(element_name), cib, LOG_TRACE);
175 }