summaryrefslogtreecommitdiffstats
path: root/linhes/zabbix/fix-build-with-libxml2.patch
blob: c4716f098531e35b498a7a4579d062aadd4f30e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
diff --git a/ChangeLog.d/bugfix/ZBX-23738 b/ChangeLog.d/bugfix/ZBX-23738
new file mode 100644
index 0000000..f7c7dd5
--- /dev/null
+++ b/ChangeLog.d/bugfix/ZBX-23738
@@ -0,0 +1 @@
+.......PS. [ZBX-23738] fixed Zabbix backend sources for libxml2 2.12.0 version changes (akozlovs)
diff --git a/m4/libxml2.m4 b/m4/libxml2.m4
index b0a3c77..282d3b6 100644
--- a/m4/libxml2.m4
+++ b/m4/libxml2.m4
@@ -30,10 +30,13 @@ AS_HELP_STRING([--with-libxml2@<:@=ARG@:>@],
         [
         if test "$withval" = "no"; then
             want_libxml2="no"
+            _libxml2_with="no"
         elif test "$withval" = "yes"; then
             want_libxml2="yes"
+            _libxml2_with="yes"
         else
             want_libxml2="yes"
+            _libxml2_with=$withval
         fi
         ],
         [want_libxml2="no"]
@@ -49,27 +52,43 @@ AS_HELP_STRING([--with-libxml2@<:@=ARG@:>@],
     dnl
 
     if test "$want_libxml2" = "yes"; then
-        AC_REQUIRE([PKG_PROG_PKG_CONFIG])
-        m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG()], [:])
+        if test "$_libxml2_with" != "yes"; then
+            XML2_INCDIR=$_libxml2_with/include
+            XML2_LIBDIR=$_libxml2_with/lib
+            LIBXML2_CFLAGS="-I$XML2_INCDIR"
+            LIBXML2_LDFLAGS="-L$XML2_LIBDIR"
+            _full_libxml2_libs=$LIBXML2_LDFLAGS
+            configured_libxml2="yes"
+        else
+            AC_REQUIRE([PKG_PROG_PKG_CONFIG])
+            m4_ifdef([PKG_PROG_PKG_CONFIG], [PKG_PROG_PKG_CONFIG()], [:])
+
+            if test -x "$PKG_CONFIG"; then
 
-        if test -x "$PKG_CONFIG"; then
+                LIBXML2_CFLAGS="`$PKG_CONFIG --cflags libxml-2.0`"
 
-            LIBXML2_CFLAGS="`$PKG_CONFIG --cflags libxml-2.0`"
+                _full_libxml2_libs="`$PKG_CONFIG --libs libxml-2.0`"
+
+                for i in $_full_libxml2_libs; do
+                    case $i in
+                       -lxml2)
+                            ;;
+                       -L*)
+                            LIBXML2_LDFLAGS="${LIBXML2_LDFLAGS} $i"
+                            ;;
+                       -R*)
+                            LIBXML2_LDFLAGS="${LIBXML2_LDFLAGS} -Wl,$i"
+                            ;;
+                    esac
+                done
 
-            _full_libxml2_libs="`$PKG_CONFIG --libs libxml-2.0`"
+                configured_libxml2="yes"
+            else
+                configured_libxml2="no"
+            fi
+        fi
 
-            for i in $_full_libxml2_libs; do
-                case $i in
-                   -lxml2)
-                        ;;
-                   -L*)
-                        LIBXML2_LDFLAGS="${LIBXML2_LDFLAGS} $i"
-                        ;;
-                   -R*)
-                        LIBXML2_LDFLAGS="${LIBXML2_LDFLAGS} -Wl,$i"
-                        ;;
-                esac
-            done
+        if test "$configured_libxml2" = "yes"; then
 
             if test "x$enable_static" = "xyes"; then
                 for i in $_full_libxml2_libs; do
