libzypp 17.37.17
providemessage.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
9
12
13#include <zypp-core/Url.h>
14#include <string_view>
15#include <string>
16
17namespace zyppng {
18
20 {
22 for ( const auto &v : *this ) {
23 frame.addHeader( v.first, v.second );
24 }
25 return zyppng::expected<zypp::PluginFrame>::success( std::move(frame) );
26 }
27
29 {
30 try {
32 ZYPP_THROW( InvalidMessageReceivedException("Message is not of type ProviderConfiguration") );
33
35 for ( auto i = msg.headerBegin (); i != msg.headerEnd(); i++ ) {
36 res.insert_or_assign ( i->first, i->second );
37 }
38
40
41 } catch ( const zypp::Exception &e ) {
42 ZYPP_CAUGHT (e);
44 }
45 }
46
52
55
57 {
58 return _protocolVersion;
59 }
60
62 {
63 return static_cast<WorkerType>(_workerType);
64 }
65
67 {
68 return static_cast<WorkerCaps::Flags>(_cfgFlags);
69 }
70
71 const std::string &WorkerCaps::worker_name() const
72 {
73 return _workerName;
74 }
75
77 {
79 }
80
85
87 {
88 _cfgFlags = f;
89 }
90
91 void WorkerCaps::set_worker_name(std::string name)
92 {
93 _workerName = std::move(name);
94 }
95
97 {
98 try {
100 pf.addHeader ( "protocolVersion", zypp::str::asString (_protocolVersion) );
101 pf.addHeader ( "workerType" , zypp::str::asString (_workerType) );
102 pf.addHeader ( "cfgFlags" , zypp::str::asString (_cfgFlags) );
103 pf.addHeader ( "workerName" , zypp::str::asString (_workerName) );
104 return zyppng::expected<zypp::PluginFrame>::success ( std::move(pf) );
105
106 } catch ( const zypp::Exception &e ) {
107 ZYPP_CAUGHT (e);
109 }
110 }
111
113 {
114 try {
115 if ( msg.command() != WorkerCaps::typeName )
116 ZYPP_THROW( InvalidMessageReceivedException("Message is not of type WorkerCaps") );
117
118 WorkerCaps res;
119 zyppng::rpc::parseHeaderIntoField( msg, "protocolVersion", res._protocolVersion );
120 zyppng::rpc::parseHeaderIntoField( msg, "workerType", res._workerType );
121 zyppng::rpc::parseHeaderIntoField( msg, "cfgFlags", res._cfgFlags );
122 zyppng::rpc::parseHeaderIntoField( msg, "workerName", res._workerName );
123 return zyppng::expected<WorkerCaps>::success ( std::move(res) );
124
125 } catch ( const zypp::Exception &e ) {
126 ZYPP_CAUGHT (e);
128 }
129 }
130
131 template <typename T>
132 static zyppng::expected<void> doParseField( const std::string &val, ProvideMessage &t, std::string_view msgtype, std::string_view name ) {
133 try {
134 T tVal; // the target value type
136 t.addValue( name, std::move(tVal) );
138 } catch ( const zypp::Exception &e ) {
139 ZYPP_CAUGHT(e);
140 return zyppng::expected<void>::error( ZYPP_EXCPT_PTR( InvalidMessageReceivedException( zypp::str::Str() << "Parse error " << msgtype << ", Field " << name << " has invalid type" ) ) );
141 }
142 }
143
146
148 {
149 if ( msg.command() != ProvideMessage::typeName ) {
150 return zyppng::expected<ProvideMessage>::error( ZYPP_EXCPT_PTR( InvalidMessageReceivedException("Message is not of type WorkerCaps") ) );
151 }
152
153 const std::string &codeStr = msg.getHeaderNT( std::string(ProvideMessageFields::RequestCode) );
154 if ( codeStr.empty () ) {
155 return zyppng::expected<ProvideMessage>::error( ZYPP_EXCPT_PTR ( InvalidMessageReceivedException("Invalid message, PluginFrame has no requestId header.")) );
156 }
157
158 const auto c = zyppng::str::safe_strtonum<uint32_t>( codeStr ).value_or ( NoCode );
159 const auto validCode = ( c >= ProvideMessage::Code::FirstInformalCode && c <= ProvideMessage::Code::LastInformalCode )
160 || ( c >= ProvideMessage::Code::FirstSuccessCode && c <= ProvideMessage::Code::LastSuccessCode )
161 || ( c >= ProvideMessage::Code::FirstRedirCode && c <= ProvideMessage::Code::LastRedirCode )
162 || ( c >= ProvideMessage::Code::FirstClientErrCode && c <= ProvideMessage::Code::LastClientErrCode )
163 || ( c >= ProvideMessage::Code::FirstSrvErrCode && c <= ProvideMessage::Code::LastSrvErrCode )
164 || ( c >= ProvideMessage::Code::FirstControllerCode && c <= ProvideMessage::Code::LastControllerCode)
165 || ( c >= ProvideMessage::Code::FirstWorkerCode && c <= ProvideMessage::Code::LastWorkerCode );
166 if ( !validCode ) {
168 }
169
170 const std::string & idStr = msg.getHeaderNT( std::string(ProvideMessageFields::RequestId) );
171 if ( idStr.empty () ) {
172 return zyppng::expected<ProvideMessage>::error( ZYPP_EXCPT_PTR ( InvalidMessageReceivedException("Invalid message, PluginFrame has no requestId header.")) );
173 }
174
175 const auto &maybeId = zyppng::str::safe_strtonum<uint>( idStr );
176 if ( !maybeId ) {
177 return zyppng::expected<ProvideMessage>::error( ZYPP_EXCPT_PTR ( InvalidMessageReceivedException("Invalid message, can not parse requestId header.")) );
178 }
179
180 ProvideMessage pMessage;
181 pMessage.setCode ( static_cast<MessageCodes>(c) );
182 pMessage.setRequestId ( *maybeId );
183
184 #define DEF_REQ_FIELD( fname ) bool has_##fname = false
185
186 #define PARSE_FIELD( msgtype, fname, ftype, _C_ ) \
187 if ( name == #fname ) { \
188 const auto &res = doParseField<ftype>( val, pMessage, #msgtype, #fname ); \
189 if ( !res ) { \
190 return zyppng::expected<ProvideMessage>::error(res.error()); \
191 } \
192 _C_ \
193 }
194
195 #define HANDLE_UNKNOWN_FIELD( fname, val ) { \
196 pMessage.addValue( fname, val ); \
197 }
198
199 #define OR_HANDLE_UNKNOWN_FIELD( fname, val ) else HANDLE_UNKNOWN_FIELD( fname, val )
200
201 #define BEGIN_PARSE_HEADERS \
202 for ( const auto &header : msg.headerList() ) { \
203 const auto &name = header.first; \
204 const auto &val = header.second;
205
206 #define END_PARSE_HEADERS }
207
208 #define PARSE_REQ_FIELD( msgtype, fname, ftype ) PARSE_FIELD( msgtype, fname, ftype, has_##fname = true; )
209 #define OR_PARSE_REQ_FIELD( msgtype, fname, ftype ) else PARSE_REQ_FIELD( msgtype, fname, ftype )
210 #define PARSE_OPT_FIELD( msgtype, fname, ftype ) PARSE_FIELD( msgtype, fname, ftype, )
211 #define OR_PARSE_OPT_FIELD( msgtype, fname, ftype ) else PARSE_OPT_FIELD( msgtype, fname, ftype )
212
213 #define FAIL_IF_NOT_SEEN_REQ_FIELD( msgtype, fname ) \
214 if ( !has_##fname ) \
215 return expected<ProvideMessage>::error( ZYPP_EXCPT_PTR( InvalidMessageReceivedException( zypp::str::Str() << #msgtype <<" message does not contain required " << #fname << " field" ) ) )
216
217 auto validateErrorMsg = [&]( const auto &msg ){
218 DEF_REQ_FIELD(reason);
220 PARSE_REQ_FIELD ( Error, reason, std::string )
221 OR_PARSE_OPT_FIELD ( Error, history, std::string )
222 OR_PARSE_OPT_FIELD ( Error, transient, bool )
223 OR_HANDLE_UNKNOWN_FIELD( name, val )
225 FAIL_IF_NOT_SEEN_REQ_FIELD( Error, reason );
226 return expected<ProvideMessage>::success( std::move(pMessage) );
227 };
228
229 switch ( c )
230 {
231 case ProvideMessage::Code::ProvideStarted: {
234 PARSE_REQ_FIELD ( ProvideStarted, url, std::string )
235 OR_PARSE_OPT_FIELD ( ProvideStarted, local_filename, std::string )
236 OR_PARSE_OPT_FIELD ( ProvideStarted, staging_filename, std::string )
237 OR_HANDLE_UNKNOWN_FIELD( name, val )
240 return expected<ProvideMessage>::success( std::move(pMessage) );
241 }
242 case ProvideMessage::Code::ProvideFinished: {
243 DEF_REQ_FIELD(cacheHit);
244 DEF_REQ_FIELD(local_filename);
246 PARSE_REQ_FIELD ( ProvideFinished, cacheHit, bool )
247 OR_PARSE_REQ_FIELD ( ProvideFinished, local_filename, std::string )
248 OR_HANDLE_UNKNOWN_FIELD( name, val )
252 return expected<ProvideMessage>::success( std::move(pMessage) );
253 }
254 case ProvideMessage::Code::AttachFinished: {
256 PARSE_OPT_FIELD ( AttachFinished, local_mountpoint, std::string )
257 OR_HANDLE_UNKNOWN_FIELD( name, val )
259 return expected<ProvideMessage>::success( std::move(pMessage) );
260 }
261 case ProvideMessage::Code::DetachFinished: {
262 // no known fields
264 HANDLE_UNKNOWN_FIELD( name, val )
266 return expected<ProvideMessage>::success( std::move(pMessage) );
267 }
268 case ProvideMessage::Code::AuthInfo: {
269 DEF_REQ_FIELD(username);
270 DEF_REQ_FIELD(password);
271 DEF_REQ_FIELD(auth_timestamp);
273 PARSE_REQ_FIELD ( AuthInfo, username, std::string )
274 OR_PARSE_REQ_FIELD ( AuthInfo, password, std::string )
275 OR_PARSE_REQ_FIELD ( AuthInfo, auth_timestamp, int64_t )
276 OR_PARSE_OPT_FIELD ( AuthInfo, authType, std::string )
277 OR_HANDLE_UNKNOWN_FIELD( name, val )
282 return expected<ProvideMessage>::success( std::move(pMessage) );
283 }
284 case ProvideMessage::Code::MediaChanged:
285 // no known fields
287 HANDLE_UNKNOWN_FIELD( name, val )
289 return expected<ProvideMessage>::success( std::move(pMessage) );
290
291 case ProvideMessage::Code::Redirect: {
292 DEF_REQ_FIELD(new_url);
294 PARSE_REQ_FIELD ( Redirect, new_url, std::string )
295 OR_HANDLE_UNKNOWN_FIELD( name, val )
298 return expected<ProvideMessage>::success( std::move(pMessage) );
299 }
300 case ProvideMessage::Code::Metalink: {
301 DEF_REQ_FIELD(new_url);
303 PARSE_REQ_FIELD ( Metalink, new_url, std::string )
304 OR_HANDLE_UNKNOWN_FIELD( name, val )
307 return expected<ProvideMessage>::success( std::move(pMessage) );
308 }
309 case ProvideMessage::Code::BadRequest:
310 case ProvideMessage::Code::Unauthorized:
311 case ProvideMessage::Code::Forbidden:
312 case ProvideMessage::Code::PeerCertificateInvalid:
313 case ProvideMessage::Code::NotFound:
314 case ProvideMessage::Code::ExpectedSizeExceeded:
315 case ProvideMessage::Code::ConnectionFailed:
316 case ProvideMessage::Code::Timeout:
317 case ProvideMessage::Code::Cancelled:
318 case ProvideMessage::Code::InvalidChecksum:
319 case ProvideMessage::Code::MountFailed:
320 case ProvideMessage::Code::Jammed:
321 case ProvideMessage::Code::NoAuthData:
322 case ProvideMessage::Code::MediaChangeAbort:
323 case ProvideMessage::Code::MediaChangeSkip:
324 case ProvideMessage::Code::InternalError: {
325 return validateErrorMsg(msg);
326 }
327 case ProvideMessage::Code::Prov: {
330 PARSE_REQ_FIELD ( Provide, url, std::string )
331 OR_PARSE_OPT_FIELD ( Provide, filename, std::string )
332 OR_PARSE_OPT_FIELD ( Provide, delta_file, std::string )
333 OR_PARSE_OPT_FIELD ( Provide, expected_filesize, int64_t )
334 OR_PARSE_OPT_FIELD ( Provide, check_existance_only, bool )
335 OR_PARSE_OPT_FIELD ( Provide, metalink_enabled, bool )
336 OR_HANDLE_UNKNOWN_FIELD( name, val )
339 return expected<ProvideMessage>::success( std::move(pMessage) );
340 }
341 case ProvideMessage::Code::Cancel:
342 // no known fields
344 HANDLE_UNKNOWN_FIELD( name, val )
346 return expected<ProvideMessage>::success( std::move(pMessage) );
347
348 case ProvideMessage::Code::Attach: {
349 std::exception_ptr error;
350
352 DEF_REQ_FIELD(attach_id);
353 DEF_REQ_FIELD(label);
354
355 // not really required, but this way we can check if all false or all true
356 DEF_REQ_FIELD(verify_type);
357 DEF_REQ_FIELD(verify_data);
358 DEF_REQ_FIELD(media_nr);
359
361 PARSE_REQ_FIELD ( Attach, url , std::string )
362 OR_PARSE_REQ_FIELD ( Attach, attach_id , std::string )
363 OR_PARSE_REQ_FIELD ( Attach, label , std::string )
364 OR_PARSE_REQ_FIELD ( Attach, verify_type, std::string )
365 OR_PARSE_REQ_FIELD ( Attach, verify_data, std::string )
366 OR_PARSE_REQ_FIELD ( Attach, media_nr , int32_t )
367 OR_PARSE_OPT_FIELD ( Attach, device , std::string )
368 OR_HANDLE_UNKNOWN_FIELD( name, val )
373 if ( ! ( ( has_verify_data == has_verify_type ) && ( has_verify_type == has_media_nr ) ) )
374 return expected<ProvideMessage>::error( ZYPP_EXCPT_PTR ( InvalidMessageReceivedException("Error in Attach message, one of the following fields is not set or invalid: ( verify_type, verify_data, media_nr ). Either none or all need to be set. ")) );
375
376 return expected<ProvideMessage>::success( std::move(pMessage) );
377 }
378 case ProvideMessage::Code::Detach: {
381 PARSE_REQ_FIELD ( Detach, url, std::string )
382 OR_HANDLE_UNKNOWN_FIELD( name, val )
385
386 return expected<ProvideMessage>::success( std::move(pMessage) );
387 }
388 case ProvideMessage::Code::AuthDataRequest: {
389 DEF_REQ_FIELD(effective_url);
391 PARSE_REQ_FIELD ( AuthDataRequest, effective_url, std::string )
392 OR_PARSE_OPT_FIELD ( AuthDataRequest, last_auth_timestamp, int64_t )
393 OR_PARSE_OPT_FIELD ( AuthDataRequest, username, std::string )
394 OR_PARSE_OPT_FIELD ( AuthDataRequest, authHint, std::string )
395 OR_HANDLE_UNKNOWN_FIELD( name, val )
398
399 return expected<ProvideMessage>::success( std::move(pMessage) );
400 }
401 case ProvideMessage::Code::MediaChangeRequest: {
402 DEF_REQ_FIELD(label);
403 DEF_REQ_FIELD(media_nr);
404 DEF_REQ_FIELD(device);
406 PARSE_REQ_FIELD ( MediaChangeRequest, label, std::string )
407 OR_PARSE_REQ_FIELD ( MediaChangeRequest, media_nr, int32_t )
408 OR_PARSE_REQ_FIELD ( MediaChangeRequest, device, std::string )
409 OR_PARSE_OPT_FIELD ( MediaChangeRequest, desc, std::string )
410 OR_HANDLE_UNKNOWN_FIELD( name, val )
415
416 return expected<ProvideMessage>::success( std::move(pMessage) );
417 }
418 default: {
419 // all error messages have the same format
420 if ( c >= ProvideMessage::Code::FirstClientErrCode && c <= ProvideMessage::Code::LastSrvErrCode ) {
421 return validateErrorMsg(msg);
422 }
423 }
424 }
425
426 // we should never reach this line because we check in the beginning if the know the message code
428 }
429
431 {
433 f.addHeader ( std::string(ProvideMessageFields::RequestCode), zypp::str::asString (static_cast<uint32_t>(_code)) );
435 for ( auto i = _headers.beginList (); i != _headers.endList(); i++ ) {
436 for ( const auto &val : i->second ) {
437 const auto &strVal = std::visit([&]( const auto &val ){
438 if constexpr( std::is_same_v<std::decay_t<decltype(val)>, std::monostate> )
439 return std::string();
440 else {
441 return zypp::str::asString(val);
442 }
443 }, val.asVariant() );
444 if ( strVal.empty () )
445 continue;
446 f.addHeader( i->first, strVal );
447 }
448 }
449
450 return expected<zypp::PluginFrame>::success ( std::move(f) );
451 }
452
457
458 ProvideMessage ProvideMessage::createProvideStarted( const uint32_t reqId, const zypp::Url &url, const std::optional<std::string> &localFilename, const std::optional<std::string> &stagingFilename )
459 {
460 ProvideMessage msg;
461 msg.setCode ( ProvideMessage::Code::ProvideStarted );
462 msg.setRequestId ( reqId );
463 msg.setValue ( ProvideStartedMsgFields::Url, url.asCompleteString() );
464 if ( localFilename )
465 msg.setValue ( ProvideStartedMsgFields::LocalFilename, *localFilename );
466 if ( stagingFilename )
467 msg.setValue ( ProvideStartedMsgFields::StagingFilename, *stagingFilename );
468
469 return msg;
470 }
471
472 ProvideMessage ProvideMessage::createProvideFinished( const uint32_t reqId, const std::string &localFilename, bool cacheHit )
473 {
474 ProvideMessage msg;
475 msg.setCode ( ProvideMessage::Code::ProvideFinished );
476 msg.setRequestId ( reqId );
479
480 return msg;
481 }
482
483 ProvideMessage ProvideMessage::createAttachFinished(const uint32_t reqId , const std::optional<std::string> &localMountPoint )
484 {
485 ProvideMessage msg;
486 msg.setCode ( ProvideMessage::Code::AttachFinished );
487 msg.setRequestId ( reqId );
488
489 if ( localMountPoint )
490 msg.setValue ( AttachFinishedMsgFields::LocalMountPoint, *localMountPoint );
491
492 return msg;
493 }
494
496 {
497 ProvideMessage msg;
498 msg.setCode ( ProvideMessage::Code::DetachFinished );
499 msg.setRequestId ( reqId );
500
501 return msg;
502 }
503
504 ProvideMessage ProvideMessage::createAuthInfo( const uint32_t reqId, const std::string &user, const std::string &pw, int64_t timestamp, const std::map<std::string, std::string> &extraValues )
505 {
506 ProvideMessage msg;
507 msg.setCode ( ProvideMessage::Code::AuthInfo );
508 msg.setRequestId ( reqId );
512 for ( const auto& i : extraValues ) {
513 msg.setValue( i.first, i.second );
514 }
515 return msg;
516 }
517
519 {
520 ProvideMessage msg;
521 msg.setCode ( ProvideMessage::Code::MediaChanged );
522 msg.setRequestId ( reqId );
523
524 return msg;
525 }
526
527 ProvideMessage ProvideMessage::createRedirect( const uint32_t reqId, const zypp::Url &newUrl )
528 {
529 ProvideMessage msg;
530 msg.setCode ( ProvideMessage::Code::Redirect );
531 msg.setRequestId ( reqId );
533
534 return msg;
535 }
536
537 ProvideMessage ProvideMessage::createMetalinkRedir( const uint32_t reqId, const std::vector<zypp::Url> &newUrls )
538 {
539 ProvideMessage msg;
540 msg.setCode ( ProvideMessage::Code::Metalink );
541 msg.setRequestId ( reqId );
542 for( const auto &val : newUrls )
543 msg.addValue( MetalinkRedirectMsgFields::NewUrl, val.asCompleteString() );
544
545 return msg;
546 }
547
548 ProvideMessage ProvideMessage::createErrorResponse( const uint32_t reqId, const Code code, const std::string &reason, bool transient )
549 {
550 ProvideMessage msg;
551 if ( code < Code::FirstClientErrCode || code > Code::LastSrvErrCode )
552 ZYPP_THROW(std::out_of_range("code must be between 400 and 599"));
553 msg.setCode ( code );
554 msg.setRequestId ( reqId );
555 msg.setValue ( ErrMsgFields::Reason, reason );
556 msg.setValue ( ErrMsgFields::Transient, transient );
557 return msg;
558 }
559
560 ProvideMessage ProvideMessage::createProvide( const uint32_t reqId, const zypp::Url &url, const std::optional<std::string> &filename, const std::optional<std::string> &deltaFile, const std::optional<int64_t> &expFilesize, bool checkExistOnly )
561 {
562 ProvideMessage msg;
563 msg.setCode ( ProvideMessage::Code::Prov );
564 msg.setRequestId ( reqId );
565 msg.setValue ( ProvideMsgFields::Url, url.asCompleteString() );
566
567 if ( filename )
568 msg.setValue ( ProvideMsgFields::Filename, *filename );
569 if ( deltaFile )
570 msg.setValue ( ProvideMsgFields::DeltaFile, *deltaFile );
571 if ( expFilesize )
572 msg.setValue ( ProvideMsgFields::ExpectedFilesize, *expFilesize );
573 msg.setValue ( ProvideMsgFields::CheckExistOnly, checkExistOnly );
574
575 return msg;
576 }
577
579 {
580 ProvideMessage msg;
581 msg.setCode ( ProvideMessage::Code::Cancel );
582 msg.setRequestId ( reqId );
583
584 return msg;
585 }
586
587 ProvideMessage ProvideMessage::createAttach(const uint32_t reqId, const zypp::Url &url, const std::string attachId, const std::string &label, const std::optional<std::string> &verifyType, const std::optional<std::string> &verifyData, const std::optional<int32_t> &mediaNr )
588 {
589 ProvideMessage msg;
590 msg.setCode ( ProvideMessage::Code::Attach );
591 msg.setRequestId ( reqId );
592 msg.setValue ( AttachMsgFields::Url, url.asCompleteString() );
593 msg.setValue ( AttachMsgFields::AttachId, attachId );
594 msg.setValue ( AttachMsgFields::Label, label );
595
596 if ( verifyType.has_value() && verifyData.has_value() && mediaNr.has_value() ) {
597 msg.setValue ( AttachMsgFields::VerifyType, *verifyType );
598 msg.setValue ( AttachMsgFields::VerifyData, *verifyData );
599 msg.setValue ( AttachMsgFields::MediaNr, *mediaNr );
600 } else {
601 if ( !( ( verifyType.has_value() == verifyData.has_value() ) && ( verifyData.has_value() == mediaNr.has_value() ) ) )
602 WAR << "Attach message requires verifyType, verifyData and mediaNr either set together or not set at all." << std::endl;
603 }
604
605 return msg;
606 }
607
608 ProvideMessage ProvideMessage::createDetach( const uint32_t reqId, const zypp::Url &attachUrl )
609 {
610 ProvideMessage msg;
611 msg.setCode ( ProvideMessage::Code::Detach );
612 msg.setRequestId ( reqId );
614
615 return msg;
616 }
617
618 ProvideMessage ProvideMessage::createAuthDataRequest( const uint32_t reqId, const zypp::Url &effectiveUrl, const std::string &lastTriedUser, const std::optional<int64_t> &lastAuthTimestamp, const std::map<std::string, std::string> &extraValues )
619 {
620 ProvideMessage msg;
621 msg.setCode ( ProvideMessage::Code::AuthDataRequest );
622 msg.setRequestId ( reqId );
624 if ( lastTriedUser.size() )
625 msg.setValue( AuthDataRequestMsgFields::LastUser, lastTriedUser );
626 if ( lastAuthTimestamp )
627 msg.setValue ( AuthDataRequestMsgFields::LastAuthTimestamp, *lastAuthTimestamp );
628
629 return msg;
630 }
631
632 ProvideMessage ProvideMessage::createMediaChangeRequest( const uint32_t reqId, const std::string &label, int32_t mediaNr, const std::vector<std::string> &devices, const std::optional<std::string> &desc )
633 {
634 ProvideMessage msg;
635 msg.setCode ( ProvideMessage::Code::MediaChangeRequest );
636 msg.setRequestId ( reqId );
639 for ( const auto &device : devices )
641 if ( desc )
643
644 return msg;
645 }
646
648 {
649 return _reqId;
650 }
651
653 {
654 _reqId = id;
655 }
656
658 {
659 return _code;
660 }
661
663 {
664 _code = newCode;
665 }
666
667 const std::vector<ProvideMessage::FieldVal> &ProvideMessage::values( const std::string_view &str ) const
668 {
669 return _headers.values ( str );
670 }
671
672 const std::vector<ProvideMessage::FieldVal> &ProvideMessage::values( const std::string &str ) const
673 {
674 return values( std::string_view(str));
675 }
676
677 ProvideMessage::FieldVal ProvideMessage::value( const std::string_view &str, const FieldVal &defaultVal ) const
678 {
679 return _headers.value ( str, defaultVal );
680 }
681
683 {
684 return _headers;
685 }
686
687 ProvideMessage::FieldVal ProvideMessage::value( const std::string &str, const FieldVal &defaultVal ) const
688 {
689 return value( std::string_view(str), defaultVal );
690 }
691
692 void ProvideMessage::setValue( const std::string &name, const FieldVal &value )
693 {
694 setValue( std::string_view(name), value );
695 }
696
697 void ProvideMessage::setValue( const std::string_view &name, const FieldVal &value )
698 {
699 _headers.set( std::string(name), value );
700 }
701
702 void ProvideMessage::addValue( const std::string &name, const FieldVal &value )
703 {
704 return addValue( std::string_view(name), value );
705 }
706
707 void ProvideMessage::addValue( const std::string_view &name, const FieldVal &value )
708 {
709 _headers.add( std::string(name), value );
710 }
711
712}
Base class for Exception.
Definition Exception.h:153
Command frame for communication with PluginScript.
Definition PluginFrame.h:42
const std::string & command() const
Return the frame command.
void addHeader(const std::string &key_r, const std::string &value_r=std::string())
Add header for key_r leaving already existing headers for key_r unchanged.
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
const std::string & getHeaderNT(const std::string &key_r, const std::string &default_r=std::string()) const
Not throwing version returing one of the matching header values or default_r string.
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
Url manipulation class.
Definition Url.h:93
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition Url.cc:523
static ProvideMessage createProvideStarted(const uint32_t reqId, const zypp::Url &url, const std::optional< std::string > &localFilename={}, const std::optional< std::string > &stagingFilename={})
static ProvideMessage createAuthInfo(const uint32_t reqId, const std::string &user, const std::string &pw, int64_t timestamp, const std::map< std::string, std::string > &extraValues={})
expected< zypp::PluginFrame > toStompMessage() const
static expected< ProvideMessage > fromStompMessage(const zypp::PluginFrame &msg)
static ProvideMessage createRedirect(const uint32_t reqId, const zypp::Url &newUrl)
static ProvideMessage createMetalinkRedir(const uint32_t reqId, const std::vector< zypp::Url > &newUrls)
ProvideMessage(const ProvideMessage &)=default
static ProvideMessage createCancel(const uint32_t reqId)
const HeaderValueMap & headers() const
static constexpr std::string_view typeName
static ProvideMessage createMediaChanged(const uint32_t reqId)
static ProvideMessage createProvideFinished(const uint32_t reqId, const std::string &localFilename, bool cacheHit)
static ProvideMessage createMediaChangeRequest(const uint32_t reqId, const std::string &label, int32_t mediaNr, const std::vector< std::string > &devices, const std::optional< std::string > &desc)
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
const std::vector< ProvideMessage::FieldVal > & values(const std::string_view &str) const
void setValue(const std::string &name, const FieldVal &value)
static ProvideMessage createAuthDataRequest(const uint32_t reqId, const zypp::Url &effectiveUrl, const std::string &lastTriedUser="", const std::optional< int64_t > &lastAuthTimestamp={}, const std::map< std::string, std::string > &extraValues={})
static ProvideMessage createErrorResponse(const uint32_t reqId, const Code code, const std::string &reason, bool transient=false)
static ProvideMessage createProvide(const uint32_t reqId, const zypp::Url &url, const std::optional< std::string > &filename={}, const std::optional< std::string > &deltaFile={}, const std::optional< int64_t > &expFilesize={}, bool checkExistOnly=false)
void setRequestId(const uint id)
static ProvideMessage createDetachFinished(const uint32_t reqId)
void addValue(const std::string &name, const FieldVal &value)
static ProvideMessage createDetach(const uint32_t reqId, const zypp::Url &attachUrl)
void setCode(const Code newCode)
static expected< ProvideMessage > create(const zypp::PluginFrame &message)
static ProvideMessage createAttachFinished(const uint32_t reqId, const std::optional< std::string > &localMountPoint={})
static ProvideMessage createAttach(const uint32_t reqId, const zypp::Url &url, const std::string attachId, const std::string &label, const std::optional< std::string > &verifyType={}, const std::optional< std::string > &verifyData={}, const std::optional< int32_t > &mediaNr={})
static zyppng::expected< ProviderConfiguration > fromStompMessage(const zypp::PluginFrame &msg)
zyppng::expected< zypp::PluginFrame > toStompMessage() const
static constexpr std::string_view typeName
zyppng::expected< zypp::PluginFrame > toStompMessage() const
const std::string & worker_name() const
Flags cfg_flags() const
void set_worker_type(WorkerType t)
void set_protocol_version(uint32_t v)
WorkerType worker_type() const
uint32_t protocol_version() const
static constexpr std::string_view typeName
static zyppng::expected< WorkerCaps > fromStompMessage(const zypp::PluginFrame &msg)
void set_worker_name(std::string name)
void set_cfg_flags(Flags f)
static expected success(ConsParams &&...params)
Definition expected.h:115
typename decay< T >::type decay_t
Definition TypeTraits.h:42
String related utilities and Regular expression matching.
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition String.h:140
Url details namespace.
Definition UrlBase.cc:58
constexpr std::string_view LocalMountPoint("local_mountpoint")
constexpr std::string_view AttachId("attach_id")
constexpr std::string_view VerifyData("verify_data")
constexpr std::string_view VerifyType("verify_type")
constexpr std::string_view Label("label")
constexpr std::string_view MediaNr("media_nr")
constexpr std::string_view Url("url")
constexpr std::string_view LastUser("username")
constexpr std::string_view EffectiveUrl("effective_url")
constexpr std::string_view LastAuthTimestamp("last_auth_timestamp")
constexpr std::string_view Password("password")
constexpr std::string_view Username("username")
constexpr std::string_view AuthTimestamp("auth_timestamp")
constexpr std::string_view Url("url")
constexpr std::string_view Reason("reason")
constexpr std::string_view Transient("transient")
constexpr std::string_view Label("label")
constexpr std::string_view Desc("desc")
constexpr std::string_view MediaNr("media_nr")
constexpr std::string_view Device("device")
constexpr std::string_view NewUrl("new_url")
constexpr std::string_view LocalFilename("local_filename")
constexpr std::string_view CacheHit("cacheHit")
constexpr std::string_view RequestId("requestId")
constexpr std::string_view RequestCode("requestCode")
constexpr std::string_view Url("url")
constexpr std::string_view ExpectedFilesize("expected_filesize")
constexpr std::string_view DeltaFile("delta_file")
constexpr std::string_view CheckExistOnly("check_existance_only")
constexpr std::string_view Filename("filename")
constexpr std::string_view StagingFilename("staging_filename")
constexpr std::string_view Url("url")
constexpr std::string_view LocalFilename("local_filename")
constexpr std::string_view NewUrl("new_url")
void parseHeaderIntoField(const zypp::PluginFrame &msg, const std::string &name, T &target)
void parseDataIntoField(const std::string &headerVal, T &target)
zypp::PluginFrame prepareFrame()
std::optional< T > safe_strtonum(const std::string_view &val)
Definition string.h:23
static zyppng::expected< void > doParseField(const std::string &val, ProvideMessage &t, std::string_view msgtype, std::string_view name)
#define FAIL_IF_NOT_SEEN_REQ_FIELD(msgtype, fname)
#define HANDLE_UNKNOWN_FIELD(fname, val)
#define DEF_REQ_FIELD(fname)
#define OR_PARSE_OPT_FIELD(msgtype, fname, ftype)
#define END_PARSE_HEADERS
#define OR_HANDLE_UNKNOWN_FIELD(fname, val)
#define PARSE_REQ_FIELD(msgtype, fname, ftype)
#define PARSE_OPT_FIELD(msgtype, fname, ftype)
#define BEGIN_PARSE_HEADERS
#define OR_PARSE_REQ_FIELD(msgtype, fname, ftype)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition String.h:213
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition Exception.h:475
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition Exception.h:463
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
#define WAR
Definition Logger.h:101