| 1 |
|
| 2 |
// http://e2guardian.org/ |
| 3 |
// Released under the GPL v2, with the OpenSSL exception described in the README file. |
| 4 |
|
| 5 |
#ifndef __HPP_ICAPHeader |
| 6 |
#define __HPP_ICAPHeader |
| 7 |
|
| 8 |
// INCLUDES |
| 9 |
|
| 10 |
#include <deque> |
| 11 |
|
| 12 |
#include "String.hpp" |
| 13 |
#include "Socket.hpp" |
| 14 |
#include "RegExp.hpp" |
| 15 |
#include "ListMeta.hpp" |
| 16 |
#include "FOptionContainer.hpp" |
| 17 |
#include "HTTPHeader.hpp" |
| 18 |
|
| 19 |
// DECLARATIONS |
| 20 |
|
| 21 |
class ICAPHeader |
| 22 |
{ |
| 23 |
public: |
| 24 |
std::deque<String> header; |
| 25 |
unsigned int port = 0; |
| 26 |
bool is_response = false; |
| 27 |
HTTPHeader HTTPrequest; |
| 28 |
HTTPHeader HTTPresponse; |
| 29 |
String icap_error; |
| 30 |
bool service_options = false; |
| 31 |
bool service_reqmod = false; |
| 32 |
bool service_resmod = false; |
| 33 |
bool icap_reqmod_service = false; |
| 34 |
bool icap_resmod_service = false; |
| 35 |
|
| 36 |
bool req_hdr_flag = false; |
| 37 |
bool res_hdr_flag = false; |
| 38 |
bool req_body_flag = false; |
| 39 |
bool res_body_flag = false; |
| 40 |
bool opt_body_flag = false; |
| 41 |
bool null_body_flag = false; |
| 42 |
bool out_req_hdr_flag = false; |
| 43 |
bool out_res_hdr_flag = false; |
| 44 |
String out_req_header; |
| 45 |
String out_res_header; |
| 46 |
bool out_req_body_flag = false; |
| 47 |
bool out_res_body_flag = false; |
| 48 |
String out_req_body; |
| 49 |
String out_res_body; |
| 50 |
int size_req_body; |
| 51 |
int size_res_body; |
| 52 |
String ISTag; |
| 53 |
String username; |
| 54 |
String clientip; |
| 55 |
|
| 56 |
|
| 57 |
int req_hdr = 0; |
| 58 |
int res_hdr = 0; |
| 59 |
int req_body = 0; |
| 60 |
int res_body = 0; |
| 61 |
int opt_body = 0; |
| 62 |
int null_body = 0; |
| 63 |
|
| 64 |
bool allow_204 = false; |
| 65 |
bool allow_206 = false; |
| 66 |
|
| 67 |
struct encap_rec { |
| 68 |
String name; |
| 69 |
int value = 0; |
| 70 |
}; |
| 71 |
|
| 72 |
std::deque<encap_rec> encap_recs; |
| 73 |
|
| 74 |
struct icap_com_rec { |
| 75 |
String user; |
| 76 |
String EBG; |
| 77 |
int filtergroup = 0; |
| 78 |
int mess_no = 0; |
| 79 |
int log_mess_no = 0; |
| 80 |
String mess_string; |
| 81 |
}; |
| 82 |
|
| 83 |
icap_com_rec icap_com; |
| 84 |
|
| 85 |
void set_icap_com (std::string &user, String EBG, int &filtergroup, int &mess_no, int &log_mess_no, std::string &mess_string); |
| 86 |
|
| 87 |
// reset header object for future use |
| 88 |
void reset(); |
| 89 |
|
| 90 |
// network communication funcs |
| 91 |
|
| 92 |
void setTimeout(int t); |
| 93 |
|
| 94 |
bool in(Socket *sock, bool allowpersistent = false ); |
| 95 |
|
| 96 |
void setClientIP(String &ip); |
| 97 |
|
| 98 |
bool setEncapRecs(); |
| 99 |
|
| 100 |
// respond with ICAP and HTTP headers and if given body |
| 101 |
bool respond(Socket &peersock, String rescode = "200 OK", bool echo = false, bool encap = true); |
| 102 |
|
| 103 |
bool errorResponse(Socket &peersock, String &reshdr, String & resbody); |
| 104 |
|
| 105 |
// discard remainder of POST data |
| 106 |
// amount to discard can be passed in, or will default to contentLength() |
| 107 |
void discard(Socket *sock, off_t cl = -2); |
| 108 |
|
| 109 |
// header value and type checks |
| 110 |
|
| 111 |
// request type: GET, HEAD, POST etc. |
| 112 |
String requestType(); |
| 113 |
int returnCode(); |
| 114 |
// get content length - returns -1 if undetermined |
| 115 |
String getContentType(); |
| 116 |
String userAgent(); |
| 117 |
|
| 118 |
String url(); |
| 119 |
String getUrl(); |
| 120 |
|
| 121 |
String redirecturl(); |
| 122 |
|
| 123 |
// header modifications |
| 124 |
|
| 125 |
void removeEncoding(int newlen); |
| 126 |
|
| 127 |
void setURL(String &url); |
| 128 |
// do URL decoding (%xx) on string |
| 129 |
// decode everything, or just numbers, letters and - |
| 130 |
static String decode(const String &s, bool decodeAll = false); |
| 131 |
|
| 132 |
|
| 133 |
ICAPHeader() |
| 134 |
{ |
| 135 |
reset(); |
| 136 |
}; |
| 137 |
|
| 138 |
ICAPHeader(int type) |
| 139 |
{ |
| 140 |
reset(); |
| 141 |
setType(type); |
| 142 |
}; |
| 143 |
|
| 144 |
~ICAPHeader() |
| 145 |
{ |
| 146 |
}; |
| 147 |
|
| 148 |
void setType(int type) { |
| 149 |
if (type == __HEADER_RESPONSE) |
| 150 |
is_response = true; |
| 151 |
else |
| 152 |
is_response = false; |
| 153 |
}; |
| 154 |
|
| 155 |
private: |
| 156 |
// timeout for socket operations |
| 157 |
int timeout = 120000; |
| 158 |
|
| 159 |
|
| 160 |
// header index pointers |
| 161 |
|
| 162 |
//general |
| 163 |
String *pproxyconnection; |
| 164 |
String *pencapsulated; |
| 165 |
|
| 166 |
//requests |
| 167 |
String *pauthorization; |
| 168 |
String *pallow; |
| 169 |
String *pfrom; |
| 170 |
String *phost; |
| 171 |
String *preferer; |
| 172 |
String *puseragent; |
| 173 |
String *ppreview; |
| 174 |
String *pxforwardedfor; |
| 175 |
|
| 176 |
String *pproxyauthorization; |
| 177 |
String *pproxyauthenticate; |
| 178 |
String *pcontentdisposition; |
| 179 |
String *pkeepalive; |
| 180 |
String *pupgrade; |
| 181 |
String *pclientip; |
| 182 |
String *pclientuser; |
| 183 |
String method; |
| 184 |
|
| 185 |
|
| 186 |
bool ispersistent, waspersistent; |
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
bool dirty = true; |
| 192 |
|
| 193 |
|
| 194 |
// check & fix headers from servers that don't obey standards |
| 195 |
void checkheader(bool allowpersistent); |
| 196 |
|
| 197 |
// convert %xx back to original character |
| 198 |
static String hexToChar(const String &n, bool all = false); |
| 199 |
|
| 200 |
}; |
| 201 |
|
| 202 |
#endif |