libzypp 17.37.17
reporthelper.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
10#include "reporthelper.h"
11
12#include <zypp/Digest.h>
13#include <zypp/ng/userrequest.h>
14
15namespace zyppng {
16
17 template<typename ZyppContextRef>
19 : _ctx( std::move(ctx) )
20 { }
21
22 template<typename ZyppContextRef>
24 {
25 if constexpr ( async() ) {
26 std::string label = (zypp::str::Format(_("No digest for file %s.")) % file ).str();
27 auto req = BooleanChoiceRequest::create( label, false, AcceptNoDigestRequest::makeData(file) );
28 this->_ctx->sendUserRequest( req );
29 return req->choice ();
30 } else {
31 return _report->askUserToAcceptNoDigest(file);
32 }
33 }
34
35 template<typename ZyppContextRef>
37 {
38 if constexpr ( async() ) {
39 std::string label = (zypp::str::Format(_("Unknown digest %s for file %s.")) %name % file).str();
40 auto req = BooleanChoiceRequest::create( label, false, AcceptUnknownDigestRequest::makeData(file, name) );
41 this->_ctx->sendUserRequest( req );
42 return req->choice ();
43 } else {
44 return _report->askUserToAccepUnknownDigest( file, name );
45 }
46 }
47
48 template<typename ZyppContextRef>
49 bool DigestReportHelper<ZyppContextRef>::askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
50 {
51 if constexpr ( async() ) {
52 std::string label = (zypp::str::Format(_("Digest verification failed for file '%s'")) % file).str();
53 auto req = BooleanChoiceRequest::create( label, false, AcceptWrongDigestRequest::makeData(file, requested, found) );
54 this->_ctx->sendUserRequest( req );
55 return req->choice ();
56 } else {
57 return _report->askUserToAcceptWrongDigest( file, requested, found );
58 }
59 }
60
61 template<typename ZyppContextRef>
63 {
64 if constexpr ( async() ) {
65 std::string label;
66 if (keycontext.empty())
67 label = zypp::str::Format(
68 // TranslatorExplanation: speaking of a file
69 _("File '%s' is unsigned, continue?")) % file;
70 else
71 label = zypp::str::Format(
72 // TranslatorExplanation: speaking of a file
73 _("File '%s' from repository '%s' is unsigned, continue?"))
74 % file % keycontext.repoInfo().asUserString();
75
76
77 auto req = BooleanChoiceRequest::create ( label, false, AcceptUnsignedFileRequest::makeData ( file, keycontext ) );
78 this->_ctx->sendUserRequest ( req );
79 return req->choice ();
80 } else {
81 return _report->askUserToAcceptUnsignedFile( file, keycontext );
82 }
83 }
84
85 template<typename ZyppContextRef>
87 {
88 if constexpr ( async() ) {
89 auto req = TrustKeyRequest::create(
90 _("Do you want to reject the key, trust temporarily, or trust always?"),
92 AcceptKeyRequest::makeData ( key, keycontext )
93 );
94 this->_ctx->sendUserRequest ( req );
95 return static_cast<zypp::KeyRingReport::KeyTrust>(req->choice());
96 } else {
97 return _report->askUserToAcceptKey( key, keycontext );
98 }
99 }
100
101 template<typename ZyppContextRef>
102 bool KeyRingReportHelper<ZyppContextRef>::askUserToAcceptPackageKey(const zypp::PublicKey &key_r, const zypp::KeyContext &keycontext_r)
103 {
104 if constexpr ( async() ) {
105 ERR << "Not implemented yet" << std::endl;
106 return false;
107 } else {
108 return _report->askUserToAcceptPackageKey ( key_r, keycontext_r );
109 }
110 }
111
112 template<typename ZyppContextRef>
113 void KeyRingReportHelper<ZyppContextRef>::infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext)
114 {
115 if constexpr ( async() ) {
116 std::string label = zypp::str::Format( _("Key Name: %1%")) % keyData_r.name();
117 auto req = ShowMessageRequest::create( label, ShowMessageRequest::MType::Info, VerifyInfoEvent::makeData ( file_r, keyData_r, keycontext) );
118 this->_ctx->sendUserRequest ( req );
119 } else {
120 return _report->infoVerify( file_r, keyData_r, keycontext );
121 }
122 }
123
124 template<typename ZyppContextRef>
125 void KeyRingReportHelper<ZyppContextRef>::reportAutoImportKey(const std::list<zypp::PublicKeyData> &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
126 {
127 if constexpr ( async() ) {
128 const std::string &lbl = zypp::str::Format( PL_( "Received %1% new package signing key from repository \"%2%\":",
129 "Received %1% new package signing keys from repository \"%2%\":",
130 keyDataList_r.size() )) % keyDataList_r.size() % keyContext_r.repoInfo().asUserString();
131 this->_ctx->sendUserRequest( ShowMessageRequest::create( lbl, ShowMessageRequest::MType::Info, KeyAutoImportInfoEvent::makeData( keyDataList_r, keySigning_r, keyContext_r) ) );
132 } else {
133 return _report->reportAutoImportKey( keyDataList_r, keySigning_r, keyContext_r );
134 }
135 }
136
137 template<typename ZyppContextRef>
138 bool KeyRingReportHelper<ZyppContextRef>::askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext)
139 {
140 if constexpr ( async() ) {
141 std::string label;
142 if ( keycontext.empty() )
143 // translator: %1% is a file name
144 label = zypp::str::Format(_("Signature verification failed for file '%1%'.") ) % file;
145 else
146 // translator: %1% is a file name, %2% a repositories na me
147 label = zypp::str::Format(_("Signature verification failed for file '%1%' from repository '%2%'.") ) % file % keycontext.repoInfo().asUserString();
148
149 // @TODO use a centralized Continue string!
150 label += std::string(" ") + _("Continue?");
151 auto req = BooleanChoiceRequest::create ( label, false, AcceptFailedVerificationRequest::makeData ( file, key, keycontext ) );
152 this->_ctx->sendUserRequest ( req );
153 return req->choice ();
154 } else {
155 return _report->askUserToAcceptVerificationFailed( file, key, keycontext );
156 }
157 }
158
159 template<typename ZyppContextRef>
160 bool KeyRingReportHelper<ZyppContextRef>::askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const zypp::KeyContext &keycontext )
161 {
162 if constexpr ( async() ) {
163 std::string label;
164
165 if (keycontext.empty())
166 label = zypp::str::Format(
167 // translators: the last %s is gpg key ID
168 _("File '%s' is signed with an unknown key '%s'. Continue?")) % file % id;
169 else
170 label = zypp::str::Format(
171 // translators: the last %s is gpg key ID
172 _("File '%s' from repository '%s' is signed with an unknown key '%s'. Continue?"))
173 % file % keycontext.repoInfo().asUserString() % id;
174
175 auto req = BooleanChoiceRequest::create ( label, false, AcceptUnknownKeyRequest::makeData ( file, id, keycontext ) );
176 this->_ctx->sendUserRequest ( req );
177 return req->choice ();
178 } else {
179 return _report->askUserToAcceptUnknownKey( file, id, keycontext );
180 }
181 }
182
183 template<typename ZyppContextRef>
184 bool JobReportHelper<ZyppContextRef>::debug(std::string msg_r, UserData userData_r)
185 {
186 if constexpr ( async() ) {
187 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Debug, std::move(userData_r) ) );
188 return true;
189 } else {
190 return zypp::JobReport::debug ( msg_r, userData_r );
191 }
192 }
193
194 template<typename ZyppContextRef>
195 bool JobReportHelper<ZyppContextRef>::info( std::string msg_r, UserData userData_r)
196 {
197 if constexpr ( async() ) {
198 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Info, std::move(userData_r) ) );
199 return true;
200 } else {
201 return zypp::JobReport::info ( msg_r, userData_r );
202 }
203 }
204
205 template<typename ZyppContextRef>
206 bool JobReportHelper<ZyppContextRef>::warning( std::string msg_r, UserData userData_r)
207 {
208 if constexpr ( async() ) {
209 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Warning, std::move(userData_r) ) );
210 return true;
211 } else {
212 return zypp::JobReport::warning ( msg_r, userData_r );
213 }
214 }
215
216 template<typename ZyppContextRef>
217 bool JobReportHelper<ZyppContextRef>::error( std::string msg_r, UserData userData_r)
218 {
219 if constexpr ( async() ) {
220 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Error, std::move(userData_r) ) );
221 return true;
222 } else {
223 return zypp::JobReport::error ( msg_r, userData_r );
224 }
225 }
226
227 template<typename ZyppContextRef>
228 bool JobReportHelper<ZyppContextRef>::important( std::string msg_r, UserData userData_r)
229 {
230 if constexpr ( async() ) {
231 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Important, std::move(userData_r) ) );
232 return true;
233 } else {
234 return zypp::JobReport::important ( msg_r, userData_r );
235 }
236 }
237
238 template<typename ZyppContextRef>
239 bool JobReportHelper<ZyppContextRef>::data( std::string msg_r, UserData userData_r)
240 {
241 if constexpr ( async() ) {
242 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Data, std::move(userData_r) ) );
243 return true;
244 } else {
245 return zypp::JobReport::data ( msg_r, userData_r );
246 }
247 }
248
249 // explicitely intantiate the template types we want to work with
251 template class BasicReportHelper<ContextRef>;
253 template class DigestReportHelper<ContextRef>;
255 template class KeyRingReportHelper<ContextRef>;
256 template class JobReportHelper<SyncContextRef>;
257 template class JobReportHelper<ContextRef>;
258
259
260}
std::string asUserString() const
User string: label (alias or name)
BasicReportHelper(const BasicReportHelper &)=default
static constexpr bool async()
bool askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
detail::ReportHolder< ZyppContextRef, zypp::DigestReport > _report
bool askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
bool askUserToAcceptNoDigest(const zypp::Pathname &file)
bool important(std::string msg_r, UserData userData_r=UserData())
send important message text
bool error(std::string msg_r, UserData userData_r=UserData())
send error text
bool warning(std::string msg_r, UserData userData_r=UserData())
send warning text
bool debug(std::string msg_r, UserData userData_r=UserData())
send debug message text
bool data(std::string msg_r, UserData userData_r=UserData())
send data message
bool info(std::string msg_r, UserData userData_r=UserData())
send message text
bool askUserToAcceptPackageKey(const zypp::PublicKey &key_r, const zypp::KeyContext &keycontext_r={})
void reportAutoImportKey(const std::list< zypp::PublicKeyData > &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
bool askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext={})
void infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext={})
detail::ReportHolder< ZyppContextRef, zypp::KeyRingReport > _report
bool askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
zypp::KeyRingReport::KeyTrust askUserToAcceptKey(const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
bool askUserToAcceptUnknownKey(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext={})
@ KEY_DONT_TRUST
User has chosen not to trust the key.
Definition userrequest.h:83
Definition Arch.h:364
String related utilities and Regular expression matching.
UserData makeData(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext=zypp::KeyContext())
UserData makeData(const zypp::PublicKey &key, const zypp::KeyContext &keycontext=zypp::KeyContext())
UserData makeData(const zypp::Pathname &p)
UserData makeData(const zypp::Pathname &p, const std::string &name)
UserData makeData(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext=zypp::KeyContext())
UserData makeData(const std::string &file, const zypp::KeyContext &keycontext=zypp::KeyContext())
UserData makeData(const zypp::Pathname &p, const std::string &requested, const std::string &found)
UserData makeData(const std::list< zypp::PublicKeyData > &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
UserData makeData(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext=zypp::KeyContext())
zypp::callback::UserData UserData
Definition userrequest.h:18
static bool debug(const std::string &msg_r, const UserData &userData_r=UserData())
send debug message text
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
static bool data(const std::string &msg_r, const UserData &userData_r=UserData())
send data message
static bool important(const std::string &msg_r, const UserData &userData_r=UserData())
send important message text
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
const RepoInfo repoInfo() const
Definition KeyContext.h:18
bool empty() const
Is the context unknown?
Definition KeyContext.h:15
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition KeyRing.h:54
Convenient building of std::string with boost::format.
Definition String.h:254
#define PL_(MSG1, MSG2, N)
Definition Gettext.h:42
#define _(MSG)
Definition Gettext.h:39
#define ERR
Definition Logger.h:102