added parser for patches.xml file (all available patches)
authorJiri Srain <jsrain@suse.cz>
Thu, 1 Dec 2005 13:27:12 +0000 (13:27 +0000)
committerJiri Srain <jsrain@suse.cz>
Thu, 1 Dec 2005 13:27:12 +0000 (13:27 +0000)
12 files changed:
zypp/parser/yum/Makefile.am
zypp/parser/yum/YUMParser.h
zypp/parser/yum/YUMParserData.cc
zypp/parser/yum/YUMParserData.h
zypp/parser/yum/YUMPatchesParser.cc [new file with mode: 0644]
zypp/parser/yum/YUMPatchesParser.h [new file with mode: 0644]
zypp/parser/yum/schema/patches.rnc [new file with mode: 0644]
zypp/parser/yum/schema/patches.rng [new file with mode: 0644]
zypp/parser/yum/schema/product.rng
zypp/parser/yum/schema/repomd.rnc
zypp/parser/yum/schema/repomd.rng
zypp/parser/yum/schemanames.h

index d2eef82..685c5df 100644 (file)
@@ -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
index d7c0c6f..3da2096 100644 (file)
@@ -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
index 0d8dd30..b24b5ca 100644 (file)
@@ -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
index 265e9ec..e8a7042 100644 (file)
@@ -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<shared_ptr<YUMPatchAtom> > 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<zypp::parser::yum::YUMPatchAtom> 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 (file)
index 0000000..50f20d5
--- /dev/null
@@ -0,0 +1,88 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/yum/YUMPatchesParser.cc
+ *
+*/
+
+#include <zypp/parser/yum/YUMPatchesParser.h>
+#include <zypp/parser/yum/YUMPrimaryParser.h>
+#include <istream>
+#include <string>
+#include <cassert>
+#include <libxml/xmlreader.h>
+#include <libxml/tree.h>
+#include <zypp/parser/LibXMLHelper.h>
+#include <zypp/base/Logger.h>
+#include <zypp/parser/yum/schemanames.h>
+
+using namespace std;
+namespace zypp {
+  namespace parser {
+    namespace yum {
+
+      YUMPatchesParser::~YUMPatchesParser()
+      { }
+      
+      YUMPatchesParser::YUMPatchesParser(istream &is, const string& baseUrl)
+      : XMLNodeIterator<YUMPatchesData_Ptr>(is, baseUrl,PATCHESSCHEMA)
+      {
+        fetchNext();
+      }
+      
+      YUMPatchesParser::YUMPatchesParser()
+      { }
+      
+      YUMPatchesParser::YUMPatchesParser(YUMPatchesData_Ptr& entry)
+      : XMLNodeIterator<YUMPatchesData_Ptr>(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 <data> 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 (file)
index 0000000..9d35683
--- /dev/null
@@ -0,0 +1,64 @@
+/*---------------------------------------------------------------------\
+|                          ____ _   __ __ ___                          |
+|                         |__  / \ / / . \ . \                         |
+|                           / / \ V /|  _/  _/                         |
+|                          / /__ | | | | | |                           |
+|                         /_____||_| |_| |_|                           |
+|                                                                      |
+\---------------------------------------------------------------------*/
+/** \file zypp/parser/yum/YUMPatchesParser.h
+ *
+*/
+
+
+
+#ifndef YUMPatchesParser_h
+#define YUMPatchesParser_h
+
+#include <zypp/parser/yum/YUMParserData.h>
+#include <zypp/parser/XMLNodeIterator.h>
+#include <zypp/parser/LibXMLHelper.h>
+#include <list>
+
+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<YUMPatchesData_Ptr>
+      {
+      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 (file)
index 0000000..2be9b2a
--- /dev/null
@@ -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 (file)
index 0000000..725176f
--- /dev/null
@@ -0,0 +1,29 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<element name="patches" ns="http://novell.com/package/metadata/suse/patches" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
+  <zeroOrMore>
+    <element name="patch">
+      <interleave>
+        <attribute name="id"/>
+        <element name="location">
+          <optional>
+            <attribute name="xml:base">
+              <data type="anyURI"/>
+            </attribute>
+          </optional>
+          <attribute name="href">
+            <data type="anyURI"/>
+          </attribute>
+        </element>
+        <element name="checksum">
+          <attribute name="type">
+            <choice>
+              <value>md5</value>
+              <value>sha</value>
+            </choice>
+          </attribute>
+          <text/>
+        </element>
+      </interleave>
+    </element>
+  </zeroOrMore>
+</element>
index 730cffb..35ad5e7 100644 (file)
         <element name="entry">
           <attribute name="name"/>
           <optional>
+            <attribute name="kind">
+              <choice>
+                <value>package</value>
+                <value>patch</value>
+                <value>script</value>
+                <value>message</value>
+                <value>product</value>
+              </choice>
+            </attribute>
+          </optional>
+          <optional>
             <attribute name="flags">
               <choice>
                 <value>EQ</value>
         <element name="entry">
           <attribute name="name"/>
           <optional>
+            <attribute name="kind">
+              <choice>
+                <value>package</value>
+                <value>patch</value>
+                <value>script</value>
+                <value>message</value>
+                <value>product</value>
+              </choice>
+            </attribute>
+          </optional>
+          <optional>
             <attribute name="flags">
               <choice>
                 <value>EQ</value>
         <element name="entry">
           <attribute name="name"/>
           <optional>
+            <attribute name="kind">
+              <choice>
+                <value>package</value>
+                <value>patch</value>
+                <value>script</value>
+                <value>message</value>
+                <value>product</value>
+              </choice>
+            </attribute>
+          </optional>
+          <optional>
             <attribute name="flags">
               <choice>
                 <value>EQ</value>
index b798416..2adde87 100644 (file)
@@ -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 },
index 0865bce..1b39946 100644 (file)
@@ -9,6 +9,9 @@
               <value>other</value>
               <value>filelists</value>
               <value>primary</value>
+              <value>group</value>
+              <value>product</value>
+              <value>patches</value>
             </choice>
           </attribute>
           <element name="location">
index 2a50239..bc215ad 100644 (file)
@@ -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