Remove post decoder from main and create new module

This commit is contained in:
René Linder 2023-07-18 08:58:51 +02:00
parent 077531d4c8
commit ce41a4cd23
1 changed files with 68 additions and 0 deletions

View 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