14 #include <string_view> 21 auto frame = rpc::prepareFrame<ProviderConfiguration>();
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 () ) {
158 const auto c = zyppng::str::safe_strtonum<uint32_t>( codeStr ).value_or (
NoCode );
171 if ( idStr.empty () ) {
175 const auto &maybeId = zyppng::str::safe_strtonum<uint>( idStr );
181 pMessage.
setCode ( static_cast<MessageCodes>(c) );
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 ){
325 return validateErrorMsg(msg);
349 std::exception_ptr error;
373 if ( ! ( ( has_verify_data == has_verify_type ) && ( has_verify_type == has_media_nr ) ) )
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 () )
466 if ( stagingFilename )
489 if ( localMountPoint )
512 for (
auto i : extraValues ) {
542 for(
const auto &val : newUrls )
552 ZYPP_THROW(std::out_of_range(
"code must be between 400 and 599"));
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 )
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;
624 if ( lastTriedUser.size() )
626 if ( lastAuthTimestamp )
639 for (
const auto &
device : devices )
689 return value( std::string_view(
str), defaultVal );
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.
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.
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.
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.
#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.
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.
constexpr std::string_view VerifyType("verify_type")
#define ZYPP_EXCPT_PTR(EXCPT)
Drops a logline and returns Exception as a std::exception_ptr.
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
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd)
#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)
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)
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...
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 Label("label")
std::string asCompleteString() const
Returns a complete string representation of the Url object.
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)
uint32_t _protocolVersion
zyppng::expected< zypp::PluginFrame > toStompMessage() const
WorkerType worker_type() const
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
constexpr std::string_view Reason("reason")
static ProvideMessage createRedirect(const uint32_t reqId, const zypp::Url &newUrl)
static expected success(ConsParams &&...params)
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).
constexpr std::string_view AuthTimestamp("auth_timestamp")
void setRequestId(const uint id)
Base class for Exception.
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
#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
expected< zypp::PluginFrame > toStompMessage() const
static ProvideMessage createDetachFinished(const uint32_t reqId)
constexpr std::string_view CacheHit("cacheHit")
constexpr std::string_view LastUser("username")
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")