Index: apps/app_directory.c =================================================================== RCS file: /usr/cvsroot/asterisk/apps/app_directory.c,v retrieving revision 1.32 diff -u -r1.32 app_directory.c --- apps/app_directory.c 25 Jan 2005 06:10:19 -0000 1.32 +++ apps/app_directory.c 21 Feb 2005 16:09:43 -0000 @@ -213,6 +213,79 @@ return(res); } +static struct ast_config *get_directory_realtime(char *context) +{ + struct ast_config *cfg = NULL; + struct ast_variable *rtvar = NULL; + struct ast_category *cat = NULL; + char fullname[50] = ""; + char mailbox[50] = ""; + char tmp[100] = ""; + int havename = 0; + int havemailbox = 0; + int needappend = 0; + + /* Load flat file config. */ + cfg = ast_config_load(DIRECTORY_CONFIG); + + if(!cfg) { + /* Loading config failed. Even if config file doesn't exist, we should still have an ast_config. */ + ast_log(LOG_WARNING, "Loading/Creating config failed.\n"); + ast_config_destroy(cfg); + return NULL; + } + + /* Load RealTime voicemail users for this context. */ + rtvar = ast_load_realtime("voicemail", "context", context, NULL); + + /* If we got nothing from RealTime, we can just return the Flatfile. */ + if(!rtvar) + return cfg; + + /* Does the context exist within the Flatfile? */ + if(ast_category_exist(cfg, context)) { + /* If so, hold onto it. We won't need to append it back later. */ + cat = ast_category_get(cfg, context); + needappend = 0; + } else { + /* If not, make a fresh one. It will need appending to the master config. */ + cat = ast_category_new(context); + if(!cat) { + ast_log(LOG_WARNING, "Ran out of memory while creating new ast_category!\n"); + ast_config_destroy(cfg); + return NULL; + } + needappend = 1; + } + + /* We now have a category: from the Flatfile or freshly created. */ + while(rtvar) { + if(!strcasecmp(rtvar->name, "fullname")) { + strncpy(fullname, rtvar->value, sizeof(fullname)-1); + havename = 1; + } else if(!strcasecmp(rtvar->name, "mailbox")) { + strncpy(mailbox, rtvar->value, sizeof(mailbox)-1); + havemailbox = 1; + } + + /* app_directory needs only mailbox and fullname. Fill password and email with dummy values. */ + if(havemailbox && havename) { + sprintf(tmp, "9999,%s,email@email.com", fullname); + ast_variable_append(cat, ast_variable_new(mailbox, tmp)); + havemailbox = 0; + havename = 0; + } + + rtvar = rtvar->next; + } + + /* If we created a brand new category, we must append it. */ + if(needappend) + ast_category_append(cfg, cat); + + return cfg; +} + 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 */ @@ -264,7 +337,7 @@ 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(get_directory_realtime(context), context); while(v && !res) { /* Find all candidate extensions */ while(v) {