13#include <zypp/base/LogTools.h>
14#include <zypp/base/String.h>
15#include <zypp/base/StringV.h>
16#include <zypp-core/base/InputStream>
17#include <zypp-core/base/UserRequestException>
19#include <zypp-core/parser/IniDict>
37 class RepoFileParser :
public IniDict
40 RepoFileParser(
const InputStream & is_r )
45 virtual void consume(
const std::string & section_r,
const std::string & key_r,
const std::string & value_r )
47 if ( key_r ==
"baseurl" )
50 storeUrl( _baseurls[section_r], value_r );
52 else if ( key_r ==
"gpgkey" )
55 storeUrl( _gpgkeys[section_r], value_r );
57 else if ( key_r ==
"mirrorlist" )
60 storeUrl( _mirrorlist[section_r], value_r );
62 else if ( key_r ==
"metalink" )
65 storeUrl( _metalink[section_r], value_r );
74 virtual void garbageLine(
const std::string & section_r,
const std::string & line_r )
76 switch ( _inMultiline )
78 case MultiLine::baseurl:
79 storeUrl( _baseurls[section_r], line_r );
82 case MultiLine::gpgkey:
83 storeUrl( _gpgkeys[section_r], line_r );
86 case MultiLine::mirrorlist:
87 storeUrl( _mirrorlist[section_r], line_r );
90 case MultiLine::metalink:
91 storeUrl( _metalink[section_r], line_r );
100 std::list<Url> & baseurls(
const std::string & section_r )
103 std::list<Url> & gpgkeys(
const std::string & section_r )
106 std::list<Url> & mirrorlist(
const std::string & section_r )
109 std::list<Url> & metalink(
const std::string & section_r )
113 void storeUrl( std::list<Url> & store_r,
const std::string & line_r )
116 strv::splitRx( line_r,
"[,[:blank:]]*[[:blank:]][,[:blank:]]*", [&store_r]( std::string_view w ) {
118 store_r.push_back(
Url(std::string(w)) );
122 enum class MultiLine { none, baseurl, gpgkey, mirrorlist, metalink };
142 RepoFileParser dict(is);
143 for_( its, dict.sectionsBegin(), dict.sectionsEnd() )
148 std::string proxyport;
150 for_( it, dict.entriesBegin(*its), dict.entriesEnd(*its) )
153 if (it->first ==
"name" )
155 else if ( it->first ==
"enabled" )
157 else if ( it->first ==
"priority" )
158 info.
setPriority( str::strtonum<unsigned>( it->second ) );
159 else if ( it->first ==
"path" )
161 else if ( it->first ==
"type" )
163 else if ( it->first ==
"autorefresh" )
165 else if ( it->first ==
"gpgcheck" )
167 else if ( it->first ==
"repo_gpgcheck" )
169 else if ( it->first ==
"pkg_gpgcheck" )
171 else if ( it->first ==
"keeppackages" )
173 else if ( it->first ==
"service" )
175 else if ( it->first ==
"proxy" )
184 proxy = it->second.substr( 0, it->second.size() - what[0].
size() );
185 proxyport = what[0].substr( 1 );
193 ERR <<
"Unknown attribute in [" << *its <<
"]: " << it->first <<
"=" << it->second <<
" ignored" << endl;
196 for (
auto & url : dict.baseurls( *its ) )
198 if ( ! proxy.empty() && url.getQueryParam(
"proxy" ).empty() )
200 url.setQueryParam(
"proxy", proxy );
201 url.setQueryParam(
"proxyport", proxyport );
206 if ( ! dict.gpgkeys( *its ).empty() )
209 if ( ! dict.mirrorlist( *its ).empty() )
212 if ( ! dict.metalink( *its ).empty() )
std::map< std::string, std::list< Url > > _gpgkeys
std::map< std::string, std::list< Url > > _baseurls
std::map< std::string, std::list< Url > > _metalink
std::map< std::string, std::list< Url > > _mirrorlist
function< bool(const ProgressData &)> ReceiverFnc
Most simple version of progress reporting The percentage in most cases.
What is known about a repository.
void setPkgGpgCheck(TriBool value_r)
Set the value for pkgGpgCheck (or indeterminate to use the default).
void setGpgKeyUrls(url_set urls)
Set a list of gpgkey URLs defined for this repo.
void setMirrorListUrls(url_set urls)
Like setMirrorListUrl but take an url_set.
void addBaseUrl(const Url &url)
Add a base url.
void setKeepPackages(bool keep)
Set if packaqes downloaded from this repository will be kept in local cache.
void setService(const std::string &name)
sets service which added this repository
void setGpgCheck(TriBool value_r)
Set the value for gpgCheck (or indeterminate to use the default).
void setPath(const Pathname &path)
set the product path.
void setPriority(unsigned newval_r)
Set repository priority for solver.
void setRepoGpgCheck(TriBool value_r)
Set the value for repoGpgCheck (or indeterminate to use the default).
void setMetalinkUrls(url_set urls)
Like setMirrorListUrls but expect metalink format.
virtual void consume(const std::string §ion)
Called when a section is found.
virtual void garbageLine(const std::string §ion, const std::string &line)
Called whenever a garbage line is found.
Read repository data from a .repo file.
function< bool(const RepoInfo &)> ProcessRepo
Callback definition.
RepoFileReader(const Pathname &repo_file, const ProcessRepo &callback, const ProgressData::ReceiverFnc &progress=ProgressData::ReceiverFnc())
Constructor.
void setAutorefresh(bool autorefresh)
enable or disable autorefresh
void setFilepath(const Pathname &filename)
set the path to the .repo file
void setAlias(const std::string &alias)
set the repository alias
void setName(const std::string &name)
set the repository name
void setEnabled(bool enabled)
enable or disable the repository
Regular expression match result.
const ProcessCredentials & _callback
String related utilities and Regular expression matching.
std::map< std::string, std::string > read(const Pathname &_path)
Read sysconfig file path_r and return (key,valye) pairs.
std::ostream & operator<<(std::ostream &str, const ProductFileData &obj)
static void repositories_in_stream(const InputStream &is, const RepoFileReader::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress)
List of RepoInfo's from a file.
TriBool strToTriBool(const C_Str &str)
Parse str into a bool if it's a legal true or false string; else indeterminate.
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
\relates regex \ingroup ZYPP_STR_REGEX \relates regex \ingroup ZYPP_STR_REGEX
bool strToTrue(const C_Str &str)
Parsing boolean from string.
Easy-to use interface to the ZYPP dependency resolver.
constexpr std::string_view Url("url")
#define for_(IT, BEG, END)
Convenient for-loops using iterator.