Line data Source code
1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 : *
3 : * This Source Code Form is subject to the terms of the Mozilla Public
4 : * License, v. 2.0. If a copy of the MPL was not distributed with this
5 : * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
6 :
7 : #ifndef nsNSSCallbacks_h
8 : #define nsNSSCallbacks_h
9 :
10 : #include "mozilla/Attributes.h"
11 : #include "mozilla/BasePrincipal.h"
12 : #include "mozilla/CondVar.h"
13 : #include "mozilla/Mutex.h"
14 : #include "mozilla/TimeStamp.h"
15 : #include "nsAutoPtr.h"
16 : #include "nsCOMPtr.h"
17 : #include "nsIStreamLoader.h"
18 : #include "nspr.h"
19 : #include "nsString.h"
20 : #include "pk11func.h"
21 : #include "pkix/pkixtypes.h"
22 :
23 : #include "ocspt.h" // Must be included after pk11func.h.
24 :
25 : using mozilla::OriginAttributes;
26 :
27 : class nsILoadGroup;
28 :
29 : char*
30 : PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg);
31 :
32 : void HandshakeCallback(PRFileDesc *fd, void *client_data);
33 : SECStatus CanFalseStartCallback(PRFileDesc* fd, void* client_data,
34 : PRBool *canFalseStart);
35 :
36 : class nsHTTPListener final : public nsIStreamLoaderObserver
37 : {
38 : private:
39 : // For XPCOM implementations that are not a base class for some other
40 : // class, it is good practice to make the destructor non-virtual and
41 : // private. Then the only way to delete the object is via Release.
42 : #ifdef _MSC_VER
43 : // C4265: Class has virtual members but destructor is not virtual
44 : __pragma(warning(disable:4265))
45 : #endif
46 : ~nsHTTPListener();
47 :
48 : public:
49 : nsHTTPListener();
50 :
51 : NS_DECL_THREADSAFE_ISUPPORTS
52 : NS_DECL_NSISTREAMLOADEROBSERVER
53 :
54 : nsCOMPtr<nsIStreamLoader> mLoader;
55 :
56 : nsresult mResultCode;
57 :
58 : bool mHttpRequestSucceeded;
59 : uint16_t mHttpResponseCode;
60 :
61 : const uint8_t* mResultData; // allocated in loader, but owned by listener
62 : uint32_t mResultLen;
63 :
64 : mozilla::Mutex mLock;
65 : mozilla::CondVar mCondition;
66 : volatile bool mWaitFlag;
67 :
68 : bool mResponsibleForDoneSignal;
69 : void send_done_signal();
70 :
71 : // no nsCOMPtr. When I use it, I get assertions about
72 : // loadgroup not being thread safe.
73 : // So, let's use a raw pointer and ensure we only create and destroy
74 : // it on the network thread ourselves.
75 : nsILoadGroup *mLoadGroup;
76 : PRThread *mLoadGroupOwnerThread;
77 : void FreeLoadGroup(bool aCancelLoad);
78 : };
79 :
80 0 : class nsNSSHttpServerSession
81 : {
82 : public:
83 : typedef mozilla::pkix::Result Result;
84 :
85 : nsCString mHost;
86 : uint16_t mPort;
87 :
88 : static Result createSessionFcn(const char* host,
89 : uint16_t portnum,
90 : /*out*/ nsNSSHttpServerSession** pSession);
91 : };
92 :
93 : class nsNSSHttpRequestSession
94 : {
95 : protected:
96 : mozilla::ThreadSafeAutoRefCnt mRefCount;
97 :
98 : public:
99 : typedef mozilla::pkix::Result Result;
100 :
101 : static Result createFcn(const nsNSSHttpServerSession* session,
102 : const char* httpProtocolVariant,
103 : const char* pathAndQueryString,
104 : const char* httpRequestMethod,
105 : const OriginAttributes& originAttributes,
106 : const mozilla::TimeDuration timeout,
107 : /*out*/ nsNSSHttpRequestSession** pRequest);
108 :
109 : Result setPostDataFcn(const char* httpData,
110 : const uint32_t httpDataLen,
111 : const char* httpContentType);
112 :
113 : Result trySendAndReceiveFcn(PRPollDesc** pPollDesc,
114 : uint16_t* httpResponseCode,
115 : const char** httpResponseHeaders,
116 : const char** httpResponseData,
117 : uint32_t* httpResponseDataLen);
118 :
119 : void AddRef();
120 : void Release();
121 :
122 : nsCString mURL;
123 : nsCString mRequestMethod;
124 :
125 : bool mHasPostData;
126 : nsCString mPostData;
127 : nsCString mPostContentType;
128 :
129 : OriginAttributes mOriginAttributes;
130 :
131 : mozilla::TimeDuration mTimeout;
132 :
133 : RefPtr<nsHTTPListener> mListener;
134 :
135 : protected:
136 : nsNSSHttpRequestSession();
137 : ~nsNSSHttpRequestSession();
138 :
139 : Result internal_send_receive_attempt(bool& retryableError,
140 : PRPollDesc** pPollDesc,
141 : uint16_t* httpResponseCode,
142 : const char** httpResponseHeaders,
143 : const char** httpResponseData,
144 : uint32_t* httpResponseDataLen);
145 : };
146 :
147 : class nsNSSHttpInterface
148 : {
149 : public:
150 : typedef mozilla::pkix::Result Result;
151 :
152 0 : static Result createSessionFcn(const char* host,
153 : uint16_t portnum,
154 : /*out*/ nsNSSHttpServerSession** pSession)
155 : {
156 0 : return nsNSSHttpServerSession::createSessionFcn(host, portnum, pSession);
157 : }
158 :
159 0 : static Result createFcn(const nsNSSHttpServerSession* session,
160 : const char* httpProtocolVariant,
161 : const char* pathAndQueryString,
162 : const char* httpRequestMethod,
163 : const OriginAttributes& originAttributes,
164 : const mozilla::TimeDuration timeout,
165 : /*out*/ nsNSSHttpRequestSession** pRequest)
166 : {
167 : return nsNSSHttpRequestSession::createFcn(session, httpProtocolVariant,
168 : pathAndQueryString,
169 : httpRequestMethod, originAttributes,
170 0 : timeout, pRequest);
171 : }
172 :
173 0 : static Result setPostDataFcn(nsNSSHttpRequestSession* request,
174 : const char* httpData,
175 : const uint32_t httpDataLen,
176 : const char* httpContentType)
177 : {
178 0 : return request->setPostDataFcn(httpData, httpDataLen, httpContentType);
179 : }
180 :
181 0 : static Result trySendAndReceiveFcn(nsNSSHttpRequestSession* request,
182 : PRPollDesc** pPollDesc,
183 : uint16_t* httpResponseCode,
184 : const char** httpResponseHeaders,
185 : const char** httpResponseData,
186 : uint32_t* httpResponseDataLen)
187 : {
188 : return request->trySendAndReceiveFcn(pPollDesc, httpResponseCode,
189 : httpResponseHeaders,
190 0 : httpResponseData, httpResponseDataLen);
191 : }
192 : };
193 :
194 : #endif // nsNSSCallbacks_h
|