13#include <unordered_map>
19#include <zypp-core/base/InputStream>
20#include <zypp-core/base/DefaultIntegral>
25#include <zypp-core/parser/ParseException>
32#undef ZYPP_BASE_LOGGER_LOGGROUP
33#define ZYPP_BASE_LOGGER_LOGGROUP "parser"
51 void setGlobalVar(
const std::string & key_r,
const std::string & val_r )
52 { _global[key_r] = replace( val_r ); }
55 void setSectionVar(
const std::string & key_r,
const std::string & val_r )
56 { _section[key_r] = replace( val_r ); }
59 void clearSectionVars()
62 std::string replace(
const std::string & val_r )
const
64 std::string::size_type vbeg = val_r.find(
"%{", 0 );
65 if ( vbeg == std::string::npos )
69 std::string::size_type cbeg = 0;
70 for( ; vbeg != std::string::npos; vbeg = val_r.find(
"%{", vbeg ) )
72 std::string::size_type nbeg = vbeg+2;
73 std::string::size_type nend = val_r.find(
'}', nbeg );
74 if ( nend == std::string::npos )
76 WAR <<
"Incomplete variable in '" << val_r <<
"'" << endl;
79 const std::string * varptr = getVar( val_r.substr( nbeg, nend-nbeg ) );
83 ret << val_r.substr( cbeg, vbeg-cbeg );
88 WAR <<
"Undefined variable %{" << val_r.substr( nbeg, nend-nbeg ) <<
"} in '" << val_r <<
"'" << endl;
91 if ( cbeg < val_r.size() )
92 ret << val_r.substr( cbeg );
98 const std::string * getVar(
const std::string & key_r )
const
100 const std::string * ret = getVar( key_r, _section );
102 ret = getVar( key_r, _global );
106 const std::string * getVar(
const std::string & key_r,
const std::unordered_map<std::string,std::string> & map_r )
const
108 const auto & iter = map_r.find( key_r );
109 if ( iter != map_r.end() )
110 return &(iter->second);
115 std::unordered_map<std::string,std::string> _global;
116 std::unordered_map<std::string,std::string> _section;
149 return !value_r.empty();
167 MIL <<
"Reading " << is.
path() << endl;
186 if ( reader_r->
nodeType() == XML_READER_TYPE_ELEMENT )
189 if ( reader_r->
name() ==
"repoindex" )
204 if ( reader_r->
name() ==
"repo" )
213 info.setAutorefresh(
true );
214 info.setEnabled(
false);
216 std::string attrValue;
223 info.setAlias( attrValue );
224 _replacer.setSectionVar(
"alias", attrValue );
236 if ( urlstr.empty() )
238 if ( pathstr.empty() )
249 if ( pathstr.empty() )
250 info.setBaseUrl(
Url(urlstr) );
254 url.setPathName(
Pathname(
url.getPathName()) /
"repo" / pathstr );
257 _replacer.setSectionVar(
"url", urlstr );
263 info.setName( attrValue );
266 if (
getAttrValue(
"distro_target", reader_r, attrValue ) )
267 info.setTargetDistribution( attrValue );
278 if (
getAttrValue(
"autorefresh", reader_r, attrValue ) )
284 if (
getAttrValue(
"repo_gpgcheck", reader_r, attrValue ) )
286 if (
getAttrValue(
"pkg_gpgcheck", reader_r, attrValue ) )
290 if (
getAttrValue(
"keeppackages", reader_r, attrValue ) )
295 info.setGpgKeyUrl(
Url(attrValue) );
298 if (
getAttrValue(
"mirrorlist", reader_r, attrValue ) )
299 info.setMirrorlistUrl(
Url(attrValue) );
303 info.setMetalinkUrl(
Url(attrValue) );
310 if (
info.baseUrlsEmpty() &&
info.path().empty() && not
info.mirrorListUrl().isValid() ) {
312 "url",
"mirrorlist",
"metalink",
info.alias().c_str()));
Interface of repoindex.xml file reader.
Integral type with defined initial value when default constructed.
What is known about a repository.
DefaultIntegral< Date::Duration, 0 > _ttl
bool consumeNode(Reader &reader_r)
Callback provided to the XML parser.
Impl(const InputStream &is, ProcessResource &&callback)
CTOR.
ProcessResource _callback
Function for processing collected data.
bool getAttrValue(const std::string &key_r, Reader &reader_r, std::string &value_r)
function< bool(const RepoInfo &)> ProcessResource
Callback definition.
RW_pointer< Impl, rw_pointer::Scoped< Impl > > _pimpl
RepoindexFileReader(Pathname repoindexFile, ProcessResource callback)
CTOR.
Date::Duration ttl() const
Metadata TTL (repoindex.xml:xpath:/repoindex@ttl or 0).
~RepoindexFileReader()
DTOR.
XmlString localName() const
The local name of the node.
NodeType nodeType() const
Get the node type of the current node.
XmlString value() const
Provides the text value of the node if present.
XmlString getAttribute(const char *name_r) const
Provides a copy of the attribute value with the specified qualified name.
XmlString name() const
The qualified name of the node, equal to Prefix :LocalName.
xmlTextReader based interface to iterate xml streams.
bool foreachNode(const ProcessNode &fnc_r)
std::string asString() const
Explicit conversion to std::string.
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t s
nullptr CURL handle void p CURLversion nullptr struct curl_slist list CURLM CURLM_INTERNAL_ERROR CURLM CURL CURLM_INTERNAL_ERROR CURLM curl_socket_t int int CURLM_INTERNAL_ERROR CURLINFO info
boost::noncopyable NonCopyable
Ensure derived classes cannot be copied.
bool strToTrue(const C_Str &str)
Parsing boolean from string.
TriBool strToTriBool(const C_Str &str)
Parse str into a bool if it's a legal true or false string; else indeterminate.
std::string form(const char *format,...) __attribute__((format(printf
Printf style construction of std::string.
bool strToBool(const C_Str &str, bool default_r)
Parse str into a bool depending on the default value.
TInt strtonum(const C_Str &str)
Parsing numbers from string.
Easy-to use interface to the ZYPP dependency resolver.