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
363 changed files with 29513 additions and 106012 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

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 B

View File

@@ -1,97 +0,0 @@
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Terry Weissman <terry@mozilla.org>
# Myk Melez <myk@mozilla.org>
############################################################################
# Module Initialization
############################################################################
use diagnostics;
use strict;
package Attachment;
# This module requires that its caller have said "require CGI.pl" to import
# relevant functions from that script and its companion globals.pl.
############################################################################
# Functions
############################################################################
sub query
{
# Retrieves and returns an array of attachment records for a given bug.
# This data should be given to attachment/list.atml in an
# "attachments" variable.
my ($bugid) = @_;
my $in_editbugs = &::UserInGroup("editbugs");
# Retrieve a list of attachments for this bug and write them into an array
# of hashes in which each hash represents a single attachment.
&::SendSQL("
SELECT attach_id, creation_ts, mimetype, description, ispatch,
isobsolete, submitter_id
FROM attachments WHERE bug_id = $bugid ORDER BY attach_id
");
my @attachments = ();
while (&::MoreSQLData()) {
my %a;
my $submitter_id;
($a{'attachid'}, $a{'date'}, $a{'contenttype'}, $a{'description'},
$a{'ispatch'}, $a{'isobsolete'}, $submitter_id) = &::FetchSQLData();
# Format the attachment's creation/modification date into a standard
# format (YYYY-MM-DD HH:MM)
if ($a{'date'} =~ /^(\d\d\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
$a{'date'} = "$1-$2-$3 $4:$5";
}
# Retrieve a list of status flags that have been set on the attachment.
&::PushGlobalSQLState();
&::SendSQL("
SELECT name
FROM attachstatuses, attachstatusdefs
WHERE attach_id = $a{'attachid'}
AND attachstatuses.statusid = attachstatusdefs.id
ORDER BY sortkey
");
my @statuses = ();
while (&::MoreSQLData()) {
my ($status) = &::FetchSQLData();
push @statuses , $status;
}
$a{'statuses'} = \@statuses;
&::PopGlobalSQLState();
# We will display the edit link if the user can edit the attachment;
# ie the are the submitter, or they have canedit.
# Also show the link if the user is not logged in - in that cae,
# They'll be prompted later
$a{'canedit'} = ($::userid == 0 || $submitter_id == $::userid ||
$in_editbugs);
push @attachments, \%a;
}
return \@attachments;
}
1;

View File

@@ -1,547 +0,0 @@
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Dawn Endico <endico@mozilla.org>
# Terry Weissman <terry@mozilla.org>
# Chris Yeh <cyeh@bluemartini.com>
use diagnostics;
use strict;
use DBI;
use RelationSet;
use vars qw($unconfirmedstate $legal_keywords);
require "globals.pl";
require "CGI.pl";
package Bug;
use CGI::Carp qw(fatalsToBrowser);
my %ok_field;
for my $key (qw (bug_id product version rep_platform op_sys bug_status
resolution priority bug_severity component assigned_to
reporter bug_file_loc short_desc target_milestone
qa_contact status_whiteboard creation_ts groupset
delta_ts votes whoid usergroupset comment query error) ){
$ok_field{$key}++;
}
# create a new empty bug
#
sub new {
my $type = shift();
my %bug;
# create a ref to an empty hash and bless it
#
my $self = {%bug};
bless $self, $type;
# construct from a hash containing a bug's info
#
if ($#_ == 1) {
$self->initBug(@_);
} else {
confess("invalid number of arguments \($#_\)($_)");
}
# bless as a Bug
#
return $self;
}
# dump info about bug into hash unless user doesn't have permission
# user_id 0 is used when person is not logged in.
#
sub initBug {
my $self = shift();
my ($bug_id, $user_id) = (@_);
my $old_bug_id = $bug_id;
if ((! defined $bug_id) || (!$bug_id) || (!&::detaint_natural($bug_id))) {
# no bug number given
$self->{'bug_id'} = $old_bug_id;
$self->{'error'} = "InvalidBugId";
return $self;
}
# default userid 0, or get DBID if you used an email address
unless (defined $user_id) {
$user_id = 0;
}
else {
if ($user_id =~ /^\@/) {
$user_id = &::DBname_to_id($user_id);
}
}
&::ConnectToDatabase();
&::GetVersionTable();
# this verification should already have been done by caller
# my $loginok = quietly_check_login();
$self->{'whoid'} = $user_id;
&::SendSQL("SELECT groupset FROM profiles WHERE userid=$self->{'whoid'}");
my $usergroupset = &::FetchOneColumn();
if (!$usergroupset) { $usergroupset = '0' }
$self->{'usergroupset'} = $usergroupset;
# Check to see if we can see this bug
if (!&::CanSeeBug($bug_id, $user_id, $usergroupset)) {
# Permission denied to see bug
$self->{'bug_id'} = $old_bug_id;
$self->{'error'} = "PermissionDenied";
return $self;
}
my $query = "";
if ($::driver eq 'mysql') {
$query = "
select
bugs.bug_id, product, version, rep_platform, op_sys, bug_status,
resolution, priority, bug_severity, component, assigned_to, reporter,
bug_file_loc, short_desc, target_milestone, qa_contact,
status_whiteboard, date_format(creation_ts,'%Y-%m-%d %H:%i'),
groupset, delta_ts, sum(votes.count)
from bugs left join votes using(bug_id)
where bugs.bug_id = $bug_id
group by bugs.bug_id";
} elsif ($::driver eq 'Pg') {
$query = "
select
bugs.bug_id, product, version, rep_platform, op_sys, bug_status,
resolution, priority, bug_severity, component, assigned_to, reporter,
bug_file_loc, short_desc, target_milestone, qa_contact,
status_whiteboard, creation_ts,
groupset, delta_ts, sum(votes.count)
from bugs left join votes using(bug_id)
where bugs.bug_id = $bug_id
and (bugs.groupset & int8($usergroupset)) = bugs.groupset
group by bugs.bug_id, product, version, rep_platform, op_sys, bug_status,
resolution, priority, bug_severity, component, assigned_to, reporter,
bug_file_loc, short_desc, target_milestone, qa_contact, status_whiteboard,
creation_ts, groupset, delta_ts";
}
&::SendSQL($query);
my @row;
if (@row = &::FetchSQLData()) {
my $count = 0;
my %fields;
foreach my $field ("bug_id", "product", "version", "rep_platform",
"op_sys", "bug_status", "resolution", "priority",
"bug_severity", "component", "assigned_to", "reporter",
"bug_file_loc", "short_desc", "target_milestone",
"qa_contact", "status_whiteboard", "creation_ts",
"groupset", "delta_ts", "votes") {
$fields{$field} = shift @row;
if ($fields{$field}) {
$self->{$field} = $fields{$field};
}
$count++;
}
} else {
&::SendSQL("select groupset from bugs where bug_id = $bug_id");
if (@row = &::FetchSQLData()) {
$self->{'bug_id'} = $bug_id;
$self->{'error'} = "NotPermitted";
return $self;
} else {
$self->{'bug_id'} = $bug_id;
$self->{'error'} = "NotFound";
return $self;
}
}
$self->{'assigned_to'} = &::DBID_to_name($self->{'assigned_to'});
$self->{'reporter'} = &::DBID_to_name($self->{'reporter'});
my $ccSet = new RelationSet;
$ccSet->mergeFromDB("select who from cc where bug_id=$bug_id");
my @cc = $ccSet->toArrayOfStrings();
if (@cc) {
$self->{'cc'} = \@cc;
}
if (&::Param("useqacontact") && (defined $self->{'qa_contact'}) ) {
my $name = $self->{'qa_contact'} > 0 ? &::DBID_to_name($self->{'qa_contact'}) :"";
if ($name) {
$self->{'qa_contact'} = $name;
}
}
if (@::legal_keywords) {
&::SendSQL("SELECT keyworddefs.name
FROM keyworddefs, keywords
WHERE keywords.bug_id = $bug_id
AND keyworddefs.id = keywords.keywordid
ORDER BY keyworddefs.name");
my @list;
while (&::MoreSQLData()) {
push(@list, &::FetchOneColumn());
}
if (@list) {
$self->{'keywords'} = join(', ', @list);
}
}
&::SendSQL("select attach_id, creation_ts, description
from attachments
where bug_id = $bug_id");
my @attachments;
while (&::MoreSQLData()) {
my ($attachid, $date, $desc) = (&::FetchSQLData());
if ($date =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
$date = "$3/$4/$2 $5:$6";
my %attach;
$attach{'attachid'} = $attachid;
$attach{'date'} = $date;
$attach{'desc'} = $desc;
push @attachments, \%attach;
}
}
if (@attachments) {
$self->{'attachments'} = \@attachments;
}
&::SendSQL("select bug_id, who, bug_when, thetext
from longdescs
where bug_id = $bug_id");
my @longdescs;
while (&::MoreSQLData()) {
my ($bug_id, $who, $bug_when, $thetext) = (&::FetchSQLData());
my %longdesc;
$longdesc{'who'} = $who;
$longdesc{'bug_when'} = $bug_when;
$longdesc{'thetext'} = $thetext;
push @longdescs, \%longdesc;
}
if (@longdescs) {
$self->{'longdescs'} = \@longdescs;
}
if (&::Param("usedependencies")) {
my @depends = EmitDependList("blocked", "dependson", $bug_id);
if ( @depends ) {
$self->{'dependson'} = \@depends;
}
my @blocks = EmitDependList("dependson", "blocked", $bug_id);
if ( @blocks ) {
$self->{'blocks'} = \@blocks;
}
}
return $self;
}
# given a bug hash, emit xml for it. with file header provided by caller
#
sub emitXML {
( $#_ == 0 ) || confess("invalid number of arguments");
my $self = shift();
my $xml;
if (exists $self->{'error'}) {
$xml .= "<bug error=\"$self->{'error'}\">\n";
$xml .= " <bug_id>$self->{'bug_id'}</bug_id>\n";
$xml .= "</bug>\n";
return $xml;
}
$xml .= "<bug>\n";
foreach my $field ("bug_id", "bug_status", "product",
"priority", "version", "rep_platform", "assigned_to", "delta_ts",
"component", "reporter", "target_milestone", "bug_severity",
"creation_ts", "qa_contact", "op_sys", "resolution", "bug_file_loc",
"short_desc", "keywords", "status_whiteboard") {
if ($self->{$field}) {
$xml .= " <$field>" . QuoteXMLChars($self->{$field}) . "</$field>\n";
}
}
foreach my $field ("dependson", "blocks", "cc") {
if (defined $self->{$field}) {
for (my $i=0 ; $i < @{$self->{$field}} ; $i++) {
$xml .= " <$field>" . $self->{$field}[$i] . "</$field>\n";
}
}
}
if (defined $self->{'longdescs'}) {
for (my $i=0 ; $i < @{$self->{'longdescs'}} ; $i++) {
$xml .= " <long_desc>\n";
$xml .= " <who>" . &::DBID_to_name($self->{'longdescs'}[$i]->{'who'})
. "</who>\n";
$xml .= " <bug_when>" . $self->{'longdescs'}[$i]->{'bug_when'}
. "</bug_when>\n";
$xml .= " <thetext>" . QuoteXMLChars($self->{'longdescs'}[$i]->{'thetext'})
. "</thetext>\n";
$xml .= " </long_desc>\n";
}
}
if (defined $self->{'attachments'}) {
for (my $i=0 ; $i < @{$self->{'attachments'}} ; $i++) {
$xml .= " <attachment>\n";
$xml .= " <attachid>" . $self->{'attachments'}[$i]->{'attachid'}
. "</attachid>\n";
$xml .= " <date>" . $self->{'attachments'}[$i]->{'date'} . "</date>\n";
$xml .= " <desc>" . QuoteXMLChars($self->{'attachments'}[$i]->{'desc'}) . "</desc>\n";
# $xml .= " <type>" . $self->{'attachments'}[$i]->{'type'} . "</type>\n";
# $xml .= " <data>" . $self->{'attachments'}[$i]->{'data'} . "</data>\n";
$xml .= " </attachment>\n";
}
}
$xml .= "</bug>\n";
return $xml;
}
sub EmitDependList {
my ($myfield, $targetfield, $bug_id) = (@_);
my @list;
&::SendSQL("select dependencies.$targetfield, bugs.bug_status
from dependencies, bugs
where dependencies.$myfield = $bug_id
and bugs.bug_id = dependencies.$targetfield
order by dependencies.$targetfield");
while (&::MoreSQLData()) {
my ($i, $stat) = (&::FetchSQLData());
push @list, $i;
}
return @list;
}
sub QuoteXMLChars {
$_[0] =~ s/&/&amp;/g;
$_[0] =~ s/</&lt;/g;
$_[0] =~ s/>/&gt;/g;
$_[0] =~ s/'/&apos;/g;
$_[0] =~ s/"/&quot;/g;
# $_[0] =~ s/([\x80-\xFF])/&XmlUtf8Encode(ord($1))/ge;
return($_[0]);
}
sub XML_Header {
my ($urlbase, $version, $maintainer, $exporter) = (@_);
my $xml;
$xml = "<?xml version=\"1.0\" standalone=\"yes\"?>\n";
$xml .= "<!DOCTYPE bugzilla SYSTEM \"$urlbase";
if (! ($urlbase =~ /.+\/$/)) {
$xml .= "/";
}
$xml .= "bugzilla.dtd\">\n";
$xml .= "<bugzilla";
if (defined $exporter) {
$xml .= " exporter=\"$exporter\"";
}
$xml .= " version=\"$version\"";
$xml .= " urlbase=\"$urlbase\"";
$xml .= " maintainer=\"$maintainer\">\n";
return ($xml);
}
sub XML_Footer {
return ("</bugzilla>\n");
}
sub UserInGroup {
my $self = shift();
my ($groupname) = (@_);
if ($self->{'usergroupset'} eq "0") {
return 0;
}
&::ConnectToDatabase();
&::SendSQL("select (group_bit & int8($self->{'usergroupset'})) != 0 from groups where name = "
. &::SqlQuote($groupname));
my $bit = &::FetchOneColumn();
if ($bit) {
return 1;
}
return 0;
}
sub CanChangeField {
my $self = shift();
my ($f, $oldvalue, $newvalue) = (@_);
my $UserInEditGroupSet = -1;
my $UserInCanConfirmGroupSet = -1;
my $ownerid;
my $reporterid;
my $qacontactid;
if ($f eq "assigned_to" || $f eq "reporter" || $f eq "qa_contact") {
if ($oldvalue =~ /^\d+$/) {
if ($oldvalue == 0) {
$oldvalue = "";
} else {
$oldvalue = &::DBID_to_name($oldvalue);
}
}
}
if ($oldvalue eq $newvalue) {
return 1;
}
if (&::trim($oldvalue) eq &::trim($newvalue)) {
return 1;
}
if ($f =~ /^longdesc/) {
return 1;
}
if ($UserInEditGroupSet < 0) {
$UserInEditGroupSet = UserInGroup($self, "editbugs");
}
if ($UserInEditGroupSet) {
return 1;
}
&::SendSQL("SELECT reporter, assigned_to, qa_contact FROM bugs " .
"WHERE bug_id = $self->{'bug_id'}");
($reporterid, $ownerid, $qacontactid) = (&::FetchSQLData());
# Let reporter change bug status, even if they can't edit bugs.
# If reporter can't re-open their bug they will just file a duplicate.
# While we're at it, let them close their own bugs as well.
if ( ($f eq "bug_status") && ($self->{'whoid'} eq $reporterid) ) {
return 1;
}
if ($f eq "bug_status" && $newvalue ne $::unconfirmedstate &&
&::IsOpenedState($newvalue)) {
# Hmm. They are trying to set this bug to some opened state
# that isn't the UNCONFIRMED state. Are they in the right
# group? Or, has it ever been confirmed? If not, then this
# isn't legal.
if ($UserInCanConfirmGroupSet < 0) {
$UserInCanConfirmGroupSet = &::UserInGroup("canconfirm");
}
if ($UserInCanConfirmGroupSet) {
return 1;
}
&::SendSQL("SELECT everconfirmed FROM bugs WHERE bug_id = $self->{'bug_id'}");
my $everconfirmed = FetchOneColumn();
if ($everconfirmed) {
return 1;
}
} elsif ($reporterid eq $self->{'whoid'} || $ownerid eq $self->{'whoid'} ||
$qacontactid eq $self->{'whoid'}) {
return 1;
}
$self->{'error'} = "
Only the owner or submitter of the bug, or a sufficiently
empowered user, may make that change to the $f field."
}
sub Collision {
my $self = shift();
my $write = "WRITE"; # Might want to make a param to control
# whether we do LOW_PRIORITY ...
if ($::driver eq 'mysql') {
&::SendSQL("LOCK TABLES bugs $write, bugs_activity $write, cc $write, " .
"cc AS selectVisible_cc $write, " .
"profiles $write, dependencies $write, votes $write, " .
"keywords $write, longdescs $write, fielddefs $write, " .
"keyworddefs READ, groups READ, attachments READ, products READ");
}
&::SendSQL("SELECT delta_ts FROM bugs where bug_id=$self->{'bug_id'}");
my $delta_ts = &::FetchOneColumn();
if ($::driver eq 'mysql') {
&::SendSQL("unlock tables");
}
if ($self->{'delta_ts'} ne $delta_ts) {
return 1;
}
else {
return 0;
}
}
sub AppendComment {
my $self = shift();
my ($comment) = (@_);
$comment =~ s/\r\n/\n/g; # Get rid of windows-style line endings.
$comment =~ s/\r/\n/g; # Get rid of mac-style line endings.
if ($comment =~ /^\s*$/) { # Nothin' but whitespace.
return;
}
&::SendSQL("INSERT INTO longdescs (bug_id, who, bug_when, thetext) " .
"VALUES($self->{'bug_id'}, $self->{'whoid'}, now(), " . &::SqlQuote($comment) . ")");
&::SendSQL("UPDATE bugs SET delta_ts = now() WHERE bug_id = $self->{'bug_id'}");
}
#from o'reilley's Programming Perl
sub display {
my $self = shift;
my @keys;
if (@_ == 0) { # no further arguments
@keys = sort keys(%$self);
} else {
@keys = @_; # use the ones given
}
foreach my $key (@keys) {
print "\t$key => $self->{$key}\n";
}
}
sub CommitChanges {
#snapshot bug
#snapshot dependencies
#check can change fields
#check collision
#lock and change fields
#notify through mail
}
sub AUTOLOAD {
use vars qw($AUTOLOAD);
my $self = shift;
my $type = ref($self) || $self;
my $attr = $AUTOLOAD;
$attr =~ s/.*:://;
return unless $attr=~ /[^A-Z]/;
if (@_) {
$self->{$attr} = shift;
return;
}
confess ("invalid bug attribute $attr") unless $ok_field{$attr};
if (defined $self->{$attr}) {
return $self->{$attr};
} else {
return '';
}
}
1;

File diff suppressed because it is too large Load Diff

View File

@@ -1,16 +0,0 @@
* This README is no longer used to house installation instructions. Instead,
it contains pointers to where you may find the information you need.
* Installation instructions are now found in docs/, with a variety of document
types available. Please refer to these documents when installing, configuring,
and maintaining your Bugzilla installation. A helpful starting point is
docs/txt/Bugzilla-Guide.txt, or with a web browser at docs/html/index.html.
* Release notes for people upgrading to a new version of Bugzilla are
available at docs/rel_notes.txt.
* If you wish to contribute to the documentation, please read docs/README.docs.
* The Bugzilla web site is at "http://www.mozilla.org/projects/bugzilla/".
This site will contain the latest Bugzilla information, including how to
report bugs and how to get help with Bugzilla.

View File

@@ -1,268 +0,0 @@
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 2000 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Dan Mosedale <dmose@mozilla.org>
# Terry Weissman <terry@mozilla.org>
# Dave Miller <justdave@syndicomm.com>
# This object models a set of relations between one item and a group
# of other items. An example is the set of relations between one bug
# and the users CCed on that bug. Currently, the relation objects are
# expected to be bugzilla userids. However, this could and perhaps
# should be generalized to work with non userid objects, such as
# keywords associated with a bug. That shouldn't be hard to do; it
# might involve turning this into a virtual base class, and having
# UserSet and KeywordSet types that inherit from it.
use diagnostics;
use strict;
# Everything that uses RelationSet should already have globals.pl loaded
# so we don't want to load it here. Doing so causes a loop in Perl because
# globals.pl turns around and does a 'use RelationSet'
# See http://bugzilla.mozilla.org/show_bug.cgi?id=72862
#require "globals.pl";
package RelationSet;
use CGI::Carp qw(fatalsToBrowser);
# create a new empty RelationSet
#
sub new {
my $type = shift();
# create a ref to an empty hash and bless it
#
my $self = {};
bless $self, $type;
# construct from a comma-delimited string
#
if ($#_ == 0) {
$self->mergeFromString($_[0]);
}
# unless this was a constructor for an empty list, somebody screwed up.
#
elsif ( $#_ != -1 ) {
confess("invalid number of arguments");
}
# bless as a RelationSet
#
return $self;
}
# Assumes that the set of relations "FROM $table WHERE $constantSql and
# $column = $value" is currently represented by $self, and this set should
# be updated to look like $other.
#
# Returns an array of two strings, one INSERT and one DELETE, which will
# make this change. Either or both strings may be the empty string,
# meaning that no INSERT or DELETE or both (respectively) need to be done.
#
# THE CALLER IS RESPONSIBLE FOR ANY DESIRED LOCKING AND/OR CONSISTENCY
# CHECKS (not to mention doing the SendSQL() calls).
#
sub generateSqlDeltas {
($#_ == 5) || confess("invalid number of arguments");
my ( $self, # instance ptr to set representing the existing state
$endState, # instance ptr to set representing the desired state
$table, # table where these relations are kept
$invariantName, # column held const for a RelationSet (often "bug_id")
$invariantValue, # what to hold the above column constant at
$columnName # the column which varies (often a userid)
) = @_;
# construct the insert list by finding relations which exist in the
# end state but not the current state.
#
my @endStateRelations = keys(%$endState);
my @insertList = ();
foreach ( @endStateRelations ) {
push ( @insertList, $_ ) if ( ! exists $$self{"$_"} );
}
# we've built the list. If it's non-null, add required sql chrome.
#
my $sqlInsert="";
if ( $#insertList > -1 ) {
$sqlInsert = "INSERT INTO $table ($invariantName, $columnName) VALUES " .
join (",",
map ( "($invariantValue, $_)" , @insertList )
);
}
# construct the delete list by seeing which relations exist in the
# current state but not the end state
#
my @selfRelations = keys(%$self);
my @deleteList = ();
foreach ( @selfRelations ) {
push (@deleteList, $_) if ( ! exists $$endState{"$_"} );
}
# we've built the list. if it's non-empty, add required sql chrome.
#
my $sqlDelete = "";
if ( $#deleteList > -1 ) {
$sqlDelete = "DELETE FROM $table WHERE $invariantName = $invariantValue " .
"AND $columnName IN ( " . join (",", @deleteList) . " )";
}
return ($sqlInsert, $sqlDelete);
}
# compare the current object with another.
#
sub isEqual {
($#_ == 1) || confess("invalid number of arguments");
my $self = shift();
my $other = shift();
# get arrays of the keys for faster processing
#
my @selfRelations = keys(%$self);
my @otherRelations = keys(%$other);
# make sure the arrays are the same size
#
return 0 if ( $#selfRelations != $#otherRelations );
# bail out if any of the elements are different
#
foreach my $relation ( @selfRelations ) {
return 0 if ( !exists $$other{$relation})
}
# we made it!
#
return 1;
}
# merge the results of a SQL command into this set
#
sub mergeFromDB {
( $#_ == 1 ) || confess("invalid number of arguments");
my $self = shift();
&::SendSQL(shift());
while (my @row = &::FetchSQLData()) {
$$self{$row[0]} = 1;
}
return;
}
# merge a set in string form into this set
#
sub mergeFromString {
($#_ == 1) || confess("invalid number of arguments");
my $self = shift();
# do the merge
#
foreach my $person (split(/[ ,]/, shift())) {
if ($person ne "") {
$$self{&::DBNameToIdAndCheck($person)} = 1;
}
}
}
# remove a set in string form from this set
#
sub removeItemsInString {
($#_ == 1) || confess("invalid number of arguments");
my $self = shift();
# do the merge
#
foreach my $person (split(/[ ,]/, shift())) {
if ($person ne "") {
my $dbid = &::DBNameToIdAndCheck($person);
if (exists $$self{$dbid}) {
delete $$self{$dbid};
}
}
}
}
# remove a set in array form from this set
#
sub removeItemsInArray {
($#_ > 0) || confess("invalid number of arguments");
my $self = shift();
# do the merge
#
while (my $person = shift()) {
if ($person ne "") {
my $dbid = &::DBNameToIdAndCheck($person);
if (exists $$self{$dbid}) {
delete $$self{$dbid};
}
}
}
}
# return the number of elements in this set
#
sub size {
my $self = shift();
my @k = keys(%$self);
return $#k++;
}
# return this set in array form
#
sub toArray {
my $self= shift();
return keys(%$self);
}
# return this set as an array of strings
#
sub toArrayOfStrings {
($#_ == 0) || confess("invalid number of arguments");
my $self = shift();
my @result = ();
foreach my $i ( keys %$self ) {
push @result, &::DBID_to_name($i);
}
return sort { lc($a) cmp lc($b) } @result;
}
# return this set in string form (comma-separated and sorted)
#
sub toString {
($#_ == 0) || confess("invalid number of arguments");
my $self = shift();
my @result = ();
foreach my $i ( keys %$self ) {
push @result, &::DBID_to_name($i);
}
return join(',', sort(@result));
}
1;

View File

@@ -1,273 +0,0 @@
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Myk Melez <myk@mozilla.org>
################################################################################
# Module Initialization
################################################################################
# Make it harder for us to do dangerous things in Perl.
use diagnostics;
use strict;
# Bundle the functions in this file together into the "Token" package.
package Token;
use Date::Format;
# This module requires that its caller have said "require CGI.pl" to import
# relevant functions from that script and its companion globals.pl.
################################################################################
# Constants
################################################################################
# The maximum number of days a token will remain valid.
my $maxtokenage = 3;
################################################################################
# Functions
################################################################################
sub IssueEmailChangeToken {
my ($userid, $old_email, $new_email) = @_;
my $token_ts = time();
my $issuedate = time2str("%Y-%m-%d %H:%M", $token_ts);
# Generate a unique token and insert it into the tokens table.
# We have to lock the tokens table before generating the token,
# since the database must be queried for token uniqueness.
&::SendSQL("LOCK TABLES tokens WRITE");
my $token = GenerateUniqueToken();
my $quotedtoken = &::SqlQuote($token);
my $quoted_emails = &::SqlQuote($old_email . ":" . $new_email);
&::SendSQL("INSERT INTO tokens ( userid , issuedate , token ,
tokentype , eventdata )
VALUES ( $userid , '$issuedate' , $quotedtoken ,
'emailold' , $quoted_emails )");
my $newtoken = GenerateUniqueToken();
$quotedtoken = &::SqlQuote($newtoken);
&::SendSQL("INSERT INTO tokens ( userid , issuedate , token ,
tokentype , eventdata )
VALUES ( $userid , '$issuedate' , $quotedtoken ,
'emailnew' , $quoted_emails )");
&::SendSQL("UNLOCK TABLES");
# Mail the user the token along with instructions for using it.
my $template = $::template;
my $vars = $::vars;
$vars->{'oldemailaddress'} = $old_email . &::Param('emailsuffix');
$vars->{'newemailaddress'} = $new_email . &::Param('emailsuffix');
$vars->{'max_token_age'} = $maxtokenage;
$vars->{'token_ts'} = $token_ts;
$vars->{'token'} = $token;
$vars->{'emailaddress'} = $old_email . &::Param('emailsuffix');
my $message;
$template->process("account/email/change-old.txt.tmpl", $vars, \$message)
|| &::ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i";
print SENDMAIL $message;
close SENDMAIL;
$vars->{'token'} = $newtoken;
$vars->{'emailaddress'} = $new_email . &::Param('emailsuffix');
$message = "";
$template->process("account/email/change-new.txt.tmpl", $vars, \$message)
|| &::ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i";
print SENDMAIL $message;
close SENDMAIL;
}
sub IssuePasswordToken {
# Generates a random token, adds it to the tokens table, and sends it
# to the user with instructions for using it to change their password.
my ($loginname) = @_;
# Retrieve the user's ID from the database.
my $quotedloginname = &::SqlQuote($loginname);
&::SendSQL("SELECT userid FROM profiles WHERE login_name = $quotedloginname");
my ($userid) = &::FetchSQLData();
my $token_ts = time();
my $issuedate = time2str("%Y-%m-%d %H:%M", $token_ts);
# Generate a unique token and insert it into the tokens table.
# We have to lock the tokens table before generating the token,
# since the database must be queried for token uniqueness.
&::SendSQL("LOCK TABLE tokens WRITE") if $::driver eq 'mysql';
my $token = GenerateUniqueToken();
my $quotedtoken = &::SqlQuote($token);
my $quotedipaddr = &::SqlQuote($::ENV{'REMOTE_ADDR'});
&::SendSQL("INSERT INTO tokens ( userid , issuedate , token , tokentype , eventdata )
VALUES ( $userid , '$issuedate' , $quotedtoken , 'password' , $quotedipaddr )");
&::SendSQL("UNLOCK TABLES") if $::driver eq 'mysql';
# Mail the user the token along with instructions for using it.
my $template = $::template;
my $vars = $::vars;
$vars->{'token'} = $token;
$vars->{'emailaddress'} = $loginname . &::Param('emailsuffix');
$vars->{'max_token_age'} = $maxtokenage;
$vars->{'token_ts'} = $token_ts;
my $message = "";
$template->process("account/password/forgotten-password.txt.tmpl",
$vars, \$message)
|| &::ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i";
print SENDMAIL $message;
close SENDMAIL;
}
sub CleanTokenTable {
&::SendSQL("LOCK TABLES tokens WRITE") if $::driver eq 'mysql';
if ($::driver eq 'mysql') {
&::SendSQL("DELETE FROM tokens WHERE TO_DAYS(NOW()) - TO_DAYS(issuedate) >= " . $maxtokenage);
} elsif ($::driver eq 'Pg') {
&::SendSQL("DELETE FROM tokens WHERE now() - issuedate >= '$maxtokenage days'");
}
&::SendSQL("UNLOCK TABLES") if $::driver eq 'mysql';
}
sub GenerateUniqueToken {
# Generates a unique random token. Uses &GenerateRandomPassword
# for the tokens themselves and checks uniqueness by searching for
# the token in the "tokens" table. Gives up if it can't come up
# with a token after about one hundred tries.
my $token;
my $duplicate = 1;
my $tries = 0;
while ($duplicate) {
++$tries;
if ($tries > 100) {
&::DisplayError("Something is seriously wrong with the token generation system.");
exit;
}
$token = &::GenerateRandomPassword();
&::SendSQL("SELECT userid FROM tokens WHERE token = " . &::SqlQuote($token));
$duplicate = &::FetchSQLData();
}
return $token;
}
sub Cancel {
# Cancels a previously issued token and notifies the system administrator.
# This should only happen when the user accidentally makes a token request
# or when a malicious hacker makes a token request on behalf of a user.
my ($token, $cancelaction) = @_;
# Quote the token for inclusion in SQL statements.
my $quotedtoken = &::SqlQuote($token);
# Get information about the token being cancelled.
&::SendSQL("SELECT issuedate , tokentype , eventdata , login_name , realname
FROM tokens, profiles
WHERE tokens.userid = profiles.userid
AND token = $quotedtoken");
my ($issuedate, $tokentype, $eventdata, $loginname, $realname) = &::FetchSQLData();
# Get the email address of the Bugzilla maintainer.
my $maintainer = &::Param('maintainer');
# Format the user's real name and email address into a single string.
my $username = $realname ? $realname . " <" . $loginname . ">" : $loginname;
my $template = $::template;
my $vars = $::vars;
$vars->{'emailaddress'} = $username;
$vars->{'maintainer'} = $maintainer;
$vars->{'remoteaddress'} = $::ENV{'REMOTE_ADDR'};
$vars->{'token'} = $token;
$vars->{'tokentype'} = $tokentype;
$vars->{'issuedate'} = $issuedate;
$vars->{'eventdata'} = $eventdata;
$vars->{'cancelaction'} = $cancelaction;
# Notify the user via email about the cancellation.
my $message;
$template->process("account/cancel-token.txt.tmpl", $vars, \$message)
|| &::ThrowTemplateError($template->error());
open SENDMAIL, "|/usr/lib/sendmail -t -i";
print SENDMAIL $message;
close SENDMAIL;
# Delete the token from the database.
&::SendSQL("LOCK TABLE tokens WRITE") if $::driver eq 'mysql';
&::SendSQL("DELETE FROM tokens WHERE token = $quotedtoken");
&::SendSQL("UNLOCK TABLES") if $::driver eq 'mysql';
}
sub HasPasswordToken {
# Returns a password token if the user has one.
my ($userid) = @_;
&::SendSQL("SELECT token FROM tokens
WHERE userid = $userid AND tokentype = 'password' LIMIT 1");
my ($token) = &::FetchSQLData();
return $token;
}
sub HasEmailChangeToken {
# Returns an email change token if the user has one.
my ($userid) = @_;
&::SendSQL("SELECT token FROM tokens
WHERE userid = $userid
AND tokentype = 'emailnew'
OR tokentype = 'emailold' LIMIT 1");
my ($token) = &::FetchSQLData();
return $token;
}
1;

View File

@@ -1,3 +0,0 @@
Please consult The Bugzilla Guide for instructions on how to upgrade
Bugzilla from an older version. The Guide can be found with this
distribution, in docs/html, docs/txt, and docs/sgml.

View File

@@ -1,407 +0,0 @@
This file contains only important changes made to Bugzilla before release
2.8. If you are upgrading from version older than 2.8, please read this file.
If you are upgrading from 2.8 or newer, please read the Installation and
Upgrade instructions in The Bugzilla Guide, found with this distribution in
docs/html, docs/txt, and docs/sgml.
For a complete list of what changes, use Bonsai
(http://cvs-mirror.mozilla.org/webtools/bonsai/cvsqueryform.cgi) to
query the CVS tree. For example,
http://cvs-mirror.mozilla.org/webtools/bonsai/cvsquery.cgi?module=all&branch=HEAD&branchtype=match&dir=mozilla%2Fwebtools%2Fbugzilla&file=&filetype=match&who=&whotype=match&sortby=Date&hours=2&date=week&mindate=&maxdate=&cvsroot=%2Fcvsroot
will tell you what has been changed in the last week.
10/12/99 The CHANGES file is now obsolete! There is a new file called
checksetup.pl. You should get in the habit of running that file every time
you update your installation of Bugzilla. That file will be constantly
updated to automatically update your installation to match any code changes.
If you're curious as to what is going on, changes are commented in that file,
at the end.
Many thanks to Holger Schurig <holgerschurig@nikocity.de> for writing this
script!
10/11/99 Restructured voting database to add a cached value in each
bug recording how many total votes that bug has. While I'm at it, I
removed the unused "area" field from the bugs database. It is
distressing to realize that the bugs table has reached the maximum
number of indices allowed by MySQL (16), which may make future
enhancements awkward.
You must feed the following to MySQL:
alter table bugs drop column area;
alter table bugs add column votes mediumint not null, add index (votes);
You then *must* delete the data/versioncache file when you make this
change, as it contains references to the "area" field. Deleting it is safe,
bugzilla will correctly regenerate it.
If you have been using the voting feature at all, then you will then
need to update the voting cache. You can do this by visiting the
sanitycheck.cgi page, and taking it up on its offer to rebuild the
votes stuff.
10/7/99 Added voting ability. You must run the new script
"makevotestable.sh". You must also feed the following to mysql:
alter table products add column votesperuser smallint not null;
9/15/99 Apparently, newer alphas of MySQL won't allow you to have
"when" as a column name. So, I have had to rename a column in the
bugs_activity table. You must feed the below to mysql or you won't
work at all.
alter table bugs_activity change column when bug_when datetime not null;
8/16/99 Added "OpenVMS" to the list of OS's. Feed this to mysql:
alter table bugs change column op_sys op_sys enum("All", "Windows 3.1", "Windows 95", "Windows 98", "Windows NT", "Mac System 7", "Mac System 7.5", "Mac System 7.6.1", "Mac System 8.0", "Mac System 8.5", "Mac System 8.6", "AIX", "BSDI", "HP-UX", "IRIX", "Linux", "FreeBSD", "OSF/1", "Solaris", "SunOS", "Neutrino", "OS/2", "BeOS", "OpenVMS", "other") not null;
6/22/99 Added an entry to the attachments table to record who the submitter
was. Nothing uses this yet, but it still should be recorded.
alter table attachments add column submitter_id mediumint not null;
You should also run this script to populate the new field:
#!/usr/bonsaitools/bin/perl -w
use diagnostics;
use strict;
require "globals.pl";
$|=1;
ConnectToDatabase();
SendSQL("select bug_id, attach_id from attachments order by bug_id");
my @list;
while (MoreSQLData()) {
my @row = FetchSQLData();
push(@list, \@row);
}
foreach my $ref (@list) {
my ($bug, $attach) = (@$ref);
SendSQL("select long_desc from bugs where bug_id = $bug");
my $comment = FetchOneColumn() . "Created an attachment (id=$attach)";
if ($comment =~ m@-* Additional Comments From ([^ ]*)[- 0-9/:]*\nCreated an attachment \(id=$attach\)@) {
print "Found $1\n";
SendSQL("select userid from profiles where login_name=" .
SqlQuote($1));
my $userid = FetchOneColumn();
if (defined $userid && $userid > 0) {
SendSQL("update attachments set submitter_id=$userid where attach_id = $attach");
}
} else {
print "Bug $bug can't find comment for attachment $attach\n";
}
}
6/14/99 Added "BeOS" to the list of OS's. Feed this to mysql:
alter table bugs change column op_sys op_sys enum("All", "Windows 3.1", "Windows 95", "Windows 98", "Windows NT", "Mac System 7", "Mac System 7.5", "Mac System 7.6.1", "Mac System 8.0", "Mac System 8.5", "Mac System 8.6", "AIX", "BSDI", "HP-UX", "IRIX", "Linux", "FreeBSD", "OSF/1", "Solaris", "SunOS", "Neutrino", "OS/2", "BeOS", "other") not null;
5/27/99 Added support for dependency information. You must run the new
"makedependenciestable.sh" script. You can turn off dependencies with the new
"usedependencies" param, but it defaults to being on. Also, read very
carefully the description for the new "webdotbase" param; you will almost
certainly need to tweak it.
5/24/99 Added "Mac System 8.6" and "Neutrino" to the list of OS's.
Feed this to mysql:
alter table bugs change column op_sys op_sys enum("All", "Windows 3.1", "Windows 95", "Windows 98", "Windows NT", "Mac System 7", "Mac System 7.5", "Mac System 7.6.1", "Mac System 8.0", "Mac System 8.5", "Mac System 8.6", "AIX", "BSDI", "HP-UX", "IRIX", "Linux", "FreeBSD", "OSF/1", "Solaris", "SunOS", "Neutrino", "OS/2", "other") not null;
5/12/99 Added a pref to control how much email you get. This needs a new
column in the profiles table, so feed the following to mysql:
alter table profiles add column emailnotification enum("ExcludeSelfChanges", "CConly", "All") not null default "ExcludeSelfChanges";
5/5/99 Added the ability to search by creation date. To make this perform
well, you ought to do the following:
alter table bugs change column creation_ts creation_ts datetime not null, add index (creation_ts);
4/30/99 Added a new severity, "blocker". To get this into your running
Bugzilla, do the following:
alter table bugs change column bug_severity bug_severity enum("blocker", "critical", "major", "normal", "minor", "trivial", "enhancement") not null;
4/22/99 There was a bug where the long descriptions of bugs had a variety of
newline characters at the end, depending on the operating system of the browser
that submitted the text. This bug has been fixed, so that no further changes
like that will happen. But to fix problems that have already crept into your
database, you can run the following perl script (which is slow and ugly, but
does work:)
#!/usr/bonsaitools/bin/perl -w
use diagnostics;
use strict;
require "globals.pl";
$|=1;
ConnectToDatabase();
SendSQL("select bug_id from bugs order by bug_id");
my @list;
while (MoreSQLData()) {
push(@list, FetchOneColumn());
}
foreach my $id (@list) {
if ($id % 50 == 0) {
print "\n$id ";
}
SendSQL("select long_desc from bugs where bug_id = $id");
my $comment = FetchOneColumn();
my $orig = $comment;
$comment =~ s/\r\n/\n/g; # Get rid of windows-style line endings.
$comment =~ s/\r/\n/g; # Get rid of mac-style line endings.
if ($comment ne $orig) {
SendSQL("update bugs set long_desc = " . SqlQuote($comment) .
" where bug_id = $id");
print ".";
} else {
print "-";
}
}
4/8/99 Added ability to store patches with bugs. This requires a new table
to store the data, so you will need to run the "makeattachmenttable.sh" script.
3/25/99 Unfortunately, the HTML::FromText CPAN module had too many bugs, and
so I had to roll my own. We no longer use the HTML::FromText CPAN module.
3/24/99 (This entry has been removed. It used to say that we required the
HTML::FromText CPAN module, but that's no longer true.)
3/22/99 Added the ability to query by fields which have changed within a date
range. To make this perform a bit better, we need a new index:
alter table bugs_activity add index (field);
3/10/99 Added 'groups' stuff, where we have different group bits that we can
put on a person or on a bug. Some of the group bits control access to bugzilla
features. And a person can't access a bug unless he has every group bit set
that is also set on the bug. See the comments in makegroupstable.sh for a bit
more info.
The 'maintainer' param is now used only as an email address for people to send
complaints to. The groups table is what is now used to determine permissions.
You will need to run the new script "makegroupstable.sh". And then you need to
feed the following lines to MySQL (replace XXX with the login name of the
maintainer, the person you wish to be all-powerful).
alter table bugs add column groupset bigint not null;
alter table profiles add column groupset bigint not null;
update profiles set groupset=0x7fffffffffffffff where login_name = XXX;
3/8/99 Added params to control how priorities are set in a new bug. You can
now choose whether to let submitters of new bugs choose a priority, or whether
they should just accept the default priority (which is now no longer hardcoded
to "P2", but is instead a param.) The default value of the params will cause
the same behavior as before.
3/3/99 Added a "disallownew" field to the products table. If non-zero, then
don't let people file new bugs against this product. (This is for when a
product is retired, but you want to keep the bug reports around for posterity.)
Feed this to MySQL:
alter table products add column disallownew tinyint not null;
2/8/99 Added FreeBSD to the list of OS's. Feed this to MySQL:
alter table bugs change column op_sys op_sys enum("All", "Windows 3.1", "Windows 95", "Windows 98", "Windows NT", "Mac System 7", "Mac System 7.5", "Mac System 7.6.1", "Mac System 8.0", "Mac System 8.5", "AIX", "BSDI", "HP-UX", "IRIX", "Linux", "FreeBSD", "OSF/1", "Solaris", "SunOS", "OS/2", "other") not null;
2/4/99 Added a new column "description" to the components table, and added
links to a new page which will use this to describe the components of a
given product. Feed this to MySQL:
alter table components add column description mediumtext not null;
2/3/99 Added a new column "initialqacontact" to the components table that gives
an initial QA contact field. It may be empty if you wish the initial qa
contact to be empty. If you're not using the QA contact field, you don't need
to add this column, but you might as well be safe and add it anyway:
alter table components add column initialqacontact tinytext not null;
2/2/99 Added a new column "milestoneurl" to the products table that gives a URL
which is to describe the currently defined milestones for a product. If you
don't use target milestone, you might be able to get away without adding this
column, but you might as well be safe and add it anyway:
alter table products add column milestoneurl tinytext not null;
1/29/99 Whoops; had a misspelled op_sys. It was "Mac System 7.1.6"; it should
be "Mac System 7.6.1". It turns out I had no bugs with this value set, so I
could just do the below simple command. If you have bugs with this value, you
may need to do something more complicated.
alter table bugs change column op_sys op_sys enum("All", "Windows 3.1", "Windows 95", "Windows 98", "Windows NT", "Mac System 7", "Mac System 7.5", "Mac System 7.6.1", "Mac System 8.0", "Mac System 8.5", "AIX", "BSDI", "HP-UX", "IRIX", "Linux", "OSF/1", "Solaris", "SunOS", "OS/2", "other") not null;
1/20/99 Added new fields: Target Milestone, QA Contact, and Status Whiteboard.
These fields are all optional in the UI; there are parameters to turn them on.
However, whether or not you use them, the fields need to be in the DB. There
is some code that needs them, even if you don't.
To update your DB to have these fields, send the following to MySQL:
alter table bugs add column target_milestone varchar(20) not null,
add column qa_contact mediumint not null,
add column status_whiteboard mediumtext not null,
add index (target_milestone), add index (qa_contact);
1/18/99 You can now query by CC. To make this perform reasonably, the CC table
needs some indices. The following MySQL does the necessary stuff:
alter table cc add index (bug_id), add index (who);
1/15/99 The op_sys field can now be queried by (and more easily tweaked).
To make this perform reasonably, it needs an index. The following MySQL
command will create the necessary index:
alter table bugs add index (op_sys);
12/2/98 The op_sys and rep_platform fields have been tweaked. op_sys
is now an enum, rather than having the legal values all hard-coded in
perl. rep_platform now no longer allows a value of "X-Windows".
Here's how I ported to the new world. This ought to work for you too.
Actually, it's probably overkill. I had a lot of illegal values for op_sys
in my tables, from importing bugs from strange places. If you haven't done
anything funky, then much of the below will be a no-op.
First, send the following commands to MySQL to make sure all your values for
rep_platform and op_sys are legal in the new world..
update bugs set rep_platform="Sun" where rep_platform="X-Windows" and op_sys like "Solaris%";
update bugs set rep_platform="SGI" where rep_platform="X-Windows" and op_sys = "IRIX";
update bugs set rep_platform="SGI" where rep_platform="X-Windows" and op_sys = "HP-UX";
update bugs set rep_platform="DEC" where rep_platform="X-Windows" and op_sys = "OSF/1";
update bugs set rep_platform="PC" where rep_platform="X-Windows" and op_sys = "Linux";
update bugs set rep_platform="other" where rep_platform="X-Windows";
update bugs set rep_platform="other" where rep_platform="";
update bugs set op_sys="Mac System 7" where op_sys="System 7";
update bugs set op_sys="Mac System 7.5" where op_sys="System 7.5";
update bugs set op_sys="Mac System 8.0" where op_sys="8.0";
update bugs set op_sys="OSF/1" where op_sys="Digital Unix 4.0";
update bugs set op_sys="IRIX" where op_sys like "IRIX %";
update bugs set op_sys="HP-UX" where op_sys like "HP-UX %";
update bugs set op_sys="Windows NT" where op_sys like "NT %";
update bugs set op_sys="OSF/1" where op_sys like "OSF/1 %";
update bugs set op_sys="Solaris" where op_sys like "Solaris %";
update bugs set op_sys="SunOS" where op_sys like "SunOS%";
update bugs set op_sys="other" where op_sys = "Motif";
update bugs set op_sys="other" where op_sys = "Other";
Next, send the following commands to make sure you now have only legal
entries in your table. If either of the queries do not come up empty, then
you have to do more stuff like the above.
select bug_id,op_sys,rep_platform from bugs where rep_platform not regexp "^(All|DEC|HP|Macintosh|PC|SGI|Sun|X-Windows|Other)$";
select bug_id,op_sys,rep_platform from bugs where op_sys not regexp "^(All|Windows 3.1|Windows 95|Windows 98|Windows NT|Mac System 7|Mac System 7.5|Mac System 7.1.6|Mac System 8.0|AIX|BSDI|HP-UX|IRIX|Linux|OSF/1|Solaris|SunOS|other)$";
Finally, once that's all clear, alter the table to make enforce the new legal
entries:
alter table bugs change column op_sys op_sys enum("All", "Windows 3.1", "Windows 95", "Windows 98", "Windows NT", "Mac System 7", "Mac System 7.5", "Mac System 7.1.6", "Mac System 8.0", "AIX", "BSDI", "HP-UX", "IRIX", "Linux", "OSF/1", "Solaris", "SunOS", "other") not null, change column rep_platform rep_platform enum("All", "DEC", "HP", "Macintosh", "PC", "SGI", "Sun", "Other");
11/20/98 Added searching of CC field. To better support this, added
some indexes to the CC table. You probably want to execute the following
mysql commands:
alter table cc add index (bug_id);
alter table cc add index (who);
10/27/98 security check for legal products in place. bug charts are not
available as an option if collectstats.pl has never been run. all products
get daily stats collected now. README updated: Chart::Base is listed as
a requirement, instructions for using collectstats.pl included as
an optional step. also got silly and added optional quips to bug
reports.
10/17/98 modified README installation instructions slightly.
10/7/98 Added a new table called "products". Right now, this is used
only to have a description for each product, and that description is
only used when initially adding a new bug. Anyway, you *must* create
the new table (which you can do by running the new makeproducttable.sh
script). If you just leave it empty, things will work much as they
did before, or you can add descriptions for some or all of your
products.
9/15/98 Everything has been ported to Perl. NO MORE TCL. This
transition should be relatively painless, except for the "params"
file. This is the file that contains parameters you've set up on the
editparams.cgi page. Before changing to Perl, this was a tcl-syntax
file, stored in the same directory as the code; after the change to
Perl, it becomes a perl-syntax file, stored in a subdirectory named
"data". See the README file for more details on what version of Perl
you need.
So, if updating from an older version of Bugzilla, you will need to
edit data/param, change the email address listed for
$::param{'maintainer'}, and then go revisit the editparams.cgi page
and reset all the parameters to your taste. Fortunately, your old
params file will still be around, and so you ought to be able to
cut&paste important bits from there.
Also, note that the "whineatnews" script has changed name (it now has
an extension of .pl instead of .tcl), so you'll need to change your
cron job.
And the "comments" file has been moved to the data directory. Just do
"cat comments >> data/comments" to restore any old comments that may
have been lost.
9/2/98 Changed the way password validation works. We now keep a
crypt'd version of the password in the database, and check against
that. (This is silly, because we're also keeping the plaintext
version there, but I have plans...) Stop passing the plaintext
password around as a cookie; instead, we have a cookie that references
a record in a new database table, logincookies.
IMPORTANT: if updating from an older version of Bugzilla, you must run
the following commands to keep things working:
./makelogincookiestable.sh
echo "alter table profiles add column cryptpassword varchar(64);" | mysql bugs
echo "update profiles set cryptpassword = encrypt(password,substring(rand(),3, 4));" | mysql bugs

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.3 KiB

View File

@@ -1,792 +0,0 @@
#!/usr/bonsaitools/bin/perl -wT
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Terry Weissman <terry@mozilla.org>
# Myk Melez <myk@mozilla.org>
################################################################################
# Script Initialization
################################################################################
# Make it harder for us to do dangerous things in Perl.
use diagnostics;
use strict;
use lib qw(.);
use vars qw(
$template
$vars
);
# Include the Bugzilla CGI and general utility library.
require "CGI.pl";
# Establish a connection to the database backend.
ConnectToDatabase();
# Check whether or not the user is logged in and, if so, set the $::userid
# and $::usergroupset variables.
quietly_check_login();
################################################################################
# Main Body Execution
################################################################################
# All calls to this script should contain an "action" variable whose value
# determines what the user wants to do. The code below checks the value of
# that variable and runs the appropriate code.
# Determine whether to use the action specified by the user or the default.
my $action = $::FORM{'action'} || 'view';
if ($action eq "view")
{
validateID();
view();
}
elsif ($action eq "viewall")
{
ValidateBugID($::FORM{'bugid'});
viewall();
}
elsif ($action eq "enter")
{
confirm_login();
ValidateBugID($::FORM{'bugid'});
enter();
}
elsif ($action eq "insert")
{
confirm_login();
ValidateBugID($::FORM{'bugid'});
ValidateComment($::FORM{'comment'});
validateFilename();
validateData();
validateDescription();
validateIsPatch();
validateContentType() unless $::FORM{'ispatch'};
validateObsolete() if $::FORM{'obsolete'};
insert();
}
elsif ($action eq "edit")
{
quietly_check_login();
validateID();
validateCanEdit($::FORM{'id'});
edit();
}
elsif ($action eq "update")
{
confirm_login();
ValidateComment($::FORM{'comment'});
validateID();
validateCanEdit($::FORM{'id'});
validateDescription();
validateIsPatch();
validateContentType() unless $::FORM{'ispatch'};
validateIsObsolete();
validateStatuses();
update();
}
else
{
DisplayError("I could not figure out what you wanted to do.")
}
exit;
################################################################################
# Data Validation / Security Authorization
################################################################################
sub validateID
{
# Validate the value of the "id" form field, which must contain an
# integer that is the ID of an existing attachment.
detaint_natural($::FORM{'id'})
|| DisplayError("You did not enter a valid attachment number.")
&& exit;
# Make sure the attachment exists in the database.
SendSQL("SELECT bug_id FROM attachments WHERE attach_id = $::FORM{'id'}");
MoreSQLData()
|| DisplayError("Attachment #$::FORM{'id'} does not exist.")
&& exit;
# Make sure the user is authorized to access this attachment's bug.
my ($bugid) = FetchSQLData();
ValidateBugID($bugid);
}
sub validateCanEdit
{
my ($attach_id) = (@_);
# If the user is not logged in, claim that they can edit. This allows
# the edit scrren to be displayed to people who aren't logged in.
# People not logged in can't actually commit changes, because that code
# calls confirm_login, not quietly_check_login, before calling this sub
return if $::userid == 0;
# People in editbugs can edit all attachments
return if UserInGroup("editbugs");
# Bug 97729 - the submitter can edit their attachments
SendSQL("SELECT attach_id FROM attachments WHERE " .
"attach_id = $attach_id AND submitter_id = $::userid");
FetchSQLData()
|| DisplayError("You are not authorised to edit attachment #$attach_id")
&& exit;
}
sub validateDescription
{
$::FORM{'description'}
|| DisplayError("You must enter a description for the attachment.")
&& exit;
}
sub validateIsPatch
{
# Set the ispatch flag to zero if it is undefined, since the UI uses
# an HTML checkbox to represent this flag, and unchecked HTML checkboxes
# do not get sent in HTML requests.
$::FORM{'ispatch'} = $::FORM{'ispatch'} ? 1 : 0;
# Set the content type to text/plain if the attachment is a patch.
$::FORM{'contenttype'} = "text/plain" if $::FORM{'ispatch'};
}
sub validateContentType
{
if (!$::FORM{'contenttypemethod'})
{
DisplayError("You must choose a method for determining the content type,
either <em>auto-detect</em>, <em>select from list</em>, or <em>enter
manually</em>.");
exit;
}
elsif ($::FORM{'contenttypemethod'} eq 'autodetect')
{
# The user asked us to auto-detect the content type, so use the type
# specified in the HTTP request headers.
if ( !$::FILE{'data'}->{'contenttype'} )
{
DisplayError("You asked Bugzilla to auto-detect the content type, but
your browser did not specify a content type when uploading the file,
so you must enter a content type manually.");
exit;
}
$::FORM{'contenttype'} = $::FILE{'data'}->{'contenttype'};
}
elsif ($::FORM{'contenttypemethod'} eq 'list')
{
# The user selected a content type from the list, so use their selection.
$::FORM{'contenttype'} = $::FORM{'contenttypeselection'};
}
elsif ($::FORM{'contenttypemethod'} eq 'manual')
{
# The user entered a content type manually, so use their entry.
$::FORM{'contenttype'} = $::FORM{'contenttypeentry'};
}
else
{
my $htmlcontenttypemethod = html_quote($::FORM{'contenttypemethod'});
DisplayError("Your form submission got corrupted somehow. The <em>content
method</em> field, which specifies how the content type gets determined,
should have been either <em>autodetect</em>, <em>list</em>,
or <em>manual</em>, but was instead <em>$htmlcontenttypemethod</em>.");
exit;
}
if ( $::FORM{'contenttype'} !~ /^(application|audio|image|message|model|multipart|text|video)\/.+$/ )
{
my $htmlcontenttype = html_quote($::FORM{'contenttype'});
DisplayError("The content type <em>$htmlcontenttype</em> is invalid.
Valid types must be of the form <em>foo/bar</em> where <em>foo</em>
is either <em>application, audio, image, message, model, multipart,
text,</em> or <em>video</em>.");
exit;
}
}
sub validateIsObsolete
{
# Set the isobsolete flag to zero if it is undefined, since the UI uses
# an HTML checkbox to represent this flag, and unchecked HTML checkboxes
# do not get sent in HTML requests.
$::FORM{'isobsolete'} = $::FORM{'isobsolete'} ? 1 : 0;
}
sub validateStatuses
{
# Get a list of attachment statuses that are valid for this attachment.
PushGlobalSQLState();
SendSQL("SELECT attachstatusdefs.id
FROM attachments, bugs, attachstatusdefs
WHERE attachments.attach_id = $::FORM{'id'}
AND attachments.bug_id = bugs.bug_id
AND attachstatusdefs.product = bugs.product");
my @statusdefs;
push(@statusdefs, FetchSQLData()) while MoreSQLData();
PopGlobalSQLState();
foreach my $status (@{$::MFORM{'status'}})
{
grep($_ == $status, @statusdefs)
|| DisplayError("One of the statuses you entered is not a valid status
for this attachment.")
&& exit;
# We have tested that the status is valid, so it can be detainted
detaint_natural($status);
}
}
sub validateData
{
$::FORM{'data'}
|| DisplayError("The file you are trying to attach is empty!")
&& exit;
my $len = length($::FORM{'data'});
my $maxpatchsize = Param('maxpatchsize');
my $maxattachmentsize = Param('maxattachmentsize');
# Makes sure the attachment does not exceed either the "maxpatchsize" or
# the "maxattachmentsize" parameter.
if ( $::FORM{'ispatch'} && $maxpatchsize && $len > $maxpatchsize*1024 )
{
my $lenkb = sprintf("%.0f", $len/1024);
DisplayError("The file you are trying to attach is ${lenkb} kilobytes (KB) in size.
Patches cannot be more than ${maxpatchsize}KB in size.
Try breaking your patch into several pieces.");
exit;
} elsif ( !$::FORM{'ispatch'} && $maxattachmentsize && $len > $maxattachmentsize*1024 ) {
my $lenkb = sprintf("%.0f", $len/1024);
DisplayError("The file you are trying to attach is ${lenkb} kilobytes (KB) in size.
Non-patch attachments cannot be more than ${maxattachmentsize}KB.
If your attachment is an image, try converting it to a compressable
format like JPG or PNG, or put it elsewhere on the web and
link to it from the bug's URL field or in a comment on the bug.");
exit;
}
}
sub validateFilename
{
defined $::FILE{'data'}
|| DisplayError("You did not specify a file to attach.")
&& exit;
}
sub validateObsolete
{
# Make sure the attachment id is valid and the user has permissions to view
# the bug to which it is attached.
foreach my $attachid (@{$::MFORM{'obsolete'}}) {
detaint_natural($attachid)
|| DisplayError("The attachment number of one of the attachments
you wanted to obsolete is invalid.")
&& exit;
SendSQL("SELECT bug_id, isobsolete, description
FROM attachments WHERE attach_id = $attachid");
# Make sure the attachment exists in the database.
MoreSQLData()
|| DisplayError("Attachment #$attachid does not exist.")
&& exit;
my ($bugid, $isobsolete, $description) = FetchSQLData();
if ($bugid != $::FORM{'bugid'})
{
$description = html_quote($description);
DisplayError("Attachment #$attachid ($description) is attached
to bug #$bugid, but you tried to flag it as obsolete while
creating a new attachment to bug #$::FORM{'bugid'}.");
exit;
}
if ( $isobsolete )
{
$description = html_quote($description);
DisplayError("Attachment #$attachid ($description) is already obsolete.");
exit;
}
# Check that the user can modify this attachment
validateCanEdit($attachid);
}
}
################################################################################
# Functions
################################################################################
sub view
{
# Display an attachment.
# Retrieve the attachment content and its content type from the database.
SendSQL("SELECT mimetype, thedata FROM attachments WHERE attach_id = $::FORM{'id'}");
my ($contenttype, $thedata) = FetchSQLData();
# Return the appropriate HTTP response headers.
print "Content-Type: $contenttype\n\n";
print $thedata;
}
sub viewall
{
# Display all attachments for a given bug in a series of IFRAMEs within one HTML page.
# Retrieve the attachments from the database and write them into an array
# of hashes where each hash represents one attachment.
SendSQL("SELECT attach_id, creation_ts, mimetype, description, ispatch, isobsolete
FROM attachments WHERE bug_id = $::FORM{'bugid'} ORDER BY attach_id");
my @attachments; # the attachments array
while (MoreSQLData())
{
my %a; # the attachment hash
($a{'attachid'}, $a{'date'}, $a{'contenttype'},
$a{'description'}, $a{'ispatch'}, $a{'isobsolete'}) = FetchSQLData();
# Format the attachment's creation/modification date into something readable.
if ($a{'date'} =~ /^(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/) {
$a{'date'} = "$3/$4/$2&nbsp;$5:$6";
}
# Flag attachments as to whether or not they can be viewed (as opposed to
# being downloaded). Currently I decide they are viewable if their MIME type
# is either text/*, image/*, or application/vnd.mozilla.*.
# !!! Yuck, what an ugly hack. Fix it!
$a{'isviewable'} = ( $a{'contenttype'} =~ /^(text|image|application\/vnd\.mozilla\.)/ );
# Retrieve a list of status flags that have been set on the attachment.
PushGlobalSQLState();
SendSQL("SELECT name
FROM attachstatuses, attachstatusdefs
WHERE attach_id = $a{'attachid'}
AND attachstatuses.statusid = attachstatusdefs.id
ORDER BY sortkey");
my @statuses;
push(@statuses, FetchSQLData()) while MoreSQLData();
$a{'statuses'} = \@statuses;
PopGlobalSQLState();
# Add the hash representing the attachment to the array of attachments.
push @attachments, \%a;
}
# Retrieve the bug summary for displaying on screen.
SendSQL("SELECT short_desc FROM bugs WHERE bug_id = $::FORM{'bugid'}");
my ($bugsummary) = FetchSQLData();
# Define the variables and functions that will be passed to the UI template.
$vars->{'bugid'} = $::FORM{'bugid'};
$vars->{'bugsummary'} = $bugsummary;
$vars->{'attachments'} = \@attachments;
# Return the appropriate HTTP response headers.
print "Content-Type: text/html\n\n";
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/show-multiple.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
sub enter
{
# Display a form for entering a new attachment.
# Retrieve the attachments the user can edit from the database and write
# them into an array of hashes where each hash represents one attachment.
my $canEdit = "";
if (!UserInGroup("editbugs")) {
$canEdit = "AND submitter_id = $::userid";
}
SendSQL("SELECT attach_id, description
FROM attachments
WHERE bug_id = $::FORM{'bugid'}
AND isobsolete = 0 $canEdit
ORDER BY attach_id");
my @attachments; # the attachments array
while ( MoreSQLData() ) {
my %a; # the attachment hash
($a{'id'}, $a{'description'}) = FetchSQLData();
# Add the hash representing the attachment to the array of attachments.
push @attachments, \%a;
}
# Retrieve the bug summary for displaying on screen.
SendSQL("SELECT short_desc FROM bugs WHERE bug_id = $::FORM{'bugid'}");
my ($bugsummary) = FetchSQLData();
# Define the variables and functions that will be passed to the UI template.
$vars->{'bugid'} = $::FORM{'bugid'};
$vars->{'bugsummary'} = $bugsummary;
$vars->{'attachments'} = \@attachments;
# Return the appropriate HTTP response headers.
print "Content-Type: text/html\n\n";
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/create.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
sub insert
{
# Insert a new attachment into the database.
# Escape characters in strings that will be used in SQL statements.
my $filename = SqlQuote($::FILE{'data'}->{'filename'});
my $description = SqlQuote($::FORM{'description'});
my $contenttype = SqlQuote($::FORM{'contenttype'});
my $thedata = SqlQuote($::FORM{'data'});
# Insert the attachment into the database.
SendSQL("INSERT INTO attachments (bug_id, filename, description, mimetype, ispatch, submitter_id, thedata)
VALUES ($::FORM{'bugid'}, $filename, $description, $contenttype, $::FORM{'ispatch'}, $::userid, $thedata)");
# Retrieve the ID of the newly created attachment record.
SendSQL("SELECT LAST_INSERT_ID()");
my $attachid = FetchOneColumn();
# Insert a comment about the new attachment into the database.
my $comment = "Created an attachment (id=$attachid)\n$::FORM{'description'}\n";
$comment .= ("\n" . $::FORM{'comment'}) if $::FORM{'comment'};
use Text::Wrap;
$Text::Wrap::columns = 80;
$Text::Wrap::huge = 'overflow';
$comment = Text::Wrap::wrap('', '', $comment);
AppendComment($::FORM{'bugid'},
$::COOKIE{"Bugzilla_login"},
$comment);
# Make existing attachments obsolete.
my $fieldid = GetFieldID('attachments.isobsolete');
foreach my $attachid (@{$::MFORM{'obsolete'}}) {
SendSQL("UPDATE attachments SET isobsolete = 1 WHERE attach_id = $attachid");
SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added)
VALUES ($::FORM{'bugid'}, $attachid, $::userid, NOW(), $fieldid, '0', '1')");
}
# Send mail to let people know the attachment has been created. Uses a
# special syntax of the "open" and "exec" commands to capture the output of
# "processmail", which "system" doesn't allow, without running the command
# through a shell, which backticks (``) do.
#system ("./processmail", $bugid , $::userid);
#my $mailresults = `./processmail $bugid $::userid`;
my $mailresults = '';
open(PMAIL, "-|") or exec('./processmail', $::FORM{'bugid'}, $::COOKIE{'Bugzilla_login'});
$mailresults .= $_ while <PMAIL>;
close(PMAIL);
# Define the variables and functions that will be passed to the UI template.
$vars->{'bugid'} = $::FORM{'bugid'};
$vars->{'attachid'} = $attachid;
$vars->{'description'} = $description;
$vars->{'mailresults'} = $mailresults;
$vars->{'contenttypemethod'} = $::FORM{'contenttypemethod'};
$vars->{'contenttype'} = $::FORM{'contenttype'};
# Return the appropriate HTTP response headers.
print "Content-Type: text/html\n\n";
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/created.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
sub edit
{
# Edit an attachment record. Users with "editbugs" privileges, (or the
# original attachment's submitter) can edit the attachment's description,
# content type, ispatch and isobsolete flags, and statuses, and they can
# also submit a comment that appears in the bug.
# Users cannot edit the content of the attachment itself.
# Retrieve the attachment from the database.
SendSQL("SELECT description, mimetype, bug_id, ispatch, isobsolete
FROM attachments WHERE attach_id = $::FORM{'id'}");
my ($description, $contenttype, $bugid, $ispatch, $isobsolete) = FetchSQLData();
# Flag attachment as to whether or not it can be viewed (as opposed to
# being downloaded). Currently I decide it is viewable if its content
# type is either text/.* or application/vnd.mozilla.*.
# !!! Yuck, what an ugly hack. Fix it!
my $isviewable = ( $contenttype =~ /^(text|image|application\/vnd\.mozilla\.)/ );
# Retrieve a list of status flags that have been set on the attachment.
my %statuses;
SendSQL("SELECT id, name
FROM attachstatuses JOIN attachstatusdefs
WHERE attachstatuses.statusid = attachstatusdefs.id
AND attach_id = $::FORM{'id'}");
while ( my ($id, $name) = FetchSQLData() )
{
$statuses{$id} = $name;
}
# Retrieve a list of statuses for this bug's product, and build an array
# of hashes in which each hash is a status flag record.
# ???: Move this into versioncache or its own routine?
my @statusdefs;
SendSQL("SELECT id, name
FROM attachstatusdefs, bugs
WHERE bug_id = $bugid
AND attachstatusdefs.product = bugs.product
ORDER BY sortkey");
while ( MoreSQLData() )
{
my ($id, $name) = FetchSQLData();
push @statusdefs, { 'id' => $id , 'name' => $name };
}
# Retrieve a list of attachments for this bug as well as a summary of the bug
# to use in a navigation bar across the top of the screen.
SendSQL("SELECT attach_id FROM attachments WHERE bug_id = $bugid ORDER BY attach_id");
my @bugattachments;
push(@bugattachments, FetchSQLData()) while (MoreSQLData());
SendSQL("SELECT short_desc FROM bugs WHERE bug_id = $bugid");
my ($bugsummary) = FetchSQLData();
# Define the variables and functions that will be passed to the UI template.
$vars->{'attachid'} = $::FORM{'id'};
$vars->{'description'} = $description;
$vars->{'contenttype'} = $contenttype;
$vars->{'bugid'} = $bugid;
$vars->{'bugsummary'} = $bugsummary;
$vars->{'ispatch'} = $ispatch;
$vars->{'isobsolete'} = $isobsolete;
$vars->{'isviewable'} = $isviewable;
$vars->{'statuses'} = \%statuses;
$vars->{'statusdefs'} = \@statusdefs;
$vars->{'attachments'} = \@bugattachments;
# Return the appropriate HTTP response headers.
print "Content-Type: text/html\n\n";
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
sub update
{
# Update an attachment record.
# Get the bug ID for the bug to which this attachment is attached.
SendSQL("SELECT bug_id FROM attachments WHERE attach_id = $::FORM{'id'}");
my $bugid = FetchSQLData()
|| DisplayError("Cannot figure out bug number.")
&& exit;
# Lock database tables in preparation for updating the attachment.
if ($::driver eq 'mysql') {
SendSQL("LOCK TABLES attachments WRITE , attachstatuses WRITE ,
attachstatusdefs READ , fielddefs READ , bugs_activity WRITE");
}
# Get a copy of the attachment record before we make changes
# so we can record those changes in the activity table.
SendSQL("SELECT description, mimetype, ispatch, isobsolete
FROM attachments WHERE attach_id = $::FORM{'id'}");
my ($olddescription, $oldcontenttype, $oldispatch, $oldisobsolete) = FetchSQLData();
# Get the list of old status flags.
SendSQL("SELECT attachstatusdefs.name
FROM attachments, attachstatuses, attachstatusdefs
WHERE attachments.attach_id = $::FORM{'id'}
AND attachments.attach_id = attachstatuses.attach_id
AND attachstatuses.statusid = attachstatusdefs.id
ORDER BY attachstatusdefs.sortkey
");
my @oldstatuses;
while (MoreSQLData()) {
push(@oldstatuses, FetchSQLData());
}
my $oldstatuslist = join(', ', @oldstatuses);
# Update the database with the new status flags.
SendSQL("DELETE FROM attachstatuses WHERE attach_id = $::FORM{'id'}");
foreach my $statusid (@{$::MFORM{'status'}})
{
SendSQL("INSERT INTO attachstatuses (attach_id, statusid) VALUES ($::FORM{'id'}, $statusid)");
}
# Get the list of new status flags.
SendSQL("SELECT attachstatusdefs.name
FROM attachments, attachstatuses, attachstatusdefs
WHERE attachments.attach_id = $::FORM{'id'}
AND attachments.attach_id = attachstatuses.attach_id
AND attachstatuses.statusid = attachstatusdefs.id
ORDER BY attachstatusdefs.sortkey
");
my @newstatuses;
while (MoreSQLData()) {
push(@newstatuses, FetchSQLData());
}
my $newstatuslist = join(', ', @newstatuses);
# Quote the description and content type for use in the SQL UPDATE statement.
my $quoteddescription = SqlQuote($::FORM{'description'});
my $quotedcontenttype = SqlQuote($::FORM{'contenttype'});
# Update the attachment record in the database.
# Sets the creation timestamp to itself to avoid it being updated automatically.
SendSQL("UPDATE attachments
SET description = $quoteddescription ,
mimetype = $quotedcontenttype ,
ispatch = $::FORM{'ispatch'} ,
isobsolete = $::FORM{'isobsolete'} ,
creation_ts = creation_ts
WHERE attach_id = $::FORM{'id'}
");
# Record changes in the activity table.
if ($olddescription ne $::FORM{'description'}) {
my $quotedolddescription = SqlQuote($olddescription);
my $fieldid = GetFieldID('attachments.description');
SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added)
VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $quotedolddescription, $quoteddescription)");
}
if ($oldcontenttype ne $::FORM{'contenttype'}) {
my $quotedoldcontenttype = SqlQuote($oldcontenttype);
my $fieldid = GetFieldID('attachments.mimetype');
SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added)
VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $quotedoldcontenttype, $quotedcontenttype)");
}
if ($oldispatch ne $::FORM{'ispatch'}) {
my $fieldid = GetFieldID('attachments.ispatch');
SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added)
VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $oldispatch, $::FORM{'ispatch'})");
}
if ($oldisobsolete ne $::FORM{'isobsolete'}) {
my $fieldid = GetFieldID('attachments.isobsolete');
SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added)
VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $oldisobsolete, $::FORM{'isobsolete'})");
}
if ($oldstatuslist ne $newstatuslist) {
my ($removed, $added) = DiffStrings($oldstatuslist, $newstatuslist);
my $quotedremoved = SqlQuote($removed);
my $quotedadded = SqlQuote($added);
my $fieldid = GetFieldID('attachstatusdefs.name');
SendSQL("INSERT INTO bugs_activity (bug_id, attach_id, who, bug_when, fieldid, removed, added)
VALUES ($bugid, $::FORM{'id'}, $::userid, NOW(), $fieldid, $quotedremoved, $quotedadded)");
}
# Unlock all database tables now that we are finished updating the database.
if ($::driver eq 'mysql') {
SendSQL("UNLOCK TABLES");
}
# If this installation has enabled the request manager, let the manager know
# an attachment was updated so it can check for requests on that attachment
# and fulfill them. The request manager allows users to request database
# changes of other users and tracks the fulfillment of those requests. When
# an attachment record is updated and the request manager is called, it will
# fulfill those requests that were requested of the user performing the update
# which are requests for the attachment being updated.
#my $requests;
#if (Param('userequestmanager'))
#{
# use Request;
# # Specify the fieldnames that have been updated.
# my @fieldnames = ('description', 'mimetype', 'status', 'ispatch', 'isobsolete');
# # Fulfill pending requests.
# $requests = Request::fulfillRequest('attachment', $::FORM{'id'}, @fieldnames);
# $vars->{'requests'} = $requests;
#}
# If the user submitted a comment while editing the attachment,
# add the comment to the bug.
if ( $::FORM{'comment'} )
{
use Text::Wrap;
$Text::Wrap::columns = 80;
$Text::Wrap::huge = 'wrap';
# Append a string to the comment to let users know that the comment came from
# the "edit attachment" screen.
my $comment = qq|(From update of attachment $::FORM{'id'})\n| . $::FORM{'comment'};
my $wrappedcomment = "";
foreach my $line (split(/\r\n|\r|\n/, $comment))
{
if ( $line =~ /^>/ )
{
$wrappedcomment .= $line . "\n";
}
else
{
$wrappedcomment .= wrap('', '', $line) . "\n";
}
}
# Get the user's login name since the AppendComment function needs it.
my $who = DBID_to_name($::userid);
# Mention $::userid again so Perl doesn't give me a warning about it.
my $neverused = $::userid;
# Append the comment to the list of comments in the database.
AppendComment($bugid, $who, $wrappedcomment);
}
# Send mail to let people know the bug has changed. Uses a special syntax
# of the "open" and "exec" commands to capture the output of "processmail",
# which "system" doesn't allow, without running the command through a shell,
# which backticks (``) do.
#system ("./processmail", $bugid , $::userid);
#my $mailresults = `./processmail $bugid $::userid`;
my $mailresults = '';
open(PMAIL, "-|") or exec('./processmail', $bugid, DBID_to_name($::userid));
$mailresults .= $_ while <PMAIL>;
close(PMAIL);
# Define the variables and functions that will be passed to the UI template.
$vars->{'attachid'} = $::FORM{'id'};
$vars->{'bugid'} = $bugid;
$vars->{'mailresults'} = $mailresults;
# Return the appropriate HTTP response headers.
print "Content-Type: text/html\n\n";
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("attachment/updated.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}

View File

@@ -1,378 +0,0 @@
# -*- Mode: perl; indent-tabs-mode: nil -*-
#
# The contents of this file are subject to the Mozilla 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/MPL/
#
# 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 Bugzilla Bug Tracking System.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All
# Rights Reserved.
#
# Contributor(s): Terry Weissman <terry@mozilla.org>
# Dave Miller <justdave@syndicomm.com>
use diagnostics;
use strict;
use RelationSet;
# Use the Attachment module to display attachments for the bug.
use Attachment;
sub show_bug {
# Shut up misguided -w warnings about "used only once". For some reason,
# "use vars" chokes on me when I try it here.
sub bug_form_pl_sillyness {
my $zz;
$zz = %::FORM;
$zz = %::proddesc;
$zz = %::prodmaxvotes;
$zz = @::enterable_products;
$zz = @::settable_resolution;
$zz = $::unconfirmedstate;
$zz = $::milestoneurl;
$zz = $::template;
$zz = $::vars;
$zz = @::legal_priority;
$zz = @::legal_platform;
$zz = @::legal_severity;
$zz = @::legal_bug_status;
$zz = @::target_milestone;
$zz = @::components;
$zz = @::legal_keywords;
$zz = @::versions;
$zz = @::legal_opsys;
}
# Use templates
my $template = $::template;
my $vars = $::vars;
$vars->{'GetBugLink'} = \&GetBugLink;
$vars->{'quoteUrls'} = \&quoteUrls,
$vars->{'lsearch'} = \&lsearch,
$vars->{'header_done'} = (@_),
quietly_check_login();
my $id = $::FORM{'id'};
if (!defined($id)) {
$template->process("bug/choose.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
exit;
}
my %user = %{$vars->{'user'}};
my %bug;
# Populate the bug hash with the info we get directly from the DB.
my $query = "
SELECT
bugs.bug_id,
product,
version,
rep_platform,
op_sys,
bug_status,
resolution,
priority,
bug_severity,
component,
assigned_to,
reporter,
bug_file_loc,
short_desc,
target_milestone,
qa_contact,
status_whiteboard, ";
if ($::driver eq 'mysql') {
$query .= "
date_format(creation_ts, '%Y-%m-%d %H:%i'),
groupset,
delta_ts, ";
} elsif ($::driver eq 'Pg') {
$query .= "
TO_CHAR(creation_ts, 'YYYY-MM-DD HH24:MI:SS'),
groupset,
TO_CHAR(delta_ts, 'YYYYMMDDHH24MISS'), ";
}
$query .= "
SUM(votes.count)
FROM
bugs LEFT JOIN votes USING(bug_id)
WHERE
bugs.bug_id = $id
GROUP BY
bugs.bug_id,
product,
version,
rep_platform,
op_sys,
bug_status,
resolution,
priority,
bug_severity,
component,
assigned_to,
reporter,
bug_file_loc,
short_desc,
target_milestone,
qa_contact,
status_whiteboard,
creation_ts,
groupset,
delta_ts ";
SendSQL($query);
my $value;
my @row = FetchSQLData();
foreach my $field ("bug_id", "product", "version", "rep_platform",
"op_sys", "bug_status", "resolution", "priority",
"bug_severity", "component", "assigned_to", "reporter",
"bug_file_loc", "short_desc", "target_milestone",
"qa_contact", "status_whiteboard", "creation_ts",
"groupset", "delta_ts", "votes")
{
$value = shift(@row);
$bug{$field} = defined($value) ? $value : "";
}
# General arrays of info about the database state
GetVersionTable();
# Fiddle the product list.
my $seen_curr_prod;
my @prodlist;
foreach my $product (@::enterable_products) {
if ($product eq $bug{'product'}) {
# if it's the product the bug is already in, it's ALWAYS in
# the popup, period, whether the user can see it or not, and
# regardless of the disallownew setting.
$seen_curr_prod = 1;
push(@prodlist, $product);
next;
}
if (Param("usebuggroupsentry")
&& GroupExists($product)
&& !UserInGroup($product))
{
# If we're using bug groups to restrict entry on products, and
# this product has a bug group, and the user is not in that
# group, we don't want to include that product in this list.
next;
}
push(@prodlist, $product);
}
# The current product is part of the popup, even if new bugs are no longer
# allowed for that product
if (!$seen_curr_prod) {
push (@prodlist, $bug{'product'});
@prodlist = sort @prodlist;
}
$vars->{'product'} = \@prodlist;
$vars->{'rep_platform'} = \@::legal_platform;
$vars->{'priority'} = \@::legal_priority;
$vars->{'bug_severity'} = \@::legal_severity;
$vars->{'op_sys'} = \@::legal_opsys;
$vars->{'bug_status'} = \@::legal_bug_status;
# Hack - this array contains "" for some reason. See bug 106589.
shift @::settable_resolution;
$vars->{'resolution'} = \@::settable_resolution;
$vars->{'component_'} = $::components{$bug{'product'}};
$vars->{'version'} = $::versions{$bug{'product'}};
$vars->{'target_milestone'} = $::target_milestone{$bug{'product'}};
$bug{'milestoneurl'} = $::milestoneurl{$bug{'product'}} ||
"notargetmilestone.html";
$vars->{'use_votes'} = $::prodmaxvotes{$bug{'product'}};
# Add additional, calculated fields to the bug hash
if (@::legal_keywords) {
$vars->{'use_keywords'} = 1;
SendSQL("SELECT keyworddefs.name
FROM keyworddefs, keywords
WHERE keywords.bug_id = $id
AND keyworddefs.id = keywords.keywordid
ORDER BY keyworddefs.name");
my @keywords;
while (MoreSQLData()) {
push(@keywords, FetchOneColumn());
}
$bug{'keywords'} = \@keywords;
}
# Attachments
$bug{'attachments'} = Attachment::query($id);
# Dependencies
my @list;
SendSQL("SELECT dependson FROM dependencies WHERE
blocked = $id ORDER BY dependson");
while (MoreSQLData()) {
my ($i) = FetchSQLData();
push(@list, $i);
}
$bug{'dependson'} = \@list;
my @list2;
SendSQL("SELECT blocked FROM dependencies WHERE
dependson = $id ORDER BY blocked");
while (MoreSQLData()) {
my ($i) = FetchSQLData();
push(@list2, $i);
}
$bug{'blocked'} = \@list2;
# Groups
my @groups;
if ($::usergroupset ne '0' || $bug{'groupset'} ne '0') {
my $bug_groupset = $bug{'groupset'};
if ($::driver eq 'mysql') {
SendSQL("select bit, name, description, (bit & $bug{'groupset'} != 0), " .
"(bit & $::usergroupset != 0) from groups where isbuggroup != 0 " .
# Include active groups as well as inactive groups to which
# the bug already belongs. This way the bug can be removed
# from an inactive group but can only be added to active ones.
"and ((isactive = 1 or (bit & $bug{'groupset'} != 0)) or " .
"(bit & $bug{'groupset'} != 0)) " .
"order by description");
} elsif ($::driver eq 'Pg') {
SendSQL("select group_bit, name, description, (group_bit & int8($bug{'groupset'}) != 0), " .
"(group_bit & int8($::usergroupset) != 0) from groups where isbuggroup != 0 " .
# Include active groups as well as inactive groups to which
# the bug already belongs. This way the bug can be removed
# from an inactive group but can only be added to active ones.
"and ((isactive = 1 or (group_bit & int8($bug{'groupset'}) != 0)) or " .
"(group_bit & int8($bug{'groupset'}) != 0)) " .
"order by description");
}
$user{'inallgroups'} = 1;
while (MoreSQLData()) {
my ($bit, $name, $description, $ison, $ingroup) = FetchSQLData();
# For product groups, we only want to display the checkbox if either
# (1) The bit is already set, or
# (2) The user is in the group, but either:
# (a) The group is a product group for the current product, or
# (b) The group name isn't a product name
# This means that all product groups will be skipped, but
# non-product bug groups will still be displayed.
if($ison ||
($ingroup && (($name eq $bug{'product'}) ||
(!defined $::proddesc{$name}))))
{
$user{'inallgroups'} &= $ingroup;
push (@groups, { "bit" => $bit,
"ison" => $ison,
"ingroup" => $ingroup,
"description" => $description });
}
}
# If the bug is restricted to a group, display checkboxes that allow
# the user to set whether or not the reporter
# and cc list can see the bug even if they are not members of all
# groups to which the bug is restricted.
if ($bug{'groupset'} != 0) {
$bug{'inagroup'} = 1;
# Determine whether or not the bug is always accessible by the
# reporter, QA contact, and/or users on the cc: list.
SendSQL("SELECT reporter_accessible, cclist_accessible
FROM bugs
WHERE bug_id = $id
");
($bug{'reporter_accessible'},
$bug{'cclist_accessible'}) = FetchSQLData();
}
}
$vars->{'groups'} = \@groups;
my $movers = Param("movers");
$user{'canmove'} = Param("move-enabled")
&& (defined $::COOKIE{"Bugzilla_login"})
&& ($::COOKIE{"Bugzilla_login"} =~ /\Q$movers\E/);
# User permissions
# In the below, if the person hasn't logged in ($::userid == 0), then
# we treat them as if they can do anything. That's because we don't
# know why they haven't logged in; it may just be because they don't
# use cookies. Display everything as if they have all the permissions
# in the world; their permissions will get checked when they log in
# and actually try to make the change.
$user{'canedit'} = $::userid == 0
|| $::userid == $bug{'reporter'}
|| $::userid == $bug{'qa_contact'}
|| $::userid == $bug{'assigned_to'}
|| UserInGroup("editbugs");
$user{'canconfirm'} = ($::userid == 0) || UserInGroup("canconfirm");
# Bug states
$bug{'isunconfirmed'} = ($bug{'bug_status'} eq $::unconfirmedstate);
$bug{'isopened'} = IsOpenedState($bug{'bug_status'});
# People involved with the bug
$bug{'assigned_to_email'} = DBID_to_name($bug{'assigned_to'});
$bug{'assigned_to'} = DBID_to_real_or_loginname($bug{'assigned_to'});
$bug{'reporter'} = DBID_to_real_or_loginname($bug{'reporter'});
$bug{'qa_contact'} = $bug{'qa_contact'} > 0 ?
DBID_to_name($bug{'qa_contact'}) : "";
my $ccset = new RelationSet;
$ccset->mergeFromDB("SELECT who FROM cc WHERE bug_id=$id");
my @cc = $ccset->toArrayOfStrings();
$bug{'cc'} = \@cc if $cc[0];
# Next bug in list (if there is one)
my @bug_list;
if ($::COOKIE{"BUGLIST"} && $id)
{
@bug_list = split(/:/, $::COOKIE{"BUGLIST"});
}
$vars->{'bug_list'} = \@bug_list;
$bug{'comments'} = GetComments($bug{'bug_id'});
# This is length in number of comments
$bug{'longdesclength'} = scalar(@{$bug{'comments'}});
# Add the bug and user hashes to the variables
$vars->{'bug'} = \%bug;
$vars->{'user'} = \%user;
# Generate and return the UI (HTML page) from the appropriate template.
$template->process("bug/edit.html.tmpl", $vars)
|| ThrowTemplateError($template->error());
}
1;

View File

@@ -1,206 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<!--
The contents of this file are subject to the Mozilla 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/MPL/
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 Bugzilla Bug Tracking System.
The Initial Developer of the Original Code is Netscape Communications
Corporation. Portions created by Netscape are
Copyright (C) 1998 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
Contributor(s): Terry Weissman <terry@mozilla.org>
-->
<head>
<TITLE>A Bug's Life Cycle</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<h1 ALIGN=CENTER>A Bug's Life Cycle</h1>
The <B>status</B> and <B>resolution</B> field define and track the
life cycle of a bug.
<a name="status"></a>
<p>
<TABLE BORDER=1 CELLPADDING=4>
<TR ALIGN=CENTER VALIGN=TOP>
<TD WIDTH="50%"><H1>STATUS</H1> <TD><H1>RESOLUTION</H1>
<TR VALIGN=TOP>
<TD>The <B>status</B> field indicates the general health of a bug. Only
certain status transitions are allowed.
<TD>The <b>resolution</b> field indicates what happened to this bug.
<TR VALIGN=TOP><TD>
<DL><DT><B>
<A HREF="confirmhelp.html">UNCONFIRMED</A></B>
<DD> This bug has recently been added to the database. Nobody has
validated that this bug is true. Users who have the "canconfirm"
permission set may confirm this bug, changing its state to NEW.
Or, it may be directly resolved and marked RESOLVED.
<DT><B>NEW</B>
<DD> This bug has recently been added to the assignee's list of bugs
and must be processed. Bugs in this state may be accepted, and
become <B>ASSIGNED</B>, passed on to someone else, and remain
<B>NEW</B>, or resolved and marked <B>RESOLVED</B>.
<DT><B>ASSIGNED</B>
<DD> This bug is not yet resolved, but is assigned to the proper
person. From here bugs can be given to another person and become
<B>NEW</B>, or resolved and become <B>RESOLVED</B>.
<DT><B>REOPENED</B>
<DD>This bug was once resolved, but the resolution was deemed
incorrect. For example, a <B>WORKSFORME</B> bug is
<B>REOPENED</B> when more information shows up and the bug is now
reproducible. From here bugs are either marked <B>ASSIGNED</B>
or <B>RESOLVED</B>.
</DL>
<TD>
<DL>
<DD> No resolution yet. All bugs which are in one of these "open" states
have the resolution set to blank. All other bugs
will be marked with one of the following resolutions.
</DL>
<TR VALIGN=TOP><TD>
<DL>
<DT><B>RESOLVED</B>
<DD> A resolution has been taken, and it is awaiting verification by
QA. From here bugs are either re-opened and become
<B>REOPENED</B>, are marked <B>VERIFIED</B>, or are closed for good
and marked <B>CLOSED</B>.
<DT><B>VERIFIED</B>
<DD> QA has looked at the bug and the resolution and agrees that the
appropriate resolution has been taken. Bugs remain in this state
until the product they were reported against actually ships, at
which point they become <B>CLOSED</B>.
<DT><B>CLOSED</B>
<DD> The bug is considered dead, the resolution is correct. Any zombie
bugs who choose to walk the earth again must do so by becoming
<B>REOPENED</B>.
</DL>
<TD>
<DL>
<DT><B>FIXED</B>
<DD> A fix for this bug is checked into the tree and tested.
<DT><B>INVALID</B>
<DD> The problem described is not a bug
<DT><B>WONTFIX</B>
<DD> The problem described is a bug which will never be fixed.
<DT><B>LATER</B>
<DD> The problem described is a bug which will not be fixed in this
version of the product.
<DT><B>REMIND</B>
<DD> The problem described is a bug which will probably not be fixed in this
version of the product, but might still be.
<DT><B>DUPLICATE</B>
<DD> The problem is a duplicate of an existing bug. Marking a bug
duplicate requires the bug# of the duplicating bug and will at
least put that bug number in the description field.
<DT><B>WORKSFORME</B>
<DD> All attempts at reproducing this bug were futile, reading the
code produces no clues as to why this behavior would occur. If
more information appears later, please re-assign the bug, for
now, file it.
</DL>
</TABLE>
<H1>Other Fields</H1>
<table border=1 cellpadding=4><tr><td>
<h2><a name="severity">Severity</a></h2>
This field describes the impact of a bug.
<p>
<p>
<table>
<tr><th>Blocker</th><td>Blocks development and/or testing work
<tr><th>Critical</th><td>crashes, loss of data, severe memory leak
<tr><th>Major</th><td>major loss of function
<tr><th>Minor</th><td>minor loss of function, or other problem where easy workaround is present
<tr><th>Trivial</th><td>cosmetic problem like misspelled words or misaligned text
<tr><th>Enhancement</th><td>Request for enhancement
</table>
</td><td>
<h2><a name="priority">Priority</a></h2>
This field describes the importance and order in which a bug should be
fixed. This field is utilized by the programmers/engineers to
prioritize their work to be done. The available priorities are:
<p>
<p>
<table>
<tr><th>P1</th><td>Most important
<tr><th>P2</th><td>
<tr><th>P3</th><td>
<tr><th>P4</th><td>
<tr><th>P5</th><td>Least important
</table>
</tr></table>
<h2><a name="rep_platform">Platform</a></h2>
This is the hardware platform against which the bug was reported. Legal
platforms include:
<UL>
<LI> All (happens on all platform; cross-platform bug)
<LI> Macintosh
<LI> PC
<LI> Sun
<LI> HP
</UL>
<b>Note:</b> Selecting the option "All" does not select bugs assigned against all platforms. It
merely selects bugs that <b>occur</b> on all platforms.
<h2><a name="op_sys">Operating System</a></h2>
This is the operating system against which the bug was reported. Legal
operating systems include:
<UL>
<LI> All (happens on all operating systems; cross-platform bug)
<LI> Windows 95
<LI> Mac System 8.0
<LI> Linux
</UL>
Note that the operating system implies the platform, but not always.
For example, Linux can run on PC and Macintosh and others.
<h2><a name="assigned_to">Assigned To</a></h2>
This is the person in charge of resolving the bug. Every time this
field changes, the status changes to <B>NEW</B> to make it easy to see
which new bugs have appeared on a person's list.
The default status for queries is set to NEW, ASSIGNED and REOPENED. When
searching for bugs that have been resolved or verified, remember to set the
status field appropriately.
<hr>
<!-- hhmts start -->
Last modified: Sun Apr 14 12:51:23 EST 2002
<!-- hhmts end -->
</body> </html>

File diff suppressed because it is too large Load Diff

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