* merged with otavios branch
[ntk/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 Tree 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, 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
96 public:
97
98 // Specialized action members
99 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
100 virtual void Done(string Message,unsigned long Size,string Md5Hash,
101 pkgAcquire::MethodConfig *Cnf);
102 virtual string Custom600Headers();
103 virtual string DescURI() {return RealURI + ".gz";};
104
105 pkgAcqIndex(pkgAcquire *Owner,string URI,string URIDesc,
106 string ShortDesct, string ExpectedMD5, string compressExt="");
107 };
108
109 // Item class for index files
110 class pkgAcqIndexTrans : public pkgAcqIndex
111 {
112 public:
113
114 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
115 pkgAcqIndexTrans(pkgAcquire *Owner,string URI,string URIDesc,
116 string ShortDesct);
117 };
118
119 struct IndexTarget
120 {
121 string URI;
122 string Description;
123 string ShortDesc;
124 string MetaKey;
125 };
126
127 // Item class for index signatures
128 class pkgAcqMetaSig : public pkgAcquire::Item
129 {
130 protected:
131
132 pkgAcquire::ItemDesc Desc;
133 string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
134 indexRecords* MetaIndexParser;
135 const vector<struct IndexTarget*>* IndexTargets;
136
137 public:
138
139 // Specialized action members
140 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
141 virtual void Done(string Message,unsigned long Size,string Md5Hash,
142 pkgAcquire::MethodConfig *Cnf);
143 virtual string Custom600Headers();
144 virtual string DescURI() {return RealURI; };
145
146 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
147 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
148 const vector<struct IndexTarget*>* IndexTargets,
149 indexRecords* MetaIndexParser);
150 };
151
152 // Item class for index signatures
153 class pkgAcqMetaIndex : public pkgAcquire::Item
154 {
155 protected:
156
157 pkgAcquire::ItemDesc Desc;
158 string RealURI; // FIXME: is this redundant w/ Desc.URI?
159 string SigFile;
160 const vector<struct IndexTarget*>* IndexTargets;
161 indexRecords* MetaIndexParser;
162 bool AuthPass;
163
164 bool VerifyVendor();
165 void RetrievalDone(string Message);
166 void AuthDone(string Message);
167 void QueueIndexes(bool verify);
168
169 public:
170
171 // Specialized action members
172 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
173 virtual void Done(string Message,unsigned long Size,string Md5Hash,
174 pkgAcquire::MethodConfig *Cnf);
175 virtual string Custom600Headers();
176 virtual string DescURI() {return RealURI; };
177
178 pkgAcqMetaIndex(pkgAcquire *Owner,
179 string URI,string URIDesc, string ShortDesc,
180 string SigFile,
181 const vector<struct IndexTarget*>* IndexTargets,
182 indexRecords* MetaIndexParser);
183 };
184
185 // Item class for archive files
186 class pkgAcqArchive : public pkgAcquire::Item
187 {
188 protected:
189
190 // State information for the retry mechanism
191 pkgCache::VerIterator Version;
192 pkgAcquire::ItemDesc Desc;
193 pkgSourceList *Sources;
194 pkgRecords *Recs;
195 string MD5;
196 string &StoreFilename;
197 pkgCache::VerFileIterator Vf;
198 unsigned int Retries;
199 bool Trusted;
200
201 // Queue the next available file for download.
202 bool QueueNext();
203
204 public:
205
206 // Specialized action members
207 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
208 virtual void Done(string Message,unsigned long Size,string Md5Hash,
209 pkgAcquire::MethodConfig *Cnf);
210 virtual string MD5Sum() {return MD5;};
211 virtual string DescURI() {return Desc.URI;};
212 virtual string ShortDesc() {return Desc.ShortDesc;};
213 virtual void Finished();
214 virtual bool IsTrusted();
215
216 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
217 pkgRecords *Recs,pkgCache::VerIterator const &Version,
218 string &StoreFilename);
219 };
220
221 // Fetch a generic file to the current directory
222 class pkgAcqFile : public pkgAcquire::Item
223 {
224 pkgAcquire::ItemDesc Desc;
225 string Md5Hash;
226 unsigned int Retries;
227
228 public:
229
230 // Specialized action members
231 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
232 virtual void Done(string Message,unsigned long Size,string Md5Hash,
233 pkgAcquire::MethodConfig *Cnf);
234 virtual string MD5Sum() {return Md5Hash;};
235 virtual string DescURI() {return Desc.URI;};
236
237 pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size,
238 string Desc,string ShortDesc);
239 };
240
241 #endif