summaryrefslogtreecommitdiff
path: root/openembedded/packages/libglade/libglade-2.5.1/no-xml2.patch
blob: 1c2e215b8dc7be01236e6a79a1d8787db7ae48e1 (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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
diff -urN libglade-2.4.2.orig/configure.in libglade-2.4.2/configure.in
--- libglade-2.4.2.orig/configure.in	2005-02-11 12:42:58.000000000 +0100
+++ libglade-2.4.2/configure.in	2005-03-22 01:22:00.000000000 +0100
@@ -52,11 +52,33 @@
 AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
 
 PKG_CHECK_MODULES(LIBGLADE, [dnl
-  libxml-2.0 >= required_libxml_version dnl
   atk >= required_atk_version dnl
   gtk+-2.0 >= required_gtk_version dnl
   glib-2.0 >= required_glib_version])
 
+disable_xml2=no
+AC_ARG_WITH([libxml2],
+  AC_HELP_STRING([--without-libxml2], [Don't use libxml2, use Glib's GMarkupParser instead]),
+  [disable_xml2=yes],
+  [disable_xml2=no])
+
+AC_MSG_CHECKING([if we are using libxml2])
+if test "x$disable_xml2" == "xno"; then
+  AC_MSG_RESULT(yes)
+  PKG_CHECK_MODULES(XML2, libxml-2.0 >= 2.4.10)
+  PKGCFG_REQUIRE_LIBXML2="libxml-2.0"
+  LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS $XML2_CFLAGS"
+  LIBGLADE_LIBS="$LIBGLADE_LIBS $XML2_LIBS"
+else
+  LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS -DUSE_GMARKUP_PARSER"
+  PKGCFG_REQUIRE_LIBXML2=""
+  AC_MSG_RESULT(no)
+fi
+
+AC_SUBST(XML2_LIBS)
+AC_SUBST(XML2_CFLAGS)
+AC_SUBST(PKGCFG_REQUIRE_LIBXML2)
+
 AC_MSG_CHECKING([for native Win32])
 case "$host" in
   *-*-mingw*)
@@ -116,6 +138,21 @@
   fi
 fi
 
+if test "x$disable_xml2" == "xyes"; then
+  echo "*****************************************************"
+  echo "  You chose to disable libxml2 and use Glib's"
+  echo "  GMarkupParser instead." 
+  echo  
+  echo "  Please bear in mind that using libglade with"
+  echo "  GMarkupParser is an experimental feature only."
+  echo
+  echo "  Please post problems or success stories to"
+  echo "  the glade-devel mailing list. Thank you."
+  echo "*****************************************************"
+fi
+
+
+
 GTK_DOC_CHECK(1.0)
 
 dnl gettext stuff ... there is no message catalog for libglade -- libglade
diff -urN libglade-2.4.2.orig/glade/glade-parser.c libglade-2.4.2/glade/glade-parser.c
--- libglade-2.4.2.orig/glade/glade-parser.c	2004-11-11 11:56:13.000000000 +0100
+++ libglade-2.4.2/glade/glade-parser.c	2005-03-22 01:20:00.000000000 +0100
@@ -34,7 +34,15 @@
 #  define dgettext(Domain, String) (String)
 #endif
 
-#include <libxml/parser.h>
+#ifdef USE_GMARKUP_PARSER
+#  include <zlib.h>
+#else
+#  include <libxml/parser.h>
+#endif
+
+#ifdef USE_GMARKUP_PARSER
+#  define xmlChar gchar
+#endif
 
 #include "glade-parser.h"
 #include "glade-private.h"
@@ -508,7 +516,9 @@
     case PARSER_START:
 	if (!strcmp(name, "glade-interface")) {
 	    state->state = PARSER_GLADE_INTERFACE;
-#if 0
+
+#ifndef USE_GMARKUP_PARSER
+ #if 0
 	    /* check for correct XML namespace */
 	    for (i = 0; attrs && attrs[i] != NULL; i += 2) {
 		if (!strcmp(attrs[i], "xmlns") &&
@@ -518,7 +528,9 @@
 		    g_warning("unknown attribute `%s' for <glade-interface>",
 			      attrs[i]);
 	    }
+ #endif
 #endif
+
 	} else {
 	    g_warning("Expected <glade-interface>.  Got <%s>.", name);
 	    state->prev_state = state->state;
@@ -1063,12 +1075,18 @@
     }
 }
 
+#ifndef USE_GMARKUP_PARSER
+
 static xmlEntityPtr
 glade_parser_get_entity(GladeParseState *state, const xmlChar *name)
 {
     return xmlGetPredefinedEntity(name);
 }
 
+#endif /* !defined(USE_GMARKUP_PARSER) */
+
+#ifndef USE_GMARKUP_PARSER
+
 static void
 glade_parser_warning(GladeParseState *state, const char *msg, ...)
 {
@@ -1079,6 +1097,10 @@
     va_end(args);
 }
 
+#endif /* !defined(USE_GMARKUP_PARSER) */
+
+#ifndef USE_GMARKUP_PARSER
+
 static void
 glade_parser_error(GladeParseState *state, const char *msg, ...)
 {
@@ -1089,6 +1111,10 @@
     va_end(args);
 }
 
+#endif /* !defined(USE_GMARKUP_PARSER) */
+
+#ifndef USE_GMARKUP_PARSER
+
 static void
 glade_parser_fatal_error(GladeParseState *state, const char *msg, ...)
 {
@@ -1099,6 +1125,10 @@
     va_end(args);
 }
 
+#endif /* !defined(USE_GMARKUP_PARSER) */
+
+#ifndef USE_GMARKUP_PARSER
+
 static xmlSAXHandler glade_parser = {
     (internalSubsetSAXFunc)NULL,                       /* internalSubset */
     (isStandaloneSAXFunc)NULL,                         /* isStandalone */
@@ -1126,6 +1156,82 @@
     (fatalErrorSAXFunc)glade_parser_fatal_error,       /* fatalError */
 };
 
