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 ##################################################################### */
16 #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
);
66 bool Read(std::string Data
);
70 bool WriteTillEl(std::string
&Data
,bool Single
= false);
72 // Control the write limit
73 void Limit(long long Max
) {if (Max
== -1) MaxGet
= 0-1; else MaxGet
= OutP
+ Max
;}
74 bool IsLimit() const {return MaxGet
== OutP
;};
75 void Print() const {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
77 // Test for free space in the buffer
78 bool ReadSpace() const {return Size
- (InP
- OutP
) > 0;};
79 bool WriteSpace() const {return InP
- OutP
> 0;};
85 CircleBuf(unsigned long long Size
);
91 // This is the last parsed Header Line
97 // These are some statistics from the last parsed header lines
98 unsigned long long Size
;
99 signed long long StartPos
;
102 enum {Chunked
,Stream
,Closes
} Encoding
;
103 enum {Header
, Data
} State
;
105 std::string Location
;
107 // This is a Persistent attribute of the server itself.
112 // This is the connection itself. Output is data FROM the server
118 bool HeaderLine(std::string Line
);
119 bool Comp(URI Other
) const {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
120 void Reset() {Major
= 0; Minor
= 0; Result
= 0; Size
= 0; StartPos
= 0;
121 Encoding
= Closes
; time(&Date
); ServerFd
= -1;
124 /** \brief Result of the header acquire */
125 enum RunHeadersResult
{
126 /** \brief Header ok */
128 /** \brief IO error while retrieving */
129 RUN_HEADERS_IO_ERROR
,
130 /** \brief Parse error after retrieving */
131 RUN_HEADERS_PARSE_ERROR
,
133 /** \brief Get the headers before the data */
134 RunHeadersResult
RunHeaders();
135 /** \brief Transfer the data from the socket */
141 ServerState(URI Srv
,HttpMethod
*Owner
);
142 ~ServerState() {Close();};
145 class HttpMethod
: public pkgAcqMethod
147 void SendReq(FetchItem
*Itm
,CircleBuf
&Out
);
148 bool Go(bool ToFile
,ServerState
*Srv
);
149 bool Flush(ServerState
*Srv
);
150 bool ServerDie(ServerState
*Srv
);
152 /** \brief Result of the header parsing */
153 enum DealWithHeadersResult
{
154 /** \brief The file is open and ready */
156 /** \brief We got a IMS hit, the file has not changed */
158 /** \brief The server reported a unrecoverable error */
160 /** \brief The server reported a error with a error content page */
161 ERROR_WITH_CONTENT_PAGE
,
162 /** \brief A error on the client side */
163 ERROR_NOT_FROM_SERVER
,
164 /** \brief A redirect or retry request */
165 TRY_AGAIN_OR_REDIRECT
167 /** \brief Handle the retrieved header data */
168 DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
,ServerState
*Srv
);
170 /** \brief Try to AutoDetect the proxy */
171 bool AutoDetectProxy();
173 virtual bool Configuration(std::string Message
);
175 // In the event of a fatal signal this file will be closed and timestamped.
176 static std::string FailFile
;
178 static time_t FailTime
;
179 static void SigTerm(int);
182 virtual bool Fetch(FetchItem
*);
185 std::string AutoDetectProxyCmd
;
188 friend struct ServerState
;
195 HttpMethod() : pkgAcqMethod("1.2",Pipeline
| SendConfig
)