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

apt 2.7.6 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
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 <stdarg.h>
26#include <time.h>
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 inline void Fail(const char *Why, bool Transient = false) {Fail(std::string(Why),Transient);};
96 virtual void Fail(std::string Why, bool Transient = false);
97 virtual void URIStart(FetchResult &Res);
98 virtual void URIDone(FetchResult &Res,FetchResult *Alt = 0);
99 void SendMessage(std::string const &header, std::unordered_map<std::string, std::string> &&fields);
100
101 bool MediaFail(std::string Required,std::string Drive);
102 virtual void Exit() {};
103
104 APT_DEPRECATED_MSG("Use SendMessage instead") void PrintStatus(char const * const header, const char* Format, va_list &args) const;
105
106 public:
107 enum CnfFlags
108 {
109 SingleInstance = (1 << 0),
110 Pipeline = (1 << 1),
111 SendConfig = (1 << 2),
112 LocalOnly = (1 << 3),
113 NeedsCleanup = (1 << 4),
114 Removable = (1 << 5),
115 AuxRequests = (1 << 6),
116 SendURIEncoded = (1 << 7),
117 };
118
119 void Log(const char *Format,...);
120 void Status(const char *Format,...);
121
122 void Redirect(const std::string &NewURI);
123
124 int Run(bool Single = false);
125 inline void SetFailReason(std::string Msg) {FailReason = Msg;};
126 inline void SetIP(std::string aIP) {IP = aIP;};
127
128 pkgAcqMethod(const char *Ver,unsigned long Flags = 0);
129 virtual ~pkgAcqMethod();
130 void DropPrivsOrDie();
131 private:
132 APT_HIDDEN void Dequeue();
133};
134
137#endif
Configuration
Definition configuration.h:40
HashStringList
Definition hashes.h:79
Hashes
Definition hashes.h:184
pkgAcqMethod
Definition acquire-method.h:34
pkgAcqMethod::FetchItem::Private
Definition acquire-method.cc:580
pkgAcqMethod::FetchItem
Definition acquire-method.h:38
pkgAcqMethod::FetchResult
Definition acquire-method.h:64