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/hashes.h>
34 static unsigned long BwReadLimit
;
35 static unsigned long BwTickReadData
;
36 static struct timeval BwReadTick
;
37 static const unsigned int BW_HZ
;
39 unsigned long LeftRead() const
41 unsigned long Sz
= Size
- (InP
- OutP
);
42 if (Sz
> Size
- (InP%Size
))
43 Sz
= Size
- (InP%Size
);
46 unsigned long LeftWrite() const
48 unsigned long Sz
= InP
- OutP
;
51 if (Sz
> Size
- (OutP%Size
))
52 Sz
= Size
- (OutP%Size
);
63 bool Read(string Data
);
67 bool WriteTillEl(string
&Data
,bool Single
= false);
69 // Control the write limit
70 void Limit(long Max
) {if (Max
== -1) MaxGet
= 0-1; else MaxGet
= OutP
+ Max
;}
71 bool IsLimit() const {return MaxGet
== OutP
;};
72 void Print() const {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
74 // Test for free space in the buffer
75 bool ReadSpace() const {return Size
- (InP
- OutP
) > 0;};
76 bool WriteSpace() const {return InP
- OutP
> 0;};
82 CircleBuf(unsigned long Size
);
83 ~CircleBuf() {delete [] Buf
; delete Hash
;};
88 // This is the last parsed Header Line
94 // These are some statistics from the last parsed header lines
99 enum {Chunked
,Stream
,Closes
} Encoding
;
100 enum {Header
, Data
} State
;
104 // This is a Persistent attribute of the server itself.
109 // This is the connection itself. Output is data FROM the server
115 bool HeaderLine(string Line
);
116 bool Comp(URI Other
) const {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
117 void Reset() {Major
= 0; Minor
= 0; Result
= 0; Size
= 0; StartPos
= 0;
118 Encoding
= Closes
; time(&Date
); ServerFd
= -1;
121 /** \brief Result of the header acquire */
122 enum RunHeadersResult
{
123 /** \brief Header ok */
125 /** \brief IO error while retrieving */
126 RUN_HEADERS_IO_ERROR
,
127 /** \brief Parse error after retrieving */
128 RUN_HEADERS_PARSE_ERROR
,
130 /** \brief Get the headers before the data */
131 RunHeadersResult
RunHeaders();
132 /** \brief Transfer the data from the socket */
138 ServerState(URI Srv
,HttpMethod
*Owner
);
139 ~ServerState() {Close();};
142 class HttpMethod
: public pkgAcqMethod
144 void SendReq(FetchItem
*Itm
,CircleBuf
&Out
);
145 bool Go(bool ToFile
,ServerState
*Srv
);
146 bool Flush(ServerState
*Srv
);
147 bool ServerDie(ServerState
*Srv
);
149 /** \brief Result of the header parsing */
150 enum DealWithHeadersResult
{
151 /** \brief The file is open and ready */
153 /** \brief We got a IMS hit, the file has not changed */
155 /** \brief The server reported a unrecoverable error */
157 /** \brief The server reported a error with a error content page */
158 ERROR_WITH_CONTENT_PAGE
,
159 /** \brief A error on the client side */
160 ERROR_NOT_FROM_SERVER
,
161 /** \brief A redirect or retry request */
162 TRY_AGAIN_OR_REDIRECT
164 /** \brief Handle the retrieved header data */
165 DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
,ServerState
*Srv
);
167 /** \brief Try to AutoDetect the proxy */
168 bool AutoDetectProxy();
170 virtual bool Configuration(string Message
);
172 // In the event of a fatal signal this file will be closed and timestamped.
173 static string FailFile
;
175 static time_t FailTime
;
176 static void SigTerm(int);
179 virtual bool Fetch(FetchItem
*);
182 string AutoDetectProxyCmd
;
185 friend struct ServerState
;
192 HttpMethod() : pkgAcqMethod("1.2",Pipeline
| SendConfig
)