From 4830879ab275795993a8cb1ecba59c4d5c470478 Mon Sep 17 00:00:00 2001 From: Jaroslav Kysela Date: Wed, 9 Apr 2014 19:47:24 +0200 Subject: [PATCH] URL parser fixes --- src/main.c | 1 + src/url.c | 24 +++++++++++++++++++----- src/url.h | 1 + 3 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/main.c b/src/main.c index 534e99cc..5f356381 100644 --- a/src/main.c +++ b/src/main.c @@ -859,6 +859,7 @@ main(int argc, char **argv) tvhftrace("main", hts_settings_done); tvhftrace("main", dvb_done); tvhftrace("main", lang_str_done); + tvhftrace("main", urlparse_done); tvhlog(LOG_NOTICE, "STOP", "Exiting HTS Tvheadend"); tvhlog_end(); diff --git a/src/url.c b/src/url.c index 8398b2da..d4c3c20a 100644 --- a/src/url.c +++ b/src/url.c @@ -90,6 +90,11 @@ urlparse ( const char *str, url_t *url ) return 0; } +void +urlparse_free( void ) +{ +} + /* Fallback to limited support */ #else /* ENABLE_URIPARSER */ @@ -100,25 +105,25 @@ urlparse ( const char *str, url_t *url ) #define HC "[a-z0-9\\-\\.]" #define URL_RE "^([A-Za-z]+)://(("UC"+)(:("PC"+))?@)?("HC"+)(:([0-9]+))?(/[^\\?]*)?(.([^#]*))?(#(.*))?" +static regex_t *urlparse_exp = NULL; int urlparse ( const char *str, url_t *url ) { - static regex_t *exp = NULL; regmatch_t m[16]; char buf[16]; /* Create regexp */ - if (!exp) { - exp = calloc(1, sizeof(regex_t)); - if (regcomp(exp, URL_RE, REG_ICASE | REG_EXTENDED)) { + if (!urlparse_exp) { + urlparse_exp = calloc(1, sizeof(regex_t)); + if (regcomp(urlparse_exp, URL_RE, REG_ICASE | REG_EXTENDED)) { tvherror("url", "failed to compile regexp"); exit(1); } } /* Execute */ - if (regexec(exp, str, ARRAY_SIZE(m), m, 0)) + if (regexec(urlparse_exp, str, ARRAY_SIZE(m), m, 0)) return 1; /* Extract data */ @@ -145,4 +150,13 @@ urlparse ( const char *str, url_t *url ) return 0; } +void +urlparse_done( void ) +{ + if (urlparse_exp) { + regfree(urlparse_exp); + free(urlparse_exp); + } +} + #endif /* ENABLE_URIPARSER */ diff --git a/src/url.h b/src/url.h index 200c5905..dd9aeb22 100644 --- a/src/url.h +++ b/src/url.h @@ -40,5 +40,6 @@ typedef struct url } url_t; int urlparse ( const char *str, url_t *url ); +void urlparse_done ( void ); #endif