Compare commits
10 Commits
PSM_GLUE_J
...
http11_tmp
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ff633f8d60 | ||
|
|
22361789fb | ||
|
|
9c456185f6 | ||
|
|
b36ebbf0e0 | ||
|
|
49f393c539 | ||
|
|
65fc46a090 | ||
|
|
28927614a1 | ||
|
|
0a0b6a0cd3 | ||
|
|
193207cbf5 | ||
|
|
4da7d69865 |
41
mozilla/extensions/datetime/Makefile.in
Normal file
41
mozilla/extensions/datetime/Makefile.in
Normal file
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = necko_datetime
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
nsDateTimeHandler.cpp \
|
||||
nsDateTimeChannel.cpp \
|
||||
nsDateTimeModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
333
mozilla/extensions/datetime/nsDateTimeChannel.cpp
Normal file
333
mozilla/extensions/datetime/nsDateTimeChannel.cpp
Normal file
@@ -0,0 +1,333 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
// datetime implementation
|
||||
|
||||
#include "nsDateTimeChannel.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
|
||||
// nsDateTimeChannel methods
|
||||
nsDateTimeChannel::nsDateTimeChannel() {
|
||||
NS_INIT_REFCNT();
|
||||
mContentLength = -1;
|
||||
mPort = -1;
|
||||
}
|
||||
|
||||
nsDateTimeChannel::~nsDateTimeChannel() {
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsDateTimeChannel, nsIChannel, nsIRequest, nsIStreamListener, nsIStreamObserver)
|
||||
|
||||
nsresult
|
||||
nsDateTimeChannel::Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
NS_ASSERTION(uri, "no uri");
|
||||
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mUrl = uri;
|
||||
|
||||
rv = mUrl->GetPort(&mPort);
|
||||
if (NS_FAILED(rv) || mPort < 1)
|
||||
mPort = DATETIME_PORT;
|
||||
|
||||
rv = mUrl->GetPath(getter_Copies(mHost));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsDateTimeChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
|
||||
{
|
||||
nsDateTimeChannel* dc = new nsDateTimeChannel();
|
||||
if (dc == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(dc);
|
||||
nsresult rv = dc->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(dc);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRequest methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::IsPending(PRBool *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Cancel(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Suspend(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::Resume(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mOriginalURI;
|
||||
NS_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mUrl;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = socketService->CreateTransport(mHost, mPort, mHost, 32, 32, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->OpenInputStream(startPosition, readCount, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = socketService->CreateTransport(mHost, mPort, mHost, 32, 32, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->AsyncOpen(observer, ctxt);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = socketService->CreateTransport(mHost, mPort, mHost, 32, 32, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mListener = aListener;
|
||||
|
||||
return channel->AsyncRead(startPosition, readCount, ctxt, this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetLoadAttributes(PRUint32 *aLoadAttributes)
|
||||
{
|
||||
*aLoadAttributes = mLoadAttributes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetLoadAttributes(PRUint32 aLoadAttributes)
|
||||
{
|
||||
mLoadAttributes = aLoadAttributes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#define DATETIME_TYPE "text/plain"
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetContentType(char* *aContentType) {
|
||||
if (!aContentType) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aContentType = nsCRT::strdup(DATETIME_TYPE);
|
||||
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetContentType(const char *aContentType)
|
||||
{
|
||||
//It doesn't make sense to set the content-type on this type
|
||||
// of channel...
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
{
|
||||
*aContentLength = mContentLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
*aLoadGroup = mLoadGroup;
|
||||
NS_IF_ADDREF(*aLoadGroup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
||||
{
|
||||
if (mLoadGroup) // if we already had a load group remove ourselves...
|
||||
(void)mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);
|
||||
|
||||
mLoadGroup = aLoadGroup;
|
||||
if (mLoadGroup) {
|
||||
return mLoadGroup->AddChannel(this, nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetOwner(nsISupports* *aOwner)
|
||||
{
|
||||
*aOwner = mOwner.get();
|
||||
NS_IF_ADDREF(*aOwner);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetOwner(nsISupports* aOwner)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
|
||||
{
|
||||
*aNotificationCallbacks = mCallbacks.get();
|
||||
NS_IF_ADDREF(*aNotificationCallbacks);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
|
||||
{
|
||||
mCallbacks = aNotificationCallbacks;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsIStreamObserver methods
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext) {
|
||||
return mListener->OnStartRequest(this, aContext);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OnStopRequest(nsIChannel* aChannel, nsISupports* aContext,
|
||||
nsresult aStatus, const PRUnichar* aMsg) {
|
||||
if (mLoadGroup) {
|
||||
nsresult rv = mLoadGroup->RemoveChannel(this, nsnull, aStatus, aMsg);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
return mListener->OnStopRequest(this, aContext, aStatus, aMsg);
|
||||
}
|
||||
|
||||
|
||||
// nsIStreamListener method
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeChannel::OnDataAvailable(nsIChannel* aChannel, nsISupports* aContext,
|
||||
nsIInputStream *aInputStream, PRUint32 aSourceOffset,
|
||||
PRUint32 aLength) {
|
||||
mContentLength = aLength;
|
||||
return mListener->OnDataAvailable(this, aContext, aInputStream, aSourceOffset, aLength);
|
||||
}
|
||||
|
||||
84
mozilla/extensions/datetime/nsDateTimeChannel.h
Normal file
84
mozilla/extensions/datetime/nsDateTimeChannel.h
Normal file
@@ -0,0 +1,84 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
// A datetime channel retrieves date time information from
|
||||
// RFC 867 compliant datetime servers. The date/time returned
|
||||
// to the caller is of MIME type "text/plain".
|
||||
|
||||
#ifndef nsDateTimeChannel_h___
|
||||
#define nsDateTimeChannel_h___
|
||||
|
||||
#include "nsString2.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsDateTimeHandler.h"
|
||||
#include "nsIStreamListener.h"
|
||||
|
||||
|
||||
class nsDateTimeChannel : public nsIChannel, public nsIStreamListener {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUEST
|
||||
NS_DECL_NSICHANNEL
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSISTREAMOBSERVER
|
||||
|
||||
// nsDateTimeChannel methods:
|
||||
nsDateTimeChannel();
|
||||
virtual ~nsDateTimeChannel();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
nsCOMPtr<nsIURI> mOriginalURI;
|
||||
nsCOMPtr<nsIURI> mUrl;
|
||||
nsCOMPtr<nsIStreamListener> mListener;
|
||||
PRUint32 mLoadAttributes;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCString mContentType;
|
||||
PRInt32 mContentLength;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
|
||||
PRInt32 mPort;
|
||||
nsXPIDLCString mHost;
|
||||
};
|
||||
|
||||
#endif /* nsDateTimeChannel_h___ */
|
||||
124
mozilla/extensions/datetime/nsDateTimeHandler.cpp
Normal file
124
mozilla/extensions/datetime/nsDateTimeHandler.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsDateTimeChannel.h"
|
||||
#include "nsDateTimeHandler.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
|
||||
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsDateTimeHandler::nsDateTimeHandler() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsDateTimeHandler::~nsDateTimeHandler() {
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsDateTimeHandler, NS_GET_IID(nsIProtocolHandler));
|
||||
|
||||
NS_METHOD
|
||||
nsDateTimeHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) {
|
||||
|
||||
nsDateTimeHandler* ph = new nsDateTimeHandler();
|
||||
if (ph == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(ph);
|
||||
nsresult rv = ph->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(ph);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIProtocolHandler methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeHandler::GetScheme(char* *result) {
|
||||
*result = nsCRT::strdup("datetime");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeHandler::GetDefaultPort(PRInt32 *result) {
|
||||
*result = DATETIME_PORT;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result) {
|
||||
nsresult rv;
|
||||
|
||||
// no concept of a relative datetime url
|
||||
NS_ASSERTION(!aBaseURI, "base url passed into datetime protocol handler");
|
||||
|
||||
nsIURI* url;
|
||||
rv = nsComponentManager::CreateInstance(kSimpleURICID, nsnull,
|
||||
NS_GET_IID(nsIURI),
|
||||
(void**)&url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->SetSpec((char*)aSpec);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = url;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsDateTimeHandler::NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsDateTimeChannel* channel;
|
||||
rv = nsDateTimeChannel::Create(nsnull, NS_GET_IID(nsIChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(verb, url, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = channel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
51
mozilla/extensions/datetime/nsDateTimeHandler.h
Normal file
51
mozilla/extensions/datetime/nsDateTimeHandler.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
// The datetime protocol handler creates "datetime" URIs of the form
|
||||
// "datetime:RFC867Server".
|
||||
|
||||
#ifndef nsDateTimeHandler_h___
|
||||
#define nsDateTimeHandler_h___
|
||||
|
||||
#include "nsIProtocolHandler.h"
|
||||
|
||||
#define DATETIME_PORT 13
|
||||
|
||||
// {AA27D2A0-B71B-11d3-A1A0-0050041CAF44}
|
||||
#define NS_DATETIMEHANDLER_CID \
|
||||
{ 0xaa27d2a0, 0xb71b, 0x11d3, { 0xa1, 0xa0, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } }
|
||||
|
||||
class nsDateTimeHandler : public nsIProtocolHandler
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPROTOCOLHANDLER
|
||||
|
||||
// nsDateTimeHandler methods:
|
||||
nsDateTimeHandler();
|
||||
virtual ~nsDateTimeHandler();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
};
|
||||
|
||||
#endif /* nsDateTimeHandler_h___ */
|
||||
34
mozilla/extensions/datetime/nsDateTimeModule.cpp
Normal file
34
mozilla/extensions/datetime/nsDateTimeModule.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsDateTimeHandler.h"
|
||||
|
||||
static nsModuleComponentInfo gResComponents[] = {
|
||||
{ "The DateTime Protocol Handler",
|
||||
NS_DATETIMEHANDLER_CID,
|
||||
NS_NETWORK_PROTOCOL_PROGID_PREFIX "datetime",
|
||||
nsDateTimeHandler::Create
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("datetime", gResComponents)
|
||||
41
mozilla/extensions/finger/Makefile.in
Normal file
41
mozilla/extensions/finger/Makefile.in
Normal file
@@ -0,0 +1,41 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = necko_finger
|
||||
IS_COMPONENT = 1
|
||||
|
||||
CPPSRCS = \
|
||||
nsFingerHandler.cpp \
|
||||
nsFingerChannel.cpp \
|
||||
nsFingerModule.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS += $(MOZ_COMPONENT_LIBS)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
423
mozilla/extensions/finger/nsFingerChannel.cpp
Normal file
423
mozilla/extensions/finger/nsFingerChannel.cpp
Normal file
@@ -0,0 +1,423 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
// finger implementation
|
||||
|
||||
#include "nsFingerChannel.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsIStringStream.h"
|
||||
#include "nsMimeTypes.h"
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
|
||||
#define BUFFER_SEG_SIZE (4*1024)
|
||||
#define BUFFER_MAX_SIZE (64*1024)
|
||||
|
||||
// nsFingerChannel methods
|
||||
nsFingerChannel::nsFingerChannel():
|
||||
mContentLength(-1),
|
||||
mActAsObserver(PR_TRUE),
|
||||
mPort(-1)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsFingerChannel::~nsFingerChannel() {
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsFingerChannel, nsIChannel, nsIRequest,
|
||||
nsIStreamListener, nsIStreamObserver)
|
||||
|
||||
nsresult
|
||||
nsFingerChannel::Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString autoBuffer;
|
||||
|
||||
NS_ASSERTION(uri, "no uri");
|
||||
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mUrl = uri;
|
||||
|
||||
rv = mUrl->GetPort(&mPort);
|
||||
if (NS_FAILED(rv) || mPort < 1)
|
||||
mPort = FINGER_PORT;
|
||||
|
||||
rv = mUrl->GetPath(getter_Copies(autoBuffer)); // autoBuffer = user@host
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCString cString(autoBuffer);
|
||||
nsCString tempBuf;
|
||||
|
||||
PRUint32 i;
|
||||
|
||||
// Now parse out the user and host
|
||||
for (i=0; cString[i] != '\0'; i++) {
|
||||
if (cString[i] == '@') {
|
||||
cString.Left(tempBuf, i);
|
||||
mUser = tempBuf;
|
||||
cString.Right(tempBuf, cString.Length() - i - 1);
|
||||
mHost = tempBuf;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Catch the case of just the host being given
|
||||
|
||||
if (cString[i] == '\0') {
|
||||
mHost = cString;
|
||||
}
|
||||
|
||||
#ifdef DEBUG_bryner
|
||||
printf("Status:mUser = %s, mHost = %s\n", (const char*)mUser,
|
||||
(const char*)mHost);
|
||||
#endif
|
||||
if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsFingerChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
|
||||
{
|
||||
nsFingerChannel* fc = new nsFingerChannel();
|
||||
if (fc == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(fc);
|
||||
nsresult rv = fc->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(fc);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRequest methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::IsPending(PRBool *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::Cancel(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::Suspend(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::Resume(void)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetOriginalURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mOriginalURI;
|
||||
NS_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
*aURI = mUrl;
|
||||
NS_IF_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = socketService->CreateTransport(mHost, mPort, mHost, BUFFER_SEG_SIZE,
|
||||
BUFFER_MAX_SIZE, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->OpenInputStream(startPosition, readCount, _retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = socketService->CreateTransport(mHost, mPort, mHost, BUFFER_SEG_SIZE,
|
||||
BUFFER_MAX_SIZE, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->AsyncOpen(observer, ctxt);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamListener *aListener)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = socketService->CreateTransport(mHost, mPort, mHost, BUFFER_SEG_SIZE,
|
||||
BUFFER_MAX_SIZE, getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mListener = aListener;
|
||||
|
||||
return SendRequest(channel);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::AsyncWrite(nsIInputStream *fromStream,
|
||||
PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports *ctxt,
|
||||
nsIStreamObserver *observer)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetLoadAttributes(PRUint32 *aLoadAttributes)
|
||||
{
|
||||
*aLoadAttributes = mLoadAttributes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetLoadAttributes(PRUint32 aLoadAttributes)
|
||||
{
|
||||
mLoadAttributes = aLoadAttributes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#define FINGER_TYPE TEXT_PLAIN
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetContentType(char* *aContentType) {
|
||||
if (!aContentType) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aContentType = nsCRT::strdup(FINGER_TYPE);
|
||||
if (!*aContentType) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetContentType(const char *aContentType)
|
||||
{
|
||||
//It doesn't make sense to set the content-type on this type
|
||||
// of channel...
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetContentLength(PRInt32 *aContentLength)
|
||||
{
|
||||
*aContentLength = mContentLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
*aLoadGroup = mLoadGroup;
|
||||
NS_IF_ADDREF(*aLoadGroup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
||||
{
|
||||
if (mLoadGroup) // if we already had a load group remove ourselves...
|
||||
(void)mLoadGroup->RemoveChannel(this, nsnull, nsnull, nsnull);
|
||||
|
||||
mLoadGroup = aLoadGroup;
|
||||
if (mLoadGroup) {
|
||||
return mLoadGroup->AddChannel(this, nsnull);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetOwner(nsISupports* *aOwner)
|
||||
{
|
||||
*aOwner = mOwner.get();
|
||||
NS_IF_ADDREF(*aOwner);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetOwner(nsISupports* aOwner)
|
||||
{
|
||||
mOwner = aOwner;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
|
||||
{
|
||||
*aNotificationCallbacks = mCallbacks.get();
|
||||
NS_IF_ADDREF(*aNotificationCallbacks);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
|
||||
{
|
||||
mCallbacks = aNotificationCallbacks;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
// nsIStreamObserver methods
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::OnStartRequest(nsIChannel *aChannel, nsISupports *aContext) {
|
||||
if (!mActAsObserver) {
|
||||
// acting as a listener
|
||||
return mListener->OnStartRequest(this, aContext);
|
||||
} else {
|
||||
// we don't want to pass our AsyncWrite's OnStart through
|
||||
// we just ignore this
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::OnStopRequest(nsIChannel* aChannel, nsISupports* aContext,
|
||||
nsresult aStatus, const PRUnichar* aMsg) {
|
||||
#ifdef DEBUG_bryner
|
||||
printf("nsFingerChannel::OnStopRequest, mActAsObserver=%d\n",
|
||||
mActAsObserver);
|
||||
printf(" aChannel = %p\n", aChannel);
|
||||
#endif
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!mActAsObserver) {
|
||||
if (mLoadGroup) {
|
||||
rv = mLoadGroup->RemoveChannel(this, nsnull, aStatus, aMsg);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
return mListener->OnStopRequest(this, aContext, aStatus, aMsg);
|
||||
} else {
|
||||
// at this point we know the request has been sent.
|
||||
// we're no longer acting as an observer.
|
||||
|
||||
mActAsObserver = PR_FALSE;
|
||||
return aChannel->AsyncRead(0, -1, 0, this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// nsIStreamListener method
|
||||
NS_IMETHODIMP
|
||||
nsFingerChannel::OnDataAvailable(nsIChannel* aChannel, nsISupports* aContext,
|
||||
nsIInputStream *aInputStream, PRUint32 aSourceOffset,
|
||||
PRUint32 aLength) {
|
||||
mContentLength = aLength;
|
||||
return mListener->OnDataAvailable(this, aContext, aInputStream, aSourceOffset, aLength);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsFingerChannel::SendRequest(nsIChannel* aChannel) {
|
||||
// The text to send should already be in mUser
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsISupports> result;
|
||||
nsCOMPtr<nsIInputStream> charstream;
|
||||
nsCString requestBuffer(mUser);
|
||||
|
||||
requestBuffer.Append(CRLF);
|
||||
|
||||
mRequest = requestBuffer.ToNewCString();
|
||||
|
||||
rv = NS_NewCharInputStream(getter_AddRefs(result), mRequest);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
charstream = do_QueryInterface(result, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
#ifdef DEBUG_bryner
|
||||
printf("Sending: %s\n", requestBuffer.GetBuffer());
|
||||
#endif
|
||||
|
||||
rv = aChannel->AsyncWrite(charstream, 0, requestBuffer.Length(), 0,
|
||||
this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
87
mozilla/extensions/finger/nsFingerChannel.h
Normal file
87
mozilla/extensions/finger/nsFingerChannel.h
Normal file
@@ -0,0 +1,87 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsFingerChannel_h___
|
||||
#define nsFingerChannel_h___
|
||||
|
||||
#include "nsString2.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsFingerHandler.h"
|
||||
#include "nsIStreamListener.h"
|
||||
|
||||
|
||||
class nsFingerChannel : public nsIChannel, public nsIStreamListener {
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUEST
|
||||
NS_DECL_NSICHANNEL
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSISTREAMOBSERVER
|
||||
|
||||
// nsFingerChannel methods:
|
||||
nsFingerChannel();
|
||||
virtual ~nsFingerChannel();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
|
||||
nsresult Init(const char* verb,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
nsCOMPtr<nsIURI> mOriginalURI;
|
||||
nsCOMPtr<nsIURI> mUrl;
|
||||
nsCOMPtr<nsIStreamListener> mListener;
|
||||
PRUint32 mLoadAttributes;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCString mContentType;
|
||||
PRInt32 mContentLength;
|
||||
nsCOMPtr<nsISupports> mOwner;
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
PRBool mActAsObserver;
|
||||
|
||||
PRInt32 mPort;
|
||||
nsXPIDLCString mHost;
|
||||
nsXPIDLCString mUser;
|
||||
|
||||
nsXPIDLCString mRequest;
|
||||
|
||||
protected:
|
||||
nsresult SendRequest(nsIChannel* aChannel);
|
||||
};
|
||||
|
||||
#endif /* nsFingerChannel_h___ */
|
||||
124
mozilla/extensions/finger/nsFingerHandler.cpp
Normal file
124
mozilla/extensions/finger/nsFingerHandler.cpp
Normal file
@@ -0,0 +1,124 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsFingerChannel.h"
|
||||
#include "nsFingerHandler.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIProgressEventSink.h"
|
||||
|
||||
static NS_DEFINE_CID(kSimpleURICID, NS_SIMPLEURI_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsFingerHandler::nsFingerHandler() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsFingerHandler::~nsFingerHandler() {
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsFingerHandler, NS_GET_IID(nsIProtocolHandler));
|
||||
|
||||
NS_METHOD
|
||||
nsFingerHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) {
|
||||
|
||||
nsFingerHandler* ph = new nsFingerHandler();
|
||||
if (ph == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(ph);
|
||||
nsresult rv = ph->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(ph);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIProtocolHandler methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerHandler::GetScheme(char* *result) {
|
||||
*result = nsCRT::strdup("finger");
|
||||
if (!*result) return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerHandler::GetDefaultPort(PRInt32 *result) {
|
||||
*result = FINGER_PORT;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result) {
|
||||
nsresult rv;
|
||||
|
||||
// no concept of a relative finger url
|
||||
NS_ASSERTION(!aBaseURI, "base url passed into finger protocol handler");
|
||||
|
||||
nsIURI* url;
|
||||
rv = nsComponentManager::CreateInstance(kSimpleURICID, nsnull,
|
||||
NS_GET_IID(nsIURI),
|
||||
(void**)&url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->SetSpec((char*)aSpec);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = url;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsFingerHandler::NewChannel(const char* verb, nsIURI* url,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsFingerChannel* channel;
|
||||
rv = nsFingerChannel::Create(nsnull, NS_GET_IID(nsIChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(verb, url, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = channel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
52
mozilla/extensions/finger/nsFingerHandler.h
Normal file
52
mozilla/extensions/finger/nsFingerHandler.h
Normal file
@@ -0,0 +1,52 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
// The finger protocol handler creates "finger" URIs of the form
|
||||
// "finger:user@host" or "finger:host".
|
||||
|
||||
#ifndef nsFingerHandler_h___
|
||||
#define nsFingerHandler_h___
|
||||
|
||||
#include "nsIProtocolHandler.h"
|
||||
|
||||
#define FINGER_PORT 79
|
||||
|
||||
// {0x76d6d5d8-1dd2-11b2-b361-850ddf15ef07}
|
||||
#define NS_FINGERHANDLER_CID \
|
||||
{ 0x76d6d5d8, 0x1dd2, 0x11b2, \
|
||||
{0xb3, 0x61, 0x85, 0x0d, 0xdf, 0x15, 0xef, 0x07} }
|
||||
|
||||
class nsFingerHandler : public nsIProtocolHandler
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPROTOCOLHANDLER
|
||||
|
||||
// nsFingerHandler methods:
|
||||
nsFingerHandler();
|
||||
virtual ~nsFingerHandler();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult);
|
||||
};
|
||||
|
||||
#endif /* nsFingerHandler_h___ */
|
||||
34
mozilla/extensions/finger/nsFingerModule.cpp
Normal file
34
mozilla/extensions/finger/nsFingerModule.cpp
Normal file
@@ -0,0 +1,34 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsFingerHandler.h"
|
||||
|
||||
static nsModuleComponentInfo gResComponents[] = {
|
||||
{ "The Finger Protocol Handler",
|
||||
NS_FINGERHANDLER_CID,
|
||||
NS_NETWORK_PROTOCOL_PROGID_PREFIX "finger",
|
||||
nsFingerHandler::Create
|
||||
}
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("finger", gResComponents)
|
||||
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
nsIPSMComponent.idl
|
||||
nsIPSMUIHandler.idl
|
||||
nsISecureBrowserUI.idl
|
||||
nsISSLSocketProvider.idl
|
||||
@@ -1,53 +0,0 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Hubbie Shaw
|
||||
# Doug Turner <dougt@netscape.com>
|
||||
# Terry Hayes <thayes@netscape.com>
|
||||
#
|
||||
|
||||
MODULE = psmglue
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DLLNAME = psmglue
|
||||
PDBFILE = $(DLLNAME).pdb
|
||||
MAPFILE = $(DLLNAME).map
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
XPIDL_INCLUDES=-I$(DEPTH)\..\mozilla\dist\idl
|
||||
|
||||
XPIDLSRCS= \
|
||||
.\nsIPSMComponent.idl \
|
||||
.\nsIPSMUIHandler.idl \
|
||||
.\nsISecureBrowserUI.idl \
|
||||
.\nsISSLSocketProvider.idl \
|
||||
.\nsIPSMSocketInfo.idl \
|
||||
.\nsISecretDecoderRing.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install::
|
||||
$(MAKE_INSTALL) .\psm-glue.js $(DIST)\bin\defaults\pref
|
||||
@@ -1,58 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
* Mitch Stoltz <mstoltz@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
interface nsIPrincipal;
|
||||
|
||||
%{C++
|
||||
#include "cmtcmn.h"
|
||||
%}
|
||||
|
||||
[ptr] native nsCMTControlStar(CMT_CONTROL);
|
||||
|
||||
[scriptable, uuid(9e482670-5412-11d3-bbc8-0000861d1237)]
|
||||
interface nsIPSMComponent : nsISupports
|
||||
{
|
||||
|
||||
[noscript] nsCMTControlStar getControlConnection( );
|
||||
|
||||
/**
|
||||
* Display the Security Advisor. PickledStatus and hostName can be null.
|
||||
* If they are, the "Selected Info" dialog will be empty.
|
||||
*/
|
||||
|
||||
void displaySecurityAdvisor(in string pickledStatus, in string hostName);
|
||||
|
||||
/**
|
||||
* This will send PSM all preferences that we know about.
|
||||
*/
|
||||
void passPrefs();
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define PSM_COMPONENT_PROGID "component://netscape/psm"
|
||||
#define PSM_COMPONENT_CLASSNAME "Mozilla PSM Component"
|
||||
%}
|
||||
|
||||
@@ -1,50 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
%{C++
|
||||
#include "cmtcmn.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
%}
|
||||
|
||||
[ptr] native psmtControlStar(CMT_CONTROL);
|
||||
[ptr] native cmSocketStar(CMSocket);
|
||||
[ptr] native nsFileDescStar(PRFileDesc);
|
||||
|
||||
[noscript, uuid(deeb8dfc-fb7a-11d3-ac84-00c04fa0d26b)]
|
||||
interface nsIPSMSocketInfo : nsISupports {
|
||||
|
||||
readonly attribute string hostName;
|
||||
readonly attribute PRInt32 hostPort;
|
||||
|
||||
readonly attribute string proxyName;
|
||||
readonly attribute PRInt32 proxyPort;
|
||||
|
||||
readonly attribute psmtControlStar controlPtr;
|
||||
readonly attribute cmSocketStar socketPtr;
|
||||
readonly attribute nsFileDescStar fileDescPtr;
|
||||
|
||||
void getPickledStatus(out charPtr pickledStatus);
|
||||
};
|
||||
|
||||
@@ -1,36 +0,0 @@
|
||||
/* -*- Mode: IDL; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Mozilla browser.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications, Inc. Portions created by Netscape are
|
||||
* Copyright (C) 1999, Mozilla. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(d92be9b0-601b-11d3-8c4a-000064657374)]
|
||||
interface nsIPSMUIHandler : nsISupports
|
||||
{
|
||||
void DisplayURI(in long width, in long height, in PRBool modal, in string urlStr);
|
||||
void PromptForFile(in wstring prompt, in string fileRegEx, in boolean shouldFileExist, out string outFile);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define PSM_UI_HANLDER_PROGID "component://netscape/psm/ui"
|
||||
#define PSM_UI_HANLDER_CLASSNAME "Mozilla PSM UI Handler"
|
||||
%}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* thayes@netscape.com
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/* Buffer type - for storing 8-bit octet values */
|
||||
[ptr] native buffer(unsigned char);
|
||||
|
||||
[scriptable, uuid(0EC80360-075C-11d4-9FD4-00C04F1B83D8)]
|
||||
interface nsISecretDecoderRing: nsISupports {
|
||||
|
||||
/* Encrypt a buffer - callable only from C++ */
|
||||
[noscript] long encrypt(in buffer data, in long dataLen, out buffer result);
|
||||
|
||||
/* Decrypt a buffer - callable only from C++ */
|
||||
[noscript] long decrypt(in buffer data, in long dataLen, out buffer result);
|
||||
|
||||
/* Encrypt nul-terminated string to BASE64 output */
|
||||
string encryptString(in string text);
|
||||
|
||||
/* Decrypt BASE64 input to nul-terminated string output */
|
||||
/* There is no check for embedded nul values in the decrypted output */
|
||||
string decryptString(in string crypt);
|
||||
|
||||
/* Prompt the user to change the password on the SDR key */
|
||||
void changePassword();
|
||||
|
||||
/* Logout of the security device that protects the SDR key */
|
||||
void logout();
|
||||
};
|
||||
|
||||
/*
|
||||
* Configuration interface for the Secret Decoder Ring
|
||||
* - this interface allows setting the window that will be
|
||||
* used as parent for dialog windows (such as password prompts)
|
||||
*/
|
||||
[scriptable, uuid(01D8C0F0-0CCC-11d4-9FDD-000064657374)]
|
||||
interface nsISecretDecoderRingConfig: nsISupports {
|
||||
void setWindow(in nsISupports w);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
pref("general.useragent.security", "U");
|
||||
|
||||
pref("security.enable_ssl2", true);
|
||||
pref("security.enable_ssl3", true);
|
||||
pref("security.default_personal_cert", "Select Automatically");
|
||||
pref("security.ask_for_password", 0);
|
||||
pref("security.password_lifetime", 30);
|
||||
pref("security.warn_entering_secure", true);
|
||||
pref("security.warn_leaving_secure", true);
|
||||
pref("security.warn_viewing_mixed", true);
|
||||
pref("security.warn_submit_insecure", true);
|
||||
@@ -1,3 +0,0 @@
|
||||
securityOverlay.xul
|
||||
securityUI.js
|
||||
PSMTaskMenu.xul
|
||||
@@ -1,22 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://communicator/locale/PSMTaskMenu.dtd" >
|
||||
|
||||
<overlay id="psmTaskMenuID"
|
||||
xmlns:html="http://www.w3.org/1999/xhtml"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script language="JavaScript">
|
||||
function displaySecurityAdvisor()
|
||||
{
|
||||
var psm = Components.classes["component://netscape/psm"].getService();
|
||||
psm = psm.QueryInterface(Components.interfaces.nsIPSMComponent);
|
||||
psm.displaySecurityAdvisor( null, null );
|
||||
}
|
||||
</script>
|
||||
|
||||
<menupopup id="personalManagers">
|
||||
<menuitem id="PSMMentItem" position="1" value="&PSMCmd.label;" oncommand="displaySecurityAdvisor()"/>
|
||||
</menupopup>
|
||||
|
||||
</overlay>
|
||||
@@ -1,14 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<?xml-stylesheet href="chrome://communicator/skin/securityOverlay.css" type="text/css"?>
|
||||
|
||||
<!DOCTYPE window SYSTEM "chrome://communicator/locale/securityOverlay.dtd">
|
||||
|
||||
<overlay id="NavSecurityOverlay"
|
||||
xmlns:html="http://www.w3.org/TR/REC-html40"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
|
||||
<script language="JavaScript" src="chrome://communicator/content/securityUI.js" />
|
||||
|
||||
<statusbarpanel id="security-button" onclick="displayPageInfo()" tooltip="aToolTip" tooltiptext="&lockIcon.label;"/>
|
||||
|
||||
</overlay>
|
||||
@@ -1,3 +0,0 @@
|
||||
PSMTaskMenu.dtd
|
||||
securityOverlay.dtd
|
||||
security.properties
|
||||
@@ -1 +0,0 @@
|
||||
<!ENTITY PSMCmd.label "Security Manager">
|
||||
@@ -1,29 +0,0 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
Title=Security Warning
|
||||
MixedContentMessage=You have requested a secure document that contains some insecure information.
|
||||
LeaveSiteMessage=You have requested an insecure document. The document and any information you send back could be observed by a third party while in transit.
|
||||
EnterSiteMessage=You have requested a secure document. The document and any information you send back are encrypted for privacy while in transit.
|
||||
PostToInsecure=Warning! Although this document is secure, the information you have submitted is insecure and could be observed by a third party while in transit. If you are submitting passwords, credit card numbers, or other information you would like to keep private, it would be safer for you to cancel the submission.
|
||||
PostToInsecureFromInsecure=Any information you submit is insecure and could be observed by a third party while in transit. If you are submitting passwords, credit card numbers, or other information you would like to keep private, it would be safer for you to cancel the submission.
|
||||
DontShowAgain=Show Me This Alert Next Time.
|
||||
FindText=Please find the Personal Security Manager application
|
||||
@@ -1,2 +0,0 @@
|
||||
|
||||
<!ENTITY lockIcon.label "Show security information for this window">
|
||||
@@ -1,72 +0,0 @@
|
||||
#!nmake
|
||||
#
|
||||
# The contents of this file are subject to the Mozilla Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/MPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Hubbie Shaw
|
||||
# Doug Turner <dougt@netscape.com>
|
||||
#
|
||||
|
||||
MODULE = psmglue
|
||||
|
||||
DEPTH=..\..\..
|
||||
IGNORE_MANIFEST=1
|
||||
|
||||
DLLNAME = psmglue
|
||||
PDBFILE = $(DLLNAME).pdb
|
||||
MAPFILE = $(DLLNAME).map
|
||||
DLL = .\$(OBJDIR)\$(DLLNAME).dll
|
||||
MAKE_OBJ_TYPE = DLL
|
||||
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
LINCS = $(LINCS) \
|
||||
-I$(PUBLIC) \
|
||||
-I$(PUBLIC)/security \
|
||||
$(NULL)
|
||||
|
||||
LLIBS = \
|
||||
$(LIBNSPR) \
|
||||
$(DIST)\lib\neckobase_s.lib \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\js3250.lib \
|
||||
$(DIST)\lib\cmt.lib \
|
||||
$(DIST)\lib\protocol.lib \
|
||||
$(DIST)\lib\mozreg.lib \
|
||||
$(DIST)\lib\jsdom.lib \
|
||||
$(NULL)
|
||||
|
||||
OBJS = \
|
||||
.\$(OBJDIR)\nsPSMMutex.obj \
|
||||
.\$(OBJDIR)\nsPSMShimLayer.obj \
|
||||
.\$(OBJDIR)\nsPSMComponent.obj \
|
||||
.\$(OBJDIR)\nsPSMUICallbacks.obj \
|
||||
.\$(OBJDIR)\nsPSMModule.obj \
|
||||
.\$(OBJDIR)\nsSecureBrowserUIImpl.obj \
|
||||
.\$(OBJDIR)\nsSSLIOLayer.obj \
|
||||
.\$(OBJDIR)\nsSSLSocketProvider.obj \
|
||||
.\$(OBJDIR)\nsSDR.obj \
|
||||
.\$(OBJDIR)\nsFSDR.obj \
|
||||
.\$(OBJDIR)\nsCrypto.obj \
|
||||
.\$(OBJDIR)\nsKeygenHandler.obj \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME).dll $(DIST)\bin\components
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,112 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#ifndef _nsCrypto_h_
|
||||
#define _nsCrypto_h_
|
||||
#include "nsIDOMCRMFObject.h"
|
||||
#include "nsIDOMCrypto.h"
|
||||
#include "nsIScriptObjectOwner.h"
|
||||
#include "nsIDOMPkcs11.h"
|
||||
|
||||
#define NS_CRYPTO_CLASSNAME "Crypto JavaScript Class"
|
||||
#define NS_CRYPTO_CID \
|
||||
{0x929d9320, 0x251e, 0x11d4, { 0x8a, 0x7c, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} }
|
||||
|
||||
#define NS_PKCS11_CLASSNAME "Pkcs11 JavaScript Class"
|
||||
#define NS_PKCS11_CID \
|
||||
{0x74b7a390, 0x3b41, 0x11d4, { 0x8a, 0x80, 0x00, 0x60, 0x08, 0xc8, 0x44, 0xc3} }
|
||||
|
||||
class nsIPSMComponent;
|
||||
class nsIDOMScriptObjectFactory;
|
||||
|
||||
|
||||
class nsCRMFObject : public nsIDOMCRMFObject,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
nsCRMFObject();
|
||||
virtual ~nsCRMFObject();
|
||||
NS_DECL_IDOMCRMFOBJECT
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
nsresult init();
|
||||
|
||||
nsresult SetCRMFRequest(char *inRequest);
|
||||
private:
|
||||
|
||||
nsString mBase64Request;
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
|
||||
class nsCrypto: public nsIDOMCrypto,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
nsCrypto();
|
||||
virtual ~nsCrypto();
|
||||
nsresult init();
|
||||
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IDOMCRYPTO
|
||||
|
||||
static nsresult GetScriptObjectFactory(nsIDOMScriptObjectFactory **aResult);
|
||||
static nsIDOMScriptObjectFactory *gScriptObjectFactory;
|
||||
static nsIPrincipal* GetScriptPrincipal(JSContext *cx);
|
||||
static const char *kPSMComponentProgID;
|
||||
|
||||
private:
|
||||
|
||||
nsIPSMComponent *mPSM;
|
||||
nsString mVersionString;
|
||||
PRBool mVersionStringSet;
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
class nsPkcs11 : public nsIDOMPkcs11,
|
||||
public nsIScriptObjectOwner {
|
||||
public:
|
||||
nsPkcs11();
|
||||
virtual ~nsPkcs11();
|
||||
|
||||
nsresult init();
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_IDOMPKCS11
|
||||
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
|
||||
NS_IMETHOD SetScriptObject(void* aScriptObject);
|
||||
|
||||
private:
|
||||
nsIPSMComponent *mPSM;
|
||||
void *mScriptObject;
|
||||
};
|
||||
|
||||
nsresult
|
||||
getPSMComponent(nsIPSMComponent ** retPSM);
|
||||
|
||||
#endif //_nsCrypto_h_
|
||||
|
||||
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,60 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Terry Hayes <thayes@netscape.com>
|
||||
* Steve Morse <morse@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSFSDR_H_
|
||||
#define _NSFSDR_H_
|
||||
|
||||
#include "nsISecretDecoderRing.h"
|
||||
|
||||
// ===============================================
|
||||
// nsFSecretDecoderRing - "fake" implementation of nsISecretDecoderRing
|
||||
// ===============================================
|
||||
|
||||
#define NS_FSDR_CLASSNAME "Fake Secret Decoder Ring"
|
||||
#define NS_FSDR_CID \
|
||||
{ 0x1ee28720, 0x2b93, 0x11d4, { 0xa0, 0xa4, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
|
||||
#define NS_FSDR_PROGID "netscape.security.fsdr"
|
||||
|
||||
class nsFSecretDecoderRing : public nsISecretDecoderRing
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISECRETDECODERRING
|
||||
|
||||
nsFSecretDecoderRing();
|
||||
virtual ~nsFSecretDecoderRing();
|
||||
|
||||
nsresult init();
|
||||
|
||||
private:
|
||||
nsIPSMComponent *mPSM;
|
||||
|
||||
static const char *kPSMComponentProgID;
|
||||
|
||||
nsresult encode(const unsigned char *data, PRInt32 dataLen, char **_retval);
|
||||
nsresult decode(const char *data, unsigned char **result, PRInt32 * _retval);
|
||||
};
|
||||
|
||||
#endif /* _NSFSDR_H_ */
|
||||
@@ -1,255 +0,0 @@
|
||||
//For some weird reason, nsProxiedService has to be the first file
|
||||
//included. Don't ask me, I'm just the messenger.
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsKeygenHandler.h"
|
||||
#include "nsVoidArray.h"
|
||||
#include "nsSecureBrowserUIImpl.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIDOMHTMLSelectElement.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsIPSMUIHandler.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "nsCrypto.h"
|
||||
#include "cmtcmn.h"
|
||||
#include "cmtjs.h"
|
||||
|
||||
//These defines are taken from the PKCS#11 spec
|
||||
#define CKM_RSA_PKCS_KEY_PAIR_GEN 0x00000000
|
||||
#define CKM_DH_PKCS_KEY_PAIR_GEN 0x00000020
|
||||
#define CKM_DSA_KEY_PAIR_GEN 0x00000010
|
||||
|
||||
static NS_DEFINE_IID(kFormProcessorIID, NS_IFORMPROCESSOR_IID);
|
||||
static NS_DEFINE_IID(kIDOMHTMLSelectElementIID, NS_IDOMHTMLSELECTELEMENT_IID);
|
||||
|
||||
static const char *mozKeyGen = "-mozilla-keygen";
|
||||
|
||||
NS_IMPL_ADDREF(nsKeygenFormProcessor);
|
||||
NS_IMPL_RELEASE(nsKeygenFormProcessor);
|
||||
NS_IMPL_QUERY_INTERFACE(nsKeygenFormProcessor, kFormProcessorIID);
|
||||
|
||||
nsKeygenFormProcessor::nsKeygenFormProcessor()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
getPSMComponent(&mPSM);
|
||||
}
|
||||
|
||||
char *
|
||||
nsKeygenFormProcessor::ChooseToken(PCMT_CONTROL control,
|
||||
CMKeyGenTagArg *psmarg,
|
||||
CMKeyGenTagReq *reason)
|
||||
{
|
||||
CMUint32 resID;
|
||||
CMTStatus crv;
|
||||
CMTItem url;
|
||||
char *keyString = nsnull;
|
||||
nsresult rv = NS_OK;
|
||||
NameList *tokenNames;
|
||||
int i;
|
||||
|
||||
// In this case, PSM provided us with a list of potential tokens to choose
|
||||
// from, but we're gonna make it use it's UI for now, so let's delte the
|
||||
// memory associated with the structure it sent back.
|
||||
tokenNames = (NameList*)psmarg->current;
|
||||
for (i=0; i < tokenNames->numitems; i++) {
|
||||
nsCRT::free(tokenNames->names[i]);
|
||||
}
|
||||
nsCRT::free((char*)tokenNames);
|
||||
resID = psmarg->rid;
|
||||
memset(&url, 0, sizeof(CMTItem));
|
||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
||||
crv = CMT_GetStringAttribute(control, resID, SSM_FID_CHOOSE_TOKEN_URL, &url);
|
||||
if (crv != CMTSuccess) {
|
||||
goto loser;
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
handler->DisplayURI(400, 300, PR_TRUE, (char*)url.data);
|
||||
} else {
|
||||
goto loser;
|
||||
}
|
||||
return CMT_GetGenKeyResponse(control, psmarg, reason);
|
||||
loser:
|
||||
if (keyString)
|
||||
nsCRT::free(keyString);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
char *
|
||||
nsKeygenFormProcessor::SetUserPassword(PCMT_CONTROL control,
|
||||
CMKeyGenTagArg *psmarg,
|
||||
CMKeyGenTagReq *reason)
|
||||
{
|
||||
nsresult rv;
|
||||
CMTStatus crv;
|
||||
CMTItem url;
|
||||
char *keystring=nsnull;
|
||||
|
||||
// We need to delete the memory the PSM client API allocated for us since
|
||||
// we're just gonna tell it to use it's own UI.
|
||||
nsCRT::free((char*)psmarg->current);
|
||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
||||
memset (&url, 0, sizeof(CMTItem));
|
||||
crv = CMT_GetStringAttribute(control,psmarg->rid, SSM_FID_INIT_DB_URL, &url);
|
||||
if (crv != CMTSuccess || NS_FAILED(rv)){
|
||||
goto loser;
|
||||
}
|
||||
|
||||
handler->DisplayURI(500, 450, PR_TRUE, (char*)url.data);
|
||||
|
||||
return CMT_GetGenKeyResponse(control, psmarg, reason);
|
||||
loser:
|
||||
if (keystring)
|
||||
nsCRT::free(keystring);
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsKeygenFormProcessor::GetPublicKey(nsString& value, nsString& challenge,
|
||||
nsString& keyType,
|
||||
nsString& outPublicKey, nsString& pqg)
|
||||
{
|
||||
PCMT_CONTROL control;
|
||||
nsresult rv;
|
||||
CMKeyGenParams *params = nsnull;
|
||||
CMKeyGenTagArg *psmarg = nsnull;
|
||||
CMKeyGenTagReq reason;
|
||||
char *emptyCString = "null";
|
||||
char *keystring = nsnull;
|
||||
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (NS_FAILED(rv)) {
|
||||
goto loser;
|
||||
}
|
||||
params = new CMKeyGenParams;
|
||||
if (params == nsnull) {
|
||||
goto loser;
|
||||
}
|
||||
params->typeString = (keyType.IsEmpty()) ? emptyCString :
|
||||
keyType.ToNewCString();
|
||||
params->challenge = (challenge.IsEmpty()) ? emptyCString :
|
||||
challenge.ToNewCString();
|
||||
params->choiceString = value.ToNewCString();
|
||||
params->pqgString = (pqg.IsEmpty()) ? emptyCString : pqg.ToNewCString();
|
||||
psmarg = new CMKeyGenTagArg;
|
||||
if (psmarg == nsnull) {
|
||||
goto loser;
|
||||
}
|
||||
// ARGH, while this is going on, we need to lock the control
|
||||
// connection so that the event loop doesn't drop our response on
|
||||
// the floor.
|
||||
CMT_LockConnection(control);
|
||||
psmarg->op = CM_KEYGEN_START;
|
||||
psmarg->rid = 0;
|
||||
psmarg->tokenName = NULL;
|
||||
psmarg->current = params;
|
||||
keystring = CMT_GenKeyOldStyle(control, psmarg, &reason);
|
||||
while (!keystring) {
|
||||
psmarg->op = reason;
|
||||
switch (psmarg->op) {
|
||||
case CM_KEYGEN_PICK_TOKEN:
|
||||
keystring = ChooseToken(control, psmarg, &reason);
|
||||
break;
|
||||
case CM_KEYGEN_SET_PASSWORD:
|
||||
keystring = SetUserPassword(control, psmarg, &reason);
|
||||
break;
|
||||
case CM_KEYGEN_ERR:
|
||||
default:
|
||||
goto loser;
|
||||
}
|
||||
}
|
||||
CMT_UnlockConnection(control);
|
||||
outPublicKey.AssignWithConversion(keystring);
|
||||
nsCRT::free(keystring);
|
||||
return NS_OK;
|
||||
loser:
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsKeygenFormProcessor::ProcessValue(nsIDOMHTMLElement *aElement,
|
||||
const nsString& aName,
|
||||
nsString& aValue)
|
||||
{
|
||||
#ifdef DEBUG_javi
|
||||
char *name = aName.ToNewCString();
|
||||
char *value = aValue.ToNewCString();
|
||||
printf("ProcessValue: name %s value %s\n", name, value);
|
||||
delete [] name;
|
||||
delete [] value;
|
||||
#endif
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr<nsIDOMHTMLSelectElement>selectElement;
|
||||
nsresult res = aElement->QueryInterface(kIDOMHTMLSelectElementIID,
|
||||
getter_AddRefs(selectElement));
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
nsAutoString keygenvalue;
|
||||
nsAutoString challengeValue;
|
||||
nsString publicKey;
|
||||
nsString mozillaKeygen;
|
||||
nsString mozType;
|
||||
|
||||
mozType.AssignWithConversion("_moz-type");
|
||||
mozillaKeygen.AssignWithConversion(mozKeyGen);
|
||||
res = selectElement->GetAttribute(mozType, keygenvalue);
|
||||
|
||||
if (NS_CONTENT_ATTR_HAS_VALUE == res && keygenvalue.Equals(mozillaKeygen)) {
|
||||
nsString challenge;
|
||||
nsString keyType;
|
||||
nsString keyTypeValue;
|
||||
nsString pqg, pqgValue;
|
||||
|
||||
challenge.AssignWithConversion("challenge");
|
||||
pqg.AssignWithConversion("pqg");
|
||||
res = selectElement->GetAttribute(pqg, pqgValue);
|
||||
keyType.AssignWithConversion("keytype");
|
||||
res = selectElement->GetAttribute(keyType, keyTypeValue);
|
||||
if (NS_FAILED(res) || keyTypeValue.IsEmpty()) {
|
||||
// If this field is not present, we default to rsa.
|
||||
keyTypeValue.AssignWithConversion("rsa");
|
||||
}
|
||||
res = selectElement->GetAttribute(challenge, challengeValue);
|
||||
rv = GetPublicKey(aValue, challenge, keyTypeValue,
|
||||
publicKey, pqgValue);
|
||||
aValue = publicKey;
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD nsKeygenFormProcessor::ProvideContent(const nsString& aFormType,
|
||||
nsVoidArray& aContent,
|
||||
nsString& aAttribute)
|
||||
{
|
||||
nsString selectString;
|
||||
nsresult rv;
|
||||
PCMT_CONTROL control;
|
||||
PRUint32 i;
|
||||
|
||||
selectString.AssignWithConversion("SELECT");
|
||||
if (aFormType.EqualsIgnoreCase(selectString)) {
|
||||
nsString *selectString;
|
||||
char **result;
|
||||
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (NS_FAILED(rv)) {
|
||||
goto loser;
|
||||
}
|
||||
result = CMT_GetKeyChoiceList(control, "rsa"/*Need to figure out if DSA*/,
|
||||
nsnull);
|
||||
for (i=0; result[i] != nsnull; i++) {
|
||||
selectString = new nsString;
|
||||
selectString->AssignWithConversion(result[i]);
|
||||
aContent.AppendElement(selectString);
|
||||
delete []result[i];
|
||||
}
|
||||
delete []result;
|
||||
aAttribute.AssignWithConversion(mozKeyGen);
|
||||
}
|
||||
return NS_OK;
|
||||
loser:
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
#ifndef _NSKEYGENHANDLER_H_
|
||||
#define _NSKEYGENHANDLER_H_
|
||||
// Form Processor
|
||||
#include "nsIFormProcessor.h"
|
||||
#include "ssmdefs.h"
|
||||
#include "cmtcmn.h"
|
||||
|
||||
class nsIPSMComponent;
|
||||
|
||||
class nsKeygenFormProcessor : public nsIFormProcessor {
|
||||
public:
|
||||
nsKeygenFormProcessor();
|
||||
NS_IMETHOD ProcessValue(nsIDOMHTMLElement *aElement,
|
||||
const nsString& aName,
|
||||
nsString& aValue);
|
||||
|
||||
NS_IMETHOD ProvideContent(const nsString& aFormType,
|
||||
nsVoidArray& aContent,
|
||||
nsString& aAttribute);
|
||||
NS_DECL_ISUPPORTS
|
||||
protected:
|
||||
nsresult GetPublicKey(nsString& value, nsString& challenge,
|
||||
nsString& keyType, nsString& outPublicKey,
|
||||
nsString& pqg);
|
||||
char * ChooseToken(PCMT_CONTROL control, CMKeyGenTagArg *psmarg,
|
||||
CMKeyGenTagReq *reason);
|
||||
char * SetUserPassword(PCMT_CONTROL control, CMKeyGenTagArg *psmarg,
|
||||
CMKeyGenTagReq *reason);
|
||||
nsIPSMComponent *mPSM;
|
||||
};
|
||||
|
||||
#endif //_NSKEYGENHANDLER_H_
|
||||
@@ -1,935 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
* Mitch Stoltz <mstoltz@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "VerReg.h"
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsPSMComponent.h"
|
||||
|
||||
#include "nsCRT.h"
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIStreamListener.h"
|
||||
|
||||
#include "nsIPref.h"
|
||||
#include "nsIProfile.h"
|
||||
#include "nsILocalFile.h"
|
||||
|
||||
#include "nsDirectoryService.h"
|
||||
|
||||
#include "rsrcids.h"
|
||||
|
||||
#include "nsPSMMutex.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
#include "nsICertificatePrincipal.h"
|
||||
|
||||
#include "nsIProtocolProxyService.h"
|
||||
|
||||
#define PSM_VERSION_REG_KEY "/Netscape/Personal Security Manager"
|
||||
|
||||
#ifdef WIN32
|
||||
#define PSM_FILE_NAME "psm.exe"
|
||||
#elif XP_UNIX
|
||||
#define PSM_FILE_NAME "start-psm"
|
||||
#else
|
||||
#define PSM_FILE_NAME "psm"
|
||||
#endif
|
||||
|
||||
|
||||
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
static NS_DEFINE_CID(kProfileCID, NS_PROFILE_CID);
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kProtocolProxyServiceCID, NS_PROTOCOLPROXYSERVICE_CID);
|
||||
|
||||
nsPSMComponent* nsPSMComponent::mInstance = nsnull;
|
||||
|
||||
nsPSMComponent::nsPSMComponent()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mControl = nsnull;
|
||||
}
|
||||
|
||||
nsPSMComponent::~nsPSMComponent()
|
||||
{
|
||||
if (mControl)
|
||||
{
|
||||
CMT_CloseControlConnection(mControl);
|
||||
mControl = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::CreatePSMComponent(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (!aResult) {
|
||||
return NS_ERROR_INVALID_POINTER;
|
||||
}
|
||||
if (aOuter) {
|
||||
*aResult = nsnull;
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
if (mInstance == nsnull)
|
||||
{
|
||||
mInstance = new nsPSMComponent();
|
||||
}
|
||||
|
||||
if (mInstance == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsresult rv = mInstance->QueryInterface(aIID, aResult);
|
||||
if (NS_FAILED(rv))
|
||||
{
|
||||
*aResult = nsnull;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* nsISupports Implementation for the class */
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS3(nsPSMComponent,
|
||||
nsIPSMComponent,
|
||||
nsIContentHandler,
|
||||
nsISignatureVerifier);
|
||||
|
||||
#define INIT_NUM_PREFS 100
|
||||
/* preference types */
|
||||
#define STRING_PREF 0
|
||||
#define BOOL_PREF 1
|
||||
#define INT_PREF 2
|
||||
|
||||
|
||||
/* resizable list struct that contains pref items */
|
||||
typedef struct CMSetPrefList {
|
||||
int n; /* number of filled items */
|
||||
int capacity; /* allocated memory */
|
||||
CMTSetPrefElement* list; /* actual list */
|
||||
} CMSetPrefList;
|
||||
|
||||
static void get_pack_bool_pref(nsIPref *prefManager, char* key, CMTSetPrefElement* list, int* n)
|
||||
{
|
||||
PRBool boolpref;
|
||||
|
||||
list[*n].key = nsCRT::strdup(key);
|
||||
list[*n].type = BOOL_PREF;
|
||||
|
||||
if ((prefManager->GetBoolPref(key, &boolpref) != 0) || boolpref)
|
||||
{
|
||||
list[*n].value = nsCRT::strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
list[*n].value = nsCRT::strdup("false");
|
||||
}
|
||||
|
||||
(*n)++; /* increment the counter after done packing */
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
static void SaveAllPrefs(int number, CMTSetPrefElement* list)
|
||||
{
|
||||
nsCOMPtr<nsIPref> prefManager;
|
||||
|
||||
nsresult res = nsServiceManager::GetService(kPrefCID,
|
||||
nsIPref::GetIID(),
|
||||
getter_AddRefs(prefManager));
|
||||
|
||||
if (NS_FAILED(res) || !prefManager)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
int i;
|
||||
int intval;
|
||||
|
||||
for (i = 0; i < number; i++)
|
||||
{
|
||||
if (list[i].key == nsnull)
|
||||
{
|
||||
/* misconfigured item: next */
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (list[i].type)
|
||||
{
|
||||
case 0: /* string type */
|
||||
prefManager->SetCharPref(list[i].key, list[i].value);
|
||||
break;
|
||||
case 1: /* boolean type */
|
||||
if (strcmp(list[i].value, "true") == 0) {
|
||||
prefManager->SetBoolPref(list[i].key, (PRBool)1);
|
||||
}
|
||||
else if (strcmp(list[i].value, "false") == 0) {
|
||||
prefManager->SetBoolPref(list[i].key, (PRBool)0);
|
||||
}
|
||||
break;
|
||||
case 2:
|
||||
intval = atoi(list[i].value);
|
||||
prefManager->SetIntPref(list[i].key, intval);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::PassPrefs()
|
||||
{
|
||||
// if we have not passed anything to psm yet, this function can just return.
|
||||
|
||||
if (!mControl)
|
||||
return NS_OK;
|
||||
|
||||
int i;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
char* strpref = NULL;
|
||||
int intpref;
|
||||
PRBool boolpref;
|
||||
CMSetPrefList prefs = {0};
|
||||
CMTSetPrefElement* list = NULL;
|
||||
|
||||
char* pickAuto = "Select Automatically";
|
||||
char* alwaysAsk = "Ask Every Time";
|
||||
|
||||
nsCOMPtr<nsIPref> prefManager;
|
||||
|
||||
nsresult res = nsServiceManager::GetService(kPrefCID,
|
||||
nsIPref::GetIID(),
|
||||
getter_AddRefs(prefManager));
|
||||
|
||||
if (NS_OK != res)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
/* allocate memory for list */
|
||||
prefs.n = 0; /* counter */
|
||||
prefs.capacity = INIT_NUM_PREFS;
|
||||
prefs.list = (CMTSetPrefElement*) new char[(INIT_NUM_PREFS * sizeof(CMTSetPrefElement))];
|
||||
|
||||
if (prefs.list == NULL)
|
||||
{
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* shorthand */
|
||||
list = prefs.list;
|
||||
|
||||
/* get preferences */
|
||||
get_pack_bool_pref(prefManager, "security.enable_ssl2", (CMTSetPrefElement*)list, &(prefs.n));
|
||||
get_pack_bool_pref(prefManager, "security.enable_ssl3", (CMTSetPrefElement*)list, &(prefs.n));
|
||||
|
||||
/* this pref is a boolean pref in nature but a string pref for
|
||||
* historical reason
|
||||
*/
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.default_personal_cert");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
|
||||
if ((prefManager->CopyCharPref(list[prefs.n].key, &strpref) == 0) && (strcmp(strpref, pickAuto) == 0))
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup(pickAuto);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* although one could choose a specific cert for client auth in
|
||||
* Nova, that mode is deprecated with PSM and mapped to ASK
|
||||
*/
|
||||
list[prefs.n].value = nsCRT::strdup(alwaysAsk);
|
||||
}
|
||||
|
||||
prefs.n++;
|
||||
if (strpref != NULL)
|
||||
{
|
||||
nsCRT::free(strpref);
|
||||
}
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.default_mail_cert");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
if (prefManager->CopyCharPref(list[prefs.n].key, &list[prefs.n].value) != 0)
|
||||
{
|
||||
list[prefs.n].value = NULL;
|
||||
}
|
||||
prefs.n++;
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.ask_for_password");
|
||||
list[prefs.n].type = INT_PREF;
|
||||
if (prefManager->GetIntPref(list[prefs.n].key, &intpref) != 0)
|
||||
{
|
||||
intpref = 0; /* default */
|
||||
}
|
||||
|
||||
list[prefs.n].value = PR_smprintf("%d", intpref);
|
||||
prefs.n++;
|
||||
|
||||
list[prefs.n].key = nsCRT::strdup("security.password_lifetime");
|
||||
list[prefs.n].type = INT_PREF;
|
||||
if (prefManager->GetIntPref(list[prefs.n].key, &intpref) != 0)
|
||||
{
|
||||
intpref = 30; /* default */
|
||||
}
|
||||
|
||||
list[prefs.n].value = PR_smprintf("%d", intpref);
|
||||
prefs.n++;
|
||||
|
||||
/* OCSP preferences */
|
||||
/* XXX since these are the new ones added by PSM, we will be more
|
||||
* error-tolerant in fetching them
|
||||
*/
|
||||
if (prefManager->GetBoolPref("security.OCSP.enabled", &boolpref) == 0)
|
||||
{
|
||||
if (boolpref)
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("false");
|
||||
}
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.enabled");
|
||||
list[prefs.n].type = BOOL_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
if (prefManager->GetBoolPref("security.OCSP.useDefaultResponder", &boolpref) == 0)
|
||||
{
|
||||
if (boolpref)
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("true");
|
||||
}
|
||||
else
|
||||
{
|
||||
list[prefs.n].value = nsCRT::strdup("false");
|
||||
}
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.useDefaultResponder");
|
||||
list[prefs.n].type = BOOL_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
if (prefManager->CopyCharPref("security.OCSP.URL", &strpref) == 0)
|
||||
{
|
||||
list[prefs.n].value = strpref;
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.URL");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
if (prefManager->CopyCharPref("security.OCSP.signingCA", &strpref) == 0)
|
||||
{
|
||||
list[prefs.n].value = strpref;
|
||||
list[prefs.n].key = nsCRT::strdup("security.OCSP.signingCA");
|
||||
list[prefs.n].type = STRING_PREF;
|
||||
prefs.n++;
|
||||
}
|
||||
|
||||
/* now application-specific preferences */
|
||||
/* get navigator preferences */
|
||||
get_pack_bool_pref(prefManager, "security.warn_entering_secure", (CMTSetPrefElement*)list, &prefs.n);
|
||||
get_pack_bool_pref(prefManager, "security.warn_leaving_secure", (CMTSetPrefElement*)list, &prefs.n);
|
||||
get_pack_bool_pref(prefManager, "security.warn_viewing_mixed", (CMTSetPrefElement*)list, &prefs.n);
|
||||
get_pack_bool_pref(prefManager, "security.warn_submit_insecure", (CMTSetPrefElement*)list, &prefs.n);
|
||||
|
||||
// Add any other prefs here such as ldap or mail/news.
|
||||
|
||||
CMT_SetSavePrefsCallback(mControl, (savePrefsCallback_fn)SaveAllPrefs);
|
||||
|
||||
if (CMT_PassAllPrefs(mControl, prefs.n, (CMTSetPrefElement*)prefs.list) != CMTSuccess)
|
||||
{
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = NS_OK; /* success */
|
||||
loser:
|
||||
/* clean out memory for prefs */
|
||||
for (i = 0; i < prefs.n; i++)
|
||||
{
|
||||
if (prefs.list[i].key != NULL)
|
||||
{
|
||||
nsCRT::free(prefs.list[i].key);
|
||||
}
|
||||
|
||||
if (prefs.list[i].value != NULL)
|
||||
{
|
||||
nsCRT::free(prefs.list[i].value);
|
||||
}
|
||||
}
|
||||
|
||||
if (prefs.list != NULL)
|
||||
{
|
||||
delete(prefs.list);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
#ifdef XP_MAC
|
||||
extern "C" {
|
||||
void RunMacPSM(void* arg);
|
||||
PRThread* SSM_CreateAndRegisterThread(PRThreadType type, void (*start)(void *arg),
|
||||
void *arg, PRThreadPriority priority,
|
||||
PRThreadScope scope, PRThreadState state,
|
||||
PRUint32 stackSize);
|
||||
void SSM_KillAllThreads(void);
|
||||
}
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::GetControlConnection( CMT_CONTROL * *_retval )
|
||||
{
|
||||
nsresult rv;
|
||||
*_retval = nsnull;
|
||||
if (mControl)
|
||||
{
|
||||
*_retval = mControl;
|
||||
return NS_OK;
|
||||
}
|
||||
else /* initialize mutex, sock table, etc. */
|
||||
{
|
||||
|
||||
if (nsPSMMutexInit() != PR_SUCCESS)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
#ifdef XP_MAC
|
||||
/* FIXME: Really need better error handling in PSM, which simply exits on error. */
|
||||
/* use a cached monitor to rendezvous with the PSM thread. */
|
||||
PRMonitor* monitor = PR_CEnterMonitor(this);
|
||||
if (monitor != nsnull) {
|
||||
/* create the Cartman thread, and let it run awhile to get things going. */
|
||||
PRThread* cartmanThread = SSM_CreateAndRegisterThread(PR_USER_THREAD, RunMacPSM,
|
||||
this, PR_PRIORITY_NORMAL,
|
||||
PR_LOCAL_THREAD, PR_UNJOINABLE_THREAD, 0);
|
||||
if (cartmanThread != nsnull) {
|
||||
/* need a good way to rendezvouz with the Cartman thread. */
|
||||
PR_CWait(this, PR_INTERVAL_NO_TIMEOUT);
|
||||
}
|
||||
|
||||
PR_CExitMonitor(this);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Try to see if it is open already
|
||||
mControl = CMT_ControlConnect(&nsPSMMutexTbl, &nsPSMShimTbl);
|
||||
|
||||
// Find the one in the bin directory
|
||||
if (mControl == nsnull)
|
||||
{
|
||||
nsCOMPtr<nsILocalFile> psmAppFile;
|
||||
NS_WITH_SERVICE(nsIProperties, directoryService, NS_DIRECTORY_SERVICE_PROGID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
directoryService->Get("system.OS_CurrentProcessDirectory",
|
||||
NS_GET_IID(nsIFile),
|
||||
getter_AddRefs(psmAppFile));
|
||||
|
||||
|
||||
psmAppFile->Append("psm");
|
||||
psmAppFile->Append(PSM_FILE_NAME);
|
||||
|
||||
PRBool isExecutable, exists;
|
||||
psmAppFile->Exists(&exists);
|
||||
psmAppFile->IsExecutable(&isExecutable);
|
||||
if (exists && isExecutable)
|
||||
{
|
||||
nsXPIDLCString path;
|
||||
psmAppFile->GetPath(getter_Copies(path));
|
||||
// FIX THIS. using a file path is totally wrong here.
|
||||
mControl = CMT_EstablishControlConnection((char*)(const char*)path, &nsPSMShimTbl, &nsPSMMutexTbl);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the one in the version registry
|
||||
if (mControl == nsnull)
|
||||
{
|
||||
//Try to find it.
|
||||
int err;
|
||||
char filepath[MAXREGPATHLEN];
|
||||
|
||||
err = VR_GetPath(PSM_VERSION_REG_KEY, sizeof(filepath), filepath);
|
||||
if ( err == REGERR_OK )
|
||||
{
|
||||
nsFileSpec psmSpec(filepath);
|
||||
psmSpec += PSM_FILE_NAME;
|
||||
|
||||
if (psmSpec.Exists())
|
||||
{
|
||||
mControl = CMT_EstablishControlConnection((char *)psmSpec.GetNativePathCString(), &nsPSMShimTbl, &nsPSMMutexTbl);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (!mControl || InitPSMUICallbacks(mControl) != PR_SUCCESS)
|
||||
goto failure;
|
||||
|
||||
nsFileSpec profileSpec;
|
||||
PRUnichar* profileName;
|
||||
|
||||
NS_WITH_SERVICE(nsIProfile, profile, kProfileCID, &rv);
|
||||
if (NS_FAILED(rv)) goto failure;
|
||||
|
||||
rv = profile->GetCurrentProfileDir(&profileSpec);
|
||||
if (NS_FAILED(rv)) goto failure;;
|
||||
|
||||
#ifdef XP_MAC
|
||||
profileSpec += "Security";
|
||||
// make sure the dir exists
|
||||
profileSpec.CreateDirectory();
|
||||
#endif
|
||||
|
||||
rv = profile->GetCurrentProfile(&profileName);
|
||||
if (NS_FAILED(rv)) goto failure;
|
||||
|
||||
CMTStatus psmStatus;
|
||||
nsCAutoString profilenameC;
|
||||
profilenameC.AssignWithConversion(profileName);
|
||||
|
||||
psmStatus = CMT_Hello( mControl,
|
||||
PROTOCOL_VERSION,
|
||||
profilenameC,
|
||||
(char*)profileSpec.GetNativePathCString());
|
||||
|
||||
if (psmStatus == CMTFailure)
|
||||
{
|
||||
PR_FREEIF(profileName);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (InitPSMEventLoop(mControl) != PR_SUCCESS)
|
||||
{
|
||||
PR_FREEIF(profileName);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
if (NS_FAILED(PassPrefs()))
|
||||
{
|
||||
PR_FREEIF(profileName);
|
||||
goto failure;
|
||||
}
|
||||
|
||||
PR_FREEIF(profileName);
|
||||
|
||||
nsCOMPtr<nsIProtocolProxyService> proxySvc = do_GetService(kProtocolProxyServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
proxySvc->AddNoProxyFor("127.0.0.1", mControl->port);
|
||||
|
||||
*_retval = mControl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
failure:
|
||||
#ifdef DEBUG
|
||||
printf("*** Failure setting up Cartman! \n");
|
||||
#endif
|
||||
|
||||
if (mControl)
|
||||
{
|
||||
CMT_CloseControlConnection(mControl);
|
||||
mControl = NULL;
|
||||
}
|
||||
|
||||
// TODO we need to unregister our UI callback BEFORE destroying our mutex.
|
||||
// nsPSMMutexDestroy();
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::DisplaySecurityAdvisor(const char *pickledStatus, const char *hostName)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
GetControlConnection( &controlConnection );
|
||||
if (DisplayPSMUIDialog(controlConnection, pickledStatus, hostName) == PR_SUCCESS)
|
||||
return NS_OK;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
class CertDownloader : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
CertDownloader() {NS_ASSERTION(0, "don't use this constructor."); }
|
||||
CertDownloader(PRInt32 type);
|
||||
virtual ~CertDownloader();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
protected:
|
||||
char* mByteData;
|
||||
PRInt32 mBufferOffset;
|
||||
PRInt32 mContentLength;
|
||||
PRInt32 mType;
|
||||
};
|
||||
|
||||
|
||||
CertDownloader::CertDownloader(PRInt32 type)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mByteData = nsnull;
|
||||
mType = type;
|
||||
}
|
||||
|
||||
CertDownloader::~CertDownloader()
|
||||
{
|
||||
if (mByteData)
|
||||
nsMemory::Free(mByteData);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(CertDownloader,NS_GET_IID(nsIStreamListener));
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
CertDownloader::OnStartRequest(nsIChannel* channel, nsISupports* context)
|
||||
{
|
||||
channel->GetContentLength(&mContentLength);
|
||||
if (mContentLength == -1)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
mBufferOffset = 0;
|
||||
mByteData = (char*) nsMemory::Alloc(mContentLength);
|
||||
if (!mByteData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
CertDownloader::OnDataAvailable(nsIChannel* channel,
|
||||
nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
if (!mByteData)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
PRUint32 amt;
|
||||
nsresult err;
|
||||
|
||||
do
|
||||
{
|
||||
err = aIStream->Read(mByteData+mBufferOffset, mContentLength-mBufferOffset, &amt);
|
||||
if (amt == 0) break;
|
||||
if (NS_FAILED(err)) return err;
|
||||
|
||||
aLength -= amt;
|
||||
mBufferOffset += amt;
|
||||
|
||||
} while (aLength > 0);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
CertDownloader::OnStopRequest(nsIChannel* channel,
|
||||
nsISupports* context,
|
||||
nsresult aStatus,
|
||||
const PRUnichar* aMsg)
|
||||
{
|
||||
|
||||
nsCOMPtr<nsIPSMComponent> psm = do_QueryInterface(context);
|
||||
|
||||
if (!psm) return NS_ERROR_FAILURE;
|
||||
|
||||
CMT_CONTROL *controlConnection;
|
||||
psm->GetControlConnection( &controlConnection );
|
||||
unsigned int certID;
|
||||
|
||||
certID = CMT_DecodeAndCreateTempCert(controlConnection, mByteData, mContentLength, mType);
|
||||
|
||||
if (certID)
|
||||
CMT_DestroyResource(controlConnection, certID, SSM_RESTYPE_CERTIFICATE);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
/* other mime types that we should handle sometime:
|
||||
|
||||
application/x-pkcs7-crl
|
||||
application/x-pkcs7-mime
|
||||
application/pkcs7-signature
|
||||
application/pre-encrypted
|
||||
|
||||
*/
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::HandleContent(const char * aContentType,
|
||||
const char * aCommand,
|
||||
const char * aWindowTarget,
|
||||
nsISupports* aWindowContext,
|
||||
nsIChannel * aChannel)
|
||||
{
|
||||
// We were called via CI. We better protect ourselves and addref.
|
||||
NS_ADDREF_THIS();
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (!aChannel) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
CMUint32 type = -1;
|
||||
|
||||
if ( nsCRT::strcasecmp(aContentType, "application/x-x509-ca-cert") == 0)
|
||||
{
|
||||
type = 1; //CA cert
|
||||
}
|
||||
else if (nsCRT::strcasecmp(aContentType, "application/x-x509-server-cert") == 0)
|
||||
{
|
||||
type = 2; //Server cert
|
||||
}
|
||||
else if (nsCRT::strcasecmp(aContentType, "application/x-x509-user-cert") == 0)
|
||||
{
|
||||
type = 3; //User cert
|
||||
}
|
||||
else if (nsCRT::strcasecmp(aContentType, "application/x-x509-email-cert") == 0)
|
||||
{
|
||||
type = 4; //Someone else's email cert
|
||||
}
|
||||
|
||||
if (type != -1)
|
||||
{
|
||||
// I can't directly open the passed channel cause it fails :-(
|
||||
|
||||
nsCOMPtr<nsIURI> uri;
|
||||
rv = aChannel->GetURI(getter_AddRefs(uri));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
rv = NS_OpenURI(getter_AddRefs(channel), uri);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return channel->AsyncRead(new CertDownloader(type), NS_STATIC_CAST(nsIPSMComponent*,this));
|
||||
}
|
||||
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------
|
||||
// Functions Implenenting NSISignatureVerifier
|
||||
//---------------------------------------------
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::HashBegin(PRUint32 alg, PRUint32* id)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if(CMT_HashCreate(controlConnection, alg, (CMUint32*)id) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
if(CMT_HASH_Begin(controlConnection, *id) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::HashUpdate(PRUint32 id, const char* buf, PRUint32 buflen)
|
||||
{
|
||||
CMT_CONTROL *controlConnection;
|
||||
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
if (CMT_HASH_Update(controlConnection, id,
|
||||
(const unsigned char*)buf, buflen) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::HashEnd(PRUint32 id, unsigned char** hash,
|
||||
PRUint32* hashLen, PRUint32 maxLen)
|
||||
{
|
||||
if (!hash)
|
||||
return NS_ERROR_ILLEGAL_VALUE;
|
||||
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
if(CMT_HASH_End(controlConnection, id, *hash,
|
||||
(CMUint32*)hashLen, maxLen) != CMTSuccess)
|
||||
return NS_ERROR_FAILURE;
|
||||
CMT_HASH_Destroy(controlConnection, id);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::CreatePrincipalFromSignature(const char* aRSABuf, PRUint32 aRSABufLen,
|
||||
nsIPrincipal** aPrincipal)
|
||||
{
|
||||
PRInt32 errorCode;
|
||||
return VerifySignature(aRSABuf, aRSABufLen, nsnull, 0, &errorCode, aPrincipal);
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
UselessPK7DataSink(void* arg, const char* buf, CMUint32 len)
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMComponent::VerifySignature(const char* aRSABuf, PRUint32 aRSABufLen,
|
||||
const char* aPlaintext, PRUint32 aPlaintextLen,
|
||||
PRInt32* aErrorCode,
|
||||
nsIPrincipal** aPrincipal)
|
||||
{
|
||||
if (!aPrincipal || !aErrorCode)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*aErrorCode = 0;
|
||||
*aPrincipal = nsnull;
|
||||
|
||||
CMT_CONTROL *controlConnection;
|
||||
if (NS_FAILED(GetControlConnection( &controlConnection )))
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
//-- Decode the signature stream
|
||||
CMUint32 decoderID;
|
||||
CMInt32* blah = nsnull;
|
||||
CMTStatus result = CMT_PKCS7DecoderStart(controlConnection, nsnull,
|
||||
&decoderID, blah,
|
||||
UselessPK7DataSink, nsnull);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
result = CMT_PKCS7DecoderUpdate(controlConnection, decoderID, aRSABuf, aRSABufLen);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
CMUint32 contentInfo;
|
||||
result = CMT_PKCS7DecoderFinish(controlConnection,
|
||||
decoderID, &contentInfo);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
|
||||
CMTItem hashItem;
|
||||
hashItem.data = 0;
|
||||
hashItem.len = 0;
|
||||
//-- If a plaintext was provided, hash it.
|
||||
if (aPlaintext)
|
||||
{
|
||||
CMUint32 hashId;
|
||||
CMT_HashCreate(controlConnection, nsISignatureVerifier::SHA1, &hashId);
|
||||
CMT_HASH_Begin(controlConnection, hashId);
|
||||
CMTStatus result = CMT_HASH_Update(controlConnection, hashId,
|
||||
(const unsigned char*)aPlaintext, aPlaintextLen);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
|
||||
unsigned char* hash = (unsigned char*)PR_MALLOC(nsISignatureVerifier::SHA1_LENGTH);
|
||||
if (!hash) return NS_ERROR_OUT_OF_MEMORY;
|
||||
CMUint32 hashLen;
|
||||
result = CMT_HASH_End(controlConnection, hashId, hash,
|
||||
&hashLen, nsISignatureVerifier::SHA1_LENGTH);
|
||||
if (result != CMTSuccess)
|
||||
{
|
||||
PR_FREEIF(hash);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
NS_ASSERTION(hashLen == nsISignatureVerifier::SHA1_LENGTH,
|
||||
"PSMComponent: Hash too short.");
|
||||
CMT_HASH_Destroy(controlConnection, hashId);
|
||||
hashItem.data = hash;
|
||||
hashItem.len = hashLen;
|
||||
}
|
||||
|
||||
//-- Verify signature
|
||||
// We need to call this function even if we're only creating a principal, not
|
||||
// verifying, because PSM won't give us certificate information unless this
|
||||
// function has been called.
|
||||
result = CMT_PKCS7VerifyDetachedSignature(controlConnection, contentInfo,
|
||||
6 /* =Object Signing Cert */,
|
||||
3 /* =SHA1 algorithm (MD5=2)*/,
|
||||
1,/* Save Certificate */
|
||||
&hashItem, (CMInt32*)aErrorCode);
|
||||
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
if (aPlaintext && *aErrorCode != 0) return NS_OK; // Verification failed.
|
||||
|
||||
CMUint32 certID;
|
||||
result = CMT_GetRIDAttribute(controlConnection, contentInfo,
|
||||
SSM_FID_P7CINFO_SIGNER_CERT, &certID);
|
||||
if ((result != CMTSuccess) || !certID) return NS_OK; // No signature present
|
||||
|
||||
CMTItem fingerprint;
|
||||
result = CMT_GetStringAttribute(controlConnection, certID,
|
||||
SSM_FID_CERT_FINGERPRINT, &fingerprint);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
|
||||
//-- Get a principal
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIScriptSecurityManager, secMan,
|
||||
NS_SCRIPTSECURITYMANAGER_PROGID, &rv)
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
rv = secMan->GetCertificatePrincipal((char*)fingerprint.data,
|
||||
aPrincipal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
//-- Get common name and store it in the principal.
|
||||
// Using common name + organizational unit as the user-visible certificate name
|
||||
nsCOMPtr<nsICertificatePrincipal> certificate = do_QueryInterface(*aPrincipal, &rv);
|
||||
if (NS_FAILED(rv)) return NS_ERROR_FAILURE;
|
||||
|
||||
CMTItem common;
|
||||
result = CMT_GetStringAttribute(controlConnection, certID,
|
||||
SSM_FID_CERT_COMMON_NAME, &common);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
CMTItem subject;
|
||||
result = CMT_GetStringAttribute(controlConnection, certID,
|
||||
SSM_FID_CERT_SUBJECT_NAME, &subject);
|
||||
if (result != CMTSuccess) return NS_ERROR_FAILURE;
|
||||
|
||||
nsCAutoString commonName;
|
||||
commonName = (char*)common.data;
|
||||
static const char orgUnitTag[] = " OU=";
|
||||
char* orgUnitPos = PL_strstr((char*)subject.data, orgUnitTag);
|
||||
if (orgUnitPos)
|
||||
{
|
||||
orgUnitPos += sizeof(orgUnitTag)-1;
|
||||
char* orgUnitEnd = PL_strchr(orgUnitPos, ',');
|
||||
PRInt32 orgUnitLen;
|
||||
if(orgUnitEnd)
|
||||
orgUnitLen = orgUnitEnd - orgUnitPos;
|
||||
else
|
||||
orgUnitLen = PL_strlen(orgUnitPos);
|
||||
commonName.Append(' ');
|
||||
commonName.Append(orgUnitPos, orgUnitLen);
|
||||
}
|
||||
char* commonChar = commonName.ToNewCString();
|
||||
if (!commonChar) return NS_ERROR_OUT_OF_MEMORY;
|
||||
rv = certificate->SetCommonName(commonChar);
|
||||
Recycle(commonChar);
|
||||
return rv;
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsISignatureVerifier.h"
|
||||
#include "nsIStringBundle.h"
|
||||
|
||||
#include "nsIContentHandler.h"
|
||||
|
||||
#define SECURITY_STRING_BUNDLE_URL "chrome://communicator/locale/security.properties"
|
||||
|
||||
#define NS_PSMCOMPONENT_CID {0xddcae170, 0x5412, 0x11d3, {0xbb, 0xc8, 0x00, 0x00, 0x86, 0x1d, 0x12, 0x37}}
|
||||
|
||||
// Implementation of the PSM component interface.
|
||||
class nsPSMComponent : public nsIPSMComponent,
|
||||
public nsIContentHandler,
|
||||
public nsISignatureVerifier
|
||||
{
|
||||
public:
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_PSMCOMPONENT_CID );
|
||||
|
||||
nsPSMComponent();
|
||||
virtual ~nsPSMComponent();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPSMCOMPONENT
|
||||
NS_DECL_NSICONTENTHANDLER
|
||||
NS_DECL_NSISIGNATUREVERIFIER
|
||||
|
||||
static NS_METHOD CreatePSMComponent(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
private:
|
||||
|
||||
PCMT_CONTROL mControl;
|
||||
|
||||
nsCOMPtr<nsISupports> mSecureBrowserIU;
|
||||
static nsPSMComponent* mInstance;
|
||||
};
|
||||
@@ -1,178 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "nsPSMComponent.h"
|
||||
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsSecureBrowserUIImpl.h"
|
||||
|
||||
#include "nsSSLSocketProvider.h"
|
||||
|
||||
#include "nsSDR.h"
|
||||
#include "nsFSDR.h"
|
||||
#include "nsCrypto.h"
|
||||
#include "nsKeygenHandler.h"
|
||||
//For the NS_CRYPTO_PROGID define
|
||||
#include "nsDOMCID.h"
|
||||
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsISupportsUtils.h"
|
||||
|
||||
// Define SDR object constructor
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kFormProcessorCID, NS_IFORMPROCESSOR_CID);
|
||||
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSecretDecoderRing, init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsFSecretDecoderRing, init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsCrypto, init)
|
||||
NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsPkcs11, init)
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{
|
||||
PSM_COMPONENT_CLASSNAME,
|
||||
NS_PSMCOMPONENT_CID,
|
||||
PSM_COMPONENT_PROGID,
|
||||
nsPSMComponent::CreatePSMComponent
|
||||
},
|
||||
|
||||
{
|
||||
"PSM Content Handler - application/x-x509-ca-cert",
|
||||
NS_PSMCOMPONENT_CID,
|
||||
NS_CONTENT_HANDLER_PROGID_PREFIX"application/x-x509-ca-cert",
|
||||
nsPSMComponent::CreatePSMComponent
|
||||
},
|
||||
|
||||
{
|
||||
"PSM Content Handler - application/x-x509-server-cert",
|
||||
NS_PSMCOMPONENT_CID,
|
||||
NS_CONTENT_HANDLER_PROGID_PREFIX"application/x-x509-server-cert",
|
||||
nsPSMComponent::CreatePSMComponent
|
||||
},
|
||||
|
||||
{
|
||||
"PSM Content Handler - application/x-x509-user-cert",
|
||||
NS_PSMCOMPONENT_CID,
|
||||
NS_CONTENT_HANDLER_PROGID_PREFIX"application/x-x509-user-cert",
|
||||
nsPSMComponent::CreatePSMComponent
|
||||
},
|
||||
|
||||
{
|
||||
"PSM Content Handler - application/x-x509-email-cert",
|
||||
NS_PSMCOMPONENT_CID,
|
||||
NS_CONTENT_HANDLER_PROGID_PREFIX"application/x-x509-email-cert",
|
||||
nsPSMComponent::CreatePSMComponent
|
||||
},
|
||||
|
||||
|
||||
{
|
||||
PSM_UI_HANLDER_CLASSNAME,
|
||||
NS_PSMUIHANDLER_CID,
|
||||
PSM_UI_HANLDER_PROGID,
|
||||
nsPSMUIHandlerImpl::CreatePSMUIHandler
|
||||
},
|
||||
|
||||
{
|
||||
NS_SECURE_BROWSER_UI_CLASSNAME,
|
||||
NS_SECURE_BROWSER_UI_CID,
|
||||
NS_SECURE_BROWSER_UI_PROGID,
|
||||
nsSecureBrowserUIImpl::Create
|
||||
},
|
||||
|
||||
{
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_CLASSNAME,
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_CID,
|
||||
NS_SECURE_BROWSER_DOCOBSERVER_PROGID,
|
||||
nsSecureBrowserUIImpl::Create
|
||||
},
|
||||
|
||||
{
|
||||
NS_ISSLSOCKETPROVIDER_CLASSNAME,
|
||||
NS_SSLSOCKETPROVIDER_CID,
|
||||
NS_ISSLSOCKETPROVIDER_PROGID,
|
||||
nsSSLSocketProvider::Create
|
||||
},
|
||||
|
||||
{
|
||||
NS_SDR_CLASSNAME,
|
||||
NS_SDR_CID,
|
||||
NS_SDR_PROGID,
|
||||
nsSecretDecoderRingConstructor
|
||||
},
|
||||
|
||||
{
|
||||
NS_FSDR_CLASSNAME,
|
||||
NS_FSDR_CID,
|
||||
NS_FSDR_PROGID,
|
||||
nsFSecretDecoderRingConstructor
|
||||
},
|
||||
|
||||
{
|
||||
NS_CRYPTO_CLASSNAME,
|
||||
NS_CRYPTO_CID,
|
||||
NS_CRYPTO_PROGID,
|
||||
nsCryptoConstructor
|
||||
},
|
||||
{
|
||||
NS_PKCS11_CLASSNAME,
|
||||
NS_PKCS11_CID,
|
||||
NS_PKCS11_PROGID,
|
||||
nsPkcs11Constructor
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
#if 0
|
||||
NS_IMPL_NSGETMODULE("PSMComponent", components);
|
||||
#endif
|
||||
|
||||
extern "C" NS_EXPORT nsresult NSGetModule(nsIComponentManager *servMgr,
|
||||
nsIFile* location,
|
||||
nsIModule** result)
|
||||
{
|
||||
nsresult rv;
|
||||
// Put in code to register KEYGEN form input handler.
|
||||
rv= NS_NewGenericModule("PSMComponent",
|
||||
sizeof(components) / sizeof(components[0]),
|
||||
components, nsnull, result);
|
||||
// Register a form processor. The form processor has the opportunity to
|
||||
// modify the value's passed during form submission.
|
||||
nsKeygenFormProcessor* testFormProcessor = new nsKeygenFormProcessor();
|
||||
nsCOMPtr<nsISupports> formProcessor;
|
||||
rv = testFormProcessor->QueryInterface(kISupportsIID,
|
||||
getter_AddRefs(formProcessor));
|
||||
if (NS_SUCCEEDED(rv) && formProcessor) {
|
||||
rv = nsServiceManager::RegisterService(kFormProcessorCID, formProcessor);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,72 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "prmon.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#include "nsPSMMutex.h"
|
||||
|
||||
static PRMonitor *_nsPSMMutexVar;
|
||||
|
||||
PRStatus
|
||||
nsPSMMutexInit()
|
||||
{
|
||||
if (!_nsPSMMutexVar)
|
||||
_nsPSMMutexVar = PR_NewMonitor();
|
||||
|
||||
return _nsPSMMutexVar ? PR_SUCCESS : PR_FAILURE;
|
||||
}
|
||||
|
||||
PRStatus
|
||||
nsPSMMutexDestroy()
|
||||
{
|
||||
if (!_nsPSMMutexVar)
|
||||
return PR_FAILURE;
|
||||
|
||||
PR_Wait(_nsPSMMutexVar, PR_INTERVAL_NO_TIMEOUT);
|
||||
|
||||
PR_DestroyMonitor(_nsPSMMutexVar);
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
static void
|
||||
nsPSMMutexLock(CMTMutexPointer *p)
|
||||
{
|
||||
PR_EnterMonitor(*(PRMonitor **)p);
|
||||
return;
|
||||
}
|
||||
|
||||
static void
|
||||
nsPSMMutexUnlock(CMTMutexPointer *p)
|
||||
{
|
||||
PR_ExitMonitor(*(PRMonitor **)p);
|
||||
return;
|
||||
}
|
||||
|
||||
CMT_MUTEX nsPSMMutexTbl =
|
||||
{
|
||||
&_nsPSMMutexVar,
|
||||
(CMTMutexFunction)nsPSMMutexLock,
|
||||
(CMTMutexFunction)nsPSMMutexUnlock
|
||||
};
|
||||
@@ -1,293 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
#include "private/pprio.h" /* for PR_Socket */
|
||||
#endif
|
||||
|
||||
#define PSM_TIMEOUT_IN_SEC 300
|
||||
|
||||
#define NSPSMSHIMMAXFD 50
|
||||
|
||||
|
||||
static PRIntervalTime gTimeout = PR_INTERVAL_NO_TIMEOUT;
|
||||
|
||||
CMT_SocketFuncs nsPSMShimTbl =
|
||||
{
|
||||
nsPSMShimGetSocket,
|
||||
nsPSMShimConnect,
|
||||
nsPSMShimVerifyUnixSocket,
|
||||
nsPSMShimSend,
|
||||
nsPSMShimSelect,
|
||||
nsPSMShimReceive,
|
||||
nsPSMShimShutdown,
|
||||
nsPSMShimClose
|
||||
};
|
||||
|
||||
|
||||
CMTSocket
|
||||
nsPSMShimGetSocket(int unixSock)
|
||||
{
|
||||
PRStatus rv;
|
||||
PRFileDesc *fd;
|
||||
CMSocket *sock;
|
||||
PRSocketOptionData sockopt;
|
||||
|
||||
/*
|
||||
if (PR_INTERVAL_NO_WAIT == gTimeout)
|
||||
{
|
||||
gTimeout = PR_SecondsToInterval(PSM_TIMEOUT_IN_SEC);
|
||||
}
|
||||
*/
|
||||
|
||||
if (unixSock)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return NULL;
|
||||
#else
|
||||
fd = PR_Socket(PR_AF_LOCAL, PR_SOCK_STREAM, 0);
|
||||
PR_ASSERT(fd);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
fd = PR_NewTCPSocket();
|
||||
PR_ASSERT(fd);
|
||||
|
||||
/* disable Nagle algorithm delay for control sockets */
|
||||
sockopt.option = PR_SockOpt_NoDelay;
|
||||
sockopt.value.no_delay = PR_TRUE;
|
||||
rv = PR_SetSocketOption(fd, &sockopt);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
}
|
||||
|
||||
sock = (CMSocket *)PR_Malloc(sizeof(CMSocket));
|
||||
|
||||
if (sock == NULL)
|
||||
return sock;
|
||||
|
||||
sock->fd = fd;
|
||||
sock->isUnix = unixSock;
|
||||
|
||||
memset(&sock->netAddr, 0, sizeof(PRNetAddr));
|
||||
|
||||
return (CMTSocket)sock;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimConnect(CMTSocket sock, short port, char *path)
|
||||
{
|
||||
CMTStatus rv = CMTSuccess;
|
||||
PRStatus err;
|
||||
PRErrorCode errcode;
|
||||
PRSocketOptionData sockopt;
|
||||
PRBool nonBlocking;
|
||||
CMSocket *cmSock = (CMSocket *)sock;
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
if (cmSock->isUnix)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
int pathLen;
|
||||
if (!path)
|
||||
{
|
||||
return CMTFailure;
|
||||
}
|
||||
|
||||
/* check buffer overrun */
|
||||
pathLen = strlen(path)+1;
|
||||
|
||||
pathLen = pathLen < sizeof(cmSock->netAddr.local.path)
|
||||
? pathLen : sizeof(cmSock->netAddr.local.path);
|
||||
|
||||
memcpy(&cmSock->netAddr.local.path, path, pathLen);
|
||||
cmSock->netAddr.local.family = PR_AF_LOCAL;
|
||||
#endif
|
||||
}
|
||||
else /* cmSock->isUnix */
|
||||
{
|
||||
cmSock->netAddr.inet.family = PR_AF_INET;
|
||||
cmSock->netAddr.inet.port = PR_htons(port);
|
||||
cmSock->netAddr.inet.ip = PR_htonl(PR_INADDR_LOOPBACK);
|
||||
}
|
||||
|
||||
/* Save non-blocking status */
|
||||
sockopt.option = PR_SockOpt_Nonblocking;
|
||||
err = PR_GetSocketOption(cmSock->fd, &sockopt);
|
||||
PR_ASSERT(PR_SUCCESS == err);
|
||||
|
||||
nonBlocking = sockopt.value.non_blocking;
|
||||
|
||||
/* make connect blocking for now */
|
||||
sockopt.option = PR_SockOpt_Nonblocking;
|
||||
sockopt.value.non_blocking = PR_FALSE;
|
||||
err = PR_SetSocketOption(cmSock->fd, &sockopt);
|
||||
PR_ASSERT(PR_SUCCESS == err);
|
||||
|
||||
err = PR_Connect( cmSock->fd, &cmSock->netAddr, PR_INTERVAL_MAX );
|
||||
|
||||
if (err == PR_FAILURE)
|
||||
{
|
||||
errcode = PR_GetError();
|
||||
|
||||
if (PR_IS_CONNECTED_ERROR != errcode)
|
||||
rv = CMTFailure;
|
||||
}
|
||||
|
||||
/* restore nonblock status */
|
||||
if (nonBlocking) {
|
||||
sockopt.option = PR_SockOpt_Nonblocking;
|
||||
sockopt.value.non_blocking = nonBlocking;
|
||||
err = PR_SetSocketOption(cmSock->fd, &sockopt);
|
||||
PR_ASSERT(PR_SUCCESS == err);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimVerifyUnixSocket(CMTSocket sock)
|
||||
{
|
||||
#ifndef XP_UNIX
|
||||
return CMTFailure;
|
||||
#else
|
||||
|
||||
int rv;
|
||||
CMSocket *cmSock;
|
||||
struct stat statbuf;
|
||||
|
||||
cmSock = (CMSocket *)sock;
|
||||
|
||||
if (!cmSock || !cmSock->isUnix)
|
||||
return CMTFailure;
|
||||
|
||||
rv = stat(cmSock->netAddr.local.path, &statbuf);
|
||||
if (rv < 0 || statbuf.st_uid != geteuid() )
|
||||
{
|
||||
PR_Close(cmSock->fd);
|
||||
cmSock->fd = NULL;
|
||||
PR_Free(cmSock);
|
||||
return CMTFailure;
|
||||
}
|
||||
return CMTSuccess;
|
||||
#endif
|
||||
}
|
||||
|
||||
size_t
|
||||
nsPSMShimSend(CMTSocket sock, void *buffer, size_t length)
|
||||
{
|
||||
CMSocket *cmSock = (CMSocket *)sock;
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
return PR_Send(cmSock->fd, buffer, length, 0, gTimeout);
|
||||
}
|
||||
|
||||
size_t
|
||||
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize)
|
||||
{
|
||||
CMSocket *cmSock = (CMSocket *)sock;
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
return PR_Recv(cmSock->fd, buffer, bufSize, 0, gTimeout);
|
||||
}
|
||||
|
||||
|
||||
CMTSocket
|
||||
nsPSMShimSelect(CMTSocket *socks, int numsocks, int poll)
|
||||
{
|
||||
CMSocket **sockArr = (CMSocket **)socks;
|
||||
PRPollDesc readPDs[NSPSMSHIMMAXFD];
|
||||
PRIntervalTime timeout;
|
||||
PRInt32 cnt;
|
||||
int i;
|
||||
|
||||
if (!socks) return NULL;
|
||||
|
||||
memset(readPDs, 0, sizeof(readPDs));
|
||||
|
||||
PR_ASSERT(NSPSMSHIMMAXFD >= numsocks);
|
||||
|
||||
for (i=0; i<numsocks; i++)
|
||||
{
|
||||
readPDs[i].fd = sockArr[i]->fd;
|
||||
readPDs[i].in_flags = PR_POLL_READ;
|
||||
}
|
||||
|
||||
timeout = poll ? PR_INTERVAL_NO_WAIT : PR_INTERVAL_NO_TIMEOUT;
|
||||
|
||||
cnt = PR_Poll(readPDs, numsocks, timeout);
|
||||
|
||||
/* Figure out which socket was selected */
|
||||
if (cnt > 0)
|
||||
{
|
||||
for (i=0; i<numsocks; i++)
|
||||
{
|
||||
if (readPDs[i].out_flags & PR_POLL_READ)
|
||||
{
|
||||
return (CMTSocket)sockArr[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimShutdown(CMTSocket sock)
|
||||
{
|
||||
CMSocket *cmSock = (CMSocket*)sock;
|
||||
PRStatus rv;
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
rv = PR_Shutdown(cmSock->fd, PR_SHUTDOWN_SEND);
|
||||
return (PR_SUCCESS == rv) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
|
||||
CMTStatus
|
||||
nsPSMShimClose(CMTSocket sock)
|
||||
{
|
||||
CMSocket *cmSock = (CMSocket*)sock;
|
||||
PRStatus rv = PR_SUCCESS;
|
||||
PR_ASSERT(cmSock);
|
||||
|
||||
if (!sock) return CMTFailure;
|
||||
|
||||
rv = PR_Close(cmSock->fd);
|
||||
cmSock->fd = NULL;
|
||||
|
||||
PR_Free(cmSock);
|
||||
|
||||
return (PR_SUCCESS == rv) ? CMTSuccess : CMTFailure;
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSPSMSHIMLAYER_H_
|
||||
#define _NSPSMSHIMLAYER_H_
|
||||
|
||||
#include "cmtcmn.h"
|
||||
#include "prio.h"
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
typedef struct CMSocket {
|
||||
PRFileDesc *fd;
|
||||
PRBool isUnix;
|
||||
PRNetAddr netAddr;
|
||||
} CMSocket;
|
||||
|
||||
PR_EXTERN(CMT_SocketFuncs) nsPSMShimTbl;
|
||||
|
||||
PR_EXTERN(CMTSocket)
|
||||
nsPSMShimGetSocket(int unixSock);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimConnect(CMTSocket sock, short port, char *path);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimVerifyUnixSocket(CMTSocket sock);
|
||||
|
||||
PR_EXTERN(size_t)
|
||||
nsPSMShimSend(CMTSocket sock, void *buffer, size_t length);
|
||||
|
||||
PR_EXTERN(CMTSocket)
|
||||
nsPSMShimSelect(CMTSocket *socks, int numsocks, int poll);
|
||||
|
||||
PR_EXTERN(size_t)
|
||||
nsPSMShimReceive(CMTSocket sock, void *buffer, size_t bufSize);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimShutdown(CMTSocket sock);
|
||||
|
||||
PR_EXTERN(CMTStatus)
|
||||
nsPSMShimClose(CMTSocket sock);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* _NSPSMSHIMLAYER_H_ */
|
||||
@@ -1,348 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nsProxiedService.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsPSMUICallbacks.h"
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIFilePicker.h"
|
||||
|
||||
#include "nsAppShellCIDs.h"
|
||||
#include "prprf.h"
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsSSLIOLayer.h" // for SSMSTRING_PADDED_LENGTH
|
||||
#include "ssmdefs.h"
|
||||
#include "rsrcids.h"
|
||||
|
||||
// Interfaces Needed
|
||||
#include "nsIAppShellService.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIXULWindow.h"
|
||||
|
||||
static NS_DEFINE_IID(kAppShellServiceCID, NS_APPSHELL_SERVICE_CID);
|
||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
|
||||
|
||||
// Happy callbacks
|
||||
static char * PromptUserCallback(void *arg, char *prompt, int isPasswd);
|
||||
static char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist);
|
||||
static void ApplicationFreeCallback(char *userInput);
|
||||
|
||||
static void * CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height,
|
||||
CMBool isModal, char* urlStr, void *data);
|
||||
|
||||
extern "C" void CARTMAN_UIEventLoop(void *data);
|
||||
|
||||
|
||||
/* nsISupports Implementation for the class */
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPSMUIHandlerImpl, nsIPSMUIHandler)
|
||||
|
||||
NS_METHOD
|
||||
nsPSMUIHandlerImpl::DisplayURI(PRInt32 width, PRInt32 height, PRBool modal, const char *urlStr)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIDOMWindow> hiddenWindow;
|
||||
JSContext *jsContext;
|
||||
|
||||
NS_WITH_SERVICE(nsIAppShellService, appShell, kAppShellServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = appShell->GetHiddenWindowAndJSContext( getter_AddRefs( hiddenWindow ),
|
||||
&jsContext );
|
||||
|
||||
if ( NS_SUCCEEDED( rv ) )
|
||||
{
|
||||
// Set up arguments for "window.open"
|
||||
void *stackPtr;
|
||||
char params[36];
|
||||
|
||||
if (modal) // if you change this, remember to change the buffer size above.
|
||||
strcpy(params, "menubar=no,height=%d,width=%d,modal");
|
||||
else
|
||||
strcpy(params, "menubar=no,height=%d,width=%d");
|
||||
|
||||
char buffer[256];
|
||||
PR_snprintf(buffer,
|
||||
sizeof(buffer),
|
||||
params,
|
||||
height,
|
||||
width );
|
||||
|
||||
jsval *argv = JS_PushArguments(jsContext, &stackPtr, "sss", urlStr, "_blank", buffer);
|
||||
if (argv)
|
||||
{
|
||||
// open the window
|
||||
nsIDOMWindow *newWindow;
|
||||
hiddenWindow->Open(jsContext, argv, 3, &newWindow);
|
||||
newWindow->ResizeTo(width, height);
|
||||
JS_PopArguments(jsContext, stackPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMUIHandlerImpl::PromptForFile(const PRUnichar *prompt, const char *fileRegEx, PRBool shouldFileExist, char **outFile)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(outFile);
|
||||
nsCOMPtr<nsIFilePicker> fp = do_CreateInstance("component://mozilla/filepicker");
|
||||
|
||||
if (!fp)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
|
||||
fp->Init(nsnull, prompt, nsIFilePicker::modeOpen);
|
||||
fp->AppendFilter(NS_ConvertASCIItoUCS2(fileRegEx).GetUnicode(), NS_ConvertASCIItoUCS2(fileRegEx).GetUnicode());
|
||||
fp->AppendFilters(nsIFilePicker::filterAll);
|
||||
PRInt16 mode;
|
||||
nsresult rv = fp->Show(&mode);
|
||||
|
||||
if (NS_FAILED(rv) || (mode == nsIFilePicker::returnCancel))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr<nsILocalFile> file;
|
||||
rv = fp->GetFile(getter_AddRefs(file));
|
||||
|
||||
if (file)
|
||||
file->GetPath(outFile);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsPSMUIHandlerImpl::CreatePSMUIHandler(nsISupports* aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if ( aResult )
|
||||
{
|
||||
/* Allocate new find component object. */
|
||||
nsPSMUIHandlerImpl *component = new nsPSMUIHandlerImpl();
|
||||
if ( component )
|
||||
{
|
||||
/* Allocated OK, do query interface to get proper */
|
||||
/* pointer and increment refcount. */
|
||||
rv = component->QueryInterface( aIID, aResult );
|
||||
if ( NS_FAILED( rv ) )
|
||||
{
|
||||
/* refcount still at zero, delete it here. */
|
||||
delete component;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
|
||||
extern "C" void CARTMAN_UIEventLoop(void *data)
|
||||
{
|
||||
CMT_EventLoop((PCMT_CONTROL)data);
|
||||
}
|
||||
|
||||
PRStatus InitPSMEventLoop(PCMT_CONTROL control)
|
||||
{
|
||||
PR_CreateThread(PR_USER_THREAD,
|
||||
CARTMAN_UIEventLoop,
|
||||
control,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_GLOBAL_THREAD,
|
||||
PR_UNJOINABLE_THREAD,
|
||||
0);
|
||||
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
PRStatus InitPSMUICallbacks(PCMT_CONTROL control)
|
||||
{
|
||||
if (!control)
|
||||
return PR_FAILURE;
|
||||
|
||||
CMT_SetPromptCallback(control, (promptCallback_fn)PromptUserCallback, nsnull);
|
||||
CMT_SetAppFreeCallback(control, (applicationFreeCallback_fn) ApplicationFreeCallback);
|
||||
CMT_SetFilePathPromptCallback(control, (filePathPromptCallback_fn) FilePathPromptCallback, nsnull);
|
||||
|
||||
if (CMT_SetUIHandlerCallback(control, (uiHandlerCallback_fn) CartmanUIHandler, NULL) != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, const char *pickledStatus, const char *hostName)
|
||||
{
|
||||
CMUint32 advRID = 0;
|
||||
CMInt32 width = 0;
|
||||
CMInt32 height = 0;
|
||||
CMTItem urlItem = {0, NULL, 0};
|
||||
CMTStatus rv = CMTSuccess;
|
||||
CMTItem advisorContext = {0, NULL, 0};
|
||||
void * pwin;
|
||||
|
||||
CMTSecurityAdvisorData data;
|
||||
memset(&data, '\0', sizeof(CMTSecurityAdvisorData));
|
||||
|
||||
if (hostName)
|
||||
{
|
||||
// if there is a hostName, than this request is about
|
||||
// a webpage.
|
||||
data.hostname = (char*) hostName;
|
||||
data.infoContext = SSM_BROWSER;
|
||||
|
||||
if (pickledStatus)
|
||||
{
|
||||
CMTItem pickledResource = {0, NULL, 0};
|
||||
CMUint32 socketStatus = 0;
|
||||
|
||||
pickledResource.len = *(int*)(pickledStatus);
|
||||
pickledResource.data = (unsigned char*) PR_Malloc(SSMSTRING_PADDED_LENGTH(pickledResource.len));
|
||||
|
||||
if (! pickledResource.data) return PR_FAILURE;
|
||||
|
||||
memcpy(pickledResource.data, pickledStatus+sizeof(int), pickledResource.len);
|
||||
|
||||
/* Unpickle the SSL Socket Status */
|
||||
if (CMT_UnpickleResource( control,
|
||||
SSM_RESTYPE_SSL_SOCKET_STATUS,
|
||||
pickledResource,
|
||||
&socketStatus) == CMTSuccess)
|
||||
{
|
||||
data.infoContext = SSM_BROWSER;
|
||||
data.resID = socketStatus;
|
||||
}
|
||||
|
||||
PR_FREEIF(pickledResource.data);
|
||||
}
|
||||
}
|
||||
|
||||
/* Create a Security Advisor context object. */
|
||||
rv = CMT_SecurityAdvisor(control, &data, &advRID);
|
||||
|
||||
if (rv != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
/* Get the URL, width, height, etc. from the advisor context. */
|
||||
rv = CMT_GetStringAttribute(control,
|
||||
advRID,
|
||||
SSM_FID_SECADVISOR_URL,
|
||||
&urlItem);
|
||||
|
||||
if ((rv != CMTSuccess) || (!urlItem.data))
|
||||
return PR_FAILURE;
|
||||
|
||||
rv = CMT_GetNumericAttribute(control,
|
||||
advRID,
|
||||
SSM_FID_SECADVISOR_WIDTH,
|
||||
&width);
|
||||
if (rv != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
rv = CMT_GetNumericAttribute(control,
|
||||
advRID,
|
||||
SSM_FID_SECADVISOR_HEIGHT,
|
||||
&height);
|
||||
if (rv != CMTSuccess)
|
||||
return PR_FAILURE;
|
||||
|
||||
/* Fire the URL up in a window of its own. */
|
||||
pwin = CartmanUIHandler(advRID, nsnull, width, height, CM_FALSE, (char*)urlItem.data, NULL);
|
||||
|
||||
//allocated by cmt, we can free with free:
|
||||
free(urlItem.data);
|
||||
|
||||
return PR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void* CartmanUIHandler(uint32 resourceID, void* clientContext, uint32 width, uint32 height, CMBool isModal, char* urlStr, void *data)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
handler->DisplayURI(width, height, isModal, urlStr);
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char * PromptUserCallback(void *arg, char *prompt, int isPasswd)
|
||||
{
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
PRUnichar *password;
|
||||
PRBool value;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, NS_UI_THREAD_EVENTQ, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = dialog->PromptPassword(nsnull, NS_ConvertASCIItoUCS2(prompt).GetUnicode(),
|
||||
NS_ConvertASCIItoUCS2(" ").GetUnicode(), // hostname
|
||||
PR_TRUE, &password, &value);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && value) {
|
||||
nsString a(password);
|
||||
char* str = a.ToNewCString();
|
||||
Recycle(password);
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void ApplicationFreeCallback(char *userInput)
|
||||
{
|
||||
nsMemory::Free(userInput);
|
||||
}
|
||||
|
||||
char * FilePathPromptCallback(void *arg, char *prompt, char *fileRegEx, CMUint32 shouldFileExist)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
char* filePath = nsnull;
|
||||
|
||||
NS_WITH_PROXIED_SERVICE(nsIPSMUIHandler, handler, nsPSMUIHandlerImpl::GetCID(), NS_UI_THREAD_EVENTQ, &rv);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
handler->PromptForFile(NS_ConvertASCIItoUCS2(prompt).GetUnicode(), fileRegEx, (PRBool)shouldFileExist, &filePath);
|
||||
|
||||
return filePath;
|
||||
}
|
||||
@@ -1,56 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSPSMUICALLBACKS_H
|
||||
#define _NSPSMUICALLBACKS_H
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#include "nsIPSMUIHandler.h"
|
||||
|
||||
PRStatus InitPSMUICallbacks(PCMT_CONTROL gControl);
|
||||
PRStatus InitPSMEventLoop(PCMT_CONTROL gControl);
|
||||
PRStatus DisplayPSMUIDialog(PCMT_CONTROL control, const char* pickledStatus, const char *hostName);
|
||||
|
||||
|
||||
#define NS_PSMUIHANDLER_CID {0x15944e30, 0x601e, 0x11d3, {0x8c, 0x4a, 0x00, 0x00, 0x64, 0x65, 0x73, 0x74}}
|
||||
|
||||
class nsPSMUIHandlerImpl : public nsIPSMUIHandler
|
||||
{
|
||||
public:
|
||||
|
||||
NS_DEFINE_STATIC_CID_ACCESSOR( NS_PSMUIHANDLER_CID );
|
||||
|
||||
/* ctor/dtor */
|
||||
nsPSMUIHandlerImpl() { NS_INIT_REFCNT(); }
|
||||
virtual ~nsPSMUIHandlerImpl() { }
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPSMUIHANDLER
|
||||
|
||||
static NS_METHOD CreatePSMUIHandler(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,320 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* thayes@netscape.com
|
||||
*/
|
||||
|
||||
#include "stdlib.h"
|
||||
#include "plstr.h"
|
||||
#include "nsMemory.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "plbase64.h"
|
||||
|
||||
#include "nsISecretDecoderRing.h"
|
||||
|
||||
#include "cmtcmn.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
|
||||
#include "nsSDR.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsSecretDecoderRing, nsISecretDecoderRing)
|
||||
|
||||
nsSecretDecoderRing::nsSecretDecoderRing()
|
||||
{
|
||||
NS_INIT_ISUPPORTS();
|
||||
|
||||
mPSM = NULL;
|
||||
}
|
||||
|
||||
nsSecretDecoderRing::~nsSecretDecoderRing()
|
||||
{
|
||||
if (mPSM) mPSM->Release();
|
||||
}
|
||||
|
||||
/* Init the new instance */
|
||||
nsresult nsSecretDecoderRing::
|
||||
init()
|
||||
{
|
||||
nsresult rv;
|
||||
nsISupports *psm;
|
||||
|
||||
rv = nsServiceManager::GetService(kPSMComponentProgID, NS_GET_IID(nsIPSMComponent),
|
||||
&psm);
|
||||
if (rv != NS_OK) goto loser; /* Should promote error */
|
||||
|
||||
mPSM = (nsIPSMComponent *)psm;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* [noscript] long encrypt (in buffer data, in long dataLen, out buffer result); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
Encrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
unsigned char *r = 0;
|
||||
CMT_CONTROL *control;
|
||||
CMTStatus status;
|
||||
CMUint32 cLen;
|
||||
|
||||
if (data == nsnull || result == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Check object initialization */
|
||||
NS_ASSERTION(mPSM != nsnull, "SDR object not initialized");
|
||||
if (mPSM == nsnull) { rv = NS_ERROR_NOT_INITIALIZED; goto loser; }
|
||||
|
||||
/* Get the control connect to use for the request */
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }
|
||||
|
||||
status = CMT_SDREncrypt(control, (void *)0, (const unsigned char *)0, 0,
|
||||
data, dataLen, result, &cLen);
|
||||
if (status != CMTSuccess) { rv = NS_ERROR_FAILURE; goto loser; } /* XXX */
|
||||
|
||||
/* Copy returned data to nsMemory buffer ? */
|
||||
*_retval = cLen;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* [noscript] long decrypt (in buffer data, in long dataLen, out buffer result); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
Decrypt(unsigned char * data, PRInt32 dataLen, unsigned char * *result, PRInt32 *_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
CMTStatus status;
|
||||
CMT_CONTROL *control;
|
||||
CMUint32 len;
|
||||
|
||||
if (data == nsnull || result == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
/* Check object initialization */
|
||||
NS_ASSERTION(mPSM != nsnull, "SDR object not initialized");
|
||||
if (mPSM == nsnull) { rv = NS_ERROR_NOT_INITIALIZED; goto loser; }
|
||||
|
||||
/* Get the control connection */
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }
|
||||
|
||||
/* Call PSM to decrypt the value */
|
||||
status = CMT_SDRDecrypt(control, (void *)0, data, dataLen, result, &len);
|
||||
if (status != CMTSuccess) { rv = NS_ERROR_FAILURE; goto loser; } /* Promote? */
|
||||
|
||||
/* Copy returned data to nsMemory buffer ? */
|
||||
*_retval = len;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* string encryptString (in string text); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
EncryptString(const char *text, char **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
unsigned char *encrypted = 0;
|
||||
PRInt32 eLen;
|
||||
|
||||
if (text == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = Encrypt((unsigned char *)text, PL_strlen(text), &encrypted, &eLen);
|
||||
if (rv != NS_OK) { goto loser; }
|
||||
|
||||
rv = encode(encrypted, eLen, _retval);
|
||||
|
||||
loser:
|
||||
if (encrypted) nsMemory::Free(encrypted);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* string decryptString (in string crypt); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
DecryptString(const char *crypt, char **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
char *r = 0;
|
||||
unsigned char *decoded = 0;
|
||||
PRInt32 decodedLen;
|
||||
unsigned char *decrypted = 0;
|
||||
PRInt32 decryptedLen;
|
||||
|
||||
if (crypt == nsnull || _retval == nsnull) {
|
||||
rv = NS_ERROR_INVALID_POINTER;
|
||||
goto loser;
|
||||
}
|
||||
|
||||
rv = decode(crypt, &decoded, &decodedLen);
|
||||
if (rv != NS_OK) goto loser;
|
||||
|
||||
rv = Decrypt(decoded, decodedLen, &decrypted, &decryptedLen);
|
||||
if (rv != NS_OK) goto loser;
|
||||
|
||||
// Convert to NUL-terminated string
|
||||
r = (char *)nsMemory::Alloc(decryptedLen+1);
|
||||
if (!r) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
memcpy(r, decrypted, decryptedLen);
|
||||
r[decryptedLen] = 0;
|
||||
|
||||
*_retval = r;
|
||||
r = 0;
|
||||
|
||||
loser:
|
||||
if (r) nsMemory::Free(r);
|
||||
if (decrypted) nsMemory::Free(decrypted);
|
||||
if (decoded) nsMemory::Free(decoded);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void changePassword(); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
ChangePassword()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
CMTStatus status;
|
||||
CMT_CONTROL *control;
|
||||
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }
|
||||
|
||||
status = CMT_SDRChangePassword(control, (void*)0);
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
/* void logout(); */
|
||||
NS_IMETHODIMP nsSecretDecoderRing::
|
||||
Logout()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
CMTStatus status;
|
||||
CMT_CONTROL *control;
|
||||
|
||||
/* Check object initialization */
|
||||
NS_ASSERTION(mPSM != nsnull, "SDR object not initialized");
|
||||
if (mPSM == nsnull) { rv = NS_ERROR_NOT_INITIALIZED; goto loser; }
|
||||
|
||||
/* Get the control connection */
|
||||
rv = mPSM->GetControlConnection(&control);
|
||||
if (rv != NS_OK) { rv = NS_ERROR_NOT_AVAILABLE; goto loser; }
|
||||
|
||||
/* Call PSM to decrypt the value */
|
||||
status = CMT_LogoutAllTokens(control);
|
||||
if (status != CMTSuccess) { rv = NS_ERROR_FAILURE; goto loser; } /* Promote? */
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
// Support routines
|
||||
|
||||
nsresult nsSecretDecoderRing::
|
||||
encode(const unsigned char *data, PRInt32 dataLen, char **_retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
*_retval = PL_Base64Encode((const char *)data, dataLen, NULL);
|
||||
if (!*_retval) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
|
||||
#if 0
|
||||
nsresult rv = NS_OK;
|
||||
char *r = 0;
|
||||
|
||||
// Allocate space for encoded string (with NUL)
|
||||
r = (char *)nsMemory::Alloc(dataLen+1);
|
||||
if (!r) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
memcpy(r, data, dataLen);
|
||||
r[dataLen] = 0;
|
||||
|
||||
*_retval = r;
|
||||
r = 0;
|
||||
|
||||
loser:
|
||||
if (r) nsMemory::Free(r);
|
||||
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
nsresult nsSecretDecoderRing::
|
||||
decode(const char *data, unsigned char **result, PRInt32 * _retval)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRUint32 len = PL_strlen(data);
|
||||
int adjust = 0;
|
||||
|
||||
/* Compute length adjustment */
|
||||
if (data[len-1] == '=') {
|
||||
adjust++;
|
||||
if (data[len-2] == '=') adjust++;
|
||||
}
|
||||
|
||||
*result = (unsigned char *)PL_Base64Decode(data, len, NULL);
|
||||
if (!*result) { rv = NS_ERROR_ILLEGAL_VALUE; goto loser; }
|
||||
|
||||
*_retval = (len*3)/4 - adjust;
|
||||
|
||||
loser:
|
||||
return rv;
|
||||
|
||||
#if 0
|
||||
nsresult rv = NS_OK;
|
||||
unsigned char *r = 0;
|
||||
PRInt32 rLen;
|
||||
|
||||
// Allocate space for decoded string (missing NUL)
|
||||
rLen = PL_strlen(data);
|
||||
r = (unsigned char *)nsMemory::Alloc(rLen);
|
||||
if (!r) { rv = NS_ERROR_OUT_OF_MEMORY; goto loser; }
|
||||
|
||||
memcpy(r, data, rLen);
|
||||
|
||||
*result = r;
|
||||
r = 0;
|
||||
*_retval = rLen;
|
||||
|
||||
loser:
|
||||
if (r) nsMemory::Free(r);
|
||||
|
||||
return rv;
|
||||
#endif
|
||||
}
|
||||
|
||||
const char * nsSecretDecoderRing::kPSMComponentProgID = PSM_COMPONENT_PROGID;
|
||||
@@ -1,58 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Terry Hayes <thayes@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef _NSSDR_H_
|
||||
#define _NSSDR_H_
|
||||
|
||||
#include "nsISecretDecoderRing.h"
|
||||
|
||||
// ===============================================
|
||||
// nsSecretDecoderRing - implementation of nsISecretDecoderRing
|
||||
// ===============================================
|
||||
|
||||
#define NS_SDR_CLASSNAME "Secret Decoder Ring"
|
||||
#define NS_SDR_CID \
|
||||
{ 0xd9a0341, 0xce7, 0x11d4, { 0x9f, 0xdd, 0x0, 0x0, 0x64, 0x65, 0x73, 0x74 } }
|
||||
#define NS_SDR_PROGID "netscape.security.sdr"
|
||||
|
||||
class nsSecretDecoderRing : public nsISecretDecoderRing
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISECRETDECODERRING
|
||||
|
||||
nsSecretDecoderRing();
|
||||
virtual ~nsSecretDecoderRing();
|
||||
|
||||
nsresult init();
|
||||
|
||||
private:
|
||||
nsIPSMComponent *mPSM;
|
||||
|
||||
static const char *kPSMComponentProgID;
|
||||
|
||||
nsresult encode(const unsigned char *data, PRInt32 dataLen, char **_retval);
|
||||
nsresult decode(const char *data, unsigned char **result, PRInt32 * _retval);
|
||||
};
|
||||
|
||||
#endif /* _NSSDR_H_ */
|
||||
@@ -1,550 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsString.h"
|
||||
#include "cmtcmn.h"
|
||||
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsIPSMSocketInfo.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsPSMShimLayer.h"
|
||||
#include "nsSSLIOLayer.h"
|
||||
|
||||
static PRDescIdentity nsSSLIOLayerIdentity;
|
||||
static PRIOMethods nsSSLIOLayerMethods;
|
||||
static nsIPSMComponent* gPSMService = nsnull;
|
||||
|
||||
|
||||
|
||||
class nsPSMSocketInfo : public nsIPSMSocketInfo
|
||||
{
|
||||
public:
|
||||
nsPSMSocketInfo();
|
||||
virtual ~nsPSMSocketInfo();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPSMSOCKETINFO
|
||||
|
||||
// internal functions to psm-glue.
|
||||
nsresult SetSocketPtr(CMSocket *socketPtr);
|
||||
nsresult SetControlPtr(CMT_CONTROL *aControlPtr);
|
||||
nsresult SetFileDescPtr(PRFileDesc *aControlPtr);
|
||||
nsresult SetHostName(char *aHostName);
|
||||
nsresult SetProxyName(char *aName);
|
||||
|
||||
nsresult SetHostPort(PRInt32 aPort);
|
||||
nsresult SetProxyPort(PRInt32 aPort);
|
||||
nsresult SetPickledStatus();
|
||||
|
||||
protected:
|
||||
CMT_CONTROL* mControl;
|
||||
CMSocket* mSocket;
|
||||
PRFileDesc* mFd;
|
||||
|
||||
nsString mHostName;
|
||||
PRInt32 mHostPort;
|
||||
|
||||
nsString mProxyName;
|
||||
PRInt32 mProxyPort;
|
||||
|
||||
unsigned char* mPickledStatus;
|
||||
};
|
||||
|
||||
|
||||
static PRStatus PR_CALLBACK
|
||||
nsSSLIOLayerConnect(PRFileDesc *fd, const PRNetAddr *addr, PRIntervalTime timeout)
|
||||
{
|
||||
nsresult result;
|
||||
PRStatus rv = PR_SUCCESS;
|
||||
CMTStatus status = CMTFailure;
|
||||
|
||||
/* Set the error in case of failure. */
|
||||
|
||||
PR_SetError(PR_UNKNOWN_ERROR, status);
|
||||
|
||||
if (!fd || !addr || !fd->secret || !gPSMService)
|
||||
return PR_FAILURE;
|
||||
|
||||
char ipBuffer[PR_NETDB_BUF_SIZE];
|
||||
rv = PR_NetAddrToString(addr, (char*)&ipBuffer, PR_NETDB_BUF_SIZE);
|
||||
if (rv != PR_SUCCESS)
|
||||
return PR_FAILURE;
|
||||
|
||||
if (addr->raw.family == PR_AF_INET6 && PR_IsNetAddrType(addr, PR_IpAddrV4Mapped))
|
||||
{
|
||||
/* Chop off the leading "::ffff:" */
|
||||
strcpy(ipBuffer, ipBuffer + 7);
|
||||
}
|
||||
|
||||
|
||||
CMT_CONTROL *control;
|
||||
result = gPSMService->GetControlConnection(&control);
|
||||
if (result != PR_SUCCESS)
|
||||
return PR_FAILURE;
|
||||
|
||||
CMSocket* cmsock = (CMSocket *)PR_Malloc(sizeof(CMSocket));
|
||||
if (!cmsock)
|
||||
return PR_FAILURE;
|
||||
|
||||
memset(cmsock, 0, sizeof(CMSocket));
|
||||
|
||||
cmsock->fd = fd->lower;
|
||||
cmsock->isUnix = PR_FALSE;
|
||||
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
|
||||
infoObject->SetControlPtr(control);
|
||||
infoObject->SetSocketPtr(cmsock);
|
||||
|
||||
char* proxyName;
|
||||
char* hostName;
|
||||
infoObject->GetProxyName(&proxyName);
|
||||
infoObject->GetHostName(&hostName);
|
||||
|
||||
if (!proxyName)
|
||||
{
|
||||
// Direct connection
|
||||
status = CMT_OpenSSLConnection(control,
|
||||
cmsock,
|
||||
SSM_REQUEST_SSL_DATA_SSL,
|
||||
PR_ntohs(addr->inet.port),
|
||||
ipBuffer,
|
||||
(hostName ? hostName : ipBuffer),
|
||||
CM_FALSE,
|
||||
nsnull);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
// not supported yet.
|
||||
|
||||
return PR_FAILURE;
|
||||
#if 0
|
||||
PRInt32 destPort;
|
||||
|
||||
infoObject->GetProxyPort(&destPort);
|
||||
|
||||
status = CMT_OpenSSLProxyConnection(control,
|
||||
cmsock,
|
||||
destPort,
|
||||
proxyName, // wants IP
|
||||
hostName);
|
||||
#endif
|
||||
}
|
||||
|
||||
if (hostName) Recycle(hostName);
|
||||
if (proxyName) Recycle(proxyName);
|
||||
|
||||
if (CMTSuccess == status)
|
||||
{
|
||||
// since our stuff can block, what we want to do is return PR_FAILURE,
|
||||
// but set the nspr ERROR to BLOCK. This will put us into a select
|
||||
// q.
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, status);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
/* CMT_DestroyDataConnection(ctrl, sock); */
|
||||
/* need to strip our layer, pass result to DestroyDataConnection */
|
||||
/* which will clean up the CMT accounting of sock, then call our */
|
||||
/* shim layer to translate back to NSPR */
|
||||
|
||||
static PRStatus PR_CALLBACK
|
||||
nsSSLIOLayerClose(PRFileDesc *fd)
|
||||
{
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (infoObject && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
CMT_CONTROL* control;
|
||||
CMSocket* socket;
|
||||
|
||||
PR_Shutdown(fd, PR_SHUTDOWN_BOTH);
|
||||
|
||||
infoObject->GetControlPtr(&control);
|
||||
infoObject->GetSocketPtr(&socket);
|
||||
infoObject->SetPickledStatus();
|
||||
|
||||
CMT_GetSSLDataErrorCode(control, socket, &errorCode);
|
||||
CMT_DestroyDataConnection(control, socket);
|
||||
NS_RELEASE(infoObject); // if someone is interested in us, the better have an addref.
|
||||
fd->identity = PR_INVALID_IO_LAYER;
|
||||
|
||||
return (PRStatus)errorCode;
|
||||
}
|
||||
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
nsSSLIOLayerRead( PRFileDesc *fd, void *buf, PRInt32 amount)
|
||||
{
|
||||
if (!fd)
|
||||
return PR_FAILURE;
|
||||
|
||||
PRInt32 result = PR_Recv(fd, buf, amount, 0, PR_INTERVAL_MIN);
|
||||
|
||||
if (result > 0)
|
||||
return result;
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
PRErrorCode code = PR_GetError();
|
||||
|
||||
if (code == PR_IO_TIMEOUT_ERROR )
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (infoObject && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
|
||||
CMT_CONTROL* control;
|
||||
CMSocket* socket;
|
||||
|
||||
infoObject->GetControlPtr(&control);
|
||||
infoObject->GetSocketPtr(&socket);
|
||||
|
||||
CMT_GetSSLDataErrorCode(control, socket, &errorCode);
|
||||
|
||||
if (errorCode == PR_IO_TIMEOUT_ERROR)
|
||||
{
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
PR_SetError(0, 0);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static PRInt32 PR_CALLBACK
|
||||
nsSSLIOLayerWrite( PRFileDesc *fd, const void *buf, PRInt32 amount)
|
||||
{
|
||||
if (!fd)
|
||||
return PR_FAILURE;
|
||||
|
||||
PRInt32 result = PR_Send(fd, buf, amount, 0, PR_INTERVAL_MIN);
|
||||
|
||||
if (result > 0)
|
||||
return result;
|
||||
|
||||
if (result == -1)
|
||||
{
|
||||
PRErrorCode code = PR_GetError();
|
||||
|
||||
if (code == PR_IO_TIMEOUT_ERROR )
|
||||
PR_SetError(PR_WOULD_BLOCK_ERROR, PR_WOULD_BLOCK_ERROR);
|
||||
return PR_FAILURE;
|
||||
}
|
||||
|
||||
if (result == 0)
|
||||
{
|
||||
nsPSMSocketInfo *infoObject = (nsPSMSocketInfo *)fd->secret;
|
||||
PRDescIdentity id = PR_GetLayersIdentity(fd);
|
||||
|
||||
if (infoObject && id == nsSSLIOLayerIdentity)
|
||||
{
|
||||
CMInt32 errorCode = PR_FAILURE;
|
||||
CMT_CONTROL* control;
|
||||
CMSocket* socket;
|
||||
|
||||
infoObject->GetControlPtr(&control);
|
||||
infoObject->GetSocketPtr(&socket);
|
||||
|
||||
CMT_GetSSLDataErrorCode(control, socket, &errorCode);
|
||||
PR_SetError(0, 0);
|
||||
return errorCode;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsPSMSocketInfo::nsPSMSocketInfo()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mControl = nsnull;
|
||||
mSocket = nsnull;
|
||||
mPickledStatus = nsnull;
|
||||
}
|
||||
|
||||
nsPSMSocketInfo::~nsPSMSocketInfo()
|
||||
{
|
||||
PR_FREEIF(mPickledStatus);
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS1(nsPSMSocketInfo, nsIPSMSocketInfo);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetControlPtr(CMT_CONTROL * *aControlPtr)
|
||||
{
|
||||
*aControlPtr = mControl;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetControlPtr(CMT_CONTROL *aControlPtr)
|
||||
{
|
||||
mControl = aControlPtr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetSocketPtr(CMSocket * *socketPtr)
|
||||
{
|
||||
*socketPtr = mSocket;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetSocketPtr(CMSocket *socketPtr)
|
||||
{
|
||||
mSocket = socketPtr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetFileDescPtr(PRFileDesc * *aFilePtr)
|
||||
{
|
||||
*aFilePtr = mFd;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetFileDescPtr(PRFileDesc *aFilePtr)
|
||||
{
|
||||
mFd = aFilePtr;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetHostName(char * *aHostName)
|
||||
{
|
||||
if (mHostName.IsEmpty())
|
||||
*aHostName = nsnull;
|
||||
else
|
||||
*aHostName = mHostName.ToNewCString();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetHostName(char *aHostName)
|
||||
{
|
||||
mHostName.AssignWithConversion(aHostName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetHostPort(PRInt32 *aPort)
|
||||
{
|
||||
*aPort = mHostPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetHostPort(PRInt32 aPort)
|
||||
{
|
||||
mHostPort = aPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetProxyName(char * *aName)
|
||||
{
|
||||
if (mProxyName.IsEmpty())
|
||||
*aName = nsnull;
|
||||
else
|
||||
*aName = mProxyName.ToNewCString();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetProxyName(char *aName)
|
||||
{
|
||||
mProxyName.AssignWithConversion(aName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetProxyPort(PRInt32 *aPort)
|
||||
{
|
||||
*aPort = mProxyPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetProxyPort(PRInt32 aPort)
|
||||
{
|
||||
mProxyPort = aPort;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsresult
|
||||
nsPSMSocketInfo::SetPickledStatus()
|
||||
{
|
||||
PR_FREEIF(mPickledStatus);
|
||||
|
||||
long level;
|
||||
CMTItem pickledStatus = {0, nsnull, 0};
|
||||
unsigned char* ret = nsnull;
|
||||
|
||||
if (CMT_GetSSLSocketStatus(mControl, mSocket, &pickledStatus, &level) != PR_FAILURE)
|
||||
{
|
||||
ret = (unsigned char*) PR_Malloc( (SSMSTRING_PADDED_LENGTH(pickledStatus.len) + sizeof(int)) );
|
||||
if (ret)
|
||||
{
|
||||
*(int*)ret = pickledStatus.len;
|
||||
memcpy(ret+sizeof(int), pickledStatus.data, *(int*)ret);
|
||||
}
|
||||
|
||||
PR_FREEIF(pickledStatus.data);
|
||||
mPickledStatus = ret;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsPSMSocketInfo::GetPickledStatus(char * *pickledStatusString)
|
||||
{
|
||||
if (!mPickledStatus)
|
||||
SetPickledStatus();
|
||||
|
||||
if (mPickledStatus)
|
||||
{
|
||||
PRInt32 len = *(int*)mPickledStatus;
|
||||
char *out = (char *)nsMemory::Alloc(len);
|
||||
memcpy(out, mPickledStatus, len);
|
||||
*pickledStatusString = out;
|
||||
return NS_OK;
|
||||
}
|
||||
*pickledStatusString = nsnull;
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSSLIOLayerNewSocket( const char *host,
|
||||
PRInt32 port,
|
||||
const char *proxyHost,
|
||||
PRInt32 proxyPort,
|
||||
PRFileDesc **fd,
|
||||
nsISupports** info)
|
||||
{
|
||||
static PRBool firstTime = PR_TRUE;
|
||||
if (firstTime)
|
||||
{
|
||||
nsSSLIOLayerIdentity = PR_GetUniqueIdentity("Cartman layer");
|
||||
nsSSLIOLayerMethods = *PR_GetDefaultIOMethods();
|
||||
|
||||
nsSSLIOLayerMethods.connect = nsSSLIOLayerConnect;
|
||||
nsSSLIOLayerMethods.close = nsSSLIOLayerClose;
|
||||
nsSSLIOLayerMethods.read = nsSSLIOLayerRead;
|
||||
nsSSLIOLayerMethods.write = nsSSLIOLayerWrite;
|
||||
|
||||
|
||||
nsresult result = nsServiceManager::GetService( PSM_COMPONENT_PROGID,
|
||||
NS_GET_IID(nsIPSMComponent),
|
||||
(nsISupports**)&gPSMService);
|
||||
if (NS_FAILED(result))
|
||||
return PR_FAILURE;
|
||||
|
||||
firstTime = PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
|
||||
PRFileDesc * sock;
|
||||
PRFileDesc * layer;
|
||||
PRStatus rv;
|
||||
|
||||
/* Get a normal NSPR socket */
|
||||
sock = PR_NewTCPSocket();
|
||||
if (! sock) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
/* disable Nagle algorithm delay for control sockets */
|
||||
PRSocketOptionData sockopt;
|
||||
sockopt.option = PR_SockOpt_NoDelay;
|
||||
sockopt.value.no_delay = PR_TRUE;
|
||||
rv = PR_SetSocketOption(sock, &sockopt);
|
||||
PR_ASSERT(PR_SUCCESS == rv);
|
||||
|
||||
|
||||
layer = PR_CreateIOLayerStub(nsSSLIOLayerIdentity, &nsSSLIOLayerMethods);
|
||||
if (! layer)
|
||||
{
|
||||
PR_Close(sock);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
nsPSMSocketInfo *infoObject = new nsPSMSocketInfo();
|
||||
if (!infoObject)
|
||||
{
|
||||
PR_Close(sock);
|
||||
// clean up IOLayerStub.
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_ADDREF(infoObject);
|
||||
|
||||
infoObject->SetHostName((char*)host);
|
||||
infoObject->SetHostPort(port);
|
||||
infoObject->SetProxyName((char*)proxyHost);
|
||||
infoObject->SetProxyPort(proxyPort);
|
||||
|
||||
layer->secret = (PRFilePrivate*) infoObject;
|
||||
rv = PR_PushIOLayer(sock, PR_GetLayersIdentity(sock), layer);
|
||||
|
||||
if (rv == PR_SUCCESS)
|
||||
{
|
||||
*fd = sock;
|
||||
*info = infoObject;
|
||||
NS_ADDREF(*info);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
PR_Close(sock);
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
@@ -1,94 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsSSLSocketProvider.h"
|
||||
#include "nsSSLIOLayer.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsSSLSocketProvider::nsSSLSocketProvider()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSSLSocketProvider::Init()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsSSLSocketProvider::~nsSSLSocketProvider()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS2(nsSSLSocketProvider, nsISocketProvider, nsISSLSocketProvider);
|
||||
|
||||
NS_METHOD
|
||||
nsSSLSocketProvider::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsSSLSocketProvider * inst;
|
||||
|
||||
if (NULL == aResult) {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
return rv;
|
||||
}
|
||||
*aResult = NULL;
|
||||
if (NULL != aOuter) {
|
||||
rv = NS_ERROR_NO_AGGREGATION;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_NEWXPCOM(inst, nsSSLSocketProvider);
|
||||
if (NULL == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(inst);
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSSLSocketProvider::NewSocket(const char *host,
|
||||
PRInt32 port,
|
||||
const char *proxyHost,
|
||||
PRInt32 proxyPort,
|
||||
PRFileDesc **_result,
|
||||
nsISupports **securityInfo)
|
||||
{
|
||||
nsresult rv = nsSSLIOLayerNewSocket(host,
|
||||
port,
|
||||
proxyHost,
|
||||
proxyPort,
|
||||
_result,
|
||||
securityInfo);
|
||||
|
||||
return (NS_FAILED(rv)) ? NS_ERROR_SOCKET_CREATE_FAILED : NS_OK;
|
||||
}
|
||||
@@ -1,654 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998-2000 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
* Stuart Parmenter <pavlov@netscape.com>
|
||||
*/
|
||||
|
||||
#include "nspr.h"
|
||||
#include "prlog.h"
|
||||
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsSecureBrowserUIImpl.h"
|
||||
#include "nsIPSMComponent.h"
|
||||
#include "nsPSMComponent.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsIServiceManager.h"
|
||||
|
||||
#include "nsIScriptGlobalObject.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIDocumentLoader.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIDocumentViewer.h"
|
||||
#include "nsCURILoader.h"
|
||||
#include "nsIDocument.h"
|
||||
#include "nsIDOMHTMLDocument.h"
|
||||
#include "nsIDOMXULDocument.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIContent.h"
|
||||
#include "nsIWebProgress.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIPSMSocketInfo.h"
|
||||
|
||||
#include "nsIURI.h"
|
||||
|
||||
#include "prmem.h"
|
||||
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsICommonDialogs.h"
|
||||
#include "nsIPref.h"
|
||||
|
||||
#include "nsIFormSubmitObserver.h"
|
||||
|
||||
static NS_DEFINE_CID(kCStringBundleServiceCID, NS_STRINGBUNDLESERVICE_CID);
|
||||
static NS_DEFINE_CID(kCommonDialogsCID, NS_CommonDialog_CID );
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
|
||||
#define ENTER_SITE_PREF "security.warn_entering_secure"
|
||||
#define LEAVE_SITE_PREF "security.warn_leaving_secure"
|
||||
#define MIXEDCONTENT_PREF "security.warn_viewing_mixed"
|
||||
#define INSECURE_SUBMIT_PREF "security.warn_submit_insecure"
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
//
|
||||
// Log module for nsSecureBroswerUI logging...
|
||||
//
|
||||
// To enable logging (see prlog.h for full details):
|
||||
//
|
||||
// set NSPR_LOG_MODULES=nsSecureBroswerUI:5
|
||||
// set NSPR_LOG_FILE=nspr.log
|
||||
//
|
||||
// this enables PR_LOG_DEBUG level information and places all output in
|
||||
// the file nspr.log
|
||||
//
|
||||
PRLogModuleInfo* gSecureDocLog = nsnull;
|
||||
#endif /* PR_LOGGING */
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsSecureBrowserUIImpl * inst;
|
||||
|
||||
if (NULL == aResult) {
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
return rv;
|
||||
}
|
||||
*aResult = NULL;
|
||||
if (NULL != aOuter) {
|
||||
rv = NS_ERROR_NO_AGGREGATION;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_NEWXPCOM(inst, nsSecureBrowserUIImpl);
|
||||
if (NULL == inst) {
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
return rv;
|
||||
}
|
||||
NS_ADDREF(inst);
|
||||
rv = inst->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(inst);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsSecureBrowserUIImpl::nsSecureBrowserUIImpl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
if (nsnull == gSecureDocLog) {
|
||||
gSecureDocLog = PR_NewLogModule("nsSecureBroswerUI");
|
||||
}
|
||||
#endif /* PR_LOGGING */
|
||||
|
||||
|
||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
||||
mLastPSMStatus = nsnull;
|
||||
mCurrentURI = nsnull;
|
||||
mSecurityButton = nsnull;
|
||||
}
|
||||
|
||||
nsSecureBrowserUIImpl::~nsSecureBrowserUIImpl()
|
||||
{
|
||||
PR_FREEIF(mLastPSMStatus);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS4(nsSecureBrowserUIImpl,
|
||||
nsSecureBrowserUI,
|
||||
nsIWebProgressListener,
|
||||
nsIFormSubmitObserver,
|
||||
nsIObserver);
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Init(nsIDOMWindow *window, nsIDOMElement *button)
|
||||
{
|
||||
mSecurityButton = button;
|
||||
mWindow = window;
|
||||
|
||||
nsresult rv = nsServiceManager::GetService( kPrefCID,
|
||||
NS_GET_IID(nsIPref),
|
||||
getter_AddRefs(mPref));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIStringBundleService, service, kCStringBundleServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsILocale* locale = nsnull;
|
||||
rv = service->CreateBundle(SECURITY_STRING_BUNDLE_URL, locale, getter_AddRefs(mStringBundle));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// hook up to the form post notifications:
|
||||
nsIObserverService *svc = 0;
|
||||
rv = nsServiceManager::GetService(NS_OBSERVERSERVICE_PROGID,
|
||||
NS_GET_IID(nsIObserverService),
|
||||
(nsISupports**)&svc );
|
||||
if (NS_SUCCEEDED(rv) && svc) {
|
||||
nsString topic; topic.AssignWithConversion(NS_FORMSUBMIT_SUBJECT);
|
||||
rv = svc->AddObserver( this, topic.GetUnicode());
|
||||
nsServiceManager::ReleaseService( NS_OBSERVERSERVICE_PROGID, svc );
|
||||
}
|
||||
|
||||
// hook up to the webprogress notifications.
|
||||
nsCOMPtr<nsIDocShell> docShell;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> sgo = do_QueryInterface(window);
|
||||
if (!sgo) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
sgo->GetDocShell(getter_AddRefs(docShell));
|
||||
if (!docShell) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsCOMPtr<nsIWebProgress> wp = do_GetInterface(docShell);
|
||||
if (!wp) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
wp->AddProgressListener(NS_STATIC_CAST(nsIWebProgressListener*,this));
|
||||
|
||||
mInitByLocationChange = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::DisplayPageInfoUI()
|
||||
{
|
||||
nsresult res;
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
nsXPIDLCString host;
|
||||
if (mCurrentURI)
|
||||
mCurrentURI->GetHost(getter_Copies(host));
|
||||
|
||||
return psm->DisplaySecurityAdvisor(mLastPSMStatus, host);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Observe(nsISupports*, const PRUnichar*, const PRUnichar*)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
|
||||
static nsresult IsChildOfDomWindow(nsIDOMWindow *parent, nsIDOMWindow *child, PRBool* value)
|
||||
{
|
||||
*value = PR_FALSE;
|
||||
|
||||
if (parent == child)
|
||||
{
|
||||
*value = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> childsParent;
|
||||
child->GetParent(getter_AddRefs(childsParent));
|
||||
|
||||
if (childsParent && childsParent.get() != child)
|
||||
IsChildOfDomWindow(parent, childsParent, value);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::Notify(nsIContent* formNode, nsIDOMWindow* window, nsIURI* actionURL)
|
||||
{
|
||||
// Return NS_OK unless we want to prevent this form from submitting.
|
||||
|
||||
if (!window || !actionURL || !formNode) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIDocument> document;
|
||||
formNode->GetDocument(*getter_AddRefs(document));
|
||||
if (!document) return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIScriptGlobalObject> globalObject;
|
||||
document->GetScriptGlobalObject(getter_AddRefs(globalObject));
|
||||
nsCOMPtr<nsIDOMWindow> postingWindow = do_QueryInterface(globalObject);
|
||||
|
||||
PRBool isChild;
|
||||
IsChildOfDomWindow(mWindow, postingWindow, &isChild);
|
||||
|
||||
if (!isChild)
|
||||
return NS_OK;
|
||||
|
||||
PRBool okayToPost;
|
||||
nsresult res = CheckPost(actionURL, &okayToPost);
|
||||
|
||||
if (NS_SUCCEEDED(res) && okayToPost)
|
||||
return NS_OK;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// nsIWebProgressListener
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnProgressChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
PRInt32 aCurSelfProgress,
|
||||
PRInt32 aMaxSelfProgress,
|
||||
PRInt32 aCurTotalProgress,
|
||||
PRInt32 aMaxTotalProgress)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnStateChange(nsIWebProgress* aWebProgress,
|
||||
nsIRequest* aRequest,
|
||||
PRInt32 aProgressStateFlags,
|
||||
nsresult aStatus)
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
|
||||
if (aRequest == nsnull || !mSecurityButton || !mPref)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
// Get the channel from the request...
|
||||
// If the request is not network based, then ignore it.
|
||||
nsCOMPtr<nsIChannel> channel;
|
||||
channel = do_QueryInterface(aRequest, &res);
|
||||
if (NS_FAILED(res))
|
||||
return NS_OK;
|
||||
|
||||
nsCOMPtr<nsIURI> loadingURI;
|
||||
channel->GetURI(getter_AddRefs(loadingURI));
|
||||
|
||||
#if defined(DEBUG)
|
||||
nsXPIDLCString temp;
|
||||
loadingURI->GetSpec(getter_Copies(temp));
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnStateChange: %x :%s\n", this, aProgressStateFlags,(const char*)temp));
|
||||
#endif
|
||||
|
||||
// A Document is starting to load...
|
||||
if ((aProgressStateFlags & flag_start) &&
|
||||
(aProgressStateFlags & flag_is_network))
|
||||
{
|
||||
// starting to load a webpage
|
||||
PR_FREEIF(mLastPSMStatus); mLastPSMStatus = nsnull;
|
||||
|
||||
mIsSecureDocument = mMixContentAlertShown = mIsDocumentBroken = PR_FALSE;
|
||||
|
||||
res = CheckProtocolContextSwitch( loadingURI, mCurrentURI);
|
||||
return res;
|
||||
}
|
||||
|
||||
// A document has finished loading
|
||||
if ((aProgressStateFlags & flag_stop) &&
|
||||
(aProgressStateFlags & flag_is_network) &&
|
||||
mIsSecureDocument)
|
||||
{
|
||||
if (!mIsDocumentBroken) // and status is okay FIX
|
||||
{
|
||||
// qi for the psm information about this channel load.
|
||||
nsCOMPtr<nsISupports> info;
|
||||
channel->GetSecurityInfo(getter_AddRefs(info));
|
||||
nsCOMPtr<nsIPSMSocketInfo> psmInfo = do_QueryInterface(info);
|
||||
if (psmInfo)
|
||||
{
|
||||
// Everything looks okay. Lets stash the picked status.
|
||||
PR_FREEIF(mLastPSMStatus);
|
||||
res = psmInfo->GetPickledStatus(&mLastPSMStatus);
|
||||
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: Icon set to lock\n", this));
|
||||
res = mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("high") );
|
||||
return res;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: Icon set to broken\n", this));
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
res = mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("broken"));
|
||||
return res;
|
||||
}
|
||||
|
||||
/// if (aProgressStateFlags == nsIWebProgress::flag_net_redirecting)
|
||||
/// {
|
||||
/// // need to implmentent.
|
||||
/// }
|
||||
|
||||
// don't need to do anything more if the page is broken or not secure...
|
||||
|
||||
if (!mIsSecureDocument || mIsDocumentBroken)
|
||||
return NS_OK;
|
||||
|
||||
// A URL is starting to load...
|
||||
if ((aProgressStateFlags & flag_start) &&
|
||||
(aProgressStateFlags & flag_is_request))
|
||||
{ // check to see if we are going to mix content.
|
||||
return CheckMixedContext(loadingURI);
|
||||
}
|
||||
|
||||
// A URL has finished loading...
|
||||
if ((aProgressStateFlags & flag_stop) &&
|
||||
(aProgressStateFlags & flag_is_request))
|
||||
{
|
||||
if (1) // FIX status from the flag...
|
||||
{
|
||||
nsCOMPtr<nsISupports> info;
|
||||
channel->GetSecurityInfo(getter_AddRefs(info));
|
||||
nsCOMPtr<nsIPSMSocketInfo> psmInfo = do_QueryInterface(info, &res);
|
||||
|
||||
// qi for the psm information about this channel load.
|
||||
if (psmInfo) {
|
||||
return NS_OK;
|
||||
}
|
||||
}
|
||||
|
||||
PR_LOG(gSecureDocLog, PR_LOG_DEBUG, ("SecureUI:%p: OnStateChange - Icon set to broken\n", this));
|
||||
mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("broken") );
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsSecureBrowserUIImpl::OnLocationChange(nsIURI* aLocation)
|
||||
{
|
||||
mCurrentURI = aLocation;
|
||||
|
||||
if (mInitByLocationChange)
|
||||
{
|
||||
IsURLHTTPS(mCurrentURI, &mIsSecureDocument);
|
||||
mInitByLocationChange = PR_FALSE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::IsURLHTTPS(nsIURI* aURL, PRBool* value)
|
||||
{
|
||||
*value = PR_FALSE;
|
||||
|
||||
if (!aURL)
|
||||
return NS_OK;
|
||||
|
||||
char* scheme;
|
||||
aURL->GetScheme(&scheme);
|
||||
|
||||
if (scheme == nsnull)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if ( PL_strncasecmp(scheme, "https", 5) == 0 )
|
||||
*value = PR_TRUE;
|
||||
|
||||
nsMemory::Free(scheme);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void nsSecureBrowserUIImpl::GetBundleString(const nsString& name, nsString &outString)
|
||||
{
|
||||
if (mStringBundle && name.Length() > 0) {
|
||||
PRUnichar *ptrv = nsnull;
|
||||
if (NS_SUCCEEDED(mStringBundle->GetStringFromName(name.GetUnicode(), &ptrv)))
|
||||
outString = ptrv;
|
||||
else
|
||||
outString.SetLength(0);;
|
||||
|
||||
nsMemory::Free(ptrv);
|
||||
|
||||
} else {
|
||||
outString.SetLength(0);;
|
||||
}
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::CheckProtocolContextSwitch( nsIURI* newURI, nsIURI* oldURI)
|
||||
{
|
||||
nsresult res;
|
||||
PRBool isNewSchemeSecure, isOldSchemeSecure, boolpref;
|
||||
|
||||
res = IsURLHTTPS(oldURI, &isOldSchemeSecure);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
res = IsURLHTTPS(newURI, &isNewSchemeSecure);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
// Check to see if we are going from a secure page to and insecure page
|
||||
if ( !isNewSchemeSecure && isOldSchemeSecure)
|
||||
{
|
||||
mSecurityButton->RemoveAttribute( NS_ConvertASCIItoUCS2("level") );
|
||||
|
||||
if ((mPref->GetBoolPref(LEAVE_SITE_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref)
|
||||
{
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("LeaveSiteMessage"), message);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
dialog->AlertCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue);
|
||||
|
||||
if (!outCheckValue) {
|
||||
mPref->SetBoolPref(LEAVE_SITE_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
}
|
||||
}
|
||||
// check to see if we are going from an insecure page to a secure one.
|
||||
else if (isNewSchemeSecure && !isOldSchemeSecure)
|
||||
{
|
||||
if ((mPref->GetBoolPref(ENTER_SITE_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref)
|
||||
{
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("EnterSiteMessage"), message);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
dialog->AlertCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue);
|
||||
|
||||
if (!outCheckValue)
|
||||
{
|
||||
mPref->SetBoolPref(ENTER_SITE_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &res);
|
||||
if (NS_FAILED(res))
|
||||
return res;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
mIsSecureDocument = isNewSchemeSecure;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::CheckMixedContext(nsIURI* nextURI)
|
||||
{
|
||||
PRBool secure;
|
||||
|
||||
nsresult rv = IsURLHTTPS(nextURI, &secure);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
if (!secure && mIsSecureDocument)
|
||||
{
|
||||
mIsDocumentBroken = PR_TRUE;
|
||||
mSecurityButton->SetAttribute( NS_ConvertASCIItoUCS2("level"), NS_ConvertASCIItoUCS2("broken") );
|
||||
|
||||
if (!mPref) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
PRBool boolpref;
|
||||
if ((mPref->GetBoolPref(MIXEDCONTENT_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref && !mMixContentAlertShown)
|
||||
{
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("MixedContentMessage"), message);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
|
||||
dialog->AlertCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue);
|
||||
|
||||
if (!outCheckValue) {
|
||||
mPref->SetBoolPref(MIXEDCONTENT_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
|
||||
mMixContentAlertShown = PR_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsSecureBrowserUIImpl::CheckPost(nsIURI *actionURL, PRBool *okayToPost)
|
||||
{
|
||||
PRBool secure;
|
||||
|
||||
nsresult rv = IsURLHTTPS(actionURL, &secure);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
// if we are posting to a secure link from a secure page, all is okay.
|
||||
if (secure && mIsSecureDocument)
|
||||
return NS_OK;
|
||||
|
||||
|
||||
PRBool boolpref;
|
||||
|
||||
// posting to a non https URL.
|
||||
if ((mPref->GetBoolPref(INSECURE_SUBMIT_PREF, &boolpref) != 0))
|
||||
boolpref = PR_TRUE;
|
||||
|
||||
if (boolpref) {
|
||||
NS_WITH_SERVICE(nsICommonDialogs, dialog, kCommonDialogsCID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsAutoString windowTitle, message, dontShowAgain;
|
||||
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("Title"), windowTitle);
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("DontShowAgain"), dontShowAgain);
|
||||
|
||||
// posting to insecure webpage from a secure webpage.
|
||||
if (!secure && mIsSecureDocument && !mIsDocumentBroken) {
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("PostToInsecure"), message);
|
||||
} else { // anything else, post generic warning
|
||||
GetBundleString(NS_ConvertASCIItoUCS2("PostToInsecureFromInsecure"), message);
|
||||
}
|
||||
|
||||
PRBool outCheckValue = PR_TRUE;
|
||||
dialog->ConfirmCheck(mWindow,
|
||||
windowTitle.GetUnicode(),
|
||||
message.GetUnicode(),
|
||||
dontShowAgain.GetUnicode(),
|
||||
&outCheckValue,
|
||||
okayToPost);
|
||||
|
||||
if (!outCheckValue) {
|
||||
mPref->SetBoolPref(INSECURE_SUBMIT_PREF, PR_FALSE);
|
||||
NS_WITH_SERVICE(nsIPSMComponent, psm, PSM_COMPONENT_PROGID, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
psm->PassPrefs();
|
||||
}
|
||||
} else {
|
||||
*okayToPost = PR_TRUE;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,108 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Hubbie Shaw
|
||||
* Doug Turner <dougt@netscape.com>
|
||||
*/
|
||||
|
||||
#ifndef nsSecureBrowserUIImpl_h_
|
||||
#define nsSecureBrowserUIImpl_h_
|
||||
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIObserver.h"
|
||||
#include "nsIDocumentLoaderObserver.h"
|
||||
#include "nsIDOMElement.h"
|
||||
#include "nsIDOMWindow.h"
|
||||
#include "nsIStringBundle.h"
|
||||
#include "nsISecureBrowserUI.h"
|
||||
#include "nsIDocShell.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIWebProgressListener.h"
|
||||
#include "nsIFormSubmitObserver.h"
|
||||
#include "nsIURI.h"
|
||||
|
||||
#define NS_SECURE_BROWSER_DOCOBSERVER_CLASSNAME "Mozilla Secure Browser Doc Observer"
|
||||
|
||||
#define NS_SECURE_BROWSER_DOCOBSERVER_CID \
|
||||
{0x97c06c30, 0xa145, 0x11d3, \
|
||||
{0x8c, 0x7c, 0x00, 0x60, 0x97, 0x92, 0x27, 0x8c}}
|
||||
|
||||
#define NS_SECURE_BROWSER_DOCOBSERVER_PROGID "component://netscape/secure_browser_docobserver"
|
||||
|
||||
|
||||
class nsSecureBrowserUIImpl : public nsSecureBrowserUI,
|
||||
public nsIWebProgressListener,
|
||||
public nsIFormSubmitObserver,
|
||||
public nsIObserver
|
||||
{
|
||||
public:
|
||||
|
||||
nsSecureBrowserUIImpl();
|
||||
virtual ~nsSecureBrowserUIImpl();
|
||||
|
||||
static NS_METHOD Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIWEBPROGRESSLISTENER
|
||||
NS_DECL_NSSECUREBROWSERUI
|
||||
|
||||
|
||||
// nsIObserver
|
||||
NS_DECL_NSIOBSERVER
|
||||
NS_IMETHOD Notify(nsIContent* formNode, nsIDOMWindow* window, nsIURI *actionURL);
|
||||
|
||||
protected:
|
||||
|
||||
nsCOMPtr<nsIDOMWindow> mWindow;
|
||||
nsCOMPtr<nsIDOMElement> mSecurityButton;
|
||||
nsCOMPtr<nsIDocumentLoaderObserver> mOldWebShellObserver;
|
||||
nsCOMPtr<nsIPref> mPref;
|
||||
nsCOMPtr<nsIStringBundle> mStringBundle;
|
||||
|
||||
nsCOMPtr<nsIURI> mCurrentURI;
|
||||
|
||||
PRBool mIsSecureDocument; // is https loaded
|
||||
PRBool mIsDocumentBroken; //
|
||||
PRBool mMixContentAlertShown;
|
||||
|
||||
PRBool mInitByLocationChange;
|
||||
|
||||
char* mLastPSMStatus;
|
||||
|
||||
|
||||
void GetBundleString(const nsString& name, nsString &outString);
|
||||
nsresult LoadStringBundle();
|
||||
|
||||
nsresult CheckProtocolContextSwitch( nsIURI* newURI, nsIURI* oldURI);
|
||||
nsresult CheckMixedContext(nsIURI* nextURI);
|
||||
nsresult CheckPost(nsIURI *actionURL, PRBool *okayToPost);
|
||||
nsresult IsURLHTTPS(nsIURI* aURL, PRBool *value);
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsSecureBrowserUIImpl_h_ */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
39
mozilla/modules/libjar/nsIJARChannel.idl
Normal file
39
mozilla/modules/libjar/nsIJARChannel.idl
Normal file
@@ -0,0 +1,39 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIChannel.idl"
|
||||
|
||||
interface nsISimpleEnumerator;
|
||||
|
||||
[scriptable, uuid(c7e410d1-85f2-11d3-9f63-006008a6efe9)]
|
||||
interface nsIJARChannel : nsIChannel
|
||||
{
|
||||
|
||||
/**
|
||||
* Enumerates all the entries in the JAR (the root URI).
|
||||
* ARGUMENTS:
|
||||
* aRoot - a string representing the root dir to enumerate from
|
||||
* or null to enumerate the whole thing.
|
||||
*/
|
||||
nsISimpleEnumerator EnumerateEntries(in string aRoot);
|
||||
|
||||
};
|
||||
@@ -1,9 +1,9 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
@@ -17,23 +17,16 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _NSSSLIOLAYER_H
|
||||
#define _NSSSLIOLAYER_H
|
||||
#include "nsIProtocolHandler.idl"
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "prio.h"
|
||||
#include "nsIPSMSocketInfo.h"
|
||||
[scriptable, uuid(92c3b42c-98c4-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIJARProtocolHandler : nsIProtocolHandler {
|
||||
|
||||
// define taken from 4.x cartman glue code.
|
||||
#define SSMSTRING_PADDED_LENGTH(x) ((((x)+3)/4)*4)
|
||||
|
||||
nsresult nsSSLIOLayerNewSocket(const char *host,
|
||||
PRInt32 port,
|
||||
const char *proxyHost,
|
||||
PRInt32 proxyPort,
|
||||
PRFileDesc **fd,
|
||||
nsISupports **securityInfo);
|
||||
#endif /* _NSSSLIOLAYER_H */
|
||||
/**
|
||||
* Add any jar-specific methods here later.
|
||||
*/
|
||||
|
||||
};
|
||||
42
mozilla/modules/libjar/nsIJARURI.idl
Normal file
42
mozilla/modules/libjar/nsIJARURI.idl
Normal file
@@ -0,0 +1,42 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsIURI.idl"
|
||||
|
||||
/**
|
||||
* JAR URLs have the following syntax
|
||||
*
|
||||
* jar:<jar-file-uri>!/<jar-entry>
|
||||
*
|
||||
* EXAMPLE: jar:http://www.big.com/blue.jar!/ocean.html
|
||||
*/
|
||||
[scriptable, uuid(c7e410d3-85f2-11d3-9f63-006008a6efe9)]
|
||||
interface nsIJARURI : nsIURI {
|
||||
|
||||
/**
|
||||
* Returns the root URI (the one for the actual JAR file) for this JAR.
|
||||
* eg http://www.big.com/blue.jar
|
||||
*/
|
||||
attribute nsIURI JARFile;
|
||||
|
||||
/**
|
||||
* Returns the entry specified for this JAR URI.
|
||||
* eg ocean.html
|
||||
*/
|
||||
attribute string JAREntry;
|
||||
};
|
||||
690
mozilla/modules/libjar/nsJARChannel.cpp
Normal file
690
mozilla/modules/libjar/nsJARChannel.cpp
Normal file
@@ -0,0 +1,690 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*
|
||||
*/
|
||||
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsJARChannel.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIFileTransportService.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsIMIMEService.h"
|
||||
#include "nsAutoLock.h"
|
||||
#include "nsIFileStreams.h"
|
||||
#include "nsIPrincipal.h"
|
||||
#include "nsMimeTypes.h"
|
||||
|
||||
static NS_DEFINE_CID(kFileTransportServiceCID, NS_FILETRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kMIMEServiceCID, NS_MIMESERVICE_CID);
|
||||
static NS_DEFINE_CID(kZipReaderCID, NS_ZIPREADER_CID);
|
||||
static NS_DEFINE_CID(kFileChannelCID, NS_FILECHANNEL_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsJARDownloadObserver : public nsIStreamObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD OnStartRequest(nsIChannel* jarCacheTransport,
|
||||
nsISupports* context) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHOD OnStopRequest(nsIChannel* jarCacheTransport,
|
||||
nsISupports* context,
|
||||
nsresult status,
|
||||
const PRUnichar* aMsg) {
|
||||
nsresult rv = NS_OK;
|
||||
nsAutoMonitor monitor(mJARChannel->mMonitor);
|
||||
|
||||
if (NS_SUCCEEDED(status) && mJARChannel->mJarCacheTransport) {
|
||||
NS_ASSERTION(jarCacheTransport == (mJARChannel->mJarCacheTransport).get(),
|
||||
"wrong transport");
|
||||
// after successfully downloading the jar file to the cache,
|
||||
// start the extraction process:
|
||||
nsCOMPtr<nsIFileChannel> jarCacheFile;
|
||||
rv = NS_NewFileChannel(mJarCacheFile,
|
||||
PR_RDONLY,
|
||||
nsnull, // XXX content type
|
||||
0, // XXX content length
|
||||
mJARChannel->mLoadGroup,
|
||||
mJARChannel->mCallbacks,
|
||||
mJARChannel->mLoadAttributes,
|
||||
nsnull,
|
||||
mJARChannel->mBufferSegmentSize,
|
||||
mJARChannel->mBufferMaxSize,
|
||||
getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJARChannel->ExtractJARElement(jarCacheFile);
|
||||
}
|
||||
mJARChannel->mJarCacheTransport = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsJARDownloadObserver(nsIFile* jarCacheFile, nsJARChannel* jarChannel) {
|
||||
NS_INIT_REFCNT();
|
||||
mJarCacheFile = jarCacheFile;
|
||||
mJARChannel = jarChannel;
|
||||
NS_ADDREF(mJARChannel);
|
||||
}
|
||||
|
||||
virtual ~nsJARDownloadObserver() {
|
||||
NS_RELEASE(mJARChannel);
|
||||
}
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIFile> mJarCacheFile;
|
||||
nsJARChannel* mJARChannel;
|
||||
};
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsJARDownloadObserver, nsIStreamObserver)
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsJARChannel::nsJARChannel()
|
||||
: mCommand(nsnull),
|
||||
mContentType(nsnull),
|
||||
mJAREntry(nsnull),
|
||||
mMonitor(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsJARChannel::~nsJARChannel()
|
||||
{
|
||||
if (mCommand)
|
||||
nsCRT::free(mCommand);
|
||||
if (mContentType)
|
||||
nsCRT::free(mContentType);
|
||||
if (mJAREntry)
|
||||
nsCRT::free(mJAREntry);
|
||||
if (mMonitor)
|
||||
PR_DestroyMonitor(mMonitor);
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS6(nsJARChannel,
|
||||
nsIJARChannel,
|
||||
nsIChannel,
|
||||
nsIRequest,
|
||||
nsIStreamObserver,
|
||||
nsIStreamListener,
|
||||
nsIFileSystem)
|
||||
|
||||
NS_METHOD
|
||||
nsJARChannel::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsJARChannel* jarChannel = new nsJARChannel();
|
||||
if (jarChannel == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(jarChannel);
|
||||
rv = jarChannel->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(jarChannel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::Init(nsIJARProtocolHandler* aHandler,
|
||||
const char* command,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize)
|
||||
{
|
||||
nsresult rv;
|
||||
mURI = do_QueryInterface(uri, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mCommand = nsCRT::strdup(command);
|
||||
if (mCommand == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
mOriginalURI = originalURI ? originalURI : uri;
|
||||
mBufferSegmentSize = bufferSegmentSize;
|
||||
mBufferMaxSize = bufferMaxSize;
|
||||
|
||||
rv = SetLoadAttributes(loadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetLoadGroup(aLoadGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = SetNotificationCallbacks(notificationCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
mMonitor = PR_NewMonitor();
|
||||
if (mMonitor == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIRequest methods
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::IsPending(PRBool* result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::Cancel()
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoMonitor monitor(mMonitor);
|
||||
|
||||
if (mJarCacheTransport) {
|
||||
rv = mJarCacheTransport->Cancel();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mJarCacheTransport = nsnull;
|
||||
}
|
||||
if (mJarExtractionTransport) {
|
||||
rv = mJarExtractionTransport->Cancel();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
mJarExtractionTransport = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::Suspend()
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoMonitor monitor(mMonitor);
|
||||
|
||||
if (mJarCacheTransport) {
|
||||
rv = mJarCacheTransport->Suspend();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (mJarExtractionTransport) {
|
||||
rv = mJarExtractionTransport->Suspend();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::Resume()
|
||||
{
|
||||
nsresult rv;
|
||||
nsAutoMonitor monitor(mMonitor);
|
||||
|
||||
if (mJarCacheTransport) {
|
||||
rv = mJarCacheTransport->Resume();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
if (mJarExtractionTransport) {
|
||||
rv = mJarExtractionTransport->Resume();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIChannel methods
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetOriginalURI(nsIURI* *aOriginalURI)
|
||||
{
|
||||
*aOriginalURI = mOriginalURI;
|
||||
NS_ADDREF(*aOriginalURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetURI(nsIURI* *aURI)
|
||||
{
|
||||
*aURI = mURI;
|
||||
NS_ADDREF(*aURI);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsIInputStream* *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::OpenOutputStream(PRUint32 startPosition, nsIOutputStream* *result)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::AsyncOpen(nsIStreamObserver* observer, nsISupports* ctxt)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
|
||||
nsISupports* ctxt,
|
||||
nsIStreamListener* listener)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = mURI->GetJARFile(getter_AddRefs(mJARBaseURI));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mURI->GetJAREntry(&mJAREntry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIChannel> jarBaseChannel;
|
||||
rv = NS_OpenURI(getter_AddRefs(jarBaseChannel),
|
||||
mJARBaseURI, mLoadGroup, mCallbacks, mLoadAttributes);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileChannel> jarBaseFile = do_QueryInterface(jarBaseChannel, &rv);
|
||||
|
||||
// XXX need to set a state variable here to say we're reading
|
||||
mStartPosition = startPosition;
|
||||
mReadCount = readCount;
|
||||
mUserContext = ctxt;
|
||||
mUserListener = listener;
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// then we've already got a local jar file -- no need to download it
|
||||
rv = ExtractJARElement(jarBaseFile);
|
||||
}
|
||||
else {
|
||||
// otherwise, we need to download the jar file
|
||||
|
||||
nsCOMPtr<nsIFile> jarCacheFile;
|
||||
rv = GetCacheFile(getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool filePresent;
|
||||
|
||||
rv = jarCacheFile->IsFile(&filePresent);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && filePresent)
|
||||
{
|
||||
// then we've already got the file in the local cache -- no need to download it
|
||||
nsCOMPtr<nsIFileChannel> fileChannel;
|
||||
rv = nsComponentManager::CreateInstance(kFileChannelCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileChannel),
|
||||
getter_AddRefs(fileChannel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fileChannel->Init(jarCacheFile,
|
||||
PR_RDONLY,
|
||||
nsnull, // contentType
|
||||
-1, // contentLength
|
||||
nsnull, // loadGroup
|
||||
nsnull, // notificationCallbacks
|
||||
nsIChannel::LOAD_NORMAL,
|
||||
nsnull, // originalURI
|
||||
mBufferSegmentSize,
|
||||
mBufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = ExtractJARElement(fileChannel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsAutoMonitor monitor(mMonitor);
|
||||
|
||||
// use a file transport to serve as a data pump for the download (done
|
||||
// on some other thread)
|
||||
nsCOMPtr<nsIChannel> jarCacheTransport;
|
||||
rv = fts->CreateTransport(jarCacheFile, PR_RDONLY, mCommand,
|
||||
mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mJarCacheTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJarCacheTransport->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIStreamObserver> downloadObserver = new nsJARDownloadObserver(jarCacheFile, this);
|
||||
if (downloadObserver == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsCOMPtr<nsIInputStream> jarBaseIn;
|
||||
rv = jarBaseChannel->OpenInputStream(0, -1, getter_AddRefs(jarBaseIn));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJarCacheTransport->AsyncWrite(jarBaseIn, 0, -1, nsnull, downloadObserver);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::GetCacheFile(nsIFile* *cacheFile)
|
||||
{
|
||||
// XXX change later to use the real network cache
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIFile> jarCacheFile;
|
||||
rv = NS_GetSpecialDirectory("xpcom.currentProcess.componentDirectory",
|
||||
getter_AddRefs(jarCacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
jarCacheFile->Append("jarCache");
|
||||
|
||||
PRBool exists;
|
||||
rv = jarCacheFile->Exists(&exists);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!exists) {
|
||||
rv = jarCacheFile->Create(nsIFile::DIRECTORY_TYPE, 0664);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
}
|
||||
|
||||
nsCOMPtr<nsIURL> jarBaseURL = do_QueryInterface(mJARBaseURI, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char* jarFileName;
|
||||
rv = jarBaseURL->GetFileName(&jarFileName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = jarCacheFile->Append(jarFileName);
|
||||
nsCRT::free(jarFileName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*cacheFile = jarCacheFile;
|
||||
NS_ADDREF(*cacheFile);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARChannel::ExtractJARElement(nsIFileChannel* jarBaseFile)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsAutoMonitor monitor(mMonitor);
|
||||
|
||||
mJARBaseFile = jarBaseFile;
|
||||
|
||||
NS_WITH_SERVICE(nsIFileTransportService, fts, kFileTransportServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = fts->CreateTransportFromFileSystem(this, mCommand,
|
||||
mBufferSegmentSize, mBufferMaxSize,
|
||||
getter_AddRefs(mJarExtractionTransport));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJarExtractionTransport->SetNotificationCallbacks(mCallbacks);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJarExtractionTransport->AsyncRead(mStartPosition, mReadCount, nsnull, this);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::AsyncWrite(nsIInputStream* fromStream, PRUint32 startPosition,
|
||||
PRInt32 writeCount,
|
||||
nsISupports* ctxt,
|
||||
nsIStreamObserver* observer)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetLoadAttributes(PRUint32* aLoadFlags)
|
||||
{
|
||||
*aLoadFlags = mLoadAttributes;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetLoadAttributes(PRUint32 aLoadFlags)
|
||||
{
|
||||
mLoadAttributes = aLoadFlags;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetContentType(char* *aContentType)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (mContentType == nsnull) {
|
||||
char* fileName = new char[PL_strlen(mJAREntry)+1];
|
||||
PL_strcpy(fileName, mJAREntry);
|
||||
|
||||
if (fileName != nsnull) {
|
||||
PRInt32 len = nsCRT::strlen(fileName);
|
||||
const char* ext = nsnull;
|
||||
for (PRInt32 i = len; i >= 0; i--) {
|
||||
if (fileName[i] == '.') {
|
||||
ext = &fileName[i + 1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (ext) {
|
||||
NS_WITH_SERVICE(nsIMIMEService, mimeServ, kMIMEServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = mimeServ->GetTypeFromExtension(ext, &mContentType);
|
||||
}
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_FAILURE;
|
||||
|
||||
nsCRT::free(fileName);
|
||||
}
|
||||
else {
|
||||
rv = NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
mContentType = nsCRT::strdup(UNKNOWN_CONTENT_TYPE);
|
||||
if (mContentType == nsnull)
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
else
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
*aContentType = nsCRT::strdup(mContentType);
|
||||
if (*aContentType == nsnull)
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetContentType(const char *aContentType)
|
||||
{
|
||||
if (mContentType) {
|
||||
nsCRT::free(mContentType);
|
||||
}
|
||||
|
||||
mContentType = nsCRT::strdup(aContentType);
|
||||
if (!mContentType) return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetContentLength(PRInt32* aContentLength)
|
||||
{
|
||||
if (mContentLength == -1)
|
||||
return NS_ERROR_FAILURE;
|
||||
*aContentLength = mContentLength;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
||||
{
|
||||
*aLoadGroup = mLoadGroup;
|
||||
NS_IF_ADDREF(*aLoadGroup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
||||
{
|
||||
mLoadGroup = aLoadGroup;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetOwner(nsISupports* *aOwner)
|
||||
{
|
||||
nsCOMPtr<nsIPrincipal> principal;
|
||||
nsresult rv = mJAR->GetPrincipal(mJAREntry, getter_AddRefs(principal));
|
||||
if (NS_SUCCEEDED(rv) && principal)
|
||||
rv = principal->QueryInterface(NS_GET_IID(nsISupports), (void **)aOwner);
|
||||
else
|
||||
*aOwner = nsnull;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetOwner(nsISupports* aOwner)
|
||||
{
|
||||
//XXX: is this OK?
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetNotificationCallbacks(nsIInterfaceRequestor* *aNotificationCallbacks)
|
||||
{
|
||||
*aNotificationCallbacks = mCallbacks.get();
|
||||
NS_IF_ADDREF(*aNotificationCallbacks);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::SetNotificationCallbacks(nsIInterfaceRequestor* aNotificationCallbacks)
|
||||
{
|
||||
mCallbacks = aNotificationCallbacks;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIStreamObserver methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::OnStartRequest(nsIChannel* jarExtractionTransport,
|
||||
nsISupports* context)
|
||||
{
|
||||
return mUserListener->OnStartRequest(this, mUserContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::OnStopRequest(nsIChannel* jarExtractionTransport,
|
||||
nsISupports* context,
|
||||
nsresult status,
|
||||
const PRUnichar* aMsg)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = mUserListener->OnStopRequest(this, mUserContext, status, aMsg);
|
||||
mJarExtractionTransport = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIStreamListener methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::OnDataAvailable(nsIChannel* jarCacheTransport,
|
||||
nsISupports* context,
|
||||
nsIInputStream *inStr,
|
||||
PRUint32 sourceOffset,
|
||||
PRUint32 count)
|
||||
{
|
||||
return mUserListener->OnDataAvailable(this, mUserContext,
|
||||
inStr, sourceOffset, count);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIFileSystem methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::Open(char* *contentType, PRInt32 *contentLength)
|
||||
{
|
||||
nsresult rv;
|
||||
rv = nsComponentManager::CreateInstance(kZipReaderCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIZipReader),
|
||||
getter_AddRefs(mJAR));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFile> fs;
|
||||
rv = mJARBaseFile->GetFile(getter_AddRefs(fs));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJAR->Init(fs);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = mJAR->Open();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// If this fails, GetOwner will fail, but otherwise we can continue.
|
||||
mJAR->ParseManifest();
|
||||
|
||||
nsCOMPtr<nsIZipEntry> entry;
|
||||
rv = mJAR->GetEntry(mJAREntry, getter_AddRefs(entry));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = entry->GetRealSize((PRUint32*)contentLength);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return GetContentType(contentType);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::Close(nsresult status)
|
||||
{
|
||||
mJAR = null_nsCOMPtr();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetInputStream(nsIInputStream* *aInputStream)
|
||||
{
|
||||
return mJAR->GetInputStream(mJAREntry, aInputStream);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::GetOutputStream(nsIOutputStream* *aOutputStream)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIJARChannel methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARChannel::EnumerateEntries(const char *aRoot, nsISimpleEnumerator **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
115
mozilla/modules/libjar/nsJARChannel.h
Normal file
115
mozilla/modules/libjar/nsJARChannel.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsJARChannel_h__
|
||||
#define nsJARChannel_h__
|
||||
|
||||
#include "nsIJARChannel.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIJARProtocolHandler.h"
|
||||
#include "nsIJARURI.h"
|
||||
#include "nsIFileSystem.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIZipReader.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIFile.h"
|
||||
#include "prmon.h"
|
||||
|
||||
class nsIFileChannel;
|
||||
|
||||
#define NS_JARCHANNEL_CID \
|
||||
{ /* 0xc7e410d5-0x85f2-11d3-9f63-006008a6efe9 */ \
|
||||
0xc7e410d5, \
|
||||
0x85f2, \
|
||||
0x11d3, \
|
||||
{0x9f, 0x63, 0x00, 0x60, 0x08, 0xa6, 0xef, 0xe9} \
|
||||
}
|
||||
|
||||
#define JAR_DIRECTORY "jarCache"
|
||||
|
||||
class nsJARChannel : public nsIJARChannel,
|
||||
public nsIStreamListener,
|
||||
public nsIFileSystem
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIREQUEST
|
||||
NS_DECL_NSICHANNEL
|
||||
NS_DECL_NSIJARCHANNEL
|
||||
NS_DECL_NSISTREAMOBSERVER
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSIFILESYSTEM
|
||||
|
||||
nsJARChannel();
|
||||
virtual ~nsJARChannel();
|
||||
|
||||
// Define a Create method to be used with a factory:
|
||||
static NS_METHOD
|
||||
Create(nsISupports* aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init(nsIJARProtocolHandler* aHandler,
|
||||
const char* command,
|
||||
nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize);
|
||||
|
||||
nsresult ExtractJARElement(nsIFileChannel* jarFileChannel);
|
||||
nsresult GetCacheFile(nsIFile* *cacheFile);
|
||||
|
||||
friend class nsJARDownloadObserver;
|
||||
|
||||
protected:
|
||||
char* mCommand;
|
||||
nsCOMPtr<nsIJARURI> mURI;
|
||||
nsCOMPtr<nsILoadGroup> mLoadGroup;
|
||||
nsCOMPtr<nsIInterfaceRequestor> mCallbacks;
|
||||
nsCOMPtr<nsIURI> mOriginalURI;
|
||||
nsLoadFlags mLoadAttributes;
|
||||
|
||||
PRUint32 mStartPosition;
|
||||
PRInt32 mReadCount;
|
||||
nsCOMPtr<nsISupports> mUserContext;
|
||||
nsCOMPtr<nsIStreamListener> mUserListener;
|
||||
|
||||
char* mContentType;
|
||||
PRInt32 mContentLength;
|
||||
nsCOMPtr<nsIURI> mJARBaseURI;
|
||||
nsCOMPtr<nsIFileChannel> mJARBaseFile;
|
||||
char* mJAREntry;
|
||||
nsCOMPtr<nsIZipReader> mJAR;
|
||||
PRUint32 mBufferSegmentSize;
|
||||
PRUint32 mBufferMaxSize;
|
||||
|
||||
PRMonitor* mMonitor;
|
||||
nsCOMPtr<nsIChannel> mJarCacheTransport;
|
||||
nsCOMPtr<nsIChannel> mJarExtractionTransport;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsJARChannel_h__
|
||||
146
mozilla/modules/libjar/nsJARProtocolHandler.cpp
Normal file
146
mozilla/modules/libjar/nsJARProtocolHandler.cpp
Normal file
@@ -0,0 +1,146 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsJARProtocolHandler.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsJARURI.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsJARChannel.h"
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
static NS_DEFINE_CID(kJARUriCID, NS_JARURI_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsJARProtocolHandler::nsJARProtocolHandler()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARProtocolHandler::Init()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsJARProtocolHandler::~nsJARProtocolHandler()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsJARProtocolHandler,
|
||||
nsIJARProtocolHandler,
|
||||
nsIProtocolHandler)
|
||||
|
||||
NS_METHOD
|
||||
nsJARProtocolHandler::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsJARProtocolHandler* ph = new nsJARProtocolHandler();
|
||||
if (ph == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(ph);
|
||||
nsresult rv = ph->Init();
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = ph->QueryInterface(aIID, aResult);
|
||||
}
|
||||
NS_RELEASE(ph);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIProtocolHandler methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARProtocolHandler::GetScheme(char* *result)
|
||||
{
|
||||
*result = nsCRT::strdup("jar");
|
||||
if (*result == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARProtocolHandler::GetDefaultPort(PRInt32 *result)
|
||||
{
|
||||
*result = -1; // no port for JAR: URLs
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
|
||||
nsIURI **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIURI* url;
|
||||
if (aBaseURI) {
|
||||
rv = aBaseURI->Clone(&url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->SetRelativePath(aSpec);
|
||||
}
|
||||
else {
|
||||
rv = nsJARURI::Create(nsnull, NS_GET_IID(nsIJARURI), (void**)&url);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = url->SetSpec((char*)aSpec);
|
||||
}
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(url);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = url;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARProtocolHandler::NewChannel(const char* verb, nsIURI* uri,
|
||||
nsILoadGroup* aLoadGroup,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsJARChannel* channel;
|
||||
rv = nsJARChannel::Create(nsnull, NS_GET_IID(nsIJARChannel), (void**)&channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->Init(this, verb, uri, aLoadGroup, notificationCallbacks,
|
||||
loadAttributes, originalURI, bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) {
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
*result = channel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
57
mozilla/modules/libjar/nsJARProtocolHandler.h
Normal file
57
mozilla/modules/libjar/nsJARProtocolHandler.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsJARProtocolHandler_h___
|
||||
#define nsJARProtocolHandler_h___
|
||||
|
||||
#include "nsIJARProtocolHandler.h"
|
||||
#include "nsIProtocolHandler.h"
|
||||
#include "nsIJARURI.h"
|
||||
|
||||
#define NS_JARPROTOCOLHANDLER_CID \
|
||||
{ /* 0xc7e410d4-0x85f2-11d3-9f63-006008a6efe9 */ \
|
||||
0xc7e410d4, \
|
||||
0x85f2, \
|
||||
0x11d3, \
|
||||
{0x9f, 0x63, 0x00, 0x60, 0x08, 0xa6, 0xef, 0xe9} \
|
||||
}
|
||||
|
||||
|
||||
class nsJARProtocolHandler : public nsIJARProtocolHandler
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIPROTOCOLHANDLER
|
||||
|
||||
// nsJARProtocolHandler methods:
|
||||
nsJARProtocolHandler();
|
||||
virtual ~nsJARProtocolHandler();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init();
|
||||
|
||||
protected:
|
||||
};
|
||||
|
||||
#endif /* nsJARProtocolHandler_h___ */
|
||||
38
mozilla/modules/libjar/nsJARProtocolModule.cpp
Normal file
38
mozilla/modules/libjar/nsJARProtocolModule.cpp
Normal file
@@ -0,0 +1,38 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
#include "nsIModule.h"
|
||||
#include "nsIGenericFactory.h"
|
||||
#include "nsJARProtocolHandler.h"
|
||||
|
||||
|
||||
static nsModuleComponentInfo components[] =
|
||||
{
|
||||
{ "JAR Protocol Handler",
|
||||
NS_JARPROTOCOLHANDLER_CID,
|
||||
NS_NETWORK_PROTOCOL_PROGID_PREFIX "jar",
|
||||
nsJARProtocolHandler::Create
|
||||
},
|
||||
};
|
||||
|
||||
NS_IMPL_NSGETMODULE("nsJarProtocolModule", components);
|
||||
|
||||
|
||||
384
mozilla/modules/libjar/nsJARURI.cpp
Normal file
384
mozilla/modules/libjar/nsJARURI.cpp
Normal file
@@ -0,0 +1,384 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsJARURI.h"
|
||||
#include "nsNetUtil.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIComponentManager.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIZipReader.h"
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsJARURI::nsJARURI()
|
||||
: mJAREntry(nsnull)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsJARURI::~nsJARURI()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsJARURI, nsIJARURI, nsIURI)
|
||||
|
||||
NS_METHOD
|
||||
nsJARURI::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
|
||||
nsJARURI* uri = new nsJARURI();
|
||||
|
||||
if (uri == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(uri);
|
||||
nsresult rv = uri->Init();
|
||||
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = uri->QueryInterface(aIID, aResult);
|
||||
}
|
||||
NS_RELEASE(uri);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsJARURI::Init()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#define NS_JAR_SCHEME "jar:"
|
||||
#define NS_JAR_DELIMITER "!/"
|
||||
|
||||
nsresult
|
||||
nsJARURI::FormatSpec(const char* entryPath, char* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
char* jarFileSpec;
|
||||
rv = mJARFile->GetSpec(&jarFileSpec);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCString spec(NS_JAR_SCHEME);
|
||||
spec += jarFileSpec;
|
||||
nsCRT::free(jarFileSpec);
|
||||
spec += NS_JAR_DELIMITER;
|
||||
spec += entryPath;
|
||||
|
||||
*result = nsCRT::strdup(spec);
|
||||
return *result ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsURI methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetSpec(char* *aSpec)
|
||||
{
|
||||
return FormatSpec(mJAREntry, aSpec);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetSpec(const char * aSpec)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRUint32 startPos, endPos;
|
||||
rv = serv->ExtractScheme(aSpec, &startPos, &endPos, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (nsCRT::strncmp("jar", &aSpec[startPos], endPos - startPos - 1) != 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
|
||||
// Search backward from the end for the "!/" delimiter. Remember, jar URLs
|
||||
// can nest, e.g.:
|
||||
// jar:jar:http://www.foo.com/bar.jar!/a.jar!/b.html
|
||||
// This gets the b.html document from out of the a.jar file, that's
|
||||
// contained within the bar.jar file.
|
||||
|
||||
nsCAutoString jarPath(aSpec);
|
||||
PRInt32 pos = jarPath.RFind(NS_JAR_DELIMITER);
|
||||
if (pos == -1 || endPos + 1 > (PRUint32)pos)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
|
||||
jarPath.Cut(pos, jarPath.Length());
|
||||
jarPath.Cut(0, endPos);
|
||||
|
||||
rv = serv->NewURI(jarPath, nsnull, getter_AddRefs(mJARFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString entry(aSpec);
|
||||
entry.Cut(0, pos + 2); // 2 == strlen(NS_JAR_DELIMITER)
|
||||
|
||||
rv = serv->ResolveRelativePath(entry, nsnull, &mJAREntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetScheme(char * *aScheme)
|
||||
{
|
||||
*aScheme = nsCRT::strdup("jar");
|
||||
return *aScheme ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetScheme(const char * aScheme)
|
||||
{
|
||||
// doesn't make sense to set the scheme of a jar: URL
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetUsername(char * *aUsername)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetUsername(const char * aUsername)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetPassword(char * *aPassword)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetPassword(const char * aPassword)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetPreHost(char * *aPreHost)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetPreHost(const char * aPreHost)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetHost(char * *aHost)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetHost(const char * aHost)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetPort(PRInt32 *aPort)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetPort(PRInt32 aPort)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetPath(char * *aPath)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetPath(const char * aPath)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetURLParser(nsIURLParser * *aURLParser)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetURLParser(nsIURLParser * aURLParser)
|
||||
{
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::Equals(nsIURI *other, PRBool *result)
|
||||
{
|
||||
nsresult rv;
|
||||
*result = PR_FALSE;
|
||||
|
||||
nsJARURI* otherJAR;
|
||||
rv = other->QueryInterface(NS_GET_IID(nsIJARURI), (void**)&otherJAR);
|
||||
if (NS_FAILED(rv))
|
||||
return NS_OK; // not equal
|
||||
|
||||
nsCOMPtr<nsIURI> otherJARFile;
|
||||
rv = otherJAR->GetJARFile(getter_AddRefs(otherJARFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
PRBool equal;
|
||||
rv = mJARFile->Equals(otherJARFile, &equal);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!equal)
|
||||
return NS_OK; // not equal
|
||||
|
||||
char* otherJAREntry;
|
||||
rv = otherJAR->GetJAREntry(&otherJAREntry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = nsCRT::strcmp(mJAREntry, otherJAREntry) == 0;
|
||||
nsCRT::free(otherJAREntry);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::Clone(nsIURI **result)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIURI> newJARFile;
|
||||
rv = mJARFile->Clone(getter_AddRefs(newJARFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char* newJAREntry = nsCRT::strdup(mJAREntry);
|
||||
if (newJAREntry == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
nsJARURI* uri = new nsJARURI();
|
||||
if (uri == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(uri);
|
||||
uri->mJARFile = newJARFile;
|
||||
uri->mJAREntry = newJAREntry;
|
||||
*result = uri;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetRelativePath(const char *relativePath)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path(mJAREntry);
|
||||
PRInt32 pos = path.RFind("/");
|
||||
if (pos >= 0)
|
||||
path.Truncate(pos + 1);
|
||||
else
|
||||
path = "";
|
||||
|
||||
char* resolvedEntry;
|
||||
rv = serv->ResolveRelativePath(relativePath, path.GetBuffer(),
|
||||
&resolvedEntry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCRT::free(mJAREntry);
|
||||
mJAREntry = resolvedEntry;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::Resolve(const char *relativePath, char **result)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCAutoString path(mJAREntry);
|
||||
PRInt32 pos = path.RFind("/");
|
||||
if (pos >= 0)
|
||||
path.Truncate(pos + 1);
|
||||
else
|
||||
path = "";
|
||||
|
||||
char* resolvedEntry;
|
||||
rv = serv->ResolveRelativePath(relativePath, path.GetBuffer(),
|
||||
&resolvedEntry);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = FormatSpec(resolvedEntry, result);
|
||||
nsCRT::free(resolvedEntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// nsIJARUri methods:
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetJARFile(nsIURI* *jarFile)
|
||||
{
|
||||
*jarFile = mJARFile;
|
||||
NS_ADDREF(*jarFile);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetJARFile(nsIURI* jarFile)
|
||||
{
|
||||
mJARFile = jarFile;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::GetJAREntry(char* *entryPath)
|
||||
{
|
||||
nsCAutoString entry(mJAREntry);
|
||||
PRInt32 pos = entry.RFindCharInSet("#?;");
|
||||
if (pos >= 0)
|
||||
entry.Truncate(pos);
|
||||
*entryPath = entry.ToNewCString();
|
||||
return *entryPath ? NS_OK : NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsJARURI::SetJAREntry(const char* entryPath)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
if (mJAREntry)
|
||||
nsCRT::free(mJAREntry);
|
||||
|
||||
rv = serv->ResolveRelativePath(entryPath, nsnull, &mJAREntry);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
55
mozilla/modules/libjar/nsJARURI.h
Normal file
55
mozilla/modules/libjar/nsJARURI.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsJARURI_h__
|
||||
#define nsJARURI_h__
|
||||
|
||||
#include "nsIJARURI.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
#define NS_JARURI_CID \
|
||||
{ /* 0xc7e410d7-0x85f2-11d3-9f63-006008a6efe9 */ \
|
||||
0xc7e410d7, \
|
||||
0x85f2, \
|
||||
0x11d3, \
|
||||
{0x9f, 0x63, 0x00, 0x60, 0x08, 0xa6, 0xef, 0xe9} \
|
||||
}
|
||||
|
||||
class nsJARURI : public nsIJARURI
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIURI
|
||||
NS_DECL_NSIJARURI
|
||||
|
||||
// nsJARURI
|
||||
nsJARURI();
|
||||
virtual ~nsJARURI();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsresult Init();
|
||||
nsresult FormatSpec(const char* entryPath, char* *result);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIURI> mJARFile;
|
||||
char *mJAREntry;
|
||||
};
|
||||
|
||||
#endif // nsJARURI_h__
|
||||
45
mozilla/netwerk/Makefile.in
Normal file
45
mozilla/netwerk/Makefile.in
Normal file
@@ -0,0 +1,45 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = \
|
||||
cache \
|
||||
base \
|
||||
dns \
|
||||
socket \
|
||||
build \
|
||||
protocol \
|
||||
mime \
|
||||
streamconv \
|
||||
$(NULL)
|
||||
|
||||
ifdef ENABLE_TESTS
|
||||
DIRS += test
|
||||
endif
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
#
|
||||
|
||||
DEPTH = ../..
|
||||
topsrcdir = @top_srcdir@
|
||||
@@ -26,7 +26,7 @@ VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS = public src res
|
||||
DIRS = public src
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
31
mozilla/netwerk/base/makefile.win
Normal file
31
mozilla/netwerk/base/makefile.win
Normal file
@@ -0,0 +1,31 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
DEPTH = ..\..
|
||||
|
||||
MODULE = necko
|
||||
|
||||
DIRS= \
|
||||
public \
|
||||
src \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
7
mozilla/netwerk/base/public/MANIFEST
Normal file
7
mozilla/netwerk/base/public/MANIFEST
Normal file
@@ -0,0 +1,7 @@
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
netCore.h
|
||||
nsNetUtil.h
|
||||
nsUnixColorPrintf.h
|
||||
17
mozilla/netwerk/base/public/MANIFEST_IDL
Normal file
17
mozilla/netwerk/base/public/MANIFEST_IDL
Normal file
@@ -0,0 +1,17 @@
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
nsIStreamListener.idl
|
||||
nsIStreamObserver.idl
|
||||
nsIURI.idl
|
||||
nsIURL.idl
|
||||
nsIChannel.idl
|
||||
nsIRequest.idl
|
||||
nsISocketTransportService.idl
|
||||
nsIFileTransportService.idl
|
||||
nsIFileSystem.idl
|
||||
nsIPrompt.idl
|
||||
nsIStreamLoader.idl
|
||||
nsIURLParser.idl
|
||||
nsIProtocolProxyService.idl
|
||||
67
mozilla/netwerk/base/public/Makefile.in
Normal file
67
mozilla/netwerk/base/public/Makefile.in
Normal file
@@ -0,0 +1,67 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
XPIDL_MODULE = necko_base
|
||||
|
||||
XPIDLSRCS = \
|
||||
nsIFileStreams.idl \
|
||||
nsIRequest.idl \
|
||||
nsIChannel.idl \
|
||||
nsIURI.idl \
|
||||
nsIURL.idl \
|
||||
nsIStreamObserver.idl \
|
||||
nsIStreamListener.idl \
|
||||
nsIIOService.idl \
|
||||
nsIPrompt.idl \
|
||||
nsIProtocolHandler.idl \
|
||||
nsIProgressEventSink.idl \
|
||||
nsINetModRegEntry.idl \
|
||||
nsINetModuleMgr.idl \
|
||||
nsINetNotify.idl \
|
||||
nsILoadGroup.idl \
|
||||
nsIFileTransportService.idl \
|
||||
nsISocketTransportService.idl \
|
||||
nsIStatusCodeEventSink.idl \
|
||||
nsIFileSystem.idl \
|
||||
nsIStreamLoader.idl \
|
||||
nsINetPrompt.idl \
|
||||
nsISocketTransport.idl \
|
||||
nsIURLParser.idl \
|
||||
nsIProxy.idl \
|
||||
nsIProtocolProxyService.idl \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
netCore.h \
|
||||
nsNetUtil.h \
|
||||
nsUnixColorPrintf.h \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
66
mozilla/netwerk/base/public/makefile.win
Normal file
66
mozilla/netwerk/base/public/makefile.win
Normal file
@@ -0,0 +1,66 @@
|
||||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
MODULE = necko
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
EXPORTS = \
|
||||
netCore.h \
|
||||
nsNetUtil.h \
|
||||
nsUnixColorPrintf.h \
|
||||
$(NULL)
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\nsIFileStreams.idl \
|
||||
.\nsIRequest.idl \
|
||||
.\nsIChannel.idl \
|
||||
.\nsIURI.idl \
|
||||
.\nsIURL.idl \
|
||||
.\nsIStreamObserver.idl \
|
||||
.\nsIStreamListener.idl \
|
||||
.\nsIIOService.idl \
|
||||
.\nsIPrompt.idl \
|
||||
.\nsIProtocolHandler.idl \
|
||||
.\nsIProgressEventSink.idl \
|
||||
.\nsINetModRegEntry.idl \
|
||||
.\nsINetModuleMgr.idl \
|
||||
.\nsINetNotify.idl \
|
||||
.\nsILoadGroup.idl \
|
||||
.\nsISocketTransportService.idl \
|
||||
.\nsIFileTransportService.idl \
|
||||
.\nsIStatusCodeEventSink.idl \
|
||||
.\nsIFileSystem.idl \
|
||||
.\nsIStreamLoader.idl \
|
||||
.\nsINetPrompt.idl \
|
||||
.\nsISocketTransport.idl \
|
||||
.\nsIURLParser.idl \
|
||||
.\nsIProxy.idl \
|
||||
.\nsIProtocolProxyService.idl \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
$(DEPTH)\netwerk\dist\include:
|
||||
-mkdir $(DEPTH)\netwerk\dist
|
||||
-mkdir $(DEPTH)\netwerk\dist\include
|
||||
|
||||
64
mozilla/netwerk/base/public/netCore.h
Normal file
64
mozilla/netwerk/base/public/netCore.h
Normal file
@@ -0,0 +1,64 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef __netCore_h__
|
||||
#define __netCore_h__
|
||||
|
||||
#include "nsError.h"
|
||||
|
||||
/* networking error codes */
|
||||
|
||||
// NET RANGE: 1 -20
|
||||
// FTP RANGE: 21-30
|
||||
// HTTP RANGE: 31-40
|
||||
// DNS RANGE: 41-50
|
||||
|
||||
#define NS_ERROR_ALREADY_CONNECTED \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 11)
|
||||
|
||||
#define NS_ERROR_NOT_CONNECTED \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 12)
|
||||
|
||||
/* NS_ERROR_CONNECTION_REFUSED and NS_ERROR_NET_TIMEOUT moved to nsISocketTransportService.idl */
|
||||
|
||||
#define NS_ERROR_IN_PROGRESS \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 15)
|
||||
|
||||
#define NS_ERROR_OFFLINE \
|
||||
NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 16)
|
||||
|
||||
#undef NS_NET
|
||||
#ifdef _IMPL_NS_NET
|
||||
#ifdef XP_PC
|
||||
#define NS_NET _declspec(dllexport)
|
||||
#else /* !XP_PC */
|
||||
#define NS_NET
|
||||
#endif /* !XP_PC */
|
||||
#else /* !_IMPL_NS_NET */
|
||||
#ifdef XP_PC
|
||||
#define NS_NET _declspec(dllimport)
|
||||
#else /* !XP_PC */
|
||||
#define NS_NET
|
||||
#endif /* !XP_PC */
|
||||
#endif /* !_IMPL_NS_NET */
|
||||
|
||||
#endif // __netCore_h__
|
||||
289
mozilla/netwerk/base/public/nsIChannel.idl
Normal file
289
mozilla/netwerk/base/public/nsIChannel.idl
Normal file
@@ -0,0 +1,289 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIRequest.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIInputStream;
|
||||
interface nsIOutputStream;
|
||||
interface nsIStreamObserver;
|
||||
interface nsIStreamListener;
|
||||
interface nsILoadGroup;
|
||||
interface nsIInterfaceRequestor;
|
||||
interface nsIFile;
|
||||
|
||||
typedef unsigned long nsLoadFlags;
|
||||
|
||||
/**
|
||||
* nsIChannel is the abstract base class for transports and URLs.
|
||||
* It's abstract in that it doesn't provide a means to specify the
|
||||
* location/destination of the data being accessed.
|
||||
*/
|
||||
[scriptable, uuid(2d905684-8b5c-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIChannel : nsIRequest
|
||||
{
|
||||
/**
|
||||
* Returns the original URL used to construct the channel.
|
||||
*/
|
||||
readonly attribute nsIURI originalURI;
|
||||
|
||||
/**
|
||||
* Returns the URL to which the channel currently refers.
|
||||
*/
|
||||
readonly attribute nsIURI URI;
|
||||
|
||||
/**
|
||||
* Opens a blocking input stream to the URL's specified source.
|
||||
* @param startPosition - The offset from the start of the data
|
||||
* from which to read.
|
||||
* @param readCount - The number of bytes to read. If -1, everything
|
||||
* up to the end of the data is read. If greater than the end of
|
||||
* the data, the amount available is returned in the stream.
|
||||
*/
|
||||
nsIInputStream openInputStream(in unsigned long startPosition,
|
||||
in long readCount);
|
||||
|
||||
/**
|
||||
* Opens a blocking output stream to the URL's specified destination.
|
||||
* @param startPosition - The offset from the start of the data
|
||||
* from which to begin writing.
|
||||
*/
|
||||
nsIOutputStream openOutputStream(in unsigned long startPosition);
|
||||
|
||||
/**
|
||||
* Opens the channel asynchronously. The nsIStreamObserver's OnStartRequest
|
||||
* method is called back when the channel actually becomes open, providing
|
||||
* the content type. Its OnStopRequest method is called when the channel
|
||||
* becomes closed.
|
||||
*/
|
||||
void asyncOpen(in nsIStreamObserver observer,
|
||||
in nsISupports ctxt);
|
||||
|
||||
/**
|
||||
* Reads asynchronously from the URL's specified source. Notifications
|
||||
* are provided to the stream listener on the thread of the specified
|
||||
* event queue.
|
||||
* The startPosition argument designates the offset in the source where
|
||||
* the data will be read.
|
||||
* If the readCount == -1 then all the available data is delivered to
|
||||
* the stream listener.
|
||||
*/
|
||||
void asyncRead(in unsigned long startPosition,
|
||||
in long readCount,
|
||||
in nsISupports ctxt,
|
||||
in nsIStreamListener listener);
|
||||
|
||||
/**
|
||||
* Writes asynchronously to the URL's specified destination. Notifications
|
||||
* are provided to the stream observer on the thread of the specified
|
||||
* event queue.
|
||||
* The startPosition argument designates the offset in the destination where
|
||||
* the data will be written.
|
||||
* If the writeCount == -1, then all the available data in the input
|
||||
* stream is written.
|
||||
*/
|
||||
void asyncWrite(in nsIInputStream fromStream,
|
||||
in unsigned long startPosition,
|
||||
in long writeCount,
|
||||
in nsISupports ctxt,
|
||||
in nsIStreamObserver observer);
|
||||
|
||||
/**
|
||||
* Load attribute flags. These may be or'd together.
|
||||
*
|
||||
* Note that more will follow for each protocol's implementation of a channel,
|
||||
* although channel writers have to be careful to not let the flag bits
|
||||
* overlap. Otherwise, users won't be able to create a single flag word
|
||||
* of load attributes that applies to a number of different channel types.
|
||||
*/
|
||||
const unsigned long LOAD_NORMAL = 0; /* no special load attributes -- use defaults */
|
||||
const unsigned long LOAD_BACKGROUND = 1 << 0; /* don't deliver status notifications to the
|
||||
* nsIProgressEventSink, or keep this load from
|
||||
* completing the nsILoadGroup it may belong to */
|
||||
|
||||
const unsigned long LOAD_DOCUMENT_URI = 1 << 1;
|
||||
const unsigned long LOAD_RETARGETED_DOCUMENT_URI = 1 << 2; /* if the end consumer for this
|
||||
load has been retargeted after
|
||||
discovering it's content, this flag
|
||||
will be set */
|
||||
//
|
||||
// The following flags control caching behavior. Not all protocols pay
|
||||
// attention to all these flags, but they are applicable to more than one
|
||||
// protocol, so they are defined here.
|
||||
//
|
||||
|
||||
// Don't store data in the disk cache. This can be used to preserve
|
||||
// privacy, e.g. so that no https transactions are recorded, or to avoid
|
||||
// caching a stream to disk that is already stored in a local file,
|
||||
// e.g. the mailbox: protocol.
|
||||
const unsigned long INHIBIT_PERSISTENT_CACHING = 1 << 8;
|
||||
|
||||
// Force an end-to-end download of content data from the origin server (and
|
||||
// any intervening proxies that sit between it and the client), e.g. this
|
||||
// flag is used for a shift-reload.
|
||||
const unsigned long FORCE_RELOAD = 1 << 9;
|
||||
|
||||
// Force revalidation with server (or proxy) to verify that cached content
|
||||
// is up-to-date, e.g. by comparing last-modified date on server with that
|
||||
// of the cached version. For example, this flag is used when the reload
|
||||
// button is pressed.
|
||||
const unsigned long FORCE_VALIDATION = 1 << 10;
|
||||
|
||||
// If the CACHE_AS_FILE flag is set, any stream content is stored in the
|
||||
// cache as a single disk file. Content will not be cached in the memory
|
||||
// cache nor will it be stored in any other type of cache, e.g. a flat-file
|
||||
// cache database. This is used to implement the jar protocol handler and
|
||||
// to provide the stream-as-file semantics required by the classic browser
|
||||
// plugin API.
|
||||
const unsigned long CACHE_AS_FILE = 1 << 11;
|
||||
|
||||
// When cache data is potentially out of date, it can be revalidated with
|
||||
// the origin server to see if the content needs to be reloaded. The
|
||||
// following four flags control how often this validation occurs.
|
||||
// These flags are commonly used for "normal" loading. Note that
|
||||
// the VALIDATE_HEURISTICALLY and VALIDATE_ONCE_PER_SESSION flags can be
|
||||
// combined to validate heuristically but no more than once per session.
|
||||
//
|
||||
const unsigned long VALIDATE_NEVER = 1 << 12;
|
||||
const unsigned long VALIDATE_ALWAYS = 1 << 13;
|
||||
const unsigned long VALIDATE_ONCE_PER_SESSION = 1 << 14;
|
||||
const unsigned long VALIDATE_HEURISTICALLY = 1 << 15;
|
||||
|
||||
|
||||
/**
|
||||
* Accesses the load attributes for the channel. E.g. setting the load
|
||||
* attributes with the LOAD_QUIET bit set causes the loading process to
|
||||
* not deliver status notifications to the program performing the load,
|
||||
* and to not contribute to keeping any nsILoadGroup it may be contained
|
||||
* in from firing its OnLoadComplete notification.
|
||||
*/
|
||||
attribute nsLoadFlags loadAttributes;
|
||||
|
||||
/**
|
||||
* Returns the content MIME type of the channel if available. Note that the
|
||||
* content type can often be wrongly specified (wrong file extension, wrong
|
||||
* MIME type, wrong document type stored on a server, etc.) and the caller
|
||||
* most likely wants to verify with the actual data.
|
||||
*/
|
||||
attribute string contentType;
|
||||
|
||||
/**
|
||||
* Returns the length of the data assiciated with the channel if available.
|
||||
* If the length is unknown then -1 is returned.
|
||||
*/
|
||||
readonly attribute long contentLength;
|
||||
|
||||
/**
|
||||
* Accesses the owner corresponding to the entity that is
|
||||
* responsible for this channel. Used by security code to grant
|
||||
* or diminish privileges to mobile code loaded from this channel.
|
||||
*/
|
||||
attribute nsISupports owner;
|
||||
|
||||
/**
|
||||
* Accesses the load group in which the channel is a currently a member.
|
||||
*/
|
||||
attribute nsILoadGroup loadGroup;
|
||||
|
||||
/**
|
||||
* Accesses the capabilities callbacks of the channel. This is set by clients
|
||||
* who wish to provide a means to receive progress, status and protocol-specific
|
||||
* notifications.
|
||||
*/
|
||||
attribute nsIInterfaceRequestor notificationCallbacks;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* nsIInputStreamChannel is an interface that allows for the initialization
|
||||
* of a simple nsIChannel that is constructed from a single input stream and
|
||||
* associated content type. Input stream channels only allow the input stream
|
||||
* to be accessed, not the output stream.
|
||||
*/
|
||||
[scriptable, uuid(bfbf843a-8b89-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIInputStreamChannel : nsIChannel
|
||||
{
|
||||
void init(in nsIURI uri,
|
||||
in string contentType,
|
||||
in long contentLength,
|
||||
in nsIInputStream inStr,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_INPUTSTREAMCHANNEL_CID \
|
||||
{ /* 436d84f8-8b8a-11d3-8cd9-0060b0fc14a3 */ \
|
||||
0x436d84f8, \
|
||||
0x8b8a, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xd9, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
* nsIFileChannel is an interface that allows for the initialization
|
||||
* of a simple nsIChannel that is constructed from a single nsIFile and
|
||||
* associated content type.
|
||||
*/
|
||||
[scriptable, uuid(6eef6444-c7e3-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIFileChannel : nsIChannel
|
||||
{
|
||||
void init(in nsIFile file,
|
||||
in long mode,
|
||||
in string contentType,
|
||||
in long contentLength,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
readonly attribute nsIFile file;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_FILECHANNEL_CLASSNAME "File Channel"
|
||||
#define NS_FILECHANNEL_PROGID "component://netscape/network/file-channel"
|
||||
|
||||
#define NS_FILECHANNEL_CID \
|
||||
{ /* 7036066e-c7e3-11d3-8cda-0060b0fc14a3 */ \
|
||||
0x7036066e, \
|
||||
0xc7e3, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
30
mozilla/netwerk/base/public/nsIEventSinkGetter.idl
Normal file
30
mozilla/netwerk/base/public/nsIEventSinkGetter.idl
Normal file
@@ -0,0 +1,30 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(fb65fd70-1881-11d3-9337-00104ba0fd40)]
|
||||
interface nsIEventSinkGetter : nsISupports
|
||||
{
|
||||
nsISupports getEventSink(in string command, in nsIIDRef eventSinkIID);
|
||||
};
|
||||
|
||||
244
mozilla/netwerk/base/public/nsIFileStreams.idl
Normal file
244
mozilla/netwerk/base/public/nsIFileStreams.idl
Normal file
@@ -0,0 +1,244 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIInputStream.idl"
|
||||
#include "nsIOutputStream.idl"
|
||||
#include "nsILocalFile.idl"
|
||||
|
||||
[scriptable, uuid(e3d56a20-c7ec-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIFileInputStream : nsIInputStream
|
||||
{
|
||||
void init(in nsILocalFile file);
|
||||
};
|
||||
|
||||
[scriptable, uuid(e6f68040-c7ec-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIFileOutputStream : nsIOutputStream
|
||||
{
|
||||
void init(in nsILocalFile file, in long flags, in long mode);
|
||||
};
|
||||
|
||||
[scriptable, uuid(e9de5df0-c7ec-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsISeekableStream : nsISupports
|
||||
{
|
||||
// correspond to PRSeekWhence values
|
||||
const long NS_SEEK_SET = 0;
|
||||
const long NS_SEEK_CUR = 1;
|
||||
const long NS_SEEK_END = 2;
|
||||
|
||||
void seek(in long whence, in long offset);
|
||||
unsigned long tell();
|
||||
};
|
||||
|
||||
[scriptable, uuid(616f5b48-da09-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIBufferedInputStream : nsIInputStream
|
||||
{
|
||||
void init(in nsIInputStream fillFromStream,
|
||||
in unsigned long bufferSize);
|
||||
};
|
||||
|
||||
[scriptable, uuid(6476378a-da09-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIBufferedOutputStream : nsIOutputStream
|
||||
{
|
||||
void init(in nsIOutputStream sinkToStream,
|
||||
in unsigned long bufferSize);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NS_FILEINPUTSTREAM_CLASSNAME "File Input Stream"
|
||||
#define NS_FILEINPUTSTREAM_PROGID "component://netscape/network/file-input-stream"
|
||||
|
||||
#define NS_FILEINPUTSTREAM_CID \
|
||||
{ /* be9a53ae-c7e9-11d3-8cda-0060b0fc14a3 */ \
|
||||
0xbe9a53ae, \
|
||||
0xc7e9, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
#define NS_FILEOUTPUTSTREAM_CLASSNAME "File Output Stream"
|
||||
#define NS_FILEOUTPUTSTREAM_PROGID "component://netscape/network/file-output-stream"
|
||||
|
||||
#define NS_FILEOUTPUTSTREAM_CID \
|
||||
{ /* c272fee0-c7e9-11d3-8cda-0060b0fc14a3 */ \
|
||||
0xc272fee0, \
|
||||
0xc7e9, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#define NS_BUFFEREDINPUTSTREAM_CLASSNAME "Buffered Input Stream"
|
||||
#define NS_BUFFEREDINPUTSTREAM_PROGID "component://netscape/network/buffered-input-stream"
|
||||
|
||||
#define NS_BUFFEREDINPUTSTREAM_CID \
|
||||
{ /* 9226888e-da08-11d3-8cda-0060b0fc14a3 */ \
|
||||
0x9226888e, \
|
||||
0xda08, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
#define NS_BUFFEREDOUTPUTSTREAM_CLASSNAME "Buffered Output Stream"
|
||||
#define NS_BUFFEREDOUTPUTSTREAM_PROGID "component://netscape/network/buffered-output-stream"
|
||||
|
||||
#define NS_BUFFEREDOUTPUTSTREAM_CID \
|
||||
{ /* 9868b4ce-da08-11d3-8cda-0060b0fc14a3 */ \
|
||||
0x9868b4ce, \
|
||||
0xda08, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xda, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// move to nsNetUtil.h later...
|
||||
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsILocalFile.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "prio.h" // for read/write modes, etc.
|
||||
|
||||
inline nsresult
|
||||
NS_NewFileChannel(nsIFile* file,
|
||||
PRInt32 mode,
|
||||
const char* contentType,
|
||||
PRUint32 contentLength,
|
||||
nsILoadGroup* group,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIFileChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileChannel> channel;
|
||||
static NS_DEFINE_CID(kFileChannelCID, NS_FILECHANNEL_CID);
|
||||
rv = nsComponentManager::CreateInstance(kFileChannelCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileChannel),
|
||||
getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = channel->Init(file, mode, contentType, contentLength, group,
|
||||
notificationCallbacks, loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = channel;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewFileInputStream(nsIFile* file, nsIInputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileInputStream> in;
|
||||
static NS_DEFINE_CID(kFileInputStreamCID, NS_FILEINPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kFileInputStreamCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileInputStream),
|
||||
getter_AddRefs(in));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = in->Init(localFile);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = in;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewFileOutputStream(nsIFile* file, PRInt32 flags, PRInt32 mode,
|
||||
nsIOutputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIFileOutputStream> out;
|
||||
static NS_DEFINE_CID(kFileOutputStreamCID, NS_FILEOUTPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kFileOutputStreamCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIFileOutputStream),
|
||||
getter_AddRefs(out));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
nsCOMPtr<nsILocalFile> localFile = do_QueryInterface(file, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = out->Init(localFile, flags, mode);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = out;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
inline nsresult
|
||||
NS_NewBufferedInputStream(nsIInputStream* str, PRUint32 bufferSize,
|
||||
nsIInputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIBufferedInputStream> in;
|
||||
static NS_DEFINE_CID(kBufferedInputStreamCID, NS_BUFFEREDINPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kBufferedInputStreamCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIBufferedInputStream),
|
||||
getter_AddRefs(in));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = in->Init(str, bufferSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = in;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewBufferedOutputStream(nsIOutputStream* str, PRUint32 bufferSize,
|
||||
nsIOutputStream* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIBufferedOutputStream> out;
|
||||
static NS_DEFINE_CID(kBufferedOutputStreamCID, NS_BUFFEREDOUTPUTSTREAM_CID);
|
||||
rv = nsComponentManager::CreateInstance(kBufferedOutputStreamCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIBufferedOutputStream),
|
||||
getter_AddRefs(out));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = out->Init(str, bufferSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = out;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
%}
|
||||
@@ -1,9 +1,9 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
@@ -17,29 +17,24 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
window.addEventListener("load", SetSecurityButton, false);
|
||||
#include "nsISupports.idl"
|
||||
|
||||
var securityUI;
|
||||
interface nsIInputStream;
|
||||
interface nsIOutputStream;
|
||||
|
||||
function SetSecurityButton()
|
||||
[scriptable, uuid(818e1370-77c4-11d3-9395-00104ba0fd40)]
|
||||
interface nsIFileSystem : nsISupports
|
||||
{
|
||||
dump("in SetSecurityButton\n");
|
||||
void open(out string contentType,
|
||||
out long contentLength);
|
||||
|
||||
var ui = Components.classes["component://netscape/secure_browser_ui"].createInstance();
|
||||
securityUI = ui.QueryInterface(Components.interfaces.nsSecureBrowserUI);
|
||||
|
||||
var button = document.getElementById('security-button');
|
||||
if (button && window.content)
|
||||
securityUI.init(window.content, button);
|
||||
}
|
||||
|
||||
function displayPageInfo()
|
||||
{
|
||||
if (securityUI)
|
||||
securityUI.displayPageInfoUI();
|
||||
}
|
||||
void close(in nsresult status);
|
||||
|
||||
readonly attribute nsIInputStream inputStream;
|
||||
|
||||
readonly attribute nsIOutputStream outputStream;
|
||||
};
|
||||
|
||||
73
mozilla/netwerk/base/public/nsIFileTransportService.idl
Normal file
73
mozilla/netwerk/base/public/nsIFileTransportService.idl
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
%{C++
|
||||
#include "nsFileSpec.h"
|
||||
%}
|
||||
|
||||
interface nsIChannel;
|
||||
interface nsIFileSystem;
|
||||
interface nsIEventSinkGetter;
|
||||
interface nsIInputStream;
|
||||
interface nsIRunnable;
|
||||
interface nsIFile;
|
||||
|
||||
[scriptable, uuid(57211a60-8c45-11d3-93ac-00104ba0fd40)]
|
||||
interface nsIFileTransportService : nsISupports
|
||||
{
|
||||
nsIChannel createTransport(in nsIFile file,
|
||||
in long mode,
|
||||
in string command,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
// This version can be used with an existing input stream to serve
|
||||
// as a data pump:
|
||||
nsIChannel createTransportFromStream(in nsIInputStream fromStream,
|
||||
in string contentType,
|
||||
in long contentLength,
|
||||
in string command,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
nsIChannel createTransportFromFileSystem(in nsIFileSystem fsObj,
|
||||
in string command,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
void dispatchRequest(in nsIRunnable runnable);
|
||||
void suspend(in nsIRunnable trans);
|
||||
void resume(in nsIRunnable trans);
|
||||
void processPendingRequests();
|
||||
void shutdown();
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_FILETRANSPORTSERVICE_CID \
|
||||
{ /* 2bb2b250-ea35-11d2-931b-00104ba0fd40 */ \
|
||||
0x2bb2b250, \
|
||||
0xea35, \
|
||||
0x11d2, \
|
||||
{0x93, 0x1b, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
%}
|
||||
175
mozilla/netwerk/base/public/nsIIOService.idl
Normal file
175
mozilla/netwerk/base/public/nsIIOService.idl
Normal file
@@ -0,0 +1,175 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIChannel.idl"
|
||||
|
||||
interface nsIProtocolHandler;
|
||||
interface nsIURI;
|
||||
interface nsIInterfaceRequestor;
|
||||
interface nsIStreamObserver;
|
||||
interface nsIStreamListener;
|
||||
interface nsIEventQueue;
|
||||
interface nsIBufferInputStream;
|
||||
interface nsIInputStream;
|
||||
interface nsIBufferOutputStream;
|
||||
interface nsIFileChannel;
|
||||
interface nsILoadGroup;
|
||||
interface nsILoadGroupObserver;
|
||||
interface nsIFile;
|
||||
interface nsIInputStream;
|
||||
interface nsIOutputStream;
|
||||
|
||||
[scriptable, uuid(ab7c3a84-d488-11d3-8cda-0060b0fc14a3)]
|
||||
interface nsIIOService : nsISupports
|
||||
{
|
||||
/**
|
||||
* constants for the Escape mask in the call to URLEscape
|
||||
*/
|
||||
const short url_Scheme = (1<<0);
|
||||
const short url_Username = (1<<1);
|
||||
const short url_Password = (1<<2);
|
||||
const short url_Host = (1<<3);
|
||||
const short url_Directory = (1<<4);
|
||||
const short url_FileBaseName = (1<<5);
|
||||
const short url_FileExtension = (1<<6);
|
||||
const short url_Param = (1<<7);
|
||||
const short url_Query = (1<<8);
|
||||
const short url_Ref = (1<<9);
|
||||
|
||||
/**
|
||||
* Returns a protocol handler for a given URI scheme.
|
||||
*/
|
||||
nsIProtocolHandler getProtocolHandler(in string scheme);
|
||||
|
||||
/**
|
||||
* This method constructs a new URI by first determining the scheme
|
||||
* of the URI spec, and then delegating the construction of the URI
|
||||
* to the protocol handler for that scheme. QueryInterface can be used
|
||||
* on the resulting URI object to obtain a more specific type of URI.
|
||||
*/
|
||||
nsIURI newURI(in string aSpec, in nsIURI aBaseURI);
|
||||
|
||||
/**
|
||||
* Creates a channel for a given URI. The notificationCallbacks argument
|
||||
* is used to obtain the appropriate callbacks for the URI's protocol from the
|
||||
* application.
|
||||
*
|
||||
* @param originalURI - Specifies the original URI which caused the creation
|
||||
* of this channel. This can occur when the construction of one channel
|
||||
* (e.g. for resource:) causes another channel to be created on its behalf
|
||||
* (e.g. a file: channel), or if a redirect occurs, causing the current
|
||||
* URL to become different from the original URL. If NULL, the aURI parameter
|
||||
* will be used as the originalURI instead.
|
||||
*/
|
||||
nsIChannel newChannelFromURI(in string verb,
|
||||
in nsIURI aURI,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
/**
|
||||
* Convenience routine that first creates a URI by calling NewURI, and
|
||||
* then passes the URI to NewChannelFromURI.
|
||||
*/
|
||||
nsIChannel newChannel(in string verb,
|
||||
in string aSpec,
|
||||
in nsIURI aBaseURI,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
/**
|
||||
* Returns true if networking is in "offline" mode. When in offline mode, attempts
|
||||
* to access the network will fail (although this is not necessarily corrolated with
|
||||
* whether there is actually a network available -- that's hard to detect without
|
||||
* causing the dialer to come up).
|
||||
*/
|
||||
attribute boolean offline;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// URL parsing utilities
|
||||
|
||||
/**
|
||||
* Utility for protocol implementors -- extracts the scheme from a URL
|
||||
* string, consistently and according to spec.
|
||||
* @param urlString - the URL string to parse
|
||||
* @param schemeStartPos - the resulting starting position of the scheme substring
|
||||
* (may skip over whitespace)
|
||||
* @param schemeEndPos - the resulting ending position of the scheme substring
|
||||
* (the position of the colon)
|
||||
* @param scheme - an allocated substring containing the scheme. If this parameter
|
||||
* is null going into the routine, then the scheme is not allocated and
|
||||
* returned. Free with nsCRT::free.
|
||||
*
|
||||
* @return NS_OK - if successful
|
||||
* @return NS_ERROR_MALFORMED_URI - if the urlString is not of the right form
|
||||
*/
|
||||
void extractScheme(in string urlString,
|
||||
out unsigned long schemeStartPos,
|
||||
out unsigned long schemeEndPos,
|
||||
out string scheme);
|
||||
|
||||
/**
|
||||
* Encode characters into % escaped hexcodes.
|
||||
*/
|
||||
string escape(in string str, in short mask);
|
||||
|
||||
/**
|
||||
* Decode % escaped hex codes into character values.
|
||||
*/
|
||||
string unescape(in string str);
|
||||
|
||||
/**
|
||||
* Get port from string.
|
||||
*/
|
||||
long extractPort(in string str);
|
||||
|
||||
/**
|
||||
* Resolves a relative path string containing "." and ".."
|
||||
* with respect to a base path (assumed to already be resolved).
|
||||
* For example, resolving "../../foo/./bar/../baz.html" w.r.t.
|
||||
* "/a/b/c/d/e/" yields "/a/b/c/foo/baz.html". Attempting to
|
||||
* ascend above the base results in the NS_ERROR_MALFORMED_URI
|
||||
* exception. If basePath is null, it treats it as "/".
|
||||
*/
|
||||
string resolveRelativePath(in string relativePath,
|
||||
in string basePath);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_IOSERVICE_CID \
|
||||
{ /* 9ac9e770-18bc-11d3-9337-00104ba0fd40 */ \
|
||||
0x9ac9e770, \
|
||||
0x18bc, \
|
||||
0x11d3, \
|
||||
{0x93, 0x37, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
%}
|
||||
104
mozilla/netwerk/base/public/nsILoadGroup.idl
Normal file
104
mozilla/netwerk/base/public/nsILoadGroup.idl
Normal file
@@ -0,0 +1,104 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIRequest.idl"
|
||||
|
||||
interface nsIChannel;
|
||||
interface nsISimpleEnumerator;
|
||||
interface nsIStreamObserver;
|
||||
interface nsIStreamListener;
|
||||
interface nsIInputStream;
|
||||
|
||||
|
||||
[scriptable, uuid(60fdf550-5392-11d3-9a97-0080c7cb1080)]
|
||||
interface nsILoadGroupListenerFactory : nsISupports
|
||||
{
|
||||
nsIStreamListener createLoadGroupListener(in nsIStreamListener alistener);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* A load group maintains a collection of active URL requests.
|
||||
*/
|
||||
[scriptable, uuid(19845248-29ab-11d3-8cce-0060b0fc14a3)]
|
||||
interface nsILoadGroup : nsIRequest
|
||||
{
|
||||
void init(in nsIStreamObserver observer);
|
||||
|
||||
/**
|
||||
* Accesses the default load attributes for the group, returned as
|
||||
* a flag word. Setting the default load attributes will cause them
|
||||
* to be applied to each new channel inserted into the group.
|
||||
*/
|
||||
attribute unsigned long defaultLoadAttributes;
|
||||
|
||||
/**
|
||||
* Accesses the default load channel for the group. Each time a number
|
||||
* of channels are added to a group, the DefaultLoadChannel may be set
|
||||
* to indicate that all of the channels are related to a particular URL.
|
||||
*/
|
||||
attribute nsIChannel defaultLoadChannel;
|
||||
|
||||
/**
|
||||
* Adds a new channel to the group. This will cause the default load
|
||||
* attributes to be applied to that channel. If the channel added is
|
||||
* the first channel in the group, the group's observer's OnStartRequest
|
||||
* method is called.
|
||||
*/
|
||||
void addChannel(in nsIChannel channel,
|
||||
in nsISupports ctxt);
|
||||
|
||||
/**
|
||||
* Removes a channel from the group. If the channel removed is
|
||||
* the last channel in the group, the group's observer's OnStopRequest
|
||||
* method is called.
|
||||
*/
|
||||
void removeChannel(in nsIChannel channel,
|
||||
in nsISupports ctxt,
|
||||
in nsresult status,
|
||||
in wstring errorMsg);
|
||||
|
||||
/**
|
||||
* Returns the channels contained directly in this group.
|
||||
* Enumerator element type: nsIChannel.
|
||||
*/
|
||||
readonly attribute nsISimpleEnumerator channels;
|
||||
|
||||
attribute nsIStreamObserver groupObserver;
|
||||
|
||||
attribute nsILoadGroupListenerFactory groupListenerFactory;
|
||||
|
||||
|
||||
readonly attribute unsigned long activeCount;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_LOADGROUP_CID \
|
||||
{ /* e1c61582-2a84-11d3-8cce-0060b0fc14a3 */ \
|
||||
0xe1c61582, \
|
||||
0x2a84, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xce, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
%}
|
||||
47
mozilla/netwerk/base/public/nsINetModRegEntry.idl
Normal file
47
mozilla/netwerk/base/public/nsINetModRegEntry.idl
Normal file
@@ -0,0 +1,47 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/* This interface defines a registry entry for the networking libraries
|
||||
* external module registry. */
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsINetNotify.idl"
|
||||
|
||||
interface nsIEventQueue;
|
||||
interface nsINetModRegEntry;
|
||||
interface nsINetNotify;
|
||||
|
||||
%{ C++
|
||||
// {F126BD90-1472-11d3-A15A-0050041CAF44}
|
||||
#define NS_NETMODREGENTRY_CID \
|
||||
{ 0xf126bd90, 0x1472, 0x11d3, { 0xa1, 0x5a, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } }
|
||||
%}
|
||||
|
||||
[scriptable, uuid(9F482BD0-1476-11d3-A15A-0050041CAF44)]
|
||||
interface nsINetModRegEntry : nsISupports
|
||||
{
|
||||
readonly attribute nsINetNotify syncProxy;
|
||||
readonly attribute nsINetNotify asyncProxy;
|
||||
readonly attribute string topic;
|
||||
|
||||
boolean equals(in nsINetModRegEntry aEntry);
|
||||
};
|
||||
80
mozilla/netwerk/base/public/nsINetModuleMgr.idl
Normal file
80
mozilla/netwerk/base/public/nsINetModuleMgr.idl
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/* The nsINetModuleMgr singleton service allows external module to register
|
||||
* themselves with the networking library to receive events they want to
|
||||
* receive.
|
||||
*
|
||||
* An external module that is interested in being notified when a particular
|
||||
* networking level event occurs would register with this service, and
|
||||
* implement the appropriate interface(s) that correspond to the events they
|
||||
* want to receive. These interfaces are defined by networking internal
|
||||
* components (for example, http would define a notification interface that
|
||||
* the external cookies module would implement).
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIEnumerator.idl"
|
||||
#include "nsINetNotify.idl"
|
||||
|
||||
interface nsIEventQueue;
|
||||
|
||||
%{ C++
|
||||
|
||||
// {4EBDAFE0-13BA-11d3-A15A-0050041CAF44}
|
||||
#define NS_NETMODULEMGR_CID \
|
||||
{ 0x4ebdafe0, 0x13ba, 0x11d3, { 0xa1, 0x5a, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } }
|
||||
|
||||
// The list of available PROGIDS to register for notification on.
|
||||
#define NS_NETWORK_MODULE_MANAGER_HTTP_REQUEST_PROGID "component://netscape/network/moduleMgr/http/request"
|
||||
#define NS_NETWORK_MODULE_MANAGER_HTTP_RESPONSE_PROGID "component://netscape/network/moduleMgr/http/response"
|
||||
%}
|
||||
|
||||
[scriptable, uuid(ff9ead40-0ef2-11d3-9de6-0010a4053fd0)]
|
||||
interface nsINetModuleMgr : nsISupports {
|
||||
|
||||
// Register the external module to receive notifications.
|
||||
//
|
||||
// ARGUMENTS:
|
||||
// aTopic: The internal component that the external module wants to monitor.
|
||||
// aNotify: The external module interface methods to be called when an event is fired.
|
||||
//
|
||||
// RETURNS: nsresult
|
||||
void registerModule(in string aTopic, in nsINetNotify aNotify);
|
||||
|
||||
// Unregister the external module. Removes the nsINetModuleMgr binding between
|
||||
// internal component and external module.
|
||||
//
|
||||
// ARGUMENTS:
|
||||
// aTopic: The internal component being monitored.
|
||||
// aNotify: The external modules notification module.
|
||||
//
|
||||
// RETURNS: nsresult
|
||||
void unregisterModule(in string aTopic, in nsINetNotify aNotify);
|
||||
|
||||
// Enumerates all the registered modules for the specified topic.
|
||||
//
|
||||
// ARGUMENTS:
|
||||
// aTopic: the component to get all the notifiers for.
|
||||
// aEnumerator: the array of notifiers.
|
||||
void enumerateModules(in string aTopic, out nsISimpleEnumerator aEnumerator);
|
||||
};
|
||||
28
mozilla/netwerk/base/public/nsINetNotify.idl
Normal file
28
mozilla/netwerk/base/public/nsINetNotify.idl
Normal file
@@ -0,0 +1,28 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[uuid(4A3019E0-1CF3-11d3-A15B-0050041CAF44)]
|
||||
interface nsINetNotify : nsISupports {
|
||||
|
||||
};
|
||||
76
mozilla/netwerk/base/public/nsINetPrompt.idl
Normal file
76
mozilla/netwerk/base/public/nsINetPrompt.idl
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
|
||||
|
||||
[scriptable, uuid(edd8be01-8e0d-11d3-b7a0-c46e946292bc)]
|
||||
interface nsINetPrompt : nsISupports
|
||||
{
|
||||
/**
|
||||
* Puts up an alert dialog with an OK button.
|
||||
*/
|
||||
void alert( in string url, in boolean stripurl, in wstring title, in wstring text);
|
||||
|
||||
/**
|
||||
* Puts up a dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean confirm( in string url, in boolean stripurl, in wstring title, in wstring text);
|
||||
|
||||
/**
|
||||
* Puts up a username/password dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean promptUsernameAndPassword(
|
||||
in string url,
|
||||
in boolean stripurl,
|
||||
in wstring title,
|
||||
in wstring text,
|
||||
out wstring user,
|
||||
out wstring pwd);
|
||||
|
||||
/**
|
||||
* Puts up a password dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean promptPassword(
|
||||
in string url,
|
||||
in boolean stripurl,
|
||||
in wstring title,
|
||||
in wstring text,
|
||||
out wstring pwd);
|
||||
|
||||
/**
|
||||
* Puts up a prompt dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean prompt(
|
||||
in string url,
|
||||
in boolean stripurl,
|
||||
in wstring title,
|
||||
in wstring text,
|
||||
out wstring pwd);
|
||||
};
|
||||
|
||||
|
||||
51
mozilla/netwerk/base/public/nsIProgressEventSink.idl
Normal file
51
mozilla/netwerk/base/public/nsIProgressEventSink.idl
Normal file
@@ -0,0 +1,51 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIChannel;
|
||||
|
||||
/**
|
||||
* An instance of nsIFfpEventSink should be passed as the eventSink
|
||||
* argument of nsINetService::NewConnection for ftp URLs. It defines
|
||||
* the callbacks to the application program (the html parser).
|
||||
*/
|
||||
[scriptable, uuid(dd47ee00-18c2-11d3-9337-00104ba0fd40)]
|
||||
interface nsIProgressEventSink : nsISupports
|
||||
{
|
||||
/**
|
||||
* Notify the EventSink that progress as occurred for the URL load.<BR>
|
||||
*/
|
||||
void onProgress(in nsIChannel channel,
|
||||
in nsISupports ctxt,
|
||||
in unsigned long aProgress,
|
||||
in unsigned long aProgressMax);
|
||||
|
||||
/**
|
||||
* Notify the EventSink with a status message for the URL load.<BR>
|
||||
*/
|
||||
void onStatus(in nsIChannel channel,
|
||||
in nsISupports ctxt,
|
||||
in wstring aMsg);
|
||||
|
||||
};
|
||||
102
mozilla/netwerk/base/public/nsIPrompt.idl
Normal file
102
mozilla/netwerk/base/public/nsIPrompt.idl
Normal file
@@ -0,0 +1,102 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(a63f70c0-148b-11d3-9333-00104ba0fd40)]
|
||||
interface nsIPrompt : nsISupports
|
||||
{
|
||||
/**
|
||||
* Puts up an alert dialog with an OK button.
|
||||
*/
|
||||
void alert(in wstring text);
|
||||
|
||||
/**
|
||||
* Puts up a dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean confirm(in wstring text);
|
||||
|
||||
/**
|
||||
* Puts up a dialog with OK and Cancel buttons, and
|
||||
* a message with a single checkbox.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean confirmCheck(in wstring text,
|
||||
in wstring checkMsg,
|
||||
out boolean checkValue);
|
||||
|
||||
/**
|
||||
* Puts up a text input dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean prompt(in wstring text,
|
||||
in wstring defaultText,
|
||||
out wstring result);
|
||||
|
||||
/**
|
||||
* Puts up a username/password dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean promptUsernameAndPassword(in wstring text,
|
||||
out wstring user,
|
||||
out wstring pwd);
|
||||
|
||||
/**
|
||||
* Puts up a password dialog with OK and Cancel buttons.
|
||||
* @return true for OK, false for Cancel
|
||||
*/
|
||||
boolean promptPassword(in wstring text,
|
||||
in wstring title,
|
||||
out wstring pwd);
|
||||
|
||||
/**
|
||||
* Puts up a dialog box which has a list box of strings
|
||||
*/
|
||||
boolean select(in wstring inDialogTitle,
|
||||
in wstring inMsg,
|
||||
in PRUint32 inCount,
|
||||
[array, size_is(inCount)] in wstring inList,
|
||||
out long outSelection);
|
||||
|
||||
/**
|
||||
* Put up a universal dialog
|
||||
*/
|
||||
void universalDialog(in wstring inTitleMessage,
|
||||
in wstring inDialogTitle, /* e.g., alert, confirm, prompt, prompt password */
|
||||
in wstring inMsg, /* main message for dialog */
|
||||
in wstring inCheckboxMsg, /* message for checkbox */
|
||||
in wstring inButton0Text, /* text for first button */
|
||||
in wstring inButton1Text, /* text for second button */
|
||||
in wstring inButton2Text, /* text for third button */
|
||||
in wstring inButton3Text, /* text for fourth button */
|
||||
in wstring inEditfield1Msg, /*message for first edit field */
|
||||
in wstring inEditfield2Msg, /* message for second edit field */
|
||||
inout wstring inoutEditfield1Value, /* initial and final value for first edit field */
|
||||
inout wstring inoutEditfield2Value, /* initial and final value for second edit field */
|
||||
in wstring inIConURL, /* url of icon to be displayed in dialog */
|
||||
inout boolean inoutCheckboxState, /* initial and final state of checkbox */
|
||||
in PRInt32 inNumberButtons, /* total number of buttons (0 to 4) */
|
||||
in PRInt32 inNumberEditfields, /* total number of edit fields (0 to 2) */
|
||||
in PRInt32 inEditField1Password, /* ??? */
|
||||
out PRInt32 outButtonPressed); /* number of button that was pressed (0 to 3) */
|
||||
};
|
||||
74
mozilla/netwerk/base/public/nsIProtocolHandler.idl
Normal file
74
mozilla/netwerk/base/public/nsIProtocolHandler.idl
Normal file
@@ -0,0 +1,74 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIChannel.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsIInterfaceRequestor;
|
||||
interface nsILoadGroup;
|
||||
|
||||
[scriptable, uuid(15fd6940-8ea7-11d3-93ad-00104ba0fd40)]
|
||||
interface nsIProtocolHandler : nsISupports
|
||||
{
|
||||
readonly attribute string scheme;
|
||||
|
||||
readonly attribute long defaultPort;
|
||||
|
||||
/**
|
||||
* Makes a URI object that is suitable for loading by this protocol.
|
||||
* In the usual case (when only the accessors provided by nsIURI are
|
||||
* needed), this method just constructs a standard URI using the
|
||||
* component manager with kStandardURLCID.
|
||||
*/
|
||||
nsIURI newURI(in string aSpec, in nsIURI aBaseURI);
|
||||
|
||||
/**
|
||||
* Constructs a new channel for this protocol handler.
|
||||
*
|
||||
* @param originalURI - Specifies the original URI which caused the creation
|
||||
* of this channel. This can occur when the construction of one channel
|
||||
* (e.g. for resource:) causes another channel to be created on its behalf
|
||||
* (e.g. a file: channel), or if a redirect occurs, causing the current
|
||||
* URL to become different from the original URL. If NULL, the aURI parameter
|
||||
* will be used as the originalURI instead.
|
||||
*/
|
||||
nsIChannel newChannel(in string verb,
|
||||
in nsIURI aURI,
|
||||
in nsILoadGroup aLoadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in nsIURI originalURI,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_NETWORK_PROTOCOL_PROGID "component://netscape/network/protocol"
|
||||
#define NS_NETWORK_PROTOCOL_PROGID_PREFIX NS_NETWORK_PROTOCOL_PROGID "?name="
|
||||
#define NS_NETWORK_PROTOCOL_PROGID_PREFIX_LENGTH 43 // nsCRT::strlen(NS_NETWORK_PROTOCOL_PROGID_PREFIX)
|
||||
|
||||
// Unknown Protocol Error
|
||||
#define NS_ERROR_UNKNOWN_PROTOCOL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 18)
|
||||
|
||||
%}
|
||||
40
mozilla/netwerk/base/public/nsIProtocolProxyService.idl
Normal file
40
mozilla/netwerk/base/public/nsIProtocolProxyService.idl
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIURI.idl"
|
||||
#include "nsIProxy.idl"
|
||||
|
||||
%{C++
|
||||
#define NS_PROTOCOLPROXYSERVICE_CID \
|
||||
{ /* E9B301C0-E0E4-11d3-A1A8-0050041CAF44 */ \
|
||||
0xe9b301c0, 0xe0e4, 0x11d3, { 0xa1, 0xa8, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } }
|
||||
%}
|
||||
|
||||
[scriptable, uuid(495CC980-E0D4-11d3-A1A8-0050041CAF44)]
|
||||
interface nsIProtocolProxyService : nsISupports
|
||||
{
|
||||
readonly attribute PRBool proxyEnabled;
|
||||
|
||||
void examineForProxy(in nsIURI aURI, in nsIProxy aProxy);
|
||||
};
|
||||
|
||||
41
mozilla/netwerk/base/public/nsIProxy.idl
Normal file
41
mozilla/netwerk/base/public/nsIProxy.idl
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
/*
|
||||
The nsIProxy interface allows setting and getting of proxy host and port.
|
||||
This is for use by protocol handlers. If you are writing a protocol handler
|
||||
and would like to support proxy behaviour then derive from this as well as
|
||||
the nsIProtocolHandler class.
|
||||
|
||||
-Gagan Saksena 02/25/99
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(0492D011-CD2F-11d2-B013-006097BFC036)]
|
||||
interface nsIProxy : nsISupports
|
||||
{
|
||||
attribute string proxyHost;
|
||||
|
||||
/* -1 on Set call indicates switch to default port */
|
||||
attribute long proxyPort;
|
||||
};
|
||||
55
mozilla/netwerk/base/public/nsIRequest.idl
Normal file
55
mozilla/netwerk/base/public/nsIRequest.idl
Normal file
@@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(F2CAABA0-2F25-11d3-A164-0050041CAF44)]
|
||||
interface nsIRequest : nsISupports
|
||||
{
|
||||
/**
|
||||
* Returns true if the request is pending (active). Returns false
|
||||
* after completion or successful calling Cancel. Suspended requests
|
||||
* are still considered pending.
|
||||
*/
|
||||
boolean isPending();
|
||||
|
||||
/**
|
||||
* Cancels the current request. This will close any open input or
|
||||
* output streams and terminate any async requests.
|
||||
*/
|
||||
void cancel();
|
||||
|
||||
/**
|
||||
* Suspends the current requests. This may have the effect of closing
|
||||
* any underlying transport (in order to free up resources), although
|
||||
* any open streams remain logically opened and will continue delivering
|
||||
* data when the transport is resumed.
|
||||
*/
|
||||
void suspend();
|
||||
|
||||
/**
|
||||
* Resumes the current request. This may have the effect of re-opening
|
||||
* any underlying transport and will resume the delivery of data to
|
||||
* any open streams.
|
||||
*/
|
||||
void resume();
|
||||
};
|
||||
35
mozilla/netwerk/base/public/nsISocketTransport.idl
Normal file
35
mozilla/netwerk/base/public/nsISocketTransport.idl
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
[scriptable, uuid(785CA0F0-C39E-11d3-9ED6-0010A4053FD0)]
|
||||
interface nsISocketTransport : nsISupports
|
||||
{
|
||||
attribute boolean reuseConnection;
|
||||
|
||||
/**
|
||||
* Is used to tell the channel to stop reading data after a certain point;
|
||||
* needed by HTTP/1.1
|
||||
*/
|
||||
attribute long bytesAllowed;
|
||||
};
|
||||
76
mozilla/netwerk/base/public/nsISocketTransportService.idl
Normal file
76
mozilla/netwerk/base/public/nsISocketTransportService.idl
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIChannel;
|
||||
interface nsIEventSinkGetter;
|
||||
|
||||
[scriptable, uuid(05331390-6884-11d3-9382-00104ba0fd40)]
|
||||
interface nsISocketTransportService : nsISupports
|
||||
{
|
||||
/**
|
||||
* Creates a transport for a specified host and port.
|
||||
* The eventSinkGetter is used to get the appropriate callbacks
|
||||
* for the socket activity from the application. These include
|
||||
* the progress and the status messages like "Contacting host.."
|
||||
* etc. The printHost contains the actual hostname (and not the
|
||||
* proxy) for displaying in status messages.
|
||||
*/
|
||||
nsIChannel createTransport(in string host,
|
||||
in long port,
|
||||
in string printHost,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
nsIChannel createTransportOfType(in string socketType,
|
||||
in string host,
|
||||
in long port,
|
||||
in string printHost,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
/**
|
||||
* Returns true if the specified transport is good enough for
|
||||
* being used again. The situations in which this may return false
|
||||
* include- an error including server resets, an explicit
|
||||
* Connection: close header (for HTTP) and timeouts!
|
||||
*/
|
||||
boolean reuseTransport(in nsIChannel i_Transport);
|
||||
|
||||
void shutdown ();
|
||||
void wakeup (in nsIChannel i_Transport);
|
||||
};
|
||||
|
||||
%{C++
|
||||
#define NS_SOCKETTRANSPORTSERVICE_CID \
|
||||
{ /* c07e81e0-ef12-11d2-92b6-00105a1b0d64 */ \
|
||||
0xc07e81e0, \
|
||||
0xef12, \
|
||||
0x11d2, \
|
||||
{0x92, 0xb6, 0x00, 0x10, 0x5a, 0x1b, 0x0d, 0x64} \
|
||||
}
|
||||
|
||||
#define NS_ERROR_CONNECTION_REFUSED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 13)
|
||||
|
||||
#define NS_ERROR_NET_TIMEOUT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 14)
|
||||
|
||||
%}
|
||||
48
mozilla/netwerk/base/public/nsIStatusCodeEventSink.idl
Normal file
48
mozilla/netwerk/base/public/nsIStatusCodeEventSink.idl
Normal file
@@ -0,0 +1,48 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIProgressEventSink;
|
||||
interface nsIChannel;
|
||||
|
||||
/**
|
||||
* The nsIStatusCodeEventSink is a temporary interface to allow passing
|
||||
* status codes from the socket threads onto the UI without having to
|
||||
* pass strings. This could eventually go away if the proxy events
|
||||
* stuff can handle nested event loop. dougt is working on that.
|
||||
* We could continue to use this if this seems reasonable enough.
|
||||
*/
|
||||
[scriptable, uuid(6998ff36-1dd2-11b2-9ab7-e72a0f9fdd8c)]
|
||||
interface nsIStatusCodeEventSink : nsISupports
|
||||
{
|
||||
|
||||
/**
|
||||
* Notify the EventSink with a status code for the URL load.<BR>
|
||||
* Use IOService to request converting that code to a string.
|
||||
*/
|
||||
void onStatus(in nsIProgressEventSink sink,
|
||||
in nsIChannel channel,
|
||||
in nsISupports ctxt,
|
||||
in unsigned long aCode);
|
||||
|
||||
};
|
||||
96
mozilla/netwerk/base/public/nsIStreamListener.idl
Normal file
96
mozilla/netwerk/base/public/nsIStreamListener.idl
Normal file
@@ -0,0 +1,96 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIStreamObserver.idl"
|
||||
|
||||
interface nsIBufferInputStream;
|
||||
interface nsIInputStream;
|
||||
interface nsIBufferOutputStream;
|
||||
interface nsIEventQueue;
|
||||
|
||||
[scriptable, uuid(1a637020-1482-11d3-9333-00104ba0fd40)]
|
||||
interface nsIStreamListener : nsIStreamObserver
|
||||
{
|
||||
void onDataAvailable(in nsIChannel channel,
|
||||
in nsISupports ctxt,
|
||||
in nsIInputStream inStr,
|
||||
in unsigned long sourceOffset,
|
||||
in unsigned long count);
|
||||
};
|
||||
|
||||
/**
|
||||
* An asynchronous stream listener is used to ship data over to another thread specified
|
||||
* by the thread's event queue. The receiver stream listener is then used to receive
|
||||
* the notifications on the other thread.
|
||||
*
|
||||
* This interface only provides the initialization needed after construction. Otherwise,
|
||||
* these objects are used simply as nsIStreamListener.
|
||||
*/
|
||||
[scriptable, uuid(1b012ade-91bf-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIAsyncStreamListener : nsIStreamListener
|
||||
{
|
||||
/**
|
||||
* Initializes an nsIAsyncStreamListener.
|
||||
* @param eventQueue - may be null indicating the calling thread's event queue
|
||||
*/
|
||||
void init(in nsIStreamListener receiver,
|
||||
in nsIEventQueue eventQueue);
|
||||
};
|
||||
|
||||
/**
|
||||
* A synchronous stream listener pushes data through a pipe that ends up
|
||||
* in an input stream to be read by another thread.
|
||||
*
|
||||
* This interface only provides the initialization needed after construction. Otherwise,
|
||||
* these objects are used simply as nsIStreamListener.
|
||||
*/
|
||||
[scriptable, uuid(1f9fb93e-91bf-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsISyncStreamListener : nsIStreamListener
|
||||
{
|
||||
/**
|
||||
* Initializes an nsISyncStreamListener.
|
||||
*/
|
||||
void init(out nsIInputStream inStream,
|
||||
out nsIBufferOutputStream outStream);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
// Use this CID to construct an nsIAsyncStreamListener
|
||||
#define NS_ASYNCSTREAMLISTENER_CID \
|
||||
{ /* 60047bb2-91c0-11d3-8cd9-0060b0fc14a3 */ \
|
||||
0x60047bb2, \
|
||||
0x91c0, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xd9, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
// Use this CID to construct an nsISyncStreamListener
|
||||
#define NS_SYNCSTREAMLISTENER_CID \
|
||||
{ /* 65fa5cb2-91c0-11d3-8cd9-0060b0fc14a3 */ \
|
||||
0x65fa5cb2, \
|
||||
0x91c0, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xd9, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
%}
|
||||
67
mozilla/netwerk/base/public/nsIStreamLoader.idl
Normal file
67
mozilla/netwerk/base/public/nsIStreamLoader.idl
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIChannel.idl"
|
||||
|
||||
interface nsIURI;
|
||||
interface nsILoadGroup;
|
||||
interface nsIStreamObserver;
|
||||
interface nsIStreamLoader;
|
||||
interface nsIInterfaceRequestor;
|
||||
|
||||
[scriptable, uuid(359F7990-D4E9-11d3-A1A5-0050041CAF44)]
|
||||
interface nsIStreamLoaderObserver : nsISupports
|
||||
{
|
||||
void onStreamComplete(in nsIStreamLoader loader,
|
||||
in nsISupports ctxt,
|
||||
in nsresult status,
|
||||
in unsigned long resultLength,
|
||||
[size_is(resultLength)] in string result);
|
||||
};
|
||||
|
||||
[scriptable, uuid(31d37360-8e5a-11d3-93ad-00104ba0fd40)]
|
||||
interface nsIStreamLoader : nsISupports
|
||||
{
|
||||
void init(in nsIURI uri,
|
||||
in nsIStreamLoaderObserver completionObserver,
|
||||
in nsISupports ctxt,
|
||||
in nsILoadGroup loadGroup,
|
||||
in nsIInterfaceRequestor notificationCallbacks,
|
||||
in nsLoadFlags loadAttributes,
|
||||
in unsigned long bufferSegmentSize,
|
||||
in unsigned long bufferMaxSize);
|
||||
|
||||
/**
|
||||
* Gets the number of bytes read so far.
|
||||
*/
|
||||
readonly attribute unsigned long numBytesRead;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_STREAMLOADER_CID \
|
||||
{ /* 5BA6D920-D4E9-11d3-A1A5-0050041CAF44 */ \
|
||||
0x5ba6d920, 0xd4e9, 0x11d3, { 0xa1, 0xa5, 0x0, 0x50, 0x4, 0x1c, 0xaf, 0x44 } \
|
||||
}
|
||||
|
||||
%}
|
||||
78
mozilla/netwerk/base/public/nsIStreamObserver.idl
Normal file
78
mozilla/netwerk/base/public/nsIStreamObserver.idl
Normal file
@@ -0,0 +1,78 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
interface nsIEventQueue;
|
||||
interface nsIChannel;
|
||||
|
||||
[scriptable, uuid(fd91e2e0-1481-11d3-9333-00104ba0fd40)]
|
||||
interface nsIStreamObserver : nsISupports
|
||||
{
|
||||
void onStartRequest(in nsIChannel channel,
|
||||
in nsISupports ctxt);
|
||||
|
||||
void onStopRequest(in nsIChannel channel,
|
||||
in nsISupports ctxt,
|
||||
in nsresult status,
|
||||
in wstring errorMsg);
|
||||
};
|
||||
|
||||
/**
|
||||
* An asynchronous stream observer is used to ship data over to another thread specified
|
||||
* by the thread's event queue. The receiver stream observer is then used to receive
|
||||
* the notifications on the other thread.
|
||||
*
|
||||
* This interface only provides the initialization needed after construction. Otherwise,
|
||||
* these objects are used simply as nsIStreamObservers.
|
||||
*/
|
||||
[scriptable, uuid(a28dc590-91b3-11d3-8cd9-0060b0fc14a3)]
|
||||
interface nsIAsyncStreamObserver : nsIStreamObserver
|
||||
{
|
||||
/**
|
||||
* Initializes an nsIAsyncStreamObserver.
|
||||
* @param eventQueue - may be null indicating the calling thread's event queue
|
||||
*/
|
||||
void init(in nsIStreamObserver receiver,
|
||||
in nsIEventQueue eventQueue);
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
// Use this CID to construct an nsIAsyncStreamObserver
|
||||
#define NS_ASYNCSTREAMOBSERVER_CID \
|
||||
{ /* fcc7c380-91b3-11d3-8cd9-0060b0fc14a3 */ \
|
||||
0xfcc7c380, \
|
||||
0x91b3, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xd9, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Generic status codes for OnStopRequest:
|
||||
|
||||
#define NS_BINDING_SUCCEEDED NS_OK
|
||||
#define NS_BINDING_FAILED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 1)
|
||||
#define NS_BINDING_ABORTED NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 2)
|
||||
|
||||
%}
|
||||
|
||||
183
mozilla/netwerk/base/public/nsIURI.idl
Normal file
183
mozilla/netwerk/base/public/nsIURI.idl
Normal file
@@ -0,0 +1,183 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
#include "nsIURLParser.idl"
|
||||
|
||||
/**
|
||||
* URIs are essentially structured names for things -- anything.
|
||||
* This interface provides accessors to destructure those names.
|
||||
*
|
||||
* This interface follows Tim Berners-Lee's URI spec:
|
||||
*
|
||||
* http://www.w3.org/Addressing/URI/URI_Overview.html
|
||||
*
|
||||
* essentially:
|
||||
*
|
||||
* ftp://username:password@hostname:portnumber/pathname
|
||||
* \ / \ / \ / \ /\ /
|
||||
* - --------------- ------ -------- -------
|
||||
* | | | | |
|
||||
* | | | | Path
|
||||
* | | | Port
|
||||
* | | Host
|
||||
* | PreHost
|
||||
* Scheme
|
||||
*
|
||||
* The subclass nsIURL provides a means to open an input or output
|
||||
* stream to a URI as a source/destination, as well as providing additional
|
||||
* accessors to destructure the path, query and reference portions typically
|
||||
* associated with URLs.
|
||||
*/
|
||||
|
||||
%{C++
|
||||
#undef GetPort // XXX Windows!
|
||||
#undef SetPort // XXX Windows!
|
||||
%}
|
||||
|
||||
[scriptable, uuid(07a22cc0-0ce5-11d3-9331-00104ba0fd40)]
|
||||
interface nsIURI : nsISupports
|
||||
{
|
||||
/**
|
||||
* Returns a string representation of the URI. Setting the spec
|
||||
* causes the new spec to be parsed, initializing the URI. Setting
|
||||
* the spec (or any of the accessors) causes also any currently
|
||||
* open streams on the URI's channel to be closed.
|
||||
*/
|
||||
attribute string spec;
|
||||
|
||||
/**
|
||||
* The Scheme is the protocol to which this URI refers. Setting
|
||||
* the scheme is a special operation that builds up an equivalent
|
||||
* URI string from the new scheme and all the other URI attributes
|
||||
* and passes the it to the nsIOService to create a new URI for
|
||||
* the new scheme.
|
||||
*/
|
||||
attribute string scheme;
|
||||
|
||||
/**
|
||||
* The PreHost portion includes elements like the optional
|
||||
* username:password, or maybe other scheme specific items.
|
||||
*/
|
||||
attribute string preHost;
|
||||
|
||||
attribute string username;
|
||||
|
||||
attribute string password;
|
||||
|
||||
/**
|
||||
* The Host is the internet domain name to which this URI refers.
|
||||
* Note that it could be an IP address as well.
|
||||
*/
|
||||
attribute string host;
|
||||
|
||||
/**
|
||||
* A return value of -1 indicates that no port value is set and the
|
||||
* implementor of the specific scheme will use its default port.
|
||||
* Similarly setting a value of -1 indicates that the default is to be used.
|
||||
* Thus as an example:
|
||||
* for HTTP, Port 80 is same as a return value of -1.
|
||||
* However after setting a port (even if its default), the port number will
|
||||
* appear in the ToNewCString function.
|
||||
*/
|
||||
attribute long port;
|
||||
|
||||
/**
|
||||
* Note that the path includes the leading '/' Thus if no path is
|
||||
* available the Path accessor will return a "/"
|
||||
* For SetPath if none is provided, one would be prefixed to the path.
|
||||
*/
|
||||
attribute string path;
|
||||
|
||||
/**
|
||||
* This is a handle to the Parser used to parse the URI
|
||||
*/
|
||||
attribute nsIURLParser URLParser;
|
||||
|
||||
/**
|
||||
* Note that this comparison is only on char* level. Use
|
||||
* the scheme specific URI to do a more thorough check. For example,
|
||||
* in HTTP:
|
||||
* http://foo.com:80 == http://foo.com
|
||||
* but this function through nsIURI alone will not return equality
|
||||
* for this case.
|
||||
*/
|
||||
boolean equals(in nsIURI other);
|
||||
|
||||
/**
|
||||
* Clones the current URI. The newly created URI will be in a closed
|
||||
* state even if the underlying channel of the cloned URI is open.
|
||||
* Cloning allows the current location to be retained since once the
|
||||
* channel is opened the URI may get redirected to a new location.
|
||||
*/
|
||||
nsIURI clone();
|
||||
|
||||
/**
|
||||
* Sets the given string to be a relative path for this URI, and
|
||||
* changes this to read relative. Thus for example- if this =
|
||||
* http://foo.com/bar/index.html, then calling SetRelativePath("/baz") will
|
||||
* change this to http://foo.com/baz and calling it with "baz" will
|
||||
* change this to http://foo.com/bar/baz.
|
||||
*/
|
||||
void setRelativePath(in string relativePath);
|
||||
|
||||
/**
|
||||
* This method resolves a relative string into an absolute URI string,
|
||||
* using the URI as the base.
|
||||
*
|
||||
* This method subsumes the deprecated method nsIIOService::MakeAbsolute.
|
||||
*/
|
||||
string resolve(in string relativePath);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
// Malformed URI Error
|
||||
#define NS_ERROR_MALFORMED_URI NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_NETWORK, 10)
|
||||
|
||||
/**
|
||||
* Protocol writers can obtain a very basic (ok, degenerate) implementation
|
||||
* of nsIURI by calling the component manager with NS_SIMPLEURI_CID. The
|
||||
* implementation returned will only parse things of the form:
|
||||
*
|
||||
* about:cache
|
||||
* \ / \ /
|
||||
* --- ---
|
||||
* | |
|
||||
* Scheme Path
|
||||
*
|
||||
* where the path is everything after the colon. Note that this is probably
|
||||
* only useful for cases like about: or javascript: URIs.
|
||||
*
|
||||
* *** What you most likely will want is NS_STANDARDURL_CID which is much more
|
||||
* full featured. Look at nsIURL.idl for more details.
|
||||
*/
|
||||
|
||||
#define NS_SIMPLEURI_CID \
|
||||
{ /* e0da1d70-2f7b-11d3-8cd0-0060b0fc14a3 */ \
|
||||
0xe0da1d70, \
|
||||
0x2f7b, \
|
||||
0x11d3, \
|
||||
{0x8c, 0xd0, 0x00, 0x60, 0xb0, 0xfc, 0x14, 0xa3} \
|
||||
}
|
||||
|
||||
%}
|
||||
148
mozilla/netwerk/base/public/nsIURL.idl
Normal file
148
mozilla/netwerk/base/public/nsIURL.idl
Normal file
@@ -0,0 +1,148 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsIURI.idl"
|
||||
|
||||
interface nsIChannel;
|
||||
interface nsIEventSinkGetter;
|
||||
|
||||
/**
|
||||
* The nsIURL interface provides convenience methods that further
|
||||
* break down the path portion of nsIURI:
|
||||
*
|
||||
* http://directory/fileBaseName.fileExtension?query
|
||||
* http://directory/fileBaseName.fileExtension#ref
|
||||
* http://directory/fileBaseName.fileExtension;param
|
||||
* \ \ /
|
||||
* \ -----------------------
|
||||
* \ | /
|
||||
* \ fileName /
|
||||
* ----------------------------
|
||||
* |
|
||||
* filePath
|
||||
*/
|
||||
[scriptable, uuid(d6116970-8034-11d3-9399-00104ba0fd40)]
|
||||
interface nsIURL : nsIURI
|
||||
{
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// The path attribute is broken down into the following attributes:
|
||||
// filePath, param, query, and ref:
|
||||
|
||||
/**
|
||||
* Returns a path including the directory and file portions of a
|
||||
* URL. E.g. The filePath of "http://foo/bar.html#baz" is
|
||||
* "/foo/bar.html".
|
||||
*/
|
||||
attribute string filePath;
|
||||
|
||||
/**
|
||||
* Returns the parameters specified after the ; in the URL.
|
||||
*
|
||||
*/
|
||||
attribute string param;
|
||||
|
||||
/**
|
||||
* Returns the query portion (the part after the "?") of the URL.
|
||||
* If there isn't one, an empty string is returned.
|
||||
*/
|
||||
attribute string query;
|
||||
|
||||
/**
|
||||
* Returns the reference portion (the part after the "#") of the URL.
|
||||
* If there isn't one, an empty string is returned.
|
||||
*/
|
||||
attribute string ref;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// The filePath attribute is further broken down into the following
|
||||
// attributes: directory, file:
|
||||
|
||||
/**
|
||||
* Returns the directory portion of a URL.
|
||||
* If the URL denotes a path to a directory and not a file,
|
||||
* e.g. http://foo/bar/, then the Directory attribute accesses
|
||||
* the complete /foo/bar/ portion, and the FileName is the
|
||||
* empty string. If the trailing slash is omitted, then the
|
||||
* Directory is /foo/ and the file is bar (i.e. this is a
|
||||
* syntactic, not a semantic breakdown of the Path).
|
||||
* And hence dont rely on this for something to be a definitely
|
||||
* be a file. But you can get just the leading directory portion
|
||||
* for sure.
|
||||
*/
|
||||
attribute string directory;
|
||||
|
||||
/**
|
||||
* Returns the file name portion of a URL.
|
||||
* If the URL denotes a path to a directory and not a file,
|
||||
* e.g. http://foo/bar/, then the Directory attribute accesses
|
||||
* the complete /foo/bar/ portion, and the FileName is the
|
||||
* empty string. Note that this is purely based on searching
|
||||
* for the last trailing slash. And hence dont rely on this to
|
||||
* be a definite file.
|
||||
*/
|
||||
attribute string fileName;
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
// The fileName attribute is further broken down into the following
|
||||
// attributes: fileName, fileExtension:
|
||||
|
||||
attribute string fileBaseName;
|
||||
|
||||
/**
|
||||
* Returns the file extension portion of a filename in a url.
|
||||
* If a file extension does not exist, the empty string is returned.
|
||||
*/
|
||||
attribute string fileExtension;
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
/**
|
||||
* Protocol writers can obtain a default nsIURL implementation by calling the
|
||||
* component manager with NS_STANDARDURL_CID. The implementation returned will
|
||||
* only implement the set of accessors specified by nsIURL. After obtaining the
|
||||
* instance from the component manager, the Init routine must be called on it
|
||||
* to initialize it from the user's URL spec.
|
||||
*/
|
||||
|
||||
#define NS_STANDARDURL_CID \
|
||||
{ /* de9472d0-8034-11d3-9399-00104ba0fd40 */ \
|
||||
0xde9472d0, \
|
||||
0x8034, \
|
||||
0x11d3, \
|
||||
{0x93, 0x99, 0x00, 0x10, 0x4b, 0xa0, 0xfd, 0x40} \
|
||||
}
|
||||
|
||||
%}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
interface nsIFile;
|
||||
|
||||
/**
|
||||
* nsIFileURL is used for the file: protocol, and gives access to the
|
||||
* underlying nsIFile object.
|
||||
*/
|
||||
interface nsIFileURL : nsIURL
|
||||
{
|
||||
attribute nsIFile file;
|
||||
};
|
||||
125
mozilla/netwerk/base/public/nsIURLParser.idl
Normal file
125
mozilla/netwerk/base/public/nsIURLParser.idl
Normal file
@@ -0,0 +1,125 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Andreas Otte
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsISupports.idl"
|
||||
|
||||
/**
|
||||
* nsIURLParser is the abstract base class for parsing URLs
|
||||
*/
|
||||
|
||||
[scriptable, uuid(4b4975f9-f128-47fd-b11e-88402233cbdf)]
|
||||
interface nsIURLParser : nsISupports
|
||||
{
|
||||
|
||||
/**
|
||||
* Parses a URL and thinks it is parsing the scheme
|
||||
*/
|
||||
void ParseAtScheme(in string i_Spec,
|
||||
out string o_Scheme,
|
||||
out string o_Username,
|
||||
out string o_Password,
|
||||
out string o_Host,
|
||||
out long o_Port,
|
||||
out string o_Path);
|
||||
|
||||
/**
|
||||
* Parses a URL and thinks it is parsing the prehost
|
||||
*/
|
||||
void ParseAtPreHost(in string i_Spec,
|
||||
out string o_Username,
|
||||
out string o_Password,
|
||||
out string o_Host,
|
||||
out long o_Port,
|
||||
out string o_Path);
|
||||
|
||||
/**
|
||||
* Parses a URL and thinks it is parsing the host
|
||||
*/
|
||||
void ParseAtHost(in string i_Spec,
|
||||
out string o_Host,
|
||||
out long o_Port,
|
||||
out string o_Path);
|
||||
|
||||
/**
|
||||
* Parses a URL and thinks it is parsing the port
|
||||
*/
|
||||
void ParseAtPort(in string i_Spec,
|
||||
out long o_Port,
|
||||
out string o_Path);
|
||||
|
||||
/**
|
||||
* Parses a URL and thinks it is parsing the path
|
||||
*/
|
||||
void ParseAtPath(in string i_Spec,
|
||||
out string o_Path);
|
||||
|
||||
/**
|
||||
* Parses a URL-path and thinks it is parsing the directory
|
||||
*/
|
||||
void ParseAtDirectory(in string i_Path,
|
||||
out string o_Directory,
|
||||
out string o_FileBaseName,
|
||||
out string o_FileExtension,
|
||||
out string o_Param,
|
||||
out string o_Query,
|
||||
out string o_Ref);
|
||||
|
||||
/**
|
||||
* Parses the URL-PreHost into its components
|
||||
*/
|
||||
void ParsePreHost(in string i_PreHost,
|
||||
out string o_Username,
|
||||
out string o_Password);
|
||||
|
||||
/**
|
||||
* Parses the URL-Filename into its components
|
||||
*/
|
||||
void ParseFileName(in string i_FileName,
|
||||
out string o_FileBaseName,
|
||||
out string o_FileExtension);
|
||||
|
||||
};
|
||||
|
||||
%{C++
|
||||
|
||||
#define NS_STANDARDURLPARSER_CID \
|
||||
{ /* dbf72351-4fd8-46f0-9dbc-fa5ba60a30c5 */ \
|
||||
0xdbf72351, \
|
||||
0x4fd8, \
|
||||
0x46f0, \
|
||||
{0x9d, 0xbc, 0xfa, 0x5b, 0xa6, 0x0a, 0x30, 0x5c} \
|
||||
}
|
||||
|
||||
#define NS_AUTHORITYURLPARSER_CID \
|
||||
{ /* 90012125-1616-4fa1-ae14-4e7fa5766eb6 */ \
|
||||
0x90012125, \
|
||||
0x1616, \
|
||||
0x4fa1, \
|
||||
{0xae, 0x14, 0x4e, 0x7f, 0xa5, 0x76, 0x6e, 0xb6} \
|
||||
}
|
||||
|
||||
#define NS_NOAUTHORITYURLPARSER_CID \
|
||||
{ /* 9eeb1b89-c87e-4404-9de6-dbd41aeaf3d7 */ \
|
||||
0x9eeb1b89, \
|
||||
0xc87e, \
|
||||
0x4404, \
|
||||
{0x9d, 0xe6, 0xdb, 0xd4, 0x1a, 0xea, 0xf3, 0xd7} \
|
||||
}
|
||||
|
||||
%}
|
||||
322
mozilla/netwerk/base/public/nsNetUtil.h
Normal file
322
mozilla/netwerk/base/public/nsNetUtil.h
Normal file
@@ -0,0 +1,322 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsNetUtil_h__
|
||||
#define nsNetUtil_h__
|
||||
|
||||
#include "nsIURI.h"
|
||||
#include "netCore.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIInterfaceRequestor.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIHTTPProtocolHandler.h"
|
||||
#include "nsIStreamLoader.h"
|
||||
|
||||
inline nsresult
|
||||
NS_NewURI(nsIURI* *result, const char* spec, nsIURI* baseURI = nsnull)
|
||||
{
|
||||
nsresult rv;
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = serv->NewURI(spec, baseURI, result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewURI(nsIURI* *result, const nsString& spec, nsIURI* baseURI = nsnull)
|
||||
{
|
||||
char* specStr = spec.ToNewUTF8String(); // this forces a single byte char*
|
||||
if (specStr == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
nsresult rv = NS_NewURI(result, specStr, baseURI);
|
||||
nsAllocator::Free(specStr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_OpenURI(nsIChannel* *result, nsIURI* uri, nsILoadGroup *aGroup,
|
||||
nsIInterfaceRequestor *capabilities = nsnull,
|
||||
nsLoadFlags loadAttributes = nsIChannel::LOAD_NORMAL,
|
||||
PRUint32 bufferSegmentSize = 0,
|
||||
PRUint32 bufferMaxSize = 0)
|
||||
{
|
||||
nsresult rv;
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIChannel* channel;
|
||||
rv = serv->NewChannelFromURI("load", uri, aGroup, capabilities,
|
||||
loadAttributes, nsnull,
|
||||
bufferSegmentSize, bufferMaxSize, &channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = channel;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Use this function with CAUTION. And do not use it on
|
||||
// the UI thread. It creates a stream that blocks when
|
||||
// you Read() from it and blocking the UI thread is
|
||||
// illegal. If you don't want to implement a full
|
||||
// blown asyncrhonous consumer (via nsIStreamListener)
|
||||
// look at nsIStreamLoader instead.
|
||||
inline nsresult
|
||||
NS_OpenURI(nsIInputStream* *result, nsIURI* uri)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIChannel* channel;
|
||||
|
||||
rv = NS_OpenURI(&channel, uri, nsnull);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsIInputStream* inStr;
|
||||
rv = channel->OpenInputStream(0, -1, &inStr);
|
||||
NS_RELEASE(channel);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = inStr;
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_OpenURI(nsIStreamListener* aConsumer, nsISupports* context, nsIURI* uri,
|
||||
nsILoadGroup *aGroup)
|
||||
{
|
||||
nsresult rv;
|
||||
nsIChannel* channel;
|
||||
|
||||
rv = NS_OpenURI(&channel, uri, aGroup);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = channel->AsyncRead(0, -1, context, aConsumer);
|
||||
NS_RELEASE(channel);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_MakeAbsoluteURI(const char* spec, nsIURI* baseURI, char* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
NS_ASSERTION(baseURI, "It doesn't make sense to not supply a base URI");
|
||||
|
||||
if (spec == nsnull)
|
||||
return baseURI->GetSpec(result);
|
||||
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
|
||||
PRUint32 startPos, endPos;
|
||||
rv = serv->ExtractScheme(spec, &startPos, &endPos, nsnull);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
// if spec has a scheme, then it's already absolute
|
||||
*result = nsCRT::strdup(spec);
|
||||
return (*result == nsnull) ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
return baseURI->Resolve(spec, result);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_MakeAbsoluteURI(const nsString& spec, nsIURI* baseURI, nsString& result)
|
||||
{
|
||||
char* resultStr;
|
||||
char* specStr = spec.ToNewUTF8String();
|
||||
if (!specStr) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
nsresult rv = NS_MakeAbsoluteURI(specStr, baseURI, &resultStr);
|
||||
nsAllocator::Free(specStr);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
result = resultStr;
|
||||
nsAllocator::Free(resultStr);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewPostDataStream(PRBool isFile, const char *data, PRUint32 encodeFlags,
|
||||
nsIInputStream **result)
|
||||
{
|
||||
nsresult rv;
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIProtocolHandler> handler;
|
||||
rv = serv->GetProtocolHandler("http", getter_AddRefs(handler));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIHTTPProtocolHandler> http = do_QueryInterface(handler, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return http->NewPostDataStream(isFile, data, encodeFlags, result);
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewInputStreamChannel(nsIURI* uri,
|
||||
const char* contentType,
|
||||
PRInt32 contentLength,
|
||||
nsIInputStream* inStr,
|
||||
nsILoadGroup* group,
|
||||
nsIInterfaceRequestor* notificationCallbacks,
|
||||
nsLoadFlags loadAttributes,
|
||||
nsIURI* originalURI,
|
||||
PRUint32 bufferSegmentSize,
|
||||
PRUint32 bufferMaxSize,
|
||||
nsIChannel **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIInputStreamChannel> channel;
|
||||
static NS_DEFINE_CID(kInputStreamChannelCID, NS_INPUTSTREAMCHANNEL_CID);
|
||||
rv = nsComponentManager::CreateInstance(kInputStreamChannelCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIInputStreamChannel),
|
||||
getter_AddRefs(channel));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = channel->Init(uri, contentType, contentLength, inStr, group,
|
||||
notificationCallbacks, loadAttributes, originalURI,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = channel;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewLoadGroup(nsIStreamObserver* obs, nsILoadGroup* *result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsILoadGroup> group;
|
||||
static NS_DEFINE_CID(kLoadGroupCID, NS_LOADGROUP_CID);
|
||||
rv = nsComponentManager::CreateInstance(kLoadGroupCID, nsnull,
|
||||
NS_GET_IID(nsILoadGroup),
|
||||
getter_AddRefs(group));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = group->Init(obs);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = group;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
inline nsresult
|
||||
NS_NewStreamLoader(nsIStreamLoader* *result,
|
||||
nsIURI* uri,
|
||||
nsIStreamLoaderObserver* observer,
|
||||
nsISupports* context = nsnull,
|
||||
nsILoadGroup* loadGroup = nsnull,
|
||||
nsIInterfaceRequestor* notificationCallbacks = nsnull,
|
||||
nsLoadFlags loadAttributes = nsIChannel::LOAD_NORMAL,
|
||||
PRUint32 bufferSegmentSize = 0,
|
||||
PRUint32 bufferMaxSize = 0)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIStreamLoader> loader;
|
||||
static NS_DEFINE_CID(kStreamLoaderCID, NS_STREAMLOADER_CID);
|
||||
rv = nsComponentManager::CreateInstance(kStreamLoaderCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIStreamLoader),
|
||||
getter_AddRefs(loader));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = loader->Init(uri, observer, context, loadGroup, notificationCallbacks, loadAttributes,
|
||||
bufferSegmentSize, bufferMaxSize);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
*result = loader;
|
||||
NS_ADDREF(*result);
|
||||
return rv;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewAsyncStreamObserver(nsIStreamObserver *receiver, nsIEventQueue *eventQueue,
|
||||
nsIStreamObserver **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAsyncStreamObserver> obs;
|
||||
static NS_DEFINE_CID(kAsyncStreamObserverCID, NS_ASYNCSTREAMOBSERVER_CID);
|
||||
rv = nsComponentManager::CreateInstance(kAsyncStreamObserverCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIAsyncStreamObserver),
|
||||
getter_AddRefs(obs));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = obs->Init(receiver, eventQueue);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = obs;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewAsyncStreamListener(nsIStreamListener *receiver, nsIEventQueue *eventQueue,
|
||||
nsIStreamListener **result)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIAsyncStreamListener> lsnr;
|
||||
static NS_DEFINE_CID(kAsyncStreamListenerCID, NS_ASYNCSTREAMLISTENER_CID);
|
||||
rv = nsComponentManager::CreateInstance(kAsyncStreamListenerCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsIAsyncStreamListener),
|
||||
getter_AddRefs(lsnr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = lsnr->Init(receiver, eventQueue);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*result = lsnr;
|
||||
NS_ADDREF(*result);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
inline nsresult
|
||||
NS_NewSyncStreamListener(nsIInputStream **inStream,
|
||||
nsIBufferOutputStream **outStream,
|
||||
nsIStreamListener **listener)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsISyncStreamListener> lsnr;
|
||||
static NS_DEFINE_CID(kSyncStreamListenerCID, NS_SYNCSTREAMLISTENER_CID);
|
||||
rv = nsComponentManager::CreateInstance(kSyncStreamListenerCID,
|
||||
nsnull,
|
||||
NS_GET_IID(nsISyncStreamListener),
|
||||
getter_AddRefs(lsnr));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = lsnr->Init(inStream, outStream);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*listener = lsnr;
|
||||
NS_ADDREF(*listener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
#endif // nsNetUtil_h__
|
||||
100
mozilla/netwerk/base/public/nsUnixColorPrintf.h
Normal file
100
mozilla/netwerk/base/public/nsUnixColorPrintf.h
Normal file
@@ -0,0 +1,100 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef _nsUnixColorPrintf_h_
|
||||
#define _nsUnixColorPrintf_h_
|
||||
|
||||
#if defined(XP_UNIX) && defined(NS_DEBUG)
|
||||
|
||||
#define STARTGRAY "\033[1;30m"
|
||||
#define STARTRED "\033[1;31m"
|
||||
#define STARTGREEN "\033[1;32m"
|
||||
#define STARTYELLOW "\033[1;33m"
|
||||
#define STARTBLUE "\033[1;34m"
|
||||
#define STARTMAGENTA "\033[1;35m"
|
||||
#define STARTCYAN "\033[1;36m"
|
||||
#define STARTUNDERLINE "\033[4m"
|
||||
#define STARTREVERSE "\033[7m"
|
||||
#define ENDCOLOR "\033[0m"
|
||||
|
||||
#define PRINTF_GRAY nsUnixColorPrintf __color_printf(STARTGREY)
|
||||
#define PRINTF_RED nsUnixColorPrintf __color_printf(STARTRED)
|
||||
#define PRINTF_GREEN nsUnixColorPrintf __color_printf(STARTGREEN)
|
||||
#define PRINTF_YELLOW nsUnixColorPrintf __color_printf(STARTYELLOW)
|
||||
#define PRINTF_BLUE nsUnixColorPrintf __color_printf(STARTBLUE)
|
||||
#define PRINTF_MAGENTA nsUnixColorPrintf __color_printf(STARTMAGENTA)
|
||||
#define PRINTF_CYAN nsUnixColorPrintf __color_printf(STARTCYAN)
|
||||
#define PRINTF_UNDERLINE nsUnixColorPrintf __color_printf(STARTUNDERLINE)
|
||||
#define PRINTF_REVERSE nsUnixColorPrintf __color_printf(STARTREVERSE)
|
||||
|
||||
/*
|
||||
The nsUnixColorPrintf is a handy set of color term codes to change
|
||||
the color of console texts for easier spotting. As of now this is
|
||||
Unix and Debug only.
|
||||
|
||||
Usage is simple.
|
||||
|
||||
See examples in
|
||||
mozilla/netwerk/protocol/http/src/nsHTTPHandler.cpp
|
||||
|
||||
-Gagan Saksena 11/01/99
|
||||
*/
|
||||
|
||||
class nsUnixColorPrintf
|
||||
{
|
||||
public:
|
||||
nsUnixColorPrintf(const char* colorCode)
|
||||
{
|
||||
printf("%s",colorCode);
|
||||
}
|
||||
~nsUnixColorPrintf()
|
||||
{
|
||||
printf("%s",ENDCOLOR);
|
||||
}
|
||||
};
|
||||
|
||||
#else // XP_UNIX
|
||||
|
||||
#define STARTGRAY ""
|
||||
#define STARTRED ""
|
||||
#define STARTGREEN ""
|
||||
#define STARTYELLOW ""
|
||||
#define STARTBLUE ""
|
||||
#define STARTMAGENTA ""
|
||||
#define STARTCYAN ""
|
||||
#define STARTUNDERLINE ""
|
||||
#define STARTREVERSE ""
|
||||
#define ENDCOLOR ""
|
||||
|
||||
#define PRINTF_GRAY
|
||||
#define PRINTF_RED
|
||||
#define PRINTF_GREEN
|
||||
#define PRINTF_YELLOW
|
||||
#define PRINTF_BLUE
|
||||
#define PRINTF_MAGENTA
|
||||
#define PRINTF_CYAN
|
||||
#define PRINTF_UNDERLINE
|
||||
#define PRINTF_REVERSE
|
||||
|
||||
#endif // XP_UNIX
|
||||
#endif // nsUnixColorPrintf
|
||||
|
||||
63
mozilla/netwerk/base/src/Makefile.in
Normal file
63
mozilla/netwerk/base/src/Makefile.in
Normal file
@@ -0,0 +1,63 @@
|
||||
#
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
#
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = necko
|
||||
LIBRARY_NAME = neckobase_s
|
||||
|
||||
CPPSRCS = \
|
||||
nsURLHelper.cpp \
|
||||
nsFileStreams.cpp \
|
||||
nsBufferedStreams.cpp \
|
||||
nsAsyncStreamListener.cpp \
|
||||
nsSyncStreamListener.cpp \
|
||||
nsIOService.cpp \
|
||||
nsSocketTransport.cpp \
|
||||
nsSocketTransportService.cpp \
|
||||
nsFileTransport.cpp \
|
||||
nsFileTransportService.cpp \
|
||||
nsStdURLParser.cpp \
|
||||
nsAuthURLParser.cpp \
|
||||
nsNoAuthURLParser.cpp \
|
||||
nsStdURL.cpp \
|
||||
nsSimpleURI.cpp \
|
||||
nsNetModuleMgr.cpp \
|
||||
nsNetModRegEntry.cpp \
|
||||
nsLoadGroup.cpp \
|
||||
nsInputStreamChannel.cpp \
|
||||
nsDirectoryIndexStream.cpp \
|
||||
nsStreamLoader.cpp \
|
||||
nsProtocolProxyService.cpp \
|
||||
$(NULL)
|
||||
|
||||
# we don't want the shared lib, but we want to force the creation of a
|
||||
# static lib.
|
||||
override NO_SHARED_LIB=1
|
||||
override NO_STATIC_LIB=
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
64
mozilla/netwerk/base/src/makefile.win
Normal file
64
mozilla/netwerk/base/src/makefile.win
Normal file
@@ -0,0 +1,64 @@
|
||||
# The contents of this file are subject to the Netscape Public
|
||||
# License Version 1.1 (the "License"); you may not use this file
|
||||
# except in compliance with the License. You may obtain a copy of
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
|
||||
MODULE = necko
|
||||
|
||||
DEPTH = ..\..\..
|
||||
include <$(DEPTH)/config/config.mak>
|
||||
|
||||
LCFLAGS = -DWIN32_LEAN_AND_MEAN -D_IMPL_NS_NET
|
||||
|
||||
LIBRARY_NAME=neckobase_s
|
||||
|
||||
CPP_OBJS = \
|
||||
.\$(OBJDIR)\nsURLHelper.obj \
|
||||
.\$(OBJDIR)\nsFileStreams.obj \
|
||||
.\$(OBJDIR)\nsBufferedStreams.obj \
|
||||
.\$(OBJDIR)\nsAsyncStreamListener.obj \
|
||||
.\$(OBJDIR)\nsSyncStreamListener.obj \
|
||||
.\$(OBJDIR)\nsIOService.obj \
|
||||
.\$(OBJDIR)\nsSocketTransport.obj \
|
||||
.\$(OBJDIR)\nsSocketTransportService.obj \
|
||||
.\$(OBJDIR)\nsFileTransport.obj \
|
||||
.\$(OBJDIR)\nsFileTransportService.obj \
|
||||
.\$(OBJDIR)\nsStdURLParser.obj \
|
||||
.\$(OBJDIR)\nsAuthURLParser.obj \
|
||||
.\$(OBJDIR)\nsNoAuthURLParser.obj \
|
||||
.\$(OBJDIR)\nsStdURL.obj \
|
||||
.\$(OBJDIR)\nsSimpleURI.obj \
|
||||
.\$(OBJDIR)\nsNetModuleMgr.obj \
|
||||
.\$(OBJDIR)\nsNetModRegEntry.obj \
|
||||
.\$(OBJDIR)\nsLoadGroup.obj \
|
||||
.\$(OBJDIR)\nsInputStreamChannel.obj \
|
||||
.\$(OBJDIR)\nsDirectoryIndexStream.obj \
|
||||
.\$(OBJDIR)\nsStreamLoader.obj \
|
||||
.\$(OBJDIR)\nsProtocolProxyService.obj \
|
||||
$(NULL)
|
||||
|
||||
INCS = $(INCS) \
|
||||
-I$(DEPTH)\dist\include \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
|
||||
install:: $(LIBRARY)
|
||||
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
|
||||
|
||||
clobber::
|
||||
rm -f $(DIST)\lib\$(LIBRARY_NAME).lib
|
||||
468
mozilla/netwerk/base/src/nsAsyncStreamListener.cpp
Normal file
468
mozilla/netwerk/base/src/nsAsyncStreamListener.cpp
Normal file
@@ -0,0 +1,468 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsAsyncStreamListener.h"
|
||||
#include "nsIBufferInputStream.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsIEventQueueService.h"
|
||||
#include "nsIIOService.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "prlog.h"
|
||||
|
||||
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
PRLogModuleInfo* gStreamEventLog = 0;
|
||||
#endif
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsStreamListenerEvent
|
||||
{
|
||||
public:
|
||||
nsStreamListenerEvent(nsAsyncStreamObserver* listener,
|
||||
nsIChannel* channel, nsISupports* context);
|
||||
virtual ~nsStreamListenerEvent();
|
||||
|
||||
nsresult Fire(nsIEventQueue* aEventQ);
|
||||
|
||||
NS_IMETHOD HandleEvent() = 0;
|
||||
|
||||
protected:
|
||||
static void PR_CALLBACK HandlePLEvent(PLEvent* aEvent);
|
||||
static void PR_CALLBACK DestroyPLEvent(PLEvent* aEvent);
|
||||
|
||||
nsAsyncStreamObserver* mListener;
|
||||
nsIChannel* mChannel;
|
||||
nsISupports* mContext;
|
||||
PLEvent * mEvent;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsStreamListenerEvent::nsStreamListenerEvent(nsAsyncStreamObserver* listener,
|
||||
nsIChannel* channel, nsISupports* context)
|
||||
: mListener(listener), mChannel(channel), mContext(context), mEvent(nsnull)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsStreamListenerEvent);
|
||||
|
||||
NS_IF_ADDREF(mListener);
|
||||
NS_IF_ADDREF(mChannel);
|
||||
NS_IF_ADDREF(mContext);
|
||||
}
|
||||
|
||||
nsStreamListenerEvent::~nsStreamListenerEvent()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsStreamListenerEvent);
|
||||
|
||||
NS_IF_RELEASE(mListener);
|
||||
NS_IF_RELEASE(mChannel);
|
||||
NS_IF_RELEASE(mContext);
|
||||
|
||||
if (nsnull != mEvent)
|
||||
{
|
||||
delete mEvent;
|
||||
mEvent = nsnull;
|
||||
}
|
||||
}
|
||||
|
||||
void PR_CALLBACK nsStreamListenerEvent::HandlePLEvent(PLEvent* aEvent)
|
||||
{
|
||||
nsStreamListenerEvent * ev =
|
||||
(nsStreamListenerEvent *) PL_GetEventOwner(aEvent);
|
||||
|
||||
NS_ASSERTION(nsnull != ev,"null event.");
|
||||
|
||||
nsresult rv = ev->HandleEvent();
|
||||
ev->mListener->SetStatus(rv);
|
||||
}
|
||||
|
||||
void PR_CALLBACK nsStreamListenerEvent::DestroyPLEvent(PLEvent* aEvent)
|
||||
{
|
||||
nsStreamListenerEvent * ev =
|
||||
(nsStreamListenerEvent *) PL_GetEventOwner(aEvent);
|
||||
|
||||
NS_ASSERTION(nsnull != ev,"null event.");
|
||||
|
||||
delete ev;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsStreamListenerEvent::Fire(nsIEventQueue* aEventQueue)
|
||||
{
|
||||
NS_PRECONDITION(nsnull != aEventQueue, "nsIEventQueue for thread is null");
|
||||
|
||||
NS_PRECONDITION(nsnull == mEvent, "Init plevent only once.");
|
||||
|
||||
mEvent = new PLEvent;
|
||||
|
||||
PL_InitEvent(mEvent,
|
||||
this,
|
||||
(PLHandleEventProc) nsStreamListenerEvent::HandlePLEvent,
|
||||
(PLDestroyEventProc) nsStreamListenerEvent::DestroyPLEvent);
|
||||
|
||||
PRStatus status = aEventQueue->PostEvent(mEvent);
|
||||
return status == PR_SUCCESS ? NS_OK : NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsAsyncStreamObserver::~nsAsyncStreamObserver()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_THREADSAFE_ADDREF(nsAsyncStreamObserver)
|
||||
NS_IMPL_THREADSAFE_RELEASE(nsAsyncStreamObserver)
|
||||
NS_IMPL_QUERY_INTERFACE2(nsAsyncStreamObserver,
|
||||
nsIAsyncStreamObserver,
|
||||
nsIStreamObserver)
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsAsyncStreamListener, nsAsyncStreamObserver);
|
||||
NS_IMPL_RELEASE_INHERITED(nsAsyncStreamListener, nsAsyncStreamObserver);
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAsyncStreamListener::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
|
||||
if (aIID.Equals(NS_GET_IID(nsIAsyncStreamListener))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIAsyncStreamListener*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(NS_GET_IID(nsIStreamListener))) {
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIStreamListener*, this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
return nsAsyncStreamObserver::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAsyncStreamObserver::Init(nsIStreamObserver* aObserver, nsIEventQueue* aEventQ)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
mReceiver = aObserver;
|
||||
|
||||
NS_WITH_SERVICE(nsIEventQueueService, eventQService, kEventQueueService, &rv);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = eventQService->ResolveEventQueue(aEventQ, getter_AddRefs(mEventQueue));
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// OnStartRequest...
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsOnStartRequestEvent : public nsStreamListenerEvent
|
||||
{
|
||||
public:
|
||||
nsOnStartRequestEvent(nsAsyncStreamObserver* listener,
|
||||
nsIChannel* channel, nsISupports* context)
|
||||
: nsStreamListenerEvent(listener, channel, context) {}
|
||||
virtual ~nsOnStartRequestEvent() {}
|
||||
|
||||
NS_IMETHOD HandleEvent();
|
||||
};
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOnStartRequestEvent::HandleEvent()
|
||||
{
|
||||
#if defined(PR_LOGGING)
|
||||
if (!gStreamEventLog)
|
||||
gStreamEventLog = PR_NewLogModule("netlibStreamEvent");
|
||||
PR_LOG(gStreamEventLog, PR_LOG_DEBUG,
|
||||
("netlibEvent: Handle Start [event=%x]", this));
|
||||
#endif
|
||||
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
|
||||
return receiver->OnStartRequest(mChannel, mContext);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAsyncStreamObserver::OnStartRequest(nsIChannel* channel, nsISupports* context)
|
||||
{
|
||||
nsresult rv = GetStatus();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsOnStartRequestEvent* event =
|
||||
new nsOnStartRequestEvent(this, channel, context);
|
||||
if (event == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
#if defined(PR_LOGGING)
|
||||
PLEventQueue *equeue;
|
||||
mEventQueue->GetPLEventQueue(&equeue);
|
||||
char ts[80];
|
||||
sprintf(ts, "nsAsyncStreamObserver: Start [this=%lx queue=%lx",
|
||||
(long)this, (long)equeue);
|
||||
if (!gStreamEventLog)
|
||||
gStreamEventLog = PR_NewLogModule("netlibStreamEvent");
|
||||
PR_LOG(gStreamEventLog, PR_LOG_DEBUG,
|
||||
("nsAsyncStreamObserver: Start [this=%x queue=%x event=%x]",
|
||||
this, equeue, event));
|
||||
#endif
|
||||
rv = event->Fire(mEventQueue);
|
||||
if (NS_FAILED(rv)) goto failed;
|
||||
return rv;
|
||||
|
||||
failed:
|
||||
delete event;
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// OnStopRequest
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsOnStopRequestEvent : public nsStreamListenerEvent
|
||||
{
|
||||
public:
|
||||
nsOnStopRequestEvent(nsAsyncStreamObserver* listener,
|
||||
nsISupports* context, nsIChannel* channel)
|
||||
: nsStreamListenerEvent(listener, channel, context),
|
||||
mStatus(NS_OK), mMessage(nsnull) {}
|
||||
virtual ~nsOnStopRequestEvent();
|
||||
|
||||
nsresult Init(nsresult status, const PRUnichar* aMsg);
|
||||
NS_IMETHOD HandleEvent();
|
||||
|
||||
protected:
|
||||
nsresult mStatus;
|
||||
PRUnichar* mMessage;
|
||||
};
|
||||
|
||||
nsOnStopRequestEvent::~nsOnStopRequestEvent()
|
||||
{
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsOnStopRequestEvent::Init(nsresult status, const PRUnichar* aMsg)
|
||||
{
|
||||
mStatus = status;
|
||||
mMessage = (PRUnichar*)aMsg;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOnStopRequestEvent::HandleEvent()
|
||||
{
|
||||
#if defined(PR_LOGGING)
|
||||
if (!gStreamEventLog)
|
||||
gStreamEventLog = PR_NewLogModule("netlibStreamEvent");
|
||||
PR_LOG(gStreamEventLog, PR_LOG_DEBUG,
|
||||
("netlibEvent: Handle Stop [event=%x]", this));
|
||||
#endif
|
||||
nsIStreamObserver* receiver = (nsIStreamObserver*)mListener->GetReceiver();
|
||||
nsresult rv = mListener->GetStatus();
|
||||
|
||||
//
|
||||
// If the consumer returned a failure code, then pass it out in the
|
||||
// OnStopRequest(...) notification...
|
||||
//
|
||||
if (NS_FAILED(rv)) {
|
||||
mStatus = rv;
|
||||
}
|
||||
return receiver->OnStopRequest(mChannel, mContext, mStatus, mMessage);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAsyncStreamObserver::OnStopRequest(nsIChannel* channel, nsISupports* context,
|
||||
nsresult aStatus,
|
||||
const PRUnichar* aMsg)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
//
|
||||
// Fire the OnStopRequest(...) regardless of what the current
|
||||
// Status is...
|
||||
//
|
||||
nsOnStopRequestEvent* event =
|
||||
new nsOnStopRequestEvent(this, context, channel);
|
||||
if (event == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = event->Init(aStatus, aMsg);
|
||||
if (NS_FAILED(rv)) goto failed;
|
||||
#if defined(PR_LOGGING)
|
||||
PLEventQueue *equeue;
|
||||
mEventQueue->GetPLEventQueue(&equeue);
|
||||
if (!gStreamEventLog)
|
||||
gStreamEventLog = PR_NewLogModule("netlibStreamEvent");
|
||||
PR_LOG(gStreamEventLog, PR_LOG_DEBUG,
|
||||
("nsAsyncStreamObserver: Stop [this=%x queue=%x event=%x]",
|
||||
this, equeue, event));
|
||||
#endif
|
||||
rv = event->Fire(mEventQueue);
|
||||
if (NS_FAILED(rv)) goto failed;
|
||||
return rv;
|
||||
|
||||
failed:
|
||||
delete event;
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// OnDataAvailable
|
||||
//
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsOnDataAvailableEvent : public nsStreamListenerEvent
|
||||
{
|
||||
public:
|
||||
nsOnDataAvailableEvent(nsAsyncStreamObserver* listener,
|
||||
nsIChannel* channel, nsISupports* context)
|
||||
: nsStreamListenerEvent(listener, channel, context),
|
||||
mIStream(nsnull), mLength(0) {}
|
||||
virtual ~nsOnDataAvailableEvent();
|
||||
|
||||
nsresult Init(nsIInputStream* aIStream, PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
NS_IMETHOD HandleEvent();
|
||||
|
||||
protected:
|
||||
nsIInputStream* mIStream;
|
||||
PRUint32 mSourceOffset;
|
||||
PRUint32 mLength;
|
||||
};
|
||||
|
||||
nsOnDataAvailableEvent::~nsOnDataAvailableEvent()
|
||||
{
|
||||
NS_RELEASE(mIStream);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsOnDataAvailableEvent::Init(nsIInputStream* aIStream, PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
mSourceOffset = aSourceOffset;
|
||||
mLength = aLength;
|
||||
mIStream = aIStream;
|
||||
NS_ADDREF(mIStream);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsOnDataAvailableEvent::HandleEvent()
|
||||
{
|
||||
#if defined(PR_LOGGING)
|
||||
if (!gStreamEventLog)
|
||||
gStreamEventLog = PR_NewLogModule("netlibStreamEvent");
|
||||
PR_LOG(gStreamEventLog, PR_LOG_DEBUG,
|
||||
("netlibEvent: Handle Data [event=%x]", this));
|
||||
#endif
|
||||
nsIStreamListener* receiver = (nsIStreamListener*)mListener->GetReceiver();
|
||||
nsresult rv = mListener->GetStatus();
|
||||
//
|
||||
// Only send OnDataAvailable(... ) notifications if all previous calls
|
||||
// have succeeded...
|
||||
//
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
rv = receiver->OnDataAvailable(mChannel, mContext,
|
||||
mIStream, mSourceOffset, mLength);
|
||||
//
|
||||
// If the consumer fails, then cancel the transport. This is necessary
|
||||
// in case where the socket transport is blocked waiting for room in the
|
||||
// pipe, but the consumer fails without consuming all the data.
|
||||
//
|
||||
// Unless the transport is cancelled, it will block forever, waiting for
|
||||
// the pipe to empty...
|
||||
//
|
||||
if (NS_FAILED(rv)) {
|
||||
mChannel->Cancel();
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsAsyncStreamListener::OnDataAvailable(nsIChannel* channel, nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength)
|
||||
{
|
||||
nsresult rv = GetStatus();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsOnDataAvailableEvent* event =
|
||||
new nsOnDataAvailableEvent(this, channel, context);
|
||||
if (event == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
rv = event->Init(aIStream, aSourceOffset, aLength);
|
||||
if (NS_FAILED(rv)) goto failed;
|
||||
#if defined(PR_LOGGING)
|
||||
PLEventQueue *equeue;
|
||||
mEventQueue->GetPLEventQueue(&equeue);
|
||||
if (!gStreamEventLog)
|
||||
gStreamEventLog = PR_NewLogModule("netlibStreamEvent");
|
||||
PR_LOG(gStreamEventLog, PR_LOG_DEBUG,
|
||||
("nsAsyncStreamObserver: Data [this=%x queue=%x event=%x]",
|
||||
this, equeue, event));
|
||||
#endif
|
||||
rv = event->Fire(mEventQueue);
|
||||
if (NS_FAILED(rv)) goto failed;
|
||||
return rv;
|
||||
|
||||
failed:
|
||||
delete event;
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_METHOD
|
||||
nsAsyncStreamObserver::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
nsAsyncStreamObserver* l = new nsAsyncStreamObserver();
|
||||
if (l == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(l);
|
||||
nsresult rv = l->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(l);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
nsAsyncStreamListener::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
nsAsyncStreamListener* l = new nsAsyncStreamListener();
|
||||
if (l == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(l);
|
||||
nsresult rv = l->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(l);
|
||||
return rv;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
106
mozilla/netwerk/base/src/nsAsyncStreamListener.h
Normal file
106
mozilla/netwerk/base/src/nsAsyncStreamListener.h
Normal file
@@ -0,0 +1,106 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsAsyncStreamListener_h__
|
||||
#define nsAsyncStreamListener_h__
|
||||
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIStreamObserver.h"
|
||||
#include "nsIStreamListener.h"
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsAsyncStreamObserver : public nsIAsyncStreamObserver
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSISTREAMOBSERVER
|
||||
NS_DECL_NSIASYNCSTREAMOBSERVER
|
||||
|
||||
// nsAsyncStreamObserver methods:
|
||||
nsAsyncStreamObserver()
|
||||
: mStatus(NS_OK)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
virtual ~nsAsyncStreamObserver();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
nsISupports* GetReceiver() { return mReceiver.get(); }
|
||||
nsresult GetStatus() { return mStatus; }
|
||||
void SetStatus(nsresult value) { if (NS_SUCCEEDED(mStatus)) mStatus = value; }
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIEventQueue> mEventQueue;
|
||||
nsCOMPtr<nsIStreamObserver> mReceiver;
|
||||
nsresult mStatus;
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class nsAsyncStreamListener : public nsAsyncStreamObserver,
|
||||
public nsIAsyncStreamListener
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
// nsIStreamListener methods:
|
||||
NS_IMETHOD OnStartRequest(nsIChannel* channel,
|
||||
nsISupports* context)
|
||||
{
|
||||
return nsAsyncStreamObserver::OnStartRequest(channel, context);
|
||||
}
|
||||
|
||||
NS_IMETHOD OnStopRequest(nsIChannel* channel,
|
||||
nsISupports* context,
|
||||
nsresult aStatus,
|
||||
const PRUnichar* aMsg)
|
||||
{
|
||||
return nsAsyncStreamObserver::OnStopRequest(channel, context, aStatus, aMsg);
|
||||
}
|
||||
|
||||
NS_IMETHOD OnDataAvailable(nsIChannel* channel, nsISupports* context,
|
||||
nsIInputStream *aIStream,
|
||||
PRUint32 aSourceOffset,
|
||||
PRUint32 aLength);
|
||||
|
||||
// nsIAsyncStreamListener methods:
|
||||
NS_IMETHOD Init(nsIStreamListener* aListener, nsIEventQueue* aEventQ) {
|
||||
return nsAsyncStreamObserver::Init(aListener, aEventQ);
|
||||
}
|
||||
|
||||
// nsAsyncStreamListener methods:
|
||||
nsAsyncStreamListener() {}
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
};
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#endif // nsAsyncStreamListener_h__
|
||||
497
mozilla/netwerk/base/src/nsAuthURLParser.cpp
Normal file
497
mozilla/netwerk/base/src/nsAuthURLParser.cpp
Normal file
@@ -0,0 +1,497 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Andreas Otte.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#include "nsAuthURLParser.h"
|
||||
#include "nsURLHelper.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsString.h"
|
||||
#include "prprf.h"
|
||||
|
||||
NS_IMPL_THREADSAFE_ISUPPORTS(nsAuthURLParser, NS_GET_IID(nsIURLParser))
|
||||
|
||||
nsAuthURLParser::~nsAuthURLParser()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
NS_METHOD
|
||||
nsAuthURLParser::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
||||
{
|
||||
if (aOuter)
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
nsAuthURLParser* p = new nsAuthURLParser();
|
||||
if (p == nsnull)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
NS_ADDREF(p);
|
||||
nsresult rv = p->QueryInterface(aIID, aResult);
|
||||
NS_RELEASE(p);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParseAtScheme(const char* i_Spec, char* *o_Scheme,
|
||||
char* *o_Username, char* *o_Password,
|
||||
char* *o_Host, PRInt32 *o_Port, char* *o_Path)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
NS_PRECONDITION( (nsnull != i_Spec), "Parse called on empty url!");
|
||||
if (!i_Spec)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
|
||||
int len = PL_strlen(i_Spec);
|
||||
if (len >= 2 && *i_Spec == '/' && *(i_Spec+1) == '/') // No Scheme
|
||||
{
|
||||
rv = ParseAtPreHost(i_Spec, o_Username, o_Password, o_Host, o_Port,
|
||||
o_Path);
|
||||
return rv;
|
||||
}
|
||||
|
||||
static const char delimiters[] = "/:@?"; //this order is optimized.
|
||||
char* brk = PL_strpbrk(i_Spec, delimiters);
|
||||
|
||||
if (!brk) // everything is a host
|
||||
{
|
||||
rv = ExtractString((char*)i_Spec, o_Host, len);
|
||||
ToLowerCase(*o_Host);
|
||||
return rv;
|
||||
} else
|
||||
len = PL_strlen(brk);
|
||||
|
||||
switch (*brk)
|
||||
{
|
||||
case '/' :
|
||||
case '?' :
|
||||
// If the URL starts with a slash then everything is a path
|
||||
if (brk == i_Spec)
|
||||
{
|
||||
rv = ParseAtPath(brk, o_Path);
|
||||
return rv;
|
||||
}
|
||||
else // The first part is host, so its host/path
|
||||
{
|
||||
rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
ToLowerCase(*o_Host);
|
||||
rv = ParseAtPath(brk, o_Path);
|
||||
return rv;
|
||||
}
|
||||
break;
|
||||
case ':' :
|
||||
if (len >= 2 && *(brk+1) == '/') {
|
||||
// Standard http://... or malformed http:/...
|
||||
rv = ExtractString((char*)i_Spec, o_Scheme, (brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
ToLowerCase(*o_Scheme);
|
||||
rv = ParseAtPreHost(brk+1, o_Username, o_Password, o_Host,
|
||||
o_Port, o_Path);
|
||||
return rv;
|
||||
} else {
|
||||
// Could be host:port, so try conversion to number
|
||||
PRInt32 port = ExtractPortFrom(brk+1);
|
||||
if (port > 0)
|
||||
{
|
||||
rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
ToLowerCase(*o_Host);
|
||||
rv = ParseAtPort(brk+1, o_Port, o_Path);
|
||||
return rv;
|
||||
} else {
|
||||
// No, it's not a number try scheme:host...
|
||||
rv = ExtractString((char*)i_Spec, o_Scheme,
|
||||
(brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
ToLowerCase(*o_Scheme);
|
||||
rv = ParseAtPreHost(brk+1, o_Username, o_Password, o_Host,
|
||||
o_Port, o_Path);
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case '@' :
|
||||
rv = ParseAtPreHost(i_Spec, o_Username, o_Password, o_Host,
|
||||
o_Port, o_Path);
|
||||
return rv;
|
||||
break;
|
||||
default:
|
||||
NS_ASSERTION(0, "This just can't be!");
|
||||
break;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParseAtPreHost(const char* i_Spec, char* *o_Username,
|
||||
char* *o_Password, char* *o_Host,
|
||||
PRInt32 *o_Port, char* *o_Path)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// Skip leading two slashes
|
||||
char* fwdPtr= (char*) i_Spec;
|
||||
if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/'))
|
||||
fwdPtr++;
|
||||
if (fwdPtr && (*fwdPtr != '\0') && (*fwdPtr == '/'))
|
||||
fwdPtr++;
|
||||
|
||||
static const char delimiters[] = "/:@?";
|
||||
char* brk = PL_strpbrk(fwdPtr, delimiters);
|
||||
char* brk2 = nsnull;
|
||||
|
||||
if (!brk)
|
||||
{
|
||||
rv = ParseAtHost(fwdPtr, o_Host, o_Port, o_Path);
|
||||
return rv;
|
||||
}
|
||||
|
||||
char* e_PreHost = nsnull;
|
||||
switch (*brk)
|
||||
{
|
||||
case ':' :
|
||||
// this maybe the : of host:port or username:password
|
||||
// look if the next special char is @
|
||||
brk2 = PL_strpbrk(brk+1, delimiters);
|
||||
|
||||
if (!brk2)
|
||||
{
|
||||
rv = ParseAtHost(fwdPtr, o_Host, o_Port, o_Path);
|
||||
return rv;
|
||||
}
|
||||
switch (*brk2)
|
||||
{
|
||||
case '@' :
|
||||
rv = ExtractString(fwdPtr, &e_PreHost, (brk2 - fwdPtr));
|
||||
if (NS_FAILED(rv)) {
|
||||
CRTFREEIF(e_PreHost);
|
||||
return rv;
|
||||
}
|
||||
rv = ParsePreHost(e_PreHost,o_Username,o_Password);
|
||||
CRTFREEIF(e_PreHost);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = ParseAtHost(brk2+1, o_Host, o_Port, o_Path);
|
||||
break;
|
||||
default:
|
||||
rv = ParseAtHost(fwdPtr, o_Host, o_Port, o_Path);
|
||||
return rv;
|
||||
}
|
||||
break;
|
||||
case '@' :
|
||||
rv = ExtractString(fwdPtr, &e_PreHost, (brk - fwdPtr));
|
||||
if (NS_FAILED(rv)) {
|
||||
CRTFREEIF(e_PreHost);
|
||||
return rv;
|
||||
}
|
||||
rv = ParsePreHost(e_PreHost,o_Username,o_Password);
|
||||
CRTFREEIF(e_PreHost);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
rv = ParseAtHost(brk+1, o_Host, o_Port, o_Path);
|
||||
break;
|
||||
default:
|
||||
rv = ParseAtHost(fwdPtr, o_Host, o_Port, o_Path);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParseAtHost(const char* i_Spec, char* *o_Host,
|
||||
PRInt32 *o_Port, char* *o_Path)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
int len = PL_strlen(i_Spec);
|
||||
static const char delimiters[] = ":/?"; //this order is optimized.
|
||||
char* brk = PL_strpbrk(i_Spec, delimiters);
|
||||
if (!brk) // everything is a host
|
||||
{
|
||||
rv = ExtractString((char*)i_Spec, o_Host, len);
|
||||
ToLowerCase(*o_Host);
|
||||
return rv;
|
||||
}
|
||||
|
||||
switch (*brk)
|
||||
{
|
||||
case '/' :
|
||||
case '?' :
|
||||
// Get the Host, the rest is Path
|
||||
rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
ToLowerCase(*o_Host);
|
||||
rv = ParseAtPath(brk, o_Path);
|
||||
return rv;
|
||||
break;
|
||||
case ':' :
|
||||
// Get the Host
|
||||
rv = ExtractString((char*)i_Spec, o_Host, (brk - i_Spec));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
ToLowerCase(*o_Host);
|
||||
rv = ParseAtPort(brk+1, o_Port, o_Path);
|
||||
return rv;
|
||||
break;
|
||||
default:
|
||||
NS_ASSERTION(0, "This just can't be!");
|
||||
break;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParseAtPort(const char* i_Spec, PRInt32 *o_Port,
|
||||
char* *o_Path)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
static const char delimiters[] = "/?"; //this order is optimized.
|
||||
char* brk = PL_strpbrk(i_Spec, delimiters);
|
||||
if (!brk) // everything is a Port
|
||||
{
|
||||
*o_Port = ExtractPortFrom(i_Spec);
|
||||
if (*o_Port <= 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
switch (*brk)
|
||||
{
|
||||
case '/' :
|
||||
case '?' :
|
||||
// Get the Port, the rest is Path
|
||||
*o_Port = ExtractPortFrom(i_Spec);
|
||||
if (*o_Port <= 0)
|
||||
return NS_ERROR_MALFORMED_URI;
|
||||
rv = ParseAtPath(brk, o_Path);
|
||||
return rv;
|
||||
break;
|
||||
default:
|
||||
NS_ASSERTION(0, "This just can't be!");
|
||||
break;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParseAtPath(const char* i_Spec, char* *o_Path)
|
||||
{
|
||||
// Just write the path and check for a starting /
|
||||
nsCAutoString dir;
|
||||
if ('/' != *i_Spec)
|
||||
dir += "/";
|
||||
|
||||
dir += i_Spec;
|
||||
|
||||
*o_Path = dir.ToNewCString();
|
||||
return (*o_Path ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParseAtDirectory(const char* i_Path, char* *o_Directory,
|
||||
char* *o_FileBaseName, char* *o_FileExtension,
|
||||
char* *o_Param, char* *o_Query, char* *o_Ref)
|
||||
{
|
||||
// Cleanout
|
||||
CRTFREEIF(*o_Directory);
|
||||
CRTFREEIF(*o_FileBaseName);
|
||||
CRTFREEIF(*o_FileExtension);
|
||||
CRTFREEIF(*o_Param);
|
||||
CRTFREEIF(*o_Query);
|
||||
CRTFREEIF(*o_Ref);
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
// Parse the Path into its components
|
||||
if (!i_Path)
|
||||
{
|
||||
DupString(o_Directory, "/");
|
||||
return (o_Directory ? NS_OK : NS_ERROR_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
char* dirfile = nsnull;
|
||||
char* options = nsnull;
|
||||
|
||||
int len = PL_strlen(i_Path);
|
||||
|
||||
/* Factor out the optionpart with ;?# */
|
||||
static const char delimiters[] = ";?#"; // for param, query and ref
|
||||
char* brk = PL_strpbrk(i_Path, delimiters);
|
||||
|
||||
if (!brk) // Everything is just path and filename
|
||||
{
|
||||
DupString(&dirfile, i_Path);
|
||||
}
|
||||
else
|
||||
{
|
||||
int dirfileLen = brk - i_Path;
|
||||
ExtractString((char*)i_Path, &dirfile, dirfileLen);
|
||||
len -= dirfileLen;
|
||||
ExtractString((char*)i_Path + dirfileLen, &options, len);
|
||||
brk = options;
|
||||
}
|
||||
|
||||
/* now that we have broken up the path treat every part differently */
|
||||
/* first dir+file */
|
||||
|
||||
char* file;
|
||||
|
||||
int dlen = PL_strlen(dirfile);
|
||||
if (dlen == 0)
|
||||
{
|
||||
DupString(o_Directory, "/");
|
||||
file = dirfile;
|
||||
} else {
|
||||
CoaleseDirs(dirfile);
|
||||
// Get length again
|
||||
dlen = PL_strlen(dirfile);
|
||||
|
||||
// First find the last slash
|
||||
file = PL_strrchr(dirfile, '/');
|
||||
if (!file)
|
||||
{
|
||||
DupString(o_Directory, "/");
|
||||
file = dirfile;
|
||||
}
|
||||
|
||||
// If its not the same as the first slash then extract directory
|
||||
if (file != dirfile)
|
||||
{
|
||||
ExtractString(dirfile, o_Directory, (file - dirfile)+1);
|
||||
} else {
|
||||
DupString(o_Directory, "/");
|
||||
}
|
||||
}
|
||||
|
||||
/* Extract FileBaseName and FileExtension */
|
||||
if (dlen > 0) {
|
||||
// Look again if there was a slash
|
||||
char* slash = PL_strrchr(dirfile, '/');
|
||||
char* e_FileName = nsnull;
|
||||
if (slash) {
|
||||
if (dirfile+dlen-1>slash)
|
||||
ExtractString(slash+1, &e_FileName, dlen-(slash-dirfile+1));
|
||||
} else {
|
||||
// Use the full String as Filename
|
||||
ExtractString(dirfile, &e_FileName, dlen);
|
||||
}
|
||||
|
||||
rv = ParseFileName(e_FileName,o_FileBaseName,o_FileExtension);
|
||||
|
||||
CRTFREEIF(e_FileName);
|
||||
}
|
||||
|
||||
// Now take a look at the options. "#" has precedence over "?"
|
||||
// which has precedence over ";"
|
||||
if (options) {
|
||||
// Look for "#" first. Everything following it is in the ref
|
||||
brk = PL_strchr(options, '#');
|
||||
if (brk) {
|
||||
int pieceLen = len - (brk + 1 - options);
|
||||
ExtractString(brk+1, o_Ref, pieceLen);
|
||||
len -= pieceLen + 1;
|
||||
*brk = '\0';
|
||||
}
|
||||
|
||||
// Now look for "?"
|
||||
brk = PL_strchr(options, '?');
|
||||
if (brk) {
|
||||
int pieceLen = len - (brk + 1 - options);
|
||||
ExtractString(brk+1, o_Query, pieceLen);
|
||||
len -= pieceLen + 1;
|
||||
*brk = '\0';
|
||||
}
|
||||
|
||||
// Now look for ';'
|
||||
brk = PL_strchr(options, ';');
|
||||
if (brk) {
|
||||
int pieceLen = len - (brk + 1 - options);
|
||||
ExtractString(brk+1, o_Param, pieceLen);
|
||||
len -= pieceLen + 1;
|
||||
*brk = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
nsCRT::free(dirfile);
|
||||
nsCRT::free(options);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParsePreHost(const char* i_PreHost, char* *o_Username,
|
||||
char* *o_Password)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!i_PreHost) {
|
||||
*o_Username = nsnull;
|
||||
*o_Password = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Search for :
|
||||
static const char delimiters[] = ":";
|
||||
char* brk = PL_strpbrk(i_PreHost, delimiters);
|
||||
if (brk)
|
||||
{
|
||||
rv = ExtractString((char*)i_PreHost, o_Username, (brk - i_PreHost));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = ExtractString(brk+1, o_Password,
|
||||
(i_PreHost+PL_strlen(i_PreHost) - brk - 1));
|
||||
} else {
|
||||
CRTFREEIF(*o_Password);
|
||||
rv = DupString(o_Username, i_PreHost);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsAuthURLParser::ParseFileName(const char* i_FileName, char* *o_FileBaseName,
|
||||
char* *o_FileExtension)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!i_FileName) {
|
||||
*o_FileBaseName = nsnull;
|
||||
*o_FileExtension = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// Search for FileExtension
|
||||
// Search for last .
|
||||
// Ignore . at the beginning
|
||||
char* brk = PL_strrchr(i_FileName+1, '.');
|
||||
if (brk)
|
||||
{
|
||||
rv = ExtractString((char*)i_FileName, o_FileBaseName,
|
||||
(brk - i_FileName));
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
rv = ExtractString(brk + 1, o_FileExtension,
|
||||
(i_FileName+PL_strlen(i_FileName) - brk - 1));
|
||||
} else {
|
||||
rv = DupString(o_FileBaseName, i_FileName);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
51
mozilla/netwerk/base/src/nsAuthURLParser.h
Normal file
51
mozilla/netwerk/base/src/nsAuthURLParser.h
Normal file
@@ -0,0 +1,51 @@
|
||||
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public
|
||||
* License Version 1.1 (the "License"); you may not use this file
|
||||
* except in compliance with the License. You may obtain a copy of
|
||||
* the License at http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
*/
|
||||
|
||||
#ifndef nsAuthURLParser_h__
|
||||
#define nsAuthURLParser_h__
|
||||
|
||||
#include "nsIURLParser.h"
|
||||
#include "nsIURI.h"
|
||||
#include "nsAgg.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
class nsAuthURLParser : public nsIURLParser
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// nsAuthURLParser methods:
|
||||
nsAuthURLParser() {
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
virtual ~nsAuthURLParser();
|
||||
|
||||
static NS_METHOD
|
||||
Create(nsISupports *aOuter, REFNSIID aIID, void **aResult);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// nsIURLParser methods:
|
||||
NS_DECL_NSIURLPARSER
|
||||
|
||||
};
|
||||
|
||||
#endif // nsAuthURLParser_h__
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user