00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "asterisk.h"
00036
00037 ASTERISK_FILE_VERSION(__FILE__, "$Revision: 85850 $")
00038
00039 #include <stdlib.h>
00040 #include <stdio.h>
00041 #include <string.h>
00042 #include <unistd.h>
00043 #include <dirent.h>
00044 #include <sys/types.h>
00045
00046 #include "asterisk/file.h"
00047 #include "asterisk/logger.h"
00048 #include "asterisk/channel.h"
00049 #include "asterisk/pbx.h"
00050 #include "asterisk/module.h"
00051 #include "asterisk/lock.h"
00052 #include "asterisk/utils.h"
00053 #include "asterisk/app.h"
00054 #include "asterisk/options.h"
00055
00056 static char *app_hasvoicemail = "HasVoicemail";
00057 static char *hasvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set";
00058 static char *hasvoicemail_descrip =
00059 "HasVoicemail(vmbox[/folder][@context][|varname[|options]])\n"
00060 " Optionally sets <varname> to the number of messages in that folder."
00061 " Assumes folder of INBOX if not specified.\n"
00062 " The option string may contain zero or the following character:\n"
00063 " 'j' -- jump to priority n+101, if there is voicemail in the folder indicated.\n"
00064 " This application sets the following channel variable upon completion:\n"
00065 " HASVMSTATUS The result of the voicemail check returned as a text string as follows\n"
00066 " <# of messages in the folder, 0 for NONE>\n"
00067 "\nThis application has been deprecated in favor of the VMCOUNT() function\n";
00068
00069 static char *app_hasnewvoicemail = "HasNewVoicemail";
00070 static char *hasnewvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set";
00071 static char *hasnewvoicemail_descrip =
00072 "HasNewVoicemail(vmbox[/folder][@context][|varname[|options]])\n"
00073 "Assumes folder 'INBOX' if folder is not specified. Optionally sets <varname> to the number of messages\n"
00074 "in that folder.\n"
00075 " The option string may contain zero of the following character:\n"
00076 " 'j' -- jump to priority n+101, if there is new voicemail in folder 'folder' or INBOX\n"
00077 " This application sets the following channel variable upon completion:\n"
00078 " HASVMSTATUS The result of the new voicemail check returned as a text string as follows\n"
00079 " <# of messages in the folder, 0 for NONE>\n"
00080 "\nThis application has been deprecated in favor of the VMCOUNT() function\n";
00081
00082
00083 static int hasvoicemail_exec(struct ast_channel *chan, void *data)
00084 {
00085 struct ast_module_user *u;
00086 char *input, *varname = NULL, *vmbox, *context = "default";
00087 char *vmfolder;
00088 int vmcount = 0;
00089 static int dep_warning = 0;
00090 int priority_jump = 0;
00091 char tmp[12];
00092 AST_DECLARE_APP_ARGS(args,
00093 AST_APP_ARG(vmbox);
00094 AST_APP_ARG(varname);
00095 AST_APP_ARG(options);
00096 );
00097
00098 if (!dep_warning) {
00099 ast_log(LOG_WARNING, "The applications HasVoicemail and HasNewVoicemail have been deprecated. Please use the VMCOUNT() function instead.\n");
00100 dep_warning = 1;
00101 }
00102
00103 if (!data) {
00104 ast_log(LOG_WARNING, "HasVoicemail requires an argument (vm-box[/folder][@context][|varname[|options]])\n");
00105 return -1;
00106 }
00107
00108 u = ast_module_user_add(chan);
00109
00110 input = ast_strdupa(data);
00111
00112 AST_STANDARD_APP_ARGS(args, input);
00113
00114 vmbox = strsep(&args.vmbox, "@");
00115
00116 if (!ast_strlen_zero(args.vmbox))
00117 context = args.vmbox;
00118
00119 vmfolder = strchr(vmbox, '/');
00120 if (vmfolder) {
00121 *vmfolder = '\0';
00122 vmfolder++;
00123 } else {
00124 vmfolder = "INBOX";
00125 }
00126
00127 if (args.options) {
00128 if (strchr(args.options, 'j'))
00129 priority_jump = 1;
00130 }
00131
00132 vmcount = ast_app_messagecount(context, vmbox, vmfolder);
00133
00134 if (varname) {
00135 snprintf(tmp, sizeof(tmp), "%d", vmcount);
00136 pbx_builtin_setvar_helper(chan, varname, tmp);
00137 }
00138
00139 if (vmcount > 0) {
00140
00141 if (priority_jump || ast_opt_priority_jumping) {
00142 if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101))
00143 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);
00144 }
00145 }
00146
00147 snprintf(tmp, sizeof(tmp), "%d", vmcount);
00148 pbx_builtin_setvar_helper(chan, "HASVMSTATUS", tmp);
00149
00150 ast_module_user_remove(u);
00151
00152 return 0;
00153 }
00154
00155 static int acf_vmcount_exec(struct ast_channel *chan, char *cmd, char *argsstr, char *buf, size_t len)
00156 {
00157 struct ast_module_user *u;
00158 char *context;
00159 AST_DECLARE_APP_ARGS(args,
00160 AST_APP_ARG(vmbox);
00161 AST_APP_ARG(folder);
00162 );
00163
00164 if (ast_strlen_zero(argsstr))
00165 return -1;
00166
00167 u = ast_module_user_add(chan);
00168
00169 buf[0] = '\0';
00170
00171 AST_STANDARD_APP_ARGS(args, argsstr);
00172
00173 if (strchr(args.vmbox, '@')) {
00174 context = args.vmbox;
00175 args.vmbox = strsep(&context, "@");
00176 } else {
00177 context = "default";
00178 }
00179
00180 if (ast_strlen_zero(args.folder)) {
00181 args.folder = "INBOX";
00182 }
00183
00184 snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
00185
00186 ast_module_user_remove(u);
00187
00188 return 0;
00189 }
00190
00191 struct ast_custom_function acf_vmcount = {
00192 .name = "VMCOUNT",
00193 .synopsis = "Counts the voicemail in a specified mailbox",
00194 .syntax = "VMCOUNT(vmbox[@context][|folder])",
00195 .desc =
00196 " context - defaults to \"default\"\n"
00197 " folder - defaults to \"INBOX\"\n",
00198 .read = acf_vmcount_exec,
00199 };
00200
00201 static int unload_module(void)
00202 {
00203 int res;
00204
00205 res = ast_custom_function_unregister(&acf_vmcount);
00206 res |= ast_unregister_application(app_hasvoicemail);
00207 res |= ast_unregister_application(app_hasnewvoicemail);
00208
00209 ast_module_user_hangup_all();
00210
00211 return res;
00212 }
00213
00214 static int load_module(void)
00215 {
00216 int res;
00217
00218 res = ast_custom_function_register(&acf_vmcount);
00219 res |= ast_register_application(app_hasvoicemail, hasvoicemail_exec, hasvoicemail_synopsis, hasvoicemail_descrip);
00220 res |= ast_register_application(app_hasnewvoicemail, hasvoicemail_exec, hasnewvoicemail_synopsis, hasnewvoicemail_descrip);
00221
00222 return res;
00223 }
00224
00225 AST_MODULE_INFO_STANDARD(ASTERISK_GPL_KEY, "Indicator for whether a voice mailbox has messages in a given folder.");