annotate http.c @ 105:d7ab50ab9376 libavformat

native Indeo3 decoder implementation
author tmmm
date Tue, 15 Apr 2003 10:12:38 +0000
parents ff560598f12d
children b0771ae979e3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
1 /*
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
2 * HTTP protocol for ffmpeg client
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
3 * Copyright (c) 2000, 2001 Fabrice Bellard.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
4 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * version 2 of the License, or (at your option) any later version.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 * License along with this library; if not, write to the Free Software
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
18 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
19 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include <ctype.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <sys/types.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <sys/socket.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <netinet/in.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #ifndef __BEOS__
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 # include <arpa/inet.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 # include "barpainet.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #include <netdb.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 /* XXX: POST protocol is not completly implemented because ffmpeg use
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34 only a subset of it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 /* used for protocol handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 #define BUFFER_SIZE 1024
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 #define URL_SIZE 4096
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 URLContext *hd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 int line_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 int http_code;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 char location[URL_SIZE];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 } HTTPContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 static int http_connect(URLContext *h, const char *path, const char *hoststr);
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
51 static int http_write(URLContext *h, uint8_t *buf, int size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 /* return non zero if error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 static int http_open(URLContext *h, const char *uri, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 const char *path, *proxy_path;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 char hostname[1024], hoststr[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 char path1[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 char buf[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 int port, use_proxy, err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 HTTPContext *s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 URLContext *hd = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 h->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 s = av_malloc(sizeof(HTTPContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 if (!s) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 h->priv_data = s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 proxy_path = getenv("http_proxy");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 strstart(proxy_path, "http://", NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 /* fill the dest addr */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 redo:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 /* needed in any case to build the host string */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 url_split(NULL, 0, hostname, sizeof(hostname), &port,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 path1, sizeof(path1), uri);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 if (port > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 pstrcpy(hoststr, sizeof(hoststr), hostname);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 if (use_proxy) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 url_split(NULL, 0, hostname, sizeof(hostname), &port,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 NULL, 0, proxy_path);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 path = uri;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 if (path1[0] == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 path = "/";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 path = path1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 if (port < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 port = 80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 err = url_open(&hd, buf, URL_RDWR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 s->hd = hd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 if (http_connect(h, path, hoststr) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 if (s->http_code == 303 && s->location[0] != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 /* url moved, get next */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 uri = s->location;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 url_close(hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 goto redo;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 if (hd)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 url_close(hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 static int http_getc(HTTPContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 if (s->buf_ptr >= s->buf_end) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 len = url_read(s->hd, s->buffer, BUFFER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 if (len < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 } else if (len == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 s->buf_ptr = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 s->buf_end = s->buffer + len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 return *s->buf_ptr++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 static int process_line(HTTPContext *s, char *line, int line_count)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 char *tag, *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 /* end of header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 if (line[0] == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 p = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 if (line_count == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 while (!isspace(*p) && *p != '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 while (isspace(*p))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 s->http_code = strtol(p, NULL, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 printf("http_code=%d\n", s->http_code);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 while (*p != '\0' && *p != ':')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 if (*p != ':')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 *p = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 tag = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 while (isspace(*p))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 if (!strcmp(tag, "Location")) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 strcpy(s->location, p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 static int http_connect(URLContext *h, const char *path, const char *hoststr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 int post, err, ch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180 char line[1024], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 /* send http header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 post = h->flags & URL_WRONLY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
186 snprintf(s->buffer, sizeof(s->buffer),
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187 "%s %s HTTP/1.0\n"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188 "User-Agent: FFmpeg %s\n"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 "Accept: */*\n"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 "Host: %s\n"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 "\n",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 post ? "POST" : "GET",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 path,
81
ff560598f12d simplified
al3x
parents: 65
diff changeset
194 LIBAVFORMAT_VERSION,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195 hoststr);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
197 if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 /* init input buffer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 s->buf_ptr = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 s->buf_end = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 s->line_count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 s->location[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 if (post) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 sleep(1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 /* wait for header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 q = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 ch = http_getc(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 if (ch < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 return -EIO;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 if (ch == '\n') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 /* process line */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 if (q > line && q[-1] == '\r')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 q--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 printf("header='%s'\n", line);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 err = process_line(s, line, s->line_count);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 if (err == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 s->line_count++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 q = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 if ((q - line) < sizeof(line) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 *q++ = ch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
239 static int http_read(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 int size1, len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 size1 = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 while (size > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 /* read bytes from input buffer first */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247 len = s->buf_end - s->buf_ptr;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248 if (len > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
249 if (len > size)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 len = size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 memcpy(buf, s->buf_ptr, len);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 s->buf_ptr += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 len = url_read (s->hd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255 if (len < 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 return len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
257 } else if (len == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 break;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 size -= len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262 buf += len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 return size1 - size;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 /* used only when posting data */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
268 static int http_write(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 return url_write(s->hd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 static int http_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 url_close(s->hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
280 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
281
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
282 URLProtocol http_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
283 "http",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
284 http_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
285 http_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
286 http_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
287 NULL, /* seek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
288 http_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
289 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
290