aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-04-06 18:55:33 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2005-04-06 18:55:33 +0000
commit0d2814ae15531a6de8de485cdf9075f70c7f0de7 (patch)
treebb990d407fd0b72ada8763739ae9e3f47a97282f
parent523527e9f2088169ed973bffc08cdfbf44126cc6 (diff)
re-implement realtime support in app_directory
add support for hiding entries from app_directory using new hidefromdir= option (bug #3950) git-svn-id: http://svn.digium.com/svn/asterisk/trunk@5429 f38db490-d61c-443f-a65b-d21fe96a405b
-rwxr-xr-xapps/app_directory.c83
-rwxr-xr-xconfigs/voicemail.conf.sample4
2 files changed, 40 insertions, 47 deletions
diff --git a/apps/app_directory.c b/apps/app_directory.c
index c169f43da..3e4b7d353 100755
--- a/apps/app_directory.c
+++ b/apps/app_directory.c
@@ -48,7 +48,7 @@ static char *descrip =
/* For simplicity, I'm keeping the format compatible with the voicemail config,
but i'm open to suggestions for isolating it */
-#define DIRECTORY_CONFIG "voicemail.conf"
+#define VOICEMAIL_CONFIG "voicemail.conf"
/* How many digits to read in */
#define NUMDIGITS 3
@@ -215,66 +215,59 @@ static int play_mailbox_owner(struct ast_channel *chan, char *context, char *dia
static struct ast_config *realtime_directory(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;
+ struct ast_config *cfg;
+ struct ast_config *rtdata;
+ struct ast_category *cat;
+ struct ast_variable *var;
+ char *mailbox;
+ char *fullname;
+ char *hidefromdir;
+ char tmp[100];
/* Load flat file config. */
- cfg = ast_config_load(DIRECTORY_CONFIG);
+ cfg = ast_config_load(VOICEMAIL_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");
+ /* Loading config failed. */
+ ast_log(LOG_WARNING, "Loading config failed.\n");
return NULL;
}
- /* Load RealTime voicemail users for this context. */
- rtvar = ast_load_realtime("voicemail", "context", context, NULL);
+ /* Get realtime entries, categorized by their mailbox number
+ and present in the requested context */
+ rtdata = ast_load_realtime_multientry("voicemail", "mailbox LIKE", "%", "context", context, NULL);
- /* If we got nothing from RealTime, we can just return the Flatfile. */
- if (!rtvar)
+ /* if there are no results, just return the entries from the config file */
+ if (!rtdata)
return cfg;
- /* Does the context exist within the Flatfile? */
- if (ast_category_exist(cfg, context)) {
- /* If so, get a pointer to it so we can append RealTime variables to it. */
- cat = ast_category_get(cfg, context);
- } else {
- /* If not, make a fresh one and append it to the master config. */
+ /* Does the context exist within the config file? If not, make one */
+ cat = ast_category_get(cfg, context);
+ if (!cat) {
cat = ast_category_new(context);
if (!cat) {
- ast_log(LOG_WARNING, "Ran out of memory while creating new ast_category!\n");
+ ast_log(LOG_WARNING, "Out of memory\n");
ast_config_destroy(cfg);
return NULL;
}
ast_category_append(cfg, cat);
}
- /* 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;
+ mailbox = ast_category_browse(rtdata, NULL);
+ while (mailbox) {
+ fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
+ hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
+ snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
+ fullname ? fullname : "",
+ hidefromdir ? hidefromdir : "no");
+ var = ast_variable_new(mailbox, tmp);
+ if (var)
+ ast_variable_append(cat, var);
+ else
+ ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
+ mailbox = ast_category_browse(rtdata, mailbox);
}
+ ast_config_destroy(rtdata);
return cfg;
}
@@ -336,7 +329,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
while(v) {
/* Find a candidate extension */
start = strdup(v->value);
- if (start) {
+ if (start && !strcasestr(start, "hidefromdir=yes")) {
stringp=start;
strsep(&stringp, ",");
pos = strsep(&stringp, ",");
@@ -435,10 +428,8 @@ top:
dialcontext = context;
cfg = realtime_directory(context);
- if (!cfg) {
- ast_log(LOG_WARNING, "Unable to open/create directory configuration %s\n", DIRECTORY_CONFIG);
+ if (!cfg)
return -1;
- }
LOCAL_USER_ADD(u);
diff --git a/configs/voicemail.conf.sample b/configs/voicemail.conf.sample
index 52a727811..8cff4a803 100755
--- a/configs/voicemail.conf.sample
+++ b/configs/voicemail.conf.sample
@@ -133,7 +133,9 @@ sendvoicemail=yes ; Context to Send voicemail from [option 5 from the advanced m
; determined by the password being the same as
; the mailbox number. The default is "no".
; forcegreetings=no ; This is the same as forcename, except for recording
- ; greetings. The default is "no".
+ ; greetings. The default is "no".
+; hidefromdir=yes ; Hide this mailbox from the directory produced by app_directory
+ ; The default is "no".
[zonemessages]
eastern=America/New_York|'vm-received' Q 'digits/at' IMp