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., 59 Temple Place - Suite 330, Boston, MA 02111, 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 = 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(answer->p_body) + 1;
639 answer->p_body = realloc( answer->p_body, answer->i_body );
643 if( strncmp( answer->p_body, "HTTP/1.", 7 ) )
645 int i_status, i_headers;
646 char *psz_headers, *psz_new, *psz_status;
648 if( !strncmp( answer->p_body, "Status: ", 8 ) )
651 i_status = strtol( &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 = answer->p_body;
660 i_headers = answer->i_body;
668 psz_status = "Unauthorized";
671 psz_status = "Undefined";
674 snprintf( psz_code, sizeof(psz_code), "%d", i_status );
675 answer->i_body = sizeof("HTTP/1.0 \r\n") + strlen(psz_code)
676 + strlen(psz_status) + i_headers - 1;
677 psz_new = malloc( answer->i_body + 1);
678 sprintf( psz_new, "HTTP/1.0 %s %s\r\n", psz_code, psz_status );
679 memcpy( &psz_new[strlen(psz_new)], psz_headers, i_headers );
680 free( answer->p_body );
681 answer->p_body = psz_new;
687 httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
688 const char *psz_user,
689 const char *psz_password,
690 const vlc_acl_t *p_acl,
691 httpd_handler_callback_t pf_fill,
692 httpd_handler_sys_t *p_sys )
694 httpd_handler_t *handler = malloc( sizeof( httpd_handler_t ) );
696 if( ( handler->url = httpd_UrlNewUnique( host, psz_url, psz_user,
697 psz_password, p_acl )
704 handler->pf_fill = pf_fill;
705 handler->p_sys = p_sys;
707 httpd_UrlCatch( handler->url, HTTPD_MSG_HEAD, httpd_HandlerCallBack,
708 (httpd_callback_sys_t*)handler );
709 httpd_UrlCatch( handler->url, HTTPD_MSG_GET, httpd_HandlerCallBack,
710 (httpd_callback_sys_t*)handler );
711 httpd_UrlCatch( handler->url, HTTPD_MSG_POST, httpd_HandlerCallBack,
712 (httpd_callback_sys_t*)handler );
717 void httpd_HandlerDelete( httpd_handler_t *handler )
719 httpd_UrlDelete( handler->url );
723 /*****************************************************************************
724 * High Level Functions: httpd_redirect_t
725 *****************************************************************************/
726 struct httpd_redirect_t
732 static int httpd_RedirectCallBack( httpd_callback_sys_t *p_sys,
733 httpd_client_t *cl, httpd_message_t *answer,
734 httpd_message_t *query )
736 httpd_redirect_t *rdir = (httpd_redirect_t*)p_sys;
739 if( answer == NULL || query == NULL )
743 answer->i_proto = query->i_proto;
744 answer->i_version= query->i_version;
745 answer->i_type = HTTPD_MSG_ANSWER;
746 answer->i_status = 301;
747 answer->psz_status = strdup( "Moved Permanently" );
749 p = answer->p_body = malloc( 1000 + strlen( rdir->psz_dst ) );
750 p += sprintf( (char *)p,
751 "<?xml version=\"1.0\" encoding=\"ascii\" ?>\n"
752 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
753 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
756 "<title>Redirection</title>\n"
760 "<a href=\"%s\">redirected</a></h1>\n"
762 "<p><a href=\"http://www.videolan.org\">VideoLAN</a>\n</p>"
765 "</html>\n", rdir->psz_dst );
766 answer->i_body = p - answer->p_body;
768 /* XXX check if it's ok or we need to set an absolute url */
769 httpd_MsgAdd( answer, "Location", "%s", rdir->psz_dst );
771 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
776 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst,
777 const char *psz_url_src )
779 httpd_redirect_t *rdir = malloc( sizeof( httpd_redirect_t ) );
781 if( !( rdir->url = httpd_UrlNewUnique( host, psz_url_src, NULL, NULL, NULL ) ) )
786 rdir->psz_dst = strdup( psz_url_dst );
788 /* Redirect apply for all HTTP request and RTSP DESCRIBE resquest */
789 httpd_UrlCatch( rdir->url, HTTPD_MSG_HEAD, httpd_RedirectCallBack,
790 (httpd_callback_sys_t*)rdir );
791 httpd_UrlCatch( rdir->url, HTTPD_MSG_GET, httpd_RedirectCallBack,
792 (httpd_callback_sys_t*)rdir );
793 httpd_UrlCatch( rdir->url, HTTPD_MSG_POST, httpd_RedirectCallBack,
794 (httpd_callback_sys_t*)rdir );
795 httpd_UrlCatch( rdir->url, HTTPD_MSG_DESCRIBE, httpd_RedirectCallBack,
796 (httpd_callback_sys_t*)rdir );
800 void httpd_RedirectDelete( httpd_redirect_t *rdir )
802 httpd_UrlDelete( rdir->url );
803 free( rdir->psz_dst );
807 /*****************************************************************************
808 * High Level Funtions: httpd_stream_t
809 *****************************************************************************/
810 struct httpd_stream_t
817 /* Header to send as first packet */
821 /* circular buffer */
822 int i_buffer_size; /* buffer size, can't be reallocated smaller */
823 uint8_t *p_buffer; /* buffer */
824 int64_t i_buffer_pos; /* absolute position from begining */
825 int64_t i_buffer_last_pos; /* a new connection will start with that */
828 static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
829 httpd_client_t *cl, httpd_message_t *answer,
830 httpd_message_t *query )
832 httpd_stream_t *stream = (httpd_stream_t*)p_sys;
834 if( answer == NULL || query == NULL || cl == NULL )
838 if( answer->i_body_offset > 0 )
844 fprintf( stderr, "httpd_StreamCallBack i_body_offset=%lld\n",
845 answer->i_body_offset );
848 if( answer->i_body_offset >= stream->i_buffer_pos )
850 /* fprintf( stderr, "httpd_StreamCallBack: no data\n" ); */
851 return VLC_EGENERIC; /* wait, no data available */
853 if( answer->i_body_offset + stream->i_buffer_size <
854 stream->i_buffer_pos )
856 /* this client isn't fast enough */
857 fprintf( stderr, "fixing i_body_offset (old=%lld new=%lld)\n",
858 answer->i_body_offset, stream->i_buffer_last_pos );
859 answer->i_body_offset = stream->i_buffer_last_pos;
862 i_pos = answer->i_body_offset % stream->i_buffer_size;
863 i_write = stream->i_buffer_pos - answer->i_body_offset;
864 if( i_write > HTTPD_CL_BUFSIZE )
866 i_write = HTTPD_CL_BUFSIZE;
868 else if( i_write <= 0 )
870 return VLC_EGENERIC; /* wait, no data available */
873 /* Don't go past the end of the circular buffer */
874 i_write = __MIN( i_write, stream->i_buffer_size - i_pos );
876 /* using HTTPD_MSG_ANSWER -> data available */
877 answer->i_proto = HTTPD_PROTO_HTTP;
878 answer->i_version= 0;
879 answer->i_type = HTTPD_MSG_ANSWER;
881 answer->i_body = i_write;
882 answer->p_body = malloc( i_write );
883 memcpy( answer->p_body, &stream->p_buffer[i_pos], i_write );
885 answer->i_body_offset += i_write;
891 answer->i_proto = HTTPD_PROTO_HTTP;
892 answer->i_version= 0;
893 answer->i_type = HTTPD_MSG_ANSWER;
895 answer->i_status = 200;
896 answer->psz_status = strdup( "OK" );
898 if( query->i_type != HTTPD_MSG_HEAD )
900 httpd_ClientModeStream( cl );
901 vlc_mutex_lock( &stream->lock );
902 /* Send the header */
903 if( stream->i_header > 0 )
905 answer->i_body = stream->i_header;
906 answer->p_body = malloc( stream->i_header );
907 memcpy( answer->p_body, stream->p_header, stream->i_header );
909 answer->i_body_offset = stream->i_buffer_last_pos;
910 vlc_mutex_unlock( &stream->lock );
914 httpd_MsgAdd( answer, "Content-Length", "%d", 0 );
915 answer->i_body_offset = 0;
918 if( !strcmp( stream->psz_mime, "video/x-ms-asf-stream" ) )
920 vlc_bool_t b_xplaystream = VLC_FALSE;
923 httpd_MsgAdd( answer, "Content-type", "%s",
924 "application/octet-stream" );
925 httpd_MsgAdd( answer, "Server", "Cougar 4.1.0.3921" );
926 httpd_MsgAdd( answer, "Pragma", "no-cache" );
927 httpd_MsgAdd( answer, "Pragma", "client-id=%d", rand()&0x7fff );
928 httpd_MsgAdd( answer, "Pragma", "features=\"broadcast\"" );
930 /* Check if there is a xPlayStrm=1 */
931 for( i = 0; i < query->i_name; i++ )
933 if( !strcasecmp( query->name[i], "Pragma" ) &&
934 strstr( query->value[i], "xPlayStrm=1" ) )
936 b_xplaystream = VLC_TRUE;
942 answer->i_body_offset = 0;
947 httpd_MsgAdd( answer, "Content-type", "%s", stream->psz_mime );
949 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
954 httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
955 const char *psz_url, const char *psz_mime,
956 const char *psz_user, const char *psz_password,
957 const vlc_acl_t *p_acl )
959 httpd_stream_t *stream = malloc( sizeof( httpd_stream_t ) );
961 if( ( stream->url = httpd_UrlNewUnique( host, psz_url, psz_user,
962 psz_password, p_acl )
968 vlc_mutex_init( host, &stream->lock );
969 if( psz_mime && *psz_mime )
971 stream->psz_mime = strdup( psz_mime );
975 stream->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
977 stream->i_header = 0;
978 stream->p_header = NULL;
979 stream->i_buffer_size = 5000000; /* 5 Mo per stream */
980 stream->p_buffer = malloc( stream->i_buffer_size );
981 /* We set to 1 to make life simpler
982 * (this way i_body_offset can never be 0) */
983 stream->i_buffer_pos = 1;
984 stream->i_buffer_last_pos = 1;
986 httpd_UrlCatch( stream->url, HTTPD_MSG_HEAD, httpd_StreamCallBack,
987 (httpd_callback_sys_t*)stream );
988 httpd_UrlCatch( stream->url, HTTPD_MSG_GET, httpd_StreamCallBack,
989 (httpd_callback_sys_t*)stream );
990 httpd_UrlCatch( stream->url, HTTPD_MSG_POST, httpd_StreamCallBack,
991 (httpd_callback_sys_t*)stream );
996 int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
998 vlc_mutex_lock( &stream->lock );
999 if( stream->p_header )
1001 free( stream->p_header );
1002 stream->p_header = NULL;
1004 stream->i_header = i_data;
1007 stream->p_header = malloc( i_data );
1008 memcpy( stream->p_header, p_data, i_data );
1010 vlc_mutex_unlock( &stream->lock );
1015 int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
1020 if( i_data < 0 || p_data == NULL )
1024 vlc_mutex_lock( &stream->lock );
1026 /* save this pointer (to be used by new connection) */
1027 stream->i_buffer_last_pos = stream->i_buffer_pos;
1029 i_pos = stream->i_buffer_pos % stream->i_buffer_size;
1035 i_copy = __MIN( i_count, stream->i_buffer_size - i_pos );
1037 /* Ok, we can't go past the end of our buffer */
1038 memcpy( &stream->p_buffer[i_pos], p_data, i_copy );
1040 i_pos = ( i_pos + i_copy ) % stream->i_buffer_size;
1045 stream->i_buffer_pos += i_data;
1047 vlc_mutex_unlock( &stream->lock );
1051 void httpd_StreamDelete( httpd_stream_t *stream )
1053 httpd_UrlDelete( stream->url );
1054 vlc_mutex_destroy( &stream->lock );
1055 if( stream->psz_mime ) free( stream->psz_mime );
1056 if( stream->p_header ) free( stream->p_header );
1057 if( stream->p_buffer ) free( stream->p_buffer );
1062 /*****************************************************************************
1064 *****************************************************************************/
1065 static void httpd_HostThread( httpd_host_t * );
1067 /* create a new host */
1068 httpd_host_t *httpd_HostNew( vlc_object_t *p_this, const char *psz_host,
1071 return httpd_TLSHostNew( p_this, psz_host, i_port, NULL, NULL, NULL, NULL
1075 httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
1077 const char *psz_cert, const char *psz_key,
1078 const char *psz_ca, const char *psz_crl )
1082 tls_server_t *p_tls;
1084 vlc_value_t lockval;
1087 if( psz_hostname == NULL )
1090 psz_host = strdup( psz_hostname );
1091 if( psz_host == NULL )
1093 msg_Err( p_this, "memory error" );
1097 /* to be sure to avoid multiple creation */
1098 var_Create( p_this->p_libvlc, "httpd_mutex", VLC_VAR_MUTEX );
1099 var_Get( p_this->p_libvlc, "httpd_mutex", &lockval );
1100 vlc_mutex_lock( lockval.p_address );
1102 if( !(httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE )) )
1104 msg_Info( p_this, "creating httpd" );
1105 if( ( httpd = vlc_object_create( p_this, VLC_OBJECT_HTTPD ) ) == NULL )
1107 vlc_mutex_unlock( lockval.p_address );
1115 vlc_object_yield( httpd );
1116 vlc_object_attach( httpd, p_this->p_vlc );
1119 /* verify if it already exist */
1120 for( i = httpd->i_host - 1; i >= 0; i-- )
1122 host = httpd->host[i];
1124 /* cannot mix TLS and non-TLS hosts */
1125 if( ( ( httpd->host[i]->p_tls != NULL ) != ( psz_cert != NULL ) )
1126 || ( host->i_port != i_port )
1127 || strcmp( host->psz_hostname, psz_hostname ) )
1133 vlc_mutex_unlock( lockval.p_address );
1139 /* determine TLS configuration */
1140 if ( psz_cert != NULL )
1142 p_tls = tls_ServerCreate( p_this, psz_cert, psz_key );
1143 if ( p_tls == NULL )
1145 msg_Err( p_this, "TLS initialization error" );
1149 if ( ( psz_ca != NULL) && tls_ServerAddCA( p_tls, psz_ca ) )
1151 msg_Err( p_this, "TLS CA error" );
1155 if ( ( psz_crl != NULL) && tls_ServerAddCRL( p_tls, psz_crl ) )
1157 msg_Err( p_this, "TLS CRL error" );
1164 /* create the new host */
1165 host = vlc_object_create( p_this, sizeof( httpd_host_t ) );
1166 host->httpd = httpd;
1167 vlc_mutex_init( httpd, &host->lock );
1170 host->fd = net_ListenTCP( p_this, psz_host, i_port );
1171 if( host->fd == NULL )
1173 msg_Err( p_this, "cannot create socket(s) for HTTP host" );
1177 host->i_port = i_port;
1178 host->psz_hostname = psz_host;
1183 host->client = NULL;
1185 host->p_tls = p_tls;
1187 /* create the thread */
1188 if( vlc_thread_create( host, "httpd host thread", httpd_HostThread,
1189 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
1191 msg_Err( p_this, "cannot spawn http host thread" );
1195 /* now add it to httpd */
1196 TAB_APPEND( httpd->i_host, httpd->host, host );
1197 vlc_mutex_unlock( lockval.p_address );
1203 if( httpd->i_host <= 0 )
1205 vlc_object_release( httpd );
1206 vlc_object_detach( httpd );
1207 vlc_object_destroy( httpd );
1209 vlc_mutex_unlock( lockval.p_address );
1213 net_ListenClose( host->fd );
1214 vlc_mutex_destroy( &host->lock );
1215 vlc_object_destroy( host );
1219 tls_ServerDelete( p_tls );
1225 void httpd_HostDelete( httpd_host_t *host )
1227 httpd_t *httpd = host->httpd;
1228 vlc_value_t lockval;
1231 msg_Dbg( host, "httpd_HostDelete" );
1233 var_Get( httpd->p_libvlc, "httpd_mutex", &lockval );
1234 vlc_mutex_lock( lockval.p_address );
1237 if( host->i_ref > 0 )
1240 vlc_mutex_unlock( lockval.p_address );
1241 msg_Dbg( host, "httpd_HostDelete: host still used" );
1244 TAB_REMOVE( httpd->i_host, httpd->host, host );
1246 msg_Dbg( host, "httpd_HostDelete: host removed from http" );
1249 vlc_thread_join( host );
1251 msg_Dbg( host, "httpd_HostDelete: host thread joined" );
1253 for( i = 0; i < host->i_url; i++ )
1255 msg_Err( host, "url still registered:%s", host->url[i]->psz_url );
1257 for( i = 0; i < host->i_client; i++ )
1259 httpd_client_t *cl = host->client[i];
1260 msg_Warn( host, "client still connected" );
1261 httpd_ClientClean( cl );
1262 TAB_REMOVE( host->i_client, host->client, cl );
1268 if( host->p_tls != NULL)
1269 tls_ServerDelete( host->p_tls );
1271 net_ListenClose( host->fd );
1272 free( host->psz_hostname );
1274 vlc_mutex_destroy( &host->lock );
1275 vlc_object_destroy( host );
1277 vlc_object_release( httpd );
1278 if( httpd->i_host <= 0 )
1280 msg_Info( httpd, "httpd doesn't reference any host, deleting" );
1281 vlc_object_detach( httpd );
1282 vlc_object_destroy( httpd );
1284 vlc_mutex_unlock( lockval.p_address );
1287 /* register a new url */
1288 static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, const char *psz_url,
1289 const char *psz_user, const char *psz_password,
1290 const vlc_acl_t *p_acl, vlc_bool_t b_check )
1295 vlc_mutex_lock( &host->lock );
1298 for( i = 0; i < host->i_url; i++ )
1300 if( !strcmp( psz_url, host->url[i]->psz_url ) )
1302 msg_Warn( host->httpd,
1303 "cannot add '%s' (url already defined)", psz_url );
1304 vlc_mutex_unlock( &host->lock );
1310 url = malloc( sizeof( httpd_url_t ) );
1313 vlc_mutex_init( host->httpd, &url->lock );
1314 url->psz_url = strdup( psz_url );
1315 url->psz_user = strdup( psz_user ? psz_user : "" );
1316 url->psz_password = strdup( psz_password ? psz_password : "" );
1317 url->p_acl = ACL_Duplicate( host, p_acl );
1318 for( i = 0; i < HTTPD_MSG_MAX; i++ )
1320 url->catch[i].cb = NULL;
1321 url->catch[i].p_sys = NULL;
1324 TAB_APPEND( host->i_url, host->url, url );
1325 vlc_mutex_unlock( &host->lock );
1330 httpd_url_t *httpd_UrlNew( httpd_host_t *host, const char *psz_url,
1331 const char *psz_user, const char *psz_password,
1332 const vlc_acl_t *p_acl )
1334 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1335 psz_password, p_acl, VLC_FALSE );
1338 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, const char *psz_url,
1339 const char *psz_user, const char *psz_password,
1340 const vlc_acl_t *p_acl )
1342 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1343 psz_password, p_acl, VLC_TRUE );
1346 /* register callback on a url */
1347 int httpd_UrlCatch( httpd_url_t *url, int i_msg, httpd_callback_t cb,
1348 httpd_callback_sys_t *p_sys )
1350 vlc_mutex_lock( &url->lock );
1351 url->catch[i_msg].cb = cb;
1352 url->catch[i_msg].p_sys= p_sys;
1353 vlc_mutex_unlock( &url->lock );
1360 void httpd_UrlDelete( httpd_url_t *url )
1362 httpd_host_t *host = url->host;
1365 vlc_mutex_lock( &host->lock );
1366 TAB_REMOVE( host->i_url, host->url, url );
1368 vlc_mutex_destroy( &url->lock );
1369 free( url->psz_url );
1370 free( url->psz_user );
1371 free( url->psz_password );
1372 ACL_Destroy( url->p_acl );
1374 for( i = 0; i < host->i_client; i++ )
1376 httpd_client_t *client = host->client[i];
1378 if( client->url == url )
1380 /* TODO complete it */
1381 msg_Warn( host, "force closing connections" );
1382 httpd_ClientClean( client );
1383 TAB_REMOVE( host->i_client, host->client, client );
1389 vlc_mutex_unlock( &host->lock );
1392 void httpd_MsgInit( httpd_message_t *msg )
1395 msg->i_type = HTTPD_MSG_NONE;
1396 msg->i_proto = HTTPD_PROTO_NONE;
1397 msg->i_version = -1;
1400 msg->psz_status = NULL;
1402 msg->psz_url = NULL;
1403 msg->psz_args = NULL;
1405 msg->i_channel = -1;
1412 msg->i_body_offset = 0;
1417 void httpd_MsgClean( httpd_message_t *msg )
1421 if( msg->psz_status )
1423 free( msg->psz_status );
1427 free( msg->psz_url );
1431 free( msg->psz_args );
1433 for( i = 0; i < msg->i_name; i++ )
1435 free( msg->name[i] );
1436 free( msg->value[i] );
1448 free( msg->p_body );
1450 httpd_MsgInit( msg );
1453 char *httpd_MsgGet( httpd_message_t *msg, char *name )
1457 for( i = 0; i < msg->i_name; i++ )
1459 if( !strcasecmp( msg->name[i], name ))
1461 return msg->value[i];
1466 void httpd_MsgAdd( httpd_message_t *msg, char *name, char *psz_value, ... )
1471 va_start( args, psz_value );
1472 #if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
1473 vasprintf( &value, psz_value, args );
1476 int i_size = strlen( psz_value ) + 4096; /* FIXME stupid system */
1477 value = calloc( i_size, sizeof( char ) );
1478 vsnprintf( value, i_size, psz_value, args );
1479 value[i_size - 1] = 0;
1484 name = strdup( name );
1486 TAB_APPEND( msg->i_name, msg->name, name );
1487 TAB_APPEND( msg->i_value, msg->value, value );
1490 static void httpd_ClientInit( httpd_client_t *cl )
1492 cl->i_state = HTTPD_CLIENT_RECEIVING;
1493 cl->i_activity_date = mdate();
1494 cl->i_activity_timeout = I64C(10000000);
1495 cl->i_buffer_size = HTTPD_CL_BUFSIZE;
1497 cl->p_buffer = malloc( cl->i_buffer_size );
1498 cl->i_mode = HTTPD_CLIENT_FILE;
1499 cl->b_read_waiting = VLC_FALSE;
1501 httpd_MsgInit( &cl->query );
1502 httpd_MsgInit( &cl->answer );
1505 void httpd_ClientModeStream( httpd_client_t *cl )
1507 cl->i_mode = HTTPD_CLIENT_STREAM;
1510 void httpd_ClientModeBidir( httpd_client_t *cl )
1512 cl->i_mode = HTTPD_CLIENT_BIDIR;
1515 char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip )
1517 return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1520 char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip )
1522 return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1525 static void httpd_ClientClean( httpd_client_t *cl )
1529 if( cl->p_tls != NULL )
1530 tls_ServerSessionClose( cl->p_tls );
1531 net_Close( cl->fd );
1535 httpd_MsgClean( &cl->answer );
1536 httpd_MsgClean( &cl->query );
1540 free( cl->p_buffer );
1541 cl->p_buffer = NULL;
1545 static httpd_client_t *httpd_ClientNew( int fd, struct sockaddr_storage *sock,
1547 tls_session_t *p_tls )
1549 httpd_client_t *cl = malloc( sizeof( httpd_client_t ) );
1552 memcpy( &cl->sock, sock, sizeof( cl->sock ) );
1553 cl->i_sock_size = i_sock_size;
1557 httpd_ClientInit( cl );
1563 static int httpd_NetRecv( httpd_client_t *cl, uint8_t *p, int i_len )
1565 tls_session_t *p_tls;
1569 return tls_Recv( p_tls, p, i_len );
1571 return recv( cl->fd, p, i_len, 0 );
1575 static int httpd_NetSend( httpd_client_t *cl, const uint8_t *p, int i_len )
1577 tls_session_t *p_tls;
1581 return tls_Send( p_tls, p, i_len );
1583 return send( cl->fd, p, i_len, 0 );
1587 static void httpd_ClientRecv( httpd_client_t *cl )
1591 if( cl->query.i_proto == HTTPD_PROTO_NONE )
1593 /* enough to see if it's rtp over rtsp or RTSP/HTTP */
1594 i_len = httpd_NetRecv( cl, &cl->p_buffer[cl->i_buffer],
1598 cl->i_buffer += i_len;
1601 if( cl->i_buffer >= 4 )
1603 /*fprintf( stderr, "peek=%4.4s\n", cl->p_buffer );*/
1605 if( cl->p_buffer[0] == '$' )
1607 /* RTSP (rtp over rtsp) */
1608 cl->query.i_proto = HTTPD_PROTO_RTSP;
1609 cl->query.i_type = HTTPD_MSG_CHANNEL;
1610 cl->query.i_channel = cl->p_buffer[1];
1611 cl->query.i_body = (cl->p_buffer[2] << 8)|cl->p_buffer[3];
1612 cl->query.p_body = malloc( cl->query.i_body );
1616 else if( !memcmp( cl->p_buffer, "HTTP", 4 ) )
1618 cl->query.i_proto = HTTPD_PROTO_HTTP;
1619 cl->query.i_type = HTTPD_MSG_ANSWER;
1621 else if( !memcmp( cl->p_buffer, "RTSP", 4 ) )
1623 cl->query.i_proto = HTTPD_PROTO_RTSP;
1624 cl->query.i_type = HTTPD_MSG_ANSWER;
1626 else if( !memcmp( cl->p_buffer, "GET", 3 ) ||
1627 !memcmp( cl->p_buffer, "HEAD", 4 ) ||
1628 !memcmp( cl->p_buffer, "POST", 4 ) )
1630 cl->query.i_proto = HTTPD_PROTO_HTTP;
1631 cl->query.i_type = HTTPD_MSG_NONE;
1635 cl->query.i_proto = HTTPD_PROTO_RTSP;
1636 cl->query.i_type = HTTPD_MSG_NONE;
1640 else if( cl->query.i_body > 0 )
1642 /* we are reading the body of a request or a channel */
1643 i_len = httpd_NetRecv( cl, &cl->query.p_body[cl->i_buffer],
1644 cl->query.i_body - cl->i_buffer );
1647 cl->i_buffer += i_len;
1649 if( cl->i_buffer >= cl->query.i_body )
1651 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1656 /* we are reading a header -> char by char */
1659 i_len = httpd_NetRecv (cl, &cl->p_buffer[cl->i_buffer], 1 );
1666 if( cl->i_buffer + 1 >= cl->i_buffer_size )
1668 cl->i_buffer_size += 1024;
1669 cl->p_buffer = realloc( cl->p_buffer, cl->i_buffer_size );
1671 if( ( cl->i_buffer >= 2 && !memcmp( &cl->p_buffer[cl->i_buffer-2], "\n\n", 2 ) )||
1672 ( cl->i_buffer >= 4 && !memcmp( &cl->p_buffer[cl->i_buffer-4], "\r\n\r\n", 4 ) ) )
1676 /* we have finished the header so parse it and set i_body */
1677 cl->p_buffer[cl->i_buffer] = '\0';
1679 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1682 * assume strlen( "HTTP/1.x" ) = 8
1684 cl->query.i_status =
1685 strtol( (char *)&cl->p_buffer[8],
1691 cl->query.psz_status = strdup( p );
1703 { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP },
1704 { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP },
1705 { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP },
1707 { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP },
1708 { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP },
1709 { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP },
1710 { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP },
1711 { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP },
1712 { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP },
1714 { NULL, HTTPD_MSG_NONE, HTTPD_PROTO_NONE }
1719 cl->query.i_type = HTTPD_MSG_NONE;
1721 /*fprintf( stderr, "received new request=%s\n", cl->p_buffer);*/
1723 for( i = 0; msg_type[i].name != NULL; i++ )
1725 if( !strncmp( (char *)cl->p_buffer, msg_type[i].name,
1726 strlen( msg_type[i].name ) ) )
1728 p = (char *)&cl->p_buffer[strlen((char *)msg_type[i].name) + 1 ];
1729 cl->query.i_type = msg_type[i].i_type;
1730 if( cl->query.i_proto != msg_type[i].i_proto )
1733 cl->query.i_proto = HTTPD_PROTO_NONE;
1734 cl->query.i_type = HTTPD_MSG_NONE;
1741 if( strstr( (char *)cl->p_buffer, "HTTP/1." ) )
1743 cl->query.i_proto = HTTPD_PROTO_HTTP;
1745 else if( strstr( (char *)cl->p_buffer, "RTSP/1." ) )
1747 cl->query.i_proto = HTTPD_PROTO_RTSP;
1759 p2 = strchr( p, ' ' );
1764 if( !strncasecmp( p, "rtsp:", 5 ) )
1766 /* for rtsp url, you have rtsp://localhost:port/path */
1768 while( *p == '/' ) p++;
1769 while( *p && *p != '/' ) p++;
1771 cl->query.psz_url = strdup( p );
1772 if( ( p3 = strchr( cl->query.psz_url, '?' ) ) )
1775 cl->query.psz_args = (uint8_t *)strdup( p3 );
1783 if( !strncasecmp( p2, "HTTP/1.", 7 ) )
1785 cl->query.i_proto = HTTPD_PROTO_HTTP;
1786 cl->query.i_version = atoi( p2+7 );
1788 else if( !strncasecmp( p2, "RTSP/1.", 7 ) )
1790 cl->query.i_proto = HTTPD_PROTO_RTSP;
1791 cl->query.i_version = atoi( p2+7 );
1799 p = strchr( p, '\n' );
1803 while( *p == '\n' || *p == '\r' )
1807 while( p && *p != '\0' )
1810 char *eol = p = strchr( p, '\n' );
1813 while( eol && eol >= line && ( *eol == '\n' || *eol == '\r' ) )
1818 if( ( colon = strchr( line, ':' ) ) )
1824 while( *colon == ' ' )
1828 name = strdup( line );
1829 value = strdup( colon );
1831 TAB_APPEND( cl->query.i_name, cl->query.name, name );
1832 TAB_APPEND( cl->query.i_value,cl->query.value,value);
1834 if( !strcasecmp( name, "Content-Length" ) )
1836 cl->query.i_body = atol( value );
1843 while( *p == '\n' || *p == '\r' )
1850 if( cl->query.i_body > 0 )
1852 /* TODO Mhh, handle the case client will only send a request and close the connection
1853 * to mark and of body (probably only RTSP) */
1854 cl->query.p_body = malloc( cl->query.i_body );
1859 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1865 /* check if the client is to be set to dead */
1866 #if defined( WIN32 ) || defined( UNDER_CE )
1867 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1869 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1872 if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE )
1874 /* connection closed -> end of data */
1875 if( cl->query.i_body > 0 )
1877 cl->query.i_body = cl->i_buffer;
1879 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1883 cl->i_state = HTTPD_CLIENT_DEAD;
1886 cl->i_activity_date = mdate();
1888 /* XXX: for QT I have to disable timeout. Try to find why */
1889 if( cl->query.i_proto == HTTPD_PROTO_RTSP )
1890 cl->i_activity_timeout = 0;
1892 /* Debugging only */
1893 /*if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
1897 fprintf( stderr, "received new request\n" );
1898 fprintf( stderr, " - proto=%s\n",
1899 cl->query.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP" );
1900 fprintf( stderr, " - version=%d\n", cl->query.i_version );
1901 fprintf( stderr, " - msg=%d\n", cl->query.i_type );
1902 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1904 fprintf( stderr, " - answer=%d '%s'\n", cl->query.i_status,
1905 cl->query.psz_status );
1907 else if( cl->query.i_type != HTTPD_MSG_NONE )
1909 fprintf( stderr, " - url=%s\n", cl->query.psz_url );
1911 for( i = 0; i < cl->query.i_name; i++ )
1913 fprintf( stderr, " - option name='%s' value='%s'\n",
1914 cl->query.name[i], cl->query.value[i] );
1920 static void httpd_ClientSend( httpd_client_t *cl )
1925 if( cl->i_buffer < 0 )
1927 /* We need to create the header */
1931 i_size = strlen( "HTTP/1.") + 10 + 10 +
1932 strlen( cl->answer.psz_status ? cl->answer.psz_status : "" ) + 5;
1933 for( i = 0; i < cl->answer.i_name; i++ )
1935 i_size += strlen( cl->answer.name[i] ) + 2 +
1936 strlen( cl->answer.value[i] ) + 2;
1939 if( cl->i_buffer_size < i_size )
1941 cl->i_buffer_size = i_size;
1942 free( cl->p_buffer );
1943 cl->p_buffer = malloc( i_size );
1945 p = (char *)cl->p_buffer;
1947 p += sprintf( p, "%s/1.%d %d %s\r\n",
1948 cl->answer.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP",
1949 cl->answer.i_version,
1950 cl->answer.i_status, cl->answer.psz_status );
1951 for( i = 0; i < cl->answer.i_name; i++ )
1953 p += sprintf( p, "%s: %s\r\n", cl->answer.name[i],
1954 cl->answer.value[i] );
1956 p += sprintf( p, "\r\n" );
1959 cl->i_buffer_size = (uint8_t*)p - cl->p_buffer;
1961 /*fprintf( stderr, "sending answer\n" );
1962 fprintf( stderr, "%s", cl->p_buffer );*/
1965 i_len = httpd_NetSend( cl, &cl->p_buffer[cl->i_buffer],
1966 cl->i_buffer_size - cl->i_buffer );
1969 cl->i_activity_date = mdate();
1970 cl->i_buffer += i_len;
1972 if( cl->i_buffer >= cl->i_buffer_size )
1974 if( cl->answer.i_body == 0 && cl->answer.i_body_offset > 0 &&
1975 !cl->b_read_waiting )
1977 /* catch more body data */
1978 int i_msg = cl->query.i_type;
1979 int64_t i_offset = cl->answer.i_body_offset;
1981 httpd_MsgClean( &cl->answer );
1982 cl->answer.i_body_offset = i_offset;
1984 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
1985 &cl->answer, &cl->query );
1988 if( cl->answer.i_body > 0 )
1990 /* send the body data */
1991 free( cl->p_buffer );
1992 cl->p_buffer = cl->answer.p_body;
1993 cl->i_buffer_size = cl->answer.i_body;
1996 cl->answer.i_body = 0;
1997 cl->answer.p_body = NULL;
2002 cl->i_state = HTTPD_CLIENT_SEND_DONE;
2008 #if defined( WIN32 ) || defined( UNDER_CE )
2009 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
2011 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
2015 cl->i_state = HTTPD_CLIENT_DEAD;
2020 static void httpd_ClientTlsHsIn( httpd_client_t *cl )
2022 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2025 cl->i_state = HTTPD_CLIENT_RECEIVING;
2029 cl->i_state = HTTPD_CLIENT_DEAD;
2034 cl->i_state = HTTPD_CLIENT_TLS_HS_OUT;
2038 static void httpd_ClientTlsHsOut( httpd_client_t *cl )
2040 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2043 cl->i_state = HTTPD_CLIENT_RECEIVING;
2047 cl->i_state = HTTPD_CLIENT_DEAD;
2052 cl->i_state = HTTPD_CLIENT_TLS_HS_IN;
2057 static void httpd_HostThread( httpd_host_t *host )
2059 tls_session_t *p_tls = NULL;
2061 while( !host->b_die )
2063 struct timeval timeout;
2066 /* FIXME: (too) many int variables */
2068 int i_handle_max = 0;
2071 int b_low_delay = 0;
2073 if( host->i_url <= 0 )
2080 /* built a set of handle to select */
2081 FD_ZERO( &fds_read );
2082 FD_ZERO( &fds_write );
2086 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
2088 FD_SET( fd, &fds_read );
2089 if( fd > i_handle_max )
2093 /* prepare a new TLS session */
2094 if( ( p_tls == NULL ) && ( host->p_tls != NULL ) )
2095 p_tls = tls_ServerSessionPrepare( host->p_tls );
2097 /* add all socket that should be read/write and close dead connection */
2098 vlc_mutex_lock( &host->lock );
2099 for( i_client = 0; i_client < host->i_client; i_client++ )
2101 httpd_client_t *cl = host->client[i_client];
2103 if( cl->i_ref < 0 || ( cl->i_ref == 0 &&
2104 ( cl->i_state == HTTPD_CLIENT_DEAD ||
2105 ( cl->i_activity_timeout > 0 &&
2106 cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
2108 httpd_ClientClean( cl );
2109 TAB_REMOVE( host->i_client, host->client, cl );
2114 else if( ( cl->i_state == HTTPD_CLIENT_RECEIVING )
2115 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) )
2117 FD_SET( cl->fd, &fds_read );
2118 i_handle_max = __MAX( i_handle_max, cl->fd );
2120 else if( ( cl->i_state == HTTPD_CLIENT_SENDING )
2121 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) )
2123 FD_SET( cl->fd, &fds_write );
2124 i_handle_max = __MAX( i_handle_max, cl->fd );
2126 else if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
2128 httpd_message_t *answer = &cl->answer;
2129 httpd_message_t *query = &cl->query;
2130 int i_msg = query->i_type;
2132 httpd_MsgInit( answer );
2134 /* Handle what we received */
2135 if( cl->i_mode != HTTPD_CLIENT_BIDIR &&
2136 (i_msg == HTTPD_MSG_ANSWER || i_msg == HTTPD_MSG_CHANNEL) )
2138 /* we can only receive request from client when not
2141 cl->i_state = HTTPD_CLIENT_DEAD;
2143 else if( i_msg == HTTPD_MSG_ANSWER )
2145 /* We are in BIDIR mode, trigger the callback and then
2146 * check for new data */
2147 if( cl->url && cl->url->catch[i_msg].cb )
2149 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2152 cl->i_state = HTTPD_CLIENT_WAITING;
2154 else if( i_msg == HTTPD_MSG_CHANNEL )
2156 /* We are in BIDIR mode, trigger the callback and then
2157 * check for new data */
2158 if( cl->url && cl->url->catch[i_msg].cb )
2160 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2163 cl->i_state = HTTPD_CLIENT_WAITING;
2165 else if( i_msg == HTTPD_MSG_OPTIONS )
2170 answer->i_proto = query->i_proto ;
2171 answer->i_type = HTTPD_MSG_ANSWER;
2172 answer->i_version= 0;
2173 answer->i_status = 200;
2174 answer->psz_status = strdup( "Ok" );
2177 answer->p_body = NULL;
2179 i_cseq = atoi( httpd_MsgGet( query, "Cseq" ) );
2180 httpd_MsgAdd( answer, "Cseq", "%d", i_cseq );
2181 httpd_MsgAdd( answer, "Server", "VLC Server" );
2182 httpd_MsgAdd( answer, "Public", "DESCRIBE, SETUP, "
2183 "TEARDOWN, PLAY, PAUSE" );
2184 httpd_MsgAdd( answer, "Content-Length", "%d",
2187 cl->i_buffer = -1; /* Force the creation of the answer in
2188 * httpd_ClientSend */
2189 cl->i_state = HTTPD_CLIENT_SENDING;
2191 else if( i_msg == HTTPD_MSG_NONE )
2193 if( query->i_proto == HTTPD_PROTO_NONE )
2196 cl->i_state = HTTPD_CLIENT_DEAD;
2203 answer->i_proto = query->i_proto ;
2204 answer->i_type = HTTPD_MSG_ANSWER;
2205 answer->i_version= 0;
2206 answer->i_status = 501;
2207 answer->psz_status = strdup( "Unimplemented" );
2209 p = answer->p_body = malloc( 1000 );
2211 p += sprintf( (char *)p,
2212 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2213 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2214 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2217 "<title>Error 501</title>\n"
2220 "<h1>501 Unimplemented</h1>\n"
2222 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2226 answer->i_body = p - answer->p_body;
2227 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2229 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2230 cl->i_state = HTTPD_CLIENT_SENDING;
2235 vlc_bool_t b_auth_failed = VLC_FALSE;
2236 vlc_bool_t b_hosts_failed = VLC_FALSE;
2239 /* Search the url and trigger callbacks */
2240 for( i = 0; i < host->i_url; i++ )
2242 httpd_url_t *url = host->url[i];
2244 if( !strcmp( url->psz_url, query->psz_url ) )
2246 if( url->catch[i_msg].cb )
2248 if( answer && ( url->p_acl != NULL ) )
2250 char ip[NI_MAXNUMERICHOST];
2252 if( httpd_ClientIP( cl, ip ) != NULL )
2254 if( ACL_Check( url->p_acl, ip ) )
2256 b_hosts_failed = VLC_TRUE;
2261 b_hosts_failed = VLC_TRUE;
2264 if( answer && ( *url->psz_user || *url->psz_password ) )
2266 /* create the headers */
2267 char *b64 = httpd_MsgGet( query, "Authorization" ); /* BASIC id */
2271 asprintf( &id, "%s:%s", url->psz_user, url->psz_password );
2272 auth = malloc( strlen(b64) + 1 );
2274 if( !strncasecmp( b64, "BASIC", 5 ) )
2277 while( *b64 == ' ' )
2281 b64_decode( auth, b64 );
2287 if( strcmp( id, auth ) )
2289 httpd_MsgAdd( answer, "WWW-Authenticate", "Basic realm=\"%s\"", url->psz_user );
2290 /* We fail for all url */
2291 b_auth_failed = VLC_TRUE;
2301 if( !url->catch[i_msg].cb( url->catch[i_msg].p_sys, cl, answer, query ) )
2303 if( answer->i_proto == HTTPD_PROTO_NONE )
2305 /* Raw answer from a CGI */
2306 cl->i_buffer = cl->i_buffer_size;
2311 /* only one url can answer */
2313 if( cl->url == NULL )
2325 answer->i_proto = query->i_proto;
2326 answer->i_type = HTTPD_MSG_ANSWER;
2327 answer->i_version= 0;
2328 p = answer->p_body = malloc( 1000 + strlen(query->psz_url) );
2330 if( b_hosts_failed )
2332 answer->i_status = 403;
2333 answer->psz_status = strdup( "Forbidden" );
2335 /* FIXME: lots of code duplication */
2336 p += sprintf( (char *)p,
2337 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2338 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2339 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2342 "<title>Error 403</title>\n"
2345 "<h1>403 Forbidden (%s)</h1>\n"
2347 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2349 "</html>\n", query->psz_url );
2351 else if( b_auth_failed )
2353 answer->i_status = 401;
2354 answer->psz_status = strdup( "Authorization Required" );
2356 p += sprintf( (char *)p,
2357 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2358 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2359 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2362 "<title>Error 401</title>\n"
2365 "<h1>401 Authorization Required (%s)</h1>\n"
2367 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2369 "</html>\n", query->psz_url );
2373 /* no url registered */
2374 answer->i_status = 404;
2375 answer->psz_status = strdup( "Not found" );
2377 p += sprintf( (char *)p,
2378 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2379 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2380 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2383 "<title>Error 404</title>\n"
2386 "<h1>404 Resource not found(%s)</h1>\n"
2388 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2390 "</html>\n", query->psz_url );
2393 answer->i_body = p - answer->p_body;
2394 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2395 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2398 cl->i_state = HTTPD_CLIENT_SENDING;
2401 else if( cl->i_state == HTTPD_CLIENT_SEND_DONE )
2403 if( cl->i_mode == HTTPD_CLIENT_FILE || cl->answer.i_body_offset == 0 )
2406 if( ( cl->query.i_proto == HTTPD_PROTO_HTTP &&
2407 ( ( cl->answer.i_version == 0 && !strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Keep-Alive" ) ) ||
2408 ( cl->answer.i_version == 1 && strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) ) ) ||
2409 ( cl->query.i_proto == HTTPD_PROTO_RTSP &&
2410 strcasecmp( httpd_MsgGet( &cl->query, "Connection" ), "Close" ) &&
2411 strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) )
2413 httpd_MsgClean( &cl->query );
2414 httpd_MsgInit( &cl->query );
2417 cl->i_buffer_size = 1000;
2418 free( cl->p_buffer );
2419 cl->p_buffer = malloc( cl->i_buffer_size );
2420 cl->i_state = HTTPD_CLIENT_RECEIVING;
2424 cl->i_state = HTTPD_CLIENT_DEAD;
2426 httpd_MsgClean( &cl->answer );
2428 else if( cl->b_read_waiting )
2430 /* we have a message waiting for us to read it */
2431 httpd_MsgClean( &cl->answer );
2432 httpd_MsgClean( &cl->query );
2435 cl->i_buffer_size = 1000;
2436 free( cl->p_buffer );
2437 cl->p_buffer = malloc( cl->i_buffer_size );
2438 cl->i_state = HTTPD_CLIENT_RECEIVING;
2439 cl->b_read_waiting = VLC_FALSE;
2443 int64_t i_offset = cl->answer.i_body_offset;
2444 httpd_MsgClean( &cl->answer );
2446 cl->answer.i_body_offset = i_offset;
2447 free( cl->p_buffer );
2448 cl->p_buffer = NULL;
2450 cl->i_buffer_size = 0;
2452 cl->i_state = HTTPD_CLIENT_WAITING;
2455 else if( cl->i_state == HTTPD_CLIENT_WAITING )
2457 int64_t i_offset = cl->answer.i_body_offset;
2458 int i_msg = cl->query.i_type;
2460 httpd_MsgInit( &cl->answer );
2461 cl->answer.i_body_offset = i_offset;
2463 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
2464 &cl->answer, &cl->query );
2465 if( cl->answer.i_type != HTTPD_MSG_NONE )
2467 /* we have new data, so reenter send mode */
2469 cl->p_buffer = cl->answer.p_body;
2470 cl->i_buffer_size = cl->answer.i_body;
2471 cl->answer.p_body = NULL;
2472 cl->answer.i_body = 0;
2473 cl->i_state = HTTPD_CLIENT_SENDING;
2477 /* we shouldn't wait too long */
2478 b_low_delay = VLC_TRUE;
2482 /* Special for BIDIR mode we also check reading */
2483 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2484 cl->i_state == HTTPD_CLIENT_SENDING )
2486 FD_SET( cl->fd, &fds_read );
2487 i_handle_max = __MAX( i_handle_max, cl->fd );
2490 vlc_mutex_unlock( &host->lock );
2492 /* we will wait 100ms or 20ms (not too big 'cause HTTPD_CLIENT_WAITING) */
2494 timeout.tv_usec = b_low_delay ? 20000 : 100000;
2496 i_ret = select( i_handle_max + 1,
2497 &fds_read, &fds_write, NULL, &timeout );
2499 if( i_ret == -1 && errno != EINTR )
2501 #if defined(WIN32) || defined(UNDER_CE)
2502 msg_Warn( host, "cannot select sockets (%d)", WSAGetLastError( ) );
2504 msg_Warn( host, "cannot select sockets : %s", strerror( errno ) );
2509 else if( i_ret <= 0 )
2514 /* accept new connections */
2515 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
2517 if( FD_ISSET( fd, &fds_read ) )
2519 socklen_t i_sock_size = sizeof( struct sockaddr_storage );
2520 struct sockaddr_storage sock;
2522 fd = accept( fd, (struct sockaddr *)&sock, &i_sock_size );
2527 /* set this new socket non-block */
2528 #if defined( WIN32 ) || defined( UNDER_CE )
2530 unsigned long i_dummy = 1;
2531 ioctlsocket( fd, FIONBIO, &i_dummy );
2534 fcntl( fd, F_SETFL, O_NONBLOCK );
2539 switch ( tls_ServerSessionHandshake( p_tls, fd ) )
2542 msg_Err( host, "Rejecting TLS connection" );
2548 case 1: /* missing input - most likely */
2549 i_state = HTTPD_CLIENT_TLS_HS_IN;
2552 case 2: /* missing output */
2553 i_state = HTTPD_CLIENT_TLS_HS_OUT;
2562 cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
2564 vlc_mutex_lock( &host->lock );
2565 TAB_APPEND( host->i_client, host->client, cl );
2566 vlc_mutex_unlock( &host->lock );
2569 cl->i_state = i_state; // override state for TLS
2575 /* now try all others socket */
2576 vlc_mutex_lock( &host->lock );
2577 for( i_client = 0; i_client < host->i_client; i_client++ )
2579 httpd_client_t *cl = host->client[i_client];
2580 if( cl->i_state == HTTPD_CLIENT_RECEIVING )
2582 httpd_ClientRecv( cl );
2584 else if( cl->i_state == HTTPD_CLIENT_SENDING )
2586 httpd_ClientSend( cl );
2588 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN )
2590 httpd_ClientTlsHsIn( cl );
2592 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT )
2594 httpd_ClientTlsHsOut( cl );
2597 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2598 cl->i_state == HTTPD_CLIENT_SENDING &&
2599 FD_ISSET( cl->fd, &fds_read ) )
2601 cl->b_read_waiting = VLC_TRUE;
2604 vlc_mutex_unlock( &host->lock );
2608 tls_ServerSessionClose( p_tls );
2611 #else /* ENABLE_HTTPD */
2613 /* We just define an empty wrapper */
2614 httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, char *b, int c,
2617 msg_Err( a, "HTTP daemon support is disabled" );
2620 httpd_host_t *httpd_HostNew( vlc_object_t *a, char *b, int c )
2622 msg_Err( a, "HTTP daemon support is disabled" );
2625 void httpd_HostDelete( httpd_host_t *a )
2628 httpd_url_t *httpd_UrlNew( httpd_host_t *host, char *psz_url,
2629 char *psz_user, char *psz_password,
2630 const vlc_acl_t *p_acl )
2634 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, char *psz_url,
2635 char *psz_user, char *psz_password,
2636 const vlc_acl_t *p_acl )
2640 int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c,
2641 httpd_callback_sys_t *d ){ return 0; }
2642 void httpd_UrlDelete( httpd_url_t *a ){}
2644 char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip ) { return NULL; }
2645 char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip ) { return NULL; }
2647 void httpd_ClientModeStream( httpd_client_t *a ){}
2648 void httpd_ClientModeBidir( httpd_client_t *a ){}
2650 void httpd_FileDelete( httpd_file_t *a ){}
2651 httpd_file_t *httpd_FileNew( httpd_host_t *a, char *b, char *c, char *d,
2652 char *e, httpd_file_callback_t f,
2653 httpd_file_sys_t *g ){ return 0; }
2655 httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
2656 const char *psz_user,
2657 const char *psz_password,
2658 const vlc_acl_t *p_acl,
2659 httpd_handler_callback_t pf_fill,
2660 httpd_handler_sys_t *p_sys )
2664 void httpd_HandlerDelete( httpd_handler_t *handler ) {}
2666 void httpd_RedirectDelete( httpd_redirect_t *a ){}
2667 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *a,
2668 char *b, char *c ){ return 0; }
2670 void httpd_StreamDelete( httpd_stream_t *a ){}
2671 int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2672 int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2673 httpd_stream_t *httpd_StreamNew( httpd_host_t *a, char *b, char *c,
2674 char *d, char *e ){ return 0; }
2676 void httpd_MsgInit ( httpd_message_t *a ){}
2677 void httpd_MsgAdd ( httpd_message_t *a, char *b, char *c, ... ){}
2678 char *httpd_MsgGet ( httpd_message_t *a, char *b ){ return 0; }
2679 void httpd_MsgClean( httpd_message_t *a ){}
2681 #endif /* ENABLE_HTTPD */