[asterisk-commits] murf: branch murf/bug_7638 r59031 - in /team/murf/bug_7638: include/asterisk/...

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Fri Mar 16 13:57:06 MST 2007


Author: murf
Date: Fri Mar 16 15:57:05 2007
New Revision: 59031

URL: http://svn.digium.com/view/asterisk?view=rev&rev=59031
Log:
a quick checkpoint checkin; I may have broke everything, but so be it.

Added:
    team/murf/bug_7638/include/asterisk/extconf.h   (with props)
Modified:
    team/murf/bug_7638/utils/conf2ael.c
    team/murf/bug_7638/utils/extconf.c

Added: team/murf/bug_7638/include/asterisk/extconf.h
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7638/include/asterisk/extconf.h?view=auto&rev=59031
==============================================================================
--- team/murf/bug_7638/include/asterisk/extconf.h (added)
+++ team/murf/bug_7638/include/asterisk/extconf.h Fri Mar 16 15:57:05 2007
@@ -1,0 +1,166 @@
+/*  
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 2007, Digium, Inc.
+ *
+ * Steve Murphy <murf at digium.com>
+ *
+ * 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.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#ifdef NOTYET
+/* I'm going to define all the structs mentioned below, to avoid
+   possible conflicts in declarations that might be introduced, 
+   if we just include the files that define them-- this may be
+   unnecessary */
+
+struct ast_comment {
+	struct ast_comment *next;
+	char cmt[0];
+};
+
+struct ast_variable {
+	char *name;
+	char *value;
+	int lineno;
+	int object;		/*!< 0 for variable, 1 for object */
+	int blanklines; 	/*!< Number of blanklines following entry */
+	struct ast_comment *precomments;
+	struct ast_comment *sameline;
+	struct ast_variable *next;
+	char stuff[0];
+};
+
+struct ast_category {
+	char name[80];
+	int ignored;			/*!< do not let user of the config see this category */
+	int include_level;	
+	struct ast_comment *precomments;
+	struct ast_comment *sameline;
+	struct ast_variable *root;
+	struct ast_variable *last;
+	struct ast_category *next;
+};
+
+struct ast_config {
+	struct ast_category *root;
+	struct ast_category *last;
+	struct ast_category *current;
+	struct ast_category *last_browse;		/*!< used to cache the last category supplied via category_browse */
+	int include_level;
+	int max_include_level;
+};
+
+/* ================== above: the config world; below, the dialplan world */
+
+/*! \brief ast_app: A registered application */
+struct ast_app {
+	int (*execute)(struct ast_channel *chan, void *data);
+	const char *synopsis;			/*!< Synopsis text for 'show applications' */
+	const char *description;		/*!< Description (help text) for 'show application &lt;name&gt;' */
+	AST_RWLIST_ENTRY(ast_app) list;		/*!< Next app in list */
+	void *module;			/*!< Module this app belongs to */
+	char name[0];				/*!< Name of the application */
+};
+/*!
+   \brief ast_exten: An extension
+	The dialplan is saved as a linked list with each context
+	having it's own linked list of extensions - one item per
+	priority.
+*/
+struct ast_exten {
+	char *exten;			/*!< Extension name */
+	int matchcid;			/*!< Match caller id ? */
+	const char *cidmatch;		/*!< Caller id to match for this extension */
+	int priority;			/*!< Priority */
+	const char *label;		/*!< Label */
+	struct ast_context *parent;	/*!< The context this extension belongs to  */
+	const char *app; 		/*!< Application to execute */
+	struct ast_app *cached_app;     /*!< Cached location of application */
+	void *data;			/*!< Data to use (arguments) */
+	void (*datad)(void *);		/*!< Data destructor */
+	struct ast_exten *peer;		/*!< Next higher priority with our extension */
+	const char *registrar;		/*!< Registrar */
+	struct ast_exten *next;		/*!< Extension with a greater ID */
+	char stuff[0];
+};
+/* from pbx.h */
+typedef int (*ast_state_cb_type)(char *context, char* id, enum ast_extension_states state, void *data);
+struct ast_timing {
+	int hastime;				/*!< If time construct exists */
+	unsigned int monthmask;			/*!< Mask for month */
+	unsigned int daymask;			/*!< Mask for date */
+	unsigned int dowmask;			/*!< Mask for day of week (mon-sun) */
+	unsigned int minmask[24];		/*!< Mask for minute */
+};
+/*! \brief ast_include: include= support in extensions.conf */
+struct ast_include {
+	const char *name;
+	const char *rname;			/*!< Context to include */
+	const char *registrar;			/*!< Registrar */
+	int hastime;				/*!< If time construct exists */
+	struct ast_timing timing;               /*!< time construct */
+	struct ast_include *next;		/*!< Link them together */
+	char stuff[0];
+};
+
+/*! \brief ast_sw: Switch statement in extensions.conf */
+struct ast_sw {
+	char *name;
+	const char *registrar;			/*!< Registrar */
+	char *data;				/*!< Data load */
+	int eval;
+	AST_LIST_ENTRY(ast_sw) list;
+	char *tmpdata;
+	char stuff[0];
+};
+
+*! \brief ast_ignorepat: Ignore patterns in dial plan */
+struct ast_ignorepat {
+	const char *registrar;
+	struct ast_ignorepat *next;
+	const char pattern[0];
+};
+
+/*! \brief ast_context: An extension context */
+struct ast_context {
+	ast_rwlock_t lock; 			/*!< A lock to prevent multiple threads from clobbering the context */
+	struct ast_exten *root;			/*!< The root of the list of extensions */
+	struct ast_context *next;		/*!< Link them together */
+	struct ast_include *includes;		/*!< Include other contexts */
+	struct ast_ignorepat *ignorepats;	/*!< Patterns for which to continue playing dialtone */
+	const char *registrar;			/*!< Registrar */
+	AST_LIST_HEAD_NOLOCK(, ast_sw) alts;	/*!< Alternative switches */
+	ast_mutex_t macrolock;			/*!< A lock to implement "exclusive" macros - held whilst a call is executing in the macro */
+	char name[0];				/*!< Name of the context */
+};
+
+#endif
+
+struct ast_config *localized_config_load(const char *filename);
+struct ast_config *localized_config_load_with_comments(const char *filename);
+struct ast_category *localized_category_get(const struct ast_config *config, const char *category_name);
+int localized_config_text_file_save(const char *configfile, const struct ast_config *cfg, const char *generator);
+struct ast_context *localized_walk_contexts(struct ast_context *con);
+struct ast_exten *localized_walk_context_extensions(struct ast_context *con,
+													struct ast_exten *exten);
+struct ast_exten *localized_walk_extension_priorities(struct ast_exten *exten,
+													  struct ast_exten *priority);
+struct ast_include *localized_walk_context_includes(struct ast_context *con,
+													struct ast_include *inc);
+struct ast_sw *localized_walk_context_switches(struct ast_context *con,
+											   struct ast_sw *sw);
+
+void localized_context_destroy(struct ast_context *con, const char *registrar);
+int localized_pbx_load_module(void);
+
+struct ast_context *localize_context_create(struct ast_context **extcontexts, const char *name, const char *registrar);
+

