From: michael Date: Sun, 2 Jul 2006 01:07:26 +0000 (+0000) Subject: better url detection X-Git-Url: https://git.zerfleddert.de/cgi-bin/gitweb.cgi/record-dvb/commitdiff_plain/c0833e33c10e0e92bf94fa8f80bee08cf9e764b4?ds=inline better url detection --- diff --git a/common.c b/common.c index 8f000fd..825b5ae 100644 --- a/common.c +++ b/common.c @@ -92,3 +92,20 @@ int resolve(struct dvb_host *dvbhost, struct sockaddr_in *server) return 0; } +int is_url(char *string) +{ + char *pos; + + if (!(strlen(string))) + return 0; + + pos = string; + + while(*pos != ':' && *pos != 0) + pos++; + + if (!strncmp("://", pos, 3)) + return 1; + + return 0; +} diff --git a/common.h b/common.h index b7015da..80dba96 100644 --- a/common.h +++ b/common.h @@ -7,3 +7,4 @@ struct dvb_host { struct dvb_host *parse(char *urlpart, char *defport); int resolve(struct dvb_host *dvbhost, struct sockaddr_in *server); +int is_url(char *string); diff --git a/dump-stream.c b/dump-stream.c index 1cbaad2..a6039e0 100644 --- a/dump-stream.c +++ b/dump-stream.c @@ -9,8 +9,12 @@ #include #include #include +#include #include "mcast.h" +#include "http.h" +#include "sap.h" +#include "common.h" #define CHUNKSIZE 1500 @@ -28,8 +32,26 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - if ((in = open_mcast(url)) < 0) { - fprintf(stderr,"Can't open url %s!\n",url); + if (!is_url(url)) { + char *service_url; + if ((service_url = get_url_from_sap(url))) { + printf("SAP says: '%s' -> %s\n", url, service_url); + url = service_url; + } + } + + if (is_http(url)) { + if ((in = open_http(url)) < 0) { + fprintf(stderr,"Can't open url %s!\n",url); + exit(EXIT_FAILURE); + } + } else if (is_mcast(url)) { + if ((in = open_mcast(url)) < 0) { + fprintf(stderr,"Can't open url %s!\n",url); + exit(EXIT_FAILURE); + } + } else { + printf("URL '%s' not supported!\n", url); exit(EXIT_FAILURE); } diff --git a/record-dvb.c b/record-dvb.c index 9356348..5a055b8 100644 --- a/record-dvb.c +++ b/record-dvb.c @@ -10,10 +10,12 @@ #include #include #include +#include #include "http.h" #include "mcast.h" #include "sap.h" +#include "common.h" #define CHUNKSIZE 3000 #define GTOD_INTERVAL 100 @@ -118,7 +120,7 @@ int main(int argc, char **argv) exit(EXIT_FAILURE); } - if (!is_http(url) && !is_mcast(url)) { + if (!is_url(url)) { char *service_url; if ((service_url = get_url_from_sap(url))) { printf("SAP says: '%s' -> %s\n", url, service_url);