2000-02-02 22:48:55 +00:00
|
|
|
/* -*- 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"
|
2000-02-23 06:53:46 +00:00
|
|
|
#include "nsMimeTypes.h"
|
2000-04-11 22:41:02 +00:00
|
|
|
#include "nsIStreamConverterService.h"
|
|
|
|
#include "nsITXTToHTMLConv.h"
|
2000-02-02 22:48:55 +00:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
2000-04-11 22:41:02 +00:00
|
|
|
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
2000-02-02 22:48:55 +00:00
|
|
|
|
|
|
|
#define BUFFER_SEG_SIZE (4*1024)
|
|
|
|
#define BUFFER_MAX_SIZE (64*1024)
|
|
|
|
|
|
|
|
// nsFingerChannel methods
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::nsFingerChannel()
|
|
|
|
: mContentLength(-1),
|
|
|
|
mActAsObserver(PR_TRUE),
|
|
|
|
mPort(-1),
|
|
|
|
mStatus(NS_OK)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
|
|
|
NS_INIT_REFCNT();
|
|
|
|
}
|
|
|
|
|
|
|
|
nsFingerChannel::~nsFingerChannel() {
|
|
|
|
}
|
|
|
|
|
2000-03-22 21:15:57 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS4(nsFingerChannel, nsIChannel, nsIRequest,
|
|
|
|
nsIStreamListener, nsIStreamObserver)
|
2000-02-02 22:48:55 +00:00
|
|
|
|
|
|
|
nsresult
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::Init(nsIURI* uri)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsXPIDLCString autoBuffer;
|
|
|
|
|
|
|
|
NS_ASSERTION(uri, "no uri");
|
|
|
|
|
|
|
|
mUrl = uri;
|
|
|
|
|
2000-03-23 06:40:36 +00:00
|
|
|
// For security reasons, we do not allow the user to specify a
|
|
|
|
// non-default port for finger: URL's.
|
|
|
|
|
|
|
|
mPort = FINGER_PORT;
|
2000-02-02 22:48:55 +00:00
|
|
|
|
|
|
|
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,
|
2000-03-29 03:58:50 +00:00
|
|
|
(const char*)mHost);
|
2000-02-02 22:48:55 +00:00
|
|
|
#endif
|
|
|
|
if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
|
|
|
|
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)
|
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsFingerChannel::IsPending");
|
2000-02-02 22:48:55 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::GetStatus(nsresult *status)
|
|
|
|
{
|
|
|
|
*status = mStatus;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::Cancel(nsresult status)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
2000-04-12 07:58:24 +00:00
|
|
|
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
|
2000-03-22 21:15:57 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
mStatus = status;
|
2000-03-22 21:15:57 +00:00
|
|
|
if (mTransport) {
|
2000-03-29 03:58:50 +00:00
|
|
|
rv = mTransport->Cancel(status);
|
2000-03-22 21:15:57 +00:00
|
|
|
}
|
|
|
|
return rv;
|
2000-02-02 22:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::Suspend(void)
|
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsFingerChannel::Suspend");
|
2000-02-02 22:48:55 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::Resume(void)
|
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsFingerChannel::Resume");
|
2000-02-02 22:48:55 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIChannel methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::GetOriginalURI(nsIURI* *aURI)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
*aURI = mOriginalURI ? mOriginalURI : mUrl;
|
2000-02-02 22:48:55 +00:00
|
|
|
NS_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::SetOriginalURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
mOriginalURI = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetURI(nsIURI* *aURI)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
|
|
|
*aURI = mUrl;
|
|
|
|
NS_IF_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::SetURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
mUrl = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::OpenInputStream(nsIInputStream **_retval)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2000-05-20 00:19:24 +00:00
|
|
|
rv = socketService->CreateTransport(mHost, mPort, nsnull, -1, BUFFER_SEG_SIZE,
|
2000-02-02 22:48:55 +00:00
|
|
|
BUFFER_MAX_SIZE, getter_AddRefs(channel));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = channel->SetNotificationCallbacks(mCallbacks);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
return channel->OpenInputStream(_retval);
|
2000-02-02 22:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::OpenOutputStream(nsIOutputStream **_retval)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsFingerChannel::OpenOutputStream");
|
2000-02-02 22:48:55 +00:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 03:58:50 +00:00
|
|
|
nsFingerChannel::AsyncRead(nsIStreamListener *aListener, nsISupports *ctxt)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel;
|
2000-05-20 00:19:24 +00:00
|
|
|
rv = socketService->CreateTransport(mHost, mPort, nsnull, -1, BUFFER_SEG_SIZE,
|
2000-02-02 22:48:55 +00:00
|
|
|
BUFFER_MAX_SIZE, getter_AddRefs(channel));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = channel->SetNotificationCallbacks(mCallbacks);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
mListener = aListener;
|
2000-03-22 21:15:57 +00:00
|
|
|
mResponseContext = ctxt;
|
|
|
|
mTransport = channel;
|
2000-02-02 22:48:55 +00:00
|
|
|
|
|
|
|
return SendRequest(channel);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::AsyncWrite(nsIInputStream *fromStream,
|
2000-03-29 03:58:50 +00:00
|
|
|
nsIStreamObserver *observer,
|
|
|
|
nsISupports *ctxt)
|
2000-02-02 22:48:55 +00:00
|
|
|
{
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_NOTREACHED("nsFingerChannel::AsyncWrite");
|
2000-02-02 22:48:55 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-04-11 22:41:02 +00:00
|
|
|
#define FINGER_TYPE TEXT_HTML
|
2000-02-02 22:48:55 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetContentLength(PRInt32 aContentLength)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::SetContentLength");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetTransferOffset(PRUint32 *aTransferOffset)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::GetTransferOffset");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetTransferOffset(PRUint32 aTransferOffset)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::SetTransferOffset");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetTransferCount(PRInt32 *aTransferCount)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::GetTransferCount");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetTransferCount(PRInt32 aTransferCount)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::SetTransferCount");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetBufferSegmentSize(PRUint32 *aBufferSegmentSize)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::GetBufferSegmentSize");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetBufferSegmentSize(PRUint32 aBufferSegmentSize)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::SetBufferSegmentSize");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetBufferMaxSize(PRUint32 *aBufferMaxSize)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::GetBufferMaxSize");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetBufferMaxSize(PRUint32 aBufferMaxSize)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::SetBufferMaxSize");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-06-02 23:39:45 +00:00
|
|
|
nsFingerChannel::GetLocalFile(nsIFile* *file)
|
2000-03-29 03:58:50 +00:00
|
|
|
{
|
2000-06-02 23:39:45 +00:00
|
|
|
*file = nsnull;
|
2000-03-29 03:58:50 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetPipeliningAllowed(PRBool *aPipeliningAllowed)
|
|
|
|
{
|
|
|
|
*aPipeliningAllowed = PR_FALSE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetPipeliningAllowed(PRBool aPipeliningAllowed)
|
|
|
|
{
|
|
|
|
NS_NOTREACHED("SetPipeliningAllowed");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2000-02-02 22:48:55 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetLoadGroup(nsILoadGroup* *aLoadGroup)
|
|
|
|
{
|
|
|
|
*aLoadGroup = mLoadGroup;
|
|
|
|
NS_IF_ADDREF(*aLoadGroup);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetLoadGroup(nsILoadGroup* aLoadGroup)
|
|
|
|
{
|
|
|
|
mLoadGroup = aLoadGroup;
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2000-03-17 22:06:32 +00:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetSecurityInfo(nsISupports * *aSecurityInfo)
|
|
|
|
{
|
|
|
|
*aSecurityInfo = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-02 22:48:55 +00:00
|
|
|
|
|
|
|
// 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,
|
2000-07-25 05:45:56 +00:00
|
|
|
nsresult aStatus, const PRUnichar* aStatusArg)
|
|
|
|
{
|
2000-02-02 22:48:55 +00:00
|
|
|
#ifdef DEBUG_bryner
|
|
|
|
printf("nsFingerChannel::OnStopRequest, mActAsObserver=%d\n",
|
|
|
|
mActAsObserver);
|
|
|
|
printf(" aChannel = %p\n", aChannel);
|
|
|
|
#endif
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2000-03-22 21:15:57 +00:00
|
|
|
if (NS_FAILED(aStatus) || !mActAsObserver) {
|
2000-02-02 22:48:55 +00:00
|
|
|
if (mLoadGroup) {
|
2000-07-25 05:45:56 +00:00
|
|
|
rv = mLoadGroup->RemoveChannel(this, nsnull, aStatus, aStatusArg);
|
2000-02-02 22:48:55 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2000-07-25 05:45:56 +00:00
|
|
|
rv = mListener->OnStopRequest(this, aContext, aStatus, aStatusArg);
|
2000-03-22 21:15:57 +00:00
|
|
|
mTransport = 0;
|
|
|
|
return rv;
|
2000-02-02 22:48:55 +00:00
|
|
|
} else {
|
|
|
|
// at this point we know the request has been sent.
|
|
|
|
// we're no longer acting as an observer.
|
|
|
|
|
|
|
|
mActAsObserver = PR_FALSE;
|
2000-04-11 22:41:02 +00:00
|
|
|
nsCOMPtr<nsIStreamListener> converterListener;
|
|
|
|
|
|
|
|
NS_WITH_SERVICE(nsIStreamConverterService, StreamConvService,
|
|
|
|
kStreamConverterServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsAutoString fromStr; fromStr.AssignWithConversion("text/plain");
|
|
|
|
nsAutoString toStr; toStr.AssignWithConversion("text/html");
|
|
|
|
|
|
|
|
rv = StreamConvService->AsyncConvertData(fromStr.GetUnicode(),
|
|
|
|
toStr.GetUnicode(), this, mResponseContext,
|
|
|
|
getter_AddRefs(converterListener));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsITXTToHTMLConv> converter(do_QueryInterface(converterListener));
|
|
|
|
if (converter) {
|
2000-04-18 02:40:23 +00:00
|
|
|
nsAutoString title; title.AssignWithConversion("Finger information for ");
|
|
|
|
nsXPIDLCString userHost;
|
|
|
|
rv = mUrl->GetPath(getter_Copies(userHost));
|
2000-04-18 23:53:10 +00:00
|
|
|
title.AppendWithConversion(userHost);
|
2000-04-11 22:41:02 +00:00
|
|
|
converter->SetTitle(title.GetUnicode());
|
|
|
|
converter->PreFormatHTML(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return aChannel->AsyncRead(converterListener, mResponseContext);
|
2000-02-02 22:48:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// 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);
|
|
|
|
|
2000-03-22 21:15:57 +00:00
|
|
|
if (mLoadGroup) {
|
|
|
|
mLoadGroup->AddChannel(this, nsnull);
|
|
|
|
}
|
|
|
|
|
2000-02-02 22:48:55 +00:00
|
|
|
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
|
|
|
|
|
2000-03-29 03:58:50 +00:00
|
|
|
rv = aChannel->SetTransferCount(requestBuffer.Length());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
rv = aChannel->AsyncWrite(charstream, this, 0);
|
2000-02-02 22:48:55 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
|