Configuring and Managing MPE/iX Internet Services (August 2002)
Chapter 9
HP WebWise MPE/iX Secure Web Server
Sample Module Code (mod_hw)
177
Sample Module Code (mod_hw)
This section contains source code for the sample DSO module discussed in the previous sections, mod_hw.so.
The module source code consists of two files, mod_hw.c and hw.c. Mod_hw.c contains the module structure
and hw.c contains a function called by mod_hw.c.
mod_hw.c
Mod_hw.c is a simple Apache module. It calls pow() (in the math library, /lib/libm) and helloworld() in
hw.c. This example is designed to illustrate the use of external function calls.
shell/iX> cat mod_hw.c
#include <stdlib.h>
#include <math.h>
#include "httpd.h"
#include "http_config.h"
#include "http_core.h"
#include "http_log.h"
#include "http_protocol.h"
/* here’s the content handler */
static int hw_handler(request_rec *r) {
double root = 12;
double power = 2;
r->content_type = "text/html";
ap_send_http_header(r);
helloworld(r);
ap_rprintf(r, "\nresult of %.2lf**%.2lf is %.2lf",root,power,pow(root,power));
return OK;
}
/* Make the name of the content handler known to Apache */
static handler_rec hw_handlers[] =
{
{"hw-handler", hw_handler},
{NULL}
};
/* Tell Apache what phases of the transaction we handle */
module MODULE_VAR_EXPORT hw_module =
{
STANDARD_MODULE_STUFF,
NULL, /* module initializer */
NULL, /* per-directory config creator */
NULL, /* dir config merger */
NULL, /* server config creator */
NULL, /* server config merger */
NULL, /* command table */
hw_handlers, /* [7] content handlers */