| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							|  |  |  |  *  | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  |  * Copyright (C) 2005, Christian Richter | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Christian Richter <crich@beronet.com> | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * See http://www.asterisk.org for more information about
 | 
					
						
							|  |  |  |  * the Asterisk project. Please do not directly contact | 
					
						
							|  |  |  |  * any of the maintainers of this project for assistance; | 
					
						
							|  |  |  |  * the project provides a web site, mailing lists and IRC | 
					
						
							|  |  |  |  * channels for your use. | 
					
						
							|  |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /*!
 | 
					
						
							|  |  |  |  * \file | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \brief chan_misdn configuration management | 
					
						
							|  |  |  |  * \author Christian Richter <crich@beronet.com> | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * \ingroup channel_drivers | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ASTERISK_FILE_VERSION(__FILE__, "$Revision$") | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | #include <stdlib.h>
 | 
					
						
							|  |  |  | #include <stdio.h>
 | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | #include <string.h>
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | #include <errno.h>
 | 
					
						
							| 
									
										
										
										
											2005-11-15 20:20:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | #include "chan_misdn_config.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk/config.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/logger.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/strings.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | #define AST_LOAD_CFG ast_config_load
 | 
					
						
							|  |  |  | #define AST_DESTROY_CFG ast_config_destroy
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | #define NO_DEFAULT "<>"
 | 
					
						
							|  |  |  | #define NONE 0
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define GEN_CFG 1
 | 
					
						
							|  |  |  | #define PORT_CFG 2
 | 
					
						
							|  |  |  | #define NUM_GEN_ELEMENTS (sizeof(gen_spec) / sizeof(struct misdn_cfg_spec))
 | 
					
						
							|  |  |  | #define NUM_PORT_ELEMENTS (sizeof(port_spec) / sizeof(struct misdn_cfg_spec))
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | enum misdn_cfg_type { | 
					
						
							|  |  |  | 	MISDN_CTYPE_STR, | 
					
						
							|  |  |  | 	MISDN_CTYPE_INT, | 
					
						
							|  |  |  | 	MISDN_CTYPE_BOOL, | 
					
						
							|  |  |  | 	MISDN_CTYPE_BOOLINT, | 
					
						
							|  |  |  | 	MISDN_CTYPE_MSNLIST, | 
					
						
							|  |  |  | 	MISDN_CTYPE_ASTGROUP | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct msn_list { | 
					
						
							|  |  |  | 	char *msn; | 
					
						
							|  |  |  | 	struct msn_list *next; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | union misdn_cfg_pt { | 
					
						
							|  |  |  | 	char *str; | 
					
						
							|  |  |  | 	int *num; | 
					
						
							|  |  |  | 	struct msn_list *ml; | 
					
						
							|  |  |  | 	ast_group_t *grp; | 
					
						
							|  |  |  | 	void *any; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct misdn_cfg_spec { | 
					
						
							|  |  |  | 	char name[BUFFERSIZE]; | 
					
						
							|  |  |  | 	enum misdn_cfg_elements elem; | 
					
						
							|  |  |  | 	enum misdn_cfg_type type; | 
					
						
							|  |  |  | 	char def[BUFFERSIZE]; | 
					
						
							|  |  |  | 	int boolint_def; | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	char desc[BUFFERSIZE]; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static const char ports_description[] = | 
					
						
							|  |  |  | 	"Define your ports, e.g. 1,2 (depends on mISDN-driver loading order)."; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static const struct misdn_cfg_spec port_spec[] = { | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "name", MISDN_CFG_GROUPNAME, MISDN_CTYPE_STR, "default", NONE, | 
					
						
							|  |  |  | 		"Name of the portgroup." }, | 
					
						
							|  |  |  | 	{ "allowed_bearers", MISDN_CFG_ALLOWED_BEARERS, MISDN_CTYPE_STR, "all", NONE, | 
					
						
							|  |  |  | 		"Here you can define which bearers should be allowed." }, | 
					
						
							|  |  |  | 	{ "rxgain", MISDN_CFG_RXGAIN, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Set this between -8 and 8 to change the RX Gain." }, | 
					
						
							|  |  |  | 	{ "txgain", MISDN_CFG_TXGAIN, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Set this between -8 and 8 to change the TX Gain." }, | 
					
						
							|  |  |  | 	{ "te_choose_channel", MISDN_CFG_TE_CHOOSE_CHANNEL, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Some telcos espacially in NL seem to need this set to yes,\n" | 
					
						
							|  |  |  | 		"\talso in switzerland this seems to be important." }, | 
					
						
							|  |  |  | 	{ "far_alerting", MISDN_CFG_FAR_ALERTING, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"If we should generate ringing for chan_sip and others." }, | 
					
						
							| 
									
										
											  
											
												Merged revisions 48319,48321,48467,48552,48576,49135,49303 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/branches/1.2
........
r48319 | crichter | 2006-12-06 15:35:25 +0100 (Mi, 06 Dez 2006) | 1 line
changed a few debugs to higher debug levels
........
r48321 | crichter | 2006-12-06 16:48:45 +0100 (Mi, 06 Dez 2006) | 1 line
added the export and import of the MISDN_ADDRESS_COMPLETE Variable to inidcate wether the extension is already completely dialed or if there might come additional digits by information elements. also added some docs for that.
........
r48467 | crichter | 2006-12-14 14:03:49 +0100 (Do, 14 Dez 2006) | 1 line
removed FIXUP state. added check for channel allocation conflict when we create a setup while the other site creates a setup on the same channel, besides the check we resolve this conflict.
........
r48552 | crichter | 2006-12-18 11:19:39 +0100 (Mo, 18 Dez 2006) | 1 line
when our PTP Partner sends us a SETUP with a preselected channel we just accept it, even when we're NT. added some checks for segfaults.
........
r48576 | crichter | 2006-12-19 14:08:51 +0100 (Di, 19 Dez 2006) | 1 line
when we reject a channel, because it's in use already, we shouldn't process the setup anymore. made the channel allocation a bit easier and more understandable, removed a few unused lines
........
r49135 | crichter | 2007-01-02 11:07:22 +0100 (Di, 02 Jan 2007) | 1 line
added check for channel ranges in the set/empty channel functions. set pmp_l1_check default to no. added misdn restart pid cli command. added cleaning of channel when we send a RELEASE_COMPLETE. 
........
r49303 | crichter | 2007-01-03 09:24:00 +0100 (Mi, 03 Jan 2007) | 9 lines
* Added check for bridging in misdn_call to avoid setting echocancellation
  when 2 mISDN channels are involved and when bridging is set. That lead
  to a kernel panic before under different situations, because we switched 
  about 2 times between hardware bridging and echocancelation
* readded MISDN_URATE variable which got lost before, this should make app_v110
  work again
* fixed typo
........
git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/1.4@49313 65c4cc65-6c06-0410-ace0-fbb531ad65f3
											
										 
											2007-01-03 09:06:50 +00:00
										 |  |  | 	{ "pmp_l1_check", MISDN_CFG_PMP_L1_CHECK, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 		"This option defines, if chan_misdn should check the L1 on a PMP\n" | 
					
						
							|  |  |  | 		"\tbefore makeing a group call on it. The L1 may go down for PMP Ports\n" | 
					
						
							|  |  |  | 		"\tso we might need this.\n" | 
					
						
							|  |  |  | 		"\tBut be aware! a broken or plugged off cable might be used for a group call\n" | 
					
						
							|  |  |  | 		"\tas well, since chan_misdn has no chance to distinguish if the L1 is down\n" | 
					
						
							|  |  |  | 		"\tbecause of a lost Link or because the Provider shut it down..." }, | 
					
						
							| 
									
										
										
										
											2006-11-24 15:46:13 +00:00
										 |  |  | 	{ "block_on_alarm", MISDN_CFG_ALARM_BLOCK, MISDN_CTYPE_BOOL, "no", NONE , | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 	  "Block this port if we have an alarm on it." | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | 	  "default: yes\n" }, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "hdlc", MISDN_CFG_HDLC, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Set this to yes, if you want to bridge a mISDN data channel to\n" | 
					
						
							|  |  |  | 		"\tanother channel type or to an application." }, | 
					
						
							|  |  |  | 	{ "context", MISDN_CFG_CONTEXT, MISDN_CTYPE_STR, "default", NONE, | 
					
						
							|  |  |  | 		"Context to use for incoming calls." }, | 
					
						
							|  |  |  | 	{ "language", MISDN_CFG_LANGUAGE, MISDN_CTYPE_STR, "en", NONE, | 
					
						
							|  |  |  | 		"Language." }, | 
					
						
							|  |  |  | 	{ "musicclass", MISDN_CFG_MUSICCLASS, MISDN_CTYPE_STR, "default", NONE, | 
					
						
							|  |  |  | 		"Sets the musiconhold class." }, | 
					
						
							|  |  |  | 	{ "callerid", MISDN_CFG_CALLERID, MISDN_CTYPE_STR, "", NONE, | 
					
						
							|  |  |  | 		"Sets the caller ID." }, | 
					
						
							|  |  |  | 	{ "method", MISDN_CFG_METHOD, MISDN_CTYPE_STR, "standard", NONE, | 
					
						
							|  |  |  | 		"Sets the method to use for channel selection:\n" | 
					
						
							|  |  |  | 		"\t  standard    - always choose the first free channel with the lowest number\n" | 
					
						
							|  |  |  | 		"\t  round_robin - use the round robin algorithm to select a channel. use this\n" | 
					
						
							|  |  |  | 		"\t                if you want to balance your load." }, | 
					
						
							|  |  |  | 	{ "dialplan", MISDN_CFG_DIALPLAN, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Dialplan means Type Of Number in ISDN Terms (for outgoing calls)\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tThere are different types of the dialplan:\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tdialplan -> outgoing Number\n" | 
					
						
							|  |  |  | 		"\tlocaldialplan -> callerid\n" | 
					
						
							|  |  |  | 		"\tcpndialplan -> connected party number\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tdialplan options:\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\t0 - unknown\n" | 
					
						
							|  |  |  | 		"\t1 - International\n" | 
					
						
							|  |  |  | 		"\t2 - National\n" | 
					
						
							|  |  |  | 		"\t4 - Subscriber\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tThis setting is used for outgoing calls." }, | 
					
						
							|  |  |  | 	{ "localdialplan", MISDN_CFG_LOCALDIALPLAN, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Dialplan means Type Of Number in ISDN Terms (for outgoing calls)\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tThere are different types of the dialplan:\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tdialplan -> outgoing Number\n" | 
					
						
							|  |  |  | 		"\tlocaldialplan -> callerid\n" | 
					
						
							|  |  |  | 		"\tcpndialplan -> connected party number\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tdialplan options:\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\t0 - unknown\n" | 
					
						
							|  |  |  | 		"\t1 - International\n" | 
					
						
							|  |  |  | 		"\t2 - National\n" | 
					
						
							|  |  |  | 		"\t4 - Subscriber\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tThis setting is used for outgoing calls" }, | 
					
						
							|  |  |  | 	{ "cpndialplan", MISDN_CFG_CPNDIALPLAN, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Dialplan means Type Of Number in ISDN Terms (for outgoing calls)\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tThere are different types of the dialplan:\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tdialplan -> outgoing Number\n" | 
					
						
							|  |  |  | 		"\tlocaldialplan -> callerid\n" | 
					
						
							|  |  |  | 		"\tcpndialplan -> connected party number\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tdialplan options:\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\t0 - unknown\n" | 
					
						
							|  |  |  | 		"\t1 - International\n" | 
					
						
							|  |  |  | 		"\t2 - National\n" | 
					
						
							|  |  |  | 		"\t4 - Subscriber\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tThis setting is used for outgoing calls." }, | 
					
						
							|  |  |  | 	{ "nationalprefix", MISDN_CFG_NATPREFIX, MISDN_CTYPE_STR, "0", NONE, | 
					
						
							|  |  |  | 		"Prefix for national, this is put before the\n" | 
					
						
							|  |  |  | 		"\toad if an according dialplan is set by the other end." }, | 
					
						
							|  |  |  | 	{ "internationalprefix", MISDN_CFG_INTERNATPREFIX, MISDN_CTYPE_STR, "00", NONE, | 
					
						
							|  |  |  | 		"Prefix for international, this is put before the\n" | 
					
						
							|  |  |  | 		"\toad if an according dialplan is set by the other end." }, | 
					
						
							|  |  |  | 	{ "presentation", MISDN_CFG_PRES, MISDN_CTYPE_INT, "-1", NONE, | 
					
						
							|  |  |  | 		"These (presentation and screen) are the exact isdn screening and presentation\n" | 
					
						
							|  |  |  | 		"\tindicators.\n" | 
					
						
							|  |  |  | 		"\tIf -1 is given for both values, the presentation indicators are used from\n" | 
					
						
							|  |  |  | 		"\tAsterisks SetCallerPres application.\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tscreen=0, presentation=0 -> callerid presented not screened\n" | 
					
						
							|  |  |  | 		"\tscreen=1, presentation=1 -> callerid presented but screened (the remote end doesn't see it!)" }, | 
					
						
							|  |  |  | 	{ "screen", MISDN_CFG_SCREEN, MISDN_CTYPE_INT, "-1", NONE, | 
					
						
							|  |  |  | 		"These (presentation and screen) are the exact isdn screening and presentation\n" | 
					
						
							|  |  |  | 		"\tindicators.\n" | 
					
						
							|  |  |  | 		"\tIf -1 is given for both values, the presentation indicators are used from\n" | 
					
						
							|  |  |  | 		"\tAsterisks SetCallerPres application.\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tscreen=0, presentation=0 -> callerid presented not screened\n" | 
					
						
							|  |  |  | 		"\tscreen=1, presentation=1 -> callerid presented but screened (the remote end doesn't see it!)" }, | 
					
						
							|  |  |  | 	{ "always_immediate", MISDN_CFG_ALWAYS_IMMEDIATE, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Enable this to get into the s dialplan-extension.\n" | 
					
						
							|  |  |  | 		"\tThere you can use DigitTimeout if you can't or don't want to use\n" | 
					
						
							|  |  |  | 		"\tisdn overlap dial.\n" | 
					
						
							|  |  |  | 		"\tNOTE: This will jump into the s extension for every exten!" }, | 
					
						
							| 
									
										
										
										
											2006-07-13 14:13:24 +00:00
										 |  |  | 	{ "nodialtone", MISDN_CFG_NODIALTONE, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Enable this to prevent chan_misdn to generate the dialtone\n" | 
					
						
							|  |  |  | 		"\tThis makes only sense together with the always_immediate=yes option\n" | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		"\tto generate your own dialtone with Playtones or so."}, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "immediate", MISDN_CFG_IMMEDIATE, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Enable this if you want callers which called exactly the base\n" | 
					
						
							|  |  |  | 		"\tnumber (so no extension is set) to jump into the s extension.\n" | 
					
						
							|  |  |  | 		"\tIf the user dials something more, it jumps to the correct extension\n" | 
					
						
							|  |  |  | 		"\tinstead." }, | 
					
						
							|  |  |  | 	{ "senddtmf", MISDN_CFG_SENDDTMF, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Enable this if we should produce DTMF Tones ourselves." }, | 
					
						
							| 
									
										
										
										
											2007-09-19 09:31:55 +00:00
										 |  |  | 	{ "astdtmf", MISDN_CFG_ASTDTMF, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Enable this if you want to use the Asterisk dtmf detector\n" | 
					
						
							|  |  |  | 		"instead of the mISDN_dsp/hfcmulti one." | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "hold_allowed", MISDN_CFG_HOLD_ALLOWED, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		"Enable this to have support for hold and retrieve." }, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "early_bconnect", MISDN_CFG_EARLY_BCONNECT, MISDN_CTYPE_BOOL, "yes", NONE, | 
					
						
							|  |  |  | 		"Disable this if you don't mind correct handling of Progress Indicators." }, | 
					
						
							|  |  |  | 	{ "incoming_early_audio", MISDN_CFG_INCOMING_EARLY_AUDIO, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Turn this on if you like to send Tone Indications to a Incoming\n" | 
					
						
							|  |  |  | 		"\tisdn channel on a TE Port. Rarely used, only if the Telco allows\n" | 
					
						
							|  |  |  | 		"\tyou to send indications by yourself, normally the Telco sends the\n" | 
					
						
							|  |  |  | 		"\tindications to the remote party." }, | 
					
						
							|  |  |  | 	{ "echocancel", MISDN_CFG_ECHOCANCEL, MISDN_CTYPE_BOOLINT, "0", 128, | 
					
						
							|  |  |  | 		"This enables echocancellation, with the given number of taps.\n" | 
					
						
							|  |  |  | 		"\tBe aware, move this setting only to outgoing portgroups!\n" | 
					
						
							|  |  |  | 		"\tA value of zero turns echocancellation off.\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tPossible values are: 0,32,64,128,256,yes(=128),no(=0)" }, | 
					
						
							| 
									
										
										
										
											2007-03-26 15:25:53 +00:00
										 |  |  | #ifdef MISDN_1_2
 | 
					
						
							|  |  |  | 	{ "pipeline", MISDN_CFG_PIPELINE, MISDN_CTYPE_STR, NO_DEFAULT, NONE, | 
					
						
							|  |  |  | 		"Set the configuration string for the mISDN dsp pipeline.\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tExample for enabling the mg2 echo cancellation module with deftaps\n" | 
					
						
							|  |  |  | 		"\tset to 128:\n" | 
					
						
							|  |  |  | 		"\t\tmg2ec(deftaps=128)" }, | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-08-03 16:38:00 +00:00
										 |  |  | #ifdef WITH_BEROEC
 | 
					
						
							|  |  |  | 	{ "bnechocancel", MISDN_CFG_BNECHOCANCEL, MISDN_CTYPE_BOOLINT, "yes", 64, | 
					
						
							|  |  |  | 		"echotail in ms (1-200)\n"}, | 
					
						
							|  |  |  | 	{ "bnec_antihowl", MISDN_CFG_BNEC_ANTIHOWL, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Use antihowl\n"}, | 
					
						
							|  |  |  | 	{ "bnec_nlp", MISDN_CFG_BNEC_NLP, MISDN_CTYPE_BOOL, "yes", NONE, | 
					
						
							|  |  |  | 		"Nonlinear Processing (much faster adaption)"}, | 
					
						
							|  |  |  | 	{ "bnec_zerocoeff", MISDN_CFG_BNEC_ZEROCOEFF, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"ZeroCoeffeciens\n"}, | 
					
						
							|  |  |  | 	{ "bnec_tonedisabler", MISDN_CFG_BNEC_TD, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Disable Tone\n"}, | 
					
						
							|  |  |  | 	{ "bnec_adaption", MISDN_CFG_BNEC_ADAPT, MISDN_CTYPE_INT, "1", NONE, | 
					
						
							|  |  |  | 		"Adaption mode (0=no,1=full,2=fast)\n"}, | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "need_more_infos", MISDN_CFG_NEED_MORE_INFOS, MISDN_CTYPE_BOOL, "0", NONE, | 
					
						
							|  |  |  | 		"Send Setup_Acknowledge on incoming calls anyway (instead of PROCEEDING),\n" | 
					
						
							|  |  |  | 		"\tthis requests additional Infos, so we can waitfordigits without much\n" | 
					
						
							|  |  |  | 		"\tissues. This works only for PTP Ports" }, | 
					
						
							| 
									
										
										
										
											2007-04-03 07:20:27 +00:00
										 |  |  | 	{ "noautorespond_on_setup", MISDN_CFG_NOAUTORESPOND_ON_SETUP, MISDN_CTYPE_BOOL, "0", NONE, | 
					
						
							|  |  |  | 		"Do not send SETUP_ACKNOWLEDGE or PROCEEDING automatically to the calling Party.\n" | 
					
						
							|  |  |  | 		"Instead we directly jump into the dialplan. This might be useful for fast call\n" | 
					
						
							|  |  |  | 		"rejection, or for some broken switches, that need hangup causes like busy in the.\n" | 
					
						
							|  |  |  | 		"RELEASE_COMPLETE Message, instead of the DISCONNECT Message.\n"}, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "jitterbuffer", MISDN_CFG_JITTERBUFFER, MISDN_CTYPE_INT, "4000", NONE, | 
					
						
							|  |  |  | 		"The jitterbuffer." }, | 
					
						
							|  |  |  | 	{ "jitterbuffer_upper_threshold", MISDN_CFG_JITTERBUFFER_UPPER_THRESHOLD, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Change this threshold to enable dejitter functionality." }, | 
					
						
							|  |  |  | 	{ "callgroup", MISDN_CFG_CALLGROUP, MISDN_CTYPE_ASTGROUP, NO_DEFAULT, NONE, | 
					
						
							|  |  |  | 		"Callgroup." }, | 
					
						
							|  |  |  | 	{ "pickupgroup", MISDN_CFG_PICKUPGROUP, MISDN_CTYPE_ASTGROUP, NO_DEFAULT, NONE, | 
					
						
							|  |  |  | 		"Pickupgroup." }, | 
					
						
							|  |  |  | 	{ "max_incoming", MISDN_CFG_MAX_IN, MISDN_CTYPE_INT, "-1", NONE, | 
					
						
							|  |  |  | 		"Defines the maximum amount of incoming calls per port for this group.\n" | 
					
						
							|  |  |  | 		"\tCalls which exceed the maximum will be marked with the channel varible\n" | 
					
						
							|  |  |  | 		"\tMAX_OVERFLOW. It will contain the amount of overflowed calls" }, | 
					
						
							|  |  |  | 	{ "max_outgoing", MISDN_CFG_MAX_OUT, MISDN_CTYPE_INT, "-1", NONE, | 
					
						
							|  |  |  | 		"Defines the maximum amount of outgoing calls per port for this group\n" | 
					
						
							|  |  |  | 		"\texceeding calls will be rejected" }, | 
					
						
							| 
									
										
										
										
											2006-10-06 12:50:25 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	{ "reject_cause", MISDN_CFG_REJECT_CAUSE, MISDN_CTYPE_INT, "21", NONE, | 
					
						
							|  |  |  | 		"Defines the cause with which a 3. call is rejected on PTMP BRI."}, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "faxdetect", MISDN_CFG_FAXDETECT, MISDN_CTYPE_STR, "no", NONE, | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		"Setup fax detection:\n" | 
					
						
							|  |  |  | 		"\t    no        - no fax detection\n" | 
					
						
							|  |  |  | 		"\t    incoming  - fax detection for incoming calls\n" | 
					
						
							|  |  |  | 		"\t    outgoing  - fax detection for outgoing calls\n" | 
					
						
							|  |  |  | 		"\t    both      - fax detection for incoming and outgoing calls\n" | 
					
						
							|  |  |  | 		"\tAdd +nojump to your value (i.e. faxdetect=both+nojump) if you don't want to jump into the\n" | 
					
						
							|  |  |  | 		"\tfax-extension but still want to detect the fax and prepare the channel for fax transfer." }, | 
					
						
							|  |  |  | 	{ "faxdetect_timeout", MISDN_CFG_FAXDETECT_TIMEOUT, MISDN_CTYPE_INT, "5", NONE, | 
					
						
							|  |  |  | 		"Number of seconds the fax detection should do its job. After the given period of time,\n" | 
					
						
							|  |  |  | 		"\twe assume that it's not a fax call and save some CPU time by turning off fax detection.\n" | 
					
						
							|  |  |  | 		"\tSet this to 0 if you don't want a timeout (never stop detecting)." }, | 
					
						
							|  |  |  | 	{ "faxdetect_context", MISDN_CFG_FAXDETECT_CONTEXT, MISDN_CTYPE_STR, NO_DEFAULT, NONE, | 
					
						
							|  |  |  | 		"Context to jump into if we detect a fax. Don't set this if you want to stay in the current context." }, | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 	{ "l1watcher_timeout", MISDN_CFG_L1_TIMEOUT, MISDN_CTYPE_BOOLINT, "0", 4, | 
					
						
							|  |  |  | 		"Watches the layer 1. If the layer 1 is down, it tries to\n" | 
					
						
							|  |  |  | 		"\tget it up. The timeout is given in seconds. with 0 as value it\n" | 
					
						
							|  |  |  | 		"\tdoes not watch the l1 at all\n" | 
					
						
							|  |  |  | 		"\n" | 
					
						
							|  |  |  | 		"\tThis option is only read at loading time of chan_misdn, which\n" | 
					
						
							|  |  |  | 		"\tmeans you need to unload and load chan_misdn to change the value,\n" | 
					
						
							|  |  |  | 		"\tan Asterisk restart should do the trick." }, | 
					
						
							| 
									
										
										
										
											2006-08-09 09:24:21 +00:00
										 |  |  | 	{ "overlapdial", MISDN_CFG_OVERLAP_DIAL, MISDN_CTYPE_BOOLINT, "0", 4, | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 		"Enables overlap dial for the given amount of seconds.\n" | 
					
						
							|  |  |  | 		"\tPossible values are positive integers or:\n" | 
					
						
							|  |  |  | 		"\t   yes (= 4 seconds)\n" | 
					
						
							|  |  |  | 		"\t   no  (= 0 seconds = disabled)" }, | 
					
						
							| 
									
										
										
										
											2006-10-27 09:58:44 +00:00
										 |  |  | 	{ "nttimeout", MISDN_CFG_NTTIMEOUT, MISDN_CTYPE_BOOL, "no", NONE , | 
					
						
							| 
									
										
										
										
											2006-10-27 09:49:20 +00:00
										 |  |  | 		"Set this to yes if you want calls disconnected in overlap mode"  | 
					
						
							|  |  |  | 		"when a timeout happens.\n"}, | 
					
						
							| 
									
										
										
										
											2007-06-05 10:25:32 +00:00
										 |  |  | 	{ "bridging", MISDN_CFG_BRIDGING, MISDN_CTYPE_BOOL, "yes", NONE, | 
					
						
							|  |  |  | 	 	"Set this to yes/no, default is yes.\n" | 
					
						
							|  |  |  | 		"This can be used to have bridging enabled in general and to\n" | 
					
						
							|  |  |  | 		"disable it for specific ports. It makes sense to disable\n" | 
					
						
							|  |  |  | 		"bridging on NT Port where you plan to use the HOLD/RETRIEVE\n" | 
					
						
							|  |  |  | 		"features with ISDN phones.\n" | 
					
						
							|  |  |  | 		}, | 
					
						
							| 
									
										
										
										
											2007-04-10 12:43:40 +00:00
										 |  |  | 	{ "msns", MISDN_CFG_MSNS, MISDN_CTYPE_MSNLIST, "*", NONE, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 		"MSN's for TE ports, listen on those numbers on the above ports, and\n" | 
					
						
							|  |  |  | 		"\tindicate the incoming calls to Asterisk.\n" | 
					
						
							|  |  |  | 		"\tHere you can give a comma seperated list, or simply an '*' for any msn." }, | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static const struct misdn_cfg_spec gen_spec[] = { | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "debug", MISDN_GEN_DEBUG, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							|  |  |  | 		"Sets the debugging flag:\n" | 
					
						
							|  |  |  | 		"\t0 - No Debug\n" | 
					
						
							|  |  |  | 		"\t1 - mISDN Messages and * - Messages, and * - State changes\n" | 
					
						
							|  |  |  | 		"\t2 - Messages + Message specific Informations (e.g. bearer capability)\n" | 
					
						
							|  |  |  | 		"\t3 - very Verbose, the above + lots of Driver specific infos\n" | 
					
						
							|  |  |  | 		"\t4 - even more Verbose than 3" }, | 
					
						
							| 
									
										
										
										
											2007-04-03 11:02:46 +00:00
										 |  |  | #ifndef MISDN_1_2
 | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "misdn_init", MISDN_GEN_MISDN_INIT, MISDN_CTYPE_STR, "/etc/misdn-init.conf", NONE, | 
					
						
							|  |  |  | 		"Set the path to the misdn-init.conf (for nt_ptp mode checking)." }, | 
					
						
							| 
									
										
										
										
											2007-04-03 11:02:46 +00:00
										 |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "tracefile", MISDN_GEN_TRACEFILE, MISDN_CTYPE_STR, "/var/log/asterisk/misdn.log", NONE, | 
					
						
							|  |  |  | 		"Set the path to the massively growing trace file, if you want that." }, | 
					
						
							|  |  |  | 	{ "bridging", MISDN_GEN_BRIDGING, MISDN_CTYPE_BOOL, "yes", NONE, | 
					
						
							|  |  |  | 		"Set this to yes if you want mISDN_dsp to bridge the calls in HW." }, | 
					
						
							|  |  |  | 	{ "stop_tone_after_first_digit", MISDN_GEN_STOP_TONE, MISDN_CTYPE_BOOL, "yes", NONE, | 
					
						
							|  |  |  | 		"Stops dialtone after getting first digit on NT Port." }, | 
					
						
							|  |  |  | 	{ "append_digits2exten", MISDN_GEN_APPEND_DIGITS2EXTEN, MISDN_CTYPE_BOOL, "yes", NONE, | 
					
						
							|  |  |  | 		"Wether to append overlapdialed Digits to Extension or not." }, | 
					
						
							|  |  |  | 	{ "dynamic_crypt", MISDN_GEN_DYNAMIC_CRYPT, MISDN_CTYPE_BOOL, "no", NONE, | 
					
						
							|  |  |  | 		"Wether to look out for dynamic crypting attempts." }, | 
					
						
							|  |  |  | 	{ "crypt_prefix", MISDN_GEN_CRYPT_PREFIX, MISDN_CTYPE_STR, NO_DEFAULT, NONE, | 
					
						
							|  |  |  | 		"What is used for crypting Protocol." }, | 
					
						
							|  |  |  | 	{ "crypt_keys", MISDN_GEN_CRYPT_KEYS, MISDN_CTYPE_STR, NO_DEFAULT, NONE, | 
					
						
							|  |  |  | 		"Keys for cryption, you reference them in the dialplan\n" | 
					
						
							|  |  |  | 		"\tLater also in dynamic encr." }, | 
					
						
							| 
									
										
										
										
											2007-11-12 09:45:36 +00:00
										 |  |  |  	{ "ntkeepcalls", MISDN_GEN_NTKEEPCALLS, MISDN_CTYPE_BOOL, "no", NONE,  | 
					
						
							|  |  |  | 		"avoid dropping calls if the L2 goes down. some nortel pbx\n"  | 
					
						
							|  |  |  | 		"do put down the L2/L1 for some milliseconds even if there\n" | 
					
						
							|  |  |  | 		"are running calls. with this option you can avoid dropping them\n" }, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "ntdebugflags", MISDN_GEN_NTDEBUGFLAGS, MISDN_CTYPE_INT, "0", NONE, | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 	  	"No description yet."}, | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	{ "ntdebugfile", MISDN_GEN_NTDEBUGFILE, MISDN_CTYPE_STR, "/var/log/misdn-nt.log", NONE, | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 	  	"No description yet." } | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | /* array of port configs, default is at position 0. */ | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static union misdn_cfg_pt **port_cfg; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | /* max number of available ports, is set on init */ | 
					
						
							|  |  |  | static int max_ports; | 
					
						
							|  |  |  | /* general config */ | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static union misdn_cfg_pt *general_cfg; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | /* storing the ptp flag separated to save memory */ | 
					
						
							|  |  |  | static int *ptp; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | /* maps enum config elements to array positions */ | 
					
						
							|  |  |  | static int *map; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | static ast_mutex_t config_mutex;  | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | #define CLI_ERROR(name, value, section) ({ \
 | 
					
						
							|  |  |  | 	ast_log(LOG_WARNING, "misdn.conf: \"%s=%s\" (section: %s) invalid or out of range. " \ | 
					
						
							|  |  |  | 		"Please edit your misdn.conf and then do a \"misdn reload\".\n", name, value, section); \ | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | static int _enum_array_map (void) | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 	int i, j, ok; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (i = MISDN_CFG_FIRST + 1; i < MISDN_CFG_LAST; ++i) { | 
					
						
							|  |  |  | 		if (i == MISDN_CFG_PTP) | 
					
						
							|  |  |  | 			continue; | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		ok = 0; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		for (j = 0; j < NUM_PORT_ELEMENTS; ++j) { | 
					
						
							|  |  |  | 			if (port_spec[j].elem == i) { | 
					
						
							|  |  |  | 				map[i] = j; | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 				ok = 1; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		if (!ok) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (port section) has no corresponding element in the config struct!\n", i); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	for (i = MISDN_GEN_FIRST + 1; i < MISDN_GEN_LAST; ++i) { | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		ok = 0; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		for (j = 0; j < NUM_GEN_ELEMENTS; ++j) { | 
					
						
							|  |  |  | 			if (gen_spec[j].elem == i) { | 
					
						
							|  |  |  | 				map[i] = j; | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 				ok = 1; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		if (!ok) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Enum element %d in misdn_cfg_elements (general section) has no corresponding element in the config struct!\n", i); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int get_cfg_position (char *name, int type) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	switch (type) { | 
					
						
							|  |  |  | 	case PORT_CFG: | 
					
						
							|  |  |  | 		for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { | 
					
						
							|  |  |  | 			if (!strcasecmp(name, port_spec[i].name)) | 
					
						
							|  |  |  | 				return i; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case GEN_CFG: | 
					
						
							|  |  |  | 		for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { | 
					
						
							|  |  |  | 			if (!strcasecmp(name, gen_spec[i].name)) | 
					
						
							|  |  |  | 				return i; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline void misdn_cfg_lock (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	ast_mutex_lock(&config_mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static inline void misdn_cfg_unlock (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	ast_mutex_unlock(&config_mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static void _free_msn_list (struct msn_list* iter) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	if (iter->next) | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		_free_msn_list(iter->next); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	if (iter->msn) | 
					
						
							|  |  |  | 		free(iter->msn); | 
					
						
							|  |  |  | 	free(iter); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static void _free_port_cfg (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	int i, j; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	int gn = map[MISDN_CFG_GROUPNAME]; | 
					
						
							| 
									
										
										
										
											2006-02-22 16:48:25 +00:00
										 |  |  | 	union misdn_cfg_pt* free_list[max_ports + 2]; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	memset(free_list, 0, sizeof(free_list)); | 
					
						
							|  |  |  | 	free_list[0] = port_cfg[0]; | 
					
						
							|  |  |  | 	for (i = 1; i <= max_ports; ++i) { | 
					
						
							|  |  |  | 		if (port_cfg[i][gn].str) { | 
					
						
							|  |  |  | 			/* we always have a groupname in the non-default case, so this is fine */ | 
					
						
							|  |  |  | 			for (j = 1; j <= max_ports; ++j) { | 
					
						
							|  |  |  | 				if (free_list[j] && free_list[j][gn].str == port_cfg[i][gn].str) | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				else if (!free_list[j]) { | 
					
						
							|  |  |  | 					free_list[j] = port_cfg[i]; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	for (j = 0; free_list[j]; ++j) { | 
					
						
							|  |  |  | 		for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { | 
					
						
							|  |  |  | 			if (free_list[j][i].any) { | 
					
						
							|  |  |  | 				if (port_spec[i].type == MISDN_CTYPE_MSNLIST) | 
					
						
							|  |  |  | 					_free_msn_list(free_list[j][i].ml); | 
					
						
							|  |  |  | 				else | 
					
						
							|  |  |  | 					free(free_list[j][i].any); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static void _free_general_cfg (void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	for (i = 0; i < NUM_GEN_ELEMENTS; i++)  | 
					
						
							|  |  |  | 		if (general_cfg[i].any) | 
					
						
							|  |  |  | 			free(general_cfg[i].any); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_cfg_get (int port, enum misdn_cfg_elements elem, void *buf, int bufsize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int place; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		memset(buf, 0, bufsize); | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Port number %d is not valid.\n", port); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	misdn_cfg_lock(); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	if (elem == MISDN_CFG_PTP) { | 
					
						
							|  |  |  | 		if (!memcpy(buf, &ptp[port], (bufsize > ptp[port]) ? sizeof(ptp[port]) : bufsize)) | 
					
						
							|  |  |  | 			memset(buf, 0, bufsize); | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		if ((place = map[elem]) < 0) { | 
					
						
							|  |  |  | 			memset (buf, 0, bufsize); | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get! Invalid element (%d) requested.\n", elem); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			if (elem < MISDN_CFG_LAST) { | 
					
						
							|  |  |  | 				switch (port_spec[place].type) { | 
					
						
							|  |  |  | 				case MISDN_CTYPE_STR: | 
					
						
							|  |  |  | 					if (port_cfg[port][place].str) { | 
					
						
							|  |  |  | 						if (!memccpy(buf, port_cfg[port][place].str, 0, bufsize)) | 
					
						
							|  |  |  | 							memset(buf, 0, 1); | 
					
						
							|  |  |  | 					} else if (port_cfg[0][place].str) { | 
					
						
							|  |  |  | 						if (!memccpy(buf, port_cfg[0][place].str, 0, bufsize)) | 
					
						
							|  |  |  | 							memset(buf, 0, 1); | 
					
						
							| 
									
										
										
										
											2008-01-29 17:41:43 +00:00
										 |  |  | 					} else | 
					
						
							|  |  |  | 						memset(buf, 0, bufsize); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					if (port_cfg[port][place].any) | 
					
						
							|  |  |  | 						memcpy(buf, port_cfg[port][place].any, bufsize); | 
					
						
							|  |  |  | 					else if (port_cfg[0][place].any) | 
					
						
							|  |  |  | 						memcpy(buf, port_cfg[0][place].any, bufsize); | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						memset(buf, 0, bufsize); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				switch (gen_spec[place].type) { | 
					
						
							|  |  |  | 				case MISDN_CTYPE_STR: | 
					
						
							|  |  |  | 					if (!general_cfg[place].str || !memccpy(buf, general_cfg[place].str, 0, bufsize)) | 
					
						
							|  |  |  | 						memset(buf, 0, 1); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				default: | 
					
						
							|  |  |  | 					if (general_cfg[place].any) | 
					
						
							|  |  |  | 						memcpy(buf, general_cfg[place].any, bufsize); | 
					
						
							|  |  |  | 					else | 
					
						
							|  |  |  | 						memset(buf, 0, bufsize); | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | enum misdn_cfg_elements misdn_cfg_get_elem (char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int pos; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ | 
					
						
							|  |  |  | 	if (!strcmp(name, "ports")) | 
					
						
							|  |  |  | 		return MISDN_CFG_GROUPNAME; | 
					
						
							|  |  |  | 	if (!strcmp(name, "name")) | 
					
						
							|  |  |  | 		return MISDN_CFG_FIRST; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	pos = get_cfg_position (name, PORT_CFG); | 
					
						
							|  |  |  | 	if (pos >= 0) | 
					
						
							|  |  |  | 		return port_spec[pos].elem; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	pos = get_cfg_position (name, GEN_CFG); | 
					
						
							|  |  |  | 	if (pos >= 0) | 
					
						
							|  |  |  | 		return gen_spec[pos].elem; | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	return MISDN_CFG_FIRST; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void misdn_cfg_get_name (enum misdn_cfg_elements elem, void *buf, int bufsize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	struct misdn_cfg_spec *spec = NULL; | 
					
						
							|  |  |  | 	int place = map[elem]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* the ptp hack */ | 
					
						
							|  |  |  | 	if (elem == MISDN_CFG_PTP) { | 
					
						
							|  |  |  | 		memset(buf, 0, 1); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	/* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ | 
					
						
							|  |  |  | 	if (elem == MISDN_CFG_GROUPNAME) { | 
					
						
							|  |  |  | 		if (!snprintf(buf, bufsize, "ports")) | 
					
						
							|  |  |  | 			memset(buf, 0, 1); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	 | 
					
						
							|  |  |  | 	if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST)) | 
					
						
							|  |  |  | 		spec = (struct misdn_cfg_spec *)port_spec; | 
					
						
							|  |  |  | 	else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST)) | 
					
						
							|  |  |  | 		spec = (struct misdn_cfg_spec *)gen_spec; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!spec || !memccpy(buf, spec[place].name, 0, bufsize)) | 
					
						
							|  |  |  | 		memset(buf, 0, 1); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void misdn_cfg_get_desc (enum misdn_cfg_elements elem, void *buf, int bufsize, void *buf_default, int bufsize_default) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int place = map[elem]; | 
					
						
							|  |  |  | 	struct misdn_cfg_spec *spec = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* here comes a hack to replace the (not existing) "name" elemet with the "ports" element */ | 
					
						
							|  |  |  | 	if (elem == MISDN_CFG_GROUPNAME) { | 
					
						
							|  |  |  | 		if (!memccpy(buf, ports_description, 0, bufsize)) | 
					
						
							|  |  |  | 			memset(buf, 0, 1); | 
					
						
							|  |  |  | 		if (buf_default && bufsize_default) | 
					
						
							|  |  |  | 			memset(buf_default, 0, 1); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((elem > MISDN_CFG_FIRST) && (elem < MISDN_CFG_LAST)) | 
					
						
							|  |  |  | 		spec = (struct misdn_cfg_spec *)port_spec; | 
					
						
							|  |  |  | 	else if ((elem > MISDN_GEN_FIRST) && (elem < MISDN_GEN_LAST)) | 
					
						
							|  |  |  | 		spec = (struct misdn_cfg_spec *)gen_spec; | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 	if (!spec || !spec[place].desc) | 
					
						
							|  |  |  | 		memset(buf, 0, 1); | 
					
						
							|  |  |  | 	else { | 
					
						
							|  |  |  | 		if (!memccpy(buf, spec[place].desc, 0, bufsize)) | 
					
						
							|  |  |  | 			memset(buf, 0, 1); | 
					
						
							|  |  |  | 		if (buf_default && bufsize) { | 
					
						
							|  |  |  | 			if (!strcmp(spec[place].def, NO_DEFAULT)) | 
					
						
							|  |  |  | 				memset(buf_default, 0, 1); | 
					
						
							|  |  |  | 			else if (!memccpy(buf_default, spec[place].def, 0, bufsize_default)) | 
					
						
							|  |  |  | 				memset(buf_default, 0, 1); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | int misdn_cfg_is_msn_valid (int port, char* msn) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int re = 0; | 
					
						
							|  |  |  | 	struct msn_list *iter; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	if (!misdn_cfg_is_port_valid(port)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid call to misdn_cfg_is_msn_valid! Port number %d is not valid.\n", port); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	misdn_cfg_lock(); | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 	if (port_cfg[port][map[MISDN_CFG_MSNS]].ml) | 
					
						
							|  |  |  | 		iter = port_cfg[port][map[MISDN_CFG_MSNS]].ml; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 		iter = port_cfg[0][map[MISDN_CFG_MSNS]].ml; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	for (; iter; iter = iter->next)  | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 		if (*(iter->msn) == '*' || ast_extension_match(iter->msn, msn)) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			re = 1; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	return re; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | int misdn_cfg_is_port_valid (int port) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-07-03 16:41:43 +00:00
										 |  |  | 	int gn = map[MISDN_CFG_GROUPNAME]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return (port >= 1 && port <= max_ports && port_cfg[port][gn].str); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | int misdn_cfg_is_group_method (char *group, enum misdn_cfg_method meth) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	int i, re = 0; | 
					
						
							| 
									
										
										
										
											2007-03-20 13:16:06 +00:00
										 |  |  | 	char *method ; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	misdn_cfg_lock(); | 
					
						
							| 
									
										
										
										
											2007-03-20 13:16:06 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	method = port_cfg[0][map[MISDN_CFG_METHOD]].str; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	for (i = 1; i <= max_ports; i++) { | 
					
						
							|  |  |  | 		if (port_cfg[i] && port_cfg[i][map[MISDN_CFG_GROUPNAME]].str) { | 
					
						
							|  |  |  | 			if (!strcasecmp(port_cfg[i][map[MISDN_CFG_GROUPNAME]].str, group)) | 
					
						
							|  |  |  | 				method = (port_cfg[i][map[MISDN_CFG_METHOD]].str ?  | 
					
						
							|  |  |  | 						  port_cfg[i][map[MISDN_CFG_METHOD]].str : port_cfg[0][map[MISDN_CFG_METHOD]].str); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-03-20 13:16:06 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	if (method) { | 
					
						
							|  |  |  | 		switch (meth) { | 
					
						
							|  |  |  | 		case METHOD_STANDARD:		re = !strcasecmp(method, "standard"); | 
					
						
							|  |  |  | 									break; | 
					
						
							|  |  |  | 		case METHOD_ROUND_ROBIN:	re = !strcasecmp(method, "round_robin"); | 
					
						
							|  |  |  | 									break; | 
					
						
							| 
									
										
										
										
											2007-03-20 13:16:06 +00:00
										 |  |  | 		case METHOD_STANDARD_DEC:	re = !strcasecmp(method, "standard_dec"); | 
					
						
							|  |  |  | 									break; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	return re; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_cfg_get_ports_string (char *ports) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	char tmp[16]; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	int l, i; | 
					
						
							|  |  |  | 	int gn = map[MISDN_CFG_GROUPNAME]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	*ports = 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	misdn_cfg_lock(); | 
					
						
							|  |  |  | 	for (i = 1; i <= max_ports; i++) { | 
					
						
							|  |  |  | 		if (port_cfg[i][gn].str) { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 			if (ptp[i]) | 
					
						
							|  |  |  | 				sprintf(tmp, "%dptp,", i); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				sprintf(tmp, "%d,", i); | 
					
						
							|  |  |  | 			strcat(ports, tmp); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((l = strlen(ports))) | 
					
						
							|  |  |  | 		ports[l-1] = 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_cfg_get_config_string (int port, enum misdn_cfg_elements elem, char* buf, int bufsize) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int place; | 
					
						
							|  |  |  | 	char tempbuf[BUFFERSIZE] = ""; | 
					
						
							|  |  |  | 	struct msn_list *iter; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if ((elem < MISDN_CFG_LAST) && !misdn_cfg_is_port_valid(port)) { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		*buf = 0; | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Port number %d is not valid.\n", port); | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	place = map[elem]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	misdn_cfg_lock(); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	if (elem == MISDN_CFG_PTP) { | 
					
						
							|  |  |  | 		snprintf(buf, bufsize, " -> ptp: %s", ptp[port] ? "yes" : "no"); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else if (elem > MISDN_CFG_FIRST && elem < MISDN_CFG_LAST) { | 
					
						
							|  |  |  | 		switch (port_spec[place].type) { | 
					
						
							|  |  |  | 		case MISDN_CTYPE_INT: | 
					
						
							|  |  |  | 		case MISDN_CTYPE_BOOLINT: | 
					
						
							|  |  |  | 			if (port_cfg[port][place].num) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[port][place].num); | 
					
						
							|  |  |  | 			else if (port_cfg[0][place].num) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %d", port_spec[place].name, *port_cfg[0][place].num); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s:", port_spec[place].name); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		case MISDN_CTYPE_BOOL: | 
					
						
							|  |  |  | 			if (port_cfg[port][place].num) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[port][place].num ? "yes" : "no"); | 
					
						
							|  |  |  | 			else if (port_cfg[0][place].num) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, *port_cfg[0][place].num ? "yes" : "no"); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s:", port_spec[place].name); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MISDN_CTYPE_ASTGROUP: | 
					
						
							|  |  |  | 			if (port_cfg[port][place].grp) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,  | 
					
						
							|  |  |  | 						 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[port][place].grp)); | 
					
						
							|  |  |  | 			else if (port_cfg[0][place].grp) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name,  | 
					
						
							|  |  |  | 						 ast_print_group(tempbuf, sizeof(tempbuf), *port_cfg[0][place].grp)); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s:", port_spec[place].name); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MISDN_CTYPE_MSNLIST: | 
					
						
							|  |  |  | 			if (port_cfg[port][place].ml) | 
					
						
							|  |  |  | 				iter = port_cfg[port][place].ml; | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				iter = port_cfg[0][place].ml; | 
					
						
							|  |  |  | 			if (iter) { | 
					
						
							|  |  |  | 				for (; iter; iter = iter->next) | 
					
						
							|  |  |  | 					sprintf(tempbuf, "%s%s, ", tempbuf, iter->msn); | 
					
						
							|  |  |  | 				tempbuf[strlen(tempbuf)-2] = 0; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			snprintf(buf, bufsize, " -> msns: %s", *tempbuf ? tempbuf : "none"); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MISDN_CTYPE_STR: | 
					
						
							|  |  |  | 			if ( port_cfg[port][place].str) { | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[port][place].str); | 
					
						
							|  |  |  | 			} else if (port_cfg[0][place].str) { | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", port_spec[place].name, port_cfg[0][place].str); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s:", port_spec[place].name); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else if (elem > MISDN_GEN_FIRST && elem < MISDN_GEN_LAST) { | 
					
						
							|  |  |  | 		switch (gen_spec[place].type) { | 
					
						
							|  |  |  | 		case MISDN_CTYPE_INT: | 
					
						
							|  |  |  | 		case MISDN_CTYPE_BOOLINT: | 
					
						
							|  |  |  | 			if (general_cfg[place].num) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %d", gen_spec[place].name, *general_cfg[place].num); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MISDN_CTYPE_BOOL: | 
					
						
							|  |  |  | 			if (general_cfg[place].num) | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, *general_cfg[place].num ? "yes" : "no"); | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		case MISDN_CTYPE_STR: | 
					
						
							|  |  |  | 			if ( general_cfg[place].str) { | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s: %s", gen_spec[place].name, general_cfg[place].str); | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				snprintf(buf, bufsize, " -> %s:", gen_spec[place].name); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		default: | 
					
						
							|  |  |  | 			snprintf(buf, bufsize, " -> type of %s not handled yet", gen_spec[place].name); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else { | 
					
						
							|  |  |  | 		*buf = 0; | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid call to misdn_cfg_get_config_string! Invalid config element (%d) requested.\n", elem); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | int misdn_cfg_get_next_port (int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int p = -1; | 
					
						
							|  |  |  | 	int gn = map[MISDN_CFG_GROUPNAME]; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	 | 
					
						
							|  |  |  | 	misdn_cfg_lock(); | 
					
						
							|  |  |  | 	for (port++; port <= max_ports; port++) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		if (port_cfg[port][gn].str) { | 
					
						
							|  |  |  | 			p = port; | 
					
						
							|  |  |  | 			break; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	return p; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | int misdn_cfg_get_next_port_spin (int port) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int p = misdn_cfg_get_next_port(port); | 
					
						
							|  |  |  | 	return (p > 0) ? p : misdn_cfg_get_next_port(0); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static int _parse (union misdn_cfg_pt *dest, char *value, enum misdn_cfg_type type, int boolint_def) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int re = 0; | 
					
						
							|  |  |  | 	int len, tmp; | 
					
						
							|  |  |  | 	char *valtmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	switch (type) { | 
					
						
							|  |  |  | 	case MISDN_CTYPE_STR: | 
					
						
							|  |  |  | 		if ((len = strlen(value))) { | 
					
						
							|  |  |  | 			dest->str = (char *)malloc((len + 1) * sizeof(char)); | 
					
						
							|  |  |  | 			strncpy(dest->str, value, len); | 
					
						
							|  |  |  | 			dest->str[len] = 0; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			dest->str = (char *)malloc( sizeof(char)); | 
					
						
							|  |  |  | 			dest->str[0] = 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MISDN_CTYPE_INT: | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 	{ | 
					
						
							|  |  |  | 		char *pat; | 
					
						
							|  |  |  | 		if (strchr(value,'x'))  | 
					
						
							|  |  |  | 			pat="%x"; | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			pat="%d"; | 
					
						
							|  |  |  | 		if (sscanf(value, pat, &tmp)) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			dest->num = (int *)malloc(sizeof(int)); | 
					
						
							|  |  |  | 			memcpy(dest->num, &tmp, sizeof(int)); | 
					
						
							|  |  |  | 		} else | 
					
						
							|  |  |  | 			re = -1; | 
					
						
							| 
									
										
										
										
											2006-06-29 20:12:19 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		break; | 
					
						
							|  |  |  | 	case MISDN_CTYPE_BOOL: | 
					
						
							|  |  |  | 		dest->num = (int *)malloc(sizeof(int)); | 
					
						
							|  |  |  | 		*(dest->num) = (ast_true(value) ? 1 : 0); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MISDN_CTYPE_BOOLINT: | 
					
						
							|  |  |  | 		dest->num = (int *)malloc(sizeof(int)); | 
					
						
							|  |  |  | 		if (sscanf(value, "%d", &tmp)) { | 
					
						
							|  |  |  | 			memcpy(dest->num, &tmp, sizeof(int)); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			*(dest->num) = (ast_true(value) ? boolint_def : 0); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MISDN_CTYPE_MSNLIST: | 
					
						
							|  |  |  | 		for (valtmp = strsep(&value, ","); valtmp; valtmp = strsep(&value, ",")) { | 
					
						
							|  |  |  | 			if ((len = strlen(valtmp))) { | 
					
						
							|  |  |  | 				struct msn_list *ml = (struct msn_list *)malloc(sizeof(struct msn_list)); | 
					
						
							|  |  |  | 				ml->msn = (char *)calloc(len+1, sizeof(char)); | 
					
						
							|  |  |  | 				strncpy(ml->msn, valtmp, len); | 
					
						
							|  |  |  | 				ml->next = dest->ml; | 
					
						
							|  |  |  | 				dest->ml = ml; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case MISDN_CTYPE_ASTGROUP: | 
					
						
							|  |  |  | 		dest->grp = (ast_group_t *)malloc(sizeof(ast_group_t)); | 
					
						
							|  |  |  | 		*(dest->grp) = ast_get_group(value); | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	return re; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static void _build_general_config (struct ast_variable *v) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int pos; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (; v; v = v->next) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		if (((pos = get_cfg_position(v->name, GEN_CFG)) < 0) ||  | 
					
						
							|  |  |  | 			(_parse(&general_cfg[pos], v->value, gen_spec[pos].type, gen_spec[pos].boolint_def) < 0)) | 
					
						
							|  |  |  | 			CLI_ERROR(v->name, v->value, "general"); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static void _build_port_config (struct ast_variable *v, char *cat) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int pos, i; | 
					
						
							|  |  |  | 	union misdn_cfg_pt cfg_tmp[NUM_PORT_ELEMENTS]; | 
					
						
							|  |  |  | 	int cfg_for_ports[max_ports + 1]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	if (!v || !cat) | 
					
						
							|  |  |  | 		return; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	memset(cfg_tmp, 0, sizeof(cfg_tmp)); | 
					
						
							|  |  |  | 	memset(cfg_for_ports, 0, sizeof(cfg_for_ports)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	if (!strcasecmp(cat, "default")) { | 
					
						
							|  |  |  | 		cfg_for_ports[0] = 1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	if (((pos = get_cfg_position("name", PORT_CFG)) < 0) ||  | 
					
						
							|  |  |  | 		(_parse(&cfg_tmp[pos], cat, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) { | 
					
						
							|  |  |  | 		CLI_ERROR(v->name, v->value, cat); | 
					
						
							|  |  |  | 		return; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (; v; v = v->next) { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		if (!strcasecmp(v->name, "ports")) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			char *token; | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 			char ptpbuf[BUFFERSIZE] = ""; | 
					
						
							|  |  |  | 			int start, end; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			for (token = strsep(&v->value, ","); token; token = strsep(&v->value, ","), *ptpbuf = 0) {  | 
					
						
							|  |  |  | 				if (!*token) | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 					continue; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 				if (sscanf(token, "%d-%d%s", &start, &end, ptpbuf) >= 2) { | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 					for (; start <= end; start++) { | 
					
						
							|  |  |  | 						if (start <= max_ports && start > 0) { | 
					
						
							|  |  |  | 							cfg_for_ports[start] = 1; | 
					
						
							|  |  |  | 							ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; | 
					
						
							|  |  |  | 						} else | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 							CLI_ERROR(v->name, v->value, cat); | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 					} | 
					
						
							|  |  |  | 				} else { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 					if (sscanf(token, "%d%s", &start, ptpbuf)) { | 
					
						
							| 
									
										
										
										
											2005-12-09 11:01:18 +00:00
										 |  |  | 						if (start <= max_ports && start > 0) { | 
					
						
							|  |  |  | 							cfg_for_ports[start] = 1; | 
					
						
							|  |  |  | 							ptp[start] = (strstr(ptpbuf, "ptp")) ? 1 : 0; | 
					
						
							|  |  |  | 						} else | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 							CLI_ERROR(v->name, v->value, cat); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 					} else | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 						CLI_ERROR(v->name, v->value, cat); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		} else { | 
					
						
							|  |  |  | 			if (((pos = get_cfg_position(v->name, PORT_CFG)) < 0) ||  | 
					
						
							|  |  |  | 				(_parse(&cfg_tmp[pos], v->value, port_spec[pos].type, port_spec[pos].boolint_def) < 0)) | 
					
						
							|  |  |  | 				CLI_ERROR(v->name, v->value, cat); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 0; i < (max_ports + 1); ++i) { | 
					
						
							|  |  |  | 		if (cfg_for_ports[i]) { | 
					
						
							|  |  |  | 			memcpy(port_cfg[i], cfg_tmp, sizeof(cfg_tmp)); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void misdn_cfg_update_ptp (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2007-04-03 11:02:46 +00:00
										 |  |  | #ifndef MISDN_1_2
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	char misdn_init[BUFFERSIZE]; | 
					
						
							|  |  |  | 	char line[BUFFERSIZE]; | 
					
						
							|  |  |  | 	FILE *fp; | 
					
						
							|  |  |  | 	char *tok, *p, *end; | 
					
						
							|  |  |  | 	int port; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	misdn_cfg_get(0, MISDN_GEN_MISDN_INIT, &misdn_init, sizeof(misdn_init)); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-21 14:37:20 +00:00
										 |  |  | 	if (!ast_strlen_zero(misdn_init)) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		fp = fopen(misdn_init, "r"); | 
					
						
							|  |  |  | 		if (fp) { | 
					
						
							|  |  |  | 			while(fgets(line, sizeof(line), fp)) { | 
					
						
							|  |  |  | 				if (!strncmp(line, "nt_ptp", 6)) { | 
					
						
							|  |  |  | 					for (tok = strtok_r(line,",=", &p); | 
					
						
							|  |  |  | 						 tok; | 
					
						
							|  |  |  | 						 tok = strtok_r(NULL,",=", &p)) { | 
					
						
							|  |  |  | 						port = strtol(tok, &end, 10); | 
					
						
							|  |  |  | 						if (end != tok && misdn_cfg_is_port_valid(port)) { | 
					
						
							|  |  |  | 							misdn_cfg_lock(); | 
					
						
							|  |  |  | 							ptp[port] = 1; | 
					
						
							|  |  |  | 							misdn_cfg_unlock(); | 
					
						
							|  |  |  | 						} | 
					
						
							|  |  |  | 					} | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			fclose(fp); | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING,"Couldn't open %s: %s\n", misdn_init, strerror(errno)); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-04-03 11:02:46 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	int i; | 
					
						
							|  |  |  | 	int proto; | 
					
						
							|  |  |  | 	char filename[128]; | 
					
						
							|  |  |  | 	FILE *fp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (i = 1; i <= max_ports; ++i) { | 
					
						
							|  |  |  | 		snprintf(filename, sizeof(filename), "/sys/class/mISDN-stacks/st-%08x/protocol", i << 8); | 
					
						
							|  |  |  | 		fp = fopen(filename, "r"); | 
					
						
							|  |  |  | 		if (!fp) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Could not open %s: %s\n", filename, strerror(errno)); | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (fscanf(fp, "0x%08x", &proto) != 1) | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Could not parse contents of %s!\n", filename); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			ptp[i] = proto & 1<<5 ? 1 : 0; | 
					
						
							|  |  |  | 		fclose(fp); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | #endif
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | static void _fill_defaults (void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	for (i = 0; i < NUM_PORT_ELEMENTS; ++i) { | 
					
						
							|  |  |  | 		if (!port_cfg[0][i].any && strcasecmp(port_spec[i].def, NO_DEFAULT)) | 
					
						
							|  |  |  | 			_parse(&(port_cfg[0][i]), (char *)port_spec[i].def, port_spec[i].type, port_spec[i].boolint_def); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	for (i = 0; i < NUM_GEN_ELEMENTS; ++i) { | 
					
						
							|  |  |  | 		if (!general_cfg[i].any && strcasecmp(gen_spec[i].def, NO_DEFAULT)) | 
					
						
							|  |  |  | 			_parse(&(general_cfg[i]), (char *)gen_spec[i].def, gen_spec[i].type, gen_spec[i].boolint_def); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_cfg_reload (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	misdn_cfg_init (0); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | void misdn_cfg_destroy (void) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	misdn_cfg_lock(); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	_free_port_cfg(); | 
					
						
							|  |  |  | 	_free_general_cfg(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	free(port_cfg); | 
					
						
							|  |  |  | 	free(general_cfg); | 
					
						
							|  |  |  | 	free(ptp); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	free(map); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | 	ast_mutex_destroy(&config_mutex); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | int misdn_cfg_init (int this_max_ports) | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	char config[] = "misdn.conf"; | 
					
						
							|  |  |  | 	char *cat, *p; | 
					
						
							|  |  |  | 	int i; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	struct ast_config *cfg; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	struct ast_variable *v; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(cfg = AST_LOAD_CFG(config))) { | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "missing file: misdn.conf\n"); | 
					
						
							|  |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-07-11 19:30:35 +00:00
										 |  |  | 	ast_mutex_init(&config_mutex); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	misdn_cfg_lock(); | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	if (this_max_ports) { | 
					
						
							|  |  |  | 		/* this is the first run */ | 
					
						
							|  |  |  | 		max_ports = this_max_ports; | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		map = (int *)calloc(MISDN_GEN_LAST + 1, sizeof(int)); | 
					
						
							|  |  |  | 		if (_enum_array_map()) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		p = (char *)calloc(1, (max_ports + 1) * sizeof(union misdn_cfg_pt *) | 
					
						
							|  |  |  | 						   + (max_ports + 1) * NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt)); | 
					
						
							|  |  |  | 		port_cfg = (union misdn_cfg_pt **)p; | 
					
						
							|  |  |  | 		p += (max_ports + 1) * sizeof(union misdn_cfg_pt *); | 
					
						
							|  |  |  | 		for (i = 0; i <= max_ports; ++i) { | 
					
						
							|  |  |  | 			port_cfg[i] = (union misdn_cfg_pt *)p; | 
					
						
							|  |  |  | 			p += NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		general_cfg = (union misdn_cfg_pt *)calloc(1, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		ptp = (int *)calloc(max_ports + 1, sizeof(int)); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		/* misdn reload */ | 
					
						
							|  |  |  | 		_free_port_cfg(); | 
					
						
							|  |  |  | 		_free_general_cfg(); | 
					
						
							|  |  |  | 		memset(port_cfg[0], 0, NUM_PORT_ELEMENTS * sizeof(union misdn_cfg_pt) * (max_ports + 1)); | 
					
						
							|  |  |  | 		memset(general_cfg, 0, sizeof(union misdn_cfg_pt *) * NUM_GEN_ELEMENTS); | 
					
						
							|  |  |  | 		memset(ptp, 0, sizeof(int) * (max_ports + 1)); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	cat = ast_category_browse(cfg, NULL); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	while(cat) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 		v = ast_variable_browse(cfg, cat); | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		if (!strcasecmp(cat, "general")) { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			_build_general_config(v); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} else { | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 			_build_port_config(v, cat); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 		cat = ast_category_browse(cfg, cat); | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-02-02 21:15:34 +00:00
										 |  |  | 	_fill_defaults(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | 	misdn_cfg_unlock(); | 
					
						
							|  |  |  | 	AST_DESTROY_CFG(cfg); | 
					
						
							| 
									
										
										
										
											2006-08-08 18:13:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return 0; | 
					
						
							| 
									
										
										
										
											2005-10-31 22:51:12 +00:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2006-05-22 15:02:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 |