From d021cfae6695f0f44102edf758abfc42e2f3c093 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 3 Sep 2003 02:08:25 +0000 Subject: 2003-09-01 Havoc Pennington * glib/dbus-gparser.c: implement * glib/dbus-gobject.c: start implementing skeletons support * configure.in: when disabling checks/assert, also define G_DISABLE_ASSERT and G_DISABLE_CHECKS --- glib/dbus-gloader-expat.c | 254 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 254 insertions(+) create mode 100644 glib/dbus-gloader-expat.c (limited to 'glib/dbus-gloader-expat.c') diff --git a/glib/dbus-gloader-expat.c b/glib/dbus-gloader-expat.c new file mode 100644 index 00000000..050d3532 --- /dev/null +++ b/glib/dbus-gloader-expat.c @@ -0,0 +1,254 @@ +/* -*- mode: C; c-file-style: "gnu" -*- */ +/* dbus-gloader-expat.c expat XML loader + * + * Copyright (C) 2003 Red Hat, Inc. + * + * Licensed under the Academic Free License version 1.2 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +#include "dbus-gparser.h" +#include + +static void* +expat_g_malloc (size_t sz) +{ + return g_malloc (sz); +} + +static void* +expat_g_realloc (void *mem, size_t sz) +{ + return g_realloc (mem, sz); +} + +static XML_Memory_Handling_Suite memsuite = +{ + expat_g_malloc, + expat_g_realloc, + g_free +}; + +typedef struct +{ + Parser *parser; + const char *filename; + GString *content; + GError **error; + gboolean failed; +} ExpatParseContext; + +static dbus_bool_t +process_content (ExpatParseContext *context) +{ + if (context->failed) + return FALSE; + + if (context->content->len > 0) + { + if (!parser_content (context->parser, + context->content->str, + context->content->len, + context->error)) + { + context->failed = TRUE; + return FALSE; + } + g_string_set_size (context->content, 0); + } + + return TRUE; +} + +static void +expat_StartElementHandler (void *userData, + const XML_Char *name, + const XML_Char **atts) +{ + ExpatParseContext *context = userData; + int i; + char **names; + char **values; + + /* Expat seems to suck and can't abort the parse if we + * throw an error. Expat 2.0 is supposed to fix this. + */ + if (context->failed) + return; + + if (!process_content (context)) + return; + + /* "atts" is key, value, key, value, NULL */ + for (i = 0; atts[i] != NULL; ++i) + ; /* nothing */ + + g_assert (i % 2 == 0); + names = g_new0 (char *, i / 2 + 1); + values = g_new0 (char *, i / 2 + 1); + + i = 0; + while (atts[i] != NULL) + { + g_assert (i % 2 == 0); + names [i / 2] = (char*) atts[i]; + values[i / 2] = (char*) atts[i+1]; + + i += 2; + } + + if (!parser_start_element (context->parser, + name, + (const char **) names, + (const char **) values, + context->error)) + { + g_free (names); + g_free (values); + context->failed = TRUE; + return; + } + + g_free (names); + g_free (values); +} + +static void +expat_EndElementHandler (void *userData, + const XML_Char *name) +{ + ExpatParseContext *context = userData; + + if (!process_content (context)) + return; + + if (!parser_end_element (context->parser, + name, + context->error)) + { + context->failed = TRUE; + return; + } +} + +/* s is not 0 terminated. */ +static void +expat_CharacterDataHandler (void *userData, + const XML_Char *s, + int len) +{ + ExpatParseContext *context = userData; + + if (context->failed) + return; + + g_string_append_len (context->content, + s, len); +} + +Parser* +description_load_from_file (const char *filename, + GError **error) +{ + char *contents; + gsize len; + Parser *parser; + + contents = NULL; + if (!g_file_get_contents (filename, &contents, &len, error)) + return NULL; + + parser = description_load_from_string (contents, len, error); + g_free (contents); + + return parser; +} + +Parser* +description_load_from_string (const char *str, + int len, + GError **error) +{ + XML_Parser expat; + ExpatParseContext context; + + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + + expat = NULL; + context.parser = NULL; + context.error = error; + context.failed = FALSE; + + expat = XML_ParserCreate_MM ("UTF-8", &memsuite, NULL); + if (expat == NULL) + g_error ("No memory to create XML parser\n"); + + context.parser = parser_new (); + context.content = g_string_new (NULL); + + XML_SetUserData (expat, &context); + XML_SetElementHandler (expat, + expat_StartElementHandler, + expat_EndElementHandler); + XML_SetCharacterDataHandler (expat, + expat_CharacterDataHandler); + + if (!XML_Parse (expat, str, len, TRUE)) + { + if (context.error != NULL && + *context.error == NULL) + { + enum XML_Error e; + + e = XML_GetErrorCode (expat); + if (e == XML_ERROR_NO_MEMORY) + g_error ("Not enough memory to parse XML document"); + else + g_set_error (error, + G_MARKUP_ERROR, + G_MARKUP_ERROR_PARSE, + "Error in D-BUS description XML, line %d, column %d: %s\n", + XML_GetCurrentLineNumber (expat), + XML_GetCurrentColumnNumber (expat), + XML_ErrorString (e)); + } + + goto failed; + } + + if (context.failed) + goto failed; + + if (!parser_finished (context.parser, error)) + goto failed; + + XML_ParserFree (expat); + g_string_free (context.content, TRUE); + + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + return context.parser; + + failed: + g_return_val_if_fail (error == NULL || *error != NULL, NULL); + + g_string_free (context.content, TRUE); + if (expat) + XML_ParserFree (expat); + if (context.parser) + parser_unref (context.parser); + return NULL; +} -- cgit From 85ab0327d82e4945ad16630e583d8cc68df25a90 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Sun, 7 Sep 2003 23:04:54 +0000 Subject: 2003-09-07 Havoc Pennington * Make Doxygen contented. --- glib/dbus-gloader-expat.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'glib/dbus-gloader-expat.c') diff --git a/glib/dbus-gloader-expat.c b/glib/dbus-gloader-expat.c index 050d3532..149e7117 100644 --- a/glib/dbus-gloader-expat.c +++ b/glib/dbus-gloader-expat.c @@ -43,13 +43,16 @@ static XML_Memory_Handling_Suite memsuite = g_free }; +/** + * Context for Expat parser for introspection data. + */ typedef struct { - Parser *parser; - const char *filename; - GString *content; - GError **error; - gboolean failed; + Parser *parser; /**< The parser for the introspection data */ + const char *filename; /**< The filename being loaded */ + GString *content; /**< The content of the current element */ + GError **error; /**< Error return location */ + gboolean failed; /**< True if parse has failed */ } ExpatParseContext; static dbus_bool_t -- cgit From 583994cb3b7f5562fb7b8c37b4cb0d5af78e4ce2 Mon Sep 17 00:00:00 2001 From: Havoc Pennington Date: Wed, 17 Sep 2003 03:52:07 +0000 Subject: 2003-09-15 Havoc Pennington * dbus/dbus-pending-call.c: add the get/set object data boilerplate as for DBusConnection, etc. Use generic object data for the notify callback. * glib/dbus-gparser.c (parse_node): parse child nodes * tools/dbus-viewer.c: more hacking on the dbus-viewer * glib/dbus-gutils.c (_dbus_gutils_split_path): add a file to contain functions shared between the convenience lib and the installed lib * glib/Makefile.am (libdbus_glib_1_la_LDFLAGS): add -export-symbols-regex to the GLib library * dbus/dbus-object-tree.c (_dbus_object_tree_dispatch_and_unlock): fix the locking in here, and add a default handler for Introspect() that just returns sub-nodes. 2003-09-14 Havoc Pennington * glib/dbus-gthread.c (dbus_g_thread_init): rename to make g_foo rather than gfoo consistent * glib/dbus-gproxy.h: delete for now, move contents to dbus-glib.h, because the include files don't work right since we aren't in the dbus/ subdir. * glib/dbus-gproxy.c (dbus_gproxy_send): finish implementing (dbus_gproxy_end_call): finish (dbus_gproxy_begin_call): finish * glib/dbus-gmain.c (dbus_set_g_error): new * glib/dbus-gobject.c (handle_introspect): include information about child nodes in the introspection * dbus/dbus-connection.c (dbus_connection_list_registered): new function to help in implementation of introspection * dbus/dbus-object-tree.c (_dbus_object_tree_list_registered_and_unlock): new function 2003-09-12 Havoc Pennington * glib/dbus-gidl.h: add common base class for all the foo_info types * tools/dbus-viewer.c: add GTK-based introspection UI thingy similar to kdcop * test/Makefile.am: try test srcdir -ef . in addition to test srcdir = ., one of them should work (yeah lame) * glib/Makefile.am: build the "idl" parser stuff as a convenience library * glib/dbus-gparser.h: make description_load routines return NodeInfo* not Parser* * Makefile.am (SUBDIRS): build test dir after all library dirs * configure.in: add GTK+ detection --- glib/dbus-gloader-expat.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'glib/dbus-gloader-expat.c') diff --git a/glib/dbus-gloader-expat.c b/glib/dbus-gloader-expat.c index 149e7117..01587d21 100644 --- a/glib/dbus-gloader-expat.c +++ b/glib/dbus-gloader-expat.c @@ -163,31 +163,32 @@ expat_CharacterDataHandler (void *userData, s, len); } -Parser* +NodeInfo* description_load_from_file (const char *filename, GError **error) { char *contents; gsize len; - Parser *parser; + NodeInfo *nodes; contents = NULL; if (!g_file_get_contents (filename, &contents, &len, error)) return NULL; - parser = description_load_from_string (contents, len, error); + nodes = description_load_from_string (contents, len, error); g_free (contents); - return parser; + return nodes; } -Parser* +NodeInfo* description_load_from_string (const char *str, int len, GError **error) { XML_Parser expat; ExpatParseContext context; + NodeInfo *nodes; g_return_val_if_fail (error == NULL || *error == NULL, NULL); @@ -242,8 +243,11 @@ description_load_from_string (const char *str, XML_ParserFree (expat); g_string_free (context.content, TRUE); - g_return_val_if_fail (error == NULL || *error == NULL, NULL); - return context.parser; + g_return_val_if_fail (error == NULL || *error == NULL, NULL); + nodes = parser_get_nodes (context.parser); + node_info_ref (nodes); + parser_unref (context.parser); + return nodes; failed: g_return_val_if_fail (error == NULL || *error != NULL, NULL); @@ -255,3 +259,4 @@ description_load_from_string (const char *str, parser_unref (context.parser); return NULL; } + -- cgit