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.
63 /** Ctro taking a ProcessResource2 callback */
64 Impl(const Pathname &repomd_file, const ProcessResource2 & callback )
65 : _callback( callback )
67 , _type( ResourceType::NONE_e )
69 Reader reader( repomd_file );
70 MIL << "Reading " << repomd_file << endl;
71 reader.foreachNode( bind( &RepomdFileReader::Impl::consumeNode, this, _1 ) );
73 /** \overload Redirect an old ProcessResource callback */
74 Impl(const Pathname &repomd_file, const ProcessResource & callback)
75 : Impl( repomd_file, ProcessResource2( bind( callback, _1, _2 ) ) )
79 * Callback provided to the XML parser.
81 bool consumeNode( Reader & reader_r );
85 /** Function for processing collected data. Passed-in through constructor. */
86 ProcessResource2 _callback;
88 /** Used to remember currently processed tag */
91 /** Type of metadata file (string) */
94 /** Type of metadata file as enum of well known repoinded.xml entries. */
95 repo::yum::ResourceType _type;
97 /** Location of metadata file. */
98 OnMediaLocation _location;
100 ///////////////////////////////////////////////////////////////////////
103 * xpath and multiplicity of processed nodes are included in the code
106 * // xpath: <xpath> (?|*|+)
108 * if multiplicity is ommited, then the node has multiplicity 'one'.
111 // --------------------------------------------------------------------------
113 bool RepomdFileReader::Impl::consumeNode( Reader & reader_r )
115 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
118 if ( reader_r->name() == "repomd" )
124 // xpath: /repomd/data (+)
125 if ( reader_r->name() == "data" )
128 _typeStr = reader_r->getAttribute("type").asString();
129 _type = ResourceType(_typeStr);
133 // xpath: /repomd/location
134 if ( reader_r->name() == "location" )
137 _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
138 // ignoring attribute xml:base
142 // xpath: /repomd/checksum
143 if ( reader_r->name() == "checksum" )
146 string checksum_type = reader_r->getAttribute("type").asString() ;
147 string checksum_vaue = reader_r.nodeText().asString();
148 _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
152 // xpath: /repomd/timestamp
153 if ( reader_r->name() == "timestamp" )
159 // xpath: /repomd/size
160 if ( reader_r->name() == "size" )
162 string size_value = reader_r.nodeText().asString();
163 zypp::ByteCount size = zypp::ByteCount( str::strtonum<ByteCount::SizeType>( size_value ) );
164 _location.setDownloadSize( size );
168 //! \todo xpath: /repomd/open-checksum (?)
171 else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
173 // xpath: /repomd/data
174 if ( reader_r->name() == "data" )
177 _callback( _location, _type, _typeStr );
187 ///////////////////////////////////////////////////////////////////
189 // CLASS NAME : RepomdFileReader
191 ///////////////////////////////////////////////////////////////////
193 RepomdFileReader::RepomdFileReader( const Pathname & repomd_file, const ProcessResource & callback )
194 : _pimpl( new Impl(repomd_file, callback) )
197 RepomdFileReader::RepomdFileReader( const Pathname & repomd_file, const ProcessResource2 & callback )
198 : _pimpl( new Impl(repomd_file, callback) )
201 RepomdFileReader::~RepomdFileReader()
209 // vim: set ts=2 sts=2 sw=2 et ai: