libhomegear-base  0.7
Base library for Homegear and Homegear family modules.
ServerInfo.h
Go to the documentation of this file.
1 /* Copyright 2013-2019 Homegear GmbH
2  *
3  * libhomegear-base is free software: you can redistribute it and/or
4  * modify it under the terms of the GNU Lesser General Public License as
5  * published by the Free Software Foundation, either version 3 of the
6  * License, or (at your option) any later version.
7  *
8  * libhomegear-base is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Lesser General Public License for more details.
12  *
13  * You should have received a copy of the GNU Lesser General Public
14  * License along with libhomegear-base. If not, see
15  * <http://www.gnu.org/licenses/>.
16  *
17  * In addition, as a special exception, the copyright holders give
18  * permission to link the code of portions of this program with the
19  * OpenSSL library under certain conditions as described in each
20  * individual source file, and distribute linked combinations
21  * including the two.
22  * You must obey the GNU Lesser General Public License in all respects
23  * for all of the code used other than OpenSSL. If you modify
24  * file(s) with this exception, you may extend this exception to your
25  * version of the file(s), but you are not obligated to do so. If you
26  * do not wish to do so, delete this exception statement from your
27  * version. If you delete this exception statement from all source
28  * files in the program, then also delete it here.
29 */
30 
31 #ifndef SERVERINFO_H_
32 #define SERVERINFO_H_
33 
34 #include "../Variable.h"
35 
36 #include <memory>
37 #include <string>
38 #include <map>
39 #include <cstring>
40 #include <vector>
41 #include <unordered_set>
42 
43 namespace BaseLib {
44 
45 class SharedObjects;
46 class FileDescriptor;
47 typedef std::shared_ptr<FileDescriptor> PFileDescriptor;
48 
49 namespace Rpc {
50 
51 class ServerInfo {
52  public:
53  class Info {
54  public:
55  enum AuthType { undefined = 0, none = 1, basic = 2, cert = 4, session = 8, oauth2Local = 16 };
56 
57  Info() {
58  interface = "::";
59  contentPath = "/var/lib/homegear/www/";
60  }
61  virtual ~Info() {}
62  int32_t index = -1;
63  std::string name;
64  std::string interface;
65  int32_t port = -1;
66  bool ssl = true;
67  std::string caPath;
68  std::string certPath;
69  std::string keyPath;
70  std::string dhParamPath;
71  AuthType authType = AuthType::cert;
72  std::unordered_set<uint64_t> validGroups;
73  std::string contentPath;
74  uint32_t contentPathPermissions = 360;
75  std::string contentPathUser;
76  std::string contentPathGroup;
77  bool webServer = false;
78  bool webSocket = false;
79  AuthType websocketAuthType = AuthType::session;
80  bool rpcServer = false;
81  bool restServer = false;
82  bool familyServer = false;
83  int32_t cacheAssets = 2592000;
84  std::string redirectTo;
85 
86  // Helpers
87  PFileDescriptor socketDescriptor;
88 
89  // Mods
90  std::map<std::string, std::vector<std::string>> modSettings;
91 
92  //Not settable
93  std::string address;
95 
100  void unserialize(PVariable data);
101  };
102 
103  ServerInfo();
104  explicit ServerInfo(BaseLib::SharedObjects *baseLib);
105  ~ServerInfo() = default;
106  void init(BaseLib::SharedObjects *baseLib);
107  void load(const std::string &filename);
108 
109  int32_t count() { return _servers.size(); }
110  std::shared_ptr<Info> get(int32_t index) { if (_servers.find(index) != _servers.end()) return _servers[index]; else return std::shared_ptr<Info>(); }
111  private:
112  BaseLib::SharedObjects *_bl = nullptr;
113  std::map<int32_t, std::shared_ptr<Info>> _servers;
114 
115  void reset();
116 };
117 
118 typedef std::shared_ptr<ServerInfo::Info> PServerInfo;
119 
120 }
121 }
122 #endif
std::string name
Definition: ServerInfo.h:63
std::string contentPath
Definition: ServerInfo.h:73
Definition: ServerInfo.h:55
ServerInfo()
Definition: ServerInfo.cpp:118
std::string contentPathUser
Definition: ServerInfo.h:75
Definition: ServerInfo.h:55
Definition: ServerInfo.h:51
int32_t cacheAssets
Definition: ServerInfo.h:83
AuthType authType
Definition: ServerInfo.h:71
std::string dhParamPath
Definition: ServerInfo.h:70
This is the base library main class.
Definition: BaseLib.h:95
std::string interface
Definition: ServerInfo.h:64
std::string address
Definition: ServerInfo.h:93
bool familyServer
Definition: ServerInfo.h:82
Definition: BaseLib.cpp:34
std::string caPath
Definition: ServerInfo.h:67
uint32_t contentPathPermissions
Definition: ServerInfo.h:74
int32_t port
Definition: ServerInfo.h:65
AuthType
Definition: ServerInfo.h:55
Definition: ServerInfo.h:55
void unserialize(PVariable data)
Definition: ServerInfo.cpp:70
void init(BaseLib::SharedObjects *baseLib)
Definition: ServerInfo.cpp:129
std::shared_ptr< Variable > PVariable
Definition: PhysicalInterfaceSettings.h:41
PVariable serializedInfo
Definition: ServerInfo.h:94
bool restServer
Definition: ServerInfo.h:81
std::string redirectTo
Definition: ServerInfo.h:84
AuthType websocketAuthType
Definition: ServerInfo.h:79
std::string certPath
Definition: ServerInfo.h:68
std::string contentPathGroup
Definition: ServerInfo.h:76
std::unordered_set< uint64_t > validGroups
Definition: ServerInfo.h:72
std::shared_ptr< ServerInfo::Info > PServerInfo
Definition: ServerInfo.h:118
std::string keyPath
Definition: ServerInfo.h:69
Info()
Definition: ServerInfo.h:57
std::shared_ptr< FileDescriptor > PFileDescriptor
Definition: FileDescriptorManager.h:52
PFileDescriptor socketDescriptor
Definition: ServerInfo.h:87
int32_t index
Definition: ServerInfo.h:62
Definition: ServerInfo.h:53
std::map< std::string, std::vector< std::string > > modSettings
Definition: ServerInfo.h:90
bool rpcServer
Definition: ServerInfo.h:80
bool webServer
Definition: ServerInfo.h:77
bool webSocket
Definition: ServerInfo.h:78
PVariable serialize()
Serializes the whole object except modSettings.
Definition: ServerInfo.cpp:36
int32_t count()
Definition: ServerInfo.h:109
bool ssl
Definition: ServerInfo.h:66
Definition: ServerInfo.h:55
void load(const std::string &filename)
Definition: ServerInfo.cpp:133