Propchange: team/murf/bug_7638/include/asterisk/extconf.h
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: team/murf/bug_7638/include/asterisk/extconf.h
------------------------------------------------------------------------------
    svn:keywords = Author Id Date Revision

Propchange: team/murf/bug_7638/include/asterisk/extconf.h
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: team/murf/bug_7638/utils/conf2ael.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7638/utils/conf2ael.c?view=diff&rev=59031&r1=59030&r2=59031
==============================================================================
--- team/murf/bug_7638/utils/conf2ael.c (original)
+++ team/murf/bug_7638/utils/conf2ael.c Fri Mar 16 15:57:05 2007
@@ -54,8 +54,8 @@
 #include "asterisk/stringfields.h"
 #include "asterisk/ael_structs.h"
 #include "asterisk/pval.h"
-
-int pbx_load_config(const char *config_file);
+#include "asterisk/extconf.h"
+
 void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *start, int *end);
 int all_bits_set(unsigned int *word, int bitsperword, int totalbits);
 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
@@ -289,22 +289,6 @@
 extern struct ast_context *contexts;
 
 
-/* request and result for pbx_find_extension */
-struct pbx_find_info {
-#if 0
-	const char *context;
-	const char *exten;
-	int priority;
-#endif
-
-	char *incstack[AST_PBX_MAX_STACK];      /* filled during the search */
-	int stacklen;                   /* modified during the search */
-	int status;                     /* set on return */
-	struct ast_switch *swo;         /* set on return */
-	const char *data;               /* set on return */
-	const char *foundcontext;       /* set on return */
-};
-
 
 
 struct profile_entry {
@@ -321,6 +305,47 @@
 	struct profile_entry e[0];
 };
 
