]> arthur.barton.de Git - netdata.git/blob - src/web_client.h
added configuration options for controlling web compression level and strategy and...
[netdata.git] / src / web_client.h
1
2 #ifdef NETDATA_WITH_ZLIB
3 #include <zlib.h>
4 #endif
5
6 #include <sys/time.h>
7 #include <string.h>
8 #include <sys/types.h>
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <arpa/inet.h>
12 #include <netdb.h>
13
14 #include "web_buffer.h"
15 #include "dictionary.h"
16
17 #define DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS 60
18 extern int web_client_timeout;
19
20 #ifdef NETDATA_WITH_ZLIB
21 extern int web_enable_gzip, web_gzip_level, web_gzip_strategy;
22 #endif /* NETDATA_WITH_ZLIB */
23
24 #ifndef NETDATA_WEB_CLIENT_H
25 #define NETDATA_WEB_CLIENT_H 1
26
27 #define WEB_CLIENT_MODE_NORMAL          0
28 #define WEB_CLIENT_MODE_FILECOPY        1
29 #define WEB_CLIENT_MODE_OPTIONS         2
30
31 #define URL_MAX 8192
32 #define ZLIB_CHUNK      16384
33 #define HTTP_RESPONSE_HEADER_SIZE 4096
34 #define COOKIE_MAX 1024
35 #define ORIGIN_MAX 1024
36
37 struct response {
38         BUFFER *header;                                 // our response header
39         BUFFER *header_output;                  // internal use
40         BUFFER *data;                                   // our response data buffer
41
42         int code;                                               // the HTTP response code
43
44         size_t rlen;                                    // if non-zero, the excepted size of ifd (input of firecopy)
45         size_t sent;                                    // current data length sent to output
46
47         int zoutput;                                    // if set to 1, web_client_send() will send compressed data
48 #ifdef NETDATA_WITH_ZLIB
49         z_stream zstream;                               // zlib stream for sending compressed output to client
50         Bytef zbuffer[ZLIB_CHUNK];              // temporary buffer for storing compressed output
51         size_t zsent;                                   // the compressed bytes we have sent to the client
52         size_t zhave;                                   // the compressed bytes that we have received from zlib
53         int zinitialized:1;
54 #endif /* NETDATA_WITH_ZLIB */
55
56 };
57
58 struct web_client {
59         unsigned long long id;
60
61         uint8_t obsolete:1;                                     // if set to 1, the listener will remove this client
62                                                                                 // after setting this to 1, you should not touch
63                                                                                 // this web_client
64
65         uint8_t dead:1;                                         // if set to 1, this client is dead
66
67         uint8_t keepalive:1;                            // if set to 1, the web client will be re-used
68         uint8_t enable_gzip:1;                          // if set to 1, the response will be compressed
69
70         uint8_t mode:3;                                         // the operational mode of the client
71
72         uint8_t wait_receive:1;                         // 1 = we are waiting more input data
73         uint8_t wait_send:1;                            // 1 = we have data to send to the client
74
75 #ifdef TCP_CORK
76         int tcp_cork;                                           // 1 = we have a cork on the socket
77 #endif /* TCP_CORK */
78
79         int ifd;
80         int ofd;
81
82         char client_ip[NI_MAXHOST+1];
83         char client_port[NI_MAXSERV+1];
84
85         char decoded_url[URL_MAX + 1];  // we decode the URL in this buffer
86         char last_url[URL_MAX+1];               // we keep a copy of the decoded URL here
87
88         struct timeval tv_in, tv_ready;
89
90         char cookie1[COOKIE_MAX+1];
91         char cookie2[COOKIE_MAX+1];
92         char origin[ORIGIN_MAX+1];
93
94         struct sockaddr_storage clientaddr;
95         struct response response;
96
97         size_t stats_received_bytes;
98         size_t stats_sent_bytes;
99
100         pthread_t thread;                               // the thread servicing this client
101
102         struct web_client *prev;
103         struct web_client *next;
104 };
105
106 #define WEB_CLIENT_IS_DEAD(w) (w)->dead=1
107
108 extern struct web_client *web_clients;
109
110 extern uid_t web_files_uid(void);
111 extern uid_t web_files_gid(void);
112
113 extern struct web_client *web_client_create(int listener);
114 extern struct web_client *web_client_free(struct web_client *w);
115 extern ssize_t web_client_send(struct web_client *w);
116 extern ssize_t web_client_receive(struct web_client *w);
117 extern void web_client_process(struct web_client *w);
118 extern void web_client_reset(struct web_client *w);
119
120 extern void *web_client_main(void *ptr);
121
122 #endif