Back to index

lightning-sunbird  0.9+nobinonly
nsNSSCallbacks.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
00002  *
00003  * ***** BEGIN LICENSE BLOCK *****
00004  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00005  *
00006  * The contents of this file are subject to the Mozilla Public License Version
00007  * 1.1 (the "License"); you may not use this file except in compliance with
00008  * the License. You may obtain a copy of the License at
00009  * http://www.mozilla.org/MPL/
00010  *
00011  * Software distributed under the License is distributed on an "AS IS" basis,
00012  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00013  * for the specific language governing rights and limitations under the
00014  * License.
00015  *
00016  * The Original Code is mozilla.org code.
00017  *
00018  * The Initial Developer of the Original Code is
00019  * Netscape Communications Corporation.
00020  * Portions created by the Initial Developer are Copyright (C) 1998
00021  * the Initial Developer. All Rights Reserved.
00022  *
00023  * Contributor(s):
00024  *   Brian Ryner <bryner@brianryner.com>
00025  *   Kai Engert <kengert@redhat.com>
00026  *
00027  * Alternatively, the contents of this file may be used under the terms of
00028  * either the GNU General Public License Version 2 or later (the "GPL"), or
00029  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00030  * in which case the provisions of the GPL or the LGPL are applicable instead
00031  * of those above. If you wish to allow use of your version of this file only
00032  * under the terms of either the GPL or the LGPL, and not to allow others to
00033  * use your version of this file under the terms of the MPL, indicate your
00034  * decision by deleting the provisions above and replace them with the notice
00035  * and other provisions required by the GPL or the LGPL. If you do not delete
00036  * the provisions above, a recipient may use your version of this file under
00037  * the terms of any one of the MPL, the GPL or the LGPL.
00038  *
00039  * ***** END LICENSE BLOCK ***** */
00040 
00041 #ifndef _NSNSSCALLBACKS_H_
00042 #define _NSNSSCALLBACKS_H_
00043 
00044 #include "pk11func.h"
00045 #include "nspr.h"
00046 #include "ocspt.h"
00047 #include "nsIStreamLoader.h"
00048 
00049 char* PR_CALLBACK
00050 PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg);
00051 
00052 void PR_CALLBACK HandshakeCallback(PRFileDesc *fd, void *client_data);
00053 SECStatus PR_CALLBACK AuthCertificateCallback(void* client_data, PRFileDesc* fd,
00054                                               PRBool checksig, PRBool isServer);
00055 
00056 class nsHTTPListener : public nsIStreamLoaderObserver
00057 {
00058 private:
00059   // For XPCOM implementations that are not a base class for some other
00060   // class, it is good practice to make the destructor non-virtual and
00061   // private.  Then the only way to delete the object is via Release.
00062   ~nsHTTPListener();
00063 
00064 public:
00065   nsHTTPListener();
00066 
00067   NS_DECL_ISUPPORTS
00068   NS_DECL_NSISTREAMLOADEROBSERVER
00069 
00070   nsCOMPtr<nsIStreamLoader> mLoader;
00071 
00072   nsresult mResultCode;
00073 
00074   PRBool mHttpRequestSucceeded;
00075   PRUint16 mHttpResponseCode;
00076   nsCString mHttpResponseContentType;
00077 
00078   const PRUint8* mResultData; // not owned, refers to mLoader
00079   PRUint32 mResultLen;
00080   
00081   nsresult InitLocks();
00082   
00083   PRLock *mLock;
00084   PRCondVar *mCondition;
00085   volatile PRBool mWaitFlag;
00086   
00087   PRBool mResponsibleForDoneSignal;
00088   void send_done_signal();
00089 };
00090 
00091 class nsNSSHttpServerSession
00092 {
00093 public:
00094   nsCString mHost;
00095   PRUint16 mPort;  
00096 
00097   static SECStatus createSessionFcn(const char *host,
00098                                     PRUint16 portnum,
00099                                     SEC_HTTP_SERVER_SESSION *pSession);
00100 };
00101 
00102 class nsNSSHttpRequestSession
00103 {
00104 public:
00105   static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
00106                              const char *http_protocol_variant,
00107                              const char *path_and_query_string,
00108                              const char *http_request_method, 
00109                              const PRIntervalTime timeout, 
00110                              SEC_HTTP_REQUEST_SESSION *pRequest);
00111 
00112   SECStatus setPostDataFcn(const char *http_data, 
00113                            const PRUint32 http_data_len,
00114                            const char *http_content_type);
00115 
00116   SECStatus addHeaderFcn(const char *http_header_name, 
00117                          const char *http_header_value);
00118 
00119   SECStatus trySendAndReceiveFcn(PRPollDesc **pPollDesc,
00120                                  PRUint16 *http_response_code, 
00121                                  const char **http_response_content_type, 
00122                                  const char **http_response_headers, 
00123                                  const char **http_response_data, 
00124                                  PRUint32 *http_response_data_len);
00125 
00126   SECStatus cancelFcn();
00127   SECStatus freeFcn();
00128 
00129   nsCString mURL;
00130   nsCString mRequestMethod;
00131   
00132   PRBool mHasPostData;
00133   nsCString mPostData;
00134   nsCString mPostContentType;
00135   
00136   PRIntervalTime mTimeoutInterval;
00137   
00138   nsCOMPtr<nsHTTPListener> mListener;
00139   
00140 protected:
00141   nsNSSHttpRequestSession();
00142   ~nsNSSHttpRequestSession();
00143 
00144   SECStatus internal_send_receive_attempt(PRBool &retryable_error,
00145                                           PRPollDesc **pPollDesc,
00146                                           PRUint16 *http_response_code,
00147                                           const char **http_response_content_type,
00148                                           const char **http_response_headers,
00149                                           const char **http_response_data,
00150                                           PRUint32 *http_response_data_len);
00151 };
00152 
00153 class nsNSSHttpInterface
00154 {
00155 public:
00156   static SECStatus createSessionFcn(const char *host,
00157                                     PRUint16 portnum,
00158                                     SEC_HTTP_SERVER_SESSION *pSession)
00159   {
00160     return nsNSSHttpServerSession::createSessionFcn(host, portnum, pSession);
00161   }
00162 
00163   static SECStatus keepAliveFcn(SEC_HTTP_SERVER_SESSION session,
00164                                 PRPollDesc **pPollDesc)
00165   {
00166     // Not yet implemented, however, Necko does transparent keep-alive 
00167     // anyway, when enabled in Necko's prefs.
00168     return SECSuccess;
00169   }
00170 
00171   static SECStatus freeSessionFcn(SEC_HTTP_SERVER_SESSION session)
00172   {
00173     delete NS_STATIC_CAST(nsNSSHttpServerSession*, session);
00174     return SECSuccess;
00175   }
00176 
00177   static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
00178                              const char *http_protocol_variant,
00179                              const char *path_and_query_string,
00180                              const char *http_request_method, 
00181                              const PRIntervalTime timeout, 
00182                              SEC_HTTP_REQUEST_SESSION *pRequest)
00183   {
00184     return nsNSSHttpRequestSession::createFcn(session, http_protocol_variant,
00185                                      path_and_query_string, http_request_method, 
00186                                      timeout, pRequest);
00187   }
00188 
00189   static SECStatus setPostDataFcn(SEC_HTTP_REQUEST_SESSION request, 
00190                                   const char *http_data, 
00191                                   const PRUint32 http_data_len,
00192                                   const char *http_content_type)
00193   {
00194     return NS_STATIC_CAST(nsNSSHttpRequestSession*, request)
00195             ->setPostDataFcn(http_data, http_data_len, http_content_type);
00196   }
00197 
00198   static SECStatus addHeaderFcn(SEC_HTTP_REQUEST_SESSION request,
00199                                 const char *http_header_name, 
00200                                 const char *http_header_value)
00201   {
00202     return NS_STATIC_CAST(nsNSSHttpRequestSession*, request)
00203             ->addHeaderFcn(http_header_name, http_header_value);
00204   }
00205 
00206   static SECStatus trySendAndReceiveFcn(SEC_HTTP_REQUEST_SESSION request, 
00207                                         PRPollDesc **pPollDesc,
00208                                         PRUint16 *http_response_code, 
00209                                         const char **http_response_content_type, 
00210                                         const char **http_response_headers, 
00211                                         const char **http_response_data, 
00212                                         PRUint32 *http_response_data_len)
00213   {
00214     return NS_STATIC_CAST(nsNSSHttpRequestSession*, request)
00215             ->trySendAndReceiveFcn(pPollDesc, http_response_code, http_response_content_type, 
00216                      http_response_headers, http_response_data, http_response_data_len);
00217   }
00218 
00219   static SECStatus cancelFcn(SEC_HTTP_REQUEST_SESSION request)
00220   {
00221     return NS_STATIC_CAST(nsNSSHttpRequestSession*, request)
00222             ->cancelFcn();
00223   }
00224 
00225   static SECStatus freeFcn(SEC_HTTP_REQUEST_SESSION request)
00226   {
00227     return NS_STATIC_CAST(nsNSSHttpRequestSession*, request)
00228             ->freeFcn();
00229   }
00230 
00231   static void initTable();
00232   static SEC_HttpClientFcn sNSSInterfaceTable;
00233 
00234   void registerHttpClient();
00235   void unregisterHttpClient();
00236 };
00237 
00238 #endif // _NSNSSCALLBACKS_H_
00239 
00240 
00241