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