Thu, 15 Jan 2015 21:03:48 +0100
Integrate friendly tips from Tor colleagues to make (or not) 4.5 alpha 3;
This includes removal of overloaded (but unused) methods, and addition of
a overlooked call to DataStruct::SetData(nsISupports, uint32_t, bool.)
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
michael@0 | 2 | /* vim: set sw=4 ts=8 et tw=80 : */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | #ifndef nsHttpConnectionInfo_h__ |
michael@0 | 8 | #define nsHttpConnectionInfo_h__ |
michael@0 | 9 | |
michael@0 | 10 | #include "nsHttp.h" |
michael@0 | 11 | #include "nsProxyInfo.h" |
michael@0 | 12 | #include "nsCOMPtr.h" |
michael@0 | 13 | #include "nsStringFwd.h" |
michael@0 | 14 | |
michael@0 | 15 | extern PRLogModuleInfo *gHttpLog; |
michael@0 | 16 | |
michael@0 | 17 | //----------------------------------------------------------------------------- |
michael@0 | 18 | // nsHttpConnectionInfo - holds the properties of a connection |
michael@0 | 19 | //----------------------------------------------------------------------------- |
michael@0 | 20 | |
michael@0 | 21 | namespace mozilla { namespace net { |
michael@0 | 22 | |
michael@0 | 23 | class nsHttpConnectionInfo |
michael@0 | 24 | { |
michael@0 | 25 | public: |
michael@0 | 26 | nsHttpConnectionInfo(const nsACString &host, int32_t port, |
michael@0 | 27 | const nsACString &username, |
michael@0 | 28 | nsProxyInfo* proxyInfo, |
michael@0 | 29 | bool usingSSL=false); |
michael@0 | 30 | |
michael@0 | 31 | virtual ~nsHttpConnectionInfo() |
michael@0 | 32 | { |
michael@0 | 33 | PR_LOG(gHttpLog, 4, ("Destroying nsHttpConnectionInfo @%x\n", this)); |
michael@0 | 34 | } |
michael@0 | 35 | |
michael@0 | 36 | const nsAFlatCString &HashKey() const { return mHashKey; } |
michael@0 | 37 | |
michael@0 | 38 | void SetOriginServer(const nsACString &host, int32_t port); |
michael@0 | 39 | |
michael@0 | 40 | void SetOriginServer(const char *host, int32_t port) |
michael@0 | 41 | { |
michael@0 | 42 | SetOriginServer(nsDependentCString(host), port); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | // OK to treat this as an infalible allocation |
michael@0 | 46 | nsHttpConnectionInfo* Clone() const; |
michael@0 | 47 | |
michael@0 | 48 | const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nullptr; } |
michael@0 | 49 | int32_t ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; } |
michael@0 | 50 | const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nullptr; } |
michael@0 | 51 | |
michael@0 | 52 | // Compare this connection info to another... |
michael@0 | 53 | // Two connections are 'equal' if they end up talking the same |
michael@0 | 54 | // protocol to the same server. This is needed to properly manage |
michael@0 | 55 | // persistent connections to proxies |
michael@0 | 56 | // Note that we don't care about transparent proxies - |
michael@0 | 57 | // it doesn't matter if we're talking via socks or not, since |
michael@0 | 58 | // a request will end up at the same host. |
michael@0 | 59 | bool Equals(const nsHttpConnectionInfo *info) |
michael@0 | 60 | { |
michael@0 | 61 | return mHashKey.Equals(info->HashKey()); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | const char *Host() const { return mHost.get(); } |
michael@0 | 65 | int32_t Port() const { return mPort; } |
michael@0 | 66 | const char *Username() const { return mUsername.get(); } |
michael@0 | 67 | nsProxyInfo *ProxyInfo() { return mProxyInfo; } |
michael@0 | 68 | bool UsingHttpProxy() const { return mUsingHttpProxy; } |
michael@0 | 69 | bool UsingSSL() const { return mUsingSSL; } |
michael@0 | 70 | bool UsingConnect() const { return mUsingConnect; } |
michael@0 | 71 | int32_t DefaultPort() const { return mUsingSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; } |
michael@0 | 72 | void SetAnonymous(bool anon) |
michael@0 | 73 | { mHashKey.SetCharAt(anon ? 'A' : '.', 2); } |
michael@0 | 74 | bool GetAnonymous() const { return mHashKey.CharAt(2) == 'A'; } |
michael@0 | 75 | void SetPrivate(bool priv) { mHashKey.SetCharAt(priv ? 'P' : '.', 3); } |
michael@0 | 76 | bool GetPrivate() const { return mHashKey.CharAt(3) == 'P'; } |
michael@0 | 77 | |
michael@0 | 78 | const nsCString &GetHost() { return mHost; } |
michael@0 | 79 | |
michael@0 | 80 | // Returns true for any kind of proxy (http, socks, etc..) |
michael@0 | 81 | bool UsingProxy(); |
michael@0 | 82 | |
michael@0 | 83 | // Returns true when mHost is an RFC1918 literal. |
michael@0 | 84 | bool HostIsLocalIPLiteral() const; |
michael@0 | 85 | |
michael@0 | 86 | private: |
michael@0 | 87 | nsCString mHashKey; |
michael@0 | 88 | nsCString mHost; |
michael@0 | 89 | int32_t mPort; |
michael@0 | 90 | nsCString mUsername; |
michael@0 | 91 | nsCOMPtr<nsProxyInfo> mProxyInfo; |
michael@0 | 92 | bool mUsingHttpProxy; |
michael@0 | 93 | bool mUsingSSL; |
michael@0 | 94 | bool mUsingConnect; // if will use CONNECT with http proxy |
michael@0 | 95 | |
michael@0 | 96 | // for nsRefPtr |
michael@0 | 97 | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(nsHttpConnectionInfo) |
michael@0 | 98 | }; |
michael@0 | 99 | |
michael@0 | 100 | }} // namespace mozilla::net |
michael@0 | 101 | |
michael@0 | 102 | #endif // nsHttpConnectionInfo_h__ |