Logo ROOT   6.07/09
Reference Guide
THttpServer.h
Go to the documentation of this file.
1 // $Id$
2 // Author: Sergey Linev 21/12/2013
3 
4 #ifndef ROOT_THttpServer
5 #define ROOT_THttpServer
6 
7 #ifndef ROOT_TObject
8 #include "TObject.h"
9 #endif
10 
11 #ifndef ROOT_TList
12 #include "TList.h"
13 #endif
14 
15 #ifndef ROOT_TNamed
16 #include "TNamed.h"
17 #endif
18 
19 #ifndef ROOT_THttpCallArg
20 #include "THttpCallArg.h"
21 #endif
22 
23 #include <mutex>
24 
25 class THttpEngine;
26 class THttpTimer;
27 class TRootSniffer;
28 
29 
30 class THttpServer : public TNamed {
31 
32 protected:
33 
34  TList fEngines; //! engines which runs http server
35  THttpTimer *fTimer; //! timer used to access main thread
36  TRootSniffer *fSniffer; //! sniffer provides access to ROOT objects hierarchy
37 
38  Long_t fMainThrdId; //! id of the main ROOT process
39 
40  TString fJSROOTSYS; //! location of local JSROOT files
41  TString fTopName; //! name of top folder, default - "ROOT"
42  TString fJSROOT; //! location of external JSROOT files
43  TList fLocations; //! list of local directories, which could be accessed via server
44 
45  TString fDefaultPage; //! file name for default page name
46  TString fDefaultPageCont; //! content of the file content
47  TString fDrawPage; //! file name for drawing of single element
48  TString fDrawPageCont; //! content of draw page
49 
50  std::mutex fMutex; //! mutex to protect list with arguments
51  TList fCallArgs; //! submitted arguments
52 
53  // Here any request can be processed
54  virtual void ProcessRequest(THttpCallArg *arg);
55 
56  static Bool_t VerifyFilePath(const char *fname);
57 
58 public:
59 
60  THttpServer(const char *engine = "civetweb:8080");
61  virtual ~THttpServer();
62 
63  Bool_t CreateEngine(const char *engine);
64 
65  Bool_t IsAnyEngine() const { return fEngines.GetSize() > 0; }
66 
68  {
69  // returns pointer on objects sniffer
70 
71  return fSniffer;
72  }
73 
74  void SetSniffer(TRootSniffer *sniff);
75 
76  Bool_t IsReadOnly() const;
77 
78  void SetReadOnly(Bool_t readonly);
79 
80  void SetTopName(const char *top)
81  {
82  // set name of top item in objects hierarchy
83  fTopName = top;
84  }
85 
86  const char *GetTopName() const
87  {
88  // returns name of top item in objects hierarchy
89  return fTopName.Data();
90  }
91 
92  void SetJSROOT(const char *location);
93 
94  void AddLocation(const char *prefix, const char *path);
95 
96  void SetDefaultPage(const char *filename);
97 
98  void SetDrawPage(const char *filename);
99 
100  void SetTimer(Long_t milliSec = 100, Bool_t mode = kTRUE);
101 
102  /** Check if file is requested, thread safe */
103  Bool_t IsFileRequested(const char *uri, TString &res) const;
104 
105  /** Execute HTTP request */
107 
108  /** Process submitted requests, must be called from main thread */
109  void ProcessRequests();
110 
111  /** Register object in subfolder */
112  Bool_t Register(const char *subfolder, TObject *obj);
113 
114  /** Unregister object */
115  Bool_t Unregister(TObject *obj);
116 
117  /** Restrict access to specified object */
118  void Restrict(const char *path, const char* options);
119 
120  Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon = 0);
121 
122  Bool_t Hide(const char *fullname, Bool_t hide = kTRUE);
123 
124  Bool_t SetIcon(const char *fullname, const char *iconname);
125 
126  Bool_t CreateItem(const char *fullname, const char *title);
127 
128  Bool_t SetItemField(const char *fullname, const char *name, const char *value);
129 
130  const char *GetItemField(const char *fullname, const char *name);
131 
132  /** Guess mime type base on file extension */
133  static const char *GetMimeType(const char *path);
134 
135  /** Reads content of file from the disk */
136  static char *ReadFileContent(const char *filename, Int_t &len);
137 
138  ClassDef(THttpServer, 0) // HTTP server for ROOT analysis
139 };
140 
141 #endif
TRootSniffer * GetSniffer() const
Definition: THttpServer.h:67
const char * GetItemField(const char *fullname, const char *name)
Basic string class.
Definition: TString.h:137
TString fTopName
location of local JSROOT files
Definition: THttpServer.h:41
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TList fEngines
Definition: THttpServer.h:34
void ProcessRequests()
Process submitted requests, must be called from main thread.
Bool_t CreateItem(const char *fullname, const char *title)
const char * Data() const
Definition: TString.h:349
TRootSniffer * fSniffer
timer used to access main thread
Definition: THttpServer.h:36
THttpServer(const char *engine="civetweb:8080")
constructor
#define ClassDef(name, id)
Definition: Rtypes.h:254
The TNamed class is the base class for all named ROOT classes.
Definition: TNamed.h:33
THttpTimer * fTimer
engines which runs http server
Definition: THttpServer.h:35
void SetTimer(Long_t milliSec=100, Bool_t mode=kTRUE)
create timer which will invoke ProcessRequests() function periodically Timer is required to perform a...
TList fLocations
location of external JSROOT files
Definition: THttpServer.h:43
TString fJSROOTSYS
id of the main ROOT process
Definition: THttpServer.h:40
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 ...
A doubly linked list.
Definition: TList.h:47
Bool_t CreateEngine(const char *engine)
factory method to create different http engines At the moment two engine kinds are supported: civetwe...
virtual ~THttpServer()
destructor delete all http engines and sniffer
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
Definition: THttpServer.h:45
Bool_t IsReadOnly() const
returns read-only mode
void SetSniffer(TRootSniffer *sniff)
Set TRootSniffer to the server Server takes ownership over sniffer.
Bool_t ExecuteHttp(THttpCallArg *arg)
Execute HTTP request.
TString fDrawPage
content of the file content
Definition: THttpServer.h:47
long Long_t
Definition: RtypesCore.h:50
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
Definition: TCollection.h:95
Bool_t Hide(const char *fullname, Bool_t hide=kTRUE)
hides folder or element from web gui
std::mutex fMutex
content of draw page
Definition: THttpServer.h:50
virtual void ProcessRequest(THttpCallArg *arg)
submitted arguments
TString fDrawPageCont
file name for drawing of single element
Definition: THttpServer.h:48
TString fDefaultPageCont
file name for default page name
Definition: THttpServer.h:46
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.
Definition: TObject.h:44
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
Bool_t Unregister(TObject *obj)
Unregister object.
Long_t fMainThrdId
sniffer provides access to ROOT objects hierarchy
Definition: THttpServer.h:38
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
const char * GetTopName() const
Definition: THttpServer.h:86
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
Definition: THttpServer.h:51
static Bool_t VerifyFilePath(const char *fname)
Checked that filename does not contains relative path below current directory Used to prevent access ...
TString fJSROOT
name of top folder, default - "ROOT"
Definition: THttpServer.h:42
const Bool_t kTRUE
Definition: Rtypes.h:91
void SetDrawPage(const char *filename)
Set file name of HTML page, delivered by the server when objects drawing page is requested from the b...
Bool_t SetItemField(const char *fullname, const char *name, const char *value)
char name[80]
Definition: TGX11.cxx:109
void Restrict(const char *path, const char *options)
Restrict access to specified object.
Bool_t IsAnyEngine() const
Definition: THttpServer.h:65
void SetDefaultPage(const char *filename)
Set file name of HTML page, delivered by the server when http address is opened in the browser...
void SetTopName(const char *top)
Definition: THttpServer.h:80
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)