]>
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
37 unsigned long long Size
; // size of the usable content (aka: the file)
38 unsigned long long JunkSize
; // size of junk content (aka: server error pages)
39 unsigned long long StartPos
;
42 enum {Chunked
,Stream
,Closes
} Encoding
;
43 enum {Header
, Data
} State
;
47 // This is a Persistent attribute of the server itself.
51 unsigned long TimeOut
;
56 virtual bool ReadHeaderLines(std::string
&Data
) = 0;
57 virtual bool LoadNextResponse(bool const ToFile
, FileFd
* const File
) = 0;
60 bool HeaderLine(std::string Line
);
62 /** \brief Result of the header acquire */
63 enum RunHeadersResult
{
64 /** \brief Header ok */
66 /** \brief IO error while retrieving */
68 /** \brief Parse error after retrieving */
69 RUN_HEADERS_PARSE_ERROR
71 /** \brief Get the headers before the data */
72 RunHeadersResult
RunHeaders(FileFd
* const File
, const std::string
&Uri
);
74 bool Comp(URI Other
) const {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
75 virtual void Reset() {Major
= 0; Minor
= 0; Result
= 0; Code
[0] = '\0'; Size
= 0; JunkSize
= 0;
76 StartPos
= 0; Encoding
= Closes
; time(&Date
); HaveContent
= false;
77 State
= Header
; Persistent
= false; Pipeline
= true;};
78 virtual bool WriteResponse(std::string
const &Data
) = 0;
80 /** \brief Transfer the data from the socket */
81 virtual bool RunData(FileFd
* const File
) = 0;
83 virtual bool Open() = 0;
84 virtual bool IsOpen() = 0;
85 virtual bool Close() = 0;
86 virtual bool InitHashes(FileFd
&File
) = 0;
87 virtual Hashes
* GetHashes() = 0;
88 virtual bool Die(FileFd
&File
) = 0;
89 virtual bool Flush(FileFd
* const File
) = 0;
90 virtual bool Go(bool ToFile
, FileFd
* const File
) = 0;
92 ServerState(URI Srv
, ServerMethod
*Owner
);
93 virtual ~ServerState() {};
96 class ServerMethod
: public pkgAcqMethod
99 virtual bool Fetch(FetchItem
*);
105 unsigned long PipelineDepth
;
111 /** \brief Result of the header parsing */
112 enum DealWithHeadersResult
{
113 /** \brief The file is open and ready */
115 /** \brief We got a IMS hit, the file has not changed */
117 /** \brief The server reported a unrecoverable error */
119 /** \brief The server reported a error with a error content page */
120 ERROR_WITH_CONTENT_PAGE
,
121 /** \brief An error on the client side */
122 ERROR_NOT_FROM_SERVER
,
123 /** \brief A redirect or retry request */
124 TRY_AGAIN_OR_REDIRECT
126 /** \brief Handle the retrieved header data */
127 DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
);
129 // In the event of a fatal signal this file will be closed and timestamped.
130 static std::string FailFile
;
132 static time_t FailTime
;
133 static APT_NORETURN
void SigTerm(int);
135 virtual bool Configuration(std::string Message
);
136 virtual bool Flush() { return Server
->Flush(File
); };
140 virtual void SendReq(FetchItem
*Itm
) = 0;
141 virtual ServerState
* CreateServerState(URI uri
) = 0;
142 virtual void RotateDNS() = 0;
144 ServerMethod(const char *Ver
,unsigned long Flags
= 0) : pkgAcqMethod(Ver
, Flags
), Server(NULL
), File(NULL
), PipelineDepth(0), AllowRedirect(false), Debug(false) {};
145 virtual ~ServerMethod() {};