Version 0.1.8 from FTP
[asterisk/asterisk.git] / pbx / pbx_config.c
1 /*
2  * Asterisk -- A telephony toolkit for Linux.
3  *
4  * Populate and remember extensions from static config file
5  * 
6  * Copyright (C) 1999, Mark Spencer
7  *
8  * Mark Spencer <markster@linux-support.net>
9  *
10  * This program is free software, distributed under the terms of
11  * the GNU General Public License
12  */
13
14 #include <asterisk/pbx.h>
15 #include <asterisk/config.h>
16 #include <asterisk/module.h>
17 #include <asterisk/logger.h>
18 #include <stdlib.h>
19 #include <stdio.h>
20 #include <string.h>
21 /* For where to put dynamic tables */
22 #include "../asterisk.h"
23
24 static char *dtext = "Text Extension Configuration";
25 static char *config = "extensions.conf";
26
27 static int static_config = 0;
28
29 int unload_module(void)
30 {
31         return 0;
32 }
33
34 int load_module(void)
35 {
36         struct ast_config *cfg;
37         struct ast_variable *v;
38         char *cxt, *ext, *pri, *appl, *data, *tc;
39         struct ast_context *con;
40
41         cfg = ast_load(config);
42         if (cfg) {
43                 /* Use existing config to populate the PBX table */
44                 static_config = ast_true(ast_variable_retrieve(cfg, "general", "static"));
45                 cxt = ast_category_browse(cfg, NULL);
46                 while(cxt) {
47                         /* All categories but "general" are considered contexts */
48                         if (!strcasecmp(cxt, "general")) {
49                                 cxt = ast_category_browse(cfg, cxt);
50                                 continue;
51                         }
52                         if ((con=ast_context_create(cxt))) {
53                                 v = ast_variable_browse(cfg, cxt);
54                                 while(v) {
55                                         if (!strcasecmp(v->name, "exten")) {
56                                                 tc = strdup(v->value);
57                                                 ext = strtok(tc, ",");
58                                                 if (!ext)
59                                                         ext="";
60                                                 pri = strtok(NULL, ",");
61                                                 if (!pri)
62                                                         pri="";
63                                                 appl = strtok(NULL, ",");
64                                                 if (!appl)
65                                                         appl="";
66                                                 data = strtok(NULL, ",");
67                                                 if (!data)
68                                                         data="";
69                                                 if (ast_add_extension2(con, 0, ext, atoi(pri), appl, strdup(data), free)) {
70                                                         ast_log(LOG_WARNING, "Unable to register extension\n");
71                                                 }
72                                                 free(tc);
73                                         } else if(!strcasecmp(v->name, "include")) {
74                                                 if (ast_context_add_include2(con, v->value))
75                                                         ast_log(LOG_WARNING, "Unable to include context '%s' in context '%s'\n", v->value, cxt);
76                                         }
77                                         v = v->next;
78                                 }
79                         }
80                         cxt = ast_category_browse(cfg, cxt);
81                 }
82                 ast_destroy(cfg);
83         }
84         return 0;
85 }
86
87 int usecount(void)
88 {
89         return 0;
90 }
91
92 char *description(void)
93 {
94         return dtext;
95 }
96
97 char *key(void)
98 {
99         return ASTERISK_GPL_KEY;
100 }