nsd.h File Reference

#include "ns.h"
#include <pthread.h>
#include <sys/mman.h>
#include <assert.h>
#include <sys/resource.h>
#include <sys/wait.h>
#include <sys/ioctl.h>
#include <sys/stat.h>
#include <ctype.h>
#include <grp.h>

Go to the source code of this file.

Data Structures

struct  pollfd
struct  _nsconf
struct  FileKey
struct  AdpFrame
struct  AdpCode
struct  Driver
struct  Sock
struct  Limits
struct  Conn
struct  Pool
struct  Nsv
struct  NsServer
struct  NsInterp
struct  NsInterp::nsconn
struct  NsInterp::adp

Defines

#define NSD_EXPORTS
#define POLLIN   1
#define POLLOUT   2
#define POLLPRI   4
#define POLLHUP   8
#define F_CLOEXEC   1
#define NS_SIGTERM   SIGTERM
#define NS_SIGHUP   SIGHUP
#define _MAX(x, y)   ((x) > (y) ? (x) : (y))
#define _MIN(x, y)   ((x) > (y) ? (y) : (x))
#define NSD_NAME   "AOLserver"
#define NSD_VERSION   NS_PATCH_LEVEL
#define NSD_LABEL   "aolserver4_5"
#define NSD_TAG   "$Name: $"
#define NS_CONFIG_PARAMETERS   "ns/parameters"
#define NS_CONFIG_THREADS   "ns/threads"
#define ADP_OK   0
#define ADP_BREAK   1
#define ADP_ABORT   2
#define ADP_RETURN   4
#define NSD_TEXTHTML   "text/html; charset=iso-8859-1"
#define FILE_KEYS   (sizeof(FileKey)/sizeof(int))
#define AdpCodeLen(cp, i)   ((cp)->len[(i)])
#define AdpCodeLine(cp, i)   ((cp)->line[(i)])
#define AdpCodeText(cp)   ((cp)->text.string)
#define AdpCodeBlocks(cp)   ((cp)->nblocks)
#define AdpCodeScripts(cp)   ((cp)->nscripts)
#define ADP_SAFE   0x01
#define ADP_SINGLE   0x02
#define ADP_DEBUG   0x04
#define ADP_EXPIRE   0x08
#define ADP_NOCACHE   0x10
#define ADP_TRACE   0x20
#define ADP_GZIP   0x80
#define ADP_DETAIL   0x100
#define ADP_STRICT   0x200
#define ADP_DISPLAY   0x400
#define ADP_TRIM   0x800
#define ADP_FLUSHED   0x1000
#define ADP_ERRLOGGED   0x2000
#define ADP_AUTOABORT   0x4000
#define ADP_EVAL_FILE   0x8000
#define SERV_AOLPRESS   0x0001
#define SERV_CHUNKED   0x0002
#define SERV_MODSINCE   0x0004
#define SERV_NOTICEDETAIL   0x0008
#define SERV_GZIP   0x0010
#define CONN_TCLFORM   1
#define CONN_TCLHDRS   2
#define CONN_TCLOUTHDRS   4

Typedefs

typedef int bool

Functions

