RepomdFileReader.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013
00014 #include "zypp/base/String.h"
00015 #include "zypp/base/Logger.h"
00016
00017 #include "zypp/Pathname.h"
00018 #include "zypp/Date.h"
00019 #include "zypp/CheckSum.h"
00020 #include "zypp/parser/xml/Reader.h"
00021
00022 #include "zypp/parser/yum/RepomdFileReader.h"
00023
00024 #undef ZYPP_BASE_LOGGER_LOGGROUP
00025 #define ZYPP_BASE_LOGGER_LOGGROUP "parser::yum"
00026
00027 using namespace std;
00028 using namespace zypp::xml;
00029 using zypp::repo::yum::ResourceType;
00030
00031 namespace zypp
00032 {
00033 namespace parser
00034 {
00035 namespace yum
00036 {
00037
00038
00040
00041
00042
00043 class RepomdFileReader::Impl : private base::NonCopyable
00044 {
00045 public:
00046
00051 enum Tag
00052 {
00053 tag_NONE,
00054 tag_Repomd,
00055 tag_Data,
00056 tag_Location,
00057 tag_CheckSum,
00058 tag_Timestamp,
00059 tag_OpenCheckSum
00060 };
00061
00062 public:
00068 Impl(const Pathname &repomd_file, const ProcessResource & callback);
00069
00073 bool consumeNode( Reader & reader_r );
00074
00075
00076 private:
00078 OnMediaLocation _location;
00079
00081 Tag _tag;
00082
00084 repo::yum::ResourceType _type;
00085
00087 ProcessResource _callback;
00088
00090 CheckSum _checksum;
00091
00093 std::string _checksum_type;
00094
00096 Date _timestamp;
00097 };
00099
00100 RepomdFileReader::Impl::Impl(
00101 const Pathname &repomd_file, const ProcessResource & callback)
00102 :
00103 _tag(tag_NONE), _type(ResourceType::NONE_e), _callback(callback)
00104 {
00105 Reader reader( repomd_file );
00106 MIL << "Reading " << repomd_file << endl;
00107 reader.foreachNode( bind( &RepomdFileReader::Impl::consumeNode, this, _1 ) );
00108 }
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123 bool RepomdFileReader::Impl::consumeNode( Reader & reader_r )
00124 {
00125 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT )
00126 {
00127
00128 if ( reader_r->name() == "repomd" )
00129 {
00130 _tag = tag_Repomd;
00131 return true;
00132 }
00133
00134
00135 if ( reader_r->name() == "data" )
00136 {
00137 _tag = tag_Data;
00138 _type = ResourceType(reader_r->getAttribute("type").asString());
00139 return true;
00140 }
00141
00142
00143 if ( reader_r->name() == "location" )
00144 {
00145 _tag = tag_Location;
00146 _location.setLocation( reader_r->getAttribute("href").asString(), 1 );
00147
00148 return true;
00149 }
00150
00151
00152 if ( reader_r->name() == "checksum" )
00153 {
00154 _tag = tag_CheckSum;
00155 string checksum_type = reader_r->getAttribute("type").asString() ;
00156 string checksum_vaue = reader_r.nodeText().asString();
00157 _location.setChecksum( CheckSum( checksum_type, checksum_vaue ) );
00158 return true;
00159 }
00160
00161
00162 if ( reader_r->name() == "timestamp" )
00163 {
00164
00165 return true;
00166 }
00167
00169 }
00170
00171 else if ( reader_r->nodeType() == XML_READER_TYPE_END_ELEMENT )
00172 {
00173
00174 if ( reader_r->name() == "data" )
00175 {
00176 if (_callback)
00177 _callback( _location, _type );
00178
00179 return true;
00180 }
00181 }
00182
00183 return true;
00184 }
00185
00186
00188
00189
00190
00192
00193 RepomdFileReader::RepomdFileReader(
00194 const Pathname & repomd_file, const ProcessResource & callback)
00195 :
00196 _pimpl(new Impl(repomd_file, callback))
00197 {}
00198
00199 RepomdFileReader::~RepomdFileReader()
00200 {}
00201
00202
00203 }
00204 }
00205 }
00206
00207