libzypp  17.32.4
providemessage.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
9 
11 
12 #include <zypp-core/Url.h>
13 #include <string_view>
14 #include <string>
15 
16 #include <zypp-proto/media/provider.pb.h>
17 
18 namespace zyppng {
19 
20  const std::string &ProviderConfiguration::staticTypeName()
21  {
22  return rpc::messageTypeName<zypp::proto::Configuration>();
23  }
24 
25  const std::string &ProviderConfiguration::typeName() const
26  {
27  return staticTypeName();
28  }
29 
30  bool ProviderConfiguration::deserialize(const std::string &data)
31  {
32  clear();
34  if ( !implVar.ParseFromString( data ) )
35  return false;
36 
37  insert( implVar.values ().begin (), implVar.values ().end() );
38  return true;
39  }
40 
41  void ProviderConfiguration::serializeInto(std::string &str) const
42  {
44  implVar.mutable_values()->insert( begin(), end() );
45  implVar.SerializeToString( &str );
46  }
47 
48  std::string ProviderConfiguration::serialize( ) const
49  {
50  std::string res;
51  serializeInto(res);
52  return res;
53  }
54 
55 
60  : _data( new zypp::proto::Capabilities() )
61  { }
62 
63  ZYPP_IMPL_RPCBASE(WorkerCaps, zypp::proto::Capabilities, _data)
64 
66  { }
67 
69  {
70  return _data->protocol_version ();
71  }
72 
74  {
75  return static_cast<WorkerCaps::WorkerType>(_data->worker_type ());
76  }
77 
79  {
80  return static_cast<WorkerCaps::Flags>(_data->cfg_flags());
81  }
82 
83  const std::string &WorkerCaps::worker_name() const
84  {
85  return _data->worker_name();
86  }
87 
89  {
90  _data->set_protocol_version(v);
91  }
92 
94  {
95  _data->set_worker_type( static_cast<uint32_t>(t) );
96  }
97 
99  {
100  _data->set_cfg_flags( static_cast<uint32_t>(f) );
101  }
102 
103  void WorkerCaps::set_worker_name(std::string name)
104  {
105  _data->set_worker_name ( std::move(name) );
106  }
107 
108  static ProvideMessage::FieldVal fieldValFromProto ( const zypp::proto::DataField &field )
109  {
111  switch ( field.field_val_case () ) {
112  case zypp::proto::DataField::FieldValCase::kBoolVal:
113  v = field.bool_val();
114  break;
115  case zypp::proto::DataField::FieldValCase::kDoubleVal:
116  v = field.double_val();
117  break;
118  case zypp::proto::DataField::FieldValCase::kIntVal:
119  v = field.int_val();
120  break;
121  case zypp::proto::DataField::FieldValCase::kLongVal:
122  v = field.long_val();
123  break;
124  case zypp::proto::DataField::FieldValCase::kStrVal:
125  v = field.str_val();
126  break;
127  case zypp::proto::DataField::FieldValCase::FIELD_VAL_NOT_SET:
128  ZYPP_THROW( std::logic_error("Unexpected DataField type"));
129  break;
130  }
131  return v;
132  }
133 
134  static void fieldValToProto ( const ProvideMessage::FieldVal &val, zypp::proto::DataField &field )
135  {
136  if ( val.isString() )
137  field.set_str_val( val.asString () );
138  else if ( val.isInt() )
139  field.set_int_val( val.asInt() );
140  else if ( val.isInt64() )
141  field.set_long_val( val.asInt64() );
142  else if ( val.isDouble() )
143  field.set_double_val( val.asDouble() );
144  else if ( val.isBool() )
145  field.set_bool_val( val.asBool() );
146  else
147  ZYPP_THROW( std::logic_error("Unexpected FieldVal type"));
148  }
149 
150  static expected<void> validateMessage ( const ProvideMessage &msg )
151  {
152  const auto c = msg.code();
160  if ( !validCode ) {
161  return zyppng::expected<void>::error( ZYPP_EXCPT_PTR ( InvalidMessageReceivedException("Invalid code in ProvideMessage")) );
162  }
163 
164  #define DEF_REQ_FIELD( fname ) bool has_##fname = false
165 
166  #define REQ_FIELD_CHECK( msgtype, fname, ftype ) \
167  if ( name == #fname ) { \
168  if ( !std::holds_alternative<ftype>(val.asVariant()) ) { \
169  error = ZYPP_EXCPT_PTR( InvalidMessageReceivedException( zypp::str::Str() << "Parse error " << #msgtype << ", Field " << #fname << " has invalid type" ) ); \
170  return false; \
171  } \
172  has_##fname = true; \
173  }
174 
175  #define OR_REQ_FIELD_CHECK( msgtype, fname, ftype ) else REQ_FIELD_CHECK( msgtype, fname, ftype )
176 
177  #define OPT_FIELD_CHECK( msgtype, fname, ftype ) \
178  if ( name == #fname ) { \
179  if ( !std::holds_alternative<ftype>(val.asVariant() ) ) { \
180  error = ZYPP_EXCPT_PTR( InvalidMessageReceivedException( zypp::str::Str() << "Parse error " << #msgtype << ", Field " << #fname << " has invalid type" ) ); \
181  return false; \
182  } \
183  }
184 
185  #define OR_OPT_FIELD_CHECK( msgtype, fname, ftype ) else OPT_FIELD_CHECK( msgtype, fname, ftype )
186 
187  #define FAIL_IF_NOT_SEEN_REQ_FIELD( msgtype, fname ) \
188  if ( !has_##fname ) \
189  return expected<void>::error( ZYPP_EXCPT_PTR( InvalidMessageReceivedException( zypp::str::Str() << #msgtype <<" message does not contain required " << #fname << " field" ) ) )
190 
191  #define FAIL_IF_ERROR( ) \
192  if ( error ) return expected<void>::error( error )
193 
194  const auto &validateErrorMsg = []( const auto &msg ){
195  std::exception_ptr error;
196  DEF_REQ_FIELD(reason);
197  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
198  REQ_FIELD_CHECK ( Error, reason, std::string )
199  OR_OPT_FIELD_CHECK ( Error, history, std::string )
200  OR_OPT_FIELD_CHECK ( Error, transient, bool )
201  return true;
202  });
204  FAIL_IF_ERROR();
205  return expected<void>::success();
206  };
207 
208  switch ( c )
209  {
211  std::exception_ptr error;
212  DEF_REQ_FIELD(url);
213  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
214  REQ_FIELD_CHECK ( ProvideStarted, url, std::string )
215  OR_OPT_FIELD_CHECK ( ProvideStarted, local_filename, std::string )
216  OR_OPT_FIELD_CHECK ( ProvideStarted, staging_filename, std::string )
217  return true;
218  });
220  FAIL_IF_ERROR();
221  break;
222  }
224  std::exception_ptr error;
225  DEF_REQ_FIELD(cacheHit);
226  DEF_REQ_FIELD(local_filename);
227  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
228  REQ_FIELD_CHECK ( ProvideFinished, cacheHit, bool )
229  OR_REQ_FIELD_CHECK ( ProvideFinished, local_filename, std::string )
230  return true;
231  });
233  FAIL_IF_NOT_SEEN_REQ_FIELD( ProvideFinished, local_filename );
234  FAIL_IF_ERROR();
235  break;
236  }
238  std::exception_ptr error;
239  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
240  OPT_FIELD_CHECK ( AttachFinished, local_mountpoint, std::string )
241  return true;
242  });
243  FAIL_IF_ERROR();
244  break;
245  }
247  // no fields
248  break;
249  }
251  std::exception_ptr error;
252  DEF_REQ_FIELD(username);
253  DEF_REQ_FIELD(password);
254  DEF_REQ_FIELD(auth_timestamp);
255  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
256  REQ_FIELD_CHECK ( AuthInfo, username, std::string )
257  OR_REQ_FIELD_CHECK ( AuthInfo, password, std::string )
258  OR_REQ_FIELD_CHECK ( AuthInfo, auth_timestamp, int64_t )
259  OR_OPT_FIELD_CHECK ( AuthInfo, authType, std::string )
260  return true;
261  });
264  FAIL_IF_NOT_SEEN_REQ_FIELD( ProvideStarted, auth_timestamp );
265  FAIL_IF_ERROR();
266  break;
267  }
269  /* No Fields */
270  break;
272  std::exception_ptr error;
273  DEF_REQ_FIELD(new_url);
274  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
275  REQ_FIELD_CHECK ( Redirect, new_url, std::string )
276  return true;
277  });
279  FAIL_IF_ERROR();
280  break;
281  }
283  std::exception_ptr error;
284  DEF_REQ_FIELD(new_url);
285  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
286  REQ_FIELD_CHECK ( Metalink, new_url, std::string )
287  return true;
288  });
290  FAIL_IF_ERROR();
291  break;
292  }
309  const auto &e = validateErrorMsg(msg);
310  if ( !e )
311  return e;
312  break;
313  }
315  std::exception_ptr error;
316  DEF_REQ_FIELD(url);
317  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
318  REQ_FIELD_CHECK ( Provide, url, std::string )
319  OR_OPT_FIELD_CHECK ( Provide, filename, std::string )
320  OR_OPT_FIELD_CHECK ( Provide, delta_file, std::string )
321  OR_OPT_FIELD_CHECK ( Provide, expected_filesize, int64_t )
322  OR_OPT_FIELD_CHECK ( Provide, check_existance_only, bool )
323  OR_OPT_FIELD_CHECK ( Provide, metalink_enabled, bool )
324  return true;
325  });
327  FAIL_IF_ERROR();
328  break;
329  }
331  /* No Fields */
332  break;
333 
335  std::exception_ptr error;
336 
337  DEF_REQ_FIELD(url);
338  DEF_REQ_FIELD(attach_id);
339  DEF_REQ_FIELD(label);
340 
341  // not really required, but this way we can check if all false or all true
342  DEF_REQ_FIELD(verify_type);
343  DEF_REQ_FIELD(verify_data);
344  DEF_REQ_FIELD(media_nr);
345 
346  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
347  REQ_FIELD_CHECK ( Attach, url , std::string )
348  OR_REQ_FIELD_CHECK ( Attach, attach_id , std::string )
349  OR_REQ_FIELD_CHECK ( Attach, label , std::string )
350  OR_REQ_FIELD_CHECK ( Attach, verify_type, std::string )
351  OR_REQ_FIELD_CHECK ( Attach, verify_data, std::string )
352  OR_REQ_FIELD_CHECK ( Attach, media_nr , int32_t )
353  OR_OPT_FIELD_CHECK ( Attach, device , std::string )
354  return true;
355  });
358  FAIL_IF_NOT_SEEN_REQ_FIELD( Provide, attach_id );
359  if ( ! ( ( has_verify_data == has_verify_type ) && ( has_verify_type == has_media_nr ) ) )
360  return expected<void>::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. ")) );
361  FAIL_IF_ERROR();
362  break;
363  }
365  std::exception_ptr error;
366  DEF_REQ_FIELD(url);
367  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
368  REQ_FIELD_CHECK ( Detach, url, std::string )
369  return true;
370  });
372  FAIL_IF_ERROR();
373  break;
374  }
376  std::exception_ptr error;
377  DEF_REQ_FIELD(effective_url);
378  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
379  REQ_FIELD_CHECK ( AuthDataRequest, effective_url, std::string )
380  OR_OPT_FIELD_CHECK ( AuthDataRequest, last_auth_timestamp, int64_t )
381  OR_OPT_FIELD_CHECK ( AuthDataRequest, username, std::string )
382  OR_OPT_FIELD_CHECK ( AuthDataRequest, authHint, std::string )
383  return true;
384  });
386  FAIL_IF_ERROR();
387  break;
388  }
390  std::exception_ptr error;
391  DEF_REQ_FIELD(label);
392  DEF_REQ_FIELD(media_nr);
394  msg.forEachVal( [&]( const auto &name, const ProvideMessage::FieldVal &val ){
395  REQ_FIELD_CHECK ( MediaChangeRequest, label, std::string )
396  OR_REQ_FIELD_CHECK ( MediaChangeRequest, media_nr, int32_t )
398  OR_OPT_FIELD_CHECK ( MediaChangeRequest, desc, std::string )
399  return true;
400  });
404  FAIL_IF_ERROR();
405  break;
406  }
407  default: {
408  // all error messages have the same format
410  const auto &e = validateErrorMsg(msg);
411  if ( !e )
412  return e;
413  }
414  break;
415  }
416  }
417  return expected<void>::success();
418  }
419 
421  : _impl ( new zypp::proto::ProvideMessage )
422  { }
423 
424  ZYPP_IMPL_RPCBASE( ProvideMessage, zypp::proto::ProvideMessage, _impl )
425 
426  expected<zyppng::ProvideMessage> ProvideMessage::create(const RpcMessage &message)
427  {
428  ProvideMessage msg;
429  const auto &res = RpcMessageStream::parseMessageInto<zypp::proto::ProvideMessage>( message, *msg._impl );
430  if ( res ) {
431  const auto &valid = validateMessage(msg);
432  if ( !valid ) {
433  ERR << "Invalid message for ID: " << msg._impl->request_id() << std::endl;;
434  return zyppng::expected<zyppng::ProvideMessage>::error( valid.error() );
435  }
436 
437  return zyppng::expected<zyppng::ProvideMessage>::success( std::move(msg) );
438  }
439  ERR << "Failed to parse message" << std::endl;;
440  return zyppng::expected<zyppng::ProvideMessage>::error( res.error() );
441  }
442 
443  expected<ProvideMessage> ProvideMessage::create( const zypp::proto::ProvideMessage &message )
444  {
445  ProvideMessage msg;
446  *msg._impl = std::move(message);
447  const auto &valid = validateMessage(msg);
448  if ( !valid ) {
449  ERR << "Invalid message for ID: " << msg._impl->request_id() << std::endl;;
450  return zyppng::expected<zyppng::ProvideMessage>::error( valid.error() );
451  }
452 
453  return zyppng::expected<zyppng::ProvideMessage>::success( std::move(msg) );
454  }
455 
456  ProvideMessage ProvideMessage::createProvideStarted( const uint32_t reqId, const zypp::Url &url, const std::optional<std::string> &localFilename, const std::optional<std::string> &stagingFilename )
457  {
458  ProvideMessage msg;
460  msg.setRequestId ( reqId );
462  if ( localFilename )
463  msg.setValue ( ProvideStartedMsgFields::LocalFilename, *localFilename );
464  if ( stagingFilename )
465  msg.setValue ( ProvideStartedMsgFields::StagingFilename, *stagingFilename );
466 
467  return msg;
468  }
469 
470  ProvideMessage ProvideMessage::createProvideFinished( const uint32_t reqId, const std::string &localFilename, bool cacheHit )
471  {
472  ProvideMessage msg;
474  msg.setRequestId ( reqId );
475  msg.setValue ( ProvideFinishedMsgFields::LocalFilename, localFilename );
477 
478  return msg;
479  }
480 
481  ProvideMessage ProvideMessage::createAttachFinished(const uint32_t reqId , const std::optional<std::string> &localMountPoint )
482  {
483  ProvideMessage msg;
485  msg.setRequestId ( reqId );
486 
487  if ( localMountPoint )
488  msg.setValue ( AttachFinishedMsgFields::LocalMountPoint, *localMountPoint );
489 
490  return msg;
491  }
492 
494  {
495  ProvideMessage msg;
497  msg.setRequestId ( reqId );
498 
499  return msg;
500  }
501 
502  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 )
503  {
504  ProvideMessage msg;
506  msg.setRequestId ( reqId );
509  msg.setValue ( AuthInfoMsgFields::AuthTimestamp, timestamp );
510  for ( auto i : extraValues ) {
511  msg.setValue( i.first, i.second );
512  }
513  return msg;
514  }
515 
517  {
518  ProvideMessage msg;
520  msg.setRequestId ( reqId );
521 
522  return msg;
523  }
524 
525  ProvideMessage ProvideMessage::createRedirect( const uint32_t reqId, const zypp::Url &newUrl )
526  {
527  ProvideMessage msg;
529  msg.setRequestId ( reqId );
531 
532  return msg;
533  }
534 
535  ProvideMessage ProvideMessage::createMetalinkRedir( const uint32_t reqId, const std::vector<zypp::Url> &newUrls )
536  {
537  ProvideMessage msg;
539  msg.setRequestId ( reqId );
540  for( const auto &val : newUrls )
541  msg.addValue( MetalinkRedirectMsgFields::NewUrl, val.asCompleteString() );
542 
543  return msg;
544  }
545 
546  ProvideMessage ProvideMessage::createErrorResponse( const uint32_t reqId, const uint code, const std::string &reason, bool transient )
547  {
548  ProvideMessage msg;
549  if ( code < Code::FirstClientErrCode || code > Code::LastSrvErrCode )
550  ZYPP_THROW(std::out_of_range("code must be between 400 and 599"));
551  msg.setCode ( code );
552  msg.setRequestId ( reqId );
553  msg.setValue ( ErrMsgFields::Reason, reason );
554  msg.setValue ( ErrMsgFields::Transient, transient );
555  return msg;
556  }
557 
558  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 )
559  {
560  ProvideMessage msg;
562  msg.setRequestId ( reqId );
564 
565  if ( filename )
566  msg.setValue ( ProvideMsgFields::Filename, *filename );
567  if ( deltaFile )
568  msg.setValue ( ProvideMsgFields::DeltaFile, *deltaFile );
569  if ( expFilesize )
570  msg.setValue ( ProvideMsgFields::ExpectedFilesize, *expFilesize );
571  msg.setValue ( ProvideMsgFields::CheckExistOnly, checkExistOnly );
572 
573  return msg;
574  }
575 
577  {
578  ProvideMessage msg;
580  msg.setRequestId ( reqId );
581 
582  return msg;
583  }
584 
585  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 )
586  {
587  ProvideMessage msg;
589  msg.setRequestId ( reqId );
591  msg.setValue ( AttachMsgFields::AttachId, attachId );
592  msg.setValue ( AttachMsgFields::Label, label );
593 
594  if ( verifyType.has_value() && verifyData.has_value() && mediaNr.has_value() ) {
595  msg.setValue ( AttachMsgFields::VerifyType, *verifyType );
596  msg.setValue ( AttachMsgFields::VerifyData, *verifyData );
597  msg.setValue ( AttachMsgFields::MediaNr, *mediaNr );
598  } else {
599  if ( !( ( verifyType.has_value() == verifyData.has_value() ) && ( verifyData.has_value() == mediaNr.has_value() ) ) )
600  WAR << "Attach message requires verifyType, verifyData and mediaNr either set together or not set at all." << std::endl;
601  }
602 
603  return msg;
604  }
605 
606  ProvideMessage ProvideMessage::createDetach( const uint32_t reqId, const zypp::Url &attachUrl )
607  {
608  ProvideMessage msg;
610  msg.setRequestId ( reqId );
611  msg.setValue ( DetachMsgFields::Url, attachUrl.asCompleteString() );
612 
613  return msg;
614  }
615 
616  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 )
617  {
618  ProvideMessage msg;
620  msg.setRequestId ( reqId );
622  if ( lastTriedUser.size() )
623  msg.setValue( AuthDataRequestMsgFields::LastUser, lastTriedUser );
624  if ( lastAuthTimestamp )
625  msg.setValue ( AuthDataRequestMsgFields::LastAuthTimestamp, *lastAuthTimestamp );
626 
627  return msg;
628  }
629 
630  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 )
631  {
632  ProvideMessage msg;
634  msg.setRequestId ( reqId );
637  for ( const auto &device : devices )
639  if ( desc )
641 
642  return msg;
643  }
644 
646  {
647  return _impl->request_id();
648  }
649 
650  void ProvideMessage::setRequestId(const uint id)
651  {
652  _impl->set_request_id( id );
653  }
654 
655  uint32_t ProvideMessage::code() const
656  {
657  return _impl->message_code();
658  }
659 
660  void ProvideMessage::setCode(const uint32_t newCode )
661  {
662  _impl->set_message_code ( newCode );
663  }
664 
665  std::vector<ProvideMessage::FieldVal> ProvideMessage::values( const std::string_view &str ) const
666  {
667  std::vector<ProvideMessage::FieldVal> values;
668  const auto &fields = _impl->fields();
669  for ( const auto &field : fields ) {
670  if ( field.key() != str )
671  continue;
672  values.push_back( fieldValFromProto(field) );
673  }
674  return values;
675  }
676 
677  std::vector<ProvideMessage::FieldVal> ProvideMessage::values( const std::string &str ) const
678  {
679  return values( std::string_view(str));
680  }
681 
682  ProvideMessage::FieldVal ProvideMessage::value( const std::string_view &str, const FieldVal &defaultVal ) const
683  {
684  const auto &fields = _impl->fields();
685  auto i = std::find_if( fields.rbegin(), fields.rend(), [&str]( const auto &val ){ return val.key() == str; } );
686  if ( i == fields.rend() )
687  return defaultVal;
688  return fieldValFromProto(*i);
689  }
690 
691 
693  {
694  HeaderValueMap res;
695  auto &fields = _impl->fields();
696  for ( const auto &val : fields ) {
697  res.add( val.key() ,fieldValFromProto(val) );
698  }
699  return res;
700  }
701 
702  ProvideMessage::FieldVal ProvideMessage::value( const std::string &str, const FieldVal &defaultVal ) const
703  {
704  return value( std::string_view(str), defaultVal );
705  }
706 
707  void ProvideMessage::setValue( const std::string &name, const FieldVal &value )
708  {
709  setValue( std::string_view(name), value );
710  }
711 
712  void ProvideMessage::setValue( const std::string_view &name, const FieldVal &value )
713  {
714  auto &fields = *_impl->mutable_fields();
715  auto i = std::find_if( fields.rbegin(), fields.rend(), [&name]( const auto &val ){ return val.key() == name; } );
716  if ( i == fields.rend() ) {
717  auto &newVal = *_impl->add_fields();
718  newVal.set_key( name.data() );
719  fieldValToProto( value, newVal );
720  } else
721  fieldValToProto( value, *i );
722  }
723 
724  void ProvideMessage::addValue( const std::string &name, const FieldVal &value )
725  {
726  return addValue( std::string_view(name), value );
727  }
728 
729  void ProvideMessage::addValue( const std::string_view &name, const FieldVal &value )
730  {
731  auto &newVal = *_impl->add_fields();
732  newVal.set_key( name.data() );
733  fieldValToProto( value, newVal );
734  }
735 
736  void ProvideMessage::forEachVal( const std::function<bool (const std::string &, const FieldVal &)> &cb ) const
737  {
738  auto &fields = _impl->fields();
739  for ( const auto &val : fields ) {
740  if ( !cb( val.key(), fieldValFromProto(val) ) ) {
741  return;
742  }
743  }
744  }
745 }
746 
747 namespace zypp {
748  template<>
749  proto::Configuration *rwcowClone<proto::Configuration>(const proto::Configuration *rhs)
750  { return new proto::Configuration( *rhs ); }
751 
752  template<>
753  proto::Capabilities *rwcowClone<proto::Capabilities>(const proto::Capabilities *rhs)
754  { return new proto::Capabilities( *rhs ); }
755 
756  template<>
757  zypp::proto::ProvideMessage* rwcowClone<zypp::proto::ProvideMessage>( const zypp::proto::ProvideMessage * rhs )
758  { return new zypp::proto::ProvideMessage(*rhs); }
759 }
static ProvideMessage createErrorResponse(const uint32_t reqId, const uint code, const std::string &reason, bool transient=false)
void add(const std::string &key, const Value &val)
constexpr std::string_view Url("url")
constexpr std::string_view LocalFilename("local_filename")
const std::string & asString() const
bool isDouble() const
constexpr std::string_view AttachId("attach_id")
static void fieldValToProto(const ProvideMessage::FieldVal &val, zypp::proto::DataField &field)
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition: Exception.h:429
zypp::RWCOW_pointer< zypp::proto::Capabilities > _data
zypp::RWCOW_pointer< zypp::proto::ProvideMessage > _impl
void forEachVal(const std::function< bool(const std::string &name, const FieldVal &val)> &cb) const
constexpr std::string_view VerifyData("verify_data")
static ProvideMessage createMetalinkRedir(const uint32_t reqId, const std::vector< zypp::Url > &newUrls)
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")
static ProvideMessage::FieldVal fieldValFromProto(const zypp::proto::DataField &field)
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={})
HeaderValueMap headers() const
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)
static ProvideMessage createMediaChanged(const uint32_t reqId)
String related utilities and Regular expression matching.
constexpr std::string_view MediaNr("media_nr")
#define FAIL_IF_NOT_SEEN_REQ_FIELD(msgtype, fname)
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:433
void addValue(const std::string &name, const FieldVal &value)
constexpr std::string_view Label("label")
#define FAIL_IF_ERROR()
bool isString() const
#define ERR
Definition: Logger.h:98
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")
int64_t asInt64() const
void set_worker_type(WorkerType t)
constexpr std::string_view CheckExistOnly("check_existance_only")
constexpr std::string_view NewUrl("new_url")
constexpr std::string_view LocalFilename("local_filename")
FieldVal value(const std::string_view &str, const FieldVal &defaultVal=FieldVal()) const
void setCode(const uint32_t newCode)
constexpr std::string_view LastAuthTimestamp("last_auth_timestamp")
std::vector< FieldVal > values(const std::string_view &str) const
constexpr std::string_view Device("device")
constexpr std::string_view Label("label")
uint32_t code() const
#define WAR
Definition: Logger.h:97
std::string asCompleteString() const
Returns a complete string representation of the Url object.
Definition: Url.cc:509
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)
WorkerType worker_type() const
constexpr std::string_view Reason("reason")
static ProvideMessage createRedirect(const uint32_t reqId, const zypp::Url &newUrl)
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")
const std::string & worker_name() const
constexpr std::string_view Transient("transient")
constexpr std::string_view AuthTimestamp("auth_timestamp")
bool deserialize(const std::string &str_r, DownloadMode &result_r)
Definition: DownloadMode.cc:23
#define OR_REQ_FIELD_CHECK(msgtype, fname, ftype)
void setRequestId(const uint id)
bool isInt64() const
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")
int32_t asInt() const
zyppng::ProviderConfiguration Configuration
Definition: provideworker.h:32
static expected< void > validateMessage(const ProvideMessage &msg)
constexpr std::string_view device("device")
constexpr std::string_view StagingFilename("staging_filename")
#define REQ_FIELD_CHECK(msgtype, fname, ftype)
Flags cfg_flags() const
constexpr std::string_view Url("url")
Easy-to use interface to the ZYPP dependency resolver.
Definition: Application.cc:19
static expected< ProvideMessage > create(const zyppng::RpcMessage &message)
constexpr std::string_view Desc("desc")
static ProvideMessage createDetachFinished(const uint32_t reqId)
double asDouble() const
#define OR_OPT_FIELD_CHECK(msgtype, fname, ftype)
constexpr std::string_view CacheHit("cacheHit")
constexpr std::string_view LastUser("username")
Url manipulation class.
Definition: Url.h:91
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")
#define OPT_FIELD_CHECK(msgtype, fname, ftype)