Mercurial > mplayer.hg
annotate stream/network.c @ 30610:b0f5b5d43941
TOOLS/realcodecs: Remove pointless '#if 1' preprocessor directives.
author | diego |
---|---|
date | Fri, 19 Feb 2010 09:46:31 +0000 |
parents | 74a6c2a3dcce |
children | 300fd6ee0f8b |
rev | line source |
---|---|
903 | 1 /* |
2 * Network layer for MPlayer | |
30426
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
3 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
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:
29263
diff
changeset
|
5 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
6 * This file is part of MPlayer. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
7 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
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:
29263
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:
29263
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:
29263
diff
changeset
|
11 * (at your option) any later version. |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
diff
changeset
|
12 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
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:
29263
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:
29263
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:
29263
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:
29263
diff
changeset
|
17 * |
ce0122361a39
Add license header to all files missing it in the stream subdirectory.
diego
parents:
29263
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:
29263
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:
29263
diff
changeset
|
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
903 | 21 */ |
22 | |
1028 | 23 //#define DUMP2FILE |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
24 |
1430 | 25 #include <stdio.h> |
26 #include <stdlib.h> | |
27 #include <string.h> | |
833 | 28 #include <unistd.h> |
1430 | 29 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
30 #include <errno.h> |
903 | 31 #include <ctype.h> |
833 | 32 |
2555
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
33 #include "config.h" |
66837325b929
config.h cleanup, few things added to steram/demuxer headers
arpi
parents:
2489
diff
changeset
|
34 |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
35 #include "mp_msg.h" |
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
36 #include "help_mp.h" |
27472
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
37 |
28402 | 38 #if HAVE_WINSOCK2_H |
27472
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
39 #include <winsock2.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
40 #include <ws2tcpip.h> |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
41 #endif |
c0b233cd30ca
Revert moving closesocket definition and network headers to network.h.
diego
parents:
27464
diff
changeset
|
42 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
43 #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
|
44 #include "libmpdemux/demuxer.h" |
17012 | 45 #include "m_config.h" |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
46 |
841 | 47 #include "network.h" |
19335
2a9d669e5ff6
isolated tcp socket code from network.c to a dedicated file
ben
parents:
19331
diff
changeset
|
48 #include "tcp.h" |
903 | 49 #include "http.h" |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
50 #include "cookies.h" |
903 | 51 #include "url.h" |
841 | 52 |
17012 | 53 #include "version.h" |
6466 | 54 |
7867 | 55 extern int stream_cache_size; |
4121 | 56 |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
57 /* Variables for the command line option -user, -passwd, -bandwidth, |
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
58 -user-agent and -nocookies */ |
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
59 |
7867 | 60 char *network_username=NULL; |
61 char *network_password=NULL; | |
62 int network_bandwidth=0; | |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
63 int network_cookies_enabled = 0; |
11228 | 64 char *network_useragent=NULL; |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
65 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
66 /* IPv6 options */ |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
67 int network_ipv4_only_proxy = 0; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
68 |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
69 |
25246 | 70 const mime_struct_t mime_type_table[] = { |
30475
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
71 #ifdef CONFIG_LIBAVFORMAT |
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
72 // Flash Video |
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
73 { "video/x-flv", DEMUXER_TYPE_LAVF_PREFERRED}, |
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
74 { "video/quicktime", DEMUXER_TYPE_LAVF_PREFERRED }, |
9f36eccc490a
Prefer libavformat over our own mov demuxer also for video/quicktime
reimar
parents:
30426
diff
changeset
|
75 #endif |
3042 | 76 // MP3 streaming, some MP3 streaming server answer with audio/mpeg |
4729
f51bd827ed1c
fixed MP3 ICY detection, return detected file format for open_stream
alex
parents:
4652
diff
changeset
|
77 { "audio/mpeg", DEMUXER_TYPE_AUDIO }, |
3042 | 78 // MPEG streaming |
14002
009337ffcfc4
forced autodetection of file format when content-type is video-x-mpeg to give mpeg-ts a chance
nicodvb
parents:
12894
diff
changeset
|
79 { "video/mpeg", DEMUXER_TYPE_UNKNOWN }, |
009337ffcfc4
forced autodetection of file format when content-type is video-x-mpeg to give mpeg-ts a chance
nicodvb
parents:
12894
diff
changeset
|
80 { "video/x-mpeg", DEMUXER_TYPE_UNKNOWN }, |
009337ffcfc4
forced autodetection of file format when content-type is video-x-mpeg to give mpeg-ts a chance
nicodvb
parents:
12894
diff
changeset
|
81 { "video/x-mpeg2", DEMUXER_TYPE_UNKNOWN }, |
3042 | 82 // AVI ??? => video/x-msvideo |
83 { "video/x-msvideo", DEMUXER_TYPE_AVI }, | |
84 // MOV => video/quicktime | |
85 { "video/quicktime", DEMUXER_TYPE_MOV }, | |
86 // ASF | |
87 { "audio/x-ms-wax", DEMUXER_TYPE_ASF }, | |
88 { "audio/x-ms-wma", DEMUXER_TYPE_ASF }, | |
89 { "video/x-ms-asf", DEMUXER_TYPE_ASF }, | |
90 { "video/x-ms-afs", DEMUXER_TYPE_ASF }, | |
91 { "video/x-ms-wmv", DEMUXER_TYPE_ASF }, | |
92 { "video/x-ms-wma", DEMUXER_TYPE_ASF }, | |
17235 | 93 { "application/x-mms-framed", DEMUXER_TYPE_ASF }, |
17657
f5f4200785fc
More complete ASF MIME detection, closing bug# 248,
gpoirier
parents:
17566
diff
changeset
|
94 { "application/vnd.ms.wms-hdr.asfv1", DEMUXER_TYPE_ASF }, |
19841
e7f56cc4505e
Change demuxer for "application/octet-stream" http streams from
eugeni
parents:
19335
diff
changeset
|
95 { "application/octet-stream", DEMUXER_TYPE_UNKNOWN }, |
4783 | 96 // Playlists |
7393 | 97 { "video/x-ms-wmx", DEMUXER_TYPE_PLAYLIST }, |
23675
c056ed2819e8
wvx files (mimetype video/x-ms-wvx) are asx playlists. Fix bugzilla #750
rtogni
parents:
22142
diff
changeset
|
98 { "video/x-ms-wvx", DEMUXER_TYPE_PLAYLIST }, |
4783 | 99 { "audio/x-scpls", DEMUXER_TYPE_PLAYLIST }, |
100 { "audio/x-mpegurl", DEMUXER_TYPE_PLAYLIST }, | |
6032 | 101 { "audio/x-pls", DEMUXER_TYPE_PLAYLIST }, |
102 // Real Media | |
15209
b9c199dd123f
Do not force real demuxer on x-pn-realaudio mimetype
rtognimp
parents:
14720
diff
changeset
|
103 // { "audio/x-pn-realaudio", DEMUXER_TYPE_REAL }, |
8114
ba66375adb6f
Added OGG streaming support, patch from Balatoni Denes <pnis@coder.hu>
bertrand
parents:
8027
diff
changeset
|
104 // OGG Streaming |
12175 | 105 { "application/x-ogg", DEMUXER_TYPE_OGG }, |
106 // NullSoft Streaming Video | |
12477
1550ef7117c4
Add detection of nsa streamed by aol ultravox server
rtognimp
parents:
12390
diff
changeset
|
107 { "video/nsv", DEMUXER_TYPE_NSV}, |
15585 | 108 { "misc/ultravox", DEMUXER_TYPE_NSV}, |
109 { NULL, DEMUXER_TYPE_UNKNOWN}, | |
3042 | 110 }; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
111 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
112 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
113 streaming_ctrl_t * |
17566
f580a7755ac5
Patch by Stefan Huehner / stefan % huehner ! org \
rathann
parents:
17235
diff
changeset
|
114 streaming_ctrl_new(void) { |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
115 streaming_ctrl_t *streaming_ctrl; |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18466
diff
changeset
|
116 streaming_ctrl = malloc(sizeof(streaming_ctrl_t)); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
117 if( streaming_ctrl==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
118 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
119 return NULL; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
120 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
121 memset( streaming_ctrl, 0, sizeof(streaming_ctrl_t) ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
122 return streaming_ctrl; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
123 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
124 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
125 void |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
126 streaming_ctrl_free( streaming_ctrl_t *streaming_ctrl ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
127 if( streaming_ctrl==NULL ) return; |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
128 if( streaming_ctrl->url ) url_free( streaming_ctrl->url ); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
129 if( streaming_ctrl->buffer ) free( streaming_ctrl->buffer ); |
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
130 if( streaming_ctrl->data ) free( streaming_ctrl->data ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
131 free( streaming_ctrl ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
132 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
133 |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
134 URL_t* |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
135 check4proxies( URL_t *url ) { |
4652 | 136 URL_t *url_out = NULL; |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
137 if( url==NULL ) return NULL; |
4652 | 138 url_out = url_new( url->url ); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
139 if( !strcasecmp(url->protocol, "http_proxy") ) { |
5915 | 140 mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: http://%s:%d\n", url->hostname, url->port ); |
4652 | 141 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
142 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
143 // Check if the http_proxy environment variable is set. |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
144 if( !strcasecmp(url->protocol, "http") ) { |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
145 char *proxy; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
146 proxy = getenv("http_proxy"); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
147 if( proxy!=NULL ) { |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
148 // We got a proxy, build the URL to use it |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
149 int len; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
150 char *new_url; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
151 URL_t *tmp_url; |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
152 URL_t *proxy_url = url_new( proxy ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
153 |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
154 if( proxy_url==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
155 mp_msg(MSGT_NETWORK,MSGL_WARN, |
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
156 MSGTR_MPDEMUX_NW_InvalidProxySettingTryingWithout); |
4652 | 157 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
158 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
159 |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
160 #ifdef HAVE_AF_INET6 |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
161 if (network_ipv4_only_proxy && (gethostbyname(url->hostname)==NULL)) { |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
162 mp_msg(MSGT_NETWORK,MSGL_WARN, |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
163 MSGTR_MPDEMUX_NW_CantResolvTryingWithoutProxy); |
16419 | 164 url_free(proxy_url); |
9691
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
165 return url_out; |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
166 } |
ed72c158215d
Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents:
8939
diff
changeset
|
167 #endif |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
168 |
5915 | 169 mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: %s\n", proxy_url->url ); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
170 len = strlen( proxy_url->hostname ) + strlen( url->url ) + 20; // 20 = http_proxy:// + port |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
171 new_url = malloc( len+1 ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
172 if( new_url==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
173 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
16419 | 174 url_free(proxy_url); |
4652 | 175 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
176 } |
5915 | 177 sprintf(new_url, "http_proxy://%s:%d/%s", proxy_url->hostname, proxy_url->port, url->url ); |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
178 tmp_url = url_new( new_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
179 if( tmp_url==NULL ) { |
16419 | 180 free( new_url ); |
181 url_free( proxy_url ); | |
4652 | 182 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
183 } |
4652 | 184 url_free( url_out ); |
185 url_out = tmp_url; | |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
186 free( new_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
187 url_free( proxy_url ); |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
188 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
189 } |
4652 | 190 return url_out; |
4146
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
191 } |
925046ea34ec
Added support for the environment variable http_proxy.
bertrand
parents:
4145
diff
changeset
|
192 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
193 int |
11965 | 194 http_send_request( URL_t *url, off_t pos ) { |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
195 HTTP_header_t *http_hdr; |
4121 | 196 URL_t *server_url; |
11228 | 197 char str[256]; |
21535 | 198 int fd = -1; |
4121 | 199 int ret; |
200 int proxy = 0; // Boolean | |
201 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
202 http_hdr = http_new_header(); |
4121 | 203 |
4145 | 204 if( !strcasecmp(url->protocol, "http_proxy") ) { |
4121 | 205 proxy = 1; |
206 server_url = url_new( (url->file)+1 ); | |
207 http_set_uri( http_hdr, server_url->url ); | |
208 } else { | |
209 server_url = url; | |
210 http_set_uri( http_hdr, server_url->file ); | |
211 } | |
12638
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
212 if (server_url->port && server_url->port != 80) |
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
213 snprintf(str, 256, "Host: %s:%d", server_url->hostname, server_url->port ); |
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
214 else |
2ebd553876c8
RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents:
12610
diff
changeset
|
215 snprintf(str, 256, "Host: %s", server_url->hostname ); |
3585 | 216 http_set_field( http_hdr, str); |
11228 | 217 if (network_useragent) |
218 { | |
219 snprintf(str, 256, "User-Agent: %s", network_useragent); | |
220 http_set_field(http_hdr, str); | |
221 } | |
222 else | |
223 http_set_field( http_hdr, "User-Agent: MPlayer/"VERSION); | |
11965 | 224 |
27847
28deb37052cd
Add a noicyx:// protocol to allow easier testing for misconfigured servers.
reimar
parents:
27473
diff
changeset
|
225 if( strcasecmp(url->protocol, "noicyx") ) |
27848 | 226 http_set_field(http_hdr, "Icy-MetaData: 1"); |
16013 | 227 |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
228 if(pos>0) { |
11965 | 229 // Extend http_send_request with possibility to do partial content retrieval |
16750
0a31740dd5e6
Use PRI?64 defines as format strings for 64 bit variables.
reimar
parents:
16419
diff
changeset
|
230 snprintf(str, 256, "Range: bytes=%"PRId64"-", (int64_t)pos); |
11965 | 231 http_set_field(http_hdr, str); |
232 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
233 |
11583
2af52902e7dc
Send HTTP Cookies (reading from mozilla/netscape files) support by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>. Disabled by default.
alex
parents:
11505
diff
changeset
|
234 if (network_cookies_enabled) cookies_set( http_hdr, server_url->hostname, server_url->url ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
235 |
12352 | 236 http_set_field( http_hdr, "Connection: close"); |
6515 | 237 http_add_basic_authentication( http_hdr, url->username, url->password ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
238 if( http_build_request( http_hdr )==NULL ) { |
16417 | 239 goto err_out; |
833 | 240 } |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
241 |
4121 | 242 if( proxy ) { |
243 if( url->port==0 ) url->port = 8080; // Default port for the proxy server | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
244 fd = connect2Server( url->hostname, url->port,1 ); |
4121 | 245 url_free( server_url ); |
17777
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
246 server_url = NULL; |
4121 | 247 } else { |
248 if( server_url->port==0 ) server_url->port = 80; // Default port for the web server | |
10625
620cc649f519
ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents:
10317
diff
changeset
|
249 fd = connect2Server( server_url->hostname, server_url->port,1 ); |
4121 | 250 } |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
251 if( fd<0 ) { |
16417 | 252 goto err_out; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
253 } |
5915 | 254 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request: [%s]\n", http_hdr->buffer ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
255 |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
10199
diff
changeset
|
256 ret = send( fd, http_hdr->buffer, http_hdr->buffer_size, 0 ); |
7953 | 257 if( ret!=(int)http_hdr->buffer_size ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
258 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrSendingHTTPRequest); |
16417 | 259 goto err_out; |
4121 | 260 } |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
261 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
262 http_free( http_hdr ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
263 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
264 return fd; |
16417 | 265 err_out: |
21535 | 266 if (fd > 0) closesocket(fd); |
16417 | 267 http_free(http_hdr); |
17777
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
268 if (proxy && server_url) |
13b2332c5154
missing url_free when using proxy and connect fails
reimar
parents:
17657
diff
changeset
|
269 url_free(server_url); |
16417 | 270 return -1; |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
271 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
272 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
273 HTTP_header_t * |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
274 http_read_response( int fd ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
275 HTTP_header_t *http_hdr; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
276 char response[BUFFER_SIZE]; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
277 int i; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
278 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
279 http_hdr = http_new_header(); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
280 if( http_hdr==NULL ) { |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
281 return NULL; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
282 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
283 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
284 do { |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
285 i = recv( fd, response, BUFFER_SIZE, 0 ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
286 if( i<0 ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
287 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ReadFailed); |
3365 | 288 http_free( http_hdr ); |
289 return NULL; | |
290 } | |
291 if( i==0 ) { | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
292 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_Read0CouldBeEOF); |
3365 | 293 http_free( http_hdr ); |
294 return NULL; | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
295 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
296 http_response_append( http_hdr, response, i ); |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
297 } while( !http_is_header_entire( http_hdr ) ); |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
298 http_response_parse( http_hdr ); |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
299 return http_hdr; |
833 | 300 } |
301 | |
6555 | 302 int |
303 http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry) { | |
304 char *aut; | |
7953 | 305 |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
306 if( *auth_retry==1 ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
307 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed); |
6555 | 308 return -1; |
309 } | |
310 if( *auth_retry>0 ) { | |
311 if( url->username ) { | |
312 free( url->username ); | |
313 url->username = NULL; | |
314 } | |
315 if( url->password ) { | |
316 free( url->password ); | |
317 url->password = NULL; | |
318 } | |
319 } | |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
320 |
6555 | 321 aut = http_get_field(http_hdr, "WWW-Authenticate"); |
322 if( aut!=NULL ) { | |
323 char *aut_space; | |
324 aut_space = strstr(aut, "realm="); | |
325 if( aut_space!=NULL ) aut_space += 6; | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
326 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequiredFor, aut_space); |
6555 | 327 } else { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
328 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequired); |
6555 | 329 } |
7867 | 330 if( network_username ) { |
331 url->username = strdup(network_username); | |
6555 | 332 if( url->username==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
333 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
6555 | 334 return -1; |
335 } | |
336 } else { | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
337 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed); |
6555 | 338 return -1; |
339 } | |
7867 | 340 if( network_password ) { |
341 url->password = strdup(network_password); | |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
342 if( url->password==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
343 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
344 return -1; |
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
345 } |
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
346 } else { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
347 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_NoPasswdProvidedTryingBlank); |
6558
b379b061ce50
Read username/password from the -user -pass command line options.
bertrand
parents:
6555
diff
changeset
|
348 } |
6555 | 349 (*auth_retry)++; |
350 return 0; | |
351 } | |
352 | |
11965 | 353 int |
354 http_seek( stream_t *stream, off_t pos ) { | |
355 HTTP_header_t *http_hdr = NULL; | |
356 int fd; | |
357 if( stream==NULL ) return 0; | |
358 | |
359 if( stream->fd>0 ) closesocket(stream->fd); // need to reconnect to seek in http-stream | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
360 fd = http_send_request( stream->streaming_ctrl->url, pos ); |
11965 | 361 if( fd<0 ) return 0; |
362 | |
363 http_hdr = http_read_response( fd ); | |
364 | |
365 if( http_hdr==NULL ) return 0; | |
366 | |
367 switch( http_hdr->status_code ) { | |
368 case 200: | |
369 case 206: // OK | |
370 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") ); | |
371 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") ); | |
372 if( http_hdr->body_size>0 ) { | |
373 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) { | |
374 http_free( http_hdr ); | |
375 return -1; | |
376 } | |
377 } | |
378 break; | |
379 default: | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
380 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrServerReturned, http_hdr->status_code, http_hdr->reason_phrase ); |
11965 | 381 close( fd ); |
382 fd = -1; | |
383 } | |
384 stream->fd = fd; | |
385 | |
386 if( http_hdr ) { | |
387 http_free( http_hdr ); | |
388 stream->streaming_ctrl->data = NULL; | |
389 } | |
390 | |
391 stream->pos=pos; | |
392 | |
393 return 1; | |
394 } | |
395 | |
396 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
397 int |
3042 | 398 streaming_bufferize( streaming_ctrl_t *streaming_ctrl, char *buffer, int size) { |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
399 //printf("streaming_bufferize\n"); |
19062
83c3afeab35d
drops casts from void * on malloc/calloc from libmpdemux code
reynaldo
parents:
18466
diff
changeset
|
400 streaming_ctrl->buffer = malloc(size); |
3042 | 401 if( streaming_ctrl->buffer==NULL ) { |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
402 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed); |
3042 | 403 return -1; |
404 } | |
405 memcpy( streaming_ctrl->buffer, buffer, size ); | |
406 streaming_ctrl->buffer_size = size; | |
3599 | 407 return size; |
3042 | 408 } |
409 | |
410 int | |
411 nop_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) { | |
412 int len=0; | |
413 //printf("nop_streaming_read\n"); | |
414 if( stream_ctrl->buffer_size!=0 ) { | |
415 int buffer_len = stream_ctrl->buffer_size-stream_ctrl->buffer_pos; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
416 //printf("%d bytes in buffer\n", stream_ctrl->buffer_size); |
3042 | 417 len = (size<buffer_len)?size:buffer_len; |
418 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len ); | |
419 stream_ctrl->buffer_pos += len; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
420 //printf("buffer_pos = %d\n", stream_ctrl->buffer_pos ); |
3042 | 421 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) { |
422 free( stream_ctrl->buffer ); | |
423 stream_ctrl->buffer = NULL; | |
424 stream_ctrl->buffer_size = 0; | |
425 stream_ctrl->buffer_pos = 0; | |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
426 //printf("buffer cleaned\n"); |
3042 | 427 } |
4251
05affdf4bdcd
Moved network related code from open.c to network.c
bertrand
parents:
4236
diff
changeset
|
428 //printf("read %d bytes from buffer\n", len ); |
3042 | 429 } |
430 | |
431 if( len<size ) { | |
3365 | 432 int ret; |
10206
35e306346e59
Using recv/send instead read/write for proper MinGW support (it's a 4.2BSD standard). Patch by FloDt <flodt8@yahoo.de>
alex
parents:
10199
diff
changeset
|
433 ret = recv( fd, buffer+len, size-len, 0 ); |
3494
fb9de639ed30
Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents:
3453
diff
changeset
|
434 if( ret<0 ) { |
5915 | 435 mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_read error : %s\n",strerror(errno)); |
3365 | 436 } |
437 len += ret; | |
3042 | 438 //printf("read %d bytes from network\n", len ); |
439 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28402
diff
changeset
|
440 |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
441 return len; |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
442 } |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
443 |
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
444 int |
3042 | 445 nop_streaming_seek( int fd, off_t pos, streaming_ctrl_t *stream_ctrl ) { |
446 return -1; | |
7953 | 447 // To shut up gcc warning |
448 fd++; | |
449 pos++; | |
450 stream_ctrl=NULL; | |
3042 | 451 } |
452 | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
453 |
15954 | 454 void fixup_network_stream_cache(stream_t *stream) { |
15585 | 455 if(stream->streaming_ctrl->buffering) { |
456 if(stream_cache_size<0) { | |
457 // cache option not set, will use our computed value. | |
458 // buffer in KBytes, *5 because the prefill is 20% of the buffer. | |
459 stream_cache_size = (stream->streaming_ctrl->prebuffer_size/1024)*5; | |
460 if( stream_cache_size<64 ) stream_cache_size = 64; // 16KBytes min buffer | |
461 } | |
17153
c0b147bdf49d
Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents:
17012
diff
changeset
|
462 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_CacheSizeSetTo, stream_cache_size); |
15585 | 463 } |
9922 | 464 } |
465 | |
466 | |
30557
74a6c2a3dcce
stream: Mark functions not used outside of their files as static.
diego
parents:
30475
diff
changeset
|
467 static int |
3042 | 468 streaming_stop( stream_t *stream ) { |
469 stream->streaming_ctrl->status = streaming_stopped_e; | |
999
92833c9472e8
Continue implementation of the network streaming part.
bertrand
parents:
903
diff
changeset
|
470 return 0; |
903 | 471 } |