]> git.saurik.com Git - apt.git/blame - apt-pkg/acquire-method.h
provide public interface to hold/unhold packages
[apt.git] / apt-pkg / acquire-method.h
CommitLineData
93bf083d
AL
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
93bf083d
AL
3/* ######################################################################
4
5 Acquire Method - Method helper class + functions
6
7 These functions are designed to be used within the method task to
8 ease communication with APT.
9
10 ##################################################################### */
11 /*}}}*/
3174e150
MV
12
13/** \addtogroup acquire
14 * @{
15 *
16 * \file acquire-method.h
17 */
18
93bf083d
AL
19#ifndef PKGLIB_ACQUIRE_METHOD_H
20#define PKGLIB_ACQUIRE_METHOD_H
21
b3501edb 22#include <apt-pkg/hashes.h>
ce62f1de
DK
23#include <apt-pkg/macros.h>
24
f1bdfe81 25#include <stdarg.h>
453b82a3 26#include <time.h>
93bf083d 27
472ff00e
DK
28#include <string>
29#include <vector>
30
b9dadc24
DK
31#ifndef APT_8_CLEANER_HEADERS
32#include <apt-pkg/configuration.h>
33#include <apt-pkg/strutl.h>
34#endif
35
93bf083d
AL
36class pkgAcqMethod
37{
38 protected:
93bf083d 39
be4401bf
AL
40 struct FetchItem
41 {
42 FetchItem *Next;
43
8f3ba4e8
DK
44 std::string Uri;
45 std::string DestFile;
da6f750f 46 int DestFileFd;
be4401bf 47 time_t LastModified;
a72ace20 48 bool IndexFile;
963b16dc 49 bool FailIgnore;
d003a557 50 HashStringList ExpectedHashes;
c48eea97
MV
51 // a maximum size we will download, this can be the exact filesize
52 // for when we know it or a arbitrary limit when we don't know the
53 // filesize (like a InRelease file)
54 unsigned long long MaximumSize;
c8a4ce6c
DK
55
56 FetchItem();
57 virtual ~FetchItem();
58 private:
6c55f07a 59 void * const d;
be4401bf
AL
60 };
61
93bf083d
AL
62 struct FetchResult
63 {
b3501edb 64 HashStringList Hashes;
8f3ba4e8 65 std::vector<std::string> GPGVOutput;
93bf083d
AL
66 time_t LastModified;
67 bool IMSHit;
8f3ba4e8 68 std::string Filename;
73da43e9
DK
69 unsigned long long Size;
70 unsigned long long ResumePoint;
a7c835af 71
b3501edb 72 void TakeHashes(class Hashes &Hash);
93bf083d 73 FetchResult();
c8a4ce6c
DK
74 virtual ~FetchResult();
75 private:
6c55f07a 76 void * const d;
93bf083d 77 };
be4401bf
AL
78
79 // State
8f3ba4e8 80 std::vector<std::string> Messages;
be4401bf 81 FetchItem *Queue;
5cb5d8dc 82 FetchItem *QueueBack;
8f3ba4e8
DK
83 std::string FailReason;
84 std::string UsedMirror;
85 std::string IP;
36795154 86
93bf083d 87 // Handlers for messages
8f3ba4e8 88 virtual bool Configuration(std::string Message);
727f18af 89 virtual bool Fetch(FetchItem * /*Item*/) {return true;};
36795154
DK
90 virtual bool URIAcquire(std::string const &/*Message*/, FetchItem *Itm) { return Fetch(Itm); };
91
93bf083d 92 // Outgoing messages
a72ace20 93 void Fail(bool Transient = false);
8f3ba4e8
DK
94 inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
95 virtual void Fail(std::string Why, bool Transient = false);
14e097c1
MV
96 virtual void URIStart(FetchResult &Res);
97 virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
98
8f3ba4e8 99 bool MediaFail(std::string Required,std::string Drive);
459681d3 100 virtual void Exit() {};
8e5fc8f5 101
f1bdfe81
DK
102 void PrintStatus(char const * const header, const char* Format, va_list &args) const;
103
93bf083d 104 public:
a72ace20
AL
105 enum CnfFlags {SingleInstance = (1<<0),
106 Pipeline = (1<<1), SendConfig = (1<<2),
459681d3
AL
107 LocalOnly = (1<<3), NeedsCleanup = (1<<4),
108 Removable = (1<<5)};
93bf083d 109
be4401bf
AL
110 void Log(const char *Format,...);
111 void Status(const char *Format,...);
112
8f3ba4e8 113 void Redirect(const std::string &NewURI);
ebb461fd 114
be4401bf 115 int Run(bool Single = false);
8f3ba4e8
DK
116 inline void SetFailReason(std::string Msg) {FailReason = Msg;};
117 inline void SetIP(std::string aIP) {IP = aIP;};
93bf083d
AL
118
119 pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
862bafea 120 virtual ~pkgAcqMethod();
7b18d559 121 void DropPrivsOrDie();
e1284a59 122 private:
ce62f1de 123 APT_HIDDEN void Dequeue();
93bf083d
AL
124};
125
3174e150
MV
126/** @} */
127
93bf083d 128#endif