]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
webu/streaming: handle/generate ticket for /play redirects, fixes #3116
authorJaroslav Kysela <perex@perex.cz>
Sun, 27 Sep 2015 17:10:31 +0000 (19:10 +0200)
committerJaroslav Kysela <perex@perex.cz>
Sun, 27 Sep 2015 17:10:47 +0000 (19:10 +0200)
src/webui/webui.c

index 69118d8e7f07d7b1b6f94dc432b639ba63aa04d4..3475e7478aa8512a31dfb709c12919cb4c2edbeb 100644 (file)
@@ -1037,28 +1037,37 @@ page_xspf(http_connection_t *hc, const char *remain, void *opaque)
 {
   size_t maxlen;
   char *buf, *hostpath = http_get_hostpath(hc);
-  const char *title, *profile, *image;
+  const char *title, *profile, *ticket, *image;
   size_t len;
 
   if ((title = http_arg_get(&hc->hc_req_args, "title")) == NULL)
     title = "TVHeadend Stream";
   profile = http_arg_get(&hc->hc_req_args, "profile");
+  ticket  = http_arg_get(&hc->hc_req_args, "ticket");
   image   = http_arg_get(&hc->hc_req_args, "image");
 
   maxlen = strlen(remain) + strlen(title) + 512;
   buf = alloca(maxlen);
 
+  pthread_mutex_lock(&global_lock);
+  if (ticket == NULL) {
+    snprintf(buf, maxlen, "/%s", remain);
+    ticket = access_ticket_create(buf, hc->hc_access);
+  }
   snprintf(buf, maxlen, "\
 <?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n\
 <playlist version=\"1\" xmlns=\"http://xspf.org/ns/0/\">\r\n\
   <trackList>\r\n\
      <track>\r\n\
        <title>%s</title>\r\n\
-       <location>%s/%s%s%s</location>\r\n%s%s%s\
+       <location>%s/%s%s%s%s%s</location>\r\n%s%s%s\
      </track>\r\n\
   </trackList>\r\n\
-</playlist>\r\n", title, hostpath, remain, profile ? "?profile=" : "", profile ?: "",
-  image ? "       <image>" : "", image ?: "", image ? "</image>\r\n" : "");
+</playlist>\r\n", title, hostpath, remain,
+    profile ? "?profile=" : "", profile ?: "",
+    profile ? "&ticket=" : "?ticket=", ticket,
+    image ? "       <image>" : "", image ?: "", image ? "</image>\r\n" : "");
+  pthread_mutex_unlock(&global_lock);
 
   len = strlen(buf);
   http_send_header(hc, 200, "application/xspf+xml", len, 0, NULL, 10, 0, NULL, NULL);
@@ -1077,20 +1086,29 @@ page_m3u(http_connection_t *hc, const char *remain, void *opaque)
 {
   size_t maxlen;
   char *buf, *hostpath = http_get_hostpath(hc);
-  const char *title, *profile;
+  const char *title, *profile, *ticket;
   size_t len;
 
   if ((title = http_arg_get(&hc->hc_req_args, "title")) == NULL)
     title = "TVHeadend Stream";
   profile = http_arg_get(&hc->hc_req_args, "profile");
+  ticket = http_arg_get(&hc->hc_req_args, "ticket");
 
   maxlen = strlen(remain) + strlen(title) + 256;
   buf = alloca(maxlen);
 
+  pthread_mutex_lock(&global_lock);
+  if (ticket == NULL) {
+    snprintf(buf, maxlen, "/%s", remain);
+    ticket = access_ticket_create(buf, hc->hc_access);
+  }
   snprintf(buf, maxlen, "\
 #EXTM3U\r\n\
 #EXTINF:-1,%s\r\n\
-%s/%s%s%s\r\n", title, hostpath, remain, profile ? "?profile=" : "", profile ?: "");
+%s/%s%s%s%s%s\r\n", title, hostpath, remain,
+    profile ? "?profile=" : "", profile ?: "",
+    profile ? "&ticket=" : "?ticket=", ticket);
+  pthread_mutex_unlock(&global_lock);
 
   len = strlen(buf);
   http_send_header(hc, 200, "audio/x-mpegurl", len, 0, NULL, 10, 0, NULL, NULL);
@@ -1436,7 +1454,7 @@ webui_init(int xspf)
 
   http_path_add("/state", NULL, page_statedump, ACCESS_ADMIN);
 
-  http_path_add("/stream",  NULL, http_stream,  ACCESS_STREAMING);
+  http_path_add("/stream",  NULL, http_stream,  ACCESS_ANONYMOUS);
 
   http_path_add("/imagecache", NULL, page_imagecache, ACCESS_ANONYMOUS);