libzypp
17.35.19
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
15
namespace
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::AutoDispose
Reference counted access to a Tp object calling a custom Dispose function when the last AutoDispose h...
Definition
AutoDispose.h:95
zypp::PublicKeyData
Class representing one GPG Public Keys data.
Definition
PublicKey.h:208
zypp::PublicKey
Class representing one GPG Public Key (PublicKeyData + ASCII armored in a tempfile).
Definition
PublicKey.h:365
zypp::callback::UserData
Typesafe passing of user data via callbacks.
Definition
UserData.h:40
zypp::filesystem::Pathname
Pathname.
Definition
Pathname.h:47
zyppng::BasicReportHelper::BasicReportHelper
BasicReportHelper(const BasicReportHelper &)=default
zyppng::DigestReportHelper
Definition
reporthelper.h:80
zyppng::DigestReportHelper::askUserToAcceptNoDigest
bool askUserToAcceptNoDigest(const zypp::Pathname &file)
Definition
reporthelper.cc:23
zyppng::JobReportHelper
Definition
reporthelper.h:135
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
std
Definition
Arch.h:364
str
String related utilities and Regular expression matching.
zyppng
Definition
MediaNetwork.h:23
reporthelper.h
_ctx
DlContextRefType _ctx
Definition
rpmmd.cc:69
zypp::JobReport::debug
static bool debug(const std::string &msg_r, const UserData &userData_r=UserData())
send debug message text
Definition
ZYppCallbacks.h:1023
zypp::JobReport::warning
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text
Definition
ZYppCallbacks.h:1031
zypp::JobReport::error
static bool error(const std::string &msg_r, const UserData &userData_r=UserData())
send error text
Definition
ZYppCallbacks.h:1035
zypp::JobReport::data
static bool data(const std::string &msg_r, const UserData &userData_r=UserData())
send data message
Definition
ZYppCallbacks.h:1043
zypp::JobReport::important
static bool important(const std::string &msg_r, const UserData &userData_r=UserData())
send important message text
Definition
ZYppCallbacks.h:1039
zypp::JobReport::info
static bool info(const std::string &msg_r, const UserData &userData_r=UserData())
send message text
Definition
ZYppCallbacks.h:1027
zypp::KeyContext
Definition
KeyContext.h:9
zypp::KeyRingReport::KeyTrust
KeyTrust
User reply options for the askUserToTrustKey callback.
Definition
KeyRing.h:52
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
zypp
ng
reporthelper.cc
Generated by
1.10.0