1 #ifndef NETDATA_WEB_CLIENT_H
2 #define NETDATA_WEB_CLIENT_H 1
4 #define DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS 60
5 extern int web_client_timeout;
7 #ifdef NETDATA_WITH_ZLIB
8 extern int web_enable_gzip,
11 #endif /* NETDATA_WITH_ZLIB */
13 extern int respect_web_browser_do_not_track_policy;
14 extern char *web_x_frame_options;
16 #define WEB_CLIENT_MODE_NORMAL 0
17 #define WEB_CLIENT_MODE_FILECOPY 1
18 #define WEB_CLIENT_MODE_OPTIONS 2
21 #define ZLIB_CHUNK 16384
22 #define HTTP_RESPONSE_HEADER_SIZE 4096
23 #define COOKIE_MAX 1024
24 #define ORIGIN_MAX 1024
27 BUFFER *header; // our response header
28 BUFFER *header_output; // internal use
29 BUFFER *data; // our response data buffer
31 int code; // the HTTP response code
33 size_t rlen; // if non-zero, the excepted size of ifd (input of firecopy)
34 size_t sent; // current data length sent to output
36 int zoutput; // if set to 1, web_client_send() will send compressed data
37 #ifdef NETDATA_WITH_ZLIB
38 z_stream zstream; // zlib stream for sending compressed output to client
39 Bytef zbuffer[ZLIB_CHUNK]; // temporary buffer for storing compressed output
40 size_t zsent; // the compressed bytes we have sent to the client
41 size_t zhave; // the compressed bytes that we have received from zlib
43 #endif /* NETDATA_WITH_ZLIB */
48 unsigned long long id;
50 uint8_t obsolete:1; // if set to 1, the listener will remove this client
51 // after setting this to 1, you should not touch
54 uint8_t dead:1; // if set to 1, this client is dead
56 uint8_t keepalive:1; // if set to 1, the web client will be re-used
58 uint8_t mode:3; // the operational mode of the client
60 uint8_t wait_receive:1; // 1 = we are waiting more input data
61 uint8_t wait_send:1; // 1 = we have data to send to the client
63 uint8_t donottrack:1; // 1 = we should not set cookies on this client
64 uint8_t tracking_required:1; // 1 = if the request requires cookies
66 int tcp_cork; // 1 = we have a cork on the socket
71 char client_ip[NI_MAXHOST+1];
72 char client_port[NI_MAXSERV+1];
74 char decoded_url[URL_MAX + 1]; // we decode the URL in this buffer
75 char last_url[URL_MAX+1]; // we keep a copy of the decoded URL here
77 struct timeval tv_in, tv_ready;
79 char cookie1[COOKIE_MAX+1];
80 char cookie2[COOKIE_MAX+1];
81 char origin[ORIGIN_MAX+1];
83 struct sockaddr_storage clientaddr;
84 struct response response;
86 size_t stats_received_bytes;
87 size_t stats_sent_bytes;
89 pthread_t thread; // the thread servicing this client
91 struct web_client *prev;
92 struct web_client *next;
95 #define WEB_CLIENT_IS_DEAD(w) (w)->dead=1
97 extern struct web_client *web_clients;
99 extern uid_t web_files_uid(void);
100 extern uid_t web_files_gid(void);
102 extern struct web_client *web_client_create(int listener);
103 extern struct web_client *web_client_free(struct web_client *w);
104 extern ssize_t web_client_send(struct web_client *w);
105 extern ssize_t web_client_receive(struct web_client *w);
106 extern void web_client_process_request(struct web_client *w);
107 extern void web_client_reset(struct web_client *w);
109 extern void *web_client_main(void *ptr);
111 extern int web_client_api_request_v1_data_group(char *name, int def);
112 extern const char *group_method2string(int group);
114 extern void buffer_data_options2string(BUFFER *wb, uint32_t options);