From: Alex Rousskov Date: Thu, 8 May 2008 20:10:05 +0000 (-0600) Subject: Added Adaptation::Message that brings together the HttpMsg and the X-Git-Tag: SQUID_3_1_0_1~45^2~11^2~26^2~6 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=cb255235c5b7d6af6d6a7ccd3087988a05a6ff4d;p=thirdparty%2Fsquid.git Added Adaptation::Message that brings together the HttpMsg and the corresponding body_pipe and handle HttpMsg locking. TODO: This class should not be needed. HttpMsg already has body_pipe. In the past, we could not use that pipe "as is" because some other code would steal it from the message. Once such cases are removed and something like HttpMsg::Pointer is added to handle locking, there will be no need for Adaptation::Message. TODO: ICAPInOut should be replaced with two Adaptation::Messages, one for the virgin message (that often has a body) and one for the cause, even though the ICAP cause does not need a body. --- diff --git a/src/adaptation/Makefile.am b/src/adaptation/Makefile.am index fb09a726c6..77ceb0a5b4 100644 --- a/src/adaptation/Makefile.am +++ b/src/adaptation/Makefile.am @@ -22,6 +22,8 @@ libadaptation_la_SOURCES = \ Initiate.h \ Initiator.cc \ Initiator.h \ + Message.cc \ + Message.h \ Service.cc \ Service.h \ ServiceConfig.cc \ diff --git a/src/adaptation/Message.cc b/src/adaptation/Message.cc new file mode 100644 index 0000000000..5d7ed767b2 --- /dev/null +++ b/src/adaptation/Message.cc @@ -0,0 +1,58 @@ +/* + * DEBUG: section XXX + */ + +#include "squid.h" +#include "HttpMsg.h" +#include "TextException.h" +#include "adaptation/Message.h" + +Adaptation::Message::Message(): header(NULL) +{ +} + +Adaptation::Message::Message(Header *aHeader): header(NULL) +{ + set(aHeader); +} + +Adaptation::Message::~Message() +{ + clear(); +} + +void +Adaptation::Message::clear() +{ + HTTPMSGUNLOCK(header); + body_pipe = NULL; +} + +void +Adaptation::Message::set(Header *aHeader) +{ + clear(); + if (aHeader) { + header = HTTPMSGLOCK(aHeader); + body_pipe = header->body_pipe; + } +} + +void +Adaptation::Message::copyTo(Message &dest) +{ + Must(!dest.body_pipe); // can relax if needed, but need !body_pipe->used() + dest.clear(); + if (header) { + if (header->body_pipe != NULL) { + // check that it would not be too late to clone the pipe + Must(!header->body_pipe->consumedSize()); + header->body_pipe->clearConsumer(); // if any + // note: current header->body_pipe producer may later become + // dest.body_pipe consumer and consume its own data + // TODO: consumer should detect and short-circuit no-op adaptation + } + Header *copy = header->clone(); + dest.set(copy); + } +} diff --git a/src/adaptation/Message.h b/src/adaptation/Message.h new file mode 100644 index 0000000000..531fec6bd6 --- /dev/null +++ b/src/adaptation/Message.h @@ -0,0 +1,50 @@ + +/* + * $Id$ + */ + +#ifndef SQUID__ADAPTATION__MESSAGE_H +#define SQUID__ADAPTATION__MESSAGE_H + +class HttpMsg; +class BodyPipe; +template +class RefCount; +typedef RefCount BodyPipePointer; + +namespace Adaptation { + +// Manages the header and the body of an HTTP message being worked on. +// Adaptation transactions use this class for virgin and adapted HTTP messages. +class Message +{ + +public: + typedef HttpMsg Header; + + Message(); + Message(Header *aHeader); + ~Message(); + + void clear(); + void set(Header *aHeader); + + void copyTo(Message &dest); + +public: + // virgin or adapted message being worked on + Header *header; // parsed HTTP status/request line and headers + + // Copy of header->body_pipe, in case somebody moves the original. + BodyPipePointer body_pipe; + +private: + Message(const Message &); // not implemented + Message &operator =(const Message &); // not implemented +}; + +} // namespace Adaptation; + +// TODO: replace ICAPInOut with Adaptation::Message (adding one for "cause") + +#endif /* SQUID__ADAPTATION__MESSAGE_H */