Merge remote-tracking branch 'refs/remotes/origin/main'
This commit is contained in:
commit
edccdf62cd
3 changed files with 82 additions and 59 deletions
68
inc/lweb_http_post_decoder.pbi
Normal file
68
inc/lweb_http_post_decoder.pbi
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
;********************************
|
||||||
|
;*
|
||||||
|
;* lweb_http_post_decoder.pbi
|
||||||
|
;*
|
||||||
|
;* LiHaSo Webserver HTTP POST Data decoder
|
||||||
|
;*
|
||||||
|
;* Currently only x_www_form_urlencode implemented.
|
||||||
|
;*
|
||||||
|
|
||||||
|
DeclareModule lhs_web_post
|
||||||
|
Declare.s mem_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
|
||||||
|
Declare.s mem_multipart_form_data(ContentLength.i, MemorySize.i, Memory.i)
|
||||||
|
#error_string = "error"
|
||||||
|
EndDeclareModule
|
||||||
|
|
||||||
|
Module lhs_web_post
|
||||||
|
Procedure.s mem_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
|
||||||
|
Define.s JSONString, Working, ContentString
|
||||||
|
Define CountParams, Count, JSON
|
||||||
|
Protected NewMap Posts.s()
|
||||||
|
|
||||||
|
If ContentLength > 0
|
||||||
|
OffsetMemory = Memory + (MemorSize - ContentLength)
|
||||||
|
ContentString = PeekS(OffsetMemory, ContentLength, #PB_UTF8)
|
||||||
|
;Zerlegen &
|
||||||
|
;Mapname = Content
|
||||||
|
If Len(ContentString) > 0
|
||||||
|
CountParams = CountString(ContentString,"&")
|
||||||
|
If CountParams = 0
|
||||||
|
If CountString(ContentString, "=")
|
||||||
|
Posts(StringField(ContentString, 1, "=")) = StringField(ContentString,2, "=")
|
||||||
|
Else
|
||||||
|
ProcedureReturn ""
|
||||||
|
EndIf
|
||||||
|
ElseIf CountParams > 0
|
||||||
|
Count = 0
|
||||||
|
Repeat
|
||||||
|
Posts(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
|
||||||
|
ProcedureReturn ""
|
||||||
|
EndIf
|
||||||
|
JSON = CreateJSON(#PB_Any)
|
||||||
|
If JSON
|
||||||
|
InsertJSONMap(JSONValue(JSON), Posts())
|
||||||
|
JSONString = ComposeJSON(JSON)
|
||||||
|
FreeMap(Posts())
|
||||||
|
FreeJSON(JSON)
|
||||||
|
ProcedureReturn JSONString.s
|
||||||
|
Else
|
||||||
|
ProcedureReturn #error_string
|
||||||
|
EndIf
|
||||||
|
Else
|
||||||
|
ProcedureReturn ""
|
||||||
|
EndIf
|
||||||
|
Else
|
||||||
|
ProcedureReturn ""
|
||||||
|
EndIf
|
||||||
|
|
||||||
|
EndProcedure
|
||||||
|
|
||||||
|
Procedure.s mem_multipart_form_data(ContentLength.i, MemorySize.i, Memory.i)
|
||||||
|
|
||||||
|
ProcedureReturn "NA"
|
||||||
|
EndProcedure
|
||||||
|
EndModule
|
63
lweb.pbi
63
lweb.pbi
|
@ -10,6 +10,9 @@
|
||||||
|
|
||||||
XIncludeFile "lhs_lib/NET/lhs_net_tls.pbi"
|
XIncludeFile "lhs_lib/NET/lhs_net_tls.pbi"
|
||||||
XIncludeFile "lhs_lib/NET/lhs_net_socket.pbi"
|
XIncludeFile "lhs_lib/NET/lhs_net_socket.pbi"
|
||||||
|
XIncludeFile "inc/lweb_http_post_decoder.pbi"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Module lhs_web
|
Module lhs_web
|
||||||
;********************************
|
;********************************
|
||||||
|
@ -211,8 +214,8 @@ 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 call_function(ToCallType.i, ToCall.i, Map Header.s(), PostMapString.s ="")
|
Declare.s call_function(ToCallType.i, ToCall.i, Map Header.s(), PostMapString.s ="")
|
||||||
Declare advanced_register_handler(RequesterString.s, Permament.i = 0, Library.s = "", Host.s = "")
|
Declare advanced_register_handler(RequesterString.s, Permament.i = 0, Library.s = "", Host.s = "")
|
||||||
Declare.s Work_Post_ToJSON_multipart_form_data(ContentLength.i, MemorSize.i, Memory.i)
|
;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)
|
||||||
|
|
||||||
XIncludeFile "inc/lweb_IP.pbi"
|
XIncludeFile "inc/lweb_IP.pbi"
|
||||||
|
@ -872,7 +875,7 @@ Module lhs_web
|
||||||
|
|
||||||
;{ POST Content Type Decoder
|
;{ 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 = lhs_web_post::mem_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)
|
||||||
If MyThreadJSON
|
If MyThreadJSON
|
||||||
ClearMap(Post())
|
ClearMap(Post())
|
||||||
|
@ -884,7 +887,7 @@ Module lhs_web
|
||||||
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
|
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)
|
PostMapString = lhs_web_post::mem_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)
|
||||||
If MyThreadJSON
|
If MyThreadJSON
|
||||||
ClearMap(Post())
|
ClearMap(Post())
|
||||||
|
@ -1352,58 +1355,6 @@ Module lhs_web
|
||||||
ProcedureReturn Val(call_request_string(RequestString.s, Info.i))
|
ProcedureReturn Val(call_request_string(RequestString.s, Info.i))
|
||||||
EndProcedure
|
EndProcedure
|
||||||
|
|
||||||
Procedure.s Work_Post_ToJSON_x_www_form_urlencoded(ContentLength.i, MemorSize.i, Memory.i)
|
|
||||||
Define.s JSONString, Working, ContentString
|
|
||||||
Define CountParams, Count, JSON
|
|
||||||
Protected NewMap Posts.s()
|
|
||||||
|
|
||||||
If ContentLength > 0
|
|
||||||
OffsetMemory = Memory + (MemorSize - ContentLength)
|
|
||||||
ContentString = PeekS(OffsetMemory, ContentLength, #PB_UTF8)
|
|
||||||
;Zerlegen &
|
|
||||||
;Mapname = Content
|
|
||||||
If Len(ContentString) > 0
|
|
||||||
CountParams = CountString(ContentString,"&")
|
|
||||||
If CountParams = 0
|
|
||||||
If CountString(ContentString, "=")
|
|
||||||
Posts(StringField(ContentString, 1, "=")) = StringField(ContentString,2, "=")
|
|
||||||
Else
|
|
||||||
ProcedureReturn ""
|
|
||||||
EndIf
|
|
||||||
ElseIf CountParams > 0
|
|
||||||
Count = 0
|
|
||||||
Repeat
|
|
||||||
Posts(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
|
|
||||||
ProcedureReturn ""
|
|
||||||
EndIf
|
|
||||||
JSON = CreateJSON(#PB_Any)
|
|
||||||
If JSON
|
|
||||||
InsertJSONMap(JSONValue(JSON), Posts())
|
|
||||||
JSONString = ComposeJSON(JSON)
|
|
||||||
FreeMap(Posts())
|
|
||||||
FreeJSON(JSON)
|
|
||||||
ProcedureReturn JSONString.s
|
|
||||||
Else
|
|
||||||
ProcedureReturn #error_string
|
|
||||||
EndIf
|
|
||||||
Else
|
|
||||||
ProcedureReturn ""
|
|
||||||
EndIf
|
|
||||||
Else
|
|
||||||
ProcedureReturn ""
|
|
||||||
EndIf
|
|
||||||
|
|
||||||
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, Host.s = "")
|
Procedure.s register_client_handler(Route.s, Callback.i, AppPrototype.i = #handler_proto_get, RouteType.i = #handler_sub, Host.s = "")
|
||||||
If Len(Host) > 0
|
If Len(Host) > 0
|
||||||
Host = "SpecServer:["+Host+"]"
|
Host = "SpecServer:["+Host+"]"
|
||||||
|
|
10
lweb.pbp
10
lweb.pbp
|
@ -1,6 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
<project xmlns="http://www.purebasic.com/namespace" version="1.0" creator="PureBasic 6.02 LTS (Linux - x64)">
|
<project xmlns="http://www.purebasic.com/namespace" version="1.0" creator="PureBasic 6.03 beta 3 LTS (Linux - x64)">
|
||||||
<section name="config">
|
<section name="config">
|
||||||
<options closefiles="1" openmode="0" name="LiHaSo Webserver Modul"/>
|
<options closefiles="1" openmode="0" name="LiHaSo Webserver Modul"/>
|
||||||
<comment>Projekt ist inklusive Beispiel Code</comment>
|
<comment>Projekt ist inklusive Beispiel Code</comment>
|
||||||
|
@ -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="2023-07-07 15:22" user="renlin" host="renlin-office"/>
|
<lastopen date="2023-07-18 08:57" user="renlin" host="localhost.localdomain"/>
|
||||||
</section>
|
</section>
|
||||||
<section name="files">
|
<section name="files">
|
||||||
<file name="installation.pb">
|
<file name="installation.pb">
|
||||||
|
@ -113,7 +113,7 @@
|
||||||
</file>
|
</file>
|
||||||
<file name="lweb.pbi">
|
<file name="lweb.pbi">
|
||||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="26" panelstate="+"/>
|
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="26" panelstate="+"/>
|
||||||
<fingerprint md5="1a0fcb4cf90a344c342ba86840365bf6"/>
|
<fingerprint md5="e3243900ab7a7478fce202e60875e752"/>
|
||||||
</file>
|
</file>
|
||||||
<file name="inc/lweb_helper_header.pbi">
|
<file name="inc/lweb_helper_header.pbi">
|
||||||
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="27" panelstate="+-"/>
|
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="27" panelstate="+-"/>
|
||||||
|
@ -131,6 +131,10 @@
|
||||||
<config load="0" scan="1" panel="1" warn="1" lastopen="0" sortindex="999" panelstate="+-"/>
|
<config load="0" scan="1" panel="1" warn="1" lastopen="0" sortindex="999" panelstate="+-"/>
|
||||||
<fingerprint md5="3228c16f329808e2e6e3c6866861ae59"/>
|
<fingerprint md5="3228c16f329808e2e6e3c6866861ae59"/>
|
||||||
</file>
|
</file>
|
||||||
|
<file name="inc/lweb_http_post_decoder.pbi">
|
||||||
|
<config load="0" scan="1" panel="1" warn="1" lastopen="1" sortindex="29" panelstate="+-"/>
|
||||||
|
<fingerprint md5="f05103675e4b6921ea9f745a1344d6cd"/>
|
||||||
|
</file>
|
||||||
</section>
|
</section>
|
||||||
<section name="targets">
|
<section name="targets">
|
||||||
<target name="Standard-Ziel" enabled="1" default="0">
|
<target name="Standard-Ziel" enabled="1" default="0">
|
||||||
|
|
Loading…
Reference in a new issue