- ignore empty url keys (baseurl, mirrorlist, gpgkey) instead of throwing bad url...
[platform/upstream/libzypp.git] / zypp / parser / RepoFileReader.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/repo/RepoFileReader.cc
10  *
11 */
12 #include <iostream>
13 #include "zypp/base/Logger.h"
14 #include "zypp/base/InputStream.h"
15 #include "zypp/base/UserRequestException.h"
16
17 #include "zypp/parser/IniDict.h"
18 #include "zypp/parser/RepoFileReader.h"
19
20 using std::endl;
21 using zypp::parser::IniDict;
22
23 ///////////////////////////////////////////////////////////////////
24 namespace zypp
25 { /////////////////////////////////////////////////////////////////
26   ///////////////////////////////////////////////////////////////////
27   namespace parser
28   { /////////////////////////////////////////////////////////////////
29
30     /**
31    * \short List of RepoInfo's from a file.
32    * \param file pathname of the file to read.
33    */
34     static void repositories_in_file( const Pathname &file,
35                                       const RepoFileReader::ProcessRepo &callback,
36                                       const ProgressData::ReceiverFnc &progress )
37     {
38       InputStream is(file);
39       parser::IniDict dict(is);
40       for ( parser::IniDict::section_const_iterator its = dict.sectionsBegin();
41             its != dict.sectionsEnd();
42             ++its )
43       {
44         MIL << (*its) << endl;
45         
46         RepoInfo info;
47         info.setAlias(*its);
48                       
49         for ( IniDict::entry_const_iterator it = dict.entriesBegin(*its);
50               it != dict.entriesEnd(*its);
51               ++it )
52         {
53           //MIL << (*it).first << endl;
54           if (it->first == "name" )
55             info.setName(it-> second);
56           else if ( it->first == "enabled" )
57             info.setEnabled( it->second == "1" );
58           else if ( it->first == "baseurl" && !it->second.empty())
59             info.addBaseUrl( Url(it->second) );
60           else if ( it->first == "path" )
61             info.setPath( Pathname(it->second) );
62           else if ( it->first == "type" )
63             info.setType(repo::RepoType(it->second));
64           else if ( it->first == "autorefresh" )
65             info.setAutorefresh( it->second == "1" );
66           else if ( it->first == "mirrorlist" && !it->second.empty())
67             info.setMirrorListUrl(Url(it->second));
68           else if ( it->first == "gpgkey" && !it->second.empty())
69             info.setGpgKeyUrl( Url(it->second) );
70           else if ( it->first == "gpgcheck" )
71             info.setGpgCheck( it->second == "1" );
72           else
73             ERR << "Unknown attribute " << it->second << " ignored" << endl;
74         }
75         MIL << "Linking repo info with file " << file << endl;
76         info.setFilepath(file);
77         // add it to the list.
78         callback(info);
79         //if (!progress.tick())
80         //  ZYPP_THROW(AbortRequestException());
81       }
82     }
83
84     ///////////////////////////////////////////////////////////////////
85     //
86     //  CLASS NAME : RepoFileReader
87     //
88     ///////////////////////////////////////////////////////////////////
89
90     RepoFileReader::RepoFileReader( const Pathname & repo_file,
91                                     const ProcessRepo & callback,
92                                     const ProgressData::ReceiverFnc &progress )
93       : _callback(callback)
94     {
95       repositories_in_file(repo_file, _callback, progress);
96       //MIL << "Done" << endl;
97     }
98
99     RepoFileReader::~RepoFileReader()
100     {}
101
102     std::ostream & operator<<( std::ostream & str, const RepoFileReader & obj )
103     {
104       return str;
105     }
106
107     /////////////////////////////////////////////////////////////////
108   } // namespace parser
109   ///////////////////////////////////////////////////////////////////
110   /////////////////////////////////////////////////////////////////
111 } // namespace zypp
112 ///////////////////////////////////////////////////////////////////