52 void Send(
const void *buf,
int len)
override
92 auto arg = std::make_shared<THttpCallArg>();
93 arg->SetPathAndFileName(request_info->
local_uri);
96 arg->SetMethod(
"WS_CONNECT");
100 return execres && !arg->Is404() ? 0 : 1;
116 auto arg = std::make_shared<THttpCallArg>();
117 arg->SetPathAndFileName(request_info->
local_uri);
119 arg->SetMethod(
"WS_READY");
145 auto arg = std::make_shared<THttpCallArg>();
146 arg->SetPathAndFileName(request_info->
local_uri);
149 arg->SetMethod(
"WS_CLOSE");
166 int fin = code & 0x80, opcode = code & 0x0F;
169 enum { OP_CONTINUE = 0, OP_TEXT = 1, OP_BINARY = 2, OP_CLOSE = 8 };
172 if (fin && (opcode == OP_CLOSE)) {
184 if ((opcode != OP_CONTINUE) && (opcode != OP_TEXT) && (opcode != OP_BINARY)) {
209 auto arg = std::make_shared<THttpCallArg>();
210 arg->SetPathAndFileName(request_info->
local_uri);
213 arg->SetMethod(
"WS_DATA");
221 arg->SetPostData(std::string(
data,
len));
242 if ((
gDebug > 0) || (strstr(message,
"cannot bind to") != 0))
243 fprintf(stderr,
"Error in <TCivetweb::Log> %s\n", message);
261 auto arg = std::make_shared<THttpCallArg>();
274 arg->SetContent(std::move(buf));
278 arg->AddNoCacheHeader();
285 arg->SetPathAndFileName(request_info->
local_uri);
296 arg->SetRequestHeader(header);
306 arg->SetPostData(std::move(buf));
311 cont.
Append(
"<title>Civetweb echo</title>");
312 cont.
Append(
"<h1>Civetweb echo</h1>\n");
314 static int count = 0;
322 if (arg->GetUserName())
325 cont.
Append(
"</pre><p>\n");
327 cont.
Append(
"Environment:<br/>\n<pre>\n");
331 cont.
Append(
"</pre><p>\n");
333 arg->SetContentType(
"text/html");
335 arg->SetContent(cont);
342 if (!execres || arg->Is404()) {
343 std::string hdr = arg->FillHttpHeader(
"HTTP/1.1");
345 }
else if (arg->IsFile()) {
346 filename = (
const char *)arg->GetContent();
350 auto hFile = CreateFile(
filename.Data(),
355 FILE_ATTRIBUTE_NORMAL,
361 auto dwRet = GetFinalPathNameByHandle( hFile, Path,
BUFSIZE, FILE_NAME_NORMALIZED | VOLUME_NAME_DOS );
364 if (dwRet > 4 && Path[0] ==
'\\' && Path[1] ==
'\\' && Path[2] ==
'?' && Path[3] ==
'\\')
381 switch (arg->GetZipping()) {
384 if (arg->GetContentLength() < 10000)
break;
401 arg->CompressWithGzip();
403 std::string hdr = arg->FillHttpHeader(
"HTTP/1.1");
406 if (arg->GetContentLength() > 0)
407 mg_write(conn, arg->GetContent(), (
size_t)arg->GetContentLength());
453 :
THttpEngine(
"civetweb",
"compact embedded http server"),
454 fOnlySecured(only_secured)
472 if ((
gDebug > 0) || (strstr(message,
"cannot bind to") != 0))
473 Error(
"Log",
"%s", message);
517 websocket_timeout =
"300000",
518 dir_listening =
"no",
524 Int_t socket_mode = 0700;
525 bool use_ws =
kTRUE, is_socket =
false;
533 is_socket = *args ==
'x';
535 while ((*args != 0) && (*args !=
'?') && (is_socket || (*args !=
'/')))
541 while ((*args != 0) && (*args !=
'?'))
560 num_threads.Form(
"%d", thrds);
568 auth_domain = adomain;
576 websocket_timeout.Format(
"%d", wtmout * 1000);
591 if (dls && (!strcmp(dls,
"no") || !strcmp(dls,
"yes")))
596 socket_mode = std::stoi(smode,
nullptr, *smode==
'0' ? 8 : 10);
599 sport =
TString(
"127.0.0.1:") + sport;
603 if (addr && strlen(addr))
604 sport =
TString(addr) +
":" + sport;
623 const char *options[25];
626 Info(
"Create",
"Starting HTTP server on port %s", sport.
Data());
628 options[op++] =
"listening_ports";
629 options[op++] = sport.
Data();
630 options[op++] =
"num_threads";
631 options[op++] = num_threads.Data();
634 options[op++] =
"websocket_timeout_ms";
635 options[op++] = websocket_timeout.Data();
638 if ((auth_file.Length() > 0) && (auth_domain.Length() > 0)) {
639 options[op++] =
"global_auth_file";
640 options[op++] = auth_file.Data();
641 options[op++] =
"authentication_domain";
642 options[op++] = auth_domain.Data();
644 options[op++] =
"enable_auth_domain_check";
645 options[op++] =
"no";
648 if (log_file.Length() > 0) {
649 options[op++] =
"error_log_file";
650 options[op++] = log_file.Data();
653 if (ssl_cert.Length() > 0) {
654 options[op++] =
"ssl_certificate";
655 options[op++] = ssl_cert.Data();
657 Error(
"Create",
"No SSL certificate file configured");
660 if (max_age.Length() > 0) {
661 options[op++] =
"static_file_max_age";
662 options[op++] = max_age.Data();
665 options[op++] =
"enable_directory_listing";
666 options[op++] = dir_listening.Data();
668 options[op++] =
nullptr;
671 if (is_socket && !sport.
Contains(
","))
687 if (is_socket && !sport.
Contains(
","))
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 *)
void websocket_ready_handler(struct mg_connection *conn, void *)
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
R__EXTERN TSystem * gSystem
int mg_printf(struct mg_connection *conn, const char *fmt,...)
void mg_send_file(struct mg_connection *conn, const char *path)
struct mg_context * mg_start(const struct mg_callbacks *callbacks, void *user_data, const char **options)
void mg_set_websocket_handler(struct mg_context *ctx, const char *uri, mg_websocket_connect_handler connect_handler, mg_websocket_ready_handler ready_handler, mg_websocket_data_handler data_handler, mg_websocket_close_handler close_handler, void *cbdata)
void mg_send_mime_file(struct mg_connection *conn, const char *path, const char *mime_type)
const char * mg_get_header(const struct mg_connection *conn, const char *name)
int mg_write(struct mg_connection *conn, const void *buf, size_t len)
const struct mg_request_info * mg_get_request_info(const struct mg_connection *conn)
void mg_set_user_connection_data(const struct mg_connection *const_conn, void *data)
void * mg_get_user_connection_data(const struct mg_connection *conn)
int mg_read(struct mg_connection *conn, void *buf, size_t len)
void mg_set_request_handler(struct mg_context *ctx, const char *uri, mg_request_handler handler, void *cbdata)
struct mg_context * mg_get_context(const struct mg_connection *conn)
void mg_stop(struct mg_context *ctx)
void * mg_get_user_data(const struct mg_context *ctx)
int mg_websocket_write(struct mg_connection *conn, int opcode, const char *data, size_t data_len)
@ MG_WEBSOCKET_OPCODE_CONNECTION_CLOSE
@ MG_WEBSOCKET_OPCODE_BINARY
@ MG_WEBSOCKET_OPCODE_TEXT
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.
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
virtual ~TCivetwebWSEngine()=default
TCivetwebWSEngine(struct mg_connection *conn)
THttpEngine implementation, based on civetweb embedded server.
struct mg_context * fCtx
! civetweb context
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
Bool_t fTerminating
! server doing shutdown and not react on requests
Bool_t Create(const char *args) override
Creates embedded civetweb server.
Bool_t IsDebugMode() const
virtual ~TCivetweb()
destructor
Bool_t IsWinSymLinks() const
Bool_t fDebug
! debug mode
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.
Bool_t IsFileRequested(const char *uri, TString &res) const
Check if file is requested, thread safe.
Bool_t ExecuteWS(std::shared_ptr< THttpCallArg > &arg, Bool_t external_thrd=kFALSE, Bool_t wait_process=kFALSE)
Execute WS request.
Bool_t ExecuteHttp(std::shared_ptr< THttpCallArg > arg)
Execute HTTP request.
void SetCors(const std::string &domain="*")
Enable CORS header to ProcessRequests() responses Specified location (typically "*") add as "Access-C...
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.
const char * Data() const
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.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
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.
const char * GetValueFromOptions(const char *key) const
Return a value for a given key from the URL options.
Int_t GetIntValueFromOptions(const char *key) const
Return a value for a given key from the URL options as an Int_t, a missing key returns -1.
void ParseOptions() const
Parse URL options into a key/value map.
Bool_t HasOption(const char *key) const
Returns true if the given key appears in the URL options list.
int(* log_message)(const struct mg_connection *, const char *message)
struct mg_header http_headers[(64)]
const char * request_method
const char * query_string