func_vmcount.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. /*! \file
  19. *
  20. * \brief VMCOUNT dialplan function
  21. *
  22. * \author Tilghman Lesher <asterisk-vmcount-func@the-tilghman.com>
  23. *
  24. * \ingroup functions
  25. */
  26. /*** MODULEINFO
  27. <support_level>core</support_level>
  28. ***/
  29. #include "asterisk.h"
  30. ASTERISK_FILE_VERSION(__FILE__, "$Revision$")
  31. #include <dirent.h>
  32. #include "asterisk/file.h"
  33. #include "asterisk/channel.h"
  34. #include "asterisk/pbx.h"
  35. #include "asterisk/module.h"
  36. #include "asterisk/lock.h"
  37. #include "asterisk/utils.h"
  38. #include "asterisk/app.h"
  39. /*** DOCUMENTATION
  40. <function name="VMCOUNT" language="en_US">
  41. <synopsis>
  42. Count the voicemails in a specified mailbox.
  43. </synopsis>
  44. <syntax>
  45. <parameter name="vmbox" required="true" />
  46. <parameter name="folder" required="false">
  47. <para>If not specified, defaults to <literal>INBOX</literal></para>
  48. </parameter>
  49. </syntax>
  50. <description>
  51. <para>Count the number of voicemails in a specified mailbox, you could also specify
  52. the mailbox <replaceable>folder</replaceable>.</para>
  53. <para>Example: <literal>exten => s,1,Set(foo=${VMCOUNT(125@default)})</literal></para>
  54. </description>
  55. </function>
  56. ***/
  57. static int acf_vmcount_exec(struct ast_channel *chan, const char *cmd, char *argsstr, char *buf, size_t len)
  58. {
  59. AST_DECLARE_APP_ARGS(args,
  60. AST_APP_ARG(vmbox);
  61. AST_APP_ARG(folder);
  62. );
  63. buf[0] = '\0';
  64. if (ast_strlen_zero(argsstr))
  65. return -1;
  66. AST_STANDARD_APP_ARGS(args, argsstr);
  67. if (ast_strlen_zero(args.vmbox)) {
  68. return -1;
  69. }
  70. if (ast_strlen_zero(args.folder)) {
  71. args.folder = "INBOX";
  72. }
  73. snprintf(buf, len, "%d", ast_app_messagecount(args.vmbox, args.folder));
  74. return 0;
  75. }
  76. static struct ast_custom_function acf_vmcount = {
  77. .name = "VMCOUNT",
  78. .read = acf_vmcount_exec,
  79. .read_max = 12,
  80. };
  81. static int unload_module(void)
  82. {
  83. return ast_custom_function_unregister(&acf_vmcount);
  84. }
  85. static int load_module(void)
  86. {
  87. return ast_custom_function_register(&acf_vmcount);
  88. }
  89. AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");