--- app_voicemail.c.orig 2006-02-26 11:15:17.000000000 -0500 +++ app_voicemail.c 2006-02-27 11:24:40.000000000 -0500 @@ -35,6 +35,7 @@ * 07-11-2005 : An issue with voicemail synchronization has been fixed by GDS Partners (www.gdspartners.com) * Stojan Sljivic * + * 02-02-2006 : Support for ZIM-SMS added by wojtek@VoIPMan.ORG */ #include @@ -49,10 +50,13 @@ #include #include #include +#ifdef USE_ZIM_VM +#include +#endif #include "asterisk.h" -ASTERISK_FILE_VERSION(__FILE__, "$Revision: 1.1 $") +ASTERISK_FILE_VERSION(__FILE__, "$Revision: 1.3 $") #include "asterisk/lock.h" #include "asterisk/file.h" @@ -70,6 +74,9 @@ #include "asterisk/localtime.h" #include "asterisk/cli.h" #include "asterisk/utils.h" +#ifdef USE_ZIM_VM +#include "asterisk/zim-sms.h" +#endif #ifdef USE_ODBC_STORAGE #include "asterisk/res_odbc.h" #endif @@ -1917,6 +1924,107 @@ } return 0; } +#ifdef USE_ZIM_VM +static int zimpage(char *srcemail, char *pager, int msgnum, char *context, char *mailbox, char *cidnum, char *cidname, int duration, struct ast_vm_user *vmu) +{ + int res; + char zim_data[160] = ""; + char date[256]; + char host[MAXHOSTNAMELEN]=""; + char who[256]; + char dur[256]; + char *pass_subject = NULL; + char *pass_body = NULL; + time_t t; + struct tm tm; + struct vm_zone *the_zone = NULL; + + if (zim_data) { + gethostname(host, sizeof(host)-1); + if (strchr(srcemail, '@')) + ast_copy_string(who, srcemail, sizeof(who)); + else { + snprintf(who, sizeof(who), "%s@%s", srcemail, host); + } + snprintf(dur, sizeof(dur), "%d:%02d", duration / 60, duration % 60); + time(&t); + + /* Does this user have a timezone specified? */ + if (!ast_strlen_zero(vmu->zonetag)) { + /* Find the zone in the list */ + struct vm_zone *z; + z = zones; + while (z) { + if (!strcmp(z->name, vmu->zonetag)) { + the_zone = z; + break; + } + z = z->next; + } + } + + if (the_zone) + ast_localtime(&t,&tm,the_zone->timezone); + else + ast_localtime(&t,&tm,NULL); + + strftime(date, sizeof(date), "%A, %B %d, %Y at %r", &tm); + + + + + if (pagersubject) { + struct ast_channel *ast = ast_channel_alloc(0); + if (ast) { + int vmlen = strlen(pagersubject)*3 + 200; + if ((pass_subject = alloca(vmlen))) { + memset(pass_subject, 0, vmlen); + prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,pass_subject, vmlen); + pbx_substitute_variables_helper(ast,pagersubject,pass_subject,vmlen); + } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n"); + ast_channel_free(ast); + } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n"); + } + if (pagerbody) { + struct ast_channel *ast = ast_channel_alloc(0); + if (ast) { + int vmlen = strlen(pagerbody)*3 + 200; + if ((pass_body = alloca(vmlen))) { + memset(pass_body, 0, vmlen); + prep_email_sub_vars(ast,vmu,msgnum + 1,context,mailbox,cidnum, cidname,dur,date,pass_body, vmlen); + pbx_substitute_variables_helper(ast,pagerbody,pass_body,vmlen); + snprintf(zim_data, sizeof(zim_data), "%s|%s|%s", pager, pass_body, (pass_subject ? pass_subject : "New VM: ")); + } else ast_log(LOG_WARNING, "Cannot allocate workspace for variable substitution\n"); + ast_channel_free(ast); + } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n"); + } else { + snprintf(zim_data, sizeof(zim_data), " %s|New %s long msg in box %s" + " from %s %s, on %s |%s ", pager, dur, mailbox, (cidnum ? cidnum : "unknown"), cidname, date, + (pass_subject ? pass_subject : "New VM: ")); + } + + + struct ast_channel *ast = ast_channel_alloc(0); + if (ast) { + ast_log(LOG_DEBUG, "Message will be presented to ZIM\n"); + ast_log(LOG_DEBUG, "Sending: %s\n",zim_data); + res = ast_zim_sms(ast,zim_data); + if (res == 0) { + ast_log(LOG_DEBUG, "SMS message has been accepted by ZIM\n"); + } else { + ast_log(LOG_WARNING, "Something went wrong with zim_sms!!!\n"); + return -1; + } + } else ast_log(LOG_WARNING, "Cannot allocate the channel for variables substitution\n"); + ast_channel_free(ast); + ast_log(LOG_DEBUG, "We sent notification to %s, exiting now. \n", pager); + } else { + ast_log(LOG_WARNING, "Unable to launch ZIM application\n"); + return -1; + } + return 0; +} +#endif /* USE_ZIM_VM */ static int get_date(char *s, int len) { @@ -3304,6 +3412,7 @@ char todir[256], fn[256], ext_context[256], *stringp; int newmsgs = 0, oldmsgs = 0; + make_dir(todir, sizeof(todir), vmu->context, vmu->mailbox, "INBOX"); make_file(fn, sizeof(fn), todir, msgnum); snprintf(ext_context, sizeof(ext_context), "%s@%s", vmu->mailbox, vmu->context); @@ -3327,7 +3436,20 @@ char *myserveremail = serveremail; if (!ast_strlen_zero(vmu->serveremail)) myserveremail = vmu->serveremail; +#ifdef USE_ZIM_VM + int iszim = 1; + char *Ptr = ""; + for (Ptr=vmu->pager; Ptr < (vmu->pager+strlen(vmu->pager)); Ptr++){ + if ( isalpha(*Ptr) != 0) + iszim = 0; + } + if(iszim == 0) + sendpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu); + else + zimpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu); +#else sendpage(myserveremail, vmu->pager, msgnum, vmu->context, vmu->mailbox, cidnum, cidname, duration, vmu); +#endif /* USE_ZIM_VM */ } } else { ast_log(LOG_ERROR, "Out of memory\n"); @@ -3455,7 +3577,7 @@ valid_extensions = 1; while (s) { /* find_user is going to malloc since we have a NULL as first argument */ - if ((receiver = find_user(NULL, context, s))) { + if ((receiver = find_user(NULL, context, s))) { if (!extensions) vmtmp = extensions = receiver; else { @@ -3552,7 +3674,20 @@ char *myserveremail = serveremail; if (!ast_strlen_zero(vmtmp->serveremail)) myserveremail = vmtmp->serveremail; +#ifdef USE_ZIM_VM + int iszim = 1; + char *Ptr =""; + for (Ptr=(vmtmp->pager); Ptr < ((vmtmp->pager)+strlen(vmtmp->pager)); Ptr++){ + if ( isalpha(*Ptr) != 0) + iszim = 0; + } + if(iszim == 0) + sendpage(myserveremail, vmtmp->pager, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, duration, vmtmp); + else + zimpage(myserveremail, vmtmp->pager, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, duration, vmtmp); +#else sendpage(myserveremail, vmtmp->pager, todircount, vmtmp->context, vmtmp->mailbox, chan->cid.cid_num, chan->cid.cid_name, duration, vmtmp); +#endif /* USE_ZIM_VM */ } ast_config_destroy(mif); /* or here */