Mon May 14 04:43:48 2007

Asterisk developer's documentation


app_hasnewvoicemail.c File Reference

HasVoicemail application. More...

#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/logger.h"
#include "asterisk/channel.h"
#include "asterisk/pbx.h"
#include "asterisk/module.h"
#include "asterisk/lock.h"
#include "asterisk/utils.h"
#include "asterisk/app.h"
#include "asterisk/options.h"

Include dependency graph for app_hasnewvoicemail.c:

Go to the source code of this file.

Functions

static int acf_vmcount_exec (struct ast_channel *chan, char *cmd, char *argsstr, char *buf, size_t len)
 AST_MODULE_INFO_STANDARD (ASTERISK_GPL_KEY,"Indicator for whether a voice mailbox has messages in a given folder.")
static int hasvoicemail_exec (struct ast_channel *chan, void *data)
static int load_module (void)
static int unload_module (void)

Variables

ast_custom_function acf_vmcount
static char * app_hasnewvoicemail = "HasNewVoicemail"
static char * app_hasvoicemail = "HasVoicemail"
static char * hasnewvoicemail_descrip
static char * hasnewvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set"
static char * hasvoicemail_descrip
static char * hasvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set"


Detailed Description

HasVoicemail application.

Author:
Todd Freeman <freeman@andrews.edu>
Note:
95% based on HasNewVoicemail by Tilghman Lesher <asterisk-hasnewvoicemail-app@the-tilghman.com>

Definition in file app_hasnewvoicemail.c.


Function Documentation

static int acf_vmcount_exec ( struct ast_channel chan,
char *  cmd,
char *  argsstr,
char *  buf,
size_t  len 
) [static]

Definition at line 155 of file app_hasnewvoicemail.c.

References AST_APP_ARG, ast_app_messagecount(), AST_DECLARE_APP_ARGS, ast_module_user_add, ast_module_user_remove, AST_STANDARD_APP_ARGS, ast_strlen_zero(), ast_module_user::chan, context, and strsep().

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    u = ast_module_user_add(chan);
00165 
00166    buf[0] = '\0';
00167 
00168    AST_STANDARD_APP_ARGS(args, argsstr);
00169 
00170    if (strchr(args.vmbox, '@')) {
00171       context = args.vmbox;
00172       args.vmbox = strsep(&context, "@");
00173    } else {
00174       context = "default";
00175    }
00176 
00177    if (ast_strlen_zero(args.folder)) {
00178       args.folder = "INBOX";
00179    }
00180 
00181    snprintf(buf, len, "%d", ast_app_messagecount(context, args.vmbox, args.folder));
00182 
00183    ast_module_user_remove(u);
00184    
00185    return 0;
00186 }

AST_MODULE_INFO_STANDARD ( ASTERISK_GPL_KEY  ,
"Indicator for whether a voice mailbox has messages in a given folder."   
)

static int hasvoicemail_exec ( struct ast_channel chan,
void *  data 
) [static]

Definition at line 83 of file app_hasnewvoicemail.c.

References AST_APP_ARG, ast_app_messagecount(), AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), ast_module_user_add, ast_module_user_remove, ast_opt_priority_jumping, AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), ast_module_user::chan, ast_channel::context, context, input(), LOG_WARNING, pbx_builtin_setvar_helper(), and strsep().

Referenced by load_module().

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    /* Set the count in the channel variable */
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       /* Branch to the next extension */
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 }

static int load_module ( void   )  [static]

Definition at line 211 of file app_hasnewvoicemail.c.

References acf_vmcount, ast_custom_function_register(), ast_register_application(), and hasvoicemail_exec().

static int unload_module ( void   )  [static]

Definition at line 198 of file app_hasnewvoicemail.c.

References acf_vmcount, ast_custom_function_unregister(), ast_module_user_hangup_all, and ast_unregister_application().

00199 {
00200    int res;
00201    
00202    res = ast_custom_function_unregister(&acf_vmcount);
00203    res |= ast_unregister_application(app_hasvoicemail);
00204    res |= ast_unregister_application(app_hasnewvoicemail);
00205    
00206    ast_module_user_hangup_all();
00207 
00208    return res;
00209 }


Variable Documentation

struct ast_custom_function acf_vmcount

Definition at line 188 of file app_hasnewvoicemail.c.

Referenced by load_module(), and unload_module().

char* app_hasnewvoicemail = "HasNewVoicemail" [static]

Definition at line 69 of file app_hasnewvoicemail.c.

char* app_hasvoicemail = "HasVoicemail" [static]

Definition at line 56 of file app_hasnewvoicemail.c.

char* hasnewvoicemail_descrip [static]

Definition at line 71 of file app_hasnewvoicemail.c.

char* hasnewvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set" [static]

Definition at line 70 of file app_hasnewvoicemail.c.

char* hasvoicemail_descrip [static]

Definition at line 58 of file app_hasnewvoicemail.c.

char* hasvoicemail_synopsis = "Conditionally branches to priority + 101 with the right options set" [static]

Definition at line 57 of file app_hasnewvoicemail.c.


Generated on Mon May 14 04:43:49 2007 for Asterisk - the Open Source PBX by  doxygen 1.5.1