Mercurial > libavformat.hg
annotate http.c @ 6119:16ca32d9c5f0 libavformat
Use a bitstream filter for converting the extradata syntax when generating an SDP.
This allows to generate correct SDPs for H.264 video in "MP4 syntax".
author | lucabe |
---|---|
date | Fri, 11 Jun 2010 08:01:45 +0000 |
parents | f221641c262a |
children | 6b770ef6cbea |
rev | line source |
---|---|
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
1 /* |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
2 * HTTP protocol for ffmpeg client |
4251
77e0c7511d41
cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents:
3973
diff
changeset
|
3 * Copyright (c) 2000, 2001 Fabrice Bellard |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
4 * |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
5 * This file is part of FFmpeg. |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
6 * |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
7 * FFmpeg is free software; you can redistribute it and/or |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
8 * modify it under the terms of the GNU Lesser General Public |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
9 * License as published by the Free Software Foundation; either |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
10 * version 2.1 of the License, or (at your option) any later version. |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
11 * |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
12 * FFmpeg is distributed in the hope that it will be useful, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
15 * Lesser General Public License for more details. |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
16 * |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
17 * You should have received a copy of the GNU Lesser General Public |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
18 * License along with FFmpeg; if not, write to the Free Software |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
20 */ |
3286 | 21 |
22 #include "libavutil/avstring.h" | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
23 #include "avformat.h" |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
24 #include <unistd.h> |
5059
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
25 #include <strings.h> |
5837
d605f589f0be
move ff_url_split() and ff_url_join() declarations to internal.h
aurel
parents:
5776
diff
changeset
|
26 #include "internal.h" |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
27 #include "network.h" |
6104 | 28 #include "http.h" |
2774
477419a721a3
os_support.h is also needed for usleep and lseek on MinGW.
ramiro
parents:
2274
diff
changeset
|
29 #include "os_support.h" |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
30 #include "httpauth.h" |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
31 |
1986 | 32 /* XXX: POST protocol is not completely implemented because ffmpeg uses |
33 only a subset of it. */ | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
34 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
35 /* used for protocol handling */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
36 #define BUFFER_SIZE 1024 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
37 #define URL_SIZE 4096 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
38 #define MAX_REDIRECTS 8 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
39 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
40 typedef struct { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
41 URLContext *hd; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
42 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
43 int line_count; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
44 int http_code; |
5059
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
45 int64_t chunksize; /**< Used if "Transfer-Encoding: chunked" otherwise -1. */ |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3286
diff
changeset
|
46 int64_t off, filesize; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
47 char location[URL_SIZE]; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
48 HTTPAuthState auth_state; |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
49 int init; |
6104 | 50 unsigned char headers[BUFFER_SIZE]; |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
51 int is_chunked; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
52 } HTTPContext; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
53 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
54 static int http_connect(URLContext *h, const char *path, const char *hoststr, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
55 const char *auth, int *new_location); |
6068 | 56 static int http_write(URLContext *h, const uint8_t *buf, int size); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
57 |
6104 | 58 void ff_http_set_headers(URLContext *h, const char *headers) |
59 { | |
60 HTTPContext *s = h->priv_data; | |
61 int len = strlen(headers); | |
62 | |
63 if (len && strcmp("\r\n", headers + len - 2)) | |
64 av_log(NULL, AV_LOG_ERROR, "No trailing CRLF found in HTTP header.\n"); | |
65 | |
66 av_strlcpy(s->headers, headers, sizeof(s->headers)); | |
67 } | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
68 |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
69 void ff_http_set_chunked_transfer_encoding(URLContext *h, int is_chunked) |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
70 { |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
71 ((HTTPContext*)h->priv_data)->is_chunked = is_chunked; |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
72 } |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
73 |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
74 /* return non zero if error */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
75 static int http_open_cnx(URLContext *h) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
76 { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
77 const char *path, *proxy_path; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
78 char hostname[1024], hoststr[1024]; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
79 char auth[1024]; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
80 char path1[1024]; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
81 char buf[1024]; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
82 int port, use_proxy, err, location_changed = 0, redirects = 0; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
83 HTTPAuthType cur_auth_type; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
84 HTTPContext *s = h->priv_data; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
85 URLContext *hd = NULL; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
86 |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
87 s->init = 1; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
88 proxy_path = getenv("http_proxy"); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
89 use_proxy = (proxy_path != NULL) && !getenv("no_proxy") && |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
90 av_strstart(proxy_path, "http://", NULL); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
91 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
92 /* fill the dest addr */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
93 redo: |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
94 /* needed in any case to build the host string */ |
5775 | 95 ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, |
5776 | 96 path1, sizeof(path1), s->location); |
5756
7c7fe75728dd
Use ff_url_join for assembling URLs, instead of snprintf
mstorsjo
parents:
5544
diff
changeset
|
97 ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
98 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
99 if (use_proxy) { |
5775 | 100 ff_url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port, |
5776 | 101 NULL, 0, proxy_path); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
102 path = s->location; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
103 } else { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
104 if (path1[0] == '\0') |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
105 path = "/"; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
106 else |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
107 path = path1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
108 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
109 if (port < 0) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
110 port = 80; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
111 |
5756
7c7fe75728dd
Use ff_url_join for assembling URLs, instead of snprintf
mstorsjo
parents:
5544
diff
changeset
|
112 ff_url_join(buf, sizeof(buf), "tcp", NULL, hostname, port, NULL); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
113 err = url_open(&hd, buf, URL_RDWR); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
114 if (err < 0) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
115 goto fail; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
116 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
117 s->hd = hd; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
118 cur_auth_type = s->auth_state.auth_type; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
119 if (http_connect(h, path, hoststr, auth, &location_changed) < 0) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
120 goto fail; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
121 if (s->http_code == 401) { |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
122 if (cur_auth_type == HTTP_AUTH_NONE && s->auth_state.auth_type != HTTP_AUTH_NONE) { |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
123 url_close(hd); |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
124 goto redo; |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
125 } else |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
126 goto fail; |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
127 } |
1852
467a411b5d26
make HTTP MOVED messages also work in ffmpeg (302 is essentially the same as 303).
gpoirier
parents:
1822
diff
changeset
|
128 if ((s->http_code == 302 || s->http_code == 303) && location_changed == 1) { |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
129 /* url moved, get next */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
130 url_close(hd); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
131 if (redirects++ >= MAX_REDIRECTS) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2193
diff
changeset
|
132 return AVERROR(EIO); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
133 location_changed = 0; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
134 goto redo; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
135 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
136 return 0; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
137 fail: |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
138 if (hd) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
139 url_close(hd); |
6107 | 140 s->hd = NULL; |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2193
diff
changeset
|
141 return AVERROR(EIO); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
142 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
143 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
144 static int http_open(URLContext *h, const char *uri, int flags) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
145 { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
146 HTTPContext *s; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
147 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
148 h->is_streamed = 1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
149 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
150 s = av_malloc(sizeof(HTTPContext)); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
151 if (!s) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
152 return AVERROR(ENOMEM); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
153 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
154 h->priv_data = s; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
155 s->filesize = -1; |
5059
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
156 s->chunksize = -1; |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
157 s->is_chunked = 1; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
158 s->off = 0; |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
159 s->init = 0; |
6107 | 160 s->hd = NULL; |
6104 | 161 *s->headers = '\0'; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
162 memset(&s->auth_state, 0, sizeof(s->auth_state)); |
2193
5ce5fad0dfac
replace the uses of old string functions that Reimar missed
mru
parents:
2189
diff
changeset
|
163 av_strlcpy(s->location, uri, URL_SIZE); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
164 |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
165 return 0; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
166 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
167 static int http_getc(HTTPContext *s) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
168 { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
169 int len; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
170 if (s->buf_ptr >= s->buf_end) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
171 len = url_read(s->hd, s->buffer, BUFFER_SIZE); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
172 if (len < 0) { |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2193
diff
changeset
|
173 return AVERROR(EIO); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
174 } else if (len == 0) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
175 return -1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
176 } else { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
177 s->buf_ptr = s->buffer; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
178 s->buf_end = s->buffer + len; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
179 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
180 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
181 return *s->buf_ptr++; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
182 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
183 |
5007
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
184 static int http_get_line(HTTPContext *s, char *line, int line_size) |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
185 { |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
186 int ch; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
187 char *q; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
188 |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
189 q = line; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
190 for(;;) { |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
191 ch = http_getc(s); |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
192 if (ch < 0) |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
193 return AVERROR(EIO); |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
194 if (ch == '\n') { |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
195 /* process line */ |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
196 if (q > line && q[-1] == '\r') |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
197 q--; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
198 *q = '\0'; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
199 |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
200 return 0; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
201 } else { |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
202 if ((q - line) < line_size - 1) |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
203 *q++ = ch; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
204 } |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
205 } |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
206 } |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
207 |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
208 static int process_line(URLContext *h, char *line, int line_count, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
209 int *new_location) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
210 { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
211 HTTPContext *s = h->priv_data; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
212 char *tag, *p; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
213 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
214 /* end of header */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
215 if (line[0] == '\0') |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
216 return 0; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
217 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
218 p = line; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
219 if (line_count == 0) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
220 while (!isspace(*p) && *p != '\0') |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
221 p++; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
222 while (isspace(*p)) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
223 p++; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
224 s->http_code = strtol(p, NULL, 10); |
5009 | 225 |
226 dprintf(NULL, "http_code=%d\n", s->http_code); | |
227 | |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
228 /* error codes are 4xx and 5xx, but regard 401 as a success, so we |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
229 * don't abort until all headers have been parsed. */ |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
230 if (s->http_code >= 400 && s->http_code < 600 && s->http_code != 401) |
1881 | 231 return -1; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
232 } else { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
233 while (*p != '\0' && *p != ':') |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
234 p++; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
235 if (*p != ':') |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
236 return 1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
237 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
238 *p = '\0'; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
239 tag = line; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
240 p++; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
241 while (isspace(*p)) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
242 p++; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
243 if (!strcmp(tag, "Location")) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
244 strcpy(s->location, p); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
245 *new_location = 1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
246 } else if (!strcmp (tag, "Content-Length") && s->filesize == -1) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
247 s->filesize = atoll(p); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
248 } else if (!strcmp (tag, "Content-Range")) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
249 /* "bytes $from-$to/$document_size" */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
250 const char *slash; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
251 if (!strncmp (p, "bytes ", 6)) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
252 p += 6; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
253 s->off = atoll(p); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
254 if ((slash = strchr(p, '/')) && strlen(slash) > 0) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
255 s->filesize = atoll(slash+1); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
256 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
257 h->is_streamed = 0; /* we _can_ in fact seek */ |
5059
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
258 } else if (!strcmp (tag, "Transfer-Encoding") && !strncasecmp(p, "chunked", 7)) { |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
259 s->filesize = -1; |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
260 s->chunksize = 0; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
261 } else if (!strcmp (tag, "WWW-Authenticate")) { |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
262 ff_http_auth_handle_header(&s->auth_state, tag, p); |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
263 } else if (!strcmp (tag, "Authentication-Info")) { |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
264 ff_http_auth_handle_header(&s->auth_state, tag, p); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
265 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
266 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
267 return 1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
268 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
269 |
6104 | 270 static inline int has_header(const char *str, const char *header) |
271 { | |
272 /* header + 2 to skip over CRLF prefix. (make sure you have one!) */ | |
273 return av_stristart(str, header + 2, NULL) || av_stristr(str, header); | |
274 } | |
275 | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
276 static int http_connect(URLContext *h, const char *path, const char *hoststr, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
277 const char *auth, int *new_location) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
278 { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
279 HTTPContext *s = h->priv_data; |
5007
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
280 int post, err; |
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
281 char line[1024]; |
6106 | 282 char headers[1024] = ""; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
283 char *authstr = NULL; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3286
diff
changeset
|
284 int64_t off = s->off; |
6104 | 285 int len = 0; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
286 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
287 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
288 /* send http header */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
289 post = h->flags & URL_WRONLY; |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
290 authstr = ff_http_auth_create_response(&s->auth_state, auth, path, |
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
291 post ? "POST" : "GET"); |
6104 | 292 |
293 /* set default headers if needed */ | |
294 if (!has_header(s->headers, "\r\nUser-Agent: ")) | |
295 len += av_strlcatf(headers + len, sizeof(headers) - len, | |
296 "User-Agent: %s\r\n", LIBAVFORMAT_IDENT); | |
297 if (!has_header(s->headers, "\r\nAccept: ")) | |
298 len += av_strlcpy(headers + len, "Accept: */*\r\n", | |
299 sizeof(headers) - len); | |
300 if (!has_header(s->headers, "\r\nRange: ")) | |
301 len += av_strlcatf(headers + len, sizeof(headers) - len, | |
6106 | 302 "Range: bytes=%"PRId64"-\r\n", s->off); |
6104 | 303 if (!has_header(s->headers, "\r\nConnection: ")) |
304 len += av_strlcpy(headers + len, "Connection: close\r\n", | |
305 sizeof(headers)-len); | |
306 if (!has_header(s->headers, "\r\nHost: ")) | |
307 len += av_strlcatf(headers + len, sizeof(headers) - len, | |
308 "Host: %s\r\n", hoststr); | |
309 | |
310 /* now add in custom headers */ | |
311 av_strlcpy(headers+len, s->headers, sizeof(headers)-len); | |
312 | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
313 snprintf(s->buffer, sizeof(s->buffer), |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
314 "%s %s HTTP/1.1\r\n" |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
315 "%s" |
6104 | 316 "%s" |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
317 "%s" |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
318 "\r\n", |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
319 post ? "POST" : "GET", |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
320 path, |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
321 post && s->is_chunked ? "Transfer-Encoding: chunked\r\n" : "", |
6104 | 322 headers, |
323 authstr ? authstr : ""); | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
324 |
5879
61062082488b
Split out http authentication handling into a separate file
mstorsjo
parents:
5837
diff
changeset
|
325 av_freep(&authstr); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
326 if (http_write(h, s->buffer, strlen(s->buffer)) < 0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2193
diff
changeset
|
327 return AVERROR(EIO); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
328 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
329 /* init input buffer */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
330 s->buf_ptr = s->buffer; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
331 s->buf_end = s->buffer; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
332 s->line_count = 0; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
333 s->off = 0; |
1909
663139d56669
Properly initialize filesize during input buffer initialization.
diego
parents:
1881
diff
changeset
|
334 s->filesize = -1; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
335 if (post) { |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
336 /* always use chunked encoding for upload data */ |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
337 s->chunksize = 0; |
6080 | 338 /* Pretend that it did work. We didn't read any header yet, since |
339 * we've still to send the POST data, but the code calling this | |
340 * function will check http_code after we return. */ | |
341 s->http_code = 200; | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
342 return 0; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
343 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
344 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
345 /* wait for header */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
346 for(;;) { |
5007
1d5f8836c8a8
Introduce http_get_line and modify http_connect to use http_get_line.
jai_menon
parents:
4640
diff
changeset
|
347 if (http_get_line(s, line, sizeof(line)) < 0) |
2274
b21c2af60bc9
Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents:
2193
diff
changeset
|
348 return AVERROR(EIO); |
5009 | 349 |
350 dprintf(NULL, "header='%s'\n", line); | |
351 | |
5008 | 352 err = process_line(h, line, s->line_count, new_location); |
353 if (err < 0) | |
354 return err; | |
355 if (err == 0) | |
356 break; | |
357 s->line_count++; | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
358 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
359 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
360 return (off == s->off) ? 0 : -1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
361 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
362 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
363 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
364 static int http_read(URLContext *h, uint8_t *buf, int size) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
365 { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
366 HTTPContext *s = h->priv_data; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
367 int len; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
368 |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
369 if (!s->init) { |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
370 int ret = http_open_cnx(h); |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
371 if (ret != 0) |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
372 return ret; |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
373 } |
6117
f221641c262a
Make sure the http protocol handler returns errors if a delayed open had failed
mstorsjo
parents:
6115
diff
changeset
|
374 if (!s->hd) |
f221641c262a
Make sure the http protocol handler returns errors if a delayed open had failed
mstorsjo
parents:
6115
diff
changeset
|
375 return AVERROR(EIO); |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
376 |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
377 /* A size of zero can be used to force |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
378 * initializaton of the connection. */ |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
379 if (!size) |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
380 return 0; |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
381 |
5059
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
382 if (s->chunksize >= 0) { |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
383 if (!s->chunksize) { |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
384 char line[32]; |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
385 |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
386 for(;;) { |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
387 do { |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
388 if (http_get_line(s, line, sizeof(line)) < 0) |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
389 return AVERROR(EIO); |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
390 } while (!*line); /* skip CR LF from last chunk */ |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
391 |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
392 s->chunksize = strtoll(line, NULL, 16); |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
393 |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
394 dprintf(NULL, "Chunked encoding data size: %"PRId64"'\n", s->chunksize); |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
395 |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
396 if (!s->chunksize) |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
397 return 0; |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
398 break; |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
399 } |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
400 } |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
401 size = FFMIN(size, s->chunksize); |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
402 } |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
403 /* read bytes from input buffer first */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
404 len = s->buf_end - s->buf_ptr; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
405 if (len > 0) { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
406 if (len > size) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
407 len = size; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
408 memcpy(buf, s->buf_ptr, len); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
409 s->buf_ptr += len; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
410 } else { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
411 len = url_read(s->hd, buf, size); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
412 } |
5059
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
413 if (len > 0) { |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
414 s->off += len; |
5059
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
415 if (s->chunksize > 0) |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
416 s->chunksize -= len; |
a5b8b8cce2dd
Add support for "chunked" data blocks. Patch by Peter Holik (peter holik at).
rbultje
parents:
5009
diff
changeset
|
417 } |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
418 return len; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
419 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
420 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
421 /* used only when posting data */ |
6068 | 422 static int http_write(URLContext *h, const uint8_t *buf, int size) |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
423 { |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
424 char temp[11] = ""; /* 32-bit hex + CRLF + nul */ |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
425 int ret; |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
426 char crlf[] = "\r\n"; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
427 HTTPContext *s = h->priv_data; |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
428 |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
429 if (!s->init) { |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
430 int ret = http_open_cnx(h); |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
431 if (ret != 0) |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
432 return ret; |
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
433 } |
6117
f221641c262a
Make sure the http protocol handler returns errors if a delayed open had failed
mstorsjo
parents:
6115
diff
changeset
|
434 if (!s->hd) |
f221641c262a
Make sure the http protocol handler returns errors if a delayed open had failed
mstorsjo
parents:
6115
diff
changeset
|
435 return AVERROR(EIO); |
6103
447fe3440991
Modify the behaviour of http_open to implicitly delay connection establishment
mstorsjo
parents:
6080
diff
changeset
|
436 |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
437 if (s->chunksize == -1) { |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
438 /* headers are sent without any special encoding */ |
5527 | 439 return url_write(s->hd, buf, size); |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
440 } |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
441 |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
442 /* silently ignore zero-size data since chunk encoding that would |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
443 * signal EOF */ |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
444 if (size > 0) { |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
445 /* upload data using chunked encoding */ |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
446 if(s->is_chunked) { |
6110 | 447 snprintf(temp, sizeof(temp), "%x\r\n", size); |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
448 if ((ret = url_write(s->hd, temp, strlen(temp))) < 0) |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
449 return ret; |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
450 } |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
451 |
6108
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
452 if ((ret = url_write(s->hd, buf, size)) < 0) |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
453 return ret; |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
454 |
117b1826ce8e
Add support for disabling chunked transfer encoding for the http protocol
mstorsjo
parents:
6107
diff
changeset
|
455 if (s->is_chunked && (ret = url_write(s->hd, crlf, sizeof(crlf) - 1)) < 0) |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
456 return ret; |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
457 } |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
458 return size; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
459 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
460 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
461 static int http_close(URLContext *h) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
462 { |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
463 int ret = 0; |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
464 char footer[] = "0\r\n\r\n"; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
465 HTTPContext *s = h->priv_data; |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
466 |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
467 /* signal end of chunked encoding if used */ |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
468 if ((h->flags & URL_WRONLY) && s->chunksize != -1) { |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
469 ret = url_write(s->hd, footer, sizeof(footer) - 1); |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
470 ret = ret > 0 ? 0 : ret; |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
471 } |
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
472 |
6107 | 473 if (s->hd) |
474 url_close(s->hd); | |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
475 av_free(s); |
5526
f09594ca5f77
Use chunked encoding for HTTP uploads. Patch by Tomas H¸«£rdin
rbultje
parents:
5059
diff
changeset
|
476 return ret; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
477 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
478 |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3286
diff
changeset
|
479 static int64_t http_seek(URLContext *h, int64_t off, int whence) |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
480 { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
481 HTTPContext *s = h->priv_data; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
482 URLContext *old_hd = s->hd; |
3973
549a09cf23fe
Remove offset_t typedef and use int64_t directly instead.
diego
parents:
3286
diff
changeset
|
483 int64_t old_off = s->off; |
5544
fc48f8bfbf2e
restore old buffer content when seek failed in http protocol, fix issue #1631
bcoudurier
parents:
5527
diff
changeset
|
484 uint8_t old_buf[BUFFER_SIZE]; |
fc48f8bfbf2e
restore old buffer content when seek failed in http protocol, fix issue #1631
bcoudurier
parents:
5527
diff
changeset
|
485 int old_buf_size; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
486 |
6115 | 487 if (!s->init) { |
488 int ret = http_open_cnx(h); | |
489 if (ret != 0) | |
490 return ret; | |
491 } | |
6117
f221641c262a
Make sure the http protocol handler returns errors if a delayed open had failed
mstorsjo
parents:
6115
diff
changeset
|
492 if (!s->hd) |
f221641c262a
Make sure the http protocol handler returns errors if a delayed open had failed
mstorsjo
parents:
6115
diff
changeset
|
493 return AVERROR(EIO); |
6115 | 494 |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
495 if (whence == AVSEEK_SIZE) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
496 return s->filesize; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
497 else if ((s->filesize == -1 && whence == SEEK_END) || h->is_streamed) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
498 return -1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
499 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
500 /* we save the old context in case the seek fails */ |
5544
fc48f8bfbf2e
restore old buffer content when seek failed in http protocol, fix issue #1631
bcoudurier
parents:
5527
diff
changeset
|
501 old_buf_size = s->buf_end - s->buf_ptr; |
fc48f8bfbf2e
restore old buffer content when seek failed in http protocol, fix issue #1631
bcoudurier
parents:
5527
diff
changeset
|
502 memcpy(old_buf, s->buf_ptr, old_buf_size); |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
503 s->hd = NULL; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
504 if (whence == SEEK_CUR) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
505 off += s->off; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
506 else if (whence == SEEK_END) |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
507 off += s->filesize; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
508 s->off = off; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
509 |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
510 /* if it fails, continue on old connection */ |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
511 if (http_open_cnx(h) < 0) { |
5544
fc48f8bfbf2e
restore old buffer content when seek failed in http protocol, fix issue #1631
bcoudurier
parents:
5527
diff
changeset
|
512 memcpy(s->buffer, old_buf, old_buf_size); |
fc48f8bfbf2e
restore old buffer content when seek failed in http protocol, fix issue #1631
bcoudurier
parents:
5527
diff
changeset
|
513 s->buf_ptr = s->buffer; |
fc48f8bfbf2e
restore old buffer content when seek failed in http protocol, fix issue #1631
bcoudurier
parents:
5527
diff
changeset
|
514 s->buf_end = s->buffer + old_buf_size; |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
515 s->hd = old_hd; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
516 s->off = old_off; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
517 return -1; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
518 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
519 url_close(old_hd); |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
520 return off; |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
521 } |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
522 |
4640
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
523 static int |
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
524 http_get_file_handle(URLContext *h) |
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
525 { |
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
526 HTTPContext *s = h->priv_data; |
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
527 return url_get_file_handle(s->hd); |
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
528 } |
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
529 |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
530 URLProtocol http_protocol = { |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
531 "http", |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
532 http_open, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
533 http_read, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
534 http_write, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
535 http_seek, |
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
536 http_close, |
4640
b34d9614b887
Add url_get_file_handle(), which is used to get the file descriptor
rbultje
parents:
4630
diff
changeset
|
537 .url_get_file_handle = http_get_file_handle, |
1822
2526fc1e568b
Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff
changeset
|
538 }; |