libzypp  13.10.6
RepomdFileReader.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/Pathname.h"
18 #include "zypp/Date.h"
19 #include "zypp/CheckSum.h"
20 #include "zypp/parser/xml/Reader.h"
21 
23 
24 #undef ZYPP_BASE_LOGGER_LOGGROUP
25 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
26 
27 using namespace std;
28 using namespace zypp::xml;
30 
31 namespace zypp
32 {
33  namespace parser
34  {
35  namespace yum
36  {
37 
38 
40  //
41  // CLASS NAME : RepomdFileReader::Impl
42  //
44  {
45  public:
46 
51  enum Tag
52  {
60  };
61 
62  public:
68  Impl(const Pathname &repomd_file, const ProcessResource & callback);
69 
73  bool consumeNode( Reader & reader_r );
74 
75 
76  private:
79 
82 
85 
88 
91 
93  std::string _checksum_type;
94 
97  };
99 
100  RepomdFileReader::Impl::Impl(
101  const Pathname &repomd_file, const ProcessResource & callback)
102  :
103  _tag(tag_NONE), _type(ResourceType::NONE_e), _callback(callback)
104  {
105  Reader reader( repomd_file );
106  MIL << "Reading " << repomd_file << endl;
107  reader.foreachNode( bind( &RepomdFileReader::Impl::consumeNode, this, _1 ) );
108  }
109 
110  // --------------------------------------------------------------------------
111 
112  /*
113  * xpath and multiplicity of processed nodes are included in the code
114  * for convenience:
115  *
116  * // xpath: <xpath> (?|*|+)
117  *
118  * if multiplicity is ommited, then the node has multiplicity 'one'.
119  */
120 
121  // --------------------------------------------------------------------------
122 
124  {
125  if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
126  {
127  // xpath: /repomd
128  if ( reader_r->name() == "repomd" )
129  {
130  _tag = tag_Repomd;
131  return true;
132  }
133 
134  // xpath: /repomd/data (+)
135  if ( reader_r->name() == "data" )
136  {
137  _tag = tag_Data;
138  _type = ResourceType(reader_r->getAttribute("type").asString());
139  return true;
140  }
141 
142  // xpath: /repomd/location
143  if ( reader_r->name() == "location" )
144  {
145  _tag = tag_Location;
146  _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
147  // ignoring attribute xml:base
148  return true;
149  }
150 
151  // xpath: /repomd/checksum
152  if ( reader_r->name() == "checksum" )
153  {
154  _tag = tag_CheckSum;
155  string checksum_type = reader_r->getAttribute("type").asString() ;
156  string checksum_vaue = reader_r.nodeText().asString();
157  _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
158  return true;
159  }
160 
161  // xpath: /repomd/timestamp
162  if ( reader_r->name() == "timestamp" )
163  {
164  // ignore it
165  return true;
166  }
167 
169  }
170 
171  else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
172  {
173  // xpath: /repomd/data
174  if ( reader_r->name() == "data" )
175  {
176  if (_callback)
177  _callback( _location, _type );
178 
179  return true;
180  }
181  }
182 
183  return true;
184  }
185 
186 
188  //
189  // CLASS NAME : RepomdFileReader
190  //
192 
194  const Pathname & repomd_file, const ProcessResource & callback)
195  :
196  _pimpl(new Impl(repomd_file, callback))
197  {}
198 
200  {}
201 
202 
203  } // ns yum
204  } // ns parser
205 } // ns zypp
206 
207 // vim: set ts=2 sts=2 sw=2 et ai:
#define MIL
Definition: Logger.h:47
RepomdFileReader(const Pathname &repomd_file, const ProcessResource &callback)
CTOR.
Describes a path on a certain media amongs as the information required to download it...
Tag
Enumeration of repomd.xml tags.
Date _timestamp
Metadata file time-stamp.
bool consumeNode(Reader &reader_r)
Callback provided to the XML parser.
CheckSum _checksum
Checksum of metadata file.
repo::yum::ResourceType _type
Type of metadata file.
std::string _checksum_type
Type of checksum of metadata file.
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
Definition: NonCopyable.h:26
Store and operate on date (time_t).
Definition: Date.h:31
OnMediaLocation _location
Location of metadata file.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
function< bool(const OnMediaLocation &, const repo::yum::ResourceType &)> ProcessResource
Callback definition.
Tag _tag
Used to remember currently processed tag.
XmlString name() const
The qualified name of the node, equal to Prefix :LocalName.
Definition: Node.h:115
std::string asString() const
Explicit conversion to std::string.
Definition: XmlString.h:77
XmlString getAttribute(const char *name_r) const
Provides a copy of the attribute value with the specified qualified name.
Definition: Node.h:71
XmlString nodeText()
If the curent node is not empty, advances the reader to the next node, and returns the value...
Definition: Reader.cc:140
bool foreachNode(ProcessNode fnc_r)
Definition: Reader.h:144
Interface of repomd.xml file reader.
ProcessResource _callback
Function for processing collected data.
NodeType nodeType() const
Get the node type of the current node.
Definition: Node.h:123
xmlTextReader based interface to iterate xml streams.
Definition: Reader.h:95