tclinit.c File Reference

#include "nsd.h"

Data Structures

struct  TclData
struct  TclTrace
struct  ScriptTrace
struct  Defer
struct  AtClose
struct  Package

Functions

void NsInitTcl (void)
Tcl_Interp * Ns_TclCreateInterp (void)
int Ns_TclInit (Tcl_Interp *interp)
int Nsd_Init (Tcl_Interp *interp)
int Ns_TclEval (Ns_DString *dsPtr, char *server, char *script)
Tcl_Interp * Ns_TclAllocateInterp (char *server)
void Ns_TclDeAllocateInterp (Tcl_Interp *interp)
Tcl_Interp * Ns_GetConnInterp (Ns_Conn *conn)
void Ns_FreeConnInterp (Ns_Conn *conn)
Ns_Conn * Ns_TclGetConn (Tcl_Interp *interp)
void Ns_TclDestroyInterp (Tcl_Interp *interp)
void Ns_TclMarkForDelete (Tcl_Interp *interp)
int Ns_TclRegisterTrace (char *server, Ns_TclTraceProc *proc, void *arg, int when)
int Ns_TclRegisterAtCreate (Ns_TclTraceProc *proc, void *arg)
int Ns_TclRegisterAtCleanup (Ns_TclTraceProc *proc, void *arg)
int Ns_TclRegisterAtDelete (Ns_TclTraceProc *proc, void *arg)
int Ns_TclInitInterps (char *server, Ns_TclInterpInitProc *proc, void *arg)
void Ns_TclRegisterDeferred (Tcl_Interp *interp, Ns_TclDeferProc *proc, void *arg)
char * Ns_TclLibrary (char *server)
char * Ns_TclInterpServer (Tcl_Interp *interp)
char * Ns_TclLogError (Tcl_Interp *interp)
char * Ns_TclLogErrorRequest (Tcl_Interp *interp, Ns_Conn *conn)
int Ns_TclInitModule (char *server, char *module)
int NsTclGetServer (NsInterp *itPtr, char **serverPtr)
int NsTclICtlObjCmd (ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv)
int NsTclAtCloseObjCmd (ClientData arg, Tcl_Interp *interp, int objc, CONST Tcl_Obj **objv)
int NsTclMarkForDeleteObjCmd (ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv)
void NsTclInitServer (char *server)
NsInterpNsGetInterpData (Tcl_Interp *interp)
void NsFreeConnInterp (Conn *connPtr)
void NsTclRunAtClose (NsInterp *itPtr)

Function Documentation

void Ns_FreeConnInterp ( Ns_Conn *  conn  ) 

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

Ns_FreeConnInterp --

Release and cleanup the interp associated with given connection. This routine no longer does actual cleanup. The connection cleanup code will call NsFreeConnInterp if needed.

Results: None.

Side effects: None.

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

Tcl_Interp* Ns_GetConnInterp ( Ns_Conn *  conn  ) 

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

Ns_GetConnInterp --

Get the interp for the given connection. When first called for a connection, the interp data is allocated and associated with the given connection. The interp will be automatically cleaned up at the end of the connection via a call to via NsFreeConnInterp().

Results: Pointer to Tcl interp data initialized for given connection.

Side effects: See NsGetInputEncodings for details on connection encoding setup required to ensure proper UTF-8 input and output.

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

Tcl_Interp* Ns_TclAllocateInterp ( char *  server  ) 

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

Ns_TclAllocateInterp --

Allocate an interpreter from the per-thread list. Note that a single thread can have multiple interps for multiple virtual servers.

Results: Pointer to Tcl_Interp.

Side effects: See PopInterp for details on various traces which may be called.

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

Tcl_Interp* Ns_TclCreateInterp ( void   ) 

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

Ns_TclCreateInterp --

Create a new interp with basic Nsd package.

Results: Pointer to new interp.

Side effects: See CreateInterp.

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

void Ns_TclDeAllocateInterp ( Tcl_Interp *  interp  ) 

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

Ns_TclDeAllocateInterp --

Get the NsInterp for the given interp and return the interp to the per-thread cache. If the interp is associated with a connection, silently do nothing as cleanup will occur later with connection cleanup. Also, if the interp is not actually an AOLserver interp, i.e., missing the NsInterp structure, simply delete the interp directly.

Results: None.

Side effects: See notes on garbage collection in PushInterp.

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

void Ns_TclDestroyInterp ( Tcl_Interp *  interp  ) 

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

Ns_TclDestroyInterp --

Delete an interp.

Results: None.

Side effects: None.

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

int Ns_TclEval ( Ns_DString *  dsPtr,
char *  server,
char *  script 
)

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

Ns_TclEval --

Execute a Tcl script in the context of the the given server.

Results: Tcl return code.

Side effects: String results or error are placed in dsPtr if not NULL.

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

Ns_Conn* Ns_TclGetConn ( Tcl_Interp *  interp  ) 

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

Ns_TclGetConn --

Get the Ns_Conn structure associated with this tcl interp.

Results: An Ns_Conn.

Side effects: None.

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

int Ns_TclInit ( Tcl_Interp *  interp  ) 

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

Ns_TclInit --

Initialize an interp with the global server context.

Results: TCL_OK or TCL_ERROR on init error.

Side effects: See InitData.

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

int Ns_TclInitInterps ( char *  server,
Ns_TclInterpInitProc *  proc,
void *  arg 
)

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

Ns_TclInitInterps --

