ROOT  6.06/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_TMutex
16 #include "TMutex.h"
17 #endif
18 
19 #ifndef ROOT_THttpCallArg
20 #include "THttpCallArg.h"
21 #endif
22 
23 
24 class THttpEngine;
25 class THttpTimer;
26 class TRootSniffer;
27 
28 
29 class THttpServer : public TNamed {
30 
31 protected:
32 
33  TList fEngines; //! engines which runs http server
34  THttpTimer *fTimer; //! timer used to access main thread
35  TRootSniffer *fSniffer; //! sniffer provides access to ROOT objects hierarchy
36 
37  Long_t fMainThrdId; //! id of the main ROOT process
38 
39  TString fJSROOTSYS; //! location of local JSROOT files
40  TString fTopName; //! name of top folder, default - "ROOT"
41  TString fJSROOT; //! location of external JSROOT files
42  TList fLocations; //! list of local directories, which could be accessed via server
43 
44  TString fDefaultPage; //! file name for default page name
45  TString fDefaultPageCont; //! content of the file content
46  TString fDrawPage; //! file name for drawing of single element
47  TString fDrawPageCont; //! content of draw page
48 
49  TMutex fMutex; //! mutex to protect list with arguments
50  TList fCallArgs; //! submitted arguments
51 
52  // Here any request can be processed
53  virtual void ProcessRequest(THttpCallArg *arg);
54 
55  static Bool_t VerifyFilePath(const char *fname);
56 
57 public:
58 
59  THttpServer(const char *engine = "civetweb:8080");
60  virtual ~THttpServer();
61 
62  Bool_t CreateEngine(const char *engine);
63 
64  Bool_t IsAnyEngine() const { return fEngines.GetSize() > 0; }
65 
67  {
68  // returns pointer on objects sniffer
69 
70  return fSniffer;
71  }
72 
73  void SetSniffer(TRootSniffer *sniff);
74 
75  Bool_t IsReadOnly() const;
76 
77  void SetReadOnly(Bool_t readonly);
78 
79  void SetTopName(const char *top)
80  {
81  // set name of top item in objects hierarchy
82  fTopName = top;
83  }
84 
85  const char *GetTopName() const
86  {
87  // returns name of top item in objects hierarchy
88  return fTopName.Data();
89  }
90 
91  void SetJSROOT(const char *location);
92 
93  void AddLocation(const char *prefix, const char *path);
94 
95  void SetDefaultPage(const char *filename);
96 
97  void SetDrawPage(const char *filename);
98 
99  void SetTimer(Long_t milliSec = 100, Bool_t mode = kTRUE);
100 
101  /** Check if file is requested, thread safe */
102  Bool_t IsFileRequested(const char *uri, TString &res) const;
103 
104  /** Execute HTTP request */
106 
107  /** Process submitted requests, must be called from main thread */
108  void ProcessRequests();
109 
110  /** Register object in subfolder */
111  Bool_t Register(const char *subfolder, TObject *obj);
112 
113  /** Unregister object */
115 
116  /** Restrict access to specified object */
117  void Restrict(const char *path, const char* options);
118 
119  Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon = 0);
120 
121  Bool_t Hide(const char *fullname, Bool_t hide = kTRUE);
122 
123  Bool_t SetIcon(const char *fullname, const char *iconname);
124 
125  Bool_t CreateItem(const char *fullname, const char *title);
126 
127  Bool_t SetItemField(const char *fullname, const char *name, const char *value);
128 
129  const char *GetItemField(const char *fullname, const char *name);
130 
131  /** Guess mime type base on file extension */
132  static const char *GetMimeType(const char *path);
133 
134  /** Reads content of file from the disk */
135  static char *ReadFileContent(const char *filename, Int_t &len);
136 
137  ClassDef(THttpServer, 0) // HTTP server for ROOT analysis
138 };
139 
140 #endif
Definition: TMutex.h:37
TRootSniffer * GetSniffer() const
Definition: THttpServer.h:66
const char * GetItemField(const char *fullname, const char *name)
static const char * filename()
Basic string class.
Definition: TString.h:137
TString fTopName
location of local JSROOT files
Definition: THttpServer.h:40
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
TList fEngines
Definition: THttpServer.h:33
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:35
THttpServer(const char *engine="civetweb:8080")
#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:34
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:42
TString fJSROOTSYS
id of the main ROOT process
Definition: THttpServer.h:39
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:44
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:46
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
virtual void ProcessRequest(THttpCallArg *arg)
submitted arguments
TString fDrawPageCont
file name for drawing of single element
Definition: THttpServer.h:47
TString fDefaultPageCont
file name for default page name
Definition: THttpServer.h:45
Bool_t RegisterCommand(const char *cmdname, const char *method, const char *icon=0)
Register command which can be executed from web interface.
#define name(a, b)
Definition: linkTestLib0.cpp:5
Mother of all ROOT objects.
Definition: TObject.h:58
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:37
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
const char * GetTopName() const
Definition: THttpServer.h:85
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:50
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:41
const Bool_t kTRUE
Definition: Rtypes.h:91
TObject * obj
float value
Definition: math.cpp:443
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)
TMutex fMutex
content of draw page
Definition: THttpServer.h:49
void Restrict(const char *path, const char *options)
Restrict access to specified object.
Bool_t IsAnyEngine() const
Definition: THttpServer.h:64
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:79
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)