test server add lws_status
[platform/upstream/libwebsockets.git] / test-server / test-server.h
1 /*
2  * libwebsockets-test-server - libwebsockets test implementation
3  *
4  * Copyright (C) 2010-2016 Andy Green <andy@warmcat.com>
5  *
6  * This file is made available under the Creative Commons CC0 1.0
7  * Universal Public Domain Dedication.
8  *
9  * The person who associated a work with this deed has dedicated
10  * the work to the public domain by waiving all of his or her rights
11  * to the work worldwide under copyright law, including all related
12  * and neighboring rights, to the extent allowed by law. You can copy,
13  * modify, distribute and perform the work, even for commercial purposes,
14  * all without asking permission.
15  *
16  * The test apps are intended to be adapted for use in your code, which
17  * may be proprietary.  So unlike the library itself, they are licensed
18  * Public Domain.
19  */
20
21 #if defined(_WIN32) && defined(EXTERNAL_POLL)
22 #define WINVER 0x0600
23 #define _WIN32_WINNT 0x0600
24 #define poll(fdArray, fds, timeout)  WSAPoll((LPWSAPOLLFD)(fdArray), (ULONG)(fds), (INT)(timeout))
25 #endif
26
27 #include "lws_config.h"
28
29 #include <stdio.h>
30 #include <stdlib.h>
31 #include <getopt.h>
32 #include <signal.h>
33 #include <string.h>
34 #include <sys/stat.h>
35 #include <fcntl.h>
36 #include <assert.h>
37
38 #include "../lib/libwebsockets.h"
39
40 #ifdef _WIN32
41 #include <io.h>
42 #include "gettimeofday.h"
43 #else
44 #include <syslog.h>
45 #include <sys/time.h>
46 #include <unistd.h>
47 #endif
48
49 extern int close_testing;
50 extern int max_poll_elements;
51
52 #ifdef EXTERNAL_POLL
53 extern struct lws_pollfd *pollfds;
54 extern int *fd_lookup;
55 extern int count_pollfds;
56 #endif
57 extern volatile int force_exit;
58 extern struct lws_context *context;
59 extern char *resource_path;
60
61 extern void test_server_lock(int care);
62 extern void test_server_unlock(int care);
63
64 #ifndef __func__
65 #define __func__ __FUNCTION__
66 #endif
67
68 struct per_session_data__http {
69         lws_filefd_type fd;
70 };
71
72 /*
73  * one of these is auto-created for each connection and a pointer to the
74  * appropriate instance is passed to the callback in the user parameter
75  *
76  * for this example protocol we use it to individualize the count for each
77  * connection.
78  */
79
80 struct per_session_data__dumb_increment {
81         int number;
82 };
83
84 struct per_session_data__lws_mirror {
85         struct lws *wsi;
86         int ringbuffer_tail;
87 };
88
89 struct per_session_data__echogen {
90         size_t total;
91         size_t total_rx;
92         int fd;
93         int fragsize;
94         int wr;
95 };
96
97 struct per_session_data__lws_status {
98         struct per_session_data__lws_status *list;
99         struct timeval tv_established;
100         int last;
101         char ip[270];
102         char user_agent[512];
103         const char *pos;
104         int len;
105 };
106
107 extern int
108 callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
109               void *in, size_t len);
110 extern int
111 callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
112                     void *user, void *in, size_t len);
113 extern int
114 callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
115                         void *user, void *in, size_t len);
116 extern int
117 callback_lws_echogen(struct lws *wsi, enum lws_callback_reasons reason,
118                         void *user, void *in, size_t len);
119 extern int
120 callback_lws_status(struct lws *wsi, enum lws_callback_reasons reason,
121                     void *user, void *in, size_t len);
122
123
124 extern void
125 dump_handshake_info(struct lws *wsi);