From: spdfrk Date: Sun, 4 Dec 2022 10:23:58 +0000 (+0100) Subject: RTSP redirect support fix and moved to http client X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=061cf95b148680cc01689f1f49d10d3977bda15d;p=thirdparty%2Ftvheadend.git RTSP redirect support fix and moved to http client --- diff --git a/src/httpc.c b/src/httpc.c index 45b96a68f..26353a0be 100644 --- a/src/httpc.c +++ b/src/httpc.c @@ -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; diff --git a/src/input/mpegts/iptv/iptv_rtsp.c b/src/input/mpegts/iptv/iptv_rtsp.c index d917f44a0..66d83c2c7 100644 --- a/src/input/mpegts/iptv/iptv_rtsp.c +++ b/src/input/mpegts/iptv/iptv_rtsp.c @@ -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: