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