]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
http: enhance redirect and playlists mux override
authorJaroslav Kysela <perex@perex.cz>
Mon, 4 Aug 2014 19:18:49 +0000 (21:18 +0200)
committerJaroslav Kysela <perex@perex.cz>
Mon, 4 Aug 2014 19:18:49 +0000 (21:18 +0200)
src/http.c
src/http.h
src/webui/simpleui.c
src/webui/webui.c

index 0973ebbacd582b5ae52bd0bc14e197a3bb320b3a..435cf49b81265f6e93b50391e2d3961a9f4cac47 100644 (file)
@@ -355,10 +355,31 @@ http_output_content(http_connection_t *hc, const char *content)
  * Send an HTTP REDIRECT
  */
 void
-http_redirect(http_connection_t *hc, const char *location)
+http_redirect(http_connection_t *hc, const char *location,
+              http_arg_list_t *req_args)
 {
+  const char *loc = location;
   htsbuf_queue_flush(&hc->hc_reply);
 
+  if (req_args) {
+    http_arg_t *ra;
+    htsbuf_queue_t hq;
+    int first = 1;
+    htsbuf_queue_init(&hq, 0);
+    htsbuf_append(&hq, location, strlen(location));
+    htsbuf_append(&hq, "?", 1);
+    TAILQ_FOREACH(ra, req_args, link) {
+      if (!first)
+        htsbuf_append(&hq, "&", 1);
+      first = 0;
+      htsbuf_append_and_escape_url(&hq, ra->key);
+      htsbuf_append(&hq, "=", 1);
+      htsbuf_append_and_escape_url(&hq, ra->val);
+    }
+    loc = htsbuf_to_string(&hq);
+    htsbuf_queue_flush(&hq);
+  }
+
   htsbuf_qprintf(&hc->hc_reply,
                 "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
                 "<HTML><HEAD>\r\n"
@@ -366,9 +387,11 @@ http_redirect(http_connection_t *hc, const char *location)
                 "</HEAD><BODY>\r\n"
                 "Please follow <a href=\"%s\">%s</a>\r\n"
                 "</BODY></HTML>\r\n",
-                location, location);
+                loc, loc);
 
