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