2002-06-26 05:33:07 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
2001-09-29 00:14:13 +04:00
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-12-29 23:55:42 +03:00
|
|
|
*
|
2004-04-18 18:21:17 +04:00
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
1999-12-29 23:55:42 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
1999-12-29 23:55:42 +03:00
|
|
|
*
|
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2003-08-06 00:09:21 +04:00
|
|
|
* The Initial Developer of the Original Code is
|
2001-09-29 00:14:13 +04:00
|
|
|
* Netscape Communications Corporation.
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
1999-12-29 23:55:42 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
1999-12-29 23:55:42 +03:00
|
|
|
* Pierre Phaneuf <pp@ludusdesign.com>
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
2004-04-18 18:21:17 +04:00
|
|
|
* either of the GNU General Public License Version 2 or later (the "GPL"),
|
|
|
|
* or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
2001-09-29 00:14:13 +04:00
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
2004-04-18 18:21:17 +04:00
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
2001-09-29 00:14:13 +04:00
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
2004-04-18 18:21:17 +04:00
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
2001-09-29 00:14:13 +04:00
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-12-29 23:55:42 +03:00
|
|
|
|
|
|
|
#include "nsID.h"
|
|
|
|
#include "nsCRT.h"
|
2001-09-29 12:28:41 +04:00
|
|
|
#include "nsReadableUtils.h"
|
1999-12-29 23:55:42 +03:00
|
|
|
#include "nsIInputStream.h"
|
2006-07-21 20:28:51 +04:00
|
|
|
#include "nsUnicharInputStream.h"
|
1999-12-29 23:55:42 +03:00
|
|
|
#include "pratom.h"
|
2000-05-02 09:08:39 +04:00
|
|
|
#include "nsEnumeratorUtils.h"
|
2001-09-30 08:01:15 +04:00
|
|
|
#include "nsReadableUtils.h"
|
2002-06-26 05:33:07 +04:00
|
|
|
#include "nsPrintfCString.h"
|
1999-12-29 23:55:42 +03:00
|
|
|
|
2002-06-26 05:33:07 +04:00
|
|
|
#define PL_ARENA_CONST_ALIGN_MASK 3
|
|
|
|
#include "nsPersistentProperties.h"
|
|
|
|
#include "nsIProperties.h"
|
2006-08-08 22:18:50 +04:00
|
|
|
#include "nsISupportsArray.h"
|
2002-06-26 05:33:07 +04:00
|
|
|
#include "nsProperties.h"
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
struct PropertyTableEntry : public PLDHashEntryHdr
|
2002-06-26 05:33:07 +04:00
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
// both of these are arena-allocated
|
|
|
|
const char *mKey;
|
|
|
|
const PRUnichar *mValue;
|
2002-06-26 05:33:07 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
static PRUnichar*
|
|
|
|
ArenaStrdup(const nsAFlatString& aString, PLArenaPool* aArena)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
void *mem;
|
|
|
|
// add one to include the null terminator
|
|
|
|
PRInt32 len = (aString.Length()+1) * sizeof(PRUnichar);
|
|
|
|
PL_ARENA_ALLOCATE(mem, aArena, len);
|
|
|
|
NS_ASSERTION(mem, "Couldn't allocate space!\n");
|
|
|
|
if (mem) {
|
|
|
|
memcpy(mem, aString.get(), len);
|
|
|
|
}
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<PRUnichar*>(mem);
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2002-06-26 05:33:07 +04:00
|
|
|
static char*
|
|
|
|
ArenaStrdup(const nsAFlatCString& aString, PLArenaPool* aArena)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
void *mem;
|
|
|
|
// add one to include the null terminator
|
|
|
|
PRInt32 len = (aString.Length()+1) * sizeof(char);
|
|
|
|
PL_ARENA_ALLOCATE(mem, aArena, len);
|
|
|
|
NS_ASSERTION(mem, "Couldn't allocate space!\n");
|
|
|
|
if (mem)
|
|
|
|
memcpy(mem, aString.get(), len);
|
2007-07-08 11:08:04 +04:00
|
|
|
return static_cast<char*>(mem);
|
2002-06-26 05:33:07 +04:00
|
|
|
}
|
|
|
|
|
2003-04-04 19:10:37 +04:00
|
|
|
static const struct PLDHashTableOps property_HashTableOps = {
|
2003-08-06 00:09:21 +04:00
|
|
|
PL_DHashAllocTable,
|
|
|
|
PL_DHashFreeTable,
|
|
|
|
PL_DHashStringKey,
|
|
|
|
PL_DHashMatchStringKey,
|
|
|
|
PL_DHashMoveEntryStub,
|
|
|
|
PL_DHashClearEntryStub,
|
|
|
|
PL_DHashFinalizeStub,
|
|
|
|
nsnull,
|
2002-06-26 05:33:07 +04:00
|
|
|
};
|
|
|
|
|
1999-12-29 23:55:42 +03:00
|
|
|
nsPersistentProperties::nsPersistentProperties()
|
2003-07-15 01:07:31 +04:00
|
|
|
: mIn(nsnull)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2007-07-08 11:08:04 +04:00
|
|
|
mSubclass = static_cast<nsIPersistentProperties*>(this);
|
2003-08-06 00:09:21 +04:00
|
|
|
mTable.ops = nsnull;
|
|
|
|
PL_INIT_ARENA_POOL(&mArena, "PersistentPropertyArena", 2048);
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsPersistentProperties::~nsPersistentProperties()
|
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
PL_FinishArenaPool(&mArena);
|
|
|
|
if (mTable.ops)
|
|
|
|
PL_DHashTableFinish(&mTable);
|
2003-07-15 01:07:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
nsPersistentProperties::Init()
|
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
if (!PL_DHashTableInit(&mTable, &property_HashTableOps, nsnull,
|
|
|
|
sizeof(PropertyTableEntry), 20)) {
|
|
|
|
mTable.ops = nsnull;
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
}
|
|
|
|
return NS_OK;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsPersistentProperties::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
nsPersistentProperties* props = new nsPersistentProperties();
|
|
|
|
if (props == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(props);
|
|
|
|
nsresult rv = props->Init();
|
|
|
|
if (NS_SUCCEEDED(rv))
|
|
|
|
rv = props->QueryInterface(aIID, aResult);
|
|
|
|
|
|
|
|
NS_RELEASE(props);
|
|
|
|
return rv;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2008-02-21 23:39:23 +03:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsPersistentProperties, nsIPersistentProperties, nsIProperties)
|
|
|
|
|
2003-02-04 08:43:57 +03:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPersistentProperties::Load(nsIInputStream *aIn)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2003-02-04 08:43:57 +03:00
|
|
|
PRInt32 c;
|
2006-07-21 20:28:51 +04:00
|
|
|
nsresult ret = nsSimpleUnicharStreamFactory::GetInstance()->
|
|
|
|
CreateInstanceFromUTF8Stream(aIn, &mIn);
|
2003-08-06 00:09:21 +04:00
|
|
|
|
2003-02-04 08:43:57 +03:00
|
|
|
if (ret != NS_OK) {
|
|
|
|
NS_WARNING("NS_NewUTF8ConverterStream failed");
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
c = Read();
|
|
|
|
while (1) {
|
|
|
|
c = SkipWhiteSpace(c);
|
|
|
|
if (c < 0) {
|
1999-12-29 23:55:42 +03:00
|
|
|
break;
|
|
|
|
}
|
2003-02-04 08:43:57 +03:00
|
|
|
else if ((c == '#') || (c == '!')) {
|
|
|
|
c = SkipLine(c);
|
|
|
|
continue;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
else {
|
2003-02-04 08:43:57 +03:00
|
|
|
nsAutoString key;
|
|
|
|
while ((c >= 0) && (c != '=') && (c != ':')) {
|
|
|
|
key.Append(PRUnichar(c));
|
|
|
|
c = Read();
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
2003-02-04 08:43:57 +03:00
|
|
|
if (c < 0) {
|
|
|
|
break;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
2003-02-04 08:43:57 +03:00
|
|
|
static const char trimThese[] = " \t";
|
|
|
|
key.Trim(trimThese, PR_FALSE, PR_TRUE);
|
|
|
|
c = Read();
|
2007-04-29 21:51:38 +04:00
|
|
|
nsAutoString value, tempValue;
|
|
|
|
while ((c >= 0) && (c != '\r') && (c != '\n')) {
|
|
|
|
if (c == '\\') {
|
|
|
|
c = Read();
|
|
|
|
switch(c) {
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
|
|
|
// Only skip first EOL characters and then next line's
|
|
|
|
// whitespace characters. Skipping all EOL characters
|
|
|
|
// and all upcoming whitespace is too agressive.
|
|
|
|
if (c == '\r')
|
|
|
|
c = Read();
|
|
|
|
if (c == '\n')
|
|
|
|
c = Read();
|
|
|
|
while (c == ' ' || c == '\t')
|
|
|
|
c = Read();
|
|
|
|
continue;
|
|
|
|
default:
|
|
|
|
tempValue.Append((PRUnichar) '\\');
|
|
|
|
tempValue.Append((PRUnichar) c);
|
|
|
|
} // switch(c)
|
|
|
|
} else {
|
|
|
|
tempValue.Append((PRUnichar) c);
|
|
|
|
}
|
|
|
|
c = Read();
|
|
|
|
}
|
|
|
|
tempValue.Trim(trimThese, PR_TRUE, PR_TRUE);
|
|
|
|
|
2003-02-04 08:43:57 +03:00
|
|
|
PRUint32 state = 0;
|
|
|
|
PRUnichar uchar = 0;
|
2007-04-29 21:51:38 +04:00
|
|
|
for (PRUint32 i = 0; i < tempValue.Length(); ++i) {
|
|
|
|
PRUnichar ch = tempValue[i];
|
2003-02-04 08:43:57 +03:00
|
|
|
switch(state) {
|
|
|
|
case 0:
|
2007-04-29 21:51:38 +04:00
|
|
|
if (ch == '\\') {
|
|
|
|
++i;
|
|
|
|
if (i == tempValue.Length())
|
|
|
|
break;
|
|
|
|
ch = tempValue[i];
|
|
|
|
switch(ch) {
|
2003-02-04 08:43:57 +03:00
|
|
|
case 'u':
|
|
|
|
case 'U':
|
|
|
|
state = 1;
|
|
|
|
uchar=0;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
value.Append(PRUnichar('\t'));
|
|
|
|
break;
|
|
|
|
case 'n':
|
|
|
|
value.Append(PRUnichar('\n'));
|
|
|
|
break;
|
|
|
|
case 'r':
|
|
|
|
value.Append(PRUnichar('\r'));
|
|
|
|
break;
|
|
|
|
default:
|
2007-04-29 21:51:38 +04:00
|
|
|
value.Append(ch);
|
|
|
|
} // switch(ch)
|
2003-02-04 08:43:57 +03:00
|
|
|
} else {
|
2007-04-29 21:51:38 +04:00
|
|
|
value.Append(ch);
|
2003-02-04 08:43:57 +03:00
|
|
|
}
|
2007-04-29 21:51:38 +04:00
|
|
|
continue;
|
2003-02-04 08:43:57 +03:00
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
2007-04-29 21:51:38 +04:00
|
|
|
if (('0' <= ch) && (ch <= '9')) {
|
|
|
|
uchar = (uchar << 4) | (ch - '0');
|
2003-02-04 08:43:57 +03:00
|
|
|
state++;
|
2007-04-29 21:51:38 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (('a' <= ch) && (ch <= 'f')) {
|
|
|
|
uchar = (uchar << 4) | (ch - 'a' + 0x0a);
|
2003-02-04 08:43:57 +03:00
|
|
|
state++;
|
2007-04-29 21:51:38 +04:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (('A' <= ch) && (ch <= 'F')) {
|
|
|
|
uchar = (uchar << 4) | (ch - 'A' + 0x0a);
|
2003-02-04 08:43:57 +03:00
|
|
|
state++;
|
2007-04-29 21:51:38 +04:00
|
|
|
continue;
|
2003-02-04 08:43:57 +03:00
|
|
|
}
|
2007-04-29 21:51:38 +04:00
|
|
|
// if not hex digit, fall through
|
2003-02-04 08:43:57 +03:00
|
|
|
case 5:
|
|
|
|
value.Append((PRUnichar) uchar);
|
|
|
|
state = 0;
|
2007-04-29 21:51:38 +04:00
|
|
|
--i;
|
|
|
|
break;
|
2003-02-04 08:43:57 +03:00
|
|
|
}
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
2003-08-06 00:09:21 +04:00
|
|
|
if (state != 0) {
|
2003-02-04 08:43:57 +03:00
|
|
|
value.Append((PRUnichar) uchar);
|
|
|
|
state = 0;
|
2000-07-11 23:14:59 +04:00
|
|
|
}
|
2007-04-29 21:51:38 +04:00
|
|
|
|
2003-02-04 08:43:57 +03:00
|
|
|
nsAutoString oldValue;
|
2006-02-03 17:18:39 +03:00
|
|
|
mSubclass->SetStringProperty(NS_ConvertUTF16toUTF8(key), value, oldValue);
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
2003-02-03 17:59:39 +03:00
|
|
|
}
|
2003-02-04 08:43:57 +03:00
|
|
|
mIn->Close();
|
|
|
|
NS_RELEASE(mIn);
|
1999-12-29 23:55:42 +03:00
|
|
|
|
2003-01-22 08:15:40 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPersistentProperties::SetStringProperty(const nsACString& aKey,
|
|
|
|
const nsAString& aNewValue,
|
|
|
|
nsAString& aOldValue)
|
|
|
|
{
|
2003-02-04 08:43:57 +03:00
|
|
|
#if 0
|
|
|
|
cout << "will add " << aKey.get() << "=" <<
|
|
|
|
NS_LossyConvertUCS2ToASCII(aNewValue).get() << endl;
|
|
|
|
#endif
|
|
|
|
|
2002-08-30 21:13:34 +04:00
|
|
|
const nsAFlatCString& flatKey = PromiseFlatCString(aKey);
|
2003-08-06 00:09:21 +04:00
|
|
|
PropertyTableEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<PropertyTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mTable, flatKey.get(), PL_DHASH_ADD));
|
2002-06-26 05:33:07 +04:00
|
|
|
|
|
|
|
if (entry->mKey) {
|
2003-08-06 00:09:21 +04:00
|
|
|
aOldValue = entry->mValue;
|
|
|
|
NS_WARNING(nsPrintfCString(aKey.Length() + 30,
|
|
|
|
"the property %s already exists\n",
|
|
|
|
flatKey.get()).get());
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2002-06-26 05:33:07 +04:00
|
|
|
entry->mKey = ArenaStrdup(flatKey, &mArena);
|
|
|
|
entry->mValue = ArenaStrdup(PromiseFlatString(aNewValue), &mArena);
|
2003-08-06 00:09:21 +04:00
|
|
|
|
1999-12-29 23:55:42 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-08-30 21:13:34 +04:00
|
|
|
nsPersistentProperties::Save(nsIOutputStream* aOut, const nsACString& aHeader)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
nsPersistentProperties::Subclass(nsIPersistentProperties* aSubclass)
|
|
|
|
{
|
|
|
|
if (aSubclass) {
|
|
|
|
mSubclass = aSubclass;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-08-30 21:13:34 +04:00
|
|
|
nsPersistentProperties::GetStringProperty(const nsACString& aKey,
|
|
|
|
nsAString& aValue)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2002-08-30 21:13:34 +04:00
|
|
|
const nsAFlatCString& flatKey = PromiseFlatCString(aKey);
|
2002-06-26 05:33:07 +04:00
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
PropertyTableEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<PropertyTableEntry*>
|
|
|
|
(PL_DHashTableOperate(&mTable, flatKey.get(), PL_DHASH_LOOKUP));
|
2002-06-26 05:33:07 +04:00
|
|
|
|
2002-06-26 07:43:43 +04:00
|
|
|
if (PL_DHASH_ENTRY_IS_FREE(entry))
|
2002-06-26 05:33:07 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
1999-12-29 23:55:42 +03:00
|
|
|
|
2002-06-26 05:33:07 +04:00
|
|
|
aValue = entry->mValue;
|
|
|
|
return NS_OK;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2002-06-26 05:33:07 +04:00
|
|
|
PR_STATIC_CALLBACK(PLDHashOperator)
|
|
|
|
AddElemToArray(PLDHashTable* table, PLDHashEntryHdr *hdr,
|
|
|
|
PRUint32 i, void *arg)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2002-06-26 05:33:07 +04:00
|
|
|
nsISupportsArray *propArray = (nsISupportsArray *) arg;
|
2003-08-06 00:09:21 +04:00
|
|
|
PropertyTableEntry* entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<PropertyTableEntry*>(hdr);
|
2003-08-06 00:09:21 +04:00
|
|
|
|
2001-12-04 04:10:43 +03:00
|
|
|
nsPropertyElement *element =
|
2002-08-30 21:13:34 +04:00
|
|
|
new nsPropertyElement(nsDependentCString(entry->mKey),
|
|
|
|
nsDependentString(entry->mValue));
|
1999-12-29 23:55:42 +03:00
|
|
|
if (!element)
|
2002-06-26 05:33:07 +04:00
|
|
|
return PL_DHASH_STOP;
|
1999-12-29 23:55:42 +03:00
|
|
|
|
|
|
|
propArray->InsertElementAt(element, i);
|
|
|
|
|
2002-06-26 05:33:07 +04:00
|
|
|
return PL_DHASH_NEXT;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2000-05-02 09:08:39 +04:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-08-30 21:13:34 +04:00
|
|
|
nsPersistentProperties::Enumerate(nsISimpleEnumerator** aResult)
|
2000-05-02 09:08:39 +04:00
|
|
|
{
|
2005-11-17 00:27:11 +03:00
|
|
|
nsCOMPtr<nsISupportsArray> propArray;
|
|
|
|
nsresult rv = NS_NewISupportsArray(getter_AddRefs(propArray));
|
|
|
|
if (NS_FAILED(rv))
|
2000-05-02 09:08:39 +04:00
|
|
|
return rv;
|
1999-12-29 23:55:42 +03:00
|
|
|
|
2005-11-17 00:27:11 +03:00
|
|
|
// We know the necessary size; we can avoid growing it while adding elements
|
|
|
|
if (!propArray->SizeTo(mTable.entryCount))
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2000-05-02 09:08:39 +04:00
|
|
|
// Step through hash entries populating a transient array
|
2002-06-26 05:33:07 +04:00
|
|
|
PRUint32 n =
|
2003-08-06 00:09:21 +04:00
|
|
|
PL_DHashTableEnumerate(&mTable, AddElemToArray, (void *)propArray);
|
|
|
|
if (n < mTable.entryCount)
|
1999-12-29 23:55:42 +03:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
return NS_NewArrayEnumerator(aResult, propArray);
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2000-05-02 09:08:39 +04:00
|
|
|
|
1999-12-29 23:55:42 +03:00
|
|
|
PRInt32
|
|
|
|
nsPersistentProperties::Read()
|
|
|
|
{
|
|
|
|
PRUnichar c;
|
|
|
|
PRUint32 nRead;
|
|
|
|
nsresult ret;
|
|
|
|
|
2003-03-06 22:54:51 +03:00
|
|
|
ret = mIn->Read(&c, 1, &nRead);
|
1999-12-29 23:55:42 +03:00
|
|
|
if (ret == NS_OK && nRead == 1) {
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-02-04 08:43:57 +03:00
|
|
|
#define IS_WHITE_SPACE(c) \
|
|
|
|
(((c) == ' ') || ((c) == '\t') || ((c) == '\r') || ((c) == '\n'))
|
|
|
|
|
1999-12-29 23:55:42 +03:00
|
|
|
PRInt32
|
|
|
|
nsPersistentProperties::SkipWhiteSpace(PRInt32 c)
|
|
|
|
{
|
2003-09-25 20:28:06 +04:00
|
|
|
while (IS_WHITE_SPACE(c)) {
|
1999-12-29 23:55:42 +03:00
|
|
|
c = Read();
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
PRInt32
|
|
|
|
nsPersistentProperties::SkipLine(PRInt32 c)
|
|
|
|
{
|
|
|
|
while ((c >= 0) && (c != '\r') && (c != '\n')) {
|
|
|
|
c = Read();
|
|
|
|
}
|
|
|
|
if (c == '\r') {
|
|
|
|
c = Read();
|
|
|
|
}
|
|
|
|
if (c == '\n') {
|
|
|
|
c = Read();
|
|
|
|
}
|
|
|
|
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
2003-08-06 00:09:21 +04:00
|
|
|
// XXX Some day we'll unify the nsIPersistentProperties interface with
|
1999-12-29 23:55:42 +03:00
|
|
|
// nsIProperties, but until now...
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
NS_IMETHODIMP
|
2002-08-27 00:36:44 +04:00
|
|
|
nsPersistentProperties::Get(const char* prop, const nsIID & uuid, void* *result)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
NS_IMETHODIMP
|
2002-08-27 00:36:44 +04:00
|
|
|
nsPersistentProperties::Set(const char* prop, nsISupports* value)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
2003-08-06 00:09:21 +04:00
|
|
|
NS_IMETHODIMP
|
2002-08-27 00:36:44 +04:00
|
|
|
nsPersistentProperties::Undefine(const char* prop)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
|
|
|
}
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
NS_IMETHODIMP
|
2002-08-27 00:36:44 +04:00
|
|
|
nsPersistentProperties::Has(const char* prop, PRBool *result)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2003-02-04 08:43:57 +03:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2003-08-06 00:09:21 +04:00
|
|
|
NS_IMETHODIMP
|
2002-08-27 00:36:44 +04:00
|
|
|
nsPersistentProperties::GetKeys(PRUint32 *count, char ***keys)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2002-08-27 00:36:44 +04:00
|
|
|
return NS_ERROR_NOT_IMPLEMENTED;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// PropertyElement
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
NS_METHOD
|
|
|
|
nsPropertyElement::Create(nsISupports *aOuter, REFNSIID aIID, void **aResult)
|
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
if (aOuter)
|
|
|
|
return NS_ERROR_NO_AGGREGATION;
|
|
|
|
nsPropertyElement* propElem = new nsPropertyElement();
|
|
|
|
if (propElem == nsnull)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
NS_ADDREF(propElem);
|
|
|
|
nsresult rv = propElem->QueryInterface(aIID, aResult);
|
|
|
|
NS_RELEASE(propElem);
|
|
|
|
return rv;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
2008-02-21 23:39:23 +03:00
|
|
|
NS_IMPL_ISUPPORTS1(nsPropertyElement, nsIPropertyElement)
|
|
|
|
|
1999-12-29 23:55:42 +03:00
|
|
|
NS_IMETHODIMP
|
2002-08-30 21:13:34 +04:00
|
|
|
nsPropertyElement::GetKey(nsACString& aReturnKey)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2002-08-30 21:13:34 +04:00
|
|
|
aReturnKey = mKey;
|
|
|
|
return NS_OK;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-08-30 21:13:34 +04:00
|
|
|
nsPropertyElement::GetValue(nsAString& aReturnValue)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2002-08-30 21:13:34 +04:00
|
|
|
aReturnValue = mValue;
|
|
|
|
return NS_OK;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-08-30 21:13:34 +04:00
|
|
|
nsPropertyElement::SetKey(const nsACString& aKey)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2000-05-02 09:08:39 +04:00
|
|
|
mKey = aKey;
|
|
|
|
return NS_OK;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2002-08-30 21:13:34 +04:00
|
|
|
nsPropertyElement::SetValue(const nsAString& aValue)
|
1999-12-29 23:55:42 +03:00
|
|
|
{
|
2000-05-02 09:08:39 +04:00
|
|
|
mValue = aValue;
|
|
|
|
return NS_OK;
|
1999-12-29 23:55:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|