1 /*****************************************************************************
3 *****************************************************************************
4 * Copyright (C) 2004-2006 the VideoLAN team
7 * Authors: Laurent Aimar <fenrir@via.ecp.fr>
8 * RĂ©mi Denis-Courmont <rem # videolan.org>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23 *****************************************************************************/
32 #include "vlc_httpd.h"
48 #if defined( UNDER_CE )
50 #elif defined( WIN32 )
51 # include <winsock2.h>
53 # include <sys/socket.h>
57 /* We need HUGE buffer otherwise TCP throughput is very limited */
58 #define HTTPD_CL_BUFSIZE 1000000
60 #define HTTPD_CL_BUFSIZE 10000
63 static void httpd_ClientClean( httpd_client_t *cl );
79 httpd_callback_sys_t *p_sys;
80 } catch[HTTPD_MSG_MAX];
86 HTTPD_CLIENT_RECEIVING,
87 HTTPD_CLIENT_RECEIVE_DONE,
90 HTTPD_CLIENT_SEND_DONE,
96 HTTPD_CLIENT_TLS_HS_IN,
97 HTTPD_CLIENT_TLS_HS_OUT
103 HTTPD_CLIENT_FILE, /* default */
104 HTTPD_CLIENT_STREAM, /* regulary get data from cb */
105 HTTPD_CLIENT_BIDIR, /* check for reading and get data from cb */
108 struct httpd_client_t
114 struct sockaddr_storage sock;
120 int b_read_waiting; /* stop as soon as possible sending */
122 mtime_t i_activity_date;
123 mtime_t i_activity_timeout;
125 /* buffer for reading header */
131 httpd_message_t query; /* client -> httpd */
132 httpd_message_t answer; /* httpd -> client */
135 tls_session_t *p_tls;
139 /*****************************************************************************
141 *****************************************************************************/
142 /*char b64[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";*/
143 static void b64_decode( char *dest, char *src )
148 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 00-0F */
149 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 10-1F */
150 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,62,-1,-1,-1,63, /* 20-2F */
151 52,53,54,55,56,57,58,59,60,61,-1,-1,-1,-1,-1,-1, /* 30-3F */
152 -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,10,11,12,13,14, /* 40-4F */
153 15,16,17,18,19,20,21,22,23,24,25,-1,-1,-1,-1,-1, /* 50-5F */
154 -1,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40, /* 60-6F */
155 41,42,43,44,45,46,47,48,49,50,51,-1,-1,-1,-1,-1, /* 70-7F */
156 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 80-8F */
157 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* 90-9F */
158 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* A0-AF */
159 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* B0-BF */
160 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* C0-CF */
161 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* D0-DF */
162 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, /* E0-EF */
163 -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1 /* F0-FF */
166 for( i_level = 0; *src != '\0'; src++ )
170 c = b64[(unsigned int)*src];
182 *dest++ = ( last << 2 ) | ( ( c >> 4)&0x03 );
186 *dest++ = ( ( last << 4 )&0xf0 ) | ( ( c >> 2 )&0x0f );
190 *dest++ = ( ( last &0x03 ) << 6 ) | c;
202 const char *psz_mime;
205 { ".htm", "text/html" },
206 { ".html", "text/html" },
207 { ".txt", "text/plain" },
208 { ".xml", "text/xml" },
209 { ".dtd", "text/dtd" },
211 { ".css", "text/css" },
214 { ".gif", "image/gif" },
215 { ".jpe", "image/jpeg" },
216 { ".jpg", "image/jpeg" },
217 { ".jpeg", "image/jpeg" },
218 { ".png", "image/png" },
219 { ".mpjpeg","multipart/x-mixed-replace; boundary=This Random String" },
222 { ".avi", "video/avi" },
223 { ".asf", "video/x-ms-asf" },
224 { ".m1a", "audio/mpeg" },
225 { ".m2a", "audio/mpeg" },
226 { ".m1v", "video/mpeg" },
227 { ".m2v", "video/mpeg" },
228 { ".mp2", "audio/mpeg" },
229 { ".mp3", "audio/mpeg" },
230 { ".mpa", "audio/mpeg" },
231 { ".mpg", "video/mpeg" },
232 { ".mpeg", "video/mpeg" },
233 { ".mpe", "video/mpeg" },
234 { ".mov", "video/quicktime" },
235 { ".moov", "video/quicktime" },
236 { ".ogg", "application/ogg" },
237 { ".ogm", "application/ogg" },
238 { ".wav", "audio/wav" },
239 { ".wma", "audio/x-ms-wma" },
240 { ".wmv", "video/x-ms-wmv" },
247 static const char *httpd_MimeFromUrl( const char *psz_url )
252 psz_ext = strrchr( psz_url, '.' );
257 for( i = 0; http_mime[i].psz_ext != NULL ; i++ )
259 if( !strcasecmp( http_mime[i].psz_ext, psz_ext ) )
261 return http_mime[i].psz_mime;
265 return "application/octet-stream";
272 const char *psz_reason;
275 static const http_status_info http_reason[] =
277 /*{ 100, "Continue" },
278 { 101, "Switching Protocols" },*/
282 { 203, "Non-Authoritative Information" },
283 { 204, "No Content" },
284 { 205, "Reset Content"Â },
285 { 206, "Partial Content" },
286 { 250, "Low on Storage Space" },
287 { 300, "Multiple Choices" }*/,
288 { 301, "Moved Permanently" }/*,
289 { 302, "Moved Temporarily" }, - aka "Found"
290 { 303, "See Other" },
291 { 304, "Not Modified" },
292 { 305, "Use Proxy" },
293 { 307, "Temporary Redirect" },
294 { 400, "Bad Request" }*/,
295 { 401, "Unauthorized" }/*,
296 { 402, "Payment Required" }*/,
297 { 403, "Forbidden" },
298 { 404, "Not Found" }/*,
299 { 405, "Method Not Allowed" },
300 { 406, "Not Acceptable" },
301 { 407, "Proxy Authentication Required" },
302 { 408, "Request Time-out" },
305 { 411, "Length Required" },
306 { 412, "Precondition Failed" },
307 { 413, "Request Entity Too Large" },
308 { 414, "Request-URI Too Large" },
309 { 415, "Unsupported Media Type" },
310 { 416, "Requested range not satisfiable" },
311 { 417, "Expectation Failed" },
312 { 451, "Parameter Not Understood" },
313 { 452, "Conference Not Found" },
314 { 453, "Not Enough Bandwidth" }*/,
315 { 454, "Session Not Found" }/*,
316 { 455, "Method Not Valid in This State" },
317 { 456, "Header Field Not Valid for Resource" },
318 { 457, "Invalid Range" },
319 { 458, "Parameter Is Read-Only" },
320 { 459, "Aggregate operation not allowed" },
321 { 460, "Only aggregate operation allowed" }*/,
322 { 461, "Unsupported transport" }/*,
323 { 462, "Destination unreachable" }*/,
324 { 500, "Internal Server Error" },
325 { 501, "Not Implemented" }/*,
326 { 502, "Bad Gateway" }*/,
327 { 503, "Service Unavailable" }/*,
328 { 504, "Gateway Time-out" },
329 { 505, "Protocol version not supported" }*/,
333 static const char *psz_fallback_reason[] =
334 { "Continue", "OK", "Found", "Client Error", "Server Error" };
336 static const char *httpd_ReasonFromCode( int i_code )
338 const http_status_info *p;
340 for (p = http_reason; p->i_code < i_code; p++);
342 if( p->i_code == i_code )
343 return p->psz_reason;
345 assert( ( i_code >= 100 ) && ( i_code <= 599 ) );
346 return psz_fallback_reason[(i_code / 100) - 1];
350 /*****************************************************************************
351 * High Level Functions: httpd_file_t
352 *****************************************************************************/
360 httpd_file_callback_t pf_fill;
361 httpd_file_sys_t *p_sys;
365 static int httpd_FileCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, httpd_message_t *answer, httpd_message_t *query )
367 httpd_file_t *file = (httpd_file_t*)p_sys;
368 uint8_t *psz_args = query->psz_args;
369 uint8_t **pp_body, *p_body;
370 char *psz_connection = NULL;
371 int *pi_body, i_body;
373 if( answer == NULL || query == NULL )
377 answer->i_proto = HTTPD_PROTO_HTTP;
378 answer->i_version= query->i_version;
379 answer->i_type = HTTPD_MSG_ANSWER;
381 answer->i_status = 200;
382 answer->psz_status = strdup( "OK" );
384 httpd_MsgAdd( answer, "Content-type", "%s", file->psz_mime );
385 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
387 if( query->i_type != HTTPD_MSG_HEAD )
389 pp_body = &answer->p_body;
390 pi_body = &answer->i_body;
394 /* The file still needs to be executed. */
401 if( query->i_type == HTTPD_MSG_POST )
403 /* msg_Warn not supported */
406 file->pf_fill( file->p_sys, file, psz_args, pp_body, pi_body );
408 if( query->i_type == HTTPD_MSG_HEAD && p_body != NULL )
413 /* We respect client request */
414 psz_connection = httpd_MsgGet( &cl->query, "Connection" );
415 if( psz_connection != NULL )
417 httpd_MsgAdd( answer, "Connection", psz_connection );
420 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
425 httpd_file_t *httpd_FileNew( httpd_host_t *host,
426 const char *psz_url, const char *psz_mime,
427 const char *psz_user, const char *psz_password,
428 const vlc_acl_t *p_acl, httpd_file_callback_t pf_fill,
429 httpd_file_sys_t *p_sys )
431 httpd_file_t *file = malloc( sizeof( httpd_file_t ) );
433 if( ( file->url = httpd_UrlNewUnique( host, psz_url, psz_user,
434 psz_password, p_acl )
441 file->psz_url = strdup( psz_url );
442 if( psz_mime && *psz_mime )
444 file->psz_mime = strdup( psz_mime );
448 file->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
451 file->pf_fill = pf_fill;
454 httpd_UrlCatch( file->url, HTTPD_MSG_HEAD, httpd_FileCallBack,
455 (httpd_callback_sys_t*)file );
456 httpd_UrlCatch( file->url, HTTPD_MSG_GET, httpd_FileCallBack,
457 (httpd_callback_sys_t*)file );
458 httpd_UrlCatch( file->url, HTTPD_MSG_POST, httpd_FileCallBack,
459 (httpd_callback_sys_t*)file );
464 void httpd_FileDelete( httpd_file_t *file )
466 httpd_UrlDelete( file->url );
468 free( file->psz_url );
469 free( file->psz_mime );
474 /*****************************************************************************
475 * High Level Functions: httpd_handler_t (for CGIs)
476 *****************************************************************************/
477 struct httpd_handler_t
481 httpd_handler_callback_t pf_fill;
482 httpd_handler_sys_t *p_sys;
486 static int httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, httpd_message_t *answer, httpd_message_t *query )
488 httpd_handler_t *handler = (httpd_handler_t*)p_sys;
489 uint8_t *psz_args = query->psz_args;
490 char psz_remote_addr[NI_MAXNUMERICHOST];
492 if( answer == NULL || query == NULL )
496 answer->i_proto = HTTPD_PROTO_NONE;
497 answer->i_type = HTTPD_MSG_ANSWER;
499 /* We do it ourselves, thanks */
500 answer->i_status = 0;
501 answer->psz_status = NULL;
503 if( httpd_ClientIP( cl, psz_remote_addr ) == NULL )
504 *psz_remote_addr = '\0';
506 handler->pf_fill( handler->p_sys, handler, query->psz_url, psz_args,
507 query->i_type, query->p_body, query->i_body,
508 psz_remote_addr, NULL,
509 &answer->p_body, &answer->i_body );
511 if( query->i_type == HTTPD_MSG_HEAD )
513 char *p = (char *)answer->p_body;
514 while ( (p = strchr( p, '\r' )) != NULL )
516 if( p[1] && p[1] == '\n' && p[2] && p[2] == '\r'
517 && p[3] && p[3] == '\n' )
525 answer->i_body = strlen((char*)answer->p_body) + 1;
526 answer->p_body = realloc( answer->p_body, answer->i_body );
530 if( strncmp( (char *)answer->p_body, "HTTP/1.", 7 ) )
532 int i_status, i_headers;
533 char *psz_headers, *psz_new, *psz_status;
535 if( !strncmp( (char *)answer->p_body, "Status: ", 8 ) )
538 i_status = strtol( (char *)&answer->p_body[8], &psz_headers, 0 );
539 if( *psz_headers ) psz_headers++;
540 if( *psz_headers ) psz_headers++;
541 i_headers = answer->i_body - (psz_headers - (char *)answer->p_body);
546 psz_headers = (char *)answer->p_body;
547 i_headers = answer->i_body;
555 psz_status = "Unauthorized";
558 if( (i_status < 0) || (i_status > 999) )
560 psz_status = "Undefined";
563 answer->i_body = sizeof("HTTP/1.0 xxx \r\n")
564 + strlen(psz_status) + i_headers - 1;
565 psz_new = (char *)malloc( answer->i_body + 1);
566 sprintf( psz_new, "HTTP/1.0 %03d %s\r\n", i_status, psz_status );
567 memcpy( &psz_new[strlen(psz_new)], psz_headers, i_headers );
568 free( answer->p_body );
569 answer->p_body = (uint8_t *)psz_new;
575 httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
576 const char *psz_user,
577 const char *psz_password,
578 const vlc_acl_t *p_acl,
579 httpd_handler_callback_t pf_fill,
580 httpd_handler_sys_t *p_sys )
582 httpd_handler_t *handler = malloc( sizeof( httpd_handler_t ) );
584 if( ( handler->url = httpd_UrlNewUnique( host, psz_url, psz_user,
585 psz_password, p_acl )
592 handler->pf_fill = pf_fill;
593 handler->p_sys = p_sys;
595 httpd_UrlCatch( handler->url, HTTPD_MSG_HEAD, httpd_HandlerCallBack,
596 (httpd_callback_sys_t*)handler );
597 httpd_UrlCatch( handler->url, HTTPD_MSG_GET, httpd_HandlerCallBack,
598 (httpd_callback_sys_t*)handler );
599 httpd_UrlCatch( handler->url, HTTPD_MSG_POST, httpd_HandlerCallBack,
600 (httpd_callback_sys_t*)handler );
605 void httpd_HandlerDelete( httpd_handler_t *handler )
607 httpd_UrlDelete( handler->url );
611 /*****************************************************************************
612 * High Level Functions: httpd_redirect_t
613 *****************************************************************************/
614 struct httpd_redirect_t
620 static int httpd_RedirectCallBack( httpd_callback_sys_t *p_sys,
621 httpd_client_t *cl, httpd_message_t *answer,
622 httpd_message_t *query )
624 httpd_redirect_t *rdir = (httpd_redirect_t*)p_sys;
626 if( answer == NULL || query == NULL )
630 answer->i_proto = query->i_proto;
631 answer->i_version= query->i_version;
632 answer->i_type = HTTPD_MSG_ANSWER;
633 answer->i_status = 301;
634 answer->psz_status = strdup( "Moved Permanently" );
636 answer->i_body = asprintf( (char **)&answer->p_body,
637 "<?xml version=\"1.0\" encoding=\"ascii\" ?>\n"
638 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
639 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
642 "<title>Redirection</title>\n"
646 "<a href=\"%s\">redirected</a></h1>\n"
648 "<p><a href=\"http://www.videolan.org\">VideoLAN</a>\n</p>"
651 "</html>\n", rdir->psz_dst );
653 /* XXX check if it's ok or we need to set an absolute url */
654 httpd_MsgAdd( answer, "Location", "%s", rdir->psz_dst );
656 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
661 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst,
662 const char *psz_url_src )
664 httpd_redirect_t *rdir = malloc( sizeof( httpd_redirect_t ) );
666 if( !( rdir->url = httpd_UrlNewUnique( host, psz_url_src, NULL, NULL, NULL ) ) )
671 rdir->psz_dst = strdup( psz_url_dst );
673 /* Redirect apply for all HTTP request and RTSP DESCRIBE resquest */
674 httpd_UrlCatch( rdir->url, HTTPD_MSG_HEAD, httpd_RedirectCallBack,
675 (httpd_callback_sys_t*)rdir );
676 httpd_UrlCatch( rdir->url, HTTPD_MSG_GET, httpd_RedirectCallBack,
677 (httpd_callback_sys_t*)rdir );
678 httpd_UrlCatch( rdir->url, HTTPD_MSG_POST, httpd_RedirectCallBack,
679 (httpd_callback_sys_t*)rdir );
680 httpd_UrlCatch( rdir->url, HTTPD_MSG_DESCRIBE, httpd_RedirectCallBack,
681 (httpd_callback_sys_t*)rdir );
685 void httpd_RedirectDelete( httpd_redirect_t *rdir )
687 httpd_UrlDelete( rdir->url );
688 free( rdir->psz_dst );
692 /*****************************************************************************
693 * High Level Funtions: httpd_stream_t
694 *****************************************************************************/
695 struct httpd_stream_t
702 /* Header to send as first packet */
706 /* circular buffer */
707 int i_buffer_size; /* buffer size, can't be reallocated smaller */
708 uint8_t *p_buffer; /* buffer */
709 int64_t i_buffer_pos; /* absolute position from begining */
710 int64_t i_buffer_last_pos; /* a new connection will start with that */
713 static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
714 httpd_client_t *cl, httpd_message_t *answer,
715 httpd_message_t *query )
717 httpd_stream_t *stream = (httpd_stream_t*)p_sys;
719 if( answer == NULL || query == NULL || cl == NULL )
724 if( answer->i_body_offset > 0 )
730 fprintf( stderr, "httpd_StreamCallBack i_body_offset=%lld\n",
731 answer->i_body_offset );
734 if( answer->i_body_offset >= stream->i_buffer_pos )
736 /* fprintf( stderr, "httpd_StreamCallBack: no data\n" ); */
737 return VLC_EGENERIC; /* wait, no data available */
739 if( answer->i_body_offset + stream->i_buffer_size <
740 stream->i_buffer_pos )
742 /* this client isn't fast enough */
744 fprintf( stderr, "fixing i_body_offset (old=%lld new=%lld)\n",
745 answer->i_body_offset, stream->i_buffer_last_pos );
747 answer->i_body_offset = stream->i_buffer_last_pos;
750 i_pos = answer->i_body_offset % stream->i_buffer_size;
751 i_write = stream->i_buffer_pos - answer->i_body_offset;
752 if( i_write > HTTPD_CL_BUFSIZE )
754 i_write = HTTPD_CL_BUFSIZE;
756 else if( i_write <= 0 )
758 return VLC_EGENERIC; /* wait, no data available */
761 /* Don't go past the end of the circular buffer */
762 i_write = __MIN( i_write, stream->i_buffer_size - i_pos );
764 /* using HTTPD_MSG_ANSWER -> data available */
765 answer->i_proto = HTTPD_PROTO_HTTP;
766 answer->i_version= 0;
767 answer->i_type = HTTPD_MSG_ANSWER;
769 answer->i_body = i_write;
770 answer->p_body = malloc( i_write );
771 memcpy( answer->p_body, &stream->p_buffer[i_pos], i_write );
773 answer->i_body_offset += i_write;
779 answer->i_proto = HTTPD_PROTO_HTTP;
780 answer->i_version= 0;
781 answer->i_type = HTTPD_MSG_ANSWER;
783 answer->i_status = 200;
784 answer->psz_status = strdup( "OK" );
786 if( query->i_type != HTTPD_MSG_HEAD )
788 httpd_ClientModeStream( cl );
789 vlc_mutex_lock( &stream->lock );
790 /* Send the header */
791 if( stream->i_header > 0 )
793 answer->i_body = stream->i_header;
794 answer->p_body = malloc( stream->i_header );
795 memcpy( answer->p_body, stream->p_header, stream->i_header );
797 answer->i_body_offset = stream->i_buffer_last_pos;
798 vlc_mutex_unlock( &stream->lock );
802 httpd_MsgAdd( answer, "Content-Length", "%d", 0 );
803 answer->i_body_offset = 0;
806 if( !strcmp( stream->psz_mime, "video/x-ms-asf-stream" ) )
808 vlc_bool_t b_xplaystream = VLC_FALSE;
811 httpd_MsgAdd( answer, "Content-type", "%s",
812 "application/octet-stream" );
813 httpd_MsgAdd( answer, "Server", "Cougar 4.1.0.3921" );
814 httpd_MsgAdd( answer, "Pragma", "no-cache" );
815 httpd_MsgAdd( answer, "Pragma", "client-id=%d", rand()&0x7fff );
816 httpd_MsgAdd( answer, "Pragma", "features=\"broadcast\"" );
818 /* Check if there is a xPlayStrm=1 */
819 for( i = 0; i < query->i_name; i++ )
821 if( !strcasecmp( query->name[i], "Pragma" ) &&
822 strstr( query->value[i], "xPlayStrm=1" ) )
824 b_xplaystream = VLC_TRUE;
830 answer->i_body_offset = 0;
835 httpd_MsgAdd( answer, "Content-type", "%s", stream->psz_mime );
837 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
842 httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
843 const char *psz_url, const char *psz_mime,
844 const char *psz_user, const char *psz_password,
845 const vlc_acl_t *p_acl )
847 httpd_stream_t *stream = malloc( sizeof( httpd_stream_t ) );
849 if( ( stream->url = httpd_UrlNewUnique( host, psz_url, psz_user,
850 psz_password, p_acl )
856 vlc_mutex_init( host, &stream->lock );
857 if( psz_mime && *psz_mime )
859 stream->psz_mime = strdup( psz_mime );
863 stream->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
865 stream->i_header = 0;
866 stream->p_header = NULL;
867 stream->i_buffer_size = 5000000; /* 5 Mo per stream */
868 stream->p_buffer = malloc( stream->i_buffer_size );
869 /* We set to 1 to make life simpler
870 * (this way i_body_offset can never be 0) */
871 stream->i_buffer_pos = 1;
872 stream->i_buffer_last_pos = 1;
874 httpd_UrlCatch( stream->url, HTTPD_MSG_HEAD, httpd_StreamCallBack,
875 (httpd_callback_sys_t*)stream );
876 httpd_UrlCatch( stream->url, HTTPD_MSG_GET, httpd_StreamCallBack,
877 (httpd_callback_sys_t*)stream );
878 httpd_UrlCatch( stream->url, HTTPD_MSG_POST, httpd_StreamCallBack,
879 (httpd_callback_sys_t*)stream );
884 int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
886 vlc_mutex_lock( &stream->lock );
887 if( stream->p_header )
889 free( stream->p_header );
890 stream->p_header = NULL;
892 stream->i_header = i_data;
895 stream->p_header = malloc( i_data );
896 memcpy( stream->p_header, p_data, i_data );
898 vlc_mutex_unlock( &stream->lock );
903 int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
908 if( i_data < 0 || p_data == NULL )
912 vlc_mutex_lock( &stream->lock );
914 /* save this pointer (to be used by new connection) */
915 stream->i_buffer_last_pos = stream->i_buffer_pos;
917 i_pos = stream->i_buffer_pos % stream->i_buffer_size;
923 i_copy = __MIN( i_count, stream->i_buffer_size - i_pos );
925 /* Ok, we can't go past the end of our buffer */
926 memcpy( &stream->p_buffer[i_pos], p_data, i_copy );
928 i_pos = ( i_pos + i_copy ) % stream->i_buffer_size;
933 stream->i_buffer_pos += i_data;
935 vlc_mutex_unlock( &stream->lock );
939 void httpd_StreamDelete( httpd_stream_t *stream )
941 httpd_UrlDelete( stream->url );
942 vlc_mutex_destroy( &stream->lock );
943 if( stream->psz_mime ) free( stream->psz_mime );
944 if( stream->p_header ) free( stream->p_header );
945 if( stream->p_buffer ) free( stream->p_buffer );
949 /*****************************************************************************
951 *****************************************************************************/
952 static void httpd_HostThread( httpd_host_t * );
954 /* create a new host */
955 httpd_host_t *httpd_HostNew( vlc_object_t *p_this, const char *psz_host,
958 return httpd_TLSHostNew( p_this, psz_host, i_port, NULL, NULL, NULL, NULL
962 httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
964 const char *psz_cert, const char *psz_key,
965 const char *psz_ca, const char *psz_crl )
974 if( psz_hostname == NULL )
977 psz_host = strdup( psz_hostname );
978 if( psz_host == NULL )
980 msg_Err( p_this, "memory error" );
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 /* verify if it already exist */
1007 for( i = httpd->i_host - 1; i >= 0; i-- )
1009 host = httpd->host[i];
1011 /* cannot mix TLS and non-TLS hosts */
1012 if( ( ( httpd->host[i]->p_tls != NULL ) != ( psz_cert != NULL ) )
1013 || ( host->i_port != i_port )
1014 || strcmp( host->psz_hostname, psz_hostname ) )
1020 vlc_mutex_unlock( lockval.p_address );
1026 /* determine TLS configuration */
1027 if ( psz_cert != NULL )
1029 p_tls = tls_ServerCreate( p_this, psz_cert, psz_key );
1030 if ( p_tls == NULL )
1032 msg_Err( p_this, "TLS initialization error" );
1036 if ( ( psz_ca != NULL) && tls_ServerAddCA( p_tls, psz_ca ) )
1038 msg_Err( p_this, "TLS CA error" );
1042 if ( ( psz_crl != NULL) && tls_ServerAddCRL( p_tls, psz_crl ) )
1044 msg_Err( p_this, "TLS CRL error" );
1051 /* create the new host */
1052 host = vlc_object_create( p_this, VLC_OBJECT_HTTPD_HOST );
1053 host->httpd = httpd;
1054 vlc_mutex_init( httpd, &host->lock );
1057 host->fd = net_ListenTCP( p_this, psz_host, i_port );
1058 if( host->fd == NULL )
1060 msg_Err( p_this, "cannot create socket(s) for HTTP host" );
1064 host->i_port = i_port;
1065 host->psz_hostname = psz_host;
1070 host->client = NULL;
1072 host->p_tls = p_tls;
1074 /* create the thread */
1075 if( vlc_thread_create( host, "httpd host thread", httpd_HostThread,
1076 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
1078 msg_Err( p_this, "cannot spawn http host thread" );
1082 /* now add it to httpd */
1083 TAB_APPEND( httpd->i_host, httpd->host, host );
1084 vlc_mutex_unlock( lockval.p_address );
1090 if( httpd->i_host <= 0 )
1092 vlc_object_release( httpd );
1093 vlc_object_detach( httpd );
1094 vlc_object_destroy( httpd );
1096 vlc_mutex_unlock( lockval.p_address );
1100 net_ListenClose( host->fd );
1101 vlc_mutex_destroy( &host->lock );
1102 vlc_object_destroy( host );
1106 tls_ServerDelete( p_tls );
1112 void httpd_HostDelete( httpd_host_t *host )
1114 httpd_t *httpd = host->httpd;
1115 vlc_value_t lockval;
1118 var_Get( httpd->p_libvlc, "httpd_mutex", &lockval );
1119 vlc_mutex_lock( lockval.p_address );
1122 if( host->i_ref > 0 )
1125 vlc_mutex_unlock( lockval.p_address );
1126 msg_Dbg( host, "httpd_HostDelete: host still used" );
1129 TAB_REMOVE( httpd->i_host, httpd->host, host );
1132 vlc_thread_join( host );
1134 msg_Dbg( host, "HTTP host removed" );
1136 for( i = 0; i < host->i_url; i++ )
1138 msg_Err( host, "url still registered: %s", host->url[i]->psz_url );
1140 for( i = 0; i < host->i_client; i++ )
1142 httpd_client_t *cl = host->client[i];
1143 msg_Warn( host, "client still connected" );
1144 httpd_ClientClean( cl );
1145 TAB_REMOVE( host->i_client, host->client, cl );
1151 if( host->p_tls != NULL)
1152 tls_ServerDelete( host->p_tls );
1154 net_ListenClose( host->fd );
1155 free( host->psz_hostname );
1157 vlc_mutex_destroy( &host->lock );
1158 vlc_object_destroy( host );
1160 vlc_object_release( httpd );
1161 if( httpd->i_host <= 0 )
1163 msg_Dbg( httpd, "no host left, stopping httpd" );
1164 vlc_object_detach( httpd );
1165 vlc_object_destroy( httpd );
1167 vlc_mutex_unlock( lockval.p_address );
1170 /* register a new url */
1171 static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, const char *psz_url,
1172 const char *psz_user, const char *psz_password,
1173 const vlc_acl_t *p_acl, vlc_bool_t b_check )
1178 vlc_mutex_lock( &host->lock );
1181 for( i = 0; i < host->i_url; i++ )
1183 if( !strcmp( psz_url, host->url[i]->psz_url ) )
1185 msg_Warn( host->httpd,
1186 "cannot add '%s' (url already defined)", psz_url );
1187 vlc_mutex_unlock( &host->lock );
1193 url = malloc( sizeof( httpd_url_t ) );
1196 vlc_mutex_init( host->httpd, &url->lock );
1197 url->psz_url = strdup( psz_url );
1198 url->psz_user = strdup( psz_user ? psz_user : "" );
1199 url->psz_password = strdup( psz_password ? psz_password : "" );
1200 url->p_acl = ACL_Duplicate( host, p_acl );
1201 for( i = 0; i < HTTPD_MSG_MAX; i++ )
1203 url->catch[i].cb = NULL;
1204 url->catch[i].p_sys = NULL;
1207 TAB_APPEND( host->i_url, host->url, url );
1208 vlc_mutex_unlock( &host->lock );
1213 httpd_url_t *httpd_UrlNew( httpd_host_t *host, const char *psz_url,
1214 const char *psz_user, const char *psz_password,
1215 const vlc_acl_t *p_acl )
1217 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1218 psz_password, p_acl, VLC_FALSE );
1221 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, const char *psz_url,
1222 const char *psz_user, const char *psz_password,
1223 const vlc_acl_t *p_acl )
1225 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1226 psz_password, p_acl, VLC_TRUE );
1229 /* register callback on a url */
1230 int httpd_UrlCatch( httpd_url_t *url, int i_msg, httpd_callback_t cb,
1231 httpd_callback_sys_t *p_sys )
1233 vlc_mutex_lock( &url->lock );
1234 url->catch[i_msg].cb = cb;
1235 url->catch[i_msg].p_sys= p_sys;
1236 vlc_mutex_unlock( &url->lock );
1242 void httpd_UrlDelete( httpd_url_t *url )
1244 httpd_host_t *host = url->host;
1247 vlc_mutex_lock( &host->lock );
1248 TAB_REMOVE( host->i_url, host->url, url );
1250 vlc_mutex_destroy( &url->lock );
1251 free( url->psz_url );
1252 free( url->psz_user );
1253 free( url->psz_password );
1254 ACL_Destroy( url->p_acl );
1256 for( i = 0; i < host->i_client; i++ )
1258 httpd_client_t *client = host->client[i];
1260 if( client->url == url )
1262 /* TODO complete it */
1263 msg_Warn( host, "force closing connections" );
1264 httpd_ClientClean( client );
1265 TAB_REMOVE( host->i_client, host->client, client );
1271 vlc_mutex_unlock( &host->lock );
1274 void httpd_MsgInit( httpd_message_t *msg )
1277 msg->i_type = HTTPD_MSG_NONE;
1278 msg->i_proto = HTTPD_PROTO_NONE;
1279 msg->i_version = -1;
1282 msg->psz_status = NULL;
1284 msg->psz_url = NULL;
1285 msg->psz_args = NULL;
1287 msg->i_channel = -1;
1294 msg->i_body_offset = 0;
1299 void httpd_MsgClean( httpd_message_t *msg )
1303 if( msg->psz_status )
1305 free( msg->psz_status );
1309 free( msg->psz_url );
1313 free( msg->psz_args );
1315 for( i = 0; i < msg->i_name; i++ )
1317 free( msg->name[i] );
1318 free( msg->value[i] );
1330 free( msg->p_body );
1332 httpd_MsgInit( msg );
1335 char *httpd_MsgGet( httpd_message_t *msg, char *name )
1339 for( i = 0; i < msg->i_name; i++ )
1341 if( !strcasecmp( msg->name[i], name ))
1343 return msg->value[i];
1349 void httpd_MsgAdd( httpd_message_t *msg, char *name, char *psz_value, ... )
1354 va_start( args, psz_value );
1355 #if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined(SYS_BEOS)
1356 vasprintf( &value, psz_value, args );
1359 int i_size = strlen( psz_value ) + 4096; /* FIXME stupid system */
1360 value = calloc( i_size, sizeof( char ) );
1361 vsnprintf( value, i_size, psz_value, args );
1362 value[i_size - 1] = 0;
1367 name = strdup( name );
1369 TAB_APPEND( msg->i_name, msg->name, name );
1370 TAB_APPEND( msg->i_value, msg->value, value );
1373 static void httpd_ClientInit( httpd_client_t *cl )
1375 cl->i_state = HTTPD_CLIENT_RECEIVING;
1376 cl->i_activity_date = mdate();
1377 cl->i_activity_timeout = I64C(10000000);
1378 cl->i_buffer_size = HTTPD_CL_BUFSIZE;
1380 cl->p_buffer = malloc( cl->i_buffer_size );
1381 cl->i_mode = HTTPD_CLIENT_FILE;
1382 cl->b_read_waiting = VLC_FALSE;
1384 httpd_MsgInit( &cl->query );
1385 httpd_MsgInit( &cl->answer );
1388 void httpd_ClientModeStream( httpd_client_t *cl )
1390 cl->i_mode = HTTPD_CLIENT_STREAM;
1393 void httpd_ClientModeBidir( httpd_client_t *cl )
1395 cl->i_mode = HTTPD_CLIENT_BIDIR;
1398 char* httpd_ClientIP( const httpd_client_t *cl, char *psz_ip )
1400 return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1403 char* httpd_ServerIP( const httpd_client_t *cl, char *psz_ip )
1405 return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1408 static void httpd_ClientClean( httpd_client_t *cl )
1412 if( cl->p_tls != NULL )
1413 tls_ServerSessionClose( cl->p_tls );
1414 net_Close( cl->fd );
1418 httpd_MsgClean( &cl->answer );
1419 httpd_MsgClean( &cl->query );
1423 free( cl->p_buffer );
1424 cl->p_buffer = NULL;
1428 static httpd_client_t *httpd_ClientNew( int fd, struct sockaddr_storage *sock,
1430 tls_session_t *p_tls )
1432 httpd_client_t *cl = malloc( sizeof( httpd_client_t ) );
1434 if( !cl ) return NULL;
1438 memcpy( &cl->sock, sock, sizeof( cl->sock ) );
1439 cl->i_sock_size = i_sock_size;
1443 httpd_ClientInit( cl );
1448 static int httpd_NetRecv( httpd_client_t *cl, uint8_t *p, int i_len )
1450 tls_session_t *p_tls;
1454 return tls_Recv( p_tls, p, i_len );
1456 return recv( cl->fd, p, i_len, 0 );
1459 static int httpd_NetSend( httpd_client_t *cl, const uint8_t *p, int i_len )
1461 tls_session_t *p_tls;
1465 return tls_Send( p_tls, p, i_len );
1467 return send( cl->fd, p, i_len, 0 );
1470 static void httpd_ClientRecv( httpd_client_t *cl )
1474 if( cl->query.i_proto == HTTPD_PROTO_NONE )
1476 /* enough to see if it's rtp over rtsp or RTSP/HTTP */
1477 i_len = httpd_NetRecv( cl, &cl->p_buffer[cl->i_buffer],
1481 cl->i_buffer += i_len;
1484 if( cl->i_buffer >= 4 )
1486 /*fprintf( stderr, "peek=%4.4s\n", cl->p_buffer );*/
1488 if( cl->p_buffer[0] == '$' )
1490 /* RTSP (rtp over rtsp) */
1491 cl->query.i_proto = HTTPD_PROTO_RTSP;
1492 cl->query.i_type = HTTPD_MSG_CHANNEL;
1493 cl->query.i_channel = cl->p_buffer[1];
1494 cl->query.i_body = (cl->p_buffer[2] << 8)|cl->p_buffer[3];
1495 cl->query.p_body = malloc( cl->query.i_body );
1499 else if( !memcmp( cl->p_buffer, "HTTP", 4 ) )
1501 cl->query.i_proto = HTTPD_PROTO_HTTP;
1502 cl->query.i_type = HTTPD_MSG_ANSWER;
1504 else if( !memcmp( cl->p_buffer, "RTSP", 4 ) )
1506 cl->query.i_proto = HTTPD_PROTO_RTSP;
1507 cl->query.i_type = HTTPD_MSG_ANSWER;
1509 else if( !memcmp( cl->p_buffer, "GET ", 4 ) ||
1510 !memcmp( cl->p_buffer, "HEAD", 4 ) ||
1511 !memcmp( cl->p_buffer, "POST", 4 ) )
1513 cl->query.i_proto = HTTPD_PROTO_HTTP;
1514 cl->query.i_type = HTTPD_MSG_NONE;
1518 cl->query.i_proto = HTTPD_PROTO_RTSP;
1519 cl->query.i_type = HTTPD_MSG_NONE;
1523 else if( cl->query.i_body > 0 )
1525 /* we are reading the body of a request or a channel */
1526 i_len = httpd_NetRecv( cl, &cl->query.p_body[cl->i_buffer],
1527 cl->query.i_body - cl->i_buffer );
1530 cl->i_buffer += i_len;
1532 if( cl->i_buffer >= cl->query.i_body )
1534 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1539 /* we are reading a header -> char by char */
1542 i_len = httpd_NetRecv (cl, &cl->p_buffer[cl->i_buffer], 1 );
1549 if( cl->i_buffer + 1 >= cl->i_buffer_size )
1551 cl->i_buffer_size += 1024;
1552 cl->p_buffer = realloc( cl->p_buffer, cl->i_buffer_size );
1554 if( ( cl->i_buffer >= 2 && !memcmp( &cl->p_buffer[cl->i_buffer-2], "\n\n", 2 ) )||
1555 ( cl->i_buffer >= 4 && !memcmp( &cl->p_buffer[cl->i_buffer-4], "\r\n\r\n", 4 ) ) )
1559 /* we have finished the header so parse it and set i_body */
1560 cl->p_buffer[cl->i_buffer] = '\0';
1562 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1565 * assume strlen( "HTTP/1.x" ) = 8
1567 cl->query.i_status =
1568 strtol( (char *)&cl->p_buffer[8],
1574 cl->query.psz_status = strdup( p );
1586 { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP },
1587 { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP },
1588 { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP },
1589 { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP },
1590 { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP },
1591 { "GET_PARAMETER", HTTPD_MSG_GETPARAMETER, HTTPD_PROTO_RTSP },
1592 { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP },
1594 { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP },
1595 { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP },
1596 { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP },
1598 { NULL, HTTPD_MSG_NONE, HTTPD_PROTO_NONE }
1603 cl->query.i_type = HTTPD_MSG_NONE;
1605 /*fprintf( stderr, "received new request=%s\n", cl->p_buffer);*/
1607 for( i = 0; msg_type[i].name != NULL; i++ )
1609 if( !strncmp( (char *)cl->p_buffer, msg_type[i].name,
1610 strlen( msg_type[i].name ) ) )
1612 p = (char *)&cl->p_buffer[strlen((char *)msg_type[i].name) + 1 ];
1613 cl->query.i_type = msg_type[i].i_type;
1614 if( cl->query.i_proto != msg_type[i].i_proto )
1617 cl->query.i_proto = HTTPD_PROTO_NONE;
1618 cl->query.i_type = HTTPD_MSG_NONE;
1625 if( strstr( (char *)cl->p_buffer, "HTTP/1." ) )
1627 cl->query.i_proto = HTTPD_PROTO_HTTP;
1629 else if( strstr( (char *)cl->p_buffer, "RTSP/1." ) )
1631 cl->query.i_proto = HTTPD_PROTO_RTSP;
1643 p2 = strchr( p, ' ' );
1648 if( !strncasecmp( p, "rtsp:", 5 ) )
1650 /* for rtsp url, you have rtsp://localhost:port/path */
1652 while( *p == '/' ) p++;
1653 while( *p && *p != '/' ) p++;
1655 cl->query.psz_url = strdup( p );
1656 if( ( p3 = strchr( cl->query.psz_url, '?' ) ) )
1659 cl->query.psz_args = (uint8_t *)strdup( p3 );
1667 if( !strncasecmp( p2, "HTTP/1.", 7 ) )
1669 cl->query.i_proto = HTTPD_PROTO_HTTP;
1670 cl->query.i_version = atoi( p2+7 );
1672 else if( !strncasecmp( p2, "RTSP/1.", 7 ) )
1674 cl->query.i_proto = HTTPD_PROTO_RTSP;
1675 cl->query.i_version = atoi( p2+7 );
1683 p = strchr( p, '\n' );
1687 while( *p == '\n' || *p == '\r' )
1691 while( p && *p != '\0' )
1694 char *eol = p = strchr( p, '\n' );
1697 while( eol && eol >= line && ( *eol == '\n' || *eol == '\r' ) )
1702 if( ( colon = strchr( line, ':' ) ) )
1708 while( *colon == ' ' )
1712 name = strdup( line );
1713 value = strdup( colon );
1715 TAB_APPEND( cl->query.i_name, cl->query.name, name );
1716 TAB_APPEND( cl->query.i_value,cl->query.value,value);
1718 if( !strcasecmp( name, "Content-Length" ) )
1720 cl->query.i_body = atol( value );
1727 while( *p == '\n' || *p == '\r' )
1734 if( cl->query.i_body > 0 )
1736 /* TODO Mhh, handle the case client will only send a request and close the connection
1737 * to mark and of body (probably only RTSP) */
1738 cl->query.p_body = malloc( cl->query.i_body );
1743 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1749 /* check if the client is to be set to dead */
1750 #if defined( WIN32 ) || defined( UNDER_CE )
1751 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1753 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1756 if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE )
1758 /* connection closed -> end of data */
1759 if( cl->query.i_body > 0 )
1761 cl->query.i_body = cl->i_buffer;
1763 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1767 cl->i_state = HTTPD_CLIENT_DEAD;
1770 cl->i_activity_date = mdate();
1772 /* XXX: for QT I have to disable timeout. Try to find why */
1773 if( cl->query.i_proto == HTTPD_PROTO_RTSP )
1774 cl->i_activity_timeout = 0;
1776 #if 0 /* Debugging only */
1777 if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
1781 fprintf( stderr, "received new request\n" );
1782 fprintf( stderr, " - proto=%s\n",
1783 cl->query.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP" );
1784 fprintf( stderr, " - version=%d\n", cl->query.i_version );
1785 fprintf( stderr, " - msg=%d\n", cl->query.i_type );
1786 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1788 fprintf( stderr, " - answer=%d '%s'\n", cl->query.i_status,
1789 cl->query.psz_status );
1791 else if( cl->query.i_type != HTTPD_MSG_NONE )
1793 fprintf( stderr, " - url=%s\n", cl->query.psz_url );
1795 for( i = 0; i < cl->query.i_name; i++ )
1797 fprintf( stderr, " - option name='%s' value='%s'\n",
1798 cl->query.name[i], cl->query.value[i] );
1804 static void httpd_ClientSend( httpd_client_t *cl )
1809 if( cl->i_buffer < 0 )
1811 /* We need to create the header */
1815 i_size = strlen( "HTTP/1.") + 10 + 10 +
1816 strlen( cl->answer.psz_status ? cl->answer.psz_status : "" ) + 5;
1817 for( i = 0; i < cl->answer.i_name; i++ )
1819 i_size += strlen( cl->answer.name[i] ) + 2 +
1820 strlen( cl->answer.value[i] ) + 2;
1823 if( cl->i_buffer_size < i_size )
1825 cl->i_buffer_size = i_size;
1826 free( cl->p_buffer );
1827 cl->p_buffer = malloc( i_size );
1829 p = (char *)cl->p_buffer;
1831 p += sprintf( p, "%s/1.%d %d %s\r\n",
1832 cl->answer.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP",
1833 cl->answer.i_version,
1834 cl->answer.i_status, cl->answer.psz_status );
1835 for( i = 0; i < cl->answer.i_name; i++ )
1837 p += sprintf( p, "%s: %s\r\n", cl->answer.name[i],
1838 cl->answer.value[i] );
1840 p += sprintf( p, "\r\n" );
1843 cl->i_buffer_size = (uint8_t*)p - cl->p_buffer;
1845 /*fprintf( stderr, "sending answer\n" );
1846 fprintf( stderr, "%s", cl->p_buffer );*/
1849 i_len = httpd_NetSend( cl, &cl->p_buffer[cl->i_buffer],
1850 cl->i_buffer_size - cl->i_buffer );
1853 cl->i_activity_date = mdate();
1854 cl->i_buffer += i_len;
1856 if( cl->i_buffer >= cl->i_buffer_size )
1858 if( cl->answer.i_body == 0 && cl->answer.i_body_offset > 0 &&
1859 !cl->b_read_waiting )
1861 /* catch more body data */
1862 int i_msg = cl->query.i_type;
1863 int64_t i_offset = cl->answer.i_body_offset;
1865 httpd_MsgClean( &cl->answer );
1866 cl->answer.i_body_offset = i_offset;
1868 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
1869 &cl->answer, &cl->query );
1872 if( cl->answer.i_body > 0 )
1874 /* send the body data */
1875 free( cl->p_buffer );
1876 cl->p_buffer = cl->answer.p_body;
1877 cl->i_buffer_size = cl->answer.i_body;
1880 cl->answer.i_body = 0;
1881 cl->answer.p_body = NULL;
1886 cl->i_state = HTTPD_CLIENT_SEND_DONE;
1892 #if defined( WIN32 ) || defined( UNDER_CE )
1893 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1895 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1899 cl->i_state = HTTPD_CLIENT_DEAD;
1904 static void httpd_ClientTlsHsIn( httpd_client_t *cl )
1906 switch( tls_SessionContinueHandshake( cl->p_tls ) )
1909 cl->i_state = HTTPD_CLIENT_RECEIVING;
1913 cl->i_state = HTTPD_CLIENT_DEAD;
1918 cl->i_state = HTTPD_CLIENT_TLS_HS_OUT;
1922 static void httpd_ClientTlsHsOut( httpd_client_t *cl )
1924 switch( tls_SessionContinueHandshake( cl->p_tls ) )
1927 cl->i_state = HTTPD_CLIENT_RECEIVING;
1931 cl->i_state = HTTPD_CLIENT_DEAD;
1936 cl->i_state = HTTPD_CLIENT_TLS_HS_IN;
1941 static void httpd_HostThread( httpd_host_t *host )
1943 tls_session_t *p_tls = NULL;
1945 host->p_total_counter = stats_CounterCreate( host,
1946 VLC_VAR_INTEGER, STATS_COUNTER );
1947 host->p_active_counter = stats_CounterCreate( host,
1948 VLC_VAR_INTEGER, STATS_COUNTER );
1950 while( !host->b_die )
1952 struct timeval timeout;
1955 /* FIXME: (too) many int variables */
1957 int i_handle_max = 0;
1960 int b_low_delay = 0;
1962 if( host->i_url <= 0 )
1969 /* built a set of handle to select */
1970 FD_ZERO( &fds_read );
1971 FD_ZERO( &fds_write );
1975 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
1977 FD_SET( fd, &fds_read );
1978 if( fd > i_handle_max )
1982 /* prepare a new TLS session */
1983 if( ( p_tls == NULL ) && ( host->p_tls != NULL ) )
1984 p_tls = tls_ServerSessionPrepare( host->p_tls );
1986 /* add all socket that should be read/write and close dead connection */
1987 vlc_mutex_lock( &host->lock );
1988 for( i_client = 0; i_client < host->i_client; i_client++ )
1990 httpd_client_t *cl = host->client[i_client];
1992 if( cl->i_ref < 0 || ( cl->i_ref == 0 &&
1993 ( cl->i_state == HTTPD_CLIENT_DEAD ||
1994 ( cl->i_activity_timeout > 0 &&
1995 cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
1997 httpd_ClientClean( cl );
1998 stats_UpdateInteger( host, host->p_active_counter, -1, NULL );
1999 TAB_REMOVE( host->i_client, host->client, cl );
2004 else if( ( cl->i_state == HTTPD_CLIENT_RECEIVING )
2005 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) )
2007 FD_SET( cl->fd, &fds_read );
2008 i_handle_max = __MAX( i_handle_max, cl->fd );
2010 else if( ( cl->i_state == HTTPD_CLIENT_SENDING )
2011 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) )
2013 FD_SET( cl->fd, &fds_write );
2014 i_handle_max = __MAX( i_handle_max, cl->fd );
2016 else if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
2018 httpd_message_t *answer = &cl->answer;
2019 httpd_message_t *query = &cl->query;
2020 int i_msg = query->i_type;
2022 httpd_MsgInit( answer );
2024 /* Handle what we received */
2025 if( (cl->i_mode != HTTPD_CLIENT_BIDIR) &&
2026 (i_msg == HTTPD_MSG_ANSWER || i_msg == HTTPD_MSG_CHANNEL) )
2028 /* we can only receive request from client when not
2031 cl->i_state = HTTPD_CLIENT_DEAD;
2033 else if( i_msg == HTTPD_MSG_ANSWER )
2035 /* We are in BIDIR mode, trigger the callback and then
2036 * check for new data */
2037 if( cl->url && cl->url->catch[i_msg].cb )
2039 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2042 cl->i_state = HTTPD_CLIENT_WAITING;
2044 else if( i_msg == HTTPD_MSG_CHANNEL )
2046 /* We are in BIDIR mode, trigger the callback and then
2047 * check for new data */
2048 if( cl->url && cl->url->catch[i_msg].cb )
2050 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2053 cl->i_state = HTTPD_CLIENT_WAITING;
2055 else if( i_msg == HTTPD_MSG_OPTIONS )
2057 char *psz_cseq = NULL;
2061 answer->i_proto = query->i_proto ;
2062 answer->i_type = HTTPD_MSG_ANSWER;
2063 answer->i_version= 0;
2064 answer->i_status = 200;
2065 answer->psz_status = strdup( "Ok" );
2068 answer->p_body = NULL;
2070 psz_cseq = httpd_MsgGet( query, "Cseq" );
2072 i_cseq = atoi( psz_cseq );
2075 httpd_MsgAdd( answer, "Cseq", "%d", i_cseq );
2076 httpd_MsgAdd( answer, "Server", "VLC Server" );
2077 httpd_MsgAdd( answer, "Public", "DESCRIBE, SETUP, "
2078 "TEARDOWN, PLAY, PAUSE" );
2079 httpd_MsgAdd( answer, "Content-Length", "%d",
2082 cl->i_buffer = -1; /* Force the creation of the answer in
2083 * httpd_ClientSend */
2084 cl->i_state = HTTPD_CLIENT_SENDING;
2086 else if( i_msg == HTTPD_MSG_NONE )
2088 if( query->i_proto == HTTPD_PROTO_NONE )
2091 cl->i_state = HTTPD_CLIENT_DEAD;
2098 answer->i_proto = query->i_proto ;
2099 answer->i_type = HTTPD_MSG_ANSWER;
2100 answer->i_version= 0;
2101 answer->i_status = 501;
2102 answer->psz_status = strdup( "Unimplemented" );
2104 p = answer->p_body = malloc( 1000 );
2106 p += sprintf( (char *)p,
2107 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2108 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2109 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2112 "<title>Error 501</title>\n"
2115 "<h1>501 Unimplemented</h1>\n"
2117 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2121 answer->i_body = p - answer->p_body;
2122 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2124 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2125 cl->i_state = HTTPD_CLIENT_SENDING;
2130 vlc_bool_t b_auth_failed = VLC_FALSE;
2131 vlc_bool_t b_hosts_failed = VLC_FALSE;
2134 /* Search the url and trigger callbacks */
2135 for( i = 0; i < host->i_url; i++ )
2137 httpd_url_t *url = host->url[i];
2139 if( !strcmp( url->psz_url, query->psz_url ) )
2141 if( url->catch[i_msg].cb )
2143 if( answer && ( url->p_acl != NULL ) )
2145 char ip[NI_MAXNUMERICHOST];
2147 if( httpd_ClientIP( cl, ip ) != NULL )
2149 if( ACL_Check( url->p_acl, ip ) )
2151 b_hosts_failed = VLC_TRUE;
2156 b_hosts_failed = VLC_TRUE;
2159 if( answer && ( *url->psz_user || *url->psz_password ) )
2161 /* create the headers */
2162 char *b64 = httpd_MsgGet( query, "Authorization" ); /* BASIC id */
2166 asprintf( &id, "%s:%s", url->psz_user, url->psz_password );
2167 if( b64 ) auth = malloc( strlen(b64) + 1 );
2168 else auth = malloc( strlen("") + 1 );
2171 && !strncasecmp( b64, "BASIC", 5 ) )
2174 while( *b64 == ' ' )
2178 b64_decode( auth, b64 );
2185 if( strcmp( id, auth ) )
2187 httpd_MsgAdd( answer, "WWW-Authenticate", "Basic realm=\"%s\"", url->psz_user );
2188 /* We fail for all url */
2189 b_auth_failed = VLC_TRUE;
2199 if( !url->catch[i_msg].cb( url->catch[i_msg].p_sys, cl, answer, query ) )
2201 if( answer->i_proto == HTTPD_PROTO_NONE )
2203 /* Raw answer from a CGI */
2204 cl->i_buffer = cl->i_buffer_size;
2209 /* only one url can answer */
2211 if( cl->url == NULL )
2224 answer->i_proto = query->i_proto;
2225 answer->i_type = HTTPD_MSG_ANSWER;
2226 answer->i_version= 0;
2227 p = answer->p_body = malloc( 1000 + strlen(query->psz_url) );
2229 if( b_hosts_failed )
2231 answer->i_status = 403;
2232 answer->psz_status = strdup( "Forbidden" );
2234 /* FIXME: lots of code duplication */
2235 p += sprintf( (char *)p,
2236 "<?xml version=\"1.0\" encoding=\"us-ascii\" ?>"
2237 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2238 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2241 "<title>Error 403</title>\n"
2244 "<h1>403 Forbidden (%s)</h1>\n"
2246 "<p><a href=\"http://www.videolan.org\">VideoLAN</a></p>\n"
2248 "</html>\n", query->psz_url );
2250 else if( b_auth_failed )
2252 answer->i_status = 401;
2253 answer->psz_status = strdup( "Authorization Required" );
2255 p += sprintf( (char *)p,
2256 "<?xml version=\"1.0\" encoding=\"us-ascii\" ?>"
2257 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2258 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2261 "<title>Error 401</title>\n"
2264 "<h1>401 Authorization Required (%s)</h1>\n"
2266 "<p><a href=\"http://www.videolan.org\">VideoLAN</a></p>\n"
2268 "</html>\n", query->psz_url );
2272 /* no url registered */
2273 answer->i_status = 404;
2274 answer->psz_status = strdup( "Not found" );
2276 p += sprintf( (char *)p,
2277 "<?xml version=\"1.0\" encoding=\"us-ascii\" ?>"
2278 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2279 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2282 "<title>Error 404</title>\n"
2285 "<h1>404 Resource not found(%s)</h1>\n"
2287 "<p><a href=\"http://www.videolan.org\"> VideoLAN</a></p>\n"
2289 "</html>\n", query->psz_url );
2292 answer->i_body = p - answer->p_body;
2293 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2294 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2295 httpd_MsgAdd( answer, "Content-Type", "%s", "text/html" );
2298 cl->i_state = HTTPD_CLIENT_SENDING;
2301 else if( cl->i_state == HTTPD_CLIENT_SEND_DONE )
2303 if( cl->i_mode == HTTPD_CLIENT_FILE || cl->answer.i_body_offset == 0 )
2305 char *psz_connection = httpd_MsgGet( &cl->answer, "Connection" );
2306 char *psz_query = httpd_MsgGet( &cl->query, "Connection" );
2307 vlc_bool_t b_connection = VLC_FALSE;
2308 vlc_bool_t b_keepalive = VLC_FALSE;
2309 vlc_bool_t b_query = VLC_FALSE;
2312 if( psz_connection )
2314 b_connection = ( strcasecmp( psz_connection, "Close" ) == 0 );
2315 b_keepalive = ( strcasecmp( psz_connection, "Keep-Alive" ) == 0 );
2320 b_query = ( strcasecmp( psz_query, "Close" ) == 0 );
2323 if( ( ( cl->query.i_proto == HTTPD_PROTO_HTTP ) &&
2324 ( ( cl->answer.i_version == 0 && b_keepalive ) ||
2325 ( cl->answer.i_version == 1 && !b_connection ) ) ) ||
2326 ( ( cl->query.i_proto == HTTPD_PROTO_RTSP ) &&
2327 !b_query && !b_connection ) )
2329 httpd_MsgClean( &cl->query );
2330 httpd_MsgInit( &cl->query );
2333 cl->i_buffer_size = 1000;
2334 free( cl->p_buffer );
2335 cl->p_buffer = malloc( cl->i_buffer_size );
2336 cl->i_state = HTTPD_CLIENT_RECEIVING;
2340 cl->i_state = HTTPD_CLIENT_DEAD;
2342 httpd_MsgClean( &cl->answer );
2344 else if( cl->b_read_waiting )
2346 /* we have a message waiting for us to read it */
2347 httpd_MsgClean( &cl->answer );
2348 httpd_MsgClean( &cl->query );
2351 cl->i_buffer_size = 1000;
2352 free( cl->p_buffer );
2353 cl->p_buffer = malloc( cl->i_buffer_size );
2354 cl->i_state = HTTPD_CLIENT_RECEIVING;
2355 cl->b_read_waiting = VLC_FALSE;
2359 int64_t i_offset = cl->answer.i_body_offset;
2360 httpd_MsgClean( &cl->answer );
2362 cl->answer.i_body_offset = i_offset;
2363 free( cl->p_buffer );
2364 cl->p_buffer = NULL;
2366 cl->i_buffer_size = 0;
2368 cl->i_state = HTTPD_CLIENT_WAITING;
2371 else if( cl->i_state == HTTPD_CLIENT_WAITING )
2373 int64_t i_offset = cl->answer.i_body_offset;
2374 int i_msg = cl->query.i_type;
2376 httpd_MsgInit( &cl->answer );
2377 cl->answer.i_body_offset = i_offset;
2379 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
2380 &cl->answer, &cl->query );
2381 if( cl->answer.i_type != HTTPD_MSG_NONE )
2383 /* we have new data, so reenter send mode */
2385 cl->p_buffer = cl->answer.p_body;
2386 cl->i_buffer_size = cl->answer.i_body;
2387 cl->answer.p_body = NULL;
2388 cl->answer.i_body = 0;
2389 cl->i_state = HTTPD_CLIENT_SENDING;
2393 /* we shouldn't wait too long */
2394 b_low_delay = VLC_TRUE;
2398 /* Special for BIDIR mode we also check reading */
2399 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2400 cl->i_state == HTTPD_CLIENT_SENDING )
2402 FD_SET( cl->fd, &fds_read );
2403 i_handle_max = __MAX( i_handle_max, cl->fd );
2406 vlc_mutex_unlock( &host->lock );
2408 /* we will wait 100ms or 20ms (not too big 'cause HTTPD_CLIENT_WAITING) */
2410 timeout.tv_usec = b_low_delay ? 20000 : 100000;
2412 i_ret = select( i_handle_max + 1,
2413 &fds_read, &fds_write, NULL, &timeout );
2415 if( (i_ret == -1) && (errno != EINTR) )
2417 #if defined(WIN32) || defined(UNDER_CE)
2418 msg_Warn( host, "cannot select sockets (%d)", WSAGetLastError( ) );
2420 msg_Warn( host, "cannot select sockets : %s", strerror( errno ) );
2425 else if( i_ret <= 0 )
2430 /* accept new connections */
2431 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
2433 if( FD_ISSET( fd, &fds_read ) )
2435 socklen_t i_sock_size = sizeof( struct sockaddr_storage );
2436 struct sockaddr_storage sock;
2438 fd = accept( fd, (struct sockaddr *)&sock, &i_sock_size );
2444 setsockopt( fd, SOL_SOCKET, SO_REUSEADDR, &i_state, sizeof (i_state));
2447 /* set this new socket non-block */
2448 #if defined( WIN32 ) || defined( UNDER_CE )
2450 unsigned long i_dummy = 1;
2451 ioctlsocket( fd, FIONBIO, &i_dummy );
2454 fcntl( fd, F_SETFD, FD_CLOEXEC );
2456 int i_val = fcntl( fd, F_GETFL );
2458 O_NONBLOCK | ((i_val != -1) ? i_val : 0) );
2461 if( fd >= FD_SETSIZE )
2470 switch ( tls_ServerSessionHandshake( p_tls, fd ) )
2473 msg_Err( host, "Rejecting TLS connection" );
2479 case 1: /* missing input - most likely */
2480 i_state = HTTPD_CLIENT_TLS_HS_IN;
2483 case 2: /* missing output */
2484 i_state = HTTPD_CLIENT_TLS_HS_OUT;
2492 char ip[NI_MAXNUMERICHOST];
2493 stats_UpdateInteger( host, host->p_total_counter,
2495 stats_UpdateInteger( host, host->p_active_counter,
2497 cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
2498 httpd_ClientIP( cl, ip );
2499 msg_Dbg( host, "Connection from %s", ip );
2501 vlc_mutex_lock( &host->lock );
2502 TAB_APPEND( host->i_client, host->client, cl );
2503 vlc_mutex_unlock( &host->lock );
2506 cl->i_state = i_state; // override state for TLS
2512 /* now try all others socket */
2513 vlc_mutex_lock( &host->lock );
2514 for( i_client = 0; i_client < host->i_client; i_client++ )
2516 httpd_client_t *cl = host->client[i_client];
2517 if( cl->i_state == HTTPD_CLIENT_RECEIVING )
2519 httpd_ClientRecv( cl );
2521 else if( cl->i_state == HTTPD_CLIENT_SENDING )
2523 httpd_ClientSend( cl );
2525 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN )
2527 httpd_ClientTlsHsIn( cl );
2529 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT )
2531 httpd_ClientTlsHsOut( cl );
2534 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2535 cl->i_state == HTTPD_CLIENT_SENDING &&
2536 FD_ISSET( cl->fd, &fds_read ) )
2538 cl->b_read_waiting = VLC_TRUE;
2541 vlc_mutex_unlock( &host->lock );
2545 tls_ServerSessionClose( p_tls );
2548 #else /* ENABLE_HTTPD */
2550 /* We just define an empty wrapper */
2551 httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, char *b, int c,
2554 msg_Err( a, "HTTP daemon support is disabled" );
2558 httpd_host_t *httpd_HostNew( vlc_object_t *a, char *b, int c )
2560 msg_Err( a, "HTTP daemon support is disabled" );
2564 void httpd_HostDelete( httpd_host_t *a )
2568 httpd_url_t *httpd_UrlNew( httpd_host_t *host, char *psz_url,
2569 char *psz_user, char *psz_password,
2570 const vlc_acl_t *p_acl )
2575 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, char *psz_url,
2576 char *psz_user, char *psz_password,
2577 const vlc_acl_t *p_acl )
2582 int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c,
2583 httpd_callback_sys_t *d )
2588 void httpd_UrlDelete( httpd_url_t *a )
2592 char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip )
2597 char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip )
2602 void httpd_ClientModeStream( httpd_client_t *a )
2606 void httpd_ClientModeBidir( httpd_client_t *a )
2610 void httpd_FileDelete( httpd_file_t *a )
2614 httpd_file_t *httpd_FileNew( httpd_host_t *a, char *b, char *c, char *d,
2615 char *e, httpd_file_callback_t f,
2616 httpd_file_sys_t *g )
2621 httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
2622 const char *psz_user,
2623 const char *psz_password,
2624 const vlc_acl_t *p_acl,
2625 httpd_handler_callback_t pf_fill,
2626 httpd_handler_sys_t *p_sys )
2631 void httpd_HandlerDelete( httpd_handler_t *handler )
2635 void httpd_RedirectDelete( httpd_redirect_t *a )
2639 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *a,
2645 void httpd_StreamDelete( httpd_stream_t *a )
2649 int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c )
2654 int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c )
2659 httpd_stream_t *httpd_StreamNew( httpd_host_t *a, char *b, char *c,
2665 void httpd_MsgInit ( httpd_message_t *a )
2669 void httpd_MsgAdd ( httpd_message_t *a, char *b, char *c, ... )
2673 char *httpd_MsgGet ( httpd_message_t *a, char *b )
2678 void httpd_MsgClean( httpd_message_t *a )
2682 #endif /* ENABLE_HTTPD */