Fri May 26 01:45:56 2006

Asterisk developer's documentation


app_hasnewvoicemail.c File Reference

HasVoicemail application. More...

#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <dirent.h>
#include <sys/types.h>
#include "asterisk.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 char * acf_vmcount_exec (struct ast_channel *chan, char *cmd, char *data, char *buf, size_t len)
char * description (void)
 Provides a description of the module.
static int hasvoicemail_exec (struct ast_channel *chan, void *data)
static int hasvoicemail_internal (char *context, char *box, char *folder)
char * key ()
 Returns the ASTERISK_GPL_KEY.
int load_module (void)
 Initialize the module.
int unload_module (void)
 Cleanup all module structures, sockets, etc.
int usecount (void)
 Provides a usecount.

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"
 LOCAL_USER_DECL
 STANDARD_LOCAL_USER
static char * tdesc = "Indicator for whether a voice mailbox has messages in a given folder."


Detailed Description

HasVoicemail application.

Definition in file app_hasnewvoicemail.c.


Function Documentation

static char* acf_vmcount_exec struct ast_channel chan,
char *  cmd,
char *  data,
char *  buf,
size_t  len
[static]
 

Definition at line 178 of file app_hasnewvoicemail.c.

References ast_log(), ast_strdupa, context, hasvoicemail_internal(), LOCAL_USER_ACF_ADD, LOCAL_USER_REMOVE, LOG_ERROR, and strsep().

00179 {
00180    struct localuser *u;
00181    char *args, *context, *box, *folder;
00182 
00183    LOCAL_USER_ACF_ADD(u);
00184 
00185    buf[0] = '\0';
00186 
00187    args = ast_strdupa(data);
00188    if (!args) {
00189       ast_log(LOG_ERROR, "Out of memory");
00190       LOCAL_USER_REMOVE(u);
00191       return buf;
00192    }
00193 
00194    box = strsep(&args, "|");
00195    if (strchr(box, '@')) {
00196       context = box;
00197       box = strsep(&context, "@");
00198    } else {
00199       context = "default";
00200    }
00201 
00202    if (args) {
00203       folder = args;
00204    } else {
00205       folder = "INBOX";
00206    }
00207 
00208    snprintf(buf, len, "%d", hasvoicemail_internal(context, box, folder));
00209 
00210    LOCAL_USER_REMOVE(u);
00211    
00212    return buf;
00213 }

char* description void   ) 
 

Provides a description of the module.

Returns:
a short description of your module

Definition at line 249 of file app_hasnewvoicemail.c.

00250 {
00251    return tdesc;
00252 }

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

Definition at line 100 of file app_hasnewvoicemail.c.

References AST_APP_ARG, AST_DECLARE_APP_ARGS, ast_goto_if_exists(), ast_log(), AST_STANDARD_APP_ARGS, ast_strdupa, ast_strlen_zero(), localuser::chan, ast_channel::context, context, dep_warning, hasvoicemail_internal(), input(), LOCAL_USER_ADD, LOCAL_USER_REMOVE, LOG_ERROR, LOG_WARNING, option_priority_jumping, pbx_builtin_setvar_helper(), and strsep().

Referenced by load_module().

00101 {
00102    struct localuser *u;
00103    char *input, *varname = NULL, *vmbox, *context = "default";
00104    char *vmfolder;
00105    int vmcount = 0;
00106    static int dep_warning = 0;
00107    int priority_jump = 0;
00108    char tmp[12];
00109    AST_DECLARE_APP_ARGS(args,
00110       AST_APP_ARG(vmbox);
00111       AST_APP_ARG(varname);
00112       AST_APP_ARG(options);
00113    );
00114 
00115    if (!dep_warning) {
00116       ast_log(LOG_WARNING, "The applications HasVoicemail and HasNewVoicemail have been deprecated.  Please use the VMCOUNT() function instead.\n");
00117       dep_warning = 1;
00118    }
00119    
00120    if (!data) {
00121       ast_log(LOG_WARNING, "HasVoicemail requires an argument (vm-box[/folder][@context][|varname[|options]])\n");
00122       return -1;
00123    }
00124 
00125    LOCAL_USER_ADD(u);
00126 
00127    input = ast_strdupa((char *)data);
00128    if (! input) {
00129       ast_log(LOG_ERROR, "Out of memory error\n");
00130       LOCAL_USER_REMOVE(u);
00131       return -1;
00132    }
00133 
00134    AST_STANDARD_APP_ARGS(args, input);
00135 
00136    if ((vmbox = strsep(&args.vmbox, "@")))
00137       if (!ast_strlen_zero(args.vmbox))
00138          context = args.vmbox;
00139    if (!vmbox)
00140       vmbox = args.vmbox;
00141 
00142    vmfolder = strchr(vmbox, '/');
00143    if (vmfolder) {
00144       *vmfolder = '\0';
00145       vmfolder++;
00146    } else {
00147       vmfolder = "INBOX";
00148    }
00149 
00150    if (args.options) {
00151       if (strchr(args.options, 'j'))
00152          priority_jump = 1;
00153    }
00154 
00155    vmcount = hasvoicemail_internal(context, vmbox, vmfolder);
00156    /* Set the count in the channel variable */
00157    if (varname) {
00158       snprintf(tmp, sizeof(tmp), "%d", vmcount);
00159       pbx_builtin_setvar_helper(chan, varname, tmp);
00160    }
00161 
00162    if (vmcount > 0) {
00163       /* Branch to the next extension */
00164       if (priority_jump || option_priority_jumping) {
00165          if (ast_goto_if_exists(chan, chan->context, chan->exten, chan->priority + 101)) 
00166             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);
00167       }
00168    }
00169 
00170    snprintf(tmp, sizeof(tmp), "%d", vmcount);
00171    pbx_builtin_setvar_helper(chan, "HASVMSTATUS", tmp);
00172    
00173    LOCAL_USER_REMOVE(u);
00174 
00175    return 0;
00176 }

