Asterisk - The Open Source Telephony Project GIT-master-7e7a603
func_vmcount.c
Go to the documentation of this file.
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/*** MODULEINFO
29 <support_level>core</support_level>
30 ***/
31
32#include "asterisk.h"
33
34#include <dirent.h>
35
36#include "asterisk/file.h"
37#include "asterisk/channel.h"
38#include "asterisk/pbx.h"
39#include "asterisk/module.h"
40#include "asterisk/lock.h"
41#include "asterisk/utils.h"
42#include "asterisk/app.h"
43
44/*** DOCUMENTATION
45 <function name="VMCOUNT" language="en_US">
46 <synopsis>
47 Count the voicemails in a specified mailbox or mailboxes.
48 </synopsis>
49 <syntax>
50 <parameter name="vmbox" required="true" argsep="&amp;">
51 <para>A mailbox or list of mailboxes</para>
52 </parameter>
53 <parameter name="folder" required="false">
54 <para>If not specified, defaults to <literal>INBOX</literal></para>
55 </parameter>
56 </syntax>
57 <description>
58 <para>Count the number of voicemails in a specified mailbox, you could also specify
59 the mailbox <replaceable>folder</replaceable>.</para>
60 <example title="Mailbox folder count">
61 exten => s,1,Set(foo=${VMCOUNT(125@default)})
62 </example>
63 <para>An ampersand-separated list of mailboxes may be specified to count voicemails in
64 multiple mailboxes. If a folder is specified, this will apply to all mailboxes specified.</para>
65 <example title="Multiple mailbox inbox count">
66 same => n,NoOp(${VMCOUNT(1234@default&amp;1235@default&amp;1236@default,INBOX)})
67 </example>
68 </description>
69 </function>
70 ***/
71
72static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
73{
74 int total = 0;
75 char *mailbox = NULL;
77 AST_APP_ARG(vmbox);
78 AST_APP_ARG(folder);
79 );
80
81 buf[0] = '\0';
82
83 if (ast_strlen_zero(argsstr))
84 return -1;
85
87
88 if (ast_strlen_zero(args.vmbox)) {
89 return -1;
90 }
91
92 if (ast_strlen_zero(args.folder)) {
93 args.folder = "INBOX";
94 }
95
96 while ((mailbox = strsep(&args.vmbox, "&"))) {
97 int c;
99 continue;
100 }
102 total += (c > 0 ? c : 0);
103 }
104 snprintf(buf, len, "%d", total);
105
106 return 0;
107}
108
110 .name = "VMCOUNT",
111 .read = acf_vmcount_exec,
112 .read_max = 12,
113};
114
115static int unload_module(void)
116{
118}
119
120static int load_module(void)
121{
123}
124
125AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");
Asterisk main include file. File version handling, generic pbx functions.
General Asterisk PBX channel definitions.
char buf[BUFSIZE]
Definition: eagi_proxy.c:66
Generic File Format Support. Should be included by clients of the file handling routines....
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
Definition: func_vmcount.c:72
static int load_module(void)
Definition: func_vmcount.c:120
static struct ast_custom_function acf_vmcount
Definition: func_vmcount.c:109
static int unload_module(void)
Definition: func_vmcount.c:115
Application convenience functions, designed to give consistent look and feel to Asterisk apps.
#define AST_APP_ARG(name)
Define an application argument.
int ast_app_messagecount(const char *mailbox_id, const char *folder)
Get the number of messages in a given mailbox folder.
Definition: main/app.c:645
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application's arguments.
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the 'standard' argument separation process for an application.
char * strsep(char **str, const char *delims)
Asterisk locking-related definitions:
Asterisk module definitions.
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:567
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:46
Core PBX routines and definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1558
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
static int total
Definition: res_adsi.c:970
#define NULL
Definition: resample.c:96
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:65
Main Channel structure associated with a channel.
Data structure associated with a custom dialplan function.
Definition: pbx.h:118
const char * name
Definition: pbx.h:119
const char * args
static struct test_val c
Utility functions.