2001-09-28 20:14:13 +00:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-04-14 17:37:39 +00:00
|
|
|
/* vim: set ts=4 sw=4 et cindent: */
|
2001-09-28 20:14:13 +00:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 22:01:16 +00:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-05-21 06:29:13 +00:00
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* 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/
|
1999-05-21 06:29:13 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00: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-05-21 06:29:13 +00:00
|
|
|
*
|
1999-11-06 03:40:37 +00:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 22:01:16 +00:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-28 20:14:13 +00:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-11-06 03:40:37 +00:00
|
|
|
*
|
2001-09-28 20:14:13 +00:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 22:01:16 +00:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 22:01:16 +00:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-28 20:14:13 +00:00
|
|
|
* 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
|
2004-04-18 22:01:16 +00:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-28 20:14:13 +00:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-05-21 06:29:13 +00:00
|
|
|
|
|
|
|
/*
|
1999-06-24 21:41:19 +00:00
|
|
|
The TestProtocols tests the basic protocols architecture and can
|
|
|
|
be used to test individual protocols as well. If this grows too
|
|
|
|
big then we should split it to individual protocols.
|
2002-07-04 14:29:25 +00:00
|
|
|
|
1999-06-24 21:41:19 +00:00
|
|
|
-Gagan Saksena 04/29/99
|
1999-05-21 06:29:13 +00:00
|
|
|
*/
|
|
|
|
|
2004-10-21 20:57:17 +00:00
|
|
|
#include "TestCommon.h"
|
|
|
|
|
2004-04-14 17:37:39 +00:00
|
|
|
#define FORCE_PR_LOG
|
1999-05-21 06:29:13 +00:00
|
|
|
#include <stdio.h>
|
1999-06-01 22:02:40 +00:00
|
|
|
#ifdef WIN32
|
1999-05-21 06:29:13 +00:00
|
|
|
#include <windows.h>
|
1999-06-01 22:02:40 +00:00
|
|
|
#endif
|
2003-11-18 02:20:34 +00:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
1999-05-21 06:29:13 +00:00
|
|
|
#include "nspr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
1999-06-07 21:33:30 +00:00
|
|
|
#include "nsIIOService.h"
|
1999-05-21 06:29:13 +00:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIInputStream.h"
|
2000-08-22 07:03:33 +00:00
|
|
|
#include "nsIInputStream.h"
|
1999-05-21 06:29:13 +00:00
|
|
|
#include "nsCRT.h"
|
1999-06-07 21:33:30 +00:00
|
|
|
#include "nsIChannel.h"
|
2002-02-14 03:10:19 +00:00
|
|
|
#include "nsIResumableChannel.h"
|
1999-06-08 09:46:10 +00:00
|
|
|
#include "nsIURL.h"
|
2001-05-11 21:04:09 +00:00
|
|
|
#include "nsIHttpChannel.h"
|
2004-04-14 17:37:39 +00:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2002-09-26 23:04:01 +00:00
|
|
|
#include "nsIHttpHeaderVisitor.h"
|
2005-03-07 19:46:06 +00:00
|
|
|
#include "nsIChannelEventSink.h"
|
2010-08-05 02:15:55 +00:00
|
|
|
#include "nsIAsyncVerifyRedirectCallback.h"
|
1999-11-18 07:36:41 +00:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-05 21:28:38 +00:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
1999-07-30 04:17:23 +00:00
|
|
|
#include "nsIDNSService.h"
|
2003-11-18 02:20:34 +00:00
|
|
|
#include "nsIAuthPrompt.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
2005-04-05 17:40:32 +00:00
|
|
|
#include "nsIPropertyBag2.h"
|
|
|
|
#include "nsIWritablePropertyBag2.h"
|
2011-05-21 10:03:36 +00:00
|
|
|
#include "nsITimedChannel.h"
|
2005-04-05 17:40:32 +00:00
|
|
|
#include "nsChannelProperties.h"
|
1999-06-02 23:02:53 +00:00
|
|
|
|
1999-08-05 08:29:36 +00:00
|
|
|
#include "nsISimpleEnumerator.h"
|
2005-11-08 19:23:00 +00:00
|
|
|
#include "nsStringAPI.h"
|
2000-03-29 03:58:50 +00:00
|
|
|
#include "nsNetUtil.h"
|
2003-01-18 02:15:14 +00:00
|
|
|
#include "prlog.h"
|
2004-04-14 17:37:39 +00:00
|
|
|
#include "prtime.h"
|
2003-01-18 02:15:14 +00:00
|
|
|
|
2008-07-28 01:09:10 +00:00
|
|
|
namespace TestProtocols {
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
#if defined(PR_LOGGING)
|
|
|
|
//
|
|
|
|
// set NSPR_LOG_MODULES=Test:5
|
|
|
|
//
|
|
|
|
static PRLogModuleInfo *gTestLog = nsnull;
|
|
|
|
#endif
|
|
|
|
#define LOG(args) PR_LOG(gTestLog, PR_LOG_DEBUG, args)
|
1999-08-05 08:29:36 +00:00
|
|
|
|
1999-06-07 21:33:30 +00:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1999-05-21 06:29:13 +00:00
|
|
|
|
1999-07-13 02:37:08 +00:00
|
|
|
//static PRTime gElapsedTime; // enable when we time it...
|
1999-06-23 19:27:44 +00:00
|
|
|
static int gKeepRunning = 0;
|
1999-06-25 07:52:12 +00:00
|
|
|
static PRBool gVerbose = PR_FALSE;
|
2001-02-21 20:38:08 +00:00
|
|
|
static PRBool gAskUserForInput = PR_FALSE;
|
2002-02-14 03:10:19 +00:00
|
|
|
static PRBool gResume = PR_FALSE;
|
2004-06-16 19:51:21 +00:00
|
|
|
static PRUint64 gStartAt = 0;
|
2001-02-21 20:38:08 +00:00
|
|
|
|
2004-10-29 23:20:50 +00:00
|
|
|
static const char* gEntityID;
|
2004-04-14 17:37:39 +00:00
|
|
|
|
2003-11-18 02:20:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Set proxy preferences for testing
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
SetHttpProxy(const char *proxy)
|
|
|
|
{
|
|
|
|
const char *colon = strchr(proxy, ':');
|
|
|
|
if (!colon)
|
|
|
|
{
|
|
|
|
NS_WARNING("invalid proxy token; use host:port");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
int port = atoi(colon + 1);
|
|
|
|
if (port == 0)
|
|
|
|
{
|
|
|
|
NS_WARNING("invalid proxy port; must be an integer");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
nsCAutoString proxyHost;
|
|
|
|
proxyHost = Substring(proxy, colon);
|
|
|
|
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefs)
|
|
|
|
{
|
|
|
|
prefs->SetCharPref("network.proxy.http", proxyHost.get());
|
|
|
|
prefs->SetIntPref("network.proxy.http_port", port);
|
|
|
|
prefs->SetIntPref("network.proxy.type", 1); // manual proxy config
|
|
|
|
}
|
|
|
|
LOG(("connecting via proxy=%s:%d\n", proxyHost.get(), port));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2006-02-14 15:37:10 +00:00
|
|
|
static nsresult
|
|
|
|
SetPACFile(const char* pacURL)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (prefs)
|
|
|
|
{
|
|
|
|
prefs->SetCharPref("network.proxy.autoconfig_url", pacURL);
|
|
|
|
prefs->SetIntPref("network.proxy.type", 2); // PAC file
|
|
|
|
}
|
|
|
|
LOG(("connecting using PAC file %s\n", pacURL));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-05-21 10:03:36 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// Timing information
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void PrintTimingInformation(nsITimedChannel* channel) {
|
|
|
|
#define PRINT_VALUE(property) \
|
|
|
|
{ \
|
|
|
|
PRTime value; \
|
|
|
|
channel->Get##property(&value); \
|
|
|
|
if (value) { \
|
|
|
|
PRExplodedTime exploded; \
|
|
|
|
PR_ExplodeTime(value, PR_LocalTimeParameters, &exploded); \
|
|
|
|
char buf[256]; \
|
|
|
|
PR_FormatTime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", &exploded); \
|
|
|
|
LOG((" " #property ":\t%s (%i usec)", buf, exploded.tm_usec)); \
|
|
|
|
} else { \
|
|
|
|
LOG((" " #property ":\t0")); \
|
|
|
|
} \
|
|
|
|
}
|
|
|
|
LOG(("Timing data:"));
|
|
|
|
PRINT_VALUE(ChannelCreationTime)
|
|
|
|
PRINT_VALUE(AsyncOpenTime)
|
|
|
|
PRINT_VALUE(DomainLookupStartTime)
|
|
|
|
PRINT_VALUE(DomainLookupEndTime)
|
|
|
|
PRINT_VALUE(ConnectStartTime)
|
|
|
|
PRINT_VALUE(ConnectEndTime)
|
|
|
|
PRINT_VALUE(RequestStartTime)
|
|
|
|
PRINT_VALUE(ResponseStartTime)
|
|
|
|
PRINT_VALUE(ResponseEndTime)
|
|
|
|
PRINT_VALUE(CacheReadStartTime)
|
|
|
|
PRINT_VALUE(CacheReadEndTime)
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HeaderVisitor
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class HeaderVisitor : public nsIHttpHeaderVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIHTTPHEADERVISITOR
|
|
|
|
|
2003-01-08 22:35:09 +00:00
|
|
|
HeaderVisitor() { }
|
2001-05-11 21:04:09 +00:00
|
|
|
virtual ~HeaderVisitor() {}
|
|
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS1(HeaderVisitor, nsIHttpHeaderVisitor)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-20 22:50:33 +00:00
|
|
|
HeaderVisitor::VisitHeader(const nsACString &header, const nsACString &value)
|
2001-05-11 21:04:09 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG((" %s: %s\n",
|
2002-03-20 22:50:33 +00:00
|
|
|
PromiseFlatCString(header).get(),
|
2003-01-18 02:15:14 +00:00
|
|
|
PromiseFlatCString(value).get()));
|
2001-05-11 21:04:09 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// URLLoadInfo
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-05-21 06:29:13 +00:00
|
|
|
|
1999-06-27 11:02:40 +00:00
|
|
|
class URLLoadInfo : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
URLLoadInfo(const char* aUrl);
|
|
|
|
virtual ~URLLoadInfo();
|
|
|
|
|
|
|
|
// ISupports interface...
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2001-03-02 09:26:57 +00:00
|
|
|
const char* Name() { return mURLString.get(); }
|
2011-04-01 00:15:27 +00:00
|
|
|
PRInt64 mBytesRead;
|
1999-06-27 11:02:40 +00:00
|
|
|
PRTime mTotalTime;
|
|
|
|
PRTime mConnectTime;
|
1999-08-29 17:42:34 +00:00
|
|
|
nsCString mURLString;
|
1999-06-27 11:02:40 +00:00
|
|
|
};
|
|
|
|
|
1999-08-29 17:42:34 +00:00
|
|
|
URLLoadInfo::URLLoadInfo(const char *aUrl) : mURLString(aUrl)
|
1999-06-27 11:02:40 +00:00
|
|
|
{
|
|
|
|
mBytesRead = 0;
|
|
|
|
mConnectTime = mTotalTime = PR_Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
URLLoadInfo::~URLLoadInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-21 01:48:11 +00:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS0(URLLoadInfo)
|
1999-06-27 11:02:40 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
2005-03-07 19:46:06 +00:00
|
|
|
// TestChannelEventSink
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
1999-06-27 11:02:40 +00:00
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
class TestChannelEventSink : public nsIChannelEventSink
|
1999-05-21 06:29:13 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2005-03-07 19:46:06 +00:00
|
|
|
NS_DECL_NSICHANNELEVENTSINK
|
1999-05-21 06:29:13 +00:00
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
TestChannelEventSink();
|
|
|
|
virtual ~TestChannelEventSink();
|
1999-06-16 09:40:40 +00:00
|
|
|
};
|
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
TestChannelEventSink::TestChannelEventSink()
|
1999-06-16 09:40:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
TestChannelEventSink::~TestChannelEventSink()
|
1999-06-16 09:40:40 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(TestChannelEventSink, nsIChannelEventSink)
|
1999-06-16 09:40:40 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2010-08-05 02:15:55 +00:00
|
|
|
TestChannelEventSink::AsyncOnChannelRedirect(nsIChannel *channel,
|
|
|
|
nsIChannel *newChannel,
|
|
|
|
PRUint32 flags,
|
|
|
|
nsIAsyncVerifyRedirectCallback *callback)
|
1999-06-16 09:40:40 +00:00
|
|
|
{
|
2005-03-07 19:46:06 +00:00
|
|
|
LOG(("\n+++ TestChannelEventSink::OnChannelRedirect (with flags %x) +++\n",
|
|
|
|
flags));
|
2010-08-05 02:15:55 +00:00
|
|
|
callback->OnRedirectVerifyCallback(NS_OK);
|
1999-06-16 09:40:40 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-18 02:20:34 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// TestAuthPrompt
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class TestAuthPrompt : public nsIAuthPrompt
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIAUTHPROMPT
|
|
|
|
|
|
|
|
TestAuthPrompt();
|
|
|
|
virtual ~TestAuthPrompt();
|
|
|
|
};
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(TestAuthPrompt, nsIAuthPrompt)
|
|
|
|
|
|
|
|
TestAuthPrompt::TestAuthPrompt()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
TestAuthPrompt::~TestAuthPrompt()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TestAuthPrompt::Prompt(const PRUnichar *dialogTitle,
|
|
|
|
const PRUnichar *text,
|
|
|
|
const PRUnichar *passwordRealm,
|
|
|
|
PRUint32 savePassword,
|
|
|
|
const PRUnichar *defaultText,
|
|
|
|
PRUnichar **result,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TestAuthPrompt::PromptUsernameAndPassword(const PRUnichar *dialogTitle,
|
|
|
|
const PRUnichar *dialogText,
|
|
|
|
const PRUnichar *passwordRealm,
|
|
|
|
PRUint32 savePassword,
|
|
|
|
PRUnichar **user,
|
|
|
|
PRUnichar **pwd,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
NS_ConvertUTF16toUTF8 text(passwordRealm);
|
|
|
|
printf("* --------------------------------------------------------------------------- *\n");
|
|
|
|
printf("* Authentication Required [%s]\n", text.get());
|
|
|
|
printf("* --------------------------------------------------------------------------- *\n");
|
|
|
|
|
|
|
|
char buf[256];
|
|
|
|
int n;
|
|
|
|
|
|
|
|
printf("Enter username: ");
|
|
|
|
fgets(buf, sizeof(buf), stdin);
|
|
|
|
n = strlen(buf);
|
|
|
|
buf[n-1] = '\0'; // trim trailing newline
|
2005-11-08 19:23:00 +00:00
|
|
|
*user = NS_StringCloneData(NS_ConvertUTF8toUTF16(buf));
|
2003-11-18 02:20:34 +00:00
|
|
|
|
|
|
|
const char *p;
|
2011-04-28 20:15:46 +00:00
|
|
|
#if defined(XP_UNIX) && !defined(ANDROID)
|
2003-11-18 02:20:34 +00:00
|
|
|
p = getpass("Enter password: ");
|
|
|
|
#else
|
|
|
|
printf("Enter password: ");
|
|
|
|
fgets(buf, sizeof(buf), stdin);
|
|
|
|
n = strlen(buf);
|
|
|
|
buf[n-1] = '\0'; // trim trailing newline
|
|
|
|
p = buf;
|
|
|
|
#endif
|
2005-11-08 19:23:00 +00:00
|
|
|
*pwd = NS_StringCloneData(NS_ConvertUTF8toUTF16(p));
|
2003-11-18 02:20:34 +00:00
|
|
|
|
|
|
|
// zap buf
|
|
|
|
memset(buf, 0, sizeof(buf));
|
|
|
|
|
|
|
|
*_retval = PR_TRUE;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
TestAuthPrompt::PromptPassword(const PRUnichar *dialogTitle,
|
|
|
|
const PRUnichar *text,
|
|
|
|
const PRUnichar *passwordRealm,
|
|
|
|
PRUint32 savePassword,
|
|
|
|
PRUnichar **pwd,
|
|
|
|
PRBool *_retval)
|
|
|
|
{
|
|
|
|
*_retval = PR_FALSE;
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// InputTestConsumer
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-06-16 09:40:40 +00:00
|
|
|
|
|
|
|
class InputTestConsumer : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
InputTestConsumer();
|
|
|
|
virtual ~InputTestConsumer();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2001-04-10 06:01:08 +00:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
1999-09-16 01:16:22 +00:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-05-21 06:29:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
InputTestConsumer::InputTestConsumer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputTestConsumer::~InputTestConsumer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-03-06 03:30:02 +00:00
|
|
|
NS_IMPL_ISUPPORTS2(InputTestConsumer, nsIStreamListener, nsIRequestObserver)
|
1999-05-21 06:29:13 +00:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
1999-05-21 06:29:13 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("InputTestConsumer::OnStartRequest\n"));
|
|
|
|
|
1999-06-27 11:02:40 +00:00
|
|
|
URLLoadInfo* info = (URLLoadInfo*)context;
|
2001-05-11 21:04:09 +00:00
|
|
|
if (info)
|
1999-06-27 11:02:40 +00:00
|
|
|
info->mConnectTime = PR_Now() - info->mConnectTime;
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
if (gVerbose)
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\nStarted loading: %s\n", info ? info->Name() : "UNKNOWN URL"));
|
1999-06-25 07:52:12 +00:00
|
|
|
|
2002-03-20 22:50:33 +00:00
|
|
|
nsCAutoString value;
|
2001-05-11 21:04:09 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
if (channel) {
|
2002-01-13 00:54:27 +00:00
|
|
|
nsresult status;
|
|
|
|
channel->GetStatus(&status);
|
2004-04-14 17:37:39 +00:00
|
|
|
LOG(("Channel Status: %08x\n", status));
|
2002-01-13 00:54:27 +00:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("Channel Info:\n"));
|
|
|
|
|
|
|
|
channel->GetName(value);
|
|
|
|
LOG(("\tName: %s\n", value.get()));
|
2002-03-20 22:50:33 +00:00
|
|
|
|
|
|
|
channel->GetContentType(value);
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\tContent-Type: %s\n", value.get()));
|
2002-03-20 22:50:33 +00:00
|
|
|
|
|
|
|
channel->GetContentCharset(value);
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\tContent-Charset: %s\n", value.get()));
|
2002-01-13 00:54:27 +00:00
|
|
|
|
2010-08-30 20:20:39 +00:00
|
|
|
PRInt32 length = -1;
|
2002-01-13 00:54:27 +00:00
|
|
|
if (NS_SUCCEEDED(channel->GetContentLength(&length)))
|
2010-08-30 20:20:39 +00:00
|
|
|
LOG(("\tContent-Length: %d\n", length));
|
2002-01-13 00:54:27 +00:00
|
|
|
else
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\tContent-Length: Unknown\n"));
|
2002-01-13 00:54:27 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
channel->GetOwner(getter_AddRefs(owner));
|
|
|
|
LOG(("\tChannel Owner: %x\n", owner.get()));
|
1999-06-25 07:52:12 +00:00
|
|
|
}
|
|
|
|
|
2005-04-05 17:40:32 +00:00
|
|
|
nsCOMPtr<nsIPropertyBag2> props = do_QueryInterface(request);
|
2004-10-28 22:52:45 +00:00
|
|
|
if (props) {
|
|
|
|
nsCOMPtr<nsIURI> foo;
|
2005-04-05 17:40:32 +00:00
|
|
|
props->GetPropertyAsInterface(NS_LITERAL_STRING("test.foo"),
|
|
|
|
NS_GET_IID(nsIURI),
|
|
|
|
getter_AddRefs(foo));
|
2004-10-28 22:52:45 +00:00
|
|
|
if (foo) {
|
|
|
|
nsCAutoString spec;
|
|
|
|
foo->GetSpec(spec);
|
|
|
|
LOG(("\ttest.foo: %s\n", spec.get()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-08-30 20:20:39 +00:00
|
|
|
nsCOMPtr<nsIPropertyBag2> propbag = do_QueryInterface(request);
|
|
|
|
if (propbag) {
|
|
|
|
PRInt64 len;
|
|
|
|
nsresult rv = propbag->GetPropertyAsInt64(NS_CHANNEL_PROP_CONTENT_LENGTH,
|
|
|
|
&len);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
LOG(("\t64-bit length: %lli\n", len));
|
|
|
|
}
|
|
|
|
|
2004-04-14 17:37:39 +00:00
|
|
|
nsCOMPtr<nsIHttpChannelInternal> httpChannelInt(do_QueryInterface(request));
|
|
|
|
if (httpChannelInt) {
|
|
|
|
PRUint32 majorVer, minorVer;
|
|
|
|
nsresult rv = httpChannelInt->GetResponseVersion(&majorVer, &minorVer);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
LOG(("HTTP Response version: %u.%u\n", majorVer, minorVer));
|
|
|
|
}
|
2001-05-11 21:04:09 +00:00
|
|
|
nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(request));
|
|
|
|
if (httpChannel) {
|
|
|
|
HeaderVisitor *visitor = new HeaderVisitor();
|
|
|
|
if (!visitor)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(visitor);
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("HTTP request headers:\n"));
|
2001-05-11 21:04:09 +00:00
|
|
|
httpChannel->VisitRequestHeaders(visitor);
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("HTTP response headers:\n"));
|
2001-05-11 21:04:09 +00:00
|
|
|
httpChannel->VisitResponseHeaders(visitor);
|
|
|
|
|
|
|
|
NS_RELEASE(visitor);
|
1999-06-25 07:52:12 +00:00
|
|
|
}
|
2002-07-04 14:29:25 +00:00
|
|
|
|
2002-02-14 03:10:19 +00:00
|
|
|
nsCOMPtr<nsIResumableChannel> resChannel = do_QueryInterface(request);
|
|
|
|
if (resChannel) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("Resumable entity identification:\n"));
|
2004-09-01 18:04:17 +00:00
|
|
|
nsCAutoString entityID;
|
|
|
|
nsresult rv = resChannel->GetEntityID(entityID);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
LOG(("\t|%s|\n", entityID.get()));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG(("\t<none>\n"));
|
2002-02-14 03:10:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-21 06:29:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
InputTestConsumer::OnDataAvailable(nsIRequest *request,
|
1999-07-07 08:08:40 +00:00
|
|
|
nsISupports* context,
|
1999-06-28 20:37:10 +00:00
|
|
|
nsIInputStream *aIStream,
|
1999-05-21 06:29:13 +00:00
|
|
|
PRUint32 aSourceOffset,
|
|
|
|
PRUint32 aLength)
|
|
|
|
{
|
|
|
|
char buf[1025];
|
1999-10-05 05:02:56 +00:00
|
|
|
PRUint32 amt, size;
|
1999-06-25 06:28:58 +00:00
|
|
|
nsresult rv;
|
1999-06-27 11:02:40 +00:00
|
|
|
URLLoadInfo* info = (URLLoadInfo*)context;
|
1999-06-25 06:28:58 +00:00
|
|
|
|
1999-10-05 05:02:56 +00:00
|
|
|
while (aLength) {
|
2011-06-25 14:06:02 +00:00
|
|
|
size = NS_MIN<PRUint32>(aLength, sizeof(buf));
|
1999-10-05 05:02:56 +00:00
|
|
|
|
|
|
|
rv = aIStream->Read(buf, size, &amt);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_ASSERTION((NS_BASE_STREAM_WOULD_BLOCK != rv),
|
|
|
|
"The stream should never block.");
|
|
|
|
return rv;
|
|
|
|
}
|
1999-06-25 07:52:12 +00:00
|
|
|
if (gVerbose) {
|
|
|
|
buf[amt] = '\0';
|
|
|
|
puts(buf);
|
|
|
|
}
|
1999-06-27 11:02:40 +00:00
|
|
|
if (info) {
|
|
|
|
info->mBytesRead += amt;
|
|
|
|
}
|
1999-05-21 06:29:13 +00:00
|
|
|
|
1999-10-05 05:02:56 +00:00
|
|
|
aLength -= amt;
|
|
|
|
}
|
1999-05-21 06:29:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 20:38:08 +00:00
|
|
|
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
|
2001-04-10 06:01:08 +00:00
|
|
|
nsresult aStatus)
|
1999-05-21 06:29:13 +00:00
|
|
|
{
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("InputTestConsumer::OnStopRequest [status=%x]\n", aStatus));
|
|
|
|
|
1999-06-27 11:02:40 +00:00
|
|
|
URLLoadInfo* info = (URLLoadInfo*)context;
|
|
|
|
|
|
|
|
if (info) {
|
1999-06-29 06:54:05 +00:00
|
|
|
double connectTime;
|
|
|
|
double readTime;
|
1999-07-15 22:57:50 +00:00
|
|
|
PRUint32 httpStatus;
|
|
|
|
PRBool bHTTPURL = PR_FALSE;
|
1999-06-29 06:54:05 +00:00
|
|
|
|
1999-06-27 11:02:40 +00:00
|
|
|
info->mTotalTime = PR_Now() - info->mTotalTime;
|
1999-06-29 06:54:05 +00:00
|
|
|
|
|
|
|
connectTime = (info->mConnectTime/1000.0)/1000.0;
|
|
|
|
readTime = ((info->mTotalTime-info->mConnectTime)/1000.0)/1000.0;
|
1999-06-27 11:02:40 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
nsCOMPtr<nsIHttpChannel> pHTTPCon(do_QueryInterface(request));
|
1999-07-15 22:57:50 +00:00
|
|
|
if (pHTTPCon) {
|
|
|
|
pHTTPCon->GetResponseStatus(&httpStatus);
|
|
|
|
bHTTPURL = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\nFinished loading: %s Status Code: %x\n", info->Name(), aStatus));
|
1999-07-15 22:57:50 +00:00
|
|
|
if (bHTTPURL)
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\tHTTP Status: %u\n", httpStatus));
|
2002-12-04 04:18:08 +00:00
|
|
|
if (NS_ERROR_UNKNOWN_HOST == aStatus ||
|
|
|
|
NS_ERROR_UNKNOWN_PROXY_HOST == aStatus) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\tDNS lookup failed.\n"));
|
1999-07-30 02:35:12 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\tTime to connect: %.3f seconds\n", connectTime));
|
|
|
|
LOG(("\tTime to read: %.3f seconds.\n", readTime));
|
2011-04-28 18:30:30 +00:00
|
|
|
LOG(("\tRead: %lld bytes.\n", info->mBytesRead));
|
2011-04-01 00:15:27 +00:00
|
|
|
if (info->mBytesRead == PRInt64(0)) {
|
2002-01-13 00:54:27 +00:00
|
|
|
} else if (readTime > 0.0) {
|
2011-04-01 00:15:27 +00:00
|
|
|
LOG(("\tThroughput: %.0f bps.\n", (PRFloat64)(info->mBytesRead*PRInt64(8))/readTime));
|
1999-06-29 06:54:05 +00:00
|
|
|
} else {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\tThroughput: REAL FAST!!\n"));
|
1999-06-29 06:54:05 +00:00
|
|
|
}
|
2011-05-21 10:03:36 +00:00
|
|
|
|
|
|
|
nsCOMPtr<nsITimedChannel> timed(do_QueryInterface(request));
|
|
|
|
if (timed)
|
|
|
|
PrintTimingInformation(timed);
|
1999-06-27 11:02:40 +00:00
|
|
|
} else {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\nFinished loading: UNKNOWN URL. Status Code: %x\n", aStatus));
|
1999-06-27 11:02:40 +00:00
|
|
|
}
|
1999-06-25 07:52:12 +00:00
|
|
|
|
2006-05-10 17:30:15 +00:00
|
|
|
if (--gKeepRunning == 0)
|
|
|
|
QuitPumpingEvents();
|
1999-05-21 06:29:13 +00:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// NotificationCallbacks
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-06-07 21:33:30 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
class NotificationCallbacks : public nsIInterfaceRequestor {
|
1999-06-07 21:33:30 +00:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
NotificationCallbacks() {
|
1999-06-16 09:40:40 +00:00
|
|
|
}
|
|
|
|
|
2003-11-18 02:20:34 +00:00
|
|
|
NS_IMETHOD GetInterface(const nsIID& iid, void* *result) {
|
1999-06-11 09:18:25 +00:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
if (iid.Equals(NS_GET_IID(nsIChannelEventSink))) {
|
|
|
|
TestChannelEventSink *sink;
|
1999-06-11 09:18:25 +00:00
|
|
|
|
2005-03-07 19:46:06 +00:00
|
|
|
sink = new TestChannelEventSink();
|
1999-11-17 08:14:52 +00:00
|
|
|
if (sink == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(sink);
|
2003-11-18 02:20:34 +00:00
|
|
|
rv = sink->QueryInterface(iid, result);
|
1999-11-17 08:14:52 +00:00
|
|
|
NS_RELEASE(sink);
|
1999-06-07 21:33:30 +00:00
|
|
|
}
|
2003-11-18 02:20:34 +00:00
|
|
|
|
|
|
|
if (iid.Equals(NS_GET_IID(nsIAuthPrompt))) {
|
|
|
|
TestAuthPrompt *prompt;
|
|
|
|
|
|
|
|
prompt = new TestAuthPrompt();
|
|
|
|
if (prompt == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(prompt);
|
|
|
|
rv = prompt->QueryInterface(iid, result);
|
|
|
|
NS_RELEASE(prompt);
|
|
|
|
}
|
1999-06-11 09:18:25 +00:00
|
|
|
return rv;
|
1999-06-07 21:33:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
NS_IMPL_ISUPPORTS1(NotificationCallbacks, nsIInterfaceRequestor)
|
1999-06-07 21:33:30 +00:00
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// helpers...
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-05-21 06:29:13 +00:00
|
|
|
|
1999-06-17 07:46:00 +00:00
|
|
|
nsresult StartLoadingURL(const char* aUrlString)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2001-07-25 07:54:28 +00:00
|
|
|
nsCOMPtr<nsIIOService> pService(do_GetService(kIOServiceCID, &rv));
|
1999-06-17 07:46:00 +00:00
|
|
|
if (pService) {
|
|
|
|
nsCOMPtr<nsIURI> pURL;
|
|
|
|
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = pService->NewURI(nsDependentCString(aUrlString), nsnull, nsnull, getter_AddRefs(pURL));
|
1999-06-17 07:46:00 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("ERROR: NewURI failed for %s [rv=%x]\n", aUrlString));
|
1999-06-17 07:46:00 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIChannel> pChannel;
|
|
|
|
|
2001-05-11 21:04:09 +00:00
|
|
|
NotificationCallbacks* callbacks = new NotificationCallbacks();
|
1999-11-17 08:14:52 +00:00
|
|
|
if (!callbacks) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("Failed to create a new consumer!"));
|
1999-06-17 07:46:00 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;;
|
|
|
|
}
|
1999-11-17 08:14:52 +00:00
|
|
|
NS_ADDREF(callbacks);
|
1999-06-17 07:46:00 +00:00
|
|
|
|
|
|
|
// Async reading thru the calls of the event sink interface
|
2002-03-06 07:48:55 +00:00
|
|
|
rv = NS_NewChannel(getter_AddRefs(pChannel), pURL, pService,
|
|
|
|
nsnull, // loadGroup
|
|
|
|
callbacks); // notificationCallbacks
|
1999-11-17 08:14:52 +00:00
|
|
|
NS_RELEASE(callbacks);
|
1999-06-17 07:46:00 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("ERROR: NS_OpenURI failed for %s [rv=%x]\n", aUrlString, rv));
|
1999-06-17 07:46:00 +00:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-05-21 10:03:36 +00:00
|
|
|
nsCOMPtr<nsITimedChannel> timed(do_QueryInterface(pChannel));
|
|
|
|
if (timed)
|
|
|
|
timed->SetTimingEnabled(PR_TRUE);
|
|
|
|
|
2005-04-05 17:40:32 +00:00
|
|
|
nsCOMPtr<nsIWritablePropertyBag2> props = do_QueryInterface(pChannel);
|
2004-10-28 22:52:45 +00:00
|
|
|
if (props) {
|
2005-04-05 17:40:32 +00:00
|
|
|
rv = props->SetPropertyAsInterface(NS_LITERAL_STRING("test.foo"),
|
|
|
|
pURL);
|
|
|
|
if (NS_SUCCEEDED(rv))
|
2004-10-28 22:52:45 +00:00
|
|
|
LOG(("set prop 'test.foo'\n"));
|
|
|
|
}
|
|
|
|
|
1999-06-17 07:46:00 +00:00
|
|
|
/*
|
|
|
|
You may optionally add/set other headers on this
|
|
|
|
request object. This is done by QI for the specific
|
|
|
|
protocolConnection.
|
|
|
|
*/
|
2001-05-11 21:04:09 +00:00
|
|
|
nsCOMPtr<nsIHttpChannel> pHTTPCon(do_QueryInterface(pChannel));
|
1999-06-17 07:46:00 +00:00
|
|
|
|
|
|
|
if (pHTTPCon) {
|
1999-10-01 23:32:12 +00:00
|
|
|
// Setting a sample header.
|
2002-03-20 22:50:33 +00:00
|
|
|
rv = pHTTPCon->SetRequestHeader(NS_LITERAL_CSTRING("sample-header"),
|
2002-11-22 07:40:16 +00:00
|
|
|
NS_LITERAL_CSTRING("Sample-Value"),
|
|
|
|
PR_FALSE);
|
1999-06-17 07:46:00 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-01 23:32:12 +00:00
|
|
|
}
|
1999-06-17 07:46:00 +00:00
|
|
|
InputTestConsumer* listener;
|
|
|
|
|
|
|
|
listener = new InputTestConsumer;
|
|
|
|
NS_IF_ADDREF(listener);
|
|
|
|
if (!listener) {
|
|
|
|
NS_ERROR("Failed to create a new stream listener!");
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;;
|
|
|
|
}
|
|
|
|
|
1999-06-27 11:02:40 +00:00
|
|
|
URLLoadInfo* info;
|
|
|
|
info = new URLLoadInfo(aUrlString);
|
|
|
|
NS_IF_ADDREF(info);
|
|
|
|
if (!info) {
|
|
|
|
NS_ERROR("Failed to create a load info!");
|
1999-10-06 08:26:01 +00:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-27 11:02:40 +00:00
|
|
|
}
|
2002-02-14 03:10:19 +00:00
|
|
|
|
|
|
|
if (gResume) {
|
|
|
|
nsCOMPtr<nsIResumableChannel> res = do_QueryInterface(pChannel);
|
|
|
|
if (!res) {
|
|
|
|
NS_ERROR("Channel is not resumable!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2004-09-01 18:04:17 +00:00
|
|
|
nsCAutoString id;
|
|
|
|
if (gEntityID)
|
|
|
|
id = gEntityID;
|
|
|
|
LOG(("* resuming at %llu bytes, with entity id |%s|\n", gStartAt, id.get()));
|
2004-06-16 19:51:21 +00:00
|
|
|
res->ResumeAt(gStartAt, id);
|
2002-02-14 03:10:19 +00:00
|
|
|
}
|
2004-06-16 19:51:21 +00:00
|
|
|
rv = pChannel->AsyncOpen(listener, // IStreamListener consumer
|
|
|
|
info);
|
2000-03-29 03:58:50 +00:00
|
|
|
|
1999-06-27 11:02:40 +00:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2006-05-10 17:30:15 +00:00
|
|
|
gKeepRunning++;
|
1999-06-27 11:02:40 +00:00
|
|
|
}
|
2003-01-18 02:15:14 +00:00
|
|
|
else {
|
|
|
|
LOG(("ERROR: AsyncOpen failed [rv=%x]\n", rv));
|
|
|
|
}
|
1999-06-17 07:46:00 +00:00
|
|
|
NS_RELEASE(listener);
|
1999-06-27 11:02:40 +00:00
|
|
|
NS_RELEASE(info);
|
1999-06-17 07:46:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2005-11-08 19:23:00 +00:00
|
|
|
static PRInt32
|
|
|
|
FindChar(nsCString& buffer, char c)
|
|
|
|
{
|
|
|
|
const char *b;
|
|
|
|
PRInt32 len = NS_CStringGetData(buffer, &b);
|
|
|
|
|
|
|
|
for (PRInt32 offset = 0; offset < len; ++offset) {
|
|
|
|
if (b[offset] == c)
|
|
|
|
return offset;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
|
|
|
StripChar(nsCString& buffer, char c)
|
|
|
|
{
|
|
|
|
const char *b;
|
|
|
|
PRUint32 len = NS_CStringGetData(buffer, &b) - 1;
|
|
|
|
|
|
|
|
for (; len > 0; --len) {
|
|
|
|
if (b[len] == c) {
|
|
|
|
buffer.Cut(len, 1);
|
|
|
|
NS_CStringGetData(buffer, &b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
1999-06-27 11:02:40 +00:00
|
|
|
|
|
|
|
nsresult LoadURLsFromFile(char *aFileName)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRInt32 len, offset;
|
|
|
|
PRFileDesc* fd;
|
|
|
|
char buffer[1024];
|
1999-08-29 17:42:34 +00:00
|
|
|
nsCString fileBuffer;
|
2005-11-08 19:23:00 +00:00
|
|
|
nsCString urlString;
|
1999-06-27 11:02:40 +00:00
|
|
|
|
|
|
|
fd = PR_Open(aFileName, PR_RDONLY, 777);
|
|
|
|
if (!fd) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Keep reading the file until EOF (or an error) is reached...
|
|
|
|
do {
|
|
|
|
len = PR_Read(fd, buffer, sizeof(buffer));
|
|
|
|
if (len>0) {
|
|
|
|
fileBuffer.Append(buffer, len);
|
|
|
|
// Treat each line as a URL...
|
2005-11-08 19:23:00 +00:00
|
|
|
while ((offset = FindChar(fileBuffer, '\n')) != -1) {
|
2005-11-08 23:39:42 +00:00
|
|
|
urlString = StringHead(fileBuffer, offset);
|
1999-06-27 11:02:40 +00:00
|
|
|
fileBuffer.Cut(0, offset+1);
|
|
|
|
|
2005-11-08 19:23:00 +00:00
|
|
|
StripChar(urlString, '\r');
|
1999-06-27 11:02:40 +00:00
|
|
|
if (urlString.Length()) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\t%s\n", urlString.get()));
|
2001-03-02 09:26:57 +00:00
|
|
|
rv = StartLoadingURL(urlString.get());
|
1999-06-27 11:02:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (len>0);
|
|
|
|
|
|
|
|
// If anything is left in the fileBuffer, treat it as a URL...
|
2005-11-08 19:23:00 +00:00
|
|
|
StripChar(fileBuffer, '\r');
|
1999-06-27 11:02:40 +00:00
|
|
|
if (fileBuffer.Length()) {
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\t%s\n", fileBuffer.get()));
|
2001-03-02 09:26:57 +00:00
|
|
|
StartLoadingURL(fileBuffer.get());
|
1999-06-27 11:02:40 +00:00
|
|
|
}
|
2002-07-04 14:29:25 +00:00
|
|
|
|
1999-06-27 11:02:40 +00:00
|
|
|
PR_Close(fd);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-21 20:38:08 +00:00
|
|
|
|
|
|
|
nsresult LoadURLFromConsole()
|
|
|
|
{
|
|
|
|
char buffer[1024];
|
|
|
|
printf("Enter URL (\"q\" to start): ");
|
|
|
|
scanf("%s", buffer);
|
|
|
|
if (buffer[0]=='q')
|
|
|
|
gAskUserForInput = PR_FALSE;
|
|
|
|
else
|
|
|
|
StartLoadingURL(buffer);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2008-07-28 01:09:10 +00:00
|
|
|
} // namespace
|
|
|
|
|
|
|
|
using namespace TestProtocols;
|
|
|
|
|
1999-05-21 06:29:13 +00:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
2004-10-21 20:57:17 +00:00
|
|
|
if (test_common_init(&argc, &argv) != 0)
|
|
|
|
return -1;
|
|
|
|
|
1999-07-13 02:37:08 +00:00
|
|
|
nsresult rv= (nsresult)-1;
|
1999-05-21 06:29:13 +00:00
|
|
|
if (argc < 2) {
|
2006-02-14 15:37:10 +00:00
|
|
|
printf("usage: %s [-verbose] [-file <name>] [-resume <startoffset>"
|
|
|
|
"[-entityid <entityid>]] [-proxy <proxy>] [-pac <pacURL>]"
|
|
|
|
"[-console] <url> <url> ... \n", argv[0]);
|
1999-05-21 06:29:13 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
#if defined(PR_LOGGING)
|
2003-11-18 02:20:34 +00:00
|
|
|
gTestLog = PR_NewLogModule("Test");
|
2003-01-18 02:15:14 +00:00
|
|
|
#endif
|
|
|
|
|
1999-05-21 06:29:13 +00:00
|
|
|
/*
|
1999-06-01 22:02:40 +00:00
|
|
|
The following code only deals with XPCOM registration stuff. and setting
|
|
|
|
up the event queues. Copied from TestSocketIO.cpp
|
1999-05-21 06:29:13 +00:00
|
|
|
*/
|
1999-06-01 22:02:40 +00:00
|
|
|
|
2001-10-16 03:35:52 +00:00
|
|
|
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
1999-05-21 06:29:13 +00:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-07-04 14:29:25 +00:00
|
|
|
{
|
|
|
|
int i;
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("Trying to load:\n"));
|
2002-07-04 14:29:25 +00:00
|
|
|
for (i=1; i<argc; i++) {
|
|
|
|
// Turn on verbose printing...
|
|
|
|
if (PL_strcasecmp(argv[i], "-verbose") == 0) {
|
|
|
|
gVerbose = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Turn on netlib tracing...
|
|
|
|
if (PL_strcasecmp(argv[i], "-file") == 0) {
|
|
|
|
LoadURLsFromFile(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PL_strcasecmp(argv[i], "-console") == 0) {
|
|
|
|
gAskUserForInput = PR_TRUE;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PL_strcasecmp(argv[i], "-resume") == 0) {
|
|
|
|
gResume = PR_TRUE;
|
2004-06-16 19:51:21 +00:00
|
|
|
PR_sscanf(argv[++i], "%llu", &gStartAt);
|
2002-07-04 14:29:25 +00:00
|
|
|
continue;
|
|
|
|
}
|
1999-05-21 06:29:13 +00:00
|
|
|
|
2004-09-01 18:04:17 +00:00
|
|
|
if (PL_strcasecmp(argv[i], "-entityid") == 0) {
|
|
|
|
gEntityID = argv[++i];
|
2004-04-14 17:37:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-11-18 02:20:34 +00:00
|
|
|
if (PL_strcasecmp(argv[i], "-proxy") == 0) {
|
|
|
|
SetHttpProxy(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2006-02-14 15:37:10 +00:00
|
|
|
if (PL_strcasecmp(argv[i], "-pac") == 0) {
|
|
|
|
SetPACFile(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-01-18 02:15:14 +00:00
|
|
|
LOG(("\t%s\n", argv[i]));
|
2002-07-04 14:29:25 +00:00
|
|
|
rv = StartLoadingURL(argv[i]);
|
2002-02-14 03:10:19 +00:00
|
|
|
}
|
2006-05-10 17:30:15 +00:00
|
|
|
// Enter the message pump to allow the URL load to proceed.
|
|
|
|
PumpEvents();
|
2002-07-04 14:29:25 +00:00
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
2000-03-05 21:26:01 +00:00
|
|
|
NS_ShutdownXPCOM(nsnull);
|
1999-05-21 06:29:13 +00:00
|
|
|
return rv;
|
|
|
|
}
|