mirror of
https://github.com/asterisk/asterisk.git
synced 2025-10-24 21:50:53 +00:00
re-implement realtime support in app_directory
add support for hiding entries from app_directory using new hidefromdir= option (bug #3950) git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@5429 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
@@ -48,7 +48,7 @@ static char *descrip =
|
|||||||
/* For simplicity, I'm keeping the format compatible with the voicemail config,
|
/* For simplicity, I'm keeping the format compatible with the voicemail config,
|
||||||
but i'm open to suggestions for isolating it */
|
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 */
|
/* How many digits to read in */
|
||||||
#define NUMDIGITS 3
|
#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)
|
static struct ast_config *realtime_directory(char *context)
|
||||||
{
|
{
|
||||||
struct ast_config *cfg = NULL;
|
struct ast_config *cfg;
|
||||||
struct ast_variable *rtvar = NULL;
|
struct ast_config *rtdata;
|
||||||
struct ast_category *cat = NULL;
|
struct ast_category *cat;
|
||||||
char fullname[50] = "";
|
struct ast_variable *var;
|
||||||
char mailbox[50] = "";
|
char *mailbox;
|
||||||
char tmp[100] = "";
|
char *fullname;
|
||||||
int havename = 0;
|
char *hidefromdir;
|
||||||
int havemailbox = 0;
|
char tmp[100];
|
||||||
|
|
||||||
/* Load flat file config. */
|
/* Load flat file config. */
|
||||||
cfg = ast_config_load(DIRECTORY_CONFIG);
|
cfg = ast_config_load(VOICEMAIL_CONFIG);
|
||||||
|
|
||||||
if (!cfg) {
|
if (!cfg) {
|
||||||
/* Loading config failed. Even if config file doesn't exist, we should still have an ast_config. */
|
/* Loading config failed. */
|
||||||
ast_log(LOG_WARNING, "Loading/Creating config failed.\n");
|
ast_log(LOG_WARNING, "Loading config failed.\n");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Load RealTime voicemail users for this context. */
|
/* Get realtime entries, categorized by their mailbox number
|
||||||
rtvar = ast_load_realtime("voicemail", "context", context, NULL);
|
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 there are no results, just return the entries from the config file */
|
||||||
if (!rtvar)
|
if (!rtdata)
|
||||||
return cfg;
|
return cfg;
|
||||||
|
|
||||||
/* Does the context exist within the Flatfile? */
|
/* Does the context exist within the config file? If not, make one */
|
||||||
if (ast_category_exist(cfg, context)) {
|
cat = ast_category_get(cfg, context);
|
||||||
/* If so, get a pointer to it so we can append RealTime variables to it. */
|
if (!cat) {
|
||||||
cat = ast_category_get(cfg, context);
|
|
||||||
} else {
|
|
||||||
/* If not, make a fresh one and append it to the master config. */
|
|
||||||
cat = ast_category_new(context);
|
cat = ast_category_new(context);
|
||||||
if (!cat) {
|
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);
|
ast_config_destroy(cfg);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
ast_category_append(cfg, cat);
|
ast_category_append(cfg, cat);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* We now have a category: from the Flatfile or freshly created. */
|
mailbox = ast_category_browse(rtdata, NULL);
|
||||||
while (rtvar) {
|
while (mailbox) {
|
||||||
if (!strcasecmp(rtvar->name, "fullname")) {
|
fullname = ast_variable_retrieve(rtdata, mailbox, "fullname");
|
||||||
strncpy(fullname, rtvar->value, sizeof(fullname)-1);
|
hidefromdir = ast_variable_retrieve(rtdata, mailbox, "hidefromdir");
|
||||||
havename = 1;
|
snprintf(tmp, sizeof(tmp), "no-password,%s,hidefromdir=%s",
|
||||||
} else if (!strcasecmp(rtvar->name, "mailbox")) {
|
fullname ? fullname : "",
|
||||||
strncpy(mailbox, rtvar->value, sizeof(mailbox)-1);
|
hidefromdir ? hidefromdir : "no");
|
||||||
havemailbox = 1;
|
var = ast_variable_new(mailbox, tmp);
|
||||||
}
|
if (var)
|
||||||
|
ast_variable_append(cat, var);
|
||||||
/* app_directory needs only mailbox and fullname. Fill password and email with dummy values. */
|
else
|
||||||
if (havemailbox && havename) {
|
ast_log(LOG_WARNING, "Out of memory adding mailbox '%s'\n", mailbox);
|
||||||
sprintf(tmp, "9999,%s,email@email.com", fullname);
|
mailbox = ast_category_browse(rtdata, mailbox);
|
||||||
ast_variable_append(cat, ast_variable_new(mailbox, tmp));
|
|
||||||
havemailbox = 0;
|
|
||||||
havename = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
rtvar = rtvar->next;
|
|
||||||
}
|
}
|
||||||
|
ast_config_destroy(rtdata);
|
||||||
|
|
||||||
return cfg;
|
return cfg;
|
||||||
}
|
}
|
||||||
@@ -336,7 +329,7 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
|
|||||||
while(v) {
|
while(v) {
|
||||||
/* Find a candidate extension */
|
/* Find a candidate extension */
|
||||||
start = strdup(v->value);
|
start = strdup(v->value);
|
||||||
if (start) {
|
if (start && !strcasestr(start, "hidefromdir=yes")) {
|
||||||
stringp=start;
|
stringp=start;
|
||||||
strsep(&stringp, ",");
|
strsep(&stringp, ",");
|
||||||
pos = strsep(&stringp, ",");
|
pos = strsep(&stringp, ",");
|
||||||
@@ -435,10 +428,8 @@ top:
|
|||||||
dialcontext = context;
|
dialcontext = context;
|
||||||
|
|
||||||
cfg = realtime_directory(context);
|
cfg = realtime_directory(context);
|
||||||
if (!cfg) {
|
if (!cfg)
|
||||||
ast_log(LOG_WARNING, "Unable to open/create directory configuration %s\n", DIRECTORY_CONFIG);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
|
|
||||||
LOCAL_USER_ADD(u);
|
LOCAL_USER_ADD(u);
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
; determined by the password being the same as
|
||||||
; the mailbox number. The default is "no".
|
; the mailbox number. The default is "no".
|
||||||
; forcegreetings=no ; This is the same as forcename, except for recording
|
; 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]
|
[zonemessages]
|
||||||
eastern=America/New_York|'vm-received' Q 'digits/at' IMp
|
eastern=America/New_York|'vm-received' Q 'digits/at' IMp
|
||||||
|
|||||||
Reference in New Issue
Block a user