@@ -88,6 +107,20 @@ AS_HELP_STRING([--with-libxml2@<:@=ARG@:>@],
                 done
             fi
 
+            if test "$_libxml2_with" != "yes"; then
+                if test -f $_libxml2_with/include/libxml2/libxml/xmlversion.h; then
+                    LIBXML2_VERSION=`cat $_libxml2_with/include/libxml2/libxml/xmlversion.h \
+                                  | grep '#define.*LIBXML_DOTTED_VERSION.*' \
+                                  | sed -e 's/#define LIBXML_DOTTED_VERSION  *//' \
+                                  | sed -e 's/  *\/\*.*\*\///' \
+                                  | sed -e 's/\"//g'`
+                else
+                    AC_MSG_ERROR([Not found libxml2 library])
+                fi
+            else
+                LIBXML2_VERSION=`$PKG_CONFIG --version libxml-2.0`
+            fi
+
             _save_libxml2_libs="${LIBS}"
             _save_libxml2_ldflags="${LDFLAGS}"
             _save_libxml2_cflags="${CFLAGS}"
@@ -96,7 +129,7 @@ AS_HELP_STRING([--with-libxml2@<:@=ARG@:>@],
             CFLAGS="${CFLAGS} ${LIBXML2_CFLAGS}"
 
             AC_CHECK_LIB(xml2, xmlReadMemory, [
-                    LIBXML2_LIBS="-lxml2 ${LIBXML2_LIBS}"
+                    LIBXML2_LIBS="${LIBXML2_LIBS} -lxml2"
                     ],[
                     AC_MSG_ERROR([Not found libxml2 library])
                     ])
@@ -108,8 +141,6 @@ AS_HELP_STRING([--with-libxml2@<:@=ARG@:>@],
             unset _save_libxml2_ldflags
             unset _save_libxml2_cflags
 
-            LIBXML2_VERSION=`$PKG_CONFIG --version libxml-2.0`
-
             AC_DEFINE([HAVE_LIBXML2], [1], [Define to 1 if libxml2 libraries are available])
 
             found_libxml2="yes"
diff --git a/src/libs/zbxpreproc/item_preproc.c b/src/libs/zbxpreproc/item_preproc.c
index 88f94c6..8921b2d 100644
--- a/src/libs/zbxpreproc/item_preproc.c
+++ b/src/libs/zbxpreproc/item_preproc.c
@@ -27,6 +27,7 @@
 #include "zbxxml.h"
 #ifdef HAVE_LIBXML2
 #	include <libxml/xpath.h>
+#	include <libxml/parser.h>
 #endif
 
 #include "zbxnum.h"
@@ -896,7 +897,7 @@ int	item_preproc_get_error_from_xml(const zbx_variant_t *value, const char *para
 	xmlDoc			*doc = NULL;
 	xmlXPathContext		*xpathCtx = NULL;
 	xmlXPathObject		*xpathObj = NULL;
-	xmlErrorPtr		pErr;
+	const xmlError		*pErr;
 	xmlBufferPtr		xmlBufferLocal;
 
 	zbx_variant_copy(&value_str, value);
diff --git a/src/libs/zbxpreproc/pp_manager.c b/src/libs/zbxpreproc/pp_manager.c
index 9959a9f..a39f95d 100644
--- a/src/libs/zbxpreproc/pp_manager.c
+++ b/src/libs/zbxpreproc/pp_manager.c
@@ -34,6 +34,7 @@
 
 #ifdef HAVE_LIBXML2
 #	include <libxml/xpath.h>
+#	include <libxml/parser.h>
 #endif
 
 #define PP_STARTUP_TIMEOUT	10
diff --git a/src/libs/zbxxml/xml.c b/src/libs/zbxxml/xml.c
index 00eadce..7763be8 100644
--- a/src/libs/zbxxml/xml.c
+++ b/src/libs/zbxxml/xml.c
@@ -27,6 +27,7 @@
 
 #ifdef HAVE_LIBXML2
 #	include <libxml/xpath.h>
+#	include <libxml/parser.h>
 #endif
 
 typedef struct _zbx_xml_node_t zbx_xml_node_t;
@@ -282,7 +283,7 @@ int	zbx_query_xpath(zbx_variant_t *value, const char *params, char **errmsg)
 	xmlXPathContext	*xpathCtx;
 	xmlXPathObject	*xpathObj;
 	xmlNodeSetPtr	nodeset;
-	xmlErrorPtr	pErr;
+	const xmlError	*pErr;
 	xmlBufferPtr	xmlBufferLocal;
 
 	if (NULL == (doc = xmlReadMemory(value->data.str, strlen(value->data.str), "noname.xml", NULL, 0)))
@@ -638,7 +639,7 @@ static void	vector_to_json(zbx_vector_xml_node_ptr_t *nodes, struct zbx_json *js
  ******************************************************************************/
 int	zbx_open_xml(char *data, int options, int maxerrlen, void **xml_doc, void **root_node, char **errmsg)
 {
-	xmlErrorPtr	pErr;
+	const xmlError	*pErr;
 
 	if (NULL == (*xml_doc = xmlReadMemory(data, strlen(data), "noname.xml", NULL, options)))
 	{
@@ -694,7 +695,7 @@ int	zbx_open_xml(char *data, int options, int maxerrlen, void **xml_doc, void **
  ******************************************************************************/
 int	zbx_check_xml_memory(char *mem, int maxerrlen, char **errmsg)
 {
-	xmlErrorPtr	pErr;
+	const xmlError	*pErr;
 
 	if (NULL == mem)
 	{
@@ -949,7 +950,7 @@ int	zbx_json_to_xml(char *json_data, char **xstr, char **errmsg)
 	int			size, ret = FAIL;
 	struct zbx_json_parse	jp;
 	xmlDoc			*doc = NULL;
-	xmlErrorPtr		pErr;
+	const xmlError		*pErr;
 	xmlChar			*xmem;
 
 	if (NULL == (doc = xmlNewDoc(BAD_CAST XML_DEFAULT_VERSION)))
@@ -1005,7 +1006,11 @@ zbx_libxml_error_t;
  *             err       - [IN] the libxml2 error message                     *
  *                                                                            *
  ******************************************************************************/
+#if 21200 > LIBXML_VERSION /* version 2.12.0 */
 static void	libxml_handle_error_xpath_check(void *user_data, xmlErrorPtr err)
+#else
+static void	libxml_handle_error_xpath_check(void *user_data, const xmlError *err)
+#endif
 {
 	zbx_libxml_error_t	*err_ctx;
 
@@ -1155,7 +1160,11 @@ out:
  *             err       - [IN] the libxml2 error message                     *
  *                                                                            *
  ******************************************************************************/
+#if 21200 > LIBXML_VERSION /* version 2.12.0 */
 static void	libxml_handle_error_try_read_value(void *user_data, xmlErrorPtr err)
+#else
+static void	libxml_handle_error_try_read_value(void *user_data, const xmlError *err)
+#endif
 {
 	ZBX_UNUSED(user_data);
 	ZBX_UNUSED(err);