From 1ce6a7cb6d8cca21515aca6d302cd7b37417256e Mon Sep 17 00:00:00 2001 From: Klaus Kaempf Date: Tue, 31 Jan 2006 17:24:35 +0000 Subject: [PATCH] preliminary ! --- zypp/VendorAttr.cc | 106 +++++++++++++++++++++++++++++++++++++++++++++++++++++ zypp/VendorAttr.h | 62 +++++++++++++++++++++++++++++++ 2 files changed, 168 insertions(+) create mode 100644 zypp/VendorAttr.cc create mode 100644 zypp/VendorAttr.h diff --git a/zypp/VendorAttr.cc b/zypp/VendorAttr.cc new file mode 100644 index 0000000..f0cb17f --- /dev/null +++ b/zypp/VendorAttr.cc @@ -0,0 +1,106 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/* + File: VendorAttr.cc + + Author: Michael Andres + Maintainer: Michael Andres + + Purpose: Manage vendor attributes + +/-*/ + +#include + +#include "zypp/base/String.h" +#include "zypp/VendorAttr.h" + +using namespace std; + +/////////////////////////////////////////////////////////////////// +namespace zypp { +////////////////////////////////////////////////////////////////// + +bool +VendorAttr::trusted ( const Vendor & vendor_r ) +{ + TrustMap::value_type val( vendor_r, false ); + pair res = _trustMap.insert( val ); + + if ( res.second ) { + // check the new vendor in map + for ( VendorList::const_iterator it = _trustedVendors.begin(); + it != _trustedVendors.end(); ++it ) + { + if ( str::toLower( res.first->first.substr( 0, it->size() ) ) + == str::toLower( *it ) ) { + // match + res.first->second = true; + break; + } + } + } + + return res.first->second; +} + +VendorAttr::VendorAttr () +{ + char *vendors[] = { + "jpackage project", + "novell", + "sgi", + "silicon graphics", + "suse", + NULL + }; + + char **vptr = vendors; + while (*vptr) { + _trustedVendors.push_back (string(*vptr)); + ++vptr; + } +} + +VendorAttr::~VendorAttr () +{} + + +VendorAttr +VendorAttr::vendorAttr (void) +{ + static VendorAttr va; + + return va; +} + + +/** + * Return whether it's a known vendor + **/ +bool +VendorAttr::isKnown( const Vendor & vendor_r ) +{ + return trusted( vendor_r ); +} + + +/** + * Return whether this vendors packages should be protected by + * default. + **/ +bool +VendorAttr::autoProtect( const Vendor & vendor_r ) +{ + return ! trusted( vendor_r ); +} + +/////////////////////////////////////////////////////////////////// +} // namespace zypp +/////////////////////////////////////////////////////////////////// diff --git a/zypp/VendorAttr.h b/zypp/VendorAttr.h new file mode 100644 index 0000000..cc0ab72 --- /dev/null +++ b/zypp/VendorAttr.h @@ -0,0 +1,62 @@ +/*---------------------------------------------------------------------\ +| ____ _ __ __ ___ | +| |__ / \ / / . \ . \ | +| / / \ V /| _/ _/ | +| / /__ | | | | | | | +| /_____||_| |_| |_| | +| | +\---------------------------------------------------------------------*/ +/** \file zypp/VendorAttr.h + * +*/ +#ifndef ZYPP_VENDORATTR_H +#define ZYPP_VENDORATTR_H + +#include +#include +#include +#include + +#include "zypp/NeedAType.h" + +/////////////////////////////////////////////////////////////////// +namespace zypp { +////////////////////////////////////////////////////////////////// + +class VendorAttr { + + private: + typedef std::map TrustMap; + + TrustMap _trustMap; + + typedef std::list VendorList; + VendorList _trustedVendors; + + private: + + VendorAttr (); + ~VendorAttr (); + + bool trusted ( const Vendor & vendor_r ); + + public: + static VendorAttr vendorAttr (void); + + /** + * Return whether it's a known vendor + **/ + bool isKnown( const Vendor & vendor_r ); + + /** + * Return whether this vendors packages should be protected by + * default. + **/ + bool autoProtect( const Vendor & vendor_r ); +}; + +/////////////////////////////////////////////////////////////////// +}; // namespace zypp +/////////////////////////////////////////////////////////////////// + +#endif // ZYPP_VENDORATTR_H -- 2.7.4