1 2 /* Web Polygraph http://www.web-polygraph.org/ 3 * Copyright 2003-2011 The Measurement Factory 4 * Licensed under the Apache License, Version 2.0 */ 5 6 #ifndef POLYGRAPH__CSM_BODYITER_H 7 #define POLYGRAPH__CSM_BODYITER_H 8 9 #include "xstd/Rnd.h" 10 #include "base/ObjId.h" 11 12 class WrBuf; 13 class ContentCfg; 14 class HttpPrinter; 15 16 class BodyIter { 17 public: 18 BodyIter(); ~BodyIter()19 virtual ~BodyIter() {}; 20 virtual BodyIter *clone() const = 0; 21 contentCfg(const ContentCfg * cfg)22 void contentCfg(const ContentCfg *cfg) { theContentCfg = cfg; } oidCfg(const ObjId & anOid,int aHash)23 void oidCfg(const ObjId &anOid, int aHash) { theOid = anOid; theContentHash = aHash; } 24 void contentSize(Size aContentSize, Size aSuffixSize); 25 26 virtual void start(WrBuf *aBuf); stop()27 virtual void stop() {} 28 oid()29 const ObjId &oid() const { return theOid; } contentCfg()30 const ContentCfg *contentCfg() const { return theContentCfg; } contentHash()31 int contentHash() const { return theContentHash; } 32 Size contentSize() const; 33 virtual Size fullEntitySize() const; builtSize()34 Size builtSize() const { return theBuiltSize; } offSeed()35 Size offSeed() const { return theContentHash; } 36 37 bool canPour() const; // can add to buffer and buffer has space 38 bool pouredAll() const; // has someting to add to buffer 39 virtual bool pour(); // fills the buffer; false if unrecoverable error 40 virtual void putHeaders(HttpPrinter &hp) const; 41 42 operator void *() const { return pouredAll() ? 0 : (void*)-1; } 43 44 void putBack(); 45 46 protected: 47 /* pouring methods for "typical" body parts */ 48 void pourPrefix(); 49 virtual bool pourMiddle(); 50 void pourSuffix(); 51 52 // pours the requested number of random bytes (of an appropriate kind) 53 // returns whether anything was poured 54 bool pourRandom(const Size upToSize); 55 56 virtual void calcContentSize() const; 57 Size middleSizeLeft() const; 58 59 protected: 60 const ContentCfg *theContentCfg; 61 ObjId theOid; // XXX: replace with a pointer when ObjRec is removed 62 WrBuf *theBuf; 63 RndGen theRng; 64 mutable Size theContentSize; // including prefix and suffix, if any 65 mutable Size theSuffixSize; 66 int theContentHash; 67 68 Size theBuiltSize; // including prefix and suffix, if any 69 }; 70 71 #endif 72