Attachment 'squid-ecap-gzip_up_to_libecap-1.0.0.patch'

Download

   1 diff -u -r ./squid-ecap-gzip.orig/src/adapter_gzip.cc ./squid-ecap-gzip/src/adapter_gzip.cc
   2 --- ./squid-ecap-gzip.orig/src/adapter_gzip.cc	2011-02-13 17:42:20.000000000 +0300
   3 +++ ./squid-ecap-gzip/src/adapter_gzip.cc	2014-01-24 17:05:46.510557141 +0400
   4 @@ -38,9 +38,9 @@
   5  #include <string.h>
   6  #include <stdlib.h>
   7  #include <iostream>
   8 -#include <libecap/common/message.h>
   9  #include <libecap/common/registry.h>
  10  #include <libecap/common/errors.h>
  11 +#include <libecap/common/message.h>
  12  #include <libecap/common/header.h>
  13  #include <libecap/common/names.h>
  14  #include <libecap/adapter/service.h>
  15 @@ -50,11 +50,9 @@
  16  
  17  namespace Adapter { // not required, but adds clarity
  18  	
  19 -	using libecap::size_type;
  20 -	using libecap::StatusLine;
  21 -	
  22 -	class Service: public libecap::adapter::Service {
  23 +using libecap::size_type;
  24  		
  25 +class Service: public libecap::adapter::Service {
  26  	public:
  27  		// About
  28  		virtual std::string uri() const; // unique across all vendors
  29 @@ -62,8 +60,8 @@
  30  		virtual void describe(std::ostream &os) const; // free-format info
  31  		
  32  		// Configuration
  33 -		virtual void configure(const Config &cfg);
  34 -		virtual void reconfigure(const Config &cfg);
  35 +		virtual void configure(const libecap::Options &cfg);
  36 +		virtual void reconfigure(const libecap::Options &cfg);
  37  		
  38  		// Lifecycle
  39  		virtual void start(); // expect makeXaction() calls
  40 @@ -74,15 +72,20 @@
  41  		virtual bool wantsUrl(const char *url) const;
  42  		
  43  		// Work
  44 -		virtual libecap::adapter::Xaction *makeXaction(libecap::host::Xaction *hostx);
  45 -	};
  46 +		virtual Adapter::Service::MadeXactionPointer makeXaction(libecap::host::Xaction *hostx);
  47  	
  48 +};
  49  	
  50 -	class Xaction: public libecap::adapter::Xaction {
  51 +
  52 +class Xaction: public libecap::adapter::Xaction {
  53  	public:
  54 -		Xaction(libecap::host::Xaction *x);
  55 +		Xaction(libecap::shared_ptr<Service> s, libecap::host::Xaction *x);
  56  		virtual ~Xaction();
  57  		
  58 +		// meta-information for the host transaction
  59 +		virtual const libecap::Area option(const libecap::Name &name) const;
  60 +		virtual void visitEachOption(libecap::NamedValueVisitor &visitor) const;
  61 +
  62  		// lifecycle
  63  		virtual void start();
  64  		virtual void stop();
  65 @@ -101,13 +104,12 @@
  66          virtual void noteVbContentDone(bool atEnd);
  67          virtual void noteVbContentAvailable();
  68  		
  69 -		// libecap::Callable API, via libecap::host::Xaction
  70 -		virtual bool callable() const;
  71 -		
  72  	protected:
  73 +		void stopVb(); // stops receiving vb (if we are receiving it)
  74  		libecap::host::Xaction *lastHostCall(); // clears hostx
  75  		
  76  	private:
  77 +		libecap::shared_ptr<const Service> service; // configuration access
  78  		libecap::host::Xaction *hostx; // Host transaction rep
  79  		
  80  		typedef enum { opUndecided, opOn, opComplete, opNever } OperationState;
  81 @@ -137,7 +139,10 @@
  82  		} requirements;
  83  		
  84  		bool requirementsAreMet();
  85 -	};
  86 +};
  87 +
  88 +static const std::string CfgErrorPrefix =
  89 +	"Modifying Adapter: configuration error: ";
  90  	
  91  } // namespace Adapter
  92  
  93 @@ -169,7 +174,6 @@
  94  	return true;
  95  }
  96  
  97 -
  98  /**
  99   * Initializes the zlib data structures.
 100   */
 101 @@ -217,9 +221,7 @@
 102  	}
 103  }
 104  
 105 -/**
 106 - * Returns the URI of the VIGOS gzip eCAP service.
 107 - */
 108 +
 109  std::string Adapter::Service::uri() const {
 110  	return "ecap://www.vigos.com/ecap_gzip";
 111  }
 112 @@ -232,16 +234,16 @@
 113  	os << "HTTP GZIP compression eCAP adapter";
 114  }
 115  
 116 -void Adapter::Service::configure(const Config &) {
 117 +void Adapter::Service::configure(const libecap::Options &cfg) {
 118  	// this service is not configurable
 119  }
 120  
 121 -void Adapter::Service::reconfigure(const Config &) {
 122 +void Adapter::Service::reconfigure(const libecap::Options &cfg) {
 123  	// this service is not configurable
 124  }
 125  
 126  void Adapter::Service::start() {
 127 -	// libecap::adapter::Service::start();
 128 +	//libecap::adapter::Service::start();
 129  	// custom code would go here, but this service does not have one
 130  }
 131  
 132 @@ -259,13 +261,17 @@
 133  	return true; // no-op is applied to all messages
 134  }
 135  
 136 -libecap::adapter::Xaction *Adapter::Service::makeXaction(libecap::host::Xaction *hostx) {
 137 -	return new Adapter::Xaction(hostx);
 138 +Adapter::Service::MadeXactionPointer Adapter::Service::makeXaction(libecap::host::Xaction *hostx) {
 139 +	return Service::MadeXactionPointer(new Adapter::Xaction(std::tr1::static_pointer_cast<Service>(self),
 140 +		hostx));
 141  }
 142  
 143  
 144 -Adapter::Xaction::Xaction(libecap::host::Xaction *x): hostx(x),
 145 -receivingVb(opUndecided), sendingAb(opUndecided) {
 146 +Adapter::Xaction::Xaction(libecap::shared_ptr<Service> aService,
 147 +	libecap::host::Xaction *x):
 148 +	service(aService),
 149 +	hostx(x),
 150 +	receivingVb(opUndecided), sendingAb(opUndecided) {
 151  }
 152  
 153  Adapter::Xaction::~Xaction() {
 154 @@ -275,17 +281,30 @@
 155  	}
 156  }
 157  
 158 +const libecap::Area Adapter::Xaction::option(const libecap::Name &) const {
 159 +	return libecap::Area(); // this transaction has no meta-information
 160 +}
 161 +
 162 +void Adapter::Xaction::visitEachOption(libecap::NamedValueVisitor &) const {
 163 +	// this transaction has no meta-information to pass to the visitor
 164 +}
 165 +
 166  void Adapter::Xaction::start() {
 167 +
 168  	gzipContext = 0;
 169  
 170  	Must(hostx);
 171 +
 172  	if (hostx->virgin().body()) {
 173  		receivingVb = opOn;
 174  		hostx->vbMake(); // ask host to supply virgin body
 175  	} else {
 176 +		// we are not interested in vb if there is not one
 177  		receivingVb = opNever;
 178  	}
 179  	
 180 +	/* adapt message header */
 181 +
 182  	libecap::shared_ptr<libecap::Message> adapted = hostx->virgin().clone();
 183      Must(adapted != 0);
 184  
 185 @@ -313,7 +332,6 @@
 186  		}
 187  	}
 188  	
 189 -	
 190  	/**
 191  	 * Checks if the response Cache-Control header allows transformation of the response.
 192  	 */
 193 @@ -334,7 +352,6 @@
 194  		}
 195  	}
 196  
 197 -
 198  	/**
 199  	 * Do not compress if response has a content-range header and status code "206 Partial content". 
 200  	 */
 201 @@ -369,7 +386,6 @@
 202  		}
 203  	}
 204  
 205 -
 206  	/**
 207  	 * Checks the Content-Encoding response header.
 208  	 * If this header is present, we must not compress the respone.
 209 @@ -384,16 +400,16 @@
 210  		this->requirements.responseContentTypeOk = false;
 211  	}
 212  
 213 -	
 214  	// delete ContentLength header because we may change the length
 215  	// unknown length may have performance implications for the host
 216  	adapted->header().removeAny(libecap::headerContentLength);
 217  
 218 -	// Add informational response header	
 219 +	// add a custom header
 220  	static const libecap::Name name("X-Ecap");
 221  	const libecap::Header::Value value = libecap::Area::FromTempString("VIGOS eCAP GZIP Adapter");
 222  	adapted->header().add(name, value);
 223  	
 224 +
 225  	// Add "Vary: Accept-Encoding" response header if Content-Type is "text/html"
 226  	if(requirements.responseContentTypeOk) {
 227  		static const libecap::Name varyName("Vary");
 228 @@ -442,8 +458,9 @@
 229  void Adapter::Xaction::abDiscard()
 230  {
 231  	Must(sendingAb == opUndecided); // have not started yet
 232 -	
 233  	sendingAb = opNever;
 234 +	// we do not need more vb if the host is not interested in ab
 235 +	stopVb();
 236  }
 237  
 238  void Adapter::Xaction::abMake()
 239 @@ -467,13 +484,12 @@
 240  void Adapter::Xaction::abStopMaking()
 241  {
 242  	sendingAb = opComplete;
 243 -	// we may still continue receiving
 244 +	// we do not need more vb if the host is not interested in more ab
 245 +	stopVb();
 246  }
 247  
 248  
 249 -libecap::Area Adapter::Xaction::abContent(size_type offset, size_type size)
 250 -{
 251 -	// required to not raise an exception on the final call with opComplete
 252 +libecap::Area Adapter::Xaction::abContent(size_type offset, size_type size) {
 253  	Must(sendingAb == opOn || sendingAb == opComplete);
 254  
 255  	// if complete, there is nothing more to return.
 256 @@ -487,17 +503,15 @@
 257  	return libecap::Area::FromTempBuffer((const char*)&gzipContext->gzipBuffer[offset], size);
 258  }
 259  
 260 -
 261 -void Adapter::Xaction::abContentShift(size_type size)
 262 -{
 263 -	Must(sendingAb == opOn);
 264 +void Adapter::Xaction::abContentShift(size_type size) {
 265 +	Must(sendingAb == opOn || sendingAb == opComplete);
 266  	gzipContext->sendingOffset += size;
 267  	hostx->vbContentShift(gzipContext->lastChunkSize);
 268  }
 269  
 270 -
 271  void Adapter::Xaction::noteVbContentDone(bool atEnd)
 272  {
 273 +
 274  	Must(gzipContext);
 275  	
 276  	gzipContext->zstream.total_out = 0;
 277 @@ -530,9 +544,9 @@
 278  	gzipContext->originalSize >>= 8;
 279  	gzipContext->gzipBuffer[gzipContext->compressedSize++] = (char) gzipContext->originalSize & 0xff;
 280  	
 281 +
 282  	Must(receivingVb == opOn);
 283  	receivingVb = opComplete;
 284 -	
 285  	if (sendingAb == opOn) {
 286  		hostx->noteAbContentDone(atEnd);
 287  		sendingAb = opComplete;
 288 @@ -546,8 +560,7 @@
 289  	Must(receivingVb == opOn);
 290  	Must(gzipContext);
 291  
 292 -	// get all virgin body
 293 -	const libecap::Area vb = hostx->vbContent(0, libecap::nsize);
 294 +        const libecap::Area vb = hostx->vbContent(0, libecap::nsize); // get all vb
 295  	
 296  	// calculate original byte size for GZIP footer
 297  	gzipContext->originalSize += vb.size;
 298 @@ -588,15 +601,20 @@
 299  	
 300  	gzipContext->compressedSize += gzipContext->zstream.total_out;
 301  	
 302 -	if(sendingAb == opOn)
 303 -	{
 304 +	if (sendingAb == opOn)
 305  		hostx->noteAbContentAvailable();
 306 -	}
 307  }
 308  
 309 -
 310 -bool Adapter::Xaction::callable() const {
 311 -    return hostx != 0; // no point to call us if we are done
 312 +// tells the host that we are not interested in [more] vb
 313 +// if the host does not know that already
 314 +void Adapter::Xaction::stopVb() {
 315 +	if (receivingVb == opOn) {
 316 +		hostx->vbStopMaking();
 317 +		receivingVb = opComplete;
 318 +	} else {
 319 +		// we already got the entire body or refused it earlier
 320 +		Must(receivingVb != opUndecided);
 321 +	}
 322  }
 323  
 324  // this method is used to make the last call to hostx transaction
 325 @@ -610,6 +628,6 @@
 326  }
 327  
 328  // create the adapter and register with libecap to reach the host application
 329 -static const bool Registered = (libecap::RegisterService(new Adapter::Service), true);
 330 +static const bool Registered = (libecap::RegisterVersionedService(new Adapter::Service));
 331  
 332  

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2016-06-08 18:00:06, 1.4 KB) [[attachment:gzip_ecap_extended_compressible_types.patch]]
  • [get | view] (2016-06-11 20:37:49, 1.6 KB) [[attachment:gzip_ecap_extended_compressible_types_latest.patch]]
  • [get | view] (2016-06-08 21:13:39, 1.4 KB) [[attachment:gzip_ecap_extended_compressible_types_v1.patch]]
  • [get | view] (2016-06-09 12:19:51, 1.6 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_2.patch]]
  • [get | view] (2016-06-11 20:31:49, 1.6 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_2.patch.latest]]
  • [get | view] (2016-06-12 14:51:20, 1.9 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_3.patch]]
  • [get | view] (2016-06-20 20:35:35, 1.2 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_4.patch]]
  • [get | view] (2016-06-20 20:50:23, 2.1 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_5.patch]]
  • [get | view] (2016-06-20 21:26:21, 1.8 KB) [[attachment:gzip_ecap_extended_compressible_types_v1_6.patch]]
  • [get | view] (2016-06-18 16:44:11, 0.8 KB) [[attachment:gzip_ecap_vb_stop_on_done_v1.patch]]
  • [get | view] (2016-06-08 17:56:50, 1.4 KB) [[attachment:gzip_exap_extended_compressible_types.patch]]
  • [get | view] (2015-03-29 19:40:02, 1.5 KB) [[attachment:squid-ecap-gzip_all_text_compressed.patch]]
  • [get | view] (2015-03-29 19:35:49, 8.5 KB) [[attachment:squid-ecap-gzip_up_to_libecap-0.2.0.patch]]
  • [get | view] (2015-03-29 19:35:56, 9.2 KB) [[attachment:squid-ecap-gzip_up_to_libecap-1.0.0.patch]]
 All files | Selected Files: delete move to page copy to page

You are not allowed to attach a file to this page.