static int hasvoicemail_internal char *  context,
char *  box,
char *  folder
[static]
 

Definition at line 80 of file app_hasnewvoicemail.c.

References ast_config_AST_SPOOL_DIR.

Referenced by acf_vmcount_exec(), and hasvoicemail_exec().

00081 {
00082    char vmpath[256];
00083    DIR *vmdir;
00084    struct dirent *vment;
00085    int count=0;
00086 
00087    snprintf(vmpath,sizeof(vmpath), "%s/voicemail/%s/%s/%s", (char *)ast_config_AST_SPOOL_DIR, context, box, folder);
00088    if ((vmdir = opendir(vmpath))) {
00089       /* No matter what the format of VM, there will always be a .txt file for each message. */
00090       while ((vment = readdir(vmdir))) {
00091          if (!strncmp(vment->d_name + 7, ".txt", 4)) {
00092             count++;
00093          }
00094       }
00095       closedir(vmdir);
00096    }
00097    return count;
00098 }

char* key void   ) 
 

Returns the ASTERISK_GPL_KEY.

This returns the ASTERISK_GPL_KEY, signifiying that you agree to the terms of the GPL stated in the ASTERISK_GPL_KEY. Your module will not load if it does not return the EXACT message:

 char *key(void) {
         return ASTERISK_GPL_KEY;
 }

Returns:
ASTERISK_GPL_KEY

Definition at line 261 of file app_hasnewvoicemail.c.

References ASTERISK_GPL_KEY.

00262 {
00263    return ASTERISK_GPL_KEY;
00264 }

int load_module void   ) 
 

Initialize the module.

Initialize the Agents module. This function is being called by Asterisk when loading the module. Among other thing it registers applications, cli commands and reads the cofiguration file.

Returns:
int Always 0.

Definition at line 238 of file app_hasnewvoicemail.c.

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

int unload_module void   ) 
 

Cleanup all module structures, sockets, etc.

This is called at exit. Any registrations and memory allocations need to be unregistered and free'd here. Nothing else will do these for you (until exit).

Returns:
Zero on success, or non-zero on error.

Definition at line 225 of file app_hasnewvoicemail.c.

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

00226 {
00227    int res;
00228    
00229    res = ast_custom_function_unregister(&acf_vmcount);
00230    res |= ast_unregister_application(app_hasvoicemail);
00231    res |= ast_unregister_application(app_hasnewvoicemail);
00232    
00233    STANDARD_HANGUP_LOCALUSERS;
00234 
00235    return res;
00236 }

int usecount void   ) 
 

Provides a usecount.

This function will be called by various parts of asterisk. Basically, all it has to do is to return a usecount when called. You will need to maintain your usecount within the module somewhere. The usecount should be how many channels provided by this module are in use.

Returns:
The module's usecount.

Definition at line 254 of file app_hasnewvoicemail.c.

References STANDARD_USECOUNT.

00255 {
00256    int res;
00257    STANDARD_USECOUNT(res);
00258    return res;
00259 }


Variable Documentation

struct ast_custom_function acf_vmcount
 

Definition at line 215 of file app_hasnewvoicemail.c.

Referenced by load_module(), and unload_module().

char* app_hasnewvoicemail = "HasNewVoicemail" [static]
 

Definition at line 64 of file app_hasnewvoicemail.c.

char* app_hasvoicemail = "HasVoicemail" [static]
 

Definition at line 52 of file app_hasnewvoicemail.c.

char* hasnewvoicemail_descrip [static]
 

Definition at line 66 of file app_hasnewvoicemail.c.

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

Definition at line 65 of file app_hasnewvoicemail.c.

char* hasvoicemail_descrip [static]
 

Definition at line 54 of file app_hasnewvoicemail.c.

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

Definition at line 53 of file app_hasnewvoicemail.c.

LOCAL_USER_DECL
 

Definition at line 78 of file app_hasnewvoicemail.c.

STANDARD_LOCAL_USER
 

Definition at line 76 of file app_hasnewvoicemail.c.

char* tdesc = "Indicator for whether a voice mailbox has messages in a given folder." [static]
 

Definition at line 51 of file app_hasnewvoicemail.c.


Generated on Fri May 26 01:45:56 2006 for Asterisk - the Open Source PBX by  doxygen 1.4.6