libzypp  14.48.5
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 
123  bool RepomdFileReader::Impl::consumeNode( Reader & reader_r )
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 
168  // xpath: /repomd/size
169  if ( reader_r->name() == "size" )
170  {
171  string size_value = reader_r.nodeText().asString();
172  zypp::ByteCount size = zypp::ByteCount( str::strtonum<ByteCount::SizeType>( size_value ) );
173  _location.setDownloadSize( size );
174  return true;
175  }
176 
178  }
179 
180  else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
181  {
182  // xpath: /repomd/data
183  if ( reader_r->name() == "data" )
184  {
185  if (_callback)
186  _callback( _location, _type );
187 
188  return true;
189  }
190  }
191 
192  return true;
193  }
194 
195 
197  //
198  // CLASS NAME : RepomdFileReader
199  //
201 
203  const Pathname & repomd_file, const ProcessResource & callback)
204  :
205  _pimpl(new Impl(repomd_file, callback))
206  {}
207 
209  {}
210 
211 
212  } // ns yum
213  } // ns parser
214 } // ns zypp
215 
216 // 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.
Store and operate with byte count.
Definition: ByteCount.h:30
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.
const ProcessCredentials & _callback
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:32
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.
Interface of repomd.xml file reader.
ProcessResource _callback
Function for processing collected data.