~mvo/apt/mvo

« back to all changes in this revision

Viewing changes to methods/http.h

  • Committer: Michael Vogt
  • Date: 2011-11-10 15:32:52 UTC
  • mfrom: (1561.70.60 debian-experimental2)
  • Revision ID: michael.vogt@ubuntu.com-20111110153252-1u9lc3lm2cgb6b1m
merged from http://bzr.debian.org/bzr/apt/apt/debian-experimental2

Show diffs side-by-side

added added

removed removed

Lines of Context:
13
13
 
14
14
#define MAXLEN 360
15
15
 
16
 
#include <apt-pkg/hashes.h>
 
16
#include <apt-pkg/strutl.h>
 
17
 
 
18
#include <string>
17
19
 
18
20
using std::cout;
19
21
using std::endl;
20
22
 
21
23
class HttpMethod;
 
24
class Hashes;
22
25
 
23
26
class CircleBuf
24
27
{
25
28
   unsigned char *Buf;
26
 
   unsigned long Size;
27
 
   unsigned long InP;
28
 
   unsigned long OutP;
29
 
   string OutQueue;
30
 
   unsigned long StrPos;
31
 
   unsigned long MaxGet;
 
29
   unsigned long long Size;
 
30
   unsigned long long InP;
 
31
   unsigned long long OutP;
 
32
   std::string OutQueue;
 
33
   unsigned long long StrPos;
 
34
   unsigned long long MaxGet;
32
35
   struct timeval Start;
33
36
   
34
 
   static unsigned long BwReadLimit;
35
 
   static unsigned long BwTickReadData;
 
37
   static unsigned long long BwReadLimit;
 
38
   static unsigned long long BwTickReadData;
36
39
   static struct timeval BwReadTick;
37
40
   static const unsigned int BW_HZ;
38
41
 
39
 
   unsigned long LeftRead()
 
42
   unsigned long long LeftRead() const
40
43
   {
41
 
      unsigned long Sz = Size - (InP - OutP);
 
44
      unsigned long long Sz = Size - (InP - OutP);
42
45
      if (Sz > Size - (InP%Size))
43
46
         Sz = Size - (InP%Size);
44
47
      return Sz;
45
48
   }
46
 
   unsigned long LeftWrite()
 
49
   unsigned long long LeftWrite() const
47
50
   {
48
 
      unsigned long Sz = InP - OutP;
 
51
      unsigned long long Sz = InP - OutP;
49
52
      if (InP > MaxGet)
50
53
         Sz = MaxGet - OutP;
51
54
      if (Sz > Size - (OutP%Size))
60
63
   
61
64
   // Read data in
62
65
   bool Read(int Fd);
63
 
   bool Read(string Data);
 
66
   bool Read(std::string Data);
64
67
   
65
68
   // Write data out
66
69
   bool Write(int Fd);
67
 
   bool WriteTillEl(string &Data,bool Single = false);
 
70
   bool WriteTillEl(std::string &Data,bool Single = false);
68
71
   
69
72
   // Control the write limit
70
 
   void Limit(long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;}   
71
 
   bool IsLimit() {return MaxGet == OutP;};
72
 
   void Print() {cout << MaxGet << ',' << OutP << endl;};
 
73
   void Limit(long long Max) {if (Max == -1) MaxGet = 0-1; else MaxGet = OutP + Max;}   
 
74
   bool IsLimit() const {return MaxGet == OutP;};
 
75
   void Print() const {cout << MaxGet << ',' << OutP << endl;};
73
76
 
74
77
   // Test for free space in the buffer
75
 
   bool ReadSpace() {return Size - (InP - OutP) > 0;};
76
 
   bool WriteSpace() {return InP - OutP > 0;};
 
78
   bool ReadSpace() const {return Size - (InP - OutP) > 0;};
 
79
   bool WriteSpace() const {return InP - OutP > 0;};
77
80
 
78
81
   // Dump everything
79
82
   void Reset();
80
83
   void Stats();
81
84
 
82
 
   CircleBuf(unsigned long Size);
83
 
   ~CircleBuf() {delete [] Buf; delete Hash;};
 
85
   CircleBuf(unsigned long long Size);
 
86
   ~CircleBuf();
84
87
};
85
88
 
86
89
struct ServerState
92
95
   char Code[MAXLEN];
93
96
   
94
97
   // These are some statistics from the last parsed header lines
95
 
   unsigned long Size;
96
 
   signed long StartPos;
 
98
   unsigned long long Size;
 
99
   signed long long StartPos;
97
100
   time_t Date;
98
101
   bool HaveContent;
99
102
   enum {Chunked,Stream,Closes} Encoding;
100
103
   enum {Header, Data} State;
101
104
   bool Persistent;
102
 
   string Location;
 
105
   std::string Location;
103
106
   
104
107
   // This is a Persistent attribute of the server itself.
105
108
   bool Pipeline;
112
115
   int ServerFd;
113
116
   URI ServerName;
114
117
  
115
 
   bool HeaderLine(string Line);
116
 
   bool Comp(URI Other) {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
 
118
   bool HeaderLine(std::string Line);
 
119
   bool Comp(URI Other) const {return Other.Host == ServerName.Host && Other.Port == ServerName.Port;};
117
120
   void Reset() {Major = 0; Minor = 0; Result = 0; Size = 0; StartPos = 0;
118
121
                 Encoding = Closes; time(&Date); ServerFd = -1; 
119
122
                 Pipeline = true;};
167
170
   /** \brief Try to AutoDetect the proxy */
168
171
   bool AutoDetectProxy();
169
172
 
170
 
   virtual bool Configuration(string Message);
 
173
   virtual bool Configuration(std::string Message);
171
174
   
172
175
   // In the event of a fatal signal this file will be closed and timestamped.
173
 
   static string FailFile;
 
176
   static std::string FailFile;
174
177
   static int FailFd;
175
178
   static time_t FailTime;
176
179
   static void SigTerm(int);
178
181
   protected:
179
182
   virtual bool Fetch(FetchItem *);
180
183
   
181
 
   string NextURI;
182
 
   string AutoDetectProxyCmd;
 
184
   std::string NextURI;
 
185
   std::string AutoDetectProxyCmd;
183
186
 
184
187
   public:
185
188
   friend struct ServerState;