home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / modules / rdf / src / rdf-int.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  13.1 KB  |  386 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19.  
  20.  
  21. #ifndef    _RDF_RDF_INT_H
  22. #define    _RDF_RDF_INT_H
  23.  
  24. /*
  25. #define    DEBUG_RDF_GetSlotValue_Memory_Needs_Freedom    1
  26. */
  27.  
  28.  
  29. #define WINTEST 0
  30. #define DBMTEST 1 
  31. #define FSTEST 1
  32.  
  33.  
  34. #define    RDF_BUF_SIZE    4096
  35. #define LINE_SIZE     512
  36. #define RDF_BOOKMARKS 128
  37. #define RDF_MCF       129
  38. #define RDF_XML       130
  39.  
  40. #include <stdlib.h>
  41. #include <string.h>
  42. #include "rdf.h"
  43. #include "nspr.h"
  44. #include "plhash.h"
  45. #include "ntypes.h"
  46. #include "net.h"
  47. #include "xp.h"
  48. #include "xp_str.h"
  49.  
  50. #ifndef XP_WIN32
  51. #include "prefapi.h"
  52. #endif
  53.  
  54. #ifndef true
  55. #define true PR_TRUE
  56. #endif
  57. #ifndef false
  58. #define false PR_FALSE
  59. #endif
  60. #define null NULL
  61. #define nullp(x) (((void*)x) == ((void*)0))
  62.  
  63.  
  64. #define noRDFErr 0
  65. #define noMoreValuesErr 1
  66.  
  67. #define MAX_ATTRIBUTES 10
  68.  
  69. #define RDF_RT 0
  70. #define LFS_RT 1
  71. #define FTP_RT  3
  72. #define ES_RT 4
  73. #define SEARCH_RT  5
  74. #define HISTORY_RT 6
  75. #define LDAP_RT 7
  76. #define PM_RT 8
  77. #define RDM_RT 9
  78. #define    IM_RT    10
  79. #define CACHE_RT 11
  80. #define WILDCARD_RT 15
  81.  
  82.  
  83. #define CHECK_VAR(var, return_value) {if (var == NULL) {XP_ASSERT(var); return return_value;}}
  84. #define CHECK_VAR1(var) {if (var == NULL) {XP_ASSERT(var); return;}}
  85.  
  86.  
  87.  
  88. #define MAX_URL_SIZE 300
  89.  
  90. #define copyString(source) XP_STRDUP(source)
  91. #define stringEquals(x, y) (strcasecomp(x, y) ==0)
  92. /*#define stringAppend(x, y)   XP_AppendStr(x,y) */
  93.  
  94. struct RDF_ResourceStruct {
  95.   char* url;
  96.   uint8  type;  
  97.   uint8  flags;
  98.   struct RDF_AssertionStruct* rarg1;
  99.   struct RDF_AssertionStruct* rarg2;
  100.   struct RDF_ListStruct*          rdf;
  101. } ;
  102.  
  103. #define RDF_GET_SLOT_VALUES_QUERY 0x01
  104. #define RDF_GET_SLOT_VALUE_QUERY 0x02
  105. #define RDF_FIND_QUERY 0x03
  106. #define RDF_ARC_LABELS_IN_QUERY 0x04
  107. #define RDF_ARC_LABELS_OUT_QUERY 0x05
  108.  
  109. struct RDF_CursorStruct {
  110.   RDF_Resource u;
  111.   RDF_Resource s;
  112.   PRBool tv;
  113.   PRBool inversep;
  114.   void* value;
  115.   RDF_ValueType type;
  116.   struct RDF_CursorStruct* current;
  117.   int16 count;
  118.   void* pdata;
  119.   uint16 size;
  120.   RDF    rdf;
  121.   uint8 queryType;
  122. };
  123.  
  124. typedef uint8 RDF_BT;
  125.  
  126. #define getMem(x) PR_Calloc(1,(x))
  127. #define freeMem(x) PR_Free((x))
  128.  
  129. struct RDF_AssertionStruct {
  130.   RDF_Resource u;
  131.   RDF_Resource s;
  132.   void* value;
  133.   PRBool tv;
  134.   RDF_ValueType type;
  135.   uint8 tags;
  136.   struct RDF_AssertionStruct* next;
  137.   struct RDF_AssertionStruct* invNext;
  138. } ;
  139.  
  140.  
  141. typedef struct RDF_AssertionStruct *Assertion;
  142. typedef struct RDF_TranslatorStruct *RDFT;
  143. typedef struct RDF_FileStruct *RDFFile;
  144.  
  145.  
  146. RDF    newNavCenterDB();
  147. typedef PRBool (*assertProc)(RDFT r, RDF_Resource u, RDF_Resource  s, void* value, RDF_ValueType type, PRBool tv);
  148. typedef PRBool (*hasAssertionProc)(RDFT r, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
  149. typedef void* (*getSlotValueProc)(RDFT r, RDF_Resource u, RDF_Resource s, RDF_ValueType type,  PRBool inversep, PRBool tv) ;
  150. typedef RDF_Cursor (*getSlotValuesProc)(RDFT r, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
  151. typedef PRBool (*unassertProc)(RDFT r, RDF_Resource u, RDF_Resource s, void* value, RDF_ValueType type);
  152. typedef void* (*nextItemProc)(RDFT r, RDF_Cursor c) ;
  153. typedef RDF_Error (*disposeCursorProc)(RDFT r, RDF_Cursor c);
  154. typedef RDF_Error (*disposeResourceProc)(RDFT r, RDF_Resource u);
  155. typedef RDF_Error (*destroyProc)(struct RDF_TranslatorStruct*);
  156. typedef RDF_Cursor (*arcLabelsOutProc)(RDFT r, RDF_Resource u);
  157. typedef RDF_Cursor (*arcLabelsInProc)(RDFT r, RDF_Resource u);
  158. typedef PRBool (*fAssert1Proc) (RDFFile  file, RDFT mcf,  RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
  159.  
  160. struct RDF_ListStruct {
  161.   struct RDF_DBStruct*   rdf;
  162.   struct RDF_ListStruct* next;
  163. } ;
  164.  
  165. typedef struct RDF_ListStruct *RDFL;
  166.  
  167. struct RDF_TranslatorStruct {
  168.   RDFL             rdf;
  169.   char*            url;
  170.   void*            pdata;
  171.   destroyProc      destroy;
  172.   hasAssertionProc hasAssertion;
  173.   unassertProc     unassert;
  174.   assertProc       assert;
  175.   getSlotValueProc getSlotValue;
  176.   getSlotValuesProc getSlotValues;
  177.   nextItemProc      nextValue;
  178.   disposeCursorProc disposeCursor;
  179.   disposeResourceProc disposeResource;
  180.   arcLabelsInProc   arcLabelsIn;
  181.   arcLabelsInProc   arcLabelsOut;
  182. };
  183.  
  184.  
  185. extern     PLHashTable*  resourceHash;  
  186. struct RDF_DBStruct {
  187.   int16 numTranslators;
  188.   RDFT*  translators;
  189.   struct RDF_FileStruct* files;
  190.   struct RDF_NotificationStruct* notifs;
  191. };
  192.  
  193. extern RDFT gLocalStore;
  194. extern RDFT gRemoteStore;
  195. extern RDFT gSessionDB;
  196. extern size_t gCoreVocabSize;
  197. extern RDF_Resource* gAllVocab;
  198.  
  199. /* reading rdf */
  200.  
  201. #define HEADERS 1
  202. #define BODY    2
  203.  
  204.  
  205. struct XMLNameSpaceStruct {
  206.   char* as;
  207.   char* url;
  208.   struct XMLNameSpaceStruct* next;
  209. } ;
  210.  
  211. typedef struct XMLNameSpaceStruct *XMLNameSpace;
  212.  
  213. struct RDF_FileStruct {
  214.   char* url;
  215.   RDF_Resource currentResource;
  216.   RDF_Resource top;
  217.   RDF_Resource rtop;
  218.   char*  currentSlot;
  219.   PRBool genlAdded;
  220.   PRBool localp;
  221.   char* storeAway;
  222.   char* line;
  223.   uint16   status;
  224.   uint16   resourceCount;
  225.   uint16   resourceListSize;
  226.   uint16   assertionCount;
  227.   uint16   assertionListSize;
  228.   RDF_Resource* resourceList;
  229.   Assertion* assertionList;
  230.   char* holdOver;
  231.   PRTime lastReadTime;
  232.   PRTime *expiryTime;
  233.   RDF_Resource stack[16];
  234.   uint16   depth ;
  235.   uint8   fileType;
  236.   PRBool  locked;
  237.   RDF_Resource lastItem;
  238.   int32   lineSize;
  239.   struct RDF_FileStruct* next;
  240.   PRBool tv;
  241.   fAssert1Proc assert;
  242.   RDFT     db;
  243.   void* pdata;
  244.   XMLNameSpace namespaces;
  245. } ;
  246.  
  247.  
  248.  
  249. RDF_Resource nextFindValue (RDF_Cursor c) ;
  250. PRBool isTypeOf (RDF rdf, RDF_Resource u,  RDF_Resource v); 
  251. RDF getRDFDB (void);
  252. RDFFile readRDFFile (char* url, RDF_Resource top, PRBool localp);
  253. void sendNotifications (RDF rdf, RDF_EventType opType, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv, char* ds);
  254. void sendNotifications2 (RDFT rdf, RDF_EventType opType, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
  255. RDF_Error exitRDF (RDF rdf);
  256. void parseNextBkBlob(RDFFile f, char* blob, int32 blobSize);
  257. void printAssertion(Assertion as);
  258. RDF_Error addChildAfter (RDFT rdf, RDF_Resource parent, RDF_Resource child, RDF_Resource afterWhat);
  259. RDF_Error addChildBefore (RDFT rdf, RDF_Resource parent, RDF_Resource child, RDF_Resource beforeWhat);
  260. void nlclStoreKill(RDFT rdf, RDF_Resource r);
  261. char* resourceID(RDF_Resource id);
  262. PRBool containerp (RDF_Resource r);
  263. void   setContainerp (RDF_Resource r, PRBool contp);
  264. PRBool lockedp (RDF_Resource r);
  265. void   setLockedp (RDF_Resource r, PRBool contp);
  266. uint8  resourceType (RDF_Resource r);
  267. void   setResourceType (RDF_Resource r, uint8 type);
  268. char* getBaseURL (const char* url) ;
  269. void freeNamespaces (RDFFile f) ;
  270. PRBool asEqual(Assertion as, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
  271. Assertion makeNewAssertion (RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
  272.  
  273.  
  274. void readResourceFile(RDF rdf, RDF_Resource u);
  275. void possiblyGCResource(RDF_Resource u);
  276. PLHashNumber idenHash(const void* key);
  277.  
  278. /* string utilities */
  279.  
  280. int16 charSearch(const char c,const  char* string);
  281. int16 revCharSearch(const char c, const char* string);
  282. PR_PUBLIC_API(PRBool) startsWith(const char* startPattern,const  char* string);
  283. PRBool endsWith(const char* endPattern,const  char* string);
  284. PRBool inverseTV(PRBool tv);
  285. void createBootstrapResources();
  286. PRBool urlEquals(const char* url1,const  char* url2);
  287. char* append2Strings(const char* str1,const  char* str2);
  288. PRBool substring(const char* pattern, const char* data);
  289. void stringAppend(char* in, const char* append);
  290.  
  291. RDFFile makeRDFFile (char* url, RDF_Resource top, PRBool localp);
  292. void initRDFFile (RDFFile ans) ;
  293. void parseNextRDFLine (RDFFile f, char* line) ;
  294. void parseNextRDFBlob (RDFFile f, char* blob, int32 size);
  295. void finishRDFParse (RDFFile f) ;
  296. void abortRDFParse (RDFFile f);
  297. void unitTransition (RDFFile f) ;    
  298. void assignHeaderSlot (RDFFile f, char* slot, char* value);            
  299. RDF_Error getFirstToken (char* line, char* nextToken, int16* l) ;
  300. void addSlotValue (RDFFile f, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
  301. void assignSlot (RDF_Resource u, char* slot, char* value, RDFFile f);
  302. RDF_Error parseSlotValue (RDFFile f, RDF_Resource s, char* value, void** parsed_value, RDF_ValueType* data_type) ;
  303. RDF_Resource resolveReference (char *tok, RDFFile f) ;
  304. RDF_Resource resolveGenlPosReference(char* tok,  RDFFile f);
  305. RDF_Resource resolveReference (char *tok, RDFFile f) ;
  306. RDF_Resource resolveGenlPosReference(char* tok,  RDFFile f);
  307. void beginReadingRDFFile(RDFFile f);
  308. void gcRDFFile (RDFFile f);
  309. #ifdef XP_MAC
  310. char* unescapeURL(char* inURL);
  311. #endif
  312. char* convertFileURLToNSPRCopaceticPath(char* inURL);
  313. PRFileDesc* CallPROpenUsingFileURL(char *fileURL, PRIntn flags, PRIntn mode);
  314. DB *CallDBOpenUsingFileURL(char *fileURL, int flags,int mode, DBTYPE type, const void *openinfo);
  315.  
  316. PRBool nlocalStoreAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, 
  317.              RDF_ValueType type, PRBool tv) ;
  318.  
  319. void initLocalStore(RDFT rdf);
  320. void freeAssertion(Assertion as);
  321. Assertion localStoreAdd (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv)  ;
  322. Assertion localStoreRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type)  ;
  323.  
  324. Assertion remoteStoreAdd (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
  325. Assertion remoteStoreRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type) ;
  326. void* remoteStoreGetSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep,  PRBool tv) ;
  327. void ht_fprintf(PRFileDesc *file, const char *fmt, ...);
  328.  
  329. RDF_Resource createContainer (char* id);
  330. PRBool isContainer (RDF_Resource r) ;
  331. PRBool isSeparator (RDF_Resource r) ;
  332. PRBool isLeaf (RDF_Resource r) ;
  333. PRBool bookmarkSlotp (RDF_Resource s) ;
  334.  
  335. void basicAssertions (void) ;
  336. char* makeResourceName (RDF_Resource node) ;
  337. char* makeDBURL (char* name);
  338.  
  339. int rdf_GetURL (MWContext *cx, int method, Net_GetUrlExitFunc *exit_routine, RDFFile rdfFile);
  340.  
  341.  
  342. PRBool nlocalStoreAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
  343.              RDF_ValueType type, PRBool tv) ;
  344. PRBool nlocalStoreUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
  345.                RDF_ValueType type) ;
  346. PRBool nlocalStoreHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
  347. void* nlocalStoreGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep,  PRBool tv) ;
  348. RDF_Cursor nlocalStoreGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,  PRBool inversep, PRBool tv) ;
  349. void* nlocalStoreNextValue (RDFT mcf, RDF_Cursor c) ;
  350. RDF_Error nlocalStoreDisposeCursor (RDFT mcf, RDF_Cursor c) ;
  351. void createCoreVocab () ;
  352.  
  353.  
  354. PRBool remoteAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
  355.              RDF_ValueType type, PRBool tv) ;
  356. PRBool remoteUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
  357.                RDF_ValueType type) ;
  358. PRBool remoteAssert1 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
  359.              RDF_ValueType type, PRBool tv) ;
  360. PRBool remoteAssert2 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
  361.              RDF_ValueType type, PRBool tv) ;
  362. PRBool remoteUnassert1 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
  363.                RDF_ValueType type) ;
  364. PRBool remoteStoreHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
  365. void* remoteStoreGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep,  PRBool tv) ;
  366. RDF_Cursor remoteStoreGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,  PRBool inversep, PRBool tv) ;
  367. RDF_Cursor remoteStoreGetSlotValuesInt (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,  PRBool inversep, PRBool tv) ;
  368.  
  369. void* remoteStoreNextValue (RDFT mcf, RDF_Cursor c) ;
  370. RDF_Error remoteStoreDisposeCursor (RDFT mcf, RDF_Cursor c) ;
  371. PRBool remoteStoreHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
  372. PRBool remoteStoreHasAssertionInt (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv) ;
  373. PRBool  nlocalStoreAddChildAt(RDFT mcf, RDF_Resource obj, RDF_Resource ref, RDF_Resource new, 
  374.               PRBool beforep);
  375. char* advertURLOfContainer (RDF r, RDF_Resource u) ;
  376.  
  377.  
  378.  
  379.  
  380. extern RDF_WDVocab gWebData;
  381. extern RDF_NCVocab gNavCenter;
  382. extern RDF_CoreVocab gCoreVocab;
  383.  
  384.  
  385. #endif
  386.