Wed Jan 8 2020 09:49:48

Asterisk developer's documentation


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 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 328209 $")
35 
36 #include <dirent.h>
37 
38 #include "asterisk/file.h"
39 #include "asterisk/channel.h"
40 #include "asterisk/pbx.h"
41 #include "asterisk/module.h"
42 #include "asterisk/lock.h"
43 #include "asterisk/utils.h"
44 #include "asterisk/app.h"
45 
46 /*** DOCUMENTATION
47  <function name="VMCOUNT" language="en_US">
48  <synopsis>
49  Count the voicemails in a specified mailbox.
50  </synopsis>
51  <syntax>
52  <parameter name="vmbox" required="true" argsep="@">
53  <argument name="vmbox" required="true" />
54  <argument name="context" required="false">
55  <para>If not specified, defaults to <literal>default</literal>.</para>
56  </argument>
57  </parameter>
58  <parameter name="folder" required="false">
59  <para>If not specified, defaults to <literal>INBOX</literal></para>
60  </parameter>
61  </syntax>
62  <description>
63  <para>Count the number of voicemails in a specified mailbox, you could also specify
64  the <replaceable>context</replaceable> and the mailbox <replaceable>folder</replaceable>.</para>
65  <para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125)})</literal></para>
66  </description>
67  </function>
68  ***/
69 
70 static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
71 {
72  char *context;
74  AST_APP_ARG(vmbox);
75  AST_APP_ARG(folder);
76  );
77 
78  buf[0] = '\0';
79 
80  if (ast_strlen_zero(argsstr))
81  return -1;
82 
83  AST_STANDARD_APP_ARGS(args, argsstr);
84 
85  if (strchr(args.vmbox, '@')) {
86  context = args.vmbox;
87  args.vmbox = strsep(&context, "@");
88  } else {
89  context = "default";
90  }
91 
92  if (ast_strlen_zero(args.folder)) {
93  args.folder = "INBOX";
94  }
95 
96  snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
97 
98  return 0;
99 }
100 
102  .name = "VMCOUNT",
103  .read = acf_vmcount_exec,
104  .read_max = 12,
105 };
106 
107 static int unload_module(void)
108 {
109  return ast_custom_function_unregister(&acf_vmcount);
110 }
111 
112 static int load_module(void)
113 {
114  return ast_custom_function_register(&acf_vmcount);
115 }
116 
117 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");
Main Channel structure associated with a channel.
Definition: channel.h:742
#define AST_MODULE_INFO_STANDARD(keystr, desc)
Definition: module.h:396
Asterisk locking-related definitions:
Asterisk main include file. File version handling, generic pbx functions.
char * strsep(char **str, const char *delims)
static int load_module(void)
Definition: func_vmcount.c:112
#define AST_DECLARE_APP_ARGS(name, arglist)
Declare a structure to hold an application&#39;s arguments.
Definition: app.h:572
Generic File Format Support. Should be included by clients of the file handling routines. File service providers should instead include mod_format.h.
int ast_custom_function_unregister(struct ast_custom_function *acf)
Unregister a custom function.
Definition: pbx.c:3814
Utility functions.
static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
Definition: func_vmcount.c:70
General Asterisk PBX channel definitions.
static force_inline int attribute_pure ast_strlen_zero(const char *s)
Definition: strings.h:63
Data structure associated with a custom dialplan function.
Definition: pbx.h:95
Core PBX routines and definitions.
static struct @350 args
static int len(struct ast_channel *chan, const char *cmd, char *data, char *buf, size_t buflen)
static int unload_module(void)
Definition: func_vmcount.c:107
Application convenience functions, designed to give consistent look and feel to Asterisk apps...
const char * name
Definition: pbx.h:96
#define AST_APP_ARG(name)
Define an application argument.
Definition: app.h:555
#define AST_STANDARD_APP_ARGS(args, parse)
Performs the &#39;standard&#39; argument separation process for an application.
Definition: app.h:604
static char context[AST_MAX_CONTEXT]
Definition: chan_alsa.c:107
int ast_app_messagecount(const char *context, const char *mailbox, const char *folder)
Check number of messages in a given context, mailbox, and folder.
Definition: app.c:486
#define ASTERISK_GPL_KEY
The text the key() function should return.
Definition: module.h:38
Asterisk module definitions.
#define ast_custom_function_register(acf)
Register a custom function.
Definition: pbx.h:1164
static struct ast_custom_function acf_vmcount
Definition: func_vmcount.c:101
#define ASTERISK_FILE_VERSION(file, version)
Register/unregister a source code file with the core.
Definition: asterisk.h:180