]>
Commit | Line | Data |
---|---|---|
be4401bf | 1 | // -*- mode: cpp; mode: fold -*- |
f93d1355 | 2 | // Description /*{{{*/// $Id: http.h,v 1.7 1999/12/09 03:45:56 jgg Exp $ |
be4401bf AL |
3 | /* ###################################################################### |
4 | ||
5 | HTTP Aquire Method - This is the HTTP aquire method for APT. | |
6 | ||
7 | ##################################################################### */ | |
8 | /*}}}*/ | |
9 | ||
10 | #ifndef APT_HTTP_H | |
11 | #define APT_HTTP_H | |
12 | ||
13 | #define MAXLEN 360 | |
14 | ||
15 | class HttpMethod; | |
16 | ||
17 | class CircleBuf | |
18 | { | |
19 | unsigned char *Buf; | |
20 | unsigned long Size; | |
21 | unsigned long InP; | |
22 | unsigned long OutP; | |
23 | string OutQueue; | |
24 | unsigned long StrPos; | |
25 | unsigned long MaxGet; | |
26 | struct timeval Start; | |
27 | ||
28 | unsigned long LeftRead() | |
29 | { | |
30 | unsigned long Sz = Size - (InP - OutP); | |
31 | if (Sz > Size - (InP%Size)) | |
32 | Sz = Size - (InP%Size); | |
33 | return Sz; | |
34 | } | |
35 | unsigned long LeftWrite() | |
36 | { | |
37 | unsigned long Sz = InP - OutP; | |
38 | if (InP > MaxGet) | |
39 | Sz = MaxGet - OutP; | |
40 | if (Sz > Size - (OutP%Size)) | |
41 | Sz = Size - (OutP%Size); | |
42 | return Sz; | |
43 | } | |
44 | void FillOut(); | |
45 | ||
46 | public: | |
47 | ||
48 | MD5Summation *MD5; | |
49 | ||
50 | // Read data in | |
51 | bool Read(int Fd); | |
52 | bool Read(string Data); | |
53 | ||
54 | // Write data out | |
55 | bool Write(int Fd); | |
56 | bool WriteTillEl(string &Data,bool Single = false); | |
57 | ||
58 | // Control the write limit | |
59 | void Limit(long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;} | |
60 | bool IsLimit() {return MaxGet == OutP;}; | |
61 | void Print() {cout << MaxGet << ',' << OutP << endl;}; | |
62 | ||
63 | // Test for free space in the buffer | |
64 | bool ReadSpace() {return Size - (InP - OutP) > 0;}; | |
65 | bool WriteSpace() {return InP - OutP > 0;}; | |
66 | ||
67 | // Dump everything | |
68 | void Reset(); | |
69 | void Stats(); | |
70 | ||
71 | CircleBuf(unsigned long Size); | |
72 | ~CircleBuf() {delete [] Buf;}; | |
73 | }; | |
74 | ||
75 | struct ServerState | |
76 | { | |
77 | // This is the last parsed Header Line | |
78 | unsigned int Major; | |
79 | unsigned int Minor; | |
80 | unsigned int Result; | |
81 | char Code[MAXLEN]; | |
82 | ||
92e889c8 | 83 | // These are some statistics from the last parsed header lines |
be4401bf AL |
84 | unsigned long Size; |
85 | signed long StartPos; | |
86 | time_t Date; | |
92e889c8 | 87 | bool HaveContent; |
be4401bf AL |
88 | enum {Chunked,Stream,Closes} Encoding; |
89 | enum {Header, Data} State; | |
f93d1355 | 90 | bool Pipeline; |
be4401bf AL |
91 | |
92 | HttpMethod *Owner; | |
93 | ||
94 | // This is the connection itself. Output is data FROM the server | |
95 | CircleBuf In; | |
96 | CircleBuf Out; | |
97 | int ServerFd; | |
98 | URI ServerName; | |
99 | ||
100 | bool HeaderLine(string Line); | |
101 | bool Comp(URI Other) {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;}; | |
102 | void Reset() {Major = 0; Minor = 0; Result = 0; Size = 0; StartPos = 0; | |
f93d1355 AL |
103 | Encoding = Closes; time(&Date); ServerFd = -1; |
104 | Pipeline = true;}; | |
92e889c8 | 105 | int RunHeaders(); |
be4401bf AL |
106 | bool RunData(); |
107 | ||
108 | bool Open(); | |
109 | bool Close(); | |
110 | ||
111 | ServerState(URI Srv,HttpMethod *Owner); | |
112 | ~ServerState() {Close();}; | |
113 | }; | |
114 | ||
115 | class HttpMethod : public pkgAcqMethod | |
116 | { | |
117 | void SendReq(FetchItem *Itm,CircleBuf &Out); | |
118 | bool Go(bool ToFile,ServerState *Srv); | |
119 | bool Flush(ServerState *Srv); | |
120 | bool ServerDie(ServerState *Srv); | |
121 | int DealWithHeaders(FetchResult &Res,ServerState *Srv); | |
5cb5d8dc | 122 | |
85f72a56 AL |
123 | virtual bool Fetch(FetchItem *); |
124 | virtual bool Configuration(string Message); | |
be4401bf | 125 | |
492f957a AL |
126 | // In the event of a fatal signal this file will be closed and timestamped. |
127 | static string FailFile; | |
128 | static int FailFd; | |
129 | static time_t FailTime; | |
130 | static void SigTerm(int); | |
131 | ||
be4401bf AL |
132 | public: |
133 | friend ServerState; | |
134 | ||
be4401bf | 135 | FileFd *File; |
5cb5d8dc | 136 | ServerState *Server; |
be4401bf AL |
137 | |
138 | int Loop(); | |
139 | ||
b98f2859 | 140 | HttpMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig) |
be4401bf | 141 | { |
be4401bf | 142 | File = 0; |
5cb5d8dc | 143 | Server = 0; |
be4401bf AL |
144 | }; |
145 | }; | |
146 | ||
147 | URI Proxy; | |
148 | ||
149 | #endif |