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