[Asterisk-Dev] [patch] - app_directory RealTime support

Matthew Boehm mboehm at cytelcom.com
Fri Nov 5 10:23:16 MST 2004


http://bugs.digium.com/bug_view_page.php?bug_id=0002475

tada! app_directory with RealTime support. I need some testers to test it
with other RealTime drivers.

The patch allows app_directory to use RealTime ability and retrieve
directory information out of the voicemail database AND the voicemail.conf
file. (YES! It works with both! am i a genius or what?)

But wait! There's more!

If you use the option 'hidefromdir=yes' you can keep a person(s) from being
listed by the app! Wow! (Disclaimer: hidefromdir ability only valid with
RealTime)

(Sorry for being so giddy but earlier this morning someone quoted me to
someone else on the -users list and I've felt so great. So awesome to be
quoted by someone to someone else.)

-Matthew
-------------- next part --------------
Index: apps/app_directory.c
===================================================================
RCS file: /usr/cvsroot/asterisk/apps/app_directory.c,v
retrieving revision 1.28
diff -u -r1.28 app_directory.c
--- apps/app_directory.c        2 Oct 2004 00:58:31 -0000       1.28
+++ apps/app_directory.c        5 Nov 2004 17:10:36 -0000
@@ -18,6 +18,7 @@
 #include <asterisk/pbx.h>
 #include <asterisk/module.h>
 #include <asterisk/config.h>
+#include <asterisk/config_pvt.h>
 #include <asterisk/say.h>
 #include <asterisk/utils.h>
 #include <string.h>
@@ -210,6 +211,87 @@
        return(res);
 }
 
+static struct ast_variable *get_directory_realtime(struct ast_variable *static_list, char *context)
+{
+       /* Basically we are going to take the ast_variable list that contains the static members of voicemail.conf
+          and append the list we get out of RealTime to the static list. */
+
+       struct ast_variable *cur, *from_RT, *new = NULL, *tmp_list = NULL, *tack_list = NULL;
+       char *mailbox = NULL, *fullname = NULL, tmp_vm[100], sql[50];
+       int havemailbox = 0, havename = 0;
+
+       /* This is the nastiest hack I've ever done. I've got to fool RealTime into accepting a non-equals query. yuck. */
+       sprintf(sql, "%s' AND options NOT LIKE '%%hidefromdir%%", context);
+
+       /* Load RealTime voicemail members. */
+       from_RT = ast_load_realtime("voicemail", "context", sql, NULL);
+
+       if(!from_RT) {
+               /* Got nothing from RealTime, so we can just return the static list. */
+               if(static_list) {
+                       /* There was stuff in the static list. */
+                       return static_list;
+               } else {
+                       /* The static list was also empty. */
+                       return NULL;
+               }
+       }
+
+       /* What we got back from RealTime was a long ast_variable list of <column_name> => <column_value>
+          The app_directory algorithm for splitting the last name and converting the numbers into a last name is based off
+          the <mailbox> => <password>,<name>,<email>,<pager_email>,<options> format. So, we need to convert our
+          RealTime list into this format. All app_directory needs is mailbox, and name. */
+
+       while(from_RT) {
+               if(!strcmp(from_RT->name,"mailbox")) {
+                       mailbox = from_RT->value;
+                       havemailbox++;
+               } else if(!strcmp(from_RT->name,"fullname")) {
+                       fullname = from_RT->value;
+                       havename++;
+               }
+
+               if(havemailbox && havename) {
+                       /* once I have mailbox, and name I am ready to make the format. */
+                       sprintf(tmp_vm, "password,%s,email,pager,options", fullname);
+                       new = ast_new_variable(mailbox, tmp_vm);
+
+                       if(tmp_list) {
+                               tmp_list->next = new;
+                               tmp_list = tmp_list->next;
+                       } else {
+                               tmp_list = new;
+                               tack_list = tmp_list;
+                       }
+
+                       havemailbox = 0;
+                       havename = 0;
+               }
+               from_RT = from_RT->next;
+       }
+       ast_destroy_realtime(from_RT);
+
+       /* Check the original list and traverse if needed. */
+       if(!static_list) {
+               /* There was no static list, so just return what we got from RealTime. */
+               return tack_list;
+       }
+
+       cur = static_list;
+       while(cur->next) {
+               cur = cur->next;
+       }
+
+       /* cur should now be pointing to the last variable in the static list. We know this,
+          because cur->next is NULL. Now we can set cur->next = tack_list. */
+
+       cur->next = tack_list;
+
+       /* static_list should now contain the original list, plus what we tacked onto the end from RealTime. */
+       return static_list;
+
+}
+
 static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context, char *dialcontext, char digit, int last)
 {
        /* Read in the first three digits..  "digit" is the first digit, already read */
@@ -233,7 +315,8 @@
        if (ast_readstring(chan, ext + 1, NUMDIGITS - 1, 3000, 3000, "#") < 0) res = -1;
        if (!res) {
                /* Search for all names which start with those digits */
-               v = ast_variable_browse(cfg, context);
+               /* v = ast_variable_browse(cfg, context); ** OLD STYLE ** */
+               v = get_directory_realtime(ast_variable_browse(cfg, context), context);
                while(v && !res) {
                        /* Find all candidate extensions */
                        while(v) {


More information about the asterisk-dev mailing list