Only allow one <namespace/> element per <repository/> (#560419)
authorOwen Taylor <otaylor@src.gnome.org>
Wed, 12 Nov 2008 17:16:49 +0000 (17:16 +0000)
committerOwen Taylor <otaylor@src.gnome.org>
Wed, 12 Nov 2008 17:16:49 +0000 (17:16 +0000)
The logic in girparser.c didn't work very well if there were multiple
<namespace/> nodes within a single <repository/> (context->namespace
was always the overall filename and not the the name specified in the
<namespace/> element for one thing; this would cause aliases to
be mis-prefixed in include modules.) Also check that the "name" in
the <namespace/> node matches the filename.

svn path=/trunk/; revision=902

ChangeLog
girepository/girparser.c

index 73355ee..e8e4c60 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,24 @@
+2008-11-12  Owen Taylor  <otaylor@redhat.com>
+
+       Only allow one <namespace/> element per <repository/> (#560419)
+
+       * girepository/girparser.c: The logic in girparser.c didn't work
+       very well if there were multiple <namespace/> nodes within a
+       single <repository/> (context->namespace was always the overall
+       filename and not the the name specified in the <namespace/>
+       element for one thing; this would cause aliases to be mis-prefixed
+       in include modules.) Also check that the "name" in the
+       <namespace/> node matches the filename.
+
+2008-11-12  Owen Taylor  <otaylor@redhat.com>
+
+       Add a GirParser object to hold the state of a compilation
+
+       * girepository/girparser.[ch] tools/compiler.c: Add a toplevel
+       GirParser object to hold state that is global across a
+       compilation. Currently just holds the include path, but will
+       eventually also keep a cached list of parsed modules.
+
 2008-11-12  Tommi Komulainen  <tommi.komulainen@iki.fi>
 
        * girepository/girepository.c (find_namespace_latest): Fix
index e41d696..6601fcc 100644 (file)
@@ -2457,7 +2457,16 @@ start_element_handler (GMarkupParseContext *context,
       if (strcmp (element_name, "namespace") == 0 && ctx->state == STATE_REPOSITORY)
        {
          const gchar *name, *version, *shared_library;
-         
+
+         if (ctx->current_module != NULL)
+           {
+             g_set_error (error,
+                          G_MARKUP_ERROR,
+                          G_MARKUP_ERROR_INVALID_CONTENT,
+                          "Only one <namespace/> element is currently allowed per <repository/>");
+             goto out;
+           }
+
          name = find_attribute ("name", attribute_names, attribute_values);
          version = find_attribute ("version", attribute_names, attribute_values);
          shared_library = find_attribute ("shared-library", attribute_names, attribute_values);
@@ -2468,6 +2477,13 @@ start_element_handler (GMarkupParseContext *context,
            MISSING_ATTRIBUTE (context, error, element_name, "version");
          else
            {
+             if (strcmp (name, ctx->namespace) != 0)
+               g_set_error (error,
+                            G_MARKUP_ERROR,
+                            G_MARKUP_ERROR_INVALID_CONTENT,
+                            "<namespace/> name element '%s' doesn't match file name '%s'",
+                            name, ctx->namespace);
+
              ctx->current_module = g_ir_module_new (name, version, shared_library);
              ctx->modules = g_list_append (ctx->modules, ctx->current_module);
              ctx->current_module->dependencies = ctx->dependencies;
@@ -3073,6 +3089,7 @@ g_ir_parser_parse_file (GIrParser   *parser,
   GList *modules;
   GList *iter;
   const char *slash;
+  char *dash;
   char *namespace;
 
   if (!g_str_has_suffix (filename, ".gir"))
@@ -3093,6 +3110,11 @@ g_ir_parser_parse_file (GIrParser   *parser,
     namespace = g_strdup (slash+1);
   namespace[strlen(namespace)-4] = '\0';
 
+  /* Remove version */
+  dash = strstr (namespace, "-");
+  if (dash != NULL)
+    *dash = '\0';
+
   if (!g_file_get_contents (filename, &buffer, &length, error))
     return NULL;