]> git.ipfire.org Git - thirdparty/tvheadend.git/commitdiff
RTSP redirect support fix and moved to http client
authorspdfrk <spdfrk123456@gmail.com>
Sun, 4 Dec 2022 10:23:58 +0000 (11:23 +0100)
committerFlole998 <Flole998@users.noreply.github.com>
Fri, 24 Feb 2023 11:22:35 +0000 (12:22 +0100)
src/httpc.c
src/input/mpegts/iptv/iptv_rtsp.c

index 45b96a68fcfb79832f279497b13e640f7da185ef..26353a0be6c87fbfe0833e506f0bdc393e80a98d 100644 (file)
@@ -724,8 +724,7 @@ http_client_finish( http_client_t *hc )
   wcmd = TAILQ_FIRST(&hc->hc_wqueue);
   if (wcmd)
     http_client_cmd_destroy(hc, wcmd);
-  if (hc->hc_version != RTSP_VERSION_1_0 &&
-      hc->hc_handle_location &&
+  if (hc->hc_handle_location &&
       (hc->hc_code == HTTP_STATUS_MOVED ||
        hc->hc_code == HTTP_STATUS_FOUND ||
        hc->hc_code == HTTP_STATUS_SEE_OTHER ||
@@ -1339,14 +1338,17 @@ http_client_simple_reconnect ( http_client_t *hc, const url_t *u,
 
   http_client_flush(hc, 0);
 
-  http_arg_init(&h);
-  hc->hc_hdr_create(hc, &h, u, 0);
   hc->hc_reconnected = 1;
   hc->hc_shutdown    = 0;
   hc->hc_pevents     = 0;
   hc->hc_version     = ver;
 
-  r = http_client_send(hc, hc->hc_cmd, u->path, u->query, &h, NULL, 0);
+  if (ver != RTSP_VERSION_1_0) {
+    http_arg_init(&h);
+    hc->hc_hdr_create(hc, &h, u, 0);
+    r = http_client_send(hc, hc->hc_cmd, u->path, u->query, &h, NULL, 0);
+  } else
+    r = http_client_send(hc, hc->hc_cmd, u->raw, u->query, NULL, NULL, 0);
   if (r < 0)
     return r;
 
index d917f44a0034e5b438ce3a7a53cf0ce4dbe9bf5c..66d83c2c717eec1885ba6c2350f41f0904731b77 100644 (file)
@@ -75,7 +75,6 @@ iptv_rtsp_header ( http_client_t *hc )
 {
   iptv_mux_t *im = hc->hc_aux;
   rtsp_priv_t *rp;
-  url_t url;
   int r;
   char *p;
 
@@ -101,7 +100,11 @@ iptv_rtsp_header ( http_client_t *hc )
     return 0;
   }
 
-  if (hc->hc_cmd == RTSP_CMD_DESCRIBE && hc->hc_code != HTTP_STATUS_OK && hc->hc_code != HTTP_STATUS_SEE_OTHER) {
+  if (hc->hc_cmd == RTSP_CMD_DESCRIBE && hc->hc_code != HTTP_STATUS_OK &&
+      !(hc->hc_code == HTTP_STATUS_MOVED ||
+      hc->hc_code == HTTP_STATUS_FOUND ||
+      hc->hc_code == HTTP_STATUS_SEE_OTHER ||
+      hc->hc_code == HTTP_STATUS_NOT_MODIFIED)) {
     tvherror(LS_IPTV, "DESCRIBE request returned an invalid error code (%d) for '%s', "
              "fall back to GET_PARAMETER in keep alive loop.", hc->hc_code, im->mm_iptv_url_raw);
     hc->hc_rtsp_keep_alive_cmd = RTSP_CMD_GET_PARAMETER;
@@ -114,42 +117,28 @@ iptv_rtsp_header ( http_client_t *hc )
 
   switch (hc->hc_cmd) {
   case RTSP_CMD_DESCRIBE:
-    if(rp->play) {
+    if (rp->play) {
       // Already active, most probably a keep-alive response
       break;
     }
-    if (hc->hc_code == HTTP_STATUS_SEE_OTHER) {
+    if (hc->hc_code == HTTP_STATUS_MOVED ||
+        hc->hc_code == HTTP_STATUS_FOUND ||
+        hc->hc_code == HTTP_STATUS_SEE_OTHER ||
+        hc->hc_code == HTTP_STATUS_NOT_MODIFIED) {
+      // Redirect from RTSP server
       if (!hc->hc_handle_location) {
-        tvherror(LS_IPTV, "received code 303 from RTSP server but redirects disabled '%s'",
-            im->mm_iptv_url_raw);
+        tvherror(LS_IPTV, "received code %d from RTSP server but redirects disabled '%s'",
+            hc->hc_code, im->mm_iptv_url_raw);
         return -1;
       }
-      // Redirect from RTSP server, parse new location and use that instead
       p = http_arg_get(&hc->hc_args, "Location");
       if (p == NULL) {
-        tvherror(LS_IPTV, "received code 303 from RTSP server but no new location given for '%s'",
-            im->mm_iptv_url_raw);
-        return -1;
-      }
-      tvhinfo(LS_IPTV, "received new location from RTSP server '%s' was '%s'", p,
-          im->mm_iptv_url_raw);
-      urlinit(&url);
-      if (urlparse(p, &url) || strncmp(url.scheme, "rtsp", 4) != 0) {
-        tvherror(LS_IPTV, "%s - invalid URL [%s]", im->mm_nicename, p);
-        return -1;
-      }
-      if(rp->path)
-        free(rp->path);
-      if(rp->query)
-        free(rp->query);
-      rp->path = strdup(url.path ? : "");
-      rp->query = strdup(url.query ? : "");
-      urlreset(&url);
-      r = rtsp_describe(hc, rp->path, rp->query);
-      if (r < 0) {
-        tvherror(LS_IPTV, "rtsp: DESCRIBE failed");
+        tvherror(LS_IPTV, "received code %d from RTSP server but no new location given for '%s'",
+            hc->hc_code, im->mm_iptv_url_raw);
         return -1;
       }
+      tvhinfo(LS_IPTV, "received new location from RTSP server (code: %d) '%s' was '%s'",
+          hc->hc_code, p, im->mm_iptv_url_raw);
     }
     break;
   case RTSP_CMD_SETUP: