RepoFileReader.cc
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00012 #include <iostream>
00013 #include "zypp/base/Logger.h"
00014 #include "zypp/base/String.h"
00015 #include "zypp/base/Regex.h"
00016 #include "zypp/base/InputStream.h"
00017 #include "zypp/base/UserRequestException.h"
00018
00019 #include "zypp/parser/IniDict.h"
00020 #include "zypp/parser/RepoFileReader.h"
00021
00022 using std::endl;
00023 using zypp::parser::IniDict;
00024
00026 namespace zypp
00027 {
00028
00029 namespace parser
00030 {
00031
00036 static void repositories_in_stream( const InputStream &is,
00037 const RepoFileReader::ProcessRepo &callback,
00038 const ProgressData::ReceiverFnc &progress )
00039 {
00040 parser::IniDict dict(is);
00041 for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin();
00042 its != dict.sectionsEnd();
00043 ++its )
00044 {
00045 RepoInfo info;
00046 info.setAlias(*its);
00047 Url url;
00048
00049 for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
00050 it != dict.entriesEnd(*its);
00051 ++it )
00052 {
00053
00054 if (it->first == "name" )
00055 info.setName(it-> second);
00056 else if ( it->first == "enabled" )
00057 info.setEnabled( str::strToTrue( it->second ) );
00058 else if ( it->first == "priority" )
00059 info.setPriority( str::strtonum<unsigned>( it->second ) );
00060 else if ( it->first == "baseurl" && !it->second.empty())
00061 url = it->second;
00062 else if ( it->first == "path" )
00063 info.setPath( Pathname(it->second) );
00064 else if ( it->first == "type" )
00065 info.setType(repo::RepoType(it->second));
00066 else if ( it->first == "autorefresh" )
00067 info.setAutorefresh( str::strToTrue( it->second ) );
00068 else if ( it->first == "mirrorlist" && !it->second.empty())
00069 info.setMirrorListUrl(Url(it->second));
00070 else if ( it->first == "gpgkey" && !it->second.empty())
00071 info.setGpgKeyUrl( Url(it->second) );
00072 else if ( it->first == "gpgcheck" )
00073 info.setGpgCheck( str::strToTrue( it->second ) );
00074 else if ( it->first == "keeppackages" )
00075 info.setKeepPackages( str::strToTrue( it->second ) );
00076 else if ( it->first == "service" )
00077 info.setService( it->second );
00078 else if ( it->first == "proxy" )
00079 {
00080 if (it->second != "_none_" )
00081 {
00082 str::regex ex("^(.*):([0-9]+)$");
00083 str::smatch what;
00084 if(str::regex_match(it->second, what, ex)){
00085 url.setQueryParam("proxy", what[1]);
00086 url.setQueryParam("proxyport", what[2]);
00087 }
00088 }
00089 } else
00090 ERR << "Unknown attribute in [" << *its << "]: " << it->second << " ignored" << endl;
00091 }
00092 if (url.isValid())
00093 info.addBaseUrl(url);
00094 info.setFilepath(is.path());
00095 MIL << info << endl;
00096
00097 callback(info);
00098
00099
00100 }
00101 }
00102
00104
00105
00106
00108
00109 RepoFileReader::RepoFileReader( const Pathname & repo_file,
00110 const ProcessRepo & callback,
00111 const ProgressData::ReceiverFnc &progress )
00112 : _callback(callback)
00113 {
00114 repositories_in_stream(InputStream(repo_file), _callback, progress);
00115 }
00116
00117 RepoFileReader::RepoFileReader( const InputStream &is,
00118 const ProcessRepo & callback,
00119 const ProgressData::ReceiverFnc &progress )
00120 : _callback(callback)
00121 {
00122 repositories_in_stream(is, _callback, progress);
00123 }
00124
00125 RepoFileReader::~RepoFileReader()
00126 {}
00127
00128
00129 std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
00130 {
00131 return str;
00132 }
00133
00135 }
00138 }