1998-09-20 09:56:41 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS"
|
|
|
|
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
|
|
|
* the License for the specific language governing rights and limitations
|
|
|
|
* under the License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Communicator client code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape Communications
|
|
|
|
* Corporation. Portions created by Netscape are Copyright (C) 1998
|
|
|
|
* Netscape Communications Corporation. All Rights Reserved.
|
|
|
|
*/
|
|
|
|
|
1998-09-16 04:35:32 +04:00
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsILoadAttribs.h"
|
|
|
|
#include "prtypes.h"
|
1999-01-09 04:16:40 +03:00
|
|
|
#include "prmem.h"
|
|
|
|
#include "plstr.h"
|
1998-09-16 04:35:32 +04:00
|
|
|
|
1998-10-06 10:17:25 +04:00
|
|
|
#if defined(XP_PC)
|
|
|
|
#include <windows.h> // Needed for Interlocked APIs defined in nsISupports.h
|
|
|
|
#endif /* XP_PC */
|
|
|
|
|
1998-09-16 04:35:32 +04:00
|
|
|
|
|
|
|
// nsLoadAttribs definition.
|
|
|
|
class nsLoadAttribs : public nsILoadAttribs {
|
|
|
|
public:
|
1998-10-10 08:32:18 +04:00
|
|
|
nsLoadAttribs();
|
1998-09-16 04:35:32 +04:00
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
1998-09-16 04:35:32 +04:00
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
// nsILoadAttribs
|
|
|
|
NS_IMETHOD Clone(nsILoadAttribs* aLoadAttribs);
|
|
|
|
|
|
|
|
NS_IMETHOD SetBypassProxy(PRBool aBypass);
|
|
|
|
NS_IMETHOD GetBypassProxy(PRBool *aBypass);
|
|
|
|
|
|
|
|
NS_IMETHOD SetLocalIP(const PRUint32 aIP);
|
|
|
|
NS_IMETHOD GetLocalIP(PRUint32 *aIP);
|
|
|
|
|
|
|
|
NS_IMETHOD SetReloadType(nsURLReloadType aType);
|
|
|
|
NS_IMETHOD GetReloadType(nsURLReloadType* aResult);
|
|
|
|
|
|
|
|
NS_IMETHOD SetLoadType(nsURLLoadType aType);
|
|
|
|
NS_IMETHOD GetLoadType(nsURLLoadType* aResult);
|
1998-09-16 04:35:32 +04:00
|
|
|
|
1999-01-09 04:16:40 +03:00
|
|
|
// Byte Range Support
|
|
|
|
NS_IMETHOD SetByteRangeHeader(const char *aByteRangeHeader);
|
|
|
|
NS_IMETHOD GetByteRangeHeader(char** aByteRangeHeader);
|
|
|
|
|
1998-10-02 01:37:32 +04:00
|
|
|
protected:
|
|
|
|
virtual ~nsLoadAttribs();
|
|
|
|
|
1998-09-16 04:35:32 +04:00
|
|
|
private:
|
1998-10-10 08:32:18 +04:00
|
|
|
PRBool mBypass;
|
|
|
|
PRUint32 mLocalIP;
|
|
|
|
nsURLLoadType mLoadType;
|
|
|
|
nsURLReloadType mReloadType;
|
1999-01-09 04:16:40 +03:00
|
|
|
char* mByteRangeHeader;
|
1998-09-16 04:35:32 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
// nsLoadAttribs Implementation
|
|
|
|
|
1998-09-20 09:56:41 +04:00
|
|
|
static NS_DEFINE_IID(kILoadAttribsIID, NS_ILOAD_ATTRIBS_IID);
|
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS(nsLoadAttribs, kILoadAttribsIID);
|
1998-09-16 04:35:32 +04:00
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
nsLoadAttribs::nsLoadAttribs()
|
|
|
|
{
|
1998-10-02 01:37:32 +04:00
|
|
|
NS_INIT_REFCNT();
|
1998-10-10 08:32:18 +04:00
|
|
|
|
|
|
|
mBypass = PR_FALSE;
|
|
|
|
mLocalIP = 0;
|
|
|
|
mLoadType = nsURLLoadNormal;
|
|
|
|
mReloadType = nsURLReload;
|
1999-01-13 10:17:39 +03:00
|
|
|
mByteRangeHeader = nsnull;
|
1998-09-16 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
nsLoadAttribs::~nsLoadAttribs()
|
|
|
|
{
|
1999-01-09 04:16:40 +03:00
|
|
|
PR_FREEIF(mByteRangeHeader);
|
1998-09-16 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
1998-10-02 01:37:32 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLoadAttribs::Clone(nsILoadAttribs* aLoadAttribs)
|
|
|
|
{
|
1998-10-10 08:32:18 +04:00
|
|
|
nsresult rv = NS_OK;
|
1998-10-02 01:37:32 +04:00
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
if (nsnull == aLoadAttribs) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
|
|
|
|
aLoadAttribs->GetBypassProxy(&mBypass);
|
|
|
|
aLoadAttribs->GetLocalIP(&mLocalIP);
|
|
|
|
aLoadAttribs->GetReloadType(&mReloadType);
|
1998-10-02 01:37:32 +04:00
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
}
|
|
|
|
return rv;
|
1998-10-02 01:37:32 +04:00
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
}
|
1998-10-02 01:37:32 +04:00
|
|
|
|
1998-10-10 08:32:18 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLoadAttribs::SetBypassProxy(PRBool aBypass)
|
|
|
|
{
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
mBypass = aBypass;
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
return NS_OK;
|
1998-10-02 01:37:32 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1998-10-10 08:32:18 +04:00
|
|
|
nsLoadAttribs::GetBypassProxy(PRBool *aBypass)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aBypass) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
1998-09-20 09:56:41 +04:00
|
|
|
NS_LOCK_INSTANCE();
|
1998-10-10 08:32:18 +04:00
|
|
|
*aBypass = mBypass;
|
1998-09-20 09:56:41 +04:00
|
|
|
NS_UNLOCK_INSTANCE();
|
1998-10-10 08:32:18 +04:00
|
|
|
}
|
|
|
|
return rv;
|
1998-09-16 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
1998-10-02 01:37:32 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-10 08:32:18 +04:00
|
|
|
nsLoadAttribs::SetLocalIP(const PRUint32 aLocalIP)
|
|
|
|
{
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
mLocalIP = aLocalIP;
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
return NS_OK;
|
1998-09-16 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
1998-10-02 01:37:32 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-10 08:32:18 +04:00
|
|
|
nsLoadAttribs::GetLocalIP(PRUint32 *aLocalIP)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aLocalIP) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
1998-09-20 09:56:41 +04:00
|
|
|
NS_LOCK_INSTANCE();
|
1998-10-10 08:32:18 +04:00
|
|
|
*aLocalIP = mLocalIP;
|
1998-09-20 09:56:41 +04:00
|
|
|
NS_UNLOCK_INSTANCE();
|
1998-10-10 08:32:18 +04:00
|
|
|
}
|
|
|
|
return rv;
|
1998-09-16 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
1998-10-02 01:37:32 +04:00
|
|
|
NS_IMETHODIMP
|
1998-10-10 08:32:18 +04:00
|
|
|
nsLoadAttribs::SetReloadType(nsURLReloadType aType)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if ((aType < nsURLReload) || (aType >= nsURLReloadMax)) {
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
} else {
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
mReloadType = aType;
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLoadAttribs::GetReloadType(nsURLReloadType* aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
*aResult = mReloadType;
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLoadAttribs::SetLoadType(nsURLLoadType aType)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if ((aType < nsURLLoadNormal) || (aType >= nsURLLoadMax)) {
|
|
|
|
rv = NS_ERROR_ILLEGAL_VALUE;
|
|
|
|
} else {
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
mLoadType = aType;
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLoadAttribs::GetLoadType(nsURLLoadType* aResult)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
|
|
|
if (nsnull == aResult) {
|
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
|
|
|
} else {
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
*aResult = mLoadType;
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
}
|
|
|
|
return rv;
|
1998-09-16 04:35:32 +04:00
|
|
|
}
|
|
|
|
|
1999-01-09 04:16:40 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLoadAttribs::SetByteRangeHeader(const char* aByteRangeHeader)
|
|
|
|
{
|
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
|
1999-01-13 10:17:39 +03:00
|
|
|
// Free the old range header if any...
|
|
|
|
PR_FREEIF(mByteRangeHeader);
|
|
|
|
mByteRangeHeader = nsnull;
|
|
|
|
|
|
|
|
if (nsnull != aByteRangeHeader) {
|
|
|
|
mByteRangeHeader = PL_strdup(aByteRangeHeader);
|
|
|
|
}
|
1999-01-09 04:16:40 +03:00
|
|
|
|
|
|
|
NS_UNLOCK_INSTANCE();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsLoadAttribs::GetByteRangeHeader(char **aByteRangeHeader)
|
|
|
|
{
|
|
|
|
nsresult rv = NS_OK;
|
|
|
|
|
1999-01-13 10:17:39 +03:00
|
|
|
NS_LOCK_INSTANCE();
|
|
|
|
|
|
|
|
if (nsnull == aByteRangeHeader) {
|
1999-01-09 04:16:40 +03:00
|
|
|
rv = NS_ERROR_NULL_POINTER;
|
1999-01-13 10:17:39 +03:00
|
|
|
} else if (nsnull != mByteRangeHeader) {
|
1999-01-09 04:16:40 +03:00
|
|
|
*aByteRangeHeader = PL_strdup(mByteRangeHeader);
|
1999-01-13 10:17:39 +03:00
|
|
|
} else {
|
|
|
|
*aByteRangeHeader = nsnull;
|
1999-01-09 04:16:40 +03:00
|
|
|
}
|
1999-01-13 10:17:39 +03:00
|
|
|
|
|
|
|
NS_UNLOCK_INSTANCE();
|
1999-01-09 04:16:40 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
1998-09-16 04:35:32 +04:00
|
|
|
// Creation routines
|
|
|
|
NS_NET nsresult NS_NewLoadAttribs(nsILoadAttribs** aInstancePtrResult) {
|
1998-10-02 01:37:32 +04:00
|
|
|
nsILoadAttribs* it;
|
|
|
|
|
|
|
|
NS_NEWXPCOM(it, nsLoadAttribs);
|
1998-09-16 04:35:32 +04:00
|
|
|
if (nsnull == it) {
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
1998-09-20 09:56:41 +04:00
|
|
|
return it->QueryInterface(kILoadAttribsIID, (void **) aInstancePtrResult);
|
1999-03-30 05:48:20 +04:00
|
|
|
}
|