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_CONTENTCFG_H 7 #define POLYGRAPH__CSM_CONTENTCFG_H 8 9 #include "xstd/String.h" 10 #include "xstd/Array.h" 11 #include "runtime/httpHdrs.h" 12 13 class ClientBehaviorSym; 14 class ObjId; 15 class RndDistr; 16 class RndBuf; 17 class BodyIter; 18 class ContentDbase; 19 class RamFiles; 20 class TextDbase; 21 class ContentSym; 22 class EmbedContMdl; 23 class ObjTimes; 24 class ObjLifeCycle; 25 class InjectIter; 26 class IOBuf; 27 class MimeHeadersCfg; 28 class RamFile; 29 30 class ContentCfg { 31 public: 32 typedef Array<String*> Strings; 33 34 public: 35 ContentCfg(int anId); 36 ~ContentCfg(); 37 38 void configure(const ContentSym &cfg); 39 id()40 int id() const { return theId; } kind()41 const String &kind() const { return theKind; } 42 const String &url_ext(int seed) const; 43 const String &url_pfx(int seed) const; 44 const String &url_qry(int seed) const; 45 double repSizeMean() const; hasEmbedCont()46 bool hasEmbedCont() const { return theEmbedCont != 0; } 47 bool multipleContentCodings() const; clientBehaviorSym()48 const ClientBehaviorSym *clientBehaviorSym() const { return theClientBehaviorSym; } 49 const RndBuf &rndBuf() const; 50 51 void calcTimes(const ObjId &oid, ObjTimes ×) const; 52 bool calcContentCoding(ObjId &oid, const ReqHdr &req) const; 53 Size calcRawRepSize(const ObjId &oid, Size *suffixSizePtr = 0) const; 54 Size calcFullEntitySize(const ObjId &oid); 55 bool calcCachability(const ObjId &oid) const; 56 bool calcChecksumNeed(const ObjId &oid) const; 57 xstd::Checksum calcChecksum(const ObjId &oid); 58 Size pourContentPrefix(const ObjId &oid, IOBuf &buf) const; 59 Size pourContentSuffix(const ObjId &oid, IOBuf &buf) const; 60 61 double compContPerCall(const ContentCfg *cc) const; 62 63 BodyIter *getBodyIter(const ObjId &oid, const RangeList *const ranges = 0); 64 void putBodyIter(BodyIter *i) const; 65 void putInjector(InjectIter *i) const; 66 67 Size calcContentPrefixSize(const ObjId &oid) const; 68 Size calcContentSuffixSize(const ObjId &oid) const; 69 mimeHeaders()70 const MimeHeadersCfg *mimeHeaders() const { return theMimeHeaders; } 71 ramFiles()72 const RamFiles *ramFiles() const { return theRamFiles; } 73 const RamFile &ramFile(const ObjId &oid) const; // requires ramFiles()! 74 75 protected: 76 void configureEncodings(const ContentSym &cfg); 77 void configureInjections(const ContentSym &cfg); 78 void configureRndGeneration(const ContentSym &cfg); 79 void configureMimeHeaders(const ContentSym &cfg); 80 81 int selectCdbStart(const ObjId &oid) const; 82 const String &pickStr(const Strings &strings, RndDistr *sel, int seed) const; 83 84 bool shouldInject(const ObjId &oid) const; 85 Size pourUniqueContentPrefix(const ObjId &oid, IOBuf &buf) const; 86 Size pourUri(const ObjId &oid, ostream &os) const; 87 int contentUniqueness(const ObjId &oid) const; 88 int contentHash(const ObjId &oid) const; 89 90 public: 91 String theKind; 92 String theMimeType; 93 ObjLifeCycle *theObjLifeCycle; 94 double theChbRatio; 95 double theChecksumRatio; 96 double theUniqueRatio; 97 98 protected: 99 RndDistr *theSize; // null if must use cdb entry sizes 100 EmbedContMdl *theEmbedCont; 101 ContentDbase *theCdb; 102 RamFiles *theRamFiles; 103 104 int theInjectionAlgorithm; 105 TextDbase *theTdb; 106 RndDistr *theInjGap; // distance between injections 107 double theInfProb; // portion of infected files 108 109 Strings theExtensions; // file extensions 110 mutable RndDistr *theExtSel; // selector for the above 111 112 Strings thePrefixes; // URL path prefixes 113 mutable RndDistr *thePfxSel; // selector for the above 114 115 Strings theQueries; // URL query strings 116 mutable RndDistr *theQrySel; // selector for the above 117 118 const int theId; 119 String theCommonPrefix; 120 121 int *theEncodings; // content-encodings 122 MimeHeadersCfg *theMimeHeaders; // user-configured MIME headers 123 124 const ClientBehaviorSym *theClientBehaviorSym; // client behavior sym 125 126 bool generateText; // whether to fill random bodies with "ASCII" text 127 128 enum ContentUniqueness { cuChance = 0, cuUnique, cuCommon }; 129 }; 130 131 extern int TheForeignContentId; 132 extern int TheBodilessContentId; 133 extern int TheUnknownContentId; 134 135 #endif 136