14 #include "RConfigure.h"
39 class THttpTimer :
public TTimer {
45 TTimer(milliSec, mode), fServer(serv)
58 if (fServer) fServer->ProcessRequests();
111 TNamed("http", "ROOT http server"),
136 fLocations.SetOwner(
kTRUE);
140 #ifdef COMPILED_WITH_DABC
147 if (jsrootsys != 0) fJSROOTSYS = jsrootsys;
149 if (fJSROOTSYS.Length() == 0) {
153 TString jsdir(
"$(ROOTSYS)/etc/http");
156 Warning(
"THttpServer",
"problems resolving '%s', use JSROOTSYS to specify $ROOTSYS/etc/http location", jsdir.
Data());
163 AddLocation(
"currentdir/",
".");
164 AddLocation(
"jsrootsys/", fJSROOTSYS);
168 AddLocation(
"rootsys/", rootsys);
178 fDefaultPage = fJSROOTSYS +
"/files/online.htm";
179 fDrawPage = fJSROOTSYS +
"/files/draw.htm";
186 if (strchr(engine,
';') == 0) {
187 CreateEngine(engine);
193 if ((strcmp(opt,
"readonly") == 0) || (strcmp(opt,
"ro") == 0)) {
194 GetSniffer()->SetReadOnly(
kTRUE);
195 }
else if ((strcmp(opt,
"readwrite") == 0) || (strcmp(opt,
"rw") == 0)) {
196 GetSniffer()->SetReadOnly(
kFALSE);
254 if ((prefix==0) || (*prefix==0))
return;
275 fJSROOT = location ? location :
"";
286 if ((filename!=0) && (*filename!=0))
303 if ((filename!=0) && (*filename!=0))
324 if (engine == 0)
return kFALSE;
326 const char *arg = strchr(engine,
':');
327 if (arg == 0)
return kFALSE;
330 if (arg != engine) clname.
Append(engine, arg - engine);
332 if ((clname.
Length() == 0) || (clname ==
"http") || (clname ==
"civetweb"))
333 clname =
"TCivetweb";
334 else if (clname ==
"fastcgi")
336 else if (clname ==
"dabc")
337 clname =
"TDabcEngine";
341 if (engine_class == 0)
return kFALSE;
344 if (eng == 0)
return kFALSE;
348 if (!eng->
Create(arg + 1)) {
375 fTimer =
new THttpTimer(milliSec, mode,
this);
386 if ((fname == 0) || (*fname == 0))
return kFALSE;
390 while (*fname != 0) {
393 const char *
next = strpbrk(fname,
"/\\");
394 if (next == 0)
return kTRUE;
397 if ((next == fname + 2) && (*fname ==
'.') && (*(fname + 1) ==
'.')) {
400 if (level < 0)
return kFALSE;
405 if ((next == fname + 1) && (*fname ==
'.')) {
432 if ((uri == 0) || (strlen(uri) == 0))
return kFALSE;
438 while ((obj=
iter()) != 0) {
440 if (pos ==
kNPOS)
continue;
468 std::unique_lock<std::mutex> lk(
fMutex);
487 Error(
"ProcessRequests",
"Should be called only from main ROOT thread");
491 std::unique_lock<std::mutex> lk(
fMutex, std::defer_lock);
513 arg->
fCond.notify_one();
552 const char *hjsontag =
"\"$$$h.json$$$\"";
564 arg->
AddHeader(
"Cache-Control",
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
583 const char *rootjsontag =
"\"$$$root.json$$$\"";
584 const char *hjsontag =
"\"$$$h.json$$$\"";
613 arg->
AddHeader(
"Cache-Control",
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
636 if ((filename ==
"h.xml") || (filename ==
"get.xml")) {
640 arg->
fContent.
Form(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
658 if (filename ==
"h.json") {
667 if (bindata != 0) arg->
SetBinData(bindata, bindatalen);
676 if (arg->
Is404())
return;
680 if (filename ==
"root.bin") {
688 arg->
AddHeader(
"Cache-Control",
"private, no-cache, no-store, must-revalidate, max-age=0, proxy-revalidate, s-maxage=0");
759 return SetItemField(foldername,
"_hidden", hide ?
"true" : (
const char *) 0);
799 static const struct {
804 {
".xml", 4,
"text/xml"},
805 {
".json", 5,
"application/json"},
806 {
".bin", 4,
"application/x-binary"},
807 {
".gif", 4,
"image/gif"},
808 {
".jpg", 4,
"image/jpeg"},
809 {
".png", 4,
"image/png"},
810 {
".html", 5,
"text/html"},
811 {
".htm", 4,
"text/html"},
812 {
".shtm", 5,
"text/html"},
813 {
".shtml", 6,
"text/html"},
814 {
".css", 4,
"text/css"},
815 {
".js", 3,
"application/x-javascript"},
816 {
".ico", 4,
"image/x-icon"},
817 {
".jpeg", 5,
"image/jpeg"},
818 {
".svg", 4,
"image/svg+xml"},
819 {
".txt", 4,
"text/plain"},
820 {
".torrent", 8,
"application/x-bittorrent"},
821 {
".wav", 4,
"audio/x-wav"},
822 {
".mp3", 4,
"audio/x-mp3"},
823 {
".mid", 4,
"audio/mid"},
824 {
".m3u", 4,
"audio/x-mpegurl"},
825 {
".ogg", 4,
"application/ogg"},
826 {
".ram", 4,
"audio/x-pn-realaudio"},
827 {
".xslt", 5,
"application/xml"},
828 {
".xsl", 4,
"application/xml"},
829 {
".ra", 3,
"audio/x-pn-realaudio"},
830 {
".doc", 4,
"application/msword"},
831 {
".exe", 4,
"application/octet-stream"},
832 {
".zip", 4,
"application/x-zip-compressed"},
833 {
".xls", 4,
"application/excel"},
834 {
".tgz", 4,
"application/x-tar-gz"},
835 {
".tar", 4,
"application/x-tar"},
836 {
".gz", 3,
"application/x-gunzip"},
837 {
".arj", 4,
"application/x-arj-compressed"},
838 {
".rar", 4,
"application/x-arj-compressed"},
839 {
".rtf", 4,
"application/rtf"},
840 {
".pdf", 4,
"application/pdf"},
841 {
".swf", 4,
"application/x-shockwave-flash"},
842 {
".mpg", 4,
"video/mpeg"},
843 {
".webm", 5,
"video/webm"},
844 {
".mpeg", 5,
"video/mpeg"},
845 {
".mov", 4,
"video/quicktime"},
846 {
".mp4", 4,
"video/mp4"},
847 {
".m4v", 4,
"video/x-m4v"},
848 {
".asf", 4,
"video/x-ms-asf"},
849 {
".avi", 4,
"video/x-msvideo"},
850 {
".bmp", 4,
"image/bmp"},
851 {
".ttf", 4,
"application/x-font-ttf"},
855 int path_len = strlen(path);
875 std::ifstream is(filename);
882 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.
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.
ClassImp(TSeqCollection) Int_t TSeqCollection TIter next(this)
Return index of object in collection.
static const struct @203 builtin_mime_types[]
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)
const char * GetItemField(const char *fullname, const char *name)
static const char * filename()
TString fQuery
authenticated user name (if any)
TString fTopName
location of local JSROOT files
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)
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 * 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.
std::map< std::string, std::string >::const_iterator iter
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)
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.
ClassImp(THttpServer) THttpServer
constructor
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
TPaveLabel title(3, 27.1, 15, 28.7,"ROOT Environment and Tools")
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.
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
length of binary data
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
TString fDefaultPageCont
file name for default page name
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
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="")
Change (i.e. set) the title of the TNamed.
Vc_ALWAYS_INLINE_L T *Vc_ALWAYS_INLINE_R malloc(size_t n)
Allocates memory on the Heap with alignment and padding suitable for vectorized access.
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...
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)