netwerk/protocol/http/nsHttpConnectionInfo.h

Thu, 15 Jan 2015 21:03:48 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 15 Jan 2015 21:03:48 +0100
branch
TOR_BUG_9701
changeset 11
deefc01c0e14
permissions
-rw-r--r--

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.)

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

mercurial