]>
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>
27 // This is the last parsed Header Line
33 // These are some statistics from the last parsed header lines
34 unsigned long long Size
;
35 signed long long StartPos
;
38 enum {Chunked
,Stream
,Closes
} Encoding
;
39 enum {Header
, Data
} State
;
43 // This is a Persistent attribute of the server itself.
47 unsigned long TimeOut
;
52 bool HeaderLine(std::string Line
);
53 virtual bool ReadHeaderLines(std::string
&Data
) = 0;
54 virtual bool LoadNextResponse(bool const ToFile
, FileFd
* const File
) = 0;
57 /** \brief Result of the header acquire */
58 enum RunHeadersResult
{
59 /** \brief Header ok */
61 /** \brief IO error while retrieving */
63 /** \brief Parse error after retrieving */
64 RUN_HEADERS_PARSE_ERROR
,
66 /** \brief Get the headers before the data */
67 RunHeadersResult
RunHeaders(FileFd
* const File
);
69 bool Comp(URI Other
) const {return Other
.Host
== ServerName
.Host
&& Other
.Port
== ServerName
.Port
;};
70 virtual void Reset() {Major
= 0; Minor
= 0; Result
= 0; Code
[0] = '\0'; Size
= 0;
71 StartPos
= 0; Encoding
= Closes
; time(&Date
); HaveContent
= false;
72 State
= Header
; Persistent
= false; Pipeline
= true;};
73 virtual bool WriteResponse(std::string
const &Data
) = 0;
75 /** \brief Transfer the data from the socket */
76 virtual bool RunData(FileFd
* const File
) = 0;
78 virtual bool Open() = 0;
79 virtual bool IsOpen() = 0;
80 virtual bool Close() = 0;
81 virtual bool InitHashes(FileFd
&File
) = 0;
82 virtual Hashes
* GetHashes() = 0;
83 virtual bool Die(FileFd
&File
) = 0;
84 virtual bool Flush(FileFd
* const File
) = 0;
85 virtual bool Go(bool ToFile
, FileFd
* const File
) = 0;
87 ServerState(URI Srv
, ServerMethod
*Owner
);
88 virtual ~ServerState() {};
91 class ServerMethod
: public pkgAcqMethod
94 virtual bool Fetch(FetchItem
*);
100 unsigned long PipelineDepth
;
106 /** \brief Result of the header parsing */
107 enum DealWithHeadersResult
{
108 /** \brief The file is open and ready */
110 /** \brief We got a IMS hit, the file has not changed */
112 /** \brief The server reported a unrecoverable error */
114 /** \brief The server reported a error with a error content page */
115 ERROR_WITH_CONTENT_PAGE
,
116 /** \brief An error on the client side */
117 ERROR_NOT_FROM_SERVER
,
118 /** \brief A redirect or retry request */
119 TRY_AGAIN_OR_REDIRECT
121 /** \brief Handle the retrieved header data */
122 DealWithHeadersResult
DealWithHeaders(FetchResult
&Res
);
124 // In the event of a fatal signal this file will be closed and timestamped.
125 static std::string FailFile
;
127 static time_t FailTime
;
128 static void SigTerm(int);
130 virtual bool Configuration(std::string Message
);
131 virtual bool Flush() { return Server
->Flush(File
); };
135 virtual void SendReq(FetchItem
*Itm
) = 0;
136 virtual ServerState
* CreateServerState(URI uri
) = 0;
138 ServerMethod(const char *Ver
,unsigned long Flags
= 0) : pkgAcqMethod(Ver
, Flags
), PipelineDepth(0), AllowRedirect(false), Debug(false) {};
139 virtual ~ServerMethod() {};