1998-12-10 02:08:59 +03:00
|
|
|
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
|
|
|
*
|
1999-11-06 06:43:54 +03: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/
|
1998-12-10 02:08:59 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03: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.
|
1998-12-10 02:08:59 +03:00
|
|
|
*
|
1999-11-06 06:43:54 +03:00
|
|
|
* The Original Code is mozilla.org code.
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is Netscape
|
1998-12-10 02:08:59 +03:00
|
|
|
* Communications Corporation. Portions created by Netscape are
|
1999-11-06 06:43:54 +03:00
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All
|
|
|
|
* Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
1998-12-10 02:08:59 +03:00
|
|
|
*/
|
|
|
|
#include "rdf-int.h"
|
1998-12-14 23:51:53 +03:00
|
|
|
#include "gs.h"
|
1998-12-10 02:08:59 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
asEqual(RDFT r, Assertion as, RDF_Resource u, RDF_Resource s, void* v,
|
|
|
|
RDF_ValueType type)
|
|
|
|
{
|
|
|
|
return (((r == NULL) || (as->db == r)) &&
|
|
|
|
(as->u == u) &&
|
|
|
|
(as->s == s) &&
|
|
|
|
(as->type == type) &&
|
|
|
|
((as->value == v) ||
|
1998-12-14 02:45:53 +03:00
|
|
|
((type == RDF_STRING_TYPE) && (strcmp((char*)v, (char*)as->value) == 0))));
|
1998-12-10 02:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Assertion
|
|
|
|
makeNewAssertion (RDFT r, RDF_Resource u, RDF_Resource s, void* v,
|
|
|
|
RDF_ValueType type, int tv)
|
|
|
|
{
|
1998-12-12 04:58:15 +03:00
|
|
|
Assertion newAs = (Assertion) fgetMem(sizeof(RDF_AssertionStruct));
|
1998-12-10 02:08:59 +03:00
|
|
|
newAs->u = u;
|
|
|
|
newAs->s = s;
|
|
|
|
newAs->value = v;
|
|
|
|
newAs->type = type;
|
|
|
|
newAs->db = r;
|
|
|
|
return newAs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
addToAssertionList (RDFT f, Assertion as)
|
|
|
|
{
|
|
|
|
if (f->assertionListCount >= f->assertionListSize) {
|
1998-12-14 02:45:53 +03:00
|
|
|
f->assertionList = (Assertion*) realloc(f->assertionList,
|
1998-12-10 02:08:59 +03:00
|
|
|
(sizeof(Assertion*) *
|
|
|
|
(f->assertionListSize =
|
|
|
|
f->assertionListSize + GROW_LIST_INCR)));
|
|
|
|
}
|
|
|
|
*(f->assertionList + f->assertionListCount++) = as;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
freeAssertion (Assertion as)
|
|
|
|
{
|
|
|
|
if (as->type == RDF_STRING_TYPE) {
|
|
|
|
freeMem(as->value);
|
|
|
|
}
|
|
|
|
freeMem(as);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Assertion
|
|
|
|
remoteStoreAdd (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
|
|
|
RDF_ValueType type, int tv)
|
|
|
|
{
|
1998-12-12 04:58:15 +03:00
|
|
|
Assertion newAs = makeNewAssertion(mcf, u, s, v, type, tv);
|
|
|
|
newAs->next = u->rarg1;
|
|
|
|
u->rarg1 = newAs;
|
1998-12-10 02:08:59 +03:00
|
|
|
|
|
|
|
if (type == RDF_RESOURCE_TYPE) {
|
1998-12-12 04:58:15 +03:00
|
|
|
RDF_Resource iu = (RDF_Resource)v;
|
|
|
|
newAs->invNext = iu->rarg2;
|
|
|
|
iu->rarg2 = newAs;
|
1998-12-10 02:08:59 +03:00
|
|
|
}
|
1999-02-01 19:32:37 +03:00
|
|
|
/* if (type == RDF_STRING_TYPE) RDFGS_AddSearchIndex(mcf, (char*) v, s, u); */
|
1998-12-14 23:51:53 +03:00
|
|
|
|
1998-12-10 02:08:59 +03:00
|
|
|
return newAs;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Assertion
|
|
|
|
remoteStoreRemove (RDFT mcf, RDF_Resource u, RDF_Resource s,
|
|
|
|
void* v, RDF_ValueType type)
|
|
|
|
{
|
|
|
|
Assertion nextAs, prevAs, ans;
|
|
|
|
int found = false;
|
|
|
|
nextAs = prevAs = u->rarg1;
|
|
|
|
while (nextAs != null) {
|
|
|
|
if (asEqual(mcf, nextAs, u, s, v, type)) {
|
|
|
|
if (prevAs == nextAs) {
|
|
|
|
u->rarg1 = nextAs->next;
|
|
|
|
} else {
|
|
|
|
prevAs->next = nextAs->next;
|
|
|
|
}
|
|
|
|
found = true;
|
|
|
|
ans = nextAs;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
prevAs = nextAs;
|
|
|
|
nextAs = nextAs->next;
|
|
|
|
}
|
|
|
|
if (found == false) return null;
|
|
|
|
if (type == RDF_RESOURCE_TYPE) {
|
|
|
|
nextAs = prevAs = ((RDF_Resource)v)->rarg2;
|
|
|
|
while (nextAs != null) {
|
|
|
|
if (nextAs == ans) {
|
|
|
|
if (prevAs == nextAs) {
|
|
|
|
((RDF_Resource)v)->rarg2 = nextAs->invNext;
|
|
|
|
} else {
|
|
|
|
prevAs->invNext = nextAs->invNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
prevAs = nextAs;
|
|
|
|
nextAs = nextAs->invNext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return ans;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
remoteStoreHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, int tv)
|
|
|
|
{
|
|
|
|
Assertion nextAs;
|
|
|
|
|
|
|
|
nextAs = u->rarg1;
|
|
|
|
while (nextAs != null) {
|
|
|
|
if (asEqual(mcf, nextAs, u, s, v, type)) return true;
|
|
|
|
nextAs = nextAs->next;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void *
|
|
|
|
getSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, int inversep, int tv)
|
|
|
|
{
|
|
|
|
Assertion nextAs;
|
|
|
|
|
|
|
|
nextAs = (inversep ? u->rarg2 : u->rarg1);
|
|
|
|
while (nextAs != null) {
|
|
|
|
if (((nextAs->db == mcf) || (!mcf)) && (nextAs->s == s)
|
|
|
|
&& (nextAs->type == type)) {
|
|
|
|
return (inversep ? nextAs->u : nextAs->value);
|
|
|
|
}
|
|
|
|
nextAs = (inversep ? nextAs->invNext : nextAs->next);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
RDF_Cursor
|
|
|
|
getSlotValues (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, int inversep, int tv)
|
|
|
|
{
|
|
|
|
Assertion as = (inversep ? u->rarg2 : u->rarg1);
|
|
|
|
RDF_Cursor c;
|
|
|
|
if (!as) return NULL;
|
|
|
|
c = (RDF_Cursor)getMem(sizeof(RDF_CursorStruct));
|
|
|
|
c->u = u;
|
|
|
|
c->s = s;
|
|
|
|
c->type = type;
|
|
|
|
c->inversep = inversep;
|
|
|
|
c->count = 0;
|
|
|
|
c->db = mcf;
|
|
|
|
c->pdata = as;
|
|
|
|
c->queryType = GET_SLOT_VALUES;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
void *
|
|
|
|
nextValue (RDF_Cursor c) {
|
1998-12-16 22:20:49 +03:00
|
|
|
if (!c) return null;
|
1998-12-10 02:08:59 +03:00
|
|
|
while (c->pdata != null) {
|
|
|
|
Assertion as = (Assertion) c->pdata;
|
|
|
|
if (((as->db == c->db) || (!c->db)) && (as->s == c->s) && (c->type == as->type)) {
|
|
|
|
c->value = (c->inversep ? as->u : as->value);
|
|
|
|
c->pdata = (c->inversep ? as->invNext : as->next);
|
|
|
|
return c->value;
|
|
|
|
}
|
|
|
|
c->pdata = (c->inversep ? as->invNext : as->next);
|
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
disposeCursor (RDF_Cursor c)
|
|
|
|
{
|
1998-12-16 22:20:49 +03:00
|
|
|
if (c) freeMem(c);
|
1998-12-10 02:08:59 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
unloadRDFT (RDFT f)
|
|
|
|
{
|
|
|
|
int n = 0;
|
|
|
|
while (n < f->assertionListCount) {
|
|
|
|
Assertion as = *(f->assertionList + n);
|
|
|
|
remoteStoreRemove(f, as->u, as->s, as->value, as->type);
|
|
|
|
freeAssertion(as);
|
|
|
|
*(f->assertionList + n) = NULL;
|
|
|
|
n++;
|
|
|
|
}
|
|
|
|
f->assertionListCount = 0;
|
|
|
|
f->assertionListSize = 0;
|
|
|
|
freeMem(f->assertionList);
|
|
|
|
f->assertionList = NULL;
|
|
|
|
}
|
|
|
|
|