]>
Commit | Line | Data |
---|---|---|
be4401bf | 1 | // -*- mode: cpp; mode: fold -*- |
a305f593 AL |
2 | // Description /*{{{*/// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $ |
3 | // $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $ | |
be4401bf AL |
4 | /* ###################################################################### |
5 | ||
1e3f4083 | 6 | HTTP Acquire Method - This is the HTTP acquire method for APT. |
be4401bf AL |
7 | |
8 | ##################################################################### */ | |
9 | /*}}}*/ | |
10 | ||
11 | #ifndef APT_HTTP_H | |
12 | #define APT_HTTP_H | |
13 | ||
472ff00e | 14 | #include <apt-pkg/strutl.h> |
453b82a3 | 15 | #include <apt-pkg/acquire-method.h> |
472ff00e DK |
16 | |
17 | #include <string> | |
453b82a3 DK |
18 | #include <sys/time.h> |
19 | #include <iostream> | |
42195eb2 | 20 | |
7330f4df DK |
21 | #include "server.h" |
22 | ||
42195eb2 AL |
23 | using std::cout; |
24 | using std::endl; | |
25 | ||
453b82a3 | 26 | class FileFd; |
be4401bf | 27 | class HttpMethod; |
472ff00e | 28 | class Hashes; |
be4401bf AL |
29 | |
30 | class CircleBuf | |
31 | { | |
32 | unsigned char *Buf; | |
650faab0 DK |
33 | unsigned long long Size; |
34 | unsigned long long InP; | |
35 | unsigned long long OutP; | |
8f3ba4e8 | 36 | std::string OutQueue; |
650faab0 DK |
37 | unsigned long long StrPos; |
38 | unsigned long long MaxGet; | |
be4401bf | 39 | struct timeval Start; |
7330f4df | 40 | |
650faab0 DK |
41 | static unsigned long long BwReadLimit; |
42 | static unsigned long long BwTickReadData; | |
7c6e2dc7 MV |
43 | static struct timeval BwReadTick; |
44 | static const unsigned int BW_HZ; | |
45 | ||
74b22002 | 46 | unsigned long long LeftRead() const |
be4401bf | 47 | { |
650faab0 | 48 | unsigned long long Sz = Size - (InP - OutP); |
be4401bf AL |
49 | if (Sz > Size - (InP%Size)) |
50 | Sz = Size - (InP%Size); | |
51 | return Sz; | |
52 | } | |
74b22002 | 53 | unsigned long long LeftWrite() const |
be4401bf | 54 | { |
650faab0 | 55 | unsigned long long Sz = InP - OutP; |
be4401bf AL |
56 | if (InP > MaxGet) |
57 | Sz = MaxGet - OutP; | |
58 | if (Sz > Size - (OutP%Size)) | |
59 | Sz = Size - (OutP%Size); | |
60 | return Sz; | |
61 | } | |
62 | void FillOut(); | |
7330f4df | 63 | |
be4401bf | 64 | public: |
63b1700f | 65 | Hashes *Hash; |
dcd5856b MV |
66 | // total amount of data that got written so far |
67 | unsigned long long TotalWriten; | |
7330f4df | 68 | |
be4401bf AL |
69 | // Read data in |
70 | bool Read(int Fd); | |
8f3ba4e8 | 71 | bool Read(std::string Data); |
7330f4df | 72 | |
be4401bf AL |
73 | // Write data out |
74 | bool Write(int Fd); | |
8f3ba4e8 | 75 | bool WriteTillEl(std::string &Data,bool Single = false); |
7330f4df | 76 | |
be4401bf | 77 | // Control the write limit |
7330f4df | 78 | void Limit(long long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;} |
f5a34606 DK |
79 | bool IsLimit() const {return MaxGet == OutP;}; |
80 | void Print() const {cout << MaxGet << ',' << OutP << endl;}; | |
be4401bf AL |
81 | |
82 | // Test for free space in the buffer | |
f5a34606 DK |
83 | bool ReadSpace() const {return Size - (InP - OutP) > 0;}; |
84 | bool WriteSpace() const {return InP - OutP > 0;}; | |
be4401bf | 85 | |
be4401bf | 86 | void Reset(); |
dcd5856b | 87 | // Dump everything |
be4401bf AL |
88 | void Stats(); |
89 | ||
650faab0 | 90 | CircleBuf(unsigned long long Size); |
472ff00e | 91 | ~CircleBuf(); |
be4401bf AL |
92 | }; |
93 | ||
7330f4df | 94 | struct HttpServerState: public ServerState |
be4401bf | 95 | { |
be4401bf AL |
96 | // This is the connection itself. Output is data FROM the server |
97 | CircleBuf In; | |
98 | CircleBuf Out; | |
99 | int ServerFd; | |
7330f4df DK |
100 | |
101 | protected: | |
102 | virtual bool ReadHeaderLines(std::string &Data); | |
103 | virtual bool LoadNextResponse(bool const ToFile, FileFd * const File); | |
104 | virtual bool WriteResponse(std::string const &Data); | |
105 | ||
106 | public: | |
107 | virtual void Reset() { ServerState::Reset(); ServerFd = -1; }; | |
108 | ||
109 | virtual bool RunData(FileFd * const File); | |
110 | ||
111 | virtual bool Open(); | |
112 | virtual bool IsOpen(); | |
113 | virtual bool Close(); | |
9224ce3d | 114 | virtual bool InitHashes(FileFd &File, HashStringList const &ExpectedHashes); |
7330f4df DK |
115 | virtual Hashes * GetHashes(); |
116 | virtual bool Die(FileFd &File); | |
117 | virtual bool Flush(FileFd * const File); | |
118 | virtual bool Go(bool ToFile, FileFd * const File); | |
119 | ||
120 | HttpServerState(URI Srv, HttpMethod *Owner); | |
121 | virtual ~HttpServerState() {Close();}; | |
be4401bf AL |
122 | }; |
123 | ||
7330f4df | 124 | class HttpMethod : public ServerMethod |
be4401bf | 125 | { |
7330f4df DK |
126 | public: |
127 | virtual void SendReq(FetchItem *Itm); | |
7273e494 | 128 | |
8f3ba4e8 | 129 | virtual bool Configuration(std::string Message); |
7330f4df DK |
130 | |
131 | virtual ServerState * CreateServerState(URI uri); | |
fd46d305 | 132 | virtual void RotateDNS(); |
5f6b130d MV |
133 | |
134 | protected: | |
8f3ba4e8 | 135 | std::string AutoDetectProxyCmd; |
7273e494 | 136 | |
be4401bf | 137 | public: |
7330f4df DK |
138 | friend struct HttpServerState; |
139 | ||
140 | HttpMethod() : ServerMethod("1.2",Pipeline | SendConfig) | |
be4401bf | 141 | { |
be4401bf | 142 | File = 0; |
5cb5d8dc | 143 | Server = 0; |
be4401bf AL |
144 | }; |
145 | }; | |
146 | ||
be4401bf | 147 | #endif |