]>
git.saurik.com Git - apt.git/blob - methods/http.h
1 // -*- mode: cpp; mode: fold -*-
3 // $Id: http.h,v 1.4 1998/11/11 06:54:22 jgg Exp $
4 /* ######################################################################
6 HTTP Aquire Method - This is the HTTP aquire method for APT.
8 ##################################################################### */
29 unsigned long LeftRead()
31 unsigned long Sz
= Size
- (InP
- OutP
);
32 if (Sz
> Size
- (InP%Size
))
33 Sz
= Size
- (InP%Size
);
36 unsigned long LeftWrite()
38 unsigned long Sz
= InP
- OutP
;
41 if (Sz
> Size
- (OutP%Size
))
42 Sz
= Size
- (OutP%Size
);
53 bool Read(string Data
);
57 bool WriteTillEl(string
&Data
,bool Single
= false);
59 // Control the write limit
60 void Limit(long Max
) {if (Max
== -1) MaxGet
= 0-1; else MaxGet
= OutP
+ Max
;}
61 bool IsLimit() {return MaxGet
== OutP
;};
62 void Print() {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
64 // Test for free space in the buffer
65 bool ReadSpace() {return Size
- (InP
- OutP
) > 0;};
66 bool WriteSpace() {return InP
- OutP
> 0;};
72 CircleBuf(unsigned long Size
);
73 ~CircleBuf() {delete [] Buf
;};
78 // This is the last parsed Header Line
84 // These are some statistics from the last parsed header lines
89 enum {Chunked
,Stream
,Closes
} Encoding
;
90 enum {Header
, Data
} State
;
94 // This is the connection itself. Output is data FROM the server
100 bool HeaderLine(string Line
);
101 bool Comp(URI Other
) {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
102 void Reset() {Major
= 0; Minor
= 0; Result
= 0; Size
= 0; StartPos
= 0;
103 Encoding
= Closes
; time(&Date
); ServerFd
= -1;};
110 ServerState(URI Srv
,HttpMethod
*Owner
);
111 ~ServerState() {Close();};
114 class HttpMethod
: public pkgAcqMethod
116 void SendReq(FetchItem
*Itm
,CircleBuf
&Out
);
117 bool Go(bool ToFile
,ServerState
*Srv
);
118 bool Flush(ServerState
*Srv
);
119 bool ServerDie(ServerState
*Srv
);
120 int DealWithHeaders(FetchResult
&Res
,ServerState
*Srv
);
122 // In the event of a fatal signal this file will be closed and timestamped.
123 static string FailFile
;
125 static time_t FailTime
;
126 static void SigTerm(int);
136 HttpMethod() : pkgAcqMethod("1.2",Pipeline
| SendConfig
)