]> git.saurik.com Git - apt.git/blame - methods/http.h
close server if parsing of header field failed
[apt.git] / methods / http.h
CommitLineData
be4401bf 1// -*- mode: cpp; mode: fold -*-
a305f593
AL
2// Description /*{{{*/// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $
3// $Id: http.h,v 1.12 2002/04/18 05:09:38 jgg Exp $
be4401bf
AL
4/* ######################################################################
5
1e3f4083 6 HTTP Acquire Method - This is the HTTP acquire method for APT.
be4401bf
AL
7
8 ##################################################################### */
9 /*}}}*/
10
11#ifndef APT_HTTP_H
12#define APT_HTTP_H
13
472ff00e
DK
14#include <apt-pkg/strutl.h>
15
16#include <string>
453b82a3
DK
17#include <sys/time.h>
18#include <iostream>
42195eb2 19
7330f4df
DK
20#include "server.h"
21
42195eb2
AL
22using std::cout;
23using std::endl;
24
453b82a3 25class FileFd;
be4401bf 26class HttpMethod;
472ff00e 27class Hashes;
be4401bf
AL
28
29class CircleBuf
30{
31 unsigned char *Buf;
650faab0
DK
32 unsigned long long Size;
33 unsigned long long InP;
34 unsigned long long OutP;
8f3ba4e8 35 std::string OutQueue;
650faab0
DK
36 unsigned long long StrPos;
37 unsigned long long MaxGet;
be4401bf 38 struct timeval Start;
7330f4df 39
650faab0
DK
40 static unsigned long long BwReadLimit;
41 static unsigned long long BwTickReadData;
7c6e2dc7
MV
42 static struct timeval BwReadTick;
43 static const unsigned int BW_HZ;
44
74b22002 45 unsigned long long LeftRead() const
be4401bf 46 {
650faab0 47 unsigned long long Sz = Size - (InP - OutP);
be4401bf
AL
48 if (Sz > Size - (InP%Size))
49 Sz = Size - (InP%Size);
50 return Sz;
51 }
74b22002 52 unsigned long long LeftWrite() const
be4401bf 53 {
650faab0 54 unsigned long long Sz = InP - OutP;
be4401bf
AL
55 if (InP > MaxGet)
56 Sz = MaxGet - OutP;
57 if (Sz > Size - (OutP%Size))
58 Sz = Size - (OutP%Size);
59 return Sz;
60 }
61 void FillOut();
7330f4df 62
be4401bf 63 public:
63b1700f 64 Hashes *Hash;
dcd5856b
MV
65 // total amount of data that got written so far
66 unsigned long long TotalWriten;
7330f4df 67
be4401bf
AL
68 // Read data in
69 bool Read(int Fd);
8f3ba4e8 70 bool Read(std::string Data);
7330f4df 71
be4401bf
AL
72 // Write data out
73 bool Write(int Fd);
8f3ba4e8 74 bool WriteTillEl(std::string &Data,bool Single = false);
7330f4df 75
be4401bf 76 // Control the write limit
7330f4df 77 void Limit(long long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;}
f5a34606
DK
78 bool IsLimit() const {return MaxGet == OutP;};
79 void Print() const {cout << MaxGet << ',' << OutP << endl;};
be4401bf
AL
80
81 // Test for free space in the buffer
f5a34606
DK
82 bool ReadSpace() const {return Size - (InP - OutP) > 0;};
83 bool WriteSpace() const {return InP - OutP > 0;};
be4401bf 84
be4401bf 85 void Reset();
dcd5856b 86 // Dump everything
be4401bf
AL
87 void Stats();
88
258b9e51 89 explicit CircleBuf(unsigned long long Size);
472ff00e 90 ~CircleBuf();
be4401bf
AL
91};
92
7330f4df 93struct HttpServerState: public ServerState
be4401bf 94{
be4401bf
AL
95 // This is the connection itself. Output is data FROM the server
96 CircleBuf In;
97 CircleBuf Out;
98 int ServerFd;
7330f4df
DK
99
100 protected:
3b302846
DK
101 virtual bool ReadHeaderLines(std::string &Data) APT_OVERRIDE;
102 virtual bool LoadNextResponse(bool const ToFile, FileFd * const File) APT_OVERRIDE;
103 virtual bool WriteResponse(std::string const &Data) APT_OVERRIDE;
7330f4df
DK
104
105 public:
3b302846 106 virtual void Reset() APT_OVERRIDE { ServerState::Reset(); ServerFd = -1; };
7330f4df 107
3b302846 108 virtual bool RunData(FileFd * const File) APT_OVERRIDE;
7330f4df 109
3b302846
DK
110 virtual bool Open() APT_OVERRIDE;
111 virtual bool IsOpen() APT_OVERRIDE;
112 virtual bool Close() APT_OVERRIDE;
113 virtual bool InitHashes(HashStringList const &ExpectedHashes) APT_OVERRIDE;
114 virtual Hashes * GetHashes() APT_OVERRIDE;
115 virtual bool Die(FileFd &File) APT_OVERRIDE;
116 virtual bool Flush(FileFd * const File) APT_OVERRIDE;
117 virtual bool Go(bool ToFile, FileFd * const File) APT_OVERRIDE;
7330f4df
DK
118
119 HttpServerState(URI Srv, HttpMethod *Owner);
120 virtual ~HttpServerState() {Close();};
be4401bf
AL
121};
122
7330f4df 123class HttpMethod : public ServerMethod
be4401bf 124{
7330f4df 125 public:
3b302846 126 virtual void SendReq(FetchItem *Itm) APT_OVERRIDE;
7273e494 127
3b302846 128 virtual bool Configuration(std::string Message) APT_OVERRIDE;
7330f4df 129
830a1b8c 130 virtual std::unique_ptr<ServerState> CreateServerState(URI const &uri) APT_OVERRIDE;
3b302846 131 virtual void RotateDNS() APT_OVERRIDE;
5f6b130d
MV
132
133 protected:
8f3ba4e8 134 std::string AutoDetectProxyCmd;
7273e494 135
be4401bf 136 public:
7330f4df
DK
137 friend struct HttpServerState;
138
23e64f6d 139 HttpMethod() : ServerMethod("http", "1.2",Pipeline | SendConfig)
be4401bf 140 {
be4401bf 141 File = 0;
5cb5d8dc 142 Server = 0;
be4401bf
AL
143 };
144};
145
be4401bf 146#endif