2015-04-09 20:25:05 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set ts=8 sts=2 et sw=2 tw=80: */
|
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"
|
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)
|
2014-07-09 19:15:21 +04:00
|
|
|
NS_INTERFACE_MAP_ENTRY(nsIProperties)
|
2005-09-28 17:13:27 +04:00
|
|
|
NS_INTERFACE_MAP_END
|
1999-05-26 05:38:36 +04:00
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
NS_IMETHODIMP
|
2014-07-09 19:15:21 +04:00
|
|
|
nsProperties::Get(const char* prop, const nsIID& uuid, void** result)
|
1999-04-22 11:32:51 +04:00
|
|
|
{
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!prop)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsCOMPtr<nsISupports> value;
|
|
|
|
if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
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
|
|
|
{
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!prop)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
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)
|
|
|
|
{
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!prop)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2007-05-13 20:48:39 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
nsCOMPtr<nsISupports> value;
|
|
|
|
if (!nsProperties_HashBase::Get(prop, getter_AddRefs(value))) {
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
2002-08-27 00:36:44 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
Remove(prop);
|
|
|
|
return NS_OK;
|
2002-08-27 00:36:44 +04:00
|
|
|
}
|
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
NS_IMETHODIMP
|
2014-07-09 19:15:21 +04:00
|
|
|
nsProperties::Has(const char* prop, bool* result)
|
2000-01-05 12:29:25 +03:00
|
|
|
{
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!prop)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
2007-05-13 20:48:39 +04:00
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
nsCOMPtr<nsISupports> value;
|
|
|
|
*result = nsProperties_HashBase::Get(prop, getter_AddRefs(value));
|
|
|
|
return NS_OK;
|
1999-01-27 02:50:25 +03:00
|
|
|
}
|
|
|
|
|
2014-07-09 19:15:21 +04:00
|
|
|
NS_IMETHODIMP
|
|
|
|
nsProperties::GetKeys(uint32_t* aCount, char*** aKeys)
|
2002-08-27 00:36:44 +04:00
|
|
|
{
|
2014-07-09 19:15:21 +04:00
|
|
|
if (NS_WARN_IF(!aCount) || NS_WARN_IF(!aKeys)) {
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2015-07-10 02:54:59 +03:00
|
|
|
uint32_t count = Count();
|
|
|
|
char** keys = (char**)moz_xmalloc(count * sizeof(char*));
|
|
|
|
uint32_t j = 0;
|
|
|
|
|
|
|
|
for (auto iter = this->Iter(); !iter.Done(); iter.Next()) {
|
2015-07-20 15:21:28 +03:00
|
|
|
const char* key = iter.Key();
|
2015-07-10 02:54:59 +03:00
|
|
|
keys[j] = strdup(key);
|
|
|
|
|
|
|
|
if (!keys[j]) {
|
|
|
|
// Free 'em all
|
|
|
|
for (uint32_t i = 0; i < j; i++) {
|
|
|
|
free(keys[i]);
|
|
|
|
}
|
|
|
|
free(keys);
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
2004-10-25 23:52:48 +04:00
|
|
|
}
|
2015-07-10 02:54:59 +03:00
|
|
|
j++;
|
2014-07-09 19:15:21 +04:00
|
|
|
}
|
2004-10-25 23:52:48 +04:00
|
|
|
|
2015-07-10 02:54:59 +03:00
|
|
|
*aCount = count;
|
|
|
|
*aKeys = keys;
|
2014-07-09 19:15:21 +04:00
|
|
|
return NS_OK;
|
2004-10-25 23:52:48 +04:00
|
|
|
}
|
|
|
|
|
1999-04-22 11:32:51 +04:00
|
|
|
////////////////////////////////////////////////////////////////////////////////
|