]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Added Adaptation::Message that brings together the HttpMsg and the
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 8 May 2008 20:10:05 +0000 (14:10 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Thu, 8 May 2008 20:10:05 +0000 (14:10 -0600)
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.

src/adaptation/Makefile.am
src/adaptation/Message.cc [new file with mode: 0644]
src/adaptation/Message.h [new file with mode: 0644]

index fb09a726c6dadc209f209f91ae9104a909744981..77ceb0a5b4362b0dadaa5ff3432f3ca4e77fbbfa 100644 (file)
@@ -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 (file)
index 0000000..5d7ed76
--- /dev/null
@@ -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 (file)
index 0000000..531fec6
--- /dev/null
@@ -0,0 +1,50 @@
+
+/*
+ * $Id$
+ */
+
+#ifndef SQUID__ADAPTATION__MESSAGE_H
+#define SQUID__ADAPTATION__MESSAGE_H
+
+class HttpMsg;
+class BodyPipe;
+template <class C>
+class RefCount;
+typedef RefCount<BodyPipe> 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 */