+static int bit_at(unsigned int *word, int bitsperword, int bitnum)
+{
+ return word[bitnum/bitsperword] & (1 << (bitnum % bitsperword));
+}
+
+void get_start_stop(unsigned int *word, int bitsperword, int totalbits, int *start, int *end)
+{
+ int i;
+ int thisbit, thatbit = bit_at(word, bitsperword, totalbits-1);
+
+ for (i=0; i<totalbits; i++) {
+  thisbit = bit_at(word, bitsperword, i);
+
+  if (thisbit != thatbit ) {
+   if (thisbit) {
+    *start = i;
+   } else {
+    *end = i;
+   }
+  }
+  thatbit = thisbit;
+ }
+}
+
+int all_bits_set(unsigned int *word, int bitsperword, int totalbits )
+{
+
+ int i, total=totalbits/bitsperword,bitmask = 0;
+
+ for (i=0; i<bitsperword; i++)
+ {
+  bitmask |= (1 << i);
+ }
+
+ for (i=0; i<total; i++)
+ {
+  if (word[i] != bitmask)
+   return 0;
+ }
+ return 1;
+}
 
 
 int main(int argc, char **argv)
@@ -345,16 +370,12 @@
 	
 	printf("Loading %s/%s...\n", ast_config_AST_CONFIG_DIR, config);
 	
-	pbx_load_config(config);
-	
-	contexts = local_contexts;
-	
-	local_contexts = 0;
+	localized_pbx_load_module();
 	
 	printf("... Done!\n");
 	
 	tmp = 0;
