1 // $FreeBSD: src/share/examples/isdn/contrib/answer.c,v 1.1.2.1 2001/08/10 14:59:47 obrien Exp $
2 // $DragonFly: src/share/examples/isdn/contrib/answer.c,v 1.2 2003/06/17 04:36:57 dillon Exp $
3 // changed ".g711a" to ".al" (-hm)
4 // Tue Mar 3 02:42:14 MET 1998 dave@turbocat.de
8 #define SOX "/usr/local/bin/sox"
9 #define ALAWULAW "/usr/local/bin/alaw2ulaw"
19 char tmpBuf[1024] = "";
22 void writeToPhone (char *path)
29 srcfile = fopen(path,"r");
31 for (i=0;i<BLK_SIZE;i++) {
37 readcount = fread(buf,1, BLK_SIZE, srcfile);
38 fwrite(buf, 1, readcount, device);
40 // fprintf(logfile,"%d read (%d)\n",i,readcount);
41 } while (readcount == BLK_SIZE);
45 fprintf(logfile,"Can't open file '%s'\n",path);
49 void readFromPhone (char *path)
56 destfile = fopen(path,"a");
58 for (i=0;i<BLK_SIZE;i++) {
64 readcount = fread(buf,1, BLK_SIZE, device);
65 fwrite(buf, 1, readcount, destfile);
67 // fprintf(logfile,"%d read (%d)\n",i,readcount);
68 } while (readcount == BLK_SIZE);
72 fprintf(logfile,"Can't open file '%s'\n",path);
78 fprintf(stderr,"Usage: answer -D device -d destination -s source\n");
82 const char * argWithName (const char* aName)
84 // '-D /dev/null -d 82834 -s 3305682834'
89 for (i = 0; i < sizeof(tmpBuf);i++) {
93 for (i = 0; i<strlen(argbuf);i++) {
95 for (;(i<strlen(argbuf) && (argbuf[i] != ' '));i++) {
100 for (;(i<strlen(argbuf) && (argbuf[i] != ' '));i++) {
102 strncpy(tmpBuf,&argbuf[startpos], i-startpos);
106 if (0 == strncmp(aName,&argbuf[i], strlen(aName))) {
115 int main (int argc, const char *argv[]) {
122 char outfileName[1024] = "";
123 char cmdStr[2048] = "";
128 strftime(timeStr,40,I4B_TIME_FORMAT,localtime(&now));
130 logfile = fopen("/var/log/answer.log","a");
132 fprintf(logfile,"%s Started\n",timeStr);
135 for (i=1;i<argc;i++) {
136 sprintf(&argbuf[strlen(argbuf)],"%s ",argv[i]);
138 if (strlen(argbuf) > 2) {
139 argbuf[strlen(argbuf)-1] = '\0';
143 device = fopen(argWithName("-D"),"r+");
144 strcpy(destNum, argWithName("-d"));
145 strcpy(srcNum, argWithName("-s"));
147 fprintf(logfile,"device '%s'\n", argWithName("-D"));
148 fprintf(logfile,"srcNum '%s'\n", srcNum);
149 fprintf(logfile,"destNum '%s'\n", destNum);
154 strftime(timeStr,40,I4B_TIME_FORMAT,localtime(&now));
156 sprintf(outfileName,"/var/isdn/%s_%s_%s", timeStr, srcNum, destNum);
158 writeToPhone ("/usr/local/lib/isdn/msg.al");
159 readFromPhone (outfileName);
161 sprintf(cmdStr,"/bin/cat %s | %s | %s -t raw -U -b -r 8000 - -t .au %s.snd", outfileName, ALAWULAW, SOX, outfileName);
162 fprintf(logfile,"%s\n",cmdStr);
168 fprintf(logfile,"Can't open file '%s'\n",argWithName("-D"));
173 strftime(timeStr,40,I4B_TIME_FORMAT,localtime(&now));
175 fprintf(logfile,"%s Done\n",timeStr);
177 exit(0); // insure the process exit status is 0
178 return 0; // ...and make main fit the ANSI spec.