1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004-2005 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Remi Denis-Courmont <courmisch@via.ecp.fr>
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"
45 #if defined( UNDER_CE )
47 #elif defined( WIN32 )
48 # include <winsock2.h>
49 # include <ws2tcpip.h>
51 # include <netdb.h> /* hostent ... */
52 # include <sys/socket.h>
53 # include <netinet/in.h>
54 # ifdef HAVE_ARPA_INET_H
55 # include <arpa/inet.h> /* inet_ntoa(), inet_aton() */
59 #if defined(WIN32) && !defined(UNDER_CE)
60 static const struct in6_addr in6addr_any = {{IN6ADDR_ANY_INIT}};
61 #elif defined(UNDER_CE) && defined(AF_INET6)
66 # define PF_INET AF_INET /* BeOS */
70 typedef struct httpd_t httpd_t;
72 typedef struct httpd_host_t httpd_host_t;
73 typedef struct httpd_url_t httpd_url_t;
74 typedef struct httpd_client_t httpd_client_t;
83 /* channel communication */
99 /* just to track the count of MSG */
112 httpd_client_t *cl; /* NULL if not throught a connection e vlc internal */
124 char *psz_args; /* FIXME find a clean way to handle GET(psz_args) and POST(body) through the same code */
126 /* for rtp over rtsp */
136 int64_t i_body_offset;
142 typedef struct httpd_callback_sys_t httpd_callback_sys_t;
143 /* answer could be null, int this case no answer is requested */
144 typedef int (*httpd_callback_t)( httpd_callback_sys_t *, httpd_client_t *, httpd_message_t *answer, httpd_message_t *query );
147 /* create a new host */
148 httpd_host_t *httpd_HostNew( vlc_object_t *, char *psz_host, int i_port );
150 void httpd_HostDelete( httpd_host_t * );
152 /* register a new url */
153 httpd_url_t *httpd_UrlNew( httpd_host_t *, char *psz_url );
154 /* register callback on a url */
155 int httpd_UrlCatch( httpd_url_t *, int i_msg,
156 httpd_callback_t, httpd_callback_sys_t * );
158 void httpd_UrlDelete( httpd_url_t * );
161 void httpd_ClientModeStream( httpd_client_t *cl );
162 void httpd_ClientModeBidir( httpd_client_t *cl );
163 static void httpd_ClientClean( httpd_client_t *cl );
166 typedef struct httpd_file_t httpd_file_t;
167 typedef struct httpd_file_sys_t httpd_file_sys_t;
168 typedef int (*httpd_file_callback_t)( httpd_file_sys_t*, httpd_file_t *, uint8_t *psz_request, uint8_t **pp_data, int *pi_data );
169 httpd_file_t *httpd_FileNew( httpd_host_t *,
170 char *psz_url, char *psz_mime,
171 char *psz_user, char *psz_password,
172 httpd_file_callback_t pf_fill,
173 httpd_file_sys_t *p_sys );
174 void httpd_FileDelete( httpd_file_t * );
176 typedef struct httpd_redirect_t httpd_redirect_t;
177 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *, char *psz_url_dst, char *psz_url_src );
178 void httpd_RedirectDelete( httpd_redirect_t * );
181 typedef struct httpd_stream_t httpd_stream_t;
182 httpd_stream_t *httpd_StreamNew( httpd_host_t * );
183 int httpd_StreamHeader( httpd_stream_t *, uint8_t *p_data, int i_data );
184 int httpd_StreamSend( httpd_stream_t *, uint8_t *p_data, int i_data );
185 void httpd_StreamDelete( httpd_stream_t * );
188 /* Msg functions facilities */
189 void httpd_MsgInit( httpd_message_t * );
190 void httpd_MsgAdd( httpd_message_t *, char *psz_name, char *psz_value, ... );
191 /* return "" if not found. The string is not allocated */
192 char *httpd_MsgGet( httpd_message_t *, char *psz_name );
193 void httpd_MsgClean( httpd_message_t * );
201 /* vlc_mutex_t lock; */
207 static void httpd_ClientClean( httpd_client_t *cl );
209 /* each host run in his own thread */
219 /* address/port and socket for listening at connections */
220 struct sockaddr_storage sock;
226 /* all registered url (becarefull that 2 httpd_url_t could point at the same url)
227 * This will slow down the url research but make my live easier
228 * All url will have their cb trigger, but only the first one can answer
234 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;
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 char *httpd_MimeFromUrl( 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 Funtions: 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;
460 if( answer == NULL || query == NULL )
464 answer->i_proto = HTTPD_PROTO_HTTP;
465 answer->i_version= query->i_version;
466 answer->i_type = HTTPD_MSG_ANSWER;
468 answer->i_status = 200;
469 answer->psz_status = strdup( "OK" );
471 httpd_MsgAdd( answer, "Content-type", "%s", file->psz_mime );
472 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
474 if( query->i_type != HTTPD_MSG_HEAD )
476 char *psz_args = query->psz_args;
477 if( query->i_type == HTTPD_MSG_POST )
480 psz_args = query->p_body;
482 file->pf_fill( file->p_sys, file, psz_args, &answer->p_body,
485 /* We respect client request */
486 if( strcmp( httpd_MsgGet( &cl->query, "Connection" ), "" ) )
488 httpd_MsgAdd( answer, "Connection",
489 httpd_MsgGet( &cl->query, "Connection" ) );
492 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
498 httpd_file_t *httpd_FileNew( httpd_host_t *host,
499 char *psz_url, char *psz_mime,
500 char *psz_user, char *psz_password,
501 httpd_file_callback_t pf_fill,
502 httpd_file_sys_t *p_sys )
504 httpd_file_t *file = malloc( sizeof( httpd_file_t ) );
506 if( ( file->url = httpd_UrlNewUnique( host, psz_url, psz_user,
507 psz_password ) ) == NULL )
513 file->psz_url = strdup( psz_url );
514 if( psz_mime && *psz_mime )
516 file->psz_mime = strdup( psz_mime );
520 file->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
523 file->pf_fill = pf_fill;
526 httpd_UrlCatch( file->url, HTTPD_MSG_HEAD, httpd_FileCallBack,
527 (httpd_callback_sys_t*)file );
528 httpd_UrlCatch( file->url, HTTPD_MSG_GET, httpd_FileCallBack,
529 (httpd_callback_sys_t*)file );
530 httpd_UrlCatch( file->url, HTTPD_MSG_POST, httpd_FileCallBack,
531 (httpd_callback_sys_t*)file );
536 void httpd_FileDelete( httpd_file_t *file )
538 httpd_UrlDelete( file->url );
540 free( file->psz_url );
541 free( file->psz_mime );
546 /*****************************************************************************
547 * High Level Funtions: httpd_redirect_t
548 *****************************************************************************/
549 struct httpd_redirect_t
555 static int httpd_RedirectCallBack( httpd_callback_sys_t *p_sys,
556 httpd_client_t *cl, httpd_message_t *answer,
557 httpd_message_t *query )
559 httpd_redirect_t *rdir = (httpd_redirect_t*)p_sys;
562 if( answer == NULL || query == NULL )
566 answer->i_proto = query->i_proto;
567 answer->i_version= query->i_version;
568 answer->i_type = HTTPD_MSG_ANSWER;
569 answer->i_status = 301;
570 answer->psz_status = strdup( "Moved Permanently" );
572 p = answer->p_body = malloc( 1000 + strlen( rdir->psz_dst ) );
573 p += sprintf( p, "<html>\n" );
574 p += sprintf( p, "<head>\n" );
575 p += sprintf( p, "<title>Redirection</title>\n" );
576 p += sprintf( p, "</head>\n" );
577 p += sprintf( p, "<body>\n" );
578 p += sprintf( p, "<h1><center>You should be <a href=\"%s\">redirected</a></center></h1>\n", rdir->psz_dst );
579 p += sprintf( p, "<hr />\n" );
580 p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
581 p += sprintf( p, "</body>\n" );
582 p += sprintf( p, "</html>\n" );
583 answer->i_body = p - answer->p_body;
585 /* XXX check if it's ok or we need to set an absolute url */
586 httpd_MsgAdd( answer, "Location", "%s", rdir->psz_dst );
588 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
593 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, char *psz_url_dst,
596 httpd_redirect_t *rdir = malloc( sizeof( httpd_redirect_t ) );
598 if( !( rdir->url = httpd_UrlNewUnique( host, psz_url_src, NULL, NULL ) ) )
603 rdir->psz_dst = strdup( psz_url_dst );
605 /* Redirect apply for all HTTP request and RTSP DESCRIBE resquest */
606 httpd_UrlCatch( rdir->url, HTTPD_MSG_HEAD, httpd_RedirectCallBack,
607 (httpd_callback_sys_t*)rdir );
608 httpd_UrlCatch( rdir->url, HTTPD_MSG_GET, httpd_RedirectCallBack,
609 (httpd_callback_sys_t*)rdir );
610 httpd_UrlCatch( rdir->url, HTTPD_MSG_POST, httpd_RedirectCallBack,
611 (httpd_callback_sys_t*)rdir );
612 httpd_UrlCatch( rdir->url, HTTPD_MSG_DESCRIBE, httpd_RedirectCallBack,
613 (httpd_callback_sys_t*)rdir );
617 void httpd_RedirectDelete( httpd_redirect_t *rdir )
619 httpd_UrlDelete( rdir->url );
620 free( rdir->psz_dst );
624 /*****************************************************************************
625 * High Level Funtions: httpd_stream_t
626 *****************************************************************************/
627 struct httpd_stream_t
634 /* Header to send as first packet */
638 /* circular buffer */
639 int i_buffer_size; /* buffer size, can't be reallocated smaller */
640 uint8_t *p_buffer; /* buffer */
641 int64_t i_buffer_pos; /* absolute position from begining */
642 int64_t i_buffer_last_pos; /* a new connection will start with that */
645 static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
646 httpd_client_t *cl, httpd_message_t *answer,
647 httpd_message_t *query )
649 httpd_stream_t *stream = (httpd_stream_t*)p_sys;
651 if( answer == NULL || query == NULL || cl == NULL )
655 if( answer->i_body_offset > 0 )
661 fprintf( stderr, "httpd_StreamCallBack i_body_offset=%lld\n",
662 answer->i_body_offset );
665 if( answer->i_body_offset >= stream->i_buffer_pos )
667 /* fprintf( stderr, "httpd_StreamCallBack: no data\n" ); */
668 return VLC_EGENERIC; /* wait, no data available */
670 if( answer->i_body_offset + stream->i_buffer_size <
671 stream->i_buffer_pos )
673 /* this client isn't fast enough */
674 fprintf( stderr, "fixing i_body_offset (old=%lld new=%lld)\n",
675 answer->i_body_offset, stream->i_buffer_last_pos );
676 answer->i_body_offset = stream->i_buffer_last_pos;
679 i_pos = answer->i_body_offset % stream->i_buffer_size;
680 i_write = stream->i_buffer_pos - answer->i_body_offset;
681 if( i_write > 10000 )
685 else if( i_write <= 0 )
687 return VLC_EGENERIC; /* wait, no data available */
690 /* Don't go past the end of the circular buffer */
691 i_write = __MIN( i_write, stream->i_buffer_size - i_pos );
693 /* using HTTPD_MSG_ANSWER -> data available */
694 answer->i_proto = HTTPD_PROTO_HTTP;
695 answer->i_version= 0;
696 answer->i_type = HTTPD_MSG_ANSWER;
698 answer->i_body = i_write;
699 answer->p_body = malloc( i_write );
700 memcpy( answer->p_body, &stream->p_buffer[i_pos], i_write );
702 answer->i_body_offset += i_write;
708 answer->i_proto = HTTPD_PROTO_HTTP;
709 answer->i_version= 0;
710 answer->i_type = HTTPD_MSG_ANSWER;
712 answer->i_status = 200;
713 answer->psz_status = strdup( "OK" );
715 if( query->i_type != HTTPD_MSG_HEAD )
717 httpd_ClientModeStream( cl );
718 vlc_mutex_lock( &stream->lock );
719 /* Send the header */
720 if( stream->i_header > 0 )
722 answer->i_body = stream->i_header;
723 answer->p_body = malloc( stream->i_header );
724 memcpy( answer->p_body, stream->p_header, stream->i_header );
726 answer->i_body_offset = stream->i_buffer_last_pos;
727 vlc_mutex_unlock( &stream->lock );
731 httpd_MsgAdd( answer, "Content-Length", "%d", 0 );
732 answer->i_body_offset = 0;
735 if( !strcmp( stream->psz_mime, "video/x-ms-asf-stream" ) )
737 vlc_bool_t b_xplaystream = VLC_FALSE;
740 httpd_MsgAdd( answer, "Content-type", "%s",
741 "application/octet-stream" );
742 httpd_MsgAdd( answer, "Server", "Cougar 4.1.0.3921" );
743 httpd_MsgAdd( answer, "Pragma", "no-cache" );
744 httpd_MsgAdd( answer, "Pragma", "client-id=%d", rand()&0x7fff );
745 httpd_MsgAdd( answer, "Pragma", "features=\"broadcast\"" );
747 /* Check if there is a xPlayStrm=1 */
748 for( i = 0; i < query->i_name; i++ )
750 if( !strcasecmp( query->name[i], "Pragma" ) &&
751 strstr( query->value[i], "xPlayStrm=1" ) )
753 b_xplaystream = VLC_TRUE;
759 answer->i_body_offset = 0;
764 httpd_MsgAdd( answer, "Content-type", "%s", stream->psz_mime );
766 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
771 httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
772 char *psz_url, char *psz_mime,
773 char *psz_user, char *psz_password )
775 httpd_stream_t *stream = malloc( sizeof( httpd_stream_t ) );
777 if( ( stream->url = httpd_UrlNewUnique( host, psz_url, psz_user,
778 psz_password ) ) == NULL )
783 vlc_mutex_init( host, &stream->lock );
784 if( psz_mime && *psz_mime )
786 stream->psz_mime = strdup( psz_mime );
790 stream->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
792 stream->i_header = 0;
793 stream->p_header = NULL;
794 stream->i_buffer_size = 5000000; /* 5 Mo per stream */
795 stream->p_buffer = malloc( stream->i_buffer_size );
796 /* We set to 1 to make life simpler
797 * (this way i_body_offset can never be 0) */
798 stream->i_buffer_pos = 1;
799 stream->i_buffer_last_pos = 1;
801 httpd_UrlCatch( stream->url, HTTPD_MSG_HEAD, httpd_StreamCallBack,
802 (httpd_callback_sys_t*)stream );
803 httpd_UrlCatch( stream->url, HTTPD_MSG_GET, httpd_StreamCallBack,
804 (httpd_callback_sys_t*)stream );
805 httpd_UrlCatch( stream->url, HTTPD_MSG_POST, httpd_StreamCallBack,
806 (httpd_callback_sys_t*)stream );
811 int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
813 vlc_mutex_lock( &stream->lock );
814 if( stream->p_header )
816 free( stream->p_header );
817 stream->p_header = NULL;
819 stream->i_header = i_data;
822 stream->p_header = malloc( i_data );
823 memcpy( stream->p_header, p_data, i_data );
825 vlc_mutex_unlock( &stream->lock );
830 int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
835 if( i_data < 0 || p_data == NULL )
839 vlc_mutex_lock( &stream->lock );
841 /* save this pointer (to be used by new connection) */
842 stream->i_buffer_last_pos = stream->i_buffer_pos;
844 i_pos = stream->i_buffer_pos % stream->i_buffer_size;
850 i_copy = __MIN( i_count, stream->i_buffer_size - i_pos );
852 /* Ok, we can't go past the end of our buffer */
853 memcpy( &stream->p_buffer[i_pos], p_data, i_copy );
855 i_pos = ( i_pos + i_copy ) % stream->i_buffer_size;
860 stream->i_buffer_pos += i_data;
862 vlc_mutex_unlock( &stream->lock );
866 void httpd_StreamDelete( httpd_stream_t *stream )
868 httpd_UrlDelete( stream->url );
869 vlc_mutex_destroy( &stream->lock );
870 if( stream->psz_mime ) free( stream->psz_mime );
871 if( stream->p_header ) free( stream->p_header );
872 if( stream->p_buffer ) free( stream->p_buffer );
877 /*****************************************************************************
879 *****************************************************************************/
880 #define LISTEN_BACKLOG 100
882 #if defined(HAVE_GETNAMEINFO) && !defined(HAVE_GETADDRINFO)
884 * For now, VLC's configure script does not check for getaddrinfo(),
885 * but it should be present if getnameinfo() is (the opposite is untrue, with
886 * Debian potato as an example)
888 # define HAVE_GETADDRINFO 1
891 static void httpd_HostThread( httpd_host_t * );
892 static int GetAddrPort( const struct sockaddr_storage *p_ss );
894 #ifndef HAVE_GETADDRINFO
895 struct httpd_addrinfo
901 struct sockaddr *ai_addr;
903 struct httpd_addrinfo *ai_next;
905 # define addrinfo httpd_addrinfo
907 static int BuildAddr( struct sockaddr_in * p_socket,
908 const char * psz_address, int i_port );
912 /* create a new host */
913 httpd_host_t *httpd_HostNew( vlc_object_t *p_this, char *psz_host,
916 return httpd_TLSHostNew( p_this, psz_host, i_port, NULL );
919 httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, char *psz_host,
920 int i_port, tls_server_t *p_tls )
923 httpd_host_t *host = NULL;
926 struct addrinfo *res, *ptr;
929 #ifdef HAVE_GETADDRINFO
933 struct addrinfo hints;
935 memset( &hints, 0, sizeof( hints ) );
939 * For now, keep IPv4 by default. That said, it should be safe to use
940 * IPv6 by default *on the server side*, as, apart from NetBSD, most
941 * systems accept IPv4 clients on IPv6 listening sockets.
943 hints.ai_family = PF_INET;
947 /* Check if ipv4 or ipv6 were forced */
948 var_Create( p_this, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
949 var_Get( p_this, "ipv4", &val );
951 hints.ai_family = PF_INET;
953 var_Create( p_this, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
954 var_Get( p_this, "ipv6", &val );
956 hints.ai_family = PF_INET6;
958 hints.ai_socktype = SOCK_STREAM;
959 hints.ai_flags = AI_PASSIVE;
961 if (*psz_host == '\0')
964 snprintf( psz_port, sizeof( psz_port ), "%d", i_port );
965 psz_port[sizeof( psz_port ) - 1] = '\0';
967 if( getaddrinfo( psz_host, psz_port, &hints, &res ) )
969 msg_Err( p_this, "cannot resolve %s:%d", psz_host, i_port );
975 struct sockaddr_in sock;
976 struct httpd_addrinfo info;
978 info.ai_family = PF_INET;
979 info.ai_socktype = SOCK_STREAM;
980 info.ai_protocol = 0;
981 info.ai_addr = (struct sockaddr *)&sock;
982 info.ai_addrlen = sizeof( sock );
987 if( BuildAddr( &sock, psz_host, i_port ) )
989 msg_Err( p_this, "cannot build address for %s:%d", psz_host, i_port );
993 # define freeaddrinfo( r ) (void)0;
996 /* to be sure to avoid multiple creation */
997 var_Create( p_this->p_libvlc, "httpd_mutex", VLC_VAR_MUTEX );
998 var_Get( p_this->p_libvlc, "httpd_mutex", &lockval );
999 vlc_mutex_lock( lockval.p_address );
1001 if( !(httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE )) )
1003 msg_Info( p_this, "creating httpd" );
1004 if( ( httpd = vlc_object_create( p_this, VLC_OBJECT_HTTPD ) ) == NULL )
1006 vlc_mutex_unlock( lockval.p_address );
1007 freeaddrinfo( res );
1014 vlc_object_yield( httpd );
1015 vlc_object_attach( httpd, p_this->p_vlc );
1018 for( ptr = res; (ptr != NULL) && (fd == -1); ptr = ptr->ai_next )
1022 if( ((unsigned)ptr->ai_addrlen) > sizeof( struct sockaddr_storage ) )
1024 msg_Dbg( p_this, "socket address too big" );
1028 /* verify if it already exist */
1029 for( i = 0; i < httpd->i_host; i++ )
1031 if( GetAddrPort (&httpd->host[i]->sock) != i_port )
1034 /* Cannot re-use host if it uses TLS/SSL */
1035 if( httpd->host[i]->p_tls != NULL )
1039 if( httpd->host[i]->sock.ss_family == AF_INET6 )
1041 const struct sockaddr_in6 *p_hsock, *p_sock;
1043 p_hsock = (const struct sockaddr_in6 *)&httpd->host[i]->sock;
1044 p_sock = (const struct sockaddr_in6 *)ptr->ai_addr;
1046 if( memcmp( &p_hsock->sin6_addr, &in6addr_any,
1047 sizeof( struct in6_addr ) ) &&
1048 ( p_sock->sin6_family != AF_INET6 ||
1049 memcmp( &p_hsock->sin6_addr, &p_sock->sin6_addr,
1050 sizeof( struct in6_addr ) ) ) )
1051 continue; /* does not match */
1053 else if( ptr->ai_family == PF_INET6 )
1057 if( httpd->host[i]->sock.ss_family == AF_INET )
1059 const struct sockaddr_in *p_hsock, *p_sock;
1061 p_hsock = (const struct sockaddr_in *)&httpd->host[i]->sock;
1062 p_sock = (const struct sockaddr_in *)ptr->ai_addr;
1064 if( p_hsock->sin_addr.s_addr != INADDR_ANY &&
1065 ( p_sock->sin_family != AF_INET ||
1066 p_hsock->sin_addr.s_addr != p_sock->sin_addr.s_addr ) )
1067 continue; /* does not match */
1069 else if( ptr->ai_family == PF_INET )
1073 msg_Dbg( p_this, "host with unknown address family" );
1077 freeaddrinfo( res );
1080 host = httpd->host[i];
1083 vlc_mutex_unlock( lockval.p_address );
1085 msg_Dbg( p_this, "host already registered" );
1089 /* create the listening socket */
1090 fd = socket( ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol );
1097 if( setsockopt( fd, SOL_SOCKET, SO_REUSEADDR,
1098 (void *)&dummy, sizeof( dummy ) ) < 0 )
1100 msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR)" );
1105 if( bind( fd, ptr->ai_addr, ptr->ai_addrlen ) )
1107 msg_Err( p_this, "cannot bind socket" );
1110 /* set to non-blocking */
1111 #if defined( WIN32 ) || defined( UNDER_CE )
1113 unsigned long i_dummy = 1;
1114 if( ioctlsocket( fd, FIONBIO, &i_dummy ) != 0 )
1116 msg_Err( p_this, "cannot set socket to non-blocking mode" );
1122 unsigned int i_flags;
1123 if( ( i_flags = fcntl( fd, F_GETFL, 0 ) ) < 0 )
1125 msg_Err( p_this, "cannot F_GETFL socket" );
1128 if( fcntl( fd, F_SETFL, i_flags | O_NONBLOCK ) < 0 )
1130 msg_Err( p_this, "cannot F_SETFL O_NONBLOCK" );
1136 if( listen( fd, LISTEN_BACKLOG ) < 0 )
1138 msg_Err( p_this, "cannot listen socket" );
1152 freeaddrinfo( res );
1156 /* create the new host */
1157 host = vlc_object_create( p_this, sizeof( httpd_host_t ) );
1158 host->httpd = httpd;
1159 vlc_mutex_init( httpd, &host->lock );
1163 memcpy( &host->sock, ptr->ai_addr, ptr->ai_addrlen );
1164 host->i_sock_size = ptr->ai_addrlen;
1168 host->client = NULL;
1170 freeaddrinfo( res );
1171 host->p_tls = p_tls;
1173 /* create the thread */
1174 if( vlc_thread_create( host, "httpd host thread", httpd_HostThread,
1175 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
1177 msg_Err( p_this, "cannot spawn http host thread" );
1181 /* now add it to httpd */
1182 TAB_APPEND( httpd->i_host, httpd->host, host );
1183 vlc_mutex_unlock( lockval.p_address );
1188 vlc_mutex_unlock( lockval.p_address );
1195 vlc_mutex_destroy( &host->lock );
1196 vlc_object_destroy( host );
1199 /* TODO destroy no more used httpd TODO */
1200 vlc_object_release( httpd );
1205 void httpd_HostDelete( httpd_host_t *host )
1207 httpd_t *httpd = host->httpd;
1208 vlc_value_t lockval;
1211 msg_Dbg( host, "httpd_HostDelete" );
1213 var_Get( httpd->p_libvlc, "httpd_mutex", &lockval );
1214 vlc_mutex_lock( lockval.p_address );
1216 vlc_object_release( httpd );
1219 if( host->i_ref > 0 )
1222 vlc_mutex_unlock( lockval.p_address );
1223 msg_Dbg( host, "httpd_HostDelete: host still used" );
1226 TAB_REMOVE( httpd->i_host, httpd->host, host );
1228 msg_Dbg( host, "httpd_HostDelete: host removed from http" );
1231 vlc_thread_join( host );
1233 msg_Dbg( host, "httpd_HostDelete: host thread joined" );
1235 for( i = 0; i < host->i_url; i++ )
1237 msg_Err( host, "url still registered:%s", host->url[i]->psz_url );
1239 for( i = 0; i < host->i_client; i++ )
1241 httpd_client_t *cl = host->client[i];
1242 msg_Warn( host, "client still connected" );
1243 httpd_ClientClean( cl );
1244 TAB_REMOVE( host->i_client, host->client, cl );
1250 if( host->p_tls != NULL)
1251 tls_ServerDelete( host->p_tls );
1252 net_Close( host->fd );
1253 vlc_mutex_destroy( &host->lock );
1254 vlc_object_destroy( host );
1256 if( httpd->i_host <= 0 )
1258 msg_Info( httpd, "httpd doesn't reference any host, deleting" );
1259 vlc_object_detach( httpd );
1260 vlc_object_destroy( httpd );
1262 vlc_mutex_unlock( lockval.p_address );
1265 /* register a new url */
1266 static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, char *psz_url,
1267 char *psz_user, char *psz_password,
1268 vlc_bool_t b_check )
1273 vlc_mutex_lock( &host->lock );
1276 for( i = 0; i < host->i_url; i++ )
1278 if( !strcmp( psz_url, host->url[i]->psz_url ) )
1280 msg_Warn( host->httpd,
1281 "cannot add '%s' (url already defined)", psz_url );
1282 vlc_mutex_unlock( &host->lock );
1288 url = malloc( sizeof( httpd_url_t ) );
1291 vlc_mutex_init( host->httpd, &url->lock );
1292 url->psz_url = strdup( psz_url );
1293 url->psz_user = strdup( psz_user ? psz_user : "" );
1294 url->psz_password = strdup( psz_password ? psz_password : "" );
1295 for( i = 0; i < HTTPD_MSG_MAX; i++ )
1297 url->catch[i].cb = NULL;
1298 url->catch[i].p_sys = NULL;
1301 TAB_APPEND( host->i_url, host->url, url );
1302 vlc_mutex_unlock( &host->lock );
1307 httpd_url_t *httpd_UrlNew( httpd_host_t *host, char *psz_url,
1308 char *psz_user, char *psz_password )
1310 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1311 psz_password, VLC_FALSE );
1314 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, char *psz_url,
1315 char *psz_user, char *psz_password )
1317 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1318 psz_password, VLC_TRUE );
1321 /* register callback on a url */
1322 int httpd_UrlCatch( httpd_url_t *url, int i_msg, httpd_callback_t cb,
1323 httpd_callback_sys_t *p_sys )
1325 vlc_mutex_lock( &url->lock );
1326 url->catch[i_msg].cb = cb;
1327 url->catch[i_msg].p_sys= p_sys;
1328 vlc_mutex_unlock( &url->lock );
1335 void httpd_UrlDelete( httpd_url_t *url )
1337 httpd_host_t *host = url->host;
1340 vlc_mutex_lock( &host->lock );
1341 TAB_REMOVE( host->i_url, host->url, url );
1343 vlc_mutex_destroy( &url->lock );
1344 free( url->psz_url );
1345 free( url->psz_user );
1346 free( url->psz_password );
1348 for( i = 0; i < host->i_client; i++ )
1350 httpd_client_t *client = host->client[i];
1352 if( client->url == url )
1354 /* TODO complete it */
1355 msg_Warn( host, "force closing connections" );
1356 httpd_ClientClean( client );
1357 TAB_REMOVE( host->i_client, host->client, client );
1363 vlc_mutex_unlock( &host->lock );
1366 void httpd_MsgInit( httpd_message_t *msg )
1369 msg->i_type = HTTPD_MSG_NONE;
1370 msg->i_proto = HTTPD_PROTO_NONE;
1371 msg->i_version = -1;
1374 msg->psz_status = NULL;
1376 msg->psz_url = NULL;
1377 msg->psz_args = NULL;
1379 msg->i_channel = -1;
1386 msg->i_body_offset = 0;
1391 void httpd_MsgClean( httpd_message_t *msg )
1395 if( msg->psz_status )
1397 free( msg->psz_status );
1401 free( msg->psz_url );
1405 free( msg->psz_args );
1407 for( i = 0; i < msg->i_name; i++ )
1409 free( msg->name[i] );
1410 free( msg->value[i] );
1422 free( msg->p_body );
1424 httpd_MsgInit( msg );
1427 char *httpd_MsgGet( httpd_message_t *msg, char *name )
1431 for( i = 0; i < msg->i_name; i++ )
1433 if( !strcasecmp( msg->name[i], name ))
1435 return msg->value[i];
1440 void httpd_MsgAdd( httpd_message_t *msg, char *name, char *psz_value, ... )
1445 va_start( args, psz_value );
1446 #if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
1447 vasprintf( &value, psz_value, args );
1450 int i_size = strlen( psz_value ) + 4096; /* FIXME stupid system */
1451 value = calloc( i_size, sizeof( char ) );
1452 vsnprintf( value, i_size, psz_value, args );
1453 value[i_size - 1] = 0;
1458 name = strdup( name );
1460 TAB_APPEND( msg->i_name, msg->name, name );
1461 TAB_APPEND( msg->i_value, msg->value, value );
1464 static void httpd_ClientInit( httpd_client_t *cl )
1466 cl->i_state = HTTPD_CLIENT_RECEIVING;
1467 cl->i_activity_date = mdate();
1468 cl->i_activity_timeout = I64C(10000000);
1469 cl->i_buffer_size = 10000;
1471 cl->p_buffer = malloc( cl->i_buffer_size );
1472 cl->i_mode = HTTPD_CLIENT_FILE;
1473 cl->b_read_waiting = VLC_FALSE;
1475 httpd_MsgInit( &cl->query );
1476 httpd_MsgInit( &cl->answer );
1479 void httpd_ClientModeStream( httpd_client_t *cl )
1481 cl->i_mode = HTTPD_CLIENT_STREAM;
1484 void httpd_ClientModeBidir( httpd_client_t *cl )
1486 cl->i_mode = HTTPD_CLIENT_BIDIR;
1489 char* httpd_ClientIP( httpd_client_t *cl )
1491 #ifdef HAVE_GETNAMEINFO
1492 char sz_ip[INET6_ADDRSTRLEN + 2];
1495 if( (cl->sock.ss_family == AF_INET6) &&
1496 IN6_IS_ADDR_V4MAPPED( &((const struct sockaddr_in6 *)
1497 &cl->sock)->sin6_addr) )
1499 /* If client is using IPv4 but server is using IPv6 */
1500 struct sockaddr_in a;
1502 memset( &a, 0, sizeof( a ) );
1503 a.sin_family = AF_INET;
1504 a.sin_port = ((const struct sockaddr_in6 *)&cl->sock)->sin6_port;
1505 a.sin_addr.s_addr = ((const uint32_t *)&((const struct sockaddr_in6 *)
1506 &cl->sock)->sin6_addr)[3];
1507 i = getnameinfo( (const struct sockaddr *)&a, sizeof( a ),
1508 &sz_ip[1], INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST );
1511 i = getnameinfo( (const struct sockaddr *)&cl->sock, cl->i_sock_size,
1512 &sz_ip[1], INET6_ADDRSTRLEN, NULL, 0,
1516 /* FIXME: msg_Err */
1519 if( strchr( &sz_ip[1], ':' ) != NULL )
1522 i = strlen( sz_ip );
1526 return strdup( sz_ip );
1529 return strdup( &sz_ip[1] );
1532 /* FIXME not thread safe */
1533 return strdup( inet_ntoa( ((const struct sockaddr_in *)&cl->sock)->sin_addr ) );
1537 static void httpd_ClientClean( httpd_client_t *cl )
1541 if( cl->p_tls != NULL )
1542 tls_SessionClose( cl->p_tls );
1543 net_Close( cl->fd );
1547 httpd_MsgClean( &cl->answer );
1548 httpd_MsgClean( &cl->query );
1552 free( cl->p_buffer );
1553 cl->p_buffer = NULL;
1557 static httpd_client_t *httpd_ClientNew( int fd, struct sockaddr_storage *sock,
1559 tls_session_t *p_tls )
1561 httpd_client_t *cl = malloc( sizeof( httpd_client_t ) );
1564 memcpy( &cl->sock, sock, sizeof( cl->sock ) );
1565 cl->i_sock_size = i_sock_size;
1569 httpd_ClientInit( cl );
1575 static int httpd_NetRecv( httpd_client_t *cl, char *p, int i_len )
1577 tls_session_t *p_tls;
1581 return tls_Recv( p_tls, p, i_len );
1583 return recv( cl->fd, p, i_len, 0 );
1587 static int httpd_NetSend( httpd_client_t *cl, const char *p, int i_len )
1589 tls_session_t *p_tls;
1593 return tls_Send( p_tls, p, i_len );
1595 return send( cl->fd, p, i_len, 0 );
1599 static void httpd_ClientRecv( httpd_client_t *cl )
1603 if( cl->query.i_proto == HTTPD_PROTO_NONE )
1605 /* enought to see if it's rtp over rtsp or RTSP/HTTP */
1606 i_len = httpd_NetRecv( cl, &cl->p_buffer[cl->i_buffer],
1610 cl->i_buffer += i_len;
1613 if( cl->i_buffer >= 4 )
1615 fprintf( stderr, "peek=%4.4s\n", cl->p_buffer );
1617 if( cl->p_buffer[0] == '$' )
1619 /* RTSP (rtp over rtsp) */
1620 cl->query.i_proto = HTTPD_PROTO_RTSP;
1621 cl->query.i_type = HTTPD_MSG_CHANNEL;
1622 cl->query.i_channel = cl->p_buffer[1];
1623 cl->query.i_body = (cl->p_buffer[2] << 8)|cl->p_buffer[3];
1624 cl->query.p_body = malloc( cl->query.i_body );
1628 else if( !strncmp( cl->p_buffer, "HTTP", 4 ) )
1630 cl->query.i_proto = HTTPD_PROTO_HTTP;
1631 cl->query.i_type = HTTPD_MSG_ANSWER;
1633 else if( !strncmp( cl->p_buffer, "RTSP", 4 ) )
1635 cl->query.i_proto = HTTPD_PROTO_RTSP;
1636 cl->query.i_type = HTTPD_MSG_ANSWER;
1638 else if( !strncmp( cl->p_buffer, "GET", 3 ) ||
1639 !strncmp( cl->p_buffer, "HEAD", 4 ) ||
1640 !strncmp( cl->p_buffer, "POST", 4 ) )
1642 cl->query.i_proto = HTTPD_PROTO_HTTP;
1643 cl->query.i_type = HTTPD_MSG_NONE;
1647 cl->query.i_proto = HTTPD_PROTO_RTSP;
1648 cl->query.i_type = HTTPD_MSG_NONE;
1652 else if( cl->query.i_body > 0 )
1654 /* we are reading the body of a request or a channel */
1655 i_len = httpd_NetRecv( cl, &cl->query.p_body[cl->i_buffer],
1656 cl->query.i_body - cl->i_buffer );
1659 cl->i_buffer += i_len;
1661 if( cl->i_buffer >= cl->query.i_body )
1663 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1668 /* we are reading a header -> char by char */
1671 i_len = httpd_NetRecv (cl, &cl->p_buffer[cl->i_buffer], 1 );
1678 if( cl->i_buffer + 1 >= cl->i_buffer_size )
1680 cl->i_buffer_size += 1024;
1681 cl->p_buffer = realloc( cl->p_buffer, cl->i_buffer_size );
1683 if( ( cl->i_buffer >= 2 && !strncmp( &cl->p_buffer[cl->i_buffer-2], "\n\n", 2 ) )||
1684 ( cl->i_buffer >= 4 && !strncmp( &cl->p_buffer[cl->i_buffer-4], "\r\n\r\n", 4 ) ) )
1688 /* we have finished the header so parse it and set i_body */
1689 cl->p_buffer[cl->i_buffer] = '\0';
1691 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1693 cl->query.i_status =
1694 strtol( &cl->p_buffer[strlen( "HTTP/1.x" )], &p, 0 );
1699 cl->query.psz_status = strdup( p );
1711 { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP },
1712 { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP },
1713 { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP },
1715 { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP },
1716 { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP },
1717 { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP },
1718 { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP },
1719 { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP },
1720 { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP },
1722 { NULL, HTTPD_MSG_NONE, HTTPD_PROTO_NONE }
1727 cl->query.i_type = HTTPD_MSG_NONE;
1729 fprintf( stderr, "received new request=%s\n", cl->p_buffer);
1731 for( i = 0; msg_type[i].name != NULL; i++ )
1733 if( !strncmp( cl->p_buffer, msg_type[i].name,
1734 strlen( msg_type[i].name ) ) )
1736 p = &cl->p_buffer[strlen(msg_type[i].name) + 1 ];
1737 cl->query.i_type = msg_type[i].i_type;
1738 if( cl->query.i_proto != msg_type[i].i_proto )
1741 cl->query.i_proto = HTTPD_PROTO_NONE;
1742 cl->query.i_type = HTTPD_MSG_NONE;
1749 if( strstr( cl->p_buffer, "HTTP/1." ) )
1751 cl->query.i_proto = HTTPD_PROTO_HTTP;
1753 else if( strstr( cl->p_buffer, "RTSP/1." ) )
1755 cl->query.i_proto = HTTPD_PROTO_RTSP;
1767 p2 = strchr( p, ' ' );
1772 if( !strncasecmp( p, "rtsp:", 5 ) )
1774 /* for rtsp url, you have rtsp://localhost:port/path */
1776 while( *p == '/' ) p++;
1777 while( *p && *p != '/' ) p++;
1779 cl->query.psz_url = strdup( p );
1780 if( ( p3 = strchr( cl->query.psz_url, '?' ) ) )
1783 cl->query.psz_args = strdup( p3 );
1791 if( !strncasecmp( p2, "HTTP/1.", 7 ) )
1793 cl->query.i_proto = HTTPD_PROTO_HTTP;
1794 cl->query.i_version = atoi( p2+7 );
1796 else if( !strncasecmp( p2, "RTSP/1.", 7 ) )
1798 cl->query.i_proto = HTTPD_PROTO_RTSP;
1799 cl->query.i_version = atoi( p2+7 );
1807 p = strchr( p, '\n' );
1811 while( *p == '\n' || *p == '\r' )
1815 while( p && *p != '\0' )
1818 char *eol = p = strchr( p, '\n' );
1821 while( eol && eol >= line && ( *eol == '\n' || *eol == '\r' ) )
1826 if( ( colon = strchr( line, ':' ) ) )
1832 while( *colon == ' ' )
1836 name = strdup( line );
1837 value = strdup( colon );
1839 TAB_APPEND( cl->query.i_name, cl->query.name, name );
1840 TAB_APPEND( cl->query.i_value,cl->query.value,value);
1842 if( !strcasecmp( name, "Content-Length" ) )
1844 cl->query.i_body = atol( value );
1851 while( *p == '\n' || *p == '\r' )
1858 if( cl->query.i_body > 0 )
1860 /* TODO Mhh, handle the case client will only send a request and close the connection
1861 * to mark and of body (probably only RTSP) */
1862 cl->query.p_body = malloc( cl->query.i_body );
1867 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1873 /* check if the client is to be set to dead */
1874 #if defined( WIN32 ) || defined( UNDER_CE )
1875 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1877 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1880 if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE )
1882 /* connection closed -> end of data */
1883 if( cl->query.i_body > 0 )
1885 cl->query.i_body = cl->i_buffer;
1887 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1891 cl->i_state = HTTPD_CLIENT_DEAD;
1894 cl->i_activity_date = mdate();
1896 /* XXX: for QT I have to disable timeout. Try to find why */
1897 if( cl->query.i_proto == HTTPD_PROTO_RTSP )
1898 cl->i_activity_timeout = 0;
1900 /* Debugging only */
1901 if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
1905 fprintf( stderr, "received new request\n" );
1906 fprintf( stderr, " - proto=%s\n",
1907 cl->query.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP" );
1908 fprintf( stderr, " - version=%d\n", cl->query.i_version );
1909 fprintf( stderr, " - msg=%d\n", cl->query.i_type );
1910 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1912 fprintf( stderr, " - answer=%d '%s'\n", cl->query.i_status,
1913 cl->query.psz_status );
1915 else if( cl->query.i_type != HTTPD_MSG_NONE )
1917 fprintf( stderr, " - url=%s\n", cl->query.psz_url );
1919 for( i = 0; i < cl->query.i_name; i++ )
1921 fprintf( stderr, " - option name='%s' value='%s'\n",
1922 cl->query.name[i], cl->query.value[i] );
1928 static void httpd_ClientSend( httpd_client_t *cl )
1933 if( cl->i_buffer < 0 )
1935 /* We need to create the header */
1939 i_size = strlen( "HTTP/1.") + 10 + 10 +
1940 strlen( cl->answer.psz_status ? cl->answer.psz_status : "" ) + 5;
1941 for( i = 0; i < cl->answer.i_name; i++ )
1943 i_size += strlen( cl->answer.name[i] ) + 2 +
1944 strlen( cl->answer.value[i] ) + 2;
1947 if( cl->i_buffer_size < i_size )
1949 cl->i_buffer_size = i_size;
1950 free( cl->p_buffer );
1951 cl->p_buffer = malloc( i_size );
1955 p += sprintf( p, "%s/1.%d %d %s\r\n",
1956 cl->answer.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP",
1957 cl->answer.i_version,
1958 cl->answer.i_status, cl->answer.psz_status );
1959 for( i = 0; i < cl->answer.i_name; i++ )
1961 p += sprintf( p, "%s: %s\r\n", cl->answer.name[i],
1962 cl->answer.value[i] );
1964 p += sprintf( p, "\r\n" );
1967 cl->i_buffer_size = (uint8_t*)p - cl->p_buffer;
1969 fprintf( stderr, "sending answer\n" );
1970 fprintf( stderr, "%s", cl->p_buffer );
1973 i_len = httpd_NetSend( cl, &cl->p_buffer[cl->i_buffer],
1974 cl->i_buffer_size - cl->i_buffer );
1977 cl->i_activity_date = mdate();
1978 cl->i_buffer += i_len;
1980 if( cl->i_buffer >= cl->i_buffer_size )
1982 if( cl->answer.i_body == 0 && cl->answer.i_body_offset > 0 &&
1983 !cl->b_read_waiting )
1985 /* catch more body data */
1986 int i_msg = cl->query.i_type;
1987 int64_t i_offset = cl->answer.i_body_offset;
1989 httpd_MsgClean( &cl->answer );
1990 cl->answer.i_body_offset = i_offset;
1992 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
1993 &cl->answer, &cl->query );
1996 if( cl->answer.i_body > 0 )
1998 /* send the body data */
1999 free( cl->p_buffer );
2000 cl->p_buffer = cl->answer.p_body;
2001 cl->i_buffer_size = cl->answer.i_body;
2004 cl->answer.i_body = 0;
2005 cl->answer.p_body = NULL;
2010 cl->i_state = HTTPD_CLIENT_SEND_DONE;
2016 #if defined( WIN32 ) || defined( UNDER_CE )
2017 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
2019 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
2023 cl->i_state = HTTPD_CLIENT_DEAD;
2028 static void httpd_ClientTlsHsIn( httpd_client_t *cl )
2030 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2033 cl->i_state = HTTPD_CLIENT_RECEIVING;
2037 cl->i_state = HTTPD_CLIENT_DEAD;
2042 cl->i_state = HTTPD_CLIENT_TLS_HS_OUT;
2046 static void httpd_ClientTlsHsOut( httpd_client_t *cl )
2048 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2051 cl->i_state = HTTPD_CLIENT_RECEIVING;
2055 cl->i_state = HTTPD_CLIENT_DEAD;
2060 cl->i_state = HTTPD_CLIENT_TLS_HS_IN;
2065 static void httpd_HostThread( httpd_host_t *host )
2067 tls_session_t *p_tls = NULL;
2069 while( !host->b_die )
2071 struct timeval timeout;
2074 int i_handle_max = 0;
2077 int b_low_delay = 0;
2079 if( host->i_url <= 0 )
2086 /* built a set of handle to select */
2087 FD_ZERO( &fds_read );
2088 FD_ZERO( &fds_write );
2090 FD_SET( host->fd, &fds_read );
2091 i_handle_max = host->fd;
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()) ) ) )
2110 // FIXME: it sucks to allocate memory on the stack for debug
2111 ip = httpd_ClientIP( cl );
2112 msg_Dbg( host, "connection closed(%s)",
2113 (ip != NULL) ? ip : "unknown" );
2116 httpd_ClientClean( cl );
2117 TAB_REMOVE( host->i_client, host->client, cl );
2122 else if( ( cl->i_state == HTTPD_CLIENT_RECEIVING )
2123 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) )
2125 FD_SET( cl->fd, &fds_read );
2126 i_handle_max = __MAX( i_handle_max, cl->fd );
2128 else if( ( cl->i_state == HTTPD_CLIENT_SENDING )
2129 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) )
2131 FD_SET( cl->fd, &fds_write );
2132 i_handle_max = __MAX( i_handle_max, cl->fd );
2134 else if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
2136 httpd_message_t *answer = &cl->answer;
2137 httpd_message_t *query = &cl->query;
2138 int i_msg = query->i_type;
2140 httpd_MsgInit( answer );
2142 /* Handle what we received */
2143 if( cl->i_mode != HTTPD_CLIENT_BIDIR &&
2144 (i_msg == HTTPD_MSG_ANSWER || i_msg == HTTPD_MSG_CHANNEL) )
2146 /* we can only receive request from client when not
2149 cl->i_state = HTTPD_CLIENT_DEAD;
2151 else if( i_msg == HTTPD_MSG_ANSWER )
2153 /* We are in BIDIR mode, trigger the callback and then
2154 * check for new data */
2155 if( cl->url && cl->url->catch[i_msg].cb )
2157 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2160 cl->i_state = HTTPD_CLIENT_WAITING;
2162 else if( i_msg == HTTPD_MSG_CHANNEL )
2164 /* We are in BIDIR mode, trigger the callback and then
2165 * check for new data */
2166 if( cl->url && cl->url->catch[i_msg].cb )
2168 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2171 cl->i_state = HTTPD_CLIENT_WAITING;
2173 else if( i_msg == HTTPD_MSG_OPTIONS )
2178 answer->i_proto = query->i_proto ;
2179 answer->i_type = HTTPD_MSG_ANSWER;
2180 answer->i_version= 0;
2181 answer->i_status = 200;
2182 answer->psz_status = strdup( "Ok" );
2185 answer->p_body = NULL;
2187 i_cseq = atoi( httpd_MsgGet( query, "Cseq" ) );
2188 httpd_MsgAdd( answer, "Cseq", "%d", i_cseq );
2189 httpd_MsgAdd( answer, "Server", "VLC Server" );
2190 httpd_MsgAdd( answer, "Public", "DESCRIBE, SETUP, "
2191 "TEARDOWN, PLAY, PAUSE" );
2192 httpd_MsgAdd( answer, "Content-Length", "%d",
2195 cl->i_buffer = -1; /* Force the creation of the answer in
2196 * httpd_ClientSend */
2197 cl->i_state = HTTPD_CLIENT_SENDING;
2199 else if( i_msg == HTTPD_MSG_NONE )
2201 if( query->i_proto == HTTPD_PROTO_NONE )
2204 cl->i_state = HTTPD_CLIENT_DEAD;
2211 answer->i_proto = query->i_proto ;
2212 answer->i_type = HTTPD_MSG_ANSWER;
2213 answer->i_version= 0;
2214 answer->i_status = 501;
2215 answer->psz_status = strdup( "Unimplemented" );
2217 p = answer->p_body = malloc( 1000 );
2219 p += sprintf( p, "<html>\n" );
2220 p += sprintf( p, "<head>\n" );
2221 p += sprintf( p, "<title>Error 501</title>\n" );
2222 p += sprintf( p, "</head>\n" );
2223 p += sprintf( p, "<body>\n" );
2224 p += sprintf( p, "<h1><center> 501 Unimplemented</center></h1>\n" );
2225 p += sprintf( p, "<hr />\n" );
2226 p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
2227 p += sprintf( p, "</body>\n" );
2228 p += sprintf( p, "</html>\n" );
2230 answer->i_body = p - answer->p_body;
2231 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2233 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2234 cl->i_state = HTTPD_CLIENT_SENDING;
2239 vlc_bool_t b_auth_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->psz_user || *url->psz_password ) )
2253 /* create the headers */
2254 char *b64 = httpd_MsgGet( query, "Authorization" ); /* BASIC id */
2258 asprintf( &id, "%s:%s", url->psz_user, url->psz_password );
2259 auth = malloc( strlen(b64) + 1 );
2261 if( !strncasecmp( b64, "BASIC", 5 ) )
2264 while( *b64 == ' ' )
2268 b64_decode( auth, b64 );
2274 if( strcmp( id, auth ) )
2276 httpd_MsgAdd( answer, "WWW-Authenticate", "Basic realm=\"%s\"", url->psz_user );
2277 /* We fail for all url */
2278 b_auth_failed = VLC_TRUE;
2288 if( !url->catch[i_msg].cb( url->catch[i_msg].p_sys, cl, answer, query ) )
2290 /* only one url can answer */
2292 if( cl->url == NULL )
2304 answer->i_proto = query->i_proto;
2305 answer->i_type = HTTPD_MSG_ANSWER;
2306 answer->i_version= 0;
2307 p = answer->p_body = malloc( 1000 + strlen(query->psz_url) );
2311 answer->i_status = 401;
2312 answer->psz_status = strdup( "Authorization Required" );
2314 p += sprintf( p, "<html>\n" );
2315 p += sprintf( p, "<head>\n" );
2316 p += sprintf( p, "<title>Error 401</title>\n" );
2317 p += sprintf( p, "</head>\n" );
2318 p += sprintf( p, "<body>\n" );
2319 p += sprintf( p, "<h1><center> 401 Authorization Required (%s)</center></h1>\n", query->psz_url );
2320 p += sprintf( p, "<hr />\n" );
2321 p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
2322 p += sprintf( p, "</body>\n" );
2323 p += sprintf( p, "</html>\n" );
2327 /* no url registered */
2328 answer->i_status = 404;
2329 answer->psz_status = strdup( "Not found" );
2331 p += sprintf( p, "<html>\n" );
2332 p += sprintf( p, "<head>\n" );
2333 p += sprintf( p, "<title>Error 404</title>\n" );
2334 p += sprintf( p, "</head>\n" );
2335 p += sprintf( p, "<body>\n" );
2336 p += sprintf( p, "<h1><center> 404 Resource not found(%s)</center></h1>\n", query->psz_url );
2337 p += sprintf( p, "<hr />\n" );
2338 p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
2339 p += sprintf( p, "</body>\n" );
2340 p += sprintf( p, "</html>\n" );
2343 answer->i_body = p - answer->p_body;
2344 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2346 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2347 cl->i_state = HTTPD_CLIENT_SENDING;
2350 else if( cl->i_state == HTTPD_CLIENT_SEND_DONE )
2352 if( cl->i_mode == HTTPD_CLIENT_FILE || cl->answer.i_body_offset == 0 )
2355 if( ( cl->query.i_proto == HTTPD_PROTO_HTTP &&
2356 ( ( cl->answer.i_version == 0 && !strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Keep-Alive" ) ) ||
2357 ( cl->answer.i_version == 1 && strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) ) ) ||
2358 ( cl->query.i_proto == HTTPD_PROTO_RTSP &&
2359 strcasecmp( httpd_MsgGet( &cl->query, "Connection" ), "Close" ) &&
2360 strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) )
2362 httpd_MsgClean( &cl->query );
2363 httpd_MsgInit( &cl->query );
2366 cl->i_buffer_size = 1000;
2367 free( cl->p_buffer );
2368 cl->p_buffer = malloc( cl->i_buffer_size );
2369 cl->i_state = HTTPD_CLIENT_RECEIVING;
2373 cl->i_state = HTTPD_CLIENT_DEAD;
2375 httpd_MsgClean( &cl->answer );
2377 else if( cl->b_read_waiting )
2379 /* we have a message waiting for us to read it */
2380 httpd_MsgClean( &cl->answer );
2381 httpd_MsgClean( &cl->query );
2384 cl->i_buffer_size = 1000;
2385 free( cl->p_buffer );
2386 cl->p_buffer = malloc( cl->i_buffer_size );
2387 cl->i_state = HTTPD_CLIENT_RECEIVING;
2388 cl->b_read_waiting = VLC_FALSE;
2392 int64_t i_offset = cl->answer.i_body_offset;
2393 httpd_MsgClean( &cl->answer );
2395 cl->answer.i_body_offset = i_offset;
2396 free( cl->p_buffer );
2397 cl->p_buffer = NULL;
2399 cl->i_buffer_size = 0;
2401 cl->i_state = HTTPD_CLIENT_WAITING;
2404 else if( cl->i_state == HTTPD_CLIENT_WAITING )
2406 int64_t i_offset = cl->answer.i_body_offset;
2407 int i_msg = cl->query.i_type;
2409 httpd_MsgInit( &cl->answer );
2410 cl->answer.i_body_offset = i_offset;
2412 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
2413 &cl->answer, &cl->query );
2414 if( cl->answer.i_type != HTTPD_MSG_NONE )
2416 /* we have new data, so reenter send mode */
2418 cl->p_buffer = cl->answer.p_body;
2419 cl->i_buffer_size = cl->answer.i_body;
2420 cl->answer.p_body = NULL;
2421 cl->answer.i_body = 0;
2422 cl->i_state = HTTPD_CLIENT_SENDING;
2426 /* we shouldn't wait too long */
2427 b_low_delay = VLC_TRUE;
2431 /* Special for BIDIR mode we also check reading */
2432 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2433 cl->i_state == HTTPD_CLIENT_SENDING )
2435 FD_SET( cl->fd, &fds_read );
2436 i_handle_max = __MAX( i_handle_max, cl->fd );
2439 vlc_mutex_unlock( &host->lock );
2441 /* we will wait 100ms or 20ms (not too big 'cause HTTPD_CLIENT_WAITING) */
2443 timeout.tv_usec = b_low_delay ? 20000 : 100000;
2445 i_ret = select( i_handle_max + 1,
2446 &fds_read, &fds_write, NULL, &timeout );
2448 if( i_ret == -1 && errno != EINTR )
2450 msg_Warn( host, "cannot select sockets" );
2454 else if( i_ret <= 0 )
2459 /* accept new connections */
2460 if( FD_ISSET( host->fd, &fds_read ) )
2462 int i_sock_size = sizeof( struct sockaddr_storage );
2463 struct sockaddr_storage sock;
2466 fd = accept( host->fd, (struct sockaddr *)&sock, &i_sock_size );
2471 /* set this new socket non-block */
2472 #if defined( WIN32 ) || defined( UNDER_CE )
2474 unsigned long i_dummy = 1;
2475 ioctlsocket( fd, FIONBIO, &i_dummy );
2478 fcntl( fd, F_SETFL, O_NONBLOCK );
2483 switch ( tls_SessionHandshake( p_tls, fd ) )
2486 msg_Err( host, "Rejecting TLS connection" );
2492 case 1: /* missing input - most likely */
2493 i_state = HTTPD_CLIENT_TLS_HS_IN;
2496 case 2: /* missing output */
2497 i_state = HTTPD_CLIENT_TLS_HS_OUT;
2507 cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
2509 vlc_mutex_lock( &host->lock );
2510 TAB_APPEND( host->i_client, host->client, cl );
2511 vlc_mutex_unlock( &host->lock );
2514 cl->i_state = i_state; // override state for TLS
2516 // FIXME: it sucks to allocate memory for debug
2517 ip = httpd_ClientIP( cl );
2518 msg_Dbg( host, "new connection (%s)",
2519 ip != NULL ? ip : "unknown" );
2525 /* now try all others socket */
2526 vlc_mutex_lock( &host->lock );
2527 for( i_client = 0; i_client < host->i_client; i_client++ )
2529 httpd_client_t *cl = host->client[i_client];
2530 if( cl->i_state == HTTPD_CLIENT_RECEIVING )
2532 httpd_ClientRecv( cl );
2534 else if( cl->i_state == HTTPD_CLIENT_SENDING )
2536 httpd_ClientSend( cl );
2538 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN )
2540 httpd_ClientTlsHsIn( cl );
2542 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT )
2544 httpd_ClientTlsHsOut( cl );
2547 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2548 cl->i_state == HTTPD_CLIENT_SENDING &&
2549 FD_ISSET( cl->fd, &fds_read ) )
2551 cl->b_read_waiting = VLC_TRUE;
2554 vlc_mutex_unlock( &host->lock );
2558 #ifndef HAVE_GETADDRINFO
2559 static int BuildAddr( struct sockaddr_in * p_socket,
2560 const char * psz_address, int i_port )
2563 memset( p_socket, 0, sizeof( struct sockaddr_in ) );
2564 p_socket->sin_family = AF_INET; /* family */
2565 p_socket->sin_port = htons( (uint16_t)i_port );
2568 p_socket->sin_addr.s_addr = INADDR_ANY;
2572 struct hostent * p_hostent;
2574 /* Try to convert address directly from in_addr - this will work if
2575 * psz_address is dotted decimal. */
2576 #ifdef HAVE_ARPA_INET_H
2577 if( !inet_aton( psz_address, &p_socket->sin_addr ) )
2579 p_socket->sin_addr.s_addr = inet_addr( psz_address );
2581 /* if( p_socket->sin_addr.s_addr == INADDR_NONE )*/
2582 if( p_socket->sin_addr.s_addr == INADDR_BROADCAST )
2585 /* We have a fqdn, try to find its address */
2586 if ( (p_hostent = gethostbyname( psz_address )) == NULL )
2591 /* Copy the first address of the host in the socket address */
2592 memcpy( &((struct sockaddr_in *)p_socket)->sin_addr, p_hostent->h_addr_list[0],
2593 p_hostent->h_length );
2600 static int GetAddrPort( const struct sockaddr_storage *p_ss )
2604 switch (p_ss->ss_family)
2608 i_port = ((const struct sockaddr_in6 *)p_ss)->sin6_port;
2613 i_port = ((const struct sockaddr_in *)p_ss)->sin_port;
2620 return ntohs( i_port );
2623 #else /* ENABLE_HTTPD */
2625 /* We just define an empty wrapper */
2626 httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, char *b, int c,
2629 msg_Err( a, "HTTP daemon support is disabled" );
2632 httpd_host_t *httpd_HostNew( vlc_object_t *a, char *b, int c )
2634 msg_Err( a, "HTTP daemon support is disabled" );
2637 void httpd_HostDelete( httpd_host_t *a ){}
2638 httpd_url_t *httpd_UrlNew( httpd_host_t *a, char *b ){ return 0; }
2639 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *a, char *b, char *c,
2640 char *d ){ return 0; }
2641 int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c,
2642 httpd_callback_sys_t *d ){ return 0; }
2643 void httpd_UrlDelete( httpd_url_t *a ){}
2645 char *httpd_ClientIP( httpd_client_t *a ){ return 0; }
2646 void httpd_ClientModeStream( httpd_client_t *a ){}
2647 void httpd_ClientModeBidir( httpd_client_t *a ){}
2649 void httpd_FileDelete( httpd_file_t *a ){}
2650 httpd_file_t *httpd_FileNew( httpd_host_t *a, char *b, char *c, char *d,
2651 char *e, httpd_file_callback_t f,
2652 httpd_file_sys_t *g ){ return 0; }
2654 void httpd_RedirectDelete( httpd_redirect_t *a ){}
2655 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *a,
2656 char *b, char *c ){ return 0; }
2658 void httpd_StreamDelete( httpd_stream_t *a ){}
2659 int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2660 int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2661 httpd_stream_t *httpd_StreamNew( httpd_host_t *a, char *b, char *c,
2662 char *d, char *e ){ return 0; }
2664 void httpd_MsgInit ( httpd_message_t *a ){}
2665 void httpd_MsgAdd ( httpd_message_t *a, char *b, char *c, ... ){}
2666 char *httpd_MsgGet ( httpd_message_t *a, char *b ){ return 0; }
2667 void httpd_MsgClean( httpd_message_t *a ){}
2669 #endif /* ENABLE_HTTPD */