-
Notifications
You must be signed in to change notification settings - Fork 0
/
proxy-handler.h
91 lines (79 loc) · 2.02 KB
/
proxy-handler.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <pthread.h>
#include <stdbool.h>
#include "cache.h"
#include "http-parser.h"
#include "pstring.h"
#ifndef _PROXY_HANDLER_H
#define _PROXY_HANDLER_H
#define PROXY_HTTP_RESPONSE_VALID_LINE_LEN sizeof("HTTP/1.0 200") - 1
struct target_state;
typedef struct client_state {
int socket;
volatile int revents;
volatile bool cache_updates;
http_parser parser;
bool parse_error;
pthread_mutex_t lock;
pthread_cond_t notifier;
pthread_t thread;
pstring_t url;
bool url_dumped;
pstring_t client_outbuff;
pstring_t target_outbuff;
pstring_t header_key;
pstring_t header_value;
struct target_state* target;
cache_entry_reader_t* reader;
cache_entry_t* cache;
size_t cache_offset;
bool use_cache;
} client_state_t;
typedef struct target_state {
int socket;
volatile int revents;
http_parser parser;
pthread_mutex_t lock;
pthread_cond_t notifier;
pthread_t thread;
pstring_t outbuff;
cache_entry_t* cache;
bool message_complete;
} target_state_t;
/**
* Accepts new client at required socket.
*
* @param socket Socket.
*/
void proxy_accept_client(int socket);
/**
* Establish connection to proxying target at required hostname and port.
* Also creates target input handler and parser.
*
* @param state Current state.
* @param host hostname[:port]
*
* @return {@code true} if successfully established.
*/
bool proxy_establish_connection(client_state_t* state, char* host);
/**
* Sends string to the socket.
*
* @param socket Target socket.
* @param buff Sending string.
*
* @return Zero if all string was sent, or 1 if some output data stored
* as substring of buffer, or -1 if error occured.
*/
int send_pstring(int socket, pstring_t* buff);
/**
* Allocates and build header string from header entry.
*
* @param key Header key.
* @param value Header value.
* @param result_len Result string length.
*
* @return New header string allocated on heap or {@code NULL} if not enougth
* memory.
*/
char* build_header_string(pstring_t* key, pstring_t* value, size_t* result_len);
#endif