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 aquire method for APT.
8 ##################################################################### */
14 #include <apt-pkg/strutl.h>
29 unsigned long long Size
;
30 unsigned long long InP
;
31 unsigned long long OutP
;
33 unsigned long long StrPos
;
34 unsigned long long MaxGet
;
37 static unsigned long long BwReadLimit
;
38 static unsigned long long BwTickReadData
;
39 static struct timeval BwReadTick
;
40 static const unsigned int BW_HZ
;
42 unsigned long long LeftRead() const
44 unsigned long long Sz
= Size
- (InP
- OutP
);
45 if (Sz
> Size
- (InP%Size
))
46 Sz
= Size
- (InP%Size
);
49 unsigned long long LeftWrite() const
51 unsigned long long Sz
= InP
- OutP
;
54 if (Sz
> Size
- (OutP%Size
))
55 Sz
= Size
- (OutP%Size
);
65 bool Read(std::string Data
);
69 bool WriteTillEl(std::string
&Data
,bool Single
= false);
71 // Control the write limit
72 void Limit(long long Max
) {if (Max
== -1) MaxGet
= 0-1; else MaxGet
= OutP
+ Max
;}
73 bool IsLimit() const {return MaxGet
== OutP
;};
74 void Print() const {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
76 // Test for free space in the buffer
77 bool ReadSpace() const {return Size
- (InP
- OutP
) > 0;};
78 bool WriteSpace() const {return InP
- OutP
> 0;};
84 CircleBuf(unsigned long long Size
);
88 struct HttpServerState
: public ServerState
90 // This is the connection itself. Output is data FROM the server
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
);
101 virtual void Reset() { ServerState::Reset(); ServerFd
= -1; };
103 virtual bool RunData(FileFd
* const File
);
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
);
114 HttpServerState(URI Srv
, HttpMethod
*Owner
);
115 virtual ~HttpServerState() {Close();};
118 class HttpMethod
: public ServerMethod
121 virtual void SendReq(FetchItem
*Itm
);
123 /** \brief Try to AutoDetect the proxy */
124 bool AutoDetectProxy();
126 virtual bool Configuration(std::string Message
);
128 virtual ServerState
* CreateServerState(URI uri
);
129 virtual void RotateDNS();
132 std::string AutoDetectProxyCmd
;
135 friend struct HttpServerState
;
137 HttpMethod() : ServerMethod("1.2",Pipeline
| SendConfig
)