Add missing terminator to ast_event_subscribe to fix a crash.
[asterisk-bristuff.git] / funcs / func_vmcount.c
blob24d83140d42538ba231a74feced5ef43195dd0e6
1 /*
2 * Asterisk -- An open source telephony toolkit.
4 * Copyright (c) 2006 Tilghman Lesher. All rights reserved.
5 *
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.
19 /*! \file
21 * \brief VMCOUNT dialplan function
23 * \author Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
25 * \ingroup functions
28 #include "asterisk.h"
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
32 #include <dirent.h>
34 #include "asterisk/file.h"
35 #include "asterisk/channel.h"
36 #include "asterisk/pbx.h"
37 #include "asterisk/module.h"
38 #include "asterisk/lock.h"
39 #include "asterisk/utils.h"
40 #include "asterisk/app.h"
42 static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
44 char *context;
45 AST_DECLARE_APP_ARGS(args,
46 AST_APP_ARG(vmbox);
47 AST_APP_ARG(folder);
50 buf[0] = '\0';
52 if (ast_strlen_zero(argsstr))
53 return -1;
55 AST_STANDARD_APP_ARGS(args, argsstr);
57 if (strchr(args.vmbox, '@')) {
58 context = args.vmbox;
59 args.vmbox = strsep(&context, "@");
60 } else {
61 context = "default";
64 if (ast_strlen_zero(args.folder)) {
65 args.folder = "INBOX";
68 snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
70 return 0;
73 struct ast_custom_function acf_vmcount = {
74 .name = "VMCOUNT",
75 .synopsis = "Counts the voicemail in a specified mailbox",
76 .syntax = "VMCOUNT(vmbox[@context][,folder])",
77 .desc =
78 " context - defaults to \"default\"\n"
79 " folder - defaults to \"INBOX\"\n",
80 .read = acf_vmcount_exec,
83 static int unload_module(void)
85 return ast_custom_function_unregister(&acf_vmcount);
88 static int load_module(void)
90 return ast_custom_function_register(&acf_vmcount);
93 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");