00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <iostream>
00020 #include <set>
00021 #include <map>
00022
00023 #include "zypp/base/LogTools.h"
00024
00025 #include "zypp/base/String.h"
00026 #include "zypp/VendorAttr.h"
00027
00028 using namespace std;
00029
00030 #undef ZYPP_BASE_LOGGER_LOGGROUP
00031 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::VendorAttr"
00032
00034 namespace zypp
00035 {
00036
00038 namespace
00039 {
00040
00041 typedef std::map<Vendor,bool> TrustMap;
00042 TrustMap _trustMap;
00043
00044 typedef std::set<std::string> VendorList;
00045 VendorList _trustedVendors;
00046
00047 bool trusted( const Vendor & vendor_r )
00048 {
00049 TrustMap::value_type val( vendor_r, false );
00050 pair<TrustMap::iterator, bool> res = _trustMap.insert( val );
00051
00052 if ( res.second )
00053 {
00054
00055 for ( VendorList::const_iterator it = _trustedVendors.begin();
00056 it != _trustedVendors.end(); ++it )
00057 {
00058 if ( str::toLower( res.first->first.substr( 0, it->size() ) )
00059 == str::toLower( *it ) )
00060 {
00061
00062 res.first->second = true;
00063 break;
00064 }
00065 }
00066 }
00067 return res.first->second;
00068 }
00069
00070
00072 }
00074
00075 const VendorAttr & VendorAttr::instance()
00076 {
00077 static VendorAttr _val;
00078 return _val;
00079 }
00080
00081 VendorAttr::VendorAttr ()
00082 {
00083 char * vendors[] = {
00084 "jpackage project",
00085 "novell",
00086 "sgi",
00087 "silicon graphics",
00088 "suse",
00089 "ati technologies inc.",
00090 "nvidia"
00091 };
00092 _trustedVendors.insert( vendors, vendors+(sizeof(vendors)/sizeof(char *)) );
00093 MIL << "Trusted Vendors: " << _trustedVendors << endl;
00094 }
00095
00096 bool VendorAttr::isKnown( const Vendor & vendor_r ) const
00097 { return trusted( vendor_r ); }
00098
00099
00100 bool VendorAttr::autoProtect( const Vendor & vendor_r ) const
00101 { return ! trusted( vendor_r ); }
00102
00104 }
00106