DABC (Data Acquisition Backbone Core)  2.9.9
Server.h
Go to the documentation of this file.
1 // $Id: Server.h 4481 2020-04-15 14:46:54Z linev $
2 
3 /************************************************************
4  * The Data Acquisition Backbone Core (DABC) *
5  ************************************************************
6  * Copyright (C) 2009 - *
7  * GSI Helmholtzzentrum fuer Schwerionenforschung GmbH *
8  * Planckstr. 1, 64291 Darmstadt, Germany *
9  * Contact: http://dabc.gsi.de *
10  ************************************************************
11  * This software can be used under the GPL license *
12  * agreements as stated in LICENSE.txt file *
13  * which is part of the distribution. *
14  ************************************************************/
15 
16 #ifndef HTTP_Server
17 #define HTTP_Server
18 
19 #ifndef DABC_Worker
20 #include "dabc/Worker.h"
21 #endif
22 
23 #include <vector>
24 
25 namespace http {
26 
31  class Server : public dabc::Worker {
32 
33  protected:
34 
35  struct Location {
36  std::string fFilePath;
37  std::string fAbsPrefix;
38  std::string fNamePrefix;
39  std::string fNamePrefixRepl;
40  };
41 
42  std::vector<Location> fLocations;
43  std::string fHttpSys;
44  std::string fJsRootSys;
46 
47  std::string fAutoLoad;
48  std::string fTopTitle;
49  std::string fBrowser;
50  std::string fLayout;
51  std::string fDrawItem;
52  std::string fDrawOpt;
54 
56  static bool VerifyFilePath(const char* fname);
57 
59  bool IsFileRequested(const char* uri, std::string& fname);
60 
61  void ExtractPathAndFile(const char* uri, std::string& pathname, std::string& filename);
62 
64  bool IsAuthRequired(const char* uri);
65 
67  bool Process(const char* uri, const char* query,
68  std::string& content_type,
69  std::string& content_header,
70  std::string& content_str,
71  dabc::Buffer& content_bin);
72 
73  public:
74  Server(const std::string &name, dabc::Command cmd = nullptr);
75 
76  virtual ~Server();
77 
79  void AddLocation(const std::string &filepath,
80  const std::string &absprefix,
81  const std::string &nameprefix = "",
82  const std::string &nameprefixrepl = "");
83 
84  virtual const char* ClassName() const { return "HttpServer"; }
85 
86  static const char* GetMimeType(const char* fname);
87  };
88 
89 }
90 
91 #endif
Reference on memory from memory pool.
Definition: Buffer.h:135
Represents command with its arguments.
Definition: Command.h:99
Active object, which is working inside dabc::Thread.
Definition: Worker.h:116
Server provides http access to DABC
Definition: Server.h:31
int fMonitoring
_monitoring value in h.json, only for top page
Definition: Server.h:53
int fDefaultAuth
0 - false, 1 - true, -1 - ignored
Definition: Server.h:45
bool IsFileRequested(const char *uri, std::string &fname)
Check if file is requested.
Definition: Server.cxx:207
static bool VerifyFilePath(const char *fname)
Check if relative path below current dir - prevents file access to top directories via http.
Definition: Server.cxx:169
std::string fJsRootSys
location of JSROOT code, need to read special files
Definition: Server.h:44
Server(const std::string &name, dabc::Command cmd=nullptr)
Definition: Server.cxx:99
std::string fHttpSys
location of http plugin, need to read special files
Definition: Server.h:43
std::string fDrawItem
_drawitem value in h.json, only for top page
Definition: Server.h:51
virtual const char * ClassName() const
Returns class name of the object instance.
Definition: Server.h:84
std::vector< Location > fLocations
different locations known to server
Definition: Server.h:42
std::string fLayout
_layout value in h.json
Definition: Server.h:50
bool IsAuthRequired(const char *uri)
Returns true if authentication is required.
Definition: Server.cxx:240
std::string fTopTitle
_toptitle value in h.json
Definition: Server.h:48
std::string fBrowser
_browser value in h.json
Definition: Server.h:49
void ExtractPathAndFile(const char *uri, std::string &pathname, std::string &filename)
Definition: Server.cxx:226
virtual ~Server()
Definition: Server.cxx:152
std::string fDrawOpt
_drawopt value in h.json, only for top page
Definition: Server.h:52
bool Process(const char *uri, const char *query, std::string &content_type, std::string &content_header, std::string &content_str, dabc::Buffer &content_bin)
Method process different URL requests, should be called from server thread.
Definition: Server.cxx:259
std::string fAutoLoad
_autoload value in h.json
Definition: Server.h:47
static const char * GetMimeType(const char *fname)
Definition: Server.cxx:27
void AddLocation(const std::string &filepath, const std::string &absprefix, const std::string &nameprefix="", const std::string &nameprefixrepl="")
Add files location.
Definition: Server.cxx:156
Support of HTTP in DABC.
Definition: Civetweb.h:25
std::string fNamePrefix
prefix in filename like "dabc_"
Definition: Server.h:38
std::string fFilePath
path on file system /home/user/dabc
Definition: Server.h:36
std::string fNamePrefixRepl
replacement for name prefix like "/files/"
Definition: Server.h:39
std::string fAbsPrefix
prefix in http address like "/dabcsys"
Definition: Server.h:37