LCOV - code coverage report
Current view: directory - netwerk/protocol/http - nsHttpConnectionInfo.h (source / functions) Found Hit Coverage
Test: app.info Lines: 34 33 97.1 %
Date: 2012-06-02 Functions: 17 16 94.1 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is Mozilla.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 2001
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Darin Fisher <darin@netscape.com> (original author)
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      27                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : 
      39                 : #ifndef nsHttpConnectionInfo_h__
      40                 : #define nsHttpConnectionInfo_h__
      41                 : 
      42                 : #include "nsHttp.h"
      43                 : #include "nsProxyInfo.h"
      44                 : #include "nsCOMPtr.h"
      45                 : #include "nsDependentString.h"
      46                 : #include "nsString.h"
      47                 : #include "plstr.h"
      48                 : #include "nsCRT.h"
      49                 : 
      50                 : //-----------------------------------------------------------------------------
      51                 : // nsHttpConnectionInfo - holds the properties of a connection
      52                 : //-----------------------------------------------------------------------------
      53                 : 
      54                 : class nsHttpConnectionInfo
      55                 : {
      56                 : public:
      57            3805 :     nsHttpConnectionInfo(const nsACString &host, PRInt32 port,
      58                 :                          nsProxyInfo* proxyInfo,
      59                 :                          bool usingSSL=false)
      60                 :         : mRef(0)
      61                 :         , mProxyInfo(proxyInfo)
      62            3805 :         , mUsingSSL(usingSSL)
      63                 :     {
      64            3805 :         LOG(("Creating nsHttpConnectionInfo @%x\n", this));
      65                 : 
      66            3805 :         mUsingHttpProxy = (proxyInfo && !nsCRT::strcmp(proxyInfo->Type(), "http"));
      67                 : 
      68            3805 :         SetOriginServer(host, port);
      69            3805 :     }
      70                 :     
      71            3531 :    ~nsHttpConnectionInfo()
      72            3531 :     {
      73            3531 :         LOG(("Destroying nsHttpConnectionInfo @%x\n", this));
      74            3531 :     }
      75                 : 
      76           12746 :     nsrefcnt AddRef()
      77                 :     {
      78           12746 :         nsrefcnt n = NS_AtomicIncrementRefcnt(mRef);
      79           12746 :         NS_LOG_ADDREF(this, n, "nsHttpConnectionInfo", sizeof(*this));
      80           12746 :         return n;
      81                 :     }
      82                 : 
      83           12460 :     nsrefcnt Release()
      84                 :     {
      85           12460 :         nsrefcnt n = NS_AtomicDecrementRefcnt(mRef);
      86           12460 :         NS_LOG_RELEASE(this, n, "nsHttpConnectionInfo");
      87           12460 :         if (n == 0)
      88            3531 :             delete this;
      89           12460 :         return n;
      90                 :     }
      91                 : 
      92           12348 :     const nsAFlatCString &HashKey() const { return mHashKey; }
      93                 : 
      94                 :     void SetOriginServer(const nsACString &host, PRInt32 port);
      95                 : 
      96                 :     void SetOriginServer(const char *host, PRInt32 port)
      97                 :     {
      98                 :         SetOriginServer(nsDependentCString(host), port);
      99                 :     }
     100                 :     
     101                 :     nsHttpConnectionInfo* Clone() const;
     102                 : 
     103            3805 :     const char *ProxyHost() const { return mProxyInfo ? mProxyInfo->Host().get() : nsnull; }
     104              20 :     PRInt32     ProxyPort() const { return mProxyInfo ? mProxyInfo->Port() : -1; }
     105            3489 :     const char *ProxyType() const { return mProxyInfo ? mProxyInfo->Type() : nsnull; }
     106                 : 
     107                 :     // Compare this connection info to another...
     108                 :     // Two connections are 'equal' if they end up talking the same
     109                 :     // protocol to the same server. This is needed to properly manage
     110                 :     // persistent connections to proxies
     111                 :     // Note that we don't care about transparent proxies - 
     112                 :     // it doesn't matter if we're talking via socks or not, since
     113                 :     // a request will end up at the same host.
     114                 :     bool Equals(const nsHttpConnectionInfo *info)
     115                 :     {
     116                 :         return mHashKey.Equals(info->HashKey());
     117                 :     }
     118                 : 
     119           11817 :     const char   *Host() const           { return mHost.get(); }
     120            6767 :     PRInt32       Port() const           { return mPort; }
     121            6916 :     nsProxyInfo  *ProxyInfo()            { return mProxyInfo; }
     122           12980 :     bool          UsingHttpProxy() const { return mUsingHttpProxy; }
     123           27988 :     bool          UsingSSL() const       { return mUsingSSL; }
     124             377 :     PRInt32       DefaultPort() const    { return mUsingSSL ? NS_HTTPS_DEFAULT_PORT : NS_HTTP_DEFAULT_PORT; }
     125            3280 :     void          SetAnonymous(bool anon)         
     126            3280 :                                          { mHashKey.SetCharAt(anon ? 'A' : '.', 2); }
     127               4 :     bool          GetAnonymous()         { return mHashKey.CharAt(2) == 'A'; }
     128                 :     bool          ShouldForceConnectMethod();
     129               0 :     const nsCString &GetHost() { return mHost; }
     130                 : 
     131                 : private:
     132                 :     nsrefcnt               mRef;
     133                 :     nsCString              mHashKey;
     134                 :     nsCString              mHost;
     135                 :     PRInt32                mPort;
     136                 :     nsCOMPtr<nsProxyInfo>  mProxyInfo;
     137                 :     bool                   mUsingHttpProxy;
     138                 :     bool                   mUsingSSL;
     139                 : };
     140                 : 
     141                 : #endif // nsHttpConnectionInfo_h__

Generated by: LCOV version 1.7