]> git.saurik.com Git - apt.git/blame - methods/http.h
Updated authors
[apt.git] / methods / http.h
CommitLineData
be4401bf 1// -*- mode: cpp; mode: fold -*-
e836f356 2// Description /*{{{*/// $Id: http.h,v 1.8 2000/05/28 04:33:59 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
15class HttpMethod;
16
17class 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
75struct 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;
e836f356
AL
90 bool Persistent;
91
92 // This is a Persistent attribute of the server itself.
f93d1355 93 bool Pipeline;
be4401bf
AL
94
95 HttpMethod *Owner;
96
97 // This is the connection itself. Output is data FROM the server
98 CircleBuf In;
99 CircleBuf Out;
100 int ServerFd;
101 URI ServerName;
102
103 bool HeaderLine(string Line);
104 bool Comp(URI Other) {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
105 void Reset() {Major = 0; Minor = 0; Result = 0; Size = 0; StartPos = 0;
f93d1355
AL
106 Encoding = Closes; time(&Date); ServerFd = -1;
107 Pipeline = true;};
92e889c8 108 int RunHeaders();
be4401bf
AL
109 bool RunData();
110
111 bool Open();
112 bool Close();
113
114 ServerState(URI Srv,HttpMethod *Owner);
115 ~ServerState() {Close();};
116};
117
118class HttpMethod : public pkgAcqMethod
119{
120 void SendReq(FetchItem *Itm,CircleBuf &Out);
121 bool Go(bool ToFile,ServerState *Srv);
122 bool Flush(ServerState *Srv);
123 bool ServerDie(ServerState *Srv);
124 int DealWithHeaders(FetchResult &Res,ServerState *Srv);
5cb5d8dc 125
85f72a56
AL
126 virtual bool Fetch(FetchItem *);
127 virtual bool Configuration(string Message);
be4401bf 128
492f957a
AL
129 // In the event of a fatal signal this file will be closed and timestamped.
130 static string FailFile;
131 static int FailFd;
132 static time_t FailTime;
133 static void SigTerm(int);
134
be4401bf
AL
135 public:
136 friend ServerState;
137
be4401bf 138 FileFd *File;
5cb5d8dc 139 ServerState *Server;
be4401bf
AL
140
141 int Loop();
142
b98f2859 143 HttpMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig)
be4401bf 144 {
be4401bf 145 File = 0;
5cb5d8dc 146 Server = 0;
be4401bf
AL
147 };
148};
149
150URI Proxy;
151
152#endif