1
/*---------------------------------------------------------------------\
3
| |__ / \ / / . \ . \ |
8
\---------------------------------------------------------------------*/
9
/** \file zypp/repo/RepoFileReader.cc
13
#include "zypp/base/Logger.h"
14
#include "zypp/base/String.h"
15
#include "zypp/base/Regex.h"
16
#include "zypp/base/InputStream.h"
17
#include "zypp/base/UserRequestException.h"
19
#include "zypp/parser/IniDict.h"
20
#include "zypp/parser/RepoFileReader.h"
23
using zypp::parser::IniDict;
25
///////////////////////////////////////////////////////////////////
27
{ /////////////////////////////////////////////////////////////////
28
///////////////////////////////////////////////////////////////////
30
{ /////////////////////////////////////////////////////////////////
33
* \short List of RepoInfo's from a file.
34
* \param file pathname of the file to read.
36
static void repositories_in_stream( const InputStream &is,
37
const RepoFileReader::ProcessRepo &callback,
38
const ProgressData::ReceiverFnc &progress )
40
parser::IniDict dict(is);
41
for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin();
42
its != dict.sectionsEnd();
49
for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
50
it != dict.entriesEnd(*its);
53
//MIL << (*it).first << endl;
54
if (it->first == "name" )
55
info.setName(it-> second);
56
else if ( it->first == "enabled" )
57
info.setEnabled( str::strToTrue( it->second ) );
58
else if ( it->first == "priority" )
59
info.setPriority( str::strtonum<unsigned>( it->second ) );
60
else if ( it->first == "baseurl" && !it->second.empty())
62
else if ( it->first == "path" )
63
info.setPath( Pathname(it->second) );
64
else if ( it->first == "type" )
65
info.setType(repo::RepoType(it->second));
66
else if ( it->first == "autorefresh" )
67
info.setAutorefresh( str::strToTrue( it->second ) );
68
else if ( it->first == "mirrorlist" && !it->second.empty())
69
info.setMirrorListUrl(Url(it->second));
70
else if ( it->first == "gpgkey" && !it->second.empty())
72
std::vector<std::string> keys;
73
str::split( it->second, std::back_inserter(keys) );
75
info.setGpgKeyUrl( Url(*keys.begin()) );
77
else if ( it->first == "gpgcheck" )
78
info.setGpgCheck( str::strToTrue( it->second ) );
79
else if ( it->first == "keeppackages" )
80
info.setKeepPackages( str::strToTrue( it->second ) );
81
else if ( it->first == "service" )
82
info.setService( it->second );
83
else if ( it->first == "proxy" )
85
if (it->second != "_none_" )
87
str::regex ex("^(.*):([0-9]+)$");
89
if(str::regex_match(it->second, what, ex)){
90
url.setQueryParam("proxy", what[1]);
91
url.setQueryParam("proxyport", what[2]);
95
ERR << "Unknown attribute in [" << *its << "]: " << it->first << "=" << it->second << " ignored" << endl;
99
info.setFilepath(is.path());
101
// add it to the list.
103
//if (!progress.tick())
104
// ZYPP_THROW(AbortRequestException());
108
///////////////////////////////////////////////////////////////////
110
// CLASS NAME : RepoFileReader
112
///////////////////////////////////////////////////////////////////
114
RepoFileReader::RepoFileReader( const Pathname & repo_file,
115
const ProcessRepo & callback,
116
const ProgressData::ReceiverFnc &progress )
117
: _callback(callback)
119
repositories_in_stream(InputStream(repo_file), _callback, progress);
122
RepoFileReader::RepoFileReader( const InputStream &is,
123
const ProcessRepo & callback,
124
const ProgressData::ReceiverFnc &progress )
125
: _callback(callback)
127
repositories_in_stream(is, _callback, progress);
130
RepoFileReader::~RepoFileReader()
134
std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
139
/////////////////////////////////////////////////////////////////
140
} // namespace parser
141
///////////////////////////////////////////////////////////////////
142
/////////////////////////////////////////////////////////////////
144
///////////////////////////////////////////////////////////////////