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
103 changed files with 29513 additions and 9122 deletions

View File

@@ -1,80 +0,0 @@
#!perl
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# 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):
# Simon Fraser <sfraser@netscape.com>
#
require 5.004;
use strict;
use Cwd;
use Moz::BuildUtils;
use Moz::BuildCore;
#-------------------------------------------------------------
# Where have the build options gone?
#
# The various build flags have been centralized into one place.
# The master list of options is in MozBuildFlags.txt. However,
# you should never need to edit that file, or this one.
#
# To customize what gets built, or where to start the build,
# edit the $prefs_file_name file in
# System Folder:Preferences:Mozilla build prefs:
# Documentation is provided in that file.
#-------------------------------------------------------------
my($prefs_file_name) = "Mozilla opt build prefs";
my($config_header_file_name) = ":mozilla:config:mac:DefinesOptions.h";
#-------------------------------------------------------------
# hashes to hold build options
#-------------------------------------------------------------
my(%build);
my(%options);
my(%filepaths);
my(%optiondefines);
# Hash of input files for this build. Eventually, there will be
# input files for manifests, and projects too.
my(%inputfiles) = (
"buildflags", "MozillaBuildFlags.txt",
"checkoutdata", "MozillaCheckoutList.txt",
"buildprogress", "¥ Mozilla opt progress",
"buildmodule", "MozillaBuildList.pm",
"checkouttime", "Mozilla last checkout"
);
#-------------------------------------------------------------
# end build hashes
#-------------------------------------------------------------
# set the build root directory, which is the the dir above mozilla
SetupBuildRootDir(":mozilla:build:mac:build_scripts");
# Set up all the flags on $main::, like DEBUG, CARBON etc.
# Override the defaults using the preferences files.
SetupDefaultBuildOptions(0, ":mozilla:dist:viewer:", $config_header_file_name);
my($do_checkout) = 0;
my($do_build) = 1;
RunBuild($do_checkout, $do_build, \%inputfiles, $prefs_file_name);

View File

@@ -1,80 +0,0 @@
#!perl
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# 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):
# Simon Fraser <sfraser@netscape.com>
#
require 5.004;
use strict;
use Cwd;
use Moz::BuildUtils;
use Moz::BuildCore;
#-------------------------------------------------------------
# Where have the build options gone?
#
# The various build flags have been centralized into one place.
# The master list of options is in MozBuildFlags.txt. However,
# you should never need to edit that file, or this one.
#
# To customize what gets built, or where to start the build,
# edit the $prefs_file_name file in
# System Folder:Preferences:Mozilla build prefs:
# Documentation is provided in that file.
#-------------------------------------------------------------
my($prefs_file_name) = "Mozilla debug build prefs";
my($config_header_file_name) = ":mozilla:config:mac:DefinesOptionsDebug.h";
#-------------------------------------------------------------
# hashes to hold build options
#-------------------------------------------------------------
my(%build);
my(%options);
my(%filepaths);
my(%optiondefines);
# Hash of input files for this build. Eventually, there will be
# input files for manifests, and projects too.
my(%inputfiles) = (
"buildflags", "MozillaBuildFlags.txt",
"checkoutdata", "MozillaCheckoutList.txt",
"buildprogress", "¥ Mozilla debug progress",
"buildmodule", "MozillaBuildList.pm",
"checkouttime", "Mozilla last checkout"
);
#-------------------------------------------------------------
# end build hashes
#-------------------------------------------------------------
# set the build root directory, which is the the dir above mozilla
SetupBuildRootDir(":mozilla:build:mac:build_scripts");
# Set up all the flags on $main::, like DEBUG, CARBON etc.
# Override the defaults using the preferences files.
SetupDefaultBuildOptions(1, ":mozilla:dist:viewer_debug:", $config_header_file_name);
my($do_pull) = 0; # overridden by flags and prefs
my($do_build) = 1;
RunBuild($do_pull, $do_build, \%inputfiles, $prefs_file_name);

View File

@@ -1,595 +0,0 @@
#!perl -w
package Moz::BuildCore;
require 5.004;
require Exporter;
use strict;
use vars qw( @ISA @EXPORT );
# perl includes
use Cwd;
use POSIX;
use Time::Local;
use File::Basename;
use LWP::Simple;
# homegrown
use Moz::Moz;
use Moz::Jar;
use Moz::BuildFlags;
use Moz::BuildUtils;
use Moz::CodeWarriorLib;
# use MozillaBuildList; # eventually, this should go away, and be replaced by data input
@ISA = qw(Exporter);
@EXPORT = qw(
RunBuild
);
#//--------------------------------------------------------------------------------------------------
#// DoPrebuildCheck
#//
#// Check the build tools etc before running the build.
#//--------------------------------------------------------------------------------------------------
sub DoPrebuildCheck()
{
SanityCheckBuildOptions();
# launch codewarrior and persist its location. Have to call this before first
# call to getCodeWarriorPath().
my($ide_path_file) = $main::filepaths{"idepath"};
$ide_path_file = full_path_to($ide_path_file);
LaunchCodeWarrior($ide_path_file);
}
#//--------------------------------------------------------------------------------------------------
#// SanityCheckBuildOptions
#//--------------------------------------------------------------------------------------------------
sub SanityCheckBuildOptions()
{
my($bad_options) = 0;
# Jar options
if (!$main::options{chrome_jars} && !$main::options{chrome_files})
{
print "Warning: Both \$options{chrome_jars} and \$options{chrome_files} are off. You won't get any chrome.\n";
$bad_options = 1;
}
if (!$main::options{chrome_jars} && $main::options{use_jars})
{
print "Warning: \$options{chrome_jars} is off but \$options{use_jars} is on. Your build won't run (expects jars, got files).\n";
$bad_options = 1;
}
if (!$main::options{chrome_files} && !$main::options{use_jars})
{
print "Warning: \$options{chrome_jars} is off but \$options{chrome_files} is on. Your build won't run (expects files, got jars).\n";
$bad_options = 1;
}
if ($main::options{ldap_experimental} && !$main::options{ldap})
{
print "Warning: \$options{ldap_experimental} is on but \$options{ldap} is off. LDAP experimental features will not be built.\n";
$bad_options = 1;
}
if ($main::options{wsp} && !$main::options{xmlextras})
{
print "Warning: \$options{wsp} is on but \$options{xmlextras} is off. wsp will not be built.\n";
$bad_options = 1;
}
if ($bad_options) {
print "Build will start in 5 seconds. Press command-. to stop\n";
DelayFor(5);
}
}
#//--------------------------------------------------------------------------------------------------
#// GenBuildSystemInfo
#//--------------------------------------------------------------------------------------------------
sub GenBuildSystemInfo()
{
# always rebuild the configuration program.
BuildProjectClean(":mozilla:build:mac:tools:BuildSystemInfo:BuildSystemInfo.mcp", "BuildSystemInfo");
# delete the configuration file.
unlink(":mozilla:build:mac:BuildSystemInfo.pm");
# run the program.
system(":mozilla:build:mac:BuildSystemInfo");
# wait for the file to be created.
while (!(-e ":mozilla:build:mac:BuildSystemInfo.pm")) { WaitNextEvent(); }
# wait for BuildSystemInfo to finish, so that we see correct results.
while (IsProcessRunning("BuildSystemInfo")) { WaitNextEvent(); }
# now, evaluate the contents of the file.
open(F, ":mozilla:build:mac:BuildSystemInfo.pm");
while (<F>) { eval; }
close(F);
}
#//--------------------------------------------------------------------------------------------------
#// Make library aliases
#//--------------------------------------------------------------------------------------------------
sub MakeLibAliases()
{
my($dist_dir) = GetBinDirectory();
#// ProfilerLib
if ($main::PROFILE)
{
my($profilerlibpath) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:Profiler:Profiler Common:ProfilerLib");
MakeAlias("$profilerlibpath", "$dist_dir"."Essential Files:");
}
}
#//--------------------------------------------------------------------------------------------------
#// ConfigureBuildSystem
#//
#// defines some build-system configuration variables.
#//--------------------------------------------------------------------------------------------------
sub ConfigureBuildSystem()
{
#// In the future, we may want to do configurations based on the actual build system itself.
#// GenBuildSystemInfo();
#// For now, if we discover a newer header file than existed in Universal Interfaces 3.2,
#// we'll assume that 3.3 or later is in use.
my($universal_interfaces) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:Universal:Interfaces:CIncludes:");
if (-e ($universal_interfaces . "ControlDefinitions.h")) {
$main::UNIVERSAL_INTERFACES_VERSION = 0x0330;
}
#// Rename IC SDK folder in the Mac OS Support folder
my($ic_sdk_folder) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:ICProgKit2.0.2");
if( -e $ic_sdk_folder)
{
my($new_ic_folder_name) = Moz::CodeWarriorLib::getCodeWarriorPath("MacOS Support:(ICProgKit2.0.2)");
rename ($ic_sdk_folder, $new_ic_folder_name);
# note that CodeWarrior doesn't descend into folders with () the name
print "Mozilla no longer needs the Internet Config SDK to build:\n Renaming the 'ICProgKit2.0.2' folder to '(ICProgKit2.0.2)'\n";
}
printf("UNIVERSAL_INTERFACES_VERSION = 0x%04X\n", $main::UNIVERSAL_INTERFACES_VERSION);
# alias required CodeWarrior libs into the Essential Files folder (only the Profiler lib now)
MakeLibAliases();
}
#//--------------------------------------------------------------------------------------------------
#// CheckOutModule. Takes variable number of args; first two are required
#//--------------------------------------------------------------------------------------------------
sub CheckOutModule($$$$)
{
my($session, $module, $revision, $date) = @_;
my($result) = $session->checkout($module, $revision, $date);
# result of 1 is success
if ($result) { return; }
my($checkout_err) = $session->getLastError();
if ($checkout_err == 708) {
die "Error: Checkout was cancelled.\n";
} elsif ($checkout_err == 911) {
die "Error: CVS session settings are incorrect. Check your password, and the CVS root settings.\n";
} elsif ($checkout_err == 703) {
die "Error: CVS checkout failed. Unknown module, unknown tag, bad username, or other CVS error.\n";
} elsif ($checkout_err == 711) {
print "Checkout of '$module' failed.\n";
}
}
#//--------------------------------------------------------------------------------------------------
#// getScriptFolder
#//--------------------------------------------------------------------------------------------------
sub getScriptFolder()
{
return dirname($0);
}
#//--------------------------------------------------------------------------------------------------
#// getScriptFolder
#//--------------------------------------------------------------------------------------------------
sub get_url_contents($)
{
my($url) = @_;
my($url_contents) = LWP::Simple::get($url);
$url_contents =~ s/\r\n/\n/g; # normalize linebreaks
$url_contents =~ s/\r/\n/g; # normalize linebreaks
return $url_contents;
}
#//--------------------------------------------------------------------------------------------------
#// get_files_from_content
#//--------------------------------------------------------------------------------------------------
sub uniq
{
my $lastval;
grep(($_ ne $lastval, $lastval = $_)[$[], @_);
}
#//--------------------------------------------------------------------------------------------------
#// get_files_from_content
#//--------------------------------------------------------------------------------------------------
sub get_files_from_content($)
{
my($content) = @_;
my(@jscalls) = grep (/return js_file_menu[^{]*/, split(/\n/, $content));
my $i;
for ($i = 0; $i < @jscalls ; $i++)
{
$jscalls[$i] =~ s/.*\(|\).*//g;
my(@callparams) = split(/,/, $jscalls[$i]);
my ($repos, $dir, $file, $rev) = grep(s/['\s]//g, @callparams);
$jscalls[$i] = "$dir/$file";
}
&uniq(sort(@jscalls));
}
#//--------------------------------------------------------------------------------------------------
#// getLastUpdateTime
#//
#// Get the last time we updated. Return 0 on failure
#//--------------------------------------------------------------------------------------------------
sub getLastUpdateTime($)
{
my($timestamp_file) = @_;
my($time_string);
local(*TIMESTAMP_FILE);
unless (open(TIMESTAMP_FILE, "< $timestamp_file")) { return 0; }
while (<TIMESTAMP_FILE>)
{
my($line) = $_;
chomp($line);
# ignore comments and empty lines
if ($line =~ /^\#/ || $line =~ /^\s*$/) {
next;
}
$time_string = $line;
}
# get the epoch seconds
my($last_update_secs) = $time_string;
$last_update_secs =~ s/\s#.+$//;
print "FAST_UPDATE found that you last updated at ".localtime($last_update_secs)."\n";
# how long ago was this, in hours?
my($gm_now) = time();
my($update_hours) = 1 + ceil(($gm_now - $last_update_secs) / (60 * 60));
return $update_hours;
}
#//--------------------------------------------------------------------------------------------------
#// saveCheckoutTimestamp
#//
#// Create a file on disk containing the current time. Param is time(), which is an Epoch seconds
#// (and therefore in GMT).
#//
#//--------------------------------------------------------------------------------------------------
sub saveCheckoutTimestamp($$)
{
my($gm_secs, $timestamp_file) = @_;
local(*TIMESTAMP_FILE);
open(TIMESTAMP_FILE, ">$timestamp_file") || die "Failed to open $timestamp_file\n";
print(TIMESTAMP_FILE "# time of last checkout or update, in GMT. Used by FAST_UPDATE\n");
print(TIMESTAMP_FILE "$gm_secs \# around ".localtime()." local time\n");
close(TIMESTAMP_FILE);
}
#//--------------------------------------------------------------------------------------------------
#// FastUpdate
#//
#// Use Bonsai url data to update only those dirs which have new files
#//
#//--------------------------------------------------------------------------------------------------
sub FastUpdate($$)
{
my($modules, $timestamp_file) = @_; # list of modules to check out
my($num_hours) = getLastUpdateTime($timestamp_file);
if ($num_hours == 0 || $num_hours > 170) {
print "Can't fast_update; last update was too long ago, or never. Doing normal checkout.\n";
return 0;
}
print "Doing fast update, pulling files changed in the last $num_hours hours\n";
my($cvsfile) = AskAndPersistFile($main::filepaths{"sessionpath"});
my($session) = Moz::MacCVS->new( $cvsfile );
unless (defined($session)) { die "Error: Checkout aborted. Cannot create session file: $session" }
# activate MacCVS
ActivateApplication('Mcvs');
my($checkout_start_time) = time();
#print "Time now is $checkout_start_time ($checkout_start_time + 0)\n";
my($this_co);
foreach $this_co (@$modules)
{
my($module, $revision, $date) = ($this_co->[0], $this_co->[1], $this_co->[2]);
# assume that things pulled by date wont change
if ($date ne "") {
print "$module is pulled by date, so ignoring in FastUpdate.\n";
next;
}
my($search_type) = "hours";
my($min_date) = "";
my($max_date) = "";
my($url) = "http://bonsai.mozilla.org/cvsquery.cgi?treeid=default&module=${module}&branch=${revision}&branchtype=match&dir=&file=&filetype=match&who=&whotype=match&sortby=Date&hours=${num_hours}&date=${search_type}&mindate=${min_date}&maxdate=${max_date}&cvsroot=%2Fcvsroot";
if ($revision eq "") {
print "Getting list of checkins to $module from Bonsai...\n";
} else {
print "Getting list of checkins to $module on branch $revision from Bonsai...\n";
}
my(@files) = &get_files_from_content(&get_url_contents($url));
if ($#files > 0)
{
my(@cvs_co_list);
my($co_file);
foreach $co_file (@files)
{
print "Updating $co_file\n";
push(@cvs_co_list, $co_file);
}
my($result) = $session->update($revision, \@cvs_co_list);
# result of 1 is success
if (!$result) { die "Error: Fast update failed\n"; }
} else {
print "No files in this module changed\n";
}
}
saveCheckoutTimestamp($checkout_start_time, $timestamp_file);
return 1;
}
#//--------------------------------------------------------------------------------------------------
#// Checkout
#//--------------------------------------------------------------------------------------------------
sub CheckoutModules($$$)
{
my($modules, $pull_date, $timestamp_file) = @_; # list of modules to check out
my($start_time) = TimeStart();
# assertRightDirectory();
my($cvsfile) = AskAndPersistFile($main::filepaths{"sessionpath"});
my($session) = Moz::MacCVS->new( $cvsfile );
unless (defined($session)) { die "Error: Checkout aborted. Cannot create session file: $session" }
my($checkout_start_time) = time();
# activate MacCVS
ActivateApplication('Mcvs');
my($this_co);
foreach $this_co (@$modules)
{
my($module, $revision, $date) = ($this_co->[0], $this_co->[1], $this_co->[2]);
if ($date eq "") {
$date = $pull_date;
}
CheckOutModule($session, $module, $revision, $date);
# print "Checking out $module with ref $revision, date $date\n";
}
saveCheckoutTimestamp($checkout_start_time, $timestamp_file);
TimeEnd($start_time, "Checkout");
}
#//--------------------------------------------------------------------------------------------------
#// ReadCheckoutModulesFile
#//--------------------------------------------------------------------------------------------------
sub ReadCheckoutModulesFile($$)
{
my($modules_file, $co_list) = @_;
my($checkout_file) = getScriptFolder().":".$modules_file;
local(*CHECKOUT_FILE);
open(CHECKOUT_FILE, "< $checkout_file") || die "Error: failed to open checkout list $checkout_file\n";
while (<CHECKOUT_FILE>)
{
my($line) = $_;
chomp($line);
# ignore comments and empty lines
if ($line =~ /^\#/ || $line =~ /^\s*$/) {
next;
}
my(@cvs_co) = ["", "", ""];
my($module, $revision, $date) = (0, 1, 2);
if ($line =~ /\s*([^#,\s]+)\s*\,\s*([^#,\s]+)\s*\,\s*([^#]+)/)
{
@cvs_co[$module] = $1;
@cvs_co[$revision] = $2;
@cvs_co[$date] = $3;
}
elsif ($line =~ /\s*([^#,\s]+)\s*\,\s*([^#,\s]+)\s*(#.+)?/)
{
@cvs_co[$module] = $1;
@cvs_co[$revision] = $2;
}
elsif ($line =~ /\s*([^#,\s]+)\s*\,\s*,\s*([^#,]+)/)
{
@cvs_co[$module] = $1;
@cvs_co[$date] = $2;
}
elsif ($line =~ /\s*([^#,\s]+)/)
{
@cvs_co[$module] = $1;
}
else
{
die "Error: unrecognized line '$line' in $modules_file\n";
}
# strip surrounding space from date
@cvs_co[$date] =~ s/^\s*|\s*$//g;
# print "Going to check out '@cvs_co[$module]', '@cvs_co[$revision]', '@cvs_co[$date]'\n";
push(@$co_list, \@cvs_co);
}
close(CHECKOUT_FILE);
}
#//--------------------------------------------------------------------------------------------------
#// PullFromCVS
#//--------------------------------------------------------------------------------------------------
sub PullFromCVS($$)
{
unless ( $main::build{pull} ) { return; }
my($modules_file, $timestamp_file) = @_;
StartBuildModule("pull");
my(@cvs_co_list);
ReadCheckoutModulesFile($modules_file, \@cvs_co_list);
if ($main::FAST_UPDATE && $main::options{pull_by_date})
{
die "Error: you can't use FAST_UPDATE if you are pulling by date.\n";
}
my($did_fast_update) = $main::FAST_UPDATE && FastUpdate(\@cvs_co_list, $timestamp_file);
if (!$did_fast_update)
{
my($pull_date) = "";
if ($main::options{pull_by_date})
{
# acceptable CVS date formats are (in local time):
# ISO8601 (e.g. "1972-09-24 20:05") and Internet (e.g. "24 Sep 1972 20:05").
# Perl's localtime() string format also seems to work.
$pull_date = localtime().""; # force string interp.
print "Pulling by date $pull_date\n";
}
CheckoutModules(\@cvs_co_list, $pull_date, $timestamp_file);
}
EndBuildModule("pull");
}
#//--------------------------------------------------------------------------------------------------
#// RunBuild
#//--------------------------------------------------------------------------------------------------
sub RunBuild($$$$)
{
my($do_pull, $do_build, $input_files, $build_prefs) = @_;
InitBuildProgress($input_files->{"buildprogress"});
# if we are pulling, we probably want to do a full build, so clear the build progress
if ($do_pull) {
ClearBuildProgress();
}
# read local prefs, and the build progress file, and set flags to say what to build
SetupBuildParams(\%main::build,
\%main::options,
\%main::optiondefines,
\%main::filepaths,
$input_files->{"buildflags"},
$build_prefs);
# If we were told to pull, make sure we do, overriding prefs etc.
if ($do_pull)
{
$main::build{"pull"} = 1;
}
# transfer this flag
$CodeWarriorLib::CLOSE_PROJECTS_FIRST = $main::CLOSE_PROJECTS_FIRST;
# setup the build log
SetupBuildLog($main::filepaths{"buildlogfilepath"}, $main::USE_TIMESTAMPED_LOGS);
StopForErrors();
if ($main::LOG_TO_FILE) {
RedirectOutputToFile($main::filepaths{"scriptlogfilepath"});
}
# run a pre-build check to see that the tools etc are in order
DoPrebuildCheck();
# do the pull
PullFromCVS($input_files->{"checkoutdata"}, $input_files->{"checkouttime"});
unless ($do_build) { return; }
my($build_start) = TimeStart();
# check the build environment
ConfigureBuildSystem();
# here we load and call methods in the build module indirectly.
# we have to use indirection because the build module can be named
# differently for different builds.
chdir(dirname($0)); # change to the script dir
my($build_module) = $input_files->{"buildmodule"};
# load the build module
require $build_module;
{ # scope for no strict 'refs'
no strict 'refs';
my($package_name) = $build_module;
$package_name =~ s/\.pm$//;
chdir($main::MOZ_SRC);
&{$package_name."::BuildDist"}();
chdir($main::MOZ_SRC);
&{$package_name."::BuildProjects"}();
}
# the build finished, so clear the build progress state
ClearBuildProgress();
TimeEnd($build_start, "Build");
print "Build complete\n";
}
1;

View File

@@ -1,425 +0,0 @@
#!perl -w
package Moz::BuildFlags;
require 5.004;
require Exporter;
# Package that attempts to read a file from the Preferences folder,
# and get build settings out of it
use strict;
use Exporter;
use Cwd;
use File::Basename;
use Moz::Moz;
use Moz::Prefs;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
SetupBuildParams
InitBuildProgress
WriteBuildProgress
ClearBuildProgress
ReadBuildProgress
);
my(@build_flags);
my(@options_flags);
my(@filepath_flags);
my(%arrays_list) = (
"build_flags", \@build_flags,
"options_flags", \@options_flags,
"filepath_flags", \@filepath_flags
);
my($progress_file) = "¥ÊBuild progress";
#-------------------------------------------------------------------------------
# appendArrayFlag
#
# Set a flag in the array
#-------------------------------------------------------------------------------
sub appendArrayFlag(@)
{
my($array_name) = shift;
my($setting) = shift;
my($value) = shift;
my(@optional_values);
foreach (@_) {
push(@optional_values, $_);
}
my(@this_flag) = [$setting, $value, @optional_values];
my($flags_array) = $arrays_list{$array_name};
if ($flags_array)
{
push(@{$flags_array}, @this_flag) || die "Failed to append\n";
}
else
{
die "Error: unknown build flags array $array_name\n";
}
}
#-------------------------------------------------------------------------------
# readFlagsFile
#
# Read the file of build flags from disk. File path is relative to the
# script directory.
#-------------------------------------------------------------------------------
sub readFlagsFile($)
{
my($flags_file) = @_;
my($file_path) = $0;
$file_path =~ s/[^:]+$/$flags_file/;
print "Reading build flags from '$file_path'\n";
local(*FLAGS_FILE);
open(FLAGS_FILE, "< $file_path") || die "Error: failed to open flags file $file_path\n";
my($cur_array) = "";
while(<FLAGS_FILE>)
{
my($line) = $_;
chomp($line);
# ignore comments and empty lines
if ($line =~ /^\#/ || $line =~ /^\s*$/) {
next;
}
# 1-word line, probably array name
if ($line =~ /^([^#\s]+)\s*$/)
{
$cur_array = $1;
next;
}
elsif ($line =~ /^([^#\s]+)\s+\"(.+)\"(\s+#.+)?$/) # quoted option, possible comment
{
my($flag) = $1;
my($setting) = $2;
appendArrayFlag($cur_array, $flag, $setting);
}
elsif ($line =~ /^([^#\s]+)((\s+[^#\s]+)+)(\s+#.+)?$/) # multiple word line, possible comment
{
my($flag) = $1;
appendArrayFlag($cur_array, $flag, split(' ', $2));
}
else
{
die "Error: unknown build flag at '$line'\n";
}
}
close(FLAGS_FILE);
}
#-------------------------------------------------------------------------------
# flagsArrayToHash
#
# Utility routine to migrate flag from a 2D array to a hash, where
# item[n][0] is the hash entry name, and item[n][1] is the hash entry value.
#-------------------------------------------------------------------------------
sub flagsArrayToHash($$)
{
my($src_array, $dest_hash) = @_;
my($item);
foreach $item (@$src_array)
{
$dest_hash->{$item->[0]} = $item->[1];
}
}
#-----------------------------------------------
# printHash
#
# Utility routine to print a hash
#-----------------------------------------------
sub printHash($)
{
my($hash_ref) = @_;
print "Printing hash:\n";
my($key, $value);
while (($key, $value) = each (%$hash_ref))
{
print " $key $value\n";
}
}
#-----------------------------------------------
# printBuildArray
#
# Utility routine to print a 2D array
#-----------------------------------------------
sub printBuildArray($)
{
my($build_array) = @_;
my($entry);
foreach $entry (@$build_array)
{
print "$entry->[0] = $entry->[1]\n";
}
}
#-------------------------------------------------------------------------------
# SetBuildFlags
#-------------------------------------------------------------------------------
sub SetBuildFlags($)
{
my($build) = @_;
flagsArrayToHash(\@build_flags, $build);
}
#-------------------------------------------------------------------------------
# SetBuildOptions
#-------------------------------------------------------------------------------
sub SetBuildOptions($)
{
my($options) = @_;
flagsArrayToHash(\@options_flags, $options);
}
#-------------------------------------------------------------------------------
# SetFilepathFlags
#-------------------------------------------------------------------------------
sub SetFilepathFlags($)
{
my($filepath) = @_;
flagsArrayToHash(\@filepath_flags, $filepath);
}
#-------------------------------------------------------------------------------
# SetOptionDefines
#-------------------------------------------------------------------------------
sub SetOptionDefines($)
{
my($optiondefines) = @_;
foreach my $entry (@options_flags)
{
if (defined($entry->[2])) {
$optiondefines->{$entry->[0]}{$entry->[2]} = 1;
}
}
}
#-------------------------------------------------------------------------------
# PropagateAllFlags
#-------------------------------------------------------------------------------
sub PropagateAllFlags($)
{
my($build_array) = @_;
# if "all" is set, set all the flags to 1
unless ($build_array->[0][0] eq "all") { die "Error: 'all' must come first in the flags array\n"; }
if ($build_array->[0][1] == 1)
{
my($index);
foreach $index (@$build_array)
{
$index->[1] = 1;
}
}
}
#//--------------------------------------------------------------------------------------------------
#// _getBuildProgressFile
#//--------------------------------------------------------------------------------------------------
sub _getBuildProgressFile()
{
return $progress_file;
}
#//--------------------------------------------------------------------------------------------------
#// setBuildProgressStart
#//
#// This automagically sets $build{"all"} to 0
#//--------------------------------------------------------------------------------------------------
sub setBuildProgressStart($$)
{
my($build_array, $name) = @_;
my($index);
foreach $index (@$build_array)
{
$index->[1] = 0;
if ($index->[0] eq $name) {
last;
}
}
print "Building from module after $name, as specified by build progress\n";
}
#//--------------------------------------------------------------------------------------------------
#// InitBuildProgress
#//--------------------------------------------------------------------------------------------------
sub InitBuildProgress($)
{
my($prog_file) = @_;
if ($prog_file ne "") {
$progress_file = full_path_to($prog_file);
print "Writing build progress to $progress_file\n";
}
}
#//--------------------------------------------------------------------------------------------------
#// WriteBuildProgress
#//--------------------------------------------------------------------------------------------------
sub WriteBuildProgress($)
{
my($module_built) = @_;
my($progress_file) = _getBuildProgressFile();
if ($progress_file ne "")
{
open(PROGRESS_FILE, ">>$progress_file") || die "Failed to open $progress_file\n";
print(PROGRESS_FILE "$module_built\n");
close(PROGRESS_FILE);
}
}
#//--------------------------------------------------------------------------------------------------
#// ClearBuildProgress
#//--------------------------------------------------------------------------------------------------
sub ClearBuildProgress()
{
my($progress_file) = _getBuildProgressFile();
if ($progress_file ne "") {
unlink $progress_file;
}
}
#//--------------------------------------------------------------------------------------------------
#// WipeBuildProgress
#//--------------------------------------------------------------------------------------------------
sub WipeBuildProgress()
{
print "Ignoring build progress\n";
ClearBuildProgress();
$progress_file = "";
}
#//--------------------------------------------------------------------------------------------------
#// ReadBuildProgress
#//--------------------------------------------------------------------------------------------------
sub ReadBuildProgress($)
{
my($build_array) = @_;
my($progress_file) = _getBuildProgressFile();
my($last_module);
if (open(PROGRESS_FILE, "< $progress_file"))
{
print "Getting build progress from $progress_file\n";
while (<PROGRESS_FILE>)
{
my($line) = $_;
chomp($line);
$last_module = $line;
}
close(PROGRESS_FILE);
}
if ($last_module)
{
setBuildProgressStart($build_array, $last_module);
}
}
#-------------------------------------------------------------------------------
# clearOldBuildSettings
#-------------------------------------------------------------------------------
sub clearOldBuildSettings($$$$)
{
my($build, $options, $optiondefines, $filepaths) = @_;
# empty the arrays in case we're being called twice
@build_flags = ();
@options_flags = ();
@filepath_flags = ();
# and empty the hashes
%$build = ();
%$options = ();
%$optiondefines = ();
%$filepaths = ();
}
#-------------------------------------------------------------------------------
# SetupBuildParams
#-------------------------------------------------------------------------------
sub SetupBuildParams($$$$$$)
{
my($build, $options, $optiondefines, $filepaths, $flags_file, $prefs_file) = @_;
# Empty the hashes and arrays, to wipe out any stale data.
# Needed because these structures persist across two build scripts
# called using 'do' from a parent script.
clearOldBuildSettings($build, $options, $optiondefines, $filepaths);
# Read from the flags file, which sets up the various arrays
readFlagsFile($flags_file);
# If 'all' is set in the build array, propagate that to all entries
PropagateAllFlags(\@build_flags);
# read the user pref file, that can change values in the array
ReadMozUserPrefs($prefs_file, \@build_flags, \@options_flags, \@filepath_flags);
# If build progress exists, this clears flags in the array up to a certain point
if ($main::USE_BUILD_PROGRESS) {
ReadBuildProgress(\@build_flags);
} else {
WipeBuildProgress();
}
# printBuildArray(\@build_flags);
# printBuildArray(\@options_flags);
SetBuildFlags($build);
SetBuildOptions($options);
SetOptionDefines($optiondefines);
SetFilepathFlags($filepaths);
# printHash($build);
# printHash($options);
}
1;

View File

@@ -1,786 +0,0 @@
package Moz::BuildUtils;
require 5.004;
require Exporter;
# Package that contains build util functions specific to the Mozilla build
# process.
use strict;
use Exporter;
use Cwd;
use File::Path;
use File::Basename;
use Mac::Events;
use Mac::StandardFile;
use Moz::Moz;
use Moz::BuildFlags;
use Moz::MacCVS;
#use Moz::ProjectXML; #optional; required for static build only
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
SetupDefaultBuildOptions
SetupBuildRootDir
StartBuildModule
EndBuildModule
GetBinDirectory
BuildOneProjectWithOutput
BuildOneProject
BuildProject
BuildProjectClean
BuildIDLProject
BuildFolderResourceAliases
AskAndPersistFile
DelayFor
TimeStart
TimeEnd
EmptyTree
SetupBuildLog
SetBuildNumber
SetTimeBomb
UpdateConfigHeader
);
#//--------------------------------------------------------------------------------------------------
#// SetupDefaultBuildOptions
#//--------------------------------------------------------------------------------------------------
sub SetupDefaultBuildOptions($$$)
{
my($debug, $bin_dir, $config_header_file_name) = @_;
# Here we set up defaults for the various build flags.
# If you want to override any of these, it's best to do
# so via the relevant preferences file, which lives in
# System Folder:Preferences:Mozilla build prefs:{build prefs file}.
# For the name of the prefs file, see the .pl script that you
# run to start this build. The prefs files are created when
# you run the build, and contain some documentation.
#-------------------------------------------------------------
# configuration variables that globally affect what is built
#-------------------------------------------------------------
$main::DEBUG = $debug;
$main::PROFILE = 0;
$main::RUNTIME = 0; # turn on to just build runtime support and NSPR projects
$main::GC_LEAK_DETECTOR = 0; # turn on to use GC leak detection
$main::MOZILLA_OFFICIAL = 0; # generate build number
$main::LOG_TO_FILE = 0; # write perl output to a file
#-------------------------------------------------------------
# configuration variables that affect the manner of building,
# but possibly affecting the outcome.
#-------------------------------------------------------------
$main::ALIAS_SYM_FILES = $main::DEBUG;
$main::CLOBBER_LIBS = 1; # turn on to clobber existing libs and .xSYM files before
# building each project
# The following two options will delete all dist files (if you have $main::build{dist} turned on),
# but leave the directory structure intact.
$main::CLOBBER_DIST_ALL = 1; # turn on to clobber all aliases/files inside dist (headers/xsym/libs)
$main::CLOBBER_DIST_LIBS = 0; # turn on to clobber only aliases/files for libraries/sym files in dist
$main::CLOBBER_IDL_PROJECTS = 0; # turn on to clobber all IDL projects.
$main::CLOBBER_PROJECTS = 0; # turn on to remove object code from each project before building it
$main::UNIVERSAL_INTERFACES_VERSION = 0x0320;
#-------------------------------------------------------------
# configuration variables that are preferences for the build,
# style and do not affect what is built.
#-------------------------------------------------------------
$main::CLOSE_PROJECTS_FIRST = 0;
# 1 = close then make (for development),
# 0 = make then close (for tinderbox).
$main::USE_TIMESTAMPED_LOGS = 0;
$main::USE_BUILD_PROGRESS = 1; # track build progress for restartable builds
#-------------------------------------------------------------
# END OF CONFIG SWITCHES
#-------------------------------------------------------------
$main::BIN_DIRECTORY = $bin_dir;
$main::DEFINESOPTIONS_FILE = $config_header_file_name;
}
#//--------------------------------------------------------------------------------------------------
#// SetupBuildRootDir
#//--------------------------------------------------------------------------------------------------
sub SetupBuildRootDir($)
{
my($rel_path_to_script) = @_;
my($cur_dir) = cwd();
$cur_dir =~ s/$rel_path_to_script$//;
chdir($cur_dir) || die "Error: failed to set build root directory to '$cur_dir'.\nYou probably need to put 'mozilla' one level down (in a folder).\n";
$main::MOZ_SRC = cwd();
}
#//--------------------------------------------------------------------------------------------------
#// StartBuildModule
#//--------------------------------------------------------------------------------------------------
sub StartBuildModule($)
{
my($module) = @_;
print("---- Start of $module ----\n");
}
#//--------------------------------------------------------------------------------------------------
#// EndBuildModule
#//--------------------------------------------------------------------------------------------------
sub EndBuildModule($)
{
my($module) = @_;
WriteBuildProgress($module);
print("---- End of $module ----\n");
}
#--------------------------------------------------------------------------------------------------
# GetBinDirectory
#--------------------------------------------------------------------------------------------------
sub GetBinDirectory()
{
if ($main::BIN_DIRECTORY eq "") { die "Dist directory not set\n"; }
return $main::BIN_DIRECTORY;
}
#--------------------------------------------------------------------------------------------------
# AskAndPersistFile stores the information about the user pick inside
# the file $session_storage
#--------------------------------------------------------------------------------------------------
sub AskAndPersistFile($)
{
my ($sessionStorage) = @_;
my $cvsfile;
if (( -e $sessionStorage) &&
open( SESSIONFILE, $sessionStorage ))
{
# Read in the path if available
$cvsfile = <SESSIONFILE>;
chomp $cvsfile;
close SESSIONFILE;
if ( ! -e $cvsfile )
{
print STDERR "$cvsfile has disappeared\n";
undef $cvsfile;
}
}
unless (defined ($cvsfile))
{
# make sure that MacPerl is a front process
ActivateApplication('McPL');
MacPerl::Answer("Could not find your MacCVS session file. Please choose one", "OK");
# prompt user for the file name, and store it
my $macFile = StandardGetFile( 0, "McvD");
if ( $macFile->sfGood() )
{
$cvsfile = $macFile->sfFile();
# save the choice if we can
if ( open (SESSIONFILE, ">" . $sessionStorage))
{
printf SESSIONFILE $cvsfile, "\n";
close SESSIONFILE;
}
else
{
print STDERR "Could not open storage file $sessionStorage for saving $cvsfile\n";
}
}
}
return $cvsfile;
}
#--------------------------------------------------------------------------------------------------
# BuildIDLProject
#
#--------------------------------------------------------------------------------------------------
sub BuildIDLProject($$)
{
my ($project_path, $module_name) = @_;
if ($main::CLOBBER_IDL_PROJECTS)
{
my (@suffix_list) = (".mcp", ".xml");
my ($project_name, $project_dir, $suffix) = fileparse($project_path, @suffix_list);
if ($suffix eq "") { die "Error: Project, $project_path must end in .xml or .mcp\n"; }
my($datafolder_path);
if ($suffix eq ".xml")
{
$datafolder_path = $project_dir . "_" . $project_name . " Data:";
}
else {
$datafolder_path = $project_dir . $project_name . " Data:";
}
print STDERR "Deleting IDL data folder: $datafolder_path\n";
EmptyTree($datafolder_path);
}
BuildOneProject($project_path, "headers", 0, 0, 0);
BuildOneProject($project_path, $module_name.".xpt", 1, 0, 1);
}
#--------------------------------------------------------------------------------------------------
# CreateStaticLibTargets
#
#--------------------------------------------------------------------------------------------------
sub CreateXMLStaticLibTargets($)
{
my($xml_path) = @_;
my (@suffix_list) = (".xml");
my ($project_name, $project_dir, $suffix) = fileparse($xml_path, @suffix_list);
if ($suffix eq "") { die "XML munging: $xml_path must end in .xml\n"; }
#sniff the file to see if we need to fix up broken Pro5-exported XML
print "Parsing $xml_path\n";
my $ide_version = Moz::ProjectXML::SniffProjectXMLIDEVersion($xml_path);
if ($ide_version eq "4.0")
{
my $new_file = $project_dir.$project_name."2.xml";
print "Cleaning up Pro 5 xml to $new_file\n";
Moz::ProjectXML::CleanupPro5XML($xml_path, $new_file);
unlink $xml_path;
rename ($new_file, $xml_path);
}
my $doc = Moz::ProjectXML::ParseXMLDocument($xml_path);
my @target_list = Moz::ProjectXML::GetTargetsList($doc);
my $target;
my %target_hash; # for easy lookups below
foreach $target (@target_list) { $target_hash{$target} = 1; }
foreach $target (@target_list)
{
if ($target =~ /(.+).shlb$/) # if this is a shared lib target
{
my $target_base = $1;
my $static_target = $target_base.".o";
# ensure that this does not exist already
if ($target_hash{$static_target}) {
print "Static target $static_target already exists in project. Not making\n";
next;
}
print "Making static target '$static_target' from target '$target'\n";
Moz::ProjectXML::CloneTarget($doc, $target, $static_target);
Moz::ProjectXML::SetAsStaticLibraryTarget($doc, $static_target, $static_target);
}
}
print "Writing XML file to $xml_path\n";
my $temp_path = $project_dir."_".$project_name.".xml";
Moz::ProjectXML::WriteXMLDocument($doc, $temp_path, $ide_version);
Moz::ProjectXML::DisposeXMLDocument($doc);
if (-e $temp_path)
{
unlink $xml_path;
rename ($temp_path, $xml_path);
}
else
{
die "Error: Failed to add new targets to XML project\n";
}
}
#//--------------------------------------------------------------------------------------------------
#// ProcessProjectXML
#//
#// Helper routine to allow for XML pre-processing. This should read in the XML, process it,
#// and replace the original file with the processed version.
#//--------------------------------------------------------------------------------------------------
sub ProcessProjectXML($)
{
my($xml_path) = @_;
# we need to manually load Moz::ProjectXML, becaues not everyone will have the
# required perl modules in their distro.
my($cur_dir) = cwd();
chdir(dirname($0)); # change to the script dir
eval "require Moz::ProjectXML";
if ($@) { die "Error: could not do Project XML munging because you do not have the correct XML modules installed. Error is:\n################\n $@################"; }
chdir($cur_dir);
CreateXMLStaticLibTargets($xml_path);
}
#//--------------------------------------------------------------------------------------------------
#// Build one project, and make the alias. Parameters are project path, target name, shared library
#// name, make shlb alias (boolean), make xSYM alias (boolean), and is component (boolean).
#//--------------------------------------------------------------------------------------------------
sub BuildOneProjectWithOutput($$$$$$)
{
my ($project_path, $target_name, $output_name, $alias_lib, $alias_xSYM, $component) = @_;
unless ($project_path =~ m/^$main::BUILD_ROOT.+/) { return; }
my (@suffix_list) = (".mcp", ".xml");
my ($project_name, $project_dir, $suffix) = fileparse($project_path, @suffix_list);
if ($suffix eq "") { die "Error: Project, $project_path must end in .xml or .mcp\n"; }
my($dist_dir) = GetBinDirectory();
# Put libraries in "Essential Files" folder, Components in "Components" folder
my($output_dir) = $component ? "Components:" : "Essential Files:";
my($output_path) = $dist_dir.$output_dir;
if ($main::options{static_build})
{
if ($output_name =~ /\.o$/ || $output_name =~ /\.[Ll]ib$/)
{
$alias_xSYM = 0;
$alias_lib = 1;
$output_path = $main::DEBUG ? ":mozilla:dist:static_libs_debug:" : ":mozilla:dist:static_libs:";
}
}
# if the flag is on to export projects to XML, export and munge them
if ($main::EXPORT_PROJECTS && !($project_path =~ /IDL\.mcp$/))
{
my $xml_out_path = $project_path;
$xml_out_path =~ s/\.mcp$/\.xml/;
# only do this if project is newer?
if (! -e $xml_out_path)
{
ExportProjectToXML(full_path_to($project_path), full_path_to($xml_out_path));
ProcessProjectXML($xml_out_path);
}
}
# if the flag is set to use XML projects, default to XML if the file
# is present.
if ($main::USE_XML_PROJECTS && !($project_path =~ /IDL\.mcp$/))
{
my $xml_project_path = $project_dir.$project_name.".xml";
if (-e $xml_project_path)
{
$project_path = $xml_project_path;
$suffix = ".xml";
}
}
if ($suffix eq ".xml")
{
my($xml_path) = $project_path;
# Prepend an "_" onto the name of the generated project file so it doesn't conflict
$project_path = $project_dir . "_" . $project_name . ".mcp";
my($project_modtime) = (-e $project_path ? GetFileModDate($project_path) : 0);
my($xml_modtime) = (-e $xml_path ? GetFileModDate($xml_path) : 0);
if ($xml_modtime > $project_modtime)
{
print("Importing $project_path from $project_name.xml.\n");
unlink($project_path);
# Might want to delete the "xxx.mcp Data" dir ???
ImportXMLProject(full_path_to($xml_path), full_path_to($project_path));
}
}
if ($main::CLOBBER_LIBS)
{
unlink "$project_dir$output_name"; # it's OK if these fail
unlink "$project_dir$output_name.xSYM";
}
DoBuildProject($project_path, $target_name, $main::CLOBBER_PROJECTS);
$alias_lib ? MakeAlias("$project_dir$output_name", "$output_path") : 0;
$alias_xSYM ? MakeAlias("$project_dir$output_name.xSYM", "$output_path") : 0;
}
#//--------------------------------------------------------------------------------------------------
#// For compatiblity with existing scripts, BuildOneProject now just calls
#// BuildOneProjectWithOutput, with the output name and target name identical.
#// Note that this routine assumes that the target name and the shared libary name
#// are the same.
#//--------------------------------------------------------------------------------------------------
sub BuildOneProject($$$$$)
{
my ($project_path, $target_name, $alias_lib, $alias_xSYM, $component) = @_;
BuildOneProjectWithOutput($project_path, $target_name, $target_name,
$alias_lib, $alias_xSYM, $component);
}
#//--------------------------------------------------------------------------------------------------
#// For compatiblity with existing scripts, BuildProject now just calls
#// BuildOneProjectWithOutput, with the output name and target name identical.
#// Note that this routine assumes that the target name and the shared libary name
#// are the same. No aliases of the output are made.
#//--------------------------------------------------------------------------------------------------
sub BuildProject($$)
{
my ($project_path, $target_name) = @_;
BuildOneProjectWithOutput($project_path, $target_name, $target_name, 0, 0, 0);
}
#//--------------------------------------------------------------------------------------------------
#// Identical to BuildProject but clobbers the project before building it.
#//--------------------------------------------------------------------------------------------------
sub BuildProjectClean($$)
{
my ($project_path, $target_name) = @_;
my ($save_clobber_flag) = $main::CLOBBER_PROJECTS;
$main::CLOBBER_PROJECTS = 1;
BuildOneProjectWithOutput($project_path, $target_name, $target_name, 0, 0, 0);
$main::CLOBBER_PROJECTS = $save_clobber_flag;
}
#//--------------------------------------------------------------------------------------------------
#// Make resource aliases for one directory
#//--------------------------------------------------------------------------------------------------
sub BuildFolderResourceAliases($$)
{
my($src_dir, $dest_dir) = @_;
# get a list of all the resource files
opendir(SRCDIR, $src_dir) || die("can't open $src_dir");
my(@resource_files) = readdir(SRCDIR);
closedir(SRCDIR);
# make aliases for each one into the dest directory
print("Placing aliases to all files from $src_dir in $dest_dir\n");
for ( @resource_files )
{
next if $_ eq "CVS";
#print(" Doing $_\n");
if (-l $src_dir.$_)
{
print(" $_ is an alias\n");
next;
}
my($file_name) = $src_dir . $_;
MakeAlias($file_name, $dest_dir);
}
}
#//--------------------------------------------------------------------------------------------------
#// DelayFor
#//
#// Delay for the given number of seconds, allowing the script to be cancelled
#//--------------------------------------------------------------------------------------------------
sub DelayFor($)
{
my($delay_secs) = @_;
STDOUT->autoflush(1);
my($end_time) = time() + $delay_secs;
my($last_time) = 0;
my($cur_time) = time();
while ($cur_time < $end_time)
{
$cur_time = time();
if ($cur_time > $last_time)
{
print ".";
$last_time = $cur_time;
}
WaitNextEvent();
}
print "\n";
STDOUT->autoflush(0);
}
#//--------------------------------------------------------------------------------------------------
#// TimeStart
#//--------------------------------------------------------------------------------------------------
sub TimeStart()
{
return time();
}
#//--------------------------------------------------------------------------------------------------
#// TimeEnd
#//--------------------------------------------------------------------------------------------------
sub TimeEnd($$)
{
use integer;
my($start_time, $operation_name) = @_;
my($end_time) = time();
my($tot_sec) = $end_time - $start_time;
my($seconds) = $tot_sec;
my($hours) = $seconds / (60 * 60);
$seconds -= $hours * (60 * 60);
my($minutes) = $seconds / 60;
$seconds -= $minutes * 60;
print "$operation_name took $hours hours $minutes minutes and $seconds seconds\n";
}
#//--------------------------------------------------------------------------------------------------
#// Remove all files from a tree, leaving directories intact (except "CVS").
#//--------------------------------------------------------------------------------------------------
sub EmptyTree($)
{
my ($root) = @_;
#print "EmptyTree($root)\n";
opendir(DIR, $root);
my $sub;
foreach $sub (readdir(DIR))
{
my $fullpathname = $root.$sub; # -f, -d only work on full paths
# Don't call empty tree for the alias of a directory.
# -d returns true for the alias of a directory, false for a broken alias)
if (-d $fullpathname)
{
if (-l $fullpathname) # delete aliases
{
unlink $fullpathname;
next;
}
EmptyTree($fullpathname.":");
if ($sub eq "CVS")
{
#print "rmdir $fullpathname\n";
rmdir $fullpathname;
}
}
else
{
unless (unlink $fullpathname) { die "Failed to delete $fullpathname\n"; }
}
}
closedir(DIR);
}
#//--------------------------------------------------------------------------------------------------
#// Recurse through a directory hierarchy, looking for MANIFEST files.
#// Currently unused.
#//--------------------------------------------------------------------------------------------------
sub ScanForManifestFiles($$$$)
{
my($dir, $theme_root, $theme_name, $dist_dir) = @_;
opendir(DIR, $dir) or die "Cannot open dir $dir\n";
my @files = readdir(DIR);
closedir DIR;
my $file;
foreach $file (@files)
{
my $filepath = $dir.":".$file;
if (-d $filepath)
{
# print "Looking for MANIFEST files in $filepath\n";
ScanForManifestFiles($filepath, $theme_root, $theme_name, $dist_dir);
}
elsif ($file eq "MANIFEST")
{
# print "Doing manifest file $filepath\n";
# Get the dest path from the first line of the file
open(MANIFEST, $filepath) || die "Could not open file $file";
# Read in the path if available
my($dest_line) = <MANIFEST>;
chomp $dest_line;
close MANIFEST;
$dest_line =~ s|^#!dest[\t ]+|| || die "No destination line found in $filepath\n";
my($dest_path) = $dist_dir."chrome:skins:$theme_name:$dest_line";
# print " Destination is $dest_path\n";
InstallResources($filepath, "$dest_path", 0);
}
}
}
#-----------------------------------------------
# SetupBuildLog
#-----------------------------------------------
sub SetupBuildLog($$)
{
my($logfile_path, $timestamped_log) = @_;
my($logdir) = "";
my($logfile) = $logfile_path;
if ($logfile_path =~ /(.+?:)([^:]+)$/) # ? for non-greedy match
{
$logdir = $1;
$logfile = $2;
mkpath($logdir);
}
if ($timestamped_log)
{
#Use time-stamped names so that you don't clobber your previous log file!
my $now = localtime();
while ($now =~ s@:@.@) {} # replace all colons by periods
OpenErrorLog("${logdir}${now}");
}
else
{
OpenErrorLog("${logdir}${logfile}");
}
}
#-----------------------------------------------
# SetBuildNumber
#-----------------------------------------------
sub SetBuildNumber($$)
{
my($build_num_file, $files_to_touch) = @_;
# Make sure we add the config dir to search, to pick up mozBDate.pm
# Need to do this dynamically, because this module can be used before
# mozilla/config has been checked out.
my ($inc_path) = $0; # $0 is the path to the parent script
$inc_path =~ s/:build:mac:build_scripts:.+$/:config/;
push(@INC, $inc_path);
require mozBDate;
mozBDate::UpdateBuildNumber($build_num_file, $main::MOZILLA_OFFICIAL);
my($file);
foreach $file (@$files_to_touch)
{
print "Writing build number to $file from ${file}.in\n";
mozBDate::SubstituteBuildNumber($file, $build_num_file, "${file}.in");
}
}
#-----------------------------------------------
# SetTimeBomb
#-----------------------------------------------
sub SetTimeBomb($$)
{
my ($warn_days, $bomb_days) = @_;
system("perl :mozilla:config:mac-set-timebomb.pl $warn_days $bomb_days");
}
#//--------------------------------------------------------------------------------------------------
#// Regenerate a configuration header file if necessary
#//--------------------------------------------------------------------------------------------------
sub UpdateConfigHeader($)
{
my($config_path) = @_;
my($config, $oldconfig) = ("", "");
my($define, $definevalue, $defines);
my($k, $l,);
foreach $k (keys(%main::options))
{
if ($main::options{$k})
{
foreach $l (keys(%{$main::optiondefines{$k}}))
{
$my::defines{$l} = $main::optiondefines{$k}{$l};
print "Setting up my::defines{$l}\n";
}
}
}
my $config_headerfile = current_directory().$config_path;
if (-e $config_headerfile)
{
open(CONFIG_HEADER, "< $config_headerfile") || die "$config_headerfile: $!\n";
my($line);
while ($line = <CONFIG_HEADER>)
{
if ($line =~ m/#define\s+([^\s]*)\s+([^\s]*)\s*\n/)
{
$define = $1;
$definevalue = $2;
#canonicalize so that whitespace changes are not significant
my $canon_value = "#define " . $define . " " . $definevalue . "\n";
$oldconfig .= $canon_value;
if (exists ($my::defines{$define}) and ($my::defines{$define} == $definevalue))
{
delete $my::defines{$define};
$config .= $canon_value;
}
}
}
close(CONFIG_HEADER);
}
if (%my::defines)
{
foreach $k (keys(%my::defines))
{
$config .= "#define " . $k . " " . $my::defines{$k} . "\n";
}
}
my $file_name = basename($config_headerfile);
if (($config ne $oldconfig) || (!-e $config_headerfile))
{
printf("Writing new configuration header $file_name\n");
open(CONFIG_HEADER, "> $config_headerfile") || die "$config_headerfile: $!\n";
print(CONFIG_HEADER "/* This file is auto-generated based on build options. Do not edit. */\n");
print CONFIG_HEADER ($config);
close(CONFIG_HEADER);
MacPerl::SetFileInfo("CWIE", "TEXT", $config_headerfile);
}
else
{
printf("Configuration header $file_name is up-to-date\n");
}
}
1;

View File

@@ -1,660 +0,0 @@
#!perl
package Moz::CodeWarriorLib;
=pod
=head1 NAME
CodeWarriorLib - supply interface to CodeWarrior
=head1 SYNOPSIS
#!perl
use CodeWarriorLib;
CodeWarriorLib::activate();
$had_errors = CodeWarriorLib::build_project(
$project_path, $target_name, $recent_errors_file, $clean_build
);
=head1 DESCRIPTION
Replaces the AppleScript library I<CodeWarriorLib>.
=over 4
=cut
use strict;
use Cwd;
use File::Basename;
use Mac::Types;
use Mac::Events;
use Mac::AppleEvents;
use Mac::AppleEvents::Simple;
use Mac::Processes;
use Mac::MoreFiles;
use Mac::StandardFile;
use vars qw($VERSION);
$VERSION = '1.02';
my($app) = 'CWIE';
my($scriptDir) = cwd(); # could use $0 for this
my($ide_loc_file) = "";
# 0 == don't switch CWIE to front app in do_event(), 1 == do switch
# note: activate() still switches when called
$Mac::AppleEvents::Simple::SWITCH = 0;
# $Mac::AppleEvents::Simple::WARN = 1;
# supply your own path to the source here
#_test('PowerPudgeIV:mozilla:mozilla:');
# If you want to understand the gobbldeygook that's used to build Apple Events,
# you should start by reading the AEGizmos documentation.
=pod
=item _get_project($full_path)
A private routine returning a reference to the open project with the given name,
or else the empty string (when that project is not open)
full_path is a string identifying the project to be built and is of the form,
e.g., "HD:ProjectFolder:MyProject.mcp". It must be supplied.
=cut
sub _get_project ($) {
my(
$full_path, $candidate_projects
) = @_;
$candidate_projects = _doc_named(basename($full_path, '*'));
if ($candidate_projects) {
my($cps) = _get_dobj($candidate_projects);
my($num) = AECountItems($cps);
if ($num) { # is a list
foreach (1 .. AECountItems($cps)) {
my($cp) = AEGetNthDesc($cps, $_);
if (lc $full_path eq lc _full_path($cp)) {
return($cp);
}
}
} else { # is only one, not a list
if (lc $full_path eq lc _full_path($cps)) {
return($cps);
}
}
}
return;
}
=pod
=item build_project
Build a selected target of a project, saving any errors to a file, if supplied.
full_path is a string identifying the project to be built and is of the form,
e.g., "HD:ProjectFolder:MyProject.mcp". It must be supplied.
If target_name is the empty string, the current target of the selected project
will be built, else, target_name should be a string matching a target name in
the selected project.
If error_path is the empty string, errors will not be saved to a file,
else, error_path should be the full path of a file to save error messages into.
=cut
$CodeWarriorLib::CLOSE_PROJECTS_FIRST = 0; # If true we close then make. If false, make then close.
my $last_project_built = "";
my $last_project_was_closed = 0;
sub build_project ($;$$$) {
my(
$full_path, $target_name, $error_path,
$remove_object, $p, $project_was_closed, $had_errors
) = @_;
_close_errors_window();
if ($CodeWarriorLib::CLOSE_PROJECTS_FIRST && ($last_project_built ne $full_path))
{
# If we're in "close first" mode, we don't close if the current project
# is the same as the previous one.
if ($last_project_was_closed) {
$p = _get_project($last_project_built);
_close($p);
}
$last_project_built = $full_path;
$last_project_was_closed = 0; # now refers to the new project
}
$project_was_closed = 0;
while (1) {
$p = _get_project($full_path);
if (!$p) {
if ($project_was_closed) {
print "### Error - request for project document failed after opening\n";
die "### possibly CW Pro 4 bug: be sure to close your Find window\n";
}
$project_was_closed = 1;
$last_project_was_closed = 1;
_open_file($full_path);
} else {
last;
}
}
$had_errors = 0;
if ($target_name eq '') {
if ($remove_object) {_remove_object($p)}
_build($p);
} else {
if ($remove_object) {_remove_object($p, $target_name)}
_build($p, $target_name);
}
if ($error_path ne '') {
_save_errors_window($error_path);
}
$had_errors = _close_errors_window();
if (!$CodeWarriorLib::CLOSE_PROJECTS_FIRST)
{
if ($project_was_closed) {
$p = _get_project($full_path);
_close($p);
}
}
return($had_errors);
}
=pod
=item appIsRunning()
=cut
sub _appIsRunning($)
{
my ($appSignature) = @_;
my ($psi);
my ($found) = 0;
my ($appPSN);
foreach $psi (values(%Process))
{
if ($psi->processSignature() eq $appSignature)
{
$appPSN = $psi->processNumber();
$found = 1;
last;
}
}
return $found;
}
=pod
=item appIsFrontmost()
=cut
sub _appIsFrontmost($)
{
my ($appSignature) = @_;
my ($psi);
my ($found) = 0;
my ($appPSN);
foreach $psi (values(%Process))
{
if ($psi->processSignature() eq $appSignature)
{
$appPSN = $psi->processNumber();
$found = 1;
last;
}
}
return (GetFrontProcess() == $appPSN);
}
=pod
=item activate()
Launches CodeWarrior and brings it to the front.
Once found, path will be saved in $idepath_file for future reference.
Edit or delete this file to change the location of the IDE. If app is
moved, C<activate()> will prompt for a new location.
First looks for an open CodeWarrior app. Second, tries to open previously
saved location in ':idepath.txt'. Third, tries to find it and allow user
to choose it with Navigation Services (if present). Fourth, uses good old
GUSI routines built-in to MacPerl for a Choose Directory dialog box.
=cut
sub activate ($) {
$ide_loc_file = $_[0]; # save in global
my($filepath, $appath, $psi) = ($ide_loc_file);
foreach $psi (values(%Process)) {
if ($psi->processSignature() eq $app) {
$appath = $psi->processAppSpec();
_save_appath($filepath, $appath);
last;
}
}
if (!$appath || !-x $appath) {
$appath = _read_appath($filepath);
}
if (!$appath || ! -x $appath)
{
# make sure that MacPerl is a front process
#ActivateApplication('McPL');
MacPerl::Answer("Please locate the CodeWarrior application.", "OK");
# prompt user for the file name, and store it
my $macFile = StandardGetFile( 0, "APPL");
if ( $macFile->sfGood() )
{
$appath = $macFile->sfFile();
}
else
{
die "Operation canceled\n";
}
# if (eval {require Mac::Navigation}) {
# my($options, $nav);
# Mac::Navigation->import();
# $options = NavGetDefaultDialogOptions();
# $options->message('Where is CodeWarrior IDE?');
# $options->windowTitle('Find CodeWarrior IDE');
# $nav = NavChooseObject($Application{$app}, $options);
# die "CodeWarrior IDE not found.\n" if (!$nav || !$nav->file(1));
# $appath = $nav->file(1);
# } else {
# local(*D);
# my $cwd = `pwd`;
# $appath = _get_folder(
# 'Where is the CW IDE folder?',
# dirname($Application{$app})
# );
# die "CodeWarrior IDE not found.\n" if !$appath;
# opendir(D, $appath) or die $!;
# chdir($appath);
# foreach my $file (sort readdir (D)) {
# my(@app) = MacPerl::GetFileInfo($file);
# if ($app[0] && $app[1] &&
# $app[1] eq 'APPL' && $app[0] eq $app
# ) {
# $appath .= $file;
# last;
# }
# }
# chomp($cwd);
# chdir($cwd);
# }
_save_appath($filepath, $appath);
}
my($lp) = LaunchParam->new(
launchAppSpec => $appath,
launchControlFlags => launchContinue() + launchNoFileFlags()
);
unless (LaunchApplication($lp)) {
unlink($filepath);
die $^E;
}
# wait for CodeWarrior to show up in the list of processes
while (!_appIsRunning('CWIE'))
{
WaitNextEvent();
}
# wait for CodeWarrior to come to the front
while (!_appIsFrontmost('CWIE'))
{
WaitNextEvent();
}
}
=pod
=item getCodeWarriorPath()
Returns a file path relative to the CodeWarrior folder
=cut
sub getCodeWarriorPath($)
{
my($subfolder)=@_;
my($app_path) = _read_appath($ide_loc_file);
if ($app_path eq "") { die "Error: Failed to get CodeWarrior IDE path\n"; }
my($codewarrior_root) = $app_path;
$codewarrior_root =~ s/[^:]*$//;
return ($codewarrior_root . $subfolder);
}
=pod
=item getCodeWarriorIDEName()
Returns the name of the CodeWarrior application
=cut
sub getCodeWarriorIDEName()
{
my($subfolder)=@_;
my($app_path) = _read_appath($ide_loc_file);
if ($app_path eq "") { die "Error: Failed to get CodeWarrior IDE path\n"; }
my(@codewarrior_path) = split(/:/, $app_path);
return pop(@codewarrior_path);
}
=pod
=item quit()
Quits CodeWarrior.
=cut
sub quit() {
$last_project_built = "";
$last_project_was_closed = 0;
my($evt) = do_event(qw/aevt quit/, $app);
}
sub _build ($;$) {
my($evt);
if ($_[1]) {
my($prm) =
q"'----':obj {form:name, want:type(TRGT), seld:TEXT(@), from:" .
AEPrint($_[0]) . '}';
$evt = do_event(qw/CWIE MAKE/, $app, $prm, $_[1]);
} else {
my($prm) = q"'----':" . AEPrint($_[0]);
$evt = do_event(qw/CWIE MAKE/, $app, $prm);
}
}
sub _remove_object ($;$) {
my($evt);
if ($_[1]) {
my($prm) =
q"'----':obj {form:name, want:type(TRGT), seld:TEXT(@), from:" .
AEPrint($_[0]) . '}';
$evt = do_event(qw/CWIE RMOB/, $app, $prm, $_[1]);
} else {
my($prm) = q"'----':" . AEPrint($_[0]);
$evt = do_event(qw/CWIE RMOB/, $app, $prm);
}
}
sub _open_file ($) {
my($prm) =
q"'----':obj {form:name, want:type(alis), " .
q"seld:TEXT(@), from:'null'()}";
do_event(qw/aevt odoc/, $app, $prm, $_[0]);
}
sub import_project ($$) {
my($xml_file, $project_path) = @_;
my($prm) = "kocl:type(PRJD), rtyp:TEXT(@), data:TEXT(@), &subj:'null'()";
my($evt) = do_event(qw/core crel/, $app, $prm, $project_path, $xml_file);
my($result) = _get_event_result($evt);
if ($result eq "") {
_close(_get_project($project_path));
}
return $result;
}
sub export_project ($$) {
my($project_path, $xml_out_path) = @_;
my($p, $project_was_closed);
$project_was_closed = 0;
while (1) {
$p = _get_project($project_path);
if (!$p) {
if ($project_was_closed) {
print "### Error - request for project document failed after opening\n";
die "### possibly CW bug: be sure to close your Find window\n";
}
$project_was_closed = 1;
_open_file($project_path);
} else {
last;
}
}
# avoid problems with the Project Messages window
_close_named_window("Project Messages");
my($prm) =
q"'----':obj {form:indx, want:type(PRJD), " .
q"seld:1, from:'null'()}, kfil:TEXT(@)";
my($evt) = do_event(qw/CWIE EXPT/, $app, $prm, $xml_out_path);
if ($project_was_closed) {
$p = _get_project($project_path);
_close($p);
}
return _get_event_result($evt);
}
sub _doc_named ($) {
my($prm) =
q"'----':obj {form:test, want:type(docu), from:'null'(), " .
q"seld:cmpd{relo:'= ', 'obj1':obj {form:prop, want:type" .
q"(prop), seld:type(pnam), from:'exmn'()}, 'obj2':TEXT(@)}}";
my($evt) = do_event(qw/core getd/, $app, $prm, $_[0]);
return($evt->{REPLY} eq 'aevt\ansr{}' ? undef : $evt);
}
sub _full_path ($) {
my($obj) = $_[0];
my($prm) =
q"'----':obj {form:prop, want:type(prop), seld:type(FILE), " .
q"from:" . AEPrint($_[0]) . q"}, rtyp:type(TEXT)";
my($evt) = do_event(qw/core getd/, $app, $prm);
return MacPerl::MakePath(
MacUnpack('fss ', (
AEGetParamDesc($evt->{REP}, keyDirectObject()))->data()->get()
)
);
}
sub _save_errors_window ($) {
my($prm) =
q"'----':obj {form:name, want:type(alis), seld:TEXT(@), from:'null'()}";
do_event(qw/MMPR SvMs/, $app, $prm, $_[0]);
}
sub _close_errors_window () {
return _close_named_window('Errors & Warnings');
}
sub _close_named_window ($) {
my($window_name) = @_;
my($prm) =
q"'----':obj {form:name, want:type(cwin), " .
q"seld:TEXT(@), from:'null'()}";
my($evt) = do_event(qw/core clos/, $app, $prm, $window_name);
return($evt->{REPLY} eq 'aevt\ansr{}' ? 1 : 0);
}
sub _close () {
my($prm) = q"'----':" . AEPrint($_[0]);
do_event(qw/core clos/, $app, $prm);
}
sub _get_dobj ($) {
return(AEGetParamDesc($_[0]->{REP}, keyDirectObject()));
}
sub _get_folder ($$) {
require 'GUSI.ph';
my($prompt, $default) = @_;
MacPerl::Choose(
GUSI::AF_FILE(), 0, $prompt, '',
GUSI::CHOOSE_DIR() + ($default ? &GUSI::CHOOSE_DEFAULT : 0),
$default
);
}
sub _get_event_result ($)
{
my($evt) = @_;
my($result) = $evt->{ERROR};
if ( $result eq "" && $evt->{ERRNO} != 0 )
{
$result = "unknown error (".$evt->{ERRNO}.")";
}
return $result;
}
sub _save_appath ($$) {
my($cwd) = cwd(); # remember the current working dir
chdir($scriptDir); # change dir to the script dir
local(*F);
open(F, '>' . $_[0]) or die $!;
print F $_[1];
close(F);
chdir($cwd); # restore the cwd
}
sub _read_appath ($) {
my($filepath) = @_;
my($cwd) = cwd(); # remember the current working dir
chdir($scriptDir); # change dir to the script dir
if (! -e $filepath) {
return "";
}
local(*F);
open(F, $filepath);
my($appath) = <F>;
close(F);
chdir($cwd); # restore the cwd
return($appath);
}
sub _test ($) {
activate($ide_loc_file);
my($path) = $_[0];
build_project(
"${path}modules:xml:macbuild:XML.mcp", '',
"${path}build:mac:Mozilla.BuildLog.part"
);
}
1;
=pod
=back
=head1 HISTORY
=over 4
=item v1.02, September 23, 1998
Made fixes in finding and saving location of CodeWarrior IDE.
=item v1.01, June 1, 1998
Made fixes to C<chdir()> in C<activate()>, made C<activate()> more robust
in finding CodeWarrior IDE, added global variable to NOT switch to IDE
for each sent event, a few other fixes.
=item v1.00, May 30, 1998
First shot
=back
=head1 AUTHORS
Chris Nandor F<E<lt>pudge@pobox.comE<gt>>, and the author of the
original I<CodeWarriorLib>, Scott Collins F<E<lt>scc@netscape.comE<gt>>.
=head1 SEE ALSO
BuildProject L<Moz>.
=head1 COPYRIGHT
The contents of this file are subject to the Netscape Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/NPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Mozilla Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
=cut

View File

@@ -1,573 +0,0 @@
#!perl -w
package Moz::Jar;
#
# Module for creating jar files, either using a jar manifest, or
# simply jarring up folders on disk.
#
require 5.004;
require Exporter;
use strict;
use Archive::Zip;
use File::Path;
use Mac::Files;
use Moz::Moz;
use vars qw( @ISA @EXPORT );
@ISA = qw(Exporter);
@EXPORT = qw(
CreateJarFileFromDirectory
CreateJarFromManifest
WriteOutJarFiles
SanityCheckJarOptions
);
#-------------------------------------------------------------------------------
# Add the contents of a directory to the zip file
#
#-------------------------------------------------------------------------------
sub _addDirToJar($$$$)
{
my($dir, $jar_root, $zip, $compress) = @_;
opendir(DIR, $dir) or die "Error: Cannot open dir $dir\n";
my @files = readdir(DIR);
closedir DIR;
my $unix_jar_root = $jar_root;
$unix_jar_root =~ s|:|/|g; # colon to slash conversion
my $file;
foreach $file (@files)
{
my $filepath = $dir.":".$file;
if (-d $filepath)
{
print "Adding files to jar from $filepath\n";
_addDirToJar($filepath, $jar_root, $zip, $compress);
}
else
{
my $member = Archive::Zip::Member->newFromFile($filepath);
die "Error: Failed to create zip file member $filepath\n" unless $member;
my $unixName = $filepath;
$unixName =~ s|:|/|g; # colon to slash conversion
$unixName =~ s|^$unix_jar_root||; # relativise
$member->fileName($unixName);
# print "Adding $file as $unixName\n";
if ($compress) {
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_DEFLATED);
} else {
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_STORED);
}
$zip->addMember($member);
}
}
}
#-------------------------------------------------------------------------------
# Add the contents of a directory to the zip file
#
#-------------------------------------------------------------------------------
sub CreateJarFileFromDirectory($$$)
{
my($srcdir, $jarpath, $compress) = @_;
my $zip = Archive::Zip->new();
_addDirToJar($srcdir, $srcdir, $zip, $compress);
print "Saving zip file...\n";
my $status = $zip->writeToFileNamed($jarpath);
if ($status == 0) {
print "Zipping completed successfully\n";
} else {
print "Error saving zip file\n";
}
# set the file type/creator to something reasonable
MacPerl::SetFileInfo("ZIP ", "ZIP ", $jarpath);
}
#-------------------------------------------------------------------------------
# printZipContents
#
#-------------------------------------------------------------------------------
sub printZipContents($)
{
my($zip) = @_;
my(@members) = $zip->memberNames();
print "Zip contains:\n";
my($member);
foreach $member (@members)
{
print " $member\n";
}
}
#-------------------------------------------------------------------------------
# safeSaveJarFile
#
# Archive::Zip has a problem where you cannot save a zip file on top of
# an existing zip file that it has open, because it holds references
# into that zip. So we have to save to a temp file, then do a swap.
#
# Note that the zip will become invalid after this operation.
# If you want to do further operations on it, you'll have to reread it.
#-------------------------------------------------------------------------------
sub safeSaveJarFile($$)
{
my($zip, $full_dest_path) = @_;
my($temp_file_name) = $full_dest_path."_temp";
($zip->writeToFileNamed($temp_file_name) == Archive::Zip::AZ_OK) || die "Error: died writing jar to temp file $temp_file_name\n";
unlink $full_dest_path;
(rename $temp_file_name, $full_dest_path) || die "Error: Failed to rename $temp_file_name\n";
MacPerl::SetFileInfo("ZIP ", "ZIP ", $full_dest_path);
}
#-------------------------------------------------------------------------------
# addToJarFile
#
# Add a file to a jar file
#
# Parameters:
# 1. Jar ID. Unix path of jar file inside chrome.
# 2. Abs path to jar.mn file (i.e. source) (mac breaks)
# 3. File source, relative to jar.mn path (mac breaks)
# 4. Abs path to the resulting .jar file (mac breaks)
# 5. Relative file path within the jar (unix breaks)
# 6. Reference to hash of jar files
#
#-------------------------------------------------------------------------------
sub addToJarFile($$$$$$$)
{
my($jar_id, $jar_man_dir, $file_src, $jar_path, $file_jar_path, $override, $jars) = @_;
# print "addToJarFile with:\n $jar_man_dir\n $file_src\n $jar_path\n $file_jar_path\n";
unless ($jar_path =~ m/(.+:)([^:]+)$/) { die "Error: Bad jar path $jar_path\n"; }
my($target_dir) = $1;
my($jar_name) = $2;
$target_dir =~ s/[^:]+$//;
# print "¥ $target_dir $jar_name\n";
# find the source file
my($src) = $jar_man_dir.":".$file_src;
if ((!-e $src) && ($file_src =~ m/.+:([^:]+)$/)) # src does not exist. Fall back to looking for src in jar.mn dir
{
$file_src = $1;
$src = $jar_man_dir.":".$file_src;
if (!-e $src) {
die "Error: Can't find chrome file $src\n";
}
}
if ($main::options{chrome_jars})
{
my($zip) = $jars->{$jar_id};
unless ($zip) { die "Error: Can't find Zip entry for $jar_id\n"; }
# print "Adding $file_src to jar file $jar_path at $file_jar_path\n";
my($member) = Archive::Zip::Member->newFromFile($src);
unless ($member) { die "Error: Failed to create zip file member $src\n"; }
$member->fileName($file_jar_path);
my($compress) = 1;
if ($compress) {
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_DEFLATED);
$member->desiredCompressionLevel(Archive::Zip::COMPRESSION_LEVEL_DEFAULT); # defaults to 6
} else {
$member->desiredCompressionMethod(Archive::Zip::COMPRESSION_STORED);
}
my($old_member) = $zip->memberNamed($file_jar_path);
if ($override)
{
if ($old_member)
{
# print "Overriding $file_jar_path in jar file $jar_id\n";
# need to compare mod dates or use the + here
$zip->removeMember($old_member);
}
$zip->addMember($member);
}
else
{
if ($old_member)
{
#compare dates here
my($member_moddate) = $old_member->lastModTime();
my($file_moddate) = GetFileModDate($src);
if ($file_moddate > $member_moddate)
{
print "Updating older file $file_jar_path in $jar_id\n";
$zip->removeMember($old_member);
$zip->addMember($member);
}
else
{
print "File $file_jar_path in $jar_id is more recent. Not updating.\n";
}
}
else
{
$zip->addMember($member);
}
}
}
if ($main::options{chrome_files}) # we install raw files too
{
my($rel_path) = $file_jar_path;
$rel_path =~ s|/|:|g; # slash to colons
my($dir_name) = $jar_name;
$dir_name =~ s/\.jar$//;
my($dst) = $target_dir.$dir_name.":".$rel_path;
# print "Aliassing $src\n to\n$dst\n";
if ($override)
{
unlink $dst;
MakeAlias($src, $dst); # don't check errors, otherwise we fail on replacement
}
else
{
if (-e $dst)
{
#compare dates here
my($dst_moddate) = GetFileModDate($dst);
my($file_moddate) = GetFileModDate($src);
if ($file_moddate > $dst_moddate)
{
print "Updating older file $rel_path in $dir_name\n";
unlink $dst;
MakeAlias($src, $dst);
}
else
{
print "File $file_jar_path in $jar_id is more recent. Not updating.\n";
}
}
else
{
MakeAlias($src, $dst);
}
}
}
}
#-------------------------------------------------------------------------------
# setupJarFile
#
# setup a zip for writing
#-------------------------------------------------------------------------------
sub setupJarFile($$$)
{
my($jar_id, $dest_path, $jar_hash) = @_;
# print "Creating jar file $jar_id at $jar_path\n";
my($jar_file) = $jar_id;
$jar_file =~ s|/|:|g; # slash to colons
my($full_jar_path) = full_path_to($dest_path.":".$jar_file);
if ($main::options{chrome_jars})
{
my($zip) = $jar_hash->{$jar_id};
if (!$zip) # if we haven't made it already, do so
{
my($zip) = Archive::Zip->new();
$jar_hash->{$jar_id} = $zip;
# does the jar file exist already? If so, read it in
if (-e $full_jar_path)
{
print "Reading in jar file $jar_id\n";
if ($zip->read($full_jar_path) != Archive::Zip::AZ_OK) { die "Error: Failed to re-read $full_jar_path\n"; }
# printZipContents($zip);
}
}
}
else
{
# installing files.
# nothing to do. MakeAlias creates dirs as needed.
# add this jar to the list
$jar_hash->{$jar_id} = 1;
}
}
#-------------------------------------------------------------------------------
# closeJarFile
#
# We're done with this jar file _for this jar.mn_. We may add more entries
# to it later, so keep it open in the hash.
#-------------------------------------------------------------------------------
sub closeJarFile($$)
{
my($jar_path, $jar_hash) = @_;
# print "Closing jar file $jar_path\n";
if ($main::options{chrome_jars})
{
}
else
{
# installing files.
# nothing to do
}
}
#-------------------------------------------------------------------------------
# WriteOutJarFiles
#
# Now we dump out the jars
#-------------------------------------------------------------------------------
sub WriteOutJarFiles($$)
{
my($chrome_dir, $jars) = @_;
unless ($main::options{chrome_jars}) { return; }
my($full_chrome_path) = full_path_to($chrome_dir);
my($key);
foreach $key (keys %$jars)
{
my($zip) = $jars->{$key};
my($rel_path) = $key;
$rel_path =~ s/\//:/g;
my($output_path) = $full_chrome_path.":".$rel_path;
print "Writing zip file $key to $output_path\n";
# ensure the target dirs exist
my($path) = $output_path;
$path =~ s/[^:]+$//;
mkpath($path);
# unlink $output_path; # remove any existing jar
safeSaveJarFile($zip, $output_path);
# $zip is invalid after this operation, so nuke it here
$jars->{$key} = 0;
}
}
#-------------------------------------------------------------------------------
# registerChromePackage
#
# Enter a chrome package into the installed-chrome.txt file
#-------------------------------------------------------------------------------
sub registerChromePackage($$$$$$)
{
my($jar_file, $file_path, $chrome_dir, $jar_hash, $chrome_type, $pkg_name) = @_;
my($manifest_subdir) = $jar_file;
$manifest_subdir =~ s/:/\//g;
my($chrome_entry);
if ($main::options{use_jars}) {
$chrome_entry = "$chrome_type,install,url,jar:resource:/chrome/$manifest_subdir!/$chrome_type/$pkg_name";
} else {
$manifest_subdir =~ s/\.jar$//;
$chrome_entry = "$chrome_type,install,url,resource:/chrome/$manifest_subdir/$chrome_type/$pkg_name";
}
# print "Entering $chrome_entry in installed-chrome.txt\n";
# ensure chrome_dir exists
mkpath($chrome_dir);
my($inst_chrome) = ${chrome_dir}.":installed-chrome.txt";
if (open(CHROMEFILE, "<$inst_chrome")) {
while (<CHROMEFILE>) {
chomp;
if ($_ eq $chrome_entry) {
# $chrome_entry already appears in installed-chrome.txt file
# just update the mod date
my $now = time;
utime($now, $now, $inst_chrome) || die "Error: Couldn't touch $inst_chrome";
print "+++ updating chrome $inst_chrome\n+++\t\t$chrome_entry\n";
close(CHROMEFILE) || die "Error: can't close $inst_chrome: $!";
return 0;
}
}
close(CHROMEFILE) || die "Error: can't close $inst_chrome: $!";
}
open(CHROMEFILE, ">>${inst_chrome}") || die "Error: Failed to open $inst_chrome\n";
print(CHROMEFILE "${chrome_entry}\n");
close(CHROMEFILE) || die "Error: Failed to close $inst_chrome\n";
print "+++ adding chrome $inst_chrome\n+++\t\t$chrome_entry\n";
}
#-------------------------------------------------------------------------------
# Create or add to a jar file from a jar.mn file.
# Both arguments are relative to the mozilla root dir.
#
#
#-------------------------------------------------------------------------------
sub CreateJarFromManifest($$$)
{
my($jar_man_path, $dest_path, $jars) = @_;
if ($main::options{chrome_jars}) {
print "Jarring from $jar_man_path\n";
}
if ($main::options{chrome_files}) {
print "Installing files from $jar_man_path\n";
}
$jar_man_path = full_path_to($jar_man_path);
$dest_path = full_path_to($dest_path);
# if the jars hash is empty, nuke installed-chrome.txt
if (! scalar(%$jars))
{
print "Nuking installed-chrome.txt\n";
my($installed_chrome) = $dest_path.":installed-chrome.txt";
# unlink $installed_chrome;
}
my $jar_man_dir = "";
my $jar_man_file = "";
if ($jar_man_path =~ /(.+):([^:]+)$/)
{
$jar_man_dir = $1; # no trailing :
$jar_man_file = $2;
}
# Keep a hash of jar files, keyed on relative jar path (e.g. "packages/core.jar")
# Entries are open Archive::Zips (if zipping), and installed-chrome entries.
my($jar_id) = ""; # Current foo/bar.jar from jar.mn file
my($jar_file) = ""; # relative path to jar file (from $dest_path), with mac separators
my($full_jar_path);
open(FILE, "<$jar_man_path") || die "Error: could not open \"$jar_man_path\": $!";
while (<FILE>)
{
my($line) = $_;
chomp($line);
# print "$line\n";
if ($line =~ /^\s*\#.*$/) { # skip comments
next;
}
if ($line =~/^([\w\d.\-\_\\\/]+)\:\s*$/) # line start jar file entries
{
$jar_id = $1;
$jar_file = $jar_id;
$jar_file =~ s|/|:|g; # slash to colons
$full_jar_path = $dest_path.":".$jar_file;
setupJarFile($jar_id, $dest_path, $jars);
}
elsif ($line =~ /^(\+?)\s+([\w\d.\-\_\\\/]+)\s*(\([\w\d.\-\_\\\/]+\))?$\s*/) # jar file entry
{
my($override) = ($1 eq "+");
my($file_dest) = $2;
my($file_src) = $3;
if ($file_src) {
$file_src = substr($file_src, 1, -1); #strip the ()
} else {
$file_src = $file_dest;
}
$file_src =~ s|/|:|g;
if ($jar_file ne "") # if jar is open, add to jar
{
if ($file_dest =~ /([\w\d.\-\_]+)\/([\w\d.\-\_\\\/]+)contents.rdf/)
{
my $chrome_type = $1;
my $pkg_name = $2;
registerChromePackage($jar_file, $file_dest, $dest_path, $jars, $chrome_type, $pkg_name);
}
addToJarFile($jar_id, $jar_man_dir, $file_src, $full_jar_path, $file_dest, $override, $jars);
}
else
{
die "Error: bad jar.mn format at $line\n";
}
}
elsif ($line =~ /^\s*$/ ) # blank line
{
if ($jar_file ne "") #if a jar file is open, close it
{
closeJarFile($full_jar_path, $jars);
$jar_file = "";
$full_jar_path = "";
}
}
}
close(FILE);
if ($jar_file ne "") #if a jar file is open, close it
{
closeJarFile($full_jar_path, $jars);
}
}
1;

View File

@@ -1,228 +0,0 @@
#!perl -w
package Moz::MacCVS;
# package Mac::Apps::MacCVS; this should really be the name of the package
# but due to our directory hierarchy in mozilla, I am not doing it
require 5.004;
require Exporter;
use strict;
use Exporter;
use vars qw($VERSION @ISA @EXPORT);
use Cwd;
use File::Basename;
use Mac::StandardFile;
use Mac::AppleEvents;
use Mac::AppleEvents::Simple;
@ISA = qw(Exporter);
@EXPORT = qw(new describe checkout update);
$VERSION = "1.00";
# If you want to understand the gobbldeygook that's used to build Apple Events,
# you should start by reading the AEGizmos documentation.
# Architecture:
# cvs session object:
# name - session name
# session_file - session file
#
#
my($last_error) = 0;
my($gAppSig) = 'Mcvs'; # MacCVS Pro
#
# utility routines
#
sub _checkForEventError($)
{
my($evt) = @_;
if ($evt->{ERRNO} != 0)
{
print STDERR "Error. Script returned '$evt->{ERROR} (error $evt->{ERRNO})\n";
$last_error = $evt->{ERRNO};
return 0;
}
return 1; # success
}
#
# Session object methods
#
sub new
{
my ( $proto, $session_file) = @_;
my $class = ref($proto) || $proto;
my $self = {};
if ( defined($session_file) && ( -e $session_file) )
{
$self->{"name"} = basename( $session_file );
$self->{"session_file"} = $session_file;
bless $self, $class;
return $self;
}
else
{
print STDERR "MacCVS->new cvs file < $session_file > does not exist\n";
return;
}
}
# makes sure that the session is open
# assertSessionOpen()
# returns 1 on success
sub assertSessionOpen()
{
my ($self) = shift;
$last_error = 0;
my($prm) =
q"'----':obj {form:name, want:type(alis), seld:TEXT(@), from:'null'()}";
my($evt) = do_event(qw/aevt odoc/, $gAppSig, $prm, $self->{session_file});
return _checkForEventError($evt);
}
# prints the cvs object, used mostly for debugging
sub describe
{
my($self) = shift;
$last_error = 0;
print "MacCVS:: name: ", $self->{name}, " session file: ", $self->{session_file}, "\n";
}
# checkout( self, module, revision, date)
# MacCVS checkout command
# returns 1 on success.
sub checkout()
{
my($self, $module, $revision, $date ) = @_;
unless( defined ($module) ) { $module = ""; } # get rid of the pesky undefined warnings
unless( defined ($revision) ) { $revision = ""; }
unless( defined ($date) ) { $date = ""; }
$last_error = 0;
$self->assertSessionOpen() || die "Error: failed to open MacCVS session file at $self->{session_file}\n";
my($revstring) = ($revision ne "") ? $revision : "(none)";
my($datestring) = ($date ne "") ? $date : "(none)";
print "Checking out $module with revision $revstring, date $datestring\n";
my($prm) =
q"'----':obj {form:name, want:type(docu), seld:TEXT(@), from:'null'()}, ".
q"modl:'TEXT'(@), tagr:'TEXT'(@), tagd:'TEXT'(@) ";
my($evt) = do_event(qw/MCvs cout/, $gAppSig, $prm, $self->{name}, $module, $revision, $date);
return _checkForEventError($evt);
}
# update( self, branch tag, list of paths)
# MacCVS udate command
# returns 1 on success.
# NOTE: MacCVS Pro does not correctly support this stuff yet (as of version 2.7d5).
sub update()
{
my($self, $branch, $paths ) = @_;
$last_error = 0;
$self->assertSessionOpen() || die "Error: failed to open MacCVS session file at $self->{session_file}\n";
if ($branch eq "HEAD") {
$branch = "";
}
my($paths_list) = "";
my($path);
foreach $path (@$paths)
{
if ($paths_list ne "") {
$paths_list = $paths_list.", ";
}
$paths_list = $paths_list."Ò".$path."Ó";
}
my($prm) =
q"'----':obj {form:name, want:type(docu), seld:TEXT(@), from:'null'()}, ".
q"tagr:'TEXT'(@), tFls:[";
$prm = $prm.$paths_list."]";
my($evt) = do_event(qw/MCvs updt/, $gAppSig, $prm, $self->{name}, $branch);
return _checkForEventError($evt);
};
sub getLastError()
{
return $last_error;
}
1;
=pod
=head1 NAME
MacCVS - Interface to MacCVS
=head1 SYNOPSIS
use MacCVS;
$session = MacCVS->new( <session_file_path>) || die "cannot create session";
$session->checkout([module] [revision] [date]) || die "Could not check out";
=head1 DESCRIPTION
This is a MacCVS interface for talking to MacCVS Pro client.
MacCVSSession is the class used to manipulate the session
=item new
MacCVS->new( <cvs session file path>);
Creates a new session. Returns undef on failure.
=item checkout( <module> [revision] [date] )
cvs checkout command. Revision and date are optional
returns 0 on failure
=cut
=head1 SEE ALSO
=over
=item MacCVS Home Page
http://www.maccvs.org/
=back
=head1 AUTHORS
Aleks Totic atotic@netscape.com
Simon Fraser sfraser@netscape.com
=cut
__END__

View File

@@ -1,603 +0,0 @@
=head1 NAME
B<Moz> - routines for automating CodeWarrior builds, and some extra-curricular
activities related to building Mozilla
=head1 SYNOPSIS
use Moz;
OpenErrorLog(":::BuildLog");
StopForErrors();
$Moz::QUIET = 1;
InstallFromManifest(":projects:MANIFEST", $dist_dir);
BuildProjectClean(":projects:SomeProject.mcp", "SomeTarget");
MakeAlias(":projects:SomeProject.shlb", $dist_dir);
DontStopForErrors();
BuildProject(":projects:SomeOtherProject.mcp", "SomeTarget");
=head1 DESCRIPTION
B<Moz> comprises the routines needed to slap CodeWarrior around, force it
to build a sequence of projects, report the results, and a few other things.
This module should only contain functions that are generic to any build,
not just the Mozilla build.
=cut
package Moz::Moz;
require Exporter;
use Cwd;
use File::Copy;
use File::Path;
use File::Basename;
use Mac::Types;
use Mac::Events;
use Mac::Processes;
use ExtUtils::Manifest 'maniread';
use Moz::CodeWarriorLib;
@ISA = qw(Exporter);
@EXPORT = qw( LaunchCodeWarrior
GetCodeWarriorRelativePath
current_directory
full_path_to
DoBuildProject
ImportXMLProject
ExportProjectToXML
OpenErrorLog
MakeAlias
GetFileModDate
StopForErrors
DontStopForErrors
InstallFromManifest
InstallResources
RedirectOutputToFile
Delay
ActivateApplication
IsProcessRunning);
@EXPORT_OK = qw(CloseErrorLog QUIET);
sub current_directory()
{
my $current_directory = cwd();
chop($current_directory) if ( $current_directory =~ m/:$/ );
return $current_directory;
}
sub full_path_to($)
{
my ($path) = @_;
if ( $path =~ m/^[^:]+$/ )
{
$path = ":" . $path;
}
if ( $path =~ m/^:/ )
{
$path = current_directory() . $path;
}
return $path;
}
$logging = 0;
$recent_errors_file = "";
$stop_on_1st_error = 1;
$QUIET = 0;
=head2 Logging all the errors and warnings - C<OpenErrorLog($log_file)>, C<CloseErrorLog()>
The warnings and errors generated in the course of building projects can be logged to a file.
Tinderbox uses this facility to show why a remote build failed.
Logging is off by default.
Start logging at any point in your build process with C<OpenErrorLog($log_file)>.
Stop with C<CloseErrorLog()>.
You never need to close the log explicitly, unless you want to just log a couple of projects in the middle of a big list.
C<CloseErrorLog()> is not exported by default.
=cut
sub CloseErrorLog()
{
if ( $logging )
{
close(ERROR_LOG);
$logging = 0;
StopForErrors() if $stop_on_1st_error;
}
}
sub OpenErrorLog($)
{
my ($log_file) = @_;
CloseErrorLog();
if ( $log_file )
{
$log_file = full_path_to($log_file);
open(ERROR_LOG, ">$log_file") || die "Error: Can't open $log_file\n";
MacPerl::SetFileInfo("CWIE", "TEXT", $log_file);
$log_file =~ m/.+:(.+)/;
$recent_errors_file = full_path_to("$1.part");
$logging = 1;
}
}
=head2 Stopping before it's too late - C<StopForErrors()>, C<DontStopForErrors()>
When building a long list of projects, you decide whether to continue building subsequent projects when one fails.
By default, your build script will C<die> after the first project that generates an error while building.
Change this behavior with C<DontStopForErrors()>.
Re-enable it with C<StopForErrors()>.
=cut
sub StopForErrors()
{
$stop_on_1st_error = 1;
# Can't stop for errors unless we notice them.
# Can't notice them unless we are logging.
# If the user didn't explicitly request logging, log to a temporary file.
if ( ! $recent_errors_file )
{
OpenErrorLog("${TMPDIR}BuildResults");
}
}
sub DontStopForErrors()
{
$stop_on_1st_error = 0;
}
sub log_message($)
{
if ( $logging )
{
my ($message) = @_;
print ERROR_LOG $message;
}
}
sub log_message_with_time($)
{
if ( $logging )
{
my ($message) = @_;
my $time_stamp = localtime();
log_message("$message ($time_stamp)\n");
}
}
sub log_recent_errors($)
{
my ($project_name) = @_;
my $found_errors = 0;
if ( $logging )
{
open(RECENT_ERRORS, "<$recent_errors_file");
while( <RECENT_ERRORS> )
{
if ( /^Error/ || /^CouldnÕt find project file/ || /^Link Error/ )
{
# if (!$found_errors)
# print $_;
$found_errors = 1;
}
print ERROR_LOG $_;
}
close(RECENT_ERRORS);
unlink("$recent_errors_file");
}
if ( $stop_on_1st_error && $found_errors )
{
print ERROR_LOG "### Build failed.\n";
die "### Errors encountered building \"$project_name\".\n";
}
}
sub DoBuildProject($$$)
{
my ($project_path, $target_name, $clean_build) = @_;
$project_path = full_path_to($project_path);
# $project_path =~ m/.+:(.+)/;
# my $project_name = $1;
log_message_with_time("### Building \"$project_path\"");
# Check that the given project exists
if (! -e $project_path)
{
print ERROR_LOG "### Build failed.\n";
die "### Can't find project file \"$project_path\".\n";
}
print "Building \"$project_path\[$target_name\]\"\n";
$had_errors = Moz::CodeWarriorLib::build_project(
$project_path, $target_name, $recent_errors_file, $clean_build
);
WaitNextEvent();
# $had_errors =
#MacPerl::DoAppleScript(<<END_OF_APPLESCRIPT);
# tell (load script file "$CodeWarriorLib") to BuildProject("$project_path", "$project_name", "$target_name", "$recent_errors_file", $clean_build)
#END_OF_APPLESCRIPT
# Append any errors to the globally accumulated log file
# if ( $had_errors ) # Removed this test, because we want warnings, too. -- jrm
{
log_recent_errors($project_path);
}
}
sub ImportXMLProject($$)
{
my ($xml_path, $project_path) = @_;
# my ($codewarrior_ide_name) = Moz::CodeWarriorLib::getCodeWarriorIDEName();
# my $ascript = <<EOS;
# tell application "$codewarrior_ide_name"
# make new (project document) as ("$project_path") with data ("$xml_path")
# end tell
#EOS
# print $ascript."\n";
# my($result) = MacPerl::DoAppleScript($ascript);
# unless ($result) { die "Error: ImportXMLProject AppleScript failed $^E $result\n"; }
#
my($import_error) = Moz::CodeWarriorLib::import_project($xml_path, $project_path);
if ($import_error ne "") {
die "Error: ImportXMLProject failed with error $import_error\n";
}
}
sub ExportProjectToXML($$)
{
my ($project_path, $xml_path) = @_;
my (@suffix_list) = (".mcp");
my ($project_name, $project_dir, $suffix) = fileparse($project_path, @suffix_list);
if ($suffix eq "") { die "Project: $project_path doesn't look like a project file.\n"; }
if (-e $xml_path) {
print "$xml_path exists - not exporting $project_path\n";
}
else {
print "Exporting $project_path to $xml_path\n";
my($export_error) = Moz::CodeWarriorLib::export_project($project_path, $xml_path);
if ($export_error ne "") {
die "Error: export_project failed with error '$export_error'\n";
}
if (! -e $xml_path) {
die "Error: XML export to $xml_path failed\n";
}
}
}
=head2 Miscellaneous
C<MakeAlias($old_file, $new_file)> functions like C<symlink()>, except with better argument defaulting and more explicit error messages.
=cut
sub MakeAlias($$)
{
my ($old_file, $new_file) = @_;
# if the directory to hold $new_file doesn't exist, create it
if ( ($new_file =~ m/(.+:)/) && !-d $1 )
{
mkpath($1);
}
# if a leaf name wasn't specified for $new_file, use the leaf from $old_file
if ( ($new_file =~ m/:$/) && ($old_file =~ m/.+:(.+)/) )
{
$new_file .= $1;
}
my $message = "Can't create a Finder alias (at \"$new_file\")\n for \"$old_file\"; because ";
die "Error: $message \"$old_file\" doesn't exist.\n" unless -e $old_file;
die "Error: $message I won't replace an existing (non-alias) file with an alias.\n" if ( -e $new_file && ! -l $new_file );
# now: $old_file exists; $new_file doesn't (or else, is an alias already)
if ( -l $new_file )
{
# ...then see if it already points to $old_file
my $current_target = full_path_to(readlink($new_file));
my $new_target = full_path_to($old_file);
return if ( $current_target eq $new_target );
# if the desired alias already exists and points to the right thing, then we're done
unlink $new_file;
}
symlink($old_file, $new_file) || die "Error: $message symlink returned an unexpected error.\n";
}
=pod
C<InstallFromManifest()>
=cut
sub InstallFromManifest($;$$)
{
my ($manifest_file, $dest_dir, $flat) = @_;
$flat = 0 unless defined($flat); # if $flat, all rel. paths in MANIFEST get aliased to the root of $dest_dir
$dest_dir ||= ":";
$manifest_file =~ m/(.+):/;
my $source_dir = $1;
chop($dest_dir) if $dest_dir =~ m/:$/;
#Mac::Events->import();
WaitNextEvent();
if ($flat)
{
print "Doing manifest on \"$manifest_file\" FLAT\n" unless $QUIET;
}
else
{
print "Doing manifest on \"$manifest_file\"\n" unless $QUIET;
}
my $read = maniread(full_path_to($manifest_file));
foreach $file (keys %$read)
{
next unless $file;
$subdir = ":";
if (!$flat && ($file =~ /:.+:/ ))
{
$subdir = $&;
}
$file = ":$file" unless $file =~ m/^:/;
MakeAlias("$source_dir$file", "$dest_dir$subdir");
}
}
=pod
C<InstallResources()>
=cut
# parameters are path to MANIFEST file, destination dir, true (to make copies) or false (to make aliases)
sub InstallResources($;$;$)
{
my ($manifest_file, $dest_dir, $copy_files) = @_;
$dest_dir ||= ":";
mkpath($dest_dir) if !-d $dest_dir;
$manifest_file =~ m/(.+):/;
my $source_dir = $1;
chop($dest_dir) if $dest_dir =~ m/:$/;
WaitNextEvent();
print "Installing resources from \"$manifest_file\"\n" unless $QUIET;
my $read = maniread(full_path_to($manifest_file));
foreach $file (keys %$read)
{
next unless $file;
if ($copy_files)
{
copy("$source_dir:$file", "$dest_dir:$file");
}
else
{
MakeAlias("$source_dir:$file", "$dest_dir:$file");
}
}
}
#//--------------------------------------------------------------------------------------------------
#// Delay
#//--------------------------------------------------------------------------------------------------
sub Delay($)
{
my ($delay_seconds) = @_;
$now = time;
$exit_time = $now + $delay_seconds;
while ($exit_time > $now) {
$now = time;
}
}
#//--------------------------------------------------------------------------------------------------
#// GetFileModDate
#//--------------------------------------------------------------------------------------------------
sub GetFileModDate($)
{
my($filePath)=@_;
my($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,
$atime,$mtime,$ctime,$blksize,$blocks) = stat($filePath);
return $mtime;
}
#//--------------------------------------------------------------------------------------------------
#// LaunchCodeWarrior
#//--------------------------------------------------------------------------------------------------
sub LaunchCodeWarrior($)
{
my($idepath_file) = @_; # full path to IDE location file
my($cur_dir) = cwd();
# this both launches and writes the IDE path file
Moz::CodeWarriorLib::activate($idepath_file);
chdir($cur_dir);
}
#//--------------------------------------------------------------------------------------------------
#// GetCodeWarriorRelativePath
#//--------------------------------------------------------------------------------------------------
sub GetCodeWarriorRelativePath($)
{
my($rel_path) = @_;
return Moz::CodeWarriorLib::getCodeWarriorPath($rel_path);
}
#//--------------------------------------------------------------------------------------------------
#// RedirectOutputToFile
#//--------------------------------------------------------------------------------------------------
sub RedirectOutputToFile($)
{
my($log_file) = @_;
# ensure that folders in the path exist
my($logdir) = "";
my($logfile) = $log_file;
if ($log_file =~ /(.+?:)([^:]+)$/) # ? for non-greedy match
{
$logdir = $1;
$logfile = $2;
mkpath($logdir);
}
print "Output is now being redirected to the file '$log_file'\n";
open(STDOUT, "> $log_file") || die "Can't redirect stdout";
open(STDERR, ">&STDOUT") || die "Can't dup stdout";
select(STDERR); $| = 1; # make unbuffered
select(STDOUT); $| = 1; # make unbuffered
MacPerl::SetFileInfo("CWIE", "TEXT", $log_file);
}
#//--------------------------------------------------------------------------------------------------
#// ActivateApplication
#//--------------------------------------------------------------------------------------------------
sub ActivateApplication($)
{
my ($appSignature) = @_;
my ($psi, $found);
my ($appPSN);
$found = 0;
foreach $psi (values(%Process))
{
if ($psi->processSignature() eq $appSignature)
{
$appPSN = $psi->processNumber();
$found = 1;
last;
}
}
if ($found == 0 || SameProcess($appPSN, GetFrontProcess()))
{
return;
}
SetFrontProcess($appPSN);
while (GetFrontProcess() != $appPSN)
{
WaitNextEvent();
}
}
#//--------------------------------------------------------------------------------------------------
#// IsProcessRunning
#//--------------------------------------------------------------------------------------------------
sub IsProcessRunning($)
{
my($processName, $psn, $psi) = @_;
while ( ($psn, $psi) = each(%Process) ) {
if ($psi->processName eq $processName) { return 1; }
}
return 0;
}
1;
=head1 AUTHORS
Scott Collins <scc@netscape.com>, Simon Fraser <sfraser@netscape.com>, Chris Yeh <cyeh@netscape.com>
=head1 SEE ALSO
BuildMozillaDebug.pl (et al), BuildList.pm, CodeWarriorLib (an AppleScript library)
=head1 COPYRIGHT
The contents of this file are subject to the Netscape Public
License Version 1.1 (the "License"); you may not use this file
except in compliance with the License. You may obtain a copy of
the License at http://www.mozilla.org/NPL/
Software distributed under the License is distributed on an "AS
IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
implied. See the License for the specific language governing
rights and limitations under the License.
The Original Code is Mozilla Communicator client code, released
March 31, 1998.
The Initial Developer of the Original Code is Netscape
Communications Corporation. Portions created by Netscape are
Copyright (C) 1998-1999 Netscape Communications Corporation. All
Rights Reserved.
Contributor(s):
=cut

View File

@@ -1,272 +0,0 @@
package Moz::Prefs;
require 5.004;
require Exporter;
# Package that attempts to read a file from the Preferences folder,
# and get build settings out of it
use strict;
use Exporter;
use File::Path;
use Mac::Files;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(ReadMozUserPrefs);
#-------------------------------------------------------------------------------
#
# GetPrefsFolder
#
#-------------------------------------------------------------------------------
sub GetPrefsFolder()
{
my($prefs_folder) = FindFolder(kOnSystemDisk, kPreferencesFolderType, 1);
return $prefs_folder.":Mozilla build prefs";
}
#-------------------------------------------------------------------------------
#
# SetArrayValue
#
#-------------------------------------------------------------------------------
sub SetArrayValue($$$)
{
my($array_ref, $index1, $index2) = @_;
my($index);
foreach $index (@$array_ref)
{
if ($index->[0] eq $index1)
{
$index->[1] = $index2;
return 1;
}
}
return 0;
}
#-------------------------------------------------------------------------------
#
# WriteDefaultPrefsFile
#
#-------------------------------------------------------------------------------
sub WriteDefaultPrefsFile($)
{
my($file_path) = @_;
my($file_contents);
$file_contents = <<'EOS';
% You can use this file to customize the Mozilla build system.
% The following kinds of lines are allowable:
% Comment lines, which start with a '%' in the first column
% Lines which modify the default build settings. For the list of flags,
% see MozBuildFlags.pm. Examples are:
%
% build pull 0 % don't pull
% options mng 1 % turn mng on
%
% Line containing the special 'buildfrom' flag, which specifies
% where to start the build. Example:
%
% buildfrom nglayout % where to start the build
%
% Lines which specify the location of the files used to store paths
% to the CodeWarrior IDE, and the MacCVS Pro session file. Note quoting
% of paths containing whitespace. Examples:
%
% filepath idepath ::codewarrior.txt
% filepath sessionpath ":Some folder:MacCVS session path.txt"
%
% Lines which modify the build settings like %main::DEBUG.
% Any lines which do not match either of the above are assumed
% to set variables on $main::. Examples:
%
% MOZILLA_OFFICIAL 1
%
EOS
$file_contents =~ s/%/#/g;
local(*PREFS_FILE);
open(PREFS_FILE, "> $file_path") || die "Could not write default prefs file\n";
print PREFS_FILE ($file_contents);
close(PREFS_FILE);
MacPerl::SetFileInfo("McPL", "TEXT", $file_path);
}
#-------------------------------------------------------------------------------
#
# HandlePrefSet
#
#-------------------------------------------------------------------------------
sub HandlePrefSet($$$$)
{
my($flags, $name, $value, $desc) = @_;
if (SetArrayValue($flags, $name, $value)) {
print "Prefs set $desc flag '$name' to '$value'\n";
} else {
die "$desc setting '$name' is not a valid option\n";
}
}
#-------------------------------------------------------------------------------
#
# HandleBuildFromPref
#
#-------------------------------------------------------------------------------
sub HandleBuildFromPref($$)
{
my($build_array, $name) = @_;
my($setting) = 0;
my($index);
foreach $index (@$build_array)
{
if ($index->[0] eq $name) {
$setting = 1;
}
$index->[1] = $setting;
}
if ($setting == 1) {
print "Building from $name onwards, as specified by prefs\n";
} else {
printf "Failed to find buildfrom setting '$name'\n";
}
}
#-------------------------------------------------------------------------------
#
# ReadPrefsFile
#
#-------------------------------------------------------------------------------
sub ReadPrefsFile($$$$$)
{
my($file_path, $build_flags, $options_flags, $filepath_flags, $create_if_missing) = @_;
local(*PREFS_FILE);
if (open(PREFS_FILE, "< $file_path"))
{
print "Reading build prefs from '$file_path'\n";
while (<PREFS_FILE>)
{
my($line) = $_;
chomp($line);
if ($line =~ /^\#/ || $line =~ /^\s*$/) { # ignore comments and empty lines
next;
}
if (($line =~ /^\s*([^#\s]+)\s+([^#\s]+)\s+\"(.+)\"(\s+#.+)?/) ||
($line =~ /^\s*([^#\s]+)\s+([^#\s]+)\s+\'(.+)\'(\s+#.+)?/) ||
($line =~ /^\s*([^#\s]+)\s+([^#\s]+)\s+([^#\s]+)(\s+#.+)?/))
{
my($array_name) = $1;
my($option_name) = $2;
my($option_value) = $3;
# print "Read '$array_name' '$option_name' '$option_value'\n";
if ($array_name eq "build")
{
HandlePrefSet($build_flags, $option_name, $option_value, "Build");
}
elsif ($array_name eq "options")
{
HandlePrefSet($options_flags, $option_name, $option_value, "Options");
}
elsif ($array_name eq "filepath" && $option_name && $option_value)
{
HandlePrefSet($filepath_flags, $option_name, $option_value, "Filepath");
}
else
{
print "Unknown pref option at $line\n";
}
}
elsif ($line =~ /^\s*buildfrom\s+([^#\s]+)(\s+#.+)?/)
{
my($build_start) = $1;
HandleBuildFromPref($build_flags, $build_start);
}
elsif ($line =~ /^\s*([^#\s]+)\s+([^#\s]+)(\s+#.+)?/)
{
my($build_var) = $1;
my($var_setting) = $2;
print "Setting \$main::$build_var to $var_setting\n";
eval "\$main::$build_var = \"$var_setting\"";
}
else
{
print "Unrecognized input line at $line\n";
}
}
close(PREFS_FILE);
}
elsif ($create_if_missing)
{
print "No prefs file found at $file_path; using defaults\n";
my($folder_path) = $file_path;
$folder_path =~ s/[^:]+$//;
mkpath($folder_path);
WriteDefaultPrefsFile($file_path);
}
}
#-------------------------------------------------------------------------------
#
# ReadMozUserPrefs
#
#-------------------------------------------------------------------------------
sub ReadMozUserPrefs($$$$)
{
my($prefs_file_name, $build_flags, $options_flags, $filepath_flags) = @_;
if ($prefs_file_name eq "") { return; }
# if local prefs exist, just use those. Othewise, look in the prefs folder
if (-e $prefs_file_name)
{
# read local prefs
ReadPrefsFile($prefs_file_name, $build_flags, $options_flags, $filepath_flags, 0);
}
else
{
# first read prefs folder prefs
my($prefs_path) = GetPrefsFolder();
$prefs_path .= ":$prefs_file_name";
ReadPrefsFile($prefs_path, $build_flags, $options_flags, $filepath_flags, 1);
}
}
1;

View File

@@ -1,932 +0,0 @@
#!/usr/bin/perl
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# 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):
# Simon Fraser <sfraser@netscape.com>
#
package Moz::ProjectXML;
require 5.004;
require Exporter;
use strict;
use Exporter;
use Cwd;
use XML::DOM;
use vars qw(@ISA @EXPORT);
@ISA = qw(Exporter);
@EXPORT = qw(
ParseXMLDocument
DisposeXMLDocument
WriteXMLDocument
CleanupPro5XML
GetTargetsList
CloneTarget
SetAsSharedLibraryTarget
SetAsStaticLibraryTarget
AddTarget
RemoveTarget
GetTargetSetting
SetTargetSetting
getChildElementTextContents
);
#--------------------------------------------------------------------------------------------------
# A module for reading, manipulating, and writing XML-format CodeWarrior project files.
#
# Sample usage:
#
# use ProjectXML;
#
# my $doc = ProjectXML::ParseXMLDocument("Test.mcp.xml");
# ProjectXML::CloneTarget($doc, "Test.shlb", "Test.lib");
# ProjectXML::SetAsStaticLibraryTarget($doc, "Test.lib", "TestOutput.lib");
# ProjectXML::WriteXMLDocument($doc, "Test_out.xml");
# ProjectXML::DisposeXMLDocument($doc);
#
#--------------------------------------------------------------------------------------------------
#//--------------------------------------------------------------------------------------------------
#// ParseXMLDocument
#// Note that the caller must call DisposeXMLDocument on the returned doc
#//--------------------------------------------------------------------------------------------------
sub ParseXMLDocument($)
{
my($doc_path) = @_;
my $parser = new XML::DOM::Parser(ErrorContext => 2);
my $doc = $parser->parsefile($doc_path);
return $doc;
}
#//--------------------------------------------------------------------------------------------------
#// DisposeXMLDocument
#// Needed to avoid memory leaks - cleanup circular references for garbage collection
#//--------------------------------------------------------------------------------------------------
sub DisposeXMLDocument($)
{
my($doc) = @_;
$doc->dispose();
}
#//--------------------------------------------------------------------------------------------------
#// WriteXMLDocument
#//--------------------------------------------------------------------------------------------------
sub _pro5_tag_compression($$)
{
return 1; # Pro 5 is broken and can't import XML with <foo/> style tags
}
sub _pro6plus_tag_compression($$)
{
return 0; # Pro 6 can deal with empty XML tags like <foo/>
}
sub WriteXMLDocument($$$)
{
my($doc, $file_path, $ide_version) = @_;
if ($ide_version eq "4.0")
{
XML::DOM::setTagCompression(\&_pro5_tag_compression);
}
else
{
XML::DOM::setTagCompression(\&_pro6plus_tag_compression);
}
$doc->printToFile($file_path);
}
#//--------------------------------------------------------------------------------------------------
#// CleanupPro5XML
#// XML Projects exported by Pro 5 contain garbage data under the MWMerge_MacOS_skipResources
#// setting. This routine cleans this up, saving the result to a new file
#//--------------------------------------------------------------------------------------------------
sub CleanupPro5XML($$)
{
my($xml_path, $out_path) = @_;
local(*XML_FILE);
open(XML_FILE, "< $xml_path") || die "Error: failed to open file $xml_path\n";
local(*CLEANED_FILE);
open(CLEANED_FILE, "> $out_path") || die "Error: failed to open file $out_path for writing\n";
my $in_skip_resources_settings = 0;
while(<XML_FILE>)
{
my($line) = $_;
if ($line =~ /^<\?codewarrior/) # is processing inst line
{
my $test_line = $line;
chomp($test_line);
my $out_line = $test_line;
if ($test_line =~ /^<\?codewarrior\s+exportversion=\"(.+)\"\s+ideversion=\"(.+)\"\s*\?>$/)
{
my $export_version = $1;
my $ide_version = $2;
$ide_version = "4.0_mozilla"; # pseudo IDE version so we know we touched it
$out_line = "<?codewarrior exportversion=\"".$export_version."\" ideversion=\"".$ide_version."\"?>";
}
print CLEANED_FILE "$out_line\n";
next;
}
if ($line =~ /MWMerge_MacOS_skipResources/)
{
$in_skip_resources_settings = 1;
print CLEANED_FILE "$line";
}
elsif($in_skip_resources_settings && $line =~ /<!-- Settings for/)
{
# leaving bad settings lines. Write closing tag
print CLEANED_FILE " <!-- Corrupted setting entries removed by script -->\n";
print CLEANED_FILE " </SETTING>\n\n";
print CLEANED_FILE "$line";
$in_skip_resources_settings = 0;
}
elsif (!$in_skip_resources_settings)
{
print CLEANED_FILE "$line";
}
}
close(XML_FILE);
close(CLEANED_FILE);
}
#--------------------------------------------------------------------------------------------------
# SniffProjectXMLIDEVersion
#
#--------------------------------------------------------------------------------------------------
sub SniffProjectXMLIDEVersion($)
{
my($xml_path) = @_;
my $found_version = "";
local(*XML_FILE);
open(XML_FILE, "< $xml_path") || die "Error: failed to open file $xml_path\n";
while(<XML_FILE>)
{
my($line) = $_;
chomp($line);
if ($line =~ /^<\?codewarrior/) # is processing inst line
{
unless ($line =~ /^<\?codewarrior\s+exportversion=\"(.+)\"\s+ideversion=\"(.+)\"\s*\?>$/)
{
die "Error: Failed to find ideversion in $xml_path in line $line\n";
}
my $export_version = $1;
my $ide_version = $2;
$found_version = $ide_version;
last;
}
}
close(XML_FILE);
return $found_version;
}
#//--------------------------------------------------------------------------------------------------
#// GetTargetsList
#// Returns an array of target names
#//--------------------------------------------------------------------------------------------------
sub GetTargetsList($)
{
my($doc) = @_;
my $nodes = $doc->getElementsByTagName("TARGET");
my $n = $nodes->getLength;
my @target_names;
for (my $i = 0; $i < $n; $i++)
{
my ($node) = $nodes->item($i);
my($target_name) = getChildElementTextContents($node, "NAME");
push(@target_names, $target_name);
}
return @target_names;
}
#//--------------------------------------------------------------------------------------------------
#// CloneTarget
#// Clone the named target, renaming it to 'new_name'
#//--------------------------------------------------------------------------------------------------
sub CloneTarget($$$)
{
my($doc, $target_name, $new_name) = @_;
my $target_node = getTargetNode($doc, $target_name);
# clone here
my $target_clone = $target_node->cloneNode(1); # deep clone
# -- munge target settings --
# set the target name field
setChildElementTextContents($doc, $target_clone, "NAME", $new_name);
# set the targetname pref
setTargetNodeSetting($doc, $target_clone, "Targetname", $new_name);
# -- insert new target subtree --
my $target_list = $target_node->getParentNode();
$target_list->appendChild($target_clone);
# -- now add to targetorder --
my (@target_order_nodes) = getChildOfDocument($doc, "TARGETORDER");
my $target_order = @target_order_nodes[0];
my $new_order = $doc->createElement("ORDEREDTARGET");
my $order_name = $doc->createElement("NAME");
$new_order->appendChild($order_name);
setChildElementTextContents($doc, $new_order, "NAME", $new_name);
$target_order->appendChild($new_order);
}
#//--------------------------------------------------------------------------------------------------
#// SetAsSharedLibraryTarget
#//
#//--------------------------------------------------------------------------------------------------
sub SetAsSharedLibraryTarget($$$)
{
my($doc, $target_name, $output_name) = @_;
my $target_node = getTargetNode($doc, $target_name);
setTargetNodeSetting($doc, $target_node, "MWProject_PPC_type", "SharedLibrary");
setTargetNodeSetting($doc, $target_node, "MWProject_PPC_filetype", "1936223330"); #'shlb'
setTargetNodeSetting($doc, $target_node, "MWProject_PPC_outfile", $output_name);
}
#//--------------------------------------------------------------------------------------------------
#// AddFileToTarget
#//
#// Add a file to the specified target(s).
#//
#//--------------------------------------------------------------------------------------------------
sub AddFileToTarget($$$)
{
my($doc, $target_list, $file_name) = @_;
# the file must be added in 3 places:
# 1. in <TARGET><FILELIST><FILE> (with linkage flags if necessary)
# 2. in <TARGET><LINKORDER><FILEREF>
# 3. in <GROUPLIST><GROUP><FILEREF>
die "Write me\n";
}
#//--------------------------------------------------------------------------------------------------
#// RemoveFileFromTarget
#//
#// Remove a file from the specified target, removing it from the entire project
#// if no other targets reference it.
#//
#//--------------------------------------------------------------------------------------------------
sub RemoveFileFromTarget($$$)
{
my($doc, $target_node, $file_name) = @_;
# the file must be removed in 3 places:
# 1. in <TARGET><FILELIST><FILE>
# 2. in <TARGET><LINKORDER><FILEREF>
# 3. in <GROUPLIST><GROUP><FILEREF>
# first, remove from <FILELIST>
my $filelist_node = getFirstChildElement($target_node, "FILELIST");
unless ($filelist_node) { die "Error: failed to find FILELIST node\n"; }
my $file_node = getChildNodeByGrandchildContents($doc, $filelist_node, "FILE", "PATH", $file_name);
unless ($file_node) { return; }
$filelist_node->removeChild($file_node);
# next, remove from <LINKORDER>
my $linkorder_node = getFirstChildElement($target_node, "LINKORDER");
unless ($linkorder_node) { die "Error: failed to find LINKORDER node\n"; }
my $fileref_node = getChildNodeByGrandchildContents($doc, $linkorder_node, "FILEREF", "PATH", $file_name);
unless ($fileref_node) { die "Error: link order node for file $file_name not found\n"; }
$linkorder_node->removeChild($fileref_node);
# last, remove from <GROUPLIST>
# <GROUPLIST> is cross-target, so we have to be careful here.
my $grouplist_node = getChildOfDocument($doc, "GROUPLIST");
unless ($grouplist_node) { die "Error: failed to find GROUPLIST node\n"; }
# if the file isn't in any other targets, remove it from the groups
if (!GetFileInUse($doc, $file_name))
{
print "File $file_name is in no other targest. Removing from project\n";
my @group_nodes;
getChildElementsOfType($doc, $grouplist_node, "GROUP", \@group_nodes);
my $group_node;
foreach $group_node (@group_nodes)
{
my @fileref_nodes;
getChildElementsOfType($doc, $group_node, "FILEREF", \@fileref_nodes);
my $fileref_node;
foreach $fileref_node (@fileref_nodes)
{
my $path_name = getChildElementTextContents($fileref_node, "PATH");
if ($path_name eq $file_name)
{
print "Removing $file_name from project group list\n";
$group_node->removeChild($fileref_node);
last;
}
}
# can a file appear in more than one group?
}
}
}
#//--------------------------------------------------------------------------------------------------
#// SetAsStaticLibraryTarget
#//
#//--------------------------------------------------------------------------------------------------
sub SetAsStaticLibraryTarget($$$)
{
my($doc, $target_name, $output_name) = @_;
my $target_node = getTargetNode($doc, $target_name);
setTargetNodeSetting($doc, $target_node, "MWProject_PPC_type", "Library");
setTargetNodeSetting($doc, $target_node, "MWProject_PPC_filetype", "1061109567"); #'????'
setTargetNodeSetting($doc, $target_node, "MWProject_PPC_outfile", $output_name);
# static targets don't need any library linkage, so we can remove linkage
# with all .shlb and .Lib files.
my(@obsolete_files) = ("NSStdLibStubs", "InterfacesStubs", "InterfaceLib", "InternetConfigLib");
print " Removing libraries etc. from target\n";
# get all files in target
my @target_files = GetTargetFilesList($doc, $target_name);
my $target_file;
foreach $target_file (@target_files)
{
if ($target_file =~ /(\.shlb|\.lib|\.Lib|\.o|\.exp)$/)
{
RemoveFileFromTarget($doc, $target_node, $target_file);
}
}
print " Removing stub libraries from target\n";
# then remove files with known names
my $obs_file;
foreach $obs_file (@obsolete_files)
{
RemoveFileFromTarget($doc, $target_node, $obs_file);
}
}
#//--------------------------------------------------------------------------------------------------
#// AddTarget
#//
#//--------------------------------------------------------------------------------------------------
sub AddTarget($$)
{
my($doc, $target_name) = @_;
die "Write me\n";
}
#//--------------------------------------------------------------------------------------------------
#// RemoveTarget
#//
#//--------------------------------------------------------------------------------------------------
sub RemoveTarget($$)
{
my($doc, $target_name) = @_;
die "Write me\n";
}
#//--------------------------------------------------------------------------------------------------
#// GetTargetSetting
#// Get the value for the specified setting in the specified target
#//--------------------------------------------------------------------------------------------------
sub GetTargetSetting($$$)
{
my($doc, $target_name, $setting_name) = @_;
my $target_node = getTargetNode($doc, $target_name);
return getTargetNodeSetting($target_node, "VALUE");
}
#//--------------------------------------------------------------------------------------------------
#// SetTargetSetting
#// Set the value for the specified setting in the specified target
#//--------------------------------------------------------------------------------------------------
sub SetTargetSetting($$$$)
{
my($doc, $target_name, $setting_name, $new_value) = @_;
my $target_node = getTargetNode($doc, $target_name);
setTargetNodeSetting($doc, $target_node, "VALUE", $new_value);
}
#//--------------------------------------------------------------------------------------------------
#// GetTargetFilesList
#// Return an array of the files in the target (in filelist order)
#//--------------------------------------------------------------------------------------------------
sub GetTargetFilesList($$)
{
my($doc, $target_name) = @_;
my $target_node = getTargetNode($doc, $target_name);
my @files_list;
my $filelist_node = getFirstChildElement($target_node, "FILELIST");
unless ($filelist_node) { die "Error: failed to find FILELIST node\n"; }
my @file_nodes;
getChildElementsOfType($doc, $filelist_node, "FILE", \@file_nodes);
my $node;
foreach $node (@file_nodes)
{
my $file_name = getChildElementTextContents($node, "PATH");
push(@files_list, $file_name);
}
return @files_list;
}
#//--------------------------------------------------------------------------------------------------
#// FileIsInTarget
#//
#//--------------------------------------------------------------------------------------------------
sub FileIsInTarget($$$)
{
my($doc, $file_name, $target_name) = @_;
my $target_node = getTargetNode($doc, $target_name);
unless ($target_node) { die "Error: no target found called $target_name\n"; }
my $file_node = GetTargetFileNode($doc, $target_node, $file_name);
if ($file_node) {
return 1;
}
return 0;
}
#//--------------------------------------------------------------------------------------------------
#// GetFileTargetsList
#// Return an array of the targets that a file is in (expensive)
#//--------------------------------------------------------------------------------------------------
sub GetFileTargetsList($$)
{
my ($doc, $file_name) = @_;
my @target_list;
my @targets = GetTargetsList($doc);
my $target;
foreach $target (@targets)
{
if (FileIsInTarget($doc, $file_name, $target))
{
push(@target_list, $target);
}
}
return @target_list;
}
#//--------------------------------------------------------------------------------------------------
#// GetTargetFileNode
#//
#//--------------------------------------------------------------------------------------------------
sub GetTargetFileNode($$$)
{
my($doc, $target_node, $file_name) = @_;
my $filelist_node = getFirstChildElement($target_node, "FILELIST");
unless ($filelist_node) { die "Error: failed to find FILELIST node\n"; }
my $file_node = getChildNodeByGrandchildContents($doc, $filelist_node, "FILE", "PATH", $file_name);
return $file_node;
}
#//--------------------------------------------------------------------------------------------------
#// GetFileInUse
#// Return true if the file is used by any target
#//--------------------------------------------------------------------------------------------------
sub GetFileInUse($$)
{
my($doc, $file_name) = @_;
my $targetlist_node = getChildOfDocument($doc, "TARGETLIST");
my $target_node = $targetlist_node->getFirstChild();
while ($target_node)
{
if ($target_node->getNodeTypeName eq "ELEMENT_NODE" &&
$target_node->getTagName() eq "TARGET")
{
# if this is a target node
my $file_node = GetTargetFileNode($doc, $target_node, $file_name);
if ($file_node) {
return 1; # found it
}
}
$target_node = $target_node->getNextSibling();
}
# not found
return 0;
}
#//--------------------------------------------------------------------------------------------------
#// getChildOfDocument
#//--------------------------------------------------------------------------------------------------
sub getChildOfDocument($$)
{
my($doc, $child_type) = @_;
return getFirstChildElement($doc->getDocumentElement(), $child_type);
}
#//--------------------------------------------------------------------------------------------------
#// getFirstChildElement
#//--------------------------------------------------------------------------------------------------
sub getFirstChildElement($$)
{
my($node, $element_name) = @_;
my $found_node;
unless ($node) { die "getFirstChildElement called with empty node\n"; }
#look for the first "element_name" child
my $child_node = $node->getFirstChild();
while ($child_node)
{
if ($child_node->getNodeTypeName eq "ELEMENT_NODE" &&
$child_node->getTagName() eq $element_name)
{
$found_node = $child_node;
last;
}
$child_node = $child_node->getNextSibling();
}
return $found_node;
}
#//--------------------------------------------------------------------------------------------------
#// getChildElementsOfType
#//
#// Return an array of refs to child nodes of the given type
#//--------------------------------------------------------------------------------------------------
sub getChildElementsOfType($$$$)
{
my($doc, $node, $child_type, $array_ref) = @_;
my $child_node = $node->getFirstChild();
while ($child_node)
{
if ($child_node->getNodeTypeName eq "ELEMENT_NODE" &&
$child_node->getTagName() eq $child_type)
{
push(@$array_ref, $child_node);
}
$child_node = $child_node->getNextSibling();
}
}
#//--------------------------------------------------------------------------------------------------
#// getChildElementTextContents
#//--------------------------------------------------------------------------------------------------
#
# Given <FOOPY><NERD>Hi!</NERD></FOOPY>, where $node is <FOOPY>,
# returns "Hi!". If > 1 <NERD> node, returns the contents of the first.
#
sub getChildElementTextContents($$)
{
my($node, $tag_name) = @_;
my $first_element = getFirstChildElement($node, $tag_name);
my $text_node = $first_element->getFirstChild();
my $text_contents = "";
# concat adjacent text nodes
while ($text_node)
{
if ($text_node->getNodeTypeName() ne "TEXT_NODE")
{
last;
}
$text_contents = $text_contents.$text_node->getData();
$text_node = $text_node->getNextSibling();
}
return $text_contents;
}
#//--------------------------------------------------------------------------------------------------
#// setChildElementTextContents
#//--------------------------------------------------------------------------------------------------
sub setChildElementTextContents($$$$)
{
my($doc, $node, $tag_name, $contents_text) = @_;
my $first_element = getFirstChildElement($node, $tag_name);
my $new_text_node = $doc->createTextNode($contents_text);
# replace all child elements with a text element
removeAllChildren($first_element);
$first_element->appendChild($new_text_node);
}
#//--------------------------------------------------------------------------------------------------
#// getChildNodeByContents
#//
#// Consider <foo><bar><baz>Foopy</baz></bar><bar><baz>Loopy</baz></bar></foo>
#// This function, when called with getChildNodeByContents($foonode, "bar", "baz", "Loopy")
#// returns the second <bar> node.
#//--------------------------------------------------------------------------------------------------
sub getChildNodeByGrandchildContents($$$$$)
{
my($doc, $node, $child_type, $gc_type, $gc_contents) = @_; # gc = grandchild
my $found_node;
my $child_node = $node->getFirstChild();
while ($child_node)
{
if ($child_node->getNodeTypeName eq "ELEMENT_NODE" &&
$child_node->getTagName() eq $child_type)
{
# check for a child of this node of type
my $child_contents = getChildElementTextContents($child_node, $gc_type);
if ($child_contents eq $gc_contents)
{
$found_node = $child_node;
last;
}
}
$child_node = $child_node->getNextSibling();
}
return $found_node;
}
#//--------------------------------------------------------------------------------------------------
#// getTargetNode
#//--------------------------------------------------------------------------------------------------
sub getTargetNode($$)
{
my($doc, $target_name) = @_;
my $targetlist_node = getChildOfDocument($doc, "TARGETLIST");
return getChildNodeByGrandchildContents($doc, $targetlist_node, "TARGET", "NAME", $target_name);
}
#//--------------------------------------------------------------------------------------------------
#// getTargetNamedSettingNode
#//--------------------------------------------------------------------------------------------------
sub getTargetNamedSettingNode($$)
{
my($target_node, $setting_name) = @_;
my $setting_node;
my $settinglist_node = getFirstChildElement($target_node, "SETTINGLIST");
my $child_node = $settinglist_node->getFirstChild();
while ($child_node)
{
if ($child_node->getNodeTypeName ne "ELEMENT_NODE")
{
$child_node = $child_node->getNextSibling();
next;
}
if ($child_node->getTagName() eq "SETTING")
{
my $set_name = getChildElementTextContents($child_node, "NAME");
if ($set_name eq $setting_name)
{
$setting_node = $child_node;
last;
}
}
$child_node = $child_node->getNextSibling();
}
return $setting_node;
}
#//--------------------------------------------------------------------------------------------------
#// getTargetNodeSetting
#//--------------------------------------------------------------------------------------------------
sub getTargetNodeSetting($$)
{
my($target_node, $setting_name) = @_;
my $setting_node = getTargetNamedSettingNode($target_node, $setting_name);
return getChildElementTextContents($setting_node, "VALUE");
}
#//--------------------------------------------------------------------------------------------------
#// setTargetNodeSetting
#//--------------------------------------------------------------------------------------------------
sub setTargetNodeSetting($$$$)
{
my($doc, $target_node, $setting_name, $new_value) = @_;
my $setting_node = getTargetNamedSettingNode($target_node, $setting_name);
setChildElementTextContents($doc, $setting_node, "VALUE", $new_value);
}
#//--------------------------------------------------------------------------------------------------
#// elementInArray
#//--------------------------------------------------------------------------------------------------
sub elementInArray($$)
{
my($element, $array) = @_;
my $test;
foreach $test (@$array)
{
if ($test eq $element) {
return 1;
}
}
return 0;
}
#//--------------------------------------------------------------------------------------------------
#// removeAllChildren
#//--------------------------------------------------------------------------------------------------
sub removeAllChildren($)
{
my($node) = @_;
my $child_node = $node->getFirstChild();
while ($child_node)
{
$node->removeChild($child_node);
$child_node = $node->getFirstChild();
}
}
#//--------------------------------------------------------------------------------------------------
#// dumpNodeData
#//--------------------------------------------------------------------------------------------------
sub dumpNodeData($)
{
my($node) = @_;
unless ($node) { die "Null node passed to dumpNodeData\n"; }
print "Dumping node $node\n";
my($node_type) = $node->getNodeTypeName();
if ($node_type eq "ELEMENT_NODE")
{
my($node_name) = $node->getTagName();
print "Element $node_name\n";
}
elsif ($node_type eq "TEXT_NODE")
{
my($node_data) = $node->getData;
# my(@node_vals) = unpack("C*", $node_data);
print "Text '$node_data'\n"; # may contain LF chars
}
else
{
print "Node $node_type\n";
}
}
#//--------------------------------------------------------------------------------------------------
#// dumpNodeTree
#//--------------------------------------------------------------------------------------------------
sub dumpNodeTree($)
{
my($node) = @_;
my($child_node) = $node->getFirstChild();
unless ($child_node) { return; }
# recurse
dumpNodeData($child_node);
# then go through child nodes
while ($child_node)
{
dumpNodeTree($child_node);
$child_node = $child_node->getNextSibling();
}
}
1;

View File

@@ -1,90 +0,0 @@
#-------------------------------------------------------------------------------
# These 3 lists are the 'master lists' to control what gets built.
#
# Ordering in these arrays is important; it has to reflect the order in
# which the build occurs.
#
# Setting containing spaces must be quoted with double quotes.
#-------------------------------------------------------------------------------
build_flags
all 1
pull 0
dist 0
config 0
xpidl 0
idl 0
stubs 0
runtime 0
common 0
imglib 0
libimg2 0
necko 0
security 0
browserutils 0
intl 0
nglayout 0
accessiblity 0
editor 0
embedding 0
viewer 0
xpapp 0
extensions 0
plugins 0
mailnews 0
apprunner 0
resources 0
options_flags
pull_by_date 0
chrome_jars 1
chrome_files 0
use_jars 1
transformiix 1
mathml 0 MOZ_MATHML
svg 0 MOZ_SVG
# svg requires libart, which is an lgpl library. You need to pull it
# explicitly.
libart_lgpl 0
mng 1
ldap 1 MOZ_LDAP_XPCOM
ldap_experimental 0 MOZ_LDAP_XPCOM_EXPERIMENTAL
xmlextras 1
wsp 0 MOZ_WSP
inspector 1
mailextras 1
xptlink 0
psm 0 MOZ_PSM
embedding_test 1
embedding_chrome 0
embedding_xulprefs 0
embedding_xulsecurity 0
carbon 0 TARGET_CARBON
useimg2 1 USE_IMG2
lowmem 0 MOZ_MAC_LOWMEM
accessible 1 ACCESSIBILITY
bidi 1 IBMBIDI
p3p 0
jsd 1
venkman 1
moz_logging 1 MOZ_LOGGING
chatzilla 1
content_packs 1
xml_rpc 1
cview 1
help 1
timeline 0 MOZ_TIMELINE
static_build 0 MOZ_STATIC_COMPONENT_LIBS
string_debug 0 DEBUG_STRING
string_stats 0 DEBUG_STRING_STATS
xpctools 0 XPC_TOOLS_SUPPORT
smime 1
mdn 1
print_preview 1 NS_PRINT_PREVIEW
moz_xul 1 MOZ_XUL
filepath_flags
idepath ":CodeWarrior IDE Path.txt"
sessionpath ":Mozilla session path.txt"
buildlogfilepath ":Build Logs:Mozilla build log.txt" # this is a path
scriptlogfilepath ":Build Logs:Mozilla script log.txt"

File diff suppressed because it is too large Load Diff

View File

@@ -1,22 +0,0 @@
# List of modules to check out. Format is
# module, (tag), (date)
# where tag and date are optional (non-trailing commas are required)
#
# Examples:
# mozilla/nsprpub, NSPRPUB_CLIENT_TAG
# mozilla/gc, , 10/25/2000 12:00:00
#
mozilla/nsprpub, NETSCAPE_7_0_RTM
mozilla/security/nss, NETSCAPE_7_0_RTM
mozilla/security/manager, NETSCAPE_7_0_RTM
mozilla/accessible, NETSCAPE_7_0_RTM
mozilla/directory/c-sdk, NETSCAPE_7_0_RTM
mozilla/lib/mac/Instrumentation, NETSCAPE_7_0_RTM
mozilla/gfx2, NETSCAPE_7_0_RTM
mozilla/modules/libpr0n, NETSCAPE_7_0_RTM
SeaMonkeyAll, NETSCAPE_7_0_RTM
## You need this if you want to be able to use SVG
## Note that this library is under the LGPL, not the MPL
#mozilla/other-licenses/libart_lgpl

View File

@@ -1,79 +0,0 @@
#!perl
#
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# 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):
# Simon Fraser <sfraser@netscape.com>
#
require 5.004;
use strict;
use Cwd;
use Moz::BuildUtils;
use Moz::BuildCore;
#-------------------------------------------------------------
# Where have the build options gone?
#
# The various build flags have been centralized into one place.
# The master list of options is in MozBuildFlags.txt. However,
# you should never need to edit that file, or this one.
#
# To customize what gets built, or where to start the build,
# edit the $prefs_file_name file in
# System Folder:Preferences:Mozilla build prefs:
# Documentation is provided in that file.
#-------------------------------------------------------------
my($prefs_file_name) = "Mozilla pull prefs";
#-------------------------------------------------------------
# hashes to hold build options
#-------------------------------------------------------------
my(%build);
my(%options);
my(%filepaths);
my(%optiondefines);
# Hash of input files for this build. Eventually, there will be
# input files for manifests, and projects too.
my(%inputfiles) = (
"buildflags", "MozillaBuildFlags.txt",
"checkoutdata", "MozillaCheckoutList.txt",
"buildprogress", "",
"buildmodule", "MozillaBuildList.pm",
"checkouttime", "Mozilla last checkout"
);
#-------------------------------------------------------------
# end build hashes
#-------------------------------------------------------------
# set the build root directory, which is the the dir above mozilla
SetupBuildRootDir(":mozilla:build:mac:build_scripts");
# Set up all the flags on $main::, like DEBUG, CARBON etc.
# Override the defaults using the preferences files.
SetupDefaultBuildOptions(0, ":mozilla:dist:viewer:", "");
my($do_checkout) = 1;
my($do_build) = 0;
RunBuild($do_checkout, $do_build, \%inputfiles, $prefs_file_name);

View File

@@ -1,511 +0,0 @@
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# 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):
DEPTH=.
!if !defined(MOZ_TOP)
#enable builds from changed top level directories
MOZ_TOP=mozilla
!endif
MOZ_SRC_FLIPPED = $(MOZ_SRC:\=/)
MOZ_DIST_FLIPPED = $(MOZ_SRC_FLIPPED)/mozilla/dist
!ifdef MOZ_DEBUG
MOZ_OBJDIR = WIN32_D.OBJ
!else
MOZ_OBJDIR = WIN32_O.OBJ
!endif
#
# Command macro defines
#
#//------------------------------------------------------------------------
#// Figure out how to do the pull.
#//------------------------------------------------------------------------
# uncomment these, modify branch tag, and check in to branch for milestones
MOZ_BRANCH=NETSCAPE_7_0_RTM
NSPR_CO_TAG=NETSCAPE_7_0_RTM
PSM_CO_TAG=NETSCAPE_7_0_RTM
NSS_CO_TAG=NETSCAPE_7_0_RTM
LDAPCSDK_CO_TAG=NETSCAPE_7_0_RTM
ACCESSIBLE_CO_TAG=NETSCAPE_7_0_RTM
IMGLIB2_CO_TAG=NETSCAPE_7_0_RTM
GFX2_CO_TAG=NETSCAPE_7_0_RTM
!ifdef MOZ_BRANCH
CVS_BRANCH=-r $(MOZ_BRANCH)
!endif
!ifdef MOZ_DATE
CVS_BRANCH=$(CVS_BRANCH) -D "$(MOZ_DATE)"
!endif
# default pull is "quiet" but it can be overridden with MOZ_CVS_VERBOSE
!ifndef MOZ_CVS_VERBOSE
CVS_FLAGS=-q
!endif
# honor any user-defined CVS flags
!ifdef MOZ_CVS_FLAGS
CVS_FLAGS=$(CVS_FLAGS) $(MOZ_CVS_FLAGS)
!endif
# let's be explicit about CVSROOT... some windows cvs clients
# are too stupid to correctly work without the -d option
#
# if they are too stupid, they should fail. I am
# commenting this out because this does not work
# under 4nt. (%'s are evaluted differently)
#
# If it breaks you, mail dougt@netscape.com
# and leaf@mozilla.org
#
!if 0
!if defined(CVSROOT)
CVS_FLAGS=$(CVS_FLAGS) -d "$(CVSROOT)"
!endif
!endif
!ifndef MOZ_CO_FLAGS
MOZ_CO_FLAGS = -P
!endif
CVSCO = cvs $(CVS_FLAGS) co $(MOZ_CO_FLAGS) $(CVS_BRANCH)
#//------------------------------------------------------------------------
#// Figure out how to pull NSPR.
#// If no NSPR_CO_TAG is specified, use the default static tag
#//------------------------------------------------------------------------
!ifndef NSPR_CO_FLAGS
NSPR_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
NSPR_CO_FLAGS=$(NSPR_CO_FLAGS) $(CVS_BRANCH)
CVSCO_NSPR = cvs $(CVS_FLAGS) co $(NSPR_CO_FLAGS)
#//------------------------------------------------------------------------
#// Figure out how to pull NSS and PSM libs.
#// If no NSS_CO_TAG or PSM_CO_TAG is specified, use the default static tag
#//------------------------------------------------------------------------
!ifndef NSS_CO_FLAGS
NSS_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
NSS_CO_FLAGS=$(NSS_CO_FLAGS) $(CVS_BRANCH)
CVSCO_NSS = cvs $(CVS_FLAGS) co $(NSS_CO_FLAGS)
!ifndef PSM_CO_FLAGS
PSM_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
PSM_CO_FLAGS=$(PSM_CO_FLAGS) $(CVS_BRANCH)
CVSCO_PSM = cvs $(CVS_FLAGS) co $(PSM_CO_FLAGS)
#//------------------------------------------------------------------------
#// Figure out how to pull LDAP C SDK client libs.
#// If no LDAPCSDK_CO_TAG is specified, use the default tag
#//------------------------------------------------------------------------
!ifndef LDAPCSDK_CO_FLAGS
LDAPCSDK_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
LDAPCSDK_CO_FLAGS=$(LDAPCSDK_CO_FLAGS) $(CVS_BRANCH)
CVSCO_LDAPCSDK = cvs $(CVS_FLAGS) co $(LDAPCSDK_CO_FLAGS)
#//------------------------------------------------------------------------
#// Figure out how to pull accessibility libs.
#// If no ACCESSIBLE_CO_TAG is specified, use the default tag
#//------------------------------------------------------------------------
!ifndef ACCESSIBLE_CO_FLAGS
ACCESSIBLE_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
ACCESSIBLE_CO_FLAGS=$(ACCESSIBLE_CO_FLAGS) $(CVS_BRANCH)
CVSCO_ACCESSIBLE = cvs $(CVS_FLAGS) co $(ACCESSIBLE_CO_FLAGS)
#//------------------------------------------------------------------------
#// Figure out how to pull new image library.
#// If no IMGLIB2_CO_TAG is specified, use the default tag
#//------------------------------------------------------------------------
!ifndef IMGLIB2_CO_FLAGS
IMGLIB2_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
IMGLIB2_CO_FLAGS=$(IMGLIB2_CO_FLAGS) $(CVS_BRANCH)
CVSCO_IMGLIB2 = cvs $(CVS_FLAGS) co $(IMGLIB2_CO_FLAGS)
#//------------------------------------------------------------------------
#// Figure out how to pull new image library.
#// If no GFX2_CO_TAG is specified, use the default tag
#//------------------------------------------------------------------------
!ifndef GFX2_CO_FLAGS
GFX2_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
GFX2_CO_FLAGS=$(GFX2_CO_FLAGS) $(CVS_BRANCH)
CVSCO_GFX2 = cvs $(CVS_FLAGS) co $(GFX2_CO_FLAGS)
#//------------------------------------------------------------------------
#// Figure out how to pull the internal libart
#// (only pulled and built if MOZ_INTERNAL_LIBART_LGPL is set)
#// If no MOZ_INTERNAL_LIBART_CO_TAG is specified, use the default tag
#//------------------------------------------------------------------------
!if defined(MOZ_SVG) && !defined(MOZ_INTERNAL_LIBART_LGPL)
ERR_MESSAGE = ^
You are trying to build Mozilla with SVG support (MOZ_SVG=1), but you ^
haven not specified that mozilla/other-licenses/libart_lgpl should be ^
pulled and built. At the moment Mozilla SVG builds need this patched ^
version of libart. You either need to disable SVG support (unset MOZ_SVG) ^
or enable pulling and building by setting MOZ_INTERNAL_LIBART_LGPL=1.^
^
If you choose to pull and build libart, note that it is only licensed^
under the terms of the LGPL, not the MPL. (Which is why you have to opt^
in explicitly.)
!endif
!if defined(MOZ_INTERNAL_LIBART_LGPL)
!ifndef MOZ_INTERNAL_LIBART_CO_FLAGS
MOZ_INTERNAL_LIBART_CO_FLAGS=$(MOZ_CO_FLAGS)
!endif
!if "$(MOZ_INTERNAL_LIBART_CO_TAG)" != ""
MOZ_INTERNAL_LIBART_CO_FLAGS=$(MOZ_INTERNAL_LIBART_CO_FLAGS) -r $(MOZ_INTERNAL_LIBART_CO_TAG)
!else
MOZ_INTERNAL_LIBART_CO_FLAGS=$(MOZ_INTERNAL_LIBART_CO_FLAGS) $(CVS_BRANCH)
!endif
CVSCO_MOZ_INTERNAL_LIBART = cvs $(CVS_FLAGS) co $(MOZ_INTERNAL_LIBART_CO_FLAGS)
!endif
## The master target
############################################################
pull_and_build_all: pull_all build_all_dep
## Rules for pulling the source from the cvs repository
############################################################
pull_clobber_and_build_all: pull_all clobber_all build_all
!if !defined(MOZ_INTERNAL_LIBART_LGPL)
pull_all: pull_nspr pull_psm pull_ldapcsdk pull_accessible pull_gfx2 pull_imglib2 pull_seamonkey
!else
pull_all: pull_nspr pull_psm pull_ldapcsdk pull_accessible pull_gfx2 pull_imglib2 pull_moz_internal_libart pull_seamonkey
!endif
pull_nspr: pull_clientmak
cd $(MOZ_SRC)\.
$(CVSCO_NSPR) mozilla/nsprpub
pull_nss:
cd $(MOZ_SRC)\.
$(CVSCO_NSS) mozilla/security/coreconf
$(CVSCO_NSS) mozilla/security/nss
pull_psm: pull_nss
cd $(MOZ_SRC)\.
$(CVSCO_PSM) mozilla/security/manager
$(CVSCO_PSM) mozilla/security/makefile.win
pull_ldapcsdk:
cd $(MOZ_SRC)\.
$(CVSCO_LDAPCSDK) mozilla/directory/c-sdk
pull_accessible:
cd $(MOZ_SRC)\.
$(CVSCO_ACCESSIBLE) mozilla/accessible
pull_gfx2:
cd $(MOZ_SRC)\.
$(CVSCO_GFX2) mozilla/gfx2
pull_imglib2:
cd $(MOZ_SRC)\.
$(CVSCO_IMGLIB2) mozilla/modules/libpr0n
!if defined(MOZ_INTERNAL_LIBART_LGPL)
pull_moz_internal_libart:
cd $(MOZ_SRC)\.
$(CVSCO_MOZ_INTERNAL_LIBART) mozilla/other-licenses/libart_lgpl
!endif
pull_xpconnect: pull_nspr
cd $(MOZ_SRC)\.
$(CVSCO) mozilla/include
$(CVSCO) mozilla/config
$(CVSCO) -l mozilla/js
$(CVSCO) -l mozilla/js/src
$(CVSCO) mozilla/js/src/fdlibm
$(CVSCO) mozilla/js/src/xpconnect
$(CVSCO) mozilla/modules/libreg
$(CVSCO) mozilla/xpcom
$(CVSCO) mozilla/string
# pull either layout only or seamonkey the browser
pull_layout:
cd $(MOZ_SRC)\.
$(CVSCO) RaptorWin
pull_seamonkey: pull_clientmak
cd $(MOZ_SRC)\.
$(CVSCO) SeaMonkeyAll
pull_clientmak:
cd $(MOZ_SRC)\.
$(CVSCO) mozilla/client.mak
############################################################
# nmake has to be hardcoded, or we have to depend on mozilla/config
# being pulled already to figure out what $(NMAKE) should be.
clobber_all: clobber_nspr clobber_ldapcsdk clobber_psm clobber_seamonkey
build_all: build_nspr build_ldapcsdk build_seamonkey
build_all_dep: depend libs
distclean:
@cd $(MOZ_SRC)\$(MOZ_TOP)\directory\c-sdk
gmake -f gmakefile.win distclean MOZ_SRC_FLIPPED=$(MOZ_SRC_FLIPPED)
@cd $(MOZ_SRC)\$(MOZ_TOP)\nsprpub
gmake -f gmakefile.win distclean MOZ_SRC_FLIPPED=$(MOZ_SRC_FLIPPED)
@cd $(MOZ_SRC)\$(MOZ_TOP)
nmake /f client.mak clobber_psm
nmake /f client.mak clobber_seamonkey
clobber_ldapcsdk:
@cd $(MOZ_SRC)\$(MOZ_TOP)\directory\c-sdk
gmake -f gmakefile.win clobber_all MOZ_SRC_FLIPPED=$(MOZ_SRC_FLIPPED) \
SHELL=sh
clobber_nspr:
@cd $(MOZ_SRC)\$(MOZ_TOP)\nsprpub
gmake -f gmakefile.win clobber_all MOZ_SRC_FLIPPED=$(MOZ_SRC_FLIPPED)
clobber_psm:
@cd $(MOZ_SRC)\$(MOZ_TOP)\security
nmake -f makefile.win clobber_all
clobber_xpconnect:
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
-rd /s /q dist
@cd $(MOZ_SRC)\$(MOZ_TOP)\nsprpub
gmake -f gmakefile.win clobber_all MOZ_SRC_FLIPPED=$(MOZ_SRC_FLIPPED)
@cd $(MOZ_SRC)\$(MOZ_TOP)\include
nmake -f makefile.win clobber_all
@cd $(MOZ_SRC)\$(MOZ_TOP)\modules\libreg
nmake -f makefile.win clobber_all
@cd $(MOZ_SRC)\$(MOZ_TOP)\string
nmake -f makefile.win clobber_all
@cd $(MOZ_SRC)\$(MOZ_TOP)\xpcom
nmake -f makefile.win clobber_all
@cd $(MOZ_SRC)\$(MOZ_TOP)\js
nmake -f makefile.win clobber_all
@cd $(MOZ_SRC)\$(MOZ_TOP)\js\src\xpconnect
nmake -f makefile.win clobber_all
clobber_seamonkey:
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
-rd /s /q dist
nmake -f makefile.win clobber_all
depend: export
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
nmake -f makefile.win depend
depend_xpconnect:
@cd $(MOZ_SRC)\$(MOZ_TOP)\include
nmake -f makefile.win depend
@cd $(MOZ_SRC)\$(MOZ_TOP)\modules\libreg
nmake -f makefile.win depend
@cd $(MOZ_SRC)\$(MOZ_TOP)\string
nmake -f makefile.win depend
@cd $(MOZ_SRC)\$(MOZ_TOP)\xpcom
nmake -f makefile.win depend
@cd $(MOZ_SRC)\$(MOZ_TOP)\js\src
nmake -f makefile.win depend
@cd $(MOZ_SRC)\$(MOZ_TOP)\js\src\xpconnect
nmake -f makefile.win depend
build_nspr:
@cd $(MOZ_SRC)\$(MOZ_TOP)\nsprpub
gmake -f gmakefile.win MOZ_SRC_FLIPPED=$(MOZ_SRC_FLIPPED)
build_ldapcsdk:
@cd $(MOZ_SRC)\$(MOZ_TOP)\directory\c-sdk
gmake -f gmakefile.win MOZ_SRC_FLIPPED=$(MOZ_SRC_FLIPPED) SHELL=sh
build_psm:
@cd $(MOZ_SRC)\$(MOZ_TOP)\security
nmake -f makefile.win
build_xpconnect: build_nspr
@cd $(MOZ_SRC)\$(MOZ_TOP)\include
nmake -f makefile.win all
@cd $(MOZ_SRC)\$(MOZ_TOP)\modules\libreg
nmake -f makefile.win all
@cd $(MOZ_SRC)\$(MOZ_TOP)\xpcom
nmake -f makefile.win export
@cd $(MOZ_SRC)\$(MOZ_TOP)\string
nmake -f makefile.win all
@cd $(MOZ_SRC)\$(MOZ_TOP)\xpcom
nmake -f makefile.win libs
@cd $(MOZ_SRC)\$(MOZ_TOP)\js\src
nmake -f makefile.win all
@cd $(MOZ_SRC)\$(MOZ_TOP)\js\src\xpconnect
nmake -f makefile.win all
build_seamonkey:
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
nmake -f makefile.win all
build_client:
@cd $(MOZ_SRC)\mozilla\.
nmake -f makefile.win all
build_layout:
@cd $(MOZ_SRC)\mozilla\.
nmake -f makefile.win all
build_dist:
@cd $(MOZ_SRC)\mozilla\.
nmake -f makefile.win all
libs:
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
nmake -f makefile.win libs
export: build_nspr build_ldapcsdk
@cd $(MOZ_SRC)\$(MOZ_TOP)\.
nmake -f makefile.win export
clobber_dist:
@cd $(MOZ_SRC)\mozilla\.
nmake -f makefile.win clobber_all
clobber_client:
@cd $(MOZ_SRC)\mozilla\.
nmake -f makefile.win clobber_all
clobber_layout:
@cd $(MOZ_SRC)\mozilla\.
nmake -f makefile.win clobber_all
browse_info::
cd $(MOZ_SRC)\$(MOZ_TOP)
-dir /s /b *.sbr > sbrlist.tmp
-bscmake /Es /o mozilla.bsc @sbrlist.tmp
-rm sbrlist.tmp
regchrome::
@cd $(MOZ_SRC)\mozilla\.
nmake /f makefile.win regchrome
deliver::
@cd $(MOZ_SRC)\mozilla\.
nmake /f makefile.win splitsymbols
#//------------------------------------------------------------------------
#// Utility stuff...
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
# Verify that MOZ_SRC is set correctly
#//------------------------------------------------------------------------
# Check to see if it is set at all
!if "$(MOZ_SRC)"==""
MOZ_SRC = $(MAKEDIR)\..
!endif
#
# create a temp file at the root and make sure it is visible from MOZ_SRC
#
!if [copy $(MAKEDIR)\client.mak $(MAKEDIR)\xyzzy.tmp > NUL] == 0
!endif
!if !EXIST( $(MOZ_SRC)\mozilla\xyzzy.tmp )
ERR_MESSAGE=$(ERR_MESSAGE)^
MOZ_SRC isn't set correctly: [$(MOZ_SRC)\mozilla]!=[$(MAKEDIR)]
!endif
!if [del $(MAKEDIR)\xyzzy.tmp]
!endif
#//------------------------------------------------------------------------
# Verify that MOZ_BITS is set
#//------------------------------------------------------------------------
!if !defined(MOZ_BITS)
ERR_MESSAGE=$(ERR_MESSAGE)^
Environment variable MOZ_BITS isn't set.
!endif
!if !defined(MOZ_TOOLS)
ERR_MESSAGE=$(ERR_MESSAGE)^
Environment variable MOZ_TOOLS isn't set.
!endif
#//------------------------------------------------------------------------
#// Display error
#//------------------------------------------------------------------------
!if "$(ERR_MESSAGE)" != ""
ERR_MESSAGE = ^
client.mak: ^
$(ERR_MESSAGE) ^
^
client.mak: usage^
^
nmake -f client.mak [MOZ_BRANCH=<cvs_branch_name>] ^
[MOZ_DATE=<cvs_date>]^
[pull_and_build_all]^
[pull_all]^
[build_all]^
^
Environment variables:^
^
MOZ_BITS set to 32^
MOZ_TOOLS set to the directory containing the needed tools ^
!ERROR $(ERR_MESSAGE)
!endif

View File

@@ -1,650 +0,0 @@
# The contents of this file are subject to the Netscape Public
# License Version 1.1 (the "License"); you may not use this file
# except in compliance with the License. You may obtain a copy of
# the License at http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
# implied. See the License for the specific language governing
# rights and limitations under the License.
#
# The Original Code is mozilla.org code.
#
# 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): Stephen Lamm
# Build the Mozilla client.
#
# This needs CVSROOT set to work, e.g.,
# setenv CVSROOT :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
# or
# setenv CVSROOT :pserver:username%somedomain.org@cvs.mozilla.org:/cvsroot
#
# To checkout and build a tree,
# 1. cvs co mozilla/client.mk
# 2. cd mozilla
# 3. gmake -f client.mk
#
# Other targets (gmake -f client.mk [targets...]),
# checkout
# build
# clean (realclean is now the same as clean)
# distclean
#
# See http://www.mozilla.org/build/unix.html for more information.
#
# Options:
# MOZ_OBJDIR - Destination object directory
# MOZ_CO_DATE - Date tag to use for checkout (default: none)
# MOZ_CO_MODULE - Module to checkout (default: SeaMonkeyAll)
# MOZ_CVS_FLAGS - Flags to pass cvs (default: -q -z3)
# MOZ_CO_FLAGS - Flags to pass after 'cvs co' (default: -P)
# MOZ_MAKE_FLAGS - Flags to pass to $(MAKE)
# MOZ_CO_BRANCH - Branch tag (Deprecated. Use MOZ_CO_TAG below.)
#
#######################################################################
# Checkout Tags
#
# For branches, uncomment the MOZ_CO_TAG line with the proper tag,
# and commit this file on that tag.
MOZ_CO_TAG = NETSCAPE_7_0_RTM
NSPR_CO_TAG = NETSCAPE_7_0_RTM
PSM_CO_TAG = NETSCAPE_7_0_RTM
NSS_CO_TAG = NETSCAPE_7_0_RTM
LDAPCSDK_CO_TAG = NETSCAPE_7_0_RTM
ACCESSIBLE_CO_TAG = NETSCAPE_7_0_RTM
GFX2_CO_TAG = NETSCAPE_7_0_RTM
IMGLIB2_CO_TAG = NETSCAPE_7_0_RTM
BUILD_MODULES = all
#######################################################################
# Defines
#
CVS = cvs
CWD := $(shell pwd)
ifeq "$(CWD)" "/"
CWD := /.
endif
ifneq (, $(wildcard client.mk))
# Ran from mozilla directory
ROOTDIR := $(shell dirname $(CWD))
TOPSRCDIR := $(CWD)
else
# Ran from mozilla/.. directory (?)
ROOTDIR := $(CWD)
TOPSRCDIR := $(CWD)/mozilla
endif
# on os2, TOPSRCDIR may have two forward slashes in a row, which doesn't
# work; replace first instance with one forward slash
TOPSRCDIR := $(shell echo "$(TOPSRCDIR)" | sed -e 's%//%/%')
ifndef TOPSRCDIR_MOZ
TOPSRCDIR_MOZ=$(TOPSRCDIR)
endif
# if ROOTDIR equals only drive letter (i.e. "C:"), set to "/"
DIRNAME := $(shell echo "$(ROOTDIR)" | sed -e 's/^.://')
ifeq ($(DIRNAME),)
ROOTDIR := /.
endif
AUTOCONF := autoconf
MKDIR := mkdir
SH := /bin/sh
ifndef MAKE
MAKE := gmake
endif
CONFIG_GUESS_SCRIPT := $(wildcard $(TOPSRCDIR)/build/autoconf/config.guess)
ifdef CONFIG_GUESS_SCRIPT
CONFIG_GUESS = $(shell $(CONFIG_GUESS_SCRIPT))
else
_IS_FIRST_CHECKOUT := 1
endif
####################################
# CVS
# Add the CVS root to CVS_FLAGS if needed
CVS_ROOT_IN_TREE := $(shell cat $(TOPSRCDIR)/CVS/Root 2>/dev/null)
ifneq ($(CVS_ROOT_IN_TREE),)
ifneq ($(CVS_ROOT_IN_TREE),$(CVSROOT))
CVS_FLAGS := -d $(CVS_ROOT_IN_TREE)
endif
endif
CVSCO = $(strip $(CVS) $(CVS_FLAGS) co $(CVS_CO_FLAGS))
CVSCO_LOGFILE := $(ROOTDIR)/cvsco.log
CVSCO_LOGFILE := $(shell echo $(CVSCO_LOGFILE) | sed s%//%/%)
ifdef MOZ_CO_TAG
CVS_CO_FLAGS := -r $(MOZ_CO_TAG)
endif
####################################
# Load mozconfig Options
# See build pages, http://www.mozilla.org/build/unix.html,
# for how to set up mozconfig.
MOZCONFIG_LOADER := mozilla/build/autoconf/mozconfig2client-mk
MOZCONFIG_FINDER := mozilla/build/autoconf/mozconfig-find
MOZCONFIG_MODULES := mozilla/build/unix/modules.mk
run_for_side_effects := \
$(shell cd $(ROOTDIR); \
if test "$(_IS_FIRST_CHECKOUT)"; then \
$(CVSCO) $(MOZCONFIG_FINDER) $(MOZCONFIG_LOADER) $(MOZCONFIG_MODULES); \
else true; \
fi; \
$(MOZCONFIG_LOADER) $(TOPSRCDIR) mozilla/.mozconfig.mk > mozilla/.mozconfig.out)
include $(TOPSRCDIR)/.mozconfig.mk
include $(TOPSRCDIR)/build/unix/modules.mk
####################################
# Options that may come from mozconfig
# Change CVS flags if anonymous root is requested
ifdef MOZ_CO_USE_MIRROR
CVS_FLAGS := -d :pserver:anonymous@cvs-mirror.mozilla.org:/cvsroot
endif
# MOZ_CVS_FLAGS - Basic CVS flags
ifeq "$(origin MOZ_CVS_FLAGS)" "undefined"
CVS_FLAGS := $(CVS_FLAGS) -q -z 3
else
CVS_FLAGS := $(MOZ_CVS_FLAGS)
endif
# This option is deprecated. The best way to have client.mk pull a tag
# is to set MOZ_CO_TAG (see above) and commit that change on the tag.
ifdef MOZ_CO_BRANCH
$(warning Use MOZ_CO_TAG instead of MOZ_CO_BRANCH)
CVS_CO_FLAGS := -r $(MOZ_CO_BRANCH)
endif
# MOZ_CO_FLAGS - Anything that we should use on all checkouts
ifeq "$(origin MOZ_CO_FLAGS)" "undefined"
CVS_CO_FLAGS := $(CVS_CO_FLAGS) -P
else
CVS_CO_FLAGS := $(CVS_CO_FLAGS) $(MOZ_CO_FLAGS)
endif
ifdef MOZ_CO_DATE
CVS_CO_DATE_FLAGS := -D "$(MOZ_CO_DATE)"
endif
ifdef MOZ_OBJDIR
OBJDIR := $(MOZ_OBJDIR)
MOZ_MAKE := $(MAKE) $(MOZ_MAKE_FLAGS) -C $(OBJDIR)
else
OBJDIR := $(TOPSRCDIR)
MOZ_MAKE := $(MAKE) $(MOZ_MAKE_FLAGS)
endif
####################################
# CVS defines for PSM
#
PSM_CO_MODULE= mozilla/security/manager
PSM_CO_FLAGS := -P -A
ifdef MOZ_CO_FLAGS
PSM_CO_FLAGS := $(MOZ_CO_FLAGS)
endif
ifdef PSM_CO_TAG
PSM_CO_FLAGS := $(PSM_CO_FLAGS) -r $(PSM_CO_TAG)
endif
CVSCO_PSM = $(CVS) $(CVS_FLAGS) co $(PSM_CO_FLAGS) $(CVS_CO_DATE_FLAGS) $(PSM_CO_MODULE)
####################################
# CVS defines for NSS
#
NSS_CO_MODULE = mozilla/security/nss \
mozilla/security/coreconf \
$(NULL)
NSS_CO_FLAGS := -P
ifdef MOZ_CO_FLAGS
NSS_CO_FLAGS := $(MOZ_CO_FLAGS)
endif
ifdef NSS_CO_TAG
NSS_CO_FLAGS := $(NSS_CO_FLAGS) -r $(NSS_CO_TAG)
endif
# Cannot pull static tags by date
ifeq ($(NSS_CO_TAG),NSS_CLIENT_TAG)
CVSCO_NSS = $(CVS) $(CVS_FLAGS) co $(NSS_CO_FLAGS) $(NSS_CO_MODULE)
else
CVSCO_NSS = $(CVS) $(CVS_FLAGS) co $(NSS_CO_FLAGS) $(CVS_CO_DATE_FLAGS) $(NSS_CO_MODULE)
endif
####################################
# CVS defines for NSPR
#
NSPR_CO_MODULE = mozilla/nsprpub
NSPR_CO_FLAGS := -P
ifdef MOZ_CO_FLAGS
NSPR_CO_FLAGS := $(MOZ_CO_FLAGS)
endif
ifdef NSPR_CO_TAG
NSPR_CO_FLAGS := $(NSPR_CO_FLAGS) -r $(NSPR_CO_TAG)
endif
# Cannot pull static tags by date
ifeq ($(NSPR_CO_TAG),NSPRPUB_CLIENT_TAG)
CVSCO_NSPR = $(CVS) $(CVS_FLAGS) co $(NSPR_CO_FLAGS) $(NSPR_CO_MODULE)
else
CVSCO_NSPR = $(CVS) $(CVS_FLAGS) co $(NSPR_CO_FLAGS) $(CVS_CO_DATE_FLAGS) $(NSPR_CO_MODULE)
endif
####################################
# CVS defines for the C LDAP SDK
#
LDAPCSDK_CO_MODULE = mozilla/directory/c-sdk
LDAPCSDK_CO_FLAGS := -P
ifdef MOZ_CO_FLAGS
LDAPCSDK_CO_FLAGS := $(MOZ_CO_FLAGS)
endif
ifdef LDAPCSDK_CO_TAG
LDAPCSDK_CO_FLAGS := $(LDAPCSDK_CO_FLAGS) -r $(LDAPCSDK_CO_TAG)
endif
CVSCO_LDAPCSDK = $(CVS) $(CVS_FLAGS) co $(LDAPCSDK_CO_FLAGS) $(CVS_CO_DATE_FLAGS) $(LDAPCSDK_CO_MODULE)
####################################
# CVS defines for the C LDAP SDK
#
ACCESSIBLE_CO_MODULE = mozilla/accessible
ACCESSIBLE_CO_FLAGS := -P
ifdef MOZ_CO_FLAGS
ACCESSIBLE_CO_FLAGS := $(MOZ_CO_FLAGS)
endif
ifdef ACCESSIBLE_CO_TAG
ACCESSIBLE_CO_FLAGS := $(ACCESSIBLE_CO_FLAGS) -r $(ACCESSIBLE_CO_TAG)
endif
CVSCO_ACCESSIBLE = $(CVS) $(CVS_FLAGS) co $(ACCESSIBLE_CO_FLAGS) $(CVS_CO_DATE_FLAGS) $(ACCESSIBLE_CO_MODULE)
####################################
# CVS defines for gfx2
#
GFX2_CO_MODULE = mozilla/gfx2
GFX2_CO_FLAGS := -P
ifdef MOZ_CO_FLAGS
GFX2_CO_FLAGS := $(MOZ_CO_FLAGS)
endif
ifdef GFX2_CO_TAG
GFX2_CO_FLAGS := $(GFX2_CO_FLAGS) -r $(GFX2_CO_TAG)
endif
CVSCO_GFX2 = $(CVS) $(CVS_FLAGS) co $(GFX2_CO_FLAGS) $(CVS_CO_DATE_FLAGS) $(GFX2_CO_MODULE)
####################################
# CVS defines for new image library
#
IMGLIB2_CO_MODULE = mozilla/modules/libpr0n
IMGLIB2_CO_FLAGS := -P
ifdef MOZ_CO_FLAGS
IMGLIB2_CO_FLAGS := $(MOZ_CO_FLAGS)
endif
ifdef IMGLIB2_CO_TAG
IMGLIB2_CO_FLAGS := $(IMGLIB2_CO_FLAGS) -r $(IMGLIB2_CO_TAG)
endif
CVSCO_IMGLIB2 = $(CVS) $(CVS_FLAGS) co $(IMGLIB2_CO_FLAGS) $(CVS_CO_DATE_FLAGS) $(IMGLIB2_CO_MODULE)
####################################
# CVS defines for standalone modules
#
ifneq ($(BUILD_MODULES),all)
MOZ_CO_MODULE := $(filter-out $(NSPRPUB_DIR) security directory/c-sdk, $(BUILD_MODULE_CVS))
MOZ_CO_MODULE += allmakefiles.sh client.mk aclocal.m4 configure configure.in
MOZ_CO_MODULE += Makefile.in
MOZ_CO_MODULE := $(addprefix mozilla/, $(MOZ_CO_MODULE))
NOSUBDIRS_MODULE := $(addprefix mozilla/, $(BUILD_MODULE_CVS_NS))
ifneq ($(NOSUBDIRS_MODULE),)
CVSCO_NOSUBDIRS := $(CVSCO) -l $(CVS_CO_DATE_FLAGS) $(NOSUBDIRS_MODULE)
endif
ifeq (,$(filter $(NSPRPUB_DIR), $(BUILD_MODULE_CVS)))
CVSCO_NSPR :=
endif
ifeq (,$(filter security security/manager, $(BUILD_MODULE_CVS)))
CVSCO_PSM :=
CVSCO_NSS :=
endif
ifeq (,$(filter directory/c-sdk, $(BUILD_MODULE_CVS)))
CVSCO_LDAPCSDK :=
endif
ifeq (,$(filter accessible, $(BUILD_MODULE_CVS)))
CVSCO_ACCESSIBLE :=
endif
ifeq (,$(filter gfx2, $(BUILD_MODULE_CVS)))
CVSCO_GFX2 :=
endif
ifeq (,$(filter modules/libpr0n, $(BUILD_MODULE_CVS)))
CVSCO_IMGLIB2 :=
endif
endif
####################################
# CVS defines for SeaMonkey
#
ifeq ($(MOZ_CO_MODULE),)
MOZ_CO_MODULE := SeaMonkeyAll
endif
CVSCO_SEAMONKEY := $(CVSCO) $(CVS_CO_DATE_FLAGS) $(MOZ_CO_MODULE)
####################################
# CVS defined for libart (pulled and built if MOZ_INTERNAL_LIBART_LGPL is set)
#
CVSCO_LIBART := $(CVSCO) $(CVS_CO_DATE_FLAGS) mozilla/other-licenses/libart_lgpl
ifdef MOZ_INTERNAL_LIBART_LGPL
FASTUPDATE_LIBART := fast_update $(CVSCO_LIBART)
CHECKOUT_LIBART := cvs_co $(CVSCO_LIBART)
else
CHECKOUT_LIBART := true
FASTUPDATE_LIBART := true
endif
####################################
# CVS defines for Calendar (pulled and built if MOZ_CALENDAR is set)
#
CVSCO_CALENDAR := $(CVSCO) $(CVS_CO_DATE_FLAGS) mozilla/calendar
ifdef MOZ_CALENDAR
FASTUPDATE_CALENDAR := fast_update $(CVSCO_CALENDAR)
CHECKOUT_CALENDAR := cvs_co $(CVSCO_CALENDAR)
else
CHECKOUT_CALENDAR := true
FASTUPDATE_CALENDAR := true
endif
# because some cygwin tools can't handle native dos-drive paths & vice-versa
# force configure to use a relative path for --srcdir
# need a better check for win32
# and we need to get OBJDIR earlier
ifdef MOZ_TOOLS
_tmpobjdir := $(shell cygpath -u $(OBJDIR))
_abs2rel := $(shell cygpath -w $(TOPSRCDIR)/build/unix/abs2rel.pl | sed -e 's|\\|/|g')
_OBJ2SRCPATH := $(shell $(_abs2rel) $(TOPSRCDIR) $(_tmpobjdir))
endif
#######################################################################
# Rules
#
# Print out any options loaded from mozconfig.
all build checkout clean depend distclean export libs install realclean::
@if test -f .mozconfig.out; then \
cat .mozconfig.out; \
rm -f .mozconfig.out; \
else true; \
fi
ifdef _IS_FIRST_CHECKOUT
all:: checkout build
else
all:: checkout alldep
endif
# Windows equivalents
pull_all: checkout
build_all: build
build_all_dep: alldep
build_all_depend: alldep
clobber clobber_all: clean
pull_and_build_all: checkout alldep
# Do everything from scratch
everything: checkout clean build
####################################
# CVS checkout
#
checkout::
# @: Backup the last checkout log.
@if test -f $(CVSCO_LOGFILE) ; then \
mv $(CVSCO_LOGFILE) $(CVSCO_LOGFILE).old; \
else true; \
fi
ifdef RUN_AUTOCONF_LOCALLY
@echo "Removing local configures" ; \
cd $(ROOTDIR) && \
$(RM) -f mozilla/configure mozilla/nsprpub/configure \
mozilla/directory/c-sdk/configure
endif
@echo "checkout start: "`date` | tee $(CVSCO_LOGFILE)
@echo '$(CVSCO) mozilla/client.mk mozilla/build/unix/modules.mk'; \
cd $(ROOTDIR) && \
$(CVSCO) mozilla/client.mk mozilla/build/unix/modules.mk
@cd $(ROOTDIR) && $(MAKE) -f mozilla/client.mk real_checkout
real_checkout:
# @: Start the checkout. Split the output to the tty and a log file. \
# : If it fails, touch an error file because "tee" hides the error.
@failed=.cvs-failed.tmp; rm -f $$failed*; \
cvs_co() { echo "$$@" ; \
("$$@" || touch $$failed) 2>&1 | tee -a $(CVSCO_LOGFILE) && \
if test -f $$failed; then false; else true; fi; }; \
cvs_co $(CVSCO_NSPR) && \
cvs_co $(CVSCO_NSS) && \
cvs_co $(CVSCO_PSM) && \
cvs_co $(CVSCO_LDAPCSDK) && \
cvs_co $(CVSCO_ACCESSIBLE) && \
cvs_co $(CVSCO_GFX2) && \
cvs_co $(CVSCO_IMGLIB2) && \
$(CHECKOUT_CALENDAR) && \
$(CHECKOUT_LIBART) && \
cvs_co $(CVSCO_SEAMONKEY) && \
cvs_co $(CVSCO_NOSUBDIRS)
@echo "checkout finish: "`date` | tee -a $(CVSCO_LOGFILE)
# @: Check the log for conflicts. ;
@conflicts=`egrep "^C " $(CVSCO_LOGFILE)` ;\
if test "$$conflicts" ; then \
echo "$(MAKE): *** Conflicts during checkout." ;\
echo "$$conflicts" ;\
echo "$(MAKE): Refer to $(CVSCO_LOGFILE) for full log." ;\
false; \
else true; \
fi
ifdef RUN_AUTOCONF_LOCALLY
@echo Generating configures using $(AUTOCONF) ; \
cd $(TOPSRCDIR) && $(AUTOCONF) && \
cd $(TOPSRCDIR)/nsprpub && $(AUTOCONF) && \
cd $(TOPSRCDIR)/directory/c-sdk && $(AUTOCONF)
endif
fast-update:
# @: Backup the last checkout log.
@if test -f $(CVSCO_LOGFILE) ; then \
mv $(CVSCO_LOGFILE) $(CVSCO_LOGFILE).old; \
else true; \
fi
ifdef RUN_AUTOCONF_LOCALLY
@echo "Removing local configures" ; \
cd $(ROOTDIR) && \
$(RM) -f mozilla/configure mozilla/nsprpub/configure \
mozilla/directory/c-sdk/configure
endif
@echo "checkout start: "`date` | tee $(CVSCO_LOGFILE)
@echo '$(CVSCO) mozilla/client.mk mozilla/build/unix/modules.mk'; \
cd $(ROOTDIR) && \
$(CVSCO) mozilla/client.mk mozilla/build/unix/modules.mk
@cd $(TOPSRCDIR) && \
$(MAKE) -f client.mk real_fast-update
real_fast-update:
# @: Start the update. Split the output to the tty and a log file. \
# : If it fails, touch an error file because "tee" hides the error.
@failed=.fast_update-failed.tmp; rm -f $$failed*; \
fast_update() { (config/cvsco-fast-update.pl $$@ || touch $$failed) 2>&1 | tee -a $(CVSCO_LOGFILE) && \
if test -f $$failed; then false; else true; fi; }; \
cvs_co() { echo "$$@" ; \
("$$@" || touch $$failed) 2>&1 | tee -a $(CVSCO_LOGFILE) && \
if test -f $$failed; then false; else true; fi; }; \
fast_update $(CVSCO_NSPR) && \
cd $(ROOTDIR) && \
failed=mozilla/.fast_update-failed.tmp && \
cvs_co $(CVSCO_NSS) && \
failed=.fast_update-failed.tmp && \
cd mozilla && \
fast_update $(CVSCO_PSM) && \
fast_update $(CVSCO_LDAPCSDK) && \
fast_update $(CVSCO_ACCESSIBLE) && \
fast_update $(CVSCO_GFX2) && \
fast_update $(CVSCO_IMGLIB2) && \
$(FASTUPDATE_CALENDAR) && \
$(FASTUPDATE_LIBART) && \
fast_update $(CVSCO_SEAMONKEY) && \
fast_update $(CVSCO_NOSUBDIRS)
@echo "fast_update finish: "`date` | tee -a $(CVSCO_LOGFILE)
# @: Check the log for conflicts. ;
@conflicts=`egrep "^C " $(CVSCO_LOGFILE)` ;\
if test "$$conflicts" ; then \
echo "$(MAKE): *** Conflicts during fast-update." ;\
echo "$$conflicts" ;\
echo "$(MAKE): Refer to $(CVSCO_LOGFILE) for full log." ;\
false; \
else true; \
fi
ifdef RUN_AUTOCONF_LOCALLY
@echo Generating configures using $(AUTOCONF) ; \
cd $(TOPSRCDIR) && $(AUTOCONF) && \
cd $(TOPSRCDIR)/nsprpub && $(AUTOCONF) && \
cd $(TOPSRCDIR)/directory/c-sdk && $(AUTOCONF)
endif
####################################
# Web configure
WEBCONFIG_FILE := $(HOME)/.mozconfig
MOZCONFIG2CONFIGURATOR := build/autoconf/mozconfig2configurator
webconfig:
@cd $(TOPSRCDIR); \
url=`$(MOZCONFIG2CONFIGURATOR) $(TOPSRCDIR)`; \
echo Running mozilla with the following url: ;\
echo ;\
echo $$url ;\
mozilla -remote "openURL($$url)" || \
netscape -remote "openURL($$url)" || \
mozilla $$url || \
netscape $$url ;\
echo ;\
echo 1. Fill out the form on the browser. ;\
echo 2. Save the results to $(WEBCONFIG_FILE)
#####################################################
# First Checkout
ifdef _IS_FIRST_CHECKOUT
# First time, do build target in a new process to pick up new files.
build::
$(MAKE) -f $(TOPSRCDIR)/client.mk build
else
#####################################################
# After First Checkout
####################################
# Configure
CONFIG_STATUS := $(wildcard $(OBJDIR)/config.status)
CONFIG_CACHE := $(wildcard $(OBJDIR)/config.cache)
ifdef RUN_AUTOCONF_LOCALLY
EXTRA_CONFIG_DEPS := \
$(TOPSRCDIR)/aclocal.m4 \
$(wildcard $(TOPSRCDIR)/build/autoconf/*.m4) \
$(NULL)
$(TOPSRCDIR)/configure: $(TOPSRCDIR)/configure.in $(EXTRA_CONFIG_DEPS)
@echo Generating $@ using autoconf
cd $(TOPSRCDIR); $(AUTOCONF)
endif
CONFIG_STATUS_DEPS_L10N := $(wildcard $(TOPSRCDIR)/l10n/makefiles.all)
CONFIG_STATUS_DEPS := \
$(TOPSRCDIR)/configure \
$(TOPSRCDIR)/allmakefiles.sh \
$(TOPSRCDIR)/.mozconfig.mk \
$(wildcard $(TOPSRCDIR)/nsprpub/configure) \
$(wildcard $(TOPSRCDIR)/directory/c-sdk/configure) \
$(wildcard $(TOPSRCDIR)/mailnews/makefiles) \
$(CONFIG_STATUS_DEPS_L10N) \
$(wildcard $(TOPSRCDIR)/themes/makefiles) \
$(NULL)
# configure uses the program name to determine @srcdir@. Calling it without
# $(TOPSRCDIR) will set @srcdir@ to "."; otherwise, it is set to the full
# path of $(TOPSRCDIR).
ifeq ($(TOPSRCDIR),$(OBJDIR))
CONFIGURE := ./configure
else
CONFIGURE := $(TOPSRCDIR)/configure
endif
ifdef _OBJ2SRCPATH
CONFIGURE_ARGS := --srcdir=$(_OBJ2SRCPATH) $(CONFIGURE_ARGS)
endif
$(OBJDIR)/Makefile $(OBJDIR)/config.status: $(CONFIG_STATUS_DEPS)
@if test ! -d $(OBJDIR); then $(MKDIR) $(OBJDIR); else true; fi
@echo cd $(OBJDIR);
@echo $(CONFIGURE) $(CONFIGURE_ARGS)
@cd $(OBJDIR) && $(CONFIGURE_ENV_ARGS) $(CONFIGURE) $(CONFIGURE_ARGS) \
|| ( echo "*** Fix above errors and then restart with\
\"$(MAKE) -f client.mk build\"" && exit 1 )
@touch $(OBJDIR)/Makefile
ifdef CONFIG_STATUS
$(OBJDIR)/config/autoconf.mk: $(TOPSRCDIR)/config/autoconf.mk.in
cd $(OBJDIR); \
CONFIG_FILES=config/autoconf.mk ./config.status
endif
####################################
# Depend
depend:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
$(MOZ_MAKE) export && $(MOZ_MAKE) depend
####################################
# Build it
build:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
$(MOZ_MAKE)
####################################
# Other targets
# Pass these target onto the real build system
install export libs clean realclean distclean alldep:: $(OBJDIR)/Makefile $(OBJDIR)/config.status
$(MOZ_MAKE) $@
cleansrcdir:
@cd $(TOPSRCDIR); \
if [ -f webshell/embed/gtk/Makefile ]; then \
$(MAKE) -C webshell/embed/gtk distclean; \
fi; \
if [ -f Makefile ]; then \
$(MAKE) distclean ; \
else \
echo "Removing object files from srcdir..."; \
rm -fr `find . -type d \( -name .deps -print -o -name CVS \
-o -exec test ! -d {}/CVS \; \) -prune \
-o \( -name '*.[ao]' -o -name '*.so' \) -type f -print`; \
build/autoconf/clean-config.sh; \
fi;
# (! IS_FIRST_CHECKOUT)
endif
.PHONY: checkout real_checkout depend build export libs alldep install clean realclean distclean cleansrcdir pull_all build_all clobber clobber_all pull_and_build_all everything

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 */

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