-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix http open and http_seek (redirect) authentication bug
- Loading branch information
Showing
2 changed files
with
92 additions
and
53 deletions.
There are no files selected for viewing
92 changes: 92 additions & 0 deletions
92
patches/ffmpeg-n6.1/0023-fix-http-open-and-http_seek-redirect-authentication-.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
From 471ccf6b139063fabacf243501ae0c69000bbe8e Mon Sep 17 00:00:00 2001 | ||
From: qianlongxu <qianlongxu@gmail.com> | ||
Date: Tue, 5 Nov 2024 18:51:46 +0800 | ||
Subject: [PATCH 23] fix http open and http_seek (redirect) authentication bug | ||
|
||
--- | ||
libavformat/http.c | 25 +++++++++++++++++++++++-- | ||
1 file changed, 23 insertions(+), 2 deletions(-) | ||
|
||
diff --git a/libavformat/http.c b/libavformat/http.c | ||
index 06f1bdd..dc0ba67 100644 | ||
--- a/libavformat/http.c | ||
+++ b/libavformat/http.c | ||
@@ -78,6 +78,7 @@ typedef struct HTTPContext { | ||
char *uri; | ||
char *location; | ||
HTTPAuthState auth_state; | ||
+ int auth_type2; | ||
HTTPAuthState proxy_auth_state; | ||
char *http_proxy; | ||
char *headers; | ||
@@ -166,6 +167,7 @@ static const AVOption options[] = { | ||
{ "icy_metadata_packet", "return current ICY metadata packet", OFFSET(icy_metadata_packet), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, AV_OPT_FLAG_EXPORT }, | ||
{ "metadata", "metadata read from the bitstream", OFFSET(metadata), AV_OPT_TYPE_DICT, {0}, 0, 0, AV_OPT_FLAG_EXPORT }, | ||
{ "auth_type", "HTTP authentication type", OFFSET(auth_state.auth_type), AV_OPT_TYPE_INT, { .i64 = HTTP_AUTH_NONE }, HTTP_AUTH_NONE, HTTP_AUTH_BASIC, D | E, "auth_type"}, | ||
+ { "auth_type2", "backup HTTP authentication type for seek request", OFFSET(auth_type2), AV_OPT_TYPE_INT, { .i64 = HTTP_AUTH_NONE }, HTTP_AUTH_NONE, HTTP_AUTH_BASIC, D | E, "auth_type"}, | ||
{ "none", "No auth method set, autodetect", 0, AV_OPT_TYPE_CONST, { .i64 = HTTP_AUTH_NONE }, 0, 0, D | E, "auth_type"}, | ||
{ "basic", "HTTP basic authentication", 0, AV_OPT_TYPE_CONST, { .i64 = HTTP_AUTH_BASIC }, 0, 0, D | E, "auth_type"}, | ||
{ "send_expect_100", "Force sending an Expect: 100-continue header for POST", OFFSET(send_expect_100), AV_OPT_TYPE_BOOL, { .i64 = -1 }, -1, 1, E }, | ||
@@ -699,7 +701,10 @@ static int http_open(URLContext *h, const char *uri, int flags, | ||
HTTPContext *s = h->priv_data; | ||
int ret; | ||
s->app_ctx = (AVApplicationContext *)av_dict_strtoptr(s->app_ctx_intptr); | ||
- | ||
+ if (s->auth_type2 == HTTP_AUTH_NONE) { | ||
+ //backup the init auth_type, when not assign. | ||
+ s->auth_type2 = s->auth_state.auth_type; | ||
+ } | ||
// av_log(NULL, AV_LOG_INFO, "%-*s: %-*s = %s\n", 12, "xql http_open verify", 28, "ijkapplication", s->app_ctx_intptr); | ||
// av_log(NULL, AV_LOG_INFO, "%-*s: %-*s = %s\n", 12, "xql http_open verify", 28, "tcp_hook", s->tcp_hook); | ||
|
||
@@ -1428,6 +1433,7 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, | ||
uint64_t off = s->off; | ||
const char *method; | ||
int send_expect_100 = 0; | ||
+ int cur_auth_type = s->auth_state.auth_type; | ||
|
||
av_bprint_init_for_buffer(&request, s->buffer, sizeof(s->buffer)); | ||
|
||
@@ -1569,9 +1575,19 @@ static int http_connect(URLContext *h, const char *path, const char *local_path, | ||
|
||
if (s->new_location) | ||
s->off = off; | ||
- | ||
err = (off == s->off) ? 0 : -1; | ||
+ | ||
+ //in http_seek_internal func reverted to the original uri,but the s->off is not zero,so err is -1,cause can't goto the 401 authenticate logic. | ||
+ if (err != 0 && cur_auth_type != s->auth_state.auth_type && s->http_code == 401) { | ||
+ //reverte the off,otherwise can't seek the target position. | ||
+ s->off = off; | ||
+ av_log(NULL, AV_LOG_ERROR, "http 401 error,need authenticate,s->off:%llu\n", s->buffer, s->off); | ||
+ err = 0; | ||
+ } | ||
done: | ||
+ if (err != 0) { | ||
+ av_log(NULL, AV_LOG_ERROR, "http error %s\n", s->buffer); | ||
+ } | ||
av_freep(&authstr); | ||
av_freep(&proxyauthstr); | ||
return err; | ||
@@ -1961,6 +1977,8 @@ static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int fo | ||
return s->off; | ||
} | ||
|
||
+ // http_seek use lasest redirect location, because after redirect, reset the auth_state: `memset(&s->auth_state, 0, sizeof(s->auth_state));` | ||
+ | ||
/* if the location changed (redirect), revert to the original uri */ | ||
if (strcmp(s->uri, s->location)) { | ||
char *new_uri; | ||
@@ -1969,6 +1987,9 @@ static int64_t http_seek_internal(URLContext *h, int64_t off, int whence, int fo | ||
return AVERROR(ENOMEM); | ||
av_free(s->location); | ||
s->location = new_uri; | ||
+ if (s->auth_type2 != HTTP_AUTH_NONE) { | ||
+ s->auth_state.auth_type = s->auth_type2; | ||
+ } | ||
} | ||
|
||
/* we save the old context in case the seek fails */ | ||
-- | ||
2.39.5 (Apple Git-154) | ||
|
53 changes: 0 additions & 53 deletions
53
patches/ffmpeg-n6.1/0023-fix-http_seek-use-latest-redirect-location-but-offse.patch
This file was deleted.
Oops, something went wrong.