int poll (struct pollfd *, unsigned long, int)
void NsInitBinder (void)
void NsInitCache (void)
void NsInitConf (void)
void NsInitConfig (void)
void NsInitEncodings (void)
void NsInitFd (void)
void NsInitListen (void)
void NsInitLog (void)
void NsInitMimeTypes (void)
void NsInitModLoad (void)
void NsInitNsv (void)
void NsInitProcInfo (void)
void NsInitQueue (void)
void NsInitLimits (void)
void NsInitPools (void)
void NsInitDrivers (void)
void NsInitSched (void)
void NsInitServers (void)
void NsInitTcl (void)
void NsInitTclCache (void)
void NsInitUrlSpace (void)
void NsInitRequests (void)
char * NsFindVersion (char *request, unsigned int *majorPtr, unsigned int *minorPtr)
void NsQueueConn (Conn *connPtr)
int NsCheckQuery (Ns_Conn *conn)
void NsAppendConn (Tcl_DString *bufPtr, Conn *connPtr, char *state)
void NsAppendRequest (Tcl_DString *dsPtr, Ns_Request *request)
int NsConnSend (Ns_Conn *conn, struct iovec *bufs, int nbufs)
void NsSockClose (Sock *sockPtr, int keep)
int NsPoll (struct pollfd *pfds, int nfds, Ns_Time *timeoutPtr)
void NsFreeConn (Conn *connPtr)
NsServerNsGetServer (char *server)
char * NsGetServers (void)
NsServerNsGetInitServer (void)
NsInterpNsGetInterpData (Tcl_Interp *interp)
void NsFreeConnInterp (Conn *connPtr)
Ns_Cache * NsFastpathCache (char *server, int size)
void NsAdpInit (NsInterp *itPtr)
void NsAdpReset (NsInterp *itPtr)
void NsAdpFree (NsInterp *itPtr)
void NsTclRunAtClose (NsInterp *itPtr)
int NsUrlToFile (Ns_DString *dsPtr, NsServer *servPtr, char *url)
void NsGetCallbacks (Tcl_DString *dsPtr)
void NsGetSockCallbacks (Tcl_DString *dsPtr)
void NsGetScheduled (Tcl_DString *dsPtr)
char * NsConnContent (Ns_Conn *conn, char **nextPtr, int *availPtr)
void NsConnSeek (Ns_Conn *conn, int count)
void * NsMap (int fd, off_t start, size_t len, int writeable, void **argPtr)
void NsUnMap (void *addr, void *arg)
void NsCreatePidFile (char *service)
void NsRemovePidFile (char *service)
void NsLogOpen (void)
void NsLogConf (void)
void NsTclInitObjs (void)
void NsUpdateMimeTypes (void)
void NsUpdateEncodings (void)
void NsRunPreStartupProcs (void)
void NsBlockSignals (int debug)
void NsHandleSignals (void)
void NsStopDrivers (void)
void NsPreBind (char *bindargs, char *bindfile)
SOCKET NsSockGetBound (struct sockaddr_in *saPtr)
void NsClosePreBound (void)
void NsInitServer (char *server, Ns_ServerInitProc *initProc)
char * NsConfigRead (char *file)
void NsConfigEval (char *config, int argc, char **argv, int optind)
void NsConfUpdate (void)
void NsEnableDNSCache (void)
void NsStartPools (void)
void NsStopPools (Ns_Time *timeoutPtr)
int NsTclGetPool (Tcl_Interp *interp, char *pool, Pool **poolPtrPtr)
void NsCreateConnThread (Pool *poolPtr)
void NsJoinConnThreads (void)
int NsStartDrivers (void)
void NsWaitDriversShutdown (Ns_Time *toPtr)
void NsStartSchedShutdown (void)
void NsWaitSchedShutdown (Ns_Time *toPtr)
void NsStartSockShutdown (void)
void NsWaitSockShutdown (Ns_Time *toPtr)
void NsStartShutdownProcs (void)
void NsWaitShutdownProcs (Ns_Time *toPtr)
void NsStartQueueShutdown (void)
void NsWaitQueueShutdown (Ns_Time *toPtr)
void NsStartJobsShutdown (void)
void NsWaitJobsShutdown (Ns_Time *toPtr)
void NsTclInitServer (char *server)
int NsTclGetServer (NsInterp *itPtr, char **serverPtr)
int NsTclGetConn (NsInterp *itPtr, Ns_Conn **connPtr)
void NsLoadModules (char *server)
BucketNsTclCreateBuckets (char *server, int nbuckets)
void NsClsCleanup (Conn *connPtr)
void NsTclAddCmds (Tcl_Interp *interp, NsInterp *itPtr)
void NsRestoreSignals (void)
void NsSendSignal (int sig)
LimitsNsGetRequestLimits (char *server, char *method, char *url)
PoolNsGetConnPool (Conn *connPtr)
Ns_Cache * NsAdpCache (char *server, int size)
void NsAdpSetMimeType (NsInterp *itPtr, char *type)
void NsAdpSetCharSet (NsInterp *itPtr, char *charset)
int NsAdpGetBuf (NsInterp *itPtr, Tcl_DString **dsPtrPtr)
int NsAdpAppend (NsInterp *itPtr, char *buf, int len)
int NsAdpFlush (NsInterp *itPtr, int stream)
int NsAdpDebug (NsInterp *itPtr, char *host, char *port, char *procs)
int NsAdpEval (NsInterp *itPtr, int objc, Tcl_Obj *objv[], int flags, char *resvar)
int NsAdpSource (NsInterp *itPtr, int objc, Tcl_Obj *objv[], int flags, char *resvar)
int NsAdpInclude (NsInterp *itPtr, int objc, Tcl_Obj *objv[], char *file, Ns_Time *ttlPtr)
void NsAdpParse (AdpCode *codePtr, NsServer *servPtr, char *utf, int flags)
void NsAdpFreeCode (AdpCode *codePtr)
void NsAdpLogError (NsInterp *itPtr)
int NsTclCheckConnId (Tcl_Interp *interp, Tcl_Obj *objPtr)
void NsTclInitQueueType (void)
void NsTclInitAddrType (void)
void NsTclInitCacheType (void)
void NsTclInitKeylistType (void)
void NsTclInitTimeType (void)
int NsRunFilters (Ns_Conn *conn, int why)
void NsRunCleanups (Ns_Conn *conn)
void NsRunTraces (Ns_Conn *conn)
void NsRunSignalProcs (void)
void NsRunStartupProcs (void)
void NsRunAtReadyProcs (void)
void NsRunAtExitProcs (void)
bool NsParamBool (char *key, bool def)
int NsParamInt (char *key, int def)
char * NsParamString (char *key, char *def)
int NsCloseAllFiles (int errFd)
int Ns_ConnRunRequest (Ns_Conn *conn)
int Ns_GetGid (char *group)
int Ns_GetUserGid (char *user)
int Ns_TclGetOpenFd (Tcl_Interp *, char *, int write, int *fp)
void NsStopSockCallbacks (void)
void NsStopScheduledProcs (void)
Tcl_Encoding NsGetInputEncoding (Conn *connPtr)
Tcl_Encoding NsGetOutputEncoding (Conn *connPtr)
int NsConnRunProxyRequest (Ns_Conn *conn)

Variables

_nsconf nsconf
Ns_OpProc NsAdpProc
Ns_Callback NsTclCallback
Ns_Callback NsTclSignalProc
Ns_SchedProc NsTclSchedProc
Ns_ArgProc NsTclArgProc
Ns_ThreadProc NsTclThread
Ns_ArgProc NsTclThreadArgProc
Ns_Callback NsCachePurge
Ns_ArgProc NsCacheArgProc
Ns_SockProc NsTclSockProc
Ns_ArgProc NsTclSockArgProc
Ns_ThreadProc NsConnThread
Ns_ArgProc NsConnArgProc
Tcl_ObjCmdProc NsTclListPoolsObjCmd


Define Documentation

#define _MAX ( x,
 )     ((x) > (y) ? (x) : (y))

#define _MIN ( x,
 )     ((x) > (y) ? (y) : (x))

#define ADP_ABORT   2

#define ADP_AUTOABORT   0x4000

#define ADP_BREAK   1

#define ADP_DEBUG   0x04

#define ADP_DETAIL   0x100

#define ADP_DISPLAY   0x400

#define ADP_ERRLOGGED   0x2000

#define ADP_EVAL_FILE   0x8000

#define ADP_EXPIRE   0x08

#define ADP_FLUSHED   0x1000

#define ADP_GZIP   0x80

#define ADP_NOCACHE   0x10

#define ADP_OK   0

#define ADP_RETURN   4

#define ADP_SAFE   0x01

Various ADP option bits.

#define ADP_SINGLE   0x02

#define ADP_STRICT   0x200

#define ADP_TRACE   0x20

#define ADP_TRIM   0x800

#define AdpCodeBlocks ( cp   )     ((cp)->nblocks)

#define AdpCodeLen ( cp,
 )     ((cp)->len[(i)])

#define AdpCodeLine ( cp,
 )     ((cp)->line[(i)])

#define AdpCodeScripts ( cp   )     ((cp)->nscripts)

#define AdpCodeText ( cp   )     ((cp)->text.string)

#define CONN_TCLFORM   1

The following pointer and struct maintain state for the active connection, if any, and support the ns_conn command.

#define CONN_TCLHDRS   2

#define CONN_TCLOUTHDRS   4

#define F_CLOEXEC   1

#define FILE_KEYS   (sizeof(FileKey)/sizeof(int))

#define NS_CONFIG_PARAMETERS   "ns/parameters"

#define NS_CONFIG_THREADS   "ns/threads"

#define NS_SIGHUP   SIGHUP

#define NS_SIGTERM   SIGTERM

#define NSD_EXPORTS

The contents of this file are subject to the AOLserver Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://aolserver.com/.

Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License.

The Original Code is AOLserver Code and related documentation distributed by AOL.

The Initial Developer of the Original Code is America Online, Inc. Portions created by AOL are Copyright (C) 1999 America Online, Inc. All Rights Reserved.

Alternatively, the contents of this file may be used under the terms of the GNU General Public License (the "GPL"), in which case the provisions of GPL are applicable instead of those above. If you wish to allow use of your version of this file only under the terms of the GPL and not to allow others to use your version of this file under the License, indicate your decision by deleting the provisions above and replace them with the notice and other provisions required by the GPL. If you do not delete the provisions above, a recipient may use your version of this file under either the License or the GPL.

#define NSD_LABEL   "aolserver4_5"

#define NSD_NAME   "AOLserver"

constants

#define NSD_TAG   "$Name: $"

#define NSD_TEXTHTML   "text/html; charset=iso-8859-1"

The following is the default text/html content type sent to the browsers. The charset is also used for both input (url query) and output encodings.

#define NSD_VERSION   NS_PATCH_LEVEL

#define POLLHUP   8

#define POLLIN   1

WIN32

#define POLLOUT   2

#define POLLPRI   4

#define SERV_AOLPRESS   0x0001

#define SERV_CHUNKED   0x0002

#define SERV_GZIP   0x0010

#define SERV_MODSINCE   0x0004

#define SERV_NOTICEDETAIL   0x0008


Typedef Documentation

typedef int bool

Typedef definitions.


Function Documentation

int Ns_ConnRunRequest ( Ns_Conn *  conn  ) 

----------------------------------------------------------------------

Ns_ConnRunRequest --

Locate and execute the procedure for the given method and url pattern.

Results: Standard request procedure result, normally NS_OK.

Side effects: Depends on request procedure.

----------------------------------------------------------------------

Return a quick unavailable error on overflow.

Prevent infinite internal redirect loops.

int Ns_GetGid ( char *  group  ) 

---------------------------------------------------------------------- Ns_GetGid --

Get the group id from a group name.

Results: Group id or -1 if not found.

Side effects: None.

----------------------------------------------------------------------

int Ns_GetUserGid ( char *  user  ) 

---------------------------------------------------------------------- Ns_GetUserGid --

Get the group id for a user name

Results: Returns group id of the user name found in /etc/passwd or -1 otherwise.

Side effects: None.

----------------------------------------------------------------------

int Ns_TclGetOpenFd ( Tcl_Interp *  interp,
char *  chanId,
int  write,
int *  fdPtr 
)

----------------------------------------------------------------------

Ns_TclGetOpenFd --

Return an open Unix file descriptor for the given channel. This routine is used by the AOLserver * routines to provide access to the underlying socket.

Results: TCL_OK or TCL_ERROR.

Side effects: The value at fdPtr is updated with a valid Unix file descriptor.

----------------------------------------------------------------------

int NsAdpAppend ( NsInterp itPtr,
char *  buf,
int  len 
)

----------------------------------------------------------------------

NsAdpAppend --

Append content to the ADP output buffer, flushing the content if necessary.

Results: TCL_ERROR if append and/or flush failed, TCL_OK otherwise.

Side effects: Will set ADP error flag and leave an error message in the interp on flush failure.

----------------------------------------------------------------------

Ns_Cache* NsAdpCache ( char *  server,
int  size 
)

ADP routines.

int NsAdpDebug ( NsInterp itPtr,
char *  host,
char *  port,
char *  procs 
)

----------------------------------------------------------------------

NsAdpDebug --

Initialize the debugger by calling the debug init proc with the hostname and port of the debugger and a pattern of procs to auto-instrument.

Results: TCL_OK if debugger initialized, TCL_ERROR otherwise.

Side effects: Interp is marked for delete on next deallocation.

----------------------------------------------------------------------

Link the ADP output buffer result to a global variable which can be monitored with a variable watch.

int NsAdpEval ( NsInterp itPtr,
int  objc,
Tcl_Obj *  objv[],
int  flags,
char *  resvar 
)

----------------------------------------------------------------------

NsAdpEval, NsAdpSource --

Evaluate an ADP string or file and return the output as the interp result.

Results: A standard Tcl result.

Side effects: Variable named by resvar, if any, is updated with results of Tcl interp before being replaced with ADP output.

----------------------------------------------------------------------

int NsAdpFlush ( NsInterp itPtr,
int  stream 
)

----------------------------------------------------------------------

NsAdpFlush --

Flush output to connection response buffer.

Results: TCL_ERROR if flush failed, TCL_OK otherwise.

Side effects: Output buffer is truncated in all cases.

----------------------------------------------------------------------

Verify output context.

If enabled, trim leading whitespace if no content has been sent yet.

Leave error messages if output is disabled or failed. Otherwise, send data if there's any to send or stream is 0, indicating this is the final flush call.

Raise an abort exception if autoabort is enabled.

void NsAdpFree ( NsInterp itPtr  ) 

void NsAdpFreeCode ( AdpCode codePtr  ) 

----------------------------------------------------------------------

NsAdpFreeCode --

Free internal AdpCode storage.

Results: None.

Side effects: None.

----------------------------------------------------------------------

int NsAdpGetBuf ( NsInterp itPtr,
Tcl_DString **  dsPtrPtr 
)

