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 *****
|
|
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
1999-12-29 23:55:42 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/NPL/
|
1999-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
|
2003-08-06 00:09:21 +04:00
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
2001-09-29 00:14:13 +04:00
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
1999-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"
|
|
|
|
#include "nsIUnicharInputStream.h"
|
|
|
|
#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"
|
|
|
|
#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);
|
|
|
|
}
|
|
|
|
return NS_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);
|
|
|
|
return NS_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_DHashGetKeyStub,
|
|
|
|
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
|
|
|
{
|
2003-08-06 00:09:21 +04:00
|
|
|
mSubclass = NS_STATIC_CAST(nsIPersistentProperties*, this);
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2000-05-27 00:59:04 +04:00
|
|
|
NS_IMPL_THREADSAFE_ISUPPORTS2(nsPersistentProperties, nsIPersistentProperties, nsIProperties)
|
1999-12-29 23:55:42 +03:00
|
|
|
|
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;
|
|
|
|
nsresult ret = NS_NewUTF8ConverterStream(&mIn, aIn, 0);
|
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();
|
|
|
|
nsAutoString value;
|
|
|
|
PRUint32 state = 0;
|
|
|
|
PRUnichar uchar = 0;
|
|
|
|
while ((c >= 0) && (c != '\r') && (c != '\n')) {
|
|
|
|
switch(state) {
|
|
|
|
case 0:
|
|
|
|
if (c == '\\') {
|
|
|
|
c = Read();
|
|
|
|
switch(c) {
|
|
|
|
case '\r':
|
|
|
|
case '\n':
|
2003-09-25 20:28:06 +04:00
|
|
|
// 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();
|
2003-09-22 20:28:55 +04:00
|
|
|
continue;
|
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:
|
|
|
|
value.Append((PRUnichar) c);
|
|
|
|
} // switch(c)
|
|
|
|
} else {
|
|
|
|
value.Append((PRUnichar) c);
|
|
|
|
}
|
|
|
|
c = Read();
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
case 2:
|
|
|
|
case 3:
|
|
|
|
case 4:
|
2003-08-06 00:09:21 +04:00
|
|
|
if (('0' <= c) && (c <= '9')) {
|
2003-02-04 08:43:57 +03:00
|
|
|
uchar = (uchar << 4) | (c - '0');
|
|
|
|
state++;
|
|
|
|
c = Read();
|
2003-08-06 00:09:21 +04:00
|
|
|
} else if (('a' <= c) && (c <= 'f')) {
|
2003-02-04 08:43:57 +03:00
|
|
|
uchar = (uchar << 4) | (c - 'a' + 0x0a);
|
|
|
|
state++;
|
|
|
|
c = Read();
|
2003-08-06 00:09:21 +04:00
|
|
|
} else if (('A' <= c) && (c <= 'F')) {
|
2003-02-04 08:43:57 +03:00
|
|
|
uchar = (uchar << 4) | (c - 'A' + 0x0a);
|
|
|
|
state++;
|
|
|
|
c = Read();
|
|
|
|
} else {
|
|
|
|
value.Append((PRUnichar) uchar);
|
|
|
|
state = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
value.Append((PRUnichar) uchar);
|
|
|
|
state = 0;
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2003-02-04 08:43:57 +03:00
|
|
|
value.Trim(trimThese, PR_TRUE, PR_TRUE);
|
|
|
|
nsAutoString oldValue;
|
|
|
|
mSubclass->SetStringProperty(NS_ConvertUCS2toUTF8(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 =
|
|
|
|
NS_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 =
|
|
|
|
NS_STATIC_CAST(PropertyTableEntry*,
|
2002-06-26 05:33:07 +04:00
|
|
|
PL_DHashTableOperate(&mTable, flatKey.get(), PL_DHASH_LOOKUP));
|
|
|
|
|
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 =
|
|
|
|
NS_STATIC_CAST(PropertyTableEntry*, hdr);
|
|
|
|
|
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
|
|
|
|
|
|
|
NS_ADDREF(element);
|
|
|
|
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
|
|
|
{
|
|
|
|
nsCOMPtr<nsIBidirectionalEnumerator> iterator;
|
|
|
|
|
|
|
|
nsISupportsArray* propArray;
|
|
|
|
nsresult rv = NS_NewISupportsArray(&propArray);
|
|
|
|
if (rv != NS_OK)
|
|
|
|
return rv;
|
1999-12-29 23:55:42 +03:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsPropertyElement, nsIPropertyElement)
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|