Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

QuickBASIC on the Web

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Does anyone know of a CGI function library that can be linked to executable QuickBASIC (compiled version) code to make executable CGI programs? Visual Basic has CGI32.BAS, and there are several C/C++ libraries available on the Internet, but none of my searches turned up anything for QuickBASIC like what I'm looking for.

I suppose I could get the C libraries and make a lib and qlb file from revissing the functions (declaring them as Pascal functions to handle argument and return value handling correctly) and compiling those to obj code, but was looking for something that might already be optimized for QB.

My job is doing web programming, and I do some ASP, but the file access is SO kludge-y compared to the simplicity of writing code for QB. It'd be nice to be able to handle all that with a QB executable.
 
You do not in fact need any special library to do CGI. All that CGI libraries do is decode the query string for you and, depending on the library, take care of the output headers. You can do all this yourself. However, QuickBASIC's primary output is not to the standard output device. Instead, it writes directly to the screen. What you need to do is open the character device file "CONS:" and send the text you want sent to the user there.

The response header set you need to send is interpreted by the server, so it does not need to be a full HTTP set of headers. A minimal response is the status header:

Status: ### description

Use number 200 for a valid, successful request. Here are some other codes you can use to help indicate the status of the response:

- 302: permanently moved (you need to specify the 'Location:' response header alongside this to specify where the resource has moved to)
- 401: authorization needed (this will make the client attempt to use HTTP authentication, which will require some base64 decoding to properly use).
- 403: forbidden (the client will not attempt to re-request the resource)
- 404: not found
- 500: internal server error

There are many others, and they are all listed in the HTTP RFC (#2068). There are some other headers you can specify, such as:

- Location: <url> (used in conjunction with status codes 302 and 305, as well as for specifying the filename when outputting binary data)
- Content-Type: <mime-type> (used to specify how the browser should treat the data, typically you want either &quot;text/html&quot; or &quot;application/octet-stream&quot;)
- Content-Length: <number of bytes> (can help to optimize the browser's retrieval of the data, but is not strictly necesary)

There are also many other headers you can use. Most of the headers listed in the RFC should be valid here, including cache control headers.

Once you are done with the headers, output a blank line, and then start sending your content. It's as simple as that!

As for getting parameters from the request, avoid the &quot;POST&quot; method, as it is a headache to deal with manually (especially in multipart mode, and especially from QB). Use the &quot;GET&quot; method in forms, which will put all the parameters into the environment variable &quot;QUERY_STRING&quot; in the following form:

- each parameter is specified in the form name=value (or just name if value is not present)
- parameters are delimited by ampersands ('&')
- spaces have been turned into + signs, and a number of symbols including the following will have been turned into hex form: + = & % # /

Hex form consists of &quot;%xx&quot;, where xx is a hexadecimal number. Replace the 3 characters with a single character whose ASCII code is the value of the hexademical number.

To parse the QUERY_STRING, first break it down into parts delimited by &. This will give you one part per parameter. Break each parameter down into parts delimited by =. This will give either one part (in which case it is a name), or two parts (in which case the first part is a name and the second part is a value). Take each of these parts and do the following (in this order):

- turn all +'s into spaces
- turn all %xx's into the corresponding characters

It seems a bit daunting, but once you've written it once, you can re-use the code in multiple CGI applications.

When it actually comes down to it, though, I recommend the PowerBASIC Console Compiler for writing CGI stuff in the QuickBASIC language. PBCC costs about $100 USD, if I recall correctly, and can be ordered online from PBCC takes code that is very, very similar to QB code (they quote 98% compatible), and produces Win32 console binaries that run fairly efficiently (the compiler does some simple optimizations). The net result is that your CGI programs will load more quickly and run more quickly.

Anyway, good luck with your CGI endeavours :) Ultimately, the future lies in technologies like Microsoft's ASP.NET, where your code is essentially integrated into the web server at runtime, but CGI is a good place to start, and it's good to get a good feel for what's going on behind the scenes.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top