otsdaq  v2_05_02_indev
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 
22 // CodeEditor
23 // This class provides the functionality for editing, saving, and building code
25 {
26  public:
27  CodeEditor();
28 
29  // request are handled here
30  void xmlRequest(const std::string& option, bool readOnlyMode, cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut, const std::string& username);
31 
32  private:
33  void getDirectoryContent(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut);
34  void getPathContent(const std::string& basepath, const std::string& path, HttpXmlDocument* xmlOut);
35  void getFileContent(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut);
36  void saveFileContent(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut, const std::string& username);
37  void build(cgicc::Cgicc& cgiIn, HttpXmlDocument* xmlOut, const std::string& username);
38 
39  std::string safePathString(const std::string& path);
40  std::string safeExtensionString(const std::string& extension);
41 
42  public:
43  static const std::string SPECIAL_TYPE_FEInterface, SPECIAL_TYPE_DataProcessor, SPECIAL_TYPE_Table, SPECIAL_TYPE_SlowControls, SPECIAL_TYPE_Tools,
44  SPECIAL_TYPE_UserData, SPECIAL_TYPE_OutputData;
45 
46  static const std::string SOURCE_BASE_PATH, USER_DATA_PATH, OTSDAQ_DATA_PATH;
47 
48  static std::map<std::string /*special type*/, std::set<std::string> /*special file paths*/> getSpecialsMap(void);
49 
50  static void readFile(const std::string& basepath, const std::string& path, std::string& contents);
51  static void writeFile(const std::string& basepath,
52  const std::string& path,
53  const std::string& contents,
54  const std::string& username,
55  const unsigned long long& insertPos = -1,
56  const std::string& insertString = "");
57 
58  const std::set<std::string> ALLOWED_FILE_EXTENSIONS_;
59 };
60 
61 } // namespace ots
62 
63 #endif