Sun ONE logo      Previous      Contents      Index      Next     

Sun ONE Web Server 6.1 NSAPI Programmer's Guide

Chapter 8
Data Structure Reference

NSAPI uses many data structures that are defined in the nsapi.h header file, which is in the directory server-root/plugins/include.

The NSAPI functions described in "NSAPI Function Reference" provide access to most of the data structures and data fields. Before directly accessing a data structure in naspi.h, check to see if an accessor function exists for it.

For information about the privatization of some data structures in Sun ONE Web Server 4.x, see "Privatization of Some Data Structures."

The rest of this chapter describes public data structures in nsapi.h. Note that data structures in nsapi.h that are not described in this chapter are considered private and may change incompatibly in future releases.

This chapter has the following sections:

Privatization of Some Data Structures

In Sun ONE Web Server 4.x, some data structures were moved from nsapi.h to nsapi_pvt.h. The data structures in nsapi_pvt.h are now considered to be private data structures, and you should not write code that accesses them directly. Instead, use accessor functions. We expect that very few people have written plugins that access these data structures directly, so this change should have very little impact on customer-defined plugins. Look in nsapi_pvt.h to see which data structures have been removed from the public domain, and to see the accessor functions you can use to access them from now on.

Plugins written for Enterprise Server 3.x that access contents of data structures defined in nsapi_pvt.h will not be source compatible with Sun ONE Web Server 4.x and 6.x, that is, it will be necessary to #include "nsapi_pvt.h" to build such plugins from source. There is also a small chance that these programs will not be binary compatible with Sun ONE Web Server 4.x and 6.x, because some of the data structures in nsapi_pvt.h have changed size. In particular, the directive structure is larger, which means that a plugin that indexes through the directives in a dtable will not work without being rebuilt (with nsapi_pvt.h included).

We hope that the majority of plugins do not reference the internals of data structures in nsapi_pvt.h, and therefore that most existing NSAPI plugins will be both binary and source compatible with Sun ONE Web Server 6.1.


A session is the time between the opening and closing of the connection between the client and the server. The session data structure holds variables that apply session wide, regardless of the requests being sent, as shown here:

typedef struct {
/* Information about the remote client */
  pblock *client;

  /* The socket descriptor to the remote client */
  SYS_NETFD csd;

  /* The input buffer for that socket descriptor */
  netbuf *inbuf;

  /* Raw socket information about the remote */
  /* client (for internal use) */
  struct in_addr iaddr;
} Session;


The parameter block is the hash table that holds pb_entry structures. Its contents are transparent to most code. This data structure is frequently used in NSAPI; it provides the basic mechanism for packaging up parameters and values. There are many functions for creating and managing parameter blocks, and for extracting, adding, and deleting entries. See the functions whose names start with pblock_ in "NSAPI Function Reference." You should not need to write code that accesses pblock data fields directly.

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


The pb_entry is a single element in the parameter block.

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


The pb_param represents a name-value pair, as stored in a pb_entry.

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


The Session->client parameter block structure contains two entries:


Under HTTP protocol, there is only one request per session. The request structure contains the variables that apply to the request in that session (for example, the variables include the client’s HTTP headers).

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

  /* The method, URI, and protocol revision of this request */
  block *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;
} Request;


When a program calls the stat( ) function for a given file, the system returns a structure that provides information about the file. The specific details of the structure should be obtained from your platform’s implementation, but the basic outline of the structure is as follows:

struct stat {
  dev_t      st_dev;     /* device of inode */
  inot_t     st_ino;     /* inode number */
  short      st_mode;    /* mode bits */
  short      st_nlink;   /* number of links to file /*
  short      st_uid;     /* owner’s user id */
  short      st_gid;     /* owner’s group id */
  dev_t      st_rdev;    /* for special files */
  off_t      st_size;    /* file size in characters */
  time_t     st_atime;   /* time last accessed */
  time_t     st_mtime;   /* time last modified */
  time_t     st_ctime;   /* time inode last changed*/

The elements that are most significant for server plugin API activities are st_size, st_atime, st_mtime, and st_ctime.


typedef struct {
  void       *data;   /* the data */
  HANDLE     fdmap;
  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 */
} shmem_s;


The cinfo data structure records the content information for a file.

typedef struct {
  char    *type;
          /* Identifies what kind of data is in the file*/
  char    *encoding;
          /* encoding identifies any compression or other /*
          /* content-independent transformation that’s been /*
          /* applied to the file, such as uuencode)*/
  char    *language;      
          /* Identifies the language a text document is in. */
} cinfo;


The sendfiledata data structure is used to pass parameters to the net_sendfile function. It is also passed to the sendfile method in an installed filter in response to a net_sendfile call.

typedef struct {
    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 */
} sendfiledata;


The Filter data structure is an opaque representation of a filter. A Filter structure is created by calling filter_create.

typedef struct Filter Filter;


The FilterContext data structure stores context associated with a particular filter layer. Filter layers are created by calling filter_insert.

Filter developers may use the data member to store filter-specific context information.

typedef struct {
    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 */
} FilterContext;


The FilterLayer data structure represents one layer in a filter stack. The FilterLayer structure identifies the filter installed at that layer and provides pointers to layer-specific context and a filter stack that represents the layer immediately below it in the filter stack.

typedef struct {
    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 */
} FilterLayer;


The FilterMethods data structure is passed to filter_create to define the filter methods a filter supports. Each new FilterMethods instance must be initialized with the FILTER_METHODS_INITIALIZER macro. For each filter method a filter supports, the corresponding FilterMethods member should point to a function that implements that filter method.

typedef struct {
    size_t size;
    FilterInsertFunc *insert;
    FilterRemoveFunc *remove;
    FilterFlushFunc *flush;
    FilterReadFunc *read;
    FilterWriteFunc *write;
    FilterWritevFunc *writev;
    FilterSendfileFunc *sendfile;
} FilterMethods;

Previous      Contents      Index      Next     

Copyright 2004 Sun Microsystems, Inc. All rights reserved.