fhq-server  v0.2.33
Documentation for fhq-server. FreeHackQuest is an open source platform for competitions of computer security.
employees.h
Go to the documentation of this file.
1 #ifndef EMPLOYEES_H
2 #define EMPLOYEES_H
3 
4 #include <map>
5 #include <string>
6 #include <vector>
7 #include <fallen.h>
8 #include <wsjcpp_employees.h>
9 #include <cmd_handlers.h>
10 
11 // ---------------------------------------------------------------------
12 // employ enum code results
13 
15  OK,
22 };
23 
24 // ----------------------------------------------------------------------
25 
31 };
32 
33 // ----------------------------------------------------------------------
34 
46 };
47 
48 // ----------------------------------------------------------------------
49 
51  public:
52  WsjcppSettingItem(const std::string &sSettingGroup, const std::string &sSettingName);
53  // WsjcppSettingItem(const WsjcppSettingItem &item);
58  WsjcppSettingItem &string(const std::string &sDefaultStringValue);
59  WsjcppSettingItem &password(const std::string &sDefaultPasswordValue);
60  WsjcppSettingItem &dirPath(const std::string &sDefaultDirPathValue);
61  WsjcppSettingItem &filePath(const std::string &sDefaultFilePathValue);
62  WsjcppSettingItem &text(const std::string &sDefaultTextValue);
63  WsjcppSettingItem &number(int nDefaultNumberValue);
64  WsjcppSettingItem &boolean(bool bDefaultBooleanValue);
67 
68  void checkWithThrow() const;
69  bool isInited() const;
70  bool isReadonly() const;
71  std::string getName() const;
72  std::string getGroupName() const;
73  bool isFromFile() const;
74  bool isFromDatabase() const;
75  bool isFromRuntime() const;
76 
77  bool isString() const;
78  bool isPassword() const;
79  bool isDirPath() const;
80  bool isFilePath() const;
81  bool isText() const;
82  bool isNumber() const;
83  bool isBoolean() const;
84  bool isJson() const;
85  bool isList() const;
86 
87  bool isLikeString() const;
88 
89  std::string getDefaultStringValue() const;
90  std::string getStringValue() const;
91  void setStringValue(const std::string &sStringValue);
92 
93  std::string getDefaultPasswordValue() const;
94  std::string getPasswordValue() const;
95  void setPasswordValue(const std::string &sPasswordValue);
96 
97  std::string getDefaultDirPathValue() const;
98  std::string getDirPathValue() const;
99  void setDirPathValue(const std::string &sDirPathValue);
100 
101  std::string getDefaultFilePathValue() const;
102  std::string getFilePathValue() const;
103  void setFilePathValue(const std::string &sFilePathValue);
104 
105  std::string getDefaultTextValue() const;
106  std::string getTextValue() const;
107  void setTextValue(const std::string &sTextValue);
108 
109  int getDefaultNumberValue() const;
110  int getNumberValue() const;
111  void setNumberValue(int nNumberValue);
112 
113  bool getDefaultBooleanValue() const;
114  bool getBooleanValue() const;
115  void setBooleanValue(bool bBooleanValue);
116 
117  nlohmann::json toJson(bool bHidePassword);
118  std::string convertValueToString(bool bHidePassword) const;
119  std::string convertTypeToString() const;
120 
121  private:
122  std::string TAG;
123  std::string m_sSettingName;
124  std::string m_sSettingGroup;
127  std::string m_sStorageType;
129  std::string m_sSettingType;
130  bool m_bInited;
131 
132  // isString
134  std::string m_sStringValue;
135 
136  // isPassword
138  std::string m_sPasswordValue;
139 
140  // isDirPath
142  std::string m_sDirPathValue;
143 
144  // isFilePath
146  std::string m_sFilePathValue;
147 
148  // isText
149  std::string m_sDefaultTextValue;
150  std::string m_sTextValue;
151 
152  // isNumber
155 
156  // isBoolean
159 };
160 
161 // ----------------------------------------------------------------------
162 
164  public:
165  virtual void onSettingsChanged(const WsjcppSettingItem *pSettingItem) = 0;
166 };
167 
168 // ----------------------------------------------------------------------
169 
171  public:
172  virtual std::map<std::string, std::string> loadAllSettings() = 0;
173  virtual void updateSettingItem(const WsjcppSettingItem *pSettingItem) = 0;
174  virtual void initSettingItem(WsjcppSettingItem *pSettingItem) = 0;
175 };
176 
177 // ---------------------------------------------------------------------
178 // WsjcppEmployGlobalSettings
179 
181  public:
183  static std::string name() { return "EmployGlobalSettings"; }
184  virtual bool init(); // here will be init from file
185  virtual bool deinit();
186  void setWorkDir(const std::string &sWorkDir); // TODO deprecated
187 
188  WsjcppSettingItem &registrySetting(const std::string &sSettingGroup, const std::string &sSettingName);
189 
190  const WsjcppSettingItem &get(const std::string &sSettingName);
191  bool exists(const std::string &sSettingName);
192  void update(const std::string &sSettingName, const std::string &sValue);
193  void update(const std::string &sSettingName, int nValue);
194  void update(const std::string &sSettingName, bool bValue);
195 
196  void addListener(WsjcppSettingListener *);
197  void removeListener(WsjcppSettingListener *);
198  bool initFromDatabase(WsjcppSettingsStore *pDatabaseSettingsStore);
199  std::string getFilepathConf() const;
200  nlohmann::json toJson(bool bHidePassword);
201  void printSettings() const;
202 
203  private:
204  std::string TAG;
205  std::string m_sWorkDir;
206  std::string m_sFilepathConf;
208 
209  bool findFileConfig();
210  bool initFromFile();
211  void eventSettingsChanged(const WsjcppSettingItem *pSettingItem);
212  std::map <std::string, WsjcppSettingItem *> m_mapSettingItems;
213  std::vector<WsjcppSettingListener *> m_vListeners;
214 };
215 
216 // ---------------------------------------------------------------------
217 // WJSCppEmployServer
218 
220  public:
221  EmployServer();
222  static std::string name() { return "EmployServer"; }
223  virtual bool init();
224  virtual bool deinit();
225  bool validateInputParameters(WsjcppError &error, CmdHandlerBase *pCmdHandler, const nlohmann::json& jsonMessage);
226  void setServer(IWebSocketServer *pWebSocketServer);
227  void sendToAll(const nlohmann::json& jsonMessage);
228  void sendToOne(QWebSocket *pClient, const nlohmann::json& jsonMessage);
229 
230  private:
231  std::string TAG;
233 };
234 
235 #endif // EMPLOYEES_H
void setNumberValue(int nNumberValue)
Definition: employees.cpp:493
Definition: employees.h:29
void setDirPathValue(const std::string &sDirPathValue)
Definition: employees.cpp:400
std::string m_sSettingGroup
Definition: employees.h:124
Definition: employees.h:180
std::string getDirPathValue() const
Definition: employees.cpp:391
Definition: employees.h:41
Definition: employees.h:21
Definition: employees.h:50
bool isNumber() const
Definition: employees.cpp:285
int getNumberValue() const
Definition: employees.cpp:484
WsjcppSettingItem & string(const std::string &sDefaultStringValue)
Definition: employees.cpp:87
WsjcppSettingItem & dirPath(const std::string &sDefaultDirPathValue)
Definition: employees.cpp:111
WsjcppSettingItem & json()
Definition: employees.cpp:171
std::string m_sDefaultStringValue
Definition: employees.h:133
std::string m_sFilepathConf
Definition: employees.h:206
void setBooleanValue(bool bBooleanValue)
Definition: employees.cpp:525
WsjcppSettingDataType m_nSettingType
Definition: employees.h:128
std::string m_sStringValue
Definition: employees.h:134
void setStringValue(const std::string &sStringValue)
Definition: employees.cpp:338
bool isReadonly() const
Definition: employees.cpp:219
Definition: employees.h:43
Definition: employees.h:45
void setPasswordValue(const std::string &sPasswordValue)
Definition: employees.cpp:369
std::string TAG
Definition: employees.h:231
std::string m_sDirPathValue
Definition: employees.h:142
std::string getDefaultFilePathValue() const
Definition: employees.cpp:413
bool isPassword() const
Definition: employees.cpp:261
Definition: employees.h:163
Definition: employees.h:170
bool isList() const
Definition: employees.cpp:303
void setFilePathValue(const std::string &sFilePathValue)
Definition: employees.cpp:431
std::string m_sTextValue
Definition: employees.h:150
std::string m_sDefaultTextValue
Definition: employees.h:149
Definition: employees.h:20
bool getBooleanValue() const
Definition: employees.cpp:516
IWebSocketServer * m_pWebSocketServer
Definition: employees.h:232
bool isDirPath() const
Definition: employees.cpp:267
std::string TAG
Definition: employees.h:122
bool isText() const
Definition: employees.cpp:279
std::string m_sStorageType
Definition: employees.h:127
Definition: employees.h:19
std::string getGroupName() const
Definition: employees.cpp:231
std::string m_sSettingName
Definition: employees.h:123
std::string m_sPasswordValue
Definition: employees.h:138
Definition: employees.h:40
std::string getDefaultDirPathValue() const
Definition: employees.cpp:382
WsjcppSettingDataType
Definition: employees.h:35
int getDefaultNumberValue() const
Definition: employees.cpp:475
WsjcppSettingItem & boolean(bool bDefaultBooleanValue)
Definition: employees.cpp:159
WsjcppSettingStorageType m_nStorageType
Definition: employees.h:126
WsjcppSettingItem & text(const std::string &sDefaultTextValue)
Definition: employees.cpp:135
IWebSocketServer -.
Definition: cmd_handlers.h:86
Definition: employees.h:219
WsjcppSettingItem & inFile()
Definition: employees.cpp:45
Definition: employees.h:38
std::string getTextValue() const
Definition: employees.cpp:453
std::map< std::string, WsjcppSettingItem * > m_mapSettingItems
Definition: employees.h:212
std::string getDefaultTextValue() const
Definition: employees.cpp:444
std::string m_sDefaultDirPathValue
Definition: employees.h:141
WsjcppSettingItem & inDatabase()
Definition: employees.cpp:57
WsjcppSettingItem(const std::string &sSettingGroup, const std::string &sSettingName)
Definition: employees.cpp:12
std::string getFilePathValue() const
Definition: employees.cpp:422
bool isFromDatabase() const
Definition: employees.cpp:243
Definition: employees.h:42
WsjcppSettingItem & password(const std::string &sDefaultPasswordValue)
Definition: employees.cpp:99
bool isString() const
Definition: employees.cpp:255
void checkWithThrow() const
Definition: employees.cpp:197
WsjcppError - helper class for errors.
Definition: cmd_handlers.h:18
nlohmann::json toJson(bool bHidePassword)
Definition: employees.cpp:539
Definition: employees.h:28
EmployResult
Definition: employees.h:14
WsjcppSettingItem & number(int nDefaultNumberValue)
Definition: employees.cpp:147
void setTextValue(const std::string &sTextValue)
Definition: employees.cpp:462
WsjcppSettingsStore * m_pDatabaseSettingsStore
Definition: employees.h:207
std::string getStringValue() const
Definition: employees.cpp:329
std::string m_sFilePathValue
Definition: employees.h:146
std::string getDefaultStringValue() const
Definition: employees.cpp:320
Definition: wsjcpp_employees.h:13
bool isJson() const
Definition: employees.cpp:297
Definition: employees.h:37
bool isLikeString() const
Definition: employees.cpp:309
std::vector< WsjcppSettingListener * > m_vListeners
Definition: employees.h:213
std::string getDefaultPasswordValue() const
Definition: employees.cpp:351
Definition: employees.h:30
std::string getPasswordValue() const
Definition: employees.cpp:360
Definition: employees.h:18
std::string convertTypeToString() const
Definition: employees.cpp:594
std::string convertValueToString(bool bHidePassword) const
Definition: employees.cpp:570
Definition: employees.h:44
bool isFromRuntime() const
Definition: employees.cpp:249
std::string m_sDefaultFilePathValue
Definition: employees.h:145
Definition: employees.h:39
Definition: employees.h:16
bool m_bReadonly
Definition: employees.h:125
std::string getName() const
Definition: employees.cpp:225
bool m_bDefaultBooleanValue
Definition: employees.h:157
static std::string name()
Definition: employees.h:222
std::string m_sWorkDir
Definition: employees.h:205
WsjcppSettingItem & filePath(const std::string &sDefaultFilePathValue)
Definition: employees.cpp:123
std::string TAG
Definition: employees.h:204
std::string m_sSettingType
Definition: employees.h:129
Api handler Base.
Definition: cmd_handlers.h:202
bool isFromFile() const
Definition: employees.cpp:237
std::string m_sDefaultPasswordValue
Definition: employees.h:137
bool getDefaultBooleanValue() const
Definition: employees.cpp:507
bool m_bBooleanValue
Definition: employees.h:158
int m_nNumberValue
Definition: employees.h:154
WsjcppSettingItem & list()
Definition: employees.cpp:184
static std::string name()
Definition: employees.h:183
Definition: employees.h:27
int m_nDefaultNumberValue
Definition: employees.h:153
Definition: employees.h:15
bool m_bInited
Definition: employees.h:130
Definition: employees.h:36
bool isInited() const
Definition: employees.cpp:213
WsjcppSettingItem & inRuntime()
Definition: employees.cpp:68
bool isFilePath() const
Definition: employees.cpp:273
WsjcppSettingItem & readonly()
Definition: employees.cpp:80
Definition: employees.h:17
WsjcppSettingStorageType
Definition: employees.h:26
bool isBoolean() const
Definition: employees.cpp:291