зеркало из https://github.com/mozilla/pjs.git
*** empty log message ***
This commit is contained in:
Родитель
0f6302fed1
Коммит
cc0efd9e79
|
@ -87,11 +87,11 @@ public:
|
|||
* Find all RDF resources that point to a given node over the
|
||||
* specified arc & truth value (defaults to "PR_TRUE").
|
||||
*/
|
||||
NS_IMETHOD GetSources(RDF_Node target,
|
||||
NS_IMETHOD GetSources(RDF_Resource target,
|
||||
RDF_Resource arcLabel,
|
||||
nsIRDFCursor **sources /* out */) = 0;
|
||||
|
||||
NS_IMETHOD GetSources(RDF_Node target,
|
||||
NS_IMETHOD GetSources(RDF_Resource target,
|
||||
RDF_Resource arcLabel,
|
||||
PRBool tv,
|
||||
nsIRDFCursor **sources /* out */) = 0;
|
||||
|
|
|
@ -57,9 +57,13 @@ public:
|
|||
nsIRDFDataSource **source /* out */) = 0;
|
||||
#endif /* RDF_NOT_IMPLEMENTED */
|
||||
|
||||
NS_IMETHOD CreateDatabase(const RDF_String* url_ary,
|
||||
NS_IMETHOD CreateDatabase(const char** url_ary,
|
||||
nsIRDFDataBase **db /* out */) = 0;
|
||||
|
||||
NS_IMETHOD ResourceIdentifier(RDF_Resource r,
|
||||
char** url /* out */) = 0;
|
||||
|
||||
|
||||
};
|
||||
|
||||
PR_PUBLIC_API(nsresult) NS_GetRDFService(nsIRDFService **);
|
||||
|
|
|
@ -39,7 +39,7 @@ typedef struct RDF_NotificationStruct* RDF_Notification;
|
|||
|
||||
typedef void (*RDF_NotificationProc)(RDF_Event theEvent, void* pdata);
|
||||
|
||||
PR_PUBLIC_API(RDF) RDF_GetDB(const RDF_String* dbs);
|
||||
PR_PUBLIC_API(RDF) RDF_GetDB(const char** dbs);
|
||||
PR_PUBLIC_API(RDF_Error) RDF_ReleaseDB(RDF rdf);
|
||||
PR_PUBLIC_API(RDFT) RDF_AddDataSource(RDF rdf, char* dataSource);
|
||||
PR_PUBLIC_API(RDF_Error) RDF_ReleaseDataSource(RDF rdf, RDFT dataSource);
|
||||
|
@ -47,6 +47,7 @@ PR_PUBLIC_API(RDF_Resource) RDF_GetResource(RDF db, char* id, PRBool createp);
|
|||
PR_PUBLIC_API(RDF_Error) RDF_ReleaseResource(RDF db, RDF_Resource resource);
|
||||
PR_PUBLIC_API(RDF_Error) RDF_DeleteAllArcs(RDF rdfDB, RDF_Resource source);
|
||||
PR_PUBLIC_API(RDF_Error) RDF_Update(RDF rdfDB, RDF_Resource u);
|
||||
PR_PUBLIC_API(char*) RDF_ResourceID(RDF_Resource u);
|
||||
|
||||
PR_PUBLIC_API(RDF_Notification) RDF_AddNotifiable (RDF rdfDB, RDF_NotificationProc callBack, RDF_Event ev, void* pdata);
|
||||
PR_PUBLIC_API(RDF_Error) RDF_DeleteNotifiable (RDF_Notification ns);
|
||||
|
|
|
@ -256,7 +256,7 @@ newFolderBkItem(RDFFile f, char* token)
|
|||
void
|
||||
newLeafBkItem (RDFFile f, char* token)
|
||||
{
|
||||
char buffer[128];
|
||||
/* char buffer[128]; */
|
||||
struct tm *time;
|
||||
uint32 dateVal;
|
||||
char* url = NULL;
|
||||
|
|
|
@ -60,11 +60,11 @@ public:
|
|||
PRBool tv,
|
||||
RDF_Resource *source /* out */);
|
||||
|
||||
NS_METHOD GetSources(RDF_Node target,
|
||||
NS_METHOD GetSources(RDF_Resource target,
|
||||
RDF_Resource arcLabel,
|
||||
nsIRDFCursor **sources /* out */);
|
||||
|
||||
NS_METHOD GetSources(RDF_Node target,
|
||||
NS_METHOD GetSources(RDF_Resource target,
|
||||
RDF_Resource arcLabel,
|
||||
PRBool tv,
|
||||
nsIRDFCursor **sources /* out */);
|
||||
|
@ -160,9 +160,13 @@ public:
|
|||
rdfServiceWrapper();
|
||||
~rdfServiceWrapper();
|
||||
|
||||
NS_METHOD CreateDatabase(const RDF_String* url,
|
||||
NS_METHOD CreateDatabase(const char** url,
|
||||
nsIRDFDataBase** db);
|
||||
|
||||
NS_IMETHOD ResourceIdentifier(RDF_Resource r,
|
||||
char** url /* out */);
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -292,7 +296,7 @@ rdfDatabaseWrapper::GetSource(RDF_Node target,
|
|||
}
|
||||
|
||||
NS_METHOD
|
||||
rdfDatabaseWrapper::GetSources(RDF_Node target,
|
||||
rdfDatabaseWrapper::GetSources(RDF_Resource target,
|
||||
RDF_Resource arcLabel,
|
||||
nsIRDFCursor **sources /* out */)
|
||||
{
|
||||
|
@ -300,7 +304,7 @@ rdfDatabaseWrapper::GetSources(RDF_Node target,
|
|||
}
|
||||
|
||||
NS_METHOD
|
||||
rdfDatabaseWrapper::GetSources(RDF_Node target,
|
||||
rdfDatabaseWrapper::GetSources(RDF_Resource target,
|
||||
RDF_Resource arcLabel,
|
||||
PRBool tv,
|
||||
nsIRDFCursor **sources /* out */)
|
||||
|
@ -312,7 +316,7 @@ rdfDatabaseWrapper::GetSources(RDF_Node target,
|
|||
*sources = 0;
|
||||
|
||||
RDF_Cursor c = RDF_GetSources( mRDF,
|
||||
target->value.r,
|
||||
target,
|
||||
arcLabel,
|
||||
RDF_RESOURCE_TYPE, // anything else makes no sense
|
||||
tv );
|
||||
|
@ -556,7 +560,7 @@ rdfServiceWrapper::~rdfServiceWrapper()
|
|||
}
|
||||
|
||||
NS_METHOD
|
||||
rdfServiceWrapper::CreateDatabase(const RDF_String* url_ary,
|
||||
rdfServiceWrapper::CreateDatabase(const char** url_ary,
|
||||
nsIRDFDataBase **db)
|
||||
{
|
||||
PR_ASSERT( 0 != db );
|
||||
|
@ -577,6 +581,20 @@ rdfServiceWrapper::CreateDatabase(const RDF_String* url_ary,
|
|||
return result;
|
||||
}
|
||||
|
||||
NS_METHOD
|
||||
rdfServiceWrapper::ResourceIdentifier(RDF_Resource r,
|
||||
char** url)
|
||||
{
|
||||
char* resourceID(RDF_Resource r);
|
||||
PR_ASSERT( 0 != r );
|
||||
if( 0 == r )
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*url = RDF_ResourceID(r);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
|
||||
rdfCursorWrapper
|
||||
|
|
1124
rdf/src/core.c
1124
rdf/src/core.c
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -22,7 +22,7 @@
|
|||
#include "nsString.h"
|
||||
#include "rdf-int.h"
|
||||
#include "rdfparse.h"
|
||||
|
||||
#include <stdio.h>
|
||||
class rdfStreamListener : public nsIStreamListener
|
||||
{
|
||||
public:
|
||||
|
@ -152,6 +152,17 @@ rdfStreamListener::OnStopBinding(nsIURL* aURL,
|
|||
void
|
||||
beginReadingRDFFile (RDFFile file)
|
||||
{
|
||||
if (!strchr(file->url, ':') && (endsWith(".rdf", file->url))) {
|
||||
FILE* f = fopen(file->url, "r");
|
||||
char buffer[4096];
|
||||
int n;
|
||||
while (f && ((n = fread(buffer, 1, 4095, f)) > 0)) {
|
||||
buffer[n] = '\0';
|
||||
parseNextRDFXMLBlobInt(file, buffer, n);
|
||||
}
|
||||
fclose(f);
|
||||
return;
|
||||
} else {
|
||||
rdfStreamListener* pListener = new rdfStreamListener(file);
|
||||
pListener->AddRef(); // XXX is this evil? Can't see any reason to use factories but...
|
||||
nsIURL* pURL = NULL;
|
||||
|
@ -165,5 +176,6 @@ beginReadingRDFFile (RDFFile file)
|
|||
if( NS_OK != r ) {
|
||||
// XXX what to do?
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,462 +0,0 @@
|
|||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#ifndef _RDF_RDF_INT_H
|
||||
#define _RDF_RDF_INT_H
|
||||
|
||||
|
||||
#define WINTEST 0
|
||||
#define DBMTEST 1
|
||||
#define FSTEST 1
|
||||
|
||||
|
||||
#define RDF_BUF_SIZE 4096
|
||||
#define LINE_SIZE 512
|
||||
#define RDF_BOOKMARKS 128
|
||||
#define RDF_MCF 129
|
||||
#define RDF_XML 130
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include "rdf.h"
|
||||
#include "nspr.h"
|
||||
#include "plhash.h"
|
||||
|
||||
#include "rdfstr.h"
|
||||
|
||||
|
||||
|
||||
#ifndef true
|
||||
#define true PR_TRUE
|
||||
#endif
|
||||
#ifndef false
|
||||
#define false PR_FALSE
|
||||
#endif
|
||||
#define null NULL
|
||||
#define nullp(x) (((void*)x) == ((void*)0))
|
||||
#define LookupResource(x) ((RDF_Resource)PL_HashTableLookup(resourceHash, x));
|
||||
|
||||
#define noRDFErr 0
|
||||
#define noMoreValuesErr 1
|
||||
|
||||
#define MAX_ATTRIBUTES 64
|
||||
|
||||
#define RDF_RT 0
|
||||
#define LFS_RT 1
|
||||
#define FTP_RT 3
|
||||
#define ES_RT 4
|
||||
#define SEARCH_RT 5
|
||||
#define HISTORY_RT 6
|
||||
#define LDAP_RT 7
|
||||
#define PM_RT 8
|
||||
#define RDM_RT 9
|
||||
#define IM_RT 10
|
||||
#define CACHE_RT 11
|
||||
#define ATALK_RT 12
|
||||
#define ATALKVIRTUAL_RT 13
|
||||
#define COOKIE_RT 14
|
||||
#define JSEC_RT 15
|
||||
#define PMF_RT 16
|
||||
|
||||
#define CHECK_VAR(var, return_value) {if (var == NULL) {/*xxx PR_ASSERT(var); */ return return_value;}}
|
||||
#define CHECK_VAR1(var) {if (var == NULL) {/*xxx PR_ASSERT(var);*/ return;}}
|
||||
|
||||
|
||||
#ifdef XP_WIN
|
||||
#define FS_URL_OFFSET 8
|
||||
#else
|
||||
#define FS_URL_OFFSET 7
|
||||
#endif
|
||||
|
||||
|
||||
#define MAX_URL_SIZE 300
|
||||
|
||||
|
||||
#define convertString2UTF8(charsetid, s) \
|
||||
(s != NULL ? \
|
||||
INTL_ConvertLineWithoutAutoDetect( \
|
||||
(charsetid) , \
|
||||
CS_UTF8, \
|
||||
(unsigned char*)(s), \
|
||||
RDF_STRLEN(s) \
|
||||
) : NULL)
|
||||
|
||||
#define stringEquals(x, y) (strcmp(x, y) ==0)
|
||||
/*#define stringAppend(x, y) XP_AppendStr(x,y) */
|
||||
|
||||
NSPR_BEGIN_EXTERN_C
|
||||
|
||||
struct RDF_ResourceStruct {
|
||||
char* url;
|
||||
uint8 type;
|
||||
uint8 flags;
|
||||
struct RDF_AssertionStruct* rarg1;
|
||||
struct RDF_AssertionStruct* rarg2;
|
||||
struct RDF_ListStruct* rdf;
|
||||
void* pdata;
|
||||
} ;
|
||||
|
||||
#define RDF_GET_SLOT_VALUES_QUERY 0x01
|
||||
#define RDF_GET_SLOT_VALUE_QUERY 0x02
|
||||
#define RDF_FIND_QUERY 0x03
|
||||
#define RDF_ARC_LABELS_IN_QUERY 0x04
|
||||
#define RDF_ARC_LABELS_OUT_QUERY 0x05
|
||||
|
||||
struct RDF_CursorStruct {
|
||||
RDF_Resource u;
|
||||
RDF_Resource s;
|
||||
RDF_Resource match;
|
||||
void *value;
|
||||
struct RDF_CursorStruct* current;
|
||||
RDF rdf;
|
||||
void* pdata;
|
||||
PRBool tv;
|
||||
PRBool inversep;
|
||||
RDF_ValueType type;
|
||||
int16 count;
|
||||
uint16 size;
|
||||
uint8 queryType;
|
||||
};
|
||||
|
||||
typedef uint8 RDF_BT;
|
||||
|
||||
#define getMem(x) PR_Calloc(1,(x))
|
||||
#define freeMem(x) PR_Free((x))
|
||||
|
||||
struct RDF_AssertionStruct {
|
||||
RDF_Resource u;
|
||||
RDF_Resource s;
|
||||
void* value;
|
||||
PRBool tv;
|
||||
RDF_ValueType type;
|
||||
uint8 tags;
|
||||
struct RDF_AssertionStruct* next;
|
||||
struct RDF_AssertionStruct* invNext;
|
||||
struct RDF_TranslatorStruct* db;
|
||||
} ;
|
||||
|
||||
|
||||
typedef struct RDF_AssertionStruct *Assertion;
|
||||
typedef struct RDF_FileStruct *RDFFile;
|
||||
|
||||
|
||||
typedef PRBool (*assertProc)(RDFT r, RDF_Resource u, RDF_Resource s, void* value, RDF_ValueType type, PRBool tv);
|
||||
typedef PRBool (*hasAssertionProc)(RDFT r, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
|
||||
typedef void* (*getSlotValueProc)(RDFT r, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
|
||||
typedef RDF_Cursor (*getSlotValuesProc)(RDFT r, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
|
||||
typedef PRBool (*unassertProc)(RDFT r, RDF_Resource u, RDF_Resource s, void* value, RDF_ValueType type);
|
||||
typedef void* (*nextItemProc)(RDFT r, RDF_Cursor c) ;
|
||||
typedef RDF_Error (*disposeCursorProc)(RDFT r, RDF_Cursor c);
|
||||
typedef RDF_Error (*disposeResourceProc)(RDFT r, RDF_Resource u);
|
||||
typedef RDF_Error (*updateProc)(RDFT r, RDF_Resource u);
|
||||
typedef RDF_Error (*destroyProc)(struct RDF_TranslatorStruct*);
|
||||
typedef RDF_Cursor (*arcLabelsOutProc)(RDFT r, RDF_Resource u);
|
||||
typedef RDF_Cursor (*arcLabelsInProc)(RDFT r, RDF_Resource u);
|
||||
typedef PRBool (*fAssert1Proc) (RDFFile file, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
typedef PRBool (*fUnAssert1Proc) (RDFFile file, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type) ;
|
||||
typedef void (*accessFileProc) (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep) ;
|
||||
|
||||
struct RDF_ListStruct {
|
||||
struct RDF_DBStruct* rdf;
|
||||
struct RDF_ListStruct* next;
|
||||
} ;
|
||||
|
||||
typedef struct RDF_ListStruct *RDFL;
|
||||
|
||||
struct RDF_TranslatorStruct {
|
||||
RDFL rdf;
|
||||
char* url;
|
||||
void* pdata;
|
||||
destroyProc destroy;
|
||||
hasAssertionProc hasAssertion;
|
||||
unassertProc unassert;
|
||||
assertProc assert;
|
||||
getSlotValueProc getSlotValue;
|
||||
getSlotValuesProc getSlotValues;
|
||||
nextItemProc nextValue;
|
||||
disposeCursorProc disposeCursor;
|
||||
disposeResourceProc disposeResource;
|
||||
arcLabelsInProc arcLabelsIn;
|
||||
arcLabelsInProc arcLabelsOut;
|
||||
accessFileProc possiblyAccessFile;
|
||||
updateProc update;
|
||||
RDFL dependents;
|
||||
RDFL dependentOn;
|
||||
};
|
||||
|
||||
|
||||
extern PLHashTable* resourceHash;
|
||||
extern PLHashTable* dataSourceHash;
|
||||
extern char* gNavCntrUrl;
|
||||
struct RDF_DBStruct {
|
||||
int32 numTranslators;
|
||||
int32 translatorArraySize;
|
||||
RDFT* translators;
|
||||
struct RDF_FileStruct* files;
|
||||
struct RDF_NotificationStruct* notifs;
|
||||
void* context;
|
||||
};
|
||||
|
||||
extern RDFT gLocalStore;
|
||||
extern RDFT gRemoteStore;
|
||||
extern RDFT gSessionDB;
|
||||
extern size_t gCoreVocabSize;
|
||||
extern RDF_Resource* gAllVocab;
|
||||
|
||||
/* reading rdf */
|
||||
|
||||
#define HEADERS 1
|
||||
#define BODY 2
|
||||
|
||||
|
||||
struct XMLNameSpaceStruct {
|
||||
char* as;
|
||||
char* url;
|
||||
struct XMLNameSpaceStruct* next;
|
||||
} ;
|
||||
|
||||
typedef struct XMLNameSpaceStruct *XMLNameSpace;
|
||||
|
||||
#define RDF_MAX_NUM_FILE_TOKENS 8
|
||||
|
||||
struct RDF_FileStructTokens {
|
||||
RDF_Resource token;
|
||||
RDF_ValueType type;
|
||||
int16 tokenNum;
|
||||
char *data;
|
||||
};
|
||||
|
||||
struct RDF_FileStruct {
|
||||
char* url;
|
||||
|
||||
RDF_Resource currentResource;
|
||||
RDF_Resource top;
|
||||
RDF_Resource rtop;
|
||||
char* currentSlot;
|
||||
PRBool genlAdded;
|
||||
PRBool localp;
|
||||
char* storeAway;
|
||||
char* line;
|
||||
XMLNameSpace namespaces;
|
||||
uint16 status;
|
||||
char* holdOver;
|
||||
int32 lineSize;
|
||||
RDF_Resource stack[16];
|
||||
uint16 depth ;
|
||||
|
||||
|
||||
uint16 resourceCount;
|
||||
uint16 resourceListSize;
|
||||
uint16 assertionCount;
|
||||
uint16 assertionListSize;
|
||||
RDF_Resource* resourceList;
|
||||
Assertion* assertionList;
|
||||
char* updateURL;
|
||||
char* postURL;
|
||||
|
||||
PRTime lastReadTime;
|
||||
PRTime *expiryTime;
|
||||
uint8 fileType;
|
||||
PRBool locked;
|
||||
RDF_Resource lastItem;
|
||||
|
||||
|
||||
PRBool tv;
|
||||
fAssert1Proc assert;
|
||||
fUnAssert1Proc unassert;
|
||||
RDFT db;
|
||||
PRBool refreshingp;
|
||||
|
||||
void* pdata;
|
||||
|
||||
int16 numFileTokens;
|
||||
struct RDF_FileStructTokens tokens[RDF_MAX_NUM_FILE_TOKENS];
|
||||
struct RDF_FileStruct* next;
|
||||
};
|
||||
|
||||
RDF newNavCenterDB();
|
||||
void walkThroughAllBookmarks (RDF_Resource u);
|
||||
RDFT NewRemoteStore (char* url);
|
||||
RDF_Resource nextFindValue (RDF_Cursor c) ;
|
||||
PRBool isTypeOf (RDF rdf, RDF_Resource u, RDF_Resource v);
|
||||
RDF getRDFDB (void);
|
||||
RDFFile readRDFFile (char* url, RDF_Resource top, PRBool localp, RDFT rdf);
|
||||
void sendNotifications (RDF rdf, RDF_EventType opType, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv, char* ds);
|
||||
void sendNotifications2 (RDFT rdf, RDF_EventType opType, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
RDF_Error exitRDF (RDF rdf);
|
||||
void gcRDFFileInt (RDFFile f);
|
||||
void parseNextBkBlob(RDFFile f, char* blob, int32 blobSize);
|
||||
void printAssertion(Assertion as);
|
||||
RDF_Error addChildAfter (RDFT rdf, RDF_Resource parent, RDF_Resource child, RDF_Resource afterWhat);
|
||||
RDF_Error addChildBefore (RDFT rdf, RDF_Resource parent, RDF_Resource child, RDF_Resource beforeWhat);
|
||||
void nlclStoreKill(RDFT rdf, RDF_Resource r);
|
||||
char* resourceID(RDF_Resource id);
|
||||
PRBool containerp (RDF_Resource r);
|
||||
void setContainerp (RDF_Resource r, PRBool contp);
|
||||
PRBool lockedp (RDF_Resource r);
|
||||
void setLockedp (RDF_Resource r, PRBool contp);
|
||||
uint8 resourceType (RDF_Resource r);
|
||||
void setResourceType (RDF_Resource r, uint8 type);
|
||||
char* getBaseURL (const char* url) ;
|
||||
void freeNamespaces (RDFFile f) ;
|
||||
PRBool asEqual(RDFT r, Assertion as, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
|
||||
Assertion makeNewAssertion (RDFT r, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
|
||||
|
||||
RDFT MakeRemoteStore (char* url);
|
||||
RDFT MakeMailAccountDB(char* url);
|
||||
PRDir * OpenDir(char *name);
|
||||
void PopGetNewMail (RDF_Resource r) ;
|
||||
void readResourceFile(RDF rdf, RDF_Resource u);
|
||||
void possiblyGCResource(RDF_Resource u);
|
||||
PLHashNumber idenHash(const void* key);
|
||||
|
||||
RDFT MakeBMKStore (char* url);
|
||||
RDFT MakeLocalStore (char* url);
|
||||
RDFT MakeFileDB (char* url);
|
||||
RDFT MakeSCookDB (char* url);
|
||||
char * makeRDFDBURL(char* directory, char* name);
|
||||
void addToResourceList (RDFFile f, RDF_Resource u);
|
||||
void removeFromAssertionList(RDFFile f, Assertion as);
|
||||
|
||||
|
||||
|
||||
|
||||
/* string utilities */
|
||||
|
||||
int16 charSearch(const char c,const char* string);
|
||||
int16 revCharSearch(const char c, const char* string);
|
||||
PR_PUBLIC_API(PRBool) startsWith(const char* startPattern,const char* string);
|
||||
PRBool endsWith(const char* endPattern,const char* string);
|
||||
PRBool inverseTV(PRBool tv);
|
||||
void createBootstrapResources();
|
||||
PRBool urlEquals(const char* url1,const char* url2);
|
||||
char* append2Strings(const char* str1,const char* str2);
|
||||
char* convertString2UTF8AndAppend(int16 charsetID, const char* str1,const char* str2);
|
||||
PRBool substring(const char* pattern, const char* data);
|
||||
void stringAppend(char* in, const char* append);
|
||||
|
||||
RDFFile makeRDFFile (char* url, RDF_Resource top, PRBool localp);
|
||||
void initRDFFile (RDFFile ans) ;
|
||||
void parseNextRDFLine (RDFFile f, char* line) ;
|
||||
void parseNextRDFBlob (RDFFile f, char* blob, int32 size);
|
||||
void finishRDFParse (RDFFile f) ;
|
||||
void abortRDFParse (RDFFile f);
|
||||
void unitTransition (RDFFile f) ;
|
||||
void assignHeaderSlot (RDFFile f, char* slot, char* value);
|
||||
RDF_Error getFirstToken (char* line, char* nextToken, int16* l) ;
|
||||
void addSlotValue (RDFFile f, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, char* op);
|
||||
void assignSlot (RDF_Resource u, char* slot, char* value, RDFFile f);
|
||||
RDF_Error parseSlotValue (RDFFile f, RDF_Resource s, char* value, void** parsed_value, RDF_ValueType* data_type) ;
|
||||
RDF_Resource resolveReference (char *tok, RDFFile f) ;
|
||||
RDF_Resource resolveGenlPosReference(char* tok, RDFFile f);
|
||||
RDF_Resource resolveReference (char *tok, RDFFile f) ;
|
||||
RDF_Resource resolveGenlPosReference(char* tok, RDFFile f);
|
||||
void beginReadingRDFFile(RDFFile f);
|
||||
void gcRDFFile (RDFFile f);
|
||||
#ifdef XP_MAC
|
||||
char* unescapeURL(char* inURL);
|
||||
#endif
|
||||
char* convertFileURLToNSPRCopaceticPath(char* inURL);
|
||||
PRFileDesc* CallPROpenUsingFileURL(char *fileURL, PRIntn flags, PRIntn mode);
|
||||
/* DB *CallDBOpenUsingFileURL(char *fileURL, int flags,int mode, DBTYPE type, const void *openinfo); */
|
||||
|
||||
char* copyString (const char* url);
|
||||
PRBool nlocalStoreAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv) ;
|
||||
char* MCDepFileURL (char* url) ;
|
||||
void initLocalStore(RDFT rdf);
|
||||
void freeAssertion(Assertion as);
|
||||
Assertion localStoreAdd (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
Assertion localStoreRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type) ;
|
||||
|
||||
Assertion remoteStoreAdd (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
Assertion remoteStoreRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type) ;
|
||||
void* remoteStoreGetSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
|
||||
void ht_fprintf(PRFileDesc *file, const char *fmt, ...);
|
||||
|
||||
RDF_Resource createContainer (char* id);
|
||||
PRBool isContainer (RDF_Resource r) ;
|
||||
PRBool isSeparator (RDF_Resource r) ;
|
||||
PRBool isLeaf (RDF_Resource r) ;
|
||||
PRBool bookmarkSlotp (RDF_Resource s) ;
|
||||
|
||||
void basicAssertions (void) ;
|
||||
char* makeResourceName (RDF_Resource node) ;
|
||||
char* makeDBURL (char* name);
|
||||
|
||||
/* int rdf_GetURL (MWContext *cx, int method, Net_GetUrlExitFunc *exit_routine, RDFFile rdfFile); */
|
||||
|
||||
RDFT MakePopDB (char* url) ;
|
||||
PRBool nlocalStoreAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv) ;
|
||||
PRBool nlocalStoreUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type) ;
|
||||
PRBool nlocalStoreHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
void* nlocalStoreGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
|
||||
RDF_Cursor nlocalStoreGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
|
||||
void* nlocalStoreNextValue (RDFT mcf, RDF_Cursor c) ;
|
||||
RDF_Error nlocalStoreDisposeCursor (RDFT mcf, RDF_Cursor c) ;
|
||||
void createCoreVocab () ;
|
||||
|
||||
|
||||
PRBool remoteAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv) ;
|
||||
PRBool remoteUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type) ;
|
||||
PRBool remoteAssert1 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv) ;
|
||||
PRBool remoteAssert2 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv) ;
|
||||
PRBool remoteUnassert1 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type) ;
|
||||
PRBool remoteStoreHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
void* remoteStoreGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
|
||||
RDF_Cursor remoteStoreGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
|
||||
RDF_Cursor remoteStoreGetSlotValuesInt (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv) ;
|
||||
RDF_Resource createSeparator(void);
|
||||
PRBool
|
||||
remoteAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
|
||||
|
||||
void* remoteStoreNextValue (RDFT mcf, RDF_Cursor c) ;
|
||||
RDF_Error remoteStoreDisposeCursor (RDFT mcf, RDF_Cursor c) ;
|
||||
PRBool remoteStoreHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
PRBool remoteStoreHasAssertionInt (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
|
||||
PRBool nlocalStoreAddChildAt(RDFT mcf, RDF_Resource obj, RDF_Resource ref, RDF_Resource _new,
|
||||
PRBool beforep);
|
||||
RDFT getTranslator (char* url);
|
||||
|
||||
RDFT MakeCookieStore (char* url);
|
||||
|
||||
char* advertURLOfContainer (RDF r, RDF_Resource u) ;
|
||||
RDFT RDFTNamed (RDF rdf, char* name) ;
|
||||
|
||||
char* RDF_SerializeRDFStore (RDFT store) ;
|
||||
char * unescapeURL(char *inURL);
|
||||
|
||||
|
||||
|
||||
|
||||
extern RDF_WDVocab gWebData;
|
||||
extern RDF_NCVocab gNavCenter;
|
||||
extern RDF_CoreVocab gCoreVocab;
|
||||
|
||||
NSPR_END_EXTERN_C
|
||||
|
||||
#endif
|
|
@ -1,833 +0,0 @@
|
|||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
This file implements remote store support for the rdf data model.
|
||||
For more information on this file, contact rjc or guha
|
||||
For more information on RDF, look at the RDF section of www.mozilla.org
|
||||
*/
|
||||
|
||||
#include "remstore.h"
|
||||
|
||||
|
||||
/* globals */
|
||||
|
||||
extern char *profileDirURL;
|
||||
extern char *gBookmarkURL;
|
||||
RDFT gLocalStore = 0;
|
||||
|
||||
RDFT
|
||||
MakeRemoteStore (char* url)
|
||||
{
|
||||
if (startsWith("rdf:remoteStore", url)) {
|
||||
if (gRemoteStore == 0) {
|
||||
gRemoteStore = NewRemoteStore(url);
|
||||
return gRemoteStore;
|
||||
} else return gRemoteStore;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDFT
|
||||
MakeFileDB (char* url)
|
||||
{
|
||||
if (RDF_STRCHR(url, ':')) {
|
||||
RDFT ntr = NewRemoteStore(url);
|
||||
ntr->possiblyAccessFile = RDFFilePossiblyAccessFile ;
|
||||
if (RDF_STRCMP(gNavCntrUrl, url) == 0)
|
||||
readRDFFile(url, RDF_GetResource(NULL, url, 1), 0, ntr);
|
||||
return ntr;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
asEqual(RDFT r, Assertion as, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type)
|
||||
{
|
||||
return ((as->db == r) && (as->u == u) && (as->s == s) && (as->type == type) &&
|
||||
((as->value == v) ||
|
||||
((type == RDF_STRING_TYPE) && ((RDF_STRCMP(v, as->value) == 0) || (((char *)v)[0] =='\0')))));
|
||||
}
|
||||
|
||||
|
||||
|
||||
Assertion
|
||||
makeNewAssertion (RDFT r, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv)
|
||||
{
|
||||
Assertion newAs = (Assertion) getMem(sizeof(struct RDF_AssertionStruct));
|
||||
newAs->u = u;
|
||||
newAs->s = s;
|
||||
newAs->value = v;
|
||||
newAs->type = type;
|
||||
newAs->tv = tv;
|
||||
newAs->db = r;
|
||||
if (RDF_STRCMP(r->url, "rdf:history")) {
|
||||
int n = 0;
|
||||
}
|
||||
return newAs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
freeAssertion (Assertion as)
|
||||
{
|
||||
if (as->type == RDF_STRING_TYPE) {
|
||||
freeMem(as->value);
|
||||
}
|
||||
freeMem(as);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
remoteAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv)
|
||||
{
|
||||
return (remoteStoreAdd(mcf, u, s, v, type, tv) != NULL);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
remoteUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type)
|
||||
{
|
||||
return (remoteStoreRemove(mcf, u, s, v, type) != NULL);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
remoteAssert3 (RDFFile fi, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv)
|
||||
{
|
||||
Assertion as = remoteStoreAdd(mcf, u, s, v, type, tv);
|
||||
if (as != NULL) {
|
||||
addToAssertionList(fi, as);
|
||||
return 1;
|
||||
} else return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
remoteUnassert3 (RDFFile fi, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type)
|
||||
{
|
||||
Assertion as = remoteStoreRemove(mcf, u, s, v, type);
|
||||
if (as != NULL) {
|
||||
removeFromAssertionList(fi, as);
|
||||
return 1;
|
||||
} else return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
remoteStoreflushChildren(RDFT mcf, RDF_Resource parent)
|
||||
{
|
||||
RDF_Cursor c;
|
||||
RDF_Resource child;
|
||||
#if 0
|
||||
RDF_Cursor cc;
|
||||
RDF_Resource s;
|
||||
char *value;
|
||||
#endif
|
||||
|
||||
if (parent == NULL) return;
|
||||
if ((c = remoteStoreGetSlotValues (mcf, parent, gCoreVocab->RDF_parent,
|
||||
RDF_RESOURCE_TYPE, true, true)) != NULL)
|
||||
{
|
||||
while((child = remoteStoreNextValue (mcf, c)) != NULL)
|
||||
{
|
||||
remoteStoreflushChildren(mcf, child);
|
||||
|
||||
/* XXX should we remove all arcs coming off of this node? */
|
||||
#if 0
|
||||
if ((cc = remoteStoreArcLabelsOut(mcf, child)) != NULL)
|
||||
{
|
||||
if ((s = remoteStoreNextValue (mcf, cc)) != NULL)
|
||||
{
|
||||
if (s == gCoreVocab->RDF_name)
|
||||
{
|
||||
value = remoteStoreGetSlotValue (mcf, child, s,
|
||||
RDF_STRING_TYPE, PR_FALSE, PR_TRUE);
|
||||
if (value != NULL)
|
||||
{
|
||||
remoteStoreRemove (mcf, child, s,
|
||||
value, RDF_STRING_TYPE);
|
||||
}
|
||||
}
|
||||
}
|
||||
remoteStoreDisposeCursor(mcf, cc);
|
||||
}
|
||||
#endif
|
||||
remoteStoreRemove (mcf, child, gCoreVocab->RDF_parent,
|
||||
parent, RDF_RESOURCE_TYPE);
|
||||
}
|
||||
remoteStoreDisposeCursor (mcf, c);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Assertion
|
||||
remoteStoreAdd (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
|
||||
RDF_ValueType type, PRBool tv)
|
||||
{
|
||||
Assertion nextAs, prevAs, newAs;
|
||||
nextAs = prevAs = u->rarg1;
|
||||
|
||||
if (s == gNavCenter->RDF_Command)
|
||||
{
|
||||
if ((type == RDF_RESOURCE_TYPE) && (tv) && (v == gNavCenter->RDF_Command_Refresh))
|
||||
{
|
||||
/* flush any children of 'u' */
|
||||
remoteStoreflushChildren(mcf, u);
|
||||
}
|
||||
/* don't store RDF Commands in the remote store */
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
while (nextAs != null) {
|
||||
if (asEqual(mcf, nextAs, u, s, v, type)) return null;
|
||||
prevAs = nextAs;
|
||||
nextAs = nextAs->next;
|
||||
}
|
||||
newAs = makeNewAssertion(mcf, u, s, v, type, tv);
|
||||
if (prevAs == null) {
|
||||
u->rarg1 = newAs;
|
||||
} else {
|
||||
prevAs->next = newAs;
|
||||
}
|
||||
if (type == RDF_RESOURCE_TYPE) {
|
||||
nextAs = prevAs = ((RDF_Resource)v)->rarg2;
|
||||
while (nextAs != null) {
|
||||
prevAs = nextAs;
|
||||
nextAs = nextAs->invNext;
|
||||
}
|
||||
if (prevAs == null) {
|
||||
((RDF_Resource)v)->rarg2 = newAs;
|
||||
} else {
|
||||
prevAs->invNext = newAs;
|
||||
}
|
||||
}
|
||||
sendNotifications2(mcf, RDF_ASSERT_NOTIFY, u, s, v, type, tv);
|
||||
return newAs;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Assertion
|
||||
remoteStoreRemove (RDFT mcf, RDF_Resource u, RDF_Resource s,
|
||||
void* v, RDF_ValueType type)
|
||||
{
|
||||
Assertion nextAs, prevAs, ans;
|
||||
PRBool 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;
|
||||
}
|
||||
}
|
||||
sendNotifications2(mcf, RDF_DELETE_NOTIFY, u, s, v, type, ans->tv);
|
||||
return ans;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PRBool
|
||||
fileReadp (RDFT rdf, char* url, PRBool mark)
|
||||
{
|
||||
RDFFile f;
|
||||
RDFFile rdfFiles = (RDFFile) rdf->pdata;
|
||||
uint n = 0;
|
||||
for (f = rdfFiles; (f != NULL) ; f = f->next) {
|
||||
if (urlEquals(url, f->url)) {
|
||||
if (mark == true) f->lastReadTime = PR_Now();
|
||||
return false; /* true; */
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
possiblyAccessFile (RDFT mcf, RDF_Resource u, RDF_Resource s, PRBool inversep)
|
||||
{
|
||||
if (mcf->possiblyAccessFile)
|
||||
(*(mcf->possiblyAccessFile))(mcf, u, s, inversep);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
RDFFilePossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep)
|
||||
{
|
||||
if ((resourceType(u) == RDF_RT) &&
|
||||
(startsWith(rdf->url, resourceID(u))) &&
|
||||
|
||||
(s == gCoreVocab->RDF_parent) && (containerp(u))) {
|
||||
readRDFFile( resourceID(u), u, false, rdf);
|
||||
/* if(newFile) newFile->lastReadTime = PR_Now(); */
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
remoteStoreHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv)
|
||||
{
|
||||
Assertion nextAs;
|
||||
if ((s == gNavCenter->RDF_Command) && (type == RDF_RESOURCE_TYPE) && (tv) && (v == gNavCenter->RDF_Command_Refresh))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
nextAs = u->rarg1;
|
||||
while (nextAs != null) {
|
||||
if (asEqual(mcf, nextAs, u, s, v, type) && (nextAs->tv == tv)) return true;
|
||||
nextAs = nextAs->next;
|
||||
}
|
||||
possiblyAccessFile(mcf, u, s, 0);
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *
|
||||
remoteStoreGetSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv)
|
||||
{
|
||||
Assertion nextAs;
|
||||
|
||||
if ((s == gWebData->RDF_URL) && (tv) && (!inversep) && (type == RDF_STRING_TYPE))
|
||||
{
|
||||
return copyString(resourceID(u));
|
||||
}
|
||||
|
||||
nextAs = (inversep ? u->rarg2 : u->rarg1);
|
||||
while (nextAs != null) {
|
||||
if ((nextAs->db == mcf) && (nextAs->s == s) && (nextAs->tv == tv) && (nextAs->type == type)) {
|
||||
void* ans = (inversep ? nextAs->u : nextAs->value);
|
||||
if (type == RDF_STRING_TYPE) {
|
||||
return copyString((char*)ans);
|
||||
} else return ans;
|
||||
}
|
||||
nextAs = (inversep ? nextAs->invNext : nextAs->next);
|
||||
}
|
||||
if (s == gCoreVocab->RDF_parent) possiblyAccessFile(mcf, u, s, inversep);
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDF_Cursor
|
||||
remoteStoreGetSlotValuesInt (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv)
|
||||
{
|
||||
Assertion as = (inversep ? u->rarg2 : u->rarg1);
|
||||
RDF_Cursor c;
|
||||
if (as == null) {
|
||||
possiblyAccessFile(mcf, u, s, inversep);
|
||||
as = (inversep ? u->rarg2 : u->rarg1);
|
||||
if (as == NULL) return null;
|
||||
}
|
||||
c = (RDF_Cursor)getMem(sizeof(struct RDF_CursorStruct));
|
||||
c->u = u;
|
||||
c->s = s;
|
||||
c->type = type;
|
||||
c->inversep = inversep;
|
||||
c->tv = tv;
|
||||
c->count = 0;
|
||||
c->pdata = as;
|
||||
return c;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDF_Cursor
|
||||
remoteStoreGetSlotValues (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv)
|
||||
{
|
||||
|
||||
return remoteStoreGetSlotValuesInt(mcf, u, s, type, inversep, tv);
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDF_Cursor
|
||||
remoteStoreArcLabelsIn (RDFT mcf, RDF_Resource u)
|
||||
{
|
||||
if (u->rarg2) {
|
||||
RDF_Cursor c = (RDF_Cursor)getMem(sizeof(struct RDF_CursorStruct));
|
||||
c->u = u;
|
||||
c->queryType = RDF_ARC_LABELS_IN_QUERY;
|
||||
c->pdata = u->rarg2;
|
||||
return c;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDF_Cursor
|
||||
remoteStoreArcLabelsOut (RDFT mcf, RDF_Resource u)
|
||||
{
|
||||
if (u->rarg1) {
|
||||
RDF_Cursor c = (RDF_Cursor)getMem(sizeof(struct RDF_CursorStruct));
|
||||
c->u = u;
|
||||
c->queryType = RDF_ARC_LABELS_OUT_QUERY;
|
||||
c->pdata = u->rarg1;
|
||||
return c;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *
|
||||
arcLabelsOutNextValue (RDFT mcf, RDF_Cursor c)
|
||||
{
|
||||
while (c->pdata != null) {
|
||||
Assertion as = (Assertion) c->pdata;
|
||||
if ((as->db == mcf) && (as->u == c->u)) {
|
||||
c->value = as->s;
|
||||
c->pdata = as->next;
|
||||
return c->value;
|
||||
}
|
||||
c->pdata = as->next;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *
|
||||
arcLabelsInNextValue (RDFT mcf, RDF_Cursor c)
|
||||
{
|
||||
while (c->pdata != null) {
|
||||
Assertion as = (Assertion) c->pdata;
|
||||
if ((as->db == mcf) && (as->value == c->u)) {
|
||||
c->value = as->s;
|
||||
c->pdata = as->invNext;
|
||||
return c->value;
|
||||
}
|
||||
c->pdata = as->invNext;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void *
|
||||
remoteStoreNextValue (RDFT mcf, RDF_Cursor c)
|
||||
{
|
||||
if (c->queryType == RDF_ARC_LABELS_OUT_QUERY) {
|
||||
return arcLabelsOutNextValue(mcf, c);
|
||||
} else if (c->queryType == RDF_ARC_LABELS_IN_QUERY) {
|
||||
return arcLabelsInNextValue(mcf, c);
|
||||
} else {
|
||||
while (c->pdata != null) {
|
||||
Assertion as = (Assertion) c->pdata;
|
||||
if ((as->db == mcf) && (as->s == c->s) && (as->tv == c->tv) && (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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDF_Error
|
||||
remoteStoreDisposeCursor (RDFT mcf, RDF_Cursor c)
|
||||
{
|
||||
freeMem(c);
|
||||
return noRDFErr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static RDFFile
|
||||
leastRecentlyUsedRDFFile (RDF mcf)
|
||||
{
|
||||
RDFFile lru = mcf->files;
|
||||
RDFFile f;
|
||||
#ifndef HAVE_LONG_LONG
|
||||
int64 result;
|
||||
#endif /* !HAVE_LONG_LONG */
|
||||
for (f = mcf->files ; (f != NULL) ; f = f->next) {
|
||||
if (!f->locked) {
|
||||
#ifndef HAVE_LONG_LONG
|
||||
LL_SUB(result, lru->lastReadTime, f->lastReadTime);
|
||||
if ((!LL_IS_ZERO(result) && LL_GE_ZERO(result)) && (f->localp == false))
|
||||
#else
|
||||
if (((lru->lastReadTime - f->lastReadTime) > 0) && (f->localp == false))
|
||||
#endif /* !HAVE_LONG_LONG */
|
||||
lru = f;
|
||||
}
|
||||
}
|
||||
if (!lru->locked) {
|
||||
return lru;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
gcRDFFileInt (RDFFile f)
|
||||
{
|
||||
int32 n = 0;
|
||||
while (n < f->assertionCount) {
|
||||
Assertion as = *(f->assertionList + n);
|
||||
remoteStoreRemove(f->db, as->u, as->s, as->value, as->type);
|
||||
freeAssertion(as);
|
||||
*(f->assertionList + n) = NULL;
|
||||
n++;
|
||||
}
|
||||
n = 0;
|
||||
while (n < f->resourceCount) {
|
||||
*(f->resourceList + n) = NULL;
|
||||
n++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDF_Error
|
||||
DeleteRemStore (RDFT db)
|
||||
{
|
||||
RDFFile f = (RDFFile) db->pdata;
|
||||
RDFFile next;
|
||||
while (f) {
|
||||
next = f->next;
|
||||
gcRDFFileInt(f);
|
||||
freeMem(f->assertionList);
|
||||
freeMem(f->resourceList);
|
||||
f = next;
|
||||
}
|
||||
freeMem(db);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDF_Error
|
||||
remStoreUpdate (RDFT db, RDF_Resource u)
|
||||
{
|
||||
RDFFile f = db->pdata;
|
||||
if (f != NULL) {
|
||||
int32 n = 0;
|
||||
PRBool proceedp = 0;
|
||||
while (n < f->resourceCount) {
|
||||
if (*(f->resourceList + n++) == u) {
|
||||
proceedp = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (proceedp) {
|
||||
RDF_Resource top = f->top;
|
||||
char* url = db->url;
|
||||
PRBool localp = f->localp;
|
||||
gcRDFFileInt(f);
|
||||
freeMem(f->assertionList);
|
||||
freeMem(f->resourceList);
|
||||
f->assertionList = NULL;
|
||||
f->resourceList = NULL;
|
||||
initRDFFile(f);
|
||||
f->refreshingp = 1;
|
||||
beginReadingRDFFile(f);
|
||||
return 0;
|
||||
} else return -1;
|
||||
} else return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
gcRDFFile (RDFFile f)
|
||||
{
|
||||
RDFFile f1 = (RDFFile) f->db->pdata;
|
||||
|
||||
if (f->locked) return;
|
||||
|
||||
if (f == f1) {
|
||||
f->db->pdata = f->next;
|
||||
} else {
|
||||
RDFFile prev = f1;
|
||||
while (f1 != NULL) {
|
||||
if (f1 == f) {
|
||||
prev->next = f->next;
|
||||
break;
|
||||
}
|
||||
prev = f1;
|
||||
f1 = f1->next;
|
||||
}
|
||||
}
|
||||
gcRDFFileInt(f);
|
||||
freeMem(f->assertionList);
|
||||
freeMem(f->resourceList);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PRBool
|
||||
freeSomeRDFSpace (RDF mcf)
|
||||
{
|
||||
RDFFile lru = leastRecentlyUsedRDFFile (mcf);
|
||||
if (lru== NULL) {
|
||||
return false;
|
||||
} else {
|
||||
gcRDFFile(lru);
|
||||
freeMem(lru);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDFFile
|
||||
readRDFFile (char* url, RDF_Resource top, PRBool localp, RDFT db)
|
||||
{
|
||||
RDFFile f = makeNewRDFFile(url, top, localp, db);
|
||||
if (!f) return NULL;
|
||||
beginReadingRDFFile(f);
|
||||
return f;
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDFFile
|
||||
makeNewRDFFile (char* url, RDF_Resource top, PRBool localp, RDFT db)
|
||||
{
|
||||
if ((!strstr(url, ":/")) ||
|
||||
(fileReadp(db, url, true))) {
|
||||
return NULL;
|
||||
} else {
|
||||
RDFFile newFile = makeRDFFile(url, top, localp);
|
||||
if (db->pdata) {
|
||||
newFile->next = (RDFFile) db->pdata;
|
||||
db->pdata = newFile;
|
||||
} else {
|
||||
db->pdata = (RDFFile) newFile;
|
||||
}
|
||||
newFile->assert = remoteAssert3;
|
||||
newFile->unassert = remoteUnassert3;
|
||||
if (top) {
|
||||
if (resourceType(top) == RDF_RT) {
|
||||
if (strstr(url, ".mcf")) {
|
||||
newFile->fileType = RDF_MCF;
|
||||
} else {
|
||||
newFile->fileType = RDF_XML;
|
||||
}
|
||||
} else {
|
||||
newFile->fileType = resourceType(top);
|
||||
}
|
||||
}
|
||||
newFile->db = db;
|
||||
return newFile;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
possiblyRefreshRDFFiles ()
|
||||
{
|
||||
RDFFile f = (RDFFile)gRemoteStore->pdata;
|
||||
PRTime tm = PR_Now();
|
||||
while (f != NULL) {
|
||||
if (f->expiryTime != NULL) {
|
||||
PRTime *expiry = f->expiryTime;
|
||||
#ifdef HAVE_LONG_LONG
|
||||
if ((tm - *expiry) > 0)
|
||||
#else
|
||||
int64 result;
|
||||
LL_SUB(result, tm, *expiry);
|
||||
if ((!LL_IS_ZERO(result) && LL_GE_ZERO(result)))
|
||||
#endif
|
||||
{
|
||||
gcRDFFile (f);
|
||||
initRDFFile(f);
|
||||
beginReadingRDFFile(f);
|
||||
}
|
||||
}
|
||||
f = f->next;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
SCookPossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep)
|
||||
{
|
||||
/*if ((resourceType(u) == RDF_RT) && (startsWith("rdf:ht", rdf->url)) &&
|
||||
(s == gCoreVocab->RDF_parent) &&
|
||||
(containerp(u))) {
|
||||
RDFFile newFile = readRDFFile( resourceID(u), u, false, rdf);
|
||||
if(newFile) newFile->lastReadTime = PR_Now();
|
||||
} */
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDFT
|
||||
NewRemoteStore (char* url)
|
||||
{
|
||||
RDFT ntr;
|
||||
|
||||
if ((ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct))) != NULL)
|
||||
{
|
||||
ntr->getSlotValue = remoteStoreGetSlotValue;
|
||||
ntr->getSlotValues = remoteStoreGetSlotValues;
|
||||
ntr->hasAssertion = remoteStoreHasAssertion;
|
||||
ntr->nextValue = remoteStoreNextValue;
|
||||
ntr->disposeCursor = remoteStoreDisposeCursor;
|
||||
ntr->url = copyString(url);
|
||||
ntr->destroy = DeleteRemStore;
|
||||
ntr->arcLabelsIn = remoteStoreArcLabelsIn;
|
||||
ntr->arcLabelsOut = remoteStoreArcLabelsOut;
|
||||
ntr->update = remStoreUpdate;
|
||||
}
|
||||
return(ntr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
RDFT
|
||||
MakeSCookDB (char* url)
|
||||
{
|
||||
if (startsWith("rdf:scook:", url) || (startsWith("rdf:ht", url))) {
|
||||
RDFT ntr = NewRemoteStore(url);
|
||||
ntr->possiblyAccessFile = SCookPossiblyAccessFile;
|
||||
return ntr;
|
||||
} else return NULL;
|
||||
}
|
||||
|
||||
|
||||
RDFT
|
||||
MakeLocalStore (char* url)
|
||||
{
|
||||
char* file = makeRDFDBURL(profileDirURL, "localStore.rdf");
|
||||
RDFT ntr = NewRemoteStore(file);
|
||||
gLocalStore = ntr;
|
||||
ntr->assert = remoteAssert;
|
||||
ntr->unassert = remoteUnassert;
|
||||
return ntr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void
|
||||
addToRDFTOut (RDFTOut out)
|
||||
{
|
||||
int32 len = RDF_STRLEN(out->temp);
|
||||
if (len + out->bufferPos < out->bufferSize) {
|
||||
RDF_STRCAT(out->buffer, out->temp);
|
||||
out->bufferPos = out->bufferPos + len;
|
||||
memset(out->temp, '\0', 1000);
|
||||
} else {
|
||||
PR_Realloc(out->buffer, out->bufferSize + 20000);
|
||||
out->bufferSize = out->bufferSize + 20000;
|
||||
addToRDFTOut (out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRIntn
|
||||
RDFSerializerEnumerator (PLHashEntry *he, PRIntn i, void *arg)
|
||||
{
|
||||
RDF_Resource u = (RDF_Resource)he->value;
|
||||
RDFTOut out = (RDFTOut) arg;
|
||||
Assertion as = u->rarg1;
|
||||
PRBool somethingOutp = 0;
|
||||
while (as) {
|
||||
if (as->db == out->store) {
|
||||
if (!somethingOutp) {
|
||||
somethingOutp = 1;
|
||||
sprintf(out->temp, "<RDF:Description href=\"%s\">\n", resourceID(as->u));
|
||||
addToRDFTOut(out);
|
||||
}
|
||||
if (as->type == RDF_RESOURCE_TYPE) {
|
||||
sprintf(out->temp, " <%s href=\"%s\"/>\n", resourceID(as->s),
|
||||
resourceID((RDF_Resource)as->value));
|
||||
} else if (as->type == RDF_INT_TYPE) {
|
||||
sprintf(out->temp, " <%s dt=\"int\">%i</%s>\n", resourceID(as->s),
|
||||
(int)as->value, resourceID(as->s));
|
||||
} else {
|
||||
sprintf(out->temp, " <%s>%s</%s>\n", resourceID(as->s),
|
||||
(char*)as->value, resourceID(as->s));
|
||||
}
|
||||
addToRDFTOut(out);
|
||||
}
|
||||
as = as->next;
|
||||
}
|
||||
if (somethingOutp) {
|
||||
sprintf(out->temp, "</RDF:Description>\n\n");
|
||||
addToRDFTOut(out);
|
||||
}
|
||||
return HT_ENUMERATE_NEXT;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
RDF_SerializeRDFStore (RDFT store) {
|
||||
RDFTOut out = getMem(sizeof(struct RDFTOutStruct));
|
||||
char* ans = out->buffer = getMem(20000);
|
||||
out->bufferSize = 20000;
|
||||
out->temp = getMem(1000);
|
||||
out->store = store;
|
||||
sprintf(out->temp, "<RDF:RDF>\n\n");
|
||||
addToRDFTOut(out);
|
||||
PL_HashTableEnumerateEntries(resourceHash, RDFSerializerEnumerator, out);
|
||||
sprintf(out->temp, "</RDF:RDF>\n\n");
|
||||
addToRDFTOut(out);
|
||||
freeMem(out->temp);
|
||||
freeMem(out);
|
||||
return ans;
|
||||
}
|
||||
|
|
@ -429,7 +429,10 @@ resourceType (RDF_Resource r)
|
|||
return r->type;
|
||||
}
|
||||
|
||||
|
||||
PR_PUBLIC_API(char*)
|
||||
RDF_ResourceID(RDF_Resource u) {
|
||||
return u->url;
|
||||
}
|
||||
|
||||
void
|
||||
setResourceType (RDF_Resource r, uint8 val)
|
||||
|
|
|
@ -17,17 +17,39 @@
|
|||
*/
|
||||
|
||||
#include "rdf.h"
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsINetService.h"
|
||||
#include "plstr.h"
|
||||
#include "plevent.h"
|
||||
#include "nsRepository.h"
|
||||
|
||||
#define RDF_DB "file:///sitemap.rdf"
|
||||
#define RDF_DB "test.rdf"
|
||||
#define SUCCESS 0
|
||||
#define FAILURE -1
|
||||
|
||||
|
||||
#ifdef XP_PC
|
||||
#define NETLIB_DLL "netlib.dll"
|
||||
#endif
|
||||
|
||||
#include "nsIPostToServer.h"
|
||||
#include "nsINetService.h"
|
||||
|
||||
|
||||
static NS_DEFINE_IID(kNetServiceCID, NS_NETSERVICE_CID);
|
||||
|
||||
NS_DEFINE_IID(kIPostToServerIID, NS_IPOSTTOSERVER_IID);
|
||||
|
||||
void fail(char* msg);
|
||||
|
||||
int
|
||||
main(int argc, char** argv)
|
||||
{
|
||||
nsIRDFService* pRDF = 0;
|
||||
PL_InitializeEventsLib("");
|
||||
nsRepository::RegisterFactory(kNetServiceCID, NETLIB_DLL, PR_FALSE, PR_FALSE);
|
||||
|
||||
NS_GetRDFService( &pRDF );
|
||||
PR_ASSERT( pRDF != 0 );
|
||||
|
@ -37,30 +59,30 @@ main(int argc, char** argv)
|
|||
|
||||
/* turn on logging */
|
||||
|
||||
pRDF->CreateDatabase( url, &pDB );
|
||||
pRDF->CreateDatabase((const char**) url, &pDB );
|
||||
PR_ASSERT( pDB != 0 );
|
||||
|
||||
/* execute queries */
|
||||
RDF_Resource resource = 0;
|
||||
if( NS_OK != pDB->CreateResource("http://www.hotwired.com", &resource) )
|
||||
if( NS_OK != pDB->CreateResource("test.rdf#root", &resource) )
|
||||
fail("Unable to get resource on db!!!\n");
|
||||
RDF_Resource child = 0;
|
||||
if( NS_OK != pDB->GetResource("child", &resource) )
|
||||
fail("Unable to get resource 'child'!!!\n");
|
||||
PR_ASSERT( child != 0 );
|
||||
RDF_Resource parent = 0;
|
||||
if( NS_OK != pDB->GetResource("parent", &parent) )
|
||||
fail("Unable to get resource 'parent'!!!\n");
|
||||
PR_ASSERT(parent != 0 );
|
||||
{
|
||||
// enumerate children
|
||||
nsIRDFCursor* cursor;
|
||||
if( NS_OK != pDB->GetTargets( resource, child, RDF_RESOURCE_TYPE, &cursor ) )
|
||||
if( NS_OK != pDB->GetSources(resource, parent, RDF_RESOURCE_TYPE, &cursor ) )
|
||||
fail("Unable to get targets on db\n!!!");
|
||||
|
||||
PRBool hasElements;
|
||||
cursor->HasElements( hasElements );
|
||||
while( hasElements ) {
|
||||
RDF_NodeStruct node;
|
||||
cursor->Next( node );
|
||||
RDF_NodeStruct node;
|
||||
cursor->Next(node);
|
||||
while(node.value.r != NULL) {
|
||||
char* url;
|
||||
pRDF->ResourceIdentifier(node.value.r, &url);
|
||||
printf("%s\n", url );
|
||||
pDB->ReleaseResource( node.value.r );
|
||||
cursor->HasElements( hasElements );
|
||||
cursor->Next(node);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче