02 CGI

CGI_Post 流程圖

\ Anew -Gci.f \ Webserver extension

needs SCOOP     \ scopes

needs DSTR      \ dynamic strings

needs sock      \ socket library

needs sockserv  \ socket server extention

needs HTTPerr   \ http error codes

needs http.f

\ scope httpreq

\ with httpreq definitions

\ Short manual:

\ Save test.htm in the webpath ( content after the source ) 保存TEST.HTM在webpath(源後的內容)

\ Include Gci.f in the webserver after httpecho.f

\ Compile the webserver

\ Start your browser

\ Open http://localhost/test.htm,

\ Fill in the form and press the button.

\ GciApplcation could of course access a database and

\ interact in a more complicated way.

fload CGI/分析取得資料字串.f

fload CGI/更新網頁檔案.f

: GciApplcation ( AdrDataPost len - adrReplyFromApplication - len )

\ Process the form. Just showing the data here

2dup

cr ." Data from the form:" 

type

cr

分析取得資料字串

更新網頁檔案 ( www/RTL8710.html )

s" Thank you!" \ Send some reply back.

;

with httpreq

: GetDataMethod ( - adr len ) 0 0 getparam ;

: DataLineFromPost ( AdrHeadr len - adr len )

tuck + over 0xa -scan

rot swap - 1- swap 1 + swap

;

: GciPost ( - )

request with dstr count

DataLineFromPost GciApplcation

reply free

s" <HTML><BODY><PRE>" reply append

reply append \ from GciApplcation

s" </PRE></BODY></HTML>" reply append

endwith 200 code !

;

: doGci ( -- flag ) \ Handles GCI commands with the POST method

url [char] / scan [char] / skip

2dup [char] / scan nip - s" Win32Forth.cgi" istr=

if GetDataMethod s" POST" istr=

if GciPost

then

true

else false then

;

doURL doGci http-done

endwith

\s

: _Win32Forth.cgi  doURL doGci http-done endwith  ;

_Win32Forth.cgi

' _Win32Forth.cgi turnkey Win32Forth.cgi       \ build an application on disk