Compare commits

..

14 Commits

Author SHA1 Message Date
jgellman%netscape.com
0b2424f7ca netlib glue, not as modular as we want but getting there
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@13281 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-21 21:51:10 +00:00
jgellman%netscape.com
75bfddcd5c it builds!!
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@13056 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-17 01:37:57 +00:00
jgellman%netscape.com
d67638c1e0 move old C api stuff out of rdf.h, small changes to COM API
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12956 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-16 01:30:03 +00:00
jgellman%netscape.com
021dfd7c81 RDF_XPCOM_BRANCH
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12953 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-16 00:44:55 +00:00
rjc%netscape.com
272deb6ee9 More HT_RAPTOR support.
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12250 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-08 01:05:41 +00:00
rjc%netscape.com
f81f4440bd Support for HT_RAPTOR.
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12249 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-08 00:56:49 +00:00
jgellman%netscape.com
914f82571b add rdfstr.h
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12236 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-07 23:05:10 +00:00
jgellman%netscape.com
0f1dfe3d0d remove various XP dependencies
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12235 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-07 23:04:45 +00:00
guha%netscape.com
05693f5648 try again
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12217 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-07 20:43:39 +00:00
jgellman%netscape.com
26c6838a88 back out changes to rdf.h until later...: rdf.h
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12154 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-07 04:25:27 +00:00
guha%netscape.com
90406a1af2 Disentangling RDF from the include file mess.
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12149 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-07 02:06:36 +00:00
jgellman%netscape.com
41eefd7f6c rdf c api factored out
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12104 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-06 22:32:41 +00:00
jgellman%netscape.com
ab25b9b291 initial checkin of a bunch of stuff that doesn't work
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@12102 18797224-902f-48f8-a5cc-f745e15eee43
1998-10-06 22:31:12 +00:00
(no author)
a151d7380d This commit was manufactured by cvs2svn to create branch 'RDF_XPCOM_BRANCH'.
git-svn-id: svn://10.0.0.236/branches/RDF_XPCOM_BRANCH@11545 18797224-902f-48f8-a5cc-f745e15eee43
1998-09-30 10:28:36 +00:00
216 changed files with 29513 additions and 193744 deletions

View File

@@ -0,0 +1,9 @@
#! gmake
DEPTH = ../..
DIRS = include src
INCLUDE = $(INCLUDE) -I$(DEPTH)/modules/libimg/public
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,14 @@
#! gmake
DEPTH = ../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = include src
INCLUDE += -I$(topsrcdir)/modules/libimg/public
include $(topsrcdir)/config/rules.mk

Binary file not shown.

After

Width:  |  Height:  |  Size: 269 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1017 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.0 KiB

View File

@@ -0,0 +1,8 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
rdf.h
vocab.h
htrdf.h
jsec2rdf.h

View File

@@ -0,0 +1,26 @@
#!gmake
#
# 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.
#
#
#
MODULE = rdf
DEPTH = ../../..
EXPORTS = rdf.h htrdf.h vocab.h jsec2rdf.h
include $(DEPTH)/config/rules.mk

View File

@@ -0,0 +1,33 @@
#!gmake
#
# 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.
#
#
#
MODULE = rdf
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
EXPORTS = rdf.h htrdf.h vocab.h jsec2rdf.h
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/rules.mk

View File

@@ -0,0 +1,8 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
rdf.h
vocab.h
htrdf.h
jsec2rdf.h

View File

@@ -0,0 +1,580 @@
/* -*- 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 htrdf_h___
#define htrdf_h___
/* the RDF HT API */
#include "rdf.h"
#ifdef XPCOM_XXX
#include "ntypes.h"
#include "structs.h"
#include "pa_parse.h"
#endif
/*
* Hyper Tree Api
*
* Hyper tree is the tree view of the rdf store. This is for use by the FE in
* implementing the nav center.
*
* The RDF structure could be a gnarly graph whose nodes are RDF_Resource.
* There can be multiple tree views (HT_View) into this graph. Corresponding
* to each view, there is a hyper tree whose nodes are HT_Resource.
* Each HT_Resource belongs to exactly one HT_View.
* The FE iterate over the hypertree to draw it. It can start the iteration
* either at the top or at some interior node. When some state change occurs
* in the hypertree, the FE will get notified about the node on which the
* change took place. At that point, it can either redraw the whole thing
* or do a partial redraw. The FE does this by iterating over the relevant
* portions of the hypertree. Since the hypertree is a strict tree, the FE
* can also iterate upwards.
*
*
* Possible state changes to the hypertree of an HT_View include :
* (i) addition/deletion of nodes
* (ii) containers closing/opening
* (iii) selection changes
* These changes could occur either because of
* (i) User clicking around the tree
* (ii) Network activity
* (iii) scripts running
* The FE can recieve notifications about these activities.
* If the FE does not want to be notified about something, it can set
* the notification mask to block certain notifications.
*/
NSPR_BEGIN_EXTERN_C
/* Opaque data structures */
typedef struct _HT_ViewStruct* HT_View;
typedef struct _HT_PaneStruct* HT_Pane;
typedef struct _HT_CursorStruct* HT_Cursor;
typedef struct _HT_ResourceStruct* HT_Resource;
/* for use with HT_GetTemplate */
enum TemplateType {
ht_template_chrome,
ht_template_management,
ht_template_navigation
};
/*
* This is the Notification structure that gets passed to the HT layer on
* creation of the view. This should be allocated/static memory. HT layer
* will store a pointer to this structure. On CloseView, a View Closed
* event will be generated and the notification function will be called.
* At this point, the module using HT can free the memory associated with
* the HT_Notification struct.
*/
typedef uint32 HT_NotificationMask;
typedef uint32 HT_Event;
typedef uint32 HT_Error;
#define HT_NoErr 0
#define HT_Err 1
struct _HT_NotificationStruct;
typedef void (*HT_NotificationProc)(struct _HT_NotificationStruct*,
HT_Resource node, HT_Event whatHappened, void *param, uint32 tokenType);
typedef struct _HT_NotificationStruct {
HT_NotificationProc notifyProc;
void *data;
} HT_NotificationStruct;
/*
* HT_Notification events and masks
*/
typedef HT_NotificationStruct* HT_Notification;
#define HT_EVENT_NODE_ADDED 0x00000001UL
#define HT_EVENT_NODE_DELETED_DATA 0x00000002UL
#define HT_EVENT_NODE_DELETED_NODATA 0x00000004UL
#define HT_EVENT_NODE_VPROP_CHANGED 0x00000008UL
#define HT_EVENT_NODE_SELECTION_CHANGED 0x00000010UL
#define HT_EVENT_NODE_OPENCLOSE_CHANGED 0x00000020UL
#define HT_EVENT_VIEW_CLOSED 0x00000040UL /* same as HT_EVENT_VIEW_DELETED */
#define HT_EVENT_VIEW_DELETED 0x00000040UL /* same as HT_EVENT_VIEW_CLOSED */
#define HT_EVENT_VIEW_SELECTED 0x00000080UL
#define HT_EVENT_VIEW_ADDED 0x00000100UL
#define HT_EVENT_NODE_OPENCLOSE_CHANGING 0x00000200UL
#define HT_EVENT_VIEW_SORTING_CHANGED 0x00000400UL
#define HT_EVENT_VIEW_REFRESH 0x00000800UL
#define HT_EVENT_VIEW_WORKSPACE_REFRESH 0x00001000UL
#define HT_EVENT_NODE_EDIT 0x00002000UL
#define HT_EVENT_WORKSPACE_EDIT 0x00004000UL
#define HT_EVENT_VIEW_HTML_ADD 0x00008000UL
#define HT_EVENT_VIEW_HTML_REMOVE 0x00010000UL
#define HT_EVENT_NODE_ENABLE 0x00020000UL
#define HT_EVENT_NODE_DISABLE 0x00040000UL
#define HT_EVENT_NODE_SCROLLTO 0x00080000UL
#define HT_EVENT_COLUMN_ADD 0x00100000UL
#define HT_EVENT_COLUMN_DELETE 0x00200000UL
#define HT_EVENT_COLUMN_SIZETO 0x00400000UL
#define HT_EVENT_COLUMN_REORDER 0x00800000UL
#define HT_EVENT_COLUMN_SHOW 0x01000000UL
#define HT_EVENT_COLUMN_HIDE 0x02000000UL
#define HT_EVENT_VIEW_MODECHANGED 0x04000000UL
#define HT_EVENT_VIEW_WINDOWTYPE_CHANGED 0x04000000UL
#define HT_EVENT_NO_NOTIFICATION_MASK 0x00000000UL
#define HT_EVENT_DEFAULT_NOTIFICATION_MASK 0xFFFFFFFFUL
/*-----------------------------------------------------------------------*/
/* View/Pane Creation / Destruction / Management */
/*-----------------------------------------------------------------------*/
/* Window Types for Panes */
#define HT_POPUP_WINDOW 0
#define HT_DOCKED_WINDOW 1
#define HT_STANDALONE_WINDOW 2
#define HT_EMBEDDED_WINDOW 3
PR_PUBLIC_API(HT_Pane) HT_PaneFromResource(RDF_Resource r, HT_Notification n, PRBool autoFlush, PRBool autoOpen, PRBool useColumns);
PR_PUBLIC_API(HT_Pane) HT_PaneFromURL(void* context, char* url, char* templateType,
HT_Notification n, PRBool autoFlush, int32 param_count,
char** param_names, char** param_values);
/* NewQuickFilePane
* Creates a pane consisting of one view. This view has the RDF resource
* corresponding to the Quickfile folder as its root.
*/
PR_PUBLIC_API(HT_Pane) HT_NewQuickFilePane (HT_Notification notify);
/* NewToolbarPane
* Added by Dave
* Create a pane consisting of multiple views. Each view corresponds to a single toolbar.
*/
PR_PUBLIC_API(HT_Pane) HT_NewToolbarPane (HT_Notification notify);
/* NewPersonalToolbarPane
* Creates a pane consisting of one view. This view has the RDF resource
* corresponding to the Personal Toolbar folder as its root.
*/
PR_PUBLIC_API(HT_Pane) HT_NewPersonalToolbarPane (HT_Notification notify);
/* HT_NewBreadcrumbPane
*/
PR_PUBLIC_API(HT_Pane) HT_NewBreadcrumbPane (HT_Notification notify);
PR_PUBLIC_API(void) HT_AddToContainer (HT_Resource container, char *url, char *optionalTitle);
PR_PUBLIC_API(void) HT_AddBookmark (char *url, char *optionalTitle);
/* CreateView
* Takes an rdf node as the root of the view tree and creates a XP view.
* HT_Notification would be to the notifier when there is a state change.
*/
PR_PUBLIC_API(HT_Pane) HT_NewPane (HT_Notification notify);
/* DeleteView
* Destroy a valid view created via CreateView
*/
PR_PUBLIC_API(HT_Error) HT_DeleteView (HT_View view);
PR_PUBLIC_API(HT_Error) HT_DeletePane (HT_Pane pane);
/* HT_TopNode
* Obtain the top node associated with a view tree
*/
PR_PUBLIC_API(HT_Resource) HT_TopNode (HT_View view);
PR_PUBLIC_API(void*) HT_GetViewFEData (HT_View node);
PR_PUBLIC_API(void) HT_SetViewFEData (HT_View node, void* data);
PR_PUBLIC_API(void*) HT_GetPaneFEData (HT_Pane pane);
PR_PUBLIC_API(void) HT_SetPaneFEData (HT_Pane pane, void* data);
PR_PUBLIC_API(HT_View) HT_GetSelectedView (HT_Pane pane);
PR_PUBLIC_API(HT_Error) HT_SetSelectedView (HT_Pane pane, HT_View view);
#ifdef XPCOM_XXX
PR_PUBLIC_API(void) HT_LayoutComplete(MWContext *context, TagList *metaTags, char *url);
#endif
enum _HT_ViewType {
HT_VIEW_BOOKMARK=0, HT_VIEW_HISTORY, HT_VIEW_SITEMAP, HT_VIEW_FILES, HT_VIEW_SEARCH
} ;
typedef enum _HT_ViewType HT_ViewType;
/*
* HT_GetViewType: find a particular view type (returns NULL if not found or unknown)
*/
PR_PUBLIC_API(HT_View) HT_GetViewType (HT_Pane pane, HT_ViewType viewType);
/*
* HT_GetView
* Obtain the view tree associated with a node
*/
PR_PUBLIC_API(HT_View) HT_GetView (HT_Resource node);
PR_PUBLIC_API(HT_Pane) HT_GetPane (HT_View view);
/*
* HT_GetViewData / HT_SetViewData
* get/set FE specific data to be associated with a view
*/
PR_PUBLIC_API(void*) HT_GetNodeFEData (HT_Resource node);
PR_PUBLIC_API(void) HT_SetNodeFEData (HT_Resource node, void* data);
/*
* HT_GetNotificationMask / HT_SetNotificationMask
* get/set the notification mask associated with a view
*/
PR_PUBLIC_API(HT_Error) HT_GetNotificationMask (HT_Pane node, HT_NotificationMask *mask);
PR_PUBLIC_API(HT_Error) HT_SetNotificationMask (HT_Pane node, HT_NotificationMask mask);
/*-----------------------------------------------------------------------*/
/* View Traversal */
/*-----------------------------------------------------------------------*/
PR_PUBLIC_API(char *) HT_GetViewName(HT_View view);
/*
* HT_GetNthView
*/
PR_PUBLIC_API(HT_View) HT_GetNthView (HT_Pane pane, uint32 theIndex);
PR_PUBLIC_API(uint32) HT_GetViewIndex(HT_View view);
PR_PUBLIC_API(uint32) HT_GetViewListCount(HT_Pane pane);
/*
* HT_GetNthItem / HT_GetNodeIndex
* get the nth resource in a view (or NULL if not in view),
* or find a resource's index in a view
*/
PR_PUBLIC_API(HT_Resource) HT_GetNthItem (HT_View view, uint32 theIndex);
PR_PUBLIC_API(uint32) HT_GetNodeIndex(HT_View view, HT_Resource node);
PR_PUBLIC_API(uint32) HT_GetItemListCount(HT_View view);
PR_PUBLIC_API(uint16) HT_GetItemIndentation(HT_Resource r);
/*
* HT_GetParent
* obtain the parent of a node
*/
PR_PUBLIC_API(HT_Resource) HT_GetParent (HT_Resource node);
/*
* HT_NodeDisplayString/HT_ViewDisplayString (obsolete)
* obtain the name of a node
*/
PR_PUBLIC_API(HT_Error) HT_NodeDisplayString (HT_Resource node, char *buffer, int bufferLen); /* obsolete! */
PR_PUBLIC_API(HT_Error) HT_ViewDisplayString (HT_View view, char *buffer, int bufferLen); /* obsolete! */
/* an API for external access to the templates. It takes a specifier
defined by enum TemplateType, in this file. HT_GetTemplate() returns
the basic HT_Pane corresponding to the requested type. */
PR_PUBLIC_API(HT_Pane) HT_GetTemplate(int templateType);
PR_PUBLIC_API(PRBool) HT_GetTemplateData(HT_Resource node, void* token, uint32 tokenType, void **nodeData);
PR_PUBLIC_API(PRBool) HT_GetNodeData (HT_Resource node, void *token,
uint32 tokenType, void **data);
PR_PUBLIC_API(PRBool) HT_IsNodeDataEditable(HT_Resource node,
void *token, uint32 tokenType);
PR_PUBLIC_API(HT_Error) HT_SetNodeData (HT_Resource node, void *token,
uint32 tokenType, void *data);
PR_PUBLIC_API(HT_Error) HT_SetNodeName (HT_Resource node, void *data);
PR_PUBLIC_API(HT_Error) HT_SetTreeStateForButton(HT_Resource node, int state);
PR_PUBLIC_API(int) HT_GetTreeStateForButton(HT_Resource node);
PR_PUBLIC_API(HT_Error) HT_SetWindowType(HT_Pane pane, int windowType);
PR_PUBLIC_API(int) HT_GetWindowType(HT_Pane pane);
/*
* HT_GetLargeIconURL / HT_GetSmallIconURL
* obtain the large/small icon URLs for a node if available, otherwise return NULL
*/
PR_PUBLIC_API(char *) HT_GetWorkspaceLargeIconURL (HT_View view);
PR_PUBLIC_API(char *) HT_GetWorkspaceSmallIconURL (HT_View view);
PR_PUBLIC_API(char *) HT_GetNodeLargeIconURL (HT_Resource r);
PR_PUBLIC_API(char *) HT_GetNodeSmallIconURL (HT_Resource r);
PR_PUBLIC_API(char *) HT_GetIconURL(HT_Resource r, PRBool isToolbarIcon, PRBool isWorkspace, int buttonState);
PR_PUBLIC_API(char *) HT_GetLargeIconURL (HT_Resource r); /* obsolete! */
PR_PUBLIC_API(char *) HT_GetSmallIconURL (HT_Resource r); /* obsolete! */
/*
* HT_NewColumnCursor / HT_GetNextColumn / HT_DeleteColumnCursor
* obtain column information
*/
enum _HT_ColumnType {
HT_COLUMN_UNKNOWN=0, HT_COLUMN_STRING, HT_COLUMN_DATE_STRING,
HT_COLUMN_DATE_INT, HT_COLUMN_INT, HT_COLUMN_RESOURCE
} ;
typedef enum _HT_ColumnType HT_ColumnType;
PR_PUBLIC_API(HT_Cursor) HT_NewColumnCursor (HT_View view);
PR_PUBLIC_API(PRBool) HT_GetNextColumn(HT_Cursor cursor, char **colName,
uint32 *colWidth, void **token, uint32 *tokenType);
PR_PUBLIC_API(void) HT_DeleteColumnCursor(HT_Cursor cursor);
PR_PUBLIC_API(void) HT_SetColumnOrder(HT_View view, void *srcColToken,
void *destColToken,
PRBool afterDestFlag);
PR_PUBLIC_API(void) HT_SetSortColumn(HT_View view, void *token,
uint32 tokenType, PRBool descendingFlag);
PR_PUBLIC_API(void) HT_SetColumnWidth(HT_View view, void *token,
uint32 tokenType, uint32 width);
PR_PUBLIC_API(uint32) HT_GetColumnWidth(HT_View view, void *token, uint32 tokenType);
PR_PUBLIC_API(void) HT_SetColumnVisibility(HT_View view, void *token, uint32 tokenType, PRBool isHiddenFlag);
PR_PUBLIC_API(PRBool) HT_GetColumnVisibility(HT_View view, void *token, uint32 tokenType);
PR_PUBLIC_API(void) HT_ShowColumn(HT_View view, void *token, uint32 tokenType);
PR_PUBLIC_API(void) HT_HideColumn(HT_View view, void *token, uint32 tokenType);
PR_PUBLIC_API(PRBool) HT_ContainerSupportsNaturalOrderSort(HT_Resource container);
PR_PUBLIC_API(void) HT_SetColumnFEData(HT_View view, void *token, void *data);
PR_PUBLIC_API(void *) HT_GetColumnFEData (HT_View view, void *token);
PR_PUBLIC_API(void) HT_SetTopVisibleNodeIndex(HT_View view, uint32 topNodeIndex);
PR_PUBLIC_API(uint32) HT_GetTopVisibleNodeIndex(HT_View view);
/*
* HT Menu Commands
*/
enum _HT_MenuCmd {
HT_CMD_SEPARATOR=0, HT_CMD_OPEN, HT_CMD_OPEN_FILE, HT_CMD_PRINT_FILE,
HT_CMD_OPEN_NEW_WIN, HT_CMD_OPEN_COMPOSER, HT_CMD_OPEN_AS_WORKSPACE,
HT_CMD_NEW_BOOKMARK, HT_CMD_NEW_FOLDER, HT_CMD_NEW_SEPARATOR,
HT_CMD_MAKE_ALIAS, HT_CMD_ADD_TO_BOOKMARKS, HT_CMD_SAVE_AS,
HT_CMD_CREATE_SHORTCUT, HT_CMD_SET_TOOLBAR_FOLDER,
HT_CMD_SET_BOOKMARK_MENU, HT_CMD_SET_BOOKMARK_FOLDER, HT_CMD_CUT,
HT_CMD_COPY, HT_CMD_PASTE, HT_CMD_DELETE_FILE, HT_CMD_DELETE_FOLDER,
HT_CMD_REVEAL_FILEFOLDER, HT_CMD_PROPERTIES, HT_CMD_RENAME_WORKSPACE,
HT_CMD_DELETE_WORKSPACE, HT_CMD_MOVE_WORKSPACE_UP, HT_CMD_MOVE_WORKSPACE_DOWN,
HT_CMD_REFRESH, HT_CMD_EXPORT, HT_CMD_REMOVE_BOOKMARK_MENU,
HT_CMD_REMOVE_BOOKMARK_FOLDER, HT_CMD_SET_PASSWORD, HT_CMD_REMOVE_PASSWORD,
HT_CMD_EXPORTALL, HT_CMD_UNDO, HT_CMD_NEW_WORKSPACE, HT_CMD_RENAME, HT_CMD_FIND,
HT_CMD_GET_NEW_MAIL
};
typedef enum _HT_MenuCmd HT_MenuCmd;
PR_PUBLIC_API(HT_Cursor) HT_NewContextMenuCursor(HT_Resource r);
PR_PUBLIC_API(HT_Cursor) HT_NewContextualMenuCursor (HT_View view,
PRBool workspaceMenuCmds,
PRBool backgroundMenuCmds);
PR_PUBLIC_API(PRBool) HT_NextContextMenuItem(HT_Cursor c, HT_MenuCmd *menuCmd);
PR_PUBLIC_API(void) HT_DeleteContextMenuCursor(HT_Cursor c);
PR_PUBLIC_API(char *) HT_GetMenuCmdName(HT_MenuCmd menuCmd);
PR_PUBLIC_API(HT_Error) HT_DoMenuCmd(HT_Pane pane, HT_MenuCmd menuCmd);
PR_PUBLIC_API(PRBool) HT_IsMenuCmdEnabled(HT_Pane pane, HT_MenuCmd menuCmd);
/*
* HT_Find
* show HTML find dialog (hint is the default string to look for and can be NULL)
*/
PR_PUBLIC_API(void) HT_Find(char *hint);
/*
* HT_Properties
* show HTML dialog of node's properties
*/
PR_PUBLIC_API(void) HT_Properties (HT_Resource r);
/*
* HT_GetRDFResource
* obtain the RDF_Resource associated with a HT node
*/
PR_PUBLIC_API(RDF_Resource) HT_GetRDFResource (HT_Resource node);
/*
* Access the node's name and URL
*/
PR_PUBLIC_API(char *) HT_GetNodeURL(HT_Resource node);
PR_PUBLIC_API(char *) HT_GetNodeDisplayURL(HT_Resource node);
PR_PUBLIC_API(char *) HT_GetNodeName(HT_Resource node);
/*-----------------------------------------------------------------------*/
/* Accessor and Mutators */
/*-----------------------------------------------------------------------*/
/*
* HT_IsURLBar
* determine whether node is a URL bar
*/
PR_PUBLIC_API(PRBool) HT_IsURLBar (HT_Resource node);
/*
* HT_IsSeparator
* determine whether node is a separator
*/
PR_PUBLIC_API(PRBool) HT_IsSeparator (HT_Resource node);
/*
* HT_IsContainer
* determine whether node is a container
*/
PR_PUBLIC_API(PRBool) HT_IsContainer (HT_Resource node);
PR_PUBLIC_API(uint32) HT_GetCountVisibleChildren(HT_Resource node);
PR_PUBLIC_API(uint32) HT_GetCountDirectChildren(HT_Resource node);
PR_PUBLIC_API(HT_Resource) HT_GetContainerItem(HT_Resource parent, uint32 childNum);
/*
* HT_DataSource : obtain the origin of the data
* HT_IsLocalData : is the data local?
*/
PR_PUBLIC_API(PRBool) HT_IsLocalData (HT_Resource node) ;
PR_PUBLIC_API(char *) HT_DataSource (HT_Resource node) ;
PR_PUBLIC_API(HT_Pane) HT_GetHTPaneList ();
PR_PUBLIC_API(HT_Pane) HT_GetNextHTPane (HT_Pane pane);
/*
* HT_IsSelected / HT_GetSelectedState / HT_SetSelectedState
* manage selection state of a node; get/set operations will generate
* a HT_EVENT_NODE_SELECTION_CHANGED notification unless masked out
*/
PR_PUBLIC_API(PRBool) HT_IsSelected (HT_Resource node);
PR_PUBLIC_API(HT_Error) HT_GetSelectedState (HT_Resource node, PRBool *selectedState);
PR_PUBLIC_API(HT_Error) HT_SetSelectedState (HT_Resource node, PRBool isSelected);
PR_PUBLIC_API(HT_Error) HT_SetSelection (HT_Resource node);
PR_PUBLIC_API(HT_Error) HT_SetSelectionAll (HT_View view, PRBool selectedState);
PR_PUBLIC_API(HT_Error) HT_SetSelectionRange (HT_Resource node1, HT_Resource node2);
PR_PUBLIC_API(HT_Resource) HT_GetNextSelection(HT_View view, HT_Resource startingNode);
PR_PUBLIC_API(void) HT_ToggleSelection(HT_Resource node);
PR_PUBLIC_API(PRBool) HT_IsEnabled (HT_Resource node);
PR_PUBLIC_API(HT_Error) HT_GetEnabledState (HT_Resource node, PRBool *enabledState);
PR_PUBLIC_API(HT_Error) HT_SetEnabledState(HT_Resource node, PRBool isEnabled);
#ifdef XPCOM_XXX /* mwcontext dependency */
PR_PUBLIC_API(PRBool) HT_Launch(HT_Resource node, MWContext *context);
PR_PUBLIC_API(PRBool) HT_LaunchURL(HT_Pane pane, char *url, MWContext *context);
#endif
PR_PUBLIC_API(void) HT_TypeTo(HT_Pane pane, char *typed);
/*
* HT_NewCursor, HT_GetNextItem, HT_DeleteCursor
* Used to iterate over a container's children. Until the container has been
* opened at least once, you won't see any of the children.
*/
PR_PUBLIC_API(HT_Cursor) HT_NewCursor (HT_Resource node) ;
PR_PUBLIC_API(HT_Error) HT_DeleteCursor (HT_Cursor cursor) ;
PR_PUBLIC_API(HT_Resource) HT_GetNextItem (HT_Cursor cursor) ;
/*
* HT_IsContainerOpen / HT_GetOpenState / HT_SetOpenState
* manage open state of a node; get/set operations will generate
* a HT_EVENT_NODE_OPENCLOSE_CHANGED notification unless masked out
*/
PR_PUBLIC_API(PRBool) HT_IsContainerOpen (HT_Resource node);
PR_PUBLIC_API(HT_Error) HT_GetOpenState (HT_Resource containerNode, PRBool *openState);
PR_PUBLIC_API(HT_Error) HT_SetOpenState (HT_Resource containerNode, PRBool isOpen);
PR_PUBLIC_API(HT_Error) HT_SetAutoFlushOpenState (HT_Resource containerNode, PRBool isOpen);
/*
* HT_ItemHasForwardSibling / HT_ItemHasBackwardSibling
* determine if a given node has a following/previous sibling node
*/
PR_PUBLIC_API(PRBool) HT_ItemHasForwardSibling(HT_Resource r);
PR_PUBLIC_API(PRBool) HT_ItemHasBackwardSibling(HT_Resource r);
PR_PUBLIC_API(void) HT_NewWorkspace(HT_Pane pane, char *id, char *optionalTitle);
PR_PUBLIC_API(void) HT_SetWorkspaceOrder(HT_View src, HT_View dest, PRBool afterDestFlag);
/*-----------------------------------------------------------------------*/
/* Creating new containers */
/*-----------------------------------------------------------------------*/
PR_PUBLIC_API(HT_Resource) HT_MakeNewContainer(HT_Resource parent, char* name);
/*-----------------------------------------------------------------------*/
/* Drag and Drop */
/* drop actions should be made an enum */
/*-----------------------------------------------------------------------*/
typedef uint8 HT_DropAction;
#define DROP_NOT_ALLOWED 0
#define COPY_MOVE_CONTENT 1
#define UPLOAD_RDF 2
#define COPY_MOVE_LINK 3
#define UPLOAD_LFS 4
#define DROP_ABORTED 5
PR_PUBLIC_API(HT_DropAction) HT_CanDropHTROn(HT_Resource dropTarget, HT_Resource obj);
PR_PUBLIC_API(HT_DropAction) HT_CanDropURLOn(HT_Resource dropTarget, char* url);
PR_PUBLIC_API(HT_DropAction) HT_DropHTROn(HT_Resource dropTarget, HT_Resource obj);
PR_PUBLIC_API(HT_DropAction) HT_DropURLOn(HT_Resource dropTarget, char* url);
PR_PUBLIC_API(HT_DropAction) HT_DropURLAndTitleOn(HT_Resource dropTarget,
char* url, char *title);
PR_PUBLIC_API(HT_DropAction) HT_CanDropHTRAtPos(HT_Resource dropTarget, HT_Resource obj,
PRBool before);
PR_PUBLIC_API(HT_DropAction) HT_CanDropURLAtPos(HT_Resource dropTarget, char* url,
PRBool before);
PR_PUBLIC_API(HT_DropAction) HT_DropHTRAtPos(HT_Resource dropTarget, HT_Resource obj,
PRBool before);
PR_PUBLIC_API(HT_DropAction) HT_DropURLAtPos(HT_Resource dropTarget, char* url,
PRBool before);
PR_PUBLIC_API(HT_DropAction) HT_DropURLAndTitleAtPos(HT_Resource dropTarget,
char* url, char *title, PRBool before);
PR_PUBLIC_API(PRBool) HT_IsDropTarget(HT_Resource dropTarget);
/*-----------------------------------------------------------------------*/
/* Editing */
/*-----------------------------------------------------------------------*/
PR_PUBLIC_API(PRBool) HT_RemoveChild (HT_Resource parent, HT_Resource child);
/*-----------------------------------------------------------------------*/
/* Other */
/*-----------------------------------------------------------------------*/
PR_PUBLIC_API(RDF) RDF_GetNavCenterDB();
PR_PUBLIC_API(void) HT_InformRDFOfNewDocument(char* address);
PR_PUBLIC_API(PRBool) HT_HasHTMLPane(HT_View htView);
PR_PUBLIC_API(char *) HT_HTMLPaneHeight(HT_View htView);
PR_PUBLIC_API(void) HT_AddSitemapFor(HT_Pane htPane, char *pUrl, char *pSitemapUrl, char* name);
PR_PUBLIC_API(void) HT_AddRelatedLinksFor(HT_Pane htPane, char *pUrl);
PR_PUBLIC_API(void) HT_ExitPage(HT_Pane htPane, char *pUrl);
PR_PUBLIC_API(void)
RDF_AddCookieResource(char* name, char* path, char* host, char* expires, char* value,
PRBool isDomain, PRBool secure) ;
NSPR_END_EXTERN_C
#endif /* htrdf_h___ */

View File

@@ -0,0 +1,75 @@
/* -*- 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 _JSEC_2_RDF_H_
#define _JSEC_2_RDF_H_
#include "rdf.h"
typedef int16 JSec_Error;
#define JSec_OK ((JSec_Error)0x0000)
#define JSec_NullObject ((JSec_Error)0x0001)
typedef RDF_Resource JSec_Principal;
typedef RDF_Resource JSec_PrincipalUse;
typedef RDF_Resource JSec_Target;
NSPR_BEGIN_EXTERN_C
PR_EXTERN(char*) RDFJSec_GetPrincipalURLString(char *principalID);
PR_EXTERN(const char*) RDFJSec_PrincipalUseID(JSec_PrincipalUse prUse);
PR_EXTERN(JSec_Error) RDFJSec_InitPrivilegeDB(); /* just use gNCDB */
PR_EXTERN(JSec_Error) RDFJSec_SavePrivilegeDB();
PR_EXTERN(JSec_Error) RDFJSec_ClosePrivilegeDB();
PR_EXTERN(RDF_Cursor) RDFJSec_ListAllPrincipals();
PR_EXTERN(JSec_Principal) RDFJSec_NextPrincipal(RDF_Cursor c);
PR_EXTERN(JSec_Error) RDFJSec_ReleaseCursor(RDF_Cursor c);
PR_EXTERN(JSec_Principal) RDFJSec_NewPrincipal(char* principalID);
PR_EXTERN(JSec_Error) RDFJSec_AddPrincipal(JSec_Principal pr);
PR_EXTERN(JSec_Error) RDFJSec_DeletePrincipal(JSec_Principal pr);
PR_EXTERN(char*) RDFJSec_PrincipalID(JSec_Principal pr);
PR_EXTERN(void*) RDFJSec_AttributeOfPrincipal(JSec_Principal pr, char* attributeType);
PR_EXTERN(JSec_Error) RDFJSec_SetPrincipalAttribute(JSec_Principal pr, char* attributeType, void* attValue);
PR_EXTERN(RDF_Cursor) RDFJSec_ListAllPrincipalUses(JSec_Principal pr);
PR_EXTERN(JSec_PrincipalUse) RDFJSec_NextPrincipalUse(RDF_Cursor c);
PR_EXTERN(JSec_PrincipalUse) RDFJSec_NewPrincipalUse(JSec_Principal pr, JSec_Target tr, char* priv);
PR_EXTERN(JSec_Error) RDFJSec_AddPrincipalUse(JSec_Principal pr, JSec_PrincipalUse prUse);
PR_EXTERN(JSec_Error) RDFJSec_DeletePrincipalUse (JSec_Principal pr, JSec_PrincipalUse prUse);
PR_EXTERN(JSec_Error) RDFJSec_AddPrincipalUsePrivilege (JSec_PrincipalUse prUse, char* priv);
PR_EXTERN(JSec_Error) RDFJSec_DeletePrincipalUsePrivilege (JSec_PrincipalUse prUse, char* priv);
PR_EXTERN(char*) RDFJSec_PrivilegeOfPrincipalUse (JSec_PrincipalUse p);
PR_EXTERN(JSec_Error) RDFJSec_AddTargetToPrincipalUse(JSec_PrincipalUse prUse, JSec_Target tr);
PR_EXTERN(JSec_Error) RDFJSec_DeleteTargetToPrincipalUse(JSec_PrincipalUse prUse, JSec_Target tr);
PR_EXTERN(JSec_Target) RDFJSec_TargetOfPrincipalUse (JSec_PrincipalUse p);
PR_EXTERN(JSec_Target) RDFJSec_NewTarget(char* targetName, JSec_Principal pr);
PR_EXTERN(char*) RDFJSec_GetTargetName(JSec_Target tr);
PR_EXTERN(char*) RDFJSec_AttributeOfTarget(JSec_Target tr, char* attributeType);
PR_EXTERN(JSec_Error) RDFJSec_SetTargetAttribute(JSec_Target tr, char* attributeType, char* attValue);
NSPR_END_EXTERN_C
#endif /* _JSEC_2_RDF_H_ */

View File

@@ -0,0 +1,37 @@
#!gmake
#
# 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.
MODULE = rdf
DEPTH = ..\..\..
EXPORTS = rdf.h \
rdfc.h \
nsIRDFService.h \
nsIRDFDataSource.h \
nsIRDFDataBase.h \
nsIRDFObserver.h \
nsIRDFCursor.h \
htrdf.h \
vocab.h \
jsec2rdf.h \
$(NULL)
include <$(DEPTH)/config/rules.mak>

View File

@@ -0,0 +1,53 @@
/* -*- 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 nsIRDFCursor_h__
#define nsIRDFCursor_h__
/*
nsIRDFCursor:
An iterator for RDF data sources.
*/
#include "nsISupports.h"
#include "rdf.h"
// 1c2abdb0-4cef-11d2-bc16-00805f912fe7
#define NS_IRDFCURSOR_IID \
{ \
0x1c2abdb0, \
0x4cef, \
0x11d2, \
{ 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } \
}
class nsIRDFCursor : public nsISupports {
public:
NS_IMETHOD HasElements(PRBool& hasElements) = 0;
NS_IMETHOD Next(RDF_NodeStruct& next /* in/out */) = 0;
};
#endif /* nsIRDFCursor_h__ */

View File

@@ -0,0 +1,74 @@
/* -*- 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 nsIRDFDataBase_h__
#define nsIRDFDataBase_h__
/*
This file contains the interface definition for an RDF database.
RDF databases aggregate RDF data sources (see nsIRDFDataSource.h)
*/
#include "nsISupports.h"
#include "nsIRDFDataSource.h"
#include "rdf.h"
// 96343820-307c-11d2-bc15-00805f912fe7
#define NS_IRDFDATABASE_IID \
{ \
0x96343820, \
0x307c, \
0x11d2, \
{ 0xb, 0xc15, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } \
}
class nsIRDFDataBase : public nsIRDFDataSource {
public:
#ifdef RDF_NOT_IMPLEMENTED
NS_IMETHOD Initialize(nsIRDFResourceManager* r) = 0;
#endif
#ifdef RDF_NOT_IMPLEMENTED
/*
Add a data source for the specified URL to the database.
Parameters:
dataSource -- a ptr to the data source to add
Returns:
*/
NS_IMETHOD AddDataSource(nsIRDFDataSource* dataSource) = 0;
NS_IMETHOD RemoveDataSource(nsIRDFDataSource* dataSource) = 0;
NS_IMETHOD GetDataSource(RDF_String url,
nsIRDFDataSource **source /* out */ ) = 0;
#endif
// XXX move these to datasource?
NS_IMETHOD DeleteAllArcs(RDF_Resource resource) = 0;
};
#endif /* nsIRDFDataBase_h__ */

View File

@@ -0,0 +1,223 @@
/* -*- 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 nsIRDFDataSource_h__
#define nsIRDFDataSource_h__
/*
This file contains the interface definition for an RDF data source.
Classes which implement this interface for a particular type of URL
are registered with the RDF singleton via nsIRDF::RegisterHandler(...)
*/
#include "nsISupports.h"
#include "rdf.h"
// 852666b0-2cce-11d2-bc14-00805f912fe7
#define NS_IRDFDATASOURCE_IID \
{ \
0x852666b0, \
0x2cce, \
0x11d2, \
{ 0xb, 0xc14,0x00, 0x80, 0x5f, 0x91 0x2f, 0xe7 } \
}
class nsIRDFCursor;
class nsIRDFObserver;
class nsIRDFDataBase;
class nsIRDFDataSource : public nsISupports {
public:
#ifdef RDF_NOT_IMPLEMENTED
/**
* Initialize this data source
*/
NS_IMETHOD Initialize(RDF_String url,
nsIRDFResourceManager* m);
#endif
/**
* Get the name of this data source.
*
* For regular data sources, this will be the URL of the source.
*
* For aggregated sources, it generally will not be a valid RDF URL.
*/
NS_IMETHOD GetName(const RDF_String* name /* out */ ) = 0;
/**
* Find an RDF resource that points to a given node over the
* specified arc & truth value (defaults to "PR_TRUE").
*/
NS_IMETHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
RDF_Resource *source /* out */) = 0;
NS_IMETHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
RDF_Resource *source /* out */) = 0;
/**
* 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,
RDF_Resource arcLabel,
nsIRDFCursor **sources /* out */) = 0;
NS_IMETHOD GetSources(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
nsIRDFCursor **sources /* out */) = 0;
/**
* Find a child of that is related to the source by the given arc
* arc and truth value (defaults to PR_TRUE).
*/
NS_IMETHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
RDF_NodeStruct& target /* in/out */) = 0;
NS_IMETHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
PRBool tv,
RDF_NodeStruct& target /* in/out */) = 0;
/**
* Find all children of that are related to the source by the given arc
* arc and truth value (defaults to PR_TRUE).
*/
NS_IMETHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */) = 0;
NS_IMETHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
PRBool tv,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */) = 0;
#ifdef RDF_NOT_IMPLEMENTED
/**
* Find all parents that point to a node over a given arc label,
* regardless of truth value.
*/
NS_IMETHOD GetAllSources(RDF_Node target,
RDF_Resource arcLabel,
nsIRDFCursor2 **sources /* out */) = 0;
/**
* Find all children of a resource that are related by the
* given arc label, regardless of the truth value.
*/
NS_IMETHOD GetAllTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor2 **targets /* out */);
#endif /* RDF_NOT_IMPLEMENTED */
/**
* Add an assertion to the graph.
*/
NS_IMETHOD Assert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv = PR_TRUE) = 0;
/**
* Remove an assertion from the graph.
*/
NS_IMETHOD Unassert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target) = 0;
/**
* Query whether an assertion exists in this graph.
*
*/
NS_IMETHOD HasAssertion(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool truthValue,
PRBool* hasAssertion /* out */) = 0;
/**
* Add an observer to this data source.
*/
NS_IMETHOD AddObserver(nsIRDFObserver *n,
RDF_EventMask type = RDF_ANY_NOTIFY) = 0;
/**
* Remove an observer from this data source
*/
NS_IMETHOD RemoveObserver(nsIRDFObserver *n,
RDF_EventMask = RDF_ANY_NOTIFY) = 0;
/**
* Get a cursor to iterate over all the arcs that point into a node.
*/
NS_IMETHOD ArcLabelsIn(RDF_Node node,
nsIRDFCursor **labels /* out */) = 0;
/**
* Get a cursor to iterate over all the arcs that originate in
* a resource.
*/
NS_IMETHOD ArcLabelsOut(RDF_Resource source,
nsIRDFCursor **labels /* out */) = 0;
#ifdef RDF_NOT_IMPLEMENTED
/**
* Notify this data source that it is a child of a database.
*
* The datasource must send notifications to the parent when
* changes to it's graph are made, in case the parent has observers
* interested in the events generated.
*/
NS_IMETHOD AddParent(nsIRDFDataBase* parent) = 0;
/**
* Notify this data source that it has been disconnected from a
* parent.
*/
NS_IMETHOD RemoveParent(nsIRDFDataBase* parent) = 0;
/**
* Request that a data source obtain updates if applicable.
*/
// XXX move this to an nsIRDFRemoteDataStore interface?
NS_IMETHOD Update(RDF_Resource hint) = 0;
#endif /* RDF_NOT_IMPLEMENTED */
/**
* Request that a data source write it's contents out to
* permanent storage if applicable.
*/
NS_IMETHOD Flush() = 0;
};
#endif /* nsIRDFDataSource_h__ */

View File

@@ -0,0 +1,51 @@
/* -*- 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 nsIRDFObserver_h__
#define nsIRDFObserver_h__
/*
This file defines the interface for RDF observers.
*/
#include "nsISupports.h"
#include "rdf.h"
// 3cc75360-484a-11d2-bc16-00805f912fe7
#define NS_IRDFOBSERVER_IID \
{ \
0x3cc75360, \
0x484a, \
0x11d2, \
{ 0xbc, 0x16, 0x00, 0x80, 0x5f, 0x91, 0x2f, 0xe7 } \
}
class nsIRDFDataSource;
class nsIRDFObserver : public nsISupports
{
public:
NS_IMETHOD HandleEvent(nsIRDFDataSource *source,
RDF_Event event) = 0;
};
#endif /* nsIRDFObserver_h__ */

View File

@@ -0,0 +1,68 @@
/* -*- 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 nsIRDFService_h__
#define nsIRDFService_h__
/*
This file defines the interface for the RDF singleton,
which maintains various pieces of pieces of information global
to all RDF data sources.
In particular, it provides the interface for mapping rdf URL types
to nsIRDFDataSource implementors for that type of content.
*/
#include "nsISupports.h"
#include "nsIFactory.h" /* nsCID typedef, for consistency */
#include "rdf.h"
class nsIRDFDataSource;
class nsIRDFDataBase;
// 6edf3660-32f0-11d2-9abe-00600866748f
#define NS_IRDFSERVICE_IID \
{ \
0x6edf3660, \
0x32f0, \
0x11d2, \
{ 0x9a, 0xbe, 0x00, 0x60, 0x08, 0x66, 0x74, 0x8f } \
}
class nsIRDFService : public nsISupports {
public:
NS_IMETHOD Initialize();
#ifdef RDF_NOT_IMPLEMENTED
NS_IMETHOD RegisterHandler(RDF_String url_selector, const nsCID& clsid) = 0;
NS_IMETHOD RemoveHandler(RDF_String url_selector, const nsCID& clsid) = 0;
NS_IMETHOD CreateDataSource(RDF_String url,
nsIRDFDataSource **source /* out */) = 0;
#endif /* RDF_NOT_IMPLEMENTED */
NS_IMETHOD CreateDatabase(const RDF_String* url_ary,
nsIRDFDataBase **db /* out */) = 0;
};
#endif /* nsIRDFService_h__ */

View File

@@ -0,0 +1,120 @@
/* -*- 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_h___
#define rdf_h___
#include "nspr.h"
#include "nsError.h"
typedef nsresult RDF_Error;
#define RDF_ERROR_ILLEGAL_ASSERT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF,1)
#define RDF_ERROR_ILLEGAL_KILL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF,2)
#define RDF_ERROR_UNABLE_TO_CREATE NS_ERROR_GENERATE_FAILURE( NS_ERROR_MODULE_RDF,3)
#define RDF_ERROR_NO_MEMORY NS_ERROR_OUT_OF_MEMORY /* XXX remove this */
NSPR_BEGIN_EXTERN_C
typedef struct RDF_ResourceStruct* RDF_Resource;
typedef struct RDF_CursorStruct* RDF_Cursor;
typedef struct RDF_DBStruct* RDF;
typedef struct RDF_TranslatorStruct *RDFT;
typedef char* RDF_String;
typedef enum {
RDF_ANY_TYPE,
RDF_RESOURCE_TYPE,
RDF_INT_TYPE,
RDF_STRING_TYPE,
#ifdef RDF_BLOB
RDF_BLOB_TYPE
#endif
} RDF_ValueType;
#ifdef RDF_BLOB
typedef struct RDF_BlobStruct {
PRUint32 size;
void* data;
} *RDF_Blob;
#endif
typedef struct RDF_NodeStruct {
RDF_ValueType type;
union {
RDF_Resource r;
RDF_String s;
#ifdef RDF_BLOB
RDF_Blob b;
#endif
} value;
} *RDF_Node;
typedef PRUint32 RDF_EventType;
#define RDF_ASSERT_NOTIFY ((RDF_EventType)0x00000001)
#define RDF_DELETE_NOTIFY ((RDF_EventType)0x00000002)
#define RDF_KILL_NOTIFY ((RDF_EventType)0x00000004)
#define RDF_CREATE_NOTIFY ((RDF_EventType)0x00000008)
#define RDF_RESOURCE_GC_NOTIFY ((RDF_EventType)0x00000010)
#define RDF_INSERT_NOTIFY ((RDF_EventType)0x00000020)
typedef PRUint32 RDF_EventMask;
#define RDF_ANY_NOTIFY ((RDF_EventMask)0xFFFFFFFF)
typedef struct RDF_AssertEventStruct {
RDF_Resource u;
RDF_Resource s;
void* v;
RDF_ValueType type;
PRBool tv;
char* dataSource;
} *RDF_AssertEvent;
typedef struct RDF_UnassertEventStruct {
RDF_Resource u;
RDF_Resource s;
void* v;
RDF_ValueType type;
char* dataSource;
} *RDF_UnassertEvent;
typedef struct RDF_KillEventStruct {
RDF_Resource u;
} *RDF_KillEvent;
typedef struct RDF_EventStruct {
RDF_EventType eventType;
union ev {
struct RDF_AssertEventStruct assert;
struct RDF_UnassertEventStruct unassert;
struct RDF_KillEventStruct kill;
} event;
} *RDF_Event;
#include "vocab.h"
#include "rdfc.h"
NSPR_END_EXTERN_C
#endif /* rdf_h___ */

View File

@@ -0,0 +1,106 @@
/* -*- 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_h___
#define rdf_h___
#include "nspr.h"
#include "nsError.h"
typedef nsresult RDF_Error;
#define RDF_ERROR_ILLEGAL_ASSERT NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF,1)
#define RDF_ERROR_ILLEGAL_KILL NS_ERROR_GENERATE_FAILURE(NS_ERROR_MODULE_RDF,2)
NSPR_BEGIN_EXTERN_C
typedef struct RDF_ResourceStruct* RDF_Resource;
typedef struct RDF_CursorStruct* RDF_Cursor;
typedef struct RDF_DBStruct* RDF;
typedef struct RDF_TranslatorStruct *RDFT;
typedef enum {
RDF_ANY_TYPE,
RDF_RESOURCE_TYPE,
RDF_INT_TYPE,
RDF_STRING_TYPE.
#ifdef RDF_BLOB
RDF_BLOB_TYPE
#endif
} RDF_ValueType;
#ifdef RDF_BLOB
typedef struct RDF_BlobStruct {
PRUint32 size;
void* data;
} *RDF_Blob;
#endif
typedef struct RDF_NodeStruct {
RDF_ValueType type;
union {
RDF_Resource r;
RDF_String s;
#ifdef RDF_BLOB
RDF_Blob b;
#endif
} value;
} *RDF_Node;
typedef PRUint32 RDF_EventType;
#define RDF_ASSERT_NOTIFY ((RDF_EventType)0x00000001)
#define RDF_DELETE_NOTIFY ((RDF_EventType)0x00000002)
typedef PRUint32 RDF_EventMask;
#define RDF_ANY_NOTIFY ((RDF_EventMask)0xFFFFFFFF)
typedef struct RDF_AssertEventStruct {
RDF_Resource u;
RDF_Resource s;
struct RDF_NodeStruct v;
PRBool tv;
char* dataSource;
} *RDF_AssertEvent;
typedef struct RDF_UnassertEventStruct {
RDF_Resource u;
RDF_Resource s;
struct RDF_NodeStruct v;
char* dataSource;
} *RDF_UnassertEvent;
typedef struct RDF_KillEventStruct {
RDF_Resource u;
} *RDF_KillEvent;
typedef struct RDF_EventStruct {
RDF_EventType eventType;
union ev {
struct RDF_AssertEventStruct assert;
struct RDF_UnassertEventStruct unassert;
struct RDF_KillEventStruct kill;
} event;
} *RDF_Event;
#include "vocab.h"
NSPR_END_EXTERN_C
#endif /* rdf_h___ */

View File

@@ -0,0 +1,128 @@
/* -*- 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 rdfc_h__
#define rdfc_h__
#include "rdf.h"
#include "nspr.h"
/* core rdf apis */
NSPR_BEGIN_EXTERN_C
typedef struct _RDF_InitParamsStruct {
char *profileURL;
char *bookmarksURL;
char *globalHistoryURL;
} RDF_InitParamsStruct;
typedef struct _RDF_InitParamsStruct* RDF_InitParams;
struct RDF_NotificationStruct;
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_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);
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(RDF_Notification) RDF_AddNotifiable (RDF rdfDB, RDF_NotificationProc callBack, RDF_Event ev, void* pdata);
PR_PUBLIC_API(RDF_Error) RDF_DeleteNotifiable (RDF_Notification ns);
PR_PUBLIC_API(PRBool) RDF_Assert(RDF rdfDB, RDF_Resource source, RDF_Resource arcLabel,
void* target, RDF_ValueType targetType);
PR_PUBLIC_API(PRBool) RDF_AssertFalse(RDF rdfDB, RDF_Resource source, RDF_Resource arcLabel,
void* target, RDF_ValueType targetType);
PR_PUBLIC_API(PRBool) RDF_Unassert(RDF rdfDB, RDF_Resource source, RDF_Resource arcLabel,
void* target, RDF_ValueType targetType);
PR_PUBLIC_API(PRBool) RDF_CanAssert(RDF rdfDB, RDF_Resource u, RDF_Resource arcLabel, void* v, RDF_ValueType targetType);
PR_PUBLIC_API(PRBool) RDF_CanAssertFalse(RDF rdfDB, RDF_Resource u, RDF_Resource arcLabel, void* v, RDF_ValueType targetType);
PR_PUBLIC_API(PRBool) RDF_CanUnassert(RDF rdfDB, RDF_Resource u, RDF_Resource arcLabel, void* v, RDF_ValueType targetType);
PR_PUBLIC_API(PRBool) RDF_HasAssertion (RDF rdfDB, RDF_Resource source, RDF_Resource arcLabel,
void* target, RDF_ValueType targetType, PRBool tv);
PR_PUBLIC_API(void*) RDF_GetSlotValue (RDF rdfDB, RDF_Resource u, RDF_Resource s, RDF_ValueType targetType,
PRBool inversep, PRBool tv);
PR_PUBLIC_API(RDF_Cursor) RDF_GetTargets (RDF rdfDB, RDF_Resource source, RDF_Resource arcLabel,
RDF_ValueType targetType, PRBool tv);
PR_PUBLIC_API(RDF_Cursor) RDF_GetSources (RDF rdfDB, RDF_Resource target, RDF_Resource arcLabel,
RDF_ValueType sourceType, PRBool tv);
PR_PUBLIC_API(RDF_Cursor) RDF_ArcLabelsOut (RDF rdfDB, RDF_Resource u);
PR_PUBLIC_API(RDF_Cursor) RDF_ArcLabelsIn (RDF rdfDB, RDF_Resource u);
PR_PUBLIC_API(void*) RDF_NextValue(RDF_Cursor c);
PR_PUBLIC_API(char*) RDF_ValueDataSource(RDF_Cursor c);
PR_PUBLIC_API(RDF_ValueType) RDF_CursorValueType(RDF_Cursor c);
PR_PUBLIC_API(RDF_Error) RDF_DisposeCursor (RDF_Cursor c);
/*** Guha needs to get his act together and figure out how to do this.
PR_PUBLIC_API(RDF_Error) RDF_Undo(RDF rdf);
***/
/* These two should be removed soon. They are here because Nav Center
depends on them. */
/* PR_PUBLIC_API(RDF_Error) RDF_Init(char *profileDirURL); */
PR_PUBLIC_API(RDF_Error) RDF_Init(RDF_InitParams params);
PR_PUBLIC_API(RDF_Error) RDF_Shutdown(void);
/* the stuff in vocab.h will supercede whats below. I am leaving this here
only for the very near future */
/** utilities : move out of here!!! **/
/* well known resources */
PR_PUBLIC_API(char*) RDF_GetResourceName(RDF rdfDB, RDF_Resource node);
PR_PUBLIC_API(RDF_Resource) RDFUtil_GetFirstInstance (RDF_Resource type, char* defaultURL);
PR_PUBLIC_API(void) RDFUtil_SetFirstInstance (RDF_Resource type, RDF_Resource item);
typedef void (*printProc)(void* data, char* str);
PR_PUBLIC_API(void) outputMCFTree (RDF db, printProc printer, void* data, RDF_Resource node);
PR_PUBLIC_API(RDF_Resource) RDFUtil_GetBreadcrumb();
PR_PUBLIC_API(RDF_Resource) RDFUtil_GetQuickFileFolder();
PR_PUBLIC_API(void) RDFUtil_SetQuickFileFolder(RDF_Resource container);
PR_PUBLIC_API(RDF_Resource) RDFUtil_GetPTFolder();
PR_PUBLIC_API(void) RDFUtil_SetPTFolder(RDF_Resource container);
PR_PUBLIC_API(RDF_Cursor) RDF_Find (RDF_Resource s, RDF_Resource match, void* v, RDF_ValueType type);
PR_PUBLIC_API(RDF_Resource) RDFUtil_GetNewBookmarkFolder();
PR_PUBLIC_API(void) RDFUtil_SetNewBookmarkFolder(RDF_Resource container);
PR_PUBLIC_API(RDF_Resource) RDFUtil_GetDefaultSelectedView();
PR_PUBLIC_API(void) RDFUtil_SetDefaultSelectedView(RDF_Resource container);
/** end utilities **/
/* this stuff is stuck in here for netlib */
NSPR_END_EXTERN_C
#endif /* rdfc_h__ */

View File

@@ -0,0 +1,229 @@
/* -*- 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_VOCAB_H_
#define _RDF_VOCAB_H_
typedef struct _RDF_CoreVocabStruct {
RDF_Resource RDF_parent;
RDF_Resource RDF_name;
RDF_Resource RDF_instanceOf;
RDF_Resource RDF_subClassOf;
RDF_Resource RDF_PropertyType;
RDF_Resource RDF_Class;
RDF_Resource RDF_slotsHere;
RDF_Resource RDF_slotsIn;
RDF_Resource RDF_domain;
RDF_Resource RDF_range;
RDF_Resource RDF_StringType;
RDF_Resource RDF_IntType;
RDF_Resource RDF_equals;
RDF_Resource RDF_lessThan;
RDF_Resource RDF_greaterThan;
RDF_Resource RDF_lessThanOrEqual;
RDF_Resource RDF_greaterThanOrEqual;
RDF_Resource RDF_stringEquals;
RDF_Resource RDF_stringNotEquals;
RDF_Resource RDF_substring;
RDF_Resource RDF_stringStartsWith;
RDF_Resource RDF_stringEndsWith;
RDF_Resource RDF_child;
RDF_Resource RDF_comment;
RDF_Resource RDF_content;
RDF_Resource RDF_summary;
} RDF_CoreVocabStruct;
typedef RDF_CoreVocabStruct* RDF_CoreVocab;
typedef struct _RDF_NCVocabStruct {
RDF_Resource RDF_overview;
RDF_Resource RDF_Trash;
RDF_Resource RDF_Clipboard;
RDF_Resource RDF_Top;
RDF_Resource RDF_Search;
RDF_Resource RDF_Sitemaps;
RDF_Resource RDF_BreadCrumbCategory;
RDF_Resource RDF_BookmarkFolderCategory;
RDF_Resource RDF_NewBookmarkFolderCategory;
RDF_Resource RDF_History;
RDF_Resource RDF_HistoryBySite;
RDF_Resource RDF_HistoryByDate;
RDF_Resource RDF_HistoryMostVisited;
/* IE items */
RDF_Resource RDF_IEBookmarkFolderCategory;
RDF_Resource RDF_IEHistory;
RDF_Resource RDF_bookmarkAddDate;
RDF_Resource RDF_PersonalToolbarFolderCategory;
RDF_Resource RDF_Column;
RDF_Resource RDF_ColumnResource;
RDF_Resource RDF_ColumnWidth;
RDF_Resource RDF_ColumnIconURL;
RDF_Resource RDF_ColumnDataType;
RDF_Resource RDF_smallIcon; /* Small normal icon. */
RDF_Resource RDF_largeIcon; /* Large normal icon. */
RDF_Resource RDF_Guide;
RDF_Resource RDF_HTMLURL;
RDF_Resource RDF_HTMLHeight;
RDF_Resource RDF_LocalFiles;
RDF_Resource RDF_FTP;
RDF_Resource RDF_Appletalk;
RDF_Resource RDF_Mail;
RDF_Resource RDF_Password;
RDF_Resource RDF_SBProviders;
RDF_Resource RDF_WorkspacePos;
RDF_Resource RDF_ItemPos;
RDF_Resource RDF_Locks;
RDF_Resource RDF_AddLock;
RDF_Resource RDF_DeleteLock;
RDF_Resource RDF_IconLock;
RDF_Resource RDF_NameLock;
RDF_Resource RDF_CopyLock;
RDF_Resource RDF_MoveLock;
RDF_Resource RDF_WorkspacePosLock;
RDF_Resource RDF_DefaultSelectedView;
RDF_Resource RDF_AutoOpen;
RDF_Resource RDF_resultType;
RDF_Resource RDF_methodType;
RDF_Resource RDF_prompt;
RDF_Resource RDF_HTMLType;
RDF_Resource RDF_URLShortcut;
RDF_Resource RDF_Poll;
RDF_Resource RDF_PollInterval;
RDF_Resource RDF_PollURL;
RDF_Resource RDF_Cookies;
#ifdef TRANSACTION_RECEIPTS
RDF_Resource RDF_Receipts;
#endif
RDF_Resource RDF_Toolbar;
RDF_Resource RDF_JSec;
RDF_Resource RDF_JSecPrincipal;
RDF_Resource RDF_JSecTarget;
RDF_Resource RDF_JSecAccess;
/* Commands */
RDF_Resource RDF_Command;
RDF_Resource RDF_Command_Launch;
RDF_Resource RDF_Command_Refresh;
RDF_Resource RDF_Command_Reveal;
RDF_Resource RDF_Command_Atalk_FlatHierarchy;
RDF_Resource RDF_Command_Atalk_Hierarchy;
/* NavCenter appearance styles */
RDF_Resource viewFGColor;
RDF_Resource viewBGColor;
RDF_Resource viewBGURL;
RDF_Resource showTreeConnections;
RDF_Resource treeConnectionFGColor;
RDF_Resource treeOpenTriggerIconURL;
RDF_Resource treeClosedTriggerIconURL;
RDF_Resource selectionFGColor;
RDF_Resource selectionBGColor;
RDF_Resource columnHeaderFGColor;
RDF_Resource columnHeaderBGColor;
RDF_Resource columnHeaderBGURL;
RDF_Resource showColumnHeaders;
RDF_Resource showColumnHeaderDividers;
RDF_Resource showTitleBar; /* Whether or not to show the title bar at all */
RDF_Resource showControlStrip; /* Whether or not to show the control strip at all. */
RDF_Resource sortColumnFGColor;
RDF_Resource sortColumnBGColor;
RDF_Resource titleBarFGColor;
RDF_Resource titleBarBGColor;
RDF_Resource titleBarBGURL;
RDF_Resource titleBarShowText;
RDF_Resource dividerColor;
RDF_Resource showDivider;
RDF_Resource selectedColumnHeaderFGColor;
RDF_Resource selectedColumnHeaderBGColor;
RDF_Resource showColumnHilite;
RDF_Resource triggerPlacement;
/* NavCenter behavior flags */
RDF_Resource useInlineEditing;
RDF_Resource useSingleClick;
RDF_Resource loadOpenState;
RDF_Resource saveOpenState;
/* Toolbar Appearance Styles */
RDF_Resource toolbarBitmapPosition; /* Bitmap's position ("side"/"top") */
RDF_Resource toolbarDisplayMode;
RDF_Resource toolbarCollapsed;
RDF_Resource toolbarVisible;
RDF_Resource toolbarRolloverIcon; /* The icon to display on rollover. */
RDF_Resource toolbarPressedIcon; /* The icon to display on a press. */
RDF_Resource toolbarDisabledIcon; /* The icon to display when disabled. */
RDF_Resource toolbarEnabledIcon; /* THe icon to display when enabled. */
/* Cookie Stuff */
RDF_Resource cookieDomain;
RDF_Resource cookieValue;
RDF_Resource cookieHost;
RDF_Resource cookiePath;
RDF_Resource cookieSecure;
RDF_Resource cookieExpires;
RDF_Resource toolbarButtonsFixedSize; /* Whether or not the buttons must be the same size ("yes"/"no") */
RDF_Resource viewRolloverColor; /* What to display when an item is rolled over in a view.*/
RDF_Resource viewPressedColor; /* What to display when an item is pressed in a view. */
RDF_Resource viewDisabledColor; /* Color to use when item is disabled in a view. */
RDF_Resource urlBar; /* Whether or not the button is a URL bar. */
RDF_Resource urlBarWidth; /* The width of the URL bar. */
RDF_Resource buttonTreeState; /* The tree state (docked, popup) for a button. */
RDF_Resource buttonTooltipText; /* The tooltip text for a button. */
RDF_Resource buttonStatusbarText; /* The status bar text for a button. */
RDF_Resource buttonBorderStyle; /* What type of border the button should have. */
RDF_Resource controlStripFGColor; /* The tree's control strip foreground */
RDF_Resource controlStripBGColor; /* The tree's control strip background */
RDF_Resource controlStripBGURL; /* The tree's control strip BG URL */
RDF_Resource controlStripCloseText; /* The text displayed for the close function in the control strip. */
RDF_Resource pos;
RDF_Resource from;
RDF_Resource to;
RDF_Resource subject;
RDF_Resource date;
RDF_Resource displayURL;
} RDF_NCVocabStruct;
typedef RDF_NCVocabStruct* RDF_NCVocab;
typedef struct _RDF_WDVocabStruct {
RDF_Resource RDF_URL;
RDF_Resource RDF_description;
RDF_Resource RDF_keyword;
RDF_Resource RDF_Container;
RDF_Resource RDF_firstVisitDate;
RDF_Resource RDF_lastVisitDate;
RDF_Resource RDF_numAccesses;
RDF_Resource RDF_creationDate;
RDF_Resource RDF_lastModifiedDate;
RDF_Resource RDF_size;
} RDF_WDVocabStruct;
typedef RDF_WDVocabStruct* RDF_WDVocab;
#endif

View File

@@ -0,0 +1,27 @@
/* -*- 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.
*/
//
// RDFDebug.Prefix
//
// Global prefix file for the debug RDF project.
//
//
#include "MacPrefix_debug.h"
#include "RDFConfig.h"

View File

@@ -0,0 +1,193 @@
###
### Symbols you may have to hand annotate with #{code} or #{data}...
###
HT_CanDropHTROn
HT_CanDropURLOn
HT_DeleteCursor
HT_DeleteView
HT_DropHTROn
HT_DropURLOn
HT_GetNextItem
HT_GetNotificationMask
HT_GetNthItem
HT_GetNthItemInt
HT_GetOpenState
HT_GetParent
HT_GetRDFResource
HT_GetSelectedState
HT_GetView
HT_GetViewData
HT_IsContainer
HT_IsContainerOpen
HT_IsSelected
HT_KillResource
HT_MakeNewContainer
HT_NewCursor
HT_NewView
HT_NodeDisplayString
HT_RemoveChild
HT_SetNotificationMask
HT_SetOpenState
HT_SetSelectedState
HT_SetViewData
HT_TopNode
HT_WriteOutAsBookmarks
RDF_AddNotifiable
RDF_Assert
RDF_CanAssert
RDF_CanUnassert
RDF_Create
RDF_DeleteNotifiable
RDF_DisposeCursor
RDF_GetSlotValue
RDF_GetSlotValues
RDF_HasAssertion
RDF_Init
RDF_InitLocalStores
RDF_Kill
RDF_NextValue
RDF_SaveState
RDF_SetResourceLock
RDF_Shutdown
RDF_StdVocab
RDF_Unassert
RDF_AddCookieResource
# RDFglueExit
# RDFglueInitialize
# __initialize
# __ptmf_null
# __terminate
# abortRDFParse
# addChildAfter
# addChildBefore
# addDescription
# addNotifiable
# addSlotValue
# addToAssertionList
# addToResourceList
# append2Strings
# asEqual
# asTv
# asType
# assert
# assignHeaderSlot
# assignSlot
# beginReadingRDFFile
# bkStateTransition
# bookmarkSlotp
# charSearch
# containerIDp
# containerp
# copyString
# createBootstrapResources
# createContainer
# createSeparator
# deleteNotifiable
# derelativizeURL
# destroyViewInt
# disposeCursor
# endsWith
# exitRDF
# fillContainer
# finishRDFParse
# freeAssertion
# freeMem
# gBookmarkURL
# gLocalStoreURL
# gRDFDB
# gcRDFFile
# getElfProp
# getFirstToken
# getHash
# getMem
# getRDFDB
# getRelURL
# getSlotValue
# getSlotValues
# globals
# hasAssertion
# hashIndex
# ht_fprintf
# htrdfNotifFunc
# idenEqual
# idenHash
# initDataSources
# initLocalStore
# inverseTV
# isContainer
# isLeaf
# isSeparator
# isTypeOf
# killResource
# localStoreAdd
# localStoreAssert
# localStoreDisposeCursor
# localStoreGetSlotValue
# localStoreGetSlotValues
# localStoreHasAssertion
# localStoreNextValue
# localStoreRemove
# localStoreUnassert
# lockedp
# longjmp
# makeNewAssertion
# makeNewID
# makeNewRDFDB
# makeRDFFile
# newFolderBkItem
# newHTEntry
# newHashtable
# newLeafBkItem
# nextValue
# outputRDFTree
# outputRDFTreeInt
# parseNextBkBlob
# parseNextBkToken
# parseNextMCFBlob
# parseNextRDFBlob
# parseNextRDFLine
# parseNextRDFToken
# parseNextRDFXMLBlob
# parseRDFElement
# parseSlotValue
# possiblyGCResource
# putHash
# rdfDB
# rdfDBInited
# readRDFFile
# remHash
# remoteAssert
# remoteStoreAdd
# remoteStoreDisposeCursor
# remoteStoreGetSlotValue
# remoteStoreGetSlotValues
# remoteStoreHasAssertion
# remoteStoreNextValue
# remoteStoreRemove
# remoteUnassert
# resolveGenlPosReference
# resolveReference
# resourceDescription
# resourceFromID
# resourceLastModifiedDate
# resourceLastVisitDate
# resourceName
# resourceTransition
# revCharSearch
# saveLocalStore
# sendNotification
# sendNotifications
# separatorCounter
# setAsTv
# setAsType
# setContainerp
# setHiddenState
# setLockedp
# startsWith
# stringAppend
# stringEquals
# translators
# unassert
# urlEquals
# writeResource

Binary file not shown.

View File

@@ -0,0 +1,18 @@
/* -*- 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.
*/
#define CGLUESUPPORTED 0 // turn off C glue support to avoid conflict on create() in RDF

View File

@@ -0,0 +1,27 @@
/* -*- 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.
*/
//
// RDFDebug.Prefix
//
// Global prefix file for the debug RDF project.
//
//
#include "MacPrefix_debug.h"
#include "RDFConfig.h"

View File

@@ -0,0 +1,29 @@
/* -*- 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.
*/
//
// RDFDebug.Prefix
//
// Global prefix file for the debug RDF project.
//
//
#define MOZ_LITE 1
#define DEVELOPER_DEBUG 1
#include "RDFConfig.h"
#include <OpenTransport.h>

View File

@@ -0,0 +1,30 @@
/* -*- 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.
*/
//
// RDFDebug.Prefix
//
// Global prefix file for the debug RDF project.
//
//
#define MOZ_LITE 1
#define DEBUG 1
#define DEVELOPER_DEBUG 1
#include "RDFConfig.h"
#include <OpenTransport.h>

View File

@@ -0,0 +1,9 @@
DEPTH=..\..
DIRS=\
include \
src \
$(NULL)
include <$(DEPTH)\config\rules.mak>

View File

@@ -0,0 +1,46 @@
#!gmake
#
# 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.
#
#
#
DEPTH = ../../..
MODULE = rdf
LIBRARY_NAME = $(LITE_PREFIX)rdf
LIBXP = $(DIST)/lib/libxp.$(LIB_SUFFIX)
REQUIRES = nspr
JNI_GEN = netscape.rdf.core.NativeRDF netscape.rdf.core.NativeRDFEnumeration
CSRCS = \
vocab.c \
mcf.c \
remstore.c \
utils.c \
rdfparse.c \
bmk2mcf.c \
rdfht.c \
columns.c \
$(NULL)
LOCAL_INCLUDES = -I$(PUBLIC)/rdf
include $(DEPTH)/config/rules.mk
$(LIBRARY): $(OBJS)

View File

@@ -0,0 +1,87 @@
#!gmake
#
# 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.
#
#
#
DEPTH = ../../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = rdf
LIBRARY_NAME = $(LITE_PREFIX)rdf
LIBXP = $(DIST)/lib/libxp.$(LIB_SUFFIX)
REQUIRES = nspr dbm java js htmldlgs util img layer pref ldap network parse
JNI_GEN = netscape.rdf.core.NativeRDF netscape.rdf.core.NativeRDFEnumeration
CSRCS = \
vocab.c \
mcf.c \
remstore.c \
utils.c \
rdfparse.c \
mcff2mcf.c \
bmk2mcf.c \
ldap2rdf.c \
glue.c \
rdfht.c \
jsec2rdf.c \
$(NULL)
ifndef RDF_STANDALONE
CSRCS += \
nlcstore.c \
find2rdf.c \
fs2rdf.c \
hist2rdf.c \
pm2rdf.c \
es2mcf.c \
columns.c \
ht.c \
$(NULL)
endif
SPF_OBJS = $(OBJDIR)/spf2ldif.o \
$(OBJDIR)/hashtable.o
LOCAL_INCLUDES = -I$(PUBLIC)/rdf
include $(topsrcdir)/config/rules.mk
ifdef RDF_STANDALONE
DEFINES := $(filter-out -DMOZILLA_CLIENT, $(DEFINES))
endif
$(LIBRARY): $(OBJS)
test: $(OBJDIR)/test
spf2ldif: $(OBJDIR)/spf2ldif
.PHONY: test spf2ldif
$(OBJDIR)/test: $(OBJDIR)/test.o $(LIBRARY)
@$(MAKE_OBJDIR)
$(CC) -o $@ $(OBJDIR)/test.o $(LIBRARY) $(LIBNSPR) $(LIBXP) $(LDFLAGS) $(OS_LIBS)
$(OBJDIR)/spf2ldif: $(SPF_OBJS) $(LIBRARY)
@$(MAKE_OBJDIR)
$(CC) -o $@ $(SPF_OBJS) $(LIBRARY) $(LIBNSPR) $(LIBXP) $(LDFLAGS) $(OS_LIBS)

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,87 @@
/* -*- 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_ATALK_H_
#define _RDF_ATALK_H_
#ifdef XP_MAC
#include <Appletalk.h>
#include <Devices.h>
#include <Gestalt.h>
#include "rdf.h"
#include "rdf-int.h"
#include "mcf.h"
#include "vocab.h"
#include "utils.h"
#include "prefapi.h"
/* atalk.c data structures and defines */
extern int RDF_APPLETALK_TOP_NAME, RDF_AFP_CLIENT_37_STR, RDF_AFP_AUTH_FAILED_STR;
extern int RDF_AFP_PW_EXPIRED_STR, RDF_AFP_ALREADY_MOUNTED_STR, RDF_AFP_MAX_SERVERS_STR;
extern int RDF_AFP_NOT_RESPONDING_STR, RDF_AFP_SAME_NODE_STR, RDF_AFP_ERROR_NUM_STR;
extern int RDF_VOLUME_DESC_STR, RDF_DIRECTORY_DESC_STR, RDF_FILE_DESC_STR;
#define ATALK_NOHIERARCHY_PREF "browser.navcenter.appletalk.zone.nohierarchy"
#define ATALK_CMD_PREFIX "Command:at:"
#define kAppleShareVerGestalt 'afps'
#define kAppleShareVer_3_7 0x00000006
#define AFPX_PROT_VERSION 0
#define BASE_AFPX_OFFSET 30
#define BASE_AFP_OFFSET 24
typedef struct _ourNBPUserDataStruct
{
RDFT rdf;
char *parentID;
} ourNBPUserDataStruct;
typedef ourNBPUserDataStruct *ourNBPUserDataPtr;
/* atalk.c function prototypes */
NSPR_BEGIN_EXTERN_C
#ifdef XP_MAC
PRBool isAFPVolume(short ioVRefNum);
#endif
void getZones(RDFT rdf);
void processZones(RDFT rdf, char *zones, uint16 numZones, XP_Bool noHierarchyFlag);
void checkServerLookup (MPPParamBlock *nbp);
void getServers(RDFT rdf, RDF_Resource parent);
void AtalkPossible(RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep);
RDF_Error AtalkDestroy (RDFT r);
PRBool AtalkHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void *v, RDF_ValueType type, PRBool tv);
PRBool AtalkAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void *v, RDF_ValueType type, PRBool tv);
char * convertAFPtoUnescapedFile(char *id);
void * AtalkGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor AtalkGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * AtalkNextValue (RDFT rdf, RDF_Cursor c);
RDF_Resource CreateAFPFSUnit (char *nname, PRBool isDirectoryFlag);
RDFT MakeAtalkStore (char* url);
NSPR_END_EXTERN_C
#endif
#endif

View File

@@ -0,0 +1,602 @@
/* -*- 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.
*/
/* Reading bookmarks.htm into rdf.
tags in the bookmark file.
<TITLE>
<H1>
<H3>
<DL></DL>
<DT>
<P>
<DT> indicates that an item is coming.
If the next item is an <a then we have a url
If the next item is a h3, we have a folder.
<DL> indicates that the previous item (which should have been a folder)
is the parent of the next set.
</DL> indicates pop out a level
<P> ignore this on reading, but write out one after each <DL>
<DD> the description for the previous <DT>
Category urls. Make it up out of the add dates. */
/*
This file translates netscape bookmarks into 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 "bmk2mcf.h"
#include "utils.h"
#include "time.h"
#ifdef MOZILLA_CLIENT
/* extern declarations */
PR_PUBLIC_API(void) HT_WriteOutAsBookmarks (RDF r, PRFileDesc *fp, RDF_Resource u); /* XXX this should be elsewhere */
extern char *gBookmarkURL;
extern RDF gNCDB;
/* globals */
uint16 separatorCounter = 0;
static char* gBkFolderDate;
static RDFT gBMKStore = 0;
extern int RDF_PERSONAL_TOOLBAR_NAME;
RDF_Resource
createSeparator(void)
{
char url[50];
RDF_Resource sep;
PR_snprintf(url, 50, "separator%i", separatorCounter++);
sep = RDF_GetResource(NULL, url, 1);
return sep;
}
#endif
RDF_Resource
createContainer (char* id)
{
RDF_Resource r = RDF_GetResource(NULL, id, true);
setContainerp(r, 1);
return r;
}
#ifdef MOZILLA_CLIENT
char *
resourceDescription (RDF rdf, RDF_Resource r)
{
return (char*)RDF_GetSlotValue(rdf, r, gWebData->RDF_description, RDF_STRING_TYPE, false, true);
}
char *
resourceLastVisitDate (RDF rdf, RDF_Resource r)
{
return (char*)RDF_GetSlotValue(rdf, r, gWebData->RDF_lastVisitDate, RDF_STRING_TYPE, false, true);
}
char *
resourceLastModifiedDate (RDF rdf, RDF_Resource r)
{
return (char*)RDF_GetSlotValue(rdf, r, gWebData->RDF_lastModifiedDate, RDF_STRING_TYPE, false, true);
}
void
parseNextBkBlob (RDFFile f, char* blob, int32 size)
{
int32 n, last, m;
PRBool somethingseenp = false;
n = last = 0;
while (n < size) {
char c = blob[n];
m = 0;
somethingseenp = false;
memset(f->line, '\0', f->lineSize);
if (f->holdOver[0] != '\0') {
memcpy(f->line, f->holdOver, RDF_STRLEN(f->holdOver));
m = RDF_STRLEN(f->holdOver);
somethingseenp = true;
memset(f->holdOver, '\0', RDF_BUF_SIZE);
}
while ((m < 300) && (c != '<') && (c != '>') && (n < size)) {
f->line[m] = c;
m++;
somethingseenp = (somethingseenp || ((c != ' ') && (c != '\r') && (c != '\n')));
n++;
c = blob[n];
}
if (c == '>') f->line[m] = c;
n++;
if (m > 0) {
if ((c == '<') || (c == '>')) {
last = n;
if (c == '<') f->holdOver[0] = '<';
if (somethingseenp == true) parseNextBkToken(f, f->line);
} else if (size > last) {
memcpy(f->holdOver, f->line, m);
}
} else if (c == '<') f->holdOver[0] = '<';
}
}
void
parseNextBkToken (RDFFile f, char* token)
{
/* printf(token); */
if (token[0] == '<') {
bkStateTransition(f, token);
} else {
/* ok, we have a piece of content.
can be the title, or a description or */
if ((f->status == IN_TITLE) || (f->status == IN_H3) ||
(f->status == IN_ITEM_TITLE)) {
if (IN_H3 && gBkFolderDate) {
char *url;
RDF_Resource newFolder;
url = PR_smprintf("%s%s.rdf", gBkFolderDate, token);
newFolder = createContainer(url);
free(url);
addSlotValue(f,newFolder, gCoreVocab->RDF_parent, f->stack[f->depth-1],
RDF_RESOURCE_TYPE, NULL);
freeMem(gBkFolderDate);
gBkFolderDate = NULL;
f->lastItem = newFolder;
}
if ((f->db == gLocalStore) || (f->status != IN_TITLE))
{
addSlotValue(f, f->lastItem, gCoreVocab->RDF_name,
copyString(token), RDF_STRING_TYPE, NULL);
}
if (startsWith("Personal Toolbar", token) && (containerp(f->lastItem)))
addSlotValue(f, f->lastItem, gCoreVocab->RDF_instanceOf,
gNavCenter->RDF_PersonalToolbarFolderCategory,
RDF_RESOURCE_TYPE, "true");
} else if (f->status == IN_ITEM_DESCRIPTION) {
addDescription(f, f->lastItem, token);
}
}
}
void
addDescription (RDFFile f, RDF_Resource r, char* token)
{
char* desc = (char*) remoteStoreGetSlotValue(gLocalStore, r, gWebData->RDF_description,
RDF_STRING_TYPE, false, true);
if (desc == NULL) {
addSlotValue(f, f->lastItem, gWebData->RDF_description,
copyString(token),
RDF_STRING_TYPE, NULL);
} else {
addSlotValue(f, f->lastItem, gWebData->RDF_description,
append2Strings(desc, token), RDF_STRING_TYPE, NULL);
remoteUnassert(gLocalStore, f->lastItem, gWebData->RDF_description, desc, RDF_STRING_TYPE);
}
}
void
bkStateTransition (RDFFile f, char* token)
{
if (startsWith("<A", token)) {
newLeafBkItem(f, token);
f->status = IN_ITEM_TITLE;
} else if (startsWith(OPEN_H3_STRING, token)) {
newFolderBkItem(f, token);
f->status = IN_H3;
} else if (startsWith(OPEN_TITLE_STRING, token)) {
f->status = IN_TITLE;
} else if (startsWith(OPEN_H3_STRING, token)) {
f->status = IN_H3;
} else if (startsWith(DD_STRING, token)) {
if (remoteStoreGetSlotValue(gLocalStore, f->lastItem, gWebData->RDF_description,
RDF_STRING_TYPE, false, true)
== NULL) f->status = IN_ITEM_DESCRIPTION;
} else if (startsWith(OPEN_DL_STRING, token)) {
f->stack[f->depth++] = f->lastItem;
} else if (startsWith(CLOSE_DL_STRING, token)) {
f->depth--;
} else if (startsWith("<HR>", token)) {
addSlotValue(f, createSeparator(), gCoreVocab->RDF_parent, f->stack[f->depth-1],
RDF_RESOURCE_TYPE, NULL);
f->status = 0;
} else if ((f->status == IN_ITEM_DESCRIPTION) && (startsWith("<BR>", token))) {
addDescription(f, f->lastItem, token);
} else f->status = 0;
}
void
newFolderBkItem(RDFFile f, char* token)
{
int16 start, end;
start = charSearch('"', token);
end = revCharSearch('"', token);
token[end] = '\0';
gBkFolderDate = copyString(&token[start+1]);
}
void
newLeafBkItem (RDFFile f, char* token)
{
char buffer[128];
struct tm *time;
uint32 dateVal;
char* url = NULL;
char* addDate = NULL;
char* lastVisit = NULL;
char* lastModified = NULL;
uint8 current = 0;
int32 len = RDF_STRLEN(token);
int32 n = 0;
char c = token[n++];
PRBool inString = false;
RDF_Resource newR;
while (n < len) {
if (c == '"') {
if (inString) {
token[n-1] = '\0';
inString = false;
} else {
inString = true;
if (current == 0) {
url = &token[n];
} else if (current == 1) {
addDate = &token[n];
} else if (current == 2) {
lastVisit = &token[n];
} else if (current == 3) {
lastModified = &token[n];
}
current++;
}
}
c = token[n++];
}
if (url == NULL) return;
newR = RDF_GetResource(NULL, url, true);
addSlotValue(f, newR, gCoreVocab->RDF_parent, f->stack[f->depth-1],
RDF_RESOURCE_TYPE, NULL);
/* addSlotValue(f, newR, gWebData->RDF_URL, (void*)copyString(url),
RDF_STRING_TYPE, true); */
if (addDate != NULL)
{
dateVal = atol(addDate);
if ((time = localtime((time_t *) &dateVal)) != NULL)
{
/* xxx
#ifdef XP_MAC
time->tm_year += 4;
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#elif XP_UNIX
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#else
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_WINDATE),time);
#endif
addSlotValue(f, newR, gNavCenter->RDF_bookmarkAddDate,
(void*)copyString(buffer), RDF_STRING_TYPE, NULL);
*/
}
}
if (lastVisit != NULL)
{
dateVal = atol(lastVisit);
if ((time = localtime((time_t *) &dateVal)) != NULL)
{
/* xxx
#ifdef XP_MAC
time->tm_year += 4;
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#elif XP_UNIX
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#else
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_WINDATE),time);
#endif
addSlotValue(f, newR, gWebData->RDF_lastVisitDate,
(void*)copyString(buffer), RDF_STRING_TYPE, NULL);
*/
}
}
if (lastModified != NULL)
{
dateVal = atol(lastModified);
if ((time = localtime((time_t *) &dateVal)) != NULL)
{
/* xxx
#ifdef XP_MAC
time->tm_year += 4;
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#elif XP_UNIX
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#else
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_WINDATE),time);
#endif
addSlotValue(f, newR, gWebData->RDF_lastModifiedDate,
(void*)copyString(buffer), RDF_STRING_TYPE, NULL);
*/
}
}
f->lastItem = newR;
}
char *
numericDate(char *url)
{
char *date = NULL;
int len=0;
if (!url) return NULL;
while (url[len])
{
if (!isdigit(url[len])) break;
++len;
}
if (len > 0)
{
if ((date = getMem(len+1)) != NULL)
{
strncpy(date, url, len);
}
}
return(date);
}
PRBool
bookmarkSlotp (RDF_Resource s)
{
return ((s == gCoreVocab->RDF_parent) || (s == gWebData->RDF_lastVisitDate) || (s == gWebData->RDF_description) ||
(s == gNavCenter->RDF_bookmarkAddDate) || (s == gWebData->RDF_lastModifiedDate) ||
(s == gCoreVocab->RDF_name));
}
void
HT_WriteOutAsBookmarks1 (RDF rdf, PRFileDesc *fp, RDF_Resource u, RDF_Resource top, int indent)
{
RDF_Cursor c = RDF_GetSources(rdf, u, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
RDF_Resource next;
char *date, *name, *url;
int loop;
if (c == NULL) return;
if (u == top) {
name = RDF_GetResourceName(rdf, u);
ht_rjcprintf(fp, "<!DOCTYPE NETSCAPE-Bookmark-file-1>\n", NULL);
ht_rjcprintf(fp, "<!-- This is an automatically generated file.\n", NULL);
ht_rjcprintf(fp, "It will be read and overwritten.\n", NULL);
ht_rjcprintf(fp, "Do Not Edit! -->\n", NULL);
ht_rjcprintf(fp, "<TITLE>%s</TITLE>\n", (name) ? name:"");
ht_rjcprintf(fp, "<H1>%s</H1>\n<DL><p>\n", (name) ? name:"");
}
while ((next = RDF_NextValue(c)) != NULL) {
url = resourceID(next);
if (containerp(next) && (!startsWith("ftp:",url)) && (!startsWith("file:",url))
&& (!startsWith("IMAP:", url)) && (!startsWith("nes:", url))
&& (!startsWith("mail:", url)) && (!startsWith("cache:", url))
&& (!startsWith("ldap:", url))) {
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", NULL);
date = numericDate(resourceID(next));
ht_rjcprintf(fp, "<DT><H3 ADD_DATE=\"%s\">", (date) ? date:"");
if (date) freeMem(date);
name = RDF_GetResourceName(rdf, next);
ht_rjcprintf(fp, "%s</H3>\n", name);
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", NULL);
ht_rjcprintf(fp, "<DL><p>\n", NULL);
HT_WriteOutAsBookmarks1(rdf, fp, next, top, indent+1);
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", NULL);
ht_rjcprintf(fp, "</DL><p>\n", NULL);
}
else if (isSeparator(next)) {
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", NULL);
ht_rjcprintf(fp, "<HR>\n", NULL);
}
else {
char* bkAddDate = (char*)RDF_GetSlotValue(rdf, next,
gNavCenter->RDF_bookmarkAddDate,
RDF_STRING_TYPE, false, true);
for (loop=0; loop<indent; loop++) ht_rjcprintf(fp, " ", NULL);
ht_rjcprintf(fp, "<DT><A HREF=\"%s\" ", resourceID(next));
date = numericDate(bkAddDate);
ht_rjcprintf(fp, "ADD_DATE=\"%s\" ", (date) ? date: "");
if (date) freeMem(date);
ht_rjcprintf(fp, "LAST_VISIT=\"%s\" ", resourceLastVisitDate(rdf, next));
ht_rjcprintf(fp, "LAST_MODIFIED=\"%s\">", resourceLastModifiedDate(rdf, next));
ht_rjcprintf(fp, "%s</A>\n", RDF_GetResourceName(rdf, next));
if (resourceDescription(rdf, next) != NULL) {
ht_rjcprintf(fp, "<DD>%s\n", resourceDescription(rdf, next));
}
}
}
RDF_DisposeCursor(c);
if (u == top) {
ht_rjcprintf(fp, "</DL>\n", NULL);
}
}
PR_PUBLIC_API(void)
HT_WriteOutAsBookmarks (RDF r, PRFileDesc *fp, RDF_Resource u)
{
HT_WriteOutAsBookmarks1 (r, fp, u, u, 1);
}
void
flushBookmarks()
{
PRFileDesc *bkfp;
if (gBookmarkURL != NULL)
{
/*
delete bookmark.htm as PROpen() with PR_TRUNCATE appears broken (at least on Mac)
*/
CallPRDeleteFileUsingFileURL(gBookmarkURL);
if ((bkfp = CallPROpenUsingFileURL(gBookmarkURL, (PR_WRONLY|PR_CREATE_FILE|PR_TRUNCATE),
0644)) != NULL)
{
HT_WriteOutAsBookmarks(gNCDB, bkfp, gNavCenter->RDF_BookmarkFolderCategory);
PR_Close(bkfp);
}
}
}
PRBool
ResourceBelongsToBookmarksp (RDF_Resource r, int32 depth) {
if (depth > 20) {
return false;
} else if (r == gNavCenter->RDF_BookmarkFolderCategory) {
return 1;
} else if (containerp(r)) {
Assertion as = r->rarg1;
while (as) {
if ((as->db == gBMKStore) &&
(as->s == gCoreVocab->RDF_parent) &&
(as->tv == 1) &&
(ResourceBelongsToBookmarksp((RDF_Resource)as->value, depth+1))) return 1;
as = as->next;
}
return 0;
} else return 0;
}
PRBool remoteAssert3 (RDFFile fi, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv);
PRBool remoteUnassert3 (RDFFile fi, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type);
PRBool
bmkUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s,
void* v, RDF_ValueType type) {
if (ResourceBelongsToBookmarksp(u, 0)) {
return (remoteStoreRemove(mcf, u, s, v, type) != NULL);
} else return 0;
}
PRBool
bmkAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv) {
if (ResourceBelongsToBookmarksp(u, 0)) {
return (remoteStoreAdd(mcf, u, s, v, type, tv) != NULL);
} else return 0;
}
extern RDF_Resource gPTFolder;
void
readInBookmarks()
{
/* RDF_Resource ptFolder; */
RDF_Resource bmk = RDF_GetResource(NULL, "NC:Bookmarks", true);
RDFFile f = makeRDFFile(gBookmarkURL, bmk, true);
PRFileDesc *fp;
int32 len;
char buf[512];
f->fileType = RDF_BOOKMARKS;
f->db = gBMKStore;
f->assert = remoteAssert3;
fp = CallPROpenUsingFileURL(f->url, PR_RDONLY|PR_CREATE_FILE, 0644);
if (fp == NULL) return;
while((len=PR_Read(fp, buf, sizeof(buf))) >0) {
parseNextBkBlob(f, buf, len);
}
gPTFolder = remoteStoreGetSlotValue(f->db,
gNavCenter->RDF_PersonalToolbarFolderCategory,
gCoreVocab->RDF_instanceOf, RDF_RESOURCE_TYPE, true, true);
if (gPTFolder == NULL) {
if ((gPTFolder = createContainer("personaltoolbar.rdf")) != NULL) {
addSlotValue(f, gPTFolder, gCoreVocab->RDF_instanceOf,
gNavCenter->RDF_PersonalToolbarFolderCategory,
RDF_RESOURCE_TYPE, "true");
addSlotValue(f, gPTFolder, gCoreVocab->RDF_name,
copyString("Personal Toolbar"),
RDF_STRING_TYPE, "true");
RDFUtil_SetPTFolder(gPTFolder);
}
}
PR_Close(fp);
freeMem(f->line);
freeMem(f->currentSlot);
freeMem(f->holdOver);
}
RDFT
MakeBMKStore (char* url)
{
if (startsWith("rdf:bookmarks", url)) {
if (gBMKStore == 0) {
RDFT ntr = gBMKStore = NewRemoteStore(url);
ntr->assert = bmkAssert;
ntr->unassert = bmkUnassert;
readInBookmarks();
return ntr;
} else return gBMKStore;
} else return NULL;
}
#endif

View File

@@ -0,0 +1,72 @@
/* -*- 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_BMK2MCF_H_
#define _RDF_BMK2MCF_H_
#include "rdf.h"
#include "rdf-int.h"
#include "vocab.h"
#include "stdio.h"
#include "ctype.h"
/* bmk2mcf.c data structures and defines */
#define OPEN_TITLE_STRING "<TITLE>"
#define CLOSE_TITLE_STRING "</TITLE>"
#define OPEN_H1_STRING "<H1>"
#define CLOSE_H1_STRING "</H1>"
#define OPEN_H3_STRING "<H3"
#define CLOSE_H3_STRING "</H3>"
#define OPEN_DL_STRING "<DL>"
#define CLOSE_DL_STRING "</DL>"
#define DT_STRING "<DT>"
#define PAR_STRING "<P>"
#define DD_STRING "<DD>"
#define IN_TITLE 1
#define IN_H3 5
#define IN_ITEM_TITLE 7
#define IN_ITEM_DESCRIPTION 9
/* bmk2mcf.c function prototypes */
RDF_Resource createSeparator(void);
RDF_Resource createContainer (char* id);
char * resourceDescription (RDF rdf, RDF_Resource r);
char * resourceLastVisitDate (RDF rdf, RDF_Resource r);
char * resourceLastModifiedDate (RDF rdf, RDF_Resource r);
void parseNextBkBlob (RDFFile f, char* blob, int32 size);
void parseNextBkToken (RDFFile f, char* token);
void addDescription (RDFFile f, RDF_Resource r, char* token);
void bkStateTransition (RDFFile f, char* token);
void newFolderBkItem(RDFFile f, char* token);
void newLeafBkItem (RDFFile f, char* token);
char * numericDate(char *url);
void HT_WriteOutAsBookmarks1 (RDF rdf, PRFileDesc *fp, RDF_Resource u, RDF_Resource top, int indent);
void flushBookmarks();
#endif

View File

@@ -0,0 +1,114 @@
/* -*- 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.
*/
#include "rdf-int.h"
/* We need to define a new class of urls for cache objects.
e.g., cache:<something here>
The url for the rdf datastore corresponding to the cache
is rdf:cache.
The Cache Schema.
The cache consists of a hierarchy of objects. The standard
hierarchy relation (RDF_parent). In addition, each object
may have the following properties.
lastAccess
lastModified
container cache objects start with cache:container ...
*/
RDFT gCacheStore = NULL;
RDFT MakeCacheStore (char* url) {
if (startsWith("rdf:cache", url)) {
if (gCacheStore != NULL) {
return gCacheStore;
} else {
RDF_Translator ntr = (RDF_Translator)getMem(sizeof(RDF_TranslatorStruct));
ntr->assert = NULL;
ntr->unassert = NULL;
ntr->getSlotValue = cacheGetSlotValue;
ntr->getSlotValues = cacheGetSlotValues;
ntr->hasAssertion = cacheHasAssertion;
ntr->nextValue = cacheNextValue;
ntr->disposeCursor = cacheDisposeCursor;
gCacheStore = ntr;
return ntr;
}
} else return NULL;
}
PRBool
cacheHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv) {
if ((resourceType(u) == CACHE_RT) && tv) {
/*e.g., u->id = cache:http://www.netscape.com/
s = gWebData->RDF_size
v = 1000
type = RDF_INT_TYPE
return true if the cache object corresponding to u has a size of 1000
e.g., u->id = cache:http://www.netscape.com/
s = gCoreVocab->RDF_parent
type = RDF_RESOURCE_TYPE
v-> = "cache:container:MemoryCache"
*/
} else {
return 0;
}
}
RDF_Cursor cacheGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv) {
if ((resourceType(u) == CACHE_RT) && tv && (s == gCoreVocab->RDF_parent) && inversep) {
RDF_Cursor c;
c = (RDF_Cursor) getMem(sizeof(RDF_CursorStruc));
c->u = u;
c->count = 0;
c->pdata = NULL;
c->type = type;
return c;
} else return NULL;
}
void* cacheNextValue (RDFT rdf, RDF_Cursor c) {
"return the next value, update count, return NUll when there are no more.
the children are nodes. to create a new node, call RDF_Create(url, 1);
If something is a container, after getting the object, do setContainerp(r, 1);"
}
RDF_Error cacheDisposeCursor (RDFT rdf, RDF_Cursor c) {
"dispose it. c could be NULL"
}
void* cacheGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,
PRBool inversep, PRBool tv) {
if ("willing to answer this") {
return the value;
} else {
return NULL;
}
}

View File

@@ -0,0 +1,284 @@
/* -*- 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 synthesizes default columns for a given node.
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 "columns.h"
RDF_Cursor
ColumnsGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv)
{
RDF_Cursor c;
if (!containerp(u) || (s != gNavCenter->RDF_Column) || (inversep) ||
(!tv) || (type != RDF_RESOURCE_TYPE))
{
return(NULL);
}
if ((c = (RDF_Cursor)getMem(sizeof(struct RDF_CursorStruct))) != NULL)
{
c->u = u;
c->value = NULL;
c->count = 0;
}
return(c);
}
void *
ColumnsGetSlotValue(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,
PRBool inversep, PRBool tv)
{
void *val = NULL;
if (u == NULL) return(NULL);
if ((s == gCoreVocab->RDF_name) && (type == RDF_STRING_TYPE)
&& (!inversep) && (tv))
{
#ifdef XXX
if (u == gCoreVocab->RDF_name) val = copyString(XP_GetString(RDF_NAME_STR));
else if (u == gNavCenter->RDF_URLShortcut) val = copyString(XP_GetString(RDF_SHORTCUT_STR));
else if (u == gWebData->RDF_URL) val = copyString(XP_GetString(RDF_URL_STR));
else if (u == gWebData->RDF_description) val = copyString(XP_GetString(RDF_DESCRIPTION_STR));
else if (u == gWebData->RDF_firstVisitDate) val = copyString(XP_GetString(RDF_FIRST_VISIT_STR));
else if (u == gWebData->RDF_lastVisitDate) val = copyString(XP_GetString(RDF_LAST_VISIT_STR));
else if (u == gWebData->RDF_numAccesses) val = copyString(XP_GetString(RDF_NUM_ACCESSES_STR));
else if (u == gWebData->RDF_creationDate) val = copyString(XP_GetString(RDF_CREATED_ON_STR));
else if (u == gWebData->RDF_lastModifiedDate) val = copyString(XP_GetString(RDF_LAST_MOD_STR));
else if (u == gWebData->RDF_size) val = copyString(XP_GetString(RDF_SIZE_STR));
else if (u == gNavCenter->RDF_bookmarkAddDate) val = copyString(XP_GetString(RDF_ADDED_ON_STR));
#endif
}
else if ((s == gNavCenter->RDF_ColumnDataType) &&
(type == RDF_INT_TYPE) && (!inversep) && (tv))
{
if (u == gNavCenter->RDF_bookmarkAddDate ||
u == gWebData->RDF_firstVisitDate ||
u == gWebData->RDF_lastVisitDate ||
u == gWebData->RDF_lastModifiedDate ||
u == gWebData->RDF_creationDate)
{
val = (void *)HT_COLUMN_STRING;
}
else if (u == gWebData->RDF_size ||
u == gWebData->RDF_numAccesses ||
u == gNavCenter->cookieDomain ||
u == gNavCenter->cookieSecure)
{
val = (void *)HT_COLUMN_INT;
}
else
{
/* default to string... XXX wrong thing to do? */
val = (void *)HT_COLUMN_STRING;
}
}
else if ((s == gNavCenter->RDF_ColumnWidth) &&
(type == RDF_INT_TYPE) && (!inversep) && (tv))
{
if (u == gCoreVocab->RDF_name) val = (void *)128L;
else if (u == gWebData->RDF_URL) val = (void *)200L;
else val = (void *)80;
}
return(val);
}
void *
ColumnsNextValue (RDFT rdf, RDF_Cursor c)
{
void *arc = NULL;
PR_ASSERT(c != NULL);
if (c == NULL) return(NULL);
switch( resourceType(c->u) )
{
case RDF_RT:
if ((c->u == gNavCenter->RDF_Sitemaps) || (c->u == gNavCenter->RDF_Mail))
{
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1: arc = gWebData->RDF_URL; break;
}
}
else do
{
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1:
if ((idenEqual(c->u, gNavCenter->RDF_BookmarkFolderCategory)) ||
((!startsWith("http://", resourceID(c->u))) && endsWith(".rdf", resourceID(c->u))))
{
arc = gNavCenter->RDF_URLShortcut;
}
else
{
/* disallow shortcuts from external RDF graphs, so skip to next column */
arc = NULL;
++(c->count);
}
break;
case 2: arc = gWebData->RDF_URL; break;
case 3: arc = gWebData->RDF_description; break;
case 4: arc = gWebData->RDF_keyword; break;
case 5: arc = gNavCenter->RDF_bookmarkAddDate; break;
case 6: arc = gWebData->RDF_lastVisitDate; break;
case 7: arc = gWebData->RDF_lastModifiedDate; break;
case 8: arc = gNavCenter->pos; break;
}
} while ((c->count <= 6) && (arc == NULL));
break;
case HISTORY_RT:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1: arc = gWebData->RDF_URL; break;
case 2: arc = gWebData->RDF_firstVisitDate; break;
case 3: arc = gWebData->RDF_lastVisitDate; break;
case 4: arc = NULL; break;
case 5: arc = gWebData->RDF_numAccesses; break;
}
break;
case COOKIE_RT:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1: arc = gNavCenter->cookieHost; break;
case 2: arc = gNavCenter->cookiePath; break;
case 3: arc = gNavCenter->cookieValue; break;
case 4: arc = gNavCenter->cookieExpires; break;
case 5: arc = gNavCenter->cookieDomain; break;
case 6: arc = gNavCenter->cookieSecure; break;
}
break;
case FTP_RT:
case ES_RT:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1: arc = gWebData->RDF_URL; break;
case 2: arc = gWebData->RDF_description; break;
case 3: arc = gWebData->RDF_size; break;
case 4: arc = gWebData->RDF_lastModifiedDate; break;
}
break;
case LFS_RT:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1: arc = gWebData->RDF_URL; break;
case 2: arc = gWebData->RDF_description; break;
case 3: arc = gWebData->RDF_size; break;
case 4: arc = gWebData->RDF_lastModifiedDate; break;
case 5: arc = gWebData->RDF_creationDate; break;
}
break;
case LDAP_RT:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
}
break;
case PM_RT:
case IM_RT:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1: arc = gWebData->RDF_URL; break;
}
break;
case SEARCH_RT:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
case 1: arc = gNavCenter->RDF_URLShortcut; break;
case 2: arc = gWebData->RDF_URL; break;
case 3: arc = gWebData->RDF_description; break;
case 4: arc = gWebData->RDF_keyword; break;
}
break;
default:
switch(c->count)
{
case 0: arc = gCoreVocab->RDF_name; break;
}
break;
}
++(c->count);
return(arc);
}
RDF_Error
ColumnsDisposeCursor (RDFT rdf, RDF_Cursor c)
{
if (c != NULL)
{
freeMem(c);
}
return(0);
}
RDFT
MakeColumnStore (char* url)
{
RDFT ntr = NULL;
if (strstr(url, "rdf:columns"))
{
if ((ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct))) != NULL)
{
ntr->getSlotValues = ColumnsGetSlotValues;
ntr->getSlotValue = ColumnsGetSlotValue;
ntr->nextValue = ColumnsNextValue;
ntr->disposeCursor = ColumnsDisposeCursor;
ntr->url = copyString(url);
}
}
return(ntr);
}

View File

@@ -0,0 +1,48 @@
/* -*- 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_COLUMNS_H_
#define _RDF_COLUMNS_H_
#include "rdf-int.h"
#include "htrdf.h"
#include "utils.h"
/* columns.c data structures */
extern int RDF_NAME_STR, RDF_SHORTCUT_STR, RDF_URL_STR, RDF_DESCRIPTION_STR;
extern int RDF_FIRST_VISIT_STR, RDF_LAST_VISIT_STR, RDF_NUM_ACCESSES_STR;
extern int RDF_CREATED_ON_STR, RDF_LAST_MOD_STR, RDF_SIZE_STR, RDF_ADDED_ON_STR;
/* columns.c function prototypes */
NSPR_BEGIN_EXTERN_C
RDF_Cursor ColumnsGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * ColumnsGetSlotValue(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * ColumnsNextValue (RDFT rdf, RDF_Cursor c);
RDF_Error ColumnsDisposeCursor (RDFT rdf, RDF_Cursor c);
RDFT MakeColumnStore (char* url);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,574 @@
/* -*- 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.
*/
#include "rdf.h"
#include "nsIRDFDataSource.h"
#include "nsIRDFDataBase.h"
#include "nsIRDFObserver.h"
#include "nsIRDFService.h"
#include "nsIRDFCursor.h"
#include "nspr.h"
#include "plhash.h"
PR_BEGIN_EXTERN_C
PR_PUBLIC_API(void) _comwrap_NotificationCB(RDF_Event event, void* pdata);
PR_END_EXTERN_C
class rdfDataBaseWrapper;
class rdfCursorWrapper;
class rdfServiceWrapper;
class rdfServiceFactory;
class rdfDatabaseWrapper : public nsIRDFDataBase {
public:
NS_DECL_ISUPPORTS
rdfDatabaseWrapper(RDF r);
virtual ~rdfDatabaseWrapper();
/* nsIRDFDataSource methods: */
NS_METHOD GetName(const RDF_String* name /* out */ );
NS_METHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
RDF_Resource *source /* out */);
NS_METHOD GetSource(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
RDF_Resource *source /* out */);
NS_METHOD GetSources(RDF_Node target,
RDF_Resource arcLabel,
nsIRDFCursor **sources /* out */);
NS_METHOD GetSources(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
nsIRDFCursor **sources /* out */);
NS_METHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
RDF_NodeStruct& target /* in/out */);
NS_METHOD GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
PRBool tv,
RDF_NodeStruct& target /* in/out */);
NS_METHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */);
NS_METHOD GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
PRBool tv,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */);
NS_METHOD Assert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv = PR_TRUE);
NS_METHOD Unassert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target);
NS_METHOD HasAssertion(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv,
PRBool* hasAssertion /* out */);
NS_METHOD AddObserver(nsIRDFObserver *n,
RDF_EventMask type = RDF_ANY_NOTIFY);
NS_METHOD RemoveObserver(nsIRDFObserver *n,
RDF_EventMask = RDF_ANY_NOTIFY);
NS_METHOD ArcLabelsIn(RDF_Node node,
nsIRDFCursor **labels /* out */);
NS_METHOD ArcLabelsOut(RDF_Resource source,
nsIRDFCursor **labels /* out */);
NS_METHOD Flush();
/* nsIRDFDataBase methods: */
NS_METHOD AddDataSource(nsIRDFDataSource* dataSource);
NS_METHOD RemoveDataSource(nsIRDFDataSource* dataSource);
NS_METHOD GetDataSource(RDF_String url,
nsIRDFDataSource **source /* out */ );
NS_METHOD DeleteAllArcs(RDF_Resource resource);
private:
RDF mRDF;
PLHashTable* mpObserverMap;
};
class rdfCursorWrapper : public nsIRDFCursor {
public:
NS_DECL_ISUPPORTS
rdfCursorWrapper(RDF_Cursor c);
virtual ~rdfCursorWrapper();
NS_METHOD HasElements(PRBool& hasElements);
NS_METHOD Next(RDF_NodeStruct& n);
private:
RDF_Cursor mCursor;
};
class rdfServiceWrapper : public nsIRDFService {
public:
NS_DECL_ISUPPORTS
NS_METHOD CreateDatabase(const RDF_String* url,
nsIRDFDataBase** db);
};
class rdfServiceFactory : public nsIFactory {
public:
NS_DECL_ISUPPORTS
rdfServiceFactory();
virtual ~rdfServiceFactory();
NS_METHOD CreateInstance(nsISupports *aOuter,
REFNSIID anIID,
void **aResult);
NS_METHOD LockFactory(PRBool aLock);
};
/*
rdfDataBaseWrapper:
*/
NS_IMPL_ISUPPORTS( rdfDatabaseWrapper, NS_IRDFDATABASE_IID )
rdfDatabaseWrapper::rdfDatabaseWrapper(RDF r) : mRDF(r)
{
mpObserverMap = PL_NewHashTable( 100,
NULL, // XXX isn't there are hash fn for pointers???
PL_CompareValues,
PL_CompareValues,
0,
0 );
PR_ASSERT( mpObserverMap );
#ifdef XXX
if( !mpObserverMap ) // XXX just like 'new' failing on this object?
throw bad_alloc("rdf: unable to allocate observer map" );
#endif
}
rdfDatabaseWrapper::~rdfDatabaseWrapper()
{
PL_HashTableDestroy( mpObserverMap );
}
NS_METHOD
rdfDatabaseWrapper::GetName(const RDF_String* name /* out */ )
{
PR_ASSERT( PR_FALSE );
return NS_ERROR_NOT_IMPLEMENTED; // XXX
}
NS_METHOD
rdfDatabaseWrapper::GetSource(RDF_Node target,
RDF_Resource arcLabel,
RDF_Resource *source /* out */)
{
PR_ASSERT( target && source );
*source = (RDF_Resource) RDF_GetSlotValue( mRDF,
target->value.r,
arcLabel,
RDF_RESOURCE_TYPE, // anything else makes no sense
PR_TRUE,
PR_TRUE );
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetSource(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
RDF_Resource *source /* out */)
{
*source = (RDF_Resource) RDF_GetSlotValue( mRDF,
target->value.r,
arcLabel,
RDF_RESOURCE_TYPE, // anything else makes no sense
PR_TRUE,
tv );
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetSources(RDF_Node target,
RDF_Resource arcLabel,
nsIRDFCursor **sources /* out */)
{
return GetSources(target,arcLabel,PR_TRUE,sources);
}
NS_METHOD
rdfDatabaseWrapper::GetSources(RDF_Node target,
RDF_Resource arcLabel,
PRBool tv,
nsIRDFCursor **sources /* out */)
{
PR_ASSERT( sources );
if( 0 == sources )
return NS_ERROR_NULL_POINTER;
*sources = 0;
RDF_Cursor c = RDF_GetSources( mRDF,
target->value.r,
arcLabel,
RDF_RESOURCE_TYPE, // anything else makes no sense
tv );
if( c ) {
*sources = new rdfCursorWrapper( c );
(*sources)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
RDF_NodeStruct& target /* in/out */)
{
return GetTarget(source,arcLabel,targetType,PR_TRUE,target);
}
NS_METHOD
rdfDatabaseWrapper::GetTarget(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
PRBool tv,
RDF_NodeStruct& target /* in/out */)
{
PR_ASSERT( targetType != RDF_ANY_TYPE ); // not ready to support this yet
void* value = RDF_GetSlotValue( mRDF,
target.value.r,
arcLabel,
targetType, // anything else makes no sense
PR_FALSE,
tv );
target.type = targetType;
target.value.r = (RDF_Resource) value; // reasonable? XXX
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */)
{
return GetTargets(source,arcLabel,PR_TRUE,targetType,targets);
}
NS_METHOD
rdfDatabaseWrapper::GetTargets(RDF_Resource source,
RDF_Resource arcLabel,
PRBool tv,
RDF_ValueType targetType,
nsIRDFCursor **targets /* out */)
{
PR_ASSERT( targets );
if( 0 == targets )
return NS_ERROR_NULL_POINTER;
*targets = 0;
RDF_Cursor c = RDF_GetTargets( mRDF,
source,
arcLabel,
targetType,
tv );
if( c ) {
*targets = new rdfCursorWrapper( c );
(*targets)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::Assert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool tv)
{
PRBool b = tv ? RDF_Assert( mRDF, source, arcLabel, (void*)target->value.r, target->type ) :
RDF_AssertFalse( mRDF, source, arcLabel, (void*)target->value.r, target->type );
// XXX
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::Unassert(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target)
{
PRBool b = RDF_Unassert( mRDF,
source,
arcLabel,
target->value.r,
target->type ); // XXX
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::HasAssertion(RDF_Resource source,
RDF_Resource arcLabel,
RDF_Node target,
PRBool truthValue,
PRBool* hasAssertion /* out */)
{
*hasAssertion = RDF_HasAssertion( mRDF,
source,
arcLabel,
target->value.r,
target->type,
truthValue );
return NS_OK;
}
PR_IMPLEMENT(void)
_comwrap_NotificationCB(RDF_Event event, void* pdata)
{
nsIRDFObserver* observer = (nsIRDFObserver*) pdata;
// XXX QueryInterface & release??
observer->HandleEvent( (nsIRDFDataSource*)pdata, event );
}
NS_METHOD
rdfDatabaseWrapper::AddObserver(nsIRDFObserver *observer,
RDF_EventMask type)
{
// XXX event masking does not currently work
RDF_Notification notification = (RDF_Notification) PL_HashTableLookup( mpObserverMap, observer );
if( !notification ) {
observer->AddRef();
notification = RDF_AddNotifiable( mRDF,
_comwrap_NotificationCB,
NULL, // XXX
observer );
PL_HashTableAdd( mpObserverMap,
observer,
notification );
}
return NS_OK; // XXX
}
NS_METHOD
rdfDatabaseWrapper::RemoveObserver(nsIRDFObserver *observer,
RDF_EventMask type)
{
RDF_Notification notification = (RDF_Notification) PL_HashTableLookup( mpObserverMap, observer );
if( !notification )
return NS_ERROR_ILLEGAL_VALUE;
RDF_Error err = RDF_DeleteNotifiable( notification );
PR_ASSERT( !err ); // the current implementation never fails!
PL_HashTableRemove( mpObserverMap, observer );
observer->Release();
return NS_OK; // XXX
}
NS_METHOD
rdfDatabaseWrapper::ArcLabelsIn(RDF_Node node,
nsIRDFCursor **labels /* out */)
{
PR_ASSERT( labels );
if( 0 == labels )
return NS_ERROR_NULL_POINTER;
*labels = 0;
RDF_Cursor c = RDF_ArcLabelsIn( mRDF, node->value.r );
if( c ) {
*labels = new rdfCursorWrapper( c );
(*labels)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::ArcLabelsOut(RDF_Resource source,
nsIRDFCursor **labels /* out */)
{
PR_ASSERT( labels );
if( 0 == labels )
return NS_ERROR_NULL_POINTER;
*labels = 0;
RDF_Cursor c = RDF_ArcLabelsOut( mRDF, source );
if( c ) {
*labels = new rdfCursorWrapper( c );
(*labels)->AddRef();
}
return NS_OK;
}
NS_METHOD
rdfDatabaseWrapper::Flush()
{
return NS_ERROR_NOT_IMPLEMENTED; // XXX
}
NS_METHOD
rdfDatabaseWrapper::DeleteAllArcs(RDF_Resource resource)
{
return RDF_DeleteAllArcs( mRDF, resource );
}
/*
rdfServiceWrapper: the RDF service singleton
*/
NS_IMPL_ISUPPORTS( rdfServiceWrapper, NS_IRDFSERVICE_IID )
NS_METHOD
rdfServiceWrapper::CreateDatabase(const RDF_String* url_ary,
nsIRDFDataBase **db)
{
PR_ASSERT( 0 != db );
if( 0 == db )
return NS_ERROR_NULL_POINTER;
*db = 0;
nsresult result = NS_OK;
RDF rdf = RDF_GetDB(url_ary);
if( 0 == rdf ) {
result = RDF_ERROR_UNABLE_TO_CREATE; // XXX this is too wishy-washy
} else {
*db = new rdfDatabaseWrapper(rdf); // XXX
}
return result;
}
/*
rdfCursorWrapper
*/
NS_IMPL_ISUPPORTS( rdfCursorWrapper, NS_IRDFCURSOR_IID )
rdfCursorWrapper::rdfCursorWrapper(RDF_Cursor c) : mCursor(c)
{
}
rdfCursorWrapper::~rdfCursorWrapper()
{
RDF_DisposeCursor( mCursor );
}
NS_METHOD
rdfCursorWrapper::Next(RDF_NodeStruct& next)
{
next.type = RDF_CursorValueType( mCursor );
next.value.r = (RDF_Resource) RDF_NextValue( mCursor );
return NS_OK;
}
/*
rdfServiceFactory
*/
NS_IMPL_ISUPPORTS( rdfServiceFactory, NS_IFACTORY_IID )
NS_METHOD
rdfServiceFactory::CreateInstance( nsISupports *aOuter,
REFNSIID aIID,
void **aResult )
{
PR_ASSERT( aResult );
if( 0 == aResult )
return NS_ERROR_NULL_POINTER;
*aResult = 0;
nsISupports* instance = new rdfServiceWrapper();
nsresult result = instance->QueryInterface( aIID, aResult );
PR_ASSERT( result = NS_OK );
if( result != NS_OK )
delete instance; // wrong interface!
return result;
}
NS_METHOD
rdfServiceFactory::LockFactory(PRBool lock)
{
PR_ASSERT( PR_FALSE );
return NS_ERROR_NOT_IMPLEMENTED;
}

View File

@@ -0,0 +1,490 @@
/* -*- 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 FTP 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 "es2mcf.h"
#include "glue.h"
#include "ht.h"
#include "utils.h"
/* externs */
extern RDF gNCDB;
#define ESFTPRT(x) ((resourceType((RDF_Resource)x) == ES_RT) || (resourceType((RDF_Resource)x) == FTP_RT))
RDFT
MakeESFTPStore (char* url)
{
RDFT ntr = NewRemoteStore(url);
ntr->assert = ESAssert;
ntr->unassert = ESUnassert;
ntr->possiblyAccessFile = ESFTPPossiblyAccessFile;
return ntr;
}
void
ESFTPPossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep)
{
if (((resourceType(u) == ES_RT) || (resourceType(u) == FTP_RT)) &&
(s == gCoreVocab->RDF_parent) && (containerp(u))) {
char* id = resourceID(u);
readRDFFile((resourceType(u) == ES_RT ? &id[4] : id), u, false, rdf);
}
}
PRBool
ESAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
PRBool retVal;
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char*) v)));
if ((s == gCoreVocab->RDF_parent) && (type == RDF_RESOURCE_TYPE) &&
(ESFTPRT((RDF_Resource)v)) &&
(tv) && (containerp((RDF_Resource)v))) {
ESAddChild((RDF_Resource)v, u);
retVal = PR_TRUE;
} else {
retVal = PR_FALSE;
}
return(retVal);
}
PRBool
ESUnassert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type)
{
PRBool retVal;
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char*) v)));
if ((s == gCoreVocab->RDF_parent) && (type == RDF_RESOURCE_TYPE) &&
(ESFTPRT((RDF_Resource)v)) &&
(containerp((RDF_Resource)v))) {
ESRemoveChild((RDF_Resource)v, u);
retVal = PR_TRUE;
} else {
retVal = PR_FALSE;
}
return(retVal);
}
void
es_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx)
{
RDF_Resource parent = NULL, child = NULL, r;
_esFEData *feData;
char *newURL, *p;
feData = (_esFEData *)urls->fe_data;
if ((status >= 0) && (feData != NULL))
{
parent = RDF_GetResource(gNCDB, feData->parent, false);
child = RDF_GetResource(gNCDB, feData->child, false);
if ((parent != NULL) && (child != NULL))
{
switch(feData->method)
{
case URL_POST_METHOD:
if (((p = RDF_STRRCHR(resourceID(child), '/')) != NULL) && (*++p != '\0'))
{
if ((newURL = append2Strings(resourceID(parent), p)) != NULL)
{
if ((r = RDF_GetResource(gNCDB, newURL, 1)) != NULL)
{
setContainerp(r, containerp(child));
setResourceType(r, resourceType(child));
remoteStoreAdd(gRemoteStore, r,
gCoreVocab->RDF_parent, parent,
RDF_RESOURCE_TYPE, 1);
}
freeMem(newURL);
}
}
break;
case URL_DELETE_METHOD:
remoteStoreRemove(gRemoteStore, child,
gCoreVocab->RDF_parent, parent,
RDF_RESOURCE_TYPE);
break;
}
}
}
else if (status < 0)
{
if ((cx != NULL) && (urls != NULL) && (urls->error_msg != NULL))
{
FE_Alert(cx, urls->error_msg);
}
}
if (feData != NULL)
{
esFreeFEData(feData);
}
NET_FreeURLStruct (urls);
}
char *
nativeFilename(char *filename)
{
char *newName = NULL, *temp;
int x = 0;
if (filename == NULL) return(NULL);
if ((newName = unescapeURL(filename)) != NULL)
{
if ((temp = convertFileURLToNSPRCopaceticPath(newName)) != NULL)
{
temp = copyString(temp);
}
freeMem(newName);
newName = temp;
#ifdef XP_WIN
if (newName != NULL)
{
while (newName[x] != '\0')
{
if (newName[x] == '/')
{
newName[x] = '\\';
}
++x;
}
}
#endif
}
return(newName);
}
_esFEData *
esMakeFEData(RDF_Resource parent, RDF_Resource child, int method)
{
_esFEData *feData;
if ((feData = (_esFEData *)XP_ALLOC(3*sizeof(char *))) != NULL)
{
feData->parent = copyString(resourceID(parent));
feData->child = copyString(resourceID(child));
feData->method = method;
}
return(feData);
}
void
esFreeFEData(_esFEData *feData)
{
if (feData != NULL)
{
if (feData->parent) freeMem(feData->parent);
if (feData->child) freeMem(feData->child);
freeMem(feData);
}
}
/** go tell the directory that child got added to parent **/
void
ESAddChild (RDF_Resource parent, RDF_Resource child)
{
URL_Struct *urls;
void *feData, **files_to_post = NULL;
if ((urls = NET_CreateURLStruct(resourceID(parent), NET_SUPER_RELOAD)) != NULL)
{
feData = (void *)esMakeFEData(parent, child, URL_POST_METHOD);
if ((files_to_post = (char **)XP_ALLOC(2*sizeof(char *))) != NULL)
{
files_to_post[0] = nativeFilename(resourceID(child));
files_to_post[1] = NULL;
}
if ((feData != NULL) && (files_to_post != NULL))
{
urls->files_to_post = (void *)files_to_post;
urls->post_to = NULL;
urls->method = URL_POST_METHOD;
urls->fe_data = (void *)feData;
NET_GetURL(urls, FO_PRESENT,
(MWContext *)gRDFMWContext(NULL),
es_GetUrlExitFunc);
}
else
{
if (feData != NULL)
{
esFreeFEData(feData);
}
if (files_to_post != NULL)
{
if (files_to_post[0] != NULL) freeMem(files_to_post[0]);
XP_FREE(files_to_post);
}
NET_FreeURLStruct(urls);
}
}
}
/** remove the child from the directory **/
void
ESRemoveChild (RDF_Resource parent, RDF_Resource child)
{
URL_Struct *urls;
void *feData;
if ((urls = NET_CreateURLStruct(resourceID(child), NET_SUPER_RELOAD)) != NULL)
{
feData = (void *)esMakeFEData(parent, child, URL_DELETE_METHOD);
if (feData != NULL)
{
urls->method = URL_DELETE_METHOD;
urls->fe_data = (void *)feData;
NET_GetURL(urls, FO_PRESENT,
(MWContext *)gRDFMWContext(NULL),
es_GetUrlExitFunc);
}
else
{
NET_FreeURLStruct(urls);
}
}
}
void
parseNextESFTPLine (RDFFile f, char* line)
{
PRBool directoryp;
RDF_Resource ru;
char *token, *url;
int16 loop, tokenNum = 0;
int32 val;
if (f->fileType != FTP_RT && f->fileType != ES_RT) return;
/* work around bug where linefeeds are actually encoded as %0A */
if (endsWith("%0A", line)) line[RDF_STRLEN(line)-3] = '\0';
if ((token = strtok(line, " ")) != NULL)
{
/* skip 1st token (the numeric command) */
token = strtok(NULL, " \t");
}
if (startsWith("200:", line))
{
while (token != NULL)
{
while ((token != NULL) && (tokenNum < RDF_MAX_NUM_FILE_TOKENS))
{
if (!RDF_STRCMP(token, "Filename"))
{
f->tokens[f->numFileTokens].token = gCoreVocab->RDF_name;
f->tokens[f->numFileTokens].type = RDF_STRING_TYPE;
f->tokens[f->numFileTokens].tokenNum = tokenNum;
++(f->numFileTokens);
}
else if (!RDF_STRCMP(token, "Content-Length"))
{
f->tokens[f->numFileTokens].token = gWebData->RDF_size;
f->tokens[f->numFileTokens].type = RDF_INT_TYPE;
f->tokens[f->numFileTokens].tokenNum = tokenNum;
++(f->numFileTokens);
}
else if (!RDF_STRCMP(token, "File-type"))
{
f->tokens[f->numFileTokens].token = gWebData->RDF_description;
f->tokens[f->numFileTokens].type = RDF_STRING_TYPE;
f->tokens[f->numFileTokens].tokenNum = tokenNum;
++(f->numFileTokens);
}
else if (!RDF_STRCMP(token, "Last-Modified"))
{
f->tokens[f->numFileTokens].token = gWebData->RDF_lastModifiedDate;
f->tokens[f->numFileTokens].type = RDF_STRING_TYPE;
f->tokens[f->numFileTokens].tokenNum = tokenNum;
++(f->numFileTokens);
}
/*
else if (!RDF_STRCMP(token, "Permissions"))
{
f->tokens[f->numFileTokens].token = NULL;
f->tokens[f->numFileTokens].type = RDF_STRING_TYPE;
f->tokens[f->numFileTokens].tokenNum = tokenNum;
++(f->numFileTokens);
}
*/
++tokenNum;
token = strtok(NULL, " \t");
}
}
}
else if (startsWith("201:", line))
{
directoryp = false;
while (token != NULL)
{
for (loop=0; loop<f->numFileTokens; loop++)
{
if (tokenNum == f->tokens[loop].tokenNum)
{
f->tokens[loop].data = strdup(token);
if (f->tokens[loop].token == gWebData->RDF_description)
{
if (startsWith("Directory", token) ||
startsWith("Sym-Directory", token))
{
directoryp = true;
}
}
}
}
++tokenNum;
token = strtok(NULL, " \t");
}
ru = NULL;
for (loop=0; loop<f->numFileTokens; loop++)
{
/* find name, create resource from it */
if (f->tokens[loop].token == gCoreVocab->RDF_name)
{
if (resourceType(f->top) == ES_RT)
{
url = PR_smprintf("nes:%s%s%s", f->url, f->tokens[loop].data, (directoryp) ? "/":"");
}
else
{
url = PR_smprintf("%s%s%s", f->url, f->tokens[loop].data, (directoryp) ? "/":"");
}
if (url != NULL)
{
if ((ru = RDF_GetResource(NULL, url, 1)) != NULL)
{
setResourceType(ru, resourceType(f->top));
if (directoryp == true)
{
setContainerp(ru, 1);
}
XP_FREE(url);
}
}
break;
}
}
if (ru != NULL)
{
for (loop=0; loop<f->numFileTokens; loop++)
{
if (f->tokens[loop].data != NULL)
{
switch(f->tokens[loop].type)
{
case RDF_STRING_TYPE:
addSlotValue(f, ru, f->tokens[loop].token,
unescapeURL(f->tokens[loop].data),
f->tokens[loop].type, NULL);
break;
case RDF_INT_TYPE:
if (directoryp == false)
{
sscanf(f->tokens[loop].data, "%lu", &val);
if (val != 0)
{
addSlotValue(f, ru, f->tokens[loop].token,
(void *)val, f->tokens[loop].type, NULL);
}
}
break;
}
}
}
addSlotValue(f, ru, gCoreVocab->RDF_parent, f->top, RDF_RESOURCE_TYPE, NULL);
}
}
}
int
parseNextESFTPBlob(NET_StreamClass *stream, char* blob, int32 size)
{
RDFFile f;
int32 n, last, m;
n = last = 0;
f = (RDFFile)stream->data_object;
if (f == NULL || size < 0) {
return MK_INTERRUPTED;
}
while (n < size) {
char c = blob[n];
m = 0;
memset(f->line, '\0', f->lineSize);
if (f->holdOver[0] != '\0') {
memcpy(f->line, f->holdOver, RDF_STRLEN(f->holdOver));
m = RDF_STRLEN(f->holdOver);
memset(f->holdOver, '\0', RDF_BUF_SIZE);
}
while ((m < f->lineSize) && (c != '\r') && (c != '\n') && (n < size)) {
f->line[m] = c;
m++;
n++;
c = blob[n];
}
n++;
if (m > 0) {
if ((c == '\n') || (c == '\r')) {
last = n;
parseNextESFTPLine(f, f->line);
} else if (size > last) {
memcpy(f->holdOver, f->line, m);
}
}
}
return(size);
}

View File

@@ -0,0 +1,67 @@
/* -*- 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_ES2MCF_H_
#define _RDF_ES2MCF_H_
#include "rdf-int.h"
#include "net.h"
/* es2mcf.c data structures and defines */
typedef struct {
char *parent;
char *child;
int method;
} _esFEData;
/* es2mcf.c function prototypes */
NSPR_BEGIN_EXTERN_C
RDFT MakeESFTPStore (char* url);
_esFEData * esMakeFEData(RDF_Resource parent, RDF_Resource child, int method);
void esFreeFEData(_esFEData *feData);
void ESFTPPossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep) ;
RDF_Error ESInit (RDFT ntr);
PRBool ESFTPRT (RDF_Resource u);
PRBool ESAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool ESUnassert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool ESDBAdd (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool ESDBRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool ESHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
void * ESGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor ESGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * ESNextValue (RDFT mcf, RDF_Cursor c);
RDF_Error ESDisposeCursor (RDFT mcf, RDF_Cursor c);
void es_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx);
char * nativeFilename(char *filename);
void ESAddChild (RDF_Resource parent, RDF_Resource child);
void ESRemoveChild (RDF_Resource parent, RDF_Resource child);
void possiblyAccessES(RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep);
void parseNextESFTPLine (RDFFile f, char* line);
int parseNextESFTPBlob(NET_StreamClass *stream, char* blob, int32 size);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,372 @@
/* -*- Mode: C; tab-width: 8; 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 Find 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 "find2rdf.h"
/* globals */
static RDFT gRDFFindDB = NULL;
void
parseResourceIntoFindTokens(RDF_Resource u, findTokenStruct *tokens)
{
char *id, *token, *value;
int loop;
if ((id = copyString(resourceID(u) + RDF_STRLEN("find:"))) != NULL)
{
/* parse ID, build up token list */
if ((token = strtok(id, "&")) != NULL)
{
while (token != NULL)
{
if ((value = strstr(token, "=")) != NULL)
{
*value++ = '\0';
}
for (loop=0; tokens[loop].token != NULL; loop++)
{
if (!RDF_STRCMP(token, tokens[loop].token))
{
tokens[loop].value = copyString(value);
break;
}
}
token = strtok(NULL, "&");
}
}
freeMem(id);
}
}
RDF_Cursor
parseFindURL(RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv)
{
RDF_Cursor c = NULL;
RDF_Resource searchOn = NULL, matchOn = NULL;
int loop;
findTokenStruct tokens[5];
/* build up a token list */
tokens[0].token = "location"; tokens[0].value = NULL;
tokens[1].token = "attribute"; tokens[1].value = NULL;
tokens[2].token = "method"; tokens[2].value = NULL;
tokens[3].token = "value"; tokens[3].value = NULL;
tokens[4].token = NULL; tokens[4].value = NULL;
parseResourceIntoFindTokens(u, tokens);
if ((tokens[1].value != NULL) && (tokens[3].value != NULL))
{
if ((searchOn = RDF_GetResource(NULL, tokens[1].value, 0)) != NULL)
{
if ((matchOn = RDF_GetResource(NULL, tokens[2].value, 0)) == NULL)
{
matchOn = gCoreVocab->RDF_substring;
}
if ((c = getMem(sizeof(struct RDF_CursorStruct))) != NULL)
{
c->u = u;
c->s = s;
c->type = type;
c->tv = tv;
c->inversep = inversep;
c->count = 0;
/* Note: need to copy value string [its a local variable] */
c->pdata = (void *)RDF_Find(searchOn, matchOn,
copyString(tokens[3].value), RDF_STRING_TYPE);
if (c->pdata == NULL)
{
freeMem(c);
c = NULL;
}
}
}
}
/* free values in token list */
for (loop=0; tokens[loop].token != NULL; loop++)
{
if (tokens[loop].value != NULL)
{
freeMem(tokens[loop].value);
tokens[loop].value = NULL;
}
}
return(c);
}
RDF_Cursor
FindGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv)
{
RDF_Cursor c = NULL;
PRBool passThru = PR_TRUE;
if ((((s == gCoreVocab->RDF_child) && (!inversep)) ||
((s == gCoreVocab->RDF_parent) && (inversep))) &&
(type == RDF_RESOURCE_TYPE) && (tv))
{
if (startsWith("find:", resourceID(u)))
{
passThru = PR_FALSE;
c = parseFindURL(rdf, u, s, type, inversep, tv);
}
}
if (passThru == PR_TRUE)
{
c = remoteStoreGetSlotValues(rdf, u, s, type, inversep, tv);
}
return(c);
}
void *
findNextURL(RDF_Cursor c)
{
RDF_Resource r = NULL;
PRBool valid = PR_FALSE;
do
{
if ((r = (RDF_Resource)RDF_NextValue(c)) != NULL)
{
if (strstr(resourceID(r), ":"))
{
if ((!startsWith("find:", resourceID(r))) &&
(!startsWith("NC:", resourceID(r))) &&
(!startsWith("Command:", resourceID(r))))
{
valid = PR_TRUE;
}
}
}
} while((r != NULL) && (valid == PR_FALSE));
return((void *)r);
}
void *
FindNextValue(RDFT rdf, RDF_Cursor c)
{
PRBool passThru = PR_TRUE;
void *retVal = NULL;
PR_ASSERT(c != NULL);
if (c == NULL) return(NULL);
if ((c->u != NULL) && (((c->s == gCoreVocab->RDF_child) && (!(c->inversep))) ||
((c->s == gCoreVocab->RDF_parent) && (c->inversep))) &&
(c->type == RDF_RESOURCE_TYPE) && (c->tv))
{
if (startsWith("find:", resourceID(c->u)))
{
if (c->pdata != NULL)
{
passThru = PR_FALSE;
retVal = findNextURL((RDF_Cursor)(c->pdata));
}
}
}
if (passThru == PR_TRUE)
{
retVal = remoteStoreNextValue(rdf, c);
}
return(retVal);
}
void *
FindGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv)
{
void *retVal = NULL;
PRBool passThru = PR_TRUE;
if ((startsWith("find:", resourceID(u))) && (s == gCoreVocab->RDF_name))
{
/* DebugStr("\p FindGetSlotValue on name"); */
}
if (passThru == PR_TRUE)
{
retVal = remoteStoreGetSlotValue(rdf, u, s, type, inversep, tv);
}
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char*) retVal)));
return(retVal);
}
void
FindPossible(RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep)
{
RDF_Cursor c;
RDF_Resource r;
if ((startsWith("find:", resourceID(u))) && (containerp(u) &&
(((s == gCoreVocab->RDF_parent) && (inversep)) ||
((s == gCoreVocab->RDF_child) && (!inversep))) ))
{
if ((c = FindGetSlotValues (rdf, u, s, RDF_RESOURCE_TYPE, inversep, PR_TRUE)) != NULL)
{
while((r = (RDF_Resource)FindNextValue(rdf, c)) != NULL)
{
if (!remoteStoreHasAssertion (rdf, r, gCoreVocab->RDF_parent,
u, RDF_RESOURCE_TYPE, PR_TRUE))
{
remoteStoreAdd(rdf, r, gCoreVocab->RDF_parent,
u, RDF_RESOURCE_TYPE, PR_TRUE);
}
}
RDF_DisposeCursor(c);
}
}
}
RDF_Error
FindDisposeCursor(RDFT mcf, RDF_Cursor c)
{
RDF_Error err = noRDFErr;
char *value;
if (c != NULL)
{
if ((((c->s == gCoreVocab->RDF_child) && (!(c->inversep))) ||
((c->s == gCoreVocab->RDF_parent) && (c->inversep))) &&
(c->type == RDF_RESOURCE_TYPE) && (c->tv))
{
if (startsWith("find:", resourceID(c->u)))
{
if (c->pdata != NULL)
{
/* Note: at creation, we had to copy "v",
so free it here */
if ((value = ((RDF_Cursor)(c->pdata))->value) != NULL)
{
freeMem(value);
((RDF_Cursor)(c->pdata))->value = NULL;
}
RDF_DisposeCursor((RDF_Cursor)(c->pdata));
c->pdata = NULL;
}
}
freeMem(c);
}
else
{
err = remoteStoreDisposeCursor (mcf, c);
}
}
return(0);
}
void
findPossiblyAddName(RDFT rdf, RDF_Resource u)
{
findTokenStruct tokens[5];
char *name;
if ((name = (char *)remoteStoreGetSlotValue(rdf, u, gCoreVocab->RDF_name,
RDF_STRING_TYPE, PR_FALSE, PR_TRUE)) == NULL)
{
/* build up a token list */
tokens[0].token = "location"; tokens[0].value = NULL;
tokens[1].token = "attribute"; tokens[1].value = NULL;
tokens[2].token = "method"; tokens[2].value = NULL;
tokens[3].token = "value"; tokens[3].value = NULL;
tokens[4].token = NULL; tokens[4].value = NULL;
parseResourceIntoFindTokens(u, tokens);
if ((name = PR_smprintf(XP_GetString(RDF_FIND_FULLNAME_STR),
((tokens[1].value != NULL) ? tokens[1].value : ""),
((tokens[2].value != NULL) ? tokens[2].value : ""),
((tokens[3].value != NULL) ? tokens[3].value : ""))) != NULL)
{
remoteStoreAdd(rdf, u, gCoreVocab->RDF_name, name,
RDF_STRING_TYPE, PR_TRUE);
}
}
}
PRBool
FindAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
/* don't handle the assert, but simply add a name if it doesn't already have one */
if (startsWith("find:", resourceID(u)))
{
findPossiblyAddName(rdf, u);
}
return(PR_FALSE);
}
RDFT
MakeFindStore (char *url)
{
RDFT ntr = NULL;
if (gRDFFindDB != NULL) return(gRDFFindDB);
if (strstr(url, "rdf:find"))
{
if ((ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct))) != NULL)
{
ntr->assert = FindAssert;
ntr->unassert = NULL;
ntr->hasAssertion = remoteStoreHasAssertion;
ntr->getSlotValue = FindGetSlotValue;
ntr->getSlotValues = FindGetSlotValues;
ntr->nextValue = FindNextValue;
ntr->disposeCursor = FindDisposeCursor;
ntr->possiblyAccessFile = FindPossible;
ntr->destroy = NULL;
ntr->url = copyString(url);
gRDFFindDB = ntr;
}
}
return(ntr);
}

View File

@@ -0,0 +1,52 @@
/* -*- Mode: C; tab-width: 8; 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_FIND_H_
#define _RDF_FIND_H_
#include "rdf-int.h"
#include "utils.h"
/* find.c data structures and defines */
typedef struct _findTokenStruct {
char *token;
char *value;
} findTokenStruct;
/* find.c function prototypes */
NSPR_BEGIN_EXTERN_C
void parseResourceIntoFindTokens(RDF_Resource u, findTokenStruct *tokens);
RDF_Cursor parseFindURL(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor FindGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * findNextURL(RDF_Cursor c);
void * FindNextValue(RDFT rdf, RDF_Cursor c);
void * FindGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void FindPossible(RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep);
RDF_Error FindDisposeCursor(RDFT mcf, RDF_Cursor c);
void findPossiblyAddName(RDFT rdf, RDF_Resource u);
PRBool FindAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
RDFT MakeFindStore (char* url);
NSPR_END_EXTERN_C
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,84 @@
/* -*- 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_FS2RDF_H_
#define _RDF_FS2RDF_H_
#include "rdf-int.h"
#include "xp_mem.h"
#include "client.h"
#include "prio.h"
#include "prlong.h"
#include "nlcstore.h"
#include "remstore.h"
#ifdef XP_MAC
#include <Appletalk.h>
#include <Devices.h>
#include <Files.h>
#include <FinderRegistry.h>
#include <Folders.h>
#include <Processes.h>
#include "FullPath.h"
#endif
/* fs2rdf.c data structures and defines */
extern int RDF_VOLUME_DESC_STR, RDF_DIRECTORY_DESC_STR, RDF_FILE_DESC_STR;
#define fsUnitp(u) (resourceType(u) == LFS_RT)
#define XP_DIRECTORY_SEPARATOR '/'
/* fs2rdf.c function prototypes */
NSPR_BEGIN_EXTERN_C
#ifdef XP_MAC
OSErr nativeMacPathname(char *fileURL, FSSpec *fss);
OSErr getPSNbyTypeSig(ProcessSerialNumber *thePSN, OSType pType, OSType pSignature);
#endif
void importForProfile (char *dir, const char *uname);
void GuessIEBookmarks(void);
char * getVolume(int16 volNum, PRBool afpVols);
PRDir * OpenDir(char *name);
RDFT MakeLFSStore (char* url);
PRBool fsAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool fsRemoveFile(char *filePathname, PRBool justCheckWriteAccess);
PRBool fsRemoveDir(char *filePathname, PRBool justCheckWriteAccess);
PRBool fsUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool fsHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
void * fsGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
PRBool fileDirectoryp(RDF_Resource u);
RDF_Cursor fsGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * fsNextValue (RDFT rdf, RDF_Cursor c);
PRBool isFileVisible(char *fileURL);
RDF_Error fsDisposeCursor (RDFT rdf, RDF_Cursor c);
RDF_Resource CreateFSUnit (char* nname, PRBool isDirectoryFlag);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,469 @@
/* -*- Mode: C; tab-width: 8; 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 contains the glue code that links the RDF module with
* ugly navigator stuff including Netlib for getURL, preferences for
* finding out where bookmarks.htm and lclstore.mcf are located. By
* changing this glue file, one should be able to use the rest of the
* RDF library with something else (like the server).
* 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 "rdf-int.h"
#include "glue.h"
#include "remstore.h"
#include "rdfparse.h"
#include "es2mcf.h"
#include "mcff2mcf.h"
#include "nlcstore.h"
#include "autoupdt.h"
#include "ht.h"
#ifdef NU_CACHE
#include "CacheStubs.h"
#endif
/* external routines */
extern MWContext *FE_GetRDFContext(void);
extern char *gDefaultNavcntr;
extern RDF gNCDB;
unsigned int
rdf_write_ready(NET_StreamClass *stream)
{
return MAX_WRITE_READY;
}
void
rdf_complete(NET_StreamClass *stream)
{
RDFFile f = (RDFFile)stream->data_object;
if (RDF_STRCMP(f->url, gNavCntrUrl) == 0) {
if (f->resourceCount == 0) {
parseNextRDFXMLBlob(stream, gDefaultNavcntr, RDF_STRLEN(gDefaultNavcntr));
} else {
RDF_Resource browser = RDF_GetResource(NULL, "netscape:browser", 1);
RDF_Resource updateFrom = RDF_GetResource(NULL, "updateURL", 1);
char* uf = RDF_GetSlotValue(gNCDB, browser, updateFrom,
RDF_STRING_TYPE, false, true);
RDF_Resource fileSize = RDF_GetResource(NULL, "fileSize", 1);
char* fs = RDF_GetSlotValue(gNCDB, browser, fileSize,
RDF_STRING_TYPE, false, true);
uint32 fSize;
if (fs == NULL) {
fSize = 3000;
} else {
sscanf("%lu", fs, &fSize);
freeMem(fs);
}
if (uf != NULL) {
#ifdef MOZ_SMARTUPDATE
checkForAutoUpdate((void *)FE_GetRDFContext(), uf, fSize);
#endif /* MOZ_SMARTUPDATE */
freeMem(uf);
}
/* A temporary hack to demo AutoUpdate on windows */
#ifndef MOZ_SMARTUPDATE
#ifdef XP_WIN
checkForAutoUpdate((void *)FE_GetRDFContext(), "http://warp/u/raman/gromit/softupdt.exe", 45328);
#endif /* XP_WIN */
#endif /* MOZ_SMARTUPDATE */
}
}
if (f) {
freeMem(f->line);
freeMem(f->currentSlot);
freeMem(f->holdOver);
freeNamespaces(f) ;
f->line = NULL;
f->currentSlot = NULL;
f->holdOver = NULL;
}
}
void
rdf_abort(NET_StreamClass *stream, int status)
{
RDFFile f = (RDFFile)stream->data_object;
if (RDF_STRCMP(f->url, gNavCntrUrl) == 0) {
parseNextRDFXMLBlob(stream, gDefaultNavcntr, RDF_STRLEN(gDefaultNavcntr));
}
if (f) {
f->locked = false;
gcRDFFile (f);
freeMem(f->line);
freeMem(f->currentSlot);
freeMem(f->holdOver);
freeNamespaces(f) ;
}
}
#ifdef MOZILLA_CLIENT
#ifdef XP_MAC
PR_PUBLIC_API(NET_StreamClass *)
#else
PUBLIC NET_StreamClass *
#endif
int
parseNextRDFXMLBlob (NET_StreamClass *stream, char* blob, int32 size)
{
RDFFile f;
f = (RDFFile)stream->data_object;
if ((f == NULL) || (size < 0)) {
return MK_INTERRUPTED;
}
return parseNextRDFXMLBlobInt(f, blob, size);
}
rdf_Converter(FO_Present_Types format_out, void *client_data,
URL_Struct *urls, MWContext *cx)
{
RDFFile rdfFile;
MKStreamWriteFunc writeFunc = NULL;
if ((urls == NULL) || (urls->fe_data == NULL))
{
return(NULL);
}
/* determine appropriate write function to use */
rdfFile = urls->fe_data;
switch(rdfFile->fileType)
{
/* case ES_RT:
case FTP_RT:
writeFunc = (MKStreamWriteFunc)parseNextESFTPBlob;
break;
*/
default:
writeFunc = (MKStreamWriteFunc)parseNextRDFXMLBlob;
break;
}
/* allocate stream data block */
return NET_NewStream("RDF", writeFunc,
(MKStreamCompleteFunc)rdf_complete,
(MKStreamAbortFunc)rdf_abort,
(MKStreamWriteReadyFunc)rdf_write_ready,
urls->fe_data, cx);
}
void
rdf_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx)
{
RDFFile f;
char *navCenterURL = NULL;
if ((status < 0) && (urls != NULL))
{
if ((cx != NULL) && (urls->error_msg != NULL))
{
FE_Alert(cx, urls->error_msg);
}
/* if unable to read in navcntr.rdf file, create some default views */
if ((f = (RDFFile) urls->fe_data) != NULL)
{
if (RDF_STRCMP(f->url, gNavCntrUrl) == 0)
{
parseNextRDFXMLBlobInt(f, gDefaultNavcntr,
RDF_STRLEN(gDefaultNavcntr));
}
}
}
if (urls != NULL)
{
if ((f = (RDFFile) urls->fe_data) != NULL)
{
htLoadComplete(f->url, status);
}
}
NET_FreeURLStruct (urls);
}
/*
int
rdfRetrievalType (RDFFile f)
{
URL_Struct *urls;
char *url;
int type;
url = f->url;
if (f->localp)
{
urls = NET_CreateURLStruct(url, NET_CACHE_ONLY_RELOAD);
if ((urls != NULL) && (NET_IsURLInDiskCache(urls) || NET_IsURLInMemCache(urls)))
{
type = NET_DONT_RELOAD;
}
else
{
type = NET_NORMAL_RELOAD;
}
if (urls != NULL) NET_FreeURLStruct(urls);
}
else
{
type = NET_NORMAL_RELOAD;
}
return(type);
}
*/
int
rdf_GetURL (MWContext *cx, int method, Net_GetUrlExitFunc *exit_routine, RDFFile rdfFile)
{
URL_Struct *urls = NULL;
char* url ;
#ifdef DEBUG_gagan
return 0;
#endif
if (cx == NULL) return 0;
if (rdfFile->refreshingp && rdfFile->updateURL) {
url = rdfFile->updateURL;
} else {
url = rdfFile->url;
}
if (RDF_STRCMP(url, gNavCntrUrl) == 0) {
urls = NET_CreateURLStruct(url, NET_CACHE_ONLY_RELOAD);
#ifdef NU_CACHE
if (!CacheManager_Contains(url)) {
#else
if (NET_IsURLInDiskCache(urls) || NET_IsURLInMemCache(urls)) {
} else {
#endif
NET_FreeURLStruct(urls);
urls = NULL;
}
}
if (!urls)
urls = NET_CreateURLStruct(url, (rdfFile->refreshingp ?
NET_SUPER_RELOAD : NET_NORMAL_RELOAD));
if (urls == NULL) return 0;
urls->fe_data = rdfFile;
if (method) urls->method = method;
NET_GetURL(urls, FO_CACHE_AND_RDF, cx, rdf_GetUrlExitFunc);
return 1;
}
#endif /* MOZILLA_CLIENT */
void
possiblyRereadRDFFiles (void* data)
{
possiblyRefreshRDFFiles();
/* timerID = FE_SetTimeout(possiblyRereadRDFFiles, NULL, 1000 * 60 * 10);
once every 10 minutes
diabled for legal reasons.*/
}
void
RDFglueInitialize()
{
#ifdef MOZILLA_CLIENT
timerID = FE_SetTimeout(possiblyRereadRDFFiles, NULL, 1000 * 60 * 10); /* once every 10 minutes */
if (gRLForbiddenDomains != NULL)
{
freeMem(gRLForbiddenDomains);
gRLForbiddenDomains = NULL;
}
if (PREF_CopyCharPref("browser.relatedLinksDisabledForDomains", &gRLForbiddenDomains) != PREF_OK)
{
gRLForbiddenDomains = NULL;
}
#endif /* MOZILLA_CLIENT */
}
void
RDFglueExit (void)
{
#ifdef MOZILLA_CLIENT
if (timerID != NULL)
{
/* commented out as the timer's window has already been destroyed */
/* FE_ClearTimeout(timerID); */
timerID = NULL;
}
#endif /* MOZILLA_CLIENT */
}
void *
gRDFMWContext(RDFT db)
{
#ifndef MOZILLA_CLIENT
return NULL;
#else
void *cx;
RDFL rdf = NULL;
if (db) rdf = db->rdf;
while (rdf) {
if (rdf->rdf->context) return (rdf->rdf->context);
rdf = rdf->next;
}
cx = (void *)FE_GetRDFContext();
return(cx);
#endif
}
/*
* beginReadingRDFFile is called whenever we need to read something of
* the net (or local drive). The url of the file to be read is at
* file->url. As the bits are read in (and it can take the bits in
* any sized chunks) it should call parseNextRDFBlob(file, nextBlock,
* blobSize) when its done, it should call void finishRDFParse
* (RDFFile f) to abort, it should call void abortRDFParse (RDFFile f)
* [which will undo all that has been read from that file]
*/
void
beginReadingRDFFile (RDFFile file)
{
char *url;
int method = 0;
#ifndef MOZILLA_CLIENT
/* If standalone, we just use to open the file */
NET_StreamClass stream;
PRFileDesc *fd;
PRFileInfo fi;
PRBool bSuccess = FALSE;
url = file->url;
fd = CallPROpenUsingFileURL(url, PR_RDONLY, 0);
if(fd)
{
if(PR_GetOpenFileInfo(fd, &fi) == PR_SUCCESS)
{
char* buf = malloc(fi.size);
if(PR_Read(fd, buf, fi.size))
{
stream.data_object = file;
if(parseNextRDFXMLBlob (&stream, buf, fi.size))
bSuccess = TRUE;
}
free(buf);
}
PR_Close(fd);
}
if(bSuccess == TRUE)
rdf_complete(&stream);
#else
/*
XXX this is the pre-raptor world
url = file->url;
if (file->fileType == ES_RT) method = URL_INDEX_METHOD;
rdf_GetURL (gRDFMWContext(file->db), method, NULL, file);
*/
rdfStreamListener* pListener = new rdfStreamListener;
pListener->AddRef(); // XXX is this evil? Can't see any reason to use factories but...
#endif
}
#ifdef MOZILLA_CLIENT
DB *
CallDBOpenUsingFileURL(char *fileURL, int flags,int mode, DBTYPE type, const void *openinfo)
{
DB *result;
char *path;
char *escapedPath;
if (fileURL == NULL) return NULL;
escapedPath = unescapeURL(fileURL);
#ifdef XP_MAC
path = WH_FilePlatformName(convertFileURLToNSPRCopaceticPath(fileURL));
PR_ASSERT(path != NULL);
#else
path = convertFileURLToNSPRCopaceticPath(escapedPath);
#endif
result = dbopen(path, flags, mode, type, openinfo);
#ifdef XP_MAC
XP_FREE(path);
#endif
if (escapedPath != NULL) freeMem(escapedPath);
return result;
}
#else
#if defined(XP_WIN) && defined(DEBUG)
/* Some XP functions that are implemented in winfe
* in the client.
*/
void XP_AssertAtLine( char *pFileName, int iLine )
{
fprintf(stderr, "assert: line %d, file %s%c\n", __LINE__, pFileName, 7);
}
char* NOT_NULL(const char* x)
{
return (char*)x;
}
#endif
#endif

View File

@@ -0,0 +1,90 @@
/* -*- 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_GLUE_H_
#define _RDF_GLUE_H_
#include "xp.h"
#include "xp_mem.h"
#include "net.h"
#include "ntypes.h"
#include "fe_proto.h"
#include "prinit.h"
#ifdef XP_UNIX
#include <sys/fcntl.h>
#elif defined(XP_MAC)
#include <fcntl.h>
#endif
#include "rdf.h"
#include "rdf-int.h"
#include "ht.h"
#define APPLICATION_RDF "application/x-rdf" /* XXX what should these be? */
#define EXTENSION_RDF ".rdf"
#define EXTENSION_MCF ".mcf"
/* external globals */
extern char* gLocalStoreURL;
extern char* gBookmarkURL;
/* glue.c prototypes */
NSPR_BEGIN_EXTERN_C
void ht_fprintf(PRFileDesc *file, const char *fmt, ...);
unsigned int rdf_write_ready(NET_StreamClass *stream);
void rdf_complete(NET_StreamClass *stream);
void rdf_abort(NET_StreamClass *stream, int status);
NET_StreamClass * rdf_Converter(FO_Present_Types format_out,
void *client_data, URL_Struct *urls, MWContext *cx);
void rdf_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx);
int rdfRetrievalType (RDFFile f);
int rdf_GetURL (MWContext *cx, int method,
Net_GetUrlExitFunc *exit_routine, RDFFile rdfFile);
void possiblyRereadRDFFiles (void* data);
void RDFglueInitialize (void);
void RDFglueExit (void);
void *gRDFMWContext(RDFT db);
void beginReadingRDFFile (RDFFile file);
void readLocalFile (RDFFile file);
char *unescapeURL(char *inURL);
char *convertFileURLToNSPRCopaceticPath(char* inURL);
PRFileDesc *CallPROpenUsingFileURL(char *fileURL, PRIntn flags, PRIntn mode);
PRDir *CallPROpenDirUsingFileURL(char *fileURL);
int32 CallPRWriteAccessFileUsingFileURL(char *fileURL);
int32 CallPRDeleteFileUsingFileURL(char *fileURL);
int CallPR_RmDirUsingFileURL(char *dirURL);
int32 CallPRMkDirUsingFileURL(char *dirURL, int mode);
DB *CallDBOpenUsingFileURL(char *fileURL, int flags,int mode,
DBTYPE type, const void *openinfo);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,675 @@
/* -*- Mode: C; tab-width: 8; 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 History 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 "hist2rdf.h"
#include "remstore.h"
#include "utils.h"
static PRBool histInFlatFilep = 0;
/* extern declarations */
void GH_DeleteHistoryItem (char * url);
PR_PUBLIC_API(void) updateNewHistItem (DBT *key, DBT *data); /* XXX this should be elsewhere */
/* externs */
extern char *profileDirURL;
extern char *gGlobalHistoryURL;
/* external string references in allxpstr */
extern int RDF_WEEKOF, RDF_WITHINLASTHOUR, RDF_TODAY, RDF_DAY_0;
extern int RDF_RELATEDLINKSNAME;
/* globals */
PLHashTable *hostHash = 0;
RDFT grdf = NULL;
RDFT gHistoryStore = 0;
PRBool ByDateOpened = 0;
PRBool historyInitialized = 0;
static int saveCount = 0;
char *prefixList[] = {
"about:", "javascript:", "livescript:", "mailbox:", "mailto:",
"mocha:", "news:", "pop3", "snews:", "view-source", "wysiwyg:", NULL
};
char *suffixList[] = {
".gif", ".jpg", ".jpeg", ".xbm", ".pfr", ".class", ".tmp", ".js", ".rdf",
".mcf", ".mco", NULL
};
char *intermediateList[] = {
".gif", ".GIF", NULL
};
void
collateHistory (RDFT r, RDF_Resource u, PRBool byDateFlag)
{
HASHINFO hash = { 4*1024, 0, 0, 0, 0, 0};
DBT key, data;
time_t last,first;
uint32 numaccess;
PRBool firstOne = 0;
DB* db = CallDBOpenUsingFileURL(gGlobalHistoryURL, O_RDONLY ,0600,
DB_HASH, &hash);
grdf = r;
if (db != NULL) {
while (0 == (*db->seq)(db, &key, &data, (firstOne ? R_NEXT : R_FIRST))) {
char* title = ((char*)data.data + 16); /* title */
char* url = (char*)key.data; /* url */
/* int32 flag = (int32)*((char*)data.data + 3*sizeof(int32)); */
int32 flag;
HIST_COPY_INT32(&flag, (int8 *)data.data + 3 * sizeof(int32));
firstOne = 1;
#ifdef XP_UNIX
if ((/*1 == flag &&*/ displayHistoryItem((char*)key.data))) {
#else
if (1 == flag && displayHistoryItem((char*)key.data)) {
#endif
HIST_COPY_INT32(&last, (time_t *)((int8 *)data.data));
HIST_COPY_INT32(&first, (time_t *)((int8 *)data.data + sizeof(int32)));
HIST_COPY_INT32(&numaccess, (time_t *)((int8 *)data.data + 2*sizeof(int32)));
collateOneHist(r, u,url,title, last, first, numaccess, byDateFlag);
}
}
(*db->close)(db);
}
}
void
collateOneHist (RDFT r, RDF_Resource u, char* url, char* title, time_t lastAccessDate,
time_t firstAccessDate, uint32 numAccesses, PRBool byDateFlag)
{
char buffer[128];
struct tm *time;
RDF_Resource hostUnit, urlUnit;
char* existingName = NULL;
uint32 oldNumAccess = 0;
if (startsWith("404", title)) return;
urlUnit = HistCreate(url, 1);
existingName = remoteStoreGetSlotValue(gLocalStore, urlUnit, gCoreVocab->RDF_name, RDF_STRING_TYPE, 0, 1);
PR_ASSERT( IsUTF8String((const char* )existingName));
if (existingName == NULL) {
if (title[0] != '\0') remoteAddName(urlUnit, title);
} else freeMem(existingName);
if (byDateFlag) {
hostUnit = hostUnitOfDate(r, u, lastAccessDate);
} else {
hostUnit = hostUnitOfURL(r, u, urlUnit, title);
}
if (hostUnit == NULL) return;
if (hostUnit != urlUnit) remoteAddParent(urlUnit, hostUnit);
if ((time = localtime((time_t *) &lastAccessDate)) != NULL)
{
#ifdef XP_MAC
time->tm_year += 4;
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#elif XP_UNIX
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#else
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_WINDATE),time);
#endif
PR_ASSERT( IsUTF8String((const char* )buffer));
remoteStoreAdd(gRemoteStore, urlUnit, gWebData->RDF_lastVisitDate,
(void *)copyString(buffer), RDF_STRING_TYPE, 1);
}
if ((time = localtime((time_t *) &firstAccessDate)) != NULL)
{
#ifdef XP_MAC
time->tm_year += 4;
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#elif XP_UNIX
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_MACDATE),time);
#else
strftime(buffer,sizeof(buffer),XP_GetString(RDF_HTML_WINDATE),time);
#endif
PR_ASSERT( IsUTF8String((const char* )buffer));
remoteStoreAdd(gRemoteStore, urlUnit, gWebData->RDF_firstVisitDate,
(void *)copyString(buffer), RDF_STRING_TYPE, 1);
}
/* oldNumAccess = remoteStoreGetSlotValue(gHistoryStore, urlUnit, gWebData->RDF_numAccesses,
RDF_INT_TYPE, 0, 1);
if (oldNumAccess) remoteStoreRemove(gHistoryStore, urlUnit, gWebData->RDF_numAccesses, oldNumAccess,
RDF_INT_TYPE);
if (numAccesses==0) ++numAccesses;
remoteStoreAdd(gHistoryStore, urlUnit, gWebData->RDF_numAccesses,
(void *)numAccesses, RDF_INT_TYPE, 1); */
if (numAccesses > 5) histAddParent(urlUnit, gNavCenter->RDF_HistoryMostVisited);
}
RDF_Resource
hostUnitOfURL (RDFT r, RDF_Resource top, RDF_Resource nu, char* title)
{
char host[100];
char* url = resourceID(nu);
int16 s1, s2, s3;
RDF_Resource hostResource, existing;
if (RDF_STRLEN(url) > 100) return NULL;
if (startsWith("file", url)) {
return RDF_GetResource(NULL, "Local Files", 1);
} else {
memset(host, '\0', 100);
s1 = charSearch(':', url)+3;
s2 = charSearch('/', &url[s1]);
s3 = charSearch(':', &url[s1]);
if (s2 == -1) s2 = RDF_STRLEN(url)-s1;
if ((s3 != -1) && (s2 > s3)) s2 = s3;
if (startsWith("www", &url[s1])) {s1 = s1+4; s2 = s2-4;}
if (s2<1) return(NULL);
memcpy((char*)host, &url[s1], s2);
host[0] = toupper(host[0]);
hostResource = RDF_GetResource(NULL, host, 1);
setContainerp(hostResource, 1);
setResourceType(hostResource, HISTORY_RT);
existing = PL_HashTableLookup(hostHash, hostResource);
if (existing != NULL) {
if (existing == nu) {
return existing;
} else if (existing == top) {
return hostResource;
} else {
remoteStoreRemove(gHistoryStore, existing, gCoreVocab->RDF_parent, top, RDF_RESOURCE_TYPE);
histAddParent(existing, hostResource);
histAddParent(hostResource, top);
PL_HashTableAdd(hostHash, hostResource, top);
return hostResource;
}
} else {
PL_HashTableAdd(hostHash, hostResource, nu);
histAddParent(nu, top);
return nu;
}
}
}
void
hourRange(char *buffer, struct tm *theTm)
{
char *startHourStr="AM",*endHourStr="AM";
if (theTm->tm_hour > 0 && theTm->tm_hour < 12) {
sprintf(buffer, "AM");
} else {
sprintf(buffer, "PM");
}
}
RDF_Resource
hostUnitOfDate (RDFT r, RDF_Resource u, time_t lastAccessDate)
{
RDF_Resource node = NULL, parentNode;
/*
RDF_Resources std;
*/
time_t now, tempTime;
struct tm *T,nowStruct, dateStruct;
char hourBuffer[128], dayBuffer[128], weekBuffer[128];
char bigBuffer[1024];
int numDays;
/* NOTE: localtime uses a single static buffer, so MUST copy contents out */
time((time_t *)&now);
if ((T = localtime(&now)) == NULL) return(NULL);
nowStruct = *T;
if ((T = localtime(&lastAccessDate)) == NULL) return(NULL);
dateStruct = *T;
bigBuffer[0] = hourBuffer[0] = dayBuffer[0] = weekBuffer[0] = 0;
if (now < (lastAccessDate + SECS_IN_HOUR)) /* within the last hour */
{
strcpy(hourBuffer, XP_GetString(RDF_WITHINLASTHOUR));
}
else if ((nowStruct.tm_year == dateStruct.tm_year) && /* some time today */
(nowStruct.tm_yday == dateStruct.tm_yday))
{
strcpy(dayBuffer, XP_GetString(RDF_TODAY));
hourRange(hourBuffer, &dateStruct);
}
else /* check if within last week */
{
numDays = 7;
do
{
now -= SECS_IN_DAY;
if ((T = localtime(&now)) == NULL) return(NULL);
nowStruct = *T;
if ((nowStruct.tm_year == dateStruct.tm_year) &&
(nowStruct.tm_yday == dateStruct.tm_yday))
{
sprintf(dayBuffer, "%d/%d - %s",
(uint) dateStruct.tm_mon + 1, (uint)dateStruct.tm_mday,
XP_GetString(RDF_DAY_0 + nowStruct.tm_wday));
hourRange(hourBuffer, &dateStruct);
break;
}
} while (numDays-- > 0);
if (dayBuffer[0] == '\0') /* older than a week */
{
tempTime = lastAccessDate;
numDays = dateStruct.tm_wday;
while (numDays-- > 0)
{
tempTime -= SECS_IN_DAY;
}
if ((T = localtime(&tempTime)) == NULL) return(NULL);
dateStruct = *T;
#ifdef XP_MAC
/* Mac epoch according to localtime is 1904 */
PR_snprintf(weekBuffer, sizeof(weekBuffer)-1, XP_GetString(RDF_WEEKOF), (uint)dateStruct.tm_mon + 1,
(int)dateStruct.tm_mday, (uint)dateStruct.tm_year + 1904);
#else
PR_snprintf(weekBuffer, sizeof(weekBuffer)-1, XP_GetString(RDF_WEEKOF), (uint)dateStruct.tm_mon + 1,
(int)dateStruct.tm_mday, (uint)dateStruct.tm_year + 1900);
#endif
if ((T = localtime(&lastAccessDate)) == NULL) return(NULL);
dateStruct = *T;
#ifdef XP_MAC
/* Mac epoch according to localtime is 1904 */
sprintf(dayBuffer, "%s - %d/%d/%d",
XP_GetString(RDF_DAY_0 + dateStruct.tm_wday), (uint) dateStruct.tm_mon + 1,
(uint)dateStruct.tm_mday, (uint)dateStruct.tm_year + 1904);
#else
sprintf(dayBuffer, "%s - %d/%d/%d",
XP_GetString(RDF_DAY_0 + dateStruct.tm_wday), (uint) dateStruct.tm_mon + 1,
(uint)dateStruct.tm_mday, (uint)dateStruct.tm_year + 1900);
#endif
hourRange(hourBuffer, &dateStruct);
}
}
parentNode = u;
if (weekBuffer[0] != '\0')
{
if ((node = RDF_GetResource(NULL, weekBuffer, false)) == NULL)
{
if ((node = RDF_GetResource(NULL, weekBuffer, true)) == NULL) return(NULL);
}
setContainerp(node, 1);
setResourceType(node, HISTORY_RT);
remoteStoreAdd(gHistoryStore, node, gCoreVocab->RDF_parent,
parentNode, RDF_RESOURCE_TYPE, 1);
PR_ASSERT( IsUTF8String((const char* )weekBuffer));
remoteStoreAdd(gHistoryStore, node, gCoreVocab->RDF_name,
copyString(weekBuffer), RDF_STRING_TYPE, 1);
parentNode = node;
}
if (dayBuffer[0] != '\0')
{
sprintf(bigBuffer, "%d/%d", (uint) dateStruct.tm_mon + 1,
(uint)dateStruct.tm_mday);
if ((node = RDF_GetResource(NULL, bigBuffer, false)) == NULL)
{
if ((node = RDF_GetResource(NULL, bigBuffer, true)) == NULL) return(NULL);
}
setContainerp(node, 1);
setResourceType(node, HISTORY_RT);
histAddParent(node, parentNode);
sprintf(bigBuffer,"%s - %s",weekBuffer,dayBuffer);
PR_ASSERT( IsUTF8String((const char* )dayBuffer));
remoteStoreAdd(gHistoryStore, node, gCoreVocab->RDF_name,
copyString(dayBuffer), RDF_STRING_TYPE, 1);
parentNode = node;
}
if (hourBuffer[0] == 'W')
{
sprintf(bigBuffer, "%s", hourBuffer);
if ((node = RDF_GetResource(NULL, bigBuffer, false)) == NULL)
{
if ((node = RDF_GetResource(NULL, bigBuffer, true)) == NULL) return(NULL);
}
setContainerp(node, 1);
setResourceType(node, HISTORY_RT);
remoteStoreAdd(gHistoryStore, node, gCoreVocab->RDF_parent,
parentNode, RDF_RESOURCE_TYPE, 1);
PR_ASSERT( IsUTF8String((const char* )hourBuffer));
remoteStoreAdd(gHistoryStore, node, gCoreVocab->RDF_name,
copyString(hourBuffer), RDF_STRING_TYPE, 1);
parentNode = node;
}
return (node);
}
void
saveHistory ()
{
char* escapedPath = unescapeURL(gGlobalHistoryURL);
char* path = WH_FilePlatformName(convertFileURLToNSPRCopaceticPath(escapedPath));
PRFileDesc* file = PR_Open(path, PR_WRONLY | PR_CREATE_FILE, 00200);
char* hist;
if (file != NULL) {
hist = RDF_SerializeRDFStore(gHistoryStore) ;
if (hist != NULL) {
PR_Write(file, hist, RDF_STRLEN(hist));
}
}
freeMem(path);
freeMem(escapedPath);
PR_Close(file);
}
PR_PUBLIC_API(void)
updateNewHistItem (DBT *key, DBT *data)
{
time_t last,first,numaccess;
int32 flg = (int32)*((char*)data->data + 3*sizeof(int32));
if (!displayHistoryItem((char*)key->data)) return;
if (historyInitialized && (gHistoryStore != NULL)) {
HIST_COPY_INT32(&last, (time_t *)((char *)data->data));
HIST_COPY_INT32(&first, (time_t *)((char *)data->data + sizeof(int32)));
HIST_COPY_INT32(&numaccess, (time_t *)((char *)data->data + 2*sizeof(int32)));
if (hostHash) collateOneHist(grdf, gNavCenter->RDF_HistoryBySite,
(char*)key->data, /* url */
((char*)data->data + 4*sizeof(int32)), /* title */
last, first, numaccess, 0);
if (ByDateOpened) collateOneHist(grdf, gNavCenter->RDF_HistoryByDate,
(char*)key->data, /* url */
((char*)data->data + 4*sizeof(int32)), /* title */
last, first, numaccess, 1);
saveCount++;
if (saveCount > 5) {
if (histInFlatFilep) saveHistory();
saveCount = 0;
}
}
}
/** History clustering utils **/
PRBool
displayHistoryItem (char* url)
{
int x;
x=0;
while (prefixList[x]) {
if (startsWith(prefixList[x++], url)) return 0;
}
x=0;
while (suffixList[x]) {
if (endsWith(suffixList[x++], url)) return 0;
}
x=0;
while (intermediateList[x]) {
if (strstr(url, intermediateList[x++])) return 0;
}
return 1;
}
RDF_Resource
HistCreate (char* url, PRBool createp)
{
size_t size = RDF_STRLEN(url);
char* nurl = getMem(size+8);
RDF_Resource ans;
if (charSearch(':', url) == -1) {
if (url[size-1] == '/') {
sprintf(nurl, "http://%s", url);
nurl[RDF_STRLEN(nurl)-1] = '\0';
} else {
sprintf(nurl, "http://%s/", url);
}
} else {
if (url[size-1] == '/') {
memcpy(nurl, url, size-1);
} else {
sprintf(nurl, "%s/", url);
}
}
ans = RDF_GetResource(NULL, nurl, 0);
if (ans != NULL) {
freeMem(nurl);
return ans;
}
freeMem(nurl);
ans = RDF_GetResource(NULL, url, createp);
if (ans != NULL) {
return ans;
} else {
return NULL;
}
}
PRBool bySite = 0;
Assertion
histAddParent (RDF_Resource child, RDF_Resource parent)
{
Assertion nextAs, prevAs, newAs;
RDF_Resource s = gCoreVocab->RDF_parent;
RDF_ValueType type = RDF_RESOURCE_TYPE;
nextAs = prevAs = child->rarg1;
while (nextAs != null) {
if (asEqual(gHistoryStore, nextAs, child, s, parent, type)) return null;
prevAs = nextAs;
nextAs = nextAs->next;
}
newAs = makeNewAssertion(gHistoryStore, child, s, parent, type, 1);
if (prevAs == null) {
child->rarg1 = newAs;
} else {
prevAs->next = newAs;
}
nextAs = prevAs = parent->rarg2;
if (nextAs == NULL) {
parent->rarg2 = newAs;
} else {
PRBool added = 0;
if (bySite) {
while (nextAs && !isSeparator(nextAs->u)) {
prevAs = nextAs;
nextAs = nextAs->invNext;
}
if (nextAs) {
prevAs = nextAs;
nextAs = nextAs->invNext;
}
}
while (nextAs != null) {
char* nid = resourceID(nextAs->u);
if (RDF_STRCMP(resourceID(child), resourceID(nextAs->u)) > 0) {
if (prevAs == nextAs) {
newAs->invNext = prevAs;
parent->rarg2 = newAs;
added = 1;
break;
} else {
newAs->invNext = nextAs;
prevAs->invNext = newAs;
added = 1;
break;
}
}
prevAs = nextAs;
nextAs = nextAs->invNext;
}
if (!added) prevAs->invNext = newAs;
}
sendNotifications2(gHistoryStore, RDF_ASSERT_NOTIFY, child, s, parent, type, 1);
/* XXX have to mark the entire subtree XXX */
/* sendNotifications(gHistoryStore->rdf, RDF_ASSERT_NOTIFY, child, s, parent, type, 1); */
return(newAs);
}
PRBool
historyUnassert (RDFT hst, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type)
{
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
if ((type == RDF_RESOURCE_TYPE) && (resourceType((RDF_Resource)v) == HISTORY_RT) &&
(s == gCoreVocab->RDF_parent)) {
RDF_Resource parents[5];
int8 n = 0;
Assertion as = u->rarg1;
memset(parents, '\0', 5 * sizeof(RDF_Resource));
while (as) {
if ((as->type == RDF_RESOURCE_TYPE) && (as->s == gCoreVocab->RDF_parent) &&
(resourceType((RDF_Resource)as->value) == HISTORY_RT) && (n < 5)) {
parents[n++] = (RDF_Resource)as->value;
}
as = as->next;
}
if (containerp(u)) {
Assertion as = u->rarg2;
while (as) {
if ((as->db == gHistoryStore) && (as->s == gCoreVocab->RDF_parent)) {
GH_DeleteHistoryItem (resourceID(as->u));
}
as = as->invNext;
}
} else {
GH_DeleteHistoryItem (resourceID(u));
}
while (n > 0) {
n = n - 1;
if (parents[n]) {
Assertion nas = remoteStoreRemove (gHistoryStore, u, gCoreVocab->RDF_parent,
parents[n], RDF_RESOURCE_TYPE);
freeMem(nas);
}
}
return 1;
}
return 0;
}
void
HistPossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep)
{
if ((s == gCoreVocab->RDF_parent) && inversep && (rdf == gHistoryStore) &&
((u == gNavCenter->RDF_HistoryByDate) || (u == gNavCenter->RDF_HistoryBySite))) {
if (histInFlatFilep) {
readRDFFile(gGlobalHistoryURL, NULL, 0, gHistoryStore);
historyInitialized = 1;
} else {
collateHistory(rdf, u, (u == gNavCenter->RDF_HistoryByDate));
historyInitialized = 1;
}
} else if ((s == gCoreVocab->RDF_parent) && inversep && (rdf == gHistoryStore) &&
(u == gNavCenter->RDF_HistoryMostVisited)) {
collateHistory(rdf, gNavCenter->RDF_HistoryBySite, 0);
historyInitialized = 1;
}
}
RDFT
MakeHistoryStore (char* url)
{
if (startsWith("rdf:history", url)) {
if (gHistoryStore == 0) {
RDFT ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct));
RDF_Resource sep = createSeparator();
ntr->assert = NULL;
ntr->unassert = historyUnassert;
ntr->getSlotValue = remoteStoreGetSlotValue;
ntr->getSlotValues = remoteStoreGetSlotValues;
ntr->hasAssertion = remoteStoreHasAssertion;
ntr->nextValue = remoteStoreNextValue;
ntr->disposeCursor = remoteStoreDisposeCursor;
ntr->possiblyAccessFile = HistPossiblyAccessFile;
gHistoryStore = ntr;
histInFlatFilep = endsWith(".rdf", gGlobalHistoryURL);
ntr->url = copyString(url);
hostHash = PL_NewHashTable(500, idenHash, PL_CompareValues, PL_CompareValues, null, null);
ByDateOpened = 1;
return ntr;
} else return gHistoryStore;
} else return NULL;
}
/*
void
dumpHist ()
{
FILE *fp = fopen("history.txt", "w");
HASHINFO hash = { 4*1024, 0, 0, 0, 0, 0};
DBT key, data;
PRBool firstOne = 0;
DB* db = CallDBOpenUsingFileURL(gGlobalHistoryURL, O_RDONLY ,0600,
DB_HASH, &hash);
if (db != NULL) {
while (0 == (*db->seq)(db, &key, &data, (firstOne ? R_NEXT : R_FIRST))) {
firstOne = 1;
if ((1 == (int32)*((char*)data.data + 3*sizeof(uint32)) &&
displayHistoryItem((char*)key.data))) {
fprintf(fp, "%s\n", (char*)key.data);
}
}
}
fclose(fp);
(*db->close)(db);
}
*/

View File

@@ -0,0 +1,84 @@
/* -*- 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_HIST2RDF_H_
#define _RDF_HIST2RDF_H_
#include "rdf-int.h"
#include <stdio.h>
#include "prtypes.h" /* for IS_LITTLE_ENDIAN / IS_BIG_ENDIAN */
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
#error Must have a byte order
#endif
#ifdef IS_LITTLE_ENDIAN
#define HIST_COPY_INT32(_a,_b) XP_MEMCPY(_a, _b, sizeof(int32));
#else
#define HIST_COPY_INT32(_a,_b) \
do { \
((char *)(_a))[0] = ((char *)(_b))[3]; \
((char *)(_a))[1] = ((char *)(_b))[2]; \
((char *)(_a))[2] = ((char *)(_b))[1]; \
((char *)(_a))[3] = ((char *)(_b))[0]; \
} while(0)
#endif
/* hist2rdf.c data structures and defines */
#define remoteAddParent(child, parent) histAddParent(child, parent);
#define remoteAddName(u, name) remoteStoreAdd(gRemoteStore, u, gCoreVocab->RDF_name, copyString(name), RDF_STRING_TYPE, 1);
#define SECS_IN_HOUR (60L * 60L)
#define SECS_IN_DAY (SECS_IN_HOUR * 24L)
extern int RDF_HTML_WINDATE, RDF_HTML_MACDATE;
/* hist2rdf.c function prototypes */
NSPR_BEGIN_EXTERN_C
void collateHistory (RDFT r, RDF_Resource u, PRBool byDateFlag);
void collateOneHist (RDFT r, RDF_Resource u, char* url, char* title, time_t lastAccessDate, time_t firstAccessDate, uint32 numAccesses, PRBool byDateFlag);
RDF_Resource hostUnitOfURL (RDFT r, RDF_Resource top, RDF_Resource nu, char* title);
void hourRange(char *buffer, struct tm *theTm);
RDF_Resource hostUnitOfDate (RDFT r, RDF_Resource u, time_t lastAccessDate);
void saveHistory();
void deleteCurrentSitemaps (char *address);
void addRelatedLinks (char* address);
PRBool displayHistoryItem (char* url);
RDF_Resource HistCreate (char* url, PRBool createp);
Assertion histAddParent (RDF_Resource child, RDF_Resource parent);
PRBool historyUnassert (RDFT hst, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
void HistPossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep);
RDF_Cursor historyStoreGetSlotValuesInt (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
PRBool historyStoreHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
RDFT MakeHistoryStore (char* url);
void dumpHist ();
NSPR_END_EXTERN_C
#endif

10391
mozilla/modules/rdf/src/ht.c Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,398 @@
/* -*- 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_HT_H_
#define _RDF_HT_H_
#ifndef HT_RAPTOR
#include "xpassert.h"
#include "xp_qsort.h"
#include "xp_time.h"
#include "client.h"
#include "net.h"
#include "xpgetstr.h"
#include "xp_str.h"
#include "htmldlgs.h"
#include "xp_ncent.h"
#include "xpassert.h"
#include "nspr.h"
#include "prefapi.h"
#include "fe_proto.h"
#include "intl_csi.h"
#ifdef XP_MAC
#include "stdlib.h"
#include <Aliases.h>
#endif
#include "rdf.h"
#include "rdf-int.h"
#include "math.h"
#include "htrdf.h"
#ifdef SMART_MAIL
#include "pm2rdf.h"
#endif
#else
#include "prprf.h"
#include "plhash.h"
#include "xp_core.h"
#include "rdf.h"
#include "rdf-int.h"
#include "mcf.h"
#include "htrdf.h"
#include "vocab.h"
#ifndef XP_ASSERT
#define XP_ASSERT(x)
#endif
#ifndef XP_FREE
#define XP_FREE(x) PR_Free((x))
#endif
#ifndef XP_STRCASECMP
#define XP_STRCASECMP(x,y) strcmp((x),(y))
#endif
#define MWContext void
#endif
/* HT data structures and defines */
#define ITEM_LIST_SIZE 500 /* XXX ITEM_LIST_SIZE should be dynamic */
#define ITEM_LIST_ELEMENT_SIZE 20
#define NUM_MENU_CMDS 40
#define RDF_SITEMAP 1
#define RDF_RELATED_LINKS 2
#define FROM_PAGE 1
#define GUESS_FROM_PREVIOUS_PAGE 2
#define HTDEL remoteStoreRemove
#ifndef HT_RAPTOR
/* external string references in allxpstr */
extern int RDF_HTML_STR, RDF_HTML_STR_1, RDF_HTML_STR_2, RDF_HTML_STR_3;
extern int RDF_HTML_STR_4, RDF_HTML_STR_5, RDF_HTML_STR_NUMBER;
extern int RDF_HTML_WINDATE, RDF_HTML_MACDATE, RDF_CMD_0, RDF_DATA_1, RDF_DATA_2;
extern int RDF_DELETEFILE, RDF_UNABLETODELETEFILE, RDF_DELETEFOLDER;
extern int RDF_UNABLETODELETEFOLDER, RDF_SITEMAPNAME;
extern int RDF_RELATEDLINKSNAME, RDF_DEFAULTCOLUMNNAME;
extern int RDF_NEWWORKSPACEPROMPT, RDF_DELETEWORKSPACE;
extern int RDF_ADDITIONS_ALLOWED, RDF_DELETION_ALLOWED;
extern int RDF_ICON_URL_LOCKED, RDF_NAME_LOCKED, RDF_COPY_ALLOWED;
extern int RDF_MOVE_ALLOWED, RDF_WORKSPACE_POS_LOCKED;
extern int RDF_MAIN_TITLE, RDF_COLOR_TITLE, RDF_HTML_INFOHEADER_STR;
extern int RDF_MISSION_CONTROL_TITLE, RDF_TREE_COLORS_TITLE, RDF_SELECTION_COLORS_TITLE;
extern int RDF_COLUMN_COLORS_TITLE, RDF_TITLEBAR_COLORS_TITLE, RDF_HTML_MAININFOHEADER_STR;
extern int RDF_HTML_EMPTYHEADER_STR, RDF_HTML_COLOR_STR, RDF_SETCOLOR_JS, RDF_DEFAULTCOLOR_JS;
extern int RDF_COLOR_LAYER, RDF_HTMLCOLOR_STR;
extern int RDF_SELECT_START, RDF_SELECT_END, RDF_SELECT_OPTION;
extern int RDF_FIND_STR1, RDF_FIND_STR2, RDF_FIND_INPUT_STR;
extern int RDF_LOCAL_LOCATION_STR, RDF_REMOTE_LOCATION_STR, RDF_ALL_LOCATION_STR;
extern int RDF_CONTAINS_STR, RDF_IS_STR, RDF_IS_NOT_STR, RDF_STARTS_WITH_STR, RDF_ENDS_WITH_STR;
extern int RDF_FIND_TITLE, RDF_FIND_FULLNAME_STR, RDF_SHORTCUT_CONFLICT_STR, RDF_FTP_NAME_STR;
#ifdef HT_PASSWORD_RTNS
extern int RDF_NEWPASSWORD, RDF_CONFIRMPASSWORD;
extern int RDF_MISMATCHPASSWORD, RDF_ENTERPASSWORD;
#endif
#endif
#define MISSION_CONTROL_RDF_PREF "browser.navcenter.admin"
#define NETSCAPE_RDF_FILENAME "netscape.rdf"
typedef struct _SBProviderStruct {
struct _SBProviderStruct *next;
char *url;
char *name;
PRBool containerp;
PRBool openp;
} SBProviderStruct;
typedef SBProviderStruct* SBProvider;
typedef struct _HT_PaneStruct {
struct _HT_PaneStruct *next;
void *pdata;
HT_Notification ns;
PLHashTable *hash;
HT_NotificationMask mask;
RDF db;
RDF_Notification rns;
struct _HT_ViewStruct *viewList;
struct _HT_ViewStruct *selectedView;
struct _HT_URLSiteMapAssoc *smp;
struct _HT_URLSiteMapAssoc *sbp;
uint32 viewListCount;
PRBool autoFlushFlag;
SBProvider smartBrowsingProviders;
PRBool dirty;
PRBool personaltoolbar;
PRBool toolbar;
PRBool bookmarkmenu;
PRBool special;
int windowType;
char *windowURL;
char *templateType;
struct _HT_PaneStruct *templatePane;
char *htdburl;
RDFT htdb;
} HT_PaneStruct;
typedef struct HT_ColumnStruct {
struct HT_ColumnStruct *next;
char *name;
uint32 width;
uint32 tokenType;
void *token;
void *feData;
PRBool isHiddenFlag;
} HT_ColumnStruct, *HT_Column;
typedef struct _HT_ViewStruct {
struct _HT_ViewStruct *next;
HT_Pane pane;
HT_Resource top;
void *pdata;
HT_Column columns;
uint32 workspacePos;
struct _HT_ResourceStruct ***itemList;
uint32 itemListSize;
uint32 itemListCount;
uint32 topNodeIndex;
uint32 selectedNodeHint;
uint32 sortTokenType;
void *sortToken;
PRBool descendingFlag;
PRBool refreshingItemListp;
PRBool inited;
RDF_Resource treeRel;
} HT_ViewStruct;
typedef struct _HT_ValueStruct {
struct _HT_ValueStruct *next;
uint32 tokenType;
RDF_Resource token;
void *data;
} HT_ValueStruct, *HT_Value;
#define HT_CONTAINER_FLAG 0x0001
#define HT_OPEN_FLAG 0x0002
#define HT_AUTOFLUSH_OPEN_FLAG 0x0004
#define HT_HIDDEN_FLAG 0x0008
#define HT_SELECTED_FLAG 0x0010
#define HT_VOLATILE_URL_FLAG 0x0020
#define HT_FREEICON_URL_FLAG 0x0040
#define HT_PASSWORDOK_FLAG 0x0080
#define HT_INITED_FLAG 0x0100
#define HT_DIRTY_FLAG 0x0200
#define HT_ENABLED_FLAG 0x0400
typedef struct _HT_ResourceStruct {
struct _HT_ResourceStruct *nextItem;
HT_View view;
HT_Resource parent;
RDF_Resource node;
void *feData;
char *dataSource;
char *url[5];
HT_Value values;
HT_Resource child;
HT_Resource *children; /* used by sorting */
uint32 unsortedIndex; /* used by sorting */
uint32 itemListIndex;
uint32 numChildren, numChildrenTotal;
uint16 flags;
uint16 depth;
HT_Resource next;
/* a pane or view might have multiple occurances of a RDF_Resource.
The hash table just points to the first of them. This allows us to
make a linked list of it */
} HT_ResourceStruct;
typedef struct _HT_MenuCommandStruct {
struct _HT_MenuCommandStruct *next;
HT_MenuCmd menuCmd;
char *name;
RDF_Resource graphCommand;
} _HT_MenuCommandStruct, *HT_MenuCommand;
typedef struct _HT_CursorStruct {
HT_Resource container;
HT_Resource node;
RDF_Cursor cursor;
uint32 numElements;
HT_Column columns;
uint16 contextMenuIndex;
PRBool foundValidMenuItem;
PRBool isWorkspaceFlag;
PRBool isBackgroundFlag;
PRBool commandExtensions;
PRBool commandListBuild;
HT_MenuCmd menuCmd;
HT_MenuCommand menuCommandList;
} HT_CursorStruct;
typedef struct _HT_Icon {
struct _HT_Icon *next;
char *name;
} _HT_Icon, *HT_Icon;
typedef struct _htmlElement {
struct _htmlElement *next;
HT_Resource node;
RDF_Resource token;
uint32 tokenType;
} _htmlElement, *_htmlElementPtr;
typedef struct _HT_URLSiteMapAssoc {
uint8 siteToolType;
uint8 origin;
uint8 onDisplayp;
char *url;
RDF_Resource sitemap;
char* name;
char* sitemapUrl;
RDFT db;
struct _HT_URLSiteMapAssoc *next;
} HT_URLSiteMapAssoc;
/* HT function prototypes */
XP_BEGIN_PROTOS
void HT_Startup();
void HT_Shutdown();
void htLoadComplete(char *url, int status);
void htTimerRoutine(void *timerID);
PRBool possiblyUpdateView(HT_View view);
void updateViewItem(HT_Resource node);
HT_Resource newHTEntry (HT_View view, RDF_Resource node);
void addWorkspace(HT_Pane pane, RDF_Resource r, void *feData);
void deleteWorkspace(HT_Pane pane, RDF_Resource r);
void htrdfNotifFunc (RDF_Event ns, void* pdata);
void bmkNotifFunc (RDF_Event ns, void* pdata);
void refreshItemListInt (HT_View view, HT_Resource node);
PRBool relatedLinksContainerp (HT_Resource node);
int nodeCompareRtn(HT_Resource *node1, HT_Resource *node2);
void sortNodes(HT_View view, HT_Resource parent, HT_Resource *children, uint32 numChildren);
uint32 refreshItemList1(HT_View view, HT_Resource node);
void refreshItemList (HT_Resource node, HT_Event whatHappened);
void refreshPanes();
PRBool initToolbars (HT_Pane pane);
HT_Pane paneFromResource(RDF db, RDF_Resource resource, HT_Notification notify, PRBool autoFlushFlag, PRBool autoOpenFlag, PRBool useColumns);
void htSetBookmarkAddDateToNow(RDF_Resource r);
RDF newHTPaneDB();
RDF HTRDF_GetDB();
PRBool initViews (HT_Pane pane);
void htNewWorkspace(HT_Pane pane, char *id, char *optionalTitle, uint32 workspacePos);
HT_PaneStruct * HT_GetHTPaneList ();
HT_PaneStruct * HT_GetNextHTPane (HT_PaneStruct* pane);
void htSetWorkspaceOrder(RDF_Resource src, RDF_Resource dest, PRBool afterDestFlag);
HT_View HT_NewView (RDF_Resource topNode, HT_Pane pane, PRBool useColumns, void *feData, PRBool autoOpen);
void sendNotification (HT_Resource node, HT_Event whatHappened, RDF_Resource s, HT_ColumnType type);
void deleteHTNode(HT_Resource node);
void destroyViewInt (HT_Resource r, PRBool saveOpenState);
void htDeletePane(HT_Pane pane, PRBool saveWorkspaceOrder);
void saveWorkspaceOrder(HT_Pane pane);
void resynchItem (HT_Resource node, void *token, void *data, PRBool assertAction);
void resynchContainer (HT_Resource container);
HT_Resource addContainerItem (HT_Resource container, RDF_Resource item);
void refreshContainerIndexes(HT_Resource container);
void removeHTFromHash (HT_Pane pane, HT_Resource item);
void deleteHTSubtree (HT_Resource subtree);
void deleteContainerItem (HT_Resource container, RDF_Resource item);
uint32 fillContainer (HT_Resource node);
void sendColumnNotification (HT_View view, void *token, uint32 tokenType, HT_Event whatHappened);
PRBool htIsMenuCmdEnabled(HT_Pane pane, HT_MenuCmd menuCmd, PRBool isWorkspaceFlag, PRBool isBackgroundFlag);
void freeMenuCommandList();
void exportCallbackWrite(PRFileDesc *fp, char *str);
void exportCallback(MWContext *context, char *filename, RDF_Resource node);
void htEmptyClipboard(RDF_Resource parent);
void htCopyReference(RDF_Resource original, RDF_Resource newParent, PRBool empty);
PRBool htVerifyUniqueToken(HT_Resource node, void *token, uint32 tokenType, char *data);
PRBool ht_isURLReal(HT_Resource node);
char * buildInternalIconURL(HT_Resource node, PRBool *volatileURLFlag, PRBool largeIconFlag, PRBool workspaceFlag);
char * getIconURL( HT_Resource node, PRBool toolbarFlag, PRBool workspaceFlag, int state);
PRBool htIsPropertyInMoreOptions(RDF_Resource r);
void addHtmlElement(HT_Resource node, RDF_Resource token, uint32 tokenType);
void freeHtmlElementList();
_htmlElementPtr findHtmlElement(void *token);
void freeHtmlElement(void *token);
char * constructHTMLTagData(char *dynStr, int strID, char *data);
char * constructHTML(char *dynStr, HT_Resource node, void *token, uint32 tokenType);
char * constructHTMLPermission(char *dynStr, HT_Resource node, RDF_Resource token, char *permText);
PRBool htIsOpLocked(HT_Resource node, RDF_Resource token);
char * constructBasicHTML(char *dynStr, int strID, char *data1, char *data2);
void setHiddenState (HT_Resource node);
void htSetFindResourceName(RDF db, RDF_Resource r);
void htOpenTo(HT_View view, RDF_Resource u, PRBool selectView);
PRBool mutableContainerp (RDF_Resource node);
char * possiblyCleanUpTitle (char* title);
PRBool htRemoveChild(HT_Resource parent, HT_Resource child, PRBool moveToTrash);
void ht_SetPassword(HT_Resource node, char *password);
PRBool ht_hasPassword(HT_Resource node);
PRBool ht_checkPassword(HT_Resource node, PRBool alwaysCheck);
HT_DropAction htLaunchSmartNode(HT_Resource dropTarget, char *fullURL);
HT_DropAction dropOnSmartNode(HT_Resource dropTarget, HT_Resource dropObject, PRBool justAction);
HT_DropAction dropOnSmartURL(HT_Resource dropTarget, char *objTitle, PRBool justAction);
HT_DropAction dropOn (HT_Resource dropTarget, HT_Resource dropObject, PRBool justAction);
void Win32FileCopyMove(HT_Resource dropTarget, HT_Resource dropObject);
HT_DropAction copyMoveRDFLink (HT_Resource dropTarget, HT_Resource dropObject);
HT_DropAction copyMoveRDFLinkAtPos (HT_Resource dropx, HT_Resource dropObject, PRBool before);
HT_DropAction uploadLFS (HT_Resource dropTarget, HT_Resource dropObject);
HT_DropAction uploadRDFFile (HT_Resource dropTarget, HT_Resource dropObject);
HT_DropAction esfsCopyMoveContent (HT_Resource dropTarget, HT_Resource dropObject);
RDF_BT urlResourceType (char* url);
HT_DropAction dropURLOn (HT_Resource dropTarget, char* objURL, char *objTitle, PRBool justAction);
void replacePipeWithColon(char* url);
HT_DropAction copyRDFLinkURL (HT_Resource dropTarget, char* objURL, char *objTitle);
HT_DropAction copyRDFLinkURLAt (HT_Resource dropx, char* objURL, char *objTitle, PRBool before);
HT_DropAction uploadLFSURL (HT_Resource dropTarget, char* objURL);
HT_DropAction uploadRDFFileURL (HT_Resource dropTarget, char* objURL);
HT_DropAction esfsCopyMoveContentURL (HT_Resource dropTarget, char* objURL);
RDFT HTADD(HT_Pane pane, RDF_Resource u, RDF_Resource s, void* v);
HT_URLSiteMapAssoc * makeNewSMP (HT_Pane htPane, char* pUrl, char* sitemapurl);
void RetainOldSitemaps (HT_Pane htPane, char *pUrl);
void populateSBProviders (HT_Pane htPane);
SBProvider SBProviderOfNode (HT_Resource node);
PRBool implicitDomainURL (char* url);
PRBool domainMatches (char *dom, char *url);
void nextDomain (char* dom, size_t *n);
PRBool relatedLinksEnabledURL (char* url);
void cleanupInt (HT_Pane htPane, HT_URLSiteMapAssoc *nsmp, RDF_Resource parent);
HT_Pane newTemplatePane(char* templateName);
void PaneDeleteSBPCleanup (HT_Pane htPane);
#ifndef HT_RAPTOR
PRBool rdfFindDialogHandler(XPDialogState *dlgstate, char **argv, int argc, unsigned int button);
#endif
XP_END_PROTOS
#endif

View File

@@ -0,0 +1,404 @@
/* -*- 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.
*/
#include "jsec2rdf.h"
#include "fs2rdf.h"
#include "utils.h"
#include "nlcstore.h"
#include "vocabint.h"
NSPR_BEGIN_EXTERN_C
extern RDF gNCDB;
RDF gJSecDB = NULL;
JSec_Error
RDFJSec_InitPrivilegeDB()
{
if (gJSecDB == 0) {
gJSecDB = gNCDB;
}
return JSec_OK;
}
JSec_Error
RDFJSec_SavePrivilegeDB()
{
return JSec_OK;
}
JSec_Error
RDFJSec_ClosePrivilegeDB()
{
return JSec_OK;
}
#define JSEC_PRINCIPAL_URL "jsecprin:"
char *
RDFJSec_GetPrincipalURLString(char *principalID)
{
size_t size = RDF_STRLEN(principalID);
char* url = getMem(size+RDF_STRLEN(JSEC_PRINCIPAL_URL)+1);
if (url == NULL) {
return NULL;
}
sprintf(url, "%s%s", JSEC_PRINCIPAL_URL, principalID);
strcpy(url, principalID);
return url;
}
RDF_Cursor
RDFJSec_ListAllPrincipals()
{
RDF_Cursor c = NULL;
if (gNavCenter != NULL) {
c = RDF_GetSources(gJSecDB, gNavCenter->RDF_JSec,
gNavCenter->RDF_JSecPrincipal,
RDF_RESOURCE_TYPE, TRUE);
}
return(c);
}
JSec_Principal
RDFJSec_NextPrincipal(RDF_Cursor c)
{
if (c != NULL) {
return RDF_NextValue(c);
}
return NULL;
}
RDF_Error
RDFJSec_ReleaseCursor(RDF_Cursor c)
{
RDF_Error err = 0;
if (c != NULL) {
err = RDF_DisposeCursor(c);
}
return (err);
}
JSec_Principal
RDFJSec_NewPrincipal(char* principalID)
{
RDF_Resource principalUnit;
char *url = RDFJSec_GetPrincipalURLString(principalID);
if (url == NULL) {
return NULL;
}
principalUnit = RDF_GetResource(NULL, url, FALSE);
if (!principalUnit) {
principalUnit = RDF_GetResource(NULL, url, TRUE);
}
freeMem(url);
return (JSec_Principal)principalUnit;
}
JSec_Error
RDFJSec_AddPrincipal(JSec_Principal pr)
{
if ((pr == NULL) || (gNavCenter == NULL)) {
return JSec_NullObject;
}
if (RDF_HasAssertion(gJSecDB, pr, gNavCenter->RDF_JSecPrincipal, gNavCenter->RDF_JSec,
RDF_RESOURCE_TYPE, PR_FALSE)) {
return JSec_OK;
}
setContainerp(pr, PR_TRUE);
setResourceType(pr, JSEC_RT);
RDF_Assert(gJSecDB, pr, gNavCenter->RDF_JSecPrincipal, gNavCenter->RDF_JSec, RDF_RESOURCE_TYPE);
return JSec_OK;
}
JSec_Error
RDFJSec_DeletePrincipal(JSec_Principal pr)
{
RDF_Cursor c;
if ((pr == NULL) || (gNavCenter == NULL)) {
return JSec_NullObject;
}
/* Before deleting the principal, delete all the PrincipalUses for this principal.
*/
c = RDFJSec_ListAllPrincipalUses(pr);
if (c != NULL) {
JSec_PrincipalUse prUse;
while ((prUse = RDFJSec_NextPrincipalUse(c)) != NULL) {
RDFJSec_DeletePrincipalUse(pr, prUse);
}
}
RDF_Unassert(gJSecDB, pr, gNavCenter->RDF_JSecPrincipal, gNavCenter->RDF_JSec, RDF_RESOURCE_TYPE);
return JSec_OK;
}
char *
RDFJSec_PrincipalID(JSec_Principal pr)
{
char *url = resourceID(pr);
char *ans = getMem(RDF_STRLEN(url)+1);
int n;
if (ans == NULL) {
return NULL;
}
n = charSearch(':', url);
if (n == -1) {
strcpy(ans, url);
} else {
strcpy(ans, url+n+1);
}
return ans;
}
void *
RDFJSec_AttributeOfPrincipal(JSec_Principal pr, char* attributeType)
{
RDF_Resource attributeResource = RDF_GetResource(NULL, attributeType, TRUE);
void *attValue;
RDF_Cursor c = NULL;
c = RDF_GetTargets(gJSecDB, pr, attributeResource, RDF_STRING_TYPE, TRUE);
if (c == NULL) {
return NULL;
}
attValue = RDF_NextValue(c);
RDF_DisposeCursor(c);
return attValue;
}
JSec_Error
RDFJSec_SetPrincipalAttribute(JSec_Principal pr, char* attributeType, void* attValue)
{
RDF_Resource attributeResource = RDF_GetResource(NULL, attributeType, TRUE);
RDF_Assert(gJSecDB, pr, attributeResource, attValue, RDF_STRING_TYPE);
return JSec_OK;
}
RDF_Cursor
RDFJSec_ListAllPrincipalUses(JSec_Principal pr)
{
RDF_Cursor c = NULL;
c = RDF_GetSources(gJSecDB, (RDF_Resource)pr, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
return(c);
}
JSec_PrincipalUse
RDFJSec_NextPrincipalUse(RDF_Cursor c)
{
if (c != NULL) {
return RDF_NextValue(c);
}
return NULL;
}
JSec_PrincipalUse
RDFJSec_NewPrincipalUse(JSec_Principal pr, JSec_Target tr, char* priv)
{
RDF_Resource principalUseUnit;
char *targetID = resourceID(tr);
char *principalID = resourceID(pr);
char *principalUseID = getMem(RDF_STRLEN(principalID) + strlen(targetID) + 2);
if (principalUseID == NULL) {
return NULL;
}
sprintf(principalUseID, "%s!%s", principalID, targetID);
principalUseUnit = RDF_GetResource(NULL, principalUseID, FALSE);
if (!principalUseUnit) {
principalUseUnit = RDF_GetResource(NULL, principalUseID, TRUE);
RDFJSec_AddTargetToPrincipalUse(principalUseUnit, tr);
RDFJSec_AddPrincipalUsePrivilege(principalUseUnit, priv);
}
return principalUseUnit;
}
JSec_Error
RDFJSec_AddPrincipalUse(JSec_Principal pr, JSec_PrincipalUse prUse)
{
if ((pr == NULL) || (prUse == NULL)) {
return JSec_NullObject;
}
setContainerp(prUse, PR_TRUE);
setResourceType(prUse, JSEC_RT);
RDF_Assert(gJSecDB, prUse, gCoreVocab->RDF_parent, pr, RDF_RESOURCE_TYPE);
return JSec_OK;
}
JSec_Error
RDFJSec_DeletePrincipalUse (JSec_Principal pr, JSec_PrincipalUse prUse)
{
JSec_Target tr;
char *priv;
if ((pr == NULL) || (prUse == NULL)) {
return JSec_NullObject;
}
/* Before deleting the principal, delete all the PrincipalUses for this principal.
*/
tr = RDFJSec_TargetOfPrincipalUse(prUse);
RDFJSec_DeleteTargetToPrincipalUse(prUse, tr);
priv = RDFJSec_PrivilegeOfPrincipalUse(prUse);
RDFJSec_DeletePrincipalUsePrivilege(prUse, priv);
RDF_Unassert(gJSecDB, prUse, gCoreVocab->RDF_parent, pr, RDF_RESOURCE_TYPE);
return JSec_OK;
}
const char *
RDFJSec_PrincipalUseID(JSec_PrincipalUse prUse)
{
return resourceID(prUse);
}
JSec_Error
RDFJSec_AddPrincipalUsePrivilege (JSec_PrincipalUse prUse, char* priv)
{
char *oldPriv;
if ((prUse == NULL) || (priv == NULL) || (gNavCenter == NULL)) {
return JSec_NullObject;
}
/* Each PrincipalUse can only have one Privilege. Thus delete the old privilege*/
oldPriv = RDFJSec_PrivilegeOfPrincipalUse(prUse);
RDFJSec_DeletePrincipalUsePrivilege(prUse, oldPriv);
RDF_Assert(gJSecDB, prUse, gNavCenter->RDF_JSecAccess, priv, RDF_STRING_TYPE);
return JSec_OK;
}
JSec_Error
RDFJSec_DeletePrincipalUsePrivilege (JSec_PrincipalUse prUse, char* priv)
{
if ((prUse == NULL) || (priv == NULL) || (gNavCenter == NULL)) {
return JSec_NullObject;
}
RDF_Unassert(gJSecDB, prUse, gNavCenter->RDF_JSecAccess, priv, RDF_STRING_TYPE);
return JSec_OK;
}
char *
RDFJSec_PrivilegeOfPrincipalUse (JSec_PrincipalUse prUse)
{
RDF_Cursor c = NULL;
char *privilege;
if (gNavCenter == NULL) {
return NULL;
}
c = RDF_GetTargets(gJSecDB, (RDF_Resource)prUse, gNavCenter->RDF_JSecAccess, RDF_STRING_TYPE, TRUE);
if (c == NULL) {
return NULL;
}
privilege = RDF_NextValue(c);
RDF_DisposeCursor(c);
return privilege;
}
JSec_Error
RDFJSec_AddTargetToPrincipalUse(JSec_PrincipalUse prUse, JSec_Target tr)
{
JSec_Target oldTarget;
if ((prUse == NULL) || (tr == NULL) || (gNavCenter == NULL)) {
return JSec_NullObject;
}
/* Each PrincipalUse can only have one Target. Thus delete the old target */
oldTarget = RDFJSec_TargetOfPrincipalUse(prUse);
RDFJSec_DeleteTargetToPrincipalUse(prUse, oldTarget);
RDF_Assert(gJSecDB, prUse, gNavCenter->RDF_JSecTarget, tr, RDF_RESOURCE_TYPE);
return JSec_OK;
}
JSec_Error
RDFJSec_DeleteTargetToPrincipalUse(JSec_PrincipalUse prUse, JSec_Target tr)
{
if ((prUse == NULL) || (tr == NULL) || (gNavCenter == NULL)) {
return JSec_NullObject;
}
RDF_Unassert(gJSecDB, prUse, gNavCenter->RDF_JSecTarget, tr, RDF_RESOURCE_TYPE);
return JSec_OK;
}
JSec_Target
RDFJSec_TargetOfPrincipalUse (JSec_PrincipalUse prUse)
{
RDF_Cursor c = NULL;
JSec_Target tr;
if ((prUse == NULL) || (gNavCenter == NULL)) {
return NULL;
}
c = RDF_GetTargets(gJSecDB, (RDF_Resource)prUse, gNavCenter->RDF_JSecTarget, RDF_RESOURCE_TYPE, true);
if (c == NULL) {
return NULL;
}
tr = RDF_NextValue(c);
RDF_DisposeCursor(c);
return tr;
}
JSec_Target
RDFJSec_NewTarget(char* targetName, JSec_Principal pr)
{
RDF_Resource tr;
/* RDF_Resource prResource; */
char *principalID = RDFJSec_PrincipalID(pr);
char *targetID = getMem(RDF_STRLEN(targetName) + strlen(principalID) + 2);
if (targetID == NULL) {
return NULL;
}
if (gNavCenter == NULL) {
return NULL;
}
sprintf(targetID, "%s!%s", targetName, principalID);
tr = RDF_GetResource(NULL, targetID, FALSE);
if (!tr) {
tr = RDF_GetResource(NULL, targetID, TRUE);
if (tr == NULL) {
return NULL;
}
RDFJSec_SetTargetAttribute(tr, "targetName", targetName);
RDF_Assert(gJSecDB, tr, gNavCenter->RDF_JSecPrincipal, pr, RDF_RESOURCE_TYPE);
}
return tr;
}
char *
RDFJSec_GetTargetName(JSec_Target tr)
{
return RDFJSec_AttributeOfTarget(tr, "targetName");
}
char *
RDFJSec_AttributeOfTarget(JSec_Target tr, char* attributeType)
{
RDF_Resource attributeResource = RDF_GetResource(NULL, attributeType, TRUE);
char *attValue;
RDF_Cursor c = NULL;
c = RDF_GetTargets(gJSecDB, tr, attributeResource, RDF_STRING_TYPE, TRUE);
if (c == NULL) {
return NULL;
}
attValue = RDF_NextValue(c);
RDF_DisposeCursor(c);
return attValue;
}
JSec_Error
RDFJSec_SetTargetAttribute(JSec_Target tr, char* attributeType, char* attValue)
{
RDF_Resource attributeResource = RDF_GetResource(NULL, attributeType, TRUE);
RDF_Assert(gJSecDB, tr, attributeResource, attValue, RDF_STRING_TYPE);
return JSec_OK;
}
NSPR_END_EXTERN_C

View File

@@ -0,0 +1,562 @@
/* -*- 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 LDAP 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
*/
/*
XXX Someone needs to get this up to speed again
*/
#if 0
#ifdef MOZ_LDAP
#include "ldap2rdf.h"
#include "utils.h"
/* statics */
static PRHashTable *ldap2rdfHash;
static PRHashTable *invldap2rdfHash;
static RDFT gRDFDB;
static PRBool ldap2rdfInitedp = 0;
RDFT
MakeLdapStore (char* url)
{
RDFT ntr = (RDFT)getMem(sizeof(RDF_TranslatorStruct));
ntr->assert = ldapAssert;
ntr->unassert = ldapUnassert;
ntr->getSlotValue = ldapGetSlotValue;
ntr->getSlotValues = ldapGetSlotValues;
ntr->hasAssertion = ldapHasAssertion;
ntr->nextValue = ldapNextValue;
ntr->disposeCursor = ldapDisposeCursor;
ldap2rdfInit(ntr);
return ntr;
}
RDF_Error
LdapInit (RDFT ntr)
{
ntr->assert = ldapAssert;
ntr->unassert = ldapUnassert;
ntr->getSlotValue = ldapGetSlotValue;
ntr->getSlotValues = ldapGetSlotValues;
ntr->hasAssertion = ldapHasAssertion;
ntr->nextValue = ldapNextValue;
ntr->disposeCursor = ldapDisposeCursor;
ldap2rdfInit(ntr);
return 0;
}
void
ldap2rdfInit (RDFT rdf)
{
if (!ldap2rdfInitedp) {
ldap2rdfHash = PR_NewHashTable(500, idenHash, idenEqual, idenEqual, null, null);
invldap2rdfHash = PR_NewHashTable(500, idenHash, idenEqual, idenEqual, null, null);
gRDFDB = rdf;
ldap2rdfInitedp = 1;
}
}
Assertion
ldaparg1 (RDF_Resource u)
{
return (Assertion) PR_HashTableLookup(ldap2rdfHash, u);
}
Assertion
setldaparg1 (RDF_Resource u, Assertion as)
{
return (Assertion) PR_HashTableAdd(ldap2rdfHash, u, as);
}
Assertion
ldaparg2 (RDF_Resource u)
{
return (Assertion) PR_HashTableLookup(invldap2rdfHash, u);
}
Assertion
setldaparg2 (RDF_Resource u, Assertion as)
{
return (Assertion) PR_HashTableAdd(invldap2rdfHash, u, as);
}
PRBool
ldapAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v));
if (!ldap2rdfInitedp) ldap2rdfInit(rdf);
if ((s == gCoreVocab->RDF_parent) && (type == RDF_RESOURCE_TYPE) &&
(tv) && (ldapContainerp(v))) {
return (ldapAddChild(rdf, (RDF_Resource)v, u));
} else {
return 0;
}
}
PRBool
ldapUnassert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type)
{
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
if (!ldap2rdfInitedp) ldap2rdfInit(rdf);
if ((s == gCoreVocab->RDF_parent) && (type == RDF_RESOURCE_TYPE) &&
(ldapContainerp(v))) {
return (ldapRemoveChild(rdf, (RDF_Resource)v, u));
} else {
return 0;
}
}
PRBool
ldapDBAdd (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type)
{
Assertion nextAs, prevAs, newAs;
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
if ((s == gCoreVocab->RDF_instanceOf) && (v == gWebData->RDF_Container)) {
setContainerp(u, true);
return 1;
}
nextAs = prevAs = ldaparg1(u);
while (nextAs != null) {
if (asEqual(nextAs, u, s, v, type)) return 1;
prevAs = nextAs;
nextAs = nextAs->next;
}
newAs = makeNewAssertion(u, s, v, type, 1);
if (prevAs == null) {
setldaparg1(u, newAs);
} else {
prevAs->next = newAs;
}
if (type == RDF_RESOURCE_TYPE) {
nextAs = prevAs = ldaparg2((RDF_Resource)v);
while (nextAs != null) {
prevAs = nextAs;
nextAs = nextAs->invNext;
}
if (prevAs == null) {
setldaparg2((RDF_Resource)v, newAs);
} else {
prevAs->invNext = newAs;
}
}
sendNotifications2(rdf, RDF_ASSERT_NOTIFY, u, s, v, type, 1);
return true;
}
PRBool
ldapDBRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type)
{
Assertion nextAs, prevAs, ans;
PRBool found = false;
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
nextAs = prevAs = ldaparg1(u);
while (nextAs != null) {
if (asEqual(nextAs, u, s, v, type)) {
if (prevAs == null) {
setldaparg1(u, nextAs->next);
} else {
prevAs->next = nextAs->next;
}
found = true;
ans = nextAs;
break;
}
prevAs = nextAs;
nextAs = nextAs->next;
}
if (found == false) return false;
if (type == RDF_RESOURCE_TYPE) {
nextAs = prevAs = ldaparg2((RDF_Resource)v);
while (nextAs != null) {
if (nextAs == ans) {
if (prevAs == nextAs) {
setldaparg2((RDF_Resource)v, nextAs->invNext);
} else {
prevAs->invNext = nextAs->invNext;
}
}
prevAs = nextAs;
nextAs = nextAs->invNext;
}
}
sendNotifications2(rdf, RDF_DELETE_NOTIFY, u, s, v, type, 1);
return true;
}
PRBool
ldapHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv)
{
Assertion nextAs;
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
if (!ldap2rdfInitedp) ldap2rdfInit(rdf);
nextAs = ldaparg1(u);
while (nextAs != null) {
if (asEqual(nextAs, u, s, v, type) && (nextAs->tv == tv)) return true;
nextAs = nextAs->next;
}
possiblyAccessldap(rdf, u, s, false);
nextAs = ldaparg1(u);
while (nextAs != null) {
if (asEqual(nextAs, u, s, v, type) && (nextAs->tv == tv)) return true;
nextAs = nextAs->next;
}
return false;
}
void *
ldapGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv)
{
Assertion nextAs;
if (!ldap2rdfInitedp) ldap2rdfInit(rdf);
nextAs = (inversep ? ldaparg2(u) : ldaparg1(u));
while (nextAs != null) {
if ((nextAs->s == s) && (nextAs->tv == tv) && (nextAs->type == type)) {
void * retVal = (inversep ? nextAs->u : nextAs->value);
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )retVal)));
return retVal
}
nextAs = (inversep ? nextAs->invNext : nextAs->next);
}
possiblyAccessldap(rdf, u, s, inversep);
nextAs = (inversep ? ldaparg2(u) : ldaparg1(u));
while (nextAs != null) {
if ((nextAs->s == s) && (nextAs->tv == tv) && (nextAs->type == type)) {
void * retVal = (inversep ? nextAs->u : nextAs->value);
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )retVal)));
return retVal
}
nextAs = (inversep ? nextAs->invNext : nextAs->next);
}
return null;
}
RDF_Cursor
ldapGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv)
{
Assertion as;
RDF_Cursor c;
if (!ldap2rdfInitedp) ldap2rdfInit(rdf);
as = (inversep ? ldaparg2(u) : ldaparg1(u));
if (as == null) {
possiblyAccessldap(rdf, u, s, inversep);
as = (inversep ? ldaparg2(u) : ldaparg1(u));
if (as == null)
return null;
}
c = (RDF_CursorStruc*)getMem(sizeof(RDF_CursorStruc));
c->u = u;
c->s = s;
c->type = type;
c->inversep = inversep;
c->tv = tv;
c->count = 0;
c->pdata = as;
return c;
}
void *
ldapNextValue (RDFT mcf, RDF_Cursor c)
{
while (c->pdata != null) {
Assertion as = (Assertion) c->pdata;
if ((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
ldapDisposeCursor (RDFT mcf, RDF_Cursor c)
{
freeMem(c);
return noRDFErr;
}
RDF_Resource
ldapNewContainer(char *id)
{
return(NULL);
}
int
ldapModifyEntry (RDFT rdf, RDF_Resource parent, RDF_Resource child, PRBool addFlag)
{
RDF_Cursor c;
RDF_Resource newParent, r;
char *urivals[2];
LDAP *ld;
LDAPMod urimod, *mods[2];
LDAPURLDesc *ldURL=NULL;
int err;
char *errStr, *parentID;
parentID = resourceID(parent);
if (containerp(child))
{
if (newParent = ldapNewContainer(parentID))
{
if ((c = RDF_GetSources(rdf->rdf->rdf, child,
gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, 1)) != NULL)
{
while ((r = RDF_NextValue(c)) != NULL)
{
err = ldapModifyEntry(rdf, newParent, r, addFlag);
if (err)
{
/* XXX MAJOR rollback issues!
Punt for now! */
return(err);
}
}
}
else
{
return(-1);
}
}
else
{
return(-1);
}
}
ldap_url_parse(parentID, &ldURL);
if (ldURL == NULL) return(-1);
ld = ldap_init (ldURL->lud_host, ldURL->lud_port);
if (ld == NULL)
{
ldap_free_urldesc(ldURL);
return(-1);
}
if ((err = ldap_simple_bind_s(ld, ADMIN_ID, ADMIN_PW)) /* XXX */
!= LDAP_SUCCESS)
{
if ((errStr = ldap_err2string(err)) != NULL)
{
/* We need to change XP_MakeHTMLAlert to use UTF8 */
XP_MakeHTMLAlert(NULL, errStr);
}
ldap_unbind(ld);
ldap_free_urldesc(ldURL);
return(-1);
}
urivals[0] = resourceID(child);
urivals[1] = NULL;
urimod.mod_op = ((addFlag == true) ? LDAP_MOD_ADD : LDAP_MOD_DELETE);
urimod.mod_type = "labeledURI";
urimod.mod_values = urivals;
mods[0] = &urimod;
mods[1] = NULL;
err = ldap_modify_s(ld, ldURL->lud_dn, mods);
if (err != LDAP_SUCCESS)
{
if ((errStr = ldap_err2string(err)) != NULL)
{
/* We need to change XP_MakeHTMLAlert to use UTF8 */
XP_MakeHTMLAlert(NULL, errStr);
}
}
ldap_unbind(ld);
ldap_free_urldesc(ldURL);
return(err);
}
PRBool
ldapAddChild (RDFT rdf, RDF_Resource parent, RDF_Resource child)
{
return (ldapModifyEntry(rdf, parent, child, true) != LDAP_SUCCESS);
}
PRBool
ldapRemoveChild (RDFT rdf, RDF_Resource parent, RDF_Resource child)
{
return (ldapModifyEntry(rdf, parent, child, false) != LDAP_SUCCESS);
}
void
possiblyAccessldap(RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep)
{
/** try to get the values of u.s from the directory **/
LDAP *ld;
LDAPMessage *result=NULL, *entry;
LDAPURLDesc *ldURL=NULL;
RDF_Resource node;
char *attrs[2], **vals;
int err, i;
char *title = NULL;
/*
Note: a labeledURI is a url followed by an optional [space title-string]
*/
if (!stringEquals(resourceID(s), resourceID(gCoreVocab->RDF_parent)) || (!inversep) || (!ldap_is_ldap_url(resourceID(u)))) return;
ldap_url_parse(resourceID(u), &ldURL);
if (ldURL == NULL) return;
ld = ldap_init (ldURL->lud_host, ldURL->lud_port);
if (ld == NULL)
{
ldap_free_urldesc(ldURL);
return;
}
if ((err = ldap_simple_bind_s(ld, NULL, NULL)) != LDAP_SUCCESS)
{
ldap_unbind(ld);
ldap_free_urldesc(ldURL);
return;
}
attrs[0] = "labeledURI";
attrs[1] = NULL;
err = ldap_search_s(ld, ldURL->lud_dn, LDAP_SCOPE_BASE, ldURL->lud_filter, attrs, 0, &result);
if (err == LDAP_SUCCESS)
{
for (entry=ldap_first_entry(ld, result); entry!=NULL; entry=ldap_next_entry(ld, entry))
{
if ((vals = ldap_get_values(ld, entry, attrs[0])) != NULL)
{
for (i=0; vals[i] != NULL; i++)
{
/* vals[i] has a URL... add into RDF graph */
/*
if (((title = strstr(vals[i], " ")) != NULL)
&& (*(title+1) != '\0'))
{
*(++title) = '\0';
}
else
{
title = NULL;
}
*/
if ((node = RDF_Create(vals[i], true)) != NULL)
{
setResourceType(node, LDAP_RT);
if (ldapContainerp(node) == true)
{
setContainerp(node, 1);
}
ldapDBAdd(rdf, node, gCoreVocab->RDF_parent,
u, RDF_RESOURCE_TYPE);
if (title != NULL)
{
ldapDBAdd(rdf, node, gCoreVocab->RDF_name,
title, RDF_STRING_TYPE);
}
}
}
ldap_value_free(vals);
}
}
}
if (result != NULL)
{
ldap_msgfree(result);
}
ldap_unbind(ld);
ldap_free_urldesc(ldURL);
}
PRBool
ldapContainerp (RDF_Resource u)
{
return(ldap_is_ldap_url(resourceID(u))); /* XXX ??? */
}
#endif /* MOZ_LDAP */
#endif

View File

@@ -0,0 +1,69 @@
/* -*- 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_LDAP2RDF_H_
#define _RDF_LDAP2RDF_H_
#include "rdf-int.h"
#ifdef MOZ_LDAP
#include "ldap.h"
#include "xpgetstr.h"
#include "htmldlgs.h"
#endif
/* ldap2rdf.c data structures and defines */
#define ADMIN_ID "uid=rjc, ou=People, o=airius.com"
#define ADMIN_PW "netscape"
/* ldap2rdf.c function prototypes */
NSPR_BEGIN_EXTERN_C
RDFT MakeLdapStore (char* url);
RDF_Error LdapInit (RDFT ntr);
void ldap2rdfInit (RDFT rdf);
Assertion ldaparg1 (RDF_Resource u);
Assertion setldaparg1 (RDF_Resource u, Assertion as);
Assertion ldaparg2 (RDF_Resource u);
Assertion setldaparg2 (RDF_Resource u, Assertion as);
PRBool ldapAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool ldapUnassert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool ldapDBAdd (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool ldapDBRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool ldapHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
void * ldapGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor ldapGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * ldapNextValue (RDFT mcf, RDF_Cursor c);
RDF_Error ldapDisposeCursor (RDFT mcf, RDF_Cursor c);
RDF_Resource ldapNewContainer(char *id);
int ldapModifyEntry (RDFT rdf, RDF_Resource parent, RDF_Resource child, PRBool addFlag);
PRBool ldapAddChild (RDFT rdf, RDF_Resource parent, RDF_Resource child);
PRBool ldapRemoveChild (RDFT rdf, RDF_Resource parent, RDF_Resource child);
void possiblyAccessldap(RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep);
PRBool ldapContainerp (RDF_Resource u);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,52 @@
#!gmake
#
# 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.
DEPTH = ..\..\..
LIBRARY_SUFFIX=$(MOZ_BITS)
MAKE_OBJ_TYPE=DLL
MODULE=rdf
LIBRARY_NAME=rdf
REQUIRES=nspr
C_OBJS=.\$(OBJDIR)\vocab.obj \
.\$(OBJDIR)\mcf.obj \
.\$(OBJDIR)\remstore.obj \
.\$(OBJDIR)\utils.obj \
.\$(OBJDIR)\rdfparse.obj \
.\$(OBJDIR)\bmk2mcf.obj \
.\$(OBJDIR)\columns.obj \
.\$(OBJDIR)\rdfht.obj \
$(NULL)
CPP_OBJS=\
.\$(OBJDIR)\comwrap.obj \
.\$(OBJDIR)\netglue.obj \
$(NULL)
LINCS=-I$(XPDIST)\public\xpcom
LINCS=$(LINCS) -I$(PUBLIC)\rdf
LINCS=$(LINCS) -I$(PUBLIC)\netlib -I$(PUBLIC)\raptor
include <$(DEPTH)\config\rules.mak>
libs:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,93 @@
/* -*- 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_MCF_H_
#define _RDF_MCF_H_
#include "rdf-int.h"
#include "prprf.h"
#include "prtime.h"
#include <string.h>
/* mcf.c data structures and defines */
struct RDF_NotificationStruct {
RDF_Event theEvent;
void* pdata;
RDF_NotificationProc notifFunction;
RDF rdf;
struct RDF_NotificationStruct* next;
};
#define ntr(r, n) (*((RDFT*)r->translators + n))
#define ntrn(r, n) (*((RDFT*)r->translators + n) == NULL)
#define callAssert(n, r, u, s, v,type,tv) (ntrn(r, n) || (ntr(r, n)->assert == NULL) ? 0 : (*(ntr(r, n)->assert))(ntr(r, n), u, s, v, type, tv))
#define callUnassert(n, r, u, s, v,type) (ntrn(r, n) || (ntr(r, n)->unassert == NULL) ? 0 : (*(ntr(r, n)->unassert))(ntr(r, n), u, s, v, type))
#define callGetSlotValue(n, r, u, s, type, invp, tv) (ntrn(r, n) || (ntr(r, n)->getSlotValue == NULL) ? 0 : (*(ntr(r, n)->getSlotValue))(ntr(r, n), u, s, type, invp, tv))
#define callGetSlotValues(n, r, u, s, type,invp, tv) (ntrn(r, n) || (ntr(r, n)->getSlotValues == NULL) ? 0 : (*(ntr(r, n)->getSlotValues))(ntr(r, n), u, s, type,invp, tv))
#define callHasAssertions(n, r, u, s, v,type,tv) (ntrn(r, n) || (ntr(r, n)->hasAssertion == NULL) ? 0 : (*(ntr(r, n)->hasAssertion))(ntr(r, n), u, s, v, type, tv))
#define callArcLabelsOut(n, r, u) (ntrn(r, n) || (ntr(r, n)->arcLabelsOut == NULL) ? 0 : (*(ntr(r, n)->arcLabelsOut))(ntr(r, n), u))
#define callArcLabelsIn(n, r, u) (ntrn(r, n) || (ntr(r, n)->arcLabelsIn == NULL) ? 0 : (*(ntr(r, n)->arcLabelsIn))(ntr(r, n), u))
#define callDisposeResource(n, r, u) (ntrn(r, n) || (ntr(r, n)->disposeResource == NULL) ? 1 : (*(ntr(r, n)->disposeResource))(ntr(r, n), u))
#define callExitRoutine(n, r) (ntrn(r, n) || (ntr(r, n)->destroy == NULL) ? 0 : (*(ntr(r, n)->destroy))(ntr(r, n)))
#define callUpdateRoutine(n, r, u) (ntrn(r, n) || (ntr(r, n)->update == NULL) ? 0 : (*(ntr(r, n)->update))(ntr(r, n), u))
#define ID_BUF_SIZE 20
/* mcf.c function prototypes */
RDFT getTranslator (char* url);
RDFL deleteFromRDFList (RDFL xrl, RDF db);
RDF_Error exitRDF (RDF rdf);
RDF_Resource addDep (RDF db, RDF_Resource u);
PRBool rdfassert(RDF rdf, RDF_Resource u, RDF_Resource s, void* value, RDF_ValueType type, PRBool tv);
PRBool containerIDp(char* id);
char * makeNewID ();
PRBool iscontainerp (RDF_Resource u);
RDF_BT resourceTypeFromID (char* id);
RDF_Resource specialUrlResource (char* id);
RDF_Resource NewRDFResource (char* id);
RDF_Resource QuickGetResource (char* id);
RDF_Cursor getSlotValues (RDF rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void disposeResourceInt (RDF rdf, RDF_Resource u);
void possiblyGCResource (RDF_Resource u);
RDF_Resource NewRDFResource (char* id);
RDF_Resource QuickGetResource (char* id);
void assertNotify (RDF rdf, RDF_Notification not, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv, char* ds);
void insertNotify (RDF rdf, RDF_Notification not, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv, char* ds);
void unassertNotify (RDF_Notification not, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, char* ds);
void sendNotifications1 (RDFL rl, RDF_EventType opType, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
void sendNotifications (RDF rdf, RDF_EventType opType, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv, char* ds);
RDF_Resource nextFindValue (RDF_Cursor c);
PRBool matchStrings(RDF_Resource match, char *str1, char *str2);
PRBool itemMatchesFind (RDF r, RDF_Resource u, RDF_Resource s, void* v, RDF_Resource match, RDF_ValueType type);
PR_PUBLIC_API(RDF_Cursor)RDF_Find (RDF_Resource s, RDF_Resource match, void* v, RDF_ValueType type);
PRIntn findEnumerator (PLHashEntry *he, PRIntn i, void *arg);
void disposeAllDBs ();
#endif

View File

@@ -0,0 +1,374 @@
/* -*- 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.
*/
#include "mcff2mcf.h"
#include "utils.h"
int
parseNextMCFBlob(NET_StreamClass *stream, char* blob, int32 size)
{
RDFFile f;
int32 n, last, m;
n = last = 0;
f = (RDFFile)stream->data_object;
if ((f == NULL) || (size < 0)) {
return MK_INTERRUPTED;
}
while (n < size) {
char c = blob[n];
m = 0;
memset(f->line, '\0', f->lineSize);
if (f->holdOver[0] != '\0') {
memcpy(f->line, f->holdOver, RDF_STRLEN(f->holdOver));
m = RDF_STRLEN(f->holdOver);
memset(f->holdOver, '\0', RDF_BUF_SIZE);
}
while ((m < f->lineSize) && (c != '\r') && (c != '\n') && (n < size)) {
f->line[m] = c;
m++;
n++;
c = blob[n];
}
n++;
if (m > 0) {
if ((c == '\n') || (c == '\r')) {
last = n;
parseNextMCFLine(f, f->line);
} else if (size > last) {
memcpy(f->holdOver, f->line, m);
}
}
}
return(size);
}
void
parseNextMCFLine (RDFFile f, char* line)
{
char* nextToken ;
int16 offset = 0;
RDF_Error err;
if ((nullp(line)) || (line[0] == '\0'))return;
nextToken = getMem(MAX_URL_SIZE);
err = getFirstToken(line, nextToken, &offset);
offset++;
if ((err != noRDFErr) && (nextToken[0] == ';')) {
freeMem(nextToken);
return;
}
if (startsWith("begin-headers", nextToken)) {
f->status = HEADERS;
} else if (startsWith("end-headers", nextToken)) {
f->status = BODY;
} else if (startsWith("unit", nextToken)) {
f->status = BODY;
if (!(nullp(f->currentResource))) resourceTransition(f);
getFirstToken(&line[offset], nextToken, &offset);
f->currentResource = resolveReference(nextToken, f);
} else if (nextToken[RDF_STRLEN(nextToken)-1] == ':') {
memset(f->currentSlot, '\0', 100);
memcpy(f->currentSlot, nextToken, RDF_STRLEN(nextToken)-1);
while (getFirstToken(&line[offset], nextToken, &offset) == noRDFErr) {
if (f->status == HEADERS) {
assignHeaderSlot(f, f->currentSlot, nextToken);
} else if (f->currentResource) {
assignSlot(f->currentResource, f->currentSlot, nextToken, f);
}
offset++;
}
}
freeMem(nextToken);
}
void
finishMCFParse (RDFFile f)
{
parseNextMCFLine(f, f->storeAway);
resourceTransition(f);
}
void
resourceTransition (RDFFile f)
{
if ((f->currentResource) && (!f->genlAdded))
addSlotValue(f, f->currentResource, gCoreVocab->RDF_parent, f->rtop,
RDF_RESOURCE_TYPE, NULL);
f->genlAdded = false;
}
void
assignHeaderSlot (RDFFile f, char* slot, char* value)
{
if (startsWith(slot, "expiresOn")) {
if (f->expiryTime == NULL) f->expiryTime = (PRTime*)getMem(sizeof(PRTime));
if (PR_ParseTimeString (value, 0, f->expiryTime) != PR_SUCCESS) {
freeMem(f->expiryTime);
f->expiryTime = NULL;
}
} else if (!(startsWith(slot, "RDFVersion"))) {
assignSlot(f->top, slot, value, f);
}
}
RDF_Error
getFirstToken (char* line, char* nextToken, int16* l)
{
PRBool in_paren = 0;
PRBool in_string = 0;
PRBool in_bracket = 0;
PRBool something_seen = 0;
uint16 front_spaces = 0;
uint16 index;
RDF_Error ans = -1;
memset(nextToken, '\0', 200);
for (index = 0; index < RDF_STRLEN(line); index++) {
char c = line[index];
if ((c == '\n') || (c == '\0') || (c == '\r')) {
*l = index + *l ;
return ans;
}
if ((c == ':') && ((index == 0) || (line[index-1] == ' ')) &&
((line[index+1] == ' ') || (line[index+1] == '\0'))) c = ' ';
if (c != ' ') something_seen = 1;
if (in_paren) {
if (c == ')') {
nextToken[index-front_spaces] = c;
ans = noRDFErr;
*l = index + *l ;
return ans;
} else {
ans = noRDFErr;
nextToken[index-front_spaces] = c;
}
} else if (in_string) {
if (c == '"') {
nextToken[index-front_spaces] = c;
ans = noRDFErr;
*l = index + *l ;
return ans;
} else {
ans = noRDFErr;
nextToken[index-front_spaces] = c;
}
} else if (in_bracket) {
if (c == ']') {
nextToken[index-front_spaces] = c;
*l = index + *l ;
ans = noRDFErr;
return ans;
} else {
ans = noRDFErr;
nextToken[index-front_spaces] = c;
}
} else if (c == '"') {
ans = noRDFErr;
nextToken[index-front_spaces] = c;
in_string = 1;
} else if (c == '[') {
ans = noRDFErr;
nextToken[index-front_spaces] = c;
in_bracket = 1;
} else if (c == '(') {
ans = noRDFErr;
nextToken[index-front_spaces] = c;
in_paren = 1;
} else if (c == ' '){
if (something_seen) {
*l = index + *l ;
return ans;
} else {
front_spaces++;
}
} else {
ans = noRDFErr;
nextToken[index-front_spaces] = c;
}
}
*l = index + *l ;
return ans;
}
void
assignSlot (RDF_Resource u, char* slot, char* value, RDFFile f)
{
PRBool tv = true;
char* tvstr;
if (value[0] == '(') {
tv = false;
value = &value[1];
value[RDF_STRLEN(value)-1] = '\0';
}
if (tv) {
tvstr = "true";
} else tvstr = "false";
if (startsWith("default_genl", slot)) return;
if (startsWith("name", slot) || (startsWith("local-name", slot))) {
value[RDF_STRLEN(value)-1] = '\0';
addSlotValue(f, u, gCoreVocab->RDF_name, copyString(&value[1]), RDF_STRING_TYPE, tvstr);
} else if (startsWith("specs", slot) || (startsWith("child", slot))) {
RDF_Resource spec = resolveReference(value, f);
if (!nullp(spec)) addSlotValue(f, spec, gCoreVocab->RDF_parent, u, RDF_RESOURCE_TYPE, tvstr);
} else if (startsWith("genls_pos", slot)) {
RDF_Resource genl = resolveGenlPosReference(value, f);
if (!nullp(genl)) addSlotValue(f, u, gCoreVocab->RDF_parent, genl, RDF_RESOURCE_TYPE, tvstr);
} else if ((startsWith("genls", slot)) || (startsWith("parent", slot))) {
RDF_Resource genl = resolveReference(value, f);
if (!nullp(genl)) addSlotValue(f, u, gCoreVocab->RDF_parent, genl, RDF_RESOURCE_TYPE, tvstr);
} else {
void* parsed_value;
RDF_ValueType data_type;
RDF_Resource s = RDF_GetResource(NULL, slot, true);
RDF_Error err = parseSlotValue(f, s, value, &parsed_value, &data_type);
if ((err == noRDFErr) && (!nullp(parsed_value)))
addSlotValue(f, u, s, parsed_value, data_type, tvstr);
}
}
RDF_Error
parseSlotValue (RDFFile f, RDF_Resource s, char* value, void** parsed_value, RDF_ValueType* data_type)
{
if (value[0] == '"') {
int32 size = RDF_STRLEN(value)-1;
*parsed_value = getMem(size);
value[size] = '\0';
*parsed_value = &value[1];
*data_type = RDF_STRING_TYPE;
return noRDFErr;
} else if (value[0] == '#') {
if (value[1] == '"') {
value[RDF_STRLEN(value)-1] = '\0';
value = &value[2];
} else {
value = &value[1];
}
*parsed_value = resolveReference(value, f);
return noRDFErr;
} else if (charSearch('.', value) == -1) {
int16 ans = 0;
/* XXX sscanf(value, "%ld", &ans); */
*data_type = RDF_INT_TYPE;
return noRDFErr;
} else {
return -1;
}
}
void
derelativizeURL (char* tok, char* url, RDFFile f)
{
if ((tok[0] == '/') && (endsWith(".mco", tok))) {
void stringAppendBase (char* dest, const char* addition) ;
stringAppendBase(url, f->url);
stringAppend(url, "#");
stringAppend(url, tok);
} else if ((endsWith(".mco", tok)) && (charSearch('#', tok) == -1)) {
void stringAppendBase (char* dest, const char* addition) ;
stringAppendBase(url, f->url);
stringAppend(url, "#");
stringAppend(url, tok);
} else {
memcpy(url, tok, RDF_STRLEN(tok));
}
}
RDF_Resource
resolveReference (char *tok, RDFFile f)
{
RDF_Resource existing;
char* url = getMem(MAX_URL_SIZE);
if (tok[0] == '#') tok = &tok[1];
if (tok[RDF_STRLEN(tok)-1] == '"') tok[strlen(tok)-1] = '\0';
if (tok[0] == '"') tok = &tok[1];
memset(url, '\0', 200);
if (charSearch(':', tok) == -1) {
derelativizeURL(tok, url, f);
} else {
memcpy(url, tok, RDF_STRLEN(tok));
}
if (RDF_STRCMP(url,"this") == 0) {
existing = f->top;
} else {
existing = RDF_GetResource(NULL, url, false);
}
if (existing != null) return existing;
existing = RDF_GetResource(NULL, url, true);
addToResourceList(f, existing);
freeMem(url);
return existing;
}
RDF_Resource
resolveGenlPosReference(char* tok, RDFFile f)
{
RDF_Resource ans;
char* url = (char*)getMem(MAX_URL_SIZE);
long i1, i2;
i1 = charSearch('"', tok);
i2 = revCharSearch('"', tok);
memcpy(url, &tok[i1], i2-i1+1);
ans = resolveReference(url, f);
freeMem(url);
return ans;
}
char *
getRelURL (RDF_Resource u, RDF_Resource top)
{
char* uID = resourceID(u);
char* topID = resourceID(top);
if (startsWith(topID, uID)) {
int16 n = charSearch('#', uID);
if (n == -1) return uID;
return &(uID)[n+1];
} else return uID;
}

View File

@@ -0,0 +1,61 @@
/* -*- 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_MCFF2MCF_H_
#define _RDF_MCFF2MCF_H_
#include "rdf-int.h"
/* mcff2mcf.c data structures and defines */
/* mcff2mcf.c function prototypes */
NSPR_BEGIN_EXTERN_C
RDF_Resource getMCFFrtop (char* furl);
RDFFile makeRDFFile (char* url, RDF_Resource top, PRBool localp);
void initRDFFile (RDFFile ans);
void finishRDFParse (RDFFile f);
void abortRDFParse (RDFFile f);
void addToResourceList (RDFFile f, RDF_Resource u);
void addToAssertionList (RDFFile f, Assertion as);
void parseNextRDFBlob (RDFFile f, char* blob, int32 size);
int parseNextMCFBlob(NET_StreamClass *stream, char* blob, int32 size);
void parseNextMCFLine (RDFFile f, char* line);
void finishMCFParse (RDFFile f);
void resourceTransition (RDFFile f);
void assignHeaderSlot (RDFFile f, char* slot, char* value);
RDF_Error getFirstToken (char* line, char* nextToken, int16* l);
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);
void derelativizeURL (char* tok, char* url, RDFFile f);
RDF_Resource resolveReference (char *tok, RDFFile f);
RDF_Resource resolveGenlPosReference(char* tok, RDFFile f);
char * getRelURL (RDF_Resource u, RDF_Resource top);
PRBool bookmarkSlotp (RDF_Resource s);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,165 @@
/* -*- 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.
*/
#include "nsIStreamListener.h"
#include "nsIURL.h"
#include "nsIInputStream.h"
#include "nsString.h"
#include "rdf-int.h"
class rdfStreamListener : public nsIStreamListener
{
public:
NS_DECL_ISUPPORTS
rdfStreamListener(RDFFile);
~rdfStreamListener();
NS_METHOD GetBindInfo(nsIURL* aURL);
NS_METHOD OnProgress(nsIURL* aURL, PRInt32 Progress, PRInt32 ProgressMax);
NS_METHOD OnStatus(nsIURL* aURL, const nsString& aMsg);
NS_METHOD OnStartBinding(nsIURL* aURL, const char *aContentType);
NS_METHOD OnDataAvailable(nsIURL* aURL, nsIInputStream *pIStream, PRInt32 length);
NS_METHOD OnStopBinding(nsIURL* aURL, PRInt32 status, const nsString& aMsg);
protected:
rdfStreamListener::rdfStreamListener();
private:
RDFFile mFile;
};
rdfStreamListener::rdfStreamListener(RDFFile f) : mFile(f)
{
}
rdfStreamListener::~rdfStreamListener()
{
}
NS_METHOD
rdfStreamListener::GetBindInfo(nsIURL* aURL)
{
return NS_OK;
}
NS_METHOD
rdfStreamListener::OnProgress(nsIURL* aURL,
PRInt32 Progress,
PRInt32 ProgressMax)
{
return NS_OK;
}
NS_METHOD
rdfStreamListener::OnStatus(nsIURL* aURL,
const nsString& aMsg)
{
return NS_OK;
}
NS_METHOD
rdfStreamListener::OnStartBinding(nsIURL* aURL,
const char *aContentType)
{
return NS_OK;
}
NS_METHOD
rdfStreamListener::OnDataAvailable(nsIURL* aURL,
nsIInputStream *pIStream,
PRInt32 length)
{
PRInt32 len;
// PRLOG(("\n+++ rdfStreamListener::OnDataAvailable: URL: %p, %d bytes available...\n", aURL, length));
do {
const PRUint32 buffer_size = 80;
char buffer[buffer_size];
nsresult err = pIStream->Read(buffer, 0, buffer_size, &len);
if (err == NS_OK) {
(void) parseNextRDFXMLBlobInt(mFile, buffer, len);
} // else XXX ?
} while (len > 0);
return NS_OK;
}
NS_METHOD
rdfStreamListener::OnStopBinding(nsIURL* aURL,
PRInt32 status,
const nsString& aMsg)
{
nsresult result = NS_OK;
switch( status ) {
case NS_BINDING_SUCCEEDED:
finishRDFParse( mFile );
break;
case NS_BINDING_FAILED:
case NS_BINDING_ABORTED:
abortRDFParse( mFile );
// XXX status code?
break;
default:
PR_ASSERT(PR_FALSE);
result = NS_ERROR_ILLEGAL_VALUE;
}
return result;
}
/*
* beginReadingRDFFile is called whenever we need to read something of
* the net (or local drive). The url of the file to be read is at
* file->url. As the bits are read in (and it can take the bits in
* any sized chunks) it should call parseNextRDFBlobInt(file, nextBlock,
* blobSize) when its done, it should call void finishRDFParse
* (RDFFile f) to abort, it should call void abortRDFParse (RDFFile f)
* [which will undo all that has been read from that file]
*/
void
beginReadingRDFFile (RDFFile file)
{
rdfStreamListener* pListener = new rdfStreamListener(file);
pListener->AddRef(); // XXX is this evil? Can't see any reason to use factories but...
nsIURL* pURL = NULL;
nsString url_address( file->url );
nsresult r = NS_NewURL( &pURL, url_address );
if( NS_OK != r ) {
// XXX what to do?
}
r = pURL->Open(pListener);
if( NS_OK != r ) {
// XXX what to do?
}
}

View File

@@ -0,0 +1,829 @@
/* -*- 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 local 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 "nlcstore.h"
#include "glue.h"
#include "mcf.h"
#include "xpassert.h"
#include "utils.h"
/* globals */
PRBool doingFirstTimeInitp = 0;
RDFT gOPSStore = 0;
/* externs */
extern char *profileDirURL;
extern char *gBookmarkURL;
/*
To do : killing a unit
*/
PRBool
compareUnalignedUINT32Ptrs(void *v1, void *v2)
{
uint32 val1, val2;
memcpy(&val1,v1,sizeof(uint32));
memcpy(&val2,v2,sizeof(uint32));
return((val1==val2) ? PR_TRUE:PR_FALSE);
}
void
DBM_OpenDBMStore (DBMRDF store, char* directory)
{
HASHINFO hash_info = {128, 0, 0, 0, 0, 0};
PRBool createp = 0;
char* dbPathname;
char* dirPathname;
CHECK_VAR1(profileDirURL);
dirPathname = makeDBURL(directory);
CallPRMkDirUsingFileURL(dirPathname, 00700);
freeMem(dirPathname);
dbPathname = makeRDFDBURL(directory, "names.db");
CHECK_VAR1(dbPathname);
store->nameDB = CallDBOpenUsingFileURL(dbPathname, O_RDWR, 0644, DB_HASH, &hash_info);
if (store->nameDB == NULL) {
createp = 1;
store->nameDB = CallDBOpenUsingFileURL(dbPathname, O_RDWR | O_CREAT, 0644, DB_HASH, &hash_info);
}
freeMem(dbPathname);
CHECK_VAR1(store->nameDB);
dbPathname = makeRDFDBURL(directory, "child.db");
CHECK_VAR1(dbPathname);
hash_info.bsize = 2056;
store->childrenDB = CallDBOpenUsingFileURL(dbPathname,
O_RDWR | O_CREAT, 0644, DB_HASH, &hash_info);
freeMem(dbPathname);
CHECK_VAR1(store->childrenDB);
dbPathname = makeRDFDBURL(directory, "lstr.db");
hash_info.bsize = 1024 ;
store->propDB = CallDBOpenUsingFileURL(dbPathname,
O_RDWR | O_CREAT, 0644, DB_HASH, &hash_info);
freeMem(dbPathname);
CHECK_VAR1(store->propDB);
dbPathname = makeRDFDBURL(directory, "ilstr.db");
CHECK_VAR1(dbPathname);
hash_info.bsize = 1024*16;
store->invPropDB = CallDBOpenUsingFileURL(dbPathname,
O_RDWR | O_CREAT, 0644, DB_HASH, &hash_info);
freeMem(dbPathname);
CHECK_VAR1(store->invPropDB);
if (RDF_STRCMP(directory, "NavCen") == 0) {
}
}
RDF_Error
DBM_CloseRDFDBMStore (RDFT r)
{
DBMRDF db = (DBMRDF)r->pdata;
if (r->rdf) return 0;
if (db->nameDB != NULL) (*db->nameDB->close)(db->nameDB);
if (db->childrenDB != NULL) (*db->childrenDB->close)(db->childrenDB);
if (db->propDB != NULL) (*db->propDB->close)(db->propDB);
if (db->invPropDB != NULL) (*db->invPropDB->close)(db->invPropDB);
freeMem(db);
r->pdata = NULL;
return 0;
}
char *
makeUSKey (RDF_Resource u, RDF_Resource s, PRBool inversep, size_t *size)
{
if ((s == gCoreVocab->RDF_name) || (inversep && (s == gCoreVocab->RDF_parent))) {
*size = RDF_STRLEN(resourceID(u));
return resourceID(u);
} else {
char* ans;
*size = RDF_STRLEN(resourceID(u)) + strlen(resourceID(s));
ans = getMem(*size);
memcpy(ans, resourceID(u), RDF_STRLEN(resourceID(u)));
memcpy(&ans[RDF_STRLEN(resourceID(u))], resourceID(s), strlen(resourceID(s)));
return ans;
}
}
DB *
getUSDB (RDFT r, RDF_Resource u, RDF_Resource s, PRBool inversep)
{
DBMRDF db = (DBMRDF)r->pdata;
if (inversep) {
if (s == gCoreVocab->RDF_parent) {
return db->childrenDB;
} else {
return db->invPropDB;
}
} else if (s == gCoreVocab->RDF_name) {
return db->nameDB;
} else return db->propDB;
}
void
freeKey (char* keyData, RDF_Resource u, RDF_Resource s, PRBool inversep)
{
if ((s == gCoreVocab->RDF_name) || (inversep && (s == gCoreVocab->RDF_parent))) return;
freeMem(keyData);
}
DBMAs *
DBM_GetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep, size_t *size)
{
size_t keySize;
void* keyData = makeUSKey(u, s, inversep, &keySize);
DBT key, data;
DB *db;
int status;
CHECK_VAR(keyData, NULL);
key.data = keyData;
key.size = keySize;
db = getUSDB(rdf, u, s, inversep);
if (db == NULL) {
*size = 0;
freeKey(keyData, u, s, inversep);
return NULL;
}
status = (*db->get)(db, &key, &data, 0);
if (status != 0) {
*size = 0;
freeKey(keyData, u, s, inversep);
return NULL;
} else {
void* ans = (char*)getMem(data.size);
*size = data.size;
memcpy(ans, data.data, *size);
freeKey(keyData, u, s, inversep);
return (DBMAs*) ans;
}
}
void
DBM_PutSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep, void* value, size_t size)
{
size_t keySize;
void* keyData = makeUSKey(u, s, inversep, &keySize);
DBT key, data;
int status;
DB* db;
CHECK_VAR1(keyData);
db = getUSDB(rdf, u, s, inversep);
if (db == NULL) {
freeKey(keyData, u, s, inversep);
return ;
}
key.data = keyData;
key.size = keySize;
data.data = value;
data.size = size;
status = (*db->del)(db, &key, 0);
if (value != NULL) {
status = (*db->put)(db, &key, &data, 0);
}
if ((status == 0) && (!doingFirstTimeInitp)) (*db->sync)(db, 0);
freeKey(keyData, u, s, inversep);
}
PRBool
nlocalStoreHasAssertion (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv)
{
size_t size ;
DBMAs *data;
uint16 n = 0;
PRBool ans = 0;
PRBool invp = (s == gCoreVocab->RDF_parent);
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
data = (invp ? DBM_GetSlotValue(rdf, (RDF_Resource)v, s, 1, &size) :
DBM_GetSlotValue(rdf, u, s, 0, &size));
if (data == NULL) return 0;
while (n < size) {
DBMAs nas = nthdbmas(data, n);
if (nas == NULL) break;
if ((type == valueTypeOfAs(nas)) && (tvOfAs(nas) == tv) &&
(invp ? valueEqual(type, dataOfDBMAs(nas), u) : valueEqual(type, dataOfDBMAs(nas), v))) {
ans = 1;
break;
}
n = dbmasSize(nas) + n;
}
freeMem(data);
return ans;
}
void *
nlocalStoreGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type, PRBool inversep, PRBool tv)
{
size_t size ;
DBMAs *data;
uint16 n = 0;
void* ans;
data = DBM_GetSlotValue(rdf, u, s, inversep, &size);
if (data == NULL) return 0;
while (n < size) {
DBMAs nas = nthdbmas(data, n);
if (nas == NULL) break;
if (type == valueTypeOfAs(nas)) {
if (type == RDF_STRING_TYPE) {
ans = copyString((char *)dataOfDBMAs(nas));
} else if (type == RDF_RESOURCE_TYPE) {
ans = RDF_GetResource(NULL, (char *)dataOfDBMAs(nas), true);
} else if (type == RDF_INT_TYPE) {
/* ans = dataOfDBMAs(nas); */
memcpy((char*)&ans, dataOfDBMAs(nas), sizeof(uint32));
}
freeMem(data);
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )ans)));
return ans;
}
n = dbmasSize(nas) + n;
}
freeMem((void*)data);
return NULL;
}
RDF_Cursor
nlocalStoreGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s,
RDF_ValueType type,
PRBool inversep, PRBool tv)
{
RDF_Cursor c;
void* val;
size_t size;
if (resourceType(u) == LFS_RT) return NULL;
if (!tv && (s != gCoreVocab->RDF_parent)) return NULL;
val = DBM_GetSlotValue(rdf, u, s, inversep, &size);
if (val == NULL) return NULL;
c = (RDF_Cursor) getMem(sizeof(struct RDF_CursorStruct));
if (c == NULL) {
freeMem(val);
return NULL;
}
c->u = u;
c->s = s;
c->inversep = inversep;
c->type = type;
c->tv = tv;
c->count = 0;
c->pdata = val;
c->size = size;
return c;
}
void *
nlocalStoreNextValue (RDFT rdf, RDF_Cursor c)
{
void* ans;
void* data;
if ((c == NULL) || (c->pdata == NULL)) return NULL;
if ((c->type == RDF_ARC_LABELS_IN_QUERY) || (c->type == RDF_ARC_LABELS_OUT_QUERY))
return nlcStoreArcsInOutNextValue(rdf, c);
data = c->pdata;
while (c->count < c->size) {
DBMAs nas = nthdbmas(data, c->count);
if (nas == NULL) break;
if ((c->tv == tvOfAs(nas)) && (c->type == valueTypeOfAs(nas))) {
if (c->type == RDF_RESOURCE_TYPE) {
RDF_Resource nu = RDF_GetResource(NULL, (char *)dataOfDBMAs(nas), 1);
if (nu && startsWith("http:", resourceID(nu)) && strstr(resourceID(nu), ".rdf")) {
RDFL rl = rdf->rdf;
char* dburl = getBaseURL(resourceID(nu));
while (rl) {
RDF_AddDataSource(rl->rdf, dburl);
rl = rl->next;
}
freeMem(dburl);
}
ans = nu;
c->count = dbmasSize(nas) + c->count;
return nu;
} else {
ans = dataOfDBMAs(nas);
c->count = dbmasSize(nas) + c->count;
return ans;
}
}
c->count = dbmasSize(nas) + c->count;
}
return NULL;
}
RDF_Error
nlocalStoreDisposeCursor (RDFT rdf, RDF_Cursor c)
{
if (c != NULL) {
if (c->pdata) freeMem(c->pdata);
c->pdata = NULL;
freeMem(c);
}
return noRDFErr;
}
DBMAs
makeAsBlock (void* v, RDF_ValueType type, PRBool tv, size_t *size)
{
size_t vsize=0;
DBMAs ans;
int rem = 0;
/*
ldiv_t cdiv ;
*/
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
if (type == RDF_STRING_TYPE) {
vsize = RDF_STRLEN(v);
} else if (type == RDF_RESOURCE_TYPE) {
vsize = RDF_STRLEN( resourceID((RDF_Resource)v));
} else if (type == RDF_INT_TYPE) {
vsize = 4;
}
*size = 4 + vsize + 1;
rem = *size % 4;
if (rem) {
*size += 4 - rem;
}
ans = (DBMAs) getMem(*size);
if (ans == NULL) return NULL;
ans->size[0] = (uint8)(((*size) & 0x00FF0000) >> 16);
ans->size[1] = (uint8)(((*size) & 0x0000FF00) >> 8);
ans->size[2] = (uint8)((*size) & 0x000000FF);
*(((unsigned char *)ans)+3) = (tv ? 0x10 : 0) | (type & 0x0F);
if (type == RDF_STRING_TYPE) {
memcpy((char*)ans+4, (char*) v, vsize);
} else if (type == RDF_RESOURCE_TYPE) {
memcpy((char*)ans+4, resourceID((RDF_Resource)v), vsize);
} else if (type == RDF_INT_TYPE) {
memcpy((char*)ans+4, (char*)v, vsize);
}
/*
cdiv = ldiv(*size, 256);
ans->size[0] = (uint8)(cdiv.quot);
ans->size[1] = (uint8)(cdiv.rem);
ans->tag = (tv ? 0x10 : 0) | (type & 0x0F);
if (type == RDF_STRING_TYPE) {
memcpy((char*)ans+3, (char*) v, vsize);
} else if (type == RDF_RESOURCE_TYPE) {
memcpy((char*)ans+3, resourceID((RDF_Resource)v), vsize);
} else if (type == RDF_INT_TYPE) {
memcpy((char*)ans+3, (char*)v, vsize);
}
*/
return ans;
}
PRBool
nlocalStoreAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
size_t size ;
DBMAs* data;
char* ndata;
DBMAs temp;
uint16 n = 0;
size_t tsize;
PRBool ans = 0;
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
/* don't store RDF Commands in the local store */
if (s == gNavCenter->RDF_Command) return 0;
data = DBM_GetSlotValue(rdf, u, s, 0, &size);
if (((data == NULL) && (size != 0)) || ((size == 0) && (data != NULL))) return 0;
while (n < size) {
DBMAs nas = nthdbmas(data, n);
if (nas == NULL) {freeMem(data); return 0;}
if (type == valueTypeOfAs(nas) && (valueEqual(type, dataOfDBMAs(nas), v))) {
ans = 1;
break;
}
n = dbmasSize(nas) + n;
}
if (ans) {
freeMem(data);
return 1;
} else {
temp = makeAsBlock(v, type, tv, &tsize);
if (temp == NULL) {freeMem(data);return 0;}
if (data == NULL) {
DBM_PutSlotValue(rdf, u, s, 0, (void*)temp, tsize);
/* addSlotsHere(rdf, u, s); */
freeMem(temp);
temp = NULL;
} else {
ndata = (char*)getMem(size + tsize);
if (ndata == NULL) {freeMem(data); freeMem(temp);return 0;}
memcpy(ndata, data, size);
memcpy(&ndata[size], (char*)temp, tsize);
DBM_PutSlotValue(rdf, u,s, 0, ndata, size+tsize);
freeMem(data);
freeMem(ndata);
freeMem(temp);
}
if (type == RDF_RESOURCE_TYPE) {
temp = makeAsBlock(u, RDF_RESOURCE_TYPE, tv, &tsize);
if (temp == NULL) return 0;
data = DBM_GetSlotValue(rdf, (RDF_Resource)v, s, 1, &size);
if (data == NULL) {
DBM_PutSlotValue(rdf, (RDF_Resource)v, s, 1, (void*) temp, tsize);
freeMem(temp);
/* addSlotsIn(rdf, (RDF_Resource)v, s);*/
} else {
ndata = (char*)getMem(size + tsize);
if (ndata == NULL) {freeMem(data); freeMem(temp);return 0;}
memcpy(ndata, data, size);
memcpy(&ndata[size], (char*)temp, tsize);
DBM_PutSlotValue(rdf, (RDF_Resource)v, s, 1, ndata, size+tsize);
freeMem(data);
freeMem(ndata);
freeMem(temp);
}
}
}
sendNotifications2(rdf, RDF_INSERT_NOTIFY, u, s, v, type, tv);
return 1;
}
PRBool
nlocalStoreAssert1 (RDFFile f, RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
return nlocalStoreAssert(rdf, u, s, v, type, tv);
}
PRBool
nlocalStoreUnassert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type)
{
size_t size ;
DBMAs* data;
char* temp;
uint16 n = 0;
size_t tsize;
PRBool ans = 0;
DBMAs nas;
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
data = DBM_GetSlotValue(rdf, u, s, 0, &size);
if (data == NULL) return 1;
while (n < size) {
nas = nthdbmas(data, n);
if (type == valueTypeOfAs(nas) && (valueEqual(type, dataOfDBMAs(nas), v))) {
ans = 1;
break;
}
n = dbmasSize(nas) + n;
}
if (!ans) {
freeMem(data);
return 1;
} else {
if (size == dbmasSize(nas)) {
DBM_PutSlotValue(rdf, u, s, 0, NULL, 0);
/*deleteSlotsHere(rdf, u, s);*/
} else {
tsize = size - dbmasSize(nas);
temp = (char*)getMem(tsize);
if (temp == NULL) {
freeMem(data);
return 0;
}
if (n != 0) memcpy(temp, data, n);
memcpy(((char*)temp+n), ((char*)data + n + dbmasSize(nas)), tsize-n);
DBM_PutSlotValue(rdf, u, s, 0, temp, tsize);
freeMem(temp);
}
freeMem(data);
if (type == RDF_RESOURCE_TYPE) {
data = DBM_GetSlotValue(rdf, ((RDF_Resource)v), s, 1, &size);
ans = n = 0;
if (data == NULL) {
return 1;
} else {
while (n < size) {
nas = nthdbmas(data, n);
if (valueEqual(RDF_RESOURCE_TYPE, dataOfDBMAs(nas), u)){
ans = 1;
break;
}
n = dbmasSize(nas) + n;
}
if (!ans) {
return 1;
} else {
if (size == dbmasSize(nas)) {
DBM_PutSlotValue(rdf, (RDF_Resource)v, s, 1, NULL, 0);
/* deleteSlotsIn(rdf, (RDF_Resource)v, s); */
} else {
tsize = size - dbmasSize(nas);
temp = (char*)getMem(tsize);
if (temp == NULL) {
freeMem(data);
return 0;
}
if (n) memcpy(temp, data, n);
memcpy(((char*)temp+n), ((char*)data + n + dbmasSize(nas)), tsize-n);
DBM_PutSlotValue(rdf, ((RDF_Resource)v), s, 1, temp, tsize);
freeMem(temp);
}
freeMem(data);
}
}
}
}
sendNotifications2(rdf, RDF_DELETE_NOTIFY, u, s, v, type, 1);
return 1;
}
void
addSlotsHere (RDFT rdf, RDF_Resource u, RDF_Resource s)
{
if ((s != gCoreVocab->RDF_name) && (s != gCoreVocab->RDF_parent) &&
(s != gCoreVocab->RDF_slotsHere) && (s != gCoreVocab->RDF_slotsIn)) {
nlocalStoreAssert (rdf, u, gCoreVocab->RDF_slotsHere, s, RDF_RESOURCE_TYPE, 1);
}
}
void
deleteSlotsHere (RDFT rdf, RDF_Resource u, RDF_Resource s)
{
if ((s != gCoreVocab->RDF_name) && (s != gCoreVocab->RDF_parent) &&
(s != gCoreVocab->RDF_slotsHere) && (s != gCoreVocab->RDF_slotsIn)) {
nlocalStoreUnassert (rdf, u, gCoreVocab->RDF_slotsHere, s, RDF_RESOURCE_TYPE);
}
}
void
addSlotsIn (RDFT rdf, RDF_Resource u, RDF_Resource s)
{
if ((s != gCoreVocab->RDF_name) && (s != gCoreVocab->RDF_parent) &&
(s != gCoreVocab->RDF_slotsHere) && (s != gCoreVocab->RDF_slotsIn)) {
nlocalStoreAssert (rdf, u, gCoreVocab->RDF_slotsIn, s, RDF_RESOURCE_TYPE, 1);
}
}
void
deleteSlotsIn (RDFT rdf, RDF_Resource u, RDF_Resource s)
{
if ((s != gCoreVocab->RDF_name) && (s != gCoreVocab->RDF_parent) &&
(s != gCoreVocab->RDF_slotsHere) && (s != gCoreVocab->RDF_slotsIn)) {
nlocalStoreUnassert (rdf, u, gCoreVocab->RDF_slotsIn, s, RDF_RESOURCE_TYPE);
}
}
void
nlclStoreKill (RDFT rdf, RDF_Resource u)
{
size_t size ;
DBMAs* data;
uint16 n = 0;
data = DBM_GetSlotValue(rdf, u, gCoreVocab->RDF_slotsHere, 0, &size);
while (n < size) {
DBMAs nas = nthdbmas(data, n);
RDF_Resource s;
s = RDF_GetResource(NULL, (char*)dataOfDBMAs(nas), 1);
DBM_PutSlotValue(rdf, u, s, 0, NULL, 0);
n = dbmasSize(nas) + n;
}
DBM_PutSlotValue(rdf, u, gCoreVocab->RDF_name, 0, NULL, 0) ;
DBM_PutSlotValue(rdf, u, gCoreVocab->RDF_parent, 1, NULL, 0) ;
DBM_PutSlotValue(rdf, u, gCoreVocab->RDF_parent, 0, NULL, 0) ;
data = DBM_GetSlotValue(rdf, u, gCoreVocab->RDF_slotsIn, 0, &size);
while (n < size) {
DBMAs nas = nthdbmas(data, n);
RDF_Resource s;
s = RDF_GetResource(NULL, (char*)dataOfDBMAs(nas), 1);
DBM_PutSlotValue(rdf, u, s, 1, NULL, 0);
n = dbmasSize(nas) + n;
}
}
PRBool
nlocalStoreAddChildAt(RDFT rdf, RDF_Resource parent, RDF_Resource ref,
RDF_Resource new, PRBool beforep)
{
size_t size ;
DBMAs* data;
char* ndata;
RDF_Resource s = gCoreVocab->RDF_parent;
DBMAs temp;
uint16 n = 0;
size_t tsize;
PRBool ans = 0;
DBMAs nas;
data = DBM_GetSlotValue(rdf, parent, s, 1, &size);
if (!data) return 0;
while (n < size) {
nas = nthdbmas(data, n);
if (valueEqual(RDF_RESOURCE_TYPE, dataOfDBMAs(nas), ref)) {
ans = 1;
if (!beforep) {
n = dbmasSize(nas) + n;
}
break;
}
n = dbmasSize(nas) + n;
}
if (!ans) {
freeMem(data);
return 0;
} else {
char* dx = (char*)data;
temp = makeAsBlock(new, RDF_RESOURCE_TYPE, 1, &tsize);
ndata = (char*)getMem(size + tsize);
if ((temp == NULL) || (ndata == NULL)) {freeMem(data);freeMem(temp);freeMem(ndata);return 1;}
memcpy(ndata, dx, n);
memcpy(&ndata[n], (char*)temp, tsize);
memcpy(&ndata[n+tsize], &dx[n], size-n);
DBM_PutSlotValue(rdf, parent, s, 1, ndata, size+tsize);
freeMem(data);
freeMem(ndata);
freeMem(temp);
}
temp = makeAsBlock(parent, RDF_RESOURCE_TYPE, 1, &tsize);
if (temp == NULL) return 0;
data = DBM_GetSlotValue(rdf, new, s, 0, &size);
if (data == NULL) {
DBM_PutSlotValue(rdf, new, s, 0, (void*) temp, tsize);
} else {
ndata = (char*)getMem(size + tsize);
if (ndata == NULL) {freeMem(data);freeMem(temp);return 0;}
memcpy(ndata, data, size);
memcpy(&ndata[size], (char*)temp, tsize);
DBM_PutSlotValue(rdf, (RDF_Resource)new, s, 0, ndata, size+tsize);
freeMem(data);
freeMem(ndata);
freeMem(temp);
}
sendNotifications2(rdf, RDF_INSERT_NOTIFY, new, s, parent, RDF_RESOURCE_TYPE, 1);
return 1;
}
RDF_Cursor
nlcStoreArcsIn (RDFT rdf, RDF_Resource u)
{
RDF_Cursor c = (RDF_Cursor) getMem(sizeof(struct RDF_CursorStruct));
c->u = u;
c->queryType = RDF_ARC_LABELS_IN_QUERY;
c->inversep = 1;
c->count = 0;
return c;
}
RDF_Cursor
nlcStoreArcsOut (RDFT rdf, RDF_Resource u)
{
RDF_Cursor c = (RDF_Cursor) getMem(sizeof(struct RDF_CursorStruct));
c->u = u;
c->queryType = RDF_ARC_LABELS_OUT_QUERY;
c->count = 0;
return c;
}
RDF_Resource
nlcStoreArcsInOutNextValue (RDFT rdf, RDF_Cursor c)
{
while (c->count < (int16) gCoreVocabSize) {
RDF_Resource s = *(gAllVocab + c->count);
size_t size;
void* data = DBM_GetSlotValue(rdf, c->u, s, c->inversep, &size);
c->count++;
if (data) {
freeMem(data);
return s;
} else {
freeMem(data);
}
}
return NULL;
}
/*
RDFT
MakeLocalStore (char* url)
{
if (startsWith(url, "rdf:localStore") && (gLocalStore)) {
return gLocalStore;
} else if (startsWith(url, "rdf:ops") && (gOPSStore)) {
return gOPSStore;
} else if (startsWith(url, "rdf:ops") || startsWith(url, "rdf:localStore")) {
RDFT ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct));
DBMRDF db = (DBMRDF)getMem(sizeof(struct _DBMRDFStruct));
CHECK_VAR(ntr, NULL);
CHECK_VAR(db, NULL);
if (startsWith(url, "rdf:localStore")) {
gLocalStore = ntr;
} else {
gOPSStore = ntr;
}
ntr->url = copyString(url);
ntr->assert = nlocalStoreAssert;
ntr->unassert = nlocalStoreUnassert;
ntr->getSlotValue = nlocalStoreGetSlotValue;
ntr->getSlotValues = nlocalStoreGetSlotValues;
ntr->hasAssertion = nlocalStoreHasAssertion;
ntr->nextValue = nlocalStoreNextValue;
ntr->disposeCursor = nlocalStoreDisposeCursor;
ntr->destroy = DBM_CloseRDFDBMStore;
ntr->arcLabelsIn = nlcStoreArcsIn;
ntr->arcLabelsOut = nlcStoreArcsOut;
ntr->pdata = db;
DBM_OpenDBMStore(db, (startsWith(url, "rdf:localStore") ? "NavCen" : &url[4]));
nlocalStoreAssert(ntr, gNavCenter->RDF_BookmarkFolderCategory, gCoreVocab->RDF_name,
copyString("Bookmarks"), RDF_STRING_TYPE, 1);
return ntr;
}
else return NULL;
} */

View File

@@ -0,0 +1,122 @@
/* -*- 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_NLCSTORE_H_
#define _RDF_NLCSTORE_H_
#include "rdf-int.h"
#include "rdf.h"
#include "mcom_ndbm.h"
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
#error Must have a byte order
#endif
#ifdef IS_LITTLE_ENDIAN
#define COPY_INT16(_a,_b) XP_MEMCPY(_a, _b, sizeof(uint16));
#else
#define COPY_INT16(_a,_b) \
do { \
((char *)(_a))[0] = ((char *)(_b))[1]; \
((char *)(_a))[1] = ((char *)(_b))[0]; \
} while(0)
#endif
#if !defined(XP_MAC) && !defined(COPY_INT16)
#define COPY_INT16(_a,_b) XP_MEMCPY(_a, _b, sizeof(int16));
#endif
/* nlcstore.c data structures and defines */
#ifdef XP_MAC
#pragma options align=packed
#endif
typedef struct _DBMAsStruct {
uint8 size[3];
uint8 tag;
uint8 data[1]; /* me & the compiler man, we're like _this_ */
} DBMAsStruct;
typedef DBMAsStruct* DBMAs;
#ifdef XP_MAC
#pragma options align=reset
#endif
typedef struct _DBMRDFStruct {
DB *propDB;
DB *invPropDB;
DB *nameDB;
DB *childrenDB;
} *DBMRDF;
#define dataOfDBMAs(dbmas) (((char *)dbmas) + 4)
#define dbmasSize(dbmas) ((size_t)(((1 << 16) * dbmas->size[0]) + ((1 << 8) * dbmas->size[1]) + dbmas->size[2]))
#define nthdbmas(data, n) ((DBMAs)(((char *)data) + n))
#define valueTypeOfAs(nas) (RDF_ValueType) ((*(((uint8 *)(nas)) + 3)) & 0x0F)
#define tvOfAs(nas) ((PRBool)(((*((uint8 *)(nas) + 3)) & 0x10) != 0))
#define valueEqual(type, v1, v2) (((type == RDF_RESOURCE_TYPE) && stringEquals((char*)v1, resourceID((RDF_Resource)v2))) || \
((type == RDF_INT_TYPE) && (compareUnalignedUINT32Ptrs(v1,v2))) || \
((type == RDF_STRING_TYPE) && stringEquals((char*)v1, (char*)v2)))
/* nlcstore.c function prototypes */
NSPR_BEGIN_EXTERN_C
PRBool compareUnalignedUINT32Ptrs(void *v1, void *v2);
char * makeRDFDBURL(char* directory, char* name);
void readInBookmarksOnInit(RDFFile f);
void DBM_OpenDBMStore (DBMRDF store, char* directory);
RDF_Error DBM_CloseRDFDBMStore (RDFT r);
char * makeUSKey (RDF_Resource u, RDF_Resource s, PRBool inversep, size_t *size);
DB * getUSDB (RDFT r, RDF_Resource u, RDF_Resource s, PRBool inversep);
void freeKey (char* keyData, RDF_Resource u, RDF_Resource s, PRBool inversep);
DBMAs * DBM_GetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep, size_t *size);
void DBM_PutSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep, void* value, size_t size);
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 rdf, RDF_Cursor c);
RDF_Error nlocalStoreDisposeCursor (RDFT rdf, RDF_Cursor c);
DBMAs makeAsBlock (void* v, RDF_ValueType type, PRBool tv, size_t *size);
PRBool nlocalStoreAssert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool nlocalStoreAssert1 (RDFFile f, RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool nlocalStoreUnassert (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
void addSlotsHere (RDFT rdf, RDF_Resource u, RDF_Resource s);
void deleteSlotsHere (RDFT rdf, RDF_Resource u, RDF_Resource s);
void addSlotsIn (RDFT rdf, RDF_Resource u, RDF_Resource s);
void deleteSlotsIn (RDFT rdf, RDF_Resource u, RDF_Resource s);
void nlclStoreKill (RDFT rdf, RDF_Resource u);
PRBool nlocalStoreAddChildAt(RDFT rdf, RDF_Resource parent, RDF_Resource ref, RDF_Resource new, PRBool beforep);
RDF_Cursor nlcStoreArcsIn (RDFT rdf, RDF_Resource u);
RDF_Cursor nlcStoreArcsOut (RDFT rdf, RDF_Resource u);
RDF_Resource nlcStoreArcsInOutNextValue (RDFT rdf, RDF_Cursor c);
RDFT MakeLocalStore (char* url);
RDF_Resource nlcStoreArcsInOutNextValue (RDFT rdf, RDF_Cursor c) ;
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,563 @@
/* -*- 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 mail 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
*/
#ifdef SMART_MAIL
#include "pm2rdf.h"
extern char *profileDirURL;
void
Pop_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx)
{
}
void
GetPopToRDF (RDFT rdf)
{
MF folder = (MF) rdf->pdata;
if (endsWith("/inbox", rdf->url)) {
char* popurl = getMem(100);
int n = 10;
int l = RDF_STRLEN(rdf->url);
URL_Struct *urls ;
memcpy(popurl, "pop3://", 7);
while (n < l) {
if (rdf->url[n] == '/') break;
popurl[n-3] = rdf->url[n];
n++;
}
urls = NET_CreateURLStruct(popurl, NET_DONT_RELOAD);
if (urls != NULL) {
urls->fe_data = rdf;
NET_GetURL(urls, FO_PRESENT, gRDFMWContext(rdf), Pop_GetUrlExitFunc);
}
}
}
void
PopGetNewMail (RDF_Resource r)
{
if (containerp(r) && (resourceType(r) == PM_RT)) {
MF folder = (MF) r->pdata;
GetPopToRDF(folder->rdf);
}
}
char *
stripCopy (char* str)
{
return copyString(XP_StripLine(str));
}
PRBool
msgDeletedp (MM msg)
{
return (msg && (msg->flags) && (msg->flags[4] == '8'));
}
FILE *
openPMFile (char* path)
{
FILE* ans = fopen(path, "r+");
if (!ans) {
ans = fopen(path, "w");
if (ans) fclose(ans);
ans = fopen(path, "r+");
}
return ans;
}
void
addMsgToFolder (MF folder, MM msg)
{
if (!folder->tail) {
folder->msg = folder->tail = msg;
} else {
folder->tail->next = msg;
folder->tail = msg;
}
}
void
RDF_StartMessageDelivery (RDFT rdf)
{
MF folder = (MF) rdf->pdata;
MM msg = (MM) getMem(sizeof(struct MailMessage));
char* nurl = getMem(100);
fseek(folder->mfile, 0L, SEEK_END);
fprintf(folder->mfile, "From - \n");
msg->offset = ftell(folder->mfile);
sprintf(nurl, "%s?%i", rdf->url, msg->offset);
msg->r = RDF_GetResource(NULL, nurl, 1);
msg->r->pdata = msg;
msg->flags = getMem(4);
folder->add = msg;
setResourceType(msg->r, PM_RT);
fseek(folder->mfile, 0L, SEEK_END);
fputs("X-Mozilla-Status: 0000\n", folder->mfile);
}
char *
MIW1 (const char* block, int32 len)
{
char* blk = XP_ALLOC(len +1);
int32 n = 0;
int32 m = 0;
PRBool seenp = 0;
PRBool wsendp = 0;
memset(blk, '\0', len);
while (n++ < len) {
char c = block[n];
if ((c == '\r') || (c == '\n')) break;
if (!seenp) {
seenp = (c == ':');
} else {
if (c != ' ') wsendp = 1;
if (wsendp) {
blk[m++] = c;
}
}
}
return blk;
}
void
RDF_AddMessageLine (RDFT rdf, char* block, int32 length)
{
MF folder = (MF) rdf->pdata;
MM msg = folder->add;
char* temp = getMem(length+1);
memcpy(temp, block, length);
if (!msg->from && (startsWith("From:", block))) {
msg->from = MIW1(block, length);
} else if (!msg->subject && (startsWith("Subject:", block))) {
msg->subject = MIW1(block, length);
} else if (!msg->date && (startsWith("Date:", block))) {
msg->date = MIW1(block, length);
}
fseek(folder->mfile, 0L, SEEK_END);
fputs(temp, folder->mfile);
freeMem(temp);
}
#define TON(s) ((s == NULL) ? "" : s)
void writeMsgSum (MF folder, MM msg) {
if (!msg->flags) msg->flags = copyString("0000");
if (msg->summOffset == -1) {
fseek(folder->sfile, 0L, SEEK_END);
msg->summOffset = ftell(folder->sfile);
} else {
fseek(folder->sfile, msg->summOffset, SEEK_SET);
}
fprintf(folder->sfile, "Status: %s\nSOffset: %d\nFrom: %s\nSubject: %s\nDate: %s\nMOffset: %d\n",
msg->flags, ftell(folder->sfile),
TON(msg->from), TON(msg->subject), TON(msg->date), msg->offset );
}
void
RDF_FinishMessageDelivery (RDFT rdf)
{
MF folder = (MF) rdf->pdata;
MM msg = folder->add;
folder->add = NULL;
addMsgToFolder(folder, msg);
setResourceType(msg->r, PM_RT);
fseek(folder->sfile, 0L, SEEK_END);
msg->summOffset = ftell(folder->sfile);
writeMsgSum(folder, msg);
fseek(folder->mfile, 0L, SEEK_END);
fputs("\n", folder->mfile);
sendNotifications2(rdf, RDF_ASSERT_NOTIFY, msg->r, gCoreVocab->RDF_parent, folder->top,
RDF_RESOURCE_TYPE, 1);
}
void
setMessageFlag (RDFT rdf, RDF_Resource r, char* newFlag)
{
MF folder = (MF) rdf->pdata;
MM msg = (MM)r->pdata;
fseek(folder->sfile, msg->summOffset+8, SEEK_SET);
fputs(newFlag, folder->sfile);
freeMem(msg->flags);
msg->flags = copyString(newFlag);
/* need to mark the flag in the message file */
fflush(folder->sfile);
}
#define BUFF_SIZE 50000
RDFT
getBFTranslator (char* url) {
if (startsWith("mailbox://folder/", url)) {
char* temp = getMem(RDF_STRLEN(url));
RDFT ans = NULL;
sprintf(temp, "mailbox://%s", &url[17]);
ans = getTranslator(temp);
freeMem(temp);
return ans;
} else return getTranslator(url);
}
PRBool
MoveMessage (char* to, char* from, MM message) {
RDFT todb = getBFTranslator(to);
RDFT fromdb = getBFTranslator(from);
MF tom = todb->pdata;
MF fom = fromdb->pdata;
RDF_Resource r;
MM newMsg = (MM)getMem(sizeof(struct MailMessage));
char* buffer = getMem(BUFF_SIZE);
if (!buffer) return 0;
setMessageFlag(fromdb, message->r, "0008");
fseek(tom->mfile, 0L, SEEK_END);
fseek(fom->mfile, message->offset, SEEK_SET);
fputs("From -\n", tom->mfile);
sprintf(buffer, "mailbox://%s?%d", &to[17], ftell(tom->mfile));
r = RDF_GetResource(NULL, buffer, 1);
newMsg->subject = copyString(message->subject);
newMsg->from = copyString(message->from);
newMsg->date = copyString(message->date);
newMsg->r = r;
r->pdata = newMsg;
setResourceType(r, PM_RT);
newMsg->summOffset = -1;
newMsg->offset = ftell(tom->mfile);
writeMsgSum(tom, newMsg);
addMsgToFolder (tom, newMsg) ;
fflush(tom->sfile);
while (fgets(buffer, BUFF_SIZE, fom->mfile) && strncmp("From ", buffer, 5)) {
fputs(buffer, tom->mfile);
}
sendNotifications2(todb, RDF_ASSERT_NOTIFY, r, gCoreVocab->RDF_parent, tom->top,
RDF_RESOURCE_TYPE, 1);
sendNotifications2(fromdb, RDF_DELETE_NOTIFY, message->r, gCoreVocab->RDF_parent, fom->top,
RDF_RESOURCE_TYPE, 1);
freeMem(buffer);
return 1;
}
void
readSummaryFile (RDFT rdf)
{
if (startsWith("mailbox://", rdf->url)) {
char* url = rdf->url;
char* folderURL = &url[10];
int32 flen = RDF_STRLEN(profileDirURL) + strlen(folderURL) + 4;
char* fileurl = getMem(flen);
char* nurl = getMem(RDF_STRLEN(url) + 20);
FILE *f;
char* buff = getMem(BUFF_SIZE);
MF folder = (MF) getMem(sizeof(struct MailFolder));
MM msg = NULL;
FILE *mf;
char* aclen;
rdf->pdata = folder;
sprintf(fileurl, "%s%s.ssf", profileDirURL, folderURL);
fileurl = MCDepFileURL(fileurl);
f = openPMFile(fileurl);
sprintf(fileurl, "%s%s", profileDirURL, folderURL);
fileurl = MCDepFileURL(fileurl);
mf = openPMFile(fileurl);
folder->top = RDF_GetResource(NULL, rdf->url, 1);
setResourceType(folder->top, PM_RT);
setContainerp(folder->top, 1);
folder->top->pdata = folder;
folder->rdf = rdf;
folder->sfile = f;
folder->mfile = mf;
while (f && fgets(buff, BUFF_SIZE, f)) {
if (startsWith("Status:", buff)) {
msg = (MM) getMem(sizeof(struct MailMessage));
msg->flags = stripCopy(&buff[8]);
fgets(buff, BUFF_SIZE, f);
sscanf(&buff[9], "%d", &msg->summOffset);
fgets(buff, BUFF_SIZE, f);
msg->from = stripCopy(&buff[6]);
fgets(buff, BUFF_SIZE, f);
msg->subject = stripCopy(&buff[8]);
fgets(buff, BUFF_SIZE, f);
msg->date = stripCopy(&buff[6]);
fgets(buff, BUFF_SIZE, f);
sscanf(&buff[9], "%d", &msg->offset);
sprintf(nurl, "%s?%d", url, msg->offset);
msg->r = RDF_GetResource(NULL, nurl, 1);
msg->r->pdata = msg;
addMsgToFolder (folder, msg) ;
setResourceType(msg->r, PM_RT);
}
}
if (msg == NULL) {
/* either a new mailbox or need to read BMF to recreate */
while (mf && fgets(buff, BUFF_SIZE, mf)) {
if (strncmp("From ", buff, 5) ==0) {
if (msg) writeMsgSum(folder, msg);
msg = (MM) getMem(sizeof(struct MailMessage));
msg->offset = ftell(mf);
msg->summOffset = -1;
sprintf(nurl, "%s?%i", url, msg->offset);
msg->r = RDF_GetResource(NULL, nurl, 1);
msg->r->pdata = msg;
setResourceType(msg->r, PM_RT);
addMsgToFolder (folder, msg) ;
}
if ((!msg->from) && (startsWith("From:", buff))) {
msg->from = stripCopy(&buff[6]);
} else if ((!msg->date) && (startsWith("Date:", buff))) {
msg->date = stripCopy(&buff[6]);
} else if ((!msg->subject) && (startsWith("Subject:", buff))) {
msg->subject = stripCopy(&buff[8]);
} else if ((!msg->flags) && (startsWith("X-Mozilla-Status:", buff))) {
msg->flags = stripCopy(&buff[17]);
}
}
if (msg) writeMsgSum(folder, msg);
if (folder->sfile) fflush(folder->sfile);
}
memset(fileurl, '\0', flen);
memcpy(fileurl, rdf->url, RDF_STRLEN(rdf->url));
aclen = RDF_STRCHR(&fileurl[10], '/');
fileurl[aclen-fileurl] = '\0';
RDF_STRCAT(fileurl, "/trash");
folder->trash = fileurl;
freeMem(buff);
freeMem(nurl);
/* GetPopToRDF(rdf); */
}
}
void *
pmGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,
PRBool inversep, PRBool tv)
{
if ((resourceType(u) == PM_RT) && tv && (!inversep) && (type == RDF_STRING_TYPE) && (u->pdata)) {
MM msg = (MM) u->pdata;
if (s == gNavCenter->from) {
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )msg->from)));
return copyString(msg->from);
} else if (s == gNavCenter->subject) {
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )msg->subject)));
return copyString(msg->subject);
} else if (s == gNavCenter->date) {
return copyString(msg->date);
} else return NULL;
} else return NULL;
}
RDF_Cursor
pmGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type,
PRBool inversep, PRBool tv)
{
if ((resourceType(u) == PM_RT) && tv && (inversep) && (type == RDF_RESOURCE_TYPE)
&& (s == gCoreVocab->RDF_parent)) {
MF folder = (MF)rdf->pdata;
if (folder->top == u) {
RDF_Cursor 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 = folder->msg;
return c;
} else return NULL;
} else return NULL;
}
void *
pmNextValue (RDFT rdf, RDF_Cursor c)
{
MM msg = (MM) c->pdata;
RDF_Resource ans = NULL;
while (msg && msgDeletedp(msg)) {
msg = msg->next;
}
if (msg) {
ans = msg->r;
c->pdata = msg->next;
}
return ans;
}
RDF_Error
pmDisposeCursor (RDFT mcf, RDF_Cursor c)
{
freeMem(c);
return noRDFErr;
}
FILE *
getPopMBox (RDFT db)
{
MF folder = (MF)db->pdata;
return folder->mfile;
}
PRBool
pmHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv)
{
/*this is clearly wrong, but doesn't break anything now ...*/
return 1;
}
PRBool
pmRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type)
{
PR_ASSERT( (RDF_STRING_TYPE != type) || ( IsUTF8String((const char* )v)));
if ((startsWith("mailbox://", rdf->url)) && (resourceType(u) == PM_RT) && (s == gCoreVocab->RDF_parent)
&& (type == RDF_RESOURCE_TYPE)) {
RDF_Resource mbox = (RDF_Resource) v;
if (!(containerp(mbox) && (resourceType(mbox) == PM_RT))) {
return false;
} else {
MF folder = (MF)mbox->pdata;
sendNotifications2(rdf, RDF_DELETE_NOTIFY, u, s, v, type, 1);
MoveMessage(folder->trash, resourceID(mbox), (MM)u->pdata);
return 1;
}
} else return false;
}
RDFT
MakePopDB (char* url)
{
if (startsWith("mailbox://", url)) {
RDFT ntr;
if ((ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct))) != NULL) {
char* fileurl = getMem(100);
PRDir* dir ;
char* aclen;
sprintf(fileurl, "%s%s", profileDirURL, &url[10]);
aclen = RDF_STRCHR(&fileurl[RDF_STRLEN(profileDirURL)+1], '/');
fileurl[aclen-fileurl] = '\0';
dir = OpenDir(fileurl);
if (dir == NULL) {
if ( CallPRMkDirUsingFileURL(fileurl, 00700) > -1) dir = OpenDir(fileurl);
}
freeMem(fileurl);
if (dir) {
PR_CloseDir(dir);
ntr->assert = NULL;
ntr->unassert = pmRemove;
ntr->getSlotValue = pmGetSlotValue;
ntr->getSlotValues = pmGetSlotValues;
ntr->hasAssertion = pmHasAssertion;
ntr->nextValue = pmNextValue;
ntr->disposeCursor = pmDisposeCursor;
ntr->url = copyString(url);
readSummaryFile(ntr);
return ntr;
} else {
freeMem(ntr);
return NULL;
}
}
else return NULL;
} else return NULL;
}
RDFT
MakeMailAccountDB (char* url)
{
if (startsWith("mailaccount://", url)) {
RDFT ntr = NewRemoteStore(url);
char* fileurl = getMem(100);
int32 n = PR_SKIP_BOTH;
PRDirEntry *de;
PRDir* dir ;
RDF_Resource top = RDF_GetResource(NULL, url, 1);
sprintf(fileurl, "%s%s", profileDirURL, &url[14]);
dir = OpenDir(fileurl);
if (dir == NULL) {
if ( CallPRMkDirUsingFileURL(fileurl, 00700) > -1) dir = OpenDir(fileurl);
}
while ((dir != NULL) && ((de = PR_ReadDir(dir, (PRDirFlags)(n++))) != NULL)) {
if ((!endsWith(".ssf", de->name)) && (!endsWith(".dat", de->name)) &&
(!endsWith(".snm", de->name)) && (!endsWith("~", de->name))) {
RDF_Resource r;
sprintf(fileurl, "mailbox://folder/%s/%s", &url[14], de->name);
r = RDF_GetResource(NULL, fileurl, 1);
setResourceType(r, PMF_RT);
remoteStoreAdd(ntr, r, gCoreVocab->RDF_parent, top, RDF_RESOURCE_TYPE, 1);
remoteStoreAdd(ntr, r, gCoreVocab->RDF_name, copyString(de->name), RDF_STRING_TYPE, 1);
}
}
freeMem(fileurl);
if (dir) PR_CloseDir(dir);
return ntr;
} else return NULL;
}
#endif

View File

@@ -0,0 +1,101 @@
/* -*- 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_PM2RDF_H_
#define _RDF_PM2RDF_H_
#include "net.h"
#include "rdf.h"
#include "rdf-int.h"
#include "prio.h"
#include "glue.h"
#include "utils.h"
#include "xp_str.h"
#include <stdio.h>
/* pm2rdf.c data structures and defines */
#define TON(s) ((s == NULL) ? "" : s)
#define pmUnitp(u) ((resourceType(u) == PM_RT) || (resourceType(u) == IM_RT))
struct MailFolder {
FILE *sfile;
FILE *mfile;
struct MailMessage* msg;
struct MailMessage* tail;
struct MailMessage* add;
RDF_Resource top;
int32 status;
RDFT rdf;
char* trash;
};
typedef struct MailFolder* MF;
struct MailMessage {
char* subject;
char* from;
char* date;
int32 offset;
char* flags;
int32 summOffset;
RDF_Resource r;
struct MailMessage *next;
};
typedef struct MailMessage* MM;
/* pm2rdf.c function prototypes */
NSPR_BEGIN_EXTERN_C
void Pop_GetUrlExitFunc (URL_Struct *urls, int status, MWContext *cx);
void GetPopToRDF (RDFT rdf);
void PopGetNewMail (RDF_Resource r);
char * stripCopy (char* str);
PRBool msgDeletedp (MM msg);
FILE * openPMFile (char* path);
void addMsgToFolder (MF folder, MM msg);
void RDF_StartMessageDelivery (RDFT rdf);
char * MIW1 (const char* block, int32 len);
void RDF_AddMessageLine (RDFT rdf, char* block, int32 length);
void writeMsgSum (MF folder, MM msg);
void RDF_FinishMessageDelivery (RDFT rdf);
void setMessageFlag (RDFT rdf, RDF_Resource r, char* newFlag);
PRBool MoveMessage (char* to, char* from, MM message);
void readSummaryFile (RDFT rdf);
void * pmGetSlotValue (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor pmGetSlotValues (RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * pmNextValue (RDFT rdf, RDF_Cursor c);
RDF_Error pmDisposeCursor (RDFT mcf, RDF_Cursor c);
FILE * getPopMBox (RDFT db);
PRBool pmHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool pmRemove (RDFT rdf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
RDFT MakePopDB (char* url);
RDFT MakeMailAccountDB (char* url);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,432 @@
/* -*- 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.
*/
/* qryparse.c
A parser for queries expressed in RDF syntax.
There is a query tag (RDF:Query) which encloses one or more literal tags.
It has an id (which is currently ignored).
Literal tags (RDF:Literal) are like assertions, except they may contain variables.
Variables are specified as hrefs, the first character of which is $.
The format of a literal whose range is a resource type is:
<RDF:Literal href=domain>
<property href=range>
</RDF:Literal>
a literal whose range is a string or int is expressed as:
<RDF:Literal href=domain>
<property>string-or-int-value</property>
</RDF:Literal>
Note: in order for the query engine to correctly retrieve property values
which are strings or ints, you must add assertions about the
property's range (otherwise it is assumed to be a resource).
The range property may be the resource named "String", "Int", or any
other resource.
For example:
<RDF:Resource id="motto">
<domain href="State.mcf"/>
<range href="String"/>
</RDF:Resource>
Here is an example of a query:
<RDF:Query id="query1">
<result href="$result"/>
<RDF:Literal href="$var1">
<typeof href="Country.mcf"/>
</RDF:Literal>
<RDF:Literal href="$var1">
<state href="$var2"/>
</RDF:Literal>
<RDF:Literal href="$var2">
<capitalCity href="$result"/>
</RDF:Literal>
</RDF:Query>
In the Prolog-like syntax this looks like:
typeof($var1, Country) & state($var1, $var2) & capitalCity($var2, $result)
*/
#include "query.h"
#include "rdf-int.h"
#define QUERY_TAG "RDF:Query"
#define LITERAL_TAG "RDF:Literal"
#define RESULT_TAG "RDF:result"
#define SEQ_TAG "RDF:seq"
#define SEQ_END_TAG "</RDF:seq>"
#define LI_TAG "RDF:li"
#define RDF_OBJECT 10 /* status */
#define RDF_PROPERTY 11 /* status */
#define RDF_SEQ 12
#define RDF_LI 13
#define RDF_PARSE_ERROR 5 /* this should go in rdf.h */
/* analogous to RDFFile */
typedef struct _QueryParseStruct {
uint16 status; /* whether we're parsing an object or property */
PRBool tv; /* truth value of current literal */
uint16 depth;
RDF rdf;
RDF_Query query;
RDFElement elf;
TermStruc stack[16];
TermStruc* value;
uint8 valueCount;
uint8 valueSize;
} QueryParseStruct;
extern void parseRDFElement(RDFElement elf, char* token);
extern char* getElfProp(char* prop, RDFElement elf);
extern PRBool variableTermp(TermStruc term);
extern PRBool resourceTermp(TermStruc term);
extern PRBool constantTermp(TermStruc term);
/* prototypes */
PRBool variablep(char* elf);
RDF_ValueType rangeType(RDF rdf, RDF_Resource prop);
RDF_Error parseNextQueryToken (QueryParseStruct *q, char* token);
RDF_Query parseQuery(RDF rdf, char* blob, int32 size);
RDF_Error parsePropertyValue(QueryParseStruct *q, char* token);
RDF_Error parseEndTag(QueryParseStruct *q, char* token);
RDF_Error parseTag (QueryParseStruct *q, char* token);
RDF_Error addValueToList(QueryParseStruct *q, void* value, RDF_TermType type);
TermStruc* copyTermList(TermStruc* list, uint8 count);
PRBool variablep(char* elf) {
return elf[0] == '$';
}
/* Returns the ValueType of the range of the property specified */
RDF_ValueType rangeType(RDF rdf, RDF_Resource prop) {
RDF_Resource rangeType;
if (prop == gCoreVocab->RDF_substring) return RDF_STRING_TYPE;
else if (prop == gCoreVocab->RDF_notSubstring) return RDF_STRING_TYPE;
else if (prop == gCoreVocab->RDF_stringEquals) return RDF_STRING_TYPE;
else if (prop == gCoreVocab->RDF_notStringEquals) return RDF_STRING_TYPE;
else if (prop == gCoreVocab->RDF_lessThan) return RDF_INT_TYPE;
else if (prop == gCoreVocab->RDF_greaterThan) return RDF_INT_TYPE;
else if (prop == gCoreVocab->RDF_lessThanOrEqual) return RDF_INT_TYPE;
else if (prop == gCoreVocab->RDF_greaterThanOrEqual) return RDF_INT_TYPE;
else if (prop == gCoreVocab->RDF_equals) return RDF_INT_TYPE;
else if (prop == gCoreVocab->RDF_notEquals) return RDF_INT_TYPE;
/* fix me - add RDF_stringEquals */
rangeType = RDF_GetSlotValue(rdf, prop, gCoreVocab->RDF_range, RDF_RESOURCE_TYPE, false, true);
if (rangeType == NULL) return RDF_RESOURCE_TYPE; /* don't know so assume resource */
else if (rangeType == gCoreVocab->RDF_StringType) return RDF_STRING_TYPE;
else if (rangeType == gCoreVocab->RDF_IntType) return RDF_INT_TYPE;
else return RDF_RESOURCE_TYPE; /* not string or int so must be a resource */
}
/* Returns query parsed from blob, NULL if there was a parsing error.
This is adapted from parseNextRDFXMLBlob, the main differences being that
a file structure is not maintained. blob must contain the entire query.
*/
RDF_Query parseQuery(RDF rdf, char* blob, int32 size) {
RDF_Error err = noRDFErr;
QueryParseStruct q;
char line[LINE_SIZE];
char holdOver[LINE_SIZE];
int32 n, last, m;
PRBool somethingseenp = false;
n = last = 0;
q.depth = 0;
q.elf = (RDFElement)getMem(sizeof(RDFElementStruct));
q.rdf = rdf;
q.query = RDF_CreateQuery(rdf);
q.tv = true;
q.value = NULL;
q.valueCount = 0;
q.valueSize = 0;
memset(holdOver, '\0', LINE_SIZE);
while (n < size) {
char c = blob[n];
m = 0;
somethingseenp = false;
memset(line, '\0', LINE_SIZE);
if (holdOver[0] != '\0') {
memcpy(line, holdOver, RDF_STRLEN(holdOver));
m = RDF_STRLEN(holdOver);
somethingseenp = true;
memset(holdOver, '\0', LINE_SIZE);
}
while ((m < 300) && (c != '<') && (c != '>')) {
line[m] = c;
m++;
somethingseenp = (somethingseenp || ((c != ' ') && (c != '\r') && (c != '\n')));
n++;
if (n < size) c = blob[n];
else break;
}
if (c == '>') line[m] = c;
n++;
if (m > 0) {
if ((c == '<') || (c == '>')) {
last = n;
if (c == '<') holdOver[0] = '<';
if (somethingseenp == true) {
err = parseNextQueryToken(&q, line);
if (err != noRDFErr) {
if (q.query != NULL) RDF_DestroyQuery(q.query);
q.query = NULL;
break; /* while (n < size) */
}
}
} else if (size > last) {
memcpy(holdOver, line, m);
}
} else if (c == '<') holdOver[0] = '<';
}
if (q.elf != NULL) freeMem(q.elf);
return q.query;
}
RDF_Error addValueToList(QueryParseStruct *q, void* value, RDF_TermType type) {
RDF_Error err = noRDFErr;
int increment = 5;
if (q->valueSize == q->valueCount) {
TermStruc* old = q->value;
TermStruc* newTermList = (TermStruc*)getMem((q->valueSize + increment) * sizeof(TermStruc));
if (newTermList == NULL) return RDF_NO_MEMORY;
memcpy((char*)newTermList, (char*)q->value, (q->valueSize)* sizeof(TermStruc));
q->value = newTermList;
q->valueSize = q->valueSize + increment;
freeMem(old);
}
(q->value + q->valueCount)->value = value;
(q->value + q->valueCount)->type = type;
q->valueCount++;
return err;
}
TermStruc* copyTermList(TermStruc* list, uint8 count) {
TermStruc* newList = (TermStruc*)getMem(count * sizeof(TermStruc));
if (newList == NULL) return NULL;
memcpy((char*)newList, (char*)list, count * sizeof(TermStruc));
return newList;
}
RDF_Error parsePropertyValue(QueryParseStruct *q, char* token) {
RDF_Error err = noRDFErr;
if ((q->depth == 3) && (q->status == RDF_PROPERTY)) {
/* parse the property value */
RDF_Resource slot = (RDF_Resource)q->stack[q->depth-1].value;
RDF_ValueType type = rangeType(q->rdf, slot);
TermStruc unitTerm = q->stack[q->depth-2];
switch (type) { /* switch on value type of property */
int i;
case RDF_RESOURCE_TYPE:
err = RDF_PARSE_ERROR;
break;
case RDF_STRING_TYPE:
if (variablep(token)) {
RDF_Variable rangeVar = RDF_GetVariable(q->query, token);
if (variableTermp(unitTerm))
err = RDF_AddConjunctVRV(q->query, (RDF_Variable)unitTerm.value, slot, rangeVar, type);
else err = RDF_AddConjunctRRV(q->query, (RDF_Resource)unitTerm.value, slot, rangeVar, type);
} else if (variableTermp(unitTerm)) {
err = RDF_AddConjunctVRO(q->query, (RDF_Variable)unitTerm.value, slot, (void*)token, type);
} else err = RDF_AddConjunctRRO(q->query, (RDF_Resource)unitTerm.value, slot, (void*)token, type);
break;
case RDF_INT_TYPE:
if (variablep(token)) {
RDF_Variable rangeVar = RDF_GetVariable(q->query, token);
if (variableTermp(unitTerm))
err = RDF_AddConjunctVRV(q->query, (RDF_Variable)unitTerm.value, slot, rangeVar, type);
else err = RDF_AddConjunctRRV(q->query, (RDF_Resource)unitTerm.value, slot, rangeVar, type);
} else if (sscanf(token, "%d", &i) == 1) { /* fix me */
if (variableTermp(unitTerm)) {
err = RDF_AddConjunctVRO(q->query, (RDF_Variable)unitTerm.value, slot, (void*)i, type);
} else err = RDF_AddConjunctRRO(q->query, (RDF_Resource)unitTerm.value, slot, (void*)i, type);
} else err = RDF_PARSE_ERROR;
break;
default:
err = RDF_PARSE_ERROR; /* should never get here */
break;
}
} else if (q->status == RDF_LI) {
RDF_Resource slot = (RDF_Resource)q->stack[q->depth-3].value;
RDF_ValueType type = rangeType(q->rdf, slot);
switch (type) {
int i;
case RDF_RESOURCE_TYPE:
err = RDF_PARSE_ERROR;
break;
case RDF_STRING_TYPE:
if (variablep(token))
err = addValueToList(q, RDF_GetVariable(q->query, token), RDF_VARIABLE_TERM_TYPE);
else err = addValueToList(q, copyString(token), RDF_CONSTANT_TERM_TYPE);
break;
case RDF_INT_TYPE:
if (variablep(token)) {
err = addValueToList(q, RDF_GetVariable(q->query, token), RDF_VARIABLE_TERM_TYPE);
} else if (sscanf(token, "%d", &i) == 1) { /* fix me */
err = addValueToList(q, (void*)i, RDF_CONSTANT_TERM_TYPE);
} else err = RDF_PARSE_ERROR;
break;
default:
err = RDF_PARSE_ERROR; /* should never get here */
break;
}
}
return err;
}
RDF_Error parseTag (QueryParseStruct *q, char* token) {
RDF_Error err = noRDFErr;
RDFElement elf = q->elf;
memset((char*)elf, '\0', sizeof(RDFElementStruct));
parseRDFElement(elf, token);
/* the block can start with Query, Literal or a property name */
if (startsWith(QUERY_TAG, elf->tagName)) {
char* url = getElfProp("id", elf);
/* don't have anything to do with id right now */
q->stack[q->depth++].value = (void*)NULL;
q->status = RDF_OBJECT;
} else if (startsWith(LITERAL_TAG, elf->tagName)) {
char* domain = getElfProp("href", elf);
if (variablep(domain)) {
q->stack[q->depth].value = RDF_GetVariable(q->query, domain);
q->stack[q->depth].type = RDF_VARIABLE_TERM_TYPE;
q->depth++;
} else {
q->stack[q->depth].value = resourceFromID(domain, true);
q->stack[q->depth].type = RDF_RESOURCE_TERM_TYPE;
q->depth++;
}
q->status = RDF_OBJECT;
/*
if (stringEquals(LITERAL_NEGATION_TAG, elf->tagName))
q->tv = false;
else q->tv = true;
*/
} else if (stringEquals(elf->tagName, RESULT_TAG) && (q->depth == 1)) {
/* set a result variable */
char* range = getElfProp("href", elf);
RDF_Variable resultVar = RDF_GetVariable(q->query, range);
RDF_SetResultVariable(resultVar, true);
q->status = RDF_OBJECT;
} else if (stringEquals(elf->tagName, SEQ_TAG) && (q->depth == 3)) {
/* ignore stack value */
q->depth++;
q->status = RDF_SEQ;
q->valueSize = 10;
q->valueCount = 0;
q->value = (TermStruc*)getMem(q->valueSize * sizeof(TermStruc));
if (q->value == NULL) err = RDF_PARSE_ERROR;
} else if (stringEquals(elf->tagName, LI_TAG) && (q->depth == 4)) {
/* ignore stack value */
if (elf->emptyTagp) { /* <RDF:li href="$var"/> */
char* range = getElfProp("href", elf);
RDF_Resource slot = (RDF_Resource)q->stack[q->depth-2].value;
RDF_ValueType type = rangeType(q->rdf, slot);
if (type == RDF_RESOURCE_TYPE) {
if (variablep(range)) {
err = addValueToList(q, RDF_GetVariable(q->query, range), RDF_VARIABLE_TERM_TYPE);
} else err = addValueToList(q, resourceFromID(range, true), RDF_RESOURCE_TERM_TYPE);
} else err = RDF_PARSE_ERROR;
} else { /* <RDF:li> */
q->depth++;
q->status = RDF_LI;
}
} else if (q->depth != 1) { /* property */
char* pname = elf->tagName;
RDF_Resource slot = resourceFromID(pname, true);
if (elf->emptyTagp) {
char* range = getElfProp("href", elf);
RDF_ValueType type = rangeType(q->rdf, slot);
TermStruc unitTerm = q->stack[q->depth-1];
switch (type) { /* switch on value type of property */
case RDF_RESOURCE_TYPE:
if (variablep(range)) {
RDF_Variable rangeVar = RDF_GetVariable(q->query, range);
if (variableTermp(unitTerm)) {
err = RDF_AddConjunctVRV(q->query, (RDF_Variable)unitTerm.value, slot, rangeVar, type);
} else {
err = RDF_AddConjunctRRV(q->query, (RDF_Resource)unitTerm.value, slot, rangeVar, type);
}
} else {
RDF_Resource rangeRsrc = resourceFromID(range, true);
if (variableTermp(unitTerm)) {
/* RDF_AddConjunctVRR */
err = RDF_AddConjunctVRR(q->query, (RDF_Variable)unitTerm.value, slot, rangeRsrc);
} else err = RDF_PARSE_ERROR;
}
break;
default:
err = RDF_PARSE_ERROR; /* strings and ints cannot be inside href */
break;
}
q->status = RDF_OBJECT;
} else {
/* this isn't really a term, its just a property but we access it in the same way as a term */
q->stack[q->depth].value = slot;
q->stack[q->depth].type = RDF_RESOURCE_TERM_TYPE;
q->depth++;
q->status = RDF_PROPERTY;
}
}
return err;
}
RDF_Error parseEndTag(QueryParseStruct *q, char* token) {
RDF_Error err = noRDFErr;
if (stringEquals(SEQ_END_TAG, token)) {
RDF_Resource slot = (RDF_Resource)q->stack[q->depth-2].value;
RDF_ValueType type = rangeType(q->rdf, slot);
TermStruc unitTerm = q->stack[q->depth-3];
/* copy the value list, add the conjunct, and destroy the list - the engine destroys the copy. */
TermStruc* copy = copyTermList(q->value, q->valueCount);
if (copy == NULL) return RDF_NO_MEMORY;
err = RDF_AddConjunctVRL(q->query, (RDF_Variable)unitTerm.value, slot, (RDF_Term)copy, type, q->valueCount);
q->valueCount = q->valueSize = 0;
freeMem(q->value);
}
if (q->depth == 0) return RDF_PARSE_ERROR;
q->depth--;
if (q->status == RDF_OBJECT)
q->status = RDF_PROPERTY;
else if (q->status == RDF_LI)
q->status = RDF_SEQ;
else if (q->status == RDF_SEQ)
q->status = RDF_OBJECT; /* also terminates the property */
return err;
}
/* this is adapted from parseNextRDFToken, the difference being in the actions. */
RDF_Error parseNextQueryToken (QueryParseStruct *q, char* token) {
RDF_Error err = noRDFErr;
if (token[0] == '\n' || token[0] == '\r') return err;
if (token[0] != '<') {
err = parsePropertyValue(q, token);
} else if (token[1] == '/') {
err = parseEndTag(q, token);
} else {
err = parseTag(q, token);
}
return err;
}

View File

@@ -0,0 +1,651 @@
/* -*- 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 query 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
*/
#ifdef XP_PC
#define strcasecomp RDF_STRCMP
#endif
#include "query.h"
#include "rdf-int.h"
/* prototypes */
PRBool variableTermp(TermStruc term);
PRBool resourceTermp(TermStruc term);
PRBool constantTermp(TermStruc term);
RDF_Error addVariableToList(RDF_Variable variable, RDF_VariableList *list);
void destroyVariableList(RDF_VariableList list, PRBool destroyVariables);
void destroyLiteralList(RDF_LiteralList list, PRBool destroyLiterals);
PRBool comparisonp(RDF_Resource r);
PRBool specialResourcePredicate(RDF_Resource r);
PRBool findLiteral(RDF_Literal target, RDF_LiteralList list);
RDF_Literal getNthLiteral(RDF_Query q, uint16 index);
PRBool constantp(TermStruc term, RDF_VariableList knownVars);
RDF_Literal oneUnknownAs(RDF_Query q, RDF_LiteralList orderedLiterals, RDF_VariableList knownVars);
RDF_Literal noUnknownAs(RDF_Query q, RDF_LiteralList orderedLiterals, RDF_VariableList knownVars);
PRBool orderConjuncts(RDF_Query q);
PRBool processNextLiteral(RDF_Query q, RDF_Literal literal);
void addLiteral(RDF_Query q, RDF_Literal literal);
/* Variable API */
PR_PUBLIC_API(PRBool) RDF_IsResultVariable(RDF_Variable var) {
return var->isResult;
}
PR_PUBLIC_API(void) RDF_SetResultVariable(RDF_Variable var, PRBool isResult) {
var->isResult = isResult;
}
PR_PUBLIC_API(void*) RDF_GetVariableValue(RDF_Variable var) {
if (var->query->queryRunning)
return var->value;
else return NULL;
}
PR_PUBLIC_API(void) RDF_SetVariableValue(RDF_Variable var, void* value, RDF_ValueType type) {
if (!var->query->queryRunning) var->query->conjunctsOrdered = false;
var->value = value;
var->type = type;
}
PRBool variableTermp(TermStruc term) {
return term.type == RDF_VARIABLE_TERM_TYPE;
}
PRBool resourceTermp(TermStruc term) {
return term.type == RDF_RESOURCE_TERM_TYPE;
}
PRBool constantTermp(TermStruc term) {
return term.type == RDF_CONSTANT_TERM_TYPE;
}
/* Adds the variable to the variable list if it isn't already on the list. */
RDF_Error addVariableToList(RDF_Variable variable, RDF_VariableList *list) {
PRBool found = false;
RDF_VariableList current = *list;
while (current != NULL) {
if (current->element == variable) {
found = true;
break;
}
current = current->next;
}
if (!found) {
RDF_VariableList newlist = (RDF_VariableList)getMem(sizeof(RDF_VariableListStruc));
if (newlist == NULL) return RDF_NO_MEMORY;
newlist->element = variable;
newlist->next = *list;
*list = newlist;
}
return noRDFErr;
}
void destroyVariableList(RDF_VariableList list, PRBool destroyVariables) {
if (list != NULL) {
destroyVariableList(list->next, destroyVariables);
if (destroyVariables) freeMem(list->element); /* free the variable */
freeMem(list); /* free the list structure */
}
}
void destroyLiteralList(RDF_LiteralList list, PRBool destroyLiterals) {
if (list != NULL) {
destroyLiteralList(list->next, destroyLiterals);
if (destroyLiterals) {
RDF_Literal literal = list->element;
if (literal->c != NULL) RDF_DisposeCursor(literal->c);
if (literal->valueType == RDF_STRING_TYPE) {
int i;
for (i = 0; i < literal->valueCount; i++) {
TermStruc term = *(literal->v + i);
if (constantTermp(term)) freeMem(term.value);
}
}
freeMem(literal->v);
freeMem(list->element); /* free the literal */
}
freeMem(list); /* free the list structure */
}
}
PRBool comparisonp(RDF_Resource r) {
return (r == gCoreVocab->RDF_substring ||
r == gCoreVocab->RDF_notSubstring ||
r == gCoreVocab->RDF_lessThan ||
r == gCoreVocab->RDF_greaterThan ||
r == gCoreVocab->RDF_lessThanOrEqual ||
r == gCoreVocab->RDF_greaterThanOrEqual ||
r == gCoreVocab->RDF_equals ||
r == gCoreVocab->RDF_notEquals ||
r == gCoreVocab->RDF_stringEquals ||
r == gCoreVocab->RDF_notStringEquals);
}
PRBool specialResourcePredicate(RDF_Resource r) {
return (r == gCoreVocab->RDF_notInstanceOf || r == gCoreVocab->RDF_notParent);
}
/* Creates and initializes a query. Returns NULL if not enough memory. */
PR_PUBLIC_API(RDF_Query) RDF_CreateQuery(RDF rdf) {
RDF_Query q = (RDF_Query)getMem(sizeof(RDF_QueryStruc));
if (q == NULL) return q;
q->variables = NULL;
q->literals = NULL;
q->numLiterals = 0;
q->index = 0;
q->conjunctsOrdered = false;
q->queryRunning = false;
q->rdf = rdf;
return q;
}
/* Destroys a query. */
PR_PUBLIC_API(void) RDF_DestroyQuery(RDF_Query q) {
destroyLiteralList(q->literals, true); /* free the literals */
q->literals = NULL;
destroyVariableList(q->variables, true); /* free the variables */
q->variables = NULL;
freeMem(q); /* free the query */
q = NULL;
}
/* Returns the variable with the given name in the query.
If not found:
if the query is running, return NULL
otherwise create a new variable with the given name.
if there isn't enough memory, return NULL.
*/
PR_PUBLIC_API(RDF_Variable) RDF_GetVariable(RDF_Query q, char* name) {
RDF_Variable newvar;
RDF_VariableList newlist;
RDF_VariableList current = q->variables;
while (current != NULL) {
if (stringEquals(current->element->id, name)) return current->element;
if (current->next == NULL) break;
else current = current->next;
}
if (q->queryRunning) return NULL;
newvar = (RDF_Variable)getMem(sizeof(RDF_VariableStruc));
if (newvar == NULL) return NULL;
newvar->id = copyString(name);
newvar->query = q;
/* create a list containing the variable and append it to the front of the variable list */
newlist = (RDF_VariableList)getMem(sizeof(RDF_VariableListStruc));
if (newlist == NULL) {
freeMem(newvar);
return NULL;
}
newlist->element = newvar;
newlist->next = q->variables;
q->variables = newlist;
return newvar;
}
/* Returns the number of variables in the query. */
PR_PUBLIC_API(uint16) RDF_GetVariableListCount(RDF_Query q) {
RDF_VariableList current = q->variables;
uint16 count = 0;
while (current != NULL) {
current = current->next;
count++;
}
return count;
}
/* Returns the variables belonging to the query at the given index. */
PR_PUBLIC_API(RDF_Variable) RDF_GetNthVariable(RDF_Query q, uint16 index) {
RDF_VariableList current = q->variables;
uint16 count = 0;
while (current != NULL) {
if (count == index)
return current->element;
else {
current = current->next;
count++;
}
}
return NULL;
}
/* Returns true if target is found in literal */
PRBool findLiteral(RDF_Literal target, RDF_LiteralList list) {
while (list != NULL) {
if (list->element == target) return true;
else list = list->next;
}
return false;
}
/* Returns the literal belonging to the query at the given index. */
RDF_Literal getNthLiteral(RDF_Query q, uint16 index) {
RDF_LiteralList current = q->literals;
uint16 count = 0;
while (current != NULL) {
if (count == index)
return current->element;
else {
current = current->next;
count++;
}
}
return NULL;
}
/* A term is constant if it is not a variable, if it is a variable with
a non-null value, or if it is a known variable.
*/
PRBool constantp(TermStruc term, RDF_VariableList knownVars) {
if (term.type != RDF_VARIABLE_TERM_TYPE) return true;
else {
RDF_Variable var = (RDF_Variable)term.value;
if (var->value != NULL) return true;
else {
while (knownVars != NULL) {
if (knownVars->element == var) return true;
knownVars = knownVars->next;
}
return false;
}
}
}
/* Returns a literal with a constant term which has not been ordered yet. */
RDF_Literal oneUnknownAs(RDF_Query q, RDF_LiteralList orderedLiterals, RDF_VariableList knownVars) {
RDF_LiteralList list = q->literals;
RDF_Literal answer = NULL;
while (list != NULL) {
RDF_Literal current = list->element;
if (!findLiteral(current, orderedLiterals)) {
if (((constantp(current->u, knownVars)) || (constantp(*current->v, knownVars))) &&
current->valueCount == 1 && /* no disjunctions */
!comparisonp(current->s) && /* comparisons must have constant terms */
!specialResourcePredicate(current->s) /* notTypeOf and notParent must have constant terms */
/* && current->tv == true */) {
if (answer == NULL) {
answer = current;
} else {
/* fix me - deal with branching factor */
answer = current;
}
}
}
list = list->next;
}
return answer;
}
/* Returns a literal with both terms constant which has not been ordered yet. */
RDF_Literal noUnknownAs(RDF_Query q, RDF_LiteralList orderedLiterals, RDF_VariableList knownVars) {
RDF_LiteralList list = q->literals;
while (list != NULL) {
RDF_Literal current = list->element;
if (!findLiteral(current, orderedLiterals) &&
constantp(current->u, knownVars)) {
int i;
PRBool foundNonConstant = false;
for (i = 0; i < current->valueCount; i++) { /* all values constant? */
TermStruc term = *(current->v + i);
if (!constantp(term, knownVars)) foundNonConstant = true;
}
if (foundNonConstant) list = list->next;
else return current;
}
else list = list->next;
}
return NULL;
}
/* Returns true if the conjuncts were ordered succesfully.
*/
PRBool orderConjuncts(RDF_Query q) {
uint16 numOrdered = 0;
RDF_Error err = noRDFErr;
RDF_LiteralList orderedLiterals = NULL;
RDF_LiteralList orderedLiteralsTail = orderedLiterals;
RDF_VariableList knownVars = NULL;
if (q->conjunctsOrdered) return true;
while (numOrdered < q->numLiterals) {
RDF_Literal lit1 = noUnknownAs(q, orderedLiterals, knownVars);
if (lit1 != NULL) {
/* add literal to ordered list */
RDF_LiteralList newlist = (RDF_LiteralList)getMem(sizeof(RDF_LiteralListStruc));
if (newlist == NULL) break;
newlist->element = lit1;
newlist->next = NULL;
if (orderedLiterals == NULL)
orderedLiterals = orderedLiteralsTail = newlist;
else {
orderedLiteralsTail->next = newlist;
orderedLiteralsTail = orderedLiteralsTail->next;
}
numOrdered++;
} else {
RDF_Literal lit2 = oneUnknownAs(q, orderedLiterals, knownVars);
if (lit2 != NULL) {
RDF_LiteralList newlist = (RDF_LiteralList)getMem(sizeof(RDF_LiteralListStruc));
if (newlist == NULL) break;
/* add unit and value as known variables */
lit2->variable = (RDF_Variable) (constantp(lit2->u, knownVars) ? lit2->v->value : lit2->u.value);
if (variableTermp(lit2->u)) {
err = addVariableToList((RDF_Variable)lit2->u.value, &knownVars);
if (err != noRDFErr) break;
}
if (variableTermp(*lit2->v)) {
err = addVariableToList((RDF_Variable)lit2->v->value, &knownVars);
if (err != noRDFErr) break;
}
/* add literal to ordered list */
newlist->element = lit2;
newlist->next = NULL;
if (orderedLiterals == NULL)
orderedLiterals = orderedLiteralsTail = newlist;
else {
orderedLiteralsTail->next = newlist;
orderedLiteralsTail = orderedLiteralsTail->next;
}
numOrdered++;
} else break;
}
}
if (numOrdered == q->numLiterals) { /* ordered all succesfully so replace literals */
RDF_LiteralList old = q->literals;
q->literals = orderedLiterals;
destroyLiteralList(old, false);
q->conjunctsOrdered = true;
} else { /* unsuccessful so destroy ordered list structure */
destroyLiteralList(orderedLiterals, false);
q->conjunctsOrdered = false;
}
destroyVariableList(knownVars, false); /* free the knownVars list structure */
return q->conjunctsOrdered;
}
PRBool processNextLiteral(RDF_Query q, RDF_Literal literal) {
if (literal->c != NULL) {
RDF_SetVariableValue(literal->variable, RDF_NextValue(literal->c), literal->valueType);
return (RDF_GetVariableValue(literal->variable) != NULL);
} else {
RDF_Resource u; /* unit is a resource except for the comparison case so don't set it yet. */
RDF_Resource s = literal->s;
void* v;
if (literal->variable == NULL) {
PRBool result = false;
PRBool ans = false;
int i;
if (literal->bt) return false;
/* find a value that satisfies predicate */
for (i = 0; i < literal->valueCount; i++) {
TermStruc valueTerm = *(literal->v + i);
if (comparisonp(s)) {
/* unit is a variable in all comparisons.
value may be a variable or a constant.
*/
switch (literal->valueType) {
char *str, *pattern;
int i, j;
case RDF_STRING_TYPE:
if (literal->u.type != RDF_VARIABLE_TERM_TYPE) return false; /* error */
if (((RDF_Variable)literal->u.value)->type != RDF_STRING_TYPE) return false;
str = (char*)RDF_GetVariableValue((RDF_Variable)literal->u.value);
switch (valueTerm.type) {
case RDF_VARIABLE_TERM_TYPE:
pattern = (char*)RDF_GetVariableValue((RDF_Variable)valueTerm.value);
break;
case RDF_CONSTANT_TERM_TYPE:
pattern = (char*)valueTerm.value;
break;
default:
/* should blow up */
return false;
break;
}
if (s == gCoreVocab->RDF_stringEquals) {
ans = stringEquals(pattern, str);
} else if (s == gCoreVocab->RDF_substring) {
ans = substring(pattern, str);
} else if (s == gCoreVocab->RDF_notStringEquals) {
ans = !stringEquals(pattern, str);
} else if (s == gCoreVocab->RDF_notSubstring) {
ans = !substring(pattern, str);
} else return false; /* error */
break;
case RDF_INT_TYPE:
if (literal->u.type != RDF_VARIABLE_TERM_TYPE) return false; /* error */
if (((RDF_Variable)literal->u.value)->type != RDF_INT_TYPE) return false;
i = (int)RDF_GetVariableValue((RDF_Variable)literal->u.value);
switch (valueTerm.type) {
case RDF_VARIABLE_TERM_TYPE:
j = (int)RDF_GetVariableValue((RDF_Variable)valueTerm.value);
break;
case RDF_CONSTANT_TERM_TYPE:
j = (int)valueTerm.value;
break;
default:
/* should blow up */
return false;
break;
}
if (s == gCoreVocab->RDF_equals) {
ans = (i == j);
} else if (s == gCoreVocab->RDF_notEquals) {
ans = (i != j);
} else if (s == gCoreVocab->RDF_lessThan) {
ans = (i < j);
} else if (s == gCoreVocab->RDF_greaterThan) {
ans = (i > j);
} else if (s == gCoreVocab->RDF_lessThanOrEqual) {
ans = (i <= j);
} else if (s == gCoreVocab->RDF_greaterThanOrEqual) {
ans = (i >= j);
} else return false;
break;
default:
return false;
break;
}
}
else {
u = (RDF_Resource)((variableTermp(literal->u)) ? ((RDF_Variable)literal->u.value)->value : literal->u.value);
/* special predicates */
if (s == gCoreVocab->RDF_notInstanceOf) {
ans = !RDF_HasAssertion(q->rdf, u, gCoreVocab->RDF_instanceOf, valueTerm.value, literal->valueType, true);
} else if (s == gCoreVocab->RDF_notParent) {
ans = !RDF_HasAssertion(q->rdf, u, gCoreVocab->RDF_parent, valueTerm.value, literal->valueType, true);
} else ans = RDF_HasAssertion(q->rdf, u, s, valueTerm.value, literal->valueType, true);
}
literal->bt = true;
/* result = ((literal->tv == true) ? ans : !ans); */
result = ans;
if (result) return result; /* otherwise try next value */
}
return result;
}
u = (RDF_Resource)((variableTermp(literal->u)) ? ((RDF_Variable)literal->u.value)->value : literal->u.value);
v = (variableTermp(*literal->v)) ? ((RDF_Variable)literal->v->value)->value : literal->v->value;
if ((u == NULL) && variableTermp(literal->u) && resourceTermp(*literal->v)) {
literal->c = RDF_GetSources(q->rdf, (RDF_Resource)v, s, literal->valueType, true);
if (literal->c == NULL) return false;
RDF_SetVariableValue(literal->variable, RDF_NextValue(literal->c), literal->valueType);
return (RDF_GetVariableValue(literal->variable) != NULL);
} else if ((v == NULL) && variableTermp(*literal->v) && (u != NULL)) {
literal->c = RDF_GetTargets(q->rdf, u, s, literal->valueType, true); /* note arg order differs from java implementation */
if (literal->c == NULL) return false;
RDF_SetVariableValue(literal->variable, RDF_NextValue(literal->c), literal->valueType);
return (RDF_GetVariableValue(literal->variable) != NULL);
} else return false;
}
}
PR_PUBLIC_API(PRBool) RDF_RunQuery (RDF_Query q) {
q->queryRunning = true;
orderConjuncts(q);
if (q->conjunctsOrdered)
return true;
else return false;
}
PR_PUBLIC_API(PRBool) RDF_GetNextElement(RDF_Query q) {
if (!q->queryRunning) RDF_RunQuery(q);
if (q->index == q->numLiterals) q->index--;
while (q->index < q->numLiterals) {
RDF_Literal lit = getNthLiteral(q, q->index); /* we know it's it range so don't have to check for NULL */
if (!processNextLiteral(q, lit)) {
if (q->index == 0) return false;
lit->c = NULL;
if (lit->variable != NULL) RDF_SetVariableValue(lit->variable, (void*)NULL, RDF_RESOURCE_TYPE);
lit->bt = false;
q->index--;
} else {
q->index++;
}
}
return true;
}
PR_PUBLIC_API(void) RDF_EndQuery (RDF_Query q) {
q->queryRunning = false;
}
PR_PUBLIC_API(RDF_VariableList) RDF_GetVariableList(RDF_Query q) {
return q->variables;
}
/* Note: should put a test for overflow of numLiterals */
/* Adds a literal to the query. */
void addLiteral(RDF_Query q, RDF_Literal literal) {
RDF_LiteralList newlist = (RDF_LiteralList)getMem(sizeof(RDF_LiteralListStruc));
if (newlist == NULL) return;
newlist->element = literal;
newlist->next = q->literals;
q->literals = newlist;
q->numLiterals++;
}
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRV(RDF_Query q, RDF_Variable arg1, RDF_Resource s, RDF_Variable arg2, RDF_ValueType type) {
RDF_Literal literal = (RDF_Literal)getMem(sizeof(LiteralStruc));
if (literal == NULL) return RDF_NO_MEMORY;
literal->u.value = (void*)arg1;
literal->u.type = RDF_VARIABLE_TERM_TYPE;
((RDF_Variable)literal->u.value)->type = RDF_RESOURCE_TYPE;
literal->s = s;
literal->valueCount = 1;
literal->v = (TermStruc*)getMem(sizeof(TermStruc));
literal->v->value = (void*)arg2;
literal->v->type = RDF_VARIABLE_TERM_TYPE;
((RDF_Variable)literal->v->value)->type = literal->valueType = type;
literal->tv = true;
addLiteral(q, literal);
q->conjunctsOrdered = false;
return noRDFErr;
}
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRO(RDF_Query q, RDF_Variable arg1, RDF_Resource s, void* arg2, RDF_ValueType type) {
RDF_Literal literal = (RDF_Literal)getMem(sizeof(LiteralStruc));
if (literal == NULL) return RDF_NO_MEMORY;
literal->u.value = (void*)arg1;
literal->u.type = RDF_VARIABLE_TERM_TYPE;
((RDF_Variable)literal->u.value)->type = type;
literal->s = s;
literal->valueCount = 1;
literal->v = (TermStruc*)getMem(sizeof(TermStruc));
literal->v->value = (type == RDF_STRING_TYPE) ? (void*)copyString((char*)arg2) : (void*)arg2;
literal->v->type = RDF_CONSTANT_TERM_TYPE;
literal->valueType = type;
literal->tv = true;
addLiteral(q, literal);
q->conjunctsOrdered = false;
return noRDFErr;
}
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctRRO(RDF_Query q, RDF_Resource arg1, RDF_Resource s, void* arg2, RDF_ValueType type) {
RDF_Literal literal = (RDF_Literal)getMem(sizeof(LiteralStruc));
if (literal == NULL) return RDF_NO_MEMORY;
literal->u.value = (void*)arg1;
literal->u.type = RDF_RESOURCE_TERM_TYPE;
literal->s = s;
literal->valueCount = 1;
literal->v = (TermStruc*)getMem(sizeof(TermStruc));
literal->v->value = (type == RDF_STRING_TYPE) ? (void*)copyString((char*)arg2) : (void*)arg2;
literal->v->type = RDF_CONSTANT_TERM_TYPE;
literal->valueType = type;
literal->tv = true;
addLiteral(q, literal);
q->conjunctsOrdered = false;
return noRDFErr;
}
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRR(RDF_Query q, RDF_Variable arg1, RDF_Resource s, RDF_Resource arg2) {
RDF_Literal literal = (RDF_Literal)getMem(sizeof(LiteralStruc));
if (literal == NULL) return RDF_NO_MEMORY;
literal->u.value = (void*)arg1;
literal->u.type = RDF_VARIABLE_TERM_TYPE;
((RDF_Variable)literal->u.value)->type = RDF_RESOURCE_TYPE;
literal->s = s;
literal->valueCount = 1;
literal->v = (TermStruc*)getMem(sizeof(TermStruc));
literal->v->value = (void*)arg2;
literal->v->type = RDF_RESOURCE_TERM_TYPE;
literal->valueType = RDF_RESOURCE_TYPE;
literal->tv = true;
addLiteral(q, literal);
q->conjunctsOrdered = false;
return noRDFErr;
}
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctRRV(RDF_Query q, RDF_Resource arg1, RDF_Resource s, RDF_Variable arg2, RDF_ValueType type) {
RDF_Literal literal = (RDF_Literal)getMem(sizeof(LiteralStruc));
if (literal == NULL) return RDF_NO_MEMORY;
literal->u.value = arg1;
literal->u.type = RDF_RESOURCE_TERM_TYPE;
literal->s = s;
literal->valueCount = 1;
literal->v = (TermStruc*)getMem(sizeof(TermStruc));
literal->v->value = (void*)arg2;
literal->v->type = RDF_VARIABLE_TERM_TYPE;
((RDF_Variable)literal->v->value)->type = literal->valueType = type;
literal->tv = true;
addLiteral(q, literal);
q->conjunctsOrdered = false;
return noRDFErr;
}
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRL(RDF_Query q, RDF_Variable arg1, RDF_Resource s, RDF_Term arg2, RDF_ValueType type, uint8 count) {
RDF_Literal literal = (RDF_Literal)getMem(sizeof(LiteralStruc));
if (literal == NULL) return RDF_NO_MEMORY;
literal->u.value = (void*)arg1;
literal->u.type = RDF_VARIABLE_TERM_TYPE;
((RDF_Variable)literal->u.value)->type = type;
literal->s = s;
literal->valueCount = count;
literal->v = (void*)arg2;
/* value and type of each term already assigned */
literal->valueType = type;
literal->tv = true;
addLiteral(q, literal);
q->conjunctsOrdered = false;
return noRDFErr;
}

View File

@@ -0,0 +1,113 @@
/* -*- 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 query_h___
#define query_h___
/* the RDF Query API. */
#include "rdf.h"
typedef uint8 RDF_TermType; /* type of a term */
/* values of RDF_TermType */
#define RDF_VARIABLE_TERM_TYPE 1
#define RDF_RESOURCE_TERM_TYPE 2
#define RDF_CONSTANT_TERM_TYPE 3
typedef struct _RDF_VariableStruc {
void* value;
RDF_ValueType type;
char* id;
PRBool isResult;
struct _RDF_QueryStruc* query;
} RDF_VariableStruc;
typedef RDF_VariableStruc* RDF_Variable;
typedef struct _RDF_VariableListStruc {
RDF_Variable element;
struct _RDF_VariableListStruc* next;
} RDF_VariableListStruc;
typedef RDF_VariableListStruc* RDF_VariableList;
PR_PUBLIC_API(PRBool) RDF_IsResultVariable(RDF_Variable var);
PR_PUBLIC_API(void) RDF_SetResultVariable(RDF_Variable var, PRBool isResult);
PR_PUBLIC_API(void*) RDF_GetVariableValue(RDF_Variable var);
PR_PUBLIC_API(void) RDF_SetVariableValue(RDF_Variable var, void* value, RDF_ValueType type);
typedef struct _Term {
void* value;
RDF_TermType type;
} TermStruc;
typedef struct TermStruc* RDF_Term;
typedef struct _LiteralStruc {
TermStruc u;
RDF_Resource s;
TermStruc* v;
uint8 valueCount; /* disjunction */
RDF_Cursor c;
PRBool tv;
PRBool bt;
RDF_Variable variable;
RDF_ValueType valueType;
} LiteralStruc;
typedef LiteralStruc* RDF_Literal;
typedef struct _RDF_LiteralListStruc {
RDF_Literal element;
struct _RDF_LiteralListStruc* next;
} RDF_LiteralListStruc;
typedef RDF_LiteralListStruc* RDF_LiteralList;
typedef struct _RDF_QueryStruc {
struct _RDF_VariableListStruc* variables;
struct _RDF_LiteralListStruc* literals;
uint16 numLiterals;
uint16 index;
PRBool conjunctsOrdered;
PRBool queryRunning;
RDF rdf;
} RDF_QueryStruc;
typedef RDF_QueryStruc* RDF_Query;
/* Note: the API assumes that the query parameter is non-NULL. */
PR_PUBLIC_API(RDF_Query) RDF_CreateQuery(RDF rdf);
PR_PUBLIC_API(void) RDF_DestroyQuery(RDF_Query q);
PR_PUBLIC_API(RDF_Variable) RDF_GetVariable(RDF_Query q, char* name);
PR_PUBLIC_API(PRBool) RDF_RunQuery (RDF_Query q);
PR_PUBLIC_API(PRBool) RDF_GetNextElement(RDF_Query q);
PR_PUBLIC_API(void) RDF_EndQuery (RDF_Query q);
PR_PUBLIC_API(RDF_VariableList) RDF_GetVariableList(RDF_Query q);
PR_PUBLIC_API(uint16) RDF_GetVariableListCount(RDF_Query q);
PR_PUBLIC_API(RDF_Variable) RDF_GetNthVariable(RDF_Query q, uint16 index);
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRV(RDF_Query q, RDF_Variable arg1, RDF_Resource s, RDF_Variable arg2, RDF_ValueType type);
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRO(RDF_Query q, RDF_Variable arg1, RDF_Resource s, void* arg2, RDF_ValueType type);
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctRRO(RDF_Query q, RDF_Resource arg1, RDF_Resource s, void* arg2, RDF_ValueType type);
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRR(RDF_Query q, RDF_Variable arg1, RDF_Resource s, RDF_Resource arg2);
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctRRV(RDF_Query q, RDF_Resource arg1, RDF_Resource s, RDF_Variable arg2, RDF_ValueType type);
PR_PUBLIC_API(RDF_Error) RDF_AddConjunctVRL(RDF_Query q, RDF_Variable arg1, RDF_Resource s, RDF_Term arg2, RDF_ValueType type, uint8 count);
#endif /* query_h___ */

View File

@@ -0,0 +1,451 @@
/* -*- 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) (strcasecomp(x, y) ==0)
/*#define stringAppend(x, y) XP_AppendStr(x,y) */
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);
/* 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 () ;
int parseNextRDFXMLBlobInt(RDFFile f, char* blob, int32 size) ;
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;
#endif

View File

@@ -0,0 +1,177 @@
/* -*- 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 high level 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 "rdf-int.h"
#include "vocab.h"
#include "vocabint.h"
#include "bmk2mcf.h"
#include "mcf.h"
/* globals */
char *profileDirURL = NULL;
char *gLocalStoreURL = NULL;
char *gBookmarkURL = NULL;
char *gGlobalHistoryURL = NULL;
void *timerID = NULL;
char *gRLForbiddenDomains = NULL;
extern RDF gNCDB ;
static PRBool sRDFInitedB = PR_FALSE;
char* gNavCntrUrl;
char * gNavCenterDataSources[15] =
{"rdf:localStore", "rdf:remoteStore", "rdf:bookmarks", "rdf:remoteStore", "rdf:history",
/* "rdf:ldap", */
"rdf:esftp",
"rdf:lfs", "rdf:CookieStore",
"rdf:columns", "rdf:find",
#ifdef XP_MAC
"rdf:appletalk",
#endif
NULL, NULL
};
RDF
newNavCenterDB()
{
return RDF_GetDB((char**)gNavCenterDataSources);
}
void
walkThroughAllBookmarks (RDF_Resource u)
{
#ifdef MOZILLA_CLIENT
RDF_Cursor c = RDF_GetSources(gNCDB, u, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
RDF_Resource next;
while ((next = RDF_NextValue(c)) != NULL) {
if (resourceType(next) == RDF_RT) walkThroughAllBookmarks(next);
}
RDF_DisposeCursor(c);
#endif
}
PR_PUBLIC_API(RDF_Error)
RDF_Init(RDF_InitParams params)
{
#ifdef MOZILLA_CLIENT
char* navCenterURL;
#endif
if ( sRDFInitedB )
return -1;
#ifdef MOZILLA_CLIENT
/*
copy init params out before doing anything else (such as creating vocabulary)
to prevent any XP_GetString round-robin problems (ex: FE could be using XP_GetString
to pass in the init strings, which createVocabs() could affect
*/
profileDirURL = copyString(params->profileURL);
gBookmarkURL = copyString(params->bookmarksURL);
gGlobalHistoryURL = copyString(params->globalHistoryURL);
#endif
resourceHash = PL_NewHashTable(500, PL_HashString, PL_CompareStrings,
PL_CompareValues, NULL, NULL);
dataSourceHash = PL_NewHashTable(100, PL_HashString, PL_CompareStrings,
PL_CompareValues, NULL, NULL);
RDFglueInitialize();
MakeRemoteStore("rdf:remoteStore");
createVocabs();
sRDFInitedB = PR_TRUE;
#ifdef MOZILLA_CLIENT
/* xxx
PREF_SetDefaultCharPref("browser.NavCenter", "http://rdf.netscape.com/rdf/navcntr.rdf");
PREF_CopyCharPref("browser.NavCenter", &navCenterURL);
*/
navCenterURL = copyString("http://rdf.netscape.com/rdf/navcntr.rdf");
if (!RDF_STRCHR(navCenterURL, ':')) {
navCenterURL = makeDBURL(navCenterURL);
}
gNavCntrUrl = copyString(navCenterURL);
*(gNavCenterDataSources + 1) = copyString(navCenterURL);
gNCDB = newNavCenterDB();
freeMem(navCenterURL);
HT_Startup();
/* GuessIEBookmarks(); */
#endif
walkThroughAllBookmarks(RDF_GetResource(NULL, "NC:Bookmarks", true));
return 0;
}
/*need to keep a linked list of all the dbs opened so that they
can all be closed down on exit */
PR_PUBLIC_API(RDF_Error)
RDF_Shutdown ()
{
#ifdef MOZILLA_CLIENT
/* flushBookmarks(); */
HT_Shutdown();
RDFglueExit();
if (profileDirURL != NULL)
{
freeMem(profileDirURL);
profileDirURL = NULL;
}
if (gBookmarkURL != NULL)
{
freeMem(gBookmarkURL);
gBookmarkURL = NULL;
}
if (gGlobalHistoryURL != NULL)
{
freeMem(gGlobalHistoryURL);
gGlobalHistoryURL = NULL;
}
if (gLocalStoreURL != NULL)
{
freeMem(gLocalStoreURL);
gLocalStoreURL = NULL;
}
#endif
disposeAllDBs();
sRDFInitedB = PR_FALSE;
return 0;
}

View File

@@ -0,0 +1,554 @@
/* -*- 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 parsing 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 "rdfparse.h"
#include "mcf.h"
#define wsCharp(c) ((c == '\r') || (c == '\t') || (c == ' ') || (c == '\n'))
char
decodeEntityRef (char* string, int32* stringIndexPtr, int32 len)
{
if (startsWith("lt;", string)) {
*stringIndexPtr = *stringIndexPtr + 3;
return '<';
} else if (startsWith("gt;", string)) {
*stringIndexPtr = *stringIndexPtr + 3;
return '>';
} else if (startsWith("amp;", string)) {
*stringIndexPtr = *stringIndexPtr + 4;
return '&';
} else return -1;
}
char *
copyStringIgnoreWhiteSpace(char* string)
{
int32 len = RDF_STRLEN(string);
char* buf = (char*)getMem(len + 1);
PRBool inWhiteSpace = 1;
int32 buffIndex = 0;
int32 stringIndex = 0;
while (stringIndex < len) {
char nextChar = *(string + stringIndex);
PRBool wsp = wsCharp(nextChar);
if (!wsp) {
if (nextChar == '&') {
*(buf + buffIndex++) = decodeEntityRef(&string[stringIndex+1],
&stringIndex, len-stringIndex);
} else {
*(buf + buffIndex++) = nextChar;
}
inWhiteSpace = 0;
} else if (!inWhiteSpace) {
*(buf + buffIndex++) = ' ';
inWhiteSpace = 1;
} else {
inWhiteSpace = 1;
}
stringIndex++;
}
return buf;
}
char *
getHref(char** attlist)
{
char* ans = getAttributeValue(attlist, "rdf:href");
if (!ans) ans = getAttributeValue(attlist, "RDF:href");
if (!ans) ans = getAttributeValue(attlist, "href");
return ans;
}
int parseNextRDFXMLBlobInt(RDFFile f, char* blob, int32 size) {
int32 n, last, m;
PRBool somethingseenp = 0;
n = last = 0;
while (n < size) {
char c = blob[n];
m = 0;
somethingseenp = 0;
memset(f->line, '\0', RDF_BUF_SIZE-1);
if (f->holdOver[0] != '\0') {
memcpy(f->line, f->holdOver, RDF_STRLEN(f->holdOver));
m = RDF_STRLEN(f->holdOver);
somethingseenp = 1;
memset(f->holdOver, '\0', RDF_BUF_SIZE-1);
}
while ((n < size) && (wsc(c))) {c = blob[++n];}
/* f->line[m++] = c;
c = blob[++n]; */
while ((m < RDF_BUF_SIZE) && (c != '<') && (c != '>')) {
f->line[m] = c;
m++;
somethingseenp = (somethingseenp || (!(wsc(c))));
n++;
if (n < size) c = blob[n];
else break;
}
if (c == '>') f->line[m] = c;
n++;
if (m > 0) {
if ((c == '<') || (c == '>')) {
last = n;
if (c == '<') f->holdOver[0] = '<';
if (somethingseenp == 1) parseNextRDFToken(f, f->line);
} else if (size > last) {
memcpy(f->holdOver, f->line, m);
}
} else if (c == '<') f->holdOver[0] = '<';
}
return(size);
}
void
parseRDFProcessingInstruction (RDFFile f, char* token)
{
char* attlist[2*MAX_ATTRIBUTES+1];
char* elementName;
tokenizeElement(token, attlist, &elementName);
if (RDF_STRCMP(elementName, "?xml:namespace") == 0) {
char* as = getAttributeValue(attlist, "prefix");
char* url = getAttributeValue(attlist, "ns");
if ((as != NULL) && (url != NULL)) {
XMLNameSpace ns = (XMLNameSpace)getMem(sizeof(struct XMLNameSpaceStruct));
size_t urln = RDF_STRLEN(url);
PRBool addSlash = (url[urln-1] != '/');
if(addSlash) urln++;
ns->url = (char*)getMem(sizeof(char) * (urln + 1));
sprintf(ns->url, "%s%s", url, addSlash ? "/" : "");
ns->as = copyString(as);
ns->next = f->namespaces;
f->namespaces = ns;
}
}
}
void
freeNamespaces (RDFFile f)
{
XMLNameSpace ns1 = f->namespaces;
while (ns1) {
XMLNameSpace next = ns1->next;
freeMem(ns1->as);
freeMem(ns1->url);
freeMem(ns1);
ns1 = next;
}
f->namespaces = NULL;
}
PR_PUBLIC_API(char *)
getAttributeValue (char** attlist, char* elName)
{
size_t n = 0;
if (!attlist) return NULL;
while ((n < 2*MAX_ATTRIBUTES) && (*(attlist + n) != NULL)) {
if (RDF_STRCMP(*(attlist + n), elName) == 0) return *(attlist + n + 1);
n = n + 2;
}
return NULL;
}
PRBool
tagEquals (RDFFile f, char* tag1, char* tag2)
{
return (RDF_STRCMP(tag1, tag2) == 0);
}
void
addElementProps (char** attlist, char* elementName, RDFFile f, RDF_Resource obj)
{
uint32 count = 0;
while (count < 2*MAX_ATTRIBUTES) {
char* attName = attlist[count++];
char* attValue = attlist[count++];
if ((attName == NULL) || (attValue == NULL)) break;
if (!tagEquals(f, attName, "href") && !tagEquals(f, attName, "rdf:href") &&
!tagEquals(f, attName, "RDF:href") && !tagEquals(f, attName, "tv")
&& !tagEquals(f, attName, "id")) {
addSlotValue(f, obj, ResourceFromElementName(f, attName), copyStringIgnoreWhiteSpace(attValue),
RDF_STRING_TYPE, "true");
}
}
}
PRBool
knownObjectElement (char* eln)
{
return (RDF_STRCMP(eln, "RDF:Description") == 0);
}
char *
possiblyMakeAbsolute (RDFFile f, char* url)
{
if (RDF_STRCHR(url, ':') != NULL) {
return copyString(url);
} else {
char* ans = getMem(RDF_STRLEN(f->url) + strlen(url)+2);
sprintf(ans, "%s#%s", f->url, url);
return ans;
}
}
PRBool
containerTagp (RDFFile f, char* elementName)
{
return (tagEquals(f, elementName, "Container") ||
tagEquals(f, elementName, "Topic") ||
(tagEquals(f, elementName, "RelatedLinks")));
}
#define DC_TITLE "http://purl.org/metadata/dublin_core/title"
#define SM_CHILD "http://purl.org/metadata/sitemap/child"
RDF_Resource
ResourceFromElementName (RDFFile f, char* elementName)
{
if(!elementName || (RDF_STRCHR(elementName, ':') == NULL) ) {
return RDF_GetResource(NULL, elementName, 1);
} else {
XMLNameSpace ns = f->namespaces;
while (ns) {
if (startsWith(ns->as, elementName)) {
RDF_Resource ans;
size_t asn = RDF_STRLEN(ns->as);
size_t urln = RDF_STRLEN(ns->url);
char* url = getMem(RDF_STRLEN(ns->url) + strlen(elementName)-asn);
memcpy(url, ns->url, urln);
RDF_STRCAT(url, &elementName[asn+1]);
if (RDF_STRCMP(url, DC_TITLE) == 0) {
ans = gCoreVocab->RDF_name;
} else if (RDF_STRCMP(url, SM_CHILD) == 0) {
ans = gCoreVocab->RDF_child;
} else
ans = RDF_GetResource(NULL, url, 1);
freeMem(url);
return ans;
}
ns = ns->next;
}
return RDF_GetResource(NULL, elementName, 1);
}
}
void
parseNextRDFToken (RDFFile f, char* token)
{
char* attlist[2*MAX_ATTRIBUTES+1];
char* elementName;
if (token[0] != '<') {
if ((f->status == EXPECTING_OBJECT) && (f->depth > 1)) {
RDF_Resource u = f->stack[f->depth-2];
RDF_Resource s = f->stack[f->depth-1];
addSlotValue(f, u, s, copyStringIgnoreWhiteSpace(token), RDF_STRING_TYPE, NULL);
}
} else if (startsWith("<!--", token)) {
return;
} else if (token[1] == '?') {
parseRDFProcessingInstruction(f, token);
} else if (token[1] == '/') {
if ((f->status != EXPECTING_OBJECT) && (f->status != EXPECTING_PROPERTY)) return;
if (f->depth > 0) f->depth--;
f->status = (f->status == EXPECTING_OBJECT ? EXPECTING_PROPERTY : EXPECTING_OBJECT);
} else if ((f->status == 0) && startsWith("<RDF:RDF", token)) {
char* status = NULL;
char* update;
char* post;
f->status = EXPECTING_OBJECT;
tokenizeElement(token, attlist, &elementName);
update = getAttributeValue(attlist, "updateURL");
post = getAttributeValue(attlist, "postURL");
if (update) f->updateURL = copyString(update);
if (post) f->postURL = copyString(post);
status = getAttributeValue(attlist, "status");
if (status && (RDF_STRCMP(status, "replace"))) gcRDFFileInt(f);
} else if (startsWith("<RelatedLinks", token)) {
f->stack[f->depth++] = f->top;
f->status = EXPECTING_PROPERTY;
} else {
PRBool emptyElementp = (token[RDF_STRLEN(token)-2] == '/');
if ((f->status != EXPECTING_OBJECT) && (f->status != EXPECTING_PROPERTY)) return;
tokenizeElement(token, attlist, &elementName);
if ((f->status == EXPECTING_PROPERTY) && (knownObjectElement(elementName))) return;
if (f->status == EXPECTING_OBJECT) {
char* url = NULL;
RDF_Resource obj;
uint16 count = 0;
url = getHref(attlist);
if (url == NULL) url = getAttributeValue(attlist, "id");
if (url) url = possiblyMakeAbsolute(f, url);
obj = ResourceFromElementName(f, url);
if (url) freeMem(url);
addToResourceList(f, obj);
addElementProps (attlist, elementName, f, obj) ;
if (!tagEquals(f, elementName, "RDF:Description")) {
if (containerTagp(f, elementName)) {
setContainerp(obj, 1);
} else {
RDF_Resource eln = ResourceFromElementName(f, elementName);
addSlotValue(f, obj, gCoreVocab->RDF_instanceOf, eln, RDF_RESOURCE_TYPE, getAttributeValue(attlist, "tv"));
}
}
if (f->depth > 1) {
addSlotValue(f, f->stack[f->depth-2], f->stack[f->depth-1], obj,
RDF_RESOURCE_TYPE, getAttributeValue(attlist, "tv"));
}
if (!emptyElementp) {
f->stack[f->depth++] = obj;
f->status = EXPECTING_PROPERTY;
}
} else if (f->status == EXPECTING_PROPERTY) {
char* url;
RDF_Resource obj;
uint16 count = 0;
url = getHref(attlist) ;
if (url) {
RDF_Resource eln = ResourceFromElementName(f, elementName);
char* tvAtt = getAttributeValue(attlist, "tv");
url = possiblyMakeAbsolute(f, url);
obj = ResourceFromElementName(f, url);
freeMem(url);
addElementProps (attlist, elementName, f, obj) ;
addToResourceList(f, obj);
addSlotValue(f, f->stack[f->depth-1], eln,obj,RDF_RESOURCE_TYPE,
getAttributeValue(attlist, "tv"));
} else if ((RDF_STRCMP(elementName, "child") == 0) && attlist[0] &&
(RDF_STRCMP(attlist[0], "instanceOf") == 0) &&
attlist[1] && startsWith("Separator", attlist[1])) {
RDF_Resource sep = createSeparator();
RDF_Resource eln = ResourceFromElementName(f, elementName);
addSlotValue(f, f->stack[f->depth-1], eln,sep,RDF_RESOURCE_TYPE,
getAttributeValue(attlist, "tv"));
}
if (!emptyElementp) {
f->stack[f->depth++] = ResourceFromElementName(f, elementName);
f->status = EXPECTING_OBJECT;
}
}
}
}
void
tokenizeElement (char* attr, char** attlist, char** elementName)
{
size_t n = 1;
size_t s = RDF_STRLEN(attr);
char c ;
size_t m = 0;
size_t atc = 0;
PRBool emptyTagp = (attr[s-2] == '/');
PRBool inAttrNamep = 1;
c = attr[n++];
while (wsc(c)) {
c = attr[n++];
}
*elementName = &attr[n-1];
while (n < s) {
if (wsc(c)) break;
c = attr[n++];
}
attr[n-1] = '\0';
while (atc < 2*MAX_ATTRIBUTES+1) {*(attlist + atc++) = NULL;}
atc = 0;
s = (emptyTagp ? s-2 : s-1);
while (n < s) {
PRBool attributeOpenStringSeenp = 0;
m = 0;
c = attr[n++];
while ((n <= s) && (atc < 2*MAX_ATTRIBUTES)) {
if (inAttrNamep && (m > 0) && (wsc(c) || (c == '='))) {
attr[n-1] = '\0';
*(attlist + atc++) = &attr[n-m-1];
break;
}
if (!inAttrNamep && attributeOpenStringSeenp && (c == '"')) {
attr[n-1] = '\0';
*(attlist + atc++) = &attr[n-m-1];
break;
}
if (inAttrNamep) {
if ((m > 0) || (!wsc(c))) m++;
} else {
if (c == '"') {
attributeOpenStringSeenp = 1;
} else {
if ((m > 0) || (!(wsc(c)))) m++;
}
}
c = attr[n++];
}
inAttrNamep = (inAttrNamep ? 0 : 1);
}
}
void
outputRDFTreeInt (RDF rdf, PRFileDesc *fp, RDF_Resource node, uint32 depth, PRBool localOnly)
{
RDF_Cursor c = RDF_GetSources(rdf, node, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
RDF_Resource next;
char* buf = getMem(1024);
char* space = getMem((4*depth)+1);
char* url = resourceID(node);
char* name = RDF_GetResourceName(rdf, node);
char* hrefid;
if ((buf == NULL) || (space == NULL)) return;
if (depth > 0) memset(space, ' ', depth);
if (!RDF_STRCHR(url, ':') || (depth == 0)) {
hrefid = "id";
} else {
hrefid = "rdf:href";
}
if (depth == 0) url="root";
if (containerp(node)) {
if (depth > 0) {
sprintf(buf, "%s<child>\n", space);
PR_Write(fp, buf, RDF_STRLEN(buf));
}
sprintf(buf, "%s<Topic %s=\"%s\"\n%s name=\"%s\">\n", space, hrefid, url, space, name);
PR_Write(fp, buf, RDF_STRLEN(buf));
while ((next = RDF_NextValue(c)) != NULL) {
/* if exporting EVERYTHING, need to skip over certain things */
if ((localOnly == PR_FALSE) || ((!startsWith("ftp:",url)) && (!startsWith("file:",url))
&& (!startsWith("IMAP:", url)) && (!startsWith("nes:", url))
&& (!startsWith("mail:", url)) && (!startsWith("cache:", url))
&& (!startsWith("ldap:", url)) &&
(!urlEquals(resourceID(node), resourceID(gNavCenter->RDF_LocalFiles))) &&
(!urlEquals(resourceID(node), resourceID(gNavCenter->RDF_History)))))
{
outputRDFTreeInt(rdf, fp, next, depth+1, localOnly);
}
}
sprintf(buf, "%s</Topic>\n", space);
PR_Write(fp, buf, RDF_STRLEN(buf));
if (depth > 0) {
sprintf(buf, "%s</child>\n", space);
PR_Write(fp, buf, RDF_STRLEN(buf));
}
} else {
sprintf(buf, "%s<child %s=\"%s\"\n%s name=\"%s\"/>\n", space, hrefid, url, space, name);
PR_Write(fp, buf, RDF_STRLEN(buf));
}
RDF_DisposeCursor(c);
freeMem(buf);
freeMem(space);
}
void
outputRDFTree (RDF rdf, PRFileDesc *fp, RDF_Resource node)
{
ht_fprintf(fp, "<RDF:RDF>\n\n");
outputRDFTreeInt(rdf, fp, node, 0, (node==gNavCenter->RDF_Top) ? PR_TRUE:PR_FALSE);
ht_fprintf(fp, "\n</RDF:RDF>\n");
}
void
addSlotValue (RDFFile f, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, char* op)
{
PRBool tv;
if (f == NULL || u == NULL || s == NULL || v == NULL) return;
if (s == gCoreVocab->RDF_child) {
RDF_Resource temp = (RDF_Resource)v;
if (type != RDF_RESOURCE_TYPE) return;
s = gCoreVocab->RDF_parent;
v = u;
u = temp;
}
if (op == NULL) {
tv = 1;
} else if (RDF_STRCMP(op, "true") == 0) {
tv = 1;
} else if (RDF_STRCMP(op, "false") == 0) {
tv = 0;
} else if (RDF_STRCMP(op, "delete") == 0) {
if (f->unassert) (*f->unassert)(f, f->db, u, s, v, type);
return;
}
if ((s == gCoreVocab->RDF_parent) && (type == RDF_RESOURCE_TYPE)) {
f->genlAdded = true;
if (strstr(resourceID(u), ".rdf") && startsWith("http", resourceID(u))) {
RDFL rl = f->db->rdf;
char* dburl = getBaseURL(resourceID(u));
if (!startsWith(dburl, resourceID((RDF_Resource)v))) {
while (rl) {
RDF_AddDataSource(rl->rdf, dburl);
rl = rl->next;
}
freeMem(dburl);
}
}
}
(*f->assert)(f, f->db, u, s, v, type, tv);
if (s == gCoreVocab->RDF_parent) setContainerp((RDF_Resource)v, 1);
#ifndef MOZILLA_CLIENT
notifySlotValueAdded(u, s, v, type);
#endif
}

View File

@@ -0,0 +1,60 @@
/* -*- 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_RDFPARSE_H_
#define _RDF_RDFPARSE_H_
#include "rdf-int.h"
/* rdfparse.c data structures and defines */
#define wsc(c) ((c == ' ') || (c == '\r') || (c == '\n') || (c == '\t'))
#define EXPECTING_OBJECT 21
#define EXPECTING_PROPERTY 22
/* rdfparse.c function prototypes */
char decodeEntityRef (char* string, int32* stringIndexPtr, int32 len);
char * copyStringIgnoreWhiteSpace(char* string);
char * getHref(char** attlist);
void parseRDFProcessingInstruction (RDFFile f, char* token);
PR_PUBLIC_API(char *) getAttributeValue (char** attlist, char* elName);
PRBool tagEquals (RDFFile f, char* tag1, char* tag2);
void addElementProps (char** attlist, char* elementName, RDFFile f, RDF_Resource obj);
PRBool knownObjectElement (char* eln);
char * possiblyMakeAbsolute (RDFFile f, char* url);
PRBool containerTagp (RDFFile f, char* elementName);
RDF_Resource ResourceFromElementName (RDFFile f, char* elementName);
void parseNextRDFToken (RDFFile f, char* token);
void tokenizeElement (char* attr, char** attlist, char** elementName);
void outputRDFTreeInt (RDF rdf, PRFileDesc *fp, RDF_Resource node, uint32 depth, PRBool localOnly);
void outputRDFTree (RDF rdf, PRFileDesc *fp, RDF_Resource node);
#endif

View File

@@ -0,0 +1,32 @@
/* -*- 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.
*/
#include "plstr.h"
#define RDF_STRLEN(s) PL_strlen((s))
#define RDF_STRCMP(s1,s2) PL_strcmp((s1),(s2))
/* #define RDF_STRDUP(s) PL_strdup((s)) evil? */
#define RDF_STRCHR(s,c) PL_strchr((s),(c))
#define RDF_STRRCHR(s,c) PL_strrchr((s),(c))
#define RDF_STRCAT(dest,src) PL_strcat((dest),(src))
#define RDF_STRCASECMP(s1,s2) PL_strcasecmp((s1),(s2))
#define RDF_STRNCASECMP(s1,s2,n) PL_strncasecmp((s1),(s2),(n))
#define RDF_STRCASESTR(s1,s2) PL_strcasestr((s1),(s2))

View File

@@ -0,0 +1,832 @@
/* -*- 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;
}

View File

@@ -0,0 +1,85 @@
/* -*- 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_REMSTORE_H_
#define _RDF_REMSTORE_H_
#include "rdf-int.h"
#include "prtime.h"
/* remstore.c data structures and defines */
struct RDFTOutStruct {
char *buffer;
int32 bufferSize;
int32 bufferPos;
char *temp;
RDFT store;
};
typedef struct RDFTOutStruct *RDFTOut;
/* remstore.c function prototypes */
RDFT MakeRemoteStore (char* url);
RDFT existingRDFFileDB (char* url);
RDFT MakeFileDB (char* url);
void freeAssertion (Assertion as);
PRBool remoteAssert3 (RDFFile fi, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool remoteUnassert3 (RDFFile fi, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
void remoteStoreflushChildren(RDFT mcf, RDF_Resource parent);
Assertion remoteStoreAdd (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
Assertion remoteStoreRemove (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool fileReadablep (char* id);
PRBool remoteStoreHasAssertionInt (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool remoteStoreHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
void * remoteStoreGetSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor remoteStoreGetSlotValuesInt (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor remoteStoreGetSlotValues (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor remoteStoreArcLabelsIn (RDFT mcf, RDF_Resource u);
RDF_Cursor remoteStoreArcLabelsOut (RDFT mcf, RDF_Resource u);
void * arcLabelsOutNextValue (RDFT mcf, RDF_Cursor c);
void * arcLabelsInNextValue (RDFT mcf, RDF_Cursor c);
void * remoteStoreNextValue (RDFT mcf, RDF_Cursor c);
RDF_Error remoteStoreDisposeCursor (RDFT mcf, RDF_Cursor c);
RDF_Error DeleteRemStore (RDFT db);
RDF_Error remStoreUpdate (RDFT db, RDF_Resource u);
void gcRDFFile (RDFFile f);
void RDFFilePossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep);
void possiblyRefreshRDFFiles ();
void SCookPossiblyAccessFile (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep);
RDFT MakeSCookDB (char* url);
void addToRDFTOut (RDFTOut out);
PRIntn RDFSerializerEnumerator (PLHashEntry *he, PRIntn i, void *arg);
RDFFile makeNewRDFFile (char* url, RDF_Resource top, PRBool localp, RDFT db) ;
static PRBool fileReadp (RDFT rdf, char* url, PRBool mark);
static void possiblyAccessFile (RDFT mcf, RDF_Resource u, RDF_Resource s, PRBool inversep);
static RDFFile leastRecentlyUsedRDFFile (RDF mcf);
static PRBool freeSomeRDFSpace (RDF mcf);
RDFFile reReadRDFFile (char* url, RDF_Resource top, PRBool localp, RDFT db);
#endif

View File

@@ -0,0 +1,440 @@
/* -*- 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 Super Cookie 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 "rdf-int.h"
#include "scook.h"
#include "glue.h"
#include "remstore.h"
/* externs */
extern char* profileDirURL;
char *
makeSCookPathname(char* name)
{
char *ans ;
size_t s;
if ((ans = (char*) getMem(RDF_STRLEN(profileDirURL) + strlen(name) + 8)) != NULL) {
s = RDF_STRLEN(profileDirURL);
memcpy(ans, profileDirURL, s);
if (ans[s-1] != '/') {
ans[s++] = '/';
}
memcpy(&ans[s], "SCook/", 5);
s = s + 5;
#ifdef XP_WIN
if (ans[9] == '|') ans[9] = ':';
#endif
CallPRMkDirUsingFileURL(ans, 00700);
memcpy(&ans[s], name, RDF_STRLEN(name));
}
return(ans);
}
PRBool
SCookAssert1 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
return 0;
}
PRBool
SCookAssert3 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
return (SCookAssert(mcf, u, s, v, type, tv) != NULL);
}
PRBool
SCookAssert2 (RDFFile file, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
Assertion as = SCookAssert(mcf , u, s, v, type, tv);
if (as != NULL) {
void addToAssertionList (RDFFile f, Assertion as) ;
addToAssertionList(file, as);
return 1;
} else return 0;
}
Assertion
SCookAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type, PRBool tv)
{
Assertion nextAs, prevAs, newAs;
nextAs = prevAs = getArg1(mcf, u);
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) {
setArg1(mcf, u, newAs);
} else {
prevAs->next = newAs;
}
if (type == RDF_RESOURCE_TYPE) {
nextAs = prevAs = getArg2(mcf, (RDF_Resource)v);
while (nextAs != null) {
prevAs = nextAs;
nextAs = nextAs->invNext;
}
if (prevAs == null) {
setArg2(mcf, ((RDF_Resource)v), newAs);
} else {
prevAs->invNext = newAs;
}
}
/* XXX have to mark the entire subtree XXX */
sendNotifications2(mcf, RDF_ASSERT_NOTIFY, u, s, v, type, tv);
return newAs;
}
PRBool
SCookUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v,
RDF_ValueType type)
{
Assertion as = SCookRemove(mcf, u, s, v, type);
freeMem(as);
return (as != NULL);
}
Assertion
SCookRemove (RDFT mcf, RDF_Resource u, RDF_Resource s,
void* v, RDF_ValueType type)
{
Assertion nextAs, prevAs, ans;
PRBool found = false;
nextAs = prevAs = getArg1(mcf, u);
while (nextAs != null) {
if (asEqual(mcf, nextAs, u, s, v, type)) {
if (prevAs == nextAs) {
setArg1(mcf, u, 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 = getArg2(mcf, (RDF_Resource)v);
while (nextAs != null) {
if (nextAs == ans) {
if (prevAs == nextAs) {
setArg2(mcf, ((RDF_Resource)v), nextAs->invNext);
} else {
prevAs->invNext = nextAs->invNext;
}
}
prevAs = nextAs;
nextAs = nextAs->invNext;
}
}
/* Need to make sure that if something is removed from the bookmark tree,
the type is updated */
sendNotifications2(mcf, RDF_DELETE_NOTIFY, u, s, v, type, ans->tv);
return ans;
}
PRBool
SCookHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv)
{
Assertion nextAs;
nextAs = getArg1(mcf, u);
while (nextAs != null) {
if (asEqual(mcf, nextAs, u, s, v, type) && (nextAs->tv == tv)) return true;
nextAs = nextAs->next;
}
possiblyAccessSCookFile(mcf, u, s, 0);
return false;
}
void *
SCookGetSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv)
{
Assertion nextAs;
nextAs = (inversep ? getArg2(mcf, u) : getArg1(mcf, u));
while (nextAs != null) {
if ((nextAs->s == s) && (nextAs->tv == tv) && (nextAs->type == type)) {
return (inversep ? nextAs->u : nextAs->value);
}
nextAs = (inversep ? nextAs->invNext : nextAs->next);
}
possiblyAccessSCookFile(mcf, u, s, inversep);
return null;
}
RDF_Cursor
SCookGetSlotValues (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv)
{
Assertion as = (inversep ? getArg2(mcf, u) : getArg1(mcf, u));
RDF_Cursor c;
if (as == null) {
possiblyAccessSCookFile(mcf, u, s, inversep);
as = (inversep ? getArg2(mcf, u) : getArg1(mcf, u));
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;
}
void *
SCookNextValue (RDFT mcf, RDF_Cursor c)
{
while (c->pdata != null) {
Assertion as = (Assertion) c->pdata;
if ((as->s == c->s) && (as->tv == c->tv) && (c->type == as->type)) {
if (c->s == gCoreVocab->RDF_slotsHere) {
c->value = as->s;
} else {
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
SCookDisposeCursor (RDFT mcf, RDF_Cursor c)
{
freeMem(c);
return noRDFErr;
}
Assertion
getArg1 (RDFT r, RDF_Resource u)
{
return PL_HashTableLookup(((SCookDB)r->pdata)->lhash, u);
}
Assertion
getArg2 (RDFT r, RDF_Resource u)
{
return PL_HashTableLookup(((SCookDB)r->pdata)->rhash, u);
}
void
setArg1 (RDFT r, RDF_Resource u, Assertion as)
{
if (as == NULL) {
PL_HashTableRemove(((SCookDB)r->pdata)->lhash, u);
} else {
PL_HashTableAdd(((SCookDB)r->pdata)->lhash, u, as);
}
}
void
setArg2 (RDFT r, RDF_Resource u, Assertion as)
{
if (as == NULL) {
PL_HashTableRemove(((SCookDB)r->pdata)->rhash, u);
} else {
PL_HashTableAdd(((SCookDB)r->pdata)->rhash, u, as);
}
}
void
gcSCookFile (RDFT rdf, RDFFile f)
{
int16 n = 0;
RDFFile f1;
SCookDB sk = (SCookDB)rdf->pdata;
f1 = sk->rf;
if (f->locked) return;
if (f == f1) {
sk->rf = f->next;
} else {
RDFFile prev = f1;
while (f1 != NULL) {
if (f1 == f) {
prev->next = f->next;
break;
}
prev = f1;
f1 = f1->next;
}
}
while (n < f->assertionCount) {
Assertion as = *(f->assertionList + n);
SCookUnassert(rdf, as->u, as->s, as->value, as->type);
freeAssertion(as);
*(f->assertionList + n) = NULL;
n++;
}
n = 0;
while (n < f->resourceCount) {
RDF_Resource u = *(f->resourceList + n);
possiblyGCResource(u);
n++;
}
freeMem(f->assertionList);
freeMem(f->resourceList);
}
void
disposeAllSCookFiles (RDFT rdf, RDFFile f)
{
if (f != NULL) {
disposeAllSCookFiles(rdf, f->next);
gcSCookFile(rdf, f);
}
}
void
SCookDisposeDB (RDFT rdf)
{
SCookDB db = (SCookDB)rdf->pdata;
disposeAllSCookFiles(rdf, db->rf);
PL_HashTableDestroy(db->rhash);
PL_HashTableDestroy(db->lhash);
freeMem(db);
}
static PRBool
SCookFileReadp (RDFT rdf, RDF_Resource u)
{
RDFFile f;
SCookDB db = (SCookDB)rdf->pdata;
uint n = 0;
for (f = db->rf; (f != NULL) ; f = f->next) {
n++;
if (urlEquals( resourceID(u), f->url)) {
return true;
}
}
return false;
}
void
possiblyAccessSCookFile (RDFT mcf, RDF_Resource u, RDF_Resource s, PRBool inversep)
{
if ((s == gCoreVocab->RDF_parent) && (strstr(resourceID(u), ":/")) &&
(((SCookDB)mcf->pdata)->rf != NULL) && (containerp(u)) &&
(resourceType(u) == RDF_RT) && (!SCookFileReadp(mcf, u))) {
RDFFile newFile = makeRDFFile( resourceID(u), u, 0);
SCookDB db = (SCookDB)mcf->pdata;
newFile->next = db->rf;
newFile->fileType = RDF_XML;
newFile->db = mcf;
db->rf = newFile;
newFile->db = mcf;
newFile->assert = SCookAssert2;
beginReadingRDFFile(newFile);
}
}
void SCookPossiblyAccessFile1 (RDFT rdf, RDF_Resource u, RDF_Resource s, PRBool inversep) {
if ((resourceType(u) == RDF_RT) && (RDF_STRCMP(rdf->url, "rdf:ht") ==0) &&
(strstr(resourceID(u), ".rdf") || strstr(resourceID(u), ".mcf")) &&
(s == gCoreVocab->RDF_parent) &&
(containerp(u))) {
RDFFile newFile = readRDFFile( resourceID(u), u, false, rdf);
if(newFile) newFile->lastReadTime = PR_Now();
}
}
RDFT
MakeSCookDB1 (char* url)
{
if (startsWith("rdf:scook:", url) || (startsWith("rdf:ht", url))) {
RDFT ntr = (RDFT)getMem(sizeof(struct RDF_TranslatorStruct));
ntr->assert = NULL;
ntr->unassert = NULL;
ntr->getSlotValue = remoteStoreGetSlotValue;
ntr->getSlotValues = remoteStoreGetSlotValues;
ntr->hasAssertion = remoteStoreHasAssertion;
ntr->nextValue = remoteStoreNextValue;
ntr->disposeCursor = remoteStoreDisposeCursor;
ntr->possiblyAccessFile = RDFFilePossiblyAccessFile ;
ntr->url = copyString(url);
return ntr;
} else return NULL;
}

View File

@@ -0,0 +1,69 @@
/* -*- 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_SCOOK_H_
#define _RDF_SCOOK_H_
#include "rdf-int.h"
/* scook.c data structures */
typedef struct _SCookDBStruct {
PLHashTable* lhash;
PLHashTable* rhash;
char* reader;
RDFFile rf;
RDFT db;
} SCookDBStruct;
typedef SCookDBStruct* SCookDB;
/* scook.c function prototypes */
NSPR_BEGIN_EXTERN_C
char * makeSCookPathname(char* name);
PRBool SCookAssert1 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool SCookAssert3 (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool SCookAssert2 (RDFFile file, RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
Assertion SCookAssert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
PRBool SCookUnassert (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
Assertion SCookRemove (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
PRBool SCookHasAssertion (RDFT mcf, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type, PRBool tv);
void * SCookGetSlotValue (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
RDF_Cursor SCookGetSlotValues (RDFT mcf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * SCookNextValue (RDFT mcf, RDF_Cursor c);
RDF_Error SCookDisposeCursor (RDFT mcf, RDF_Cursor c);
Assertion getArg1 (RDFT r, RDF_Resource u);
Assertion getArg2 (RDFT r, RDF_Resource u);
void setArg1 (RDFT r, RDF_Resource u, Assertion as);
void setArg2 (RDFT r, RDF_Resource u, Assertion as);
void gcSCookFile (RDFT rdf, RDFFile f);
void disposeAllSCookFiles (RDFT rdf, RDFFile f);
void SCookDisposeDB (RDFT rdf);
void possiblyAccessSCookFile (RDFT mcf, RDF_Resource u, RDF_Resource s, PRBool inversep);
RDFT MakeSCookDB (char* url);
NSPR_END_EXTERN_C
#endif

View File

@@ -0,0 +1,177 @@
/* -*- 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.
*/
/*
* test.cpp
*
* This file is provided to ensure that the RDF engine will
* compile and run standalone (outside of mozilla). It may also
* be useful as a demonstration of how to initialize and
* use the engine, and possibly for performance testing.
* Finally, it ensures that the header files are probably written
* for C++.
*
* Currently this program simply reads in an rdf site-map file
* and spits it back out to the display. Feel free to
* modify/enhance as desired.
*
* See Dan Libby (danda@netscape.com) for more info.
*
*/
#include "stdlib.h"
#include "rdf-int.h"
#include "rdf.h"
#include "rdfparse.h"
const char *dataSources[] = {
"rdf:remoteStore", NULL
};
void
main(int argc, char** argv)
{
RDF rdf;
RDF_Error err;
RDF_InitParamsStruct initParams = {0};
RDF_Resource u, s, root;
void *v;
RDFFile file;
#ifdef XP_WIN
char* fileURL = (argc > 1) ? argv[1] : "file:///test.rdf";
#else
char* fileURL = (argc > 1) ? argv[1] : "file://test.rdf";
#endif
char* rootURL = (char*)getMem(200);
err = RDF_Init(&initParams);
if (err)
{
perror("RDF_Init: ");
exit(1);
}
else
{
printf("RDF Init success\n");
}
/*
* Try and get a reference to the remote store DB
*/
rdf = RDF_GetDB(dataSources);
if (rdf == NULL)
{
perror("RDF_GetDB");
exit(1);
}
else
{
printf("RDF_GetDB success\n");
}
sprintf(rootURL, "%s#root", fileURL);
root = (RDF_Resource)RDF_GetResource(NULL, rootURL, PR_TRUE);
setResourceType(root, RDF_RT);
/* Create a test resource */
u = RDF_GetResource(rdf, "http://people.netscape.com/danda/", TRUE);
s = gCoreVocab->RDF_name;
v = "Dan Libby";
/* make an assertion into RDF's graph */
RDF_Assert(rdf, u,s,v, RDF_STRING_TYPE);
/* check to see if assertion exists */
if (!RDF_HasAssertion(rdf,u,s,v, RDF_STRING_TYPE, true))
{
printf("Assertion failure.\n");
}
else
{
printf("Assertion success.\n");
}
/* Import an RDF file */
printf("Reading \"%s\"\n", fileURL);
fflush(stdout);
file = readRDFFile (fileURL, root, PR_TRUE, gRemoteStore);
if (file && file->assertionCount > 0)
{
printf("\"%s\" read in successfully. (%i assertions)\n", fileURL, file->assertionCount);
fflush(stdout);
PRFileDesc *fd = PR_GetSpecialFD(PR_StandardOutput);
outputRDFTree (rdf, fd, root);
#if 0
RDF_Cursor c;
int i = 0;
c = RDF_GetSources(rdf, root, gCoreVocab->RDF_parent, RDF_RESOURCE_TYPE, true);
if (c)
{
u = (RDF_Resource)RDF_NextValue(c);
while (u)
{
printf("%i: %s\n", ++i, u->url);
u = (RDF_Resource)RDF_NextValue(c);
}
RDF_DisposeCursor(c);
}
#endif
}
else
{
printf("error reading %s\n", fileURL);
}
RDF_Shutdown();
}
/* This function has to be here when building standalone RDF or you
* will get a link error.
*/
extern "C"
void notifySlotValueAdded(RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type)
{
if(type == RDF_STRING_TYPE)
{
#if 0
printf("String Value added: %s\n", (char*)v);
#endif
}
else if(type == RDF_RESOURCE_TYPE)
{
if(type == RDF_RESOURCE_TYPE)
{
/* Right here you can find out when
* resources are added, and what their
* ids are, for querying later. This is
* useful when the ID of the resource is
* not known at compile time.
*/
#if 0
printf("Resource added, ID: %s\n", resourceID((RDF_Resource)v));
#endif
}
}
}

View File

@@ -0,0 +1,798 @@
/* -*- 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 utility routines 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 "utils.h"
#include "vocabint.h"
/* globals */
PRBool rdfDBInited = 0;
PLHashTable* resourceHash = 0;
PLHashTable* dataSourceHash = 0;
RDFT gRemoteStore = 0;
RDFT gSessionDB = 0;
/* externs */
extern char *profileDirURL;
#define INITIAL_RESOURCE_LIST_SIZE 50
#define INITIAL_ASSERTION_LIST_SIZE 100
#define GROW_LIST_INCR 50
int
compareStrings(char *s1, char *s2)
{
return RDF_STRCASECMP(s1, s2);
}
char *
makeRDFDBURL(char* directory, char* name)
{
char *ans;
size_t s;
if (profileDirURL == NULL) return NULL;
if ((ans = (char*) getMem(RDF_STRLEN(profileDirURL) + strlen(directory) + strlen(name) + 3)) != NULL) {
s = RDF_STRLEN(profileDirURL);
memcpy(ans, profileDirURL, s);
if (ans[s-1] != '/') {
ans[s++] = '/';
}
stringAppend(ans, directory);
stringAppend(ans, "/");
stringAppend(ans, name);
}
return(ans);
}
RDF_Resource
getMCFFrtop (char* furl)
{
char* url = getBaseURL(furl);
RDF_Resource r;
r = RDF_GetResource(NULL, url, 1);
freeMem(url);
return r;
}
char*
copyString (const char* url) {
int32 len = RDF_STRLEN(url);
char* newStr = (char*)getMem(len+1);
if (newStr != NULL) {
memcpy(newStr, url, len);
}
return newStr;
}
RDFFile
makeRDFFile (char* url, RDF_Resource top, PRBool localp)
{
RDFFile ans = (RDFFile)getMem(sizeof(struct RDF_FileStruct));
/* ans->rdf = rdf; */
ans->url = getBaseURL(url);
ans->top = top;
ans->localp = localp;
if (!localp) ans->refreshingp = PR_TRUE;
initRDFFile(ans);
return ans;
}
void
initRDFFile (RDFFile ans)
{
char* url = ans->url;
ans->rtop = getMCFFrtop(url);
ans->line = (char*)getMem(RDF_BUF_SIZE);
ans->currentSlot = (char*)getMem(100);
ans->resourceList = (RDF_Resource*)getMem(INITIAL_RESOURCE_LIST_SIZE * sizeof(RDF_Resource));
ans->assertionList = (Assertion*)getMem(INITIAL_ASSERTION_LIST_SIZE * sizeof(Assertion));
ans->resourceListSize = INITIAL_RESOURCE_LIST_SIZE;
ans->assertionListSize = INITIAL_ASSERTION_LIST_SIZE;
ans->holdOver = (char*)getMem(RDF_BUF_SIZE);
ans->depth = 1;
ans->lastItem = ans->stack[0] = ans->top;
ans->locked = ans->localp;
ans->lineSize = LINE_SIZE;
ans->tv = true;
ans->resourceCount = 0;
ans->assertionCount = 0;
}
void
addToResourceList (RDFFile f, RDF_Resource u)
{
if (f->resourceListSize == f->resourceCount) {
RDF_Resource* newResourceList = (RDF_Resource*)getMem(sizeof(RDF_Resource)*(f->resourceListSize + GROW_LIST_INCR));
RDF_Resource* old = f->resourceList;
memcpy((char*)newResourceList, (char*)f->resourceList, sizeof(RDF_Resource)*f->resourceListSize);
f->resourceList = newResourceList;
f->resourceListSize = f->resourceListSize + GROW_LIST_INCR;
freeMem(old);
}
*(f->resourceList + f->resourceCount++) = u;
}
void
addToAssertionList (RDFFile f, Assertion as)
{
if (f->assertionListSize == f->assertionCount) {
Assertion* newAssertionList = (Assertion*)getMem(sizeof(RDF_Resource)*(f->assertionListSize + GROW_LIST_INCR));
Assertion* old = f->assertionList;
memcpy((char*)newAssertionList, (char*)f->assertionList, sizeof(RDF_Resource)*f->assertionListSize);
f->assertionList = newAssertionList;
f->assertionListSize = f->assertionListSize + GROW_LIST_INCR;
freeMem(old);
}
*(f->assertionList + f->assertionCount++) = as;
}
void
removeFromAssertionList(RDFFile f, Assertion as)
{
/* XXX implement */
}
void
ht_fprintf(PRFileDesc *file, const char *fmt, ...)
{
va_list ap;
char *buf;
va_start(ap, fmt);
buf = PR_smprintf(fmt, ap);
va_end(ap);
if(buf) {
PR_Write(file, buf, RDF_STRLEN(buf));
free(buf);
}
}
void
ht_rjcprintf(PRFileDesc *file, const char *fmt, const char *data)
{
char *buf;
buf = PR_smprintf(fmt, data);
if(buf) {
PR_Write(file, buf, RDF_STRLEN(buf));
free(buf);
}
}
char *
makeDBURL(char* name)
{
char *ans;
size_t s;
if (profileDirURL == NULL) return NULL;
if ((ans = (char*) getMem(RDF_STRLEN(profileDirURL) + strlen(name) + 3)) != NULL) {
s = RDF_STRLEN(profileDirURL);
memcpy(ans, profileDirURL, s);
if (ans[s-1] != '/') {
ans[s++] = '/';
}
memcpy(&ans[s], name, RDF_STRLEN(name));
#ifdef XP_WIN
if (ans[9] == '|') ans[9] = ':';
#endif
}
return(ans);
}
PLHashNumber
idenHash (const void *key)
{
return (PLHashNumber)key;
}
int
idenEqual (const void *v1, const void *v2)
{
return (v1 == v2);
}
PRBool
inverseTV (PRBool tv)
{
if (tv == true) {
return false;
} else return true;
}
char *
append2Strings (const char* str1, const char* str2)
{
int32 l1 = RDF_STRLEN(str1);
int32 len = l1 + RDF_STRLEN(str2);
char* ans = (char*) getMem(len+1);
memcpy(ans, str1, l1);
memcpy(&ans[l1], str2, len-l1);
return ans;
}
void
stringAppendBase (char* dest, const char* addition)
{
int32 l1 = RDF_STRLEN(dest);
int32 l2 = RDF_STRLEN(addition);
int32 l3 = charSearch('#', addition);
if (l3 != -1) l2 = l3;
memcpy(&dest[l1], addition, l2);
}
void
stringAppend (char* dest, const char* addition)
{
int32 l1 = RDF_STRLEN(dest);
int32 l2 = RDF_STRLEN(addition);
memcpy(&dest[l1], addition, l2);
}
int16
charSearch (const char c, const char* data)
{
char* ch = RDF_STRCHR(data, c);
if (ch) {
return (ch - data);
} else {
return -1;
}
}
PRBool
endsWith (const char* pattern, const char* uuid)
{
short l1 = RDF_STRLEN(pattern);
short l2 = RDF_STRLEN(uuid);
short index;
if (l2 < l1) return false;
for (index = 1; index <= l1; index++) {
if (toupper(pattern[l1-index]) != toupper(uuid[l2-index])) return false;
}
return true;
}
PR_PUBLIC_API(PRBool)
startsWith (const char* pattern, const char* uuid)
{
short l1 = RDF_STRLEN(pattern);
short l2 = RDF_STRLEN(uuid);
if (l2 < l1) return false;
return (RDF_STRNCASECMP(pattern, uuid, l1) == 0);
}
PRBool
substring (const char* pattern, const char* data)
{
char *p = RDF_STRCASESTR(data, pattern);
return p != NULL;
}
int16
revCharSearch (const char c, const char* data)
{
char *p = RDF_STRRCHR(data, c);
return p ? p-data : -1;
}
PRBool
urlEquals (const char* url1, const char* url2)
{
int16 n1 = charSearch('#', url1);
int16 n2 = charSearch('#', url2);
if ((n1 == -1) && (n2 == -1)) {
return (RDF_STRCMP(url1, url2) == 0);
} else if ((n2 == -1) && (n1 > 0)) {
return ((RDF_STRLEN(url2) == (size_t)(n1)) && (strncmp(url1, url2, n1) == 0));
} else if ((n1 == -1) && (size_t) (n2 > 0)) {
return ((RDF_STRLEN(url1) == (size_t)(n2)) && (strncmp(url1, url2, n2) == 0));
} else return 0;
}
PRBool
isSeparator (RDF_Resource r)
{
return (startsWith("separator", resourceID(r)) || startsWith("nc:separator", resourceID(r))) ;
}
char *
getBaseURL (const char* url)
{
int n = charSearch('#' , url);
char* ans;
if (n == -1) return copyString(url);
if (n == 0) return NULL;
ans = getMem(n+1);
memcpy(ans, url, n);
return ans;
}
void
setContainerp (RDF_Resource r, PRBool val)
{
if (val) {
r->flags |= CONTAINER_FLAG;
} else {
r->flags &= (~CONTAINER_FLAG);
}
}
PRBool
containerp (RDF_Resource r)
{
return (r->flags & CONTAINER_FLAG);
}
void
setLockedp (RDF_Resource r, PRBool val)
{
if (val) {
r->flags |= LOCKED_FLAG;
} else {
r->flags &= (~LOCKED_FLAG);
}
}
PRBool
lockedp (RDF_Resource r)
{
return (r->flags & LOCKED_FLAG);
}
uint8
resourceType (RDF_Resource r)
{
return r->type;
}
void
setResourceType (RDF_Resource r, uint8 val)
{
r->type = val;
}
char *
resourceID(RDF_Resource r)
{
return r->url;
}
char* opTypeToString (RDF_EventType opType) {
switch (opType) {
case RDF_ASSERT_NOTIFY :
return "Assert";
case RDF_INSERT_NOTIFY :
return "Insert";
case RDF_DELETE_NOTIFY :
return "Unassert";
}
return "Unknown Op";
}
void traceNotify (char* event, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type) {
#ifdef DEBUG_guha1
char* traceLine = getMem(1000);
if (type == RDF_INT_TYPE) {
sprintf(traceLine, "%s %s(%s, %i)\n",
event, resourceID(s), resourceID(u), (int) v);
} else if (type == RDF_STRING_TYPE){
sprintf(traceLine, "%s %s(%s, \"%s\")\n",
event, resourceID(s), resourceID(u), (char*) v);
} else if (type == RDF_RESOURCE_TYPE) {
sprintf(traceLine, "%s %s(%s, %s)\n",
event, resourceID(s), resourceID(u), resourceID((RDF_Resource)v));
} else {
sprintf(traceLine, "%s <gubbish>\n", event);
}
FE_Trace(traceLine);
freeMem(traceLine);
#endif
}
char *
makeResourceName (RDF_Resource node)
{
char *name = NULL;
name = resourceID(node);
if (startsWith("http:", resourceID(node)))
{
name = &name[7];
}
else if (startsWith("file:", resourceID(node)))
{
name = &name[FS_URL_OFFSET];
}
else
{
name = resourceID(node);
}
return ((name != NULL) ? copyString(name) : NULL);
}
PR_PUBLIC_API(char *)
RDF_GetResourceName(RDF rdf, RDF_Resource node)
{
char* name = RDF_GetSlotValue(rdf, node, gCoreVocab->RDF_name, RDF_STRING_TYPE, false, true);
if (name != NULL) return name;
name = makeResourceName(node);
return name;
}
#ifdef MOZILLA_CLIENT
PR_PUBLIC_API(RDF_Resource)
RDFUtil_GetFirstInstance (RDF_Resource type, char* defaultURL)
{
RDF_Resource bmk = remoteStoreGetSlotValue(gLocalStore, type,
gCoreVocab->RDF_instanceOf,
RDF_RESOURCE_TYPE, true, true);
if (bmk == NULL) {
/* bmk = RDF_GetResource(NULL, defaultURL, 1); */
bmk = createContainer(defaultURL);
remoteAssert(gLocalStore, bmk, gCoreVocab->RDF_instanceOf,
type, RDF_RESOURCE_TYPE, 1);
}
return bmk;
}
PR_PUBLIC_API(void)
RDFUtil_SetFirstInstance (RDF_Resource type, RDF_Resource item)
{
RDF_Resource bmk = remoteStoreGetSlotValue(gLocalStore, type,
gCoreVocab->RDF_instanceOf,
RDF_RESOURCE_TYPE, true, true);
if (bmk) {
remoteUnassert(gLocalStore, bmk, gCoreVocab->RDF_instanceOf,
type, RDF_RESOURCE_TYPE);
}
if (item) {
remoteAssert(gLocalStore, item, gCoreVocab->RDF_instanceOf,
type, RDF_RESOURCE_TYPE, true);
}
}
PR_PUBLIC_API(RDF_Resource)
RDFUtil_GetQuickFileFolder()
{
return RDFUtil_GetFirstInstance(gNavCenter->RDF_BookmarkFolderCategory, "NC:Bookmarks");
}
PR_PUBLIC_API(void)
RDFUtil_SetQuickFileFolder(RDF_Resource container)
{
RDFUtil_SetFirstInstance(gNavCenter->RDF_BookmarkFolderCategory, container);
}
RDF_Resource gPTFolder = NULL;
PR_PUBLIC_API(RDF_Resource)
RDFUtil_GetPTFolder()
{
if (gPTFolder) return gPTFolder;
return (gPTFolder = RDFUtil_GetFirstInstance(gNavCenter->RDF_PersonalToolbarFolderCategory, "PersonalToolbar"));
}
PR_PUBLIC_API(void)
RDFUtil_SetPTFolder(RDF_Resource container)
{
/*
RDFUtil_SetFirstInstance( gNavCenter->RDF_PersonalToolbarFolderCategory, container);
*/
}
PR_PUBLIC_API(RDF_Resource)
RDFUtil_GetNewBookmarkFolder()
{
return RDFUtil_GetFirstInstance(gNavCenter->RDF_NewBookmarkFolderCategory, "NC:Bookmarks");
}
PR_PUBLIC_API(void)
RDFUtil_SetNewBookmarkFolder(RDF_Resource container)
{
RDFUtil_SetFirstInstance(gNavCenter->RDF_NewBookmarkFolderCategory, container);
}
PR_PUBLIC_API(RDF_Resource)
RDFUtil_GetDefaultSelectedView()
{
return RDFUtil_GetFirstInstance(gNavCenter->RDF_DefaultSelectedView, "selectedView");
}
PR_PUBLIC_API(void)
RDFUtil_SetDefaultSelectedView(RDF_Resource container)
{
RDFUtil_SetFirstInstance(gNavCenter->RDF_DefaultSelectedView, container);
}
/* Returns a new string with inURL unescaped. */
/* We return a new string because NET_UnEscape unescapes */
/* string in place */
char *
unescapeURL(char *inURL)
{
char *escapedPath = copyString(inURL);
#ifdef MOZILLA_CLIENT
#ifdef XP_WIN
replacePipeWithColon(escapedPath);
#endif
/* xxx NET_UnEscape(escapedPath); */
#endif
return (escapedPath);
}
/* Given a file URL of form "file:///", return substring */
/* that can be used as a path for PR_Open. */
/* NOTE: This routine DOESN'T allocate a new string */
char *
convertFileURLToNSPRCopaceticPath(char* inURL)
{
#ifdef XP_WIN
if (startsWith("file://", inURL)) return (inURL + 8);
else if (startsWith("mailbox:/", inURL)) return (inURL + 9);
else if (startsWith("IMAP:/", inURL)) return (inURL + 6);
else return (inURL);
#else
/* For Mac & Unix, need preceeding '/' so that NSPR */
/* interprets path as full path */
if (startsWith("file://", inURL)) return (inURL + 7);
else if (startsWith("mailbox:/", inURL)) return (inURL + 8);
else if (startsWith("IMAP:/", inURL)) return (inURL + 5);
else return (inURL);
#endif
}
char* MCDepFileURL (char* url) {
char* furl;
int32 len;
char* baz = "\\";
int32 n = 0;
furl = convertFileURLToNSPRCopaceticPath(unescapeURL(url));
len = RDF_STRLEN(furl);
#ifdef XP_WIN
while (n < len) {
if (furl[n] == '/') furl[n] = baz[0];
n++;
}
#endif
return furl;
}
PRFileDesc *
CallPROpenUsingFileURL(char *fileURL, PRIntn flags, PRIntn mode)
{
PRFileDesc* result = NULL;
const char *path;
char *escapedPath = unescapeURL(fileURL);
path = convertFileURLToNSPRCopaceticPath(escapedPath);
if (path != NULL) {
result = PR_Open(path, flags, mode);
}
if (escapedPath != NULL) freeMem(escapedPath);
return result;
}
PRDir *
CallPROpenDirUsingFileURL(char *fileURL)
{
PRDir* result = NULL;
const char *path;
char *escapedPath = unescapeURL(fileURL);
path = convertFileURLToNSPRCopaceticPath(escapedPath);
if (path != NULL) {
result = PR_OpenDir(path);
}
if (escapedPath != NULL) freeMem(escapedPath);
return result;
}
int32
CallPRWriteAccessFileUsingFileURL(char *fileURL)
{
int32 result = -1;
const char *path;
char *escapedPath = unescapeURL(fileURL);
path = convertFileURLToNSPRCopaceticPath(escapedPath);
if (path != NULL) {
result = PR_Access(path, PR_ACCESS_WRITE_OK);
}
if (escapedPath != NULL) freeMem(escapedPath);
return result;
}
int32
CallPRDeleteFileUsingFileURL(char *fileURL)
{
int32 result = -1;
const char *path;
char *escapedPath = unescapeURL(fileURL);
path = convertFileURLToNSPRCopaceticPath(escapedPath);
if (path != NULL) {
result = PR_Delete(path);
}
if (escapedPath != NULL) freeMem(escapedPath);
return result;
}
int
CallPR_RmDirUsingFileURL(char *dirURL)
{
int32 result=-1;
const char *path;
char *escapedPath = unescapeURL(dirURL);
path = convertFileURLToNSPRCopaceticPath(escapedPath);
if (path != NULL) {
result = PR_RmDir(path);
}
if (escapedPath != NULL) freeMem(escapedPath);
return result;
}
int32
CallPRMkDirUsingFileURL(char *dirURL, int mode)
{
int32 result=-1;
const char *path;
char *escapedPath = unescapeURL(dirURL);
path = convertFileURLToNSPRCopaceticPath(escapedPath);
if (path != NULL) {
result = PR_MkDir(path,mode);
}
if (escapedPath != NULL) freeMem(escapedPath);
return result;
}
#endif /* MOZILLA_CLIENT */

View File

@@ -0,0 +1,89 @@
/* -*- 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_UTILS_H_
#define _RDF_UTILS_H_
#include "rdf.h"
#include "rdf-int.h"
#include "htrdf.h"
#include "prprf.h"
#include <stdarg.h>
#include <ctype.h>
/* utils.c data structures and defines */
#define CONTAINER_FLAG 0x01
#define LOCKED_FLAG 0x02
/* utils.c function prototypes */
RDF_Resource getMCFFrtop (char* furl);
void addToResourceList (RDFFile f, RDF_Resource u);
void addToAssertionList (RDFFile f, Assertion as);
void removeFromAssertionList(RDFFile f, Assertion as);
void ht_fprintf(PRFileDesc *file, const char *fmt, ...);
void ht_rjcprintf(PRFileDesc *file, const char *fmt, const char *data);
char * makeDBURL(char* name);
PLHashNumber idenHash (const void *key);
int idenEqual (const void *v1, const void *v2);
PRBool inverseTV (PRBool tv);
char * append2Strings (const char* str1, const char* str2);
void stringAppendBase (char* dest, const char* addition);
void stringAppend (char* dest, const char* addition);
int16 charSearch (const char c, const char* data);
PRBool endsWith (const char* pattern, const char* uuid);
PRBool substring (const char* pattern, const char* data);
int compareStrings(char *s1, char *s2);
int16 revCharSearch (const char c, const char* data);
PRBool urlEquals (const char* url1, const char* url2);
PRBool isSeparator (RDF_Resource r);
void setContainerp (RDF_Resource r, PRBool val);
PRBool containerp (RDF_Resource r);
uint8 resourceType (RDF_Resource r);
void setResourceType (RDF_Resource r, uint8 val);
char * resourceID(RDF_Resource r);
char * makeResourceName (RDF_Resource node);
char* opTypeToString (RDF_EventType opType) ;
void traceNotify (char* event, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type) ;
PRBool IsUTF8Text(const char* utf8, int32 len);
PRBool IsUTF8String(const char* utf8);
void AddCookieResource(char* name, char* path, char* host, char* expires);
void RDF_ReadCookies(char * filename);
PRBool CookieUnassert (RDFT r, RDF_Resource u, RDF_Resource s, void* v, RDF_ValueType type);
RDF_Cursor CookieGetSlotValues(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
void * CookieGetNextValue(RDFT rdf, RDF_Cursor c);
RDF_Error CookieDisposeCursor(RDFT rdf, RDF_Cursor c);
PRBool CookieAssert(RDFT rdf, RDF_Resource u, RDF_Resource s, void *v, RDF_ValueType type, PRBool tv);
void * CookieGetSlotValue(RDFT rdf, RDF_Resource u, RDF_Resource s, RDF_ValueType type, PRBool inversep, PRBool tv);
#endif

View File

@@ -0,0 +1,338 @@
/* -*- 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 a standard vocabulary 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 "vocabint.h"
#include "bmk2mcf.h"
/* globals */
#ifdef XP_MAC
#pragma export on
#endif
RDF_WDVocab gWebData = NULL;
RDF_NCVocab gNavCenter = NULL;
RDF_CoreVocab gCoreVocab = NULL;
#ifdef XP_MAC
#pragma export off
#endif
size_t gCoreVocabSize = 0;
RDF_Resource* gAllVocab;
/* externs */
extern char* gLocalStoreURL;
extern char* profileDirURL;
RDF gCoreDB = 0;
void
createVocabs ()
{
size_t n = 0;
size_t m = 0;
gAllVocab = getMem((gCoreVocabSize =
sizeof(RDF_CoreVocabStruct)+sizeof(RDF_NCVocabStruct)+sizeof(RDF_WDVocabStruct)));
gCoreDB = (RDF)getMem(sizeof(struct RDF_DBStruct));
createCoreVocab();
createNavCenterVocab();
createWebDataVocab();
while (n < (sizeof(RDF_CoreVocabStruct)/sizeof(RDF_Resource))) {
*(gAllVocab + m++) = *((RDF_Resource*)gCoreVocab + n++);
}
n = 0;
while (n < (sizeof(RDF_NCVocabStruct)/sizeof(RDF_Resource))) {
*(gAllVocab + m++) = *((RDF_Resource*)gNavCenter + n++);
}
n = 0;
while (n < (sizeof(RDF_WDVocabStruct)/sizeof(RDF_Resource))) {
*(gAllVocab + m++) = *((RDF_Resource*)gWebData + n++);
}
}
void
createCoreVocab ()
{
gCoreVocab = (RDF_CoreVocab) getMem(sizeof(RDF_CoreVocabStruct));
gCoreVocab->RDF_parent = RDF_GetResource(gCoreDB, "parent", 1);
gCoreVocab->RDF_name = RDF_GetResource(gCoreDB, "name", 1);
gCoreVocab->RDF_instanceOf = RDF_GetResource(gCoreDB, "instanceOf", 1);
gCoreVocab->RDF_subClassOf = RDF_GetResource(gCoreDB, "subClassOf", 1);
gCoreVocab->RDF_Class = RDF_GetResource(gCoreDB, "Class", 1);
gCoreVocab->RDF_PropertyType = RDF_GetResource(gCoreDB, "PropertyType", 1);
gCoreVocab->RDF_slotsHere = RDF_GetResource(gCoreDB, "slotsHere", 1);
gCoreVocab->RDF_slotsIn = RDF_GetResource(gCoreDB, "slotsIn", 1);
gCoreVocab->RDF_domain = RDF_GetResource(gCoreDB, "domain", 1);
gCoreVocab->RDF_range = RDF_GetResource(gCoreDB, "range", 1);
gCoreVocab->RDF_StringType = RDF_GetResource(gCoreDB, "String", 1);
gCoreVocab->RDF_IntType = RDF_GetResource(gCoreDB, "Int", 1);
gCoreVocab->RDF_equals = RDF_GetResource(gCoreDB, "equals", 1);
gCoreVocab->RDF_lessThan = RDF_GetResource(gCoreDB, "lessThan", 1);
gCoreVocab->RDF_greaterThan = RDF_GetResource(gCoreDB, "greaterThan", 1);
gCoreVocab->RDF_lessThanOrEqual = RDF_GetResource(gCoreDB, "lessThanOrEqualTo", 1);
gCoreVocab->RDF_greaterThanOrEqual = RDF_GetResource(gCoreDB, "greaterThanOrEqualTo", 1);
gCoreVocab->RDF_stringEquals = newResource("stringEquals", RDF_IS_STR);
gCoreVocab->RDF_stringNotEquals = newResource("stringNotEquals", RDF_IS_NOT_STR);
gCoreVocab->RDF_substring = newResource("substring", RDF_CONTAINS_STR);
gCoreVocab->RDF_stringStartsWith = newResource("stringStartsWith", RDF_STARTS_WITH_STR);
gCoreVocab->RDF_stringEndsWith = newResource("stringEndsWith", RDF_ENDS_WITH_STR);
gCoreVocab->RDF_child = RDF_GetResource(gCoreDB, "child", 1);
gCoreVocab->RDF_content = RDF_GetResource(gCoreDB, "content", 1);
gCoreVocab->RDF_summary = RDF_GetResource(gCoreDB, "summary", 1);
gCoreVocab->RDF_comment = RDF_GetResource(gCoreDB, "comment", 1);
}
void
createNavCenterVocab () {
gNavCenter = (RDF_NCVocab) getMem(sizeof(RDF_NCVocabStruct));
#ifdef MOZILLA_CLIENT
gNavCenter->RDF_overview = RDF_GetResource(gCoreDB, "overview", 1);
gNavCenter->RDF_Trash = createContainer("Trash");
gNavCenter->RDF_Clipboard = createContainer("Clipboard");
gNavCenter->RDF_Top = createContainer("NC:NavCenter");
setResourceType(gNavCenter->RDF_Top, RDF_RT);
gNavCenter->RDF_Search = createContainer("NC:Search");
setResourceType(gNavCenter->RDF_Search, SEARCH_RT);
gNavCenter->RDF_Sitemaps = createContainer("NC:Sitemaps");
gNavCenter->RDF_BreadCrumbCategory = createContainer("BreadCrumbs");
gNavCenter->RDF_BookmarkFolderCategory = createContainer("NC:Bookmarks");
gNavCenter->RDF_NewBookmarkFolderCategory = RDF_GetResource(gCoreDB, "NewBookmarks", true);
gNavCenter->RDF_History = createContainer("NC:History");
gNavCenter->RDF_HistoryBySite = createContainer("NC:HistoryBySite");
gNavCenter->RDF_HistoryByDate = createContainer("NC:HistoryByDate");
gNavCenter->RDF_HistoryMostVisited = createContainer("NC:HistoryMostVisited");
setResourceType(gNavCenter->RDF_History, HISTORY_RT);
setResourceType(gNavCenter->RDF_HistoryBySite, HISTORY_RT);
setResourceType(gNavCenter->RDF_HistoryByDate, HISTORY_RT);
setResourceType(gNavCenter->RDF_HistoryMostVisited, HISTORY_RT);
/* IE items */
gNavCenter->RDF_IEBookmarkFolderCategory = createContainer("NC:IEBookmarks");
gNavCenter->RDF_IEHistory = createContainer("NC:IEHistory");
setResourceType(gNavCenter->RDF_IEHistory, HISTORY_RT);
gNavCenter->RDF_bookmarkAddDate = newResource("bookmarkAddDate", RDF_ADDED_ON_STR);
gNavCenter->RDF_PersonalToolbarFolderCategory =
RDF_GetResource(gCoreDB, "PersonalToolbarCat", true);
gNavCenter->RDF_Column = RDF_GetResource(gCoreDB, "Column", true);
gNavCenter->RDF_ColumnResource = RDF_GetResource(gCoreDB, "ColumnResource", true);
gNavCenter->RDF_ColumnWidth = RDF_GetResource(gCoreDB, "ColumnWidth", true);
gNavCenter->RDF_ColumnIconURL = RDF_GetResource(gCoreDB, "ColumnIconURL", true);
gNavCenter->RDF_ColumnDataType = RDF_GetResource(gCoreDB, "ColumnDataType", true);
gNavCenter->RDF_smallIcon = newResource("smallIcon", RDF_ICON_URL_STR);
gNavCenter->RDF_largeIcon = newResource("largeIcon", RDF_LARGE_ICON_URL_STR);
gNavCenter->RDF_HTMLURL = newResource("htmlURL", RDF_HTML_URL_STR);
gNavCenter->RDF_HTMLHeight = newResource("htmlHeight", RDF_HTML_HEIGHT_STR);
gNavCenter->RDF_LocalFiles = createContainer("NC:LocalFiles");
/* setResourceType(gNavCenter->RDF_LocalFiles, LFS_RT); */
gNavCenter->RDF_FTP = createContainer("NC:FTP");
gNavCenter->RDF_FTP = newResource("NC:FTP", RDF_FTP_NAME_STR);
gNavCenter->RDF_Appletalk = createContainer("NC:Appletalk");
gNavCenter->RDF_Appletalk = newResource("NC:Appletalk", RDF_APPLETALK_TOP_NAME);
setResourceType(gNavCenter->RDF_Appletalk, ATALKVIRTUAL_RT);
gNavCenter->RDF_Mail = RDF_GetResource(gCoreDB, "NC:Mail", true);
gNavCenter->RDF_Guide = RDF_GetResource(gCoreDB, "NC:Guide", true);
gNavCenter->RDF_Password = RDF_GetResource(gCoreDB, "password", true);
gNavCenter->RDF_SBProviders = RDF_GetResource(gCoreDB, "NC:SmartBrowsingProviders", true);
gNavCenter->RDF_WorkspacePos = RDF_GetResource(gCoreDB, "workspacePos", true);
gNavCenter->RDF_ItemPos = RDF_GetResource(gCoreDB, "pos", true);
gNavCenter->RDF_Locks = RDF_GetResource(gCoreDB, "locks", true);
gNavCenter->RDF_AddLock = RDF_GetResource(gCoreDB, "addLock", true);
gNavCenter->RDF_DeleteLock = RDF_GetResource(gCoreDB, "deleteLock", true);
gNavCenter->RDF_IconLock = RDF_GetResource(gCoreDB, "iconLock", true);
gNavCenter->RDF_NameLock = RDF_GetResource(gCoreDB, "nameLock", true);
gNavCenter->RDF_CopyLock = RDF_GetResource(gCoreDB, "copyLock", true);
gNavCenter->RDF_MoveLock = RDF_GetResource(gCoreDB, "moveLock", true);
gNavCenter->RDF_WorkspacePosLock = RDF_GetResource(gCoreDB, "workspacePosLock", true);
gNavCenter->RDF_DefaultSelectedView = RDF_GetResource(gCoreDB, "selectedView", true);
gNavCenter->RDF_AutoOpen = RDF_GetResource(gCoreDB, "autoOpen", true);
gNavCenter->RDF_resultType = RDF_GetResource (gCoreDB, "resultType", true);
gNavCenter->RDF_methodType = RDF_GetResource (gCoreDB, "methodType", true);
gNavCenter->RDF_prompt = RDF_GetResource (gCoreDB, "prompt", true);
gNavCenter->RDF_HTMLType = RDF_GetResource (gCoreDB, "HTMLPage", true);
gNavCenter->RDF_URLShortcut = RDF_GetResource(gCoreDB, "URLShortcut", true);
gNavCenter->RDF_Poll = RDF_GetResource(gCoreDB, "poll", true);
gNavCenter->RDF_PollInterval = RDF_GetResource(gCoreDB, "pollInterval", true);
gNavCenter->RDF_PollURL = RDF_GetResource(gCoreDB, "pollURL", true);
gNavCenter->RDF_Cookies = createContainer("NC:Cookies");
setResourceType(gNavCenter->RDF_Cookies, COOKIE_RT);
gNavCenter->RDF_Toolbar = createContainer("NC:Toolbar");
gNavCenter->RDF_JSec = createContainer("NC:Jsec");
gNavCenter->RDF_JSecPrincipal = RDF_GetResource(gCoreDB, "JsecPrincipal", true);
gNavCenter->RDF_JSecTarget = RDF_GetResource(gCoreDB, "JsecTarget", true);
gNavCenter->RDF_JSecAccess = RDF_GetResource(gCoreDB, "JsecAccess", true);
/* Commands */
gNavCenter->RDF_Command = RDF_GetResource (gCoreDB, "Command", true);
gNavCenter->RDF_Command_Launch = RDF_GetResource(gCoreDB, "Command:Launch", true);
gNavCenter->RDF_Command_Refresh = RDF_GetResource(gCoreDB, "Command:Refresh", true);
gNavCenter->RDF_Command_Reveal = RDF_GetResource(gCoreDB, "Command:Reveal", true);
gNavCenter->RDF_Command_Atalk_FlatHierarchy = RDF_GetResource(gCoreDB, "Command:at:View Zone List", true);
gNavCenter->RDF_Command_Atalk_Hierarchy = RDF_GetResource(gCoreDB, "Command:at:View Zone Hierarchy", true);
/* NavCenter appearance styles */
gNavCenter->viewFGColor = newResource("viewFGColor", RDF_FOREGROUND_COLOR_STR);
gNavCenter->viewBGColor = newResource("viewBGColor", RDF_BACKGROUND_COLOR_STR);
gNavCenter->viewBGURL = newResource("viewBGURL", RDF_BACKGROUND_IMAGE_STR);
gNavCenter->showTreeConnections = newResource("showTreeConnections", RDF_SHOW_TREE_CONNECTIONS_STR);
gNavCenter->treeConnectionFGColor = newResource("treeConnectionFGColor", RDF_CONNECTION_FG_COLOR_STR);
gNavCenter->treeOpenTriggerIconURL = newResource("treeOpenTriggerIconURL", RDF_OPEN_TRIGGER_IMAGE_STR);
gNavCenter->treeClosedTriggerIconURL = newResource("treeClosedTriggerIconURL", RDF_CLOSED_TRIGGER_IMAGE_STR);
gNavCenter->selectionFGColor = newResource("selectionFGColor", RDF_FOREGROUND_COLOR_STR);
gNavCenter->selectionBGColor = newResource("selectionBGColor", RDF_BACKGROUND_COLOR_STR);
gNavCenter->columnHeaderFGColor = newResource("columnHeaderFGColor", RDF_FOREGROUND_COLOR_STR);
gNavCenter->columnHeaderBGColor = newResource("columnHeaderBGColor", RDF_BACKGROUND_COLOR_STR);
gNavCenter->columnHeaderBGURL = newResource("columnHeaderBGURL", RDF_BACKGROUND_IMAGE_STR);
gNavCenter->showColumnHeaders = newResource("showColumnHeaders", RDF_SHOW_HEADERS_STR);
gNavCenter->showColumnHeaderDividers = newResource("showColumnHeaderDividers", RDF_SHOW_HEADER_DIVIDERS_STR);
gNavCenter->sortColumnFGColor = newResource("sortColumnFGColor", RDF_SORT_COLUMN_FG_COLOR_STR);
gNavCenter->sortColumnBGColor = newResource("sortColumnBGColor", RDF_SORT_COLUMN_BG_COLOR_STR);
gNavCenter->titleBarFGColor = newResource("titleBarFGColor", RDF_FOREGROUND_COLOR_STR);
gNavCenter->titleBarBGColor = newResource("titleBarBGColor", RDF_BACKGROUND_COLOR_STR);
gNavCenter->titleBarBGURL = newResource("titleBarBGURL", RDF_BACKGROUND_IMAGE_STR);
gNavCenter->dividerColor = newResource("dividerColor", RDF_DIVIDER_COLOR_STR);
gNavCenter->showDivider = newResource("showDivider", RDF_SHOW_COLUMN_DIVIDERS_STR);
gNavCenter->selectedColumnHeaderFGColor = newResource("selectedColumnHeaderFGColor", RDF_SELECTED_HEADER_FG_COLOR_STR);
gNavCenter->selectedColumnHeaderBGColor = newResource("selectedColumnHeaderBGColor", RDF_SELECTED_HEADER_BG_COLOR_STR);
gNavCenter->showColumnHilite = newResource("showColumnHilite", RDF_SHOW_COLUMN_HILITING_STR);
gNavCenter->triggerPlacement = newResource("triggerPlacement", RDF_TRIGGER_PLACEMENT_STR);
/* NavCenter behavior properties */
gNavCenter->useInlineEditing = newResource("useInlineEditing", 0 /* XXX */);
gNavCenter->useSingleClick = newResource("useSingleClick", 0 /* XXX */);
gNavCenter->loadOpenState = newResource("loadOpenState", 0 /* XXX */);
gNavCenter->saveOpenState = newResource("saveOpenState", 0 /* XXX */);
/* Toolbars */
/* Toolbar Appearance Styles */
gNavCenter->toolbarBitmapPosition = newResource("toolbarBitmapPosition", 0 /* XXX "Toolbar Bitmap Position" */ );
gNavCenter->toolbarButtonsFixedSize = newResource("toolbarButtonsFixedSize", 0 /* XXX "Toolbar Bitmap Position" */ );
gNavCenter->toolbarDisplayMode = newResource("toolbarDisplayMode", 0);
gNavCenter->toolbarCollapsed = newResource("toolbarCollapsed", 0);
gNavCenter->toolbarVisible = newResource("toolbarVisible", 0);
gNavCenter->toolbarDisabledIcon = newResource("toolbarDisabledIcon", 0 /* XXX */);
gNavCenter->toolbarEnabledIcon = newResource("toolbarEnabledIcon", 0 /* XXX */);
gNavCenter->toolbarRolloverIcon = newResource("toolbarRolloverIcon", 0 /* XXX */);
gNavCenter->toolbarPressedIcon = newResource("toolbarPressedIcon", 0 /* XXX */);
gNavCenter->buttonTooltipText = newResource("buttonTooltipText", 0 /* XXX */);
gNavCenter->buttonStatusbarText = newResource("buttonStatusbarText", 0 /* XXX */);
gNavCenter->buttonBorderStyle = newResource("buttonBorderStyle", 0 /* XXX */);
gNavCenter->urlBar = newResource("urlBar", 0 /* XXX */);
gNavCenter->urlBarWidth = newResource("urlBarWidth", 0 /* XXX */);
gNavCenter->pos = newResource("pos", 0 /* XXX */);
gNavCenter->viewRolloverColor = newResource("viewRolloverColor", 0 /* XXX */);
gNavCenter->viewPressedColor = newResource("viewPressedColor", 0 /* XXX */);
gNavCenter->viewDisabledColor = newResource("viewDisabledColor", 0 /* XXX */);
gNavCenter->controlStripFGColor = newResource("controlStripFGColor", 0 /* XXX */);
gNavCenter->controlStripBGColor = newResource("controlStripBGColor", 0 /* XXX */);
gNavCenter->controlStripBGURL = newResource("controlStripBGURL", 0 /* XXX */);
gNavCenter->controlStripCloseText = newResource("controlStripCloseText", 0 /* XXX */);
gNavCenter->titleBarShowText = newResource("titleBarShowText", 0 /* XXX */);
gNavCenter->showTitleBar = newResource("showTitleBar", 0 /* XXX */);
gNavCenter->showControlStrip = newResource("showControlStrip", 0 /* XXX */);
/* Buttons */
gNavCenter->buttonTreeState = newResource("buttonTreeState", 0 /* XXX */);
/* Cookies */
gNavCenter->cookieDomain = newResource("cookieDomain", 0 /* XXX */);
gNavCenter->cookieValue = newResource("cookieValue", 0 /* XXX */);
gNavCenter->cookieHost = newResource("cookieHost", 0 /* XXX */);
gNavCenter->cookiePath = newResource("cookiePath", 0 /* XXX */);
gNavCenter->cookieSecure = newResource("cookieSecure", 0 /* XXX */);
gNavCenter->cookieExpires = newResource("cookieExpiration", 0 /* XXX */);
gNavCenter->from = newResource("mail:From", 0 );
gNavCenter->to = newResource("mail:To", 0 );
gNavCenter->subject = newResource("mail:Subject", 0 /* XXX */);
gNavCenter->date = newResource("mail:Date", 0 /* XXX */);
gNavCenter->displayURL = newResource("displayURL", 0 /* XXX */);
remoteStoreAdd(gRemoteStore, gNavCenter->from, gCoreVocab->RDF_name, copyString("from"), RDF_STRING_TYPE, 1);
remoteStoreAdd(gRemoteStore, gNavCenter->to, gCoreVocab->RDF_name, copyString("to"), RDF_STRING_TYPE, 1);
remoteStoreAdd(gRemoteStore, gNavCenter->subject, gCoreVocab->RDF_name, copyString("subject"), RDF_STRING_TYPE, 1);
remoteStoreAdd(gRemoteStore, gNavCenter->date, gCoreVocab->RDF_name, copyString("date"), RDF_STRING_TYPE, 1);
#endif /* MOZILLA_CLIENT */
}
void
createWebDataVocab ()
{
gWebData = (RDF_WDVocab) getMem(sizeof(RDF_WDVocabStruct));
#ifdef MOZILLA_CLIENT
gWebData->RDF_URL = newResource("URL", RDF_URL_STR);
gWebData->RDF_description = newResource("description", RDF_DESCRIPTION_STR);
gWebData->RDF_keyword = newResource("keyword", 0 /* XXX */);
gWebData->RDF_Container = RDF_GetResource (gCoreDB, "Container", true);
gWebData->RDF_firstVisitDate = newResource("firstVisitDate", RDF_FIRST_VISIT_STR);
gWebData->RDF_lastVisitDate = newResource("lastVisitDate", RDF_LAST_VISIT_STR);
gWebData->RDF_numAccesses = newResource("numAccesses", RDF_NUM_ACCESSES_STR);
gWebData->RDF_creationDate = newResource("creationDate", RDF_CREATED_ON_STR);
gWebData->RDF_lastModifiedDate = newResource("lastModifiedDate", RDF_LAST_MOD_STR);
gWebData->RDF_size = newResource("size", RDF_SIZE_STR);
#endif /* MOZILLA_CLIENT */
}
RDF_Resource
newResource(char *id, int optionalNameStrID)
{
RDF_Resource r;
r = RDF_GetResource(gCoreDB, id, true);
return(r);
}
char *
getResourceDefaultName(RDF_Resource node)
{
int strID = 0;
char *defaultName = NULL;
return resourceID(node);
}
char *gDefaultNavcntr =
"<RDF:RDF> <Topic id=\"NC:Toolbar\"> <child> <Topic id=\"NC:CommandToolBar\" name=\"Command Toolbar\" toolbarBitmapPosition=\"top\" toolbarButtonsFixedSize=\"yes\" > <child href=\"command:back\" name=\"Back\"/> <child buttonTooltipText=\"Reload this page from the server\" buttonStatusbarText=\"Reload the current page\" href=\"command:reload\" name=\"Reload\"/> <child href=\"command:stop\" name=\"Stop\"/> <child href=\"command:forward\" name=\"Forward\"/> <child name=\"separator0\" href=\"nc:separator0\"/> <child href=\"command:urlbar\" name=\" \" buttonStatusBarText=\"Location/Search Bar\" buttonTooltipText=\"Location/Search Bar\" urlBar=\"Yes\" urlBarWidth=\"*\"/> <child name=\"separator2\" href=\"nc:separator2\"/> </Topic> </child> <child> <Topic id=\"NC:InfoToolbar\" name=\"Info Toolbar\"> <child> <Topic id=\"NC:Bookmarks\" name=\"Bookmarks\"></Topic> </child> <child> <Topic id=\"NC:History\" largeIcon=\"icon/large:workspace,history\" name=\"History\"> <child href=\"NC:HistoryMostVisited\" name=\"Most Frequented Pages\"/> <child href=\"NC:HistoryBySite\" name=\"History By Site\"/> <child href=\"NC:HistoryByDate\" name=\"History By Date\"/> </Topic> </child> <child href=\"NC:Sitemaps\" name=\"Related\" htmlURL=\"http://rdf.netscape.com/rdf/navcntradvert.html\"/> </Topic> </child> <child> <Topic id=\"NC:PersonalToolbar\" name=\"Personal Toolbar\"> </Topic> </child> </Topic> <Topic id=\"NC:NavCenter\"> <child href=\"NC:Bookmarks\" name=\"Bookmarks\"/> <child href=\"NC:Search\" largeIcon=\"icon/large:workspace,search\" name=\"Search\"/> <child href=\"NC:History\" name=\"History\"/> <child id=\"NC:Sitemaps\" name=\"Site Tools\" htmlURL=\"http://rdf.netscape.com/rdf/navcntradvert.html\" /> <child id=\"NC:LocalFiles\" name=\"Files\" largeIcon=\"http://rdf.netscape.com/rdf/heabou.gif\"/> </Topic></RDF:RDF>" ;

View File

@@ -0,0 +1,56 @@
/* -*- 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_VOCABINT_H_
#define _RDF_VOCABINT_H_
#include "rdf-int.h"
#include "htrdf.h"
/* vocab.c data structures */
extern int RDF_FOREGROUND_COLOR_STR, RDF_BACKGROUND_COLOR_STR, RDF_BACKGROUND_IMAGE_STR;
extern int RDF_SHOW_TREE_CONNECTIONS_STR, RDF_CONNECTION_FG_COLOR_STR, RDF_OPEN_TRIGGER_IMAGE_STR;
extern int RDF_CLOSED_TRIGGER_IMAGE_STR, RDF_SHOW_HEADERS_STR, RDF_SHOW_HEADER_DIVIDERS_STR;
extern int RDF_SORT_COLUMN_FG_COLOR_STR, RDF_SORT_COLUMN_BG_COLOR_STR, RDF_DIVIDER_COLOR_STR;
extern int RDF_SHOW_COLUMN_DIVIDERS_STR, RDF_SELECTED_HEADER_FG_COLOR_STR, RDF_SELECTED_HEADER_BG_COLOR_STR;
extern int RDF_SHOW_COLUMN_HILITING_STR, RDF_TRIGGER_PLACEMENT_STR, RDF_URL_STR;
extern int RDF_DESCRIPTION_STR, RDF_FIRST_VISIT_STR, RDF_LAST_VISIT_STR, RDF_NUM_ACCESSES_STR;
extern int RDF_CREATED_ON_STR, RDF_LAST_MOD_STR, RDF_SIZE_STR, RDF_ADDED_ON_STR, RDF_ICON_URL_STR;
extern int RDF_LARGE_ICON_URL_STR, RDF_HTML_URL_STR, RDF_HTML_HEIGHT_STR;
extern int RDF_CONTAINS_STR, RDF_IS_STR, RDF_IS_NOT_STR, RDF_STARTS_WITH_STR, RDF_ENDS_WITH_STR;
extern int RDF_FTP_NAME_STR, RDF_APPLETALK_TOP_NAME;
/* vocab.c function prototypes */
NSPR_BEGIN_EXTERN_C
void createVocabs ();
void createCoreVocab ();
void createNavCenterVocab ();
void createWebDataVocab ();
RDF_Resource newResource(char *id, int optionalNameStrID);
char *getResourceDefaultName(RDF_Resource r);
NSPR_END_EXTERN_C
#endif

View File

@@ -1,46 +0,0 @@
Mstone building instructions
For Unix, just "gmake" one of these
release The usual optimized build
debug Debug build includes some asserts
rpackage Build the release and package it
dpackage Build the debug version and package it
all_OPT Build a multi-platform package
all_DBG Build a multi-platform debug package
For NT, run autobuild.bat. This will build and package both the debug
and optimized versions. Perl must already be built and installed in
\. The NT build may be behind the Unix stuff. Pull the build/package/*
subdirectories into the main build/package before doing a 'make all_???'.
You can build multiple OSes in the same tree. Debug and optimized
builds are kept separately. The all_??? targets will combine whatever
OSes are present into a multi-architecture package (including NT).
Note that you have ot build and package each OS before doing the all_
step.
Helper components
Linux usually comes with workable versions of gnuplot and perl. Most
other OSes don't. Mstone can build and package perl, gnuplot, and gd
with the right settings. These will be automatically built and
packaged if they are present.
Unpack gd1.3 or later in the mstone directory. You can probably find
gd from here: http://www.boutell.com/gd/. The directory should look
like gd?.*. Right now we need the (obsolete) version 1.3 to generate
GIF files (without patented run-length coding). The scripts need to
be updated to be able to handle PNG or GIF files.
Unpack gnuplot 3.7 or later in the mstone directory. You can probably
find gnuplot from http://www.cs.dartmouth.edu/gnuplot_info.html. The
directory should look like gnuplot-?.* (the exact version should not
matter). Gnuplot requres gd to generate GIFs (which is what we need).
Unpack perl 5.005 or later in the mstone directory. You can probably
find perl from http://www.perl.com/pub/language/info/software.html.
The directory should look like perl5.* (the exact version should
not matter).

View File

@@ -1,73 +0,0 @@
2005-02-19 Dan Christian <robodan@idiom.com>
* Merge big Sendmail patch see ChangeLog-Sendmail for details
* src/bench.h (VERSION): Start working toward version 5.0 (now 4.9)
2004-09-07 Dan Christian <robodan@idiom.com>
* data/*.msg: Updated with more realistic messages
* bin/args.pl: Really fix doc link to be relative
* src/smtp.c (sendSMTPLoop): Handle file lists (random selection)
(sendFile): New, send file with option offset and head/tail
(SmtpFilePrep): Split a glob pattern to a list
(SmtpFileInit): New, split out initial file scan
* src/bench.c (rangeNext): Get to last value in a random range
2004-06-14 Dan Christian <robodan@idiom.com>
* Makefile (VERSION): Bump version to 4.3
* Make build work on recent versions of Linux and Solaris
* Make ssh the default way to get a remote shell
* Support SVG graph output (not supported by all browsers)
* Use rfc822 style from addresses
* Fix documentation link on index page to be local
2000-04-28 Dan Christian <dac@x.cx>
* http and wmap now use common routines from http-util
* http is now separated from the pish command structure.
2000-04-27 Dan Christian <dac@x.cx>
* bin/genplot.pl: Support gnuplot generating images other than gif
* src/smtp.c (sendSMTPStart): Send domain name with HELO
2000-04-05 Dan Christian <robodan@netscape.com>
* Fix bug in WMAP where the login field was reporting banner data.
* Add a reconnect concept to WMAP. This separates out the
reconnect activity from the initial connections. There is still a
bug/feature that the reconnect increments an error which can
eventually hit the maxErrors limit. You have to record the error
or else you could not get the "connections" graph right.
2000-03-31 Dan Christian <robodan@netscape.com>
* Merged setup and mstone into one script to reduce command
namespace polution. "mstone setup" is the the same as "setup".
* Made setup try to be more tolerant of OSes that were not
include in the distribution. SunOS 5.7 will fall back to 5.6.
* Now package conf/general.wld.in and only copy to general.wld if
there isn't one already in place. This means that you can unpack
new bits over old bits without blowing away your configuration.
* Added <includeOnce file> command to workloads. This allows
tests to be used either as a stand alone or as part of another
test (e.g. smtp).
* Converted ChangeLog to more common formating
* Spilt off old ChangeLog entries to ChangeLog.1 and ChangeLog.2

View File

@@ -1,86 +0,0 @@
2005-02-03 Thom O'Connor <thom@sendmail.com>
* Merge Mozilla mstone HEAD with Sendmail,Inc. modifications. In
particular, this included some hand-waving around the bitwise
operators "leaveMailOnServer" in the Mozilla branch and the
dinst_t struct pish->leaveMailOnServerDist.
2005-01-25 Thom O'Connor <thom@sendmail.com>
* Fix comments, properly attribute Sean O'Rourke's contributions.
2004-09-21 Thom O'Connor <thom@sendmail.com>
* Modified config/config.mk to build SSL version of mailclient.
2004-06-07 Thom O'Connor <thom@sendmail.com>
* Remove _thread_sys_poll defininition for poll in FreeBSD builds
(bench.h).
2001-04-27 Sean O'Rourke <sean@sendmail.com>
* distributions can now be truncated. This is used to prevent
0-recipient messages, and could be used to prevent enormous
messages.
* throttling: Preload workloads use some additional mstone magic
to throttle delivery rate based on server responsiveness. This is
still in the experimental phase, and may change.
* fix for parsing bug exposed by distribution truncation notation.
2001-03-10 Sean O'Rourke <sean@sendmail.com>
* clients: Fixed up code for specifying client counts on a
per-host or per-group basis. This eliminates the need to force
the mozilla distribution code to do one's bidding.
* smtpsink.pl: Very basic threaded perl SMTP sink. This may go
away to be replaced by the sink from smtpslam. Needs much better
statistics.
2001-02-24 Sean O'Rourke <sean@sendmail.com>
* checksums added. See {checksum,md5}.{c,h}. Auto-generated
messages can currently have checksums computed over the body, and
pop and multipop retrieval will verify the sum.
2001-02-21 Sean O'Rourke <sean@sendmail.com>
* MIME generation changed to generate deep messages rather than
several parts. This should be a better test of MIME parsers,
forcing them to save more state.
2001-02-18 Sean O'Rourke <sean@sendmail.com>
* mstone_changes.html: update SSL documentation.
* wld, defaults.pm: divide the ever-expanding "config" section
into more descriptive subparts: clients, server, sink, mstone.
* report: now in bin directory, where it should be.
2001-02-17 Sean O'Rourke <sean@sendmail.com>
* client.c, main.c, parse.c: removed old throttling code, as it
wasn't being used.
* ALL: General code cleanup.
* sysdep.c: simplified rlimit-bumping code, added increase for
RLIM_NPROC, as threads are procs on some systems.
* imap4.c: removed silliness of malloc()ing a buffer the size of
the entire message every time we retrieve a message.
* xalloc.c, xalloc.h: consolidated memory allocation so everyone
handles OOM the same way (for now, dump core).
* constants.h: various assumptions and limits, were in bench.h.
* events: added event-queue model to reduce thread requirements.
Eventually, it would be nice for a consultant to be able to run
this off a laptop to test a small- to medium-sized box. For
now, at least, configuration remains the same. This doesn't
work on NT. Oh, well.

View File

@@ -1,129 +0,0 @@
MailStone 4.1: Changes to since version 4.0
* threads are used on all platforms reduces memory requirements by
10x for large numbers of clients must run as root for maximum
connections per process
* massive internal code and script cleanup / rewrite performance
improvements for socket handling (blocking) and caching files and
name lookups
* filename and path conventions restructuring '/mailstone'
hardwired path no longer required mailstone/results/index.html
(index of test runs) mailstone/results/<datestamp>/stderr (look
here for errors) mailstone/results/<datestamp>/results.html
mailstone/results/<datestamp>/results.txt
mailstone/results/<datestamp>/work.wld (workload config used)
mailstone/results/<datestamp>/testbed.tbd (testbed used)
mailstone/results/<datestamp>/summary.csv (per client summary)
mailstone/results/<datestamp>/*.gif (graphs)
mailstone/tmp/<datestamp>/*.out (raw results from each client)
mailstone/conf/*.wld (workload file) mailstone/conf/*.html
(machine descriptions for reports) mailstone/data/*.msg (sample
test messages)
* periodic statistics reporting allows for trend analysis of many
variables per protocol. sampling rate is automatically determined
by mailmaster Can now generate on-the-fly reports for above by
running "process"
* The accountFormat directive is now obsolete. Use loginFormat
and addressFormat instead.
* The numAccounts and beginAccounts directives are now obsolete.
Use numLogins, firstLogin, numAddresses, and firstAddress instead.
* The sequentialLogins directive disables random account number
selection. This insures a predictable account sequence.
* The checkMailInterval directive for IMAP is now obsolete. Use
loopDelay instead.
* The directives idleTime, loopDelay, and numLoops now apply to
all protocols. See the manual for how loopDelay and numLoops are
used by each protocol.
* a command directive such as <SMTP> without HOSTS=xxx will now
apply to all clients in the testbed
* <include> directive for workload and testbed files (e.g. for
user profile)
* workloads are now passed to 'mailclient' through stdin no test
specific files need to be copied to client machines more
synchonized test startup
* 'setup' script will copy mailclient and test messages
(data/*.msg) to each testbed machine in /var/tmp
* 'cleanup' form of setup will remove mailclient and test messages
from each testbed machine in /var/tmp
* 'checktime' form of setup will (nearly) simultaneously retrieve
time from each client. This lets you easily check for clock
problems.
* 'timesync' form of setup will (nearly) simultaneously set time
on each client. This only works on OSs that support setting
seconds through the "date" command. rdate or ntpdate should be
used if available. You must be the root user and be able to rsh
as root for timesync to work.
* Improved reports in text and html (formatting and content)
* The text version of the report is now only displayed
automatically if "-v" is given.
* Graphs with more than one protocol will also display a "Total"
graph
* The graphs can now be customized for each test (see sample.wld
for the default)
* You can now add graphs (in addition to the default or configured
ones) by using "process timestamp -a conf/moregraph.wld".
* An informative index of test runs is now generated in
results/index.html
* The index is updated while the run is in progress to make
checking for errors easier.
* The error log now displays times relative to test start.
* Memory use while processing results has been greatly reduced.
* A summary of the data from each process is now saved in a
Comma-separated-value (CSV) file. results/timestamp/clients.csv
* A summary of the data over time is now saved in a
Comma-separated-value (CSV) file.
results/timestamp/protocol-time.csv
* new gnuplot binary included, can output directly to gif format
* read and write performance numbers now reported separately
* new runtime banners and copyrights (ooh boy)
* idleTime option for IMAP fixed, plus now applies to all commands
* blockTime now sets a delay between command blocks
* Process model is as follows
User runs the top-level 'mstone' script
This calls 'conf/testname.pl' with command line arguments
This calls 'mailmaster.pl' with config and command line arguments
mailmaster uses 'rsh' or equivalent to launch mailclients
mailclient runs on each testbed and forks numprocs
each proc spawns numthreads (one per client)
<run tests> (note: results are being sent continuously)
threads send results back through sockets to top mailclient
mailclient forwards results back over stdout via rsh pipe
(for future work - do some data reduction/combining here)
mailmaster directs output to each client-<hostname> file
mailmaster launches report generator
* sample LDIF fragment for a postmaster entry included

View File

@@ -1,77 +0,0 @@
MailStone 4.15: Changes to Mailstone since version 4.1
* Setup now checks license acceptance and configures a basic
setup. By default, it will also create a user LDIF file with a
'allusers' account.
* All parameters and and testbed information may now be specified
in the workload files (*.wld). New sections: CONFIG, CLIENT,
MONITOR, PRETEST, and POSTTEST. Command line parameters still
override the files. A complete copy of the configuration is saved
in results/<TIMESTAMP>/all.wld.
* The '*.pl', '*.tbd', and 'config*' files in ./conf/ are
depreciated. These should still work, but the new sections are
simpler and more flexible.
* Any CONFIG parameter can now be specified on the command line
using the form: 'PARAMETER=value'. Note that PARAMETER is case
insensitive. No whitespace is allowed before or after the '='.
* The new switch '-l' or CONFIG parameter 'ClientCount' can now
specify the total number of clients. The 'MaxClients' and
'MaxThreads' parameters in each CLIENT section control load
balancing. If the 'processes' and 'threads' parameters are set,
then the load for that CLIENT section will not be adjusted, but
will be taken into account when calculating other CLIENT sections.
If just 'processes' is set, then only the thread count will be
adjusted. All hosts in a CLIENT section will run the same number
of processes and threads.
* bin/makeusers.pl now creates users, broadcast account, etc.
Numbered passwords are now suppored. The new user/password format
now replaces '%ld' with the user number to match the rest of
mailstone. The ldif/ directory is obsolete. Run "perl/bin/perl
bin/makeusers.pl -h" for usage.
* NT client machines may now be used from a Unix test master. See
conf/sample.wld for configuration details.
* Commands can now be run for a specified block count, error
count, or time (whichever comes first). Set 'maxBlocks' and/or
'maxErrors'.
* Telemetry logging to /var/tmp/mstone-log.pn.tn is now performed
when "telemetry 1" is specified.
* The name used in the "CLIENT" section is now used to match
"HOSTS=..." qualifier. Compatibility with "hostname" is no longer
needed.
* Config values can now use quoted characters such as \n, \r, \t
* Config values can be continued using \ (backslash)
* System configuration information (SYSCONFIG) can now be
specified entirely within a workload file by quoting the newlines.
* Config values get enclosing double-quotes stripped
* Preliminary support for HTTP and WMAP (WebMail) testing.
* New table formats are easier to interpret and allow more protocols.
* The new text format report is easier to machine processes.
* The following command line switches are now obsolete: -f, -g,
-e, -p, and -l. The same functionality can be obtained by
FREQUENCY=<interval>, GNUPLOT=<path>, RSH=<path>, RCP=<path>, and
TEMPDIR=<directory> respectively.
* File backups are now created. When ./process is run multiple
times, the old files are moved to the ./tmp/<TIMESTAMP>/
directory.
* perl has been updated to include full perl5.005_03 install
package. Perl support for each architecture is now under the
perl/ directory.

View File

@@ -1,222 +0,0 @@
Mstone 4.15 Quick Installation
This version of Mstone runs on many current UNIX platforms and NT.
Only a web browser and text editor are needed to view the results and
configure tests.
QUICK INSTALL
-------------
IMPORTANT: If you have an existing mstone, save a copy of the
mstone/conf directory to preserve any configuration files you may want
to keep.
Unpack distribution:
tar xzf /tmp/mstone_OPT.tar.gz
or
gunzip -c /tmp/mstone_OPT.tar.gz | tar xf -
or
unzip /tmp/mstone_OPT.zip
cd mstone
Both the tar.gz file and the zip file are identical. Use whichever is
more convenient for you.
This will create a sub-directory named "mstone" with files and
directories under that.
cd mstone
NOTE: all scripts must be run from the mstone directory.
Do initial configuration:
Run "mstone config". It will ask you about your system configuration.
Fill in the appropriate values and create the optional user accounts
and broadcast account. When it asks about client machines, enter them
seperated by commas, with no spaces (e.g. host1,host2,host3). If you
need to re-configure, run "mstone config".
The machine starting the test may also be a client. For accurate
results, clients should not be run on the test mailserver machine (or
its directory server). If all the client machines are not running
the same operating system version, see "Configuring Client Machines"
below to configure for different OSes.
When the test master is on NT, only the local machine may be a client
and only one process is allowed. You will not be asked about client
machines.
Setup only configures the most important parameters. If you have more
advanced needs, edit conf/general.wld appropriately.
Run "mstone setup". It will now push the necessary files to each
client machine. If there are problems (i.e. with rsh permissions),
fix them and re-run "mstone setup" until everything works.
Install test accounts:
Setup will create a file called conf/MAILHOST.ldif (where MAILHOST is the
name of your mail server). If you are not using Netscape Messaging
and Directory Servers, then you may have to edit the ldif file or use
alternate means to create the user accounts.
To import these users into Netscape Messaging Server, use "add
entries" from the directory console or use the ldapmodify command line
utility.
Note: imports will go faster if access logging is disabled. For large
user counts (more than 10,000 users), it may be much faster to export
the current database, merge the files together manually, and then
import the new database.
Here is how the ldapmodify supplied with Netscape Messaging Server
would be used.
setenv LD_LIBRARY_PATH /usr/netscape/messaging/lib
cd /usr/netscape/messaging
shared/bin/ldapmodify -h mailhost -a -D 'cn=directory manager' -w d_m_password < conf/MAILHOST.ldif
Check time consistency:
IMPORTANT: The system time on each client machine must be synchronized
within one second of each other for accurate results graphs.
Run "checktime" to see the time on each client. There should not be
more than two seconds difference among the displayed time.
The best way to synchronize clients is use NTP (Network Time Protocol)
or similar protocols (like rdate or timeslave) that have sub second
accuracy.
A simple utility called "timesync" is provide to push the local
system time to all clients. You must be root and have root rsh
permissions to use timesync. Timesync only works on OSs that support
setting seconds using "date MMDDhhmmCCYY.ss". Timesync is only
accurate to a second (at best) and should only be used if better
protocols aren't available.
When running the test master on NT, "checktime" and "timesync" are
never needed (because there is only one client machine). Timesync
will be ignored for NT clients, another method must be used
(e.g. timeserv or Dimension4).
Run tests:
Try it out. Use small process and thread counts until everything is
working.
mstone pop -t 30s
The script will tell you how many processes and threads it is running
on each system and where errors are logged. At the end of the test,
it will print out a URL for the test results and an indication of the
size of the errorlog file (stderr).
The results of the mstone run will display statistics for each
protocol that was tested. The results are presented in both a HTML
web page and a text file. The text file is simple and uniform, while
the web page is more user readable. The web page has links to the
test configuration files, error log, and the text version.
For long tests run (e.g. 8 hours), the results can be updated while
the test is running by using the "process" utility. Don't run
"process" near the very end of the test.
If a test has to be aborted, then use "process" to generate a report
using the available data.
Customize tests:
Copy and edit the scripts (e.g. "conf/pop.wld") to define new tests.
The CONFIG section specifies all the attributes used in the test.
Other sections specify the protocols to be tested and the parameters
for them.
All switches can be overridden on the command line to facilitate
easier testing. The exact configuration (include command line
overrides) is stored with the results from each test.
Maintenance:
You can run "mstone setup" at any time (except during a test :-) to
update the files on the client machines.
Use "mstone cleanup" to remove the files created by "mstone setup".
After the test is finished, the directories under "tmp/" can be
compressed or deleted to save space. All the information about a test
run is stored in the "results/" directories.
Configuring client machines:
Edit conf/general.wld to include CLIENT sections for each machines to
use.
You can also specify the OS type for each client machine. Set the
"Arch" parameter in each CLIENT section as appropriate (e.g. SunOS5.6,
Linux2.2_x86, AIX4.2, HP-UXB.11.00, IRIX6.5, OSF1V4.0, WINNT4.0). The
directories under "bin" specify the available OS types.
For NT4.0 clients with a UNIX test master, you will need to configure
"command" and "tempDir" for proper operation. See the "HOSTS=winnt01"
example in conf/sample.wld.
The total number of processes and threads that can be supported on a
client is dependent on the number of commands in the test, the OS, and
available memory. Check the stderr log for messages about not being
able to create processes or threads. Check on the client machines
during the test and make sure they aren't running out of CPU. The
UNIX programs "top" and "vmstat" are good for this. If the client CPU
is more than 75% busy, use more machines.
Also watch out for network saturation. You may have to use machines
with separate networks to the server to reach full server load.
Know problems:
There can be extraneous errors or connections after the specified end
of the test. These are most likely do to stopping the test and should
be ignored.
At the end of the test, all current connections will logout without
any delays. This can cause very high peak loads.
If one process exits early (due to misconfiguration or resource
exhaustion) and the monitoring command did not specify a count (%c),
then the monitoring tasks will be terminated early as well.
Monitoring commands that specify a count (%c), may take longer than
predicted and delay the processing of test results. This is because
vmstat actually delays the requested time plus the time needed to
generate the statistics summary.
If you are doing tests with large thread counts, you may have to run
as root to allow mailclient to raise its resource limits.
The telemetry logging for SMTP, POP3, and IMAP4 is incomplete. Most
commands are captured, but banners and message contents may be missing.
The MaxBlocks parameter gets divided by the total number of processes
before starting each client. This doesn't account for clients that
don't have commands to run.
The HTTP protocol used by WMAP allows connections to be dropped and
re-connected as needed. WMAP logs this as an error and an additional
connect. The error log must be consulted to distinguish another types
of connection errors (timeout or connection refused) from an automatic
re-connect.
The HTTP protocol test is experimental and subject to change.

View File

@@ -1,19 +0,0 @@
The contents of this software package are subject to the Netscape
Public License Version 1.1 (the "License"); you may not use this
software except in compliance with the License. You may obtain a copy
of the License at http://www.mozilla.org/NPL/
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.
Alternatively, the this software package may be used under the terms
of the GNU Public License (the "GPL"), in which case the provisions of
the GPL are applicable instead of those above. If you wish to allow
use of your version of this file only under the terms of the GPL and
not to allow others to use your version of this file under the NPL,
indicate your decision by deleting the provisions above and replace
them with the notice and other provisions required by the GPL. If you
do not delete the provisions above, a recipient may use your version
of this file under either the NPL or the GPL.

View File

@@ -1,535 +0,0 @@
MOZILLA PUBLIC LICENSE
Version 1.1
---------------
1. Definitions.
1.0.1. "Commercial Use" means distribution or otherwise making the
Covered Code available to a third party.
1.1. "Contributor" means each entity that creates or contributes to
the creation of Modifications.
1.2. "Contributor Version" means the combination of the Original
Code, prior Modifications used by a Contributor, and the Modifications
made by that particular Contributor.
1.3. "Covered Code" means the Original Code or Modifications or the
combination of the Original Code and Modifications, in each case
including portions thereof.
1.4. "Electronic Distribution Mechanism" means a mechanism generally
accepted in the software development community for the electronic
transfer of data.
1.5. "Executable" means Covered Code in any form other than Source
Code.
1.6. "Initial Developer" means the individual or entity identified
as the Initial Developer in the Source Code notice required by Exhibit
A.
1.7. "Larger Work" means a work which combines Covered Code or
portions thereof with code not governed by the terms of this License.
1.8. "License" means this document.
1.8.1. "Licensable" means having the right to grant, to the maximum
extent possible, whether at the time of the initial grant or
subsequently acquired, any and all of the rights conveyed herein.
1.9. "Modifications" means any addition to or deletion from the
substance or structure of either the Original Code or any previous
Modifications. When Covered Code is released as a series of files, a
Modification is:
A. Any addition to or deletion from the contents of a file
containing Original Code or previous Modifications.
B. Any new file that contains any part of the Original Code or
previous Modifications.
1.10. "Original Code" means Source Code of computer software code
which is described in the Source Code notice required by Exhibit A as
Original Code, and which, at the time of its release under this
License is not already Covered Code governed by this License.
1.10.1. "Patent Claims" means any patent claim(s), now owned or
hereafter acquired, including without limitation, method, process,
and apparatus claims, in any patent Licensable by grantor.
1.11. "Source Code" means the preferred form of the Covered Code for
making modifications to it, including all modules it contains, plus
any associated interface definition files, scripts used to control
compilation and installation of an Executable, or source code
differential comparisons against either the Original Code or another
well known, available Covered Code of the Contributor's choice. The
Source Code can be in a compressed or archival form, provided the
appropriate decompression or de-archiving software is widely available
for no charge.
1.12. "You" (or "Your") means an individual or a legal entity
exercising rights under, and complying with all of the terms of, this
License or a future version of this License issued under Section 6.1.
For legal entities, "You" includes any entity which controls, is
controlled by, or is under common control with You. For purposes of
this definition, "control" means (a) the power, direct or indirect,
to cause the direction or management of such entity, whether by
contract or otherwise, or (b) ownership of more than fifty percent
(50%) of the outstanding shares or beneficial ownership of such
entity.
2. Source Code License.
2.1. The Initial Developer Grant.
The Initial Developer hereby grants You a world-wide, royalty-free,
non-exclusive license, subject to third party intellectual property
claims:
(a) under intellectual property rights (other than patent or
trademark) Licensable by Initial Developer to use, reproduce,
modify, display, perform, sublicense and distribute the Original
Code (or portions thereof) with or without Modifications, and/or
as part of a Larger Work; and
(b) under Patents Claims infringed by the making, using or
selling of Original Code, to make, have made, use, practice,
sell, and offer for sale, and/or otherwise dispose of the
Original Code (or portions thereof).
(c) the licenses granted in this Section 2.1(a) and (b) are
effective on the date Initial Developer first distributes
Original Code under the terms of this License.
(d) Notwithstanding Section 2.1(b) above, no patent license is
granted: 1) for code that You delete from the Original Code; 2)
separate from the Original Code; or 3) for infringements caused
by: i) the modification of the Original Code or ii) the
combination of the Original Code with other software or devices.
2.2. Contributor Grant.
Subject to third party intellectual property claims, each Contributor
hereby grants You a world-wide, royalty-free, non-exclusive license
(a) under intellectual property rights (other than patent or
trademark) Licensable by Contributor, to use, reproduce, modify,
display, perform, sublicense and distribute the Modifications
created by such Contributor (or portions thereof) either on an
unmodified basis, with other Modifications, as Covered Code
and/or as part of a Larger Work; and
(b) under Patent Claims infringed by the making, using, or
selling of Modifications made by that Contributor either alone
and/or in combination with its Contributor Version (or portions
of such combination), to make, use, sell, offer for sale, have
made, and/or otherwise dispose of: 1) Modifications made by that
Contributor (or portions thereof); and 2) the combination of
Modifications made by that Contributor with its Contributor
Version (or portions of such combination).
(c) the licenses granted in Sections 2.2(a) and 2.2(b) are
effective on the date Contributor first makes Commercial Use of
the Covered Code.
(d) Notwithstanding Section 2.2(b) above, no patent license is
granted: 1) for any code that Contributor has deleted from the
Contributor Version; 2) separate from the Contributor Version;
3) for infringements caused by: i) third party modifications of
Contributor Version or ii) the combination of Modifications made
by that Contributor with other software (except as part of the
Contributor Version) or other devices; or 4) under Patent Claims
infringed by Covered Code in the absence of Modifications made by
that Contributor.
3. Distribution Obligations.
3.1. Application of License.
The Modifications which You create or to which You contribute are
governed by the terms of this License, including without limitation
Section 2.2. The Source Code version of Covered Code may be
distributed only under the terms of this License or a future version
of this License released under Section 6.1, and You must include a
copy of this License with every copy of the Source Code You
distribute. You may not offer or impose any terms on any Source Code
version that alters or restricts the applicable version of this
License or the recipients' rights hereunder. However, You may include
an additional document offering the additional rights described in
Section 3.5.
3.2. Availability of Source Code.
Any Modification which You create or to which You contribute must be
made available in Source Code form under the terms of this License
either on the same media as an Executable version or via an accepted
Electronic Distribution Mechanism to anyone to whom you made an
Executable version available; and if made available via Electronic
Distribution Mechanism, must remain available for at least twelve (12)
months after the date it initially became available, or at least six
(6) months after a subsequent version of that particular Modification
has been made available to such recipients. You are responsible for
ensuring that the Source Code version remains available even if the
Electronic Distribution Mechanism is maintained by a third party.
3.3. Description of Modifications.
You must cause all Covered Code to which You contribute to contain a
file documenting the changes You made to create that Covered Code and
the date of any change. You must include a prominent statement that
the Modification is derived, directly or indirectly, from Original
Code provided by the Initial Developer and including the name of the
Initial Developer in (a) the Source Code, and (b) in any notice in an
Executable version or related documentation in which You describe the
origin or ownership of the Covered Code.
3.4. Intellectual Property Matters
(a) Third Party Claims.
If Contributor has knowledge that a license under a third party's
intellectual property rights is required to exercise the rights
granted by such Contributor under Sections 2.1 or 2.2,
Contributor must include a text file with the Source Code
distribution titled "LEGAL" which describes the claim and the
party making the claim in sufficient detail that a recipient will
know whom to contact. If Contributor obtains such knowledge after
the Modification is made available as described in Section 3.2,
Contributor shall promptly modify the LEGAL file in all copies
Contributor makes available thereafter and shall take other steps
(such as notifying appropriate mailing lists or newsgroups)
reasonably calculated to inform those who received the Covered
Code that new knowledge has been obtained.
(b) Contributor APIs.
If Contributor's Modifications include an application programming
interface and Contributor has knowledge of patent licenses which
are reasonably necessary to implement that API, Contributor must
also include this information in the LEGAL file.
(c) Representations.
Contributor represents that, except as disclosed pursuant to
Section 3.4(a) above, Contributor believes that Contributor's
Modifications are Contributor's original creation(s) and/or
Contributor has sufficient rights to grant the rights conveyed by
this License.
3.5. Required Notices.
You must duplicate the notice in Exhibit A in each file of the Source
Code. If it is not possible to put such notice in a particular Source
Code file due to its structure, then You must include such notice in a
location (such as a relevant directory) where a user would be likely
to look for such a notice. If You created one or more Modification(s)
You may add your name as a Contributor to the notice described in
Exhibit A. You must also duplicate this License in any documentation
for the Source Code where You describe recipients' rights or ownership
rights relating to Covered Code. You may choose to offer, and to
charge a fee for, warranty, support, indemnity or liability
obligations to one or more recipients of Covered Code. However, You
may do so only on Your own behalf, and not on behalf of the Initial
Developer or any Contributor. You must make it absolutely clear than
any such warranty, support, indemnity or liability obligation is
offered by You alone, and You hereby agree to indemnify the Initial
Developer and every Contributor for any liability incurred by the
Initial Developer or such Contributor as a result of warranty,
support, indemnity or liability terms You offer.
3.6. Distribution of Executable Versions.
You may distribute Covered Code in Executable form only if the
requirements of Section 3.1-3.5 have been met for that Covered Code,
and if You include a notice stating that the Source Code version of
the Covered Code is available under the terms of this License,
including a description of how and where You have fulfilled the
obligations of Section 3.2. The notice must be conspicuously included
in any notice in an Executable version, related documentation or
collateral in which You describe recipients' rights relating to the
Covered Code. You may distribute the Executable version of Covered
Code or ownership rights under a license of Your choice, which may
contain terms different from this License, provided that You are in
compliance with the terms of this License and that the license for the
Executable version does not attempt to limit or alter the recipient's
rights in the Source Code version from the rights set forth in this
License. If You distribute the Executable version under a different
license You must make it absolutely clear that any terms which differ
from this License are offered by You alone, not by the Initial
Developer or any Contributor. You hereby agree to indemnify the
Initial Developer and every Contributor for any liability incurred by
the Initial Developer or such Contributor as a result of any such
terms You offer.
3.7. Larger Works.
You may create a Larger Work by combining Covered Code with other code
not governed by the terms of this License and distribute the Larger
Work as a single product. In such a case, You must make sure the
requirements of this License are fulfilled for the Covered Code.
4. Inability to Comply Due to Statute or Regulation.
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Code due to
statute, judicial order, or regulation then You must: (a) comply with
the terms of this License to the maximum extent possible; and (b)
describe the limitations and the code they affect. Such description
must be included in the LEGAL file described in Section 3.4 and must
be included with all distributions of the Source Code. Except to the
extent prohibited by statute or regulation, such description must be
sufficiently detailed for a recipient of ordinary skill to be able to
understand it.
5. Application of this License.
This License applies to code to which the Initial Developer has
attached the notice in Exhibit A and to related Covered Code.
6. Versions of the License.
6.1. New Versions.
Netscape Communications Corporation ("Netscape") may publish revised
and/or new versions of the License from time to time. Each version
will be given a distinguishing version number.
6.2. Effect of New Versions.
Once Covered Code has been published under a particular version of the
License, You may always continue to use it under the terms of that
version. You may also choose to use such Covered Code under the terms
of any subsequent version of the License published by Netscape. No one
other than Netscape has the right to modify the terms applicable to
Covered Code created under this License.
6.3. Derivative Works.
If You create or use a modified version of this License (which you may
only do in order to apply it to code which is not already Covered Code
governed by this License), You must (a) rename Your license so that
the phrases "Mozilla", "MOZILLAPL", "MOZPL", "Netscape",
"MPL", "NPL" or any confusingly similar phrase do not appear in your
license (except to note that your license differs from this License)
and (b) otherwise make it clear that Your version of the license
contains terms which differ from the Mozilla Public License and
Netscape Public License. (Filling in the name of the Initial
Developer, Original Code or Contributor in the notice described in
Exhibit A shall not of themselves be deemed to be modifications of
this License.)
7. DISCLAIMER OF WARRANTY.
COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
8. TERMINATION.
8.1. This License and the rights granted hereunder will terminate
automatically if You fail to comply with terms herein and fail to cure
such breach within 30 days of becoming aware of the breach. All
sublicenses to the Covered Code which are properly granted shall
survive any termination of this License. Provisions which, by their
nature, must remain in effect beyond the termination of this License
shall survive.
8.2. If You initiate litigation by asserting a patent infringement
claim (excluding declatory judgment actions) against Initial Developer
or a Contributor (the Initial Developer or Contributor against whom
You file such action is referred to as "Participant") alleging that:
(a) such Participant's Contributor Version directly or indirectly
infringes any patent, then any and all rights granted by such
Participant to You under Sections 2.1 and/or 2.2 of this License
shall, upon 60 days notice from Participant terminate prospectively,
unless if within 60 days after receipt of notice You either: (i)
agree in writing to pay Participant a mutually agreeable reasonable
royalty for Your past and future use of Modifications made by such
Participant, or (ii) withdraw Your litigation claim with respect to
the Contributor Version against such Participant. If within 60 days
of notice, a reasonable royalty and payment arrangement are not
mutually agreed upon in writing by the parties or the litigation claim
is not withdrawn, the rights granted by Participant to You under
Sections 2.1 and/or 2.2 automatically terminate at the expiration of
the 60 day notice period specified above.
(b) any software, hardware, or device, other than such Participant's
Contributor Version, directly or indirectly infringes any patent, then
any rights granted to You by such Participant under Sections 2.1(b)
and 2.2(b) are revoked effective as of the date You first made, used,
sold, distributed, or had made, Modifications made by that
Participant.
8.3. If You assert a patent infringement claim against Participant
alleging that such Participant's Contributor Version directly or
indirectly infringes any patent where such claim is resolved (such as
by license or settlement) prior to the initiation of patent
infringement litigation, then the reasonable value of the licenses
granted by such Participant under Sections 2.1 or 2.2 shall be taken
into account in determining the amount or value of any payment or
license.
8.4. In the event of termination under Sections 8.1 or 8.2 above,
all end user license agreements (excluding distributors and resellers)
which have been validly granted by You or any distributor hereunder
prior to termination shall survive termination.
9. LIMITATION OF LIABILITY.
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL
DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR
ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY
CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF GOODWILL,
WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER
COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN
INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO
THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
10. U.S. GOVERNMENT END USERS.
The Covered Code is a "commercial item," as that term is defined in
48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer
software" and "commercial computer software documentation," as such
terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
all U.S. Government End Users acquire Covered Code with only those
rights set forth herein.
11. MISCELLANEOUS.
This License represents the complete agreement concerning subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. This License shall be governed by
California law provisions (except to the extent applicable law, if
any, provides otherwise), excluding its conflict-of-law provisions.
With respect to disputes in which at least one party is a citizen of,
or an entity chartered or registered to do business in the United
States of America, any litigation relating to this License shall be
subject to the jurisdiction of the Federal Courts of the Northern
District of California, with venue lying in Santa Clara County,
California, with the losing party responsible for costs, including
without limitation, court costs and reasonable attorneys' fees and
expenses. The application of the United Nations Convention on
Contracts for the International Sale of Goods is expressly excluded.
Any law or regulation which provides that the language of a contract
shall be construed against the drafter shall not apply to this
License.
12. RESPONSIBILITY FOR CLAIMS.
As between Initial Developer and the Contributors, each party is
responsible for claims and damages arising, directly or indirectly,
out of its utilization of rights under this License and You agree to
work with Initial Developer and Contributors to distribute such
responsibility on an equitable basis. Nothing herein is intended or
shall be deemed to constitute any admission of liability.
13. MULTIPLE-LICENSED CODE.
Initial Developer may designate portions of the Covered Code as
"Multiple-Licensed". "Multiple-Licensed" means that the Initial
Developer permits you to utilize portions of the Covered Code under
Your choice of the NPL or the alternative licenses, if any, specified
by the Initial Developer in the file described in Exhibit A.
EXHIBIT A-Netscape Public License.
"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/
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.
The Original Code is the Netscape Mailstone code, released
March 17, 2000.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1999-2000 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s): Dan Christian <robodan@netscape.com>
Marcel DePaolis <marcel@netscape.com>
Jim Salter <jsalter@netscape.com>
Mike Blakely, David Shak, Brain Williams
Alternatively, the contents of this file may be used under the
terms of the GNU General Public license Version 2 or later
(the "GPL"), in which case the provisions of GPL are
applicable instead of those above. If you wish to allow use
of your version of this file only under the terms of the GPL
and not to allow others to use your version of this file
under the NPL, indicate your decision by deleting the
provisions above and replace them with the notice and other
provisions required by the GPL. If you do not delete the
provisions above, a recipient may use your version of this
file under either the NPL or the GPL License."
----------------------------------------------------------------------
AMENDMENTS
The Netscape Public License Version 1.1 ("NPL") consists of the
Mozilla Public License Version 1.1 with the following Amendments,
including Exhibit A-Netscape Public License. Files identified with
"Exhibit A-Netscape Public License" are governed by the Netscape
Public License Version 1.1.
Additional Terms applicable to the Netscape Public License.
I. Effect.
These additional terms described in this Netscape Public
License -- Amendments shall apply to the Mozilla Communicator
client code and to all Covered Code under this License.
II. "Netscape's Branded Code" means Covered Code that Netscape
distributes and/or permits others to distribute under one or more
trademark(s) which are controlled by Netscape but which are not
licensed for use under this License.
III. Netscape and logo.
This License does not grant any rights to use the trademarks
"Netscape", the "Netscape N and horizon" logo or the "Netscape
lighthouse" logo, "Netcenter", "Gecko", "Java" or "JavaScript",
"Smart Browsing" even if such marks are included in the Original
Code or Modifications.
IV. Inability to Comply Due to Contractual Obligation.
Prior to licensing the Original Code under this License, Netscape
has licensed third party code for use in Netscape's Branded Code.
To the extent that Netscape is limited contractually from making
such third party code available under this License, Netscape may
choose to reintegrate such code into Covered Code without being
required to distribute such code in Source Code form, even if
such code would otherwise be considered "Modifications" under
this License.
V. Use of Modifications and Covered Code by Initial Developer.
V.1. In General.
The obligations of Section 3 apply to Netscape, except to
the extent specified in this Amendment, Section V.2 and V.3.
V.2. Other Products.
Netscape may include Covered Code in products other than the
Netscape's Branded Code which are released by Netscape
during the two (2) years following the release date of the
Original Code, without such additional products becoming
subject to the terms of this License, and may license such
additional products on different terms from those contained
in this License.
V.3. Alternative Licensing.
Netscape may license the Source Code of Netscape's Branded
Code, including Modifications incorporated therein, without
such Netscape Branded Code becoming subject to the terms of
this License, and may license such Netscape Branded Code on
different terms from those contained in this License.
VI. Litigation.
Notwithstanding the limitations of Section 11 above, the
provisions regarding litigation in Section 11(a), (b) and (c) of
the License shall apply to all disputes relating to this License.

View File

@@ -1,246 +0,0 @@
# Makefile for mstone
# use gmake
# Builds each of the components and then packages everything
topsrcdir = .
CP := cp -p
ifndef INCLUDED_CONFIG_MK
include $(topsrcdir)/config/config.mk
endif
# dynamically find the optional directories names
LIBGD_DIR = $(wildcard gd?.*)
GNUPLOT_DIR = $(wildcard gnuplot-?.*)
PERL_DIR = $(wildcard perl5.*)
# file that we package
GDFILES = gd.txt gd.html libgd.* gd.h demoin.gif gddemo giftogd webgif
GNUPLOTFILES = gnuplot Copyright gnuplot_x11 gnuplot.1 gnuplot.gih
VERSION = 4.3
TARBALL = mstone-$(VERSION)-$(NSARCH)$(OBJDIR_TAG).tar.gz
ZIPFILE = mstone-$(VERSION)-$(NSARCH)$(OBJDIR_TAG).zip
TARBALL_ALL = mstone-$(VERSION)-all$(OBJDIR_TAG).tar.gz
ZIPFILE_ALL = mstone-$(VERSION)-all$(OBJDIR_TAG).zip
NTFILES = mstone.bat process.bat setup.bat
all:: usage
usage::
@$(ECHO) "gmake [ release | rpackage | debug | dpackage ]"
@$(ECHO) " [ DIST=/m/dist/mailstone/1999xxxx dist ]"
@$(ECHO) " [ all_DBG | all_OPT ]"
@$(ECHO) "perl is" $(PERL_DIR) ". gd is" $(LIBGD_DIR) ". gnuplot is" $(GNUPLOT_DIR) "."
targets:: $(OBJDIR) mailclient
ifneq (,$(LIBGD_DIR))
targets:: libgd
endif
ifneq (,$(GNUPLOT_DIR))
targets:: gnuplot
endif
ifneq (,$(PERL_DIR))
targets:: perl
endif
$(OBJDIR):
-mkdir -p $(OBJDIR)
mailclient::
@$(ECHO) "\n===== [`date`] making OS_CONFIG=$(NSARCH) BUILD_VARIANT=$(BUILD_VARIANT)\n"
cd src; $(MAKE) BUILD_VARIANT=$(BUILD_VARIANT) OBJDIR=../$(OBJDIR) PKGDIR=../$(PKGDIR) all
# Use our top level makefiles to drive the component builds
libgd $(OBJDIR)/gd/libgd.a::
$(MAKE) -f gd.mk LIBGD_DIR=$(LIBGD_DIR) libgd
gnuplot $(OBJDIR)/gnuplot/gnuplot::
$(MAKE) -f gnuplot.mk LIBGD_DIR=$(LIBGD_DIR) GNUPLOT_DIR=$(GNUPLOT_DIR) gnuplot
perl $(OBJDIR)/perl/perl::
$(MAKE) -f perl.mk PERL_DIR=$(PERL_DIR) perl
# Create packaging binary directories
# Note: dont make gd or gnuplot here. For multi-OS, they are links
mkpkgdirs:: $(PKGDIR)/bin $(PKGDIR)/conf $(PKGDIR)/data $(PKGDIR)/doc
$(PKGDIR)/bin:
mkdir -p $(PKGDIR)/bin
$(PKGDIR)/conf:
mkdir -p $(PKGDIR)/conf
$(PKGDIR)/data:
mkdir -p $(PKGDIR)/data
$(PKGDIR)/doc:
mkdir -p $(PKGDIR)/doc
$(PKGDIR)/gd:
mkdir -p $(PKGDIR)/gd
$(PKGDIR)/gnuplot:
mkdir -p $(PKGDIR)/gnuplot
$(PKGDIR)/perl:
mkdir -p $(PKGDIR)/perl
# operating system independent share-files (at least for Unix)
pkg-share-files:: mkpkgdirs
@$(ECHO) "\n===== [`date`] making package share-files...\n"
$(CP) mstone process $(PKGDIR)
(cd $(PKGDIR); [ ! -f setup ] || rm -f setup; ln -s mstone setup)
(cd $(PKGDIR); [ ! -f cleanup ] || rm -f cleanup; ln -s mstone cleanup)
(cd $(PKGDIR); [ ! -f checktime ] || rm -f checktime; ln -s mstone checktime)
(cd $(PKGDIR); [ ! -f timesync ] || rm -f timesync; ln -s mstone timesync)
-$(CP) nsarch bin/*.pl $(PKGDIR)/bin
-$(CP) conf/*.wld conf/*.wld.in conf/*.html $(PKGDIR)/conf
-$(CP) data/*.msg $(PKGDIR)/data
-$(CP) doc/*.html doc/*.gif $(PKGDIR)/doc
-$(CP) INSTALL $(PKGDIR)
-$(CP) README $(PKGDIR)
-$(CP) ChangeLog $(PKGDIR)
-$(CP) LICENSE $(PKGDIR)
# split out OS specific file so that combined packaging possible (set PKGDIR)
pkg-arch-files-gd:: $(PKGDIR)/gd $(OBJDIR)/gd/libgd.a
$(CP) $(addprefix $(OBJDIR)/gd/, $(GDFILES)) $(PKGDIR)/gd
-$(STRIP) $(PKGDIR)/gd/webgif $(PKGDIR)/gd/giftogd $(PKGDIR)/gd/gddemo
pkg-arch-files-gnuplot:: $(PKGDIR)/gnuplot $(OBJDIR)/gnuplot/gnuplot
$(CP) $(addprefix $(OBJDIR)/gnuplot/, $(GNUPLOTFILES)) $(PKGDIR)/gnuplot
-$(STRIP) $(PKGDIR)/gnuplot/gnuplot $(PKGDIR)/gnuplot/gnuplot_x11
ifneq (,$(LIBGD_DIR))
pkg-arch-files:: pkg-arch-files-gd
endif
ifneq (,$(GNUPLOT_DIR))
pkg-arch-files:: pkg-arch-files-gnuplot
endif
pkg-arch-files:: $(PKGDIR)/bin $(OBJDIR)/mailclient
@$(ECHO) "\n===== [`date`] making package arch-files...\n"
$(CP) $(OBJDIR)/mailclient $(PKGDIR)/bin
-$(STRIP) $(PKGDIR)/bin/mailclient
pkg-perl-files:: $(PKGDIR)/bin $(OBJDIR)/perl/perl
@$(ECHO) "\n===== [`date`] making package perl-files...\n"
$(MAKE) -f perl.mk PERL_DIR=$(PERL_DIR) \
BUILD_VARIANT=$(BUILD_VARIANT) \
OBJDIR=$(OBJDIR) PKGDIR=$(PKGDIR) package-perl
find $(PKGDIR)/perl/lib -name .packlist -exec rm {} \; -print
-$(STRIP) $(PKGDIR)/perl/bin/perl
-$(STRIP) $(PKGDIR)/perl/bin/a2p
# for combined packaging, this should not be part of pkg-arch-files
# perl is handled seperately do to its size
ifneq (,$(PERL_DIR))
pkg:: pkg-perl-files
endif
pkg:: targets pkg-share-files pkg-arch-files
tarball: build/$(TARBALL)
build/$(TARBALL):
@$(ECHO) "\n===== [`date`] making os tar file...\n"
-rm -f build/$(TARBALL)
cd $(dir $(PKGDIR)) && tar cf - . | gzip > ../../$(TARBALL)
zipfile: build/$(ZIPFILE)
build/$(ZIPFILE):
@$(ECHO) "\n===== [`date`] making os zip file...\n"
-rm -f build/$(ZIPFILE)
cd $(dir $(PKGDIR)) && zip -r -q ../../$(ZIPFILE) .
########################################################################
# Generate a combined build for every Unix OS that is already packaged
# NT has to be done seperately because it has different file names
# We have to nuke some old parts, because permissions wont allow overwrites
# Finally, dont ship perl development headers and libraries
all_DBG all_OPT::
@$(ECHO) "===== [`date`] unified packaging for $@..."
$(MAKE) NSARCH=$@ OBJDIR_TAG='' \
PKGDIR=$(topsrcdir)/build/package/$@.OBJ/mstone pkg-share-files
./ospkg.sh $@.OBJ \
$(notdir $(shell ls -d build/package/[A-Z]*$(subst all,,$@.OBJ)))
[ -d $(topsrcdir)/build/package/$@.OBJ/mstone/bin/WINNT4.0 ] \
&& cp -p $(NTFILES) $(topsrcdir)/build/package/$@.OBJ/mstone; :
-rm -f ./build/mstone-$(VERSION)-$@.tar.gz
cd ./build/package/$@.OBJ \
&& tar cf - . | gzip > ../../mstone-$(VERSION)-$@.tar.gz
-rm -f ./build/mstone-$(VERSION)-$@.zip
cd ./build/package/$@.OBJ \
&& zip -r -q ../../mstone-$(VERSION)-$@.zip .
########################################################################
# Copy all the packaged trees to the distribution site
# Copy in the unified tarball and zip file
# Link mstone to mailstone for Netscape back compatibility
# Re-map short Linux name to standard Netscape convention
dist::
@[ "$(DIST)" != "" ] || ($(MAKE) usage && /bin/false)
@[ ! -d "$(DIST)" ] || ($(ECHO) "Error: $(DIST) already exists" && \
$(MAKE) usage && /bin/false)
mkdir -p $(DIST)
cp -p build/mstone-$(VERSION)-all_*.*[a-z] $(DIST)/
(cd build/package; tar cf - *.OBJ) | (cd $(DIST); tar xf - )
for l in $(DIST)/*_???.OBJ ; do \
(cd $$l; ln -s mstone mailstone); done
cd $(DIST); for l in Linux*_???.OBJ ; do \
nn=`echo $$l | sed -e 's/_OPT/_glibc_PTH_OPT/' | sed -e 's/_DBG/_glibc_PTH_DBG/'`; \
ln -s $$l $$nn; done
# since the default is release mode, this can just work off a dependency
release:: targets
#release::
# @$(ECHO) "\n===== [`date`] making release build..."
# $(MAKE) BUILD_VARIANT=release OBJDIR_TAG=_OPT targets
@$(ECHO) "\n===== [`date`] making release build done."
rpackage:: release pkg #tarball zipfile
#rpackage:: release
# @$(ECHO) "\n===== [`date`] making release package..."
# $(MAKE) BUILD_VARIANT=release OBJDIR_TAG=_OPT pkg tarball zipfile
@$(ECHO) "\n===== [`date`] making release package done."
# since the default is release mode, start a make with the right mode
debug::
@$(ECHO) "\n===== [`date`] making debug build..."
$(MAKE) BUILD_VARIANT=debug OBJDIR_TAG=_DBG targets
@$(ECHO) "\n===== [`date`] making debug build done."
# We dont usually bother to tar up a debug build
dpackage:: debug
@$(ECHO) "\n===== [`date`] making debug package..."
$(MAKE) BUILD_VARIANT=debug OBJDIR_TAG=_DBG pkg
@$(ECHO) "\n===== [`date`] making debug package done."
# These are old and may be broken
cleanvariant::
(cd src; $(MAKE) OBJDIR=../$(OBJDIR) clean)
rm -rf $(PKGDIR)
clean::
$(MAKE) BUILD_VARIANT=release OBJDIR_TAG=_OPT cleanvariant
$(MAKE) BUILD_VARIANT=debug OBJDIR_TAG=_DBG cleanvariant
distcleanvariant::
(cd src; $(MAKE) OBJDIR=../$(OBJDIR) distclean)
rm -rf $(OBJDIR) $(PKGDIR)
distclean:: clean
$(MAKE) BUILD_VARIANT=release OBJDIR_TAG=_OPT distcleanvariant
$(MAKE) BUILD_VARIANT=debug OBJDIR_TAG=_DBG distcleanvariant

View File

@@ -1,75 +0,0 @@
MSTONE 4.2
Mstone is a mail server performance testing tool designed to simulate
the different types and volume of mail traffic a mail server would
experience during a peak activity period. Mstone was formerly known
as Mailstone.
A quick installation guide is available in INSTALL.
The full Mailstone 4.15 user manual is available at
http://lxr.mozilla.org/mozilla/source/mstone/doc/MailStone.html
Testing strategy
----------------
Mstone is capable of opening SMTP, POP3, IMAP4, and other protocol
connections to mail servers. The number and type of connections made
to the mail server is based on a weighted command list which provides
the ability to test mail server implementation requirements.
A series of perl script allow you to setup client machines, run tests,
and then cleanup client machine files. Each client machine has a copy
of the mailclient program and SMTP message files. When the test is
run, the mailclient is started with the proper command line and work load.
After experimenting with mstone loads, you will notice that there
are a few factors that can distort server the byte and message
throughput. You will find that the server byte throughput is related
to the average SMTP message (file) size. Also, server throughput, in
bytes and messages, is affected by larger than normal POP3/IMAP4
mailboxes. So it is important to approach the mstone command
configuration with data collected from existing mail server
implementations, for example, a customer might say "during our peak
activity in the morning, we handle up to two thousand employees
sending an average of 5 messages of 20K average size and receiving 25
messages of same size". With input like this, you can begin tuning
mstone to generate relevant data.
There are two important things to consider when reviewing the results of
mstone performance analysis: Was the test run on target for
simulating the type and volume of mail traffic; and did the server, both
software and machine, handle the load within an acceptable margin?
With this information, it can be determined: whether enough SMTP
connections were made to the server during the run, and how many
messages were downloaded over how many POP3/IMAP4 connections. If the
number of SMTP connections is not in the acceptable range, then
consider adding more client processes/machines or checking the server
performance during the run. The message/connection ratio for
POP3/IMAP4 should be checked for soundness, and adjustments should be
made to the mailboxes before running the next test.
Monitoring the server performance during test runs is crucial in
understanding the results. If the number of client connections is not
being achieved and the server cpu usage and process run queue is not
settling down after the initial spike, then modifications to the server
architecture could be in order.
The analysis of mstone results is an iterative process of client
(mstone client) and server tuning. The bottom line is to determine
whether the messaging solution can handle the type of load expected in
an acceptable manner.
Server Log Tuning
-----------------
The Messaging and Directory server ship with access logging enabled by
default. This gives the most information about what is going on in
the system, but can reduce performance. You should test the way the
system will be run.
Noticeable performance increases are often obtained by disabling access
logging on the directory server and by reducing the logging level of
the messaging servers from "Notice" to "Warning".

View File

@@ -1,16 +0,0 @@
Under the terms of the Mozilla Public License, Version 1.1, granted
by Mozilla, Sendmail Inc. is contributing the following Source Code
changes to the Mozilla mstone source repository.
Sendmail, Inc. is making available these source code modifications
according to the Distribution Obligations as listed in section 3
of the Mozilla Public License, Version 1.1
The changes provided herein are described in the included files:
README.Sendmail-mstone_changes.html
ChangeLog-Sendmail
All modifications are derived, directly or indirectly, from the original
code as provided by Mozilla.

View File

@@ -1,419 +0,0 @@
<html>
<head><title>Sendmail, Inc. Mstone changes</title></head>
<body>
<h3>Mstone modifications</h3>
<ol>
<li><h4>Random Variable Parameters</h4>
In addition to taking on constant values, some parameters can now be
sampled from probability distributions. These variables are:
<ul>
<li><code>startDelay</code>
<li><code>idleTime</code>
<li><code>blockTime</code>
<li><code>loopDelay</code>
<li><code>numRecips</code>
<li><code>size</code>
<li><code>headers</code>
<li><code>mime</code>
<li><code>leaveMailOnServer</code>
<li><code>bandwidth</code>
<li><code>latency</code>
</ul>
<p>
The following distributions are currently implemented:
<ul>
<li>Uniform (~unif(a, b))
<li>Normal (~normal(a, b))
<li>Log-Normal (~lognormal(a, b))
<li>Weibull (~weib(a, b, c))
<li>Exponential (~exp(a))
<li>Constant (~const(a))
<li>Binomial (~binomial(a))
</ul>
<p>
Sampled values may also be constrained by a minimum and maximum value.
This is particularly useful for e.g. the normal and lognormal
distributions, though over-tight constraints will create a "lump" at
the end of the generated distribution, and any constraints may change
the distribution's characteristics (e.g. mean). To specify
constraints, do the following:
<h5>getdist</h5>
<p>
There is also a helper tool called "getdist" in the Sendmail mstone
distribution. Building getdist:
<pre>
file: mstone/src/idle.c
# gcc -DTEST_PROB -Dxalloc=malloc -Dxfree=free -lm idle.c
</pre>
<p>
Rename the resulting binary to "getdist"
<p>
<b>Using getdist</b>
<p>
To run it interactively:
<ol>
<li>Start up getdist</li>
<li>Enter the distribution you want to see a sample and mean (ignore warning about 'gets()')</li>
</ol>
<p>
Example:
<pre>
% getdist
warning: this program uses gets(), which is unsafe.
~lognormal(3,4.5)
Samples:
6.846493
0.109578
31.402784
0.467486
21.905714
7.113645
0.225102
29.372181
4.252427
1.444493
mean: 29.128932
</pre>
<p>
It will only OUTPUT 10 samples as examples but the mean
is calculated based on 2000 samples by default. You can specify
the mean sample size on the command line by giving it a -n option:
<pre>
% getdist -n 1000000
</pre>
<p>
This will calculate the mean based on a sample of 1000000 entries.
<p>
The above data was calculated with 2M samples.
<p>
<i>Known Problems</i><BR>
It appears (anecdotally) that the first set of samples returned by
getdist are inaccurate. After starting the getdist program interactively,
it may appear necessary to ignore the first set of output, but that entering
the distribution again will return a more accurate result.<BR>
<p>
For example:
<pre>
# getdist
~lognormal(10,2)
Samples:
670043.575395
48.842052
54.039792
0.460849
2.152179
32.534664
6.163511
42.827706
27.806642
4.966444
mean: 364.747532
var: 224352671.855287
stddev: 14978.406853
~lognormal(10,2)
Samples:
1.842800
39.760727
4.798239
10.722216
27.052030
28.923926
61.504273
20.743583
5.373420
42.195531
mean: 25.510130
var: 2674.124997
stddev: 51.711942
</pre>
<dl>
<dt><code>~dist(...) : [min,]</code>
<dd>force all sampled values to be >= <code>min</code>
<dt><code>~dist(...) : [min,max]</code>
<dd>force all sampled values X to be <code>min</code> <= X <= <code>max</code>.
<dt><code>~dist(...) : [,max]</code>
<dd>force values to be <= <code>max</code>
</dl>
<li><h4>Parsing Changes</h4>
All of the time-valued test parameters except <code>rampTime</code>
and <code>time</code> now have millisecond values. In particular,
this means that a value of "17" parses to 17
<strong>milliseconds</strong>, not 17 seconds. Use "17s" instead.
<p>
Size-valued parameters can have units of "k" or "m" to indicate
kilobytes or megabytes, respectively.
<p>
For parameters supporting random-variable values, a value starting
with "~" will be interpreted as a random variable specification of the
form "~NAME([ARGS ...])". Unit suffixes (e.g. "s", and "m") apply to
random variable parameters as well as constant values. This implies
that for unitless parameters, the suffixes corresponding to the random
variable's units will still be recognized (i.e. the values will be
multiplied by the appropriate factors). This is probably best
considered as a "bug" rather than excercised as a "feature."
<p>
<code>blockTime</code>, <code>loopDelay</code>, and
<code>idleTime</code> now refer to the total amount of time a command
block, loop, and initialization phase should take, respectively, not
the amount of time the simulation should stall after completing each
phase. For example, if a block takes 2 seconds to complete, and the
block time is 4 seconds, the client thread will sleep for 2 seconds
after finishing instead of the full 4.<p>
<code>rampTime</code> is now solely for the benefit of the client
machines, to control the rate at which threads are started. The rate
at which commands from a given protocol are started is now controlled
by the <code>startDelay</code> variable, which is
distribution-valued. Thus the actual command loop now looks like
this:
<pre>
wait for startDelay
start counting idleTime
start counting blockTime
execute start function
wait for remainder of idleTime
for (1 ... numLoops)
start counting loopDelay
execute loop function
wait for remainder of loopDelay
execute end function
wait for remainder of blockTime
</pre>
<li><h4>Automatic Message Generation</h4>
Both MIME and text/plain messages can now be generated automatically.
To enable automatic message generation, set the <code>file</code>
attribute of an SMTP block to "auto". The messages will then have at
least as many headers as the value of the <code>headers</code>
attribute, have bodies <code>size</code> bytes long, and have
<code>mime</code> MIME parts. To generate text/plain messages, set
<code>mime</code> to zero.
<table border=1 cellpadding=2>
<tr><th>Attribute</th><th>Description</th></tr>
<tr>
<td><code>headers <i>N</i></code></td>
<td>(optional; default=5) Each automatically generated message will
have <code>min(<i>N</i>, min_hdrs)</code> headers, where
<code>min_hdrs</code> is 5 for text/plain, and about 7 for MIME
messages. Additional headers are named
"X-generated-header-%d". </td>
</tr>
<tr>
<td><code>size <i>N</i></code></td>
<td>(required) Each generated message will have a body be <i>N</i>
bytes long.</td>
</tr>
<tr>
<td><code>mime <i>N</i></code></td>
<td>Each generated message will have <code>N</code> MIME parts. If
the value of <code>size</code> does not allow <code>N</code> parts,
one part is generated. If <code>N</code> is zero, the message is
text/plain.</td>
</tr>
<tr>
<td><code>checksum <i>{yes|no|save}</i></code></td>
<td>For SMTP: each generated message will have the MD5 sum of the
message body appended to the message unless the value is <i>no</i>.
For retrieval protocols, checksums will be verified. (NOT
IMPLEMENTED: if <code>checksum</code> is <i>save</i>, messages with
incorrect checksums will be saved to temporary files for later
examination.) </td>
</tr>
</table>
<li><h4>Linespeed Emulation</h4>
SMTP, POP, and IMAP all support a form of linespeed emulation,
controlled via the <code>latency</code> and <code>bandwidth</code>
parameters.
<table border=1 cellpadding=2>
<tr><th>Attribute</th><th>Description</th></tr>
<tr><td><code>latency <i>N</i></code></td>
<td>Set the network latency to <code>N</code> milliseconds.</td></tr>
<tr><td><code>bandwidth <i>N</i></code></td>
<td>Transfer at most <code>N</code> bytes per second.</td></tr>
</table>
<li><h4>TLS support</h4>
If you have openssl, mstone now supports STARTTLS for SMTP and IMAP,
and STLS for POP (both old-style and MULTIPOP), as well as SSL
tunneling. This support is <strong>not</strong> well-tested, and TLS
can be a bit tricky to set up, so use at your own risk. TLS
introduces several new attributes to the protocol blocks:
<table border=1 cellpadding=2>
<tr><th>Attribute</th><th>Description</th></tr>
<tr><td><code>sslcert <i>filename</i></code></td>
<td>Read the client's cert from <i>filename</i>, which should be in
PEM format. </td></tr>
<tr><td><code>sslkey <i>filename</i></code></td>
<td>Read the client's private key from <i>filename</i>, which should
be in PEM format.</td></tr>
<tr><td><code>usetls {0|1}</code></td>
<td>Turn STARTTLS/STLS on or off (default: off). <b>Note</b>:
<code>starttls</code> and <code>ssltunnel</code> are mutually
exlcusive.</td></tr>
<tr><td><code>ssltunnel {0|1}</code></td>
<td>Turn SSL tunneling on or off (default: off).</td></tr>
</table>
<li><h4>"Multi-POP" protocol</h4>
<b>Note</b>: multipop, always a band-aid, is hopefully obsoleted by
the new event-queue execution model. Though it has not been tested,
it should be easier, more efficient, and more accurate to use the
normal POP protocol with events to simulate a large number of users
with a reasonable number of threads. Once this has been tested,
automatically-generated workloads should revert to using POP.
<p>To simulate a large number of concurrently active POP users with
Mstone's extravagant use of threads, and to simulate a period of
activity comprised of several POP sessions one can use the MULTIPOP
protocol to multiplex active users onto a single thread. The protocol
has all the same parameters as POP, plus the following:
<table border=1 cellpadding=2>
<tr><th>Attribute</th><th>Description</th></tr>
<tr><td><code>userSpacing</code></td>
<td>Total time for each user's session.</td>
</tr>
<tr><td><code>usersPerModem</code></td>
<td>The maximum number of concurrently connected users is limited
to <code>users / usersPerModem</code></td>
</tr>
</table>
<p>
The protocol functions are substantially different. Instead of
simulating a single login-check-logout sequence, a protocol block
simulates an entire active period for a set of users. Each user
checks mail once in the initialization function, once each time the
loop body is executed, and once more in the protocol conclusion
function.
<p>
<li><h4>"Event-queue" implementation</h4>
<p>
Unless the "noevents" parameter in the "&lt;config&gt;" section is set to 1,
or mailclient is not given the "-e" flag, mstone will run in
"event-queue" mode. Instead of creating one thread per client, it
will multiplex clients over a much smaller number of threads. This is
intended to increase the tool's scalability.
<p>
Note that I/O is still synchronous with this model, so the number of
threads required will approximately equal the maximum number of
concurrent operations. Also note that this change does not reduce the
number of required file descriptors.
<p>
<li><h4>Other Minor Additions</h4>
<ul>
<li>IMAP now has a ramp-down time, enabled by defining
<code>IMAP_RAMPDOWN</code>. IMAP threads now exit uniformly between
the time the test is supposed to be over and the time Mstone starts
killing them.
<li>Mstone used to always time out connections after 60 seconds. The
timeout value can now be configured on a per-block basis via the
<code>timeout</code> parameter. The value of the timeout parameter must
be defined in milliseconds, so the following value would mean a timeout
of one (1) hour:<BR>
&nbsp;&nbsp;&nbsp;timeout 3600000
<li>Simplified client allocation. It is now possible to specify the
number of clients in each group by specifying a value for
<code>clients</code> in each <code>&lt;CLIENT&gt;</code> section and
<em>not</em> specifying a global <code>clientCount</code> in the
<code>&lt;CONFIG&gt;</code> section.
</ul>
<li><h4>Bug Fixes</h4>
<ul>
<li>SMTP now ignores debugging output appearing over the connection.
Before, Mstone would generate an error when talking to
e.g. <code>sendmail -d64.5</code>.
<li>(now it works...) The old sequence of IMAP commands used by
Mstone was incorrect. Instead of only downloading unread messages, it
would download all messages received since the start of the session
each time a new messages was received. Depending on what you were
doing, this could have a serious effect on your results.
</ul>
<li><h4>Wish List</h4>
<ul>
<li>Scriptable user behavior for POP and IMAP protocols. While we should
probably not go overboard, adding more configuration options to Mstone
is probably not the answer. There is already some support for more
complex behaviors in the IMAP code -- we may or may not want to make
use of it. More to the point, wider coverage of the IMAP
protocol is vital to QA's use of the tool.
</ul>
</ol>
</body></html>

View File

@@ -1,189 +0,0 @@
Mstone TODO List
Updated:
3-20-2000 Dan Christian
======================================================================
Minor improvements
Data reduction at each testbed client
Test message generator (plain and MIME styles)
More graphs for multiple runs
Option to drop a fraction of connections
IMAP delete without reading
Just get the message list and delete everything. This could
be the fastest way to drain out the store.
Display MIN/MAX or standard deviation on graphs
Gnuplot can do data points with error bars. You could either
use MIN/MAX or the standard deviation for the error bars. There are
issues with calculating the standard deviation numbers throughout the
graph that need to be addressed.
Statistics reset
At least the MIN and MAX statistics could be easily reset
during the test (after ramp up). This keeps the transients during
startup and shutdown from dominating these numbers. The standard
deviation statistics are much trickier to reset during the run. It
may be better to isolate sections in post processing.
Perl web server
Sometimes it would be nice to include our own web server to
provide the results (instead of using file: URLs). This would also be
a gateway to form based test configuration editing and allow results
to be interactively updated during tests. Perl with a socket library
could handle this without too much trouble.
Dynamic test loading
Finalize an API for dynamically loading tests. This would
allow tests to be added or updated separately from the core
functionality. This may be needed for some types of security testing.
Link graphs to the results tables
There are already tags by each graph. You should be able to
link the appropriate results table entry to each graph. This sort of
tricky since graphs often combine multiple entries.
Show statistics for every block
Statistics are actually kept for every block in every thread.
There should be a way to view information at this detail.
Man pages
The online docs are nice, but good 'ol man pages would be
great in a different way.
Reduce namespace polution
Scripts names like setup and cleanup are too general. They
should be part of the main 'mstone' script (e.g. mstone setup).
Examples of script series
Include example scripts to run entire series of tests in a
sane way.
Fix FORMAT clash
At the start of a test, each client process outputs the
information needed to report all its protocols. When there are
multiple processes on one client, these FORMAT lines can intermix and
cause parsing errors.
Set connection drop rate
Drop some percentage of the connections without a proper
shutdown. This tests how well a server can detect and recover from
hard disconnects.
Improve randomness
The way that we generate random numbers in a range may be not
generate the proper randomness. We are using lrand48()%range we
should use (lrand48/RAND_RANGE)*range. There are some end conditions
that need to be thought about. All of this is in the sequence code;
one change should fix (or break :) everything.
Also, we may be generating numbers that are never used. This
may be costly, and can create holes in the proper sequence.
Improve printing
The color graphs are great on screen, but tend to print
poorly. Either we need a better way to generate a printable version
(maybe through a CGI button), or the seperate protocols need to be
printed individually. Also, Communicator does a lousy job of keeping
title with tables or graphs. Hopefully, Mozilla will do better.
======================================================================
Whole new protocol tests:
ICQ
Test high volume instant messaging. Very useful for the
bridges and gateways that people are considering using.
WAP
WAP is the emerging standard for mobile phones.
WCAP
Web based calendar services
LDAP
Use the LDAP SDK to do basic LDAP testing. The SDK probably
isn't fast enough to call this a real performance test, but you can at
least test performance degredation due to load from a real application
(like a mail server).
DNS
Mail servers use DNS a lot. You should at least be able to
see if performance is degrading due to load.
Disk/filesystem
Test read, write, sync, link, un-link, and append performance under
multiple threads.
Cert servers
Test certificate authenticity checking performance
======================================================================
Possible dummy servers:
SMTP
Receive mail via SMTP and ignore it. Usefull for SMTP relay
testing.
DNS
Simulate slow DNS server lookups. Usefull for SMTP relay testing.
======================================================================
Major changes
Throttling
Monitor and control transaction rates so that specific load
levels can be easily specified. The rates should be able to vary to
simulate peek hour usage and disconnect-restore.
NSPR threading
Use NSPR for threading and sockets. This may allow other OSes
to be used as clients. This might be easy, since mstone does not need
any locking, just simple thread creation and harvesting. NSPR
argument parsing and hashes may also be useful.
SSL
Support SSL on the protocols that allow it. May require NSPR.
Line speed emulation
Simulate the variable delays and limited throughput of dial up
connections.
Scripting
Allow more detailed control of protocol tests. It looks
difficult to make this scalable and fast.
Combined tests
Deliver mail over SMTP and then see when it arrives using IMAP.

View File

@@ -1,462 +0,0 @@
#!/bin/ksh
########################################################################
# buildall - automated multi-platform build tool
#
# 10/09/97 - marcel - created
# 10/13/97 - marcel - support shared build tree
# 2/11/98 - marcel - updated for 4.0 Beta builds (need -update)
# 2/26/98 - marcel - added -r, -t and host specifiers
# 7/01/99 - robodan - added VAR=value ability
# 8/01/99 - robodan - explicitly know about building on localhost
# 10/15/99 - robodan - remove older OSes from build list
# 2000/4/7 - robodan - Created mstone version
########################################################################
#
# This script is intended to do a set of UNIX builds for a
# given CVS module. It is designed to use 'rsh' between a
# set of trusting hosts and use shared NFS storage with common
# mount points (e.g. /u/username/...)
#
# To check if you have rights to rsh to a particular host, try:
# rsh hostname "echo $PATH"
# You may have to edit your .rhosts or /etc/hosts.equiv
#
# A target directory will be created based on the current date.
#
# A set of global build logs plus a log per platform are kept
# in a log directory under the target
#
# It will checkout a copy of the source, duplicate it for
# each platform and perform a set of remote builds in parallel.
# The script will exit when all the work has been completed.
#
# Example usage:
# cd ~/src; buildall msg
# Result:
# ~/src/19980210_40.1/
# ~/src/19980210_40.1/logs/...
# ~/src/19980210_40.1/src/...
# ...
#
# Buildhosts
DEFAULT_BUILDHOSTS="kimo nugget vsync shave purgatory trex0"
usage() {
echo ""
echo "usage: buildall [ make assigns... ] < -t | target > [ -r ] [ buildhosts... ]"
echo " [ -t | --test]: just test rsh and report OS versions."
echo " [-r | --respin]: rebuild in place using existing source."
echo " [-p | --postbuild]: Execute post build command too."
echo " [make assigns]: e.g. VARIANT=release"
echo " <target>: one of: mstone42"
echo " [buildhosts...]: default [$DEFAULT_BUILDHOSTS]"
echo ""
exit 1
}
########################################################################
# Set these defaults and options for your desired build
########################################################################
# Target base destination directory
DESTBASE=`pwd`
# Can we do multiple ARCH builds in same source tree
SHARESRC=yes
DESCRIPTION=""
BUILDHOSTS=""
RESPIN="no"
POSTBUILD="no"
JUST_TEST="no"
DESTTYPE=""
CO_CMD="cvs -d $CVSROOT -q checkout"
CHECKOUT=""
CHECKOUT2=""
#MOZCVSROOT=':pserver:anonymous@cvs.mozilla.org:/cvsroot'
MOZCVSROOT=':pserver:robodan%netscape.com@cvs.mozilla.org:/cvsroot'
MAKE="gmake"
MK_ARG=""
ARGS="$@"
for ARG in "$@"; do
# If this is a make assignment (FOO=whatever), add it to make command
# Arguments with quotes in them dont go all the way through.
# Make args trick: 'FOO=nop -j 2'
# The pre-post arg stuff uses hostnames as a switch, ugly calling syntax.
if [[ -n "`echo z$ARG | egrep '^z[A-Z0-9_]+=[^ ]'`" ]] ; then
if [[ -n "$DESCRIPTION" ]] ; then
echo "Arg after target is ignored! ($ARG)"
continue
fi
if [[ -z "$BUILDHOSTS" ]] ; then # pre args
MAKE="$MAKE $ARG"
else # post args
MK_ARG="$MK_ARG $ARG"
fi
continue
fi
# should we just rebuild todays latest source...
if [[ "$ARG" = "-r" || "$ARG" = "--respin" || "$ARG" = "respin" ]]; then
RESPIN="yes"
continue
fi
# should we just run post build command...
if [[ "$ARG" = "-p" || "$ARG" = "--postbuild" || "$ARG" = "postbuild" ]]; then
POSTBUILD="yes"
continue
fi
# should we just test remote connectivity and execute permissions...
if [[ "$ARG" = "-t" || "$ARG" = "--test" ]]; then
JUST_TEST="yes"
RESPIN="yes"
continue
fi
# We will pull source using: "$CHECKOUT"
# And build on each machine: "cd $BUILDDIR && $BUILDCMD"
# expand targets (but dont confuse hosts for targets (msg7))
# These will build just mstone
# expand targets (but dont confuse hosts for targets (msg7))
if [[ "$BUILDCMD" = "" && "$ARG" = mailstone* ]]; then
case ${ARG#mstone} in
"")
"42")
DESTTYPE=_MSTONE42
MS_BRANCH=""
#BUILDCMD="$MAKE $MK_ARG debug release"
#POSTCMD="$MAKE $MK_ARG all_DBG.OBJ all_OPT.OBJ"
BUILDCMD="$MAKE $MK_ARG rpackage"
POSTCMD="$MAKE $MK_ARG all_OPT"
;;
*)
echo "Unknown mstone version in $ARG"
echo "Try mstone42"
exit 1;;
esac
DESCRIPTION="Mstone $MS_BRANCH"
BUILDDIR=./mozilla/mstone
CVSROOT=$MOZCVSROOT
CHECKOUT="$CO_CMD $MS_BRANCH mozilla/mstone"
# BUG No way to unpack perl, gd, and gnuplot before building
continue
fi
#########################
# Other...
#########################
# These will print some tools info
if [[ "$ARG" = "tools" ]]; then
CHECKOUT="$CO_CMD modules"
BUILDDIR=.
BUILDCMD="which gcc && ls -l /tools/ns/bin/gcc && which gcc-2.7.2.1 && ls -l /tools/ns/bin/gcc-2.7.2.1"
continue
fi
#########################
# Everything else is assumed to be a hostname
#########################
BUILDHOSTS="$ARG $BUILDHOSTS"
done # for ARG in $*; do
if [[ "$BUILDHOSTS" = "" ]]; then
BUILDHOSTS=$DEFAULT_BUILDHOSTS
fi
if [[ "$BUILDCMD" = "" && "$JUST_TEST" = "no" ]]; then
usage
fi
########################################################################
# You shouldn't have to modify stuff below here too much
########################################################################
# Who and Where are we
PROG=buildall
RSH=rsh
SYS=`uname -s`
echo SYS=$SYS
if [[ "$SYS" = "HP-UX" ]]; then
RSH=remsh
fi
########################################################################
# Simple log output function
########################################################################
log() {
# echo "[`date +\"%Y/%m/%d %H:%M:%S\"`] $PROG: $*"
echo "`date +\"%H:%M:%S\"` $PROG: $*"
}
########################################################################
# Error
########################################################################
quit() {
log "$* (exiting)..."
exit 1
}
# Where should the work be done
REV=1
WORKDIR=$DESTBASE/`date +"%Y%m%d"`$DESTTYPE.$REV
LASTWORKDIR=$WORKDIR
LASTREV=$REV
while [[ -d $WORKDIR ]]; do
LASTREV=$REV
let "REV= REV + 1"
LASTWORKDIR=$WORKDIR
WORKDIR=$DESTBASE/`date +"%Y%m%d"`$DESTTYPE.$REV
done
if [[ "$RESPIN" = "yes" ]]; then
WORKDIR=$LASTWORKDIR
REV=$LASTREV
fi
BUILDREV=$REV
if [[ ! -d $WORKDIR && "$RESPIN" = "yes" ]]; then
quit "missing expected respin workdir ($WORKDIR)"
fi
mkdir -p $WORKDIR
# Where to send logs
LOGDIR=$WORKDIR/logs
[[ -d $LOGDIR ]] || mkdir $LOGDIR
# What tool to use for compressed tar
if [[ -x /tools/ns/bin/tar ]] ; then # ROBDAN 9-15-98 for Linux
TAR=/tools/ns/bin/tar
else
TAR=tar
fi
SRCDIR=$WORKDIR/src
SRCTAR=$WORKDIR/src.tar.gz
########################################################################
# The function which extracts the source and prepares for copies
########################################################################
prepare_source() {
log "Preparing source code..."
mkdir $SRCDIR
(cd $SRCDIR;
log "Extracting source in $SRCDIR...";
log "$CHECKOUT > $LOGDIR/cvs-co.txt";
$CHECKOUT > $LOGDIR/cvs-co.txt;
RET=$?
if [[ $RET -ne 0 ]]; then quit "### Failed($RET): $CHECKOUT"; fi
if [[ "$CHECKOUT2" != "" ]]; then
log "$CHECKOUT2 >> $LOGDIR/cvs-co.txt";
$CHECKOUT2 >> $LOGDIR/cvs-co.txt;
RET=$?
if [[ $RET -ne 0 ]]; then quit "### Failed($RET): $CHECKOUT2"; fi
fi
log "Listing source...";
ls -Rl > $LOGDIR/src-ls-Rl.txt
log "Archiving source..."
$TAR czf $SRCTAR .
)
RET=$?
if [[ $RET -ne 0 ]]; then
quit "### Failed($RET): cannot prepare source";
else
log "Source extraction complete";
fi
}
########################################################################
# The function which does a build
########################################################################
do_rbuild() {
OSDEST=$1
if [ "$SHARESRC" = "yes" ]; then
RSRCDIR=$SRCDIR
else
RSRCDIR=$WORKDIR/$OSDEST
fi
[[ -d $RSRCDIR ]] || mkdir -p $RSRCDIR
cd $RSRCDIR;
# do any late variable expansions
RAWCMD=$BUILDCMD
BUILDCMD=$(eval echo $RAWCMD)
if [[ $RHOST = localhost ]] ; then
log "Build locally for $OSDEST ($BUILDCMD)...";
cd $BUILDDIR && pwd && $BUILDCMD && echo $PROG: Success
RET=$?
if [[ $RET -ne 0 ]]; then quit "### Failed($RET): $OSDEST build"; fi
log "Completed local build..."
return
fi
if [[ "$SHARESRC" != "yes" ]]; then
log "Extracting source for $OSDEST...";
$RSH $RHOST -n "cd $RSRCDIR && pwd && $TAR xzf $SRCTAR";
RET=$?
if [[ $RET -ne 0 ]]; then quit "### Failed($RET): $OSDEST source extraction"; fi
else
log "Using common source in $RSRCDIR";
fi
log "Building for $OSDEST ($BUILDCMD)...";
$RSH $RHOST -n "cd $RSRCDIR/$BUILDDIR && pwd && $BUILDCMD && echo $PROG: Success"
RET=$?
if [[ $RET -ne 0 ]]; then quit "### Failed($RET): $OSDEST build"; fi
log "Completed $OSDEST...";
}
buildhost() {
RHOST=$1
log "Query $RHOST configuration...";
if [[ $RHOST = localhost ]] ; then
uname -s > /tmp/$$.$RHOST 2>&1
else
$RSH $RHOST -n "uname -s" > /tmp/$$.$RHOST 2>&1
RET=$?
if [[ $RET -ne 0 ]]; then
quit "..[$RHOST] ### Failed($RET): $RSH $RHOST -n \"uname -s\"";
fi
fi
ROSTYPE=`tail -1 /tmp/$$.$RHOST`
if [[ "$ROSTYPE" = "AIX" ]]; then
$RSH $RHOST -n "uname -v" > /tmp/$$.$RHOST 2>&1
ROSTYPE=${ROSTYPE}`tail -1 /tmp/$$.$RHOST`
fi
if [[ $RHOST = localhost ]] ; then
uname -r > /tmp/$$.$RHOST 2>&1
else
$RSH $RHOST -n "uname -r" > /tmp/$$.$RHOST 2>&1
fi
ROSREV=`tail -1 /tmp/$$.$RHOST`
rm /tmp/$$.$RHOST
if [[ $RHOST = localhost ]] ; then
OSDEST=`hostname | cut -f1 -d.`-${ROSTYPE}${ROSREV}
else
OSDEST=${RHOST}-${ROSTYPE}${ROSREV}
fi
log "..Building on [$OSDEST]..."
REV=1 # find unique logfile name
OSLOG=$LOGDIR/$OSDEST.$REV
while [[ -f $OSLOG ]]; do
let "REV = REV + 1"
OSLOG=$LOGDIR/$OSDEST.$REV
done
if [[ "$JUST_TEST" = "yes" ]]; then
echo "$PROG: Success" > $OSLOG
else
( do_rbuild $OSDEST ) > $OSLOG 2>&1
fi
grep "$PROG: Success" $OSLOG > /dev/null
RET=$?
if [[ $RET -eq 0 ]]; then
RESULT="SUCCESS";
else
RESULT="FAILURE($RET)";
fi
log "..Completed [$OSDEST] <$RESULT>.";
}
########################################################################
# The function which initiates all the builds
########################################################################
do_builds() {
log "Launching builds..."
for HOST in $BUILDHOSTS; do
buildhost $HOST &
done
}
########################################################################
# main
########################################################################
main() {
if [[ "$JUST_TEST" = "yes" ]]; then
log "Automated test starting..."
else
log "Automated build of [$DESCRIPTION] starting..."
fi
log ""
log " ARGS = $ARGS"
log " BUILDHOSTS = $BUILDHOSTS"
log " WORKDIR = $WORKDIR"
log " SRCDIR = $SRCDIR"
log " LOGDIR = $LOGDIR"
log " CHECKOUT = $CHECKOUT"
log " BUILDDIR = $BUILDDIR"
log " BUILDCMD = $BUILDCMD"
log " RESPIN = $RESPIN"
log ""
[[ "$RESPIN" = "no" ]] && prepare_source
do_builds
log "Waiting for all builds to complete..."
wait
log "All builds completed."
if [[ -n "$POSTCMD" && "$POSTBUILD" = "yes" ]] ; then
log "Running post build command."
REV=1 # find unique logfile name
POSTLOG=$LOGDIR/postbuild.$REV
while [[ -f $POSTLOG ]]; do
let "REV = REV + 1"
POSTLOG=$LOGDIR/postbuild.$REV
done
echo "Dir $SRCDIR/$BUILDDIR" > $POSTLOG
echo "Cmd $POSTCMD" >> $POSTLOG
(cd $SRCDIR/$BUILDDIR && $POSTCMD && echo $PROG: Success) >> $POSTLOG 2>&1
log "Post build command completed."
elif [[ -n "$POSTCMD" ]] ; then
echo "Skipping post build command: $POSTCMD"
fi
}
REV=1
PROGLOG=$LOGDIR/$PROG.$REV
while [[ -f $PROGLOG ]]; do
REV=`expr $REV + 1`
PROGLOG=$LOGDIR/$PROG.$REV
done
main | tee $PROGLOG 2>&1
exit 0

Some files were not shown because too many files have changed in this diff Show More