libzypp 8.13.6
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 00014 #include "zypp/base/String.h" 00015 #include "zypp/base/Logger.h" 00016 #include "zypp/base/Gettext.h" 00017 #include "zypp/base/InputStream.h" 00018 00019 #include "zypp/Pathname.h" 00020 00021 #include "zypp/parser/xml/Reader.h" 00022 #include "zypp/parser/ParseException.h" 00023 00024 #include "zypp/RepoInfo.h" 00025 00026 #include "zypp/parser/RepoindexFileReader.h" 00027 00028 00029 #undef ZYPP_BASE_LOGGER_LOGGROUP 00030 #define ZYPP_BASE_LOGGER_LOGGROUP "parser" 00031 00032 using namespace std; 00033 using namespace zypp::xml; 00034 00035 namespace zypp 00036 { 00037 namespace parser 00038 { 00039 00040 00042 // 00043 // CLASS NAME : RepoindexFileReader::Impl 00044 // 00045 class RepoindexFileReader::Impl : private base::NonCopyable 00046 { 00047 public: 00053 Impl(const InputStream &is, const ProcessResource & callback); 00054 00058 bool consumeNode( Reader & reader_r ); 00059 00060 00061 private: 00063 ProcessResource _callback; 00064 string _target_distro; 00065 }; 00067 00068 RepoindexFileReader::Impl::Impl(const InputStream &is, 00069 const ProcessResource & callback) 00070 : _callback(callback) 00071 { 00072 Reader reader( is ); 00073 MIL << "Reading " << is.path() << endl; 00074 reader.foreachNode( bind( &RepoindexFileReader::Impl::consumeNode, this, _1 ) ); 00075 } 00076 00077 // -------------------------------------------------------------------------- 00078 00079 /* 00080 * xpath and multiplicity of processed nodes are included in the code 00081 * for convenience: 00082 * 00083 * // xpath: <xpath> (?|*|+) 00084 * 00085 * if multiplicity is ommited, then the node has multiplicity 'one'. 00086 */ 00087 00088 // -------------------------------------------------------------------------- 00089 00090 bool RepoindexFileReader::Impl::consumeNode( Reader & reader_r ) 00091 { 00092 if ( reader_r->nodeType() == XML_READER_TYPE_ELEMENT ) 00093 { 00094 // xpath: /repoindex 00095 if ( reader_r->name() == "repoindex" ) 00096 { 00097 return true; 00098 } 00099 00100 // xpath: /repoindex/data (+) 00101 if ( reader_r->name() == "repo" ) 00102 { 00103 XmlString s; 00104 00105 RepoInfo info; 00106 00107 // enabled or disabled is controlled by the 00108 // reposToEnable/Disable list, unless the 00109 // enabled attribute is set 00110 info.setEnabled(false); 00111 00112 // url and/or path 00113 string url_s; 00114 s = reader_r->getAttribute("url"); 00115 if (s.get()) 00116 url_s = s.asString(); 00117 string path_s; 00118 s = reader_r->getAttribute("path"); 00119 if (s.get()) 00120 path_s = s.asString(); 00121 00122 if (url_s.empty() && path_s.empty()) 00123 throw ParseException(str::form(_("One or both of '%s' or '%s' attributes is required."), "url", "path")); 00125 else if (url_s.empty()) 00126 info.setPath(Pathname(string("/repo/") + path_s)); 00127 else if (path_s.empty()) 00128 info.setBaseUrl(Url(url_s)); 00129 else 00130 info.setBaseUrl(Url(url_s + "/repo/" + path_s)); 00131 00132 // required alias 00133 s = reader_r->getAttribute("alias"); 00134 if (!s.get()) 00135 throw ParseException(str::form(_("Required attribute '%s' is missing."), "alias")); 00136 info.setAlias(s.asString()); 00137 00138 // optional type 00139 s = reader_r->getAttribute("type"); 00140 if (s.get()) 00141 info.setType(repo::RepoType(s.asString())); 00142 00143 // optional name 00144 s = reader_r->getAttribute("name"); 00145 if (s.get()) 00146 info.setName(s.asString()); 00147 00148 // optional targetDistro 00149 s = reader_r->getAttribute("distro_target"); 00150 if (s.get()) 00151 info.setTargetDistribution(s.asString()); 00152 00153 // optional priority 00154 s = reader_r->getAttribute("priority"); 00155 if (s.get()) { 00156 info.setPriority(str::strtonum<unsigned>(s.asString())); 00157 } 00158 00159 // optional enabled 00160 s = reader_r->getAttribute("enabled"); 00161 if (s.get()) { 00162 info.setEnabled(str::strToTrue(s.asString())); 00163 } 00164 00165 DBG << info << endl; 00166 00167 // Set some defaults that are not contained in the repo information 00168 info.setAutorefresh( true ); 00169 00170 // ignore the rest 00171 _callback(info); 00172 return true; 00173 } 00174 } 00175 00176 return true; 00177 } 00178 00179 00181 // 00182 // CLASS NAME : RepoindexFileReader 00183 // 00185 00186 RepoindexFileReader::RepoindexFileReader( 00187 const Pathname & repoindex_file, const ProcessResource & callback) 00188 : 00189 _pimpl(new Impl(InputStream(repoindex_file), callback)) 00190 {} 00191 00192 RepoindexFileReader::RepoindexFileReader( 00193 const InputStream &is, const ProcessResource & callback ) 00194 : _pimpl(new Impl(is, callback)) 00195 {} 00196 00197 RepoindexFileReader::~RepoindexFileReader() 00198 {} 00199 00200 00201 } // ns parser 00202 } // ns zypp 00203 00204 // vim: set ts=2 sts=2 sw=2 et ai: