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;
627 if( answer == NULL || query == NULL )
631 answer->i_proto = query->i_proto;
632 answer->i_version= query->i_version;
633 answer->i_type = HTTPD_MSG_ANSWER;
634 answer->i_status = 301;
635 answer->psz_status = strdup( "Moved Permanently" );
637 answer->i_body = asprintf( &p_body,
638 "<?xml version=\"1.0\" encoding=\"ascii\" ?>\n"
639 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
640 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
643 "<title>Redirection</title>\n"
647 "<a href=\"%s\">redirected</a></h1>\n"
649 "<p><a href=\"http://www.videolan.org\">VideoLAN</a>\n</p>"
652 "</html>\n", rdir->psz_dst );
653 answer->p_body = (unsigned char *)p_body;
655 /* XXX check if it's ok or we need to set an absolute url */
656 httpd_MsgAdd( answer, "Location", "%s", rdir->psz_dst );
658 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
663 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst,
664 const char *psz_url_src )
666 httpd_redirect_t *rdir = malloc( sizeof( httpd_redirect_t ) );
668 if( !( rdir->url = httpd_UrlNewUnique( host, psz_url_src, NULL, NULL, NULL ) ) )
673 rdir->psz_dst = strdup( psz_url_dst );
675 /* Redirect apply for all HTTP request and RTSP DESCRIBE resquest */
676 httpd_UrlCatch( rdir->url, HTTPD_MSG_HEAD, httpd_RedirectCallBack,
677 (httpd_callback_sys_t*)rdir );
678 httpd_UrlCatch( rdir->url, HTTPD_MSG_GET, httpd_RedirectCallBack,
679 (httpd_callback_sys_t*)rdir );
680 httpd_UrlCatch( rdir->url, HTTPD_MSG_POST, httpd_RedirectCallBack,
681 (httpd_callback_sys_t*)rdir );
682 httpd_UrlCatch( rdir->url, HTTPD_MSG_DESCRIBE, httpd_RedirectCallBack,
683 (httpd_callback_sys_t*)rdir );
687 void httpd_RedirectDelete( httpd_redirect_t *rdir )
689 httpd_UrlDelete( rdir->url );
690 free( rdir->psz_dst );
694 /*****************************************************************************
695 * High Level Funtions: httpd_stream_t
696 *****************************************************************************/
697 struct httpd_stream_t
704 /* Header to send as first packet */
708 /* circular buffer */
709 int i_buffer_size; /* buffer size, can't be reallocated smaller */
710 uint8_t *p_buffer; /* buffer */
711 int64_t i_buffer_pos; /* absolute position from begining */
712 int64_t i_buffer_last_pos; /* a new connection will start with that */
715 static int httpd_StreamCallBack( httpd_callback_sys_t *p_sys,
716 httpd_client_t *cl, httpd_message_t *answer,
717 httpd_message_t *query )
719 httpd_stream_t *stream = (httpd_stream_t*)p_sys;
721 if( answer == NULL || query == NULL || cl == NULL )
726 if( answer->i_body_offset > 0 )
732 fprintf( stderr, "httpd_StreamCallBack i_body_offset=%lld\n",
733 answer->i_body_offset );
736 if( answer->i_body_offset >= stream->i_buffer_pos )
738 /* fprintf( stderr, "httpd_StreamCallBack: no data\n" ); */
739 return VLC_EGENERIC; /* wait, no data available */
741 if( answer->i_body_offset + stream->i_buffer_size <
742 stream->i_buffer_pos )
744 /* this client isn't fast enough */
746 fprintf( stderr, "fixing i_body_offset (old=%lld new=%lld)\n",
747 answer->i_body_offset, stream->i_buffer_last_pos );
749 answer->i_body_offset = stream->i_buffer_last_pos;
752 i_pos = answer->i_body_offset % stream->i_buffer_size;
753 i_write = stream->i_buffer_pos - answer->i_body_offset;
754 if( i_write > HTTPD_CL_BUFSIZE )
756 i_write = HTTPD_CL_BUFSIZE;
758 else if( i_write <= 0 )
760 return VLC_EGENERIC; /* wait, no data available */
763 /* Don't go past the end of the circular buffer */
764 i_write = __MIN( i_write, stream->i_buffer_size - i_pos );
766 /* using HTTPD_MSG_ANSWER -> data available */
767 answer->i_proto = HTTPD_PROTO_HTTP;
768 answer->i_version= 0;
769 answer->i_type = HTTPD_MSG_ANSWER;
771 answer->i_body = i_write;
772 answer->p_body = malloc( i_write );
773 memcpy( answer->p_body, &stream->p_buffer[i_pos], i_write );
775 answer->i_body_offset += i_write;
781 answer->i_proto = HTTPD_PROTO_HTTP;
782 answer->i_version= 0;
783 answer->i_type = HTTPD_MSG_ANSWER;
785 answer->i_status = 200;
786 answer->psz_status = strdup( "OK" );
788 if( query->i_type != HTTPD_MSG_HEAD )
790 httpd_ClientModeStream( cl );
791 vlc_mutex_lock( &stream->lock );
792 /* Send the header */
793 if( stream->i_header > 0 )
795 answer->i_body = stream->i_header;
796 answer->p_body = malloc( stream->i_header );
797 memcpy( answer->p_body, stream->p_header, stream->i_header );
799 answer->i_body_offset = stream->i_buffer_last_pos;
800 vlc_mutex_unlock( &stream->lock );
804 httpd_MsgAdd( answer, "Content-Length", "%d", 0 );
805 answer->i_body_offset = 0;
808 if( !strcmp( stream->psz_mime, "video/x-ms-asf-stream" ) )
810 vlc_bool_t b_xplaystream = VLC_FALSE;
813 httpd_MsgAdd( answer, "Content-type", "%s",
814 "application/octet-stream" );
815 httpd_MsgAdd( answer, "Server", "Cougar 4.1.0.3921" );
816 httpd_MsgAdd( answer, "Pragma", "no-cache" );
817 httpd_MsgAdd( answer, "Pragma", "client-id=%d", rand()&0x7fff );
818 httpd_MsgAdd( answer, "Pragma", "features=\"broadcast\"" );
820 /* Check if there is a xPlayStrm=1 */
821 for( i = 0; i < query->i_name; i++ )
823 if( !strcasecmp( query->name[i], "Pragma" ) &&
824 strstr( query->value[i], "xPlayStrm=1" ) )
826 b_xplaystream = VLC_TRUE;
832 answer->i_body_offset = 0;
837 httpd_MsgAdd( answer, "Content-type", "%s", stream->psz_mime );
839 httpd_MsgAdd( answer, "Cache-Control", "%s", "no-cache" );
844 httpd_stream_t *httpd_StreamNew( httpd_host_t *host,
845 const char *psz_url, const char *psz_mime,
846 const char *psz_user, const char *psz_password,
847 const vlc_acl_t *p_acl )
849 httpd_stream_t *stream = malloc( sizeof( httpd_stream_t ) );
851 if( ( stream->url = httpd_UrlNewUnique( host, psz_url, psz_user,
852 psz_password, p_acl )
858 vlc_mutex_init( host, &stream->lock );
859 if( psz_mime && *psz_mime )
861 stream->psz_mime = strdup( psz_mime );
865 stream->psz_mime = strdup( httpd_MimeFromUrl( psz_url ) );
867 stream->i_header = 0;
868 stream->p_header = NULL;
869 stream->i_buffer_size = 5000000; /* 5 Mo per stream */
870 stream->p_buffer = malloc( stream->i_buffer_size );
871 /* We set to 1 to make life simpler
872 * (this way i_body_offset can never be 0) */
873 stream->i_buffer_pos = 1;
874 stream->i_buffer_last_pos = 1;
876 httpd_UrlCatch( stream->url, HTTPD_MSG_HEAD, httpd_StreamCallBack,
877 (httpd_callback_sys_t*)stream );
878 httpd_UrlCatch( stream->url, HTTPD_MSG_GET, httpd_StreamCallBack,
879 (httpd_callback_sys_t*)stream );
880 httpd_UrlCatch( stream->url, HTTPD_MSG_POST, httpd_StreamCallBack,
881 (httpd_callback_sys_t*)stream );
886 int httpd_StreamHeader( httpd_stream_t *stream, uint8_t *p_data, int i_data )
888 vlc_mutex_lock( &stream->lock );
889 if( stream->p_header )
891 free( stream->p_header );
892 stream->p_header = NULL;
894 stream->i_header = i_data;
897 stream->p_header = malloc( i_data );
898 memcpy( stream->p_header, p_data, i_data );
900 vlc_mutex_unlock( &stream->lock );
905 int httpd_StreamSend( httpd_stream_t *stream, uint8_t *p_data, int i_data )
910 if( i_data < 0 || p_data == NULL )
914 vlc_mutex_lock( &stream->lock );
916 /* save this pointer (to be used by new connection) */
917 stream->i_buffer_last_pos = stream->i_buffer_pos;
919 i_pos = stream->i_buffer_pos % stream->i_buffer_size;
925 i_copy = __MIN( i_count, stream->i_buffer_size - i_pos );
927 /* Ok, we can't go past the end of our buffer */
928 memcpy( &stream->p_buffer[i_pos], p_data, i_copy );
930 i_pos = ( i_pos + i_copy ) % stream->i_buffer_size;
935 stream->i_buffer_pos += i_data;
937 vlc_mutex_unlock( &stream->lock );
941 void httpd_StreamDelete( httpd_stream_t *stream )
943 httpd_UrlDelete( stream->url );
944 vlc_mutex_destroy( &stream->lock );
945 if( stream->psz_mime ) free( stream->psz_mime );
946 if( stream->p_header ) free( stream->p_header );
947 if( stream->p_buffer ) free( stream->p_buffer );
951 /*****************************************************************************
953 *****************************************************************************/
954 static void httpd_HostThread( httpd_host_t * );
956 /* create a new host */
957 httpd_host_t *httpd_HostNew( vlc_object_t *p_this, const char *psz_host,
960 return httpd_TLSHostNew( p_this, psz_host, i_port, NULL, NULL, NULL, NULL
964 httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname,
966 const char *psz_cert, const char *psz_key,
967 const char *psz_ca, const char *psz_crl )
976 if( psz_hostname == NULL )
979 psz_host = strdup( psz_hostname );
980 if( psz_host == NULL )
982 msg_Err( p_this, "memory error" );
986 /* to be sure to avoid multiple creation */
987 var_Create( p_this->p_libvlc, "httpd_mutex", VLC_VAR_MUTEX );
988 var_Get( p_this->p_libvlc, "httpd_mutex", &lockval );
989 vlc_mutex_lock( lockval.p_address );
991 if( !(httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE )) )
993 msg_Info( p_this, "creating httpd" );
994 if( ( httpd = vlc_object_create( p_this, VLC_OBJECT_HTTPD ) ) == NULL )
996 vlc_mutex_unlock( lockval.p_address );
1004 vlc_object_yield( httpd );
1005 vlc_object_attach( httpd, p_this->p_vlc );
1008 /* verify if it already exist */
1009 for( i = httpd->i_host - 1; i >= 0; i-- )
1011 host = httpd->host[i];
1013 /* cannot mix TLS and non-TLS hosts */
1014 if( ( ( httpd->host[i]->p_tls != NULL ) != ( psz_cert != NULL ) )
1015 || ( host->i_port != i_port )
1016 || strcmp( host->psz_hostname, psz_hostname ) )
1022 vlc_mutex_unlock( lockval.p_address );
1028 /* determine TLS configuration */
1029 if ( psz_cert != NULL )
1031 p_tls = tls_ServerCreate( p_this, psz_cert, psz_key );
1032 if ( p_tls == NULL )
1034 msg_Err( p_this, "TLS initialization error" );
1038 if ( ( psz_ca != NULL) && tls_ServerAddCA( p_tls, psz_ca ) )
1040 msg_Err( p_this, "TLS CA error" );
1044 if ( ( psz_crl != NULL) && tls_ServerAddCRL( p_tls, psz_crl ) )
1046 msg_Err( p_this, "TLS CRL error" );
1053 /* create the new host */
1054 host = vlc_object_create( p_this, VLC_OBJECT_HTTPD_HOST );
1055 host->httpd = httpd;
1056 vlc_mutex_init( httpd, &host->lock );
1059 host->fd = net_ListenTCP( p_this, psz_host, i_port );
1060 if( host->fd == NULL )
1062 msg_Err( p_this, "cannot create socket(s) for HTTP host" );
1066 host->i_port = i_port;
1067 host->psz_hostname = psz_host;
1072 host->client = NULL;
1074 host->p_tls = p_tls;
1076 /* create the thread */
1077 if( vlc_thread_create( host, "httpd host thread", httpd_HostThread,
1078 VLC_THREAD_PRIORITY_LOW, VLC_FALSE ) )
1080 msg_Err( p_this, "cannot spawn http host thread" );
1084 /* now add it to httpd */
1085 TAB_APPEND( httpd->i_host, httpd->host, host );
1086 vlc_mutex_unlock( lockval.p_address );
1092 if( httpd->i_host <= 0 )
1094 vlc_object_release( httpd );
1095 vlc_object_detach( httpd );
1096 vlc_object_destroy( httpd );
1098 vlc_mutex_unlock( lockval.p_address );
1102 net_ListenClose( host->fd );
1103 vlc_mutex_destroy( &host->lock );
1104 vlc_object_destroy( host );
1108 tls_ServerDelete( p_tls );
1114 void httpd_HostDelete( httpd_host_t *host )
1116 httpd_t *httpd = host->httpd;
1117 vlc_value_t lockval;
1120 var_Get( httpd->p_libvlc, "httpd_mutex", &lockval );
1121 vlc_mutex_lock( lockval.p_address );
1124 if( host->i_ref > 0 )
1127 vlc_mutex_unlock( lockval.p_address );
1128 msg_Dbg( host, "httpd_HostDelete: host still used" );
1131 TAB_REMOVE( httpd->i_host, httpd->host, host );
1134 vlc_thread_join( host );
1136 msg_Dbg( host, "HTTP host removed" );
1138 for( i = 0; i < host->i_url; i++ )
1140 msg_Err( host, "url still registered: %s", host->url[i]->psz_url );
1142 for( i = 0; i < host->i_client; i++ )
1144 httpd_client_t *cl = host->client[i];
1145 msg_Warn( host, "client still connected" );
1146 httpd_ClientClean( cl );
1147 TAB_REMOVE( host->i_client, host->client, cl );
1153 if( host->p_tls != NULL)
1154 tls_ServerDelete( host->p_tls );
1156 net_ListenClose( host->fd );
1157 free( host->psz_hostname );
1159 vlc_mutex_destroy( &host->lock );
1160 vlc_object_destroy( host );
1162 vlc_object_release( httpd );
1163 if( httpd->i_host <= 0 )
1165 msg_Dbg( httpd, "no host left, stopping httpd" );
1166 vlc_object_detach( httpd );
1167 vlc_object_destroy( httpd );
1169 vlc_mutex_unlock( lockval.p_address );
1172 /* register a new url */
1173 static httpd_url_t *httpd_UrlNewPrivate( httpd_host_t *host, const char *psz_url,
1174 const char *psz_user, const char *psz_password,
1175 const vlc_acl_t *p_acl, vlc_bool_t b_check )
1180 vlc_mutex_lock( &host->lock );
1183 for( i = 0; i < host->i_url; i++ )
1185 if( !strcmp( psz_url, host->url[i]->psz_url ) )
1187 msg_Warn( host->httpd,
1188 "cannot add '%s' (url already defined)", psz_url );
1189 vlc_mutex_unlock( &host->lock );
1195 url = malloc( sizeof( httpd_url_t ) );
1198 vlc_mutex_init( host->httpd, &url->lock );
1199 url->psz_url = strdup( psz_url );
1200 url->psz_user = strdup( psz_user ? psz_user : "" );
1201 url->psz_password = strdup( psz_password ? psz_password : "" );
1202 url->p_acl = ACL_Duplicate( host, p_acl );
1203 for( i = 0; i < HTTPD_MSG_MAX; i++ )
1205 url->catch[i].cb = NULL;
1206 url->catch[i].p_sys = NULL;
1209 TAB_APPEND( host->i_url, host->url, url );
1210 vlc_mutex_unlock( &host->lock );
1215 httpd_url_t *httpd_UrlNew( httpd_host_t *host, const char *psz_url,
1216 const char *psz_user, const char *psz_password,
1217 const vlc_acl_t *p_acl )
1219 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1220 psz_password, p_acl, VLC_FALSE );
1223 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, const char *psz_url,
1224 const char *psz_user, const char *psz_password,
1225 const vlc_acl_t *p_acl )
1227 return httpd_UrlNewPrivate( host, psz_url, psz_user,
1228 psz_password, p_acl, VLC_TRUE );
1231 /* register callback on a url */
1232 int httpd_UrlCatch( httpd_url_t *url, int i_msg, httpd_callback_t cb,
1233 httpd_callback_sys_t *p_sys )
1235 vlc_mutex_lock( &url->lock );
1236 url->catch[i_msg].cb = cb;
1237 url->catch[i_msg].p_sys= p_sys;
1238 vlc_mutex_unlock( &url->lock );
1244 void httpd_UrlDelete( httpd_url_t *url )
1246 httpd_host_t *host = url->host;
1249 vlc_mutex_lock( &host->lock );
1250 TAB_REMOVE( host->i_url, host->url, url );
1252 vlc_mutex_destroy( &url->lock );
1253 free( url->psz_url );
1254 free( url->psz_user );
1255 free( url->psz_password );
1256 ACL_Destroy( url->p_acl );
1258 for( i = 0; i < host->i_client; i++ )
1260 httpd_client_t *client = host->client[i];
1262 if( client->url == url )
1264 /* TODO complete it */
1265 msg_Warn( host, "force closing connections" );
1266 httpd_ClientClean( client );
1267 TAB_REMOVE( host->i_client, host->client, client );
1273 vlc_mutex_unlock( &host->lock );
1276 void httpd_MsgInit( httpd_message_t *msg )
1279 msg->i_type = HTTPD_MSG_NONE;
1280 msg->i_proto = HTTPD_PROTO_NONE;
1281 msg->i_version = -1;
1284 msg->psz_status = NULL;
1286 msg->psz_url = NULL;
1287 msg->psz_args = NULL;
1289 msg->i_channel = -1;
1296 msg->i_body_offset = 0;
1301 void httpd_MsgClean( httpd_message_t *msg )
1305 if( msg->psz_status )
1307 free( msg->psz_status );
1311 free( msg->psz_url );
1315 free( msg->psz_args );
1317 for( i = 0; i < msg->i_name; i++ )
1319 free( msg->name[i] );
1320 free( msg->value[i] );
1332 free( msg->p_body );
1334 httpd_MsgInit( msg );
1337 char *httpd_MsgGet( httpd_message_t *msg, char *name )
1341 for( i = 0; i < msg->i_name; i++ )
1343 if( !strcasecmp( msg->name[i], name ))
1345 return msg->value[i];
1351 void httpd_MsgAdd( httpd_message_t *msg, char *name, char *psz_value, ... )
1356 va_start( args, psz_value );
1357 #if defined(HAVE_VASPRINTF) && !defined(__APPLE__) && !defined(SYS_BEOS)
1358 vasprintf( &value, psz_value, args );
1361 int i_size = strlen( psz_value ) + 4096; /* FIXME stupid system */
1362 value = calloc( i_size, sizeof( char ) );
1363 vsnprintf( value, i_size, psz_value, args );
1364 value[i_size - 1] = 0;
1369 name = strdup( name );
1371 TAB_APPEND( msg->i_name, msg->name, name );
1372 TAB_APPEND( msg->i_value, msg->value, value );
1375 static void httpd_ClientInit( httpd_client_t *cl )
1377 cl->i_state = HTTPD_CLIENT_RECEIVING;
1378 cl->i_activity_date = mdate();
1379 cl->i_activity_timeout = I64C(10000000);
1380 cl->i_buffer_size = HTTPD_CL_BUFSIZE;
1382 cl->p_buffer = malloc( cl->i_buffer_size );
1383 cl->i_mode = HTTPD_CLIENT_FILE;
1384 cl->b_read_waiting = VLC_FALSE;
1386 httpd_MsgInit( &cl->query );
1387 httpd_MsgInit( &cl->answer );
1390 void httpd_ClientModeStream( httpd_client_t *cl )
1392 cl->i_mode = HTTPD_CLIENT_STREAM;
1395 void httpd_ClientModeBidir( httpd_client_t *cl )
1397 cl->i_mode = HTTPD_CLIENT_BIDIR;
1400 char* httpd_ClientIP( const httpd_client_t *cl, char *psz_ip )
1402 return net_GetPeerAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1405 char* httpd_ServerIP( const httpd_client_t *cl, char *psz_ip )
1407 return net_GetSockAddress( cl->fd, psz_ip, NULL ) ? NULL : psz_ip;
1410 static void httpd_ClientClean( httpd_client_t *cl )
1414 if( cl->p_tls != NULL )
1415 tls_ServerSessionClose( cl->p_tls );
1416 net_Close( cl->fd );
1420 httpd_MsgClean( &cl->answer );
1421 httpd_MsgClean( &cl->query );
1425 free( cl->p_buffer );
1426 cl->p_buffer = NULL;
1430 static httpd_client_t *httpd_ClientNew( int fd, struct sockaddr_storage *sock,
1432 tls_session_t *p_tls )
1434 httpd_client_t *cl = malloc( sizeof( httpd_client_t ) );
1436 if( !cl ) return NULL;
1440 memcpy( &cl->sock, sock, sizeof( cl->sock ) );
1441 cl->i_sock_size = i_sock_size;
1445 httpd_ClientInit( cl );
1450 static int httpd_NetRecv( httpd_client_t *cl, uint8_t *p, int i_len )
1452 tls_session_t *p_tls;
1456 return tls_Recv( p_tls, p, i_len );
1458 return recv( cl->fd, p, i_len, 0 );
1461 static int httpd_NetSend( httpd_client_t *cl, const uint8_t *p, int i_len )
1463 tls_session_t *p_tls;
1467 return tls_Send( p_tls, p, i_len );
1469 return send( cl->fd, p, i_len, 0 );
1472 static void httpd_ClientRecv( httpd_client_t *cl )
1476 if( cl->query.i_proto == HTTPD_PROTO_NONE )
1478 /* enough to see if it's rtp over rtsp or RTSP/HTTP */
1479 i_len = httpd_NetRecv( cl, &cl->p_buffer[cl->i_buffer],
1483 cl->i_buffer += i_len;
1486 if( cl->i_buffer >= 4 )
1488 /*fprintf( stderr, "peek=%4.4s\n", cl->p_buffer );*/
1490 if( cl->p_buffer[0] == '$' )
1492 /* RTSP (rtp over rtsp) */
1493 cl->query.i_proto = HTTPD_PROTO_RTSP;
1494 cl->query.i_type = HTTPD_MSG_CHANNEL;
1495 cl->query.i_channel = cl->p_buffer[1];
1496 cl->query.i_body = (cl->p_buffer[2] << 8)|cl->p_buffer[3];
1497 cl->query.p_body = malloc( cl->query.i_body );
1501 else if( !memcmp( cl->p_buffer, "HTTP", 4 ) )
1503 cl->query.i_proto = HTTPD_PROTO_HTTP;
1504 cl->query.i_type = HTTPD_MSG_ANSWER;
1506 else if( !memcmp( cl->p_buffer, "RTSP", 4 ) )
1508 cl->query.i_proto = HTTPD_PROTO_RTSP;
1509 cl->query.i_type = HTTPD_MSG_ANSWER;
1511 else if( !memcmp( cl->p_buffer, "GET ", 4 ) ||
1512 !memcmp( cl->p_buffer, "HEAD", 4 ) ||
1513 !memcmp( cl->p_buffer, "POST", 4 ) )
1515 cl->query.i_proto = HTTPD_PROTO_HTTP;
1516 cl->query.i_type = HTTPD_MSG_NONE;
1520 cl->query.i_proto = HTTPD_PROTO_RTSP;
1521 cl->query.i_type = HTTPD_MSG_NONE;
1525 else if( cl->query.i_body > 0 )
1527 /* we are reading the body of a request or a channel */
1528 i_len = httpd_NetRecv( cl, &cl->query.p_body[cl->i_buffer],
1529 cl->query.i_body - cl->i_buffer );
1532 cl->i_buffer += i_len;
1534 if( cl->i_buffer >= cl->query.i_body )
1536 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1541 /* we are reading a header -> char by char */
1544 i_len = httpd_NetRecv (cl, &cl->p_buffer[cl->i_buffer], 1 );
1551 if( cl->i_buffer + 1 >= cl->i_buffer_size )
1553 cl->i_buffer_size += 1024;
1554 cl->p_buffer = realloc( cl->p_buffer, cl->i_buffer_size );
1556 if( ( cl->i_buffer >= 2 && !memcmp( &cl->p_buffer[cl->i_buffer-2], "\n\n", 2 ) )||
1557 ( cl->i_buffer >= 4 && !memcmp( &cl->p_buffer[cl->i_buffer-4], "\r\n\r\n", 4 ) ) )
1561 /* we have finished the header so parse it and set i_body */
1562 cl->p_buffer[cl->i_buffer] = '\0';
1564 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1567 * assume strlen( "HTTP/1.x" ) = 8
1569 cl->query.i_status =
1570 strtol( (char *)&cl->p_buffer[8],
1576 cl->query.psz_status = strdup( p );
1588 { "OPTIONS", HTTPD_MSG_OPTIONS, HTTPD_PROTO_RTSP },
1589 { "DESCRIBE", HTTPD_MSG_DESCRIBE, HTTPD_PROTO_RTSP },
1590 { "SETUP", HTTPD_MSG_SETUP, HTTPD_PROTO_RTSP },
1591 { "PLAY", HTTPD_MSG_PLAY, HTTPD_PROTO_RTSP },
1592 { "PAUSE", HTTPD_MSG_PAUSE, HTTPD_PROTO_RTSP },
1593 { "GET_PARAMETER", HTTPD_MSG_GETPARAMETER, HTTPD_PROTO_RTSP },
1594 { "TEARDOWN", HTTPD_MSG_TEARDOWN, HTTPD_PROTO_RTSP },
1596 { "GET", HTTPD_MSG_GET, HTTPD_PROTO_HTTP },
1597 { "HEAD", HTTPD_MSG_HEAD, HTTPD_PROTO_HTTP },
1598 { "POST", HTTPD_MSG_POST, HTTPD_PROTO_HTTP },
1600 { NULL, HTTPD_MSG_NONE, HTTPD_PROTO_NONE }
1605 cl->query.i_type = HTTPD_MSG_NONE;
1607 /*fprintf( stderr, "received new request=%s\n", cl->p_buffer);*/
1609 for( i = 0; msg_type[i].name != NULL; i++ )
1611 if( !strncmp( (char *)cl->p_buffer, msg_type[i].name,
1612 strlen( msg_type[i].name ) ) )
1614 p = (char *)&cl->p_buffer[strlen((char *)msg_type[i].name) + 1 ];
1615 cl->query.i_type = msg_type[i].i_type;
1616 if( cl->query.i_proto != msg_type[i].i_proto )
1619 cl->query.i_proto = HTTPD_PROTO_NONE;
1620 cl->query.i_type = HTTPD_MSG_NONE;
1627 if( strstr( (char *)cl->p_buffer, "HTTP/1." ) )
1629 cl->query.i_proto = HTTPD_PROTO_HTTP;
1631 else if( strstr( (char *)cl->p_buffer, "RTSP/1." ) )
1633 cl->query.i_proto = HTTPD_PROTO_RTSP;
1645 p2 = strchr( p, ' ' );
1650 if( !strncasecmp( p, "rtsp:", 5 ) )
1652 /* for rtsp url, you have rtsp://localhost:port/path */
1654 while( *p == '/' ) p++;
1655 while( *p && *p != '/' ) p++;
1657 cl->query.psz_url = strdup( p );
1658 if( ( p3 = strchr( cl->query.psz_url, '?' ) ) )
1661 cl->query.psz_args = (uint8_t *)strdup( p3 );
1669 if( !strncasecmp( p2, "HTTP/1.", 7 ) )
1671 cl->query.i_proto = HTTPD_PROTO_HTTP;
1672 cl->query.i_version = atoi( p2+7 );
1674 else if( !strncasecmp( p2, "RTSP/1.", 7 ) )
1676 cl->query.i_proto = HTTPD_PROTO_RTSP;
1677 cl->query.i_version = atoi( p2+7 );
1685 p = strchr( p, '\n' );
1689 while( *p == '\n' || *p == '\r' )
1693 while( p && *p != '\0' )
1696 char *eol = p = strchr( p, '\n' );
1699 while( eol && eol >= line && ( *eol == '\n' || *eol == '\r' ) )
1704 if( ( colon = strchr( line, ':' ) ) )
1710 while( *colon == ' ' )
1714 name = strdup( line );
1715 value = strdup( colon );
1717 TAB_APPEND( cl->query.i_name, cl->query.name, name );
1718 TAB_APPEND( cl->query.i_value,cl->query.value,value);
1720 if( !strcasecmp( name, "Content-Length" ) )
1722 cl->query.i_body = atol( value );
1729 while( *p == '\n' || *p == '\r' )
1736 if( cl->query.i_body > 0 )
1738 /* TODO Mhh, handle the case client will only send a request and close the connection
1739 * to mark and of body (probably only RTSP) */
1740 cl->query.p_body = malloc( cl->query.i_body );
1745 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1751 /* check if the client is to be set to dead */
1752 #if defined( WIN32 ) || defined( UNDER_CE )
1753 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1755 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1758 if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE )
1760 /* connection closed -> end of data */
1761 if( cl->query.i_body > 0 )
1763 cl->query.i_body = cl->i_buffer;
1765 cl->i_state = HTTPD_CLIENT_RECEIVE_DONE;
1769 cl->i_state = HTTPD_CLIENT_DEAD;
1772 cl->i_activity_date = mdate();
1774 /* XXX: for QT I have to disable timeout. Try to find why */
1775 if( cl->query.i_proto == HTTPD_PROTO_RTSP )
1776 cl->i_activity_timeout = 0;
1778 #if 0 /* Debugging only */
1779 if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
1783 fprintf( stderr, "received new request\n" );
1784 fprintf( stderr, " - proto=%s\n",
1785 cl->query.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP" );
1786 fprintf( stderr, " - version=%d\n", cl->query.i_version );
1787 fprintf( stderr, " - msg=%d\n", cl->query.i_type );
1788 if( cl->query.i_type == HTTPD_MSG_ANSWER )
1790 fprintf( stderr, " - answer=%d '%s'\n", cl->query.i_status,
1791 cl->query.psz_status );
1793 else if( cl->query.i_type != HTTPD_MSG_NONE )
1795 fprintf( stderr, " - url=%s\n", cl->query.psz_url );
1797 for( i = 0; i < cl->query.i_name; i++ )
1799 fprintf( stderr, " - option name='%s' value='%s'\n",
1800 cl->query.name[i], cl->query.value[i] );
1806 static void httpd_ClientSend( httpd_client_t *cl )
1811 if( cl->i_buffer < 0 )
1813 /* We need to create the header */
1817 i_size = strlen( "HTTP/1.") + 10 + 10 +
1818 strlen( cl->answer.psz_status ? cl->answer.psz_status : "" ) + 5;
1819 for( i = 0; i < cl->answer.i_name; i++ )
1821 i_size += strlen( cl->answer.name[i] ) + 2 +
1822 strlen( cl->answer.value[i] ) + 2;
1825 if( cl->i_buffer_size < i_size )
1827 cl->i_buffer_size = i_size;
1828 free( cl->p_buffer );
1829 cl->p_buffer = malloc( i_size );
1831 p = (char *)cl->p_buffer;
1833 p += sprintf( p, "%s/1.%d %d %s\r\n",
1834 cl->answer.i_proto == HTTPD_PROTO_HTTP ? "HTTP" : "RTSP",
1835 cl->answer.i_version,
1836 cl->answer.i_status, cl->answer.psz_status );
1837 for( i = 0; i < cl->answer.i_name; i++ )
1839 p += sprintf( p, "%s: %s\r\n", cl->answer.name[i],
1840 cl->answer.value[i] );
1842 p += sprintf( p, "\r\n" );
1845 cl->i_buffer_size = (uint8_t*)p - cl->p_buffer;
1847 /*fprintf( stderr, "sending answer\n" );
1848 fprintf( stderr, "%s", cl->p_buffer );*/
1851 i_len = httpd_NetSend( cl, &cl->p_buffer[cl->i_buffer],
1852 cl->i_buffer_size - cl->i_buffer );
1855 cl->i_activity_date = mdate();
1856 cl->i_buffer += i_len;
1858 if( cl->i_buffer >= cl->i_buffer_size )
1860 if( cl->answer.i_body == 0 && cl->answer.i_body_offset > 0 &&
1861 !cl->b_read_waiting )
1863 /* catch more body data */
1864 int i_msg = cl->query.i_type;
1865 int64_t i_offset = cl->answer.i_body_offset;
1867 httpd_MsgClean( &cl->answer );
1868 cl->answer.i_body_offset = i_offset;
1870 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
1871 &cl->answer, &cl->query );
1874 if( cl->answer.i_body > 0 )
1876 /* send the body data */
1877 free( cl->p_buffer );
1878 cl->p_buffer = cl->answer.p_body;
1879 cl->i_buffer_size = cl->answer.i_body;
1882 cl->answer.i_body = 0;
1883 cl->answer.p_body = NULL;
1888 cl->i_state = HTTPD_CLIENT_SEND_DONE;
1894 #if defined( WIN32 ) || defined( UNDER_CE )
1895 if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) )
1897 if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) )
1901 cl->i_state = HTTPD_CLIENT_DEAD;
1906 static void httpd_ClientTlsHsIn( httpd_client_t *cl )
1908 switch( tls_SessionContinueHandshake( cl->p_tls ) )
1911 cl->i_state = HTTPD_CLIENT_RECEIVING;
1915 cl->i_state = HTTPD_CLIENT_DEAD;
1920 cl->i_state = HTTPD_CLIENT_TLS_HS_OUT;
1924 static void httpd_ClientTlsHsOut( httpd_client_t *cl )
1926 switch( tls_SessionContinueHandshake( cl->p_tls ) )
1929 cl->i_state = HTTPD_CLIENT_RECEIVING;
1933 cl->i_state = HTTPD_CLIENT_DEAD;
1938 cl->i_state = HTTPD_CLIENT_TLS_HS_IN;
1943 static void httpd_HostThread( httpd_host_t *host )
1945 tls_session_t *p_tls = NULL;
1947 host->p_total_counter = stats_CounterCreate( host,
1948 VLC_VAR_INTEGER, STATS_COUNTER );
1949 host->p_active_counter = stats_CounterCreate( host,
1950 VLC_VAR_INTEGER, STATS_COUNTER );
1952 while( !host->b_die )
1954 struct timeval timeout;
1957 /* FIXME: (too) many int variables */
1959 int i_handle_max = 0;
1962 int b_low_delay = 0;
1964 if( host->i_url <= 0 )
1971 /* built a set of handle to select */
1972 FD_ZERO( &fds_read );
1973 FD_ZERO( &fds_write );
1977 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
1979 FD_SET( fd, &fds_read );
1980 if( fd > i_handle_max )
1984 /* prepare a new TLS session */
1985 if( ( p_tls == NULL ) && ( host->p_tls != NULL ) )
1986 p_tls = tls_ServerSessionPrepare( host->p_tls );
1988 /* add all socket that should be read/write and close dead connection */
1989 vlc_mutex_lock( &host->lock );
1990 for( i_client = 0; i_client < host->i_client; i_client++ )
1992 httpd_client_t *cl = host->client[i_client];
1994 if( cl->i_ref < 0 || ( cl->i_ref == 0 &&
1995 ( cl->i_state == HTTPD_CLIENT_DEAD ||
1996 ( cl->i_activity_timeout > 0 &&
1997 cl->i_activity_date+cl->i_activity_timeout < mdate()) ) ) )
1999 httpd_ClientClean( cl );
2000 stats_UpdateInteger( host, host->p_active_counter, -1, NULL );
2001 TAB_REMOVE( host->i_client, host->client, cl );
2006 else if( ( cl->i_state == HTTPD_CLIENT_RECEIVING )
2007 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) )
2009 FD_SET( cl->fd, &fds_read );
2010 i_handle_max = __MAX( i_handle_max, cl->fd );
2012 else if( ( cl->i_state == HTTPD_CLIENT_SENDING )
2013 || ( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) )
2015 FD_SET( cl->fd, &fds_write );
2016 i_handle_max = __MAX( i_handle_max, cl->fd );
2018 else if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
2020 httpd_message_t *answer = &cl->answer;
2021 httpd_message_t *query = &cl->query;
2022 int i_msg = query->i_type;
2024 httpd_MsgInit( answer );
2026 /* Handle what we received */
2027 if( (cl->i_mode != HTTPD_CLIENT_BIDIR) &&
2028 (i_msg == HTTPD_MSG_ANSWER || i_msg == HTTPD_MSG_CHANNEL) )
2030 /* we can only receive request from client when not
2033 cl->i_state = HTTPD_CLIENT_DEAD;
2035 else if( i_msg == HTTPD_MSG_ANSWER )
2037 /* We are in BIDIR mode, trigger the callback and then
2038 * check for new data */
2039 if( cl->url && cl->url->catch[i_msg].cb )
2041 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2044 cl->i_state = HTTPD_CLIENT_WAITING;
2046 else if( i_msg == HTTPD_MSG_CHANNEL )
2048 /* We are in BIDIR mode, trigger the callback and then
2049 * check for new data */
2050 if( cl->url && cl->url->catch[i_msg].cb )
2052 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys,
2055 cl->i_state = HTTPD_CLIENT_WAITING;
2057 else if( i_msg == HTTPD_MSG_OPTIONS )
2059 char *psz_cseq = NULL;
2063 answer->i_proto = query->i_proto ;
2064 answer->i_type = HTTPD_MSG_ANSWER;
2065 answer->i_version= 0;
2066 answer->i_status = 200;
2067 answer->psz_status = strdup( "Ok" );
2070 answer->p_body = NULL;
2072 psz_cseq = httpd_MsgGet( query, "Cseq" );
2074 i_cseq = atoi( psz_cseq );
2077 httpd_MsgAdd( answer, "Cseq", "%d", i_cseq );
2078 httpd_MsgAdd( answer, "Server", "VLC Server" );
2079 httpd_MsgAdd( answer, "Public", "DESCRIBE, SETUP, "
2080 "TEARDOWN, PLAY, PAUSE" );
2081 httpd_MsgAdd( answer, "Content-Length", "%d",
2084 cl->i_buffer = -1; /* Force the creation of the answer in
2085 * httpd_ClientSend */
2086 cl->i_state = HTTPD_CLIENT_SENDING;
2088 else if( i_msg == HTTPD_MSG_NONE )
2090 if( query->i_proto == HTTPD_PROTO_NONE )
2093 cl->i_state = HTTPD_CLIENT_DEAD;
2100 answer->i_proto = query->i_proto ;
2101 answer->i_type = HTTPD_MSG_ANSWER;
2102 answer->i_version= 0;
2103 answer->i_status = 501;
2104 answer->psz_status = strdup( "Unimplemented" );
2106 p = answer->p_body = malloc( 1000 );
2108 p += sprintf( (char *)p,
2109 "<?xml version=\"1.0\" encoding=\"ascii\" ?>"
2110 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2111 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2114 "<title>Error 501</title>\n"
2117 "<h1>501 Unimplemented</h1>\n"
2119 "<a href=\"http://www.videolan.org\">VideoLAN</a>\n"
2123 answer->i_body = p - answer->p_body;
2124 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2126 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2127 cl->i_state = HTTPD_CLIENT_SENDING;
2132 vlc_bool_t b_auth_failed = VLC_FALSE;
2133 vlc_bool_t b_hosts_failed = VLC_FALSE;
2136 /* Search the url and trigger callbacks */
2137 for( i = 0; i < host->i_url; i++ )
2139 httpd_url_t *url = host->url[i];
2141 if( !strcmp( url->psz_url, query->psz_url ) )
2143 if( url->catch[i_msg].cb )
2145 if( answer && ( url->p_acl != NULL ) )
2147 char ip[NI_MAXNUMERICHOST];
2149 if( httpd_ClientIP( cl, ip ) != NULL )
2151 if( ACL_Check( url->p_acl, ip ) )
2153 b_hosts_failed = VLC_TRUE;
2158 b_hosts_failed = VLC_TRUE;
2161 if( answer && ( *url->psz_user || *url->psz_password ) )
2163 /* create the headers */
2164 char *b64 = httpd_MsgGet( query, "Authorization" ); /* BASIC id */
2168 asprintf( &id, "%s:%s", url->psz_user, url->psz_password );
2169 if( b64 ) auth = malloc( strlen(b64) + 1 );
2170 else auth = malloc( strlen("") + 1 );
2173 && !strncasecmp( b64, "BASIC", 5 ) )
2176 while( *b64 == ' ' )
2180 b64_decode( auth, b64 );
2187 if( strcmp( id, auth ) )
2189 httpd_MsgAdd( answer, "WWW-Authenticate", "Basic realm=\"%s\"", url->psz_user );
2190 /* We fail for all url */
2191 b_auth_failed = VLC_TRUE;
2201 if( !url->catch[i_msg].cb( url->catch[i_msg].p_sys, cl, answer, query ) )
2203 if( answer->i_proto == HTTPD_PROTO_NONE )
2205 /* Raw answer from a CGI */
2206 cl->i_buffer = cl->i_buffer_size;
2211 /* only one url can answer */
2213 if( cl->url == NULL )
2226 answer->i_proto = query->i_proto;
2227 answer->i_type = HTTPD_MSG_ANSWER;
2228 answer->i_version= 0;
2229 p = answer->p_body = malloc( 1000 + strlen(query->psz_url) );
2231 if( b_hosts_failed )
2233 answer->i_status = 403;
2234 answer->psz_status = strdup( "Forbidden" );
2236 /* FIXME: lots of code duplication */
2237 p += sprintf( (char *)p,
2238 "<?xml version=\"1.0\" encoding=\"us-ascii\" ?>"
2239 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2240 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2243 "<title>Error 403</title>\n"
2246 "<h1>403 Forbidden (%s)</h1>\n"
2248 "<p><a href=\"http://www.videolan.org\">VideoLAN</a></p>\n"
2250 "</html>\n", query->psz_url );
2252 else if( b_auth_failed )
2254 answer->i_status = 401;
2255 answer->psz_status = strdup( "Authorization Required" );
2257 p += sprintf( (char *)p,
2258 "<?xml version=\"1.0\" encoding=\"us-ascii\" ?>"
2259 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2260 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2263 "<title>Error 401</title>\n"
2266 "<h1>401 Authorization Required (%s)</h1>\n"
2268 "<p><a href=\"http://www.videolan.org\">VideoLAN</a></p>\n"
2270 "</html>\n", query->psz_url );
2274 /* no url registered */
2275 answer->i_status = 404;
2276 answer->psz_status = strdup( "Not found" );
2278 p += sprintf( (char *)p,
2279 "<?xml version=\"1.0\" encoding=\"us-ascii\" ?>"
2280 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
2281 "\"http://www.w3.org/TR/xhtml10/DTD/xhtml10strict.dtd\">\n"
2284 "<title>Error 404</title>\n"
2287 "<h1>404 Resource not found(%s)</h1>\n"
2289 "<p><a href=\"http://www.videolan.org\"> VideoLAN</a></p>\n"
2291 "</html>\n", query->psz_url );
2294 answer->i_body = p - answer->p_body;
2295 cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
2296 httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
2297 httpd_MsgAdd( answer, "Content-Type", "%s", "text/html" );
2300 cl->i_state = HTTPD_CLIENT_SENDING;
2303 else if( cl->i_state == HTTPD_CLIENT_SEND_DONE )
2305 if( cl->i_mode == HTTPD_CLIENT_FILE || cl->answer.i_body_offset == 0 )
2307 char *psz_connection = httpd_MsgGet( &cl->answer, "Connection" );
2308 char *psz_query = httpd_MsgGet( &cl->query, "Connection" );
2309 vlc_bool_t b_connection = VLC_FALSE;
2310 vlc_bool_t b_keepalive = VLC_FALSE;
2311 vlc_bool_t b_query = VLC_FALSE;
2314 if( psz_connection )
2316 b_connection = ( strcasecmp( psz_connection, "Close" ) == 0 );
2317 b_keepalive = ( strcasecmp( psz_connection, "Keep-Alive" ) == 0 );
2322 b_query = ( strcasecmp( psz_query, "Close" ) == 0 );
2325 if( ( ( cl->query.i_proto == HTTPD_PROTO_HTTP ) &&
2326 ( ( cl->answer.i_version == 0 && b_keepalive ) ||
2327 ( cl->answer.i_version == 1 && !b_connection ) ) ) ||
2328 ( ( cl->query.i_proto == HTTPD_PROTO_RTSP ) &&
2329 !b_query && !b_connection ) )
2331 httpd_MsgClean( &cl->query );
2332 httpd_MsgInit( &cl->query );
2335 cl->i_buffer_size = 1000;
2336 free( cl->p_buffer );
2337 cl->p_buffer = malloc( cl->i_buffer_size );
2338 cl->i_state = HTTPD_CLIENT_RECEIVING;
2342 cl->i_state = HTTPD_CLIENT_DEAD;
2344 httpd_MsgClean( &cl->answer );
2346 else if( cl->b_read_waiting )
2348 /* we have a message waiting for us to read it */
2349 httpd_MsgClean( &cl->answer );
2350 httpd_MsgClean( &cl->query );
2353 cl->i_buffer_size = 1000;
2354 free( cl->p_buffer );
2355 cl->p_buffer = malloc( cl->i_buffer_size );
2356 cl->i_state = HTTPD_CLIENT_RECEIVING;
2357 cl->b_read_waiting = VLC_FALSE;
2361 int64_t i_offset = cl->answer.i_body_offset;
2362 httpd_MsgClean( &cl->answer );
2364 cl->answer.i_body_offset = i_offset;
2365 free( cl->p_buffer );
2366 cl->p_buffer = NULL;
2368 cl->i_buffer_size = 0;
2370 cl->i_state = HTTPD_CLIENT_WAITING;
2373 else if( cl->i_state == HTTPD_CLIENT_WAITING )
2375 int64_t i_offset = cl->answer.i_body_offset;
2376 int i_msg = cl->query.i_type;
2378 httpd_MsgInit( &cl->answer );
2379 cl->answer.i_body_offset = i_offset;
2381 cl->url->catch[i_msg].cb( cl->url->catch[i_msg].p_sys, cl,
2382 &cl->answer, &cl->query );
2383 if( cl->answer.i_type != HTTPD_MSG_NONE )
2385 /* we have new data, so reenter send mode */
2387 cl->p_buffer = cl->answer.p_body;
2388 cl->i_buffer_size = cl->answer.i_body;
2389 cl->answer.p_body = NULL;
2390 cl->answer.i_body = 0;
2391 cl->i_state = HTTPD_CLIENT_SENDING;
2395 /* we shouldn't wait too long */
2396 b_low_delay = VLC_TRUE;
2400 /* Special for BIDIR mode we also check reading */
2401 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2402 cl->i_state == HTTPD_CLIENT_SENDING )
2404 FD_SET( cl->fd, &fds_read );
2405 i_handle_max = __MAX( i_handle_max, cl->fd );
2408 vlc_mutex_unlock( &host->lock );
2410 /* we will wait 100ms or 20ms (not too big 'cause HTTPD_CLIENT_WAITING) */
2412 timeout.tv_usec = b_low_delay ? 20000 : 100000;
2414 i_ret = select( i_handle_max + 1,
2415 &fds_read, &fds_write, NULL, &timeout );
2417 if( (i_ret == -1) && (errno != EINTR) )
2419 #if defined(WIN32) || defined(UNDER_CE)
2420 msg_Warn( host, "cannot select sockets (%d)", WSAGetLastError( ) );
2422 msg_Warn( host, "cannot select sockets : %s", strerror( errno ) );
2427 else if( i_ret <= 0 )
2432 /* accept new connections */
2433 for( i_fd = 0; (fd = host->fd[i_fd]) != -1; i_fd++ )
2435 if( FD_ISSET( fd, &fds_read ) )
2437 socklen_t i_sock_size = sizeof( struct sockaddr_storage );
2438 struct sockaddr_storage sock;
2440 fd = accept( fd, (struct sockaddr *)&sock, &i_sock_size );
2446 setsockopt( fd, SOL_SOCKET, SO_REUSEADDR, &i_state, sizeof (i_state));
2449 /* set this new socket non-block */
2450 #if defined( WIN32 ) || defined( UNDER_CE )
2452 unsigned long i_dummy = 1;
2453 ioctlsocket( fd, FIONBIO, &i_dummy );
2456 fcntl( fd, F_SETFD, FD_CLOEXEC );
2458 int i_val = fcntl( fd, F_GETFL );
2460 O_NONBLOCK | ((i_val != -1) ? i_val : 0) );
2463 if( fd >= FD_SETSIZE )
2472 switch ( tls_ServerSessionHandshake( p_tls, fd ) )
2475 msg_Err( host, "Rejecting TLS connection" );
2481 case 1: /* missing input - most likely */
2482 i_state = HTTPD_CLIENT_TLS_HS_IN;
2485 case 2: /* missing output */
2486 i_state = HTTPD_CLIENT_TLS_HS_OUT;
2494 char ip[NI_MAXNUMERICHOST];
2495 stats_UpdateInteger( host, host->p_total_counter,
2497 stats_UpdateInteger( host, host->p_active_counter,
2499 cl = httpd_ClientNew( fd, &sock, i_sock_size, p_tls );
2500 httpd_ClientIP( cl, ip );
2501 msg_Dbg( host, "Connection from %s", ip );
2503 vlc_mutex_lock( &host->lock );
2504 TAB_APPEND( host->i_client, host->client, cl );
2505 vlc_mutex_unlock( &host->lock );
2508 cl->i_state = i_state; // override state for TLS
2514 /* now try all others socket */
2515 vlc_mutex_lock( &host->lock );
2516 for( i_client = 0; i_client < host->i_client; i_client++ )
2518 httpd_client_t *cl = host->client[i_client];
2519 if( cl->i_state == HTTPD_CLIENT_RECEIVING )
2521 httpd_ClientRecv( cl );
2523 else if( cl->i_state == HTTPD_CLIENT_SENDING )
2525 httpd_ClientSend( cl );
2527 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN )
2529 httpd_ClientTlsHsIn( cl );
2531 else if( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT )
2533 httpd_ClientTlsHsOut( cl );
2536 if( cl->i_mode == HTTPD_CLIENT_BIDIR &&
2537 cl->i_state == HTTPD_CLIENT_SENDING &&
2538 FD_ISSET( cl->fd, &fds_read ) )
2540 cl->b_read_waiting = VLC_TRUE;
2543 vlc_mutex_unlock( &host->lock );
2547 tls_ServerSessionClose( p_tls );
2550 #else /* ENABLE_HTTPD */
2552 /* We just define an empty wrapper */
2553 httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, char *b, int c,
2556 msg_Err( a, "HTTP daemon support is disabled" );
2560 httpd_host_t *httpd_HostNew( vlc_object_t *a, char *b, int c )
2562 msg_Err( a, "HTTP daemon support is disabled" );
2566 void httpd_HostDelete( httpd_host_t *a )
2570 httpd_url_t *httpd_UrlNew( httpd_host_t *host, char *psz_url,
2571 char *psz_user, char *psz_password,
2572 const vlc_acl_t *p_acl )
2577 httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, char *psz_url,
2578 char *psz_user, char *psz_password,
2579 const vlc_acl_t *p_acl )
2584 int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c,
2585 httpd_callback_sys_t *d )
2590 void httpd_UrlDelete( httpd_url_t *a )
2594 char* httpd_ClientIP( httpd_client_t *cl, char *psz_ip )
2599 char* httpd_ServerIP( httpd_client_t *cl, char *psz_ip )
2604 void httpd_ClientModeStream( httpd_client_t *a )
2608 void httpd_ClientModeBidir( httpd_client_t *a )
2612 void httpd_FileDelete( httpd_file_t *a )
2616 httpd_file_t *httpd_FileNew( httpd_host_t *a, char *b, char *c, char *d,
2617 char *e, httpd_file_callback_t f,
2618 httpd_file_sys_t *g )
2623 httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url,
2624 const char *psz_user,
2625 const char *psz_password,
2626 const vlc_acl_t *p_acl,
2627 httpd_handler_callback_t pf_fill,
2628 httpd_handler_sys_t *p_sys )
2633 void httpd_HandlerDelete( httpd_handler_t *handler )
2637 void httpd_RedirectDelete( httpd_redirect_t *a )
2641 httpd_redirect_t *httpd_RedirectNew( httpd_host_t *a,
2647 void httpd_StreamDelete( httpd_stream_t *a )
2651 int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c )
2656 int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c )
2661 httpd_stream_t *httpd_StreamNew( httpd_host_t *a, char *b, char *c,
2667 void httpd_MsgInit ( httpd_message_t *a )
2671 void httpd_MsgAdd ( httpd_message_t *a, char *b, char *c, ... )
2675 char *httpd_MsgGet ( httpd_message_t *a, char *b )
2680 void httpd_MsgClean( httpd_message_t *a )
2684 #endif /* ENABLE_HTTPD */