Mercurial > mplayer.hg
annotate stream/http.c @ 36673:1285e5ce2054
Prettify the skin browser.
Use the same design as with the other similar lists
(available audio and video drivers, playlist).
author | ib |
---|---|
date | Fri, 31 Jan 2014 17:08:39 +0000 |
parents | 389d43c448b3 |
children |
rev | line source |
---|---|
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
1 /* |
902 | 2 * HTTP Helper |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
3 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
4 * Copyright (C) 2001 Bertrand Baudet <bertrand_baudet@yahoo.com> |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
5 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
6 * This file is part of MPlayer. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
7 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
8 * MPlayer is free software; you can redistribute it and/or modify |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
9 * it under the terms of the GNU General Public License as published by |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
10 * the Free Software Foundation; either version 2 of the License, or |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
11 * (at your option) any later version. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
12 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
13 * MPlayer is distributed in the hope that it will be useful, |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
16 * GNU General Public License for more details. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
17 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
18 * You should have received a copy of the GNU General Public License along |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
19 * with MPlayer; if not, write to the Free Software Foundation, Inc., |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
30357
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
902 | 21 */ |
22 | |
15614
a4a46131ee71
Change header order to avoid compile error because of STREAM_SEEK
reimar
parents:
15585
diff
changeset
|
23 #include "config.h" |
a4a46131ee71
Change header order to avoid compile error because of STREAM_SEEK
reimar
parents:
15585
diff
changeset
|
24 |
870 | 25 #include <stdio.h> |
26 #include <stdlib.h> | |
27 #include <string.h> | |
35903 | 28 #include <strings.h> |
15585 | 29 #include <unistd.h> |
870 | 30 |
28402 | 31 #if !HAVE_WINSOCK2_H |
27472
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
32 #else |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
33 #include <winsock2.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
34 #include <ws2tcpip.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
35 #endif |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
36 |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
37 #include "http.h" |
4816
f1dea39a50bb
Fixed the http response parser when the http header only has the HTTP
bertrand
parents:
4311
diff
changeset
|
38 #include "url.h" |
5915 | 39 #include "mp_msg.h" |
870 | 40 |
15585 | 41 #include "stream.h" |
19312
ab8d6b6deb63
proper inclusion of demuxer.h (including libmpdemux in Makefile only was to make previous split easier)
ben
parents:
19271
diff
changeset
|
42 #include "libmpdemux/demuxer.h" |
15585 | 43 #include "network.h" |
44 #include "help_mp.h" | |
45 | |
32585 | 46 #include "libavutil/base64.h" |
15585 | 47 |
16013 | 48 typedef struct { |
49 unsigned metaint; | |
50 unsigned metapos; | |
51 int is_ultravox; | |
52 } scast_data_t; | |
53 | |
54 /** | |
55 * \brief first read any data from sc->buffer then from fd | |
56 * \param fd file descriptor to read data from | |
57 * \param buffer buffer to read into | |
58 * \param len how many bytes to read | |
59 * \param sc streaming control containing buffer to read from first | |
60 * \return len unless there is a read error or eof | |
61 */ | |
62 static unsigned my_read(int fd, char *buffer, int len, streaming_ctrl_t *sc) { | |
63 unsigned pos = 0; | |
64 unsigned cp_len = sc->buffer_size - sc->buffer_pos; | |
65 if (cp_len > len) | |
66 cp_len = len; | |
67 memcpy(buffer, &sc->buffer[sc->buffer_pos], cp_len); | |
68 sc->buffer_pos += cp_len; | |
69 pos += cp_len; | |
70 while (pos < len) { | |
16070 | 71 int ret = recv(fd, &buffer[pos], len - pos, 0); |
16013 | 72 if (ret <= 0) |
73 break; | |
74 pos += ret; | |
75 } | |
76 return pos; | |
77 } | |
78 | |
16032 | 79 /** |
80 * \brief read and process (i.e. discard *g*) a block of ultravox metadata | |
81 * \param fd file descriptor to read from | |
82 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd | |
83 * \return number of real data before next metadata block starts or 0 on error | |
34343 | 84 * |
85 * You can use unsv://samples.mplayerhq.hu/V-codecs/VP5/vp5_artefacts.nsv to | |
86 * test. | |
16032 | 87 */ |
16013 | 88 static unsigned uvox_meta_read(int fd, streaming_ctrl_t *sc) { |
89 unsigned metaint; | |
16070 | 90 unsigned char info[6] = {0, 0, 0, 0, 0, 0}; |
91 int info_read; | |
16013 | 92 do { |
16070 | 93 info_read = my_read(fd, info, 1, sc); |
16013 | 94 if (info[0] == 0x00) |
16070 | 95 info_read = my_read(fd, info, 6, sc); |
16013 | 96 else |
16070 | 97 info_read += my_read(fd, &info[1], 5, sc); |
98 if (info_read != 6) // read error or eof | |
99 return 0; | |
16031
c2e78215f0d9
Ultravox improvements according to specs (didn't know they existed *g*)
reimar
parents:
16013
diff
changeset
|
100 // sync byte and reserved flags |
c2e78215f0d9
Ultravox improvements according to specs (didn't know they existed *g*)
reimar
parents:
16013
diff
changeset
|
101 if (info[0] != 0x5a || (info[1] & 0xfc) != 0x00) { |
16013 | 102 mp_msg(MSGT_DEMUXER, MSGL_ERR, "Invalid or unknown uvox metadata\n"); |
103 return 0; | |
104 } | |
16031
c2e78215f0d9
Ultravox improvements according to specs (didn't know they existed *g*)
reimar
parents:
16013
diff
changeset
|
105 if (info[1] & 0x01) |
c2e78215f0d9
Ultravox improvements according to specs (didn't know they existed *g*)
reimar
parents:
16013
diff
changeset
|
106 mp_msg(MSGT_DEMUXER, MSGL_WARN, "Encrypted ultravox data\n"); |
16013 | 107 metaint = info[4] << 8 | info[5]; |
16031
c2e78215f0d9
Ultravox improvements according to specs (didn't know they existed *g*)
reimar
parents:
16013
diff
changeset
|
108 if ((info[3] & 0xf) < 0x07) { // discard any metadata nonsense |
16013 | 109 char *metabuf = malloc(metaint); |
110 my_read(fd, metabuf, metaint, sc); | |
111 free(metabuf); | |
112 } | |
16031
c2e78215f0d9
Ultravox improvements according to specs (didn't know they existed *g*)
reimar
parents:
16013
diff
changeset
|
113 } while ((info[3] & 0xf) < 0x07); |
16013 | 114 return metaint; |
115 } | |
116 | |
117 /** | |
118 * \brief read one scast meta data entry and print it | |
16032 | 119 * \param fd file descriptor to read from |
120 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd | |
16013 | 121 */ |
122 static void scast_meta_read(int fd, streaming_ctrl_t *sc) { | |
123 unsigned char tmp = 0; | |
124 unsigned metalen; | |
125 my_read(fd, &tmp, 1, sc); | |
126 metalen = tmp * 16; | |
127 if (metalen > 0) { | |
30938 | 128 int i; |
30941
fb3bde3ec3a8
Change type to uint8_t to avoid checks depending on char signedness.
reimar
parents:
30938
diff
changeset
|
129 uint8_t *info = malloc(metalen + 1); |
16013 | 130 unsigned nlen = my_read(fd, info, metalen, sc); |
30938 | 131 // avoid breaking the user's terminal too much |
132 if (nlen > 256) nlen = 256; | |
133 for (i = 0; i < nlen; i++) | |
134 if (info[i] && info[i] < 32) info[i] = '?'; | |
16013 | 135 info[nlen] = 0; |
136 mp_msg(MSGT_DEMUXER, MSGL_INFO, "\nICY Info: %s\n", info); | |
137 free(info); | |
138 } | |
139 } | |
140 | |
16032 | 141 /** |
142 * \brief read data from scast/ultravox stream without any metadata | |
143 * \param fd file descriptor to read from | |
144 * \param buffer buffer to read data into | |
145 * \param size number of bytes to read | |
146 * \param sc streaming_ctrl_t whose buffer is consumed before reading from fd | |
147 */ | |
16013 | 148 static int scast_streaming_read(int fd, char *buffer, int size, |
149 streaming_ctrl_t *sc) { | |
150 scast_data_t *sd = (scast_data_t *)sc->data; | |
151 unsigned block, ret; | |
152 unsigned done = 0; | |
153 | |
154 // first read remaining data up to next metadata | |
155 block = sd->metaint - sd->metapos; | |
156 if (block > size) | |
157 block = size; | |
158 ret = my_read(fd, buffer, block, sc); | |
159 sd->metapos += ret; | |
160 done += ret; | |
161 if (ret != block) // read problems or eof | |
162 size = done; | |
163 | |
164 while (done < size) { // now comes the metadata | |
165 if (sd->is_ultravox) | |
16070 | 166 { |
16013 | 167 sd->metaint = uvox_meta_read(fd, sc); |
16070 | 168 if (!sd->metaint) |
169 size = done; | |
170 } | |
16013 | 171 else |
172 scast_meta_read(fd, sc); // read and display metadata | |
173 sd->metapos = 0; | |
174 block = size - done; | |
175 if (block > sd->metaint) | |
176 block = sd->metaint; | |
177 ret = my_read(fd, &buffer[done], block, sc); | |
178 sd->metapos += ret; | |
179 done += ret; | |
180 if (ret != block) // read problems or eof | |
181 size = done; | |
182 } | |
183 return done; | |
184 } | |
185 | |
186 static int scast_streaming_start(stream_t *stream) { | |
187 int metaint; | |
188 scast_data_t *scast_data; | |
189 HTTP_header_t *http_hdr = stream->streaming_ctrl->data; | |
16070 | 190 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0; |
16013 | 191 if (!stream || stream->fd < 0 || !http_hdr) |
192 return -1; | |
193 if (is_ultravox) | |
194 metaint = 0; | |
195 else { | |
196 metaint = atoi(http_get_field(http_hdr, "Icy-MetaInt")); | |
197 if (metaint <= 0) | |
198 return -1; | |
199 } | |
200 stream->streaming_ctrl->buffer = malloc(http_hdr->body_size); | |
201 stream->streaming_ctrl->buffer_size = http_hdr->body_size; | |
202 stream->streaming_ctrl->buffer_pos = 0; | |
203 memcpy(stream->streaming_ctrl->buffer, http_hdr->body, http_hdr->body_size); | |
204 scast_data = malloc(sizeof(scast_data_t)); | |
205 scast_data->metaint = metaint; | |
206 scast_data->metapos = 0; | |
207 scast_data->is_ultravox = is_ultravox; | |
208 http_free(http_hdr); | |
209 stream->streaming_ctrl->data = scast_data; | |
210 stream->streaming_ctrl->streaming_read = scast_streaming_read; | |
211 stream->streaming_ctrl->streaming_seek = NULL; | |
212 stream->streaming_ctrl->prebuffer_size = 64 * 1024; // 64 KBytes | |
213 stream->streaming_ctrl->buffering = 1; | |
214 stream->streaming_ctrl->status = streaming_playing_e; | |
215 return 0; | |
216 } | |
217 | |
15585 | 218 static int nop_streaming_start( stream_t *stream ) { |
219 HTTP_header_t *http_hdr = NULL; | |
220 char *next_url=NULL; | |
221 int fd,ret; | |
222 if( stream==NULL ) return -1; | |
223 | |
224 fd = stream->fd; | |
225 if( fd<0 ) { | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
226 fd = http_send_request( stream->streaming_ctrl->url, 0 ); |
15585 | 227 if( fd<0 ) return -1; |
228 http_hdr = http_read_response( fd ); | |
229 if( http_hdr==NULL ) return -1; | |
230 | |
231 switch( http_hdr->status_code ) { | |
232 case 200: // OK | |
233 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") ); | |
234 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") ); | |
235 if( http_hdr->body_size>0 ) { | |
236 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { | |
237 http_free( http_hdr ); | |
238 return -1; | |
239 } | |
240 } | |
241 break; | |
242 // Redirect | |
243 case 301: // Permanently | |
244 case 302: // Temporarily | |
19459
6dad4b1efb82
Handle 303 (See Other) redirect, part of a patch by Benjamin Zores (ben at geexbox org)
reimar
parents:
19312
diff
changeset
|
245 case 303: // See Other |
32630
2653cb380532
Add support for HTTP 307 (Temporary Redirect) responses.
cboesch
parents:
32585
diff
changeset
|
246 case 307: // Temporarily (since HTTP/1.1) |
15585 | 247 ret=-1; |
248 next_url = http_get_field( http_hdr, "Location" ); | |
249 | |
35301
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35229
diff
changeset
|
250 if (next_url != NULL) { |
15585 | 251 mp_msg(MSGT_NETWORK,MSGL_STATUS,"Redirected: Using this url instead %s\n",next_url); |
35301
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35229
diff
changeset
|
252 stream->streaming_ctrl->url=url_new_with_proxy(next_url); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
253 ret=nop_streaming_start(stream); //recursively get streaming started |
15585 | 254 } else { |
255 mp_msg(MSGT_NETWORK,MSGL_ERR,"Redirection failed\n"); | |
256 closesocket( fd ); | |
257 fd = -1; | |
258 } | |
259 return ret; | |
260 break; | |
261 case 401: //Authorization required | |
262 case 403: //Forbidden | |
263 case 404: //Not found | |
264 case 500: //Server Error | |
265 default: | |
266 mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned code %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase ); | |
267 closesocket( fd ); | |
268 fd = -1; | |
269 return -1; | |
270 break; | |
271 } | |
272 stream->fd = fd; | |
273 } else { | |
274 http_hdr = (HTTP_header_t*)stream->streaming_ctrl->data; | |
275 if( http_hdr->body_size>0 ) { | |
276 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { | |
277 http_free( http_hdr ); | |
278 stream->streaming_ctrl->data = NULL; | |
279 return -1; | |
280 } | |
281 } | |
282 } | |
283 | |
284 if( http_hdr ) { | |
285 http_free( http_hdr ); | |
286 stream->streaming_ctrl->data = NULL; | |
287 } | |
288 | |
289 stream->streaming_ctrl->streaming_read = nop_streaming_read; | |
290 stream->streaming_ctrl->streaming_seek = nop_streaming_seek; | |
291 stream->streaming_ctrl->prebuffer_size = 64*1024; // 64 KBytes | |
292 stream->streaming_ctrl->buffering = 1; | |
293 stream->streaming_ctrl->status = streaming_playing_e; | |
294 return 0; | |
295 } | |
296 | |
870 | 297 HTTP_header_t * |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
16948
diff
changeset
|
298 http_new_header(void) { |
870 | 299 HTTP_header_t *http_hdr; |
300 | |
32636 | 301 http_hdr = calloc(1, sizeof(*http_hdr)); |
870 | 302 if( http_hdr==NULL ) return NULL; |
303 | |
304 return http_hdr; | |
305 } | |
306 | |
307 void | |
308 http_free( HTTP_header_t *http_hdr ) { | |
3039 | 309 HTTP_field_t *field, *field2free; |
870 | 310 if( http_hdr==NULL ) return; |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
311 free(http_hdr->protocol); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
312 free(http_hdr->uri); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
313 free(http_hdr->reason_phrase); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
314 free(http_hdr->field_search); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
315 free(http_hdr->method); |
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
316 free(http_hdr->buffer); |
3039 | 317 field = http_hdr->first_field; |
318 while( field!=NULL ) { | |
319 field2free = field; | |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
320 free(field->field_name); |
3039 | 321 field = field->next; |
322 free( field2free ); | |
323 } | |
870 | 324 free( http_hdr ); |
3039 | 325 http_hdr = NULL; |
870 | 326 } |
327 | |
902 | 328 int |
329 http_response_append( HTTP_header_t *http_hdr, char *response, int length ) { | |
1027 | 330 if( http_hdr==NULL || response==NULL || length<0 ) return -1; |
7304
7da2c2a68547
Check if realloc failed on http_hdr->buffer instead of ptr in http_response_append,
bertrand
parents:
7293
diff
changeset
|
331 |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18094
diff
changeset
|
332 if( (unsigned)length > SIZE_MAX - http_hdr->buffer_size - 1) { |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18094
diff
changeset
|
333 mp_msg(MSGT_NETWORK,MSGL_FATAL,"Bad size in memory (re)allocation\n"); |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18094
diff
changeset
|
334 return -1; |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18094
diff
changeset
|
335 } |
30702 | 336 http_hdr->buffer = realloc( http_hdr->buffer, http_hdr->buffer_size+length+1 ); |
7304
7da2c2a68547
Check if realloc failed on http_hdr->buffer instead of ptr in http_response_append,
bertrand
parents:
7293
diff
changeset
|
337 if( http_hdr->buffer==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
338 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
902 | 339 return -1; |
340 } | |
7293 | 341 memcpy( http_hdr->buffer+http_hdr->buffer_size, response, length ); |
342 http_hdr->buffer_size += length; | |
343 http_hdr->buffer[http_hdr->buffer_size]=0; // close the string! | |
902 | 344 return http_hdr->buffer_size; |
345 } | |
346 | |
347 int | |
2489
0ecc1b4f7cf8
Added ASF http server streaming (Not mms streaming).
bertrand
parents:
2310
diff
changeset
|
348 http_is_header_entire( HTTP_header_t *http_hdr ) { |
902 | 349 if( http_hdr==NULL ) return -1; |
7293 | 350 if( http_hdr->buffer==NULL ) return 0; // empty |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
351 |
35894
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
352 if(http_hdr->buffer_size > 128*1024) return 1; |
3784 | 353 if( strstr(http_hdr->buffer, "\r\n\r\n")==NULL && |
354 strstr(http_hdr->buffer, "\n\n")==NULL ) return 0; | |
355 return 1; | |
902 | 356 } |
357 | |
358 int | |
359 http_response_parse( HTTP_header_t *http_hdr ) { | |
870 | 360 char *hdr_ptr, *ptr; |
361 char *field=NULL; | |
18558
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18094
diff
changeset
|
362 int pos_hdr_sep, hdr_sep_len; |
4928dd61f136
Fix potential integer overflows in memory allocation.
rtogni
parents:
18094
diff
changeset
|
363 size_t len; |
902 | 364 if( http_hdr==NULL ) return -1; |
365 if( http_hdr->is_parsed ) return 0; | |
870 | 366 |
367 // Get the protocol | |
902 | 368 hdr_ptr = strstr( http_hdr->buffer, " " ); |
870 | 369 if( hdr_ptr==NULL ) { |
5915 | 370 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. No space separator found.\n"); |
902 | 371 return -1; |
870 | 372 } |
902 | 373 len = hdr_ptr-http_hdr->buffer; |
18879 | 374 http_hdr->protocol = malloc(len+1); |
870 | 375 if( http_hdr->protocol==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
376 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
902 | 377 return -1; |
870 | 378 } |
902 | 379 strncpy( http_hdr->protocol, http_hdr->buffer, len ); |
380 http_hdr->protocol[len]='\0'; | |
870 | 381 if( !strncasecmp( http_hdr->protocol, "HTTP", 4) ) { |
382 if( sscanf( http_hdr->protocol+5,"1.%d", &(http_hdr->http_minor_version) )!=1 ) { | |
5915 | 383 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get HTTP minor version.\n"); |
902 | 384 return -1; |
870 | 385 } |
386 } | |
387 | |
388 // Get the status code | |
389 if( sscanf( ++hdr_ptr, "%d", &(http_hdr->status_code) )!=1 ) { | |
5915 | 390 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get status code.\n"); |
902 | 391 return -1; |
870 | 392 } |
393 hdr_ptr += 4; | |
394 | |
395 // Get the reason phrase | |
3514
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
396 ptr = strstr( hdr_ptr, "\n" ); |
35229 | 397 if( ptr==NULL ) { |
5915 | 398 mp_msg(MSGT_NETWORK,MSGL_ERR,"Malformed answer. Unable to get the reason phrase.\n"); |
902 | 399 return -1; |
870 | 400 } |
401 len = ptr-hdr_ptr; | |
18879 | 402 http_hdr->reason_phrase = malloc(len+1); |
870 | 403 if( http_hdr->reason_phrase==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
404 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
902 | 405 return -1; |
870 | 406 } |
407 strncpy( http_hdr->reason_phrase, hdr_ptr, len ); | |
4311 | 408 if( http_hdr->reason_phrase[len-1]=='\r' ) { |
409 len--; | |
410 } | |
870 | 411 http_hdr->reason_phrase[len]='\0'; |
412 | |
413 // Set the position of the header separator: \r\n\r\n | |
8179
63a5e03f4346
Removed hard coded value for the length of the header separator.
bertrand
parents:
7304
diff
changeset
|
414 hdr_sep_len = 4; |
902 | 415 ptr = strstr( http_hdr->buffer, "\r\n\r\n" ); |
870 | 416 if( ptr==NULL ) { |
35894
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
417 hdr_sep_len = 2; |
3514
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
418 ptr = strstr( http_hdr->buffer, "\n\n" ); |
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
419 if( ptr==NULL ) { |
5915 | 420 mp_msg(MSGT_NETWORK,MSGL_ERR,"Header may be incomplete. No CRLF CRLF found.\n"); |
35894
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
421 hdr_sep_len = 0; |
3514
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
422 } |
870 | 423 } |
902 | 424 pos_hdr_sep = ptr-http_hdr->buffer; |
870 | 425 |
3514
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
426 // Point to the first line after the method line. |
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
427 hdr_ptr = strstr( http_hdr->buffer, "\n" )+1; |
870 | 428 do { |
3514
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
429 ptr = hdr_ptr; |
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
430 while( *ptr!='\r' && *ptr!='\n' ) ptr++; |
870 | 431 len = ptr-hdr_ptr; |
35894
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
432 if (len == 0 || !memchr(hdr_ptr, ':', len)) { |
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
433 mp_msg(MSGT_NETWORK, MSGL_ERR, "Broken response header, missing ':'\n"); |
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
434 pos_hdr_sep = ptr - http_hdr->buffer; |
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
435 hdr_sep_len = 0; |
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
436 break; |
ae62be3d8de2
Handle the severely broken headers QuickTime Streaming Server sends.
reimar
parents:
35893
diff
changeset
|
437 } |
35893
6065fb95813e
Support broken icy-metaint response from QuickTime Streaming Server.
reimar
parents:
35317
diff
changeset
|
438 if (len > 16 && !strncasecmp(hdr_ptr + 4, "icy-metaint:", 12)) |
6065fb95813e
Support broken icy-metaint response from QuickTime Streaming Server.
reimar
parents:
35317
diff
changeset
|
439 { |
6065fb95813e
Support broken icy-metaint response from QuickTime Streaming Server.
reimar
parents:
35317
diff
changeset
|
440 mp_msg(MSGT_NETWORK, MSGL_WARN, "Server sent a severely broken icy-metaint HTTP header!\n"); |
6065fb95813e
Support broken icy-metaint response from QuickTime Streaming Server.
reimar
parents:
35317
diff
changeset
|
441 hdr_ptr += 4; |
6065fb95813e
Support broken icy-metaint response from QuickTime Streaming Server.
reimar
parents:
35317
diff
changeset
|
442 len -= 4; |
6065fb95813e
Support broken icy-metaint response from QuickTime Streaming Server.
reimar
parents:
35317
diff
changeset
|
443 } |
30702 | 444 field = realloc(field, len+1); |
870 | 445 if( field==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
446 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MemAllocFailed); |
902 | 447 return -1; |
870 | 448 } |
449 strncpy( field, hdr_ptr, len ); | |
450 field[len]='\0'; | |
451 http_set_field( http_hdr, field ); | |
3514
43518985def8
Handle broken server that doesn't send CRLF but jusr LF.
bertrand
parents:
3497
diff
changeset
|
452 hdr_ptr = ptr+((*ptr=='\r')?2:1); |
902 | 453 } while( hdr_ptr<(http_hdr->buffer+pos_hdr_sep) ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
454 |
32511
b39155e98ac3
Remove some useless NULL pointer checks before invoking free() on the pointer.
diego
parents:
32052
diff
changeset
|
455 free(field); |
870 | 456 |
8179
63a5e03f4346
Removed hard coded value for the length of the header separator.
bertrand
parents:
7304
diff
changeset
|
457 if( pos_hdr_sep+hdr_sep_len<http_hdr->buffer_size ) { |
870 | 458 // Response has data! |
8179
63a5e03f4346
Removed hard coded value for the length of the header separator.
bertrand
parents:
7304
diff
changeset
|
459 http_hdr->body = http_hdr->buffer+pos_hdr_sep+hdr_sep_len; |
63a5e03f4346
Removed hard coded value for the length of the header separator.
bertrand
parents:
7304
diff
changeset
|
460 http_hdr->body_size = http_hdr->buffer_size-(pos_hdr_sep+hdr_sep_len); |
870 | 461 } |
462 | |
902 | 463 http_hdr->is_parsed = 1; |
464 return 0; | |
870 | 465 } |
466 | |
467 char * | |
902 | 468 http_build_request( HTTP_header_t *http_hdr ) { |
35317 | 469 char *ptr; |
902 | 470 int len; |
3039 | 471 HTTP_field_t *field; |
870 | 472 if( http_hdr==NULL ) return NULL; |
473 | |
474 if( http_hdr->method==NULL ) http_set_method( http_hdr, "GET"); | |
475 if( http_hdr->uri==NULL ) http_set_uri( http_hdr, "/"); | |
35317 | 476 if( !http_hdr->uri || !http_hdr->method) |
477 return NULL; | |
870 | 478 |
3497 | 479 //**** Compute the request length |
480 // Add the Method line | |
35317 | 481 len = strlen(http_hdr->method)+strlen(http_hdr->uri)+12; |
3497 | 482 // Add the fields |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
483 field = http_hdr->first_field; |
3039 | 484 while( field!=NULL ) { |
485 len += strlen(field->field_name)+2; | |
486 field = field->next; | |
487 } | |
3497 | 488 // Add the CRLF |
489 len += 2; | |
490 // Add the body | |
902 | 491 if( http_hdr->body!=NULL ) { |
492 len += http_hdr->body_size; | |
493 } | |
3497 | 494 // Free the buffer if it was previously used |
902 | 495 if( http_hdr->buffer!=NULL ) { |
496 free( http_hdr->buffer ); | |
497 http_hdr->buffer = NULL; | |
498 } | |
18879 | 499 http_hdr->buffer = malloc(len+1); |
902 | 500 if( http_hdr->buffer==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
501 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MemAllocFailed); |
902 | 502 return NULL; |
503 } | |
504 http_hdr->buffer_size = len; | |
505 | |
3497 | 506 //*** Building the request |
902 | 507 ptr = http_hdr->buffer; |
3497 | 508 // Add the method line |
35317 | 509 ptr += sprintf( ptr, "%s %s HTTP/1.%d\r\n", http_hdr->method, http_hdr->uri, http_hdr->http_minor_version ); |
3039 | 510 field = http_hdr->first_field; |
3497 | 511 // Add the field |
3039 | 512 while( field!=NULL ) { |
513 ptr += sprintf( ptr, "%s\r\n", field->field_name ); | |
514 field = field->next; | |
515 } | |
870 | 516 ptr += sprintf( ptr, "\r\n" ); |
3497 | 517 // Add the body |
870 | 518 if( http_hdr->body!=NULL ) { |
519 memcpy( ptr, http_hdr->body, http_hdr->body_size ); | |
520 } | |
3497 | 521 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
522 return http_hdr->buffer; |
870 | 523 } |
524 | |
525 char * | |
526 http_get_field( HTTP_header_t *http_hdr, const char *field_name ) { | |
527 if( http_hdr==NULL || field_name==NULL ) return NULL; | |
3039 | 528 http_hdr->field_search_pos = http_hdr->first_field; |
30702 | 529 http_hdr->field_search = realloc( http_hdr->field_search, strlen(field_name)+1 ); |
870 | 530 if( http_hdr->field_search==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
531 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
870 | 532 return NULL; |
533 } | |
534 strcpy( http_hdr->field_search, field_name ); | |
535 return http_get_next_field( http_hdr ); | |
536 } | |
537 | |
538 char * | |
539 http_get_next_field( HTTP_header_t *http_hdr ) { | |
540 char *ptr; | |
3039 | 541 HTTP_field_t *field; |
870 | 542 if( http_hdr==NULL ) return NULL; |
543 | |
3039 | 544 field = http_hdr->field_search_pos; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
545 while( field!=NULL ) { |
3039 | 546 ptr = strstr( field->field_name, ":" ); |
870 | 547 if( ptr==NULL ) return NULL; |
3039 | 548 if( !strncasecmp( field->field_name, http_hdr->field_search, ptr-(field->field_name) ) ) { |
870 | 549 ptr++; // Skip the column |
550 while( ptr[0]==' ' ) ptr++; // Skip the spaces if there is some | |
3039 | 551 http_hdr->field_search_pos = field->next; |
870 | 552 return ptr; // return the value without the field name |
553 } | |
3039 | 554 field = field->next; |
870 | 555 } |
556 return NULL; | |
557 } | |
558 | |
559 void | |
3039 | 560 http_set_field( HTTP_header_t *http_hdr, const char *field_name ) { |
561 HTTP_field_t *new_field; | |
562 if( http_hdr==NULL || field_name==NULL ) return; | |
870 | 563 |
18879 | 564 new_field = malloc(sizeof(HTTP_field_t)); |
3039 | 565 if( new_field==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
566 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
870 | 567 return; |
568 } | |
3039 | 569 new_field->next = NULL; |
18879 | 570 new_field->field_name = malloc(strlen(field_name)+1); |
3039 | 571 if( new_field->field_name==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
572 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
27834
d35bcab9833b
Avoid a memleak if allocation of field_name fails, fixes bug #1319.
reimar
parents:
27473
diff
changeset
|
573 free(new_field); |
3039 | 574 return; |
575 } | |
576 strcpy( new_field->field_name, field_name ); | |
577 | |
578 if( http_hdr->last_field==NULL ) { | |
579 http_hdr->first_field = new_field; | |
580 } else { | |
581 http_hdr->last_field->next = new_field; | |
582 } | |
583 http_hdr->last_field = new_field; | |
870 | 584 http_hdr->field_nb++; |
585 } | |
586 | |
587 void | |
588 http_set_method( HTTP_header_t *http_hdr, const char *method ) { | |
589 if( http_hdr==NULL || method==NULL ) return; | |
590 | |
18879 | 591 http_hdr->method = malloc(strlen(method)+1); |
870 | 592 if( http_hdr->method==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
593 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
870 | 594 return; |
595 } | |
596 strcpy( http_hdr->method, method ); | |
597 } | |
598 | |
599 void | |
600 http_set_uri( HTTP_header_t *http_hdr, const char *uri ) { | |
601 if( http_hdr==NULL || uri==NULL ) return; | |
602 | |
18879 | 603 http_hdr->uri = malloc(strlen(uri)+1); |
870 | 604 if( http_hdr->uri==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
605 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
870 | 606 return; |
607 } | |
608 strcpy( http_hdr->uri, uri ); | |
609 } | |
610 | |
32547
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
611 static int |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
612 http_add_authentication( HTTP_header_t *http_hdr, const char *username, const char *password, const char *auth_str ) { |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
613 char *auth = NULL, *usr_pass = NULL, *b64_usr_pass = NULL; |
32585 | 614 int encoded_len, pass_len=0; |
615 size_t auth_len, usr_pass_len; | |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
616 int res = -1; |
6514 | 617 if( http_hdr==NULL || username==NULL ) return -1; |
618 | |
619 if( password!=NULL ) { | |
620 pass_len = strlen(password); | |
621 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
622 |
32585 | 623 usr_pass_len = strlen(username) + 1 + pass_len; |
624 usr_pass = malloc(usr_pass_len + 1); | |
6514 | 625 if( usr_pass==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
626 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
627 goto out; |
6514 | 628 } |
629 | |
630 sprintf( usr_pass, "%s:%s", username, (password==NULL)?"":password ); | |
631 | |
32585 | 632 encoded_len = AV_BASE64_SIZE(usr_pass_len); |
18879 | 633 b64_usr_pass = malloc(encoded_len); |
6514 | 634 if( b64_usr_pass==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
635 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
636 goto out; |
6514 | 637 } |
32585 | 638 av_base64_encode(b64_usr_pass, encoded_len, usr_pass, usr_pass_len); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
639 |
32547
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
640 auth_len = encoded_len + 100; |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
641 auth = malloc(auth_len); |
6514 | 642 if( auth==NULL ) { |
32515
84bdbf9e9c48
Use MSGTR_MemAllocFailed instead of hardcoded string
cboesch
parents:
32511
diff
changeset
|
643 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
644 goto out; |
6514 | 645 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
646 |
32547
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
647 snprintf(auth, auth_len, "%s: Basic %s", auth_str, b64_usr_pass); |
6514 | 648 http_set_field( http_hdr, auth ); |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
649 res = 0; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
650 |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
651 out: |
6514 | 652 free( usr_pass ); |
653 free( b64_usr_pass ); | |
654 free( auth ); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
655 |
18094
16f2bcd5d148
free memory on error in http_add_basic_authentication
reimar
parents:
17932
diff
changeset
|
656 return res; |
6514 | 657 } |
658 | |
32547
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
659 int |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
660 http_add_basic_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
661 return http_add_authentication(http_hdr, username, password, "Authorization"); |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
662 } |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
663 |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
664 int |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
665 http_add_basic_proxy_authentication( HTTP_header_t *http_hdr, const char *username, const char *password ) { |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
666 return http_add_authentication(http_hdr, username, password, "Proxy-Authorization"); |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
667 } |
6a629e6fdb09
Add Proxy-Authorization header to authenticate on proxies
cboesch
parents:
32515
diff
changeset
|
668 |
870 | 669 void |
670 http_debug_hdr( HTTP_header_t *http_hdr ) { | |
3039 | 671 HTTP_field_t *field; |
672 int i = 0; | |
902 | 673 if( http_hdr==NULL ) return; |
870 | 674 |
5915 | 675 mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- START ---\n"); |
676 mp_msg(MSGT_NETWORK,MSGL_V,"protocol: [%s]\n", http_hdr->protocol ); | |
677 mp_msg(MSGT_NETWORK,MSGL_V,"http minor version: [%d]\n", http_hdr->http_minor_version ); | |
678 mp_msg(MSGT_NETWORK,MSGL_V,"uri: [%s]\n", http_hdr->uri ); | |
679 mp_msg(MSGT_NETWORK,MSGL_V,"method: [%s]\n", http_hdr->method ); | |
680 mp_msg(MSGT_NETWORK,MSGL_V,"status code: [%d]\n", http_hdr->status_code ); | |
681 mp_msg(MSGT_NETWORK,MSGL_V,"reason phrase: [%s]\n", http_hdr->reason_phrase ); | |
33841
25667edae85c
cleanup: adjust printf format strings to match parameter types
diego
parents:
32720
diff
changeset
|
682 mp_msg(MSGT_NETWORK,MSGL_V,"body size: [%zu]\n", http_hdr->body_size ); |
870 | 683 |
5915 | 684 mp_msg(MSGT_NETWORK,MSGL_V,"Fields:\n"); |
3039 | 685 field = http_hdr->first_field; |
686 while( field!=NULL ) { | |
5915 | 687 mp_msg(MSGT_NETWORK,MSGL_V," %d - %s\n", i++, field->field_name ); |
3039 | 688 field = field->next; |
689 } | |
5915 | 690 mp_msg(MSGT_NETWORK,MSGL_V,"--- HTTP DEBUG HEADER --- END ---\n"); |
870 | 691 } |
6514 | 692 |
25970
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
693 static void print_icy_metadata(HTTP_header_t *http_hdr) { |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
694 const char *field_data; |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
695 // note: I skip icy-notice1 and 2, as they contain html <BR> |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
696 // and are IMHO useless info ::atmos |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
697 if( (field_data = http_get_field(http_hdr, "icy-name")) != NULL ) |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
698 mp_msg(MSGT_NETWORK,MSGL_INFO,"Name : %s\n", field_data); |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
699 if( (field_data = http_get_field(http_hdr, "icy-genre")) != NULL ) |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
700 mp_msg(MSGT_NETWORK,MSGL_INFO,"Genre : %s\n", field_data); |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
701 if( (field_data = http_get_field(http_hdr, "icy-url")) != NULL ) |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
702 mp_msg(MSGT_NETWORK,MSGL_INFO,"Website: %s\n", field_data); |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
703 // XXX: does this really mean public server? ::atmos |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
704 if( (field_data = http_get_field(http_hdr, "icy-pub")) != NULL ) |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
705 mp_msg(MSGT_NETWORK,MSGL_INFO,"Public : %s\n", atoi(field_data)?"yes":"no"); |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
706 if( (field_data = http_get_field(http_hdr, "icy-br")) != NULL ) |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
707 mp_msg(MSGT_NETWORK,MSGL_INFO,"Bitrate: %skbit/s\n", field_data); |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
708 } |
c6ec51cc3b13
Move printing of Icy-Metadata into an extra function
reimar
parents:
25969
diff
changeset
|
709 |
21567 | 710 //! If this function succeeds you must closesocket stream->fd |
15585 | 711 static int http_streaming_start(stream_t *stream, int* file_format) { |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
712 HTTP_header_t *http_hdr = NULL; |
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
713 int fd = stream->fd; |
25135
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
714 int res = STREAM_UNSUPPORTED; |
15585 | 715 int redirect = 0; |
716 int auth_retry=0; | |
717 int seekable=0; | |
718 char *content_type; | |
30357
3fdf04500df2
Handle Content-Length also when Content-Type is not set.
reimar
parents:
30356
diff
changeset
|
719 const char *content_length; |
15585 | 720 char *next_url; |
721 URL_t *url = stream->streaming_ctrl->url; | |
6514 | 722 |
15585 | 723 do |
724 { | |
21541
3b4ed8857b38
Fix potential endless loop in http_streaming_start due
reimar
parents:
21540
diff
changeset
|
725 redirect = 0; |
35308
f570e9faa3c7
Fix off-by-one errors in file descriptor validity checks.
reimar
parents:
35301
diff
changeset
|
726 if (fd >= 0) closesocket(fd); |
15585 | 727 fd = http_send_request( url, 0 ); |
728 if( fd<0 ) { | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
729 goto err_out; |
15585 | 730 } |
731 | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
732 http_free(http_hdr); |
15585 | 733 http_hdr = http_read_response( fd ); |
734 if( http_hdr==NULL ) { | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
735 goto err_out; |
15585 | 736 } |
737 | |
17932 | 738 if( mp_msg_test(MSGT_NETWORK,MSGL_V) ) { |
15585 | 739 http_debug_hdr( http_hdr ); |
740 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
741 |
15585 | 742 // Check if we can make partial content requests and thus seek in http-streams |
743 if( http_hdr!=NULL && http_hdr->status_code==200 ) { | |
30106 | 744 const char *accept_ranges = http_get_field(http_hdr,"Accept-Ranges"); |
30105
31b7d4637b50
Fix crash if http reply contains neither "Accept-Ranges" nor "Server" fields.
reimar
parents:
30103
diff
changeset
|
745 const char *server = http_get_field(http_hdr, "Server"); |
30106 | 746 if (accept_ranges) |
15585 | 747 seekable = strncmp(accept_ranges,"bytes",5)==0; |
32720
1afbc8e3ff55
100l, fix hack to check for MakeMKV server being inverted.
reimar
parents:
32698
diff
changeset
|
748 else if (server && (strcmp(server, "gvs 1.0") == 0 || |
1afbc8e3ff55
100l, fix hack to check for MakeMKV server being inverted.
reimar
parents:
32698
diff
changeset
|
749 strncmp(server, "MakeMKV", 7) == 0)) { |
32698
b171c744cd06
Add MakeMKV to list of webservers always supporting ranges even when they
reimar
parents:
32636
diff
changeset
|
750 // HACK for youtube and MakeMKV incorrectly claiming not to support seeking |
b171c744cd06
Add MakeMKV to list of webservers always supporting ranges even when they
reimar
parents:
32636
diff
changeset
|
751 mp_msg(MSGT_NETWORK, MSGL_WARN, "Broken webserver, incorrectly claims to not support Accept-Ranges\n"); |
b171c744cd06
Add MakeMKV to list of webservers always supporting ranges even when they
reimar
parents:
32636
diff
changeset
|
752 seekable = 1; |
b171c744cd06
Add MakeMKV to list of webservers always supporting ranges even when they
reimar
parents:
32636
diff
changeset
|
753 } |
15585 | 754 } |
755 | |
25971
64b1e4ea04fc
Always display Icy-Metadata if available, whether we recognize an ICY-Server
reimar
parents:
25970
diff
changeset
|
756 print_icy_metadata(http_hdr); |
64b1e4ea04fc
Always display Icy-Metadata if available, whether we recognize an ICY-Server
reimar
parents:
25970
diff
changeset
|
757 |
15585 | 758 // Check if the response is an ICY status_code reason_phrase |
25968
c7f41f9e2eb8
Detect IceCast also by Icy-MetaInt header part in http_streaming_start(),
reimar
parents:
25246
diff
changeset
|
759 if( !strcasecmp(http_hdr->protocol, "ICY") || |
c7f41f9e2eb8
Detect IceCast also by Icy-MetaInt header part in http_streaming_start(),
reimar
parents:
25246
diff
changeset
|
760 http_get_field(http_hdr, "Icy-MetaInt") ) { |
15585 | 761 switch( http_hdr->status_code ) { |
762 case 200: { // OK | |
25969 | 763 char *field_data; |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
764 // If content-type == video/nsv we most likely have a winamp video stream |
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
765 // otherwise it should be mp3. if there are more types consider adding mime type |
15585 | 766 // handling like later |
767 if ( (field_data = http_get_field(http_hdr, "content-type")) != NULL && (!strcmp(field_data, "video/nsv") || !strcmp(field_data, "misc/ultravox"))) | |
768 *file_format = DEMUXER_TYPE_NSV; | |
16948
9b7925705f5b
Add another content-type for aac audio in shoutcast streams
rtognimp
parents:
16932
diff
changeset
|
769 else if ( (field_data = http_get_field(http_hdr, "content-type")) != NULL && (!strcmp(field_data, "audio/aacp") || !strcmp(field_data, "audio/aac"))) |
16917
c45409728a9d
Use correct demuxer type for aac in shoutcast streams
rtognimp
parents:
16614
diff
changeset
|
770 *file_format = DEMUXER_TYPE_AAC; |
15585 | 771 else |
772 *file_format = DEMUXER_TYPE_AUDIO; | |
25135
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
773 res = STREAM_ERROR; |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
774 goto out; |
15585 | 775 } |
776 case 400: // Server Full | |
777 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server is full, skipping!\n"); | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
778 goto err_out; |
15585 | 779 case 401: // Service Unavailable |
780 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return service unavailable, skipping!\n"); | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
781 goto err_out; |
15585 | 782 case 403: // Service Forbidden |
783 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server return 'Service Forbidden'\n"); | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
784 goto err_out; |
15585 | 785 case 404: // Resource Not Found |
786 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: ICY-Server couldn't find requested stream, skipping!\n"); | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
787 goto err_out; |
15585 | 788 default: |
789 mp_msg(MSGT_NETWORK,MSGL_ERR,"Error: unhandled ICY-Errorcode, contact MPlayer developers!\n"); | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
790 goto err_out; |
15585 | 791 } |
792 } | |
793 | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
794 // Assume standard http if not ICY |
15585 | 795 switch( http_hdr->status_code ) { |
796 case 200: // OK | |
30357
3fdf04500df2
Handle Content-Length also when Content-Type is not set.
reimar
parents:
30356
diff
changeset
|
797 content_length = http_get_field(http_hdr, "Content-Length"); |
3fdf04500df2
Handle Content-Length also when Content-Type is not set.
reimar
parents:
30356
diff
changeset
|
798 if (content_length) { |
3fdf04500df2
Handle Content-Length also when Content-Type is not set.
reimar
parents:
30356
diff
changeset
|
799 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", content_length); |
3fdf04500df2
Handle Content-Length also when Content-Type is not set.
reimar
parents:
30356
diff
changeset
|
800 stream->end_pos = atoll(content_length); |
3fdf04500df2
Handle Content-Length also when Content-Type is not set.
reimar
parents:
30356
diff
changeset
|
801 } |
15585 | 802 // Look if we can use the Content-Type |
803 content_type = http_get_field( http_hdr, "Content-Type" ); | |
804 if( content_type!=NULL ) { | |
32557 | 805 unsigned int i; |
806 | |
15585 | 807 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", content_type ); |
808 // Check in the mime type table for a demuxer type | |
32557 | 809 for (i = 0; mime_type_table[i].mime_type != NULL; i++) { |
15585 | 810 if( !strcasecmp( content_type, mime_type_table[i].mime_type ) ) { |
811 *file_format = mime_type_table[i].demuxer_type; | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
812 res = seekable; |
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
813 goto out; |
15585 | 814 } |
815 } | |
816 } | |
817 // Not found in the mime type table, don't fail, | |
818 // we should try raw HTTP | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
819 res = seekable; |
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
820 goto out; |
15585 | 821 // Redirect |
822 case 301: // Permanently | |
823 case 302: // Temporarily | |
19459
6dad4b1efb82
Handle 303 (See Other) redirect, part of a patch by Benjamin Zores (ben at geexbox org)
reimar
parents:
19312
diff
changeset
|
824 case 303: // See Other |
32630
2653cb380532
Add support for HTTP 307 (Temporary Redirect) responses.
cboesch
parents:
32585
diff
changeset
|
825 case 307: // Temporarily (since HTTP/1.1) |
15585 | 826 // TODO: RFC 2616, recommand to detect infinite redirection loops |
827 next_url = http_get_field( http_hdr, "Location" ); | |
828 if( next_url!=NULL ) { | |
25238
f42b8e689416
Preserve unsv:// protocol specifier over http redirects.
reimar
parents:
25211
diff
changeset
|
829 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0; |
20784
720206eef78b
Support URL redirections that do not specify full URL.
reimar
parents:
20185
diff
changeset
|
830 stream->streaming_ctrl->url = url_redirect( &url, next_url ); |
35113 | 831 if (url_is_protocol(url, "mms")) { |
25135
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
832 res = STREAM_REDIRECTED; |
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
833 goto err_out; |
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
834 } |
35113 | 835 if (!url_is_protocol(url, "http")) { |
25135
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
836 mp_msg(MSGT_NETWORK,MSGL_ERR,"Unsupported http %d redirect to %s protocol\n", http_hdr->status_code, url->protocol); |
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
837 goto err_out; |
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
838 } |
35113 | 839 if (is_ultravox) |
840 url_set_protocol(url, "unsv"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
841 redirect = 1; |
15585 | 842 } |
843 break; | |
844 case 401: // Authentication required | |
21566
79d969f9eec0
STREAM_UNSUPPORTED is -1, so use the former for return value in all places.
reimar
parents:
21565
diff
changeset
|
845 if( http_authenticate(http_hdr, url, &auth_retry)<0 ) |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
846 goto err_out; |
15585 | 847 redirect = 1; |
848 break; | |
849 default: | |
850 mp_msg(MSGT_NETWORK,MSGL_ERR,"Server returned %d: %s\n", http_hdr->status_code, http_hdr->reason_phrase ); | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
851 goto err_out; |
15585 | 852 } |
853 } while( redirect ); | |
854 | |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
855 err_out: |
35308
f570e9faa3c7
Fix off-by-one errors in file descriptor validity checks.
reimar
parents:
35301
diff
changeset
|
856 if (fd >= 0) closesocket( fd ); |
21565
546cf4a6377a
Make sure stream->fd is set correct (esp. to -1 on error when fd is closed)
reimar
parents:
21542
diff
changeset
|
857 fd = -1; |
21542 | 858 http_free( http_hdr ); |
21776 | 859 http_hdr = NULL; |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
860 out: |
35309 | 861 stream->streaming_ctrl->data = http_hdr; |
21565
546cf4a6377a
Make sure stream->fd is set correct (esp. to -1 on error when fd is closed)
reimar
parents:
21542
diff
changeset
|
862 stream->fd = fd; |
21540
147c1c305f21
Fix lots and lots of potential memory/fd leaks in http_streaming_start
reimar
parents:
20784
diff
changeset
|
863 return res; |
15585 | 864 } |
865 | |
866 static int fixup_open(stream_t *stream,int seekable) { | |
16013 | 867 HTTP_header_t *http_hdr = stream->streaming_ctrl->data; |
16078
095e980cf7c0
Some ICY servers (e.g. http://broadcast.spnet.net:8000/darikhigh) do not set
reimar
parents:
16070
diff
changeset
|
868 int is_icy = http_hdr && http_get_field(http_hdr, "Icy-MetaInt"); |
16070 | 869 int is_ultravox = strcasecmp(stream->streaming_ctrl->url->protocol, "unsv") == 0; |
15585 | 870 |
871 stream->type = STREAMTYPE_STREAM; | |
16013 | 872 if(!is_icy && !is_ultravox && seekable) |
15585 | 873 { |
29920
4f740437ed2b
Finally rename the STREAM_SEEK define to MP_STREAM_SEEK, there are just too many
reimar
parents:
29263
diff
changeset
|
874 stream->flags |= MP_STREAM_SEEK; |
15585 | 875 stream->seek = http_seek; |
876 } | |
877 stream->streaming_ctrl->bandwidth = network_bandwidth; | |
16013 | 878 if ((!is_icy && !is_ultravox) || scast_streaming_start(stream)) |
15585 | 879 if(nop_streaming_start( stream )) { |
880 mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_start failed\n"); | |
21567 | 881 if (stream->fd >= 0) |
882 closesocket(stream->fd); | |
883 stream->fd = -1; | |
15585 | 884 streaming_ctrl_free(stream->streaming_ctrl); |
885 stream->streaming_ctrl = NULL; | |
24257 | 886 return STREAM_UNSUPPORTED; |
15585 | 887 } |
888 | |
889 fixup_network_stream_cache(stream); | |
890 return STREAM_OK; | |
891 } | |
892 | |
893 static int open_s1(stream_t *stream,int mode, void* opts, int* file_format) { | |
894 int seekable=0; | |
895 | |
896 stream->streaming_ctrl = streaming_ctrl_new(); | |
897 if( stream->streaming_ctrl==NULL ) { | |
898 return STREAM_ERROR; | |
899 } | |
900 stream->streaming_ctrl->bandwidth = network_bandwidth; | |
35301
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35229
diff
changeset
|
901 stream->streaming_ctrl->url = url_new_with_proxy(stream->url); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
902 |
20185 | 903 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(1), URL: %s\n", stream->url); |
15585 | 904 seekable = http_streaming_start(stream, file_format); |
905 if((seekable < 0) || (*file_format == DEMUXER_TYPE_ASF)) { | |
21567 | 906 if (stream->fd >= 0) |
907 closesocket(stream->fd); | |
908 stream->fd = -1; | |
25135
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
909 if (seekable == STREAM_REDIRECTED) |
66f628d13442
Support stream redirection from http to mms, fix bug #927.
ulion
parents:
24257
diff
changeset
|
910 return seekable; |
15585 | 911 streaming_ctrl_free(stream->streaming_ctrl); |
912 stream->streaming_ctrl = NULL; | |
24257 | 913 return STREAM_UNSUPPORTED; |
15585 | 914 } |
915 | |
916 return fixup_open(stream, seekable); | |
917 } | |
918 | |
919 static int open_s2(stream_t *stream,int mode, void* opts, int* file_format) { | |
920 int seekable=0; | |
921 | |
922 stream->streaming_ctrl = streaming_ctrl_new(); | |
923 if( stream->streaming_ctrl==NULL ) { | |
924 return STREAM_ERROR; | |
925 } | |
926 stream->streaming_ctrl->bandwidth = network_bandwidth; | |
35301
8f6d3f8ffa61
Add url_new_with_proxy function to reduce code duplication and memleaks.
reimar
parents:
35229
diff
changeset
|
927 stream->streaming_ctrl->url = url_new_with_proxy(stream->url); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
928 |
20185 | 929 mp_msg(MSGT_OPEN, MSGL_V, "STREAM_HTTP(2), URL: %s\n", stream->url); |
15585 | 930 seekable = http_streaming_start(stream, file_format); |
931 if(seekable < 0) { | |
21567 | 932 if (stream->fd >= 0) |
933 closesocket(stream->fd); | |
934 stream->fd = -1; | |
15585 | 935 streaming_ctrl_free(stream->streaming_ctrl); |
936 stream->streaming_ctrl = NULL; | |
24257 | 937 return STREAM_UNSUPPORTED; |
15585 | 938 } |
939 | |
940 return fixup_open(stream, seekable); | |
941 } | |
942 | |
943 | |
25211 | 944 const stream_info_t stream_info_http1 = { |
15585 | 945 "http streaming", |
946 "null", | |
947 "Bertrand, Albeau, Reimar Doeffinger, Arpi?", | |
948 "plain http", | |
949 open_s1, | |
27847
28deb37052cd
Add a noicyx:// protocol to allow easier testing for misconfigured servers.
reimar
parents:
27834
diff
changeset
|
950 {"http", "http_proxy", "unsv", "icyx", "noicyx", NULL}, |
15585 | 951 NULL, |
952 0 // Urls are an option string | |
953 }; | |
954 | |
25211 | 955 const stream_info_t stream_info_http2 = { |
15585 | 956 "http streaming", |
957 "null", | |
958 "Bertrand, Albeu, Arpi? who?", | |
16932
c30e0970250c
fix typos: aslo->also, falback->fallback (they were just too annoying *g*)
reimar
parents:
16917
diff
changeset
|
959 "plain http, also used as fallback for many other protocols", |
15585 | 960 open_s2, |
961 {"http", "http_proxy", "pnm", "mms", "mmsu", "mmst", "rtsp", NULL}, //all the others as fallback | |
962 NULL, | |
963 0 // Urls are an option string | |
964 }; |