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, web_gzip_level, web_gzip_strategy, web_donotrack_comply;
9 #endif /* NETDATA_WITH_ZLIB */
11 #define WEB_CLIENT_MODE_NORMAL 0
12 #define WEB_CLIENT_MODE_FILECOPY 1
13 #define WEB_CLIENT_MODE_OPTIONS 2
16 #define ZLIB_CHUNK 16384
17 #define HTTP_RESPONSE_HEADER_SIZE 4096
18 #define COOKIE_MAX 1024
19 #define ORIGIN_MAX 1024
22 BUFFER *header; // our response header
23 BUFFER *header_output; // internal use
24 BUFFER *data; // our response data buffer
26 int code; // the HTTP response code
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
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
38 #endif /* NETDATA_WITH_ZLIB */
43 unsigned long long id;
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
49 uint8_t dead:1; // if set to 1, this client is dead
51 uint8_t keepalive:1; // if set to 1, the web client will be re-used
53 uint8_t mode:3; // the operational mode of the client
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
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
61 int tcp_cork; // 1 = we have a cork on the socket
66 char client_ip[NI_MAXHOST+1];
67 char client_port[NI_MAXSERV+1];
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
72 struct timeval tv_in, tv_ready;
74 char cookie1[COOKIE_MAX+1];
75 char cookie2[COOKIE_MAX+1];
76 char origin[ORIGIN_MAX+1];
78 struct sockaddr_storage clientaddr;
79 struct response response;
81 size_t stats_received_bytes;
82 size_t stats_sent_bytes;
84 pthread_t thread; // the thread servicing this client
86 struct web_client *prev;
87 struct web_client *next;
90 #define WEB_CLIENT_IS_DEAD(w) (w)->dead=1
92 extern struct web_client *web_clients;
94 extern uid_t web_files_uid(void);
95 extern uid_t web_files_gid(void);
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);
104 extern void *web_client_main(void *ptr);
106 extern int web_client_api_request_v1_data_group(char *name, int def);
107 extern const char *group_method2string(int group);
109 extern void buffer_data_options2string(BUFFER *wb, uint32_t options);