/*
- * $Id: client_side.cc,v 1.634 2003/03/15 04:17:39 robertc Exp $
+ * $Id: client_side.cc,v 1.635 2003/04/06 08:23:10 robertc Exp $
*
* DEBUG: section 33 Client-side Routines
* AUTHOR: Duane Wessels
static bool okToAccept();
static int clientIsRequestBodyValid(int bodyLength);
static int clientIsRequestBodyTooLargeForPolicy(size_t bodyLength);
-static void clientProcessBody(ConnStateData * conn);
+/* convenience class while splitting up body handling */
+/* temporary existence only - on stack use expected */
+
+class ClientBody
+{
+
+public:
+ ClientBody (ConnStateData *);
+ void process();
+ void preProcessing();
+ void processBuffer();
+
+private:
+ ConnStateData *conn;
+ char *buf;
+ CBCB *callback;
+ request_t *request;
+};
+
static void clientUpdateStatHistCounters(log_type logType, int svc_time);
static void clientUpdateStatCounters(log_type logType);
static void clientUpdateHierCounters(HierarchyLogEntry *);
if (conn->in.notYetUsed != conn->body.size_left) {
/* != 0 when no request body */
/* Partial request received. Abort client connection! */
- debug(33, 3) ("clientReadRequest: FD %d aborted, partial request\n",+ fd);
+ debug(33, 3) ("clientAfterReadingRequests: FD %d aborted, partial request\n",+ fd);
comm_close(fd);
return;
}
if (context->flags.parsed_ok == 0) {
clientStreamNode *node = context->getClientReplyContext();
- debug(33, 1) ("clientReadRequest: Invalid Request\n");
+ debug(33, 1) ("clientProcessRequest: Invalid Request\n");
clientReplyContext *repContext = dynamic_cast<clientReplyContext *>(node->data.getRaw());
assert (repContext);
repContext->setReplyToError(ERR_INVALID_REQ, HTTP_BAD_REQUEST, method, NULL,
int result = conn->getConcurrentRequestCount() < (Config.onoff.pipeline_prefetch ? 2 : 1);
if (!result) {
- debug(33, 3) ("clientReadRequest: FD %d max concurrent requests reached\n",
+ debug(33, 3) ("connOkToAddRequest: FD %d max concurrent requests reached\n",
conn->fd);
- debug(33, 5) ("clientReadRequest: FD %d defering new request until one is done\n",
+ debug(33, 5) ("connOkToAddRequest: FD %d defering new request until one is done\n",
conn->fd);
}
/* Process request body if any */
- if (conn->in.notYetUsed > 0 && conn->body.callback != NULL)
- clientProcessBody(conn);
+ if (conn->in.notYetUsed > 0 && conn->body.callback != NULL) {
+ ClientBody body(conn);
+ body.process();
+ }
/* Process next request */
if (conn->getConcurrentRequestCount() == 0)
conn->body.buf = buf;
conn->body.bufsize = size;
conn->body.request = requestLink(request);
- clientProcessBody(conn);
+ ClientBody body (conn);
+ body.process();
}
-/* Called by clientReadRequest to process body content */
-static void
-clientProcessBody(ConnStateData * conn)
+ClientBody::ClientBody(ConnStateData *aConn) : conn(aConn), buf (NULL), callback(NULL), request(NULL)
+{}
+
+void
+ClientBody::preProcessing()
{
- size_t size;
- char *buf = conn->body.buf;
- void *cbdata = conn->body.cbdata;
- CBCB *callback = conn->body.callback;
- request_t *request = conn->body.request;
+ callback = conn->body.callback;
+ request = conn->body.request;
/* Note: request is null while eating "aborted" transfers */
- debug(33, 2) ("clientProcessBody: start fd=%d body_size=%lu in.notYetUsed=%lu cb=%p req=%p\n",
+ debug(33, 2) ("clientBody::process: start fd=%d body_size=%lu in.notYetUsed=%lu cb=%p req=%p\n",
conn->fd, (unsigned long int) conn->body.size_left,
(unsigned long int) conn->in.notYetUsed, callback, request);
+}
- if (conn->in.notYetUsed) {
- /* Some sanity checks... */
- assert(conn->body.size_left > 0);
- assert(conn->in.notYetUsed > 0);
- assert(callback != NULL);
- assert(buf != NULL);
- /* How much do we have to process? */
- size = conn->in.notYetUsed;
+/* Called by clientReadRequest to process body content */
+void
+ClientBody::process()
+{
+ preProcessing();
- if (size > conn->body.size_left) /* only process the body part */
- size = conn->body.size_left;
+ if (conn->in.notYetUsed)
+ processBuffer();
+ else
+ conn->readSomeData();
+}
- if (size > conn->body.bufsize) /* don't copy more than requested */
- size = conn->body.bufsize;
+void
+ClientBody::processBuffer()
+{
+ /* Some sanity checks... */
+ assert(conn->body.size_left > 0);
+ assert(conn->in.notYetUsed > 0);
+ assert(callback != NULL);
+ buf = conn->body.buf;
+ assert(buf != NULL);
+ /* How much do we have to process? */
+ size_t size = conn->in.notYetUsed;
- xmemcpy(buf, conn->in.buf, size);
+ if (size > conn->body.size_left) /* only process the body part */
+ size = conn->body.size_left;
- conn->body.size_left -= size;
+ if (size > conn->body.bufsize) /* don't copy more than requested */
+ size = conn->body.bufsize;
- /* Move any remaining data */
- conn->in.notYetUsed -= size;
+ xmemcpy(buf, conn->in.buf, size);
- if (conn->in.notYetUsed > 0)
- xmemmove(conn->in.buf, conn->in.buf + size, conn->in.notYetUsed);
+ conn->body.size_left -= size;
- /* Remove request link if this is the last part of the body, as
- * clientReadRequest automatically continues to process next request */
- if (conn->body.size_left <= 0 && request != NULL)
- request->body_connection = NULL;
+ /* Move any remaining data */
+ conn->in.notYetUsed -= size;
- /* Remove clientReadBody arguments (the call is completed) */
- conn->body.request = NULL;
+ if (conn->in.notYetUsed > 0)
+ xmemmove(conn->in.buf, conn->in.buf + size, conn->in.notYetUsed);
- conn->body.callback = NULL;
+ /* Remove request link if this is the last part of the body, as
+ * clientReadRequest automatically continues to process next request */
+ if (conn->body.size_left <= 0 && request != NULL)
+ request->body_connection = NULL;
- conn->body.buf = NULL;
+ /* Remove clientReadBody arguments (the call is completed) */
+ conn->body.request = NULL;
- conn->body.bufsize = 0;
+ conn->body.callback = NULL;
- /* Remember that we have touched the body, not restartable */
- if (request != NULL) {
- request->flags.body_sent = 1;
- conn->body.request = NULL;
- }
+ conn->body.buf = NULL;
- /* Invoke callback function */
- callback(buf, size, cbdata);
+ conn->body.bufsize = 0;
- if (request != NULL) {
- requestUnlink(request); /* Linked in clientReadBody */
- }
+ /* Remember that we have touched the body, not restartable */
+ if (request != NULL) {
+ request->flags.body_sent = 1;
+ conn->body.request = NULL;
+ }
- debug(33, 2) ("clientProcessBody: end fd=%d size=%lu body_size=%lu in.notYetUsed=%lu cb=%p req=%p\n",
- conn->fd, (unsigned long int)size, (unsigned long int) conn->body.size_left,
- (unsigned long) conn->in.notYetUsed, callback, request);
+ /* Invoke callback function */
+ void *cbdata = conn->body.cbdata;
+
+ callback(buf, size, cbdata);
+
+ if (request != NULL) {
+ requestUnlink(request); /* Linked in clientReadBody */
}
+
+ debug(33, 2) ("ClientBody::process: end fd=%d size=%lu body_size=%lu in.notYetUsed=%lu cb=%p req=%p\n",
+ conn->fd, (unsigned long int)size, (unsigned long int) conn->body.size_left,
+ (unsigned long) conn->in.notYetUsed, callback, request);
}
/* A dummy handler that throws away a request-body */
}
clientReadBodyAbortHandler(NULL, -1, conn); /* Install abort handler */
- /* clientProcessBody() */
+ /* ClientBody::process() */
return 1; /* Aborted */
}