]> git.saurik.com Git - apt.git/blob - methods/http.h
Fixed See Also
[apt.git] / methods / http.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/// $Id: http.h,v 1.6 1998/12/10 05:39:56 jgg Exp $
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
83 // These are some statistics from the last parsed header lines
84 unsigned long Size;
85 signed long StartPos;
86 time_t Date;
87 bool HaveContent;
88 enum {Chunked,Stream,Closes} Encoding;
89 enum {Header, Data} State;
90
91 HttpMethod *Owner;
92
93 // This is the connection itself. Output is data FROM the server
94 CircleBuf In;
95 CircleBuf Out;
96 int ServerFd;
97 URI ServerName;
98
99 bool HeaderLine(string Line);
100 bool Comp(URI Other) {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
101 void Reset() {Major = 0; Minor = 0; Result = 0; Size = 0; StartPos = 0;
102 Encoding = Closes; time(&Date); ServerFd = -1;};
103 int RunHeaders();
104 bool RunData();
105
106 bool Open();
107 bool Close();
108
109 ServerState(URI Srv,HttpMethod *Owner);
110 ~ServerState() {Close();};
111 };
112
113 class HttpMethod : public pkgAcqMethod
114 {
115 void SendReq(FetchItem *Itm,CircleBuf &Out);
116 bool Go(bool ToFile,ServerState *Srv);
117 bool Flush(ServerState *Srv);
118 bool ServerDie(ServerState *Srv);
119 int DealWithHeaders(FetchResult &Res,ServerState *Srv);
120
121 virtual bool Fetch(FetchItem *);
122 virtual bool Configuration(string Message);
123
124 // In the event of a fatal signal this file will be closed and timestamped.
125 static string FailFile;
126 static int FailFd;
127 static time_t FailTime;
128 static void SigTerm(int);
129
130 public:
131 friend ServerState;
132
133 FileFd *File;
134 ServerState *Server;
135
136 int Loop();
137
138 HttpMethod() : pkgAcqMethod("1.2",Pipeline | SendConfig)
139 {
140 File = 0;
141 Server = 0;
142 };
143 };
144
145 URI Proxy;
146
147 #endif