Ignore some files generated from 1.6.x/trunk build
[asterisk-bristuff.git] / channels / misdn_config.c
blob5125058ea0aa0e0a9c9418616fd4229a553fcc98
1 /*
2 * Asterisk -- An open source telephony toolkit.
3 *
4 * Copyright (C) 2005, Christian Richter
6 * Christian Richter <crich@beronet.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
20 /*!
21 * \file
23 * \brief chan_misdn configuration management
24 * \author Christian Richter <crich@beronet.com>
26 * \ingroup channel_drivers
29 #include "asterisk.h"
31 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
33 #include <stdlib.h>
34 #include <stdio.h>
35 #include <string.h>
36 #include <errno.h>
38 #include "chan_misdn_config.h"
40 #include "asterisk/config.h"
41 #include "asterisk/channel.h"
42 #include "asterisk/logger.h"
43 #include "asterisk/lock.h"
44 #include "asterisk/pbx.h"
45 #include "asterisk/strings.h"
46 #include "asterisk/utils.h"
48 #define AST_LOAD_CFG ast_config_load
49 #define AST_DESTROY_CFG ast_config_destroy
51 #define NO_DEFAULT "<>"
52 #define NONE 0
54 #define GEN_CFG 1
55 #define PORT_CFG 2
56 #define NUM_GEN_ELEMENTS (sizeof(gen_spec) / sizeof(struct misdn_cfg_spec))
57 #define NUM_PORT_ELEMENTS (sizeof(port_spec) / sizeof(struct misdn_cfg_spec))
59 enum misdn_cfg_type {
60 MISDN_CTYPE_STR,
61 MISDN_CTYPE_INT,
62 MISDN_CTYPE_BOOL,
63 MISDN_CTYPE_BOOLINT,
64 MISDN_CTYPE_MSNLIST,
65 MISDN_CTYPE_ASTGROUP
68 struct msn_list {
69 char *msn;
70 struct msn_list *next;
73 union misdn_cfg_pt {
74 char *str;
75 int *num;
76 struct msn_list *ml;
77 ast_group_t *grp;
78 void *any;
81 struct misdn_cfg_spec {
82 char name[BUFFERSIZE];
83 enum misdn_cfg_elements elem;
84 enum misdn_cfg_type type;
85 char def[BUFFERSIZE];
86 int boolint_def;
87 char desc[BUFFERSIZE];
91 static const char ports_description[] =
92 "Define your ports, e.g. 1,2 (depends on mISDN-driver loading order).";
94 static const struct misdn_cfg_spec port_spec[] = {
95 { "name", MISDN_CFG_GROUPNAME, MISDN_CTYPE_STR, "default", NONE,
96 "Name of the portgroup." },
97 { "allowed_bearers", MISDN_CFG_ALLOWED_BEARERS, MISDN_CTYPE_STR, "all", NONE,
98 "Here you can list which bearer capabilities should be allowed:\n"
99 "\t all - allow any bearer capability\n"
100 "\t speech - allow speech\n"
101 "\t 3_1khz - allow 3.1KHz audio\n"
102 "\t digital_unrestricted - allow unrestricted digital\n"
103 "\t digital_restricted - allow restricted digital\n"
104 "\t video - allow video" },
105 { "rxgain", MISDN_CFG_RXGAIN, MISDN_CTYPE_INT, "0", NONE,
106 "Set this between -8 and 8 to change the RX Gain." },
107 { "txgain", MISDN_CFG_TXGAIN, MISDN_CTYPE_INT, "0", NONE,
108 "Set this between -8 and 8 to change the TX Gain." },
109 { "te_choose_channel", MISDN_CFG_TE_CHOOSE_CHANNEL, MISDN_CTYPE_BOOL, "no", NONE,
110 "Some telcos especially in NL seem to need this set to yes,\n"
111 "\talso in Switzerland this seems to be important." },
112 { "far_alerting", MISDN_CFG_FAR_ALERTING, MISDN_CTYPE_BOOL, "no", NONE,
113 "If we should generate ringing for chan_sip and others." },
114 { "pmp_l1_check", MISDN_CFG_PMP_L1_CHECK, MISDN_CTYPE_BOOL, "no", NONE,
115 "This option defines, if chan_misdn should check the L1 on a PMP\n"
116 "\tbefore making a group call on it. The L1 may go down for PMP Ports\n"
117 "\tso we might need this.\n"
118 "\tBut be aware! a broken or plugged off cable might be used for a group call\n"
119 "\tas well, since chan_misdn has no chance to distinguish if the L1 is down\n"
120 "\tbecause of a lost Link or because the Provider shut it down..." },
121 { "block_on_alarm", MISDN_CFG_ALARM_BLOCK, MISDN_CTYPE_BOOL, "no", NONE ,
122 "Block this port if we have an alarm on it." },
123 { "hdlc", MISDN_CFG_HDLC, MISDN_CTYPE_BOOL, "no", NONE,
124 "Set this to yes, if you want to bridge a mISDN data channel to\n"
125 "\tanother channel type or to an application." },
126 { "context", MISDN_CFG_CONTEXT, MISDN_CTYPE_STR, "default", NONE,
127 "Context to use for incoming calls." },
128 { "language", MISDN_CFG_LANGUAGE, MISDN_CTYPE_STR, "en", NONE,
129 "Language." },
130 { "musicclass", MISDN_CFG_MUSICCLASS, MISDN_CTYPE_STR, "default", NONE,
131 "Sets the musiconhold class." },
132 { "callerid", MISDN_CFG_CALLERID, MISDN_CTYPE_STR, "", NONE,
133 "Sets the caller ID." },
134 { "method", MISDN_CFG_METHOD, MISDN_CTYPE_STR, "standard", NONE,
135 "Sets the method to use for channel selection:\n"
136 "\t standard - always choose the first free channel with the lowest number\n"
137 "\t round_robin - use the round robin algorithm to select a channel. use this\n"
138 "\t if you want to balance your load." },
139 { "dialplan", MISDN_CFG_DIALPLAN, MISDN_CTYPE_INT, "0", NONE,
140 "Dialplan means Type Of Number in ISDN Terms (for outgoing calls)\n"
141 "\n"
142 "\tThere are different types of the dialplan:\n"
143 "\n"
144 "\tdialplan -> outgoing Number\n"
145 "\tlocaldialplan -> callerid\n"
146 "\tcpndialplan -> connected party number\n"
147 "\n"
148 "\tdialplan options:\n"
149 "\n"
150 "\t0 - unknown\n"
151 "\t1 - International\n"
152 "\t2 - National\n"
153 "\t4 - Subscriber\n"
154 "\n"
155 "\tThis setting is used for outgoing calls." },
156 { "localdialplan", MISDN_CFG_LOCALDIALPLAN, MISDN_CTYPE_INT, "0", NONE,
157 "Dialplan means Type Of Number in ISDN Terms (for outgoing calls)\n"
158 "\n"
159 "\tThere are different types of the dialplan:\n"
160 "\n"
161 "\tdialplan -> outgoing Number\n"
162 "\tlocaldialplan -> callerid\n"
163 "\tcpndialplan -> connected party number\n"
164 "\n"
165 "\tdialplan options:\n"
166 "\n"
167 "\t0 - unknown\n"
168 "\t1 - International\n"
169 "\t2 - National\n"
170 "\t4 - Subscriber\n"
171 "\n"
172 "\tThis setting is used for outgoing calls." },
173 { "cpndialplan", MISDN_CFG_CPNDIALPLAN, MISDN_CTYPE_INT, "0", NONE,
174 "Dialplan means Type Of Number in ISDN Terms (for outgoing calls)\n"
175 "\n"
176 "\tThere are different types of the dialplan:\n"
177 "\n"
178 "\tdialplan -> outgoing Number\n"
179 "\tlocaldialplan -> callerid\n"
180 "\tcpndialplan -> connected party number\n"
181 "\n"
182 "\tdialplan options:\n"
183 "\n"
184 "\t0 - unknown\n"
185 "\t1 - International\n"
186 "\t2 - National\n"
187 "\t4 - Subscriber\n"
188 "\n"
189 "\tThis setting is used for outgoing calls." },
190 { "nationalprefix", MISDN_CFG_NATPREFIX, MISDN_CTYPE_STR, "0", NONE,
191 "Prefix for national, this is put before the\n"
192 "\toad if an according dialplan is set by the other end." },
193 { "internationalprefix", MISDN_CFG_INTERNATPREFIX, MISDN_CTYPE_STR, "00", NONE,
194 "Prefix for international, this is put before the\n"
195 "\toad if an according dialplan is set by the other end." },
196 { "presentation", MISDN_CFG_PRES, MISDN_CTYPE_INT, "-1", NONE,
197 "These (presentation and screen) are the exact isdn screening and presentation\n"
198 "\tindicators.\n"
199 "\tIf -1 is given for either value, the presentation indicators are used from\n"
200 "\tAsterisk's SetCallerPres application.\n"
201 "\n"
202 "\tscreen=0, presentation=0 -> callerid presented\n"
203 "\tscreen=1, presentation=1 -> callerid restricted (the remote end doesn't see it!)" },
204 { "screen", MISDN_CFG_SCREEN, MISDN_CTYPE_INT, "-1", NONE,
205 "These (presentation and screen) are the exact isdn screening and presentation\n"
206 "\tindicators.\n"
207 "\tIf -1 is given for either value, the presentation indicators are used from\n"
208 "\tAsterisk's SetCallerPres application.\n"
209 "\n"
210 "\tscreen=0, presentation=0 -> callerid presented\n"
211 "\tscreen=1, presentation=1 -> callerid restricted (the remote end doesn't see it!)" },
212 { "always_immediate", MISDN_CFG_ALWAYS_IMMEDIATE, MISDN_CTYPE_BOOL, "no", NONE,
213 "Enable this to get into the s dialplan-extension.\n"
214 "\tThere you can use DigitTimeout if you can't or don't want to use\n"
215 "\tisdn overlap dial.\n"
216 "\tNOTE: This will jump into the s extension for every exten!" },
217 { "nodialtone", MISDN_CFG_NODIALTONE, MISDN_CTYPE_BOOL, "no", NONE,
218 "Enable this to prevent chan_misdn to generate the dialtone\n"
219 "\tThis makes only sense together with the always_immediate=yes option\n"
220 "\tto generate your own dialtone with Playtones or so."},
221 { "immediate", MISDN_CFG_IMMEDIATE, MISDN_CTYPE_BOOL, "no", NONE,
222 "Enable this if you want callers which called exactly the base\n"
223 "\tnumber (so no extension is set) to jump into the s extension.\n"
224 "\tIf the user dials something more, it jumps to the correct extension\n"
225 "\tinstead." },
226 { "senddtmf", MISDN_CFG_SENDDTMF, MISDN_CTYPE_BOOL, "no", NONE,
227 "Enable this if we should produce DTMF Tones ourselves." },
228 { "astdtmf", MISDN_CFG_ASTDTMF, MISDN_CTYPE_BOOL, "no", NONE,
229 "Enable this if you want to use the Asterisk dtmf detector\n"
230 "instead of the mISDN_dsp/hfcmulti one."
232 { "hold_allowed", MISDN_CFG_HOLD_ALLOWED, MISDN_CTYPE_BOOL, "no", NONE,
233 "Enable this to have support for hold and retrieve." },
234 { "early_bconnect", MISDN_CFG_EARLY_BCONNECT, MISDN_CTYPE_BOOL, "yes", NONE,
235 "Disable this if you don't mind correct handling of Progress Indicators." },
236 { "incoming_early_audio", MISDN_CFG_INCOMING_EARLY_AUDIO, MISDN_CTYPE_BOOL, "no", NONE,
237 "Turn this on if you like to send Tone Indications to a Incoming\n"
238 "\tisdn channel on a TE Port. Rarely used, only if the Telco allows\n"
239 "\tyou to send indications by yourself, normally the Telco sends the\n"
240 "\tindications to the remote party." },
241 { "echocancel", MISDN_CFG_ECHOCANCEL, MISDN_CTYPE_BOOLINT, "0", 128,
242 "This enables echo cancellation with the given number of taps.\n"
243 "\tBe aware: Move this setting only to outgoing portgroups!\n"
244 "\tA value of zero turns echo cancellation off.\n"
245 "\n"
246 "\tPossible values are: 0,32,64,128,256,yes(=128),no(=0)" },
247 #ifdef MISDN_1_2
248 { "pipeline", MISDN_CFG_PIPELINE, MISDN_CTYPE_STR, NO_DEFAULT, NONE,
249 "Set the configuration string for the mISDN dsp pipeline.\n"
250 "\n"
251 "\tExample for enabling the mg2 echo cancellation module with deftaps\n"
252 "\tset to 128:\n"
253 "\t\tmg2ec(deftaps=128)" },
254 #endif
255 #ifdef WITH_BEROEC
256 { "bnechocancel", MISDN_CFG_BNECHOCANCEL, MISDN_CTYPE_BOOLINT, "yes", 64,
257 "echotail in ms (1-200)\n"},
258 { "bnec_antihowl", MISDN_CFG_BNEC_ANTIHOWL, MISDN_CTYPE_INT, "0", NONE,
259 "Use antihowl\n"},
260 { "bnec_nlp", MISDN_CFG_BNEC_NLP, MISDN_CTYPE_BOOL, "yes", NONE,
261 "Nonlinear Processing (much faster adaption)"},
262 { "bnec_zerocoeff", MISDN_CFG_BNEC_ZEROCOEFF, MISDN_CTYPE_BOOL, "no", NONE,
263 "ZeroCoeffeciens\n"},
264 { "bnec_tonedisabler", MISDN_CFG_BNEC_TD, MISDN_CTYPE_BOOL, "no", NONE,
265 "Disable Tone\n"},
266 { "bnec_adaption", MISDN_CFG_BNEC_ADAPT, MISDN_CTYPE_INT, "1", NONE,
267 "Adaption mode (0=no,1=full,2=fast)\n"},
268 #endif
269 { "need_more_infos", MISDN_CFG_NEED_MORE_INFOS, MISDN_CTYPE_BOOL, "0", NONE,
270 "Send Setup_Acknowledge on incoming calls anyway (instead of PROCEEDING),\n"
271 "\tthis requests additional Infos, so we can waitfordigits without much\n"
272 "\tissues. This works only for PTP Ports" },
273 { "noautorespond_on_setup", MISDN_CFG_NOAUTORESPOND_ON_SETUP, MISDN_CTYPE_BOOL, "0", NONE,
274 "Do not send SETUP_ACKNOWLEDGE or PROCEEDING automatically to the calling Party.\n"
275 "Instead we directly jump into the dialplan. This might be useful for fast call\n"
276 "rejection, or for some broken switches, that need hangup causes like busy in the.\n"
277 "RELEASE_COMPLETE Message, instead of the DISCONNECT Message."},
278 { "jitterbuffer", MISDN_CFG_JITTERBUFFER, MISDN_CTYPE_INT, "4000", NONE,
279 "The jitterbuffer." },
280 { "jitterbuffer_upper_threshold", MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, MISDN_CTYPE_INT, "0", NONE,
281 "Change this threshold to enable dejitter functionality." },
282 { "callgroup", MISDN_CFG_CALLGROUP, MISDN_CTYPE_ASTGROUP, NO_DEFAULT, NONE,
283 "Callgroup." },
284 { "pickupgroup", MISDN_CFG_PICKUPGROUP, MISDN_CTYPE_ASTGROUP, NO_DEFAULT, NONE,
285 "Pickupgroup." },
286 { "max_incoming", MISDN_CFG_MAX_IN, MISDN_CTYPE_INT, "-1", NONE,
287 "Defines the maximum amount of incoming calls per port for this group.\n"
288 "\tCalls which exceed the maximum will be marked with the channel variable\n"
289 "\tMAX_OVERFLOW. It will contain the amount of overflowed calls" },
290 { "max_outgoing", MISDN_CFG_MAX_OUT, MISDN_CTYPE_INT, "-1", NONE,
291 "Defines the maximum amount of outgoing calls per port for this group\n"
292 "\texceeding calls will be rejected" },
294 { "reject_cause", MISDN_CFG_REJECT_CAUSE, MISDN_CTYPE_INT, "21", NONE,
295 "Defines the cause with which a 3. call is rejected on PTMP BRI."},
296 { "faxdetect", MISDN_CFG_FAXDETECT, MISDN_CTYPE_STR, "no", NONE,
297 "Setup fax detection:\n"
298 "\t no - no fax detection\n"
299 "\t incoming - fax detection for incoming calls\n"
300 "\t outgoing - fax detection for outgoing calls\n"
301 "\t both - fax detection for incoming and outgoing calls\n"
302 "\tAdd +nojump to your value (i.e. faxdetect=both+nojump) if you don't want to jump into the\n"
303 "\tfax-extension but still want to detect the fax and prepare the channel for fax transfer." },
304 { "faxdetect_timeout", MISDN_CFG_FAXDETECT_TIMEOUT, MISDN_CTYPE_INT, "5", NONE,
305 "Number of seconds the fax detection should do its job. After the given period of time,\n"
306 "\twe assume that it's not a fax call and save some CPU time by turning off fax detection.\n"
307 "\tSet this to 0 if you don't want a timeout (never stop detecting)." },
308 { "faxdetect_context", MISDN_CFG_FAXDETECT_CONTEXT, MISDN_CTYPE_STR, NO_DEFAULT, NONE,
309 "Context to jump into if we detect a fax. Don't set this if you want to stay in the current context." },
310 { "l1watcher_timeout", MISDN_CFG_L1_TIMEOUT, MISDN_CTYPE_BOOLINT, "0", 4,
311 "Watches the layer 1. If the layer 1 is down, it tries to\n"
312 "\tget it up. The timeout is given in seconds. with 0 as value it\n"
313 "\tdoes not watch the l1 at all\n"
314 "\n"
315 "\tThis option is only read at loading time of chan_misdn, which\n"
316 "\tmeans you need to unload and load chan_misdn to change the value,\n"
317 "\tan Asterisk restart should do the trick." },
318 { "overlapdial", MISDN_CFG_OVERLAP_DIAL, MISDN_CTYPE_BOOLINT, "0", 4,
319 "Enables overlap dial for the given amount of seconds.\n"
320 "\tPossible values are positive integers or:\n"
321 "\t yes (= 4 seconds)\n"
322 "\t no (= 0 seconds = disabled)" },
323 { "nttimeout", MISDN_CFG_NTTIMEOUT, MISDN_CTYPE_BOOL, "no", NONE ,
324 "Set this to yes if you want calls disconnected in overlap mode"
325 "when a timeout happens."},
326 { "bridging", MISDN_CFG_BRIDGING, MISDN_CTYPE_BOOL, "yes", NONE,
327 "Set this to yes/no, default is yes.\n"
328 "This can be used to have bridging enabled in general and to\n"
329 "disable it for specific ports. It makes sense to disable\n"
330 "bridging on NT Port where you plan to use the HOLD/RETRIEVE\n"
331 "features with ISDN phones." },
332 { "msns", MISDN_CFG_MSNS, MISDN_CTYPE_MSNLIST, "*", NONE,
333 "MSN's for TE ports, listen on those numbers on the above ports, and\n"
334 "\tindicate the incoming calls to Asterisk.\n"
335 "\tHere you can give a comma separated list, or simply an '*' for any msn." },
338 static const struct misdn_cfg_spec gen_spec[] = {
339 { "debug", MISDN_GEN_DEBUG, MISDN_CTYPE_INT, "0", NONE,
340 "Sets the debugging flag:\n"
341 "\t0 - No Debug\n"
342 "\t1 - mISDN Messages and * - Messages, and * - State changes\n"
343 "\t2 - Messages + Message specific Informations (e.g. bearer capability)\n"
344 "\t3 - very Verbose, the above + lots of Driver specific infos\n"
345 "\t4 - even more Verbose than 3" },
346 #ifndef MISDN_1_2
347 { "misdn_init", MISDN_GEN_MISDN_INIT, MISDN_CTYPE_STR, "/etc/misdn-init.conf", NONE,
348 "Set the path to the misdn-init.conf (for nt_ptp mode checking)." },
349 #endif
350 { "tracefile", MISDN_GEN_TRACEFILE, MISDN_CTYPE_STR, "/var/log/asterisk/misdn.log", NONE,
351 "Set the path to the massively growing trace file, if you want that." },
352 { "bridging", MISDN_GEN_BRIDGING, MISDN_CTYPE_BOOL, "yes", NONE,
353 "Set this to yes if you want mISDN_dsp to bridge the calls in HW." },
354 { "stop_tone_after_first_digit", MISDN_GEN_STOP_TONE, MISDN_CTYPE_BOOL, "yes", NONE,
355 "Stops dialtone after getting first digit on NT Port." },
356 { "append_digits2exten", MISDN_GEN_APPEND_DIGITS2EXTEN, MISDN_CTYPE_BOOL, "yes", NONE,
357 "Whether to append overlapdialed Digits to Extension or not." },
358 { "dynamic_crypt", MISDN_GEN_DYNAMIC_CRYPT, MISDN_CTYPE_BOOL, "no", NONE,
359 "Whether to look out for dynamic crypting attempts." },
360 { "crypt_prefix", MISDN_GEN_CRYPT_PREFIX, MISDN_CTYPE_STR, NO_DEFAULT, NONE,
361 "What is used for crypting Protocol." },
362 { "crypt_keys", MISDN_GEN_CRYPT_KEYS, MISDN_CTYPE_STR, NO_DEFAULT, NONE,
363 "Keys for cryption, you reference them in the dialplan\n"
364 "\tLater also in dynamic encr." },
365 { "ntkeepcalls", MISDN_GEN_NTKEEPCALLS, MISDN_CTYPE_BOOL, "no", NONE,
366 "avoid dropping calls if the L2 goes down. some Nortel pbx\n"
367 "do put down the L2/L1 for some milliseconds even if there\n"
368 "are running calls. with this option you can avoid dropping them" },
369 { "ntdebugflags", MISDN_GEN_NTDEBUGFLAGS, MISDN_CTYPE_INT, "0", NONE,
370 "No description yet."},
371 { "ntdebugfile", MISDN_GEN_NTDEBUGFILE, MISDN_CTYPE_STR, "/var/log/misdn-nt.log", NONE,
372 "No description yet." }
376 /* array of port configs, default is at position 0. */
377 static union misdn_cfg_pt **port_cfg;
378 /* max number of available ports, is set on init */
379 static int max_ports;
380 /* general config */
381 static union misdn_cfg_pt *general_cfg;
382 /* storing the ptp flag separated to save memory */
383 static int *ptp;
384 /* maps enum config elements to array positions */
385 static int *map;
387 static ast_mutex_t config_mutex;
389 #define CLI_ERROR(name, value, section) ({ \
390 ast_log(LOG_WARNING, "misdn.conf: \"%s=%s\" (section: %s) invalid or out of range. " \
391 "Please edit your misdn.conf and then do a \"misdn reload\".\n", name, value, section); \
394 static int _enum_array_map (void)
396 int i, j, ok;
398 for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) {
399 if (i == MISDN_CFG_PTP)
400 continue;
401 ok = 0;
402 for (j = 0; j < NUM_PORT_ELEMENTS; ++j) {
403 if (port_spec[j].elem == i) {
404 map[i] = j;
405 ok = 1;
406 break;
409 if (!ok) {
410 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i);
411 return -1;
414 for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) {
415 ok = 0;
416 for (j = 0; j < NUM_GEN_ELEMENTS; ++j) {
417 if (gen_spec[j].elem == i) {
418 map[i] = j;
419 ok = 1;
420 break;
423 if (!ok) {
424 ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i);
425 return -1;
428 return 0;
431 static int get_cfg_position (char *name, int type)
433 int i;
435 switch (type) {
436 case PORT_CFG:
437 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
438 if (!strcasecmp(name, port_spec[i].name))
439 return i;
441 break;
442 case GEN_CFG:
443 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
444 if (!strcasecmp(name, gen_spec[i].name))
445 return i;
449 return -1;
452 static inline void misdn_cfg_lock (void)
454 ast_mutex_lock(&config_mutex);
457 static inline void misdn_cfg_unlock (void)
459 ast_mutex_unlock(&config_mutex);
462 static void _free_msn_list (struct msn_list* iter)
464 if (iter->next)
465 _free_msn_list(iter->next);
466 if (iter->msn)
467 free(iter->msn);
468 free(iter);
471 static void _free_port_cfg (void)
473 int i, j;
474 int gn = map[MISDN_CFG_GROUPNAME];
475 union misdn_cfg_pt* free_list[max_ports + 2];
477 memset(free_list, 0, sizeof(free_list));
478 free_list[0] = port_cfg[0];
479 for (i = 1; i <= max_ports; ++i) {
480 if (port_cfg[i][gn].str) {
481 /* we always have a groupname in the non-default case, so this is fine */
482 for (j = 1; j <= max_ports; ++j) {
483 if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str)
484 break;
485 else if (!free_list[j]) {
486 free_list[j] = port_cfg[i];
487 break;
492 for (j = 0; free_list[j]; ++j) {
493 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
494 if (free_list[j][i].any) {
495 if (port_spec[i].type == MISDN_CTYPE_MSNLIST)
496 _free_msn_list(free_list[j][i].ml);
497 else
498 free(free_list[j][i].any);
504 static void _free_general_cfg (void)
506 int i;
508 for (i = 0; i < NUM_GEN_ELEMENTS; i++)
509 if (general_cfg[i].any)
510 free(general_cfg[i].any);
513 void misdn_cfg_get (int port, enum misdn_cfg_elements elem, void *buf, int bufsize)
515 int place;
517 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
518 memset(buf, 0, bufsize);
519 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port);
520 return;
523 misdn_cfg_lock();
524 if (elem == MISDN_CFG_PTP) {
525 if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize))
526 memset(buf, 0, bufsize);
527 } else {
528 if ((place = map[elem]) < 0) {
529 memset (buf, 0, bufsize);
530 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem);
531 } else {
532 if (elem < MISDN_CFG_LAST) {
533 switch (port_spec[place].type) {
534 case MISDN_CTYPE_STR:
535 if (port_cfg[port][place].str) {
536 if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize))
537 memset(buf, 0, 1);
538 } else if (port_cfg[0][place].str) {
539 if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize))
540 memset(buf, 0, 1);
541 } else
542 memset(buf, 0, bufsize);
543 break;
544 default:
545 if (port_cfg[port][place].any)
546 memcpy(buf, port_cfg[port][place].any, bufsize);
547 else if (port_cfg[0][place].any)
548 memcpy(buf, port_cfg[0][place].any, bufsize);
549 else
550 memset(buf, 0, bufsize);
552 } else {
553 switch (gen_spec[place].type) {
554 case MISDN_CTYPE_STR:
555 if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize))
556 memset(buf, 0, 1);
557 break;
558 default:
559 if (general_cfg[place].any)
560 memcpy(buf, general_cfg[place].any, bufsize);
561 else
562 memset(buf, 0, bufsize);
567 misdn_cfg_unlock();
570 enum misdn_cfg_elements misdn_cfg_get_elem (char *name)
572 int pos;
574 /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
575 if (!strcmp(name, "ports"))
576 return MISDN_CFG_GROUPNAME;
577 if (!strcmp(name, "name"))
578 return MISDN_CFG_FIRST;
580 pos = get_cfg_position (name, PORT_CFG);
581 if (pos >= 0)
582 return port_spec[pos].elem;
584 pos = get_cfg_position (name, GEN_CFG);
585 if (pos >= 0)
586 return gen_spec[pos].elem;
588 return MISDN_CFG_FIRST;
591 void misdn_cfg_get_name (enum misdn_cfg_elements elem, void *buf, int bufsize)
593 struct misdn_cfg_spec *spec = NULL;
594 int place = map[elem];
596 /* the ptp hack */
597 if (elem == MISDN_CFG_PTP) {
598 memset(buf, 0, 1);
599 return;
602 /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
603 if (elem == MISDN_CFG_GROUPNAME) {
604 if (!snprintf(buf, bufsize, "ports"))
605 memset(buf, 0, 1);
606 return;
609 if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
610 spec = (struct misdn_cfg_spec *)port_spec;
611 else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
612 spec = (struct misdn_cfg_spec *)gen_spec;
614 if (!spec || !memccpy(buf, spec[place].name, 0, bufsize))
615 memset(buf, 0, 1);
618 void misdn_cfg_get_desc (enum misdn_cfg_elements elem, void *buf, int bufsize, void *buf_default, int bufsize_default)
620 int place = map[elem];
621 struct misdn_cfg_spec *spec = NULL;
623 /* here comes a hack to replace the (not existing) "name" element with the "ports" element */
624 if (elem == MISDN_CFG_GROUPNAME) {
625 if (!memccpy(buf, ports_description, 0, bufsize))
626 memset(buf, 0, 1);
627 if (buf_default && bufsize_default)
628 memset(buf_default, 0, 1);
629 return;
632 if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST))
633 spec = (struct misdn_cfg_spec *)port_spec;
634 else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST))
635 spec = (struct misdn_cfg_spec *)gen_spec;
637 if (!spec || !spec[place].desc)
638 memset(buf, 0, 1);
639 else {
640 if (!memccpy(buf, spec[place].desc, 0, bufsize))
641 memset(buf, 0, 1);
642 if (buf_default && bufsize) {
643 if (!strcmp(spec[place].def, NO_DEFAULT))
644 memset(buf_default, 0, 1);
645 else if (!memccpy(buf_default, spec[place].def, 0, bufsize_default))
646 memset(buf_default, 0, 1);
651 int misdn_cfg_is_msn_valid (int port, char* msn)
653 int re = 0;
654 struct msn_list *iter;
656 if (!misdn_cfg_is_port_valid(port)) {
657 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port);
658 return 0;
661 misdn_cfg_lock();
662 if (port_cfg[port][map[MISDN_CFG_MSNS]].ml)
663 iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml;
664 else
665 iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml;
666 for (; iter; iter = iter->next)
667 if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) {
668 re = 1;
669 break;
671 misdn_cfg_unlock();
673 return re;
676 int misdn_cfg_is_port_valid (int port)
678 int gn = map[MISDN_CFG_GROUPNAME];
680 return (port >= 1 && port <= max_ports && port_cfg[port][gn].str);
683 int misdn_cfg_is_group_method (char *group, enum misdn_cfg_method meth)
685 int i, re = 0;
686 char *method ;
688 misdn_cfg_lock();
690 method = port_cfg[0][map[MISDN_CFG_METHOD]].str;
692 for (i = 1; i <= max_ports; i++) {
693 if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) {
694 if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group))
695 method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ?
696 port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str);
700 if (method) {
701 switch (meth) {
702 case METHOD_STANDARD: re = !strcasecmp(method, "standard");
703 break;
704 case METHOD_ROUND_ROBIN: re = !strcasecmp(method, "round_robin");
705 break;
706 case METHOD_STANDARD_DEC: re = !strcasecmp(method, "standard_dec");
707 break;
710 misdn_cfg_unlock();
712 return re;
715 /*!
716 * \brief Generate a comma separated list of all active ports
718 void misdn_cfg_get_ports_string (char *ports)
720 char tmp[16];
721 int l, i;
722 int gn = map[MISDN_CFG_GROUPNAME];
724 *ports = 0;
726 misdn_cfg_lock();
727 for (i = 1; i <= max_ports; i++) {
728 if (port_cfg[i][gn].str) {
729 if (ptp[i])
730 sprintf(tmp, "%dptp,", i);
731 else
732 sprintf(tmp, "%d,", i);
733 strcat(ports, tmp);
736 misdn_cfg_unlock();
738 if ((l = strlen(ports))) {
739 /* Strip trailing ',' */
740 ports[l-1] = 0;
744 void misdn_cfg_get_config_string (int port, enum misdn_cfg_elements elem, char* buf, int bufsize)
746 int place;
747 char tempbuf[BUFFERSIZE] = "";
748 struct msn_list *iter;
750 if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) {
751 *buf = 0;
752 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port);
753 return;
756 place = map[elem];
758 misdn_cfg_lock();
759 if (elem == MISDN_CFG_PTP) {
760 snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no");
762 else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) {
763 switch (port_spec[place].type) {
764 case MISDN_CTYPE_INT:
765 case MISDN_CTYPE_BOOLINT:
766 if (port_cfg[port][place].num)
767 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num);
768 else if (port_cfg[0][place].num)
769 snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num);
770 else
771 snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
772 break;
773 case MISDN_CTYPE_BOOL:
774 if (port_cfg[port][place].num)
775 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no");
776 else if (port_cfg[0][place].num)
777 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no");
778 else
779 snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
780 break;
781 case MISDN_CTYPE_ASTGROUP:
782 if (port_cfg[port][place].grp)
783 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
784 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp));
785 else if (port_cfg[0][place].grp)
786 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,
787 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp));
788 else
789 snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
790 break;
791 case MISDN_CTYPE_MSNLIST:
792 if (port_cfg[port][place].ml)
793 iter = port_cfg[port][place].ml;
794 else
795 iter = port_cfg[0][place].ml;
796 if (iter) {
797 for (; iter; iter = iter->next)
798 sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn);
799 tempbuf[strlen(tempbuf)-2] = 0;
801 snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none");
802 break;
803 case MISDN_CTYPE_STR:
804 if ( port_cfg[port][place].str) {
805 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str);
806 } else if (port_cfg[0][place].str) {
807 snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str);
808 } else {
809 snprintf(buf, bufsize, " -> %s:", port_spec[place].name);
811 break;
813 } else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) {
814 switch (gen_spec[place].type) {
815 case MISDN_CTYPE_INT:
816 case MISDN_CTYPE_BOOLINT:
817 if (general_cfg[place].num)
818 snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num);
819 else
820 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
821 break;
822 case MISDN_CTYPE_BOOL:
823 if (general_cfg[place].num)
824 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no");
825 else
826 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
827 break;
828 case MISDN_CTYPE_STR:
829 if ( general_cfg[place].str) {
830 snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str);
831 } else {
832 snprintf(buf, bufsize, " -> %s:", gen_spec[place].name);
834 break;
835 default:
836 snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name);
837 break;
839 } else {
840 *buf = 0;
841 ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem);
843 misdn_cfg_unlock();
846 int misdn_cfg_get_next_port (int port)
848 int p = -1;
849 int gn = map[MISDN_CFG_GROUPNAME];
851 misdn_cfg_lock();
852 for (port++; port <= max_ports; port++) {
853 if (port_cfg[port][gn].str) {
854 p = port;
855 break;
858 misdn_cfg_unlock();
860 return p;
863 int misdn_cfg_get_next_port_spin (int port)
865 int p = misdn_cfg_get_next_port(port);
866 return (p > 0) ? p : misdn_cfg_get_next_port(0);
869 static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type type, int boolint_def)
871 int re = 0;
872 int len, tmp;
873 char *valtmp;
875 switch (type) {
876 case MISDN_CTYPE_STR:
877 if ((len = strlen(value))) {
878 dest->str = (char *)malloc((len + 1) * sizeof(char));
879 strncpy(dest->str, value, len);
880 dest->str[len] = 0;
881 } else {
882 dest->str = (char *)malloc( sizeof(char));
883 dest->str[0] = 0;
885 break;
886 case MISDN_CTYPE_INT:
888 char *pat;
889 if (strchr(value,'x'))
890 pat="%x";
891 else
892 pat="%d";
893 if (sscanf(value, pat, &tmp)) {
894 dest->num = (int *)malloc(sizeof(int));
895 memcpy(dest->num, &tmp, sizeof(int));
896 } else
897 re = -1;
899 break;
900 case MISDN_CTYPE_BOOL:
901 dest->num = (int *)malloc(sizeof(int));
902 *(dest->num) = (ast_true(value) ? 1 : 0);
903 break;
904 case MISDN_CTYPE_BOOLINT:
905 dest->num = (int *)malloc(sizeof(int));
906 if (sscanf(value, "%d", &tmp)) {
907 memcpy(dest->num, &tmp, sizeof(int));
908 } else {
909 *(dest->num) = (ast_true(value) ? boolint_def : 0);
911 break;
912 case MISDN_CTYPE_MSNLIST:
913 for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) {
914 if ((len = strlen(valtmp))) {
915 struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list));
916 ml->msn = (char *)calloc(len+1, sizeof(char));
917 strncpy(ml->msn, valtmp, len);
918 ml->next = dest->ml;
919 dest->ml = ml;
922 break;
923 case MISDN_CTYPE_ASTGROUP:
924 dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t));
925 *(dest->grp) = ast_get_group(value);
926 break;
929 return re;
932 static void _build_general_config (struct ast_variable *v)
934 int pos;
936 for (; v; v = v->next) {
937 if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) ||
938 (_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0))
939 CLI_ERROR(v->name, v->value, "general");
943 static void _build_port_config (struct ast_variable *v, char *cat)
945 int pos, i;
946 union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS];
947 int cfg_for_ports[max_ports + 1];
949 if (!v || !cat)
950 return;
952 memset(cfg_tmp, 0, sizeof(cfg_tmp));
953 memset(cfg_for_ports, 0, sizeof(cfg_for_ports));
955 if (!strcasecmp(cat, "default")) {
956 cfg_for_ports[0] = 1;
959 if (((pos = get_cfg_position("name", PORT_CFG)) < 0) ||
960 (_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) {
961 CLI_ERROR(v->name, v->value, cat);
962 return;
965 for (; v; v = v->next) {
966 if (!strcasecmp(v->name, "ports")) {
967 char *token;
968 char ptpbuf[BUFFERSIZE] = "";
969 int start, end;
970 for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) {
971 if (!*token)
972 continue;
973 if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) {
974 for (; start <= end; start++) {
975 if (start <= max_ports && start > 0) {
976 cfg_for_ports[start] = 1;
977 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
978 } else
979 CLI_ERROR(v->name, v->value, cat);
981 } else {
982 if (sscanf(token, "%d%s", &start, ptpbuf)) {
983 if (start <= max_ports && start > 0) {
984 cfg_for_ports[start] = 1;
985 ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0;
986 } else
987 CLI_ERROR(v->name, v->value, cat);
988 } else
989 CLI_ERROR(v->name, v->value, cat);
992 } else {
993 if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) ||
994 (_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0))
995 CLI_ERROR(v->name, v->value, cat);
999 for (i = 0; i < (max_ports + 1); ++i) {
1000 if (cfg_for_ports[i]) {
1001 memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp));
1006 void misdn_cfg_update_ptp (void)
1008 #ifndef MISDN_1_2
1009 char misdn_init[BUFFERSIZE];
1010 char line[BUFFERSIZE];
1011 FILE *fp;
1012 char *tok, *p, *end;
1013 int port;
1015 misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init));
1017 if (!ast_strlen_zero(misdn_init)) {
1018 fp = fopen(misdn_init, "r");
1019 if (fp) {
1020 while(fgets(line, sizeof(line), fp)) {
1021 if (!strncmp(line, "nt_ptp", 6)) {
1022 for (tok = strtok_r(line,",=", &p);
1023 tok;
1024 tok = strtok_r(NULL,",=", &p)) {
1025 port = strtol(tok, &end, 10);
1026 if (end != tok && misdn_cfg_is_port_valid(port)) {
1027 misdn_cfg_lock();
1028 ptp[port] = 1;
1029 misdn_cfg_unlock();
1034 fclose(fp);
1035 } else {
1036 ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno));
1039 #else
1040 int i;
1041 int proto;
1042 char filename[128];
1043 FILE *fp;
1045 for (i = 1; i <= max_ports; ++i) {
1046 snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8);
1047 fp = fopen(filename, "r");
1048 if (!fp) {
1049 ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno));
1050 continue;
1052 if (fscanf(fp, "0x%08x", &proto) != 1)
1053 ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename);
1054 else
1055 ptp[i] = proto & 1<<5 ? 1 : 0;
1056 fclose(fp);
1058 #endif
1061 static void _fill_defaults (void)
1063 int i;
1065 for (i = 0; i < NUM_PORT_ELEMENTS; ++i) {
1066 if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT))
1067 _parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def);
1069 for (i = 0; i < NUM_GEN_ELEMENTS; ++i) {
1070 if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT))
1071 _parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def);
1075 void misdn_cfg_reload (void)
1077 misdn_cfg_init (0);
1080 void misdn_cfg_destroy (void)
1082 misdn_cfg_lock();
1084 _free_port_cfg();
1085 _free_general_cfg();
1087 free(port_cfg);
1088 free(general_cfg);
1089 free(ptp);
1090 free(map);
1092 misdn_cfg_unlock();
1093 ast_mutex_destroy(&config_mutex);
1096 int misdn_cfg_init (int this_max_ports)
1098 char config[] = "misdn.conf";
1099 char *cat, *p;
1100 int i;
1101 struct ast_config *cfg;
1102 struct ast_variable *v;
1104 if (!(cfg = AST_LOAD_CFG(config))) {
1105 ast_log(LOG_WARNING, "missing file: misdn.conf\n");
1106 return -1;
1109 ast_mutex_init(&config_mutex);
1111 misdn_cfg_lock();
1113 if (this_max_ports) {
1114 /* this is the first run */
1115 max_ports = this_max_ports;
1116 map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int));
1117 if (_enum_array_map())
1118 return -1;
1119 p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *)
1120 + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt));
1121 port_cfg = (union misdn_cfg_pt **)p;
1122 p += (max_ports + 1) * sizeof(union misdn_cfg_pt *);
1123 for (i = 0; i <= max_ports; ++i) {
1124 port_cfg[i] = (union misdn_cfg_pt *)p;
1125 p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt);
1127 general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
1128 ptp = (int *)calloc(max_ports + 1, sizeof(int));
1130 else {
1131 /* misdn reload */
1132 _free_port_cfg();
1133 _free_general_cfg();
1134 memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1));
1135 memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS);
1136 memset(ptp, 0, sizeof(int) * (max_ports + 1));
1139 cat = ast_category_browse(cfg, NULL);
1141 while(cat) {
1142 v = ast_variable_browse(cfg, cat);
1143 if (!strcasecmp(cat, "general")) {
1144 _build_general_config(v);
1145 } else {
1146 _build_port_config(v, cat);
1148 cat = ast_category_browse(cfg, cat);
1151 _fill_defaults();
1153 misdn_cfg_unlock();
1154 AST_DESTROY_CFG(cfg);
1156 return 0;