util iptv: add support for using liburiparser

This is more flexible (it supports IPv6) and almost certainly more robust!
This commit is contained in:
Adam Sutton 2013-11-24 13:26:03 +00:00
parent dd7ef9e8f9
commit cf97cbafa7
4 changed files with 105 additions and 17 deletions

12
configure vendored
View file

@ -29,6 +29,7 @@ OPTIONS=(
"zlib:auto"
"libav:auto"
"inotify:auto"
"uriparser:auto"
"bundle:no"
"dvbcsa:no"
"epoll:yes"
@ -133,6 +134,17 @@ if enabled_or_auto zlib; then
fi
fi
#
# uriparser
#
if enabled_or_auto uriparser; then
if check_pkg liburiparser; then
enable uriparser
elif enabled uriparser; then
die "liburiparser development support not found (use --disable-uriparser)"
fi
fi
#
# Bundling
#

4
debian/control vendored
View file

@ -2,12 +2,12 @@ Source: tvheadend
Section: video
Priority: extra
Maintainer: Andreas Öman <andreas@tvheadend.org>
Build-Depends: debhelper (>= 7.0.50), pkg-config, libavahi-client-dev, libssl-dev, zlib1g-dev, wget, bzip2, libcurl4-gnutls-dev, git-core
Build-Depends: debhelper (>= 7.0.50), pkg-config, libavahi-client-dev, libssl-dev, zlib1g-dev, wget, bzip2, libcurl4-gnutls-dev, git-core, liburiparser-dev
Standards-Version: 3.7.3
Package: tvheadend
Architecture: any
Depends: ${shlibs:Depends}, libavahi-client3, zlib1g
Depends: ${shlibs:Depends}, libavahi-client3, zlib1g, liburiparser1
Recommends: xmltv-util
Enhances: showtime
Replaces: hts-tvheadend

View file

@ -25,8 +25,84 @@
#include <regex.h>
#include <string.h>
/* Use liburiparser if available */
#if ENABLE_URIPARSER
#include <uriparser/Uri.h>
int
urlparse ( const char *str, url_t *url )
{
UriParserStateA state;
UriPathSegmentA *path;
UriUriA uri;
char *s, buf[256];
/* Parse */
state.uri = &uri;
if (uriParseUriA(&state, str) != URI_SUCCESS) {
uriFreeUriMembersA(&uri);
return -1;
}
/* Store raw */
strncpy(url->raw, str, sizeof(url->raw));
/* Copy */
#define uri_copy(y, x)\
if (x.first) {\
size_t len = x.afterLast - x.first;\
strncpy(y, x.first, len);\
y[len] = 0;\
} else {\
*y = 0;\
}
uri_copy(url->scheme, uri.scheme);
uri_copy(url->host, uri.hostText);
uri_copy(url->user, uri.userInfo);
uri_copy(url->query, uri.query);
uri_copy(url->frag, uri.fragment);
uri_copy(buf, uri.portText);
if (*buf)
url->port = atoi(buf);
else
url->port = 0;
*url->path = 0;
path = uri.pathHead;
while (path) {
strcat(url->path, "/");
uri_copy(buf, path->text);
strcat(url->path, buf);
path = path->next;
}
// TODO: query/fragment
/* Split user/pass */
s = strstr(url->user, ":");
if (s) {
strcpy(url->pass, s+1);
*s = 0;
} else {
*url->pass = 0;
}
/* Cleanup */
uriFreeUriMembersA(&uri);
return 0;
}
/* Fallback to limited support */
#else /* ENABLE_URIPARSER */
/* URL regexp - I probably found this online */
// TODO: does not support ipv6
#define UC "[a-z0-9_\\-\\.!£$%^&]"
#define PC UC
#define HC "[a-z0-9\\-\\.]"
#define URL_RE "^(\\w+)://(("UC"+)(:("PC"+))?@)?("HC"+)(:([0-9]+))?(/.*)?"
int
urlparse ( const char *str, url_t *url )
{
static regex_t *exp = NULL;
regmatch_t m[12];
@ -61,9 +137,12 @@ urlparse ( const char *str, url_t *url )
copy(url->path, 9);
copy(buf, 8);
url->port = atoi(buf);
*url->query = 0;
*url->frag = 0;
strncpy(url->raw, str, sizeof(url->raw));
return 0;
}
#endif /* ENABLE_URIPARSER */

View file

@ -22,26 +22,23 @@
#include <stdint.h>
// TODO: might be better to find a lib to do this!
// TODO: limits are a bit arbitrary and it's a bit inflexible, but it
// does keep things simple, not having dynamically allocated strings
/* URL structure */
typedef struct url
{
char scheme[16];
char user[128];
char pass[128];
char host[256];
uint16_t port;
char path[256];
char raw[1024];
char scheme[32];
char user[128];
char pass[128];
char host[256];
short port;
char path[256];
char query[1024];
char frag[256];
char raw[2048];
} url_t;
/* URL regexp - I probably found this online */
#define UC "[a-z0-9_\\-\\.!£$%^&]"
#define PC UC
#define HC "[a-z0-9\\-\\.]"
#define URL_RE "^(\\w+)://(("UC"+)(:("PC"+))?@)?("HC"+)(:([0-9]+))?(/.*)?"
int urlparse ( const char *str, url_t *url );
#endif