MCPcopy Create free account
hub / github.com/FFmpeg/FFmpeg / http_open_cnx

Function http_open_cnx

libavformat/http.c:56–121  ·  view source on GitHub ↗

return non zero if error */

Source from the content-addressed store, hash-verified

54
55/* return non zero if error */
56static int http_open_cnx(URLContext *h)
57{
58 const char *path, *proxy_path;
59 char hostname[1024], hoststr[1024];
60 char auth[1024];
61 char path1[1024];
62 char buf[1024];
63 int port, use_proxy, err, location_changed = 0, redirects = 0;
64 HTTPAuthType cur_auth_type;
65 HTTPContext *s = h->priv_data;
66 URLContext *hd = NULL;
67
68 proxy_path = getenv("http_proxy");
69 use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
70 av_strstart(proxy_path, "http://", NULL);
71
72 /* fill the dest addr */
73 redo:
74 /* needed in any case to build the host string */
75 ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
76 path1, sizeof(path1), s->location);
77 ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
78
79 if (use_proxy) {
80 ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
81 NULL, 0, proxy_path);
82 path = s->location;
83 } else {
84 if (path1[0] == '\0')
85 path = "/";
86 else
87 path = path1;
88 }
89 if (port < 0)
90 port = 80;
91
92 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL);
93 err = url_open(&hd, buf, URL_RDWR);
94 if (err < 0)
95 goto fail;
96
97 s->hd = hd;
98 cur_auth_type = s->auth_state.auth_type;
99 if (http_connect(h, path, hoststr, auth, &location_changed) < 0)
100 goto fail;
101 if (s->http_code == 401) {
102 if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) {
103 url_close(hd);
104 goto redo;
105 } else
106 goto fail;
107 }
108 if ((s->http_code == 302 || s->http_code == 303) && location_changed == 1) {
109 /* url moved, get next */
110 url_close(hd);
111 if (redirects++ >= MAX_REDIRECTS)
112 return AVERROR(EIO);
113 location_changed = 0;

Callers 2

http_openFunction · 0.85
http_seekFunction · 0.85

Calls 6

av_strstartFunction · 0.85
ff_url_splitFunction · 0.85
ff_url_joinFunction · 0.85
url_openFunction · 0.85
http_connectFunction · 0.85
url_closeFunction · 0.85

Tested by

no test coverage detected