GSM BS: Release all calls in case the connection to OpenBSC disappears
[lcr.git] / gsm_conf.c
1 /*****************************************************************************\
2 **                                                                           **
3 ** PBX4Linux                                                                 **
4 **                                                                           **
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg                                              **
7 **                                                                           **
8 ** reading options.conf and filling structure                                **
9 **                                                                           **
10 \*****************************************************************************/ 
11
12 #include "main.h"
13
14
15 /* read options
16  *
17  * read options from options.conf
18  */
19 int gsm_conf(struct gsm_conf *gsm_conf, char *conf_error)
20 {
21         FILE *fp=NULL;
22         char filename[128];
23         char *p;
24         char option[32];
25         char params[11][256];
26         int pnum;
27         unsigned int line,i;
28         char buffer[256];
29
30         /* set defaults */
31         SCPY(gsm_conf->debug, "");
32         SCPY(gsm_conf->hlr, "hlr.sqlite3");
33         SCPY(gsm_conf->openbsc_cfg, "openbsc.cfg");
34         gsm_conf->reject_cause = 0;
35         gsm_conf->keep_l2 = 0;
36
37         SPRINT(filename, "%s/gsm.conf", CONFIG_DATA);
38
39         if (!(fp=fopen(filename,"r"))) {
40                 UPRINT(conf_error, "Cannot open %s\n",filename);
41                 return(0);
42         }
43
44         line=0;
45         while((GETLINE(buffer, fp))) {
46                 line++;
47                 p=buffer;
48
49                 while(*p <= 32) { /* skip spaces */
50                         if (*p == 0)
51                                 break;
52                         p++;
53                 }
54                 if (*p==0 || *p=='#') /* ignore comments and empty line */
55                         continue;
56
57                 option[0]=0;
58                 i=0; /* read option */
59                 while(*p > 32) {
60                         if (i+1 >= sizeof(option)) {
61                                 UPRINT(conf_error, "Error in %s (line %d): option too long.\n",filename,line);
62                                 goto error;
63                         }
64                         option[i+1] = '\0';
65                         option[i++] = *p++;
66                 }
67
68                 while(*p <= 32) { /* skip spaces */
69                         if (*p == 0)
70                                 break;
71                         p++;
72                 }
73
74                 params[0][0] = 0;
75                 pnum = 0;
76                 while(*p!=0 && *p!='#' && pnum < 10) { /* param */
77                         i=0; /* read param */
78                         while(*p > 32) {
79                                 if (i+1 >= sizeof(params[pnum])) {
80                                         UPRINT(conf_error, "Error in %s (line %d): param too long.\n",filename,line);
81                                         goto error;
82                                 }
83                                 params[pnum][i+1] = '\0';
84                                 params[pnum][i++] = *p++;
85                         }
86                         while(*p <= 32) { /* skip spaces */
87                                 if (*p == 0)
88                                         break;
89                                 p++;
90                         }
91                         pnum++;
92                         params[pnum][0] = 0;
93                 }
94
95                 /* at this point we have option and param */
96
97                 /* check option */
98                 if (!strcmp(option,"debug")) {
99                         if (params[0][0]==0) {
100                                 UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line,option);
101                                 goto error;
102                         }
103                         SCPY(gsm_conf->debug, params[0]);
104
105                 } else
106                 if (!strcmp(option,"config")) {
107                         if (params[0][0]==0) {
108                                 UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
109                                 goto error;
110                         }
111                         SCPY(gsm_conf->openbsc_cfg, params[0]);
112
113                 } else
114                 if (!strcmp(option,"hlr")) {
115                         if (params[0][0]==0) {
116                                 UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
117                                 goto error;
118                         }
119                         SCPY(gsm_conf->hlr, params[0]);
120
121                 } else
122                 if (!strcmp(option,"reject-cause")) {
123                         UPRINT(conf_error, "Option '%s' in gsm.conf has moved to openbsc.cfg", option);
124                         goto error;
125                 } else
126                 if (!strcmp(option,"allow-all")) {
127                         gsm_conf->allow_all = 1;
128                 } else
129                 if (!strcmp(option,"keep-l2")) {
130                         gsm_conf->keep_l2 = 1;
131
132                 } else
133                 if (!strcmp(option,"pcapfile")) {
134                         if (params[0][0]==0) {
135                                 UPRINT(conf_error, "Error in %s (line %d): parameter for option %s missing.\n",filename,line, option);
136                                 goto error;
137                         }
138                         SCPY(gsm_conf->pcapfile, params[0]);
139                 } else {
140                         UPRINT(conf_error, "Error in %s (line %d): wrong option keyword %s.\n", filename,line,option);
141                         goto error;
142                 }
143         }
144
145         if (fp) fclose(fp);
146         return(1);
147 error:
148         if (fp) fclose(fp);
149         return(0);
150 }
151
152