ignore
[platform/upstream/libzypp.git] / zypp / VendorAttr.cc
1 /*---------------------------------------------------------------------\
2 |                          ____ _   __ __ ___                          |
3 |                         |__  / \ / / . \ . \                         |
4 |                           / / \ V /|  _/  _/                         |
5 |                          / /__ | | | | | |                           |
6 |                         /_____||_| |_| |_|                           |
7 |                                                                      |
8 \---------------------------------------------------------------------*/
9 /*
10   File:       VendorAttr.cc
11
12   Author:     Michael Andres <ma@suse.de>
13   Maintainer: Michael Andres <ma@suse.de>
14
15   Purpose: Manage vendor attributes
16
17 /-*/
18
19 #include <iostream>
20 #include <set>
21 #include <map>
22
23 #include "zypp/base/LogTools.h"
24
25 #include "zypp/base/String.h"
26 #include "zypp/VendorAttr.h"
27
28 using namespace std;
29
30 #undef  ZYPP_BASE_LOGGER_LOGGROUP
31 #define ZYPP_BASE_LOGGER_LOGGROUP "zypp::VendorAttr"
32
33 ///////////////////////////////////////////////////////////////////
34 namespace zypp
35 { /////////////////////////////////////////////////////////////////
36
37   ///////////////////////////////////////////////////////////////////
38   namespace
39   { /////////////////////////////////////////////////////////////////
40
41     typedef std::map<Vendor,bool> TrustMap;
42     TrustMap _trustMap;
43
44     typedef std::set<std::string> VendorList;
45     VendorList _trustedVendors;
46
47     bool trusted( const Vendor & vendor_r )
48     {
49       TrustMap::value_type val( vendor_r, false );
50       pair<TrustMap::iterator, bool> res = _trustMap.insert( val );
51
52       if ( res.second )
53         {
54           // check the new vendor in map
55           for ( VendorList::const_iterator it = _trustedVendors.begin();
56                 it != _trustedVendors.end(); ++it )
57             {
58               if ( str::toLower( res.first->first.substr( 0, it->size() ) )
59                    == str::toLower( *it ) )
60                 {
61                   // match
62                   res.first->second = true;
63                   break;
64                 }
65             }
66         }
67       return res.first->second;
68     }
69
70
71     /////////////////////////////////////////////////////////////////
72   } // namespace
73   ///////////////////////////////////////////////////////////////////
74
75   const VendorAttr & VendorAttr::instance()
76   {
77     static VendorAttr _val;
78     return _val;
79   }
80
81   VendorAttr::VendorAttr ()
82   {
83     char * vendors[] = {
84       "jpackage project",
85       "novell",
86       "opensuse",
87       "sgi",
88       "silicon graphics",
89       "suse",
90       "ati technologies inc.",
91       "nvidia"
92     };
93     _trustedVendors.insert( vendors, vendors+(sizeof(vendors)/sizeof(char *)) );
94     MIL << "Trusted Vendors: " << _trustedVendors << endl;
95   }
96
97   bool VendorAttr::isKnown( const Vendor & vendor_r ) const
98   { return trusted( vendor_r ); }
99
100
101   bool VendorAttr::autoProtect( const Vendor & vendor_r ) const
102   { return ! trusted( vendor_r ); }
103
104   /////////////////////////////////////////////////////////////////
105 } // namespace zypp
106 ///////////////////////////////////////////////////////////////////
107