int NsAdpInclude ( NsInterp itPtr,
int  objc,
Tcl_Obj *  objv[],
char *  file,
Ns_Time *  ttlPtr 
)

----------------------------------------------------------------------

NsAdpInclude --

Evaluate an ADP file, utilizing per-thread byte-code pages.

Results: A standard Tcl result.

Side effects: Output is either left in current ADP buffer.

----------------------------------------------------------------------

If an ADP execution is already active, use the current output buffer. Otherwise, use the top-level buffer in the ADP struct.

void NsAdpInit ( NsInterp itPtr  ) 

----------------------------------------------------------------------

NsAdpInit, NsAdpFree --

Initialize or free the NsInterp ADP data structures.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsAdpLogError ( NsInterp itPtr  ) 

----------------------------------------------------------------------

NsAdpLogError --

Log an ADP error, possibly invoking the log handling ADP file if configured.

Results: None.

Side effects: Depends on log handler.

----------------------------------------------------------------------

NB: Avoid truncating multi-byte UTF-8 character.

void NsAdpParse ( AdpCode codePtr,
NsServer servPtr,
char *  adp,
int  flags 
)

----------------------------------------------------------------------

NsAdpParse --

Parse a string of ADP text/script. Parsing is done in a single, top to bottom pass, looking for the following four types of embedded script sequences:

1. <% tcl script %> 2. <script runat="server" language="tcl>"> tcl script </script> 3. <registered-tag arg=val arg=val> 4. <registered-start-tag arg=val arg=val> text </registered-end-tag>

Nested sequences are handled for each case, for example:

Text <% ns_adp_eval {<% ... %>} %> text ...

Results: None.

Side effects: Given AdpCode structure is initialized and filled in with copy of parsed ADP.

----------------------------------------------------------------------

Initialize the code and parse structures.

Parse ADP one tag at a time.

Process the tag depending on the current state.

Look for a <% ... %> sequence.

NB: Avoid <%>.

Find the cooresponding %> beyond any additional nested <% ... %> sequences.

No matching %> found. Append text and invalid opening <% before searching for next ADP tag.

NB: Next text after invalid opening <%.

Append text block followed by script block unless in safe mode which suppresses in-line scripts and continue looking for next ADP tag.

NB: Next text after valid closing %>.

NB: Will incr +1, past text, below.

Check for <script> tags or registered tags.

Append text and begin looking for closing </script> tag.

Append text and the registered tag content if the tag does not require a closing tag. Otherwise, save the tag attribute offsets and begin looking for required closing tag.

Look for cooresponding closing </script> tag, handling possible nesting of other <script> tags.

Found closing tag. If not in safe mode, enable streaming if requested and appending the embedded script and then begin looking for next ADP tag.

Looking for cooresponding closing tag for a registered tag, handling possible nesting of the same tag.

Found closing tag. Append tag content and being looking for next ADP tag.

Skip to next possible ADP tag location.

Append the remaining text block and complete the parse code structure.

If requested, collapse blocks to a single Tcl script.

void NsAdpReset ( NsInterp itPtr  ) 

----------------------------------------------------------------------

NsAdpReset --

Reset the NsInterp ADP data structures for the next execution request.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsAdpSetCharSet ( NsInterp itPtr,
char *  charset 
)

void NsAdpSetMimeType ( NsInterp itPtr,
char *  type 
)

int NsAdpSource ( NsInterp itPtr,
int  objc,
Tcl_Obj *  objv[],
int  flags,
char *  resvar 
)

void NsAppendConn ( Tcl_DString *  dsPtr,
Conn connPtr,
char *  state 
)

----------------------------------------------------------------------

NsAppendConn --

Append connection data to a dstring.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsAppendRequest ( Tcl_DString *  dsPtr,
Ns_Request *  request 
)

----------------------------------------------------------------------

NsAppendRequest --

Utility function to append string of given request.

Results: None.

Side effects: None

----------------------------------------------------------------------

void NsBlockSignals ( int  debug  ) 

----------------------------------------------------------------------

NsBlockSignals --

Block signals at startup.

Results: None.

Side effects: Signals will be pending until NsHandleSignals.

----------------------------------------------------------------------

Block SIGHUP, SIGPIPE, SIGTERM, and SIGINT. This mask is inherited by all subsequent threads so that only this thread will catch the signals in the sigwait() loop below. Unfortunately this makes it impossible to kill the server with a signal other than SIGKILL until startup is complete.

NB: Don't block SIGINT in debug mode for Solaris dbx.

Make sure "synchronous" signals (those generated by execution errors like SIGSEGV or SIGILL which get delivered to the thread that caused them) have an appropriate handler installed.

int NsCheckQuery ( Ns_Conn *  conn  ) 

----------------------------------------------------------------------

NsCheckQuery --

Validate the connection query was decoded with the current URL encoding.

Results: 1 if query is valid, 0 otherwise.

Side effects: None.

----------------------------------------------------------------------

int NsCloseAllFiles ( int  errFd  ) 

void NsClosePreBound ( void   ) 

----------------------------------------------------------------------

NsClosePreBound --

Close any remaining pre-bound sockets.

Results: None.

Side effects: Pre-bound sockets closed.

----------------------------------------------------------------------

void NsClsCleanup ( Conn connPtr  ) 

----------------------------------------------------------------------

NsClsCleanup --

Cleanup connection local storage in a manner similar to thread local storage.

Results: None.

Side effects: Depends on callbacks.

----------------------------------------------------------------------

void NsConfigEval ( char *  config,
int  argc,
char **  argv,
int  optind 
)

----------------------------------------------------------------------

NsConfigEval --

Eval config script in a startup Tcl interp.

Results: None.

Side Effects: Various variables in the configInterp will be set as well as the sundry configuration hashes

---------------------------------------------------------------------

Create an interp with a few config-related commands.

char* NsConfigRead ( char *  file  ) 

----------------------------------------------------------------------

NsConfigRead --

Read a config file at startup.

Results: Pointer to the config buffer of an ns_malloc'ed string.

Side Effects: Server aborts if file cannot be read for any reason.

---------------------------------------------------------------------

