--- asterisk-1.8.7.0/apps/app_voicemail.c 2011-09-06 14:48:03.000000000 +0100 +++ asterisk-1.8.7.0.vmi/apps/app_voicemail.c 2011-10-13 18:45:57.631000000 +0100 @@ -356,6 +356,40 @@ context. + + + Returns the selected attribute from a mailbox + + + + + + + + + + + + + + + + + + + Returns the selected attribute from the specified mailbox. + If context is not specified, defaults to the default + context. + + List All Voicemail User Information. @@ -11013,11 +11047,67 @@ return 0; } +static int acf_vm_info(struct ast_channel *chan, const char *cmd, char *args, char *buf, size_t len) +{ + struct ast_vm_user *vmu = NULL; + char *tmp, *mbox, *context; + + AST_DECLARE_APP_ARGS(arg, + AST_APP_ARG(mailbox_context); + AST_APP_ARG(attribute); + ); + + buf[0] = '\0'; + + AST_STANDARD_APP_ARGS(arg, args); + + if (ast_strlen_zero(arg.mailbox_context) || ast_strlen_zero(arg.attribute)) { + ast_log(LOG_ERROR, "VM_INFO requires an argument ([@],attribute)\n"); + return -1; + } + + tmp = ast_strdupa(arg.mailbox_context); + mbox = strsep(&tmp, "@"); + context = strsep(&tmp, ""); + + if (ast_strlen_zero(context)) { + context = "default"; + } + + vmu = find_user(NULL, context, mbox); + + if (vmu) { + if (!strncasecmp(arg.attribute, "password", 8)) { + ast_copy_string(buf, vmu->password, len); + } + else if (!strncasecmp(arg.attribute, "fullname",8)){ + ast_copy_string(buf, vmu->fullname, len); + } + else if (!strncasecmp(arg.attribute, "email",5)){ + ast_copy_string(buf, vmu->email, len); + } + else if (!strncasecmp(arg.attribute, "pager",5)){ + ast_copy_string(buf, vmu->pager, len); + } + else { + ast_log(LOG_ERROR, "Unknown attribute for VM_INFO"); + return -1; + } + } + + return 0; +} + static struct ast_custom_function mailbox_exists_acf = { .name = "MAILBOX_EXISTS", .read = acf_mailbox_exists, }; +static struct ast_custom_function vm_info_acf = { + .name = "VM_INFO", + .read = acf_vm_info, +}; + static int vmauthenticate(struct ast_channel *chan, const char *data) { char *s, *user = NULL, *context = NULL, mailbox[AST_MAX_EXTENSION] = ""; @@ -12925,6 +13015,7 @@ res |= ast_unregister_application(app4); res |= ast_unregister_application(sayname_app); res |= ast_custom_function_unregister(&mailbox_exists_acf); + res |= ast_custom_function_unregister(&vm_info_acf); res |= ast_manager_unregister("VoicemailUsersList"); res |= ast_data_unregister(NULL); #ifdef TEST_FRAMEWORK @@ -12975,6 +13066,7 @@ res |= ast_register_application_xml(app4, vmauthenticate); res |= ast_register_application_xml(sayname_app, vmsayname_exec); res |= ast_custom_function_register(&mailbox_exists_acf); + res |= ast_custom_function_register(&vm_info_acf); res |= ast_manager_register_xml("VoicemailUsersList", EVENT_FLAG_CALL | EVENT_FLAG_REPORTING, manager_list_voicemail_users); #ifdef TEST_FRAMEWORK res |= AST_TEST_REGISTER(test_voicemail_vmsayname);