]>
Commit | Line | Data |
---|---|---|
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 | Three item classes are provided to provide functionality for | |
13 | downloading of Index, Translation and Packages files. | |
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, | |
52 | StatAuthError, StatTransientNetworkError} Status; | |
53 | string ErrorText; | |
54 | unsigned long FileSize; | |
55 | unsigned long PartialSize; | |
56 | const char *Mode; | |
57 | unsigned long ID; | |
58 | bool Complete; | |
59 | bool Local; | |
60 | string UsedMirror; | |
61 | ||
62 | // Number of queues we are inserted into | |
63 | unsigned int QueueCounter; | |
64 | ||
65 | // File to write the fetch into | |
66 | string DestFile; | |
67 | ||
68 | // Action members invoked by the worker | |
69 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
70 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
71 | pkgAcquire::MethodConfig *Cnf); | |
72 | virtual void Start(string Message,unsigned long Size); | |
73 | virtual string Custom600Headers() {return string();}; | |
74 | virtual string DescURI() = 0; | |
75 | virtual string ShortDesc() {return DescURI();} | |
76 | virtual void Finished() {}; | |
77 | ||
78 | // Inquire functions | |
79 | virtual string MD5Sum() {return string();}; | |
80 | pkgAcquire *GetOwner() {return Owner;}; | |
81 | virtual bool IsTrusted() {return false;}; | |
82 | ||
83 | // report mirror problems | |
84 | void ReportMirrorFailure(string FailCode); | |
85 | ||
86 | Item(pkgAcquire *Owner); | |
87 | virtual ~Item(); | |
88 | }; | |
89 | ||
90 | // Item class for index files | |
91 | class pkgAcqIndex : public pkgAcquire::Item | |
92 | { | |
93 | protected: | |
94 | ||
95 | bool Decompression; | |
96 | bool Erase; | |
97 | pkgAcquire::ItemDesc Desc; | |
98 | string RealURI; | |
99 | string ExpectedMD5; | |
100 | string CompressionExtension; | |
101 | ||
102 | public: | |
103 | ||
104 | // Specialized action members | |
105 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
106 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
107 | pkgAcquire::MethodConfig *Cnf); | |
108 | virtual string Custom600Headers(); | |
109 | virtual string DescURI() {return RealURI + CompressionExtension;}; | |
110 | ||
111 | pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc, | |
112 | string ShortDesct, string ExpectedMD5, string compressExt=""); | |
113 | }; | |
114 | ||
115 | // Item class for translated package index files | |
116 | class pkgAcqIndexTrans : public pkgAcqIndex | |
117 | { | |
118 | public: | |
119 | ||
120 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
121 | pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc, | |
122 | string ShortDesct); | |
123 | }; | |
124 | ||
125 | struct IndexTarget | |
126 | { | |
127 | string URI; | |
128 | string Description; | |
129 | string ShortDesc; | |
130 | string MetaKey; | |
131 | }; | |
132 | ||
133 | // Item class for index signatures | |
134 | class pkgAcqMetaSig : public pkgAcquire::Item | |
135 | { | |
136 | protected: | |
137 | ||
138 | pkgAcquire::ItemDesc Desc; | |
139 | string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc; | |
140 | indexRecords* MetaIndexParser; | |
141 | const vector<struct IndexTarget*>* IndexTargets; | |
142 | ||
143 | public: | |
144 | ||
145 | // Specialized action members | |
146 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
147 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
148 | pkgAcquire::MethodConfig *Cnf); | |
149 | virtual string Custom600Headers(); | |
150 | virtual string DescURI() {return RealURI; }; | |
151 | ||
152 | pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc, | |
153 | string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc, | |
154 | const vector<struct IndexTarget*>* IndexTargets, | |
155 | indexRecords* MetaIndexParser); | |
156 | }; | |
157 | ||
158 | // Item class for index signatures | |
159 | class pkgAcqMetaIndex : public pkgAcquire::Item | |
160 | { | |
161 | protected: | |
162 | ||
163 | pkgAcquire::ItemDesc Desc; | |
164 | string RealURI; // FIXME: is this redundant w/ Desc.URI? | |
165 | string SigFile; | |
166 | const vector<struct IndexTarget*>* IndexTargets; | |
167 | indexRecords* MetaIndexParser; | |
168 | bool AuthPass; | |
169 | // required to deal gracefully with problems caused by incorrect ims hits | |
170 | bool IMSHit; | |
171 | ||
172 | bool VerifyVendor(string Message); | |
173 | void RetrievalDone(string Message); | |
174 | void AuthDone(string Message); | |
175 | void QueueIndexes(bool verify); | |
176 | ||
177 | public: | |
178 | ||
179 | // Specialized action members | |
180 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
181 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
182 | pkgAcquire::MethodConfig *Cnf); | |
183 | virtual string Custom600Headers(); | |
184 | virtual string DescURI() {return RealURI; }; | |
185 | ||
186 | pkgAcqMetaIndex(pkgAcquire *Owner, | |
187 | string URI,string URIDesc, string ShortDesc, | |
188 | string SigFile, | |
189 | const vector<struct IndexTarget*>* IndexTargets, | |
190 | indexRecords* MetaIndexParser); | |
191 | }; | |
192 | ||
193 | // Item class for archive files | |
194 | class pkgAcqArchive : public pkgAcquire::Item | |
195 | { | |
196 | protected: | |
197 | ||
198 | // State information for the retry mechanism | |
199 | pkgCache::VerIterator Version; | |
200 | pkgAcquire::ItemDesc Desc; | |
201 | pkgSourceList *Sources; | |
202 | pkgRecords *Recs; | |
203 | string MD5; | |
204 | string &StoreFilename; | |
205 | pkgCache::VerFileIterator Vf; | |
206 | unsigned int Retries; | |
207 | bool Trusted; | |
208 | ||
209 | // Queue the next available file for download. | |
210 | bool QueueNext(); | |
211 | ||
212 | public: | |
213 | ||
214 | // Specialized action members | |
215 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
216 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
217 | pkgAcquire::MethodConfig *Cnf); | |
218 | virtual string MD5Sum() {return MD5;}; | |
219 | virtual string DescURI() {return Desc.URI;}; | |
220 | virtual string ShortDesc() {return Desc.ShortDesc;}; | |
221 | virtual void Finished(); | |
222 | virtual bool IsTrusted(); | |
223 | ||
224 | pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources, | |
225 | pkgRecords *Recs,pkgCache::VerIterator const &Version, | |
226 | string &StoreFilename); | |
227 | }; | |
228 | ||
229 | // Fetch a generic file to the current directory | |
230 | class pkgAcqFile : public pkgAcquire::Item | |
231 | { | |
232 | pkgAcquire::ItemDesc Desc; | |
233 | string Md5Hash; | |
234 | unsigned int Retries; | |
235 | ||
236 | public: | |
237 | ||
238 | // Specialized action members | |
239 | virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf); | |
240 | virtual void Done(string Message,unsigned long Size,string Md5Hash, | |
241 | pkgAcquire::MethodConfig *Cnf); | |
242 | virtual string MD5Sum() {return Md5Hash;}; | |
243 | virtual string DescURI() {return Desc.URI;}; | |
244 | ||
245 | // If DestFilename is empty, download to DestDir/<basename> if | |
246 | // DestDir is non-empty, $CWD/<basename> otherwise. If | |
247 | // DestFilename is NOT empty, DestDir is ignored and DestFilename | |
248 | // is the absolute name to which the file should be downloaded. | |
249 | pkgAcqFile(pkgAcquire *Owner, string URI, string MD5, unsigned long Size, | |
250 | string Desc, string ShortDesc, | |
251 | const string &DestDir="", const string &DestFilename=""); | |
252 | }; | |
253 | ||
254 | #endif |