Merge pull request #23 from openSUSE/drop_package_manager
[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       /**
93        * Patch category (recommended, security,...)
94        */
95       std::string category() const;
96
97       /** Patch category as enum of wellknown categories.
98        * Unknown values are mapped to \ref CAT_OTHER.
99        */
100       Category categoryEnum() const;
101
102       /**
103        * Severity string as specified in metadata.
104        * For use in computaions see \ref severityFlag.
105        */
106       std::string severity() const;
107
108       /**
109        * Severity string mapped to an enum.
110        * Unknown string values are mapped to \ref SEV_OTHER
111        */
112       SeverityFlag severityFlag() const;
113
114       /**
115        * Does the system need to reboot to finish the update process?
116        */
117       bool rebootSuggested() const;
118
119       /**
120        * Does the patch affect the package manager itself?
121        * restart is suggested then
122        */
123       bool restartSuggested() const;
124
125       /**
126        * Does the patch needs the user to relogin to take effect?
127        * relogin is suggested then
128        */
129       bool reloginSuggested() const;
130
131       /**
132        * \short Information or warning to be displayed to the user
133        */
134       std::string message( const Locale & lang_r = Locale() ) const;
135
136       /**
137        * Get the InteractiveFlags of this Patch
138        */
139       InteractiveFlags interactiveFlags() const;
140
141       /**
142        * Is the patch still interactive when ignoring this flags?
143        */
144       bool interactiveWhenIgnoring( InteractiveFlags flags_r = NoFlags ) const;
145
146       /**
147        * Is the patch installation interactive? (does it need user input?)
148        *
149        * For security reasons patches requiring a reboot are not
150        * installed in an unattended mode. They are considered to be
151        * \c interactive so the user gets informed about the need for
152        * reboot. \a ignoreRebootFlag_r may be used to explicitly turn
153        * off this behavior and include those patches (unless they actually
154        * contain interactive components as well, like messages or licenses).
155        */
156       bool interactive() const;
157
158     public:
159       /**
160        * The collection of packages associated with this patch.
161        */
162       Contents contents() const;
163
164     public:
165
166       /** Query class for Patch issue references */
167       class ReferenceIterator;
168       /**
169        * Get an iterator to the beginning of the patch
170        * references. \see Patch::ReferenceIterator
171        */
172       ReferenceIterator referencesBegin() const;
173       /**
174        * Get an iterator to the end of the patch
175        * references. \see Patch::ReferenceIterator
176        */
177       ReferenceIterator referencesEnd() const;
178
179     protected:
180       friend Ptr make<Self>( const sat::Solvable & solvable_r );
181       /** Ctor */
182       Patch( const sat::Solvable & solvable_r );
183       /** Dtor */
184       virtual ~Patch();
185   };
186   ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
187   ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
188
189   /** \relates Patch::SeverityFlag string representation.*/
190   std::string asString( const Patch::SeverityFlag & obj );
191
192   /**
193    * Query class for Patch issue references
194    * like bugzilla and security issues the
195    * patch is supposed to fix.
196    *
197    * The iterator does not provide a dereference
198    * operator so you can do * on it, but you can
199    * access the attributes of each patch issue reference
200    * directly from the iterator.
201    *
202    * \code
203    * for ( Patch::ReferenceIterator it = patch->referencesBegin();
204    *       it != patch->referencesEnd();
205    *       ++it )
206    * {
207    *   cout << it.href() << endl;
208    * }
209    * \endcode
210    *
211    */
212   class Patch::ReferenceIterator : public boost::iterator_adaptor<
213       Patch::ReferenceIterator           // Derived
214       , sat::LookupAttr::iterator        // Base
215       , int                              // Value
216       , boost::forward_traversal_tag     // CategoryOrTraversal
217       , int                              // Reference
218   >
219   {
220     public:
221       ReferenceIterator() {}
222       explicit ReferenceIterator( const sat::Solvable & val_r );
223
224       /**
225        * The id of the reference. For bugzilla entries
226        * this is the bug number as a string.
227        */
228       std::string id() const;
229       /**
230        * Url or pointer where to find more information
231        */
232       std::string href() const;
233       /**
234        * Title describing the issue
235        */
236       std::string title() const;
237       /**
238        * Type of the reference. For example
239        * "bugzilla"
240        */
241       std::string type() const;
242
243     private:
244       friend class boost::iterator_core_access;
245       int dereference() const { return 0; }
246   };
247
248   inline Patch::ReferenceIterator Patch::referencesBegin() const
249   { return ReferenceIterator(satSolvable()); }
250
251   inline Patch::ReferenceIterator Patch::referencesEnd() const
252   { return ReferenceIterator(); }
253
254   /////////////////////////////////////////////////////////////////
255
256 } // namespace zypp
257 ///////////////////////////////////////////////////////////////////
258 #endif // ZYPP_PATCH_H