]>
git.saurik.com Git - apt.git/blob - methods/http.h
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 Aquire Method - This is the HTTP aquire method for APT.
8 ##################################################################### */
34 unsigned long LeftRead()
36 unsigned long Sz
= Size
- (InP
- OutP
);
37 if (Sz
> Size
- (InP%Size
))
38 Sz
= Size
- (InP%Size
);
41 unsigned long LeftWrite()
43 unsigned long Sz
= InP
- OutP
;
46 if (Sz
> Size
- (OutP%Size
))
47 Sz
= Size
- (OutP%Size
);
58 bool Read(string Data
);
62 bool WriteTillEl(string
&Data
,bool Single
= false);
64 // Control the write limit
65 void Limit(long Max
) {if (Max
== -1) MaxGet
= 0-1; else MaxGet
= OutP
+ Max
;}
66 bool IsLimit() {return MaxGet
== OutP
;};
67 void Print() {cout
<< MaxGet
<< ',' << OutP
<< endl
;};
69 // Test for free space in the buffer
70 bool ReadSpace() {return Size
- (InP
- OutP
) > 0;};
71 bool WriteSpace() {return InP
- OutP
> 0;};
77 CircleBuf(unsigned long Size
);
78 ~CircleBuf() {delete [] Buf
; delete Hash
;};
83 // This is the last parsed Header Line
89 // These are some statistics from the last parsed header lines
94 enum {Chunked
,Stream
,Closes
} Encoding
;
95 enum {Header
, Data
} State
;
98 // This is a Persistent attribute of the server itself.
103 // This is the connection itself. Output is data FROM the server
109 bool HeaderLine(string Line
);
110 bool Comp(URI Other
) {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
111 void Reset() {Major
= 0; Minor
= 0; Result
= 0; Size
= 0; StartPos
= 0;
112 Encoding
= Closes
; time(&Date
); ServerFd
= -1;
120 ServerState(URI Srv
,HttpMethod
*Owner
);
121 ~ServerState() {Close();};
124 class HttpMethod
: public pkgAcqMethod
126 void SendReq(FetchItem
*Itm
,CircleBuf
&Out
);
127 bool Go(bool ToFile
,ServerState
*Srv
);
128 bool Flush(ServerState
*Srv
);
129 bool ServerDie(ServerState
*Srv
);
130 int DealWithHeaders(FetchResult
&Res
,ServerState
*Srv
);
132 virtual bool Fetch(FetchItem
*);
133 virtual bool Configuration(string Message
);
135 // In the event of a fatal signal this file will be closed and timestamped.
136 static string FailFile
;
138 static time_t FailTime
;
139 static void SigTerm(int);
142 friend class ServerState
;
149 HttpMethod() : pkgAcqMethod("1.2",Pipeline
| SendConfig
)