void NsConfUpdate ( void   ) 

----------------------------------------------------------------------

NsConfUpdate --

Update various elements of the nsconf structure now that the config script has been evaluated.

Results: None.

Side effects: Various, depending on config.

----------------------------------------------------------------------

char* NsConnContent ( Ns_Conn *  conn,
char **  nextPtr,
int *  availPtr 
)

----------------------------------------------------------------------

NsConnContent --

Return the connction content buffer, mapping the temp file if necessary.

NB: It may make better sense to update the various content reading/parsing code to handle true incremental reads from an open file instead of risking a potential mapping failure. The current approach keeps the code simple and flexible.

Results: Pointer to start of content or NULL if mapping failed.

Side effects: If nextPtr and/or availPtr are not NULL, they are updated with the next byte to read and remaining content available.

----------------------------------------------------------------------

int NsConnRunProxyRequest ( Ns_Conn *  conn  ) 

----------------------------------------------------------------------

NsConnRunProxyRequest --

Locate and execute the procedure for the given method and protocol pattern.

Results: Standard request procedure result, normally NS_OK.

Side effects: Depends on request procedure.

----------------------------------------------------------------------

void NsConnSeek ( Ns_Conn *  conn,
int  count 
)

----------------------------------------------------------------------

NsConnSeek --

Update the next read and available content counter.

Results: None.

Side effects: None.

----------------------------------------------------------------------

int NsConnSend ( Ns_Conn *  conn,
struct iovec *  bufs,
int  nbufs 
)

----------------------------------------------------------------------

NsConnSend --

Send buffers via the connection's driver callback.

Results: # of bytes sent or -1 on error.

Side effects: Depends on driver proc.

----------------------------------------------------------------------

void NsCreateConnThread ( Pool poolPtr  ) 

----------------------------------------------------------------------

NsCreateConnThread --

Create a connection thread.

Results: None.

Side effects: New thread.

----------------------------------------------------------------------

Reap any dead threads.

Create a new connection thread.

void NsCreatePidFile ( char *  procname  ) 

----------------------------------------------------------------------

NsCreatePidFile, NsRemovePidFile --

Create/remove file with current pid.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsEnableDNSCache ( void   ) 

---------------------------------------------------------------------- NsEnableDNSCache --

Enable DNS results caching.

Results: None.

Side effects: Futher DNS lookups will be cached up to given timeout.

----------------------------------------------------------------------

NB: Config minutes, seconds internally.

Ns_Cache* NsFastpathCache ( char *  server,
int  size 
)

---------------------------------------------------------------------- NsFastpathCache --

Initialize the fastpath cache.

Results: Pointer to Ns_Cache.

Side effects: None.

----------------------------------------------------------------------

char* NsFindVersion ( char *  request,
unsigned int *  majorPtr,
unsigned int *  minorPtr 
)

----------------------------------------------------------------------

NsFindVersion --

Find the HTTP/x.y version string in a request line.

Results: Start of version string or NULL if not found.

Side effects: Given majorPtr and minorPtr will be updated.

----------------------------------------------------------------------

void NsFreeConn ( Conn connPtr  ) 

----------------------------------------------------------------------

NsFreeConn --

Return a Conn structure to the free list after processing.

Results: None.

Side effects: Will close Sock structure if still open.

----------------------------------------------------------------------

Return the Conn to the driver.

void NsFreeConnInterp ( Conn connPtr  ) 

----------------------------------------------------------------------

NsFreeConnInterp --

Free the interp data, if any, for given connection. This routine is called at the end of connection processing.

Results: None.

Side effects: See PushInterp.

----------------------------------------------------------------------

void NsGetCallbacks ( Tcl_DString *  dsPtr  ) 

Pool* NsGetConnPool ( Conn connPtr  ) 

----------------------------------------------------------------------

NsGetConnPool --

Get pool for given connection.

Results: Pointer to Pool.

Side effects: None.

----------------------------------------------------------------------

NsServer* NsGetInitServer ( void   ) 

----------------------------------------------------------------------

NsGetInitServer --

Return the currently initializing server.

Results: Pointer to NsServer.

Side effects: None.

----------------------------------------------------------------------

Tcl_Encoding NsGetInputEncoding ( Conn connPtr  ) 

----------------------------------------------------------------------

NsGetInputEncoding --

Return the registered input encoding for the connection method/url, if any.

Results: Pointer to Tcl_Encoding or NULL if no encoding registered.

Side effects: None.

----------------------------------------------------------------------

NsInterp* NsGetInterpData ( Tcl_Interp *  interp  ) 

----------------------------------------------------------------------

NsGetInterpData --

Return the interp's NsInterp structure from assoc data. This routine is used when the NsInterp is needed and not available as command ClientData.

Results: Pointer to NsInterp or NULL if none.

Side effects: None.

----------------------------------------------------------------------

Tcl_Encoding NsGetOutputEncoding ( Conn connPtr  ) 

Limits* NsGetRequestLimits ( char *  server,
char *  method,
char *  url 
)

----------------------------------------------------------------------

NsGetRequestLimits --

Return the limits structure for a given request.

Results: Pointer to limits.

Side effects: May return the default limits if no more specific limits have been created.

----------------------------------------------------------------------

void NsGetScheduled ( Tcl_DString *  dsPtr  ) 

NsServer* NsGetServer ( char *  server  ) 

----------------------------------------------------------------------

NsGetServer --

Return the NsServer structure, allocating if necessary.

Results: Pointer to NsServer.

Side effects: None.

----------------------------------------------------------------------

char* NsGetServers ( void   ) 

----------------------------------------------------------------------

NsGetServers --

Return Tcl list of all servers.

Results: Pointer to server list string.

Side effects: None.

----------------------------------------------------------------------

void NsGetSockCallbacks ( Tcl_DString *  dsPtr  ) 

void NsHandleSignals ( void   ) 

----------------------------------------------------------------------

NsHandleSignals --

Loop forever processing signals until a term signal is received.

Results: None.

Side effects: HUP callbacks may be called.

----------------------------------------------------------------------

Wait endlessly for trigger wakeups.

Unblock the signals and exit.

