libzypp  17.36.7
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 
17 namespace zyppng {
18 
20  {
21  auto frame = rpc::prepareFrame<ProviderConfiguration>();
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 
39  return zyppng::expected<ProviderConfiguration>::success ( std::move(res) );
40 
41  } catch ( const zypp::Exception &e ) {
42  ZYPP_CAUGHT (e);
44  }
45  }
46 
51  { }
52 
54  { }
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  {
78  _protocolVersion = v;
79  }
80 
82  {
83  _workerType = t;
84  }
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 {
99  zypp::PluginFrame pf = zyppng::rpc::prepareFrame<WorkerCaps>();
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
135  zyppng::rpc::parseDataIntoField ( val, tVal );
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 
145  { }
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 );
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 )
226  return expected<ProvideMessage>::success( std::move(pMessage) );
227  };
228 
229  switch ( c )
230  {
232  DEF_REQ_FIELD(url);
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  }
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 )
251  FAIL_IF_NOT_SEEN_REQ_FIELD( ProvideFinished, local_filename );
252  return expected<ProvideMessage>::success( std::move(pMessage) );
253  }
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  }
262  // no known fields
264  HANDLE_UNKNOWN_FIELD( name, val )
266  return expected<ProvideMessage>::success( std::move(pMessage) );
267  }
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 )
281  FAIL_IF_NOT_SEEN_REQ_FIELD( ProvideStarted, auth_timestamp );
282  return expected<ProvideMessage>::success( std::move(pMessage) );
283  }
285  // no known fields
287  HANDLE_UNKNOWN_FIELD( name, val )
289  return expected<ProvideMessage>::success( std::move(pMessage) );
290 
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  }
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  }
325  return validateErrorMsg(msg);
326  }
328  DEF_REQ_FIELD(url);
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  }
342  // no known fields
344  HANDLE_UNKNOWN_FIELD( name, val )
346  return expected<ProvideMessage>::success( std::move(pMessage) );
347 
349  std::exception_ptr error;
350 
351  DEF_REQ_FIELD(url);
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 )
372  FAIL_IF_NOT_SEEN_REQ_FIELD( Provide, attach_id );
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  }
379  DEF_REQ_FIELD(url);
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  }
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  }
402  DEF_REQ_FIELD(label);
403  DEF_REQ_FIELD(media_nr);
406  PARSE_REQ_FIELD ( MediaChangeRequest, label, std::string )
407  OR_PARSE_REQ_FIELD ( MediaChangeRequest, media_nr, int32_t )
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
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  {
432  zypp::PluginFrame f = rpc::prepareFrame<ProvideMessage>();
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 
454  {
455  return ProvideMessage::create(msg);
456  }
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;
462  msg.setRequestId ( reqId );
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;
476  msg.setRequestId ( reqId );
477  msg.setValue ( ProvideFinishedMsgFields::LocalFilename, localFilename );
479 
480  return msg;
481  }
482 
483  ProvideMessage ProvideMessage::createAttachFinished(const uint32_t reqId , const std::optional<std::string> &localMountPoint )
484  {
485  ProvideMessage msg;
487  msg.setRequestId ( reqId );
488 
489  if ( localMountPoint )
490  msg.setValue ( AttachFinishedMsgFields::LocalMountPoint, *localMountPoint );
491 
492  return msg;
493  }
494 
496  {
497  ProvideMessage msg;
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;
508  msg.setRequestId ( reqId );
511  msg.setValue ( AuthInfoMsgFields::AuthTimestamp, timestamp );
512  for ( const auto& i : extraValues ) {
513  msg.setValue( i.first, i.second );
514  }
515  return msg;
516  }
517 
519  {
520  ProvideMessage msg;
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;
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;
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;
564  msg.setRequestId ( reqId );
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;
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;
591  msg.setRequestId ( reqId );
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;
612  msg.setRequestId ( reqId );
613  msg.setValue ( DetachMsgFields::Url, attachUrl.asCompleteString() );
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;
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;
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 
652  void ProvideMessage::setRequestId(const uint id)
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 }
void add(const std::string &key, const Value &val)
constexpr std::string_view Url("url")
constexpr std::string_view LocalFilename("local_filename")
static constexpr std::string_view typeName
constexpr std::string_view AttachId("attach_id")
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:424
constexpr std::string_view VerifyData("verify_data")
static ProvideMessage createMetalinkRedir(const uint32_t reqId, const std::vector< zypp::Url > &newUrls)
Command frame for communication with PluginScript.
Definition: PluginFrame.h:41
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)
constexpr std::string_view Filename("filename")
const std::string & command() const
Return the frame command.
Definition: PluginFrame.cc:439
static zyppng::expected< void > doParseField(const std::string &val, ProvideMessage &t, std::string_view msgtype, std::string_view name)
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={})
void set_cfg_flags(Flags f)
void set_protocol_version(uint32_t v)
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={})
#define DEF_REQ_FIELD(fname)
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.
Definition: PluginFrame.cc:475
#define OR_HANDLE_UNKNOWN_FIELD(fname, val)
static ProvideMessage createMediaChanged(const uint32_t reqId)
String related utilities and Regular expression matching.
void setCode(const Code newCode)
constexpr std::string_view MediaNr("media_nr")
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
Definition: String.h:139
ValueMap::iterator endList()
static ProvideMessage createErrorResponse(const uint32_t reqId, const Code code, const std::string &reason, bool transient=false)
#define FAIL_IF_NOT_SEEN_REQ_FIELD(msgtype, fname)
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.
Definition: PluginFrame.cc:481
constexpr std::string_view VerifyType("verify_type")
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
Definition: Exception.h:428
void addValue(const std::string &name, const FieldVal &value)
#define HANDLE_UNKNOWN_FIELD(fname, val)
#define PARSE_REQ_FIELD(msgtype, fname, ftype)
constexpr std::string_view RequestCode("requestCode")
#define OR_PARSE_OPT_FIELD(msgtype, fname, ftype)
#define BEGIN_PARSE_HEADERS
constexpr std::string_view Label("label")
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
Definition: PluginFrame.h:171
#define PARSE_OPT_FIELD(msgtype, fname, ftype)
static ProvideMessage createProvideStarted(const uint32_t reqId, const zypp::Url &url, const std::optional< std::string > &localFilename={}, const std::optional< std::string > &stagingFilename={})
constexpr std::string_view Password("password")
constexpr std::string_view Username("username")
static zyppng::expected< ProviderConfiguration > fromStompMessage(const zypp::PluginFrame &msg)
std::vector< Value > & values(const std::string &key)
void set_worker_type(WorkerType t)
Value value(const std::string_view &str, const Value &defaultVal=Value()) const
constexpr std::string_view CheckExistOnly("check_existance_only")
constexpr std::string_view NewUrl("new_url")
constexpr std::string_view RequestId("requestId")
static expected< ProvideMessage > create(const zypp::PluginFrame &message)
constexpr std::string_view LocalFilename("local_filename")
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
static zyppng::expected< WorkerCaps > fromStompMessage(const zypp::PluginFrame &msg)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
Definition: String.h:211
constexpr std::string_view LastAuthTimestamp("last_auth_timestamp")
zyppng::expected< zypp::PluginFrame > toStompMessage() const
void parseDataIntoField(const std::string &headerVal, T &target)
constexpr std::string_view Device("device")
constexpr std::string_view Label("label")
#define WAR
Definition: Logger.h:101
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:523
constexpr std::string_view MediaNr("media_nr")
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={})
void set_worker_name(std::string name)
static ProvideMessage createDetach(const uint32_t reqId, const zypp::Url &attachUrl)
zyppng::expected< zypp::PluginFrame > toStompMessage() const
WorkerType worker_type() const
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
Definition: PluginFrame.h:175
constexpr std::string_view Reason("reason")
ValueMap::iterator beginList()
void set(const std::string &key, Value val)
static ProvideMessage createRedirect(const uint32_t reqId, const zypp::Url &newUrl)
static expected success(ConsParams &&...params)
Definition: expected.h:115
constexpr std::string_view NewUrl("new_url")
uint32_t protocol_version() const
void setValue(const std::string &name, const FieldVal &value)
constexpr std::string_view DeltaFile("delta_file")
constexpr std::string_view EffectiveUrl("effective_url")
static constexpr std::string_view typeName
static expected< ProvideMessage > fromStompMessage(const zypp::PluginFrame &msg)
const std::string & worker_name() const
constexpr std::string_view Transient("transient")
const std::vector< ProvideMessage::FieldVal > & values(const std::string_view &str) const
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
Definition: Exception.h:440
constexpr std::string_view AuthTimestamp("auth_timestamp")
void setRequestId(const uint id)
Base class for Exception.
Definition: Exception.h:146
static ProvideMessage createCancel(const uint32_t reqId)
constexpr std::string_view Url("url")
constexpr std::string_view LocalMountPoint("local_mountpoint")
static ProvideMessage createProvideFinished(const uint32_t reqId, const std::string &localFilename, bool cacheHit)
constexpr std::string_view Url("url")
void parseHeaderIntoField(const zypp::PluginFrame &msg, const std::string &name, T &target)
constexpr std::string_view device("device")
constexpr std::string_view StagingFilename("staging_filename")
typename decay< T >::type decay_t
Definition: TypeTraits.h:42
Flags cfg_flags() const
#define END_PARSE_HEADERS
constexpr std::string_view Url("url")
static constexpr std::string_view typeName
#define OR_PARSE_REQ_FIELD(msgtype, fname, ftype)
const HeaderValueMap & headers() const
constexpr std::string_view Desc("desc")
expected< zypp::PluginFrame > toStompMessage() const
static ProvideMessage createDetachFinished(const uint32_t reqId)
constexpr std::string_view CacheHit("cacheHit")
constexpr std::string_view LastUser("username")
Url manipulation class.
Definition: Url.h:92
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)
static ProvideMessage createAttachFinished(const uint32_t reqId, const std::optional< std::string > &localMountPoint={})
constexpr std::string_view ExpectedFilesize("expected_filesize")