+#else /* USE_GMARKUP_PARSER */
+
+static void
+glade_parser_start_element_wrapper(GMarkupParseContext *context,
+                                   const gchar         *name, 
+                                   const gchar        **attr_names,
+                                   const gchar        **attr_values,
+                                   gpointer             state,
+                                   GError             **error)
+{
+    guint i = 0;
+
+    /* Pack attribute names/values from two separate
+     *  arrays (GMarkupParser style) into one single
+     *  array (libxml SAXParser style). This is not
+     *  very efficient, but we do it to make the
+     *  GMarkupParser code as little invasive as
+     *  possible. */
+
+    while (attr_names[i] != NULL) {
+      ++i;
+    }
+
+    if (1)
+    {
+        const gchar *attr[(i*2)+1];
+        guint j, k;
+       
+        for (j=0, k=0;  k < i;  j += 2)
+        {
+            attr[j] = attr_names[k];
+            attr[j+1] = attr_values[k];
+            ++k;
+        }
+        attr[i*2] = NULL;
+
+        glade_parser_start_element((GladeParseState*)state, name, attr);
+    }
+}
+
+static void
+glade_parser_end_element_wrapper(GMarkupParseContext *context, 
+                                 const gchar         *name,
+                                 gpointer             state,
+                                 GError             **err)
+{
+    glade_parser_end_element((GladeParseState*)state, name);
+}
+
+static void
+glade_parser_characters_wrapper(GMarkupParseContext *context, 
+                                const gchar         *chars, 
+                                gsize                len,
+                                gpointer             state,
+                                GError             **err)
+{
+    glade_parser_characters((GladeParseState*)state, chars, (int) len);
+}
+
+static void
+glade_parser_error(GMarkupParseContext *context, GError *err, gpointer data)
+{
+    g_log("Glade-Parser", G_LOG_LEVEL_CRITICAL, "%s", err->message);
+}
+
+static const GMarkupParser   glade_parser = {
+    glade_parser_start_element_wrapper,  /* element open   */
+    glade_parser_end_element_wrapper,    /* element close  */
+    glade_parser_characters_wrapper,     /* text content   */
+    NULL,                                /* passthrough    */
+    glade_parser_error,                  /* parse error    */
+};
+
+#endif /* USE_GMARKUP_PARSER */
+
+
 static void
 widget_info_free(GladeWidgetInfo *info)
 {
@@ -1191,6 +1297,9 @@
  *
  * Returns: the GladeInterface structure for the XML file.
  */
+
+#ifndef USE_GMARKUP_PARSER
+
 GladeInterface *
 glade_parser_parse_file(const gchar *file, const gchar *domain)
 {
@@ -1222,6 +1331,31 @@
     return state.interface;
 }
 
+#else /* defined(USE_GMARKUP_PARSER) */
+
+GladeInterface *
+glade_parser_parse_file(const gchar *file, const gchar *domain)
+{
+    GladeInterface  *interface;
+    GError          *err     = NULL;
+    gchar           *content = NULL;
+    gsize            clen;
+
+    if (!g_file_get_contents(file, &content, &clen, &err)) {
+        g_warning("could not load glade file: %s", err->message);
+        g_error_free(err);
+        return NULL;
+    }
+
+    interface = glade_parser_parse_buffer(content, (gint) clen, domain);
+
+    g_free(content);
+
+    return interface;
+}
+
+#endif /* USE_GMARKUP_PARSER */
+
 /**
  * glade_parser_parse_buffer
  * @buffer: a buffer in memory containing XML data.
@@ -1237,6 +1371,9 @@
  *
  * Returns: the GladeInterface structure for the XML buffer.
  */
+
+#ifndef USE_GMARKUP_PARSER
+
 GladeInterface *
 glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
 {
@@ -1263,6 +1400,161 @@
     return state.interface;
 }
 
+#else /* defined(USE_GMARKUP_PARSER) */
+
+
+static GladeInterface *
+glade_parser_parse_buffer_internal(const gchar *buffer, gint len, const gchar *domain)
+{
+	GMarkupParseContext  *context;
+	GladeParseState       state = { 0 };
+	GError               *err   = NULL;
+
+	state.interface = NULL;
+	if (domain)
+		state.domain = domain;
+	else
+		state.domain = textdomain(NULL);
+
+	/* FIXME: This strstr() is not safe, as it ignores the len
+	 *        argument and assumes the buffer is NUL-terminated */
+	if (strstr(buffer, "<?xml") == NULL) {
+		g_warning("No XML header found in document!");
+		return NULL;
+	}
+
+	context = g_markup_parse_context_new(&glade_parser, (GMarkupParseFlags) 0, &state, NULL);
+
+	glade_parser_start_document(&state);
+
+	if (!g_markup_parse_context_parse(context, buffer, (gssize) len, &err)) {
+		g_warning("document not well formed: %s", err->message);
+		g_error_free(err);
+		if (state.interface)
+			glade_interface_destroy (state.interface);
+		return NULL;
+	}
+
+	glade_parser_end_document(&state);
+
+	if (state.state != PARSER_FINISH) {
+		g_warning("did not finish in PARSER_FINISH state!");
+
+		if (state.interface)
+			glade_interface_destroy(state.interface);
+
+		return NULL;
+	}
+
+	return state.interface;
+}
+
+struct _gzip_rfc1952_hdr
+{
+	guint8	id1, id2, cm, flags;
+	guint32 mtime;
+	guint8  xflags;
+	guint8  os;
+};
+
+static GladeInterface *
+glade_parser_parse_gzipped_buffer(const gchar *buffer, gint len, const gchar *domain)
+{
+	struct _gzip_rfc1952_hdr *hdr = (struct _gzip_rfc1952_hdr*)buffer;
+	struct z_stream_s         zstream;
+	GladeInterface           *interface;
+	const guint8             *cbuf;              /* start of compressed data */
+	guint8                   *decompress_buf;
+	gulong                    decompress_len = 0;
+	gint                      ret;
+
+	g_assert(hdr != NULL && hdr->id1 == 0x1f && hdr->id2 == 0x8b);
+
+	if (hdr->cm != Z_DEFLATED) {
+		g_warning("Unknown decompression method %u", (guint) hdr->cm);
+		return NULL;
+	}
+
+	/* Uncompressed size (modulo 2^32) is last
+	 *  4 bytes of gzipped file, and little endian.
+	 *  See RFC 1952 */
+	decompress_len = GUINT32_FROM_LE(*((guint32*)(((guint8*)buffer) + len - 4)));
+
+	/* paranoid mode: glade files > 5MB are unlikely */
+	g_return_val_if_fail(decompress_len < 5*1024*1024, NULL);
+
+	decompress_buf = g_malloc0(decompress_len + 1); /* +1 for NUL-terminator */
+
+	/* find start of compressed data, skipping header stuff */
+	cbuf = (guint8*)buffer + 10;
+	if (hdr->flags & 0x04) {
+		guint16 xlen = GUINT16_FROM_LE(*((guint16*)cbuf));
+		cbuf += xlen + 2;
+	}
+	if (hdr->flags & 0x08) {
+		guint16 onamelen = strlen(cbuf);
+		cbuf += onamelen + 1;
+	}
+	if (hdr->flags & 0x10) {
+		guint16 commentlen = strlen(cbuf);
+		cbuf += commentlen + 1;
+	}
+	if (hdr->flags & 0x02)
+	{
+		cbuf += 2; /* skip header CRC16 */
+	}
+
+	zstream.next_in  = (void*)cbuf;
+	zstream.avail_in = (uLongf) len - ((void*)cbuf-(void*)buffer) - 4 - 4 +1; 
+	zstream.next_out = decompress_buf;
+	zstream.avail_out= decompress_len;
+	zstream.zalloc   = Z_NULL;
+	zstream.zfree    = Z_NULL;
+	zstream.opaque   = Z_NULL;
+
+	ret = inflateInit2(&zstream, -MAX_WBITS);
+
+	if (ret != Z_OK) {
+		g_warning("inflateInit2() failed. zlib error code: %d", ret);
+		g_free(decompress_buf);
+		return NULL;
+	}
+
+	ret = inflate(&zstream, Z_FINISH);
+
+	if (ret != Z_STREAM_END) {
+		g_warning("zlib decompression failed. zlib error code: %d", ret);
+		g_free(decompress_buf);
+		return NULL;
+	}
+
+	interface = glade_parser_parse_buffer_internal(decompress_buf, decompress_len, domain);
+
+	g_free(decompress_buf);
+
+	return interface;
+}
+
+GladeInterface *
+glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain)
+{
+	g_return_val_if_fail(buffer != NULL, NULL);
+	g_return_val_if_fail(len > 0, NULL);
+
+	/* Check if buffer is gzipped */
+	if (buffer[0] == 0x1f && buffer[1] == (gchar)0x8b) {
+		return glade_parser_parse_gzipped_buffer(buffer, len, domain);
+	}
+
+	/* Buffer is cleartext. */
+	return glade_parser_parse_buffer_internal(buffer, len, domain);
+}
+
+#endif /* USE_GMARKUP_PARSER */
+
+
+#ifndef USE_GMARKUP_PARSER
+
 static void
 dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent)
 {
@@ -1382,6 +1674,8 @@
 	xmlNodeAddContent(widget, "  ");
 }
 