void NsInitBinder ( void   ) 

----------------------------------------------------------------------

NsInitBinder --

Initialize the pre-bind table.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitCache ( void   ) 

----------------------------------------------------------------------

NsInitCache --

Initialize the cache API.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitConf ( void   ) 

----------------------------------------------------------------------

NsInitConf --

Initialize core elements of the nsconf structure at startup.

Results: None.

Side effects: None.

----------------------------------------------------------------------

NB: Declared in stamp.c

Set various core environment variables.

Set various default values.

At library load time the server is considered started. Normally it's marked stopped immediately by Ns_Main unless libnsd is being used for some other, non-server program.

void NsInitConfig ( void   ) 

----------------------------------------------------------------------

NsInitConfig --

Initialize the config interface.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitDrivers ( void   ) 

----------------------------------------------------------------------

NsInitDrivers --

Init communication drivers data structures.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitEncodings ( void   ) 

----------------------------------------------------------------------

NsInitEncodings --

Add compiled-in default encodings.

Results: None.

Side effects: None.

----------------------------------------------------------------------

Allocate URL space id for input encodings.

Initialize hash table of encodings and charsets.

Add default charset and file mappings.

void NsInitFd ( void   ) 

----------------------------------------------------------------------

NsInitFd --

Initialize the fd API's.

Results: None.

Side effects: Will open a shared fd to /dev/null and ensure stdin, stdout, and stderr are open on something.

----------------------------------------------------------------------

Ensure fd 0, 1, and 2 are open on at least /dev/null.

AOLserver now uses poll() but Tcl and other components may still use select() which will likely break when fd's exceed FD_SETSIZE. We now allow setting the fd limit above FD_SETSIZE, but do so at your own risk.

Open a fd on /dev/null which can be later re-used.

void NsInitLimits ( void   ) 

----------------------------------------------------------------------

NsInitLimits --

Initialize request limits.

Results: None.

Side effects: Will create the default limits.

----------------------------------------------------------------------

void NsInitListen ( void   ) 

----------------------------------------------------------------------

NsInitListen --

Initialize listen callback API.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitLog ( void   ) 

----------------------------------------------------------------------

NsInitLog --

Initialize the log API and TLS slot.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitMimeTypes ( void   ) 

----------------------------------------------------------------------

NsInitMimeTypes --

Add compiled-in default mime types.

Results: None.

Side effects: None.

----------------------------------------------------------------------

Initialize hash table of file extensions.

Add default system types first from above

void NsInitModLoad ( void   ) 

----------------------------------------------------------------------

NsInitModLoad --

Initialize module table.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitNsv ( void   ) 

void NsInitPools ( void   ) 

----------------------------------------------------------------------

NsInitPools --

Init thread pools.

Results: None.

Side effects: The default and error pools will be created.

----------------------------------------------------------------------

void NsInitProcInfo ( void   ) 

----------------------------------------------------------------------

NsInitProcInfo --

Initialize the proc info API and default compiled-in callbacks.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitQueue ( void   ) 

----------------------------------------------------------------------

NsInitQueue --

Init connection queue.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitRequests ( void   ) 

----------------------------------------------------------------------

NsInitRequests --

Initialize the request API.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitSched ( void   ) 

----------------------------------------------------------------------

NsInitSched --

Initialize scheduler API.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsInitServer ( char *  server,
Ns_ServerInitProc *  initProc 
)

----------------------------------------------------------------------

NsInitServer --

Create and initialize a new virtual server.

Results: None.

Side effects: Depends on resulting Tcl and module inits.

----------------------------------------------------------------------

Register the fastpath and ADP requests. Fastpath is register by default for all URL's.

Call the given init proc, if any, which may register additional static modules and then load all dynamic and static modules and initialize Tcl. The order is significant.

void NsInitServers ( void   ) 

----------------------------------------------------------------------

NsInitServers --

Server data structures library init.

Results: None.

Side effects: Allocates the global pseudo-server.

----------------------------------------------------------------------

void NsInitTcl ( void   ) 

----------------------------------------------------------------------

NsInitTcl --

Initialize the Nsd Tcl package.

Results: None.

Side effects: None.

----------------------------------------------------------------------

Allocate the thread storage slot for the table of interps per-thread. At thread exit, DeleteData will be called to free any interps remaining on the thread cache and remove the async cancel handler.

Initialize the table of all threads with active TclData and the one-time init table.

void NsInitTclCache ( void   ) 

void NsInitUrlSpace ( void   ) 

----------------------------------------------------------------------

NsInitUrlSpace --

Initialize the urlspace API.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsJoinConnThreads ( void   ) 

----------------------------------------------------------------------

NsJoinConnThreads --

Join any connection threads which have exited.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsLoadModules ( char *  server  ) 

----------------------------------------------------------------------

NsLoadModules --

Load all modules for given server.

Results: None.

Side effects: Will load and initialize modules.

----------------------------------------------------------------------

Check for specific module init after filename.

Load the module if it's not the reserved "tcl" name.

Add this module to the server Tcl init list.

Initialize the static modules (if any). Note that a static module could add a new static module and so the loop is repeated until they're all gone.

void NsLogConf ( void   ) 

----------------------------------------------------------------------

NsLogConf --

Config the logging interface.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsLogOpen ( void   ) 

----------------------------------------------------------------------

NsLogOpen --

Open the log file. Adjust configurable parameters, too.

Results: None.

Side effects: Configures this module to use the newly opened log file. If LogRoll is turned on in the config file, then it registers a signal callback.

----------------------------------------------------------------------

Open the log and schedule the signal roll.

void* NsMap ( int  fd,
off_t  start,
size_t  len,
int  writable,
void **  argPtr 
)

----------------------------------------------------------------------

NsMap --

Memory map a region of a file.

Results: Pointer to mapped region or NULL if mapping failed.

Side effects: None.

----------------------------------------------------------------------

bool NsParamBool ( char *  key,
bool  def 
)

Utility functions.

int NsParamInt ( char *  key,
int  def 
)

----------------------------------------------------------------------

NsParamInt, NsParamBool, NsParamString --

