annotate libmpdemux/network.c @ 18066:2ee39341b7a6

fix segfault in the skin browser when sbSelectedSkin gets dereferenced before setting, when no skin is selected in the skin list upon opening the browser, and "Cancel" or "OK" buttons get clicked. Noticed when runnig freshly compiled gmplayer on a system where the skins were still under the old location. based on a combined patch by Stanislav Maslovski <stanislav POIS maslovski AH gmail POIS com>
author gpoirier
date Sun, 09 Apr 2006 13:52:45 +0000
parents 77ecc381e6e9
children 028e4c7a749e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
1 /*
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
2 * Network layer for MPlayer
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
3 * by Bertrand BAUDET <bertrand_baudet@yahoo.com>
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
4 * (C) 2001, MPlayer team.
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
5 */
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
6
1028
a710b2a06564 Commented the default output to file.
bertrand
parents: 999
diff changeset
7 //#define DUMP2FILE
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
8
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
9 #include <stdio.h>
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
10 #include <stdlib.h>
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
11 #include <string.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
12 #include <unistd.h>
1430
1728d249c783 missing unistd.h (requires for off_t under freebsd)
arpi
parents: 1028
diff changeset
13
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
14 #include <errno.h>
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
15 #include <ctype.h>
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
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
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
22 #ifndef HAVE_WINSOCK2
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
23 #define closesocket close
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
24 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
25 #include <winsock2.h>
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
26 #include <ws2tcpip.h>
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
27 #endif
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
28
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
29 #include "stream.h"
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
30 #include "demuxer.h"
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16750
diff changeset
31 #include "m_config.h"
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
32
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
33 #include "network.h"
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
34 #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
35 #include "cookies.h"
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
36 #include "url.h"
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
37
17012
6ff3379a0862 Unify include path handling, -I.. is in CFLAGS.
diego
parents: 16750
diff changeset
38 #include "version.h"
6466
ebffa928a5d4 Added mplayer version in the user-agent field.
bertrand
parents: 6454
diff changeset
39
7867
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
40 extern int stream_cache_size;
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
41
7862
013c255225d8 mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
arpi
parents: 7513
diff changeset
42 extern int mp_input_check_interrupt(int time);
013c255225d8 mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
arpi
parents: 7513
diff changeset
43
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
44 /* 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
45 -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
46
7867
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
47 char *network_username=NULL;
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
48 char *network_password=NULL;
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
49 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
50 int network_cookies_enabled = 0;
11228
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
51 char *network_useragent=NULL;
6558
b379b061ce50 Read username/password from the -user -pass command line options.
bertrand
parents: 6555
diff changeset
52
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
53 /* IPv6 options */
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
54 int network_prefer_ipv4 = 0;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
55 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
56
6558
b379b061ce50 Read username/password from the -user -pass command line options.
bertrand
parents: 6555
diff changeset
57
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
58 mime_struct_t mime_type_table[] = {
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
59 // 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
60 { "audio/mpeg", DEMUXER_TYPE_AUDIO },
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
61 // 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
62 { "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
63 { "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
64 { "video/x-mpeg2", DEMUXER_TYPE_UNKNOWN },
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
65 // AVI ??? => video/x-msvideo
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
66 { "video/x-msvideo", DEMUXER_TYPE_AVI },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
67 // MOV => video/quicktime
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
68 { "video/quicktime", DEMUXER_TYPE_MOV },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
69 // ASF
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
70 { "audio/x-ms-wax", DEMUXER_TYPE_ASF },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
71 { "audio/x-ms-wma", DEMUXER_TYPE_ASF },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
72 { "video/x-ms-asf", DEMUXER_TYPE_ASF },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
73 { "video/x-ms-afs", DEMUXER_TYPE_ASF },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
74 { "video/x-ms-wvx", DEMUXER_TYPE_ASF },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
75 { "video/x-ms-wmv", DEMUXER_TYPE_ASF },
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
76 { "video/x-ms-wma", DEMUXER_TYPE_ASF },
17235
fbac61e449d5 Add "application/x-mms-framed" for ASF
rtognimp
parents: 17153
diff changeset
77 { "application/x-mms-framed", DEMUXER_TYPE_ASF },
17657
f5f4200785fc More complete ASF MIME detection, closing bug# 248,
gpoirier
parents: 17566
diff changeset
78 { "application/vnd.ms.wms-hdr.asfv1", DEMUXER_TYPE_ASF },
f5f4200785fc More complete ASF MIME detection, closing bug# 248,
gpoirier
parents: 17566
diff changeset
79 { "application/octet-stream", DEMUXER_TYPE_ASF },
4783
17f29765ea77 Support for retriving mp3 playlist from the network
albeu
parents: 4730
diff changeset
80 // Playlists
7393
52b29760fe95 Added a new ASX playlist mime-type
bertrand
parents: 7251
diff changeset
81 { "video/x-ms-wmx", DEMUXER_TYPE_PLAYLIST },
4783
17f29765ea77 Support for retriving mp3 playlist from the network
albeu
parents: 4730
diff changeset
82 { "audio/x-scpls", DEMUXER_TYPE_PLAYLIST },
17f29765ea77 Support for retriving mp3 playlist from the network
albeu
parents: 4730
diff changeset
83 { "audio/x-mpegurl", DEMUXER_TYPE_PLAYLIST },
6032
4577bda5806a added some new types
alex
parents: 5916
diff changeset
84 { "audio/x-pls", DEMUXER_TYPE_PLAYLIST },
4577bda5806a added some new types
alex
parents: 5916
diff changeset
85 // Real Media
15209
b9c199dd123f Do not force real demuxer on x-pn-realaudio mimetype
rtognimp
parents: 14720
diff changeset
86 // { "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
87 // OGG Streaming
12175
da8e39bfe121 nsv (Nullsoft streaming video) demuxer
rtognimp
parents: 12018
diff changeset
88 { "application/x-ogg", DEMUXER_TYPE_OGG },
da8e39bfe121 nsv (Nullsoft streaming video) demuxer
rtognimp
parents: 12018
diff changeset
89 // NullSoft Streaming Video
12477
1550ef7117c4 Add detection of nsa streamed by aol ultravox server
rtognimp
parents: 12390
diff changeset
90 { "video/nsv", DEMUXER_TYPE_NSV},
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
91 { "misc/ultravox", DEMUXER_TYPE_NSV},
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
92 { NULL, DEMUXER_TYPE_UNKNOWN},
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
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;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
99 streaming_ctrl = (streaming_ctrl_t*)malloc(sizeof(streaming_ctrl_t));
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
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
117
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
118 // Converts an address family constant to a string
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
119
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
120 char *af2String(int af) {
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
121 switch (af) {
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
122 case AF_INET: return "AF_INET";
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
123
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
124 #ifdef HAVE_AF_INET6
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
125 case AF_INET6: return "AF_INET6";
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
126 #endif
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
127 default: return "Unknown address family!";
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
128 }
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
129 }
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
130
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
131
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
132
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
133 // Connect to a server using a TCP connection, with specified address family
7251
cc83ad6af513 Return -2 for fatal error while connecting to a server.
bertrand
parents: 7007
diff changeset
134 // return -2 for fatal error, like unable to resolve name, connection timeout...
cc83ad6af513 Return -2 for fatal error while connecting to a server.
bertrand
parents: 7007
diff changeset
135 // return -1 is unable to connect to a particular port
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
136
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
137 int
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents: 10317
diff changeset
138 connect2Server_with_af(char *host, int port, int af,int verb) {
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
139 int socket_server_fd;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
140 int err, err_len;
4825
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
141 int ret,count = 0;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
142 fd_set set;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
143 struct timeval tv;
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
144 union {
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
145 struct sockaddr_in four;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
146 #ifdef HAVE_AF_INET6
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
147 struct sockaddr_in6 six;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
148 #endif
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
149 } server_address;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
150 size_t server_address_size;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
151 void *our_s_addr; // Pointer to sin_addr or sin6_addr
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7881
diff changeset
152 struct hostent *hp=NULL;
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
153 char buf[255];
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
154
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
155 #ifdef HAVE_WINSOCK2
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
156 u_long val;
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
157 #endif
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
158
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
159 socket_server_fd = socket(af, SOCK_STREAM, 0);
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
160
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
161
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
162 if( socket_server_fd==-1 ) {
11227
a7cbee9f21f7 disable a silly errormessage
alex
parents: 10625
diff changeset
163 // mp_msg(MSGT_NETWORK,MSGL_ERR,"Failed to create %s socket:\n", af2String(af));
7251
cc83ad6af513 Return -2 for fatal error while connecting to a server.
bertrand
parents: 7007
diff changeset
164 return -2;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
165 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
166
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
167 switch (af) {
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
168 case AF_INET: our_s_addr = (void *) &server_address.four.sin_addr; break;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
169 #ifdef HAVE_AF_INET6
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
170 case AF_INET6: our_s_addr = (void *) &server_address.six.sin6_addr; break;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
171 #endif
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
172 default:
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
173 mp_msg(MSGT_NETWORK,MSGL_ERR, MSGTR_MPDEMUX_NW_UnknownAF, af);
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
174 return -2;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
175 }
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
176
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
177
14642
38572280e8e7 bzero is deprecated patch by Gianluigi Tiesi <mplayer at netfarm.it>
faust3
parents: 14265
diff changeset
178 memset(&server_address, 0, sizeof(server_address));
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
179
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
180 #ifndef HAVE_WINSOCK2
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
181 #ifdef USE_ATON
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
182 if (inet_aton(host, our_s_addr)!=1)
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
183 #else
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
184 if (inet_pton(af, host, our_s_addr)!=1)
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
185 #endif
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
186 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
187 if ( inet_addr(host)==INADDR_NONE )
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
188 #endif
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
189 {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
190 if(verb) mp_msg(MSGT_NETWORK,MSGL_STATUS,MSGTR_MPDEMUX_NW_ResolvingHostForAF, host, af2String(af));
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
191
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
192 #ifdef HAVE_GETHOSTBYNAME2
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
193 hp=(struct hostent*)gethostbyname2( host, af );
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
194 #else
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
195 hp=(struct hostent*)gethostbyname( host );
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
196 #endif
841
c906b7600fc6 Included "netdb.h" file needed.
bertrand
parents: 833
diff changeset
197 if( hp==NULL ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
198 if(verb) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_CantResolv, af2String(af), host);
7251
cc83ad6af513 Return -2 for fatal error while connecting to a server.
bertrand
parents: 7007
diff changeset
199 return -2;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
200 }
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
201
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
202 memcpy( our_s_addr, (void*)hp->h_addr, hp->h_length );
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
203 }
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
204 #ifdef HAVE_WINSOCK2
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
205 else {
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
206 unsigned long addr = inet_addr(host);
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
207 memcpy( our_s_addr, (void*)&addr, sizeof(addr) );
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
208 }
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
209 #endif
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
210
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
211 switch (af) {
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
212 case AF_INET:
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
213 server_address.four.sin_family=af;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
214 server_address.four.sin_port=htons(port);
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
215 server_address_size = sizeof(server_address.four);
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
216 break;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
217 #ifdef HAVE_AF_INET6
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
218 case AF_INET6:
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
219 server_address.six.sin6_family=af;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
220 server_address.six.sin6_port=htons(port);
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
221 server_address_size = sizeof(server_address.six);
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
222 break;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
223 #endif
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
224 default:
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
225 mp_msg(MSGT_NETWORK,MSGL_ERR, MSGTR_MPDEMUX_NW_UnknownAF, af);
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
226 return -2;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
227 }
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
228
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
229 #if defined(USE_ATON) || defined(HAVE_WINSOCK2)
9900
f36b9dda3082 Use inet_ntoa where inet_ntop is not available.
bertrand
parents: 9890
diff changeset
230 strncpy( buf, inet_ntoa( *((struct in_addr*)our_s_addr) ), 255);
f36b9dda3082 Use inet_ntoa where inet_ntop is not available.
bertrand
parents: 9890
diff changeset
231 #else
f36b9dda3082 Use inet_ntoa where inet_ntop is not available.
bertrand
parents: 9890
diff changeset
232 inet_ntop(af, our_s_addr, buf, 255);
f36b9dda3082 Use inet_ntoa where inet_ntop is not available.
bertrand
parents: 9890
diff changeset
233 #endif
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
234 if(verb) mp_msg(MSGT_NETWORK,MSGL_STATUS,MSGTR_MPDEMUX_NW_ConnectingToServer, host, buf , port );
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
235
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
236 // Turn the socket as non blocking so we can timeout on the connection
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
237 #ifndef HAVE_WINSOCK2
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
238 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) | O_NONBLOCK );
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
239 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
240 val = 1;
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
241 ioctlsocket( socket_server_fd, FIONBIO, &val );
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
242 #endif
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
243 if( connect( socket_server_fd, (struct sockaddr*)&server_address, server_address_size )==-1 ) {
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
244 #ifndef HAVE_WINSOCK2
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
245 if( errno!=EINPROGRESS ) {
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
246 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
247 if( (WSAGetLastError() != WSAEINPROGRESS) && (WSAGetLastError() != WSAEWOULDBLOCK) ) {
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
248 #endif
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
249 if(verb) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_CantConnect2Server, af2String(af));
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
250 closesocket(socket_server_fd);
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
251 return -1;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
252 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
253 }
6477
08712c93b643 Here I go again, another fix for the timeout.
bertrand
parents: 6476
diff changeset
254 tv.tv_sec = 0;
08712c93b643 Here I go again, another fix for the timeout.
bertrand
parents: 6476
diff changeset
255 tv.tv_usec = 500000;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
256 FD_ZERO( &set );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
257 FD_SET( socket_server_fd, &set );
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
258 // When the connection will be made, we will have a writable fd
4825
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
259 while((ret = select(socket_server_fd+1, NULL, &set, NULL, &tv)) == 0) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
260 if( ret<0 ) mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_SelectFailed);
4825
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
261 else if(ret > 0) break;
7862
013c255225d8 mpdemux.c|h moved to libinput, mpdemux_check_interrupt() -> mp_input_check_interrupt()
arpi
parents: 7513
diff changeset
262 else if(count > 30 || mp_input_check_interrupt(500)) {
6477
08712c93b643 Here I go again, another fix for the timeout.
bertrand
parents: 6476
diff changeset
263 if(count > 30)
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
264 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ConnTimeout);
4825
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
265 else
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 5892
diff changeset
266 mp_msg(MSGT_NETWORK,MSGL_V,"Connection interuppted by user\n");
8824
87e37d8cfb25 Return another error code for timeout.
bertrand
parents: 8766
diff changeset
267 return -3;
4825
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
268 }
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
269 count++;
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
270 FD_ZERO( &set );
41d2da3bd082 Make blocking call in libmpdemux interuptable (only with new input,
albeu
parents: 4817
diff changeset
271 FD_SET( socket_server_fd, &set );
6477
08712c93b643 Here I go again, another fix for the timeout.
bertrand
parents: 6476
diff changeset
272 tv.tv_sec = 0;
08712c93b643 Here I go again, another fix for the timeout.
bertrand
parents: 6476
diff changeset
273 tv.tv_usec = 500000;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
274 }
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
275
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
276 // Turn back the socket as blocking
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
277 #ifndef HAVE_WINSOCK2
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
278 fcntl( socket_server_fd, F_SETFL, fcntl(socket_server_fd, F_GETFL) & ~O_NONBLOCK );
10281
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
279 #else
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
280 val = 0;
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
281 ioctlsocket( socket_server_fd, FIONBIO, &val );
54bcbf28698a Networking support under MinGW.
diego
parents: 10206
diff changeset
282 #endif
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
283 // Check if there were any error
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
284 err_len = sizeof(int);
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
285 ret = getsockopt(socket_server_fd,SOL_SOCKET,SO_ERROR,&err,&err_len);
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
286 if(ret < 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_GetSockOptFailed,strerror(errno));
7251
cc83ad6af513 Return -2 for fatal error while connecting to a server.
bertrand
parents: 7007
diff changeset
288 return -2;
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
289 }
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
290 if(err > 0) {
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_ConnectError,strerror(err));
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
292 return -1;
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
293 }
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
294
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
295 return socket_server_fd;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
296 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
297
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
298 // Connect to a server using a TCP connection
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
299 // return -2 for fatal error, like unable to resolve name, connection timeout...
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
300 // return -1 is unable to connect to a particular port
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
301
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
302
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
303 int
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents: 10317
diff changeset
304 connect2Server(char *host, int port, int verb) {
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
305 #ifdef HAVE_AF_INET6
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
306 int r;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
307 int s = -2;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
308
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents: 10317
diff changeset
309 r = connect2Server_with_af(host, port, network_prefer_ipv4 ? AF_INET:AF_INET6,verb);
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
310 if (r > -1) return r;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
311
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents: 10317
diff changeset
312 s = connect2Server_with_af(host, port, network_prefer_ipv4 ? AF_INET6:AF_INET,verb);
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
313 if (s == -2) return r;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
314 return s;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
315 #else
10625
620cc649f519 ftp support. The change on connect2Server is needed bcs we need 2
albeu
parents: 10317
diff changeset
316 return connect2Server_with_af(host, port, AF_INET,verb);
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
317 #endif
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
318
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
319
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
320 }
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
321
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
322 URL_t*
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
323 check4proxies( URL_t *url ) {
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
324 URL_t *url_out = NULL;
4251
05affdf4bdcd Moved network related code from open.c to network.c
bertrand
parents: 4236
diff changeset
325 if( url==NULL ) return NULL;
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
326 url_out = url_new( url->url );
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
327 if( !strcasecmp(url->protocol, "http_proxy") ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 5892
diff changeset
328 mp_msg(MSGT_NETWORK,MSGL_V,"Using HTTP proxy: http://%s:%d\n", url->hostname, url->port );
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
329 return url_out;
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
330 }
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
331 // Check if the http_proxy environment variable is set.
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
332 if( !strcasecmp(url->protocol, "http") ) {
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
333 char *proxy;
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
334 proxy = getenv("http_proxy");
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
335 if( proxy!=NULL ) {
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
336 // We got a proxy, build the URL to use it
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
337 int len;
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
338 char *new_url;
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
339 URL_t *tmp_url;
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
340 URL_t *proxy_url = url_new( proxy );
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
341
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
342 if( proxy_url==NULL ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
343 mp_msg(MSGT_NETWORK,MSGL_WARN,
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
344 MSGTR_MPDEMUX_NW_InvalidProxySettingTryingWithout);
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
345 return url_out;
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
346 }
9691
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
347
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
348 #ifdef HAVE_AF_INET6
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
349 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
350 mp_msg(MSGT_NETWORK,MSGL_WARN,
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
351 MSGTR_MPDEMUX_NW_CantResolvTryingWithoutProxy);
16419
0d860b6d64e6 memleak fixes when using an http proxy
reimar
parents: 16417
diff changeset
352 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
353 return url_out;
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
354 }
ed72c158215d Added IPv6 support, patch by Dave Lambley <mplayer-dev-eng@dlambley.freeserve.co.uk>
bertrand
parents: 8939
diff changeset
355 #endif
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
356
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 5892
diff changeset
357 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
358 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
359 new_url = malloc( len+1 );
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
360 if( new_url==NULL ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
361 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
16419
0d860b6d64e6 memleak fixes when using an http proxy
reimar
parents: 16417
diff changeset
362 url_free(proxy_url);
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
363 return url_out;
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
364 }
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 5892
diff changeset
365 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
366 tmp_url = url_new( new_url );
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
367 if( tmp_url==NULL ) {
16419
0d860b6d64e6 memleak fixes when using an http proxy
reimar
parents: 16417
diff changeset
368 free( new_url );
0d860b6d64e6 memleak fixes when using an http proxy
reimar
parents: 16417
diff changeset
369 url_free( proxy_url );
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
370 return url_out;
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
371 }
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
372 url_free( url_out );
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
373 url_out = tmp_url;
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
374 free( new_url );
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
375 url_free( proxy_url );
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
376 }
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
377 }
4652
17cf55182029 Cleaned up the way proxies checking was done.
bertrand
parents: 4553
diff changeset
378 return url_out;
4146
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
379 }
925046ea34ec Added support for the environment variable http_proxy.
bertrand
parents: 4145
diff changeset
380
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
381 int
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
382 http_send_request( URL_t *url, off_t pos ) {
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
383 HTTP_header_t *http_hdr;
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
384 URL_t *server_url;
11228
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
385 char str[256];
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
386 int fd;
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
387 int ret;
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
388 int proxy = 0; // Boolean
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
389
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
390 http_hdr = http_new_header();
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
391
4145
c66fddd8867c Changed the proxy protocol to http_proxy.
bertrand
parents: 4121
diff changeset
392 if( !strcasecmp(url->protocol, "http_proxy") ) {
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
393 proxy = 1;
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
394 server_url = url_new( (url->file)+1 );
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
395 http_set_uri( http_hdr, server_url->url );
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
396 } else {
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
397 server_url = url;
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
398 http_set_uri( http_hdr, server_url->file );
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
399 }
12638
2ebd553876c8 RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents: 12610
diff changeset
400 if (server_url->port && server_url->port != 80)
2ebd553876c8 RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents: 12610
diff changeset
401 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
402 else
2ebd553876c8 RFC compliance patch by Eric Lammerts <eric@lammerts.org>
alex
parents: 12610
diff changeset
403 snprintf(str, 256, "Host: %s", server_url->hostname );
3585
cb985ea11ed5 Added the Host field in the HTTP request.
bertrand
parents: 3494
diff changeset
404 http_set_field( http_hdr, str);
11228
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
405 if (network_useragent)
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
406 {
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
407 snprintf(str, 256, "User-Agent: %s", network_useragent);
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
408 http_set_field(http_hdr, str);
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
409 }
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
410 else
f25d54466044 User settable http user-agent. Patch by Per Wigren
alex
parents: 11227
diff changeset
411 http_set_field( http_hdr, "User-Agent: MPlayer/"VERSION);
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
412
16013
4ee24ec6ac16 SHOUTcast and ultravox support
reimar
parents: 15954
diff changeset
413 http_set_field(http_hdr, "Icy-MetaData: 1");
4ee24ec6ac16 SHOUTcast and ultravox support
reimar
parents: 15954
diff changeset
414
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
415 if(pos>0) {
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
416 // 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
417 snprintf(str, 256, "Range: bytes=%"PRId64"-", (int64_t)pos);
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
418 http_set_field(http_hdr, str);
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
419 }
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
420
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
421 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
422
12352
2e0a4b32e139 Should be Connection: close, and not closed.
bertrand
parents: 12274
diff changeset
423 http_set_field( http_hdr, "Connection: close");
6515
138ff0a71119 Added HTTP basic authentication support
bertrand
parents: 6477
diff changeset
424 http_add_basic_authentication( http_hdr, url->username, url->password );
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
425 if( http_build_request( http_hdr )==NULL ) {
16417
be6bbd50ec20 memleak fixes when invalid http url specified.
reimar
parents: 16013
diff changeset
426 goto err_out;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
427 }
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
428
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
429 if( proxy ) {
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
430 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
431 fd = connect2Server( url->hostname, url->port,1 );
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
432 url_free( server_url );
17777
13b2332c5154 missing url_free when using proxy and connect fails
reimar
parents: 17657
diff changeset
433 server_url = NULL;
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
434 } else {
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
435 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
436 fd = connect2Server( server_url->hostname, server_url->port,1 );
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
437 }
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
438 if( fd<0 ) {
16417
be6bbd50ec20 memleak fixes when invalid http url specified.
reimar
parents: 16013
diff changeset
439 goto err_out;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
440 }
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 5892
diff changeset
441 mp_msg(MSGT_NETWORK,MSGL_DBG2,"Request: [%s]\n", http_hdr->buffer );
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
442
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
443 ret = send( fd, http_hdr->buffer, http_hdr->buffer_size, 0 );
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7881
diff changeset
444 if( ret!=(int)http_hdr->buffer_size ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
445 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrSendingHTTPRequest);
16417
be6bbd50ec20 memleak fixes when invalid http url specified.
reimar
parents: 16013
diff changeset
446 goto err_out;
4121
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
447 }
a71d4ffc6c97 Added proxy support.
bertrand
parents: 4072
diff changeset
448
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
449 http_free( http_hdr );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
450
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
451 return fd;
16417
be6bbd50ec20 memleak fixes when invalid http url specified.
reimar
parents: 16013
diff changeset
452 err_out:
be6bbd50ec20 memleak fixes when invalid http url specified.
reimar
parents: 16013
diff changeset
453 http_free(http_hdr);
17777
13b2332c5154 missing url_free when using proxy and connect fails
reimar
parents: 17657
diff changeset
454 if (proxy && server_url)
13b2332c5154 missing url_free when using proxy and connect fails
reimar
parents: 17657
diff changeset
455 url_free(server_url);
16417
be6bbd50ec20 memleak fixes when invalid http url specified.
reimar
parents: 16013
diff changeset
456 return -1;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
457 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
458
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
459 HTTP_header_t *
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
460 http_read_response( int fd ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
461 HTTP_header_t *http_hdr;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
462 char response[BUFFER_SIZE];
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
463 int i;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
464
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
465 http_hdr = http_new_header();
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
466 if( http_hdr==NULL ) {
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
467 return NULL;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
468 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
469
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
470 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
471 i = recv( fd, response, BUFFER_SIZE, 0 );
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
472 if( i<0 ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
473 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ReadFailed);
3365
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
474 http_free( http_hdr );
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
475 return NULL;
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
476 }
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
477 if( i==0 ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
478 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_Read0CouldBeEOF);
3365
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
479 http_free( http_hdr );
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
480 return NULL;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
481 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
482 http_response_append( http_hdr, response, i );
2489
0ecc1b4f7cf8 Added ASF http server streaming (Not mms streaming).
bertrand
parents: 2310
diff changeset
483 } while( !http_is_header_entire( http_hdr ) );
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
484 http_response_parse( http_hdr );
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
485 return http_hdr;
833
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
486 }
b8cecdc0c67f Starting implementation of ASF network streaming.
bertrand
parents:
diff changeset
487
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
488 int
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
489 http_authenticate(HTTP_header_t *http_hdr, URL_t *url, int *auth_retry) {
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
490 char *aut;
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7881
diff changeset
491
6558
b379b061ce50 Read username/password from the -user -pass command line options.
bertrand
parents: 6555
diff changeset
492 if( *auth_retry==1 ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
493 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed);
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
494 return -1;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
495 }
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
496 if( *auth_retry>0 ) {
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
497 if( url->username ) {
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
498 free( url->username );
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
499 url->username = NULL;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
500 }
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
501 if( url->password ) {
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
502 free( url->password );
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
503 url->password = NULL;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
504 }
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
505 }
6558
b379b061ce50 Read username/password from the -user -pass command line options.
bertrand
parents: 6555
diff changeset
506
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
507 aut = http_get_field(http_hdr, "WWW-Authenticate");
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
508 if( aut!=NULL ) {
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
509 char *aut_space;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
510 aut_space = strstr(aut, "realm=");
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
511 if( aut_space!=NULL ) aut_space += 6;
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
512 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequiredFor, aut_space);
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
513 } else {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
514 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_AuthRequired);
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
515 }
7867
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
516 if( network_username ) {
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
517 url->username = strdup(network_username);
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
518 if( url->username==NULL ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
519 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
520 return -1;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
521 }
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
522 } else {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
523 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_AuthFailed);
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
524 return -1;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
525 }
7867
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
526 if( network_password ) {
3dc0b71630ff cleanup config option handling in libmpdemux.
arpi
parents: 7862
diff changeset
527 url->password = strdup(network_password);
6558
b379b061ce50 Read username/password from the -user -pass command line options.
bertrand
parents: 6555
diff changeset
528 if( url->password==NULL ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
529 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
530 return -1;
b379b061ce50 Read username/password from the -user -pass command line options.
bertrand
parents: 6555
diff changeset
531 }
b379b061ce50 Read username/password from the -user -pass command line options.
bertrand
parents: 6555
diff changeset
532 } else {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
533 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
534 }
6555
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
535 (*auth_retry)++;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
536 return 0;
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
537 }
f54b5148885d Moved authentication code into its own function.
bertrand
parents: 6516
diff changeset
538
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
539 int
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
540 http_seek( stream_t *stream, off_t pos ) {
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
541 HTTP_header_t *http_hdr = NULL;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
542 int fd;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
543 if( stream==NULL ) return 0;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
544
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
545 if( stream->fd>0 ) closesocket(stream->fd); // need to reconnect to seek in http-stream
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
546 fd = http_send_request( stream->streaming_ctrl->url, pos );
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
547 if( fd<0 ) return 0;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
548
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
549 http_hdr = http_read_response( fd );
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
550
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
551 if( http_hdr==NULL ) return 0;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
552
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
553 switch( http_hdr->status_code ) {
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
554 case 200:
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
555 case 206: // OK
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
556 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Type: [%s]\n", http_get_field(http_hdr, "Content-Type") );
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
557 mp_msg(MSGT_NETWORK,MSGL_V,"Content-Length: [%s]\n", http_get_field(http_hdr, "Content-Length") );
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
558 if( http_hdr->body_size>0 ) {
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
559 if( streaming_bufferize( stream->streaming_ctrl, http_hdr->body, http_hdr->body_size )<0 ) {
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
560 http_free( http_hdr );
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
561 return -1;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
562 }
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
563 }
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
564 break;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
565 default:
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
566 mp_msg(MSGT_NETWORK,MSGL_ERR,MSGTR_MPDEMUX_NW_ErrServerReturned, http_hdr->status_code, http_hdr->reason_phrase );
11965
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
567 close( fd );
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
568 fd = -1;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
569 }
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
570 stream->fd = fd;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
571
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
572 if( http_hdr ) {
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
573 http_free( http_hdr );
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
574 stream->streaming_ctrl->data = NULL;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
575 }
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
576
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
577 stream->pos=pos;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
578
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
579 return 1;
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
580 }
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
581
3d75bcc28231 enable seeking in http streams
attila
parents: 11583
diff changeset
582
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
583 int
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
584 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
585 //printf("streaming_bufferize\n");
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
586 streaming_ctrl->buffer = (char*)malloc(size);
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
587 if( streaming_ctrl->buffer==NULL ) {
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
588 mp_msg(MSGT_NETWORK,MSGL_FATAL,MSGTR_MemAllocFailed);
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
589 return -1;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
590 }
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
591 memcpy( streaming_ctrl->buffer, buffer, size );
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
592 streaming_ctrl->buffer_size = size;
3599
2141db140d84 nop_steraming fixed
arpi
parents: 3585
diff changeset
593 return size;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
594 }
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
595
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
596 int
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
597 nop_streaming_read( int fd, char *buffer, int size, streaming_ctrl_t *stream_ctrl ) {
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
598 int len=0;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
599 //printf("nop_streaming_read\n");
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
600 if( stream_ctrl->buffer_size!=0 ) {
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
601 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
602 //printf("%d bytes in buffer\n", stream_ctrl->buffer_size);
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
603 len = (size<buffer_len)?size:buffer_len;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
604 memcpy( buffer, (stream_ctrl->buffer)+(stream_ctrl->buffer_pos), len );
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
605 stream_ctrl->buffer_pos += len;
4251
05affdf4bdcd Moved network related code from open.c to network.c
bertrand
parents: 4236
diff changeset
606 //printf("buffer_pos = %d\n", stream_ctrl->buffer_pos );
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
607 if( stream_ctrl->buffer_pos>=stream_ctrl->buffer_size ) {
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
608 free( stream_ctrl->buffer );
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
609 stream_ctrl->buffer = NULL;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
610 stream_ctrl->buffer_size = 0;
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
611 stream_ctrl->buffer_pos = 0;
4251
05affdf4bdcd Moved network related code from open.c to network.c
bertrand
parents: 4236
diff changeset
612 //printf("buffer cleaned\n");
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
613 }
4251
05affdf4bdcd Moved network related code from open.c to network.c
bertrand
parents: 4236
diff changeset
614 //printf("read %d bytes from buffer\n", len );
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
615 }
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
616
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
617 if( len<size ) {
3365
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
618 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
619 ret = recv( fd, buffer+len, size-len, 0 );
3494
fb9de639ed30 Applied the patch from Alban Bedel <albeu@free.fr>.
bertrand
parents: 3453
diff changeset
620 if( ret<0 ) {
5915
f716aa9e2df2 Convert printf to mp_msg in the network layer
albeu
parents: 5892
diff changeset
621 mp_msg(MSGT_NETWORK,MSGL_ERR,"nop_streaming_read error : %s\n",strerror(errno));
3365
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
622 }
eb1c24557dad Checked the return values on read.
bertrand
parents: 3072
diff changeset
623 len += ret;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
624 //printf("read %d bytes from network\n", len );
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
625 }
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
626
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
627 return len;
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
628 }
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
629
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
630 int
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
631 nop_streaming_seek( int fd, off_t pos, streaming_ctrl_t *stream_ctrl ) {
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
632 return -1;
7953
60624e692b95 GCC warning fixes
bertrand
parents: 7881
diff changeset
633 // To shut up gcc warning
60624e692b95 GCC warning fixes
bertrand
parents: 7881
diff changeset
634 fd++;
60624e692b95 GCC warning fixes
bertrand
parents: 7881
diff changeset
635 pos++;
60624e692b95 GCC warning fixes
bertrand
parents: 7881
diff changeset
636 stream_ctrl=NULL;
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
637 }
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
638
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
639
15954
341bfd887e36 small warning fix:
rathann
parents: 15812
diff changeset
640 void fixup_network_stream_cache(stream_t *stream) {
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
641 if(stream->streaming_ctrl->buffering) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
642 if(stream_cache_size<0) {
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
643 // cache option not set, will use our computed value.
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
644 // buffer in KBytes, *5 because the prefill is 20% of the buffer.
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
645 stream_cache_size = (stream->streaming_ctrl->prebuffer_size/1024)*5;
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
646 if( stream_cache_size<64 ) stream_cache_size = 64; // 16KBytes min buffer
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
647 }
17153
c0b147bdf49d Harcoded eng strings on libmpdemux/network.c to help_mp
reynaldo
parents: 17012
diff changeset
648 mp_msg(MSGT_NETWORK,MSGL_INFO,MSGTR_MPDEMUX_NW_CacheSizeSetTo, stream_cache_size);
15585
281d155fb37f ported all network streams to the new API
nicodvb
parents: 15209
diff changeset
649 }
9922
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents: 9900
diff changeset
650 }
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents: 9900
diff changeset
651
6cb7a295ab0e Real rstp:// streaming support, ported from xine
rtognimp
parents: 9900
diff changeset
652
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
653 int
3042
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
654 streaming_stop( stream_t *stream ) {
6b6fa2be9b97 Removed my buffer hack to use cache2.
bertrand
parents: 2555
diff changeset
655 stream->streaming_ctrl->status = streaming_stopped_e;
999
92833c9472e8 Continue implementation of the network streaming part.
bertrand
parents: 903
diff changeset
656 return 0;
903
7f6641b1b0df Added autodetection of potential stream type.
bertrand
parents: 841
diff changeset
657 }