programming tools for Windows applications development
  Home  |   SwiftForth Archive  |   SwiftX Archive  |

Re: Using SF as a CGI

From: Bob Nash <BNash_at_smud.org>
Date: Mon, 9 Dec 2002 08:12:28 -0800

Thanks Mike and Kevin for you replies. Thanks Mike for the parser (I am
sure I will need it) and other sample code.

Mike: YES! Please post your HTML script engine.

The console part was as I suspected. In reading more, I think I know why
they want a console behavior: the CGI app must process and terminate without
the server having to ask Windows to kill it.

Also, I think I now see why I was confused about environment variables,
STDIN, etc. for passing CGI data. As Mike said, there isn't necessarily one
way to do it. Some pass via cmd line when CGI program is invoked. I don't
see how multiple requests would be handled with STDIN, but still reading
....

As for my quest for the ultimate small server, I have turned up several of
interest (two from Russia, one written in Forth). I will let everyone know
my experiences with them.

-----Original Message-----
From: Mike Ghan [mailto:mikeghan_at_logix-controls.com]
Sent: Saturday, December 07, 2002 9:24 AM
To: sftalk_at_forth.com
Subject: [sftalk] Re: Using SF as a CGI

-----Original Message-----
From: sftalk-bounce_at_forth.com [mailto:sftalk-bounce_at_forth.com]On
Behalf
Of Bob Nash
Sent: Friday, December 06, 2002 2:25 PM
To: SFTALK (E-mail)
Subject: [sftalk] Using SF as a CGI

> I am interested in using SF as a CGI. I would like to generate
minimal html
> pages in response to a GET method passed to a tiny HTTP server on my
home
> LAN. I was wondering if anyone had done something like this with SF
that
> they could share.
>
> Specifically, I would like to know if I am on the right path with
STDIN,
> STDOUT and environment variables.

It seems so but this is entirely dependent on the server app. Are any
parameters passed on the command line?

>
> First, I assume that I just make the API call to get a handle to
STDOUT and
> treat it like a normal file. For example: "STD_OUTPUT_HANDLE
GetStdHandle."
> From what I can tell, STDOUT is how the HTML pages that my app
generates are
> passed to the HTTP server. Am I on the right track here?

Yes - use Dosbox.F as a template - convert TYPE(C) to use WriteFile
instead of WriteConsole for redirection. If you require STDIN, you'll
need to use ReadFile (it appears the server passes parameters as
environment variables or maybe on the command line - this makes life
easier since you won't need STDIN).

>
> Second, I assume that when the HTTP server starts up my app, it
passes it
> environment variables containing the query from the remote PC. The
> environment variables passed from the HTTP server are strings such
as
> QUERY_STRING and CONTENT_LENGTH. Some time ago, Mike Ghan provided
a
> snippet to do get the environment variable string:
>
> \ Function: GetEnvironmentVariable ( lpName lpBuffer nBufSize --
#chars )
>
> : GET-ENV ( name len -- addr cnt )
> R-BUF R@ ZPLACE R> ( envName )
> 0 0 >QPAD ( buf ) 128 GetEnvironmentVariable
> QPAD SWAP ;

Here is a handy tool for parsing words:

: PARSE-WORD ( addr count char -- remainingAddr remainingCount
parsedAddr parsedCount )
   DUP >R SKIP R>
   LOCALS| char count addr |
   addr count char SCAN ( remAddr remCnt )
   addr count THIRD - 0 MAX ;

Try the following example:

S" QUERY_STRING=foobar" CHAR = PARSE-WORD
TYPE CHAR = SKIP ( past "=" ) TYPE

> Lastly, TinyWEB wants the CGI to run as a console application. I am
not
> sure what this means and how to do it. I do not plan to register a
window
> or anything like that, just output HTML on STDOUT and terminate. Is
there
> something I should know here?

A console app is just like the old familiar DOS app - no Windows
message loops, callbacks etc.

Here is an example console app:

REQUIRES DOSBOX \ <<< Nothing to do with DOS, its a Console

: TEST ( -- )
   CR CR ." This should be displayed in the console box."
   CR ." Press any key to exit" KEY DROP ;

: DO-IT ['] TEST DOS-CONSOLE P-EXECUTE ;

: MAIN ( -- )
   /DOS-CONSOLE
   ['] DO-IT CATCH DROP ( must return here! )
   0 ExitProcess ;

' MAIN 'MAIN !

/XREF \ Cleanup XRef
-1 THRESHOLD \ No Xref file

PROGRAM TESTCON

Let me know if you are interested in a SwiftForth HTML script engine,
I'll post it.

Hope this helps,

Mike

----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
----------------------------------------------------------------------
sftalk_at_forth.com The SwiftForth programming discussion email list
To unsubscribe, send subject "unsubscribe sftalk" to listar_at_forth.com
For help with listar commands, send subject "help" to listar_at_forth.com
Archives are located at http://www.forth.com/sftalk -- check them out!
Search the archives! Visit http://www.forth.com/search for details.
Received on Mon Dec 09 2002 - 08:11:54 PST

This archive was generated by hypermail 2.2.0 : Wed Jan 07 2009 - 03:04:04 PST