1999-01-05 06:53:15 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; 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
|
2017-08-17 00:10:56 +03:00
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
1999-01-05 06:53:15 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
This file provides the implementation for the RDF service manager.
|
|
|
|
|
|
|
|
TO DO
|
|
|
|
-----
|
|
|
|
|
1999-02-26 13:17:14 +03:00
|
|
|
1) Implement the CreateDataBase() methods.
|
1999-03-02 04:00:45 +03:00
|
|
|
|
1999-03-09 07:01:56 +03:00
|
|
|
2) Cache date and int literals.
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
*/
|
|
|
|
|
2005-12-01 18:03:48 +03:00
|
|
|
#include "nsRDFService.h"
|
1999-03-26 07:43:02 +03:00
|
|
|
#include "nsCOMPtr.h"
|
2005-12-01 18:03:48 +03:00
|
|
|
#include "nsAutoPtr.h"
|
2000-06-03 13:46:12 +04:00
|
|
|
#include "nsMemory.h"
|
1999-01-05 06:53:15 +03:00
|
|
|
#include "nsIAtom.h"
|
1999-03-26 07:43:02 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-05 06:53:15 +03:00
|
|
|
#include "nsIRDFDataSource.h"
|
|
|
|
#include "nsIRDFNode.h"
|
1999-06-24 04:22:58 +04:00
|
|
|
#include "nsIRDFRemoteDataSource.h"
|
1999-05-18 07:53:18 +04:00
|
|
|
#include "nsIServiceManager.h"
|
2004-11-23 23:53:38 +03:00
|
|
|
#include "nsIFactory.h"
|
1999-03-26 07:43:02 +03:00
|
|
|
#include "nsRDFCID.h"
|
1999-01-05 06:53:15 +03:00
|
|
|
#include "nsString.h"
|
1999-03-29 23:52:54 +04:00
|
|
|
#include "nsXPIDLString.h"
|
2002-01-29 02:07:55 +03:00
|
|
|
#include "nsNetUtil.h"
|
2015-07-07 05:17:00 +03:00
|
|
|
#include "nsIURI.h"
|
2015-09-16 06:49:53 +03:00
|
|
|
#include "PLDHashTable.h"
|
1999-01-05 06:53:15 +03:00
|
|
|
#include "plhash.h"
|
|
|
|
#include "plstr.h"
|
2015-05-19 21:15:34 +03:00
|
|
|
#include "mozilla/Logging.h"
|
1999-03-26 07:43:02 +03:00
|
|
|
#include "prprf.h"
|
1999-03-29 23:52:54 +04:00
|
|
|
#include "rdf.h"
|
2002-05-15 22:55:21 +04:00
|
|
|
#include "nsCRT.h"
|
2006-11-19 13:54:08 +03:00
|
|
|
#include "nsCRTGlue.h"
|
2012-03-13 02:53:18 +04:00
|
|
|
#include "mozilla/HashFunctions.h"
|
2016-12-16 06:16:31 +03:00
|
|
|
#include "mozilla/IntegerPrintfMacros.h"
|
2012-03-13 02:53:18 +04:00
|
|
|
|
|
|
|
using namespace mozilla;
|
1999-02-27 02:28:14 +03:00
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
1999-06-24 04:22:58 +04:00
|
|
|
static NS_DEFINE_CID(kRDFXMLDataSourceCID, NS_RDFXMLDATASOURCE_CID);
|
1999-07-17 05:46:34 +04:00
|
|
|
static NS_DEFINE_CID(kRDFDefaultResourceCID, NS_RDFDEFAULTRESOURCE_CID);
|
1999-03-26 07:43:02 +03:00
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
static NS_DEFINE_IID(kIRDFLiteralIID, NS_IRDFLITERAL_IID);
|
1999-03-09 07:01:56 +03:00
|
|
|
static NS_DEFINE_IID(kIRDFDateIID, NS_IRDFDATE_IID);
|
|
|
|
static NS_DEFINE_IID(kIRDFIntIID, NS_IRDFINT_IID);
|
1999-01-05 06:53:15 +03:00
|
|
|
static NS_DEFINE_IID(kIRDFNodeIID, NS_IRDFNODE_IID);
|
|
|
|
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
|
|
|
|
2016-01-28 21:35:00 +03:00
|
|
|
static LazyLogModule gLog("nsRDFService");
|
2013-12-04 03:47:39 +04:00
|
|
|
|
2002-01-15 04:57:17 +03:00
|
|
|
class BlobImpl;
|
|
|
|
|
2000-08-17 03:14:08 +04:00
|
|
|
// These functions are copied from nsprpub/lib/ds/plhash.c, with one
|
|
|
|
// change to free the key in DataSourceFreeEntry.
|
2001-12-21 02:04:33 +03:00
|
|
|
// XXX sigh, why were DefaultAllocTable et. al. declared static, anyway?
|
2000-08-17 03:14:08 +04:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void *
|
2012-08-09 11:10:11 +04:00
|
|
|
DataSourceAllocTable(void *pool, size_t size)
|
2000-08-17 03:14:08 +04:00
|
|
|
{
|
2017-07-01 05:05:41 +03:00
|
|
|
return malloc(size);
|
2000-08-17 03:14:08 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2000-08-17 03:14:08 +04:00
|
|
|
DataSourceFreeTable(void *pool, void *item)
|
|
|
|
{
|
2017-07-01 05:05:41 +03:00
|
|
|
free(item);
|
2000-08-17 03:14:08 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLHashEntry *
|
2000-08-17 03:14:08 +04:00
|
|
|
DataSourceAllocEntry(void *pool, const void *key)
|
|
|
|
{
|
2017-07-01 05:05:41 +03:00
|
|
|
return (PLHashEntry*) malloc(sizeof(PLHashEntry));
|
2000-08-17 03:14:08 +04:00
|
|
|
}
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static void
|
2012-08-22 19:56:38 +04:00
|
|
|
DataSourceFreeEntry(void *pool, PLHashEntry *he, unsigned flag)
|
2000-08-17 03:14:08 +04:00
|
|
|
{
|
|
|
|
if (flag == HT_FREE_ENTRY) {
|
|
|
|
PL_strfree((char*) he->key);
|
2017-07-01 05:05:41 +03:00
|
|
|
free(he);
|
2000-08-17 03:14:08 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static PLHashAllocOps dataSourceHashAllocOps = {
|
|
|
|
DataSourceAllocTable, DataSourceFreeTable,
|
|
|
|
DataSourceAllocEntry, DataSourceFreeEntry
|
|
|
|
};
|
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
//----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// For the mResources hashtable.
|
|
|
|
//
|
|
|
|
|
|
|
|
struct ResourceHashEntry : public PLDHashEntryHdr {
|
|
|
|
const char *mKey;
|
|
|
|
nsIRDFResource *mResource;
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2016-03-16 07:33:44 +03:00
|
|
|
HashKey(const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
2012-03-13 02:53:18 +04:00
|
|
|
return HashString(static_cast<const char *>(key));
|
2001-12-21 02:04:33 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2016-03-16 07:33:44 +03:00
|
|
|
MatchEntry(const PLDHashEntryHdr *hdr, const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
|
|
|
const ResourceHashEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const ResourceHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
return 0 == nsCRT::strcmp(static_cast<const char *>(key),
|
2001-12-21 02:04:33 +03:00
|
|
|
entry->mKey);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 06:58:27 +04:00
|
|
|
static const PLDHashTableOps gResourceTableOps = {
|
2001-12-21 02:04:33 +03:00
|
|
|
ResourceHashEntry::HashKey,
|
|
|
|
ResourceHashEntry::MatchEntry,
|
2015-09-15 00:23:47 +03:00
|
|
|
PLDHashTable::MoveEntryStub,
|
|
|
|
PLDHashTable::ClearEntryStub,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2001-12-21 02:04:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// For the mLiterals hashtable.
|
|
|
|
//
|
|
|
|
|
|
|
|
struct LiteralHashEntry : public PLDHashEntryHdr {
|
|
|
|
nsIRDFLiteral *mLiteral;
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *mKey;
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2016-03-16 07:33:44 +03:00
|
|
|
HashKey(const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
return HashString(static_cast<const char16_t *>(key));
|
2001-12-21 02:04:33 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2016-03-16 07:33:44 +03:00
|
|
|
MatchEntry(const PLDHashEntryHdr *hdr, const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
|
|
|
const LiteralHashEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const LiteralHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
return 0 == nsCRT::strcmp(static_cast<const char16_t *>(key),
|
2013-01-04 03:36:16 +04:00
|
|
|
entry->mKey);
|
2001-12-21 02:04:33 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 06:58:27 +04:00
|
|
|
static const PLDHashTableOps gLiteralTableOps = {
|
2001-12-21 02:04:33 +03:00
|
|
|
LiteralHashEntry::HashKey,
|
|
|
|
LiteralHashEntry::MatchEntry,
|
2015-09-15 00:23:47 +03:00
|
|
|
PLDHashTable::MoveEntryStub,
|
|
|
|
PLDHashTable::ClearEntryStub,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2001-12-21 02:04:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// For the mInts hashtable.
|
|
|
|
//
|
|
|
|
|
|
|
|
struct IntHashEntry : public PLDHashEntryHdr {
|
|
|
|
nsIRDFInt *mInt;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mKey;
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2016-03-16 07:33:44 +03:00
|
|
|
HashKey(const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
return PLDHashNumber(*static_cast<const int32_t *>(key));
|
2001-12-21 02:04:33 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2016-03-16 07:33:44 +03:00
|
|
|
MatchEntry(const PLDHashEntryHdr *hdr, const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
|
|
|
const IntHashEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const IntHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
return *static_cast<const int32_t *>(key) == entry->mKey;
|
2001-12-21 02:04:33 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 06:58:27 +04:00
|
|
|
static const PLDHashTableOps gIntTableOps = {
|
2001-12-21 02:04:33 +03:00
|
|
|
IntHashEntry::HashKey,
|
|
|
|
IntHashEntry::MatchEntry,
|
2015-09-15 00:23:47 +03:00
|
|
|
PLDHashTable::MoveEntryStub,
|
|
|
|
PLDHashTable::ClearEntryStub,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2001-12-21 02:04:33 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// For the mDates hashtable.
|
|
|
|
//
|
|
|
|
|
|
|
|
struct DateHashEntry : public PLDHashEntryHdr {
|
|
|
|
nsIRDFDate *mDate;
|
|
|
|
PRTime mKey;
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2016-03-16 07:33:44 +03:00
|
|
|
HashKey(const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
|
|
|
// xor the low 32 bits with the high 32 bits.
|
2007-07-08 11:08:04 +04:00
|
|
|
PRTime t = *static_cast<const PRTime *>(key);
|
2012-11-02 04:57:25 +04:00
|
|
|
int32_t h32 = int32_t(t >> 32);
|
|
|
|
int32_t l32 = int32_t(0xffffffff & t);
|
2001-12-21 02:04:33 +03:00
|
|
|
return PLDHashNumber(l32 ^ h32);
|
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2016-03-16 07:33:44 +03:00
|
|
|
MatchEntry(const PLDHashEntryHdr *hdr, const void *key)
|
2001-12-21 02:04:33 +03:00
|
|
|
{
|
|
|
|
const DateHashEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const DateHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2012-10-03 18:13:18 +04:00
|
|
|
return *static_cast<const PRTime *>(key) == entry->mKey;
|
2001-12-21 02:04:33 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 06:58:27 +04:00
|
|
|
static const PLDHashTableOps gDateTableOps = {
|
2001-12-21 02:04:33 +03:00
|
|
|
DateHashEntry::HashKey,
|
|
|
|
DateHashEntry::MatchEntry,
|
2015-09-15 00:23:47 +03:00
|
|
|
PLDHashTable::MoveEntryStub,
|
|
|
|
PLDHashTable::ClearEntryStub,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2001-12-21 02:04:33 +03:00
|
|
|
};
|
2000-08-17 03:14:08 +04:00
|
|
|
|
2002-01-15 04:57:17 +03:00
|
|
|
class BlobImpl : public nsIRDFBlob
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
struct Data {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mLength;
|
|
|
|
uint8_t *mBytes;
|
2002-01-15 04:57:17 +03:00
|
|
|
};
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
BlobImpl(const uint8_t *aBytes, int32_t aLength)
|
2002-01-15 04:57:17 +03:00
|
|
|
{
|
|
|
|
mData.mLength = aLength;
|
2012-08-22 19:56:38 +04:00
|
|
|
mData.mBytes = new uint8_t[aLength];
|
2002-01-26 03:04:45 +03:00
|
|
|
memcpy(mData.mBytes, aBytes, aLength);
|
2005-12-01 18:03:48 +03:00
|
|
|
NS_ADDREF(RDFServiceImpl::gRDFService);
|
|
|
|
RDFServiceImpl::gRDFService->RegisterBlob(this);
|
2002-01-15 04:57:17 +03:00
|
|
|
}
|
|
|
|
|
2014-07-01 02:11:50 +04:00
|
|
|
protected:
|
2002-01-15 04:57:17 +03:00
|
|
|
virtual ~BlobImpl()
|
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::gRDFService->UnregisterBlob(this);
|
2002-01-30 00:04:03 +03:00
|
|
|
// Use NS_RELEASE2() here, because we want to decrease the
|
|
|
|
// refcount, but not null out the gRDFService pointer (which is
|
|
|
|
// what a vanilla NS_RELEASE() would do).
|
|
|
|
nsrefcnt refcnt;
|
2005-12-01 18:03:48 +03:00
|
|
|
NS_RELEASE2(RDFServiceImpl::gRDFService, refcnt);
|
2002-01-15 04:57:17 +03:00
|
|
|
delete[] mData.mBytes;
|
|
|
|
}
|
|
|
|
|
2014-07-01 02:11:50 +04:00
|
|
|
public:
|
2002-01-15 04:57:17 +03:00
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
NS_DECL_NSIRDFNODE
|
|
|
|
NS_DECL_NSIRDFBLOB
|
|
|
|
|
|
|
|
Data mData;
|
|
|
|
};
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(BlobImpl, nsIRDFNode, nsIRDFBlob)
|
2002-01-15 04:57:17 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
BlobImpl::EqualsNode(nsIRDFNode *aNode, bool *aEquals)
|
2002-01-15 04:57:17 +03:00
|
|
|
{
|
|
|
|
nsCOMPtr<nsIRDFBlob> blob = do_QueryInterface(aNode);
|
|
|
|
if (blob) {
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t length;
|
2002-01-15 04:57:17 +03:00
|
|
|
blob->GetLength(&length);
|
|
|
|
|
|
|
|
if (length == mData.mLength) {
|
2012-08-22 19:56:38 +04:00
|
|
|
const uint8_t *bytes;
|
2002-01-15 04:57:17 +03:00
|
|
|
blob->GetValue(&bytes);
|
|
|
|
|
2002-01-30 00:30:32 +03:00
|
|
|
if (0 == memcmp(bytes, mData.mBytes, length)) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aEquals = true;
|
2002-01-15 04:57:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-10-17 18:59:28 +04:00
|
|
|
*aEquals = false;
|
2002-01-15 04:57:17 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
BlobImpl::GetValue(const uint8_t **aResult)
|
2002-01-15 04:57:17 +03:00
|
|
|
{
|
|
|
|
*aResult = mData.mBytes;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
BlobImpl::GetLength(int32_t *aResult)
|
2002-01-15 04:57:17 +03:00
|
|
|
{
|
|
|
|
*aResult = mData.mLength;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------
|
|
|
|
//
|
|
|
|
// For the mBlobs hashtable.
|
|
|
|
//
|
|
|
|
|
|
|
|
struct BlobHashEntry : public PLDHashEntryHdr {
|
|
|
|
BlobImpl *mBlob;
|
|
|
|
|
2008-10-10 19:04:34 +04:00
|
|
|
static PLDHashNumber
|
2016-03-16 07:33:44 +03:00
|
|
|
HashKey(const void *key)
|
2002-01-15 04:57:17 +03:00
|
|
|
{
|
|
|
|
const BlobImpl::Data *data =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const BlobImpl::Data *>(key);
|
2012-03-13 02:53:18 +04:00
|
|
|
return HashBytes(data->mBytes, data->mLength);
|
2002-01-15 04:57:17 +03:00
|
|
|
}
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static bool
|
2016-03-16 07:33:44 +03:00
|
|
|
MatchEntry(const PLDHashEntryHdr *hdr, const void *key)
|
2002-01-15 04:57:17 +03:00
|
|
|
{
|
|
|
|
const BlobHashEntry *entry =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const BlobHashEntry *>(hdr);
|
2002-01-15 04:57:17 +03:00
|
|
|
|
|
|
|
const BlobImpl::Data *left = &entry->mBlob->mData;
|
|
|
|
|
|
|
|
const BlobImpl::Data *right =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<const BlobImpl::Data *>(key);
|
2002-01-15 04:57:17 +03:00
|
|
|
|
|
|
|
return (left->mLength == right->mLength)
|
2002-01-30 00:30:32 +03:00
|
|
|
&& 0 == memcmp(left->mBytes, right->mBytes, right->mLength);
|
2002-01-15 04:57:17 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-11-19 06:58:27 +04:00
|
|
|
static const PLDHashTableOps gBlobTableOps = {
|
2002-01-15 04:57:17 +03:00
|
|
|
BlobHashEntry::HashKey,
|
|
|
|
BlobHashEntry::MatchEntry,
|
2015-09-15 00:23:47 +03:00
|
|
|
PLDHashTable::MoveEntryStub,
|
|
|
|
PLDHashTable::ClearEntryStub,
|
2012-07-30 18:20:58 +04:00
|
|
|
nullptr
|
2002-01-15 04:57:17 +03:00
|
|
|
};
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// LiteralImpl
|
|
|
|
//
|
|
|
|
// Currently, all literals are implemented exactly the same way;
|
|
|
|
// i.e., there is are no resource factories to allow you to generate
|
|
|
|
// customer resources. I doubt that makes sense, anyway.
|
|
|
|
//
|
|
|
|
class LiteralImpl : public nsIRDFLiteral {
|
|
|
|
public:
|
2000-08-26 10:43:09 +04:00
|
|
|
static nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
Create(const char16_t* aValue, nsIRDFLiteral** aResult);
|
1999-01-05 06:53:15 +03:00
|
|
|
|
|
|
|
// nsISupports
|
2013-07-19 06:24:14 +04:00
|
|
|
NS_DECL_THREADSAFE_ISUPPORTS
|
1999-01-05 06:53:15 +03:00
|
|
|
|
|
|
|
// nsIRDFNode
|
1999-08-24 13:11:48 +04:00
|
|
|
NS_DECL_NSIRDFNODE
|
1999-01-05 06:53:15 +03:00
|
|
|
|
|
|
|
// nsIRDFLiteral
|
1999-08-24 13:11:48 +04:00
|
|
|
NS_DECL_NSIRDFLITERAL
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2000-08-26 10:43:09 +04:00
|
|
|
protected:
|
2014-09-03 02:21:23 +04:00
|
|
|
explicit LiteralImpl(const char16_t* s);
|
2000-08-26 10:43:09 +04:00
|
|
|
virtual ~LiteralImpl();
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* GetValue() const {
|
|
|
|
size_t objectSize = ((sizeof(LiteralImpl) + sizeof(char16_t) - 1) / sizeof(char16_t)) * sizeof(char16_t);
|
|
|
|
return reinterpret_cast<const char16_t*>(reinterpret_cast<const unsigned char*>(this) + objectSize);
|
2000-08-26 10:43:09 +04:00
|
|
|
}
|
1999-01-05 06:53:15 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2000-08-26 10:43:09 +04:00
|
|
|
nsresult
|
2014-01-04 19:02:17 +04:00
|
|
|
LiteralImpl::Create(const char16_t* aValue, nsIRDFLiteral** aResult)
|
2000-08-26 10:43:09 +04:00
|
|
|
{
|
|
|
|
// Goofy math to get alignment right. Copied from nsSharedString.h.
|
2014-01-04 19:02:17 +04:00
|
|
|
size_t objectSize = ((sizeof(LiteralImpl) + sizeof(char16_t) - 1) / sizeof(char16_t)) * sizeof(char16_t);
|
|
|
|
size_t stringLen = nsCharTraits<char16_t>::length(aValue);
|
|
|
|
size_t stringSize = (stringLen + 1) * sizeof(char16_t);
|
2000-08-26 10:43:09 +04:00
|
|
|
|
|
|
|
void* objectPtr = operator new(objectSize + stringSize);
|
|
|
|
if (! objectPtr)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
char16_t* buf = reinterpret_cast<char16_t*>(static_cast<unsigned char*>(objectPtr) + objectSize);
|
|
|
|
nsCharTraits<char16_t>::copy(buf, aValue, stringLen + 1);
|
2000-08-26 10:43:09 +04:00
|
|
|
|
|
|
|
NS_ADDREF(*aResult = new (objectPtr) LiteralImpl(buf));
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
LiteralImpl::LiteralImpl(const char16_t* s)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::gRDFService->RegisterLiteral(this);
|
|
|
|
NS_ADDREF(RDFServiceImpl::gRDFService);
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
1999-09-10 02:35:16 +04:00
|
|
|
LiteralImpl::~LiteralImpl()
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::gRDFService->UnregisterLiteral(this);
|
1999-10-15 07:36:04 +04:00
|
|
|
|
|
|
|
// Use NS_RELEASE2() here, because we want to decrease the
|
|
|
|
// refcount, but not null out the gRDFService pointer (which is
|
|
|
|
// what a vanilla NS_RELEASE() would do).
|
|
|
|
nsrefcnt refcnt;
|
2005-12-01 18:03:48 +03:00
|
|
|
NS_RELEASE2(RDFServiceImpl::gRDFService, refcnt);
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
2013-07-19 06:24:14 +04:00
|
|
|
NS_IMPL_ADDREF(LiteralImpl)
|
|
|
|
NS_IMPL_RELEASE(LiteralImpl)
|
1999-01-05 06:53:15 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
LiteralImpl::QueryInterface(REFNSIID iid, void** result)
|
|
|
|
{
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
1999-01-05 06:53:15 +03:00
|
|
|
if (iid.Equals(kIRDFLiteralIID) ||
|
|
|
|
iid.Equals(kIRDFNodeIID) ||
|
|
|
|
iid.Equals(kISupportsIID)) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*result = static_cast<nsIRDFLiteral*>(this);
|
1999-01-05 06:53:15 +03:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
LiteralImpl::EqualsNode(nsIRDFNode* aNode, bool* aResult)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIRDFLiteral* literal;
|
1999-06-26 00:51:13 +04:00
|
|
|
rv = aNode->QueryInterface(kIRDFLiteralIID, (void**) &literal);
|
|
|
|
if (NS_SUCCEEDED(rv)) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*aResult = (static_cast<nsIRDFLiteral*>(this) == literal);
|
1999-01-05 06:53:15 +03:00
|
|
|
NS_RELEASE(literal);
|
1999-06-26 00:51:13 +04:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
else if (rv == NS_NOINTERFACE) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*aResult = false;
|
1999-06-26 00:51:13 +04:00
|
|
|
return NS_OK;
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-06-26 00:51:13 +04:00
|
|
|
return rv;
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
LiteralImpl::GetValue(char16_t* *value)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(value, "null ptr");
|
|
|
|
if (! value)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t *temp = GetValue();
|
2006-11-19 11:28:02 +03:00
|
|
|
*value = temp? NS_strdup(temp) : 0;
|
1999-01-05 06:53:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
LiteralImpl::GetValueConst(const char16_t** aValue)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2000-08-26 10:43:09 +04:00
|
|
|
*aValue = GetValue();
|
1999-01-05 06:53:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-03-09 07:01:56 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// DateImpl
|
|
|
|
//
|
|
|
|
|
|
|
|
class DateImpl : public nsIRDFDate {
|
|
|
|
public:
|
2014-09-03 02:21:23 +04:00
|
|
|
explicit DateImpl(const PRTime s);
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIRDFNode
|
1999-08-24 13:11:48 +04:00
|
|
|
NS_DECL_NSIRDFNODE
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
// nsIRDFDate
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetValue(PRTime *value) override;
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
private:
|
2014-07-01 02:11:50 +04:00
|
|
|
virtual ~DateImpl();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult EqualsDate(nsIRDFDate* date, bool* result);
|
1999-03-09 07:01:56 +03:00
|
|
|
PRTime mValue;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
DateImpl::DateImpl(const PRTime s)
|
|
|
|
: mValue(s)
|
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::gRDFService->RegisterDate(this);
|
|
|
|
NS_ADDREF(RDFServiceImpl::gRDFService);
|
1999-03-09 07:01:56 +03:00
|
|
|
}
|
|
|
|
|
1999-09-10 02:35:16 +04:00
|
|
|
DateImpl::~DateImpl()
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::gRDFService->UnregisterDate(this);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
|
|
|
// Use NS_RELEASE2() here, because we want to decrease the
|
|
|
|
// refcount, but not null out the gRDFService pointer (which is
|
|
|
|
// what a vanilla NS_RELEASE() would do).
|
|
|
|
nsrefcnt refcnt;
|
2005-12-01 18:03:48 +03:00
|
|
|
NS_RELEASE2(RDFServiceImpl::gRDFService, refcnt);
|
1999-03-09 07:01:56 +03:00
|
|
|
}
|
|
|
|
|
2003-09-08 04:18:24 +04:00
|
|
|
NS_IMPL_ADDREF(DateImpl)
|
|
|
|
NS_IMPL_RELEASE(DateImpl)
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
DateImpl::QueryInterface(REFNSIID iid, void** result)
|
|
|
|
{
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
1999-03-09 07:01:56 +03:00
|
|
|
if (iid.Equals(kIRDFDateIID) ||
|
|
|
|
iid.Equals(kIRDFNodeIID) ||
|
|
|
|
iid.Equals(kISupportsIID)) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*result = static_cast<nsIRDFDate*>(this);
|
1999-03-09 07:01:56 +03:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
DateImpl::EqualsNode(nsIRDFNode* node, bool* result)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIRDFDate* date;
|
|
|
|
if (NS_SUCCEEDED(node->QueryInterface(kIRDFDateIID, (void**) &date))) {
|
|
|
|
rv = EqualsDate(date, result);
|
|
|
|
NS_RELEASE(date);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
1999-03-09 07:01:56 +03:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-03-29 23:52:54 +04:00
|
|
|
DateImpl::GetValue(PRTime *value)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(value, "null ptr");
|
|
|
|
if (! value)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*value = mValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-26 00:51:13 +04:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
DateImpl::EqualsDate(nsIRDFDate* date, bool* result)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(date && result, "null ptr");
|
|
|
|
if (!date || !result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
PRTime p;
|
|
|
|
if (NS_FAILED(rv = date->GetValue(&p)))
|
|
|
|
return rv;
|
|
|
|
|
2013-07-19 00:50:31 +04:00
|
|
|
*result = p == mValue;
|
1999-03-09 07:01:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// IntImpl
|
|
|
|
//
|
|
|
|
|
|
|
|
class IntImpl : public nsIRDFInt {
|
|
|
|
public:
|
2014-09-03 02:21:23 +04:00
|
|
|
explicit IntImpl(int32_t s);
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
// nsISupports
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
// nsIRDFNode
|
1999-08-24 13:11:48 +04:00
|
|
|
NS_DECL_NSIRDFNODE
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
// nsIRDFInt
|
2015-03-21 19:28:04 +03:00
|
|
|
NS_IMETHOD GetValue(int32_t *value) override;
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
private:
|
2014-07-01 02:11:50 +04:00
|
|
|
virtual ~IntImpl();
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
nsresult EqualsInt(nsIRDFInt* value, bool* result);
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t mValue;
|
1999-03-09 07:01:56 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
IntImpl::IntImpl(int32_t s)
|
1999-03-09 07:01:56 +03:00
|
|
|
: mValue(s)
|
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::gRDFService->RegisterInt(this);
|
|
|
|
NS_ADDREF(RDFServiceImpl::gRDFService);
|
1999-03-09 07:01:56 +03:00
|
|
|
}
|
|
|
|
|
1999-09-10 02:35:16 +04:00
|
|
|
IntImpl::~IntImpl()
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::gRDFService->UnregisterInt(this);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
|
|
|
// Use NS_RELEASE2() here, because we want to decrease the
|
|
|
|
// refcount, but not null out the gRDFService pointer (which is
|
|
|
|
// what a vanilla NS_RELEASE() would do).
|
|
|
|
nsrefcnt refcnt;
|
2005-12-01 18:03:48 +03:00
|
|
|
NS_RELEASE2(RDFServiceImpl::gRDFService, refcnt);
|
1999-03-09 07:01:56 +03:00
|
|
|
}
|
|
|
|
|
2003-09-08 04:18:24 +04:00
|
|
|
NS_IMPL_ADDREF(IntImpl)
|
|
|
|
NS_IMPL_RELEASE(IntImpl)
|
1999-03-09 07:01:56 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
IntImpl::QueryInterface(REFNSIID iid, void** result)
|
|
|
|
{
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
*result = nullptr;
|
1999-03-09 07:01:56 +03:00
|
|
|
if (iid.Equals(kIRDFIntIID) ||
|
|
|
|
iid.Equals(kIRDFNodeIID) ||
|
|
|
|
iid.Equals(kISupportsIID)) {
|
2007-07-08 11:08:04 +04:00
|
|
|
*result = static_cast<nsIRDFInt*>(this);
|
1999-03-09 07:01:56 +03:00
|
|
|
AddRef();
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
return NS_NOINTERFACE;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
IntImpl::EqualsNode(nsIRDFNode* node, bool* result)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
nsIRDFInt* intValue;
|
|
|
|
if (NS_SUCCEEDED(node->QueryInterface(kIRDFIntIID, (void**) &intValue))) {
|
|
|
|
rv = EqualsInt(intValue, result);
|
|
|
|
NS_RELEASE(intValue);
|
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*result = false;
|
1999-03-09 07:01:56 +03:00
|
|
|
rv = NS_OK;
|
|
|
|
}
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
IntImpl::GetValue(int32_t *value)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(value, "null ptr");
|
|
|
|
if (! value)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
*value = mValue;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-06-26 00:51:13 +04:00
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
IntImpl::EqualsInt(nsIRDFInt* intValue, bool* result)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
|
|
|
NS_ASSERTION(intValue && result, "null ptr");
|
|
|
|
if (!intValue || !result)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t p;
|
1999-03-09 07:01:56 +03:00
|
|
|
if (NS_FAILED(rv = intValue->GetValue(&p)))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
*result = (p == mValue);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
1999-09-10 02:35:16 +04:00
|
|
|
// RDFServiceImpl
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl*
|
|
|
|
RDFServiceImpl::gRDFService;
|
|
|
|
|
1999-09-10 02:35:16 +04:00
|
|
|
RDFServiceImpl::RDFServiceImpl()
|
2015-05-06 04:30:27 +03:00
|
|
|
: mNamedDataSources(nullptr)
|
|
|
|
, mResources(&gResourceTableOps, sizeof(ResourceHashEntry))
|
|
|
|
, mLiterals(&gLiteralTableOps, sizeof(LiteralHashEntry))
|
|
|
|
, mInts(&gIntTableOps, sizeof(IntHashEntry))
|
|
|
|
, mDates(&gDateTableOps, sizeof(DateHashEntry))
|
|
|
|
, mBlobs(&gBlobTableOps, sizeof(BlobHashEntry))
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
gRDFService = this;
|
1999-09-10 02:35:16 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RDFServiceImpl::Init()
|
|
|
|
{
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
mNamedDataSources = PL_NewHashTable(23,
|
|
|
|
PL_HashString,
|
|
|
|
PL_CompareStrings,
|
|
|
|
PL_CompareValues,
|
2012-07-30 18:20:58 +04:00
|
|
|
&dataSourceHashAllocOps, nullptr);
|
1999-04-28 10:24:19 +04:00
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
if (! mNamedDataSources)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
mDefaultResourceFactory = do_GetClassObject(kRDFDefaultResourceCID, &rv);
|
1999-09-10 02:35:16 +04:00
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get default resource factory");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-09-10 04:01:27 +04:00
|
|
|
return NS_OK;
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-10 02:35:16 +04:00
|
|
|
RDFServiceImpl::~RDFServiceImpl()
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
|
|
|
if (mNamedDataSources) {
|
|
|
|
PL_HashTableDestroy(mNamedDataSources);
|
2012-07-30 18:20:58 +04:00
|
|
|
mNamedDataSources = nullptr;
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
2012-07-30 18:20:58 +04:00
|
|
|
gRDFService = nullptr;
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-12-01 18:03:48 +03:00
|
|
|
// static
|
1999-01-05 06:53:15 +03:00
|
|
|
nsresult
|
2005-12-01 18:03:48 +03:00
|
|
|
RDFServiceImpl::CreateSingleton(nsISupports* aOuter,
|
|
|
|
const nsIID& aIID, void **aResult)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2005-12-01 18:03:48 +03:00
|
|
|
NS_ENSURE_NO_AGGREGATION(aOuter);
|
1999-09-10 02:35:16 +04:00
|
|
|
|
2005-12-01 18:03:48 +03:00
|
|
|
if (gRDFService) {
|
|
|
|
NS_ERROR("Trying to create RDF serviec twice.");
|
|
|
|
return gRDFService->QueryInterface(aIID, aResult);
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
2015-10-18 08:24:48 +03:00
|
|
|
RefPtr<RDFServiceImpl> serv = new RDFServiceImpl();
|
2005-12-01 18:03:48 +03:00
|
|
|
nsresult rv = serv->Init();
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
return serv->QueryInterface(aIID, aResult);
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
2014-04-27 11:06:00 +04:00
|
|
|
NS_IMPL_ISUPPORTS(RDFServiceImpl, nsIRDFService, nsISupportsWeakReference)
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2001-04-28 06:12:10 +04:00
|
|
|
// Per RFC2396.
|
2012-08-22 19:56:38 +04:00
|
|
|
static const uint8_t
|
2001-04-28 06:12:10 +04:00
|
|
|
kLegalSchemeChars[] = {
|
|
|
|
// ASCII Bits Ordered Hex
|
|
|
|
// 01234567 76543210
|
|
|
|
0x00, // 00-07
|
|
|
|
0x00, // 08-0F
|
|
|
|
0x00, // 10-17
|
|
|
|
0x00, // 18-1F
|
|
|
|
0x00, // 20-27 !"#$%&' 00000000 00000000
|
|
|
|
0x28, // 28-2F ()*+,-./ 00010100 00101000 0x28
|
|
|
|
0xff, // 30-37 01234567 11111111 11111111 0xFF
|
|
|
|
0x03, // 38-3F 89:;<=>? 11000000 00000011 0x03
|
|
|
|
0xfe, // 40-47 @ABCDEFG 01111111 11111110 0xFE
|
|
|
|
0xff, // 48-4F HIJKLMNO 11111111 11111111 0xFF
|
|
|
|
0xff, // 50-57 PQRSTUVW 11111111 11111111 0xFF
|
|
|
|
0x87, // 58-5F XYZ[\]^_ 11100001 10000111 0x87
|
|
|
|
0xfe, // 60-67 `abcdefg 01111111 11111110 0xFE
|
|
|
|
0xff, // 68-6F hijklmno 11111111 11111111 0xFF
|
|
|
|
0xff, // 70-77 pqrstuvw 11111111 11111111 0xFF
|
|
|
|
0x07, // 78-7F xyz{|}~ 11100000 00000111 0x07
|
|
|
|
0x00, 0x00, 0x00, 0x00, // >= 80
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00,
|
|
|
|
0x00, 0x00, 0x00, 0x00
|
|
|
|
};
|
|
|
|
|
2011-09-29 10:19:26 +04:00
|
|
|
static inline bool
|
2001-04-28 06:12:10 +04:00
|
|
|
IsLegalSchemeCharacter(const char aChar)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
uint8_t mask = kLegalSchemeChars[aChar >> 3];
|
2012-10-20 06:01:43 +04:00
|
|
|
uint8_t bit = 1u << (aChar & 0x7);
|
2011-09-29 10:19:26 +04:00
|
|
|
return bool((mask & bit) != 0);
|
2001-04-28 06:12:10 +04:00
|
|
|
}
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-02-25 22:02:00 +03:00
|
|
|
RDFServiceImpl::GetResource(const nsACString& aURI, nsIRDFResource** aResource)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
1999-03-02 04:00:45 +03:00
|
|
|
// Sanity checks
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aResource != nullptr, "null ptr");
|
2003-03-05 05:35:23 +03:00
|
|
|
NS_PRECONDITION(!aURI.IsEmpty(), "URI is empty");
|
1999-03-02 04:00:45 +03:00
|
|
|
if (! aResource)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
2003-03-05 05:35:23 +03:00
|
|
|
if (aURI.IsEmpty())
|
|
|
|
return NS_ERROR_INVALID_ARG;
|
1999-03-02 04:00:45 +03:00
|
|
|
|
2017-06-20 12:19:05 +03:00
|
|
|
const nsCString& flatURI = PromiseFlatCString(aURI);
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug, ("rdfserv get-resource %s", flatURI.get()));
|
1999-07-17 05:46:34 +04:00
|
|
|
|
1999-03-02 04:00:45 +03:00
|
|
|
// First, check the cache to see if we've already created and
|
|
|
|
// registered this thing.
|
2015-05-21 10:34:25 +03:00
|
|
|
PLDHashEntryHdr *hdr = mResources.Search(flatURI.get());
|
2015-01-23 08:06:55 +03:00
|
|
|
if (hdr) {
|
2007-07-08 11:08:04 +04:00
|
|
|
ResourceHashEntry *entry = static_cast<ResourceHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
NS_ADDREF(*aResource = entry->mResource);
|
1999-02-26 13:17:14 +03:00
|
|
|
return NS_OK;
|
1999-03-02 04:00:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
// Nope. So go to the repository to create it.
|
1999-07-17 05:46:34 +04:00
|
|
|
|
|
|
|
// Compute the scheme of the URI. Scan forward until we either:
|
|
|
|
//
|
|
|
|
// 1. Reach the end of the string
|
|
|
|
// 2. Encounter a non-alpha character
|
|
|
|
// 3. Encouter a colon.
|
|
|
|
//
|
|
|
|
// If we encounter a colon _before_ encountering a non-alpha
|
|
|
|
// character, then assume it's the scheme.
|
|
|
|
//
|
|
|
|
// XXX Although it's really not correct, we'll allow underscore
|
|
|
|
// characters ('_'), too.
|
2003-02-25 22:02:00 +03:00
|
|
|
nsACString::const_iterator p, end;
|
|
|
|
aURI.BeginReading(p);
|
|
|
|
aURI.EndReading(end);
|
2003-03-11 18:37:32 +03:00
|
|
|
while (p != end && IsLegalSchemeCharacter(*p))
|
1999-07-17 05:46:34 +04:00
|
|
|
++p;
|
|
|
|
|
1999-02-26 13:17:14 +03:00
|
|
|
nsresult rv;
|
1999-07-17 05:46:34 +04:00
|
|
|
nsCOMPtr<nsIFactory> factory;
|
|
|
|
|
2003-02-25 22:02:00 +03:00
|
|
|
nsACString::const_iterator begin;
|
|
|
|
aURI.BeginReading(begin);
|
1999-07-17 05:46:34 +04:00
|
|
|
if (*p == ':') {
|
1999-09-10 02:35:16 +04:00
|
|
|
// There _was_ a scheme. First see if it's the same scheme
|
|
|
|
// that we just tried to use...
|
2003-02-25 22:02:00 +03:00
|
|
|
if (mLastFactory && mLastURIPrefix.Equals(Substring(begin, p)))
|
1999-09-10 02:35:16 +04:00
|
|
|
factory = mLastFactory;
|
|
|
|
else {
|
|
|
|
// Try to find a factory using the component manager.
|
2003-02-25 22:02:00 +03:00
|
|
|
nsACString::const_iterator begin;
|
|
|
|
aURI.BeginReading(begin);
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contractID;
|
2003-02-25 22:02:00 +03:00
|
|
|
contractID = NS_LITERAL_CSTRING(NS_RDF_RESOURCE_FACTORY_CONTRACTID_PREFIX) +
|
|
|
|
Substring(begin, p);
|
1999-03-02 04:00:45 +03:00
|
|
|
|
2004-11-01 21:50:36 +03:00
|
|
|
factory = do_GetClassObject(contractID.get());
|
|
|
|
if (factory) {
|
1999-09-10 02:35:16 +04:00
|
|
|
// Store the factory in our one-element cache.
|
2003-02-25 22:02:00 +03:00
|
|
|
if (p != begin) {
|
1999-09-10 02:35:16 +04:00
|
|
|
mLastFactory = factory;
|
2003-02-25 22:02:00 +03:00
|
|
|
mLastURIPrefix = Substring(begin, p);
|
1999-09-10 02:35:16 +04:00
|
|
|
}
|
|
|
|
}
|
1999-02-26 13:17:14 +03:00
|
|
|
}
|
|
|
|
}
|
1999-03-02 04:00:45 +03:00
|
|
|
|
1999-07-17 05:46:34 +04:00
|
|
|
if (! factory) {
|
|
|
|
// fall through to using the "default" resource factory if either:
|
|
|
|
//
|
|
|
|
// 1. The URI didn't have a scheme, or
|
|
|
|
// 2. There was no resource factory registered for the scheme.
|
1999-09-10 02:35:16 +04:00
|
|
|
factory = mDefaultResourceFactory;
|
1999-07-17 05:46:34 +04:00
|
|
|
|
1999-09-10 02:35:16 +04:00
|
|
|
// Store the factory in our one-element cache.
|
2003-02-25 22:02:00 +03:00
|
|
|
if (p != begin) {
|
1999-09-10 02:35:16 +04:00
|
|
|
mLastFactory = factory;
|
2003-02-25 22:02:00 +03:00
|
|
|
mLastURIPrefix = Substring(begin, p);
|
1999-09-10 02:35:16 +04:00
|
|
|
}
|
|
|
|
}
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
nsIRDFResource *result;
|
2012-07-30 18:20:58 +04:00
|
|
|
rv = factory->CreateInstance(nullptr, NS_GET_IID(nsIRDFResource), (void**) &result);
|
1999-07-17 05:46:34 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
2008-10-02 10:49:45 +04:00
|
|
|
// Now initialize it with its URI. At this point, the resource
|
1999-03-02 04:00:45 +03:00
|
|
|
// implementation should register itself with the RDF service.
|
2003-02-25 22:02:00 +03:00
|
|
|
rv = result->Init(flatURI.get());
|
1999-02-26 14:42:05 +03:00
|
|
|
if (NS_FAILED(rv)) {
|
1999-03-02 04:00:45 +03:00
|
|
|
NS_ERROR("unable to initialize resource");
|
1999-02-26 14:42:05 +03:00
|
|
|
NS_RELEASE(result);
|
|
|
|
return rv;
|
|
|
|
}
|
1999-01-05 06:53:15 +03:00
|
|
|
|
1999-03-02 04:00:45 +03:00
|
|
|
*aResource = result; // already refcounted from repository
|
1999-02-26 14:42:05 +03:00
|
|
|
return rv;
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2003-02-25 22:02:00 +03:00
|
|
|
RDFServiceImpl::GetUnicodeResource(const nsAString& aURI, nsIRDFResource** aResource)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2006-02-03 17:18:39 +03:00
|
|
|
return GetResource(NS_ConvertUTF16toUTF8(aURI), aResource);
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-09-06 23:35:41 +04:00
|
|
|
NS_IMETHODIMP
|
1999-09-10 02:35:16 +04:00
|
|
|
RDFServiceImpl::GetAnonymousResource(nsIRDFResource** aResult)
|
1999-09-06 23:35:41 +04:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
static uint32_t gCounter = 0;
|
1999-09-06 23:35:41 +04:00
|
|
|
static char gChars[] = "0123456789abcdef"
|
|
|
|
"ghijklmnopqrstuv"
|
|
|
|
"wxyzABCDEFGHIJKL"
|
|
|
|
"MNOPQRSTUVWXYZ.+";
|
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
static int32_t kMask = 0x003f;
|
|
|
|
static int32_t kShift = 6;
|
1999-09-06 23:35:41 +04:00
|
|
|
|
|
|
|
if (! gCounter) {
|
|
|
|
// Start it at a semi-unique value, just to minimize the
|
|
|
|
// chance that we get into a situation where
|
|
|
|
//
|
|
|
|
// 1. An anonymous resource gets serialized out in a graph
|
|
|
|
// 2. Reboot
|
|
|
|
// 3. The same anonymous resource gets requested, and refers
|
|
|
|
// to something completely different.
|
|
|
|
// 4. The serialization is read back in.
|
2012-10-12 21:29:11 +04:00
|
|
|
gCounter = uint32_t(PR_Now());
|
1999-09-06 23:35:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv;
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString s;
|
1999-09-06 23:35:41 +04:00
|
|
|
|
|
|
|
do {
|
|
|
|
// Ugh, this is a really sloppy way to do this; I copied the
|
|
|
|
// implementation from the days when it lived outside the RDF
|
|
|
|
// service. Now that it's a member we can be more cleverer.
|
|
|
|
|
|
|
|
s.Truncate();
|
2014-05-22 07:48:51 +04:00
|
|
|
s.AppendLiteral("rdf:#$");
|
1999-09-06 23:35:41 +04:00
|
|
|
|
2012-08-22 19:56:38 +04:00
|
|
|
uint32_t id = ++gCounter;
|
1999-09-06 23:35:41 +04:00
|
|
|
while (id) {
|
|
|
|
char ch = gChars[(id & kMask)];
|
|
|
|
s.Append(ch);
|
|
|
|
id >>= kShift;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsIRDFResource* resource;
|
2003-02-25 22:02:00 +03:00
|
|
|
rv = GetResource(s, &resource);
|
1999-09-06 23:35:41 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
// XXX an ugly but effective way to make sure that this
|
|
|
|
// resource is really unique in the world.
|
|
|
|
resource->AddRef();
|
|
|
|
nsrefcnt refcnt = resource->Release();
|
|
|
|
|
|
|
|
if (refcnt == 1) {
|
|
|
|
*aResult = resource;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_RELEASE(resource);
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
NS_IMETHODIMP
|
2014-01-04 19:02:17 +04:00
|
|
|
RDFServiceImpl::GetLiteral(const char16_t* aValue, nsIRDFLiteral** aLiteral)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aValue != nullptr, "null ptr");
|
1999-03-08 11:28:46 +03:00
|
|
|
if (! aValue)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aLiteral != nullptr, "null ptr");
|
1999-03-08 11:28:46 +03:00
|
|
|
if (! aLiteral)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
// See if we have one already cached
|
2015-05-21 10:34:25 +03:00
|
|
|
PLDHashEntryHdr *hdr = mLiterals.Search(aValue);
|
2015-01-23 08:06:55 +03:00
|
|
|
if (hdr) {
|
2007-07-08 11:08:04 +04:00
|
|
|
LiteralHashEntry *entry = static_cast<LiteralHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
NS_ADDREF(*aLiteral = entry->mLiteral);
|
1999-03-08 11:28:46 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nope. Create a new one
|
2000-08-26 10:43:09 +04:00
|
|
|
return LiteralImpl::Create(aValue, aLiteral);
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
1999-03-09 07:01:56 +03:00
|
|
|
NS_IMETHODIMP
|
2001-12-21 02:04:33 +03:00
|
|
|
RDFServiceImpl::GetDateLiteral(PRTime aTime, nsIRDFDate** aResult)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
2001-12-21 02:04:33 +03:00
|
|
|
// See if we have one already cached
|
2015-05-21 10:34:25 +03:00
|
|
|
PLDHashEntryHdr *hdr = mDates.Search(&aTime);
|
2015-01-23 08:06:55 +03:00
|
|
|
if (hdr) {
|
2007-07-08 11:08:04 +04:00
|
|
|
DateHashEntry *entry = static_cast<DateHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
NS_ADDREF(*aResult = entry->mDate);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
DateImpl* result = new DateImpl(aTime);
|
1999-03-09 07:01:56 +03:00
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
NS_ADDREF(*aResult = result);
|
1999-03-09 07:01:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
RDFServiceImpl::GetIntLiteral(int32_t aInt, nsIRDFInt** aResult)
|
1999-03-09 07:01:56 +03:00
|
|
|
{
|
2001-12-21 02:04:33 +03:00
|
|
|
// See if we have one already cached
|
2015-05-21 10:34:25 +03:00
|
|
|
PLDHashEntryHdr *hdr = mInts.Search(&aInt);
|
2015-01-23 08:06:55 +03:00
|
|
|
if (hdr) {
|
2007-07-08 11:08:04 +04:00
|
|
|
IntHashEntry *entry = static_cast<IntHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
NS_ADDREF(*aResult = entry->mInt);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
IntImpl* result = new IntImpl(aInt);
|
1999-03-09 07:01:56 +03:00
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
NS_ADDREF(*aResult = result);
|
1999-03-09 07:01:56 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-15 04:57:17 +03:00
|
|
|
NS_IMETHODIMP
|
2012-08-22 19:56:38 +04:00
|
|
|
RDFServiceImpl::GetBlobLiteral(const uint8_t *aBytes, int32_t aLength,
|
2002-01-15 04:57:17 +03:00
|
|
|
nsIRDFBlob **aResult)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
BlobImpl::Data key = { aLength, const_cast<uint8_t *>(aBytes) };
|
2002-01-15 04:57:17 +03:00
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
PLDHashEntryHdr *hdr = mBlobs.Search(&key);
|
2015-01-23 08:06:55 +03:00
|
|
|
if (hdr) {
|
2007-07-08 11:08:04 +04:00
|
|
|
BlobHashEntry *entry = static_cast<BlobHashEntry *>(hdr);
|
2002-01-15 04:57:17 +03:00
|
|
|
NS_ADDREF(*aResult = entry->mBlob);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
BlobImpl *result = new BlobImpl(aBytes, aLength);
|
|
|
|
if (! result)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
NS_ADDREF(*aResult = result);
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-09-06 23:35:41 +04:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
RDFServiceImpl::IsAnonymousResource(nsIRDFResource* aResource, bool* _result)
|
1999-09-06 23:35:41 +04:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aResource != nullptr, "null ptr");
|
1999-09-06 23:35:41 +04:00
|
|
|
if (! aResource)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
const char* uri;
|
|
|
|
rv = aResource->GetValueConst(&uri);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
|
|
|
if ((uri[0] == 'r') &&
|
|
|
|
(uri[1] == 'd') &&
|
|
|
|
(uri[2] == 'f') &&
|
|
|
|
(uri[3] == ':') &&
|
|
|
|
(uri[4] == '#') &&
|
|
|
|
(uri[5] == '$')) {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_result = true;
|
1999-09-06 23:35:41 +04:00
|
|
|
}
|
|
|
|
else {
|
2011-10-17 18:59:28 +04:00
|
|
|
*_result = false;
|
1999-09-06 23:35:41 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
RDFServiceImpl::RegisterResource(nsIRDFResource* aResource, bool aReplace)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aResource != nullptr, "null ptr");
|
1999-02-26 13:17:14 +03:00
|
|
|
if (! aResource)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
nsresult rv;
|
|
|
|
|
1999-07-17 05:46:34 +04:00
|
|
|
const char* uri;
|
|
|
|
rv = aResource->GetValueConst(&uri);
|
|
|
|
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to get URI from resource");
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-02 04:00:45 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(uri != nullptr, "resource has no URI");
|
1999-03-02 04:00:45 +03:00
|
|
|
if (! uri)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
PLDHashEntryHdr *hdr = mResources.Search(uri);
|
2015-01-23 08:06:55 +03:00
|
|
|
if (hdr) {
|
1999-09-19 23:41:45 +04:00
|
|
|
if (!aReplace) {
|
1999-04-17 02:04:32 +04:00
|
|
|
NS_WARNING("resource already registered, and replace not specified");
|
|
|
|
return NS_ERROR_FAILURE; // already registered
|
|
|
|
}
|
1999-03-18 23:47:27 +03:00
|
|
|
|
1999-04-17 02:04:32 +04:00
|
|
|
// N.B., we do _not_ release the original resource because we
|
|
|
|
// only ever held a weak reference to it. We simply replace
|
|
|
|
// it.
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
1999-04-28 10:24:19 +04:00
|
|
|
("rdfserv replace-resource [%p] <-- [%p] %s",
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<ResourceHashEntry *>(hdr)->mResource,
|
2001-12-21 02:04:33 +03:00
|
|
|
aResource, (const char*) uri));
|
1999-03-29 23:52:54 +04:00
|
|
|
}
|
1999-04-17 02:04:32 +04:00
|
|
|
else {
|
2015-09-15 00:23:12 +03:00
|
|
|
hdr = mResources.Add(uri, fallible);
|
2001-12-21 02:04:33 +03:00
|
|
|
if (! hdr)
|
1999-04-17 02:04:32 +04:00
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-29 23:52:54 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
1999-04-28 10:24:19 +04:00
|
|
|
("rdfserv register-resource [%p] %s",
|
|
|
|
aResource, (const char*) uri));
|
1999-04-17 02:04:32 +04:00
|
|
|
}
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
// N.B., we only hold a weak reference to the resource: that way,
|
|
|
|
// the resource can be destroyed when the last refcount goes
|
|
|
|
// away. The single addref that the CreateResource() call made
|
|
|
|
// will be owned by the callee.
|
2007-07-08 11:08:04 +04:00
|
|
|
ResourceHashEntry *entry = static_cast<ResourceHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
entry->mResource = aResource;
|
|
|
|
entry->mKey = uri;
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-10 02:35:16 +04:00
|
|
|
RDFServiceImpl::UnregisterResource(nsIRDFResource* aResource)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aResource != nullptr, "null ptr");
|
1999-04-28 10:24:19 +04:00
|
|
|
if (! aResource)
|
1999-03-02 04:00:45 +03:00
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-02-26 13:17:14 +03:00
|
|
|
nsresult rv;
|
1999-01-05 06:53:15 +03:00
|
|
|
|
1999-07-17 05:46:34 +04:00
|
|
|
const char* uri;
|
|
|
|
rv = aResource->GetValueConst(&uri);
|
1999-03-29 23:52:54 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_ASSERTION(uri != nullptr, "resource has no URI");
|
1999-08-12 05:16:13 +04:00
|
|
|
if (! uri)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
1999-04-28 10:24:19 +04:00
|
|
|
("rdfserv unregister-resource [%p] %s",
|
|
|
|
aResource, (const char*) uri));
|
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
#ifdef DEBUG
|
2015-05-21 10:34:25 +03:00
|
|
|
if (!mResources.Search(uri))
|
2001-12-21 02:04:33 +03:00
|
|
|
NS_WARNING("resource was never registered");
|
|
|
|
#endif
|
|
|
|
|
2015-09-15 00:23:24 +03:00
|
|
|
mResources.Remove(uri);
|
1999-01-05 06:53:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2011-09-29 10:19:26 +04:00
|
|
|
RDFServiceImpl::RegisterDataSource(nsIRDFDataSource* aDataSource, bool aReplace)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aDataSource != nullptr, "null ptr");
|
1999-01-14 13:55:08 +03:00
|
|
|
if (! aDataSource)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-03-29 23:52:54 +04:00
|
|
|
nsXPIDLCString uri;
|
|
|
|
rv = aDataSource->GetURI(getter_Copies(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-14 13:55:08 +03:00
|
|
|
|
1999-04-17 02:04:32 +04:00
|
|
|
PLHashEntry** hep =
|
|
|
|
PL_HashTableRawLookup(mNamedDataSources, (*mNamedDataSources->keyHash)(uri), uri);
|
1999-02-26 13:17:14 +03:00
|
|
|
|
1999-04-17 02:04:32 +04:00
|
|
|
if (*hep) {
|
1999-09-19 23:41:45 +04:00
|
|
|
if (! aReplace)
|
1999-04-17 02:04:32 +04:00
|
|
|
return NS_ERROR_FAILURE; // already registered
|
|
|
|
|
|
|
|
// N.B., we only hold a weak reference to the datasource, so
|
|
|
|
// just replace the old with the new and don't touch any
|
|
|
|
// refcounts.
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
1999-04-28 10:24:19 +04:00
|
|
|
("rdfserv replace-datasource [%p] <-- [%p] %s",
|
|
|
|
(*hep)->value, aDataSource, (const char*) uri));
|
|
|
|
|
1999-04-17 02:04:32 +04:00
|
|
|
(*hep)->value = aDataSource;
|
1999-02-26 13:17:14 +03:00
|
|
|
}
|
1999-04-17 02:04:32 +04:00
|
|
|
else {
|
|
|
|
const char* key = PL_strdup(uri);
|
|
|
|
if (! key)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-01-14 13:55:08 +03:00
|
|
|
|
1999-04-17 02:04:32 +04:00
|
|
|
PL_HashTableAdd(mNamedDataSources, key, aDataSource);
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
1999-04-28 10:24:19 +04:00
|
|
|
("rdfserv register-datasource [%p] %s",
|
|
|
|
aDataSource, (const char*) uri));
|
|
|
|
|
1999-04-17 02:04:32 +04:00
|
|
|
// N.B., we only hold a weak reference to the datasource, so don't
|
|
|
|
// addref.
|
|
|
|
}
|
1999-03-30 05:41:21 +04:00
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
1999-09-10 02:35:16 +04:00
|
|
|
RDFServiceImpl::UnregisterDataSource(nsIRDFDataSource* aDataSource)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aDataSource != nullptr, "null ptr");
|
1999-01-14 13:55:08 +03:00
|
|
|
if (! aDataSource)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
1999-03-29 23:52:54 +04:00
|
|
|
nsXPIDLCString uri;
|
|
|
|
rv = aDataSource->GetURI(getter_Copies(uri));
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-01-14 13:55:08 +03:00
|
|
|
|
2012-07-30 18:20:58 +04:00
|
|
|
//NS_ASSERTION(uri != nullptr, "datasource has no URI");
|
1999-04-17 02:04:32 +04:00
|
|
|
if (! uri)
|
|
|
|
return NS_ERROR_UNEXPECTED;
|
1999-01-05 06:53:15 +03:00
|
|
|
|
1999-04-17 02:04:32 +04:00
|
|
|
PLHashEntry** hep =
|
|
|
|
PL_HashTableRawLookup(mNamedDataSources, (*mNamedDataSources->keyHash)(uri), uri);
|
|
|
|
|
1999-09-24 23:54:36 +04:00
|
|
|
// It may well be that this datasource was never registered. If
|
|
|
|
// so, don't unregister it.
|
|
|
|
if (! *hep || ((*hep)->value != aDataSource))
|
|
|
|
return NS_OK;
|
1999-04-17 02:04:32 +04:00
|
|
|
|
|
|
|
// N.B., we only held a weak reference to the datasource, so we
|
|
|
|
// don't release here.
|
|
|
|
PL_HashTableRawRemove(mNamedDataSources, hep, *hep);
|
1999-01-05 06:53:15 +03:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
1999-04-28 10:24:19 +04:00
|
|
|
("rdfserv unregister-datasource [%p] %s",
|
|
|
|
aDataSource, (const char*) uri));
|
|
|
|
|
1999-01-05 06:53:15 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
1999-01-14 13:55:08 +03:00
|
|
|
NS_IMETHODIMP
|
1999-09-19 23:41:45 +04:00
|
|
|
RDFServiceImpl::GetDataSource(const char* aURI, nsIRDFDataSource** aDataSource)
|
2001-12-06 06:44:42 +03:00
|
|
|
{
|
|
|
|
// Use the other GetDataSource and ask for a non-blocking Refresh.
|
|
|
|
// If you wanted it loaded synchronously, then you should've tried to do it
|
|
|
|
// yourself, or used GetDataSourceBlocking.
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetDataSource( aURI, false, aDataSource );
|
2001-12-06 06:44:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
|
|
|
RDFServiceImpl::GetDataSourceBlocking(const char* aURI, nsIRDFDataSource** aDataSource)
|
|
|
|
{
|
|
|
|
// Use GetDataSource and ask for a blocking Refresh.
|
2011-10-17 18:59:28 +04:00
|
|
|
return GetDataSource( aURI, true, aDataSource );
|
2001-12-06 06:44:42 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
2011-09-29 10:19:26 +04:00
|
|
|
RDFServiceImpl::GetDataSource(const char* aURI, bool aBlock, nsIRDFDataSource** aDataSource)
|
1999-01-05 06:53:15 +03:00
|
|
|
{
|
2012-07-30 18:20:58 +04:00
|
|
|
NS_PRECONDITION(aURI != nullptr, "null ptr");
|
1999-09-19 23:41:45 +04:00
|
|
|
if (! aURI)
|
|
|
|
return NS_ERROR_NULL_POINTER;
|
|
|
|
|
1999-06-24 04:22:58 +04:00
|
|
|
nsresult rv;
|
|
|
|
|
2002-04-07 21:40:47 +04:00
|
|
|
// Attempt to canonify the URI before we look for it in the
|
|
|
|
// cache. We won't bother doing this on `rdf:' URIs to avoid
|
|
|
|
// useless (and expensive) protocol handler lookups.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString spec(aURI);
|
2002-04-07 21:40:47 +04:00
|
|
|
|
2003-07-14 11:37:39 +04:00
|
|
|
if (!StringBeginsWith(spec, NS_LITERAL_CSTRING("rdf:"))) {
|
2002-04-07 21:40:47 +04:00
|
|
|
nsCOMPtr<nsIURI> uri;
|
2003-07-14 11:37:39 +04:00
|
|
|
NS_NewURI(getter_AddRefs(uri), spec);
|
2016-08-31 02:08:42 +03:00
|
|
|
if (uri) {
|
|
|
|
rv = uri->GetSpec(spec);
|
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
2002-04-07 21:40:47 +04:00
|
|
|
}
|
2002-01-29 02:07:55 +03:00
|
|
|
|
1999-03-02 04:00:45 +03:00
|
|
|
// First, check the cache to see if we already have this
|
|
|
|
// datasource loaded and initialized.
|
1999-05-05 07:09:12 +04:00
|
|
|
{
|
|
|
|
nsIRDFDataSource* cached =
|
2007-07-08 11:08:04 +04:00
|
|
|
static_cast<nsIRDFDataSource*>(PL_HashTableLookup(mNamedDataSources, spec.get()));
|
1999-05-05 07:09:12 +04:00
|
|
|
|
|
|
|
if (cached) {
|
|
|
|
NS_ADDREF(cached);
|
|
|
|
*aDataSource = cached;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-01-06 20:38:37 +03:00
|
|
|
}
|
1999-03-02 04:00:45 +03:00
|
|
|
|
|
|
|
// Nope. So go to the repository to try to create it.
|
1999-05-05 07:09:12 +04:00
|
|
|
nsCOMPtr<nsIRDFDataSource> ds;
|
2003-07-14 11:37:39 +04:00
|
|
|
if (StringBeginsWith(spec, NS_LITERAL_CSTRING("rdf:"))) {
|
2002-01-29 02:07:55 +03:00
|
|
|
// It's a built-in data source. Convert it to a contract ID.
|
2012-09-02 06:35:17 +04:00
|
|
|
nsAutoCString contractID(
|
2001-10-16 07:53:44 +04:00
|
|
|
NS_LITERAL_CSTRING(NS_RDF_DATASOURCE_CONTRACTID_PREFIX) +
|
2002-01-29 02:07:55 +03:00
|
|
|
Substring(spec, 4, spec.Length() - 4));
|
1999-03-02 04:00:45 +03:00
|
|
|
|
2002-01-29 02:07:55 +03:00
|
|
|
// Strip params to get ``base'' contractID for data source.
|
2014-01-04 19:02:17 +04:00
|
|
|
int32_t p = contractID.FindChar(char16_t('&'));
|
2002-01-29 02:07:55 +03:00
|
|
|
if (p >= 0)
|
2001-10-16 07:53:44 +04:00
|
|
|
contractID.Truncate(p);
|
1999-05-15 03:56:30 +04:00
|
|
|
|
2002-01-29 02:07:55 +03:00
|
|
|
ds = do_GetService(contractID.get(), &rv);
|
1999-05-18 07:53:18 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-06-24 04:22:58 +04:00
|
|
|
nsCOMPtr<nsIRDFRemoteDataSource> remote = do_QueryInterface(ds);
|
|
|
|
if (remote) {
|
2002-01-29 02:07:55 +03:00
|
|
|
rv = remote->Init(spec.get());
|
1999-06-24 04:22:58 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
}
|
1999-03-25 10:33:07 +03:00
|
|
|
}
|
|
|
|
else {
|
1999-03-26 07:43:02 +03:00
|
|
|
// Try to load this as an RDF/XML data source
|
2000-12-09 07:21:51 +03:00
|
|
|
ds = do_CreateInstance(kRDFXMLDataSourceCID, &rv);
|
1999-05-05 07:09:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
|
1999-06-24 04:22:58 +04:00
|
|
|
nsCOMPtr<nsIRDFRemoteDataSource> remote(do_QueryInterface(ds));
|
|
|
|
NS_ASSERTION(remote, "not a remote RDF/XML data source!");
|
|
|
|
if (! remote) return NS_ERROR_UNEXPECTED;
|
|
|
|
|
2002-01-29 02:07:55 +03:00
|
|
|
rv = remote->Init(spec.get());
|
1999-06-24 04:22:58 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-26 07:43:02 +03:00
|
|
|
|
2001-12-06 06:44:42 +03:00
|
|
|
rv = remote->Refresh(aBlock);
|
1999-05-05 07:09:12 +04:00
|
|
|
if (NS_FAILED(rv)) return rv;
|
1999-03-02 04:00:45 +03:00
|
|
|
}
|
|
|
|
|
1999-03-25 10:33:07 +03:00
|
|
|
*aDataSource = ds;
|
1999-05-05 07:09:12 +04:00
|
|
|
NS_ADDREF(*aDataSource);
|
1999-03-01 08:55:18 +03:00
|
|
|
return NS_OK;
|
1999-01-05 06:53:15 +03:00
|
|
|
}
|
|
|
|
|
1999-03-08 11:28:46 +03:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
nsresult
|
2001-12-21 02:04:33 +03:00
|
|
|
RDFServiceImpl::RegisterLiteral(nsIRDFLiteral* aLiteral)
|
1999-03-08 11:28:46 +03:00
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* value;
|
2001-12-21 02:04:33 +03:00
|
|
|
aLiteral->GetValueConst(&value);
|
1999-03-08 11:28:46 +03:00
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(!mLiterals.Search(value), "literal already registered");
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2015-09-15 00:23:12 +03:00
|
|
|
PLDHashEntryHdr *hdr = mLiterals.Add(value, fallible);
|
2001-12-21 02:04:33 +03:00
|
|
|
if (! hdr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-03-08 11:28:46 +03:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
LiteralHashEntry *entry = static_cast<LiteralHashEntry *>(hdr);
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
// N.B., we only hold a weak reference to the literal: that
|
|
|
|
// way, the literal can be destroyed when the last refcount
|
|
|
|
// goes away. The single addref that the CreateLiteral() call
|
|
|
|
// made will be owned by the callee.
|
|
|
|
entry->mLiteral = aLiteral;
|
|
|
|
entry->mKey = value;
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2001-12-21 02:04:33 +03:00
|
|
|
("rdfserv register-literal [%p] %s",
|
2016-12-16 06:16:31 +03:00
|
|
|
aLiteral, NS_ConvertUTF16toUTF8(value).get()));
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
1999-07-16 08:01:21 +04:00
|
|
|
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
nsresult
|
|
|
|
RDFServiceImpl::UnregisterLiteral(nsIRDFLiteral* aLiteral)
|
|
|
|
{
|
2014-01-04 19:02:17 +04:00
|
|
|
const char16_t* value;
|
2001-12-21 02:04:33 +03:00
|
|
|
aLiteral->GetValueConst(&value);
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(mLiterals.Search(value), "literal was never registered");
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2015-09-15 00:23:24 +03:00
|
|
|
mLiterals.Remove(value);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
|
|
|
// N.B. that we _don't_ release the literal: we only held a weak
|
|
|
|
// reference to it in the hashtable.
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2001-12-21 02:04:33 +03:00
|
|
|
("rdfserv unregister-literal [%p] %s",
|
2016-12-16 06:16:31 +03:00
|
|
|
aLiteral, NS_ConvertUTF16toUTF8(value).get()));
|
1999-03-29 23:52:54 +04:00
|
|
|
|
1999-03-08 11:28:46 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
//----------------------------------------------------------------------
|
1999-03-08 11:28:46 +03:00
|
|
|
|
|
|
|
nsresult
|
2001-12-21 02:04:33 +03:00
|
|
|
RDFServiceImpl::RegisterInt(nsIRDFInt* aInt)
|
1999-03-08 11:28:46 +03:00
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t value;
|
2001-12-21 02:04:33 +03:00
|
|
|
aInt->GetValue(&value);
|
1999-03-08 11:28:46 +03:00
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(!mInts.Search(&value), "int already registered");
|
1999-03-08 11:28:46 +03:00
|
|
|
|
2015-09-15 00:23:12 +03:00
|
|
|
PLDHashEntryHdr *hdr = mInts.Add(&value, fallible);
|
2001-12-21 02:04:33 +03:00
|
|
|
if (! hdr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
IntHashEntry *entry = static_cast<IntHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
|
|
|
// N.B., we only hold a weak reference to the literal: that
|
|
|
|
// way, the literal can be destroyed when the last refcount
|
|
|
|
// goes away. The single addref that the CreateInt() call
|
|
|
|
// made will be owned by the callee.
|
|
|
|
entry->mInt = aInt;
|
|
|
|
entry->mKey = value;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2001-12-21 02:04:33 +03:00
|
|
|
("rdfserv register-int [%p] %d",
|
|
|
|
aInt, value));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RDFServiceImpl::UnregisterInt(nsIRDFInt* aInt)
|
|
|
|
{
|
2012-08-22 19:56:38 +04:00
|
|
|
int32_t value;
|
2001-12-21 02:04:33 +03:00
|
|
|
aInt->GetValue(&value);
|
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(mInts.Search(&value), "int was never registered");
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2015-09-15 00:23:24 +03:00
|
|
|
mInts.Remove(&value);
|
1999-07-17 05:46:34 +04:00
|
|
|
|
|
|
|
// N.B. that we _don't_ release the literal: we only held a weak
|
|
|
|
// reference to it in the hashtable.
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2001-12-21 02:04:33 +03:00
|
|
|
("rdfserv unregister-int [%p] %d",
|
|
|
|
aInt, value));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//----------------------------------------------------------------------
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RDFServiceImpl::RegisterDate(nsIRDFDate* aDate)
|
|
|
|
{
|
|
|
|
PRTime value;
|
|
|
|
aDate->GetValue(&value);
|
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(!mDates.Search(&value), "date already registered");
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2015-09-15 00:23:12 +03:00
|
|
|
PLDHashEntryHdr *hdr = mDates.Add(&value, fallible);
|
2001-12-21 02:04:33 +03:00
|
|
|
if (! hdr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
DateHashEntry *entry = static_cast<DateHashEntry *>(hdr);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
|
|
|
// N.B., we only hold a weak reference to the literal: that
|
|
|
|
// way, the literal can be destroyed when the last refcount
|
|
|
|
// goes away. The single addref that the CreateDate() call
|
|
|
|
// made will be owned by the callee.
|
|
|
|
entry->mDate = aDate;
|
|
|
|
entry->mKey = value;
|
1999-07-17 05:46:34 +04:00
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2016-12-16 06:16:31 +03:00
|
|
|
("rdfserv register-date [%p] %" PRId64,
|
2001-12-21 02:04:33 +03:00
|
|
|
aDate, value));
|
1999-03-29 23:52:54 +04:00
|
|
|
|
1999-03-08 11:28:46 +03:00
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2001-12-21 02:04:33 +03:00
|
|
|
|
|
|
|
nsresult
|
|
|
|
RDFServiceImpl::UnregisterDate(nsIRDFDate* aDate)
|
|
|
|
{
|
|
|
|
PRTime value;
|
|
|
|
aDate->GetValue(&value);
|
|
|
|
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(mDates.Search(&value), "date was never registered");
|
2001-12-21 02:04:33 +03:00
|
|
|
|
2015-09-15 00:23:24 +03:00
|
|
|
mDates.Remove(&value);
|
2001-12-21 02:04:33 +03:00
|
|
|
|
|
|
|
// N.B. that we _don't_ release the literal: we only held a weak
|
|
|
|
// reference to it in the hashtable.
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2016-12-16 06:16:31 +03:00
|
|
|
("rdfserv unregister-date [%p] %" PRId64,
|
2001-12-21 02:04:33 +03:00
|
|
|
aDate, value));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
2002-01-15 04:57:17 +03:00
|
|
|
nsresult
|
|
|
|
RDFServiceImpl::RegisterBlob(BlobImpl *aBlob)
|
|
|
|
{
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(!mBlobs.Search(&aBlob->mData), "blob already registered");
|
2002-01-15 04:57:17 +03:00
|
|
|
|
2015-09-15 00:23:12 +03:00
|
|
|
PLDHashEntryHdr *hdr = mBlobs.Add(&aBlob->mData, fallible);
|
2002-01-15 04:57:17 +03:00
|
|
|
if (! hdr)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
2007-07-08 11:08:04 +04:00
|
|
|
BlobHashEntry *entry = static_cast<BlobHashEntry *>(hdr);
|
2002-01-15 04:57:17 +03:00
|
|
|
|
|
|
|
// N.B., we only hold a weak reference to the literal: that
|
|
|
|
// way, the literal can be destroyed when the last refcount
|
|
|
|
// goes away. The single addref that the CreateInt() call
|
|
|
|
// made will be owned by the callee.
|
|
|
|
entry->mBlob = aBlob;
|
|
|
|
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2002-01-15 04:57:17 +03:00
|
|
|
("rdfserv register-blob [%p] %s",
|
|
|
|
aBlob, aBlob->mData.mBytes));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult
|
|
|
|
RDFServiceImpl::UnregisterBlob(BlobImpl *aBlob)
|
|
|
|
{
|
2015-05-21 10:34:25 +03:00
|
|
|
NS_ASSERTION(mBlobs.Search(&aBlob->mData), "blob was never registered");
|
2002-01-15 04:57:17 +03:00
|
|
|
|
2015-09-15 00:23:24 +03:00
|
|
|
mBlobs.Remove(&aBlob->mData);
|
2015-01-23 08:06:55 +03:00
|
|
|
|
2002-01-15 04:57:17 +03:00
|
|
|
// N.B. that we _don't_ release the literal: we only held a weak
|
|
|
|
// reference to it in the hashtable.
|
2015-06-04 01:25:57 +03:00
|
|
|
MOZ_LOG(gLog, LogLevel::Debug,
|
2002-01-15 04:57:17 +03:00
|
|
|
("rdfserv unregister-blob [%p] %s",
|
|
|
|
aBlob, aBlob->mData.mBytes));
|
|
|
|
|
|
|
|
return NS_OK;
|
|
|
|
}
|