Merged revisions 80820 via svnmerge from
[asterisk/asterisk.git] / utils / ael_main.c
index 606ac8d..6a2cb6d 100644 (file)
@@ -1,5 +1,3 @@
-#include "asterisk/autoconfig.h"
-
 #include <sys/types.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -7,18 +5,22 @@
 #include <string.h>
 #include <locale.h>
 #include <ctype.h>
-#if !defined(SOLARIS) && !defined(__CYGWIN__)
-#include <err.h>
-#endif
 #include <errno.h>
 #include <regex.h>
 #include <limits.h>
 
-#include "asterisk/ast_expr.h"
+#include "asterisk/compat.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"
+
+/*** MODULEINFO
+       <depend>res_ael_share</depend>
+ ***/
 
 struct namelist
 {
@@ -110,11 +112,55 @@ 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 */
 }
 
+struct ast_custom_function *ast_custom_function_find(const char *name);
+
+
+struct ast_custom_function *ast_custom_function_find(const char *name)
+{
+       return 0; /* in "standalone" mode, functions are just not avail */
+}
+
+
 void ast_add_profile(void)
 {
        if (!no_comp)
@@ -159,6 +205,17 @@ void ast_unregister_file_version(void)
        /* I'm erasing this, because I don't think anyone really ever needs to see it anyway */
 
 }
+void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count);
+void pbx_substitute_variables_helper(struct ast_channel *c,const char *cp1,char *cp2,int count)
+{
+       if (cp1 && *cp1)
+               strncpy(cp2,cp1,AST_MAX_EXTENSION); /* Right now, this routine is ONLY being called for 
+                                                                                          a possible var substitution on extension names,
+                                                                                          so....! */
+       else
+               *cp2 = 0;
+}
+
 int ast_add_extension2(struct ast_context *con,
                        int replace, const char *extension, int priority, const char *label, const char *callerid,
                        const char *application, void *data, void (*datad)(void *),
@@ -186,6 +243,8 @@ int ast_add_extension2(struct ast_context *con,
 
        if( dump_extensions && dumpfile ) {
                struct namelist *n;
+               char *data2,*data3=0;
+               int commacount = 0;
 
                if( FIRST_TIME ) {
                        FIRST_TIME = 0;
@@ -220,11 +279,43 @@ int ast_add_extension2(struct ast_context *con,
                        filter_newlines((char*)data);
                        filter_leading_space_from_exprs((char*)data);
 
+                       /* compiling turns commas into vertical bars in the app data, and also removes the backslash from before escaped commas;
+                          we have to restore the escaping backslash in front of any commas; the vertical bars are OK to leave as-is */
+                       for (data2 = data; *data2; data2++) {
+                               if (*data2 == ',')
+                                       commacount++;  /* we need to know how much bigger the string will grow-- one backslash for each comma  */
+                       }
+                       if (commacount) 
+                       {
+                               char *d3,*d4;
+                               
+                               data2 = (char*)malloc(strlen(data)+commacount+1);
+                               data3 = data;
+                               d3 = data;
+                               d4 = data2;
+                               while (*d3) {
+                                       if (*d3 == ',') {
+                                               *d4++ = '\\'; /* put a backslash in front of each comma */
+                                               *d4++ = *d3++;
+                                       } else
+                                               *d4++ = *d3++;  /* or just copy the char */
+                               }
+                               *d4++ = 0;  /* cap off the new string */
+                               data = data2;
+                       } else
+                               data2 = 0;
+                       
                        if( strcmp(label,"(null)") != 0  )
                                fprintf(dumpfile,"exten => %s,%d(%s),%s(%s)\n", extension, priority, label, application, (char*)data);
                        else
                                fprintf(dumpfile,"exten => %s,%d,%s(%s)\n", extension, priority, application, (char*)data);
 
+                       if (data2) {
+                               free(data2);
+                               data2 = 0;
+                               data = data3; /* restore data to pre-messedup state */
+                       }
+
                } else {
 
                        if( strcmp(label,"(null)") != 0  )
@@ -340,56 +431,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 */
@@ -428,7 +469,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)
 {
@@ -461,9 +503,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");