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