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 19 Feb 2005 00:06:59 -0000 @@ -213,6 +213,76 @@ return(res); } +static struct ast_config *get_directory_realtime(char *context) +{ + struct ast_config *cfg = NULL, *ffcfg = NULL; + struct ast_variable *rtvar = NULL; + struct ast_category *rtcat = NULL, *ffcat = NULL; + char fullname[50] = ""; + char mailbox[50] = ""; + char tmp[100] = ""; + int havename = 0; + int havemailbox = 0; + + /* Load flat file config. */ + ffcfg = ast_config_load(DIRECTORY_CONFIG); + + /* 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 ffcfg; + + /* Do our OOM checks before anything else. */ + rtcat = ast_category_new(context); + if(!rtcat) { + ast_log(LOG_WARNING, "Ran out of memory while creating new ast_category!\n"); + return NULL; + } + + cfg = ast_config_new(); + if(!cfg) { + ast_log(LOG_WARNING, "Ran out of memory while creating new ast_config!\n"); + return NULL; + } + + /* We now have a blank category. Lets fill it with the results from RealTime. */ + 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; + } + + if(havemailbox && havename) { + sprintf(tmp, "9999,%s,email@email.com", fullname); + ast_variable_append(rtcat, ast_variable_new(mailbox, tmp)); + havemailbox = 0; + havename = 0; + } + + rtvar = rtvar->next; + } + + /* We now have an ast_category containing the information from RealTime. + Does this context/category also exist within the Flatfile? */ + if(ast_category_exist(ffcfg, context)) { + /* If so, get the category (which is the context we are interested in) from the Flatfile. */ + ffcat = ast_category_get(ffcfg, context); + + /* Merge the RealTime category with the Flatfile category. */ + inherit_category(rtcat, ffcat); + } + + /* Add the RealTime category (or the RealTime-merged-Flatfile category) to the 'master' ast_config. */ + ast_category_append(cfg, rtcat); + + 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 +334,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) {