apt  2.2.4
About: Apt (Advanced Package Tool) is a management system for software packages (Debian/Ubuntu). Release series 2.2.
  Fossies Dox: apt-2.2.4.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

http.h
Go to the documentation of this file.
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 /* ######################################################################
4 
5  HTTP Acquire Method - This is the HTTP acquire method for APT.
6 
7  ##################################################################### */
8  /*}}}*/
9 
10 #ifndef APT_HTTP_H
11 #define APT_HTTP_H
12 
13 #include <apt-pkg/strutl.h>
14 
15 #include <chrono>
16 #include <iostream>
17 #include <memory>
18 #include <string>
19 #include <sys/time.h>
20 
21 #include "basehttp.h"
22 #include "connect.h"
23 
24 using std::cout;
25 using std::endl;
26 
27 class FileFd;
28 class HttpMethod;
29 class Hashes;
30 
31 class CircleBuf
32 {
33  unsigned char *Buf;
34  unsigned long long Size;
35  unsigned long long InP;
36  unsigned long long OutP;
37  std::string OutQueue;
38  unsigned long long StrPos;
39  unsigned long long MaxGet;
40 
41  static unsigned long long BwReadLimit;
42  static unsigned long long BwTickReadData;
43  static std::chrono::steady_clock::duration BwReadTick;
44  static const unsigned int BW_HZ;
45 
46  unsigned long long LeftRead() const
47  {
48  unsigned long long Sz = Size - (InP - OutP);
49  if (Sz > Size - (InP%Size))
50  Sz = Size - (InP%Size);
51  return Sz;
52  }
53  unsigned long long LeftWrite() const
54  {
55  unsigned long long Sz = InP - OutP;
56  if (InP > MaxGet)
57  Sz = MaxGet - OutP;
58  if (Sz > Size - (OutP%Size))
59  Sz = Size - (OutP%Size);
60  return Sz;
61  }
62  void FillOut();
63 
64  public:
66  // total amount of data that got written so far
67  unsigned long long TotalWriten;
68 
69  // Read data in
70  bool Read(std::unique_ptr<MethodFd> const &Fd);
71  bool Read(std::string const &Data);
72 
73  // Write data out
74  bool Write(std::unique_ptr<MethodFd> const &Fd);
75  bool Write(std::string &Data);
76  bool WriteTillEl(std::string &Data,bool Single = false);
77 
78  // Control the write limit
79  void Limit(long long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;}
80  bool IsLimit() const {return MaxGet == OutP;};
81  void Print() const {cout << MaxGet << ',' << OutP << endl;};
82 
83  // Test for free space in the buffer
84  bool ReadSpace() const {return Size - (InP - OutP) > 0;};
85  bool WriteSpace() const {return InP - OutP > 0;};
86 
87  void Reset();
88 
89  CircleBuf(HttpMethod const * const Owner, unsigned long long Size);
90  ~CircleBuf();
91 };
92 
94 {
95  // This is the connection itself. Output is data FROM the server
98  std::unique_ptr<MethodFd> ServerFd;
99 
100  protected:
101  virtual bool ReadHeaderLines(std::string &Data) APT_OVERRIDE;
102  virtual ResultState LoadNextResponse(bool const ToFile, RequestState &Req) APT_OVERRIDE;
103  virtual bool WriteResponse(std::string const &Data) APT_OVERRIDE;
104 
105  public:
106  virtual void Reset() APT_OVERRIDE;
107 
110 
111  virtual ResultState Open() APT_OVERRIDE;
112  virtual bool IsOpen() APT_OVERRIDE;
113  virtual bool Close() APT_OVERRIDE;
114  virtual bool InitHashes(HashStringList const &ExpectedHashes) APT_OVERRIDE;
115  virtual Hashes * GetHashes() APT_OVERRIDE;
117  virtual bool Flush(FileFd *const File, bool MustComplete = true) APT_OVERRIDE;
118  virtual ResultState Go(bool ToFile, RequestState &Req) APT_OVERRIDE;
119 
121  virtual ~HttpServerState() {Close();};
122 };
123 
125 {
126  public:
127  virtual void SendReq(FetchItem *Itm) APT_OVERRIDE;
128 
129  virtual std::unique_ptr<ServerState> CreateServerState(URI const &uri) APT_OVERRIDE;
130  virtual void RotateDNS() APT_OVERRIDE;
132 
133  protected:
134  std::string AutoDetectProxyCmd;
135 
136  public:
137  friend struct HttpServerState;
138 
139  explicit HttpMethod(std::string &&pProg);
140 };
141 
142 #endif
ResultState
Definition: aptmethod.h:35
DealWithHeadersResult
Result of the header parsing.
Definition: basehttp.h:137
Definition: http.h:32
unsigned long long StrPos
Definition: http.h:38
void FillOut()
Definition: http.cc:161
bool Read(std::unique_ptr< MethodFd > const &Fd)
Definition: http.cc:95
static std::chrono::steady_clock::duration BwReadTick
Definition: http.h:43
unsigned long long OutP
Definition: http.h:36
void Limit(long long Max)
Definition: http.h:79
CircleBuf(HttpMethod const *const Owner, unsigned long long Size)
Definition: http.cc:64
unsigned long long Size
Definition: http.h:34
std::string OutQueue
Definition: http.h:37
unsigned long long TotalWriten
Definition: http.h:67
void Reset()
Definition: http.cc:76
unsigned char * Buf
Definition: http.h:33
~CircleBuf()
Definition: http.cc:273
bool ReadSpace() const
Definition: http.h:84
unsigned long long LeftRead() const
Definition: http.h:46
Hashes * Hash
Definition: http.h:65
static unsigned long long BwReadLimit
Definition: http.h:41
bool WriteTillEl(std::string &Data, bool Single=false)
Definition: http.cc:229
bool IsLimit() const
Definition: http.h:80
static const unsigned int BW_HZ
Definition: http.h:44
bool WriteSpace() const
Definition: http.h:85
unsigned long long LeftWrite() const
Definition: http.h:53
static unsigned long long BwTickReadData
Definition: http.h:42
unsigned long long InP
Definition: http.h:35
void Print() const
Definition: http.h:81
unsigned long long MaxGet
Definition: http.h:39
bool Write(std::unique_ptr< MethodFd > const &Fd)
Definition: http.cc:192
Definition: fileutl.h:39
Definition: hashes.h:170
virtual void SendReq(FetchItem *Itm) APT_OVERRIDE
Definition: http.cc:877
std::string AutoDetectProxyCmd
Definition: http.h:134
HttpMethod(std::string &&pProg)
Definition: http.cc:1024
virtual void RotateDNS() APT_OVERRIDE
Definition: http.cc:995
virtual DealWithHeadersResult DealWithHeaders(FetchResult &Res, RequestState &Req) APT_OVERRIDE
Handle the retrieved header data.
Definition: http.cc:1000
virtual std::unique_ptr< ServerState > CreateServerState(URI const &uri) APT_OVERRIDE
Definition: http.cc:990
Definition: strutl.h:193
#define APT_OVERRIDE
Definition: macros.h:111
virtual Hashes * GetHashes() APT_OVERRIDE
Definition: http.cc:693
CircleBuf Out
Definition: http.h:97
virtual ResultState RunData(RequestState &Req) APT_OVERRIDE
Transfer the data from the socket.
Definition: http.cc:549
virtual ResultState Die(RequestState &Req) APT_OVERRIDE
Definition: http.cc:699
virtual ResultState Open() APT_OVERRIDE
Definition: http.cc:421
virtual bool Close() APT_OVERRIDE
Definition: http.cc:542
std::unique_ptr< MethodFd > ServerFd
Definition: http.h:98
virtual bool ReadHeaderLines(std::string &Data) APT_OVERRIDE
Definition: http.cc:659
CircleBuf In
Definition: http.h:96
virtual void Reset() APT_OVERRIDE
Definition: http.cc:686
virtual bool Flush(FileFd *const File, bool MustComplete=true) APT_OVERRIDE
Definition: http.cc:737
virtual bool IsOpen() APT_OVERRIDE
Definition: http.cc:674
virtual bool WriteResponse(std::string const &Data) APT_OVERRIDE
Definition: http.cc:669
virtual ResultState LoadNextResponse(bool const ToFile, RequestState &Req) APT_OVERRIDE
Definition: http.cc:664
virtual bool InitHashes(HashStringList const &ExpectedHashes) APT_OVERRIDE
Definition: http.cc:679
virtual ResultState RunDataToDevNull(RequestState &Req) APT_OVERRIDE
Definition: http.cc:650
virtual ResultState Go(bool ToFile, RequestState &Req) APT_OVERRIDE
Definition: http.cc:762
BaseHttpMethod * Owner
Definition: basehttp.h:78