From cabb939f708eca3f3c442b3879b50bc9e578f65a Mon Sep 17 00:00:00 2001 From: jankratochvil <> Date: Mon, 6 Sep 1999 15:15:41 +0000 Subject: [PATCH] This commit was manufactured by cvs2svn to create branch 'unlabeled-1.5.2'. Sprout from master 1999-09-06 15:15:39 UTC short 'Removed RCS Log entries as recommended in CVS Faq-O-Matic.' Delete: AUTHORS Makefile.am NEWS README acconfig.h autogen.sh configure.in manfmt.c mdsms.1.c mdsms.c setup.h strdup.c --- AUTHORS | 15 - Makefile.am | 28 -- NEWS | 8 - README | 28 -- acconfig.h | 66 ----- autogen.sh | 55 ---- configure.in | 159 ---------- manfmt.c | 48 ---- mdsms.1.c | 7 - mdsms.c | 924 ----------------------------------------------------------- setup.h | 39 --- strdup.c | 20 -- 12 files changed, 1397 deletions(-) delete mode 100644 AUTHORS delete mode 100644 Makefile.am delete mode 100644 NEWS delete mode 100644 README delete mode 100644 acconfig.h delete mode 100755 autogen.sh delete mode 100644 configure.in delete mode 100644 manfmt.c delete mode 100644 mdsms.1.c delete mode 100644 mdsms.c delete mode 100644 setup.h delete mode 100644 strdup.c diff --git a/AUTHORS b/AUTHORS deleted file mode 100644 index cffe83a..0000000 --- a/AUTHORS +++ /dev/null @@ -1,15 +0,0 @@ -Author of MobilDock SMS Sender: -------------------------------- - -Name: Jan Kratochvil - -e-Mail: short@ucw.cz - -Phone: +420603431329 or - +420602431329 - -Homepage: http://atrey.karlin.mff.cuni.cz/~short/ - -Snail-mail: K ovcinu 44 - 182 00, Praha 8 - Czech Republic diff --git a/Makefile.am b/Makefile.am deleted file mode 100644 index 4b2bef3..0000000 --- a/Makefile.am +++ /dev/null @@ -1,28 +0,0 @@ -# $Id$ - -AUTOMAKE_OPTIONS = dist-tarZ - -EXTRA_DIST = autogen.sh mdsms.1.in ChangeLog - -CLEANFILES = ChangeLog - -bin_PROGRAMS = mdsms -man_MANS = mdsms.1 -noinst_PROGRAMS = manfmt mdsms.1 -noinst_HEADERS = setup.h getopt.h - -manfmt_SOURCES = manfmt.c - -mdsms_SOURCES = mdsms.c -mdsms_LDADD = @LIBOBJS@ - -mdsms.1.o: mdsms.1.c mdsms.1.in config.h setup.h - $(CPP) > mdsms.1.o mdsms.1.c - -mdsms.1: manfmt mdsms.1.o - ./manfmt > mdsms.1 < mdsms.1.o - -.PHONY: ChangeLog - -ChangeLog: - rcs2log >ChangeLog diff --git a/NEWS b/NEWS deleted file mode 100644 index 5130256..0000000 --- a/NEWS +++ /dev/null @@ -1,8 +0,0 @@ -MobilDock SMS sender NEWS -========================= - -$Id$ - -1.2: Stabilization release - Compatibility problem with Digital UNIX 4.0 termios fixed, - all currently known defects have been fixed. diff --git a/README b/README deleted file mode 100644 index d9665d9..0000000 --- a/README +++ /dev/null @@ -1,28 +0,0 @@ -MobilDock SMS sender -==================== - -$Id$ - - Development platform / device test passed on: - - Linux [i386] (kernel 2.2.7, RedHat based) - - Supported platforms regarding successful compilation. Real functionality -expected although testing not possible: - - Digital UNIX 4.0E [alpha] - Linux [sparc] (kernel 2.1.77, RedHat based) - Sun SunOS 5.5.1 [sparc/sun4m] - SGI IRIX 6.5 [mips] - - For quick installation type: - - ./configure - make install - - For full installation options see file INSTALL. - - Documentation available in 'man' format, type "man mdsms" after -installation. - - Contact to author available in file AUTHORS. diff --git a/acconfig.h b/acconfig.h deleted file mode 100644 index 6d7a2b0..0000000 --- a/acconfig.h +++ /dev/null @@ -1,66 +0,0 @@ -/* acconfig.h Generated manually for use by autoheader. */ -/* - * $Id$ - */ - -/* __NORETURN define - usually a GCC extension. */ -#undef __NORETURN - -/* __NORETURN2 define - usually a GCC extension. */ -#undef __NORETURN2 - -/* Turn on debugging to stderr. */ -#undef DEBUG - -/* Disable runtime assertion checks. */ -#undef NDEBUG - -/* Provide stub for MAX-function if needed. */ -#undef HAVE_MAX -#ifndef HAVE_MAX -#define MAX(a,b) ((a)>(b)?(a):(b)) -#endif - -/* Provide stub for MIN-function if needed. */ -#undef HAVE_MIN -#ifndef HAVE_MIN -#define MIN(a,b) ((a)<(b)?(a):(b)) -#endif - -/* LINE_MAX from , provide default if not defined. */ -#undef HAVE_LINE_MAX -#undef LINE_MAX - -/* CBAUD define, may be missing. */ -#undef HAVE_CBAUD -#undef CBAUD - -/* CBAUDEX define, may be missing. */ -#undef HAVE_CBAUDEX -#undef CBAUDEX - -/* snprintf(3) unsafe emulation */ -#undef HAVE_SNPRINTF -#ifdef HAVE_SNPRINTF -#define VARPRINTF(v,f,d) snprintf((v),sizeof((v)),f,(d)) -#else -#define VARPRINTF(v,f,d) sprintf((v),f,(d)) -#endif - -/* vsnprintf(3) unsafe emulation */ -#undef HAVE_VSNPRINTF -#ifdef HAVE_VSNPRINTF -#define VARVPRINTF(v,f,d) vsnprintf((v),sizeof((v)),f,(d)) -#else -#define VARVPRINTF(v,f,d) vsprintf((v),f,(d)) -#endif - -/* printf family accepts %m */ -#undef PRINTF_WORKS_PM - -/* found lockfile directory */ -#undef DEF_LOCKFILE - -/* how to declare __atribute__ ((__unused__)) */ -#undef ATTR_UNUSED - diff --git a/autogen.sh b/autogen.sh deleted file mode 100755 index e5791fa..0000000 --- a/autogen.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/bin/sh -# Run this to generate all the initial makefiles, etc. - -# $Id$ - -CONFDEFS="--enable-maintainer-mode --enable-debug" - -if [ -f Makefile ];then touch ChangeLog;make maintainer-clean;fi -VER="`sed ], [LINE_MAX;], - AC_DEFINE(HAVE_LINE_MAX) AC_MSG_RESULT(yes), - AC_DEFINE(LINE_MAX, 4096) AC_MSG_RESULT(no)) - -AC_MSG_CHECKING([for CBAUD]) -AC_TRY_COMPILE([#include ], [CBAUD;], - AC_DEFINE(HAVE_CBAUD) AC_MSG_RESULT(yes), - AC_DEFINE(CBAUD, 0) AC_MSG_RESULT(no)) - -AC_MSG_CHECKING([for CBAUDEX]) -AC_TRY_COMPILE([#include ], [CBAUDEX;], - AC_DEFINE(HAVE_CBAUDEX) AC_MSG_RESULT(yes), - AC_DEFINE(CBAUDEX, 0) AC_MSG_RESULT(no)) - -AC_MSG_CHECKING([for unused attribute]) -uns=true -for un in __unused__ unused;do - if $uns;then - unx="__attribute__ (($un))" - AC_TRY_COMPILE([#include ],[char untest $unx;], - AC_DEFINE_UNQUOTED(ATTR_UNUSED, $unx) - AC_MSG_RESULT($un) - uns=false) - fi - done -if $uns;then AC_DEFINE(ATTR_UNUSED,) AC_MSG_RESULT(no);fi - -AC_CHECK_FUNC(snprintf, AC_DEFINE(HAVE_SNPRINTF)) -AC_CHECK_FUNC(vsnprintf, AC_DEFINE(HAVE_VSNPRINTF)) - -AC_TYPE_SIGNAL -AC_TYPE_PID_T - -AC_REPLACE_FUNCS(strdup) -dnl AC_MSG_CHECKING([for strdup]) -dnl AC_TRY_COMPILE([#include ], [strdup("");], -dnl AC_DEFINE(HAVE_STRDUP) AC_MSG_RESULT(yes), -dnl LIBOBJS="$LIBOBJS strdup.o" AC_MSG_RESULT(no)) - -AC_MSG_CHECKING([for working %m in printf]) -AC_TRY_RUN([int main() { char s[100]; - sprintf(s,"%m"); - return(!(strcmp(s,"m") && strcmp(s,"%m"))); - }],AC_DEFINE(PRINTF_WORKS_PM) AC_MSG_RESULT(yes),AC_MSG_RESULT(no),AC_MSG_RESULT(avoiding)) - -# Final output. - -AC_SUBST(LIBOBJS) - -AC_OUTPUT(Makefile) diff --git a/manfmt.c b/manfmt.c deleted file mode 100644 index 47092a8..0000000 --- a/manfmt.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "config.h" -#ifndef lint -static char rcsid[] ATTR_UNUSED = "$Id$"; -#endif - -#include -#include -#include -#include - -static char buf[LINE_MAX]; - -int main(void) -{ -char *s,*s2,*d; -char f; - - while (fgets(buf,sizeof(buf),stdin)) { - if (*buf=='#') continue; - for (s=buf;*s==' ';s++); - if (*s=='\n' || !*s) continue; - f=0; - for (d=s=buf;*s;s++) { - if (*s=='\t') { - if ((f=!f)) { -/*fprintf(stderr,"DURING TURN-ON:%s",s);*/ - if (s[1]=='"') s++; - } - else { -/*fprintf(stderr,"DURING TURN-OFF:%s",s);*/ - while (d>buf && (d[-1]=='"' || d[-1]==' ')) d--; - } - continue; - } - s2=s; - if (*s=='~' ) *s='"'; - else if (f && s[0]=='"' && s[1]==' ') { - while (*++s==' '); - if (*s=='"') continue; - s=s2; - } - *d++=*s; - } - *d='\0'; - fputs(buf,stdout); - } - return(EXIT_SUCCESS); -} diff --git a/mdsms.1.c b/mdsms.1.c deleted file mode 100644 index 23d8ae1..0000000 --- a/mdsms.1.c +++ /dev/null @@ -1,7 +0,0 @@ -/* - * $Id$ - */ - -#include "config.h" -#include "setup.h" -#include "mdsms.1.in" diff --git a/mdsms.c b/mdsms.c deleted file mode 100644 index a4e6498..0000000 --- a/mdsms.c +++ /dev/null @@ -1,924 +0,0 @@ -#include "config.h" -#ifndef lint -static char rcsid[] ATTR_UNUSED = "$Id$"; -#endif - -#include "setup.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_GETOPT_LONG -#include -#else -#include "getopt.h" -#endif - -#if 0 -char *strdup(const char *s); -int kill(pid_t pid,int sig); -int snprintf(char *str,size_t n,const char *format,...); -int vsnprintf(char *str,size_t n,const char *format,va_list ap); -void usleep(unsigned long usec); -#endif - -#define NELEM(x) (sizeof((x))/sizeof(*(x))) - -#ifndef DEBUG -#define dbg(cmd) -#else -#define dbg(cmd) cmd -#endif -/* ANSI C does not allow macro with variable arguments */ -#define dO stderr -#define dB(a) dbg(fprintf a) - -#define d1(n1) dB((dO,n1 )) -#define d2(n1,n2) dB((dO,n1,n2 )) -#define d3(n1,n2,n3) dB((dO,n1,n2,n3 )) -#define d4(n1,n2,n3,n4) dB((dO,n1,n2,n3,n4)) - -static const char version[]="This is MobilDock SMS sender (" PACKAGE " " VERSION ")\n"; - -static int verbose -#ifdef DEBUG - =0xFFFF -#endif - ; -static char *pname; -static int dis_cleanup=0,devfd=-1; - -static char *phone,*body,*device,*logname,*lockfile,*smsc,*maxretry,*readtime,*chartime,*cmdtime; -static int readbody; -static long maxretryn=DEF_MAXRETRY,readtimen=DEF_READTIME,chartimen=DEF_CHARTIME,cmdtimen=DEF_CMDTIME; -static size_t bodylen; - -static char *devicename; /* path stripped */ -static char lockreal[512],locked; - -static struct termios restios,tios; -static char restios_yes; -static FILE *logf; - -static void vlogmsg( -#ifndef PRINTF_WORKS_PM - char outerr, -#endif - const char *fmt,va_list ap) -{ -time_t stamp; -char *ctm,*s; -pid_t mypid=-1; -char host[LINE_MAX]; - - if (!logf) return; - if (mypid==-1) { - mypid=getpid(); - if (gethostname(host,sizeof(host))) strcpy(host,""); - } - time(&stamp); - ctm=ctime(&stamp); - if ((s=strchr(ctm,'\n'))) *s='\0'; - fprintf(logf,"%s %s %s[%d]: ",ctm,host,pname,mypid); - vfprintf(logf,fmt,ap); -#ifndef PRINTF_WORKS_PM - if (outerr) fputs(strerror(errno),logf); -#endif - fputc('\n',logf); - fflush(logf); -} - -static void logmsg(const char *fmt,...) -{ -va_list ap; - va_start(ap,fmt); - vlogmsg( -#ifndef PRINTF_WORKS_PM - 0, -#endif - fmt,ap); - va_end(ap); -} - -static void error(const char *fmt,...) -{ -va_list ap; -char fatal=*fmt; -#ifndef PRINTF_WORKS_PM -char pm,*nfmt; -size_t fmtl; -#endif - - if (fatal=='!' || fatal=='.' || fatal=='\n') fmt++; - else fatal=0; - -#ifndef PRINTF_WORKS_PM - if (!(nfmt=strdup(fmt))) return; - fmtl=strlen(fmt); - if ((pm=(fmtl>=2 && !strcmp(fmt+fmtl-2,"%m")))) nfmt[fmtl-2]='\0'; -#endif - - fprintf(stderr,"%s: ",pname); - va_start(ap,fmt); - vfprintf(stderr, -#ifdef PRINTF_WORKS_PM - fmt -#else - nfmt -#endif - ,ap); - if (fatal=='!') vlogmsg( -#ifdef PRINTF_WORKS_PM - fmt -#else - pm,nfmt -#endif - ,ap); - va_end(ap); - -#ifndef PRINTF_WORKS_PM - if (pm) { - fputs(strerror(errno),stderr); - free(nfmt); - } -#endif - - if (fatal!='\n') fputc((fatal=='.'?'.':'!'),stderr); - fputc('\n',stderr); - if (fatal=='!') exit(EXIT_FAILURE); -} - -static void chk(void *p) -{ - if (p) return; - error("!Virtual memory exhausted"); -} - -static void cleanup(void) -{ - d1("cleanup()\n"); - if (dis_cleanup) return; - if (restios_yes) { - if (tcsetattr(devfd,TCSANOW,&restios)) - error("Error restoring termios for device: %m"); - restios_yes=0; - } - if (locked && *lockreal) { - d2("Removing lockfile \"%s\"\n",lockreal); - if (unlink(lockreal)) - error("Error removing my device lockfile \"%s\": %m",lockreal); - locked=0; - } - dis_cleanup=1; - exit(EXIT_FAILURE); -} - -static void usage(void) -{ - fprintf(stderr,"\ -\n\ -%s\ -\n\ -Usage: " PACKAGE " [-c|--config ] [-d|--device ]\n\ - [-L|--log ]\n\ - [-l|--lockfile ] [-s|--smsc ] [-m|--maxretry <#>]\n\ - [-r|--readtime ] [-t|--chartime ] [-T|--cmdtime ]\n\ - [-f|--file] [-v|--verbose] [-h|--help] [-V|--version]\n\ - \n\ -\n\ - -c, --config\tRead this additional config file\n\ -\t\t(def. \"" CONFIG_MAIN "\" and \"$HOME" CONFIG_HOME "\")\n\ - -d, --device\tMobilDock on this serial device (def. \"" DEF_DEVICE "\")\n\ - -L, --log\tLog all important messages to this file (def. \"" DEF_LOGNAME "\")\n\ - -l, --lockfile\tLock serial port by this file, \"%%s\" is basename of device\n\ -\t\t(def. \"%s\")\n\ - -s, --smsc\tUse this SMS Center number (def. query from Siemens A1)\n\ - -m, --maxretry\tMaximum retries of any command before giving up (def. %d)\n\ - -r, --readtime\tSeconds for maximum wait time for response (def. %ds)\n\ - -t, --chartime\tMilliseconds between each char on baud 19200 (def. %dms)\n\ - -T, --cmdtime\tMilliseconds before each whole AT command (def. %dms)\n\ - -f, --file\tRead contents of message from file instead\n\ - -v, --verbose\tIncrease verbosity level, more \"-v\"s give more messages\n\ - -h, --help\tPrint a summary of the options\n\ - -V, --version\tPrint the version number\n\ -\n",version,DEF_LOCKFILE,DEF_MAXRETRY,DEF_READTIME,DEF_CHARTIME,DEF_CMDTIME); - exit(EXIT_FAILURE); -} - -static const struct option longopts[]={ -{"config" ,1,0,'c'}, -{"device" ,1,0,'d'}, -{"log" ,1,0,'l'}, -{"lockfile",1,0,'l'}, -{"smsc" ,1,0,'s'}, -{"maxretry",1,0,'m'}, -{"readtime",1,0,'r'}, -{"chartime",1,0,'t'}, -{"cmdtime" ,1,0,'T'}, -{"file" ,0,0,'f'}, -{"verbose" ,0,0,'v'}, -{"help" ,0,0,'h'}, -{"version" ,0,0,'V'}}; - -static void processargs(int argp,char **args,const char *from); - -static char *cfgstack[MAXCFGLOOP]; -static unsigned cfgstacki=0; - -static void chkfclose(FILE *f,const char *fname) -{ - if (fclose(f)) - error("Error closing \"%s\": %m",fname); -} - -static void readfile(const char *fname,char quiet) -{ -FILE *f; -size_t got; -char *args[MAXCFGARGS],*d,*s,blank,quote; -unsigned argp; -char *buf; -long size; -static unsigned tot=0; - - if (tot++>=MAXCFGNUM) { - if (tot==MAXCFGNUM+1) error("Too many config files to read, max is %d, break-out",MAXCFGNUM); - return; - } - if (!(f=fopen(fname,"rt"))) { - if (!quiet) error("Can't open config file \"%s\" for r/o: %m",fname); - return; - } - if (verbose>=2) error(".Reading config file \"%s\"",fname); - if (fseek(f,0,SEEK_END)) - error("Error seeking to end of \"s\": %m",fname); - if ((size=ftell(f))<0) - size=0,error("Error measuring \"%s\": %m",fname); - if (size>MAXCONFIG) - error("File \"%s\" is too long, read only %ld bytes",fname,MAXCONFIG); - chk(buf=malloc((size?size:MAXCONFIG)+1)); - rewind(f); - got=fread(buf,1,(size?size:MAXCONFIG),f); - if (size && got!=size) - error("File \"%s\" read error, got only %u bytes of %ld",fname,got,size); - chkfclose(f,fname); - buf[got]='\0'; - args[0]=pname; - for (argp=1,d=s=buf,blank=1,quote=0;s=2) error("\nConfig \"%s\": arg#%d: %s",fname,argp-1,args[argp-1]); - } - continue; - } - if (blank) { - if (argp>=NELEM(args)-1) { - error("Too many arguments in \"%s\", from offset %d ignored",fname,s-buf); - break; - } - args[argp++]=s; - d=s; - blank=0; - } - if (c=='\\') { *d++=*++s; continue; } - if (c=='"' || c=='\'') { - if (!quote ) { quote=c; continue; } - if ( quote==c) { quote=0; continue; } - /* FALLTHRU */ - } - *d++=c; - } - args[argp]=NULL; - processargs(argp,args,fname); - free(buf); -} - -static struct { - const char c; - char **const var; - unsigned stamp; - } optset[]={ - { 'd',&device }, - { 'L',&logname }, - { 'l',&lockfile }, - { 's',&smsc }, - { 'm',&maxretry }, - { 'r',&readtime }, - { 't',&chartime }, - { 'T',&cmdtime }, - }; - -static void processargs(int argp,char **args,const char *from) -{ -int optc; -static unsigned seq=0; -int i; - - seq++; - optarg=NULL; optind=0; /* FIXME: Possible portability problem. */ - while ((optc=getopt_long(argp,args,"c:d:L:l:s:m:r:t:T:fvhV",longopts,NULL))!=EOF) switch (optc) { - case 'c': - if (cfgstacki>=NELEM(cfgstack)) { - error("Looping (%d) during attempt to read config file \"%s\", break-out",NELEM(cfgstack),optind); - break; - } - chk(cfgstack[cfgstacki++]=strdup(optarg)); - break; - case 'd': case 'L': case 'l': case 's': case 'm': case 'r': case 't': case 'T': - for (i=0;i=0); - readfile(s,0); - free(s); - assert(cfgstacki>=0 && cfgstacki=3) error(".Checking the lockfile \"%s\"..",lockreal); - if ((fd=open(lockreal,O_RDONLY))==-1) break; - if ((got=read(fd,buf,sizeof(buf)-1))<=0) { -isempty: - if (empty>=DEVLOCK_MAXEMPTY) { - error(".Lockfile \"%s\" is still not valid, removing it",lockreal); - goto remove; - } - empty++; - continue; - } - assert(got=1) error("Timed out"); -} - -static void blocking(char yes) -{ -static char state=-1; - if (state==yes) return; - if (fcntl(devfd,F_SETFL,(yes?0:O_NONBLOCK))) - error("!fcntl() on device for %sblocking mode: %m",(yes?"":"non-")); - state=yes; -} - -static const char *record; -static char *catchdata; -static size_t catchdatal,catchdatasiz; - -static void catched(const char *end) -{ -size_t len; -void *p; - - if (!record) return; - assert(end>=record); - if ((p=memchr(record,'\n',end-record))) end=p; - if ((len=end-record)) { - if (catchdatal+len>catchdatasiz) - chk(catchdata=realloc(catchdata, - (catchdatasiz=MAX(LINE_MAX,(catchdatal+len)*2)))); - memcpy(catchdata+catchdatal,record,len); - catchdatal+=len; - } - record=(p?NULL:end); - assert(catchdatal<=catchdatasiz); -} - -static int retrycnt=0; -static void retrying(void) -{ - if (++retrycnt>maxretryn) error("!Maximum command retry count (%d) exceeded",maxretryn); - if (verbose>=2) error(".Retrying phase, %d out of %d..",retrycnt,maxretryn); -} - -static char *devcmd(const char *term,const char *catch,const char *send,...) -{ -size_t l,bufl,terml,catchl,fragl,offs; -char buf[LINE_MAX]; -ssize_t got; -char *hit,*s; -va_list ap; -char errout; - - if (!term) term="\nOK\n"; - if ((errout=(*send=='!'))) send++; - if (0) { -err: - alarm(0); - if (errout) return(NULL); - retrying(); - } - catchdatal=0; - va_start(ap,send); - l=VARVPRINTF(buf,send,ap); bufl=l+1; - va_end(ap); - if (bufl>=sizeof(buf)-1) error("!Command too big (%d>%d)",bufl,sizeof(buf)-1); - if (verbose>=2) error(".devcmd(send=\"%s\",term=\"%s\",catch=\"%s\")",buf,term,catch); - buf[l]='\r'; buf[l+1]='\n'; - for (offs=0,got=0;offss && (s=memchr(s,'\r',buf+bufl-s))) *s='\n'; - catched(buf+bufl); assert(!record || record==buf+bufl); - assert(bufl=fragl) { - buf[bufl]='\0'; - assert(strlen(buf)==bufl); - /* d3(">%s|%s<\n",buf,term); */ - if (strstr(buf,ERROR_SUBSTR1) || strstr(buf,ERROR_SUBSTR2)) { - error("Found ERROR response on command \"%s\"",send); - goto err; - } - if (catch && bufl>=catchl && (hit=strstr(buf,catch))) { - record=hit+catchl; - catched(buf+bufl); assert(!record || record==buf+bufl); - } - if ( bufl>= terml && (hit=strstr(buf,term))) break; - memmove(buf,buf+bufl-(fragl-1),fragl-1); - bufl=fragl-1; - if (record) record=buf+bufl; - } - } - alarm(0); - if (!catchdatal) { - if (!catch) return(NULL); - error("Data requested on command \"%s\" but no found after term \"%s\"",send,term); - goto err; - } - assert(!!catch); - record=buf; - buf[0]='\0'; - catched(buf+1); - if (verbose>=2) error(".Returning data \"%s\" for cmd \"%s\"",catchdata,send); - return(catchdata); -} - -static int prepaddr(unsigned char *d,const char *addr) -{ -int tot=0; -char flip=0,plus; -unsigned char n; - - if ((plus=(*addr=='+'))) addr++; - *++d=(plus?ADDR_INT:ADDR_NAT); - while (*addr) { - if (*addr<'0' || *addr>'9') - error("!Error during conversion of number at: %s",addr); - tot++; - n=(*addr++)-'0'; - if ((flip=!flip)) *++d=0xF0|n; - else *d=(*d&0x0F)|(n<<4U); - } - return(tot); -} - -static char *finalsmsc; -#define SMSCBINSIZE (1+1+(MAXNUMLEN+1)/2) -static char pdusmsc[SMSCBINSIZE*2+1]; - -static inline char tohex(unsigned char x) -{ - x&=0x0F; - if (x<10) return(x +'0'); - return(x-10+'A'); -} - -static void textconv(char *d,unsigned char *s,size_t len) -{ - while (len--) { - *d++=tohex(*s>>4U); - *d++=tohex(*s ); - s++; - } - *d='\0'; -} - -static inline void smscset(void) -{ -char *s,*t,*e,*serr; -long l; -unsigned char bin[2+(MAXNUMLEN+1)/2]; - - if (smsc) devcmd(NULL,NULL,"\r\nAT+CSCA=\"%s\"",smsc); - s=devcmd(NULL,"\n+CSCA:","\r\nAT+CSCA?"); - while (isspace(*s)) s++; - if (!*s || !strcmp(s,"EMPTY")) - error("!No SMS set in A1 found"); - if (verbose>=1) error("\nFound default SMSC in A1: %s",s); - if (*s!='"') error("!No left-quote found in: %s",s); - if (!(t=strrchr(s+1,'"'))) error("!No right-quote found in: %s",s); - e=t++; - while (isspace(*t)) t++; - if (*t++!=',') error("!No comma found after quotes in: %s",s); - while (isspace(*t)) t++; - l=strtol(t,&serr,10); - if ((l!=ADDR_NAT && l!=ADDR_INT) || (serr && *serr)) - error("!Type parse error in: %s",s); - if (l==ADDR_NAT || s[1]=='+') s++; - else *s='+'; - *e='\0'; - chk(finalsmsc=strdup(s)); - if (verbose>=2) error("\nDecoded SMSC address: %s",finalsmsc); - bin[0]=1+(prepaddr(bin,finalsmsc)+1)/2; - textconv(pdusmsc,bin,bin[0]+1); -} - -static char *pdudata; - -static inline unsigned char charconv(char c,size_t offs) -{ - switch (c) { - case '@': return(0); - case '$': return(2); - case 0: assert(0); - default: - return(c&0x7F); - } -#if 0 - if ((c>='A' && c<='Z') || (c>='a' && c<='z') || (c>='0' && c<='9')) return(c); - error("Can't convert character '%c' (0x%02X) at offs %d (0-based), substituted '?'", - c,(unsigned char)c,offs); - return('?'); -#endif -} - -static inline void genpdu(void) -{ -static unsigned char pdu[64+MAXNUMLEN/2+(MAXBODYLEN*7)/8]; -unsigned char *d=pdu; -int i; -char inb=0,outb=0,xb; -unsigned char inreg; -size_t offs=0; - - *d++=PDU_TYPE; - *d++=PDU_MR; - i=prepaddr(d,phone); - *d=i; d+=1+1+(i+1)/2; - *d++=PDU_PID; - *d++=PDU_DCS; - *d++=PDU_VP; - if (bodylen>MAXBODYLEN) { - error("Body too large (%d>%d), cut",bodylen,MAXBODYLEN); - bodylen=MAXBODYLEN; - } - *d=bodylen; - assert(d0); assert(!!*body); - inreg=charconv(*body++,offs++); - bodylen--; - inb=7; - } - if (!outb) { - *++d=0x00; - outb=8; - } - xb=MIN(inb,outb); - d4("inb=%d,outb=%d,xb=%d\n",inb,outb,xb); - *d|=((inreg>>(unsigned)(7-inb))&((1<"); - if ((s=getenv("HOME"))) { -size_t l=strlen(s); -char *buf=malloc(l+50); - - memcpy(buf,s,l); - strcpy(buf+l,CONFIG_HOME); - readfile(buf,1); - free(buf); - } - readfile(CONFIG_MAIN,1); - - for (i=0;i=1) - error("\nPlease enter the SMS text body, end with EOF (ctrl-D):"); - } - else { - if (!(fin=fopen(finame,"rt"))) - error("!Can't open data file \"%s\" for r/o: %m",finame); - } - chk(body=malloc(BODYLOAD)); - bodylen=fread(body,1,BODYLOAD,fin); - if (bodylen==-1) - error("!Error reading stream \"%s\": %m",(finame?finame:"")); - if (finame) { - chkfclose(fin,finame); - free(finame); - } - } - - for (i=0;i=LONG_MAX || !serr || *serr) - error("!Number parse error for parameter \"%s\" of \"%s\" at: %s", - numarg[i].msg,*numarg[i].sp,serr); - } - - if (!strchr(device,'/')) { -size_t l=strlen(device); - chk(s=malloc(5+l+1)); - strcpy(s,"/dev/"); - strcpy(s+5,device); - free(device); - device=s; - } - devicename=strrchr(device,'/')+1; assert(!!(devicename-1)); - for (i=0,s=lockfile;*s;s++) { - if (*s!='%') continue; - s++; - if (*s=='%') continue; - if (*s=='s') { - if (i) error("!Only one \"%%s\" permitted in lockfile format-string"); - i=1; continue; - } - error("!Invalid format-character '%c' in lockfile format-string, only \"%%s\" allowed",*s); - } - - if (*logname) { - if (!(logf=fopen(logname,"a"))) - error("!Error opening log \"%s\" for append: %m",logname); - logmsg("Starting up: " PACKAGE " " VERSION); - } - genpdu(); - - if (lockfile && *lockfile && VARPRINTF(lockreal,lockfile,devicename)>0) { -time_t start,end; - if (verbose>=1) error(".Locking device \"%s\" by \"%s\"..",device,lockreal); - time(&start); - lockdevice(); - time(&end); - if ((end-=start)>LOCKREPORT) - logmsg("Device lock succeeded after %d seconds",end); - } - if (verbose>=1) error(".Opening device \"%s\"..",device); - if ((devfd=open(device,O_RDWR|O_NDELAY))<0) - error("!Cannot open device \"%s\" for rw-access: %m",device); - - if (tcgetattr(devfd,&restios)) - error("Unable to get termios settings: %m"); - else { - restios.c_cflag=(restios.c_cflag&~(CBAUD|CBAUDEX))|B0|HUPCL; - restios_yes=1; - } - tios.c_iflag=IGNBRK|IGNPAR|IXON|IXOFF; - tios.c_oflag=0; - tios.c_cflag=CS8|CREAD|CLOCAL|B19200|HUPCL; - tios.c_lflag=IEXTEN|NOFLSH; - memset(tios.c_cc,_POSIX_VDISABLE,sizeof(tios.c_cc)); - tios.c_cc[VTIME]=0; - tios.c_cc[VMIN ]=1; - cfsetispeed(&tios,B19200); - if (cfsetospeed(&tios,B19200)|cfsetispeed(&tios,B19200)) - error("Error setting termios baudrate on device: %m"); - if (tcflush(devfd,TCIOFLUSH)) - error("Error flushing termios (TCIOFLUSH) on device: %m"); - if (tcsetattr(devfd,TCSANOW,&tios)) - error("!Unable to set initial termios device settings: %m"); - - signal(SIGALRM,(RETSIGTYPE (*)(int))sigalarm); - do { - devcmd("",NULL,"\r\nAT\032"); - devcmd(NULL,NULL,"\r\nAT"); - smscset(); - devcmd(NULL,NULL,"\r\nAT+CMGF=0"); - devcmd("\n> ",NULL,"\r\nAT+CMGS=%d",(strlen(pdusmsc)+strlen(pdudata))/2); - if (!(s=devcmd(NULL,"\n+CMGS:","!%s%s\032",pdusmsc,pdudata))) retrying(); - } while (!s); - while (isspace(*s)) s++; - if (verbose>=1) error("\nMessage successfuly sent with MR: %s",s); - devcmd(NULL,NULL,"\r\nAT"); - - logmsg("SMS sent (after %d retries), message reference: %s",retrycnt,s); - return(EXIT_SUCCESS); -} diff --git a/setup.h b/setup.h deleted file mode 100644 index c057cb9..0000000 --- a/setup.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * $Id$ - */ - -#define CONFIG_MAIN "/etc/" PACKAGE "rc" /* global configuration file */ -#define CONFIG_HOME "/." PACKAGE "rc" /* user-local cfg file, - $HOME is prepended automatically */ -#define DEF_DEVICE "/dev/mobildock" /* --device default */ -#define DEF_LOGNAME "" /* --log default */ -#ifndef DEF_LOCKFILE -#define DEF_LOCKFILE "/var/lock/LCK..%s" /* --lockfile default */ -#endif -#define DEF_MAXRETRY 10 /* --maxretry default */ -#define DEF_READTIME 60*60 /* --readtime default */ -#define DEF_CHARTIME 10 /* --chartime default - (500ms per 80char=6.25ms recommended by Siemens */ -#define DEF_CMDTIME 500 /* --cmdtime default */ -#define MAXCONFIG 4096 /* maximum allowed size of any configuration file */ -#define MAXCFGARGS 256 /* maximum allowed number of arguments in cfg file */ -#define MAXCFGLOOP 5 /* maximum number of recursive opens in cfg files */ -#define MAXCFGNUM 20 /* total maximum number of cfgs read during one run */ -#define DEVLOCK_PERIOD 2 /* seconds between attempts to obtain a lockfile */ -#define DEVLOCK_MAXEMPTY 1 /* seconds to wait while lockfile is empty - to prevent races during lock creation */ -#define MAXSENDTIME 2 /* max. allowed number of seconds for sending one char */ -#define LOCKREPORT 15 /* report to logfile if device lock took more than - this parameter taken in seconds */ -#define ADDR_NAT 0x81 /* PDU address type for non-'+' numbers */ -#define ADDR_INT 0x91 /* PDU address type for numbers prefixed by '+' */ -#define PDU_TYPE 0x11 /* first byte of PDU, SMS submit */ -#define PDU_MR 0x00 /* default message reference, filled by Siemens A1 */ -#define PDU_PID 0x00 /* PDU protocol identifier, SMS message type */ -#define PDU_DCS 0x00 /* PDU Data Coding Scheme, 7-bit class-2 message */ -#define PDU_VP 0xFF /* PDU Validity Period, maximum relative time */ -#define MAXNUMLEN 20 /* maximum number of digits in GSM number */ -#define MAXBODYLEN 160 /* maximum length of characters in SMS body */ -#define BODYLOAD 200 /* number of bytes to read when body not on command line */ -#define ERROR_SUBSTR1 "ERROR" /* first failure ind. substring in A1 response */ -#define ERROR_SUBSTR2 "\nError:" /* second such, this one from MobilDock */ diff --git a/strdup.c b/strdup.c deleted file mode 100644 index f67630f..0000000 --- a/strdup.c +++ /dev/null @@ -1,20 +0,0 @@ -#include "config.h" -#ifndef lint -static char rcsid[] ATTR_UNUSED = "$Id$"; -#endif - -/* This part of code is a public domain */ - -#include -#include - -/* CONFORMING TO SVID 3, BSD 4.3 */ - -char *strdup(const char *s) -{ -size_t l; -char *d; - - if (!(d=malloc(l=strlen(s)+1))) return(NULL); - return memcpy(d,s,l); -} -- 1.8.3.1