ed936bfb4b88f468edf760821979cd00c62fcf5d
[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 #if defined(LWS_OPENSSL_SUPPORT) && defined(LWS_HAVE_SSL_CTX_set1_param)
61 extern char crl_path[1024];
62 #endif
63
64 extern void test_server_lock(int care);
65 extern void test_server_unlock(int care);
66
67 #ifndef __func__
68 #define __func__ __FUNCTION__
69 #endif
70
71 struct per_session_data__http {
72         lws_fop_fd_t fop_fd;
73 #ifdef LWS_WITH_CGI
74         struct lws_cgi_args args;
75 #endif
76 #if defined(LWS_WITH_CGI) || !defined(LWS_NO_CLIENT)
77         int reason_bf;
78 #endif
79         unsigned int client_finished:1;
80
81
82         struct lws_spa *spa;
83         char result[500 + LWS_PRE];
84         int result_len;
85
86         char filename[256];
87         long file_length;
88         lws_filefd_type post_fd;
89 };
90
91 /*
92  * one of these is auto-created for each connection and a pointer to the
93  * appropriate instance is passed to the callback in the user parameter
94  *
95  * for this example protocol we use it to individualize the count for each
96  * connection.
97  */
98
99 struct per_session_data__dumb_increment {
100         int number;
101 };
102
103 struct per_session_data__lws_mirror {
104         struct lws *wsi;
105         int ringbuffer_tail;
106 };
107
108 struct per_session_data__echogen {
109         size_t total;
110         size_t total_rx;
111         int fd;
112         int fragsize;
113         int wr;
114 };
115
116 struct per_session_data__lws_status {
117         struct per_session_data__lws_status *list;
118         struct timeval tv_established;
119         int last;
120         char ip[270];
121         char user_agent[512];
122         const char *pos;
123         int len;
124 };
125
126 extern int
127 callback_http(struct lws *wsi, enum lws_callback_reasons reason, void *user,
128               void *in, size_t len);
129 extern int
130 callback_lws_mirror(struct lws *wsi, enum lws_callback_reasons reason,
131                     void *user, void *in, size_t len);
132 extern int
133 callback_dumb_increment(struct lws *wsi, enum lws_callback_reasons reason,
134                         void *user, void *in, size_t len);
135 extern int
136 callback_lws_echogen(struct lws *wsi, enum lws_callback_reasons reason,
137                         void *user, void *in, size_t len);
138 extern int
139 callback_lws_status(struct lws *wsi, enum lws_callback_reasons reason,
140                     void *user, void *in, size_t len);
141
142
143 extern void
144 dump_handshake_info(struct lws *wsi);