libzypp: zypp/ng/reporthelper.cc Source File

libzypp 17.36.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 template<typename ZyppContextRef>
18 BasicReportHelper<ZyppContextRef>::BasicReportHelper(ZyppContextRef &&ctx)
19 : _ctx( std::move(ctx) )
20 { }
21
22 template<typename ZyppContextRef>
23 bool DigestReportHelper<ZyppContextRef>::askUserToAcceptNoDigest(const zypp::Pathname &file)
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>
36 bool DigestReportHelper<ZyppContextRef>::askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
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>
62 bool KeyRingReportHelper<ZyppContextRef>::askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext)
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>
86 zypp::KeyRingReport::KeyTrust KeyRingReportHelper<ZyppContextRef>::askUserToAcceptKey(const zypp::PublicKey &key, const zypp::KeyContext &keycontext)
87 {
88 if constexpr ( async() ) {
89 auto req = TrustKeyRequest::create(
90 _("Do you want to reject the key, trust temporarily, or trust always?"),
91 TrustKeyRequest::KEY_DONT_TRUST,
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
250 template class BasicReportHelper<SyncContextRef>;
251 template class BasicReportHelper<ContextRef>;
252 template class DigestReportHelper<SyncContextRef>;
253 template class DigestReportHelper<ContextRef>;
254 template class KeyRingReportHelper<SyncContextRef>;
255 template class KeyRingReportHelper<ContextRef>;
256 template class JobReportHelper<SyncContextRef>;
257 template class JobReportHelper<ContextRef>;
258
259
260}
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:47
zypp::repo::RepoInfoBase::asUserString
std::string asUserString() const
User string: label (alias or name)
Definition RepoInfoBase.h:87
zyppng::BasicReportHelper
Definition reporthelper.h:59
zyppng::BasicReportHelper::BasicReportHelper
BasicReportHelper(const BasicReportHelper &)=default
zyppng::BasicReportHelper::_ctx
ZyppContextRef _ctx
Definition reporthelper.h:76
zyppng::BasicReportHelper::async
static constexpr bool async()
Definition reporthelper.h:70
zyppng::DigestReportHelper
Definition reporthelper.h:80
zyppng::DigestReportHelper::askUserToAccepUnknownDigest
bool askUserToAccepUnknownDigest(const zypp::Pathname &file, const std::string &name)
Definition reporthelper.cc:36
zyppng::DigestReportHelper::_report
detail::ReportHolder< ZyppContextRef, zypp::DigestReport > _report
Definition reporthelper.h:97
zyppng::DigestReportHelper::askUserToAcceptWrongDigest
bool askUserToAcceptWrongDigest(const zypp::Pathname &file, const std::string &requested, const std::string &found)
Definition reporthelper.cc:49
zyppng::DigestReportHelper::askUserToAcceptNoDigest
bool askUserToAcceptNoDigest(const zypp::Pathname &file)
Definition reporthelper.cc:23
zyppng::JobReportHelper
Definition reporthelper.h:135
zyppng::JobReportHelper::important
bool important(std::string msg_r, UserData userData_r=UserData())
send important message text
Definition reporthelper.cc:228
zyppng::JobReportHelper::error
bool error(std::string msg_r, UserData userData_r=UserData())
send error text
Definition reporthelper.cc:217
zyppng::JobReportHelper::warning
bool warning(std::string msg_r, UserData userData_r=UserData())
send warning text
Definition reporthelper.cc:206
zyppng::JobReportHelper::debug
bool debug(std::string msg_r, UserData userData_r=UserData())
send debug message text
Definition reporthelper.cc:184
zyppng::JobReportHelper::data
bool data(std::string msg_r, UserData userData_r=UserData())
send data message
Definition reporthelper.cc:239
zyppng::JobReportHelper::info
bool info(std::string msg_r, UserData userData_r=UserData())
send message text
Definition reporthelper.cc:195
zyppng::KeyRingReportHelper
Definition reporthelper.h:101
zyppng::KeyRingReportHelper::askUserToAcceptPackageKey
bool askUserToAcceptPackageKey(const zypp::PublicKey &key_r, const zypp::KeyContext &keycontext_r={})
Definition reporthelper.cc:102
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:125
zyppng::KeyRingReportHelper::askUserToAcceptUnsignedFile
bool askUserToAcceptUnsignedFile(const std::string &file, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:62
zyppng::KeyRingReportHelper::infoVerify
void infoVerify(const std::string &file_r, const zypp::PublicKeyData &keyData_r, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:113
zyppng::KeyRingReportHelper::_report
detail::ReportHolder< ZyppContextRef, zypp::KeyRingReport > _report
Definition reporthelper.h:130
zyppng::KeyRingReportHelper::askUserToAcceptVerificationFailed
bool askUserToAcceptVerificationFailed(const std::string &file, const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:138
zyppng::KeyRingReportHelper::askUserToAcceptKey
zypp::KeyRingReport::KeyTrust askUserToAcceptKey(const zypp::PublicKey &key, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:86
zyppng::KeyRingReportHelper::askUserToAcceptUnknownKey
bool askUserToAcceptUnknownKey(const std::string &file, const std::string &id, const zypp::KeyContext &keycontext={})
Definition reporthelper.cc:160
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 Arch.h:364
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 MediaCurl2.h:22
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:1093
zypp::JobReport::warning
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
Definition ZYppCallbacks.h:1101
zypp::JobReport::error
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
Definition ZYppCallbacks.h:1105
zypp::JobReport::data
static bool data(const std::string &msg_r, const UserData &userData_r=UserData())
send data message
Definition ZYppCallbacks.h:1113
zypp::JobReport::important
static bool important(const std::string &msg_r, const UserData &userData_r=UserData())
send important message text
Definition ZYppCallbacks.h:1109
zypp::JobReport::info
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
Definition ZYppCallbacks.h:1097
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:253
PL_
#define PL_(MSG1, MSG2, N)
Definition Gettext.h:42
_
#define _(MSG)
Definition Gettext.h:39
ERR
#define ERR
Definition Logger.h:102
Digest.h
userrequest.h