summaryrefslogtreecommitdiff
path: root/libavformat/http.c
diff options
context:
space:
mode:
authorMichael Niedermayer <michaelni@gmx.at>2014-08-04 03:39:39 +0200
committerMichael Niedermayer <michaelni@gmx.at>2014-08-04 03:44:11 +0200
commitb4d4f8f8266e6407f21a62110905b27d3d3d71da (patch)
tree2e6a76ed3dcc4b938923ec64098ef67b766c42c5 /libavformat/http.c
parentc2a170ac0ddd53516d004cd2bf55ceaffa59642a (diff)
parent6a463e7fb4f028c52d2e2d054f9483f4fff492bc (diff)
Merge commit '6a463e7fb4f028c52d2e2d054f9483f4fff492bc'
* commit '6a463e7fb4f028c52d2e2d054f9483f4fff492bc': http: Refactor http_open_cnx See: c2a170ac0ddd53516d004cd2bf55ceaffa59642a Merged-by: Michael Niedermayer <michaelni@gmx.at>
Diffstat (limited to 'libavformat/http.c')
-rw-r--r--libavformat/http.c37
1 files changed, 24 insertions, 13 deletions
diff --git a/libavformat/http.c b/libavformat/http.c
index 3dffaee43b..18fd9e038d 100644
--- a/libavformat/http.c
+++ b/libavformat/http.c
@@ -138,21 +138,16 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src)
sizeof(HTTPAuthState));
}
-/* return non zero if error */
-static int http_open_cnx(URLContext *h, AVDictionary **options)
+static int http_open_cnx_internal(URLContext *h, AVDictionary **options)
{
const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
char hostname[1024], hoststr[1024], proto[10];
char auth[1024], proxyauth[1024] = "";
char path1[MAX_URL_SIZE];
char buf[1024], urlbuf[MAX_URL_SIZE];
- int port, use_proxy, err, location_changed = 0, redirects = 0, attempts = 0;
- HTTPAuthType cur_auth_type, cur_proxy_auth_type;
+ int port, use_proxy, err, location_changed = 0;
HTTPContext *s = h->priv_data;
- /* fill the dest addr */
-redo:
- /* needed in any case to build the host string */
av_url_split(proto, sizeof(proto), auth, sizeof(auth),
hostname, sizeof(hostname), &port,
path1, sizeof(path1), s->location);
@@ -192,15 +187,32 @@ redo:
err = ffurl_open(&s->hd, buf, AVIO_FLAG_READ_WRITE,
&h->interrupt_callback, options);
if (err < 0)
- goto fail;
+ return err;
}
- cur_auth_type = s->auth_state.auth_type;
- cur_proxy_auth_type = s->auth_state.auth_type;
- if (http_connect(h, path, local_path, hoststr,
- auth, proxyauth, &location_changed) < 0)
+ err = http_connect(h, path, local_path, hoststr,
+ auth, proxyauth, &location_changed);
+ if (err < 0)
+ return err;
+
+ return location_changed;
+}
+
+/* return non zero if error */
+static int http_open_cnx(URLContext *h, AVDictionary **options)
+{
+ HTTPAuthType cur_auth_type, cur_proxy_auth_type;
+ HTTPContext *s = h->priv_data;
+ int location_changed, attempts = 0, redirects = 0;
+redo:
+ location_changed = http_open_cnx_internal(h, options);
+ if (location_changed < 0)
goto fail;
+
attempts++;
+ cur_auth_type = s->auth_state.auth_type;
+ cur_proxy_auth_type = s->auth_state.auth_type;
+
if (s->http_code == 401) {
if ((cur_auth_type == HTTP_AUTH_NONE || s->auth_state.stale) &&
s->auth_state.auth_type != HTTP_AUTH_NONE && attempts < 4) {
@@ -229,7 +241,6 @@ redo:
memset(&s->auth_state, 0, sizeof(s->auth_state));
attempts = 0;
location_changed = 0;
- lower_proto = "tcp";
goto redo;
}
return 0;