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

add-example-network-filter-callback.patch

Signed-off-by: Andy Green <andy.green@linaro.org>
This commit is contained in:
Andy Green 2011-02-13 08:40:37 +00:00
parent 0703409235
commit 863d4d25e7
2 changed files with 41 additions and 0 deletions

View file

@ -98,6 +98,25 @@ static int callback_http(struct libwebsocket *wsi,
fprintf(stderr, "Failed to send HTTP file\n");
break;
/*
* callback for confirming to continue with client IP appear in
* protocol 0 callback since no websocket protocol has been agreed
* yet. You can just ignore this if you won't filter on client IP
* since the default uhandled callback return is 0 meaning let the
* connection continue.
*/
case LWS_CALLBACK_FILTER_NETWORK_CONNECTION:
libwebsockets_get_peer_addresses((int)(long)user, client_name,
sizeof(client_name), client_ip, sizeof(client_ip));
fprintf(stderr, "Received network connect from %s (%s)\n",
client_name, client_ip);
/* if we returned non-zero from here, we kill the connection */
break;
/*
* callbacks for managing the external poll() array appear in
* protocol 0 callback

View file

@ -64,6 +64,9 @@ static int callback_http(struct libwebsocket *wsi,
enum libwebsocket_callback_reasons reason, void *user,
void *in, size_t len)
{
char client_name[128];
char client_ip[128];
switch (reason) {
case LWS_CALLBACK_HTTP:
fprintf(stderr, "serving HTTP URI %s\n", (char *)in);
@ -82,6 +85,25 @@ static int callback_http(struct libwebsocket *wsi,
fprintf(stderr, "Failed to send HTTP file\n");
break;
/*
* callback for confirming to continue with client IP appear in
* protocol 0 callback since no websocket protocol has been agreed
* yet. You can just ignore this if you won't filter on client IP
* since the default uhandled callback return is 0 meaning let the
* connection continue.
*/
case LWS_CALLBACK_FILTER_NETWORK_CONNECTION:
libwebsockets_get_peer_addresses((int)(long)user, client_name,
sizeof(client_name), client_ip, sizeof(client_ip));
fprintf(stderr, "Received network connect from %s (%s)\n",
client_name, client_ip);
/* if we returned non-zero from here, we kill the connection */
break;
default:
break;
}