- Changes for automake/autoconf added.

This commit is contained in:
michael 1998-06-17 12:20:35 +00:00
parent b0e5fa0996
commit eb148b7a10
6 changed files with 280 additions and 135 deletions

View File

@ -1,4 +1,4 @@
# $Id: Makefile,v 1.1 1998/06/10 13:31:48 michael Exp $
# $Id: Makefile,v 1.2 1998/06/17 12:20:35 michael Exp $
@ -34,6 +34,9 @@ voice.o: voice.h voice.c
tclscript.o: tclscript.h tclscript.c
$(CC) $(CFLAGS) -c tclscript.c
stringutils.o: stringutils.h stringutils.c
$(CC) $(CFLAGS) -c stringutils.c
#-- Modem library -------------------------------------------------------#
LIBVBOXMODEMOBJ = libvboxmodem.o
@ -49,7 +52,8 @@ VBOXGETTYOBJ = vboxgetty.o \
rc.o \
modem.o \
voice.o \
tclscript.o
tclscript.o \
stringutils.o
vboxgetty: $(VBOXGETTYOBJ)
$(CC) $(CFLAGS) $(VBOXGETTYOBJ) -o vboxgetty -L. -lvboxmodem -ldl -lm -ltcl

View File

@ -1,5 +1,5 @@
/*
** $Id: config.h,v 1.1 1998/06/10 13:31:49 michael Exp $
** $Id: config.h,v 1.2 1998/06/17 12:20:35 michael Exp $
**
** Copyright 1997-1998 by Michael 'Ghandi' Herold
*/
@ -12,6 +12,6 @@
#define VBOX_ETCDIR "/usr/local/etc"
#define VBOX_LIBDIR "/usr/local/lib"
#define VERSION "2.99.1"
#define VERSION "2.1.1"
#endif /* VBOX_CONFIG_H */

View File

@ -1,9 +1,12 @@
/*
** $Id: modem.c,v 1.1 1998/06/10 13:31:53 michael Exp $
** $Id: modem.c,v 1.2 1998/06/17 12:20:36 michael Exp $
**
** Copyright 1997-1998 by Michael Herold <michael@abadonna.mayn.de>
**
** $Log: modem.c,v $
** Revision 1.2 1998/06/17 12:20:36 michael
** - Changes for automake/autoconf added.
**
** Revision 1.1 1998/06/10 13:31:53 michael
** Source added.
**
@ -38,6 +41,7 @@ static struct modemsetup modemsetup =
{
4, /* Echo timeout (sec) */
4, /* Command timeout (sec) */
6, /* Ring timeout (sec) */
1800, /* Alive timeout (sec) */
400 /* Toggle DTR (ms) */
};
@ -48,7 +52,6 @@ static int timeoutstatus = 0;
static void modem_timeout_function(int);
static int modem_write(struct vboxmodem *, char *);
static int modem_read(struct vboxmodem *, char *, int);
static int modem_get_echo(struct vboxmodem *, char *);
static int modem_get_rawsequence(struct vboxmodem *, char *, int);
static int modem_check_result(char *, char *);
@ -270,6 +273,62 @@ int modem_command(struct vboxmodem *vbm, char *command, char *result)
return(0);
}
/*************************************************************************/
/** modem_read(): Reads a terminated string from the modem. **/
/*************************************************************************/
/** => vbm Pointer to modem structure **/
/** => line Pointer to write buffer **/
/** => readtimeout Timeout in seconds **/
/*************************************************************************/
int modem_read(struct vboxmodem *vbm, char *line, int readtimeout)
{
char c;
int r;
int timeout;
int linelen = 0;
int havetxt = 0;
log_line(LOG_D, "Reading modem answer (%ds timeout)...\n", readtimeout);
modem_set_timeout(readtimeout);
while (((r = vboxmodem_raw_read(vbm, &c, 1)) == 1) && (linelen < (VBOXMODEM_BUFFER_SIZE - 1)))
{
if (c >= 32) havetxt = 1;
if (havetxt)
{
if (c == '\n') break;
if ((c != '\r') && (c != '\n'))
{
*line++ = c;
linelen++;
}
}
if (modem_get_timeout()) break;
}
timeout = modem_get_timeout();
modem_set_timeout(0);
*line = 0;
if ((r != 1) || (timeout) || (linelen >= (VBOXMODEM_BUFFER_SIZE - 1)))
{
log_line(LOG_W, "Can't read from modem [%d]%s.\n", r, (timeout ? " (timeout)" : ""));
return(-1);
}
return(0);
}
/*************************************************************************/
/** **/
/*************************************************************************/
@ -366,60 +425,6 @@ static int modem_write(struct vboxmodem *vbm, char *s)
return(-1);
}
/*************************************************************************/
/** modem_read(): Reads a terminated string from the modem. **/
/*************************************************************************/
/** => vbm Pointer to modem structure **/
/** => line Pointer to write buffer **/
/** => readtimeout Timeout in seconds **/
/*************************************************************************/
static int modem_read(struct vboxmodem *vbm, char *line, int readtimeout)
{
char c;
int r;
int timeout;
int linelen = 0;
int havetxt = 0;
log_line(LOG_D, "Reading modem answer (%ds timeout)...\n", readtimeout);
modem_set_timeout(readtimeout);
while (((r = vboxmodem_raw_read(vbm, &c, 1)) == 1) && (linelen < (VBOXMODEM_BUFFER_SIZE - 1)))
{
if (c >= 32) havetxt = 1;
if (havetxt)
{
if (c == '\n') break;
if ((c != '\r') && (c != '\n'))
{
*line++ = c;
linelen++;
}
}
if (modem_get_timeout()) break;
}
timeout = modem_get_timeout();
modem_set_timeout(0);
*line = 0;
if ((r != 1) || (timeout) || (linelen >= (VBOXMODEM_BUFFER_SIZE - 1)))
{
log_line(LOG_W, "Can't read from modem [%d]%s.\n", r, (timeout ? " (timeout)" : ""));
return(-1);
}
return(0);
}
/*************************************************************************/
/** modem_get_echo(): Reads modem echo. **/

