1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
<HTML><HEAD>
<TITLE>C Examples -- Example 1: nshello</TITLE>
<LINK rel=Previous href="c-app.htm">
<LINK rel=ToC href="toc.htm">
<LINK rel=Index href="master.htm">
<LINK rel=Next href="c-app2.htm">
</HEAD><BODY BGCOLOR="#ffffff"><A NAME="topofpage"></A>
<TABLE WIDTH=100%>
<TR>
<TD ALIGN=LEFT>
<A NAME="topofpage"></A> <IMG SRC="as-c-sm.gif">
</TD>
<TD ALIGN=RIGHT>
<A href="c-app.htm"><IMG BORDER="0" src=navbprev.gif alt="[ Previous ]"></A>
<A href=toc.htm> <IMG BORDER="0" src=navbhome.gif alt="[ Contents ]"></A>
<A href=master.htm> <IMG BORDER="0" src=navbhelp.gif alt="[ Index ]"></A>
<A href="c-app2.htm"> <IMG BORDER="0" src=navbnext.gif alt="[ Next ]"></A>
<A name="7983"> </A>
</TD>
</TR>
</TABLE>
<a name="17805">
</a><h3>Example 1: nshello</h3>
<p><a name="14947">
</a>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.</p>
<p><a name="14881">
</a>This example can be found in the <code>examples/c/nshello</code> directory.</p>
<pre> <a name="14873"></a>
<a name="15043"></a>
<a name="15044"></a>#include "ns.h"
<a name="15050"></a>/*
<a name="15051"></a> * This is the simplest possible example of adding a C module
<a name="15052"></a> * to the AOLserver.
<a name="15053"></a> */
<a name="15054"></a>
<a name="15055"></a>/*
<a name="15056"></a> * The Ns_ModuleVersion exported integer is used to verify
<a name="15057"></a> * this module version when loaded. For AOLserver 2.0,
<a name="15058"></a> * 1 (one) is the only valid value for this variable.
<a name="15059"></a> */
<a name="15060"></a>int Ns_ModuleVersion = 1;
<a name="15061"></a>
<a name="15062"></a>static Ns_OpProc Hello;
<a name="15063"></a>
<a name="15064"></a>/*
<a name="15065"></a> * The Ns_ModuleInit function is the function the AOLserver
<a name="15066"></a> * will call each time the module is loaded into a
<a name="15067"></a> * server. The function is passed two parameters:
<a name="15068"></a> *
<a name="15069"></a> * hServer: The server `handle' as a string. This is the
<a name="15070"></a> * short name given to the virutal server such
<a name="15071"></a> * as `server1'.
<a name="15072"></a> *
<a name="15073"></a> * hModule: The module `handle' as a string. This is the
<a name="15074"></a> * short name given to the module such as `hello'
<a name="15075"></a> *
<a name="15076"></a> * For example, if this module is known as `hello' and loaded
<a name="15077"></a> * into the `server1' server with entries similar to the following
<a name="15078"></a> * in the nsd.ini file:
<a name="15079"></a> *
<a name="15080"></a> * [ns\servers]
<a name="15081"></a> * server1=My First Server
<a name="15082"></a> *
<a name="15083"></a> * [ns\server1\modules]
<a name="15084"></a> * hello=hello.dll ; or hello.so on Unix platforms
<a name="15085"></a> *
<a name="15086"></a> * This function would be called with "server1" and "hello" as
<a name="15087"></a> * its arguments.
<a name="15088"></a> *
<a name="15089"></a> */
<a name="15090"></a>int
<a name="15091"></a>Ns_ModuleInit(char *hServer, char *hModule)
<a name="15092"></a>{
<a name="15093"></a> Ns_RegisterRequest(hServer, "GET", "/helloworld", Hello,
<a name="15110"></a> NULL, NULL, 0);
<a name="15094"></a> return NS_OK;
<a name="15095"></a>}
<a name="15096"></a>
<a name="15097"></a>static int
<a name="15098"></a>Hello(Ns_OpContext context, Ns_Conn *conn)
<a name="15099"></a>{
<a name="15100"></a> char html[]="<HTML><BODY>Hello World.</BODY></HTML>";
<a name="15101"></a> Ns_ConnReturnHtml(conn, 200, html, strlen(html));
<a name="15102"></a> return NS_OK;
<a name="15103"></a>}
<a name="15104"></a>
<a name="15105"></a>
</pre><p>
<TABLE BORDER="2" CELLPADDING="1" width="100%">
<TR><TD COLSPAN=3><P ALIGN=Center>
<IMG SRC="bluebult.gif">
<A HREF="#topofpage">
<FONT SIZE=-1>Top of Page</FONT></A>
<IMG SRC="bluebult.gif">
</TD></TR>
<TR><TD COLSPAN=3><P ALIGN=Center>
<A href="c-app.htm">
<IMG BORDER="0" src=navbprev.gif alt="[ Previous ]"></A>
<A href=toc.htm>
<IMG BORDER="0" src=navbhome.gif alt="[ Contents ]"></A>
<A href=master.htm>
<IMG BORDER="0" src=navbhelp.gif alt="[ Index ]"></A>
<A href="c-app2.htm">
<IMG BORDER="0" src=navbnext.gif alt="[ Next ]"></A>
<BR align=center>
<FONT size=-1>Copyright © 1998-99 America Online,
Inc.</FONT>
</TD></TR></TABLE></BODY></HTML>
|