]>
git.saurik.com Git - apt.git/blob - methods/server.h
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/acquire-method.h>
30 // This is the last parsed Header Line
36 // These are some statistics from the last parsed header lines
38 // total size of the usable content (aka: the file)
39 unsigned long long TotalFileSize
;
40 // size we actually download (can be smaller than Size if we have partial content)
41 unsigned long long DownloadSize
;
42 // size of junk content (aka: server error pages)
43 unsigned long long JunkSize
;
44 // The start of the data (for partial content)
45 unsigned long long StartPos
;
49 enum {Chunked
,Stream
,Closes
} Encoding
;
50 enum {Header
, Data
} State
;
54 // This is a Persistent attribute of the server itself.
58 unsigned long TimeOut
;
60 unsigned long long MaximumSize
;
65 virtual bool ReadHeaderLines(std::string
&Data
) = 0;
66 virtual bool LoadNextResponse(bool const ToFile
, FileFd
* const File
) = 0;
69 bool HeaderLine(std::string Line
);
71 /** \brief Result of the header acquire */
72 enum RunHeadersResult
{
73 /** \brief Header ok */
75 /** \brief IO error while retrieving */
77 /** \brief Parse error after retrieving */
78 RUN_HEADERS_PARSE_ERROR
80 /** \brief Get the headers before the data */
81 RunHeadersResult
RunHeaders(FileFd
* const File
, const std::string
&Uri
);
82 bool AddPartialFileToHashes(FileFd
&File
);
84 bool Comp(URI Other
) const {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
85 virtual void Reset() {Major
= 0; Minor
= 0; Result
= 0; Code
[0] = '\0'; TotalFileSize
= 0; JunkSize
= 0;
86 StartPos
= 0; Encoding
= Closes
; time(&Date
); HaveContent
= false;
87 State
= Header
; Persistent
= false; Pipeline
= true; MaximumSize
= 0;};
88 virtual bool WriteResponse(std::string
const &Data
) = 0;
90 /** \brief Transfer the data from the socket */
91 virtual bool RunData(FileFd
* const File
) = 0;
93 virtual bool Open() = 0;
94 virtual bool IsOpen() = 0;
95 virtual bool Close() = 0;
96 virtual bool InitHashes(HashStringList
const &ExpectedHashes
) = 0;
97 virtual Hashes
* GetHashes() = 0;
98 virtual bool Die(FileFd
&File
) = 0;
99 virtual bool Flush(FileFd
* const File
) = 0;
100 virtual bool Go(bool ToFile
, FileFd
* const File
) = 0;
102 ServerState(URI Srv
, ServerMethod
*Owner
);
103 virtual ~ServerState() {};
106 class ServerMethod
: public pkgAcqMethod
109 virtual bool Fetch(FetchItem
*);
115 unsigned long PipelineDepth
;
118 // Find the biggest item in the fetch queue for the checking of the maximum
120 unsigned long long FindMaximumObjectSizeInQueue() const APT_PURE
;
125 /** \brief Result of the header parsing */
126 enum DealWithHeadersResult
{
127 /** \brief The file is open and ready */
129 /** \brief We got a IMS hit, the file has not changed */
131 /** \brief The server reported a unrecoverable error */
133 /** \brief The server reported a error with a error content page */
134 ERROR_WITH_CONTENT_PAGE
,
135 /** \brief An error on the client side */
136 ERROR_NOT_FROM_SERVER
,
137 /** \brief A redirect or retry request */
138 TRY_AGAIN_OR_REDIRECT
140 /** \brief Handle the retrieved header data */
141 DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
);
143 // In the event of a fatal signal this file will be closed and timestamped.
144 static std::string FailFile
;
146 static time_t FailTime
;
147 static APT_NORETURN
void SigTerm(int);
149 virtual bool Configuration(std::string Message
);
150 virtual bool Flush() { return Server
->Flush(File
); };
154 virtual void SendReq(FetchItem
*Itm
) = 0;
155 virtual ServerState
* CreateServerState(URI uri
) = 0;
156 virtual void RotateDNS() = 0;
158 ServerMethod(const char *Ver
,unsigned long Flags
= 0) : pkgAcqMethod(Ver
, Flags
), Server(NULL
), File(NULL
), PipelineDepth(10), AllowRedirect(false), Debug(false) {};
159 virtual ~ServerMethod() {};