aboutsummaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-16 23:53:58 +0000
committerkpfleming <kpfleming@f38db490-d61c-443f-a65b-d21fe96a405b>2006-09-16 23:53:58 +0000
commit5c0e56df213e669dd543a5996c77383a17a6ecd2 (patch)
tree1298da607ca8facdbaf23866e9294b57e39057d9 /apps
parent5b13041e0f380ccdf5ce117653086312c4a3a7be (diff)
merge markster's usersconf branch with some slight changes
git-svn-id: http://svn.digium.com/svn/asterisk/trunk@43052 f38db490-d61c-443f-a65b-d21fe96a405b
Diffstat (limited to 'apps')
-rw-r--r--apps/app_directory.c64
-rw-r--r--apps/app_voicemail.c92
2 files changed, 125 insertions, 31 deletions
diff --git a/apps/app_directory.c b/apps/app_directory.c
index 6f660e326..ff644566b 100644
--- a/apps/app_directory.c
+++ b/apps/app_directory.c
@@ -393,10 +393,10 @@ static struct ast_config *realtime_directory(char *context)
return cfg;
}
-static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *context, char *dialcontext, char digit, int last, int readext, int fromappvm)
+static int do_directory(struct ast_channel *chan, struct ast_config *cfg, struct ast_config *ucfg, char *context, char *dialcontext, char digit, int last, int readext, int fromappvm)
{
/* Read in the first three digits.. "digit" is the first digit, already read */
- char ext[NUMDIGITS + 1];
+ char ext[NUMDIGITS + 1], *cat;
char name[80] = "";
struct ast_variable *v;
int res;
@@ -499,6 +499,58 @@ static int do_directory(struct ast_channel *chan, struct ast_config *cfg, char *
}
}
+ if (!res && ucfg) {
+ /* Search users.conf for all names which start with those digits */
+ for (cat = ast_category_browse(ucfg, NULL); cat && !res ; cat = ast_category_browse(ucfg, cat)) {
+ if (!strcasecmp(cat, "general"))
+ continue;
+ if (!ast_true(ast_config_option(ucfg, cat, "hasdirectory")))
+ continue;
+
+ /* Find all candidate extensions */
+ if ((pos = ast_variable_retrieve(ucfg, cat, "fullname"))) {
+ ast_copy_string(name, pos, sizeof(name));
+ /* Grab the last name */
+ if (last && strrchr(pos,' '))
+ pos = strrchr(pos, ' ') + 1;
+ conv = convert(pos);
+ if (conv) {
+ if (!strcmp(conv, ext)) {
+ /* Match! */
+ found++;
+ /* We have a match -- play a greeting if they have it */
+ res = play_mailbox_owner(chan, context, dialcontext, cat, name, readext, fromappvm);
+ switch (res) {
+ case -1:
+ /* user pressed '1' but extension does not exist, or
+ * user hungup
+ */
+ lastuserchoice = 0;
+ break;
+ case '1':
+ /* user pressed '1' and extensions exists;
+ play_mailbox_owner will already have done
+ a goto() on the channel
+ */
+ lastuserchoice = res;
+ break;
+ case '*':
+ /* user pressed '*' to skip something found */
+ lastuserchoice = res;
+ res = 0;
+ break;
+ default:
+ break;
+ }
+ free(conv);
+ break;
+ }
+ free(conv);
+ }
+ }
+ }
+ }
+
if (lastuserchoice != '1') {
res = ast_streamfile(chan, found ? "dir-nomore" : "dir-nomatch", chan->language);
if (!res)
@@ -514,7 +566,7 @@ static int directory_exec(struct ast_channel *chan, void *data)
{
int res = 0;
struct ast_module_user *u;
- struct ast_config *cfg;
+ struct ast_config *cfg, *ucfg;
int last = 1;
int readext = 0;
int fromappvm = 0;
@@ -554,6 +606,8 @@ static int directory_exec(struct ast_channel *chan, void *data)
ast_module_user_remove(u);
return -1;
}
+
+ ucfg = ast_config_load("users.conf");
dirintro = ast_variable_retrieve(cfg, args.vmcontext, "directoryintro");
if (ast_strlen_zero(dirintro))
@@ -571,7 +625,7 @@ static int directory_exec(struct ast_channel *chan, void *data)
if (!res)
res = ast_waitfordigit(chan, 5000);
if (res > 0) {
- res = do_directory(chan, cfg, args.vmcontext, args.dialcontext, res, last, readext, fromappvm);
+ res = do_directory(chan, cfg, ucfg, args.vmcontext, args.dialcontext, res, last, readext, fromappvm);
if (res > 0) {
res = ast_waitstream(chan, AST_DIGIT_ANY);
ast_stopstream(chan);
@@ -581,6 +635,8 @@ static int directory_exec(struct ast_channel *chan, void *data)
}
break;
}
+ if (ucfg)
+ ast_config_destroy(ucfg);
ast_config_destroy(cfg);
ast_module_user_remove(u);
return res;
diff --git a/apps/app_voicemail.c b/apps/app_voicemail.c
index f519602c0..70ebc9f1d 100644
--- a/apps/app_voicemail.c
+++ b/apps/app_voicemail.c
@@ -404,6 +404,8 @@ static char ext_pass_cmd[128];
#define tdesc "Comedian Mail (Voicemail System)"
#endif
+static char userscontext[AST_MAX_EXTENSION] = "default";
+
static char *addesc = "Comedian Mail";
static char *synopsis_vm =
@@ -641,9 +643,32 @@ static void apply_options(struct ast_vm_user *vmu, const char *options)
}
}
+static void apply_options_full(struct ast_vm_user *retval, struct ast_variable *var)
+{
+ struct ast_variable *tmp;
+ tmp = var;
+ while (tmp) {
+ if (!strcasecmp(tmp->name, "password")) {
+ ast_copy_string(retval->password, tmp->value, sizeof(retval->password));
+ } else if (!strcasecmp(tmp->name, "uniqueid")) {
+ ast_copy_string(retval->uniqueid, tmp->value, sizeof(retval->uniqueid));
+ } else if (!strcasecmp(tmp->name, "pager")) {
+ ast_copy_string(retval->pager, tmp->value, sizeof(retval->pager));
+ } else if (!strcasecmp(tmp->name, "email")) {
+ ast_copy_string(retval->email, tmp->value, sizeof(retval->email));
+ } else if (!strcasecmp(tmp->name, "fullname")) {
+ ast_copy_string(retval->fullname, tmp->value, sizeof(retval->fullname));
+ } else if (!strcasecmp(tmp->name, "context")) {
+ ast_copy_string(retval->context, tmp->value, sizeof(retval->context));
+ } else
+ apply_option(retval, tmp->name, tmp->value);
+ tmp = tmp->next;
+ }
+}
+
static struct ast_vm_user *find_user_realtime(struct ast_vm_user *ivm, const char *context, const char *mailbox)
{
- struct ast_variable *var, *tmp;
+ struct ast_variable *var;
struct ast_vm_user *retval;
if ((retval = (ivm ? ivm : ast_calloc(1, sizeof(*retval))))) {
@@ -659,25 +684,7 @@ static struct ast_vm_user *find_user_realtime(struct ast_vm_user *ivm, const cha
else
var = ast_load_realtime("voicemail", "mailbox", mailbox, "context", context, NULL);
if (var) {
- tmp = var;
- while (tmp) {
- printf("%s => %s\n", tmp->name, tmp->value);
- if (!strcasecmp(tmp->name, "password")) {
- ast_copy_string(retval->password, tmp->value, sizeof(retval->password));
- } else if (!strcasecmp(tmp->name, "uniqueid")) {
- ast_copy_string(retval->uniqueid, tmp->value, sizeof(retval->uniqueid));
- } else if (!strcasecmp(tmp->name, "pager")) {
- ast_copy_string(retval->pager, tmp->value, sizeof(retval->pager));
- } else if (!strcasecmp(tmp->name, "email")) {
- ast_copy_string(retval->email, tmp->value, sizeof(retval->email));
- } else if (!strcasecmp(tmp->name, "fullname")) {
- ast_copy_string(retval->fullname, tmp->value, sizeof(retval->fullname));
- } else if (!strcasecmp(tmp->name, "context")) {
- ast_copy_string(retval->context, tmp->value, sizeof(retval->context));
- } else
- apply_option(retval, tmp->name, tmp->value);
- tmp = tmp->next;
- }
+ apply_options_full(retval, var);
ast_variables_destroy(var);
} else {
if (!ivm)
@@ -6573,6 +6580,26 @@ static int vm_exec(struct ast_channel *chan, void *data)
return res;
}
+static struct ast_vm_user *find_or_create(char *context, char *mbox)
+{
+ struct ast_vm_user *vmu;
+ AST_LIST_TRAVERSE(&users, vmu, list) {
+ if (ast_test_flag((&globalflags), VM_SEARCH) && !strcasecmp(mbox, vmu->mailbox))
+ break;
+ if (context && (!strcasecmp(context, vmu->context)) && (!strcasecmp(mbox, vmu->mailbox)))
+ break;
+ }
+
+ if (!vmu) {
+ if ((vmu = ast_calloc(1, sizeof(*vmu)))) {
+ ast_copy_string(vmu->context, context, sizeof(vmu->context));
+ ast_copy_string(vmu->mailbox, mbox, sizeof(vmu->mailbox));
+ AST_LIST_INSERT_TAIL(&users, vmu, list);
+ }
+ }
+ return vmu;
+}
+
static int append_mailbox(char *context, char *mbox, char *data)
{
/* Assumes lock is already held */
@@ -6582,10 +6609,7 @@ static int append_mailbox(char *context, char *mbox, char *data)
struct ast_vm_user *vmu;
ast_copy_string(tmp, data, sizeof(tmp));
- if ((vmu = ast_calloc(1, sizeof(*vmu)))) {
- ast_copy_string(vmu->context, context, sizeof(vmu->context));
- ast_copy_string(vmu->mailbox, mbox, sizeof(vmu->mailbox));
-
+ if ((vmu = find_or_create(context, mbox))) {
populate_defaults(vmu);
stringp = tmp;
@@ -6599,8 +6623,6 @@ static int append_mailbox(char *context, char *mbox, char *data)
ast_copy_string(vmu->pager, s, sizeof(vmu->pager));
if (stringp && (s = strsep(&stringp, ",")))
apply_options(vmu, s);
-
- AST_LIST_INSERT_TAIL(&users, vmu, list);
}
return 0;
}
@@ -6813,7 +6835,7 @@ static int load_config(void)
{
struct ast_vm_user *cur;
struct vm_zone *zcur;
- struct ast_config *cfg;
+ struct ast_config *cfg, *ucfg;
char *cat;
struct ast_variable *var;
char *notifystr = NULL;
@@ -6843,6 +6865,7 @@ static int load_config(void)
char *thresholdstr;
char *fmt;
char *astemail;
+ char *ucontext;
char *astmailcmd = SENDMAIL;
char *astforcename;
char *astforcegreet;
@@ -6874,6 +6897,9 @@ static int load_config(void)
if (cfg) {
/* General settings */
+ if (!(ucontext = ast_variable_retrieve(cfg, "general", "userscontext")))
+ ucontext = "default";
+ ast_copy_string(userscontext, ucontext, sizeof(userscontext));
/* Attach voice message to mail message ? */
if (!(astattach = ast_variable_retrieve(cfg, "general", "attach")))
astattach = "yes";
@@ -7159,6 +7185,18 @@ static int load_config(void)
if (!(astdirfwd = ast_variable_retrieve(cfg, "general", "usedirectory")))
astdirfwd = "no";
ast_set2_flag((&globalflags), ast_true(astdirfwd), VM_DIRECFORWARD);
+ if ((ucfg = ast_config_load("users.conf"))) {
+ for (cat = ast_category_browse(ucfg, NULL); cat ; cat = ast_category_browse(ucfg, cat)) {
+ if (!ast_true(ast_config_option(ucfg, cat, "hasvoicemail")))
+ continue;
+ if ((cur = find_or_create(userscontext, cat))) {
+ populate_defaults(cur);
+ apply_options_full(cur, ast_variable_browse(ucfg, cat));
+ ast_copy_string(cur->context, userscontext, sizeof(cur->context));
+ }
+ }
+ ast_config_destroy(ucfg);
+ }
cat = ast_category_browse(cfg, NULL);
while (cat) {
if (strcasecmp(cat, "general")) {