]> git.saurik.com Git - apt.git/blob - apt-pkg/acquire-item.h
459d7d26d6bdaae621b594fa5308e65aa4b7ed72
[apt.git] / apt-pkg / acquire-item.h
1 // -*- mode: cpp; mode: fold -*-
2 // Description /*{{{*/
3 // $Id: acquire-item.h,v 1.23 2000/01/17 07:11:49 jgg 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/sourcelist.h>
25 #include <apt-pkg/pkgrecords.h>
26
27 #ifdef __GNUG__
28 #pragma interface "apt-pkg/acquire-item.h"
29 #endif
30
31 // Item to acquire
32 class pkgAcquire::Item
33 {
34 protected:
35
36 // Some private helper methods for registering URIs
37 pkgAcquire *Owner;
38 inline void QueueURI(ItemDesc &Item)
39 {Owner->Enqueue(Item);};
40 inline void Dequeue() {Owner->Dequeue(this);};
41
42 // Safe rename function with timestamp preservation
43 void Rename(string From,string To);
44
45 public:
46
47 // State of the item
48 enum {StatIdle, StatFetching, StatDone, StatError} Status;
49 string ErrorText;
50 unsigned long FileSize;
51 unsigned long PartialSize;
52 char *Mode;
53 unsigned long ID;
54 bool Complete;
55 bool Local;
56
57 // Number of queues we are inserted into
58 unsigned int QueueCounter;
59
60 // File to write the fetch into
61 string DestFile;
62
63 // Action members invoked by the worker
64 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
65 virtual void Done(string Message,unsigned long Size,string Md5Hash,
66 pkgAcquire::MethodConfig *Cnf);
67 virtual void Start(string Message,unsigned long Size);
68 virtual string Custom600Headers() {return string();};
69 virtual string DescURI() = 0;
70 virtual void Finished() {};
71
72 // Inquire functions
73 virtual string MD5Sum() {return string();};
74
75 Item(pkgAcquire *Owner);
76 virtual ~Item();
77 };
78
79 // Item class for index files
80 class pkgAcqIndex : public pkgAcquire::Item
81 {
82 protected:
83
84 const pkgSourceList::Item *Location;
85 bool Decompression;
86 bool Erase;
87 pkgAcquire::ItemDesc Desc;
88
89 public:
90
91 // Specialized action members
92 virtual void Done(string Message,unsigned long Size,string Md5Hash,
93 pkgAcquire::MethodConfig *Cnf);
94 virtual string Custom600Headers();
95 virtual string DescURI() {return Location->PackagesURI();};
96
97 pkgAcqIndex(pkgAcquire *Owner,const pkgSourceList::Item *Location);
98 };
99
100 // Item class for index files
101 class pkgAcqIndexRel : public pkgAcquire::Item
102 {
103 protected:
104
105 const pkgSourceList::Item *Location;
106 pkgAcquire::ItemDesc Desc;
107
108 public:
109
110 // Specialized action members
111 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
112 virtual void Done(string Message,unsigned long Size,string Md5Hash,
113 pkgAcquire::MethodConfig *Cnf);
114 virtual string Custom600Headers();
115 virtual string DescURI() {return Location->ReleaseURI();};
116
117 pkgAcqIndexRel(pkgAcquire *Owner,const pkgSourceList::Item *Location);
118 };
119
120 // Item class for archive files
121 class pkgAcqArchive : public pkgAcquire::Item
122 {
123 protected:
124
125 // State information for the retry mechanism
126 pkgCache::VerIterator Version;
127 pkgAcquire::ItemDesc Desc;
128 pkgSourceList *Sources;
129 pkgRecords *Recs;
130 string MD5;
131 string &StoreFilename;
132 pkgCache::VerFileIterator Vf;
133 unsigned int Retries;
134
135 // Queue the next available file for download.
136 bool QueueNext();
137
138 public:
139
140 // Specialized action members
141 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
142 virtual void Done(string Message,unsigned long Size,string Md5Hash,
143 pkgAcquire::MethodConfig *Cnf);
144 virtual string MD5Sum() {return MD5;};
145 virtual string DescURI() {return Desc.URI;};
146 virtual void Finished();
147
148 pkgAcqArchive(pkgAcquire *Owner,pkgSourceList *Sources,
149 pkgRecords *Recs,pkgCache::VerIterator const &Version,
150 string &StoreFilename);
151 };
152
153 // Fetch a generic file to the current directory
154 class pkgAcqFile : public pkgAcquire::Item
155 {
156 pkgAcquire::ItemDesc Desc;
157 string Md5Hash;
158 unsigned int Retries;
159
160 public:
161
162 // Specialized action members
163 virtual void Failed(string Message,pkgAcquire::MethodConfig *Cnf);
164 virtual void Done(string Message,unsigned long Size,string Md5Hash,
165 pkgAcquire::MethodConfig *Cnf);
166 virtual string MD5Sum() {return Md5Hash;};
167 virtual string DescURI() {return Desc.URI;};
168
169 pkgAcqFile(pkgAcquire *Owner,string URI,string MD5,unsigned long Size,
170 string Desc,string ShortDesc);
171 };
172
173 #endif