aboutsummaryrefslogtreecommitdiffstats
path: root/common
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)
commit923e3c2dfcfef0d6a31239aceb7654ed3a49a7c4 (patch)
tree62ca3a77641fed2370af2dc4c5025d66c53b4439 /common
parent9ee950dde5943ee4083c2a0176ad4a1da4b49220 (diff)
v3.77
Diffstat (limited to 'common')
-rw-r--r--common/Subdir.mk6
-rw-r--r--common/channel.c24
-rw-r--r--common/channel.h2
-rw-r--r--common/commands.c231
-rw-r--r--common/frequencies.c21
-rw-r--r--common/parseconfig.c31
-rw-r--r--common/parseconfig.h3
7 files changed, 275 insertions, 43 deletions
diff --git a/common/Subdir.mk b/common/Subdir.mk
index 4888899..0b8b5ec 100644
--- a/common/Subdir.mk
+++ b/common/Subdir.mk
@@ -17,7 +17,9 @@ OBJS-common-input := \
# RegEdit.c is good old K&R ...
common/RegEdit.o : CFLAGS += -Wno-missing-prototypes -Wno-strict-prototypes
+common/channel-no-x11.o: CFLAGS += -DNO_X11=1
common/channel-no-x11.o:: common/channel.c
- $(CC) $(CFLAGS) -DNO_X11=1 -Wp,-MD,$*.dep -c -o $@ $<
- @sed -e "s|.*\.o:|$@::|" < $*.dep > $*.d && rm -f $*.dep
+ @$(echo_compile_c)
+ @$(compile_c)
+ @$(fixup_deps)
diff --git a/common/channel.c b/common/channel.c
index 57c3750..1b89c17 100644
--- a/common/channel.c
+++ b/common/channel.c
@@ -99,6 +99,9 @@ int nlaunch = 0;
int lookup_channel(char *channel)
{
+#if 0
+ /* Hmm, why the heck that used to be that complex?
+ * Any good reason I forgot ? */
int i,nr1,nr2;
char tag1[5],tag2[5];
@@ -130,6 +133,18 @@ int lookup_channel(char *channel)
return -1;
return i;
+#else
+ int i;
+
+ if (NULL == channel)
+ return -1;
+ for (i = 0; i < chancount; i++)
+ if (0 == strcasecmp(chanlist[i].name,channel))
+ break;
+ if (i == chancount)
+ return -1;
+ return i;
+#endif
}
int get_freq(int i)
@@ -365,7 +380,7 @@ init_channel(char *name, struct CHANNEL *c)
}
void
-read_config(char *conffile)
+read_config(char *conffile, int *argc, char **argv)
{
char filename[100];
char *val;
@@ -381,6 +396,8 @@ read_config(char *conffile)
if (0 == cfg_parse_file(filename))
have_config = 1;
}
+ if (argc)
+ cfg_parse_options(argc,argv);
/* misc global settings */
if (NULL != (val = cfg_get_str("global","mixer"))) {
@@ -460,6 +477,11 @@ read_config(char *conffile)
mov_audio = val;
if (NULL != (val = cfg_get_str("global","mov-rate")))
mov_rate = val;
+
+ if (NULL != (val = cfg_get_str("global","filter")))
+ for (i = 0; NULL != ng_filters[i]; i++)
+ if (0 == strcasecmp(ng_filters[i]->name, val))
+ cur_filter=ng_filters[i];
}
void
diff --git a/common/channel.h b/common/channel.h
index b5b04f1..4dfabe7 100644
--- a/common/channel.h
+++ b/common/channel.h
@@ -70,7 +70,7 @@ void configure_channel(struct CHANNEL *channel);
void del_channel(int nr);
void calc_frequencies(void);
-void read_config(char *conffile);
+void read_config(char *conffile, int *argc, char **argv);
void parse_config(void);
void save_config(void);
diff --git a/common/commands.c b/common/commands.c
index 0587861..66a3a95 100644
--- a/common/commands.c
+++ b/common/commands.c
@@ -11,8 +11,14 @@
#include <math.h>
#include <stdarg.h>
#include <time.h>
+#include <fcntl.h>
#include <pthread.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+
#include "grab-ng.h"
#include "capture.h"
@@ -91,6 +97,7 @@ static int movie_handler(char *name, int argc, char **argv);
static int fullscreen_handler(char *name, int argc, char **argv);
static int msg_handler(char *name, int argc, char **argv);
static int showtime_handler(char *name, int argc, char **argv);
+static int vdr_handler(char *name, int argc, char **argv);
#if TT
static int vtx_handler(char *name, int argc, char **argv);
#endif
@@ -105,6 +112,7 @@ static struct COMMANDS {
} commands[] = {
{ "setstation", 0, setstation_handler },
{ "setchannel", 0, setchannel_handler },
+ { "setfreq", 1, setchannel_handler },
{ "setfreqtab", 1, setfreqtab_handler },
{ "capture", 1, capture_handler },
@@ -137,6 +145,7 @@ static struct COMMANDS {
{ "keypad", 1, keypad_handler },
{ "showtime", 0, showtime_handler },
+ { "vdr", 1, vdr_handler },
{ NULL, 0, NULL }
};
@@ -651,48 +660,54 @@ static int setchannel_handler(char *name, int argc, char **argv)
display_message("grabber busy");
return -1;
}
-
- if (0 == strcasecmp(argv[0],"next")) {
- cur_channel = (cur_channel+1) % chancount;
- cur_fine = defaults.fine;
- } else if (0 == strcasecmp(argv[0],"prev")) {
- cur_channel = (cur_channel+chancount-1) % chancount;
- cur_fine = defaults.fine;
- } else if (0 == strcasecmp(argv[0],"fine_up")) {
- cur_fine++;
- } else if (0 == strcasecmp(argv[0],"fine_down")) {
- cur_fine--;
+
+ if (0 == strcasecmp("setfreq",name)) {
+ cur_freq = (unsigned long)(atof(argv[0])*16);
+ cur_sender = -1;
+ cur_channel = -1;
+ cur_fine = 0;
} else {
- if (-1 != (c = lookup_channel(argv[0]))) {
- cur_channel = c;
+ if (0 == strcasecmp(argv[0],"next")) {
+ cur_channel = (cur_channel+1) % chancount;
+ cur_fine = defaults.fine;
+ } else if (0 == strcasecmp(argv[0],"prev")) {
+ cur_channel = (cur_channel+chancount-1) % chancount;
cur_fine = defaults.fine;
+ } else if (0 == strcasecmp(argv[0],"fine_up")) {
+ cur_fine++;
+ } else if (0 == strcasecmp(argv[0],"fine_down")) {
+ cur_fine--;
+ } else {
+ if (-1 != (c = lookup_channel(argv[0]))) {
+ cur_channel = c;
+ cur_fine = defaults.fine;
+ }
}
- }
-
- if (0 != strncmp(argv[0],"fine",4)) {
- /* look if there is a known station on that channel */
- for (i = 0; i < count; i++) {
- if (cur_channel == channels[i]->channel) {
- char *argv[2];
- argv[0] = channels[i]->name;
- argv[1] = NULL;
- return setstation_handler("", argc, argv);
+
+ if (0 != strncmp(argv[0],"fine",4)) {
+ /* look if there is a known station on that channel */
+ for (i = 0; i < count; i++) {
+ if (cur_channel == channels[i]->channel) {
+ char *argv[2];
+ argv[0] = channels[i]->name;
+ argv[1] = NULL;
+ return setstation_handler("", argc, argv);
+ }
}
}
+ cur_sender = -1;
+ if (-1 != cur_channel)
+ cur_freq = get_freq(cur_channel)+cur_fine;
+ else {
+ cur_freq += cur_fine;
+ cur_fine = 0;
+ }
}
if (channel_switch_hook)
channel_switch_hook();
set_capture(CAPTURE_OFF,1);
- cur_sender = -1;
- if (-1 != cur_channel)
- cur_freq = get_freq(cur_channel)+cur_fine;
- else {
- cur_freq += cur_fine;
- cur_fine = 0;
- }
-
mute = ng_attr_byid(attrs,ATTR_ID_MUTE);
if (mute && !cur_attrs[ATTR_ID_MUTE])
mute->write(mute,1);
@@ -1157,6 +1172,160 @@ exit_handler(char *name, int argc, char **argv)
/* ----------------------------------------------------------------------- */
+static char *strfamily(int family)
+{
+ switch (family) {
+ case PF_INET6: return "ipv6";
+ case PF_INET: return "ipv4";
+ case PF_UNIX: return "unix";
+ }
+ return "????";
+}
+
+static int
+tcp_connect(struct addrinfo *ai, char *host, char *serv)
+{
+ struct addrinfo *res,*e;
+ char uhost[INET6_ADDRSTRLEN+1];
+ char userv[33];
+ int sock,rc,opt=1;
+
+ ai->ai_flags = AI_CANONNAME;
+ if (debug)
+ fprintf(stderr,"tcp: lookup %s:%s ... ",host,serv);
+ if (0 != (rc = getaddrinfo(host, serv, ai, &res))) {
+ fprintf(stderr,"tcp: getaddrinfo (%s:%s): %s\n",
+ host,serv,gai_strerror(rc));
+ return -1;
+ }
+ if (debug)
+ fprintf(stderr,"ok\n");
+ for (e = res; e != NULL; e = e->ai_next) {
+ if (0 != getnameinfo((struct sockaddr*)e->ai_addr,e->ai_addrlen,
+ uhost,INET6_ADDRSTRLEN,userv,32,
+ NI_NUMERICHOST | NI_NUMERICSERV)) {
+ fprintf(stderr,"tcp: getnameinfo (peer): oops\n");
+ continue;
+ }
+ if (debug)
+ fprintf(stderr,"tcp: trying %s (%s:%s) ... ",
+ strfamily(e->ai_family),uhost,userv);
+ if (-1 == (sock = socket(e->ai_family, e->ai_socktype,
+ e->ai_protocol))) {
+ fprintf(stderr,"tcp: socket: %s\n",strerror(errno));
+ continue;
+ }
+ setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&opt,sizeof(opt));
+ if (-1 == connect(sock,e->ai_addr,e->ai_addrlen)) {
+ fprintf(stderr,"tcp: connect: %s\n",strerror(errno));
+ close(sock);
+ continue;
+ }
+ if (debug)
+ fprintf(stderr,"ok\n");
+ fcntl(sock,F_SETFL,O_NONBLOCK);
+ fcntl(sock,F_SETFD,FD_CLOEXEC);
+ return sock;
+ }
+ return -1;
+}
+
+static int tcp_readbuf(int sock, int timeout, char *dest, char dlen)
+{
+ struct timeval tv;
+ fd_set set;
+ int rc;
+
+ again:
+ FD_ZERO(&set);
+ FD_SET(sock,&set);
+ tv.tv_sec = timeout;
+ tv.tv_usec = 0;
+ rc = select(sock+1,&set,NULL,NULL,&tv);
+ if (-1 == rc && EINTR == errno)
+ goto again;
+ if (-1 == rc) {
+ if (debug)
+ perror("tcp: select");
+ return -1;
+ }
+ if (0 == rc) {
+ if (debug)
+ fprintf(stderr,"tcp: select timeout\n");
+ return -1;
+ }
+ rc = read(sock,dest,dlen-1);
+ if (-1 == rc) {
+ if (debug)
+ perror("tcp: read");
+ return -1;
+ }
+ dest[rc] = 0;
+ return rc;
+}
+
+static int vdr_sock = -1;
+
+static int
+vdr_handler(char *name, int argc, char **argv)
+{
+ char line[80];
+ struct addrinfo ask;
+ int i,l,len;
+
+ if (-1 == vdr_sock) {
+ memset(&ask,0,sizeof(ask));
+ ask.ai_family = PF_UNSPEC;
+ ask.ai_socktype = SOCK_STREAM;
+ vdr_sock = tcp_connect(&ask,"localhost","2001");
+ if (-1 == vdr_sock)
+ return -1;
+
+ /* skip greeting line */
+ if (-1 == tcp_readbuf(vdr_sock,3,line,sizeof(line)))
+ goto oops;
+ if (debug)
+ fprintf(stderr,"vdr: << %s",line);
+ }
+
+ /* send command */
+ line[0] = 0;
+ for (i = 0, len = 0; i < argc; i++) {
+ l = strlen(argv[i]);
+ if (len+l+4 > sizeof(line))
+ break;
+ if (len) {
+ strcpy(line+len," ");
+ len++;
+ }
+ strcpy(line+len,argv[i]);
+ len += l;
+ }
+ strcpy(line+len,"\r\n");
+ len += 2;
+ if (len != write(vdr_sock,line,len)) {
+ if (debug)
+ perror("tcp: write");
+ goto oops;
+ }
+ if (debug)
+ fprintf(stderr,"vdr: >> %s",line);
+
+ /* skip answer */
+ if (-1 == tcp_readbuf(vdr_sock,3,line,sizeof(line)))
+ goto oops;
+ if (debug)
+ fprintf(stderr,"vdr: << %s",line);
+ return 0;
+
+oops:
+ close(vdr_sock);
+ vdr_sock = -1;
+ return -1;
+}
+
+/* ----------------------------------------------------------------------- */
+
#if TT
static struct TEXTELEM*
parse_vtx(int lines, char **text)
diff --git a/common/frequencies.c b/common/frequencies.c
index c41555d..553275b 100644
--- a/common/frequencies.c
+++ b/common/frequencies.c
@@ -1144,14 +1144,19 @@ static struct CHANLIST pal_bcast_cn[] = {
/* South Africa Broadcast */
static struct CHANLIST pal_bcast_za[] ={
- { "1", 175250 },
- { "2", 183250 },
- { "3", 191250 },
- { "4", 199250 },
- { "5", 207250 },
- { "6", 215250 },
- { "7", 223250 },
- { "8", 231250 },
+ { "1", 175250 },
+ { "2", 183250 },
+ { "3", 191250 },
+ { "4", 199250 },
+ { "5", 207250 },
+ { "6", 215250 },
+ { "7", 223250 },
+ { "8", 231250 },
+ { "9", 239250 },
+ { "10", 247250 },
+ { "11", 255250 },
+ { "12", 263250 },
+ { "13", 271250 },
FREQ_UHF
};
diff --git a/common/parseconfig.c b/common/parseconfig.c
index 7a0dd66..9c6eeaa 100644
--- a/common/parseconfig.c
+++ b/common/parseconfig.c
@@ -145,6 +145,37 @@ cfg_parse_file(char *filename)
/* ------------------------------------------------------------------------ */
+void
+cfg_parse_option(char *section, char *tag, char *value)
+{
+ struct CFG_ENTRIES *e = NULL;
+
+ if (NULL == c)
+ c = cfg_init_sections();
+ e = cfg_find_section(c,section);
+ cfg_set_entry(e,tag,value);
+}
+
+void
+cfg_parse_options(int *argc, char **argv)
+{
+ char section[64], tag[64];
+ int i,j;
+
+ for (i = 1; i+1 < *argc;) {
+ if (2 == sscanf(argv[i],"-%63[^:]:%63s",section,tag)) {
+ cfg_parse_option(section,tag,argv[i+1]);
+ for (j = i; j < *argc-1; j++)
+ argv[j] = argv[j+2];
+ (*argc) -= 2;
+ } else {
+ i++;
+ }
+ }
+}
+
+/* ------------------------------------------------------------------------ */
+
char**
cfg_list_sections()
{
diff --git a/common/parseconfig.h b/common/parseconfig.h
index e3b609d..57a462c 100644
--- a/common/parseconfig.h
+++ b/common/parseconfig.h
@@ -1,4 +1,7 @@
int cfg_parse_file(char *filename);
+void cfg_parse_option(char *section, char *tag, char *value);
+void cfg_parse_options(int *argc, char **argv);
+
char** cfg_list_sections(void);
char** cfg_list_entries(char *name);
char* cfg_get_str(char *sec, char *ent);

Privacy Policy