X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=src%2Fnetwork%2Fhttpd.c;h=546a77eee4937347d132203bee9755b4fe9774a6;hb=8bda7d7287446b0f5b54fe69c07d600cb0bbd1a2;hp=544410cf467c27b09e162c50aaec2a4f56009c00;hpb=d804de7dac7b0e414c23360396a08f29ffe85e09;p=vlc diff --git a/src/network/httpd.c b/src/network/httpd.c index 544410cf46..546a77eee4 100644 --- a/src/network/httpd.c +++ b/src/network/httpd.c @@ -27,11 +27,9 @@ # include "config.h" #endif -#include +#include #include -#ifdef ENABLE_HTTPD - #include #include @@ -189,7 +187,7 @@ struct httpd_client_t /***************************************************************************** * Various functions *****************************************************************************/ -static struct +static const struct { const char psz_ext[8]; const char *psz_mime; @@ -394,7 +392,6 @@ httpd_FileCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, httpd_message_t *answer, const httpd_message_t *query ) { httpd_file_t *file = (httpd_file_t*)p_sys; - uint8_t *psz_args = query->psz_args; uint8_t **pp_body, *p_body; const char *psz_connection; int *pi_body, i_body; @@ -431,6 +428,7 @@ httpd_FileCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, /* msg_Warn not supported */ } + uint8_t *psz_args = query->psz_args; file->pf_fill( file->p_sys, file, psz_args, pp_body, pi_body ); if( query->i_type == HTTPD_MSG_HEAD && p_body != NULL ) @@ -520,7 +518,6 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, httpd_message_t *answer, const httpd_message_t *query ) { httpd_handler_t *handler = (httpd_handler_t*)p_sys; - uint8_t *psz_args = query->psz_args; char psz_remote_addr[NI_MAXNUMERICHOST]; if( answer == NULL || query == NULL ) @@ -536,6 +533,7 @@ httpd_HandlerCallBack( httpd_callback_sys_t *p_sys, httpd_client_t *cl, if( httpd_ClientIP( cl, psz_remote_addr ) == NULL ) *psz_remote_addr = '\0'; + uint8_t *psz_args = query->psz_args; handler->pf_fill( handler->p_sys, handler, query->psz_url, psz_args, query->i_type, query->p_body, query->i_body, psz_remote_addr, NULL, @@ -960,7 +958,7 @@ void httpd_StreamDelete( httpd_stream_t *stream ) /***************************************************************************** * Low level *****************************************************************************/ -static void httpd_HostThread( httpd_host_t * ); +static void* httpd_HostThread( vlc_object_t * ); /* create a new host */ httpd_host_t *httpd_HostNew( vlc_object_t *p_this, const char *psz_host, @@ -989,10 +987,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname, psz_host = strdup( psz_hostname ); if( psz_host == NULL ) - { - msg_Err( p_this, "memory error" ); return NULL; - } /* to be sure to avoid multiple creation */ var_Create( p_this->p_libvlc, "httpd_mutex", VLC_VAR_MUTEX ); @@ -1018,7 +1013,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname, ptrval.p_address = httpd; libvlc_priv (p_this->p_libvlc)->p_httpd = httpd; - vlc_object_yield( httpd ); + vlc_object_hold( httpd ); vlc_object_attach( httpd, p_this->p_libvlc ); } @@ -1069,7 +1064,7 @@ httpd_host_t *httpd_TLSHostNew( vlc_object_t *p_this, const char *psz_hostname, /* create the new host */ host = (httpd_host_t *)vlc_custom_create( p_this, sizeof (*host), - VLC_OBJECT_HTTPD_HOST, + VLC_OBJECT_GENERIC, psz_object_type ); if (host == NULL) goto error; @@ -1123,6 +1118,7 @@ error: free( psz_host ); if( httpd->i_host <= 0 ) { + libvlc_priv (httpd->p_libvlc)->p_httpd = NULL; vlc_object_release( httpd ); vlc_object_detach( httpd ); vlc_object_release( httpd ); @@ -1310,7 +1306,7 @@ void httpd_UrlDelete( httpd_url_t *url ) vlc_mutex_unlock( &host->lock ); } -void httpd_MsgInit( httpd_message_t *msg ) +static void httpd_MsgInit( httpd_message_t *msg ) { msg->cl = NULL; msg->i_type = HTTPD_MSG_NONE; @@ -1334,7 +1330,7 @@ void httpd_MsgInit( httpd_message_t *msg ) msg->p_body = NULL; } -void httpd_MsgClean( httpd_message_t *msg ) +static void httpd_MsgClean( httpd_message_t *msg ) { int i; @@ -1457,26 +1453,32 @@ static httpd_client_t *httpd_ClientNew( int fd, tls_session_t *p_tls, mtime_t no return cl; } -static int httpd_NetRecv( httpd_client_t *cl, uint8_t *p, int i_len ) +static +ssize_t httpd_NetRecv (httpd_client_t *cl, uint8_t *p, size_t i_len) { tls_session_t *p_tls; + ssize_t val; p_tls = cl->p_tls; - if( p_tls != NULL) - return tls_Recv( p_tls, p, i_len ); - - return recv( cl->fd, p, i_len, 0 ); + do + val = p_tls ? tls_Recv (p_tls, p, i_len) + : recv (cl->fd, p, i_len, 0); + while (val == -1 && errno == EINTR); + return val; } -static int httpd_NetSend( httpd_client_t *cl, const uint8_t *p, int i_len ) +static +ssize_t httpd_NetSend (httpd_client_t *cl, const uint8_t *p, size_t i_len) { tls_session_t *p_tls; + ssize_t val; p_tls = cl->p_tls; - if( p_tls != NULL) - return tls_Send( p_tls, p, i_len ); - - return send( cl->fd, p, i_len, 0 ); + do + val = p_tls ? tls_Send( p_tls, p, i_len ) + : send (cl->fd, p, i_len, 0); + while (val == -1 && errno == EINTR); + return val; } @@ -1830,7 +1832,7 @@ static void httpd_ClientRecv( httpd_client_t *cl ) #if defined( WIN32 ) || defined( UNDER_CE ) if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) ) #else - if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) ) + if( ( i_len < 0 && errno != EAGAIN ) || ( i_len == 0 ) ) #endif { if( cl->query.i_proto != HTTPD_PROTO_NONE && cl->query.i_type != HTTPD_MSG_NONE ) @@ -1970,7 +1972,7 @@ static void httpd_ClientSend( httpd_client_t *cl ) #if defined( WIN32 ) || defined( UNDER_CE ) if( ( i_len < 0 && WSAGetLastError() != WSAEWOULDBLOCK ) || ( i_len == 0 ) ) #else - if( ( i_len < 0 && errno != EAGAIN && errno != EINTR ) || ( i_len == 0 ) ) + if( ( i_len < 0 && errno != EAGAIN ) || ( i_len == 0 ) ) #endif { /* error */ @@ -2016,14 +2018,17 @@ static void httpd_ClientTlsHsOut( httpd_client_t *cl ) } } -static void httpd_HostThread( httpd_host_t *host ) +static void* httpd_HostThread( vlc_object_t *p_this ) { + httpd_host_t *host = (httpd_host_t *)p_this; tls_session_t *p_tls = NULL; counter_t *p_total_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER ); counter_t *p_active_counter = stats_CounterCreate( host, VLC_VAR_INTEGER, STATS_COUNTER ); int evfd; bool b_die; + int canc = vlc_savecancel (); +retry: vlc_object_lock( host ); evfd = vlc_object_waitpipe( VLC_OBJECT( host ) ); b_die = !vlc_object_alive( host ); @@ -2035,7 +2040,7 @@ static void httpd_HostThread( httpd_host_t *host ) { /* 0.2s (FIXME: use a condition variable) */ msleep( 200000 ); - continue; + goto retry; } /* prepare a new TLS session */ @@ -2345,8 +2350,8 @@ static void httpd_HostThread( httpd_host_t *host ) } if( ( ( cl->query.i_proto == HTTPD_PROTO_HTTP ) && - ( ( cl->answer.i_version == 0 && b_keepalive ) || - ( cl->answer.i_version == 1 && !b_connection ) ) ) || + ( ( cl->query.i_version == 0 && b_keepalive ) || + ( cl->query.i_version == 1 && !b_connection ) ) ) || ( ( cl->query.i_proto == HTTPD_PROTO_RTSP ) && !b_query && !b_connection ) ) { @@ -2452,7 +2457,7 @@ static void httpd_HostThread( httpd_host_t *host ) { b_die = !vlc_object_alive( host ); if( !b_die ) - b_die = vlc_object_wait( host ); + vlc_object_wait( host ); } vlc_object_unlock( host ); @@ -2563,149 +2568,6 @@ static void httpd_HostThread( httpd_host_t *host ) stats_CounterClean( p_total_counter ); if( p_active_counter ) stats_CounterClean( p_active_counter ); -} - -#else /* ENABLE_HTTPD */ - -/* We just define an empty wrapper */ -httpd_host_t *httpd_TLSHostNew( vlc_object_t *a, const char *b, - int c, - const char *e, const char *f, - const char *g, const char* h) -{ - msg_Err( a, "HTTP daemon support is disabled" ); + vlc_restorecancel (canc); return NULL; } - -httpd_host_t *httpd_HostNew( vlc_object_t *a, const char *b, - int c ) -{ - msg_Err( a, "HTTP daemon support is disabled" ); - return NULL; -} - -void httpd_HostDelete( httpd_host_t *a ) -{ -} - -httpd_url_t *httpd_UrlNew( httpd_host_t *host, const char *psz_url, - const char *psz_user, const char *psz_password, - const vlc_acl_t *p_acl ) -{ - return NULL; -} - -httpd_url_t *httpd_UrlNewUnique( httpd_host_t *host, const char *psz_url, - const char *psz_user, const char *psz_password, - const vlc_acl_t *p_acl ) -{ - return NULL; -} - -int httpd_UrlCatch( httpd_url_t *a, int b, httpd_callback_t c, - httpd_callback_sys_t *d ) -{ - return 0; -} - -void httpd_UrlDelete( httpd_url_t *a ) -{ -} - -char* httpd_ClientIP( const httpd_client_t *cl, char *psz_ip ) -{ - return NULL; -} - -char* httpd_ServerIP( const httpd_client_t *cl, char *psz_ip ) -{ - return NULL; -} - -void httpd_ClientModeStream( httpd_client_t *a ) -{ -} - -void httpd_ClientModeBidir( httpd_client_t *a ) -{ -} - -httpd_file_sys_t *httpd_FileDelete( httpd_file_t *file ) -{ - return NULL; -} - -httpd_file_t *httpd_FileNew( httpd_host_t *host, - const char *psz_url, const char *psz_mime, - const char *psz_user, const char *psz_password, - const vlc_acl_t *p_acl, httpd_file_callback_t pf_fill, - httpd_file_sys_t *p_sys ) -{ - return NULL; -} - -httpd_handler_t *httpd_HandlerNew( httpd_host_t *host, const char *psz_url, - const char *psz_user, - const char *psz_password, - const vlc_acl_t *p_acl, - httpd_handler_callback_t pf_fill, - httpd_handler_sys_t *p_sys ) -{ - return NULL; -} - -httpd_handler_sys_t *httpd_HandlerDelete( httpd_handler_t *handler ) -{ - return NULL; -} - -void httpd_RedirectDelete( httpd_redirect_t *a ) -{ -} - -httpd_redirect_t *httpd_RedirectNew( httpd_host_t *host, const char *psz_url_dst, - const char *psz_url_src ) -{ - return NULL; -} - -void httpd_StreamDelete( httpd_stream_t *a ) -{ -} - -int httpd_StreamHeader( httpd_stream_t *a, uint8_t *b, int c ) -{ - return 0; -} - -int httpd_StreamSend ( httpd_stream_t *a, uint8_t *b, int c ) -{ - return 0; -} - -httpd_stream_t *httpd_StreamNew( httpd_host_t *host, - const char *psz_url, const char *psz_mime, - const char *psz_user, const char *psz_password, - const vlc_acl_t *p_acl ) -{ - return NULL; -} - -void httpd_MsgInit ( httpd_message_t *a ) -{ -} - -void httpd_MsgAdd ( httpd_message_t *a, const char *b, const char *c, ... ) -{ -} - -const char *httpd_MsgGet( const httpd_message_t *msg, const char *name ) -{ - return ""; -} - -void httpd_MsgClean( httpd_message_t *a ) -{ -} - -#endif /* ENABLE_HTTPD */