The following example provides a single request function which handles the /helloworld URL, returning 'Hello'. This module is the simplest of the AOLserver example modules.
This example can be found in the examples/c/hello
directory.
#include "ns.h" /* * This is the simplest possible example of adding a C module * to the AOLserver. */ /* * The Ns_ModuleVersion exported integer is used to verify * this module version when loaded. For AOLserver 2.0, * 1 (one) is the only valid value for this variable. */ DllExport int Ns_ModuleVersion = 1; static Ns_OpProc Hello; /* * The Ns_ModuleInit function is the function the AOLserver * will call each time the module is loaded into a virtual * server. The function is passed two parameters: * * hServer: The server `handle' as a string. This is the * short name given to the virutal server such * as `server1'. * * hModule: The module `handle' as a string. This is the * short name given to the module such as `hello' * * For example, if this module is known as `hello' and loaded * into the `server1' server with entries similar to the following * in the nsd.ini file: * * [ns\servers] * server1=My First Server * * [ns\server1\modules] * hello=hello.dll ; or hello.so on Unix platforms * * This function would be called with "server1" and "hello" as * its arguments. * */ DllExport int Ns_ModuleInit(char *hServer, char *hModule) { Ns_RegisterRequest(hServer, "GET", "/helloworld", Hello, NULL, NULL, 0); return NS_OK; } static int Hello(Ns_OpContext context, Ns_Conn *conn) { char html[]="<HTML><BODY>Hello World.</BODY></HTML>"; Ns_ConnReturnHtml(conn, 200, html, strlen(html)); return NS_OK; }