Object REXX

Rexx ICAPI Interface Package

Package: RXICAPI
 
Author:  W. David Ashley
         IBM Global Services
         dashley@us.ibm.com
         
Version: 1.02.01
This package provides an ICAPI interface to Object Rexx under Windows NT. It assumes that you have written ICAPI programs before in C/C++. This package is not an ICAPI tutorial/reference.

Package Installation

To install the package, unzip the contents to a temporary subdirectory. Move the following files to these locations (where x: is the WWW server install drive):
   rxicapi.dll    ->     x:\www\bin
                              or
                         x:\ibm\www\bin   (for Net.Commerce)
   test.rex       ->     x:\www\bin
                              or
                         x:\ibm\www\bin   (for Net.Commerce)
                              or
                         somewhere else in the NT system path
In the http.cnf file (located in x:\winnt) insert the following line:
   service /cgi-bin/rexx/* C:\www\bin\rxicapi.dll:CALLREXX
You may need to modify the line above if your WWW server bin subdirectory is not located in the specified place. Note that CALLREXX is case-sensitive.

Now restart the WWW server.

To test that the package is working start your browser and enter the following URL (where xxx is the name of your server):

 
   http://xxx/cgi-bin/rexx/test.rex
This should execute the REXX program test.rex and a sample/test HTML page should be displayed.

To build your own Rexx ICAPI programs just code your program and place it somewhere in the Windows NT system path. The interface will automatically locate the file in the path and execute the program.

Known problems

  1. None.

Information

The package was compiled under Microsoft Visual C++ version 5.0.

The package was tested using Lotus Domino Go Webserver version 4.6.2.3, Object Rexx for Windows 95/NT version 1.02 and Windows NT version 4.o with Service Pack 3 installed.

Version History

 
 Date     Author      Description                                           
 -------- ----------- ----------------------------------------------------- 
 12/01/98 WD Ashley   v1.00.01 Initial Release                                       
 12/04/98 WD Ashley   v1.01.01 Fixed problem where WWW server fails after   
                      the Rexx procedure reports an error. Also added error 
                      messages from a failed Rexx procedure to the          
                      httpd-error log file and also report them to the page 
                      returned to the browser.                              
 12/08/98 WD Ashley   v1.02.01 Added the balance of the HTTPD functions.    
                      Created the HTML documentation.
                       


Rexx HTTPD Functions

The following are the HTTPD functions available to the Rexx ICAPI programmer. Each of these external functions is automatically available at program startup. The Rexx programmer does not have to register them before using them.

HTTPD_attributes

Extracts the attributes of a file. Valid in all steps.

Rexx Function Prototype

return_code = HTTPD_attributes(handle, name, value);

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
name
Name of the file
value
Rexx variable name to return the attributes

HTTPD_authenticate

Authenticates a userid/password. Valid only in PreExit, Authenticate,and Authorization steps.

Rexx Function Prototype

return_code = HTTPD_authenticate(handle);

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle

HTTPD_exec

Executes a script to satisfy this request. Valid in PreExit, Service, NameTrans, and Error steps.

Rexx Function Prototype

return_code = HTTPD_exec(handle, name)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
name
Name of the script

HTTPD_extract

Extracts the value of a variable associated with this request. The valid variables you can use for the name parameter are the same as those used in the CGI. This function is valid in all steps, though not all variables will be.

Rexx Function Prototype

return_code = HTTPD_extract(handle, name, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
name
Name of the variable to be extracted
value
Rexx variable name to return the value of the variable

HTTPD_file

Sends a file to satisfy this request. Valid only in PreExit, Service, NameTrans, Error, and DataFilter steps.

Rexx Function Prototype

return_code = HTTPD_file(handle, name)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
name
The name of the file to send

HTTPD_log_error

Writes a string to the server’s error log. Valid in all steps.

Rexx Function Prototype

return_code = HTTPD_log_error(handle, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
value
The string to be written

HTTPD_log_trace

Writes a string to the server’s trace log. Valid in all steps.

Rexx Function Prototype

return_code = HTTPD_log_trace(handle, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
value
The string to be written

HTTPD_proxy

Makes a proxy request. Valid in PreExit and Service steps.

Note: This is a completion function; the response is complete after this function.

Rexx Function Prototype

return_code = HTTPD_proxy(handle, url, request)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
url
The URL for the proxy request
request
The body of the proxy request

HTTPD_read

Reads the body of the client’s request. Uses HTTPD_extract for headers. Valid only in the PreExit, Service and Data Filter steps.

Rexx Function Prototype

return_code = HTTPD_read(handle, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
value
Rexx variable name to return the client request

HTTPD_restart

Restarts the server after all active requests have been processed. Valid only in ServerInit and ServerTerm steps

Rexx Function Prototype

return_code = HTTPD_restart()

Function Parameters

return_code
The return code from the HTTPD function

HTTPD_reverse_translate

Translates a file system path to a URL. Valid in all steps.

Rexx Function Prototype

return_code = HTTPD_reverse_translate(handle, name, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
name
The file system path specification
value
Rexx variable name to return the URL

HTTPD_set

Sets the value of a variable associated with this request. The valid variables you can use for the name parameter are the same as those used in the CGI. Valid in all steps.

Note that you can also create variables with this function. If any variables you create are prefixed by HTTP_, they will be sent as headers in the response, without the HTTP_ prefix. For example, if you want to see a Location header, use HTTPD_set() with the variable name HTTP_LOCATION.

This function is valid in all steps, though not all variables will be.

Rexx Function Prototype

return_code = HTTPD_set(handle, name, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
name
The name of the variable to be set
value
The new value of the variable

HTTPD_supply_label

Provides the Webserver with a PICS label that was generated or retrieved during the PICSDBLookup step.

Valid only during the PICSDBLookup step.

Rexx Function Prototype

return_code = HTTPD_supply_label(handle, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
value
The value of the data to send

HTTPD_translate

Translates a URL to a file system path. Valid in all steps.

Rexx Function Prototype

return_code = HTTPD_translate(handle, name, url, path, query)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
name
The name of the URL
url
Rexx variable name to return the translated URL
path
Rexx variable name to return the PATH_TRANSLATED
query
Rexx variable name to return the QUERY_STRING

HTTPD_write

Writes the body of the response. Uses HTTPD_set and HTTPD_extract for headers. Valid in the PreExit, Service, NameTrans, Error, and Data Filter steps.

If you do not use HTTPD_set() to set the content type before the first time you call this function, the server will assume you are sending a CGI data stream.

You may need to use HTTPD_set() to set the CGI environment variable CONTENT_ENCODING to the appropriate code page for the content of your response (for example ebcdic) before you send the data to the client.

This function may be called multiple times.

Rexx Function Prototype

return_code = HTTPD_write(handle, value)

Function Parameters

return_code
The return code from the HTTPD function
handle
HTTPD handle
value
The string to be written


Rexx ICAPI Example Program

The following is a very simple Rexx ICAPI program.

/*-- REXX --*/

