New tests.
[mono.git] / mono / metadata / mono-config.c
1 /*
2  * mono-config.c
3  *
4  * Runtime and assembly configuration file support routines.
5  *
6  * Author: Paolo Molaro (lupus@ximian.com)
7  *
8  * Copyright 2002-2003 Ximian, Inc (http://www.ximian.com)
9  * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
10  */
11 #include "config.h"
12 #include <glib.h>
13 #include <string.h>
14
15 #include "mono/metadata/assembly.h"
16 #include "mono/metadata/loader.h"
17 #include "mono/metadata/mono-config.h"
18 #include "mono/metadata/metadata-internals.h"
19 #include "mono/metadata/object-internals.h"
20 #include "mono/utils/mono-logger-internal.h"
21
22 #if defined(TARGET_PS3)
23 #define CONFIG_OS "CellOS"
24 #elif defined(__linux__)
25 #define CONFIG_OS "linux"
26 #elif defined(__APPLE__)
27 #define CONFIG_OS "osx"
28 #elif defined(sun)
29 #define CONFIG_OS "solaris"
30 #elif defined(__FreeBSD__)
31 #define CONFIG_OS "freebsd"
32 #elif defined(__NetBSD__)
33 #define CONFIG_OS "netbsd"
34 #elif defined(__OpenBSD__)
35 #define CONFIG_OS "openbsd"
36 #elif defined(__WIN32__)
37 #define CONFIG_OS "windows"
38 #elif defined(_IBMR2)
39 #define CONFIG_OS "aix"
40 #elif defined(__hpux)
41 #define CONFIG_OS "hpux"
42 #elif defined(__HAIKU__)
43 #define CONFIG_OS "haiku"
44 #else
45 #warning Unknown operating system
46 #define CONFIG_OS "unknownOS"
47 #endif
48
49 #ifndef CONFIG_CPU
50 #if defined(__i386__)
51 #define CONFIG_CPU "x86"
52 #define CONFIG_WORDSIZE "32"
53 #elif defined(__x86_64__)
54 #define CONFIG_CPU "x86-64"
55 #define CONFIG_WORDSIZE "64"
56 #elif defined(sparc) || defined(__sparc__)
57 #define CONFIG_CPU "sparc"
58 #define CONFIG_WORDSIZE "32"
59 #elif defined(__ppc64__) || defined(__powerpc64__) || defined(TARGET_POWERPC)
60 #define CONFIG_WORDSIZE "64"
61 #ifdef __mono_ppc_ilp32__ 
62 #   define CONFIG_CPU "ppc64ilp32"
63 #else
64 #   define CONFIG_CPU "ppc64"
65 #endif
66 #elif defined(__ppc__) || defined(__powerpc__)
67 #define CONFIG_CPU "ppc"
68 #define CONFIG_WORDSIZE "32"
69 #elif defined(__s390x__)
70 #define CONFIG_CPU "s390x"
71 #define CONFIG_WORDSIZE "64"
72 #elif defined(__s390__)
73 #define CONFIG_CPU "s390"
74 #define CONFIG_WORDSIZE "32"
75 #elif defined(__arm__)
76 #define CONFIG_CPU "arm"
77 #define CONFIG_WORDSIZE "32"
78 #elif defined(__ia64__)
79 #define CONFIG_CPU "ia64"
80 #define CONFIG_WORDSIZE "64"
81 #elif defined(__alpha__)
82 #define CONFIG_CPU "alpha"
83 #define CONFIG_WORDSIZE "64"
84 #elif defined(hppa) || defined(__hppa__)
85 #define CONFIG_CPU "hppa"
86 #define CONFIG_WORDSIZE "32"
87 #elif defined(mips) || defined(__mips) || defined(_mips)
88 #define CONFIG_CPU "mips"
89 #define CONFIG_WORDSIZE "32"
90 #else
91 #error Unknown CPU
92 #define CONFIG_CPU "unknownCPU"
93 #endif
94 #endif
95
96 static void start_element (GMarkupParseContext *context, 
97                            const gchar         *element_name,
98                            const gchar        **attribute_names,
99                            const gchar        **attribute_values,
100                            gpointer             user_data,
101                            GError             **error);
102
103 static void end_element   (GMarkupParseContext *context,
104                            const gchar         *element_name,
105                            gpointer             user_data,
106                            GError             **error);
107
108 static void parse_text    (GMarkupParseContext *context,
109                            const gchar         *text,
110                            gsize                text_len,
111                            gpointer             user_data,
112                            GError             **error);
113
114 static void passthrough   (GMarkupParseContext *context,
115                            const gchar         *text,
116                            gsize                text_len,
117                            gpointer             user_data,
118                            GError             **error);
119
120 static void parse_error   (GMarkupParseContext *context,
121                            GError              *error,
122                            gpointer             user_data);
123
124 static const GMarkupParser 
125 mono_parser = {
126         start_element,
127         end_element,
128         parse_text,
129         passthrough,
130         parse_error
131 };
132
133 static GHashTable *config_handlers;
134
135 /* when this interface is stable, export it. */
136 typedef struct MonoParseHandler MonoParseHandler;
137
138 struct MonoParseHandler {
139         const char *element_name;
140         void*(*init)   (MonoImage *assembly);
141         void (*start)  (gpointer user_data, const gchar *name,
142                         const gchar **attributes,
143                         const gchar **values);
144         void (*text)   (gpointer user_data, const char *text, gsize test_len);
145         void (*end)    (gpointer user_data, const char *name);
146         void (*finish) (gpointer user_data);
147 };
148
149 typedef struct {
150         MonoAssemblyBindingInfo *info;
151         void (*info_parsed)(MonoAssemblyBindingInfo *info, void *user_data);
152         void *user_data;
153 } ParserUserData;
154
155 typedef struct {
156         MonoParseHandler *current;
157         void *user_data;
158         MonoImage *assembly;
159         int inited;
160 } ParseState;
161
162 static void start_element (GMarkupParseContext *context, 
163                            const gchar         *element_name,
164                            const gchar        **attribute_names,
165                            const gchar        **attribute_values,
166                            gpointer             user_data,
167                            GError             **error)
168 {
169         ParseState *state = user_data;
170         if (!state->current) {
171                 state->current = g_hash_table_lookup (config_handlers, element_name);
172                 if (state->current && state->current->init)
173                         state->user_data = state->current->init (state->assembly);
174         }
175         if (state->current && state->current->start)
176                 state->current->start (state->user_data, element_name, attribute_names, attribute_values);
177 }
178
179 static void end_element   (GMarkupParseContext *context,
180                            const gchar         *element_name,
181                            gpointer             user_data,
182                            GError             **error)
183 {
184         ParseState *state = user_data;
185         if (state->current) {
186                 if (state->current->end)
187                         state->current->end (state->user_data, element_name);
188                 if (strcmp (state->current->element_name, element_name) == 0) {
189                         if (state->current->finish)
190                                 state->current->finish (state->user_data);
191                         state->current = NULL;
192                         state->user_data = NULL;
193                 }
194         }
195 }
196
197 static void parse_text    (GMarkupParseContext *context,
198                            const gchar         *text,
199                            gsize                text_len,
200                            gpointer             user_data,
201                            GError             **error)
202 {
203         ParseState *state = user_data;
204         if (state->current && state->current->text)
205                 state->current->text (state->user_data, text, text_len);
206 }
207
208 static void passthrough   (GMarkupParseContext *context,
209                            const gchar         *text,
210                            gsize                text_len,
211                            gpointer             user_data,
212                            GError             **error)
213 {
214         /* do nothing */
215 }
216
217 static void parse_error   (GMarkupParseContext *context,
218                            GError              *error,
219                            gpointer             user_data)
220 {
221         ParseState *state = user_data;
222         const gchar *msg;
223         const gchar *filename;
224
225         filename = state && state->user_data ? (gchar *) state->user_data : "<unknown>";
226         msg = error && error->message ? error->message : "";
227         g_warning ("Error parsing %s: %s", filename, msg);
228 }
229
230 static int
231 arch_matches (const char* arch, const char *value)
232 {
233         char **splitted, **p;
234         int found = FALSE;
235         if (value [0] == '!')
236                 return !arch_matches (arch, value + 1);
237         p = splitted = g_strsplit (value, ",", 0);
238         while (*p) {
239                 if (strcmp (arch, *p) == 0) {
240                         found = TRUE;
241                         break;
242                 }
243                 p++;
244         }
245         g_strfreev (splitted);
246         return found;
247 }
248
249 typedef struct {
250         char *dll;
251         char *target;
252         int ignore;
253         MonoImage *assembly;
254 } DllInfo;
255
256 static void*
257 dllmap_init (MonoImage *assembly) {
258         DllInfo *info = g_new0 (DllInfo, 1);
259         info->assembly = assembly;
260         return info;
261 }
262
263 static void
264 dllmap_start (gpointer user_data, 
265               const gchar         *element_name,
266               const gchar        **attribute_names,
267               const gchar        **attribute_values)
268 {
269         int i;
270         DllInfo *info = user_data;
271         
272         if (strcmp (element_name, "dllmap") == 0) {
273                 g_free (info->dll);
274                 g_free (info->target);
275                 info->dll = info->target = NULL;
276                 info->ignore = FALSE;
277                 for (i = 0; attribute_names [i]; ++i) {
278                         if (strcmp (attribute_names [i], "dll") == 0)
279                                 info->dll = g_strdup (attribute_values [i]);
280                         else if (strcmp (attribute_names [i], "target") == 0)
281                                 info->target = g_strdup (attribute_values [i]);
282                         else if (strcmp (attribute_names [i], "os") == 0 && !arch_matches (CONFIG_OS, attribute_values [i]))
283                                 info->ignore = TRUE;
284                         else if (strcmp (attribute_names [i], "cpu") == 0 && !arch_matches (CONFIG_CPU, attribute_values [i]))
285                                 info->ignore = TRUE;
286                         else if (strcmp (attribute_names [i], "wordsize") == 0 && !arch_matches (CONFIG_WORDSIZE, attribute_values [i]))
287                                 info->ignore = TRUE;
288                 }
289                 if (!info->ignore)
290                         mono_dllmap_insert (info->assembly, info->dll, NULL, info->target, NULL);
291         } else if (strcmp (element_name, "dllentry") == 0) {
292                 const char *name = NULL, *target = NULL, *dll = NULL;
293                 int ignore = FALSE;
294                 for (i = 0; attribute_names [i]; ++i) {
295                         if (strcmp (attribute_names [i], "dll") == 0)
296                                 dll = attribute_values [i];
297                         else if (strcmp (attribute_names [i], "target") == 0)
298                                 target = attribute_values [i];
299                         else if (strcmp (attribute_names [i], "name") == 0)
300                                 name = attribute_values [i];
301                         else if (strcmp (attribute_names [i], "os") == 0 && !arch_matches (CONFIG_OS, attribute_values [i]))
302                                 ignore = TRUE;
303                         else if (strcmp (attribute_names [i], "cpu") == 0 && !arch_matches (CONFIG_CPU, attribute_values [i]))
304                                 ignore = TRUE;
305                         else if (strcmp (attribute_names [i], "wordsize") == 0 && !arch_matches (CONFIG_WORDSIZE, attribute_values [i]))
306                                 ignore = TRUE;
307                 }
308                 if (!dll)
309                         dll = info->dll;
310                 if (!info->ignore && !ignore)
311                         mono_dllmap_insert (info->assembly, info->dll, name, dll, target);
312         }
313 }
314
315 static void
316 dllmap_finish (gpointer user_data)
317 {
318         DllInfo *info = user_data;
319
320         g_free (info->dll);
321         g_free (info->target);
322         g_free (info);
323 }
324
325 static const MonoParseHandler
326 dllmap_handler = {
327         "dllmap",
328         dllmap_init,
329         dllmap_start,
330         NULL, /* text */
331         NULL, /* end */
332         dllmap_finish
333 };
334
335 static void
336 legacyUEP_start (gpointer user_data, 
337               const gchar         *element_name,
338               const gchar        **attribute_names,
339               const gchar        **attribute_values) {
340         if ((strcmp (element_name, "legacyUnhandledExceptionPolicy") == 0) &&
341                         (attribute_names [0] != NULL) &&
342                         (strcmp (attribute_names [0], "enabled") == 0)) {
343                 if ((strcmp (attribute_values [0], "1") == 0) ||
344                                 (g_ascii_strcasecmp (attribute_values [0], "true") == 0)) {
345                         mono_runtime_unhandled_exception_policy_set (MONO_UNHANDLED_POLICY_LEGACY);
346                 }
347         }
348 }
349
350 static const MonoParseHandler
351 legacyUEP_handler = {
352         "legacyUnhandledExceptionPolicy",
353         NULL, /* init */
354         legacyUEP_start,
355         NULL, /* text */
356         NULL, /* end */
357         NULL, /* finish */
358 };
359
360 static int inited = 0;
361
362 static void
363 mono_config_init (void)
364 {
365         inited = 1;
366         config_handlers = g_hash_table_new (g_str_hash, g_str_equal);
367         g_hash_table_insert (config_handlers, (gpointer) dllmap_handler.element_name, (gpointer) &dllmap_handler);
368         g_hash_table_insert (config_handlers, (gpointer) legacyUEP_handler.element_name, (gpointer) &legacyUEP_handler);
369 }
370
371 /* FIXME: error handling */
372
373 static void
374 mono_config_parse_xml_with_context (ParseState *state, const char *text, gsize len)
375 {
376         GMarkupParseContext *context;
377
378         if (!inited)
379                 mono_config_init ();
380
381         context = g_markup_parse_context_new (&mono_parser, 0, state, NULL);
382         if (g_markup_parse_context_parse (context, text, len, NULL)) {
383                 g_markup_parse_context_end_parse (context, NULL);
384         }
385         g_markup_parse_context_free (context);
386 }
387
388 /* If assembly is NULL, parse in the global context */
389 static int
390 mono_config_parse_file_with_context (ParseState *state, const char *filename)
391 {
392         gchar *text;
393         gsize len;
394         gint offset;
395
396         mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_CONFIG,
397                         "Config attempting to parse: '%s'.", filename);
398
399         if (!g_file_get_contents (filename, &text, &len, NULL))
400                 return 0;
401
402
403         offset = 0;
404         if (len > 3 && text [0] == '\xef' && text [1] == (gchar) '\xbb' && text [2] == '\xbf')
405                 offset = 3; /* Skip UTF-8 BOM */
406         if (state->user_data == NULL)
407                 state->user_data = (gpointer) filename;
408         mono_config_parse_xml_with_context (state, text + offset, len - offset);
409         g_free (text);
410         return 1;
411 }
412
413 /**
414  * mono_config_parse_memory:
415  * @buffer: a pointer to an string XML representation of the configuration
416  *
417  * Parses the configuration from a buffer
418  */
419 void
420 mono_config_parse_memory (const char *buffer)
421 {
422         ParseState state = {NULL};
423
424         state.user_data = (gpointer) "<buffer>";
425         mono_config_parse_xml_with_context (&state, buffer, strlen (buffer));
426 }
427
428 static void
429 mono_config_parse_file (const char *filename)
430 {
431         ParseState state = {NULL};
432         state.user_data = (gpointer) filename;
433         mono_config_parse_file_with_context (&state, filename);
434 }
435
436 /* 
437  * use the equivalent lookup code from the GAC when available.
438  * Depending on state, this should give something like:
439  *      aname/version-pubtoken/
440  *      aname/version/
441  *      aname
442  */
443 static char*
444 get_assembly_filename (MonoImage *image, int state)
445 {
446         switch (state) {
447         case 0:
448                 return g_strdup (mono_image_get_name (image));
449         default:
450                 return NULL;
451         }
452 }
453
454 typedef struct _BundledConfig BundledConfig;
455
456 struct _BundledConfig {
457         BundledConfig *next;
458         const char* aname;
459         const char* config_xml;
460 };
461
462 static BundledConfig *bundled_configs = NULL;
463
464 static const char *bundled_machine_config = NULL;
465
466 void
467 mono_register_config_for_assembly (const char* assembly_name, const char* config_xml)
468 {
469         BundledConfig *bconfig;
470
471         bconfig = g_new0 (BundledConfig, 1);
472         bconfig->aname = assembly_name;
473         bconfig->config_xml = config_xml;
474         bconfig->next = bundled_configs;
475         bundled_configs = bconfig;
476 }
477
478 const char *
479 mono_config_string_for_assembly_file (const char *filename)
480 {
481         BundledConfig *bconfig;
482         
483         for (bconfig = bundled_configs; bconfig; bconfig = bconfig->next) {
484                 if (bconfig->aname && strcmp (bconfig->aname, filename) == 0)
485                         return bconfig->config_xml;
486         }
487         return NULL;
488 }
489
490 void 
491 mono_config_for_assembly (MonoImage *assembly)
492 {
493         ParseState state = {NULL};
494         int got_it = 0, i;
495         char *aname, *cfg, *cfg_name;
496         const char *bundled_config;
497         const char *home;
498         
499         state.assembly = assembly;
500
501         bundled_config = mono_config_string_for_assembly_file (assembly->module_name);
502         if (bundled_config) {
503                 state.user_data = (gpointer) "<bundled>";
504                 mono_config_parse_xml_with_context (&state, bundled_config, strlen (bundled_config));
505         }
506
507         cfg_name = g_strdup_printf ("%s.config", mono_image_get_filename (assembly));
508         mono_config_parse_file_with_context (&state, cfg_name);
509         g_free (cfg_name);
510
511         cfg_name = g_strdup_printf ("%s.config", mono_image_get_name (assembly));
512
513         home = g_get_home_dir ();
514
515         for (i = 0; (aname = get_assembly_filename (assembly, i)) != NULL; ++i) {
516                 cfg = g_build_filename (mono_get_config_dir (), "mono", "assemblies", aname, cfg_name, NULL);
517                 got_it += mono_config_parse_file_with_context (&state, cfg);
518                 g_free (cfg);
519
520 #ifdef TARGET_WIN32
521                 cfg = g_build_filename (home, ".mono", "assemblies", aname, cfg_name, NULL);
522                 got_it += mono_config_parse_file_with_context (&state, cfg);
523                 g_free (cfg);
524 #endif
525                 g_free (aname);
526                 if (got_it)
527                         break;
528         }
529         g_free (cfg_name);
530 }
531
532 /**
533  * mono_config_parse:
534  * @filename: the filename to load the configuration variables from.
535  *
536  * Pass a NULL filename to parse the default config files
537  * (or the file in the MONO_CONFIG env var).
538  */
539 void
540 mono_config_parse (const char *filename) {
541         const char *home;
542         char *mono_cfg;
543 #ifndef TARGET_WIN32
544         char *user_cfg;
545 #endif
546
547         if (filename) {
548                 mono_config_parse_file (filename);
549                 return;
550         }
551
552         home = g_getenv ("MONO_CONFIG");
553         if (home) {
554                 mono_config_parse_file (home);
555                 return;
556         }
557
558         mono_cfg = g_build_filename (mono_get_config_dir (), "mono", "config", NULL);
559         mono_config_parse_file (mono_cfg);
560         g_free (mono_cfg);
561
562 #ifndef TARGET_WIN32
563         home = g_get_home_dir ();
564         user_cfg = g_strconcat (home, G_DIR_SEPARATOR_S, ".mono/config", NULL);
565         mono_config_parse_file (user_cfg);
566         g_free (user_cfg);
567 #endif
568 }
569
570 static const char *mono_cfg_dir = NULL;
571
572 /* Invoked during startup */
573 void
574 mono_set_config_dir (const char *dir)
575 {
576         /* If this variable is set, overrides the directory computed */
577         mono_cfg_dir = g_getenv ("MONO_CFG_DIR");
578         if (mono_cfg_dir == NULL)
579                 mono_cfg_dir = g_strdup (dir);
580 }
581
582 const char* 
583 mono_get_config_dir (void)
584 {
585         if (mono_cfg_dir == NULL)
586                 mono_set_dirs (NULL, NULL);
587
588         return mono_cfg_dir;
589 }
590
591 void
592 mono_register_machine_config (const char *config_xml)
593 {
594         bundled_machine_config = config_xml;
595 }
596
597 const char *
598 mono_get_machine_config (void)
599 {
600         return bundled_machine_config;
601 }
602
603 static void
604 assembly_binding_end (gpointer user_data, const char *element_name)
605 {
606         ParserUserData *pud = user_data;
607
608         if (!strcmp (element_name, "dependentAssembly")) {
609                 if (pud->info_parsed && pud->info) {
610                         pud->info_parsed (pud->info, pud->user_data);
611                         g_free (pud->info->name);
612                         g_free (pud->info->culture);
613                 }
614         }
615 }
616
617 static void
618 publisher_policy_start (gpointer user_data,
619                 const gchar *element_name,
620                 const gchar **attribute_names,
621                 const gchar **attribute_values)
622 {
623         ParserUserData *pud;
624         MonoAssemblyBindingInfo *info;
625         int n;
626
627         pud = user_data;
628         info = pud->info;
629         if (!strcmp (element_name, "dependentAssembly")) {
630                 info->name = NULL;
631                 info->culture = NULL;
632                 info->has_old_version_bottom = FALSE;
633                 info->has_old_version_top = FALSE;
634                 info->has_new_version = FALSE;
635                 info->is_valid = FALSE;
636                 memset (&info->old_version_bottom, 0, sizeof (info->old_version_bottom));
637                 memset (&info->old_version_top, 0, sizeof (info->old_version_top));
638                 memset (&info->new_version, 0, sizeof (info->new_version));
639         } if (!strcmp (element_name, "assemblyIdentity")) {
640                 for (n = 0; attribute_names [n]; n++) {
641                         const gchar *attribute_name = attribute_names [n];
642                         
643                         if (!strcmp (attribute_name, "name"))
644                                 info->name = g_strdup (attribute_values [n]);
645                         else if (!strcmp (attribute_name, "publicKeyToken")) {
646                                 if (strlen (attribute_values [n]) == MONO_PUBLIC_KEY_TOKEN_LENGTH - 1)
647                                         g_strlcpy ((char *) info->public_key_token, attribute_values [n], MONO_PUBLIC_KEY_TOKEN_LENGTH);
648                         } else if (!strcmp (attribute_name, "culture")) {
649                                 if (!strcmp (attribute_values [n], "neutral"))
650                                         info->culture = g_strdup ("");
651                                 else
652                                         info->culture = g_strdup (attribute_values [n]);
653                         }
654                 }
655         } else if (!strcmp (element_name, "bindingRedirect")) {
656                 for (n = 0; attribute_names [n]; n++) {
657                         const gchar *attribute_name = attribute_names [n];
658
659                         if (!strcmp (attribute_name, "oldVersion")) {
660                                 gchar **numbers, **version, **versions;
661                                 gint major, minor, build, revision;
662
663                                 /* Invalid value */
664                                 if (!strcmp (attribute_values [n], ""))
665                                         return;
666                                 
667                                 versions = g_strsplit (attribute_values [n], "-", 2);
668                                 version = g_strsplit (*versions, ".", 4);
669
670                                 /* We assign the values to gint vars to do the checks */
671                                 numbers = version;
672                                 major = *numbers ? atoi (*numbers++) : -1;
673                                 minor = *numbers ? atoi (*numbers++) : -1;
674                                 build = *numbers ? atoi (*numbers++) : -1;
675                                 revision = *numbers ? atoi (*numbers) : -1;
676                                 g_strfreev (version);
677                                 if (major < 0 || minor < 0 || build < 0 || revision < 0) {
678                                         g_strfreev (versions);
679                                         return;
680                                 }
681
682                                 info->old_version_bottom.major = major;
683                                 info->old_version_bottom.minor = minor;
684                                 info->old_version_bottom.build = build;
685                                 info->old_version_bottom.revision = revision;
686                                 info->has_old_version_bottom = TRUE;
687
688                                 if (!*(versions + 1)) {
689                                         g_strfreev (versions);
690                                         continue;
691                                 }
692                                 
693                                 numbers = version = g_strsplit (*(versions + 1), ".", 4);
694                                 major = *numbers ? atoi (*numbers++) : -1;
695                                 minor = *numbers ? atoi (*numbers++) : -1;
696                                 build = *numbers ? atoi (*numbers++) : -1;
697                                 revision = *numbers ? atoi (*numbers) : 1;
698                                 g_strfreev (version);
699                                 if (major < 0 || minor < 0 || build < 0 || revision < 0) {
700                                         g_strfreev (versions);
701                                         return;
702                                 }
703
704                                 info->old_version_top.major = major;
705                                 info->old_version_top.minor = minor;
706                                 info->old_version_top.build = build;
707                                 info->old_version_top.revision = revision;
708                                 info->has_old_version_top = TRUE;
709
710                                 g_strfreev (versions);
711                         } else if (!strcmp (attribute_name, "newVersion")) {
712                                 gchar **numbers, **version;
713
714                                 /* Invalid value */
715                                 if (!strcmp (attribute_values [n], ""))
716                                         return;
717
718                                 numbers = version = g_strsplit (attribute_values [n], ".", 4);
719                                 info->new_version.major = *numbers ? atoi (*numbers++) : -1;
720                                 info->new_version.minor = *numbers ? atoi (*numbers++) : -1;
721                                 info->new_version.build = *numbers ? atoi (*numbers++) : -1;
722                                 info->new_version.revision = *numbers ? atoi (*numbers) : -1;
723                                 info->has_new_version = TRUE;
724                                 g_strfreev (version);
725                         }
726                 }
727         }
728 }
729
730 static MonoParseHandler
731 publisher_policy_parser = {
732         "", /* We don't need to use declare an xml element */
733         NULL,
734         publisher_policy_start,
735         NULL,
736         NULL,
737         NULL
738 };
739
740 void
741 mono_config_parse_publisher_policy (const gchar *filename, MonoAssemblyBindingInfo *info)
742 {
743         ParserUserData user_data = {
744                 info,
745                 NULL,
746                 NULL
747         };
748         ParseState state = {
749                 &publisher_policy_parser, /* MonoParseHandler */
750                 &user_data, /* user_data */
751                 NULL, /* MonoImage (we don't need it right now)*/
752                 TRUE /* We are already inited */
753         };
754         
755         mono_config_parse_file_with_context (&state, filename);
756 }
757
758 static MonoParseHandler
759 config_assemblybinding_parser = {
760         "", /* We don't need to use declare an xml element */
761         NULL,
762         publisher_policy_start,
763         NULL,
764         assembly_binding_end,
765         NULL
766 };
767
768 void
769 mono_config_parse_assembly_bindings (const char *filename, int amajor, int aminor, void *user_data, void (*infocb)(MonoAssemblyBindingInfo *info, void *user_data))
770 {
771         MonoAssemblyBindingInfo info;
772         ParserUserData pud;
773         ParseState state;
774
775         info.major = amajor;
776         info.minor = aminor;
777
778         pud.info = &info;
779         pud.info_parsed = infocb;
780         pud.user_data = user_data;
781
782         state.current = &config_assemblybinding_parser;  /* MonoParseHandler */
783         state.user_data = &pud;
784         state.assembly = NULL; /* MonoImage (we don't need it right now)*/
785         state.inited = TRUE; /* We are already inited */
786
787         mono_config_parse_file_with_context (&state, filename);
788 }
789