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 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
24 #define ZLIB_CHUNK 16384
25 #define HTTP_RESPONSE_HEADER_SIZE 4096
26 #define COOKIE_MAX 1024
27 #define ORIGIN_MAX 1024
30 BUFFER *header; // our response header
31 BUFFER *header_output; // internal use
32 BUFFER *data; // our response data buffer
34 int code; // the HTTP response code
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
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
46 #endif /* NETDATA_WITH_ZLIB */
51 unsigned long long id;
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
57 uint8_t dead:1; // if set to 1, this client is dead
59 uint8_t keepalive:1; // if set to 1, the web client will be re-used
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
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
67 WEB_CLIENT_MODE mode; // the operational mode of the client
69 int tcp_cork; // 1 = we have a cork on the socket
74 char client_ip[NI_MAXHOST+1];
75 char client_port[NI_MAXSERV+1];
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
80 struct timeval tv_in, tv_ready;
82 char cookie1[COOKIE_MAX+1];
83 char cookie2[COOKIE_MAX+1];
84 char origin[ORIGIN_MAX+1];
86 struct sockaddr_storage clientaddr;
87 struct response response;
89 size_t stats_received_bytes;
90 size_t stats_sent_bytes;
92 pthread_t thread; // the thread servicing this client
94 struct web_client *prev;
95 struct web_client *next;
98 #define WEB_CLIENT_IS_DEAD(w) (w)->dead=1
100 extern struct web_client *web_clients;
102 extern uid_t web_files_uid(void);
103 extern uid_t web_files_gid(void);
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);
112 extern void *web_client_main(void *ptr);
114 extern int web_client_api_request_v1_data_group(char *name, int def);
115 extern const char *group_method2string(int group);
117 extern void buffer_data_options2string(BUFFER *wb, uint32_t options);
119 extern int mysendfile(struct web_client *w, char *filename);