+#endif /* !defined(USE_GMARKUP_PARSER) */
+
 /**
  * glade_interface_dump
  * @interface: the GladeInterface
@@ -1390,6 +1684,9 @@
  * This function dumps the contents of a GladeInterface into a file as
  * XML.  It is intended mainly as a debugging tool.
  */
+
+#ifndef USE_GMARKUP_PARSER
+
 void
 glade_interface_dump(GladeInterface *interface, const gchar *filename)
 {
@@ -1428,6 +1725,17 @@
     xmlFreeDoc(doc);
 }
 
+#else /* defined(USE_GMARKUP_PARSER) */
+
+void
+glade_interface_dump(GladeInterface *interface, const gchar *filename)
+{
+    g_warning("glade_interface_dump() is only available with libxml2.");
+}
+
+#endif /* USE_GMARKUP_PARSER */
+
+
 #if 0
 int
 main(int argc, char **argv) {
diff -urN libglade-2.4.2.orig/libglade-2.0.pc.in libglade-2.4.2/libglade-2.0.pc.in
--- libglade-2.4.2.orig/libglade-2.0.pc.in	2001-12-12 15:28:23.000000000 +0100
+++ libglade-2.4.2/libglade-2.0.pc.in	2005-03-22 01:20:00.000000000 +0100
@@ -11,7 +11,7 @@
 Name: Libglade
 Description: a library for dynamically loading GLADE interface files
 Version: @VERSION@
-Requires: gtk+-2.0 libxml-2.0
+Requires: gtk+-2.0 @PKGCFG_REQUIRE_LIBXML2@
 Libs: -L${libdir} -lglade-2.0
 Cflags: -I${includedir}/libglade-2.0