]> git.saurik.com Git - apt.git/blame - methods/http.h
merged debian/sid
[apt.git] / methods / http.h
CommitLineData
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
ae58a985 6 HTTP Acquire Method - This is the HTTP aquire 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>
42195eb2 17
7330f4df
DK
18#include "server.h"
19
42195eb2
AL
20using std::cout;
21using std::endl;
22
be4401bf 23class HttpMethod;
472ff00e 24class Hashes;
be4401bf
AL
25
26class CircleBuf
27{
28 unsigned char *Buf;
650faab0
DK
29 unsigned long long Size;
30 unsigned long long InP;
31 unsigned long long OutP;
8f3ba4e8 32 std::string OutQueue;
650faab0
DK
33 unsigned long long StrPos;
34 unsigned long long MaxGet;
be4401bf 35 struct timeval Start;
7330f4df 36
650faab0
DK
37 static unsigned long long BwReadLimit;
38 static unsigned long long BwTickReadData;
7c6e2dc7
MV
39 static struct timeval BwReadTick;
40 static const unsigned int BW_HZ;
41
74b22002 42 unsigned long long LeftRead() const
be4401bf 43 {
650faab0 44 unsigned long long Sz = Size - (InP - OutP);
be4401bf
AL
45 if (Sz > Size - (InP%Size))
46 Sz = Size - (InP%Size);
47 return Sz;
48 }
74b22002 49 unsigned long long LeftWrite() const
be4401bf 50 {
650faab0 51 unsigned long long Sz = InP - OutP;
be4401bf
AL
52 if (InP > MaxGet)
53 Sz = MaxGet - OutP;
54 if (Sz > Size - (OutP%Size))
55 Sz = Size - (OutP%Size);
56 return Sz;
57 }
58 void FillOut();
7330f4df 59
be4401bf 60 public:
63b1700f 61 Hashes *Hash;
7330f4df 62
be4401bf
AL
63 // Read data in
64 bool Read(int Fd);
8f3ba4e8 65 bool Read(std::string Data);
7330f4df 66
be4401bf
AL
67 // Write data out
68 bool Write(int Fd);
8f3ba4e8 69 bool WriteTillEl(std::string &Data,bool Single = false);
7330f4df 70
be4401bf 71 // Control the write limit
7330f4df 72 void Limit(long long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;}
f5a34606
DK
73 bool IsLimit() const {return MaxGet == OutP;};
74 void Print() const {cout << MaxGet << ',' << OutP << endl;};
be4401bf
AL
75
76 // Test for free space in the buffer
f5a34606
DK
77 bool ReadSpace() const {return Size - (InP - OutP) > 0;};
78 bool WriteSpace() const {return InP - OutP > 0;};
be4401bf
AL
79
80 // Dump everything
81 void Reset();
82 void Stats();
83
650faab0 84 CircleBuf(unsigned long long Size);
472ff00e 85 ~CircleBuf();
be4401bf
AL
86};
87
7330f4df 88struct HttpServerState: public ServerState
be4401bf 89{
be4401bf
AL
90 // This is the connection itself. Output is data FROM the server
91 CircleBuf In;
92 CircleBuf Out;
93 int ServerFd;
7330f4df
DK
94
95 protected:
96 virtual bool ReadHeaderLines(std::string &Data);
97 virtual bool LoadNextResponse(bool const ToFile, FileFd * const File);
98 virtual bool WriteResponse(std::string const &Data);
99
100 public:
101 virtual void Reset() { ServerState::Reset(); ServerFd = -1; };
102
103 virtual bool RunData(FileFd * const File);
104
105 virtual bool Open();
106 virtual bool IsOpen();
107 virtual bool Close();
108 virtual bool InitHashes(FileFd &File);
109 virtual Hashes * GetHashes();
110 virtual bool Die(FileFd &File);
111 virtual bool Flush(FileFd * const File);
112 virtual bool Go(bool ToFile, FileFd * const File);
113
114 HttpServerState(URI Srv, HttpMethod *Owner);
115 virtual ~HttpServerState() {Close();};
be4401bf
AL
116};
117
7330f4df 118class HttpMethod : public ServerMethod
be4401bf 119{
7330f4df
DK
120 public:
121 virtual void SendReq(FetchItem *Itm);
7273e494
MV
122
123 /** \brief Try to AutoDetect the proxy */
bd49b02c 124 bool AutoDetectProxy();
5cb5d8dc 125
8f3ba4e8 126 virtual bool Configuration(std::string Message);
7330f4df
DK
127
128 virtual ServerState * CreateServerState(URI uri);
fd46d305 129 virtual void RotateDNS();
5f6b130d
MV
130
131 protected:
8f3ba4e8 132 std::string AutoDetectProxyCmd;
7273e494 133
be4401bf 134 public:
7330f4df
DK
135 friend struct HttpServerState;
136
137 HttpMethod() : ServerMethod("1.2",Pipeline | SendConfig)
be4401bf 138 {
be4401bf 139 File = 0;
5cb5d8dc 140 Server = 0;
be4401bf
AL
141 };
142};
143
be4401bf 144#endif