22#include "RConfigure.h"
138 jsrootsys =
gEnv->
GetValue(
"HttpServ.JSRootPath", jsrootsys);
140 if (jsrootsys && *jsrootsys) {
141 if ((strncmp(jsrootsys,
"http://", 7)==0) || (strncmp(jsrootsys,
"https://", 8)==0))
150 ::Warning(
"THttpServer::THttpServer",
"problems resolving '%s', set JSROOTSYS to proper JavaScript ROOT location",
158 Bool_t basic_sniffer = strstr(engine,
"basic_sniffer") !=
nullptr;
173 if (!basic_sniffer) {
175 if (snifferClass && snifferClass->
IsLoaded())
178 ::Warning(
"THttpServer::THttpServer",
"Fail to load TRootSnifferFull class, use basic functionality");
192 if (strchr(engine,
';') == 0) {
199 if ((strcmp(opt,
"readonly") == 0) || (strcmp(opt,
"ro") == 0)) {
201 }
else if ((strcmp(opt,
"readwrite") == 0) || (strcmp(opt,
"rw") == 0)) {
203 }
else if (strcmp(opt,
"global") == 0) {
205 }
else if (strcmp(opt,
"noglobal") == 0) {
207 }
else if (strncmp(opt,
"cors=", 5) == 0) {
209 }
else if (strcmp(opt,
"cors") == 0) {
230 while (
auto engine =
dynamic_cast<THttpEngine *
>(iter()))
303 fSniffer->SetAllowPostObject(allow_post_obj);
341 if (!prefix || (*prefix == 0))
366 if (!prefix || (*prefix == 0) || !path || (*path == 0))
386 fJSROOT = location ? location :
"";
455 const char *arg = strchr(engine,
':');
461 clname.
Append(engine, arg - engine);
466 if ((clname.
Length() == 0) || (clname ==
"http") || (clname ==
"civetweb")) {
469 }
else if (clname ==
"socket") {
475 }
else if (clname ==
"https") {
477 }
else if (clname ==
"fastcgi") {
529 Error(
"SetTimer",
"Server runs already in special thread, therefore no any timer can be created");
531 fTimer = std::make_unique<THttpTimer>(milliSec,
mode, *
this);
555 std::thread thrd([
this] {
565 std::this_thread::sleep_for(std::chrono::milliseconds(1));
570 fThrd = std::move(thrd);
595 if (!fname || (*fname == 0))
603 const char *next = strpbrk(fname,
"/\\");
608 if ((next == fname + 2) && (*fname ==
'.') && (*(fname + 1) ==
'.')) {
617 if ((next == fname + 1) && (*fname ==
'.')) {
645 if (!uri || (*uri == 0))
650 auto file_in_dir = [&fname](
const std::string &dir) {
652 if ((fname[0] ==
'/') && (path[path.
Length() - 1] ==
'/'))
662 fname.
Remove(0, pos + (entry.first.length() - 1));
669 if (entry.second.size() > 1) {
670 for (
auto &dir : entry.second) {
671 res = file_in_dir(dir);
673 if (std::filesystem::exists(res.
Data(), ec))
677 res = file_in_dir(entry.second.front());
704 std::unique_lock<std::mutex> lk(
fMutex);
705 arg->fNotifyFlag =
kFALSE;
734 arg->NotifyCondition();
739 std::unique_lock<std::mutex> lk(
fMutex);
760 Warning(
"ProcessRequests",
"Changing main thread to %ld", (
long)
id);
780 std::unique_lock<std::mutex> lk(
fMutex, std::defer_lock);
784 std::shared_ptr<THttpCallArg> arg;
787 if (!
fArgs.empty()) {
796 if (arg->fFileName ==
"root_batch_holder.js") {
801 auto prev =
fSniffer->SetCurrentCallArg(arg.get());
811 arg->NotifyCondition();
816 while (
auto engine =
static_cast<THttpEngine *
>(iter())) {
847 auto wsptr =
FindWS(arg->GetPathName());
849 if (!wsptr || !wsptr->ProcessBatchHolder(arg)) {
851 arg->NotifyCondition();
861 std::string arr =
"[";
864 std::lock_guard<std::mutex> grd(
fWSMutex);
866 if (arr.length() > 1)
869 arr.append(
TString::Format(
"{ name: \"%s\", title: \"%s\" }", ws->GetName(), ws->GetTitle()).
Data());
877 std::string arg =
"\"$$$wslist$$$\"";
879 auto pos = res.find(arg);
880 if (pos != std::string::npos)
881 res.replace(pos, arg.length(), arr);
895 const std::string place_holder =
"<!--jsroot_importmap-->";
897 auto p = arg->fContent.find(place_holder);
899 bool old_format = (
p == std::string::npos);
903 if (arg->fPathName.Length() > 0)
905 for (
Int_t n = 1;
n < arg->fPathName.Length()-1; ++
n)
906 if (arg->fPathName[
n] ==
'/') {
907 if (arg->fPathName[
n-1] !=
'/') {
919 if (!version.empty()) {
921 std::string search =
"from './jsrootsys/";
922 std::string replace =
"from './" + version +
"/jsrootsys/";
923 arg->ReplaceAllinContent(search, replace);
925 search =
"from './rootui5sys/";
926 replace =
"from './" + version +
"/rootui5sys/";
927 arg->ReplaceAllinContent(search, replace);
929 search =
"jsrootsys/scripts/JSRoot.core.";
930 replace = version +
"/jsrootsys/scripts/JSRoot.core.";
931 arg->ReplaceAllinContent(search, replace,
true);
932 arg->AddNoCacheHeader();
940 if (repl.back() !=
'/')
945 while (slash_cnt-- > 0) repl.append(
"../");
946 repl.append(
"jsrootsys/");
951 arg->ReplaceAllinContent(
"=\"jsrootsys/", repl);
952 arg->ReplaceAllinContent(
"from './jsrootsys/",
TString::Format(
"from '%s", repl.substr(2).c_str()).
Data());
957 std::string path_prefix, jsroot_prefix;
960 while (slash_cnt-- > 0)
961 path_prefix.append(
"../");
966 if (!version.empty())
967 path_prefix.append(version +
"/");
971 if (jsroot_prefix.back() !=
'/')
972 jsroot_prefix.append(
"/");
974 jsroot_prefix = path_prefix +
"jsrootsys/";
977 static std::map<std::string, std::string> modules = {
978 {
"jsroot",
"main.mjs"}, {
"jsroot/core",
"core.mjs"},
979 {
"jsroot/io",
"io.mjs"}, {
"jsroot/tree",
"tree.mjs"},
980 {
"jsroot/draw",
"draw.mjs"}, {
"jsroot/gui",
"gui.mjs"},
981 {
"jsroot/d3",
"d3.mjs"}, {
"jsroot/three",
"three.mjs"}, {
"jsroot/three_addons",
"three_addons.mjs"},
982 {
"jsroot/geom",
"geom/TGeoPainter.mjs"}, {
"jsroot/hpainter",
"gui/HierarchyPainter.mjs"},
983 {
"jsroot/webwindow",
"webwindow.mjs"}
988 while ((--pspace > 0) && (arg->fContent[pspace] ==
' ') && (space_prefix.
Length() < 20))
992 TString importmap =
"<script type=\"importmap\">\n";
993 importmap += space_prefix +
"{\n";
994 importmap += space_prefix +
" \"imports\": ";
995 for (
auto &entry : modules) {
996 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()));
1002 if (entry.first !=
"jsrootsys/")
1003 importmap.
Append(
TString::Format(
",\n%s \"%s\": \"%s%s\"", space_prefix.
Data(), entry.first.c_str(), path_prefix.c_str(), entry.first.c_str()));
1005 importmap.
Append(space_prefix +
" }\n");
1006 importmap.
Append(space_prefix +
"}\n");
1007 importmap.
Append(space_prefix +
"</script>\n");
1009 arg->fContent.erase(
p, place_holder.length());
1011 arg->fContent.insert(
p, importmap.
Data());
1028 if ((arg->fFileName ==
"root.websocket") || (arg->fFileName ==
"root.longpoll")) {
1033 if (arg->fFileName.IsNull() || (arg->fFileName ==
"index.htm") || (arg->fFileName ==
"default.htm")) {
1035 std::string version;
1037 if (arg->fFileName ==
"default.htm") {
1043 auto wsptr =
FindWS(arg->GetPathName());
1045 auto handler = wsptr.get();
1052 arg->fContent = handler->GetDefaultPageContent().Data();
1054 if (arg->fContent.find(
"file:") == 0) {
1055 const char *fname = arg->fContent.c_str() + 5;
1061 version = handler->GetCodeVersion();
1063 handler->VerifyDefaultPageContent(arg);
1067 if (arg->fContent.empty() && arg->fFileName.IsNull() && arg->fPathName.IsNull() &&
IsWSOnly()) {
1072 arg->SetContent(
"refused");
1076 if (arg->fContent.empty() && !
IsWSOnly()) {
1084 if (arg->fContent.empty()) {
1087 }
else if (!arg->Is404()) {
1091 const char *hjsontag =
"\"$$$h.json$$$\"";
1094 if (arg->fContent.find(hjsontag) != std::string::npos) {
1098 if (arg->fTopName.Length() > 0)
1099 topname = arg->fTopName.Data();
1100 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store);
1102 arg->ReplaceAllinContent(hjsontag, h_json.
Data());
1104 arg->AddNoCacheHeader();
1106 if (arg->fQuery.Index(
"nozip") ==
kNPOS)
1109 arg->SetContentType(
"text/html");
1114 if ((arg->fFileName ==
"draw.htm") && !
IsWSOnly()) {
1121 const char *rootjsontag =
"\"$$$root.json$$$\"";
1122 const char *hjsontag =
"\"$$$h.json$$$\"";
1128 if ((arg->fQuery.Index(
"no_h_json") ==
kNPOS) && (arg->fQuery.Index(
"webcanvas") ==
kNPOS) &&
1129 (arg->fContent.find(hjsontag) != std::string::npos)) {
1133 if (arg->fTopName.Length() > 0)
1134 topname = arg->fTopName.Data();
1135 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store,
kTRUE);
1137 arg->ReplaceAllinContent(hjsontag, h_json.
Data());
1140 if ((arg->fQuery.Index(
"no_root_json") ==
kNPOS) && (arg->fQuery.Index(
"webcanvas") ==
kNPOS) &&
1141 (arg->fContent.find(rootjsontag) != std::string::npos)) {
1143 if (
fSniffer->Produce(arg->fPathName.Data(),
"root.json",
"compact=23", str))
1144 arg->ReplaceAllinContent(rootjsontag, str);
1146 arg->AddNoCacheHeader();
1147 if (arg->fQuery.Index(
"nozip") ==
kNPOS)
1149 arg->SetContentType(
"text/html");
1154 if ((arg->fFileName ==
"favicon.ico") && arg->fPathName.IsNull()) {
1155 arg->SetFile(
fJSROOTSYS +
"/img/RootIcon.ico");
1166 if (!arg->fPathName.IsNull() && !arg->fFileName.IsNull()) {
1167 TString wsname = arg->fPathName, fname;
1168 auto pos = wsname.
First(
'/');
1170 wsname = arg->fPathName;
1172 wsname = arg->fPathName(0, pos);
1173 fname = arg->fPathName(pos + 1, arg->fPathName.Length() - pos);
1177 fname.Append(arg->fFileName);
1183 if (ws && ws->CanServeFiles()) {
1184 TString fdir = ws->GetDefaultPageContent();
1186 if (fdir.
Index(
"file:") == 0) {
1188 auto separ = fdir.
Last(
'/');
1211 if (arg->fContent.empty())
1214 Bool_t compact = arg->fQuery.Index(
"compact") !=
kNPOS,
1218 res.
Form(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
1226 auto len0 = res.
Length();
1228 if (arg->fTopName.Length() > 0)
1229 topname = arg->fTopName.Data();
1230 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store,
filename ==
"get.xml");
1231 processed = res.
Length() > len0;
1238 arg->SetContent(std::string(res.
Data()));
1246 if (arg->fTopName.Length() > 0)
1247 topname = arg->fTopName.Data();
1248 fSniffer->ScanHierarchy(topname, arg->fPathName.Data(), &store);
1251 arg->SetContent(std::string(res.
Data()));
1255 }
else if (
fSniffer->Produce(arg->fPathName.Data(),
filename.Data(), arg->fQuery.Data(), arg->fContent)) {
1272 const char *parname =
fSniffer->IsStreamerInfoItem(arg->fPathName.Data()) ?
"BVersion" :
"MVersion";
1277 arg->AddNoCacheHeader();
1281 arg->AddHeader(
"Access-Control-Allow-Origin",
GetCors());
1284 arg->AddHeader(
"Access-Control-Expose-Headers",
"Content-Range, Content-Length, Date");
1285 arg->AddHeader(
"Access-Control-Allow-Methods",
"GET, HEAD, OPTIONS");
1296 return fSniffer->RegisterObject(subfolder, obj);
1306 return fSniffer->UnregisterObject(obj);
1316 std::lock_guard<std::mutex> grd(
fWSMutex);
1325 std::lock_guard<std::mutex> grd(
fWSMutex);
1338 std::lock_guard<std::mutex> grd(
fWSMutex);
1340 if (strcmp(
name, ws->GetName()) == 0)
1357 auto wsptr =
FindWS(arg->GetPathName());
1359 auto handler = wsptr.get();
1361 if (!handler && !external_thrd)
1364 if (external_thrd && (!handler || !handler->AllowMTProcess())) {
1366 std::unique_lock<std::mutex> lk(
fMutex);
1370 arg->fCond.wait(lk);
1382 if (arg->fFileName ==
"root.websocket") {
1384 process = handler->HandleWS(arg);
1385 }
else if (arg->fFileName ==
"root.longpoll") {
1387 if (arg->fQuery.BeginsWith(
"raw_connect") || arg->fQuery.BeginsWith(
"txt_connect")) {
1390 arg->SetMethod(
"WS_CONNECT");
1392 bool israw = arg->fQuery.BeginsWith(
"raw_connect");
1397 if (handler->HandleWS(arg)) {
1398 arg->SetMethod(
"WS_READY");
1400 if (handler->HandleWS(arg))
1401 arg->SetTextContent(std::string(israw ?
"txt:" :
"") + std::to_string(arg->GetWSId()));
1403 arg->TakeWSEngine();
1406 process = arg->IsText();
1413 arg->SetWSId(std::stoul(connid));
1415 arg->SetMethod(
"WS_CLOSE");
1416 arg->SetTextContent(
"OK");
1418 arg->SetMethod(
"WS_DATA");
1421 process = handler->HandleWS(arg);
1480 return fSniffer->RegisterCommand(cmdname, method, icon);
1488 return SetItemField(foldername,
"_hidden", hide ?
"true" : (
const char *)0);
1507 return fSniffer->CreateItem(fullname, title);
1531 static const struct {
1532 const char *extension;
1534 const char *mime_type;
1535 } builtin_mime_types[] = {{
".xml", 4,
"text/xml"},
1536 {
".json", 5,
"application/json"},
1537 {
".bin", 4,
"application/x-binary"},
1538 {
".gif", 4,
"image/gif"},
1539 {
".jpg", 4,
"image/jpeg"},
1540 {
".png", 4,
"image/png"},
1541 {
".html", 5,
"text/html"},
1542 {
".htm", 4,
"text/html"},
1543 {
".shtm", 5,
"text/html"},
1544 {
".shtml", 6,
"text/html"},
1545 {
".css", 4,
"text/css"},
1546 {
".js", 3,
"application/x-javascript"},
1547 {
".mjs", 4,
"text/javascript"},
1548 {
".ico", 4,
"image/x-icon"},
1549 {
".jpeg", 5,
"image/jpeg"},
1550 {
".svg", 4,
"image/svg+xml"},
1551 {
".txt", 4,
"text/plain"},
1552 {
".torrent", 8,
"application/x-bittorrent"},
1553 {
".wav", 4,
"audio/x-wav"},
1554 {
".mp3", 4,
"audio/x-mp3"},
1555 {
".mid", 4,
"audio/mid"},
1556 {
".m3u", 4,
"audio/x-mpegurl"},
1557 {
".ogg", 4,
"application/ogg"},
1558 {
".ram", 4,
"audio/x-pn-realaudio"},
1559 {
".xslt", 5,
"application/xml"},
1560 {
".xsl", 4,
"application/xml"},
1561 {
".ra", 3,
"audio/x-pn-realaudio"},
1562 {
".doc", 4,
"application/msword"},
1563 {
".exe", 4,
"application/octet-stream"},
1564 {
".zip", 4,
"application/x-zip-compressed"},
1565 {
".xls", 4,
"application/excel"},
1566 {
".tgz", 4,
"application/x-tar-gz"},
1567 {
".tar", 4,
"application/x-tar"},
1568 {
".gz", 3,
"application/x-gunzip"},
1569 {
".arj", 4,
"application/x-arj-compressed"},
1570 {
".rar", 4,
"application/x-arj-compressed"},
1571 {
".rtf", 4,
"application/rtf"},
1572 {
".pdf", 4,
"application/pdf"},
1573 {
".swf", 4,
"application/x-shockwave-flash"},
1574 {
".mpg", 4,
"video/mpeg"},
1575 {
".webm", 5,
"video/webm"},
1576 {
".mpeg", 5,
"video/mpeg"},
1577 {
".mov", 4,
"video/quicktime"},
1578 {
".mp4", 4,
"video/mp4"},
1579 {
".m4v", 4,
"video/x-m4v"},
1580 {
".asf", 4,
"video/x-ms-asf"},
1581 {
".avi", 4,
"video/x-msvideo"},
1582 {
".bmp", 4,
"image/bmp"},
1583 {
".ttf", 4,
"application/x-font-ttf"},
1584 {
".woff", 5,
"font/woff"},
1585 {
".woff2", 6,
"font/woff2"},
1588 int path_len = strlen(path);
1590 for (
int i = 0; builtin_mime_types[i].extension != NULL; i++) {
1591 if (path_len <= builtin_mime_types[i].ext_len)
1593 const char *ext = path + (path_len - builtin_mime_types[i].ext_len);
1594 if (strcmp(ext, builtin_mime_types[i].extension) == 0) {
1595 return builtin_mime_types[i].mime_type;
1599 return "text/plain";
1611 std::ifstream is(
filename, std::ios::in | std::ios::binary);
1615 is.seekg(0, is.end);
1617 is.seekg(0, is.beg);
1619 char *buf = (
char *)malloc(
len);
1635 std::ifstream is(
filename, std::ios::in | std::ios::binary);
1638 is.seekg(0, std::ios::end);
1639 res.resize(is.tellg());
1640 is.seekg(0, std::ios::beg);
1641 is.read((
char *)res.data(), res.length());
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.
winID h TVirtualViewer3D TVirtualGLPainter p
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
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
R__EXTERN TSystem * gSystem
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.
static TClass * LoadClass(const char *requestedname, Bool_t silent)
Helper function used by TClass::GetClass().
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.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
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.
void AppendLocation(const char *prefix, const char *path)
Append a directory to the files location of prefix, creating the location if there is none.
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.
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
void SetCors(const std::string &domain="*")
Enable CORS header to ProcessRequests() responses Specified location (typically "*") add as "Access-C...
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.
std::map< std::string, std::vector< std::string > > fLocations
! local directories served, per prefix
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
TRootSniffer * GetSniffer() const
returns pointer on objects sniffer
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.
void Add(TObject *obj) override
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
The TNamed class is the base class for all named ROOT classes.
TObject * At(Int_t idx) const override
Int_t GetLast() const override
Return index of last object in array.
Mother of all ROOT objects.
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.
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 SetReadOnly(Bool_t on=kTRUE)
When readonly on (default), sniffer is not allowed to change ROOT structures For instance,...
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
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
virtual const char * Getenv(const char *env)
Get environment variable.
static Long_t SelfId()
Static method returning the id for the current thread.
Handles synchronous and a-synchronous timer events.
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.