33 #ifndef NET_INSTAWEB_REWRITER_PUBLIC_DOMAIN_LAWYER_H_
34 #define NET_INSTAWEB_REWRITER_PUBLIC_DOMAIN_LAWYER_H_
39 #include "pagespeed/kernel/base/basictypes.h"
40 #include "pagespeed/kernel/base/string.h"
41 #include "pagespeed/kernel/base/string_util.h"
43 namespace net_instaweb {
94 const StringPiece& resource_url,
95 GoogleString* mapped_domain_name,
96 GoogleUrl* resolved_request,
97 MessageHandler* handler)
const;
107 const GoogleUrl& domain_to_check)
const;
133 bool MapOrigin(
const StringPiece& in, GoogleString* out,
134 GoogleString* host_header,
bool* is_proxy)
const;
135 bool MapOriginUrl(
const GoogleUrl& gurl, GoogleString* out,
136 GoogleString* host_header,
bool* is_proxy)
const;
146 bool AddDomain(
const StringPiece& domain_name, MessageHandler* handler);
150 bool AddKnownDomain(
const StringPiece& domain_name, MessageHandler* handler);
163 const StringPiece& comma_separated_from_domains,
164 MessageHandler* handler);
172 const StringPiece& from_domain_name,
173 MessageHandler* handler);
195 const StringPiece& comma_separated_from_domains,
196 const StringPiece& host_header,
197 MessageHandler* handler);
224 const StringPiece& origin_domain,
225 const StringPiece& to_domain_name,
226 MessageHandler* handler);
235 const StringPiece& from_domain_name,
236 const StringPiece& host_header,
237 MessageHandler* handler);
242 bool AddShard(
const StringPiece& to_domain,
243 const StringPiece& comma_separated_shards,
244 MessageHandler* handler);
255 bool ShardDomain(
const StringPiece& domain_name, uint32 hash,
256 GoogleString* sharded_domain)
const;
265 bool empty()
const {
return domain_map_.empty() && proxy_suffix_.empty(); }
283 return can_rewrite_domains_ || !proxy_suffix_.empty();
292 const StringPiece& domain2)
const;
297 const GoogleUrl& domain_name,
298 ConstStringStarVector* from_domains)
const;
323 const GoogleString& proxy_suffix()
const {
return proxy_suffix_; }
330 GoogleString* url, GoogleString* host)
const;
334 bool AddProxySuffix(
const GoogleUrl& base_url, GoogleString* href)
const;
345 GoogleString
ToString(StringPiece line_prefix)
const;
352 friend class DomainLawyerTest;
354 typedef bool (Domain::*SetDomainFn)(Domain* domain, MessageHandler* handler);
356 static GoogleString NormalizeDomainName(
const StringPiece& domain_name);
358 static bool IsSchemeSafeToMapTo(
const StringPiece& domain_name,
359 bool allow_https_scheme);
361 bool MapDomainHelper(
362 const StringPiece& to_domain_name,
363 const StringPiece& comma_separated_from_domains,
364 const StringPiece& host_header,
365 SetDomainFn set_domain_fn,
366 bool allow_wildcards,
367 bool allow_map_to_https,
369 MessageHandler* handler);
371 bool MapUrlHelper(
const Domain& from_domain,
372 const Domain& to_domain,
373 const GoogleUrl& gurl,
374 GoogleUrl* mapped_gurl)
const;
376 bool DomainNameToTwoProtocols(
const StringPiece& domain_name,
377 GoogleString* http_url,
378 GoogleString* https_url);
380 bool TwoProtocolDomainHelper(
381 const StringPiece& to_domain_name,
382 const StringPiece& from_domain_name,
383 const StringPiece& host_header,
384 SetDomainFn set_domain_fn,
386 MessageHandler* handler);
388 Domain* AddDomainHelper(
const StringPiece& domain_name,
389 bool warn_on_duplicate,
392 MessageHandler* handler);
393 Domain* CloneAndAdd(
const Domain* src);
395 Domain* FindDomain(
const GoogleUrl& gurl)
const;
399 typedef std::map<GoogleString, Domain*> DomainMap;
400 DomainMap domain_map_;
401 typedef std::vector<Domain*> DomainVector;
402 DomainVector wildcarded_domains_;
403 GoogleString proxy_suffix_;
404 bool can_rewrite_domains_;
407 bool authorize_all_domains_;
bool AddShard(const StringPiece &to_domain, const StringPiece &comma_separated_shards, MessageHandler *handler)
GoogleString Signature() const
bool AddProxyDomainMapping(const StringPiece &proxy_domain, const StringPiece &origin_domain, const StringPiece &to_domain_name, MessageHandler *handler)
bool can_rewrite_domains() const
Definition: domain_lawyer.h:282
bool AddProxySuffix(const GoogleUrl &base_url, GoogleString *href) const
bool MapOrigin(const StringPiece &in, GoogleString *out, GoogleString *host_header, bool *is_proxy) const
bool StripProxySuffix(const GoogleUrl &gurl, GoogleString *url, GoogleString *host) const
int num_wildcarded_domains() const
Visible for testing.
Definition: domain_lawyer.h:287
bool AddRewriteDomainMapping(const StringPiece &to_domain, const StringPiece &comma_separated_from_domains, MessageHandler *handler)
bool WillDomainChange(const GoogleUrl &url) const
bool AddDomain(const StringPiece &domain_name, MessageHandler *handler)
bool IsProxyMapped(const GoogleUrl &url) const
Determines whether a URL's domain was proxy-mapped from a different origin.
void Merge(const DomainLawyer &src)
GoogleString ToString() const
Version that's easier to call from debugger.
Definition: domain_lawyer.h:348
bool IsOriginKnown(const GoogleUrl &domain_to_check) const
bool ShardDomain(const StringPiece &domain_name, uint32 hash, GoogleString *sharded_domain) const
void set_proxy_suffix(const GoogleString &suffix)
Definition: domain_lawyer.h:322
bool AddOriginDomainMapping(const StringPiece &to_domain, const StringPiece &comma_separated_from_domains, const StringPiece &host_header, MessageHandler *handler)
bool AddTwoProtocolOriginDomainMapping(const StringPiece &to_domain_name, const StringPiece &from_domain_name, const StringPiece &host_header, MessageHandler *handler)
void FindDomainsRewrittenTo(const GoogleUrl &domain_name, ConstStringStarVector *from_domains) const
Definition: domain_lawyer.h:47
bool MapRequestToDomain(const GoogleUrl &original_request, const StringPiece &resource_url, GoogleString *mapped_domain_name, GoogleUrl *resolved_request, MessageHandler *handler) const
bool IsDomainAuthorized(const GoogleUrl &original_request, const GoogleUrl &domain_to_check) const
bool AddTwoProtocolRewriteDomainMapping(const StringPiece &to_domain_name, const StringPiece &from_domain_name, MessageHandler *handler)
bool DoDomainsServeSameContent(const StringPiece &domain1, const StringPiece &domain2) const
bool AddKnownDomain(const StringPiece &domain_name, MessageHandler *handler)