Back to index

lightning-sunbird  0.9+nobinonly
rdf-int.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is mozilla.org code.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * Netscape Communications Corporation.
00019  * Portions created by the Initial Developer are Copyright (C) 1998
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s):
00023  *
00024  * Alternatively, the contents of this file may be used under the terms of
00025  * either of the GNU General Public License Version 2 or later (the "GPL"),
00026  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00027  * in which case the provisions of the GPL or the LGPL are applicable instead
00028  * of those above. If you wish to allow use of your version of this file only
00029  * under the terms of either the GPL or the LGPL, and not to allow others to
00030  * use your version of this file under the terms of the MPL, indicate your
00031  * decision by deleting the provisions above and replace them with the notice
00032  * and other provisions required by the GPL or the LGPL. If you do not delete
00033  * the provisions above, a recipient may use your version of this file under
00034  * the terms of any one of the MPL, the GPL or the LGPL.
00035  *
00036  * ***** END LICENSE BLOCK ***** */
00037 
00038 #include <stdlib.h>
00039 #include <stdio.h>
00040 #include <string.h>
00041 #include "rdf.h"
00042 #define true 1
00043 #define false 0
00044 
00045 #define null NULL
00046 #define nullp(x) (((void*)x) == ((void*)0))
00047 #define noRDFErr 0
00048 #define noMoreValuesErr 1
00049 
00050 #define LookupResource(x) ((RDF_Resource)PL_HashTableLookup(resourceHash, x));
00051 #define stringEquals(x, y) (strcmp(x, y) ==0)
00052 
00053 #define wsCharp(c) ((c == '\r') || (c == '\t') || (c == ' ') || (c == '\n'))
00054 #define RDF_BUF_SIZE (4096 * 16)
00055 #define MAX_ATTRIBUTES 256
00056 #define EXPECTING_OBJECT 1
00057 #define EXPECTING_PROPERTY 2
00058 #define  GROW_LIST_INCR 1000
00059 
00060 typedef struct _RDF_ResourceStruct {
00061   char* url;
00062   struct _RDF_AssertionStruct* rarg1;
00063   struct _RDF_AssertionStruct* rarg2;
00064 } RDF_ResourceStruct ;
00065 
00066 
00067 
00068 
00069 typedef enum {
00070   GET_SLOT_VALUES,
00071   ARC_LABELS_IN,
00072   ARC_LABELS_OUT,
00073   SEARCH
00074 } QueryType;
00075 
00076 
00077 typedef struct _RDF_FileStruct {
00078   char* url;
00079   int   status;
00080   char* storeAway;
00081   char* line;
00082   char* holdOver;
00083   RDF_Resource stack[256];
00084   RDF_Resource lastItem;
00085   int   depth ;
00086   int   tagDepth;
00087   int   assertionListCount;
00088   int   assertionListSize;
00089   struct _RDF_AssertionStruct** assertionList;
00090   char* nsList[20];
00091   int   nsStackPoint;
00092 } RDF_FileStruct;
00093 
00094 
00095 
00096 typedef struct _RDF_CursorStruct {
00097   RDF_Resource u; 
00098   RDF_Resource s;
00099   void *value;
00100   void* pdata;
00101   void* pdata1;
00102   RDF_Resource* pdata2;
00103   int inversep;
00104   RDF_ValueType type;
00105   size_t count;
00106   size_t off;
00107   size_t off1;
00108   RDFT db;
00109   QueryType queryType;
00110   char* searchString;
00111 } RDF_CursorStruct;
00112 
00113 
00114 
00115 typedef struct _RDF_AssertionStruct {
00116   RDF_Resource u;
00117   RDF_Resource s;
00118   void* value;
00119   RDF_ValueType type;
00120   struct _RDF_AssertionStruct* next;
00121   struct _RDF_AssertionStruct* invNext;
00122   RDFT db;
00123 } RDF_AssertionStruct;
00124 
00125 
00126 typedef RDF_AssertionStruct* Assertion;
00127 typedef struct _HashTableStruct* HashTable;
00128 
00129 HashTable  NewHashTable(int size) ;
00130 void* HashLookup(HashTable ht, char* key) ;
00131 void HashAdd (HashTable ht, char* key, void* value) ;
00132 
00133 void readRDFFile (char* file) ;
00134 RDF_Resource getResource(char* url, int createp);
00135 char* getMem(size_t n);
00136 char* fgetMem (size_t size) ;
00137 void  freeMem(void* item);
00138 RDFT initFileStruct (char* url) ;
00139 void rdf_init();
00140 int startsWith (const char* pattern, const char* uuid);
00141 char decodeEntityRef (char* string, int* stringIndexPtr, int len);
00142 char * copyStringIgnoreWhiteSpace(char* string);
00143 char * getHref(char** attlist);
00144 int parseNextRDFXMLBlobInt(RDFT f, char* blob, int size) ;
00145 char * getAttributeValue (char** attlist, char* elName);
00146 int tagEquals (RDFT f, char* tag1, char* tag2);
00147 void addElementProps (char** attlist, char* elementName, RDFT f, RDF_Resource obj);
00148 int knownObjectElement (char* eln);
00149 char *possiblyMakeAbsolute (RDFT f, char* url);
00150 int containerTagp (RDFT f, char* elementName);
00151 RDF_Resource ResourceFromElementName (RDFT f, char* elementName);
00152 int parseNextRDFToken (RDFT f, char* token);
00153 int tokenizeElement (char* attr, char** attlist, char** elementName);
00154 void addSlotValue (RDFT f, RDF_Resource u, RDF_Resource s, void* v, 
00155                    RDF_ValueType type, char* op);
00156 char* copyString(char* str) ;
00157 char*  fcopyString (char* str) ;
00158 
00159 
00160 
00161 
00162 int asEqual(RDFT r, Assertion as, RDF_Resource u, RDF_Resource s, void* v, 
00163               RDF_ValueType type);
00164 Assertion makeNewAssertion (RDFT r, RDF_Resource u, RDF_Resource s, void* v,                      
00165     RDF_ValueType type, int tv);
00166 void freeAssertion (Assertion as);
00167 Assertion remoteStoreAdd (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
00168  RDF_ValueType type, int tv);
00169 Assertion remoteStoreRemove (RDFT mcf, RDF_Resource u, RDF_Resource s,  void* v, 
00170 RDF_ValueType type);
00171 int remoteStoreHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, 
00172 RDF_ValueType type, int tv);
00173 void * getSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, 
00174 int inversep,  int tv);
00175 RDF_Cursor getSlotValues (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,  
00176 int inversep, int tv);
00177 void* nextValue (RDF_Cursor c) ;
00178 void disposeCursor (RDF_Cursor c);
00179 void unloadRDFT (RDFT f);
00180 int rdf_DigestNewStuff (char* fileName, char* data, int len) ;
00181 RDFT getRDFT(char* url, int createp);
00182 char** processRDFQuery (char* query);