Converting Existing CGI Scripts to ISAPI Extensions
This section explains the basic requirements for converting existing CGI script executable files to ISAPI extension DLLs. As with other DLLs, Web server applications must be thread-safe. As more than one client will be running the same function at the same time, the code must follow safety procedures in modifying a global or static variable.
You can keep your ISAPI extension thread-safe by using appropriate synchronization techniques, such as creating critical sections and semaphores. For additional information about writing thread-safe DLLs, see the documentation in the Platform SDK and in the Microsoft Development Library.
There are several structural differences between an ISAPI extension and a CGI executable file. An ISAPI extension:
- Receives most of its data through the lpbData member of the EXTENSION_CONTROL_BLOCK structure, as opposed to reading the data from the standard input (STDIN) handle for the process. For any additional data, the extension uses the ReadClient Function callback function.
- Sends data back to the client with the WriteClient Function callback function instead of writing to the standard output (STDOUT) handle for the process.
- Accesses common CGI variables through the EXTENSION_CONTROL_BLOCK structure. For other variables, GetServerVariable Function is called. In a CGI executable file, these are retrieved from the environment table by using getenv.
- Specifies completion status by either sending the header directly using the WriteClient Function callback function, or calls the HSE_REQ_SEND_RESPONSE_HEADER_EXServerSupportFunction Function, instead of sending a "Status: NNN xxxxx..." to STDOUT.
- Redirects requests with a Location: or URL: header. If the URL is local, instead of writing the header to STDOUT, use the HSE_REQ_SEND_URL. However, if the URL is remote or unknown, use HSE_REQ_SEND_URL_REDIRECT_RESP in the ServerSupportFunction Function callback function.