]>
git.saurik.com Git - apt.git/blob - methods/http.h
6753a990122d9ffb556f463157a3a7ba7975ae99
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 ##################################################################### */
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()
41 unsigned long Sz
= Size
- (InP
- OutP
);
42 if (Sz
> Size
- (InP%Size
))
43 Sz
= Size
- (InP%Size
);
46 unsigned long LeftWrite()
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() {return MaxGet
== OutP
;};
72 void Print() {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
74 // Test for free space in the buffer
75 bool ReadSpace() {return Size
- (InP
- OutP
) > 0;};
76 bool WriteSpace() {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
;
103 // This is a Persistent attribute of the server itself.
108 // This is the connection itself. Output is data FROM the server
114 bool HeaderLine(string Line
);
115 bool Comp(URI Other
) {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
116 void Reset() {Major
= 0; Minor
= 0; Result
= 0; Size
= 0; StartPos
= 0;
117 Encoding
= Closes
; time(&Date
); ServerFd
= -1;
125 ServerState(URI Srv
,HttpMethod
*Owner
);
126 ~ServerState() {Close();};
129 class HttpMethod
: public pkgAcqMethod
131 void SendReq(FetchItem
*Itm
,CircleBuf
&Out
);
132 bool Go(bool ToFile
,ServerState
*Srv
);
133 bool Flush(ServerState
*Srv
);
134 bool ServerDie(ServerState
*Srv
);
135 int DealWithHeaders(FetchResult
&Res
,ServerState
*Srv
);
137 virtual bool Fetch(FetchItem
*);
138 virtual bool Configuration(string Message
);
140 // In the event of a fatal signal this file will be closed and timestamped.
141 static string FailFile
;
143 static time_t FailTime
;
144 static void SigTerm(int);
147 friend class ServerState
;
154 HttpMethod() : pkgAcqMethod("1.2",Pipeline
| SendConfig
)