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