This section discusses two Service() function examples: one simple and one more complex.
This section describes a very simple Service function called simple_service. This function sends a message in response to a client request. The message is initialized by the init_simple_service function during server initialization.
To load the shared object containing your functions, add the following directive in the Init section of the magnus.conf file:
Init fn=load-modules shlib=yourlibrary funcs=simple-service-init,simple-service |
To call the simple-service-init function to initialize the message representing the generated output, add the following directive to the Init section in magnus.conf. This directive must come after the directive that loads the library containing simple-service-init.
Init fn=simple-service-init generated-output="<H1>Generated-output-msg</H1>" |
To execute the custom SAF during the request-response process for an object, add the following code to that object in the obj.conf file:
Service type="text/html" fn=simple-service
The type="text/html" argument indicates that this function is invoked during the Service stage only if the content-type has been set to text/html.
The source code for this example is in the service.c file in the install-dir/samples/nsapi directory.
The send-images function is a custom SAF that replaces the doit.cgi demonstration available on the iPlanet home pages. When a file is accessed as /dir1/dir2/something.picgroup, the send-images function checks whether the file is being accessed by a Mozilla1.1 browser. If not, the function sends a short error message. The file something.picgroup contains a list of lines, each of which specifies a file name followed by a content-type. For example, one.gif image/gif.
To load the shared object containing your function, add the following directive at the beginning of the magnus.conf file:
Init fn=load-modules shlib=your-library funcs=send-images
Also, add the following line to the mime.types file:
type=magnus-internal/picgroup exts=picgroup
To execute the custom SAF during the request-response process for an object, add the following code to that object in the obj.conf file. send-images takes an optional parameter, delay, which is not used for this example.
Service method=(GET|HEAD) type=magnus-internal/picgroup fn=send-images |
The source code for this example is in the service.c file in the install-dir/samples/nsapi directory.