]>
git.saurik.com Git - apt.git/blob - methods/server.h
0f45ab99493de740159715e7d3488cfdc5081512
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
;
38 unsigned long long StartPos
;
41 enum {Chunked
,Stream
,Closes
} Encoding
;
42 enum {Header
, Data
} State
;
46 // This is a Persistent attribute of the server itself.
50 unsigned long TimeOut
;
55 virtual bool ReadHeaderLines(std::string
&Data
) = 0;
56 virtual bool LoadNextResponse(bool const ToFile
, FileFd
* const File
) = 0;
59 bool HeaderLine(std::string Line
);
61 /** \brief Result of the header acquire */
62 enum RunHeadersResult
{
63 /** \brief Header ok */
65 /** \brief IO error while retrieving */
67 /** \brief Parse error after retrieving */
68 RUN_HEADERS_PARSE_ERROR
70 /** \brief Get the headers before the data */
71 RunHeadersResult
RunHeaders(FileFd
* const File
);
73 bool Comp(URI Other
) const {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
74 virtual void Reset() {Major
= 0; Minor
= 0; Result
= 0; Code
[0] = '\0'; Size
= 0;
75 StartPos
= 0; Encoding
= Closes
; time(&Date
); HaveContent
= false;
76 State
= Header
; Persistent
= false; Pipeline
= true;};
77 virtual bool WriteResponse(std::string
const &Data
) = 0;
79 /** \brief Transfer the data from the socket */
80 virtual bool RunData(FileFd
* const File
) = 0;
82 virtual bool Open() = 0;
83 virtual bool IsOpen() = 0;
84 virtual bool Close() = 0;
85 virtual bool InitHashes(FileFd
&File
) = 0;
86 virtual Hashes
* GetHashes() = 0;
87 virtual bool Die(FileFd
&File
) = 0;
88 virtual bool Flush(FileFd
* const File
) = 0;
89 virtual bool Go(bool ToFile
, FileFd
* const File
) = 0;
91 ServerState(URI Srv
, ServerMethod
*Owner
);
92 virtual ~ServerState() {};
95 class ServerMethod
: public pkgAcqMethod
98 virtual bool Fetch(FetchItem
*);
104 unsigned long PipelineDepth
;
110 /** \brief Result of the header parsing */
111 enum DealWithHeadersResult
{
112 /** \brief The file is open and ready */
114 /** \brief We got a IMS hit, the file has not changed */
116 /** \brief The server reported a unrecoverable error */
118 /** \brief The server reported a error with a error content page */
119 ERROR_WITH_CONTENT_PAGE
,
120 /** \brief An error on the client side */
121 ERROR_NOT_FROM_SERVER
,
122 /** \brief A redirect or retry request */
123 TRY_AGAIN_OR_REDIRECT
125 /** \brief Handle the retrieved header data */
126 DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
);
128 // In the event of a fatal signal this file will be closed and timestamped.
129 static std::string FailFile
;
131 static time_t FailTime
;
132 static APT_NORETURN
void SigTerm(int);
134 virtual bool Configuration(std::string Message
);
135 virtual bool Flush() { return Server
->Flush(File
); };
139 virtual void SendReq(FetchItem
*Itm
) = 0;
140 virtual ServerState
* CreateServerState(URI uri
) = 0;
141 virtual void RotateDNS() = 0;
143 ServerMethod(const char *Ver
,unsigned long Flags
= 0) : pkgAcqMethod(Ver
, Flags
), Server(NULL
), File(NULL
), PipelineDepth(0), AllowRedirect(false), Debug(false) {};
144 virtual ~ServerMethod() {};