2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-12-21 00:48:15 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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/
|
1999-12-21 00:48:15 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* 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.
|
1999-12-21 00:48:15 +03:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-12-21 00:48:15 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-12-21 00:48:15 +03:00
|
|
|
|
|
|
|
// datetime implementation
|
|
|
|
|
|
|
|
#include "nsDateTimeChannel.h"
|
2001-06-06 04:10:09 +04:00
|
|
|
#include "nsNetUtil.h"
|
1999-12-21 00:48:15 +03:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsILoadGroup.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
1999-12-21 00:48:15 +03:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsISocketTransportService.h"
|
2001-02-21 23:38:08 +03:00
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsIProgressEventSink.h"
|
1999-12-21 00:48:15 +03:00
|
|
|
|
|
|
|
// nsDateTimeChannel methods
|
|
|
|
nsDateTimeChannel::nsDateTimeChannel() {
|
|
|
|
mContentLength = -1;
|
|
|
|
mPort = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsDateTimeChannel::~nsDateTimeChannel() {
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMPL_ISUPPORTS4(nsDateTimeChannel,
|
|
|
|
nsIChannel,
|
|
|
|
nsIRequest,
|
|
|
|
nsIStreamListener,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsIRequestObserver)
|
1999-12-21 00:48:15 +03:00
|
|
|
|
|
|
|
nsresult
|
2001-09-13 06:21:05 +04:00
|
|
|
nsDateTimeChannel::Init(nsIURI* uri, nsIProxyInfo* proxyInfo)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2000-01-12 01:16:19 +03:00
|
|
|
NS_ASSERTION(uri, "no uri");
|
|
|
|
|
1999-12-21 22:40:05 +03:00
|
|
|
mUrl = uri;
|
2001-09-13 06:21:05 +04:00
|
|
|
mProxyInfo = proxyInfo;
|
1999-12-21 22:40:05 +03:00
|
|
|
|
2000-01-12 01:16:19 +03:00
|
|
|
rv = mUrl->GetPort(&mPort);
|
|
|
|
if (NS_FAILED(rv) || mPort < 1)
|
|
|
|
mPort = DATETIME_PORT;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = mUrl->GetPath(mHost);
|
2000-01-12 01:16:19 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
1999-12-21 00:48:15 +03:00
|
|
|
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:
|
|
|
|
|
2000-08-21 12:23:54 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsDateTimeChannel::GetName(nsACString &result)
|
2000-08-21 12:23:54 +04:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-12-21 00:48:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::IsPending(PRBool *result)
|
|
|
|
{
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_NOTREACHED("nsDateTimeChannel::IsPending");
|
1999-12-21 00:48:15 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 07:58:50 +04:00
|
|
|
nsDateTimeChannel::GetStatus(nsresult *status)
|
|
|
|
{
|
|
|
|
*status = NS_OK;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::Cancel(nsresult status)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
2000-04-12 11:58:24 +04:00
|
|
|
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_NOTREACHED("nsDateTimeChannel::Cancel");
|
1999-12-21 00:48:15 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::Suspend(void)
|
|
|
|
{
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_NOTREACHED("nsDateTimeChannel::Suspend");
|
1999-12-21 00:48:15 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::Resume(void)
|
|
|
|
{
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_NOTREACHED("nsDateTimeChannel::Resume");
|
1999-12-21 00:48:15 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIChannel methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 07:58:50 +04:00
|
|
|
nsDateTimeChannel::GetOriginalURI(nsIURI* *aURI)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
2000-03-29 07:58:50 +04:00
|
|
|
*aURI = mOriginalURI ? mOriginalURI : mUrl;
|
1999-12-21 00:48:15 +03:00
|
|
|
NS_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 07:58:50 +04:00
|
|
|
nsDateTimeChannel::SetOriginalURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
mOriginalURI = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::GetURI(nsIURI* *aURI)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
|
|
|
*aURI = mUrl;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsDateTimeChannel::Open(nsIInputStream **_retval)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2001-06-06 04:10:09 +04:00
|
|
|
rv = NS_CheckPortSafety(mPort, "datetime");
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-12-21 00:48:15 +03:00
|
|
|
|
2001-09-13 06:21:05 +04:00
|
|
|
nsCOMPtr<nsISocketTransportService> sts =
|
|
|
|
do_GetService("@mozilla.org/network/socket-transport-service;1", &rv);
|
1999-12-21 00:48:15 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsCOMPtr<nsITransport> transport;
|
2001-09-13 06:21:05 +04:00
|
|
|
rv = sts->CreateTransport(mHost,
|
|
|
|
mPort,
|
|
|
|
mProxyInfo,
|
|
|
|
32,
|
|
|
|
32,
|
|
|
|
getter_AddRefs(transport));
|
1999-12-21 00:48:15 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
transport->SetNotificationCallbacks(mCallbacks,
|
2001-04-10 10:01:08 +04:00
|
|
|
(mLoadFlags & LOAD_BACKGROUND));
|
1999-12-21 22:40:05 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
return transport->OpenInputStream(0, PRUint32(-1), 0, _retval);
|
1999-12-21 00:48:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsDateTimeChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
2001-06-06 04:10:09 +04:00
|
|
|
rv = NS_CheckPortSafety(mPort, "datetime");
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
1999-12-21 00:48:15 +03:00
|
|
|
|
2001-09-13 06:21:05 +04:00
|
|
|
nsCOMPtr<nsISocketTransportService> sts =
|
|
|
|
do_GetService("@mozilla.org/network/socket-transport-service;1", &rv);
|
1999-12-21 00:48:15 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
nsCOMPtr<nsITransport> transport;
|
2001-09-13 06:21:05 +04:00
|
|
|
rv = sts->CreateTransport(mHost,
|
|
|
|
mPort,
|
|
|
|
mProxyInfo,
|
|
|
|
32,
|
|
|
|
32,
|
|
|
|
getter_AddRefs(transport));
|
1999-12-21 00:48:15 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-03-06 08:10:33 +03:00
|
|
|
transport->SetNotificationCallbacks(mCallbacks,
|
2001-04-10 10:01:08 +04:00
|
|
|
(mLoadFlags & LOAD_BACKGROUND));
|
1999-12-21 22:40:05 +03:00
|
|
|
|
1999-12-21 00:48:15 +03:00
|
|
|
mListener = aListener;
|
2001-02-21 23:38:08 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsIRequest> request;
|
2002-03-06 10:48:55 +03:00
|
|
|
return transport->AsyncRead(this, ctxt, 0, PRUint32(-1), 0, getter_AddRefs(request));
|
1999-12-21 00:48:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-10 10:01:08 +04:00
|
|
|
nsDateTimeChannel::GetLoadFlags(PRUint32 *aLoadFlags)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
2001-04-10 10:01:08 +04:00
|
|
|
*aLoadFlags = mLoadFlags;
|
1999-12-21 00:48:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-10 10:01:08 +04:00
|
|
|
nsDateTimeChannel::SetLoadFlags(PRUint32 aLoadFlags)
|
1999-12-21 00:48:15 +03:00
|
|
|
{
|
2001-04-10 10:01:08 +04:00
|
|
|
mLoadFlags = aLoadFlags;
|
1999-12-21 00:48:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define DATETIME_TYPE "text/plain"
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsDateTimeChannel::GetContentType(nsACString &aContentType)
|
|
|
|
{
|
|
|
|
aContentType = NS_LITERAL_CSTRING(DATETIME_TYPE);
|
1999-12-21 00:48:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-01-08 09:26:04 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsDateTimeChannel::SetContentType(const nsACString &aContentType)
|
2000-01-08 09:26:04 +03:00
|
|
|
{
|
2002-03-21 01:50:33 +03:00
|
|
|
// It doesn't make sense to set the content-type on this type
|
2000-01-08 09:26:04 +03:00
|
|
|
// of channel...
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
aContentCharset.Truncate();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::SetContentCharset(const nsACString &aContentCharset)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsDateTimeChannel::SetContentCharset");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-12-21 00:48:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::GetContentLength(PRInt32 *aContentLength)
|
|
|
|
{
|
|
|
|
*aContentLength = mContentLength;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::SetContentLength(PRInt32 aContentLength)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsDateTimeChannel::SetContentLength");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
1999-12-21 00:48:15 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
|
|
|
{
|
|
|
|
*aLoadGroup = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
1999-12-21 22:40:05 +03:00
|
|
|
if (mLoadGroup) // if we already had a load group remove ourselves...
|
2001-04-10 10:01:08 +04:00
|
|
|
(void)mLoadGroup->RemoveRequest(this, nsnull, NS_OK);
|
1999-12-21 22:40:05 +03:00
|
|
|
|
1999-12-21 00:48:15 +03:00
|
|
|
mLoadGroup = aLoadGroup;
|
1999-12-21 22:40:05 +03:00
|
|
|
if (mLoadGroup) {
|
2001-02-21 23:38:08 +03:00
|
|
|
return mLoadGroup->AddRequest(this, nsnull);
|
1999-12-21 22:40:05 +03:00
|
|
|
}
|
1999-12-21 00:48:15 +03:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsDateTimeChannel::GetSecurityInfo(nsISupports **sec)
|
2000-03-18 01:06:32 +03:00
|
|
|
{
|
2001-02-21 23:38:08 +03:00
|
|
|
NS_ENSURE_ARG_POINTER(sec);
|
|
|
|
*sec = nsnull;
|
2000-03-18 01:06:32 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-12-21 00:48:15 +03:00
|
|
|
|
2001-04-10 10:01:08 +04:00
|
|
|
// nsIRequestObserver methods
|
1999-12-21 00:48:15 +03:00
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsDateTimeChannel::OnStartRequest(nsIRequest *request, nsISupports *aContext) {
|
1999-12-21 00:48:15 +03:00
|
|
|
return mListener->OnStartRequest(this, aContext);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsDateTimeChannel::OnStopRequest(nsIRequest *request, nsISupports* aContext,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus) {
|
1999-12-21 22:40:05 +03:00
|
|
|
if (mLoadGroup) {
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult rv = mLoadGroup->RemoveRequest(this, nsnull, aStatus);
|
1999-12-21 22:40:05 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2001-04-10 10:01:08 +04:00
|
|
|
return mListener->OnStopRequest(this, aContext, aStatus);
|
1999-12-21 00:48:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// nsIStreamListener method
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
nsDateTimeChannel::OnDataAvailable(nsIRequest *request, nsISupports* aContext,
|
1999-12-21 00:48:15 +03:00
|
|
|
nsIInputStream *aInputStream, PRUint32 aSourceOffset,
|
|
|
|
PRUint32 aLength) {
|
|
|
|
mContentLength = aLength;
|
|
|
|
return mListener->OnDataAvailable(this, aContext, aInputStream, aSourceOffset, aLength);
|
|
|
|
}
|