New format; we can also use bison if we want.
This commit is contained in:
parent
9cac8602cd
commit
a7848e0855
7 changed files with 115 additions and 17 deletions
|
@ -1,22 +1,24 @@
|
||||||
# cnd Makefile
|
# cnd Makefile
|
||||||
# (C)2005, Dan Ponte
|
# (C)2005, Dan Ponte
|
||||||
# $Amigan: phoned/phoned/Makefile,v 1.3 2005/06/01 01:11:23 dcp1990 Exp $
|
# $Amigan: phoned/phoned/Makefile,v 1.4 2005/06/01 20:31:50 dcp1990 Exp $
|
||||||
include ../global.mk
|
include ../global.mk
|
||||||
# basic stuff. we append for a reason.
|
# basic stuff. we append for a reason.
|
||||||
CPPFLAGS=-I../include -DDEBUG
|
CPPFLAGS=-I../include -DDEBUG -DYYERROR_VERBOSE
|
||||||
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS}
|
CFLAGS+=-g -Wall -W -ansi ${CPPFLAGS}
|
||||||
LDFLAGS=
|
LDFLAGS=-lutil
|
||||||
# keep these up to date.
|
# keep these up to date.
|
||||||
MAINBIN=phoned
|
MAINBIN=phoned
|
||||||
SRCS=main.c init.c log.c cfg.c socket.c y.tab.c lex.yy.c signals.c cid.c
|
SRCS=main.c init.c log.c cfg.c socket.c y.tab.c lex.yy.c signals.c cid.c modem.c
|
||||||
OBJS=main.o init.o log.o cfg.o socket.o y.tab.o lex.yy.o signals.o cid.o
|
OBJS=main.o init.o log.o cfg.o socket.o y.tab.o lex.yy.o signals.o cid.o modem.o
|
||||||
OHDRS=y.tab.h
|
OHDRS=y.tab.h
|
||||||
CLEANFILES=y.tab.c y.tab.h lex.yy.c
|
CLEANFILES=y.tab.c y.tab.h lex.yy.c
|
||||||
|
LEX=lex
|
||||||
|
YACC=yacc
|
||||||
|
|
||||||
include ../main.mk
|
include ../main.mk
|
||||||
|
|
||||||
y.tab.h: y.tab.c
|
y.tab.h: y.tab.c
|
||||||
y.tab.c: config.y
|
y.tab.c: config.y
|
||||||
yacc -d config.y
|
$(YACC) -d config.y
|
||||||
lex.yy.c: config.l y.tab.c y.tab.h
|
lex.yy.c: config.l y.tab.c y.tab.h
|
||||||
lex config.l
|
$(LEX) config.l
|
||||||
|
|
|
@ -1,15 +1,24 @@
|
||||||
/* configuration lexer */
|
/* configuration lexer */
|
||||||
%{
|
%{
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
#ifdef BISON
|
||||||
|
#include "config.tab.h"
|
||||||
|
#else
|
||||||
#include "y.tab.h"
|
#include "y.tab.h"
|
||||||
|
#endif
|
||||||
#include <phoned.h>
|
#include <phoned.h>
|
||||||
extern int chrcnt, lincnt;
|
extern int chrcnt, lincnt;
|
||||||
%}
|
%}
|
||||||
%%
|
%%
|
||||||
. ++chrcnt; REJECT;
|
. ++chrcnt; REJECT;
|
||||||
|
main return MAIN;
|
||||||
notify return NOTIFY;
|
notify return NOTIFY;
|
||||||
|
modemdev return MODDEV;
|
||||||
|
\" return QUOTE;
|
||||||
\{ return OBRACE;
|
\{ return OBRACE;
|
||||||
\} return CBRACE;
|
\} return CBRACE;
|
||||||
|
\/[a-zA-Z0-9/._-]+ yylval.string = strdup(yytext); return PATH;
|
||||||
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string = strdup(yytext); return IPADDR;
|
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3} yylval.string = strdup(yytext); return IPADDR;
|
||||||
; return SCOLON;
|
; return SCOLON;
|
||||||
\n chrcnt = 0; ++lincnt;/* DONOTHING */
|
\n chrcnt = 0; ++lincnt;/* DONOTHING */
|
||||||
|
|
|
@ -7,15 +7,17 @@
|
||||||
%{
|
%{
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdlib.h>
|
||||||
#include <phoned.h>
|
#include <phoned.h>
|
||||||
int chrcnt = 0;
|
int chrcnt = 0;
|
||||||
int lincnt = 0;
|
int lincnt = 1;
|
||||||
int yylex(void);
|
int yylex(void);
|
||||||
|
extern char* yytext;
|
||||||
void yyerror(str)
|
void yyerror(str)
|
||||||
char* str;
|
char* str;
|
||||||
{
|
{
|
||||||
lprintf(fatal, "parser: error: %s at line %d chr %d\n", str, lincnt,
|
lprintf(fatal, "parser: error: %s at line %d chr %d (near %s)\n", str,
|
||||||
chrcnt);
|
lincnt, chrcnt, yytext);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
int yywrap(void)
|
int yywrap(void)
|
||||||
|
@ -23,15 +25,33 @@ int yywrap(void)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
%}
|
%}
|
||||||
%token NOTIFY OBRACE CBRACE SCOLON
|
%token NOTIFY OBRACE CBRACE SCOLON QUOTE MODDEV MAIN
|
||||||
%token <string> IPADDR
|
%token <string> IPADDR PATH
|
||||||
%%
|
%%
|
||||||
commands:
|
commands:
|
||||||
|
|
|
|
||||||
command commands SCOLON
|
command SCOLON commands
|
||||||
;
|
;
|
||||||
command:
|
command:
|
||||||
notify
|
notify
|
||||||
|
|
|
||||||
|
main
|
||||||
|
;
|
||||||
|
main:
|
||||||
|
MAIN params
|
||||||
|
{
|
||||||
|
lprintf(info, "parser: end main\n");
|
||||||
|
}
|
||||||
|
;
|
||||||
|
params:
|
||||||
|
OBRACE directives CBRACE
|
||||||
|
;
|
||||||
|
directives:
|
||||||
|
|
|
||||||
|
directives directive SCOLON
|
||||||
|
;
|
||||||
|
directive:
|
||||||
|
modemdev
|
||||||
;
|
;
|
||||||
notify:
|
notify:
|
||||||
NOTIFY iplist
|
NOTIFY iplist
|
||||||
|
@ -52,4 +72,16 @@ ipadr:
|
||||||
lprintf(debug, "Encountered ipaddress %s\n", $1);
|
lprintf(debug, "Encountered ipaddress %s\n", $1);
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
|
modemdev:
|
||||||
|
MODDEV devpath
|
||||||
|
{
|
||||||
|
lprintf(info, "parser: end modemdev\n");
|
||||||
|
}
|
||||||
|
;
|
||||||
|
devpath:
|
||||||
|
QUOTE PATH QUOTE
|
||||||
|
{
|
||||||
|
lprintf(debug, "Modem dev == %s\n", $2);
|
||||||
|
}
|
||||||
|
;
|
||||||
%%
|
%%
|
||||||
|
|
|
@ -23,11 +23,14 @@ void shutd(void)
|
||||||
|
|
||||||
void open_logs(void)
|
void open_logs(void)
|
||||||
{
|
{
|
||||||
|
if(strcmp(difflog ? cf.logfile : LOGFILE, "-") == 0) logf = stderr;
|
||||||
|
else {
|
||||||
logf = fopen(difflog ? cf.logfile : LOGFILE, "a");
|
logf = fopen(difflog ? cf.logfile : LOGFILE, "a");
|
||||||
if(!logf) {
|
if(!logf) {
|
||||||
perror("logf open");
|
perror("logf open");
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
lprintf(info, "phoned v" VERSION " starting..\n");
|
lprintf(info, "phoned v" VERSION " starting..\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,3 +28,49 @@
|
||||||
* SUCH DAMAGE.
|
* SUCH DAMAGE.
|
||||||
*/
|
*/
|
||||||
/* system includes */
|
/* system includes */
|
||||||
|
#include <fcntl.h>
|
||||||
|
#include <ctype.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <signal.h>
|
||||||
|
#include <termios.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <time.h>
|
||||||
|
#include <libutil.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <sys/select.h>
|
||||||
|
#include <sys/ioctl.h>
|
||||||
|
#include <sys/types.h>
|
||||||
|
#include <errno.h>
|
||||||
|
#include <phoned.h>
|
||||||
|
#define INITSTRING "ATZ\r\nAT E0 #CID=2 V0\r\n"
|
||||||
|
/* globals */
|
||||||
|
FILE* modem;
|
||||||
|
int modemfd;
|
||||||
|
void stmod(const char* str)
|
||||||
|
{
|
||||||
|
fputs(str, modem);
|
||||||
|
fflush(modem);
|
||||||
|
}
|
||||||
|
int init_modem(char* dev)
|
||||||
|
{
|
||||||
|
int lres = 0;
|
||||||
|
modemfd = open(dev, O_RDWR);
|
||||||
|
if(!modemfd) {
|
||||||
|
lprintf(error, "Error opening modem %s: %s\n", dev, strerror(errno));
|
||||||
|
return -2;
|
||||||
|
}
|
||||||
|
lres = uu_lock((dev+(sizeof("/dev/")-1)));
|
||||||
|
if(lres != 0) {
|
||||||
|
lprintf(error, "%s\n", uu_lockerr(lres));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
modem = fdopen(modemfd, "w+");
|
||||||
|
if(!modem) {
|
||||||
|
lprintf(error, "Error fdopening modemfd %d: %s\n", modemfd, strerror(errno));
|
||||||
|
return -3;
|
||||||
|
}
|
||||||
|
stmod(INITSTRING);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
main {
|
||||||
|
modemdev "/dev/ttyd0";
|
||||||
|
};
|
||||||
notify {
|
notify {
|
||||||
10.10.10.13;
|
10.10.10.13;
|
||||||
10.10.10.1;
|
10.10.10.1;
|
||||||
|
|
|
@ -45,6 +45,9 @@
|
||||||
|
|
||||||
#include <phoned.h>
|
#include <phoned.h>
|
||||||
|
|
||||||
|
extern int modemfd;
|
||||||
|
extern FILE* modem;
|
||||||
|
|
||||||
void handclient(sk)
|
void handclient(sk)
|
||||||
int sk;
|
int sk;
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in a new issue