libzypp  10.5.0
RepoFileReader.cc
Go to the documentation of this file.
00001 /*---------------------------------------------------------------------\
00002 |                          ____ _   __ __ ___                          |
00003 |                         |__  / \ / / . \ . \                         |
00004 |                           / / \ V /|  _/  _/                         |
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           //MIL << (*it).first << endl;
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           {
00072             std::vector<std::string> keys;
00073             str::split( it->second, std::back_inserter(keys) );
00074             if ( ! keys.empty() ) 
00075               info.setGpgKeyUrl( Url(*keys.begin()) );
00076           }
00077           else if ( it->first == "gpgcheck" )
00078             info.setGpgCheck( str::strToTrue( it->second ) );
00079           else if ( it->first == "keeppackages" )
00080             info.setKeepPackages( str::strToTrue( it->second ) );
00081           else if ( it->first == "service" )
00082             info.setService( it->second );
00083           else if ( it->first == "proxy" )
00084           {
00085             if (it->second != "_none_" )
00086             { 
00087               str::regex ex("^(.*):([0-9]+)$");
00088               str::smatch what;
00089               if(str::regex_match(it->second, what, ex)){
00090                url.setQueryParam("proxy", what[1]);
00091                url.setQueryParam("proxyport", what[2]);
00092               }
00093             }
00094           } else
00095             ERR << "Unknown attribute in [" << *its << "]: " << it->second << " ignored" << endl;
00096         }
00097         if (url.isValid())
00098             info.addBaseUrl(url);
00099         info.setFilepath(is.path());
00100         MIL << info << endl;
00101         // add it to the list.
00102         callback(info);
00103         //if (!progress.tick())
00104         //  ZYPP_THROW(AbortRequestException());
00105       }
00106     }
00107 
00109     //
00110     //  CLASS NAME : RepoFileReader
00111     //
00113 
00114     RepoFileReader::RepoFileReader( const Pathname & repo_file,
00115                                     const ProcessRepo & callback,
00116                                     const ProgressData::ReceiverFnc &progress )
00117       : _callback(callback)
00118     {
00119       repositories_in_stream(InputStream(repo_file), _callback, progress);
00120     }
00121 
00122     RepoFileReader::RepoFileReader( const InputStream &is,
00123                                     const ProcessRepo & callback,
00124                                     const ProgressData::ReceiverFnc &progress )
00125       : _callback(callback)
00126     {
00127       repositories_in_stream(is, _callback, progress);
00128     }
00129 
00130     RepoFileReader::~RepoFileReader()
00131     {}
00132 
00133 
00134     std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
00135     {
00136       return str;
00137     }
00138 
00140   } // namespace parser
00143 } // namespace zypp