Web51 - Simple http server |
|
Let's take a closer look at the http source code (see http.a51) and explain the processing of a http request.First, the client request is searched for "GET " (using a state machine controlled by state80table). When found, the state machine enters the port80s0 state, where fileID is filled with the hash value of the requested page. As detailed in filesystem description, three characters have a special meaning when calculating the hash sum. First, every "/" resets the sum to zero (filesystem ignores pathnames). Second and third, " " and "?" stop searching and pass the hash to exeurl, which searches the filesystem.
If a file with the same hash is found, an appropriate http header (according to file type) is sent and mode is switched to cgi or binary. In binary mode, the entire file is sent to the client using httpchar/sendchar.
Cgi mode is a little different. Input file is searched for occurences of "'". If found, another state machine (controlled by http80table) is activated. This one distinguishes double apostrophes ("''") that are converted to single apostrophy and output, and checks for "?" that indicates a "text1{text2}" sequence and causes flagIFcgi to be set. Again, the state machine tries to find a hash of the file name, which must end with a .cgi extension. After the extension, either "'", or "?" followed by a single-byte parameter (passed in state80) is expected. The respective CGI file is found according to its hash and passed to the P-Code interpreter for processing.
execgi: lcall searchfile ;r4 file type ;dptr file start ;r2r3 file end jc cginotfound mov workreg,dph mov workreg+1,dpl lcall pcode ;start p-code interpreter .pcode pcall @workreg .byte 0 ;stop p-code interpreter cginotfound: ;end of exe cgi retNow, let's show a simple example of processing CGI file testP3 (see the LED1 example).
;testP3.cgi .pcode testP3 .pcode pret ; testP3: mov a,P3 clr Zflag anl a,state80 jnz retP3 setb Zflag retP3: retExpand the CGI procedure testP3 call into its assembly equivalent, as the P-Code interpreter would expand it.
;; lcall pcode ;;start p-code interpreter ;; .pcode pcall @workreg ;;call @workreg mov R6,#high workreg mov R7,#low workreg ;;IND1 mov a,R7 mov R0,a mov a,@R0 mov R6,a inc R0 mov a,@R0 mov R7,a "push pcall" ret ;jmp pcall ;;pcall "push pcodepointer" mov DPH,R6 ;new Pcode pointer mov DPL,R7 ......DPTR now contains a new pointer to testP3.cgi (dptr = workreg = searchfile("testP3.cgi")). The P-Code interpreter fetches next command.
;; lcall pcode ;; .pcode testP3 "push testP3" ret ;jmp testP3 testP3: mov a,P3 clr Zflag anl a,state80 jnz retP3 setb Zflag retP3: ret ;ret to p-code interpreter ;; lcall pcode ;start p-code interpreter ;; .pcode pret "push pret" ret ;jmp pret ;;pret "pop pcodepointer" ;; lcall pcode ;; .byte 0 ;stop p-code interpreter ret ;return to asm cginotfound:Http server sources are in http.a51. Examples of html pages and CGI usage are in example projects.
| Web51 description | News | FAQ | ORDER FORM | DOWNLOAD | Links |
| (c)Copyright 2000 - 2002, HW server & Radek Benedikt
Web51@HW.cz, Web51.HW.cz |
|