2008-02-26 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / metadata / mono-config.c
index 6b3033f2f49856ca0f8fb234adc0a6e1fb1763e0..0dc6bd9698d833c1f645d45d71abb0ab39a09d75 100644 (file)
@@ -15,6 +15,7 @@
 #include "mono/metadata/loader.h"
 #include "mono/metadata/mono-config.h"
 #include "mono/metadata/metadata-internals.h"
+#include "mono/metadata/object-internals.h"
 #include "mono/utils/mono-logger.h"
 
 #if defined(__linux__)
@@ -289,6 +290,31 @@ dllmap_handler = {
        dllmap_finish
 };
 
+static void
+legacyUEP_start (gpointer user_data, 
+              const gchar         *element_name,
+              const gchar        **attribute_names,
+              const gchar        **attribute_values) {
+       if ((strcmp (element_name, "legacyUnhandledExceptionPolicy") == 0) &&
+                       (attribute_names [0] != NULL) &&
+                       (strcmp (attribute_names [0], "enabled") == 0)) {
+               if ((strcmp (attribute_values [0], "1") == 0) ||
+                               (g_strcasecmp (attribute_values [0], "true") == 0)) {
+                       mono_runtime_unhandled_exception_policy_set (MONO_UNHANLED_POLICY_LEGACY);
+               }
+       }
+}
+
+static const MonoParseHandler
+legacyUEP_handler = {
+       "legacyUnhandledExceptionPolicy",
+       NULL, /* init */
+       legacyUEP_start,
+       NULL, /* text */
+       NULL, /* end */
+       NULL, /* finish */
+};
+
 static int inited = 0;
 
 static void
@@ -297,6 +323,7 @@ mono_config_init (void)
        inited = 1;
        config_handlers = g_hash_table_new (g_str_hash, g_str_equal);
        g_hash_table_insert (config_handlers, (gpointer) dllmap_handler.element_name, (gpointer) &dllmap_handler);
+       g_hash_table_insert (config_handlers, (gpointer) legacyUEP_handler.element_name, (gpointer) &legacyUEP_handler);
 }
 
 /* FIXME: error handling */
@@ -382,6 +409,8 @@ struct _BundledConfig {
 
 static BundledConfig *bundled_configs = NULL;
 
+static const char *bundled_machine_config = NULL;
+
 void
 mono_register_config_for_assembly (const char* assembly_name, const char* config_xml)
 {
@@ -394,21 +423,32 @@ mono_register_config_for_assembly (const char* assembly_name, const char* config
        bundled_configs = bconfig;
 }
 
+const char *
+mono_config_string_for_assembly_file (const char *filename)
+{
+       BundledConfig *bconfig;
+       
+       for (bconfig = bundled_configs; bconfig; bconfig = bconfig->next) {
+               if (bconfig->aname && strcmp (bconfig->aname, filename) == 0)
+                       return bconfig->config_xml;
+       }
+       return NULL;
+}
+
 void 
 mono_config_for_assembly (MonoImage *assembly)
 {
        ParseState state = {NULL};
        int got_it = 0, i;
        char *aname, *cfg, *cfg_name;
+       const char *bundled_config;
        const char *home;
-       BundledConfig *bconfig;
        
        state.assembly = assembly;
 
-       for (bconfig = bundled_configs; bconfig; bconfig = bconfig->next) {
-               if (bconfig->aname && strcmp (bconfig->aname, assembly->module_name) == 0)
-                       mono_config_parse_xml_with_context (&state, bconfig->config_xml, strlen (bconfig->config_xml));
-       }
+       bundled_config = mono_config_string_for_assembly_file (assembly->module_name);
+       if (bundled_config)
+               mono_config_parse_xml_with_context (&state, bundled_config, strlen (bundled_config));
 
        cfg_name = g_strdup_printf ("%s.config", mono_image_get_filename (assembly));
        mono_config_parse_file_with_context (&state, cfg_name);
@@ -494,6 +534,18 @@ mono_get_config_dir (void)
        return mono_cfg_dir;
 }
 
+void
+mono_register_machine_config (const char *config_xml)
+{
+       bundled_machine_config = config_xml;
+}
+
+const char *
+mono_get_machine_config (void)
+{
+       return bundled_machine_config;
+}
+
 static void
 publisher_policy_start (gpointer user_data,
                const gchar *element_name,