Back to index

lightning-sunbird  0.9+nobinonly
nsSSLThread.h
Go to the documentation of this file.
00001 /* ***** BEGIN LICENSE BLOCK *****
00002  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00003  *
00004  * The contents of this file are subject to the Mozilla Public License Version
00005  * 1.1 (the "License"); you may not use this file except in compliance with
00006  * the License. You may obtain a copy of the License at
00007  * http://www.mozilla.org/MPL/
00008  *
00009  * Software distributed under the License is distributed on an "AS IS" basis,
00010  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00011  * for the specific language governing rights and limitations under the
00012  * License.
00013  *
00014  * The Original Code is mozilla.org code.
00015  *
00016  * The Initial Developer of the Original Code is
00017  * Red Hat, Inc.
00018  * Portions created by the Initial Developer are Copyright (C) 2006
00019  * the Initial Developer. All Rights Reserved.
00020  *
00021  * Contributor(s):
00022  *   Kai Engert <kengert@redhat.com>
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 #ifndef _NSSSLTHREAD_H_
00039 #define _NSSSLTHREAD_H_
00040 
00041 #include "nsCOMPtr.h"
00042 #include "nsIRequest.h"
00043 #include "nsPSMBackgroundThread.h"
00044 
00045 class nsNSSSocketInfo;
00046 class nsIHttpChannel;
00047 
00048 class nsSSLThread : public nsPSMBackgroundThread
00049 {
00050 private:
00051   // We use mMutex contained in our base class
00052   // to protect access to these variables:
00053   //   mBusySocket, mSocketScheduledToBeDestroyed
00054   // and to nsSSLSocketThreadData::mSSLState
00055   // while a socket is the busy socket.
00056 
00057   // We use mCond contained in our base class
00058   // to notify the SSL thread that a new SSL I/O 
00059   // request has been queued for processing.
00060   // It can be found in the mBusySocket variable,
00061   // containing all details in its member.
00062 
00063   // A socket that is currently owned by the SSL thread 
00064   // and has pending SSL I/O activity or I/O results 
00065   // not yet fetched by the original caller.
00066   nsNSSSocketInfo *mBusySocket;
00067   
00068   // A socket that should be closed and destroyed
00069   // as soon as possible. The request was initiated by
00070   // Necko, but it happened at a time when the SSL
00071   // thread had ownership of the socket, so the request
00072   // was delayed. It's now the responsibility of the
00073   // SSL thread to close and destroy this socket.
00074   nsNSSSocketInfo *mSocketScheduledToBeDestroyed;
00075 
00076   // Did we receive a request from NSS to fetch HTTP 
00077   // data on behalf of NSS? (Most likely this is a OCSP request)
00078   // We track a handle to the HTTP request sent to Necko.
00079   // As this HTTP request depends on some original SSL socket,
00080   // we can use this handle to cancel the dependent HTTP request,
00081   // should we be asked to close the original SSL socket.
00082   nsIRequest* mPendingHTTPRequest;
00083 
00084   virtual void Run(void);
00085 
00086   // Called from SSL thread only
00087   static PRInt32 checkHandshake(PRInt32 bytesTransfered, 
00088                                 PRBool wasReading,
00089                                 PRFileDesc* fd, 
00090                                 nsNSSSocketInfo *socketInfo);
00091 
00092   // Function can be called from either Necko or SSL thread
00093   // Caller must lock mMutex before this call.
00094   static void restoreOriginalSocket_locked(nsNSSSocketInfo *si);
00095 
00096   // Helper for requestSomething functions, 
00097   // caled from the Necko thread only.
00098   static PRFileDesc *getRealSSLFD(nsNSSSocketInfo *si);
00099 
00100   
00101 public:
00102   nsSSLThread();
00103   ~nsSSLThread();
00104 
00105   static nsSSLThread *ssl_thread_singleton;
00106 
00107   // All requestSomething functions are called from 
00108   // the Necko thread only.
00109 
00110   static PRInt32 requestRead(nsNSSSocketInfo *si, 
00111                              void *buf, 
00112                              PRInt32 amount);
00113 
00114   static PRInt32 requestWrite(nsNSSSocketInfo *si, 
00115                               const void *buf, 
00116                               PRInt32 amount);
00117 
00118   static PRInt16 requestPoll(nsNSSSocketInfo *si, 
00119                              PRInt16 in_flags, 
00120                              PRInt16 *out_flags);
00121 
00122   static PRInt32 requestRecvMsgPeek(nsNSSSocketInfo *si, void *buf, PRInt32 amount,
00123                                     PRIntn flags, PRIntervalTime timeout);
00124 
00125   static PRStatus requestClose(nsNSSSocketInfo *si);
00126 
00127   static PRStatus requestGetsockname(nsNSSSocketInfo *si, PRNetAddr *addr);
00128 
00129   static PRStatus requestGetpeername(nsNSSSocketInfo *si, PRNetAddr *addr);
00130 
00131   static PRStatus requestGetsocketoption(nsNSSSocketInfo *si, 
00132                                          PRSocketOptionData *data);
00133 
00134   static PRStatus requestSetsocketoption(nsNSSSocketInfo *si, 
00135                                          const PRSocketOptionData *data);
00136 
00137   static PRStatus requestConnectcontinue(nsNSSSocketInfo *si, 
00138                                          PRInt16 out_flags);
00139 
00140   static nsresult requestActivateSSL(nsNSSSocketInfo *si);
00141   
00142   // Called from either Necko or SSL thread.
00143   static void rememberPendingHTTPRequest(nsIRequest *aRequest);
00144   static void cancelPendingHTTPRequest();
00145 };
00146 
00147 #endif //_NSSSLTHREAD_H_