summaryrefslogtreecommitdiff
path: root/test-server
diff options
context:
space:
mode:
authorAndy Green <andy.green@linaro.org>2011-02-13 08:40:37 +0000
committerAndy Green <andy.green@linaro.org>2011-02-13 08:40:37 +0000
commit863d4d25e70a233fd9c378d736945d91ff4582c4 (patch)
tree5f24a05482bc84a40e2c9ecc4c928cfa10d9cbe1 /test-server
parent07034092357547f8c1ff55f30de9052335eab4f3 (diff)
add-example-network-filter-callback.patch
Signed-off-by: Andy Green <andy.green@linaro.org>
Diffstat (limited to 'test-server')
-rw-r--r--test-server/test-server-extpoll.c19
-rw-r--r--test-server/test-server.c22
2 files changed, 41 insertions, 0 deletions
diff --git a/test-server/test-server-extpoll.c b/test-server/test-server-extpoll.c
index e0eced7..725fb95 100644
--- a/test-server/test-server-extpoll.c
+++ b/test-server/test-server-extpoll.c
@@ -99,6 +99,25 @@ static int callback_http(struct libwebsocket *wsi,
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
*/
diff --git a/test-server/test-server.c b/test-server/test-server.c
index 4422d82..f4995c7 100644
--- a/test-server/test-server.c
+++ b/test-server/test-server.c
@@ -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;
}