# HG changeset patch # User Mark Doliner # Date 1157342112 0 # Node ID 289490ee84d15f3bdc59ada0e0c7430b6b779e45 # Parent 9c6533500fff32d83b7c1d3b28b44f02cfe60627 [gaim-migrate @ 17150] libxml2 is now required for XML parsing committer: Tailor Script diff -r 9c6533500fff -r 289490ee84d1 ChangeLog --- a/ChangeLog Mon Sep 04 03:23:41 2006 +0000 +++ b/ChangeLog Mon Sep 04 03:55:12 2006 +0000 @@ -9,8 +9,8 @@ (Sadrul Habib Chowdhury, Google Summer of Code) * Reorganized the source tree to split apart the code for the UI changes and libgaim targets - * libxml2 can now be used in place of gmarkup for expanded XML parsing - features + * libxml2 is now required. We switched from gmarkup to libxml2 for + more correct XML parsing. Status System: * The code dealing with buddy and account status, away messages, diff -r 9c6533500fff -r 289490ee84d1 configure.ac --- a/configure.ac Mon Sep 04 03:23:41 2006 +0000 +++ b/configure.ac Mon Sep 04 03:55:12 2006 +0000 @@ -183,16 +183,15 @@ dnl ################# enable_libxml2=yes PKG_CHECK_MODULES(LIBXML, [libxml-2.0], , - [ - AC_MSG_RESULT(no) - enable_libxml2=no - ]) + [ + AC_MSG_ERROR([ +*** libxml2 is required to build Gaim; please make sure you have the +*** libxml2 development headers installed.]) + ]) AC_SUBST(LIBXML_CFLAGS) AC_SUBST(LIBXML_LIBS) -AC_ARG_ENABLE(libxml, [AC_HELP_STRING([--disable-libxml], [compile without libxml2 support])],enable_libxml2=no) -if test "x$enable_libxml2" = "xyes"; then - AC_DEFINE(HAVE_LIBXML, 1, [Use libxml2 for xml parsing]) -fi + + dnl ####################################################################### dnl # Check for Meanwhile headers (for Sametime) @@ -1933,7 +1932,6 @@ eval eval echo DBUS servies directory........ : $DBUS_SERVICES_DIR fi echo Build with Cyrus SASL support. : $enable_cyrus_sasl -echo Build with libxml2 support.... : $enable_libxml2 echo Has you....................... : yes echo echo Use kerberos 4 with zephyr.... : $kerberos diff -r 9c6533500fff -r 289490ee84d1 gtk/gtkdialogs.c --- a/gtk/gtkdialogs.c Mon Sep 04 03:23:41 2006 +0000 +++ b/gtk/gtkdialogs.c Mon Sep 04 03:55:12 2006 +0000 @@ -558,12 +558,6 @@ g_string_append(str, " Tk: Disabled
"); #endif -#ifdef HAVE_LIBXML - g_string_append(str, " XML Parser: libxml2
"); -#else - g_string_append(str, " XML Parser: GMarkup
"); -#endif - #ifndef _WIN32 #ifdef USE_SM g_string_append(str, " X Session Management: Enabled
"); diff -r 9c6533500fff -r 289490ee84d1 libgaim/protocols/jabber/jabber.c --- a/libgaim/protocols/jabber/jabber.c Mon Sep 04 03:23:41 2006 +0000 +++ b/libgaim/protocols/jabber/jabber.c Mon Sep 04 03:55:12 2006 +0000 @@ -945,10 +945,6 @@ gaim_input_remove(js->gc->inpa); close(js->fd); } -#ifndef HAVE_LIBXML - if(js->context) - g_markup_parse_context_free(js->context); -#endif if(js->iq_callbacks) g_hash_table_destroy(js->iq_callbacks); if(js->disco_callbacks) diff -r 9c6533500fff -r 289490ee84d1 libgaim/protocols/jabber/jabber.h --- a/libgaim/protocols/jabber/jabber.h Mon Sep 04 03:23:41 2006 +0000 +++ b/libgaim/protocols/jabber/jabber.h Mon Sep 04 03:55:12 2006 +0000 @@ -22,9 +22,7 @@ #ifndef _GAIM_JABBER_H_ #define _GAIM_JABBER_H_ -#ifdef HAVE_LIBXML #include -#endif #include #include "circbuffer.h" #include "connection.h" @@ -71,11 +69,7 @@ GaimSrvQueryData *srv_query_data; GaimProxyConnectData *connect_data; -#ifdef HAVE_LIBXML xmlParserCtxt *context; -#else - GMarkupParseContext *context; -#endif xmlnode *current; enum { diff -r 9c6533500fff -r 289490ee84d1 libgaim/protocols/jabber/parser.c --- a/libgaim/protocols/jabber/parser.c Mon Sep 04 03:23:41 2006 +0000 +++ b/libgaim/protocols/jabber/parser.c Mon Sep 04 03:55:12 2006 +0000 @@ -20,9 +20,7 @@ */ #include "internal.h" -#ifdef HAVE_LIBXML #include -#endif #include "connection.h" #include "debug.h" @@ -30,87 +28,6 @@ #include "parser.h" #include "xmlnode.h" -#ifndef HAVE_LIBXML -static void -jabber_parser_element_start(GMarkupParseContext *context, - const char *element_name, const char **attrib_names, - const char **attrib_values, gpointer user_data, GError **error) -{ - JabberStream *js = user_data; - xmlnode *node; - int i; - - if(!element_name) { - return; - } else if(!strcmp(element_name, "stream:stream")) { - js->protocol_version = JABBER_PROTO_0_9; - for(i=0; attrib_names[i]; i++) { - if(!strcmp(attrib_names[i], "version") - && !strcmp(attrib_values[i], "1.0")) { - js->protocol_version = JABBER_PROTO_1_0; - } else if(!strcmp(attrib_names[i], "id")) { - if(js->stream_id) - g_free(js->stream_id); - js->stream_id = g_strdup(attrib_values[i]); - } - } - if(js->protocol_version == JABBER_PROTO_0_9) - js->auth_type = JABBER_AUTH_IQ_AUTH; - - if(js->state == JABBER_STREAM_INITIALIZING) - jabber_stream_set_state(js, JABBER_STREAM_AUTHENTICATING); - } else { - - if(js->current) - node = xmlnode_new_child(js->current, element_name); - else - node = xmlnode_new(element_name); - - for(i=0; attrib_names[i]; i++) { - xmlnode_set_attrib(node, attrib_names[i], attrib_values[i]); - } - - js->current = node; - } -} - -static void -jabber_parser_element_end(GMarkupParseContext *context, - const char *element_name, gpointer user_data, GError **error) -{ - JabberStream *js = user_data; - - if(!js->current) - return; - - if(js->current->parent) { - if(!strcmp(js->current->name, element_name)) - js->current = js->current->parent; - } else { - xmlnode *packet = js->current; - js->current = NULL; - jabber_process_packet(js, packet); - xmlnode_free(packet); - } -} - -static void -jabber_parser_element_text(GMarkupParseContext *context, const char *text, - gsize text_len, gpointer user_data, GError **error) -{ - JabberStream *js = user_data; - - if(!js->current) - return; - - if(!text || !text_len) - return; - - xmlnode_insert_data(js->current, text, text_len); -} - -#else /* HAVE_LIBXML */ - static void jabber_parser_element_start_libxml(void *user_data, const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace, @@ -130,7 +47,7 @@ char *attrib = g_malloc(attrib_len + 1); memcpy(attrib, attributes[i+3], attrib_len); attrib[attrib_len] = '\0'; - + if(!strcmp(attributes[i], "version") && !strcmp(attrib, "1.0")) { js->protocol_version = JABBER_PROTO_1_0; @@ -168,7 +85,7 @@ } static void -jabber_parser_element_end_libxml(void *user_data, const xmlChar *element_name, +jabber_parser_element_end_libxml(void *user_data, const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace) { JabberStream *js = user_data; @@ -200,10 +117,7 @@ xmlnode_insert_data(js->current, text, text_len); } -#endif /* HAVE_LIBXML */ - -#ifdef HAVE_LIBXML static xmlSAXHandler jabber_parser_libxml = { .internalSubset = NULL, .isStandalone = NULL, @@ -238,20 +152,10 @@ .endElementNs = jabber_parser_element_end_libxml, .serror = NULL }; -#else -static GMarkupParser jabber_parser = { - jabber_parser_element_start, - jabber_parser_element_end, - jabber_parser_element_text, - NULL, - NULL -}; -#endif void jabber_parser_setup(JabberStream *js) { -#ifdef HAVE_LIBXML /* This seems backwards, but it makes sense. The libxml code creates the parser * context when you try to use it (this way, it can figure out the encoding at * creation time. So, setting up the parser is just a matter of destroying any @@ -261,24 +165,11 @@ xmlFreeParserCtxt(js->context); js->context = NULL; } -#else - if(!js->context) - js->context = g_markup_parse_context_new(&jabber_parser, 0, js, NULL); -#endif } void jabber_parser_process(JabberStream *js, const char *buf, int len) { - -#ifndef HAVE_LIBXML - /* May need to check for other encodings and do the conversion here */ - if(!g_markup_parse_context_parse(js->context, buf, len, NULL)) { - g_markup_parse_context_free(js->context); - js->context = NULL; - gaim_connection_error(js->gc, _("XML Parse error")); - } -#else if (js->context == NULL) { /* libxml inconsistently starts parsing on creating the parser, so so a ParseChunk * right afterwards to force it. */ @@ -286,6 +177,5 @@ } else if (xmlParseChunk(js->context, buf, len, 0) < 0) { gaim_connection_error(js->gc, _("XML Parse error")); } -#endif } diff -r 9c6533500fff -r 289490ee84d1 libgaim/xmlnode.c --- a/libgaim/xmlnode.c Mon Sep 04 03:23:41 2006 +0000 +++ b/libgaim/xmlnode.c Mon Sep 04 03:55:12 2006 +0000 @@ -29,9 +29,7 @@ #include "internal.h" -#ifdef HAVE_LIBXML #include -#endif #include #include @@ -181,25 +179,17 @@ void xmlnode_set_namespace(xmlnode *node, const char *xmlns) { -#ifdef HAVE_LIBXML g_return_if_fail(node != NULL); g_free(node->namespace); node->namespace = g_strdup(xmlns); -#else - xmlnode_set_attrib(node, "xmlns", xmlns); -#endif } const char *xmlnode_get_namespace(xmlnode *node) { -#ifdef HAVE_LIBXML g_return_val_if_fail(node != NULL, NULL); return node->namespace; -#else - return xmlnode_get_attrib(node, "xmlns"); -#endif } void @@ -218,9 +208,7 @@ g_free(node->name); g_free(node->data); -#ifdef HAVE_LIBXML g_free(node->namespace); -#endif GAIM_DBUS_UNREGISTER_POINTER(node); g_free(node); @@ -305,13 +293,11 @@ node_name = g_markup_escape_text(node->name, -1); g_string_append_printf(text, "<%s", node_name); -#ifdef HAVE_LIBXML if (node->namespace) { char *namespace = g_markup_escape_text(node->namespace, -1); g_string_append_printf(text, " xmlns='%s'", namespace); g_free(namespace); } -#endif for(c = node->child; c; c = c->next) { if(c->type == XMLNODE_TYPE_ATTRIB) { @@ -386,7 +372,6 @@ xmlnode *current; }; -#ifdef HAVE_LIBXML static void xmlnode_parser_element_start_libxml(void *user_data, const xmlChar *element_name, const xmlChar *prefix, const xmlChar *namespace, @@ -408,18 +393,14 @@ xmlnode_set_namespace(node, namespace); for(i=0; i < nb_attributes * 5; i+=5) { -#ifdef HAVE_LIBXML char *txt; -#endif int attrib_len = attributes[i+4] - attributes[i+3]; char *attrib = g_malloc(attrib_len + 1); memcpy(attrib, attributes[i+3], attrib_len); attrib[attrib_len] = '\0'; -#ifdef HAVE_LIBXML txt = attrib; attrib = gaim_unescape_html(txt); g_free(txt); -#endif xmlnode_set_attrib(node, attributes[i], attrib); g_free(attrib); } @@ -457,64 +438,6 @@ xmlnode_insert_data(xpd->current, text, text_len); } -#else - -static void -xmlnode_parser_element_start(GMarkupParseContext *context, - const char *element_name, const char **attrib_names, - const char **attrib_values, gpointer user_data, GError **error) -{ - struct _xmlnode_parser_data *xpd = user_data; - xmlnode *node; - int i; - - if(!element_name) { - return; - } else { - if(xpd->current) - node = xmlnode_new_child(xpd->current, element_name); - else - node = xmlnode_new(element_name); - - for(i=0; attrib_names[i]; i++) - xmlnode_set_attrib(node, attrib_names[i], attrib_values[i]); - - xpd->current = node; - } -} - -static void -xmlnode_parser_element_end(GMarkupParseContext *context, - const char *element_name, gpointer user_data, GError **error) -{ - struct _xmlnode_parser_data *xpd = user_data; - - if(!element_name || !xpd->current) - return; - - if(xpd->current->parent) { - if(!strcmp(xpd->current->name, element_name)) - xpd->current = xpd->current->parent; - } -} - -static void -xmlnode_parser_element_text(GMarkupParseContext *context, const char *text, - gsize text_len, gpointer user_data, GError **error) -{ - struct _xmlnode_parser_data *xpd = user_data; - - if(!xpd->current) - return; - - if(!text || !text_len) - return; - - xmlnode_insert_data(xpd->current, text, text_len); -} -#endif - -#ifdef HAVE_LIBXML static xmlSAXHandler xmlnode_parser_libxml = { .internalSubset = NULL, .isStandalone = NULL, @@ -549,24 +472,12 @@ .endElementNs = xmlnode_parser_element_end_libxml, .serror = NULL }; -#else -static GMarkupParser xmlnode_parser = { - xmlnode_parser_element_start, - xmlnode_parser_element_end, - xmlnode_parser_element_text, - NULL, - NULL -}; -#endif xmlnode * xmlnode_from_str(const char *str, gssize size) { struct _xmlnode_parser_data *xpd; xmlnode *ret; -#ifndef HAVE_LIBXML - GMarkupParseContext *context; -#endif gsize real_size; g_return_val_if_fail(str != NULL, NULL); @@ -574,7 +485,6 @@ real_size = size < 0 ? strlen(str) : size; xpd = g_new0(struct _xmlnode_parser_data, 1); -#ifdef HAVE_LIBXML if (xmlSAXUserParseMemory(&xmlnode_parser_libxml, xpd, str, real_size) < 0) { while(xpd->current && xpd->current->parent) xpd->current = xpd->current->parent; @@ -582,18 +492,6 @@ xmlnode_free(xpd->current); xpd->current = NULL; } -#else - context = g_markup_parse_context_new(&xmlnode_parser, 0, xpd, NULL); - - if(!g_markup_parse_context_parse(context, str, real_size, NULL)) { - while(xpd->current && xpd->current->parent) - xpd->current = xpd->current->parent; - if(xpd->current) - xmlnode_free(xpd->current); - xpd->current = NULL; - } - g_markup_parse_context_free(context); -#endif ret = xpd->current; g_free(xpd); return ret; diff -r 9c6533500fff -r 289490ee84d1 libgaim/xmlnode.h --- a/libgaim/xmlnode.h Mon Sep 04 03:23:41 2006 +0000 +++ b/libgaim/xmlnode.h Mon Sep 04 03:55:12 2006 +0000 @@ -42,9 +42,7 @@ struct _xmlnode { char *name; /**< The name of the node. */ -#ifdef HAVE_LIBXML char *namespace; /**< The namespace of the node */ -#endif XMLNodeType type; /**< The type of the node. */ char *data; /**< The data for the node. */ size_t data_sz; /**< The size of the data. */