1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/parser/yum/RepomdFileReader.cc
10 * Implementation of repomd.xml file reader.
14 #include "zypp/base/String.h"
15 #include "zypp/base/Logger.h"
17 #include "zypp/Pathname.h"
18 #include "zypp/Date.h"
19 #include "zypp/CheckSum.h"
20 #include "zypp/parser/xml/Reader.h"
22 #include "zypp/parser/yum/RepomdFileReader.h"
24 #undef ZYPP_BASE_LOGGER_LOGGROUP
25 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
28 using namespace zypp::xml;
29 using zypp::repo::yum::ResourceType;
39 ///////////////////////////////////////////////////////////////////////
41 // CLASS NAME : RepomdFileReader::Impl
43 class RepomdFileReader::Impl : private base::NonCopyable
48 * Enumeration of repomd.xml tags.
66 * \see RepomdFileReader::RepomdFileReader(Pathname,ProcessResource)
68 Impl(const Pathname &repomd_file, const ProcessResource & callback);
71 * Callback provided to the XML parser.
73 bool consumeNode( Reader & reader_r );
77 /** Location of metadata file. */
78 OnMediaLocation _location;
80 /** Used to remember currently processed tag */
83 /** Type of metadata file. */
84 repo::yum::ResourceType _type;
86 /** Function for processing collected data. Passed-in through constructor. */
87 ProcessResource _callback;
89 /** Checksum of metadata file */
92 /** Type of checksum of metadata file */
93 std::string _checksum_type;
95 /** Metadata file time-stamp. */
98 ///////////////////////////////////////////////////////////////////////
100 RepomdFileReader::Impl::Impl(
101 const Pathname &repomd_file, const ProcessResource & callback)
103 _tag(tag_NONE), _type(ResourceType::NONE_e), _callback(callback)
105 Reader reader( repomd_file );
106 MIL << "Reading " << repomd_file << endl;
107 reader.foreachNode( bind( &RepomdFileReader::Impl::consumeNode, this, _1 ) );
110 // --------------------------------------------------------------------------
113 * xpath and multiplicity of processed nodes are included in the code
116 * // xpath: <xpath> (?|*|+)
118 * if multiplicity is ommited, then the node has multiplicity 'one'.
121 // --------------------------------------------------------------------------
123 bool RepomdFileReader::Impl::consumeNode( Reader & reader_r )
125 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
128 if ( reader_r->name() == "repomd" )
134 // xpath: /repomd/data (+)
135 if ( reader_r->name() == "data" )
138 _type = ResourceType(reader_r->getAttribute("type").asString());
142 // xpath: /repomd/location
143 if ( reader_r->name() == "location" )
146 _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
147 // ignoring attribute xml:base
151 // xpath: /repomd/checksum
152 if ( reader_r->name() == "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 ) );
161 // xpath: /repomd/timestamp
162 if ( reader_r->name() == "timestamp" )
168 // xpath: /repomd/size
169 if ( reader_r->name() == "size" )
171 string size_value = reader_r.nodeText().asString();
172 zypp::ByteCount size = zypp::ByteCount( str::strtonum<ByteCount::SizeType>( size_value ) );
173 _location.setDownloadSize( size );
177 //! \todo xpath: /repomd/open-checksum (?)
180 else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
182 // xpath: /repomd/data
183 if ( reader_r->name() == "data" )
186 _callback( _location, _type );
196 ///////////////////////////////////////////////////////////////////
198 // CLASS NAME : RepomdFileReader
200 ///////////////////////////////////////////////////////////////////
202 RepomdFileReader::RepomdFileReader(
203 const Pathname & repomd_file, const ProcessResource & callback)
205 _pimpl(new Impl(repomd_file, callback))
208 RepomdFileReader::~RepomdFileReader()
216 // vim: set ts=2 sts=2 sw=2 et ai: