dbus/bus config-parser.c,1.28,1.29

Jon Trowbridge trow at pdx.freedesktop.org
Mon Apr 12 18:37:59 PDT 2004


Update of /cvs/dbus/dbus/bus
In directory pdx:/tmp/cvs-serv20087/bus

Modified Files:
	config-parser.c 
Log Message:
2004-04-12  Jon Trowbridge  <trow at ximian.com>

	    * bus/config-parser.c (struct BusConfigParser): Added
	    included_files field.
	    (seen_include): Added.  Checks whether or not a file has already
	    been included by any parent BusConfigParser.
	    (bus_config_parser_new): Copy the parent's included_files.
	    (include_file): Track which files have been included, and fail on
	    circular inclusions.
	    (process_test_valid_subdir): Changed printf to report if we are
	    testing valid or invalid conf files.
	    (all_are_equiv): Changed printf to be a bit clearer about
	    what we are actually doing.
	    (bus_config_parser_test): Test invalid configuration files.



Index: config-parser.c
===================================================================
RCS file: /cvs/dbus/dbus/bus/config-parser.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- a/config-parser.c	9 Apr 2004 19:50:29 -0000	1.28
+++ b/config-parser.c	13 Apr 2004 01:37:57 -0000	1.29
@@ -115,6 +115,8 @@
 
   char *pidfile;         /**< PID file */
 
+  DBusList *included_files;  /**< Included files stack */
+
   unsigned int fork : 1; /**< TRUE to fork into daemon mode */
 
   unsigned int is_toplevel : 1; /**< FALSE if we are a sub-config-file inside another one */
@@ -277,6 +279,24 @@
   return TRUE;
 }
 
+static dbus_bool_t
+seen_include (BusConfigParser  *parser,
+	      const DBusString *file)
+{
+  DBusList *iter;
+
+  iter = parser->included_files;
+  while (iter != NULL)
+    {
+      if (! strcmp (_dbus_string_get_const_data (file), iter->data))
+	return TRUE;
+
+      iter = _dbus_list_get_next_link (&parser->included_files, iter);
+    }
+
+  return FALSE;
+}
+
 BusConfigParser*
 bus_config_parser_new (const DBusString      *basedir,
                        dbus_bool_t            is_toplevel,
@@ -311,6 +331,10 @@
     {
       /* Initialize the parser's limits from the parent. */
       parser->limits = parent->limits;
+
+      /* Use the parent's list of included_files to avoid
+	 circular inclusions. */
+      parser->included_files = parent->included_files;
     }
   else
     {
@@ -403,7 +427,7 @@
 
       if (parser->policy)
         bus_policy_unref (parser->policy);
-      
+
       dbus_free (parser);
     }
 }
@@ -1635,14 +1659,34 @@
    * that the result is the same
    */
   BusConfigParser *included;
+  const char *filename_str;
   DBusError tmp_error;
         
   dbus_error_init (&tmp_error);
 
+  filename_str = _dbus_string_get_const_data (filename);
+
+  /* Check to make sure this file hasn't already been included. */
+  if (seen_include (parser, filename))
+    {
+      dbus_set_error (error, DBUS_ERROR_FAILED,
+		      "Circular inclusion of file '%s'",
+		      filename_str);
+      return FALSE;
+    }
+  
+  if (! _dbus_list_append (&parser->included_files, (void *) filename_str))
+    {
+      BUS_SET_OOM (error);
+      return FALSE;
+    }
+
   /* Since parser is passed in as the parent, included
      inherits parser's limits. */
   included = bus_config_load (filename, FALSE, parser, &tmp_error);
 
+  _dbus_list_pop_last (&parser->included_files);
+
   if (included == NULL)
     {
       _DBUS_ASSERT_ERROR_IS_SET (&tmp_error);
@@ -2207,7 +2251,12 @@
       goto failed;
     }
 
-  printf ("Testing:\n");
+  if (validity == VALID)
+    printf ("Testing valid files:\n");
+  else if (validity == INVALID)
+    printf ("Testing invalid files:\n");
+  else
+    printf ("Testing unknown files:\n");
 
  next:
   while (_dbus_directory_get_next_file (dir, &filename, &error))
@@ -2458,7 +2507,7 @@
       goto finished;
     }
 
-  printf ("Comparing:\n");
+  printf ("Comparing equivalent files:\n");
 
  next:
   while (_dbus_directory_get_next_file (dir, &filename, &error))
@@ -2612,6 +2661,9 @@
   if (!process_test_valid_subdir (test_data_dir, "valid-config-files", VALID))
     return FALSE;
 
+  if (!process_test_valid_subdir (test_data_dir, "invalid-config-files", INVALID))
+    return FALSE;
+
   if (!process_test_equiv_subdir (test_data_dir, "equiv-config-files"))
     return FALSE;
 




More information about the dbus-commit mailing list