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