From bb05261a2415183e4d444a0bdb7132445b8f2a8d Mon Sep 17 00:00:00 2001 From: Duncan Mac-Vicar P Date: Wed, 9 Apr 2008 14:41:27 +0000 Subject: [PATCH] API for retrieving bugzilla and security references using a nice iterator (thanks Michael for the tips) The implementation needs to fix the attribute names --- zypp/Patch.cc | 46 ++++++++++++++++++++++ zypp/Patch.h | 124 +++++++++++++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 156 insertions(+), 14 deletions(-) diff --git a/zypp/Patch.cc b/zypp/Patch.cc index 5c35074..b884e2f 100644 --- a/zypp/Patch.cc +++ b/zypp/Patch.cc @@ -79,5 +79,51 @@ namespace zypp } ///////////////////////////////////////////////////////////////// + + + Patch::ReferenceIterator::ReferenceIterator() + {} + + Patch::ReferenceIterator::ReferenceIterator( const sat::Solvable & val_r ) + { + base_reference() = sat::LookupAttr( sat::SolvAttr("update::referenceid"), + val_r ).begin(); + _hrefit = sat::LookupAttr( sat::SolvAttr("update::referencehref"), + val_r ).begin(); + _titleit = sat::LookupAttr( sat::SolvAttr("update::referencetitle"), + val_r ).begin(); + _typeit = sat::LookupAttr( sat::SolvAttr("update::referencetype"), + val_r ).begin(); + } + + + std::string Patch::ReferenceIterator::id() const + { return base_reference().asString(); } + std::string Patch::ReferenceIterator::href() const + { return _hrefit.asString(); } + std::string Patch::ReferenceIterator::title() const + { return _titleit.asString(); } + std::string Patch::ReferenceIterator::type() const + { return _typeit.asString(); } + + + + int Patch::ReferenceIterator::dereference() const + { return 0; } + + void Patch::ReferenceIterator::increment() + { + ++base_reference(); + ++_hrefit; + ++_titleit; + ++_typeit; + } + + inline Patch::ReferenceIterator Patch::referencesBegin() const + { return ReferenceIterator(satSolvable()); } + inline Patch::ReferenceIterator Patch::referencesEnd() const + { return ReferenceIterator(); } + + } // namespace zypp /////////////////////////////////////////////////////////////////// diff --git a/zypp/Patch.h b/zypp/Patch.h index 4c686be..04aebbd 100644 --- a/zypp/Patch.h +++ b/zypp/Patch.h @@ -12,22 +12,26 @@ #ifndef ZYPP_PATCH_H #define ZYPP_PATCH_H +#include "zypp/sat/SolvAttr.h" #include "zypp/ResObject.h" /////////////////////////////////////////////////////////////////// namespace zypp { ///////////////////////////////////////////////////////////////// + DEFINE_PTR_TYPE(Patch); - /////////////////////////////////////////////////////////////////// - // - // CLASS NAME : Patch - // - /** Class representing a patch. - * \todo Patch::atoms can't be const, if Impl does not - * provide a const method. Check it. - */ + + /** + * Class representing a patch. + * + * A patch represents a specific problem that + * can be fixed by pulling in the patch dependencies. + * + * Patches can be marked for installation but their + * installation is a no-op. + */ class Patch : public ResObject { public: @@ -40,23 +44,114 @@ namespace zypp typedef sat::SolvableSet Contents; public: - /** Patch time stamp */ + /** + * issue date time + */ Date timestamp() const { return buildtime(); } - /** Patch category (recommended, security,...) */ + + /** + * Patch category (recommended, security,...) + */ std::string category() const; - /** Does the system need to reboot to finish the update process? */ + + /** + * Does the system need to reboot to finish the update process? + */ bool reboot_needed() const; - /** Does the patch affect the package manager itself? */ + + /** + * Does the patch affect the package manager itself? + */ bool affects_pkg_manager() const; - /** Is the patch installation interactive? (does it need user input?) */ + + /** + * Is the patch installation interactive? (does it need user input?) + */ bool interactive() const; public: - /** The collection of packages associated with this patch. */ + /** + * The collection of packages associated with this patch. + */ Contents contents() const; public: + + /** + * Query class for Patch issue references + * like bugzilla and security issues the + * patch is supposed to fix. + * + * The iterator does not provide a dereference + * operator so you can do * on it, but you can + * access the attributes of each patch issue reference + * directly from the iterator. + * + * \code + * for ( Patch::ReferenceIterator it = patch->referencesBegin(); + * it != patch->referencesEnd(); + * ++it ) + * { + * cout << it.href() << endl; + * } + * \endcode + * + */ + class ReferenceIterator : public boost::iterator_adaptor< + Patch::ReferenceIterator // Derived + , sat::LookupAttr::iterator // Base + , int // Value + , boost::forward_traversal_tag // CategoryOrTraversal + , int + > + { + public: + ReferenceIterator(); + explicit ReferenceIterator( const sat::Solvable & val_r ); + + /** + * The id of the reference. For bugzilla entries + * this is the bug number as a string. + */ + std::string id() const; + /** + * Url or ponter where to find more information + */ + std::string href() const; + /** + * Title describing the issue + */ + std::string title() const; + /** + * Type of the reference. For example + * "bugzilla" + */ + std::string type() const; + private: + friend class boost::iterator_core_access; + + int dereference() const; + void increment(); + private: + sat::LookupAttr::iterator _hrefit; + sat::LookupAttr::iterator _titleit; + sat::LookupAttr::iterator _typeit; + }; + + /** + * Get an iterator to the beginning of the patch + * references. \see Patch::ReferenceIterator + */ + ReferenceIterator referencesBegin() const; + /** + * Get an iterator to the end of the patch + * references. \see Patch::ReferenceIterator + */ + ReferenceIterator referencesEnd() const; + + + public: /** Patch ID * \deprecated Seems to be unsused autobuild interal data? */ @@ -79,6 +174,7 @@ namespace zypp }; ///////////////////////////////////////////////////////////////// + } // namespace zypp /////////////////////////////////////////////////////////////////// #endif // ZYPP_PATCH_H -- 2.7.4