2 * Asterisk -- An open source telephony toolkit.
4 * Changes Copyright (c) 2004 - 2006 Todd Freeman <freeman@andrews.edu>
6 * 95% based on HasNewVoicemail by:
8 * Copyright (c) 2003 Tilghman Lesher. All rights reserved.
10 * Tilghman Lesher <asterisk-hasnewvoicemail-app@the-tilghman.com>
12 * See http://www.asterisk.org for more information about
13 * the Asterisk project. Please do not directly contact
14 * any of the maintainers of this project for assistance;
15 * the project provides a web site, mailing lists and IRC
16 * channels for your use.
18 * This program is free software, distributed under the terms of
19 * the GNU General Public License Version 2. See the LICENSE file
20 * at the top of the source tree.
25 * \brief HasVoicemail application
27 * \author Todd Freeman <freeman@andrews.edu>
29 * \note 95% based on HasNewVoicemail by
30 * Tilghman Lesher <asterisk-hasnewvoicemail-app@the-tilghman.com>
32 * \ingroup applications
37 ASTERISK_FILE_VERSION(__FILE__
, "$Revision$")
44 #include <sys/types.h>
46 #include "asterisk/file.h"
47 #include "asterisk/logger.h"
48 #include "asterisk/channel.h"
49 #include "asterisk/pbx.h"
50 #include "asterisk/module.h"
51 #include "asterisk/lock.h"
52 #include "asterisk/utils.h"
53 #include "asterisk/app.h"
54 #include "asterisk/options.h"
56 static char *app_hasvoicemail
= "HasVoicemail";
57 static char *hasvoicemail_synopsis
= "Conditionally branches to priority + 101 with the right options set";
58 static char *hasvoicemail_descrip
=
59 "HasVoicemail(vmbox[/folder][@context][|varname[|options]])\n"
60 " Optionally sets <varname> to the number of messages in that folder."
61 " Assumes folder of INBOX if not specified.\n"
62 " The option string may contain zero or the following character:\n"
63 " 'j' -- jump to priority n+101, if there is voicemail in the folder indicated.\n"
64 " This application sets the following channel variable upon completion:\n"
65 " HASVMSTATUS The result of the voicemail check returned as a text string as follows\n"
66 " <# of messages in the folder, 0 for NONE>\n"
67 "\nThis application has been deprecated in favor of the VMCOUNT() function\n";
69 static char *app_hasnewvoicemail
= "HasNewVoicemail";
70 static char *hasnewvoicemail_synopsis
= "Conditionally branches to priority + 101 with the right options set";
71 static char *hasnewvoicemail_descrip
=
72 "HasNewVoicemail(vmbox[/folder][@context][|varname[|options]])\n"
73 "Assumes folder 'INBOX' if folder is not specified. Optionally sets <varname> to the number of messages\n"
75 " The option string may contain zero of the following character:\n"
76 " 'j' -- jump to priority n+101, if there is new voicemail in folder 'folder' or INBOX\n"
77 " This application sets the following channel variable upon completion:\n"
78 " HASVMSTATUS The result of the new voicemail check returned as a text string as follows\n"
79 " <# of messages in the folder, 0 for NONE>\n"
80 "\nThis application has been deprecated in favor of the VMCOUNT() function\n";
83 static int hasvoicemail_exec(struct ast_channel
*chan
, void *data
)
85 struct ast_module_user
*u
;
86 char *input
, *varname
= NULL
, *vmbox
, *context
= "default";
89 static int dep_warning
= 0;
90 int priority_jump
= 0;
92 AST_DECLARE_APP_ARGS(args
,
99 ast_log(LOG_WARNING
, "The applications HasVoicemail and HasNewVoicemail have been deprecated. Please use the VMCOUNT() function instead.\n");
104 ast_log(LOG_WARNING
, "HasVoicemail requires an argument (vm-box[/folder][@context][|varname[|options]])\n");
108 u
= ast_module_user_add(chan
);
110 input
= ast_strdupa(data
);
112 AST_STANDARD_APP_ARGS(args
, input
);
114 vmbox
= strsep(&args
.vmbox
, "@");
116 if (!ast_strlen_zero(args
.vmbox
))
117 context
= args
.vmbox
;
119 vmfolder
= strchr(vmbox
, '/');
128 if (strchr(args
.options
, 'j'))
132 vmcount
= ast_app_messagecount(context
, vmbox
, vmfolder
);
133 /* Set the count in the channel variable */
135 snprintf(tmp
, sizeof(tmp
), "%d", vmcount
);
136 pbx_builtin_setvar_helper(chan
, varname
, tmp
);
140 /* Branch to the next extension */
141 if (priority_jump
|| ast_opt_priority_jumping
) {
142 if (ast_goto_if_exists(chan
, chan
->context
, chan
->exten
, chan
->priority
+ 101))
143 ast_log(LOG_WARNING
, "VM box %s@%s has new voicemail, but extension %s, priority %d doesn't exist\n", vmbox
, context
, chan
->exten
, chan
->priority
+ 101);
147 snprintf(tmp
, sizeof(tmp
), "%d", vmcount
);
148 pbx_builtin_setvar_helper(chan
, "HASVMSTATUS", tmp
);
150 ast_module_user_remove(u
);
155 static int acf_vmcount_exec(struct ast_channel
*chan
, char *cmd
, char *argsstr
, char *buf
, size_t len
)
157 struct ast_module_user
*u
;
159 AST_DECLARE_APP_ARGS(args
,
164 u
= ast_module_user_add(chan
);
168 AST_STANDARD_APP_ARGS(args
, argsstr
);
170 if (strchr(args
.vmbox
, '@')) {
171 context
= args
.vmbox
;
172 args
.vmbox
= strsep(&context
, "@");
177 if (ast_strlen_zero(args
.folder
)) {
178 args
.folder
= "INBOX";
181 snprintf(buf
, len
, "%d", ast_app_messagecount(context
, args
.vmbox
, args
.folder
));
183 ast_module_user_remove(u
);
188 struct ast_custom_function acf_vmcount
= {
190 .synopsis
= "Counts the voicemail in a specified mailbox",
191 .syntax
= "VMCOUNT(vmbox[@context][|folder])",
193 " context - defaults to \"default\"\n"
194 " folder - defaults to \"INBOX\"\n",
195 .read
= acf_vmcount_exec
,
198 static int unload_module(void)
202 res
= ast_custom_function_unregister(&acf_vmcount
);
203 res
|= ast_unregister_application(app_hasvoicemail
);
204 res
|= ast_unregister_application(app_hasnewvoicemail
);
206 ast_module_user_hangup_all();
211 static int load_module(void)
215 res
= ast_custom_function_register(&acf_vmcount
);
216 res
|= ast_register_application(app_hasvoicemail
, hasvoicemail_exec
, hasvoicemail_synopsis
, hasvoicemail_descrip
);
217 res
|= ast_register_application(app_hasnewvoicemail
, hasvoicemail_exec
, hasnewvoicemail_synopsis
, hasnewvoicemail_descrip
);
222 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY
, "Indicator for whether a voice mailbox has messages in a given folder.");