diff --git a/inc/lweb_file_cache.pbi b/inc/lweb_file_cache.pbi
index 3bb0c57..53e337d 100644
--- a/inc/lweb_file_cache.pbi
+++ b/inc/lweb_file_cache.pbi
@@ -16,7 +16,7 @@ Procedure FileCacheCleaner(Information.i)
m_file_cache(MapKey(m_file_cache_map()))\Timer - 1
If m_file_cache(MapKey(m_file_cache_map()))\Timer <= 0
If m_file_cache(MapKey(m_file_cache_map()))\Buffer > 0
- conf_cache_current - m_file_cache(MapKey(m_file_cache_map()))\Size
+ configuration\cache\current - m_file_cache(MapKey(m_file_cache_map()))\Size
FreeMemory(m_file_cache(MapKey(m_file_cache_map()))\Buffer)
DeleteMapElement(m_file_cache(), MapKey(m_file_cache_map()))
Debug "Info:["+Str(innercount)+"] Killed:["+MapKey(m_file_cache_map())+"]"
@@ -41,18 +41,18 @@ Procedure FileCache(Information.i)
;http://purearea.net/pb/english/manual/reference/ug_memory.html
Protected FileCacheCleanerThread.i
Protected Tempbuffer.i, MaxSize.i, Current.i
- MaxSize = conf_cache_maxsize * 1024 * 1024
+ MaxSize = configuration\cache\maxsize * 1024 * 1024
FileCacheCleanerThread = CreateThread(@FileCacheCleaner(), MaxSize)
Repeat
WaitSemaphore(file_cache_semaphore)
Debug "Adresse:"+m_file_cache()\Buffer
- If (m_file_cache()\Size + conf_cache_current) <= MaxSize
- conf_cache_current + m_file_cache()\Size
+ If (m_file_cache()\Size + configuration\cache\current) <= MaxSize
+ configuration\cache\current + m_file_cache()\Size
Tempbuffer = AllocateMemory(m_file_cache()\Size)
CopyMemory(m_file_cache()\Buffer, Tempbuffer, MemorySize(m_file_cache()\Buffer))
m_file_cache()\Buffer = Tempbuffer
- m_file_cache()\Timer = conf_cache_time
+ m_file_cache()\Timer = configuration\cache\time
m_file_cache()\Is = #True
m_file_cache_map(MapKey(m_file_cache())) = #True
SignalSemaphore(file_cache_semaphore_thread)
@@ -66,7 +66,7 @@ EndProcedure
Procedure AddFileToCache(MemoryID.i, FileName.s, Size.i)
LockMutex(file_cache_mutex)
- Debug "Cache MaxSize:"+Str(conf_cache_maxsize*1024*1024)+" Actual Size:"+Str(conf_cache_current)
+ Debug "Cache MaxSize:"+Str(configuration\cache\maxsize*1024*1024)+" Actual Size:"+Str(configuration\cache\current)
m_file_cache(FileName)\Buffer = MemoryID
m_file_cache(FileName)\Size = Size
SignalSemaphore(file_cache_semaphore)
@@ -74,7 +74,7 @@ Procedure AddFileToCache(MemoryID.i, FileName.s, Size.i)
If m_file_cache(FileName)\Is
Debug FileName+" Size:"+Str(m_file_cache(FileName)\Size)+" Timer:"+Str(m_file_cache(FileName)\Timer)+ " new Memory ID:"+Str(m_file_cache(FileName)\Buffer)
Else
- Debug "File not in cache was to full:"+FileName+ " MaxSize:"+Str(conf_cache_maxsize)+" Actual Size:"+Str(conf_cache_current/1024/1024)
+ Debug "File not in cache was to full:"+FileName+ " MaxSize:"+Str(configuration\cache\maxsize)+" Actual Size:"+Str(configuration\cache\current/1024/1024)
EndIf
UnlockMutex(file_cache_mutex)
diff --git a/inc/lweb_http.pbi b/inc/lweb_http.pbi
index d2cc538..5ddc4d5 100644
--- a/inc/lweb_http.pbi
+++ b/inc/lweb_http.pbi
@@ -61,7 +61,7 @@
Str(Year(Date())) +
" " +
FormatDate("%hh:%ii:%ss GMT+1", Date()) : EndIf
- If Not FindMapElement(Header(), #http_head_server) : Header(#http_head_server) = conf_titel : EndIf
+ If Not FindMapElement(Header(), #http_head_server) : Header(#http_head_server) = configuration\identifikation : EndIf
If Not FindMapElement(Header(), #http_head_content_length) : Header(#http_head_content_length) = "0" : EndIf
If Not FindMapElement(Header(), #http_head_content_type) : Header(#http_head_content_type) = "text/txt" : EndIf
diff --git a/lhttpd.pb b/lhttpd.pb
index b653c9d..4709045 100644
--- a/lhttpd.pb
+++ b/lhttpd.pb
@@ -50,9 +50,11 @@ EndIf
;*
If lhs_web::start_server()
- lhs_log::Out("Server gestartet" + lhs_web::get_config(lhs_web::#conf_port)
+ lhs_log::Out("Server started:")
+ lhs_log::Out("HTTP Port:"+ lhs_web::get_config(lhs_web::#conf_HTTP_port)
+ lhs_log::Out("HTTPS Port:"+ lhs_web::get_config(lhs_web::#conf_HTTPS_port)
Else
- lhs_log::Out("Fehlgeschlagen"
+ lhs_log::Out("Serverstart failed."
End
EndIf
diff --git a/lweb.pbi b/lweb.pbi
index 2d9f9de..2d78008 100644
--- a/lweb.pbi
+++ b/lweb.pbi
@@ -17,37 +17,85 @@ Module lhs_web
;* WebServer Variabeln / Parameter
;*
;{
-
+
+ ;*
+ ;* 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 server
+ http.server_http
+ https.server_https
+ cache.server_cache
+ version.s
+ identifikation.s
+ defaultfile.s
+ basedir.s
+ error400.s
+ type.i
+ EndStructure
+ ;}
+ ;*
+
;*
;* Identifikation des Servers.
;*
-
- Global.s conf_version = "V0.9"
- Global.s conf_titel = "LiHaSo Webserver " + conf_version
+
+ Global configuration.server
+ configuration\version = "V0.9"
+ configuration\identifikation = "LiHaSo Webserver " + configuration\version
;*
;* 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.
- Global.s conf_defaultfile = "index.html"
- Global.s conf_basedir = "/srv/lweb-srv/"
- Global.s conf_error400 = "integrated" ; Kann "integrated" sein wass die integrierte Standard Fehlermeldung hervorruft.
- Global.i conf_max_HTTP_clients = 10 ; Max sametime HTTP connections.
- Global.i conf_max_HTTPS_clients = 100 ; Max sametime HTTPS connections.
- Global.i conf_server_type = 0
- Global.i conf_HTTP_port = 8080
- Global.s conf_HTTP_binding = "127.0.0.1"
- Global.i conf_cache_time = 120 ;120Sekunden
- Global.i conf_cache_maxsize = 1 ;1 Mbyte
- Global.i conf_cache_current = 0
- Global.i conf_cache_enable = 0
- Global.i conf_HTTPS_Port = 8443
- Global.s conf_HTTPS_binding = "127.0.0.1"
- Global.i conf_HTTPS_enable = 0 ;SSL Server
- Global.s conf_HTTPS_CA = ""
- Global.s conf_HTTPS_Cert = ""
- Global.s conf_HTTPS_Key = ""
- Global.s conf_HTTPS_Key_Pass = ""
+ configuration\defaultfile = "index.html"
+ configuration\basedir = "/srv/lweb-srv/"
+ configuration\error400 = "integrated" ; Kann "integrated" sein wass die integrierte Standard Fehlermeldung hervorruft.
+ configuration\type = 0
+
+ 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 ;
+
Enumeration s_client_do ;client_do_cli
#CLI_DO_NOP ;Keine Arbeit
@@ -143,7 +191,7 @@ 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(conf_max_HTTP_clients+conf_max_HTTPS_clients)
+ Global NewMap m_clients.s_clients(configuration\http\max_clients+configuration\https\max_clients)
Global NewMap m_request.s_request_handler()
;}
@@ -189,57 +237,57 @@ Module lhs_web
Procedure set_config(parameter.i=#conf_defaultfile, setting.s="index.html")
Select parameter
Case #conf_HTTP_port
- conf_HTTP_port = Val(setting)
+ configuration\http\port = Val(setting)
Case #conf_HTTPS_Port
- conf_HTTPS_Port = Val(setting)
+ configuration\https\port = Val(setting)
Case #conf_HTTP_binding
If IsIPStringValid(setting)
- conf_HTTP_binding = setting
+ configuration\http\binding = setting
Else
- conf_HTTP_binding = "127.0.0.1"
+ configuration\http\binding = "127.0.0.1"
ProcedureReturn #False
EndIf
Case #conf_HTTPS_Binding
If IsIPStringValid(setting)
- conf_HTTP_binding = setting
+ configuration\https\binding = setting
Else
- conf_HTTP_binding = "127.0.0.1"
+ configuration\https\binding = "127.0.0.1"
ProcedureReturn #False
EndIf
Case #conf_HTTPS_CA
- conf_HTTPS_CA = setting
+ configuration\https\CA = setting
Case #conf_HTTPS_Cert
- conf_HTTPS_Cert = setting
+ configuration\https\Certs = setting
Case #conf_HTTPS_Key
- conf_HTTPS_Key = setting
+ configuration\https\Key = setting
Case #conf_HTTPS_Key_Pass
- conf_HTTPS_Key_Pass = setting
+ configuration\https\key_pass = setting
Case #conf_HTTPS_Enable
- conf_HTTPS_enable = Val(setting)
+ configuration\https\enabled = Val(setting)
Case #conf_defaultfile
- conf_defaultfile = setting
+ configuration\defaultfile = setting
Case #conf_basedir
- conf_basedir = setting
+ configuration\basedir = setting
Case #conf_error400
- conf_error400 = setting ; Kann "integrated" sein wass die integrierte Standard Fehlermeldung hervorruft.
+ 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))
- conf_max_HTTP_clients = Val(setting)
+ configuration\http\max_clients = Val(setting)
Else
- conf_max_HTTP_clients = 10
+ configuration\http\max_clients = 10
ProcedureReturn #False
EndIf
Case #conf_max_HTTPS_clients
If MemoryStatus(#PB_System_FreePhysical) > (Val(setting)*(1024*384))
- conf_max_HTTPS_clients = Val(setting)
+ configuration\https\max_clients = Val(setting)
Else
- conf_max_HTTPS_clients = 10
+ configuration\https\max_clients = 10
ProcedureReturn #False
EndIf
Case #conf_server_type
- conf_server_type = Val(setting)
+ configuration\type = Val(setting)
Case #conf_cache_enable
- conf_cache_enable = Val(Setting)
+ configuration\cache\enable = Val(Setting)
Default
ProcedureReturn #False
EndSelect
@@ -249,34 +297,34 @@ Module lhs_web
Procedure.s get_config(parameter.i=#conf_defaultfile)
Select parameter
Case #conf_defaultfile
- ProcedureReturn conf_defaultfile
+ ProcedureReturn configuration\defaultfile
Case #conf_basedir
- ProcedureReturn conf_basedir
+ ProcedureReturn configuration\basedir
Case #conf_error400
- ProcedureReturn conf_error400
+ ProcedureReturn configuration\error400
Case #conf_max_HTTP_clients
- ProcedureReturn Str(conf_max_HTTP_clients)
+ ProcedureReturn Str(configuration\http\max_clients)
Case #conf_server_type
- ProcedureReturn Str(conf_server_type)
+ ProcedureReturn Str(configuration\type)
Case #conf_HTTP_port
- ProcedureReturn Str(conf_HTTP_port)
+ ProcedureReturn Str(configuration\http\port)
Case #conf_HTTPS_Port
- ProcedureReturn Str(conf_HTTPS_Port)
+ ProcedureReturn Str(configuration\https\port)
Default
ProcedureReturn ""
EndSelect
EndProcedure
Procedure start_server()
- Global NewMap m_clients.s_clients(conf_max_HTTP_clients+conf_max_HTTPS_clients)
+ Global NewMap m_clients.s_clients(configuration\http\max_clients+configuration\https\max_clients)
Protected tlsresponse.i
;Init HTTP Socket
- server_HTTP_id = lsocket::CreateSocket(conf_HTTP_port, conf_max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, conf_HTTP_binding)
- If conf_HTTPS_enable = 1
- server_HTTPS_id = lsocket::CreateSocket(conf_HTTPS_Port, conf_max_clients, lsocket::#SOCK_STREAM, lsocket::#AF_INET, conf_HTTPS_binding)
+ 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(conf_HTTPS_CA, conf_HTTPS_Cert, conf_HTTPS_Key, conf_HTTPS_Key_Pass)
+ 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
@@ -314,7 +362,7 @@ Module lhs_web
If m_clients(Str(client_id))\client_id = client_id
lhs_log::Out("Client Thread for socket already exist :"+Str(client_id))
Else
- If count_HTTPS_client < conf_max_HTTPS_clients
+ If count_HTTPS_client < configuration\https\max_clients
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
@@ -351,7 +399,7 @@ Module lhs_web
If m_clients(Str(client_id))\client_id = client_id
lhs_log::Out("Client Thread for socket already exist :"+Str(client_id))
Else
- If count_HTTP_client < conf_max_HTTP_clients
+ If count_HTTP_client < configuration\http\max_clients
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
@@ -465,7 +513,7 @@ Module lhs_web
;Change Thread to Work mode.
;{
- lhs_log::Out("Date received, working...")
+ lhs_log::Out("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())
@@ -505,7 +553,7 @@ Module lhs_web
;{
lhs_log::Out(#http_method_get)
If Header(#http_head_request) = "/"
- thread_requested = conf_defaultfile
+ thread_requested = configuration\defaultfile
Else
thread_requested = Header(#http_head_request)
EndIf
@@ -562,18 +610,18 @@ Module lhs_web
lhs_log::Out("Content Finished")
;}
- ElseIf conf_cache_enable = 1
+ 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, conf_basedir + thread_requested,#PB_File_SharedRead)
+ 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, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
- lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
+ 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
@@ -593,10 +641,10 @@ Module lhs_web
Else
;{ Uncached file sems to be stable tested up to 200 clients and 100 requests.
- thread_file_handle = ReadFile(#PB_Any, conf_basedir + thread_requested,#PB_File_SharedRead)
+ thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead)
If Not thread_file_handle
- thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
- lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
+ 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
@@ -650,7 +698,7 @@ Module lhs_web
;}
If Header(#http_head_request) = "/"
- thread_requested = conf_defaultfile
+ thread_requested = configuration\defaultfile
Else
thread_requested = Header(#http_head_request)
EndIf
@@ -710,13 +758,13 @@ Module lhs_web
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, conf_basedir + thread_requested,#PB_File_SharedRead)
+ 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, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
- lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
+ 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
@@ -736,10 +784,10 @@ Module lhs_web
Else
;{ Uncached file sems to be stable tested up to 200 clients and 100 requests.
- thread_file_handle = ReadFile(#PB_Any, conf_basedir + thread_requested,#PB_File_SharedRead)
+ thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead)
If Not thread_file_handle
- thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
- lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
+ 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
@@ -753,16 +801,16 @@ Module lhs_web
EndIf
If Header(#http_head_request) = "/"
- thread_requested = conf_defaultfile
+ thread_requested = configuration\defaultfile
Else
thread_requested = Header(#http_head_request)
EndIf
- thread_file_handle = ReadFile(#PB_Any, conf_basedir + thread_requested,#PB_File_SharedRead)
+ thread_file_handle = ReadFile(#PB_Any, configuration\basedir + thread_requested,#PB_File_SharedRead)
If Not thread_file_handle
- thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
- lhs_log::Out("FileDir:" + conf_basedir + thread_requested)
+ thread_file_handle = ReadFile(#PB_Any, configuration\basedir + configuration\defaultfile,#PB_File_SharedRead)
+ lhs_log::Out("FileDir:" + configuration\basedir + thread_requested)
If Not thread_file_handle
thread_file_handle = ReadFile(#PB_Any, "error.html")
EndIf
diff --git a/lweb.pbp b/lweb.pbp
index 6c927ac..557915d 100644
--- a/lweb.pbp
+++ b/lweb.pbp
@@ -8,7 +8,7 @@
@@ -37,15 +37,23 @@
-
+
+
+
+
+
+
+
+
+
-
+
@@ -53,19 +61,19 @@
-
+
-
+
-
+
-
+
diff --git a/server_example.pb b/server_example.pb
index cfb8d93..e76b3a8 100644
--- a/server_example.pb
+++ b/server_example.pb
@@ -2,7 +2,7 @@
;*
;* Lihaso Web Server
;*
-;* HTTP/HTTPS Server Beispiel
+;* HTTP/HTTPS example extended Server
;*
;* (c)2015 - 2021 by Linder Hard- und Software
;*
@@ -11,7 +11,7 @@
EnableExplicit
;*
-;* Deklaration Variabeln
+;* Includes:
;*
XIncludeFile "lhs_lib/SYS/lhs_log.pbi" ;Currently for Debugging
@@ -19,15 +19,29 @@ XIncludeFile "lhs_lib/SYS/lhs_log_ext.pbi" ;User for Access Log, Error Access
XIncludeFile "lweb_header.pbi"
XIncludeFile "lweb.pbi"
+;*
+;* Variable declaration:
+;*
+
Define counter, v_lweb_srv_stop
+Define Accesslog.s
+
+;*
+;* Basic Debug Log initialization:
+;*
lhs_log::App_Name = "http-s_server_example"
-lhs_log::SetLogFile("http-s_server_example.log")
+lhs_log::SetLogFile("http-s_server_example_debug.log")
lhs_log::SetMaxSize(32)
lhs_log::SetLogDateFormat("%yyyy.%mm.%dd %hh:%ii:%ss")
lhs_log::SetLogFileDateFormat("%yyyy_%mm_%dd_%hh_%ii_%ss")
lhs_log::Init()
+;*
+;* Enable extended Logging:
+;*
+Accesslog = lhs_log_ext::Create("Accesslog")
+
lhs_web::set_config(lhs_web::#conf_HTTP_port, "8081")
;lhs_web::set_config(lhs_web::#conf_binding, "127.0.0.1")
lhs_web::set_config(lhs_web::#conf_HTTP_binding, "0.0.0.0")