aboutsummaryrefslogtreecommitdiffstats
path: root/utils
diff options
context:
space:
mode:
authormurf <murf@f38db490-d61c-443f-a65b-d21fe96a405b>2007-08-15 19:21:27 +0000
committermurf <murf@f38db490-d61c-443f-a65b-d21fe96a405b>2007-08-15 19:21:27 +0000
commite897b4499e9719aea235ebe6e67c18183e043dea (patch)
tree85730165ce45a65a5e7bfcc9fceab9626317e49d /utils
parent46d935c8ca1dd16a67f246814417c3bf1ae2ebb6 (diff)
This commit closes bug 7605, and half-closes 7638. The AEL code has been redistributed/repartitioned to allow code re-use both inside and outside of Asterisk. This commit introduces the utils/conf2ael program, and an external config-file reader, for both normal config files, and for extensions.conf (context, exten, prio); It provides an API for programs outside of asterisk to use to play with the dialplan and config files.
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@79595 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'utils')
-rw-r--r--utils/Makefile31
-rw-r--r--utils/ael_main.c94
-rw-r--r--utils/check_expr.c65
3 files changed, 128 insertions, 62 deletions
diff --git a/utils/Makefile b/utils/Makefile
index fb6fb60a3..246eac266 100644
--- a/utils/Makefile
+++ b/utils/Makefile
@@ -16,7 +16,7 @@
.PHONY: clean all uninstall
# to get check_expr, add it to the ALL_UTILS list
-ALL_UTILS:=astman smsq stereorize streamplayer aelparse muted check_expr
+ALL_UTILS:=astman smsq stereorize streamplayer aelparse muted check_expr conf2ael
UTILS:=$(ALL_UTILS)
include $(ASTTOPDIR)/Makefile.rules
@@ -40,6 +40,7 @@ endif
ifneq ($(filter pbx_ael,$(MENUSELECT_PBX)),)
UTILS:=$(filter-out aelparse,$(UTILS))
+ UTILS:=$(filter-out conf2ael,$(UTILS))
endif
all: $(UTILS)
@@ -57,8 +58,8 @@ uninstall:
clean:
rm -f *.o $(ALL_UTILS) check_expr
rm -f .*.o.d .*.oo.d
- rm -f md5.c strcompat.c ast_expr2.c ast_expr2f.c pbx_ael.c
- rm -f aelparse.c aelbison.c
+ rm -f md5.c strcompat.c ast_expr2.c ast_expr2f.c pbx_ael.c pval.c
+ rm -f aelparse.c aelbison.c conf2ael
md5.c: ../main/md5.c
@cp $< $@
@@ -80,6 +81,9 @@ strcompat.c: ../main/strcompat.c
@echo " [FLEX] ../main/ast_expr2.fl -> $@"
@flex -o $@ --full ../main/ast_expr2.fl
+pval.c: ../res/ael/pval.c
+ @cp $< $@
+
ast_expr2.c: ../main/ast_expr2.c
@cp $< $@
@@ -88,12 +92,14 @@ ast_expr2f.c: ../main/ast_expr2f.c
ast_expr2f.o: ASTCFLAGS+=-DSTANDALONE_AEL -I../main
+pval.o : ASTCFLAGS+=-DSTANDALONE
+
check_expr: check_expr.o ast_expr2.o ast_expr2f.o
-aelbison.c: ../pbx/ael/ael.tab.c
+aelbison.c: ../res/ael/ael.tab.c
@cp $< $@
-aelbison.o: aelbison.c ../pbx/ael/ael.tab.h ../include/asterisk/ael_structs.h
-aelbison.o: ASTCFLAGS+=-I../pbx/ael -DYYENABLE_NLS=0
+aelbison.o: aelbison.c ../res/ael/ael.tab.h ../include/asterisk/ael_structs.h
+aelbison.o: ASTCFLAGS+=-I../res/ael -DYYENABLE_NLS=0
pbx_ael.c: ../pbx/pbx_ael.c
@cp $< $@
@@ -101,12 +107,17 @@ pbx_ael.o: ASTCFLAGS+=-DSTANDALONE_AEL
ael_main.o: ael_main.c ../include/asterisk/ael_structs.h
-aelparse.c: ../pbx/ael/ael_lex.c
+aelparse.c: ../res/ael/ael_lex.c
@cp $< $@
-aelparse.o: aelparse.c ../include/asterisk/ael_structs.h ../pbx/ael/ael.tab.h
-aelparse.o: ASTCFLAGS+=-I../pbx -DSTANDALONE_AEL
+aelparse.o: aelparse.c ../include/asterisk/ael_structs.h ../res/ael/ael.tab.h
+aelparse.o: ASTCFLAGS+=-I../res -DSTANDALONE_AEL
+
+aelparse: aelparse.o aelbison.o pbx_ael.o ael_main.o ast_expr2f.o ast_expr2.o strcompat.o pval.o extconf.o
+
+extconf.o : extconf.c
+
+conf2ael: conf2ael.o ast_expr2f.o ast_expr2.o aelbison.o aelparse.o pbx_ael.o pval.o extconf.o
-aelparse: aelparse.o aelbison.o pbx_ael.o ael_main.o ast_expr2f.o ast_expr2.o strcompat.o
testexpr2s: ../main/ast_expr2f.c ../main/ast_expr2.c ../main/ast_expr2.h
$(CC) -g -c -I../include -DSTANDALONE_AEL ../main/ast_expr2f.c -o ast_expr2f.o
diff --git a/utils/ael_main.c b/utils/ael_main.c
index 76562c381..6c166922f 100644
--- a/utils/ael_main.c
+++ b/utils/ael_main.c
@@ -10,11 +10,13 @@
#include <limits.h>
#include "asterisk/compat.h"
-#include "asterisk/ast_expr.h"
#include "asterisk/channel.h"
+#include "asterisk/ast_expr.h"
+#include "asterisk/ast_expr.h"
#include "asterisk/module.h"
#include "asterisk/app.h"
#include "asterisk/ael_structs.h"
+#include "asterisk/extconf.h"
struct namelist
{
@@ -106,6 +108,41 @@ static int dump_extensions = 0;
static int FIRST_TIME = 0;
static FILE *dumpfile;
+void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
+{
+ va_list vars;
+ va_start(vars,fmt);
+
+ printf("LOG: lev:%d file:%s line:%d func: %s ",
+ level, file, line, function);
+ vprintf(fmt, vars);
+ fflush(stdout);
+ va_end(vars);
+}
+
+struct ast_exten *pbx_find_extension(struct ast_channel *chan,
+ struct ast_context *bypass,
+ struct pbx_find_info *q,
+ const char *context,
+ const char *exten,
+ int priority,
+ const char *label,
+ const char *callerid,
+ enum ext_match_t action);
+
+struct ast_exten *pbx_find_extension(struct ast_channel *chan,
+ struct ast_context *bypass,
+ struct pbx_find_info *q,
+ const char *context,
+ const char *exten,
+ int priority,
+ const char *label,
+ const char *callerid,
+ enum ext_match_t action)
+{
+ return localized_find_extension(bypass, q, context, exten, priority, label, callerid, action);
+}
+
struct ast_app *pbx_findapp(const char *app)
{
return (struct ast_app*)1; /* so as not to trigger an error */
@@ -390,56 +427,6 @@ void ast_context_destroy(void)
printf("Executed ast_context_destroy();\n");
}
-void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...)
-{
- va_list vars;
- va_start(vars,fmt);
- if( !quiet || level > 2 ) {
- printf("LOG: lev:%d file:%s line:%d func: %s ",
- level, file, line, function);
- vprintf(fmt, vars);
- fflush(stdout);
- va_end(vars);
- }
-}
-
-void ast_verbose(const char *fmt, ...)
-{
- va_list vars;
- va_start(vars,fmt);
-
- printf("VERBOSE: ");
- vprintf(fmt, vars);
- fflush(stdout);
- va_end(vars);
-}
-
-char *ast_process_quotes_and_slashes(char *start, char find, char replace_with)
-{
- char *dataPut = start;
- int inEscape = 0;
- int inQuotes = 0;
-
- for (; *start; start++) {
- if (inEscape) {
- *dataPut++ = *start; /* Always goes verbatim */
- inEscape = 0;
- } else {
- if (*start == '\\') {
- inEscape = 1; /* Do not copy \ into the data */
- } else if (*start == '\'') {
- inQuotes = 1-inQuotes; /* Do not copy ' into the data */
- } else {
- /* Replace , with |, unless in quotes */
- *dataPut++ = inQuotes ? *start : ((*start==find) ? replace_with : *start);
- }
- }
- }
- if (start != dataPut)
- *dataPut = 0;
- return dataPut;
-}
-
void filter_leading_space_from_exprs(char *str)
{
/* Mainly for aesthetics */
@@ -478,7 +465,8 @@ void filter_newlines(char *str)
extern struct module_symbols mod_data;
-extern int ael_external_load_module(void);
+int ael_external_load_module(void);
+
int main(int argc, char **argv)
{
@@ -511,9 +499,11 @@ int main(int argc, char **argv)
if( use_curr_dir ) {
strcpy(ast_config_AST_CONFIG_DIR, ".");
+ localized_use_local_dir();
}
else {
strcpy(ast_config_AST_CONFIG_DIR, "/etc/asterisk");
+ localized_use_conf_dir();
}
strcpy(ast_config_AST_VAR_DIR, "/var/lib/asterisk");
diff --git a/utils/check_expr.c b/utils/check_expr.c
index f64147242..db7877539 100644
--- a/utils/check_expr.c
+++ b/utils/check_expr.c
@@ -21,8 +21,67 @@
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
+
+struct ast_channel
+{
+ char x; /* basically empty! */
+};
+
#include <../include/asterisk/compat.h>
#include <../include/asterisk/ast_expr.h>
+#define AST_API_MODULE 1
+#include "asterisk/inline_api.h"
+#include "asterisk/strings.h"
+
+/* I included this from utils.c, so as not to have everything in that .c
+ file included */
+/*!
+ * core handler for dynamic strings.
+ * This is not meant to be called directly, but rather through the
+ * various wrapper macros
+ * ast_str_set(...)
+ * ast_str_append(...)
+ * ast_str_set_va(...)
+ * ast_str_append_va(...)
+ */
+int __ast_str_helper(struct ast_str **buf, size_t max_len,
+ int append, const char *fmt, va_list ap)
+{
+ int res, need;
+ int offset = (append && (*buf)->len) ? (*buf)->used : 0;
+
+ if (max_len < 0)
+ max_len = (*buf)->len; /* don't exceed the allocated space */
+ /*
+ * Ask vsnprintf how much space we need. Remember that vsnprintf
+ * does not count the final '\0' so we must add 1.
+ */
+ res = vsnprintf((*buf)->str + offset, (*buf)->len - offset, fmt, ap);
+
+ need = res + offset + 1;
+ /*
+ * If there is not enough space and we are below the max length,
+ * reallocate the buffer and return a message telling to retry.
+ */
+ if (need > (*buf)->len && (max_len == 0 || (*buf)->len < max_len) ) {
+ if (max_len && max_len < need) /* truncate as needed */
+ need = max_len;
+ else if (max_len == 0) /* if unbounded, give more room for next time */
+ need += 16 + need/4;
+ if (ast_str_make_space(buf, need)) {
+ return AST_DYNSTR_BUILD_FAILED;
+ }
+ (*buf)->str[offset] = '\0'; /* Truncate the partial write. */
+
+ /* va_end() and va_start() must be done before calling
+ * vsnprintf() again. */
+ return AST_DYNSTR_BUILD_RETRY;
+ }
+ /* update space used, keep in mind the truncation */
+ (*buf)->used = (res + offset > (*buf)->len) ? (*buf)->len : res + offset;
+
+ return res;
+}
static int global_lineno = 1;
static int global_expr_count=0;
@@ -83,6 +142,8 @@ char *find_var(const char *varname) /* the list should be pretty short, if there
return 0;
}
+void set_var(const char *varname, const char *varval);
+
void set_var(const char *varname, const char *varval)
{
struct varz *t = (struct varz*)calloc(1,sizeof(struct varz));
@@ -162,6 +223,8 @@ unsigned int check_expr(char* buffer, char* error_report)
return warn_found;
}
+int check_eval(char *buffer, char *error_report);
+
struct ast_custom_function *ast_custom_function_find(const char *name);
struct ast_custom_function *ast_custom_function_find(const char *name)
@@ -240,6 +303,8 @@ int check_eval(char *buffer, char *error_report)
}
+void parse_file(const char *fname);
+
void parse_file(const char *fname)
{
FILE *f = fopen(fname,"r");