-	while ((tmp = ast_walk_contexts(tmp)) ) {
+	while ((tmp = localized_walk_contexts(tmp)) ) {
 		/* printf("Context: %s\n", tmp->name); */
 		tmptree = pvalCreateNode(PV_CONTEXT);
 		if (!tree)
@@ -468,7 +489,7 @@
 			ipi = ipi->next;
 		}
 		eroot=0;
-		while ( (eroot = ast_walk_context_extensions(tmp, eroot)) ) {
+		while ( (eroot = localized_walk_context_extensions(tmp, eroot)) ) {
 			pval *exten = pvalCreateNode(PV_EXTENSION);
 			pvalContextAddStatement(tmptree, exten);
 			pvalExtenSetName(exten, ast_strdup(eroot->exten));
@@ -478,7 +499,7 @@
 				pvalExtenSetStatement(exten, block);
 				
 				e = 0;
-				while ( (e = ast_walk_extension_priorities(eroot, e)) ) {
+				while ( (e = localized_walk_extension_priorities(eroot, e)) ) {
 					/* printf("           %s(%s)\n", e->app, (char*)e->data); */
 					
 					pval *statemnt = pvalCreateNode(PV_APPLICATION_CALL);
@@ -510,7 +531,8 @@
 			sws = pvalCreateNode(PV_SWITCHES);
 			pvalContextAddStatement(tmptree,sws);
 			
-			AST_LIST_TRAVERSE(&tmp->alts, sw, list) {
+			sw = 0;
+			while ((sw = localized_walk_context_switches(tmp,sw)) ) {
 				pvalSwitchesAddSwitch(sws, ast_strdup(sw->name));
 			}
 		}
@@ -522,3 +544,7 @@
 	printf("...Done!\n");
 	return 0;
 }
+
+
+/* ==================================== for linking internal stuff to external stuff */
+

Modified: team/murf/bug_7638/utils/extconf.c
URL: http://svn.digium.com/view/asterisk/team/murf/bug_7638/utils/extconf.c?view=diff&rev=59031&r1=59030&r2=59031
==============================================================================
--- team/murf/bug_7638/utils/extconf.c (original)
+++ team/murf/bug_7638/utils/extconf.c Fri Mar 16 15:57:05 2007
@@ -2740,7 +2740,7 @@
 	const char *synopsis;			/*!< Synopsis text for 'show applications' */
 	const char *description;		/*!< Description (help text) for 'show application &lt;name&gt;' */
 	AST_RWLIST_ENTRY(ast_app) list;		/*!< Next app in list */
-	struct module *module;			/*!< Module this app belongs to */
+	void *module;			/*!< Module this app belongs to */
 	char name[0];				/*!< Name of the application */
 };
 
@@ -2852,6 +2852,48 @@
 	return -1;
 }
 
+static unsigned int ast_app_separate_args(char *buf, char delim, char **array, int arraylen)
+{
+	int argc;
+	char *scan;
+	int paren = 0, quote = 0;
+
+	if (!buf || !array || !arraylen)
+		return 0;
+
+	memset(array, 0, arraylen * sizeof(*array));
+
+	scan = buf;
+
+	for (argc = 0; *scan && (argc < arraylen - 1); argc++) {
+		array[argc] = scan;
+		for (; *scan; scan++) {
+			if (*scan == '(')
+				paren++;
+			else if (*scan == ')') {
+				if (paren)
+					paren--;
+			} else if (*scan == '"' && delim != '"') {
+				quote = quote ? 0 : 1;
+				/* Remove quote character from argument */
+				memmove(scan, scan + 1, strlen(scan));
+				scan--;
+			} else if (*scan == '\\') {
+				/* Literal character, don't parse */
+				memmove(scan, scan + 1, strlen(scan));
+			} else if ((*scan == delim) && !paren && !quote) {
+				*scan++ = '\0';
+				break;
+			}
+		}
+	}
+
+	if (*scan)
+		array[argc++] = scan;
+
+	return argc;
+}
+
 static void pbx_builtin_setvar_helper(struct ast_channel *chan, const char *name, const char *value)
 {
 	struct ast_var_t *newvariable;
@@ -2893,10 +2935,52 @@
 
 }
 
+static int pbx_builtin_setvar(struct ast_channel *chan, void *data)
+{
+	char *name, *value, *mydata;
+	int argc;
+	char *argv[24];		/* this will only support a maximum of 24 variables being set in a single operation */
+	int global = 0;
+	int x;
+
+	if (ast_strlen_zero(data)) {
+		ast_log(LOG_WARNING, "Set requires at least one variable name/value pair.\n");
+		return 0;
+	}
+
+	mydata = ast_strdupa(data);
+	argc = ast_app_separate_args(mydata, '|', argv, sizeof(argv) / sizeof(argv[0]));
+
+	/* check for a trailing flags argument */
+	if ((argc > 1) && !strchr(argv[argc-1], '=')) {
+		argc--;
+		if (strchr(argv[argc], 'g'))
+			global = 1;
+	}
+
+	for (x = 0; x < argc; x++) {
+		name = argv[x];
+		if ((value = strchr(name, '='))) {
+			*value++ = '\0';
+			pbx_builtin_setvar_helper((global) ? NULL : chan, name, value);
+		} else
+			ast_log(LOG_WARNING, "Ignoring entry '%s' with no = (and not last 'options' entry)\n", name);
+	}
+
+	return(0);
+}
+
+int localized_pbx_builtin_setvar(struct ast_channel *chan, void *data)
+{
+	return pbx_builtin_setvar(chan, data);
+}
+
+
 /*! \brief Helper for get_range.
  * return the index of the matching entry, starting from 1.
  * If names is not supplied, try numeric values.
  */
+
 static int lookup_name(const char *s, char *const names[], int max)
 {
 	int i;
@@ -4218,6 +4302,14 @@
 	return con ? con->next : contexts;
 }
 
+struct ast_context *localized_walk_contexts(struct ast_context *con);
+struct ast_context *localized_walk_contexts(struct ast_context *con)
+{
+	return ast_walk_contexts(con);
+}
+
+
+
 static struct ast_exten *ast_walk_context_extensions(struct ast_context *con,
 											  struct ast_exten *exten);
 
@@ -4230,6 +4322,15 @@
 		return exten->next;
 }
 
+struct ast_exten *localized_walk_context_extensions(struct ast_context *con,
+													struct ast_exten *exten);
+struct ast_exten *localized_walk_context_extensions(struct ast_context *con,
+													struct ast_exten *exten)
+{
+	return ast_walk_context_extensions(con,exten);
+}
+
+
 static struct ast_exten *ast_walk_extension_priorities(struct ast_exten *exten,
 												struct ast_exten *priority);
 
@@ -4238,6 +4339,16 @@
 {
 	return priority ? priority->peer : exten;
 }
+
+struct ast_exten *localized_walk_extension_priorities(struct ast_exten *exten,
+													  struct ast_exten *priority);
+struct ast_exten *localized_walk_extension_priorities(struct ast_exten *exten,
+													  struct ast_exten *priority)
+{
+	return ast_walk_extension_priorities(exten, priority);
+}
+
+
 
 static struct ast_include *ast_walk_context_includes(struct ast_context *con,
 											  struct ast_include *inc);
@@ -4250,6 +4361,36 @@
 	else
 		return inc->next;
 }
