pacemaker  2.0.5-ba59be712
Scalable High-Availability cluster resource manager
xml_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017-2020 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__XML_INTERNAL__H
11 # define PCMK__XML_INTERNAL__H
12 
13 /*
14  * Internal-only wrappers for and extensions to libxml2 (libxslt)
15  */
16 
17 # include <stdlib.h>
18 # include <stdio.h>
19 # include <string.h>
20 
21 # include <crm/crm.h> /* transitively imports qblog.h */
22 
23 
67 #define PCMK__XML_LOG_BASE(priority, dechunk, postemit, prefix, fmt, ap) \
68 do { \
69  if (!(dechunk) && (prefix) == NULL) { /* quick pass */ \
70  qb_log_from_external_source_va(__func__, __FILE__, (fmt), \
71  (priority), __LINE__, 0, (ap)); \
72  (void) (postemit); \
73  } else { \
74  int CXLB_len = 0; \
75  char *CXLB_buf = NULL; \
76  static int CXLB_buffer_len = 0; \
77  static char *CXLB_buffer = NULL; \
78  static uint8_t CXLB_priority = 0; \
79  \
80  CXLB_len = vasprintf(&CXLB_buf, (fmt), (ap)); \
81  \
82  if (CXLB_len <= 0 || CXLB_buf[CXLB_len - 1] == '\n' || !(dechunk)) { \
83  if (CXLB_len < 0) { \
84  CXLB_buf = (char *) "LOG CORRUPTION HAZARD"; /*we don't modify*/\
85  CXLB_priority = QB_MIN(CXLB_priority, LOG_ERR); \
86  } else if (CXLB_len > 0 /* && (dechunk) */ \
87  && CXLB_buf[CXLB_len - 1] == '\n') { \
88  CXLB_buf[CXLB_len - 1] = '\0'; \
89  } \
90  if (CXLB_buffer) { \
91  qb_log_from_external_source(__func__, __FILE__, "%s%s%s", \
92  CXLB_priority, __LINE__, 0, \
93  (prefix) != NULL ? (prefix) : "", \
94  CXLB_buffer, CXLB_buf); \
95  free(CXLB_buffer); \
96  } else { \
97  qb_log_from_external_source(__func__, __FILE__, "%s%s", \
98  (priority), __LINE__, 0, \
99  (prefix) != NULL ? (prefix) : "", \
100  CXLB_buf); \
101  } \
102  if (CXLB_len < 0) { \
103  CXLB_buf = NULL; /* restore temporary override */ \
104  } \
105  CXLB_buffer = NULL; \
106  CXLB_buffer_len = 0; \
107  (void) (postemit); \
108  \
109  } else if (CXLB_buffer == NULL) { \
110  CXLB_buffer_len = CXLB_len; \
111  CXLB_buffer = CXLB_buf; \
112  CXLB_buf = NULL; \
113  CXLB_priority = (priority); /* remember as a running severest */ \
114  \
115  } else { \
116  CXLB_buffer = realloc(CXLB_buffer, 1 + CXLB_buffer_len + CXLB_len); \
117  memcpy(CXLB_buffer + CXLB_buffer_len, CXLB_buf, CXLB_len); \
118  CXLB_buffer_len += CXLB_len; \
119  CXLB_buffer[CXLB_buffer_len] = '\0'; \
120  CXLB_priority = QB_MIN(CXLB_priority, (priority)); /* severest? */ \
121  } \
122  free(CXLB_buf); \
123  } \
124 } while (0)
125 
131 };
132 
133 void pcmk__strip_xml_text(xmlNode *xml);
134 const char *pcmk__xe_add_last_written(xmlNode *xe);
135 
136 xmlNode *pcmk__xe_match(xmlNode *parent, const char *node_name,
137  const char *attr_n, const char *attr_v);
138 
147 char *
149 
160  const char *filespec);
161 
170 static inline xmlNode *
171 pcmk__xml_first_child(const xmlNode *parent)
172 {
173  xmlNode *child = (parent? parent->children : NULL);
174 
175  while (child && (child->type == XML_TEXT_NODE)) {
176  child = child->next;
177  }
178  return child;
179 }
180 
189 static inline xmlNode *
190 pcmk__xml_next(const xmlNode *child)
191 {
192  xmlNode *next = (child? child->next : NULL);
193 
194  while (next && (next->type == XML_TEXT_NODE)) {
195  next = next->next;
196  }
197  return next;
198 }
199 
208 static inline xmlNode *
209 pcmk__xe_first_child(const xmlNode *parent)
210 {
211  xmlNode *child = (parent? parent->children : NULL);
212 
213  while (child && (child->type != XML_ELEMENT_NODE)) {
214  child = child->next;
215  }
216  return child;
217 }
218 
227 static inline xmlNode *
228 pcmk__xe_next(const xmlNode *child)
229 {
230  xmlNode *next = child? child->next : NULL;
231 
232  while (next && (next->type != XML_ELEMENT_NODE)) {
233  next = next->next;
234  }
235  return next;
236 }
237 
238 #endif // PCMK__XML_INTERNAL__H
char * pcmk__xml_artefact_root(enum pcmk__xml_artefact_ns ns)
Definition: xml.c:2889
A dumping ground.
const char * pcmk__xe_add_last_written(xmlNode *xe)
Definition: xml.c:1088
xmlNode * pcmk__xe_match(xmlNode *parent, const char *node_name, const char *attr_n, const char *attr_v)
Definition: xml.c:497
void pcmk__strip_xml_text(xmlNode *xml)
Definition: xml.c:990
pcmk__xml_artefact_ns
Definition: xml_internal.h:126
char * pcmk__xml_artefact_path(enum pcmk__xml_artefact_ns ns, const char *filespec)
Definition: xml.c:2917