22 for (
const auto &v : *
this ) {
23 frame.addHeader( v.first, v.second );
36 res.insert_or_assign ( i->first, i->second );
131 template <
typename T>
136 t.
addValue( name, std::move(tVal) );
154 if ( codeStr.empty () ) {
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 );
171 if ( idStr.empty () ) {
184 #define DEF_REQ_FIELD( fname ) bool has_##fname = false
186 #define PARSE_FIELD( msgtype, fname, ftype, _C_ ) \
187 if ( name == #fname ) { \
188 const auto &res = doParseField<ftype>( val, pMessage, #msgtype, #fname ); \
190 return zyppng::expected<ProvideMessage>::error(res.error()); \
195 #define HANDLE_UNKNOWN_FIELD( fname, val ) { \
196 pMessage.addValue( fname, val ); \
199 #define OR_HANDLE_UNKNOWN_FIELD( fname, val ) else HANDLE_UNKNOWN_FIELD( fname, val )
201 #define BEGIN_PARSE_HEADERS \
202 for ( const auto &header : msg.headerList() ) { \
203 const auto &name = header.first; \
204 const auto &val = header.second;
206 #define END_PARSE_HEADERS }
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 )
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" ) ) )
217 auto validateErrorMsg = [&](
const auto &msg ){
231 case ProvideMessage::Code::ProvideStarted: {
242 case ProvideMessage::Code::ProvideFinished: {
254 case ProvideMessage::Code::AttachFinished: {
261 case ProvideMessage::Code::DetachFinished: {
268 case ProvideMessage::Code::AuthInfo: {
284 case ProvideMessage::Code::MediaChanged:
291 case ProvideMessage::Code::Redirect: {
300 case ProvideMessage::Code::Metalink: {
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);
327 case ProvideMessage::Code::Prov: {
341 case ProvideMessage::Code::Cancel:
348 case ProvideMessage::Code::Attach: {
349 std::exception_ptr error;
373 if ( ! ( ( has_verify_data == has_verify_type ) && ( has_verify_type == has_media_nr ) ) )
378 case ProvideMessage::Code::Detach: {
388 case ProvideMessage::Code::AuthDataRequest: {
401 case ProvideMessage::Code::MediaChangeRequest: {
420 if ( c >= ProvideMessage::Code::FirstClientErrCode && c <= ProvideMessage::Code::LastSrvErrCode ) {
421 return validateErrorMsg(msg);
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();
443 }, val.asVariant() );
444 if ( strVal.empty () )
461 msg.
setCode ( ProvideMessage::Code::ProvideStarted );
466 if ( stagingFilename )
475 msg.
setCode ( ProvideMessage::Code::ProvideFinished );
486 msg.
setCode ( ProvideMessage::Code::AttachFinished );
489 if ( localMountPoint )
498 msg.
setCode ( ProvideMessage::Code::DetachFinished );
507 msg.
setCode ( ProvideMessage::Code::AuthInfo );
512 for (
const auto& i : extraValues ) {
521 msg.
setCode ( ProvideMessage::Code::MediaChanged );
530 msg.
setCode ( ProvideMessage::Code::Redirect );
540 msg.
setCode ( ProvideMessage::Code::Metalink );
542 for(
const auto &val : newUrls )
552 ZYPP_THROW(std::out_of_range(
"code must be between 400 and 599"));
563 msg.
setCode ( ProvideMessage::Code::Prov );
581 msg.
setCode ( ProvideMessage::Code::Cancel );
590 msg.
setCode ( ProvideMessage::Code::Attach );
596 if ( verifyType.has_value() && verifyData.has_value() && mediaNr.has_value() ) {
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;
611 msg.
setCode ( ProvideMessage::Code::Detach );
621 msg.
setCode ( ProvideMessage::Code::AuthDataRequest );
624 if ( lastTriedUser.size() )
626 if ( lastAuthTimestamp )
635 msg.
setCode ( ProvideMessage::Code::MediaChangeRequest );
639 for (
const auto &device : devices )
689 return value( std::string_view(
str), defaultVal );
Base class for Exception.
Command frame for communication with PluginScript.
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)
std::string asCompleteString() const
Returns a complete string representation of the Url object.
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
uint32_t _protocolVersion
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)
typename decay< T >::type decay_t
String related utilities and Regular expression matching.
const std::string & asString(const std::string &t)
Global asString() that works with std::string too.
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 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)
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...
#define ZYPP_CAUGHT(EXCPT)
Drops a logline telling the Exception was caught (in order to handle it).
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.