Hello -
Here is a patch to add another subcommand to ns_conn called state. It
returns the current state of processing the conn:
ns_conn state -> {"adp" || "tcl || "filter" || "trace"}
The reason I wrote this patch was because I wanted to be able to write a
library function stop all processing of the conn regardless of what
state the conn is in. If the conn is in an ADP, you have to call
ns_adp_abort. If the conn is in a TCL file, you have to call
ns_tcl_abort, etc. etc. etc.
Thus the following function becomes possible:
proc ns_stop {} {
switch [ns_conn state] {
"adp" {ns_adp_abort}
"tcl" {ns_tcl_abort}
"filter" {return "filter_return"}
"trace" {return -code return}
}
}
I'm not a really good C hacker, so please feel free to assault my coding
mercilessly. The patch is built against 4b10. Thanks!
-jag
--
Joshua Ginsberg <[EMAIL PROTECTED]>
--
AOLserver - http://www.aolserver.com/
To Remove yourself from this list, simply send an email to <[EMAIL PROTECTED]> with the
body of "SIGNOFF AOLSERVER" in the email message. You can leave the Subject: field of
your email blank.
Only in /usr/local/aolserver/aolserver-4.0-beta10-src/include: Makefile.global~
Only in /usr/local/aolserver/aolserver-4.0-beta10-src/include: Makefile.module
diff -u --recursive ./include/ns.h /usr/local/aolserver/aolserver-4.0-beta10-src/include/ns.h
--- ./include/ns.h 2003-05-31 14:42:41.000000000 -0600
+++ /usr/local/aolserver/aolserver-4.0-beta10-src/include/ns.h 2003-10-19 17:19:47.000000000 -0600
@@ -327,6 +327,7 @@
char *authPasswd;
int contentLength;
int flags; /* Currently, only NS_CONN_CLOSED. */
+ char *state;
} Ns_Conn;
/*
diff -u --recursive ./nsd/adprequest.c /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/adprequest.c
--- ./nsd/adprequest.c 2003-03-06 12:39:09.000000000 -0700
+++ /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/adprequest.c 2003-10-19 17:20:26.000000000 -0600
@@ -100,6 +100,11 @@
Tcl_Obj *objv[2];
/*
+ * Set the conn state to ADP
+ */
+ conn->state = "adp";
+
+ /*
* Verify the file exists.
*/
diff -u --recursive ./nsd/conn.c /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/conn.c
--- ./nsd/conn.c 2003-03-07 11:08:16.000000000 -0700
+++ /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/conn.c 2003-10-19 17:06:44.000000000 -0600
@@ -46,6 +46,28 @@
/*
*----------------------------------------------------------------------
*
+ * Ns_ConnState --
+ *
+ * Get the current state of this conn
+ *
+ * Results:
+ * A pointer to a string with the conn's status
+ *
+ * Side effects:
+ * None
+ *
+ *----------------------------------------------------------------------
+ */
+
+char *
+Ns_ConnState(Ns_Conn *conn)
+{
+ return conn->state;
+}
+
+/*
+ *----------------------------------------------------------------------
+ *
* Ns_ConnHeaders --
*
* Get the headers
@@ -791,7 +813,7 @@
"filelength", "fileheaders", "flags", "form", "headers",
"host", "id", "isconnected", "location", "method",
"outputheaders", "peeraddr", "peerport", "port", "protocol",
- "query", "request", "server", "sock", "start", "status",
+ "query", "request", "server", "sock", "state", "start", "status",
"url", "urlc", "urlencoding", "urlv", "version", "write_encoded", NULL
};
enum ISubCmdIdx {
@@ -801,7 +823,7 @@
CFormIdx, CHeadersIdx, CHostIdx, CIdIdx, CIsConnectedIdx,
CLocationIdx, CMethodIdx, COutputHeadersIdx, CPeerAddrIdx,
CPeerPortIdx, CPortIdx, CProtocolIdx, CQueryIdx, CRequestIdx,
- CServerIdx, CSockIdx, CStartIdx, CStatusIdx, CUrlIdx,
+ CServerIdx, CSockIdx, CStateIdx, CStartIdx, CStatusIdx, CUrlIdx,
CUrlcIdx, CUrlEncodingIdx, CUrlvIdx, CVersionIdx, CWriteEncodedIdx
} opt;
@@ -1076,6 +1098,9 @@
Tcl_SetResult(interp, Ns_ConnServer(conn), TCL_STATIC);
break;
+ case CStateIdx:
+ Tcl_SetResult(interp, Ns_ConnState(conn), TCL_STATIC);
+
case CStatusIdx:
Tcl_SetIntObj(result, Ns_ConnResponseStatus(conn));
break;
diff -u --recursive ./nsd/filter.c /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/filter.c
--- ./nsd/filter.c 2002-09-28 13:23:39.000000000 -0600
+++ /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/filter.c 2003-10-19 17:21:08.000000000 -0600
@@ -130,6 +130,7 @@
status = NS_OK;
if (conn->request != NULL) {
+ conn->state = "filter";
method = conn->request->method;
url = conn->request->url;
fPtr = connPtr->servPtr->filter.firstFilterPtr;
@@ -258,7 +259,7 @@
NsRunTraces(Ns_Conn *conn)
{
Conn *connPtr = (Conn *) conn;
-
+ conn->state = "trace";
RunTraces(conn, connPtr->servPtr->filter.firstTracePtr);
}
diff -u --recursive ./nsd/nsd.h /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/nsd.h
--- ./nsd/nsd.h 2003-07-18 12:01:17.000000000 -0600
+++ /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/nsd.h 2003-10-19 17:00:03.000000000 -0600
@@ -401,6 +401,7 @@
char *authPasswd;
int contentLength;
int flags;
+ char *state;
/*
* Visible only in a Conn:
diff -u --recursive ./nsd/tclrequest.c /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/tclrequest.c
--- ./nsd/tclrequest.c 2003-01-18 12:24:20.000000000 -0700
+++ /usr/local/aolserver/aolserver-4.0-beta10-src/nsd/tclrequest.c 2003-10-19 17:16:18.000000000 -0600
@@ -333,6 +333,7 @@
static int
AdpRequest(void *arg, Ns_Conn *conn)
{
+ conn->state="adp";
return Ns_AdpRequest(conn, (char *) arg);
}
@@ -385,6 +386,7 @@
}
Tcl_DStringAppendElement(&cmd, procPtr->args ? procPtr->args : "");
}
+ conn->state="tcl";
if (Tcl_GlobalEval(interp, cmd.string) != TCL_OK) {
Ns_TclLogError(interp);
if (Ns_ConnResetReturn(conn) == NS_OK) {