-  http_send_reply(hc, HTTP_STATUS_FOUND, "text/html", NULL, location, 0);
+  http_send_reply(hc, HTTP_STATUS_FOUND, "text/html", NULL, loc, 0);
+  if (loc != location)
+    free((void *)loc);
 }
 
 /**
index ee52cfac044c31aae13a2a195d7c4598f43a0ce5..737916495dab28ccb12d6d8ee3045898f48d4ae7 100644 (file)
@@ -167,7 +167,8 @@ void http_output_html(http_connection_t *hc);
 
 void http_output_content(http_connection_t *hc, const char *content);
 
-void http_redirect(http_connection_t *hc, const char *location);
+void http_redirect(http_connection_t *hc, const char *location,
+                   struct http_arg_list *req_args);
 
 void http_send_header(http_connection_t *hc, int rc, const char *content, 
                      int64_t contentlen, const char *encoding,
index 4bea56e242bf688afd987a241aebe34c78345f12..9bd698d96cd79c792c2f1c6dac930c3a6890dde5 100644 (file)
@@ -307,7 +307,7 @@ page_pvrinfo(http_connection_t *hc, const char *remain, void *opaque)
 
   if(de == NULL) {
     pthread_mutex_unlock(&global_lock);
-    http_redirect(hc, "/simple.html");
+    http_redirect(hc, "/simple.html", &hc->hc_req_args);
     return 0;
   }
 
index 8e3f38d8ec85deb052ddc0f2edc20aba190c8ad9..05d5fbbb28651cabf46d16b761d756b689e426fb 100644 (file)
@@ -141,9 +141,9 @@ static int
 page_root(http_connection_t *hc, const char *remain, void *opaque)
 {
   if(is_client_simple(hc)) {
-    http_redirect(hc, "simple.html");
+    http_redirect(hc, "simple.html", &hc->hc_req_args);
   } else {
-    http_redirect(hc, "extjs.html");
+    http_redirect(hc, "extjs.html", &hc->hc_req_args);
   }
   return 0;
 }
@@ -154,7 +154,7 @@ page_root2(http_connection_t *hc, const char *remain, void *opaque)
   if (!tvheadend_webroot) return 1;
   char *tmp = malloc(strlen(tvheadend_webroot) + 2);
   sprintf(tmp, "%s/", tvheadend_webroot);
-  http_redirect(hc, tmp);
+  http_redirect(hc, tmp, &hc->hc_req_args);
   free(tmp);
   return 0;
 }
@@ -374,7 +374,7 @@ http_channel_playlist(http_connection_t *hc, channel_t *channel)
 
   htsbuf_qprintf(hq, "#EXTM3U\n");
   htsbuf_qprintf(hq, "#EXTINF:-1,%s\n", channel_get_name(channel));
-  htsbuf_qprintf(hq, "http://%s%s?ticket=%s", host, buf, 
+  htsbuf_qprintf(hq, "http://%s%s?ticket=%s", host, buf,
      access_ticket_create(buf));
 
 #if ENABLE_LIBAV
@@ -415,16 +415,22 @@ http_tag_playlist(http_connection_t *hc, channel_tag_t *tag)
   char buf[255];
   channel_tag_mapping_t *ctm;
   const char *host;
+  muxer_container_type_t mc;
 
   hq = &hc->hc_reply;
   host = http_arg_get(&hc->hc_args, "Host");
 
+  mc = muxer_container_txt2type(http_arg_get(&hc->hc_req_args, "mux"));
+  if(mc == MC_UNKNOWN)
+    mc = dvr_config_find_by_name_default("")->dvr_mc;
+
   htsbuf_qprintf(hq, "#EXTM3U\n");
   LIST_FOREACH(ctm, &tag->ct_ctms, ctm_tag_link) {
     snprintf(buf, sizeof(buf), "/stream/channelid/%d", channel_get_id(ctm->ctm_channel));
     htsbuf_qprintf(hq, "#EXTINF:-1,%s\n", channel_get_name(ctm->ctm_channel));
-    htsbuf_qprintf(hq, "http://%s%s?ticket=%s\n", host, buf, 
+    htsbuf_qprintf(hq, "http://%s%s?ticket=%s", host, buf,
        access_ticket_create(buf));
+    htsbuf_qprintf(hq, "&mux=%s\n", muxer_container_type2txt(mc));
   }
 
   http_output_content(hc, "audio/x-mpegurl");
@@ -443,10 +449,15 @@ http_tag_list_playlist(http_connection_t *hc)
   char buf[255];
   channel_tag_t *ct;
   const char *host;
+  muxer_container_type_t mc;
 
   hq = &hc->hc_reply;
   host = http_arg_get(&hc->hc_args, "Host");
 
+  mc = muxer_container_txt2type(http_arg_get(&hc->hc_req_args, "mux"));
+  if(mc == MC_UNKNOWN)
+    mc = dvr_config_find_by_name_default("")->dvr_mc;
+
   htsbuf_qprintf(hq, "#EXTM3U\n");
   TAILQ_FOREACH(ct, &channel_tags, ct_link) {
     if(!ct->ct_enabled || ct->ct_internal)
@@ -454,8 +465,9 @@ http_tag_list_playlist(http_connection_t *hc)
 
     snprintf(buf, sizeof(buf), "/playlist/tagid/%d", ct->ct_identifier);
     htsbuf_qprintf(hq, "#EXTINF:-1,%s\n", ct->ct_name);
-    htsbuf_qprintf(hq, "http://%s%s?ticket=%s\n", host, buf, 
+    htsbuf_qprintf(hq, "http://%s%s?ticket=%s", host, buf,
        access_ticket_create(buf));
+    htsbuf_qprintf(hq, "&mux=%s\n", muxer_container_type2txt(mc));
   }
 
   http_output_content(hc, "audio/x-mpegurl");
@@ -486,10 +498,15 @@ http_channel_list_playlist(http_connection_t *hc)
   channel_t **chlist;
   const char *host;
   int idx = 0, count = 0;
+  muxer_container_type_t mc;
 
   hq = &hc->hc_reply;
   host = http_arg_get(&hc->hc_args, "Host");
 
+  mc = muxer_container_txt2type(http_arg_get(&hc->hc_req_args, "mux"));
+  if(mc == MC_UNKNOWN)
+    mc = dvr_config_find_by_name_default("")->dvr_mc;
+
   CHANNEL_FOREACH(ch)
     count++;
 
@@ -508,8 +525,9 @@ http_channel_list_playlist(http_connection_t *hc)
     snprintf(buf, sizeof(buf), "/stream/channelid/%d", channel_get_id(ch));
 
     htsbuf_qprintf(hq, "#EXTINF:-1,%s\n", channel_get_name(ch));
-    htsbuf_qprintf(hq, "http://%s%s?ticket=%s\n", host, buf, 
+    htsbuf_qprintf(hq, "http://%s%s?ticket=%s", host, buf,
        access_ticket_create(buf));
+    htsbuf_qprintf(hq, "&mux=%s\n", muxer_container_type2txt(mc));
   }
 
   free(chlist);
@@ -557,7 +575,7 @@ http_dvr_list_playlist(http_connection_t *hc)
     htsbuf_qprintf(hq, "#EXT-X-PROGRAM-DATE-TIME:%s\n", buf);
 
     snprintf(buf, sizeof(buf), "/dvrfile/%d", de->de_id);
-    htsbuf_qprintf(hq, "http://%s%s?ticket=%s\n", host, buf, 
+    htsbuf_qprintf(hq, "http://%s%s?ticket=%s\n", host, buf,
        access_ticket_create(buf));
   }
 
@@ -624,7 +642,7 @@ page_http_playlist(http_connection_t *hc, const char *remain, void *opaque)
   channel_tag_t *tag = NULL;
 
   if(!remain) {
-    http_redirect(hc, "/playlist/channels");
+    http_redirect(hc, "/playlist/channels", &hc->hc_req_args);
     return HTTP_STATUS_FOUND;
   }
 
@@ -1231,7 +1249,7 @@ webui_static_content(const char *http_path, const char *source)
 static int
 favicon(http_connection_t *hc, const char *remain, void *opaque)
 {
-  http_redirect(hc, "static/htslogo.png");
+  http_redirect(hc, "static/htslogo.png", NULL);
   return 0;
 }