From f74d99c6a78caafdc6e32d8cb135683b7154795c Mon Sep 17 00:00:00 2001 From: David Kalnischkies Date: Sat, 28 May 2016 15:40:59 +0200 Subject: eipp: provide the internal planer as an external one Testing the current implementation can benefit from being able to be feed an EIPP request and produce a fully compliant response. It is also a great test for EIPP in general. --- apt-pkg/edsp/edspindexfile.cc | 37 ++++++++++++++++++++++++++++- apt-pkg/edsp/edspindexfile.h | 13 ++++++++++ apt-pkg/edsp/edsplistparser.cc | 54 ++++++++++++++++++++++++++++++++++++++++++ apt-pkg/edsp/edsplistparser.h | 10 ++++++++ apt-pkg/edsp/edspsystem.cc | 18 ++++++++++++++ apt-pkg/edsp/edspsystem.h | 9 +++++++ 6 files changed, 140 insertions(+), 1 deletion(-) (limited to 'apt-pkg/edsp') diff --git a/apt-pkg/edsp/edspindexfile.cc b/apt-pkg/edsp/edspindexfile.cc index e2863a2cc..042a88cf9 100644 --- a/apt-pkg/edsp/edspindexfile.cc +++ b/apt-pkg/edsp/edspindexfile.cc @@ -69,6 +69,25 @@ pkgCacheListParser * edspIndex::CreateListParser(FileFd &Pkg) return newError ? NULL : Parser; } /*}}}*/ +// EIPP Index /*{{{*/ +eippIndex::eippIndex(std::string const &File) : edspLikeIndex(File) +{ +} +std::string eippIndex::GetComponent() const +{ + return "eipp"; +} +pkgCacheListParser * eippIndex::CreateListParser(FileFd &Pkg) +{ + if (Pkg.IsOpen() == false) + return NULL; + _error->PushToStack(); + pkgCacheListParser * const Parser = new eippListParser(&Pkg); + bool const newError = _error->PendingError(); + _error->MergeWithStack(); + return newError ? NULL : Parser; +} + /*}}}*/ // Index File types for APT /*{{{*/ class APT_HIDDEN edspIFType: public pkgIndexFile::Type @@ -82,12 +101,28 @@ class APT_HIDDEN edspIFType: public pkgIndexFile::Type edspIFType() {Label = "EDSP scenario file";}; }; APT_HIDDEN edspIFType _apt_Edsp; - const pkgIndexFile::Type *edspIndex::GetType() const { return &_apt_Edsp; } + +class APT_HIDDEN eippIFType: public pkgIndexFile::Type +{ + public: + virtual pkgRecords::Parser *CreatePkgParser(pkgCache::PkgFileIterator const &) const APT_OVERRIDE + { + // we don't have a record parser for this type as the file is not presistent + return NULL; + }; + eippIFType() {Label = "EIPP scenario file";}; +}; +APT_HIDDEN eippIFType _apt_Eipp; +const pkgIndexFile::Type *eippIndex::GetType() const +{ + return &_apt_Eipp; +} /*}}}*/ edspLikeIndex::~edspLikeIndex() {} edspIndex::~edspIndex() {} +eippIndex::~eippIndex() {} diff --git a/apt-pkg/edsp/edspindexfile.h b/apt-pkg/edsp/edspindexfile.h index 26bd1232b..e146ca80c 100644 --- a/apt-pkg/edsp/edspindexfile.h +++ b/apt-pkg/edsp/edspindexfile.h @@ -46,4 +46,17 @@ public: virtual ~edspIndex(); }; +class APT_HIDDEN eippIndex : public edspLikeIndex +{ +protected: + APT_HIDDEN virtual pkgCacheListParser * CreateListParser(FileFd &Pkg) APT_OVERRIDE; + virtual std::string GetComponent() const APT_OVERRIDE; + +public: + virtual const Type *GetType() const APT_OVERRIDE APT_CONST; + + eippIndex(std::string const &File); + virtual ~eippIndex(); +}; + #endif diff --git a/apt-pkg/edsp/edsplistparser.cc b/apt-pkg/edsp/edsplistparser.cc index 39a6e8a6e..dd8890f0e 100644 --- a/apt-pkg/edsp/edsplistparser.cc +++ b/apt-pkg/edsp/edsplistparser.cc @@ -125,5 +125,59 @@ bool edspListParser::ParseStatus(pkgCache::PkgIterator &Pkg, } /*}}}*/ +// ListParser::eippListParser - Constructor /*{{{*/ +eippListParser::eippListParser(FileFd *File) : edspLikeListParser(File) +{ +} + /*}}}*/ +// ListParser::ParseStatus - Parse the status field /*{{{*/ +// --------------------------------------------------------------------- +/* The Status: line here is not a normal dpkg one but just one which tells + use if the package is installed or not, where missing means not. */ +bool eippListParser::ParseStatus(pkgCache::PkgIterator &Pkg, + pkgCache::VerIterator &Ver) +{ + // Process the flag field + static std::array const statusvalues = {{ + {"not-installed",pkgCache::State::NotInstalled}, + {"config-files",pkgCache::State::ConfigFiles}, + {"half-installed",pkgCache::State::HalfInstalled}, + {"unpacked",pkgCache::State::UnPacked}, + {"half-configured",pkgCache::State::HalfConfigured}, + {"triggers-awaited",pkgCache::State::TriggersAwaited}, + {"triggers-pending",pkgCache::State::TriggersPending}, + {"installed",pkgCache::State::Installed}, + }}; + auto const status = Section.Find("Status"); + if (status.empty() == false) + { + for (auto && sv: statusvalues) + { + if (status != sv.Str) + continue; + Pkg->CurrentState = sv.Val; + switch (Pkg->CurrentState) + { + case pkgCache::State::NotInstalled: + case pkgCache::State::ConfigFiles: + break; + case pkgCache::State::HalfInstalled: + case pkgCache::State::UnPacked: + case pkgCache::State::HalfConfigured: + case pkgCache::State::TriggersAwaited: + case pkgCache::State::TriggersPending: + case pkgCache::State::Installed: + Pkg->CurrentVer = Ver.Index(); + break; + } + break; + } + } + + return true; +} + /*}}}*/ + edspLikeListParser::~edspLikeListParser() {} edspListParser::~edspListParser() {} +eippListParser::~eippListParser() {} diff --git a/apt-pkg/edsp/edsplistparser.h b/apt-pkg/edsp/edsplistparser.h index 7cd5ab2b3..84138d6a8 100644 --- a/apt-pkg/edsp/edsplistparser.h +++ b/apt-pkg/edsp/edsplistparser.h @@ -51,4 +51,14 @@ public: edspListParser(FileFd *File); virtual ~edspListParser(); }; + +class APT_HIDDEN eippListParser : public edspLikeListParser +{ +protected: + virtual bool ParseStatus(pkgCache::PkgIterator &Pkg,pkgCache::VerIterator &Ver) APT_OVERRIDE; + +public: + eippListParser(FileFd *File); + virtual ~eippListParser(); +}; #endif diff --git a/apt-pkg/edsp/edspsystem.cc b/apt-pkg/edsp/edspsystem.cc index 2a78efe58..b0e7b8a21 100644 --- a/apt-pkg/edsp/edspsystem.cc +++ b/apt-pkg/edsp/edspsystem.cc @@ -34,6 +34,9 @@ edspLikeSystem::edspLikeSystem(char const * const Label) : pkgSystem(Label, &deb } edspSystem::edspSystem() : edspLikeSystem("Debian APT solver interface") { +} +eippSystem::eippSystem() : edspLikeSystem("Debian APT planer interface") +{ } /*}}}*/ // System::Lock - Get the lock /*{{{*/ @@ -134,6 +137,19 @@ bool edspSystem::AddStatusFiles(std::vector &List) /*{{{*/ return true; } /*}}}*/ +bool eippSystem::AddStatusFiles(std::vector &List) /*{{{*/ +{ + if (StatusFile == nullptr) + { + if (_config->Find("eipp::scenario", "") == "/nonexistent/stdin") + StatusFile.reset(new eippIndex("/nonexistent/stdin")); + else + StatusFile.reset(new eippIndex(_config->FindFile("eipp::scenario"))); + } + List.push_back(StatusFile.get()); + return true; +} + /*}}}*/ edspLikeSystem::~edspLikeSystem() {} edspSystem::~edspSystem() @@ -145,5 +161,7 @@ edspSystem::~edspSystem() RemoveFile("~edspSystem", tempPrefsFile); rmdir(tempDir.c_str()); } +eippSystem::~eippSystem() {} APT_HIDDEN edspSystem edspSys; +APT_HIDDEN eippSystem eippSys; diff --git a/apt-pkg/edsp/edspsystem.h b/apt-pkg/edsp/edspsystem.h index 2c429c3d6..c0c9526b5 100644 --- a/apt-pkg/edsp/edspsystem.h +++ b/apt-pkg/edsp/edspsystem.h @@ -57,4 +57,13 @@ public: virtual ~edspSystem(); }; +class APT_HIDDEN eippSystem : public edspLikeSystem +{ + public: + virtual bool AddStatusFiles(std::vector &List) APT_OVERRIDE; + + eippSystem(); + virtual ~eippSystem(); +}; + #endif -- cgit v1.2.3