Enhance Pickup to do native pickupgroup pickup when no arguments are specified (close...
[asterisk/asterisk.git] / utils / conf2ael.c
index 7caf069..2f5a58a 100644 (file)
@@ -1,7 +1,7 @@
 /*  
  * Asterisk -- An open source telephony toolkit.
  *
- * Copyright (C) 2006, Digium, Inc.
+ * Copyright (C) 2007, Digium, Inc.
  *
  * Steve Murphy <murf@digium.com>
  *
@@ -22,7 +22,9 @@
  *
  */
 
-
+/*** MODULEINFO
+       <depend>res_ael_share</depend>
+ ***/
 
 #include "asterisk/autoconfig.h"
 
 #include "asterisk/ael_structs.h"
 #include "asterisk/devicestate.h"
 #include "asterisk/stringfields.h"
-#include "asterisk/ael_structs.h"
 #include "asterisk/pval.h"
 #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, ...)
-{
-               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);
-}
-
 extern char *days[];
 extern char *months[];
 char ast_config_AST_CONFIG_DIR[PATH_MAX];
@@ -98,7 +87,7 @@ void ast_unregister_file_version(void);
 void ast_register_file_version(void)
 {
        /* if(!no_comp)
-               printf("Executed ast_register_file_version();\n"); */
+          printf("Executed ast_register_file_version();\n"); */
        /* I'm erasing this, because I don't think anyone really ever needs to see it anyway */
 }
 
@@ -107,21 +96,23 @@ void ast_unregister_file_version(void)
        /* if(!no_comp)
                printf("Executed ast_unregister_file_version();\n"); */
        /* I'm erasing this, because I don't think anyone really ever needs to see it anyway */
-
 }
 
-
-
-/* experiment 1: see if it's easier just to use existing config code
- *               to read in the extensions.conf file. In this scenario, 
-                 I have to rip/copy code from other modules, because they
-                 are staticly declared as-is. A solution would be to move
-                 the ripped code to another location and make them available
-                 to other modules and standalones */
-
 /* Our own version of ast_log, since the expr parser uses it. -- stolen from utils/check_expr.c */
 void ast_log(int level, const char *file, int line, const char *function, const char *fmt, ...) __attribute__ ((format (printf,5,6)));
 
+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);
+}
+
 /* stolen from pbx.c */
 struct ast_context;
 struct ast_app;
@@ -351,9 +342,17 @@ int main(int argc, char **argv)
        struct ast_sw *sw = 0;
        struct ast_ignorepat *ipi;
        pval *incl=0;
+       int localdir = 0, i;
 
        tree = 0;
        tmptree = 0;
+
+       /* process the command line args */
+       for (i=1; i<argc; i++)
+       {
+               if (strcmp(argv[i],"-d")==0)
+                       localdir =1;
+       }
        
        /* 3 simple steps: */
        /*   1. read in the extensions.conf config file 
@@ -369,11 +368,15 @@ int main(int argc, char **argv)
        printf("         The result will most likely need careful attention to\n");
        printf("         finish the job!!!!!\n");
 
+       if (!localdir)
+               printf(" (You could use -d the use the extensions.conf in the current directory!)\n");
 
        strcpy(ast_config_AST_CONFIG_DIR,"/etc/asterisk");
        
        printf("Loading %s/%s...\n", ast_config_AST_CONFIG_DIR, config);
-       
+
+       if (!localdir)
+               localized_use_conf_dir();
        localized_pbx_load_module();
        
        printf("... Done!\n");
@@ -383,11 +386,6 @@ int main(int argc, char **argv)
                printf("Context: %s\n", tmp->name);
        }
        printf("=========\n");
-       printf("Sizeof(context)=%d\n", sizeof(struct ast_context));
-       printf("Sizeof(exten)=%d\n", sizeof(struct ast_exten));
-       printf("Sizeof(include)=%d\n", sizeof(struct ast_include));
-       printf("Sizeof(ignorepat)=%d\n", sizeof(struct ast_ignorepat));
-       printf("Sizeof(sw)=%d\n", sizeof(struct ast_sw));
        tmp = 0;
        while ((tmp = localized_walk_contexts(tmp)) ) {
                /* printf("Context: %s\n", tmp->name); */
@@ -507,28 +505,43 @@ int main(int argc, char **argv)
                        pval *exten = pvalCreateNode(PV_EXTENSION);
                        pvalContextAddStatement(tmptree, exten);
                        pvalExtenSetName(exten, ast_strdup(eroot->exten));
-                       
+               
                        if (eroot->peer) {
                                pval *block = pvalCreateNode(PV_STATEMENTBLOCK);
                                pvalExtenSetStatement(exten, block);
                                
                                e = 0;
                                while ( (e = localized_walk_extension_priorities(eroot, e)) ) {
-                                       /* printf("           %s(%s)\n", e->app, (char*)e->data); */
                                        
                                        pval *statemnt = pvalCreateNode(PV_APPLICATION_CALL);
                                        pval *args = pvalCreateNode(PV_WORD);
                                        
+                                       /* printf("           %s(%s)\n", e->app, (char*)e->data); */
+
                                        pvalAppCallSetAppName(statemnt, ast_strdup(e->app));
                                        pvalWordSetString(args, ast_strdup(e->data));
                                        pvalAppCallAddArg(statemnt, args);
                                        
                                        pvalStatementBlockAddStatement(block, statemnt);
                                }
-                       } else {
+                       } else if (eroot->priority == -1) {
+
                                pval *statemnt = pvalCreateNode(PV_APPLICATION_CALL);
                                pval *args = pvalCreateNode(PV_WORD);
 
+                               /* printf("Mike, we have a hint on exten %s with data %s\n", eroot->exten, eroot->app); */
+
+                               pvalAppCallSetAppName(statemnt, "NoOp");
+                               pvalWordSetString(args, ast_strdup(eroot->app));
+
+
+                               pvalExtenSetStatement(exten, statemnt);
+                               pvalExtenSetHints(exten, ast_strdup(eroot->app));
+                       } else {
+
+                               pval *statemnt = pvalCreateNode(PV_APPLICATION_CALL);
+                               pval *args = pvalCreateNode(PV_WORD);
+       
                                /* printf("           %s (%s)\n", eroot->app, (char *)eroot->data); */
                                
                                pvalAppCallSetAppName(statemnt, ast_strdup(eroot->app));