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 #define DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS 60
18 extern int web_client_timeout;
19 extern int web_enable_gzip;
21 #ifndef NETDATA_WEB_CLIENT_H
22 #define NETDATA_WEB_CLIENT_H 1
24 #define WEB_CLIENT_MODE_NORMAL 0
25 #define WEB_CLIENT_MODE_FILECOPY 1
26 #define WEB_CLIENT_MODE_OPTIONS 2
29 #define ZLIB_CHUNK 16384
30 #define HTTP_RESPONSE_HEADER_SIZE 4096
31 #define COOKIE_MAX 1024
32 #define ORIGIN_MAX 1024
35 BUFFER *header; // our response header
36 BUFFER *header_output; // internal use
37 BUFFER *data; // our response data buffer
39 int code; // the HTTP response code
41 size_t rlen; // if non-zero, the excepted size of ifd (input of firecopy)
42 size_t sent; // current data length sent to output
44 int zoutput; // if set to 1, web_client_send() will send compressed data
45 #ifdef NETDATA_WITH_ZLIB
46 z_stream zstream; // zlib stream for sending compressed output to client
47 Bytef zbuffer[ZLIB_CHUNK]; // temporary buffer for storing compressed output
48 size_t zsent; // the compressed bytes we have sent to the client
49 size_t zhave; // the compressed bytes that we have received from zlib
56 unsigned long long id;
58 uint8_t obsolete:1; // if set to 1, the listener will remove this client
59 // after setting this to 1, you should not touch
62 uint8_t dead:1; // if set to 1, this client is dead
64 uint8_t keepalive:1; // if set to 1, the web client will be re-used
65 uint8_t enable_gzip:1; // if set to 1, the response will be compressed
67 uint8_t mode:3; // the operational mode of the client
69 uint8_t wait_receive:1; // 1 = we are waiting more input data
70 uint8_t wait_send:1; // 1 = we have data to send to the client
73 int tcp_cork; // 1 = we have a cork on the socket
79 char client_ip[NI_MAXHOST+1];
80 char client_port[NI_MAXSERV+1];
82 char decoded_url[URL_MAX + 1]; // we decode the URL in this buffer
83 char last_url[URL_MAX+1]; // we keep a copy of the decoded URL here
85 struct timeval tv_in, tv_ready;
87 char cookie1[COOKIE_MAX+1];
88 char cookie2[COOKIE_MAX+1];
89 char origin[ORIGIN_MAX+1];
91 struct sockaddr_storage clientaddr;
92 struct response response;
94 size_t stats_received_bytes;
95 size_t stats_sent_bytes;
97 pthread_t thread; // the thread servicing this client
99 struct web_client *prev;
100 struct web_client *next;
103 #define WEB_CLIENT_IS_DEAD(w) (w)->dead=1
105 extern struct web_client *web_clients;
107 extern uid_t web_files_uid(void);
108 extern uid_t web_files_gid(void);
110 extern struct web_client *web_client_create(int listener);
111 extern struct web_client *web_client_free(struct web_client *w);
112 extern ssize_t web_client_send(struct web_client *w);
113 extern ssize_t web_client_receive(struct web_client *w);
114 extern void web_client_process(struct web_client *w);
115 extern void web_client_reset(struct web_client *w);
117 extern void *web_client_main(void *ptr);