1 // -*- mode: cpp; mode: fold -*-
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 $
4 /* ######################################################################
6 HTTP Acquire Method - This is the HTTP acquire method for APT.
8 ##################################################################### */
14 #include <apt-pkg/strutl.h>
15 #include <apt-pkg/acquire-method.h>
33 unsigned long long Size
;
34 unsigned long long InP
;
35 unsigned long long OutP
;
37 unsigned long long StrPos
;
38 unsigned long long MaxGet
;
41 static unsigned long long BwReadLimit
;
42 static unsigned long long BwTickReadData
;
43 static struct timeval BwReadTick
;
44 static const unsigned int BW_HZ
;
46 unsigned long long LeftRead() const
48 unsigned long long Sz
= Size
- (InP
- OutP
);
49 if (Sz
> Size
- (InP%Size
))
50 Sz
= Size
- (InP%Size
);
53 unsigned long long LeftWrite() const
55 unsigned long long Sz
= InP
- OutP
;
58 if (Sz
> Size
- (OutP%Size
))
59 Sz
= Size
- (OutP%Size
);
66 // total amount of data that got written so far
67 unsigned long long TotalWriten
;
71 bool Read(std::string Data
);
75 bool WriteTillEl(std::string
&Data
,bool Single
= false);
77 // Control the write limit
78 void Limit(long long Max
) {if (Max
== -1) MaxGet
= 0-1; else MaxGet
= OutP
+ Max
;}
79 bool IsLimit() const {return MaxGet
== OutP
;};
80 void Print() const {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
82 // Test for free space in the buffer
83 bool ReadSpace() const {return Size
- (InP
- OutP
) > 0;};
84 bool WriteSpace() const {return InP
- OutP
> 0;};
90 CircleBuf(unsigned long long Size
);
94 struct HttpServerState
: public ServerState
96 // This is the connection itself. Output is data FROM the server
102 virtual bool ReadHeaderLines(std::string
&Data
) APT_OVERRIDE
;
103 virtual bool LoadNextResponse(bool const ToFile
, FileFd
* const File
) APT_OVERRIDE
;
104 virtual bool WriteResponse(std::string
const &Data
) APT_OVERRIDE
;
107 virtual void Reset() APT_OVERRIDE
{ ServerState::Reset(); ServerFd
= -1; };
109 virtual bool RunData(FileFd
* const File
) APT_OVERRIDE
;
111 virtual bool Open() APT_OVERRIDE
;
112 virtual bool IsOpen() APT_OVERRIDE
;
113 virtual bool Close() APT_OVERRIDE
;
114 virtual bool InitHashes(HashStringList
const &ExpectedHashes
) APT_OVERRIDE
;
115 virtual Hashes
* GetHashes() APT_OVERRIDE
;
116 virtual bool Die(FileFd
&File
) APT_OVERRIDE
;
117 virtual bool Flush(FileFd
* const File
) APT_OVERRIDE
;
118 virtual bool Go(bool ToFile
, FileFd
* const File
) APT_OVERRIDE
;
120 HttpServerState(URI Srv
, HttpMethod
*Owner
);
121 virtual ~HttpServerState() {Close();};
124 class HttpMethod
: public ServerMethod
127 virtual void SendReq(FetchItem
*Itm
) APT_OVERRIDE
;
129 virtual bool Configuration(std::string Message
) APT_OVERRIDE
;
131 virtual std::unique_ptr
<ServerState
> CreateServerState(URI
const &uri
) APT_OVERRIDE
;
132 virtual void RotateDNS() APT_OVERRIDE
;
135 std::string AutoDetectProxyCmd
;
138 friend struct HttpServerState
;
140 HttpMethod() : ServerMethod("http", "1.2",Pipeline
| SendConfig
)