17#include <zypp-core/base/InputStream> 
   18#include <zypp-core/base/UserRequestException> 
   20#include <zypp-core/parser/IniDict> 
   38      class RepoFileParser : 
public IniDict 
   41        RepoFileParser( 
const InputStream & is_r )
 
   46        void consume( 
const std::string & section_r, 
const std::string & key_r, 
const std::string & value_r )
 override 
   48          if ( key_r == 
"baseurl" )
 
   50            _inMultiline = MultiLine::baseurl;
 
   51            storeUrl( _baseurls[section_r], value_r );
 
   53          else if ( key_r == 
"gpgkey" )
 
   55            _inMultiline = MultiLine::gpgkey;
 
   56            storeUrl( _gpgkeys[section_r], value_r );
 
   58          else if ( key_r == 
"mirrorlist" )
 
   60            _inMultiline = MultiLine::mirrorlist;
 
   61            storeUrl( _mirrorlist[section_r], value_r );
 
   63          else if ( key_r == 
"metalink" )
 
   65            _inMultiline = MultiLine::metalink;
 
   66            storeUrl( _metalink[section_r], value_r );
 
   70            _inMultiline = MultiLine::none;
 
   75        void garbageLine( 
const std::string & section_r, 
const std::string & line_r )
 override 
   77          switch ( _inMultiline )
 
   79            case MultiLine::baseurl:
 
   80              storeUrl( _baseurls[section_r], line_r );
 
   83            case MultiLine::gpgkey:
 
   84              storeUrl( _gpgkeys[section_r], line_r );
 
   87            case MultiLine::mirrorlist:
 
   88              storeUrl( _mirrorlist[section_r], line_r );
 
   91            case MultiLine::metalink:
 
   92              storeUrl( _metalink[section_r], line_r );
 
  101        std::list<Url> & baseurls( 
const std::string & section_r )
 
  102        { 
return _baseurls[section_r]; }
 
  104        std::list<Url> & gpgkeys( 
const std::string & section_r )
 
  105        { 
return _gpgkeys[section_r]; }
 
  107        std::list<Url> & mirrorlist( 
const std::string & section_r )
 
  108        { 
return _mirrorlist[section_r]; }
 
  110        std::list<Url> & metalink( 
const std::string & section_r )
 
  111        { 
return _metalink[section_r]; }
 
  114        void storeUrl( std::list<Url> & store_r, 
const std::string & line_r )
 
  117          strv::splitRx( line_r, 
"[,[:blank:]]*[[:blank:]][,[:blank:]]*", [&store_r]( std::string_view w ) {
 
  119              store_r.push_back( 
Url(std::string(w)) );
 
  123        enum class MultiLine { 
none, baseurl, gpgkey, mirrorlist, metalink };
 
  124        MultiLine _inMultiline = MultiLine::none;
 
  126        std::map<std::string,std::list<Url>> _baseurls;
 
  127        std::map<std::string,std::list<Url>> _gpgkeys;
 
  128        std::map<std::string,std::list<Url>> _mirrorlist;
 
  129        std::map<std::string,std::list<Url>> _metalink;
 
  143      RepoFileParser dict(is);
 
  144      for_( its, dict.sectionsBegin(), dict.sectionsEnd() )
 
  149        std::string proxyport;
 
  151        for_( it, dict.entriesBegin(*its), dict.entriesEnd(*its) )
 
  154          if (it->first == 
"name" )
 
  156          else if ( it->first == 
"enabled" )
 
  158          else if ( it->first == 
"priority" )
 
  160          else if ( it->first == 
"path" )
 
  162          else if ( it->first == 
"type" )
 
  164          else if ( it->first == 
"autorefresh" )
 
  166          else if ( it->first == 
"gpgcheck" )
 
  168          else if ( it->first == 
"repo_gpgcheck" )
 
  170          else if ( it->first == 
"pkg_gpgcheck" )
 
  172          else if ( it->first == 
"keeppackages" )
 
  174          else if ( it->first == 
"service" )
 
  176          else if ( it->first == 
"proxy" )
 
  185              proxy = it->second.substr( 0, it->second.size() - what[0].
size() );
 
  186              proxyport = what[0].substr( 1 );
 
  194            ERR << 
"Unknown attribute in [" << *its << 
"]: " << it->first << 
"=" << it->second << 
" ignored" << endl;
 
  197        for ( 
auto & 
url : dict.baseurls( *its ) )
 
  199          if ( ! proxy.empty() && 
url.getQueryParam( 
"proxy" ).empty() )
 
  201            url.setQueryParam( 
"proxy", proxy );
 
  202            url.setQueryParam( 
"proxyport", proxyport );
 
  207        if ( ! dict.gpgkeys( *its ).empty() )
 
  210        if ( ! dict.mirrorlist( *its ).empty() )
 
  213        if ( ! dict.metalink( *its ).empty() )
 
  226      ex.
addHistory( 
"Parsing .repo file "+is.name() );
 
 
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 setMirrorListUrls(url_set urls)
Like setMirrorListUrl but take an url_set.
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 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).
void setMetalinkUrls(url_set urls)
Like setMirrorListUrls but expect metalink format.
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.
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.
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.
bool regex_match(const std::string &s, smatch &matches, const regex ®ex)
\relates regex \ingroup ZYPP_STR_REGEX    \relates regex \ingroup ZYPP_STR_REGEX
TInt strtonum(const C_Str &str)
Parsing numbers from string.
Easy-to use interface to the ZYPP dependency resolver.
#define for_(IT, BEG, END)
Convenient for-loops using iterator.
#define ZYPP_RETHROW(EXCPT)
Drops a logline and rethrows, updating the CodeLocation.
c++17: std::string_view tools