2001-01-10 04:32:29 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
2012-05-31 13:33:35 +04:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-01-10 04:32:29 +03:00
|
|
|
|
|
|
|
#ifndef _NSNSSCALLBACKS_H_
|
|
|
|
#define _NSNSSCALLBACKS_H_
|
|
|
|
|
2014-03-18 04:23:03 +04:00
|
|
|
#include "nsAutoPtr.h"
|
2012-11-12 21:42:28 +04:00
|
|
|
#include "nsCOMPtr.h"
|
2001-01-10 04:32:29 +03:00
|
|
|
#include "pk11func.h"
|
|
|
|
#include "nspr.h"
|
2006-04-04 17:14:40 +04:00
|
|
|
#include "ocspt.h"
|
|
|
|
#include "nsIStreamLoader.h"
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
#include "mozilla/CondVar.h"
|
|
|
|
#include "mozilla/Mutex.h"
|
2012-07-19 08:37:09 +04:00
|
|
|
#include "mozilla/Attributes.h"
|
2012-11-12 21:42:28 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
class nsILoadGroup;
|
2001-01-10 04:32:29 +03:00
|
|
|
|
2012-09-25 20:18:38 +04:00
|
|
|
char*
|
2002-01-28 18:23:59 +03:00
|
|
|
PK11PasswordPrompt(PK11SlotInfo *slot, PRBool retry, void* arg);
|
|
|
|
|
2012-09-25 20:18:38 +04:00
|
|
|
void HandshakeCallback(PRFileDesc *fd, void *client_data);
|
2013-06-29 00:58:28 +04:00
|
|
|
SECStatus CanFalseStartCallback(PRFileDesc* fd, void* client_data,
|
|
|
|
PRBool *canFalseStart);
|
2011-08-30 18:33:04 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class nsHTTPListener final : public nsIStreamLoaderObserver
|
2006-04-04 17:14:40 +04:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
// For XPCOM implementations that are not a base class for some other
|
|
|
|
// class, it is good practice to make the destructor non-virtual and
|
|
|
|
// private. Then the only way to delete the object is via Release.
|
2014-05-30 07:17:53 +04:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
// C4265: Class has virtual members but destructor is not virtual
|
|
|
|
__pragma(warning(disable:4265))
|
|
|
|
#endif
|
2006-04-04 17:14:40 +04:00
|
|
|
~nsHTTPListener();
|
|
|
|
|
|
|
|
public:
|
|
|
|
nsHTTPListener();
|
|
|
|
|
2013-07-19 06:24:14 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
2006-04-04 17:14:40 +04:00
|
|
|
NS_DECL_NSISTREAMLOADEROBSERVER
|
|
|
|
|
|
|
|
nsCOMPtr<nsIStreamLoader> mLoader;
|
|
|
|
|
|
|
|
nsresult mResultCode;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHttpRequestSucceeded;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mHttpResponseCode;
|
2006-04-04 17:14:40 +04:00
|
|
|
nsCString mHttpResponseContentType;
|
|
|
|
|
2014-04-10 01:48:17 +04:00
|
|
|
const uint8_t* mResultData; // allocated in loader, but owned by listener
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t mResultLen;
|
2006-04-04 17:14:40 +04:00
|
|
|
|
Rollup of bug 645263 and bug 646259: Switch to mozilla:: sync primitives. r=cjones,dbaron,doublec,ehsan src=bsmedberg
Bug 645263, part 0: Count sync primitive ctor/dtors. r=dbaron
Bug 645263, part 1: Migrate content/media to mozilla:: sync primitives. r=doublec
Bug 645263, part 2: Migrate modules/plugin to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 3: Migrate nsComponentManagerImpl to mozilla:: sync primitives. sr=bsmedberg
Bug 645263, part 4: Migrate everything else to mozilla:: sync primitives. r=dbaron
Bug 645263, part 5: Remove nsAutoLock.*. sr=bsmedberg
Bug 645263, part 6: Make editor test be nicer to deadlock detector. r=ehsan
Bug 645263, part 7: Disable tracemalloc backtraces for xpcshell tests. r=dbaron
Bug 646259: Fix nsCacheService to use a CondVar for notifying. r=cjones
2011-04-01 08:29:02 +04:00
|
|
|
mozilla::Mutex mLock;
|
|
|
|
mozilla::CondVar mCondition;
|
2011-09-29 10:19:26 +04:00
|
|
|
volatile bool mWaitFlag;
|
2006-04-04 17:14:40 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mResponsibleForDoneSignal;
|
2006-04-04 17:14:40 +04:00
|
|
|
void send_done_signal();
|
2008-04-12 08:47:22 +04:00
|
|
|
|
|
|
|
// no nsCOMPtr. When I use it, I get assertions about
|
|
|
|
// loadgroup not being thread safe.
|
|
|
|
// So, let's use a raw pointer and ensure we only create and destroy
|
|
|
|
// it on the network thread ourselves.
|
|
|
|
nsILoadGroup *mLoadGroup;
|
|
|
|
PRThread *mLoadGroupOwnerThread;
|
2011-09-29 10:19:26 +04:00
|
|
|
void FreeLoadGroup(bool aCancelLoad);
|
2006-04-04 17:14:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsNSSHttpServerSession
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
nsCString mHost;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t mPort;
|
2006-04-04 17:14:40 +04:00
|
|
|
|
|
|
|
static SECStatus createSessionFcn(const char *host,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t portnum,
|
2006-04-04 17:14:40 +04:00
|
|
|
SEC_HTTP_SERVER_SESSION *pSession);
|
|
|
|
};
|
|
|
|
|
|
|
|
class nsNSSHttpRequestSession
|
|
|
|
{
|
2008-04-23 02:46:44 +04:00
|
|
|
protected:
|
2013-07-19 06:24:14 +04:00
|
|
|
mozilla::ThreadSafeAutoRefCnt mRefCount;
|
2008-04-23 02:46:44 +04:00
|
|
|
|
2006-04-04 17:14:40 +04:00
|
|
|
public:
|
|
|
|
static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
|
|
|
|
const char *http_protocol_variant,
|
|
|
|
const char *path_and_query_string,
|
|
|
|
const char *http_request_method,
|
|
|
|
const PRIntervalTime timeout,
|
|
|
|
SEC_HTTP_REQUEST_SESSION *pRequest);
|
|
|
|
|
|
|
|
SECStatus setPostDataFcn(const char *http_data,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t http_data_len,
|
2006-04-04 17:14:40 +04:00
|
|
|
const char *http_content_type);
|
|
|
|
|
|
|
|
SECStatus addHeaderFcn(const char *http_header_name,
|
|
|
|
const char *http_header_value);
|
|
|
|
|
|
|
|
SECStatus trySendAndReceiveFcn(PRPollDesc **pPollDesc,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t *http_response_code,
|
2006-04-04 17:14:40 +04:00
|
|
|
const char **http_response_content_type,
|
|
|
|
const char **http_response_headers,
|
|
|
|
const char **http_response_data,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *http_response_data_len);
|
2006-04-04 17:14:40 +04:00
|
|
|
|
|
|
|
SECStatus cancelFcn();
|
|
|
|
SECStatus freeFcn();
|
|
|
|
|
2008-04-23 02:46:44 +04:00
|
|
|
void AddRef();
|
|
|
|
void Release();
|
|
|
|
|
2006-04-04 17:14:40 +04:00
|
|
|
nsCString mURL;
|
|
|
|
nsCString mRequestMethod;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool mHasPostData;
|
2006-04-04 17:14:40 +04:00
|
|
|
nsCString mPostData;
|
|
|
|
nsCString mPostContentType;
|
|
|
|
|
|
|
|
PRIntervalTime mTimeoutInterval;
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsHTTPListener> mListener;
|
2006-04-04 17:14:40 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
nsNSSHttpRequestSession();
|
|
|
|
~nsNSSHttpRequestSession();
|
2006-09-01 22:11:50 +04:00
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
SECStatus internal_send_receive_attempt(bool &retryable_error,
|
2006-09-01 22:11:50 +04:00
|
|
|
PRPollDesc **pPollDesc,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t *http_response_code,
|
2006-09-01 22:11:50 +04:00
|
|
|
const char **http_response_content_type,
|
|
|
|
const char **http_response_headers,
|
|
|
|
const char **http_response_data,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *http_response_data_len);
|
2006-04-04 17:14:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
class nsNSSHttpInterface
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
static SECStatus createSessionFcn(const char *host,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t portnum,
|
2006-04-04 17:14:40 +04:00
|
|
|
SEC_HTTP_SERVER_SESSION *pSession)
|
|
|
|
{
|
|
|
|
return nsNSSHttpServerSession::createSessionFcn(host, portnum, pSession);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus keepAliveFcn(SEC_HTTP_SERVER_SESSION session,
|
|
|
|
PRPollDesc **pPollDesc)
|
|
|
|
{
|
|
|
|
// Not yet implemented, however, Necko does transparent keep-alive
|
|
|
|
// anyway, when enabled in Necko's prefs.
|
|
|
|
return SECSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus freeSessionFcn(SEC_HTTP_SERVER_SESSION session)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
delete static_cast<nsNSSHttpServerSession*>(session);
|
2006-04-04 17:14:40 +04:00
|
|
|
return SECSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus createFcn(SEC_HTTP_SERVER_SESSION session,
|
|
|
|
const char *http_protocol_variant,
|
|
|
|
const char *path_and_query_string,
|
|
|
|
const char *http_request_method,
|
|
|
|
const PRIntervalTime timeout,
|
|
|
|
SEC_HTTP_REQUEST_SESSION *pRequest)
|
|
|
|
{
|
|
|
|
return nsNSSHttpRequestSession::createFcn(session, http_protocol_variant,
|
|
|
|
path_and_query_string, http_request_method,
|
|
|
|
timeout, pRequest);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus setPostDataFcn(SEC_HTTP_REQUEST_SESSION request,
|
|
|
|
const char *http_data,
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint32_t http_data_len,
|
2006-04-04 17:14:40 +04:00
|
|
|
const char *http_content_type)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsNSSHttpRequestSession*>(request)
|
2006-04-04 17:14:40 +04:00
|
|
|
->setPostDataFcn(http_data, http_data_len, http_content_type);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus addHeaderFcn(SEC_HTTP_REQUEST_SESSION request,
|
|
|
|
const char *http_header_name,
|
|
|
|
const char *http_header_value)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsNSSHttpRequestSession*>(request)
|
2006-04-04 17:14:40 +04:00
|
|
|
->addHeaderFcn(http_header_name, http_header_value);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus trySendAndReceiveFcn(SEC_HTTP_REQUEST_SESSION request,
|
|
|
|
PRPollDesc **pPollDesc,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint16_t *http_response_code,
|
2006-04-04 17:14:40 +04:00
|
|
|
const char **http_response_content_type,
|
|
|
|
const char **http_response_headers,
|
|
|
|
const char **http_response_data,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t *http_response_data_len)
|
2006-04-04 17:14:40 +04:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsNSSHttpRequestSession*>(request)
|
2006-04-04 17:14:40 +04:00
|
|
|
->trySendAndReceiveFcn(pPollDesc, http_response_code, http_response_content_type,
|
|
|
|
http_response_headers, http_response_data, http_response_data_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus cancelFcn(SEC_HTTP_REQUEST_SESSION request)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsNSSHttpRequestSession*>(request)
|
2006-04-04 17:14:40 +04:00
|
|
|
->cancelFcn();
|
|
|
|
}
|
|
|
|
|
|
|
|
static SECStatus freeFcn(SEC_HTTP_REQUEST_SESSION request)
|
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<nsNSSHttpRequestSession*>(request)
|
2006-04-04 17:14:40 +04:00
|
|
|
->freeFcn();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void initTable();
|
|
|
|
static SEC_HttpClientFcn sNSSInterfaceTable;
|
|
|
|
};
|
|
|
|
|
2001-01-19 04:12:10 +03:00
|
|
|
#endif // _NSNSSCALLBACKS_H_
|