2 #ifdef NETDATA_WITH_ZLIB
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #include <arpa/inet.h>
14 #include "web_buffer.h"
15 #include "dictionary.h"
17 #ifndef NETDATA_WEB_CLIENT_H
18 #define NETDATA_WEB_CLIENT_H 1
20 #define DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS 60
21 extern int web_client_timeout;
23 #ifdef NETDATA_WITH_ZLIB
24 extern int web_enable_gzip, web_gzip_level, web_gzip_strategy, web_donotrack_comply;
25 #endif /* NETDATA_WITH_ZLIB */
27 #define WEB_CLIENT_MODE_NORMAL 0
28 #define WEB_CLIENT_MODE_FILECOPY 1
29 #define WEB_CLIENT_MODE_OPTIONS 2
32 #define ZLIB_CHUNK 16384
33 #define HTTP_RESPONSE_HEADER_SIZE 4096
34 #define COOKIE_MAX 1024
35 #define ORIGIN_MAX 1024
38 BUFFER *header; // our response header
39 BUFFER *header_output; // internal use
40 BUFFER *data; // our response data buffer
42 int code; // the HTTP response code
44 size_t rlen; // if non-zero, the excepted size of ifd (input of firecopy)
45 size_t sent; // current data length sent to output
47 int zoutput; // if set to 1, web_client_send() will send compressed data
48 #ifdef NETDATA_WITH_ZLIB
49 z_stream zstream; // zlib stream for sending compressed output to client
50 Bytef zbuffer[ZLIB_CHUNK]; // temporary buffer for storing compressed output
51 size_t zsent; // the compressed bytes we have sent to the client
52 size_t zhave; // the compressed bytes that we have received from zlib
54 #endif /* NETDATA_WITH_ZLIB */
59 unsigned long long id;
61 uint8_t obsolete:1; // if set to 1, the listener will remove this client
62 // after setting this to 1, you should not touch
65 uint8_t dead:1; // if set to 1, this client is dead
67 uint8_t keepalive:1; // if set to 1, the web client will be re-used
69 uint8_t mode:3; // the operational mode of the client
71 uint8_t wait_receive:1; // 1 = we are waiting more input data
72 uint8_t wait_send:1; // 1 = we have data to send to the client
74 uint8_t donottrack:1; // 1 = we should not set cookies on this client
75 uint8_t tracking_required:1; // 1 = if the request requires cookies
77 int tcp_cork; // 1 = we have a cork on the socket
82 char client_ip[NI_MAXHOST+1];
83 char client_port[NI_MAXSERV+1];
85 char decoded_url[URL_MAX + 1]; // we decode the URL in this buffer
86 char last_url[URL_MAX+1]; // we keep a copy of the decoded URL here
88 struct timeval tv_in, tv_ready;
90 char cookie1[COOKIE_MAX+1];
91 char cookie2[COOKIE_MAX+1];
92 char origin[ORIGIN_MAX+1];
94 struct sockaddr_storage clientaddr;
95 struct response response;
97 size_t stats_received_bytes;
98 size_t stats_sent_bytes;
100 pthread_t thread; // the thread servicing this client
102 struct web_client *prev;
103 struct web_client *next;
106 #define WEB_CLIENT_IS_DEAD(w) (w)->dead=1
108 extern struct web_client *web_clients;
110 extern uid_t web_files_uid(void);
111 extern uid_t web_files_gid(void);
113 extern struct web_client *web_client_create(int listener);
114 extern struct web_client *web_client_free(struct web_client *w);
115 extern ssize_t web_client_send(struct web_client *w);
116 extern ssize_t web_client_receive(struct web_client *w);
117 extern void web_client_process(struct web_client *w);
118 extern void web_client_reset(struct web_client *w);
120 extern void *web_client_main(void *ptr);