Debug change to lhs_log and Empty multiform
This commit is contained in:
parent
07c55b77b6
commit
dcfd676a55
7 changed files with 149 additions and 104 deletions
|
@ -15,15 +15,15 @@ Procedure IsIPStringValid(Adress.s)
|
||||||
My_Regex_v6_compress = CreateRegularExpression(#PB_Any, "^(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,5})?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,5})?)$")
|
My_Regex_v6_compress = CreateRegularExpression(#PB_Any, "^(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,5})?)::(([0-9A-Fa-f]{1,4}(:[0-9A-Fa-f]{1,4}){0,5})?)$")
|
||||||
|
|
||||||
If MatchRegularExpression(My_Regex_v4, Adress) And Valid = 0
|
If MatchRegularExpression(My_Regex_v4, Adress) And Valid = 0
|
||||||
Debug "My_Regex_v4"
|
lhs_log::Out("My_Regex_v4")
|
||||||
Valid = 1
|
Valid = 1
|
||||||
EndIf
|
EndIf
|
||||||
If MatchRegularExpression(My_Regex_v6_nocompress, Adress) And Valid = 0
|
If MatchRegularExpression(My_Regex_v6_nocompress, Adress) And Valid = 0
|
||||||
Debug "My_Regex_v6_nocompress"
|
lhs_log::Out("My_Regex_v6_nocompress")
|
||||||
Valid = 1
|
Valid = 1
|
||||||
EndIf
|
EndIf
|
||||||
If MatchRegularExpression(My_Regex_v6_compress, Adress) And Valid = 0
|
If MatchRegularExpression(My_Regex_v6_compress, Adress) And Valid = 0
|
||||||
Debug "My_Regex_v6_compress"
|
lhs_log::Out("My_Regex_v6_compress")
|
||||||
Valid = 1
|
Valid = 1
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
|
|
@ -50,9 +50,9 @@ EndIf
|
||||||
;*
|
;*
|
||||||
|
|
||||||
If lhs_web::start_server()
|
If lhs_web::start_server()
|
||||||
Debug "Server gestartet" + lhs_web::get_config(lhs_web::#conf_port)
|
lhs_log::Out("Server gestartet" + lhs_web::get_config(lhs_web::#conf_port)
|
||||||
Else
|
Else
|
||||||
Debug "Fehlgeschlagen"
|
lhs_log::Out("Fehlgeschlagen"
|
||||||
End
|
End
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
|
32
ltls.pbi
32
ltls.pbi
|
@ -61,8 +61,22 @@ Module ltls
|
||||||
|
|
||||||
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
|
CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
|
||||||
Define libressl_tls = OpenLibrary(#PB_Any, "/usr/lib64/libtls.so.20")
|
Define libressl_tls = OpenLibrary(#PB_Any, "/usr/lib64/libtls.so.20")
|
||||||
|
If Not IsLibrary(libressl_tls)
|
||||||
|
Define libressl_tls = OpenLibrary(#PB_Any, "/usr/lib64/libtls.so.17")
|
||||||
|
If Not IsLibrary(libressl_tls)
|
||||||
|
lhs_log::Out("Library not found: /usr/lib64/libtls.so.20 or .17")
|
||||||
|
End
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
CompilerElse
|
CompilerElse
|
||||||
Define libressl_tls = OpenLibrary(#PB_Any, "/usr/lib/libtls.so.20")
|
Define libressl_tls = OpenLibrary(#PB_Any, "/usr/lib/libtls.so.20")
|
||||||
|
If Not IsLibrary(libressl_tls)
|
||||||
|
Define libressl_tls = OpenLibrary(#PB_Any, "/usr/lib/libtls.so.17")
|
||||||
|
If Not IsLibrary(libressl_tls)
|
||||||
|
lhs_log::Out("Library not found: /usr/lib/libtls.so.20 or .17")
|
||||||
|
End
|
||||||
|
EndIf
|
||||||
|
EndIf
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
||||||
|
|
||||||
|
@ -85,7 +99,7 @@ Module ltls
|
||||||
Define Call_tls_free = GetFunction(libressl_tls, "tls_free")
|
Define Call_tls_free = GetFunction(libressl_tls, "tls_free")
|
||||||
Define Call_tls_config_free = GetFunction(libressl_tls, "tls_config_free")
|
Define Call_tls_config_free = GetFunction(libressl_tls, "tls_config_free")
|
||||||
Else
|
Else
|
||||||
Debug "libtls.so Library Not found"
|
lhs_log::Out("libtls.so Library Not found")
|
||||||
End
|
End
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
@ -128,32 +142,32 @@ Module ltls
|
||||||
Protected mem_ptr.i, length.i, returns.i
|
Protected mem_ptr.i, length.i, returns.i
|
||||||
If tls_init() <> 0 : ProcedureReturn -1 : EndIf
|
If tls_init() <> 0 : ProcedureReturn -1 : EndIf
|
||||||
tls_cfg = tls_config_new()
|
tls_cfg = tls_config_new()
|
||||||
Debug "TLS cfg obj:"+Str(tls_cfg)
|
lhs_log::Out("TLS cfg obj:"+Str(tls_cfg))
|
||||||
Debug "CA:"+*Settings\CA
|
lhs_log::Out("CA:"+*Settings\CA)
|
||||||
mem_ptr = tls_load_file(*Settings\CA, @length)
|
mem_ptr = tls_load_file(*Settings\CA, @length)
|
||||||
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -2 : EndIf
|
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -2 : EndIf
|
||||||
tls_config_set_ca_mem(tls_cfg, mem_ptr, length)
|
tls_config_set_ca_mem(tls_cfg, mem_ptr, length)
|
||||||
Debug "Cert:"+*Settings\Cert
|
lhs_log::Out("Cert:"+*Settings\Cert)
|
||||||
mem_ptr = tls_load_file(*Settings\Cert, @length)
|
mem_ptr = tls_load_file(*Settings\Cert, @length)
|
||||||
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -3 : EndIf
|
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -3 : EndIf
|
||||||
tls_config_set_cert_mem(tls_cfg, mem_ptr, length)
|
tls_config_set_cert_mem(tls_cfg, mem_ptr, length)
|
||||||
If Len(*Settings\Password) > 0
|
If Len(*Settings\Password) > 0
|
||||||
Debug "Key:"+*Settings\Key + " Password:"+*Settings\Password
|
lhs_log::Out("Key:"+*Settings\Key + " Password:"+*Settings\Password)
|
||||||
mem_ptr = tls_load_file_pw(*Settings\Key, @length, *Settings\Password)
|
mem_ptr = tls_load_file_pw(*Settings\Key, @length, *Settings\Password)
|
||||||
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -4 : EndIf
|
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -4 : EndIf
|
||||||
tls_config_set_key_mem(tls_cfg, mem_ptr, length)
|
tls_config_set_key_mem(tls_cfg, mem_ptr, length)
|
||||||
Else
|
Else
|
||||||
Debug "Key:"+*Settings\Key
|
lhs_log::Out("Key:"+*Settings\Key)
|
||||||
mem_ptr = tls_load_file(*Settings\Key, @length)
|
mem_ptr = tls_load_file(*Settings\Key, @length)
|
||||||
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -5 : EndIf
|
If Not mem_ptr : tls_config_free(tls_cfg) : ProcedureReturn -5 : EndIf
|
||||||
tls_config_set_key_mem(tls_cfg, mem_ptr, length)
|
tls_config_set_key_mem(tls_cfg, mem_ptr, length)
|
||||||
EndIf
|
EndIf
|
||||||
tls_ctx = tls_server()
|
tls_ctx = tls_server()
|
||||||
Debug "TLS Server obj:"+Str(tls_ctx)
|
lhs_log::Out("TLS Server obj:"+Str(tls_ctx))
|
||||||
If Not tls_ctx : tls_config_free(tls_cfg) : ProcedureReturn -6 : EndIf
|
If Not tls_ctx : tls_config_free(tls_cfg) : ProcedureReturn -6 : EndIf
|
||||||
returns = tls_configure(tls_ctx, tls_cfg)
|
returns = tls_configure(tls_ctx, tls_cfg)
|
||||||
Debug "Configure Returns:"+Str(returns)
|
lhs_log::Out("Configure Returns:"+Str(returns))
|
||||||
If returns <> 0 :Debug ErrorTLSSrv(): tls_free(tls_ctx) : tls_config_free(tls_cfg) : ProcedureReturn -7 : EndIf
|
If returns <> 0 :lhs_log::Out(ErrorTLSSrv()): tls_free(tls_ctx) : tls_config_free(tls_cfg) : ProcedureReturn -7 : EndIf
|
||||||
ProcedureReturn 1
|
ProcedureReturn 1
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
|
156
lweb.pbi
156
lweb.pbi
|
@ -177,6 +177,7 @@ Module lhs_web
|
||||||
|
|
||||||
Declare call_request(RequestString.s, Info.i=#get_handler_procedure)
|
Declare call_request(RequestString.s, Info.i=#get_handler_procedure)
|
||||||
|
|
||||||
|
Declare.s Work_Post_ToJSON_multipart_form_data(ContentLength.i, MemorSize.i, Memory.i)
|
||||||
Declare.s Work_Post_ToJSON_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
|
Declare.s Work_Post_ToJSON_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
|
||||||
Declare count_client(Type.i, Countchange.i)
|
Declare count_client(Type.i, Countchange.i)
|
||||||
|
|
||||||
|
@ -279,7 +280,7 @@ Module lhs_web
|
||||||
If tlsresponse > 0
|
If tlsresponse > 0
|
||||||
CreateThread(@server_HTTPS(), server_HTTPS_id)
|
CreateThread(@server_HTTPS(), server_HTTPS_id)
|
||||||
Else
|
Else
|
||||||
Debug "TLS Fehler:"+Str(tlsresponse)
|
lhs_log::Out("TLS Fehler:"+Str(tlsresponse))
|
||||||
ProcedureReturn #False
|
ProcedureReturn #False
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
@ -305,13 +306,13 @@ Module lhs_web
|
||||||
|
|
||||||
thread_alive = #True
|
thread_alive = #True
|
||||||
|
|
||||||
Debug "HTTPS Server Started."
|
lhs_log::Out("HTTPS Server Started.")
|
||||||
Repeat
|
Repeat
|
||||||
client_id = ltls::WaitTLSSocket(network_server_id)
|
client_id = ltls::WaitTLSSocket(network_server_id)
|
||||||
Debug "New HTTPS Client:"+Str(client_id)
|
lhs_log::Out("New HTTPS Client:"+Str(client_id))
|
||||||
If client_id > 0
|
If client_id > 0
|
||||||
If m_clients(Str(client_id))\client_id = client_id
|
If m_clients(Str(client_id))\client_id = client_id
|
||||||
Debug "Client Thread for socket already exist :"+Str(client_id)
|
lhs_log::Out("Client Thread for socket already exist :"+Str(client_id))
|
||||||
Else
|
Else
|
||||||
If count_HTTPS_client < conf_max_HTTPS_clients
|
If count_HTTPS_client < conf_max_HTTPS_clients
|
||||||
m_clients(Str(client_id))\client_id = client_id
|
m_clients(Str(client_id))\client_id = client_id
|
||||||
|
@ -322,7 +323,7 @@ Module lhs_web
|
||||||
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
||||||
count_client(#client_HTTPS, #client_add)
|
count_client(#client_HTTPS, #client_add)
|
||||||
Else
|
Else
|
||||||
Debug "Max HTTPS Clients reached..."
|
lhs_log::Out("Max HTTPS Clients reached...")
|
||||||
ltls::CloseTLSSocket(client_id)
|
ltls::CloseTLSSocket(client_id)
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -342,13 +343,13 @@ Module lhs_web
|
||||||
|
|
||||||
thread_alive = #True
|
thread_alive = #True
|
||||||
|
|
||||||
Debug "HTTP Server Started."
|
lhs_log::Out("HTTP Server Started.")
|
||||||
Repeat
|
Repeat
|
||||||
client_id = lsocket::WaitSocket(network_server_id)
|
client_id = lsocket::WaitSocket(network_server_id)
|
||||||
Debug "New HTTP Client:"+Str(client_id)
|
lhs_log::Out("New HTTP Client:"+Str(client_id))
|
||||||
If client_id > 0
|
If client_id > 0
|
||||||
If m_clients(Str(client_id))\client_id = client_id
|
If m_clients(Str(client_id))\client_id = client_id
|
||||||
Debug "Client Thread for socket already exist :"+Str(client_id)
|
lhs_log::Out("Client Thread for socket already exist :"+Str(client_id))
|
||||||
Else
|
Else
|
||||||
If count_HTTP_client < conf_max_HTTP_clients
|
If count_HTTP_client < conf_max_HTTP_clients
|
||||||
m_clients(Str(client_id))\client_id = client_id
|
m_clients(Str(client_id))\client_id = client_id
|
||||||
|
@ -359,7 +360,7 @@ Module lhs_web
|
||||||
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
m_clients(Str(client_id))\client_thread = CreateThread(@client(), client_id)
|
||||||
count_client(#client_HTTP, #client_add)
|
count_client(#client_HTTP, #client_add)
|
||||||
Else
|
Else
|
||||||
Debug "Max HTTP Clients reached..."
|
lhs_log::Out("Max HTTP Clients reached...")
|
||||||
lsocket::CloseSocket(client_id)
|
lsocket::CloseSocket(client_id)
|
||||||
EndIf
|
EndIf
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -384,7 +385,7 @@ Module lhs_web
|
||||||
Define NewMap Post.s()
|
Define NewMap Post.s()
|
||||||
|
|
||||||
|
|
||||||
Debug "Client Thread Started. ID:" + Str(network_client_id)
|
lhs_log::Out("Client Thread Started. ID:" + Str(network_client_id))
|
||||||
Repeat
|
Repeat
|
||||||
;Prüfen ob der Thread was zu tun hat.
|
;Prüfen ob der Thread was zu tun hat.
|
||||||
;{ Main Server Triggered Things
|
;{ Main Server Triggered Things
|
||||||
|
@ -399,7 +400,7 @@ Module lhs_web
|
||||||
If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer
|
If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer
|
||||||
m_clients(Str(thread_cli_id))\datenbuffer()\Initialized = #True
|
m_clients(Str(thread_cli_id))\datenbuffer()\Initialized = #True
|
||||||
Else
|
Else
|
||||||
Debug "Buffer Initialisierung fehlgeschlagen."
|
lhs_log::Out("Buffer Initialisierung fehlgeschlagen.")
|
||||||
Break
|
Break
|
||||||
EndIf
|
EndIf
|
||||||
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
||||||
|
@ -409,7 +410,7 @@ Module lhs_web
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
If temp_receivelength = -1
|
If temp_receivelength = -1
|
||||||
Debug "Empfangsfehler."
|
lhs_log::Out("Empfangsfehler.")
|
||||||
Break
|
Break
|
||||||
ElseIf temp_receivelength = 65536
|
ElseIf temp_receivelength = 65536
|
||||||
m_clients(Str(thread_cli_id))\datenbuffer()\Size = temp_receivelength
|
m_clients(Str(thread_cli_id))\datenbuffer()\Size = temp_receivelength
|
||||||
|
@ -420,7 +421,7 @@ Module lhs_web
|
||||||
If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer
|
If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer
|
||||||
m_clients(Str(thread_cli_id))\datenbuffer()\Initialized = #True
|
m_clients(Str(thread_cli_id))\datenbuffer()\Initialized = #True
|
||||||
Else
|
Else
|
||||||
Debug "Buffer Initialisierung fehlgeschlagen."
|
lhs_log::Out("Buffer Initialisierung fehlgeschlagen.")
|
||||||
Break 2
|
Break 2
|
||||||
EndIf
|
EndIf
|
||||||
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
||||||
|
@ -439,19 +440,19 @@ Module lhs_web
|
||||||
m_clients(Str(thread_cli_id))\datenbuffer()\Size = temp_receivelength
|
m_clients(Str(thread_cli_id))\datenbuffer()\Size = temp_receivelength
|
||||||
EndIf
|
EndIf
|
||||||
;Alle Daten empfangen.
|
;Alle Daten empfangen.
|
||||||
Debug "Anzahl Buffer:" + Str(ListSize(m_clients(Str(thread_cli_id))\datenbuffer()))
|
lhs_log::Out("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_srv = #SRV_DO_NOP
|
||||||
m_clients(Str(thread_cli_id))\client_do_cli = #CLI_DO_DataWorking
|
m_clients(Str(thread_cli_id))\client_do_cli = #CLI_DO_DataWorking
|
||||||
|
|
||||||
Case #SRV_DO_ClientDisconnect
|
Case #SRV_DO_ClientDisconnect
|
||||||
;Thread beenden
|
;Thread beenden
|
||||||
Debug "#SRV_DO_ClientDisconnect"
|
lhs_log::Out("#SRV_DO_ClientDisconnect")
|
||||||
thread_alive = #False
|
thread_alive = #False
|
||||||
;* Alles IO
|
;* Alles IO
|
||||||
Default
|
Default
|
||||||
;Ressourcen freigeben und Threadzeit reduzieren
|
;Ressourcen freigeben und Threadzeit reduzieren
|
||||||
Delay(1)
|
Delay(1)
|
||||||
Debug "--------------------------------------------------------- FAILING ???"
|
lhs_log::Out("--------------------------------------------------------- FAILING ???")
|
||||||
EndSelect
|
EndSelect
|
||||||
;}
|
;}
|
||||||
|
|
||||||
|
@ -464,7 +465,7 @@ Module lhs_web
|
||||||
;Change Thread to Work mode.
|
;Change Thread to Work mode.
|
||||||
|
|
||||||
;{
|
;{
|
||||||
Debug "Date received, working..."
|
lhs_log::Out("Date received, working...")
|
||||||
m_clients(Str(thread_cli_id))\client_do_cli = #CLI_DO_DataWorking
|
m_clients(Str(thread_cli_id))\client_do_cli = #CLI_DO_DataWorking
|
||||||
;Work on Answer.
|
;Work on Answer.
|
||||||
ResetList(m_clients(Str(thread_cli_id))\datenbuffer())
|
ResetList(m_clients(Str(thread_cli_id))\datenbuffer())
|
||||||
|
@ -493,7 +494,7 @@ Module lhs_web
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
;Debug "JSONString:"+ JSONStringToMap
|
;lhs_log::Out("JSONString:"+ JSONStringToMap)
|
||||||
thread_type = ""
|
thread_type = ""
|
||||||
Select Header(#http_head_method)
|
Select Header(#http_head_method)
|
||||||
Case #http_method_get
|
Case #http_method_get
|
||||||
|
@ -502,13 +503,13 @@ Module lhs_web
|
||||||
;* Default GET
|
;* Default GET
|
||||||
;*
|
;*
|
||||||
;{
|
;{
|
||||||
Debug #http_method_get
|
lhs_log::Out(#http_method_get)
|
||||||
If Header(#http_head_request) = "/"
|
If Header(#http_head_request) = "/"
|
||||||
thread_requested = conf_defaultfile
|
thread_requested = conf_defaultfile
|
||||||
Else
|
Else
|
||||||
thread_requested = Header(#http_head_request)
|
thread_requested = Header(#http_head_request)
|
||||||
EndIf
|
EndIf
|
||||||
Debug "Requested:"+thread_requested
|
lhs_log::Out("Requested:"+thread_requested)
|
||||||
ToCallType = call_request(thread_requested, #get_handler_prototype)
|
ToCallType = call_request(thread_requested, #get_handler_prototype)
|
||||||
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_get
|
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_get
|
||||||
ToCall = call_request(thread_requested)
|
ToCall = call_request(thread_requested)
|
||||||
|
@ -529,7 +530,7 @@ Module lhs_web
|
||||||
Handler_Response = ToCallProcedure(Header())
|
Handler_Response = ToCallProcedure(Header())
|
||||||
|
|
||||||
EndSelect
|
EndSelect
|
||||||
Debug "Main Client Response :"+Handler_Response
|
lhs_log::Out("Main Client Response :"+Handler_Response)
|
||||||
MyThreadJSON = ParseJSON(#PB_Any, Handler_Response)
|
MyThreadJSON = ParseJSON(#PB_Any, Handler_Response)
|
||||||
If MyThreadJSON
|
If MyThreadJSON
|
||||||
ClearMap(Response())
|
ClearMap(Response())
|
||||||
|
@ -537,18 +538,18 @@ Module lhs_web
|
||||||
FreeJSON(MyThreadJSON)
|
FreeJSON(MyThreadJSON)
|
||||||
Else
|
Else
|
||||||
;WTF ???
|
;WTF ???
|
||||||
Debug "Fehler Absturz"
|
lhs_log::Out("Fehler Absturz")
|
||||||
Break 2 ; Thread abschiessen
|
Break 2 ; Thread abschiessen
|
||||||
EndIf
|
EndIf
|
||||||
Debug "Response Content:"+Response(#cha_R_ResponseContentType)
|
lhs_log::Out("Response Content:"+Response(#cha_R_ResponseContentType))
|
||||||
Select Response(#cha_R_ResponseContentType)
|
Select Response(#cha_R_ResponseContentType)
|
||||||
Case #response_Memory
|
Case #response_Memory
|
||||||
Debug "Response Memory"
|
lhs_log::Out("Response Memory")
|
||||||
thread_data_size = Val(Response(#cha_R_MemorySize))
|
thread_data_size = Val(Response(#cha_R_MemorySize))
|
||||||
thread_temp_cache_memory = Val(Response(#cha_R_MemoryAdress))
|
thread_temp_cache_memory = Val(Response(#cha_R_MemoryAdress))
|
||||||
thread_type = Response(#cha_R_ResponseType)
|
thread_type = Response(#cha_R_ResponseType)
|
||||||
Case #response_string
|
Case #response_string
|
||||||
Debug "Response String"
|
lhs_log::Out("Response String")
|
||||||
thread_temp_decode_memory = AllocateMemory(StringByteLength(Response(#cha_R_StringBase64)))
|
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_data_size = Base64Decoder(Response(#cha_R_StringBase64), thread_temp_decode_memory, StringByteLength(Response(#cha_R_StringBase64)))
|
||||||
thread_temp_cache_memory = AllocateMemory(thread_data_size)
|
thread_temp_cache_memory = AllocateMemory(thread_data_size)
|
||||||
|
@ -558,7 +559,7 @@ Module lhs_web
|
||||||
Default
|
Default
|
||||||
;Solte ja nicht passieren.
|
;Solte ja nicht passieren.
|
||||||
EndSelect
|
EndSelect
|
||||||
Debug "Content Finished"
|
lhs_log::Out("Content Finished")
|
||||||
;}
|
;}
|
||||||
|
|
||||||
ElseIf conf_cache_enable = 1
|
ElseIf conf_cache_enable = 1
|
||||||
|
@ -572,7 +573,7 @@ Module lhs_web
|
||||||
;Alles Ok
|
;Alles Ok
|
||||||
Else
|
Else
|
||||||
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
||||||
Debug "FileDir:" + conf_basedir + conf_defaultfile
|
lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -595,7 +596,7 @@ Module lhs_web
|
||||||
thread_file_handle = ReadFile(#PB_Any, conf_basedir + thread_requested,#PB_File_SharedRead)
|
thread_file_handle = ReadFile(#PB_Any, conf_basedir + thread_requested,#PB_File_SharedRead)
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
||||||
Debug "FileDir:" + conf_basedir + conf_defaultfile
|
lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -615,8 +616,12 @@ Module lhs_web
|
||||||
;*
|
;*
|
||||||
;* POST
|
;* POST
|
||||||
;*
|
;*
|
||||||
Debug #http_method_post
|
;* Current Finaly Implementet is only application/x-www-form-urlencoded
|
||||||
;PrintN("POST")
|
;* Error Handling must be Optimized.
|
||||||
|
;*
|
||||||
|
lhs_log::Out(#http_method_post)
|
||||||
|
|
||||||
|
;{ POST Content Type Decoder
|
||||||
If LCase(Header(#http_head_content_type)) = #http_content_type_application_x_www_form_urlencoded
|
If LCase(Header(#http_head_content_type)) = #http_content_type_application_x_www_form_urlencoded
|
||||||
PostMapString = Work_Post_ToJSON_x_www_form_urlencoded(Val(Header(#http_head_content_length)), m_clients(Str(thread_cli_id))\datenbuffer()\Size, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)
|
PostMapString = Work_Post_ToJSON_x_www_form_urlencoded(Val(Header(#http_head_content_length)), m_clients(Str(thread_cli_id))\datenbuffer()\Size, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)
|
||||||
MyThreadJSON = ParseJSON(#PB_Any, PostMapString)
|
MyThreadJSON = ParseJSON(#PB_Any, PostMapString)
|
||||||
|
@ -626,17 +631,30 @@ Module lhs_web
|
||||||
FreeJSON(MyThreadJSON)
|
FreeJSON(MyThreadJSON)
|
||||||
Else
|
Else
|
||||||
;Should not be possible.
|
;Should not be possible.
|
||||||
Debug "Error in thread, JSON Convert didn't Work"
|
lhs_log::Out("Error in thread, JSON Convert didn't Work")
|
||||||
Break 2 ; Kill Thread
|
Break 2 ; Kill Thread
|
||||||
EndIf
|
EndIf
|
||||||
|
ElseIf Left(LCase(Header(#http_head_content_type)), Len(#http_content_type_multipart_form_data)) = #http_content_type_multipart_form_data
|
||||||
|
PostMapString = Work_Post_ToJSON_multipart_form_data(Val(Header(#http_head_content_length)), m_clients(Str(thread_cli_id))\datenbuffer()\Size, m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)
|
||||||
|
MyThreadJSON = ParseJSON(#PB_Any, PostMapString)
|
||||||
|
If MyThreadJSON
|
||||||
|
ClearMap(Post())
|
||||||
|
ExtractJSONMap(JSONValue(MyThreadJSON), Post())
|
||||||
|
FreeJSON(MyThreadJSON)
|
||||||
|
Else
|
||||||
|
;Someting wrong in the POST
|
||||||
|
lhs_log::Out("Error with Content. JSON Convert didn't Work")
|
||||||
|
Break 2; Kill Thread
|
||||||
EndIf
|
EndIf
|
||||||
|
EndIf
|
||||||
|
;}
|
||||||
|
|
||||||
If Header(#http_head_request) = "/"
|
If Header(#http_head_request) = "/"
|
||||||
thread_requested = conf_defaultfile
|
thread_requested = conf_defaultfile
|
||||||
Else
|
Else
|
||||||
thread_requested = Header(#http_head_request)
|
thread_requested = Header(#http_head_request)
|
||||||
EndIf
|
EndIf
|
||||||
Debug "Requested:"+thread_requested
|
lhs_log::Out("Requested:"+thread_requested)
|
||||||
ToCallType = call_request(thread_requested, #get_handler_prototype)
|
ToCallType = call_request(thread_requested, #get_handler_prototype)
|
||||||
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_post
|
If ToCallType = #handler_proto_universal Or ToCallType = #handler_proto_post
|
||||||
ToCall = call_request(thread_requested)
|
ToCall = call_request(thread_requested)
|
||||||
|
@ -657,7 +675,7 @@ Module lhs_web
|
||||||
Handler_Response = ToCallProcedure(Header(), PostMapString)
|
Handler_Response = ToCallProcedure(Header(), PostMapString)
|
||||||
|
|
||||||
EndSelect
|
EndSelect
|
||||||
Debug "Main Client Response :"+Handler_Response
|
lhs_log::Out("Main Client Response :"+Handler_Response)
|
||||||
MyThreadJSON = ParseJSON(#PB_Any, Handler_Response)
|
MyThreadJSON = ParseJSON(#PB_Any, Handler_Response)
|
||||||
If MyThreadJSON
|
If MyThreadJSON
|
||||||
ClearMap(Response())
|
ClearMap(Response())
|
||||||
|
@ -665,10 +683,10 @@ Module lhs_web
|
||||||
FreeJSON(MyThreadJSON)
|
FreeJSON(MyThreadJSON)
|
||||||
Else
|
Else
|
||||||
;WTF ???
|
;WTF ???
|
||||||
Debug "Fehler Absturz"
|
lhs_log::Out("Fehler Absturz")
|
||||||
Break 2 ; Thread abschiessen
|
Break 2 ; Thread abschiessen
|
||||||
EndIf
|
EndIf
|
||||||
Debug "Response Content:"+Response(#cha_R_ResponseContentType)
|
lhs_log::Out("Response Content:"+Response(#cha_R_ResponseContentType))
|
||||||
Select Response(#cha_R_ResponseContentType)
|
Select Response(#cha_R_ResponseContentType)
|
||||||
Case #response_Memory
|
Case #response_Memory
|
||||||
thread_data_size = Val(Response(#cha_R_MemorySize))
|
thread_data_size = Val(Response(#cha_R_MemorySize))
|
||||||
|
@ -684,7 +702,7 @@ Module lhs_web
|
||||||
Default
|
Default
|
||||||
;Solte ja nicht passieren.
|
;Solte ja nicht passieren.
|
||||||
EndSelect
|
EndSelect
|
||||||
Debug "Content Finished"
|
lhs_log::Out("Content Finished")
|
||||||
;}
|
;}
|
||||||
|
|
||||||
ElseIf conf_cache_enable = 1
|
ElseIf conf_cache_enable = 1
|
||||||
|
@ -698,7 +716,7 @@ Module lhs_web
|
||||||
;Alles Ok
|
;Alles Ok
|
||||||
Else
|
Else
|
||||||
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
||||||
Debug "FileDir:" + conf_basedir + conf_defaultfile
|
lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -721,7 +739,7 @@ Module lhs_web
|
||||||
thread_file_handle = ReadFile(#PB_Any, conf_basedir + thread_requested,#PB_File_SharedRead)
|
thread_file_handle = ReadFile(#PB_Any, conf_basedir + thread_requested,#PB_File_SharedRead)
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
||||||
Debug "FileDir:" + conf_basedir + conf_defaultfile
|
lhs_log::Out("FileDir:" + conf_basedir + conf_defaultfile)
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -744,7 +762,7 @@ Module lhs_web
|
||||||
|
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
thread_file_handle = ReadFile(#PB_Any, conf_basedir + conf_defaultfile,#PB_File_SharedRead)
|
||||||
Debug "FileDir:" + conf_basedir + thread_requested
|
lhs_log::Out("FileDir:" + conf_basedir + thread_requested)
|
||||||
If Not thread_file_handle
|
If Not thread_file_handle
|
||||||
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
thread_file_handle = ReadFile(#PB_Any, "error.html")
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -792,25 +810,25 @@ Module lhs_web
|
||||||
thread_buffer = AllocateMemory(thread_data_size+StringByteLength(thread_header)+12)
|
thread_buffer = AllocateMemory(thread_data_size+StringByteLength(thread_header)+12)
|
||||||
thread_buffer_offset = thread_buffer
|
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
|
thread_buffer_length = PokeS(thread_buffer_offset, thread_header,-1, #PB_UTF8|#PB_String_NoZero) : thread_buffer_offset + thread_buffer_length
|
||||||
Debug "Header Finished"
|
lhs_log::Out("Header Finished")
|
||||||
EndIf
|
EndIf
|
||||||
If thread_temp_cache_memory <> 0 And thread_buffer_offset <> 0 And thread_data_size <> 0
|
If thread_temp_cache_memory <> 0 And thread_buffer_offset <> 0 And thread_data_size <> 0
|
||||||
CopyMemory(thread_temp_cache_memory, thread_buffer_offset, thread_data_size)
|
CopyMemory(thread_temp_cache_memory, thread_buffer_offset, thread_data_size)
|
||||||
Debug thread_temp_cache_memory
|
lhs_log::Out(Str(thread_temp_cache_memory))
|
||||||
FreeMemory(thread_temp_cache_memory)
|
FreeMemory(thread_temp_cache_memory)
|
||||||
thread_temp_cache_memory=0
|
thread_temp_cache_memory=0
|
||||||
Else
|
Else
|
||||||
Debug "File Buffer Troubles."
|
lhs_log::Out("File Buffer Troubles.")
|
||||||
If thread_temp_cache_memory = 0 : Debug "thread_temp_cache_memory = 0" : EndIf
|
If thread_temp_cache_memory = 0 : lhs_log::Out("thread_temp_cache_memory = 0") : EndIf
|
||||||
If thread_buffer_offset = 0 : Debug "thread_buffer_offset = 0" : EndIf
|
If thread_buffer_offset = 0 : lhs_log::Out("thread_buffer_offset = 0") : EndIf
|
||||||
If thread_data_size = 0 : Debug "thread_data_size = 0" : EndIf
|
If thread_data_size = 0 : lhs_log::Out("thread_data_size = 0") : EndIf
|
||||||
thread_alive = #False
|
thread_alive = #False
|
||||||
Break 2
|
Break 2
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
; EndIf
|
; EndIf
|
||||||
|
|
||||||
Debug "HTTP File Buffer Cleaned."
|
lhs_log::Out("HTTP File Buffer Cleaned.")
|
||||||
;Löschen des eingang Speichers.
|
;Löschen des eingang Speichers.
|
||||||
If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer > 0
|
If m_clients(Str(thread_cli_id))\datenbuffer()\Buffer > 0
|
||||||
FreeMemory(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)
|
FreeMemory(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)
|
||||||
|
@ -826,12 +844,12 @@ Module lhs_web
|
||||||
Repeat
|
Repeat
|
||||||
sent = ltls::WriteTLSSocket(thread_cli_id, sent_buffer_address , sent_length)
|
sent = ltls::WriteTLSSocket(thread_cli_id, sent_buffer_address , sent_length)
|
||||||
If sent <> -1
|
If sent <> -1
|
||||||
Debug "HTTPS Sent:"+Str(sent)+" bytes"
|
lhs_log::Out("HTTPS Sent:"+Str(sent)+" bytes")
|
||||||
sent_length - sent
|
sent_length - sent
|
||||||
sent_buffer_address + sent
|
sent_buffer_address + sent
|
||||||
sent_total + sent
|
sent_total + sent
|
||||||
Else
|
Else
|
||||||
Debug "HTTPS Sent error:"+ltls::ErrorTLSCli(thread_cli_id)
|
lhs_log::Out("HTTPS Sent error:"+ltls::ErrorTLSCli(thread_cli_id))
|
||||||
thread_alive = #False
|
thread_alive = #False
|
||||||
Break 2
|
Break 2
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -846,12 +864,12 @@ Module lhs_web
|
||||||
Repeat
|
Repeat
|
||||||
sent = lsocket::WriteSocket(thread_cli_id, thread_buffer , sent_length)
|
sent = lsocket::WriteSocket(thread_cli_id, thread_buffer , sent_length)
|
||||||
If sent <> -1
|
If sent <> -1
|
||||||
Debug "HTTP Sent:"+Str(sent)+" bytes"
|
lhs_log::Out("HTTP Sent:"+Str(sent)+" bytes")
|
||||||
sent_length - sent
|
sent_length - sent
|
||||||
sent_buffer_address + sent
|
sent_buffer_address + sent
|
||||||
sent_total + sent
|
sent_total + sent
|
||||||
Else
|
Else
|
||||||
Debug "HTTP Sent error:"+Str(sent)
|
lhs_log::Out("HTTP Sent error:"+Str(sent))
|
||||||
thread_alive = #False
|
thread_alive = #False
|
||||||
Break 2
|
Break 2
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -862,7 +880,7 @@ Module lhs_web
|
||||||
|
|
||||||
If sent = thread_data_size+(thread_buffer_offset-thread_buffer)
|
If sent = thread_data_size+(thread_buffer_offset-thread_buffer)
|
||||||
;Ok
|
;Ok
|
||||||
;Debug "Gesendet:" + PeekS(thread_buffer,thread_buffer_length, #PB_Ascii)
|
;lhs_log::Out("Gesendet:" + PeekS(thread_buffer,thread_buffer_length, #PB_Ascii))
|
||||||
If thread_buffer > 0
|
If thread_buffer > 0
|
||||||
FreeMemory(thread_buffer)
|
FreeMemory(thread_buffer)
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -871,7 +889,7 @@ Module lhs_web
|
||||||
m_clients(Str(thread_cli_id))\client_do_srv = #SRV_DO_DataReceive
|
m_clients(Str(thread_cli_id))\client_do_srv = #SRV_DO_DataReceive
|
||||||
Else
|
Else
|
||||||
;Fehler beim Senden ... Thread beenden.
|
;Fehler beim Senden ... Thread beenden.
|
||||||
Debug "Fehler:" + Str(Sent)
|
lhs_log::Out("Fehler:" + Str(Sent))
|
||||||
thread_alive = #False
|
thread_alive = #False
|
||||||
|
|
||||||
EndIf
|
EndIf
|
||||||
|
@ -887,35 +905,35 @@ Module lhs_web
|
||||||
;}
|
;}
|
||||||
|
|
||||||
Until thread_alive = #False
|
Until thread_alive = #False
|
||||||
Debug "Thread should now die..."
|
lhs_log::Out("Thread should now die...")
|
||||||
ResetList(m_clients(Str(thread_cli_id))\datenbuffer())
|
ResetList(m_clients(Str(thread_cli_id))\datenbuffer())
|
||||||
Debug "Thread kill all Initialized Memory buffers:"
|
lhs_log::Out("Thread kill all Initialized Memory buffers:")
|
||||||
While NextElement(m_clients(Str(thread_cli_id))\datenbuffer())
|
While NextElement(m_clients(Str(thread_cli_id))\datenbuffer())
|
||||||
If m_clients(Str(thread_cli_id))\datenbuffer()\Initialized
|
If m_clients(Str(thread_cli_id))\datenbuffer()\Initialized
|
||||||
Debug "Kill:"+Str(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)+ " ..."
|
lhs_log::Out("Kill:"+Str(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)+ " ...")
|
||||||
FreeMemory(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())
|
DeleteElement(m_clients(Str(thread_cli_id))\datenbuffer())
|
||||||
Debug "Freed and removed"
|
lhs_log::Out("Freed and removed")
|
||||||
Else
|
Else
|
||||||
Debug "Remove element from List with uninitialized Memory ID: "+Str(m_clients(Str(thread_cli_id))\datenbuffer()\Buffer)
|
lhs_log::Out("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())
|
DeleteElement(m_clients(Str(thread_cli_id))\datenbuffer())
|
||||||
Debug "Removed"
|
lhs_log::Out("Removed")
|
||||||
EndIf
|
EndIf
|
||||||
Wend
|
Wend
|
||||||
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
If m_clients(Str(thread_cli_id))\client_type = #client_HTTPS
|
||||||
Debug "Kill HTTPS Socket:" + Str(thread_cli_id)
|
lhs_log::Out("Kill HTTPS Socket:" + Str(thread_cli_id))
|
||||||
;ltls::CloseTLSSocket(thread_cli_id)
|
;ltls::CloseTLSSocket(thread_cli_id)
|
||||||
count_client(#client_HTTPS, #client_remove)
|
count_client(#client_HTTPS, #client_remove)
|
||||||
Debug "Killed."
|
lhs_log::Out("Killed.")
|
||||||
Else
|
Else
|
||||||
Debug "Kill HTTP Socket:" + Str(thread_cli_id)
|
lhs_log::Out("Kill HTTP Socket:" + Str(thread_cli_id))
|
||||||
lsocket::CloseSocket(thread_cli_id)
|
lsocket::CloseSocket(thread_cli_id)
|
||||||
count_client(#client_HTTP, #client_remove)
|
count_client(#client_HTTP, #client_remove)
|
||||||
Debug "Killed."
|
lhs_log::Out("Killed.")
|
||||||
EndIf
|
EndIf
|
||||||
Debug "Remove Client from map..."
|
lhs_log::Out("Remove Client from map...")
|
||||||
DeleteMapElement(m_clients(), Str(thread_cli_id))
|
DeleteMapElement(m_clients(), Str(thread_cli_id))
|
||||||
Debug "Removed and thread now died."
|
lhs_log::Out("Removed and thread now died.")
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
@ -997,7 +1015,7 @@ Module lhs_web
|
||||||
Count = 0
|
Count = 0
|
||||||
Repeat
|
Repeat
|
||||||
Posts(StringField(StringField(ContentString, Count + 1, "&"),1,"=")) = StringField(StringField(ContentString, Count + 1, "&"),2,"=")
|
Posts(StringField(StringField(ContentString, Count + 1, "&"),1,"=")) = StringField(StringField(ContentString, Count + 1, "&"),2,"=")
|
||||||
;Debug "Worked Count:"+Str(Count)+" of: "+Str(CountParams)+":"+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,"=")
|
||||||
Count + 1
|
Count + 1
|
||||||
Until Count > CountParams
|
Until Count > CountParams
|
||||||
Else
|
Else
|
||||||
|
@ -1022,11 +1040,16 @@ Module lhs_web
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.s Work_Post_ToJSON_multipart_form_data(ContentLength.i, MemorySize.i, Memory.i)
|
||||||
|
|
||||||
|
ProcedureReturn "NA"
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
Procedure.s register_client_handler(Route.s, Callback.i, AppPrototype.i = #handler_proto_get, RouteType.i = #handler_sub)
|
Procedure.s register_client_handler(Route.s, Callback.i, AppPrototype.i = #handler_proto_get, RouteType.i = #handler_sub)
|
||||||
m_request(Route)\type = AppPrototype
|
m_request(Route)\type = AppPrototype
|
||||||
m_request(Route)\call = Callback
|
m_request(Route)\call = Callback
|
||||||
m_request(Route)\routetype = RouteType
|
m_request(Route)\routetype = RouteType
|
||||||
Debug "Handler Registriert:"+Route
|
lhs_log::Out("Handler Registriert:"+Route)
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure count_client(Type.i, Countchange.i)
|
Procedure count_client(Type.i, Countchange.i)
|
||||||
|
@ -1052,4 +1075,3 @@ EndModule
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
6
lweb.pbp
6
lweb.pbp
|
@ -8,7 +8,7 @@
|
||||||
<section name="data">
|
<section name="data">
|
||||||
<explorer view="../../../bin/purebasic/examples/" pattern="0"/>
|
<explorer view="../../../bin/purebasic/examples/" pattern="0"/>
|
||||||
<log show="1"/>
|
<log show="1"/>
|
||||||
<lastopen date="2021-03-26 14:53" user="renlin" host="linux-mvsk"/>
|
<lastopen date="2021-05-18 11:07" user="renlin" host="localhost.localdomain"/>
|
||||||
</section>
|
</section>
|
||||||
<section name="files">
|
<section name="files">
|
||||||
<file name="inc/lweb_file_cache.pbi">
|
<file name="inc/lweb_file_cache.pbi">
|
||||||
|
@ -53,11 +53,11 @@
|
||||||
</file>
|
</file>
|
||||||
<file name="ltls.pbi">
|
<file name="ltls.pbi">
|
||||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
|
<config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
|
||||||
<fingerprint md5="2039445441451e5efbfb06a5d695d02f"/>
|
<fingerprint md5="b956381cac547736cc02dc190f3667ef"/>
|
||||||
</file>
|
</file>
|
||||||
<file name="lweb.pbi">
|
<file name="lweb.pbi">
|
||||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
|
<config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
|
||||||
<fingerprint md5="046f6480cd2ad72f3b9cb025dca0f810"/>
|
<fingerprint md5="de8dab8fa9d7a38afdba1b88cc9d7f23"/>
|
||||||
</file>
|
</file>
|
||||||
<file name="lweb_header.pbi">
|
<file name="lweb_header.pbi">
|
||||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
|
<config load="0" scan="1" panel="1" warn="1" lastopen="1" panelstate="+"/>
|
||||||
|
|
|
@ -10,6 +10,8 @@
|
||||||
;*
|
;*
|
||||||
|
|
||||||
EnableExplicit
|
EnableExplicit
|
||||||
|
XIncludeFile "lhs_lib/SYS/lhs_log.pbi"
|
||||||
|
|
||||||
CompilerIf #PB_Compiler_Thread = 0
|
CompilerIf #PB_Compiler_Thread = 0
|
||||||
CompilerError "Muss Threadsicher Kompiliert werden"
|
CompilerError "Muss Threadsicher Kompiliert werden"
|
||||||
CompilerEndIf
|
CompilerEndIf
|
||||||
|
|
|
@ -2,11 +2,10 @@
|
||||||
;*
|
;*
|
||||||
;* Lihaso Web Server
|
;* Lihaso Web Server
|
||||||
;*
|
;*
|
||||||
|
;* HTTP/HTTPS Server Beispiel
|
||||||
|
;*
|
||||||
;* (c)2015 - 2021 by Linder Hard- und Software
|
;* (c)2015 - 2021 by Linder Hard- und Software
|
||||||
;*
|
;*
|
||||||
;* V0.1
|
|
||||||
;* - Initial Web Server
|
|
||||||
;* - Modul interface ?
|
|
||||||
;*
|
;*
|
||||||
|
|
||||||
EnableExplicit
|
EnableExplicit
|
||||||
|
@ -15,11 +14,19 @@ EnableExplicit
|
||||||
;* Deklaration Variabeln
|
;* Deklaration Variabeln
|
||||||
;*
|
;*
|
||||||
|
|
||||||
|
XIncludeFile "lhs_lib/SYS/lhs_log.pbi"
|
||||||
XIncludeFile "lweb_header.pbi"
|
XIncludeFile "lweb_header.pbi"
|
||||||
XIncludeFile "lweb.pbi"
|
XIncludeFile "lweb.pbi"
|
||||||
|
|
||||||
Define counter, v_lweb_srv_stop
|
Define counter, v_lweb_srv_stop
|
||||||
|
|
||||||
|
lhs_log::App_Name = "http-s_server_example"
|
||||||
|
lhs_log::SetLogFile("http-s_server_example.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()
|
||||||
|
|
||||||
lhs_web::set_config(lhs_web::#conf_HTTP_port, "8081")
|
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_binding, "127.0.0.1")
|
||||||
lhs_web::set_config(lhs_web::#conf_HTTP_binding, "0.0.0.0")
|
lhs_web::set_config(lhs_web::#conf_HTTP_binding, "0.0.0.0")
|
||||||
|
@ -45,9 +52,9 @@ Procedure.s Sample_Header(Map Header.s())
|
||||||
Define.s Encoded, ZumSenden, TBD, Text
|
Define.s Encoded, ZumSenden, TBD, Text
|
||||||
NewMap Response.s()
|
NewMap Response.s()
|
||||||
If Header("cookie:") <> ""
|
If Header("cookie:") <> ""
|
||||||
Debug "A Cookie is set :" + Header("cookie:")
|
lhs_log::Out("A Cookie is set :" + Header("cookie:"))
|
||||||
Else
|
Else
|
||||||
Debug "No Cookie."
|
lhs_log::Out("No Cookie.")
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
TBD="<div><div><h1>Header</h1></div><br/>"+#CRLF$
|
TBD="<div><div><h1>Header</h1></div><br/>"+#CRLF$
|
||||||
|
@ -60,7 +67,7 @@ Procedure.s Sample_Header(Map Header.s())
|
||||||
*Text = AllocateMemory(StringByteLength(Text))
|
*Text = AllocateMemory(StringByteLength(Text))
|
||||||
PokeS(*Text, Text)
|
PokeS(*Text, Text)
|
||||||
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
||||||
Debug "Encoded: " + Encoded
|
lhs_log::Out("Encoded: " + Encoded)
|
||||||
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
||||||
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
||||||
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
||||||
|
@ -70,7 +77,7 @@ Procedure.s Sample_Header(Map Header.s())
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
ZumSenden = lhs_web::MapToJSONString(Response())
|
ZumSenden = lhs_web::MapToJSONString(Response())
|
||||||
Debug "ZumSenden: " + ZumSenden
|
lhs_log::Out("ZumSenden: " + ZumSenden)
|
||||||
ProcedureReturn ZumSenden
|
ProcedureReturn ZumSenden
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
@ -83,20 +90,20 @@ Procedure.s Formular_Test(Map Header.s(), ContentData.s)
|
||||||
While NextMapElement(Header())
|
While NextMapElement(Header())
|
||||||
TBD = TBD+"<div>"+MapKey(Header())+" : "+Header()+" </div><br/>"+#CRLF$
|
TBD = TBD+"<div>"+MapKey(Header())+" : "+Header()+" </div><br/>"+#CRLF$
|
||||||
Wend
|
Wend
|
||||||
Debug "TBD:"+TBD
|
lhs_log::Out("TBD:"+TBD)
|
||||||
Debug "contentData:"+ContentData
|
lhs_log::Out("contentData:"+ContentData)
|
||||||
Text = "<!DOCTYPE html><html><header><title>Alle Client Headers</title></header><body>"+TBD+"<hr/><br/><h1>ConentJSON</h1><br/>"+ContentData+"</body></html>"
|
Text = "<!DOCTYPE html><html><header><title>Alle Client Headers</title></header><body>"+TBD+"<hr/><br/><h1>ConentJSON</h1><br/>"+ContentData+"</body></html>"
|
||||||
*Text = AllocateMemory(StringByteLength(Text))
|
*Text = AllocateMemory(StringByteLength(Text))
|
||||||
PokeS(*Text, Text)
|
PokeS(*Text, Text)
|
||||||
Debug "Unencoded:"+PeekS(*Text, -1 , #PB_UTF8)
|
lhs_log::Out("Unencoded:"+PeekS(*Text, -1 , #PB_UTF8))
|
||||||
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
||||||
Debug "Encoded: " + Encoded
|
lhs_log::Out("Encoded: " + Encoded)
|
||||||
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
||||||
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
||||||
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
||||||
Response(lhs_web::#cha_R_http_head_status) = "200 OK"
|
Response(lhs_web::#cha_R_http_head_status) = "200 OK"
|
||||||
ZumSenden = lhs_web::MapToJSONString(Response())
|
ZumSenden = lhs_web::MapToJSONString(Response())
|
||||||
Debug "ZumSenden: " + ZumSenden
|
lhs_log::Out("ZumSenden: " + ZumSenden)
|
||||||
ProcedureReturn ZumSenden
|
ProcedureReturn ZumSenden
|
||||||
|
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
@ -107,7 +114,7 @@ Procedure.s Php_Test(Map Header.s(), ContentData.s)
|
||||||
NewMap Response.s()
|
NewMap Response.s()
|
||||||
|
|
||||||
Execute = lhs_web::get_config(lhs_web::#conf_basedir) + Header(lhs_web::#http_head_request)
|
Execute = lhs_web::get_config(lhs_web::#conf_basedir) + Header(lhs_web::#http_head_request)
|
||||||
Debug "To Execute:" + Execute
|
lhs_log::Out("To Execute:" + Execute)
|
||||||
Php = RunProgram("php", Execute, "", #PB_Program_Open | #PB_Program_Read)
|
Php = RunProgram("php", Execute, "", #PB_Program_Open | #PB_Program_Read)
|
||||||
Phpresult = ""
|
Phpresult = ""
|
||||||
If Php
|
If Php
|
||||||
|
@ -121,15 +128,15 @@ Procedure.s Php_Test(Map Header.s(), ContentData.s)
|
||||||
Text = Phpresult
|
Text = Phpresult
|
||||||
*Text = AllocateMemory(StringByteLength(Text))
|
*Text = AllocateMemory(StringByteLength(Text))
|
||||||
PokeS(*Text, Text)
|
PokeS(*Text, Text)
|
||||||
Debug "Unencoded:"+PeekS(*Text, -1 , #PB_UTF8)
|
lhs_log::Out("Unencoded:"+PeekS(*Text, -1 , #PB_UTF8))
|
||||||
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
Encoded = Base64Encoder(*Text, MemorySize(*Text))
|
||||||
Debug "Encoded: " + Encoded
|
lhs_log::Out("Encoded: " + Encoded)
|
||||||
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
Response(lhs_web::#cha_R_ResponseContentType) = lhs_web::#response_string
|
||||||
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
Response(lhs_web::#cha_R_StringBase64) = Encoded
|
||||||
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
Response(lhs_web::#cha_R_ResponseType) = lhs_web::mimetype("html")
|
||||||
Response(lhs_web::#cha_R_http_head_status) = "200 OK"
|
Response(lhs_web::#cha_R_http_head_status) = "200 OK"
|
||||||
ZumSenden = lhs_web::MapToJSONString(Response())
|
ZumSenden = lhs_web::MapToJSONString(Response())
|
||||||
Debug "ZumSenden: " + ZumSenden
|
lhs_log::Out("ZumSenden: " + ZumSenden)
|
||||||
ProcedureReturn ZumSenden
|
ProcedureReturn ZumSenden
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
|
@ -145,9 +152,9 @@ lhs_web::register_client_handler("php", @Php_Test(),lhs_web::#handler_proto_univ
|
||||||
;*
|
;*
|
||||||
|
|
||||||
If lhs_web::start_server()
|
If lhs_web::start_server()
|
||||||
Debug "Server gestartet" + lhs_web::get_config(lhs_web::#conf_HTTP_port)
|
lhs_log::Out("Server gestartet" + lhs_web::get_config(lhs_web::#conf_HTTP_port))
|
||||||
Else
|
Else
|
||||||
Debug "Fehlgeschlagen"
|
lhs_log::Out("Fehlgeschlagen")
|
||||||
End
|
End
|
||||||
EndIf
|
EndIf
|
||||||
|
|
||||||
|
@ -159,5 +166,5 @@ PrintN("HTTPS an Port:"+lhs_web::get_config(lhs_web::#conf_HTTPS_Port))
|
||||||
PrintN("Press Enter to Exit")
|
PrintN("Press Enter to Exit")
|
||||||
Input()
|
Input()
|
||||||
PrintN("Finished")
|
PrintN("Finished")
|
||||||
|
lhs_log::Close()
|
||||||
End
|
End
|
||||||
|
|
Loading…
Reference in a new issue