Helper routines for getting int, bool, or string paramaters from the ns/parameters config section, returning defaults if no config is set.

Results: Config value or default.

Side effects: None.

----------------------------------------------------------------------

char* NsParamString ( char *  key,
char *  def 
)

int NsPoll ( struct pollfd pfds,
int  nfds,
Ns_Time *  timeoutPtr 
)

----------------------------------------------------------------------

NsPoll --

Poll file descriptors using an absolute timeout and restarting after any interrupts which may be received.

Results: See poll(2) man page.

Side effects: See poll(2) man page.

----------------------------------------------------------------------

Clear revents.

Determine relative time from absolute time and continue polling if any interrupts are received.

Poll errors are not tolerated in AOLserver as they must indicate a code error which if ignored could lead to data lose and/or endless polling loops and error messages.

void NsPreBind ( char *  args,
char *  file 
)

----------------------------------------------------------------------

NsPreBind --

Pre-bind any requested ports, called from Ns_Main at startup.

Results: None.

Side effects: May pre-bind to one or more ports.

----------------------------------------------------------------------

void NsQueueConn ( Conn connPtr  ) 

----------------------------------------------------------------------

NsQueueConn --

Append a connection to the run queue.

Results: None.

Side effects: Connection will run shortly.

----------------------------------------------------------------------

Queue connection.

void NsRemovePidFile ( char *  service  ) 

void NsRestoreSignals ( void   ) 

---------------------------------------------------------------------- NsRestoreSignals --

Restore all signals to their default value.

Results: None.

Side effects: A new thread will be created.

----------------------------------------------------------------------

void NsRunAtExitProcs ( void   ) 

void NsRunAtReadyProcs ( void   ) 

void NsRunCleanups ( Ns_Conn *  conn  ) 

int NsRunFilters ( Ns_Conn *  conn,
int  why 
)

---------------------------------------------------------------------- NsRunFilters --

Execute each registered filter function in the Filter list.

Results: Returns the status returned from the registered filter function.

Side effects: None.

----------------------------------------------------------------------

void NsRunPreStartupProcs ( void   ) 

----------------------------------------------------------------------

NsRunPreStartupProcs --

Run any callbacks registered for pre-server startup.

Results: None.

Side effects: Callbacks called back.

----------------------------------------------------------------------

void NsRunSignalProcs ( void   ) 

----------------------------------------------------------------------

NsRunSignalProcs --

Run any callbacks registered for when a signal arrives

Results: None.

Side effects: Callbacks called back.

----------------------------------------------------------------------

void NsRunStartupProcs ( void   ) 

----------------------------------------------------------------------

NsRunStartupProcs --

Run any callbacks registered for server startup.

Results: None.

Side effects: Callbacks called back.

----------------------------------------------------------------------

void NsRunTraces ( Ns_Conn *  conn  ) 

---------------------------------------------------------------------- RunTraces, NsRunTraces, NsRunCleanups --

Execute each registered trace.

Results: None.

Side effects: Depends on registered traces, if any.

----------------------------------------------------------------------

void NsSendSignal ( int  sig  ) 

----------------------------------------------------------------------

NsSendSignal --

Send a signal to the main thread.

Results: None.

Side effects: Main thread in NsHandleSignals will wakeup.

----------------------------------------------------------------------

void NsSockClose ( Sock sockPtr,
int  keep 
)

----------------------------------------------------------------------

NsSockClose --

Return a Sock to its DriverThread for closing or keepalive. Note the connection may continue to run after releasing the Sock (traces, etc.).

Results: None.

Side effects: Socket may be reused by a keepalive connection.

----------------------------------------------------------------------

If keepalive is requested and enabled, set the read wait state. Otherwise, set close wait which simply drains any remaining bytes to read.

SOCKET NsSockGetBound ( struct sockaddr_in *  saPtr  ) 

----------------------------------------------------------------------

NsSockGetBound --

Get a pre-bound socket if available.

Results: Socket descriptor or INVALID_SOCKET on error.

Side effects: None.

----------------------------------------------------------------------

int NsStartDrivers ( void   ) 

----------------------------------------------------------------------

NsStartDrivers --

Start all driver threads.

Results: NS_OK if all drivers started, NS_ERROR otherwise.

Side effects: See DriverThread.

----------------------------------------------------------------------

Signal and wait for each driver to start.

void NsStartJobsShutdown ( void   ) 

----------------------------------------------------------------------

NsStartJobsShutdown --

Signal stop of the Tcl job threads.

Results: None.

Side effects: All pending jobs are cancelled and waiting threads interrupted.

----------------------------------------------------------------------

void NsStartPools ( void   ) 

----------------------------------------------------------------------

NsStartPools, NsStopPools --

Start and stop all connection pools.

Results: None.

Side effects: On stop, will wait for existing connections to complete.

----------------------------------------------------------------------

void NsStartQueueShutdown ( void   ) 

----------------------------------------------------------------------

NsStartQueueShutdown --

Trigger all task queues to begin shutdown.

Results: None.

Side effects: None.

----------------------------------------------------------------------

Trigger all queues to shutdown.

void NsStartSchedShutdown ( void   ) 

----------------------------------------------------------------------

NsStartSchedShutdown, NsWaitSchedShutdown --

Inititiate and then wait for sched shutdown.

Results: None.

Side effects: May timeout waiting for sched shutdown.

----------------------------------------------------------------------

void NsStartShutdownProcs ( void   ) 

----------------------------------------------------------------------

NsRunExitProcs --

Run any callbacks registered for server startup, then shutdown, then exit.

Results: None.

Side effects: Callbacks called back.

----------------------------------------------------------------------

void NsStartSockShutdown ( void   ) 

----------------------------------------------------------------------

NsStartSockShutdown, NsWaitSockShutdown --

Initiate and then wait for socket callbacks shutdown.

Results: None.

Side effects: May timeout waiting for shutdown.

----------------------------------------------------------------------

void NsStopDrivers ( void   ) 

----------------------------------------------------------------------

NsStopDrivers --

Trigger driver threads to begin shutdown.

Results: None.

Side effects: Driver threads will close listen sockets and exit after all outstanding connections are complete and closed.