Arrange for the given proc to be called on newly created interps. This routine now simply uses the more general Tcl interp tracing facility. Earlier versions of AOLserver would invoke the given proc immediately on each interp in a shared pool which explains this otherwise misnamed API.

Results: See Ns_TclRegisterTrace.

Side effects: See Ns_TclRegisterTrace.

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

int Ns_TclInitModule ( char *  server,
char *  module 
)

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

Ns_TclInitModule --

Add a module name to the init list.

Results: Always TCL_OK.

Side effects: Module will be initialized by the init script later.

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

char* Ns_TclInterpServer ( Tcl_Interp *  interp  ) 

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

Ns_TclInterpServer --

Return the name of the server.

Results: Server name.

Side effects: None.

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

char* Ns_TclLibrary ( char *  server  ) 

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

Ns_TclLibrary --

Return the name of the private tcl lib

Results: Tcl lib name.

Side effects: None.

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

char* Ns_TclLogError ( Tcl_Interp *  interp  ) 

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

Ns_TclLogError --

Log the global errorInfo variable to the server log.

Results: Returns a pointer to the errorInfo.

Side effects: None.

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

char* Ns_TclLogErrorRequest ( Tcl_Interp *  interp,
Ns_Conn *  conn 
)

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

Ns_TclLogErrorRequest --

Log both errorInfo and info about the HTTP request that led to it.

Results: Returns a pointer to the errorInfo.

Side effects: None.

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

void Ns_TclMarkForDelete ( Tcl_Interp *  interp  ) 

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

Ns_TclMarkForDelete --

Mark the interp to be deleted at the next deallocation. This routine is useful to destory interps after they've been modified in weird ways, e.g., by the TclPro debugger.

Results: None.

Side effects: Interp will be deleted on next de-allocate.

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

int Ns_TclRegisterAtCleanup ( Ns_TclTraceProc *  proc,
void *  arg 
)

int Ns_TclRegisterAtCreate ( Ns_TclTraceProc *  proc,
void *  arg 
)

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

Ns_TclRegisterAtCreate, Ns_TclRegisterAtCleanup, Ns_TclRegisterAtDelete --

Register callbacks for interp create, cleanup, and delete at startup. These routines are deprecated in favor of the more general Ns_TclRegisterTrace. In particular, they do not take a virtual server argument so must assume the currently initializing server is the intended server.

Results: See Ns_TclRegisterTrace.

Side effects: See Ns_TclRegisterTrace.

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

int Ns_TclRegisterAtDelete ( Ns_TclTraceProc *  proc,
void *  arg 
)

void Ns_TclRegisterDeferred ( Tcl_Interp *  interp,
Ns_TclDeferProc *  proc,
void *  arg 
)

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

Ns_TclRegisterDeferred --

Register a procedure to be called when the interp is deallocated. This is on-shot FIFO order callback mechanism which is seldom used.

Results: None.

Side effects: Procedure will be called later.

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

int Ns_TclRegisterTrace ( char *  server,
Ns_TclTraceProc *  proc,
void *  arg,
int  when 
)

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

Ns_TclRegisterTrace --

Add a Tcl trace. Traces are called in FIFO order.

Results: NS_OK if called with a non-NULL server, NS_ERROR otherwise.

Side effects: Will modify server trace list.

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

int Nsd_Init ( Tcl_Interp *  interp  ) 

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

Nsd_Init --

Init routine called when libnsd is loaded via the Tcl load command. This simply calls Ns_TclInit.

Results: See Ns_TclInit.

Side effects: See Ns_TclInit.

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

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.

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

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.

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

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.

int NsTclAtCloseObjCmd ( ClientData  arg,
Tcl_Interp *  interp,
int  objc,
CONST Tcl_Obj **  objv 
)

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

NsTclAtCloseObjCmd --

Implements ns_atclose.

Results: Tcl result.

Side effects: Script will be invoked when the connection is closed. Note the connection may continue execution, e.g., with continued ADP code, traces, etc.

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

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.

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

int NsTclICtlObjCmd ( ClientData  arg,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj **  objv 
)

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

NsTclICtlObjCmd --

Implements ns_ictl command to control interp state for virtual server interps. This command provide internal control functions required by the init.tcl script and is not intended to be called by a user directly. It supports four activities: 1. Managing the list of "modules" to initialize. 2. Saving the init script for evaluation with new interps. 3. Checking for change of the init script. 4. Register script-level traces.

See init.tcl for details.

Results: Standard Tcl result.

Side effects: May update current saved server Tcl state.

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

Add a Tcl module to the list of for later initialization.

Get the list of modules for initialization. See init.tcl for expected use.

Get the current init script to evaluate in new interps.

Check the version of this interp against current init script.

Save the init script.

NB: Epoch zero reserved for new interps.

Check for and process possible change in the init script.

Invoke the legacy defer callbacks.

Confirm the package can be loaded and determine version.

Confirm current registered package is the same version.

Register new package.

Register script-level interp traces.

NB: Silence compiler.

void NsTclInitServer ( char *  server  ) 

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

NsTclInitServer --

Evaluate server initialization script at startup.

Results: None.

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

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

int NsTclMarkForDeleteObjCmd ( ClientData  arg,
Tcl_Interp *  interp,
int  objc,
Tcl_Obj **  objv 
)

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

NsTclMarkForDeleteObjCmd --

Implements ns_markfordelete.

Results: Tcl result.

Side effects: See Ns_TclMarkForDelete.

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

void NsTclRunAtClose ( NsInterp itPtr  ) 

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

NsTclRunAtClose --

Run any registered connection at-close scripts.

Results: None.

Side effects: None.

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


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