[Libwebsockets] How to retain info from LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION

"Andy Green (林安廸)" andy at warmcat.com
Wed Sep 18 02:54:29 CEST 2013


On 18/09/13 04:25, the mail apparently from Daniel Griscom included:
> I know the LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION callback is meant for
> the server to examine the incoming connection's headers and allow or
> deny the connection based on the header values. This is also the only
> place the header values are available, since they are then immediately
> discarded.
>
> Problem: I want to retain information from the headers for use in the
> ensuing connection. For example, I want to save the WSI_TOKEN_GET_URI
> value and then handle the connection differently based on the URI. But,
> the void *user parameter of the callback, which later is used to
> maintain connection-specific information, is used for a pointer to the
> requested websocket protocol.
>
> How can I save the header information for later use in the connection?
> Can I depend that, if I allow the connection in the
> LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION callback, the next
> LWS_CALLBACK_ESTABLISHED callback will always be for the same connection
> request?
>
>
> Thanks,
> Dan
>
>
> P.S. It looks like the API documentation for the
> LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION callback is incorrect. It claims
> that the user pointer is to an array of struct lws_tokens, but that
> seems to not be true. user points to a string giving the requested
> protocol, and the actual headers are accessed through the struct
> libwebsocket pointer (as shown in the accompanying
> test-server/test-server.c).

Right... this should fix it

http://git.libwebsockets.org/cgi-bin/cgit/libwebsockets/commit/?id=96d48fdc285b6c44dbd7ea39ddbcce62a11624e1

Previously this callback happens before the user_space is allocated, I 
changed it to exist now and use the "user" callback parameter.

The docs are corrected with an explanation of how to find the headers 
and changelog updated in that commit.

The header data will still get deleted after this, but you have a chance 
to copy it into your user struct now.

-Andy



More information about the Libwebsockets mailing list