]>
Commit | Line | Data |
---|---|---|
31b3e1bb MM |
1 | /* |
2 | * BIRD Internet Routing Daemon -- Configuration File Handling | |
3 | * | |
4 | * (c) 1999 Martin Mares <mj@ucw.cz> | |
5 | * | |
6 | * Can be freely distributed and used under the terms of the GNU GPL. | |
7 | */ | |
8 | ||
9 | #include <setjmp.h> | |
10 | #include <stdarg.h> | |
11 | ||
12 | #include "nest/bird.h" | |
13 | #include "nest/protocol.h" | |
14 | #include "nest/iface.h" | |
15 | #include "lib/resource.h" | |
16 | #include "lib/string.h" | |
17 | #include "conf/conf.h" | |
18 | #include "filter/filter.h" | |
19 | ||
20 | static jmp_buf conf_jmpbuf; | |
21 | ||
22 | struct config *config, *new_config; | |
23 | ||
24 | struct config * | |
25 | config_alloc(byte *name) | |
26 | { | |
27 | pool *p = rp_new(&root_pool, "Config"); | |
28 | linpool *l = lp_new(p, 1024); | |
29 | struct config *c = lp_allocz(l, sizeof(struct config)); | |
30 | ||
31 | c->pool = p; | |
32 | cfg_mem = c->mem = l; | |
33 | init_list(&c->protos); | |
34 | c->file_name = cfg_strdup(name); | |
35 | return c; | |
36 | } | |
37 | ||
38 | int | |
39 | config_parse(struct config *c) | |
40 | { | |
41 | struct proto_config *p; | |
42 | ||
43 | debug("Parsing configuration file <%s>\n", c->file_name); | |
44 | new_config = c; | |
45 | cfg_pool = c->pool; | |
46 | cfg_mem = c->mem; | |
47 | if (setjmp(conf_jmpbuf)) | |
48 | return 0; | |
49 | cf_lex_init(1); | |
50 | cf_lex_init_tables(); | |
51 | protos_preconfig(c); | |
52 | cf_parse(); | |
31b3e1bb MM |
53 | filters_postconfig(); /* FIXME: Do we really need this? */ |
54 | protos_postconfig(c); | |
55 | return 1; | |
56 | } | |
57 | ||
58 | void | |
59 | config_free(struct config *c) | |
60 | { | |
61 | rfree(c->pool); | |
62 | } | |
63 | ||
64 | void | |
65 | config_commit(struct config *c) | |
66 | { | |
67 | config = c; | |
68 | protos_commit(c); | |
69 | } | |
70 | ||
71 | void | |
72 | cf_error(char *msg, ...) | |
73 | { | |
74 | char buf[1024]; | |
75 | va_list args; | |
76 | ||
77 | va_start(args, msg); | |
78 | if (bvsnprintf(buf, sizeof(buf), msg, args) < 0) | |
79 | strcpy(buf, "<bug: error message too long>"); | |
80 | new_config->err_msg = cfg_strdup(buf); | |
81 | new_config->err_lino = conf_lino; | |
82 | longjmp(conf_jmpbuf, 1); | |
83 | } | |
84 | ||
85 | char * | |
86 | cfg_strdup(char *c) | |
87 | { | |
88 | int l = strlen(c) + 1; | |
89 | char *z = cfg_allocu(l); | |
90 | memcpy(z, c, l); | |
91 | return z; | |
92 | } |