22#include "RConfigure.h"
135 const char *jsrootsys =
gSystem->Getenv(
"JSROOTSYS");
137 jsrootsys =
gEnv->GetValue(
"HttpServ.JSRootPath", jsrootsys);
139 if (jsrootsys && *jsrootsys) {
140 if ((strncmp(jsrootsys,
"http://", 7)==0) || (strncmp(jsrootsys,
"https://", 8)==0))
147 TString jsdir = TString::Format(
"%s/js", TROOT::GetDataDir().Data());
148 if (gSystem->ExpandPathName(jsdir)) {
149 ::Warning(
"THttpServer::THttpServer",
"problems resolving '%s', set JSROOTSYS to proper JavaScript ROOT location",
157 Bool_t basic_sniffer = strstr(engine,
"basic_sniffer") !=
nullptr;
159 AddLocation(
"jsrootsys/", fJSROOTSYS.Data());
164 AddLocation(
"currentdir/",
".");
168 fDefaultPage = fJSROOTSYS +
"/files/online.htm";
169 fDrawPage = fJSROOTSYS +
"/files/draw.htm";
172 if (!basic_sniffer) {
174 if (snifferClass && snifferClass->
IsLoaded())
177 ::Warning(
"THttpServer::THttpServer",
"Fail to load TRootSnifferFull class, use basic functionality");
191 if (strchr(engine,
';') == 0) {
192 CreateEngine(engine);
198 if ((strcmp(opt,
"readonly") == 0) || (strcmp(opt,
"ro") == 0)) {
199 GetSniffer()->SetReadOnly(
kTRUE);
200 }
else if ((strcmp(opt,
"readwrite") == 0) || (strcmp(opt,
"rw") == 0)) {
201 GetSniffer()->SetReadOnly(
kFALSE);
202 }
else if (strcmp(opt,
"global") == 0) {
203 GetSniffer()->SetScanGlobalDir(
kTRUE);
204 }
else if (strcmp(opt,
"noglobal") == 0) {
205 GetSniffer()->SetScanGlobalDir(
kFALSE);
206 }
else if (strncmp(opt,
"cors=", 5) == 0) {
208 }
else if (strcmp(opt,
"cors") == 0) {
229 while (
auto engine =
dynamic_cast<THttpEngine *
>(iter()))
302 fSniffer->SetAllowPostObject(allow_post_obj);
337 if (!prefix || (*prefix == 0))
360 fJSROOT = location ? location :
"";
429 const char *arg = strchr(engine,
':');
435 clname.
Append(engine, arg - engine);
440 if ((clname.
Length() == 0) || (clname ==
"http") || (clname ==
"civetweb")) {
443 }
else if (clname ==
"socket") {
449 }
else if (clname ==
"https") {
451 }
else if (clname ==
"fastcgi") {
503 Error(
"SetTimer",
"Server runs already in special thread, therefore no any timer can be created");
505 fTimer = std::make_unique<THttpTimer>(milliSec,
mode, *
this);
529 std::thread thrd([
this] {
539 std::this_thread::sleep_for(std::chrono::milliseconds(1));
544 fThrd = std::move(thrd);
569 if (!fname || (*fname == 0))
577 const char *next = strpbrk(fname,
"/\\");
582 if ((next == fname + 2) && (*fname ==
'.') && (*(fname + 1) ==
'.')) {
591 if ((next == fname + 1) && (*fname ==
'.')) {
619 if (!uri || (*uri == 0))
628 fname.
Remove(0, pos + (entry.first.length() - 1));
631 res = entry.second.c_str();
632 if ((fname[0] ==
'/') && (res[res.
Length() - 1] ==
'/'))
661 std::unique_lock<std::mutex> lk(
fMutex);
662 arg->fNotifyFlag =
kFALSE;
691 arg->NotifyCondition();
696 std::unique_lock<std::mutex> lk(
fMutex);
717 Warning(
"ProcessRequests",
"Changing main thread to %ld", (
long)
id);
737 std::unique_lock<std::mutex> lk(
fMutex, std::defer_lock);
741 std::shared_ptr<THttpCallArg> arg;
744 if (!
fArgs.empty()) {
753 if (arg->fFileName ==
"root_batch_holder.js") {
758 auto prev =
fSniffer->SetCurrentCallArg(arg.get());
768 arg->NotifyCondition();
773 while (
auto engine =
static_cast<THttpEngine *
>(iter())) {
804 auto wsptr =
FindWS(arg->GetPathName());
806 if (!wsptr || !wsptr->ProcessBatchHolder(arg)) {
808 arg->NotifyCondition();
818 std::string arr =
"[";
821 std::lock_guard<std::mutex> grd(
fWSMutex);
823 if (arr.length() > 1)
826 arr.append(
TString::Format(
"{ name: \"%s\", title: \"%s\" }", ws->GetName(), ws->GetTitle()).Data());
834 std::string arg =
"\"$$$wslist$$$\"";
836 auto pos = res.find(arg);
837 if (pos != std::string::npos)
838 res.replace(pos, arg.length(), arr);
852 const std::string place_holder =
"<!--jsroot_importmap-->";
854 auto p = arg->fContent.find(place_holder);
856 bool old_format = (p == std::string::npos);
860 if (arg->fPathName.Length() > 0)
862 for (
Int_t n = 1;
n < arg->fPathName.Length()-1; ++
n)
863 if (arg->fPathName[
n] ==
'/') {
864 if (arg->fPathName[
n-1] !=
'/') {
876 if (!version.empty()) {
878 std::string search =
"from './jsrootsys/";
879 std::string replace =
"from './" + version +
"/jsrootsys/";
880 arg->ReplaceAllinContent(search, replace);
882 search =
"from './rootui5sys/";
883 replace =
"from './" + version +
"/rootui5sys/";
884 arg->ReplaceAllinContent(search, replace);
886 search =
"jsrootsys/scripts/JSRoot.core.";
887 replace = version +
"/jsrootsys/scripts/JSRoot.core.";
888 arg->ReplaceAllinContent(search, replace,
true);
889 arg->AddNoCacheHeader();
897 if (repl.back() !=
'/')
902 while (slash_cnt-- > 0) repl.append(
"../");
903 repl.append(
"jsrootsys/");
908 arg->ReplaceAllinContent(
"=\"jsrootsys/", repl);
909 arg->ReplaceAllinContent(
"from './jsrootsys/",
TString::Format(
"from '%s", repl.substr(2).c_str()).Data());
914 std::string path_prefix, jsroot_prefix;
917 while (slash_cnt-- > 0)
918 path_prefix.append(
"../");
923 if (!version.empty())
924 path_prefix.append(version +
"/");
927 jsroot_prefix =
fJSROOT.Data();
928 if (jsroot_prefix.back() !=
'/')
929 jsroot_prefix.append(
"/");
931 jsroot_prefix = path_prefix +
"jsrootsys/";
934 static std::map<std::string, std::string> modules = {
935 {
"jsroot",
"main.mjs"}, {
"jsroot/core",
"core.mjs"},
936 {
"jsroot/io",
"io.mjs"}, {
"jsroot/tree",
"tree.mjs"},
937 {
"jsroot/draw",
"draw.mjs"}, {
"jsroot/gui",
"gui.mjs"},
938 {
"jsroot/d3",
"d3.mjs"}, {
"jsroot/three",
"three.mjs"}, {
"jsroot/three_addons",
"three_addons.mjs"},
939 {
"jsroot/geom",
"geom/TGeoPainter.mjs"}, {
"jsroot/hpainter",
"gui/HierarchyPainter.mjs"},
940 {
"jsroot/webwindow",
"webwindow.mjs"}
945 while ((--pspace > 0) && (arg->fContent[pspace] ==
' ') && (space_prefix.
Length() < 20))
949 TString importmap =
"<script type=\"importmap\">\n";
950 importmap += space_prefix +
"{\n";
951 importmap += space_prefix +
" \"imports\": ";
952 for (
auto &entry : modules) {
953 importmap.
Append(
TString::Format(
"%s\n%s \"%s\": \"%smodules/%s\"", first ?
"{" :
",", space_prefix.
Data(), entry.first.c_str(), jsroot_prefix.c_str(), entry.second.c_str()));
959 if (entry.first !=
"jsrootsys/")
960 importmap.
Append(
TString::Format(
",\n%s \"%s\": \"%s%s\"", space_prefix.
Data(), entry.first.c_str(), path_prefix.c_str(), entry.first.c_str()));
962 importmap.
Append(space_prefix +
" }\n");
963 importmap.
Append(space_prefix +
"}\n");
964 importmap.
Append(space_prefix +
"</script>\n");
966 arg->fContent.erase(p, place_holder.length());
968 arg->fContent.insert(p, importmap.
Data());
985 if ((arg->fFileName ==
"root.websocket") || (arg->fFileName ==
"root.longpoll")) {
990 if (arg->fFileName.IsNull() || (arg->fFileName ==
"index.htm") || (arg->fFileName ==
"default.htm")) {
994 if (arg->fFileName ==
"default.htm") {
1000 auto wsptr =
FindWS(arg->GetPathName());
1002 auto handler = wsptr.get();
1009 arg->fContent = handler->GetDefaultPageContent().Data();
1011 if (arg->fContent.find(
"file:") == 0) {
1012 const char *fname = arg->fContent.c_str() + 5;
1018 version = handler->GetCodeVersion();
1020 handler->VerifyDefaultPageContent(arg);
1024 if (arg->fContent.empty() && arg->fFileName.IsNull() && arg->fPathName.IsNull() &&
IsWSOnly()) {
1029 arg->SetContent(
"refused");
1033 if (arg->fContent.empty() && !
IsWSOnly()) {
1041 if (arg->fContent.empty()) {
1044 }
else if (!arg->Is404()) {
1048 const char *hjsontag =
"\"$$$h.json$$$\"";
1051 if (arg->fContent.find(hjsontag) != std::string::npos) {
1054 const char *topname =
fTopName.Data();
1055 if (arg->fTopName.Length() > 0)
1056 topname = arg->fTopName.Data();
1057 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store);
1059 arg->ReplaceAllinContent(hjsontag, h_json.
Data());
1061 arg->AddNoCacheHeader();
1063 if (arg->fQuery.Index(
"nozip") ==
kNPOS)
1066 arg->SetContentType(
"text/html");
1071 if ((arg->fFileName ==
"draw.htm") && !
IsWSOnly()) {
1078 const char *rootjsontag =
"\"$$$root.json$$$\"";
1079 const char *hjsontag =
"\"$$$h.json$$$\"";
1085 if ((arg->fQuery.Index(
"no_h_json") ==
kNPOS) && (arg->fQuery.Index(
"webcanvas") ==
kNPOS) &&
1086 (arg->fContent.find(hjsontag) != std::string::npos)) {
1089 const char *topname =
fTopName.Data();
1090 if (arg->fTopName.Length() > 0)
1091 topname = arg->fTopName.Data();
1092 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store,
kTRUE);
1094 arg->ReplaceAllinContent(hjsontag, h_json.
Data());
1097 if ((arg->fQuery.Index(
"no_root_json") ==
kNPOS) && (arg->fQuery.Index(
"webcanvas") ==
kNPOS) &&
1098 (arg->fContent.find(rootjsontag) != std::string::npos)) {
1100 if (
fSniffer->Produce(arg->fPathName.Data(),
"root.json",
"compact=23", str))
1101 arg->ReplaceAllinContent(rootjsontag, str);
1103 arg->AddNoCacheHeader();
1104 if (arg->fQuery.Index(
"nozip") ==
kNPOS)
1106 arg->SetContentType(
"text/html");
1111 if ((arg->fFileName ==
"favicon.ico") && arg->fPathName.IsNull()) {
1112 arg->SetFile(
fJSROOTSYS +
"/img/RootIcon.ico");
1123 if (!arg->fPathName.IsNull() && !arg->fFileName.IsNull()) {
1124 TString wsname = arg->fPathName, fname;
1125 auto pos = wsname.
First(
'/');
1127 wsname = arg->fPathName;
1129 wsname = arg->fPathName(0, pos);
1130 fname = arg->fPathName(pos + 1, arg->fPathName.Length() - pos);
1134 fname.Append(arg->fFileName);
1140 if (ws && ws->CanServeFiles()) {
1141 TString fdir = ws->GetDefaultPageContent();
1143 if (fdir.
Index(
"file:") == 0) {
1145 auto separ = fdir.
Last(
'/');
1168 if (arg->fContent.empty())
1171 Bool_t compact = arg->fQuery.Index(
"compact") !=
kNPOS,
1175 res.
Form(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1183 auto len0 = res.
Length();
1184 const char *topname =
fTopName.Data();
1185 if (arg->fTopName.Length() > 0)
1186 topname = arg->fTopName.Data();
1187 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store,
filename ==
"get.xml");
1188 processed = res.
Length() > len0;
1195 arg->SetContent(std::string(res.
Data()));
1202 const char *topname =
fTopName.Data();
1203 if (arg->fTopName.Length() > 0)
1204 topname = arg->fTopName.Data();
1205 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store);
1208 arg->SetContent(std::string(res.
Data()));
1212 }
else if (
fSniffer->Produce(arg->fPathName.Data(),
filename.Data(), arg->fQuery.Data(), arg->fContent)) {
1229 const char *parname =
fSniffer->IsStreamerInfoItem(arg->fPathName.Data()) ?
"BVersion" :
"MVersion";
1234 arg->AddNoCacheHeader();
1238 arg->AddHeader(
"Access-Control-Allow-Origin",
GetCors());
1241 arg->AddHeader(
"Access-Control-Expose-Headers",
"Content-Range, Content-Length, Date");
1242 arg->AddHeader(
"Access-Control-Allow-Methods",
"GET, HEAD, OPTIONS");
1253 return fSniffer->RegisterObject(subfolder, obj);
1263 return fSniffer->UnregisterObject(obj);
1273 std::lock_guard<std::mutex> grd(
fWSMutex);
1282 std::lock_guard<std::mutex> grd(
fWSMutex);
1295 std::lock_guard<std::mutex> grd(
fWSMutex);
1297 if (strcmp(
name, ws->GetName()) == 0)
1314 auto wsptr =
FindWS(arg->GetPathName());
1316 auto handler = wsptr.get();
1318 if (!handler && !external_thrd)
1321 if (external_thrd && (!handler || !handler->AllowMTProcess())) {
1323 std::unique_lock<std::mutex> lk(
fMutex);
1327 arg->fCond.wait(lk);
1339 if (arg->fFileName ==
"root.websocket") {
1341 process = handler->HandleWS(arg);
1342 }
else if (arg->fFileName ==
"root.longpoll") {
1344 if (arg->fQuery.BeginsWith(
"raw_connect") || arg->fQuery.BeginsWith(
"txt_connect")) {
1347 arg->SetMethod(
"WS_CONNECT");
1349 bool israw = arg->fQuery.BeginsWith(
"raw_connect");
1354 if (handler->HandleWS(arg)) {
1355 arg->SetMethod(
"WS_READY");
1357 if (handler->HandleWS(arg))
1358 arg->SetTextContent(std::string(israw ?
"txt:" :
"") + std::to_string(arg->GetWSId()));
1360 arg->TakeWSEngine();
1363 process = arg->IsText();
1370 arg->SetWSId(std::stoul(connid));
1372 arg->SetMethod(
"WS_CLOSE");
1373 arg->SetTextContent(
"OK");
1375 arg->SetMethod(
"WS_DATA");
1378 process = handler->HandleWS(arg);
1437 return fSniffer->RegisterCommand(cmdname, method, icon);
1445 return SetItemField(foldername,
"_hidden", hide ?
"true" : (
const char *)0);
1464 return fSniffer->CreateItem(fullname, title);
1488 static const struct {
1493 {
".json", 5,
"application/json"},
1494 {
".bin", 4,
"application/x-binary"},
1495 {
".gif", 4,
"image/gif"},
1496 {
".jpg", 4,
"image/jpeg"},
1497 {
".png", 4,
"image/png"},
1498 {
".html", 5,
"text/html"},
1499 {
".htm", 4,
"text/html"},
1500 {
".shtm", 5,
"text/html"},
1501 {
".shtml", 6,
"text/html"},
1502 {
".css", 4,
"text/css"},
1503 {
".js", 3,
"application/x-javascript"},
1504 {
".mjs", 4,
"text/javascript"},
1505 {
".ico", 4,
"image/x-icon"},
1506 {
".jpeg", 5,
"image/jpeg"},
1507 {
".svg", 4,
"image/svg+xml"},
1508 {
".txt", 4,
"text/plain"},
1509 {
".torrent", 8,
"application/x-bittorrent"},
1510 {
".wav", 4,
"audio/x-wav"},
1511 {
".mp3", 4,
"audio/x-mp3"},
1512 {
".mid", 4,
"audio/mid"},
1513 {
".m3u", 4,
"audio/x-mpegurl"},
1514 {
".ogg", 4,
"application/ogg"},
1515 {
".ram", 4,
"audio/x-pn-realaudio"},
1516 {
".xslt", 5,
"application/xml"},
1517 {
".xsl", 4,
"application/xml"},
1518 {
".ra", 3,
"audio/x-pn-realaudio"},
1519 {
".doc", 4,
"application/msword"},
1520 {
".exe", 4,
"application/octet-stream"},
1521 {
".zip", 4,
"application/x-zip-compressed"},
1522 {
".xls", 4,
"application/excel"},
1523 {
".tgz", 4,
"application/x-tar-gz"},
1524 {
".tar", 4,
"application/x-tar"},
1525 {
".gz", 3,
"application/x-gunzip"},
1526 {
".arj", 4,
"application/x-arj-compressed"},
1527 {
".rar", 4,
"application/x-arj-compressed"},
1528 {
".rtf", 4,
"application/rtf"},
1529 {
".pdf", 4,
"application/pdf"},
1530 {
".swf", 4,
"application/x-shockwave-flash"},
1531 {
".mpg", 4,
"video/mpeg"},
1532 {
".webm", 5,
"video/webm"},
1533 {
".mpeg", 5,
"video/mpeg"},
1534 {
".mov", 4,
"video/quicktime"},
1535 {
".mp4", 4,
"video/mp4"},
1536 {
".m4v", 4,
"video/x-m4v"},
1537 {
".asf", 4,
"video/x-ms-asf"},
1538 {
".avi", 4,
"video/x-msvideo"},
1539 {
".bmp", 4,
"image/bmp"},
1540 {
".ttf", 4,
"application/x-font-ttf"},
1541 {
".woff", 5,
"font/woff"},
1542 {
".woff2", 6,
"font/woff2"},
1545 int path_len = strlen(path);
1556 return "text/plain";
1568 std::ifstream is(
filename, std::ios::in | std::ios::binary);
1572 is.seekg(0, is.end);
1574 is.seekg(0, is.beg);
1592 std::ifstream is(
filename, std::ios::in | std::ios::binary);
1595 is.seekg(0, std::ios::end);
1596 res.resize(is.tellg());
1597 is.seekg(0, std::ios::beg);
1598 is.read((
char *)res.data(), res.length());
bool Bool_t
Boolean (0=false, 1=true) (bool)
int Int_t
Signed integer 4 bytes (int)
int Ssiz_t
String size (currently int)
long Long_t
Signed long integer 4 bytes (long). Size depends on architecture.
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
if(isa< VarDecl >(D)||isa< FieldDecl >(D)||isa< EnumConstantDecl >(D))
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize id
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void on
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
Option_t Option_t TPoint TPoint const char mode
R__EXTERN TSystem * gSystem
static const struct @243147061004330160235326056313274363054075327066 builtin_mime_types[]
THttpEngine implementation, based on civetweb embedded server.
TClass instances represent classes, structs and namespaces in the ROOT type system.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
Bool_t IsLoaded() const
Return true if the shared library of this class is currently in the a process's memory.
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
THttpEngine implementation, based on fastcgi package.
Contains arguments for single HTTP call.
void Set404()
mark reply as 404 error - page/request not exists or refused
Abstract class for implementing http protocol for THttpServer.
void SetServer(THttpServer *serv)
virtual Bool_t Create(const char *)
Method to create all components of engine.
Emulation of websocket with long poll requests.
Online http server for arbitrary ROOT application.
Bool_t IsReadOnly() const
returns read-only mode
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon=nullptr)
Register command which can be executed from web interface.
TString fJSROOT
! location of external JSROOT files
virtual void ProcessRequest(std::shared_ptr< THttpCallArg > arg)
Process single http request.
std::shared_ptr< THttpWSHandler > FindWS(const char *name)
Find web-socket handler with given name.
std::unique_ptr< TRootSniffer > fSniffer
! sniffer provides access to ROOT objects hierarchy
void SetTimer(Long_t milliSec=100, Bool_t mode=kTRUE)
Create timer which will invoke ProcessRequests() function periodically.
virtual void ProcessBatchHolder(std::shared_ptr< THttpCallArg > &arg)
Process special http request for root_batch_holder.js script.
std::vector< std::shared_ptr< THttpWSHandler > > fWSHandlers
! list of WS handlers
virtual ~THttpServer()
destructor
void SetTerminate()
set termination flag, no any further requests will be processed
virtual void MissedRequest(THttpCallArg *arg)
Method called when THttpServer cannot process request.
Bool_t fOwnThread
! true when specialized thread allocated for processing requests
void SetSniffer(TRootSniffer *sniff)
Set TRootSniffer to the server.
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
void SetReadOnly(Bool_t readonly=kTRUE)
Set read-only mode for the server (default on)
const char * GetItemField(const char *fullname, const char *name)
Get item field from sniffer.
const char * GetCors() const
Returns specified CORS domain.
std::thread fThrd
! own thread
void StopServerThread()
Stop server thread.
Int_t ProcessRequests()
Process submitted requests, must be called from appropriate thread.
Bool_t ExecuteWS(std::shared_ptr< THttpCallArg > &arg, Bool_t external_thrd=kFALSE, Bool_t wait_process=kFALSE)
Execute WS request.
void RegisterWS(std::shared_ptr< THttpWSHandler > ws)
Register WS handler.
Long_t fProcessingThrdId
! id of the thread where events are recently processing
TString fTopName
! name of top folder, default - "ROOT"
void SetDrawPage(const std::string &filename="")
Set drawing HTML page.
Bool_t CreateItem(const char *fullname, const char *title)
Create item in sniffer.
Bool_t ExecuteHttp(std::shared_ptr< THttpCallArg > arg)
Execute HTTP request.
Bool_t Hide(const char *fullname, Bool_t hide=kTRUE)
Hides folder or element from web gui.
Bool_t IsCorsCredentials() const
Returns kTRUE if Access-Control-Allow-Credentials header should be used.
void AddLocation(const char *prefix, const char *path)
Add files location, which could be used in the server.
std::map< std::string, std::string > fLocations
! list of local directories, which could be accessed via server
Bool_t SubmitHttp(std::shared_ptr< THttpCallArg > arg, Bool_t can_run_immediately=kFALSE)
Submit HTTP request.
Long_t fMainThrdId
! id of the thread for processing requests
TString fJSROOTSYS
! location of local JSROOT files
std::unique_ptr< THttpTimer > fTimer
! timer used to access main thread
Bool_t fWSOnly
! when true, handle only websockets / longpoll engine
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
TList fEngines
! engines which runs http server
Bool_t IsCors() const
Returns kTRUE if CORS was configured.
const char * GetCorsCredentials() const
Returns specified CORS credentials value - if any.
std::queue< std::shared_ptr< THttpCallArg > > fArgs
! submitted arguments
void SetDefaultPage(const std::string &filename="")
Set default HTML page.
THttpServer(const THttpServer &)=delete
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
void CreateServerThread()
Creates special thread to process all requests, directed to http server.
std::string fDrawPageCont
! content of draw html page
Bool_t Unregister(TObject *obj)
Unregister object.
void SetWSOnly(Bool_t on=kTRUE)
Set websocket-only mode.
std::string BuildWSEntryPage()
Create summary page with active WS handlers.
Bool_t IsWSOnly() const
returns true if only websockets are handled by the server
std::mutex fWSMutex
! mutex to protect WS handler lists
virtual Bool_t CreateEngine(const char *engine)
Factory method to create different http engines.
Bool_t SetIcon(const char *fullname, const char *iconname)
Set name of icon, used in browser together with the item.
std::string fDrawPage
! file name for drawing of single element
std::string fDefaultPageCont
! content of default html page
static Bool_t VerifyFilePath(const char *fname)
Checked that filename does not contains relative path below current directory.
Bool_t IsAllowPostObject() const
Returns true if server accept object content in POST reequests.
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
Set item field in sniffer.
void SetAllowPostObject(Bool_t allow_post_obj)
Set flag to allow receive and desereilize objects in POST requests.
void SetJSROOT(const char *location)
Set location of JSROOT to use with the server.
std::mutex fMutex
! mutex to protect list with arguments
std::string fDefaultPage
! file name for default page name
void UnregisterWS(std::shared_ptr< THttpWSHandler > ws)
Unregister WS handler.
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
void ReplaceJSROOTLinks(std::shared_ptr< THttpCallArg > &arg, const std::string &version="")
Replaces all references like "jsrootsys/..." or other pre-configured pathes.
Bool_t fTerminated
! termination flag, disables all requests processing
void Restrict(const char *path, const char *options)
Restrict access to specified object.
void Timeout() override
timeout handler used to process http requests in main ROOT thread
THttpTimer(Long_t milliSec, Bool_t mode, THttpServer &serv)
!< server processing requests
Class for user-side handling of websocket with THttpServer.
TObject * At(Int_t idx) const override
Int_t GetLast() const override
Return index of last object in array.
virtual const char * GetName() const
Returns name of object.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TObject()
TObject constructor.
static const TString & GetRootSys()
Get the rootsys directory in the installation. Static utility function.
static const TString & GetDataDir()
Get the data directory in the installation. Static utility function.
Storage of hierarchy scan in TRootSniffer in JSON format.
Storage of hierarchy scan in TRootSniffer in XML format.
Sniffer of ROOT objects, data provider for THttpServer.
void CreateOwnTopFolder()
Create own TFolder structures independent from gROOT This allows to have many independent TRootSniffe...
void SetScanGlobalDir(Bool_t on=kTRUE)
When enabled (default), sniffer scans gROOT for files, canvases, histograms.
Ssiz_t First(char c) const
Find first occurrence of a character c.
const char * Data() const
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
Ssiz_t Last(char c) const
Find last occurrence of a character c.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
TString & Remove(Ssiz_t pos)
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
static Long_t SelfId()
Static method returning the id for the current thread.
TTimer(const TTimer &)=delete
This class represents a WWW compatible URL.
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
void SetOptions(const char *opt)
void ParseOptions() const
Parse URL options into a key/value map.
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.