| 1 |
// For all support, instructions and copyright go to: |
| 2 |
// http://e2guardian.org/ |
| 3 |
// Released under the GPL v2, with the OpenSSL exception described in the README file. |
| 4 |
|
| 5 |
#ifndef __HPP_DATABUFFER |
| 6 |
#define __HPP_DATABUFFER |
| 7 |
|
| 8 |
#include <exception> |
| 9 |
#include <memory> |
| 10 |
#include <string.h> |
| 11 |
#include "Socket.hpp" |
| 12 |
#include "String.hpp" |
| 13 |
#include "FOptionContainer.hpp" |
| 14 |
//#include "LOptionContainer.hpp" |
| 15 |
#include "StoryBoard.hpp" |
| 16 |
|
| 17 |
#define DB_TOBIG 1 |
| 18 |
#define DB_TOBIG_SCAN 2 |
| 19 |
#define DB_TOBIG_FILTER 4 |
| 20 |
|
| 21 |
class DMPlugin; |
| 22 |
|
| 23 |
class DataBuffer |
| 24 |
{ |
| 25 |
public: |
| 26 |
char *data; |
| 27 |
off_t data_length = 0; |
| 28 |
off_t buffer_length = 0; |
| 29 |
char *compresseddata= nullptr; |
| 30 |
off_t compressed_buffer_data_length = 0; |
| 31 |
off_t tempfilesize = 0; |
| 32 |
String tempfilepath; |
| 33 |
bool dontsendbody = false; // used for fancy download manager for example |
| 34 |
bool chunked = false; |
| 35 |
bool icap = false; |
| 36 |
bool got_all = false; // used with chunked it all read-in |
| 37 |
int tempfilefd = -1; |
| 38 |
|
| 39 |
// std::shared_ptr<LOptionContainer> ldl; |
| 40 |
FOptionContainer *fgc; |
| 41 |
|
| 42 |
// the download manager we used during the last "in" |
| 43 |
DMPlugin *dm_plugin; |
| 44 |
|
| 45 |
DataBuffer(); |
| 46 |
DataBuffer(const void *indata, off_t length); |
| 47 |
~DataBuffer(); |
| 48 |
|
| 49 |
bool increase_buffer(int extra); |
| 50 |
void set_current_config (FOptionContainer *newfgc); |
| 51 |
|
| 52 |
int length() |
| 53 |
{ |
| 54 |
return data_length; |
| 55 |
}; |
| 56 |
|
| 57 |
void copyToMemory(char *location) |
| 58 |
{ |
| 59 |
memcpy(location, data, data_length); |
| 60 |
}; |
| 61 |
|
| 62 |
// read body in from proxy |
| 63 |
// gives true if it pauses due to too much data |
| 64 |
bool in(Socket *sock, Socket *peersock, class HTTPHeader *requestheader, class HTTPHeader *docheader, bool runav, int *headersent, StoryBoard &story, NaughtyFilter *cm); |
| 65 |
// send body to client |
| 66 |
bool out(Socket *sock); |
| 67 |
|
| 68 |
void setTimeout(int t) |
| 69 |
{ |
| 70 |
timeout = t; |
| 71 |
stimeout = t / 1000; |
| 72 |
}; |
| 73 |
void setDecompress(String d) |
| 74 |
{ |
| 75 |
decompress = d; |
| 76 |
}; |
| 77 |
|
| 78 |
// swap back to compressed version of body data (if data was decompressed but not modified; saves bandwidth) |
| 79 |
void swapbacktocompressed(); |
| 80 |
|
| 81 |
// content regexp search and replace |
| 82 |
bool contentRegExp(FOptionContainer* &foc); |
| 83 |
|
| 84 |
// create a temp file and return its FD - NOT a simple accessor function |
| 85 |
int getTempFileFD(); |
| 86 |
|
| 87 |
void setChunked(bool ch); |
| 88 |
void setICAP(bool ch); |
| 89 |
|
| 90 |
void reset(); |
| 91 |
|
| 92 |
private: |
| 93 |
// DM plugins do horrible things to our innards - this is acceptable pending a proper cleanup |
| 94 |
friend class DMPlugin; |
| 95 |
friend class dminstance; |
| 96 |
friend class fancydm; |
| 97 |
friend class trickledm; |
| 98 |
|
| 99 |
int timeout = 20000; // in msecs |
| 100 |
int stimeout = 20; // in secs |
| 101 |
off_t bytesalreadysent = 0; |
| 102 |
off_t bytes_toget = 0; |
| 103 |
bool geteverything = false; |
| 104 |
bool swappedtodisk = false; |
| 105 |
bool doneinitialdelay = false; |
| 106 |
bool preservetemp = false; |
| 107 |
|
| 108 |
String decompress; |
| 109 |
|
| 110 |
void zlibinflate(bool header); |
| 111 |
|
| 112 |
int readInFromSocket(Socket *sock, int size, bool wantall, int &result); |
| 113 |
|
| 114 |
// buffered socket reads - one with an extra "global" timeout within which all individual reads must complete |
| 115 |
int bufferReadFromSocket(Socket *sock, char *buffer, int size, int sockettimeout); |
| 116 |
int bufferReadFromSocket(Socket *sock, char *buffer, int size, int sockettimeout, int timeout); |
| 117 |
}; |
| 118 |
|
| 119 |
#endif |