View File

@ -1,5 +1,5 @@
/*
** $Id: modem.h,v 1.1 1998/06/10 13:31:54 michael Exp $
** $Id: modem.h,v 1.2 1998/06/17 12:20:37 michael Exp $
**
** Copyright 1997-1998 by Michael 'Ghandi' Herold
*/
@ -23,6 +23,7 @@ struct modemsetup
{
int echotimeout;
int commandtimeout;
int ringtimeout;
int alivetimeout;
int toggle_dtr_time;
@ -44,5 +45,6 @@ extern int modem_hangup(struct vboxmodem *);
extern int modem_wait(struct vboxmodem *);
extern void modem_set_nocarrier(struct vboxmodem *, int);
extern int modem_get_nocarrier(struct vboxmodem *);
extern int modem_read(struct vboxmodem *, char *, int);
#endif /* _VBOX_MODEM_H */

View File

@ -1,9 +1,12 @@
/*
** $Id: vboxgetty.c,v 1.1 1998/06/10 13:31:58 michael Exp $
** $Id: vboxgetty.c,v 1.2 1998/06/17 12:20:37 michael Exp $
**
** Copyright 1997-1998 by Michael Herold <michael@abadonna.mayn.de>
**
** $Log: vboxgetty.c,v $
** Revision 1.2 1998/06/17 12:20:37 michael
** - Changes for automake/autoconf added.
**
** Revision 1.1 1998/06/10 13:31:58 michael
** Source added.
**
@ -23,6 +26,7 @@
#include "modem.h"
#include "rc.h"
#include "voice.h"
#include "stringutils.h"
#include "tclscript.h"
#include "vboxgetty.h"
@ -64,9 +68,11 @@ static int parse_getty_rc(unsigned char *);
static void show_usage(int, int);
static int process_incoming_call(void);
static int run_modem_init(void);
static int parse_user_rc(struct vboxincomingcall *);
/*************************************************************************/
/** **/
/** The magic main... **/
/*************************************************************************/
void main(int argc, char **argv)
@ -103,12 +109,12 @@ void main(int argc, char **argv)
break;
case 'v':
show_usage(1, 0);
show_usage(200, 0);
break;
case 'h':
default:
show_usage(1, 1);
show_usage(200, 1);
break;
}
}
@ -161,14 +167,14 @@ void main(int argc, char **argv)
{
fprintf(stderr, "\n%s: error: \"%s\" doesn't exist or is not accessable!\n\n", progbasename, temppathname);
quit_program(10);
quit_program(100);
}
}
else
{
fprintf(stderr, "\n%s: error: isdn tty name is required!\n", progbasename);
show_usage(10, 1);
show_usage(100, 1);
}
/* Check if we start with root privilegs. The permissions will be */
@ -179,7 +185,7 @@ void main(int argc, char **argv)
{
fprintf(stderr, "\n%s: error: need root privilegs to start!\n\n", progbasename);
quit_program(10);
quit_program(100);
}
/* Now its time to open the log. The name of the current tty will */
@ -196,7 +202,7 @@ void main(int argc, char **argv)
{
log_line(LOG_E, "Can't create/initialize the tcl interpreter!\n");
quit_program(10);
quit_program(100);
}
log_line(LOG_I, "Running vbox version %s (with tcl version %s).\n", VERSION, scr_tcl_version());
@ -208,9 +214,12 @@ void main(int argc, char **argv)
{
log_line(LOG_E, "Unable to read/parse configuration!\n");
quit_program(10);
quit_program(100);
}
/* Open modem device and do the main loop (initialize, wait, */
/* answer and alive check). */
printstring(temppathname, "/dev/%s", isdnttyname);
log_line(LOG_D, "Opening modem device \"%s\" (57600, CTS/RTS)...\n", temppathname);
@ -219,7 +228,7 @@ void main(int argc, char **argv)
{
log_line(LOG_E, "Can't open/setup modem device (%s).\n", vboxmodem_error());
quit_program(20);
quit_program(100);
}
signal(SIGINT , quit_program);
@ -236,7 +245,7 @@ signal(SIGTERM, quit_program);
if (run_modem_init() == -1)
{
if ((i = (int)vbox_strtol(rc_get_entry(rc_getty_c, "badinitsexit"), 10)) > 0)
if ((i = (int)xstrtol(rc_get_entry(rc_getty_c, "badinitsexit"), 10)) > 0)
{
modeminits++;
@ -306,6 +315,12 @@ signal(SIGTERM, quit_program);
quit_program(0);
}
/*************************************************************************/
/** quit_program(): Frees all used resources and exist. **/
/*************************************************************************/
/** => rc Exit return code (1-99 reserved for signals) **/
/*************************************************************************/
void quit_program(int rc)
{
modem_hangup(&vboxmodem);
@ -320,37 +335,11 @@ void quit_program(int rc)
exit(rc);
}
long vbox_strtol(char *string, long number)
{
long back;
char *stop;
if (string)
{
back = strtol(string, &stop, 10);
if (*stop == '\0') return(back);
log_line(LOG_W, "Can't convert \"%s\" to number (illegal)!\n", string);
}
else log_line(LOG_W, "Can't convert string to number (string empty)!\n");
return(number);
}
/*************************************************************************/
/** **/
/** show_usage(): Shows usage/version message. **/
/*************************************************************************/
/** => rc Exit return level (1-99 reserved for signals) **/
/** => help 1 shows help message, 0 version string **/
/*************************************************************************/
static void show_usage(int rc, int help)
@ -374,6 +363,32 @@ static void show_usage(int rc, int help)
exit(rc);
}
/*************************************************************************/
/** run_modem_init(): Starts the tcl script to initialize the modem. **/
/*************************************************************************/
/** <= 0 on success or -1 on error **/
/*************************************************************************/
static int run_modem_init(void)
{
struct vbox_tcl_variable vars[] =
{
{ "vbxv_init" , rc_get_entry(rc_getty_c, "init" ) },
{ "vbxv_initnumber" , rc_get_entry(rc_getty_c, "initnumber") },
{ NULL , NULL }
};
log_line(LOG_A, "Initializing modem...\n");
if (scr_init_variables(vars) == 0)
{
if (scr_execute("initmodem.tcl", NULL) == 0) return(0);
}
log_line(LOG_E, "Can't initialize modem!\n");
return(-1);
}
@ -435,30 +450,69 @@ static int parse_getty_rc(unsigned char *tty)
return(0);
}
/*************************************************************************/
/** run_modem_init(): Starts the tcl script to initialize the modem. **/
/*************************************************************************/
/** <= 0 on success or -1 on error **/
/** **/
/*************************************************************************/
static int run_modem_init(void)
static int process_incoming_call(void)
{
struct vbox_tcl_variable vars[] =
{
{ "vbxv_init" , rc_get_entry(rc_getty_c, "init" ) },
{ "vbxv_initnumber" , rc_get_entry(rc_getty_c, "initnumber") },
{ NULL , NULL }
};
struct vboxuser vboxuser;
log_line(LOG_A, "Initializing modem...\n");
char line[VBOXMODEM_BUFFER_SIZE + 1];
int haverings;
int waitrings;
int havesetup;
if (scr_init_variables(vars) == 0)
haverings = 0;
waitrings = 0;
havesetup = 0;
while (modem_read(&vboxmodem, line, (int)xstrtol(rc_get_entry(rc_getty_c, "ringtimeout"), 6)) == 0)
{
if (scr_execute("initmodem.tcl", NULL) == 0) return(0);
if ((strncmp(line, "CALLER NUMBER: ", 15) == 0) && (!havesetup))
{
xstrncpy(vboxuser.incomingid, &line[15], VBOX_CALL_ID);
xstrncpy(vboxuser.localphone, "9317840513", VBOX_CALL_NUMBER);
if (parse_user_rc(&vboxuser) == 0)
{
if ((vboxuser.uid == 0) || (vboxuser.gid == 0))
{
log_line(LOG_W, "No user for ID %s found - call will be ignored!\n", vboxcall.callerid);
}
havesetup = 1;
}
continue;
}
if (strcmp(line, "RING") == 0)
{
haverings++;
if (havesetup)
log_line(LOG_A, "RING #%03d (%s)...\n", haverings, incomingid);
else
log_line(LOG_A, "RING #%03d...\n", haverings);
}
else
{
log_line(LOG_D, "Got junk line \"");
log_code(LOG_D, line);
log_text(LOG_D, "\"...\n");
}
}
log_line(LOG_E, "Can't initialize modem!\n");
return(-1);
}
@ -466,8 +520,57 @@ static int run_modem_init(void)
/** **/
/*************************************************************************/
static int process_incoming_call(void)
static int parse_user_rc(struct vboxuser *vboxuser)
{
char line[VBOX_RCLINE_SIZE + 1];
FILE *rc;
char *stop;
int linenr;
log_line(LOG_D, "Searching local user for ID %s...\n", vboxuser->incomingid);
vboxuser->uid = 0;
vboxuser->gid = 0;
vboxuser->home[0] = 0
vboxuser->umask = -1;
vboxuser->space = -1;
printstring(temppathname, "%s/vboxgetty.user", VBOX_ETCDIR);
if ((rc = fopen(temppathname, "r")))
{
linenr = 0;
while (fgets(line, VBOX_RCLINE_SIZE, rc))
{
linenr++;
line[strlen(line) - 1] = '\0';
if ((stop = rindex(line, '#'))) *stop = '\0';
while (strlen(line) > 0)
{
if ((line[strlen(line) - 1] != ' ') && (line[strlen(line) - 1] != '\t')) break;
line[strlen(line) - 1] = '\0';
}
if (*line == '\0') continue;
pattern = strtok(line, ":");
name = strtok(NULL, ":");
group = strtok(NULL, ":");
mask = strtok(NULL, ":");
space = strtok(NULL, ":");
if ((!pattern) || (!name) || (!group) || (!mask) || (!space))
{
log_line(LOG_E, "Error in \"%s\" line %d.\n", temppathname, linenr);
fclose(rc);
return(-1);
}
@ -476,21 +579,30 @@ static int process_incoming_call(void)
}
fclose(rc);
}
else
{
log_line(LOG_W, "Can't open \"%s\".\n", temppathname);
return(-1);
}
return(0);
}

View File

@ -1,5 +1,5 @@
/*
** $Id: vboxgetty.h,v 1.1 1998/06/10 13:31:59 michael Exp $
** $Id: vboxgetty.h,v 1.2 1998/06/17 12:20:39 michael Exp $
**
** Copyright 1997-1998 by Michael 'Ghandi' Herold
*/
@ -10,18 +10,40 @@
#include <stdio.h>
#include <stdlib.h>
#include <limits.h>
#include <unistd.h>
#define VBOX_DEFAULT_SPOOLDIR "/var/spool/vbox"
#define VBOX_RCLINE_SIZE 255
#define VBOXUSER_CALLID 64
#define VBOXUSER_NUMBER 64
extern char temppathname[PATH_MAX + 1];
extern struct vboxmodem vboxmodem;
struct vboxuser
{
uid_t uid;
gid_t gid;
int umask;
long space;
char incomingid[VBOXUSER_CALLID + 1];
char localphone[VBOXUSER_NUMBER + 1];
char home[PATH_MAX + 1];
};
extern void quit_program(int);
extern long vbox_strtol(char *, long);
#define printstring sprintf