install_prereq: Download latest Jansson.
[asterisk/asterisk.git] / funcs / func_vmcount.c
index cde1665..cb75110 100644 (file)
@@ -2,7 +2,7 @@
  * Asterisk -- An open source telephony toolkit.
  *
  * Copyright (c) 2006 Tilghman Lesher.  All rights reserved.
- * 
+ *
  * Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
  *
  * See http://www.asterisk.org for more information about
  * \ingroup functions
  */
 
-#include "asterisk.h"
+/*** MODULEINFO
+       <support_level>core</support_level>
+ ***/
 
-ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
+#include "asterisk.h"
 
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-#include <unistd.h>
 #include <dirent.h>
-#include <sys/types.h>
 
 #include "asterisk/file.h"
 #include "asterisk/channel.h"
@@ -43,11 +40,28 @@ ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
 #include "asterisk/lock.h"
 #include "asterisk/utils.h"
 #include "asterisk/app.h"
-#include "asterisk/options.h"
+
+/*** DOCUMENTATION
+       <function name="VMCOUNT" language="en_US">
+               <synopsis>
+                       Count the voicemails in a specified mailbox.
+               </synopsis>
+               <syntax>
+                       <parameter name="vmbox" required="true" />
+                       <parameter name="folder" required="false">
+                               <para>If not specified, defaults to <literal>INBOX</literal></para>
+                       </parameter>
+               </syntax>
+               <description>
+                       <para>Count the number of voicemails in a specified mailbox, you could also specify
+                       the mailbox <replaceable>folder</replaceable>.</para>
+                       <para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125@default)})</literal></para>
+               </description>
+       </function>
+ ***/
 
 static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
 {
-       char *context;
        AST_DECLARE_APP_ARGS(args,
                AST_APP_ARG(vmbox);
                AST_APP_ARG(folder);
@@ -60,30 +74,23 @@ static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *arg
 
        AST_STANDARD_APP_ARGS(args, argsstr);
 
-       if (strchr(args.vmbox, '@')) {
-               context = args.vmbox;
-               args.vmbox = strsep(&context, "@");
-       } else {
-               context = "default";
+       if (ast_strlen_zero(args.vmbox)) {
+               return -1;
        }
 
        if (ast_strlen_zero(args.folder)) {
                args.folder = "INBOX";
        }
 
-       snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
-       
+       snprintf(buf, len, "%d", ast_app_messagecount(args.vmbox, args.folder));
+
        return 0;
 }
 
-struct ast_custom_function acf_vmcount = {
+static struct ast_custom_function acf_vmcount = {
        .name = "VMCOUNT",
-       .synopsis = "Counts the voicemail in a specified mailbox",
-       .syntax = "VMCOUNT(vmbox[@context][,folder])",
-       .desc =
-       "  context - defaults to \"default\"\n"
-       "  folder  - defaults to \"INBOX\"\n",
        .read = acf_vmcount_exec,
+       .read_max = 12,
 };
 
 static int unload_module(void)