Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | Upstream-Status: Inappropriate [configuration] |
| 2 | |
| 3 | diff -urN libglade-2.4.2.orig/configure.in libglade-2.4.2/configure.in |
| 4 | --- libglade-2.4.2.orig/configure.in 2005-02-11 12:42:58.000000000 +0100 |
| 5 | +++ libglade-2.4.2/configure.in 2005-03-22 01:22:00.000000000 +0100 |
| 6 | @@ -52,11 +52,33 @@ |
| 7 | AC_PATH_PROG(PKG_CONFIG, pkg-config, no) |
| 8 | |
| 9 | PKG_CHECK_MODULES(LIBGLADE, [dnl |
| 10 | - libxml-2.0 >= required_libxml_version dnl |
| 11 | atk >= required_atk_version dnl |
| 12 | gtk+-2.0 >= required_gtk_version dnl |
| 13 | glib-2.0 >= required_glib_version]) |
| 14 | |
| 15 | +disable_xml2=no |
| 16 | +AC_ARG_WITH([libxml2], |
| 17 | + AC_HELP_STRING([--without-libxml2], [Don't use libxml2, use Glib's GMarkupParser instead]), |
| 18 | + [disable_xml2=yes], |
| 19 | + [disable_xml2=no]) |
| 20 | + |
| 21 | +AC_MSG_CHECKING([if we are using libxml2]) |
| 22 | +if test "x$disable_xml2" == "xno"; then |
| 23 | + AC_MSG_RESULT(yes) |
| 24 | + PKG_CHECK_MODULES(XML2, libxml-2.0 >= 2.4.10) |
| 25 | + PKGCFG_REQUIRE_LIBXML2="libxml-2.0" |
| 26 | + LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS $XML2_CFLAGS" |
| 27 | + LIBGLADE_LIBS="$LIBGLADE_LIBS $XML2_LIBS" |
| 28 | +else |
| 29 | + LIBGLADE_CFLAGS="$LIBGLADE_CFLAGS -DUSE_GMARKUP_PARSER" |
| 30 | + PKGCFG_REQUIRE_LIBXML2="" |
| 31 | + AC_MSG_RESULT(no) |
| 32 | +fi |
| 33 | + |
| 34 | +AC_SUBST(XML2_LIBS) |
| 35 | +AC_SUBST(XML2_CFLAGS) |
| 36 | +AC_SUBST(PKGCFG_REQUIRE_LIBXML2) |
| 37 | + |
| 38 | AC_MSG_CHECKING([for native Win32]) |
| 39 | case "$host" in |
| 40 | *-*-mingw*) |
| 41 | @@ -116,6 +138,21 @@ |
| 42 | fi |
| 43 | fi |
| 44 | |
| 45 | +if test "x$disable_xml2" == "xyes"; then |
| 46 | + echo "*****************************************************" |
| 47 | + echo " You chose to disable libxml2 and use Glib's" |
| 48 | + echo " GMarkupParser instead." |
| 49 | + echo |
| 50 | + echo " Please bear in mind that using libglade with" |
| 51 | + echo " GMarkupParser is an experimental feature only." |
| 52 | + echo |
| 53 | + echo " Please post problems or success stories to" |
| 54 | + echo " the glade-devel mailing list. Thank you." |
| 55 | + echo "*****************************************************" |
| 56 | +fi |
| 57 | + |
| 58 | + |
| 59 | + |
| 60 | GTK_DOC_CHECK(1.0) |
| 61 | |
| 62 | dnl gettext stuff ... there is no message catalog for libglade -- libglade |
| 63 | diff -urN libglade-2.4.2.orig/glade/glade-parser.c libglade-2.4.2/glade/glade-parser.c |
| 64 | --- libglade-2.4.2.orig/glade/glade-parser.c 2004-11-11 11:56:13.000000000 +0100 |
| 65 | +++ libglade-2.4.2/glade/glade-parser.c 2005-03-22 01:20:00.000000000 +0100 |
| 66 | @@ -34,7 +34,15 @@ |
| 67 | # define dgettext(Domain, String) (String) |
| 68 | #endif |
| 69 | |
| 70 | -#include <libxml/parser.h> |
| 71 | +#ifdef USE_GMARKUP_PARSER |
| 72 | +# include <zlib.h> |
| 73 | +#else |
| 74 | +# include <libxml/parser.h> |
| 75 | +#endif |
| 76 | + |
| 77 | +#ifdef USE_GMARKUP_PARSER |
| 78 | +# define xmlChar gchar |
| 79 | +#endif |
| 80 | |
| 81 | #include "glade-parser.h" |
| 82 | #include "glade-private.h" |
| 83 | @@ -508,7 +516,9 @@ |
| 84 | case PARSER_START: |
| 85 | if (!strcmp(name, "glade-interface")) { |
| 86 | state->state = PARSER_GLADE_INTERFACE; |
| 87 | -#if 0 |
| 88 | + |
| 89 | +#ifndef USE_GMARKUP_PARSER |
| 90 | + #if 0 |
| 91 | /* check for correct XML namespace */ |
| 92 | for (i = 0; attrs && attrs[i] != NULL; i += 2) { |
| 93 | if (!strcmp(attrs[i], "xmlns") && |
| 94 | @@ -518,7 +528,9 @@ |
| 95 | g_warning("unknown attribute `%s' for <glade-interface>", |
| 96 | attrs[i]); |
| 97 | } |
| 98 | + #endif |
| 99 | #endif |
| 100 | + |
| 101 | } else { |
| 102 | g_warning("Expected <glade-interface>. Got <%s>.", name); |
| 103 | state->prev_state = state->state; |
| 104 | @@ -1063,12 +1075,18 @@ |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | +#ifndef USE_GMARKUP_PARSER |
| 109 | + |
| 110 | static xmlEntityPtr |
| 111 | glade_parser_get_entity(GladeParseState *state, const xmlChar *name) |
| 112 | { |
| 113 | return xmlGetPredefinedEntity(name); |
| 114 | } |
| 115 | |
| 116 | +#endif /* !defined(USE_GMARKUP_PARSER) */ |
| 117 | + |
| 118 | +#ifndef USE_GMARKUP_PARSER |
| 119 | + |
| 120 | static void |
| 121 | glade_parser_warning(GladeParseState *state, const char *msg, ...) |
| 122 | { |
| 123 | @@ -1079,6 +1097,10 @@ |
| 124 | va_end(args); |
| 125 | } |
| 126 | |
| 127 | +#endif /* !defined(USE_GMARKUP_PARSER) */ |
| 128 | + |
| 129 | +#ifndef USE_GMARKUP_PARSER |
| 130 | + |
| 131 | static void |
| 132 | glade_parser_error(GladeParseState *state, const char *msg, ...) |
| 133 | { |
| 134 | @@ -1089,6 +1111,10 @@ |
| 135 | va_end(args); |
| 136 | } |
| 137 | |
| 138 | +#endif /* !defined(USE_GMARKUP_PARSER) */ |
| 139 | + |
| 140 | +#ifndef USE_GMARKUP_PARSER |
| 141 | + |
| 142 | static void |
| 143 | glade_parser_fatal_error(GladeParseState *state, const char *msg, ...) |
| 144 | { |
| 145 | @@ -1099,6 +1125,10 @@ |
| 146 | va_end(args); |
| 147 | } |
| 148 | |
| 149 | +#endif /* !defined(USE_GMARKUP_PARSER) */ |
| 150 | + |
| 151 | +#ifndef USE_GMARKUP_PARSER |
| 152 | + |
| 153 | static xmlSAXHandler glade_parser = { |
| 154 | (internalSubsetSAXFunc)NULL, /* internalSubset */ |
| 155 | (isStandaloneSAXFunc)NULL, /* isStandalone */ |
| 156 | @@ -1126,6 +1156,82 @@ |
| 157 | (fatalErrorSAXFunc)glade_parser_fatal_error, /* fatalError */ |
| 158 | }; |
| 159 | |
| 160 | +#else /* USE_GMARKUP_PARSER */ |
| 161 | + |
| 162 | +static void |
| 163 | +glade_parser_start_element_wrapper(GMarkupParseContext *context, |
| 164 | + const gchar *name, |
| 165 | + const gchar **attr_names, |
| 166 | + const gchar **attr_values, |
| 167 | + gpointer state, |
| 168 | + GError **error) |
| 169 | +{ |
| 170 | + guint i = 0; |
| 171 | + |
| 172 | + /* Pack attribute names/values from two separate |
| 173 | + * arrays (GMarkupParser style) into one single |
| 174 | + * array (libxml SAXParser style). This is not |
| 175 | + * very efficient, but we do it to make the |
| 176 | + * GMarkupParser code as little invasive as |
| 177 | + * possible. */ |
| 178 | + |
| 179 | + while (attr_names[i] != NULL) { |
| 180 | + ++i; |
| 181 | + } |
| 182 | + |
| 183 | + if (1) |
| 184 | + { |
| 185 | + const gchar *attr[(i*2)+1]; |
| 186 | + guint j, k; |
| 187 | + |
| 188 | + for (j=0, k=0; k < i; j += 2) |
| 189 | + { |
| 190 | + attr[j] = attr_names[k]; |
| 191 | + attr[j+1] = attr_values[k]; |
| 192 | + ++k; |
| 193 | + } |
| 194 | + attr[i*2] = NULL; |
| 195 | + |
| 196 | + glade_parser_start_element((GladeParseState*)state, name, attr); |
| 197 | + } |
| 198 | +} |
| 199 | + |
| 200 | +static void |
| 201 | +glade_parser_end_element_wrapper(GMarkupParseContext *context, |
| 202 | + const gchar *name, |
| 203 | + gpointer state, |
| 204 | + GError **err) |
| 205 | +{ |
| 206 | + glade_parser_end_element((GladeParseState*)state, name); |
| 207 | +} |
| 208 | + |
| 209 | +static void |
| 210 | +glade_parser_characters_wrapper(GMarkupParseContext *context, |
| 211 | + const gchar *chars, |
| 212 | + gsize len, |
| 213 | + gpointer state, |
| 214 | + GError **err) |
| 215 | +{ |
| 216 | + glade_parser_characters((GladeParseState*)state, chars, (int) len); |
| 217 | +} |
| 218 | + |
| 219 | +static void |
| 220 | +glade_parser_error(GMarkupParseContext *context, GError *err, gpointer data) |
| 221 | +{ |
| 222 | + g_log("Glade-Parser", G_LOG_LEVEL_CRITICAL, "%s", err->message); |
| 223 | +} |
| 224 | + |
| 225 | +static const GMarkupParser glade_parser = { |
| 226 | + glade_parser_start_element_wrapper, /* element open */ |
| 227 | + glade_parser_end_element_wrapper, /* element close */ |
| 228 | + glade_parser_characters_wrapper, /* text content */ |
| 229 | + NULL, /* passthrough */ |
| 230 | + glade_parser_error, /* parse error */ |
| 231 | +}; |
| 232 | + |
| 233 | +#endif /* USE_GMARKUP_PARSER */ |
| 234 | + |
| 235 | + |
| 236 | static void |
| 237 | widget_info_free(GladeWidgetInfo *info) |
| 238 | { |
| 239 | @@ -1191,6 +1297,9 @@ |
| 240 | * |
| 241 | * Returns: the GladeInterface structure for the XML file. |
| 242 | */ |
| 243 | + |
| 244 | +#ifndef USE_GMARKUP_PARSER |
| 245 | + |
| 246 | GladeInterface * |
| 247 | glade_parser_parse_file(const gchar *file, const gchar *domain) |
| 248 | { |
| 249 | @@ -1222,6 +1331,31 @@ |
| 250 | return state.interface; |
| 251 | } |
| 252 | |
| 253 | +#else /* defined(USE_GMARKUP_PARSER) */ |
| 254 | + |
| 255 | +GladeInterface * |
| 256 | +glade_parser_parse_file(const gchar *file, const gchar *domain) |
| 257 | +{ |
| 258 | + GladeInterface *interface; |
| 259 | + GError *err = NULL; |
| 260 | + gchar *content = NULL; |
| 261 | + gsize clen; |
| 262 | + |
| 263 | + if (!g_file_get_contents(file, &content, &clen, &err)) { |
| 264 | + g_warning("could not load glade file: %s", err->message); |
| 265 | + g_error_free(err); |
| 266 | + return NULL; |
| 267 | + } |
| 268 | + |
| 269 | + interface = glade_parser_parse_buffer(content, (gint) clen, domain); |
| 270 | + |
| 271 | + g_free(content); |
| 272 | + |
| 273 | + return interface; |
| 274 | +} |
| 275 | + |
| 276 | +#endif /* USE_GMARKUP_PARSER */ |
| 277 | + |
| 278 | /** |
| 279 | * glade_parser_parse_buffer |
| 280 | * @buffer: a buffer in memory containing XML data. |
| 281 | @@ -1237,6 +1371,9 @@ |
| 282 | * |
| 283 | * Returns: the GladeInterface structure for the XML buffer. |
| 284 | */ |
| 285 | + |
| 286 | +#ifndef USE_GMARKUP_PARSER |
| 287 | + |
| 288 | GladeInterface * |
| 289 | glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain) |
| 290 | { |
| 291 | @@ -1263,6 +1400,161 @@ |
| 292 | return state.interface; |
| 293 | } |
| 294 | |
| 295 | +#else /* defined(USE_GMARKUP_PARSER) */ |
| 296 | + |
| 297 | + |
| 298 | +static GladeInterface * |
| 299 | +glade_parser_parse_buffer_internal(const gchar *buffer, gint len, const gchar *domain) |
| 300 | +{ |
| 301 | + GMarkupParseContext *context; |
| 302 | + GladeParseState state = { 0 }; |
| 303 | + GError *err = NULL; |
| 304 | + |
| 305 | + state.interface = NULL; |
| 306 | + if (domain) |
| 307 | + state.domain = domain; |
| 308 | + else |
| 309 | + state.domain = textdomain(NULL); |
| 310 | + |
| 311 | + /* FIXME: This strstr() is not safe, as it ignores the len |
| 312 | + * argument and assumes the buffer is NUL-terminated */ |
| 313 | + if (strstr(buffer, "<?xml") == NULL) { |
| 314 | + g_warning("No XML header found in document!"); |
| 315 | + return NULL; |
| 316 | + } |
| 317 | + |
| 318 | + context = g_markup_parse_context_new(&glade_parser, (GMarkupParseFlags) 0, &state, NULL); |
| 319 | + |
| 320 | + glade_parser_start_document(&state); |
| 321 | + |
| 322 | + if (!g_markup_parse_context_parse(context, buffer, (gssize) len, &err)) { |
| 323 | + g_warning("document not well formed: %s", err->message); |
| 324 | + g_error_free(err); |
| 325 | + if (state.interface) |
| 326 | + glade_interface_destroy (state.interface); |
| 327 | + return NULL; |
| 328 | + } |
| 329 | + |
| 330 | + glade_parser_end_document(&state); |
| 331 | + |
| 332 | + if (state.state != PARSER_FINISH) { |
| 333 | + g_warning("did not finish in PARSER_FINISH state!"); |
| 334 | + |
| 335 | + if (state.interface) |
| 336 | + glade_interface_destroy(state.interface); |
| 337 | + |
| 338 | + return NULL; |
| 339 | + } |
| 340 | + |
| 341 | + return state.interface; |
| 342 | +} |
| 343 | + |
| 344 | +struct _gzip_rfc1952_hdr |
| 345 | +{ |
| 346 | + guint8 id1, id2, cm, flags; |
| 347 | + guint32 mtime; |
| 348 | + guint8 xflags; |
| 349 | + guint8 os; |
| 350 | +}; |
| 351 | + |
| 352 | +static GladeInterface * |
| 353 | +glade_parser_parse_gzipped_buffer(const gchar *buffer, gint len, const gchar *domain) |
| 354 | +{ |
| 355 | + struct _gzip_rfc1952_hdr *hdr = (struct _gzip_rfc1952_hdr*)buffer; |
| 356 | + struct z_stream_s zstream; |
| 357 | + GladeInterface *interface; |
| 358 | + const guint8 *cbuf; /* start of compressed data */ |
| 359 | + guint8 *decompress_buf; |
| 360 | + gulong decompress_len = 0; |
| 361 | + gint ret; |
| 362 | + |
| 363 | + g_assert(hdr != NULL && hdr->id1 == 0x1f && hdr->id2 == 0x8b); |
| 364 | + |
| 365 | + if (hdr->cm != Z_DEFLATED) { |
| 366 | + g_warning("Unknown decompression method %u", (guint) hdr->cm); |
| 367 | + return NULL; |
| 368 | + } |
| 369 | + |
| 370 | + /* Uncompressed size (modulo 2^32) is last |
| 371 | + * 4 bytes of gzipped file, and little endian. |
| 372 | + * See RFC 1952 */ |
| 373 | + decompress_len = GUINT32_FROM_LE(*((guint32*)(((guint8*)buffer) + len - 4))); |
| 374 | + |
| 375 | + /* paranoid mode: glade files > 5MB are unlikely */ |
| 376 | + g_return_val_if_fail(decompress_len < 5*1024*1024, NULL); |
| 377 | + |
| 378 | + decompress_buf = g_malloc0(decompress_len + 1); /* +1 for NUL-terminator */ |
| 379 | + |
| 380 | + /* find start of compressed data, skipping header stuff */ |
| 381 | + cbuf = (guint8*)buffer + 10; |
| 382 | + if (hdr->flags & 0x04) { |
| 383 | + guint16 xlen = GUINT16_FROM_LE(*((guint16*)cbuf)); |
| 384 | + cbuf += xlen + 2; |
| 385 | + } |
| 386 | + if (hdr->flags & 0x08) { |
| 387 | + guint16 onamelen = strlen(cbuf); |
| 388 | + cbuf += onamelen + 1; |
| 389 | + } |
| 390 | + if (hdr->flags & 0x10) { |
| 391 | + guint16 commentlen = strlen(cbuf); |
| 392 | + cbuf += commentlen + 1; |
| 393 | + } |
| 394 | + if (hdr->flags & 0x02) |
| 395 | + { |
| 396 | + cbuf += 2; /* skip header CRC16 */ |
| 397 | + } |
| 398 | + |
| 399 | + zstream.next_in = (void*)cbuf; |
| 400 | + zstream.avail_in = (uLongf) len - ((void*)cbuf-(void*)buffer) - 4 - 4 +1; |
| 401 | + zstream.next_out = decompress_buf; |
| 402 | + zstream.avail_out= decompress_len; |
| 403 | + zstream.zalloc = Z_NULL; |
| 404 | + zstream.zfree = Z_NULL; |
| 405 | + zstream.opaque = Z_NULL; |
| 406 | + |
| 407 | + ret = inflateInit2(&zstream, -MAX_WBITS); |
| 408 | + |
| 409 | + if (ret != Z_OK) { |
| 410 | + g_warning("inflateInit2() failed. zlib error code: %d", ret); |
| 411 | + g_free(decompress_buf); |
| 412 | + return NULL; |
| 413 | + } |
| 414 | + |
| 415 | + ret = inflate(&zstream, Z_FINISH); |
| 416 | + |
| 417 | + if (ret != Z_STREAM_END) { |
| 418 | + g_warning("zlib decompression failed. zlib error code: %d", ret); |
| 419 | + g_free(decompress_buf); |
| 420 | + return NULL; |
| 421 | + } |
| 422 | + |
| 423 | + interface = glade_parser_parse_buffer_internal(decompress_buf, decompress_len, domain); |
| 424 | + |
| 425 | + g_free(decompress_buf); |
| 426 | + |
| 427 | + return interface; |
| 428 | +} |
| 429 | + |
| 430 | +GladeInterface * |
| 431 | +glade_parser_parse_buffer(const gchar *buffer, gint len, const gchar *domain) |
| 432 | +{ |
| 433 | + g_return_val_if_fail(buffer != NULL, NULL); |
| 434 | + g_return_val_if_fail(len > 0, NULL); |
| 435 | + |
| 436 | + /* Check if buffer is gzipped */ |
| 437 | + if (buffer[0] == 0x1f && buffer[1] == (gchar)0x8b) { |
| 438 | + return glade_parser_parse_gzipped_buffer(buffer, len, domain); |
| 439 | + } |
| 440 | + |
| 441 | + /* Buffer is cleartext. */ |
| 442 | + return glade_parser_parse_buffer_internal(buffer, len, domain); |
| 443 | +} |
| 444 | + |
| 445 | +#endif /* USE_GMARKUP_PARSER */ |
| 446 | + |
| 447 | + |
| 448 | +#ifndef USE_GMARKUP_PARSER |
| 449 | + |
| 450 | static void |
| 451 | dump_widget(xmlNode *parent, GladeWidgetInfo *info, gint indent) |
| 452 | { |
| 453 | @@ -1382,6 +1674,8 @@ |
| 454 | xmlNodeAddContent(widget, " "); |
| 455 | } |
| 456 | |
| 457 | +#endif /* !defined(USE_GMARKUP_PARSER) */ |
| 458 | + |
| 459 | /** |
| 460 | * glade_interface_dump |
| 461 | * @interface: the GladeInterface |
| 462 | @@ -1390,6 +1684,9 @@ |
| 463 | * This function dumps the contents of a GladeInterface into a file as |
| 464 | * XML. It is intended mainly as a debugging tool. |
| 465 | */ |
| 466 | + |
| 467 | +#ifndef USE_GMARKUP_PARSER |
| 468 | + |
| 469 | void |
| 470 | glade_interface_dump(GladeInterface *interface, const gchar *filename) |
| 471 | { |
| 472 | @@ -1428,6 +1725,17 @@ |
| 473 | xmlFreeDoc(doc); |
| 474 | } |
| 475 | |
| 476 | +#else /* defined(USE_GMARKUP_PARSER) */ |
| 477 | + |
| 478 | +void |
| 479 | +glade_interface_dump(GladeInterface *interface, const gchar *filename) |
| 480 | +{ |
| 481 | + g_warning("glade_interface_dump() is only available with libxml2."); |
| 482 | +} |
| 483 | + |
| 484 | +#endif /* USE_GMARKUP_PARSER */ |
| 485 | + |
| 486 | + |
| 487 | #if 0 |
| 488 | int |
| 489 | main(int argc, char **argv) { |
| 490 | diff -urN libglade-2.4.2.orig/libglade-2.0.pc.in libglade-2.4.2/libglade-2.0.pc.in |
| 491 | --- libglade-2.4.2.orig/libglade-2.0.pc.in 2001-12-12 15:28:23.000000000 +0100 |
| 492 | +++ libglade-2.4.2/libglade-2.0.pc.in 2005-03-22 01:20:00.000000000 +0100 |
| 493 | @@ -11,7 +11,7 @@ |
| 494 | Name: Libglade |
| 495 | Description: a library for dynamically loading GLADE interface files |
| 496 | Version: @VERSION@ |
| 497 | -Requires: gtk+-2.0 libxml-2.0 |
| 498 | +Requires: gtk+-2.0 @PKGCFG_REQUIRE_LIBXML2@ |
| 499 | Libs: -L${libdir} -lglade-2.0 |
| 500 | Cflags: -I${includedir}/libglade-2.0 |
| 501 | |