[ Previous ] [ Contents ] [ Index ] [ Next ]

Ns_RegisterShtmlCmd

Overview

Register a new server-parsed HTML command

Syntax

    int Ns_RegisterShtmlCmd (
    	char					*hServer,
    	char					*cmd,
    	Ns_ShtmlCmdProc					*proc,
    	void					*context
    );
    
    typedef int (Ns_ShtmlCmdProc) (
    	Ns_ParseHandle					*handle,
    	void					*context
    );

Description

The Ns_RegisterShtmlCmd function registers a new server-parsed HTML command named cmd on the specified server. The proc argument (of type Ns_ShtmlCmdProc) is the function that performs the command. Inside an Ns_ShtmlCmdProc, you can use the following constructs:

    EXTERN int Ns_ParseAppend(Ns_ParseHandle *handle, char *data);
    EXTERN int Ns_ParseVarAppend(Ns_ParseHandle *handle,...);
    EXTERN int Ns_ParsePrintf(Ns_ParseHandle *handle, char *fmt,..);
    
    #define Ns_ParseConn(handle) ((handle)->conn)
    #define Ns_ParseOptions(handle) ((handle)->options)
    #define Ns_ParseFilename(handle) ((handle)->filename)
    #define Ns_ParseByteOffset(handle) ((handle)->byteoffset)
    #define Ns_ParseConfig(handle) ((handle)->config)
    #define Ns_ParseParams(handle) ((handle)->params)

The return value of the proc is an HTTP status.

Example

This is the source code for the new nstcl server-parsed HTML command. It illustrates the use of the Ns_RegisterShtmlCmd function.

    Ns_RegisterShtmlCmd(hServer, "nstcl", cmdNstcl, NULL);
    static int 
    cmdNstcl(Ns_ParseHandle * handle, void *context)
    {
        int             status;
        char           *script;
        status = 500;
        if ((script = Ns_SetGet(handle->params, "script")) != NULL) {
            Ns_DString      dsBuf;
            Ns_DStringInit(&dsBuf);
            if (Ns_TclEval(&dsBuf, Ns_ConnServer(handle->conn),
          script)!= NS_ERROR) {
                Ns_ParseAppend(handle, dsBuf.string);
                status = 200;
            } else {
                Ns_Log(Error, 
            "ParseHTML: Tcl script \"%s\" encountered an 
            error.", script);
            }
            Ns_DStringFree(&dsBuf);
        } else {
            Ns_Log(Error, 
          "ParseHTML: No Tcl script specified near byte"
          " offset %d.", handle->byteoffset);
        }
        return status;
    }

Top of Page

[ Previous ] [ Contents ] [ Index ] [ Next ]
Copyright © 1996 America Online, Inc.