fixes some coding guideline issue
[asterisk/asterisk.git] / funcs / func_vmcount.c
1 /*
2  * Asterisk -- An open source telephony toolkit.
3  *
4  * Copyright (c) 2006 Tilghman Lesher.  All rights reserved.
5  * 
6  * Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
7  *
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.
13  *
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.
17  */
18
19 /*! \file
20  *
21  * \brief VMCOUNT dialplan function
22  *
23  * \author Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
24  *
25  * \ingroup functions
26  */
27
28 #include "asterisk.h"
29
30 ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
31
32 #include <dirent.h>
33
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"
41
42 /*** DOCUMENTATION
43         <function name="VMCOUNT" language="en_US">
44                 <synopsis>
45                         Count the voicemails in a specified mailbox.
46                 </synopsis>
47                 <syntax>
48                         <parameter name="vmbox" required="true" argsep="@">
49                                 <argument name="vmbox" required="true" />
50                                 <argument name="context" required="false">
51                                         <para>If not specified, defaults to <literal>default</literal>.</para>
52                                 </argument>
53                         </parameter>
54                         <parameter name="folder" required="false">
55                                 <para>If not specified, defaults to <literal>INBOX</literal></para>
56                         </parameter>
57                 </syntax>
58                 <description>
59                         <para>Count the number of voicemails in a specified mailbox, you could also specify 
60                         the <replaceable>context</replaceable> and the mailbox <replaceable>folder</replaceable>.</para>
61                         <para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125)})</literal></para>
62                 </description>
63         </function>
64  ***/
65
66 static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
67 {
68         char *context;
69         AST_DECLARE_APP_ARGS(args,
70                 AST_APP_ARG(vmbox);
71                 AST_APP_ARG(folder);
72         );
73
74         buf[0] = '\0';
75
76         if (ast_strlen_zero(argsstr))
77                 return -1;
78
79         AST_STANDARD_APP_ARGS(args, argsstr);
80
81         if (strchr(args.vmbox, '@')) {
82                 context = args.vmbox;
83                 args.vmbox = strsep(&context, "@");
84         } else {
85                 context = "default";
86         }
87
88         if (ast_strlen_zero(args.folder)) {
89                 args.folder = "INBOX";
90         }
91
92         snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
93         
94         return 0;
95 }
96
97 static struct ast_custom_function acf_vmcount = {
98         .name = "VMCOUNT",
99         .read = acf_vmcount_exec,
100         .read_max = 12,
101 };
102
103 static int unload_module(void)
104 {
105         return ast_custom_function_unregister(&acf_vmcount);
106 }
107
108 static int load_module(void)
109 {
110         return ast_custom_function_register(&acf_vmcount);
111 }
112
113 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");