annotate http.c @ 2304:763527841a80 libavformat

additional tweaks to AC3 probe function. give a higher score to a single frame at the start of the stream. also read all available data in the probe buffer.
author jbr
date Sun, 05 Aug 2007 00:32:19 +0000
parents b21c2af60bc9
children 477419a721a3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
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 */
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
21 #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
22 #include <unistd.h>
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
23 #include "network.h"
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
24
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
25 #include "base64.h"
2189
da71207a7cf1 use new string functions
mru
parents: 2089
diff changeset
26 #include "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
27
1986
cf1622476eb7 typos/grammar
diego
parents: 1934
diff changeset
28 /* XXX: POST protocol is not completely implemented because ffmpeg uses
cf1622476eb7 typos/grammar
diego
parents: 1934
diff changeset
29 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
30
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
31 //#define DEBUG
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
32
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
33 /* 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
34 #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
35 #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
36 #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
37
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
38 typedef struct {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
39 URLContext *hd;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
40 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
41 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
42 int http_code;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
43 offset_t off, filesize;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
44 char location[URL_SIZE];
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
45 } HTTPContext;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
46
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
47 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
48 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
49 static int http_write(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
50
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
51
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
52 /* 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
53 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
54 {
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 *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
56 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
57 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
58 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
59 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
60 int port, use_proxy, err, location_changed = 0, redirects = 0;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
61 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
62 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
63
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
64 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
65 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
66 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
67
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
68 /* 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
69 redo:
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
70 /* needed in any case to build the host string */
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
71 url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
72 path1, sizeof(path1), s->location);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
73 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
74 snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
75 } else {
2189
da71207a7cf1 use new string functions
mru
parents: 2089
diff changeset
76 av_strlcpy(hoststr, hostname, sizeof(hoststr));
1822
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
77 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
78
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
79 if (use_proxy) {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
80 url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
81 NULL, 0, proxy_path);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
82 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
83 } else {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
84 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
85 path = "/";
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
86 else
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
87 path = path1;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
88 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
89 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
90 port = 80;
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 snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
93 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
94 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
95 goto fail;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
96
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
97 s->hd = hd;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
98 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
99 goto fail;
1852
467a411b5d26 make HTTP MOVED messages also work in ffmpeg (302 is essentially the same as 303).
gpoirier
parents: 1822
diff changeset
100 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
101 /* 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
102 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
103 if (redirects++ >= MAX_REDIRECTS)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2193
diff changeset
104 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
105 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
106 goto redo;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
107 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
108 return 0;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
109 fail:
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
110 if (hd)
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
111 url_close(hd);
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2193
diff changeset
112 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
113 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
114
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
115 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
116 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
117 HTTPContext *s;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
118 int ret;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
119
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
120 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
121
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
122 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
123 if (!s) {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
124 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
125 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
126 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
127 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
128 s->off = 0;
2193
5ce5fad0dfac replace the uses of old string functions that Reimar missed
mru
parents: 2189
diff changeset
129 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
130
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
131 ret = http_open_cnx(h);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
132 if (ret != 0)
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
133 av_free (s);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
134 return ret;
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 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
137 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
138 int len;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
139 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
140 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
141 if (len < 0) {
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2193
diff changeset
142 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
143 } 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
144 return -1;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
145 } else {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
146 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
147 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
148 }
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 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
151 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
152
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
153 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
154 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
155 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
156 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
157 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
158
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
159 /* 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
160 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
161 return 0;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
162
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
163 p = line;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
164 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
165 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
166 p++;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
167 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
168 p++;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
169 s->http_code = strtol(p, NULL, 10);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
170 #ifdef DEBUG
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
171 printf("http_code=%d\n", s->http_code);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
172 #endif
1881
a7abdfdb5ed7 handle http error codes
alex
parents: 1853
diff changeset
173 /* error codes are 4xx and 5xx */
a7abdfdb5ed7 handle http error codes
alex
parents: 1853
diff changeset
174 if (s->http_code >= 400 && s->http_code < 600)
a7abdfdb5ed7 handle http error codes
alex
parents: 1853
diff changeset
175 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
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 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
178 p++;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
179 if (*p != ':')
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
180 return 1;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
181
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
182 *p = '\0';
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
183 tag = line;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
184 p++;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
185 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
186 p++;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
187 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
188 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
189 *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
190 } 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
191 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
192 } 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
193 /* "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
194 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
195 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
196 p += 6;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
197 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
198 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
199 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
200 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
201 h->is_streamed = 0; /* we _can_ in fact seek */
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
202 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
203 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
204 return 1;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
205 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
206
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
207 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
208 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
209 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
210 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
211 int post, err, ch;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
212 char line[1024], *q;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
213 char *auth_b64;
1934
aab32293e595 expose av_base64_decode and av_base64_encode
lu_zero
parents: 1909
diff changeset
214 int auth_b64_len = strlen(auth)* 4 / 3 + 12;
1822
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
215 offset_t 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
216
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 /* 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
219 post = h->flags & URL_WRONLY;
1934
aab32293e595 expose av_base64_decode and av_base64_encode
lu_zero
parents: 1909
diff changeset
220 auth_b64 = av_malloc(auth_b64_len);
aab32293e595 expose av_base64_decode and av_base64_encode
lu_zero
parents: 1909
diff changeset
221 av_base64_encode(auth_b64, auth_b64_len, (uint8_t *)auth, strlen(auth));
1822
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
222 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
223 "%s %s HTTP/1.1\r\n"
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
224 "User-Agent: %s\r\n"
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
225 "Accept: */*\r\n"
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
226 "Range: bytes=%"PRId64"-\r\n"
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
227 "Host: %s\r\n"
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
228 "Authorization: Basic %s\r\n"
1853
c704f9d730bf Close connection on EOF
gpoirier
parents: 1852
diff changeset
229 "Connection: close\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
230 "\r\n",
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
231 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
232 path,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
233 LIBAVFORMAT_IDENT,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
234 s->off,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
235 hoststr,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
236 auth_b64);
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 av_freep(&auth_b64);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
239 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
240 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
241
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
242 /* 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
243 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
244 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
245 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
246 s->off = 0;
1909
663139d56669 Properly initialize filesize during input buffer initialization.
diego
parents: 1881
diff changeset
247 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
248 if (post) {
2089
c770b9a1f78f Use usleep instead of sleep, some MinGW versions lack sleep.
alex
parents: 1986
diff changeset
249 usleep(1000*1000);
1822
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
250 return 0;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
251 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
252
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
253 /* 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
254 q = line;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
255 for(;;) {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
256 ch = http_getc(s);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
257 if (ch < 0)
2274
b21c2af60bc9 Replace all occurrences of AVERROR_IO with AVERROR(EIO).
takis
parents: 2193
diff changeset
258 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
259 if (ch == '\n') {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
260 /* process line */
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
261 if (q > line && q[-1] == '\r')
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
262 q--;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
263 *q = '\0';
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
264 #ifdef DEBUG
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
265 printf("header='%s'\n", line);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
266 #endif
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
267 err = process_line(h, line, s->line_count, new_location);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
268 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
269 return err;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
270 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
271 break;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
272 s->line_count++;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
273 q = line;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
274 } else {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
275 if ((q - line) < sizeof(line) - 1)
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
276 *q++ = ch;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
277 }
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
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
280 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
281 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
282
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
283
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
284 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
285 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
286 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
287 int len;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
288
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
289 /* 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
290 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
291 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
292 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
293 len = size;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
294 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
295 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
296 } else {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
297 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
298 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
299 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
300 s->off += len;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
301 return len;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
302 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
303
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
304 /* used only when posting data */
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
305 static int http_write(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
306 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
307 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
308 return url_write(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
309 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
310
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
311 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
312 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
313 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
314 url_close(s->hd);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
315 av_free(s);
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
316 return 0;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
317 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
318
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
319 static offset_t http_seek(URLContext *h, offset_t off, int whence)
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
320 {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
321 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
322 URLContext *old_hd = s->hd;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
323 offset_t old_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
324
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
325 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
326 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
327 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
328 return -1;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
329
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
330 /* we save the old context in case the seek fails */
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
331 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
332 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
333 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
334 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
335 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
336 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
337
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
338 /* 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
339 if (http_open_cnx(h) < 0) {
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
340 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
341 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
342 return -1;
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 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
345 return off;
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
346 }
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
347
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
348 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
349 "http",
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
350 http_open,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
351 http_read,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
352 http_write,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
353 http_seek,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
354 http_close,
2526fc1e568b Reverting stray commit part II, r8156 had the base64 export patch mixed with the nutdec patch
lu_zero
parents:
diff changeset
355 };