7ddcc7c969eb2ae1a6d89a2b767b51e339125130
[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/APIConfig.h"
20
21 #include "zypp/Url.h"
22 #include "zypp/Locale.h"
23 #include "zypp/TriBool.h"
24 #include "zypp/repo/RepoType.h"
25 #include "zypp/repo/RepoVariables.h"
26
27 #include "zypp/repo/RepoInfoBase.h"
28
29 ///////////////////////////////////////////////////////////////////
30 namespace zypp
31 { /////////////////////////////////////////////////////////////////
32
33   ///////////////////////////////////////////////////////////////////
34   //
35   //    CLASS NAME : RepoInfo
36   //
37   /**
38    * \short What is known about a repository
39    *
40    * The class RepoInfo represents everything that
41    * is known about a software repository.
42    *
43    * It can be used to store information about known
44    * sources.
45    *
46    * This class tries to be compatible with the
47    * concept of a .repo file used by YUM and
48    * also available in the openSUSE build service.
49    * See <tt>man yum.conf</tt>.
50    *
51    * Example file
52    *
53    * \code
54    * [ruby]
55    * name=Ruby repository (openSUSE_10.2)
56    * type=rpm-md
57    * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
58    *         http://some.opensuse.mirror/ruby/openSUSE_10.2/
59    * gpgcheck=1
60    * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
61    * enabled=1
62    * priority=10
63    * \endcode
64    *
65    * \note A RepoInfo is a hint about how
66    * to create a Repository.
67    *
68    * \note Name, baseUrls and mirrorUrl are subject to repo variable replacement
69    * (\see \ref RepoVariablesStringReplacer).
70    */
71   class RepoInfo : public repo::RepoInfoBase
72   {
73     friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
74
75     public:
76       RepoInfo();
77       virtual ~RepoInfo();
78
79       /** Represents no Repository (one with an empty alias). */
80       static const RepoInfo noRepo;
81
82     public:
83       /**
84        * The default priority (\c 99).
85        */
86       static unsigned defaultPriority();
87       /**
88        * Repository priority for solver.
89        * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
90        */
91       unsigned priority() const;
92       /**
93        * Set repository priority for solver.
94        * A \c newval_r of \c 0 sets the default priority.
95        * \see \ref priority.
96        */
97       void setPriority( unsigned newval_r );
98
99       typedef std::list<Url>          url_set;
100       typedef url_set::size_type      urls_size_type;
101       typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
102       /**
103        * whether repository urls are available
104        */
105       bool baseUrlsEmpty() const;
106       /**
107        * Whether there are manualy configured repository urls.
108        * If \c false, a mirrorlist might be used.
109        */
110       bool baseUrlSet() const;
111       /**
112        * number of repository urls
113        */
114       urls_size_type baseUrlsSize() const;
115       /**
116        * iterator that points at begin of repository urls
117        */
118       urls_const_iterator baseUrlsBegin() const;
119       /**
120        * iterator that points at end of repository urls
121        */
122       urls_const_iterator baseUrlsEnd() const;
123
124       /**
125        * Pars pro toto: The first repository url
126        */
127       Url url() const
128       { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
129       /**
130        * Pars pro toto: The first repository raw url (no variables replaced)
131        */
132       Url rawUrl() const;
133
134       /**
135        * The complete set of repository urls
136        *
137        * These are either the configured baseurls, or if empty, the downloaded
138        * mirror list (\see \ref mirrorListUrl)
139        */
140       url_set baseUrls() const;
141       /**
142        * The complete set of raw repository urls (no variables replaced)
143        */
144       url_set rawBaseUrls() const;
145
146       /**
147        * Add a base url. \see baseUrls
148        * \param url The base url for the repository.
149        *
150        * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
151        * by addBaseUrl().
152        */
153       void addBaseUrl( const Url &url );
154       /**
155        * Clears current base URL list and adds \a url.
156        */
157       void setBaseUrl( const Url &url );
158       /**
159        * Clears current base URL list and adds an \ref url_set.
160        */
161       void setBaseUrls( url_set urls );
162
163       /**
164        * \short Repository path
165        *
166        * Pathname relative to the base Url where the product/repository
167        * is located
168        *
169        * For media containing more than one product, or repositories not
170        * located at the root of the media it is important to know the path
171        * to the product directory relative to the media root. So a media
172        * verifier can be set for that media. You may also read it as
173        * <tt>baseUrl = url to mount</tt> and <tt>path = path on the
174        * mounted media</tt>.
175        *
176        * It is not mandatory, and the default is \c /.
177        *
178        * \note As a repository can have multiple Urls, the path is unique and
179        * the same for all Urls, so it is assumed all the Urls have the
180        * same media layout.
181        *
182        */
183       Pathname path() const;
184       /**
185        * set the product path. \see path()
186        * \param path the path to the product
187        */
188       void setPath( const Pathname &path );
189
190       /**
191        * Url of a file which contains a list of repository urls
192        */
193       Url mirrorListUrl() const;
194       /**
195        * The raw mirrorListUrl (no variables replaced).
196        */
197       Url rawMirrorListUrl() const;
198       /**
199        * Set mirror list url. \see mirrorListUrl
200        * \param url The base url for the list
201        */
202       void setMirrorListUrl( const Url &url );
203
204       /**
205        * Type of repository,
206        *
207        */
208       repo::RepoType type() const;
209       /**
210        * This allows to adjust the \ref  RepoType lazy, from \c NONE to
211        * some probed value, even for const objects.
212        *
213        * This is a NOOP if the current type is not \c NONE.
214        */
215       void setProbedType( const repo::RepoType &t ) const;
216       /**
217        * set the repository type \see type
218        * \param t
219        */
220       void setType( const repo::RepoType &t );
221
222       /**
223        * \short Path where this repo metadata was read from
224        *
225        * \note could be an empty pathname for repo
226        * infos created in memory.
227        */
228       Pathname metadataPath() const;
229       /**
230        * \short set the path where the local metadata is stored
231        *
232        * The path to the metadata of this repository
233        * was defined, or empty if nowhere.
234        *
235        * \param path directory path
236        */
237       void setMetadataPath( const Pathname &path );
238
239       /**
240        * \short Path where this repo packages are cached
241        */
242       Pathname packagesPath() const;
243       /**
244        * \short set the path where the local packages are stored
245        *
246        * \param path directory path
247        */
248       void setPackagesPath( const Pathname &path );
249
250
251       /** Whether default signature checking should be performed for this repo.
252        *
253        * This will turn on \ref repoGpgCheck for signed repos and
254        * \ref pkgGpgCheck for unsigned ones or if \ref repoGpgCheck is off.
255        *
256        * The default is \c true but may be overwritten by \c zypp.conf or a \ref .repo file.
257        */
258       bool gpgCheck() const;
259       /** Set the value for \ref gpgCheck (or \c indeterminate to use the default). */
260       void setGpgCheck( TriBool value_r );
261       /** \overload \deprecated legacy and for squid */
262       void setGpgCheck( bool value_r );
263
264       /** Whether the signature of repo metadata should be checked for this repo.
265        * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
266        */
267       bool repoGpgCheck() const;
268       /** Set the value for \ref repoGpgCheck (or \c indeterminate to use the default). */
269       void setRepoGpgCheck( TriBool value_r );
270
271       /** Whether the signature of rpm packages should be checked for this repo.
272        * The default is defined by \ref gpgCheck but may be overwritten by \c zypp.conf or a \ref .repo file.
273        */
274       bool pkgGpgCheck() const;
275       /** Set the value for \ref pkgGpgCheck (or \c indeterminate to use the default). */
276       void setPkgGpgCheck( TriBool value_r );
277
278       /** Whether the repo metadata are signed and successfully validated or \c indeterminate if unsigned.
279        * The value is usually set by \ref repo::Downloader when retrieving the metadata.
280        */
281       TriBool validRepoSignature() const;
282       /** Set the value for \ref validRepoSignature (or \c indeterminate if unsigned). */
283       void setValidRepoSignature( TriBool value_r );
284
285
286       /** Whether gpgkey URLs are defined */
287       bool gpgKeyUrlsEmpty() const;
288       /** Number of gpgkey URLs defined */
289       urls_size_type gpgKeyUrlsSize() const;
290
291       /** The list of gpgkey URLs defined for this repo */
292       url_set gpgKeyUrls() const;
293       /** The list of raw gpgkey URLs defined for this repo (no variables replaced) */
294       url_set rawGpgKeyUrls() const;
295       /** Set a list of gpgkey URLs defined for this repo */
296       void setGpgKeyUrls( url_set urls );
297
298       /** (leagcy API) The 1st gpgkey URL defined for this repo */
299       Url gpgKeyUrl() const;
300       /** (leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) */
301       Url rawGpgKeyUrl() const;
302       /** (leagcy API) Set the gpgkey URL defined for this repo */
303       void setGpgKeyUrl( const Url &gpgkey );
304
305
306       /**
307        * \short Whether packages downloaded from this repository will be kept in local cache
308        */
309       bool keepPackages() const;
310       /**
311        * \short Set if packaqes downloaded from this repository will be kept in local cache
312        *
313        * If the setting is true, all downloaded packages from this repository will be
314        * copied to the local raw cache.
315        *
316        * \param keep true (keep the downloaded packages) or false (delete them after installation)
317        *
318        */
319       void setKeepPackages( bool keep );
320
321       /**
322        * Gets name of the service to which this repository belongs or empty string
323        * if it has been added manually.
324        */
325       std::string service() const;
326       /**
327        * sets service which added this repository
328        */
329       void setService( const std::string& name );
330
331       /**
332        * Distribution for which is this repository meant.
333        */
334       std::string targetDistribution() const;
335       /**
336        * Sets the distribution for which is this repository meant. This is
337        * an in-memory value only, does not get written to the .repo file upon
338        * saving.
339        */
340       void setTargetDistribution(const std::string & targetDistribution);
341
342       /** Add content keywords */
343       void addContent( const std::string & keyword_r );
344       /** \overload add keywords from container */
345       template <class _Iterator>
346       void addContentFrom( _Iterator begin_r, _Iterator end_r )
347       { for_( it, begin_r, end_r ) addContent( *it ); }
348       /** \overload  */
349       template <class _Container>
350       void addContentFrom( const _Container & container_r )
351       { addContentFrom( container_r.begin(), container_r.end() ); }
352
353       /** Check for content keywords.
354        * Checking for an empty string returns whether content kewords are
355        * known at all. They may be missing due to missing metadata in disabled
356        * repos.
357        */
358       bool hasContent( const std::string & keyword_r = std::string() ) const;
359       /** \overload check for \b all keywords being present */
360       template <class _Iterator>
361       bool hasContentAll( _Iterator begin_r, _Iterator end_r ) const
362       { for_( it, begin_r, end_r ) if ( ! hasContent( *it ) ) return false; return true; }
363       /** \overload  */
364       template <class _Container>
365       bool hasContentAll( const _Container & container_r ) const
366       { return hasContentAll( container_r.begin(), container_r.end() ); }
367       /** \overload check for \b any keyword being present */
368       template <class _Iterator>
369       bool hasContentAny( _Iterator begin_r, _Iterator end_r ) const
370       { for_( it, begin_r, end_r ) if ( hasContent( *it ) ) return true; return false; }
371       /** \overload  */
372       template <class _Container>
373       bool hasContentAny( const _Container & container_r ) const
374       { return hasContentAny( container_r.begin(), container_r.end() ); }
375
376     public:
377       /** \name Repository license
378       */
379       //@{
380       /** Whether there is a license associated with the repo. */
381       bool hasLicense() const;
382
383       /** Whether the repo license has to be accepted, e.g. there is no
384        * no acceptance needed for openSUSE.
385        */
386       bool needToAcceptLicense() const;
387
388       /** Return the best license for the current (or a specified) locale. */
389       std::string getLicense( const Locale & lang_r = Locale() ) const;
390       std::string getLicense( const Locale & lang_r = Locale() ); // LEGACY API
391
392       /** Return the locales the license is available for.
393        * \ref Locale::noCode is included in case of \c license.txt which does
394        * not specify a specific locale.
395        */
396       LocaleSet getLicenseLocales() const;
397       //@}
398
399     public:
400       /**
401        * Write a human-readable representation of this RepoInfo object
402        * into the \a str stream. Useful for logging.
403        */
404       virtual std::ostream & dumpOn( std::ostream & str ) const;
405
406       /**
407        * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
408        * Raw values, no variable replacement.
409        */
410       virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
411
412       /**
413        * Write an XML representation of this RepoInfo object.
414        * Repo variables replaced.
415        *
416        * \param str
417        * \param content this argument is ignored (used in other classed derived
418        *                from RepoInfoBase.
419        */
420       virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
421
422       class Impl;
423     private:
424       friend class RepoManager;
425       /** Raw values for RepoManager */
426       void getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const;
427
428       /** Pointer to implementation */
429       RWCOW_pointer<Impl> _pimpl;
430   };
431   ///////////////////////////////////////////////////////////////////
432
433   /** \relates RepoInfo */
434   typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
435   /** \relates RepoInfo */
436   typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
437   /** \relates RepoInfo */
438   typedef std::list<RepoInfo> RepoInfoList;
439
440   /** \relates RepoInfo Stream output */
441   std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
442
443
444   /////////////////////////////////////////////////////////////////
445 } // namespace zypp
446 ///////////////////////////////////////////////////////////////////
447 #endif // ZYPP2_REPOSITORYINFO_H