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