libzypp 17.38.3
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
19 : _ctx( std::move(ctx) )
20 { }
21
22
24 {
25#ifdef ZYPP_ENABLE_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#endif
33 }
34
35 bool DigestReportHelper::askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
36 {
37#ifdef ZYPP_ENABLE_ASYNC
38 std::string label = (zypp::str::Format(_("Unknown digest %s for file %s.")) %name % file).str();
39 auto req = BooleanChoiceRequest::create( label, false, AcceptUnknownDigestRequest::makeData(file, name) );
40 this->_ctx->sendUserRequest( req );
41 return req->choice ();
42#else
43 return _report->askUserToAccepUnknownDigest( file, name );
44#endif
45 }
46
47
48 bool DigestReportHelper::askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
49 {
50#ifdef ZYPP_ENABLE_ASYNC
51 std::string label = (zypp::str::Format(_("Digest verification failed for file '%s'")) % file).str();
52 auto req = BooleanChoiceRequest::create( label, false, AcceptWrongDigestRequest::makeData(file, requested, found) );
53 this->_ctx->sendUserRequest( req );
54 return req->choice ();
55#else
56 return _report->askUserToAcceptWrongDigest( file, requested, found );
57#endif
58 }
59
60
61 bool KeyRingReportHelper::askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext)
62 {
63#ifdef ZYPP_ENABLE_ASYNC
64 std::string label;
65 if (keycontext.empty())
66 label = zypp::str::Format(
67 // TranslatorExplanation: speaking of a file
68 _("File '%s' is unsigned, continue?")) % file;
69 else
70 label = zypp::str::Format(
71 // TranslatorExplanation: speaking of a file
72 _("File '%s' from repository '%s' is unsigned, continue?"))
73 % file % keycontext.repoInfo().asUserString();
74
75
76 auto req = BooleanChoiceRequest::create ( label, false, AcceptUnsignedFileRequest::makeData ( file, keycontext ) );
77 this->_ctx->sendUserRequest ( req );
78 return req->choice ();
79#else
80 return _report->askUserToAcceptUnsignedFile( file, keycontext );
81#endif
82 }
83
84
86 {
87#ifdef ZYPP_ENABLE_ASYNC
88 auto req = TrustKeyRequest::create(
89 _("Do you want to reject the key, trust temporarily, or trust always?"),
91 AcceptKeyRequest::makeData ( key, keycontext )
92 );
93 this->_ctx->sendUserRequest ( req );
94 return static_cast<zypp::KeyRingReport::KeyTrust>(req->choice());
95#else
96 return _report->askUserToAcceptKey( key, keycontext );
97#endif
98 }
99
100
102 {
103#ifdef ZYPP_ENABLE_ASYNC
104 ERR << "Not implemented yet" << std::endl;
105 return false;
106#else
107 return _report->askUserToAcceptPackageKey ( key_r, keycontext_r );
108#endif
109 }
110
111
112 void KeyRingReportHelper::infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext)
113 {
114#ifdef ZYPP_ENABLE_ASYNC
115 std::string label = zypp::str::Format( _("Key Name: %1%")) % keyData_r.name();
116 auto req = ShowMessageRequest::create( label, ShowMessageRequest::MType::Info, VerifyInfoEvent::makeData ( file_r, keyData_r, keycontext) );
117 this->_ctx->sendUserRequest ( req );
118#else
119 return _report->infoVerify( file_r, keyData_r, keycontext );
120#endif
121 }
122
123
124 void KeyRingReportHelper::reportAutoImportKey(const std::list<zypp::PublicKeyData> &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
125 {
126#ifdef ZYPP_ENABLE_ASYNC
127 const std::string &lbl = zypp::str::Format( PL_( "Received %1% new package signing key from repository \"%2%\":",
128 "Received %1% new package signing keys from repository \"%2%\":",
129 keyDataList_r.size() )) % keyDataList_r.size() % keyContext_r.repoInfo().asUserString();
130 this->_ctx->sendUserRequest( ShowMessageRequest::create( lbl, ShowMessageRequest::MType::Info, KeyAutoImportInfoEvent::makeData( keyDataList_r, keySigning_r, keyContext_r) ) );
131#else
132 return _report->reportAutoImportKey( keyDataList_r, keySigning_r, keyContext_r );
133#endif
134 }
135
136
137 bool KeyRingReportHelper::askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext)
138 {
139#ifdef ZYPP_ENABLE_ASYNC
140 std::string label;
141 if ( keycontext.empty() )
142 // translator: %1% is a file name
143 label = zypp::str::Format(_("Signature verification failed for file '%1%'.") ) % file;
144 else
145 // translator: %1% is a file name, %2% a repositories na me
146 label = zypp::str::Format(_("Signature verification failed for file '%1%' from repository '%2%'.") ) % file % keycontext.repoInfo().asUserString();
147
148 // @TODO use a centralized Continue string!
149 label += std::string(" ") + _("Continue?");
150 auto req = BooleanChoiceRequest::create ( label, false, AcceptFailedVerificationRequest::makeData ( file, key, keycontext ) );
151 this->_ctx->sendUserRequest ( req );
152 return req->choice ();
153#else
154 return _report->askUserToAcceptVerificationFailed( file, key, keycontext );
155#endif
156 }
157
158
159 bool KeyRingReportHelper::askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const zypp::KeyContext &keycontext )
160 {
161#ifdef ZYPP_ENABLE_ASYNC
162 std::string label;
163
164 if (keycontext.empty())
165 label = zypp::str::Format(
166 // translators: the last %s is gpg key ID
167 _("File '%s' is signed with an unknown key '%s'. Continue?")) % file % id;
168 else
169 label = zypp::str::Format(
170 // translators: the last %s is gpg key ID
171 _("File '%s' from repository '%s' is signed with an unknown key '%s'. Continue?"))
172 % file % keycontext.repoInfo().asUserString() % id;
173
174 auto req = BooleanChoiceRequest::create ( label, false, AcceptUnknownKeyRequest::makeData ( file, id, keycontext ) );
175 this->_ctx->sendUserRequest ( req );
176 return req->choice ();
177#else
178 return _report->askUserToAcceptUnknownKey( file, id, keycontext );
179#endif
180 }
181
182
183 bool JobReportHelper::debug(std::string msg_r, UserData userData_r)
184 {
185#ifdef ZYPP_ENABLE_ASYNC
186 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Debug, std::move(userData_r) ) );
187 return true;
188#else
189 return zypp::JobReport::debug ( msg_r, userData_r );
190#endif
191 }
192
193
194 bool JobReportHelper::info( std::string msg_r, UserData userData_r)
195 {
196#ifdef ZYPP_ENABLE_ASYNC
197 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Info, std::move(userData_r) ) );
198 return true;
199#else
200 return zypp::JobReport::info ( msg_r, userData_r );
201#endif
202 }
203
204
205 bool JobReportHelper::warning( std::string msg_r, UserData userData_r)
206 {
207#ifdef ZYPP_ENABLE_ASYNC
208 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Warning, std::move(userData_r) ) );
209 return true;
210#else
211 return zypp::JobReport::warning ( msg_r, userData_r );
212#endif
213 }
214
215
216 bool JobReportHelper::error( std::string msg_r, UserData userData_r)
217 {
218#ifdef ZYPP_ENABLE_ASYNC
219 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Error, std::move(userData_r) ) );
220 return true;
221#else
222 return zypp::JobReport::error ( msg_r, userData_r );
223#endif
224 }
225
226
227 bool JobReportHelper::important( std::string msg_r, UserData userData_r)
228 {
229#ifdef ZYPP_ENABLE_ASYNC
230 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Important, std::move(userData_r) ) );
231 return true;
232#else
233 return zypp::JobReport::important ( msg_r, userData_r );
234#endif
235 }
236
237
238 bool JobReportHelper::data( std::string msg_r, UserData userData_r)
239 {
240#ifdef ZYPP_ENABLE_ASYNC
241 this->_ctx->sendUserRequest( ShowMessageRequest::create( std::move(msg_r), ShowMessageRequest::MType::Data, std::move(userData_r) ) );
242 return true;
243#else
244 return zypp::JobReport::data ( msg_r, userData_r );
245#endif
246 }
247}
#define PL_(MSG1, MSG2, N)
Definition Gettext.h:42
#define _(MSG)
Definition Gettext.h:39
#define ERR
Definition Logger.h:102
Class representing one GPG Public Keys data.
Definition PublicKey.h:201
std::string name() const
Key name.
Definition PublicKey.cc:415
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:358
std::string asUserString() const
User string: label (alias or name).
BasicReportHelper(const BasicReportHelper &)=default
bool askUserToAcceptNoDigest(const zypp::Pathname &file)
detail::ReportHolder< zypp::DigestReport, Context::isAsync > _report
bool askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
bool askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
bool debug(std::string msg_r, UserData userData_r=UserData())
send debug message text
bool important(std::string msg_r, UserData userData_r=UserData())
send important 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 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 askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext={})
detail::ReportHolder< zypp::KeyRingReport, Context::isAsync > _report
bool askUserToAcceptPackageKey(const zypp::PublicKey &key_r, const zypp::KeyContext &keycontext_r={})
bool askUserToAcceptUnknownKey(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext={})
bool askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
void reportAutoImportKey(const std::list< zypp::PublicKeyData > &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
void infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext={})
zypp::KeyRingReport::KeyTrust askUserToAcceptKey(const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
@ KEY_DONT_TRUST
User has chosen not to trust the key.
Definition userrequest.h:83
Definition ansi.h:855
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