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;
20 #ifdef NETDATA_WITH_ZLIB
21 extern int web_enable_gzip, web_gzip_level, web_gzip_strategy;
22 #endif /* NETDATA_WITH_ZLIB */
24 #ifndef NETDATA_WEB_CLIENT_H
25 #define NETDATA_WEB_CLIENT_H 1
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 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);