1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/RepoInfo.h
12 #ifndef ZYPP2_REPOSITORYINFO_H
13 #define ZYPP2_REPOSITORYINFO_H
18 #include "zypp/base/Iterator.h"
19 #include "zypp/APIConfig.h"
22 #include "zypp/Locale.h"
23 #include "zypp/TriBool.h"
24 #include "zypp/base/EnumClass.h"
25 #include "zypp/repo/RepoType.h"
26 #include "zypp/repo/RepoVariables.h"
28 #include "zypp/repo/RepoInfoBase.h"
30 ///////////////////////////////////////////////////////////////////
32 { /////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////
36 // CLASS NAME : RepoInfo
39 * \short What is known about a repository
41 * The class RepoInfo represents everything that
42 * is known about a software repository.
44 * It can be used to store information about known
47 * This class tries to be compatible with the
48 * concept of a .repo file used by YUM and
49 * also available in the openSUSE build service.
50 * See <tt>man yum.conf</tt>.
56 * name=Ruby repository (openSUSE_10.2)
58 * baseurl=http://software.opensuse.org/download/ruby/openSUSE_10.2/
59 * http://some.opensuse.mirror/ruby/openSUSE_10.2/
61 * gpgkey=http://software.opensuse.org/openSUSE-Build-Service.asc
66 * \note A RepoInfo is a hint about how
67 * to create a Repository.
69 * \note Name, baseUrls and mirrorUrl are subject to repo variable replacement
70 * (\see \ref RepoVariablesStringReplacer).
72 class RepoInfo : public repo::RepoInfoBase
74 friend std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
80 /** Represents no Repository (one with an empty alias). */
81 static const RepoInfo noRepo;
85 * The default priority (\c 99).
87 static unsigned defaultPriority();
89 * Repository priority for solver.
90 * Some number between \c 1 (highest priority) and \c 99 (\ref defaultPriority).
92 unsigned priority() const;
94 * Set repository priority for solver.
95 * A \c newval_r of \c 0 sets the default priority.
98 void setPriority( unsigned newval_r );
100 typedef std::list<Url> url_set;
101 typedef url_set::size_type urls_size_type;
102 typedef transform_iterator<repo::RepoVariablesUrlReplacer, url_set::const_iterator> urls_const_iterator;
104 * whether repository urls are available
106 bool baseUrlsEmpty() const;
108 * Whether there are manualy configured repository urls.
109 * If \c false, a mirrorlist might be used.
111 bool baseUrlSet() const;
113 * number of repository urls
115 urls_size_type baseUrlsSize() const;
117 * iterator that points at begin of repository urls
119 urls_const_iterator baseUrlsBegin() const;
121 * iterator that points at end of repository urls
123 urls_const_iterator baseUrlsEnd() const;
126 * Pars pro toto: The first repository url
129 { return( baseUrlsEmpty() ? Url() : *baseUrlsBegin()); }
131 * Pars pro toto: The first repository raw url (no variables replaced)
136 * The complete set of repository urls
138 * These are either the configured baseurls, or if empty, the downloaded
139 * mirror list (\see \ref mirrorListUrl)
141 url_set baseUrls() const;
143 * The complete set of raw repository urls (no variables replaced)
145 url_set rawBaseUrls() const;
148 * Add a base url. \see baseUrls
149 * \param url The base url for the repository.
151 * To recreate the base URLs list, use \ref setBaseUrl(const Url &) followed
154 void addBaseUrl( const Url &url );
156 * Clears current base URL list and adds \a url.
158 void setBaseUrl( const Url &url );
160 * Clears current base URL list and adds an \ref url_set.
162 void setBaseUrls( url_set urls );
165 * \short Repository path
167 * Pathname relative to the base Url where the product/repository
170 * For media containing more than one product, or repositories not
171 * located at the root of the media it is important to know the path
172 * to the product directory relative to the media root. So a media
173 * verifier can be set for that media. You may also read it as
174 * <tt>baseUrl = url to mount</tt> and <tt>path = path on the
175 * mounted media</tt>.
177 * It is not mandatory, and the default is \c /.
179 * \note As a repository can have multiple Urls, the path is unique and
180 * the same for all Urls, so it is assumed all the Urls have the
184 Pathname path() const;
186 * set the product path. \see path()
187 * \param path the path to the product
189 void setPath( const Pathname &path );
192 * Url of a file which contains a list of repository urls
194 Url mirrorListUrl() const;
196 * The raw mirrorListUrl (no variables replaced).
198 Url rawMirrorListUrl() const;
200 * Set mirror list url. \see mirrorListUrl
201 * \param url The base url for the list
203 void setMirrorListUrl( const Url &url );
206 * Type of repository,
209 repo::RepoType type() const;
211 * This allows to adjust the \ref RepoType lazy, from \c NONE to
212 * some probed value, even for const objects.
214 * This is a NOOP if the current type is not \c NONE.
216 void setProbedType( const repo::RepoType &t ) const;
218 * set the repository type \see type
221 void setType( const repo::RepoType &t );
224 * \short Path where this repo metadata was read from
226 * \note could be an empty pathname for repo
227 * infos created in memory.
229 Pathname metadataPath() const;
231 * \short set the path where the local metadata is stored
233 * The path to the metadata of this repository
234 * was defined, or empty if nowhere.
236 * \param path directory path
238 void setMetadataPath( const Pathname &path );
241 * \short Path where this repo packages are cached
243 Pathname packagesPath() const;
245 * \short set the path where the local packages are stored
247 * \param path directory path
249 void setPackagesPath( const Pathname &path );
252 /** \name Repository gpgchecks
253 * How signature checking should be performed for this repo.
255 * The values are computed based in the settings of \c gpgcheck, \c repo_gpgcheck
256 * end \c pkg_gpgcheck in \c zypp.conf. Explicitly setting these values in the
257 * repositories \a .repo file will overwrite the defaults from \c zypp.conf for this
260 * If \c gpgcheck is \c on (the default) we will check the signature of repo metadata
261 * (packages are secured via checksum inside the metadata). Using unsigned repos
262 * needs to be confirmed.
263 * Packages from signed repos are accepted if their checksum matches the checksum
264 * stated in the repo metadata.
265 * Packages from unsigned repos need a valid gpg signature, using unsigned packages
266 * needs to be confirmed.
268 * The above default behavior can be tuned by explicitly setting \c repo_gpgcheck
269 * and/or \c pkg_gpgcheck:
271 * \c repo_gpgcheck = \c on same as the default.
273 * \c repo_gpgcheck = \c off will silently accept unsigned repos. It will NOT turn of
274 * signature checking on the whole, nevertheless it's not a secure setting.
276 * \c pkg_gpgcheck = \c on will enforce the package signature checking and the need
277 * to confirm unsigned packages for all repos (signed and unsigned).
279 * \c pkg_gpgcheck = \c off will silently accept unsigned packages. It will NOT turn of
280 * signature checking on the whole, nevertheless it's not a secure setting.
282 * If \c gpgCheck is \c off (not recommneded), no checks are performed. You can still
283 * enable them individually by setting \c repo_gpgcheck and/or \c pkg_gpgcheck to \c on.
286 * R: check repo signature is mandatory, confirm unsigned repos
287 * r: check repo signature, unsigned repos are ok but enforce p
288 * : do not check repo signatures
290 * P: check package signature always, confirm unsigned packages
291 * p: like P for unsigned repos, accepted by checksum for signed repos
292 * b: like p but accept unsigned packages
293 * : do not check package signatures
296 * ------------------------------------
297 * repo_ *1| R/p R/b R/P
302 * ------------------------------------
308 /** Whether default signature checking should be performed. */
309 bool gpgCheck() const;
310 /** Set the value for \ref gpgCheck (or \c indeterminate to use the default). */
311 void setGpgCheck( TriBool value_r );
312 /** \overload \deprecated legacy and for squid */
313 void setGpgCheck( bool value_r );
315 /** Whether the signature of repo metadata should be checked for this repo. */
316 bool repoGpgCheck() const;
317 /** Mandatory check (\ref repoGpgCheck is \c on) must ask to confirm using unsigned repos. */
318 bool repoGpgCheckIsMandatory() const;
319 /** Set the value for \ref repoGpgCheck (or \c indeterminate to use the default). */
320 void setRepoGpgCheck( TriBool value_r );
322 /** Whether the signature of rpm packages should be checked for this repo. */
323 bool pkgGpgCheck() const;
324 /** Mandatory check (\ref pkgGpgCheck is not \c off) must ask to confirm using unsigned packages. */
325 bool pkgGpgCheckIsMandatory() const;
326 /** Set the value for \ref pkgGpgCheck (or \c indeterminate to use the default). */
327 void setPkgGpgCheck( TriBool value_r );
329 /** Whether the repo metadata are signed and successfully validated or \c indeterminate if unsigned.
330 * The value is usually set by \ref repo::Downloader when retrieving the metadata.
332 TriBool validRepoSignature() const;
333 /** Set the value for \ref validRepoSignature (or \c indeterminate if unsigned). */
334 void setValidRepoSignature( TriBool value_r );
336 /** Some predefined settings (use like 'enum class \ref GpgCheck') */
339 indeterminate, //< not specified
340 On, //< 1** --gpgcheck
341 Strict, //< 111 --gpgcheck-strict
342 AllowUnsigned, //< 100 --gpgcheck-allow-unsigned
343 AllowUnsignedRepo, //< 10* --gpgcheck-allow-unsigned-repo
344 AllowUnsignedPackage, //< 1*0 --gpgcheck-allow-unsigned-package
345 Default, //< *** --default-gpgcheck
346 Off, //< 0** --no-gpgcheck
349 typedef base::EnumClass<GpgCheckDef> GpgCheck; ///< 'enum class GpgCheck'
351 /** Adjust *GpgCheck settings according to \a mode_r.
352 * \c GpgCheck::indeterminate will leave the settings as they are.
353 * \return whether setting were changed
355 bool setGpgCheck( GpgCheck mode_r );
359 /** Whether gpgkey URLs are defined */
360 bool gpgKeyUrlsEmpty() const;
361 /** Number of gpgkey URLs defined */
362 urls_size_type gpgKeyUrlsSize() const;
364 /** The list of gpgkey URLs defined for this repo */
365 url_set gpgKeyUrls() const;
366 /** The list of raw gpgkey URLs defined for this repo (no variables replaced) */
367 url_set rawGpgKeyUrls() const;
368 /** Set a list of gpgkey URLs defined for this repo */
369 void setGpgKeyUrls( url_set urls );
371 /** (leagcy API) The 1st gpgkey URL defined for this repo */
372 Url gpgKeyUrl() const;
373 /** (leagcy API) The 1st raw gpgkey URL defined for this repo (no variables replaced) */
374 Url rawGpgKeyUrl() const;
375 /** (leagcy API) Set the gpgkey URL defined for this repo */
376 void setGpgKeyUrl( const Url &gpgkey );
380 * \short Whether packages downloaded from this repository will be kept in local cache
382 bool keepPackages() const;
384 * \short Set if packaqes downloaded from this repository will be kept in local cache
386 * If the setting is true, all downloaded packages from this repository will be
387 * copied to the local raw cache.
389 * \param keep true (keep the downloaded packages) or false (delete them after installation)
392 void setKeepPackages( bool keep );
395 * Gets name of the service to which this repository belongs or empty string
396 * if it has been added manually.
398 std::string service() const;
400 * sets service which added this repository
402 void setService( const std::string& name );
405 * Distribution for which is this repository meant.
407 std::string targetDistribution() const;
409 * Sets the distribution for which is this repository meant. This is
410 * an in-memory value only, does not get written to the .repo file upon
413 void setTargetDistribution(const std::string & targetDistribution);
415 /** Add content keywords */
416 void addContent( const std::string & keyword_r );
417 /** \overload add keywords from container */
418 template <class _Iterator>
419 void addContentFrom( _Iterator begin_r, _Iterator end_r )
420 { for_( it, begin_r, end_r ) addContent( *it ); }
422 template <class _Container>
423 void addContentFrom( const _Container & container_r )
424 { addContentFrom( container_r.begin(), container_r.end() ); }
426 /** Check for content keywords.
427 * Checking for an empty string returns whether content kewords are
428 * known at all. They may be missing due to missing metadata in disabled
431 bool hasContent( const std::string & keyword_r = std::string() ) const;
432 /** \overload check for \b all keywords being present */
433 template <class _Iterator>
434 bool hasContentAll( _Iterator begin_r, _Iterator end_r ) const
435 { for_( it, begin_r, end_r ) if ( ! hasContent( *it ) ) return false; return true; }
437 template <class _Container>
438 bool hasContentAll( const _Container & container_r ) const
439 { return hasContentAll( container_r.begin(), container_r.end() ); }
440 /** \overload check for \b any keyword being present */
441 template <class _Iterator>
442 bool hasContentAny( _Iterator begin_r, _Iterator end_r ) const
443 { for_( it, begin_r, end_r ) if ( hasContent( *it ) ) return true; return false; }
445 template <class _Container>
446 bool hasContentAny( const _Container & container_r ) const
447 { return hasContentAny( container_r.begin(), container_r.end() ); }
450 /** \name Repository license
453 /** Whether there is a license associated with the repo. */
454 bool hasLicense() const;
456 /** Whether the repo license has to be accepted, e.g. there is no
457 * no acceptance needed for openSUSE.
459 bool needToAcceptLicense() const;
461 /** Return the best license for the current (or a specified) locale. */
462 std::string getLicense( const Locale & lang_r = Locale() ) const;
463 std::string getLicense( const Locale & lang_r = Locale() ); // LEGACY API
465 /** Return the locales the license is available for.
466 * \ref Locale::noCode is included in case of \c license.txt which does
467 * not specify a specific locale.
469 LocaleSet getLicenseLocales() const;
474 * Write a human-readable representation of this RepoInfo object
475 * into the \a str stream. Useful for logging.
477 virtual std::ostream & dumpOn( std::ostream & str ) const;
480 * Write this RepoInfo object into \a str in a <tr>.repo</tt> file format.
481 * Raw values, no variable replacement.
483 virtual std::ostream & dumpAsIniOn( std::ostream & str ) const;
486 * Write an XML representation of this RepoInfo object.
487 * Repo variables replaced.
490 * \param content this argument is ignored (used in other classed derived
493 virtual std::ostream & dumpAsXmlOn( std::ostream & str, const std::string & content = "" ) const;
497 friend class RepoManager;
498 /** Raw values for RepoManager */
499 void getRawGpgChecks( TriBool & g_r, TriBool & r_r, TriBool & p_r ) const;
501 /** Pointer to implementation */
502 RWCOW_pointer<Impl> _pimpl;
504 ///////////////////////////////////////////////////////////////////
506 /** \relates RepoInfo */
507 typedef shared_ptr<RepoInfo> RepoInfo_Ptr;
508 /** \relates RepoInfo */
509 typedef shared_ptr<const RepoInfo> RepoInfo_constPtr;
510 /** \relates RepoInfo */
511 typedef std::list<RepoInfo> RepoInfoList;
513 /** \relates RepoInfo Stream output */
514 std::ostream & operator<<( std::ostream & str, const RepoInfo & obj );
516 /** \relates RepoInfo::GpgCheck Stream output */
517 std::ostream & operator<<( std::ostream & str, const RepoInfo::GpgCheck & obj );
519 /////////////////////////////////////////////////////////////////
521 ///////////////////////////////////////////////////////////////////
522 #endif // ZYPP2_REPOSITORYINFO_H