LCOV - code coverage report
Current view: directory - netwerk/protocol/http - nsAHttpTransaction.h (source / functions) Found Hit Coverage
Test: app.info Lines: 5 3 60.0 %
Date: 2012-06-02 Functions: 4 3 75.0 %

       1                 : /* ***** BEGIN LICENSE BLOCK *****
       2                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       3                 :  *
       4                 :  * The contents of this file are subject to the Mozilla Public License Version
       5                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       6                 :  * the License. You may obtain a copy of the License at
       7                 :  * http://www.mozilla.org/MPL/
       8                 :  *
       9                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      10                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      11                 :  * for the specific language governing rights and limitations under the
      12                 :  * License.
      13                 :  *
      14                 :  * The Original Code is Mozilla.
      15                 :  *
      16                 :  * The Initial Developer of the Original Code is
      17                 :  * Netscape Communications Corporation.
      18                 :  * Portions created by the Initial Developer are Copyright (C) 2002
      19                 :  * the Initial Developer. All Rights Reserved.
      20                 :  *
      21                 :  * Contributor(s):
      22                 :  *   Darin Fisher <darin@netscape.com>
      23                 :  *
      24                 :  * Alternatively, the contents of this file may be used under the terms of
      25                 :  * either the GNU General Public License Version 2 or later (the "GPL"), or
      26                 :  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      27                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      28                 :  * of those above. If you wish to allow use of your version of this file only
      29                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      30                 :  * use your version of this file under the terms of the MPL, indicate your
      31                 :  * decision by deleting the provisions above and replace them with the notice
      32                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      33                 :  * the provisions above, a recipient may use your version of this file under
      34                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      35                 :  *
      36                 :  * ***** END LICENSE BLOCK ***** */
      37                 : 
      38                 : #ifndef nsAHttpTransaction_h__
      39                 : #define nsAHttpTransaction_h__
      40                 : 
      41                 : #include "nsISupports.h"
      42                 : #include "nsTArray.h"
      43                 : 
      44                 : class nsAHttpConnection;
      45                 : class nsAHttpSegmentReader;
      46                 : class nsAHttpSegmentWriter;
      47                 : class nsIInterfaceRequestor;
      48                 : class nsIEventTarget;
      49                 : class nsITransport;
      50                 : class nsHttpRequestHead;
      51                 : 
      52                 : //----------------------------------------------------------------------------
      53                 : // Abstract base class for a HTTP transaction:
      54                 : //
      55                 : // A transaction is a "sink" for the response data.  The connection pushes
      56                 : // data to the transaction by writing to it.  The transaction supports
      57                 : // WriteSegments and may refuse to accept data if its buffers are full (its
      58                 : // write function returns NS_BASE_STREAM_WOULD_BLOCK in this case).
      59                 : //----------------------------------------------------------------------------
      60                 : 
      61                 : class nsAHttpTransaction : public nsISupports
      62            2989 : {
      63                 : public:
      64                 :     // called by the connection when it takes ownership of the transaction.
      65                 :     virtual void SetConnection(nsAHttpConnection *) = 0;
      66                 :     virtual nsAHttpConnection *Connection() = 0;
      67                 : 
      68                 :     // called by the connection to get security callbacks to set on the
      69                 :     // socket transport.
      70                 :     virtual void GetSecurityCallbacks(nsIInterfaceRequestor **,
      71                 :                                       nsIEventTarget **) = 0;
      72                 : 
      73                 :     // called to report socket status (see nsITransportEventSink)
      74                 :     virtual void OnTransportStatus(nsITransport* transport,
      75                 :                                    nsresult status, PRUint64 progress) = 0;
      76                 : 
      77                 :     // called to check the transaction status.
      78                 :     virtual bool     IsDone() = 0;
      79                 :     virtual nsresult Status() = 0;
      80                 : 
      81                 :     // called to find out how much request data is available for writing.
      82                 :     virtual PRUint32 Available() = 0;
      83                 : 
      84                 :     // called to read request data from the transaction.
      85                 :     virtual nsresult ReadSegments(nsAHttpSegmentReader *reader,
      86                 :                                   PRUint32 count, PRUint32 *countRead) = 0;
      87                 : 
      88                 :     // called to write response data to the transaction.
      89                 :     virtual nsresult WriteSegments(nsAHttpSegmentWriter *writer,
      90                 :                                    PRUint32 count, PRUint32 *countWritten) = 0;
      91                 : 
      92                 :     // called to close the transaction
      93                 :     virtual void Close(nsresult reason) = 0;
      94                 : 
      95                 :     // called to indicate a failure at the SSL setup level
      96                 :     virtual void SetSSLConnectFailed() = 0;
      97                 :     
      98                 :     // called to retrieve the request headers of the transaction
      99                 :     virtual nsHttpRequestHead *RequestHead() = 0;
     100                 : 
     101                 :     // determine the number of real http/1.x transactions on this
     102                 :     // abstract object. Pipelines may have multiple, SPDY has 0,
     103                 :     // normal http transactions have 1.
     104                 :     virtual PRUint32 Http1xTransactionCount() = 0;
     105                 : 
     106                 :     // called to remove the unused sub transactions from an object that can
     107                 :     // handle multiple transactions simultaneously (i.e. pipelines or spdy).
     108                 :     //
     109                 :     // Returns NS_ERROR_NOT_IMPLEMENTED if the object does not implement
     110                 :     // sub-transactions.
     111                 :     //
     112                 :     // Returns NS_ERROR_ALREADY_OPENED if the subtransactions have been
     113                 :     // at least partially written and cannot be moved.
     114                 :     //
     115                 :     virtual nsresult TakeSubTransactions(
     116                 :         nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions) = 0;
     117                 : };
     118                 : 
     119                 : #define NS_DECL_NSAHTTPTRANSACTION \
     120                 :     void SetConnection(nsAHttpConnection *); \
     121                 :     nsAHttpConnection *Connection(); \
     122                 :     void GetSecurityCallbacks(nsIInterfaceRequestor **, \
     123                 :                               nsIEventTarget **);       \
     124                 :     void OnTransportStatus(nsITransport* transport, \
     125                 :                            nsresult status, PRUint64 progress); \
     126                 :     bool     IsDone(); \
     127                 :     nsresult Status(); \
     128                 :     PRUint32 Available(); \
     129                 :     nsresult ReadSegments(nsAHttpSegmentReader *, PRUint32, PRUint32 *); \
     130                 :     nsresult WriteSegments(nsAHttpSegmentWriter *, PRUint32, PRUint32 *); \
     131                 :     void     Close(nsresult reason);                                    \
     132                 :     void     SetSSLConnectFailed();                                     \
     133                 :     nsHttpRequestHead *RequestHead();                                   \
     134                 :     PRUint32 Http1xTransactionCount();                                  \
     135                 :     nsresult TakeSubTransactions(nsTArray<nsRefPtr<nsAHttpTransaction> > &outTransactions);
     136                 : 
     137                 : //-----------------------------------------------------------------------------
     138                 : // nsAHttpSegmentReader
     139                 : //-----------------------------------------------------------------------------
     140                 : 
     141                 : class nsAHttpSegmentReader
     142            2976 : {
     143                 : public:
     144                 :     // any returned failure code stops segment iteration
     145                 :     virtual nsresult OnReadSegment(const char *segment,
     146                 :                                    PRUint32 count,
     147                 :                                    PRUint32 *countRead) = 0;
     148                 : 
     149                 :     // Ask the segment reader to commit to accepting size bytes of
     150                 :     // data from subsequent OnReadSegment() calls or throw hard
     151                 :     // (i.e. not wouldblock) exceptions. Implementations
     152                 :     // can return NS_ERROR_FAILURE if they never make commitments of that size
     153                 :     // (the default), NS_BASE_STREAM_WOULD_BLOCK if they cannot make
     154                 :     // the commitment now but might in the future, or NS_OK
     155                 :     // if they make the commitment.
     156                 :     //
     157                 :     // Spdy uses this to make sure frames are atomic.
     158               0 :     virtual nsresult CommitToSegmentSize(PRUint32 size)
     159                 :     {
     160               0 :         return NS_ERROR_FAILURE;
     161                 :     }
     162                 : };
     163                 : 
     164                 : #define NS_DECL_NSAHTTPSEGMENTREADER \
     165                 :     nsresult OnReadSegment(const char *, PRUint32, PRUint32 *);
     166                 : 
     167                 : //-----------------------------------------------------------------------------
     168                 : // nsAHttpSegmentWriter
     169                 : //-----------------------------------------------------------------------------
     170                 : 
     171                 : class nsAHttpSegmentWriter
     172            2976 : {
     173                 : public:
     174                 :     // any returned failure code stops segment iteration
     175                 :     virtual nsresult OnWriteSegment(char *segment,
     176                 :                                     PRUint32 count,
     177                 :                                     PRUint32 *countWritten) = 0;
     178                 : };
     179                 : 
     180                 : #define NS_DECL_NSAHTTPSEGMENTWRITER \
     181                 :     nsresult OnWriteSegment(char *, PRUint32, PRUint32 *);
     182                 : 
     183                 : #endif // nsAHttpTransaction_h__

Generated by: LCOV version 1.7