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