1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004-2005 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * RĂ©mi Denis-Courmont <rem # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
30 #include "vlc_httpd.h"
46 #if defined( UNDER_CE )
48 #elif defined( WIN32 )
49 # include <winsock2.h>
50 # include <ws2tcpip.h>
52 # include <netdb.h> /* hostent ... */
53 # include <sys/socket.h>
54 /* FIXME: should not be needed */
55 # include <netinet/in.h>
56 # ifdef HAVE_ARPA_INET_H
57 # include <arpa/inet.h> /* inet_ntoa(), inet_aton() */
62 /* We need HUGE buffer otherwise TCP throughput is very limited */
63 #define HTTPD_CL_BUFSIZE 1000000
65 #define HTTPD_CL_BUFSIZE 10000
69 typedef struct httpd_t httpd_t;
71 typedef struct httpd_host_t httpd_host_t;
72 typedef struct httpd_url_t httpd_url_t;
73 typedef struct httpd_client_t httpd_client_t;
82 /* channel communication */
98 /* just to track the count of MSG */
111 httpd_client_t *cl; /* NULL if not throught a connection e vlc internal */
123 char *psz_args; /* FIXME find a clean way to handle GET(psz_args) and POST(body) through the same code */
125 /* for rtp over rtsp */
135 int64_t i_body_offset;
141 typedef struct httpd_callback_sys_t httpd_callback_sys_t;
142 /* answer could be null, int this case no answer is requested */
143 typedef int (*httpd_callback_t)( httpd_callback_sys_t *, httpd_client_t *, httpd_message_t *answer, httpd_message_t *query );
146 /* create a new host */
147 httpd_host_t *httpd_HostNew( vlc_object_t *, char *psz_host, int i_port );
149 void httpd_HostDelete( httpd_host_t * );
151 /* register a new url */
152 httpd_url_t *httpd_UrlNew( httpd_host_t *, char *psz_url );
153 /* register callback on a url */
154 int httpd_UrlCatch( httpd_url_t *, int i_msg,
155 httpd_callback_t, httpd_callback_sys_t * );
157 void httpd_UrlDelete( httpd_url_t * );
160 void httpd_ClientModeStream( httpd_client_t *cl );
161 void httpd_ClientModeBidir( httpd_client_t *cl );
162 static void httpd_ClientClean( httpd_client_t *cl );
165 typedef struct httpd_file_t httpd_file_t;
166 typedef struct httpd_file_sys_t httpd_file_sys_t;
167 typedef int (*httpd_file_callback_t)( httpd_file_sys_t*, httpd_file_t *, uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
168 httpd_file_t *httpd_FileNew( httpd_host_t *,
169 char *psz_url, char *psz_mime,
170 char *psz_user, char *psz_password,
171 httpd_file_callback_t pf_fill,
172 httpd_file_sys_t *p_sys );
173 void httpd_FileDelete( httpd_file_t * );
175 typedef struct httpd_redirect_t httpd_redirect_t;
176 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *, char *psz_url_dst, char *psz_url_src );
177 void httpd_RedirectDelete( httpd_redirect_t * );
180 typedef struct httpd_stream_t httpd_stream_t;
181 httpd_stream_t *httpd_StreamNew( httpd_host_t * );
182 int httpd_StreamHeader( httpd_stream_t *, uint8_t *p_data, int i_data );
183 int httpd_StreamSend( httpd_stream_t *, uint8_t *p_data, int i_data );
184 void httpd_StreamDelete( httpd_stream_t * );
187 /* Msg functions facilities */
188 void httpd_MsgInit( httpd_message_t * );
189 void httpd_MsgAdd( httpd_message_t *, char *psz_name, char *psz_value, ... );
190 /* return "" if not found. The string is not allocated */
191 char *httpd_MsgGet( httpd_message_t *, char *psz_name );
192 void httpd_MsgClean( httpd_message_t * );
200 /* vlc_mutex_t lock; */
206 static void httpd_ClientClean( httpd_client_t *cl );
208 /* each host run in his own thread */
218 /* address/port and socket for listening at connections */
225 /* all registered url (becarefull that 2 httpd_url_t could point at the same url)
226 * This will slow down the url research but make my live easier
227 * All url will have their cb trigger, but only the first one can answer
233 httpd_client_t **client;
253 httpd_callback_sys_t *p_sys;
254 } catch[HTTPD_MSG_MAX];
260 HTTPD_CLIENT_RECEIVING,
261 HTTPD_CLIENT_RECEIVE_DONE,
263 HTTPD_CLIENT_SENDING,
264 HTTPD_CLIENT_SEND_DONE,
266 HTTPD_CLIENT_WAITING,
270 HTTPD_CLIENT_TLS_HS_IN,
271 HTTPD_CLIENT_TLS_HS_OUT
276 HTTPD_CLIENT_FILE, /* default */
277 HTTPD_CLIENT_STREAM, /* regulary get data from cb */
278 HTTPD_CLIENT_BIDIR, /* check for reading and get data from cb */
281 struct httpd_client_t
287 struct sockaddr_storage sock;
293 int b_read_waiting; /* stop as soon as possible sending */
295 mtime_t i_activity_date;
296 mtime_t i_activity_timeout;
298 /* buffer for reading header */
304 httpd_message_t query; /* client -> httpd */
305 httpd_message_t answer; /* httpd -> client */
308 tls_session_t *p_tls;
312 /*****************************************************************************
314 *****************************************************************************/
315 /*char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";*/
316 static void b64_decode( char *dest, char *src )
321 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */
322 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */
323 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */
324 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */
325 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */
326 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */
327 -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */
328 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */
329 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */
330 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */
331 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */
332 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */
333 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */
334 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */
335 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */
336 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */
339 for( i_level = 0; *src != '\0'; src++ )
343 c = b64[(unsigned int)*src];
355 *dest++ = ( last << 2 ) | ( ( c >> 4)&0x03 );
359 *dest++ = ( ( last << 4 )&0xf0 ) | ( ( c >> 2 )&0x0f );
363 *dest++ = ( ( last &0x03 ) << 6 ) | c;
375 const char *psz_mime;
378 { ".htm", "text/html" },
379 { ".html", "text/html" },
380 { ".txt", "text/plain" },
381 { ".xml", "text/xml" },
382 { ".dtd", "text/dtd" },
384 { ".css", "text/css" },
387 { ".gif", "image/gif" },
388 { ".jpe", "image/jpeg" },
389 { ".jpg", "image/jpeg" },
390 { ".jpeg", "image/jpeg" },
391 { ".png", "image/png" },
392 { ".mpjpeg","multipart/x-mixed-replace; boundary=This Random String" },
395 { ".avi", "video/avi" },
396 { ".asf", "video/x-ms-asf" },
397 { ".m1a", "audio/mpeg" },
398 { ".m2a", "audio/mpeg" },
399 { ".m1v", "video/mpeg" },
400 { ".m2v", "video/mpeg" },
401 { ".mp2", "audio/mpeg" },
402 { ".mp3", "audio/mpeg" },
403 { ".mpa", "audio/mpeg" },
404 { ".mpg", "video/mpeg" },
405 { ".mpeg", "video/mpeg" },
406 { ".mpe", "video/mpeg" },
407 { ".mov", "video/quicktime" },
408 { ".moov", "video/quicktime" },
409 { ".ogg", "application/ogg" },
410 { ".ogm", "application/ogg" },
411 { ".wav", "audio/wav" },
412 { ".wma", "audio/x-ms-wma" },
413 { ".wmv", "video/x-ms-wmv" },
419 static const char *httpd_MimeFromUrl( const char *psz_url )
424 psz_ext = strrchr( psz_url, '.' );
429 for( i = 0; http_mime[i].psz_ext != NULL ; i++ )
431 if( !strcasecmp( http_mime[i].psz_ext, psz_ext ) )
433 return http_mime[i].psz_mime;
437 return "application/octet-stream";
440 /*****************************************************************************
441 * High Level Functions: httpd_file_t
442 *****************************************************************************/
450 httpd_file_callback_t pf_fill;
451 httpd_file_sys_t *p_sys;
456 static int httpd_FileCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, httpd_message_t *answer, httpd_message_t *query )
458 httpd_file_t *file = (httpd_file_t*)p_sys;
459 uint8_t *psz_args = query->psz_args;
460 uint8_t **pp_body, *p_body;
461 int *pi_body, i_body;
463 if( answer == NULL || query == NULL )
467 answer->i_proto = HTTPD_PROTO_HTTP;
468 answer->i_version= query->i_version;
469 answer->i_type = HTTPD_MSG_ANSWER;
471 answer->i_status = 200;
472 answer->psz_status = strdup( "OK" );
474 httpd_MsgAdd( answer, "Content-type", "%s", file->psz_mime );
475 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
477 if( query->i_type != HTTPD_MSG_HEAD )
479 pp_body = &answer->p_body;
480 pi_body = &answer->i_body;
484 /* The file still needs to be executed. */
491 if( query->i_type == HTTPD_MSG_POST )
493 /* msg_Warn not supported */
496 file->pf_fill( file->p_sys, file, psz_args, pp_body, pi_body );
498 if( query->i_type == HTTPD_MSG_HEAD && p_body != NULL )
503 /* We respect client request */
504 if( strcmp( httpd_MsgGet( &cl->query, "Connection" ), "" ) )
506 httpd_MsgAdd( answer, "Connection",
507 httpd_MsgGet( &cl->query, "Connection" ) );
510 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
516 httpd_file_t *httpd_FileNew( httpd_host_t *host,
517 const char *psz_url, const char *psz_mime,
518 const char *psz_user, const char *psz_password,
519 const vlc_acl_t *p_acl, httpd_file_callback_t pf_fill,
520 httpd_file_sys_t *p_sys )
522 httpd_file_t *file = malloc( sizeof( httpd_file_t ) );
524 if( ( file->url = httpd_UrlNewUnique( host, psz_url, psz_user,
525 psz_password, p_acl )
532 file->psz_url = strdup( psz_url );
533 if( psz_mime && *psz_mime )
535 file->psz_mime = strdup( psz_mime );
539 file->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
542 file->pf_fill = pf_fill;
545 httpd_UrlCatch( file->url, HTTPD_MSG_HEAD, httpd_FileCallBack,
546 (httpd_callback_sys_t*)file );
547 httpd_UrlCatch( file->url, HTTPD_MSG_GET, httpd_FileCallBack,
548 (httpd_callback_sys_t*)file );
549 httpd_UrlCatch( file->url, HTTPD_MSG_POST, httpd_FileCallBack,
550 (httpd_callback_sys_t*)file );
555 void httpd_FileDelete( httpd_file_t *file )
557 httpd_UrlDelete( file->url );
559 free( file->psz_url );
560 free( file->psz_mime );
565 /*****************************************************************************
566 * High Level Functions: httpd_handler_t (for CGIs)
567 *****************************************************************************/
568 struct httpd_handler_t
572 httpd_handler_callback_t pf_fill;
573 httpd_handler_sys_t *p_sys;
577 static int httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, httpd_message_t *answer, httpd_message_t *query )
579 httpd_handler_t *handler = (httpd_handler_t*)p_sys;
580 uint8_t *psz_args = query->psz_args;
581 char psz_remote_addr[100];
583 if( answer == NULL || query == NULL )
587 answer->i_proto = HTTPD_PROTO_NONE;
588 answer->i_type = HTTPD_MSG_ANSWER;
590 /* We do it ourselves, thanks */
591 answer->i_status = 0;
592 answer->psz_status = NULL;
594 switch( cl->sock.ss_family )
596 #ifdef HAVE_INET_PTON
598 inet_ntop( cl->sock.ss_family,
599 &((struct sockaddr_in *)&cl->sock)->sin_addr,
600 psz_remote_addr, sizeof(psz_remote_addr) );
603 inet_ntop( cl->sock.ss_family,
604 &((struct sockaddr_in6 *)&cl->sock)->sin6_addr,
605 psz_remote_addr, sizeof(psz_remote_addr) );
610 char *psz_tmp = inet_ntoa( ((struct sockaddr_in *)&cl->sock)->sin_addr );
611 strncpy( psz_remote_addr, psz_tmp, sizeof(psz_remote_addr) );
616 psz_remote_addr[0] = '\0';
619 handler->pf_fill( handler->p_sys, handler, query->psz_url, psz_args,
620 query->i_type, query->p_body, query->i_body,
621 psz_remote_addr, NULL,
622 &answer->p_body, &answer->i_body );
624 if( query->i_type == HTTPD_MSG_HEAD )
626 char *p = (char *)answer->p_body;
627 while ( (p = strchr( p, '\r' )) != NULL )
629 if( p[1] && p[1] == '\n' && p[2] && p[2] == '\r'
630 && p[3] && p[3] == '\n' )
638 answer->i_body = strlen((char*)answer->p_body) + 1;
639 answer->p_body = realloc( answer->p_body, answer->i_body );
643 if( strncmp( (char *)answer->p_body, "HTTP/1.", 7 ) )
645 int i_status, i_headers;
646 char *psz_headers, *psz_new, *psz_status;
648 if( !strncmp( (char *)answer->p_body, "Status: ", 8 ) )
651 i_status = strtol( (char *)&answer->p_body[8], &psz_headers, 0 );
652 if( *psz_headers ) psz_headers++;
653 if( *psz_headers ) psz_headers++;
654 i_headers = answer->i_body - (psz_headers - (char *)answer->p_body);
659 psz_headers = (char *)answer->p_body;
660 i_headers = answer->i_body;
668 psz_status = "Unauthorized";
671 if( (i_status < 0) || (i_status > 999) )
673 psz_status = "Undefined";
676 answer->i_body = sizeof("HTTP/1.0 xxx \r\n")
677 + strlen(psz_status) + i_headers - 1;
678 psz_new = (char *)malloc( answer->i_body + 1);
679 sprintf( psz_new, "HTTP/1.0 %03d %s\r\n", i_status, psz_status );
680 memcpy( &psz_new[strlen(psz_new)], psz_headers, i_headers );
681 free( answer->p_body );
682 answer->p_body = (uint8_t *)psz_new;
688 httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
689 const char *psz_user,
690 const char *psz_password,
691 const vlc_acl_t *p_acl,
692 httpd_handler_callback_t pf_fill,
693 httpd_handler_sys_t *p_sys )
695 httpd_handler_t *handler = malloc( sizeof( httpd_handler_t ) );
697 if( ( handler->url = httpd_UrlNewUnique( host, psz_url, psz_user,
698 psz_password, p_acl )
705 handler->pf_fill = pf_fill;
706 handler->p_sys = p_sys;
708 httpd_UrlCatch( handler->url, HTTPD_MSG_HEAD, httpd_HandlerCallBack,
709 (httpd_callback_sys_t*)handler );
710 httpd_UrlCatch( handler->url, HTTPD_MSG_GET, httpd_HandlerCallBack,
711 (httpd_callback_sys_t*)handler );
712 httpd_UrlCatch( handler->url, HTTPD_MSG_POST, httpd_HandlerCallBack,
713 (httpd_callback_sys_t*)handler );
718 void httpd_HandlerDelete( httpd_handler_t *handler )
720 httpd_UrlDelete( handler->url );
724 /*****************************************************************************
725 * High Level Functions: httpd_redirect_t
726 *****************************************************************************/
727 struct httpd_redirect_t
733 static int httpd_RedirectCallBack( httpd_callback_sys_t *p_sys,
734 httpd_client_t *cl, httpd_message_t *answer,
735 httpd_message_t *query )
737 httpd_redirect_t *rdir = (httpd_redirect_t*)p_sys;
740 if( answer == NULL || query == NULL )
744 answer->i_proto = query->i_proto;
745 answer->i_version= query->i_version;
746 answer->i_type = HTTPD_MSG_ANSWER;
747 answer->i_status = 301;
748 answer->psz_status = strdup( "Moved Permanently" );
750 p = answer->p_body = malloc( 1000 + strlen( rdir->psz_dst ) );
751 p += sprintf( (char *)p,
752 "<?xml version=\"1.0\" encoding=\"ascii\" ?>\n"
753 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
754 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
757 "<title>Redirection</title>\n"
761 "<a href=\"%s\">redirected</a></h1>\n"
763 "<p><a href=\"http://www.videolan.org\">VideoLAN</a>\n</p>"
766 "</html>\n", rdir->psz_dst );
767 answer->i_body = p - answer->p_body;
769 /* XXX check if it's ok or we need to set an absolute url */
770 httpd_MsgAdd( answer, "Location", "%s", rdir->psz_dst );
772 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
777 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst,
778 const char *psz_url_src )
780 httpd_redirect_t *rdir = malloc( sizeof( httpd_redirect_t ) );
782 if( !( rdir->url = httpd_UrlNewUnique( host, psz_url_src, NULL, NULL, NULL ) ) )
787 rdir->psz_dst = strdup( psz_url_dst );
789 /* Redirect apply for all HTTP request and RTSP DESCRIBE resquest */
790 httpd_UrlCatch( rdir->url, HTTPD_MSG_HEAD, httpd_RedirectCallBack,
791 (httpd_callback_sys_t*)rdir );
792 httpd_UrlCatch( rdir->url, HTTPD_MSG_GET, httpd_RedirectCallBack,
793 (httpd_callback_sys_t*)rdir );
794 httpd_UrlCatch( rdir->url, HTTPD_MSG_POST, httpd_RedirectCallBack,
795 (httpd_callback_sys_t*)rdir );
796 httpd_UrlCatch( rdir->url, HTTPD_MSG_DESCRIBE, httpd_RedirectCallBack,
797 (httpd_callback_sys_t*)rdir );
801 void httpd_RedirectDelete( httpd_redirect_t *rdir )
803 httpd_UrlDelete( rdir->url );
804 free( rdir->psz_dst );
808 /*****************************************************************************
809 * High Level Funtions: httpd_stream_t
810 *****************************************************************************/
811 struct httpd_stream_t
818 /* Header to send as first packet */
822 /* circular buffer */
823 int i_buffer_size; /* buffer size, can't be reallocated smaller */
824 uint8_t *p_buffer; /* buffer */
825 int64_t i_buffer_pos; /* absolute position from begining */
826 int64_t i_buffer_last_pos; /* a new connection will start with that */
829 static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
830 httpd_client_t *cl, httpd_message_t *answer,
831 httpd_message_t *query )
833 httpd_stream_t *stream = (httpd_stream_t*)p_sys;
835 if( answer == NULL || query == NULL || cl == NULL )
839 if( answer->i_body_offset > 0 )
845 fprintf( stderr, "httpd_StreamCallBack i_body_offset=%lld\n",
846 answer->i_body_offset );
849 if( answer->i_body_offset >= stream->i_buffer_pos )
851 /* fprintf( stderr, "httpd_StreamCallBack: no data\n" ); */
852 return VLC_EGENERIC; /* wait, no data available */
854 if( answer->i_body_offset + stream->i_buffer_size <
855 stream->i_buffer_pos )
857 /* this client isn't fast enough */
858 fprintf( stderr, "fixing i_body_offset (old=%lld new=%lld)\n",
859 answer->i_body_offset, stream->i_buffer_last_pos );
860 answer->i_body_offset = stream->i_buffer_last_pos;
863 i_pos = answer->i_body_offset % stream->i_buffer_size;
864 i_write = stream->i_buffer_pos - answer->i_body_offset;
865 if( i_write > HTTPD_CL_BUFSIZE )
867 i_write = HTTPD_CL_BUFSIZE;
869 else if( i_write <= 0 )
871 return VLC_EGENERIC; /* wait, no data available */
874 /* Don't go past the end of the circular buffer */
875 i_write = __MIN( i_write, stream->i_buffer_size - i_pos );
877 /* using HTTPD_MSG_ANSWER -> data available */
878 answer->i_proto = HTTPD_PROTO_HTTP;
879 answer->i_version= 0;
880 answer->i_type = HTTPD_MSG_ANSWER;
882 answer->i_body = i_write;
883 answer->p_body = malloc( i_write );
884 memcpy( answer->p_body, &stream->p_buffer[i_pos], i_write );
886 answer->i_body_offset += i_write;
892 answer->i_proto = HTTPD_PROTO_HTTP;
893 answer->i_version= 0;
894 answer->i_type = HTTPD_MSG_ANSWER;
896 answer->i_status = 200;
897 answer->psz_status = strdup( "OK" );
899 if( query->i_type != HTTPD_MSG_HEAD )
901 httpd_ClientModeStream( cl );
902 vlc_mutex_lock( &stream->lock );
903 /* Send the header */
904 if( stream->i_header > 0 )
906 answer->i_body = stream->i_header;
907 answer->p_body = malloc( stream->i_header );
908 memcpy( answer->p_body, stream->p_header, stream->i_header );
910 answer->i_body_offset = stream->i_buffer_last_pos;
911 vlc_mutex_unlock( &stream->lock );
915 httpd_MsgAdd( answer, "Content-Length", "%d", 0 );
916 answer->i_body_offset = 0;
919 if( !strcmp( stream->psz_mime, "video/x-ms-asf-stream" ) )
921 vlc_bool_t b_xplaystream = VLC_FALSE;
924 httpd_MsgAdd( answer, "Content-type", "%s",
925 "application/octet-stream" );
926 httpd_MsgAdd( answer, "Server", "Cougar 4.1.0.3921" );
927 httpd_MsgAdd( answer, "Pragma", "no-cache" );
928 httpd_MsgAdd( answer, "Pragma", "client-id=%d", rand()&0x7fff );
929 httpd_MsgAdd( answer, "Pragma", "features=\"broadcast\"" );
931 /* Check if there is a xPlayStrm=1 */
932 for( i = 0; i < query->i_name; i++ )
934 if( !strcasecmp( query->name[i], "Pragma" ) &&
935 strstr( query->value[i], "xPlayStrm=1" ) )
937 b_xplaystream = VLC_TRUE;
943 answer->i_body_offset = 0;
948 httpd_MsgAdd( answer, "Content-type", "%s", stream->psz_mime );
950 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
955 httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
956 const char *psz_url, const char *psz_mime,
957 const char *psz_user, const char *psz_password,
958 const vlc_acl_t *p_acl )
960 httpd_stream_t *stream = malloc( sizeof( httpd_stream_t ) );
962 if( ( stream->url = httpd_UrlNewUnique( host, psz_url, psz_user,
963 psz_password, p_acl )
969 vlc_mutex_init( host, &stream->lock );
970 if( psz_mime && *psz_mime )
972 stream->psz_mime = strdup( psz_mime );
976 stream->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
978 stream->i_header = 0;
979 stream->p_header = NULL;
980 stream->i_buffer_size = 5000000; /* 5 Mo per stream */
981 stream->p_buffer = malloc( stream->i_buffer_size );
982 /* We set to 1 to make life simpler
983 * (this way i_body_offset can never be 0) */
984 stream->i_buffer_pos = 1;
985 stream->i_buffer_last_pos = 1;
987 httpd_UrlCatch( stream->url, HTTPD_MSG_HEAD, httpd_StreamCallBack,
988 (httpd_callback_sys_t*)stream );
989 httpd_UrlCatch( stream->url, HTTPD_MSG_GET, httpd_StreamCallBack,
990 (httpd_callback_sys_t*)stream );
991 httpd_UrlCatch( stream->url, HTTPD_MSG_POST, httpd_StreamCallBack,
992 (httpd_callback_sys_t*)stream );
997 int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
999 vlc_mutex_lock( &stream->lock );
1000 if( stream->p_header )
1002 free( stream->p_header );
1003 stream->p_header = NULL;
1005 stream->i_header = i_data;
1008 stream->p_header = malloc( i_data );
1009 memcpy( stream->p_header, p_data, i_data );
1011 vlc_mutex_unlock( &stream->lock );
1016 int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
1021 if( i_data < 0 || p_data == NULL )
1025 vlc_mutex_lock( &stream->lock );
1027 /* save this pointer (to be used by new connection) */
1028 stream->i_buffer_last_pos = stream->i_buffer_pos;
1030 i_pos = stream->i_buffer_pos % stream->i_buffer_size;
1036 i_copy = __MIN( i_count, stream->i_buffer_size - i_pos );
1038 /* Ok, we can't go past the end of our buffer */
1039 memcpy( &stream->p_buffer[i_pos], p_data, i_copy );
1041 i_pos = ( i_pos + i_copy ) % stream->i_buffer_size;
1046 stream->i_buffer_pos += i_data;
1048 vlc_mutex_unlock( &stream->lock );
1052 void httpd_StreamDelete( httpd_stream_t *stream )
1054 httpd_UrlDelete( stream->url );
1055 vlc_mutex_destroy( &stream->lock );
1056 if( stream->psz_mime ) free( stream->psz_mime );
1057 if( stream->p_header ) free( stream->p_header );
1058 if( stream->p_buffer ) free( stream->p_buffer );
1063 /*****************************************************************************
1065 *****************************************************************************/
1066 static void httpd_HostThread( httpd_host_t * );
1068 /* create a new host */
1069 httpd_host_t *httpd_HostNew( vlc_object_t *p_this, const char *psz_host,
1072 return httpd_TLSHostNew( p_this, psz_host, i_port, NULL, NULL, NULL, NULL
1076 httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
1078 const char *psz_cert, const char *psz_key,
1079 const char *psz_ca, const char *psz_crl )
1083 tls_server_t *p_tls;
1085 vlc_value_t lockval;
1088 if( psz_hostname == NULL )
1091 psz_host = strdup( psz_hostname );
1092 if( psz_host == NULL )
1094 msg_Err( p_this, "memory error" );
1098 /* to be sure to avoid multiple creation */
1099 var_Create( p_this->p_libvlc, "httpd_mutex", VLC_VAR_MUTEX );
1100 var_Get( p_this->p_libvlc, "httpd_mutex", &lockval );
1101 vlc_mutex_lock( lockval.p_address );
1103 if( !(httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE )) )
1105 msg_Info( p_this, "creating httpd" );
1106 if( ( httpd = vlc_object_create( p_this, VLC_OBJECT_HTTPD ) ) == NULL )
1108 vlc_mutex_unlock( lockval.p_address );
1116 vlc_object_yield( httpd );
1117 vlc_object_attach( httpd, p_this->p_vlc );
1120 /* verify if it already exist */
1121 for( i = httpd->i_host - 1; i >= 0; i-- )
1123 host = httpd->host[i];
1125 /* cannot mix TLS and non-TLS hosts */
1126 if( ( ( httpd->host[i]->p_tls != NULL ) != ( psz_cert != NULL ) )
1127 || ( host->i_port != i_port )
1128 || strcmp( host->psz_hostname, psz_hostname ) )
1134 vlc_mutex_unlock( lockval.p_address );
1140 /* determine TLS configuration */
1141 if ( psz_cert != NULL )
1143 p_tls = tls_ServerCreate( p_this, psz_cert, psz_key );
1144 if ( p_tls == NULL )
1146 msg_Err( p_this, "TLS initialization error" );
1150 if ( ( psz_ca != NULL) && tls_ServerAddCA( p_tls, psz_ca ) )
1152 msg_Err( p_this, "TLS CA error" );
1156 if ( ( psz_crl != NULL) && tls_ServerAddCRL( p_tls, psz_crl ) )
1158 msg_Err( p_this, "TLS CRL error" );
1165 /* create the new host */
1166 host = vlc_object_create( p_this, sizeof( httpd_host_t ) );
1167 host->httpd = httpd;
1168 vlc_mutex_init( httpd, &host->lock );
1171 host->fd = net_ListenTCP( p_this, psz_host, i_port );
1172 if( host->fd == NULL )
1174 msg_Err( p_this, "cannot create socket(s) for HTTP host" );
1178 host->i_port = i_port;
1179 host->psz_hostname = psz_host;
1184 host->client = NULL;
1186 host->p_tls = p_tls;
1188 /* create the thread */
1189 if( vlc_thread_create( host, "httpd host thread", httpd_HostThread,
1190 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
1192 msg_Err( p_this, "cannot spawn http host thread" );
1196 /* now add it to httpd */
1197 TAB_APPEND( httpd->i_host, httpd->host, host );
1198 vlc_mutex_unlock( lockval.p_address );
1204 if( httpd->i_host <= 0 )
1206 vlc_object_release( httpd );
1207 vlc_object_detach( httpd );
1208 vlc_object_destroy( httpd );
1210 vlc_mutex_unlock( lockval.p_address );
1214 net_ListenClose( host->fd );
1215 vlc_mutex_destroy( &host->lock );
1216 vlc_object_destroy( host );
1220 tls_ServerDelete( p_tls );
1226 void httpd_HostDelete( httpd_host_t *host )
1228 httpd_t *httpd = host->httpd;
1229 vlc_value_t lockval;
1232 var_Get( httpd->p_libvlc, "httpd_mutex", &lockval );
1233 vlc_mutex_lock( lockval.p_address );
1236 if( host->i_ref > 0 )
1239 vlc_mutex_unlock( lockval.p_address );
1240 msg_Dbg( host, "httpd_HostDelete: host still used" );
1243 TAB_REMOVE( httpd->i_host, httpd->host, host );
1246 vlc_thread_join( host );
1248 msg_Dbg( host, "HTTP host removed" );
1250 for( i = 0; i < host->i_url; i++ )
1252 msg_Err( host, "url still registered:%s", host->url[i]->psz_url );
1254 for( i = 0; i < host->i_client; i++ )
1256 httpd_client_t *cl = host->client[i];
1257 msg_Warn( host, "client still connected" );
1258 httpd_ClientClean( cl );
1259 TAB_REMOVE( host->i_client, host->client, cl );
1265 if( host->p_tls != NULL)
1266 tls_ServerDelete( host->p_tls );
1268 net_ListenClose( host->fd );
1269 free( host->psz_hostname );
1271 vlc_mutex_destroy( &host->lock );
1272 vlc_object_destroy( host );
1274 vlc_object_release( httpd );
1275 if( httpd->i_host <= 0 )
1277 msg_Dbg( httpd, "no host left, stopping httpd" );
1278 vlc_object_detach( httpd );
1279 vlc_object_destroy( httpd );
1281 vlc_mutex_unlock( lockval.p_address );
1284 /* register a new url */
1285 static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, const char *psz_url,
1286 const char *psz_user, const char *psz_password,
1287 const vlc_acl_t *p_acl, vlc_bool_t b_check )
1292 vlc_mutex_lock( &host->lock );
1295 for( i = 0; i < host->i_url; i++ )
1297 if( !strcmp( psz_url, host->url[i]->psz_url ) )
1299 msg_Warn( host->httpd,
1300 "cannot add '%s' (url already defined)", psz_url );
1301 vlc_mutex_unlock( &host->lock );
1307 url = malloc( sizeof( httpd_url_t ) );
1310 vlc_mutex_init( host->httpd, &url->lock );
1311 url->psz_url = strdup( psz_url );
1312 url->psz_user = strdup( psz_user ? psz_user : "" );
1313 url->psz_password = strdup( psz_password ? psz_password : "" );
1314 url->p_acl = ACL_Duplicate( host, p_acl );
1315 for( i = 0; i < HTTPD_MSG_MAX; i++ )
1317 url->catch[i].cb = NULL;
1318 url->catch[i].p_sys = NULL;
1321 TAB_APPEND( host->i_url, host->url, url );
1322 vlc_mutex_unlock( &host->lock );
1327 httpd_url_t *httpd_UrlNew( httpd_host_t *host, const char *psz_url,
1328 const char *psz_user, const char *psz_password,
1329 const vlc_acl_t *p_acl )
1331 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1332 psz_password, p_acl, VLC_FALSE );
1335 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, const char *psz_url,
1336 const char *psz_user, const char *psz_password,
1337 const vlc_acl_t *p_acl )
1339 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1340 psz_password, p_acl, VLC_TRUE );
1343 /* register callback on a url */
1344 int httpd_UrlCatch( httpd_url_t *url, int i_msg, httpd_callback_t cb,
1345 httpd_callback_sys_t *p_sys )
1347 vlc_mutex_lock( &url->lock );
1348 url->catch[i_msg].cb = cb;
1349 url->catch[i_msg].p_sys= p_sys;
1350 vlc_mutex_unlock( &url->lock );
1357 void httpd_UrlDelete( httpd_url_t *url )
1359 httpd_host_t *host = url->host;
1362 vlc_mutex_lock( &host->lock );
1363 TAB_REMOVE( host->i_url, host->url, url );
1365 vlc_mutex_destroy( &url->lock );
1366 free( url->psz_url );
1367 free( url->psz_user );
1368 free( url->psz_password );
1369 ACL_Destroy( url->p_acl );
1371 for( i = 0; i < host->i_client; i++ )
1373 httpd_client_t *client = host->client[i];
1375 if( client->url == url )
1377 /* TODO complete it */
1378 msg_Warn( host, "force closing connections" );
1379 httpd_ClientClean( client );
1380 TAB_REMOVE( host->i_client, host->client, client );
1386 vlc_mutex_unlock( &host->lock );
1389 void httpd_MsgInit( httpd_message_t *msg )
1392 msg->i_type = HTTPD_MSG_NONE;
1393 msg->i_proto = HTTPD_PROTO_NONE;
1394 msg->i_version = -1;
1397 msg->psz_status = NULL;
1399 msg->psz_url = NULL;
1400 msg->psz_args = NULL;
1402 msg->i_channel = -1;
1409 msg->i_body_offset = 0;
1414 void httpd_MsgClean( httpd_message_t *msg )
1418 if( msg->psz_status )
1420 free( msg->psz_status );
1424 free( msg->psz_url );
1428 free( msg->psz_args );
1430 for( i = 0; i < msg->i_name; i++ )
1432 free( msg->name[i] );
1433 free( msg->value[i] );
1445 free( msg->p_body );
1447 httpd_MsgInit( msg );
1450 char *httpd_MsgGet( httpd_message_t *msg, char *name )
1454 for( i = 0; i < msg->i_name; i++ )
1456 if( !strcasecmp( msg->name[i], name ))
1458 return msg->value[i];
1463 void httpd_MsgAdd( httpd_message_t *msg, char *name, char *psz_value, ... )
1468 va_start( args, psz_value );
1469 #if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined(SYS_BEOS)
1470 vasprintf( &value, psz_value, args );
1473 int i_size = strlen( psz_value ) + 4096; /* FIXME stupid system */
1474 value = calloc( i_size, sizeof( char ) );
1475 vsnprintf( value, i_size, psz_value, args );
1476 value[i_size - 1] = 0;
1481 name = strdup( name );
1483 TAB_APPEND( msg->i_name, msg->name, name );
1484 TAB_APPEND( msg->i_value, msg->value, value );
1487 static void httpd_ClientInit( httpd_client_t *cl )
1489 cl->i_state = HTTPD_CLIENT_RECEIVING;
1490 cl->i_activity_date = mdate();
1491 cl->i_activity_timeout = I64C(10000000);
1492 cl->i_buffer_size = HTTPD_CL_BUFSIZE;
1494 cl->p_buffer = malloc( cl->i_buffer_size );
1495 cl->i_mode = HTTPD_CLIENT_FILE;
1496 cl->b_read_waiting = VLC_FALSE;
1498 httpd_MsgInit( &cl->query );
1499 httpd_MsgInit( &cl->answer );
1502 void httpd_ClientModeStream( httpd_client_t *cl )
1504 cl->i_mode = HTTPD_CLIENT_STREAM;
1507 void httpd_ClientModeBidir( httpd_client_t *cl )
1509 cl->i_mode = HTTPD_CLIENT_BIDIR;
1512 char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip )
1514 return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1517 char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip )
1519 return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1522 static void httpd_ClientClean( httpd_client_t *cl )
1526 if( cl->p_tls != NULL )
1527 tls_ServerSessionClose( cl->p_tls );
1528 net_Close( cl->fd );
1532 httpd_MsgClean( &cl->answer );
1533 httpd_MsgClean( &cl->query );
1537 free( cl->p_buffer );
1538 cl->p_buffer = NULL;
1542 static httpd_client_t *httpd_ClientNew( int fd, struct sockaddr_storage *sock,
1544 tls_session_t *p_tls )
1546 httpd_client_t *cl = malloc( sizeof( httpd_client_t ) );
1549 memcpy( &cl->sock, sock, sizeof( cl->sock ) );
1550 cl->i_sock_size = i_sock_size;
1554 httpd_ClientInit( cl );
1560 static int httpd_NetRecv( httpd_client_t *cl, uint8_t *p, int i_len )
1562 tls_session_t *p_tls;
1566 return tls_Recv( p_tls, p, i_len );
1568 return recv( cl->fd, p, i_len, 0 );
1572 static int httpd_NetSend( httpd_client_t *cl, const uint8_t *p, int i_len )
1574 tls_session_t *p_tls;
1578 return tls_Send( p_tls, p, i_len );
1580 return send( cl->fd, p, i_len, 0 );
1584 static void httpd_ClientRecv( httpd_client_t *cl )
1588 if( cl->query.i_proto == HTTPD_PROTO_NONE )
1590 /* enough to see if it's rtp over rtsp or RTSP/HTTP */
1591 i_len = httpd_NetRecv( cl, &cl->p_buffer[cl->i_buffer],
1595 cl->i_buffer += i_len;
1598 if( cl->i_buffer >= 4 )
1600 /*fprintf( stderr, "peek=%4.4s\n", cl->p_buffer );*/
1602 if( cl->p_buffer[0] == '$' )
1604 /* RTSP (rtp over rtsp) */
1605 cl->query.i_proto = HTTPD_PROTO_RTSP;
1606 cl->query.i_type = HTTPD_MSG_CHANNEL;
1607 cl->query.i_channel = cl->p_buffer[1];
1608 cl->query.i_body = (cl->p_buffer[2] << 8)|cl->p_buffer[3];
1609 cl->query.p_body = malloc( cl->query.i_body );
1613 else if( !memcmp( cl->p_buffer, "HTTP", 4 ) )
1615 cl->query.i_proto = HTTPD_PROTO_HTTP;
1616 cl->query.i_type = HTTPD_MSG_ANSWER;
1618 else if( !memcmp( cl->p_buffer, "RTSP", 4 ) )
1620 cl->query.i_proto = HTTPD_PROTO_RTSP;
1621 cl->query.i_type = HTTPD_MSG_ANSWER;
1623 else if( !memcmp( cl->p_buffer, "GET", 3 ) ||
1624 !memcmp( cl->p_buffer, "HEAD", 4 ) ||
1625 !memcmp( cl->p_buffer, "POST", 4 ) )
1627 cl->query.i_proto = HTTPD_PROTO_HTTP;
1628 cl->query.i_type = HTTPD_MSG_NONE;
1632 cl->query.i_proto = HTTPD_PROTO_RTSP;
1633 cl->query.i_type = HTTPD_MSG_NONE;
1637 else if( cl->query.i_body > 0 )
1639 /* we are reading the body of a request or a channel */
1640 i_len = httpd_NetRecv( cl, &cl->query.p_body[cl->i_buffer],
1641 cl->query.i_body - cl->i_buffer );
1644 cl->i_buffer += i_len;
1646 if( cl->i_buffer >= cl->query.i_body )
1648 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1653 /* we are reading a header -> char by char */
1656 i_len = httpd_NetRecv (cl, &cl->p_buffer[cl->i_buffer], 1 );
1663 if( cl->i_buffer + 1 >= cl->i_buffer_size )
1665 cl->i_buffer_size += 1024;
1666 cl->p_buffer = realloc( cl->p_buffer, cl->i_buffer_size );
1668 if( ( cl->i_buffer >= 2 && !memcmp( &cl->p_buffer[cl->i_buffer-2], "\n\n", 2 ) )||
1669 ( cl->i_buffer >= 4 && !memcmp( &cl->p_buffer[cl->i_buffer-4], "\r\n\r\n", 4 ) ) )
1673 /* we have finished the header so parse it and set i_body */
1674 cl->p_buffer[cl->i_buffer] = '\0';
1676 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1679 * assume strlen( "HTTP/1.x" ) = 8
1681 cl->query.i_status =
1682 strtol( (char *)&cl->p_buffer[8],
1688 cl->query.psz_status = strdup( p );
1700 { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP },
1701 { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP },
1702 { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP },
1704 { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP },
1705 { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP },
1706 { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP },
1707 { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP },
1708 { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP },
1709 { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP },
1711 { NULL, HTTPD_MSG_NONE, HTTPD_PROTO_NONE }
1716 cl->query.i_type = HTTPD_MSG_NONE;
1718 /*fprintf( stderr, "received new request=%s\n", cl->p_buffer);*/
1720 for( i = 0; msg_type[i].name != NULL; i++ )
1722 if( !strncmp( (char *)cl->p_buffer, msg_type[i].name,
1723 strlen( msg_type[i].name ) ) )
1725 p = (char *)&cl->p_buffer[strlen((char *)msg_type[i].name) + 1 ];
1726 cl->query.i_type = msg_type[i].i_type;
1727 if( cl->query.i_proto != msg_type[i].i_proto )
1730 cl->query.i_proto = HTTPD_PROTO_NONE;
1731 cl->query.i_type = HTTPD_MSG_NONE;
1738 if( strstr( (char *)cl->p_buffer, "HTTP/1." ) )
1740 cl->query.i_proto = HTTPD_PROTO_HTTP;
1742 else if( strstr( (char *)cl->p_buffer, "RTSP/1." ) )
1744 cl->query.i_proto = HTTPD_PROTO_RTSP;
1756 p2 = strchr( p, ' ' );
1761 if( !strncasecmp( p, "rtsp:", 5 ) )
1763 /* for rtsp url, you have rtsp://localhost:port/path */
1765 while( *p == '/' ) p++;
1766 while( *p && *p != '/' ) p++;
1768 cl->query.psz_url = strdup( p );
1769 if( ( p3 = strchr( cl->query.psz_url, '?' ) ) )
1772 cl->query.psz_args = (uint8_t *)strdup( p3 );
1780 if( !strncasecmp( p2, "HTTP/1.", 7 ) )
1782 cl->query.i_proto = HTTPD_PROTO_HTTP;
1783 cl->query.i_version = atoi( p2+7 );
1785 else if( !strncasecmp( p2, "RTSP/1.", 7 ) )
1787 cl->query.i_proto = HTTPD_PROTO_RTSP;
1788 cl->query.i_version = atoi( p2+7 );
1796 p = strchr( p, '\n' );
1800 while( *p == '\n' || *p == '\r' )
1804 while( p && *p != '\0' )
1807 char *eol = p = strchr( p, '\n' );
1810 while( eol && eol >= line && ( *eol == '\n' || *eol == '\r' ) )
1815 if( ( colon = strchr( line, ':' ) ) )
1821 while( *colon == ' ' )
1825 name = strdup( line );
1826 value = strdup( colon );
1828 TAB_APPEND( cl->query.i_name, cl->query.name, name );
1829 TAB_APPEND( cl->query.i_value,cl->query.value,value);
1831 if( !strcasecmp( name, "Content-Length" ) )
1833 cl->query.i_body = atol( value );
1840 while( *p == '\n' || *p == '\r' )
1847 if( cl->query.i_body > 0 )
1849 /* TODO Mhh, handle the case client will only send a request and close the connection
1850 * to mark and of body (probably only RTSP) */
1851 cl->query.p_body = malloc( cl->query.i_body );
1856 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1862 /* check if the client is to be set to dead */
1863 #if defined( WIN32 ) || defined( UNDER_CE )
1864 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1866 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1869 if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE )
1871 /* connection closed -> end of data */
1872 if( cl->query.i_body > 0 )
1874 cl->query.i_body = cl->i_buffer;
1876 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1880 cl->i_state = HTTPD_CLIENT_DEAD;
1883 cl->i_activity_date = mdate();
1885 /* XXX: for QT I have to disable timeout. Try to find why */
1886 if( cl->query.i_proto == HTTPD_PROTO_RTSP )
1887 cl->i_activity_timeout = 0;
1889 /* Debugging only */
1890 /*if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
1894 fprintf( stderr, "received new request\n" );
1895 fprintf( stderr, " - proto=%s\n",
1896 cl->query.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP" );
1897 fprintf( stderr, " - version=%d\n", cl->query.i_version );
1898 fprintf( stderr, " - msg=%d\n", cl->query.i_type );
1899 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1901 fprintf( stderr, " - answer=%d '%s'\n", cl->query.i_status,
1902 cl->query.psz_status );
1904 else if( cl->query.i_type != HTTPD_MSG_NONE )
1906 fprintf( stderr, " - url=%s\n", cl->query.psz_url );
1908 for( i = 0; i < cl->query.i_name; i++ )
1910 fprintf( stderr, " - option name='%s' value='%s'\n",
1911 cl->query.name[i], cl->query.value[i] );
1917 static void httpd_ClientSend( httpd_client_t *cl )
1922 if( cl->i_buffer < 0 )
1924 /* We need to create the header */
1928 i_size = strlen( "HTTP/1.") + 10 + 10 +
1929 strlen( cl->answer.psz_status ? cl->answer.psz_status : "" ) + 5;
1930 for( i = 0; i < cl->answer.i_name; i++ )
1932 i_size += strlen( cl->answer.name[i] ) + 2 +
1933 strlen( cl->answer.value[i] ) + 2;
1936 if( cl->i_buffer_size < i_size )
1938 cl->i_buffer_size = i_size;
1939 free( cl->p_buffer );
1940 cl->p_buffer = malloc( i_size );
1942 p = (char *)cl->p_buffer;
1944 p += sprintf( p, "%s/1.%d %d %s\r\n",
1945 cl->answer.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP",
1946 cl->answer.i_version,
1947 cl->answer.i_status, cl->answer.psz_status );
1948 for( i = 0; i < cl->answer.i_name; i++ )
1950 p += sprintf( p, "%s: %s\r\n", cl->answer.name[i],
1951 cl->answer.value[i] );
1953 p += sprintf( p, "\r\n" );
1956 cl->i_buffer_size = (uint8_t*)p - cl->p_buffer;
1958 /*fprintf( stderr, "sending answer\n" );
1959 fprintf( stderr, "%s", cl->p_buffer );*/
1962 i_len = httpd_NetSend( cl, &cl->p_buffer[cl->i_buffer],
1963 cl->i_buffer_size - cl->i_buffer );
1966 cl->i_activity_date = mdate();
1967 cl->i_buffer += i_len;
1969 if( cl->i_buffer >= cl->i_buffer_size )
1971 if( cl->answer.i_body == 0 && cl->answer.i_body_offset > 0 &&
1972 !cl->b_read_waiting )
1974 /* catch more body data */
1975 int i_msg = cl->query.i_type;
1976 int64_t i_offset = cl->answer.i_body_offset;
1978 httpd_MsgClean( &cl->answer );
1979 cl->answer.i_body_offset = i_offset;
1981 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
1982 &cl->answer, &cl->query );
1985 if( cl->answer.i_body > 0 )
1987 /* send the body data */
1988 free( cl->p_buffer );
1989 cl->p_buffer = cl->answer.p_body;
1990 cl->i_buffer_size = cl->answer.i_body;
1993 cl->answer.i_body = 0;
1994 cl->answer.p_body = NULL;
1999 cl->i_state = HTTPD_CLIENT_SEND_DONE;
2005 #if defined( WIN32 ) || defined( UNDER_CE )
2006 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
2008 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
2012 cl->i_state = HTTPD_CLIENT_DEAD;
2017 static void httpd_ClientTlsHsIn( httpd_client_t *cl )
2019 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2022 cl->i_state = HTTPD_CLIENT_RECEIVING;
2026 cl->i_state = HTTPD_CLIENT_DEAD;
2031 cl->i_state = HTTPD_CLIENT_TLS_HS_OUT;
2035 static void httpd_ClientTlsHsOut( httpd_client_t *cl )
2037 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2040 cl->i_state = HTTPD_CLIENT_RECEIVING;
2044 cl->i_state = HTTPD_CLIENT_DEAD;
2049 cl->i_state = HTTPD_CLIENT_TLS_HS_IN;
2054 static void httpd_HostThread( httpd_host_t *host )
2056 tls_session_t *p_tls = NULL;
2058 stats_Create( host, "client_connections", STATS_CLIENT_CONNECTIONS,
2059 VLC_VAR_INTEGER, STATS_COUNTER );
2060 stats_Create( host, "active_connections", STATS_ACTIVE_CONNECTIONS,
2061 VLC_VAR_INTEGER, STATS_COUNTER );
2063 while( !host->b_die )
2065 struct timeval timeout;
2068 /* FIXME: (too) many int variables */
2070 int i_handle_max = 0;
2073 int b_low_delay = 0;
2075 if( host->i_url <= 0 )
2082 /* built a set of handle to select */
2083 FD_ZERO( &fds_read );
2084 FD_ZERO( &fds_write );
2088 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
2090 FD_SET( fd, &fds_read );
2091 if( fd > i_handle_max )
2095 /* prepare a new TLS session */
2096 if( ( p_tls == NULL ) && ( host->p_tls != NULL ) )
2097 p_tls = tls_ServerSessionPrepare( host->p_tls );
2099 /* add all socket that should be read/write and close dead connection */
2100 vlc_mutex_lock( &host->lock );
2101 for( i_client = 0; i_client < host->i_client; i_client++ )
2103 httpd_client_t *cl = host->client[i_client];
2105 if( cl->i_ref < 0 || ( cl->i_ref == 0 &&
2106 ( cl->i_state == HTTPD_CLIENT_DEAD ||
2107 ( cl->i_activity_timeout > 0 &&
2108 cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
2110 httpd_ClientClean( cl );
2111 stats_UpdateInteger( host, STATS_ACTIVE_CONNECTIONS, -1, NULL );
2112 TAB_REMOVE( host->i_client, host->client, cl );
2117 else if( ( cl->i_state == HTTPD_CLIENT_RECEIVING )
2118 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) )
2120 FD_SET( cl->fd, &fds_read );
2121 i_handle_max = __MAX( i_handle_max, cl->fd );
2123 else if( ( cl->i_state == HTTPD_CLIENT_SENDING )
2124 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) )
2126 FD_SET( cl->fd, &fds_write );
2127 i_handle_max = __MAX( i_handle_max, cl->fd );
2129 else if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
2131 httpd_message_t *answer = &cl->answer;
2132 httpd_message_t *query = &cl->query;
2133 int i_msg = query->i_type;
2135 httpd_MsgInit( answer );
2137 /* Handle what we received */
2138 if( cl->i_mode != HTTPD_CLIENT_BIDIR &&
2139 (i_msg == HTTPD_MSG_ANSWER || i_msg == HTTPD_MSG_CHANNEL) )
2141 /* we can only receive request from client when not
2144 cl->i_state = HTTPD_CLIENT_DEAD;
2146 else if( i_msg == HTTPD_MSG_ANSWER )
2148 /* We are in BIDIR mode, trigger the callback and then
2149 * check for new data */
2150 if( cl->url && cl->url->catch[i_msg].cb )
2152 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2155 cl->i_state = HTTPD_CLIENT_WAITING;
2157 else if( i_msg == HTTPD_MSG_CHANNEL )
2159 /* We are in BIDIR mode, trigger the callback and then
2160 * check for new data */
2161 if( cl->url && cl->url->catch[i_msg].cb )
2163 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2166 cl->i_state = HTTPD_CLIENT_WAITING;
2168 else if( i_msg == HTTPD_MSG_OPTIONS )
2173 answer->i_proto = query->i_proto ;
2174 answer->i_type = HTTPD_MSG_ANSWER;
2175 answer->i_version= 0;
2176 answer->i_status = 200;
2177 answer->psz_status = strdup( "Ok" );
2180 answer->p_body = NULL;
2182 i_cseq = atoi( httpd_MsgGet( query, "Cseq" ) );
2183 httpd_MsgAdd( answer, "Cseq", "%d", i_cseq );
2184 httpd_MsgAdd( answer, "Server", "VLC Server" );
2185 httpd_MsgAdd( answer, "Public", "DESCRIBE, SETUP, "
2186 "TEARDOWN, PLAY, PAUSE" );
2187 httpd_MsgAdd( answer, "Content-Length", "%d",
2190 cl->i_buffer = -1; /* Force the creation of the answer in
2191 * httpd_ClientSend */
2192 cl->i_state = HTTPD_CLIENT_SENDING;
2194 else if( i_msg == HTTPD_MSG_NONE )
2196 if( query->i_proto == HTTPD_PROTO_NONE )
2199 cl->i_state = HTTPD_CLIENT_DEAD;
2206 answer->i_proto = query->i_proto ;
2207 answer->i_type = HTTPD_MSG_ANSWER;
2208 answer->i_version= 0;
2209 answer->i_status = 501;
2210 answer->psz_status = strdup( "Unimplemented" );
2212 p = answer->p_body = malloc( 1000 );
2214 p += sprintf( (char *)p,
2215 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2216 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2217 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2220 "<title>Error 501</title>\n"
2223 "<h1>501 Unimplemented</h1>\n"
2225 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2229 answer->i_body = p - answer->p_body;
2230 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2232 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2233 cl->i_state = HTTPD_CLIENT_SENDING;
2238 vlc_bool_t b_auth_failed = VLC_FALSE;
2239 vlc_bool_t b_hosts_failed = VLC_FALSE;
2242 /* Search the url and trigger callbacks */
2243 for( i = 0; i < host->i_url; i++ )
2245 httpd_url_t *url = host->url[i];
2247 if( !strcmp( url->psz_url, query->psz_url ) )
2249 if( url->catch[i_msg].cb )
2251 if( answer && ( url->p_acl != NULL ) )
2253 char ip[NI_MAXNUMERICHOST];
2255 if( httpd_ClientIP( cl, ip ) != NULL )
2257 if( ACL_Check( url->p_acl, ip ) )
2259 b_hosts_failed = VLC_TRUE;
2264 b_hosts_failed = VLC_TRUE;
2267 if( answer && ( *url->psz_user || *url->psz_password ) )
2269 /* create the headers */
2270 char *b64 = httpd_MsgGet( query, "Authorization" ); /* BASIC id */
2274 asprintf( &id, "%s:%s", url->psz_user, url->psz_password );
2275 auth = malloc( strlen(b64) + 1 );
2277 if( !strncasecmp( b64, "BASIC", 5 ) )
2280 while( *b64 == ' ' )
2284 b64_decode( auth, b64 );
2290 if( strcmp( id, auth ) )
2292 httpd_MsgAdd( answer, "WWW-Authenticate", "Basic realm=\"%s\"", url->psz_user );
2293 /* We fail for all url */
2294 b_auth_failed = VLC_TRUE;
2304 if( !url->catch[i_msg].cb( url->catch[i_msg].p_sys, cl, answer, query ) )
2306 if( answer->i_proto == HTTPD_PROTO_NONE )
2308 /* Raw answer from a CGI */
2309 cl->i_buffer = cl->i_buffer_size;
2314 /* only one url can answer */
2316 if( cl->url == NULL )
2328 answer->i_proto = query->i_proto;
2329 answer->i_type = HTTPD_MSG_ANSWER;
2330 answer->i_version= 0;
2331 p = answer->p_body = malloc( 1000 + strlen(query->psz_url) );
2333 if( b_hosts_failed )
2335 answer->i_status = 403;
2336 answer->psz_status = strdup( "Forbidden" );
2338 /* FIXME: lots of code duplication */
2339 p += sprintf( (char *)p,
2340 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2341 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2342 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2345 "<title>Error 403</title>\n"
2348 "<h1>403 Forbidden (%s)</h1>\n"
2350 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2352 "</html>\n", query->psz_url );
2354 else if( b_auth_failed )
2356 answer->i_status = 401;
2357 answer->psz_status = strdup( "Authorization Required" );
2359 p += sprintf( (char *)p,
2360 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2361 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2362 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2365 "<title>Error 401</title>\n"
2368 "<h1>401 Authorization Required (%s)</h1>\n"
2370 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2372 "</html>\n", query->psz_url );
2376 /* no url registered */
2377 answer->i_status = 404;
2378 answer->psz_status = strdup( "Not found" );
2380 p += sprintf( (char *)p,
2381 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2382 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2383 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2386 "<title>Error 404</title>\n"
2389 "<h1>404 Resource not found(%s)</h1>\n"
2391 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2393 "</html>\n", query->psz_url );
2396 answer->i_body = p - answer->p_body;
2397 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2398 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2401 cl->i_state = HTTPD_CLIENT_SENDING;
2404 else if( cl->i_state == HTTPD_CLIENT_SEND_DONE )
2406 if( cl->i_mode == HTTPD_CLIENT_FILE || cl->answer.i_body_offset == 0 )
2409 if( ( cl->query.i_proto == HTTPD_PROTO_HTTP &&
2410 ( ( cl->answer.i_version == 0 && !strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Keep-Alive" ) ) ||
2411 ( cl->answer.i_version == 1 && strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) ) ) ||
2412 ( cl->query.i_proto == HTTPD_PROTO_RTSP &&
2413 strcasecmp( httpd_MsgGet( &cl->query, "Connection" ), "Close" ) &&
2414 strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) )
2416 httpd_MsgClean( &cl->query );
2417 httpd_MsgInit( &cl->query );
2420 cl->i_buffer_size = 1000;
2421 free( cl->p_buffer );
2422 cl->p_buffer = malloc( cl->i_buffer_size );
2423 cl->i_state = HTTPD_CLIENT_RECEIVING;
2427 cl->i_state = HTTPD_CLIENT_DEAD;
2429 httpd_MsgClean( &cl->answer );
2431 else if( cl->b_read_waiting )
2433 /* we have a message waiting for us to read it */
2434 httpd_MsgClean( &cl->answer );
2435 httpd_MsgClean( &cl->query );
2438 cl->i_buffer_size = 1000;
2439 free( cl->p_buffer );
2440 cl->p_buffer = malloc( cl->i_buffer_size );
2441 cl->i_state = HTTPD_CLIENT_RECEIVING;
2442 cl->b_read_waiting = VLC_FALSE;
2446 int64_t i_offset = cl->answer.i_body_offset;
2447 httpd_MsgClean( &cl->answer );
2449 cl->answer.i_body_offset = i_offset;
2450 free( cl->p_buffer );
2451 cl->p_buffer = NULL;
2453 cl->i_buffer_size = 0;
2455 cl->i_state = HTTPD_CLIENT_WAITING;
2458 else if( cl->i_state == HTTPD_CLIENT_WAITING )
2460 int64_t i_offset = cl->answer.i_body_offset;
2461 int i_msg = cl->query.i_type;
2463 httpd_MsgInit( &cl->answer );
2464 cl->answer.i_body_offset = i_offset;
2466 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
2467 &cl->answer, &cl->query );
2468 if( cl->answer.i_type != HTTPD_MSG_NONE )
2470 /* we have new data, so reenter send mode */
2472 cl->p_buffer = cl->answer.p_body;
2473 cl->i_buffer_size = cl->answer.i_body;
2474 cl->answer.p_body = NULL;
2475 cl->answer.i_body = 0;
2476 cl->i_state = HTTPD_CLIENT_SENDING;
2480 /* we shouldn't wait too long */
2481 b_low_delay = VLC_TRUE;
2485 /* Special for BIDIR mode we also check reading */
2486 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2487 cl->i_state == HTTPD_CLIENT_SENDING )
2489 FD_SET( cl->fd, &fds_read );
2490 i_handle_max = __MAX( i_handle_max, cl->fd );
2493 vlc_mutex_unlock( &host->lock );
2495 /* we will wait 100ms or 20ms (not too big 'cause HTTPD_CLIENT_WAITING) */
2497 timeout.tv_usec = b_low_delay ? 20000 : 100000;
2499 i_ret = select( i_handle_max + 1,
2500 &fds_read, &fds_write, NULL, &timeout );
2502 if( i_ret == -1 && errno != EINTR )
2504 #if defined(WIN32) || defined(UNDER_CE)
2505 msg_Warn( host, "cannot select sockets (%d)", WSAGetLastError( ) );
2507 msg_Warn( host, "cannot select sockets : %s", strerror( errno ) );
2512 else if( i_ret <= 0 )
2517 /* accept new connections */
2518 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
2520 if( FD_ISSET( fd, &fds_read ) )
2522 socklen_t i_sock_size = sizeof( struct sockaddr_storage );
2523 struct sockaddr_storage sock;
2525 fd = accept( fd, (struct sockaddr *)&sock, &i_sock_size );
2526 fprintf ( stderr, "Accepting\n");
2531 /* set this new socket non-block */
2532 #if defined( WIN32 ) || defined( UNDER_CE )
2534 unsigned long i_dummy = 1;
2535 ioctlsocket( fd, FIONBIO, &i_dummy );
2538 fcntl( fd, F_SETFL, O_NONBLOCK );
2543 switch ( tls_ServerSessionHandshake( p_tls, fd ) )
2546 msg_Err( host, "Rejecting TLS connection" );
2552 case 1: /* missing input - most likely */
2553 i_state = HTTPD_CLIENT_TLS_HS_IN;
2556 case 2: /* missing output */
2557 i_state = HTTPD_CLIENT_TLS_HS_OUT;
2565 stats_UpdateInteger( host, STATS_CLIENT_CONNECTIONS,
2567 stats_UpdateInteger( host, STATS_ACTIVE_CONNECTIONS, 1,
2569 cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
2571 vlc_mutex_lock( &host->lock );
2572 TAB_APPEND( host->i_client, host->client, cl );
2573 vlc_mutex_unlock( &host->lock );
2576 cl->i_state = i_state; // override state for TLS
2582 /* now try all others socket */
2583 vlc_mutex_lock( &host->lock );
2584 for( i_client = 0; i_client < host->i_client; i_client++ )
2586 httpd_client_t *cl = host->client[i_client];
2587 if( cl->i_state == HTTPD_CLIENT_RECEIVING )
2589 httpd_ClientRecv( cl );
2591 else if( cl->i_state == HTTPD_CLIENT_SENDING )
2593 httpd_ClientSend( cl );
2595 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN )
2597 httpd_ClientTlsHsIn( cl );
2599 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT )
2601 httpd_ClientTlsHsOut( cl );
2604 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2605 cl->i_state == HTTPD_CLIENT_SENDING &&
2606 FD_ISSET( cl->fd, &fds_read ) )
2608 cl->b_read_waiting = VLC_TRUE;
2611 vlc_mutex_unlock( &host->lock );
2615 tls_ServerSessionClose( p_tls );
2618 #else /* ENABLE_HTTPD */
2620 /* We just define an empty wrapper */
2621 httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, char *b, int c,
2624 msg_Err( a, "HTTP daemon support is disabled" );
2627 httpd_host_t *httpd_HostNew( vlc_object_t *a, char *b, int c )
2629 msg_Err( a, "HTTP daemon support is disabled" );
2632 void httpd_HostDelete( httpd_host_t *a )
2635 httpd_url_t *httpd_UrlNew( httpd_host_t *host, char *psz_url,
2636 char *psz_user, char *psz_password,
2637 const vlc_acl_t *p_acl )
2641 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, char *psz_url,
2642 char *psz_user, char *psz_password,
2643 const vlc_acl_t *p_acl )
2647 int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c,
2648 httpd_callback_sys_t *d ){ return 0; }
2649 void httpd_UrlDelete( httpd_url_t *a ){}
2651 char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip ) { return NULL; }
2652 char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip ) { return NULL; }
2654 void httpd_ClientModeStream( httpd_client_t *a ){}
2655 void httpd_ClientModeBidir( httpd_client_t *a ){}
2657 void httpd_FileDelete( httpd_file_t *a ){}
2658 httpd_file_t *httpd_FileNew( httpd_host_t *a, char *b, char *c, char *d,
2659 char *e, httpd_file_callback_t f,
2660 httpd_file_sys_t *g ){ return 0; }
2662 httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
2663 const char *psz_user,
2664 const char *psz_password,
2665 const vlc_acl_t *p_acl,
2666 httpd_handler_callback_t pf_fill,
2667 httpd_handler_sys_t *p_sys )
2671 void httpd_HandlerDelete( httpd_handler_t *handler ) {}
2673 void httpd_RedirectDelete( httpd_redirect_t *a ){}
2674 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *a,
2675 char *b, char *c ){ return 0; }
2677 void httpd_StreamDelete( httpd_stream_t *a ){}
2678 int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2679 int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2680 httpd_stream_t *httpd_StreamNew( httpd_host_t *a, char *b, char *c,
2681 char *d, char *e ){ return 0; }
2683 void httpd_MsgInit ( httpd_message_t *a ){}
2684 void httpd_MsgAdd ( httpd_message_t *a, char *b, char *c, ... ){}
2685 char *httpd_MsgGet ( httpd_message_t *a, char *b ){ return 0; }
2686 void httpd_MsgClean( httpd_message_t *a ){}
2688 #endif /* ENABLE_HTTPD */