Merge branch 'media-verif'
[platform/upstream/libzypp.git] / zypp / RepoInfo.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.cc
10  *
11 */
12 #include <iostream>
13 #include <boost/logic/tribool_io.hpp>
14
15 #include "zypp/base/Logger.h"
16
17 #include "zypp/RepoInfo.h"
18
19 using namespace std;
20 using namespace boost;
21
22 ///////////////////////////////////////////////////////////////////
23 namespace zypp
24 { /////////////////////////////////////////////////////////////////
25
26   ///////////////////////////////////////////////////////////////////
27   //
28   //    CLASS NAME : RepoInfo::Impl
29   //
30   /** RepoInfo implementation. */
31   struct RepoInfo::Impl
32   {
33
34     Impl()
35       : enabled (indeterminate),
36         autorefresh(indeterminate),
37         gpgcheck(indeterminate),
38         type(repo::RepoType::NONE_e)
39     {}
40
41     ~Impl()
42     {
43       //MIL << std::endl;
44     }
45   public:
46     boost::tribool enabled;
47     boost::tribool autorefresh;
48     boost::tribool gpgcheck;
49     Url gpgkey_url;
50     repo::RepoType type;
51     Url mirrorlist_url;
52     std::set<Url> baseUrls;
53     Pathname path;
54     std::string alias;
55     std::string name;
56     Pathname filepath;
57     Pathname metadatapath;
58   public:
59
60   private:
61     friend Impl * rwcowClone<Impl>( const Impl * rhs );
62     /** clone for RWCOW_pointer */
63     Impl * clone() const
64     { return new Impl( *this ); }
65   };
66   ///////////////////////////////////////////////////////////////////
67
68   /** \relates RepoInfo::Impl Stream output */
69   inline std::ostream & operator<<( std::ostream & str, const RepoInfo::Impl & obj )
70   {
71     return str << "RepoInfo::Impl";
72   }
73
74   ///////////////////////////////////////////////////////////////////
75   //
76   //    CLASS NAME : RepoInfo
77   //
78   ///////////////////////////////////////////////////////////////////
79
80   ///////////////////////////////////////////////////////////////////
81   //
82   //    METHOD NAME : RepoInfo::RepoInfo
83   //    METHOD TYPE : Ctor
84   //
85   RepoInfo::RepoInfo()
86   : _pimpl( new Impl() )
87   {}
88
89   ///////////////////////////////////////////////////////////////////
90   //
91   //    METHOD NAME : RepoInfo::~RepoInfo
92   //    METHOD TYPE : Dtor
93   //
94   RepoInfo::~RepoInfo()
95   {
96     //MIL << std::endl;
97   }
98
99   RepoInfo & RepoInfo::setEnabled( boost::tribool enabled )
100   {
101     _pimpl->enabled = enabled;
102     return *this;
103   }
104
105   RepoInfo & RepoInfo::setAutorefresh( boost::tribool autorefresh )
106   {
107     _pimpl->autorefresh = autorefresh;
108     return *this;
109   }
110   
111   RepoInfo & RepoInfo::setGpgCheck( boost::tribool check )
112   {
113     _pimpl->gpgcheck = check;
114     return *this;
115   }
116
117   RepoInfo & RepoInfo::setMirrorListUrl( const Url &url )
118   {
119     _pimpl->mirrorlist_url = url;
120     return *this;
121   }
122   
123   RepoInfo & RepoInfo::setGpgKeyUrl( const Url &url )
124   {
125     _pimpl->gpgkey_url = url;
126     return *this;
127   }
128
129   RepoInfo & RepoInfo::addBaseUrl( const Url &url )
130   {
131     _pimpl->baseUrls.insert(url);
132     return *this;
133   }
134
135   RepoInfo & RepoInfo::setBaseUrl( const Url &url )
136   {
137     _pimpl->baseUrls.clear();
138     addBaseUrl(url);
139     return *this;
140   }
141
142   RepoInfo & RepoInfo::setPath( const Pathname &path )
143   {
144     _pimpl->path = path;
145     return *this;
146   }
147   
148   RepoInfo & RepoInfo::setAlias( const std::string &alias )
149   {
150     _pimpl->alias = alias;
151     return *this;
152   }
153
154   RepoInfo & RepoInfo::setType( const repo::RepoType &t )
155   {
156     _pimpl->type = t;
157     return *this;
158   }
159
160   RepoInfo & RepoInfo::setName( const std::string &name )
161   {
162     _pimpl->name = name;
163     return *this;
164   }
165
166   RepoInfo & RepoInfo::setFilepath( const Pathname &filepath )
167   {
168     _pimpl->filepath = filepath;
169     return *this;
170   }
171   
172   RepoInfo & RepoInfo::setMetadataPath( const Pathname &path )
173   {
174     _pimpl->metadatapath = path;
175     return *this;
176   }
177
178   tribool RepoInfo::enabled() const
179   { return _pimpl->enabled; }
180
181   tribool RepoInfo::autorefresh() const
182   { return _pimpl->autorefresh; }
183   
184   tribool RepoInfo::gpgCheck() const
185   { return _pimpl->gpgcheck; }
186
187   std::string RepoInfo::alias() const
188   { return _pimpl->alias; }
189
190   std::string RepoInfo::name() const
191   { return _pimpl->name; }
192
193   Pathname RepoInfo::filepath() const
194   { return _pimpl->filepath; }
195
196   Pathname RepoInfo::metadataPath() const
197   { return _pimpl->metadatapath; }
198   
199   repo::RepoType RepoInfo::type() const
200   { return _pimpl->type; }
201
202   Url RepoInfo::mirrorListUrl() const
203   { return _pimpl->mirrorlist_url; }
204   
205   Url RepoInfo::gpgKeyUrl() const
206   { return _pimpl->gpgkey_url; }
207
208   std::set<Url> RepoInfo::baseUrls() const
209   { return _pimpl->baseUrls; }
210
211   Pathname RepoInfo::path() const
212   { return _pimpl->path; }
213   
214   RepoInfo::urls_const_iterator RepoInfo::baseUrlsBegin() const
215   { return _pimpl->baseUrls.begin(); }
216
217   RepoInfo::urls_const_iterator RepoInfo::baseUrlsEnd() const
218   { return _pimpl->baseUrls.end(); }
219
220   RepoInfo::urls_size_type RepoInfo::baseUrlsSize() const
221   { return _pimpl->baseUrls.size(); }
222
223   bool RepoInfo::baseUrlsEmpty() const
224   { return _pimpl->baseUrls.empty(); }
225
226   std::ostream & RepoInfo::dumpOn( std::ostream & str ) const
227   {
228     str << "--------------------------------------" << std::endl;
229     str << "- alias       : " << alias() << std::endl;
230     std::set<Url> url_set(baseUrls());
231     for ( std::set<Url>::const_iterator it = url_set.begin();
232           it != url_set.end();
233           ++it )
234     {
235       str << "- url         : " << *it << std::endl;
236     }
237     str << "- path        : " << path() << std::endl;
238     str << "- type        : " << type() << std::endl;
239     str << "- enabled     : " << enabled() << std::endl;
240     
241     str << "- autorefresh : " << autorefresh() << std::endl;
242     str << "- gpgcheck : " << gpgCheck() << std::endl;
243     str << "- gpgkey : " << gpgKeyUrl() << std::endl;
244     
245     return str;
246   }
247
248   std::ostream & RepoInfo::dumpRepoOn( std::ostream & str ) const
249   {
250     str << "[" << alias() << "]" << endl;
251     str << "name=" << name() << endl;
252
253     if ( ! baseUrls().empty() )
254       str << "baseurl=";
255     for ( urls_const_iterator it = baseUrlsBegin();
256           it != baseUrlsEnd();
257           ++it )
258     {
259       str << *it << endl;
260     }
261     
262     if ( ! path().empty() )
263       str << "path="<< path() << endl;
264     
265     if ( ! (mirrorListUrl().asString().empty()) )
266       str << "mirrorlist=" << mirrorListUrl() << endl;
267     
268     str << "type=" << type().asString() << endl;
269     
270     if ( ! indeterminate(enabled()) )
271       str << "enabled=" << (enabled() ? "1" : "0") << endl;
272     if ( ! indeterminate(autorefresh()) )
273       str << "autorefresh=" << (autorefresh() ? "1" : "0") << endl;
274     if ( ! indeterminate(gpgCheck()) )
275       str << "gpgcheck=" << (gpgCheck() ? "1" : "0") << endl;
276     if ( ! (gpgKeyUrl().asString().empty()) )
277       str << "gpgkey=" <<gpgKeyUrl() << endl;
278
279     return str;
280   }
281
282   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj )
283   {
284     return obj.dumpOn(str);
285   }
286
287   /////////////////////////////////////////////////////////////////
288 } // namespace zypp
289 ///////////////////////////////////////////////////////////////////