Back to index

lightning-sunbird  0.9+nobinonly
nsFTPChannel.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either the GNU General Public License Version 2 or later (the "GPL"), or
00026  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 // ftp implementation header
00039 
00040 #ifndef nsFTPChannel_h___
00041 #define nsFTPChannel_h___
00042 
00043 #include "nsIIOService.h"
00044 #include "nsIURI.h"
00045 #include "nsString.h"
00046 #include "nsILoadGroup.h"
00047 #include "nsCOMPtr.h"
00048 #include "nsIProtocolHandler.h"
00049 #include "nsIProgressEventSink.h"
00050 #include "nsIInterfaceRequestor.h"
00051 #include "nsIInterfaceRequestorUtils.h"
00052 #include "nsFtpConnectionThread.h"
00053 #include "netCore.h"
00054 #include "nsIStreamListener.h"
00055 #include "nsAutoLock.h"
00056 #include "nsIPrompt.h"
00057 #include "nsIAuthPrompt.h"
00058 #include "nsIFTPChannel.h"
00059 #include "nsIUploadChannel.h"
00060 #include "nsIProxyInfo.h"
00061 #include "nsIResumableChannel.h"
00062 #include "nsHashPropertyBag.h"
00063 
00064 #include "nsICacheService.h"
00065 #include "nsICacheEntryDescriptor.h"
00066 #include "nsICacheListener.h"
00067 #include "nsICacheSession.h"
00068 
00069 #define FTP_COMMAND_CHANNEL_SEG_SIZE 64
00070 #define FTP_COMMAND_CHANNEL_SEG_COUNT 8
00071 
00072 #define FTP_DATA_CHANNEL_SEG_SIZE  (4*1024)
00073 #define FTP_DATA_CHANNEL_SEG_COUNT 8
00074 
00075 #define FTP_CACHE_CONTROL_CONNECTION 1
00076 
00077 class nsFTPChannel : public nsHashPropertyBag,
00078                      public nsIFTPChannel,
00079                      public nsIUploadChannel,
00080                      public nsIInterfaceRequestor,
00081                      public nsIProgressEventSink,
00082                      public nsIStreamListener, 
00083                      public nsICacheListener,
00084                      public nsIResumableChannel
00085 {
00086 public:
00087     NS_DECL_ISUPPORTS_INHERITED
00088     NS_DECL_NSIREQUEST
00089     NS_DECL_NSICHANNEL
00090     NS_DECL_NSIUPLOADCHANNEL
00091     NS_DECL_NSIFTPCHANNEL
00092     NS_DECL_NSIINTERFACEREQUESTOR
00093     NS_DECL_NSIPROGRESSEVENTSINK
00094     NS_DECL_NSISTREAMLISTENER
00095     NS_DECL_NSIREQUESTOBSERVER
00096     NS_DECL_NSICACHELISTENER
00097     NS_DECL_NSIRESUMABLECHANNEL
00098     
00099     // nsFTPChannel methods:
00100     nsFTPChannel();
00101     virtual ~nsFTPChannel();
00102     
00103     // initializes the channel. 
00104     nsresult Init(nsIURI* uri,
00105                   nsIProxyInfo* proxyInfo,
00106                   nsICacheSession* session);
00107 
00108     nsresult SetupState(PRUint64 startPos, const nsACString& entityID);
00109     nsresult GenerateCacheKey(nsACString &cacheKey);
00110     
00111     nsresult AsyncOpenAt(nsIStreamListener *listener, nsISupports *ctxt,
00112                          PRUint64 startPos, const nsACString& entityID);
00113 
00114     // Helper function to simplify getting notification callbacks.
00115     template <class T>
00116     void GetCallback(nsCOMPtr<T> &aResult) {
00117         GetInterface(NS_GET_IID(T), getter_AddRefs(aResult));
00118     }
00119 
00120     // Helper function for getting the nsIFTPEventSink.
00121     void GetFTPEventSink(nsCOMPtr<nsIFTPEventSink> &aResult);
00122 
00123 protected:
00124     void InitProgressSink();
00125 
00126 protected:
00127     nsCOMPtr<nsIURI>                mOriginalURI;
00128     nsCOMPtr<nsIURI>                mURL;
00129     
00130     nsCOMPtr<nsIInputStream>        mUploadStream;
00131 
00132     // various callback interfaces
00133     nsCOMPtr<nsIProgressEventSink>  mProgressSink;
00134     nsCOMPtr<nsIFTPEventSink>       mFTPEventSink;
00135     nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
00136 
00137     PRBool                          mIsPending;
00138     PRUint32                        mLoadFlags;
00139 
00140     PRUint32                        mSourceOffset;
00141     PRInt32                         mAmount;
00142     nsCOMPtr<nsILoadGroup>          mLoadGroup;
00143     nsCString                       mContentType;
00144     nsCString                       mContentCharset;
00145     PRInt32                         mContentLength;
00146     nsCOMPtr<nsISupports>           mOwner;
00147 
00148     nsCOMPtr<nsIStreamListener>     mListener;
00149 
00150     nsFtpState*                     mFTPState;   
00151 
00152     nsCOMPtr<nsISupports>           mUserContext;
00153     nsresult                        mStatus;
00154     PRPackedBool                    mCanceled;
00155 
00156     nsCOMPtr<nsIIOService>          mIOService;
00157 
00158     nsCOMPtr<nsICacheSession>         mCacheSession;
00159     nsCOMPtr<nsICacheEntryDescriptor> mCacheEntry;
00160     nsCOMPtr<nsIProxyInfo>            mProxyInfo;
00161     nsCString                         mEntityID;
00162     PRUint64                          mStartPos;
00163 };
00164 
00165 #endif /* nsFTPChannel_h___ */