func_vmcount.c

Go to the documentation of this file.
00001 /*
00002  * Asterisk -- An open source telephony toolkit.
00003  *
00004  * Copyright (c) 2006 Tilghman Lesher.  All rights reserved.
00005  * 
00006  * Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
00007  *
00008  * See http://www.asterisk.org for more information about
00009  * the Asterisk project. Please do not directly contact
00010  * any of the maintainers of this project for assistance;
00011  * the project provides a web site, mailing lists and IRC
00012  * channels for your use.
00013  *
00014  * This program is free software, distributed under the terms of
00015  * the GNU General Public License Version 2. See the LICENSE file
00016  * at the top of the source tree.
00017  */
00018 
00019 /*! \file
00020  *
00021  * \brief VMCOUNT dialplan function
00022  *
00023  * \author Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
00024  *
00025  * \ingroup functions
00026  */
00027 
00028 /*** MODULEINFO
00029    <support_level>core</support_level>
00030  ***/
00031 
00032 #include "asterisk.h"
00033 
00034 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 404350 $")
00035 
00036 #include <dirent.h>
00037 
00038 #include "asterisk/file.h"
00039 #include "asterisk/channel.h"
00040 #include "asterisk/pbx.h"
00041 #include "asterisk/module.h"
00042 #include "asterisk/lock.h"
00043 #include "asterisk/utils.h"
00044 #include "asterisk/app.h"
00045 
00046 /*** DOCUMENTATION
00047    <function name="VMCOUNT" language="en_US">
00048       <synopsis>
00049          Count the voicemails in a specified mailbox.
00050       </synopsis>
00051       <syntax>
00052          <parameter name="vmbox" required="true" />
00053          <parameter name="folder" required="false">
00054             <para>If not specified, defaults to <literal>INBOX</literal></para>
00055          </parameter>
00056       </syntax>
00057       <description>
00058          <para>Count the number of voicemails in a specified mailbox, you could also specify 
00059          the mailbox <replaceable>folder</replaceable>.</para>
00060          <para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125@default)})</literal></para>
00061       </description>
00062    </function>
00063  ***/
00064 
00065 static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
00066 {
00067    AST_DECLARE_APP_ARGS(args,
00068       AST_APP_ARG(vmbox);
00069       AST_APP_ARG(folder);
00070    );
00071 
00072    buf[0] = '\0';
00073 
00074    if (ast_strlen_zero(argsstr))
00075       return -1;
00076 
00077    AST_STANDARD_APP_ARGS(args, argsstr);
00078 
00079    if (ast_strlen_zero(args.vmbox)) {
00080       return -1;
00081    }
00082 
00083    if (ast_strlen_zero(args.folder)) {
00084       args.folder = "INBOX";
00085    }
00086 
00087    snprintf(buf, len, "%d", ast_app_messagecount(args.vmbox, args.folder));
00088    
00089    return 0;
00090 }
00091 
00092 static struct ast_custom_function acf_vmcount = {
00093    .name = "VMCOUNT",
00094    .read = acf_vmcount_exec,
00095    .read_max = 12,
00096 };
00097 
00098 static int unload_module(void)
00099 {
00100    return ast_custom_function_unregister(&acf_vmcount);
00101 }
00102 
00103 static int load_module(void)
00104 {
00105    return ast_custom_function_register(&acf_vmcount);
00106 }
00107 
00108 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");

Generated on Thu Apr 16 06:27:36 2015 for Asterisk - The Open Source Telephony Project by  doxygen 1.5.6