2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
2004-04-18 18:21:17 +04:00
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
1999-01-27 02:50:25 +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-01-27 02:50:25 +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-01-27 02:50:25 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
2004-04-18 18:21:17 +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-11-06 06:43:54 +03:00
|
|
|
*
|
2001-09-29 00:14:13 +04:00
|
|
|
* Contributor(s):
|
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
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-01-27 02:50:25 +03:00
|
|
|
|
1999-05-01 02:54:22 +04:00
|
|
|
#include "nsProperties.h"
|
2004-10-25 23:52:48 +04:00
|
|
|
#include "nsString.h"
|
2005-08-15 22:29:55 +04:00
|
|
|
#include "nsCRT.h"
|
1999-07-17 05:58:38 +04:00
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2003-09-08 04:31:50 +04:00
|
|
|
NS_IMPL_AGGREGATED(nsProperties)
|
2005-09-28 17:13:27 +04:00
|
|
|
NS_INTERFACE_MAP_BEGIN_AGGREGATED(nsProperties)
|
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProperties)
|
|
|
|
NS_INTERFACE_MAP_END
|
1999-05-26 05:38:36 +04:00
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
NS_IMETHODIMP
|
2000-01-05 12:29:25 +03:00
|
|
|
nsProperties::Get(const char* prop, const nsIID & uuid, void* *result)
|
1999-04-22 11:32:51 +04:00
|
|
|
{
|
2007-05-13 20:48:39 +04:00
|
|
|
NS_ENSURE_ARG(prop);
|
|
|
|
|
2004-10-25 23:52:48 +04:00
|
|
|
nsCOMPtr<nsISupports> value;
|
|
|
|
if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
2000-01-05 12:29:25 +03:00
|
|
|
}
|
2004-10-29 02:52:45 +04:00
|
|
|
return (value) ? value->QueryInterface(uuid, result) : NS_ERROR_NO_INTERFACE;
|
1999-04-22 11:32:51 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2000-01-05 12:29:25 +03:00
|
|
|
nsProperties::Set(const char* prop, nsISupports* value)
|
1999-04-22 11:32:51 +04:00
|
|
|
{
|
2007-05-13 20:48:39 +04:00
|
|
|
NS_ENSURE_ARG(prop);
|
|
|
|
|
2004-10-25 23:52:48 +04:00
|
|
|
return Put(prop, value) ? NS_OK : NS_ERROR_FAILURE;
|
1999-04-22 11:32:51 +04:00
|
|
|
}
|
|
|
|
|
2002-08-27 00:36:44 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProperties::Undefine(const char* prop)
|
|
|
|
{
|
2007-05-13 20:48:39 +04:00
|
|
|
NS_ENSURE_ARG(prop);
|
|
|
|
|
2004-10-25 23:52:48 +04:00
|
|
|
nsCOMPtr<nsISupports> value;
|
|
|
|
if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value)))
|
2002-08-27 00:36:44 +04:00
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
|
2004-10-25 23:52:48 +04:00
|
|
|
Remove(prop);
|
2002-08-27 00:36:44 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
NS_IMETHODIMP
|
2000-01-07 02:02:32 +03:00
|
|
|
nsProperties::Has(const char* prop, PRBool *result)
|
2000-01-05 12:29:25 +03:00
|
|
|
{
|
2007-05-13 20:48:39 +04:00
|
|
|
NS_ENSURE_ARG(prop);
|
|
|
|
|
2004-10-25 23:52:48 +04:00
|
|
|
nsCOMPtr<nsISupports> value;
|
|
|
|
*result = nsProperties_HashBase::Get(prop,
|
|
|
|
getter_AddRefs(value));
|
1999-06-13 01:07:22 +04:00
|
|
|
return NS_OK;
|
1999-01-27 02:50:25 +03:00
|
|
|
}
|
|
|
|
|
2004-10-25 23:52:48 +04:00
|
|
|
struct GetKeysEnumData
|
|
|
|
{
|
|
|
|
char **keys;
|
|
|
|
PRUint32 next;
|
|
|
|
nsresult res;
|
|
|
|
};
|
|
|
|
|
|
|
|
PR_CALLBACK PLDHashOperator
|
|
|
|
GetKeysEnumerate(const char *key, nsISupports* data,
|
|
|
|
void *arg)
|
|
|
|
{
|
|
|
|
GetKeysEnumData *gkedp = (GetKeysEnumData *)arg;
|
|
|
|
gkedp->keys[gkedp->next] = nsCRT::strdup(key);
|
|
|
|
|
|
|
|
if (!gkedp->keys[gkedp->next]) {
|
|
|
|
gkedp->res = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
return PL_DHASH_STOP;
|
|
|
|
}
|
|
|
|
|
|
|
|
gkedp->next++;
|
|
|
|
return PL_DHASH_NEXT;
|
|
|
|
}
|
|
|
|
|
2002-08-27 00:36:44 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProperties::GetKeys(PRUint32 *count, char ***keys)
|
|
|
|
{
|
2007-05-13 20:48:39 +04:00
|
|
|
NS_ENSURE_ARG(count);
|
|
|
|
NS_ENSURE_ARG(keys);
|
|
|
|
|
2004-10-25 23:52:48 +04:00
|
|
|
PRUint32 n = Count();
|
|
|
|
char ** k = (char **) nsMemory::Alloc(n * sizeof(char *));
|
2007-05-13 20:48:39 +04:00
|
|
|
NS_ENSURE_TRUE(k, NS_ERROR_OUT_OF_MEMORY);
|
2004-10-25 23:52:48 +04:00
|
|
|
|
|
|
|
GetKeysEnumData gked;
|
|
|
|
gked.keys = k;
|
|
|
|
gked.next = 0;
|
|
|
|
gked.res = NS_OK;
|
|
|
|
|
|
|
|
EnumerateRead(GetKeysEnumerate, &gked);
|
|
|
|
|
|
|
|
if (NS_FAILED(gked.res)) {
|
|
|
|
// Free 'em all
|
|
|
|
for (PRUint32 i = 0; i < gked.next; i++)
|
|
|
|
nsMemory::Free(k[i]);
|
|
|
|
nsMemory::Free(k);
|
|
|
|
return gked.res;
|
|
|
|
}
|
|
|
|
|
|
|
|
*count = n;
|
|
|
|
*keys = k;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|