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