| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Asterisk -- An open source telephony toolkit. | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * Copyright (C) 1999 - 2005, Digium, Inc. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +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. | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * This program is free software, distributed under the terms of | 
					
						
							| 
									
										
										
										
											2005-09-14 20:46:50 +00:00
										 |  |  |  * the GNU General Public License Version 2. See the LICENSE file | 
					
						
							|  |  |  |  * at the top of the source tree. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  | /*! \file
 | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-10-24 20:12:06 +00:00
										 |  |  |  * \brief Program Asterisk ADSI Scripts into phone | 
					
						
							| 
									
										
										
										
											2005-12-30 21:18:06 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * \author Mark Spencer <markster@digium.com> | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  |  * | 
					
						
							| 
									
										
										
										
											2005-11-06 15:09:47 +00:00
										 |  |  |  * \ingroup applications | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-14 21:45:16 +00:00
										 |  |  | /*! \li \ref app_adsiprog.c uses the configuration file \ref adsi.conf
 | 
					
						
							| 
									
										
										
										
											2012-10-01 23:22:50 +00:00
										 |  |  |  * \addtogroup configuration_file Configuration Files | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | /*!
 | 
					
						
							| 
									
										
										
										
											2012-10-01 23:22:50 +00:00
										 |  |  |  * \page adsi.conf adsi.conf | 
					
						
							|  |  |  |  * \verbinclude adsi.conf.sample | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-09 23:53:51 +00:00
										 |  |  | /*** MODULEINFO
 | 
					
						
							|  |  |  | 	<depend>res_adsi</depend> | 
					
						
							| 
									
										
										
										
											2018-07-17 10:24:02 +00:00
										 |  |  | 	<support_level>deprecated</support_level> | 
					
						
							| 
									
										
										
										
											2007-02-09 23:53:51 +00:00
										 |  |  |  ***/ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-06-07 18:54:56 +00:00
										 |  |  | #include "asterisk.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | #include <netinet/in.h>
 | 
					
						
							|  |  |  | #include <ctype.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | #include "asterisk/paths.h" /* use ast_config_AST_CONFIG_DIR */
 | 
					
						
							| 
									
										
										
										
											2005-06-06 22:39:32 +00:00
										 |  |  | #include "asterisk/file.h"
 | 
					
						
							|  |  |  | #include "asterisk/channel.h"
 | 
					
						
							|  |  |  | #include "asterisk/pbx.h"
 | 
					
						
							|  |  |  | #include "asterisk/module.h"
 | 
					
						
							|  |  |  | #include "asterisk/adsi.h"
 | 
					
						
							|  |  |  | #include "asterisk/utils.h"
 | 
					
						
							|  |  |  | #include "asterisk/lock.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-06-07 14:55:51 +00:00
										 |  |  | static const char app[] = "ADSIProg"; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | /*** DOCUMENTATION
 | 
					
						
							|  |  |  | 	<application name="ADSIProg" language="en_US"> | 
					
						
							|  |  |  | 		<synopsis> | 
					
						
							|  |  |  | 			Load Asterisk ADSI Scripts into phone | 
					
						
							|  |  |  | 		</synopsis> | 
					
						
							|  |  |  | 		<syntax> | 
					
						
							|  |  |  | 			<parameter name="script" required="false"> | 
					
						
							|  |  |  | 				<para>adsi script to use. If not given uses the default script <filename>asterisk.adsi</filename></para> | 
					
						
							|  |  |  | 			</parameter> | 
					
						
							|  |  |  | 		</syntax> | 
					
						
							|  |  |  | 		<description> | 
					
						
							|  |  |  | 			<para>This application programs an ADSI Phone with the given script</para> | 
					
						
							|  |  |  | 		</description> | 
					
						
							| 
									
										
										
										
											2008-11-05 13:07:29 +00:00
										 |  |  | 		<see-also> | 
					
						
							|  |  |  | 			<ref type="application">GetCPEID</ref> | 
					
						
							|  |  |  | 			<ref type="filename">adsi.conf</ref> | 
					
						
							|  |  |  | 		</see-also> | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	</application> | 
					
						
							|  |  |  |  ***/ | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* #define DUMP_MESSAGES */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct adsi_event { | 
					
						
							|  |  |  | 	int id; | 
					
						
							| 
									
										
										
										
											2009-06-07 14:55:51 +00:00
										 |  |  | 	const char *name; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const struct adsi_event events[] = { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	{ 1, "CALLERID" }, | 
					
						
							|  |  |  | 	{ 2, "VMWI" }, | 
					
						
							|  |  |  | 	{ 3, "NEARANSWER" }, | 
					
						
							|  |  |  | 	{ 4, "FARANSWER" }, | 
					
						
							|  |  |  | 	{ 5, "ENDOFRING" }, | 
					
						
							|  |  |  | 	{ 6, "IDLE" }, | 
					
						
							|  |  |  | 	{ 7, "OFFHOOK" }, | 
					
						
							|  |  |  | 	{ 8, "CIDCW" }, | 
					
						
							|  |  |  | 	{ 9, "BUSY" }, | 
					
						
							|  |  |  | 	{ 10, "FARRING" }, | 
					
						
							|  |  |  | 	{ 11, "DIALTONE" }, | 
					
						
							|  |  |  | 	{ 12, "RECALL" }, | 
					
						
							|  |  |  | 	{ 13, "MESSAGE" }, | 
					
						
							|  |  |  | 	{ 14, "REORDER" }, | 
					
						
							|  |  |  | 	{ 15, "DISTINCTIVERING" }, | 
					
						
							|  |  |  | 	{ 16, "RING" }, | 
					
						
							|  |  |  | 	{ 17, "REMINDERRING" }, | 
					
						
							|  |  |  | 	{ 18, "SPECIALRING" }, | 
					
						
							|  |  |  | 	{ 19, "CODEDRING" }, | 
					
						
							|  |  |  | 	{ 20, "TIMER" }, | 
					
						
							|  |  |  | 	{ 21, "INUSE" }, | 
					
						
							|  |  |  | 	{ 22, "EVENT22" }, | 
					
						
							|  |  |  | 	{ 23, "EVENT23" }, | 
					
						
							|  |  |  | 	{ 24, "CPEID" }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const struct adsi_event justify[] = { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	{ 0, "CENTER" }, | 
					
						
							|  |  |  | 	{ 1, "RIGHT" }, | 
					
						
							|  |  |  | 	{ 2, "LEFT" }, | 
					
						
							|  |  |  | 	{ 3, "INDENT" }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | #define STATE_NORMAL 0
 | 
					
						
							|  |  |  | #define STATE_INKEY  1
 | 
					
						
							|  |  |  | #define STATE_INSUB  2
 | 
					
						
							|  |  |  | #define STATE_INIF   3
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | #define MAX_RET_CODE 20
 | 
					
						
							|  |  |  | #define MAX_SUB_LEN  255
 | 
					
						
							|  |  |  | #define MAX_MAIN_LEN 1600
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | #define ARG_STRING (1 << 0)
 | 
					
						
							|  |  |  | #define ARG_NUMBER (1 << 1)
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | struct adsi_soft_key { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	char vname[40];  /* Which "variable" is associated with it */ | 
					
						
							|  |  |  | 	int retstrlen;   /* Length of return string */ | 
					
						
							|  |  |  | 	int initlen;     /* initial length */ | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int id; | 
					
						
							|  |  |  | 	int defined; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	char retstr[80]; /* Return string data */ | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct adsi_subscript { | 
					
						
							|  |  |  | 	char vname[40]; | 
					
						
							|  |  |  | 	int id; | 
					
						
							|  |  |  | 	int defined; | 
					
						
							|  |  |  | 	int datalen; | 
					
						
							|  |  |  | 	int inscount; | 
					
						
							|  |  |  | 	int ifinscount; | 
					
						
							|  |  |  | 	char *ifdata; | 
					
						
							|  |  |  | 	char data[2048]; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct adsi_state { | 
					
						
							|  |  |  | 	char vname[40]; | 
					
						
							|  |  |  | 	int id; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct adsi_flag { | 
					
						
							|  |  |  | 	char vname[40]; | 
					
						
							|  |  |  | 	int id; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct adsi_display { | 
					
						
							|  |  |  | 	char vname[40]; | 
					
						
							|  |  |  | 	int id; | 
					
						
							|  |  |  | 	char data[70]; | 
					
						
							|  |  |  | 	int datalen; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct adsi_script { | 
					
						
							|  |  |  | 	int state; | 
					
						
							|  |  |  | 	int numkeys; | 
					
						
							|  |  |  | 	int numsubs; | 
					
						
							|  |  |  | 	int numstates; | 
					
						
							|  |  |  | 	int numdisplays; | 
					
						
							|  |  |  | 	int numflags; | 
					
						
							|  |  |  | 	struct adsi_soft_key *key; | 
					
						
							|  |  |  | 	struct adsi_subscript *sub; | 
					
						
							|  |  |  | 	/* Pre-defined displays */ | 
					
						
							|  |  |  | 	struct adsi_display displays[63]; | 
					
						
							|  |  |  | 	/* ADSI States 1 (initial) - 254 */ | 
					
						
							|  |  |  | 	struct adsi_state states[256]; | 
					
						
							|  |  |  | 	/* Keys 2-63 */ | 
					
						
							|  |  |  | 	struct adsi_soft_key keys[62]; | 
					
						
							|  |  |  | 	/* Subscripts 0 (main) to 127 */ | 
					
						
							|  |  |  | 	struct adsi_subscript subs[128]; | 
					
						
							|  |  |  | 	/* Flags 1-7 */ | 
					
						
							|  |  |  | 	struct adsi_flag flags[7]; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Stuff from adsi script */ | 
					
						
							| 
									
										
										
										
											2005-09-07 18:55:03 +00:00
										 |  |  | 	unsigned char sec[5]; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	char desc[19]; | 
					
						
							| 
									
										
										
										
											2005-09-07 18:55:03 +00:00
										 |  |  | 	unsigned char fdn[5]; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int ver; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int process_token(void *out, char *src, int maxlen, int argtype) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	if ((strlen(src) > 1) && src[0] == '\"') { | 
					
						
							|  |  |  | 		/* This is a quoted string */ | 
					
						
							|  |  |  | 		if (!(argtype & ARG_STRING)) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		src++; | 
					
						
							|  |  |  | 		/* Don't take more than what's there */ | 
					
						
							|  |  |  | 		if (maxlen > strlen(src) - 1) | 
					
						
							|  |  |  | 			maxlen = strlen(src) - 1; | 
					
						
							|  |  |  | 		memcpy(out, src, maxlen); | 
					
						
							|  |  |  | 		((char *)out)[maxlen] = '\0'; | 
					
						
							| 
									
										
										
										
											2004-05-04 19:11:25 +00:00
										 |  |  | 	} else if (!ast_strlen_zero(src) && (src[0] == '\\')) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (!(argtype & ARG_NUMBER)) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		/* Octal value */ | 
					
						
							| 
									
										
										
										
											2014-05-09 22:49:26 +00:00
										 |  |  | 		if (sscanf(src, "%30o", (unsigned *)out) != 1) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		if (argtype & ARG_STRING) { | 
					
						
							|  |  |  | 			/* Convert */ | 
					
						
							|  |  |  | 			*((unsigned int *)out) = htonl(*((unsigned int *)out)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else if ((strlen(src) > 2) && (src[0] == '0') && (tolower(src[1]) == 'x')) { | 
					
						
							|  |  |  | 		if (!(argtype & ARG_NUMBER)) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		/* Hex value */ | 
					
						
							| 
									
										
										
										
											2009-08-10 19:20:57 +00:00
										 |  |  | 		if (sscanf(src + 2, "%30x", (unsigned int *)out) != 1) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		if (argtype & ARG_STRING) { | 
					
						
							|  |  |  | 			/* Convert */ | 
					
						
							|  |  |  | 			*((unsigned int *)out) = htonl(*((unsigned int *)out)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2004-05-04 19:11:25 +00:00
										 |  |  | 	} else if ((!ast_strlen_zero(src) && isdigit(src[0]))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (!(argtype & ARG_NUMBER)) | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		/* Hex value */ | 
					
						
							| 
									
										
										
										
											2009-08-10 19:20:57 +00:00
										 |  |  | 		if (sscanf(src, "%30d", (int *)out) != 1) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return -1; | 
					
						
							|  |  |  | 		if (argtype & ARG_STRING) { | 
					
						
							|  |  |  | 			/* Convert */ | 
					
						
							|  |  |  | 			*((unsigned int *)out) = htonl(*((unsigned int *)out)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} else | 
					
						
							|  |  |  | 		return -1; | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static char *get_token(char **buf, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tmp = *buf, *keyword; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int quoted = 0; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* Advance past any white space */ | 
					
						
							|  |  |  | 	while(*tmp && (*tmp < 33)) | 
					
						
							|  |  |  | 		tmp++; | 
					
						
							|  |  |  | 	if (!*tmp) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	keyword = tmp; | 
					
						
							|  |  |  | 	while(*tmp && ((*tmp > 32)  || quoted)) { | 
					
						
							|  |  |  | 		if (*tmp == '\"') { | 
					
						
							|  |  |  | 			quoted = !quoted; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		tmp++; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (quoted) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Mismatched quotes at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	*tmp = '\0'; | 
					
						
							|  |  |  | 	tmp++; | 
					
						
							|  |  |  | 	while(*tmp && (*tmp < 33)) | 
					
						
							|  |  |  | 		tmp++; | 
					
						
							|  |  |  | 	/* Note where we left off */ | 
					
						
							|  |  |  | 	*buf = tmp; | 
					
						
							|  |  |  | 	return keyword; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static char *validdtmf = "123456789*0#ABCD"; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int send_dtmf(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char dtmfstr[80], *a; | 
					
						
							|  |  |  | 	int bytes = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!(a = get_token(&args, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Expecting something to send for SENDDTMF at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(dtmfstr, a, sizeof(dtmfstr) - 1, ARG_STRING)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid token for SENDDTMF at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	a = dtmfstr; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	while (*a) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (strchr(validdtmf, *a)) { | 
					
						
							|  |  |  | 			*buf = *a; | 
					
						
							|  |  |  | 			buf++; | 
					
						
							|  |  |  | 			bytes++; | 
					
						
							|  |  |  | 		} else | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "'%c' is not a valid DTMF tone at line %d of %s\n", *a, lineno, script); | 
					
						
							|  |  |  | 		a++; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return bytes; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int goto_line(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *page = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 	char *gline = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int line; | 
					
						
							|  |  |  | 	unsigned char cmd; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!page || !gline) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Expecting page and line number for GOTOLINE at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (!strcasecmp(page, "INFO")) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		cmd = 0; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	else if (!strcasecmp(page, "COMM")) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		cmd = 0x80; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2017-12-20 12:14:54 -05:00
										 |  |  | 		ast_log(LOG_WARNING, "Expecting either 'INFO' or 'COMM' page, got '%s' at line %d of %s\n", page, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(&line, gline, sizeof(line), ARG_NUMBER)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid line number '%s' at line %d of %s\n", gline, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	cmd |= line; | 
					
						
							|  |  |  | 	buf[0] = 0x8b; | 
					
						
							|  |  |  | 	buf[1] = cmd; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int goto_line_rel(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *dir = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 	char *gline = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int line; | 
					
						
							|  |  |  | 	unsigned char cmd; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!dir || !gline) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Expecting direction and number of lines for GOTOLINEREL at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (!strcasecmp(dir, "UP")) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		cmd = 0; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	else if (!strcasecmp(dir, "DOWN")) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		cmd = 0x20; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	else { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Expecting either 'UP' or 'DOWN' direction, got '%s' at line %d of %s\n", dir, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(&line, gline, sizeof(line), ARG_NUMBER)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid line number '%s' at line %d of %s\n", gline, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	cmd |= line; | 
					
						
							|  |  |  | 	buf[0] = 0x8c; | 
					
						
							|  |  |  | 	buf[1] = cmd; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int send_delay(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *gtime = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int ms; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!gtime) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Expecting number of milliseconds to wait at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(&ms, gtime, sizeof(ms), ARG_NUMBER)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid delay milliseconds '%s' at line %d of %s\n", gtime, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[0] = 0x90; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (id == 11) | 
					
						
							|  |  |  | 		buf[1] = ms / 100; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		buf[1] = ms / 10; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int set_state(char *buf, char *name, int id, char *args, struct adsi_script *istate, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *gstate = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int state; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!gstate) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Expecting state number at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(&state, gstate, sizeof(state), ARG_NUMBER)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid state number '%s' at line %d of %s\n", gstate, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = state; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int cleartimer(char *buf, char *name, int id, char *args, struct adsi_script *istate, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (tok) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Clearing timer requires no arguments ('%s') at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf[0] = id; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* For some reason the clear code is different slightly */ | 
					
						
							|  |  |  | 	if (id == 7) | 
					
						
							|  |  |  | 		buf[1] = 0x10; | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 		buf[1] = 0x00; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static struct adsi_flag *getflagbyname(struct adsi_script *state, char *name, const char *script, int lineno, int create) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (x = 0; x < state->numflags; x++) { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		if (!strcasecmp(state->flags[x].vname, name)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return &state->flags[x]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* Return now if we're not allowed to create */ | 
					
						
							|  |  |  | 	if (!create) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (state->numflags > 6) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "No more flag space at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-10 23:12:25 +00:00
										 |  |  | 	ast_copy_string(state->flags[state->numflags].vname, name, sizeof(state->flags[state->numflags].vname)); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	state->flags[state->numflags].id = state->numflags + 1; | 
					
						
							|  |  |  | 	state->numflags++; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return &state->flags[state->numflags-1]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int setflag(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	char sname[80]; | 
					
						
							|  |  |  | 	struct adsi_flag *flag; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!tok) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Setting flag requires a flag number at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(sname, tok, sizeof(sname) - 1, ARG_STRING)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid flag '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(flag = getflagbyname(state, sname, script, lineno, 0))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Flag '%s' is undeclared at line %d of %s\n", sname, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = ((flag->id & 0x7) << 4) | 1; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int clearflag(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	struct adsi_flag *flag; | 
					
						
							|  |  |  | 	char sname[80]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!tok) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Clearing flag requires a flag number at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(sname, tok, sizeof(sname) - 1, ARG_STRING)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid flag '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(flag = getflagbyname(state, sname, script, lineno, 0))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Flag '%s' is undeclared at line %d of %s\n", sname, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = ((flag->id & 0x7) << 4); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int starttimer(char *buf, char *name, int id, char *args, struct adsi_script *istate, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	int secs; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!tok) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Missing number of seconds at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (process_token(&secs, tok, sizeof(secs), ARG_NUMBER)) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Invalid number of seconds '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = 0x1; | 
					
						
							|  |  |  | 	buf[2] = secs; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 3; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int geteventbyname(char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-08 16:40:28 +00:00
										 |  |  | 	for (x = 0; x < ARRAY_LEN(events); x++) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (!strcasecmp(events[x].name, name)) | 
					
						
							|  |  |  | 			return events[x].id; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int getjustifybyname(char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-08 16:40:28 +00:00
										 |  |  | 	for (x = 0; x < ARRAY_LEN(justify); x++) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (!strcasecmp(justify[x].name, name)) | 
					
						
							|  |  |  | 			return justify[x].id; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static struct adsi_soft_key *getkeybyname(struct adsi_script *state, char *name, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (x = 0; x < state->numkeys; x++) { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		if (!strcasecmp(state->keys[x].vname, name)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return &state->keys[x]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (state->numkeys > 61) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "No more key space at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-10 23:12:25 +00:00
										 |  |  | 	ast_copy_string(state->keys[state->numkeys].vname, name, sizeof(state->keys[state->numkeys].vname)); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	state->keys[state->numkeys].id = state->numkeys + 2; | 
					
						
							|  |  |  | 	state->numkeys++; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return &state->keys[state->numkeys-1]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static struct adsi_subscript *getsubbyname(struct adsi_script *state, char *name, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (x = 0; x < state->numsubs; x++) { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		if (!strcasecmp(state->subs[x].vname, name)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return &state->subs[x]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (state->numsubs > 127) { | 
					
						
							| 
									
										
										
										
											2019-05-10 09:48:28 -06:00
										 |  |  | 		ast_log(LOG_WARNING, "No more subscript space at line %d of %s\n", lineno, S_OR(script, "unknown")); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-10 23:12:25 +00:00
										 |  |  | 	ast_copy_string(state->subs[state->numsubs].vname, name, sizeof(state->subs[state->numsubs].vname)); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	state->subs[state->numsubs].id = state->numsubs; | 
					
						
							|  |  |  | 	state->numsubs++; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return &state->subs[state->numsubs-1]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static struct adsi_state *getstatebyname(struct adsi_script *state, char *name, const char *script, int lineno, int create) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (x = 0; x <state->numstates; x++) { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		if (!strcasecmp(state->states[x].vname, name)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return &state->states[x]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* Return now if we're not allowed to create */ | 
					
						
							|  |  |  | 	if (!create) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (state->numstates > 253) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "No more state space at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-10 23:12:25 +00:00
										 |  |  | 	ast_copy_string(state->states[state->numstates].vname, name, sizeof(state->states[state->numstates].vname)); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	state->states[state->numstates].id = state->numstates + 1; | 
					
						
							|  |  |  | 	state->numstates++; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return &state->states[state->numstates-1]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static struct adsi_display *getdisplaybyname(struct adsi_script *state, char *name, const char *script, int lineno, int create) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	for (x = 0; x < state->numdisplays; x++) { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		if (!strcasecmp(state->displays[x].vname, name)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			return &state->displays[x]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* Return now if we're not allowed to create */ | 
					
						
							|  |  |  | 	if (!create) | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (state->numdisplays > 61) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "No more display space at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-07-10 23:12:25 +00:00
										 |  |  | 	ast_copy_string(state->displays[state->numdisplays].vname, name, sizeof(state->displays[state->numdisplays].vname)); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	state->displays[state->numdisplays].id = state->numdisplays + 1; | 
					
						
							|  |  |  | 	state->numdisplays++; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return &state->displays[state->numdisplays-1]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int showkeys(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok, newkey[80]; | 
					
						
							|  |  |  | 	int bytes, x, flagid = 0; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	unsigned char keyid[6]; | 
					
						
							|  |  |  | 	struct adsi_soft_key *key; | 
					
						
							|  |  |  | 	struct adsi_flag *flag; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < 7; x++) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		/* Up to 6 key arguments */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 		if (!(tok = get_token(&args, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		if (!strcasecmp(tok, "UNLESS")) { | 
					
						
							|  |  |  | 			/* Check for trailing UNLESS flag */ | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 			if (!(tok = get_token(&args, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Missing argument for UNLESS clause at line %d of %s\n", lineno, script); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 			else if (process_token(newkey, tok, sizeof(newkey) - 1, ARG_STRING)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Invalid flag name '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 			else if (!(flag = getflagbyname(state, newkey, script, lineno, 0))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Flag '%s' is undeclared at line %d of %s\n", newkey, lineno, script); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 			else | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				flagid = flag->id; | 
					
						
							|  |  |  | 			if ((tok = get_token(&args, script, lineno))) | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Extra arguments after UNLESS clause: '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (x > 5) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Only 6 keys can be defined, ignoring '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (process_token(newkey, tok, sizeof(newkey) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Invalid token for key name: %s\n", tok); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 		if (!(key = getkeybyname(state, newkey, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		keyid[x] = key->id; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = (flagid & 0x7) << 3 | (x & 0x7); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	for (bytes = 0; bytes < x; bytes++) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		buf[bytes + 2] = keyid[bytes]; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2 + x; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int showdisplay(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok, dispname[80]; | 
					
						
							|  |  |  | 	int line = 0, flag = 0, cmd = 3; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	struct adsi_display *disp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Get display */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	if (!(tok = get_token(&args, script, lineno)) || process_token(dispname, tok, sizeof(dispname) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Invalid display name: %s at line %d of %s\n", tok ? tok : "<nothing>", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(disp = getdisplaybyname(state, dispname, script, lineno, 0))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Display '%s' is undefined at line %d of %s\n", dispname, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	if (!(tok = get_token(&args, script, lineno)) || strcasecmp(tok, "AT")) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Missing token 'AT' at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* Get line number */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	if (!(tok = get_token(&args, script, lineno)) || process_token(&line, tok, sizeof(line), ARG_NUMBER)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Invalid line: '%s' at line %d of %s\n", tok ? tok : "<nothing>", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((tok = get_token(&args, script, lineno)) && !strcasecmp(tok, "NOUPDATE")) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		cmd = 1; | 
					
						
							|  |  |  | 		tok = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (tok && !strcasecmp(tok, "UNLESS")) { | 
					
						
							|  |  |  | 		/* Check for trailing UNLESS flag */ | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		if (!(tok = get_token(&args, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Missing argument for UNLESS clause at line %d of %s\n", lineno, script); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		else if (process_token(&flag, tok, sizeof(flag), ARG_NUMBER)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Invalid flag number '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if ((tok = get_token(&args, script, lineno))) | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Extra arguments after UNLESS clause: '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[0] = id; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	buf[1] = (cmd << 6) | (disp->id & 0x3f); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[2] = ((line & 0x1f) << 3) | (flag & 0x7); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 3; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int cleardisplay(char *buf, char *name, int id, char *args, struct adsi_script *istate, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (tok) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Clearing display requires no arguments ('%s') at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = 0x00; | 
					
						
							|  |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int digitdirect(char *buf, char *name, int id, char *args, struct adsi_script *istate, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (tok) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Digitdirect requires no arguments ('%s') at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = 0x7; | 
					
						
							|  |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int clearcbone(char *buf, char *name, int id, char *args, struct adsi_script *istate, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2004-03-20 17:27:10 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2004-03-20 17:27:10 +00:00
										 |  |  | 	if (tok) | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "CLEARCB1 requires no arguments ('%s') at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = 0; | 
					
						
							|  |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int digitcollect(char *buf, char *name, int id, char *args, struct adsi_script *istate, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (tok) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Digitcollect requires no arguments ('%s') at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	buf[0] = id; | 
					
						
							|  |  |  | 	buf[1] = 0xf; | 
					
						
							|  |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int subscript(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 	char subscr[80]; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	struct adsi_subscript *sub; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!tok) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Missing subscript to call at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 	if (process_token(subscr, tok, sizeof(subscr) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Invalid number of seconds '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 	if (!(sub = getsubbyname(state, subscr, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	buf[0] = 0x9d; | 
					
						
							|  |  |  | 	buf[1] = sub->id; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 2; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int onevent(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *tok = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 	char subscr[80], sname[80]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	int sawin = 0, event, snums[8], scnt = 0, x; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	struct adsi_subscript *sub; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (!tok) { | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Missing event for 'ONEVENT' at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if ((event = geteventbyname(tok)) < 1) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "'%s' is not a valid event name, at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	tok = get_token(&args, script, lineno); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	while ((!sawin && !strcasecmp(tok, "IN")) || (sawin && !strcasecmp(tok, "OR"))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		sawin = 1; | 
					
						
							|  |  |  | 		if (scnt > 7) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "No more than 8 states may be specified for inclusion at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		/* Process 'in' things */ | 
					
						
							|  |  |  | 		tok = get_token(&args, script, lineno); | 
					
						
							|  |  |  | 		if (process_token(sname, tok, sizeof(sname), ARG_STRING)) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "'%s' is not a valid state name at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2008-10-30 16:49:02 +00:00
										 |  |  | 		if ((snums[scnt] = getstatebyname(state, sname, script, lineno, 0) == NULL)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "State '%s' not declared at line %d of %s\n", sname, lineno, script); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		scnt++; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 		if (!(tok = get_token(&args, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (!tok || strcasecmp(tok, "GOTO")) { | 
					
						
							|  |  |  | 		if (!tok) | 
					
						
							|  |  |  | 			tok = "<nothing>"; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		if (sawin) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Got '%s' while looking for 'GOTO' or 'OR' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Got '%s' while looking for 'GOTO' or 'IN' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	if (!(tok = get_token(&args, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Missing subscript to call at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 	if (process_token(subscr, tok, sizeof(subscr) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Invalid subscript '%s' at line %d of %s\n", tok, lineno, script); | 
					
						
							|  |  |  | 		return 0; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-08-10 14:45:25 +00:00
										 |  |  | 	if (!(sub = getsubbyname(state, subscr, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return 0; | 
					
						
							|  |  |  | 	buf[0] = 8; | 
					
						
							|  |  |  | 	buf[1] = event; | 
					
						
							|  |  |  | 	buf[2] = sub->id | 0x80; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < scnt; x++) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		buf[3 + x] = snums[x]; | 
					
						
							|  |  |  | 	return 3 + scnt; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct adsi_key_cmd { | 
					
						
							|  |  |  | 	char *name; | 
					
						
							|  |  |  | 	int id; | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | 	int (*add_args)(char *buf, char *name, int id, char *args, struct adsi_script *state, const char *script, int lineno); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const struct adsi_key_cmd kcmds[] = { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	{ "SENDDTMF", 0, send_dtmf }, | 
					
						
							|  |  |  | 	/* Encoded DTMF would go here */ | 
					
						
							|  |  |  | 	{ "ONHOOK", 0x81 }, | 
					
						
							|  |  |  | 	{ "OFFHOOK", 0x82 }, | 
					
						
							|  |  |  | 	{ "FLASH", 0x83 }, | 
					
						
							|  |  |  | 	{ "WAITDIALTONE", 0x84 }, | 
					
						
							|  |  |  | 	/* Send line number */ | 
					
						
							|  |  |  | 	{ "BLANK", 0x86 }, | 
					
						
							|  |  |  | 	{ "SENDCHARS", 0x87 }, | 
					
						
							|  |  |  | 	{ "CLEARCHARS", 0x88 }, | 
					
						
							|  |  |  | 	{ "BACKSPACE", 0x89 }, | 
					
						
							|  |  |  | 	/* Tab column */ | 
					
						
							|  |  |  | 	{ "GOTOLINE", 0x8b, goto_line }, | 
					
						
							|  |  |  | 	{ "GOTOLINEREL", 0x8c, goto_line_rel }, | 
					
						
							|  |  |  | 	{ "PAGEUP", 0x8d }, | 
					
						
							|  |  |  | 	{ "PAGEDOWN", 0x8e }, | 
					
						
							|  |  |  | 	/* Extended DTMF */ | 
					
						
							|  |  |  | 	{ "DELAY", 0x90, send_delay }, | 
					
						
							|  |  |  | 	{ "DIALPULSEONE", 0x91 }, | 
					
						
							|  |  |  | 	{ "DATAMODE", 0x92 }, | 
					
						
							|  |  |  | 	{ "VOICEMODE", 0x93 }, | 
					
						
							|  |  |  | 	/* Display call buffer 'n' */ | 
					
						
							|  |  |  | 	/* Clear call buffer 'n' */ | 
					
						
							| 
									
										
										
										
											2004-03-20 17:27:10 +00:00
										 |  |  | 	{ "CLEARCB1", 0x95, clearcbone }, | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	{ "DIGITCOLLECT", 0x96, digitcollect }, | 
					
						
							|  |  |  | 	{ "DIGITDIRECT", 0x96, digitdirect }, | 
					
						
							|  |  |  | 	{ "CLEAR", 0x97 }, | 
					
						
							|  |  |  | 	{ "SHOWDISPLAY", 0x98, showdisplay }, | 
					
						
							|  |  |  | 	{ "CLEARDISPLAY", 0x98, cleardisplay }, | 
					
						
							|  |  |  | 	{ "SHOWKEYS", 0x99, showkeys }, | 
					
						
							|  |  |  | 	{ "SETSTATE", 0x9a, set_state }, | 
					
						
							|  |  |  | 	{ "TIMERSTART", 0x9b, starttimer }, | 
					
						
							|  |  |  | 	{ "TIMERCLEAR", 0x9b, cleartimer }, | 
					
						
							|  |  |  | 	{ "SETFLAG", 0x9c, setflag }, | 
					
						
							|  |  |  | 	{ "CLEARFLAG", 0x9c, clearflag }, | 
					
						
							|  |  |  | 	{ "GOTO", 0x9d, subscript }, | 
					
						
							|  |  |  | 	{ "EVENT22", 0x9e }, | 
					
						
							|  |  |  | 	{ "EVENT23", 0x9f }, | 
					
						
							|  |  |  | 	{ "EXIT", 0xa0 }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static const struct adsi_key_cmd opcmds[] = { | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* 1 - Branch on event -- handled specially */ | 
					
						
							|  |  |  | 	{ "SHOWKEYS", 2, showkeys }, | 
					
						
							|  |  |  | 	/* Display Control */ | 
					
						
							|  |  |  | 	{ "SHOWDISPLAY", 3, showdisplay }, | 
					
						
							|  |  |  | 	{ "CLEARDISPLAY", 3, cleardisplay }, | 
					
						
							|  |  |  | 	{ "CLEAR", 5 }, | 
					
						
							|  |  |  | 	{ "SETSTATE", 6, set_state }, | 
					
						
							|  |  |  | 	{ "TIMERSTART", 7, starttimer }, | 
					
						
							|  |  |  | 	{ "TIMERCLEAR", 7, cleartimer }, | 
					
						
							|  |  |  | 	{ "ONEVENT", 8, onevent }, | 
					
						
							|  |  |  | 	/* 9 - Subroutine label, treated specially */ | 
					
						
							|  |  |  | 	{ "SETFLAG", 10, setflag }, | 
					
						
							|  |  |  | 	{ "CLEARFLAG", 10, clearflag }, | 
					
						
							|  |  |  | 	{ "DELAY", 11, send_delay }, | 
					
						
							|  |  |  | 	{ "EXIT", 12 }, | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int process_returncode(struct adsi_soft_key *key, char *code, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	int x, res; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	char *unused; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-08 16:40:28 +00:00
										 |  |  | 	for (x = 0; x < ARRAY_LEN(kcmds); x++) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if ((kcmds[x].id > -1) && !strcasecmp(kcmds[x].name, code)) { | 
					
						
							|  |  |  | 			if (kcmds[x].add_args) { | 
					
						
							|  |  |  | 				res = kcmds[x].add_args(key->retstr + key->retstrlen, | 
					
						
							|  |  |  | 						code, kcmds[x].id, args, state, script, lineno); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 				if ((key->retstrlen + res - key->initlen) <= MAX_RET_CODE) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					key->retstrlen += res; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 				else | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", kcmds[x].name, key->vname, lineno, script); | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 				if ((unused = get_token(&args, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "'%s' takes no arguments at line %d of %s (token is '%s')\n", kcmds[x].name, lineno, script, unused); | 
					
						
							|  |  |  | 				if ((key->retstrlen + 1 - key->initlen) <= MAX_RET_CODE) { | 
					
						
							|  |  |  | 					key->retstr[key->retstrlen] = kcmds[x].id; | 
					
						
							|  |  |  | 					key->retstrlen++; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 				} else | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", kcmds[x].name, key->vname, lineno, script); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int process_opcode(struct adsi_subscript *sub, char *code, char *args, struct adsi_script *state, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	int x, res, max = sub->id ? MAX_SUB_LEN : MAX_MAIN_LEN; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	char *unused; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-07-08 16:40:28 +00:00
										 |  |  | 	for (x = 0; x < ARRAY_LEN(opcmds); x++) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if ((opcmds[x].id > -1) && !strcasecmp(opcmds[x].name, code)) { | 
					
						
							|  |  |  | 			if (opcmds[x].add_args) { | 
					
						
							|  |  |  | 				res = opcmds[x].add_args(sub->data + sub->datalen, | 
					
						
							|  |  |  | 						code, opcmds[x].id, args, state, script, lineno); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 				if ((sub->datalen + res + 1) <= max) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					sub->datalen += res; | 
					
						
							|  |  |  | 				else { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "No space for '%s' code in subscript '%s' at line %d of %s\n", opcmds[x].name, sub->vname, lineno, script); | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 				if ((unused = get_token(&args, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "'%s' takes no arguments at line %d of %s (token is '%s')\n", opcmds[x].name, lineno, script, unused); | 
					
						
							|  |  |  | 				if ((sub->datalen + 2) <= max) { | 
					
						
							|  |  |  | 					sub->data[sub->datalen] = opcmds[x].id; | 
					
						
							|  |  |  | 					sub->datalen++; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "No space for '%s' code in key '%s' at line %d of %s\n", opcmds[x].name, sub->vname, lineno, script); | 
					
						
							|  |  |  | 					return -1; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* Separate commands with 0xff */ | 
					
						
							|  |  |  | 			sub->data[sub->datalen] = 0xff; | 
					
						
							|  |  |  | 			sub->datalen++; | 
					
						
							|  |  |  | 			sub->inscount++; | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return -1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int adsi_process(struct adsi_script *state, char *buf, const char *script, int lineno) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char *keyword = get_token(&buf, script, lineno); | 
					
						
							|  |  |  | 	char *args, vname[256], tmp[80], tmp2[80]; | 
					
						
							|  |  |  | 	int lrci, wi, event; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	struct adsi_display *disp; | 
					
						
							|  |  |  | 	struct adsi_subscript *newsub; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (!keyword) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return 0; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	switch(state->state) { | 
					
						
							|  |  |  | 	case STATE_NORMAL: | 
					
						
							|  |  |  | 		if (!strcasecmp(keyword, "DESCRIPTION")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if ((args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				if (process_token(state->desc, args, sizeof(state->desc) - 1, ARG_STRING)) | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "'%s' is not a valid token for DESCRIPTION at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Missing argument for DESCRIPTION at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(keyword, "VERSION")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if ((args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				if (process_token(&state->ver, args, sizeof(state->ver) - 1, ARG_NUMBER)) | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "'%s' is not a valid token for VERSION at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Missing argument for VERSION at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(keyword, "SECURITY")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if ((args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				if (process_token(state->sec, args, sizeof(state->sec) - 1, ARG_STRING | ARG_NUMBER)) | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "'%s' is not a valid token for SECURITY at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Missing argument for SECURITY at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(keyword, "FDN")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if ((args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				if (process_token(state->fdn, args, sizeof(state->fdn) - 1, ARG_STRING | ARG_NUMBER)) | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "'%s' is not a valid token for FDN at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 			} else | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Missing argument for FDN at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(keyword, "KEY")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "KEY definition missing name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:43:14 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY name at line %d of %s\n", args, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(state->key = getkeybyname(state, vname, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Out of key space at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (state->key->defined) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Cannot redefine key '%s' at line %d of %s\n", vname, lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno)) || strcasecmp(args, "IS")) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Expecting 'IS', but got '%s' at line %d of %s\n", args ? args : "<nothing>", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "KEY definition missing short name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:43:14 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY short name at line %d of %s\n", args, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if ((args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				if (strcasecmp(args, "OR")) { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "Expecting 'OR' but got '%s' instead at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 				if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "KEY definition missing optional long name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (process_token(tmp2, args, sizeof(tmp2) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:43:14 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY long name at line %d of %s\n", args, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} else { | 
					
						
							| 
									
										
										
										
											2005-07-10 23:12:25 +00:00
										 |  |  | 				ast_copy_string(tmp2, tmp, sizeof(tmp2)); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			} | 
					
						
							|  |  |  | 			if (strlen(tmp2) > 18) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Truncating full name to 18 characters at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				tmp2[18] = '\0'; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (strlen(tmp) > 7) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Truncating short name to 7 bytes at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				tmp[7] = '\0'; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* Setup initial stuff */ | 
					
						
							| 
									
										
										
										
											2018-01-06 08:25:14 +01:00
										 |  |  | 			state->key->retstr[0] = 0x80; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			/* 1 has the length */ | 
					
						
							|  |  |  | 			state->key->retstr[2] = state->key->id; | 
					
						
							|  |  |  | 			/* Put the Full name in */ | 
					
						
							|  |  |  | 			memcpy(state->key->retstr + 3, tmp2, strlen(tmp2)); | 
					
						
							|  |  |  | 			/* Update length */ | 
					
						
							|  |  |  | 			state->key->retstrlen = strlen(tmp2) + 3; | 
					
						
							|  |  |  | 			/* Put trailing 0xff */ | 
					
						
							|  |  |  | 			state->key->retstr[state->key->retstrlen++] = 0xff; | 
					
						
							|  |  |  | 			/* Put the short name */ | 
					
						
							|  |  |  | 			memcpy(state->key->retstr + state->key->retstrlen, tmp, strlen(tmp)); | 
					
						
							|  |  |  | 			/* Update length */ | 
					
						
							|  |  |  | 			state->key->retstrlen += strlen(tmp); | 
					
						
							|  |  |  | 			/* Put trailing 0xff */ | 
					
						
							|  |  |  | 			state->key->retstr[state->key->retstrlen++] = 0xff; | 
					
						
							|  |  |  | 			/* Record initial length */ | 
					
						
							|  |  |  | 			state->key->initlen = state->key->retstrlen; | 
					
						
							|  |  |  | 			state->state = STATE_INKEY; | 
					
						
							|  |  |  | 		} else if (!strcasecmp(keyword, "SUB")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "SUB definition missing name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:43:14 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY name at line %d of %s\n", args, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(state->sub = getsubbyname(state, vname, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Out of subroutine space at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (state->sub->defined) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Cannot redefine subroutine '%s' at line %d of %s\n", vname, lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			/* Setup sub */ | 
					
						
							| 
									
										
										
										
											2018-01-06 08:25:14 +01:00
										 |  |  | 			state->sub->data[0] = 0x82; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			/* 1 is the length */ | 
					
						
							|  |  |  | 			state->sub->data[2] = 0x0; /* Clear extensibility bit */ | 
					
						
							|  |  |  | 			state->sub->datalen = 3; | 
					
						
							|  |  |  | 			if (state->sub->id) { | 
					
						
							|  |  |  | 				/* If this isn't the main subroutine, make a subroutine label for it */ | 
					
						
							|  |  |  | 				state->sub->data[3] = 9; | 
					
						
							|  |  |  | 				state->sub->data[4] = state->sub->id; | 
					
						
							|  |  |  | 				/* 5 is length */ | 
					
						
							|  |  |  | 				state->sub->data[6] = 0xff; | 
					
						
							|  |  |  | 				state->sub->datalen = 7; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno)) || strcasecmp(args, "IS")) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Expecting 'IS', but got '%s' at line %d of %s\n", args ? args : "<nothing>", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			state->state = STATE_INSUB; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		} else if (!strcasecmp(keyword, "STATE")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "STATE definition missing name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:43:14 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "'%s' is not a valid token for a STATE name at line %d of %s\n", args, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (getstatebyname(state, vname, script, lineno, 0)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "State '%s' is already defined at line %d of %s\n", vname, lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			getstatebyname(state, vname, script, lineno, 1); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 		} else if (!strcasecmp(keyword, "FLAG")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "FLAG definition missing name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:43:14 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "'%s' is not a valid token for a FLAG name at line %d of %s\n", args, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (getflagbyname(state, vname, script, lineno, 0)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Flag '%s' is already defined\n", vname); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			getflagbyname(state, vname, script, lineno, 1); | 
					
						
							|  |  |  | 		} else if (!strcasecmp(keyword, "DISPLAY")) { | 
					
						
							|  |  |  | 			lrci = 0; | 
					
						
							|  |  |  | 			wi = 0; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "SUB definition missing name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (process_token(vname, args, sizeof(vname) - 1, ARG_STRING)) { | 
					
						
							| 
									
										
										
										
											2003-05-08 03:43:14 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "'%s' is not a valid token for a KEY name at line %d of %s\n", args, lineno, script); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (getdisplaybyname(state, vname, script, lineno, 0)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "State '%s' is already defined\n", vname); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(disp = getdisplaybyname(state, vname, script, lineno, 1))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				break; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno)) || strcasecmp(args, "IS")) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Missing 'IS' at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Missing Column 1 text at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Token '%s' is not valid column 1 text at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (strlen(tmp) > 20) { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Truncating column one to 20 characters at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 				tmp[20] = '\0'; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			memcpy(disp->data + 5, tmp, strlen(tmp)); | 
					
						
							|  |  |  | 			disp->datalen = strlen(tmp) + 5; | 
					
						
							|  |  |  | 			disp->data[disp->datalen++] = 0xff; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			args = get_token(&buf, script, lineno); | 
					
						
							|  |  |  | 			if (args && !process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) { | 
					
						
							|  |  |  | 				/* Got a column two */ | 
					
						
							|  |  |  | 				if (strlen(tmp) > 20) { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "Truncating column two to 20 characters at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 					tmp[20] = '\0'; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				memcpy(disp->data + disp->datalen, tmp, strlen(tmp)); | 
					
						
							|  |  |  | 				disp->datalen += strlen(tmp); | 
					
						
							|  |  |  | 				args = get_token(&buf, script, lineno); | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 			while (args) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				if (!strcasecmp(args, "JUSTIFY")) { | 
					
						
							|  |  |  | 					args = get_token(&buf, script, lineno); | 
					
						
							|  |  |  | 					if (!args) { | 
					
						
							|  |  |  | 						ast_log(LOG_WARNING, "Qualifier 'JUSTIFY' requires an argument at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 					lrci = getjustifybyname(args); | 
					
						
							|  |  |  | 					if (lrci < 0) { | 
					
						
							|  |  |  | 						ast_log(LOG_WARNING, "'%s' is not a valid justification at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 						break; | 
					
						
							|  |  |  | 					} | 
					
						
							|  |  |  | 				} else if (!strcasecmp(args, "WRAP")) { | 
					
						
							|  |  |  | 					wi = 0x80; | 
					
						
							|  |  |  | 				} else { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "'%s' is not a known qualifier at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				args = get_token(&buf, script, lineno); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			if (args) { | 
					
						
							|  |  |  | 				/* Something bad happened */ | 
					
						
							|  |  |  | 				break; | 
					
						
							|  |  |  | 			} | 
					
						
							| 
									
										
										
										
											2018-01-06 08:25:14 +01:00
										 |  |  | 			disp->data[0] = 0x81; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			disp->data[1] = disp->datalen - 2; | 
					
						
							|  |  |  | 			disp->data[2] = ((lrci & 0x3) << 6) | disp->id; | 
					
						
							|  |  |  | 			disp->data[3] = wi; | 
					
						
							|  |  |  | 			disp->data[4] = 0xff; | 
					
						
							|  |  |  | 		} else { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in PROGRAM\n", keyword); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case STATE_INKEY: | 
					
						
							|  |  |  | 		if (process_returncode(state->key, keyword, buf, state, script, lineno)) { | 
					
						
							|  |  |  | 			if (!strcasecmp(keyword, "ENDKEY")) { | 
					
						
							|  |  |  | 				/* Return to normal operation and increment current key */ | 
					
						
							|  |  |  | 				state->state = STATE_NORMAL; | 
					
						
							|  |  |  | 				state->key->defined = 1; | 
					
						
							|  |  |  | 				state->key->retstr[1] = state->key->retstrlen - 2; | 
					
						
							|  |  |  | 				state->key = NULL; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in SOFTKEY definition at line %d of %s\n", keyword, lineno, script); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case STATE_INIF: | 
					
						
							|  |  |  | 		if (process_opcode(state->sub, keyword, buf, state, script, lineno)) { | 
					
						
							|  |  |  | 			if (!strcasecmp(keyword, "ENDIF")) { | 
					
						
							|  |  |  | 				/* Return to normal SUB operation and increment current key */ | 
					
						
							|  |  |  | 				state->state = STATE_INSUB; | 
					
						
							|  |  |  | 				state->sub->defined = 1; | 
					
						
							|  |  |  | 				/* Store the proper number of instructions */ | 
					
						
							|  |  |  | 				state->sub->ifdata[2] = state->sub->ifinscount; | 
					
						
							|  |  |  | 			} else if (!strcasecmp(keyword, "GOTO")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 				if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "GOTO clause missing Subscript name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				if (process_token(tmp, args, sizeof(tmp) - 1, ARG_STRING)) { | 
					
						
							|  |  |  | 					ast_log(LOG_WARNING, "'%s' is not a valid subscript name token at line %d of %s\n", args, lineno, script); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 				if (!(newsub = getsubbyname(state, tmp, script, lineno))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					break; | 
					
						
							|  |  |  | 				/* Somehow you use GOTO to go to another place */ | 
					
						
							|  |  |  | 				state->sub->data[state->sub->datalen++] = 0x8; | 
					
						
							|  |  |  | 				state->sub->data[state->sub->datalen++] = state->sub->ifdata[1]; | 
					
						
							|  |  |  | 				state->sub->data[state->sub->datalen++] = newsub->id; | 
					
						
							|  |  |  | 				/* Terminate */ | 
					
						
							|  |  |  | 				state->sub->data[state->sub->datalen++] = 0xff; | 
					
						
							|  |  |  | 				/* Increment counters */ | 
					
						
							|  |  |  | 				state->sub->inscount++; | 
					
						
							|  |  |  | 				state->sub->ifinscount++; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in IF clause at line %d of %s\n", keyword, lineno, script); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} else | 
					
						
							|  |  |  | 			state->sub->ifinscount++; | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case STATE_INSUB: | 
					
						
							|  |  |  | 		if (process_opcode(state->sub, keyword, buf, state, script, lineno)) { | 
					
						
							|  |  |  | 			if (!strcasecmp(keyword, "ENDSUB")) { | 
					
						
							|  |  |  | 				/* Return to normal operation and increment current key */ | 
					
						
							|  |  |  | 				state->state = STATE_NORMAL; | 
					
						
							|  |  |  | 				state->sub->defined = 1; | 
					
						
							|  |  |  | 				/* Store the proper length */ | 
					
						
							|  |  |  | 				state->sub->data[1] = state->sub->datalen - 2; | 
					
						
							|  |  |  | 				if (state->sub->id) { | 
					
						
							|  |  |  | 					/* if this isn't main, store number of instructions, too */ | 
					
						
							|  |  |  | 					state->sub->data[5] = state->sub->inscount; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				state->sub = NULL; | 
					
						
							|  |  |  | 			} else if (!strcasecmp(keyword, "IFEVENT")) { | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 				if (!(args = get_token(&buf, script, lineno))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "IFEVENT clause missing Event name at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 				if ((event = geteventbyname(args)) < 1) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "'%s' is not a valid event\n", args); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 				if (!(args = get_token(&buf, script, lineno)) || strcasecmp(args, "THEN")) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 					ast_log(LOG_WARNING, "IFEVENT clause missing 'THEN' at line %d of %s\n", lineno, script); | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 				state->sub->ifinscount = 0; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 				state->sub->ifdata = state->sub->data + state->sub->datalen; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				/* Reserve header and insert op codes */ | 
					
						
							|  |  |  | 				state->sub->ifdata[0] = 0x1; | 
					
						
							|  |  |  | 				state->sub->ifdata[1] = event; | 
					
						
							|  |  |  | 				/* 2 is for the number of instructions */ | 
					
						
							|  |  |  | 				state->sub->ifdata[3] = 0xff; | 
					
						
							|  |  |  | 				state->sub->datalen += 4; | 
					
						
							|  |  |  | 				/* Update Subscript instruction count */ | 
					
						
							|  |  |  | 				state->sub->inscount++; | 
					
						
							|  |  |  | 				state->state = STATE_INIF; | 
					
						
							|  |  |  | 			} else { | 
					
						
							|  |  |  | 				ast_log(LOG_WARNING, "Invalid or Unknown keyword '%s' in SUB definition at line %d of %s\n", keyword, lineno, script); | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	default: | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Can't process keyword '%s' in weird state %d\n", keyword, state->state); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static struct adsi_script *compile_script(const char *script) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	FILE *f; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	char fn[256], buf[256], *c; | 
					
						
							|  |  |  | 	int lineno = 0, x, err; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	struct adsi_script *scr; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	if (script[0] == '/') | 
					
						
							| 
									
										
										
										
											2005-07-10 23:12:25 +00:00
										 |  |  | 		ast_copy_string(fn, script, sizeof(fn)); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	else | 
					
						
							| 
									
										
										
										
											2007-12-18 09:46:18 +00:00
										 |  |  | 		snprintf(fn, sizeof(fn), "%s/%s", ast_config_AST_CONFIG_DIR, script); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(f = fopen(fn, "r"))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		ast_log(LOG_WARNING, "Can't open file '%s'\n", fn); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-01-11 18:40:42 +00:00
										 |  |  | 	if (!(scr = ast_calloc(1, sizeof(*scr)))) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		fclose(f); | 
					
						
							|  |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	/* Create "main" as first subroutine */ | 
					
						
							|  |  |  | 	getsubbyname(scr, "main", NULL, 0); | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	while (!feof(f)) { | 
					
						
							| 
									
										
										
										
											2008-11-02 18:52:13 +00:00
										 |  |  | 		if (!fgets(buf, sizeof(buf), f)) { | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (!feof(f)) { | 
					
						
							|  |  |  | 			lineno++; | 
					
						
							|  |  |  | 			/* Trim off trailing return */ | 
					
						
							|  |  |  | 			buf[strlen(buf) - 1] = '\0'; | 
					
						
							|  |  |  | 			/* Strip comments */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 			if ((c = strchr(buf, ';'))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				*c = '\0'; | 
					
						
							| 
									
										
										
										
											2004-05-04 19:11:25 +00:00
										 |  |  | 			if (!ast_strlen_zero(buf)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				adsi_process(scr, buf, script, lineno); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	fclose(f); | 
					
						
							|  |  |  | 	/* Make sure we're in the main routine again */ | 
					
						
							|  |  |  | 	switch(scr->state) { | 
					
						
							|  |  |  | 	case STATE_NORMAL: | 
					
						
							|  |  |  | 		break; | 
					
						
							|  |  |  | 	case STATE_INSUB: | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Missing ENDSUB at end of file %s\n", script); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(scr); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	case STATE_INKEY: | 
					
						
							|  |  |  | 		ast_log(LOG_WARNING, "Missing ENDKEY at end of file %s\n", script); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(scr); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	err = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Resolve all keys and record their lengths */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < scr->numkeys; x++) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (!scr->keys[x].defined) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Key '%s' referenced but never defined in file %s\n", scr->keys[x].vname, fn); | 
					
						
							|  |  |  | 			err++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Resolve all subs */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < scr->numsubs; x++) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		if (!scr->subs[x].defined) { | 
					
						
							|  |  |  | 			ast_log(LOG_WARNING, "Subscript '%s' referenced but never defined in file %s\n", scr->subs[x].vname, fn); | 
					
						
							|  |  |  | 			err++; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		if (x == (scr->numsubs - 1)) { | 
					
						
							|  |  |  | 			/* Clear out extension bit on last message */ | 
					
						
							|  |  |  | 			scr->subs[x].data[2] = 0x80; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (err) { | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(scr); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return NULL; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	return scr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifdef DUMP_MESSAGES
 | 
					
						
							|  |  |  | static void dump_message(char *type, char *vname, unsigned char *buf, int buflen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	int x; | 
					
						
							|  |  |  | 	printf("%s %s: [ ", type, vname); | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < buflen; x++) | 
					
						
							| 
									
										
										
										
											2014-12-17 10:23:32 +00:00
										 |  |  | 		printf("%02hhx ", buf[x]); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	printf("]\n"); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int adsi_prog(struct ast_channel *chan, const char *script) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	struct adsi_script *scr; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	int x, bytes; | 
					
						
							| 
									
										
										
										
											2005-09-07 18:55:03 +00:00
										 |  |  | 	unsigned char buf[1024]; | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	if (!(scr = compile_script(script))) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Start an empty ADSI Session */ | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 	if (ast_adsi_load_session(chan, NULL, 0, 1) < 1) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	/* Now begin the download attempt */ | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 	if (ast_adsi_begin_download(chan, scr->desc, scr->fdn, scr->sec, scr->ver)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		/* User rejected us for some reason */ | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(3, "User rejected download attempt\n"); | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 		ast_log(LOG_NOTICE, "User rejected download on channel %s\n", ast_channel_name(chan)); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(scr); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bytes = 0; | 
					
						
							|  |  |  | 	/* Start with key definitions */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < scr->numkeys; x++) { | 
					
						
							| 
									
										
										
										
											2004-07-26 03:23:38 +00:00
										 |  |  | 		if (bytes + scr->keys[x].retstrlen > 253) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			/* Send what we've collected so far */ | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 			if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			bytes =0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		memcpy(buf + bytes, scr->keys[x].retstr, scr->keys[x].retstrlen); | 
					
						
							|  |  |  | 		bytes += scr->keys[x].retstrlen; | 
					
						
							|  |  |  | #ifdef DUMP_MESSAGES
 | 
					
						
							|  |  |  | 		dump_message("Key", scr->keys[x].vname, scr->keys[x].retstr, scr->keys[x].retstrlen); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (bytes) { | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 		if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bytes = 0; | 
					
						
							|  |  |  | 	/* Continue with the display messages */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < scr->numdisplays; x++) { | 
					
						
							| 
									
										
										
										
											2004-07-26 03:23:38 +00:00
										 |  |  | 		if (bytes + scr->displays[x].datalen > 253) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			/* Send what we've collected so far */ | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 			if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			bytes =0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		memcpy(buf + bytes, scr->displays[x].data, scr->displays[x].datalen); | 
					
						
							|  |  |  | 		bytes += scr->displays[x].datalen; | 
					
						
							|  |  |  | #ifdef DUMP_MESSAGES
 | 
					
						
							|  |  |  | 		dump_message("Display", scr->displays[x].vname, scr->displays[x].data, scr->displays[x].datalen); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (bytes) { | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 		if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bytes = 0; | 
					
						
							|  |  |  | 	/* Send subroutines */ | 
					
						
							| 
									
										
										
										
											2007-09-19 17:14:02 +00:00
										 |  |  | 	for (x = 0; x < scr->numsubs; x++) { | 
					
						
							| 
									
										
										
										
											2004-07-26 03:23:38 +00:00
										 |  |  | 		if (bytes + scr->subs[x].datalen > 253) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			/* Send what we've collected so far */ | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 			if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 				ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x); | 
					
						
							|  |  |  | 				return -1; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			bytes =0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		memcpy(buf + bytes, scr->subs[x].data, scr->subs[x].datalen); | 
					
						
							|  |  |  | 		bytes += scr->subs[x].datalen; | 
					
						
							|  |  |  | #ifdef DUMP_MESSAGES
 | 
					
						
							|  |  |  | 		dump_message("Sub", scr->subs[x].vname, scr->subs[x].data, scr->subs[x].datalen); | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	if (bytes) { | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 		if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DOWNLOAD)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 			ast_log(LOG_WARNING, "Unable to send chunk ending at %d\n", x); | 
					
						
							|  |  |  | 			return -1; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	bytes = 0; | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 	bytes += ast_adsi_display(buf, ADSI_INFO_PAGE, 1, ADSI_JUST_LEFT, 0, "Download complete.", ""); | 
					
						
							|  |  |  | 	bytes += ast_adsi_set_line(buf, ADSI_INFO_PAGE, 1); | 
					
						
							|  |  |  | 	if (ast_adsi_transmit_message(chan, buf, bytes, ADSI_MSG_DISPLAY) < 0) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return -1; | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 	if (ast_adsi_end_download(chan)) { | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		/* Download failed for some reason */ | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(3, "Download attempt failed\n"); | 
					
						
							| 
									
										
										
										
											2012-01-09 22:15:50 +00:00
										 |  |  | 		ast_log(LOG_NOTICE, "Download failed on %s\n", ast_channel_name(chan)); | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 		ast_free(scr); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		return -1; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-06-06 21:20:11 +00:00
										 |  |  | 	ast_free(scr); | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 	ast_adsi_unload_session(chan); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-05-21 21:13:09 +00:00
										 |  |  | static int adsi_exec(struct ast_channel *chan, const char *data) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 14:39:29 +00:00
										 |  |  | 	int res = 0; | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-10-26 19:48:14 +00:00
										 |  |  | 	if (ast_strlen_zero(data)) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		data = "asterisk.adsi"; | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-09-20 04:34:51 +00:00
										 |  |  | 	if (!ast_adsi_available(chan)) { | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(3, "ADSI Unavailable on CPE.  Not bothering to try.\n"); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	} else { | 
					
						
							| 
									
										
										
										
											2007-07-26 15:49:18 +00:00
										 |  |  | 		ast_verb(3, "ADSI Available on CPE.  Attempting Upload.\n"); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 		res = adsi_prog(chan, data); | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2008-02-07 21:08:46 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | 	return res; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int unload_module(void) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2007-07-16 13:35:20 +00:00
										 |  |  | 	return ast_unregister_application(app); | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-10-01 23:22:50 +00:00
										 |  |  | /*!
 | 
					
						
							|  |  |  |  * \brief Load the module | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Module loading including tests for configuration or dependencies. | 
					
						
							|  |  |  |  * This function can return AST_MODULE_LOAD_FAILURE, AST_MODULE_LOAD_DECLINE, | 
					
						
							|  |  |  |  * or AST_MODULE_LOAD_SUCCESS. If a dependency or environment variable fails | 
					
						
							| 
									
										
										
										
											2017-12-22 09:23:22 -05:00
										 |  |  |  * tests return AST_MODULE_LOAD_FAILURE. If the module can not load the | 
					
						
							|  |  |  |  * configuration file or other non-critical problem return | 
					
						
							| 
									
										
										
										
											2012-10-01 23:22:50 +00:00
										 |  |  |  * AST_MODULE_LOAD_DECLINE. On success return AST_MODULE_LOAD_SUCCESS. | 
					
						
							|  |  |  |  */ | 
					
						
							| 
									
										
										
										
											2006-08-21 02:11:39 +00:00
										 |  |  | static int load_module(void) | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2008-11-01 21:10:07 +00:00
										 |  |  | 	if (ast_register_application_xml(app, adsi_exec)) | 
					
						
							| 
									
										
										
										
											2017-04-11 10:07:39 -06:00
										 |  |  | 		return AST_MODULE_LOAD_DECLINE; | 
					
						
							| 
									
										
										
										
											2007-12-26 20:02:27 +00:00
										 |  |  | 	return AST_MODULE_LOAD_SUCCESS; | 
					
						
							| 
									
										
										
										
											2002-06-21 01:40:13 +00:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-09-02 05:27:53 +00:00
										 |  |  | AST_MODULE_INFO(ASTERISK_GPL_KEY, AST_MODFLAG_DEFAULT, "Asterisk ADSI Programming Application", | 
					
						
							| 
									
										
										
										
											2018-07-17 10:24:02 +00:00
										 |  |  | 	.support_level = AST_MODULE_SUPPORT_DEPRECATED, | 
					
						
							| 
									
										
										
										
											2015-05-05 20:49:04 -04:00
										 |  |  | 	.load = load_module, | 
					
						
							|  |  |  | 	.unload = unload_module, | 
					
						
							| 
									
										
										
										
											2017-11-19 17:30:49 -05:00
										 |  |  | 	.requires = "res_adsi", | 
					
						
							| 
									
										
										
										
											2015-05-05 20:49:04 -04:00
										 |  |  | ); |