Filter programs


Filter programs are written in Rexx. Based on the arguments they are passed, they decide on the document or other data to be sent to the client and then issue a command or return a result that defines that data (usually a file) to the server. GoServe then handles the transmission of the data to the client.

All requests are passed to the Rexx filter, so for every request you have full control over the response by modifying the filter as required. GoServe will never send data to a client without the filter being involved.

The filter is cached (that is, it and its tokenized version are only read from disk when changed) and is executed on the same thread as the incoming request (not as a separate process). This is very efficient; informal measurements suggest that only a small percentage of the total response time of a simple request is spent in running the filter. For example, the total time to run the sample filter on a 486/50MHz PC has been measured under OS/2 2.11 to be as little as 11ms.

For examples of filters and forms processing, please see the sample filters in the GoHTTP or GoGopher collections. The following is specific technical information on how the filters work.

Three argument strings are passed to the filter:

  1. The source of the request. This has five words [more words could be added at the end in the future], separated by one or more blanks:

    Example: "9.15.11.189 80 101 9.20.25.65 1987"

  2. The request string.

    You have complete freedom in setting request strings in Web documents and Gopher menus, and in deciding how the filter should respond depending on the string received. Very often, the name of a file is used, and that file is sent to the client. [Note: it is recommended that fully qualified filenames NOT be used for request strings.]

  3. The extended request string.

The filter can specify that GoServe send either a file or a single string to the client, or request certain other GoServe operations. All these operations are effected in the usual Rexx way, by using commands, which are described later in this document. Other commands allow more detailed control of the server.

The filter may also return a result string to GoServe; this, too, is treated as a command. [In early versions of GoServe, this was the only way to execute a GoServe command, so early GoServe filters only use that mechanism.]

In addition to the commands, GoServe provides several special-purpose functions for dealing with incoming requests. For example, the PACKUR(string) function takes a string which has been encoded for safe transmission, and reduces escape sequences (such as '%7E') to the character encoding that they represent (in this case, '~').

Any failure of the filter (such as a syntax error) is considered catastrophic and will cause GoServe to end.

Notes:

  1. Remember that GoServe will run multiple copies of the filter at once, on different threads, if more than one client connects at the same time. If building temporary files, use the transaction number and port as part of the file name.
  2. The results of SAY instructions (or tracing) in the filter program may be seen using the PMprintf package. However, Rexx interactive tracing is not supported. PMprintf should be available from the same source as GoServe, or from the GoServe Web page at http://www2.hursley.ibm.com/goserve/
  3. You may change the name of the filter when starting GoServe or by using the 'Filter selection' options page. The filter must always be in the working directory for GoServe. If you make changes to the default filter, it's a good idea to change its name, too, so if you install a new version of GoServe your filter will not be overwritten by the new default filter.
  4. External subroutines, written in Rexx, are easily called from the filter simply by using their name in a CALL instruction or function call. The names should not match that of a Rexx built-in function, and the routine should normally be in a file with the same extension (e.g, '.80') as the filter and in the same directory.
  5. You can execute OS/2 commands from the filter using the Address CMD instruction, for example:
      address cmd
      'start e foo.bar'
      'call d:\foobar\test.cmd argstring'
    

    Use caution when calling external programs before the response is complete: any slowness directly affects the response time to the client and its user. Note also that separate processes (including external commands) are not terminated automatically by GoServe if a connection times out.

    Finally, when executing commands, do not build any part of the command string from data received from the client; this could allow execution of arbitrary commands on your server (for example, if an '&' command separator character were included in the data).

  6. By default, each copy of a filter may have up to five files open at once. This limit may be increased using the Limits selection dialog (see elsewhere).
  7. A new version of the filter is only cached (loaded) when GoServe is idle, and has been idle for 5-10 seconds. Therefore, if you change the filter while GoServe is running, the changes will not be used until the first client connects after a time when there have been no clients connected for ten seconds.
  8. For more information on Rexx, try connecting to the Rexx Language page at: http://rexx.hursley.ibm.com/rexx/
  9. For more information on OS/2, try connecting to the IBM Almaden Research Center server, at index.almaden.ibm.com. Both Web and Gopher clients are supported (the server runs GoServe). The IBM home page (http://www.ibm.com) is another good starting point for OS/2 information (use the Search option).

[ previous section | GoServe | next section ]

From 'goserve.doc', version 2.32.
Copyright © International Business Machines Corporation, 1993, 1995.
All rights reserved.