annotate http.c @ 499:3e85b3d73cda libavformat

disable mov_read_elst
author michael
date Sat, 17 Jul 2004 16:35:47 +0000
parents 0fdc96c2f2fe
children 056991ab9f10
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 <sys/types.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <sys/socket.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <netinet/in.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #ifndef __BEOS__
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 # include <arpa/inet.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 # include "barpainet.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 #include <netdb.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32 /* XXX: POST protocol is not completly implemented because ffmpeg use
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
33 only a subset of it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37 /* used for protocol handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 #define BUFFER_SIZE 1024
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39 #define URL_SIZE 4096
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 URLContext *hd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 int line_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 int http_code;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 char location[URL_SIZE];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 } HTTPContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 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
50 static int http_write(URLContext *h, uint8_t *buf, int size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
52
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
53 /* return non zero if error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
54 static int http_open(URLContext *h, const char *uri, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56 const char *path, *proxy_path;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 char hostname[1024], hoststr[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 char path1[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 char buf[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 int port, use_proxy, err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 HTTPContext *s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
62 URLContext *hd = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 h->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 s = av_malloc(sizeof(HTTPContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 if (!s) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70 h->priv_data = s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 proxy_path = getenv("http_proxy");
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 strstart(proxy_path, "http://", NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76 /* fill the dest addr */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 redo:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
78 /* needed in any case to build the host string */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 url_split(NULL, 0, hostname, sizeof(hostname), &port,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80 path1, sizeof(path1), uri);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 if (port > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
84 pstrcpy(hoststr, sizeof(hoststr), hostname);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 if (use_proxy) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 url_split(NULL, 0, hostname, sizeof(hostname), &port,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 NULL, 0, proxy_path);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 path = uri;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 if (path1[0] == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
93 path = "/";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 path = path1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 if (port < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 port = 80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 err = url_open(&hd, buf, URL_RDWR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 s->hd = hd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 if (http_connect(h, path, hoststr) < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 if (s->http_code == 303 && s->location[0] != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109 /* url moved, get next */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 uri = s->location;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
111 url_close(hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 goto redo;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 if (hd)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 url_close(hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 av_free(s);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
119 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 static int http_getc(HTTPContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
124 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 if (s->buf_ptr >= s->buf_end) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126 len = url_read(s->hd, s->buffer, BUFFER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 if (len < 0) {
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
128 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 } else if (len == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 s->buf_ptr = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
133 s->buf_end = s->buffer + len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 return *s->buf_ptr++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 static int process_line(HTTPContext *s, char *line, int line_count)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 char *tag, *p;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143 /* end of header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 if (line[0] == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
147 p = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 if (line_count == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 while (!isspace(*p) && *p != '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151 while (isspace(*p))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 s->http_code = strtol(p, NULL, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 printf("http_code=%d\n", s->http_code);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 while (*p != '\0' && *p != ':')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 if (*p != ':')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 *p = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 tag = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
165 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 while (isspace(*p))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
167 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 if (!strcmp(tag, "Location")) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 strcpy(s->location, p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 static int http_connect(URLContext *h, const char *path, const char *hoststr)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 int post, err, ch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179 char line[1024], *q;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
180
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
181
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 /* send http header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 post = h->flags & URL_WRONLY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 snprintf(s->buffer, sizeof(s->buffer),
385
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
186 "%s %s HTTP/1.0\r\n"
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
187 "User-Agent: %s\r\n"
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
188 "Accept: */*\r\n"
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
189 "Host: %s\r\n"
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
190 "\r\n",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191 post ? "POST" : "GET",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
192 path,
327
741c56c608bb using LIBAVFORMAT_IDENT
alex
parents: 229
diff changeset
193 LIBAVFORMAT_IDENT,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
194 hoststr);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
195
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
196 if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
197 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
198
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
199 /* init input buffer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 s->buf_ptr = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 s->buf_end = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
202 s->line_count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
203 s->location[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
204 if (post) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
205 sleep(1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
206 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
208
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
209 /* wait for header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 q = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 ch = http_getc(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 if (ch < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
214 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 if (ch == '\n') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 /* process line */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 if (q > line && q[-1] == '\r')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 q--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
219 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 printf("header='%s'\n", line);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 err = process_line(s, line, s->line_count);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
225 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 if (err == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 s->line_count++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 q = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 if ((q - line) < sizeof(line) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 *q++ = ch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 }
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
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
238 static int http_read(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 HTTPContext *s = h->priv_data;
385
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
241 int len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242
385
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
243 /* read bytes from input buffer first */
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
244 len = s->buf_end - s->buf_ptr;
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
245 if (len > 0) {
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
246 if (len > size)
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
247 len = size;
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
248 memcpy(buf, s->buf_ptr, len);
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
249 s->buf_ptr += len;
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
250 } else {
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
251 len = url_read(s->hd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
252 }
385
2f56d366a787 no read loop tcp/http and http CRLF fix by (Leon van Stuivenberg <l dot vanstuivenberg at chello dot nl>)
michael
parents: 327
diff changeset
253 return len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
254 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
255
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
256 /* used only when posting data */
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
257 static int http_write(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
258 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
259 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
260 return url_write(s->hd, buf, size);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
261 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
262
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 static int http_close(URLContext *h)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
264 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
265 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
266 url_close(s->hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
267 av_free(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
268 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
269 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
270
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
271 URLProtocol http_protocol = {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
272 "http",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
273 http_open,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
274 http_read,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
275 http_write,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
276 NULL, /* seek */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
277 http_close,
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
278 };
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
279