2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (c) 2006 Tilghman Lesher. All rights reserved.
6 * Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
8 * See http://www.asterisk.org for more information about
9 * the Asterisk project. Please do not directly contact
10 * any of the maintainers of this project for assistance;
11 * the project provides a web site, mailing lists and IRC
12 * channels for your use.
14 * This program is free software, distributed under the terms of
15 * the GNU General Public License Version 2. See the LICENSE file
16 * at the top of the source tree.
21 * \brief VMCOUNT dialplan function
23 * \author Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
37 #include <sys/types.h>
39 #include "asterisk/file.h"
40 #include "asterisk/channel.h"
41 #include "asterisk/pbx.h"
42 #include "asterisk/module.h"
43 #include "asterisk/lock.h"
44 #include "asterisk/utils.h"
45 #include "asterisk/app.h"
46 #include "asterisk/options.h"
48 static int acf_vmcount_exec(struct ast_channel *chan, char *cmd, char *argsstr, char *buf, size_t len)
50 struct ast_module_user *u;
52 AST_DECLARE_APP_ARGS(args,
57 u = ast_module_user_add(chan);
61 AST_STANDARD_APP_ARGS(args, argsstr);
63 if (strchr(args.vmbox, '@')) {
65 args.vmbox = strsep(&context, "@");
70 if (ast_strlen_zero(args.folder)) {
71 args.folder = "INBOX";
74 snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
76 ast_module_user_remove(u);
81 struct ast_custom_function acf_vmcount = {
83 .synopsis = "Counts the voicemail in a specified mailbox",
84 .syntax = "VMCOUNT(vmbox[@context][|folder])",
86 " context - defaults to \"default\"\n"
87 " folder - defaults to \"INBOX\"\n",
88 .read = acf_vmcount_exec,
91 static int unload_module(void)
93 int res = ast_custom_function_unregister(&acf_vmcount);
94 ast_module_user_hangup_all();
99 static int load_module(void)
101 return ast_custom_function_register(&acf_vmcount);
104 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");