Imported Upstream version 17.23.5
[platform/upstream/libzypp.git] / zypp / Patch.h
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/Patch.h
10  *
11 */
12 #ifndef ZYPP_PATCH_H
13 #define ZYPP_PATCH_H
14
15 #include <zypp/base/Flags.h>
16 #include <zypp/sat/SolvAttr.h>
17 #include <zypp/ResObject.h>
18 #include <zypp/sat/SolvableSet.h>
19
20 ///////////////////////////////////////////////////////////////////
21 namespace zypp
22 { /////////////////////////////////////////////////////////////////
23
24
25   DEFINE_PTR_TYPE(Patch);
26
27
28   /**
29    * Class representing a patch.
30    *
31    * A patch represents a specific problem that
32    * can be fixed by pulling in the patch dependencies.
33    *
34    * Patches can be marked for installation but their
35    * installation is a no-op.
36    */
37   class Patch : public ResObject
38   {
39     public:
40       typedef Patch                    Self;
41       typedef ResTraits<Self>          TraitsType;
42       typedef TraitsType::PtrType      Ptr;
43       typedef TraitsType::constPtrType constPtr;
44
45     public:
46       typedef sat::SolvableSet Contents;
47
48       enum Category {
49         CAT_OTHER       = 1,    //!< unknown value specified
50         CAT_YAST        = 1<<1, //!<
51         CAT_SECURITY    = 1<<2, //!<
52         CAT_RECOMMENDED = 1<<3, //!<
53         CAT_OPTIONAL    = 1<<4, //!<
54         CAT_DOCUMENT    = 1<<5  //!<
55       };
56       ZYPP_DECLARE_FLAGS(Categories, Category);
57
58       /**
59        * Flags defining if and why this
60        * patch is interactive.
61        */
62       enum InteractiveFlag {
63         NoFlags = 0x0000,
64         Reboot  = 0x0001,
65         Message = 0x0002,
66         License = 0x0004
67       };
68       ZYPP_DECLARE_FLAGS(InteractiveFlags, InteractiveFlag);
69
70       /**
71        * \brief Possible severity levels for (security) patches.
72        * Metadata string values are mapped to this enum to ease
73        * computations. For a string representation call
74        * \ref asSring( const Patch::SeverityFlag & ).
75        */
76       enum SeverityFlag {
77         SEV_OTHER       = 1,    //!< unknown value specified
78         SEV_NONE        = 1<<1, //!< no value specified
79         SEV_LOW         = 1<<2, //!< Low
80         SEV_MODERATE    = 1<<3, //!< Moderate
81         SEV_IMPORTANT   = 1<<4, //!< Important
82         SEV_CRITICAL    = 1<<5  //!< Critical
83       };
84       ZYPP_DECLARE_FLAGS(SeverityFlags, SeverityFlag);
85
86     public:
87       /**
88        * Issue date time. For now it is the same as
89        * \ref buildtime().
90        */
91       Date timestamp() const
92       { return buildtime(); }
93
94       /** \name Patch Category */
95       //@{
96       /**
97        * Patch category (recommended, security,...)
98        */
99       std::string category() const;
100
101       /** This patch's category as enum of wellknown categories.
102        * Unknown values are mapped to \ref CAT_OTHER.
103        */
104       Category categoryEnum() const;
105
106       /** Whether this patch's category matches \a category_r */
107       bool isCategory( const std::string & category_r ) const;
108       /** \overload taking OR'ed \ref Categories */
109       bool isCategory( Categories category_r ) const;
110
111       /** \overload taking container of category strings
112        * 2nd template arg just to prevent instantiation for Category
113        */
114       template <class TContainer, typename = typename TContainer::value_type>
115       bool isCategory( const TContainer & categories_r ) const
116       {
117         for ( const std::string & el : categories_r )
118         { if ( isCategory( el ) ) return true; }
119         return false;
120       }
121
122       /** Patch category as enum of wellknown categories.
123        * Unknown values are mapped to \ref CAT_OTHER.
124        */
125       static Category categoryEnum( const std::string & category_r );
126       //@}
127
128       /** \name Patch Severity */
129       //@{
130       /**
131        * Severity string as specified in metadata.
132        * For use in computaions see \ref severityFlag.
133        */
134       std::string severity() const;
135
136       /**
137        * Severity string mapped to an enum.
138        * Unknown string values are mapped to \ref SEV_OTHER
139        */
140       SeverityFlag severityFlag() const;
141
142       /** Whether this patch's severity matches \a severity_r */
143       bool isSeverity( const std::string & severity_r ) const;
144       /** \overload taking OR'ed \ref SeverityFlags */
145       bool isSeverity( SeverityFlags severity_r ) const;
146
147       /** \overload taking container of severity strings
148        * 2nd template arg just to prevent instantiation for SeverityFlag
149        */
150       template <class TContainer, typename = typename TContainer::value_type>
151       bool isSeverity( const TContainer & severities_r ) const
152       {
153         for ( const std::string & el : severities_r )
154         { if ( isSeverity( el ) ) return true; }
155         return false;
156       }
157
158       /** Severity string mapped to an enum.
159        * Unknown string values are mapped to \ref SEV_OTHER
160        */
161       static SeverityFlag severityFlag( const std::string & category_r );
162       //@}
163
164       /**
165        * Does the system need to reboot to finish the update process?
166        */
167       bool rebootSuggested() const;
168
169       /**
170        * Does the patch affect the package manager itself?
171        * restart is suggested then
172        */
173       bool restartSuggested() const;
174
175       /**
176        * Does the patch needs the user to relogin to take effect?
177        * relogin is suggested then
178        */
179       bool reloginSuggested() const;
180
181       /**
182        * \short Information or warning to be displayed to the user
183        */
184       std::string message( const Locale & lang_r = Locale() ) const;
185
186       /**
187        * Get the InteractiveFlags of this Patch
188        */
189       InteractiveFlags interactiveFlags() const;
190
191       /**
192        * Is the patch still interactive when ignoring this flags?
193        */
194       bool interactiveWhenIgnoring( InteractiveFlags flags_r = NoFlags ) const;
195
196       /**
197        * Is the patch installation interactive? (does it need user input?)
198        *
199        * For security reasons patches requiring a reboot are not
200        * installed in an unattended mode. They are considered to be
201        * \c interactive so the user gets informed about the need for
202        * reboot. \a ignoreRebootFlag_r may be used to explicitly turn
203        * off this behavior and include those patches (unless they actually
204        * contain interactive components as well, like messages or licenses).
205        */
206       bool interactive() const;
207
208     public:
209       /**
210        * The collection of packages associated with this patch.
211        */
212       Contents contents() const;
213
214     public:
215
216       /** Query class for Patch issue references */
217       class ReferenceIterator;
218       /**
219        * Get an iterator to the beginning of the patch
220        * references. \see Patch::ReferenceIterator
221        */
222       ReferenceIterator referencesBegin() const;
223       /**
224        * Get an iterator to the end of the patch
225        * references. \see Patch::ReferenceIterator
226        */
227       ReferenceIterator referencesEnd() const;
228
229     protected:
230       friend Ptr make<Self>( const sat::Solvable & solvable_r );
231       /** Ctor */
232       Patch( const sat::Solvable & solvable_r );
233       /** Dtor */
234       virtual ~Patch();
235   };
236   ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::Categories);
237   ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
238   ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
239
240   /** \relates Patch::Category string representation.*/
241   std::string asString( const Patch::Category & obj );
242
243   /** \relates Patch::InteractiveFlag string representation.*/
244   std::string asString( const Patch::InteractiveFlag & obj );
245
246   /** \relates Patch::SeverityFlag string representation.*/
247   std::string asString( const Patch::SeverityFlag & obj );
248
249   /**
250    * Query class for Patch issue references
251    * like bugzilla and security issues the
252    * patch is supposed to fix.
253    *
254    * The iterator does not provide a dereference
255    * operator so you can do * on it, but you can
256    * access the attributes of each patch issue reference
257    * directly from the iterator.
258    *
259    * \code
260    * for ( Patch::ReferenceIterator it = patch->referencesBegin();
261    *       it != patch->referencesEnd();
262    *       ++it )
263    * {
264    *   cout << it.href() << endl;
265    * }
266    * \endcode
267    *
268    */
269   class Patch::ReferenceIterator : public boost::iterator_adaptor<
270       Patch::ReferenceIterator           // Derived
271       , sat::LookupAttr::iterator        // Base
272       , int                              // Value
273       , boost::forward_traversal_tag     // CategoryOrTraversal
274       , int                              // Reference
275   >
276   {
277     public:
278       ReferenceIterator() {}
279       explicit ReferenceIterator( const sat::Solvable & val_r );
280
281       /**
282        * The id of the reference. For bugzilla entries
283        * this is the bug number as a string.
284        */
285       std::string id() const;
286       /**
287        * Url or pointer where to find more information
288        */
289       std::string href() const;
290       /**
291        * Title describing the issue
292        */
293       std::string title() const;
294       /**
295        * Type of the reference. For example
296        * "bugzilla"
297        */
298       std::string type() const;
299
300     private:
301       friend class boost::iterator_core_access;
302       int dereference() const { return 0; }
303   };
304
305   inline Patch::ReferenceIterator Patch::referencesBegin() const
306   { return ReferenceIterator(satSolvable()); }
307
308   inline Patch::ReferenceIterator Patch::referencesEnd() const
309   { return ReferenceIterator(); }
310
311   /////////////////////////////////////////////////////////////////
312
313 } // namespace zypp
314 ///////////////////////////////////////////////////////////////////
315 #endif // ZYPP_PATCH_H