1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/repo/RepoVariables.h
11 #ifndef ZYPP_REPO_VARIABLES_H_
12 #define ZYPP_REPO_VARIABLES_H_
15 #include "zypp/base/Function.h"
16 #include "zypp/base/ValueTransform.h"
19 ///////////////////////////////////////////////////////////////////
22 ///////////////////////////////////////////////////////////////////
25 ///////////////////////////////////////////////////////////////////
26 /// \class RepoVarExpand
27 /// \brief Functor expanding repo variables in a string
29 /// Known variables are determined by a callback function taking a variable
30 /// name and returning a pointer to the variable value or \c nullptr if unset.
32 /// The \c $ character introduces variable expansion. A valid variable name
33 /// is any non-empty case-insensitive sequence of <tt>[[:alnum:]_]</tt>.
34 /// The variable name to be expanded may be enclosed in braces, which are
35 /// optional but serve to protect the variable to be expanded from characters
36 /// immediately following it which could be interpreted as part of the name.
38 /// When braces are used, the matching ending brace is the first \c } not
39 /// escaped by a backslash and not within an embedded variable expansion.
40 /// Within braces only \c $, \c } and \c backslash are escaped by a
41 /// backslash. There is no escaping outside braces, to stay comaptible
42 /// with \c YUM (which does not support braces).
45 /// <li> \c ${variable}
46 /// If \c variable is unset the original is preserved like in \c YUM.
47 /// Otherwise, the value of \c variable is substituted.</li>
49 /// <li> \c ${variable:-word} (default value)
50 /// If \c variable is unset or empty, the expansion of \c word is substituted.
51 /// Otherwise, the value of \c variable is substituted.</li>
53 /// <li> \c ${variable:+word} (alternate value)
54 /// If variable is unset or empty nothing is substituted.
55 /// Otherwise, the expansion of \c word is substituted.</li>
59 /** Function taking a variable name and returning a pointer to the variable value or \c nullptr if unset. */
60 typedef function<const std::string * ( const std::string & )> VarRetriever;
62 /** Return a copy of \a value_r with embedded variables expanded. */
63 std::string operator()( const std::string & value_r, VarRetriever varRetriever_r ) const;
64 #ifndef SWIG // Swig treats it as syntax error
65 /** \overload moving */
66 std::string operator()( std::string && value_r, VarRetriever varRetriever_r ) const;
71 * \short Functor replacing repository variables
73 * Replaces the built-in '$arch', '$basearch' and '$releasever' ans also
74 * custom repo variables (\see \ref zypp-repovars) in a string with the
77 * Additionally $releasever_major and $releasever_minor can be used
78 * to refer to $releasever major number (everything up to the 1st \c '.' )
79 * and minor number (everything after the 1st \c '.' ).
81 * \note The $releasever value is overwritten by the environment
82 * variable \c ZYPP_REPO_RELEASEVER. This might be handy for
83 * distribution upogrades like this:
85 * $ export ZYPP_REPO_RELEASEVER=13.2
88 * ....upgrades to 13.2...
90 * The same can be achieved by using zyppers --releasever global option:
92 * $ zypper --releasever 13.2 lr -u
93 * $ zypper --releasever 13.2 dup
94 * ....upgrades to 13.2...
96 * (see \ref zypp-envars)
100 * ftp://user:secret@site.net/$arch/ -> ftp://user:secret@site.net/i686/
101 * http://site.net/?basearch=$basearch -> http://site.net/?basearch=i386
104 * \see \ref RepoVarExpand for supported variable syntax.
106 struct RepoVariablesStringReplacer : public std::unary_function<const std::string &, std::string>
108 std::string operator()( const std::string & value_r ) const;
109 #ifndef SWIG // Swig treats it as syntax error
110 /** \overload moving */
111 std::string operator()( std::string && value_r ) const;
116 * \short Functor replacing repository variables
118 * Replaces repository variables in the path and query part of the URL.
119 * \see RepoVariablesStringReplacer
121 struct RepoVariablesUrlReplacer : public std::unary_function<const Url &, Url>
123 Url operator()( const Url & url_r ) const;
126 ///////////////////////////////////////////////////////////////////
128 /** \relates RepoVariablesStringReplacer Helper managing repo variables replaced strings */
129 typedef base::ValueTransform<std::string, repo::RepoVariablesStringReplacer> RepoVariablesReplacedString;
131 /** \relates RepoVariablesStringReplacer Helper managing repo variables replaced string lists */
132 typedef base::ContainerTransform<std::list<std::string>, repo::RepoVariablesStringReplacer> RepoVariablesReplacedStringList;
134 /** \relates RepoVariablesUrlReplacer Helper managing repo variables replaced urls */
135 typedef base::ValueTransform<Url, repo::RepoVariablesUrlReplacer> RepoVariablesReplacedUrl;
137 /** \relates RepoVariablesUrlReplacer Helper managing repo variables replaced url lists */
138 typedef base::ContainerTransform<std::list<Url>, repo::RepoVariablesUrlReplacer> RepoVariablesReplacedUrlList;
141 ///////////////////////////////////////////////////////////////////