Re: COBOL for utility program under Linux.



On Aug 29, 1:55 am, Michael Wojcik <mwoj...@xxxxxxxxxxx> wrote:
Richard wrote:
On Aug 28, 12:49 am, "Michael Mattias" <mmatt...@xxxxxxxxxxxxxx>
wrote:
"Richard" <rip...@xxxxxxxxxxxx> wrote in message

news:7305512a-f9cc-48be-96a0-c82e9ab18f5e@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx>MCMwrote
CGI really only needs ACCEPT and DISPLAY 'UPON COMMAND LINE'
CGI generally is reading from or writing to STDIN and STDOUT. (on unix,
<> 'stdin' and 'stdout')

CGI scripts (the specification calls anything that is executed by a
server via the CGI protocol a "script") only read from standard input
if the request includes a content-body. HTTP GET requests, for
example, do not include a content-body.

For a GET request, the client can pass data to the script as a
query-string, which will be passed to the script in the CGI
QUERY_STRING metavariable. Most, possibly all, implementations of CGI
use the environment for metavariables.

For GET requests that follow the ISINDEX syntax (ie, with no unescaped
"=" characters in the query-string), then if the system permits
passing command-line parameters to the script, it should also parse
the query-string into words using "+" as a delimiter and put those on
the command line.

I had to dig deep to find references to the deprecated <isindex> tag,
most of my material only goes back as far as the early 90s. ;-)


This is per the CGI/1.1 Internet-draft Draft 03, which does not have
force as a standard, but is the closest thing to a coherent
description of CGI/1.1 practices. Seehttp://w3.org/CGI/for links to
various CGI specifications, including the original NCSA CGI/1.1 spec
and the I-D.

When ACCEPTing from stdin (or CGI) it is usually necessary to use the
length of the text (which is supplier in an environment variable) as a
limit on the data as otherwise it will require a timeout or similar.
Surely there is another way to use standard handles with COBOL other than
DISPLAY/ACCEPT. (READ and WRITE come to mind) .
Why would you need 'another way' ?
Because as you point out, you may need the length to execute the ACCEPT,
which you don't have.

Yes you do, with CGI it is in the CONTENT_LENGTH environment variable.

Though again, this is only true if the request contains a content-body.

Whether this is actually needed depends on the implementation.

Correct. Systems which can indicate EOF to the script, MAY do so after
writing CONTENT_LENGTH octets, but are not required to. So if the
server reliably signals EOF after writing the content-body to the
script, and it's acceptable for the script to depend on that behavior,
then the script can read until EOF.

   DISPLAY "CONTENT LENGTH"  UPON Environment-Name
   ACCEPT  Content-Length    FROM Environment-Value
   ACCEPT  Content(1:FUNCTION NUMVAL(Content-Length))
           FROM CONSOLE

Since this is simple, clear, and guaranteed to work under any
conforming implementation, it's what I'd recommend. (Probably with
some error checking, just in case.)

It didn't work on MF Cobol 3.4 on OS/2 for which I had to resort to
CALL OS2API "DosRead" USING ...

Not that this was ever used in any live situation.

Under Windows using my BASIC complier, you can detect
"end of file" on STDIN when reading the HTML submitted by the caller....

Only if the server provides that behavior.

But I guess..... you could ACCEPT a byte at a time until there ain't no
more? IOr maybe is there a facility with ACCEPT to detect "no data
availale?"  Damn, I simply can't remember anymore. I suppose I could look it
up.....wow, I forgot about all the MF extensions to ACCEPT... both TIME-OUT
and ON EXCEPTION look like they will support handilng the
unknown-when-you-start-variable-lengthness of the input.

I suspect ON EXCEPTION would work for detecting EOF, though I haven't
tested it.

I'd use Richard's method, though. For maximum flexibility, if
CONTENT_LENGTH is not set, empty, or zero, the script could check
QUERY_STRING; that would let it handle both GET and POST requests.

The 'Request Method" environment variable should contain 'POST' or
'GET' allowing this source to be determined adequately. It is possible
for "CONTENT LENGTH" to be set even when the "Query String" variable
contains the data.

There are some servers (probably obsolete) than can pass the content
in a disk file in which case the file name is passed as a variable.
Most of my Cobol CGI code was originally developed in the early 90s
and initially ran on OS/2 with an IBM server, progressed (??) to
Win3.11 with some httpd I forget, UnixWare with Netscape, and Xitami
on Linux and Windows before getting to Linux with Apache.

In this progression it found a vast array of minor issues, such as the
different spellings of the variables used (eg 'CONTENT_LENGTH' or
'Content Length'. The first thing to do with a web server is to run a
simple script to dump out the environment to see what you are getting.

Of course it would be easy for me to put together another simple Cobol
CGI system should it be required because I have all this framework
running. As Peter says, without this Cobol is much too hard to start
up from scratch for any serious application when other languages now
have complete frameworks available - for free.

The best reason for doing it in Cobol would be if there are existing
systems using indexed files where live interaction is required.

(That may require some extra processing, because the value of
QUERY_STRING is URL-encoded, while the encoding of the content-body
depends on the content-type and possibly the whims of the client program.)

--
Michael Wojcik
Micro Focus
Rhetoric & Writing, Michigan State University

.



Relevant Pages

  • Re: How do I insert a cgi script into Publisher page?
    ... If your ISP supports cgi and has a form handling program then a form created ... You must tell the server what e mail address you want the form results sent ... any where else you so desire or an auto redirect script with a delay. ... link to your host and specifically where on the host website it gives you ...
    (microsoft.public.publisher.webdesign)
  • Re: How do I insert a cgi script into Publisher page?
    ... If your ISP supports cgi and has a form handling program then a form created in publisher will function using FTP upload rather than front page server extensions to upload the pages. ... The thank you page may have a link back to the page where you came from or any where else you so desire or an auto redirect script with a delay. ... Also provide us a link to your host and specifically where on the host website it gives you the instructions for using the forms program in the cgi folder. ...
    (microsoft.public.publisher.webdesign)
  • Re: Apache: limiting the execution place
    ... They want it so users can't use FTP, shell, or a CGI or PHP script to view, ... other users via shell, FTP, web server processes (such as PHP or CGI ...
    (Security-Basics)
  • Re: How do I insert a cgi script into Publisher page?
    ... is not where I host my website. ... If your ISP supports cgi and has a form handling program then a form ... You must tell the server what e mail address you want the form results ... any where else you so desire or an auto redirect script with a delay. ...
    (microsoft.public.publisher.webdesign)
  • Re: existence and size of client file
    ... to provide a FORM to the client. ... executed after the POST request reaches your server. ... The client sends an HTTP POST request, which contains the URL, the ... Then the server has inkove the CGI script so that the CGI script can ...
    (comp.lang.perl.misc)