18#include <zypp-core/base/InputStream>
19#include <zypp-core/base/UserRequestException>
21#include <zypp-core/parser/IniDict>
39 class RepoFileParser :
public IniDict
42 RepoFileParser(
const InputStream & is_r )
47 void consume(
const std::string & section_r,
const std::string & key_r,
const std::string & value_r )
override
49 if ( key_r ==
"baseurl" )
51 _inMultiline = MultiLine::baseurl;
52 storeUrl( _baseurls[section_r], value_r );
54 else if ( key_r ==
"gpgkey" )
56 _inMultiline = MultiLine::gpgkey;
57 storeUrl( _gpgkeys[section_r], value_r );
59 else if ( key_r ==
"mirrorlist" )
61 _inMultiline = MultiLine::mirrorlist;
62 storeUrl( _mirrorlist[section_r], value_r );
64 else if ( key_r ==
"metalink" )
66 _inMultiline = MultiLine::metalink;
67 storeUrl( _metalink[section_r], value_r );
71 _inMultiline = MultiLine::none;
76 void garbageLine(
const std::string & section_r,
const std::string & line_r )
override
78 switch ( _inMultiline )
80 case MultiLine::baseurl:
81 storeUrl( _baseurls[section_r], line_r );
84 case MultiLine::gpgkey:
85 storeUrl( _gpgkeys[section_r], line_r );
88 case MultiLine::mirrorlist:
89 storeUrl( _mirrorlist[section_r], line_r );
92 case MultiLine::metalink:
93 storeUrl( _metalink[section_r], line_r );
102 std::list<Url> & baseurls(
const std::string & section_r )
103 {
return _baseurls[section_r]; }
105 std::list<Url> & gpgkeys(
const std::string & section_r )
106 {
return _gpgkeys[section_r]; }
108 std::list<Url> & mirrorlist(
const std::string & section_r )
109 {
return _mirrorlist[section_r]; }
111 std::list<Url> & metalink(
const std::string & section_r )
112 {
return _metalink[section_r]; }
115 void storeUrl( std::list<Url> & store_r,
const std::string & line_r )
118 strv::splitRx( line_r,
"[,[:blank:]]*[[:blank:]][,[:blank:]]*", [&store_r]( std::string_view w ) {
120 store_r.push_back(
Url(std::string(w)) );
124 enum class MultiLine {
none, baseurl, gpgkey, mirrorlist, metalink };
125 MultiLine _inMultiline = MultiLine::none;
127 std::map<std::string,std::list<Url>> _baseurls;
128 std::map<std::string,std::list<Url>> _gpgkeys;
129 std::map<std::string,std::list<Url>> _mirrorlist;
130 std::map<std::string,std::list<Url>> _metalink;
144 RepoFileParser dict(is);
145 for_( its, dict.sectionsBegin(), dict.sectionsEnd() )
150 std::string proxyport;
152 for_( it, dict.entriesBegin(*its), dict.entriesEnd(*its) )
155 if (it->first ==
"name" )
157 else if ( it->first ==
"enabled" )
159 else if ( it->first ==
"priority" )
161 else if ( it->first ==
"path" ) {
171 else if ( it->first ==
"type" )
173 else if ( it->first ==
"autorefresh" )
175 else if ( it->first ==
"gpgcheck" )
177 else if ( it->first ==
"repo_gpgcheck" )
179 else if ( it->first ==
"pkg_gpgcheck" )
181 else if ( it->first ==
"keeppackages" )
183 else if ( it->first ==
"service" )
185 else if ( it->first ==
"proxy" )
194 proxy = it->second.substr( 0, it->second.size() - what[0].
size() );
195 proxyport = what[0].substr( 1 );
206 WAR <<
"Unknown attribute in [" << *its <<
"]: " << it->first <<
"=" << it->second <<
" not interpreted; preserved as an extra value" << endl;
211 for (
auto &
url : dict.baseurls( *its ) )
213 if ( ! proxy.empty() &&
url.getQueryParam(
"proxy" ).empty() )
215 url.setQueryParam(
"proxy", proxy );
216 url.setQueryParam(
"proxyport", proxyport );
221 if ( ! dict.gpgkeys( *its ).empty() )
224 if ( ! dict.mirrorlist( *its ).empty() )
227 if ( ! dict.metalink( *its ).empty() )
239 ex.
addHistory(
"Parsing .repo file "+is.name() );
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
Base class for Exception.
void addHistory(const std::string &msg_r)
Add some message text to the history.
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 setMetalinkUrl(const Url &url)
Set the raw metalink url.
void setMirrorlistUrl(const Url &url)
Set the raw mirrorlist 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
bool setExtraValue(const std::string &key_r, std::string value_r)
Remember extra value_r for key_r.
void setGpgCheck(TriBool value_r)
Set the value for gpgCheck (or indeterminate to use the default).
void addBaseUrl(Url url)
Add a base url.
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).
bool relativeDotDot() const
Test for a relative path referring to ../.
Pathname absolutename() const
Return this path, adding a leading '/' if relative.
Parses a INI file and offers its structure as a dictionary.
void consume(const std::string §ion) override
Called when a section is found.
virtual void garbageLine(const std::string §ion, const std::string &line)
Called whenever a garbage line is found.
function< bool(const RepoInfo &)> ProcessRepo
Callback definition.
RepoFileReader(const Pathname &repo_file, 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.
bool regex_match(const char *s, smatch &matches, const regex ®ex) ZYPP_API
Regular expression matching.
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.
static void repositories_in_stream(const InputStream &is, const RepoFileReader::ProcessRepo &callback, const ProgressData::ReceiverFnc &progress)
List of RepoInfo's from a file.
std::ostream & operator<<(std::ostream &str, const ProductFileData &obj)
relates: ProductFileData Stream output
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.
TInt strtonum(const C_Str &str)
Parsing numbers from string.
std::string sconcat(Args &&... args)
Concat words as string.
Easy-to use interface to the ZYPP dependency resolver.
static bool warning(const std::string &msg_r, const UserData &userData_r=UserData())
send warning text