15 #include "RConfigure.h"
40 class THttpTimer :
public TTimer {
46 TTimer(milliSec, mode), fServer(serv)
59 if (fServer) fServer->ProcessRequests();
112 TNamed("http", "ROOT http server"),
137 fLocations.SetOwner(
kTRUE);
141 #ifdef COMPILED_WITH_DABC
148 if (jsrootsys != 0) fJSROOTSYS = jsrootsys;
150 if (fJSROOTSYS.Length() == 0) {
153 Warning(
"THttpServer",
"problems resolving '%s', use JSROOTSYS to specify $ROOTSYS/etc/http location", jsdir.
Data());
160 AddLocation(
"currentdir/",
".");
161 AddLocation(
"jsrootsys/", fJSROOTSYS);
164 fDefaultPage = fJSROOTSYS +
"/files/online.htm";
165 fDrawPage = fJSROOTSYS +
"/files/draw.htm";
172 if (strchr(engine,
';') == 0) {
173 CreateEngine(engine);
179 if ((strcmp(opt,
"readonly") == 0) || (strcmp(opt,
"ro") == 0)) {
180 GetSniffer()->SetReadOnly(
kTRUE);
181 }
else if ((strcmp(opt,
"readwrite") == 0) || (strcmp(opt,
"rw") == 0)) {
182 GetSniffer()->SetReadOnly(
kFALSE);
240 if ((prefix==0) || (*prefix==0))
return;
261 fJSROOT = location ? location :
"";
272 if ((filename!=0) && (*filename!=0))
289 if ((filename!=0) && (*filename!=0))
310 if (engine == 0)
return kFALSE;
312 const char *arg = strchr(engine,
':');
313 if (arg == 0)
return kFALSE;
316 if (arg != engine) clname.
Append(engine, arg - engine);
318 if ((clname.
Length() == 0) || (clname ==
"http") || (clname ==
"civetweb"))
319 clname =
"TCivetweb";
320 else if (clname ==
"fastcgi")
322 else if (clname ==
"dabc")
323 clname =
"TDabcEngine";
327 if (engine_class == 0)
return kFALSE;
330 if (eng == 0)
return kFALSE;
334 if (!eng->
Create(arg + 1)) {
361 fTimer =
new THttpTimer(milliSec, mode,
this);
372 if ((fname == 0) || (*fname == 0))
return kFALSE;
376 while (*fname != 0) {
379 const char *next = strpbrk(fname,
"/\\");
380 if (next == 0)
return kTRUE;
383 if ((next == fname + 2) && (*fname ==
'.') && (*(fname + 1) ==
'.')) {
386 if (level < 0)
return kFALSE;
391 if ((next == fname + 1) && (*fname ==
'.')) {
418 if ((uri == 0) || (strlen(uri) == 0))
return kFALSE;
424 while ((obj=iter()) != 0) {
426 if (pos ==
kNPOS)
continue;
454 std::unique_lock<std::mutex> lk(
fMutex);
473 Error(
"ProcessRequests",
"Should be called only from main ROOT thread");
477 std::unique_lock<std::mutex> lk(
fMutex, std::defer_lock);
499 arg->
fCond.notify_one();
538 const char *hjsontag =
"\"$$$h.json$$$\"";
550 arg->
AddHeader(
"Cache-Control",
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
569 const char *rootjsontag =
"\"$$$root.json$$$\"";
570 const char *hjsontag =
"\"$$$h.json$$$\"";
599 arg->
AddHeader(
"Cache-Control",
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
622 if ((filename ==
"h.xml") || (filename ==
"get.xml")) {
626 arg->
fContent.
Form(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
644 if (filename ==
"h.json") {
652 if (filename ==
"root.websocket") {
661 if (strcmp(arg->
GetMethod(),
"WS_CONNECT")==0) {
668 if (strcmp(arg->
GetMethod(),
"WS_READY")==0) {
671 if (
gDebug>0)
Info(
"ProcessRequest",
"Set WebSocket handle %p", wshandle);
677 if (strcmp(arg->
GetMethod(),
"WS_DATA")==0) {
684 if (strcmp(arg->
GetMethod(),
"WS_CLOSE")==0) {
690 if (
gDebug>0)
Info(
"ProcessRequest",
"Clear WebSocket handle");
704 if (bindata != 0) arg->
SetBinData(bindata, bindatalen);
713 if (arg->
Is404())
return;
717 if (filename ==
"root.bin") {
725 arg->
AddHeader(
"Cache-Control",
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
796 return SetItemField(foldername,
"_hidden", hide ?
"true" : (
const char *) 0);
836 static const struct {
841 {
".xml", 4,
"text/xml"},
842 {
".json", 5,
"application/json"},
843 {
".bin", 4,
"application/x-binary"},
844 {
".gif", 4,
"image/gif"},
845 {
".jpg", 4,
"image/jpeg"},
846 {
".png", 4,
"image/png"},
847 {
".html", 5,
"text/html"},
848 {
".htm", 4,
"text/html"},
849 {
".shtm", 5,
"text/html"},
850 {
".shtml", 6,
"text/html"},
851 {
".css", 4,
"text/css"},
852 {
".js", 3,
"application/x-javascript"},
853 {
".ico", 4,
"image/x-icon"},
854 {
".jpeg", 5,
"image/jpeg"},
855 {
".svg", 4,
"image/svg+xml"},
856 {
".txt", 4,
"text/plain"},
857 {
".torrent", 8,
"application/x-bittorrent"},
858 {
".wav", 4,
"audio/x-wav"},
859 {
".mp3", 4,
"audio/x-mp3"},
860 {
".mid", 4,
"audio/mid"},
861 {
".m3u", 4,
"audio/x-mpegurl"},
862 {
".ogg", 4,
"application/ogg"},
863 {
".ram", 4,
"audio/x-pn-realaudio"},
864 {
".xslt", 5,
"application/xml"},
865 {
".xsl", 4,
"application/xml"},
866 {
".ra", 3,
"audio/x-pn-realaudio"},
867 {
".doc", 4,
"application/msword"},
868 {
".exe", 4,
"application/octet-stream"},
869 {
".zip", 4,
"application/x-zip-compressed"},
870 {
".xls", 4,
"application/excel"},
871 {
".tgz", 4,
"application/x-tar-gz"},
872 {
".tar", 4,
"application/x-tar"},
873 {
".gz", 3,
"application/x-gunzip"},
874 {
".arj", 4,
"application/x-arj-compressed"},
875 {
".rar", 4,
"application/x-arj-compressed"},
876 {
".rtf", 4,
"application/rtf"},
877 {
".pdf", 4,
"application/pdf"},
878 {
".swf", 4,
"application/x-shockwave-flash"},
879 {
".mpg", 4,
"video/mpeg"},
880 {
".webm", 5,
"video/webm"},
881 {
".mpeg", 5,
"video/mpeg"},
882 {
".mov", 4,
"video/quicktime"},
883 {
".mp4", 4,
"video/mp4"},
884 {
".m4v", 4,
"video/x-m4v"},
885 {
".asf", 4,
"video/x-ms-asf"},
886 {
".avi", 4,
"video/x-msvideo"},
887 {
".bmp", 4,
"image/bmp"},
888 {
".ttf", 4,
"application/x-font-ttf"},
892 int path_len = strlen(path);
912 std::ifstream is(filename);
919 char *buf = (
char *)
malloc(len);
void SetZipping(Int_t kind)
Bool_t RegisterObject(const char *subfolder, TObject *obj)
Register object in subfolder structure subfolder parameter can have many levels like: ...
virtual void Delete(Option_t *option="")
Remove all objects from the list AND delete all heap based objects.
virtual TObject * GetPrimitive(const char *name) const
Get primitive.
Bool_t Produce(const char *path, const char *file, const char *options, void *&ptr, Long_t &length, TString &str)
Method produce different kind of data out of object Parameter 'path' specifies object or object membe...
Bool_t IsStreamerInfoItem(const char *itemname)
Return true if it is streamer info item name.
virtual void Process()
Method regularly called in main ROOT context.
Int_t GetLast() const
Return index of last object in array.
Storage of hierarchy scan in TRootSniffer in JSON format.
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
const char * GetItemField(const char *fullname, const char *name)
virtual void ProcessData(THttpCallArg *arg)
process data received from the client
TString fQuery
authenticated user name (if any)
TString fTopName
location of local JSROOT files
static const TString & GetRootSys()
Get the rootsys directory in the installation. Static utility function.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
void Restrict(const char *path, const char *options)
Restrict access to the specified location.
Bool_t UnregisterObject(TObject *obj)
unregister (remove) object from folders structures folder itself will remain even when it will be emp...
void SetServer(THttpServer *serv)
virtual void AssignCanvas(TCanvas *canv)
assign canvas to the web socket connects with CanvasModified signal
void SetContentType(const char *typ)
Bool_t CreateItem(const char *fullname, const char *title)
create item element
void ProcessRequests()
Process submitted requests, must be called from main thread.
Bool_t CreateItem(const char *fullname, const char *title)
const char * GetMethod() const
const char * Data() const
TRootSniffer * fSniffer
timer used to access main thread
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString...
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
set field for specified item
Bool_t IsReadOnly() const
The TNamed class is the base class for all named ROOT classes.
void * New(ENewType defConstructor=kClassNew, Bool_t quiet=kFALSE) const
Return a pointer to a newly allocated object of this class.
void Clear()
Clear string without changing its capacity.
THttpTimer * fTimer
engines which runs http server
virtual const char * Getenv(const char *env)
Get environment variable.
TString fPathName
request method like GET or POST
TString & Append(const char *cs)
std::vector< std::vector< double > > Data
static Long_t SelfId()
Static method returning the id for the current thread.
void SetTimer(Long_t milliSec=100, Bool_t mode=kTRUE)
create timer which will invoke ProcessRequests() function periodically Timer is required to perform a...
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
TList fLocations
location of external JSROOT files
TString fJSROOTSYS
id of the main ROOT process
Storage of hierarchy scan in TRootSniffer in XML format.
Bool_t Register(const char *subfolder, TObject *obj)
Register object in subfolder.
void SetReadOnly(Bool_t readonly)
Set read-only mode for the server (default on) In read-only server is not allowed to change any ROOT ...
void SetBinData(void *data, Long_t length)
set binary data, which will be returned as reply body
Bool_t CreateEngine(const char *engine)
factory method to create different http engines At the moment two engine kinds are supported: civetwe...
Bool_t EndsWith(const char *pat, ECaseCompare cmp=kExact) const
Return true if string ends with the specified string.
R__EXTERN TSystem * gSystem
void Form(const char *fmt,...)
Formats a string using a printf style format descriptor.
virtual ~THttpServer()
destructor delete all http engines and sniffer
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon)
Register command which can be executed from web interface.
char * Form(const char *fmt,...)
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
TString fDefaultPage
list of local directories, which could be accessed via server
Bool_t IsReadOnly() const
returns read-only mode
virtual Bool_t Create(const char *)
Method to create all components of engine.
Handles synchronous and a-synchronous timer events.
The ROOT global object gROOT contains a list of all defined classes.
void Warning(const char *location, const char *msgfmt,...)
void SetSniffer(TRootSniffer *sniff)
Set TRootSniffer to the server Server takes ownership over sniffer.
static struct @163 builtin_mime_types[]
void ScanHierarchy(const char *topname, const char *path, TRootSnifferStore *store, Bool_t only_fields=kFALSE)
Method scans normal objects, registered in ROOT.
TObjArray * Tokenize(const TString &delim) const
This function is used to isolate sequential tokens in a TString.
Bool_t ExecuteHttp(THttpCallArg *arg)
Execute HTTP request.
TString fDrawPage
content of the file content
TString & Remove(Ssiz_t pos)
std::condition_variable fCond
web-socket handle, derived from TNamed class
void AddLocation(const char *prefix, const char *path)
add files location, which could be used in the server one could map some system folder to the server ...
virtual Int_t GetSize() const
Bool_t Hide(const char *fullname, Bool_t hide=kTRUE)
hides folder or element from web gui
std::mutex fMutex
content of draw page
virtual const char * GetName() const
Returns name of object.
virtual void ProcessRequest(THttpCallArg *arg)
submitted arguments
TString fDrawPageCont
file name for drawing of single element
static const TString & GetEtcDir()
Get the sysconfig directory in the installation. Static utility function.
TString fDefaultPageCont
file name for default page name
TNamed * TakeWSHandle()
takeout websocket handle with HTTP call can be done only once
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon=0)
Register command which can be executed from web interface.
Mother of all ROOT objects.
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
Bool_t Unregister(TObject *obj)
Unregister object.
TString fContent
response header like ContentEncoding, Cache-Control and so on
virtual TObject * First() const
Return the first object in the list. Returns 0 when list is empty.
Long_t fMainThrdId
sniffer provides access to ROOT objects hierarchy
void AddHeader(const char *name, const char *value)
Set name: value pair to reply header Content-Type field handled separately - one should use SetConten...
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
void SetReadOnly(Bool_t on=kTRUE)
virtual void Add(TObject *obj)
void SetFile(const char *filename=0)
Bool_t SetIcon(const char *fullname, const char *iconname)
set name of icon, used in browser together with the item
TList fCallArgs
mutex to protect list with arguments
virtual void ClearHandle()=0
static Bool_t VerifyFilePath(const char *fname)
Checked that filename does not contains relative path below current directory Used to prevent access ...
virtual Bool_t ExpandPathName(TString &path)
Expand a pathname getting rid of special shell characters like ~.
TString fJSROOT
name of top folder, default - "ROOT"
TObject * At(Int_t idx) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
void SetCurrentCallArg(THttpCallArg *arg)
set current http arguments, which then used in different process methods For instance, if user authorized with some user name, depending from restrictions some objects will be invisible or user get full access to the element
virtual const char * GetTitle() const
Returns title of object.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
void SetDrawPage(const char *filename)
Set file name of HTML page, delivered by the server when objects drawing page is requested from the b...
TString fFileName
item path
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
const char * GetItemField(TFolder *parent, TObject *item, const char *name)
return field for specified item
void Restrict(const char *path, const char *options)
Restrict access to specified object.
void Resize(Ssiz_t n)
Resize the string. Truncate or add blanks as necessary.
ULong_t GetStreamerInfoHash()
Returns hash value for streamer infos At the moment - just number of items in streamer infos list...
void SetDefaultPage(const char *filename)
Set file name of HTML page, delivered by the server when http address is opened in the browser...
TObject * FindTObjectInHierarchy(const char *path)
Search element in hierarchy, derived from TObject.
virtual void RemoveFirst()
void SetJSROOT(const char *location)
Set location of JSROOT to use with the server One could specify address like: https://root.cern.ch/js/3.3/ http://web-docs.gsi.de/~linev/js/3.3/ This allows to get new JSROOT features with old server, reduce load on THttpServer instance, also startup time can be improved When empty string specified (default), local copy of JSROOT is used (distributed with ROOT)