]> git.saurik.com Git - apt.git/blame - methods/server.h
fix test-cve-2013-1051-InRelease-parsing (fails now in the method)
[apt.git] / methods / server.h
CommitLineData
7330f4df
DK
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
3/* ######################################################################
4
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)
7
8 ##################################################################### */
9 /*}}}*/
10
11#ifndef APT_SERVER_H
12#define APT_SERVER_H
13
14#include <apt-pkg/strutl.h>
453b82a3 15#include <apt-pkg/acquire-method.h>
7330f4df 16
453b82a3
DK
17#include <time.h>
18#include <iostream>
7330f4df
DK
19#include <string>
20
21using std::cout;
22using std::endl;
23
24class Hashes;
25class ServerMethod;
26class FileFd;
27
28struct ServerState
29{
30 // This is the last parsed Header Line
31 unsigned int Major;
32 unsigned int Minor;
33 unsigned int Result;
34 char Code[360];
35
36 // These are some statistics from the last parsed header lines
37 unsigned long long Size;
3de8f956 38 unsigned long long StartPos;
7330f4df
DK
39 time_t Date;
40 bool HaveContent;
41 enum {Chunked,Stream,Closes} Encoding;
42 enum {Header, Data} State;
43 bool Persistent;
44 std::string Location;
45
46 // This is a Persistent attribute of the server itself.
47 bool Pipeline;
48 URI ServerName;
49 URI Proxy;
50 unsigned long TimeOut;
51
dcd5856b
MV
52 unsigned long long ExpectedSize;
53
7330f4df
DK
54 protected:
55 ServerMethod *Owner;
56
7330f4df
DK
57 virtual bool ReadHeaderLines(std::string &Data) = 0;
58 virtual bool LoadNextResponse(bool const ToFile, FileFd * const File) = 0;
59
60 public:
fd46d305
DK
61 bool HeaderLine(std::string Line);
62
7330f4df
DK
63 /** \brief Result of the header acquire */
64 enum RunHeadersResult {
65 /** \brief Header ok */
66 RUN_HEADERS_OK,
67 /** \brief IO error while retrieving */
68 RUN_HEADERS_IO_ERROR,
69 /** \brief Parse error after retrieving */
d3e8fbb3 70 RUN_HEADERS_PARSE_ERROR
7330f4df
DK
71 };
72 /** \brief Get the headers before the data */
9622b211 73 RunHeadersResult RunHeaders(FileFd * const File, const std::string &Uri);
7330f4df
DK
74
75 bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
76 virtual void Reset() {Major = 0; Minor = 0; Result = 0; Code[0] = '\0'; Size = 0;
77 StartPos = 0; Encoding = Closes; time(&Date); HaveContent = false;
dcd5856b 78 State = Header; Persistent = false; Pipeline = true; ExpectedSize = 0;};
7330f4df
DK
79 virtual bool WriteResponse(std::string const &Data) = 0;
80
81 /** \brief Transfer the data from the socket */
82 virtual bool RunData(FileFd * const File) = 0;
83
84 virtual bool Open() = 0;
85 virtual bool IsOpen() = 0;
86 virtual bool Close() = 0;
87 virtual bool InitHashes(FileFd &File) = 0;
88 virtual Hashes * GetHashes() = 0;
89 virtual bool Die(FileFd &File) = 0;
90 virtual bool Flush(FileFd * const File) = 0;
91 virtual bool Go(bool ToFile, FileFd * const File) = 0;
92
93 ServerState(URI Srv, ServerMethod *Owner);
94 virtual ~ServerState() {};
95};
96
97class ServerMethod : public pkgAcqMethod
98{
99 protected:
100 virtual bool Fetch(FetchItem *);
101
102 ServerState *Server;
103 std::string NextURI;
104 FileFd *File;
105
106 unsigned long PipelineDepth;
107 bool AllowRedirect;
108
109 public:
110 bool Debug;
111
112 /** \brief Result of the header parsing */
113 enum DealWithHeadersResult {
114 /** \brief The file is open and ready */
115 FILE_IS_OPEN,
116 /** \brief We got a IMS hit, the file has not changed */
117 IMS_HIT,
118 /** \brief The server reported a unrecoverable error */
119 ERROR_UNRECOVERABLE,
120 /** \brief The server reported a error with a error content page */
121 ERROR_WITH_CONTENT_PAGE,
122 /** \brief An error on the client side */
123 ERROR_NOT_FROM_SERVER,
124 /** \brief A redirect or retry request */
125 TRY_AGAIN_OR_REDIRECT
126 };
127 /** \brief Handle the retrieved header data */
128 DealWithHeadersResult DealWithHeaders(FetchResult &Res);
129
130 // In the event of a fatal signal this file will be closed and timestamped.
131 static std::string FailFile;
132 static int FailFd;
133 static time_t FailTime;
a02db58f 134 static APT_NORETURN void SigTerm(int);
7330f4df
DK
135
136 virtual bool Configuration(std::string Message);
137 virtual bool Flush() { return Server->Flush(File); };
138
139 int Loop();
140
141 virtual void SendReq(FetchItem *Itm) = 0;
142 virtual ServerState * CreateServerState(URI uri) = 0;
fd46d305 143 virtual void RotateDNS() = 0;
7330f4df 144
895417ef 145 ServerMethod(const char *Ver,unsigned long Flags = 0) : pkgAcqMethod(Ver, Flags), Server(NULL), File(NULL), PipelineDepth(10), AllowRedirect(false), Debug(false) {};
7330f4df
DK
146 virtual ~ServerMethod() {};
147};
148
149#endif