----------------------------------------------------------------------

void NsStopPools ( Ns_Time *  timeoutPtr  ) 

void NsStopScheduledProcs ( void   ) 

void NsStopSockCallbacks ( void   ) 

void NsTclAddCmds ( Tcl_Interp *  interp,
NsInterp itPtr 
)

----------------------------------------------------------------------

NsTclAddCmds --

Create basic and server Tcl commands.

Results: TCL_OK.

Side effects: None.

----------------------------------------------------------------------

int NsTclCheckConnId ( Tcl_Interp *  interp,
Tcl_Obj *  objPtr 
)

----------------------------------------------------------------------

NsTclCheckConnId --

Given an conn ID, could this be a conn ID?

Results: Boolean.

Side effects: If interp is non-null, an error message will be left if necessary.

----------------------------------------------------------------------

struct Bucket* NsTclCreateBuckets ( char *  server,
int  n 
)

----------------------------------------------------------------------

NsTclNsvCreateBuckets --

Create a new array of buckets for a server.

Results: Pointer to bucket array.

Side effects: None.

----------------------------------------------------------------------

int NsTclGetConn ( NsInterp itPtr,
Ns_Conn **  connPtr 
)

----------------------------------------------------------------------

NsTclGetConn --

Return current connection for interp.

Results: TCL_OK if a connection is active, TCL_ERROR otherwise.

Side effects: Given connPtr will be set with conn if not NULL.

----------------------------------------------------------------------

int NsTclGetPool ( Tcl_Interp *  interp,
char *  pool,
Pool **  poolPtrPtr 
)

----------------------------------------------------------------------

NsTclGetPool --

Return Pool by name in Tcl.

Results: Standard Tcl result.

Side effects: Will update poolPtrPtr to point to Pool struct or leave an error message in given interp if no such pool.

----------------------------------------------------------------------

int NsTclGetServer ( NsInterp itPtr,
char **  serverPtr 
)

----------------------------------------------------------------------

NsGetInterpServer --

Get server for given interp.

Results: TCL_OK if interp has a server, TCL_ERROR otherwise.

Side effects: Given serverPtr will be updated with pointer to server string.

----------------------------------------------------------------------

void NsTclInitAddrType ( void   ) 

----------------------------------------------------------------------

NsTclInitAddrType --

Initialize the Tcl address object type.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsTclInitCacheType ( void   ) 

----------------------------------------------------------------------

NsTclInitCacheType --

Initialize the type for Tcl caches.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsTclInitKeylistType ( void   ) 

This is called once from InitInterp() call in tclinit.c for first-time initialization of special Tcl objects.

void NsTclInitObjs ( void   ) 

void NsTclInitQueueType ( void   ) 

----------------------------------------------------------------------

NsInitTclQueueType --

Initialize the Tcl job queue.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsTclInitServer ( char *  server  ) 

----------------------------------------------------------------------

NsTclInitServer --

Evaluate server initialization script at startup.

Results: None.

Side effects: See init script (normally init.tcl).

----------------------------------------------------------------------

void NsTclInitTimeType ( void   ) 

----------------------------------------------------------------------

NsTclInitTimeType --

Initialize Ns_Time Tcl_Obj type.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsTclRunAtClose ( NsInterp itPtr  ) 

----------------------------------------------------------------------

NsTclRunAtClose --

Run any registered connection at-close scripts.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsUnMap ( void *  addr,
void *  arg 
)

----------------------------------------------------------------------

NsUnMap --

Unmap a previosly mmapped region.

Results: None.

Side effects: Failure is considered fatal.

----------------------------------------------------------------------

void NsUpdateEncodings ( void   ) 

----------------------------------------------------------------------

NsUpdateEncodings --

Add additional configured encodings.

Results: None.

Side effects: None.

----------------------------------------------------------------------

Add configured charsets and file mappings.

void NsUpdateMimeTypes ( void   ) 

----------------------------------------------------------------------

NsUpdateMimeTypes --

Add configured mime types.

Results: None.

Side effects: None.

----------------------------------------------------------------------

int NsUrlToFile ( Ns_DString *  dsPtr,
NsServer servPtr,
char *  url 
)

void NsWaitDriversShutdown ( Ns_Time *  toPtr  ) 

----------------------------------------------------------------------

NsWaitDriversShutdown --

Wait for exit of all driver threads.

Results: None.

Side effects: Driver threads are joined.

----------------------------------------------------------------------

void NsWaitJobsShutdown ( Ns_Time *  toPtr  ) 

----------------------------------------------------------------------

NsWaitJobsShutdown --

Wait for Tcl job threads to exit.

Results: None.

Side effects: None.

----------------------------------------------------------------------

void NsWaitQueueShutdown ( Ns_Time *  toPtr  ) 

----------------------------------------------------------------------

NsWaitQueueShutdown --

Wait for all task queues to shutdown.

Results: None.

Side effects: May timeout waiting for shutdown.

----------------------------------------------------------------------

Clear out list of any remaining task queues.

Join all queues possible within total allowed time.

void NsWaitSchedShutdown ( Ns_Time *  toPtr  ) 

void NsWaitShutdownProcs ( Ns_Time *  toPtr  ) 

void NsWaitSockShutdown ( Ns_Time *  toPtr  ) 

int poll ( struct pollfd ,
unsigned  long,
int   
)


Variable Documentation

Ns_OpProc NsAdpProc

Ns_ArgProc NsCacheArgProc

Ns_Callback NsCachePurge

struct _nsconf nsconf

Ns_ArgProc NsConnArgProc

Ns_ThreadProc NsConnThread

Ns_ArgProc NsTclArgProc

Ns_Callback NsTclCallback

External callback functions.

Tcl_ObjCmdProc NsTclListPoolsObjCmd

Ns_SchedProc NsTclSchedProc

Ns_Callback NsTclSignalProc

Ns_ArgProc NsTclSockArgProc

Ns_SockProc NsTclSockProc

Ns_ThreadProc NsTclThread

Ns_ArgProc NsTclThreadArgProc


Generated on Tue Sep 4 19:58:56 2007 by  doxygen 1.5.1