security/manager/ssl/src/nsNSSCallbacks.h

Wed, 31 Dec 2014 07:16:47 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 07:16:47 +0100
branch
TOR_BUG_9701
changeset 3
141e0f1194b1
permissions
-rw-r--r--

Revert simplistic fix pending revisit of Mozilla integration attempt.

michael@0 1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
michael@0 2 *
michael@0 3 * This Source Code Form is subject to the terms of the Mozilla Public
michael@0 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 6
michael@0 7 #ifndef _NSNSSCALLBACKS_H_
michael@0 8 #define _NSNSSCALLBACKS_H_
michael@0 9
michael@0 10 #include "nsAutoPtr.h"
michael@0 11 #include "nsCOMPtr.h"
michael@0 12 #include "pk11func.h"
michael@0 13 #include "nspr.h"
michael@0 14 #include "ocspt.h"
michael@0 15 #include "nsIStreamLoader.h"
michael@0 16 #include "mozilla/CondVar.h"
michael@0 17 #include "mozilla/Mutex.h"
michael@0 18 #include "mozilla/Attributes.h"
michael@0 19 #include "nsString.h"
michael@0 20
michael@0 21 class nsILoadGroup;
michael@0 22
michael@0 23 char*
michael@0 24 PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg);
michael@0 25
michael@0 26 void HandshakeCallback(PRFileDesc *fd, void *client_data);
michael@0 27 SECStatus CanFalseStartCallback(PRFileDesc* fd, void* client_data,
michael@0 28 PRBool *canFalseStart);
michael@0 29
michael@0 30 class nsHTTPListener MOZ_FINAL : public nsIStreamLoaderObserver
michael@0 31 {
michael@0 32 private:
michael@0 33 // For XPCOM implementations that are not a base class for some other
michael@0 34 // class, it is good practice to make the destructor non-virtual and
michael@0 35 // private. Then the only way to delete the object is via Release.
michael@0 36 ~nsHTTPListener();
michael@0 37
michael@0 38 public:
michael@0 39 nsHTTPListener();
michael@0 40
michael@0 41 NS_DECL_THREADSAFE_ISUPPORTS
michael@0 42 NS_DECL_NSISTREAMLOADEROBSERVER
michael@0 43
michael@0 44 nsCOMPtr<nsIStreamLoader> mLoader;
michael@0 45
michael@0 46 nsresult mResultCode;
michael@0 47
michael@0 48 bool mHttpRequestSucceeded;
michael@0 49 uint16_t mHttpResponseCode;
michael@0 50 nsCString mHttpResponseContentType;
michael@0 51
michael@0 52 const uint8_t* mResultData; // allocated in loader, but owned by listener
michael@0 53 uint32_t mResultLen;
michael@0 54
michael@0 55 mozilla::Mutex mLock;
michael@0 56 mozilla::CondVar mCondition;
michael@0 57 volatile bool mWaitFlag;
michael@0 58
michael@0 59 bool mResponsibleForDoneSignal;
michael@0 60 void send_done_signal();
michael@0 61
michael@0 62 // no nsCOMPtr. When I use it, I get assertions about
michael@0 63 // loadgroup not being thread safe.
michael@0 64 // So, let's use a raw pointer and ensure we only create and destroy
michael@0 65 // it on the network thread ourselves.
michael@0 66 nsILoadGroup *mLoadGroup;
michael@0 67 PRThread *mLoadGroupOwnerThread;
michael@0 68 void FreeLoadGroup(bool aCancelLoad);
michael@0 69 };
michael@0 70
michael@0 71 class nsNSSHttpServerSession
michael@0 72 {
michael@0 73 public:
michael@0 74 nsCString mHost;
michael@0 75 uint16_t mPort;
michael@0 76
michael@0 77 static SECStatus createSessionFcn(const char *host,
michael@0 78 uint16_t portnum,
michael@0 79 SEC_HTTP_SERVER_SESSION *pSession);
michael@0 80 };
michael@0 81
michael@0 82 class nsNSSHttpRequestSession
michael@0 83 {
michael@0 84 protected:
michael@0 85 mozilla::ThreadSafeAutoRefCnt mRefCount;
michael@0 86
michael@0 87 public:
michael@0 88 static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
michael@0 89 const char *http_protocol_variant,
michael@0 90 const char *path_and_query_string,
michael@0 91 const char *http_request_method,
michael@0 92 const PRIntervalTime timeout,
michael@0 93 SEC_HTTP_REQUEST_SESSION *pRequest);
michael@0 94
michael@0 95 SECStatus setPostDataFcn(const char *http_data,
michael@0 96 const uint32_t http_data_len,
michael@0 97 const char *http_content_type);
michael@0 98
michael@0 99 SECStatus addHeaderFcn(const char *http_header_name,
michael@0 100 const char *http_header_value);
michael@0 101
michael@0 102 SECStatus trySendAndReceiveFcn(PRPollDesc **pPollDesc,
michael@0 103 uint16_t *http_response_code,
michael@0 104 const char **http_response_content_type,
michael@0 105 const char **http_response_headers,
michael@0 106 const char **http_response_data,
michael@0 107 uint32_t *http_response_data_len);
michael@0 108
michael@0 109 SECStatus cancelFcn();
michael@0 110 SECStatus freeFcn();
michael@0 111
michael@0 112 void AddRef();
michael@0 113 void Release();
michael@0 114
michael@0 115 nsCString mURL;
michael@0 116 nsCString mRequestMethod;
michael@0 117
michael@0 118 bool mHasPostData;
michael@0 119 nsCString mPostData;
michael@0 120 nsCString mPostContentType;
michael@0 121
michael@0 122 PRIntervalTime mTimeoutInterval;
michael@0 123
michael@0 124 nsRefPtr<nsHTTPListener> mListener;
michael@0 125
michael@0 126 protected:
michael@0 127 nsNSSHttpRequestSession();
michael@0 128 ~nsNSSHttpRequestSession();
michael@0 129
michael@0 130 SECStatus internal_send_receive_attempt(bool &retryable_error,
michael@0 131 PRPollDesc **pPollDesc,
michael@0 132 uint16_t *http_response_code,
michael@0 133 const char **http_response_content_type,
michael@0 134 const char **http_response_headers,
michael@0 135 const char **http_response_data,
michael@0 136 uint32_t *http_response_data_len);
michael@0 137 };
michael@0 138
michael@0 139 class nsNSSHttpInterface
michael@0 140 {
michael@0 141 public:
michael@0 142 static SECStatus createSessionFcn(const char *host,
michael@0 143 uint16_t portnum,
michael@0 144 SEC_HTTP_SERVER_SESSION *pSession)
michael@0 145 {
michael@0 146 return nsNSSHttpServerSession::createSessionFcn(host, portnum, pSession);
michael@0 147 }
michael@0 148
michael@0 149 static SECStatus keepAliveFcn(SEC_HTTP_SERVER_SESSION session,
michael@0 150 PRPollDesc **pPollDesc)
michael@0 151 {
michael@0 152 // Not yet implemented, however, Necko does transparent keep-alive
michael@0 153 // anyway, when enabled in Necko's prefs.
michael@0 154 return SECSuccess;
michael@0 155 }
michael@0 156
michael@0 157 static SECStatus freeSessionFcn(SEC_HTTP_SERVER_SESSION session)
michael@0 158 {
michael@0 159 delete static_cast<nsNSSHttpServerSession*>(session);
michael@0 160 return SECSuccess;
michael@0 161 }
michael@0 162
michael@0 163 static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
michael@0 164 const char *http_protocol_variant,
michael@0 165 const char *path_and_query_string,
michael@0 166 const char *http_request_method,
michael@0 167 const PRIntervalTime timeout,
michael@0 168 SEC_HTTP_REQUEST_SESSION *pRequest)
michael@0 169 {
michael@0 170 return nsNSSHttpRequestSession::createFcn(session, http_protocol_variant,
michael@0 171 path_and_query_string, http_request_method,
michael@0 172 timeout, pRequest);
michael@0 173 }
michael@0 174
michael@0 175 static SECStatus setPostDataFcn(SEC_HTTP_REQUEST_SESSION request,
michael@0 176 const char *http_data,
michael@0 177 const uint32_t http_data_len,
michael@0 178 const char *http_content_type)
michael@0 179 {
michael@0 180 return static_cast<nsNSSHttpRequestSession*>(request)
michael@0 181 ->setPostDataFcn(http_data, http_data_len, http_content_type);
michael@0 182 }
michael@0 183
michael@0 184 static SECStatus addHeaderFcn(SEC_HTTP_REQUEST_SESSION request,
michael@0 185 const char *http_header_name,
michael@0 186 const char *http_header_value)
michael@0 187 {
michael@0 188 return static_cast<nsNSSHttpRequestSession*>(request)
michael@0 189 ->addHeaderFcn(http_header_name, http_header_value);
michael@0 190 }
michael@0 191
michael@0 192 static SECStatus trySendAndReceiveFcn(SEC_HTTP_REQUEST_SESSION request,
michael@0 193 PRPollDesc **pPollDesc,
michael@0 194 uint16_t *http_response_code,
michael@0 195 const char **http_response_content_type,
michael@0 196 const char **http_response_headers,
michael@0 197 const char **http_response_data,
michael@0 198 uint32_t *http_response_data_len)
michael@0 199 {
michael@0 200 return static_cast<nsNSSHttpRequestSession*>(request)
michael@0 201 ->trySendAndReceiveFcn(pPollDesc, http_response_code, http_response_content_type,
michael@0 202 http_response_headers, http_response_data, http_response_data_len);
michael@0 203 }
michael@0 204
michael@0 205 static SECStatus cancelFcn(SEC_HTTP_REQUEST_SESSION request)
michael@0 206 {
michael@0 207 return static_cast<nsNSSHttpRequestSession*>(request)
michael@0 208 ->cancelFcn();
michael@0 209 }
michael@0 210
michael@0 211 static SECStatus freeFcn(SEC_HTTP_REQUEST_SESSION request)
michael@0 212 {
michael@0 213 return static_cast<nsNSSHttpRequestSession*>(request)
michael@0 214 ->freeFcn();
michael@0 215 }
michael@0 216
michael@0 217 static void initTable();
michael@0 218 static SEC_HttpClientFcn sNSSInterfaceTable;
michael@0 219
michael@0 220 void registerHttpClient();
michael@0 221 void unregisterHttpClient();
michael@0 222 };
michael@0 223
michael@0 224 #endif // _NSNSSCALLBACKS_H_

mercurial