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>
32 unsigned long long Size
;
33 unsigned long long InP
;
34 unsigned long long OutP
;
36 unsigned long long StrPos
;
37 unsigned long long MaxGet
;
40 static unsigned long long BwReadLimit
;
41 static unsigned long long BwTickReadData
;
42 static struct timeval BwReadTick
;
43 static const unsigned int BW_HZ
;
45 unsigned long long LeftRead() const
47 unsigned long long Sz
= Size
- (InP
- OutP
);
48 if (Sz
> Size
- (InP%Size
))
49 Sz
= Size
- (InP%Size
);
52 unsigned long long LeftWrite() const
54 unsigned long long Sz
= InP
- OutP
;
57 if (Sz
> Size
- (OutP%Size
))
58 Sz
= Size
- (OutP%Size
);
65 // total amount of data that got written so far
66 unsigned long long TotalWriten
;
70 bool Read(std::string
const &Data
);
74 bool WriteTillEl(std::string
&Data
,bool Single
= false);
76 // Control the write limit
77 void Limit(long long Max
) {if (Max
== -1) MaxGet
= 0-1; else MaxGet
= OutP
+ Max
;}
78 bool IsLimit() const {return MaxGet
== OutP
;};
79 void Print() const {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
81 // Test for free space in the buffer
82 bool ReadSpace() const {return Size
- (InP
- OutP
) > 0;};
83 bool WriteSpace() const {return InP
- OutP
> 0;};
89 CircleBuf(HttpMethod
const * const Owner
, unsigned long long Size
);
93 struct HttpServerState
: public ServerState
95 // This is the connection itself. Output is data FROM the server
101 virtual bool ReadHeaderLines(std::string
&Data
) APT_OVERRIDE
;
102 virtual bool LoadNextResponse(bool const ToFile
, FileFd
* const File
) APT_OVERRIDE
;
103 virtual bool WriteResponse(std::string
const &Data
) APT_OVERRIDE
;
106 virtual void Reset(bool const Everything
= true) APT_OVERRIDE
;
108 virtual bool RunData(FileFd
* const File
) APT_OVERRIDE
;
109 virtual bool RunDataToDevNull() 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
* const 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 std::unique_ptr
<ServerState
> CreateServerState(URI
const &uri
) APT_OVERRIDE
;
130 virtual void RotateDNS() APT_OVERRIDE
;
131 virtual DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
) APT_OVERRIDE
;
134 std::string AutoDetectProxyCmd
;
137 friend struct HttpServerState
;
139 explicit HttpMethod(std::string
&&pProg
);