1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004-2005 VideoLAN
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * Remi 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"
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 static void httpd_HostThread( httpd_host_t * );
883 static int GetAddrPort( const struct sockaddr_storage *p_ss );
885 #ifndef HAVE_GETADDRINFO
886 struct httpd_addrinfo
892 struct sockaddr *ai_addr;
894 struct httpd_addrinfo *ai_next;
896 # define addrinfo httpd_addrinfo
898 static int BuildAddr( struct sockaddr_in * p_socket,
899 const char * psz_address, int i_port );
903 /* create a new host */
904 httpd_host_t *httpd_HostNew( vlc_object_t *p_this, char *psz_host,
907 return httpd_TLSHostNew( p_this, psz_host, i_port, NULL );
910 httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, char *psz_host,
911 int i_port, tls_server_t *p_tls )
914 httpd_host_t *host = NULL;
917 struct addrinfo *res, *ptr;
920 #ifdef HAVE_GETADDRINFO
924 struct addrinfo hints;
927 memset( &hints, 0, sizeof( hints ) );
929 /* Check if ipv4 or ipv6 were forced */
930 var_Create( p_this, "ipv4", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
931 var_Get( p_this, "ipv4", &val );
933 hints.ai_family = PF_INET;
935 var_Create( p_this, "ipv6", VLC_VAR_BOOL | VLC_VAR_DOINHERIT );
936 var_Get( p_this, "ipv6", &val );
938 hints.ai_family = PF_INET6;
940 hints.ai_socktype = SOCK_STREAM;
941 hints.ai_flags = AI_PASSIVE;
943 if (*psz_host == '\0')
946 snprintf( psz_port, sizeof( psz_port ), "%d", i_port );
947 psz_port[sizeof( psz_port ) - 1] = '\0';
949 check = getaddrinfo( psz_host, psz_port, &hints, &res );
952 #ifdef HAVE_GAI_STRERROR
953 msg_Err( p_this, "cannot resolve %s:%d : %s", psz_host, i_port,
954 gai_strerror( check ) );
956 msg_Err( p_this, "cannot resolve %s:%d", psz_host, i_port );
963 struct sockaddr_in sock;
964 struct httpd_addrinfo info;
966 info.ai_family = PF_INET;
967 info.ai_socktype = SOCK_STREAM;
968 info.ai_protocol = 0;
969 info.ai_addr = (struct sockaddr *)&sock;
970 info.ai_addrlen = sizeof( sock );
975 if( BuildAddr( &sock, psz_host, i_port ) )
977 msg_Err( p_this, "cannot build address for %s:%d", psz_host, i_port );
981 # define freeaddrinfo( r ) (void)0;
984 /* to be sure to avoid multiple creation */
985 var_Create( p_this->p_libvlc, "httpd_mutex", VLC_VAR_MUTEX );
986 var_Get( p_this->p_libvlc, "httpd_mutex", &lockval );
987 vlc_mutex_lock( lockval.p_address );
989 if( !(httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE )) )
991 msg_Info( p_this, "creating httpd" );
992 if( ( httpd = vlc_object_create( p_this, VLC_OBJECT_HTTPD ) ) == NULL )
994 vlc_mutex_unlock( lockval.p_address );
1002 vlc_object_yield( httpd );
1003 vlc_object_attach( httpd, p_this->p_vlc );
1006 for( ptr = res; (ptr != NULL) && (fd == -1); ptr = ptr->ai_next )
1010 if( ((unsigned)ptr->ai_addrlen) > sizeof( struct sockaddr_storage ) )
1012 msg_Dbg( p_this, "socket address too big" );
1016 /* verify if it already exist */
1017 for( i = 0; i < httpd->i_host; i++ )
1019 if( GetAddrPort (&httpd->host[i]->sock) != i_port )
1022 /* Cannot re-use host if it uses TLS/SSL */
1023 if( httpd->host[i]->p_tls != NULL )
1027 if( httpd->host[i]->sock.ss_family == AF_INET6 )
1029 const struct sockaddr_in6 *p_hsock, *p_sock;
1031 p_hsock = (const struct sockaddr_in6 *)&httpd->host[i]->sock;
1032 p_sock = (const struct sockaddr_in6 *)ptr->ai_addr;
1034 if( memcmp( &p_hsock->sin6_addr, &in6addr_any,
1035 sizeof( struct in6_addr ) ) &&
1036 ( p_sock->sin6_family != AF_INET6 ||
1037 memcmp( &p_hsock->sin6_addr, &p_sock->sin6_addr,
1038 sizeof( struct in6_addr ) ) ) )
1039 continue; /* does not match */
1041 else if( ptr->ai_family == PF_INET6 )
1045 if( httpd->host[i]->sock.ss_family == AF_INET )
1047 const struct sockaddr_in *p_hsock, *p_sock;
1049 p_hsock = (const struct sockaddr_in *)&httpd->host[i]->sock;
1050 p_sock = (const struct sockaddr_in *)ptr->ai_addr;
1052 if( p_hsock->sin_addr.s_addr != INADDR_ANY &&
1053 ( p_sock->sin_family != AF_INET ||
1054 p_hsock->sin_addr.s_addr != p_sock->sin_addr.s_addr ) )
1055 continue; /* does not match */
1057 else if( ptr->ai_family == PF_INET )
1061 msg_Dbg( p_this, "host with unknown address family" );
1065 freeaddrinfo( res );
1068 host = httpd->host[i];
1071 vlc_mutex_unlock( lockval.p_address );
1073 msg_Dbg( p_this, "host already registered" );
1077 /* create the listening socket */
1078 fd = socket( ptr->ai_family, ptr->ai_socktype, ptr->ai_protocol );
1085 if( setsockopt( fd, SOL_SOCKET, SO_REUSEADDR,
1086 (void *)&dummy, sizeof( dummy ) ) < 0 )
1088 msg_Warn( p_this, "cannot configure socket (SO_REUSEADDR)" );
1093 if( bind( fd, ptr->ai_addr, ptr->ai_addrlen ) )
1095 msg_Err( p_this, "cannot bind socket" );
1098 /* set to non-blocking */
1099 #if defined( WIN32 ) || defined( UNDER_CE )
1101 unsigned long i_dummy = 1;
1102 if( ioctlsocket( fd, FIONBIO, &i_dummy ) != 0 )
1104 msg_Err( p_this, "cannot set socket to non-blocking mode" );
1110 unsigned int i_flags;
1111 if( ( i_flags = fcntl( fd, F_GETFL, 0 ) ) < 0 )
1113 msg_Err( p_this, "cannot F_GETFL socket" );
1116 if( fcntl( fd, F_SETFL, i_flags | O_NONBLOCK ) < 0 )
1118 msg_Err( p_this, "cannot F_SETFL O_NONBLOCK" );
1124 if( listen( fd, LISTEN_BACKLOG ) < 0 )
1126 msg_Err( p_this, "cannot listen socket" );
1140 freeaddrinfo( res );
1144 /* create the new host */
1145 host = vlc_object_create( p_this, sizeof( httpd_host_t ) );
1146 host->httpd = httpd;
1147 vlc_mutex_init( httpd, &host->lock );
1151 memcpy( &host->sock, ptr->ai_addr, ptr->ai_addrlen );
1152 host->i_sock_size = ptr->ai_addrlen;
1156 host->client = NULL;
1158 freeaddrinfo( res );
1159 host->p_tls = p_tls;
1161 /* create the thread */
1162 if( vlc_thread_create( host, "httpd host thread", httpd_HostThread,
1163 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
1165 msg_Err( p_this, "cannot spawn http host thread" );
1169 /* now add it to httpd */
1170 TAB_APPEND( httpd->i_host, httpd->host, host );
1171 vlc_mutex_unlock( lockval.p_address );
1176 vlc_mutex_unlock( lockval.p_address );
1183 vlc_mutex_destroy( &host->lock );
1184 vlc_object_destroy( host );
1187 /* TODO destroy no more used httpd TODO */
1188 vlc_object_release( httpd );
1193 void httpd_HostDelete( httpd_host_t *host )
1195 httpd_t *httpd = host->httpd;
1196 vlc_value_t lockval;
1199 msg_Dbg( host, "httpd_HostDelete" );
1201 var_Get( httpd->p_libvlc, "httpd_mutex", &lockval );
1202 vlc_mutex_lock( lockval.p_address );
1204 vlc_object_release( httpd );
1207 if( host->i_ref > 0 )
1210 vlc_mutex_unlock( lockval.p_address );
1211 msg_Dbg( host, "httpd_HostDelete: host still used" );
1214 TAB_REMOVE( httpd->i_host, httpd->host, host );
1216 msg_Dbg( host, "httpd_HostDelete: host removed from http" );
1219 vlc_thread_join( host );
1221 msg_Dbg( host, "httpd_HostDelete: host thread joined" );
1223 for( i = 0; i < host->i_url; i++ )
1225 msg_Err( host, "url still registered:%s", host->url[i]->psz_url );
1227 for( i = 0; i < host->i_client; i++ )
1229 httpd_client_t *cl = host->client[i];
1230 msg_Warn( host, "client still connected" );
1231 httpd_ClientClean( cl );
1232 TAB_REMOVE( host->i_client, host->client, cl );
1238 if( host->p_tls != NULL)
1239 tls_ServerDelete( host->p_tls );
1240 net_Close( host->fd );
1241 vlc_mutex_destroy( &host->lock );
1242 vlc_object_destroy( host );
1244 if( httpd->i_host <= 0 )
1246 msg_Info( httpd, "httpd doesn't reference any host, deleting" );
1247 vlc_object_detach( httpd );
1248 vlc_object_destroy( httpd );
1250 vlc_mutex_unlock( lockval.p_address );
1253 /* register a new url */
1254 static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, char *psz_url,
1255 char *psz_user, char *psz_password,
1256 vlc_bool_t b_check )
1261 vlc_mutex_lock( &host->lock );
1264 for( i = 0; i < host->i_url; i++ )
1266 if( !strcmp( psz_url, host->url[i]->psz_url ) )
1268 msg_Warn( host->httpd,
1269 "cannot add '%s' (url already defined)", psz_url );
1270 vlc_mutex_unlock( &host->lock );
1276 url = malloc( sizeof( httpd_url_t ) );
1279 vlc_mutex_init( host->httpd, &url->lock );
1280 url->psz_url = strdup( psz_url );
1281 url->psz_user = strdup( psz_user ? psz_user : "" );
1282 url->psz_password = strdup( psz_password ? psz_password : "" );
1283 for( i = 0; i < HTTPD_MSG_MAX; i++ )
1285 url->catch[i].cb = NULL;
1286 url->catch[i].p_sys = NULL;
1289 TAB_APPEND( host->i_url, host->url, url );
1290 vlc_mutex_unlock( &host->lock );
1295 httpd_url_t *httpd_UrlNew( httpd_host_t *host, char *psz_url,
1296 char *psz_user, char *psz_password )
1298 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1299 psz_password, VLC_FALSE );
1302 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, char *psz_url,
1303 char *psz_user, char *psz_password )
1305 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1306 psz_password, VLC_TRUE );
1309 /* register callback on a url */
1310 int httpd_UrlCatch( httpd_url_t *url, int i_msg, httpd_callback_t cb,
1311 httpd_callback_sys_t *p_sys )
1313 vlc_mutex_lock( &url->lock );
1314 url->catch[i_msg].cb = cb;
1315 url->catch[i_msg].p_sys= p_sys;
1316 vlc_mutex_unlock( &url->lock );
1323 void httpd_UrlDelete( httpd_url_t *url )
1325 httpd_host_t *host = url->host;
1328 vlc_mutex_lock( &host->lock );
1329 TAB_REMOVE( host->i_url, host->url, url );
1331 vlc_mutex_destroy( &url->lock );
1332 free( url->psz_url );
1333 free( url->psz_user );
1334 free( url->psz_password );
1336 for( i = 0; i < host->i_client; i++ )
1338 httpd_client_t *client = host->client[i];
1340 if( client->url == url )
1342 /* TODO complete it */
1343 msg_Warn( host, "force closing connections" );
1344 httpd_ClientClean( client );
1345 TAB_REMOVE( host->i_client, host->client, client );
1351 vlc_mutex_unlock( &host->lock );
1354 void httpd_MsgInit( httpd_message_t *msg )
1357 msg->i_type = HTTPD_MSG_NONE;
1358 msg->i_proto = HTTPD_PROTO_NONE;
1359 msg->i_version = -1;
1362 msg->psz_status = NULL;
1364 msg->psz_url = NULL;
1365 msg->psz_args = NULL;
1367 msg->i_channel = -1;
1374 msg->i_body_offset = 0;
1379 void httpd_MsgClean( httpd_message_t *msg )
1383 if( msg->psz_status )
1385 free( msg->psz_status );
1389 free( msg->psz_url );
1393 free( msg->psz_args );
1395 for( i = 0; i < msg->i_name; i++ )
1397 free( msg->name[i] );
1398 free( msg->value[i] );
1410 free( msg->p_body );
1412 httpd_MsgInit( msg );
1415 char *httpd_MsgGet( httpd_message_t *msg, char *name )
1419 for( i = 0; i < msg->i_name; i++ )
1421 if( !strcasecmp( msg->name[i], name ))
1423 return msg->value[i];
1428 void httpd_MsgAdd( httpd_message_t *msg, char *name, char *psz_value, ... )
1433 va_start( args, psz_value );
1434 #if defined(HAVE_VASPRINTF) && !defined(SYS_DARWIN) && !defined(SYS_BEOS)
1435 vasprintf( &value, psz_value, args );
1438 int i_size = strlen( psz_value ) + 4096; /* FIXME stupid system */
1439 value = calloc( i_size, sizeof( char ) );
1440 vsnprintf( value, i_size, psz_value, args );
1441 value[i_size - 1] = 0;
1446 name = strdup( name );
1448 TAB_APPEND( msg->i_name, msg->name, name );
1449 TAB_APPEND( msg->i_value, msg->value, value );
1452 static void httpd_ClientInit( httpd_client_t *cl )
1454 cl->i_state = HTTPD_CLIENT_RECEIVING;
1455 cl->i_activity_date = mdate();
1456 cl->i_activity_timeout = I64C(10000000);
1457 cl->i_buffer_size = 10000;
1459 cl->p_buffer = malloc( cl->i_buffer_size );
1460 cl->i_mode = HTTPD_CLIENT_FILE;
1461 cl->b_read_waiting = VLC_FALSE;
1463 httpd_MsgInit( &cl->query );
1464 httpd_MsgInit( &cl->answer );
1467 void httpd_ClientModeStream( httpd_client_t *cl )
1469 cl->i_mode = HTTPD_CLIENT_STREAM;
1472 void httpd_ClientModeBidir( httpd_client_t *cl )
1474 cl->i_mode = HTTPD_CLIENT_BIDIR;
1477 char* httpd_ClientIP( httpd_client_t *cl )
1479 #ifdef HAVE_GETNAMEINFO
1480 char sz_ip[INET6_ADDRSTRLEN + 2];
1483 if( (cl->sock.ss_family == AF_INET6) &&
1484 IN6_IS_ADDR_V4MAPPED( &((const struct sockaddr_in6 *)
1485 &cl->sock)->sin6_addr) )
1487 /* If client is using IPv4 but server is using IPv6 */
1488 struct sockaddr_in a;
1490 memset( &a, 0, sizeof( a ) );
1491 a.sin_family = AF_INET;
1492 a.sin_port = ((const struct sockaddr_in6 *)&cl->sock)->sin6_port;
1493 a.sin_addr.s_addr = ((const uint32_t *)&((const struct sockaddr_in6 *)
1494 &cl->sock)->sin6_addr)[3];
1495 i = getnameinfo( (const struct sockaddr *)&a, sizeof( a ),
1496 &sz_ip[1], INET6_ADDRSTRLEN, NULL, 0, NI_NUMERICHOST );
1499 i = getnameinfo( (const struct sockaddr *)&cl->sock, cl->i_sock_size,
1500 &sz_ip[1], INET6_ADDRSTRLEN, NULL, 0,
1504 /* FIXME: msg_Err */
1507 if( strchr( &sz_ip[1], ':' ) != NULL )
1510 i = strlen( sz_ip );
1514 return strdup( sz_ip );
1517 return strdup( &sz_ip[1] );
1520 /* FIXME not thread safe */
1521 return strdup( inet_ntoa( ((const struct sockaddr_in *)&cl->sock)->sin_addr ) );
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, char *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 char *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 /* enought 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( !strncmp( cl->p_buffer, "HTTP", 4 ) )
1618 cl->query.i_proto = HTTPD_PROTO_HTTP;
1619 cl->query.i_type = HTTPD_MSG_ANSWER;
1621 else if( !strncmp( cl->p_buffer, "RTSP", 4 ) )
1623 cl->query.i_proto = HTTPD_PROTO_RTSP;
1624 cl->query.i_type = HTTPD_MSG_ANSWER;
1626 else if( !strncmp( cl->p_buffer, "GET", 3 ) ||
1627 !strncmp( cl->p_buffer, "HEAD", 4 ) ||
1628 !strncmp( 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 && !strncmp( &cl->p_buffer[cl->i_buffer-2], "\n\n", 2 ) )||
1672 ( cl->i_buffer >= 4 && !strncmp( &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 )
1681 cl->query.i_status =
1682 strtol( &cl->p_buffer[strlen( "HTTP/1.x" )], &p, 0 );
1687 cl->query.psz_status = strdup( p );
1699 { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP },
1700 { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP },
1701 { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP },
1703 { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP },
1704 { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP },
1705 { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP },
1706 { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP },
1707 { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP },
1708 { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP },
1710 { NULL, HTTPD_MSG_NONE, HTTPD_PROTO_NONE }
1715 cl->query.i_type = HTTPD_MSG_NONE;
1717 fprintf( stderr, "received new request=%s\n", cl->p_buffer);
1719 for( i = 0; msg_type[i].name != NULL; i++ )
1721 if( !strncmp( cl->p_buffer, msg_type[i].name,
1722 strlen( msg_type[i].name ) ) )
1724 p = &cl->p_buffer[strlen(msg_type[i].name) + 1 ];
1725 cl->query.i_type = msg_type[i].i_type;
1726 if( cl->query.i_proto != msg_type[i].i_proto )
1729 cl->query.i_proto = HTTPD_PROTO_NONE;
1730 cl->query.i_type = HTTPD_MSG_NONE;
1737 if( strstr( cl->p_buffer, "HTTP/1." ) )
1739 cl->query.i_proto = HTTPD_PROTO_HTTP;
1741 else if( strstr( cl->p_buffer, "RTSP/1." ) )
1743 cl->query.i_proto = HTTPD_PROTO_RTSP;
1755 p2 = strchr( p, ' ' );
1760 if( !strncasecmp( p, "rtsp:", 5 ) )
1762 /* for rtsp url, you have rtsp://localhost:port/path */
1764 while( *p == '/' ) p++;
1765 while( *p && *p != '/' ) p++;
1767 cl->query.psz_url = strdup( p );
1768 if( ( p3 = strchr( cl->query.psz_url, '?' ) ) )
1771 cl->query.psz_args = strdup( p3 );
1779 if( !strncasecmp( p2, "HTTP/1.", 7 ) )
1781 cl->query.i_proto = HTTPD_PROTO_HTTP;
1782 cl->query.i_version = atoi( p2+7 );
1784 else if( !strncasecmp( p2, "RTSP/1.", 7 ) )
1786 cl->query.i_proto = HTTPD_PROTO_RTSP;
1787 cl->query.i_version = atoi( p2+7 );
1795 p = strchr( p, '\n' );
1799 while( *p == '\n' || *p == '\r' )
1803 while( p && *p != '\0' )
1806 char *eol = p = strchr( p, '\n' );
1809 while( eol && eol >= line && ( *eol == '\n' || *eol == '\r' ) )
1814 if( ( colon = strchr( line, ':' ) ) )
1820 while( *colon == ' ' )
1824 name = strdup( line );
1825 value = strdup( colon );
1827 TAB_APPEND( cl->query.i_name, cl->query.name, name );
1828 TAB_APPEND( cl->query.i_value,cl->query.value,value);
1830 if( !strcasecmp( name, "Content-Length" ) )
1832 cl->query.i_body = atol( value );
1839 while( *p == '\n' || *p == '\r' )
1846 if( cl->query.i_body > 0 )
1848 /* TODO Mhh, handle the case client will only send a request and close the connection
1849 * to mark and of body (probably only RTSP) */
1850 cl->query.p_body = malloc( cl->query.i_body );
1855 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1861 /* check if the client is to be set to dead */
1862 #if defined( WIN32 ) || defined( UNDER_CE )
1863 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1865 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1868 if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE )
1870 /* connection closed -> end of data */
1871 if( cl->query.i_body > 0 )
1873 cl->query.i_body = cl->i_buffer;
1875 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1879 cl->i_state = HTTPD_CLIENT_DEAD;
1882 cl->i_activity_date = mdate();
1884 /* XXX: for QT I have to disable timeout. Try to find why */
1885 if( cl->query.i_proto == HTTPD_PROTO_RTSP )
1886 cl->i_activity_timeout = 0;
1888 /* Debugging only */
1889 if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
1893 fprintf( stderr, "received new request\n" );
1894 fprintf( stderr, " - proto=%s\n",
1895 cl->query.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP" );
1896 fprintf( stderr, " - version=%d\n", cl->query.i_version );
1897 fprintf( stderr, " - msg=%d\n", cl->query.i_type );
1898 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1900 fprintf( stderr, " - answer=%d '%s'\n", cl->query.i_status,
1901 cl->query.psz_status );
1903 else if( cl->query.i_type != HTTPD_MSG_NONE )
1905 fprintf( stderr, " - url=%s\n", cl->query.psz_url );
1907 for( i = 0; i < cl->query.i_name; i++ )
1909 fprintf( stderr, " - option name='%s' value='%s'\n",
1910 cl->query.name[i], cl->query.value[i] );
1916 static void httpd_ClientSend( httpd_client_t *cl )
1921 if( cl->i_buffer < 0 )
1923 /* We need to create the header */
1927 i_size = strlen( "HTTP/1.") + 10 + 10 +
1928 strlen( cl->answer.psz_status ? cl->answer.psz_status : "" ) + 5;
1929 for( i = 0; i < cl->answer.i_name; i++ )
1931 i_size += strlen( cl->answer.name[i] ) + 2 +
1932 strlen( cl->answer.value[i] ) + 2;
1935 if( cl->i_buffer_size < i_size )
1937 cl->i_buffer_size = i_size;
1938 free( cl->p_buffer );
1939 cl->p_buffer = malloc( i_size );
1943 p += sprintf( p, "%s/1.%d %d %s\r\n",
1944 cl->answer.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP",
1945 cl->answer.i_version,
1946 cl->answer.i_status, cl->answer.psz_status );
1947 for( i = 0; i < cl->answer.i_name; i++ )
1949 p += sprintf( p, "%s: %s\r\n", cl->answer.name[i],
1950 cl->answer.value[i] );
1952 p += sprintf( p, "\r\n" );
1955 cl->i_buffer_size = (uint8_t*)p - cl->p_buffer;
1957 fprintf( stderr, "sending answer\n" );
1958 fprintf( stderr, "%s", cl->p_buffer );
1961 i_len = httpd_NetSend( cl, &cl->p_buffer[cl->i_buffer],
1962 cl->i_buffer_size - cl->i_buffer );
1965 cl->i_activity_date = mdate();
1966 cl->i_buffer += i_len;
1968 if( cl->i_buffer >= cl->i_buffer_size )
1970 if( cl->answer.i_body == 0 && cl->answer.i_body_offset > 0 &&
1971 !cl->b_read_waiting )
1973 /* catch more body data */
1974 int i_msg = cl->query.i_type;
1975 int64_t i_offset = cl->answer.i_body_offset;
1977 httpd_MsgClean( &cl->answer );
1978 cl->answer.i_body_offset = i_offset;
1980 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
1981 &cl->answer, &cl->query );
1984 if( cl->answer.i_body > 0 )
1986 /* send the body data */
1987 free( cl->p_buffer );
1988 cl->p_buffer = cl->answer.p_body;
1989 cl->i_buffer_size = cl->answer.i_body;
1992 cl->answer.i_body = 0;
1993 cl->answer.p_body = NULL;
1998 cl->i_state = HTTPD_CLIENT_SEND_DONE;
2004 #if defined( WIN32 ) || defined( UNDER_CE )
2005 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
2007 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
2011 cl->i_state = HTTPD_CLIENT_DEAD;
2016 static void httpd_ClientTlsHsIn( httpd_client_t *cl )
2018 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2021 cl->i_state = HTTPD_CLIENT_RECEIVING;
2025 cl->i_state = HTTPD_CLIENT_DEAD;
2030 cl->i_state = HTTPD_CLIENT_TLS_HS_OUT;
2034 static void httpd_ClientTlsHsOut( httpd_client_t *cl )
2036 switch( tls_SessionContinueHandshake( cl->p_tls ) )
2039 cl->i_state = HTTPD_CLIENT_RECEIVING;
2043 cl->i_state = HTTPD_CLIENT_DEAD;
2048 cl->i_state = HTTPD_CLIENT_TLS_HS_IN;
2053 static void httpd_HostThread( httpd_host_t *host )
2055 tls_session_t *p_tls = NULL;
2057 while( !host->b_die )
2059 struct timeval timeout;
2062 int i_handle_max = 0;
2065 int b_low_delay = 0;
2067 if( host->i_url <= 0 )
2074 /* built a set of handle to select */
2075 FD_ZERO( &fds_read );
2076 FD_ZERO( &fds_write );
2078 FD_SET( host->fd, &fds_read );
2079 i_handle_max = host->fd;
2081 /* prepare a new TLS session */
2082 if( ( p_tls == NULL ) && ( host->p_tls != NULL ) )
2083 p_tls = tls_ServerSessionPrepare( host->p_tls );
2085 /* add all socket that should be read/write and close dead connection */
2086 vlc_mutex_lock( &host->lock );
2087 for( i_client = 0; i_client < host->i_client; i_client++ )
2089 httpd_client_t *cl = host->client[i_client];
2091 if( cl->i_ref < 0 || ( cl->i_ref == 0 &&
2092 ( cl->i_state == HTTPD_CLIENT_DEAD ||
2093 ( cl->i_activity_timeout > 0 &&
2094 cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
2098 // FIXME: it sucks to allocate memory on the stack for debug
2099 ip = httpd_ClientIP( cl );
2100 msg_Dbg( host, "connection closed(%s)",
2101 (ip != NULL) ? ip : "unknown" );
2104 httpd_ClientClean( cl );
2105 TAB_REMOVE( host->i_client, host->client, cl );
2110 else if( ( cl->i_state == HTTPD_CLIENT_RECEIVING )
2111 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) )
2113 FD_SET( cl->fd, &fds_read );
2114 i_handle_max = __MAX( i_handle_max, cl->fd );
2116 else if( ( cl->i_state == HTTPD_CLIENT_SENDING )
2117 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) )
2119 FD_SET( cl->fd, &fds_write );
2120 i_handle_max = __MAX( i_handle_max, cl->fd );
2122 else if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
2124 httpd_message_t *answer = &cl->answer;
2125 httpd_message_t *query = &cl->query;
2126 int i_msg = query->i_type;
2128 httpd_MsgInit( answer );
2130 /* Handle what we received */
2131 if( cl->i_mode != HTTPD_CLIENT_BIDIR &&
2132 (i_msg == HTTPD_MSG_ANSWER || i_msg == HTTPD_MSG_CHANNEL) )
2134 /* we can only receive request from client when not
2137 cl->i_state = HTTPD_CLIENT_DEAD;
2139 else if( i_msg == HTTPD_MSG_ANSWER )
2141 /* We are in BIDIR mode, trigger the callback and then
2142 * check for new data */
2143 if( cl->url && cl->url->catch[i_msg].cb )
2145 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2148 cl->i_state = HTTPD_CLIENT_WAITING;
2150 else if( i_msg == HTTPD_MSG_CHANNEL )
2152 /* We are in BIDIR mode, trigger the callback and then
2153 * check for new data */
2154 if( cl->url && cl->url->catch[i_msg].cb )
2156 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2159 cl->i_state = HTTPD_CLIENT_WAITING;
2161 else if( i_msg == HTTPD_MSG_OPTIONS )
2166 answer->i_proto = query->i_proto ;
2167 answer->i_type = HTTPD_MSG_ANSWER;
2168 answer->i_version= 0;
2169 answer->i_status = 200;
2170 answer->psz_status = strdup( "Ok" );
2173 answer->p_body = NULL;
2175 i_cseq = atoi( httpd_MsgGet( query, "Cseq" ) );
2176 httpd_MsgAdd( answer, "Cseq", "%d", i_cseq );
2177 httpd_MsgAdd( answer, "Server", "VLC Server" );
2178 httpd_MsgAdd( answer, "Public", "DESCRIBE, SETUP, "
2179 "TEARDOWN, PLAY, PAUSE" );
2180 httpd_MsgAdd( answer, "Content-Length", "%d",
2183 cl->i_buffer = -1; /* Force the creation of the answer in
2184 * httpd_ClientSend */
2185 cl->i_state = HTTPD_CLIENT_SENDING;
2187 else if( i_msg == HTTPD_MSG_NONE )
2189 if( query->i_proto == HTTPD_PROTO_NONE )
2192 cl->i_state = HTTPD_CLIENT_DEAD;
2199 answer->i_proto = query->i_proto ;
2200 answer->i_type = HTTPD_MSG_ANSWER;
2201 answer->i_version= 0;
2202 answer->i_status = 501;
2203 answer->psz_status = strdup( "Unimplemented" );
2205 p = answer->p_body = malloc( 1000 );
2207 p += sprintf( p, "<html>\n" );
2208 p += sprintf( p, "<head>\n" );
2209 p += sprintf( p, "<title>Error 501</title>\n" );
2210 p += sprintf( p, "</head>\n" );
2211 p += sprintf( p, "<body>\n" );
2212 p += sprintf( p, "<h1><center> 501 Unimplemented</center></h1>\n" );
2213 p += sprintf( p, "<hr />\n" );
2214 p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
2215 p += sprintf( p, "</body>\n" );
2216 p += sprintf( p, "</html>\n" );
2218 answer->i_body = p - answer->p_body;
2219 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2221 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2222 cl->i_state = HTTPD_CLIENT_SENDING;
2227 vlc_bool_t b_auth_failed = VLC_FALSE;
2230 /* Search the url and trigger callbacks */
2231 for( i = 0; i < host->i_url; i++ )
2233 httpd_url_t *url = host->url[i];
2235 if( !strcmp( url->psz_url, query->psz_url ) )
2237 if( url->catch[i_msg].cb )
2239 if( answer && ( *url->psz_user || *url->psz_password ) )
2241 /* create the headers */
2242 char *b64 = httpd_MsgGet( query, "Authorization" ); /* BASIC id */
2246 asprintf( &id, "%s:%s", url->psz_user, url->psz_password );
2247 auth = malloc( strlen(b64) + 1 );
2249 if( !strncasecmp( b64, "BASIC", 5 ) )
2252 while( *b64 == ' ' )
2256 b64_decode( auth, b64 );
2262 if( strcmp( id, auth ) )
2264 httpd_MsgAdd( answer, "WWW-Authenticate", "Basic realm=\"%s\"", url->psz_user );
2265 /* We fail for all url */
2266 b_auth_failed = VLC_TRUE;
2276 if( !url->catch[i_msg].cb( url->catch[i_msg].p_sys, cl, answer, query ) )
2278 /* only one url can answer */
2280 if( cl->url == NULL )
2292 answer->i_proto = query->i_proto;
2293 answer->i_type = HTTPD_MSG_ANSWER;
2294 answer->i_version= 0;
2295 p = answer->p_body = malloc( 1000 + strlen(query->psz_url) );
2299 answer->i_status = 401;
2300 answer->psz_status = strdup( "Authorization Required" );
2302 p += sprintf( p, "<html>\n" );
2303 p += sprintf( p, "<head>\n" );
2304 p += sprintf( p, "<title>Error 401</title>\n" );
2305 p += sprintf( p, "</head>\n" );
2306 p += sprintf( p, "<body>\n" );
2307 p += sprintf( p, "<h1><center> 401 Authorization Required (%s)</center></h1>\n", query->psz_url );
2308 p += sprintf( p, "<hr />\n" );
2309 p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
2310 p += sprintf( p, "</body>\n" );
2311 p += sprintf( p, "</html>\n" );
2315 /* no url registered */
2316 answer->i_status = 404;
2317 answer->psz_status = strdup( "Not found" );
2319 p += sprintf( p, "<html>\n" );
2320 p += sprintf( p, "<head>\n" );
2321 p += sprintf( p, "<title>Error 404</title>\n" );
2322 p += sprintf( p, "</head>\n" );
2323 p += sprintf( p, "<body>\n" );
2324 p += sprintf( p, "<h1><center> 404 Resource not found(%s)</center></h1>\n", query->psz_url );
2325 p += sprintf( p, "<hr />\n" );
2326 p += sprintf( p, "<a href=\"http://www.videolan.org\">VideoLAN</a>\n" );
2327 p += sprintf( p, "</body>\n" );
2328 p += sprintf( p, "</html>\n" );
2331 answer->i_body = p - answer->p_body;
2332 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2334 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2335 cl->i_state = HTTPD_CLIENT_SENDING;
2338 else if( cl->i_state == HTTPD_CLIENT_SEND_DONE )
2340 if( cl->i_mode == HTTPD_CLIENT_FILE || cl->answer.i_body_offset == 0 )
2343 if( ( cl->query.i_proto == HTTPD_PROTO_HTTP &&
2344 ( ( cl->answer.i_version == 0 && !strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Keep-Alive" ) ) ||
2345 ( cl->answer.i_version == 1 && strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) ) ) ||
2346 ( cl->query.i_proto == HTTPD_PROTO_RTSP &&
2347 strcasecmp( httpd_MsgGet( &cl->query, "Connection" ), "Close" ) &&
2348 strcasecmp( httpd_MsgGet( &cl->answer, "Connection" ), "Close" ) ) )
2350 httpd_MsgClean( &cl->query );
2351 httpd_MsgInit( &cl->query );
2354 cl->i_buffer_size = 1000;
2355 free( cl->p_buffer );
2356 cl->p_buffer = malloc( cl->i_buffer_size );
2357 cl->i_state = HTTPD_CLIENT_RECEIVING;
2361 cl->i_state = HTTPD_CLIENT_DEAD;
2363 httpd_MsgClean( &cl->answer );
2365 else if( cl->b_read_waiting )
2367 /* we have a message waiting for us to read it */
2368 httpd_MsgClean( &cl->answer );
2369 httpd_MsgClean( &cl->query );
2372 cl->i_buffer_size = 1000;
2373 free( cl->p_buffer );
2374 cl->p_buffer = malloc( cl->i_buffer_size );
2375 cl->i_state = HTTPD_CLIENT_RECEIVING;
2376 cl->b_read_waiting = VLC_FALSE;
2380 int64_t i_offset = cl->answer.i_body_offset;
2381 httpd_MsgClean( &cl->answer );
2383 cl->answer.i_body_offset = i_offset;
2384 free( cl->p_buffer );
2385 cl->p_buffer = NULL;
2387 cl->i_buffer_size = 0;
2389 cl->i_state = HTTPD_CLIENT_WAITING;
2392 else if( cl->i_state == HTTPD_CLIENT_WAITING )
2394 int64_t i_offset = cl->answer.i_body_offset;
2395 int i_msg = cl->query.i_type;
2397 httpd_MsgInit( &cl->answer );
2398 cl->answer.i_body_offset = i_offset;
2400 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
2401 &cl->answer, &cl->query );
2402 if( cl->answer.i_type != HTTPD_MSG_NONE )
2404 /* we have new data, so reenter send mode */
2406 cl->p_buffer = cl->answer.p_body;
2407 cl->i_buffer_size = cl->answer.i_body;
2408 cl->answer.p_body = NULL;
2409 cl->answer.i_body = 0;
2410 cl->i_state = HTTPD_CLIENT_SENDING;
2414 /* we shouldn't wait too long */
2415 b_low_delay = VLC_TRUE;
2419 /* Special for BIDIR mode we also check reading */
2420 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2421 cl->i_state == HTTPD_CLIENT_SENDING )
2423 FD_SET( cl->fd, &fds_read );
2424 i_handle_max = __MAX( i_handle_max, cl->fd );
2427 vlc_mutex_unlock( &host->lock );
2429 /* we will wait 100ms or 20ms (not too big 'cause HTTPD_CLIENT_WAITING) */
2431 timeout.tv_usec = b_low_delay ? 20000 : 100000;
2433 i_ret = select( i_handle_max + 1,
2434 &fds_read, &fds_write, NULL, &timeout );
2436 if( i_ret == -1 && errno != EINTR )
2438 msg_Warn( host, "cannot select sockets" );
2442 else if( i_ret <= 0 )
2447 /* accept new connections */
2448 if( FD_ISSET( host->fd, &fds_read ) )
2450 int i_sock_size = sizeof( struct sockaddr_storage );
2451 struct sockaddr_storage sock;
2454 fd = accept( host->fd, (struct sockaddr *)&sock, &i_sock_size );
2459 /* set this new socket non-block */
2460 #if defined( WIN32 ) || defined( UNDER_CE )
2462 unsigned long i_dummy = 1;
2463 ioctlsocket( fd, FIONBIO, &i_dummy );
2466 fcntl( fd, F_SETFL, O_NONBLOCK );
2471 switch ( tls_ServerSessionHandshake( p_tls, fd ) )
2474 msg_Err( host, "Rejecting TLS connection" );
2480 case 1: /* missing input - most likely */
2481 i_state = HTTPD_CLIENT_TLS_HS_IN;
2484 case 2: /* missing output */
2485 i_state = HTTPD_CLIENT_TLS_HS_OUT;
2495 cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
2497 vlc_mutex_lock( &host->lock );
2498 TAB_APPEND( host->i_client, host->client, cl );
2499 vlc_mutex_unlock( &host->lock );
2502 cl->i_state = i_state; // override state for TLS
2504 // FIXME: it sucks to allocate memory for debug
2505 ip = httpd_ClientIP( cl );
2506 msg_Dbg( host, "new connection (%s)",
2507 ip != NULL ? ip : "unknown" );
2513 /* now try all others socket */
2514 vlc_mutex_lock( &host->lock );
2515 for( i_client = 0; i_client < host->i_client; i_client++ )
2517 httpd_client_t *cl = host->client[i_client];
2518 if( cl->i_state == HTTPD_CLIENT_RECEIVING )
2520 httpd_ClientRecv( cl );
2522 else if( cl->i_state == HTTPD_CLIENT_SENDING )
2524 httpd_ClientSend( cl );
2526 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN )
2528 httpd_ClientTlsHsIn( cl );
2530 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT )
2532 httpd_ClientTlsHsOut( cl );
2535 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2536 cl->i_state == HTTPD_CLIENT_SENDING &&
2537 FD_ISSET( cl->fd, &fds_read ) )
2539 cl->b_read_waiting = VLC_TRUE;
2542 vlc_mutex_unlock( &host->lock );
2546 tls_ServerSessionClose( p_tls );
2549 #ifndef HAVE_GETADDRINFO
2550 static int BuildAddr( struct sockaddr_in * p_socket,
2551 const char * psz_address, int i_port )
2554 memset( p_socket, 0, sizeof( struct sockaddr_in ) );
2555 p_socket->sin_family = AF_INET; /* family */
2556 p_socket->sin_port = htons( (uint16_t)i_port );
2559 p_socket->sin_addr.s_addr = INADDR_ANY;
2563 struct hostent * p_hostent;
2565 /* Try to convert address directly from in_addr - this will work if
2566 * psz_address is dotted decimal. */
2567 #ifdef HAVE_ARPA_INET_H
2568 if( !inet_aton( psz_address, &p_socket->sin_addr ) )
2570 p_socket->sin_addr.s_addr = inet_addr( psz_address );
2572 /* if( p_socket->sin_addr.s_addr == INADDR_NONE )*/
2573 if( p_socket->sin_addr.s_addr == INADDR_BROADCAST )
2576 /* We have a fqdn, try to find its address */
2577 if ( (p_hostent = gethostbyname( psz_address )) == NULL )
2582 /* Copy the first address of the host in the socket address */
2583 memcpy( &((struct sockaddr_in *)p_socket)->sin_addr, p_hostent->h_addr_list[0],
2584 p_hostent->h_length );
2591 static int GetAddrPort( const struct sockaddr_storage *p_ss )
2595 switch (p_ss->ss_family)
2599 i_port = ((const struct sockaddr_in6 *)p_ss)->sin6_port;
2604 i_port = ((const struct sockaddr_in *)p_ss)->sin_port;
2611 return ntohs( i_port );
2614 #else /* ENABLE_HTTPD */
2616 /* We just define an empty wrapper */
2617 httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, char *b, int c,
2620 msg_Err( a, "HTTP daemon support is disabled" );
2623 httpd_host_t *httpd_HostNew( vlc_object_t *a, char *b, int c )
2625 msg_Err( a, "HTTP daemon support is disabled" );
2628 void httpd_HostDelete( httpd_host_t *a ){}
2629 httpd_url_t *httpd_UrlNew( httpd_host_t *a, char *b ){ return 0; }
2630 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *a, char *b, char *c,
2631 char *d ){ return 0; }
2632 int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c,
2633 httpd_callback_sys_t *d ){ return 0; }
2634 void httpd_UrlDelete( httpd_url_t *a ){}
2636 char *httpd_ClientIP( httpd_client_t *a ){ return 0; }
2637 void httpd_ClientModeStream( httpd_client_t *a ){}
2638 void httpd_ClientModeBidir( httpd_client_t *a ){}
2640 void httpd_FileDelete( httpd_file_t *a ){}
2641 httpd_file_t *httpd_FileNew( httpd_host_t *a, char *b, char *c, char *d,
2642 char *e, httpd_file_callback_t f,
2643 httpd_file_sys_t *g ){ return 0; }
2645 void httpd_RedirectDelete( httpd_redirect_t *a ){}
2646 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *a,
2647 char *b, char *c ){ return 0; }
2649 void httpd_StreamDelete( httpd_stream_t *a ){}
2650 int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2651 int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c ){ return 0; }
2652 httpd_stream_t *httpd_StreamNew( httpd_host_t *a, char *b, char *c,
2653 char *d, char *e ){ return 0; }
2655 void httpd_MsgInit ( httpd_message_t *a ){}
2656 void httpd_MsgAdd ( httpd_message_t *a, char *b, char *c, ... ){}
2657 char *httpd_MsgGet ( httpd_message_t *a, char *b ){ return 0; }
2658 void httpd_MsgClean( httpd_message_t *a ){}
2660 #endif /* ENABLE_HTTPD */