Chapter 7. Writing Server API programs
Overview of the Server API
The Server API allows you to extend the server’s base functions. You can write
extensions to do customized processing, such as:
v Enhance the basic authentication or replace it with a site-specific process.
v Add error handling routines to track problems or alert for serious conditions.
v Detect and track information that comes in from the requesting client, such as
server referrals and user agent code.
General procedure for writing Server API programs
Before you start writing your Server API programs, you need to understand how
the IBM HTTP Server works. The server performs a sequence of steps for each
client request that it processes. Your program can run and make function calls at
any of these steps. You need to decide where in the basic server request process
you want to add customized functions. For example, do you want the server to do
something after it reads a client request but before it performs any other
processing? Or, maybe you want the server to perform special routines during
authentication and then after it sends the requested file.
You can instruct the server to call the application functions in your program at the
appropriate processing step. You can do this by using the API directives in your
server configuration file.
Guidelines
Use the following guidelines when creating Server API programs:
v If compiling on AS/400 with Integrated Language Environment (ILE)/C, ensure
that you include QHTTPSVR in the library list.
v Give each of your application functions a unique function name and call the
server predefined functions as needed. Be sure to include HTAPI.h and to use
the HTTPD_LINKAGE macro in your function definitions to avoid abending the
server. This macro ensures that all functions use the same calling conventions.
v The server runs in a multithreaded environment; therefore, your application
functions must be threadsafe. If your application is re-entrant, performance will
not decrease.
v Keep the actions in your applications to a thread scope. Do not perform any
actions as a process scope, such as exit or change user ID.
v Eliminate global variables or protect them with a mutual exclusion semaphore.
v Do not forget to set the Content-Type header if you are using HTTPD_write() to
send data back to the client.
v You also must take into consideration the Content-Encoding header when you
use HTTPD_write() to send data back to the client.
v Always check your return codes and provide conditional processing where
necessary.
v Compile and then create your service program by using CRTSRVPGM. When
using CRTSRVPGM, you must bind to QZHBIAPI *SRVPGM that is in the
QHTTPSVR library.
© Copyright IBM Corp. 1997, 2000 109