libzypp  17.7.0
PatchesFileReader.cc
Go to the documentation of this file.
1 /*---------------------------------------------------------------------\
2 | ____ _ __ __ ___ |
3 | |__ / \ / / . \ . \ |
4 | / / \ V /| _/ _/ |
5 | / /__ | | | | | | |
6 | /_____||_| |_| |_| |
7 | |
8 \---------------------------------------------------------------------*/
12 #include <iostream>
13 
14 #include "zypp/base/String.h"
15 #include "zypp/base/Logger.h"
16 
17 #include "zypp/Date.h"
18 #include "zypp/CheckSum.h"
19 #include "zypp/OnMediaLocation.h"
20 
21 #include "zypp/parser/xml/Reader.h"
23 
24 
25 using namespace std;
26 using namespace zypp::xml;
27 
28 namespace zypp
29 {
30  namespace parser
31  {
32  namespace yum
33  {
34 
35 
36  enum Tag
37  {
45  };
46 
47 
49  //
50  // CLASS NAME : PatchesFileReader::Impl
51  //
53  {
54  public:
58  Impl(const Pathname &patches_file, const ProcessResource & callback);
59 
63  bool consumeNode( Reader & reader_r );
64 
65  private:
68  std::string _id;
71  std::string _checksum_type;
73  };
75 
76 
77  PatchesFileReader::Impl::Impl(const Pathname & patches_file,
78  const ProcessResource & callback)
79  : _tag(tag_NONE), _callback(callback)
80  {
81  Reader reader( patches_file );
82  MIL << "Reading " << patches_file << endl;
83  reader.foreachNode(bind( &PatchesFileReader::Impl::consumeNode, this, _1 ));
84  }
85 
86  // --------------------------------------------------------------------------
87 
89  {
90  //MIL << reader_r->name() << endl;
91  std::string data_type;
92  if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
93  {
94  if ( reader_r->name() == "patches" )
95  {
96  _tag = tag_Patches;
97  return true;
98  }
99  if ( reader_r->name() == "patch" )
100  {
101  _tag = tag_Patch;
102  _id = reader_r->getAttribute("id").asString();
103  return true;
104  }
105  if ( reader_r->name() == "location" )
106  {
107  _tag = tag_Location;
108  _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
109  return true;
110  }
111  if ( reader_r->name() == "checksum" )
112  {
113  _tag = tag_CheckSum;
114  string checksum_type = reader_r->getAttribute("type").asString() ;
115  string checksum_vaue = reader_r.nodeText().asString();
116  _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
117  return true;
118  }
119  if ( reader_r->name() == "timestamp" )
120  {
121  // ignore it
122  return true;
123  }
124  }
125  else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
126  {
127  //MIL << "end element" << endl;
128  if ( reader_r->name() == "patch" )
129  _callback( _location, _id );
130  return true;
131  }
132  return true;
133  }
134 
135 
137  //
138  // CLASS NAME : PatchesFileReader
139  //
141 
143  const ProcessResource & callback)
144  : _pimpl(new Impl(patches_file, callback))
145  {}
146 
148  {}
149 
150 
151  } // ns yum
152  } // ns parser
153 } // ns zypp
154 
155 // vim: set ts=2 sts=2 sw=2 et ai:
zypp::xml
Definition: libxmlfwd.cc:21
zypp::xml::Reader
xmlTextReader based interface to iterate xml streams.
Definition: Reader.h:95
zypp::xml::XmlString::asString
std::string asString() const
Explicit conversion to std::string.
Definition: XmlString.h:77
zypp::parser::yum::tag_Timestamp
@ tag_Timestamp
Definition: PatchesFileReader.cc:43
_callback
const ProcessCredentials & _callback
Definition: CredentialFileReader.cc:122
zypp::CheckSum
Definition: CheckSum.h:33
zypp::parser::yum::PatchesFileReader::Impl::consumeNode
bool consumeNode(Reader &reader_r)
Callback provided to the XML parser.
Definition: PatchesFileReader.cc:88
MIL
#define MIL
Definition: Logger.h:64
CheckSum.h
zypp::OnMediaLocation
Describes a path on a certain media amongs as the information required to download it,...
Definition: OnMediaLocation.h:39
zypp::xml::Reader::foreachNode
bool foreachNode(ProcessNode fnc_r)
Definition: Reader.h:144
zypp::parser::yum::PatchesFileReader::Impl::_checksum_type
std::string _checksum_type
Definition: PatchesFileReader.cc:71
zypp::parser::yum::PatchesFileReader::Impl::_callback
ProcessResource _callback
Definition: PatchesFileReader.cc:69
zypp::parser::yum::tag_CheckSum
@ tag_CheckSum
Definition: PatchesFileReader.cc:42
zypp::parser::yum::tag_NONE
@ tag_NONE
Definition: PatchesFileReader.cc:38
zypp::parser::yum::PatchesFileReader::Impl
Definition: PatchesFileReader.cc:52
zypp::parser::yum::PatchesFileReader::Impl::_location
OnMediaLocation _location
Definition: PatchesFileReader.cc:66
OnMediaLocation.h
zypp::parser::yum::tag_Location
@ tag_Location
Definition: PatchesFileReader.cc:41
zypp::base::NonCopyable
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Logger.h
zypp::parser::yum::PatchesFileReader::~PatchesFileReader
~PatchesFileReader()
DTOR.
Definition: PatchesFileReader.cc:147
zypp::xml::Node::nodeType
NodeType nodeType() const
Get the node type of the current node.
Definition: Node.h:126
PatchesFileReader.h
zypp::xml::Node::getAttribute
XmlString getAttribute(const char *name_r) const
Provides a copy of the attribute value with the specified qualified name.
Definition: Node.h:71
zypp::xml::Node::name
XmlString name() const
The qualified name of the node, equal to Prefix :LocalName.
Definition: Node.h:118
Date.h
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition: CodePitfalls.doc:1
zypp::parser::yum::PatchesFileReader::Impl::_checksum
CheckSum _checksum
Definition: PatchesFileReader.cc:70
zypp::parser::yum::tag_Patch
@ tag_Patch
Definition: PatchesFileReader.cc:40
zypp::parser::yum::tag_OpenCheckSum
@ tag_OpenCheckSum
Definition: PatchesFileReader.cc:44
zypp::parser::yum::PatchesFileReader::Impl::_tag
Tag _tag
Definition: PatchesFileReader.cc:67
zypp::parser::yum::PatchesFileReader::Impl::_timestamp
Date _timestamp
Definition: PatchesFileReader.cc:72
zypp::Date
Store and operate on date (time_t).
Definition: Date.h:32
std
Definition: Arch.h:344
zypp::parser::yum::PatchesFileReader::_pimpl
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
Definition: PatchesFileReader.h:71
zypp::xml::Reader::nodeText
XmlString nodeText()
If the current node is not empty, advances the reader to the next node, and returns the value.
Definition: Reader.cc:140
String.h
zypp::filesystem::Pathname
Pathname.
Definition: Pathname.h:43
zypp::parser::yum::PatchesFileReader::Impl::_id
std::string _id
Definition: PatchesFileReader.cc:68
zypp::parser::yum::Tag
Tag
Definition: PatchesFileReader.cc:36
zypp::parser::yum::tag_Patches
@ tag_Patches
Definition: PatchesFileReader.cc:39
zypp::parser::yum::PatchesFileReader::ProcessResource
function< bool(const OnMediaLocation &, const std::string &)> ProcessResource
Callback definition first parameter is a OnMediaLocation object with the resource second parameter is...
Definition: PatchesFileReader.h:51
Reader.h
zypp::parser::yum::PatchesFileReader::PatchesFileReader
PatchesFileReader(const Pathname &patches_file, const ProcessResource &callback)
CTOR.
Definition: PatchesFileReader.cc:142