From fe28ebae1c713eabab57d989dc896d155d7ecd12 Mon Sep 17 00:00:00 2001 From: Ground0 Date: Wed, 29 Mar 2023 10:46:56 +0200 Subject: [PATCH] New Multi Host/Server and XML configurationlayer --- lweb.pbi | 726 +++++++++++++++++++++++++------------------------------ 1 file changed, 328 insertions(+), 398 deletions(-) diff --git a/lweb.pbi b/lweb.pbi index 92303bb..ccf5618 100644 --- a/lweb.pbi +++ b/lweb.pbi @@ -8,8 +8,8 @@ ;* -XIncludeFile "ltls.pbi" -XIncludeFile "lsocket.pbi" +XIncludeFile "lhs_lib/NET/lhs_net_tls.pbi" +XIncludeFile "lhs_lib/NET/lhs_net_socket.pbi" Module lhs_web ;******************************** @@ -22,61 +22,7 @@ Module lhs_web ;* Configuration Structures ;* ;{ - Structure server_http - enabled.i - port.i - binding.s - max_clients.i - EndStructure - - Structure server_https - enabled.i - port.i - binding.s - max_clients.i - CA.s - Certs.s - key.s - key_pass.s - EndStructure - - Structure server_cache - time.i - maxsize.i - current.i - enable.i - EndStructure - - Structure memory - MaxFileSize.i - DefaultBlockSize.i - EndStructure - - Structure log_config - Debuglog.s - Debugdisable.i - Accesslog.s - AccesslogUUID.s - Errorlog.s - ErrorlogUUID.s - Cachelog.s - CachelogUUID.s - EndStructure - - Structure server - http.server_http - https.server_https - cache.server_cache - log.log_config - mem.memory - version.s - identifikation.s - defaultfile.s - basedir.s - error400.s - errorfile404.s - type.i - EndStructure + XIncludeFile "inc/lweb_header_privat.pbi" ;} ;* @@ -87,37 +33,22 @@ Module lhs_web Global configuration.server configuration\version = "V0.9" configuration\identifikation = "LiHaSo Webserver " + configuration\version + configuration\config_file("status_xml")\name = "cfg/default_http_status_codes.xml" + configuration\config_file("status_xml")\type = "file" + configuration\config_file("hosts_dir")\name = "cfg/server/" + configuration\config_file("hosts_dir")\type = "dir" ;* ;* Diese Parameter müssen entsprechend angepasst sein. ;* Später ausgelagert in ein nicht synchronisiertes lweb-cfg.pbi ;* Folgende Parameter müssen im Hauptprogramm definiert sein. - configuration\defaultfile = "index.html" - configuration\basedir = "/srv/lweb-srv/" - configuration\error400 = "integrated" ; Kann "integrated" sein wass die integrierte Standard Fehlermeldung hervorruft. - configuration\errorfile404 = "error.html" + configuration\type = 0 + configuration\global_max_cli_memory = 0 ; Unlimited + configuration\global_max_cli_threads = 0 ; Unlimited - configuration\http\max_clients = 10 ; Max sametime HTTP connections. - configuration\http\port = 8080 - configuration\http\binding = "127.0.0.1" - configuration\https\max_clients = 100 - configuration\https\port = 8443 - configuration\https\binding = "127.0.0.1" - configuration\https\enabled = 0 - configuration\https\CA = "" - configuration\https\Certs = "" - configuration\https\key = "" - configuration\https\key_pass = "" - - configuration\cache\enable = 0 ; Enable / Disable Cached Server - configuration\cache\time = 120 ; TTL of cached files - configuration\cache\maxsize = 1 ; Max Cache - configuration\cache\current = 0 ; - - configuration\mem\MaxFileSize = 524288 ; Default 512 KiB - configuration\mem\DefaultBlockSize = 65536 ; Default Blocksize 64 KiB + Enumeration s_client_do ;client_do_cli @@ -148,9 +79,9 @@ Module lhs_web #client_add = 1 #client_remove = -1 - #http_method_get = "GET" + #http_method_get = "GET" #http_method_post = "POST" - #http_method_put = "PUT" + #http_method_put = "PUT" ;*********************** ;* s_lweb_client Struktur Jeder Clientthread muss in die Liste eingetragen werden.: @@ -176,6 +107,14 @@ Module lhs_web Is.i EndStructure + Structure PORT_used + UUID.s + EndStructure + + Structure IP_used + Map PortS.PORT_used() + EndStructure + Structure s_clients client_id.i client_do_cli.i @@ -187,6 +126,9 @@ Module lhs_web client_test_cli.i client_test_srv.i client_cctx.i + server_uuid.s ;On which Server it is received. + host_id.s + client_timeout.i ;Individual timeout per Server to cleanup Client connections EndStructure Structure s_request_handler @@ -195,6 +137,12 @@ Module lhs_web routetype.i EndStructure + Structure s_server_runs + server_connection_id.i + UUID.s + configuration_map_id.s + EndStructure + Enumeration cli_handler_infos 1 @@ -207,6 +155,7 @@ Module lhs_web Global.i server_HTTP_id Global.i server_HTTPS_id Global.i server_mutex = CreateMutex() ;Dieser Mutex dient zu der Sicherheit der Element Liste. + Global.i server_start_semaphore = CreateSemaphore() Global.i count_HTTP_mutex = CreateMutex() Global.i count_HTTPS_mutex = CreateMutex() Global.i file_cache_mutex = CreateMutex() @@ -214,8 +163,10 @@ Module lhs_web Global.i file_cache_semaphore_thread = CreateSemaphore() Global NewMap m_file_cache_map.i() Global NewMap m_file_cache.s_file_cache() - Global NewMap m_clients.s_clients(configuration\http\max_clients+configuration\https\max_clients) + Global NewMap m_clients.s_clients() Global NewMap m_request.s_request_handler() + Global NewMap server_used.IP_used() + Global NewMap m_server_running.s_server_runs() ;} @@ -235,7 +186,8 @@ Module lhs_web ;* XIncludeFile "inc/lweb_http_header.pbi" - XIncludeFile "inc/lweb_file_cache_header.pbi" + ;XIncludeFile "inc/lweb_file_cache_header.pbi" + XIncludeFile "inc/lweb_config_header.pbi" ;******************************** ;* @@ -245,7 +197,7 @@ Module lhs_web Declare server_HTTP(network_server_id.i) Declare server_HTTPS(network_server_id.i) Declare client(network_client_id.i) - Declare.s file_check(thread_requested.s) + Declare.s file_check(thread_requested.s, hostid.s) Declare call_request(RequestString.s, Info.i=#get_handler_procedure) Declare.s Work_Post_ToJSON_multipart_form_data(ContentLength.i, MemorSize.i, Memory.i) @@ -255,201 +207,167 @@ Module lhs_web XIncludeFile "inc/lweb_IP.pbi" XIncludeFile "inc/lweb_http.pbi" XIncludeFile "inc/lweb_helper.pbi" - XIncludeFile "inc/lweb_file_cache.pbi" + ;XIncludeFile "inc/lweb_file_cache.pbi" Currently in dev. + XIncludeFile "inc/lweb_config.pbi" + IncludeFile "lhs_lib/SYS/lhs_uuid.pbi" ;It is needed as local function. - Procedure set_config(parameter.i=#conf_defaultfile, setting.s="index.html") - Select parameter - Case #conf_File_BlockSize - configuration\mem\DefaultBlockSize = Val(setting) - Case #conf_File_max_in_Memory - configuration\mem\MaxFileSize = Val(setting) - Case #conf_Access_logfile - configuration\log\Accesslog = setting - Case #conf_Error_logfile - configuration\log\Errorlog = setting - Case #conf_Access_logUUID - configuration\log\AccesslogUUID = setting - Case #conf_Error_logUUID - configuration\log\ErrorlogUUID = setting - Case #conf_Cache_logUUID - configuration\log\CachelogUUID = setting - Case #conf_debug_logfile - configuration\log\Debuglog = setting - Case #conf_debug_disable - If setting = "true" - configuration\log\Debugdisable = #True - Else - configuration\log\Debugdisable = #False - EndIf - Case #conf_runfile - - Case #conf_HTTP_port - configuration\http\port = Val(setting) - Case #conf_HTTPS_Port - configuration\https\port = Val(setting) - Case #conf_HTTP_binding - If IsIPStringValid(setting) - configuration\http\binding = setting - Else - configuration\http\binding = "127.0.0.1" - ProcedureReturn #False - EndIf - Case #conf_HTTPS_Binding - If IsIPStringValid(setting) - configuration\https\binding = setting - Else - configuration\https\binding = "127.0.0.1" - ProcedureReturn #False - EndIf - Case #conf_HTTPS_CA - configuration\https\CA = setting - Case #conf_HTTPS_Cert - configuration\https\Certs = setting - Case #conf_HTTPS_Key - configuration\https\Key = setting - Case #conf_HTTPS_Key_Pass - configuration\https\key_pass = setting - Case #conf_HTTPS_Enable - configuration\https\enabled = Val(setting) - Case #conf_defaultfile - configuration\defaultfile = setting - Case #conf_basedir - configuration\basedir = setting - Case #conf_error400 - configuration\error400 = setting ; Kann "integrated" sein wass die integrierte Standard Fehlermeldung hervorruft. - Case #conf_max_HTTP_clients - If MemoryStatus(#PB_System_FreePhysical) > (Val(setting)*(1024*384)) - configuration\http\max_clients = Val(setting) - Else - configuration\http\max_clients = 10 - ProcedureReturn #False - EndIf - Case #conf_max_HTTPS_clients - If MemoryStatus(#PB_System_FreePhysical) > (Val(setting)*(1024*384)) - configuration\https\max_clients = Val(setting) - Else - configuration\https\max_clients = 10 - ProcedureReturn #False - EndIf - Case #conf_server_type - configuration\type = Val(setting) - Case #conf_cache_enable - configuration\cache\enable = Val(Setting) - Default - ProcedureReturn #False - EndSelect + XIncludeFile "inc/lweb_server_cfg.pbi" + + Procedure server_reload(UUID.s) + ProcedureReturn #True EndProcedure + + IncludeFile "inc/lweb_http_status.pbi" - Procedure.s get_config(parameter.i=#conf_defaultfile) - Select parameter - Case #conf_File_BlockSize - ProcedureReturn Str(configuration\mem\DefaultBlockSize) - Case #conf_File_max_in_Memory - ProcedureReturn Str(configuration\mem\MaxFileSize) - Case #conf_Access_logfile - ProcedureReturn configuration\log\Accesslog - Case #conf_Error_logfile - ProcedureReturn configuration\log\Errorlog - Case #conf_Access_logUUID - ProcedureReturn configuration\log\AccesslogUUID - Case #conf_Error_logUUID - ProcedureReturn configuration\log\ErrorlogUUID - Case #conf_debug_logfile - ProcedureReturn configuration\log\Debuglog - Case #conf_debug_disable - If configuration\log\Debugdisable = #True - ProcedureReturn "true" - Else - ProcedureReturn "false" - EndIf - Case #conf_defaultfile - ProcedureReturn configuration\defaultfile - Case #conf_basedir - ProcedureReturn configuration\basedir - Case #conf_error400 - ProcedureReturn configuration\error400 - Case #conf_max_HTTP_clients - ProcedureReturn Str(configuration\http\max_clients) - Case #conf_server_type - ProcedureReturn Str(configuration\type) - Case #conf_HTTP_port - ProcedureReturn Str(configuration\http\port) - Case #conf_HTTPS_Port - ProcedureReturn Str(configuration\https\port) - Default - ProcedureReturn "" - EndSelect + Procedure.s http_server_prepare(http_port.i = 8080, http_binding.s = "127.0.0.1", https_port.i=8443, https_binding.s="127.0.0.1", https_enabled.b = #False) + ;CreateUUID + Protected UUID.s + UUID = CreateUUID() + configuration\hosts(UUID)\defaultfile = "index.html" + configuration\hosts(UUID)\basedir = "/srv/lweb-srv/" + + configuration\hosts(UUID)\http\max_clients = 10 ; Max sametime HTTP connections. + configuration\hosts(UUID)\http\port = 8080 + configuration\hosts(UUID)\http\binding = "127.0.0.1" + + configuration\hosts(UUID)\https\max_clients = 100 + configuration\hosts(UUID)\https\port = 8443 + configuration\hosts(UUID)\https\binding = "127.0.0.1" + configuration\hosts(UUID)\https\enabled = 0 + configuration\hosts(UUID)\https\CA = "" + configuration\hosts(UUID)\https\Certs = "" + configuration\hosts(UUID)\https\key = "" + configuration\hosts(UUID)\https\key_pass = "" + + configuration\hosts(UUID)\cache\enable = 0 ; Enable / Disable Cached Server + configuration\hosts(UUID)\cache\time = 120 ; TTL of cached files + configuration\hosts(UUID)\cache\maxsize = 1 ; Max Cache + configuration\hosts(UUID)\cache\current = 0 ; + + configuration\hosts(UUID)\mem\MaxFileSize = 524288 ; Default 512 KiB + configuration\hosts(UUID)\mem\DefaultBlockSize = 65536 ; Default Blocksize 64 KiB + ProcedureReturn UUID EndProcedure - Procedure start_server() - Global NewMap m_clients.s_clients(configuration\http\max_clients+configuration\https\max_clients) + Procedure main_server(id.i) + status_defaults() + EndProcedure + + Procedure server_start() + Protected server_id_HTTP + Protected server_id_HTTPS + Protected server_UUID_HTTP.s + Protected server_UUID_HTTPS.s + Protected counter.i, id.i + Global NewMap m_clients.s_clients(configuration\global_max_cli_threads) ;configuration\http\max_clients+configuration\https\max_clients Protected tlsresponse.i - If configuration\log\Debugdisable - lhs_log::Disable() - EndIf - - ;Init HTTP Socket - server_HTTP_id = lsocket::CreateSocket(configuration\http\port, configuration\http\max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, configuration\http\binding) - If configuration\https\enabled = 1 - server_HTTPS_id = lsocket::CreateSocket(configuration\https\port, configuration\https\max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, configuration\https\binding) - If server_HTTPS_id - tlsresponse = ltls::InitSimpleTLS(configuration\https\CA, configuration\https\Certs, configuration\https\key, configuration\https\key_pass) - If tlsresponse > 0 - CreateThread(@server_HTTPS(), server_HTTPS_id) - Else - lhs_log::Out("TLS Fehler:"+Str(tlsresponse)) - ProcedureReturn #False + ;Initialize all Servers in configuration\hosts() + ResetMap(configuration\hosts()) + While NextMapElement(configuration\hosts()) + server_id_HTTP = lsocket::CreateSocket(configuration\hosts()\http\port, configuration\hosts()\http\max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, configuration\hosts()\http\binding) + If server_id_HTTP + + ;Check for HTTPS + If configuration\hosts()\https\enabled = 1 + server_id_HTTPS = lsocket::CreateSocket(configuration\hosts()\https\port, configuration\hosts()\https\max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, configuration\hosts()\https\binding) + If server_id_HTTPS + ;Now Create TLS Socket + tlsresponse = tls::InitSimpleTLS(configuration\hosts()\https\CA,configuration\hosts()\https\Certs, configuration\hosts()\https\key, configuration\hosts()\https\key_pass) + If tlsresponse > 0 + m_server_running(Str(server_id_HTTPS))\configuration_map_id = MapKey(configuration\hosts()) + configuration\hosts()\https\thread_id = CreateThread(@server_HTTPS(), server_id_HTTPS) + counter + 1 + Else + ldl::Logging("HTTPS Socket configuration failed with error:"+Str(tlsresponse)) + End + EndIf + Else + ldl::Logging("HTTPS Socket ["+configuration\hosts()\https\port+"] could Not opened.") + End + EndIf EndIf + ;HTTP server start + m_server_running(Str(server_id_HTTP))\configuration_map_id = MapKey(configuration\hosts()) + configuration\hosts()\http\thread_id = CreateThread(@server_HTTP(), server_id_HTTP) + counter + 1 + configuration\hosts()\log\AccesslogUUID = lhs_log_ext::Create("Accesslog "+configuration\hosts()\description) + configuration\hosts()\log\ErrorlogUUID = lhs_log_ext::Create("Errorlog "+configuration\hosts()\description) + lhs_log_ext::Init(configuration\hosts()\log\AccesslogUUID) + lhs_log_ext::Init(configuration\hosts()\log\ErrorlogUUID) + ldl::Register(lhs_log_ext::@Out(), configuration\hosts()\log\AccesslogUUID) + ldl::Register(lhs_log_ext::@Out(), configuration\hosts()\log\ErrorlogUUID) + ldl::Logging("Accesslog UUID:"+configuration\hosts()\log\AccesslogUUID) + ldl::Logging("Errorlog UUID:"+configuration\hosts()\log\ErrorlogUUID) Else - ProcedureReturn #False + ldl::Logging("HTTP Socket ["+configuration\hosts()\http\port+"] could Not be opened.") + End EndIf - EndIf - If server_HTTP_id - CreateThread(@server_HTTP(), server_HTTP_id) - ProcedureReturn #True - Else - ProcedureReturn #False - EndIf + Wend + ;Initalize Loggers: + + + + + + For id = 1 To counter + SignalSemaphore(server_start_semaphore) + Next + + ProcedureReturn #True EndProcedure + Procedure server_stop(UUID.s = "all") + ;Current easy kill HTTP and HTTPS thread. + ;Must be changed if Caching is active ! +; If configuration\https\enabled = 1 And configuration\https\thread_id <> 0 +; KillThread(configuration\https\thread_id) +; EndIf +; If configuration\http\thread_id <> 0 +; KillThread(configuration\http\thread_id) +; EndIf + + EndProcedure + + Procedure server_HTTPS(network_server_id.i) ;************************** ;* ;* Main thread for HTTPS networksocket management. Create the Client Threads. ;* Protected.i client_id - + Protected.i server_host.s = m_server_running(Str(network_server_id))\configuration_map_id thread_alive = #True - - lhs_log::Out("HTTPS Server Started.") + WaitSemaphore(server_start_semaphore) + ldl::Logging("HTTPS Server Started.") Repeat - client_id = ltls::WaitTLSSocket(network_server_id) - lhs_log::Out("New HTTPS Client:"+Str(client_id)) + client_id = tls::WaitTLSSocket(network_server_id) + ldl::Logging("New HTTPS Client:"+Str(client_id)) If client_id > 0 If m_clients(Str(client_id))\client_id = client_id - lhs_log::Out("Client Thread for socket already exist :"+Str(client_id)) + ldl::Logging("Client Thread for socket already exist :"+Str(client_id)) Else - If count_HTTPS_client < configuration\https\max_clients + If count_HTTPS_client < 128 m_clients(Str(client_id))\client_id = client_id m_clients(Str(client_id))\client_do_cli = #CLI_DO_WaitDataReceive m_clients(Str(client_id))\client_do_srv = #SRV_DO_DataReceive m_clients(Str(client_id))\client_type = #client_HTTPS + m_clients(Str(client_id))\host_id = server_host ;Thread erstellen m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id) count_client(#client_HTTPS, #client_add) Else - lhs_log::Out("Max HTTPS Clients reached...") - ltls::CloseTLSSocket(client_id) + ldl::Logging("Max HTTPS Clients reached...") + tls::CloseTLSSocket(client_id) EndIf EndIf Else Break EndIf ForEver - ltls::CloseTLS(network_server_id) + tls::CloseTLS(network_server_id) EndProcedure Procedure server_HTTP(network_server_id.i) @@ -458,27 +376,29 @@ Module lhs_web ;* Main thread for HTTP networksocket management. Create the Client Threads. ;* Protected.i client_id - - thread_alive = #True + Protected.i server_host.s = m_server_running(Str(network_server_id))\configuration_map_id - lhs_log::Out("HTTP Server Started.") + thread_alive = #True + WaitSemaphore(server_start_semaphore) + ldl::Logging("HTTP Server Started.") Repeat client_id = lsocket::WaitSocket(network_server_id) - lhs_log::Out("New HTTP Client:"+Str(client_id)) + ldl::Logging("New HTTP Client:"+Str(client_id)) If client_id > 0 If m_clients(Str(client_id))\client_id = client_id - lhs_log::Out("Client Thread for socket already exist :"+Str(client_id)) + ldl::Logging("Client Thread for socket already exist :"+Str(client_id)) Else - If count_HTTP_client < configuration\http\max_clients + If count_HTTP_client < 128 m_clients(Str(client_id))\client_id = client_id m_clients(Str(client_id))\client_do_cli = #CLI_DO_WaitDataReceive m_clients(Str(client_id))\client_do_srv = #SRV_DO_DataReceive m_clients(Str(client_id))\client_type = #client_HTTP + m_clients(Str(client_id))\host_id = server_host ;Thread erstellen m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id) count_client(#client_HTTP, #client_add) Else - lhs_log::Out("Max HTTP Clients reached...") + ldl::Logging("Max HTTP Clients reached...") lsocket::CloseSocket(client_id) EndIf EndIf @@ -498,12 +418,17 @@ Module lhs_web Protected thread_buffer, thread_buffer_offset, thread_buffer_length, buffer_sent Protected sent_length, sent_buffer_address, sent_total Protected.b thread_alive = #True, error_message = #False, thread_redirect = #False + + Protected.s default_file = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\defaultfile + Protected.s home_dir = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\basedir + Protected.s AccessLog = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\log\AccesslogUUID + Protected.s ErrorLog = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\log\ErrorlogUUID Define NewMap Header.s() Define NewMap Response.s() Define NewMap Post.s() - lhs_log::Out("Client Thread Started. ID:" + Str(network_client_id)) + ldl::Logging("Client Thread Started. ID:" + Str(network_client_id)) Repeat ;Prüfen ob der Thread was zu tun hat. ;{ Main Server Triggered Things @@ -518,17 +443,17 @@ Module lhs_web If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer m_clients(Str(thread_cli_id))\datenbuffer()\Initialized = #True Else - lhs_log::Out("Buffer Initialisierung fehlgeschlagen.") + ldl::Logging("Buffer Initialisierung fehlgeschlagen.") Break EndIf If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS - temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536) + temp_receivelength = tls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536) Else temp_receivelength = lsocket::ReadSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536) EndIf If temp_receivelength = -1 - lhs_log::Out("Empfangsfehler.") + ldl::Logging("Empfangsfehler.") Break ElseIf temp_receivelength = 65536 m_clients(Str(thread_cli_id))\datenbuffer()\Size = temp_receivelength @@ -539,11 +464,11 @@ Module lhs_web If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer m_clients(Str(thread_cli_id))\datenbuffer()\Initialized = #True Else - lhs_log::Out("Buffer Initialisierung fehlgeschlagen.") + ldl::Logging("Buffer Initialisierung fehlgeschlagen.") Break 2 EndIf If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS - temp_receivelength = ltls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536) + temp_receivelength = tls::ReadTLSSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536) Else temp_receivelength = lsocket::ReadSocket(thread_cli_id, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, 65536) EndIf @@ -558,19 +483,19 @@ Module lhs_web m_clients(Str(thread_cli_id))\datenbuffer()\Size = temp_receivelength EndIf ;Alle Daten empfangen. - lhs_log::Out("Anzahl Buffer:" + Str(ListSize(m_clients(Str(thread_cli_id))\datenbuffer()))) + ldl::Logging("Anzahl Buffer:" + Str(ListSize(m_clients(Str(thread_cli_id))\datenbuffer()))) m_clients(Str(thread_cli_id))\client_do_srv = #SRV_DO_NOP m_clients(Str(thread_cli_id))\client_do_cli = #CLI_DO_DataWorking Case #SRV_DO_ClientDisconnect ;Thread beenden - lhs_log::Out("#SRV_DO_ClientDisconnect") + ldl::Logging("#SRV_DO_ClientDisconnect") thread_alive = #False ;* Alles IO Default ;Ressourcen freigeben und Threadzeit reduzieren Delay(1) - lhs_log::Out("--------------------------------------------------------- FAILING ???") + ldl::Logging("--------------------------------------------------------- FAILING ???") EndSelect ;} @@ -583,18 +508,19 @@ Module lhs_web ;Change Thread to Work mode. ;{ - lhs_log::Out("Data received, working...") + ldl::Logging("Data received, working...") m_clients(Str(thread_cli_id))\client_do_cli = #CLI_DO_DataWorking ;Work on Answer. ResetList(m_clients(Str(thread_cli_id))\datenbuffer()) ;TODO: Only first Buffer have a Header. - + While NextElement(m_clients(Str(thread_cli_id))\datenbuffer()) - + thread_work = PeekS(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer, m_clients(Str(thread_cli_id))\datenbuffer()\Size, #PB_Ascii) ;Move Header to Map - + ldl::Logging("Preheaderwork:"+ thread_work) + JSONStringToMap = Work_Header_to_JSONMap(thread_work) If JSONStringToMap <> #error_string MyThreadJSON = ParseJSON(#PB_Any, JSONStringToMap) @@ -609,16 +535,18 @@ Module lhs_web Else error_message = #True EndIf + ;TODO: Url with GET Parameter (Also by POST/PUT & Co.) + ;? Wen da abschneiden - ;lhs_log::Out("JSONString:"+ JSONStringToMap) + ldl::Logging("JSONString:"+ JSONStringToMap) thread_type = "" If configuration\log\AccesslogUUID <> "" If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS - lhs_log_ext::Out(configuration\log\AccesslogUUID, lsocket::GetSocketIP(ltls::GetSocket(thread_cli_id)) + " " + Header(#http_head_method) + " " + Header(#http_head_request)) + ldl::Logging(lsocket::GetSocketIP(tls::GetSocket(thread_cli_id)) + " " + Header(#http_head_method) + " " + Header(#http_head_request), AccessLog) Else - lhs_log_ext::Out(configuration\log\AccesslogUUID, lsocket::GetSocketIP(thread_cli_id) + " " + Header(#http_head_method) + " " + Header(#http_head_request)) + ldl::Logging(lsocket::GetSocketIP(thread_cli_id) + " " + Header(#http_head_method) + " " + Header(#http_head_request), AccessLog) EndIf EndIf @@ -630,15 +558,15 @@ Module lhs_web ;* Default GET ;* ;{ - lhs_log::Out(#http_method_get) + ldl::Logging(#http_method_get) If Header(#http_head_request) = "/" - thread_requested = configuration\defaultfile + thread_requested = default_file Else thread_requested = Header(#http_head_request) EndIf - lhs_log::Out("Requested:"+thread_requested) + ldl::Logging("Requested:"+thread_requested) ToCallType = call_request(thread_requested, #get_handler_prototype) If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_get ToCall = call_request(thread_requested) @@ -647,7 +575,7 @@ Module lhs_web EndIf If ToCall = 0 If Right(thread_requested,1) = "/" - thread_requested = thread_requested+configuration\defaultfile + thread_requested = default_file Else thread_requested = thread_requested EndIf @@ -666,7 +594,7 @@ Module lhs_web Handler_Response = ToCallProcedureGet(Header()) EndSelect - lhs_log::Out("Main Client Response :"+Handler_Response) + ldl::Logging("Main Client Response :"+Handler_Response) MyThreadJSON = ParseJSON(#PB_Any, Handler_Response) If MyThreadJSON ClearMap(Response()) @@ -674,18 +602,18 @@ Module lhs_web FreeJSON(MyThreadJSON) Else ;WTF ??? - lhs_log::Out("Fehler Absturz") + ldl::Logging("Fehler Absturz") Break 2 ; Thread abschiessen EndIf - lhs_log::Out("Response Content:"+Response(#cha_R_ResponseContentType)) + ldl::Logging("Response Content:"+Response(#cha_R_ResponseContentType)) Select Response(#cha_R_ResponseContentType) Case #response_Memory - lhs_log::Out("Response Memory") + ldl::Logging("Response Memory") thread_data_size = Val(Response(#cha_R_MemorySize)) thread_temp_cache_memory = Val(Response(#cha_R_MemoryAdress)) thread_type = Response(#cha_R_ResponseType) Case #response_string - lhs_log::Out("Response String") + ldl::Logging("Response String") thread_temp_decode_memory = AllocateMemory(StringByteLength(Response(#cha_R_StringBase64))) thread_data_size = Base64Decoder(Response(#cha_R_StringBase64), thread_temp_decode_memory, StringByteLength(Response(#cha_R_StringBase64))) thread_temp_cache_memory = AllocateMemory(thread_data_size) @@ -695,56 +623,56 @@ Module lhs_web Default ;Solte ja nicht passieren. EndSelect - lhs_log::Out("Content Finished") + ldl::Logging("Content Finished") ;} - ElseIf configuration\cache\enable = 1 - ;{ Cached File Handling BUGGY!!!!!!! - thread_temp_cache_memory = AllocateMemory(1024) - thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory) - If thread_temp_cache = #error_string - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead) - - If thread_file_handle - ;Alles Ok - Else - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead) - lhs_log::Out("FileDir:" + configuration\basedir + configuration\defaultfile) - If Not thread_file_handle - thread_file_handle = ReadFile(#PB_Any, "error.html") - EndIf - - EndIf - thread_data_size = Lof(thread_file_handle) - thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size) - ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size) - CloseFile(thread_file_handle) - AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size) - - Else - thread_data_size = Val(StringField(thread_temp_cache, 1, ":")) - thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":")) - EndIf - ;} +; ElseIf configuration\cache\enable = 1 +; ;{ Cached File Handling BUGGY!!!!!!! +; thread_temp_cache_memory = AllocateMemory(1024) +; thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory) +; If thread_temp_cache = #error_string +; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead) +; +; If thread_file_handle +; ;Alles Ok +; Else +; thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead) +; ldl::Logging("FileDir:" + configuration\basedir + configuration\defaultfile) +; If Not thread_file_handle +; thread_file_handle = ReadFile(#PB_Any, "error.html") +; EndIf +; +; EndIf +; thread_data_size = Lof(thread_file_handle) +; thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size) +; ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size) +; CloseFile(thread_file_handle) +; AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size) +; +; Else +; thread_data_size = Val(StringField(thread_temp_cache, 1, ":")) +; thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":")) +; EndIf +; ;} Else ;{ Uncached file sems to be stable tested up to 200 clients and 100 requests. - If file_check(thread_requested) = thread_requested - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead) + If file_check(thread_requested, m_clients(Str(thread_cli_id))\host_id) = thread_requested + thread_file_handle = ReadFile(#PB_Any, home_dir + thread_requested,#PB_File_SharedRead) If Not thread_file_handle - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead) - lhs_log::Out("FileDir:" + configuration\basedir + configuration\defaultfile) + thread_file_handle = ReadFile(#PB_Any, home_dir + default_file ,#PB_File_SharedRead) + ldl::Logging("FileDir:" + home_dir + default_file, ErrorLog) If Not thread_file_handle - lhs_log::Out("Error file set") + ldl::Logging("Error file set", ErrorLog) thread_file_handle = ReadFile(#PB_Any, "error.html") EndIf EndIf thread_data_size = Lof(thread_file_handle) ; Is File bigger than MaxFileSize in Memory allowed ? - If thread_data_size >= configuration\mem\MaxFileSize + If thread_data_size >= configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize ;Do Handle the File another way. - thread_temp_cache_memory = AllocateMemory(configuration\mem\MaxFileSize) - thread_temp_file_readed = configuration\mem\DefaultBlockSize + thread_temp_cache_memory = AllocateMemory(configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize) + thread_temp_file_readed = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\DefaultBlockSize thread_data_readed = ReadData(thread_file_handle, thread_temp_cache_memory, thread_temp_file_readed) thread_data_to_read = thread_data_size - thread_data_readed thread_oversized_file = #True @@ -771,7 +699,7 @@ Module lhs_web ;* Current Finaly Implementet is only application/x-www-form-urlencoded ;* Error Handling must be Optimized. ;* - lhs_log::Out(#http_method_post) + ldl::Logging(#http_method_post) ;{ POST Content Type Decoder If LCase(Header(#http_head_content_type)) = #http_content_type_application_x_www_form_urlencoded @@ -783,7 +711,7 @@ Module lhs_web FreeJSON(MyThreadJSON) Else ;Should not be possible. - lhs_log::Out("Error in thread, JSON Convert didn't Work") + ldl::Logging("Error in thread, JSON Convert didn't Work") Break 2 ; Kill Thread EndIf ElseIf Left(LCase(Header(#http_head_content_type)), Len(#http_content_type_multipart_form_data)) = #http_content_type_multipart_form_data @@ -795,18 +723,18 @@ Module lhs_web FreeJSON(MyThreadJSON) Else ;Someting wrong in the POST - lhs_log::Out("Error with Content. JSON Convert didn't Work") + ldl::Logging("Error with Content. JSON Convert didn't Work") Break 2; Kill Thread EndIf EndIf ;} If Header(#http_head_request) = "/" - thread_requested = configuration\defaultfile + thread_requested = default_file Else thread_requested = Header(#http_head_request) EndIf - lhs_log::Out("Requested:"+thread_requested) + ldl::Logging("Requested:"+thread_requested) ToCallType = call_request(thread_requested, #get_handler_prototype) If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_post ToCall = call_request(thread_requested) @@ -819,15 +747,15 @@ Module lhs_web Select ToCallType Case #handler_proto_universal - Define.WebHandler_Universal ToCallProcedure = ToCall - Handler_Response = ToCallProcedure(Header(), PostMapString ) + Define.WebHandler_Universal ToCallProcedure_Universal = ToCall + Handler_Response = ToCallProcedure_Universal(Header(), PostMapString ) Case #handler_proto_post - Define.WebHandler_Post ToCallProcedure = ToCall - Handler_Response = ToCallProcedure(Header(), PostMapString) + Define.WebHandler_Post ToCallProcedure_Post = ToCall + Handler_Response = ToCallProcedure_Post(Header(), PostMapString) EndSelect - lhs_log::Out("Main Client Response :"+Handler_Response) + ldl::Logging("Main Client Response :"+Handler_Response) MyThreadJSON = ParseJSON(#PB_Any, Handler_Response) If MyThreadJSON ClearMap(Response()) @@ -835,10 +763,10 @@ Module lhs_web FreeJSON(MyThreadJSON) Else ;WTF ??? - lhs_log::Out("Fehler Absturz") + ldl::Logging("Fehler Absturz") Break 2 ; Thread abschiessen EndIf - lhs_log::Out("Response Content:"+Response(#cha_R_ResponseContentType)) + ldl::Logging("Response Content:"+Response(#cha_R_ResponseContentType)) Select Response(#cha_R_ResponseContentType) Case #response_Memory thread_data_size = Val(Response(#cha_R_MemorySize)) @@ -854,57 +782,57 @@ Module lhs_web Default ;Solte ja nicht passieren. EndSelect - lhs_log::Out("Content Finished") + ldl::Logging("Content Finished") ;} ElseIf conf_cache_enable = 1 - ;{ Cached File Handling BUGGY!!!!!!! - thread_temp_cache_memory = AllocateMemory(1024) - thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory) - If thread_temp_cache = #error_string - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead) - - If thread_file_handle - ;Alles Ok - Else - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead) - lhs_log::Out("FileDir:" + configuration\basedir + configuration\defaultfile) - If Not thread_file_handle - thread_file_handle = ReadFile(#PB_Any, "error.html") - EndIf - - EndIf - thread_data_size = Lof(thread_file_handle) - thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size) - ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size) - CloseFile(thread_file_handle) - AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size) - - Else - thread_data_size = Val(StringField(thread_temp_cache, 1, ":")) - thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":")) - EndIf - ;} +; ;{ Cached File Handling BUGGY!!!!!!! +; thread_temp_cache_memory = AllocateMemory(1024) +; thread_temp_cache = GetFileFromCache(thread_requested, thread_temp_cache_memory) +; If thread_temp_cache = #error_string +; thread_file_handle = ReadFile(#PB_Any, "srv/www" + thread_requested,#PB_File_SharedRead) +; +; If thread_file_handle +; ;Alles Ok +; Else +; thread_file_handle = ReadFile(#PB_Any, "srv/www" + "index.html",#PB_File_SharedRead) +; ldl::Logging("FileDir:" + "srv/www" + "index.html") +; If Not thread_file_handle +; thread_file_handle = ReadFile(#PB_Any, "error.html") +; EndIf +; +; EndIf +; thread_data_size = Lof(thread_file_handle) +; thread_temp_cache_memory = ReAllocateMemory(thread_temp_cache_memory, thread_data_size) +; ReadData(thread_file_handle, thread_temp_cache_memory, thread_data_size) +; CloseFile(thread_file_handle) +; AddFileToCache(thread_temp_cache_memory, thread_requested, thread_data_size) +; +; Else +; thread_data_size = Val(StringField(thread_temp_cache, 1, ":")) +; thread_temp_cache_memory = Val(StringField(thread_temp_cache, 2, ":")) +; EndIf +; ;} Else ;{ Uncached file sems to be stable tested up to 200 clients and 100 requests. - If file_check(thread_requested) = thread_requested - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead) + If file_check(thread_requested, m_clients(Str(thread_cli_id))\host_id) = thread_requested + thread_file_handle = ReadFile(#PB_Any, home_dir+ thread_requested,#PB_File_SharedRead) If Not thread_file_handle - thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead) - lhs_log::Out("FileDir:" + configuration\basedir + configuration\defaultfile) + thread_file_handle = ReadFile(#PB_Any, home_dir + default_file ,#PB_File_SharedRead) + ldl::Logging("FileDir:" + home_dir + default_file) If Not thread_file_handle - lhs_log::Out("Error file set") + ldl::Logging("Error file set") thread_file_handle = ReadFile(#PB_Any, "error.html") EndIf EndIf thread_data_size = Lof(thread_file_handle) ; Is File bigger than MaxFileSize in Memory allowed ? - If thread_data_size >= configuration\mem\MaxFileSize + If thread_data_size >= configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize ;Do Handle the File another way. - thread_temp_cache_memory = AllocateMemory(configuration\mem\MaxFileSize) - thread_temp_file_readed = configuration\mem\DefaultBlockSize + thread_temp_cache_memory = AllocateMemory(configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\MaxFileSize) + thread_temp_file_readed = configuration\hosts(m_clients(Str(thread_cli_id))\host_id)\mem\DefaultBlockSize thread_data_readed = ReadData(thread_file_handle, thread_temp_cache_memory, thread_temp_file_readed) thread_data_to_read = thread_data_size - thread_data_readed thread_oversized_file = #True @@ -951,14 +879,14 @@ Module lhs_web ElseIf response_status <> "" Header(#http_head_status) = response_status Else - Header(#http_head_status) = "200 OK" + Header(#http_head_status) = status_get_message("200") EndIf If Response(#http_head_set_cookie) <> "" Header(#http_head_set_cookie) = Response(#http_head_set_cookie) EndIf If thread_redirect = #True - Header(#http_head_redirect) = file_check(thread_requested) - Header(#http_head_status) = "303 See Other" + Header(#http_head_redirect) = file_check(thread_requested, m_clients(Str(thread_cli_id))\host_id) + Header(#http_head_status) = status_get_message("303") Else Header(#http_head_content_length) = Str(thread_data_size) Header(#http_head_content_type) = thread_type @@ -978,33 +906,33 @@ Module lhs_web thread_buffer_offset = thread_buffer thread_buffer_length = PokeS(thread_buffer_offset, thread_header,-1, #PB_UTF8|#PB_String_NoZero) : thread_buffer_offset + thread_buffer_length - lhs_log::Out("Header Finished") + ldl::Logging("Header Finished") EndIf ;Copy temporary File Buffer to normal Buffer. If thread_temp_cache_memory <> 0 And thread_buffer_offset <> 0 And thread_data_size <> 0 And thread_oversized_file = #False And thread_redirect = #False CopyMemory(thread_temp_cache_memory, thread_buffer_offset, thread_data_size) - lhs_log::Out("Cache Address Memory:"+Str(thread_temp_cache_memory)) + ldl::Logging("Cache Address Memory:"+Str(thread_temp_cache_memory)) FreeMemory(thread_temp_cache_memory) thread_temp_cache_memory = 0 ElseIf thread_temp_cache_memory <> 0 And thread_buffer_offset <> 0 And thread_data_size <> 0 And thread_temp_file_readed <> 0 And thread_oversized_file = #True And thread_redirect = #False CopyMemory(thread_temp_cache_memory, thread_buffer_offset, thread_temp_file_readed) - lhs_log::Out("Cache Address Memory:"+Str(thread_temp_cache_memory)) + ldl::Logging("Cache Address Memory:"+Str(thread_temp_cache_memory)) FreeMemory(thread_temp_cache_memory) thread_temp_cache_memory = 0 ElseIf thread_redirect = #True thread_redirect = #False Else - lhs_log::Out("File Buffer Troubles.") - If thread_temp_cache_memory = 0 : lhs_log::Out("thread_temp_cache_memory = 0") : EndIf - If thread_buffer_offset = 0 : lhs_log::Out("thread_buffer_offset = 0") : EndIf - If thread_data_size = 0 : lhs_log::Out("thread_data_size = 0") : EndIf + ldl::Logging("File Buffer Troubles.") + If thread_temp_cache_memory = 0 : ldl::Logging("thread_temp_cache_memory = 0") : EndIf + If thread_buffer_offset = 0 : ldl::Logging("thread_buffer_offset = 0") : EndIf + If thread_data_size = 0 : ldl::Logging("thread_data_size = 0") : EndIf thread_alive = #False Break 2 EndIf ; EndIf - lhs_log::Out("HTTP File Buffer Cleaned.") + ldl::Logging("HTTP File Buffer Cleaned.") ;Löschen des eingang Speichers. If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer > 0 FreeMemory(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer) @@ -1026,9 +954,9 @@ Module lhs_web sent_buffer_address = thread_buffer sent_total = 0 Repeat - sent = ltls::WriteTLSSocket(thread_cli_id, sent_buffer_address , sent_length) + sent = tls::WriteTLSSocket(thread_cli_id, sent_buffer_address , sent_length) If sent <> -1 - ;lhs_log::Out("ClientID:" + Str(thread_cli_id) + " HTTPS Sent:"+Str(sent)+" bytes") + ;ldl::Logging("ClientID:" + Str(thread_cli_id) + " HTTPS Sent:"+Str(sent)+" bytes") sent_length - sent If thread_oversized_file = #False sent_buffer_address + sent @@ -1036,14 +964,14 @@ Module lhs_web ;Read next Block to Memory If sent_length <= 0 And IsFile(thread_file_handle) sent_readed = ReadData(thread_file_handle, thread_buffer, thread_temp_file_readed) - ;lhs_log::Out("ClientID:" + Str(thread_cli_id) + " HTTPS Large File -> Read Next:"+Str(sent_readed)+" bytes") + ;ldl::Logging("ClientID:" + Str(thread_cli_id) + " HTTPS Large File -> Read Next:"+Str(sent_readed)+" bytes") If sent_readed < thread_temp_file_readed CloseFile(thread_file_handle) EndIf sent_buffer_address = thread_buffer sent_length = sent_readed Else - ;lhs_log::Out("ClientID:" + Str(thread_cli_id) + " HTTPS Large File -> to Send:"+Str(sent_length)+" bytes") + ;ldl::Logging("ClientID:" + Str(thread_cli_id) + " HTTPS Large File -> to Send:"+Str(sent_length)+" bytes") sent_buffer_address + sent EndIf EndIf @@ -1054,7 +982,7 @@ Module lhs_web CloseFile(thread_file_handle) EndIf - lhs_log::Out("HTTPS Sent error:"+ltls::ErrorTLSCli(thread_cli_id)) + ldl::Logging("HTTPS Sent error:"+tls::ErrorTLSCli(thread_cli_id)) thread_alive = #False Break 2 EndIf @@ -1069,7 +997,7 @@ Module lhs_web Repeat sent = lsocket::WriteSocket(thread_cli_id, thread_buffer , sent_length) If sent <> -1 - lhs_log::Out("HTTP Sent:"+Str(sent)+" bytes") + ldl::Logging("HTTP Sent:"+Str(sent)+" bytes") sent_length - sent If thread_oversized_file = 0 sent_buffer_address + sent @@ -1093,7 +1021,7 @@ Module lhs_web CloseFile(thread_file_handle) EndIf - lhs_log::Out("HTTP Sent error:"+Str(sent)) + ldl::Logging("HTTP Sent error:"+Str(sent)) thread_alive = #False Break 2 EndIf @@ -1104,7 +1032,7 @@ Module lhs_web If sent = thread_data_size+(thread_buffer_offset-thread_buffer) ;Ok - ;lhs_log::Out("Gesendet:" + PeekS(thread_buffer,thread_buffer_length, #PB_Ascii)) + ;ldl::Logging("Gesendet:" + PeekS(thread_buffer,thread_buffer_length, #PB_Ascii)) If thread_buffer > 0 FreeMemory(thread_buffer) EndIf @@ -1113,7 +1041,7 @@ Module lhs_web m_clients(Str(thread_cli_id))\client_do_srv = #SRV_DO_DataReceive Else ;Fehler beim Senden ... Thread beenden. - lhs_log::Out("Fehler:" + Str(Sent)) + ldl::Logging("Fehler:" + Str(Sent)) thread_alive = #False EndIf @@ -1129,35 +1057,35 @@ Module lhs_web ;} Until thread_alive = #False - lhs_log::Out("Thread should now die...") + ldl::Logging("Thread should now die...") ResetList(m_clients(Str(thread_cli_id))\datenbuffer()) - lhs_log::Out("Thread kill all Initialized Memory buffers:") + ldl::Logging("Thread kill all Initialized Memory buffers:") While NextElement(m_clients(Str(thread_cli_id))\datenbuffer()) If m_clients(Str(thread_cli_id))\datenbuffer()\Initialized - lhs_log::Out("Kill:"+Str(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)+ " ...") + ldl::Logging("Kill:"+Str(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)+ " ...") FreeMemory(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer) DeleteElement(m_clients(Str(thread_cli_id))\datenbuffer()) - lhs_log::Out("Freed and removed") + ldl::Logging("Freed and removed") Else - lhs_log::Out("Remove element from List with uninitialized Memory ID: "+Str(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)) + ldl::Logging("Remove element from List with uninitialized Memory ID: "+Str(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)) DeleteElement(m_clients(Str(thread_cli_id))\datenbuffer()) - lhs_log::Out("Removed") + ldl::Logging("Removed") EndIf Wend If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS - lhs_log::Out("Kill HTTPS Socket:" + Str(thread_cli_id)) - ;ltls::CloseTLSSocket(thread_cli_id) + ldl::Logging("Kill HTTPS Socket:" + Str(thread_cli_id)) + ;tls::CloseTLSSocket(thread_cli_id) count_client(#client_HTTPS, #client_remove) - lhs_log::Out("Killed.") + ldl::Logging("Killed.") Else - lhs_log::Out("Kill HTTP Socket:" + Str(thread_cli_id)) + ldl::Logging("Kill HTTP Socket:" + Str(thread_cli_id)) lsocket::CloseSocket(thread_cli_id) count_client(#client_HTTP, #client_remove) - lhs_log::Out("Killed.") + ldl::Logging("Killed.") EndIf - lhs_log::Out("Remove Client from map...") + ldl::Logging("Remove Client from map...") DeleteMapElement(m_clients(), Str(thread_cli_id)) - lhs_log::Out("Removed and thread now died.") + ldl::Logging("Removed and thread now died.") EndProcedure @@ -1239,7 +1167,7 @@ Module lhs_web Count = 0 Repeat Posts(StringField(StringField(ContentString, Count + 1, "&"),1,"=")) = StringField(StringField(ContentString, Count + 1, "&"),2,"=") - ;lhs_log::Out("Worked Count:"+Str(Count)+" of: "+Str(CountParams)+":"+StringField(StringField(ContentString, Count + 1, "&"),1,"=")+" = "+StringField(StringField(ContentString, Count + 1, "&"),2,"=") + ;ldl::Logging("Worked Count:"+Str(Count)+" of: "+Str(CountParams)+":"+StringField(StringField(ContentString, Count + 1, "&"),1,"=")+" = "+StringField(StringField(ContentString, Count + 1, "&"),2,"=") Count + 1 Until Count > CountParams Else @@ -1273,7 +1201,7 @@ Module lhs_web m_request(Route)\type = AppPrototype m_request(Route)\call = Callback m_request(Route)\routetype = RouteType - lhs_log::Out("Handler Registriert:"+Route) + lhs_log_ext::OutL(lhs_web::get_config(lhs_web::#conf_Debug_logUUID),lhs_log_ext::#Debugging,"Handler Registriert:"+Route) EndProcedure Procedure count_client(Type.i, Countchange.i) @@ -1289,19 +1217,21 @@ Module lhs_web EndSelect EndProcedure - Procedure.s file_check(thread_requested.s) + Procedure.s file_check(thread_requested.s, hostid.s) Protected file_type.i - file_type = FileSize(configuration\basedir + thread_requested) + Debug thread_requested + file_type = FileSize(configuration\hosts(hostid)\basedir + thread_requested) If file_type = -1 - thread_requested = configuration\errorfile404 + thread_requested = "configuration\errorfile404" ElseIf file_type = -2 ;Is a Directory If Right(thread_requested,1) = "/" - thread_requested = thread_requested + configuration\defaultfile + thread_requested = thread_requested + "index.html" Else - thread_requested = thread_requested + "/" + configuration\defaultfile + thread_requested = thread_requested + "/" + "index.html" EndIf EndIf + Debug "Final:"+thread_requested ProcedureReturn thread_requested.s EndProcedure