2001-11-16 05:09:13 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2004-06-10 01:41:28 +04:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cindent: */
|
2012-05-21 15:12:37 +04:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2010-04-09 10:26:36 +04:00
|
|
|
#include "IPCMessageUtils.h"
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
#include "nsStandardURL.h"
|
|
|
|
#include "nsCRT.h"
|
|
|
|
#include "nsEscape.h"
|
2012-06-06 06:08:30 +04:00
|
|
|
#include "nsIFile.h"
|
2001-11-16 05:09:13 +03:00
|
|
|
#include "nsIObjectInputStream.h"
|
|
|
|
#include "nsIObjectOutputStream.h"
|
2002-03-06 10:48:55 +03:00
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
|
|
|
#include "nsIIDNService.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
2004-12-03 07:19:48 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2013-09-22 07:04:57 +04:00
|
|
|
#include "nsIURLParser.h"
|
|
|
|
#include "nsNetCID.h"
|
2013-06-23 16:03:39 +04:00
|
|
|
#include "mozilla/MemoryReporting.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
#include "mozilla/ipc/URIUtils.h"
|
2013-01-15 16:22:03 +04:00
|
|
|
#include <algorithm>
|
2014-05-08 13:32:00 +04:00
|
|
|
#include "mozilla/dom/EncodingUtils.h"
|
2015-01-13 03:11:02 +03:00
|
|
|
#include "nsContentUtils.h"
|
2012-08-23 23:33:46 +04:00
|
|
|
|
2014-05-08 13:32:00 +04:00
|
|
|
using mozilla::dom::EncodingUtils;
|
2012-08-23 23:33:46 +04:00
|
|
|
using namespace mozilla::ipc;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-05-19 05:02:57 +03:00
|
|
|
namespace mozilla {
|
|
|
|
namespace net {
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
static NS_DEFINE_CID(kThisImplCID, NS_THIS_STANDARDURL_IMPL_CID);
|
2002-05-03 07:01:32 +04:00
|
|
|
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
nsIIDNService *nsStandardURL::gIDN = nullptr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsStandardURL::gInitialized = false;
|
|
|
|
bool nsStandardURL::gEscapeUTF8 = true;
|
|
|
|
bool nsStandardURL::gAlwaysEncodeInUTF8 = true;
|
2014-06-10 15:53:54 +04:00
|
|
|
char nsStandardURL::gHostLimitDigits[] = { '/', '\\', '?', '#', 0 };
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
//
|
2016-05-26 02:13:54 +03:00
|
|
|
// setenv MOZ_LOG nsStandardURL:5
|
2001-11-16 05:09:13 +03:00
|
|
|
//
|
2016-05-19 05:02:57 +03:00
|
|
|
static LazyLogModule gStandardURLLog("nsStandardURL");
|
2010-04-09 10:26:36 +04:00
|
|
|
|
|
|
|
// The Chromium code defines its own LOG macro which we don't want
|
|
|
|
#undef LOG
|
2016-05-19 05:02:57 +03:00
|
|
|
#define LOG(args) MOZ_LOG(gStandardURLLog, LogLevel::Debug, args)
|
2013-11-21 02:55:44 +04:00
|
|
|
#undef LOG_ENABLED
|
2016-05-19 05:02:57 +03:00
|
|
|
#define LOG_ENABLED() MOZ_LOG_TEST(gStandardURLLog, LogLevel::Debug)
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2001-11-27 02:28:44 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
#define ENSURE_MUTABLE() \
|
|
|
|
PR_BEGIN_MACRO \
|
|
|
|
if (!mMutable) { \
|
2011-01-21 06:49:09 +03:00
|
|
|
NS_WARNING("attempt to modify an immutable nsStandardURL"); \
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_ERROR_ABORT; \
|
|
|
|
} \
|
|
|
|
PR_END_MACRO
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static nsresult
|
|
|
|
EncodeString(nsIUnicodeEncoder *encoder, const nsAFlatString &str, nsACString &result)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t len = str.Length();
|
|
|
|
int32_t maxlen;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
rv = encoder->GetMaxLength(str.get(), len, &maxlen);
|
2002-04-30 05:13:54 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
char buf[256], *p = buf;
|
2012-08-22 19:56:38 +04:00
|
|
|
if (uint32_t(maxlen) > sizeof(buf) - 1) {
|
2002-03-06 10:48:55 +03:00
|
|
|
p = (char *) malloc(maxlen + 1);
|
2002-04-30 05:13:54 +04:00
|
|
|
if (!p)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
rv = encoder->Convert(str.get(), &len, p, &maxlen);
|
2002-04-30 05:13:54 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto end;
|
|
|
|
if (rv == NS_ERROR_UENC_NOMAPPING) {
|
|
|
|
NS_WARNING("unicode conversion failed");
|
|
|
|
rv = NS_ERROR_UNEXPECTED;
|
|
|
|
goto end;
|
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
p[maxlen] = 0;
|
2008-08-15 18:56:22 +04:00
|
|
|
result.Assign(p);
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2008-08-15 18:56:22 +04:00
|
|
|
len = sizeof(buf) - 1;
|
|
|
|
rv = encoder->Finish(buf, &len);
|
2002-04-30 05:13:54 +04:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
goto end;
|
2008-08-15 18:56:22 +04:00
|
|
|
buf[len] = 0;
|
|
|
|
result.Append(buf);
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
end:
|
2002-04-30 05:13:54 +04:00
|
|
|
encoder->Reset();
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (p != buf)
|
|
|
|
free(p);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsPrefObserver
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2004-03-26 15:28:38 +03:00
|
|
|
#define NS_NET_PREF_ESCAPEUTF8 "network.standard-url.escape-utf8"
|
|
|
|
#define NS_NET_PREF_ALWAYSENCODEINUTF8 "network.standard-url.encode-utf8"
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(nsStandardURL::nsPrefObserver, nsIObserver)
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP nsStandardURL::
|
|
|
|
nsPrefObserver::Observe(nsISupports *subject,
|
|
|
|
const char *topic,
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *data)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
if (!strcmp(topic, NS_PREFBRANCH_PREFCHANGE_TOPIC_ID)) {
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch( do_QueryInterface(subject) );
|
|
|
|
if (prefBranch) {
|
2004-12-07 16:21:32 +03:00
|
|
|
PrefsChanged(prefBranch, NS_ConvertUTF16toUTF8(data).get());
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsSegmentEncoder
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsStandardURL::
|
|
|
|
nsSegmentEncoder::nsSegmentEncoder(const char *charset)
|
2003-07-13 03:06:13 +04:00
|
|
|
: mCharset(charset)
|
2001-11-27 02:28:44 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t nsStandardURL::
|
2002-03-06 10:48:55 +03:00
|
|
|
nsSegmentEncoder::EncodeSegmentCount(const char *str,
|
|
|
|
const URLSegment &seg,
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t mask,
|
2005-09-13 21:38:20 +04:00
|
|
|
nsAFlatCString &result,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool &appended,
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t extraLen)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
2011-06-07 20:17:40 +04:00
|
|
|
// extraLen is characters outside the segment that will be
|
|
|
|
// added when the segment is not empty (like the @ following
|
|
|
|
// a username).
|
2011-10-17 18:59:28 +04:00
|
|
|
appended = false;
|
2002-03-06 10:48:55 +03:00
|
|
|
if (!str)
|
|
|
|
return 0;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t len = 0;
|
2002-03-06 10:48:55 +03:00
|
|
|
if (seg.mLen > 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t pos = seg.mPos;
|
2002-03-06 10:48:55 +03:00
|
|
|
len = seg.mLen;
|
|
|
|
|
|
|
|
// first honor the origin charset if appropriate. as an optimization,
|
2003-07-13 03:06:13 +04:00
|
|
|
// only do this if the segment is non-ASCII. Further, if mCharset is
|
|
|
|
// null or the empty string then the origin charset is UTF-8 and there
|
|
|
|
// is nothing to do.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString encBuf;
|
2005-01-13 00:45:42 +03:00
|
|
|
if (mCharset && *mCharset && !nsCRT::IsAscii(str + pos, len)) {
|
2003-07-13 03:06:13 +04:00
|
|
|
// we have to encode this segment
|
|
|
|
if (mEncoder || InitUnicodeEncoder()) {
|
2006-02-03 17:18:39 +03:00
|
|
|
NS_ConvertUTF8toUTF16 ucsBuf(Substring(str + pos, str + pos + len));
|
2003-07-13 03:06:13 +04:00
|
|
|
if (NS_SUCCEEDED(EncodeString(mEncoder, ucsBuf, encBuf))) {
|
|
|
|
str = encBuf.get();
|
|
|
|
pos = 0;
|
|
|
|
len = encBuf.Length();
|
|
|
|
}
|
2010-05-13 16:19:50 +04:00
|
|
|
// else some failure occurred... assume UTF-8 is ok.
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// escape per RFC2396 unless UTF-8 and allowed by preferences
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t escapeFlags = (gEscapeUTF8 || mEncoder) ? 0 : esc_OnlyASCII;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t initLen = result.Length();
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
// now perform any required escaping
|
2005-09-13 21:38:20 +04:00
|
|
|
if (NS_EscapeURL(str + pos, len, mask | escapeFlags, result)) {
|
2002-03-06 10:48:55 +03:00
|
|
|
len = result.Length() - initLen;
|
2011-10-17 18:59:28 +04:00
|
|
|
appended = true;
|
2005-09-13 21:38:20 +04:00
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
else if (str == encBuf.get()) {
|
|
|
|
result += encBuf; // append only!!
|
|
|
|
len = encBuf.Length();
|
2011-10-17 18:59:28 +04:00
|
|
|
appended = true;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
2011-06-07 20:17:40 +04:00
|
|
|
len += extraLen;
|
2001-11-27 02:28:44 +03:00
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
const nsACString &nsStandardURL::
|
|
|
|
nsSegmentEncoder::EncodeSegment(const nsASingleFragmentCString &str,
|
2012-08-22 19:56:38 +04:00
|
|
|
int16_t mask,
|
2002-03-06 10:48:55 +03:00
|
|
|
nsAFlatCString &result)
|
|
|
|
{
|
|
|
|
const char *text;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool encoded;
|
2005-09-13 21:38:20 +04:00
|
|
|
EncodeSegmentCount(str.BeginReading(text), URLSegment(0, str.Length()), mask, result, encoded);
|
|
|
|
if (encoded)
|
2002-03-06 10:48:55 +03:00
|
|
|
return result;
|
2005-09-13 21:38:20 +04:00
|
|
|
return str;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool nsStandardURL::
|
2003-07-13 03:06:13 +04:00
|
|
|
nsSegmentEncoder::InitUnicodeEncoder()
|
|
|
|
{
|
|
|
|
NS_ASSERTION(!mEncoder, "Don't call this if we have an encoder already!");
|
2014-05-08 13:32:00 +04:00
|
|
|
// "replacement" won't survive another label resolution
|
|
|
|
nsDependentCString label(mCharset);
|
|
|
|
if (label.EqualsLiteral("replacement")) {
|
|
|
|
mEncoder = EncodingUtils::EncoderForEncoding(label);
|
|
|
|
return true;
|
2003-07-13 03:06:13 +04:00
|
|
|
}
|
2014-05-08 13:32:00 +04:00
|
|
|
nsAutoCString encoding;
|
|
|
|
if (!EncodingUtils::FindEncodingForLabelNoReplacement(label, encoding)) {
|
|
|
|
return false;
|
2003-07-13 03:06:13 +04:00
|
|
|
}
|
2014-05-08 13:32:00 +04:00
|
|
|
mEncoder = EncodingUtils::EncoderForEncoding(encoding);
|
2011-10-17 18:59:28 +04:00
|
|
|
return true;
|
2003-07-13 03:06:13 +04:00
|
|
|
}
|
|
|
|
|
2006-04-13 18:44:38 +04:00
|
|
|
#define GET_SEGMENT_ENCODER_INTERNAL(name, useUTF8) \
|
2012-07-30 18:20:58 +04:00
|
|
|
nsSegmentEncoder name(useUTF8 ? nullptr : mOriginCharset.get())
|
2006-04-13 18:44:38 +04:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
#define GET_SEGMENT_ENCODER(name) \
|
2006-04-13 18:44:38 +04:00
|
|
|
GET_SEGMENT_ENCODER_INTERNAL(name, gAlwaysEncodeInUTF8)
|
|
|
|
|
|
|
|
#define GET_QUERY_ENCODER(name) \
|
2011-11-09 19:02:14 +04:00
|
|
|
GET_SEGMENT_ENCODER_INTERNAL(name, false)
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL <public>
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2009-06-10 16:51:03 +04:00
|
|
|
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
|
|
|
|
static PRCList gAllURLs;
|
|
|
|
#endif
|
|
|
|
|
2014-08-09 07:59:00 +04:00
|
|
|
nsStandardURL::nsStandardURL(bool aSupportsFileURL, bool aTrackURL)
|
2001-11-16 05:09:13 +03:00
|
|
|
: mDefaultPort(-1)
|
|
|
|
, mPort(-1)
|
2012-07-30 18:20:58 +04:00
|
|
|
, mHostA(nullptr)
|
2004-04-03 11:32:18 +04:00
|
|
|
, mHostEncoding(eEncoding_ASCII)
|
2002-03-06 10:48:55 +03:00
|
|
|
, mSpecEncoding(eEncoding_Unknown)
|
2004-05-11 22:58:58 +04:00
|
|
|
, mURLType(URLTYPE_STANDARD)
|
2011-10-17 18:59:28 +04:00
|
|
|
, mMutable(true)
|
2002-10-06 06:20:35 +04:00
|
|
|
, mSupportsFileURL(aSupportsFileURL)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
LOG(("Creating nsStandardURL @%p\n", this));
|
|
|
|
|
|
|
|
if (!gInitialized) {
|
2011-10-17 18:59:28 +04:00
|
|
|
gInitialized = true;
|
2001-11-16 05:09:13 +03:00
|
|
|
InitGlobalObjects();
|
|
|
|
}
|
|
|
|
|
|
|
|
// default parser in case nsIStandardURL::Init is never called
|
2002-09-13 23:32:45 +04:00
|
|
|
mParser = net_GetStdURLParser();
|
2009-06-10 16:51:03 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
|
2016-05-30 13:51:45 +03:00
|
|
|
memset(&mDebugCList, 0, sizeof(mDebugCList));
|
2015-03-31 14:19:27 +03:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
if (aTrackURL) {
|
|
|
|
PR_APPEND_LINK(&mDebugCList, &gAllURLs);
|
|
|
|
} else {
|
|
|
|
PR_INIT_CLIST(&mDebugCList);
|
|
|
|
}
|
2014-08-09 07:59:00 +04:00
|
|
|
}
|
2009-06-10 16:51:03 +04:00
|
|
|
#endif
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsStandardURL::~nsStandardURL()
|
|
|
|
{
|
|
|
|
LOG(("Destroying nsStandardURL @%p\n", this));
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2013-08-22 14:31:48 +04:00
|
|
|
if (mHostA) {
|
|
|
|
free(mHostA);
|
|
|
|
}
|
2009-06-10 16:51:03 +04:00
|
|
|
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
|
2015-03-31 14:19:27 +03:00
|
|
|
if (NS_IsMainThread()) {
|
|
|
|
if (!PR_CLIST_IS_EMPTY(&mDebugCList)) {
|
|
|
|
PR_REMOVE_LINK(&mDebugCList);
|
|
|
|
}
|
2014-08-09 07:59:00 +04:00
|
|
|
}
|
2009-06-10 16:51:03 +04:00
|
|
|
#endif
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2009-06-10 16:51:03 +04:00
|
|
|
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
|
2011-06-15 09:32:03 +04:00
|
|
|
struct DumpLeakedURLs {
|
|
|
|
DumpLeakedURLs() {}
|
|
|
|
~DumpLeakedURLs();
|
|
|
|
};
|
|
|
|
|
|
|
|
DumpLeakedURLs::~DumpLeakedURLs()
|
2009-06-10 16:51:03 +04:00
|
|
|
{
|
2015-03-31 14:19:27 +03:00
|
|
|
MOZ_ASSERT(NS_IsMainThread());
|
2009-06-10 16:51:03 +04:00
|
|
|
if (!PR_CLIST_IS_EMPTY(&gAllURLs)) {
|
|
|
|
printf("Leaked URLs:\n");
|
|
|
|
for (PRCList *l = PR_LIST_HEAD(&gAllURLs); l != &gAllURLs; l = PR_NEXT_LINK(l)) {
|
|
|
|
nsStandardURL *url = reinterpret_cast<nsStandardURL*>(reinterpret_cast<char*>(l) - offsetof(nsStandardURL, mDebugCList));
|
|
|
|
url->PrintSpec();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
void
|
|
|
|
nsStandardURL::InitGlobalObjects()
|
|
|
|
{
|
2012-01-17 05:48:29 +04:00
|
|
|
nsCOMPtr<nsIPrefBranch> prefBranch( do_GetService(NS_PREFSERVICE_CONTRACTID) );
|
2004-01-29 02:45:17 +03:00
|
|
|
if (prefBranch) {
|
|
|
|
nsCOMPtr<nsIObserver> obs( new nsPrefObserver() );
|
2011-10-17 18:59:28 +04:00
|
|
|
prefBranch->AddObserver(NS_NET_PREF_ESCAPEUTF8, obs.get(), false);
|
|
|
|
prefBranch->AddObserver(NS_NET_PREF_ALWAYSENCODEINUTF8, obs.get(), false);
|
2004-12-07 16:21:32 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
PrefsChanged(prefBranch, nullptr);
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
2009-06-10 16:51:03 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
|
|
|
|
PR_INIT_CLIST(&gAllURLs);
|
|
|
|
#endif
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStandardURL::ShutdownGlobalObjects()
|
|
|
|
{
|
2005-04-27 05:32:36 +04:00
|
|
|
NS_IF_RELEASE(gIDN);
|
2010-05-13 06:34:38 +04:00
|
|
|
|
|
|
|
#ifdef DEBUG_DUMP_URLS_AT_SHUTDOWN
|
2011-06-15 09:32:03 +04:00
|
|
|
if (gInitialized) {
|
|
|
|
// This instanciates a dummy class, and will trigger the class
|
|
|
|
// destructor when libxul is unloaded. This is equivalent to atexit(),
|
|
|
|
// but gracefully handles dlclose().
|
|
|
|
static DumpLeakedURLs d;
|
|
|
|
}
|
2010-05-13 06:34:38 +04:00
|
|
|
#endif
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL <private>
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStandardURL::Clear()
|
|
|
|
{
|
|
|
|
mSpec.Truncate();
|
|
|
|
|
|
|
|
mPort = -1;
|
|
|
|
|
2014-02-04 20:55:02 +04:00
|
|
|
mScheme.Reset();
|
2001-11-16 05:09:13 +03:00
|
|
|
mAuthority.Reset();
|
|
|
|
mUsername.Reset();
|
|
|
|
mPassword.Reset();
|
2002-03-06 10:48:55 +03:00
|
|
|
mHost.Reset();
|
2004-04-03 11:32:18 +04:00
|
|
|
mHostEncoding = eEncoding_ASCII;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
mPath.Reset();
|
2002-03-06 10:48:55 +03:00
|
|
|
mFilepath.Reset();
|
2001-11-16 05:09:13 +03:00
|
|
|
mDirectory.Reset();
|
|
|
|
mBasename.Reset();
|
|
|
|
|
|
|
|
mExtension.Reset();
|
|
|
|
mQuery.Reset();
|
|
|
|
mRef.Reset();
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
void
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStandardURL::InvalidateCache(bool invalidateCachedFile)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
if (invalidateCachedFile)
|
|
|
|
mFile = 0;
|
2013-08-22 14:31:48 +04:00
|
|
|
if (mHostA) {
|
|
|
|
free(mHostA);
|
|
|
|
mHostA = nullptr;
|
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
mSpecEncoding = eEncoding_Unknown;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2015-11-18 17:25:27 +03:00
|
|
|
nsresult
|
2004-06-10 01:41:28 +04:00
|
|
|
nsStandardURL::NormalizeIDN(const nsCSubstring &host, nsCString &result)
|
|
|
|
{
|
|
|
|
// If host is ACE, then convert to UTF-8. Else, if host is already UTF-8,
|
|
|
|
// then make sure it is normalized per IDN.
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
// this function returns true if normalization succeeds.
|
2004-06-10 01:41:28 +04:00
|
|
|
|
|
|
|
// NOTE: As a side-effect this function sets mHostEncoding. While it would
|
|
|
|
// be nice to avoid side-effects in this function, the implementation of
|
|
|
|
// this function is already somewhat bound to the behavior of the
|
|
|
|
// callsites. Anyways, this function exists to avoid code duplication, so
|
|
|
|
// side-effects abound :-/
|
|
|
|
|
|
|
|
NS_ASSERTION(mHostEncoding == eEncoding_ASCII, "unexpected default encoding");
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isASCII;
|
2013-03-03 20:36:37 +04:00
|
|
|
if (!gIDN) {
|
|
|
|
nsCOMPtr<nsIIDNService> serv(do_GetService(NS_IDNSERVICE_CONTRACTID));
|
|
|
|
if (serv) {
|
|
|
|
NS_ADDREF(gIDN = serv.get());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-18 17:25:27 +03:00
|
|
|
result.Truncate();
|
|
|
|
nsresult rv = NS_ERROR_UNEXPECTED;
|
|
|
|
if (gIDN) {
|
|
|
|
rv = gIDN->ConvertToDisplayIDN(host, &isASCII, result);
|
|
|
|
if (NS_SUCCEEDED(rv) && !isASCII) {
|
2007-12-04 09:30:47 +03:00
|
|
|
mHostEncoding = eEncoding_UTF8;
|
2015-11-18 17:25:27 +03:00
|
|
|
}
|
2004-06-10 01:41:28 +04:00
|
|
|
}
|
|
|
|
|
2015-11-18 17:25:27 +03:00
|
|
|
return rv;
|
2004-06-10 01:41:28 +04:00
|
|
|
}
|
|
|
|
|
2014-05-02 07:31:43 +04:00
|
|
|
bool
|
2015-09-03 22:15:30 +03:00
|
|
|
nsStandardURL::ValidIPv6orHostname(const char *host, uint32_t length)
|
2014-05-02 07:31:43 +04:00
|
|
|
{
|
2015-10-20 12:47:12 +03:00
|
|
|
if (!host || !*host) {
|
|
|
|
// Should not be NULL or empty string
|
2014-05-02 07:31:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:15:30 +03:00
|
|
|
if (length != strlen(host)) {
|
|
|
|
// Embedded null
|
|
|
|
return false;
|
|
|
|
}
|
2014-05-02 07:31:43 +04:00
|
|
|
|
|
|
|
bool openBracket = host[0] == '[';
|
|
|
|
bool closeBracket = host[length - 1] == ']';
|
|
|
|
|
|
|
|
if (openBracket && closeBracket) {
|
|
|
|
return net_IsValidIPv6Addr(host + 1, length - 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (openBracket || closeBracket) {
|
|
|
|
// Fail if only one of the brackets is present
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2015-09-03 22:15:30 +03:00
|
|
|
const char *end = host + length;
|
|
|
|
if (end != net_FindCharInSet(host, end, "\t\n\v\f\r #/:?@[\\]")) {
|
2015-11-18 17:25:27 +03:00
|
|
|
// We still allow % because it is in the ID of addons.
|
|
|
|
// Any percent encoded ASCII characters that are not allowed in the
|
|
|
|
// hostname are not percent decoded, and will be parsed just fine.
|
2014-05-02 07:31:43 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
void
|
2003-07-16 23:09:00 +04:00
|
|
|
nsStandardURL::CoalescePath(netCoalesceFlags coalesceFlag, char *path)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2003-07-16 23:09:00 +04:00
|
|
|
net_CoalesceDirs(coalesceFlag, path);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t newLen = strlen(path);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (newLen < mPath.mLen) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t diff = newLen - mPath.mLen;
|
2001-11-16 05:09:13 +03:00
|
|
|
mPath.mLen = newLen;
|
|
|
|
mDirectory.mLen += diff;
|
2002-03-06 10:48:55 +03:00
|
|
|
mFilepath.mLen += diff;
|
2001-11-16 05:09:13 +03:00
|
|
|
ShiftFromBasename(diff);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
2016-05-10 11:52:19 +03:00
|
|
|
nsStandardURL::AppendSegmentToBuf(char *buf, uint32_t i, const char *str,
|
|
|
|
const URLSegment &segInput, URLSegment &segOutput,
|
|
|
|
const nsCString *escapedStr,
|
|
|
|
bool useEscaped, int32_t *diff)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2016-05-10 11:52:19 +03:00
|
|
|
MOZ_ASSERT(segInput.mLen == segOutput.mLen);
|
|
|
|
|
|
|
|
if (diff) *diff = 0;
|
|
|
|
|
|
|
|
if (segInput.mLen > 0) {
|
2005-09-13 21:38:20 +04:00
|
|
|
if (useEscaped) {
|
2016-05-10 11:52:19 +03:00
|
|
|
MOZ_ASSERT(diff);
|
|
|
|
segOutput.mLen = escapedStr->Length();
|
|
|
|
*diff = segOutput.mLen - segInput.mLen;
|
|
|
|
memcpy(buf + i, escapedStr->get(), segOutput.mLen);
|
|
|
|
} else {
|
|
|
|
memcpy(buf + i, str + segInput.mPos, segInput.mLen);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
2016-05-10 11:52:19 +03:00
|
|
|
segOutput.mPos = i;
|
|
|
|
i += segOutput.mLen;
|
2011-07-12 22:07:24 +04:00
|
|
|
} else {
|
2016-05-10 11:52:19 +03:00
|
|
|
segOutput.mPos = i;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t
|
|
|
|
nsStandardURL::AppendToBuf(char *buf, uint32_t i, const char *str, uint32_t len)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
memcpy(buf + i, str, len);
|
|
|
|
return i + len;
|
|
|
|
}
|
|
|
|
|
|
|
|
// basic algorithm:
|
|
|
|
// 1- escape url segments (for improved GetSpec efficiency)
|
|
|
|
// 2- allocate spec buffer
|
|
|
|
// 3- write url segments
|
|
|
|
// 4- update url segment positions and lengths
|
|
|
|
nsresult
|
|
|
|
nsStandardURL::BuildNormalizedSpec(const char *spec)
|
|
|
|
{
|
|
|
|
// Assumptions: all member URLSegments must be relative the |spec| argument
|
|
|
|
// passed to this function.
|
|
|
|
|
|
|
|
// buffers for holding escaped url segments (these will remain empty unless
|
|
|
|
// escaping is required).
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString encUsername, encPassword, encHost, encDirectory,
|
2011-08-22 18:51:52 +04:00
|
|
|
encBasename, encExtension, encQuery, encRef;
|
2012-04-08 01:25:00 +04:00
|
|
|
bool useEncUsername, useEncPassword, useEncHost = false,
|
|
|
|
useEncDirectory, useEncBasename, useEncExtension, useEncQuery, useEncRef;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString portbuf;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
//
|
|
|
|
// escape each URL segment, if necessary, and calculate approximate normalized
|
|
|
|
// spec length.
|
|
|
|
//
|
2011-08-22 18:51:52 +04:00
|
|
|
// [scheme://][username[:password]@]host[:port]/path[?query_string][#ref]
|
2011-06-07 20:17:40 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t approxLen = 0;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// the scheme is already ASCII
|
|
|
|
if (mScheme.mLen > 0)
|
2011-12-03 08:48:16 +04:00
|
|
|
approxLen += mScheme.mLen + 3; // includes room for "://", which we insert always
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
// encode URL segments; convert UTF-8 to origin charset and possibly escape.
|
|
|
|
// results written to encXXX variables only if |spec| is not already in the
|
|
|
|
// appropriate encoding.
|
|
|
|
{
|
|
|
|
GET_SEGMENT_ENCODER(encoder);
|
2006-04-13 18:44:38 +04:00
|
|
|
GET_QUERY_ENCODER(queryEncoder);
|
2011-06-07 20:17:40 +04:00
|
|
|
// Items using an extraLen of 1 don't add anything unless mLen > 0
|
|
|
|
// Username@
|
|
|
|
approxLen += encoder.EncodeSegmentCount(spec, mUsername, esc_Username, encUsername, useEncUsername, 1);
|
2011-12-03 08:48:16 +04:00
|
|
|
// :password - we insert the ':' even if there's no actual password if "user:@" was in the spec
|
|
|
|
if (mPassword.mLen >= 0)
|
|
|
|
approxLen += 1 + encoder.EncodeSegmentCount(spec, mPassword, esc_Password, encPassword, useEncPassword);
|
2011-06-07 20:17:40 +04:00
|
|
|
// mHost is handled differently below due to encoding differences
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mPort >= -1, "Invalid negative mPort");
|
2011-06-07 20:17:40 +04:00
|
|
|
if (mPort != -1 && mPort != mDefaultPort)
|
|
|
|
{
|
|
|
|
// :port
|
|
|
|
portbuf.AppendInt(mPort);
|
|
|
|
approxLen += portbuf.Length() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
approxLen += 1; // reserve space for possible leading '/' - may not be needed
|
|
|
|
// Should just use mPath? These are pessimistic, and thus waste space
|
|
|
|
approxLen += encoder.EncodeSegmentCount(spec, mDirectory, esc_Directory, encDirectory, useEncDirectory, 1);
|
2005-09-13 21:38:20 +04:00
|
|
|
approxLen += encoder.EncodeSegmentCount(spec, mBasename, esc_FileBaseName, encBasename, useEncBasename);
|
2011-06-07 20:17:40 +04:00
|
|
|
approxLen += encoder.EncodeSegmentCount(spec, mExtension, esc_FileExtension, encExtension, useEncExtension, 1);
|
|
|
|
|
|
|
|
// These next ones *always* add their leading character even if length is 0
|
|
|
|
// Handles items like "http://#"
|
|
|
|
// ?query
|
|
|
|
if (mQuery.mLen >= 0)
|
|
|
|
approxLen += 1 + queryEncoder.EncodeSegmentCount(spec, mQuery, esc_Query, encQuery, useEncQuery);
|
|
|
|
// #ref
|
2015-01-13 03:11:02 +03:00
|
|
|
|
|
|
|
if (mRef.mLen >= 0) {
|
|
|
|
if (nsContentUtils::EncodeDecodeURLHash()) {
|
|
|
|
approxLen += 1 + encoder.EncodeSegmentCount(spec, mRef, esc_Ref,
|
|
|
|
encRef, useEncRef);
|
|
|
|
} else {
|
|
|
|
approxLen += 1 + mRef.mLen;
|
|
|
|
useEncRef = false;
|
|
|
|
}
|
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// do not escape the hostname, if IPv6 address literal, mHost will
|
2001-11-16 05:09:13 +03:00
|
|
|
// already point to a [ ] delimited IPv6 address literal.
|
2004-04-03 11:32:18 +04:00
|
|
|
// However, perform Unicode normalization on it, as IDN does.
|
|
|
|
mHostEncoding = eEncoding_ASCII;
|
2011-12-03 08:48:16 +04:00
|
|
|
// Note that we don't disallow URLs without a host - file:, etc
|
2004-04-03 11:32:18 +04:00
|
|
|
if (mHost.mLen > 0) {
|
2015-11-18 17:25:27 +03:00
|
|
|
nsAutoCString tempHost;
|
|
|
|
NS_UnescapeURL(spec + mHost.mPos, mHost.mLen, esc_AlwaysCopy | esc_Host, tempHost);
|
2015-08-14 01:49:15 +03:00
|
|
|
if (tempHost.Contains('\0'))
|
2007-02-16 04:10:39 +03:00
|
|
|
return NS_ERROR_MALFORMED_URI; // null embedded in hostname
|
2015-08-14 01:49:15 +03:00
|
|
|
if (tempHost.Contains(' '))
|
2008-09-14 22:15:06 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI; // don't allow spaces in the hostname
|
2015-11-18 17:25:27 +03:00
|
|
|
nsresult rv = NormalizeIDN(tempHost, encHost);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
|
|
|
}
|
2015-09-03 22:15:30 +03:00
|
|
|
|
2015-11-18 17:25:27 +03:00
|
|
|
// NormalizeIDN always copies, if the call was successful.
|
|
|
|
useEncHost = true;
|
|
|
|
approxLen += encHost.Length();
|
|
|
|
|
|
|
|
if (!ValidIPv6orHostname(encHost.BeginReading(), encHost.Length())) {
|
2015-09-03 22:15:30 +03:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
2004-04-03 11:32:18 +04:00
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-05-10 11:52:19 +03:00
|
|
|
// We must take a copy of every single segment because they are pointing to
|
|
|
|
// the |spec| while we are changing their value, in case we must use
|
|
|
|
// encoded strings.
|
|
|
|
URLSegment username(mUsername);
|
|
|
|
URLSegment password(mPassword);
|
|
|
|
URLSegment host(mHost);
|
|
|
|
URLSegment path(mPath);
|
|
|
|
URLSegment filepath(mFilepath);
|
|
|
|
URLSegment directory(mDirectory);
|
|
|
|
URLSegment basename(mBasename);
|
|
|
|
URLSegment extension(mExtension);
|
|
|
|
URLSegment query(mQuery);
|
|
|
|
URLSegment ref(mRef);
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
//
|
|
|
|
// generate the normalized URL string
|
|
|
|
//
|
2011-06-07 20:17:40 +04:00
|
|
|
// approxLen should be correct or 1 high
|
2016-05-19 05:02:57 +03:00
|
|
|
if (!mSpec.SetLength(approxLen+1, fallible)) // buf needs a trailing '\0' below
|
2006-06-22 23:07:30 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-02-19 05:44:03 +03:00
|
|
|
char *buf;
|
|
|
|
mSpec.BeginWriting(buf);
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t i = 0;
|
2016-05-10 11:52:19 +03:00
|
|
|
int32_t diff = 0;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (mScheme.mLen > 0) {
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, mScheme, mScheme);
|
2002-09-13 23:32:45 +04:00
|
|
|
net_ToLowerCase(buf + mScheme.mPos, mScheme.mLen);
|
2001-11-16 05:09:13 +03:00
|
|
|
i = AppendToBuf(buf, i, "://", 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
// record authority starting position
|
|
|
|
mAuthority.mPos = i;
|
|
|
|
|
|
|
|
// append authority
|
|
|
|
if (mUsername.mLen > 0) {
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, username, mUsername,
|
|
|
|
&encUsername, useEncUsername, &diff);
|
|
|
|
ShiftFromPassword(diff);
|
|
|
|
if (password.mLen >= 0) {
|
2001-11-16 05:09:13 +03:00
|
|
|
buf[i++] = ':';
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, password, mPassword,
|
|
|
|
&encPassword, useEncPassword, &diff);
|
|
|
|
ShiftFromHost(diff);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
buf[i++] = '@';
|
|
|
|
}
|
2016-05-10 11:52:19 +03:00
|
|
|
if (host.mLen > 0) {
|
|
|
|
i = AppendSegmentToBuf(buf, i, spec, host, mHost, &encHost, useEncHost,
|
|
|
|
&diff);
|
|
|
|
ShiftFromPath(diff);
|
|
|
|
|
2002-09-13 23:32:45 +04:00
|
|
|
net_ToLowerCase(buf + mHost.mPos, mHost.mLen);
|
2015-02-10 01:34:50 +03:00
|
|
|
MOZ_ASSERT(mPort >= -1, "Invalid negative mPort");
|
2001-11-16 05:09:13 +03:00
|
|
|
if (mPort != -1 && mPort != mDefaultPort) {
|
|
|
|
buf[i++] = ':';
|
2011-06-07 20:17:40 +04:00
|
|
|
// Already formatted while building approxLen
|
2001-11-16 05:09:13 +03:00
|
|
|
i = AppendToBuf(buf, i, portbuf.get(), portbuf.Length());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// record authority length
|
|
|
|
mAuthority.mLen = i - mAuthority.mPos;
|
|
|
|
|
|
|
|
// path must always start with a "/"
|
|
|
|
if (mPath.mLen <= 0) {
|
|
|
|
LOG(("setting path=/"));
|
2002-03-06 10:48:55 +03:00
|
|
|
mDirectory.mPos = mFilepath.mPos = mPath.mPos = i;
|
|
|
|
mDirectory.mLen = mFilepath.mLen = mPath.mLen = 1;
|
2001-12-06 02:54:55 +03:00
|
|
|
// basename must exist, even if empty (bug 113508)
|
|
|
|
mBasename.mPos = i+1;
|
|
|
|
mBasename.mLen = 0;
|
2001-11-16 05:09:13 +03:00
|
|
|
buf[i++] = '/';
|
|
|
|
}
|
|
|
|
else {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t leadingSlash = 0;
|
2016-05-10 11:52:19 +03:00
|
|
|
if (spec[path.mPos] != '/') {
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("adding leading slash to path\n"));
|
|
|
|
leadingSlash = 1;
|
|
|
|
buf[i++] = '/';
|
2008-10-01 09:34:29 +04:00
|
|
|
// basename must exist, even if empty (bugs 113508, 429347)
|
|
|
|
if (mBasename.mLen == -1) {
|
2016-05-10 11:52:19 +03:00
|
|
|
mBasename.mPos = basename.mPos = i;
|
|
|
|
mBasename.mLen = basename.mLen = 0;
|
2008-10-01 09:34:29 +04:00
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// record corrected (file)path starting position
|
2002-03-06 10:48:55 +03:00
|
|
|
mPath.mPos = mFilepath.mPos = i - leadingSlash;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, directory, mDirectory,
|
|
|
|
&encDirectory, useEncDirectory, &diff);
|
|
|
|
ShiftFromBasename(diff);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
// the directory must end with a '/'
|
|
|
|
if (buf[i-1] != '/') {
|
|
|
|
buf[i++] = '/';
|
|
|
|
mDirectory.mLen++;
|
|
|
|
}
|
|
|
|
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, basename, mBasename,
|
|
|
|
&encBasename, useEncBasename, &diff);
|
|
|
|
ShiftFromExtension(diff);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
// make corrections to directory segment if leadingSlash
|
|
|
|
if (leadingSlash) {
|
|
|
|
mDirectory.mPos = mPath.mPos;
|
|
|
|
if (mDirectory.mLen >= 0)
|
|
|
|
mDirectory.mLen += leadingSlash;
|
|
|
|
else
|
|
|
|
mDirectory.mLen = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mExtension.mLen >= 0) {
|
|
|
|
buf[i++] = '.';
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, extension, mExtension,
|
|
|
|
&encExtension, useEncExtension, &diff);
|
|
|
|
ShiftFromQuery(diff);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
// calculate corrected filepath length
|
2002-03-06 10:48:55 +03:00
|
|
|
mFilepath.mLen = i - mFilepath.mPos;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (mQuery.mLen >= 0) {
|
|
|
|
buf[i++] = '?';
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, query, mQuery,
|
|
|
|
&encQuery, useEncQuery,
|
|
|
|
&diff);
|
|
|
|
ShiftFromRef(diff);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
if (mRef.mLen >= 0) {
|
|
|
|
buf[i++] = '#';
|
2016-05-10 11:52:19 +03:00
|
|
|
i = AppendSegmentToBuf(buf, i, spec, ref, mRef, &encRef, useEncRef,
|
|
|
|
&diff);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
// calculate corrected path length
|
|
|
|
mPath.mLen = i - mPath.mPos;
|
|
|
|
}
|
|
|
|
|
|
|
|
buf[i] = '\0';
|
|
|
|
|
2003-07-16 23:09:00 +04:00
|
|
|
if (mDirectory.mLen > 1) {
|
|
|
|
netCoalesceFlags coalesceFlag = NET_COALESCE_NORMAL;
|
|
|
|
if (SegmentIs(buf,mScheme,"ftp")) {
|
|
|
|
coalesceFlag = (netCoalesceFlags) (coalesceFlag
|
|
|
|
| NET_COALESCE_ALLOW_RELATIVE_ROOT
|
|
|
|
| NET_COALESCE_DOUBLE_SLASH_IS_ROOT);
|
|
|
|
}
|
|
|
|
CoalescePath(coalesceFlag, buf + mDirectory.mPos);
|
|
|
|
}
|
2004-02-19 05:44:03 +03:00
|
|
|
mSpec.SetLength(strlen(buf));
|
2011-06-07 20:17:40 +04:00
|
|
|
NS_ASSERTION(mSpec.Length() <= approxLen, "We've overflowed the mSpec buffer!");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsStandardURL::SegmentIs(const URLSegment &seg, const char *val, bool ignoreCase)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
// one or both may be null
|
|
|
|
if (!val || mSpec.IsEmpty())
|
|
|
|
return (!val && (mSpec.IsEmpty() || seg.mLen < 0));
|
|
|
|
if (seg.mLen < 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-11-16 05:09:13 +03:00
|
|
|
// if the first |seg.mLen| chars of |val| match, then |val| must
|
|
|
|
// also be null terminated at |seg.mLen|.
|
2008-08-19 18:48:10 +04:00
|
|
|
if (ignoreCase)
|
|
|
|
return !PL_strncasecmp(mSpec.get() + seg.mPos, val, seg.mLen)
|
|
|
|
&& (val[seg.mLen] == '\0');
|
|
|
|
else
|
|
|
|
return !strncmp(mSpec.get() + seg.mPos, val, seg.mLen)
|
|
|
|
&& (val[seg.mLen] == '\0');
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsStandardURL::SegmentIs(const char* spec, const URLSegment &seg, const char *val, bool ignoreCase)
|
2003-07-16 23:09:00 +04:00
|
|
|
{
|
|
|
|
// one or both may be null
|
|
|
|
if (!val || !spec)
|
|
|
|
return (!val && (!spec || seg.mLen < 0));
|
|
|
|
if (seg.mLen < 0)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2003-07-16 23:09:00 +04:00
|
|
|
// if the first |seg.mLen| chars of |val| match, then |val| must
|
|
|
|
// also be null terminated at |seg.mLen|.
|
2008-08-19 18:48:10 +04:00
|
|
|
if (ignoreCase)
|
|
|
|
return !PL_strncasecmp(spec + seg.mPos, val, seg.mLen)
|
|
|
|
&& (val[seg.mLen] == '\0');
|
|
|
|
else
|
|
|
|
return !strncmp(spec + seg.mPos, val, seg.mLen)
|
|
|
|
&& (val[seg.mLen] == '\0');
|
2003-07-16 23:09:00 +04:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
|
|
|
nsStandardURL::SegmentIs(const URLSegment &seg1, const char *val, const URLSegment &seg2, bool ignoreCase)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
if (seg1.mLen != seg2.mLen)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2001-11-16 05:09:13 +03:00
|
|
|
if (seg1.mLen == -1 || (!val && mSpec.IsEmpty()))
|
2011-10-17 18:59:28 +04:00
|
|
|
return true; // both are empty
|
2011-05-27 09:44:15 +04:00
|
|
|
if (!val)
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2008-08-19 18:48:10 +04:00
|
|
|
if (ignoreCase)
|
|
|
|
return !PL_strncasecmp(mSpec.get() + seg1.mPos, val + seg2.mPos, seg1.mLen);
|
|
|
|
else
|
|
|
|
return !strncmp(mSpec.get() + seg1.mPos, val + seg2.mPos, seg1.mLen);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
|
|
|
nsStandardURL::ReplaceSegment(uint32_t pos, uint32_t len, const char *val, uint32_t valLen)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
if (val && valLen) {
|
|
|
|
if (len == 0)
|
|
|
|
mSpec.Insert(val, pos, valLen);
|
|
|
|
else
|
|
|
|
mSpec.Replace(pos, len, nsDependentCString(val, valLen));
|
|
|
|
return valLen - len;
|
|
|
|
}
|
|
|
|
|
|
|
|
// else remove the specified segment
|
|
|
|
mSpec.Cut(pos, len);
|
2012-08-22 19:56:38 +04:00
|
|
|
return -int32_t(len);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t
|
|
|
|
nsStandardURL::ReplaceSegment(uint32_t pos, uint32_t len, const nsACString &val)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
if (len == 0)
|
|
|
|
mSpec.Insert(val, pos);
|
|
|
|
else
|
|
|
|
mSpec.Replace(pos, len, val);
|
|
|
|
return val.Length() - len;
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::ParseURL(const char *spec, int32_t specLen)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
2015-03-11 07:08:27 +03:00
|
|
|
if (specLen > net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
//
|
|
|
|
// parse given URL string
|
|
|
|
//
|
2004-11-07 23:43:38 +03:00
|
|
|
rv = mParser->ParseURL(spec, specLen,
|
2001-11-16 05:09:13 +03:00
|
|
|
&mScheme.mPos, &mScheme.mLen,
|
|
|
|
&mAuthority.mPos, &mAuthority.mLen,
|
|
|
|
&mPath.mPos, &mPath.mLen);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2002-03-06 10:48:55 +03:00
|
|
|
if (mScheme.mLen <= 0) {
|
|
|
|
printf("spec=%s\n", spec);
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_WARNING("malformed url: no scheme");
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
#endif
|
|
|
|
|
|
|
|
if (mAuthority.mLen > 0) {
|
|
|
|
rv = mParser->ParseAuthority(spec + mAuthority.mPos, mAuthority.mLen,
|
|
|
|
&mUsername.mPos, &mUsername.mLen,
|
|
|
|
&mPassword.mPos, &mPassword.mLen,
|
2002-03-06 10:48:55 +03:00
|
|
|
&mHost.mPos, &mHost.mLen,
|
2001-11-16 05:09:13 +03:00
|
|
|
&mPort);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2008-06-16 05:16:57 +04:00
|
|
|
// Don't allow mPort to be set to this URI's default port
|
|
|
|
if (mPort == mDefaultPort)
|
|
|
|
mPort = -1;
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
mUsername.mPos += mAuthority.mPos;
|
|
|
|
mPassword.mPos += mAuthority.mPos;
|
2002-03-06 10:48:55 +03:00
|
|
|
mHost.mPos += mAuthority.mPos;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mPath.mLen > 0)
|
|
|
|
rv = ParsePath(spec, mPath.mPos, mPath.mLen);
|
|
|
|
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::ParsePath(const char *spec, uint32_t pathPos, int32_t pathLen)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2011-07-12 22:07:24 +04:00
|
|
|
LOG(("ParsePath: %s pathpos %d len %d\n",spec,pathPos,pathLen));
|
|
|
|
|
2015-03-11 07:08:27 +03:00
|
|
|
if (pathLen > net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
nsresult rv = mParser->ParsePath(spec + pathPos, pathLen,
|
2002-03-06 10:48:55 +03:00
|
|
|
&mFilepath.mPos, &mFilepath.mLen,
|
2001-11-16 05:09:13 +03:00
|
|
|
&mQuery.mPos, &mQuery.mLen,
|
|
|
|
&mRef.mPos, &mRef.mLen);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
mFilepath.mPos += pathPos;
|
2001-11-16 05:09:13 +03:00
|
|
|
mQuery.mPos += pathPos;
|
|
|
|
mRef.mPos += pathPos;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (mFilepath.mLen > 0) {
|
|
|
|
rv = mParser->ParseFilePath(spec + mFilepath.mPos, mFilepath.mLen,
|
2001-11-16 05:09:13 +03:00
|
|
|
&mDirectory.mPos, &mDirectory.mLen,
|
|
|
|
&mBasename.mPos, &mBasename.mLen,
|
|
|
|
&mExtension.mPos, &mExtension.mLen);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
mDirectory.mPos += mFilepath.mPos;
|
|
|
|
mBasename.mPos += mFilepath.mPos;
|
|
|
|
mExtension.mPos += mFilepath.mPos;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::AppendToSubstring(uint32_t pos,
|
|
|
|
int32_t len,
|
2011-09-21 23:21:42 +04:00
|
|
|
const char *tail)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2011-09-21 23:21:42 +04:00
|
|
|
// Verify pos and length are within boundaries
|
|
|
|
if (pos > mSpec.Length())
|
2013-09-19 23:28:26 +04:00
|
|
|
return nullptr;
|
2011-09-21 23:21:42 +04:00
|
|
|
if (len < 0)
|
2013-09-19 23:28:26 +04:00
|
|
|
return nullptr;
|
2012-08-22 19:56:38 +04:00
|
|
|
if ((uint32_t)len > (mSpec.Length() - pos))
|
2013-09-19 23:28:26 +04:00
|
|
|
return nullptr;
|
2011-09-21 23:21:42 +04:00
|
|
|
if (!tail)
|
2013-09-19 23:28:26 +04:00
|
|
|
return nullptr;
|
2011-09-21 23:21:42 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t tailLen = strlen(tail);
|
2011-09-21 23:21:42 +04:00
|
|
|
|
|
|
|
// Check for int overflow for proposed length of combined string
|
2012-09-28 10:57:33 +04:00
|
|
|
if (UINT32_MAX - ((uint32_t)len + 1) < tailLen)
|
2013-09-19 23:28:26 +04:00
|
|
|
return nullptr;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2015-04-01 08:29:55 +03:00
|
|
|
char *result = (char *) moz_xmalloc(len + tailLen + 1);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (result) {
|
|
|
|
memcpy(result, mSpec.get() + pos, len);
|
|
|
|
memcpy(result + len, tail, tailLen);
|
|
|
|
result[len + tailLen] = '\0';
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStandardURL::ReadSegment(nsIBinaryInputStream *stream, URLSegment &seg)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = stream->Read32(&seg.mPos);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
rv = stream->Read32((uint32_t *) &seg.mLen);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStandardURL::WriteSegment(nsIBinaryOutputStream *stream, const URLSegment &seg)
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = stream->Write32(seg.mPos);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
rv = stream->Write32(uint32_t(seg.mLen));
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-07 16:21:32 +03:00
|
|
|
/* static */ void
|
|
|
|
nsStandardURL::PrefsChanged(nsIPrefBranch *prefs, const char *pref)
|
|
|
|
{
|
2011-09-29 10:19:26 +04:00
|
|
|
bool val;
|
2004-12-07 16:21:32 +03:00
|
|
|
|
|
|
|
LOG(("nsStandardURL::PrefsChanged [pref=%s]\n", pref));
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
#define PREF_CHANGED(p) ((pref == nullptr) || !strcmp(pref, p))
|
2004-12-07 16:21:32 +03:00
|
|
|
#define GOT_PREF(p, b) (NS_SUCCEEDED(prefs->GetBoolPref(p, &b)))
|
|
|
|
|
|
|
|
if (PREF_CHANGED(NS_NET_PREF_ESCAPEUTF8)) {
|
|
|
|
if (GOT_PREF(NS_NET_PREF_ESCAPEUTF8, val))
|
|
|
|
gEscapeUTF8 = val;
|
|
|
|
LOG(("escape UTF-8 %s\n", gEscapeUTF8 ? "enabled" : "disabled"));
|
|
|
|
}
|
2006-04-13 18:44:38 +04:00
|
|
|
|
2004-12-07 16:21:32 +03:00
|
|
|
if (PREF_CHANGED(NS_NET_PREF_ALWAYSENCODEINUTF8)) {
|
|
|
|
if (GOT_PREF(NS_NET_PREF_ALWAYSENCODEINUTF8, val))
|
|
|
|
gAlwaysEncodeInUTF8 = val;
|
|
|
|
LOG(("encode in UTF-8 %s\n", gAlwaysEncodeInUTF8 ? "enabled" : "disabled"));
|
|
|
|
}
|
|
|
|
#undef PREF_CHANGED
|
|
|
|
#undef GOT_PREF
|
|
|
|
}
|
2005-04-27 05:32:36 +04:00
|
|
|
|
2016-05-10 11:52:19 +03:00
|
|
|
#define SHIFT_FROM(name, what) \
|
|
|
|
void \
|
|
|
|
nsStandardURL::name(int32_t diff) \
|
|
|
|
{ \
|
|
|
|
if (!diff) return; \
|
|
|
|
if (what.mLen >= 0) { \
|
|
|
|
CheckedInt<int32_t> pos = what.mPos; \
|
|
|
|
pos += diff; \
|
|
|
|
MOZ_ASSERT(pos.isValid()); \
|
|
|
|
what.mPos = pos.value(); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SHIFT_FROM_NEXT(name, what, next) \
|
|
|
|
SHIFT_FROM(name, what) \
|
|
|
|
next(diff); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SHIFT_FROM_LAST(name, what) \
|
|
|
|
SHIFT_FROM(name, what) \
|
|
|
|
}
|
|
|
|
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromAuthority, mAuthority, ShiftFromUsername)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromUsername, mUsername, ShiftFromPassword)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromPassword, mPassword, ShiftFromHost)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromHost, mHost, ShiftFromPath)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromPath, mPath, ShiftFromFilepath)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromFilepath, mFilepath, ShiftFromDirectory)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromDirectory, mDirectory, ShiftFromBasename)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromBasename, mBasename, ShiftFromExtension)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromExtension, mExtension, ShiftFromQuery)
|
|
|
|
SHIFT_FROM_NEXT(ShiftFromQuery, mQuery, ShiftFromRef)
|
|
|
|
SHIFT_FROM_LAST(ShiftFromRef, mRef)
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsISupports
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMPL_ADDREF(nsStandardURL)
|
|
|
|
NS_IMPL_RELEASE(nsStandardURL)
|
|
|
|
|
2008-02-21 23:39:20 +03:00
|
|
|
NS_INTERFACE_MAP_BEGIN(nsStandardURL)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_AMBIGUOUS(nsISupports, nsIStandardURL)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURI)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIURL)
|
|
|
|
NS_INTERFACE_MAP_ENTRY_CONDITIONAL(nsIFileURL, mSupportsFileURL)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIStandardURL)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISerializable)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIClassInfo)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIMutable)
|
2012-08-23 23:33:46 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIIPCSerializableURI)
|
2015-09-11 09:44:00 +03:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISensitiveInfoHiddenURI)
|
2008-02-21 23:39:20 +03:00
|
|
|
// see nsStandardURL::Equals
|
|
|
|
if (aIID.Equals(kThisImplCID))
|
|
|
|
foundInterface = static_cast<nsIURI *>(this);
|
|
|
|
else
|
2012-02-20 07:51:48 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsISizeOf)
|
2008-02-21 23:39:20 +03:00
|
|
|
NS_INTERFACE_MAP_END
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsIURI
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetSpec(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2016-01-26 19:23:22 +03:00
|
|
|
MOZ_ASSERT(mSpec.Length() <= (uint32_t) net_GetURLMaxLength(),
|
|
|
|
"The spec should never be this long, we missed a check.");
|
2002-03-06 10:48:55 +03:00
|
|
|
result = mSpec;
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2015-09-11 09:44:00 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetSensitiveInfoHiddenSpec(nsACString &result)
|
|
|
|
{
|
|
|
|
result = mSpec;
|
|
|
|
if (mPassword.mLen >= 0) {
|
|
|
|
result.Replace(mPassword.mPos, mPassword.mLen, "****");
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2011-08-16 01:18:15 +04:00
|
|
|
// result may contain unescaped UTF-8 characters
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetSpecIgnoringRef(nsACString &result)
|
|
|
|
{
|
|
|
|
// URI without ref is 0 to one char before ref
|
|
|
|
if (mRef.mLen >= 0) {
|
|
|
|
URLSegment noRef(0, mRef.mPos - 1);
|
|
|
|
|
|
|
|
result = Segment(noRef);
|
|
|
|
} else {
|
|
|
|
result = mSpec;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetPrePath(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Prepath();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result is strictly US-ASCII
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetScheme(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Scheme();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetUserPass(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Userpass();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetUsername(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Username();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetPassword(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Password();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetHostPort(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Hostport();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetHost(nsACString &result)
|
|
|
|
{
|
|
|
|
result = Host();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::GetPort(int32_t *result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
*result = mPort;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetPath(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Path();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result is ASCII
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetAsciiSpec(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
if (mSpecEncoding == eEncoding_Unknown) {
|
|
|
|
if (IsASCII(mSpec))
|
|
|
|
mSpecEncoding = eEncoding_ASCII;
|
|
|
|
else
|
|
|
|
mSpecEncoding = eEncoding_UTF8;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mSpecEncoding == eEncoding_ASCII) {
|
|
|
|
result = mSpec;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// try to guess the capacity required for result...
|
2013-01-15 16:22:03 +04:00
|
|
|
result.SetCapacity(mSpec.Length() + std::min<uint32_t>(32, mSpec.Length()/10));
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
result = Substring(mSpec, 0, mScheme.mLen + 3);
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
NS_EscapeURL(Userpass(true), esc_OnlyNonASCII | esc_AlwaysCopy, result);
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2015-08-17 22:34:17 +03:00
|
|
|
// get the hostport
|
|
|
|
nsAutoCString hostport;
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(GetAsciiHostPort(hostport));
|
2015-08-17 22:34:17 +03:00
|
|
|
result += hostport;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2015-08-17 22:34:17 +03:00
|
|
|
NS_EscapeURL(Path(), esc_OnlyNonASCII | esc_AlwaysCopy, result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// result is ASCII
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetAsciiHostPort(nsACString &result)
|
|
|
|
{
|
|
|
|
if (mHostEncoding == eEncoding_ASCII) {
|
|
|
|
result = Hostport();
|
|
|
|
return NS_OK;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
2016-03-28 20:28:15 +03:00
|
|
|
MOZ_ALWAYS_SUCCEEDS(GetAsciiHost(result));
|
2015-08-17 22:34:17 +03:00
|
|
|
|
|
|
|
// As our mHostEncoding is not eEncoding_ASCII, we know that
|
|
|
|
// the our host is not ipv6, and we can avoid looking at it.
|
|
|
|
MOZ_ASSERT(result.FindChar(':') == -1, "The host must not be ipv6");
|
|
|
|
|
|
|
|
// hostport = "hostA" + ":port"
|
|
|
|
uint32_t pos = mHost.mPos + mHost.mLen;
|
|
|
|
if (pos < mPath.mPos)
|
|
|
|
result += Substring(mSpec, pos, mPath.mPos - pos);
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// result is ASCII
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetAsciiHost(nsACString &result)
|
|
|
|
{
|
|
|
|
if (mHostEncoding == eEncoding_ASCII) {
|
|
|
|
result = Host();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// perhaps we have it cached...
|
|
|
|
if (mHostA) {
|
|
|
|
result = mHostA;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-27 05:32:36 +04:00
|
|
|
if (gIDN) {
|
2002-03-06 10:48:55 +03:00
|
|
|
nsresult rv;
|
2005-04-27 05:32:36 +04:00
|
|
|
rv = gIDN->ConvertUTF8toACE(Host(), result);
|
2002-03-06 10:48:55 +03:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2003-03-14 02:06:14 +03:00
|
|
|
mHostA = ToNewCString(result);
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2003-03-14 02:06:14 +03:00
|
|
|
NS_WARNING("nsIDNService::ConvertUTF8toACE failed");
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// something went wrong... guess all we can do is URL escape :-/
|
2002-06-20 09:45:57 +04:00
|
|
|
NS_EscapeURL(Host(), esc_OnlyNonASCII | esc_AlwaysCopy, result);
|
2002-03-06 10:48:55 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetOriginCharset(nsACString &result)
|
|
|
|
{
|
|
|
|
if (mOriginCharset.IsEmpty())
|
2004-06-17 04:13:25 +04:00
|
|
|
result.AssignLiteral("UTF-8");
|
2002-03-06 10:48:55 +03:00
|
|
|
else
|
|
|
|
result = mOriginCharset;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-03-03 17:50:16 +03:00
|
|
|
static bool
|
|
|
|
IsSpecialProtocol(const nsACString &input)
|
|
|
|
{
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
input.BeginReading(start);
|
|
|
|
nsACString::const_iterator iterator(start);
|
|
|
|
input.EndReading(end);
|
|
|
|
|
|
|
|
while (iterator != end && *iterator != ':') {
|
|
|
|
iterator++;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsAutoCString protocol(nsDependentCSubstring(start.get(), iterator.get()));
|
|
|
|
|
|
|
|
return protocol.LowerCaseEqualsLiteral("http") ||
|
|
|
|
protocol.LowerCaseEqualsLiteral("https") ||
|
|
|
|
protocol.LowerCaseEqualsLiteral("ftp") ||
|
|
|
|
protocol.LowerCaseEqualsLiteral("ws") ||
|
|
|
|
protocol.LowerCaseEqualsLiteral("wss") ||
|
|
|
|
protocol.LowerCaseEqualsLiteral("file") ||
|
|
|
|
protocol.LowerCaseEqualsLiteral("gopher");
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::SetSpec(const nsACString &input)
|
|
|
|
{
|
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &flat = PromiseFlatCString(input);
|
2016-05-25 17:23:37 +03:00
|
|
|
LOG(("nsStandardURL::SetSpec [spec=%s]\n", flat.get()));
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-05-25 17:23:37 +03:00
|
|
|
if (input.Length() > (uint32_t) net_GetURLMaxLength()) {
|
2014-08-11 13:14:03 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
2016-05-25 17:23:37 +03:00
|
|
|
}
|
2014-08-11 13:14:03 +04:00
|
|
|
|
2016-05-25 17:23:37 +03:00
|
|
|
// filter out unexpected chars "\r\n\t" if necessary
|
|
|
|
nsAutoCString filteredURI;
|
|
|
|
net_FilterURIString(flat, filteredURI);
|
|
|
|
|
|
|
|
if (filteredURI.Length() == 0) {
|
2015-03-11 07:08:27 +03:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2014-08-11 13:14:03 +04:00
|
|
|
// Make a backup of the curent URL
|
2014-08-09 07:59:00 +04:00
|
|
|
nsStandardURL prevURL(false,false);
|
2016-07-27 01:38:46 +03:00
|
|
|
prevURL.CopyMembers(this, eHonorRef, EmptyCString());
|
2014-08-11 13:14:03 +04:00
|
|
|
Clear();
|
2002-03-12 07:07:14 +03:00
|
|
|
|
2016-03-03 17:50:16 +03:00
|
|
|
if (IsSpecialProtocol(filteredURI)) {
|
|
|
|
// Bug 652186: Replace all backslashes with slashes when parsing paths
|
|
|
|
// Stop when we reach the query or the hash.
|
|
|
|
nsAutoCString::iterator start;
|
|
|
|
nsAutoCString::iterator end;
|
|
|
|
filteredURI.BeginWriting(start);
|
|
|
|
filteredURI.EndWriting(end);
|
|
|
|
while (start != end) {
|
|
|
|
if (*start == '?' || *start == '#') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*start == '\\') {
|
|
|
|
*start = '/';
|
|
|
|
}
|
|
|
|
start++;
|
|
|
|
}
|
2004-11-07 23:43:38 +03:00
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-05-25 17:23:37 +03:00
|
|
|
const char *spec = filteredURI.get();
|
|
|
|
int32_t specLength = filteredURI.Length();
|
2016-03-03 17:50:16 +03:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
// parse the given URL...
|
2004-11-07 23:43:38 +03:00
|
|
|
nsresult rv = ParseURL(spec, specLength);
|
2014-02-04 20:55:02 +04:00
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
// finally, use the URLSegment member variables to build a normalized
|
|
|
|
// copy of |spec|
|
|
|
|
rv = BuildNormalizedSpec(spec);
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-07-13 15:19:33 +03:00
|
|
|
// Make sure that a URLTYPE_AUTHORITY has a non-empty hostname.
|
|
|
|
if (mURLType == URLTYPE_AUTHORITY && mHost.mLen == -1) {
|
|
|
|
rv = NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2014-02-04 20:55:02 +04:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
Clear();
|
2014-08-11 13:14:03 +04:00
|
|
|
// If parsing the spec has failed, restore the old URL
|
|
|
|
// so we don't end up with an empty URL.
|
2016-07-27 01:38:46 +03:00
|
|
|
CopyMembers(&prevURL, eHonorRef, EmptyCString());
|
2014-02-04 20:55:02 +04:00
|
|
|
return rv;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (LOG_ENABLED()) {
|
|
|
|
LOG((" spec = %s\n", mSpec.get()));
|
|
|
|
LOG((" port = %d\n", mPort));
|
|
|
|
LOG((" scheme = (%u,%d)\n", mScheme.mPos, mScheme.mLen));
|
|
|
|
LOG((" authority = (%u,%d)\n", mAuthority.mPos, mAuthority.mLen));
|
|
|
|
LOG((" username = (%u,%d)\n", mUsername.mPos, mUsername.mLen));
|
|
|
|
LOG((" password = (%u,%d)\n", mPassword.mPos, mPassword.mLen));
|
2002-03-06 10:48:55 +03:00
|
|
|
LOG((" hostname = (%u,%d)\n", mHost.mPos, mHost.mLen));
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG((" path = (%u,%d)\n", mPath.mPos, mPath.mLen));
|
2002-03-06 10:48:55 +03:00
|
|
|
LOG((" filepath = (%u,%d)\n", mFilepath.mPos, mFilepath.mLen));
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG((" directory = (%u,%d)\n", mDirectory.mPos, mDirectory.mLen));
|
|
|
|
LOG((" basename = (%u,%d)\n", mBasename.mPos, mBasename.mLen));
|
|
|
|
LOG((" extension = (%u,%d)\n", mExtension.mPos, mExtension.mLen));
|
|
|
|
LOG((" query = (%u,%d)\n", mQuery.mPos, mQuery.mLen));
|
|
|
|
LOG((" ref = (%u,%d)\n", mRef.mPos, mRef.mLen));
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetScheme(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
const nsPromiseFlatCString &scheme = PromiseFlatCString(input);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
LOG(("nsStandardURL::SetScheme [scheme=%s]\n", scheme.get()));
|
|
|
|
|
|
|
|
if (scheme.IsEmpty()) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("cannot remove the scheme from an url");
|
2001-11-27 02:28:44 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
if (mScheme.mLen < 0) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("uninitialized");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2002-09-13 23:32:45 +04:00
|
|
|
if (!net_IsValidScheme(scheme)) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("the given url scheme contains invalid characters");
|
2001-11-27 02:28:44 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + input.Length() - Scheme().Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t shift = ReplaceSegment(mScheme.mPos, mScheme.mLen, scheme);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (shift) {
|
2002-03-06 10:48:55 +03:00
|
|
|
mScheme.mLen = scheme.Length();
|
2001-11-16 05:09:13 +03:00
|
|
|
ShiftFromAuthority(shift);
|
|
|
|
}
|
2001-11-27 02:28:44 +03:00
|
|
|
|
|
|
|
// ensure new scheme is lowercase
|
2002-03-06 10:48:55 +03:00
|
|
|
//
|
|
|
|
// XXX the string code unfortunately doesn't provide a ToLowerCase
|
|
|
|
// that operates on a substring.
|
2002-09-13 23:32:45 +04:00
|
|
|
net_ToLowerCase((char *) mSpec.get(), mScheme.mLen);
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetUserPass(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &userpass = PromiseFlatCString(input);
|
|
|
|
|
|
|
|
LOG(("nsStandardURL::SetUserPass [userpass=%s]\n", userpass.get()));
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (mURLType == URLTYPE_NO_AUTHORITY) {
|
2004-11-09 22:23:34 +03:00
|
|
|
if (userpass.IsEmpty())
|
|
|
|
return NS_OK;
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("cannot set user:pass on no-auth url");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
if (mAuthority.mLen < 0) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("uninitialized");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + input.Length() - Userpass(true).Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (userpass.IsEmpty()) {
|
|
|
|
// remove user:pass
|
2008-02-21 04:24:41 +03:00
|
|
|
if (mUsername.mLen > 0) {
|
2001-11-16 05:09:13 +03:00
|
|
|
if (mPassword.mLen > 0)
|
|
|
|
mUsername.mLen += (mPassword.mLen + 1);
|
|
|
|
mUsername.mLen++;
|
|
|
|
mSpec.Cut(mUsername.mPos, mUsername.mLen);
|
|
|
|
mAuthority.mLen -= mUsername.mLen;
|
2002-03-06 10:48:55 +03:00
|
|
|
ShiftFromHost(-mUsername.mLen);
|
2001-11-16 05:09:13 +03:00
|
|
|
mUsername.mLen = -1;
|
|
|
|
mPassword.mLen = -1;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2003-01-10 12:43:32 +03:00
|
|
|
NS_ASSERTION(mHost.mLen >= 0, "uninitialized");
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
nsresult rv;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t usernamePos, passwordPos;
|
|
|
|
int32_t usernameLen, passwordLen;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = mParser->ParseUserInfo(userpass.get(), userpass.Length(),
|
2001-11-16 05:09:13 +03:00
|
|
|
&usernamePos, &usernameLen,
|
|
|
|
&passwordPos, &passwordLen);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// build new user:pass in |buf|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2001-11-16 05:09:13 +03:00
|
|
|
if (usernameLen > 0) {
|
2002-03-06 10:48:55 +03:00
|
|
|
GET_SEGMENT_ENCODER(encoder);
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ignoredOut;
|
2002-03-06 10:48:55 +03:00
|
|
|
usernameLen = encoder.EncodeSegmentCount(userpass.get(),
|
2002-05-08 00:23:37 +04:00
|
|
|
URLSegment(usernamePos,
|
|
|
|
usernameLen),
|
|
|
|
esc_Username | esc_AlwaysCopy,
|
2005-09-13 21:38:20 +04:00
|
|
|
buf, ignoredOut);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (passwordLen >= 0) {
|
|
|
|
buf.Append(':');
|
2002-03-06 10:48:55 +03:00
|
|
|
passwordLen = encoder.EncodeSegmentCount(userpass.get(),
|
2002-05-08 00:23:37 +04:00
|
|
|
URLSegment(passwordPos,
|
|
|
|
passwordLen),
|
|
|
|
esc_Password |
|
2005-09-13 21:38:20 +04:00
|
|
|
esc_AlwaysCopy, buf,
|
|
|
|
ignoredOut);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
if (mUsername.mLen < 0)
|
|
|
|
buf.Append('@');
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t shift = 0;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
if (mUsername.mLen < 0) {
|
2002-03-06 10:48:55 +03:00
|
|
|
// no existing user:pass
|
2001-11-16 05:09:13 +03:00
|
|
|
if (!buf.IsEmpty()) {
|
2002-03-06 10:48:55 +03:00
|
|
|
mSpec.Insert(buf, mHost.mPos);
|
|
|
|
mUsername.mPos = mHost.mPos;
|
|
|
|
shift = buf.Length();
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2002-03-06 10:48:55 +03:00
|
|
|
// replace existing user:pass
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t userpassLen = mUsername.mLen;
|
2001-11-16 05:09:13 +03:00
|
|
|
if (mPassword.mLen >= 0)
|
2002-03-06 10:48:55 +03:00
|
|
|
userpassLen += (mPassword.mLen + 1);
|
|
|
|
mSpec.Replace(mUsername.mPos, userpassLen, buf);
|
|
|
|
shift = buf.Length() - userpassLen;
|
|
|
|
}
|
|
|
|
if (shift) {
|
|
|
|
ShiftFromHost(shift);
|
|
|
|
mAuthority.mLen += shift;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
// update positions and lengths
|
|
|
|
mUsername.mLen = usernameLen;
|
|
|
|
mPassword.mLen = passwordLen;
|
|
|
|
if (passwordLen)
|
|
|
|
mPassword.mPos = mUsername.mPos + mUsername.mLen + 1;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetUsername(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &username = PromiseFlatCString(input);
|
|
|
|
|
|
|
|
LOG(("nsStandardURL::SetUsername [username=%s]\n", username.get()));
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (mURLType == URLTYPE_NO_AUTHORITY) {
|
2004-11-09 22:23:34 +03:00
|
|
|
if (username.IsEmpty())
|
|
|
|
return NS_OK;
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("cannot set username on no-auth url");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (username.IsEmpty())
|
|
|
|
return SetUserPass(username);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + input.Length() - Username().Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2001-11-27 02:28:44 +03:00
|
|
|
|
|
|
|
// escape username if necessary
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2002-03-06 10:48:55 +03:00
|
|
|
GET_SEGMENT_ENCODER(encoder);
|
|
|
|
const nsACString &escUsername =
|
|
|
|
encoder.EncodeSegment(username, esc_Username, buf);
|
2001-11-27 02:28:44 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t shift;
|
2001-11-27 02:28:44 +03:00
|
|
|
|
|
|
|
if (mUsername.mLen < 0) {
|
|
|
|
mUsername.mPos = mAuthority.mPos;
|
2002-03-06 10:48:55 +03:00
|
|
|
mSpec.Insert(escUsername + NS_LITERAL_CSTRING("@"), mUsername.mPos);
|
|
|
|
shift = escUsername.Length() + 1;
|
2001-11-27 02:28:44 +03:00
|
|
|
}
|
|
|
|
else
|
2002-03-06 10:48:55 +03:00
|
|
|
shift = ReplaceSegment(mUsername.mPos, mUsername.mLen, escUsername);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (shift) {
|
2002-03-06 10:48:55 +03:00
|
|
|
mUsername.mLen = escUsername.Length();
|
|
|
|
mAuthority.mLen += shift;
|
2001-11-16 05:09:13 +03:00
|
|
|
ShiftFromPassword(shift);
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetPassword(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &password = PromiseFlatCString(input);
|
|
|
|
|
|
|
|
LOG(("nsStandardURL::SetPassword [password=%s]\n", password.get()));
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (mURLType == URLTYPE_NO_AUTHORITY) {
|
2004-11-09 22:23:34 +03:00
|
|
|
if (password.IsEmpty())
|
|
|
|
return NS_OK;
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("cannot set password on no-auth url");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2008-02-21 04:24:41 +03:00
|
|
|
if (mUsername.mLen <= 0) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("cannot set password without existing username");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + input.Length() - Password().Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (password.IsEmpty()) {
|
2001-11-16 05:09:13 +03:00
|
|
|
if (mPassword.mLen >= 0) {
|
2002-03-06 10:48:55 +03:00
|
|
|
// cut(":password")
|
2001-11-16 05:09:13 +03:00
|
|
|
mSpec.Cut(mPassword.mPos - 1, mPassword.mLen + 1);
|
2002-03-06 10:48:55 +03:00
|
|
|
ShiftFromHost(-(mPassword.mLen + 1));
|
|
|
|
mAuthority.mLen -= (mPassword.mLen + 1);
|
2001-11-16 05:09:13 +03:00
|
|
|
mPassword.mLen = -1;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-11-27 02:28:44 +03:00
|
|
|
// escape password if necessary
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2002-03-06 10:48:55 +03:00
|
|
|
GET_SEGMENT_ENCODER(encoder);
|
|
|
|
const nsACString &escPassword =
|
|
|
|
encoder.EncodeSegment(password, esc_Password, buf);
|
2001-11-27 02:28:44 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t shift;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
|
|
|
if (mPassword.mLen < 0) {
|
|
|
|
mPassword.mPos = mUsername.mPos + mUsername.mLen + 1;
|
|
|
|
mSpec.Insert(NS_LITERAL_CSTRING(":") + escPassword, mPassword.mPos - 1);
|
|
|
|
shift = escPassword.Length() + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
shift = ReplaceSegment(mPassword.mPos, mPassword.mLen, escPassword);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (shift) {
|
2002-03-06 10:48:55 +03:00
|
|
|
mPassword.mLen = escPassword.Length();
|
2002-02-02 00:20:51 +03:00
|
|
|
mAuthority.mLen += shift;
|
2002-03-06 10:48:55 +03:00
|
|
|
ShiftFromHost(shift);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2014-06-10 15:53:54 +04:00
|
|
|
void
|
|
|
|
nsStandardURL::FindHostLimit(nsACString::const_iterator& aStart,
|
|
|
|
nsACString::const_iterator& aEnd)
|
|
|
|
{
|
|
|
|
for (int32_t i = 0; gHostLimitDigits[i]; ++i) {
|
|
|
|
nsACString::const_iterator c(aStart);
|
|
|
|
if (FindCharInReadable(gHostLimitDigits[i], c, aEnd)) {
|
|
|
|
aEnd = c;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2013-09-04 21:07:21 +04:00
|
|
|
nsStandardURL::SetHostPort(const nsACString &aValue)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
2014-05-02 07:31:43 +04:00
|
|
|
// We cannot simply call nsIURI::SetHost because that would treat the name as
|
|
|
|
// an IPv6 address (like http:://[server:443]/). We also cannot call
|
|
|
|
// nsIURI::SetHostPort because that isn't implemented. Sadfaces.
|
2013-09-04 21:07:21 +04:00
|
|
|
|
2014-05-02 07:31:43 +04:00
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
aValue.BeginReading(start);
|
|
|
|
aValue.EndReading(end);
|
|
|
|
nsACString::const_iterator iter(start);
|
|
|
|
bool isIPv6 = false;
|
2013-09-04 21:07:21 +04:00
|
|
|
|
2014-06-10 15:53:54 +04:00
|
|
|
FindHostLimit(start, end);
|
|
|
|
|
2014-05-02 07:31:43 +04:00
|
|
|
if (*start == '[') { // IPv6 address
|
|
|
|
if (!FindCharInReadable(']', iter, end)) {
|
|
|
|
// the ] character is missing
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
// iter now at the ']' character
|
|
|
|
isIPv6 = true;
|
|
|
|
} else {
|
|
|
|
nsACString::const_iterator iter2(start);
|
|
|
|
if (FindCharInReadable(']', iter2, end)) {
|
|
|
|
// if the first char isn't [ then there should be no ] character
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
}
|
2013-09-04 21:07:21 +04:00
|
|
|
|
2014-05-02 07:31:43 +04:00
|
|
|
FindCharInReadable(':', iter, end);
|
|
|
|
|
|
|
|
if (!isIPv6 && iter != end) {
|
|
|
|
nsACString::const_iterator iter2(iter);
|
|
|
|
iter2++; // Skip over the first ':' character
|
|
|
|
if (FindCharInReadable(':', iter2, end)) {
|
|
|
|
// If there is more than one ':' character it suggests an IPv6
|
|
|
|
// The format should be [2001::1]:80 where the port is optional
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = SetHost(Substring(start, iter));
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
// Also set the port if needed.
|
2013-09-04 21:07:21 +04:00
|
|
|
if (iter != end) {
|
2014-05-02 07:31:43 +04:00
|
|
|
iter++;
|
|
|
|
if (iter != end) {
|
|
|
|
nsCString portStr(Substring(iter, end));
|
|
|
|
nsresult rv;
|
|
|
|
int32_t port = portStr.ToInteger(&rv);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
|
|
|
rv = SetPort(port);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
} else {
|
|
|
|
// Failure parsing port number
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// port number is missing
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
2013-09-04 21:07:21 +04:00
|
|
|
}
|
|
|
|
|
2014-05-02 07:31:43 +04:00
|
|
|
return NS_OK;
|
2002-03-06 10:48:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::SetHost(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
2014-06-10 15:53:54 +04:00
|
|
|
const nsPromiseFlatCString &hostname = PromiseFlatCString(input);
|
|
|
|
|
|
|
|
nsACString::const_iterator start, end;
|
|
|
|
hostname.BeginReading(start);
|
|
|
|
hostname.EndReading(end);
|
|
|
|
|
|
|
|
FindHostLimit(start, end);
|
|
|
|
|
2015-11-18 17:25:27 +03:00
|
|
|
const nsCString unescapedHost(Substring(start, end));
|
|
|
|
// Do percent decoding on the the input.
|
|
|
|
nsAutoCString flat;
|
|
|
|
NS_UnescapeURL(unescapedHost.BeginReading(), unescapedHost.Length(),
|
|
|
|
esc_AlwaysCopy | esc_Host, flat);
|
2002-03-06 10:48:55 +03:00
|
|
|
const char *host = flat.get();
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("nsStandardURL::SetHost [host=%s]\n", host));
|
|
|
|
|
|
|
|
if (mURLType == URLTYPE_NO_AUTHORITY) {
|
2004-11-09 22:23:34 +03:00
|
|
|
if (flat.IsEmpty())
|
|
|
|
return NS_OK;
|
2007-05-04 10:42:28 +04:00
|
|
|
NS_WARNING("cannot set host on no-auth url");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
2014-04-23 18:45:58 +04:00
|
|
|
} else {
|
|
|
|
if (flat.IsEmpty()) {
|
|
|
|
// Setting an empty hostname is not allowed for
|
|
|
|
// URLTYPE_STANDARD and URLTYPE_AUTHORITY.
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2011-03-24 06:29:47 +03:00
|
|
|
if (strlen(host) < flat.Length())
|
2007-02-16 04:10:39 +03:00
|
|
|
return NS_ERROR_MALFORMED_URI; // found embedded null
|
|
|
|
|
2006-12-19 18:07:14 +03:00
|
|
|
// For consistency with SetSpec/nsURLParsers, don't allow spaces
|
|
|
|
// in the hostname.
|
|
|
|
if (strchr(host, ' '))
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + strlen(host) - Host().Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2004-04-03 11:32:18 +04:00
|
|
|
mHostEncoding = eEncoding_ASCII;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2015-09-03 22:15:30 +03:00
|
|
|
uint32_t len;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString hostBuf;
|
2015-11-18 17:25:27 +03:00
|
|
|
nsresult rv = NormalizeIDN(flat, hostBuf);
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
return rv;
|
2004-04-03 11:32:18 +04:00
|
|
|
}
|
2015-11-18 17:25:27 +03:00
|
|
|
|
|
|
|
// NormalizeIDN always copies if the call was successful
|
|
|
|
host = hostBuf.get();
|
|
|
|
len = hostBuf.Length();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2015-09-03 22:15:30 +03:00
|
|
|
if (!ValidIPv6orHostname(host, len)) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (mHost.mLen < 0) {
|
2014-04-10 18:23:04 +04:00
|
|
|
int port_length = 0;
|
|
|
|
if (mPort != -1) {
|
|
|
|
nsAutoCString buf;
|
|
|
|
buf.Assign(':');
|
|
|
|
buf.AppendInt(mPort);
|
|
|
|
port_length = buf.Length();
|
|
|
|
}
|
2014-08-06 16:17:53 +04:00
|
|
|
if (mAuthority.mLen > 0) {
|
|
|
|
mHost.mPos = mAuthority.mPos + mAuthority.mLen - port_length;
|
|
|
|
mHost.mLen = 0;
|
|
|
|
} else if (mScheme.mLen > 0) {
|
|
|
|
mHost.mPos = mScheme.mPos + mScheme.mLen + 3;
|
|
|
|
mHost.mLen = 0;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t shift = ReplaceSegment(mHost.mPos, mHost.mLen, host, len);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (shift) {
|
2002-03-06 10:48:55 +03:00
|
|
|
mHost.mLen = len;
|
2001-11-16 05:09:13 +03:00
|
|
|
mAuthority.mLen += shift;
|
|
|
|
ShiftFromPath(shift);
|
|
|
|
}
|
2004-12-03 07:19:48 +03:00
|
|
|
|
|
|
|
// Now canonicalize the host to lowercase
|
|
|
|
net_ToLowerCase(mSpec.BeginWriting() + mHost.mPos, mHost.mLen);
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2016-01-26 19:23:22 +03:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::SetPort(int32_t port)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("nsStandardURL::SetPort [port=%d]\n", port));
|
|
|
|
|
|
|
|
if ((port == mPort) || (mPort == -1 && port == mDefaultPort))
|
|
|
|
return NS_OK;
|
|
|
|
|
2014-01-05 00:42:42 +04:00
|
|
|
// ports must be >= 0
|
|
|
|
if (port < -1) // -1 == use default
|
2011-06-07 20:17:40 +04:00
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
|
2004-11-09 22:23:34 +03:00
|
|
|
if (mURLType == URLTYPE_NO_AUTHORITY) {
|
2007-05-04 10:42:28 +04:00
|
|
|
NS_WARNING("cannot set port on no-auth url");
|
2004-11-09 22:23:34 +03:00
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2016-02-18 06:24:34 +03:00
|
|
|
if (port == mDefaultPort) {
|
|
|
|
port = -1;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
2007-11-27 03:51:57 +03:00
|
|
|
|
2016-02-18 06:24:34 +03:00
|
|
|
ReplacePortInSpec(port);
|
2014-04-10 18:23:04 +04:00
|
|
|
|
2016-02-18 06:24:34 +03:00
|
|
|
mPort = port;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Replaces the existing port in mSpec with aNewPort.
|
|
|
|
*
|
|
|
|
* The caller is responsible for:
|
|
|
|
* - Calling InvalidateCache (since our mSpec is changing).
|
|
|
|
* - Checking whether aNewPort is mDefaultPort (in which case the
|
|
|
|
* caller should pass aNewPort=-1).
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
nsStandardURL::ReplacePortInSpec(int32_t aNewPort)
|
|
|
|
{
|
|
|
|
MOZ_ASSERT(mMutable, "Caller should ensure we're mutable");
|
2016-05-19 20:05:17 +03:00
|
|
|
NS_ASSERTION(aNewPort != mDefaultPort || mDefaultPort == -1,
|
2016-02-18 06:24:34 +03:00
|
|
|
"Caller should check its passed-in value and pass -1 instead of "
|
|
|
|
"mDefaultPort, to avoid encoding default port into mSpec");
|
|
|
|
|
|
|
|
// Create the (possibly empty) string that we're planning to replace:
|
|
|
|
nsAutoCString buf;
|
|
|
|
if (mPort != -1) {
|
2014-04-10 18:23:04 +04:00
|
|
|
buf.Assign(':');
|
|
|
|
buf.AppendInt(mPort);
|
2016-02-18 06:24:34 +03:00
|
|
|
}
|
|
|
|
// Find the position & length of that string:
|
|
|
|
const uint32_t replacedLen = buf.Length();
|
|
|
|
const uint32_t replacedStart =
|
|
|
|
mAuthority.mPos + mAuthority.mLen - replacedLen;
|
2014-04-10 18:23:04 +04:00
|
|
|
|
2016-02-18 06:24:34 +03:00
|
|
|
// Create the (possibly empty) replacement string:
|
|
|
|
if (aNewPort == -1) {
|
|
|
|
buf.Truncate();
|
|
|
|
} else {
|
2014-04-10 18:23:04 +04:00
|
|
|
buf.Assign(':');
|
2016-02-18 06:24:34 +03:00
|
|
|
buf.AppendInt(aNewPort);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
2016-02-18 06:24:34 +03:00
|
|
|
// Perform the replacement:
|
|
|
|
mSpec.Replace(replacedStart, replacedLen, buf);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-02-18 06:24:34 +03:00
|
|
|
// Bookkeeping to reflect the new length:
|
|
|
|
int32_t shift = buf.Length() - replacedLen;
|
|
|
|
mAuthority.mLen += shift;
|
|
|
|
ShiftFromPath(shift);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetPath(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
const nsPromiseFlatCString &path = PromiseFlatCString(input);
|
|
|
|
LOG(("nsStandardURL::SetPath [path=%s]\n", path.get()));
|
|
|
|
|
|
|
|
InvalidateCache();
|
|
|
|
|
|
|
|
if (!path.IsEmpty()) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2001-11-27 02:28:44 +03:00
|
|
|
spec.Assign(mSpec.get(), mPath.mPos);
|
2002-03-06 10:48:55 +03:00
|
|
|
if (path.First() != '/')
|
2001-11-27 02:28:44 +03:00
|
|
|
spec.Append('/');
|
|
|
|
spec.Append(path);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
return SetSpec(spec);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
2008-02-27 01:48:42 +03:00
|
|
|
else if (mPath.mLen >= 1) {
|
2001-11-16 05:09:13 +03:00
|
|
|
mSpec.Cut(mPath.mPos + 1, mPath.mLen - 1);
|
|
|
|
// these contain only a '/'
|
|
|
|
mPath.mLen = 1;
|
|
|
|
mDirectory.mLen = 1;
|
2002-03-06 10:48:55 +03:00
|
|
|
mFilepath.mLen = 1;
|
2001-11-16 05:09:13 +03:00
|
|
|
// these are no longer defined
|
|
|
|
mBasename.mLen = -1;
|
|
|
|
mExtension.mLen = -1;
|
|
|
|
mQuery.mLen = -1;
|
|
|
|
mRef.mLen = -1;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStandardURL::Equals(nsIURI *unknownOther, bool *result)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
|
|
|
return EqualsInternal(unknownOther, eHonorRef, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStandardURL::EqualsExceptRef(nsIURI *unknownOther, bool *result)
|
2011-05-22 05:12:45 +04:00
|
|
|
{
|
|
|
|
return EqualsInternal(unknownOther, eIgnoreRef, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStandardURL::EqualsInternal(nsIURI *unknownOther,
|
|
|
|
nsStandardURL::RefHandlingEnum refHandlingMode,
|
2011-09-29 10:19:26 +04:00
|
|
|
bool *result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(unknownOther);
|
|
|
|
NS_PRECONDITION(result, "null pointer");
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStandardURL> other;
|
2004-12-03 07:19:48 +03:00
|
|
|
nsresult rv = unknownOther->QueryInterface(kThisImplCID,
|
2008-08-11 19:05:58 +04:00
|
|
|
getter_AddRefs(other));
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-22 19:46:26 +04:00
|
|
|
// First, check whether one URIs is an nsIFileURL while the other
|
|
|
|
// is not. If that's the case, they're different.
|
2004-12-03 07:19:48 +03:00
|
|
|
if (mSupportsFileURL != other->mSupportsFileURL) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2004-12-03 07:19:48 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2005-04-22 19:46:26 +04:00
|
|
|
// Next check parts of a URI that, if different, automatically make the
|
|
|
|
// URIs different
|
|
|
|
if (!SegmentIs(mScheme, other->mSpec.get(), other->mScheme) ||
|
|
|
|
// Check for host manually, since conversion to file will
|
|
|
|
// ignore the host!
|
|
|
|
!SegmentIs(mHost, other->mSpec.get(), other->mHost) ||
|
|
|
|
!SegmentIs(mQuery, other->mSpec.get(), other->mQuery) ||
|
|
|
|
!SegmentIs(mUsername, other->mSpec.get(), other->mUsername) ||
|
|
|
|
!SegmentIs(mPassword, other->mSpec.get(), other->mPassword) ||
|
2011-08-22 18:51:52 +04:00
|
|
|
Port() != other->Port()) {
|
2005-04-22 19:46:26 +04:00
|
|
|
// No need to compare files or other URI parts -- these are different
|
|
|
|
// beasties
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2005-04-22 19:46:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2011-05-22 05:12:45 +04:00
|
|
|
|
|
|
|
if (refHandlingMode == eHonorRef &&
|
|
|
|
!SegmentIs(mRef, other->mSpec.get(), other->mRef)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2011-05-22 05:12:45 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2005-04-22 19:46:26 +04:00
|
|
|
|
|
|
|
// Then check for exact identity of URIs. If we have it, they're equal
|
|
|
|
if (SegmentIs(mDirectory, other->mSpec.get(), other->mDirectory) &&
|
|
|
|
SegmentIs(mBasename, other->mSpec.get(), other->mBasename) &&
|
|
|
|
SegmentIs(mExtension, other->mSpec.get(), other->mExtension)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = true;
|
2005-04-22 19:46:26 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// At this point, the URIs are not identical, but they only differ in the
|
|
|
|
// directory/filename/extension. If these are file URLs, then get the
|
|
|
|
// corresponding file objects and compare those, since two filenames that
|
|
|
|
// differ, eg, only in case could still be equal.
|
2004-12-03 07:19:48 +03:00
|
|
|
if (mSupportsFileURL) {
|
|
|
|
// Assume not equal for failure cases... but failures in GetFile are
|
2005-04-22 19:46:26 +04:00
|
|
|
// really failures, more or less, so propagate them to caller.
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2009-10-08 22:19:07 +04:00
|
|
|
|
2004-12-03 07:19:48 +03:00
|
|
|
rv = EnsureFile();
|
2009-10-08 22:19:07 +04:00
|
|
|
nsresult rv2 = other->EnsureFile();
|
|
|
|
// special case for resource:// urls that don't resolve to files
|
|
|
|
if (rv == NS_ERROR_NO_INTERFACE && rv == rv2)
|
|
|
|
return NS_OK;
|
|
|
|
|
2004-12-03 07:19:48 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("nsStandardURL::Equals [this=%p spec=%s] failed to ensure file",
|
|
|
|
this, mSpec.get()));
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(mFile, "EnsureFile() lied!");
|
2009-10-08 22:19:07 +04:00
|
|
|
rv = rv2;
|
2004-12-03 07:19:48 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG(("nsStandardURL::Equals [other=%p spec=%s] other failed to ensure file",
|
2008-08-11 19:05:58 +04:00
|
|
|
other.get(), other->mSpec.get()));
|
2004-12-03 07:19:48 +03:00
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
NS_ASSERTION(other->mFile, "EnsureFile() lied!");
|
|
|
|
return mFile->Equals(other->mFile, result);
|
|
|
|
}
|
2002-10-06 06:20:35 +04:00
|
|
|
|
2005-04-22 19:46:26 +04:00
|
|
|
// The URLs are not identical, and they do not correspond to the
|
|
|
|
// same file, so they are different.
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStandardURL::SchemeIs(const char *scheme, bool *result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(result, "null pointer");
|
|
|
|
|
|
|
|
*result = SegmentIs(mScheme, scheme);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2004-12-02 09:59:34 +03:00
|
|
|
/* virtual */ nsStandardURL*
|
|
|
|
nsStandardURL::StartClone()
|
2004-12-02 01:39:17 +03:00
|
|
|
{
|
2010-07-05 13:42:18 +04:00
|
|
|
nsStandardURL *clone = new nsStandardURL();
|
2004-12-02 09:59:34 +03:00
|
|
|
return clone;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::Clone(nsIURI **result)
|
|
|
|
{
|
2016-07-27 01:38:46 +03:00
|
|
|
return CloneInternal(eHonorRef, EmptyCString(), result);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::CloneIgnoringRef(nsIURI **result)
|
|
|
|
{
|
2016-07-27 01:38:46 +03:00
|
|
|
return CloneInternal(eIgnoreRef, EmptyCString(), result);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::CloneWithNewRef(const nsACString& newRef, nsIURI **result)
|
|
|
|
{
|
|
|
|
return CloneInternal(eReplaceRef, newRef, result);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsStandardURL::CloneInternal(nsStandardURL::RefHandlingEnum refHandlingMode,
|
2016-07-27 01:38:46 +03:00
|
|
|
const nsACString& newRef,
|
2011-05-22 05:12:45 +04:00
|
|
|
nsIURI **result)
|
|
|
|
|
|
|
|
{
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<nsStandardURL> clone = StartClone();
|
2001-11-16 05:09:13 +03:00
|
|
|
if (!clone)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2014-08-11 13:14:03 +04:00
|
|
|
// Copy local members into clone.
|
|
|
|
// Also copies the cached members mFile, mHostA
|
2016-07-27 01:38:46 +03:00
|
|
|
clone->CopyMembers(this, refHandlingMode, newRef, true);
|
2014-08-11 13:14:03 +04:00
|
|
|
|
|
|
|
clone.forget(result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult nsStandardURL::CopyMembers(nsStandardURL * source,
|
2016-07-27 01:38:46 +03:00
|
|
|
nsStandardURL::RefHandlingEnum refHandlingMode, const nsACString& newRef,
|
|
|
|
bool copyCached)
|
2014-08-11 13:14:03 +04:00
|
|
|
{
|
|
|
|
mSpec = source->mSpec;
|
|
|
|
mDefaultPort = source->mDefaultPort;
|
|
|
|
mPort = source->mPort;
|
|
|
|
mScheme = source->mScheme;
|
|
|
|
mAuthority = source->mAuthority;
|
|
|
|
mUsername = source->mUsername;
|
|
|
|
mPassword = source->mPassword;
|
|
|
|
mHost = source->mHost;
|
|
|
|
mPath = source->mPath;
|
|
|
|
mFilepath = source->mFilepath;
|
|
|
|
mDirectory = source->mDirectory;
|
|
|
|
mBasename = source->mBasename;
|
|
|
|
mExtension = source->mExtension;
|
|
|
|
mQuery = source->mQuery;
|
|
|
|
mRef = source->mRef;
|
|
|
|
mOriginCharset = source->mOriginCharset;
|
|
|
|
mURLType = source->mURLType;
|
|
|
|
mParser = source->mParser;
|
|
|
|
mMutable = true;
|
|
|
|
mSupportsFileURL = source->mSupportsFileURL;
|
|
|
|
mHostEncoding = source->mHostEncoding;
|
|
|
|
|
|
|
|
if (copyCached) {
|
|
|
|
mFile = source->mFile;
|
|
|
|
mHostA = source->mHostA ? strdup(source->mHostA) : nullptr;
|
|
|
|
mSpecEncoding = source->mSpecEncoding;
|
|
|
|
} else {
|
|
|
|
// The same state as after calling InvalidateCache()
|
|
|
|
mFile = nullptr;
|
|
|
|
mHostA = nullptr;
|
|
|
|
mSpecEncoding = eEncoding_Unknown;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2011-05-22 05:12:45 +04:00
|
|
|
if (refHandlingMode == eIgnoreRef) {
|
2014-08-11 13:14:03 +04:00
|
|
|
SetRef(EmptyCString());
|
2016-07-27 01:38:46 +03:00
|
|
|
} else if (refHandlingMode == eReplaceRef) {
|
|
|
|
SetRef(newRef);
|
2011-05-22 05:12:45 +04:00
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::Resolve(const nsACString &in, nsACString &out)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
const nsPromiseFlatCString &flat = PromiseFlatCString(in);
|
2002-08-14 00:22:33 +04:00
|
|
|
// filter out unexpected chars "\r\n\t" if necessary
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2016-05-25 17:23:37 +03:00
|
|
|
net_FilterURIString(flat, buf);
|
2016-03-03 17:50:16 +03:00
|
|
|
|
2016-05-25 17:23:37 +03:00
|
|
|
const char *relpath = buf.get();
|
|
|
|
int32_t relpathLen = buf.Length();
|
2016-03-03 17:50:16 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
char *result = nullptr;
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("nsStandardURL::Resolve [this=%p spec=%s relpath=%s]\n",
|
|
|
|
this, mSpec.get(), relpath));
|
|
|
|
|
2002-09-13 23:32:45 +04:00
|
|
|
NS_ASSERTION(mParser, "no parser: unitialized");
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
// NOTE: there is no need for this function to produce normalized
|
|
|
|
// output. normalization will occur when the result is used to
|
|
|
|
// initialize a nsStandardURL object.
|
|
|
|
|
|
|
|
if (mScheme.mLen < 0) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("unable to Resolve URL: this URL not initialized");
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
URLSegment scheme;
|
2012-07-30 18:20:58 +04:00
|
|
|
char *resultPath = nullptr;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool relative = false;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t offset = 0;
|
2003-07-16 23:09:00 +04:00
|
|
|
netCoalesceFlags coalesceFlag = NET_COALESCE_NORMAL;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
// relative urls should never contain a host, so we always want to use
|
|
|
|
// the noauth url parser.
|
2002-08-17 15:56:52 +04:00
|
|
|
// use it to extract a possible scheme
|
2002-10-14 23:20:54 +04:00
|
|
|
rv = mParser->ParseURL(relpath,
|
|
|
|
relpathLen,
|
2002-09-13 23:32:45 +04:00
|
|
|
&scheme.mPos, &scheme.mLen,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr, nullptr,
|
|
|
|
nullptr, nullptr);
|
2002-04-12 02:52:53 +04:00
|
|
|
|
|
|
|
// if the parser fails (for example because there is no valid scheme)
|
|
|
|
// reset the scheme and assume a relative url
|
|
|
|
if (NS_FAILED(rv)) scheme.Reset();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-03-03 17:50:16 +03:00
|
|
|
nsAutoCString protocol(Segment(scheme));
|
|
|
|
nsAutoCString baseProtocol(Scheme());
|
|
|
|
|
|
|
|
// We need to do backslash replacement for the following cases:
|
|
|
|
// 1. The input is an absolute path with a http/https/ftp scheme
|
|
|
|
// 2. The input is a relative path, and the base URL has a http/https/ftp scheme
|
|
|
|
if ((protocol.IsEmpty() && IsSpecialProtocol(baseProtocol)) ||
|
|
|
|
IsSpecialProtocol(protocol)) {
|
|
|
|
|
|
|
|
nsAutoCString::iterator start;
|
|
|
|
nsAutoCString::iterator end;
|
|
|
|
buf.BeginWriting(start);
|
|
|
|
buf.EndWriting(end);
|
|
|
|
while (start != end) {
|
|
|
|
if (*start == '?' || *start == '#') {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (*start == '\\') {
|
|
|
|
*start = '/';
|
|
|
|
}
|
|
|
|
start++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
if (scheme.mLen >= 0) {
|
2003-07-16 23:09:00 +04:00
|
|
|
// add some flags to coalesceFlag if it is an ftp-url
|
|
|
|
// need this later on when coalescing the resulting URL
|
2011-10-17 18:59:28 +04:00
|
|
|
if (SegmentIs(relpath, scheme, "ftp", true)) {
|
2003-07-16 23:09:00 +04:00
|
|
|
coalesceFlag = (netCoalesceFlags) (coalesceFlag
|
|
|
|
| NET_COALESCE_ALLOW_RELATIVE_ROOT
|
|
|
|
| NET_COALESCE_DOUBLE_SLASH_IS_ROOT);
|
|
|
|
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
// this URL appears to be absolute
|
2002-08-17 15:56:52 +04:00
|
|
|
// but try to find out more
|
2011-10-17 18:59:28 +04:00
|
|
|
if (SegmentIs(mScheme, relpath, scheme, true)) {
|
2002-08-17 15:56:52 +04:00
|
|
|
// mScheme and Scheme are the same
|
|
|
|
// but this can still be relative
|
|
|
|
if (nsCRT::strncmp(relpath + scheme.mPos + scheme.mLen,
|
|
|
|
"://",3) == 0) {
|
|
|
|
// now this is really absolute
|
|
|
|
// because a :// follows the scheme
|
2009-03-25 16:19:08 +03:00
|
|
|
result = NS_strdup(relpath);
|
2002-08-17 15:56:52 +04:00
|
|
|
} else {
|
|
|
|
// This is a deprecated form of relative urls like
|
|
|
|
// http:file or http:/path/file
|
|
|
|
// we will support it for now ...
|
2011-10-17 18:59:28 +04:00
|
|
|
relative = true;
|
2002-08-17 15:56:52 +04:00
|
|
|
offset = scheme.mLen + 1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// the schemes are not the same, we are also done
|
|
|
|
// because we have to assume this is absolute
|
2009-03-25 16:19:08 +03:00
|
|
|
result = NS_strdup(relpath);
|
2002-08-17 15:56:52 +04:00
|
|
|
}
|
|
|
|
} else {
|
2003-07-16 23:09:00 +04:00
|
|
|
// add some flags to coalesceFlag if it is an ftp-url
|
|
|
|
// need this later on when coalescing the resulting URL
|
|
|
|
if (SegmentIs(mScheme,"ftp")) {
|
|
|
|
coalesceFlag = (netCoalesceFlags) (coalesceFlag
|
|
|
|
| NET_COALESCE_ALLOW_RELATIVE_ROOT
|
|
|
|
| NET_COALESCE_DOUBLE_SLASH_IS_ROOT);
|
|
|
|
}
|
|
|
|
if (relpath[0] == '/' && relpath[1] == '/') {
|
|
|
|
// this URL //host/path is almost absolute
|
2009-03-25 16:19:08 +03:00
|
|
|
result = AppendToSubstring(mScheme.mPos, mScheme.mLen + 1, relpath);
|
2003-07-16 23:09:00 +04:00
|
|
|
} else {
|
|
|
|
// then it must be relative
|
2011-10-17 18:59:28 +04:00
|
|
|
relative = true;
|
2003-07-16 23:09:00 +04:00
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
2002-08-17 15:56:52 +04:00
|
|
|
if (relative) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = 0;
|
2002-08-17 15:56:52 +04:00
|
|
|
const char *realrelpath = relpath + offset;
|
|
|
|
switch (*realrelpath) {
|
2001-11-16 05:09:13 +03:00
|
|
|
case '/':
|
|
|
|
// overwrite everything after the authority
|
|
|
|
len = mAuthority.mPos + mAuthority.mLen;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
// overwrite the existing ?query and #ref
|
|
|
|
if (mQuery.mLen >= 0)
|
|
|
|
len = mQuery.mPos - 1;
|
|
|
|
else if (mRef.mLen >= 0)
|
|
|
|
len = mRef.mPos - 1;
|
|
|
|
else
|
|
|
|
len = mPath.mPos + mPath.mLen;
|
|
|
|
break;
|
|
|
|
case '#':
|
|
|
|
case '\0':
|
|
|
|
// overwrite the existing #ref
|
|
|
|
if (mRef.mLen < 0)
|
|
|
|
len = mPath.mPos + mPath.mLen;
|
|
|
|
else
|
|
|
|
len = mRef.mPos - 1;
|
|
|
|
break;
|
|
|
|
default:
|
2003-07-16 23:09:00 +04:00
|
|
|
if (coalesceFlag & NET_COALESCE_DOUBLE_SLASH_IS_ROOT) {
|
|
|
|
if (Filename().Equals(NS_LITERAL_CSTRING("%2F"),
|
|
|
|
nsCaseInsensitiveCStringComparator())) {
|
|
|
|
// if ftp URL ends with %2F then simply
|
|
|
|
// append relative part because %2F also
|
|
|
|
// marks the root directory with ftp-urls
|
|
|
|
len = mFilepath.mPos + mFilepath.mLen;
|
|
|
|
} else {
|
|
|
|
// overwrite everything after the directory
|
|
|
|
len = mDirectory.mPos + mDirectory.mLen;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// overwrite everything after the directory
|
|
|
|
len = mDirectory.mPos + mDirectory.mLen;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
2009-03-25 16:19:08 +03:00
|
|
|
result = AppendToSubstring(0, len, realrelpath);
|
2001-11-16 05:09:13 +03:00
|
|
|
// locate result path
|
2009-03-25 16:19:08 +03:00
|
|
|
resultPath = result + mPath.mPos;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
2009-03-25 16:19:08 +03:00
|
|
|
if (!result)
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
if (resultPath)
|
2003-07-16 23:09:00 +04:00
|
|
|
net_CoalesceDirs(coalesceFlag, resultPath);
|
2001-11-16 05:09:13 +03:00
|
|
|
else {
|
|
|
|
// locate result path
|
2009-03-25 16:19:08 +03:00
|
|
|
resultPath = PL_strstr(result, "://");
|
2001-11-16 05:09:13 +03:00
|
|
|
if (resultPath) {
|
|
|
|
resultPath = PL_strchr(resultPath + 3, '/');
|
|
|
|
if (resultPath)
|
2003-07-16 23:09:00 +04:00
|
|
|
net_CoalesceDirs(coalesceFlag,resultPath);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
}
|
2009-03-25 16:19:08 +03:00
|
|
|
out.Adopt(result);
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-27 05:30:17 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetCommonBaseSpec(nsIURI *uri2, nsACString &aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(uri2);
|
|
|
|
|
|
|
|
// if uri's are equal, then return uri as is
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEquals = false;
|
2002-03-27 05:30:17 +03:00
|
|
|
if (NS_SUCCEEDED(Equals(uri2, &isEquals)) && isEquals)
|
|
|
|
return GetSpec(aResult);
|
|
|
|
|
2002-04-03 19:38:53 +04:00
|
|
|
aResult.Truncate();
|
|
|
|
|
2002-03-27 05:30:17 +03:00
|
|
|
// check pre-path; if they don't match, then return empty string
|
|
|
|
nsStandardURL *stdurl2;
|
|
|
|
nsresult rv = uri2->QueryInterface(kThisImplCID, (void **) &stdurl2);
|
|
|
|
isEquals = NS_SUCCEEDED(rv)
|
|
|
|
&& SegmentIs(mScheme, stdurl2->mSpec.get(), stdurl2->mScheme)
|
2004-12-03 07:19:48 +03:00
|
|
|
&& SegmentIs(mHost, stdurl2->mSpec.get(), stdurl2->mHost)
|
2002-03-27 05:30:17 +03:00
|
|
|
&& SegmentIs(mUsername, stdurl2->mSpec.get(), stdurl2->mUsername)
|
|
|
|
&& SegmentIs(mPassword, stdurl2->mSpec.get(), stdurl2->mPassword)
|
|
|
|
&& (Port() == stdurl2->Port());
|
|
|
|
if (!isEquals)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
NS_RELEASE(stdurl2);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// scan for first mismatched character
|
|
|
|
const char *thisIndex, *thatIndex, *startCharPos;
|
|
|
|
startCharPos = mSpec.get() + mDirectory.mPos;
|
|
|
|
thisIndex = startCharPos;
|
|
|
|
thatIndex = stdurl2->mSpec.get() + mDirectory.mPos;
|
|
|
|
while ((*thisIndex == *thatIndex) && *thisIndex)
|
|
|
|
{
|
|
|
|
thisIndex++;
|
|
|
|
thatIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// backup to just after previous slash so we grab an appropriate path
|
|
|
|
// segment such as a directory (not partial segments)
|
2011-08-22 18:51:52 +04:00
|
|
|
// todo: also check for file matches which include '?' and '#'
|
2010-03-22 10:36:38 +03:00
|
|
|
while ((thisIndex != startCharPos) && (*(thisIndex-1) != '/'))
|
2002-03-27 05:30:17 +03:00
|
|
|
thisIndex--;
|
|
|
|
|
|
|
|
// grab spec from beginning to thisIndex
|
|
|
|
aResult = Substring(mSpec, mScheme.mPos, thisIndex - mSpec.get());
|
|
|
|
|
|
|
|
NS_RELEASE(stdurl2);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetRelativeSpec(nsIURI *uri2, nsACString &aResult)
|
|
|
|
{
|
|
|
|
NS_ENSURE_ARG_POINTER(uri2);
|
|
|
|
|
2002-04-03 19:38:53 +04:00
|
|
|
aResult.Truncate();
|
|
|
|
|
2002-03-27 05:30:17 +03:00
|
|
|
// if uri's are equal, then return empty string
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isEquals = false;
|
2002-03-27 05:30:17 +03:00
|
|
|
if (NS_SUCCEEDED(Equals(uri2, &isEquals)) && isEquals)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsStandardURL *stdurl2;
|
|
|
|
nsresult rv = uri2->QueryInterface(kThisImplCID, (void **) &stdurl2);
|
|
|
|
isEquals = NS_SUCCEEDED(rv)
|
|
|
|
&& SegmentIs(mScheme, stdurl2->mSpec.get(), stdurl2->mScheme)
|
|
|
|
&& SegmentIs(mHost, stdurl2->mSpec.get(), stdurl2->mHost)
|
|
|
|
&& SegmentIs(mUsername, stdurl2->mSpec.get(), stdurl2->mUsername)
|
|
|
|
&& SegmentIs(mPassword, stdurl2->mSpec.get(), stdurl2->mPassword)
|
|
|
|
&& (Port() == stdurl2->Port());
|
|
|
|
if (!isEquals)
|
|
|
|
{
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
NS_RELEASE(stdurl2);
|
|
|
|
|
2002-04-03 19:38:53 +04:00
|
|
|
return uri2->GetSpec(aResult);
|
2002-03-27 05:30:17 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// scan for first mismatched character
|
|
|
|
const char *thisIndex, *thatIndex, *startCharPos;
|
|
|
|
startCharPos = mSpec.get() + mDirectory.mPos;
|
|
|
|
thisIndex = startCharPos;
|
|
|
|
thatIndex = stdurl2->mSpec.get() + mDirectory.mPos;
|
2002-04-03 19:38:53 +04:00
|
|
|
|
|
|
|
#ifdef XP_WIN
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isFileScheme = SegmentIs(mScheme, "file");
|
2002-04-03 19:38:53 +04:00
|
|
|
if (isFileScheme)
|
|
|
|
{
|
|
|
|
// on windows, we need to match the first segment of the path
|
|
|
|
// if these don't match then we need to return an absolute path
|
|
|
|
// skip over any leading '/' in path
|
|
|
|
while ((*thisIndex == *thatIndex) && (*thisIndex == '/'))
|
|
|
|
{
|
|
|
|
thisIndex++;
|
|
|
|
thatIndex++;
|
|
|
|
}
|
|
|
|
// look for end of first segment
|
|
|
|
while ((*thisIndex == *thatIndex) && *thisIndex && (*thisIndex != '/'))
|
|
|
|
{
|
|
|
|
thisIndex++;
|
|
|
|
thatIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if we didn't match through the first segment, return absolute path
|
|
|
|
if ((*thisIndex != '/') || (*thatIndex != '/'))
|
|
|
|
{
|
|
|
|
NS_RELEASE(stdurl2);
|
|
|
|
return uri2->GetSpec(aResult);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2002-03-27 05:30:17 +03:00
|
|
|
while ((*thisIndex == *thatIndex) && *thisIndex)
|
|
|
|
{
|
|
|
|
thisIndex++;
|
|
|
|
thatIndex++;
|
|
|
|
}
|
|
|
|
|
|
|
|
// backup to just after previous slash so we grab an appropriate path
|
|
|
|
// segment such as a directory (not partial segments)
|
2011-08-22 18:51:52 +04:00
|
|
|
// todo: also check for file matches with '#' and '?'
|
2002-04-03 19:38:53 +04:00
|
|
|
while ((*(thatIndex-1) != '/') && (thatIndex != startCharPos))
|
|
|
|
thatIndex--;
|
|
|
|
|
2010-09-24 22:21:17 +04:00
|
|
|
const char *limit = mSpec.get() + mFilepath.mPos + mFilepath.mLen;
|
|
|
|
|
2002-04-03 19:38:53 +04:00
|
|
|
// need to account for slashes and add corresponding "../"
|
2010-09-24 22:21:17 +04:00
|
|
|
for (; thisIndex <= limit && *thisIndex; ++thisIndex)
|
2002-04-03 19:38:53 +04:00
|
|
|
{
|
|
|
|
if (*thisIndex == '/')
|
2004-12-04 13:19:29 +03:00
|
|
|
aResult.AppendLiteral("../");
|
2002-04-03 19:38:53 +04:00
|
|
|
}
|
2002-03-27 05:30:17 +03:00
|
|
|
|
|
|
|
// grab spec from thisIndex to end
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t startPos = stdurl2->mScheme.mPos + thatIndex - stdurl2->mSpec.get();
|
2002-04-03 19:38:53 +04:00
|
|
|
aResult.Append(Substring(stdurl2->mSpec, startPos,
|
|
|
|
stdurl2->mSpec.Length() - startPos));
|
2002-03-27 05:30:17 +03:00
|
|
|
|
|
|
|
NS_RELEASE(stdurl2);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsIURL
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetFilePath(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Filepath();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetQuery(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Query();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetRef(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Ref();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2011-08-16 01:18:15 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStandardURL::GetHasRef(bool *result)
|
2011-08-16 01:18:15 +04:00
|
|
|
{
|
|
|
|
*result = (mRef.mLen >= 0);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetDirectory(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Directory();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetFileName(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Filename();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetFileBaseName(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Basename();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// result may contain unescaped UTF-8 characters
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::GetFileExtension(nsACString &result)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
result = Extension();
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetFilePath(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &flat = PromiseFlatCString(input);
|
|
|
|
const char *filepath = flat.get();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
LOG(("nsStandardURL::SetFilePath [filepath=%s]\n", filepath));
|
|
|
|
|
2001-11-27 02:28:44 +03:00
|
|
|
// if there isn't a filepath, then there can't be anything
|
|
|
|
// after the path either. this url is likely uninitialized.
|
2002-03-06 10:48:55 +03:00
|
|
|
if (mFilepath.mLen < 0)
|
|
|
|
return SetPath(flat);
|
2001-11-27 02:28:44 +03:00
|
|
|
|
|
|
|
if (filepath && *filepath) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec;
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t dirPos, basePos, extPos;
|
|
|
|
int32_t dirLen, baseLen, extLen;
|
2001-11-27 02:28:44 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2016-05-25 17:23:38 +03:00
|
|
|
rv = mParser->ParseFilePath(filepath, flat.Length(),
|
2002-09-13 23:32:45 +04:00
|
|
|
&dirPos, &dirLen,
|
|
|
|
&basePos, &baseLen,
|
|
|
|
&extPos, &extLen);
|
2001-11-27 02:28:44 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// build up new candidate spec
|
|
|
|
spec.Assign(mSpec.get(), mPath.mPos);
|
|
|
|
|
|
|
|
// ensure leading '/'
|
|
|
|
if (filepath[dirPos] != '/')
|
|
|
|
spec.Append('/');
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
GET_SEGMENT_ENCODER(encoder);
|
|
|
|
|
|
|
|
// append encoded filepath components
|
2001-11-27 02:28:44 +03:00
|
|
|
if (dirLen > 0)
|
2002-05-08 00:23:37 +04:00
|
|
|
encoder.EncodeSegment(Substring(filepath + dirPos,
|
|
|
|
filepath + dirPos + dirLen),
|
|
|
|
esc_Directory | esc_AlwaysCopy, spec);
|
2001-11-27 02:28:44 +03:00
|
|
|
if (baseLen > 0)
|
2002-05-08 00:23:37 +04:00
|
|
|
encoder.EncodeSegment(Substring(filepath + basePos,
|
|
|
|
filepath + basePos + baseLen),
|
|
|
|
esc_FileBaseName | esc_AlwaysCopy, spec);
|
2001-11-27 02:28:44 +03:00
|
|
|
if (extLen >= 0) {
|
|
|
|
spec.Append('.');
|
|
|
|
if (extLen > 0)
|
2002-05-08 00:23:37 +04:00
|
|
|
encoder.EncodeSegment(Substring(filepath + extPos,
|
|
|
|
filepath + extPos + extLen),
|
|
|
|
esc_FileExtension | esc_AlwaysCopy,
|
|
|
|
spec);
|
2001-11-27 02:28:44 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// compute the ending position of the current filepath
|
2002-03-06 10:48:55 +03:00
|
|
|
if (mFilepath.mLen >= 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t end = mFilepath.mPos + mFilepath.mLen;
|
2001-11-27 02:28:44 +03:00
|
|
|
if (mSpec.Length() > end)
|
|
|
|
spec.Append(mSpec.get() + end, mSpec.Length() - end);
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
return SetSpec(spec);
|
2001-11-27 02:28:44 +03:00
|
|
|
}
|
|
|
|
else if (mPath.mLen > 1) {
|
2002-03-06 10:48:55 +03:00
|
|
|
mSpec.Cut(mPath.mPos + 1, mFilepath.mLen - 1);
|
2011-08-22 18:51:52 +04:00
|
|
|
// left shift query, and ref
|
|
|
|
ShiftFromQuery(1 - mFilepath.mLen);
|
2001-11-27 02:28:44 +03:00
|
|
|
// these contain only a '/'
|
|
|
|
mPath.mLen = 1;
|
|
|
|
mDirectory.mLen = 1;
|
2002-03-06 10:48:55 +03:00
|
|
|
mFilepath.mLen = 1;
|
2001-11-27 02:28:44 +03:00
|
|
|
// these are no longer defined
|
|
|
|
mBasename.mLen = -1;
|
|
|
|
mExtension.mLen = -1;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetQuery(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &flat = PromiseFlatCString(input);
|
|
|
|
const char *query = flat.get();
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("nsStandardURL::SetQuery [query=%s]\n", query));
|
|
|
|
|
|
|
|
if (mPath.mLen < 0)
|
2002-03-06 10:48:55 +03:00
|
|
|
return SetPath(flat);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + input.Length() - Query().Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (!query || !*query) {
|
2001-11-16 05:09:13 +03:00
|
|
|
// remove existing query
|
|
|
|
if (mQuery.mLen >= 0) {
|
|
|
|
// remove query and leading '?'
|
|
|
|
mSpec.Cut(mQuery.mPos - 1, mQuery.mLen + 1);
|
|
|
|
ShiftFromRef(-(mQuery.mLen + 1));
|
|
|
|
mPath.mLen -= (mQuery.mLen + 1);
|
|
|
|
mQuery.mPos = 0;
|
|
|
|
mQuery.mLen = -1;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2016-05-25 17:23:38 +03:00
|
|
|
int32_t queryLen = flat.Length();
|
2001-11-16 05:09:13 +03:00
|
|
|
if (query[0] == '?') {
|
|
|
|
query++;
|
|
|
|
queryLen--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mQuery.mLen < 0) {
|
|
|
|
if (mRef.mLen < 0)
|
|
|
|
mQuery.mPos = mSpec.Length();
|
|
|
|
else
|
|
|
|
mQuery.mPos = mRef.mPos - 1;
|
|
|
|
mSpec.Insert('?', mQuery.mPos);
|
|
|
|
mQuery.mPos++;
|
|
|
|
mQuery.mLen = 0;
|
2002-01-08 05:05:43 +03:00
|
|
|
// the insertion pushes these out by 1
|
|
|
|
mPath.mLen++;
|
|
|
|
mRef.mPos++;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
// encode query if necessary
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool encoded;
|
2006-04-13 18:44:38 +04:00
|
|
|
GET_QUERY_ENCODER(encoder);
|
2005-09-13 21:38:20 +04:00
|
|
|
encoder.EncodeSegmentCount(query, URLSegment(0, queryLen), esc_Query,
|
|
|
|
buf, encoded);
|
|
|
|
if (encoded) {
|
2002-03-06 10:48:55 +03:00
|
|
|
query = buf.get();
|
|
|
|
queryLen = buf.Length();
|
2001-11-27 02:28:44 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t shift = ReplaceSegment(mQuery.mPos, mQuery.mLen, query, queryLen);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
if (shift) {
|
|
|
|
mQuery.mLen = queryLen;
|
|
|
|
mPath.mLen += shift;
|
2008-04-17 12:27:44 +04:00
|
|
|
ShiftFromRef(shift);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetRef(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &flat = PromiseFlatCString(input);
|
|
|
|
const char *ref = flat.get();
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("nsStandardURL::SetRef [ref=%s]\n", ref));
|
|
|
|
|
|
|
|
if (mPath.mLen < 0)
|
2002-03-06 10:48:55 +03:00
|
|
|
return SetPath(flat);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + input.Length() - Ref().Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (!ref || !*ref) {
|
2001-11-16 05:09:13 +03:00
|
|
|
// remove existing ref
|
|
|
|
if (mRef.mLen >= 0) {
|
|
|
|
// remove ref and leading '#'
|
|
|
|
mSpec.Cut(mRef.mPos - 1, mRef.mLen + 1);
|
|
|
|
mPath.mLen -= (mRef.mLen + 1);
|
|
|
|
mRef.mPos = 0;
|
|
|
|
mRef.mLen = -1;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2015-03-18 19:40:35 +03:00
|
|
|
|
|
|
|
int32_t refLen = flat.Length();
|
2001-11-16 05:09:13 +03:00
|
|
|
if (ref[0] == '#') {
|
|
|
|
ref++;
|
|
|
|
refLen--;
|
|
|
|
}
|
2016-05-25 17:23:38 +03:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
if (mRef.mLen < 0) {
|
|
|
|
mSpec.Append('#');
|
2008-06-20 01:39:46 +04:00
|
|
|
++mPath.mLen; // Include the # in the path.
|
2001-11-16 05:09:13 +03:00
|
|
|
mRef.mPos = mSpec.Length();
|
|
|
|
mRef.mLen = 0;
|
|
|
|
}
|
|
|
|
|
2015-03-24 00:28:50 +03:00
|
|
|
// If precent encoding is necessary, `ref` will point to `buf`'s content.
|
|
|
|
// `buf` needs to outlive any use of the `ref` pointer.
|
|
|
|
nsAutoCString buf;
|
2015-01-13 03:11:02 +03:00
|
|
|
if (nsContentUtils::EncodeDecodeURLHash()) {
|
|
|
|
// encode ref if necessary
|
|
|
|
bool encoded;
|
|
|
|
GET_SEGMENT_ENCODER(encoder);
|
|
|
|
encoder.EncodeSegmentCount(ref, URLSegment(0, refLen), esc_Ref,
|
|
|
|
buf, encoded);
|
|
|
|
if (encoded) {
|
|
|
|
ref = buf.get();
|
|
|
|
refLen = buf.Length();
|
|
|
|
}
|
2001-11-27 02:28:44 +03:00
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t shift = ReplaceSegment(mRef.mPos, mRef.mLen, ref, refLen);
|
2009-02-27 21:36:23 +03:00
|
|
|
mPath.mLen += shift;
|
2001-11-16 05:09:13 +03:00
|
|
|
mRef.mLen = refLen;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetDirectory(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
|
|
|
NS_NOTYETIMPLEMENTED("");
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetFileName(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
const nsPromiseFlatCString &flat = PromiseFlatCString(input);
|
|
|
|
const char *filename = flat.get();
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("nsStandardURL::SetFileName [filename=%s]\n", filename));
|
|
|
|
|
|
|
|
if (mPath.mLen < 0)
|
2002-03-06 10:48:55 +03:00
|
|
|
return SetPath(flat);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2016-01-26 19:23:22 +03:00
|
|
|
if (mSpec.Length() + input.Length() - Filename().Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t shift = 0;
|
2002-02-02 00:03:10 +03:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
if (!(filename && *filename)) {
|
|
|
|
// remove the filename
|
|
|
|
if (mBasename.mLen > 0) {
|
|
|
|
if (mExtension.mLen >= 0)
|
|
|
|
mBasename.mLen += (mExtension.mLen + 1);
|
|
|
|
mSpec.Cut(mBasename.mPos, mBasename.mLen);
|
2002-02-02 00:03:10 +03:00
|
|
|
shift = -mBasename.mLen;
|
2001-11-16 05:09:13 +03:00
|
|
|
mBasename.mLen = 0;
|
|
|
|
mExtension.mLen = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2003-07-09 06:28:07 +04:00
|
|
|
nsresult rv;
|
|
|
|
URLSegment basename, extension;
|
|
|
|
|
|
|
|
// let the parser locate the basename and extension
|
2016-05-25 17:23:38 +03:00
|
|
|
rv = mParser->ParseFileName(filename, flat.Length(),
|
2003-07-09 06:28:07 +04:00
|
|
|
&basename.mPos, &basename.mLen,
|
|
|
|
&extension.mPos, &extension.mLen);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if (basename.mLen < 0) {
|
|
|
|
// remove existing filename
|
|
|
|
if (mBasename.mLen >= 0) {
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t len = mBasename.mLen;
|
2003-07-09 06:28:07 +04:00
|
|
|
if (mExtension.mLen >= 0)
|
|
|
|
len += (mExtension.mLen + 1);
|
|
|
|
mSpec.Cut(mBasename.mPos, len);
|
2012-08-22 19:56:38 +04:00
|
|
|
shift = -int32_t(len);
|
2003-07-09 06:28:07 +04:00
|
|
|
mBasename.mLen = 0;
|
|
|
|
mExtension.mLen = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString newFilename;
|
2011-09-29 10:19:26 +04:00
|
|
|
bool ignoredOut;
|
2002-03-06 10:48:55 +03:00
|
|
|
GET_SEGMENT_ENCODER(encoder);
|
|
|
|
basename.mLen = encoder.EncodeSegmentCount(filename, basename,
|
2002-05-08 00:23:37 +04:00
|
|
|
esc_FileBaseName |
|
|
|
|
esc_AlwaysCopy,
|
2005-09-13 21:38:20 +04:00
|
|
|
newFilename,
|
|
|
|
ignoredOut);
|
2003-07-09 06:28:07 +04:00
|
|
|
if (extension.mLen >= 0) {
|
|
|
|
newFilename.Append('.');
|
2002-03-06 10:48:55 +03:00
|
|
|
extension.mLen = encoder.EncodeSegmentCount(filename, extension,
|
2003-07-09 06:28:07 +04:00
|
|
|
esc_FileExtension |
|
|
|
|
esc_AlwaysCopy,
|
2005-09-13 21:38:20 +04:00
|
|
|
newFilename,
|
|
|
|
ignoredOut);
|
2003-07-09 06:28:07 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (mBasename.mLen < 0) {
|
|
|
|
// insert new filename
|
|
|
|
mBasename.mPos = mDirectory.mPos + mDirectory.mLen;
|
|
|
|
mSpec.Insert(newFilename, mBasename.mPos);
|
|
|
|
shift = newFilename.Length();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// replace existing filename
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t oldLen = uint32_t(mBasename.mLen);
|
2003-07-09 06:28:07 +04:00
|
|
|
if (mExtension.mLen >= 0)
|
|
|
|
oldLen += (mExtension.mLen + 1);
|
|
|
|
mSpec.Replace(mBasename.mPos, oldLen, newFilename);
|
|
|
|
shift = newFilename.Length() - oldLen;
|
|
|
|
}
|
|
|
|
|
|
|
|
mBasename.mLen = basename.mLen;
|
|
|
|
mExtension.mLen = extension.mLen;
|
|
|
|
if (mExtension.mLen >= 0)
|
|
|
|
mExtension.mPos = mBasename.mPos + mBasename.mLen + 1;
|
|
|
|
}
|
|
|
|
}
|
2002-02-02 00:03:10 +03:00
|
|
|
if (shift) {
|
2011-08-22 18:51:52 +04:00
|
|
|
ShiftFromQuery(shift);
|
2002-03-06 10:48:55 +03:00
|
|
|
mFilepath.mLen += shift;
|
2002-02-02 00:03:10 +03:00
|
|
|
mPath.mLen += shift;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetFileBaseName(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString extension;
|
2005-02-08 01:20:14 +03:00
|
|
|
nsresult rv = GetFileExtension(extension);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString newFileName(input);
|
2005-02-08 01:20:14 +03:00
|
|
|
|
|
|
|
if (!extension.IsEmpty()) {
|
|
|
|
newFileName.Append('.');
|
|
|
|
newFileName.Append(extension);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetFileName(newFileName);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-03-06 10:48:55 +03:00
|
|
|
nsStandardURL::SetFileExtension(const nsACString &input)
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString newFileName;
|
2005-02-08 01:20:14 +03:00
|
|
|
nsresult rv = GetFileBaseName(newFileName);
|
|
|
|
NS_ENSURE_SUCCESS(rv, rv);
|
|
|
|
|
|
|
|
if (!input.IsEmpty()) {
|
|
|
|
newFileName.Append('.');
|
|
|
|
newFileName.Append(input);
|
|
|
|
}
|
|
|
|
|
|
|
|
return SetFileName(newFileName);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsIFileURL
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2004-12-03 07:19:48 +03:00
|
|
|
nsresult
|
|
|
|
nsStandardURL::EnsureFile()
|
2001-11-16 05:09:13 +03:00
|
|
|
{
|
2004-12-03 07:19:48 +03:00
|
|
|
NS_PRECONDITION(mSupportsFileURL,
|
|
|
|
"EnsureFile() called on a URL that doesn't support files!");
|
|
|
|
if (mFile) {
|
|
|
|
// Nothing to do
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2004-12-03 07:19:48 +03:00
|
|
|
// Parse the spec if we don't have a cached result
|
|
|
|
if (mSpec.IsEmpty()) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("url not initialized");
|
2004-12-03 07:19:48 +03:00
|
|
|
return NS_ERROR_NOT_INITIALIZED;
|
|
|
|
}
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2004-12-03 07:19:48 +03:00
|
|
|
if (!SegmentIs(mScheme, "file")) {
|
2014-02-04 20:55:02 +04:00
|
|
|
NS_WARNING("not a file URL");
|
2004-12-03 07:19:48 +03:00
|
|
|
return NS_ERROR_FAILURE;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
2004-12-03 07:19:48 +03:00
|
|
|
return net_GetFileFromURLSpec(mSpec, getter_AddRefs(mFile));
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetFile(nsIFile **result)
|
|
|
|
{
|
|
|
|
NS_PRECONDITION(mSupportsFileURL,
|
|
|
|
"GetFile() called on a URL that doesn't support files!");
|
|
|
|
nsresult rv = EnsureFile();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2003-07-19 18:58:33 +04:00
|
|
|
if (LOG_ENABLED()) {
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString path;
|
2003-07-19 18:58:33 +04:00
|
|
|
mFile->GetNativePath(path);
|
2001-11-16 05:09:13 +03:00
|
|
|
LOG(("nsStandardURL::GetFile [this=%p spec=%s resulting_path=%s]\n",
|
|
|
|
this, mSpec.get(), path.get()));
|
|
|
|
}
|
|
|
|
|
2003-07-19 18:58:33 +04:00
|
|
|
// clone the file, so the caller can modify it.
|
|
|
|
// XXX nsIFileURL.idl specifies that the consumer must _not_ modify the
|
|
|
|
// nsIFile returned from this method; but it seems that some folks do
|
|
|
|
// (see bug 161921). until we can be sure that all the consumers are
|
|
|
|
// behaving themselves, we'll stay on the safe side and clone the file.
|
|
|
|
// see bug 212724 about fixing the consumers.
|
|
|
|
return mFile->Clone(result);
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::SetFile(nsIFile *file)
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
2007-09-05 14:22:42 +04:00
|
|
|
NS_ENSURE_ARG_POINTER(file);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
nsresult rv;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString url;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2002-09-13 23:32:45 +04:00
|
|
|
rv = net_GetURLSpecFromFile(file, url);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2016-07-13 15:19:33 +03:00
|
|
|
uint32_t oldURLType = mURLType;
|
|
|
|
uint32_t oldDefaultPort = mDefaultPort;
|
|
|
|
rv = Init(nsIStandardURL::URLTYPE_NO_AUTHORITY, -1, url, nullptr, nullptr);
|
2005-10-14 01:50:25 +04:00
|
|
|
|
2016-07-13 15:19:33 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
// Restore the old url type and default port if the call to Init fails.
|
|
|
|
mURLType = oldURLType;
|
|
|
|
mDefaultPort = oldDefaultPort;
|
|
|
|
return rv;
|
|
|
|
}
|
2002-01-30 01:04:16 +03:00
|
|
|
|
|
|
|
// must clone |file| since its value is not guaranteed to remain constant
|
2016-07-13 15:19:33 +03:00
|
|
|
InvalidateCache();
|
|
|
|
if (NS_FAILED(file->Clone(getter_AddRefs(mFile)))) {
|
|
|
|
NS_WARNING("nsIFile::Clone failed");
|
|
|
|
// failure to clone is not fatal (GetFile will generate mFile)
|
|
|
|
mFile = nullptr;
|
2002-01-30 01:04:16 +03:00
|
|
|
}
|
2016-07-13 15:19:33 +03:00
|
|
|
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsIStandardURL
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
inline bool
|
2004-11-04 23:53:24 +03:00
|
|
|
IsUTFCharset(const char *aCharset)
|
|
|
|
{
|
|
|
|
return ((aCharset[0] == 'U' || aCharset[0] == 'u') &&
|
|
|
|
(aCharset[1] == 'T' || aCharset[1] == 't') &&
|
|
|
|
(aCharset[2] == 'F' || aCharset[2] == 'f'));
|
|
|
|
}
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::Init(uint32_t urlType,
|
|
|
|
int32_t defaultPort,
|
2002-03-06 10:48:55 +03:00
|
|
|
const nsACString &spec,
|
|
|
|
const char *charset,
|
2001-11-16 05:09:13 +03:00
|
|
|
nsIURI *baseURI)
|
|
|
|
{
|
2002-03-06 10:48:55 +03:00
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
2015-03-11 07:08:27 +03:00
|
|
|
if (spec.Length() > (uint32_t) net_GetURLMaxLength()) {
|
|
|
|
return NS_ERROR_MALFORMED_URI;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
InvalidateCache();
|
2001-11-16 05:09:13 +03:00
|
|
|
|
|
|
|
switch (urlType) {
|
|
|
|
case URLTYPE_STANDARD:
|
2002-09-13 23:32:45 +04:00
|
|
|
mParser = net_GetStdURLParser();
|
2001-11-16 05:09:13 +03:00
|
|
|
break;
|
|
|
|
case URLTYPE_AUTHORITY:
|
2002-09-13 23:32:45 +04:00
|
|
|
mParser = net_GetAuthURLParser();
|
2001-11-16 05:09:13 +03:00
|
|
|
break;
|
|
|
|
case URLTYPE_NO_AUTHORITY:
|
2002-09-13 23:32:45 +04:00
|
|
|
mParser = net_GetNoAuthURLParser();
|
2001-11-16 05:09:13 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("bad urlType");
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
mDefaultPort = defaultPort;
|
2002-10-06 06:20:35 +04:00
|
|
|
mURLType = urlType;
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2004-11-04 23:53:24 +03:00
|
|
|
mOriginCharset.Truncate();
|
|
|
|
|
2016-04-06 06:13:30 +03:00
|
|
|
//if charset override is absent, use UTF8 as url encoding
|
|
|
|
if (charset != nullptr && *charset != '\0' && !IsUTFCharset(charset)) {
|
2005-01-13 00:45:42 +03:00
|
|
|
mOriginCharset = charset;
|
|
|
|
}
|
2002-03-06 10:48:55 +03:00
|
|
|
|
2016-02-05 16:45:08 +03:00
|
|
|
if (baseURI && net_IsAbsoluteURL(spec)) {
|
|
|
|
baseURI = nullptr;
|
2002-08-30 01:31:55 +04:00
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
if (!baseURI)
|
|
|
|
return SetSpec(spec);
|
2001-11-16 05:09:13 +03:00
|
|
|
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString buf;
|
2002-03-06 10:48:55 +03:00
|
|
|
nsresult rv = baseURI->Resolve(spec, buf);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
return SetSpec(buf);
|
|
|
|
}
|
|
|
|
|
2016-02-18 06:24:36 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::SetDefaultPort(int32_t aNewDefaultPort)
|
|
|
|
{
|
|
|
|
ENSURE_MUTABLE();
|
|
|
|
|
|
|
|
InvalidateCache();
|
|
|
|
|
|
|
|
// If we're already using the new default-port as a custom port, then clear
|
|
|
|
// it off of our mSpec & set mPort to -1, to indicate that we'll be using
|
|
|
|
// the default from now on (which happens to match what we already had).
|
|
|
|
if (mPort == aNewDefaultPort) {
|
|
|
|
ReplacePortInSpec(-1);
|
|
|
|
mPort = -1;
|
|
|
|
}
|
|
|
|
mDefaultPort = aNewDefaultPort;
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStandardURL::GetMutable(bool *value)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
|
|
|
*value = mMutable;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
nsStandardURL::SetMutable(bool value)
|
2002-03-06 10:48:55 +03:00
|
|
|
{
|
2006-05-02 22:54:19 +04:00
|
|
|
NS_ENSURE_ARG(mMutable || !value);
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
mMutable = value;
|
|
|
|
return NS_OK;
|
2001-11-16 05:09:13 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsISerializable
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::Read(nsIObjectInputStream *stream)
|
|
|
|
{
|
2007-09-18 02:23:12 +04:00
|
|
|
NS_PRECONDITION(!mHostA, "Shouldn't have cached ASCII host");
|
|
|
|
NS_PRECONDITION(mSpecEncoding == eEncoding_Unknown,
|
|
|
|
"Shouldn't have spec encoding here");
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t urlType;
|
2004-05-11 22:58:58 +04:00
|
|
|
rv = stream->Read32(&urlType);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
2004-05-11 22:58:58 +04:00
|
|
|
mURLType = urlType;
|
2001-11-16 05:09:13 +03:00
|
|
|
switch (mURLType) {
|
|
|
|
case URLTYPE_STANDARD:
|
2002-09-13 23:32:45 +04:00
|
|
|
mParser = net_GetStdURLParser();
|
2001-11-16 05:09:13 +03:00
|
|
|
break;
|
|
|
|
case URLTYPE_AUTHORITY:
|
2002-09-13 23:32:45 +04:00
|
|
|
mParser = net_GetAuthURLParser();
|
2001-11-16 05:09:13 +03:00
|
|
|
break;
|
|
|
|
case URLTYPE_NO_AUTHORITY:
|
2002-09-13 23:32:45 +04:00
|
|
|
mParser = net_GetNoAuthURLParser();
|
2001-11-16 05:09:13 +03:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("bad urlType");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
rv = stream->Read32((uint32_t *) &mPort);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
rv = stream->Read32((uint32_t *) &mDefaultPort);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-11-14 21:16:31 +03:00
|
|
|
rv = NS_ReadOptionalCString(stream, mSpec);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mScheme);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mAuthority);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mUsername);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mPassword);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = ReadSegment(stream, mHost);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mPath);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = ReadSegment(stream, mFilepath);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mDirectory);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mBasename);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mExtension);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-09-10 13:27:29 +04:00
|
|
|
// handle forward compatibility from older serializations that included mParam
|
|
|
|
URLSegment old_param;
|
|
|
|
rv = ReadSegment(stream, old_param);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
rv = ReadSegment(stream, mQuery);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = ReadSegment(stream, mRef);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-11-14 21:16:31 +03:00
|
|
|
rv = NS_ReadOptionalCString(stream, mOriginCharset);
|
2002-03-06 10:48:55 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool isMutable;
|
2006-05-02 22:54:19 +04:00
|
|
|
rv = stream->ReadBoolean(&isMutable);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mMutable = isMutable;
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool supportsFileURL;
|
2007-09-18 02:23:12 +04:00
|
|
|
rv = stream->ReadBoolean(&supportsFileURL);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
mSupportsFileURL = supportsFileURL;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t hostEncoding;
|
2007-09-18 02:23:12 +04:00
|
|
|
rv = stream->Read32(&hostEncoding);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
if (hostEncoding != eEncoding_ASCII && hostEncoding != eEncoding_UTF8) {
|
|
|
|
NS_WARNING("Unexpected host encoding");
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
}
|
|
|
|
mHostEncoding = hostEncoding;
|
2011-09-10 13:27:29 +04:00
|
|
|
|
|
|
|
// wait until object is set up, then modify path to include the param
|
|
|
|
if (old_param.mLen >= 0) { // note that mLen=0 is ";"
|
|
|
|
// If this wasn't empty, it marks characters between the end of the
|
|
|
|
// file and start of the query - mPath should include the param,
|
|
|
|
// query and ref already. Bump the mFilePath and
|
|
|
|
// directory/basename/extension components to include this.
|
|
|
|
mFilepath.Merge(mSpec, ';', old_param);
|
|
|
|
mDirectory.Merge(mSpec, ';', old_param);
|
|
|
|
mBasename.Merge(mSpec, ';', old_param);
|
|
|
|
mExtension.Merge(mSpec, ';', old_param);
|
|
|
|
}
|
2007-09-18 02:23:12 +04:00
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::Write(nsIObjectOutputStream *stream)
|
|
|
|
{
|
2016-01-26 19:23:22 +03:00
|
|
|
MOZ_ASSERT(mSpec.Length() <= (uint32_t) net_GetURLMaxLength(),
|
|
|
|
"The spec should never be this long, we missed a check.");
|
2001-11-16 05:09:13 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
rv = stream->Write32(mURLType);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
rv = stream->Write32(uint32_t(mPort));
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
rv = stream->Write32(uint32_t(mDefaultPort));
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = NS_WriteOptionalStringZ(stream, mSpec.get());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mScheme);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mAuthority);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mUsername);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mPassword);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = WriteSegment(stream, mHost);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mPath);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = WriteSegment(stream, mFilepath);
|
2001-11-16 05:09:13 +03:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mDirectory);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mBasename);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mExtension);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2011-09-10 13:27:29 +04:00
|
|
|
// for backwards compatibility since we removed mParam. Note that this will mean that
|
|
|
|
// an older browser will read "" for mParam, and the param(s) will be part of mPath (as they
|
|
|
|
// after the removal of special handling). It only matters if you downgrade a browser to before
|
|
|
|
// the patch.
|
|
|
|
URLSegment empty;
|
|
|
|
rv = WriteSegment(stream, empty);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
rv = WriteSegment(stream, mQuery);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = WriteSegment(stream, mRef);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2002-03-06 10:48:55 +03:00
|
|
|
rv = NS_WriteOptionalStringZ(stream, mOriginCharset.get());
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2006-05-02 22:54:19 +04:00
|
|
|
rv = stream->WriteBoolean(mMutable);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2007-09-18 02:23:12 +04:00
|
|
|
rv = stream->WriteBoolean(mSupportsFileURL);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
rv = stream->Write32(mHostEncoding);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// mSpecEncoding and mHostA are just caches that can be recovered as needed.
|
|
|
|
|
2001-11-16 05:09:13 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
2002-05-03 07:01:32 +04:00
|
|
|
|
2010-04-09 10:26:36 +04:00
|
|
|
//---------------------------------------------------------------------------
|
2012-08-23 23:33:46 +04:00
|
|
|
// nsStandardURL::nsIIPCSerializableURI
|
2010-04-09 10:26:36 +04:00
|
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
inline
|
2016-05-19 05:02:57 +03:00
|
|
|
ipc::StandardURLSegment
|
2012-08-23 23:33:46 +04:00
|
|
|
ToIPCSegment(const nsStandardURL::URLSegment& aSegment)
|
|
|
|
{
|
2016-05-19 05:02:57 +03:00
|
|
|
return ipc::StandardURLSegment(aSegment.mPos, aSegment.mLen);
|
2012-08-23 23:33:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
inline
|
|
|
|
nsStandardURL::URLSegment
|
2016-05-19 05:02:57 +03:00
|
|
|
FromIPCSegment(const ipc::StandardURLSegment& aSegment)
|
2012-08-23 23:33:46 +04:00
|
|
|
{
|
|
|
|
return nsStandardURL::URLSegment(aSegment.position(), aSegment.length());
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
nsStandardURL::Serialize(URIParams& aParams)
|
|
|
|
{
|
2016-01-26 19:23:22 +03:00
|
|
|
MOZ_ASSERT(mSpec.Length() <= (uint32_t) net_GetURLMaxLength(),
|
|
|
|
"The spec should never be this long, we missed a check.");
|
2012-08-23 23:33:46 +04:00
|
|
|
StandardURLParams params;
|
|
|
|
|
|
|
|
params.urlType() = mURLType;
|
|
|
|
params.port() = mPort;
|
|
|
|
params.defaultPort() = mDefaultPort;
|
|
|
|
params.spec() = mSpec;
|
|
|
|
params.scheme() = ToIPCSegment(mScheme);
|
|
|
|
params.authority() = ToIPCSegment(mAuthority);
|
|
|
|
params.username() = ToIPCSegment(mUsername);
|
|
|
|
params.password() = ToIPCSegment(mPassword);
|
|
|
|
params.host() = ToIPCSegment(mHost);
|
|
|
|
params.path() = ToIPCSegment(mPath);
|
|
|
|
params.filePath() = ToIPCSegment(mFilepath);
|
|
|
|
params.directory() = ToIPCSegment(mDirectory);
|
|
|
|
params.baseName() = ToIPCSegment(mBasename);
|
|
|
|
params.extension() = ToIPCSegment(mExtension);
|
|
|
|
params.query() = ToIPCSegment(mQuery);
|
|
|
|
params.ref() = ToIPCSegment(mRef);
|
|
|
|
params.originCharset() = mOriginCharset;
|
|
|
|
params.isMutable() = !!mMutable;
|
|
|
|
params.supportsFileURL() = !!mSupportsFileURL;
|
|
|
|
params.hostEncoding() = mHostEncoding;
|
|
|
|
// mSpecEncoding and mHostA are just caches that can be recovered as needed.
|
|
|
|
|
|
|
|
aParams = params;
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
bool
|
2012-08-23 23:33:46 +04:00
|
|
|
nsStandardURL::Deserialize(const URIParams& aParams)
|
2010-04-09 10:26:36 +04:00
|
|
|
{
|
|
|
|
NS_PRECONDITION(!mHostA, "Shouldn't have cached ASCII host");
|
|
|
|
NS_PRECONDITION(mSpecEncoding == eEncoding_Unknown,
|
|
|
|
"Shouldn't have spec encoding here");
|
|
|
|
NS_PRECONDITION(!mFile, "Shouldn't have cached file");
|
2012-08-23 23:33:46 +04:00
|
|
|
|
|
|
|
if (aParams.type() != URIParams::TStandardURLParams) {
|
|
|
|
NS_ERROR("Received unknown parameters from the other process!");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2012-08-23 23:33:46 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
const StandardURLParams& params = aParams.get_StandardURLParams();
|
|
|
|
|
|
|
|
mURLType = params.urlType();
|
2010-04-09 10:26:36 +04:00
|
|
|
switch (mURLType) {
|
|
|
|
case URLTYPE_STANDARD:
|
|
|
|
mParser = net_GetStdURLParser();
|
|
|
|
break;
|
|
|
|
case URLTYPE_AUTHORITY:
|
|
|
|
mParser = net_GetAuthURLParser();
|
|
|
|
break;
|
|
|
|
case URLTYPE_NO_AUTHORITY:
|
|
|
|
mParser = net_GetNoAuthURLParser();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
NS_NOTREACHED("bad urlType");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-09 10:26:36 +04:00
|
|
|
}
|
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
if (params.hostEncoding() != eEncoding_ASCII &&
|
|
|
|
params.hostEncoding() != eEncoding_UTF8) {
|
2010-04-09 10:26:36 +04:00
|
|
|
NS_WARNING("Unexpected host encoding");
|
2011-10-17 18:59:28 +04:00
|
|
|
return false;
|
2010-04-09 10:26:36 +04:00
|
|
|
}
|
|
|
|
|
2012-08-23 23:33:46 +04:00
|
|
|
mPort = params.port();
|
|
|
|
mDefaultPort = params.defaultPort();
|
|
|
|
mSpec = params.spec();
|
|
|
|
mScheme = FromIPCSegment(params.scheme());
|
|
|
|
mAuthority = FromIPCSegment(params.authority());
|
|
|
|
mUsername = FromIPCSegment(params.username());
|
|
|
|
mPassword = FromIPCSegment(params.password());
|
|
|
|
mHost = FromIPCSegment(params.host());
|
|
|
|
mPath = FromIPCSegment(params.path());
|
|
|
|
mFilepath = FromIPCSegment(params.filePath());
|
|
|
|
mDirectory = FromIPCSegment(params.directory());
|
|
|
|
mBasename = FromIPCSegment(params.baseName());
|
|
|
|
mExtension = FromIPCSegment(params.extension());
|
|
|
|
mQuery = FromIPCSegment(params.query());
|
|
|
|
mRef = FromIPCSegment(params.ref());
|
|
|
|
mOriginCharset = params.originCharset();
|
|
|
|
mMutable = params.isMutable();
|
|
|
|
mSupportsFileURL = params.supportsFileURL();
|
|
|
|
mHostEncoding = params.hostEncoding();
|
2010-04-09 10:26:36 +04:00
|
|
|
|
|
|
|
// mSpecEncoding and mHostA are just caches that can be recovered as needed.
|
2012-08-23 23:33:46 +04:00
|
|
|
return true;
|
2010-04-09 10:26:36 +04:00
|
|
|
}
|
|
|
|
|
2002-05-03 07:01:32 +04:00
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsIClassInfo
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::GetInterfaces(uint32_t *count, nsIID * **array)
|
2002-05-03 07:01:32 +04:00
|
|
|
{
|
|
|
|
*count = 0;
|
2012-07-30 18:20:58 +04:00
|
|
|
*array = nullptr;
|
2002-05-03 07:01:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2015-03-29 17:52:54 +03:00
|
|
|
nsStandardURL::GetScriptableHelper(nsIXPCScriptable **_retval)
|
2002-05-03 07:01:32 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*_retval = nullptr;
|
2002-05-03 07:01:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetContractID(char * *aContractID)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aContractID = nullptr;
|
2002-05-03 07:01:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetClassDescription(char * *aClassDescription)
|
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
*aClassDescription = nullptr;
|
2002-05-03 07:01:32 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetClassID(nsCID * *aClassID)
|
|
|
|
{
|
2015-03-27 03:01:12 +03:00
|
|
|
*aClassID = (nsCID*) moz_xmalloc(sizeof(nsCID));
|
2002-05-03 07:01:32 +04:00
|
|
|
if (!*aClassID)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return GetClassIDNoAlloc(*aClassID);
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
nsStandardURL::GetFlags(uint32_t *aFlags)
|
2002-05-03 07:01:32 +04:00
|
|
|
{
|
|
|
|
*aFlags = nsIClassInfo::MAIN_THREAD_ONLY;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsStandardURL::GetClassIDNoAlloc(nsCID *aClassIDNoAlloc)
|
|
|
|
{
|
|
|
|
*aClassIDNoAlloc = kStandardURLCID;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
2012-02-20 07:51:48 +04:00
|
|
|
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
// nsStandardURL::nsISizeOf
|
|
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
size_t
|
2016-05-19 05:02:57 +03:00
|
|
|
nsStandardURL::SizeOfExcludingThis(MallocSizeOf aMallocSizeOf) const
|
2012-02-20 07:51:48 +04:00
|
|
|
{
|
|
|
|
return mSpec.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
|
|
|
mOriginCharset.SizeOfExcludingThisIfUnshared(aMallocSizeOf) +
|
|
|
|
aMallocSizeOf(mHostA);
|
|
|
|
|
|
|
|
// Measurement of the following members may be added later if DMD finds it is
|
|
|
|
// worthwhile:
|
|
|
|
// - mParser
|
|
|
|
// - mFile
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t
|
2016-05-19 05:02:57 +03:00
|
|
|
nsStandardURL::SizeOfIncludingThis(MallocSizeOf aMallocSizeOf) const {
|
2012-02-20 07:51:48 +04:00
|
|
|
return aMallocSizeOf(this) + SizeOfExcludingThis(aMallocSizeOf);
|
|
|
|
}
|
2016-05-19 05:02:57 +03:00
|
|
|
|
|
|
|
} // namespace net
|
|
|
|
} // namespace mozilla
|