]> git.sesse.net Git - vlc/blob - modules/access/http.c
* mms: revert some parts.
[vlc] / modules / access / http.c
1 /*****************************************************************************
2  * http.c: HTTP access plug-in
3  *****************************************************************************
4  * Copyright (C) 2001, 2002 VideoLAN
5  * $Id: http.c,v 1.25 2003/03/03 14:21:08 gbazin Exp $
6  *
7  * Authors: Christophe Massiot <massiot@via.ecp.fr>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <stdlib.h>
28 #include <string.h>
29 #include <vlc/vlc.h>
30 #include <vlc/input.h>
31
32 #ifdef HAVE_ERRNO_H
33 #   include <errno.h>
34 #endif
35 #ifdef HAVE_FCNTL_H
36 #   include <fcntl.h>
37 #endif
38
39 #ifdef HAVE_SYS_TIME_H
40 #    include <sys/time.h>
41 #endif
42
43 #ifdef HAVE_UNISTD_H
44 #   include <unistd.h>
45 #endif
46
47 #if defined( UNDER_CE )
48 #   include <winsock.h>
49 #elif defined( WIN32 )
50 #   include <winsock2.h>
51 #   include <ws2tcpip.h>
52 #   ifndef IN_MULTICAST
53 #       define IN_MULTICAST(a) IN_CLASSD(a)
54 #   endif
55 #else
56 #   include <sys/socket.h>
57 #endif
58
59 #include "vlc_playlist.h"
60 #include "network.h"
61
62 /*****************************************************************************
63  * Local prototypes
64  *****************************************************************************/
65 static int  Open       ( vlc_object_t * );
66 static void Close      ( vlc_object_t * );
67
68 static int  SetProgram ( input_thread_t *, pgrm_descriptor_t * );
69 static void Seek       ( input_thread_t *, off_t );
70 static ssize_t Read    ( input_thread_t *, byte_t *, size_t );
71
72 /*****************************************************************************
73  * Module descriptor
74  *****************************************************************************/
75 #define PROXY_TEXT N_("specify an HTTP proxy")
76 #define PROXY_LONGTEXT N_( \
77     "Specify an HTTP proxy to use. It must be in the form " \
78     "http://myproxy.mydomain:myport. If none is specified, the HTTP_PROXY " \
79     "environment variable will be tried." )
80
81 #define CACHING_TEXT N_("caching value in ms")
82 #define CACHING_LONGTEXT N_( \
83     "Allows you to modify the default caching value for http streams. This " \
84     "value should be set in miliseconds units." )
85
86 vlc_module_begin();
87     add_category_hint( N_("http"), NULL, VLC_FALSE );
88     add_string( "http-proxy", NULL, NULL, PROXY_TEXT, PROXY_LONGTEXT, VLC_FALSE );
89     add_integer( "http-caching", 4 * DEFAULT_PTS_DELAY / 1000, NULL, CACHING_TEXT, CACHING_LONGTEXT, VLC_TRUE );
90     set_description( _("HTTP access module") );
91     set_capability( "access", 0 );
92     add_shortcut( "http" );
93     add_shortcut( "http4" );
94     add_shortcut( "http6" );
95     set_callbacks( Open, Close );
96 vlc_module_end();
97
98 /*****************************************************************************
99  * _input_socket_t: private access plug-in data, modified to add private
100  *                  fields
101  *****************************************************************************/
102 #define MAX_ANSWER_SIZE 1024
103 #define MAX_QUERY_SIZE 1024
104
105 typedef struct _input_socket_s
106 {
107     input_socket_t      _socket;
108
109     char *              psz_network;
110     network_socket_t    socket_desc;
111     char                psz_buffer[MAX_QUERY_SIZE];
112     char *              psz_name;
113 } _input_socket_t;
114
115 /*****************************************************************************
116  * HTTPConnect: connect to the server and seek to i_tell
117  *****************************************************************************/
118 static int HTTPConnect( input_thread_t * p_input, off_t i_tell )
119 {
120     char psz_buffer[MAX_QUERY_SIZE];
121     _input_socket_t * p_access_data;
122     module_t * p_network;
123     char * psz_parser, * psz_value, * psz_answer;
124     int i_code, i_ret, i, i_size;
125
126     enum { HTTP_PROTOCOL, ICY_PROTOCOL } i_protocol;
127
128     /* Find an appropriate network module */
129     p_access_data = (_input_socket_t *)p_input->p_access_data;
130     p_input->p_private = (void*) &p_access_data->socket_desc;
131     p_network = module_Need( p_input, "network", p_access_data->psz_network );
132     if( p_network == NULL )
133     {
134         return VLC_ENOMOD;
135     }
136     module_Unneed( p_input, p_network );
137
138     p_access_data->_socket.i_handle = p_access_data->socket_desc.i_handle;
139
140 #   define HTTP_USERAGENT "User-Agent: " COPYRIGHT_MESSAGE "\r\n"
141 #   define HTTP_END       "\r\n"
142
143     /* Build the query string */
144     if ( p_input->stream.b_seekable )
145     {
146          snprintf( psz_buffer, MAX_QUERY_SIZE,
147                    "%s"
148                    "Range: bytes="I64Fd"-\r\n"
149                    HTTP_USERAGENT HTTP_END,
150                    p_access_data->psz_buffer, i_tell );
151     }
152     else
153     {
154          snprintf( psz_buffer, MAX_QUERY_SIZE,
155                    "%s"
156                    HTTP_USERAGENT HTTP_END,
157                    p_access_data->psz_buffer );
158     }
159     psz_buffer[MAX_QUERY_SIZE - 1] = '\0';
160
161     /* Send GET query */
162     i_ret = send( p_access_data->_socket.i_handle,
163                   psz_buffer, strlen( psz_buffer ), 0 );
164     if( i_ret == -1 )
165     {
166 #ifdef HAVE_ERRNO_H
167         msg_Err( p_input, "cannot send request (%s)", strerror(errno) );
168 #else
169         msg_Err( p_input, "cannot send request" );
170 #endif
171         Close( VLC_OBJECT(p_input) );
172         return VLC_EGENERIC;
173     }
174
175     /* Prepare the input thread for reading. */
176     p_input->i_bufsize = INPUT_DEFAULT_BUFSIZE;
177
178     /* FIXME: we shouldn't have to do that ! It's UGLY but mandatory because
179      * input_FillBuffer assumes p_input->pf_read exists */
180     p_input->pf_read = Read;
181
182     while( !input_FillBuffer( p_input ) )
183     {
184         if( p_input->b_die || p_input->b_error )
185         {
186             Close( VLC_OBJECT(p_input) );
187             return VLC_EGENERIC;
188         }
189     }
190
191     /* Get the HTTP returncode */
192     i_size = input_Peek( p_input, (byte_t**)&psz_parser, MAX_ANSWER_SIZE );
193
194     if( i_size <= 0 )
195     {
196         msg_Err( p_input, "not enough data" );
197         Close( VLC_OBJECT(p_input) );
198         return VLC_EGENERIC;
199     }
200
201     /* Guess the protocol */
202     if( ( ( (size_t)i_size >= strlen("HTTP/1.x") ) &&
203             !strncmp( psz_parser, "HTTP/1.", strlen("HTTP/1.") ) ) )
204     {
205         i_protocol = HTTP_PROTOCOL;
206
207         psz_parser += strlen("HTTP/1.x");
208         i_size -= strlen("HTTP/1.x");
209     }
210     else if( ( (size_t)i_size >= strlen("ICY") &&
211              !strncmp( psz_parser, "ICY", strlen("ICY") ) ) )
212     {
213         i_protocol = ICY_PROTOCOL;
214         if( !p_input->psz_demux || !*p_input->psz_demux  )
215         {
216             msg_Info( p_input, "ICY server found, mp3 demuxer selected" );
217             p_input->psz_demux = "mp3";    // FIXME strdup ?
218         }
219
220         psz_parser += strlen("ICY");
221         i_size -= strlen("ICY");
222     }
223     else
224     {
225         msg_Err( p_input, "invalid HTTP reply '%s'", psz_parser );
226         return VLC_EGENERIC;
227     }
228
229     /* Check the HTTP return code */
230     i_code = atoi( (char*)psz_parser );
231     msg_Dbg( p_input, "%s server replied: %i",
232              i_protocol == HTTP_PROTOCOL ? "HTTP" : "ICY", i_code );
233     psz_parser += 4;
234     i_size -= 4;
235
236     /* Find the end of the line */
237     for ( i = 0; (i < i_size -1) && ((psz_parser[i] != '\r') ||
238       (psz_parser[i+1] != '\n')); i++ )
239     {
240         ;
241     }
242
243     /* Check we actually parsed something */
244     if ( i+1 == i_size && psz_parser[i+1] != '\n' )
245     {
246         msg_Err( p_input, "stream not compliant with HTTP/1.x" );
247         return VLC_EGENERIC;
248     }
249
250     /* Store the line we just parsed and skip it */
251     psz_answer = strndup( psz_parser, i );
252     if( !psz_answer )
253     {
254         return VLC_ENOMEM;
255     }
256
257     p_input->p_current_data = psz_parser + i + 2;
258
259     /* Parse remaining headers */
260     for ( ; ; )
261     {
262         char psz_line[MAX_ANSWER_SIZE];
263
264         i_size = input_Peek( p_input, (byte_t**)&psz_parser, MAX_ANSWER_SIZE );
265
266         if( i_size <= 0 )
267         {
268             msg_Err( p_input, "not enough data" );
269             Close( VLC_OBJECT(p_input) );
270             free( psz_answer );
271             return VLC_EGENERIC;
272         }
273
274         /* Copy one line to psz_line */
275         i = 0;
276         while( i_size && psz_parser[i] != '\r'
277                       && psz_parser[i + 1] != '\n' )
278         {
279             psz_line[i] = psz_parser[i];
280             i++;
281             i_size--;
282         }
283         p_input->p_current_data = psz_parser + i + 2;
284         if( !i )
285         {
286             break; /* End of headers */
287         }
288         psz_line[i] = '\0';
289         psz_parser = strchr( psz_line, ':' );
290         if ( !psz_parser )
291         {
292             msg_Err( p_input, "malformed header line: %s", psz_line );
293             free( psz_answer );
294             return VLC_EGENERIC;
295         }
296         psz_parser[0] = '\0';
297         psz_parser++;
298         while ( *psz_parser == ' ' || *psz_parser == '\t' )
299         {
300             psz_parser++;
301         }
302         psz_value = psz_parser;
303
304         if( !strcasecmp( psz_line, "Content-Length" ) )
305         {
306             off_t i_size = 0;
307 #ifdef HAVE_ATOLL
308             i_size = i_tell + atoll( psz_value );
309 #else
310             psz_parser = psz_value;
311             while( psz_parser[0] >= '0' && psz_parser[0] <= '9' )
312             {
313                 i_size *= 10;
314                 i_size += psz_parser[0] - '0';
315             }
316             i_size += i_tell;
317 #endif
318             msg_Dbg( p_input, "stream size is "I64Fd, i_size );
319
320             vlc_mutex_lock( &p_input->stream.stream_lock );
321             p_input->stream.p_selected_area->i_size = i_size;
322             vlc_mutex_unlock( &p_input->stream.stream_lock );
323         }
324         /* Redirection support */
325         else if( ( i_code == 301 || i_code == 302 ||
326                    i_code == 303 || i_code == 307 )
327                     && !strcasecmp( psz_line, "location" ) )
328         {
329             playlist_t * p_playlist = (playlist_t *) vlc_object_find(
330                                   p_input, VLC_OBJECT_PLAYLIST, FIND_PARENT );
331             if( !p_playlist )
332             {
333                 msg_Err( p_input, "redirection failed: can't find playlist" );
334                 free( psz_answer );
335                 return VLC_EGENERIC;
336             }
337             msg_Dbg( p_input, "%i %s: redirected to %s",
338                               i_code, psz_answer, psz_value );
339             p_playlist->pp_items[p_playlist->i_index]->b_autodeletion
340                                                                   = VLC_TRUE;
341             playlist_Add( p_playlist, psz_value,
342                           PLAYLIST_APPEND | PLAYLIST_GO, PLAYLIST_END );
343             vlc_object_release( p_playlist );
344         }
345
346         /* TODO: parse other headers here */
347     }
348
349     /* Something went wrong */
350     if ( i_code >= 400 )
351     {
352         msg_Err( p_input, "%i %s", i_code, psz_answer );
353         p_input->p_current_data = psz_parser + i_size;
354         free( psz_answer );
355         return VLC_EGENERIC;
356     }
357
358     free( psz_answer );
359
360     /* Set final stream properties */
361     vlc_mutex_lock( &p_input->stream.stream_lock );
362     if( i_protocol == ICY_PROTOCOL )
363     {
364         p_input->stream.b_seekable = VLC_FALSE;
365     }
366     else
367     {
368         p_input->stream.b_seekable = VLC_TRUE;
369     }
370
371     if( p_input->stream.p_selected_area->i_size )
372     {
373         p_input->stream.p_selected_area->i_tell = i_tell;
374     }
375     else
376     {
377         p_input->stream.b_seekable = VLC_FALSE;
378     }
379     p_input->stream.b_changed = VLC_TRUE;
380     vlc_mutex_unlock( &p_input->stream.stream_lock );
381
382     return VLC_SUCCESS;
383 }
384
385 /*****************************************************************************
386  * Open: parse URL and open the remote file at the beginning
387  *****************************************************************************/
388 static int Open( vlc_object_t *p_this )
389 {
390     input_thread_t *    p_input = (input_thread_t *)p_this;
391     _input_socket_t *   p_access_data;
392     char *              psz_name = strdup(p_input->psz_name);
393     char *              psz_parser = psz_name;
394     char *              psz_server_addr = "";
395     char *              psz_server_port = "";
396     char *              psz_path = "";
397     char *              psz_proxy, *psz_proxy_orig;
398     int                 i_server_port = 0;
399
400     p_access_data = malloc( sizeof(_input_socket_t) );
401     p_input->p_access_data = (access_sys_t *)p_access_data;
402     if( p_access_data == NULL )
403     {
404         msg_Err( p_input, "out of memory" );
405         free(psz_name);
406         return VLC_ENOMEM;
407     }
408
409     p_access_data->psz_name = psz_name;
410     p_access_data->psz_network = "";
411     if( config_GetInt( p_input, "ipv4" ) )
412     {
413         p_access_data->psz_network = "ipv4";
414     }
415     if( config_GetInt( p_input, "ipv6" ) )
416     {
417         p_access_data->psz_network = "ipv6";
418     }
419     if( *p_input->psz_access )
420     {
421         /* Find out which shortcut was used */
422         if( !strncmp( p_input->psz_access, "http6", 6 ) )
423         {
424             p_access_data->psz_network = "ipv6";
425         }
426         else if( !strncmp( p_input->psz_access, "http4", 6 ) )
427         {
428             p_access_data->psz_network = "ipv4";
429         }
430     }
431
432     /* Parse psz_name syntax :
433      * //<hostname>[:<port>][/<path>] */
434     while( *psz_parser == '/' )
435     {
436         psz_parser++;
437     }
438     psz_server_addr = psz_parser;
439
440     while( *psz_parser && *psz_parser != ':' && *psz_parser != '/' )
441     {
442         if( *psz_parser == '[' )
443         {
444             /* IPv6 address */
445             while( *psz_parser && *psz_parser != ']' )
446             {
447                 psz_parser++;
448             }
449         }
450         psz_parser++;
451     }
452
453     if ( *psz_parser == ':' )
454     {
455         *psz_parser = '\0';
456         psz_parser++;
457         psz_server_port = psz_parser;
458
459         while( *psz_parser && *psz_parser != '/' )
460         {
461             psz_parser++;
462         }
463     }
464
465     if( *psz_parser == '/' )
466     {
467         *psz_parser = '\0';
468         psz_parser++;
469         psz_path = psz_parser;
470     }
471
472     /* Convert port format */
473     if( *psz_server_port )
474     {
475         i_server_port = strtol( psz_server_port, &psz_parser, 10 );
476         if( *psz_parser )
477         {
478             msg_Err( p_input, "cannot parse server port near %s", psz_parser );
479             free( p_input->p_access_data );
480             free( psz_name );
481             return VLC_EGENERIC;
482         }
483     }
484
485     if( i_server_port == 0 )
486     {
487         i_server_port = 80;
488     }
489
490     if( !*psz_server_addr )
491     {
492         msg_Err( p_input, "no server given" );
493         free( p_input->p_access_data );
494         free( psz_name );
495         return VLC_EGENERIC;
496     }
497
498     /* Check proxy config variable */
499     psz_proxy_orig = config_GetPsz( p_input, "http-proxy" );
500     if( psz_proxy_orig == NULL )
501     {
502         /* Check proxy environment variable */
503         psz_proxy_orig = getenv( "http_proxy" );
504         if( psz_proxy_orig != NULL )
505         {
506             psz_proxy_orig = strdup( psz_proxy_orig );
507         }
508     }
509
510     psz_proxy = psz_proxy_orig;
511     if( psz_proxy != NULL && *psz_proxy )
512     {
513         /* http://myproxy.mydomain:myport/ */
514         int i_proxy_port = 0;
515
516         /* Skip the protocol name */
517         while( *psz_proxy && *psz_proxy != ':' )
518         {
519             psz_proxy++;
520         }
521
522         /* Skip the "://" part */
523         while( *psz_proxy && (*psz_proxy == ':' || *psz_proxy == '/') )
524         {
525             psz_proxy++;
526         }
527
528         /* Found a proxy name */
529         if( *psz_proxy )
530         {
531             char *psz_port = psz_proxy;
532
533             /* Skip the hostname part */
534             while( *psz_port && *psz_port != ':' && *psz_port != '/' )
535             {
536                 psz_port++;
537             }
538
539             /* Found a port name */
540             if( *psz_port )
541             {
542                 char * psz_junk;
543
544                 /* Replace ':' with '\0' */
545                 *psz_port = '\0';
546                 psz_port++;
547
548                 psz_junk = psz_port;
549                 while( *psz_junk && *psz_junk != '/' )
550                 {
551                     psz_junk++;
552                 }
553
554                 if( *psz_junk )
555                 {
556                     *psz_junk = '\0';
557                 }
558
559                 if( *psz_port != '\0' )
560                 {
561                     i_proxy_port = atoi( psz_port );
562                 }
563             }
564
565             psz_proxy = strdup( psz_proxy );
566
567             msg_Dbg( p_input, "using HTTP proxy server=%s port=%d",
568                      psz_proxy, i_proxy_port );
569         }
570         else
571         {
572             msg_Err( p_input, "HTTP proxy %s is invalid!", psz_proxy_orig );
573             free( p_input->p_access_data );
574             free( psz_name );
575             if( psz_proxy_orig ) free( psz_proxy_orig );
576             return VLC_EGENERIC;
577         }
578
579         if( psz_proxy_orig ) free( psz_proxy_orig );
580
581         p_access_data->socket_desc.psz_server_addr = psz_proxy;
582         p_access_data->socket_desc.i_server_port = i_proxy_port;
583         p_access_data->socket_desc.i_type = NETWORK_TCP;
584
585         snprintf( p_access_data->psz_buffer, MAX_QUERY_SIZE,
586                   "GET http://%s:%d/%s HTTP/1.0\r\n",
587                   psz_server_addr, i_server_port, psz_path );
588     }
589     else
590     {
591         /* No proxy, direct connection. */
592         p_access_data->socket_desc.i_type = NETWORK_TCP;
593         p_access_data->socket_desc.psz_server_addr = psz_server_addr;
594         p_access_data->socket_desc.i_server_port = i_server_port;
595
596         snprintf( p_access_data->psz_buffer, MAX_QUERY_SIZE,
597                   "GET /%s HTTP/1.1\r\nHost: %s\r\n",
598                   psz_path, psz_server_addr );
599     }
600     p_access_data->psz_buffer[MAX_QUERY_SIZE - 1] = '\0';
601
602     msg_Dbg( p_input, "opening server=%s port=%d path=%s",
603                       psz_server_addr, i_server_port, psz_path );
604
605     p_input->pf_read = Read;
606     p_input->pf_set_program = SetProgram;
607     p_input->pf_set_area = NULL;
608     p_input->pf_seek = Seek;
609
610     vlc_mutex_lock( &p_input->stream.stream_lock );
611     p_input->stream.b_pace_control = VLC_TRUE;
612     p_input->stream.b_seekable = VLC_TRUE;
613     p_input->stream.b_connected = VLC_TRUE;
614     p_input->stream.p_selected_area->i_tell = 0;
615     p_input->stream.p_selected_area->i_size = 0;
616     p_input->stream.i_method = INPUT_METHOD_NETWORK;
617     vlc_mutex_unlock( &p_input->stream.stream_lock );
618     p_input->i_mtu = 0;
619
620     if( HTTPConnect( p_input, 0 ) )
621     {
622         /* Request failed, try again with HTTP/1.0 */
623         char * psz_pos = strstr( p_access_data->psz_buffer, "HTTP/1.1" );
624
625         if( !psz_pos )
626         {
627             return VLC_EGENERIC;
628         }
629
630         p_input->stream.b_seekable = VLC_FALSE;
631         psz_pos[7] = '0';
632         if( HTTPConnect( p_input, 0 ) )
633         {
634             free( p_input->p_access_data );
635             free( psz_name );
636             return VLC_EGENERIC;
637         }
638     }
639
640     /* Update default_pts to a suitable value for http access */
641     p_input->i_pts_delay = config_GetInt( p_input, "http-caching" ) * 1000;
642
643     return VLC_SUCCESS;
644 }
645
646 /*****************************************************************************
647  * Close: free unused data structures
648  *****************************************************************************/
649 static void Close( vlc_object_t *p_this )
650 {
651     input_thread_t *  p_input = (input_thread_t *)p_this;
652     int i_handle = ((network_socket_t *)p_input->p_access_data)->i_handle;
653     _input_socket_t * p_access_data =
654         (_input_socket_t *)p_input->p_access_data;
655
656     free( p_access_data->psz_name );
657
658     msg_Info( p_input, "closing HTTP target `%s'", p_input->psz_source );
659
660 #if defined( WIN32 ) || defined( UNDER_CE )
661     closesocket( i_handle );
662 #else
663     close( i_handle );
664 #endif
665
666     free( p_access_data );
667 }
668
669 /*****************************************************************************
670  * SetProgram: do nothing
671  *****************************************************************************/
672 static int SetProgram( input_thread_t * p_input,
673                        pgrm_descriptor_t * p_program )
674 {
675     return VLC_SUCCESS;
676 }
677
678 /*****************************************************************************
679  * Seek: close and re-open a connection at the right place
680  *****************************************************************************/
681 static void Seek( input_thread_t * p_input, off_t i_pos )
682 {
683     _input_socket_t *p_access_data = (_input_socket_t*)p_input->p_access_data;
684 #if defined( WIN32 ) || defined( UNDER_CE )
685     closesocket( p_access_data->_socket.i_handle );
686 #else
687     close( p_access_data->_socket.i_handle );
688 #endif
689     msg_Dbg( p_input, "seeking to position "I64Fd, i_pos );
690     HTTPConnect( p_input, i_pos );
691 }
692
693 /*****************************************************************************
694  * Read: read on a file descriptor, checking b_die periodically
695  *****************************************************************************/
696 static ssize_t Read( input_thread_t * p_input, byte_t * p_buffer, size_t i_len )
697 {
698     input_socket_t * p_access_data = (input_socket_t *)p_input->p_access_data;
699     struct timeval  timeout;
700     fd_set          fds;
701     int             i_ret;
702
703     /* Initialize file descriptor set */
704     FD_ZERO( &fds );
705     FD_SET( p_access_data->i_handle, &fds );
706
707     /* We'll wait 0.5 second if nothing happens */
708     timeout.tv_sec = 0;
709     timeout.tv_usec = 500000;
710
711     /* Find if some data is available */
712     i_ret = select( p_access_data->i_handle + 1, &fds,
713                     NULL, NULL, &timeout );
714
715 #ifdef HAVE_ERRNO_H
716     if( i_ret == -1 && errno != EINTR )
717     {
718         msg_Err( p_input, "network select error (%s)", strerror(errno) );
719     }
720 #else
721     if( i_ret == -1 )
722     {
723         msg_Err( p_input, "network select error" );
724     }
725 #endif
726     else if( i_ret > 0 )
727     {
728         ssize_t i_recv = recv( p_access_data->i_handle, p_buffer, i_len, 0 );
729
730         if( i_recv < 0 )
731         {
732 #ifdef HAVE_ERRNO_H
733             msg_Err( p_input, "recv failed (%s)", strerror(errno) );
734 #else
735             msg_Err( p_input, "recv failed" );
736 #endif
737         }
738
739         return i_recv;
740     }
741
742     return 0;
743 }