1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

headers deleted after websocket established

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2013-02-06 15:15:25 +09:00
parent e4dffc99df
commit 2b57a34677
8 changed files with 72 additions and 31 deletions

View file

@ -594,10 +594,25 @@ check_accept:
!libwebsocket_ensure_user_space(wsi))
goto bail2;
/*
* we seem to be good to go, give client last chance to check
* headers and OK it
*/
wsi->protocol->callback(context, wsi,
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
wsi->user_space, NULL, 0);
/* clear his proxy connection timeout */
libwebsocket_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
/* free up his parsing allocations */
for (n = 0; n < WSI_TOKEN_COUNT; n++)
if (wsi->utf8_token[n].token)
free(wsi->utf8_token[n].token);
/* mark him as being alive */
wsi->state = WSI_STATE_ESTABLISHED;
@ -645,6 +660,12 @@ bail2:
wsi->user_space,
NULL, 0);
lwsl_info("closing connection due to bail2 connection error\n");
/* free up his parsing allocations */
for (n = 0; n < WSI_TOKEN_COUNT; n++)
if (wsi->utf8_token[n].token)
free(wsi->utf8_token[n].token);
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_PROTOCOL_ERR);

View file

@ -131,7 +131,6 @@ libwebsocket_read(struct libwebsocket_context *context,
if (!wsi->protocol)
lwsl_err("NULL protocol at libwebsocket_read\n");
/*
* It's websocket
*
@ -167,15 +166,6 @@ libwebsocket_read(struct libwebsocket_context *context,
}
}
/*
* find out which spec version the client is using
* if this header is not given, we default to 00 (aka 76)
*/
if (wsi->utf8_token[WSI_TOKEN_VERSION].token_len)
wsi->ietf_spec_revision =
atoi(wsi->utf8_token[WSI_TOKEN_VERSION].token);
/*
* Give the user code a chance to study the request and
* have the opportunity to deny it
@ -209,6 +199,14 @@ libwebsocket_read(struct libwebsocket_context *context,
goto bail;
}
/* drop the header info */
/* free up his parsing allocations... these are gone... */
for (n = 0; n < WSI_TOKEN_COUNT; n++)
if (wsi->utf8_token[n].token)
free(wsi->utf8_token[n].token);
wsi->mode = LWS_CONNMODE_WS_SERVING;
/* union transition */
@ -253,6 +251,7 @@ libwebsocket_read(struct libwebsocket_context *context,
bail:
lwsl_info("closing connection at libwebsocket_read bail:\n");
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);

View file

@ -348,11 +348,6 @@ just_kill_connection:
}
#endif
/* free up his parsing allocations */
for (n = 0; n < WSI_TOKEN_COUNT; n++)
if (wsi->utf8_token[n].token)
free(wsi->utf8_token[n].token);
#ifndef LWS_NO_CLIENT
if (wsi->c_address)
free(wsi->c_address);

View file

@ -124,6 +124,7 @@ enum libwebsocket_context_options {
enum libwebsocket_callback_reasons {
LWS_CALLBACK_ESTABLISHED,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR,
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH,
LWS_CALLBACK_CLIENT_ESTABLISHED,
LWS_CALLBACK_CLOSED,
LWS_CALLBACK_RECEIVE,
@ -377,12 +378,20 @@ struct libwebsocket_extension;
* You get an opportunity to initialize user data when called back with
* LWS_CALLBACK_ESTABLISHED reason.
*
* LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with
* LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with
* an incoming client
*
* LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has
* been unable to complete a handshake with the remote server
*
* LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for the
* client user code to examine the http headers
* and decide to reject the connection. If the
* content in the headers is interesting to the
* client (url, etc) it needs to copy it out at
* this point since it will be destroyed before
* the CLIENT_ESTABLISHED call
*
* LWS_CALLBACK_CLIENT_ESTABLISHED: after your client connection completed
* a handshake with the remote server
*

View file

@ -470,8 +470,14 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
}
}
if (wsi->u.hdr.parser_state == WSI_TOKEN_CHALLENGE)
if (wsi->u.hdr.parser_state == WSI_TOKEN_CHALLENGE) {
if (wsi->utf8_token[WSI_TOKEN_CHALLENGE].token) {
free(wsi->utf8_token[WSI_TOKEN_CHALLENGE].token);
wsi->utf8_token[WSI_TOKEN_CHALLENGE].token = NULL;
}
wsi->utf8_token[WSI_TOKEN_CHALLENGE].token_len = 0;
goto set_parsing_complete;
}
break;
@ -504,14 +510,16 @@ int libwebsocket_parse(struct libwebsocket *wsi, unsigned char c)
set_parsing_complete:
if (!wsi->utf8_token[WSI_TOKEN_VERSION].token_len) {
lwsl_info("Missing Version Header\n");
return 1;
}
wsi->ietf_spec_revision =
atoi(wsi->utf8_token[WSI_TOKEN_VERSION].token);
if (wsi->utf8_token[WSI_TOKEN_UPGRADE].token_len) {
if (!wsi->utf8_token[WSI_TOKEN_VERSION].token_len) {
// lwsl_info("Missing Version Header\n");
// return 1;
} else
wsi->ietf_spec_revision =
atoi(wsi->utf8_token[WSI_TOKEN_VERSION].token);
lwsl_parser("v%02d headers completed\n", wsi->ietf_spec_revision);
lwsl_parser("v%02d headers completed\n", wsi->ietf_spec_revision);
}
wsi->u.hdr.parser_state = WSI_PARSING_COMPLETE;
return 0;

View file

@ -270,6 +270,12 @@ handshake_0405(struct libwebsocket_context *context, struct libwebsocket *wsi)
bail:
/* free up his parsing allocations */
for (n = 0; n < WSI_TOKEN_COUNT; n++)
if (wsi->utf8_token[n].token)
free(wsi->utf8_token[n].token);
return -1;
}

View file

@ -118,13 +118,6 @@ libwebsocket_create_new_server_wsi(struct libwebsocket_context *context)
*/
new_wsi->protocol = context->protocols;
new_wsi->user_space = NULL;
/*
* Default protocol is 76 / 00
* After 76, there's a header specified to inform which
* draft the client wants, when that's seen we modify
* the individual connection's spec revision accordingly
*/
new_wsi->ietf_spec_revision = 0;
return new_wsi;

View file

@ -604,6 +604,16 @@ an incoming client
the request client connection has
been unable to complete a handshake with the remote server
</blockquote>
<h3>LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH</h3>
<blockquote>
this is the last chance for the
client user code to examine the http headers
and decide to reject the connection. If the
content in the headers is interesting to the
client (url, etc) it needs to copy it out at
this point since it will be destroyed before
the CLIENT_ESTABLISHED call
</blockquote>
<h3>LWS_CALLBACK_CLIENT_ESTABLISHED</h3>
<blockquote>
after your client connection completed