00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00032
00033 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DOMAIN_LAWYER_H_
00034 #define NET_INSTAWEB_REWRITER_PUBLIC_DOMAIN_LAWYER_H_
00035
00036 #include <map>
00037 #include <vector>
00038
00039 #include "net/instaweb/util/public/basictypes.h"
00040 #include "net/instaweb/util/public/string.h"
00041 #include "net/instaweb/util/public/string_util.h"
00042
00043 namespace net_instaweb {
00044 class GoogleUrl;
00045 class MessageHandler;
00046
00047 class DomainLawyer {
00048 public:
00049 DomainLawyer() : can_rewrite_domains_(false) {}
00050 ~DomainLawyer();
00051
00080 bool MapRequestToDomain(const GoogleUrl& original_request,
00081 const StringPiece& resource_url,
00082 GoogleString* mapped_domain_name,
00083 GoogleUrl* resolved_request,
00084 MessageHandler* handler) const;
00085
00093 bool IsDomainAuthorized(const GoogleUrl& original_request,
00094 const GoogleUrl& domain_to_check) const;
00095
00100 bool MapOrigin(const StringPiece& in, GoogleString* out) const;
00101 bool MapOriginUrl(const GoogleUrl& gurl, GoogleString* out) const;
00102
00105
00111 bool AddDomain(const StringPiece& domain_name, MessageHandler* handler);
00112
00123 bool AddRewriteDomainMapping(const StringPiece& to_domain,
00124 const StringPiece& comma_separated_from_domains,
00125 MessageHandler* handler);
00126
00135 bool AddOriginDomainMapping(const StringPiece& to_domain,
00136 const StringPiece& comma_separated_from_domains,
00137 MessageHandler* handler);
00138
00144 bool AddTwoProtocolOriginDomainMapping(const StringPiece& to_domain_name,
00145 const StringPiece& from_domain_name,
00146 MessageHandler* handler);
00147
00151 bool AddShard(const StringPiece& to_domain,
00152 const StringPiece& comma_separated_shards,
00153 MessageHandler* handler);
00154
00164 bool ShardDomain(const StringPiece& domain_name, uint32 hash,
00165 GoogleString* sharded_domain) const;
00166
00171 void Merge(const DomainLawyer& src);
00172
00176 bool WillDomainChange(const StringPiece& domain_name) const;
00177
00180 bool can_rewrite_domains() const { return can_rewrite_domains_; }
00181
00183 int num_wildcarded_domains() const { return wildcarded_domains_.size(); }
00184
00187 bool DoDomainsServeSameContent(const StringPiece& domain1,
00188 const StringPiece& domain2) const;
00189
00192 GoogleString Signature() const;
00193
00199 GoogleString ToString(StringPiece line_prefix) const;
00200
00202 GoogleString ToString() const { return ToString(StringPiece()); }
00203
00204 private:
00205 class Domain;
00206
00207 typedef bool (Domain::*SetDomainFn)(Domain* domain, MessageHandler* handler);
00208
00209 static GoogleString NormalizeDomainName(const StringPiece& domain_name);
00210
00211 static bool IsSchemeSafeToMapTo(const StringPiece& domain_name,
00212 bool allow_https_scheme);
00213
00214 bool MapDomainHelper(
00215 const StringPiece& to_domain_name,
00216 const StringPiece& comma_separated_from_domains,
00217 SetDomainFn set_domain_fn,
00218 bool allow_wildcards,
00219 bool allow_map_to_https,
00220 bool authorize,
00221 MessageHandler* handler);
00222
00223 Domain* AddDomainHelper(const StringPiece& domain_name,
00224 bool warn_on_duplicate,
00225 bool authorize,
00226 MessageHandler* handler);
00227 Domain* CloneAndAdd(const Domain* src);
00228
00229 Domain* FindDomain(const GoogleUrl& gurl) const;
00230
00233 typedef std::map<GoogleString, Domain*> DomainMap;
00234 DomainMap domain_map_;
00235 typedef std::vector<Domain*> DomainVector;
00236 DomainVector wildcarded_domains_;
00237 bool can_rewrite_domains_;
00239
00240 DISALLOW_COPY_AND_ASSIGN(DomainLawyer);
00241 };
00242
00243 }
00244
00245 #endif ///< NET_INSTAWEB_REWRITER_PUBLIC_DOMAIN_LAWYER_H_