2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-04-14 21:37:39 +04:00
|
|
|
/* vim: set ts=4 sw=4 et cindent: */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-05-21 10:29:13 +04: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-05-21 10:29:13 +04: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-05-21 10:29:13 +04:00
|
|
|
*
|
1999-11-06 06:40:37 +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-11-06 06:40:37 +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-05-21 10:29:13 +04:00
|
|
|
|
|
|
|
/*
|
1999-06-25 01:41:19 +04: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 18:29:25 +04:00
|
|
|
|
1999-06-25 01:41:19 +04:00
|
|
|
-Gagan Saksena 04/29/99
|
1999-05-21 10:29:13 +04:00
|
|
|
*/
|
|
|
|
|
2004-04-14 21:37:39 +04:00
|
|
|
#define FORCE_PR_LOG
|
1999-05-21 10:29:13 +04:00
|
|
|
#include <stdio.h>
|
1999-06-02 02:02:40 +04:00
|
|
|
#ifdef WIN32
|
1999-05-21 10:29:13 +04:00
|
|
|
#include <windows.h>
|
1999-06-02 02:02:40 +04:00
|
|
|
#endif
|
2003-11-18 05:20:34 +03:00
|
|
|
#ifdef XP_UNIX
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
1999-05-21 10:29:13 +04:00
|
|
|
#include "nspr.h"
|
|
|
|
#include "nscore.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
1999-06-08 01:33:30 +04:00
|
|
|
#include "nsIIOService.h"
|
1999-05-21 10:29:13 +04:00
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIInputStream.h"
|
2000-08-22 11:03:33 +04:00
|
|
|
#include "nsIInputStream.h"
|
1999-05-21 10:29:13 +04:00
|
|
|
#include "nsCRT.h"
|
1999-06-08 01:33:30 +04:00
|
|
|
#include "nsIChannel.h"
|
2002-02-14 06:10:19 +03:00
|
|
|
#include "nsIResumableChannel.h"
|
|
|
|
#include "nsIResumableEntityID.h"
|
1999-06-08 13:46:10 +04:00
|
|
|
#include "nsIURL.h"
|
2001-05-12 01:04:09 +04:00
|
|
|
#include "nsIHttpChannel.h"
|
2004-04-14 21:37:39 +04:00
|
|
|
#include "nsIHttpChannelInternal.h"
|
2002-09-27 03:04:01 +04:00
|
|
|
#include "nsIHttpHeaderVisitor.h"
|
2001-05-12 01:04:09 +04:00
|
|
|
#include "nsIHttpEventSink.h"
|
1999-11-18 10:36:41 +03:00
|
|
|
#include "nsIInterfaceRequestor.h"
|
2001-09-06 01:28:38 +04:00
|
|
|
#include "nsIInterfaceRequestorUtils.h"
|
1999-07-30 08:17:23 +04:00
|
|
|
#include "nsIDNSService.h"
|
2003-11-18 05:20:34 +03:00
|
|
|
#include "nsIAuthPrompt.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
1999-06-03 03:02:53 +04:00
|
|
|
|
1999-08-05 12:29:36 +04:00
|
|
|
#include "nsISimpleEnumerator.h"
|
|
|
|
#include "nsXPIDLString.h"
|
2000-03-29 07:58:50 +04:00
|
|
|
#include "nsNetUtil.h"
|
2003-01-18 05:15:14 +03:00
|
|
|
#include "prlog.h"
|
2004-04-14 21:37:39 +04:00
|
|
|
#include "prtime.h"
|
2003-01-18 05:15:14 +03: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 12:29:36 +04:00
|
|
|
|
1999-05-21 10:29:13 +04:00
|
|
|
static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
|
1999-06-08 01:33:30 +04:00
|
|
|
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
1999-05-21 10:29:13 +04:00
|
|
|
|
1999-07-13 06:37:08 +04:00
|
|
|
//static PRTime gElapsedTime; // enable when we time it...
|
1999-06-23 23:27:44 +04:00
|
|
|
static int gKeepRunning = 0;
|
1999-06-25 11:52:12 +04:00
|
|
|
static PRBool gVerbose = PR_FALSE;
|
1999-05-21 10:29:13 +04:00
|
|
|
static nsIEventQueue* gEventQ = nsnull;
|
2001-02-21 23:38:08 +03:00
|
|
|
static PRBool gAskUserForInput = PR_FALSE;
|
2002-02-14 06:10:19 +03:00
|
|
|
static PRBool gResume = PR_FALSE;
|
|
|
|
static PRUint32 gStartAt = 0;
|
2001-02-21 23:38:08 +03:00
|
|
|
|
2004-04-14 21:37:39 +04:00
|
|
|
static const char* gLastMod = NULL;
|
|
|
|
static const char* gETag = NULL;
|
|
|
|
static PRUint32 gTotalSize = PR_UINT32_MAX;
|
|
|
|
|
2003-11-18 05:20:34 +03: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;
|
|
|
|
}
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// HeaderVisitor
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
class HeaderVisitor : public nsIHttpHeaderVisitor
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIHTTPHEADERVISITOR
|
|
|
|
|
2003-01-09 01:35:09 +03:00
|
|
|
HeaderVisitor() { }
|
2001-05-12 01:04:09 +04:00
|
|
|
virtual ~HeaderVisitor() {}
|
|
|
|
};
|
|
|
|
NS_IMPL_ISUPPORTS1(HeaderVisitor, nsIHttpHeaderVisitor)
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-21 01:50:33 +03:00
|
|
|
HeaderVisitor::VisitHeader(const nsACString &header, const nsACString &value)
|
2001-05-12 01:04:09 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG((" %s: %s\n",
|
2002-03-21 01:50:33 +03:00
|
|
|
PromiseFlatCString(header).get(),
|
2003-01-18 05:15:14 +03:00
|
|
|
PromiseFlatCString(value).get()));
|
2001-05-12 01:04:09 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// URLLoadInfo
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-05-21 10:29:13 +04:00
|
|
|
|
1999-06-27 15:02:40 +04:00
|
|
|
class URLLoadInfo : public nsISupports
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
URLLoadInfo(const char* aUrl);
|
|
|
|
virtual ~URLLoadInfo();
|
|
|
|
|
|
|
|
// ISupports interface...
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2001-03-02 12:26:57 +03:00
|
|
|
const char* Name() { return mURLString.get(); }
|
1999-06-27 15:02:40 +04:00
|
|
|
PRInt32 mBytesRead;
|
|
|
|
PRTime mTotalTime;
|
|
|
|
PRTime mConnectTime;
|
1999-08-29 21:42:34 +04:00
|
|
|
nsCString mURLString;
|
1999-06-27 15:02:40 +04:00
|
|
|
};
|
|
|
|
|
1999-08-29 21:42:34 +04:00
|
|
|
URLLoadInfo::URLLoadInfo(const char *aUrl) : mURLString(aUrl)
|
1999-06-27 15:02:40 +04:00
|
|
|
{
|
|
|
|
mBytesRead = 0;
|
|
|
|
mConnectTime = mTotalTime = PR_Now();
|
|
|
|
}
|
|
|
|
|
|
|
|
URLLoadInfo::~URLLoadInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-08-21 05:48:11 +04:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS0(URLLoadInfo)
|
1999-06-27 15:02:40 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// TestHttpEventSink
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-06-27 15:02:40 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
class TestHttpEventSink : public nsIHttpEventSink
|
1999-05-21 10:29:13 +04:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
2001-05-12 01:04:09 +04:00
|
|
|
NS_DECL_NSIHTTPEVENTSINK
|
1999-05-21 10:29:13 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
TestHttpEventSink();
|
|
|
|
virtual ~TestHttpEventSink();
|
1999-06-16 13:40:40 +04:00
|
|
|
};
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
TestHttpEventSink::TestHttpEventSink()
|
1999-06-16 13:40:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
TestHttpEventSink::~TestHttpEventSink()
|
1999-06-16 13:40:40 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-08 03:12:15 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(TestHttpEventSink, nsIHttpEventSink)
|
1999-06-16 13:40:40 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-05-12 01:04:09 +04:00
|
|
|
TestHttpEventSink::OnRedirect(nsIHttpChannel *channel, nsIChannel *newChannel)
|
1999-06-16 13:40:40 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\n+++ TestHTTPEventSink::OnRedirect +++\n"));
|
1999-06-16 13:40:40 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-11-18 05:20:34 +03: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
|
|
|
|
*user = ToNewUnicode(nsDependentCString(buf));
|
|
|
|
|
|
|
|
const char *p;
|
|
|
|
#ifdef XP_UNIX
|
|
|
|
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
|
|
|
|
*pwd = ToNewUnicode(nsDependentCString(p));
|
|
|
|
|
|
|
|
// 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-12 01:04:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// InputTestConsumer
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-06-16 13:40:40 +04:00
|
|
|
|
|
|
|
class InputTestConsumer : public nsIStreamListener
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
InputTestConsumer();
|
|
|
|
virtual ~InputTestConsumer();
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
2001-04-10 10:01:08 +04:00
|
|
|
NS_DECL_NSIREQUESTOBSERVER
|
1999-09-16 05:16:22 +04:00
|
|
|
NS_DECL_NSISTREAMLISTENER
|
1999-05-21 10:29:13 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
InputTestConsumer::InputTestConsumer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
InputTestConsumer::~InputTestConsumer()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2002-03-06 06:30:02 +03:00
|
|
|
NS_IMPL_ISUPPORTS2(InputTestConsumer, nsIStreamListener, nsIRequestObserver)
|
1999-05-21 10:29:13 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
InputTestConsumer::OnStartRequest(nsIRequest *request, nsISupports* context)
|
1999-05-21 10:29:13 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("InputTestConsumer::OnStartRequest\n"));
|
|
|
|
|
1999-06-27 15:02:40 +04:00
|
|
|
URLLoadInfo* info = (URLLoadInfo*)context;
|
2001-05-12 01:04:09 +04:00
|
|
|
if (info)
|
1999-06-27 15:02:40 +04:00
|
|
|
info->mConnectTime = PR_Now() - info->mConnectTime;
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
if (gVerbose)
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\nStarted loading: %s\n", info ? info->Name() : "UNKNOWN URL"));
|
1999-06-25 11:52:12 +04:00
|
|
|
|
2002-03-21 01:50:33 +03:00
|
|
|
nsCAutoString value;
|
2001-05-12 01:04:09 +04:00
|
|
|
|
|
|
|
nsCOMPtr<nsIChannel> channel = do_QueryInterface(request);
|
|
|
|
if (channel) {
|
2002-01-13 03:54:27 +03:00
|
|
|
nsresult status;
|
|
|
|
channel->GetStatus(&status);
|
2004-04-14 21:37:39 +04:00
|
|
|
LOG(("Channel Status: %08x\n", status));
|
2002-01-13 03:54:27 +03:00
|
|
|
if (NS_SUCCEEDED(status)) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("Channel Info:\n"));
|
|
|
|
|
|
|
|
channel->GetName(value);
|
|
|
|
LOG(("\tName: %s\n", value.get()));
|
2002-03-21 01:50:33 +03:00
|
|
|
|
|
|
|
channel->GetContentType(value);
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tContent-Type: %s\n", value.get()));
|
2002-03-21 01:50:33 +03:00
|
|
|
|
|
|
|
channel->GetContentCharset(value);
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tContent-Charset: %s\n", value.get()));
|
2002-01-13 03:54:27 +03:00
|
|
|
|
|
|
|
PRInt32 length = -1;
|
|
|
|
if (NS_SUCCEEDED(channel->GetContentLength(&length)))
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tContent-Length: %d\n", length));
|
2002-01-13 03:54:27 +03:00
|
|
|
else
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tContent-Length: Unknown\n"));
|
2002-01-13 03:54:27 +03:00
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> owner;
|
|
|
|
channel->GetOwner(getter_AddRefs(owner));
|
|
|
|
LOG(("\tChannel Owner: %x\n", owner.get()));
|
1999-06-25 11:52:12 +04:00
|
|
|
}
|
|
|
|
|
2004-04-14 21:37:39 +04: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-12 01:04:09 +04: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 05:15:14 +03:00
|
|
|
LOG(("HTTP request headers:\n"));
|
2001-05-12 01:04:09 +04:00
|
|
|
httpChannel->VisitRequestHeaders(visitor);
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("HTTP response headers:\n"));
|
2001-05-12 01:04:09 +04:00
|
|
|
httpChannel->VisitResponseHeaders(visitor);
|
|
|
|
|
|
|
|
NS_RELEASE(visitor);
|
1999-06-25 11:52:12 +04:00
|
|
|
}
|
2002-07-04 18:29:25 +04:00
|
|
|
|
2002-02-14 06:10:19 +03:00
|
|
|
nsCOMPtr<nsIResumableChannel> resChannel = do_QueryInterface(request);
|
|
|
|
if (resChannel) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("Resumable entity identification:\n"));
|
2002-02-14 06:10:19 +03:00
|
|
|
nsCOMPtr<nsIResumableEntityID> entityID;
|
|
|
|
nsresult rv = resChannel->GetEntityID(getter_AddRefs(entityID));
|
|
|
|
if (NS_SUCCEEDED(rv) && entityID) {
|
|
|
|
PRUint32 size;
|
|
|
|
if (NS_SUCCEEDED(entityID->GetSize(&size)) &&
|
|
|
|
size != PRUint32(-1))
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tSize: %d\n", size));
|
2002-02-14 06:10:19 +03:00
|
|
|
else
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tSize: Unknown\n"));
|
2004-04-14 21:37:39 +04:00
|
|
|
nsCAutoString lastModified;
|
|
|
|
if (NS_SUCCEEDED(entityID->GetLastModified(lastModified)) &&
|
|
|
|
!lastModified.IsEmpty())
|
|
|
|
LOG(("\tLast Modified: %s\n", lastModified.get()));
|
|
|
|
else
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tLast Modified: Unknown\n"));
|
2004-04-14 21:37:39 +04:00
|
|
|
nsCAutoString etag;
|
|
|
|
if (NS_SUCCEEDED(entityID->GetEntityTag(etag)) &&
|
|
|
|
!etag.IsEmpty())
|
|
|
|
LOG(("\tETag: %s\n", etag.get()));
|
|
|
|
else
|
|
|
|
LOG(("\tEtag: Unknown\n"));
|
2002-02-14 06:10:19 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1999-05-21 10:29:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
InputTestConsumer::OnDataAvailable(nsIRequest *request,
|
1999-07-07 12:08:40 +04:00
|
|
|
nsISupports* context,
|
1999-06-29 00:37:10 +04:00
|
|
|
nsIInputStream *aIStream,
|
1999-05-21 10:29:13 +04:00
|
|
|
PRUint32 aSourceOffset,
|
|
|
|
PRUint32 aLength)
|
|
|
|
{
|
|
|
|
char buf[1025];
|
1999-10-05 09:02:56 +04:00
|
|
|
PRUint32 amt, size;
|
1999-06-25 10:28:58 +04:00
|
|
|
nsresult rv;
|
1999-06-27 15:02:40 +04:00
|
|
|
URLLoadInfo* info = (URLLoadInfo*)context;
|
1999-06-25 10:28:58 +04:00
|
|
|
|
1999-10-05 09:02:56 +04:00
|
|
|
while (aLength) {
|
1999-10-05 10:28:17 +04:00
|
|
|
size = PR_MIN(aLength, sizeof(buf));
|
1999-10-05 09:02:56 +04: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 11:52:12 +04:00
|
|
|
if (gVerbose) {
|
|
|
|
buf[amt] = '\0';
|
|
|
|
puts(buf);
|
|
|
|
}
|
1999-06-27 15:02:40 +04:00
|
|
|
if (info) {
|
|
|
|
info->mBytesRead += amt;
|
|
|
|
}
|
1999-05-21 10:29:13 +04:00
|
|
|
|
1999-10-05 09:02:56 +04:00
|
|
|
aLength -= amt;
|
|
|
|
}
|
1999-05-21 10:29:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
PR_STATIC_CALLBACK(void) DecrementDestroyHandler(PLEvent *self)
|
|
|
|
{
|
|
|
|
PR_DELETE(self);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
PR_STATIC_CALLBACK(void*) DecrementEventHandler(PLEvent *self)
|
|
|
|
{
|
|
|
|
gKeepRunning--;
|
|
|
|
return nsnull;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FireDecrement()
|
|
|
|
{
|
|
|
|
PLEvent *event = PR_NEW(PLEvent);
|
|
|
|
PL_InitEvent(event,
|
|
|
|
nsnull,
|
|
|
|
DecrementEventHandler,
|
|
|
|
DecrementDestroyHandler);
|
|
|
|
|
|
|
|
gEventQ->PostEvent(event);
|
|
|
|
}
|
1999-05-21 10:29:13 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2001-02-21 23:38:08 +03:00
|
|
|
InputTestConsumer::OnStopRequest(nsIRequest *request, nsISupports* context,
|
2001-04-10 10:01:08 +04:00
|
|
|
nsresult aStatus)
|
1999-05-21 10:29:13 +04:00
|
|
|
{
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("InputTestConsumer::OnStopRequest [status=%x]\n", aStatus));
|
|
|
|
|
1999-06-27 15:02:40 +04:00
|
|
|
URLLoadInfo* info = (URLLoadInfo*)context;
|
|
|
|
|
|
|
|
if (info) {
|
1999-06-29 10:54:05 +04:00
|
|
|
double connectTime;
|
|
|
|
double readTime;
|
1999-07-16 02:57:50 +04:00
|
|
|
PRUint32 httpStatus;
|
|
|
|
PRBool bHTTPURL = PR_FALSE;
|
1999-06-29 10:54:05 +04:00
|
|
|
|
1999-06-27 15:02:40 +04:00
|
|
|
info->mTotalTime = PR_Now() - info->mTotalTime;
|
1999-06-29 10:54:05 +04:00
|
|
|
|
|
|
|
connectTime = (info->mConnectTime/1000.0)/1000.0;
|
|
|
|
readTime = ((info->mTotalTime-info->mConnectTime)/1000.0)/1000.0;
|
1999-06-27 15:02:40 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> pHTTPCon(do_QueryInterface(request));
|
1999-07-16 02:57:50 +04:00
|
|
|
if (pHTTPCon) {
|
|
|
|
pHTTPCon->GetResponseStatus(&httpStatus);
|
|
|
|
bHTTPURL = PR_TRUE;
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\nFinished loading: %s Status Code: %x\n", info->Name(), aStatus));
|
1999-07-16 02:57:50 +04:00
|
|
|
if (bHTTPURL)
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tHTTP Status: %u\n", httpStatus));
|
2002-12-04 07:18:08 +03:00
|
|
|
if (NS_ERROR_UNKNOWN_HOST == aStatus ||
|
|
|
|
NS_ERROR_UNKNOWN_PROXY_HOST == aStatus) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tDNS lookup failed.\n"));
|
1999-07-30 06:35:12 +04:00
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tTime to connect: %.3f seconds\n", connectTime));
|
|
|
|
LOG(("\tTime to read: %.3f seconds.\n", readTime));
|
|
|
|
LOG(("\tRead: %d bytes.\n", info->mBytesRead));
|
2002-01-13 03:54:27 +03:00
|
|
|
if (!info->mBytesRead) {
|
|
|
|
} else if (readTime > 0.0) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tThroughput: %.0f bps.\n", (info->mBytesRead*8)/readTime));
|
1999-06-29 10:54:05 +04:00
|
|
|
} else {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\tThroughput: REAL FAST!!\n"));
|
1999-06-29 10:54:05 +04:00
|
|
|
}
|
1999-06-27 15:02:40 +04:00
|
|
|
} else {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\nFinished loading: UNKNOWN URL. Status Code: %x\n", aStatus));
|
1999-06-27 15:02:40 +04:00
|
|
|
}
|
1999-06-25 11:52:12 +04:00
|
|
|
|
2001-02-21 23:38:08 +03:00
|
|
|
FireDecrement();
|
1999-05-21 10:29:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// NotificationCallbacks
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
class NotificationCallbacks : public nsIInterfaceRequestor {
|
1999-06-08 01:33:30 +04:00
|
|
|
public:
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
NotificationCallbacks() {
|
1999-06-16 13:40:40 +04:00
|
|
|
}
|
|
|
|
|
2003-11-18 05:20:34 +03:00
|
|
|
NS_IMETHOD GetInterface(const nsIID& iid, void* *result) {
|
1999-06-11 13:18:25 +04:00
|
|
|
nsresult rv = NS_ERROR_FAILURE;
|
|
|
|
|
2003-11-18 05:20:34 +03:00
|
|
|
if (iid.Equals(NS_GET_IID(nsIHttpEventSink))) {
|
2001-05-12 01:04:09 +04:00
|
|
|
TestHttpEventSink *sink;
|
1999-06-11 13:18:25 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
sink = new TestHttpEventSink();
|
1999-11-17 11:14:52 +03:00
|
|
|
if (sink == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(sink);
|
2003-11-18 05:20:34 +03:00
|
|
|
rv = sink->QueryInterface(iid, result);
|
1999-11-17 11:14:52 +03:00
|
|
|
NS_RELEASE(sink);
|
1999-06-08 01:33:30 +04:00
|
|
|
}
|
2003-11-18 05:20:34 +03: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 13:18:25 +04:00
|
|
|
return rv;
|
1999-06-08 01:33:30 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
NS_IMPL_ISUPPORTS1(NotificationCallbacks, nsIInterfaceRequestor)
|
1999-06-08 01:33:30 +04:00
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// helpers...
|
|
|
|
//-----------------------------------------------------------------------------
|
1999-05-21 10:29:13 +04:00
|
|
|
|
1999-06-17 11:46:00 +04:00
|
|
|
nsresult StartLoadingURL(const char* aUrlString)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2001-07-25 11:54:28 +04:00
|
|
|
nsCOMPtr<nsIIOService> pService(do_GetService(kIOServiceCID, &rv));
|
1999-06-17 11:46:00 +04:00
|
|
|
if (pService) {
|
|
|
|
nsCOMPtr<nsIURI> pURL;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = pService->NewURI(nsDependentCString(aUrlString), nsnull, nsnull, getter_AddRefs(pURL));
|
1999-06-17 11:46:00 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("ERROR: NewURI failed for %s [rv=%x]\n", aUrlString));
|
1999-06-17 11:46:00 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
nsCOMPtr<nsIChannel> pChannel;
|
|
|
|
|
2001-05-12 01:04:09 +04:00
|
|
|
NotificationCallbacks* callbacks = new NotificationCallbacks();
|
1999-11-17 11:14:52 +03:00
|
|
|
if (!callbacks) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("Failed to create a new consumer!"));
|
1999-06-17 11:46:00 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;;
|
|
|
|
}
|
1999-11-17 11:14:52 +03:00
|
|
|
NS_ADDREF(callbacks);
|
1999-06-17 11:46:00 +04:00
|
|
|
|
|
|
|
// Async reading thru the calls of the event sink interface
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = NS_NewChannel(getter_AddRefs(pChannel), pURL, pService,
|
|
|
|
nsnull, // loadGroup
|
|
|
|
callbacks); // notificationCallbacks
|
1999-11-17 11:14:52 +03:00
|
|
|
NS_RELEASE(callbacks);
|
1999-06-17 11:46:00 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("ERROR: NS_OpenURI failed for %s [rv=%x]\n", aUrlString, rv));
|
1999-06-17 11:46:00 +04:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
You may optionally add/set other headers on this
|
|
|
|
request object. This is done by QI for the specific
|
|
|
|
protocolConnection.
|
|
|
|
*/
|
2001-05-12 01:04:09 +04:00
|
|
|
nsCOMPtr<nsIHttpChannel> pHTTPCon(do_QueryInterface(pChannel));
|
1999-06-17 11:46:00 +04:00
|
|
|
|
|
|
|
if (pHTTPCon) {
|
1999-10-02 03:32:12 +04:00
|
|
|
// Setting a sample header.
|
2002-03-21 01:50:33 +03:00
|
|
|
rv = pHTTPCon->SetRequestHeader(NS_LITERAL_CSTRING("sample-header"),
|
2002-11-22 10:40:16 +03:00
|
|
|
NS_LITERAL_CSTRING("Sample-Value"),
|
|
|
|
PR_FALSE);
|
1999-06-17 11:46:00 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-10-02 03:32:12 +04:00
|
|
|
}
|
1999-06-17 11:46:00 +04: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 15:02:40 +04:00
|
|
|
URLLoadInfo* info;
|
|
|
|
info = new URLLoadInfo(aUrlString);
|
|
|
|
NS_IF_ADDREF(info);
|
|
|
|
if (!info) {
|
|
|
|
NS_ERROR("Failed to create a load info!");
|
1999-10-06 12:26:01 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-06-27 15:02:40 +04:00
|
|
|
}
|
2002-02-14 06:10:19 +03:00
|
|
|
|
|
|
|
if (gResume) {
|
|
|
|
nsCOMPtr<nsIResumableChannel> res = do_QueryInterface(pChannel);
|
|
|
|
if (!res) {
|
|
|
|
NS_ERROR("Channel is not resumable!");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2004-04-14 21:37:39 +04:00
|
|
|
nsCOMPtr<nsIResumableEntityID> id;
|
|
|
|
if (gETag || gLastMod || gTotalSize != PR_UINT32_MAX) {
|
|
|
|
id = do_CreateInstance(NS_RESUMABLEENTITYID_CONTRACTID);
|
|
|
|
if (!id) {
|
|
|
|
fprintf(stderr, "Error creating entityid\n");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (gETag)
|
|
|
|
id->SetEntityTag(nsDependentCString(gETag));
|
|
|
|
if (gLastMod)
|
|
|
|
id->SetLastModified(nsDependentCString(gLastMod));
|
|
|
|
id->SetSize(gTotalSize);
|
|
|
|
}
|
|
|
|
}
|
2002-02-14 06:10:19 +03:00
|
|
|
rv = res->AsyncOpenAt(listener,
|
|
|
|
info,
|
|
|
|
gStartAt,
|
2004-04-14 21:37:39 +04:00
|
|
|
id);
|
2002-02-14 06:10:19 +03:00
|
|
|
} else {
|
|
|
|
rv = pChannel->AsyncOpen(listener, // IStreamListener consumer
|
|
|
|
info);
|
|
|
|
}
|
2000-03-29 07:58:50 +04:00
|
|
|
|
1999-06-27 15:02:40 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
gKeepRunning += 1;
|
|
|
|
}
|
2003-01-18 05:15:14 +03:00
|
|
|
else {
|
|
|
|
LOG(("ERROR: AsyncOpen failed [rv=%x]\n", rv));
|
|
|
|
}
|
1999-06-17 11:46:00 +04:00
|
|
|
NS_RELEASE(listener);
|
1999-06-27 15:02:40 +04:00
|
|
|
NS_RELEASE(info);
|
1999-06-17 11:46:00 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1999-06-27 15:02:40 +04:00
|
|
|
|
|
|
|
nsresult LoadURLsFromFile(char *aFileName)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
PRInt32 len, offset;
|
|
|
|
PRFileDesc* fd;
|
|
|
|
char buffer[1024];
|
1999-08-29 21:42:34 +04:00
|
|
|
nsCString fileBuffer;
|
|
|
|
nsCAutoString urlString;
|
1999-06-27 15:02:40 +04: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...
|
1999-08-29 21:42:34 +04:00
|
|
|
while ((offset = fileBuffer.FindChar('\n')) != -1) {
|
1999-06-27 15:02:40 +04:00
|
|
|
fileBuffer.Left(urlString, offset);
|
|
|
|
fileBuffer.Cut(0, offset+1);
|
|
|
|
|
|
|
|
urlString.StripChars("\r");
|
|
|
|
if (urlString.Length()) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\t%s\n", urlString.get()));
|
2001-03-02 12:26:57 +03:00
|
|
|
rv = StartLoadingURL(urlString.get());
|
1999-06-27 15:02:40 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} while (len>0);
|
|
|
|
|
|
|
|
// If anything is left in the fileBuffer, treat it as a URL...
|
|
|
|
fileBuffer.StripChars("\r");
|
|
|
|
if (fileBuffer.Length()) {
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\t%s\n", fileBuffer.get()));
|
2001-03-02 12:26:57 +03:00
|
|
|
StartLoadingURL(fileBuffer.get());
|
1999-06-27 15:02:40 +04:00
|
|
|
}
|
2002-07-04 18:29:25 +04:00
|
|
|
|
1999-06-27 15:02:40 +04:00
|
|
|
PR_Close(fd);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-02-21 23:38:08 +03: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;
|
|
|
|
}
|
|
|
|
|
1999-05-21 10:29:13 +04:00
|
|
|
int
|
|
|
|
main(int argc, char* argv[])
|
|
|
|
{
|
1999-07-13 06:37:08 +04:00
|
|
|
nsresult rv= (nsresult)-1;
|
1999-05-21 10:29:13 +04:00
|
|
|
if (argc < 2) {
|
2004-04-14 21:37:39 +04:00
|
|
|
printf("usage: %s [-verbose] [-file <name>] [-resume <startoffset> [-etag <etag>] [-lastmod <lastmod (string)>] [-totalsize <size>] [-proxy <proxy>] [-console] <url> <url> ... \n", argv[0]);
|
1999-05-21 10:29:13 +04:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
#if defined(PR_LOGGING)
|
2003-11-18 05:20:34 +03:00
|
|
|
gTestLog = PR_NewLogModule("Test");
|
2003-01-18 05:15:14 +03:00
|
|
|
#endif
|
|
|
|
|
1999-05-21 10:29:13 +04:00
|
|
|
/*
|
1999-06-02 02:02:40 +04:00
|
|
|
The following code only deals with XPCOM registration stuff. and setting
|
|
|
|
up the event queues. Copied from TestSocketIO.cpp
|
1999-05-21 10:29:13 +04:00
|
|
|
*/
|
1999-06-02 02:02:40 +04:00
|
|
|
|
2001-10-16 07:35:52 +04:00
|
|
|
rv = NS_InitXPCOM2(nsnull, nsnull, nsnull);
|
1999-05-21 10:29:13 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-07-04 18:29:25 +04:00
|
|
|
{
|
|
|
|
// Create the Event Queue for this thread...
|
|
|
|
nsCOMPtr<nsIEventQueueService> eventQService =
|
|
|
|
do_GetService(kEventQueueServiceCID, &rv);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
eventQService->GetThreadEventQueue(NS_CURRENT_THREAD, &gEventQ);
|
|
|
|
|
|
|
|
int i;
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("Trying to load:\n"));
|
2002-07-04 18:29:25 +04: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;
|
|
|
|
gStartAt = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
1999-05-21 10:29:13 +04:00
|
|
|
|
2004-04-14 21:37:39 +04:00
|
|
|
if (PL_strcasecmp(argv[i], "-etag") == 0) {
|
|
|
|
gETag = argv[++i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PL_strcasecmp(argv[i], "-lastmod") == 0) {
|
|
|
|
gLastMod = argv[++i];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (PL_strcasecmp(argv[i], "-totalsize") == 0) {
|
|
|
|
gTotalSize = atoi(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-11-18 05:20:34 +03:00
|
|
|
if (PL_strcasecmp(argv[i], "-proxy") == 0) {
|
|
|
|
SetHttpProxy(argv[++i]);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2003-01-18 05:15:14 +03:00
|
|
|
LOG(("\t%s\n", argv[i]));
|
2002-07-04 18:29:25 +04:00
|
|
|
rv = StartLoadingURL(argv[i]);
|
2002-02-14 06:10:19 +03:00
|
|
|
}
|
2002-07-04 18:29:25 +04:00
|
|
|
// Enter the message pump to allow the URL load to proceed.
|
|
|
|
while ( gKeepRunning ) {
|
|
|
|
PLEvent *gEvent;
|
2003-04-04 20:01:51 +04:00
|
|
|
gEventQ->WaitForEvent(&gEvent);
|
|
|
|
gEventQ->HandleEvent(gEvent);
|
2002-07-04 18:29:25 +04:00
|
|
|
}
|
|
|
|
} // this scopes the nsCOMPtrs
|
|
|
|
// no nsCOMPtrs are allowed to be alive when you call NS_ShutdownXPCOM
|
2000-03-06 00:26:01 +03:00
|
|
|
NS_ShutdownXPCOM(nsnull);
|
1999-05-21 10:29:13 +04:00
|
|
|
return rv;
|
|
|
|
}
|