!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;
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);
if (!wsi->protocol)
lwsl_err("NULL protocol at libwebsocket_read\n");
-
/*
* It's websocket
*
}
/*
- * 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
*/
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 */
bail:
lwsl_info("closing connection at libwebsocket_read bail:\n");
+
libwebsocket_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
}
#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);
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,
* 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
*
}
}
- 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;
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;
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;
}
*/
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;
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