pacemaker  1.1.18-7fdfbbe
Scalable High-Availability cluster resource manager
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
xml_internal.h
Go to the documentation of this file.
1 /*
2  * Copyright 2017 Jan Pokorny <jpokorny@redhat.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2 of the License, or (at your option) any later version.
8  *
9  * This software is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17  */
18 #ifndef CRM_COMMON_XML_INTERNAL__H
19 # define CRM_COMMON_XML_INTERNAL__H
20 
21 /*
22  * Internal-only wrappers for and extensions to libxml2 (libxslt)
23  */
24 
25 # include <stdlib.h>
26 # include <stdio.h>
27 # include <string.h>
28 
29 # include <crm/crm.h> /* transitively imports qblog.h */
30 
31 
67 #define CRM_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(__FUNCTION__, __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  \
79  CXLB_len = vasprintf(&CXLB_buf, (fmt), (ap)); \
80  \
81  if (CXLB_len <= 0 || CXLB_buf[CXLB_len - 1] == '\n' || !(dechunk)) { \
82  if (CXLB_len < 0) { \
83  CXLB_buf = (char *) "LOG CORRUPTION HAZARD"; /*we don't modify*/\
84  } else if (CXLB_len > 0 /* && (dechunk) */ \
85  && CXLB_buf[CXLB_len - 1] == '\n') { \
86  CXLB_buf[CXLB_len - 1] = '\0'; \
87  } \
88  if (CXLB_buffer) { \
89  qb_log_from_external_source(__FUNCTION__, __FILE__, "%s%s%s", \
90  (priority), __LINE__, 0, \
91  (prefix) != NULL ? (prefix) : "", \
92  CXLB_buffer, CXLB_buf); \
93  free(CXLB_buffer); \
94  } else { \
95  qb_log_from_external_source(__FUNCTION__, __FILE__, "%s%s", \
96  (priority), __LINE__, 0, \
97  (prefix) != NULL ? (prefix) : "", \
98  CXLB_buf); \
99  } \
100  if (CXLB_len < 0) { \
101  CXLB_buf = NULL; /* restore temporary override */ \
102  } \
103  CXLB_buffer = NULL; \
104  CXLB_buffer_len = 0; \
105  (void) (postemit); \
106  \
107  } else if (CXLB_buffer == NULL) { \
108  CXLB_buffer_len = CXLB_len; \
109  CXLB_buffer = CXLB_buf; \
110  CXLB_buf = NULL; \
111  \
112  } else { \
113  CXLB_buffer = realloc(CXLB_buffer, 1 + CXLB_buffer_len + CXLB_len); \
114  memcpy(CXLB_buffer + CXLB_buffer_len, CXLB_buf, CXLB_len); \
115  CXLB_buffer_len += CXLB_len; \
116  CXLB_buffer[CXLB_buffer_len] = '\0'; \
117  } \
118  free(CXLB_buf); \
119  } \
120 } while (0)
121 
122 #endif
A dumping ground.