src/server/nsapi.h

Tue, 06 Sep 2011 22:37:51 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Tue, 06 Sep 2011 22:37:51 +0200
changeset 2
cee3e65e789c
parent 1
3c066d52342d
child 3
137197831306
permissions
-rw-r--r--

added main Makefile

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
 *
 * THE BSD LICENSE
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this
 * list of conditions and the following disclaimer. 
 * Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation
 * and/or other materials provided with the distribution. 
 *
 * Neither the name of the  nor the names of its contributors may be
 * used to endorse or promote products derived from this software without 
 * specific prior written permission. 
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER 
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef PUBLIC_NSAPI_H
#define PUBLIC_NSAPI_H

/*
 * File:        nsapi.h
 *
 * Description:
 *
 *      This file defines an interface for extending the server with
 *      in-process plug-ins.
 */

#ifdef __cplusplus
extern "C" {
#endif

/* NSAPI version defined by this header file */
#define NSAPI_VERSION 303

/* Define USE_NSAPI_VERSION to use a specific NSAPI version at compile time */
#ifdef USE_NSAPI_VERSION
#if USE_NSAPI_VERSION < 300 || USE_NSAPI_VERSION > NSAPI_VERSION
#error This header file does not support the requested NSAPI version
#else
#undef NSAPI_VERSION
#define NSAPI_VERSION USE_NSAPI_VERSION
#endif
#endif

/* --- Begin native platform configuration definitions --- */

#if !defined(XP_WIN32) && !defined(XP_UNIX)
#if defined(WIN32) || defined(_WIN32) || defined(__WIN32__)
#define XP_WIN32
#else
#define XP_UNIX
#endif
#endif

#ifdef XP_UNIX
#define NSAPI_PUBLIC
#define ZERO(ptr, len) memset(ptr, 0, len)
#ifdef AIX
#define TCPLEN_T size_t
#endif
#ifdef HPUX
#define TCPLEN_T int
#endif
#ifndef TCPLEN_T
#define TCPLEN_T socklen_t
#endif
#endif /* XP_UNIX */

#ifdef XP_WIN32
#define NSAPI_PUBLIC __declspec(dllexport)
struct iovec {
    char *iov_base;
    unsigned iov_len;
};
#ifndef S_ISDIR
#define S_ISDIR(mode) ((mode & S_IFMT) == S_IFDIR)
#endif
#ifndef S_ISREG
#define S_ISREG(mode) ((mode & S_IFMT) == S_IFREG)
#endif
#ifndef S_ISLNK
#define S_ISLNK(x) (0)
#endif
#define caddr_t PCHAR
#define NEED_STRCASECMP
#define NEED_STRNCASECMP
#define ZERO(ptr, len) ZeroMemory(ptr, len)
#define TCPLEN_T int
#endif /* XP_WIN32 */

/* --- End native platform configuration definitions --- */

/* --- Begin miscellaneous definitions --- */

/* Used in some places as a length limit on error messages */
#define MAGNUS_ERROR_LEN 1024

/* Carriage return and line feed */
#define CR 13
#define LF 10
#ifdef XP_WIN32
#define ENDLINE "\r\n"
#else
#define ENDLINE "\n"
#endif

/* mime.types file identification line */
#define NCC_MT_MAGIC "#--Netscape Communications Corporation MIME Information"
#define NCC_MT_MAGIC_LEN 55

/* The character which separates extensions with cinfo_find */
#define CINFO_SEPARATOR '.'

/* The maximum length of a line in a mime.types file */
#define CINFO_MAX_LEN 1024

/* The maximum length of an error message */
#define MAX_ERROR_LEN 4096

/*
 * A warning is a minor mishap, such as a 404 being issued.
 */
#define LOG_WARN 0

/* 
 * A misconfig is when there is a syntax error or permission violation in
 * a config file.
 */
#define LOG_MISCONFIG 1

/* 
 * Security warnings are issued when authentication fails, or a host is
 * given a 403 return code.
 */
#define LOG_SECURITY 2

/*
 * A failure is when a request could not be fulfilled due to an internal
 * problem, such as a CGI script exiting prematurely, or a filesystem 
 * permissions problem.
 */
#define LOG_FAILURE 3

/*
 * A catastrophe is a fatal server error such as running out of
 * memory or processes, or a system call failing, or even a server crash. 
 * The server child cannot recover from a catastrophe.
 */
#define LOG_CATASTROPHE 4

/*
 * Informational message, of no concern.
 */
#define LOG_INFORM 5

/*
 * Internal diagnostic message.
 */
#define LOG_VERBOSE 6

/*
 * The time format to use in the error log
 */
#define ERR_TIMEFMT "[%d/%b/%Y:%H:%M:%S]"


/* The fd you will get if you are reporting errors to SYSLOG */
#define ERRORS_TO_SYSLOG NULL

/* Return codes from file I/O routines */
#define IO_OKAY 1
#define IO_ERROR -1
#define IO_EOF 0
#define NETBUF_EOF      -1
#define NETBUF_ERROR    -2
#define NETBUF_FULL     -3

/* The disk page size on this machine. */
#define FILE_BUFFERSIZE 4096

#ifdef XP_UNIX

#define FILE_PATHSEP '/'
#define FILE_PARENT "../"

#elif defined(XP_WIN32)

#define FILE_PATHSEP '/'
#define FILE_PARENT "..\\"

#endif /* XP_WIN32 */

#define NET_INFINITE_TIMEOUT 0
#define NET_ZERO_TIMEOUT -1

#ifdef USE_REGEX
/* WILDPAT uses regular expressions */
#define WILDPAT_VALID(exp)              regexp_valid(exp)
#define WILDPAT_MATCH(str, exp)         regexp_match(str, exp)
#define WILDPAT_CMP(str, exp)           regexp_cmp(str, exp)
#define WILDPAT_CASECMP(str, exp)       regexp_casecmp(str, exp)
#define WILDPAT_USES_REGEXP              1
#else
/* WILDPAT uses shell expressions */
#define WILDPAT_VALID(exp)              shexp_valid(exp)
#define WILDPAT_MATCH(str, exp)         shexp_match(str, exp)
#define WILDPAT_CMP(str, exp)           shexp_cmp(str, exp)
#define WILDPAT_CASECMP(str, exp)       shexp_casecmp(str, exp)
#define WILDPAT_USES_SHEXP              1
#endif

/* Define return codes from WILDPAT_VALID */
#define NON_WILDPAT     -1              /* exp is ordinary string */
#define INVALID_WILDPAT -2              /* exp is an invalid pattern */
#define VALID_WILDPAT   1               /* exp is a valid pattern */

/* Define return codes from regexp_valid and shexp_valid */
#define NON_SXP         NON_WILDPAT     /* exp is an ordinary string */
#define INVALID_SXP     INVALID_WILDPAT /* exp is an invalid shell exp */
#define VALID_SXP       VALID_WILDPAT   /* exp is a valid shell exp */

#define NON_REGEXP      NON_SXP
#define INVALID_REGEXP  INVALID_SXP
#define VALID_REGEXP    VALID_SXP

#define SYSTHREAD_DEFAULT_PRIORITY 16

/* The longest line in the configuration file */
#define CONF_MAXLEN 16384

#define HTTP_DATE_LEN 30
#define HTTP_DATE_FMT "%a, %d %b %Y %T GMT"

/* HTTP status codes */
#define PROTOCOL_CONTINUE 100
#define PROTOCOL_SWITCHING 101
#define PROTOCOL_OK 200
#define PROTOCOL_CREATED 201
#define PROTOCOL_ACCEPTED 202
#define PROTOCOL_NONAUTHORITATIVE 203
#define PROTOCOL_NO_RESPONSE 204
#define PROTOCOL_NO_CONTENT 204
#define PROTOCOL_RESET_CONTENT 205
#define PROTOCOL_PARTIAL_CONTENT 206
#define PROTOCOL_MULTI_STATUS 207
#define PROTOCOL_MULTIPLE_CHOICES 300
#define PROTOCOL_MOVED_PERMANENTLY 301
#define PROTOCOL_REDIRECT 302
#define PROTOCOL_SEE_OTHER 303
#define PROTOCOL_NOT_MODIFIED 304
#define PROTOCOL_USE_PROXY 305
#define PROTOCOL_TEMPORARY_REDIRECT 307
#define PROTOCOL_BAD_REQUEST 400
#define PROTOCOL_UNAUTHORIZED 401
#define PROTOCOL_PAYMENT_REQUIRED 402
#define PROTOCOL_FORBIDDEN 403
#define PROTOCOL_NOT_FOUND 404
#define PROTOCOL_METHOD_NOT_ALLOWED 405
#define PROTOCOL_NOT_ACCEPTABLE 406
#define PROTOCOL_PROXY_UNAUTHORIZED 407
#define PROTOCOL_REQUEST_TIMEOUT 408
#define PROTOCOL_CONFLICT 409
#define PROTOCOL_GONE 410
#define PROTOCOL_LENGTH_REQUIRED 411
#define PROTOCOL_PRECONDITION_FAIL 412
#define PROTOCOL_ENTITY_TOO_LARGE 413
#define PROTOCOL_URI_TOO_LARGE 414
#define PROTOCOL_UNSUPPORTED_MEDIA_TYPE 415
#define PROTOCOL_REQUESTED_RANGE_NOT_SATISFIABLE 416
#define PROTOCOL_EXPECTATION_FAILED 417
#define PROTOCOL_LOCKED 423
#define PROTOCOL_FAILED_DEPENDENCY 424
#define PROTOCOL_SERVER_ERROR 500
#define PROTOCOL_NOT_IMPLEMENTED 501
#define PROTOCOL_BAD_GATEWAY 502
#define PROTOCOL_SERVICE_UNAVAILABLE 503
#define PROTOCOL_GATEWAY_TIMEOUT 504
#define PROTOCOL_VERSION_NOT_SUPPORTED 505
#define PROTOCOL_INSUFFICIENT_STORAGE 507

#define PROTOCOL_VERSION_HTTP09 9
#define PROTOCOL_VERSION_HTTP10 100
#define PROTOCOL_VERSION_HTTP11 101
#define CURRENT_PROTOCOL_VERSION PROTOCOL_VERSION_HTTP11

/* Definitions for HTTP over SSL */
#define HTTPS_PORT 443
#define HTTPS_URL "https"

/* Definitions for HTTP over TCP */
#define HTTP_PORT 80
#define HTTP_URL "http"


#define REQ_MAX_LINE 4096
    
/*
 * The REQ_ return codes. These codes are used to determine what the server
 * should do after a particular module completes its task.
 *
 * Func type functions return these as do many internal functions.
 */

/* The function performed its task, proceed with the request */
#define REQ_PROCEED 0
/* The entire request should be aborted: An error occurred */
#define REQ_ABORTED -1
/* The function performed no task, but proceed anyway */
#define REQ_NOACTION -2
/* Tear down the session and exit */
#define REQ_EXIT -3
/* Restart the entire request-response process */
#define REQ_RESTART -4
/* Too busy to execute this now */
#define REQ_TOOBUSY -5

/* --- End miscellaneous definitions --- */

/* --- Begin native platform includes --- */

#ifdef XP_UNIX
#include <unistd.h>
#include <sys/file.h>
#ifndef HPUX
#include <sys/select.h>
#endif
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/types.h>
#include <sys/uio.h>
#include <fcntl.h>
#include <dirent.h>
#include <pwd.h>
#include <netinet/in.h>
#endif /* XP_UNIX */

#ifdef XP_WIN32
#include <wtypes.h>
#include <winbase.h>
#include <direct.h>
#include <winsock.h>
#endif /* XP_WIN32 */

#include <sys/stat.h>
#include <ctype.h>
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <time.h>

/* --- End native platform includes --- */

/* --- Begin type definitions --- */

/* NOTE: both SYS_FILE and SYS_NETFD are actually NSPR PRFileDesc * and can */
/*       be used with NSPR API calls (after casting them to PRFileDesc *) */

#ifndef SYS_FILE_T
typedef void *SYS_FILE;
#define SYS_FILE_T void *
#endif /* !SYS_FILE_T */

#define SYS_ERROR_FD ((SYS_FILE)-1)

#ifndef SYS_NETFD_T
typedef void *SYS_NETFD;
#define SYS_NETFD_T void *
#endif /* !SYS_NETFD_T */

/* Error value for a SYS_NETFD */
#ifndef SYS_NET_ERRORFD
#define SYS_NET_ERRORFD ((SYS_NETFD)-1)
#endif /* !SYS_NET_ERRORFD */

/*
 * These structures were originally defined in nsapi.h, but those definitions
 * were removed in iPlanet Web Server 4.0.  The contents of these structures
 * are now private to the server implementation and must not be accessed
 * directly.  Instead, use the objset_*, object_*, directive_table_*, and
 * directive_* accessor functions.
 */
typedef struct directive directive;
typedef struct dtable dtable;
typedef struct httpd_object httpd_object;
typedef struct httpd_objset httpd_objset;

/*
 * Type:        filebuffer, filebuf_t
 *
 * Description:
 *
 *      This structure is used to represent a buffered file.  On some
 *      systems the file may be memory-mapped.  A filebuffer is created
 *      by filebuf_open(), and destroyed by filebuf_close().
 *
 * Notes:
 *
 *      Direct access to the members of this structure, not using
 *      macros defined here, is discouraged.
 *
 *      The filebuf alias that used to be defined for this type was
 *      found to conflict with a C++ class of the same name, so it
 *      has been renamed to filebuf_t.
 */
typedef struct filebuffer filebuffer;

/* Version of filebuffer when memory-mapped files are supported */
struct filebuffer {
    SYS_FILE fd;
#ifdef XP_WIN32
    HANDLE fdmap;
#endif
    caddr_t fp;
    int len;

    unsigned char *inbuf;
    int cursize;

    int pos;
    const char *errmsg;
};

/* Return next character or IO_EOF */
#define filebuf_getc(b) ((b)->pos == (b)->len ? IO_EOF : (int)((b)->fp)[(b)->pos++])

#define filebuf_iseof(b) ((b)->pos == (b)->len)

/* C++ streamio defines a filebuf class. */
typedef filebuffer filebuf_t;

#ifdef XP_WIN32
/* Use a filebuffer to read data from a pipe */
#define pipebuf_getc(b) \
 ((b)->pos != (b)->cursize ? (int)((b)->inbuf[(b)->pos++]) : pipebuf_next(b,1))
#endif /* XP_WIN32 */

/*
 * Type:        netbuf
 *
 * Description:
 *
 *      This structure is used to represent a buffered network socket.
 *      It is created by netbuf_open(), and destroyed by netbuf_close().
 *
 * Notes:
 *
 *      Direct access to the members of this structure, not using
 *      macros defined here, is discouraged.
 *
 *      The inbuf field used to be (unsigned char *), but is now
 *      simply (char *).  The value returned by the netbuf_getc()
 *      macro is (int).
 */
typedef struct netbuf netbuf;
struct netbuf {
    SYS_NETFD sd;

    int pos, cursize, maxsize, rdtimeout;
#ifdef XP_WIN32
    CHAR address[64];
#endif /* XP_WIN32 */
    unsigned char *inbuf;
    char *errmsg;
#ifndef XP_WIN32
    char address[64];
#endif /* !XP_WIN32 */
};

/*
 * netbuf_getc gets a character from the given network buffer and returns 
 * it (as an integer).
 * 
 * It will return (int) IO_ERROR for an error and (int) IO_EOF for
 * an error condition or EOF respectively.
 */
#define netbuf_getc(b) \
 ((b)->pos != (b)->cursize ? (int)((b)->inbuf[(b)->pos++]) : netbuf_next(b,1))

/*
 * buffer_error returns the last error that occurred with buffer.  Don't use
 * this unless you know an error occurred.  Independent of network/file type.
 */
#define buffer_error(b) ((b)->errmsg)

/*
 * Type:        sendfiledata
 *
 * Description:
 *
 *      This structure is used to pass arguments to the net_sendfile()
 *      function.  offset and len may be set to 0 to transmit a file in its
 *      entirety.
 */
typedef struct sendfiledata sendfiledata;
struct sendfiledata {
    SYS_FILE fd;         /* file to send */
    size_t offset;       /* offset in file to start sending from */
    size_t len;          /* number of bytes to send from file */
    const void *header;  /* data to send before file */
    int hlen;            /* number of bytes to send before file */
    const void *trailer; /* data to send after file */
    int tlen;            /* number of bytes to send after file */
};

/*
 * Type:        NSAPIIOVec
 *
 * Description:
 *
 *      This structure is used to pass arguments to the net_writev()
 *      and FilterWritevFunc() functions.  
 */
#ifdef _LP64
typedef struct NSAPIIOVec NSAPIIOVec;
struct NSAPIIOVec {
    char *iov_base;
    int iov_len;
};
#else
typedef struct iovec NSAPIIOVec;
#endif /* _LP64 */


/*
 * Type:        cinfo
 *
 * Description:
 *
 *      This is a structure that captures the information in the name/value
 *      pairs on one line of a mime.types file.  A cinfo structure is
 *      stored in the memory-resident database, indexed by each of the
 *      file extensions specified in the "exts" name/value pair.  It
 *      defines various attributes of resources with names containing
 *      the specified file extensions.
 *
 * Notes:
 *
 *      Pointers to cinfo structures returned by this API may or may not
 *      need to freed by the caller.  See the individual function
 *      descriptions.
 *
 *      The strings referenced by the fields of cinfo structures returned
 *      by this API should be considered read-only, and do not need to be
 *      freed by the caller, even when the cinfo structure does.
 */
typedef struct cinfo cinfo;
struct cinfo {
    char *type;
    char *encoding;
    char *language;
};


typedef void* CONDVAR;
typedef void *COUNTING_SEMAPHORE;
typedef void* CRITICAL;

#ifdef XP_UNIX
typedef DIR* SYS_DIR;
typedef struct dirent SYS_DIRENT;
#endif /* XP_UNIX */

#ifdef XP_WIN32

typedef struct dirent_s dirent_s;
struct dirent_s {
    char *d_name;
};

typedef struct dir_s dir_s;
struct dir_s {
    HANDLE dp;
    WIN32_FIND_DATA fdata;
    dirent_s de;
};

typedef dir_s* SYS_DIR;
typedef dirent_s SYS_DIRENT;

#endif /* XP_WIN32 */

typedef struct pb_param pb_param;
struct pb_param {
    char *name,*value;
};

typedef struct pb_entry pb_entry;
struct pb_entry {
    pb_param *param;
    struct pb_entry *next;
};

typedef struct pblock pblock;
struct pblock {
    int hsize;
    struct pb_entry **ht;
};

#ifndef POOL_HANDLE_T
#define POOL_HANDLE_T
typedef void *pool_handle_t;
#endif

#ifndef SEMAPHORE_T
typedef void *SEMAPHORE;
#define SEMAPHORE_T void *
#endif /* !SEMAPHORE_T */

#define SESSION_HASHSIZE 5

typedef struct PListStruct_s PListStruct_s;
typedef struct ACLListHandle ACLListHandle;

#ifndef PR_AF_INET
typedef union PRNetAddr PRNetAddr;
#endif

typedef struct Session Session;
typedef struct Request Request;
struct Session {
    pblock *client;     /* client-specific information */

    SYS_NETFD csd;      /* client file descriptor */
    netbuf *inbuf;      /* input buffer */
    int csd_open;

    struct in_addr iaddr;

    pool_handle_t *pool;

    void *clauth;       /* v2 ACL client authentication information */
    struct Session *next;
    int fill;
    struct sockaddr_in local_addr;      /* local addr for this session */

    PListStruct_s *subject;
    int ssl;            /* 0 = SSL OFF, 1 = SSL ON */
    int clientauth;     /* 0 = client auth OFF, 1 = client auth ON */

    PRNetAddr *pr_client_addr;
    PRNetAddr *pr_local_addr;
};

/*
 * FuncPtr is a pointer to an NSAPI SAF function
 */

#ifdef XP_UNIX
typedef int Func(pblock *, Session *, Request *);
#else /* XP_WIN32 */
typedef int _cdecl Func(pblock *, Session *, Request *);
#endif /* XP_WIN32 */

typedef Func *FuncPtr;

/*
 * FuncStruct is a structure used in the static declaration of the 
 * functions.  This static declaration is parsed into a hash table at 
 * startup.
 */

typedef struct FuncStruct FuncStruct;

struct FuncStruct {
    const char * name;
    FuncPtr func;
    struct FuncStruct *next;
    unsigned flags;
    unsigned poolID;
    unsigned pool_resolved;
};

/*
 * VSInitFunc, VSDestroyFunc, VSDirectiveInitFunc and VSDirectiveDestroyFunc
 */
typedef struct VirtualServer VirtualServer;
typedef int VSInitFunc(VirtualServer *incoming, const VirtualServer *current);
typedef void VSDestroyFunc(VirtualServer *outgoing);
typedef VSInitFunc *VSInitFuncPtr;
typedef VSDestroyFunc *VSDestroyFuncPtr;
typedef int VSDirectiveInitFunc(const directive *dir, VirtualServer *incoming, const VirtualServer *current);
typedef void VSDirectiveDestroyFunc(const directive *dir, VirtualServer *outgoing);
typedef VSDirectiveInitFunc *VSDirectiveInitFuncPtr;
typedef VSDirectiveDestroyFunc *VSDirectiveDestroyFuncPtr;

/*
 * Filter is an opaque filter identifier
 */
typedef struct Filter Filter;

/*
 * FilterContext stores context associated with a particular filter layer
 */

typedef struct FilterContext FilterContext;

struct FilterContext {
    pool_handle_t *pool; /* pool context was allocated from */
    Session *sn;         /* session being processed */
    Request *rq;         /* request being processed */
    void *data;          /* filter-defined private data */
};

/*
 * FilterLayer represents one layer of a filter stack
 */

typedef struct FilterLayer FilterLayer;

struct FilterLayer {
    Filter *filter;         /* the filter at this layer in the filter stack */
    FilterContext *context; /* context for the filter */
    SYS_NETFD lower;        /* access to the next filter layer in the stack */
};

/*
 * Function prototypes for filter methods
 */
typedef int (FilterInsertFunc)(FilterLayer *layer, pblock *pb);
typedef void (FilterRemoveFunc)(FilterLayer *layer);
typedef int (FilterFlushFunc)(FilterLayer *layer);
typedef int (FilterReadFunc)(FilterLayer *layer, void *buf, int amount, int timeout);
typedef int (FilterWriteFunc)(FilterLayer *layer, const void *buf, int amount);
typedef int (FilterWritevFunc)(FilterLayer *layer, const NSAPIIOVec *iov, int iov_size);
typedef int (FilterSendfileFunc)(FilterLayer *layer, sendfiledata *sfd);

/*
 * FilterMethods is passed to filter_create() to declare the filter methods for
 * a new filter.  Each instance of the FilterMethods structure should be
 * initialized using the FILTER_METHODS_INITIALIZER macro.
 */

typedef struct FilterMethods FilterMethods;

struct FilterMethods {
    size_t size;
#if NSAPI_VERSION >= 302
    FilterInsertFunc *insert;
    FilterRemoveFunc *remove;
    FilterFlushFunc *flush;
    FilterReadFunc *read;
    FilterWriteFunc *write;
    FilterWritevFunc *writev;
    FilterSendfileFunc *sendfile;
#else
    void *reserved1;
    void *reserved2;
    void *reserved3;
    void *reserved4;
    void *reserved5;
    void *reserved6;
    void *reserved7;
#endif /* NSAPI_VERSION >= 302 */
};

#define FILTER_METHODS_INITIALIZER \
{                                  \
    sizeof(FilterMethods),         \
    NULL, /* insert */             \
    NULL, /* remove */             \
    NULL, /* flush */              \
    NULL, /* read */               \
    NULL, /* write */              \
    NULL, /* writev */             \
    NULL  /* sendfile */           \
}

/*
 * Filter order definitions for filter_create()
 */
#define FILTER_CONTENT_GENERATION       0xf0000
#define FILTER_CONTENT_TRANSLATION_HIGH 0xa0000
#define FILTER_CONTENT_TRANSLATION      0x90000
#define FILTER_CONTENT_TRANSLATION_LOW  0x80000
#define FILTER_CONTENT_CODING           0x50000
#define FILTER_TRANSFER_CODING          0x40000
#define FILTER_MESSAGE_CODING           0x30000
#define FILTER_TRANSPORT_CODING         0x20000
#define FILTER_NETWORK                  0x10000

typedef struct shmem_s shmem_s;
struct shmem_s {
    void *data;   /* the data */
#ifdef XP_WIN32
    HANDLE fdmap;
#endif /* XP_WIN32 */
    int size;     /* the maximum length of the data */

    char *name;   /* internal use: filename to unlink if exposed */
    SYS_FILE fd;  /* internal use: file descriptor for region */
};

/* Define a handle for a thread */
typedef void* SYS_THREAD;

/* Define an error value for the thread handle */
#define SYS_THREAD_ERROR NULL


typedef struct conf_global_vars_s conf_global_vars_s;
struct conf_global_vars_s {

    /* What port we listen to */
    int Vport;                                  /* OBSOLETE */
#define server_portnum conf_getglobals()->Vport

    /* What address to bind to */
    char *Vaddr;                                /* OBSOLETE */

    /* User to run as */
    struct passwd *Vuserpw;

    /* Directory to chroot to */
    char *Vchr;

    /* Where to log our pid to */
    char *Vpidfn;

#define pool_max conf_getglobals()->Vpool_max
    int Vpool_max;
#define pool_min conf_getglobals()->Vpool_min
    int Vpool_min;                              /* OBSOLETE */
#define pool_life conf_getglobals()->Vpool_life
    int Vpool_life;                             /* OBSOLETE */

    /* For multiprocess UNIX servers, the maximum threads per process */
#define pool_maxthreads conf_getglobals()->Vpool_maxthreads
    int Vpool_maxthreads;

#define pool_minthreads conf_getglobals()->Vpool_minthreads
    int Vpool_minthreads;                       /* OBSOLETE */

    char *Vsecure_keyfn;                        /* OBSOLETE */
    char *Vsecure_certfn;                       /* OBSOLETE */

#define security_active conf_getglobals()->Vsecurity_active
    int Vsecurity_active;
    int Vssl3_active;                           /* OBSOLETE */
    int Vssl2_active;                           /* OBSOLETE */
    int Vsecure_auth;                           /* OBSOLETE */
    int Vsecurity_session_timeout;
    long Vssl3_session_timeout;

    /* The server's hostname as should be reported in self-ref URLs */
#define server_hostname conf_getglobals()->Vserver_hostname
    char *Vserver_hostname;

    /* The main object from which all are derived */
#define root_object conf_getglobals()->Vroot_object
    char *Vroot_object;

    /* The object set the administrator has asked us to load */
#define std_os conf_getglobals()->Vstd_os
    httpd_objset *Vstd_os;

    /* The root of ACL data structures */
    void *Vacl_root;

    /* The main error log, where all errors are logged */
    char *Vmaster_error_log;

    /* The server root directory (contains instance subdirectories) */
#define server_root conf_getglobals()->Vserver_root
    char *Vserver_root;

    /* This server's id */
#define server_id conf_getglobals()->Vserver_id
    char *Vserver_id;

    /* Admin server users file */
    char *Vadmin_users;

    /* The installation directory (contains bin and lib subdirectories) */
    char *Vnetsite_root;

    /* Digest authentication stale nonce timeout value */
    int digest_stale_timeout;

    int single_accept;          /* OBSOLETE */
    int num_keep_alives;        /* OBSOLETE */
    int log_verbose;            /* OBSOLETE */
    int mmap_flags;             /* OBSOLETE */
    int mmap_prots;             /* OBSOLETE */
    int unused1;
    int unused2;

    /* Begin Enterprise 3.0 fields */
    int accept_language;        /* turn accept-language on/off */

    char *mtahost;
    char *nntphost;             /* OBSOLETE */

    /* The root of ACL data structures */
    void *Vacl_root_30;

    char *agentFilePath;        /* OBSOLETE */

    int Allowed;                /* OBSOLETE */

    pblock *genericGlobals;     /* OBSOLETE */

    char *agentsACLFile;        /* OBSOLETE */

    int wait_for_cgi;           /* OBSOLETE */
    int cgiwatch_timeout;       /* OBSOLETE */
    int started_by_watchdog;
    int restarted_by_watchdog;
    int old_accel_cache_enabled; /* OBSOLETE */
    int Vssl_cache_entries;
    int blocking_listen_socket; /* OBSOLETE */
    pblock **initfns;
    char *vs_config_file;       /* OBSOLETE */
};

/* Type used for Request rq_attr bit flags */
#ifdef AIX
#define RQATTR unsigned
#else
#define RQATTR unsigned long
#endif

struct Request {
    /* Server working variables */
    pblock *vars;

    /* The method, URI, and protocol revision of this request */
    pblock *reqpb;
    /* Protocol specific headers */
    int loadhdrs;
    pblock *headers;

    /* Server's response headers */
    int senthdrs;
    pblock *srvhdrs;

    /* The object set constructed to fulfill this request */
    httpd_objset *os;
    /* Array of objects that were created from .nsconfig files */
    httpd_objset *tmpos;

    /* The stat last returned by request_stat_path */
    char *statpath;
    char *staterr;
    struct stat *finfo;

    /* access control state */
    int aclstate;               /* ACL decision state */
    int acldirno;               /* deciding ACL directive number */
    char *aclname;              /* name of deciding ACL */
    pblock *aclpb;              /* OBSOLETE */
    /* 3.0 ACL list pointer */
    ACLListHandle *acllist;

    int request_is_cacheable;   /* */
    int directive_is_cacheable; /* set by SAFs with no external side effects that make decisions based solely on URI and path */

    char *cached_headers;       /* OBSOLETE */
    int cached_headers_len;     /* OBSOLETE */
    char *unused;

    /* HTTP/1.1 features */
#define REQ_TIME(x)             (x)->req_start
    time_t req_start;           /* time request arrived - used for selecting weak or strong cache validation */
    short protv_num;            /* protocol version number */
    short method_num;           /* method number */
    struct rq_attr {
        RQATTR abs_uri:1;               /* set if absolute URI was used */
        RQATTR chunked:1;               /* chunked transfer-coding */
        RQATTR keep_alive:1;            /* connection keep-alive */
        RQATTR pipelined:1;             /* request packet is pipelined */
        RQATTR internal_req:1;          /* this was an internal request */
        RQATTR perm_req:1;              /* don't FREE() this request */
        RQATTR header_file_present:1;   /* OBSOLETE */
        RQATTR footer_file_present:1;   /* OBSOLETE */
        RQATTR jvm_attached:1;          /* OBSOLETE */
        RQATTR req_restarted:1;         /* request was restarted */
        RQATTR jvm_request_locked:1;    /* used for first-request serialization on some platforms */
        RQATTR default_type_set:1;      /* set if default types were set using set-default-type objecttype function */
        RQATTR is_web_app:1;            /* OBSOLETE */
        RQATTR ssl_unclean_shutdown:1;  /* set if browser requires unclean SSL shutdown */
        RQATTR vary_accept_language:1;  /* set if request was restarted based on an accept-language header */
        RQATTR reserved:17;             /* if you add a flag, make sure to subtract from this */
    } rq_attr;
    char *hostname;             /* hostname used to access server (always non-NULL) */
    int allowed;                /* OBSOLETE */
    int byterange;              /* OBSOLETE */
    short status_num;           /* HTTP status code */

    int staterrno;              /* used for rqstat */
    Request *orig_rq;           /* original Request - used for internal redirects */
};

/* Request attribute macros */
#define ABS_URI(x)                      (x)->rq_attr.abs_uri
#define CHUNKED(x)                      (x)->rq_attr.chunked
#define KEEP_ALIVE(x)                   (x)->rq_attr.keep_alive 
#define PIPELINED(x)                    (x)->rq_attr.pipelined 
#define INTERNAL_REQUEST(x)             (x)->rq_attr.internal_req 
#define RESTARTED_REQUEST(x)            (x)->rq_attr.req_restarted
#define PERM_REQUEST(x)                 (x)->rq_attr.perm_req
#define JVM_REQUEST_LOCKED(x)           (x)->rq_attr.jvm_request_locked
#define SSL_UNCLEAN_SHUTDOWN(x)         (x)->rq_attr.ssl_unclean_shutdown
#define VARY_ACCEPT_LANGUAGE(x)         (x)->rq_attr.vary_accept_language

/* Define methods for HTTP/1.1 */
#define METHOD_HEAD     0
#define METHOD_GET      1
#define METHOD_PUT      2
#define METHOD_POST     3
#define METHOD_DELETE   4
#define METHOD_TRACE    5
#define METHOD_OPTIONS  6
/* The following methods are Netscape method extensions */
#define METHOD_MOVE     7
#define METHOD_INDEX    8
#define METHOD_MKDIR    9
#define METHOD_RMDIR    10
#define METHOD_COPY     11
#define METHOD_MAX      12      /* Number of methods available on this server */

#define ISMGET(r)       ((r)->method_num == METHOD_GET)
#define ISMHEAD(r)      ((r)->method_num == METHOD_HEAD)
#define ISMPUT(r)       ((r)->method_num == METHOD_PUT)
#define ISMPOST(r)      ((r)->method_num == METHOD_POST)
#define ISMDELETE(r)    ((r)->method_num == METHOD_DELETE)
#define ISMMOVE(r)      ((r)->method_num == METHOD_MOVE)
#define ISMINDEX(r)     ((r)->method_num == METHOD_INDEX)
#define ISMMKDIR(r)     ((r)->method_num == METHOD_MKDIR)
#define ISMRMDIR(r)     ((r)->method_num == METHOD_RMDIR)
#define ISMCOPY(r)      ((r)->method_num == METHOD_COPY)
#define ISMTRACE(r)     ((r)->method_num == METHOD_TRACE)
#define ISMOPTIONS(r)   ((r)->method_num == METHOD_OPTIONS)


/* --- End type definitions --- */

/* --- Begin dispatch vector table definition --- */

typedef struct nsapi_dispatch_s nsapi_dispatch_t;
struct nsapi_dispatch_s {
    char *(*f_system_version)();
    void *(*f_system_malloc)(int size);
    void *(*f_system_calloc)(int size);
    void *(*f_system_realloc)(void *ptr, int size);
    void (*f_system_free)(void *ptr);
    char *(*f_system_strdup)(const char *ptr);
    void *(*f_system_malloc_perm)(int size);
    void *(*f_system_calloc_perm)(int size);
    void *(*f_system_realloc_perm)(void *ptr, int size);
    void (*f_system_free_perm)(void *ptr);
    char *(*f_system_strdup_perm)(const char *ptr);
    int (*f_getThreadMallocKey)(void);
    void (*f_magnus_atrestart)(void (*fn)(void *), void *data);
    filebuf_t *(*f_filebuf_open)(SYS_FILE fd, int sz);
    netbuf *(*f_netbuf_open)(SYS_NETFD sd, int sz);
    filebuf_t *(*f_filebuf_create)(SYS_FILE fd, caddr_t mmap_ptr,
                                   int mmap_len, int bufsz);
    void (*f_filebuf_close_buffer)(filebuf_t *buf, int clean_mmap);
    filebuf_t *(*f_filebuf_open_nostat)(SYS_FILE fd, int sz,
                                        struct stat *finfo);
#ifdef XP_WIN32
    filebuf_t *(*f_pipebuf_open)(SYS_FILE fd, int sz, struct stat *finfo);
#else
    void *(*f_pipebuf_open)(void);
#endif /* XP_WIN32 */
    int (*f_filebuf_next)(void);
    int (*f_netbuf_next)(netbuf *buf, int advance);
#ifdef XP_WIN32 
    int (*f_pipebuf_next)(filebuf_t *buf, int advance);
#else
    int (*f_pipebuf_next)(void);
#endif /* XP_WIN32 */
    void (*f_filebuf_close)(filebuf_t *buf);
    void (*f_netbuf_close)(netbuf *buf);
#ifdef XP_WIN32
    void        (*f_pipebuf_close)(filebuf_t *buf);
#else
    void (*f_pipebuf_close)(void);
#endif /* XP_WIN32 */
    int (*f_filebuf_grab)(filebuf_t *buf, int sz);
    int (*f_netbuf_grab)(netbuf *buf, int sz);
#ifdef XP_WIN32
    int (*f_pipebuf_grab)(filebuf_t *buf, int sz);
#else
    int (*f_pipebuf_grab)(void);
#endif /* XP_WIN32 */
    int (*f_netbuf_buf2sd)(netbuf *buf, SYS_NETFD sd, int len);
    int (*f_filebuf_buf2sd)(filebuf_t *buf, SYS_NETFD sd);
#ifdef XP_WIN32
    int (*f_pipebuf_buf2sd)(filebuf_t *buf, SYS_NETFD sd, int len);
    int (*f_pipebuf_netbuf2sd)(netbuf *buf, SYS_FILE sd, int len);
    int (*f_pipebuf_netbuf2pipe)(netbuf *buf, SYS_NETFD sd, int len);
#else
    int (*f_pipebuf_buf2sd)(void);
    int (*f_pipebuf_netbuf2sd)(void);
    int (*f_pipebuf_netbuf2pipe)(void);
#endif /* XP_WIN32 */
    void (*f_cinfo_init)(void);
    void (*f_cinfo_terminate)(void);
    char *(*f_cinfo_merge)(char *fn);
    cinfo *(*f_cinfo_find)(char *uri);
    cinfo *(*f_cinfo_lookup)(char *type);
    void (*f_cinfo_dump_database)(FILE *dump);
    CRITICAL (*f_crit_init)(void);
    void (*f_crit_enter)(CRITICAL id);
    void (*f_crit_exit)(CRITICAL id);
    void (*f_crit_terminate)(CRITICAL id);
    CONDVAR (*f_condvar_init)(CRITICAL id);
    void (*f_condvar_wait)(CONDVAR cv);
    void (*f_condvar_notify)(CONDVAR cv);
    void (*f_condvar_notifyAll)(CONDVAR cv);
    void (*f_condvar_terminate)(CONDVAR cv);
    COUNTING_SEMAPHORE (*f_cs_init)(int initial_count);
    void (*f_cs_terminate)(COUNTING_SEMAPHORE csp);
    int (*f_cs_wait)(COUNTING_SEMAPHORE csp);
    int (*f_cs_trywait)(COUNTING_SEMAPHORE csp);
    int (*f_cs_release)(COUNTING_SEMAPHORE csp);
    void (*f_daemon_atrestart)(void (*fn)(void *), void *data);
    /* Obsolete: servssl_init() */
    void (*f_servssl_init)(void);
    int (*f_ereport)(int degree, const char *fmt, ...);
    int (*f_ereport_v)(int degree, const char *fmt, va_list args);
    char *(*f_ereport_init)(const char *err_fn, const char *email,
                            struct passwd *pwuser, const char *version,
                            int restart);
    void (*f_ereport_terminate)(void);
    SYS_FILE (*f_ereport_getfd)(void);
    SYS_FILE (*f_system_fopenRO)(const char *path);
    SYS_FILE (*f_system_fopenWA)(const char *path);
    SYS_FILE (*f_system_fopenRW)(const char *path);
    SYS_FILE (*f_system_fopenWT)(const char *path);
    int (*f_system_fread)(SYS_FILE fd, void *buf, int sz);
    int (*f_system_fwrite)(SYS_FILE fd, const void *buf,int sz);
    int (*f_system_fwrite_atomic)(SYS_FILE fd, const void *buf, int sz);
    int (*f_system_lseek)(SYS_FILE fd, int off, int wh);
    int (*f_system_fclose)(SYS_FILE fd);
    int (*f_system_stat)(const char *name, struct stat *finfo);
    int (*f_system_rename)(const char *oldpath, const char *newpath);
    int (*f_system_unlink)(const char *path);
    int (*f_system_tlock)(SYS_FILE fd);
    int (*f_system_flock)(SYS_FILE fd);
    int (*f_system_ulock)(SYS_FILE fd);
#ifdef XP_WIN32
    SYS_DIR (*f_dir_open)(const char *path);
    SYS_DIRENT *(*f_dir_read)(SYS_DIR ds);
    void (*f_dir_close)(SYS_DIR ds);
#else
    void *(*f_dir_open)(void);
    void *(*f_dir_read)(void);
    void (*f_dir_close)(void);
#endif /* XP_WIN32 */
    int (*f_dir_create_all)(char *dir);
#ifdef XP_WIN32
    void *(*f_system_winsockerr)(void);
    void *(*f_system_winerr)(void);
    int (*f_system_pread)(SYS_FILE fd, void *buf, int sz);
    int (*f_system_pwrite)(SYS_FILE fd, const void *buf, int sz);
    void (*f_file_unix2local)(const char *path, char *p2);
#else
    void *(*f_system_winsockerr)(void);
    void *(*f_system_winerr)(void);
    int (*f_system_pread)(void);
    int (*f_system_pwrite)(void);
    void (*f_file_unix2local)(void);
#endif /* XP_WIN32 */
    int (*f_system_nocoredumps)(void);
    int (*f_file_setinherit)(SYS_FILE fd, int value);
    int (*f_file_notfound)(void);
    char *(*f_system_errmsg)(void);
    int (*f_system_errmsg_fn)(char **buff, size_t maxlen);
    SYS_NETFD (*f_net_socket)(int domain, int type, int protocol);
    int (*f_net_listen)(SYS_NETFD s, int backlog);
    SYS_NETFD (*f_net_create_listener)(const char *ipaddr, int port);
    int (*f_net_connect)(SYS_NETFD s, const void *sockaddr, int namelen);
    int (*f_net_getpeername)(SYS_NETFD s, struct sockaddr *name, int *namelen);
    int (*f_net_close)(SYS_NETFD s);
    int (*f_net_bind)(SYS_NETFD s, const struct sockaddr *name, int namelen);
    SYS_NETFD (*f_net_accept)(SYS_NETFD s, struct sockaddr *addr, int *addrlen);
    int (*f_net_read)(SYS_NETFD sd, void *buf, int sz, int timeout);
    int (*f_net_write)(SYS_NETFD sd, const void *buf, int sz);
    int (*f_net_writev)(SYS_NETFD sd, const NSAPIIOVec *iov, int iovlen);
    int (*f_net_isalive)(SYS_NETFD sd);
    char *(*f_net_ip2host)(const char *ip, int verify);
    int (*f_net_getsockopt)(SYS_NETFD s, int level, int optname,
                            void *optval, int *optlen);
    int (*f_net_setsockopt)(SYS_NETFD s, int level, int optname,
                            const void *optval, int optlen);
    int (*f_net_select)(int nfds, fd_set *r, fd_set *w, fd_set *e, 
                        struct timeval *timeout);
    int (*f_net_ioctl)(SYS_NETFD s, int tag, void *result);
    pb_param *(*f_param_create)(const char *name, const char *value);
    int (*f_param_free)(pb_param *pp);
    pblock *(*f_pblock_create)(int n);
    void (*f_pblock_free)(pblock *pb);
    char *(*f_pblock_findval)(const char *name, const pblock *pb);
    pb_param *(*f_pblock_nvinsert)(const char *name, const char *value, pblock *pb);
    pb_param *(*f_pblock_nninsert)(const char *name, int value, pblock *pb);
    void (*f_pblock_pinsert)(pb_param *pp, pblock *pb);
    int (*f_pblock_str2pblock)(const char *str, pblock *pb);
    char *(*f_pblock_pblock2str)(const pblock *pb, char *str);
    int (*f_pblock_copy)(const pblock *src, pblock *dst);
    pblock *(*f_pblock_dup)(const pblock *src);
    char **(*f_pblock_pb2env)(const pblock *pb, char **env);
    pb_param *(*f_pblock_fr)(const char *name, pblock *pb, int remove);
    char * (*f_pblock_replace)(const char *name,char * new_value,pblock *pb);
    pool_handle_t *(*f_pool_create)(void);
    void (*f_pool_destroy)(pool_handle_t *pool_handle);
    int (*f_pool_enabled)(void);
    void *(*f_pool_malloc)(pool_handle_t *pool_handle, size_t size );
    void (*f_pool_free)(pool_handle_t *pool_handle, void *ptr );
    void *(*f_pool_calloc)(pool_handle_t *pool_handle, size_t nelem, size_t elsize);
    void *(*f_pool_realloc)(pool_handle_t *pool_handle, void *ptr, size_t size );
    char *(*f_pool_strdup)(pool_handle_t *pool_handle, const char *orig_str );
    int (*f_regexp_valid)(const char *exp);
    int (*f_regexp_match)(const char *str, const char *exp);
    int (*f_regexp_cmp)(const char *str, const char *exp);
    int (*f_regexp_casecmp)(const char *str, const char *exp);
    SEMAPHORE (*f_sem_init)(char *name, int number);
    void (*f_sem_terminate)(SEMAPHORE id);
    int (*f_sem_grab)(SEMAPHORE id);
    int (*f_sem_tgrab)(SEMAPHORE id);
    int (*f_sem_release)(SEMAPHORE id);
    Session *(*f_session_alloc)(SYS_NETFD csd, struct sockaddr_in *sac); /* internal */
    Session *(*f_session_fill)(Session *sn); /* internal */
    Session *(*f_session_create)(SYS_NETFD csd, struct sockaddr_in *sac);
    void (*f_session_free)(Session *sn);
    char *(*f_session_dns_lookup)(Session *sn, int verify);
    int (*f_shexp_valid)(const char *exp);
    int (*f_shexp_match)(const char *str, const char *exp);
    int (*f_shexp_cmp)(const char *str, const char *exp);
    int (*f_shexp_casecmp)(const char *str, const char *exp);
    shmem_s *(*f_shmem_alloc)(char *name, int size, int expose);
    void (*f_shmem_free)(shmem_s *region);
    SYS_THREAD (*f_systhread_start)(int prio, int stksz, void (*fn)(void *), void *arg);
    SYS_THREAD (*f_systhread_current)(void);
    void (*f_systhread_yield)(void);
    SYS_THREAD (*f_systhread_attach)(void);
    void (*f_systhread_detach)(SYS_THREAD thr);
    void (*f_systhread_terminate)(SYS_THREAD thr);
    void (*f_systhread_sleep)(int milliseconds);
    void (*f_systhread_init)(char *name);
    void (*f_systhread_timerset)(int usec);
    int (*f_systhread_newkey)(void);
    void *(*f_systhread_getdata)(int key);
    void (*f_systhread_setdata)(int key, void *data);
    void (*f_systhread_set_default_stacksize)(unsigned long size);
    int (*f_util_getline)(filebuffer *buf, int lineno, int maxlen, char *l);
    char **(*f_util_env_create)(char **env, int n, int *pos);
    char *(*f_util_env_str)(const char *name, const char *value);
    void (*f_util_env_replace)(char **env, const char *name, const char *value);
    void (*f_util_env_free)(char **env);
    char **(*f_util_env_copy)(char **src, char **dst);
    char *(*f_util_env_find)(char **env, const char *name);
    char *(*f_util_hostname)(void);
    int (*f_util_chdir2path)(char *path);
    int (*f_util_is_mozilla)(char *ua, char *major, char *minor);
    int (*f_util_is_url)(const char *url);
    int (*f_util_later_than)(const struct tm *lms, const char *ims);
    int (*f_util_time_equal)(const struct tm *lms, const char *ims);
    int (*f_util_str_time_equal)(const char *t1, const char *t2);
    int (*f_util_uri_is_evil)(const char *t);
    void (*f_util_uri_parse)(char *uri);
    void (*f_util_uri_unescape)(char *s);
    char *(*f_util_uri_escape)(char *d, const char *s);
    char *(*f_util_url_escape)(char *d, const char *s);
    char *(*f_util_sh_escape)(char *s);
    int (*f_util_mime_separator)(char *sep);
    int (*f_util_itoa)(int i, char *a);
    int (*f_util_vsprintf)(char *s, register const char *fmt, va_list args);
    int (*f_util_sprintf)(char *s, const char *fmt, ...);
    int (*f_util_vsnprintf)(char *s, int n, register const char *fmt, 
                            va_list args);
    int (*f_util_snprintf)(char *s, int n, const char *fmt, ...);
    int (*f_util_strftime)(char *s, const char *format, const struct tm *t);
    char *(*f_util_strtok)(char *s1, const char *s2, char **lasts);
    struct tm *(*f_util_localtime)(const time_t *clock, struct tm *res);
    char *(*f_util_ctime)(const time_t *clock, char *buf, int buflen);
    char *(*f_util_strerror)(int errnum, char *msg, int buflen);
    struct tm *(*f_util_gmtime)(const time_t *clock, struct tm *res);
    char *(*f_util_asctime)(const struct tm *tm,char *buf, int buflen);
#ifdef NEED_STRCASECMP
    int (*f_util_strcasecmp)(const char *one, const char *two);
#else
    int (*f_util_strcasecmp)(void);
#endif /* NEED_STRCASECMP */
#ifdef NEED_STRNCASECMP
    int (*f_util_strncasecmp)(const char *one, const char *two, int n);
#else
    int (*f_util_strncasecmp)(void);
#endif /* NEED_STRNCASECMP */
#ifdef XP_UNIX
    int (*f_util_can_exec)(struct stat *finfo, uid_t uid, gid_t gid);
    struct passwd *(*f_util_getpwnam)(const char *name, struct passwd
                                      *result, char *buffer,  int buflen);
    pid_t (*f_util_waitpid)(pid_t pid, int *statptr, int options);
#else
    int (*f_util_can_exec)(void);
    void *(*f_util_getpwnam)(void);
    int (*f_util_waitpid)(void);
#endif /* XP_UNIX */
#ifdef XP_WIN32
    VOID (*f_util_delete_directory)(char *FileName, BOOL delete_directory);
#else
    void (*f_util_delete_directory)(void);
#endif /* XP_WIN32 */
    void *(*f_conf_init)(void);
    void *(*f_conf_run_init_functions)(void);
    void (*f_conf_terminate)(void);
    conf_global_vars_s *(*f_conf_getglobals)(void);
    void (*f_func_init)(struct FuncStruct *func_standard);
    FuncPtr (*f_func_find)(char *name);
    int (*f_func_exec)(pblock *pb, Session *sn, Request *rq);
    struct FuncStruct *(*f_func_insert)(char *name, FuncPtr fn);
    int (*f_object_execute)(directive *inst, Session *sn, Request *rq);
    void *(*f_http_find_request)(void);
    int (*f_http_parse_request)(char *t, Request *rq, Session *sn);
    int (*f_http_scan_headers)(void);
    int (*f_http_start_response)(Session *sn, Request *rq);
    char **(*f_http_hdrs2env)(pblock *pb);
    void (*f_http_status)(Session *sn, Request *rq, int n, const char *r);
    int (*f_http_set_finfo)(Session *sn, Request *rq, struct stat *finfo);
    char *(*f_http_dump822)(pblock *pb, char *t, int *pos, int tsz);
    void (*f_http_finish_request)(Session *sn, Request *rq);
    void (*f_http_handle_session)(void);
    char *(*f_http_uri2url)(const char *prefix, const char *suffix);
    char *(*f_http_uri2url_dynamic)(const char *prefix, const char *suffix,
                                    Session *sn, Request *rq);
    void (*f_http_set_keepalive_timeout)(int secs);
    int (*f_log_error_v)(int degree, const char *func, Session *sn,
                         Request *rq, const char *fmt, va_list args);
    int (*f_log_error)(int degree, const char *func, Session *sn, Request *rq,
                       const char *fmt, ...);
    int (*f_log_ereport_v)(int degree, const char *fmt, va_list args);
    int (*f_log_ereport)(int degree, const char *fmt, ...);
    httpd_object *(*f_object_create)(int nd, pblock *name);
    void (*f_object_free)(httpd_object *obj);
    void (*f_object_add_directive)(int dc, pblock *p, pblock *c,
                                   httpd_object *obj);
    httpd_objset *(*f_objset_scan_buffer)(filebuffer *buf, char *errstr,
                                          httpd_objset *os);
    httpd_objset *(*f_objset_create)(void);
    void (*f_objset_free)(httpd_objset *os);
    void (*f_objset_free_setonly)(httpd_objset *os);
    httpd_object *(*f_objset_new_object)(pblock *name, httpd_objset *os);
    void (*f_objset_add_object)(httpd_object *obj, httpd_objset *os);
    void (*f_objset_add_init)(pblock *initfn, httpd_objset *os);
    httpd_object *(*f_objset_findbyname)(const char *name, httpd_objset *ign,
                                         httpd_objset *os);
    httpd_object *(*f_objset_findbyppath)(char *ppath, httpd_objset *ign,
                                          httpd_objset *os);
    Request *(*f_request_create)(void);
    void (*f_request_free)(Request *req);
    Request *(*f_request_restart_internal)(const char *uri, Request *rq);
    int (*f_request_header)(char *name, char **value, Session *sn,
                            Request *rq);
    struct stat *(*f_request_stat_path)(const char *path, Request *rq);
    const char *(*f_conf_getServerString)(void);
    FuncPtr (*f_func_replace)(char *funcname, FuncPtr fn);
    int (*f_net_socketpair)(SYS_NETFD *pair);
#ifdef XP_UNIX
    SYS_NETFD (*f_net_dup2)(SYS_NETFD prfd, int osfd);
    int (*f_net_is_STDOUT)(SYS_NETFD prfd);
    int (*f_net_is_STDIN)(SYS_NETFD prfd);
#else
    void *(*f_net_dup2)(void);
    int (*f_net_is_STDOUT)(void);
    int (*f_net_is_STDIN)(void);
#endif /* XP_UNIX */
    int (*f_func_set_native_thread_flag)(char *name, int flags);
#ifdef NET_SSL
    void *(*f_random_create)(void);
    void (*f_random_update)(void *rctx, unsigned char *inbuf, int length);
    void (*f_random_generate)(void *rctx, unsigned char *outbuf, int length);
    void (*f_random_destroy)(void *rctx);
    void *(*f_md5hash_create)(void);
    void *(*f_md5hash_copy)(void *hctx);
    void (*f_md5hash_begin)(void *hctx);
    void (*f_md5hash_update)(void *hctx, unsigned char *inbuf, int length);
    void (*f_md5hash_end)(void *hctx, unsigned char *outbuf);
    void (*f_md5hash_destroy)(void *hctx);
    void (*f_md5hash_data)(unsigned char *outbuf, unsigned char *src, int length);
#else
    void *(*f_random_create)(void);
    void (*f_random_update)(void);
    void (*f_random_generate)(void);
    void (*f_random_destroy)(void);
    void *(*f_md5hash_create)(void);
    void *(*f_md5hash_copy)(void);
    void (*f_md5hash_begin)(void);
    void (*f_md5hash_update)(void);
    void (*f_md5hash_end)(void);
    void (*f_md5hash_destroy)(void);
    void (*f_md5hash_data)(void);
#endif
    int (*f_ACL_SetupEval)(struct ACLListHandle *acllist, Session *sn, Request *rq, char **rights, char **map_generic, const char *user);
    int (*f_netbuf_getbytes)(netbuf *buf, char *buffer, int size);
    char *(*f_servact_translate_uri)(char *uri, Session *sn);
#ifdef NET_SSL
    int (*f_rsa_set_priv_fn)(void *);
#else
    int (*f_rsa_set_priv_fn)(void);
#endif
#ifdef XP_UNIX
    int (*f_net_native_handle)(SYS_NETFD s);
#else
    HANDLE (*f_net_native_handle)(SYS_NETFD s);
#endif /* XP_UNIX */
    int (*f_internal_request)(Request *rq);
    char *(*f_util_cookie_find)(char *cookie, const char *name);
    char *(*f_util_cookie_next)(char *cookie, char **name, char **value);
    char *(*f_util_cookie_next_av_pair)(char *cookie, char **name, char **value);
    int (*f_objset_get_number_objects)(const httpd_objset *objset);
    const httpd_object *(*f_objset_get_object)(const httpd_objset *objset, int pos);
    const pblock * const *(*f_objset_get_initfns)(const httpd_objset *objset);
    const pblock *(*f_object_get_name)(const httpd_object *object);
    int (*f_object_get_num_directives)(const httpd_object *object);
    const dtable *(*f_object_get_directive_table)(const httpd_object *object, int n);
    int (*f_directive_table_get_num_directives)(const dtable *dt);
    const directive *(*f_directive_table_get_directive)(const dtable *dt, int pos);
    const pblock *(*f_directive_get_pblock)(const directive *);
    const FuncStruct *(*f_directive_get_funcstruct)(const directive *);
    const pblock *(*f_directive_get_client_pblock)(const directive *);
#if NSAPI_VERSION >= 301
    int (*f_vs_register_cb)(VSInitFunc *vs_init_func, VSDestroyFunc *vs_destroy_func);
    const char* (*f_vs_get_id)(const VirtualServer *vs);
    const char* (*f_vs_lookup_config_var)(const VirtualServer *vs, const char *name);
    int (*f_vs_alloc_slot)(void);
    void* (*f_vs_set_data)(const VirtualServer *vs, int *slot, void *data);
    void* (*f_vs_get_data)(const VirtualServer *vs, int slot);
    const VirtualServer* (*f_request_get_vs)(Request *rq);
    httpd_objset* (*f_vs_get_httpd_objset)(VirtualServer *vs);
    httpd_object* (*f_vs_get_default_httpd_object)(VirtualServer *vs);
    char* (*f_vs_get_doc_root)(const VirtualServer *vs);
    char* (*f_vs_translate_uri)(const VirtualServer *vs, const char *uri);
    char* (*f_vs_get_mime_type)(const VirtualServer *vs, const char *uri);
    int (*f_vs_is_default_vs)(const VirtualServer *vs);
    void *(*f_vs_get_acllist)(const VirtualServer *vs);
    void (*f_vs_set_acllist)(VirtualServer *vs, void *acllist);
    int (*f_file_is_path_abs)(const char *path);
    char* (*f_file_canonicalize_path)(const char* path);
    int (*f_file_are_files_distinct)(SYS_FILE fd1, SYS_FILE fd2);
    int (*f_vs_directive_register_cb)(FuncPtr func, VSDirectiveInitFunc *vs_init_func, VSDirectiveDestroyFunc *vs_destroy_func);
    char* (*f_vs_substitute_vars)(const VirtualServer *vs, const char *string);
    const char *(*f_conf_getfilename)(void);
    const char *(*f_conf_getstring)(const char *name, const char *def);
    int (*f_conf_getboolean)(const char *name, int def);
    int (*f_conf_getinteger)(const char *name, int def);
    int (*f_conf_getboundedinteger)(const char *name, int min, int max, int def);
    void (*f_prepare_nsapi_thread)(Request *rq, Session *sn);
#endif /* NSAPI_VERSION >= 301 */
};

#if NSAPI_VERSION >= 302
typedef struct nsapi302_dispatch_s nsapi302_dispatch_t;
struct nsapi302_dispatch_s {
    int (*f_net_flush)(SYS_NETFD sd);
    int (*f_net_sendfile)(SYS_NETFD sd, sendfiledata *sfd);
    const Filter *(*f_filter_create)(const char *name, int order, const FilterMethods *methods);
    const char *(*f_filter_name)(const Filter *filter);
    const Filter *(*f_filter_find)(const char *name);
    FilterLayer *(*f_filter_layer)(SYS_NETFD sd, const Filter *filter);
    int (*f_filter_insert)(SYS_NETFD sd, pblock *pb, Session *sn, Request *rq, void *data, const Filter *filter);
    int (*f_filter_remove)(SYS_NETFD sd, const Filter *filter);
    SYS_NETFD (*f_filter_create_stack)(Session *sn);
};
#endif /* NSAPI_VERSION >= 302 */

#if NSAPI_VERSION >= 303
typedef struct nsapi303_dispatch_s nsapi303_dispatch_t;
struct hostent;
struct nsapi303_dispatch_s {
    int (*f_dns_set_hostent)(struct hostent *he, Session *sn, Request *rq);
};
#endif /* NSAPI_VERSION >= 303 */

/* --- End dispatch vector table definition --- */

/* --- Begin API macro definitions --- */

#ifndef INTNSAPI

#if NSAPI_VERSION >= 301

/*
 * In Sun ONE Web Server 6.1 and higher, http_parse_request("", NULL, NULL)
 * returns the NSAPI version.  In previous releases, it returns -1.
 */
#define __NSAPI_RUNTIME_VERSION \
        ((*__nsapi30_table->f_http_parse_request)("", NULL, NULL))

/*
 * NSAPI_RUNTIME_VERSION returns the NSAPI version the server implements.  The
 * returned NSAPI version number is reliable only in iPlanet Web Server 6.0,
 * Netscape Enterprise Server 6.0, and Sun ONE Web Server 6.0 and higher.
 */
#define NSAPI_RUNTIME_VERSION \
        (__NSAPI_RUNTIME_VERSION > 0 ? __NSAPI_RUNTIME_VERSION : 301)

#endif /* NSAPI_VERSION >= 301 */

#define system_version (*__nsapi30_table->f_system_version)

/*
 * Depending on the system, memory allocated via these macros may come from 
 * an arena.  If these functions are called from within an Init function, they
 * will be allocated from permanent storage.  Otherwise, they will be freed 
 * when the current request is finished.
 */



#endif /* !INTNSAPI */

#ifdef XP_UNIX
#define dir_open opendir
#define dir_read readdir
#define dir_close closedir
#define dir_create(path) mkdir(path, 0755)
#define dir_remove rmdir
#define system_chdir chdir
#define file_unix2local(path,p2) strcpy(p2,path)
#endif /* XP_UNIX */

#ifdef XP_WIN32
#define dir_create _mkdir
#define dir_remove _rmdir
#define system_chdir SetCurrentDirectory
#endif /* XP_WIN32 */

/*
 * Thread-safe variants of localtime and gmtime
 */
#define system_localtime(curtime, ret) util_localtime(curtime, ret)
#define system_gmtime(curtime, ret) util_gmtime(curtime, ret)

/* 
 * pblock_find finds the entry with the given name in pblock pb.
 *
 * If it is successful, it returns the param block.  If not, it returns NULL.
 */
#define pblock_find(name, pb) (pblock_fr(name,pb,0))

/*
 * pblock_remove behaves exactly like pblock_find, but removes the given
 * entry from pb.
 */
#define pblock_remove(name, pb) (pblock_fr(name,pb,1))

/*
 * session_dns returns the DNS hostname of the client of this session,
 * and inserts it into the client pblock.  Returns NULL if unavailable.
 */
#define session_dns(sn) session_dns_lookup(sn, 0)

/*
 * session_maxdns looks up a hostname from an IP address, and then verifies 
 * that the host is really who they claim to be. 
 */
#define session_maxdns(sn) session_dns_lookup(sn, 1)

#define protocol_start_response http_start_response
#define protocol_status http_status
#define protocol_set_finfo http_set_finfo
#define protocol_finish_request http_finish_request
#define protocol_uri2url http_uri2url
#define protocol_uri2url_dynamic http_uri2url_dynamic

#define request_translate_uri servact_translate_uri

/* --- OBSOLETE ----------------------------------------------------------
 * The following macros/functions are obsolete and are only maintained for
 * compatibility.  Do not use them.
 * -----------------------------------------------------------------------
 */

#define SYS_STDERR STDERR_FILENO

#ifdef XP_WIN32

typedef HANDLE pid_t;

#define ERROR_PIPE \
        (ERROR_BROKEN_PIPE | ERROR_BAD_PIPE | \
         ERROR_PIPE_BUSY | ERROR_PIPE_LISTENING | ERROR_PIPE_NOT_CONNECTED)
#define CONVERT_TO_PRINTABLE_FORMAT(Filename)   \
{                                               \
        register char *s;                       \
        if (Filename)                           \
        for (s = Filename; *s; s++)             \
                if ( *s == '\\')                \
                        *s = '/';               \
}
#define CONVERT_TO_NATIVE_FS(Filename)          \
{                                               \
        register char *s;                       \
        if (Filename)                           \
                for (s = Filename; *s; s++)     \
                        if ( *s == '/')         \
                                *s = '\\';      \
}                                                                        

#ifdef INTNSAPI
NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table;
#if NSAPI_VERSION >= 302
NSAPI_PUBLIC extern nsapi302_dispatch_t *__nsapi302_table;
#endif /* NSAPI_VERSION >= 302 */
#if NSAPI_VERSION >= 303
NSAPI_PUBLIC extern nsapi303_dispatch_t *__nsapi303_table;
#endif /* NSAPI_VERSION >= 303 */
#else
__declspec(dllimport) nsapi_dispatch_t *__nsapi30_table;
#if NSAPI_VERSION >= 302
__declspec(dllimport) nsapi302_dispatch_t *__nsapi302_table;
#endif /* NSAPI_VERSION >= 302 */
#if NSAPI_VERSION >= 303
__declspec(dllimport) nsapi303_dispatch_t *__nsapi303_table;
#endif /* NSAPI_VERSION >= 303 */
#endif /* INTNSAPI */

#else /* !XP_WIN32 */

NSAPI_PUBLIC extern nsapi_dispatch_t *__nsapi30_table;
#if NSAPI_VERSION >= 302
NSAPI_PUBLIC extern nsapi302_dispatch_t *__nsapi302_table;
#endif /* NSAPI_VERSION >= 302 */
#if NSAPI_VERSION >= 303
NSAPI_PUBLIC extern nsapi303_dispatch_t *__nsapi303_table;
#endif /* NSAPI_VERSION >= 303 */

#endif /* XP_WIN32 */

#ifdef __cplusplus
}
#endif

#endif /* !PUBLIC_NSAPI_H */

mercurial