This source file includes following definitions.
- pcmk__xml_first_child
- pcmk__xml_next
- pcmk__xe_first_child
- pcmk__xe_next
- pcmk__xe_set_props
1
2
3
4
5
6
7
8
9
10 #ifndef PCMK__XML_INTERNAL__H
11 # define PCMK__XML_INTERNAL__H
12
13
14
15
16
17 # include <stdlib.h>
18 # include <stdio.h>
19 # include <string.h>
20
21 # include <crm/crm.h>
22 # include <crm/common/output_internal.h>
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 #define PCMK__XML_LOG_BASE(priority, dechunk, postemit, prefix, fmt, ap) \
69 do { \
70 if (!(dechunk) && (prefix) == NULL) { \
71 qb_log_from_external_source_va(__func__, __FILE__, (fmt), \
72 (priority), __LINE__, 0, (ap)); \
73 (void) (postemit); \
74 } else { \
75 int CXLB_len = 0; \
76 char *CXLB_buf = NULL; \
77 static int CXLB_buffer_len = 0; \
78 static char *CXLB_buffer = NULL; \
79 static uint8_t CXLB_priority = 0; \
80 \
81 CXLB_len = vasprintf(&CXLB_buf, (fmt), (ap)); \
82 \
83 if (CXLB_len <= 0 || CXLB_buf[CXLB_len - 1] == '\n' || !(dechunk)) { \
84 if (CXLB_len < 0) { \
85 CXLB_buf = (char *) "LOG CORRUPTION HAZARD"; \
86 CXLB_priority = QB_MIN(CXLB_priority, LOG_ERR); \
87 } else if (CXLB_len > 0 \
88 && CXLB_buf[CXLB_len - 1] == '\n') { \
89 CXLB_buf[CXLB_len - 1] = '\0'; \
90 } \
91 if (CXLB_buffer) { \
92 qb_log_from_external_source(__func__, __FILE__, "%s%s%s", \
93 CXLB_priority, __LINE__, 0, \
94 (prefix) != NULL ? (prefix) : "", \
95 CXLB_buffer, CXLB_buf); \
96 free(CXLB_buffer); \
97 } else { \
98 qb_log_from_external_source(__func__, __FILE__, "%s%s", \
99 (priority), __LINE__, 0, \
100 (prefix) != NULL ? (prefix) : "", \
101 CXLB_buf); \
102 } \
103 if (CXLB_len < 0) { \
104 CXLB_buf = NULL; \
105 } \
106 CXLB_buffer = NULL; \
107 CXLB_buffer_len = 0; \
108 (void) (postemit); \
109 \
110 } else if (CXLB_buffer == NULL) { \
111 CXLB_buffer_len = CXLB_len; \
112 CXLB_buffer = CXLB_buf; \
113 CXLB_buf = NULL; \
114 CXLB_priority = (priority); \
115 \
116 } else { \
117 CXLB_buffer = realloc(CXLB_buffer, 1 + CXLB_buffer_len + CXLB_len); \
118 memcpy(CXLB_buffer + CXLB_buffer_len, CXLB_buf, CXLB_len); \
119 CXLB_buffer_len += CXLB_len; \
120 CXLB_buffer[CXLB_buffer_len] = '\0'; \
121 CXLB_priority = QB_MIN(CXLB_priority, (priority)); \
122 } \
123 free(CXLB_buf); \
124 } \
125 } while (0)
126
127
128
129
130
131 enum pcmk__xml_fmt_options {
132
133 pcmk__xml_fmt_filtered = (1 << 0),
134
135
136 pcmk__xml_fmt_pretty = (1 << 1),
137
138
139 pcmk__xml_fmt_full = (1 << 2),
140
141
142 pcmk__xml_fmt_open = (1 << 3),
143
144
145 pcmk__xml_fmt_children = (1 << 4),
146
147
148 pcmk__xml_fmt_close = (1 << 5),
149
150
151
152 pcmk__xml_fmt_text = (1 << 6),
153
154
155
156 pcmk__xml_fmt_diff_plus = (1 << 7),
157
158
159
160 pcmk__xml_fmt_diff_minus = (1 << 8),
161
162
163
164 pcmk__xml_fmt_diff_short = (1 << 9),
165 };
166
167 int pcmk__xml_show(pcmk__output_t *out, const char *prefix, const xmlNode *data,
168 int depth, uint32_t options);
169 int pcmk__xml_show_changes(pcmk__output_t *out, const xmlNode *xml);
170
171
172
173
174 #define PCMK__XP_MEMBER_NODE_CONFIG \
175 "//" XML_TAG_CIB "/" XML_CIB_TAG_CONFIGURATION "/" XML_CIB_TAG_NODES \
176 "/" XML_CIB_TAG_NODE "[not(@type) or @type='member']"
177
178
179 #define PCMK__XP_GUEST_NODE_CONFIG \
180 "//" XML_TAG_CIB "//" XML_CIB_TAG_CONFIGURATION "//" XML_CIB_TAG_RESOURCE \
181 "//" XML_TAG_META_SETS "//" XML_CIB_TAG_NVPAIR \
182 "[@name='" XML_RSC_ATTR_REMOTE_NODE "']"
183
184
185 #define PCMK__XP_REMOTE_NODE_CONFIG \
186 "//" XML_TAG_CIB "//" XML_CIB_TAG_CONFIGURATION "//" XML_CIB_TAG_RESOURCE \
187 "[@type='remote'][@provider='pacemaker']"
188
189
190 #define PCMK__XP_REMOTE_NODE_STATUS \
191 "//" XML_TAG_CIB "//" XML_CIB_TAG_STATUS "//" XML_CIB_TAG_STATE \
192 "[@" XML_NODE_IS_REMOTE "='true']"
193
194 enum pcmk__xml_artefact_ns {
195 pcmk__xml_artefact_ns_legacy_rng = 1,
196 pcmk__xml_artefact_ns_legacy_xslt,
197 pcmk__xml_artefact_ns_base_rng,
198 pcmk__xml_artefact_ns_base_xslt,
199 };
200
201 void pcmk__strip_xml_text(xmlNode *xml);
202 const char *pcmk__xe_add_last_written(xmlNode *xe);
203
204 xmlNode *pcmk__xe_match(const xmlNode *parent, const char *node_name,
205 const char *attr_n, const char *attr_v);
206
207 void pcmk__xe_remove_matching_attrs(xmlNode *element,
208 bool (*match)(xmlAttrPtr, void *),
209 void *user_data);
210
211 GString *pcmk__element_xpath(const xmlNode *xml);
212
213
214
215
216
217
218
219
220
221 char *
222 pcmk__xml_artefact_root(enum pcmk__xml_artefact_ns ns);
223
224
225
226
227
228
229
230
231
232
233 char *pcmk__xml_artefact_path(enum pcmk__xml_artefact_ns ns,
234 const char *filespec);
235
236
237
238
239
240
241
242
243
244 static inline xmlNode *
245 pcmk__xml_first_child(const xmlNode *parent)
246 {
247 xmlNode *child = (parent? parent->children : NULL);
248
249 while (child && (child->type == XML_TEXT_NODE)) {
250 child = child->next;
251 }
252 return child;
253 }
254
255
256
257
258
259
260
261
262
263 static inline xmlNode *
264 pcmk__xml_next(const xmlNode *child)
265 {
266 xmlNode *next = (child? child->next : NULL);
267
268 while (next && (next->type == XML_TEXT_NODE)) {
269 next = next->next;
270 }
271 return next;
272 }
273
274
275
276
277
278
279
280
281
282 static inline xmlNode *
283 pcmk__xe_first_child(const xmlNode *parent)
284 {
285 xmlNode *child = (parent? parent->children : NULL);
286
287 while (child && (child->type != XML_ELEMENT_NODE)) {
288 child = child->next;
289 }
290 return child;
291 }
292
293
294
295
296
297
298
299
300
301 static inline xmlNode *
302 pcmk__xe_next(const xmlNode *child)
303 {
304 xmlNode *next = child? child->next : NULL;
305
306 while (next && (next->type != XML_ELEMENT_NODE)) {
307 next = next->next;
308 }
309 return next;
310 }
311
312
313
314
315
316
317
318
319
320 void
321 pcmk__xe_set_propv(xmlNodePtr node, va_list pairs);
322
323
324
325
326
327
328
329
330
331
332
333 void
334 pcmk__xe_set_props(xmlNodePtr node, ...)
335 G_GNUC_NULL_TERMINATED;
336
337
338
339
340
341
342
343
344
345 static inline xmlAttr *
346 pcmk__xe_first_attr(const xmlNode *xe)
347 {
348 return (xe == NULL)? NULL : xe->properties;
349 }
350
351
352
353
354
355
356
357
358
359
360 char *
361 pcmk__xpath_node_id(const char *xpath, const char *node);
362
363
364
365 enum xml_private_flags {
366 pcmk__xf_none = 0x0000,
367 pcmk__xf_dirty = 0x0001,
368 pcmk__xf_deleted = 0x0002,
369 pcmk__xf_created = 0x0004,
370 pcmk__xf_modified = 0x0008,
371
372 pcmk__xf_tracking = 0x0010,
373 pcmk__xf_processed = 0x0020,
374 pcmk__xf_skip = 0x0040,
375 pcmk__xf_moved = 0x0080,
376
377 pcmk__xf_acl_enabled = 0x0100,
378 pcmk__xf_acl_read = 0x0200,
379 pcmk__xf_acl_write = 0x0400,
380 pcmk__xf_acl_deny = 0x0800,
381
382 pcmk__xf_acl_create = 0x1000,
383 pcmk__xf_acl_denied = 0x2000,
384 pcmk__xf_lazy = 0x4000,
385 };
386
387 void pcmk__set_xml_doc_flag(xmlNode *xml, enum xml_private_flags flag);
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409 int
410 pcmk__xe_foreach_child(xmlNode *xml, const char *child_element_name,
411 int (*handler)(xmlNode *xml, void *userdata),
412 void *userdata);
413
414 #endif