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