Warning, file /include/root/THttpServer.h was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_THttpServer
0013 #define ROOT_THttpServer
0014
0015 #include "TNamed.h"
0016 #include "TList.h"
0017 #include "THttpCallArg.h"
0018
0019 #include <mutex>
0020 #include <map>
0021 #include <string>
0022 #include <memory>
0023 #include <queue>
0024 #include <thread>
0025 #include <vector>
0026
0027 class THttpEngine;
0028 class THttpTimer;
0029 class TRootSniffer;
0030
0031 class THttpServer : public TNamed {
0032
0033 protected:
0034 TList fEngines;
0035 std::unique_ptr<THttpTimer> fTimer;
0036 std::unique_ptr<TRootSniffer> fSniffer;
0037 Bool_t fTerminated{kFALSE};
0038 Long_t fMainThrdId{0};
0039 Long_t fProcessingThrdId{0};
0040 Bool_t fOwnThread{kFALSE};
0041 std::thread fThrd;
0042 Bool_t fWSOnly{kFALSE};
0043
0044 TString fJSROOTSYS;
0045 TString fTopName{"ROOT"};
0046 TString fJSROOT;
0047
0048 std::map<std::string, std::string> fLocations;
0049
0050 std::string fDefaultPage;
0051 std::string fDefaultPageCont;
0052 std::string fDrawPage;
0053 std::string fDrawPageCont;
0054 std::string fCors;
0055 std::string fCorsCredentials;
0056
0057 std::mutex fMutex;
0058 std::queue<std::shared_ptr<THttpCallArg>> fArgs;
0059
0060 std::mutex fWSMutex;
0061 std::vector<std::shared_ptr<THttpWSHandler>> fWSHandlers;
0062
0063 virtual void MissedRequest(THttpCallArg *arg);
0064
0065 virtual void ProcessRequest(std::shared_ptr<THttpCallArg> arg);
0066
0067 virtual void ProcessBatchHolder(std::shared_ptr<THttpCallArg> &arg);
0068
0069 void StopServerThread();
0070
0071 std::string BuildWSEntryPage();
0072
0073 void ReplaceJSROOTLinks(std::shared_ptr<THttpCallArg> &arg, const std::string &version = "");
0074
0075 static Bool_t VerifyFilePath(const char *fname);
0076
0077 THttpServer(const THttpServer &) = delete;
0078 THttpServer &operator=(const THttpServer &) = delete;
0079
0080 public:
0081 THttpServer(const char *engine = "http:8080");
0082 virtual ~THttpServer();
0083
0084 Bool_t CreateEngine(const char *engine);
0085
0086 Bool_t IsAnyEngine() const { return fEngines.GetSize() > 0; }
0087
0088
0089 TRootSniffer *GetSniffer() const { return fSniffer.get(); }
0090
0091 void SetSniffer(TRootSniffer *sniff);
0092
0093 Bool_t IsReadOnly() const;
0094
0095 void SetReadOnly(Bool_t readonly = kTRUE);
0096
0097 Bool_t IsWSOnly() const;
0098
0099 void SetWSOnly(Bool_t on = kTRUE);
0100
0101
0102 void SetTerminate();
0103
0104
0105 Bool_t IsTerminated() const { return fTerminated; }
0106
0107
0108
0109 void SetCors(const std::string &domain = "*") { fCors = domain; }
0110
0111
0112 Bool_t IsCors() const { return !fCors.empty(); }
0113
0114
0115 const char *GetCors() const { return fCors.c_str(); }
0116
0117
0118 void SetCorsCredentials(const std::string &value = "true") { fCorsCredentials = value; }
0119
0120
0121 Bool_t IsCorsCredentials() const { return !fCorsCredentials.empty(); }
0122
0123
0124 const char *GetCorsCredentials() const { return fCorsCredentials.c_str(); }
0125
0126
0127 void SetTopName(const char *top) { fTopName = top; }
0128
0129
0130 const char *GetTopName() const { return fTopName.Data(); }
0131
0132 void SetJSROOT(const char *location);
0133
0134 void AddLocation(const char *prefix, const char *path);
0135
0136 void SetDefaultPage(const std::string &filename = "");
0137
0138 void SetDrawPage(const std::string &filename = "");
0139
0140 void SetTimer(Long_t milliSec = 100, Bool_t mode = kTRUE);
0141
0142 void CreateServerThread();
0143
0144
0145 Bool_t IsFileRequested(const char *uri, TString &res) const;
0146
0147
0148 Bool_t ExecuteHttp(std::shared_ptr<THttpCallArg> arg);
0149
0150
0151 Bool_t SubmitHttp(std::shared_ptr<THttpCallArg> arg, Bool_t can_run_immediately = kFALSE);
0152
0153
0154 Int_t ProcessRequests();
0155
0156
0157 Bool_t Register(const char *subfolder, TObject *obj);
0158
0159
0160 Bool_t Unregister(TObject *obj);
0161
0162
0163 void RegisterWS(std::shared_ptr<THttpWSHandler> ws);
0164
0165
0166 void UnregisterWS(std::shared_ptr<THttpWSHandler> ws);
0167
0168
0169 std::shared_ptr<THttpWSHandler> FindWS(const char *name);
0170
0171
0172 Bool_t ExecuteWS(std::shared_ptr<THttpCallArg> &arg, Bool_t external_thrd = kFALSE, Bool_t wait_process = kFALSE);
0173
0174
0175 void Restrict(const char *path, const char *options);
0176
0177 Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon = nullptr);
0178
0179 Bool_t Hide(const char *fullname, Bool_t hide = kTRUE);
0180
0181 Bool_t SetIcon(const char *fullname, const char *iconname);
0182
0183 Bool_t CreateItem(const char *fullname, const char *title);
0184
0185 Bool_t SetItemField(const char *fullname, const char *name, const char *value);
0186
0187 const char *GetItemField(const char *fullname, const char *name);
0188
0189
0190 static const char *GetMimeType(const char *path);
0191
0192
0193 static char *ReadFileContent(const char *filename, Int_t &len);
0194
0195
0196 static std::string ReadFileContent(const std::string &filename);
0197
0198 ClassDefOverride(THttpServer, 0)
0199 };
0200
0201 #endif