/* set some global variables */
lf = x2c('0a') /* line-feed character */
 
/* get the HTTPD handle */
handle = arg(1) /* always the first and only argument to the program */
 
/* set and send the content-type header */
call httpd_set handle, "Content-type", "text/html"
 
/* start the HTML page */
/* demonstrate the HTTPD_write function */
call httpd_write handle, "<HTML>" || lf
call httpd_write handle, "<HEAD>" || lf
call httpd_write handle, "<TITLE>Sample HTML Page From Rexx</TITLE>"" || lf
call httpd_write handle, "</HEAD>" || lf
call httpd_write handle, "<BODY>" || lf
call httpd_write handle, "<H1>Sample HTML Page From Rexx</H1>" || lf
call httpd_write handle, "<P>Hello from Rexx" || lf

/* demonstrate the HTTPD_attributes function */
file = "c:\config.sys"
call httpd_write handle, "<BR><H3>Test HTTPD_attributes</H3>" || lf
attrib = ""
call httpd_attributes handle, file, "attrib"
call httpd_write handle, "The attributes of <B>"file"</B> are <B>"attrib"</B>" || lf

/* demonstrate the HTTPD_extract function */
call httpd_write handle, "<BR><H3>Test HTTPD_extract</H3>" || lf
call httpd_write handle, "The following are some common values of variables" || lf
call httpd_write handle, "<UL>" || lf
var = "URL"
value = ""
call httpd_extract handle, var, "value"
call httpd_write handle, "<LI>"var "=" value || lf
 
/* close the HTML page */
call httpd_write handle, "</BODY>" || lf
call httpd_write handle, "</HTML>" || lf
return