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
42         cfg = ast_load(config);
43         if (cfg) {
44                 /* Use existing config to populate the PBX table */
45                 static_config = ast_true(ast_variable_retrieve(cfg, "general", "static"));
46                 cxt = ast_category_browse(cfg, NULL);
47                 while(cxt) {
48                         /* All categories but "general" are considered contexts */
49                         if (!strcasecmp(cxt, "general")) {
50                                 cxt = ast_category_browse(cfg, cxt);
51                                 continue;
52                         }
53                         if ((con=ast_context_create(cxt))) {
54                                 v = ast_variable_browse(cfg, cxt);
55                                 while(v) {
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                                         v = v->next;
73                                         free(tc);
74                                 }
75                         }
76                         cxt = ast_category_browse(cfg, cxt);
77                 }
78                 ast_destroy(cfg);
79         }
80         return 0;
81 }
82
83 int usecount(void)
84 {
85         return 0;
86 }
87
88 char *description(void)
89 {
90         return dtext;
91 }