Index: config.c
===================================================================
RCS file: /usr/cvsroot/asterisk/config.c,v
retrieving revision 1.50
diff -u -r1.50 config.c
--- config.c	25 Jan 2005 06:10:19 -0000	1.50
+++ config.c	1 Feb 2005 18:11:09 -0000
@@ -30,6 +30,8 @@
 #include <asterisk/options.h>
 #include <asterisk/logger.h>
 #include <asterisk/utils.h>
+#include <asterisk/channel.h>
+#include <asterisk/app.h>
 #include "asterisk.h"
 #include "astconf.h"
 
@@ -322,11 +324,12 @@
 
 static int process_text_line(struct ast_config *cfg, struct ast_category **cat, char *buf, int lineno, const char *configfile)
 {
-	char *c;
-	char *cur;
-	struct ast_variable *v;
-	int object;
-
+	char *c = NULL;
+	char *cur = NULL;
+	char cmd[512] = "", exec_file[512] = "";
+	struct ast_variable *v = NULL;
+	int object = 0, do_exec = 0, do_include = 0;
+	
 	cur = ast_strip(buf);
 	if (ast_strlen_zero(cur))
 		return 0;
@@ -361,8 +364,10 @@
 				c = NULL;
 		} else 
 			c = NULL;
-		if (!strcasecmp(cur, "include")) {
-			/* A #include */
+		do_include = strcasecmp(cur, "include") ? 0 : 1;
+		if(!do_include && option_exec_includes)
+			do_exec = strcasecmp(cur, "exec") ? 0 : 1;
+		if (do_include || do_exec) {
 			if (c) {
 				/* Strip off leading and trailing "'s and <>'s */
 				while((*c == '<') || (*c == '>') || (*c == '\"')) c++;
@@ -375,11 +380,28 @@
 					else
 						break;
 				}
-
-				if (!ast_config_internal_load(cur, cfg))
+				/* #exec </path/to/executable>
+				   We create a tmp file, then we #include it, then we delete it. */
+				if (do_exec) { 
+					snprintf(exec_file, sizeof(exec_file), "/var/tmp/exec.%ld.%ld", time(NULL), pthread_self());
+					snprintf(cmd, sizeof(cmd), "%s > %s 2>&1", cur, exec_file);
+					ast_safe_system(cmd);
+					cur = exec_file;
+				}
+				/* A #include */
+				do_include = ast_config_internal_load(cur, cfg) ? 1 : 0;
+				if(!ast_strlen_zero(exec_file))
+					unlink(exec_file);
+				if(!do_include)
 					return -1;
-			} else
-				ast_log(LOG_WARNING, "Directive '#include' needs an argument (filename) at line %d of %s\n", lineno, configfile);
+
+			} else {
+				ast_log(LOG_WARNING, "Directive '#%s' needs an argument (%s) at line %d of %s\n", 
+						do_exec ? "exec" : "include",
+						do_exec ? "/path/to/executable" : "filename",
+						lineno,
+						configfile);
+			}
 		}
 		else 
 			ast_log(LOG_WARNING, "Unknown directive '%s' at line %d of %s\n", cur, lineno, configfile);
@@ -766,10 +788,10 @@
 
 struct ast_config *ast_config_internal_load(const char *filename, struct ast_config *cfg)
 {
-	char db[256];
-	char table[256];
+	char db[256] = "";
+	char table[256] = "";
 	struct ast_config_engine *loader = &text_file_engine;
-	struct ast_config *result;
+	struct ast_config *result = NULL;
 
 	if (cfg->include_level == cfg->max_include_level) {
 		ast_log(LOG_WARNING, "Maximum Include level (%d) exceeded\n", cfg->max_include_level);
@@ -782,6 +804,8 @@
 		struct ast_config_engine *eng;
 
 		eng = find_engine(filename, db, sizeof(db), table, sizeof(table));
+
+
 		if (eng && eng->load_func) {
 			loader = eng;
 		} else {
@@ -792,6 +816,7 @@
 	}
 
 	result = loader->load_func(db, table, filename, cfg);
+
 	if (result)
 		result->include_level--;
 
Index: asterisk.c
===================================================================
RCS file: /usr/cvsroot/asterisk/asterisk.c,v
retrieving revision 1.137
diff -u -r1.137 asterisk.c
--- asterisk.c	25 Jan 2005 06:10:19 -0000	1.137
+++ asterisk.c	1 Feb 2005 18:11:09 -0000
@@ -70,6 +70,7 @@
 
 int option_verbose=0;
 int option_debug=0;
+int option_exec_includes=0;
 int option_nofork=0;
 int option_quiet=0;
 int option_console=0;
@@ -1547,6 +1548,8 @@
 	while(v) {
 		if (!strcasecmp(v->name, "verbose")) {
 			option_verbose= atoi(v->value);
+		} else if (!strcasecmp(v->name, "exec_includes")) {
+			option_exec_includes = ast_true(v->value);
 		} else if (!strcasecmp(v->name, "debug")) {
 			option_debug= ast_true(v->value);
 		} else if (!strcasecmp(v->name, "nofork")) {
@@ -1620,8 +1623,11 @@
 	}
 	*/
 	/* Check for options */
-	while((c=getopt(argc, argv, "thfdvVqprRgcinx:U:G:C:")) != -1) {
+	while((c=getopt(argc, argv, "ethfdvVqprRgcinx:U:G:C:")) != -1) {
 		switch(c) {
+		case 'e':
+			option_exec_includes++;
+			break;
 		case 'd':
 			option_debug++;
 			option_nofork++;
Index: include/asterisk/options.h
===================================================================
RCS file: /usr/cvsroot/asterisk/include/asterisk/options.h,v
retrieving revision 1.9
diff -u -r1.9 options.h
--- include/asterisk/options.h	7 Sep 2004 01:49:08 -0000	1.9
+++ include/asterisk/options.h	1 Feb 2005 18:11:09 -0000
@@ -28,6 +28,7 @@
 extern int option_initcrypto;
 extern int option_nocolor;
 extern int fully_booted;
+extern int option_exec_includes;
 extern int option_cache_record_files;
 extern char defaultlanguage[];
 extern time_t ast_startuptime;
