Skip to content

Commit

Permalink
Add [ns_info filters] and [ns_info procs].
Browse files Browse the repository at this point in the history
  • Loading branch information
dossy committed Nov 16, 2010
1 parent 93cdd7e commit 5ea2ab5
Show file tree
Hide file tree
Showing 10 changed files with 357 additions and 11 deletions.
8 changes: 8 additions & 0 deletions doc/ns_info.n
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ Returns the server boot time in seconds.
.RS
Returns the configuration file name.
.RE
\fBns_info filters\fR
.RS
Returns a list of registered filters added through ns_register_filter or Ns_RegisterFilter().
.RE
\fBns_info home\fR
.RS
Returns the directory where the AOLserver was installed.
Expand Down Expand Up @@ -120,6 +124,10 @@ Returns the name of the AOLserver. It's usually "AOLserver."
.RS
Returns the name of the platform that the server is running on (e.g., Solaris).
.RE
\fBns_info procs\fR
.RS
Returns a list of registered procs from maps defined at startup, or added through ns_register_proc or Ns_RegisterRequest().
.RE
\fBns_info\fR server
.RS
returns the name of this virtual server.
Expand Down
3 changes: 3 additions & 0 deletions include/ns.h
Original file line number Diff line number Diff line change
Expand Up @@ -750,6 +750,7 @@ NS_EXTERN void *Ns_RegisterFilter(char *server, char *method, char *URL,
NS_EXTERN void *Ns_RegisterServerTrace(char *server, Ns_TraceProc *proc, void *arg);
NS_EXTERN void *Ns_RegisterConnCleanup(char *server, Ns_TraceProc *proc, void *arg);
NS_EXTERN void *Ns_RegisterCleanup(Ns_TraceProc *proc, void *arg);
NS_EXTERN void Ns_FilterList(Tcl_DString *dsPtr, char *server);

/*
* htuu.c
Expand Down Expand Up @@ -964,6 +965,7 @@ NS_EXTERN void Ns_GetRequest(char *server, char *method, char *url,
int *flagsPtr);
NS_EXTERN void Ns_UnRegisterRequest(char *server, char *method, char *url,
int inherit);
NS_EXTERN int Ns_WalkRequests(char *server, Tcl_DString *dsPtr);
NS_EXTERN int Ns_ConnRunRequest(Ns_Conn *conn);
NS_EXTERN int Ns_ConnRedirect(Ns_Conn *conn, char *url);

Expand Down Expand Up @@ -1294,6 +1296,7 @@ NS_EXTERN void Ns_ServerSpecificSet(char *handle, int id, void *data, int flags,
void (*deletefunc) (void *));
NS_EXTERN void *Ns_ServerSpecificGet(char *handle, int id);
NS_EXTERN void *Ns_ServerSpecificDestroy(char *handle, int id, int flags);
NS_EXTERN int Ns_TrieWalk(int id, int (*callback) (const void *, void *), void *userdata);

/*
* fd.c:
Expand Down
41 changes: 41 additions & 0 deletions nsd/filter.c
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,47 @@ Ns_RegisterFilter(char *server, char *method, char *url,
return (void *) fPtr;
}


/*
*----------------------------------------------------------------------
* Ns_RegisterFilter --
*
* Register a filter function to handle a method/URL combination.
*
* Results:
* Returns a pointer to an opaque object that contains the filter
* information.
*
* Side effects:
* None.
*
*----------------------------------------------------------------------
*/

void
Ns_FilterList(Tcl_DString *dsPtr, char *server)
{
NsServer *servPtr = NsGetServer(server);
Filter *fPtr;

if (servPtr == NULL) {
return;
}
fPtr = servPtr->filter.firstFilterPtr;
while (fPtr != NULL) {
char when[8];

Tcl_DStringStartSublist(dsPtr);
sprintf(when, "%d", fPtr->when);
Tcl_DStringAppendElement(dsPtr, when);
Tcl_DStringAppendElement(dsPtr, fPtr->method);
Tcl_DStringAppendElement(dsPtr, fPtr->url);
Ns_GetProcInfo(dsPtr, fPtr->proc, fPtr->arg);
Tcl_DStringEndSublist(dsPtr);
fPtr = fPtr->nextPtr;
}
}


/*
*----------------------------------------------------------------------
Expand Down
33 changes: 23 additions & 10 deletions nsd/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,19 +499,19 @@ NsTclInfoObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv)
Tcl_DString ds;
static CONST char *opts[] = {
"address", "argv0", "boottime", "builddate", "callbacks",
"config", "home", "hostname", "label", "locks", "log",
"major", "minor", "name", "nsd", "pageroot", "patchlevel",
"pid", "platform", "pools", "scheduled", "server", "servers",
"sockcallbacks", "tag", "tcllib", "threads", "uptime",
"version", "winnt", NULL
"config", "filters", "home", "hostname", "label", "locks",
"log", "major", "minor", "name", "nsd", "pageroot",
"patchlevel", "pid", "platform", "pools", "procs",
"scheduled", "server", "servers", "sockcallbacks", "tag",
"tcllib", "threads", "uptime", "version", "winnt", NULL
};
enum {
IAddressIdx, IArgv0Idx, IBoottimeIdx, IBuilddateIdx, ICallbacksIdx,
IConfigIdx, IHomeIdx, hostINameIdx, ILabelIdx, ILocksIdx, ILogIdx,
IMajorIdx, IMinorIdx, INameIdx, INsdIdx, IPageRootIdx, IPatchLevelIdx,
IPidIdx, IPlatformIdx, IPoolsIdx, IScheduledIdx, IServerIdx, IServersIdx,
sockICallbacksIdx, ITagIdx, ITclLibIdx, IThreadsIdx, IUptimeIdx,
IVersionIdx, IWinntIdx,
IConfigIdx, IFiltersIdx, IHomeIdx, hostINameIdx, ILabelIdx, ILocksIdx,
ILogIdx, IMajorIdx, IMinorIdx, INameIdx, INsdIdx, IPageRootIdx,
IPatchLevelIdx, IPidIdx, IPlatformIdx, IPoolsIdx, IProcsIdx,
IScheduledIdx, IServerIdx, IServersIdx, sockICallbacksIdx, ITagIdx,
ITclLibIdx, IThreadsIdx, IUptimeIdx, IVersionIdx, IWinntIdx,
} _nsmayalias opt;

if (objc != 2) {
Expand Down Expand Up @@ -573,6 +573,19 @@ NsTclInfoObjCmd(ClientData arg, Tcl_Interp *interp, int objc, Tcl_Obj **objv)
#endif
break;

case IFiltersIdx:
if (NsTclGetServer(itPtr, &server) != TCL_OK) {
return TCL_ERROR;
}
Ns_FilterList(&ds, itPtr->servPtr->server);
Tcl_DStringResult(interp, &ds);
break;

case IProcsIdx:
(void) Ns_WalkRequests(NULL, &ds);
Tcl_DStringResult(interp, &ds);
break;

case ILogIdx:
elog = Ns_InfoErrorLog();
Tcl_SetResult(interp, elog == NULL ? "STDOUT" : elog, TCL_STATIC);
Expand Down
1 change: 1 addition & 0 deletions nsd/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -106,5 +106,6 @@ Ns_LibInit(void)
NsInitSched();
NsInitServers();
NsInitTcl();
NsInitTclRequests();
}
}
3 changes: 3 additions & 0 deletions nsd/nsd.h
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,7 @@ extern void NsInitSched(void);
extern void NsInitServers(void);
extern void NsInitTcl(void);
extern void NsInitTclCache(void);
extern void NsInitTclRequests(void);
extern void NsInitUrlSpace(void);
extern void NsInitRequests(void);
extern char *NsFindVersion(char *request, unsigned int *majorPtr,
Expand Down Expand Up @@ -946,6 +947,8 @@ extern Ns_SockProc NsTclSockProc;
extern Ns_ArgProc NsTclSockArgProc;
extern Ns_ThreadProc NsConnThread;
extern Ns_ArgProc NsConnArgProc;
extern Ns_ArgProc NsProcArgProc;
extern Ns_ArgProc NsFilterArgProc;

extern void NsGetCallbacks(Tcl_DString *dsPtr);
extern void NsGetSockCallbacks(Tcl_DString *dsPtr);
Expand Down
53 changes: 53 additions & 0 deletions nsd/op.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ typedef struct {
int refcnt;
Ns_OpProc *proc;
Ns_Callback *delete;
char *method;
char *url;
void *arg;
unsigned int flags;
} Req;
Expand All @@ -59,6 +61,7 @@ typedef struct {
*/

static void FreeReq(void *arg);
static int RequestWalkCallback(const void *data, void *userdata);

/*
* Static variables defined in this file.
Expand Down Expand Up @@ -120,6 +123,8 @@ Ns_RegisterRequest(char *server, char *method, char *url, Ns_OpProc *proc,
reqPtr = ns_malloc(sizeof(Req));
reqPtr->proc = proc;
reqPtr->delete = delete;
reqPtr->method = ns_strdup(method);
reqPtr->url = ns_strdup(url);
reqPtr->arg = arg;
reqPtr->flags = flags;
reqPtr->refcnt = 1;
Expand Down Expand Up @@ -195,6 +200,52 @@ Ns_UnRegisterRequest(char *server, char *method, char *url, int inherit)
Ns_MutexUnlock(&ulock);
}


/*
*----------------------------------------------------------------------
*
* Ns_WalkRequests --
*
* Walk the url space of registered procs.
*
* Results:
* NS_OK, or callback return value if not NS_OK.
*
* Side effects:
* Depends on callback implementation.
*
*----------------------------------------------------------------------
*/

int
Ns_WalkRequests(char *server, Tcl_DString *dsPtr)
{
int result;

Ns_MutexLock(&ulock);
result = Ns_TrieWalk(uid, RequestWalkCallback, dsPtr);
Ns_MutexUnlock(&ulock);

return result;
}

static int
RequestWalkCallback(const void *data, void *userdata)
{
Req *reqPtr = data;
Tcl_DString *dsPtr = userdata;

if (reqPtr != NULL) {
Tcl_DStringStartSublist(dsPtr);
Tcl_DStringAppendElement(dsPtr, reqPtr->method);
Tcl_DStringAppendElement(dsPtr, reqPtr->url);
Ns_GetProcInfo(dsPtr, reqPtr->proc, reqPtr->arg);
Tcl_DStringEndSublist(dsPtr);
}

return NS_OK;
}


/*
*----------------------------------------------------------------------
Expand Down Expand Up @@ -481,6 +532,8 @@ FreeReq(void *arg)
Req *reqPtr = (Req *) arg;

if (--reqPtr->refcnt == 0) {
ns_free(reqPtr->method);
ns_free(reqPtr->url);
if (reqPtr->delete != NULL) {
(*reqPtr->delete) (reqPtr->arg);
}
Expand Down
2 changes: 2 additions & 0 deletions nsd/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ struct proc {
{(void *) NsTclSockProc, "ns:tclsockcallback", NsTclSockArgProc},
{(void *) NsCachePurge, "ns:cachepurge", NsCacheArgProc},
{(void *) NsConnThread, "ns:connthread", NsConnArgProc},
{(void *) NsAdpProc, "ns:adp", NULL},
{(void *) Ns_FastPathOp, "ns:fastpath", NULL},
{NULL, NULL, NULL}
};

Expand Down
52 changes: 52 additions & 0 deletions nsd/tclrequest.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,32 @@ static int RegisterFilterObj(NsInterp *itPtr, int when, int objc,
Tcl_Obj *CONST objv[]);
static int GetNumArgs(Tcl_Interp *interp, Proc *procPtr);


/*
*----------------------------------------------------------------------
*
* NsInitTclRequests --
*
* Register Ns_OpProcs at startup.
*
* Results:
* None.
*
* Side effects:
* ProcInfo entries registered.
*
*----------------------------------------------------------------------
*/

void
NsInitTclRequests(void)
{
Ns_RegisterProcInfo(ProcRequest, "ns:proc", NsProcArgProc);
Ns_RegisterProcInfo(AdpRequest, "ns:adp", NULL);
Ns_RegisterProcInfo(ProcFilter, "ns:filter", NsProcArgProc);
Ns_RegisterProcInfo(Ns_FastPathOp, "ns:fastpath", NULL);
}


/*
*----------------------------------------------------------------------
Expand Down Expand Up @@ -708,3 +734,29 @@ FreeProc(void *arg)
}
ns_free(procPtr);
}


/*
*----------------------------------------------------------------------
*
* NsProcArgProc --
*
* Proc info routine to copy registered proc args.
*
* Results:
* None.
*
* Side effects:
* Will copy script to given dstring.
*
*----------------------------------------------------------------------
*/

void
NsProcArgProc(Tcl_DString *dsPtr, void *arg)
{
Proc *procPtr = arg;

Tcl_DStringAppendElement(dsPtr, procPtr->name);
Tcl_DStringAppendElement(dsPtr, procPtr->args);
}
Loading

0 comments on commit 5ea2ab5

Please sign in to comment.