+
+struct ast_include *localized_walk_context_includes(struct ast_context *con,
+													struct ast_include *inc);
+struct ast_include *localized_walk_context_includes(struct ast_context *con,
+													struct ast_include *inc)
+{
+	return ast_walk_context_includes(con, inc);
+}
+
+
+static struct ast_sw *ast_walk_context_switches(struct ast_context *con,
+													 struct ast_sw *sw);
+
+static struct ast_sw *ast_walk_context_switches(struct ast_context *con,
+													 struct ast_sw *sw)
+{
+	if (!sw)
+		return con ? AST_LIST_FIRST(&con->alts) : NULL;
+	else
+		return AST_LIST_NEXT(sw, list);
+}
+
+struct ast_sw *localized_walk_context_switches(struct ast_context *con,
+													struct ast_sw *sw);
+struct ast_sw *localized_walk_context_switches(struct ast_context *con,
+													struct ast_sw *sw)
+{
+	return ast_walk_context_switches(con, sw);
+}
+
 
 static struct ast_context *ast_context_find(const char *name);
 
@@ -5015,6 +5156,17 @@
 {
 	return __ast_context_create(extcontexts, name, registrar, 1);
 }
+
+static struct ast_context *ast_context_create(struct ast_context **extcontexts, const char *name, const char *registrar)
+{
+	return __ast_context_create(extcontexts, name, registrar, 0);
+}
+
+struct ast_context *localize_context_create(struct ast_context **extcontexts, const char *name, const char *registrar)
+{
+	return __ast_context_create(extcontexts, name, registrar, 0);
+}
+
 
 
 /* chopped this one off at the knees */



More information about the asterisk-commits mailing list