aboutsummaryrefslogtreecommitdiffstats
path: root/console
diff options
context:
space:
mode:
authorGerd Hoffmann <kraxel@redhat.com>2010-04-01 09:24:39 (GMT)
committerGerd Hoffmann <kraxel@redhat.com>2010-04-01 09:24:39 (GMT)
commitbc7f101b0c874e21473aca15d9b08de8bd164392 (patch)
tree878e2a671f9bd0b3401383406a513c8056f25e17 /console
parenta4a3e6b21da7d11e66364ab9ab67795a3f78020a (diff)
v3.75
Diffstat (limited to 'console')
-rw-r--r--console/Subdir.mk75
-rw-r--r--console/fbtools.c55
-rw-r--r--console/fbtools.h2
-rw-r--r--console/fbtv.c23
-rw-r--r--console/ftp.c131
-rw-r--r--console/ftp.h14
-rw-r--r--console/scantv.c117
-rw-r--r--console/ttv.c (renamed from console/aa.c)0
-rw-r--r--console/vbi-tty.c285
-rw-r--r--console/vbi-tty.h1
-rw-r--r--console/webcam.c453
11 files changed, 787 insertions, 369 deletions
diff --git a/console/Subdir.mk b/console/Subdir.mk
index 016ef0f..8f166d4 100644
--- a/console/Subdir.mk
+++ b/console/Subdir.mk
@@ -1,14 +1,17 @@
-# variables
+# targets to build
TARGETS-console := \
console/dump-mixers \
console/record \
- console/scantv \
console/showriff \
console/streamer \
console/webcam
TARGETS-v4l-conf :=
+ifeq ($(FOUND_ZVBI),yes)
+TARGETS-console += \
+ console/scantv
+endif
ifeq ($(FOUND_AALIB),yes)
TARGETS-console += \
console/ttv
@@ -21,7 +24,8 @@ TARGETS-v4l-conf += \
console/v4l-conf
endif
-OBJS-fbtv := \
+# objects for targets
+console/fbtv: \
console/fbtv.o \
console/fbtools.o \
console/fs.o \
@@ -29,65 +33,53 @@ OBJS-fbtv := \
common/channel-no-x11.o \
$(OBJS-common-input) \
$(OBJS-common-capture)
-LIBS-fbtv := \
- $(THREAD_LIBS) $(CURSES_LIBS) $(LIRC_LIBS) $(ALSA_LIBS) \
- $(FS_LIBS) -ljpeg -lm
-OBJS-ttv := \
- console/aa.o \
+console/ttv: \
+ console/ttv.o \
common/channel-no-x11.o \
$(OBJS-common-capture)
-LIBS-ttv := \
- $(THREAD_LIBS) $(AA_LIBS) -ljpeg -lm
-OBJS-scantv := \
+console/scantv: \
console/scantv.o \
+ common/vbi-data.o \
common/channel-no-x11.o \
- $(OBJS-common-capture) \
- libvbi/libvbi.a
-OBJS-streamer := \
+ $(OBJS-common-capture)
+
+console/streamer: \
console/streamer.o \
common/channel-no-x11.o \
$(OBJS-common-capture)
-LIBS-capture := \
- $(THREAD_LIBS) -ljpeg -lm
-OBJS-webcam := \
+console/webcam: \
console/webcam.o \
console/ftp.o \
common/parseconfig.o \
libng/libng.a
-LIBS-webcam := \
- $(THREAD_LIBS) -ljpeg
-# local targets
console/dump-mixers: console/dump-mixers.o
console/showriff: console/showriff.o
-
console/radio: console/radio.o
- $(CC) $(CFLAGS) -o $@ $< $(CURSES_LIBS)
-
console/record: console/record.o
- $(CC) $(CFLAGS) -o $@ $< $(CURSES_LIBS)
-
console/v4l-conf: console/v4l-conf.o
- $(CC) $(CFLAGS) -o $@ $< $(ATHENA_LIBS)
-
-console/fbtv: $(OBJS-fbtv)
- $(CC) $(CFLAGS) -o $@ $(OBJS-fbtv) $(LIBS-fbtv) $(DLFLAGS)
-
-console/scantv: $(OBJS-scantv)
- $(CC) $(CFLAGS) -o $@ $(OBJS-scantv) $(LIBS-capture) $(DLFLAGS)
-
-console/streamer: $(OBJS-streamer)
- $(CC) $(CFLAGS) -o $@ $(OBJS-streamer) $(LIBS-capture) $(DLFLAGS)
-
-console/webcam: $(OBJS-webcam)
- $(CC) $(CFLAGS) -o $@ $(OBJS-webcam) $(LIBS-webcam) $(DLFLAGS)
-
-console/ttv: $(OBJS-ttv)
- $(CC) $(CFLAGS) -o $@ $(OBJS-ttv) $(LIBS-ttv) $(DLFLAGS)
+# libraries to link
+console/fbtv : LDLIBS := \
+ $(THREAD_LIBS) $(CURSES_LIBS) $(LIRC_LIBS) $(ALSA_LIBS) \
+ $(FS_LIBS) -ljpeg -lm
+console/ttv : LDLIBS := $(THREAD_LIBS) $(AA_LIBS) -ljpeg -lm
+console/scantv : LDLIBS := $(THREAD_LIBS) $(VBI_LIBS) -ljpeg
+console/streamer : LDLIBS := $(THREAD_LIBS) -ljpeg -lm
+console/webcam : LDLIBS := $(THREAD_LIBS) -ljpeg
+console/radio : LDLIBS := $(CURSES_LIBS)
+console/record : LDLIBS := $(CURSES_LIBS)
+console/v4l-conf : LDLIBS := $(ATHENA_LIBS)
+
+# linker flags
+console/fbtv : LDFLAGS := $(DLFLAGS)
+console/ttv : LDFLAGS := $(DLFLAGS)
+console/scantv : LDFLAGS := $(DLFLAGS)
+console/streamer : LDFLAGS := $(DLFLAGS)
+console/webcam : LDFLAGS := $(DLFLAGS)
# global targets
all:: $(TARGETS-console) $(TARGETS-v4l-conf)
@@ -100,4 +92,3 @@ endif
distclean::
rm -f $(TARGETS-console) $(TARGETS-v4l-conf)
-
diff --git a/console/fbtools.c b/console/fbtools.c
index b6a53a8..b094aa5 100644
--- a/console/fbtools.c
+++ b/console/fbtools.c
@@ -11,7 +11,7 @@
#include <termios.h>
#include <signal.h>
#include <errno.h>
-#include <signal.h>
+#include <setjmp.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/wait.h>
@@ -460,29 +460,42 @@ fb_cleanup(void)
close(tty);
}
+/* -------------------------------------------------------------------- */
+/* handle fatal errors */
+
+static jmp_buf fb_fatal_cleanup;
+
+static void
+fb_catch_exit_signal(int signal)
+{
+ siglongjmp(fb_fatal_cleanup,signal);
+}
+
void
-fb_cleanup_fork()
+fb_catch_exit_signals(void)
{
- int status;
-
- switch (fork()) {
- case -1:
- fb_cleanup();
- perror("fork");
- exit(1);
- case 0:
- return;
- }
+ struct sigaction act,old;
+ int termsig;
- signal(SIGINT, SIG_IGN);
- signal(SIGTSTP,SIG_IGN);
- signal(SIGTERM,SIG_IGN);
- signal(SIGUSR1,SIG_IGN);
- signal(SIGUSR2,SIG_IGN);
+ memset(&act,0,sizeof(act));
+ act.sa_handler = fb_catch_exit_signal;
+ sigemptyset(&act.sa_mask);
+ sigaction(SIGINT, &act,&old);
+ sigaction(SIGQUIT,&act,&old);
+ sigaction(SIGTERM,&act,&old);
+
+ sigaction(SIGABRT,&act,&old);
+ sigaction(SIGTSTP,&act,&old);
+
+ sigaction(SIGBUS, &act,&old);
+ sigaction(SIGILL, &act,&old);
+ sigaction(SIGSEGV,&act,&old);
+
+ if (0 == (termsig = sigsetjmp(fb_fatal_cleanup,0)))
+ return;
- wait(&status);
+ /* cleanup */
fb_cleanup();
- if (WIFSIGNALED(status))
- fprintf(stderr,"Oops: %s\n",sys_siglist[WTERMSIG(status)]);
- exit(status);
+ fprintf(stderr,"Oops: %s\n",sys_siglist[termsig]);
+ exit(42);
}
diff --git a/console/fbtools.h b/console/fbtools.h
index 090fa01..a501c2f 100644
--- a/console/fbtools.h
+++ b/console/fbtools.h
@@ -13,7 +13,7 @@ extern int fb_switch_state;
/* init + cleanup */
int fb_init(char *device, char *mode, int vt);
void fb_cleanup(void);
-void fb_cleanup_fork(void);
+void fb_catch_exit_signals(void);
void fb_memset(void *addr, int c, size_t len);
/* console switching */
diff --git a/console/fbtv.c b/console/fbtv.c
index 95e8b6f..5eb9c7c 100644
--- a/console/fbtv.c
+++ b/console/fbtv.c
@@ -581,6 +581,8 @@ main(int argc, char *argv[])
time_t t;
char text[80],event[64],*env,*dst;
fd_set set;
+ struct sigaction act,old;
+
if (0 == geteuid() && 0 != getuid()) {
fprintf(stderr,"fbtv /must not/ be installed suid root\n");
@@ -659,7 +661,7 @@ main(int argc, char *argv[])
do_overlay = 1;
text_init(fontfile);
fb = fb_init(fbdev,mode,vt);
- fb_cleanup_fork();
+ fb_catch_exit_signals();
fb_initcolors(fb,gray);
fb_switch_init();
switch_last = fb_switch_state;
@@ -687,9 +689,10 @@ main(int argc, char *argv[])
fullscreen_hook = do_fullscreen;
tty_init();
- atexit(tty_cleanup);
- signal(SIGINT,ctrlc);
- signal(SIGTSTP,SIG_IGN);
+ memset(&act,0,sizeof(act));
+ act.sa_handler = ctrlc;
+ sigemptyset(&act.sa_mask);
+ sigaction(SIGINT,&act,&old);
/* init hardware */
attr_init();
@@ -764,7 +767,7 @@ main(int argc, char *argv[])
t1 = time(NULL);
fps = 0;
message[0] = '\0';
- for (;;) {
+ for (;!sig;) {
FD_ZERO(&set);
FD_SET(0,&set);
fdmax = 1;
@@ -812,8 +815,10 @@ main(int argc, char *argv[])
err = errno;
if (switch_last != fb_switch_state)
console_switch();
- if (-1 == rc && EINTR == err)
+ if (-1 == rc && EINTR == err) {
+ FD_ZERO(&set);
continue;
+ }
if (rc > 0)
break;
t2 = time(NULL);
@@ -899,7 +904,9 @@ main(int argc, char *argv[])
if (mute)
audio_off();
drv->close(h_drv);
- fb_memset(fb_mem+fb_mem_offset,0,fb_fix.smem_len);
- /* parent will clean up */
+ if (fb_switch_state == FB_ACTIVE)
+ fb_memset(fb_mem+fb_mem_offset,0,fb_fix.smem_len);
+ tty_cleanup();
+ fb_cleanup();
exit(0);
}
diff --git a/console/ftp.c b/console/ftp.c
index 29c8f59..b9720da 100644
--- a/console/ftp.c
+++ b/console/ftp.c
@@ -1,5 +1,5 @@
/*
- * (c) 1998-2000 Gerd Knorr
+ * (c) 1998-2002 Gerd Knorr
*
* functions to handle ftp uploads using the ftp utility
*
@@ -14,20 +14,23 @@
#include <errno.h>
#include <fcntl.h>
#include <stdarg.h>
+#include <signal.h>
#include "ftp.h"
/* ---------------------------------------------------------------------- */
/* FTP stuff */
-int ftp_connected;
-int ftp_debug;
-
-static int ftp_pty, ftp_pid;
-static char tty_name[32];
+struct ftp_state {
+ char *name;
+ int connected;
+ int debug;
+ int pty, pid;
+ char tty_name[32];
+};
static
-int open_pty(void)
+int open_pty(struct ftp_state *s)
{
#ifdef HAVE_GETPT
int master;
@@ -41,7 +44,7 @@ int open_pty(void)
close(master);
return -1;
}
- strcpy(tty_name,slave);
+ strcpy(s->tty_name,slave);
return master;
#else
static char pty_name[32];
@@ -54,8 +57,8 @@ int open_pty(void)
for (p1 = s1; *p1; p1++) {
for (p2 = s2; *p2; p2++) {
sprintf(pty_name,"/dev/pty%c%c",*p1,*p2);
- sprintf(tty_name,"/dev/tty%c%c",*p1,*p2);
- if (-1 == access(tty_name,R_OK|W_OK))
+ sprintf(s->tty_name,"/dev/tty%c%c",*p1,*p2);
+ if (-1 == access(s->tty_name,R_OK|W_OK))
continue;
if (-1 != (pty = open(pty_name,O_RDWR)))
return pty;
@@ -65,31 +68,33 @@ int open_pty(void)
#endif
}
-void
-ftp_init(int autologin, int passive)
+struct ftp_state* ftp_init(char *name, int autologin, int passive, int debug)
{
static char *doauto[] = { "ftp", NULL }; /* allow autologin via ~/.netrc */
static char *noauto[] = { "ftp", "-n", NULL };
+ struct ftp_state *s;
- if (-1 == (ftp_pty = open_pty())) {
+ s = malloc(sizeof(*s));
+ memset(s,0,sizeof(*s));
+ s->name = name;
+ s->debug = debug;
+ if (-1 == (s->pty = open_pty(s))) {
fprintf(stderr,"can't grab pty\n");
exit(1);
}
- switch (ftp_pid = fork()) {
+ switch (s->pid = fork()) {
case -1:
perror("fork");
exit(1);
case 0:
/* child */
- close(ftp_pty);
+ close(s->pty);
close(0); close(1); close(2);
setsid();
- open(tty_name,O_RDWR); dup(0); dup(0);
+ open(s->tty_name,O_RDWR); dup(0); dup(0);
/* need english messages from ftp */
- unsetenv("LANG");
- unsetenv("LC_ALL");
- unsetenv("LC_MESSAGES");
+ setenv("LC_ALL","C",1);
if (autologin)
execvp(doauto[0],doauto);
@@ -101,18 +106,18 @@ ftp_init(int autologin, int passive)
/* parent */
break;
}
- ftp_recv();
+ ftp_recv(s);
/* initialisation */
if (passive) {
- ftp_send(1,"pass");
- ftp_recv();
+ ftp_send(s,1,"pass");
+ ftp_recv(s);
}
- return;
+ return s;
}
void
-ftp_send(int argc, ...)
+ftp_send(struct ftp_state *s, int argc, ...)
{
va_list ap;
char line[256],*arg;
@@ -131,16 +136,16 @@ ftp_send(int argc, ...)
line[length++] = '\n';
va_end (ap);
- if (ftp_debug)
- fprintf(stderr,">> %s",line);
- if (length != write(ftp_pty,line,length)) {
+ if (s->debug)
+ fprintf(stderr,"[%s]>> %s",s->name,line);
+ if (length != write(s->pty,line,length)) {
fprintf(stderr,"ftp: write error\n");
exit(1);
}
}
int
-ftp_recv()
+ftp_recv(struct ftp_state *s)
{
char line[512],*p,*n;
int length, done, status, ret=0;
@@ -148,10 +153,10 @@ ftp_recv()
for (done = 0; !done;) {
FD_ZERO(&set);
- FD_SET(ftp_pty,&set);
- select(ftp_pty+1,&set,NULL,NULL,NULL);
+ FD_SET(s->pty,&set);
+ select(s->pty+1,&set,NULL,NULL,NULL);
- switch (length = read(ftp_pty,line,511)) {
+ switch (length = read(s->pty,line,511)) {
case -1:
perror("ftp: read error");
exit(1);
@@ -167,8 +172,8 @@ ftp_recv()
*(n++) = 0;
else
n = NULL;
- if (ftp_debug)
- fprintf(stderr,"<< %s\n",p);
+ if (s->debug)
+ fprintf(stderr,"[%s]<< %s\n",s->name,p);
/* prompt? */
if (NULL != strstr(p,"ftp>")) {
@@ -178,12 +183,12 @@ ftp_recv()
/* line dropped ? */
if (NULL != strstr(p,"closed connection")) {
fprintf(stderr,"ftp: lost connection\n");
- ftp_connected = 0;
+ s->connected = 0;
}
if (NULL != strstr(p,"Not connected")) {
if (ftp_connected)
fprintf(stderr,"ftp: lost connection\n");
- ftp_connected = 0;
+ s->connected = 0;
}
/* status? */
@@ -196,7 +201,7 @@ ftp_recv()
}
void
-ftp_connect(char *host, char *user, char *pass, char *dir)
+ftp_connect(struct ftp_state *s, char *host, char *user, char *pass, char *dir)
{
int delay = 0, status;
@@ -213,24 +218,24 @@ ftp_connect(char *host, char *user, char *pass, char *dir)
}
/* (re-) connect */
- ftp_send(1,"close");
- ftp_recv();
- ftp_send(2,"open",host);
- status = ftp_recv();
+ ftp_send(s,1,"close");
+ ftp_recv(s);
+ ftp_send(s,2,"open",host);
+ status = ftp_recv(s);
if (230 == status) {
fprintf(stderr,"ftp: connected to %s, login ok\n",host);
- ftp_connected = 1;
+ s->connected = 1;
goto login_ok;
}
if (220 != status && 530 != status)
continue;
fprintf(stderr,"ftp: connected to %s\n",host);
- ftp_connected = 1;
+ s->connected = 1;
/* login */
- ftp_send(3,"user",user,pass);
- if (230 != ftp_recv()) {
+ ftp_send(s,3,"user",user,pass);
+ if (230 != ftp_recv(s)) {
if (!ftp_connected)
continue;
fprintf(stderr,"ftp: login incorrect\n");
@@ -239,30 +244,44 @@ ftp_connect(char *host, char *user, char *pass, char *dir)
login_ok:
/* set directory */
- ftp_send(2,"cd",dir);
- if (250 != ftp_recv()) {
- if (!ftp_connected)
+ ftp_send(s,2,"cd",dir);
+ if (250 != ftp_recv(s)) {
+ if (!s->connected)
continue;
fprintf(stderr,"ftp: cd %s failed\n",dir);
exit(1);
}
/* initialisation */
- ftp_send(1,"bin");
- ftp_recv();
- ftp_send(1,"umask 022");
- ftp_recv();
+ ftp_send(s,1,"bin");
+ ftp_recv(s);
+ ftp_send(s,1,"umask 022");
+ ftp_recv(s);
/* ok */
break;
}
}
+int ftp_connected(struct ftp_state *s)
+{
+ return s->connected;
+}
+
void
-ftp_upload(char *local, char *remote, char *tmp)
+ftp_upload(struct ftp_state *s, char *local, char *remote, char *tmp)
+{
+ ftp_send(s,3,"put",local,tmp);
+ ftp_recv(s);
+ ftp_send(s,3,"rename",tmp,remote);
+ ftp_recv(s);
+}
+
+void ftp_fini(struct ftp_state *s)
{
- ftp_send(3,"put",local,tmp);
- ftp_recv();
- ftp_send(3,"rename",tmp,remote);
- ftp_recv();
+ ftp_send(s,1,"bye");
+ ftp_recv(s);
+ kill(s->pid,SIGTERM);
+ close(s->pty);
+ free(s);
}
diff --git a/console/ftp.h b/console/ftp.h
index f11bfdb..844087d 100644
--- a/console/ftp.h
+++ b/console/ftp.h
@@ -1,8 +1,10 @@
-extern int ftp_connected;
extern int ftp_debug;
-void ftp_init(int autologin, int passive);
-void ftp_send(int argc, ...);
-int ftp_recv(void);
-void ftp_connect(char *host, char *user, char *pass, char *dir);
-void ftp_upload(char *local, char *remote, char *tmp);
+struct ftp_state* ftp_init(char *name, int autologin, int passive, int debug);
+void ftp_send(struct ftp_state* s, int argc, ...);
+int ftp_recv(struct ftp_state* s);
+void ftp_connect(struct ftp_state* s, char *host,
+ char *user, char *pass, char *dir);
+int ftp_connected(struct ftp_state *s);
+void ftp_upload(struct ftp_state* s, char *local, char *remote, char *tmp);
+void ftp_fini(struct ftp_state *s);
diff --git a/console/scantv.c b/console/scantv.c
index 118704a..9447eef 100644
--- a/console/scantv.c
+++ b/console/scantv.c
@@ -21,21 +21,13 @@
#include "grab-ng.h"
#include "commands.h"
-/* libvbi */
-#include "vt.h"
-#include "misc.h"
-#include "fdset.h"
-#include "vbi.h"
-#include "lang.h"
-#include "dllist.h"
+#include "vbi-data.h"
int debug = 0;
int have_dga = 0;
int timeout = 3;
-char xpacket[64];
-char header[64];
-char scratch[1024*256];
+char *tvname;
/*---------------------------------------------------------------------*/
@@ -52,80 +44,36 @@ grabber_init(void)
}
static void
-event(struct dl_head *reqs, struct vt_event *ev)
+event(struct vbi_event *ev, void *user)
{
- unsigned char *p;
- struct vt_page *vtp;
-
switch (ev->type) {
- case EV_HEADER:
- p = ev->p1;
- if (debug)
- fprintf(stderr,"header %.32s\n", p+8);
- memcpy(header,p+8,32);
- header[32] = 0;
- break;
- case EV_PAGE:
- vtp = ev->p1;
- if (debug)
- fprintf(stderr,"vtx page %x.%02x \r", vtp->pgno, vtp->subno);
- break;
- case EV_XPACKET:
- p = ev->p1;
- if (debug)
- fprintf(stderr,"xpacket %x %x %x %x - %.20s\n",
- p[0],p[1],p[3],p[5],p+20);
- memcpy(xpacket,p+20,20);
- xpacket[20] = 0;
+ case VBI_EVENT_NETWORK:
+ if (NULL != tvname)
+ free(tvname);
+ if (strlen(ev->ev.network.name) > 0)
+ tvname = strdup(ev->ev.network.name);
break;
}
}
static char*
-get_vbi_name(void)
+get_vbi_name(struct vbi_state *vbi)
{
int start;
- char *name,*h;
- xpacket[0] = 0;
- header[0] = 0;
+ vbi_hasdata(vbi);
+ if (NULL != tvname)
+ free(tvname);
+ tvname = NULL;
start = time(NULL);
for (;;) {
- if (fdset_select(fds, 1000 * timeout) == 0) {
- break;
- }
- if (time(NULL) > start+timeout) {
- break;
- }
- if (xpacket[0] && header[0]) {
- break;
- }
- }
- if (xpacket[0]) {
- for (h = xpacket+19; h >= xpacket; h--) {
- if (32 != *h)
- break;
- *h = 0;
- }
- for (name = xpacket; *name == 32; name++)
- ;
- return name;
- }
-#if 0
- if (header[0]) {
- for (name = header; *name && name < header+20; name++)
- if (isalpha(*name))
- break;
- for (h = name; *name && name < header+20; name++)
- if (!isalpha(*h)) {
- *h = 0;
- break;
- }
- if (*name)
- return name;
+ vbi_hasdata(vbi);
+ if (time(NULL) > start+timeout)
+ break;
+ if (tvname)
+ break;
}
-#endif
- return NULL;
+ return tvname;
}
static int
@@ -181,7 +129,7 @@ usage(FILE *out, char *prog, char *outfile)
int
main(int argc, char **argv)
{
- struct vbi *vbi;
+ struct vbi_state *vbi;
struct ng_attribute *attr;
int c,f,f1,f2,fc,fi,on,tuned,i,j,scan=1,fullscan=0;
char *name,dummy[32];
@@ -190,8 +138,6 @@ main(int argc, char **argv)
char *outfile = NULL;
FILE *conf = stdout;
- setprgname(argv[0]);
-
/* parse options */
ng_init();
for (;;) {
@@ -275,11 +221,13 @@ main(int argc, char **argv)
do_va_cmd(2,"setfreqtab",chanlist_names[j].str);
/* vbi */
- fdset_init(fds);
- if (not(vbi = vbi_open(ng_dev.vbi, 0, 0, -1)))
- fatal("cannot open %s", ng_dev.vbi);
- vbi_add_handler(vbi, event, NULL);
-
+ vbi = vbi_open(ng_dev.vbi,0,0);
+ if (NULL == vbi) {
+ fprintf(stderr,"open %s: %s\n",ng_dev.vbi,strerror(errno));
+ exit(1);
+ }
+ vbi_event_handler_add(vbi->dec,~0,event,vbi);
+
if (!fullscan) {
/* scan channels */
fprintf(stderr,"\nscanning channel list %s...\n",
@@ -293,9 +241,8 @@ main(int argc, char **argv)
fprintf(stderr,"no station\n");
continue;
}
- fdset_select(fds, 1000 * timeout);
- name = get_vbi_name();
- fprintf(stderr,"%s\n",name ? name : "???");
+ name = get_vbi_name(vbi);
+ fprintf(stderr, "%s\n", name ? name : "???");
if (NULL == name) {
sprintf(dummy,"unknown (%s)",chanlist[i].name);
name = dummy;
@@ -354,8 +301,7 @@ main(int argc, char **argv)
(-1 != fi) ? chanlist[fi].name : "-");
drv->setfreq(h_drv,fc);
- fdset_select(fds, 1000 * timeout);
- name = get_vbi_name();
+ name = get_vbi_name(vbi);
fprintf(stderr,"%s\n",name ? name : "???");
if (NULL == name) {
sprintf(dummy,"unknown (%s)",chanlist[fi].name);
@@ -388,8 +334,5 @@ main(int argc, char **argv)
audio_off();
drv->close(h_drv);
- vbi_del_handler(vbi, event, NULL);
- vbi_close(vbi);
-
exit(0);
}
diff --git a/console/aa.c b/console/ttv.c
index 4c1e86f..4c1e86f 100644
--- a/console/aa.c
+++ b/console/ttv.c
diff --git a/console/vbi-tty.c b/console/vbi-tty.c
new file mode 100644
index 0000000..ae28bd0
--- /dev/null
+++ b/console/vbi-tty.c
@@ -0,0 +1,285 @@
+/*
+ * vbi-tty -- terminal videotext browser
+ *
+ * (c) 2002 Gerd Knorr <kraxel@bytesex.org>
+ */
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <string.h>
+#include <errno.h>
+#include <iconv.h>
+#include <locale.h>
+#include <langinfo.h>
+#include <termios.h>
+#include <fcntl.h>
+#include <sys/types.h>
+#include <sys/ioctl.h>
+
+#include "vbi-data.h"
+#include "vbi-tty.h"
+
+/* --------------------------------------------------------------------- */
+
+struct termios saved_attributes;
+int saved_fl;
+
+static void tty_raw(void)
+{
+ struct termios tattr;
+
+ fcntl(0,F_GETFL,&saved_fl);
+ tcgetattr (0, &saved_attributes);
+
+ fcntl(0,F_SETFL,O_NONBLOCK);
+ memcpy(&tattr,&saved_attributes,sizeof(struct termios));
+ tattr.c_lflag &= ~(ICANON|ECHO);
+ tattr.c_cc[VMIN] = 1;
+ tattr.c_cc[VTIME] = 0;
+ tcsetattr (0, TCSAFLUSH, &tattr);
+}
+
+static void tty_restore(void)
+{
+ fcntl(0,F_SETFL,saved_fl);
+ tcsetattr (0, TCSANOW, &saved_attributes);
+}
+
+/* --------------------------------------------------------------------- */
+
+struct vbi_tty {
+ struct vbi_state *vbi;
+ struct vbi_page pg;
+ int pgno,subno;
+ int newpage;
+};
+
+static void
+vbi_fix_head(struct vbi_tty *tty, struct vbi_char *ch)
+{
+ int showno,showsub,red,i;
+
+ showno = tty->pg.pgno;
+ showsub = tty->pg.subno;
+ red = 0;
+ if (0 == showno) {
+ showno = tty->pgno;
+ showsub = 0;
+ red = 1;
+ }
+ if (tty->newpage) {
+ showno = tty->newpage;
+ showsub = 0;
+ red = 1;
+ }
+
+ for (i = 1; i <= 6; i++)
+ ch[i].unicode = ' ';
+ if (showno >= 0x100)
+ ch[1].unicode = '0' + ((showno >> 8) & 0xf);
+ if (showno >= 0x10)
+ ch[2].unicode = '0' + ((showno >> 4) & 0xf);
+ if (showno >= 0x1)
+ ch[3].unicode = '0' + ((showno >> 0) & 0xf);
+ if (showsub) {
+ ch[4].unicode = '/';
+ ch[5].unicode = '0' + ((showsub >> 4) & 0xf);
+ ch[6].unicode = '0' + ((showsub >> 0) & 0xf);
+ }
+ if (red) {
+ ch[1].foreground = VBI_RED;
+ ch[2].foreground = VBI_RED;
+ ch[3].foreground = VBI_RED;
+ }
+}
+
+static void
+vbi_render_page(struct vbi_tty *tty)
+{
+ char *data;
+ int len;
+
+ data = malloc(25*41*24);
+ vbi_fetch_vt_page(tty->vbi->dec,&tty->pg,tty->pgno,tty->subno,
+ VBI_WST_LEVEL_1p5,25,1);
+ vbi_fix_head(tty,tty->pg.text);
+ len = vbi_export_txt(data,nl_langinfo(CODESET),25*41*8,
+ &tty->pg,&vbi_fullrect,VBI_ANSICOLOR);
+ fprintf(stderr,"\033[H");
+ fwrite(data,len,1,stderr);
+ fprintf(stderr,"\033[0;42H");
+ free(data);
+}
+
+static void
+vbi_render_head(struct vbi_tty *tty, int pgno, int subno)
+{
+ static struct vbi_rect head = {
+ x1: 0, y1: 0, x2: 41, y2: 1,
+ };
+ struct vbi_page pg;
+ char *data;
+ int len;
+
+ data = malloc(41*24);
+ memset(&pg,0,sizeof(pg));
+ vbi_fetch_vt_page(tty->vbi->dec,&pg,pgno,subno,
+ VBI_WST_LEVEL_1p5,1,1);
+ vbi_fix_head(tty,pg.text);
+ len = vbi_export_txt(data,nl_langinfo(CODESET),41*8,
+ &pg,&head,VBI_ANSICOLOR);
+ fprintf(stderr,"\033[H");
+ fwrite(data,len,1,stderr);
+ fprintf(stderr,"\033[0;42H");
+ free(data);
+}
+
+static void
+vbi_newdata(struct vbi_event *ev, void *user)
+{
+ struct vbi_tty *tty = user;
+
+ switch (ev->type) {
+ case VBI_EVENT_TTX_PAGE:
+ if (tty->pgno == ev->ev.ttx_page.pgno &&
+ (tty->subno == ev->ev.ttx_page.subno ||
+ tty->subno == VBI_ANY_SUBNO)) {
+ vbi_render_page(tty);
+ } else {
+ vbi_render_head(tty,
+ ev->ev.ttx_page.pgno,
+ ev->ev.ttx_page.subno);
+ }
+ break;
+ }
+}
+
+static void
+vbi_setpage(struct vbi_tty *tty, int pgno, int subno)
+{
+ tty->pgno = pgno;
+ tty->subno = subno;
+ tty->newpage = 0;
+ memset(&tty->pg,0,sizeof(struct vbi_page));
+ vbi_fetch_vt_page(tty->vbi->dec,&tty->pg,tty->pgno,tty->subno,
+ VBI_WST_LEVEL_1p5,25,1);
+ vbi_render_page(tty);
+}
+
+/* --------------------------------------------------------------------- */
+
+void vbi_tty(char *device, int debug, int sim)
+{
+ struct vbi_state *vbi;
+ struct vbi_tty *tty;
+ fd_set set;
+ struct winsize win;
+ struct timeval tv;
+ char key[11];
+ int rc,subno,last;
+
+ setlocale(LC_ALL,"");
+ vbi = vbi_open(device,debug,sim);
+ if (NULL == vbi)
+ exit(1);
+
+ if (-1 != ioctl(0,TIOCGWINSZ,&win) && win.ws_row < 26) {
+ fprintf(stderr,"terminal too small (need 26 rows, have %d)\n",
+ win.ws_row);
+ exit(1);
+ }
+ tty_raw();
+ fprintf(stderr,"\033[H\033[2J");
+
+ tty = malloc(sizeof(*tty));
+ memset(tty,0,sizeof(*tty));
+ tty->vbi = vbi;
+ vbi_event_handler_add(vbi->dec,~0,vbi_newdata,tty);
+ vbi_setpage(tty,0x100,VBI_ANY_SUBNO);
+
+ for (last = 0; !last;) {
+ FD_ZERO(&set);
+ FD_SET(0,&set);
+ FD_SET(vbi->fd,&set);
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ rc = select(vbi->fd+1,&set,NULL,NULL,&tv);
+ if (-1 == rc) {
+ tty_restore();
+ perror("select");
+ exit(1);
+ }
+ if (0 == rc) {
+ tty_restore();
+ fprintf(stderr,"oops: timeout\n");
+ exit(1);
+ }
+ if (FD_ISSET(0,&set)) {
+ /* tty input */
+ rc = read(0, key, 10);
+ key[rc] = 0;
+ if (1 == rc) {
+ switch (key[0]) {
+ case 'q':
+ case 'Q':
+ /* quit */
+ last = 1;
+ break;
+ case 'L' & 0x1f:
+ /* refresh */
+ fprintf(stderr,"\033[H\033[2J");
+ vbi_render_page(tty);
+ break;
+ case 'i':
+ case 'I':
+ /* index */
+ vbi_setpage(tty,0x100,VBI_ANY_SUBNO);
+ break;
+ case ' ':
+ case 'l':
+ case 'L':
+ /* next page */
+ vbi_setpage(tty,vbi_calc_page(tty->pgno,+1),VBI_ANY_SUBNO);
+ break;
+ case '\x7f':
+ case 'h':
+ case 'H':
+ /* prev page */
+ vbi_setpage(tty,vbi_calc_page(tty->pgno,-1),VBI_ANY_SUBNO);
+ break;
+ case 'k':
+ case 'K':
+ /* next subpage */
+ subno = (tty->subno != VBI_ANY_SUBNO) ?
+ tty->subno : tty->pg.subno;
+ subno = vbi_calc_subpage(tty->vbi->dec,tty->pgno,subno,+1);
+ vbi_setpage(tty,tty->pgno,subno);
+ break;
+ case 'j':
+ case 'J':
+ /* prev subpage */
+ subno = (tty->subno != VBI_ANY_SUBNO) ?
+ tty->subno : tty->pg.subno;
+ subno = vbi_calc_subpage(tty->vbi->dec,tty->pgno,subno,-1);
+ vbi_setpage(tty,tty->pgno,subno);
+ break;
+ default:
+ if (key[0] >= '0' && key[0] <= '9') {
+ tty->newpage *= 16;
+ tty->newpage += key[0] - '0';
+ if (tty->newpage >= 0x100)
+ vbi_setpage(tty,tty->newpage,VBI_ANY_SUBNO);
+ }
+ }
+ }
+ }
+ if (FD_ISSET(vbi->fd,&set)) {
+ vbi_hasdata(vbi);
+ }
+ }
+ fprintf(stderr,"\033[H");
+ tty_restore();
+}
diff --git a/console/vbi-tty.h b/console/vbi-tty.h
new file mode 100644
index 0000000..cb21adb
--- /dev/null
+++ b/console/vbi-tty.h
@@ -0,0 +1 @@
+extern void vbi_tty(char *device, int debug, int sim);
diff --git a/console/webcam.c b/console/webcam.c
index 9a2d600..5dbc88e 100644
--- a/console/webcam.c
+++ b/console/webcam.c
@@ -22,46 +22,38 @@
#include "jpeglib.h"
#include "ftp.h"
#include "parseconfig.h"
-
+#include "list.h"
/* ---------------------------------------------------------------------- */
/* configuration */
-enum mode {
- FTP = 1,
- SSH = 2,
- LOCAL = 3,
-};
+int daemonize = 0;
+char *archive = NULL;
+char *tmpdir;
+struct list_head connections;
-char *ftp_host = "www";
-char *ftp_user = "webcam";
-char *ftp_pass = "xxxxxx";
-char *ftp_dir = "public_html/images";
-char *ftp_file = "webcam.jpeg";
-char *ftp_tmp = "uploading.jpeg";
-char *ssh_cmd;
-int ftp_passive = 1;
-int ftp_auto = 0;
-enum mode ftp_mode = FTP;
-int daemonize = 0;
-
-char *grab_text = "webcam %Y-%m-%d %H:%M:%S"; /* strftime */
-char *grab_infofile = NULL;
+char *grab_text = "webcam %Y-%m-%d %H:%M:%S"; /* strftime */
+char *grab_infofile = NULL;
int grab_width = 320;
int grab_height = 240;
int grab_delay = 3;
+int grab_wait = 0;
int grab_rotate = 0;
int grab_top = 0;
int grab_left = 0;
int grab_bottom = -1;
int grab_right = -1;
int grab_quality= 75;
-int grab_trigger= 0;
-int grab_once = 0;
-char *archive = NULL;
-
-char *grab_input;
-char *grab_norm;
+int grab_trigger= 0;
+int grab_once = 0;
+int grab_fg_r = 255;
+int grab_fg_g = 255;
+int grab_fg_b = 255;
+int grab_bg_r = -1;
+int grab_bg_g = -1;
+int grab_bg_b = -1;
+char *grab_input = NULL;
+char *grab_norm = NULL;
/* ---------------------------------------------------------------------- */
/* jpeg stuff */
@@ -98,6 +90,196 @@ write_file(int fd, char *data, int width, int height)
}
/* ---------------------------------------------------------------------- */
+/* image transfer */
+
+struct xfer_ops;
+
+struct xfer_state {
+ char *name;
+ struct list_head list;
+
+ /* xfer options */
+ char *host;
+ char *user;
+ char *pass;
+ char *dir;
+ char *file;
+ char *tmpfile;
+ int debug;
+
+ /* ftp options */
+ int passive,autologin;
+
+ /* function pointers + private date */
+ struct xfer_ops *ops;
+ void *data;
+};
+
+struct xfer_ops {
+ int (*open)(struct xfer_state*);
+ void (*info)(struct xfer_state*);
+ int (*xfer)(struct xfer_state*, char *image, int width, int height);
+ void (*close)(struct xfer_state*);
+};
+
+static int ftp_open(struct xfer_state *s)
+{
+ s->data = ftp_init(s->name,s->autologin,s->passive,s->debug);
+ ftp_connect(s->data,s->host,s->user,s->pass,s->dir);
+ return 0;
+}
+
+static void ftp_info(struct xfer_state *s)
+{
+ fprintf(stderr,"ftp config [%s]:\n %s@%s:%s\n %s => %s\n",
+ s->name,s->user,s->host,s->dir,s->tmpfile,s->file);
+}
+
+static int ftp_xfer(struct xfer_state *s, char *image, int width, int height)
+{
+ char filename[1024];
+ int fh;
+
+ sprintf(filename,"%s/webcamXXXXXX",tmpdir);
+ if (-1 == (fh = mkstemp(filename))) {
+ perror("mkstemp");
+ exit(1);
+ }
+ write_file(fh, image, width, height);
+ if (ftp_connected(s->data))
+ ftp_connect(s->data,s->host,s->user,s->pass,s->dir);
+ ftp_upload(s->data,filename,s->file,s->tmpfile);
+ unlink(filename);
+ return 0;
+}
+
+static void ftp_close(struct xfer_state *s)
+{
+ ftp_fini(s->data);
+}
+
+static struct xfer_ops ftp_ops = {
+ open: ftp_open,
+ info: ftp_info,
+ xfer: ftp_xfer,
+ close: ftp_close,
+};
+
+static int ssh_open(struct xfer_state *s)
+{
+ s->data = malloc(strlen(s->user)+strlen(s->host)+strlen(s->tmpfile)*2+
+ strlen(s->dir)+strlen(s->file)+32);
+ sprintf(s->data, "ssh %s@%s \"cat >%s && mv %s %s/%s\"",
+ s->user,s->host,s->tmpfile,s->tmpfile,s->dir,s->file);
+ return 0;
+}
+
+static void ssh_info(struct xfer_state *s)
+{
+ fprintf(stderr,"ssh config [%s]:\n %s@%s:%s\n %s => %s\n",
+ s->name,s->user,s->host,s->dir,s->tmpfile,s->file);
+}
+
+static int ssh_xfer(struct xfer_state *s, char *image, int width, int height)
+{
+ char filename[1024];
+ char *cmd = s->data;
+ unsigned char buf[4096];
+ FILE *sshp, *imgdata;
+ int len,fh;
+
+ sprintf(filename,"%s/webcamXXXXXX",tmpdir);
+ if (-1 == (fh = mkstemp(filename))) {
+ perror("mkstemp");
+ exit(1);
+ }
+ write_file(fh, image, width, height);
+
+ if ((sshp=popen(cmd, "w")) == NULL) {
+ perror("popen");
+ exit(1);
+ }
+ if ((imgdata = fopen(filename,"rb"))==NULL) {
+ perror("fopen");
+ exit(1);
+ }
+ for (;;) {
+ len = fread(buf,1,sizeof(buf),imgdata);
+ if (len <= 0)
+ break;
+ fwrite(buf,1,len,sshp);
+ }
+ fclose(imgdata);
+ pclose(sshp);
+
+ unlink(filename);
+ return 0;
+}
+
+static void ssh_close(struct xfer_state *s)
+{
+ char *cmd = s->data;
+ free(cmd);
+}
+
+static struct xfer_ops ssh_ops = {
+ open: ssh_open,
+ info: ssh_info,
+ xfer: ssh_xfer,
+ close: ssh_close,
+};
+
+static int local_open(struct xfer_state *s)
+{
+ char *t;
+
+ if (s->dir != NULL && s->dir[0] != '\0' ) {
+ t = malloc(strlen(s->tmpfile)+strlen(s->dir)+2);
+ sprintf(t, "%s/%s", s->dir, s->tmpfile);
+ s->tmpfile = t;
+
+ t = malloc(strlen(s->file)+strlen(s->dir)+2);
+ sprintf(t, "%s/%s", s->dir, s->file);
+ s->file = t;
+ }
+ return 0;
+}
+
+static void local_info(struct xfer_state *s)
+{
+ fprintf(stderr,"write config [%s]:\n local transfer %s => %s\n",
+ s->name,s->tmpfile,s->file);
+}
+
+static int local_xfer(struct xfer_state *s, char *image, int width, int height)
+{
+ int fh;
+
+ if (-1 == (fh = open(s->tmpfile,O_CREAT|O_WRONLY|O_TRUNC,0666))) {
+ fprintf(stderr,"open %s: %s\n",s->tmpfile,strerror(errno));
+ exit(1);
+ }
+ write_file(fh, image, width, height);
+ if (rename(s->tmpfile, s->file) ) {
+ fprintf(stderr, "can't move %s -> %s\n", s->tmpfile, s->file);
+ exit(1);
+ }
+ return 0;
+}
+
+static void local_close(struct xfer_state *s)
+{
+ /* nothing */
+}
+
+static struct xfer_ops local_ops = {
+ open: local_open,
+ info: local_info,
+ xfer: local_xfer,
+ close: local_close,
+};
+
+/* ---------------------------------------------------------------------- */
/* capture stuff */
const struct ng_vid_driver *drv;
@@ -244,9 +426,13 @@ add_text(char *image, int width, int height)
f = fontdata[line[x] * CHAR_HEIGHT + y];
for (i = CHAR_WIDTH-1; i >= 0; i--) {
if (f & (CHAR_START << i)) {
- ptr[0] = 255;
- ptr[1] = 255;
- ptr[2] = 255;
+ ptr[0] = grab_fg_r;
+ ptr[1] = grab_fg_g;
+ ptr[2] = grab_fg_b;
+ } else if (grab_bg_r != -1) {
+ ptr[0] = grab_bg_r;
+ ptr[1] = grab_bg_g;
+ ptr[2] = grab_bg_b;
}
ptr += 3;
}
@@ -350,36 +536,15 @@ compare_images(unsigned char *last, unsigned char *current,
/* ---------------------------------------------------------------------- */
-static void ssh_upload(char *filename)
-{
- unsigned char ssh_buf[4096];
- FILE *sshp, *imgdata;
- int len;
-
- if ((sshp=popen(ssh_cmd, "w")) == NULL) {
- perror("open");
- exit(1);
- }
- if ((imgdata = fopen(filename,"rb"))==NULL) {
- perror("fopen");
- exit(1);
- }
- for (;;) {
- len = fread(ssh_buf,1,sizeof(ssh_buf),imgdata);
- if (len <= 0)
- break;
- fwrite(ssh_buf,1,len,sshp);
- }
- fclose(imgdata);
- pclose(sshp);
-}
-
int
main(int argc, char *argv[])
{
unsigned char *image,*val,*gimg,*lastimg = NULL;
- char filename[1024], *tmpdir;
int width, height, i, fh;
+ char filename[1024];
+ char **sections;
+ struct list_head *item;
+ struct xfer_state *s;
/* read config */
if (argc > 1) {
@@ -391,31 +556,6 @@ main(int argc, char *argv[])
cfg_parse_file(filename);
ng_init();
- if (NULL != (val = cfg_get_str("ftp","host")))
- ftp_host = val;
- if (NULL != (val = cfg_get_str("ftp","user")))
- ftp_user = val;
- if (NULL != (val = cfg_get_str("ftp","pass")))
- ftp_pass = val;
- if (NULL != (val = cfg_get_str("ftp","dir")))
- ftp_dir = val;
- if (NULL != (val = cfg_get_str("ftp","file")))
- ftp_file = val;
- if (NULL != (val = cfg_get_str("ftp","tmp")))
- ftp_tmp = val;
- if (-1 != (i = cfg_get_int("ftp","passive")))
- ftp_passive = i;
- if (-1 != (i = cfg_get_int("ftp","auto")))
- ftp_auto = i;
- if (-1 != (i = cfg_get_int("ftp","debug")))
- ftp_debug = i;
- if (-1 != (i = cfg_get_int("ftp","local")))
- if (i)
- ftp_mode = LOCAL;
- if (-1 != (i = cfg_get_int("ftp","ssh")))
- if (i)
- ftp_mode = SSH;
-
if (NULL != (val = cfg_get_str("grab","device")))
ng_dev.video = val;
if (NULL != (val = cfg_get_str("grab","text")))
@@ -432,6 +572,8 @@ main(int argc, char *argv[])
grab_height = i;
if (-1 != (i = cfg_get_int("grab","delay")))
grab_delay = i;
+ if (-1 != (i = cfg_get_int("grab","wait")))
+ grab_wait = i;
if (-1 != (i = cfg_get_int("grab","rotate")))
grab_rotate = i;
if (-1 != (i = cfg_get_int("grab","top")))
@@ -449,6 +591,25 @@ main(int argc, char *argv[])
if (NULL != (val = cfg_get_str("grab","archive")))
archive = val;
+ if (-1 != (i = cfg_get_int("grab","fg_red")))
+ if (i >= 0 && i <= 255)
+ grab_fg_r = i;
+ if (-1 != (i = cfg_get_int("grab","fg_green")))
+ if (i >= 0 && i <= 255)
+ grab_fg_g = i;
+ if (-1 != (i = cfg_get_int("grab","fg_blue")))
+ if (i >= 0 && i <= 255)
+ grab_fg_b = i;
+ if (-1 != (i = cfg_get_int("grab","bg_red")))
+ if (i >= 0 && i <= 255)
+ grab_bg_r = i;
+ if (-1 != (i = cfg_get_int("grab","bg_green")))
+ if (i >= 0 && i <= 255)
+ grab_bg_g = i;
+ if (-1 != (i = cfg_get_int("grab","bg_blue")))
+ if (i >= 0 && i <= 255)
+ grab_bg_b = i;
+
if ( grab_top < 0 ) grab_top = 0;
if ( grab_left < 0 ) grab_left = 0;
if ( grab_bottom > grab_height ) grab_bottom = grab_height;
@@ -458,58 +619,79 @@ main(int argc, char *argv[])
if ( grab_top >= grab_bottom ) grab_top = 0;
if ( grab_left >= grab_right ) grab_left = 0;
+ INIT_LIST_HEAD(&connections);
+ for (sections = cfg_list_sections(); *sections != NULL; sections++) {
+ if (0 == strcasecmp(*sections,"grab"))
+ continue;
+
+ /* init + set defaults */
+ s = malloc(sizeof(*s));
+ memset(s,0,sizeof(*s));
+ s->name = *sections;
+ s->host = "www";
+ s->user = "webcam";
+ s->pass = "xxxxxx";
+ s->dir = "public_html/images";
+ s->file = "webcam.jpeg";
+ s->tmpfile = "uploading.jpeg";
+ s->passive = 1;
+ s->autologin = 0;
+ s->ops = &ftp_ops;
+
+ /* from config */
+ if (NULL != (val = cfg_get_str(*sections,"host")))
+ s->host = val;
+ if (NULL != (val = cfg_get_str(*sections,"user")))
+ s->user = val;
+ if (NULL != (val = cfg_get_str(*sections,"pass")))
+ s->pass = val;
+ if (NULL != (val = cfg_get_str(*sections,"dir")))
+ s->dir = val;
+ if (NULL != (val = cfg_get_str(*sections,"file")))
+ s->file = val;
+ if (NULL != (val = cfg_get_str(*sections,"tmp")))
+ s->tmpfile = val;
+ if (-1 != (i = cfg_get_int(*sections,"passive")))
+ s->passive = i;
+ if (-1 != (i = cfg_get_int(*sections,"auto")))
+ s->autologin = i;
+ if (-1 != (i = cfg_get_int(*sections,"debug")))
+ s->debug = i;
+ if (-1 != (i = cfg_get_int(*sections,"local")))
+ if (i)
+ s->ops = &local_ops;
+ if (-1 != (i = cfg_get_int(*sections,"ssh")))
+ if (i)
+ s->ops = &ssh_ops;
+
+ /* all done */
+ list_add_tail(&s->list,&connections);
+ }
+
/* init everything */
grab_init();
+ sleep(grab_wait);
tmpdir = (NULL != getenv("TMPDIR")) ? getenv("TMPDIR") : "/tmp";
- switch (ftp_mode) {
- case LOCAL:
- if (ftp_dir != NULL && ftp_dir[0] != '\0' ) {
- char * t = malloc(strlen(ftp_tmp)+strlen(ftp_dir)+2);
- sprintf(t, "%s/%s", ftp_dir, ftp_tmp);
- ftp_tmp = t;
-
- t = malloc(strlen(ftp_file)+strlen(ftp_dir)+2);
- sprintf(t, "%s/%s", ftp_dir, ftp_file);
- ftp_file = t;
- }
- break;
- case FTP:
- ftp_init(ftp_auto,ftp_passive);
- ftp_connect(ftp_host,ftp_user,ftp_pass,ftp_dir);
- break;
- case SSH:
- ssh_cmd = malloc(strlen(ftp_user)+strlen(ftp_host)+strlen(ftp_tmp)*2+
- strlen(ftp_dir)+strlen(ftp_file)+32);
- sprintf(ssh_cmd, "ssh %s@%s \"cat >%s && mv %s %s/%s\"",
- ftp_user,ftp_host,ftp_tmp,ftp_tmp,ftp_dir,ftp_file);
- break;
+ list_for_each(item,&connections) {
+ s = list_entry(item, struct xfer_state, list);
+ s->ops->open(s);
}
/* print config */
- fprintf(stderr,"video4linux webcam v1.4 - (c) 1998-2002 Gerd Knorr\n");
+ fprintf(stderr,"video4linux webcam v1.5 - (c) 1998-2002 Gerd Knorr\n");
fprintf(stderr,"grabber config:\n size %dx%d [%s]\n",
fmt.width,fmt.height,ng_vfmt_to_desc[gfmt.fmtid]);
fprintf(stderr," input %s, norm %s, jpeg quality %d\n",
grab_input,grab_norm, grab_quality);
fprintf(stderr," rotate=%d, top=%d, left=%d, bottom=%d, right=%d\n",
grab_rotate, grab_top, grab_left, grab_bottom, grab_right);
- switch (ftp_mode) {
- case LOCAL:
- fprintf(stderr,"write config:\n local transfer %s => %s\n",
- ftp_tmp,ftp_file);
- break;
- case FTP:
- fprintf(stderr,"ftp config:\n %s@%s:%s\n %s => %s\n",
- ftp_user,ftp_host,ftp_dir,ftp_tmp,ftp_file);
- break;
- case SSH:
- fprintf(stderr,"ssh config:\n %s@%s:%s\n %s => %s\n",
- ftp_user,ftp_host,ftp_dir,ftp_tmp,ftp_file);
- break;
+ list_for_each(item,&connections) {
+ s = list_entry(item, struct xfer_state, list);
+ s->ops->info(s);
}
/* run as daemon - detach from terminal */
- if (!ftp_debug && daemonize) {
+ if (daemonize) {
switch (fork()) {
case -1:
perror("fork");
@@ -543,34 +725,9 @@ main(int argc, char *argv[])
/* ok, label it and upload */
add_text(image,width,height);
- switch (ftp_mode) {
- case LOCAL:
- if (-1 == (fh = open(ftp_tmp,O_CREAT|O_WRONLY|O_TRUNC,0666))) {
- fprintf(stderr,"open %s: %s\n",ftp_tmp,strerror(errno));
- exit(1);
- }
- write_file(fh, image, width, height);
- if (rename(ftp_tmp, ftp_file) ) {
- fprintf(stderr, "can't move %s -> %s\n", ftp_tmp, ftp_file);
- }
- break;
- case FTP:
- case SSH:
- sprintf(filename,"%s/webcamXXXXXX",tmpdir);
- if (-1 == (fh = mkstemp(filename))) {
- perror("mkstemp");
- exit(1);
- }
- write_file(fh, image, width, height);
- if (FTP == ftp_mode) {
- if (!ftp_connected)
- ftp_connect(ftp_host,ftp_user,ftp_pass,ftp_dir);
- ftp_upload(filename,ftp_file,ftp_tmp);
- }
- if (SSH == ftp_mode)
- ssh_upload(filename);
- unlink(filename);
- break;
+ list_for_each(item,&connections) {
+ s = list_entry(item, struct xfer_state, list);
+ s->ops->xfer(s,image,width,height);
}
if (archive) {
time_t t;
@@ -580,7 +737,7 @@ main(int argc, char *argv[])
tm = localtime(&t);
strftime(filename,sizeof(filename)-1,archive,tm);
if (-1 == (fh = open(filename,O_CREAT|O_WRONLY|O_TRUNC,0666))) {
- fprintf(stderr,"open %s: %s\n",ftp_tmp,strerror(errno));
+ fprintf(stderr,"open %s: %s\n",filename,strerror(errno));
exit(1);
}
write_file(fh, image, width, height);
@@ -591,9 +748,9 @@ main(int argc, char *argv[])
if (grab_delay > 0)
sleep(grab_delay);
}
- if (FTP == ftp_mode) {
- ftp_send(1,"bye");
- ftp_recv();
+ list_for_each(item,&connections) {
+ s = list_entry(item, struct xfer_state, list);
+ s->ops->close(s);
}
return 0;
}

Privacy Policy