- For retrieving a product license fall back to license.tar.gz. (bnc #372386)
[platform/upstream/libzypp.git] / zypp / RepoInfo.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file       zypp/RepoInfo.h
10  *
11 */
12 #ifndef ZYPP2_REPOSITORYINFO_H
13 #define ZYPP2_REPOSITORYINFO_H
14
15 #include <list>
16 #include <set>
17
18 #include "zypp/base/Iterator.h"
19 #include "zypp/base/Deprecated.h"
20
21 #include "zypp/Url.h"
22 #include "zypp/Locale.h"
23 #include "zypp/repo/RepoType.h"
24 #include "zypp/repo/RepoVariables.h"
25
26 #include "zypp/repo/RepoInfoBase.h"
27
28 ///////////////////////////////////////////////////////////////////
29 namespace zypp
30 { /////////////////////////////////////////////////////////////////
31
32   ///////////////////////////////////////////////////////////////////
33   //
34   //    CLASS NAME : RepoInfo
35   //
36   /**
37    * \short What is known about a repository
38    *
39    * The class RepoInfo represents everything that
40    * is known about a software repository.
41    *
42    * It can be used to store information about known
43    * sources.
44    *
45    * This class tries to be compatible with the
46    * concept of a .repo file used by YUM and
47    * also available in the openSUSE build service.
48    * See <tt>man yum.conf</tt>.
49    *
50    * Example file
51    *
52    * \code
53    * [ruby]
54    * name=Ruby repository (openSUSE_10.2)
55    * type=rpm-md
56    * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
57    * gpgcheck=1
58    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
59    * enabled=1
60    * priority=10
61    * \endcode
62    *
63    * \note A RepoInfo is a hint about how
64    * to create a Repository.
65    */
66   class RepoInfo : public repo::RepoInfoBase
67   {
68     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
69
70     public:
71       RepoInfo();
72       virtual ~RepoInfo();
73
74       /** Represents no Repository (one with an empty alias). */
75       static const RepoInfo noRepo;
76
77     public:
78       /**
79        * The default priority (\c 99).
80        */
81       static unsigned defaultPriority();
82       /**
83        * Repository priority for solver.
84        * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
85        */
86       unsigned priority() const;
87       /**
88        * Set repository priority for solver.
89        * A \c newval_r of \c 0 sets the default priority.
90        * \see \ref priority.
91        */
92       void setPriority( unsigned newval_r );
93
94       typedef std::set<Url>           url_set;
95       typedef url_set::size_type      urls_size_type;
96       typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
97       /**
98        * whether repository urls are available
99        */
100       bool baseUrlsEmpty() const;
101       /**
102        * number of repository urls
103        */
104       urls_size_type baseUrlsSize() const;
105       /**
106        * iterator that points at begin of repository urls
107        */
108       urls_const_iterator baseUrlsBegin() const;
109       /**
110        * iterator that points at end of repository urls
111        */
112       urls_const_iterator baseUrlsEnd() const;
113       /**
114        * A Url under which the metadata are located, or a set of mirrors.
115        *
116        * This can't be empty in order the repository to be valid
117        * unless the download of the mirror list succeeds and it
118        * contains a valid url.
119        *
120        * \deprecated IMO superfluous as we provide begin/end iterator.
121        */
122       std::set<Url> baseUrls() const;
123       /**
124        * Add a base url. \see baseUrls
125        * \param url The base url for the repository.
126        * \note can change keepPackages,so change it after this call
127        *
128        * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
129        * by addBaseUrl().
130        */
131       void addBaseUrl( const Url &url );
132       /**
133        * Clears current base URL list and adds \a url.
134        * \note can change keepPackages,so change it after this call
135        */
136       void setBaseUrl( const Url &url );
137
138       /**
139        * \short Repository path
140        *
141        * Pathname relative to the base Url where the product/repository
142        * is located
143        *
144        * For medias containing more than one product, or repositories not
145        * located at the root of the media it is important to
146        * know the path of the media root relative to the product directory
147        * so a media verifier can be set for that media.
148        *
149        * It is not mandatory, and the default is /
150        *
151        * \note As a repository can have multiple Urls, the path is unique and
152        * the same for all Urls, so it is assumed all the Urls have the
153        * same media layout.
154        *
155        */
156       Pathname path() const;
157       /**
158        * set the product path. \see path()
159        * \param path the path to the product
160        */
161       void setPath( const Pathname &path );
162
163       /**
164        * Url of a file which contains a list of Urls
165        * If empty, the base url will be used.
166        */
167       Url mirrorListUrl() const;
168       /**
169        * Set mirror list url. \see mirrorListUrl
170        * \param url The base url for the list
171        */
172       void setMirrorListUrl( const Url &url );
173
174       /**
175        * Type of repository,
176        *
177        */
178       repo::RepoType type() const;
179       /**
180        * This allows to adjust the \ref  RepoType lazy, from \c NONE to
181        * some probed value, even for const objects.
182        *
183        * This is a NOOP if the current type is not \c NONE.
184        */
185       void setProbedType( const repo::RepoType &t ) const;
186       /**
187        * set the repository type \see type
188        * \param t
189        */
190       void setType( const repo::RepoType &t );
191
192       /**
193        * \short Path where this repo metadata was read from
194        *
195        * \note could be an empty pathname for repo
196        * infos created in memory.
197        */
198       Pathname metadataPath() const;
199       /**
200        * \short set the path where the local metadata is stored
201        *
202        * The path to the metadata of this repository
203        * was defined, or empty if nowhere.
204        *
205        * \param path directory path
206        */
207       void setMetadataPath( const Pathname &path );
208
209       /**
210        * \short Path where this repo packages are cached
211        */
212       Pathname packagesPath() const;
213       /**
214        * \short set the path where the local packages are stored
215        *
216        * \param path directory path
217        */
218       void setPackagesPath( const Pathname &path );
219
220       /**
221        * \short Whether to check or not this repository with gpg
222        *
223        * \note This is a just a hint to the application and can
224        * be ignored.
225        *
226        */
227       bool gpgCheck() const;
228       /**
229        * \short Whether to check or not this repository with gpg
230        *
231        * \param check true (check) or false (dont'check)
232        *
233        * \note This is a just a hint to the application and can
234        * be ignored.
235        *
236        */
237       void setGpgCheck( bool check );
238
239       /**
240        * \short Key to use for gpg checking of this repository
241        *
242        * \param url Url to the key in ASCII armored format
243        *
244        * \note This is a just a hint to the application and can
245        * be ignored.
246        *
247        */
248       Url gpgKeyUrl() const;
249       /**
250        * \short Key to use for gpg checking of this repository
251        *
252        * \param url Url to the key in ASCII armored format
253        *
254        * \note This is a just a hint to the application and can
255        * be ignored.
256        *
257        */
258       void setGpgKeyUrl( const Url &gpgkey );
259
260       /**
261        * \short Whether to keep the packages downloaded from this repository will be kept in local cache
262        */
263       bool keepPackages() const;
264       /**
265        * \short Set if the packaqes downloaded from this repository will be kept in local cache
266        *
267        * If the setting is true, all downloaded packages from this repository will be
268        * copied to the local raw cache.
269        *
270        * \param keep true (keep the downloaded packages) or false (delete them after installation)
271        *
272        */
273       void setKeepPackages( bool keep );
274
275       /**
276        * Gets name of the service to which this repository belongs or empty string
277        * if it has been added manually.
278        */
279       std::string service() const;
280       /**
281        * sets service which added this repository
282        */
283       void setService( const std::string& name );
284
285       /**
286        * Distribution for which is this repository meant.
287        */
288       std::string targetDistribution() const;
289       /**
290        * Sets the distribution for which is this repository meant. This is
291        * an in-memory value only, does not get written to the .repo file upon
292        * saving.
293        */
294       void setTargetDistribution(const std::string & targetDistribution);
295
296     public:
297       /** \name Repository license
298       */
299       //@{
300       /** Whether there is a license associated with the repo. */
301       bool hasLicense() const;
302
303       /** Return the best license for the current (or a specified) locale. */
304       std::string getLicense( const Locale & lang_r = Locale() );
305
306       /** Return the locales the license is available for.
307        * \ref Locale::noCode is included in case of \c license.txt which does
308        * not specify a specific locale.
309       */
310       LocaleSet getLicenseLocales() const;
311       //@}
312     public:
313       /**
314        * Write a human-readable representation of this RepoInfo object
315        * into the \a str stream. Useful for logging.
316        */
317       virtual std::ostream & dumpOn( std::ostream & str ) const;
318
319       /**
320        * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
321        */
322       virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
323
324       /**
325        * Write an XML representation of this RepoInfo object.
326        */
327       virtual std::ostream & dumpAsXMLOn(std::ostream & str) const;
328
329       /**
330        * Write an XML representation of this RepoInfo object.
331        *
332        * \param str
333        * \param content this argument is ignored (used in other classed derived
334        *                from RepoInfoBase.
335        */
336       virtual std::ostream & dumpAsXMLOn( std::ostream & str, const std::string & content ) const;
337
338       class Impl;
339     private:
340       /** Pointer to implementation */
341       RWCOW_pointer<Impl> _pimpl;
342   };
343   ///////////////////////////////////////////////////////////////////
344
345   /** \relates RepoInfo */
346   typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
347   /** \relates RepoInfo */
348   typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
349   /** \relates RepoInfo */
350   typedef std::list<RepoInfo> RepoInfoList;
351
352   /** \relates RepoInfo Stream output */
353   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
354
355
356   /////////////////////////////////////////////////////////////////
357 } // namespace zypp
358 ///////////////////////////////////////////////////////////////////
359 #endif // ZYPP2_REPOSITORYINFO_H