]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
* merged from bubulle
[apt.git] / apt-pkg / acquire-item.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.h,v 1.26.2.3 2004/01/02 18:51:00 mdz Exp $
4 /* ######################################################################
5
6 Acquire Item - Item to acquire
7
8 When an item is instantiated it will add it self to the local list in
9 the Owner Acquire class. Derived classes will then call QueueURI to
10 register all the URI's they wish to fetch at the initial moment.
11
12 Two item classes are provided to provide functionality for downloading
13 of Index files and downloading of Packages.
14
15 A Archive class is provided for downloading .deb files. It does Md5
16 checking and source location as well as a retry algorithm.
17
18 ##################################################################### */
19 /*}}}*/
20 #ifndef PKGLIB_ACQUIRE_ITEM_H
21 #define PKGLIB_ACQUIRE_ITEM_H
22
23 #include <apt-pkg/acquire.h>
24 #include <apt-pkg/indexfile.h>
25 #include <apt-pkg/vendor.h>
26 #include <apt-pkg/sourcelist.h>
27 #include <apt-pkg/pkgrecords.h>
28 #include <apt-pkg/indexrecords.h>
29
30 #ifdef __GNUG__
31 #pragma interface "apt-pkg/acquire-item.h"
32 #endif
33
34 // Item to acquire
35 class pkgAcquire::Item
36 {
37 protected:
38
39 // Some private helper methods for registering URIs
40 pkgAcquire *Owner;
41 inline void QueueURI(ItemDesc &Item)
42 {Owner->Enqueue(Item);};
43 inline void Dequeue() {Owner->Dequeue(this);};
44
45 // Safe rename function with timestamp preservation
46 void Rename(string From,string To);
47
48 public:
49
50 // State of the item
51 enum {StatIdle, StatFetching, StatDone, StatError, StatAuthError} Status;
52 string ErrorText;
53 unsigned long FileSize;
54 unsigned long PartialSize;
55 const char *Mode;
56 unsigned long ID;
57 bool Complete;
58 bool Local;
59
60 // Number of queues we are inserted into
61 unsigned int QueueCounter;
62
63 // File to write the fetch into
64 string DestFile;
65
66 // Action members invoked by the worker
67 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
68 virtual void Done(string Message,unsigned long Size,string Md5Hash,
69 pkgAcquire::MethodConfig *Cnf);
70 virtual void Start(string Message,unsigned long Size);
71 virtual string Custom600Headers() {return string();};
72 virtual string DescURI() = 0;
73 virtual string ShortDesc() {return DescURI();}
74 virtual void Finished() {};
75
76 // Inquire functions
77 virtual string MD5Sum() {return string();};
78 pkgAcquire *GetOwner() {return Owner;};
79 virtual bool IsTrusted() {return false;};
80
81 Item(pkgAcquire *Owner);
82 virtual ~Item();
83 };
84
85 // Item class for index files
86 class pkgAcqIndex : public pkgAcquire::Item
87 {
88 protected:
89
90 bool Decompression;
91 bool Erase;
92 pkgAcquire::ItemDesc Desc;
93 string RealURI;
94 string ExpectedMD5;
95 string CompressionExtension;
96
97 public:
98
99 // Specialized action members
100 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
101 virtual void Done(string Message,unsigned long Size,string Md5Hash,
102 pkgAcquire::MethodConfig *Cnf);
103 virtual string Custom600Headers();
104 virtual string DescURI() {return RealURI + CompressionExtension;};
105
106 pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
107 string ShortDesct, string ExpectedMD5, string compressExt="");
108 };
109
110 struct IndexTarget
111 {
112 string URI;
113 string Description;
114 string ShortDesc;
115 string MetaKey;
116 };
117
118 // Item class for index signatures
119 class pkgAcqMetaSig : public pkgAcquire::Item
120 {
121 protected:
122
123 pkgAcquire::ItemDesc Desc;
124 string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
125 indexRecords* MetaIndexParser;
126 const vector<struct IndexTarget*>* IndexTargets;
127
128 public:
129
130 // Specialized action members
131 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
132 virtual void Done(string Message,unsigned long Size,string Md5Hash,
133 pkgAcquire::MethodConfig *Cnf);
134 virtual string Custom600Headers();
135 virtual string DescURI() {return RealURI; };
136
137 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
138 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
139 const vector<struct IndexTarget*>* IndexTargets,
140 indexRecords* MetaIndexParser);
141 };
142
143 // Item class for index signatures
144 class pkgAcqMetaIndex : public pkgAcquire::Item
145 {
146 protected:
147
148 pkgAcquire::ItemDesc Desc;
149 string RealURI; // FIXME: is this redundant w/ Desc.URI?
150 string SigFile;
151 const vector<struct IndexTarget*>* IndexTargets;
152 indexRecords* MetaIndexParser;
153 bool AuthPass;
154 // required to deal gracefully with problems caused by incorrect ims hits
155 bool IMSHit;
156
157 bool VerifyVendor(string Message);
158 void RetrievalDone(string Message);
159 void AuthDone(string Message);
160 void QueueIndexes(bool verify);
161
162 public:
163
164 // Specialized action members
165 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
166 virtual void Done(string Message,unsigned long Size,string Md5Hash,
167 pkgAcquire::MethodConfig *Cnf);
168 virtual string Custom600Headers();
169 virtual string DescURI() {return RealURI; };
170
171 pkgAcqMetaIndex(pkgAcquire *Owner,
172 string URI,string URIDesc, string ShortDesc,
173 string SigFile,
174 const vector<struct IndexTarget*>* IndexTargets,
175 indexRecords* MetaIndexParser);
176 };
177
178 // Item class for archive files
179 class pkgAcqArchive : public pkgAcquire::Item
180 {
181 protected:
182
183 // State information for the retry mechanism
184 pkgCache::VerIterator Version;
185 pkgAcquire::ItemDesc Desc;
186 pkgSourceList *Sources;
187 pkgRecords *Recs;
188 string MD5;
189 string &StoreFilename;
190 pkgCache::VerFileIterator Vf;
191 unsigned int Retries;
192 bool Trusted;
193
194 // Queue the next available file for download.
195 bool QueueNext();
196
197 public:
198
199 // Specialized action members
200 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
201 virtual void Done(string Message,unsigned long Size,string Md5Hash,
202 pkgAcquire::MethodConfig *Cnf);
203 virtual string MD5Sum() {return MD5;};
204 virtual string DescURI() {return Desc.URI;};
205 virtual string ShortDesc() {return Desc.ShortDesc;};
206 virtual void Finished();
207 virtual bool IsTrusted();
208
209 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
210 pkgRecords *Recs,pkgCache::VerIterator const &Version,
211 string &StoreFilename);
212 };
213
214 // Fetch a generic file to the current directory
215 class pkgAcqFile : public pkgAcquire::Item
216 {
217 pkgAcquire::ItemDesc Desc;
218 string Md5Hash;
219 unsigned int Retries;
220
221 public:
222
223 // Specialized action members
224 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
225 virtual void Done(string Message,unsigned long Size,string Md5Hash,
226 pkgAcquire::MethodConfig *Cnf);
227 virtual string MD5Sum() {return Md5Hash;};
228 virtual string DescURI() {return Desc.URI;};
229
230 // If DestFilename is empty, download to DestDir/<basename> if
231 // DestDir is non-empty, $CWD/<basename> otherwise. If
232 // DestFilename is NOT empty, DestDir is ignored and DestFilename
233 // is the absolute name to which the file should be downloaded.
234 pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size,
235 string Desc, string ShortDesc,
236 const string &DestDir="", const string &DestFilename="");
237 };
238
239 #endif