libzypp: zypp/ng/reporthelper.cc Source File

libzypp 17.38.6

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
18 BasicReportHelper::BasicReportHelper(ContextRef &&ctx)
19 : _ctx( std::move(ctx) )
20 { }
21
22
23 bool DigestReportHelper::askUserToAcceptNoDigest(const zypp::Pathname &file)
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
85 zypp::KeyRingReport::KeyTrust KeyRingReportHelper::askUserToAcceptKey(const zypp::PublicKey &key, const zypp::KeyContext &keycontext)
86 {
87#ifdef ZYPP_ENABLE_ASYNC
88 auto req = TrustKeyRequest::create(
89 _("Do you want to reject the key, trust temporarily, or trust always?"),
90 TrustKeyRequest::KEY_DONT_TRUST,
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
101 bool KeyRingReportHelper::askUserToAcceptPackageKey(const zypp::PublicKey &key_r, const zypp::KeyContext &keycontext_r)
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}
PL_
#define PL_(MSG1, MSG2, N)
Definition Gettext.h:42
_
#define _(MSG)
Definition Gettext.h:39
ERR
#define ERR
Definition Logger.h:105
zypp::PublicKeyData
Class representing one GPG Public Keys data.
Definition PublicKey.h:201
zypp::PublicKeyData::name
std::string name() const
Key name.
Definition PublicKey.cc:415
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition PublicKey.h:375
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::repo::RepoInfoBase::asUserString
std::string asUserString() const
User string: label (alias or name).
Definition RepoInfoBase.h:87
zyppng::BasicReportHelper::BasicReportHelper
BasicReportHelper(const BasicReportHelper &)=default
zyppng::BasicReportHelper::_ctx
ContextRef _ctx
Definition reporthelper.h:75
zyppng::DigestReportHelper::askUserToAcceptNoDigest
bool askUserToAcceptNoDigest(const zypp::Pathname &file)
Definition reporthelper.cc:23
zyppng::DigestReportHelper::_report
detail::ReportHolder< zypp::DigestReport, Context::isAsync > _report
Definition reporthelper.h:95
zyppng::DigestReportHelper::askUserToAccepUnknownDigest
bool askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
Definition reporthelper.cc:35
zyppng::DigestReportHelper::askUserToAcceptWrongDigest
bool askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
Definition reporthelper.cc:48
zyppng::JobReportHelper::debug
bool debug(std::string msg_r, UserData userData_r=UserData())
send debug message text
Definition reporthelper.cc:183
zyppng::JobReportHelper::important
bool important(std::string msg_r, UserData userData_r=UserData())
send important message text
Definition reporthelper.cc:227
zyppng::JobReportHelper::data
bool data(std::string msg_r, UserData userData_r=UserData())
send data message
Definition reporthelper.cc:238
zyppng::JobReportHelper::info
bool info(std::string msg_r, UserData userData_r=UserData())
send message text
Definition reporthelper.cc:194
zyppng::JobReportHelper::error
bool error(std::string msg_r, UserData userData_r=UserData())
send error text
Definition reporthelper.cc:216
zyppng::JobReportHelper::warning
bool warning(std::string msg_r, UserData userData_r=UserData())
send warning text
Definition reporthelper.cc:205
zyppng::KeyRingReportHelper::askUserToAcceptUnsignedFile
bool askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:61
zyppng::KeyRingReportHelper::_report
detail::ReportHolder< zypp::KeyRingReport, Context::isAsync > _report
Definition reporthelper.h:127
zyppng::KeyRingReportHelper::askUserToAcceptPackageKey
bool askUserToAcceptPackageKey(const zypp::PublicKey &key_r, const zypp::KeyContext &keycontext_r={})
Definition reporthelper.cc:101
zyppng::KeyRingReportHelper::askUserToAcceptUnknownKey
bool askUserToAcceptUnknownKey(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:159
zyppng::KeyRingReportHelper::askUserToAcceptVerificationFailed
bool askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:137
zyppng::KeyRingReportHelper::reportAutoImportKey
void reportAutoImportKey(const std::list< zypp::PublicKeyData > &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
Definition reporthelper.cc:124
zyppng::KeyRingReportHelper::infoVerify
void infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:112
zyppng::KeyRingReportHelper::askUserToAcceptKey
zypp::KeyRingReport::KeyTrust askUserToAcceptKey(const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:85
zyppng::ShowMessageRequest::MType::Important
@ Important
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Warning
@ Warning
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Info
@ Info
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Error
@ Error
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Debug
@ Debug
Definition userrequest.h:77
zyppng::ShowMessageRequest::MType::Data
@ Data
Definition userrequest.h:77
zyppng::TrustKeyRequest::KEY_DONT_TRUST
@ KEY_DONT_TRUST
User has chosen not to trust the key.
Definition userrequest.h:83
std
Definition ansi.h:855
str
String related utilities and Regular expression matching.
zyppng::AcceptFailedVerificationRequest::makeData
UserData makeData(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition userrequest.cc:86
zyppng::AcceptKeyRequest::makeData
UserData makeData(const zypp::PublicKey &key, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition userrequest.cc:52
zyppng::AcceptNoDigestRequest::makeData
UserData makeData(const zypp::Pathname &p)
Definition userrequest.cc:13
zyppng::AcceptUnknownDigestRequest::makeData
UserData makeData(const zypp::Pathname &p, const std::string &name)
Definition userrequest.cc:19
zyppng::AcceptUnknownKeyRequest::makeData
UserData makeData(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition userrequest.cc:77
zyppng::AcceptUnsignedFileRequest::makeData
UserData makeData(const std::string &file, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition userrequest.cc:69
zyppng::AcceptWrongDigestRequest::makeData
UserData makeData(const zypp::Pathname &p, const std::string &requested, const std::string &found)
Definition userrequest.cc:26
zyppng::KeyAutoImportInfoEvent::makeData
UserData makeData(const std::list< zypp::PublicKeyData > &keyDataList_r, const zypp::PublicKeyData &keySigning_r, const zypp::KeyContext &keyContext_r)
Definition userrequest.cc:110
zyppng::VerifyInfoEvent::makeData
UserData makeData(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext=zypp::KeyContext())
Definition userrequest.cc:60
zyppng
Definition MediaNetworkRequestExecutor.h:16
zyppng::UserData
zypp::callback::UserData UserData
Definition userrequest.h:18
reporthelper.h
zypp::JobReport::debug
static bool debug(const std::string &msg_r, const UserData &userData_r=UserData())
send debug message text
Definition ZYppCallbacks.h:1095
zypp::JobReport::warning
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
Definition ZYppCallbacks.h:1103
zypp::JobReport::error
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
Definition ZYppCallbacks.h:1107
zypp::JobReport::data
static bool data(const std::string &msg_r, const UserData &userData_r=UserData())
send data message
Definition ZYppCallbacks.h:1115
zypp::JobReport::important
static bool important(const std::string &msg_r, const UserData &userData_r=UserData())
send important message text
Definition ZYppCallbacks.h:1111
zypp::JobReport::info
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
Definition ZYppCallbacks.h:1099
zypp::KeyContext
Definition KeyContext.h:9
zypp::KeyContext::repoInfo
const RepoInfo repoInfo() const
Definition KeyContext.h:18
zypp::KeyContext::empty
bool empty() const
Is the context unknown?
Definition KeyContext.h:15
zypp::KeyRingReport::KeyTrust
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition KeyRing.h:54
zypp::str::Format
Convenient building of std::string with boost::format.
Definition String.h:254
Digest.h
userrequest.h