]> arthur.barton.de Git - netdata.git/blob - src/web_client.h
Merge pull request #277 from jgeromero/tomcat.chart.sh
[netdata.git] / src / web_client.h
1
2 #ifdef NETDATA_WITH_ZLIB
3 #include <zlib.h>
4 #endif
5
6 #include <sys/time.h>
7 #include <string.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
10 #include <arpa/inet.h>
11 #include <netdb.h>
12
13 #include "web_buffer.h"
14
15 #define DEFAULT_DISCONNECT_IDLE_WEB_CLIENTS_AFTER_SECONDS 60
16 extern int web_client_timeout;
17 extern int web_enable_gzip;
18
19 #ifndef NETDATA_WEB_CLIENT_H
20 #define NETDATA_WEB_CLIENT_H 1
21
22 #define WEB_CLIENT_MODE_NORMAL          0
23 #define WEB_CLIENT_MODE_FILECOPY        1
24 #define WEB_CLIENT_MODE_OPTIONS         2
25
26 #define URL_MAX 8192
27 #define ZLIB_CHUNK      16384
28 #define HTTP_RESPONSE_HEADER_SIZE 4096
29
30 struct response {
31         BUFFER *header;                                 // our response header
32         BUFFER *header_output;                  // internal use
33         BUFFER *data;                                   // our response data buffer
34
35         int code;                                               // the HTTP response code
36
37         size_t rlen;                                    // if non-zero, the excepted size of ifd (input)
38         size_t sent;                                    // current data length sent to output
39
40         int zoutput;                                    // if set to 1, web_client_send() will send compressed data
41 #ifdef NETDATA_WITH_ZLIB
42         z_stream zstream;                               // zlib stream for sending compressed output to client
43         Bytef zbuffer[ZLIB_CHUNK];              // temporary buffer for storing compressed output
44         long zsent;                                             // the compressed bytes we have sent to the client
45         long zhave;                                             // the compressed bytes that we have to send
46         int zinitialized;
47 #endif
48
49 };
50
51 struct web_client {
52         unsigned long long id;
53
54         char client_ip[NI_MAXHOST+1];
55         char client_port[NI_MAXSERV+1];
56
57         char last_url[URL_MAX+1];
58
59         struct timeval tv_in, tv_ready;
60
61         int mode;
62         int keepalive;
63
64         struct sockaddr_storage clientaddr;
65
66         pthread_t thread;                               // the thread servicing this client
67         int obsolete;                                   // if set to 1, the listener will remove this client
68
69         int ifd;
70         int ofd;
71
72         struct response response;
73
74         int wait_receive;
75         int wait_send;
76
77         struct web_client *prev;
78         struct web_client *next;
79 };
80
81 extern struct web_client *web_clients;
82
83 extern uid_t web_files_uid(void);
84 extern uid_t web_files_gid(void);
85
86 extern struct web_client *web_client_create(int listener);
87 extern struct web_client *web_client_free(struct web_client *w);
88
89 extern void *web_client_main(void *ptr);
90
91 #endif