]>
git.saurik.com Git - apt.git/blob - methods/server.h
6b12c7c7a4b3d68ee942f9ab60bfcd5028eb8ac6
1 // -*- mode: cpp; mode: fold -*-
3 /* ######################################################################
5 Classes dealing with the abstraction of talking to a end via a text
6 protocol like HTTP (which is used by the http and https methods)
8 ##################################################################### */
14 #include <apt-pkg/strutl.h>
15 #include <apt-pkg/fileutl.h>
16 #include "aptmethod.h"
32 unsigned int Major
= 0;
33 unsigned int Minor
= 0;
34 unsigned int Result
= 0;
37 // total size of the usable content (aka: the file)
38 unsigned long long TotalFileSize
= 0;
39 // size we actually download (can be smaller than Size if we have partial content)
40 unsigned long long DownloadSize
= 0;
41 // size of junk content (aka: server error pages)
42 unsigned long long JunkSize
= 0;
43 // The start of the data (for partial content)
44 unsigned long long StartPos
= 0;
46 unsigned long long MaximumSize
= 0;
49 bool HaveContent
= false;
50 enum {Chunked
,Stream
,Closes
} Encoding
= Closes
;
51 enum {Header
, Data
} State
= Header
;
56 ServerMethod
* const Owner
;
57 ServerState
* const Server
;
59 bool HeaderLine(std::string
const &Line
);
60 bool AddPartialFileToHashes(FileFd
&File
);
62 RequestState(ServerMethod
* const Owner
, ServerState
* const Server
) :
63 Owner(Owner
), Server(Server
) { time(&Date
); }
75 unsigned long TimeOut
;
80 virtual bool ReadHeaderLines(std::string
&Data
) = 0;
81 virtual bool LoadNextResponse(bool const ToFile
, RequestState
&Req
) = 0;
85 /** \brief Result of the header acquire */
86 enum RunHeadersResult
{
87 /** \brief Header ok */
89 /** \brief IO error while retrieving */
91 /** \brief Parse error after retrieving */
92 RUN_HEADERS_PARSE_ERROR
94 /** \brief Get the headers before the data */
95 RunHeadersResult
RunHeaders(RequestState
&Req
, const std::string
&Uri
);
97 bool Comp(URI Other
) const {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
99 virtual bool WriteResponse(std::string
const &Data
) = 0;
101 /** \brief Transfer the data from the socket */
102 virtual bool RunData(RequestState
&Req
) = 0;
103 virtual bool RunDataToDevNull(RequestState
&Req
) = 0;
105 virtual bool Open() = 0;
106 virtual bool IsOpen() = 0;
107 virtual bool Close() = 0;
108 virtual bool InitHashes(HashStringList
const &ExpectedHashes
) = 0;
109 virtual bool Die(RequestState
&Req
) = 0;
110 virtual bool Flush(FileFd
* const File
) = 0;
111 virtual bool Go(bool ToFile
, RequestState
&Req
) = 0;
112 virtual Hashes
* GetHashes() = 0;
114 ServerState(URI Srv
, ServerMethod
*Owner
);
115 virtual ~ServerState() {};
118 class ServerMethod
: public aptMethod
121 virtual bool Fetch(FetchItem
*) APT_OVERRIDE
;
123 std::unique_ptr
<ServerState
> Server
;
126 unsigned long PipelineDepth
;
129 // Find the biggest item in the fetch queue for the checking of the maximum
131 unsigned long long FindMaximumObjectSizeInQueue() const APT_PURE
;
136 /** \brief Result of the header parsing */
137 enum DealWithHeadersResult
{
138 /** \brief The file is open and ready */
140 /** \brief We got a IMS hit, the file has not changed */
142 /** \brief The server reported a unrecoverable error */
144 /** \brief The server reported a error with a error content page */
145 ERROR_WITH_CONTENT_PAGE
,
146 /** \brief An error on the client side */
147 ERROR_NOT_FROM_SERVER
,
148 /** \brief A redirect or retry request */
149 TRY_AGAIN_OR_REDIRECT
151 /** \brief Handle the retrieved header data */
152 virtual DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
, RequestState
&Req
);
154 // In the event of a fatal signal this file will be closed and timestamped.
155 static std::string FailFile
;
157 static time_t FailTime
;
158 static APT_NORETURN
void SigTerm(int);
162 virtual void SendReq(FetchItem
*Itm
) = 0;
163 virtual std::unique_ptr
<ServerState
> CreateServerState(URI
const &uri
) = 0;
164 virtual void RotateDNS() = 0;
165 virtual bool Configuration(std::string Message
) APT_OVERRIDE
;
167 bool AddProxyAuth(URI
&Proxy
, URI
const &Server
) const;
169 ServerMethod(std::string
&&Binary
, char const * const Ver
,unsigned long const Flags
);
170 virtual ~ServerMethod() {};