1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
15 #include "zypp/base/Flags.h"
16 #include "zypp/sat/SolvAttr.h"
17 #include "zypp/ResObject.h"
19 ///////////////////////////////////////////////////////////////////
21 { /////////////////////////////////////////////////////////////////
24 DEFINE_PTR_TYPE(Patch);
28 * Class representing a patch.
30 * A patch represents a specific problem that
31 * can be fixed by pulling in the patch dependencies.
33 * Patches can be marked for installation but their
34 * installation is a no-op.
36 class Patch : public ResObject
40 typedef ResTraits<Self> TraitsType;
41 typedef TraitsType::PtrType Ptr;
42 typedef TraitsType::constPtrType constPtr;
45 typedef sat::SolvableSet Contents;
48 CAT_OTHER = 1, //!< unknown value specified
50 CAT_SECURITY = 1<<2, //!<
51 CAT_RECOMMENDED = 1<<3, //!<
52 CAT_OPTIONAL = 1<<4, //!<
53 CAT_DOCUMENT = 1<<5 //!<
55 ZYPP_DECLARE_FLAGS(Categories, Category);
58 * Flags defining if and why this
59 * patch is interactive.
61 enum InteractiveFlag {
67 ZYPP_DECLARE_FLAGS(InteractiveFlags, InteractiveFlag);
70 * \brief Possible severity levels for (security) patches.
71 * Metadata string values are mapped to this enum to ease
72 * computations. For a string representation call
73 * \ref asSring( const Patch::SeverityFlag & ).
76 SEV_OTHER = 1, //!< unknown value specified
77 SEV_NONE = 1<<1, //!< no value specified
78 SEV_LOW = 1<<2, //!< Low
79 SEV_MODERATE = 1<<3, //!< Moderate
80 SEV_IMPORTANT = 1<<4, //!< Important
81 SEV_CRITICAL = 1<<5 //!< Critical
83 ZYPP_DECLARE_FLAGS(SeverityFlags, SeverityFlag);
87 * Issue date time. For now it is the same as
90 Date timestamp() const
91 { return buildtime(); }
93 /** \name Patch Category */
96 * Patch category (recommended, security,...)
98 std::string category() const;
100 /** This patch's category as enum of wellknown categories.
101 * Unknown values are mapped to \ref CAT_OTHER.
103 Category categoryEnum() const;
105 /** Whether this patch's category matches \a category_r */
106 bool isCategory( const std::string & category_r ) const;
107 /** \overload taking OR'ed \ref Categories */
108 bool isCategory( Categories category_r ) const;
109 #ifndef SWIG // Swig treats it as syntax error
110 /** \overload taking container of category strings
111 * 2nd template arg just to prevent instantiation for Category
113 template <class TContainer, typename = typename TContainer::value_type>
114 bool isCategory( const TContainer & categories_r ) const
116 for ( const std::string & el : categories_r )
117 { if ( isCategory( el ) ) return true; }
121 /** Patch category as enum of wellknown categories.
122 * Unknown values are mapped to \ref CAT_OTHER.
124 static Category categoryEnum( const std::string & category_r );
127 /** \name Patch Severity */
130 * Severity string as specified in metadata.
131 * For use in computaions see \ref severityFlag.
133 std::string severity() const;
136 * Severity string mapped to an enum.
137 * Unknown string values are mapped to \ref SEV_OTHER
139 SeverityFlag severityFlag() const;
141 /** Whether this patch's severity matches \a severity_r */
142 bool isSeverity( const std::string & severity_r ) const;
143 /** \overload taking OR'ed \ref SeverityFlags */
144 bool isSeverity( SeverityFlags severity_r ) const;
145 #ifndef SWIG // Swig treats it as syntax error
146 /** \overload taking container of severity strings
147 * 2nd template arg just to prevent instantiation for SeverityFlag
149 template <class TContainer, typename = typename TContainer::value_type>
150 bool isSeverity( const TContainer & severities_r ) const
152 for ( const std::string & el : severities_r )
153 { if ( isSeverity( el ) ) return true; }
157 /** Severity string mapped to an enum.
158 * Unknown string values are mapped to \ref SEV_OTHER
160 static SeverityFlag severityFlag( const std::string & category_r );
164 * Does the system need to reboot to finish the update process?
166 bool rebootSuggested() const;
169 * Does the patch affect the package manager itself?
170 * restart is suggested then
172 bool restartSuggested() const;
175 * Does the patch needs the user to relogin to take effect?
176 * relogin is suggested then
178 bool reloginSuggested() const;
181 * \short Information or warning to be displayed to the user
183 std::string message( const Locale & lang_r = Locale() ) const;
186 * Get the InteractiveFlags of this Patch
188 InteractiveFlags interactiveFlags() const;
191 * Is the patch still interactive when ignoring this flags?
193 bool interactiveWhenIgnoring( InteractiveFlags flags_r = NoFlags ) const;
196 * Is the patch installation interactive? (does it need user input?)
198 * For security reasons patches requiring a reboot are not
199 * installed in an unattended mode. They are considered to be
200 * \c interactive so the user gets informed about the need for
201 * reboot. \a ignoreRebootFlag_r may be used to explicitly turn
202 * off this behavior and include those patches (unless they actually
203 * contain interactive components as well, like messages or licenses).
205 bool interactive() const;
209 * The collection of packages associated with this patch.
211 Contents contents() const;
215 /** Query class for Patch issue references */
216 class ReferenceIterator;
218 * Get an iterator to the beginning of the patch
219 * references. \see Patch::ReferenceIterator
221 ReferenceIterator referencesBegin() const;
223 * Get an iterator to the end of the patch
224 * references. \see Patch::ReferenceIterator
226 ReferenceIterator referencesEnd() const;
229 friend Ptr make<Self>( const sat::Solvable & solvable_r );
231 Patch( const sat::Solvable & solvable_r );
235 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::Categories);
236 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::InteractiveFlags);
237 ZYPP_DECLARE_OPERATORS_FOR_FLAGS(Patch::SeverityFlags);
239 /** \relates Patch::Category string representation.*/
240 std::string asString( const Patch::Category & obj );
242 /** \relates Patch::InteractiveFlag string representation.*/
243 std::string asString( const Patch::InteractiveFlag & obj );
245 /** \relates Patch::SeverityFlag string representation.*/
246 std::string asString( const Patch::SeverityFlag & obj );
249 * Query class for Patch issue references
250 * like bugzilla and security issues the
251 * patch is supposed to fix.
253 * The iterator does not provide a dereference
254 * operator so you can do * on it, but you can
255 * access the attributes of each patch issue reference
256 * directly from the iterator.
259 * for ( Patch::ReferenceIterator it = patch->referencesBegin();
260 * it != patch->referencesEnd();
263 * cout << it.href() << endl;
268 class Patch::ReferenceIterator : public boost::iterator_adaptor<
269 Patch::ReferenceIterator // Derived
270 , sat::LookupAttr::iterator // Base
272 , boost::forward_traversal_tag // CategoryOrTraversal
277 ReferenceIterator() {}
278 explicit ReferenceIterator( const sat::Solvable & val_r );
281 * The id of the reference. For bugzilla entries
282 * this is the bug number as a string.
284 std::string id() const;
286 * Url or pointer where to find more information
288 std::string href() const;
290 * Title describing the issue
292 std::string title() const;
294 * Type of the reference. For example
297 std::string type() const;
300 friend class boost::iterator_core_access;
301 int dereference() const { return 0; }
304 inline Patch::ReferenceIterator Patch::referencesBegin() const
305 { return ReferenceIterator(satSolvable()); }
307 inline Patch::ReferenceIterator Patch::referencesEnd() const
308 { return ReferenceIterator(); }
310 /////////////////////////////////////////////////////////////////
313 ///////////////////////////////////////////////////////////////////
314 #endif // ZYPP_PATCH_H