Minor formatting fixes for pbx_wilcalu

git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@3358 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Mark Spencer
2004-06-29 20:09:43 +00:00
parent 074f8d9378
commit 9b32ff1eeb

View File

@@ -6,7 +6,7 @@
* *
* Copyright (C) 1999, Mark Spencer * Copyright (C) 1999, Mark Spencer
* *
* Mark Spencer <markster@linux-support.net> * Mark Spencer <markster@digium.com>
* *
* This program is free software, distributed under the terms of * This program is free software, distributed under the terms of
* the GNU General Public License * the GNU General Public License
@@ -34,24 +34,24 @@
#include "../astconf.h" #include "../astconf.h"
// Globals /* Globals */
const char dialfile[255]; const char dialfile[255];
static char *tdesc = "Wil Cal U (Auto Dialer)"; static char *tdesc = "Wil Cal U (Auto Dialer)";
static pthread_t autodialer_thread; static pthread_t autodialer_thread;
static char buf[257]; static char buf[257];
static char lastbuf[257];//contains last partial buffer static char lastbuf[257]; /* contains last partial buffer */
static char sendbuf[257]; static char sendbuf[257];
STANDARD_LOCAL_USER; STANDARD_LOCAL_USER;
LOCAL_USER_DECL; LOCAL_USER_DECL;
//prototype /* prototype */
static void *dialstring(void *string); static void *dialstring(void *string);
// types /* types */
struct alarm_data { struct alarm_data {
time_t alarm_time; time_t alarm_time;
int snooze_len; int snooze_len;
void *dialstr; void *dialstr;
}; };
static void *autodial(void *ignore) static void *autodial(void *ignore)
@@ -61,6 +61,7 @@ static void *autodial(void *ignore)
int fd=open(dialfile,O_RDONLY|O_NONBLOCK); int fd=open(dialfile,O_RDONLY|O_NONBLOCK);
int flags = fcntl(fd, F_GETFL); int flags = fcntl(fd, F_GETFL);
struct pollfd fds[1]; struct pollfd fds[1];
fcntl(fd, F_SETFL, flags & ~O_NONBLOCK); fcntl(fd, F_SETFL, flags & ~O_NONBLOCK);
if (option_debug) if (option_debug)
ast_log(LOG_DEBUG, "Entered Wil-Calu fd=%d\n",fd); ast_log(LOG_DEBUG, "Entered Wil-Calu fd=%d\n",fd);
@@ -86,23 +87,23 @@ static void *autodial(void *ignore)
int x; int x;
ast_log(LOG_DEBUG, "WilCalu : Read Buf %s\n",buf); ast_log(LOG_DEBUG, "WilCalu : Read Buf %s\n",buf);
sendbufptr=sendbuf; sendbufptr=sendbuf;
for(x=0;lastbuf[x]!=0 && x<257;x++); for(x=0; lastbuf[x]!=0 && x<257; x++);
if(x) { if(x) {
memcpy(sendbuf,lastbuf,x); memcpy(sendbuf, lastbuf, x);
sendbufptr+=x; sendbufptr+=x;
memset(lastbuf,0,257); memset(lastbuf, 0, 257);
} }
/* Process bytes read */ /* Process bytes read */
for(x=0;x<bytes;x++){ for(x=0; x<bytes; x++){
/* if & then string is complete */ /* if & then string is complete */
if(buf[x]=='&'){ if(buf[x]=='&'){
if(NULL!=(pass=(void *)strdup(sendbuf))){ if(NULL!=(pass=(void *)strdup(sendbuf))){
pthread_create(&dialstring_thread,NULL,dialstring,pass); pthread_create(&dialstring_thread, NULL, dialstring, pass);
sendbufptr=sendbuf; sendbufptr=sendbuf;
memset(sendbuf,0,257); memset(sendbuf, 0, 257);
} }
else { else {
perror("Autodial:Strdup failed"); perror("Autodial: Strdup failed");
close(fd); close(fd);
pthread_exit(NULL); pthread_exit(NULL);
} }
@@ -115,7 +116,7 @@ static void *autodial(void *ignore)
} }
} }
if(sendbufptr!=sendbuf) if(sendbufptr!=sendbuf)
memcpy(lastbuf,sendbuf,sendbufptr-sendbuf+1); memcpy(lastbuf, sendbuf, sendbufptr-sendbuf+1);
} }
} }
close(fd); close(fd);
@@ -123,26 +124,30 @@ static void *autodial(void *ignore)
return NULL; return NULL;
} }
static void *snooze_alarm(void *pass){ static void *snooze_alarm(void *pass)
{
pthread_t dialstring_thread; pthread_t dialstring_thread;
struct alarm_data *data=(struct alarm_data *)pass; struct alarm_data *data = (struct alarm_data *) pass;
sleep(data->snooze_len); sleep(data->snooze_len);
pthread_create(&dialstring_thread,NULL,dialstring,data->dialstr); pthread_create(&dialstring_thread, NULL, dialstring, data->dialstr);
// dialstring will free data->dialstr /* dialstring will free data->dialstr */
free(pass); free(pass);
pthread_exit(NULL); pthread_exit(NULL);
return NULL; return NULL;
} }
static void set_snooze_alarm(char *dialstr,int snooze_len){
static void set_snooze_alarm(char *dialstr, int snooze_len)
{
pthread_t snooze_alarm_thread; pthread_t snooze_alarm_thread;
struct alarm_data *pass; struct alarm_data *pass;
ast_log(LOG_DEBUG, "Answered: Snooze Requested\n"); ast_log(LOG_DEBUG, "Answered: Snooze Requested\n");
if(NULL==(pass=malloc(sizeof(struct alarm_data)))){ if (NULL==(pass=malloc(sizeof(struct alarm_data)))){
perror("snooze_alarm: data"); perror("snooze_alarm: data");
pthread_exit(NULL); pthread_exit(NULL);
} }
if(NULL==(pass->dialstr=(void *)strdup(dialstr))){ if (NULL==(pass->dialstr=(void *)strdup(dialstr))){
free(pass); free(pass);
perror("snooze_alarm: dialstr"); perror("snooze_alarm: dialstr");
pthread_exit(NULL); pthread_exit(NULL);
@@ -151,23 +156,24 @@ static void set_snooze_alarm(char *dialstr,int snooze_len){
pthread_create(&snooze_alarm_thread,NULL,snooze_alarm,pass); pthread_create(&snooze_alarm_thread,NULL,snooze_alarm,pass);
} }
static void *dialstring(void *string){ static void *dialstring(void *string)
{
struct ast_channel *channel; struct ast_channel *channel;
char *bufptr,*destptr; char *bufptr,*destptr;
// ms affects number of rings int ms=10000; /* ms affects number of rings */
int ms=10000;
int cnt=0,first; int cnt=0,first;
char tech[256]; char tech[256];
char tele[256]; char tele[256];
char filename[256]; char filename[256];
int answered=0; int answered=0;
for(first=0,bufptr=(char *)string,destptr=tech;*bufptr&&cnt<256;cnt++){
if(*bufptr=='/' && !first){ for(first=0, bufptr=(char *)string, destptr=tech; *bufptr&&cnt<256; cnt++){
if(*bufptr=='/' && !first) {
*destptr=0; *destptr=0;
destptr=tele; destptr=tele;
first=1; first=1;
} }
else if(*bufptr==','){ else if(*bufptr==',') {
*destptr=0; *destptr=0;
destptr=filename; destptr=filename;
} else { } else {
@@ -178,18 +184,17 @@ static void *dialstring(void *string){
} }
*destptr=0; *destptr=0;
ast_log(LOG_DEBUG, "Printing string arg: %s Eos\n", (char *)string); ast_log(LOG_DEBUG, "Printing string arg: %s Eos\n", (char *)string);
if(strlen(tech)+strlen(tele)+strlen(filename)>256){ if(strlen(tech)+strlen(tele)+strlen(filename) > 256) {
ast_log(LOG_ERROR, "Autodial:Error string too long\n"); ast_log(LOG_ERROR, "Autodial:Error string too long\n");
free(string); free(string);
pthread_exit(NULL); pthread_exit(NULL);
} }
ast_log(LOG_DEBUG, "Autodial Tech %s(%d) Tele %s(%d) Filename %s(%d)\n",tech,(int)strlen(tech),tele,(int)strlen(tele),filename,(int)strlen(filename)); ast_log(LOG_DEBUG, "Autodial Tech %s(%d) Tele %s(%d) Filename %s(%d)\n",tech, (int)strlen(tech), tele, (int)strlen(tele), filename, (int)strlen(filename));
channel=ast_request(tech,AST_FORMAT_SLINEAR,tele); channel=ast_request(tech,AST_FORMAT_SLINEAR,tele);
if(channel!=NULL){ if(channel!=NULL){
ast_call(channel,tele,10000); ast_call(channel,tele,10000);
} } else {
else {
ast_log(LOG_ERROR, "Autodial:Sorry unable to obtain channel\n"); ast_log(LOG_ERROR, "Autodial:Sorry unable to obtain channel\n");
free(string); free(string);
pthread_exit(NULL); pthread_exit(NULL);
@@ -198,19 +203,21 @@ static void *dialstring(void *string){
ast_log(LOG_DEBUG, "Autodial:Line is Up\n"); ast_log(LOG_DEBUG, "Autodial:Line is Up\n");
while(ms>0){ while(ms>0){
struct ast_frame *f; struct ast_frame *f;
ms=ast_waitfor(channel,ms); ms=ast_waitfor(channel,ms);
f=ast_read(channel); f=ast_read(channel);
if(!f){ if(!f){
ast_log(LOG_DEBUG, "Autodial:Hung Up\n"); ast_log(LOG_DEBUG, "Autodial:Hung Up\n");
break; break;
} }
if(f->frametype==AST_FRAME_CONTROL){ if (f->frametype==AST_FRAME_CONTROL) {
if(f->subclass==AST_CONTROL_ANSWER){ if (f->subclass==AST_CONTROL_ANSWER) {
ast_log(LOG_DEBUG, "Autodial:Phone Answered\n"); ast_log(LOG_DEBUG, "Autodial:Phone Answered\n");
if(channel->_state==AST_STATE_UP){ if (channel->_state==AST_STATE_UP) {
char res; char res;
ast_streamfile(channel,filename,0); ast_streamfile(channel,filename,0);
// Press Five for snooze /* Press Five for snooze */
res=ast_waitstream(channel, "37"); res=ast_waitstream(channel, "37");
if(res=='3'){ if(res=='3'){
answered=1; answered=1;
@@ -227,19 +234,20 @@ static void *dialstring(void *string){
ms=0; ms=0;
} }
} }
else if(f->subclass==AST_CONTROL_RINGING) else if (f->subclass==AST_CONTROL_RINGING)
ast_log(LOG_DEBUG, "Autodial:Phone Ringing end\n"); ast_log(LOG_DEBUG, "Autodial:Phone Ringing end\n");
} }
ast_frfree(f); ast_frfree(f);
} }
if(!answered) if(!answered)
set_snooze_alarm((char *)string,5); set_snooze_alarm((char *) string, 5);
free(string); free(string);
ast_hangup(channel); ast_hangup(channel);
ast_log(LOG_DEBUG, "Autodial:Hung up channel\n"); ast_log(LOG_DEBUG, "Autodial:Hung up channel\n");
pthread_exit(NULL); pthread_exit(NULL);
return NULL; return NULL;
} }
int unload_module(void) int unload_module(void)
{ {
STANDARD_HANGUP_LOCALUSERS; STANDARD_HANGUP_LOCALUSERS;
@@ -250,14 +258,15 @@ int unload_module(void)
int load_module(void) int load_module(void)
{ {
int val; int val;
snprintf((char *)dialfile,sizeof(dialfile)-1,"%s/%s",(char *)ast_config_AST_RUN_DIR,"autodial.ctl");
if((val=mkfifo(dialfile, 0700))){ snprintf((char *)dialfile, sizeof(dialfile)-1,"%s/%s", (char *)ast_config_AST_RUN_DIR,"autodial.ctl");
if((val=mkfifo(dialfile, 0700))) {
if(errno!=EEXIST){ if(errno!=EEXIST){
ast_log(LOG_ERROR, "Error:%d Creating Autodial FIFO\n",errno); ast_log(LOG_ERROR, "Error:%d Creating Autodial FIFO\n",errno);
return 0; return 0;
} }
} }
pthread_create(&autodialer_thread,NULL,autodial,NULL); pthread_create(&autodialer_thread, NULL, autodial, NULL);
return 0; return 0;
} }