apt: apt-pkg/acquire-method.h Source File

apt 3.1.16 commandline package manager

acquire-method.h
Go to the documentation of this file.
1// -*- mode: cpp; mode: fold -*-
2// Description /*{{{*/
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 /*}}}*/
12
18
19#ifndef PKGLIB_ACQUIRE_METHOD_H
20#define PKGLIB_ACQUIRE_METHOD_H
21
22#include <apt-pkg/hashes.h>
23#include <apt-pkg/macros.h>
24
25#include <cstdarg>
26#include <ctime>
27
28#include <string>
29#include <unordered_map>
30#include <vector>
31
32
33 class APT_PUBLIC pkgAcqMethod
34{
35 protected:
36
37 struct FetchItem
38 {
39 FetchItem *Next;
40
41 std::string Uri;
42 std::string DestFile;
43 int DestFileFd;
44 time_t LastModified;
45 bool IndexFile;
46 bool FailIgnore;
47 HashStringList ExpectedHashes;
48 // a maximum size we will download, this can be the exact filesize
49 // for when we know it or a arbitrary limit when we don't know the
50 // filesize (like a InRelease file)
51 unsigned long long MaximumSize;
52
53 FetchItem();
54 virtual ~FetchItem();
55 std::string Proxy(); // For internal use only.
56 void Proxy(std::string const &Proxy) APT_HIDDEN;
57
58 private:
59 struct Private;
60 Private *const d;
61 };
62
63 struct FetchResult
64 {
65 HashStringList Hashes;
66 std::vector<std::string> GPGVOutput;
67 time_t LastModified;
68 bool IMSHit;
69 std::string Filename;
70 unsigned long long Size;
71 unsigned long long ResumePoint;
72
73 void TakeHashes(class Hashes &Hash);
74 FetchResult();
75 virtual ~FetchResult();
76 private:
77 void * const d;
78 };
79
80 // State
81 std::vector<std::string> Messages;
82 FetchItem *Queue;
83 FetchItem *QueueBack;
84 std::string FailReason;
85 std::string UsedMirror;
86 std::string IP;
87
88 // Handlers for messages
89 virtual bool Configuration(std::string Message);
90 virtual bool Fetch(FetchItem * /*Item*/) {return true;};
91 virtual bool URIAcquire(std::string const &/*Message*/, FetchItem *Itm) { return Fetch(Itm); };
92
93 // Outgoing messages
94 void Fail(bool Transient = false);
95 void FailWithContext(std::string Why, bool Transient, std::unordered_map<std::string, std::string> &fields);
96 inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
97 virtual void Fail(std::string Why, bool Transient = false);
98 virtual void URIStart(FetchResult &Res);
99 virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
100 void SendMessage(std::string const &header, std::unordered_map<std::string, std::string> &&fields);
101
102 bool MediaFail(std::string Required,std::string Drive);
103 virtual void Exit() {};
104
105 public:
106 enum CnfFlags
107 {
108 SingleInstance = (1 << 0),
109 Pipeline = (1 << 1),
110 SendConfig = (1 << 2),
111 LocalOnly = (1 << 3),
112 NeedsCleanup = (1 << 4),
113 Removable = (1 << 5),
114 AuxRequests = (1 << 6),
115 SendURIEncoded = (1 << 7),
116 };
117
118 void Log(const char *Format,...);
119 void Status(const char *Format,...);
120
121 void Redirect(const std::string &NewURI);
122
123 int Run(bool Single = false);
124 inline void SetFailReason(std::string Msg) {FailReason = Msg;};
125 inline void SetIP(std::string aIP) {IP = aIP;};
126
127 pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
128 virtual ~pkgAcqMethod();
129 void DropPrivsOrDie();
130 private:
131 APT_HIDDEN void Dequeue();
132};
133
135
136#endif
HashStringList
Definition hashes.h:79
pkgAcqMethod::FetchItem::Private
Definition acquire-method.cc:568
pkgAcqMethod::FetchItem
Definition acquire-method.h:38