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