/[projects]/smsdaemon/AccessManager.cpp
ViewVC logotype

Annotation of /smsdaemon/AccessManager.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 217 - (hide annotations) (download)
Tue Dec 23 14:20:43 2008 UTC (15 years, 4 months ago) by torben
File size: 1514 byte(s)
Solved ToDo item:
'- Create a filtering method:
-  Incoming: which phonenumbers are allowed to invoke which plugins
-  Incoming could be solved with a PluginProxy() which intercepts the ExecutePlugin calls (only 
PluginManager needs to know about this one)'

Move the Access related items to AccessManager.*


1 torben 217 #include "AccessManager.h"
2     #include "Util.h"
3     #include "Logger.h"
4     #include "Common.h"
5     #include "ConfigFile.h"
6     #include <set>
7     #include <vector>
8     #include <sstream>
9    
10     namespace AccessManager
11     {
12     std::set<std::string> _blacklist;
13     std::set<std::string> _privileged;
14     std::set<std::string> _privplugins;
15    
16     void LoadWorker(std::set<std::string>& set, std::string config)
17     {
18     set.clear();
19     ConfigFile* conf = Common::instance()->GetConfigfile();
20    
21     std::vector<std::string> items = Util::str_split(
22     conf->GetValue("smsdaemon",config,""),
23     ",");
24    
25     std::ostringstream log;
26     log << "Loaded list '" << config << "': ";
27     for (unsigned i=0; i<items.size(); i++)
28     {
29     set.insert( Util::str_trim(items[i]) );
30     log << items[i] << " ";
31     }
32     Logger::logMessage(log.str());
33     }
34    
35     void Load()
36     {
37     LoadWorker(_blacklist, "blacklist");
38     LoadWorker(_privileged, "privileged");
39    
40     _privplugins.clear();
41     }
42    
43     bool IsInList(std::set<std::string>& set, const std::string& search)
44     {
45     std::set<std::string>::iterator it = set.find(search);
46     return ( it != set.end() );
47     }
48    
49    
50     bool IsBlacklisted(const std::string& phone)
51     {
52     return IsInList(_blacklist,phone);
53     }
54    
55     bool IsPrivileged(const std::string& phone)
56     {
57     return IsInList(_privileged,phone);
58     }
59     bool IsPrivPlugin(const std::string& pluginname)
60     {
61     return IsInList(_privplugins,pluginname);
62     }
63    
64     void AddPrivPlugin(const std::string& pluginname)
65     {
66     _privplugins.insert(pluginname);
67     }
68     }

  ViewVC Help
Powered by ViewVC 1.1.20