2001-09-29 00:14:13 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
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/. */
|
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);
|
2012-05-18 21:30:49 +04:00
|
|
|
Put(prop, value);
|
|
|
|
return NS_OK;
|
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
|
2011-09-29 10:19:26 +04:00
|
|
|
nsProperties::Has(const char* prop, bool *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;
|
|
|
|
};
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
PLDHashOperator
|
2004-10-25 23:52:48 +04:00
|
|
|
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);
|
|
|
|
|
2008-12-11 23:13:52 +03:00
|
|
|
nsresult rv = gked.res;
|
|
|
|
if (NS_FAILED(rv)) {
|
2004-10-25 23:52:48 +04:00
|
|
|
// Free 'em all
|
|
|
|
for (PRUint32 i = 0; i < gked.next; i++)
|
|
|
|
nsMemory::Free(k[i]);
|
|
|
|
nsMemory::Free(k);
|
2008-12-11 23:13:52 +03:00
|
|
|
return rv;
|
2004-10-25 23:52:48 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
*count = n;
|
|
|
|
*keys = k;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|