Commit 370c3df3 authored by Rafaël Carré's avatar Rafaël Carré

httpd: use switch, cosmetics

parent 8a8c5e19
...@@ -1732,19 +1732,15 @@ static void httpd_ClientRecv( httpd_client_t *cl ) ...@@ -1732,19 +1732,15 @@ static void httpd_ClientRecv( httpd_client_t *cl )
* mark the end of the body (probably only RTSP) */ * mark the end of the body (probably only RTSP) */
cl->query.p_body = malloc( cl->query.i_body ); cl->query.p_body = malloc( cl->query.i_body );
cl->i_buffer = 0; cl->i_buffer = 0;
if ( cl->query.p_body == NULL ) if ( cl->query.p_body == NULL ) {
{ switch (cl->query.i_proto) {
switch (cl->query.i_proto) case HTTPD_PROTO_HTTP: {
{
case HTTPD_PROTO_HTTP:
{
const uint8_t sorry[] = const uint8_t sorry[] =
"HTTP/1.1 413 Request Entity Too Large\r\n\r\n"; "HTTP/1.1 413 Request Entity Too Large\r\n\r\n";
httpd_NetSend( cl, sorry, sizeof( sorry ) - 1 ); httpd_NetSend( cl, sorry, sizeof( sorry ) - 1 );
break; break;
} }
case HTTPD_PROTO_RTSP: case HTTPD_PROTO_RTSP: {
{
const uint8_t sorry[] = const uint8_t sorry[] =
"RTSP/1.0 413 Request Entity Too Large\r\n\r\n"; "RTSP/1.0 413 Request Entity Too Large\r\n\r\n";
httpd_NetSend( cl, sorry, sizeof( sorry ) - 1 ); httpd_NetSend( cl, sorry, sizeof( sorry ) - 1 );
...@@ -1919,23 +1915,11 @@ static void httpd_ClientSend( httpd_client_t *cl ) ...@@ -1919,23 +1915,11 @@ static void httpd_ClientSend( httpd_client_t *cl )
static void httpd_ClientTlsHandshake( httpd_client_t *cl ) static void httpd_ClientTlsHandshake( httpd_client_t *cl )
{ {
switch( vlc_tls_SessionHandshake( cl->p_tls, NULL, NULL ) ) switch( vlc_tls_SessionHandshake( cl->p_tls, NULL, NULL ) ) {
{ case -1: cl->i_state = HTTPD_CLIENT_DEAD; break;
case 0: case 0: cl->i_state = HTTPD_CLIENT_RECEIVING; break;
cl->i_state = HTTPD_CLIENT_RECEIVING; case 1: cl->i_state = HTTPD_CLIENT_TLS_HS_IN; break;
break; case 2: cl->i_state = HTTPD_CLIENT_TLS_HS_OUT; break;
case -1:
cl->i_state = HTTPD_CLIENT_DEAD;
break;
case 1:
cl->i_state = HTTPD_CLIENT_TLS_HS_IN;
break;
case 2:
cl->i_state = HTTPD_CLIENT_TLS_HS_OUT;
break;
} }
} }
...@@ -1971,6 +1955,7 @@ static void* httpd_HostThread( void *data ) ...@@ -1971,6 +1955,7 @@ static void* httpd_HostThread( void *data )
for(int i_client = 0; i_client < host->i_client; i_client++ ) for(int i_client = 0; i_client < host->i_client; i_client++ )
{ {
int64_t i_offset;
httpd_client_t *cl = host->client[i_client]; httpd_client_t *cl = host->client[i_client];
if( cl->i_ref < 0 || ( cl->i_ref == 0 && if( cl->i_ref < 0 || ( cl->i_ref == 0 &&
( cl->i_state == HTTPD_CLIENT_DEAD || ( cl->i_state == HTTPD_CLIENT_DEAD ||
...@@ -1990,33 +1975,32 @@ static void* httpd_HostThread( void *data ) ...@@ -1990,33 +1975,32 @@ static void* httpd_HostThread( void *data )
pufd->fd = cl->fd; pufd->fd = cl->fd;
pufd->events = pufd->revents = 0; pufd->events = pufd->revents = 0;
if( ( cl->i_state == HTTPD_CLIENT_RECEIVING ) switch (cl->i_state) {
|| ( cl->i_state == HTTPD_CLIENT_TLS_HS_IN ) ) case HTTPD_CLIENT_RECEIVING:
{ case HTTPD_CLIENT_TLS_HS_IN:
pufd->events = POLLIN; pufd->events = POLLIN;
} break;
else if( ( cl->i_state == HTTPD_CLIENT_SENDING )
|| ( cl->i_state == HTTPD_CLIENT_TLS_HS_OUT ) ) case HTTPD_CLIENT_SENDING:
{ case HTTPD_CLIENT_TLS_HS_OUT:
pufd->events = POLLOUT; pufd->events = POLLOUT;
} break;
else if( cl->i_state == HTTPD_CLIENT_RECEIVE_DONE )
case HTTPD_CLIENT_RECEIVE_DONE:
{ {
httpd_message_t *answer = &cl->answer; httpd_message_t *answer = &cl->answer;
httpd_message_t *query = &cl->query; httpd_message_t *query = &cl->query;
int i_msg = query->i_type;
httpd_MsgInit( answer ); httpd_MsgInit( answer );
/* Handle what we received */ /* Handle what we received */
if( i_msg == HTTPD_MSG_ANSWER ) switch (query->i_type) {
{ case HTTPD_MSG_ANSWER:
cl->url = NULL; cl->url = NULL;
cl->i_state = HTTPD_CLIENT_DEAD; cl->i_state = HTTPD_CLIENT_DEAD;
} break;
else if( i_msg == HTTPD_MSG_OPTIONS )
{
case HTTPD_MSG_OPTIONS:
answer->i_type = HTTPD_MSG_ANSWER; answer->i_type = HTTPD_MSG_ANSWER;
answer->i_proto = query->i_proto; answer->i_proto = query->i_proto;
answer->i_status = 200; answer->i_status = 200;
...@@ -2030,16 +2014,13 @@ static void* httpd_HostThread( void *data ) ...@@ -2030,16 +2014,13 @@ static void* httpd_HostThread( void *data )
{ {
case HTTPD_PROTO_HTTP: case HTTPD_PROTO_HTTP:
answer->i_version = 1; answer->i_version = 1;
httpd_MsgAdd( answer, "Allow", httpd_MsgAdd(answer, "Allow", "GET,HEAD,POST,OPTIONS");
"GET,HEAD,POST,OPTIONS" );
break; break;
case HTTPD_PROTO_RTSP: case HTTPD_PROTO_RTSP:
{
const char *p;
answer->i_version = 0; answer->i_version = 0;
p = httpd_MsgGet( query, "Cseq" ); const char *p = httpd_MsgGet( query, "Cseq" );
if( p != NULL ) if( p != NULL )
httpd_MsgAdd( answer, "Cseq", "%s", p ); httpd_MsgAdd( answer, "Cseq", "%s", p );
p = httpd_MsgGet( query, "Timestamp" ); p = httpd_MsgGet( query, "Timestamp" );
...@@ -2047,8 +2028,7 @@ static void* httpd_HostThread( void *data ) ...@@ -2047,8 +2028,7 @@ static void* httpd_HostThread( void *data )
httpd_MsgAdd( answer, "Timestamp", "%s", p ); httpd_MsgAdd( answer, "Timestamp", "%s", p );
p = httpd_MsgGet( query, "Require" ); p = httpd_MsgGet( query, "Require" );
if( p != NULL ) if( p != NULL ) {
{
answer->i_status = 551; answer->i_status = 551;
httpd_MsgAdd( query, "Unsupported", "%s", p ); httpd_MsgAdd( query, "Unsupported", "%s", p );
} }
...@@ -2057,29 +2037,25 @@ static void* httpd_HostThread( void *data ) ...@@ -2057,29 +2037,25 @@ static void* httpd_HostThread( void *data )
"TEARDOWN,PLAY,PAUSE,GET_PARAMETER" ); "TEARDOWN,PLAY,PAUSE,GET_PARAMETER" );
break; break;
} }
}
cl->i_buffer = -1; /* Force the creation of the answer in cl->i_buffer = -1; /* Force the creation of the answer in
* httpd_ClientSend */ * httpd_ClientSend */
cl->i_state = HTTPD_CLIENT_SENDING; cl->i_state = HTTPD_CLIENT_SENDING;
} break;
else if( i_msg == HTTPD_MSG_NONE )
{ case HTTPD_MSG_NONE:
if( query->i_proto == HTTPD_PROTO_NONE ) if( query->i_proto == HTTPD_PROTO_NONE ) {
{
cl->url = NULL; cl->url = NULL;
cl->i_state = HTTPD_CLIENT_DEAD; cl->i_state = HTTPD_CLIENT_DEAD;
} }
else else {
{
char *p;
/* unimplemented */ /* unimplemented */
answer->i_proto = query->i_proto ; answer->i_proto = query->i_proto ;
answer->i_type = HTTPD_MSG_ANSWER; answer->i_type = HTTPD_MSG_ANSWER;
answer->i_version= 0; answer->i_version= 0;
answer->i_status = 501; answer->i_status = 501;
char *p;
answer->i_body = httpd_HtmlError (&p, 501, NULL); answer->i_body = httpd_HtmlError (&p, 501, NULL);
answer->p_body = (uint8_t *)p; answer->p_body = (uint8_t *)p;
httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body ); httpd_MsgAdd( answer, "Content-Length", "%d", answer->i_body );
...@@ -2087,9 +2063,10 @@ static void* httpd_HostThread( void *data ) ...@@ -2087,9 +2063,10 @@ static void* httpd_HostThread( void *data )
cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */ cl->i_buffer = -1; /* Force the creation of the answer in httpd_ClientSend */
cl->i_state = HTTPD_CLIENT_SENDING; cl->i_state = HTTPD_CLIENT_SENDING;
} }
} break;
else
{ default: {
int i_msg = query->i_type;
bool b_auth_failed = false; bool b_auth_failed = false;
/* Search the url and trigger callbacks */ /* Search the url and trigger callbacks */
...@@ -2191,8 +2168,10 @@ static void* httpd_HostThread( void *data ) ...@@ -2191,8 +2168,10 @@ static void* httpd_HostThread( void *data )
cl->i_state = HTTPD_CLIENT_SENDING; cl->i_state = HTTPD_CLIENT_SENDING;
} }
} }
else if( cl->i_state == HTTPD_CLIENT_SEND_DONE ) }
{ break;
case HTTPD_CLIENT_SEND_DONE:
if( !cl->b_stream_mode || cl->answer.i_body_offset == 0 ) if( !cl->b_stream_mode || cl->answer.i_body_offset == 0 )
{ {
const char *psz_connection = httpd_MsgGet( &cl->answer, "Connection" ); const char *psz_connection = httpd_MsgGet( &cl->answer, "Connection" );
...@@ -2236,7 +2215,7 @@ static void* httpd_HostThread( void *data ) ...@@ -2236,7 +2215,7 @@ static void* httpd_HostThread( void *data )
} }
else else
{ {
int64_t i_offset = cl->answer.i_body_offset; i_offset = cl->answer.i_body_offset;
httpd_MsgClean( &cl->answer ); httpd_MsgClean( &cl->answer );
cl->answer.i_body_offset = i_offset; cl->answer.i_body_offset = i_offset;
...@@ -2247,10 +2226,10 @@ static void* httpd_HostThread( void *data ) ...@@ -2247,10 +2226,10 @@ static void* httpd_HostThread( void *data )
cl->i_state = HTTPD_CLIENT_WAITING; cl->i_state = HTTPD_CLIENT_WAITING;
} }
} break;
else if( cl->i_state == HTTPD_CLIENT_WAITING )
{ case HTTPD_CLIENT_WAITING:
int64_t i_offset = cl->answer.i_body_offset; i_offset = cl->answer.i_body_offset;
int i_msg = cl->query.i_type; int i_msg = cl->query.i_type;
httpd_MsgInit( &cl->answer ); httpd_MsgInit( &cl->answer );
...@@ -2283,14 +2262,11 @@ static void* httpd_HostThread( void *data ) ...@@ -2283,14 +2262,11 @@ static void* httpd_HostThread( void *data )
canc = vlc_savecancel(); canc = vlc_savecancel();
vlc_mutex_lock( &host->lock ); vlc_mutex_lock( &host->lock );
switch( ret ) switch( ret ) {
{
case -1: case -1:
if (errno != EINTR) if (errno != EINTR) {
{
/* Kernel on low memory or a bug: pace */ /* Kernel on low memory or a bug: pace */
msg_Err( host, "polling error: %s", msg_Err( host, "polling error: %s", vlc_strerror_c(errno) );
vlc_strerror_c(errno) );
msleep( 100000 ); msleep( 100000 );
} }
case 0: case 0:
...@@ -2316,18 +2292,11 @@ static void* httpd_HostThread( void *data ) ...@@ -2316,18 +2292,11 @@ static void* httpd_HostThread( void *data )
cl->i_activity_date = now; cl->i_activity_date = now;
if( cl->i_state == HTTPD_CLIENT_RECEIVING ) switch (cl->i_state) {
{ case HTTPD_CLIENT_RECEIVING: httpd_ClientRecv( cl ); break;
httpd_ClientRecv( cl ); case HTTPD_CLIENT_SENDING: httpd_ClientSend( cl ); break;
} case HTTPD_CLIENT_TLS_HS_IN:
else if( cl->i_state == HTTPD_CLIENT_SENDING ) case HTTPD_CLIENT_TLS_HS_OUT: httpd_ClientTlsHandshake( cl ); break;
{
httpd_ClientSend( cl );
}
else if( cl->i_state == HTTPD_CLIENT_TLS_HS_IN
|| cl->i_state == HTTPD_CLIENT_TLS_HS_OUT )
{
httpd_ClientTlsHandshake( cl );
} }
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment