annotate http.c @ 1492:deaec052eec4 libavformat

Simplify VMD demuxer (but it still does not work right)
author kostya
date Mon, 13 Nov 2006 05:18:19 +0000
parents 4f4bebc36aad
children 0a990429e524
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 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1181
diff changeset
5 * This file is part of FFmpeg.
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1181
diff changeset
6 *
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1181
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1181
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
11 *
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1181
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
15 * Lesser General Public License for more details.
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
16 *
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
1358
0899bfe4105c Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 1181
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
896
edbe5c3717f9 Update licensing information: The FSF changed postal address.
diego
parents: 885
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
20 */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
21 #include "avformat.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
22 #include <unistd.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
23 #include <sys/types.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
24 #include <sys/socket.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
25 #include <netinet/in.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
26 #ifndef __BEOS__
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
27 # include <arpa/inet.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
28 #else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
29 # include "barpainet.h"
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
30 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
31 #include <netdb.h>
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
32
1432
4f4bebc36aad switch to common base64 routines in lavf
gpoirier
parents: 1358
diff changeset
33 #include "base64.h"
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
34
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
35 /* XXX: POST protocol is not completly implemented because ffmpeg use
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
36 only a subset of it */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
37
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
38 //#define DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
39
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
40 /* used for protocol handling */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
41 #define BUFFER_SIZE 1024
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
42 #define URL_SIZE 4096
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
43
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
44 typedef struct {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
45 URLContext *hd;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
46 unsigned char buffer[BUFFER_SIZE], *buf_ptr, *buf_end;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
47 int line_count;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
48 int http_code;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
49 char location[URL_SIZE];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
50 } HTTPContext;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
51
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
52 static int http_connect(URLContext *h, const char *path, const char *hoststr,
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
53 const char *auth);
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
54 static int http_write(URLContext *h, uint8_t *buf, int size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
55
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
56
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
57 /* return non zero if error */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
58 static int http_open(URLContext *h, const char *uri, int flags)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
59 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
60 const char *path, *proxy_path;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
61 char hostname[1024], hoststr[1024];
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
62 char auth[1024];
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
63 char path1[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
64 char buf[1024];
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
65 int port, use_proxy, err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
66 HTTPContext *s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
67 URLContext *hd = NULL;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
68
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
69 h->is_streamed = 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
70
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
71 s = av_malloc(sizeof(HTTPContext));
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
72 if (!s) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
73 return -ENOMEM;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
74 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
75 h->priv_data = s;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
76
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
77 proxy_path = getenv("http_proxy");
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
78 use_proxy = (proxy_path != NULL) && !getenv("no_proxy") &&
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
79 strstart(proxy_path, "http://", NULL);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
80
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
81 /* fill the dest addr */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
82 redo:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
83 /* needed in any case to build the host string */
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
84 url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
85 path1, sizeof(path1), uri);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
86 if (port > 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
87 snprintf(hoststr, sizeof(hoststr), "%s:%d", hostname, port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
88 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
89 pstrcpy(hoststr, sizeof(hoststr), hostname);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
90 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
91
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
92 if (use_proxy) {
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
93 url_split(NULL, 0, auth, sizeof(auth), hostname, sizeof(hostname), &port,
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
94 NULL, 0, proxy_path);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
95 path = uri;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
96 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
97 if (path1[0] == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
98 path = "/";
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
99 else
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
100 path = path1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
101 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
102 if (port < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
103 port = 80;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
104
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
105 snprintf(buf, sizeof(buf), "tcp://%s:%d", hostname, port);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
106 err = url_open(&hd, buf, URL_RDWR);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
107 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
108 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
109
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
110 s->hd = hd;
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
111 if (http_connect(h, path, hoststr, auth) < 0)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
112 goto fail;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
113 if (s->http_code == 303 && s->location[0] != '\0') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
114 /* url moved, get next */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
115 uri = s->location;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
116 url_close(hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
117 goto redo;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
118 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
119 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
120 fail:
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
121 if (hd)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
122 url_close(hd);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
123 av_free(s);
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
124 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
125 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
126
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
127 static int http_getc(HTTPContext *s)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
128 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
129 int len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
130 if (s->buf_ptr >= s->buf_end) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
131 len = url_read(s->hd, s->buffer, BUFFER_SIZE);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
132 if (len < 0) {
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
133 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
134 } else if (len == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
135 return -1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
136 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
137 s->buf_ptr = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
138 s->buf_end = s->buffer + len;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
139 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
140 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
141 return *s->buf_ptr++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
142 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
143
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
144 static int process_line(HTTPContext *s, char *line, int line_count)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
145 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
146 char *tag, *p;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
147
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
148 /* end of header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
149 if (line[0] == '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
150 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
151
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
152 p = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
153 if (line_count == 0) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
154 while (!isspace(*p) && *p != '\0')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
155 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
156 while (isspace(*p))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
157 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
158 s->http_code = strtol(p, NULL, 10);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
159 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
160 printf("http_code=%d\n", s->http_code);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
161 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
162 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
163 while (*p != '\0' && *p != ':')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
164 p++;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
165 if (*p != ':')
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
166 return 1;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
167
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
168 *p = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
169 tag = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
170 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
171 while (isspace(*p))
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
172 p++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
173 if (!strcmp(tag, "Location")) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
174 strcpy(s->location, p);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
175 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
176 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
177 return 1;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
178 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
179
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
180 static int http_connect(URLContext *h, const char *path, const char *hoststr,
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
181 const char *auth)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
182 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
183 HTTPContext *s = h->priv_data;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
184 int post, err, ch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
185 char line[1024], *q;
1181
c2f51d81c72e Fix memleak, patch by I. Po % yyymmmm # gmail O com %
gpoirier
parents: 1180
diff changeset
186 char *auth_b64;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
187
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
188
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
189 /* send http header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
190 post = h->flags & URL_WRONLY;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
191
1432
4f4bebc36aad switch to common base64 routines in lavf
gpoirier
parents: 1358
diff changeset
192 auth_b64 = av_base64_encode((uint8_t *)auth, strlen(auth));
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
193 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
194 "%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
195 "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
196 "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
197 "Host: %s\r\n"
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
198 "Authorization: Basic %s\r\n"
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
199 "\r\n",
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
200 post ? "POST" : "GET",
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
201 path,
327
741c56c608bb using LIBAVFORMAT_IDENT
alex
parents: 229
diff changeset
202 LIBAVFORMAT_IDENT,
511
056991ab9f10 HTTP Authentication Patch by (Petr Doubek <doubek at vision dot ee dot ethz dot ch>)
michael
parents: 482
diff changeset
203 hoststr,
1181
c2f51d81c72e Fix memleak, patch by I. Po % yyymmmm # gmail O com %
gpoirier
parents: 1180
diff changeset
204 auth_b64);
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
205
1181
c2f51d81c72e Fix memleak, patch by I. Po % yyymmmm # gmail O com %
gpoirier
parents: 1180
diff changeset
206 av_freep(&auth_b64);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
207 if (http_write(h, s->buffer, strlen(s->buffer)) < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
208 return AVERROR_IO;
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
209
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
210 /* init input buffer */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
211 s->buf_ptr = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
212 s->buf_end = s->buffer;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
213 s->line_count = 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
214 s->location[0] = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
215 if (post) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
216 sleep(1);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
217 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
218 }
885
da1d5db0ce5c COSMETICS: Remove all trailing whitespace.
diego
parents: 683
diff changeset
219
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
220 /* wait for header */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
221 q = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
222 for(;;) {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
223 ch = http_getc(s);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
224 if (ch < 0)
482
0fdc96c2f2fe sweeping change from -EIO -> AVERROR_IO
melanson
parents: 385
diff changeset
225 return AVERROR_IO;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
226 if (ch == '\n') {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
227 /* process line */
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
228 if (q > line && q[-1] == '\r')
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
229 q--;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
230 *q = '\0';
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
231 #ifdef DEBUG
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
232 printf("header='%s'\n", line);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
233 #endif
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
234 err = process_line(s, line, s->line_count);
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
235 if (err < 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
236 return err;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
237 if (err == 0)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
238 return 0;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
239 s->line_count++;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
240 q = line;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
241 } else {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
242 if ((q - line) < sizeof(line) - 1)
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
243 *q++ = ch;
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
244 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
245 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
246 }
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
247
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
248
65
a58a8a53eb46 * UINTX -> uintx_t INTX -> intx_t
kabi
parents: 0
diff changeset
249 static int http_read(URLContext *h, uint8_t *buf, int size)
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
250 {
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
251 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
252 int len;
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
253
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
254 /* 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
255 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
256 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
257 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
258 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
259 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
260 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
261 } 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
262 len = url_read(s->hd, buf, size);
0
05318cf2e886 renamed libav to libavformat
bellard
parents:
diff changeset
263 }
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
264 return len;
0
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 };