87 const char *cfg = engine->
IsWebGui() ?
"WebGui.HttpThreads parameter in rootrc" :
"thrds=N parameter in config URL";
88 const char *
place =
longpoll ?
"TCivetweb::LongpollHandler" :
"TCivetweb::WebSocketHandler";
111 auto arg = std::make_shared<THttpCallArg>();
116 arg->SetMethod(
"WS_CONNECT");
123 return execres && !arg->Is404() ? 0 : 1;
141 auto arg = std::make_shared<THttpCallArg>();
145 arg->SetMethod(
"WS_READY");
171 auto arg = std::make_shared<THttpCallArg>();
176 arg->SetMethod(
"WS_CLOSE");
195 int fin = code & 0x80, opcode = code & 0x0F;
238 auto arg = std::make_shared<THttpCallArg>();
243 arg->SetMethod(
"WS_DATA");
251 arg->SetPostData(std::string(
data,
len));
293 if (
strcmp(arg->GetFileName(),
"root.longpoll") != 0)
296 const char *
q = arg->GetQuery();
321 auto arg = std::make_shared<THttpCallArg>();
334 arg->SetContent(std::move(
buf));
338 arg->AddNoCacheHeader();
356 arg->SetRequestHeader(header);
366 arg->SetPostData(std::move(
buf));
371 cont.Append(
"<title>Civetweb echo</title>");
372 cont.Append(
"<h1>Civetweb echo</h1>\n");
374 static int count = 0;
382 if (arg->GetUserName())
385 cont.Append(
"</pre><p>\n");
387 cont.Append(
"Environment:<br/>\n<pre>\n");
391 cont.Append(
"</pre><p>\n");
393 arg->SetContentType(
"text/html");
395 arg->SetContent(
cont);
405 if (!
execres || arg->Is404()) {
406 std::string
hdr = arg->FillHttpHeader(
"HTTP/1.1");
408 }
else if (arg->IsFile()) {
409 filename = (
const char *)arg->GetContent();
444 switch (arg->GetZipping()) {
447 if (arg->GetContentLength() < 10000)
break;
464 arg->CompressWithGzip();
466 std::string
hdr = arg->FillHttpHeader(
"HTTP/1.1");
469 if (arg->IsChunked()) {
472 unsigned last_send = arg->GetContentLength();
479 serv->ExecuteHttp(arg);
490 }
else if (arg->GetContentLength() > 0)
491 mg_write(
conn, arg->GetContent(), (
size_t)arg->GetContentLength());
538 :
THttpEngine(
"civetweb",
"compact embedded http server"),
560 Error(
"Log",
"%s", message);
570 std::lock_guard<std::mutex> guard(
fMutex);
579 std::lock_guard<std::mutex> guard(
fMutex);
642 while ((*args != 0) && (*args !=
'?') && (
is_socket || (*args !=
'/')))
643 sport.Append(*args++);
648 while ((*args != 0) && (*args !=
'?'))
659 const char *top =
url.GetValueFromOptions(
"top");
663 const char *log =
url.GetValueFromOptions(
"log");
671 const char *
afile =
url.GetValueFromOptions(
"auth_file");
675 const char *
adomain =
url.GetValueFromOptions(
"auth_domain");
679 const char *
sslc =
url.GetValueFromOptions(
"ssl_certificate");
681 sslc =
url.GetValueFromOptions(
"ssl_cert");
691 if (
url.HasOption(
"websocket_disable"))
694 if (
url.HasOption(
"debug"))
701 const char *
dls =
url.GetValueFromOptions(
"dirlisting");
705 const char *
smode =
url.GetValueFromOptions(
"socket_mode");
709 if (
url.HasOption(
"loopback") && (
sport.Index(
":") ==
kNPOS))
713 const char *
addr =
url.GetValueFromOptions(
"bind");
719 const char *
cors =
url.GetValueFromOptions(
"cors");
724 const char *
cred =
url.GetValueFromOptions(
"cred_cors");
728 if (
url.HasOption(
"nocache"))
731 if (
url.HasOption(
"max_age"))
732 fMaxAge =
url.GetIntValueFromOptions(
"max_age");
741 const char *options[34];
744 Info(
"Create",
"Starting HTTP server on port %s",
sport.Data());
746 options[
op++] =
"listening_ports";
748 options[
op++] =
"num_threads";
752 options[
op++] =
"websocket_timeout_ms";
757 options[
op++] =
"global_auth_file";
759 options[
op++] =
"authentication_domain";
762 options[
op++] =
"enable_auth_domain_check";
763 options[
op++] =
"no";
767 options[
op++] =
"error_log_file";
772 options[
op++] =
"ssl_certificate";
775 Error(
"Create",
"No SSL certificate file configured");
779 options[
op++] =
"static_file_max_age";
785 options[
op++] =
"access_control_allow_origin";
790 options[
op++] =
"access_control_allow_credentials";
792 options[
op++] =
"access_control_expose_headers";
793 options[
op++] =
"Content-Range, Content-Length, Date";
794 options[
op++] =
"access_control_allow_methods";
795 options[
op++] =
"GET, HEAD, OPTIONS";
798 options[
op++] =
"enable_directory_listing";
801 options[
op++] =
nullptr;
804 Error(
"Create",
"civetweb compiled without sockets binding support");
809 Error(
"Create",
"civetweb compiled without SSL support");
814 Error(
"Create",
"civetweb compiled without websockets support");
bool Bool_t
Boolean (0=false, 1=true) (bool)
int Int_t
Signed integer 4 bytes (int)
constexpr Ssiz_t kNPOS
The equivalent of std::string::npos for the ROOT class TString.
int websocket_connect_handler(const struct mg_connection *conn, void *)
static int begin_request_handler(struct mg_connection *conn, void *)
static int log_message_handler(const struct mg_connection *conn, const char *message)
int websocket_data_handler(struct mg_connection *conn, int code, char *data, size_t len, void *)
void websocket_close_handler(const struct mg_connection *conn, void *)
Bool_t CheckEngineThreads(TCivetweb *engine, const char *uri, Bool_t longpoll)
Check if engine has enough threads to process connect to new websocket handle.
void websocket_ready_handler(struct mg_connection *conn, void *)
Bool_t IsBadLongPollConnect(TCivetweb *engine, const std::shared_ptr< THttpCallArg > &arg)
Returns kTRUE in case of longpoll connection request - or at least looks like that.
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
#define INVALID_HANDLE_VALUE
Int_t gDebug
Global variable setting the debug level. Set to 0 to disable, increase it in steps of 1 to increase t...
R__EXTERN TSystem * gSystem
struct mg_connection * fWSconn
UInt_t GetId() const override
void SendCharStar(const char *str) override
Envelope for sending string via the websocket.
void ClearHandle(Bool_t terminate) override
Bool_t SupportSendThrd() const override
True websocket requires extra thread to parallelize sending.
~TCivetwebWSEngine() override=default
void SendHeader(const char *hdr, const void *buf, int len) override
Special method to send binary data with text header For normal websocket it is two separated operatio...
void Send(const void *buf, int len) override
TCivetwebWSEngine(struct mg_connection *conn)
THttpEngine implementation, based on civetweb embedded server.
Int_t fNumThreads
! number of configured threads
Int_t fNumActiveThreads
! number of active threads - used in request and websocket handling
struct mg_context * fCtx
! civetweb context
std::mutex fMutex
! mutex to read/write fNumActiveThreads
Bool_t fWinSymLinks
! resolve symbolic links on Windows
Bool_t IsTerminating() const
const char * GetTopName() const
TCivetweb(Bool_t only_secured=kFALSE)
constructor
Int_t fMaxAge
! max-age parameter
Int_t ProcessLog(const char *message)
process civetweb log message, can be used to detect critical errors
TString fTopName
! name of top item
Int_t GetNumAvailableThreads()
Returns number of actively used threads.
Bool_t fTerminating
! server doing shutdown and not react on requests
Bool_t Create(const char *args) override
Creates embedded civetweb server.
Int_t GetNumThreads() const
Bool_t IsDebugMode() const
virtual ~TCivetweb()
destructor
Bool_t IsWinSymLinks() const
Bool_t fWebGui
! if server used for webgui
Bool_t fDebug
! debug mode
Int_t ChangeNumActiveThreads(int cnt=0)
Returns number of actively used threads.
struct mg_callbacks fCallbacks
! call-back table for civetweb webserver
Abstract class for implementing http protocol for THttpServer.
THttpServer * GetServer() const
Returns pointer to THttpServer associated with engine.
Online http server for arbitrary ROOT application.
const char * GetCors() const
Returns specified CORS domain.
void SetCorsCredentials(const std::string &value="true")
Enable/disable usage Access-Control-Allow-Credentials response header.
void SetCors(const std::string &domain="*")
Enable CORS header to ProcessRequests() responses Specified location (typically "*") add as "Access-C...
const char * GetCorsCredentials() const
Returns specified CORS credentials value - if any.
static char * ReadFileContent(const char *filename, Int_t &len)
Reads content of file from the disk.
static const char * GetMimeType(const char *path)
Guess mime type base on file extension.
Internal instance used to exchange WS functionality between THttpServer and THttpWSHandler.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Info(const char *method, const char *msgfmt,...) const
Issue info message.
Int_t Atoi() const
Return integer value of string.
UInt_t Hash(ECaseCompare cmp=kExact) const
Return hash value.
TString & Append(const char *cs)
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
virtual int Chmod(const char *file, UInt_t mode)
Set the file permission bits. Returns -1 in case or error, 0 otherwise.
virtual int Unlink(const char *name)
Unlink, i.e.
This class represents a WWW compatible URL.
TEngineHolder(TCivetweb *engine)