libzypp  17.37.5
providemessage_p.h
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \----------------------------------------------------------------------/
9 *
10 * This file contains private API, this might break at any time between releases.
11 * You have been warned!
12 */
13 #ifndef ZYPP_MEDIA_PRIVATE_PROVIDE_MESSAGE_P_H_INCLUDED
14 #define ZYPP_MEDIA_PRIVATE_PROVIDE_MESSAGE_P_H_INCLUDED
15 
18 
291 #include <zypp-core/base/PtrTypes.h>
292 #include <zypp-core/zyppng/pipelines/Expected>
294 #include <zypp-media/ng/ProvideSpec> // for FieldType
295 #include <zypp-media/ng/HeaderValueMap>
296 
297 #include <boost/iterator/iterator_adaptor.hpp>
298 
299 namespace zypp::proto {
300  class Envelope;
301  class Configuration;
302  class Capabilities;
303  class ProvideMessage;
304 }
305 
306 namespace zyppng {
307 
308  enum MessageCodes : uint32_t {
309  NoCode = 0,
313 
317  AuthInfo = 202,
321 
323  Redirect = 300,
324  Metalink = 301,
326 
328  BadRequest = 400,
330  Forbidden = 402,
332  NotFound = 404,
335  Timeout = 407,
336  Cancelled = 408,
338  MountFailed = 410,
339  Jammed = 411,
342  NoAuthData = 414,
343  NotAFile = 415,
346 
351 
353  Prov = 600,
354  Cancel = 601,
355  Attach = 602,
356  Detach = 603,
358 
363  };
364 
365  class ProviderConfiguration : public std::map<std::string, std::string>
366  {
367  public:
368  using map::map;
369 
370  static constexpr std::string_view typeName = "ProviderConfiguration";
373  };
374 
376  {
377  public:
379  enum WorkerType : uint32_t {
380  Invalid = 0,
384  CPUBound = 4,
385  };
386 
387  enum Flags : uint32_t {
388  None = 0, // Just for completeness
389  SingleInstance = 1, // If this flag is set a worker can only be started once, this is implicit in some worker types.
390  Pipeline = 2, // The worker can handle multiple requests at the same time
391  ZyppLogFormat = 4, // The worker writes messages to stderr in zypp log format
392  FileArtifacts = 8, // The results of this worker are artifacts, which means they need to be cleaned up. This is implicit for all downloading workers. For all mounting workers this is ignored.
393  // CPU bound workers can use it to signal they leave artifact files behind that need to be cleaned up
394  };
395 
396  explicit WorkerCaps();
397  ~WorkerCaps();
398 
399  WorkerCaps(const WorkerCaps &) = default;
400  WorkerCaps(WorkerCaps &&) = default;
401  WorkerCaps &operator=(const WorkerCaps &) = default;
402  WorkerCaps &operator=(WorkerCaps &&) = default;
403 
404  uint32_t protocol_version() const; // The workers should set this field to the protocol version they implement.
405  WorkerType worker_type() const;
406  Flags cfg_flags() const;
407  const std::string &worker_name() const;
408 
409  void set_protocol_version( uint32_t v );
410  void set_worker_type( WorkerType t );
411  void set_cfg_flags( Flags f );
412  void set_worker_name( std::string name );
413 
414  static constexpr std::string_view typeName = "WorkerCaps";
417 
418  private:
419  uint32_t _protocolVersion = 1;
420  uint32_t _workerType = Invalid;
421  uint32_t _cfgFlags = None;
422  std::string _workerName;
423  };
424 
425  namespace ProvideMessageFields {
426  constexpr std::string_view RequestCode("requestCode");
427  constexpr std::string_view RequestId("requestId");
428  }
429 
430  namespace ProvideStartedMsgFields
431  {
432  constexpr std::string_view Url ("url");
433  constexpr std::string_view LocalFilename ("local_filename");
434  constexpr std::string_view StagingFilename ("staging_filename");
435  }
436 
437  namespace ProvideFinishedMsgFields
438  {
439  constexpr std::string_view LocalFilename ("local_filename");
440  constexpr std::string_view CacheHit ("cacheHit");
441  }
442 
443  namespace AuthInfoMsgFields
444  {
445  constexpr std::string_view Username ("username");
446  constexpr std::string_view Password ("password");
447  constexpr std::string_view AuthTimestamp ("auth_timestamp");
448  constexpr std::string_view AuthType ("authType");
449  }
450 
451  namespace RedirectMsgFields
452  {
453  constexpr std::string_view NewUrl ("new_url");
454  }
455 
456  namespace MetalinkRedirectMsgFields
457  {
458  constexpr std::string_view NewUrl ("new_url");
459  }
460 
461  namespace ErrMsgFields
462  {
463  constexpr std::string_view Reason ("reason");
464  constexpr std::string_view Transient ("transient");
465  constexpr std::string_view History ("history");
466  }
467 
468  namespace ProvideMsgFields
469  {
470  constexpr std::string_view Url ("url");
471  constexpr std::string_view Filename ("filename");
472  constexpr std::string_view DeltaFile ("delta_file");
473  constexpr std::string_view ExpectedFilesize ("expected_filesize");
474  constexpr std::string_view CheckExistOnly ("check_existance_only");
475  constexpr std::string_view MetalinkEnabled ("metalink_enabled");
476  }
477 
478  namespace AttachMsgFields
479  {
480  constexpr std::string_view Url ("url");
481  constexpr std::string_view AttachId ("attach_id");
482  constexpr std::string_view VerifyType ("verify_type");
483  constexpr std::string_view VerifyData ("verify_data");
484  constexpr std::string_view MediaNr ("media_nr");
485  constexpr std::string_view Device ("device");
486  constexpr std::string_view Label ("label");
487  }
488 
489  namespace AttachFinishedMsgFields
490  {
491  constexpr std::string_view LocalMountPoint ("local_mountpoint");
492  }
493 
494  namespace DetachMsgFields
495  {
496  constexpr std::string_view Url ("url");
497  }
498 
499  namespace AuthDataRequestMsgFields
500  {
501  constexpr std::string_view EffectiveUrl ("effective_url");
502  constexpr std::string_view LastAuthTimestamp ("last_auth_timestamp");
503  constexpr std::string_view LastUser ("username");
504  constexpr std::string_view AuthHint ("authHint");
505  }
506 
507  namespace MediaChangeRequestMsgFields
508  {
509  constexpr std::string_view Label ("label");
510  constexpr std::string_view MediaNr ("media_nr");
511  constexpr std::string_view Device ("device");
512  constexpr std::string_view Desc ("desc");
513  }
514 
515  namespace EjectMsgFields
516  {
517  constexpr std::string_view device ("device");
518  }
519 
521  {
522  public:
524 
525  ProvideMessage(const ProvideMessage &) = default;
526  ProvideMessage(ProvideMessage &&) = default;
527  ProvideMessage &operator=(const ProvideMessage &) = default;
528  ProvideMessage &operator=(ProvideMessage &&) = default;
530 
531  static constexpr std::string_view typeName = "ProvideMessage";
532 
533  static expected<ProvideMessage> create ( const zypp::PluginFrame &message );
536 
537  static ProvideMessage createProvideStarted ( const uint32_t reqId, const zypp::Url &url , const std::optional<std::string> &localFilename = {}, const std::optional<std::string> &stagingFilename = {} );
538  static ProvideMessage createProvideFinished ( const uint32_t reqId, const std::string &localFilename , bool cacheHit );
539  static ProvideMessage createAttachFinished ( const uint32_t reqId, const std::optional<std::string> &localMountPoint = {} );
540  static ProvideMessage createDetachFinished ( const uint32_t reqId );
541  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 = {} );
542  static ProvideMessage createMediaChanged ( const uint32_t reqId );
543  static ProvideMessage createRedirect ( const uint32_t reqId, const zypp::Url &newUrl );
544  static ProvideMessage createMetalinkRedir ( const uint32_t reqId, const std::vector<zypp::Url> &newUrls );
545  static ProvideMessage createErrorResponse (const uint32_t reqId, const Code code, const std::string &reason, bool transient = false );
546 
547  static ProvideMessage createProvide ( const uint32_t reqId
548  , const zypp::Url &url
549  , const std::optional<std::string> &filename = {}
550  , const std::optional<std::string> &deltaFile = {}
551  , const std::optional<int64_t> &expFilesize = {}
552  , bool checkExistOnly = false );
553 
554  static ProvideMessage createCancel ( const uint32_t reqId );
555 
556  static ProvideMessage createAttach( const uint32_t reqId
557  , const zypp::Url &url
558  , const std::string attachId
559  , const std::string &label
560  , const std::optional<std::string> &verifyType = {}
561  , const std::optional<std::string> &verifyData = {}
562  , const std::optional<int32_t> &mediaNr = {} );
563 
564  static ProvideMessage createDetach ( const uint32_t reqId, const zypp::Url &attachUrl );
565  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 = {} );
566  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 );
567 
568  uint requestId () const;
569  void setRequestId ( const uint id );
570 
571  Code code() const;
572  void setCode (const Code newCode );
573 
574  const std::vector<ProvideMessage::FieldVal> &values ( const std::string_view &str ) const;
575  const std::vector<ProvideMessage::FieldVal> &values ( const std::string &str ) const;
576  const HeaderValueMap &headers() const;
581  FieldVal value ( const std::string_view &str, const FieldVal &defaultVal = FieldVal() ) const;
582  FieldVal value ( const std::string &str, const FieldVal &defaultVal = FieldVal() ) const;
583  void setValue ( const std::string &name, const FieldVal &value );
584  void setValue ( const std::string_view &name, const FieldVal &value );
585  void addValue ( const std::string &name, const FieldVal &value );
586  void addValue ( const std::string_view &name, const FieldVal &value );
587 
588  private:
589  ProvideMessage();
590  uint _reqId = -1;
593  };
594 }
595 
596 #endif
WorkerCaps & operator=(const WorkerCaps &)=default
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")
Container of Capability (currently read only).
Definition: Capabilities.h:35
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")
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={})
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")
static ProvideMessage createErrorResponse(const uint32_t reqId, const Code code, const std::string &reason, bool transient=false)
constexpr std::string_view VerifyType("verify_type")
void addValue(const std::string &name, const FieldVal &value)
constexpr std::string_view RequestCode("requestCode")
constexpr std::string_view Label("label")
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")
constexpr std::string_view Device("device")
static zyppng::expected< ProviderConfiguration > fromStompMessage(const zypp::PluginFrame &msg)
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 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)
constexpr std::string_view LastAuthTimestamp("last_auth_timestamp")
zyppng::expected< zypp::PluginFrame > toStompMessage() const
constexpr std::string_view Device("device")
constexpr std::string_view Label("label")
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
constexpr std::string_view AuthHint("authHint")
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")
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
constexpr std::string_view AuthTimestamp("auth_timestamp")
void setRequestId(const uint id)
static ProvideMessage createCancel(const uint32_t reqId)
constexpr std::string_view Url("url")
constexpr std::string_view LocalMountPoint("local_mountpoint")
constexpr std::string_view AuthType("authType")
static ProvideMessage createProvideFinished(const uint32_t reqId, const std::string &localFilename, bool cacheHit)
constexpr std::string_view Url("url")
zyppng::ProviderConfiguration Configuration
Definition: provideworker.h:31
constexpr std::string_view MetalinkEnabled("metalink_enabled")
constexpr std::string_view History("history")
constexpr std::string_view device("device")
constexpr std::string_view StagingFilename("staging_filename")
ProvideMessage & operator=(const ProvideMessage &)=default
Flags cfg_flags() const
constexpr std::string_view Url("url")
static constexpr std::string_view typeName
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")