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