1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/security/manager/ssl/src/nsNSSCallbacks.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,224 @@ 1.4 +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- 1.5 + * 1.6 + * This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +#ifndef _NSNSSCALLBACKS_H_ 1.11 +#define _NSNSSCALLBACKS_H_ 1.12 + 1.13 +#include "nsAutoPtr.h" 1.14 +#include "nsCOMPtr.h" 1.15 +#include "pk11func.h" 1.16 +#include "nspr.h" 1.17 +#include "ocspt.h" 1.18 +#include "nsIStreamLoader.h" 1.19 +#include "mozilla/CondVar.h" 1.20 +#include "mozilla/Mutex.h" 1.21 +#include "mozilla/Attributes.h" 1.22 +#include "nsString.h" 1.23 + 1.24 +class nsILoadGroup; 1.25 + 1.26 +char* 1.27 +PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg); 1.28 + 1.29 +void HandshakeCallback(PRFileDesc *fd, void *client_data); 1.30 +SECStatus CanFalseStartCallback(PRFileDesc* fd, void* client_data, 1.31 + PRBool *canFalseStart); 1.32 + 1.33 +class nsHTTPListener MOZ_FINAL : public nsIStreamLoaderObserver 1.34 +{ 1.35 +private: 1.36 + // For XPCOM implementations that are not a base class for some other 1.37 + // class, it is good practice to make the destructor non-virtual and 1.38 + // private. Then the only way to delete the object is via Release. 1.39 + ~nsHTTPListener(); 1.40 + 1.41 +public: 1.42 + nsHTTPListener(); 1.43 + 1.44 + NS_DECL_THREADSAFE_ISUPPORTS 1.45 + NS_DECL_NSISTREAMLOADEROBSERVER 1.46 + 1.47 + nsCOMPtr<nsIStreamLoader> mLoader; 1.48 + 1.49 + nsresult mResultCode; 1.50 + 1.51 + bool mHttpRequestSucceeded; 1.52 + uint16_t mHttpResponseCode; 1.53 + nsCString mHttpResponseContentType; 1.54 + 1.55 + const uint8_t* mResultData; // allocated in loader, but owned by listener 1.56 + uint32_t mResultLen; 1.57 + 1.58 + mozilla::Mutex mLock; 1.59 + mozilla::CondVar mCondition; 1.60 + volatile bool mWaitFlag; 1.61 + 1.62 + bool mResponsibleForDoneSignal; 1.63 + void send_done_signal(); 1.64 + 1.65 + // no nsCOMPtr. When I use it, I get assertions about 1.66 + // loadgroup not being thread safe. 1.67 + // So, let's use a raw pointer and ensure we only create and destroy 1.68 + // it on the network thread ourselves. 1.69 + nsILoadGroup *mLoadGroup; 1.70 + PRThread *mLoadGroupOwnerThread; 1.71 + void FreeLoadGroup(bool aCancelLoad); 1.72 +}; 1.73 + 1.74 +class nsNSSHttpServerSession 1.75 +{ 1.76 +public: 1.77 + nsCString mHost; 1.78 + uint16_t mPort; 1.79 + 1.80 + static SECStatus createSessionFcn(const char *host, 1.81 + uint16_t portnum, 1.82 + SEC_HTTP_SERVER_SESSION *pSession); 1.83 +}; 1.84 + 1.85 +class nsNSSHttpRequestSession 1.86 +{ 1.87 +protected: 1.88 + mozilla::ThreadSafeAutoRefCnt mRefCount; 1.89 + 1.90 +public: 1.91 + static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session, 1.92 + const char *http_protocol_variant, 1.93 + const char *path_and_query_string, 1.94 + const char *http_request_method, 1.95 + const PRIntervalTime timeout, 1.96 + SEC_HTTP_REQUEST_SESSION *pRequest); 1.97 + 1.98 + SECStatus setPostDataFcn(const char *http_data, 1.99 + const uint32_t http_data_len, 1.100 + const char *http_content_type); 1.101 + 1.102 + SECStatus addHeaderFcn(const char *http_header_name, 1.103 + const char *http_header_value); 1.104 + 1.105 + SECStatus trySendAndReceiveFcn(PRPollDesc **pPollDesc, 1.106 + uint16_t *http_response_code, 1.107 + const char **http_response_content_type, 1.108 + const char **http_response_headers, 1.109 + const char **http_response_data, 1.110 + uint32_t *http_response_data_len); 1.111 + 1.112 + SECStatus cancelFcn(); 1.113 + SECStatus freeFcn(); 1.114 + 1.115 + void AddRef(); 1.116 + void Release(); 1.117 + 1.118 + nsCString mURL; 1.119 + nsCString mRequestMethod; 1.120 + 1.121 + bool mHasPostData; 1.122 + nsCString mPostData; 1.123 + nsCString mPostContentType; 1.124 + 1.125 + PRIntervalTime mTimeoutInterval; 1.126 + 1.127 + nsRefPtr<nsHTTPListener> mListener; 1.128 + 1.129 +protected: 1.130 + nsNSSHttpRequestSession(); 1.131 + ~nsNSSHttpRequestSession(); 1.132 + 1.133 + SECStatus internal_send_receive_attempt(bool &retryable_error, 1.134 + PRPollDesc **pPollDesc, 1.135 + uint16_t *http_response_code, 1.136 + const char **http_response_content_type, 1.137 + const char **http_response_headers, 1.138 + const char **http_response_data, 1.139 + uint32_t *http_response_data_len); 1.140 +}; 1.141 + 1.142 +class nsNSSHttpInterface 1.143 +{ 1.144 +public: 1.145 + static SECStatus createSessionFcn(const char *host, 1.146 + uint16_t portnum, 1.147 + SEC_HTTP_SERVER_SESSION *pSession) 1.148 + { 1.149 + return nsNSSHttpServerSession::createSessionFcn(host, portnum, pSession); 1.150 + } 1.151 + 1.152 + static SECStatus keepAliveFcn(SEC_HTTP_SERVER_SESSION session, 1.153 + PRPollDesc **pPollDesc) 1.154 + { 1.155 + // Not yet implemented, however, Necko does transparent keep-alive 1.156 + // anyway, when enabled in Necko's prefs. 1.157 + return SECSuccess; 1.158 + } 1.159 + 1.160 + static SECStatus freeSessionFcn(SEC_HTTP_SERVER_SESSION session) 1.161 + { 1.162 + delete static_cast<nsNSSHttpServerSession*>(session); 1.163 + return SECSuccess; 1.164 + } 1.165 + 1.166 + static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session, 1.167 + const char *http_protocol_variant, 1.168 + const char *path_and_query_string, 1.169 + const char *http_request_method, 1.170 + const PRIntervalTime timeout, 1.171 + SEC_HTTP_REQUEST_SESSION *pRequest) 1.172 + { 1.173 + return nsNSSHttpRequestSession::createFcn(session, http_protocol_variant, 1.174 + path_and_query_string, http_request_method, 1.175 + timeout, pRequest); 1.176 + } 1.177 + 1.178 + static SECStatus setPostDataFcn(SEC_HTTP_REQUEST_SESSION request, 1.179 + const char *http_data, 1.180 + const uint32_t http_data_len, 1.181 + const char *http_content_type) 1.182 + { 1.183 + return static_cast<nsNSSHttpRequestSession*>(request) 1.184 + ->setPostDataFcn(http_data, http_data_len, http_content_type); 1.185 + } 1.186 + 1.187 + static SECStatus addHeaderFcn(SEC_HTTP_REQUEST_SESSION request, 1.188 + const char *http_header_name, 1.189 + const char *http_header_value) 1.190 + { 1.191 + return static_cast<nsNSSHttpRequestSession*>(request) 1.192 + ->addHeaderFcn(http_header_name, http_header_value); 1.193 + } 1.194 + 1.195 + static SECStatus trySendAndReceiveFcn(SEC_HTTP_REQUEST_SESSION request, 1.196 + PRPollDesc **pPollDesc, 1.197 + uint16_t *http_response_code, 1.198 + const char **http_response_content_type, 1.199 + const char **http_response_headers, 1.200 + const char **http_response_data, 1.201 + uint32_t *http_response_data_len) 1.202 + { 1.203 + return static_cast<nsNSSHttpRequestSession*>(request) 1.204 + ->trySendAndReceiveFcn(pPollDesc, http_response_code, http_response_content_type, 1.205 + http_response_headers, http_response_data, http_response_data_len); 1.206 + } 1.207 + 1.208 + static SECStatus cancelFcn(SEC_HTTP_REQUEST_SESSION request) 1.209 + { 1.210 + return static_cast<nsNSSHttpRequestSession*>(request) 1.211 + ->cancelFcn(); 1.212 + } 1.213 + 1.214 + static SECStatus freeFcn(SEC_HTTP_REQUEST_SESSION request) 1.215 + { 1.216 + return static_cast<nsNSSHttpRequestSession*>(request) 1.217 + ->freeFcn(); 1.218 + } 1.219 + 1.220 + static void initTable(); 1.221 + static SEC_HttpClientFcn sNSSInterfaceTable; 1.222 + 1.223 + void registerHttpClient(); 1.224 + void unregisterHttpClient(); 1.225 +}; 1.226 + 1.227 +#endif // _NSNSSCALLBACKS_H_