]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
URL parser fixes
authorJaroslav Kysela <perex@perex.cz>
Wed, 9 Apr 2014 17:47:24 +0000 (19:47 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 5 May 2014 20:00:35 +0000 (22:00 +0200)
src/main.c
src/url.c
src/url.h

index 534e99ccd34491d791ac9551cdd976a99c1a170e..5f356381def988993b08d51a8dd236a57ca7c7b5 100644 (file)
@@ -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();
index 8398b2dadaeff6ba39f18c8ba0c8c3e0b057af23..d4c3c20aac12859c9fb85fdb581b8cdbe2f589ff 100644 (file)
--- 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 */
index 200c59057967f6b198739e86d8df52eb53fc1da3..dd9aeb22d970d118ebef3a77eaf236f3666a17f6 100644 (file)
--- 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