2000-02-03 01:48:55 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
2000-09-08 01:26:29 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public
|
2000-02-03 01:48:55 +03:00
|
|
|
* License Version 1.1 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
2000-09-08 01:26:29 +04:00
|
|
|
* the License at http://www.mozilla.org/MPL/
|
2000-02-03 01:48:55 +03: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.
|
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2000-09-08 01:26:29 +04:00
|
|
|
* The Initial Developer of the Original Code is Brian Ryner.
|
|
|
|
* Portions created by Brian Ryner are Copyright (C) 2000 Brian Ryner.
|
|
|
|
* All Rights Reserved.
|
2000-02-03 01:48:55 +03:00
|
|
|
*
|
|
|
|
* Contributor(s):
|
2003-01-18 05:15:14 +03:00
|
|
|
* Brian Ryner <bryner@uiuc.edu>
|
|
|
|
* Darin Fisher <darin@netscape.com>
|
2000-02-03 01:48:55 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
// finger implementation
|
|
|
|
|
|
|
|
#include "nsFingerChannel.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsILoadGroup.h"
|
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
2000-02-03 01:48:55 +03:00
|
|
|
#include "nsXPIDLString.h"
|
|
|
|
#include "nsISocketTransportService.h"
|
|
|
|
#include "nsIStringStream.h"
|
2000-02-23 09:53:46 +03:00
|
|
|
#include "nsMimeTypes.h"
|
2000-04-12 02:41:02 +04:00
|
|
|
#include "nsIStreamConverterService.h"
|
|
|
|
#include "nsITXTToHTMLConv.h"
|
2001-02-21 23:38:08 +03:00
|
|
|
#include "nsIProgressEventSink.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "nsEventQueueUtils.h"
|
2001-01-24 01:10:34 +03:00
|
|
|
#include "nsNetUtil.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2000-02-03 01:48:55 +03:00
|
|
|
|
|
|
|
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
2000-04-12 02:41:02 +04:00
|
|
|
static NS_DEFINE_CID(kStreamConverterServiceCID, NS_STREAMCONVERTERSERVICE_CID);
|
2000-02-03 01:48:55 +03:00
|
|
|
|
|
|
|
#define BUFFER_SEG_SIZE (4*1024)
|
|
|
|
#define BUFFER_MAX_SIZE (64*1024)
|
|
|
|
|
|
|
|
// nsFingerChannel methods
|
2000-03-29 07:58:50 +04:00
|
|
|
nsFingerChannel::nsFingerChannel()
|
2003-01-18 05:15:14 +03:00
|
|
|
: mLoadFlags(LOAD_NORMAL)
|
|
|
|
, mStatus(NS_OK)
|
|
|
|
, mPort(-1)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::~nsFingerChannel()
|
|
|
|
{
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMPL_ISUPPORTS4(nsFingerChannel,
|
|
|
|
nsIChannel,
|
|
|
|
nsIRequest,
|
|
|
|
nsIStreamListener,
|
|
|
|
nsIRequestObserver)
|
2000-02-03 01:48:55 +03:00
|
|
|
|
|
|
|
nsresult
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::Init(nsIURI *uri, nsIProxyInfo *proxyInfo)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
2002-03-06 10:48:55 +03:00
|
|
|
nsCAutoString autoBuffer;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
|
|
|
NS_ASSERTION(uri, "no uri");
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
mURI = uri;
|
2001-09-13 06:21:05 +04:00
|
|
|
mProxyInfo = proxyInfo;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2000-03-23 09:40:36 +03: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-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
rv = mURI->GetPath(autoBuffer); // autoBuffer = user@host
|
2000-02-03 01:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// Now parse out the user and host
|
2001-03-14 05:51:01 +03:00
|
|
|
const char* buf = autoBuffer.get();
|
2002-03-06 10:48:55 +03:00
|
|
|
const char* pos = strchr(buf, '@');
|
2000-02-03 01:48:55 +03:00
|
|
|
|
|
|
|
// Catch the case of just the host being given
|
2001-03-14 05:51:01 +03:00
|
|
|
if (!pos) {
|
2003-01-18 05:15:14 +03:00
|
|
|
mUser.Truncate();
|
2001-03-14 05:51:01 +03:00
|
|
|
mHost.Assign(buf);
|
|
|
|
} else {
|
2003-01-18 05:15:14 +03:00
|
|
|
mUser.Assign(buf, pos-buf);
|
2001-03-14 05:51:01 +03:00
|
|
|
mHost.Assign(pos+1); // ignore '@'
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mHost.IsEmpty())
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
mContentType = NS_LITERAL_CSTRING(TEXT_HTML); // expected content-type
|
2000-02-03 01:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIRequest methods:
|
|
|
|
|
2000-08-21 12:23:54 +04:00
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsFingerChannel::GetName(nsACString &result)
|
2000-08-21 12:23:54 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
return mURI->GetSpec(result);
|
2000-08-21 12:23:54 +04:00
|
|
|
}
|
|
|
|
|
2000-02-03 01:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::IsPending(PRBool *result)
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
*result = (mPump != nsnull);
|
|
|
|
return NS_OK;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 07:58:50 +04:00
|
|
|
nsFingerChannel::GetStatus(nsresult *status)
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_SUCCEEDED(mStatus) && mPump)
|
|
|
|
mPump->GetStatus(status);
|
|
|
|
else
|
|
|
|
*status = mStatus;
|
2000-03-29 07:58:50 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::Cancel(nsresult status)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2000-04-12 11:58:24 +04:00
|
|
|
NS_ASSERTION(NS_FAILED(status), "shouldn't cancel with a success code");
|
2000-03-23 00:15:57 +03:00
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
mStatus = status;
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mPump)
|
|
|
|
mPump->Cancel(status);
|
|
|
|
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::Suspend()
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mPump)
|
|
|
|
mPump->Suspend();
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::Resume()
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mPump)
|
|
|
|
mPump->Resume();
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsIChannel methods:
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 07:58:50 +04:00
|
|
|
nsFingerChannel::GetOriginalURI(nsIURI* *aURI)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
*aURI = mOriginalURI ? mOriginalURI : mURI;
|
2000-02-03 01:48:55 +03:00
|
|
|
NS_ADDREF(*aURI);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-03-29 07:58:50 +04:00
|
|
|
nsFingerChannel::SetOriginalURI(nsIURI* aURI)
|
|
|
|
{
|
|
|
|
mOriginalURI = aURI;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetURI(nsIURI* *aURI)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
*aURI = mURI;
|
2000-02-03 01:48:55 +03:00
|
|
|
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
|
|
|
nsFingerChannel::Open(nsIInputStream **_retval)
|
2003-01-18 05:15:14 +03:00
|
|
|
{
|
|
|
|
NS_NOTREACHED("nsFingerChannel::Open");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::AsyncOpen(nsIStreamListener *aListener, nsISupports *ctxt)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
2001-06-06 04:10:09 +04:00
|
|
|
rv = NS_CheckPortSafety(mPort, "finger");
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2001-06-06 04:10:09 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIEventQueue> eventQ;
|
|
|
|
rv = NS_GetCurrentEventQ(getter_AddRefs(eventQ));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
//
|
|
|
|
// create transport
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsISocketTransportService> sts =
|
2001-07-25 11:54:28 +04:00
|
|
|
do_GetService(kSocketTransportServiceCID, &rv);
|
2000-02-03 01:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
rv = sts->CreateTransport(nsnull, 0, mHost, mPort, mProxyInfo,
|
|
|
|
getter_AddRefs(mTransport));
|
2000-02-03 01:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
// not fatal if these fail
|
|
|
|
mTransport->SetSecurityCallbacks(mCallbacks);
|
|
|
|
mTransport->SetEventSink(this, eventQ);
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
rv = WriteRequest(mTransport);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//
|
|
|
|
// create TXT to HTML stream converter
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIStreamConverterService> scs =
|
|
|
|
do_GetService(kStreamConverterServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_NAMED_LITERAL_STRING(fromStr, "text/plain");
|
|
|
|
NS_NAMED_LITERAL_STRING(toStr, "text/html");
|
2001-06-06 04:10:09 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIStreamListener> convListener;
|
|
|
|
rv = scs->AsyncConvertData(fromStr.get(), toStr.get(), this, nsnull,
|
|
|
|
getter_AddRefs(convListener));
|
2000-02-03 01:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsITXTToHTMLConv> conv = do_QueryInterface(convListener);
|
|
|
|
if (conv) {
|
|
|
|
nsCAutoString userHost;
|
|
|
|
rv = mURI->GetPath(userHost);
|
|
|
|
|
|
|
|
nsAutoString title;
|
|
|
|
title = NS_LITERAL_STRING("Finger information for ")
|
|
|
|
+ NS_ConvertUTF8toUCS2(userHost);
|
|
|
|
|
|
|
|
conv->SetTitle(title.get());
|
|
|
|
conv->PreFormatHTML(PR_TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// open input stream, and create input stream pump...
|
|
|
|
//
|
|
|
|
nsCOMPtr<nsIInputStream> sockIn;
|
|
|
|
rv = mTransport->OpenInputStream(0, 0, 0, getter_AddRefs(sockIn));
|
2000-02-03 01:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
rv = NS_NewInputStreamPump(getter_AddRefs(mPump), sockIn);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
rv = mPump->AsyncRead(convListener, nsnull);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->AddRequest(this, nsnull);
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
mListener = aListener;
|
|
|
|
mListenerContext = ctxt;
|
|
|
|
return NS_OK;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-10 10:01:08 +04:00
|
|
|
nsFingerChannel::GetLoadFlags(PRUint32 *aLoadFlags)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2001-04-10 10:01:08 +04:00
|
|
|
*aLoadFlags = mLoadFlags;
|
2000-02-03 01:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-04-10 10:01:08 +04:00
|
|
|
nsFingerChannel::SetLoadFlags(PRUint32 aLoadFlags)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2001-04-10 10:01:08 +04:00
|
|
|
mLoadFlags = aLoadFlags;
|
2000-02-03 01:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsFingerChannel::GetContentType(nsACString &aContentType)
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
aContentType = mContentType;
|
2000-02-03 01:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
nsFingerChannel::SetContentType(const nsACString &aContentType)
|
2000-02-03 01:48:55 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
mContentType = aContentType;
|
|
|
|
return NS_OK;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetContentCharset(nsACString &aContentCharset)
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
aContentCharset = mContentCharset;
|
2002-03-21 01:50:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetContentCharset(const nsACString &aContentCharset)
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
mContentCharset = aContentCharset;
|
|
|
|
return NS_OK;
|
2002-03-21 01:50:33 +03:00
|
|
|
}
|
|
|
|
|
2000-02-03 01:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::GetContentLength(PRInt32 *aContentLength)
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
*aContentLength = -1;
|
2000-02-03 01:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-29 07:58:50 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::SetContentLength(PRInt32 aContentLength)
|
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
// silently ignore this...
|
|
|
|
return NS_OK;
|
2000-03-29 07:58:50 +04:00
|
|
|
}
|
|
|
|
|
2000-02-03 01:48:55 +03: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;
|
2003-01-18 05:15:14 +03:00
|
|
|
mProgressSink = do_GetInterface(mCallbacks);
|
2000-02-03 01:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2000-03-18 01:06:32 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::GetSecurityInfo(nsISupports **aSecurityInfo)
|
2000-03-18 01:06:32 +03:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mTransport)
|
|
|
|
return mTransport->GetSecurityInfo(aSecurityInfo);
|
|
|
|
|
2000-03-18 01:06:32 +03:00
|
|
|
*aSecurityInfo = nsnull;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
2001-04-10 10:01:08 +04:00
|
|
|
// nsIRequestObserver methods
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
2000-02-03 01:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::OnStartRequest(nsIRequest *req, nsISupports *ctx)
|
|
|
|
{
|
|
|
|
return mListener->OnStartRequest(this, mListenerContext);
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::OnStopRequest(nsIRequest *req, nsISupports *ctx, nsresult status)
|
2000-07-25 09:45:56 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
if (NS_SUCCEEDED(mStatus))
|
|
|
|
mStatus = status;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
mListener->OnStopRequest(this, mListenerContext, mStatus);
|
|
|
|
mListener = 0;
|
|
|
|
mListenerContext = 0;
|
2000-04-12 02:41:02 +04:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
if (mLoadGroup)
|
|
|
|
mLoadGroup->RemoveRequest(this, nsnull, mStatus);
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
mPump = 0;
|
|
|
|
mTransport = 0;
|
|
|
|
return NS_OK;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-01-18 05:15:14 +03:00
|
|
|
nsFingerChannel::OnDataAvailable(nsIRequest *req, nsISupports *ctx,
|
|
|
|
nsIInputStream *stream, PRUint32 offset,
|
|
|
|
PRUint32 count)
|
|
|
|
{
|
|
|
|
return mListener->OnDataAvailable(this, mListenerContext, stream, offset, count);
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// nsITransportEventSink methods
|
|
|
|
//-----------------------------------------------------------------------------
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsFingerChannel::OnTransportStatus(nsITransport *trans, nsresult status,
|
|
|
|
PRUint32 progress, PRUint32 progressMax)
|
|
|
|
{
|
|
|
|
// suppress status notification if channel is no longer pending!
|
|
|
|
if (mProgressSink && mPump && !(mLoadFlags & LOAD_BACKGROUND)) {
|
|
|
|
NS_ConvertUTF8toUCS2 host(mHost);
|
|
|
|
mProgressSink->OnStatus(this, nsnull, status, host.get());
|
|
|
|
|
|
|
|
if (status == nsISocketTransport::STATUS_RECEIVING_FROM ||
|
|
|
|
status == nsISocketTransport::STATUS_SENDING_TO) {
|
|
|
|
mProgressSink->OnProgress(this, nsnull, progress, progressMax);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
//-----------------------------------------------------------------------------
|
2000-03-23 00:15:57 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsresult
|
|
|
|
nsFingerChannel::WriteRequest(nsITransport *trans)
|
|
|
|
{
|
|
|
|
// The text to send should already be in mUser
|
|
|
|
nsresult rv;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCAutoString requestBuf;
|
|
|
|
requestBuf = mUser + NS_LITERAL_CSTRING("\r\n");
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
nsCOMPtr<nsIOutputStream> stream;
|
|
|
|
rv = trans->OpenOutputStream(0, requestBuf.Length(), 1, getter_AddRefs(stream));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
PRUint32 n;
|
|
|
|
rv = stream->Write(requestBuf.get(), requestBuf.Length(), &n);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
2000-02-03 01:48:55 +03:00
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
NS_ENSURE_TRUE(n == requestBuf.Length(), NS_ERROR_UNEXPECTED);
|
|
|
|
return NS_OK;
|
2000-02-03 01:48:55 +03:00
|
|
|
}
|