--------------------- PatchSet 1517 Date: 2005/08/17 20:02:33 Author: rousskov Branch: squid3-icap Tag: (none) Log: - The ICAP Anchor implements message pipe sink and source interfaces. It helps HttpStateData to marshall the incoming/virgin HTTP message (being recieved from the HTTP server) to Squid's ICAP client module, using the MsgPipe interface. The same interface is used to get the adapted HTTP message back from the ICAP client. HttpStateData is the "owner" of the ICAPAnchor. The implementation is just a sketch for now. Members: src/ICAPAnchor.cc:1.1->1.1.2.1 src/ICAPAnchor.h:1.1->1.1.2.1 --- /dev/null Wed Feb 14 13:33:00 2007 +++ squid3/src/ICAPAnchor.cc Wed Feb 14 13:34:50 2007 @@ -0,0 +1,97 @@ +#include "squid.h" +#include "MsgPipe.h" +#include "HttpRequest.h" +#include "HttpReply.h" +#include "ICAPAnchor.h" +#include "ICAPModule.h" + +ICAPAnchor::ICAPAnchor(): virgin(NULL), adapted(NULL) { + and initialize HttpStateData pointer +} + +ICAPAnchor::~ICAPAnchor() { + stop(notifyNone); +} + +void ICAPAnchor::startRespMod(HttpRequest *request, HttpReply *reply, MemObject *buf) { + remember some pointer to HttpStateData to call it later? + + virgin = new MsgPipe; // this is the place to create a refcount ptr + virgin->source = this; + virgin->cause = request; + virgin->header = reply; + virgin->body is buf->mem_hdr; + + adapted = new MsgPipe; + adapted->sink = this; + adapted->cause = request; // should not hurt + + ICAPInitXaction(virgin, adapted); + virgin->sendSourceStart(); // we may have virgin data to provide + adapted->sendSinkNeed(); // we want adapted response, eventially +} + +void ICAPAnchor::sendMoreData() { + virgin->sendSourceProgress(); +} + +// HttpStateData tells us to abort +void ICAPAnchor::ownerAbort() { + stop(notifyIcap); +} + +// ICAP client needs more virgin response data +void ICAPAnchor::noteSinkNeed(MsgPipe *p) { + 1) tell HttpStateData to resume reading (in case it has stopped due to full buffers, etc.) + 2) check that HttpStateData is reading (or we will get stuck w/o progress) +} + +// ICAP client aborting +void ICAPAnchor::noteSinkAbort(MsgPipe *p) { + stop(notifyOwner); +} + +// ICAP client starts sending adapted response +void ICAPAnchor::noteSourceStart(MsgPipe *p) { + tell HttpStateData to prepare the response store + noteSourceProgress(p); +} + +// ICAP client sends more data +void ICAPAnchor::noteSourceProgress(MsgPipe *p) { + tell HttpStateData to store a fresh portion of the adapted response +} + +// ICAP client is done sending adapted response +void ICAPAnchor::noteSourceFinish(MsgPipe *p) { + tell HttpStateData that we expect no more response data + stop(notifyNone); +} + +// ICAP client is aborting +void ICAPAnchor::noteSourceAbort(MsgPipe *p) { + stop(notifyOwner); +} + +// internal cleanup +void ICAPAnchor::stop(Notify notify) { + if (virgin) { + if (notify == notifyIcap) + virgin->sendSourceAbort(); + // this is the place to decrement refcount ptr + virgin = NULL; + } + if (adapted) { + if (notify == notifyIcap) + adapted->sendSinkAbort(); + // this is the place to decrement refcount ptr + adapted = NULL; + } + + if (pointer to HttpStateData) { + if (notifyOwner) + tell HttpStateData that we are aborting prematurely + pointer to HttpStateData = NULL; // will not call it any more + } +} + --- /dev/null Wed Feb 14 13:33:00 2007 +++ squid3/src/ICAPAnchor.h Wed Feb 14 13:34:50 2007 @@ -0,0 +1,81 @@ + +/* + * $Id: ICAPAnchor.h,v 1.1.2.1 2005/08/17 20:02:33 rousskov Exp $ + * + * + * SQUID Web Proxy Cache http://www.squid-cache.org/ + * ---------------------------------------------------------- + * + * Squid is the result of efforts by numerous individuals from + * the Internet community; see the CONTRIBUTORS file for full + * details. Many organizations have provided support for Squid's + * development; see the SPONSORS file for full details. Squid is + * Copyrighted (C) 2001 by the Regents of the University of + * California; see the COPYRIGHT file for full details. Squid + * incorporates software developed and/or copyrighted by other + * sinks; see the CREDITS file for full details. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111, USA. + * + */ + +#ifndef SQUID_ICAPANCHOR_H +#define SQUID_ICAPANCHOR_H + +#include "MsgPipeSource.h" +#include "MsgPipeSink.h" + +/* The ICAP Anchor implements message pipe sink and source interfaces. It + * helps HttpStateData to marshall the incoming/virgin HTTP message (being + * recieved from the HTTP server) to Squid's ICAP client module, using the + * MsgPipe interface. The same interface is used to get the adapted HTTP + * message back from the ICAP client. HttpStateData is the "owner" of the + * ICAPAnchor. + */ + +class HttpRequest; +class HttpReply; + +class ICAPAnchor: public MsgPipeSource, public MsgPipeSink { +public: + ICAPAnchor(); + virtual ~ICAPAnchor(); + + // synchronous calls called by HttpStateData + void startRespMod(HttpRequest *request, HttpReply *reply); + void sendMoreData(); + void ownerAbort(); + + // pipe source methods; called by ICAP while receiving the virgin message + virtual void noteSinkNeed(MsgPipe *p); + virtual void noteSinkAbort(MsgPipe *p); + + // pipe sink methods; called by ICAP while sending the adapted message + virtual void noteSourceStart(MsgPipe *p); + virtual void noteSourceProgress(MsgPipe *p); + virtual void noteSourceFinish(MsgPipe *p); + virtual void noteSourceAbort(MsgPipe *p); + +public: + pointer to HttpStateData + MsgPipe *virgin; + MsgPipe *adapted; + +private: + typedef enum { notifyNone, notifyOwner, notifyIcap } Notify; + void stop(Notify notify); +}; + +#endif /* SQUID_ICAPANCHOR_H */