From d4a6fc2f08851e460e94c5a0c0dc310daee70537 Mon Sep 17 00:00:00 2001 From: Jiri Srain Date: Thu, 1 Dec 2005 13:27:12 +0000 Subject: [PATCH] added parser for patches.xml file (all available patches) --- zypp/parser/yum/Makefile.am | 2 + zypp/parser/yum/YUMParser.h | 1 + zypp/parser/yum/YUMParserData.cc | 12 +++++ zypp/parser/yum/YUMParserData.h | 13 ++++++ zypp/parser/yum/YUMPatchesParser.cc | 88 +++++++++++++++++++++++++++++++++++++ zypp/parser/yum/YUMPatchesParser.h | 64 +++++++++++++++++++++++++++ zypp/parser/yum/schema/patches.rnc | 16 +++++++ zypp/parser/yum/schema/patches.rng | 29 ++++++++++++ zypp/parser/yum/schema/product.rng | 33 ++++++++++++++ zypp/parser/yum/schema/repomd.rnc | 2 +- zypp/parser/yum/schema/repomd.rng | 3 ++ zypp/parser/yum/schemanames.h | 1 + 12 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 zypp/parser/yum/YUMPatchesParser.cc create mode 100644 zypp/parser/yum/YUMPatchesParser.h create mode 100644 zypp/parser/yum/schema/patches.rnc create mode 100644 zypp/parser/yum/schema/patches.rng diff --git a/zypp/parser/yum/Makefile.am b/zypp/parser/yum/Makefile.am index d2eef82..685c5df 100644 --- a/zypp/parser/yum/Makefile.am +++ b/zypp/parser/yum/Makefile.am @@ -15,6 +15,7 @@ include_HEADERS = \ YUMGroupParser.h \ YUMParserData.h \ YUMPatchParser.h \ + YUMPatchesParser.h \ YUMProductParser.h \ YUMRepomdParser.h \ schemanames.h @@ -30,6 +31,7 @@ lib@PACKAGE@_parser_yum_la_SOURCES = \ YUMRepomdParser.cc \ YUMGroupParser.cc \ YUMPatchParser.cc \ + YUMPatchesParser.cc \ YUMOtherParser.cc \ YUMPrimaryParser.cc \ YUMProductParser.cc diff --git a/zypp/parser/yum/YUMParser.h b/zypp/parser/yum/YUMParser.h index d7c0c6f..3da2096 100644 --- a/zypp/parser/yum/YUMParser.h +++ b/zypp/parser/yum/YUMParser.h @@ -21,6 +21,7 @@ #include "zypp/parser/yum/YUMFileListParser.h" #include "zypp/parser/yum/YUMOtherParser.h" #include "zypp/parser/yum/YUMPatchParser.h" +#include "zypp/parser/yum/YUMPatchesParser.h" #include "zypp/parser/yum/YUMProductParser.h" #endif diff --git a/zypp/parser/yum/YUMParserData.cc b/zypp/parser/yum/YUMParserData.cc index 0d8dd30..b24b5ca 100644 --- a/zypp/parser/yum/YUMParserData.cc +++ b/zypp/parser/yum/YUMParserData.cc @@ -121,6 +121,7 @@ namespace zypp { IMPL_PTR_TYPE(YUMFileListData); IMPL_PTR_TYPE(YUMOtherData); IMPL_PTR_TYPE(YUMPatchData); + IMPL_PTR_TYPE(YUMPatchesData); IMPL_PTR_TYPE(YUMProductData); IMPL_PTR_TYPE(YUMPatchPackage); IMPL_PTR_TYPE(YUMPatchScript); @@ -370,6 +371,17 @@ ostream& operator<<(ostream &out, const YUMPatchData& data) return out; } +ostream& operator<<(ostream &out, const YUMPatchesData& data) +{ + out << "-------------------------------------------------" << endl + << "Patches Entry Data: " << endl + << " patch ID: " << data.id << endl + << " location: " << data.location << endl + << " checksumType: '" << data.checksumType << "'" << endl + << " checksum: '" << data.checksum << "'" << endl; + return out; +} + ostream& operator<<(ostream &out, const YUMProductData& data) { out << "-------------------------------------------------" << endl diff --git a/zypp/parser/yum/YUMParserData.h b/zypp/parser/yum/YUMParserData.h index 265e9ec..e8a7042 100644 --- a/zypp/parser/yum/YUMParserData.h +++ b/zypp/parser/yum/YUMParserData.h @@ -39,6 +39,7 @@ namespace zypp { DEFINE_PTR_TYPE( YUMFileListData ); DEFINE_PTR_TYPE( YUMOtherData ); DEFINE_PTR_TYPE( YUMPatchData ); + DEFINE_PTR_TYPE( YUMPatchesData ); DEFINE_PTR_TYPE( YUMProductData ); DEFINE_PTR_TYPE( YUMPatchPackage ); DEFINE_PTR_TYPE( YUMPatchScript ); @@ -395,6 +396,17 @@ namespace zypp { std::list > atoms; }; + class YUMPatchesData : public base::ReferenceCounted, private base::NonCopyable { + public: + YUMPatchesData() {}; + ~YUMPatchesData() {}; + + std::string location; + std::string id; + std::string checksumType; + std::string checksum; + }; + class YUMProductData : public YUMObjectData { public: YUMProductData() {}; @@ -429,6 +441,7 @@ std::ostream& operator<<(std::ostream &out, const zypp::parser::yum::YUMGroupDat std::ostream& operator<<(std::ostream &out, const zypp::parser::yum::YUMFileListData& data); std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMOtherData& data); std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchData& data); +std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchesData& data); std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMProductData& data); std::ostream& operator<<(std::ostream& out, const shared_ptr data); std::ostream& operator<<(std::ostream& out, const zypp::parser::yum::YUMPatchMessage& data); diff --git a/zypp/parser/yum/YUMPatchesParser.cc b/zypp/parser/yum/YUMPatchesParser.cc new file mode 100644 index 0000000..50f20d5 --- /dev/null +++ b/zypp/parser/yum/YUMPatchesParser.cc @@ -0,0 +1,88 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/parser/yum/YUMPatchesParser.cc + * +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace std; +namespace zypp { + namespace parser { + namespace yum { + + YUMPatchesParser::~YUMPatchesParser() + { } + + YUMPatchesParser::YUMPatchesParser(istream &is, const string& baseUrl) + : XMLNodeIterator(is, baseUrl,PATCHESSCHEMA) + { + fetchNext(); + } + + YUMPatchesParser::YUMPatchesParser() + { } + + YUMPatchesParser::YUMPatchesParser(YUMPatchesData_Ptr& entry) + : XMLNodeIterator(entry) + { } + + + // select for which elements process() will be called + bool + YUMPatchesParser::isInterested(const xmlNodePtr nodePtr) + { + return _helper.isElement(nodePtr) && _helper.name(nodePtr) == "patch"; + } + + // do the actual processing + YUMPatchesData_Ptr + YUMPatchesParser::process(const xmlTextReaderPtr reader) + { + assert(reader); + YUMPatchesData_Ptr patchPtr = new YUMPatchesData; + xmlNodePtr dataNode = xmlTextReaderExpand(reader); + assert(dataNode); + + patchPtr->id = _helper.attribute(dataNode,"id"); + + for (xmlNodePtr child = dataNode->children; + child && child != dataNode; + child = child->next) { + if (_helper.isElement(child)) { + string name = _helper.name(child); + if (name == "location") { + patchPtr->location = _helper.attribute(child,"href"); + } + else if (name == "checksum") { + patchPtr->checksumType = _helper.attribute(child,"type"); + patchPtr->checksum = _helper.content(child); + } + else { + WAR << "YUM contains the unknown element <" << name << "> " + << _helper.positionInfo(child) << ", skipping" << endl; + } + } + } + return patchPtr; + } /* end process */ + + + } // namespace yum + } // namespace parser +} // namespace zypp diff --git a/zypp/parser/yum/YUMPatchesParser.h b/zypp/parser/yum/YUMPatchesParser.h new file mode 100644 index 0000000..9d35683 --- /dev/null +++ b/zypp/parser/yum/YUMPatchesParser.h @@ -0,0 +1,64 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/parser/yum/YUMPatchesParser.h + * +*/ + + + +#ifndef YUMPatchesParser_h +#define YUMPatchesParser_h + +#include +#include +#include +#include + +namespace zypp { + namespace parser { + namespace yum { + + /** + * @short Parser for YUM primary.xml files (containing package metadata) + * Use this class as an iterator that produces, one after one, + * YUMPatchesData_Ptr(s) for the XML package elements in the input. + * Here's an example: + * + * for (YUMPatchesParser iter(anIstream, baseUrl), + * iter != YUMOtherParser.end(), // or: iter() != 0, or ! iter.atEnd() + * ++iter) { + * doSomething(*iter) + * } + * + * The iterator owns the pointer (i.e., caller must not delete it) + * until the next ++ operator is called. At this time, it will be + * destroyed (and a new ENTRYTYPE is created.) + * + * If the input is fundamentally flawed so that it makes no sense to + * continue parsing, XMLNodeIterator will log it and consider the input as finished. + * You can query the exit status with errorStatus(). + */ + class YUMPatchesParser : public XMLNodeIterator + { + public: + YUMPatchesParser(std::istream &is, const std::string &baseUrl); + YUMPatchesParser(); + YUMPatchesParser(YUMPatchesData_Ptr& entry); + virtual ~YUMPatchesParser(); + + private: + virtual bool isInterested(const xmlNodePtr nodePtr); + virtual YUMPatchesData_Ptr process(const xmlTextReaderPtr reader); + LibXMLHelper _helper; + }; + } // namespace yum + } // namespace parser +} // namespace zypp + +#endif diff --git a/zypp/parser/yum/schema/patches.rnc b/zypp/parser/yum/schema/patches.rnc new file mode 100644 index 0000000..2be9b2a --- /dev/null +++ b/zypp/parser/yum/schema/patches.rnc @@ -0,0 +1,16 @@ +default namespace = "http://novell.com/package/metadata/suse/patches" + +element patches + { + element patch { + attribute id { text }& + element location { + attribute xml:base { xsd:anyURI }?, + attribute href { xsd:anyURI } + }& + element checksum { + attribute type { "md5" | "sha" }, + text + } + }* +} diff --git a/zypp/parser/yum/schema/patches.rng b/zypp/parser/yum/schema/patches.rng new file mode 100644 index 0000000..725176f --- /dev/null +++ b/zypp/parser/yum/schema/patches.rng @@ -0,0 +1,29 @@ + + + + + + + + + + + + + + + + + + + + md5 + sha + + + + + + + + diff --git a/zypp/parser/yum/schema/product.rng b/zypp/parser/yum/schema/product.rng index 730cffb..35ad5e7 100644 --- a/zypp/parser/yum/schema/product.rng +++ b/zypp/parser/yum/schema/product.rng @@ -69,6 +69,17 @@ + + + package + patch + script + message + product + + + + EQ @@ -97,6 +108,17 @@ + + + package + patch + script + message + product + + + + EQ @@ -124,6 +146,17 @@ + + + package + patch + script + message + product + + + + EQ diff --git a/zypp/parser/yum/schema/repomd.rnc b/zypp/parser/yum/schema/repomd.rnc index b798416..2adde87 100644 --- a/zypp/parser/yum/schema/repomd.rnc +++ b/zypp/parser/yum/schema/repomd.rnc @@ -2,7 +2,7 @@ default namespace = "http://linux.duke.edu/metadata/repo" element repomd { element data { - attribute type { "other" | "filelists" | "primary" }& + attribute type { "other" | "filelists" | "primary" | "group" | "product" | "patches" }& element location { attribute xml:base { xsd:anyURI }?, attribute href { xsd:anyURI }, diff --git a/zypp/parser/yum/schema/repomd.rng b/zypp/parser/yum/schema/repomd.rng index 0865bce..1b39946 100644 --- a/zypp/parser/yum/schema/repomd.rng +++ b/zypp/parser/yum/schema/repomd.rng @@ -9,6 +9,9 @@ other filelists primary + group + product + patches diff --git a/zypp/parser/yum/schemanames.h b/zypp/parser/yum/schemanames.h index 2a50239..bc215ad 100644 --- a/zypp/parser/yum/schemanames.h +++ b/zypp/parser/yum/schemanames.h @@ -25,6 +25,7 @@ namespace zypp { #define FILELISTSCHEMA (SCHEMABASE "filelists.rng") #define OTHERSCHEMA (SCHEMABASE "other.rng") #define PATCHSCHEMA (SCHEMABASE "patch.rng") + #define PATCHESSCHEMA (SCHEMABASE "patches.rng") #define PRODUCTSCHEMA (SCHEMABASE "product.rng") } // namespace yum } // namespace parser -- 2.7.4