]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
* added a callback to pkgMarkUsed() so that frontend can extend the root-set of the...
[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
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 struct IndexTarget
110 {
111 string URI;
112 string Description;
113 string ShortDesc;
114 string MetaKey;
115 };
116
117 // Item class for index signatures
118 class pkgAcqMetaSig : public pkgAcquire::Item
119 {
120 protected:
121
122 pkgAcquire::ItemDesc Desc;
123 string RealURI,MetaIndexURI,MetaIndexURIDesc,MetaIndexShortDesc;
124 indexRecords* MetaIndexParser;
125 const vector<struct IndexTarget*>* IndexTargets;
126
127 public:
128
129 // Specialized action members
130 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
131 virtual void Done(string Message,unsigned long Size,string Md5Hash,
132 pkgAcquire::MethodConfig *Cnf);
133 virtual string Custom600Headers();
134 virtual string DescURI() {return RealURI; };
135
136 pkgAcqMetaSig(pkgAcquire *Owner,string URI,string URIDesc, string ShortDesc,
137 string MetaIndexURI, string MetaIndexURIDesc, string MetaIndexShortDesc,
138 const vector<struct IndexTarget*>* IndexTargets,
139 indexRecords* MetaIndexParser);
140 };
141
142 // Item class for index signatures
143 class pkgAcqMetaIndex : public pkgAcquire::Item
144 {
145 protected:
146
147 pkgAcquire::ItemDesc Desc;
148 string RealURI; // FIXME: is this redundant w/ Desc.URI?
149 string SigFile;
150 const vector<struct IndexTarget*>* IndexTargets;
151 indexRecords* MetaIndexParser;
152 bool AuthPass;
153
154 bool VerifyVendor();
155 void RetrievalDone(string Message);
156 void AuthDone(string Message);
157 void QueueIndexes(bool verify);
158
159 public:
160
161 // Specialized action members
162 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
163 virtual void Done(string Message,unsigned long Size,string Md5Hash,
164 pkgAcquire::MethodConfig *Cnf);
165 virtual string Custom600Headers();
166 virtual string DescURI() {return RealURI; };
167
168 pkgAcqMetaIndex(pkgAcquire *Owner,
169 string URI,string URIDesc, string ShortDesc,
170 string SigFile,
171 const vector<struct IndexTarget*>* IndexTargets,
172 indexRecords* MetaIndexParser);
173 };
174
175 // Item class for archive files
176 class pkgAcqArchive : public pkgAcquire::Item
177 {
178 protected:
179
180 // State information for the retry mechanism
181 pkgCache::VerIterator Version;
182 pkgAcquire::ItemDesc Desc;
183 pkgSourceList *Sources;
184 pkgRecords *Recs;
185 string MD5;
186 string &StoreFilename;
187 pkgCache::VerFileIterator Vf;
188 unsigned int Retries;
189 bool Trusted;
190
191 // Queue the next available file for download.
192 bool QueueNext();
193
194 public:
195
196 // Specialized action members
197 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
198 virtual void Done(string Message,unsigned long Size,string Md5Hash,
199 pkgAcquire::MethodConfig *Cnf);
200 virtual string MD5Sum() {return MD5;};
201 virtual string DescURI() {return Desc.URI;};
202 virtual string ShortDesc() {return Desc.ShortDesc;};
203 virtual void Finished();
204 virtual bool IsTrusted();
205
206 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
207 pkgRecords *Recs,pkgCache::VerIterator const &Version,
208 string &StoreFilename);
209 };
210
211 // Fetch a generic file to the current directory
212 class pkgAcqFile : public pkgAcquire::Item
213 {
214 pkgAcquire::ItemDesc Desc;
215 string Md5Hash;
216 unsigned int Retries;
217
218 public:
219
220 // Specialized action members
221 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
222 virtual void Done(string Message,unsigned long Size,string Md5Hash,
223 pkgAcquire::MethodConfig *Cnf);
224 virtual string MD5Sum() {return Md5Hash;};
225 virtual string DescURI() {return Desc.URI;};
226
227 pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size,
228 string Desc,string ShortDesc);
229 };
230
231 #endif