]> git.ipfire.org Git - thirdparty/bird.git/blame - conf/conf.c
If we are compiling with debugging enabled and libefence is available,
[thirdparty/bird.git] / conf / conf.c
CommitLineData
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
20static jmp_buf conf_jmpbuf;
21
22struct config *config, *new_config;
23
24struct config *
25config_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
38int
39config_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
58void
59config_free(struct config *c)
60{
61 rfree(c->pool);
62}
63
64void
65config_commit(struct config *c)
66{
67 config = c;
68 protos_commit(c);
69}
70
71void
72cf_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
85char *
86cfg_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}