tdaq-develop-2025-02-12
CodeEditor.h
1 #ifndef _ots_CodeEditor_h_
2 #define _ots_CodeEditor_h_
3 
4 #include "otsdaq/Macros/CoutMacros.h"
5 #include "otsdaq/Macros/StringMacros.h"
6 #include "otsdaq/MessageFacility/MessageFacility.h"
7 #include "otsdaq/SOAPUtilities/SOAPMessenger.h"
8 #pragma GCC diagnostic push
9 #pragma GCC diagnostic ignored "-Wunknown-pragmas"
10 #include <xgi/Method.h> //for cgicc::Cgicc
11 #pragma GCC diagnostic pop
12 
13 #include <iostream>
14 #include <string>
15 #include <unordered_map>
16 #include <vector>
17 
18 namespace ots
19 {
20 class HttpXmlDocument;
21 
25 {
26  public:
27  CodeEditor();
28 
30  void xmlRequest(const std::string& option,
31  bool readOnlyMode,
32  cgicc::Cgicc& cgiIn,
33  HttpXmlDocument* xmlOut,
34  const std::string& username);
35 
36  private:
37  void getDirectoryContent(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut);
38  void getPathContent(const std::string& basepath,
39  const std::string& path,
40  HttpXmlDocument* xmlOut);
41  void getFileContent(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut);
42  void getFileGitURL(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut);
43  void saveFileContent(cgicc::Cgicc& cgiIn,
44  HttpXmlDocument* xmlOut,
45  const std::string& username);
46  void build(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut, const std::string& username);
47 
48  std::string safePathString(const std::string& path);
49  std::string safeExtensionString(const std::string& extension);
50 
51  public:
52  static const std::string SPECIAL_TYPE_FEInterface, SPECIAL_TYPE_DataProcessor,
53  SPECIAL_TYPE_Table, SPECIAL_TYPE_SlowControls, SPECIAL_TYPE_Tools,
54  SPECIAL_TYPE_UserData, SPECIAL_TYPE_WebPath, SPECIAL_TYPE_OutputData;
55 
56  static const std::string SOURCE_BASE_PATH, USER_DATA_PATH, OTSDAQ_WEB_PATH,
57  OTSDAQ_DATA_PATH;
58 
59  static std::map<std::string /*special type*/,
60  std::set<std::string> /*special file paths*/>
61  getSpecialsMap(void);
62 
63  static void readFile(const std::string& basepath,
64  const std::string& path,
65  std::string& contents,
66  bool binaryRead = false);
67  static void writeFile(const std::string& basepath,
68  const std::string& path,
69  const std::string& contents,
70  const std::string& username,
71  const unsigned long long& insertPos = -1,
72  const std::string& insertString = "");
73  static std::string getFileGitURL(const std::string& basepath,
74  const std::string& path);
75 
76  const std::set<std::string> ALLOWED_FILE_EXTENSIONS_;
77 };
78 
79 } // namespace ots
80 
81 #endif
void xmlRequest(const std::string &option, bool readOnlyMode, cgicc::Cgicc &cgiIn, HttpXmlDocument *xmlOut, const std::string &username)
request are handled here