Compare commits
4 Commits
NETSCAPE_7
...
alecf_fast
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
772d95df80 | ||
|
|
c92789df10 | ||
|
|
147b80a705 | ||
|
|
0bd57c4468 |
@@ -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);
|
||||
@@ -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);
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
@@ -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__
|
||||
@@ -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
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
|
||||
@@ -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
@@ -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
|
||||
@@ -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);
|
||||
@@ -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
|
||||
@@ -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
|
||||
298
mozilla/mailnews/base/src/nsMsgMailSession.cpp
Normal file
298
mozilla/mailnews/base/src/nsMsgMailSession.cpp
Normal file
@@ -0,0 +1,298 @@
|
||||
/* -*- 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 "msgCore.h" // for pre-compiled headers
|
||||
//#include "nsIMsgIdentity.h"
|
||||
#include "nsIMsgAccountManager.h"
|
||||
//#include "nsIPop3IncomingServer.h"
|
||||
#include "nsMsgMailSession.h"
|
||||
#include "nsMsgLocalCID.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsMsgFolderCache.h"
|
||||
#include "nsIFileLocator.h"
|
||||
#include "nsFileLocations.h"
|
||||
#include "nsIMsgStatusFeedback.h"
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMsgMailSession, nsCOMTypeInfo<nsIMsgMailSession>::GetIID());
|
||||
|
||||
static NS_DEFINE_CID(kMsgAccountManagerCID, NS_MSGACCOUNTMANAGER_CID);
|
||||
static NS_DEFINE_CID(kMsgFolderCacheCID, NS_MSGFOLDERCACHE_CID);
|
||||
static NS_DEFINE_IID(kIFileLocatorIID, NS_IFILELOCATOR_IID);
|
||||
static NS_DEFINE_CID(kFileLocatorCID, NS_FILELOCATOR_CID);
|
||||
|
||||
//static NS_DEFINE_CID(kMsgIdentityCID, NS_MSGIDENTITY_CID);
|
||||
//static NS_DEFINE_CID(kPop3IncomingServerCID, NS_POP3INCOMINGSERVER_CID);
|
||||
//static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
|
||||
|
||||
nsMsgMailSession::nsMsgMailSession():
|
||||
mRefCnt(0),
|
||||
m_accountManager(0),
|
||||
m_msgFolderCache(0)
|
||||
{
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
|
||||
nsMsgMailSession::~nsMsgMailSession()
|
||||
{
|
||||
Shutdown();
|
||||
}
|
||||
|
||||
nsresult nsMsgMailSession::Init()
|
||||
{
|
||||
nsresult rv = NS_NewISupportsArray(getter_AddRefs(mListeners));
|
||||
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
nsresult nsMsgMailSession::Shutdown()
|
||||
{
|
||||
if(m_accountManager)
|
||||
{
|
||||
if (m_msgFolderCache)
|
||||
m_accountManager->WriteToFolderCache(m_msgFolderCache);
|
||||
m_accountManager->CloseCachedConnections();
|
||||
m_accountManager->UnloadAccounts();
|
||||
}
|
||||
|
||||
NS_IF_RELEASE(m_accountManager);
|
||||
|
||||
NS_IF_RELEASE(m_msgFolderCache);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// nsIMsgMailSession
|
||||
nsresult nsMsgMailSession::GetCurrentIdentity(nsIMsgIdentity ** aIdentity)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager;
|
||||
rv = GetAccountManager(getter_AddRefs(accountManager));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIMsgAccount> defaultAccount;
|
||||
rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = defaultAccount->GetDefaultIdentity(aIdentity);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
NS_ADDREF(*aIdentity);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailSession::GetCurrentServer(nsIMsgIncomingServer ** aServer)
|
||||
{
|
||||
nsresult rv=NS_ERROR_UNEXPECTED;
|
||||
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager;
|
||||
rv = GetAccountManager(getter_AddRefs(accountManager));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIMsgAccount> defaultAccount;
|
||||
rv = accountManager->GetDefaultAccount(getter_AddRefs(defaultAccount));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
//if successful aServer will be addref'd by GetIncomingServer
|
||||
rv = defaultAccount->GetIncomingServer(aServer);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailSession::GetAccountManager(nsIMsgAccountManager* *aAM)
|
||||
{
|
||||
NS_ENSURE_ARG_POINTER(aAM);
|
||||
|
||||
nsresult rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgAccountManager, accountManager, kMsgAccountManagerCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
accountManager->LoadAccounts();
|
||||
|
||||
*aAM = accountManager;
|
||||
NS_IF_ADDREF(*aAM);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailSession::GetFolderCache(nsIMsgFolderCache* *aFolderCache)
|
||||
{
|
||||
if (!aFolderCache) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!m_msgFolderCache)
|
||||
{
|
||||
rv = nsComponentManager::CreateInstance(kMsgFolderCacheCID,
|
||||
NULL,
|
||||
nsCOMTypeInfo<nsIMsgFolderCache>::GetIID(),
|
||||
(void **)&m_msgFolderCache);
|
||||
if (NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
nsCOMPtr <nsIFileSpec> cacheFile;
|
||||
NS_WITH_SERVICE(nsIFileLocator, locator, kFileLocatorCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = locator->GetFileLocation(nsSpecialFileSpec::App_MessengerFolderCache50, getter_AddRefs(cacheFile));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
m_msgFolderCache->Init(cacheFile);
|
||||
|
||||
}
|
||||
|
||||
*aFolderCache = m_msgFolderCache;
|
||||
NS_IF_ADDREF(*aFolderCache);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailSession::GetTemporaryMsgStatusFeedback(nsIMsgStatusFeedback* *aMsgStatusFeedback)
|
||||
{
|
||||
if (!aMsgStatusFeedback) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*aMsgStatusFeedback = m_temporaryMsgStatusFeedback;
|
||||
NS_IF_ADDREF(*aMsgStatusFeedback);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsMsgMailSession::SetTemporaryMsgStatusFeedback(nsIMsgStatusFeedback* aMsgStatusFeedback)
|
||||
{
|
||||
m_temporaryMsgStatusFeedback = do_QueryInterface(aMsgStatusFeedback);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgMailSession::AddFolderListener(nsIFolderListener * listener)
|
||||
{
|
||||
mListeners->AppendElement(listener);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailSession::RemoveFolderListener(nsIFolderListener * listener)
|
||||
{
|
||||
mListeners->RemoveElement(listener);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgMailSession::NotifyFolderItemPropertyChanged(nsISupports *item,
|
||||
const char *property,
|
||||
const char* oldValue,
|
||||
const char* newValue)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
rv = mListeners->Count(&count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
for(PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsIFolderListener> listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i));
|
||||
listener->OnItemPropertyChanged(item, property, oldValue, newValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgMailSession::NotifyFolderItemPropertyFlagChanged(nsISupports *item,
|
||||
const char *property,
|
||||
PRUint32 oldValue,
|
||||
PRUint32 newValue)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
rv = mListeners->Count(&count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
for(PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsIFolderListener> listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i));
|
||||
listener->OnItemPropertyFlagChanged(item, property, oldValue, newValue);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailSession::NotifyFolderItemAdded(nsIFolder *folder, nsISupports *item)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
rv = mListeners->Count(&count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
for(PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsIFolderListener> listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i));
|
||||
listener->OnItemAdded(folder, item);
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailSession::NotifyFolderItemDeleted(nsIFolder *folder, nsISupports *item)
|
||||
{
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
rv = mListeners->Count(&count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
for(PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsIFolderListener> listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i));
|
||||
listener->OnItemRemoved(folder, item);
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailSession::NotifyFolderLoaded(nsIFolder *folder)
|
||||
{
|
||||
|
||||
nsresult rv;
|
||||
PRUint32 count;
|
||||
rv = mListeners->Count(&count);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
for(PRUint32 i = 0; i < count; i++)
|
||||
{
|
||||
nsCOMPtr<nsIFolderListener> listener = getter_AddRefs((nsIFolderListener*)mListeners->ElementAt(i));
|
||||
listener->OnFolderLoaded(folder);
|
||||
}
|
||||
return NS_OK;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
35
mozilla/mailnews/base/util/MANIFEST
Normal file
35
mozilla/mailnews/base/util/MANIFEST
Normal file
@@ -0,0 +1,35 @@
|
||||
# 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 is a list of local files which get copied to the mozilla:dist:mailnews directory
|
||||
#
|
||||
|
||||
nsMsgLineBuffer.h
|
||||
nsMsgGroupRecord.h
|
||||
nsUInt32Array.h
|
||||
nsMsgKeySet.h
|
||||
nsMsgFolder.h
|
||||
nsMsgDBFolder.h
|
||||
nsLocalFolderSummarySpec.h
|
||||
nsMsgIdentity.h
|
||||
nsMsgIncomingServer.h
|
||||
nsNewsSummarySpec.h
|
||||
nsMsgUtils.h
|
||||
nsMessage.h
|
||||
nsMsgProtocol.h
|
||||
nsMsgTxn.h
|
||||
nsMsgMailNewsUrl.h
|
||||
nsMsgI18N.h
|
||||
|
||||
75
mozilla/mailnews/base/util/Makefile.in
Normal file
75
mozilla/mailnews/base/util/Makefile.in
Normal file
@@ -0,0 +1,75 @@
|
||||
#
|
||||
# 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 = msgbaseutil
|
||||
LIBRARY_NAME = msgbaseutil
|
||||
|
||||
CPPSRCS = \
|
||||
nsMsgGroupRecord.cpp \
|
||||
nsMsgLineBuffer.cpp \
|
||||
nsMsgFolder.cpp \
|
||||
nsMsgDBFolder.cpp \
|
||||
nsUInt32Array.cpp \
|
||||
nsMsgKeySet.cpp \
|
||||
nsLocalFolderSummarySpec.cpp \
|
||||
nsNewsSummarySpec.cpp \
|
||||
nsMsgIdentity.cpp \
|
||||
nsMsgIncomingServer.cpp \
|
||||
nsMsgUtils.cpp \
|
||||
nsMessage.cpp \
|
||||
nsMsgProtocol.cpp \
|
||||
nsMsgMailNewsUrl.cpp \
|
||||
nsMsgTxn.cpp \
|
||||
nsMsgI18N.cpp \
|
||||
$(NULL)
|
||||
|
||||
EXPORTS = \
|
||||
nsMsgGroupRecord.h \
|
||||
nsMsgLineBuffer.h \
|
||||
nsUInt32Array.h \
|
||||
nsMsgKeySet.h \
|
||||
nsMsgFolder.h \
|
||||
nsMsgDBFolder.h \
|
||||
nsLocalFolderSummarySpec.h \
|
||||
nsNewsSummarySpec.h \
|
||||
nsMsgIdentity.h \
|
||||
nsMsgIncomingServer.h \
|
||||
nsMsgUtils.h \
|
||||
nsMessage.h \
|
||||
nsMsgProtocol.h \
|
||||
nsMsgMailNewsUrl.h \
|
||||
nsMsgTxn.h \
|
||||
nsMsgI18N.h \
|
||||
$(NULL)
|
||||
|
||||
EXTRA_DSO_LDOPTS = \
|
||||
-L$(DIST)/bin \
|
||||
-L$(DIST)/lib \
|
||||
-lxpcom \
|
||||
-lrdfutil_s \
|
||||
$(NSPR_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
BIN
mozilla/mailnews/base/util/macbuild/msgUtil.mcp
Normal file
BIN
mozilla/mailnews/base/util/macbuild/msgUtil.mcp
Normal file
Binary file not shown.
21
mozilla/mailnews/base/util/macbuild/msgUtilPrefix.h
Normal file
21
mozilla/mailnews/base/util/macbuild/msgUtilPrefix.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- 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 "MacPrefix.h"
|
||||
21
mozilla/mailnews/base/util/macbuild/msgUtilPrefixDebug.h
Normal file
21
mozilla/mailnews/base/util/macbuild/msgUtilPrefixDebug.h
Normal file
@@ -0,0 +1,21 @@
|
||||
/* -*- 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 "MacPrefix_debug.h"
|
||||
87
mozilla/mailnews/base/util/makefile.win
Normal file
87
mozilla/mailnews/base/util/makefile.win
Normal file
@@ -0,0 +1,87 @@
|
||||
#!nmake
|
||||
#
|
||||
# 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= msgbsutl
|
||||
|
||||
include <$(DEPTH)\config\config.mak>
|
||||
|
||||
################################################################################
|
||||
## exports
|
||||
|
||||
EXPORTS= \
|
||||
nsMsgLineBuffer.h \
|
||||
nsMsgGroupRecord.h \
|
||||
nsUInt32Array.h \
|
||||
nsMsgKeySet.h \
|
||||
nsMsgFolder.h \
|
||||
nsMsgDBFolder.h \
|
||||
nsLocalFolderSummarySpec.h \
|
||||
nsMsgIdentity.h \
|
||||
nsMsgIncomingServer.h \
|
||||
nsNewsSummarySpec.h \
|
||||
nsMsgUtils.h \
|
||||
nsMessage.h \
|
||||
nsMsgProtocol.h \
|
||||
nsMsgMailNewsUrl.h \
|
||||
nsMsgTxn.h \
|
||||
nsMsgI18N.h \
|
||||
$(NULL)
|
||||
|
||||
################################################################################
|
||||
## library
|
||||
|
||||
LIBNAME = .\$(OBJDIR)\msgbsutl
|
||||
DLL = $(LIBNAME).dll
|
||||
|
||||
DEFINES=-D_IMPL_NS_MSG_BASE
|
||||
|
||||
LCFLAGS = \
|
||||
$(LCFLAGS) \
|
||||
$(DEFINES) \
|
||||
$(NULL)
|
||||
|
||||
CPP_OBJS= \
|
||||
.\$(OBJDIR)\nsMsgGroupRecord.obj \
|
||||
.\$(OBJDIR)\nsMsgLineBuffer.obj \
|
||||
.\$(OBJDIR)\nsUInt32Array.obj \
|
||||
.\$(OBJDIR)\nsMsgKeySet.obj \
|
||||
.\$(OBJDIR)\nsMsgFolder.obj \
|
||||
.\$(OBJDIR)\nsMsgDBFolder.obj \
|
||||
.\$(OBJDIR)\nsLocalFolderSummarySpec.obj \
|
||||
.\$(OBJDIR)\nsMsgIdentity.obj \
|
||||
.\$(OBJDIR)\nsMsgIncomingServer.obj \
|
||||
.\$(OBJDIR)\nsNewsSummarySpec.obj \
|
||||
.\$(OBJDIR)\nsMsgUtils.obj \
|
||||
.\$(OBJDIR)\nsMessage.obj \
|
||||
.\$(OBJDIR)\nsMsgProtocol.obj \
|
||||
.\$(OBJDIR)\nsMsgMailNewsUrl.obj \
|
||||
.\$(OBJDIR)\nsMsgTxn.obj \
|
||||
.\$(OBJDIR)\nsMsgI18N.obj \
|
||||
$(NULL)
|
||||
|
||||
LLIBS= \
|
||||
$(DIST)\lib\xpcom.lib \
|
||||
$(DIST)\lib\rdfutil_s.lib \
|
||||
$(LIBNSPR) \
|
||||
$(NULL)
|
||||
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
libs:: $(DLL)
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(DLL_SUFFIX) $(DIST)\bin
|
||||
$(MAKE_INSTALL) $(LIBNAME).$(LIB_SUFFIX) $(DIST)\lib
|
||||
76
mozilla/mailnews/base/util/nsLocalFolderSummarySpec.cpp
Normal file
76
mozilla/mailnews/base/util/nsLocalFolderSummarySpec.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsLocalFolderSummarySpec.h"
|
||||
#include "plstr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsLocalFolderSummarySpec);
|
||||
|
||||
nsLocalFolderSummarySpec::~nsLocalFolderSummarySpec()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsLocalFolderSummarySpec);
|
||||
|
||||
}
|
||||
|
||||
nsLocalFolderSummarySpec::nsLocalFolderSummarySpec()
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsLocalFolderSummarySpec);
|
||||
}
|
||||
|
||||
nsLocalFolderSummarySpec::nsLocalFolderSummarySpec(const char *folderPath, PRBool create)
|
||||
: nsFileSpec(folderPath, create)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsLocalFolderSummarySpec);
|
||||
CreateSummaryFileName();
|
||||
}
|
||||
|
||||
nsLocalFolderSummarySpec::nsLocalFolderSummarySpec(const nsFileSpec& inFolderPath)
|
||||
: nsFileSpec(inFolderPath)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsLocalFolderSummarySpec);
|
||||
CreateSummaryFileName();
|
||||
}
|
||||
|
||||
nsLocalFolderSummarySpec::nsLocalFolderSummarySpec(const nsFilePath &inFolderPath, PRBool create) : nsFileSpec(inFolderPath, create)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsLocalFolderSummarySpec);
|
||||
CreateSummaryFileName();
|
||||
}
|
||||
|
||||
void nsLocalFolderSummarySpec::SetFolderName(const char *folderPath)
|
||||
{
|
||||
*this = folderPath;
|
||||
}
|
||||
|
||||
void nsLocalFolderSummarySpec:: CreateSummaryFileName()
|
||||
{
|
||||
char *leafName = GetLeafName();
|
||||
|
||||
nsString fullLeafName(leafName);
|
||||
|
||||
// Append .msf (msg summary file) this is what windows will want.
|
||||
// Mac and Unix can decide for themselves.
|
||||
|
||||
fullLeafName += ".msf"; // message summary file
|
||||
char *cLeafName = fullLeafName.ToNewCString();
|
||||
SetLeafName(cLeafName);
|
||||
nsAllocator::Free(cLeafName);
|
||||
PL_strfree(leafName);
|
||||
}
|
||||
|
||||
46
mozilla/mailnews/base/util/nsLocalFolderSummarySpec.h
Normal file
46
mozilla/mailnews/base/util/nsLocalFolderSummarySpec.h
Normal file
@@ -0,0 +1,46 @@
|
||||
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _nsLocalFolderSummarySpec_H
|
||||
#define _nsLocalFolderSummarySpec_H
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsFileSpec.h"
|
||||
|
||||
// Class to name a summary file for a local mail folder,
|
||||
// given a full folder file spec. For windows, this just means tacking .msf on the end.
|
||||
// For Unix, it might mean something like putting a '.' on the front and .msgsummary on the end.
|
||||
// Note this class expects the invoking code to fully specify the folder path.
|
||||
// This class does NOT prepend the local folder directory, or put .sbd on the containing
|
||||
// directory names.
|
||||
class NS_MSG_BASE nsLocalFolderSummarySpec : public nsFileSpec
|
||||
{
|
||||
public:
|
||||
virtual ~nsLocalFolderSummarySpec();
|
||||
nsLocalFolderSummarySpec();
|
||||
nsLocalFolderSummarySpec(const char *folderPath, PRBool create = PR_FALSE);
|
||||
nsLocalFolderSummarySpec(const nsFileSpec& inFolderPath);
|
||||
nsLocalFolderSummarySpec(const nsFilePath &inFolderPath, PRBool create = PR_FALSE);
|
||||
void SetFolderName(const char *folderPath);
|
||||
|
||||
protected:
|
||||
void CreateSummaryFileName();
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
509
mozilla/mailnews/base/util/nsMessage.cpp
Normal file
509
mozilla/mailnews/base/util/nsMessage.cpp
Normal file
@@ -0,0 +1,509 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "msgCore.h" // precompiled header...
|
||||
#include "nsMessage.h"
|
||||
#include "nsIMsgFolder.h"
|
||||
|
||||
|
||||
nsMessage::nsMessage(void)
|
||||
: nsRDFResource(), mFolder(nsnull)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsMessage::~nsMessage(void)
|
||||
{
|
||||
//Member variables are either nsCOMPtr's or ptrs we don't want to own.
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsMessage, nsRDFResource)
|
||||
NS_IMPL_RELEASE_INHERITED(nsMessage, nsRDFResource)
|
||||
|
||||
NS_IMETHODIMP nsMessage::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
|
||||
*aInstancePtr = nsnull;
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIMessage>::GetIID()) || aIID.Equals(nsCOMTypeInfo<nsIDBMessage>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDBMessage*, this);
|
||||
}
|
||||
if(*aInstancePtr)
|
||||
{
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsRDFResource::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMessage::Init(const char* aURI)
|
||||
{
|
||||
|
||||
return nsRDFResource::Init(aURI);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetProperty(const char *propertyName, nsString &resultProperty)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetProperty(propertyName, resultProperty);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetProperty(const char *propertyName, nsString &propertyStr)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetProperty(propertyName, propertyStr);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetUint32Property(const char *propertyName, PRUint32 *pResult)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetUint32Property(propertyName, pResult);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetUint32Property(const char *propertyName, PRUint32 propertyVal)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetUint32Property(propertyName, propertyVal);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetNumReferences(PRUint16 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetNumReferences(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetStringReference(PRInt32 refNum, nsCString &resultReference)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetStringReference(refNum, resultReference);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetDate(PRTime *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetDate(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetDate(PRTime date)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetDate(date);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetMessageId(const char *messageId)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetMessageId(messageId);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetReferences(const char *references)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetReferences(references);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetCCList(const char *ccList)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetCCList(ccList);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetRecipients(const char *recipients, PRBool recipientsIsNewsgroup)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetRecipients(recipients, recipientsIsNewsgroup);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetRecipientsArray(const char *names, const char *addresses, PRUint32 numAddresses)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetRecipientsArray(names, addresses, numAddresses);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetCCListArray(const char *names, const char *addresses, PRUint32 numAddresses)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetCCListArray(names, addresses, numAddresses);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetAuthor(const char *author)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetAuthor(author);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetSubject(const char *subject)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetSubject(subject);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetStatusOffset(PRUint32 statusOffset)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetStatusOffset(statusOffset);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetAuthor(nsString *resultAuthor)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetAuthor(resultAuthor);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetSubject(nsString *resultSubject)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetSubject(resultSubject);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetRecipients(nsString *resultRecipients)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetRecipients(resultRecipients);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetCCList(nsString *ccList)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetCCList(ccList);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMessageId(nsCString *resultMessageId)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetMessageId(resultMessageId);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMime2DecodedAuthor(nsString *resultAuthor)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetMime2DecodedAuthor(resultAuthor);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMime2DecodedSubject(nsString *resultSubject)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetMime2DecodedSubject(resultSubject);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMime2DecodedRecipients(nsString *resultRecipients)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetMime2DecodedRecipients(resultRecipients);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetAuthorCollationKey(nsString *resultAuthor)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetAuthorCollationKey(resultAuthor);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetSubjectCollationKey(nsString *resultSubject)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetSubjectCollationKey(resultSubject);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetRecipientsCollationKey(nsString *resultRecipients)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetRecipientsCollationKey(resultRecipients);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetFlags(PRUint32 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetFlags(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetFlags(PRUint32 flags)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetFlags(flags);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::OrFlags(PRUint32 flags, PRUint32 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->OrFlags(flags, result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::AndFlags(PRUint32 flags, PRUint32 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->AndFlags(flags, result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::MarkRead(PRBool bRead)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->MarkRead(bRead);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::MarkFlagged(PRBool bFlagged)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->MarkFlagged(bFlagged);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMessageKey(nsMsgKey *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetMessageKey(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetThreadId(nsMsgKey *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetThreadId(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetThreadId(nsMsgKey inKey)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetThreadId(inKey);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetMessageKey(nsMsgKey inKey)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetMessageKey(inKey);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMessageSize(PRUint32 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetMessageSize(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetLineCount(PRUint32 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetLineCount(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetMessageSize(PRUint32 messageSize)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetMessageSize(messageSize);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetLineCount(PRUint32 lineCount)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetLineCount(lineCount);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetPriority(nsMsgPriority priority)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetPriority(priority);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetPriority(const char *priority)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetPriority(priority);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetPriority(nsMsgPriority *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetPriority(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMessageOffset(PRUint32 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetMessageOffset(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetStatusOffset(PRUint32 *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetStatusOffset(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetCharSet(nsString *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetCharSet(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetThreadParent(nsMsgKey *result)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->GetThreadParent(result);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetThreadParent(nsMsgKey inKey)
|
||||
{
|
||||
if(mMsgHdr)
|
||||
return mMsgHdr->SetThreadParent(inKey);
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMsgFolder(nsIMsgFolder **folder)
|
||||
{
|
||||
if(!folder)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*folder = mFolder;
|
||||
if(mFolder)
|
||||
{
|
||||
NS_ADDREF(mFolder);
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetMsgFolder(nsIMsgFolder *folder)
|
||||
{
|
||||
mFolder = folder;
|
||||
//We don't want to own folder, so don't AddRef
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessage::SetMsgDBHdr(nsIMsgDBHdr *hdr)
|
||||
{
|
||||
mMsgHdr = dont_QueryInterface(hdr);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessage::GetMsgDBHdr(nsIMsgDBHdr **hdr)
|
||||
{
|
||||
*hdr = mMsgHdr;
|
||||
if(*hdr)
|
||||
{
|
||||
NS_ADDREF(*hdr);
|
||||
return NS_OK;
|
||||
}
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
113
mozilla/mailnews/base/util/nsMessage.h
Normal file
113
mozilla/mailnews/base/util/nsMessage.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/********************************************************************************************************
|
||||
|
||||
Interface for representing Messenger folders.
|
||||
|
||||
*********************************************************************************************************/
|
||||
|
||||
#ifndef nsMessage_h__
|
||||
#define nsMessage_h__
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsIMessage.h" /* include the interface we are going to support */
|
||||
#include "nsRDFResource.h"
|
||||
#include "nsIMsgHdr.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
|
||||
class NS_MSG_BASE nsMessage: public nsRDFResource, public nsIDBMessage
|
||||
{
|
||||
public:
|
||||
nsMessage(void);
|
||||
virtual ~nsMessage(void);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
NS_DECL_NSIMESSAGE
|
||||
NS_DECL_NSIDBMESSAGE
|
||||
|
||||
NS_IMETHOD Init(const char *aURI);
|
||||
//nsIMsgHdr
|
||||
NS_IMETHOD GetProperty(const char *propertyName, nsString &resultProperty);
|
||||
NS_IMETHOD SetProperty(const char *propertyName, nsString &propertyStr);
|
||||
NS_IMETHOD GetUint32Property(const char *propertyName, PRUint32 *pResult);
|
||||
NS_IMETHOD SetUint32Property(const char *propertyName, PRUint32 propertyVal);
|
||||
NS_IMETHOD GetNumReferences(PRUint16 *result);
|
||||
NS_IMETHOD GetStringReference(PRInt32 refNum, nsCString &resultReference);
|
||||
NS_IMETHOD GetDate(PRTime *result);
|
||||
NS_IMETHOD SetDate(PRTime date);
|
||||
NS_IMETHOD SetMessageId(const char *messageId);
|
||||
NS_IMETHOD SetReferences(const char *references);
|
||||
NS_IMETHOD SetCCList(const char *ccList);
|
||||
NS_IMETHOD SetRecipients(const char *recipients, PRBool recipientsIsNewsgroup);
|
||||
NS_IMETHOD SetRecipientsArray(const char *names, const char *addresses, PRUint32 numAddresses);
|
||||
NS_IMETHOD SetCCListArray(const char *names, const char *addresses, PRUint32 numAddresses);
|
||||
NS_IMETHOD SetAuthor(const char *author);
|
||||
NS_IMETHOD SetSubject(const char *subject);
|
||||
NS_IMETHOD SetStatusOffset(PRUint32 statusOffset);
|
||||
|
||||
NS_IMETHOD GetAuthor(nsString *resultAuthor);
|
||||
NS_IMETHOD GetSubject(nsString *resultSubject);
|
||||
NS_IMETHOD GetRecipients(nsString *resultRecipients);
|
||||
NS_IMETHOD GetCCList(nsString *ccList);
|
||||
NS_IMETHOD GetMessageId(nsCString *resultMessageId);
|
||||
|
||||
NS_IMETHOD GetMime2DecodedAuthor(nsString *resultAuthor);
|
||||
NS_IMETHOD GetMime2DecodedSubject(nsString *resultSubject);
|
||||
NS_IMETHOD GetMime2DecodedRecipients(nsString *resultRecipients);
|
||||
|
||||
NS_IMETHOD GetAuthorCollationKey(nsString *resultAuthor);
|
||||
NS_IMETHOD GetSubjectCollationKey(nsString *resultSubject);
|
||||
NS_IMETHOD GetRecipientsCollationKey(nsString *resultRecipients);
|
||||
|
||||
// flag handling routines
|
||||
NS_IMETHOD GetFlags(PRUint32 *result);
|
||||
NS_IMETHOD SetFlags(PRUint32 flags);
|
||||
NS_IMETHOD OrFlags(PRUint32 flags, PRUint32 *result);
|
||||
NS_IMETHOD AndFlags(PRUint32 flags, PRUint32 *result);
|
||||
|
||||
// Mark message routines
|
||||
NS_IMETHOD MarkRead(PRBool bRead);
|
||||
NS_IMETHOD MarkFlagged(PRBool bFlagged);
|
||||
|
||||
NS_IMETHOD GetMessageKey(nsMsgKey *result);
|
||||
NS_IMETHOD GetThreadId(nsMsgKey *result);
|
||||
NS_IMETHOD SetThreadId(nsMsgKey inKey);
|
||||
NS_IMETHOD SetMessageKey(nsMsgKey inKey);
|
||||
NS_IMETHOD GetMessageSize(PRUint32 *result);
|
||||
NS_IMETHOD SetMessageSize(PRUint32 messageSize);
|
||||
NS_IMETHOD GetLineCount(PRUint32 *result);
|
||||
NS_IMETHOD SetLineCount(PRUint32 lineCount);
|
||||
NS_IMETHOD SetPriority(nsMsgPriority priority);
|
||||
NS_IMETHOD SetPriority(const char *priority);
|
||||
NS_IMETHOD GetMessageOffset(PRUint32 *result);
|
||||
NS_IMETHOD GetStatusOffset(PRUint32 *result);
|
||||
NS_IMETHOD GetCharSet(nsString *result);
|
||||
NS_IMETHOD GetPriority(nsMsgPriority *result);
|
||||
NS_IMETHOD GetThreadParent(nsMsgKey *result);
|
||||
NS_IMETHOD SetThreadParent(nsMsgKey inKey);
|
||||
|
||||
protected:
|
||||
nsIMsgFolder *mFolder;
|
||||
nsCOMPtr<nsIMsgDBHdr> mMsgHdr;
|
||||
|
||||
};
|
||||
|
||||
#endif //nsMessage_h__
|
||||
|
||||
530
mozilla/mailnews/base/util/nsMsgDBFolder.cpp
Normal file
530
mozilla/mailnews/base/util/nsMsgDBFolder.cpp
Normal file
@@ -0,0 +1,530 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsIMessage.h"
|
||||
#include "nsMsgDBFolder.h"
|
||||
#include "nsMsgFolderFlags.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIMsgFolderCache.h"
|
||||
#include "nsIMsgFolderCacheElement.h"
|
||||
#include "nsIMsgMailSession.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsIMsgMailNewsUrl.h"
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
|
||||
|
||||
NS_IMPL_ADDREF_INHERITED(nsMsgDBFolder, nsMsgFolder)
|
||||
NS_IMPL_RELEASE_INHERITED(nsMsgDBFolder, nsMsgFolder)
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (!aInstancePtr) return NS_ERROR_NULL_POINTER;
|
||||
*aInstancePtr = nsnull;
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIDBChangeListener>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIDBChangeListener*, this);
|
||||
}
|
||||
else if (aIID.Equals(nsCOMTypeInfo<nsIUrlListener>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = NS_STATIC_CAST(nsIUrlListener*, this);
|
||||
}
|
||||
|
||||
if(*aInstancePtr)
|
||||
{
|
||||
AddRef();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return nsRDFResource::QueryInterface(aIID, aInstancePtr);
|
||||
}
|
||||
|
||||
nsMsgDBFolder::nsMsgDBFolder(void)
|
||||
: mCharset(""), mAddListener(PR_TRUE)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
nsMsgDBFolder::~nsMsgDBFolder(void)
|
||||
{
|
||||
if(mDatabase)
|
||||
{
|
||||
mDatabase->RemoveListener(this);
|
||||
mDatabase->Close(PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::StartFolderLoading(void)
|
||||
{
|
||||
if(mDatabase)
|
||||
mDatabase->RemoveListener(this);
|
||||
mAddListener = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::EndFolderLoading(void)
|
||||
{
|
||||
if(mDatabase)
|
||||
mDatabase->AddListener(this);
|
||||
mAddListener = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::GetThreads(nsISimpleEnumerator** threadEnumerator)
|
||||
{
|
||||
nsresult rv = GetDatabase();
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
return mDatabase->EnumerateThreads(threadEnumerator);
|
||||
else
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBFolder::GetThreadForMessage(nsIMessage *message, nsIMsgThread **thread)
|
||||
{
|
||||
nsresult rv = GetDatabase();
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIMsgDBHdr> msgDBHdr;
|
||||
nsCOMPtr<nsIDBMessage> dbMessage(do_QueryInterface(message, &rv));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = dbMessage->GetMsgDBHdr(getter_AddRefs(msgDBHdr));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = mDatabase->GetThreadContainingMsgHdr(msgDBHdr, thread);
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBFolder::HasMessage(nsIMessage *message, PRBool *hasMessage)
|
||||
{
|
||||
if(!hasMessage)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsresult rv = GetDatabase();
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsIMsgDBHdr> msgDBHdr, msgDBHdrForKey;
|
||||
nsCOMPtr<nsIDBMessage> dbMessage(do_QueryInterface(message, &rv));
|
||||
nsMsgKey key;
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = dbMessage->GetMsgDBHdr(getter_AddRefs(msgDBHdr));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = msgDBHdr->GetMessageKey(&key);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = mDatabase->ContainsKey(key, hasMessage);
|
||||
|
||||
}
|
||||
return rv;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::GetCharset(PRUnichar * *aCharset)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if(!aCharset)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if(mCharset == "")
|
||||
{
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefServiceCID, &rv);
|
||||
|
||||
char *prefCharset = nsnull;
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = prefs->CopyCharPref("intl.character_set_name", &prefCharset);
|
||||
}
|
||||
|
||||
nsString prefCharsetStr;
|
||||
if(prefCharset)
|
||||
{
|
||||
prefCharsetStr = prefCharset;
|
||||
PR_Free(prefCharset);
|
||||
}
|
||||
else
|
||||
{
|
||||
prefCharsetStr = "us-ascii";
|
||||
}
|
||||
*aCharset = prefCharsetStr.ToNewUnicode();
|
||||
}
|
||||
else
|
||||
{
|
||||
*aCharset = mCharset.ToNewUnicode();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::SetCharset(const PRUnichar * aCharset)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
nsCOMPtr<nsIDBFolderInfo> folderInfo;
|
||||
nsCOMPtr<nsIMsgDatabase> db;
|
||||
rv = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsString charset(aCharset);
|
||||
rv = folderInfo->SetCharacterSet(&charset);
|
||||
db->Commit(nsMsgDBCommitType::kLargeCommit);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgDBFolder::ReadDBFolderInfo(PRBool force)
|
||||
{
|
||||
// Since it turns out to be pretty expensive to open and close
|
||||
// the DBs all the time, if we have to open it once, get everything
|
||||
// we might need while we're here
|
||||
|
||||
nsresult result;
|
||||
|
||||
nsCOMPtr <nsIMsgFolderCache> folderCache;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kMsgMailSessionCID, &result);
|
||||
if(NS_SUCCEEDED(result))
|
||||
{
|
||||
result = mailSession->GetFolderCache(getter_AddRefs(folderCache));
|
||||
if (NS_SUCCEEDED(result) && folderCache)
|
||||
{
|
||||
char *uri;
|
||||
|
||||
result = GetURI(&uri);
|
||||
if (NS_SUCCEEDED(result) && uri)
|
||||
{
|
||||
nsCOMPtr <nsIMsgFolderCacheElement> cacheElement;
|
||||
result = folderCache->GetCacheElement(uri, PR_FALSE, getter_AddRefs(cacheElement));
|
||||
if (NS_SUCCEEDED(result) && cacheElement)
|
||||
{
|
||||
result = ReadFromFolderCache(cacheElement);
|
||||
}
|
||||
PR_Free(uri);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
// if (m_master->InitFolderFromCache (this))
|
||||
// return err;
|
||||
|
||||
if (force || !(mPrefFlags & MSG_FOLDER_PREF_CACHED))
|
||||
{
|
||||
nsCOMPtr<nsIDBFolderInfo> folderInfo;
|
||||
nsCOMPtr<nsIMsgDatabase> db;
|
||||
result = GetDBFolderInfoAndDB(getter_AddRefs(folderInfo), getter_AddRefs(db));
|
||||
if(NS_SUCCEEDED(result))
|
||||
{
|
||||
mIsCachable = PR_TRUE;
|
||||
if (folderInfo)
|
||||
{
|
||||
|
||||
folderInfo->GetFlags(&mPrefFlags);
|
||||
mPrefFlags |= MSG_FOLDER_PREF_CACHED;
|
||||
folderInfo->SetFlags(mPrefFlags);
|
||||
|
||||
folderInfo->GetNumMessages(&mNumTotalMessages);
|
||||
folderInfo->GetNumNewMessages(&mNumUnreadMessages);
|
||||
|
||||
//These should be put in IMAP folder only.
|
||||
//folderInfo->GetImapTotalPendingMessages(&mNumPendingTotalMessages);
|
||||
//folderInfo->GetImapUnreadPendingMessages(&mNumPendingUnreadMessages);
|
||||
|
||||
folderInfo->GetCharacterSet(&mCharset);
|
||||
|
||||
if (db) {
|
||||
PRBool hasnew;
|
||||
nsresult rv;
|
||||
rv = db->HasNew(&hasnew);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if (!hasnew && mNumPendingUnreadMessages <= 0) {
|
||||
ClearFlag(MSG_FOLDER_FLAG_GOT_NEW);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (db)
|
||||
db->Close(PR_FALSE);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
nsresult nsMsgDBFolder::SendFlagNotifications(nsISupports *item, PRUint32 oldFlags, PRUint32 newFlags)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
PRUint32 changedFlags = oldFlags ^ newFlags;
|
||||
if((changedFlags & MSG_FLAG_READ) || (changedFlags & MSG_FLAG_REPLIED)
|
||||
|| (changedFlags & MSG_FLAG_FORWARDED)|| (changedFlags & MSG_FLAG_NEW))
|
||||
{
|
||||
rv = NotifyPropertyFlagChanged(item, "Status", oldFlags, newFlags);
|
||||
}
|
||||
else if((changedFlags & MSG_FLAG_MARKED))
|
||||
{
|
||||
rv = NotifyPropertyFlagChanged(item, "Flagged", oldFlags, newFlags);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBFolder::GetMsgDatabase(nsIMsgDatabase** aMsgDatabase)
|
||||
{
|
||||
if (!aMsgDatabase || !mDatabase)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*aMsgDatabase = mDatabase;
|
||||
NS_ADDREF(*aMsgDatabase);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::OnKeyChange(nsMsgKey aKeyChanged, PRUint32 aOldFlags, PRUint32 aNewFlags,
|
||||
nsIDBChangeListener * aInstigator)
|
||||
{
|
||||
nsCOMPtr<nsIMsgDBHdr> pMsgDBHdr;
|
||||
nsresult rv = mDatabase->GetMsgHdrForKey(aKeyChanged, getter_AddRefs(pMsgDBHdr));
|
||||
if(NS_SUCCEEDED(rv) && pMsgDBHdr)
|
||||
{
|
||||
nsCOMPtr<nsIMessage> message;
|
||||
rv = CreateMessageFromMsgDBHdr(pMsgDBHdr, getter_AddRefs(message));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsISupports> msgSupports(do_QueryInterface(message, &rv));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
SendFlagNotifications(msgSupports, aOldFlags, aNewFlags);
|
||||
}
|
||||
UpdateSummaryTotals(PR_TRUE);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::OnKeyDeleted(nsMsgKey aKeyChanged, nsMsgKey aParentKey, PRInt32 aFlags,
|
||||
nsIDBChangeListener * aInstigator)
|
||||
{
|
||||
nsCOMPtr<nsIMsgDBHdr> pMsgDBHdr;
|
||||
nsresult rv = mDatabase->GetMsgHdrForKey(aKeyChanged, getter_AddRefs(pMsgDBHdr));
|
||||
if(NS_SUCCEEDED(rv) && pMsgDBHdr)
|
||||
{
|
||||
nsCOMPtr<nsIMessage> message;
|
||||
rv = CreateMessageFromMsgDBHdr(pMsgDBHdr, getter_AddRefs(message));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsISupports> msgSupports(do_QueryInterface(message, &rv));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
NotifyItemDeleted(msgSupports);
|
||||
}
|
||||
UpdateSummaryTotals(PR_TRUE);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::OnKeyAdded(nsMsgKey aKeyChanged, nsMsgKey aParentKey , PRInt32 aFlags,
|
||||
nsIDBChangeListener * aInstigator)
|
||||
{
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIMsgDBHdr> msgDBHdr;
|
||||
rv = mDatabase->GetMsgHdrForKey(aKeyChanged, getter_AddRefs(msgDBHdr));
|
||||
if(NS_SUCCEEDED(rv) && msgDBHdr)
|
||||
{
|
||||
nsCOMPtr<nsIMessage> message;
|
||||
rv = CreateMessageFromMsgDBHdr(msgDBHdr, getter_AddRefs(message));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
nsCOMPtr<nsISupports> msgSupports(do_QueryInterface(message));
|
||||
if(msgSupports)
|
||||
{
|
||||
NotifyItemAdded(msgSupports);
|
||||
}
|
||||
UpdateSummaryTotals(PR_TRUE);
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::OnParentChanged(nsMsgKey aKeyChanged, nsMsgKey oldParent, nsMsgKey newParent,
|
||||
nsIDBChangeListener * aInstigator)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::OnAnnouncerGoingAway(nsIDBChangeAnnouncer *
|
||||
instigator)
|
||||
{
|
||||
if (mDatabase)
|
||||
{
|
||||
mDatabase->RemoveListener(this);
|
||||
mDatabase = null_nsCOMPtr();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::ManyHeadersToDownload(PRBool *retval)
|
||||
{
|
||||
PRInt32 numTotalMessages;
|
||||
|
||||
if (!retval)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (!mDatabase)
|
||||
*retval = PR_TRUE;
|
||||
else if (NS_SUCCEEDED(GetTotalMessages(PR_FALSE, &numTotalMessages)) && numTotalMessages <= 0)
|
||||
*retval = PR_TRUE;
|
||||
else
|
||||
*retval = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
nsresult nsMsgDBFolder::ReadFromFolderCache(nsIMsgFolderCacheElement *element)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
char *charset;
|
||||
|
||||
element->GetInt32Property("flags", &mPrefFlags);
|
||||
element->GetInt32Property("totalMsgs", &mNumTotalMessages);
|
||||
element->GetInt32Property("totalUnreadMsgs", &mNumUnreadMessages);
|
||||
|
||||
element->GetStringProperty("charset", &charset);
|
||||
|
||||
#ifdef DEBUG_bienvenu1
|
||||
char *uri;
|
||||
|
||||
GetURI(&uri);
|
||||
printf("read total %ld for %s\n", mNumTotalMessages, uri);
|
||||
PR_Free(uri);
|
||||
#endif
|
||||
mCharset = charset;
|
||||
PR_FREEIF(charset);
|
||||
|
||||
mPrefFlags |= MSG_FOLDER_PREF_CACHED;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCache(nsIMsgFolderCache *folderCache)
|
||||
{
|
||||
nsCOMPtr <nsIEnumerator> aEnumerator;
|
||||
|
||||
nsresult rv = GetSubFolders(getter_AddRefs(aEnumerator));
|
||||
if(NS_FAILED(rv))
|
||||
return rv;
|
||||
|
||||
char *uri = nsnull;
|
||||
rv = GetURI(&uri);
|
||||
|
||||
if (folderCache)
|
||||
{
|
||||
nsCOMPtr <nsIMsgFolderCacheElement> cacheElement;
|
||||
rv = folderCache->GetCacheElement(uri, PR_TRUE, getter_AddRefs(cacheElement));
|
||||
if (NS_SUCCEEDED(rv) && cacheElement)
|
||||
rv = WriteToFolderCacheElem(cacheElement);
|
||||
}
|
||||
PR_FREEIF(uri);
|
||||
|
||||
|
||||
nsCOMPtr<nsISupports> aItem;
|
||||
|
||||
rv = aEnumerator->First();
|
||||
if (!NS_SUCCEEDED(rv))
|
||||
return NS_OK; // it's OK, there are no sub-folders.
|
||||
|
||||
while(NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = aEnumerator->CurrentItem(getter_AddRefs(aItem));
|
||||
if (NS_FAILED(rv)) break;
|
||||
nsCOMPtr<nsIMsgFolder> aMsgFolder(do_QueryInterface(aItem, &rv));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
if (folderCache)
|
||||
{
|
||||
rv = aMsgFolder->WriteToFolderCache(folderCache);
|
||||
if (!NS_SUCCEEDED(rv))
|
||||
break;
|
||||
}
|
||||
}
|
||||
rv = aEnumerator->Next();
|
||||
if (!NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = NS_OK;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgDBFolder::WriteToFolderCacheElem(nsIMsgFolderCacheElement *element)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
element->SetInt32Property("flags", mPrefFlags);
|
||||
element->SetInt32Property("totalMsgs", mNumTotalMessages);
|
||||
element->SetInt32Property("totalUnreadMsgs", mNumUnreadMessages);
|
||||
|
||||
element->SetStringProperty("charset", (const char *) nsCAutoString(mCharset));
|
||||
|
||||
#ifdef DEBUG_bienvenu1
|
||||
char *uri;
|
||||
|
||||
GetURI(&uri);
|
||||
printf("writing total %ld for %s\n", mNumTotalMessages, uri);
|
||||
PR_Free(uri);
|
||||
#endif
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBFolder::MarkAllMessagesRead(void)
|
||||
{
|
||||
nsresult rv = GetDatabase();
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
return mDatabase->MarkAllRead(nsnull);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBFolder::OnStartRunningUrl(nsIURI *aUrl)
|
||||
{
|
||||
NS_PRECONDITION(aUrl, "just a sanity check");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgDBFolder::OnStopRunningUrl(nsIURI *aUrl, nsresult aExitCode)
|
||||
{
|
||||
NS_PRECONDITION(aUrl, "just a sanity check");
|
||||
nsCOMPtr<nsIMsgMailNewsUrl> mailUrl = do_QueryInterface(aUrl);
|
||||
if (mailUrl)
|
||||
{
|
||||
PRBool updatingFolder = PR_FALSE;
|
||||
if (NS_SUCCEEDED(mailUrl->GetUpdatingFolder(&updatingFolder)) && updatingFolder)
|
||||
{
|
||||
NotifyFolderLoaded();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
80
mozilla/mailnews/base/util/nsMsgDBFolder.h
Normal file
80
mozilla/mailnews/base/util/nsMsgDBFolder.h
Normal file
@@ -0,0 +1,80 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsMsgDBFolder_h__
|
||||
#define nsMsgDBFolder_h__
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsMsgFolder.h"
|
||||
#include "nsIDBFolderInfo.h"
|
||||
#include "nsIMsgDatabase.h"
|
||||
#include "nsIMessage.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIDBChangeListener.h"
|
||||
#include "nsIUrlListener.h"
|
||||
|
||||
class nsIMsgFolderCacheElement;
|
||||
/*
|
||||
* nsMsgDBFolder
|
||||
* class derived from nsMsgFolder for those folders that use an nsIMsgDatabase
|
||||
*/
|
||||
|
||||
class NS_MSG_BASE nsMsgDBFolder: public nsMsgFolder,
|
||||
public nsIDBChangeListener,
|
||||
public nsIUrlListener
|
||||
{
|
||||
public:
|
||||
nsMsgDBFolder(void);
|
||||
virtual ~nsMsgDBFolder(void);
|
||||
NS_DECL_NSIDBCHANGELISTENER
|
||||
|
||||
NS_IMETHOD StartFolderLoading(void);
|
||||
NS_IMETHOD EndFolderLoading(void);
|
||||
NS_IMETHOD GetThreads(nsISimpleEnumerator** threadEnumerator);
|
||||
NS_IMETHOD GetThreadForMessage(nsIMessage *message, nsIMsgThread **thread);
|
||||
NS_IMETHOD HasMessage(nsIMessage *message, PRBool *hasMessage);
|
||||
NS_IMETHOD GetCharset(PRUnichar * *aCharset);
|
||||
NS_IMETHOD SetCharset(const PRUnichar * aCharset);
|
||||
|
||||
NS_IMETHOD GetMsgDatabase(nsIMsgDatabase** aMsgDatabase);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_DECL_NSIURLLISTENER
|
||||
|
||||
NS_IMETHOD WriteToFolderCache(nsIMsgFolderCache *folderCache);
|
||||
NS_IMETHOD WriteToFolderCacheElem(nsIMsgFolderCacheElement *element);
|
||||
NS_IMETHOD ManyHeadersToDownload(PRBool *_retval);
|
||||
|
||||
NS_IMETHOD MarkAllMessagesRead(void);
|
||||
|
||||
protected:
|
||||
virtual nsresult ReadDBFolderInfo(PRBool force);
|
||||
virtual nsresult GetDatabase() = 0;
|
||||
virtual nsresult SendFlagNotifications(nsISupports *item, PRUint32 oldFlags, PRUint32 newFlags);
|
||||
nsresult ReadFromFolderCache(nsIMsgFolderCacheElement *element);
|
||||
|
||||
protected:
|
||||
nsCOMPtr<nsIMsgDatabase> mDatabase;
|
||||
nsString mCharset;
|
||||
PRBool mAddListener;
|
||||
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
1745
mozilla/mailnews/base/util/nsMsgFolder.cpp
Normal file
1745
mozilla/mailnews/base/util/nsMsgFolder.cpp
Normal file
File diff suppressed because it is too large
Load Diff
268
mozilla/mailnews/base/util/nsMsgFolder.h
Normal file
268
mozilla/mailnews/base/util/nsMsgFolder.h
Normal file
@@ -0,0 +1,268 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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.
|
||||
*/
|
||||
|
||||
/********************************************************************************************************
|
||||
|
||||
Interface for representing Messenger folders.
|
||||
|
||||
*********************************************************************************************************/
|
||||
|
||||
#ifndef nsMsgFolder_h__
|
||||
#define nsMsgFolder_h__
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsIMsgFolder.h" /* include the interface we are going to support */
|
||||
#include "nsRDFResource.h"
|
||||
#include "nsIDBFolderInfo.h"
|
||||
#include "nsIMsgDatabase.h"
|
||||
#include "nsIMsgIncomingServer.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIURL.h"
|
||||
/*
|
||||
* MsgFolder
|
||||
*/
|
||||
|
||||
class NS_MSG_BASE nsMsgFolder: public nsRDFResource, public nsIMsgFolder
|
||||
{
|
||||
public:
|
||||
nsMsgFolder(void);
|
||||
virtual ~nsMsgFolder(void);
|
||||
|
||||
NS_DECL_ISUPPORTS_INHERITED
|
||||
|
||||
NS_DECL_NSICOLLECTION
|
||||
NS_DECL_NSIFOLDER
|
||||
// eventually this will be an instantiable class, and we should
|
||||
// use this macro:
|
||||
// NS_DECL_NSIMSGFOLDER
|
||||
|
||||
// right now a few of these methods are left abstract, and
|
||||
// are commented out below
|
||||
|
||||
// begin NS_DECL_NSIMSGFOLDER
|
||||
NS_IMETHOD AddUnique(nsISupports *element);
|
||||
NS_IMETHOD ReplaceElement(nsISupports *element, nsISupports *newElement);
|
||||
NS_IMETHOD GetMessages(nsISimpleEnumerator **_retval);
|
||||
NS_IMETHOD GetThreads(nsISimpleEnumerator **_retval);
|
||||
NS_IMETHOD StartFolderLoading(void);
|
||||
NS_IMETHOD EndFolderLoading(void);
|
||||
NS_IMETHOD UpdateFolder(void);
|
||||
NS_IMETHOD GetThreadForMessage(nsIMessage *message, nsIMsgThread **_retval);
|
||||
NS_IMETHOD HasMessage(nsIMessage *message, PRBool *_retval);
|
||||
NS_IMETHOD GetVisibleSubFolders(nsIEnumerator **_retval);
|
||||
NS_IMETHOD GetPrettiestName(PRUnichar * *aPrettiestName);
|
||||
NS_IMETHOD GetFolderURL(char * *aFolderURL);
|
||||
NS_IMETHOD GetDeleteIsMoveToTrash(PRBool *aDeleteIsMoveToTrash);
|
||||
NS_IMETHOD GetShowDeletedMessages(PRBool *aShowDeletedMessages);
|
||||
NS_IMETHOD GetServer(nsIMsgIncomingServer * *aServer);
|
||||
NS_IMETHOD GetIsServer(PRBool *aIsServer);
|
||||
NS_IMETHOD OnCloseFolder(void);
|
||||
NS_IMETHOD Delete(void);
|
||||
NS_IMETHOD DeleteSubFolders(nsISupportsArray *folders);
|
||||
NS_IMETHOD PropagateDelete(nsIMsgFolder *folder, PRBool deleteStorage);
|
||||
NS_IMETHOD RecursiveDelete(PRBool deleteStorage);
|
||||
NS_IMETHOD CreateSubfolder(const char *folderName);
|
||||
NS_IMETHOD Compact(void);
|
||||
NS_IMETHOD EmptyTrash(void);
|
||||
NS_IMETHOD Rename(const char *name);
|
||||
NS_IMETHOD Adopt(nsIMsgFolder *srcFolder, PRUint32 *outPos);
|
||||
NS_IMETHOD ContainsChildNamed(const char *name, PRBool *_retval);
|
||||
NS_IMETHOD IsAncestorOf(nsIMsgFolder *folder, PRBool *_retval);
|
||||
NS_IMETHOD GenerateUniqueSubfolderName(const char *prefix, nsIMsgFolder *otherFolder, char **_retval);
|
||||
NS_IMETHOD UpdateSummaryTotals(PRBool force);
|
||||
NS_IMETHOD SummaryChanged(void);
|
||||
NS_IMETHOD GetNumUnread(PRBool deep, PRInt32 *_retval);
|
||||
NS_IMETHOD GetTotalMessages(PRBool deep, PRInt32 *_retval);
|
||||
NS_IMETHOD GetExpungedBytesCount(PRUint32 *aExpungedBytesCount);
|
||||
NS_IMETHOD GetDeletable(PRBool *aDeletable);
|
||||
NS_IMETHOD GetCanCreateChildren(PRBool *aCanCreateChildren);
|
||||
NS_IMETHOD GetCanBeRenamed(PRBool *aCanBeRenamed);
|
||||
NS_IMETHOD GetRequiresCleanup(PRBool *aRequiresCleanup);
|
||||
NS_IMETHOD ClearRequiresCleanup(void);
|
||||
NS_IMETHOD ManyHeadersToDownload(PRBool *_retval);
|
||||
NS_IMETHOD GetKnowsSearchNntpExtension(PRBool *aKnowsSearchNntpExtension);
|
||||
NS_IMETHOD GetAllowsPosting(PRBool *aAllowsPosting);
|
||||
NS_IMETHOD GetDisplayRecipients(PRBool *aDisplayRecipients);
|
||||
NS_IMETHOD GetRelativePathName(char * *aRelativePathName);
|
||||
NS_IMETHOD GetSizeOnDisk(PRUint32 *aSizeOnDisk);
|
||||
NS_IMETHOD RememberPassword(const char *password);
|
||||
NS_IMETHOD GetRememberedPassword(char * *aRememberedPassword);
|
||||
NS_IMETHOD UserNeedsToAuthenticateForFolder(PRBool displayOnly, PRBool *_retval);
|
||||
NS_IMETHOD GetUsername(char * *aUsername);
|
||||
NS_IMETHOD GetHostname(char * *aHostname);
|
||||
NS_IMETHOD SetFlag(PRUint32 flag);
|
||||
NS_IMETHOD ClearFlag(PRUint32 flag);
|
||||
NS_IMETHOD GetFlag(PRUint32 flag, PRBool *_retval);
|
||||
NS_IMETHOD ToggleFlag(PRUint32 flag);
|
||||
NS_IMETHOD OnFlagChange(PRUint32 flag);
|
||||
NS_IMETHOD GetFlags(PRUint32 *aFlags);
|
||||
NS_IMETHOD GetFoldersWithFlag(PRUint32 flags, nsIMsgFolder **result, PRUint32 resultsize, PRUint32 *numFolders);
|
||||
NS_IMETHOD GetExpansionArray(nsISupportsArray *expansionArray);
|
||||
// NS_IMETHOD DeleteMessages(nsISupportsArray *message, nsITransactionManager *txnMgr, PRBool deleteStorage);
|
||||
NS_IMETHOD CopyMessages(nsIMsgFolder *srcFolder, nsISupportsArray *messages, PRBool isMove, nsITransactionManager *txnMgr, nsIMsgCopyServiceListener *listener);
|
||||
NS_IMETHOD CopyFileMessage(nsIFileSpec *fileSpec, nsIMessage *msgToReplace, PRBool isDraft, nsITransactionManager *txnMgr, nsIMsgCopyServiceListener *listener);
|
||||
NS_IMETHOD AcquireSemaphore(nsISupports *semHolder);
|
||||
NS_IMETHOD ReleaseSemaphore(nsISupports *semHolder);
|
||||
NS_IMETHOD TestSemaphore(nsISupports *semHolder, PRBool *_retval);
|
||||
NS_IMETHOD GetLocked(PRBool *aLocked);
|
||||
// NS_IMETHOD CreateMessageFromMsgDBHdr(nsIMsgDBHdr *msgDBHdr, nsIMessage **_retval);
|
||||
NS_IMETHOD GetNewMessages(void);
|
||||
// NS_IMETHOD WriteToFolderCache(nsIMsgFolderCache *folderCache);
|
||||
// NS_IMETHOD GetCharset(PRUnichar * *aCharset);
|
||||
// NS_IMETHOD SetCharset(const PRUnichar * aCharset);
|
||||
NS_IMETHOD GetBiffState(PRUint32 *aBiffState);
|
||||
NS_IMETHOD SetBiffState(PRUint32 aBiffState);
|
||||
NS_IMETHOD GetNumNewMessages(PRInt32 *aNumNewMessages);
|
||||
NS_IMETHOD SetNumNewMessages(PRInt32 aNumNewMessages);
|
||||
NS_IMETHOD GetNewMessagesNotificationDescription(PRUnichar * *aNewMessagesNotificationDescription);
|
||||
NS_IMETHOD GetRootFolder(nsIMsgFolder * *aRootFolder);
|
||||
NS_IMETHOD GetMsgDatabase(nsIMsgDatabase * *aMsgDatabase);
|
||||
NS_IMETHOD GetPath(nsIFileSpec * *aPath);
|
||||
NS_IMETHOD MarkMessagesRead(nsISupportsArray *messages, PRBool markRead);
|
||||
NS_IMETHOD MarkAllMessagesRead(void);
|
||||
NS_IMETHOD MarkMessagesFlagged(nsISupportsArray *messages, PRBool markFlagged);
|
||||
NS_IMETHOD GetChildWithURI(const char *uri, PRBool deep, nsIMsgFolder **_retval);
|
||||
|
||||
// end NS_DECL_NSIMSGFOLDER
|
||||
|
||||
// nsRDFResource overrides
|
||||
NS_IMETHOD Init(const char* aURI);
|
||||
|
||||
#if 0
|
||||
static nsresult GetRoot(nsIMsgFolder* *result);
|
||||
#endif
|
||||
// Gets the URL that represents the given message. Returns a newly
|
||||
// created string that must be free'd using XP_FREE().
|
||||
// If the db is NULL, then returns a URL that represents the entire
|
||||
// folder as a whole.
|
||||
#ifdef HAVE_DB
|
||||
NS_IMETHOD BuildUrl(nsMsgDatabase *db, nsMsgKey key, char ** url);
|
||||
|
||||
// updates num messages and num unread - should be pure virtual
|
||||
// when I get around to implementing in all subclasses?
|
||||
NS_IMETHOD GetTotalMessagesInDB(PRUint32 *totalMessages) const; // How many messages in database.
|
||||
// These functions are used for tricking the front end into thinking that we have more
|
||||
// messages than are really in the DB. This is usually after and IMAP message copy where
|
||||
// we don't want to do an expensive select until the user actually opens that folder
|
||||
// These functions are called when MSG_Master::GetFolderLineById is populating a MSG_FolderLine
|
||||
// struct used by the FE
|
||||
int32 GetNumPendingUnread(PRBool deep = PR_FALSE);
|
||||
int32 GetNumPendingTotalMessages(PRBool deep = PR_FALSE);
|
||||
|
||||
void ChangeNumPendingUnread(int32 delta);
|
||||
void ChangeNumPendingTotalMessages(int32 delta);
|
||||
|
||||
|
||||
NS_IMETHOD SetFolderPrefFlags(PRUint32 flags);
|
||||
NS_IMETHOD GetFolderPrefFlags(PRUint32 *flags);
|
||||
|
||||
|
||||
NS_IMETHOD SetLastMessageLoaded(nsMsgKey lastMessageLoaded);
|
||||
NS_IMETHOD GetLastMessageLoaded();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_ADMINURL
|
||||
NS_IMETHOD GetAdminUrl(MWContext *context, MSG_AdminURLType type);
|
||||
NS_IMETHOD HaveAdminUrl(MSG_AdminURLType type, PRBool *hadAdminUrl);
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef HAVE_PANE
|
||||
NS_IMETHOD MarkAllRead(MSG_Pane *pane, PRBool deep);
|
||||
NS_IMETHOD SetFlagInAllFolderPanes(PRUint32 which);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_NET
|
||||
NS_IMETHOD EscapeMessageId(const char *messageId, const char **escapeMessageID);
|
||||
NS_IMETHOD ShouldPerformOperationOffline(PRBool *performOffline);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CACHE
|
||||
virtual nsresult WriteToCache(XP_File);
|
||||
virtual nsresult ReadFromCache(char *);
|
||||
virtual PRBool IsCachable();
|
||||
void SkipCacheTokens(char **ppBuf, int numTokens);
|
||||
#endif
|
||||
|
||||
#ifdef DOES_FOLDEROPERATIONS
|
||||
int DownloadToTempFileAndUpload(MessageCopyInfo *copyInfo, nsMsgKeyArray &keysToSave, MSG_FolderInfo *dstFolder, nsMsgDatabase *sourceDB);
|
||||
void UpdateMoveCopyStatus(MWContext *context, PRBool isMove, int32 curMsgCount, int32 totMessages);
|
||||
#endif
|
||||
|
||||
virtual nsresult GetDBFolderInfoAndDB(nsIDBFolderInfo **folderInfo, nsIMsgDatabase **db) = 0;
|
||||
|
||||
|
||||
NS_IMETHOD MatchName(nsString *name, PRBool *matches);
|
||||
|
||||
|
||||
protected:
|
||||
nsresult NotifyPropertyChanged(char *property, char* oldValue, char* newValue);
|
||||
nsresult NotifyPropertyFlagChanged(nsISupports *item, char *property, PRUint32 oldValue,
|
||||
PRUint32 newValue);
|
||||
nsresult NotifyItemAdded(nsISupports *item);
|
||||
nsresult NotifyItemDeleted(nsISupports *item);
|
||||
|
||||
nsresult NotifyFolderLoaded();
|
||||
// this is a little helper function that is not part of the public interface.
|
||||
// we use it to get the IID of the incoming server for the derived folder.
|
||||
// w/out a function like this we would have to implement GetServer in each
|
||||
// derived folder class.
|
||||
virtual const char* GetIncomingServerType() = 0;
|
||||
|
||||
protected:
|
||||
PRUint32 mFlags;
|
||||
nsIFolder *mParent; //This won't be refcounted for ownership reasons.
|
||||
PRInt32 mNumUnreadMessages; /* count of unread messages (-1 means
|
||||
unknown; -2 means unknown but we already
|
||||
tried to find out.) */
|
||||
PRInt32 mNumTotalMessages; /* count of existing messages. */
|
||||
nsCOMPtr<nsISupportsArray> mSubFolders;
|
||||
nsVoidArray *mListeners; //This can't be an nsISupportsArray because due to
|
||||
//ownership issues, listeners can't be AddRef'd
|
||||
|
||||
PRInt32 mPrefFlags; // prefs like MSG_PREF_OFFLINE, MSG_PREF_ONE_PANE, etc
|
||||
nsISupports *mSemaphoreHolder; // set when the folder is being written to
|
||||
//Due to ownership issues, this won't be AddRef'd.
|
||||
|
||||
nsIMsgIncomingServer* m_server; //this won't be addrefed....ownership issue here
|
||||
|
||||
#ifdef HAVE_DB
|
||||
nsMsgKey m_lastMessageLoaded;
|
||||
#endif
|
||||
// These values are used for tricking the front end into thinking that we have more
|
||||
// messages than are really in the DB. This is usually after and IMAP message copy where
|
||||
// we don't want to do an expensive select until the user actually opens that folder
|
||||
PRInt32 mNumPendingUnreadMessages;
|
||||
PRInt32 mNumPendingTotalMessages;
|
||||
|
||||
PRUint32 mBiffState;
|
||||
PRInt32 mNumNewBiffMessages;
|
||||
|
||||
PRBool mIsCachable;
|
||||
|
||||
//
|
||||
// stuff from the uri
|
||||
//
|
||||
|
||||
PRBool mIsServer;
|
||||
nsString mName;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
598
mozilla/mailnews/base/util/nsMsgGroupRecord.cpp
Normal file
598
mozilla/mailnews/base/util/nsMsgGroupRecord.cpp
Normal file
@@ -0,0 +1,598 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 "msgCore.h" // precompiled header...
|
||||
#include "prlog.h"
|
||||
|
||||
#include "nsMsgGroupRecord.h"
|
||||
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
#include "nsEscape.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
// mscott: this is lame...I know....
|
||||
#define MK_OUT_OF_MEMORY 1
|
||||
|
||||
const PRUint32 F_ISGROUP = 0x00000001;
|
||||
const PRUint32 F_EXPANDED = 0x00000002;
|
||||
const PRUint32 F_CATCONT = 0x00000004;
|
||||
const PRUint32 F_VIRTUAL = 0x00000008;
|
||||
const PRUint32 F_DIRTY = 0x00000010;
|
||||
const PRUint32 F_DESCENDENTSLOADED = 0x00000020;
|
||||
const PRUint32 F_HTMLOKGROUP = 0x00000040;
|
||||
const PRUint32 F_HTMLOKTREE = 0x00000080;
|
||||
const PRUint32 F_NEEDEXTRAINFO = 0x00000100;
|
||||
const PRUint32 F_DOESNOTEXIST = 0x00000200;
|
||||
const PRUint32 RUNTIMEFLAGS = // Flags to be sure *not* to write to disk.
|
||||
F_DIRTY | F_DESCENDENTSLOADED | F_EXPANDED;
|
||||
|
||||
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::GroupNameCompare(const char* name1, const char* name2,
|
||||
char delimiter, PRBool caseInsensitive)
|
||||
{
|
||||
if (caseInsensitive)
|
||||
{
|
||||
while (*name1 && (nsCRT::ToUpper(*name1) == nsCRT::ToUpper(*name2))) {
|
||||
name1++;
|
||||
name2++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
while (*name1 && *name1 == *name2) {
|
||||
name1++;
|
||||
name2++;
|
||||
}
|
||||
}
|
||||
|
||||
if (*name1 && *name2) {
|
||||
if (*name1 == delimiter) return -1;
|
||||
if (*name2 == delimiter) return 1;
|
||||
}
|
||||
|
||||
if (caseInsensitive)
|
||||
return int(nsCRT::ToUpper(*name1)) - int(nsCRT::ToUpper(*name2));
|
||||
else
|
||||
return int(*name1) - int(*name2);
|
||||
}
|
||||
|
||||
|
||||
nsMsgGroupRecord*
|
||||
nsMsgGroupRecord::Create(nsMsgGroupRecord* parent, const char* partname,
|
||||
PRInt64 aTime, PRInt32 uniqueid, PRInt32 fileoffset)
|
||||
{
|
||||
nsMsgGroupRecord* result = new nsMsgGroupRecord(parent, partname,
|
||||
aTime, uniqueid, fileoffset);
|
||||
if (result && partname && !result->m_partname) {
|
||||
// We ran out of memory.
|
||||
delete result;
|
||||
result = NULL;
|
||||
}
|
||||
result->InitializeSibling();
|
||||
return result;
|
||||
}
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsMsgGroupRecord);
|
||||
|
||||
nsMsgGroupRecord::nsMsgGroupRecord(nsMsgGroupRecord* parent, const char* partname,
|
||||
PRInt64 aTime, PRInt32 uniqueid, PRInt32 fileoffset,
|
||||
char delimiter /* = '.' */)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsMsgGroupRecord);
|
||||
int length;
|
||||
m_prettyname = NULL;
|
||||
m_parent = parent;
|
||||
m_children = NULL;
|
||||
m_sibling = NULL;
|
||||
m_flags = 0;
|
||||
m_partname = NULL;
|
||||
m_addtime = aTime;
|
||||
m_uniqueId = uniqueid;
|
||||
m_fileoffset = fileoffset;
|
||||
m_delimiter = delimiter;
|
||||
if (partname) {
|
||||
length = PL_strlen(partname);
|
||||
// PR_ASSERT(parent != NULL);
|
||||
m_partname = new char [length + 1];
|
||||
if (!m_partname) {
|
||||
m_parent = NULL;
|
||||
return;
|
||||
}
|
||||
PL_strcpy(m_partname, partname);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsMsgGroupRecord::~nsMsgGroupRecord()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsMsgGroupRecord);
|
||||
delete [] m_partname;
|
||||
m_partname = NULL;
|
||||
delete [] m_prettyname;
|
||||
m_prettyname = NULL;
|
||||
while (m_children) {
|
||||
delete m_children;
|
||||
}
|
||||
m_children = NULL;
|
||||
if (m_parent) {
|
||||
nsMsgGroupRecord** ptr;
|
||||
for (ptr = &(m_parent->m_children);
|
||||
*ptr;
|
||||
ptr = &((*ptr)->m_sibling)) {
|
||||
if (*ptr == this) {
|
||||
*ptr = m_sibling;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void nsMsgGroupRecord::InitializeSibling()
|
||||
{
|
||||
if (m_parent) {
|
||||
PR_ASSERT(m_partname != NULL);
|
||||
nsMsgGroupRecord** ptr;
|
||||
for (ptr = &(m_parent->m_children) ; *ptr ; ptr = &((*ptr)->m_sibling)) {
|
||||
int comp = GroupNameCompare((*ptr)->m_partname, m_partname, m_delimiter, IsIMAPGroupRecord());
|
||||
PR_ASSERT(comp != 0);
|
||||
if (comp >= 0) break;
|
||||
}
|
||||
m_sibling = *ptr;
|
||||
*ptr = this;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
nsMsgGroupRecord*
|
||||
nsMsgGroupRecord::FindDescendant(const char* name)
|
||||
{
|
||||
if (!name || !*name) return this;
|
||||
char* ptr = PL_strchr(name, m_delimiter);
|
||||
if (ptr) *ptr = '\0';
|
||||
nsMsgGroupRecord* child;
|
||||
for (child = m_children ; child ; child = child->m_sibling) {
|
||||
if (PL_strcmp(child->m_partname, name) == 0) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (ptr) {
|
||||
*ptr++ = m_delimiter;
|
||||
if (child) {
|
||||
return child->FindDescendant(ptr);
|
||||
}
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
|
||||
nsMsgGroupRecord*
|
||||
nsMsgGroupRecord::GetSiblingOrAncestorSibling()
|
||||
{
|
||||
if (m_sibling) return m_sibling;
|
||||
if (m_parent) return m_parent->GetSiblingOrAncestorSibling();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nsMsgGroupRecord*
|
||||
nsMsgGroupRecord::GetNextAlphabetic()
|
||||
{
|
||||
nsMsgGroupRecord* result;
|
||||
if (m_children) result = m_children;
|
||||
else result = GetSiblingOrAncestorSibling();
|
||||
#ifdef DEBUG_slowAndParanoid
|
||||
if (result) {
|
||||
char* ptr1 = GetFullName();
|
||||
char* ptr2 = result->GetFullName();
|
||||
PR_ASSERT(GroupNameCompare(ptr1, ptr2) < 0);
|
||||
delete [] ptr1;
|
||||
delete [] ptr2;
|
||||
}
|
||||
#endif
|
||||
return result;
|
||||
}
|
||||
|
||||
nsMsgGroupRecord*
|
||||
nsMsgGroupRecord::GetNextAlphabeticNoCategories()
|
||||
{
|
||||
if (IsCategoryContainer()) {
|
||||
return GetSiblingOrAncestorSibling();
|
||||
} else {
|
||||
return GetNextAlphabetic();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
nsMsgGroupRecord::GetFullName()
|
||||
{
|
||||
int length = 0;
|
||||
nsMsgGroupRecord* ptr;
|
||||
for (ptr = this ; ptr ; ptr = ptr->m_parent) {
|
||||
if (ptr->m_partname) length += PL_strlen(ptr->m_partname) + 1;
|
||||
}
|
||||
PR_ASSERT(length > 0);
|
||||
if (length <= 0) return NULL;
|
||||
char* result = new char [length];
|
||||
if (result) {
|
||||
SuckInName(result);
|
||||
PR_ASSERT(int(PL_strlen(result)) + 1 == length);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
nsMsgGroupRecord::SuckInName(char* ptr)
|
||||
{
|
||||
if (m_parent && m_parent->m_partname) {
|
||||
ptr = m_parent->SuckInName(ptr);
|
||||
*ptr++ = m_delimiter;
|
||||
}
|
||||
PL_strcpy(ptr, m_partname);
|
||||
return ptr + PL_strlen(ptr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetPrettyName(const char* name)
|
||||
{
|
||||
if (name == NULL && m_prettyname == NULL) return 0;
|
||||
m_flags |= F_DIRTY;
|
||||
delete [] m_prettyname;
|
||||
m_prettyname = NULL;
|
||||
if (!name || !*name) {
|
||||
return 0;
|
||||
}
|
||||
int length = PL_strlen(name);
|
||||
m_prettyname = new char [length + 1];
|
||||
if (!m_prettyname) {
|
||||
return MK_OUT_OF_MEMORY;
|
||||
}
|
||||
PL_strcpy(m_prettyname, name);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsCategory()
|
||||
{
|
||||
return GetCategoryContainer() != NULL;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsCategoryContainer()
|
||||
{
|
||||
return (m_flags & F_CATCONT) != 0;
|
||||
}
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::NeedsExtraInfo()
|
||||
{
|
||||
return (m_flags & F_NEEDEXTRAINFO) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetNeedsExtraInfo(PRBool value)
|
||||
{
|
||||
return TweakFlag(F_NEEDEXTRAINFO, value);
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetIsCategoryContainer(PRBool value)
|
||||
{
|
||||
// refuse to set a group to be a category container if it has a parent
|
||||
// that's a category container.
|
||||
if (! (value && GetCategoryContainer()))
|
||||
return TweakFlag(F_CATCONT, value);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
nsMsgGroupRecord*
|
||||
nsMsgGroupRecord::GetCategoryContainer()
|
||||
{
|
||||
if (IsCategoryContainer()) return NULL;
|
||||
for (nsMsgGroupRecord* ptr = m_parent ; ptr ; ptr = ptr->m_parent) {
|
||||
if (ptr->IsCategoryContainer()) return ptr;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMsgGroupRecord::IsVirtual(PRBool *retval)
|
||||
{
|
||||
*retval =( (m_flags & F_VIRTUAL) != 0);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgGroupRecord::SetIsVirtual(PRBool value)
|
||||
{
|
||||
TweakFlag(F_VIRTUAL, value);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsExpanded()
|
||||
{
|
||||
return (m_flags & F_EXPANDED) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetIsExpanded(PRBool value)
|
||||
{
|
||||
return TweakFlag(F_EXPANDED, value);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsHTMLOKGroup()
|
||||
{
|
||||
return (m_flags & F_HTMLOKGROUP) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetIsHTMLOKGroup(PRBool value)
|
||||
{
|
||||
return TweakFlag(F_HTMLOKGROUP, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsHTMLOKTree()
|
||||
{
|
||||
return (m_flags & F_HTMLOKTREE) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetIsHTMLOKTree(PRBool value)
|
||||
{
|
||||
return TweakFlag(F_HTMLOKTREE, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsGroup()
|
||||
{
|
||||
return (m_flags & F_ISGROUP) != 0;
|
||||
}
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetIsGroup(PRBool value)
|
||||
{
|
||||
return TweakFlag(F_ISGROUP, value);
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsDescendentsLoaded()
|
||||
{
|
||||
return (m_flags & F_DESCENDENTSLOADED) != 0;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::SetIsDescendentsLoaded(PRBool value)
|
||||
{
|
||||
PR_ASSERT(value); // No reason we'd ever unset this.
|
||||
TweakFlag(F_DESCENDENTSLOADED, PR_TRUE);
|
||||
nsMsgGroupRecord* child;
|
||||
for (child = m_children ; child ; child = child->m_sibling) {
|
||||
child->SetIsDescendentsLoaded(value);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRBool nsMsgGroupRecord::DoesNotExistOnServer()
|
||||
{
|
||||
return (m_flags & F_DOESNOTEXIST) != 0;
|
||||
}
|
||||
|
||||
int nsMsgGroupRecord::SetDoesNotExistOnServer(PRBool value)
|
||||
{
|
||||
if (value) // turn off group flag if doesn't exist on server.
|
||||
TweakFlag(F_ISGROUP, PR_FALSE);
|
||||
return TweakFlag(F_DOESNOTEXIST, value);
|
||||
}
|
||||
|
||||
int
|
||||
nsMsgGroupRecord::TweakFlag(PRUint32 flagbit, PRBool value)
|
||||
{
|
||||
if (value) {
|
||||
if (!(m_flags & flagbit)) {
|
||||
m_flags |= flagbit;
|
||||
if (flagbit & ~RUNTIMEFLAGS)
|
||||
m_flags |= F_DIRTY;
|
||||
return 1;
|
||||
}
|
||||
} else {
|
||||
if (m_flags & flagbit) {
|
||||
m_flags &= ~flagbit;
|
||||
if (flagbit & ~RUNTIMEFLAGS)
|
||||
m_flags |= F_DIRTY;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
PRInt32
|
||||
nsMsgGroupRecord::GetNumKids()
|
||||
{
|
||||
PRInt32 result = 0;
|
||||
nsMsgGroupRecord* child;
|
||||
for (child = m_children ; child ; child = child->m_sibling) {
|
||||
if (IsIMAPGroupRecord())
|
||||
result++;
|
||||
else
|
||||
if (child->m_flags & F_ISGROUP) result++;
|
||||
|
||||
if (!IsIMAPGroupRecord())
|
||||
result += child->GetNumKids();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
char*
|
||||
nsMsgGroupRecord::GetSaveString()
|
||||
{
|
||||
char* pretty = NULL;
|
||||
char* result = nsnull;
|
||||
|
||||
if (m_prettyname) {
|
||||
pretty = nsEscape(m_prettyname, url_XAlphas);
|
||||
if (!pretty) return NULL;
|
||||
}
|
||||
char* fullname = GetFullName();
|
||||
if (!fullname) return NULL; {
|
||||
long nAddTime;
|
||||
LL_L2I(nAddTime, m_addtime);
|
||||
result = PR_smprintf("%s,%s,%lx,%lx,%lx" MSG_LINEBREAK,
|
||||
fullname, pretty ? pretty : "",
|
||||
(long) (m_flags & ~RUNTIMEFLAGS),
|
||||
nAddTime,
|
||||
(long) m_uniqueId);
|
||||
}
|
||||
delete [] fullname;
|
||||
if (pretty) nsCRT::free(pretty);
|
||||
m_flags &= ~F_DIRTY;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
PRBool
|
||||
nsMsgGroupRecord::IsDirty()
|
||||
{
|
||||
return (m_flags & F_DIRTY) != 0;
|
||||
}
|
||||
|
||||
|
||||
PRInt32
|
||||
nsMsgGroupRecord::GetDepth()
|
||||
{
|
||||
PRInt32 result = 0;
|
||||
nsMsgGroupRecord* tmp = m_parent;
|
||||
while (tmp) {
|
||||
tmp = tmp->m_parent;
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
nsMsgGroupRecord*
|
||||
nsMsgGroupRecord::Create(nsMsgGroupRecord* parent, const char* saveline,
|
||||
PRInt32 savelinelength, PRInt32 fileoffset)
|
||||
{
|
||||
char* tmp;
|
||||
char* ptr;
|
||||
char* endptr;
|
||||
char* partname;
|
||||
char* prettyname;
|
||||
PRInt32 flags;
|
||||
PRInt32 addtime;
|
||||
PRInt32 uniqueid;
|
||||
nsMsgGroupRecord* result = NULL;
|
||||
|
||||
if (savelinelength < 0) savelinelength = PL_strlen(saveline);
|
||||
tmp = (char*) PR_Malloc(savelinelength + 1);
|
||||
if (!tmp) return NULL;
|
||||
PL_strncpy(tmp, saveline, savelinelength);
|
||||
tmp[savelinelength] = '\0';
|
||||
ptr = PL_strchr(tmp, ',');
|
||||
PR_ASSERT(ptr);
|
||||
if (!ptr) goto FAIL;
|
||||
*ptr++ = '\0';
|
||||
partname = PL_strrchr(tmp, '.');
|
||||
if (!partname) partname = tmp;
|
||||
else partname++;
|
||||
|
||||
#ifdef DEBUG_slowAndParanoid
|
||||
if (parent->m_partname) {
|
||||
char* parentname = parent->GetFullName();
|
||||
PR_ASSERT(partname > tmp && partname[-1] == '.');
|
||||
partname[-1] = '\0';
|
||||
PR_ASSERT(PL_strcmp(parentname, tmp) == 0);
|
||||
partname[-1] = '.';
|
||||
delete [] parentname;
|
||||
parentname = NULL;
|
||||
} else {
|
||||
PR_ASSERT(partname == tmp);
|
||||
}
|
||||
#endif
|
||||
|
||||
endptr = PL_strchr(ptr, ',');
|
||||
PR_ASSERT(endptr);
|
||||
if (!endptr) goto FAIL;
|
||||
*endptr++ = '\0';
|
||||
prettyname = nsUnescape(ptr);
|
||||
|
||||
ptr = endptr;
|
||||
endptr = PL_strchr(ptr, ',');
|
||||
PR_ASSERT(endptr);
|
||||
if (!endptr) goto FAIL;
|
||||
*endptr++ = '\0';
|
||||
flags = strtol(ptr, NULL, 16);
|
||||
|
||||
ptr = endptr;
|
||||
endptr = PL_strchr(ptr, ',');
|
||||
PR_ASSERT(endptr);
|
||||
if (!endptr) goto FAIL;
|
||||
*endptr++ = '\0';
|
||||
addtime = strtol(ptr, NULL, 16);
|
||||
|
||||
ptr = endptr;
|
||||
uniqueid = strtol(ptr, NULL, 16);
|
||||
|
||||
PRInt64 llAddtime;
|
||||
LL_I2L(llAddtime, addtime);
|
||||
result = Create(parent, partname, llAddtime, uniqueid, fileoffset);
|
||||
if (result) {
|
||||
PRBool maybeCategoryContainer = flags & F_CATCONT;
|
||||
flags &= ~F_CATCONT;
|
||||
result->m_flags = flags;
|
||||
if (maybeCategoryContainer)
|
||||
result->SetIsCategoryContainer(PR_TRUE);
|
||||
if (prettyname && *prettyname) result->SetPrettyName(prettyname);
|
||||
}
|
||||
|
||||
FAIL:
|
||||
PR_Free(tmp);
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
160
mozilla/mailnews/base/util/nsMsgGroupRecord.h
Normal file
160
mozilla/mailnews/base/util/nsMsgGroupRecord.h
Normal file
@@ -0,0 +1,160 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 class should only be used by the subscribe UI and by newshost.cpp.
|
||||
// And, well, a bit by the category code. Everyone else should use the stuff
|
||||
// in newshost.h.
|
||||
|
||||
#ifndef _nsMsgGroupRecord_h_
|
||||
#define _nsMsgGroupRecord_h__
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "prtypes.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
class nsIMAPGroupRecord;
|
||||
|
||||
class NS_MSG_BASE nsMsgGroupRecord {
|
||||
public:
|
||||
static nsMsgGroupRecord* Create(nsMsgGroupRecord* parent,
|
||||
const char* partname,
|
||||
PRInt64 m_addtime,
|
||||
PRInt32 uniqueid,
|
||||
PRInt32 fileoffset);
|
||||
static nsMsgGroupRecord* Create(nsMsgGroupRecord* parent,
|
||||
const char* saveline,
|
||||
PRInt32 savelinelength,
|
||||
PRInt32 fileoffset);
|
||||
|
||||
|
||||
virtual void InitializeSibling();
|
||||
virtual PRBool IsIMAPGroupRecord() { return PR_FALSE; }
|
||||
virtual nsIMAPGroupRecord *GetIMAPGroupRecord() { return 0; }
|
||||
|
||||
// This is just like PL_strcmp(), except it works on news group names.
|
||||
// A container groupname is always less than any contained groups.
|
||||
// So, "netscape.devs-client-technical" > "netscape.devs.directory", even
|
||||
// though PL_strcmp says otherwise. (YICK!)
|
||||
static int GroupNameCompare(const char* name1,
|
||||
const char* name2,
|
||||
char delimiter = '.',
|
||||
PRBool caseInsensitive = PR_FALSE);
|
||||
|
||||
|
||||
virtual ~nsMsgGroupRecord();
|
||||
|
||||
nsMsgGroupRecord* FindDescendant(const char* name);
|
||||
|
||||
nsMsgGroupRecord* GetParent() {return m_parent;}
|
||||
nsMsgGroupRecord* GetChildren() {return m_children;}
|
||||
nsMsgGroupRecord* GetSibling() {return m_sibling;}
|
||||
nsMsgGroupRecord* GetSiblingOrAncestorSibling();
|
||||
nsMsgGroupRecord* GetNextAlphabetic();
|
||||
|
||||
nsMsgGroupRecord* GetNextAlphabeticNoCategories();
|
||||
|
||||
const char* GetPartName() {return m_partname;}
|
||||
|
||||
// The resulting string must be free'd using delete[].
|
||||
char* GetFullName();
|
||||
|
||||
const char* GetPrettyName() {return m_prettyname;}
|
||||
int SetPrettyName(const char* prettyname);
|
||||
|
||||
PRInt64 GetAddTime() {return m_addtime;}
|
||||
|
||||
virtual PRBool IsCategory();
|
||||
virtual PRBool IsCategoryContainer();
|
||||
virtual int SetIsCategoryContainer(PRBool value);
|
||||
|
||||
nsMsgGroupRecord* GetCategoryContainer();
|
||||
|
||||
// Get/Set whether this is a virtual newsgroup.
|
||||
nsresult IsVirtual(PRBool *retval);
|
||||
nsresult SetIsVirtual(PRBool value);
|
||||
|
||||
// Get/Set whether this is really a newsgroup (and not just a container
|
||||
// for newsgroups).
|
||||
virtual PRBool IsGroup();
|
||||
int SetIsGroup(PRBool value);
|
||||
|
||||
PRBool IsDescendentsLoaded();
|
||||
int SetIsDescendentsLoaded(PRBool value);
|
||||
|
||||
PRBool IsExpanded();
|
||||
int SetIsExpanded(PRBool value);
|
||||
|
||||
PRBool IsHTMLOKGroup();
|
||||
int SetIsHTMLOKGroup(PRBool value);
|
||||
|
||||
PRBool IsHTMLOKTree();
|
||||
int SetIsHTMLOKTree(PRBool value);
|
||||
|
||||
PRBool NeedsExtraInfo();
|
||||
int SetNeedsExtraInfo(PRBool value);
|
||||
|
||||
PRBool DoesNotExistOnServer();
|
||||
int SetDoesNotExistOnServer(PRBool value);
|
||||
|
||||
PRInt32 GetUniqueID() {return m_uniqueId;}
|
||||
|
||||
PRInt32 GetFileOffset() {return m_fileoffset;}
|
||||
int SetFileOffset(PRInt32 value) {m_fileoffset = value; return 0;}
|
||||
|
||||
// Get the number of descendents (not including ourself) that are
|
||||
// really newsgroups.
|
||||
PRInt32 GetNumKids();
|
||||
|
||||
// Gets the string that represents this group in the save file. The
|
||||
// resulting string must be free'd with PR_Free().
|
||||
char* GetSaveString();
|
||||
|
||||
PRBool IsDirty(); // Whether this record has had changes made
|
||||
// to it. Cleared by calls to GetSaveString().
|
||||
|
||||
PRInt32 GetDepth(); // Returns how deep in the heirarchy we are.
|
||||
// Basically, the number of dots in the full
|
||||
// newsgroup name, plus 1.
|
||||
virtual char GetHierarchySeparator() { return '.'; }
|
||||
|
||||
protected:
|
||||
nsMsgGroupRecord(nsMsgGroupRecord* parent,
|
||||
const char* partname,
|
||||
PRInt64 m_addtime,
|
||||
PRInt32 uniqueid,
|
||||
PRInt32 fileoffset,
|
||||
char delimiter = '.');
|
||||
int TweakFlag(PRUint32 flagbit, PRBool value);
|
||||
char* SuckInName(char* ptr);
|
||||
|
||||
char* m_partname;
|
||||
char* m_prettyname;
|
||||
nsMsgGroupRecord* m_parent;
|
||||
nsMsgGroupRecord* m_children;
|
||||
nsMsgGroupRecord* m_sibling;
|
||||
PRUint32 m_flags;
|
||||
PRInt64 m_addtime;
|
||||
PRInt32 m_uniqueId;
|
||||
PRInt32 m_fileoffset;
|
||||
char m_delimiter;
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* _grec_h_ */
|
||||
363
mozilla/mailnews/base/util/nsMsgI18N.cpp
Normal file
363
mozilla/mailnews/base/util/nsMsgI18N.cpp
Normal file
@@ -0,0 +1,363 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
// as does this
|
||||
#define NS_IMPL_IDS
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsICharsetConverterManager.h"
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsIMimeConverter.h"
|
||||
#include "msgCore.h"
|
||||
#include "rosetta_mailnews.h"
|
||||
#include "nsMsgI18N.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsFileStream.h"
|
||||
#include "nsMsgMimeCID.h"
|
||||
#include "nsMimeTypes.h"
|
||||
#include "nsIEntityConverter.h"
|
||||
#include "nsISaveAsCharset.h"
|
||||
|
||||
static NS_DEFINE_CID(kPrefCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kCMimeConverterCID, NS_MIME_CONVERTER_CID);
|
||||
static NS_DEFINE_CID(kCharsetConverterManagerCID, NS_ICHARSETCONVERTERMANAGER_CID);
|
||||
static NS_DEFINE_CID(kEntityConverterCID, NS_ENTITYCONVERTER_CID);
|
||||
static NS_DEFINE_CID(kSaveAsCharsetCID, NS_SAVEASCHARSET_CID);
|
||||
|
||||
//
|
||||
// International functions necessary for composition
|
||||
//
|
||||
|
||||
// Convert an unicode string to a C string with a given charset.
|
||||
nsresult ConvertFromUnicode(const nsString& aCharset,
|
||||
const nsString& inString,
|
||||
char** outCString)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res);
|
||||
|
||||
if(NS_SUCCEEDED(res) && (nsnull != ccm)) {
|
||||
nsIUnicodeEncoder* encoder = nsnull;
|
||||
nsString convCharset;
|
||||
|
||||
// map to converter charset
|
||||
if (aCharset.EqualsIgnoreCase("us-ascii")) {
|
||||
convCharset.SetString("iso-8859-1");
|
||||
}
|
||||
else {
|
||||
convCharset = aCharset;
|
||||
}
|
||||
|
||||
// get an unicode converter
|
||||
res = ccm->GetUnicodeEncoder(&convCharset, &encoder);
|
||||
if(NS_SUCCEEDED(res) && (nsnull != encoder)) {
|
||||
PRUnichar *unichars = (PRUnichar *) inString.GetUnicode();
|
||||
PRInt32 unicharLength = inString.Length();
|
||||
PRInt32 dstLength;
|
||||
res = encoder->GetMaxLength(unichars, unicharLength, &dstLength);
|
||||
// allocale an output buffer
|
||||
*outCString = (char *) PR_Malloc(dstLength + 1);
|
||||
if (nsnull != *outCString) {
|
||||
PRInt32 oldUnicharLength = unicharLength;
|
||||
char *tempCString = *outCString;
|
||||
PRInt32 totalCLength = 0;
|
||||
while (1) {
|
||||
res = encoder->Convert(unichars, &unicharLength, tempCString, &dstLength);
|
||||
|
||||
// increment for destination
|
||||
tempCString += dstLength;
|
||||
totalCLength += dstLength;
|
||||
|
||||
// break: this is usually the case
|
||||
// source length <= zero and no error or unrecoverable error
|
||||
if (0 >= unicharLength || NS_ERROR_UENC_NOMAPPING != res) {
|
||||
break;
|
||||
}
|
||||
// could not map unicode to the destination charset, skip one unichar and continue
|
||||
// increment for source unicode, skip one unichar
|
||||
unichars += unicharLength + 1;
|
||||
oldUnicharLength -= (unicharLength + 1);
|
||||
unicharLength = oldUnicharLength;
|
||||
// estimate target length again
|
||||
(void) encoder->GetMaxLength(unichars, unicharLength, &dstLength);
|
||||
}
|
||||
(*outCString)[totalCLength] = '\0';
|
||||
}
|
||||
else {
|
||||
res = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_IF_RELEASE(encoder);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Convert a C string to an unicode string.
|
||||
nsresult ConvertToUnicode(const nsString& aCharset,
|
||||
const char* inCString,
|
||||
nsString& outString)
|
||||
{
|
||||
nsresult res;
|
||||
NS_WITH_SERVICE(nsICharsetConverterManager, ccm, kCharsetConverterManagerCID, &res);
|
||||
|
||||
if(NS_SUCCEEDED(res) && (nsnull != ccm)) {
|
||||
nsIUnicodeDecoder* decoder = nsnull;
|
||||
PRUnichar *unichars;
|
||||
PRInt32 unicharLength;
|
||||
nsString convCharset;
|
||||
|
||||
// map to converter charset
|
||||
if (aCharset.EqualsIgnoreCase("us-ascii")) {
|
||||
convCharset.SetString("iso-8859-1");
|
||||
}
|
||||
else {
|
||||
convCharset = aCharset;
|
||||
}
|
||||
// get an unicode converter
|
||||
res = ccm->GetUnicodeDecoder(&convCharset, &decoder);
|
||||
if(NS_SUCCEEDED(res) && (nsnull != decoder)) {
|
||||
PRInt32 srcLen = PL_strlen(inCString);
|
||||
res = decoder->GetMaxLength(inCString, srcLen, &unicharLength);
|
||||
// allocale an output buffer
|
||||
unichars = (PRUnichar *) PR_Malloc(unicharLength * sizeof(PRUnichar));
|
||||
if (unichars != nsnull) {
|
||||
// convert to unicode
|
||||
res = decoder->Convert(inCString, &srcLen, unichars, &unicharLength);
|
||||
outString.SetString(unichars, unicharLength);
|
||||
PR_Free(unichars);
|
||||
}
|
||||
else {
|
||||
res = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
NS_IF_RELEASE(decoder);
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Charset to be used for the internatl processing.
|
||||
const char *msgCompHeaderInternalCharset()
|
||||
{
|
||||
// UTF-8 is a super set of us-ascii.
|
||||
// We can use the same string manipulation methods as us-ascii without breaking non us-ascii characters.
|
||||
return "UTF-8";
|
||||
}
|
||||
|
||||
// MIME encoder, output string should be freed by PR_FREE
|
||||
char * nsMsgI18NEncodeMimePartIIStr(const char *header, const char *charset, PRBool bUseMime)
|
||||
{
|
||||
// No MIME, just duplicate the string.
|
||||
if (PR_FALSE == bUseMime) {
|
||||
return PL_strdup(header);
|
||||
}
|
||||
|
||||
char *encodedString = nsnull;
|
||||
nsIMimeConverter *converter;
|
||||
nsresult res = nsComponentManager::CreateInstance(kCMimeConverterCID, nsnull,
|
||||
nsCOMTypeInfo<nsIMimeConverter>::GetIID(), (void **)&converter);
|
||||
if (NS_SUCCEEDED(res) && nsnull != converter) {
|
||||
res = converter->EncodeMimePartIIStr_UTF8(header, charset, kMIME_ENCODED_WORD_SIZE, &encodedString);
|
||||
NS_RELEASE(converter);
|
||||
}
|
||||
return NS_SUCCEEDED(res) ? encodedString : nsnull;
|
||||
}
|
||||
|
||||
// MIME decoder
|
||||
nsresult nsMsgI18NDecodeMimePartIIStr(const nsString& header, nsString& charset, nsString& decodedString)
|
||||
{
|
||||
nsIMimeConverter *converter;
|
||||
nsresult res = nsComponentManager::CreateInstance(kCMimeConverterCID, nsnull,
|
||||
nsCOMTypeInfo<nsIMimeConverter>::GetIID(), (void **)&converter);
|
||||
if (NS_SUCCEEDED(res) && nsnull != converter) {
|
||||
res = converter->DecodeMimePartIIStr(header, charset, decodedString);
|
||||
NS_RELEASE(converter);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
// Get a default mail character set.
|
||||
char * nsMsgI18NGetDefaultMailCharset()
|
||||
{
|
||||
nsresult res = NS_OK;
|
||||
char * retVal = nsnull;
|
||||
NS_WITH_SERVICE(nsIPref, prefs, kPrefCID, &res);
|
||||
if (nsnull != prefs && NS_SUCCEEDED(res))
|
||||
{
|
||||
char *prefValue;
|
||||
res = prefs->CopyCharPref("intl.character_set_name", &prefValue);
|
||||
|
||||
if (NS_SUCCEEDED(res))
|
||||
{
|
||||
//TODO: map to mail charset (e.g. Shift_JIS -> ISO-2022-JP) bug#3941.
|
||||
retVal = prefValue;
|
||||
}
|
||||
else
|
||||
retVal = PL_strdup("iso-8859-1");
|
||||
}
|
||||
|
||||
return (nsnull != retVal) ? retVal : PL_strdup("iso-8859-1");
|
||||
}
|
||||
|
||||
// Return True if a charset is stateful (e.g. JIS).
|
||||
PRBool nsMsgI18Nstateful_charset(const char *charset)
|
||||
{
|
||||
//TODO: use charset manager's service
|
||||
return (PL_strcasecmp(charset, "iso-2022-jp") == 0);
|
||||
}
|
||||
|
||||
// Check 7bit in a given buffer.
|
||||
// This is expensive (both memory and performance).
|
||||
// The check would be very simple if applied to an unicode text (e.g. nsString or utf-8).
|
||||
// Possible optimazaion is to search ESC(0x1B) in case of iso-2022-jp and iso-2022-kr.
|
||||
// Or convert and check line by line.
|
||||
PRBool nsMsgI18N7bit_data_part(const char *charset, const char *inString, const PRUint32 size)
|
||||
{
|
||||
char *aCString;
|
||||
nsString aCharset(charset);
|
||||
nsString outString;
|
||||
nsresult res;
|
||||
|
||||
aCString = (char *) PR_Malloc(size + 1);
|
||||
if (nsnull != aCString) {
|
||||
PL_strncpy(aCString, inString, size); // make a C string
|
||||
res = ConvertToUnicode(aCharset, aCString, outString);
|
||||
PR_Free(aCString);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
for (PRInt32 i = 0; i < outString.Length(); i++) {
|
||||
if (outString.CharAt(i) > 127) {
|
||||
return PR_FALSE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return PR_TRUE; // all 7 bit
|
||||
}
|
||||
|
||||
// Simple parser to parse META charset.
|
||||
// It only supports the case when the description is within one line.
|
||||
const char *
|
||||
nsMsgI18NParseMetaCharset(nsFileSpec* fileSpec)
|
||||
{
|
||||
static char charset[65];
|
||||
char buffer[512];
|
||||
nsInputFileStream fileStream(*fileSpec);
|
||||
|
||||
*charset = '\0';
|
||||
|
||||
while (!fileStream.eof() && !fileStream.failed() &&
|
||||
fileStream.is_open()) {
|
||||
fileStream.readline(buffer, 512);
|
||||
if (*buffer == CR || *buffer == LF || *buffer == 0)
|
||||
continue;
|
||||
|
||||
for (int i = 0; i < (int)PL_strlen(buffer); i++) {
|
||||
buffer[i] = toupper(buffer[i]);
|
||||
}
|
||||
|
||||
if (PL_strstr(buffer, "/HEAD"))
|
||||
break;
|
||||
|
||||
if (PL_strstr(buffer, "META") &&
|
||||
PL_strstr(buffer, "HTTP-EQUIV") &&
|
||||
PL_strstr(buffer, "CONTENT-TYPE") &&
|
||||
PL_strstr(buffer, "CHARSET")
|
||||
)
|
||||
{
|
||||
char *cp = PL_strstr(PL_strstr(buffer, "CHARSET"), "=") + 1;
|
||||
char seps[] = " \"\'";
|
||||
char *token;
|
||||
char* newStr;
|
||||
token = nsCRT::strtok(cp, seps, &newStr);
|
||||
if (token != NULL)
|
||||
{
|
||||
PL_strcpy(charset, token);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return charset;
|
||||
}
|
||||
|
||||
nsresult nsMsgI18NConvertToEntity(const nsString& inString, nsString* outString)
|
||||
{
|
||||
nsresult res;
|
||||
|
||||
outString->SetString("");
|
||||
nsCOMPtr <nsIEntityConverter> entityConv;
|
||||
res = nsComponentManager::CreateInstance(kEntityConverterCID, NULL,
|
||||
nsIEntityConverter::GetIID(), getter_AddRefs(entityConv));
|
||||
if(NS_SUCCEEDED(res)) {
|
||||
PRUnichar *entities = NULL;
|
||||
res = entityConv->ConvertToEntities(inString.GetUnicode(), nsIEntityConverter::html40Latin1, &entities);
|
||||
if (NS_SUCCEEDED(res) && (NULL != entities)) {
|
||||
outString->SetString(entities);
|
||||
nsAllocator::Free(entities);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char *charset, const PRUnichar* inString, char** outString)
|
||||
{
|
||||
NS_ASSERTION(contentType, "null ptr- contentType");
|
||||
NS_ASSERTION(charset, "null ptr- charset");
|
||||
NS_ASSERTION(outString, "null ptr- outString");
|
||||
if(!contentType || !charset || !outString)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*outString = NULL;
|
||||
|
||||
PRBool bTEXT_HTML = PR_FALSE;
|
||||
nsresult res;
|
||||
|
||||
if (!nsCRT::strcasecmp(contentType, TEXT_HTML)) {
|
||||
bTEXT_HTML = PR_TRUE;
|
||||
}
|
||||
else if (nsCRT::strcasecmp(contentType, TEXT_PLAIN)) {
|
||||
return NS_ERROR_ILLEGAL_VALUE; // not supported type
|
||||
}
|
||||
|
||||
nsCOMPtr <nsISaveAsCharset> aConv; // charset converter plus entity, NCR generation
|
||||
res = nsComponentManager::CreateInstance(kSaveAsCharsetCID, NULL,
|
||||
nsISaveAsCharset::GetIID(), getter_AddRefs(aConv));
|
||||
if(NS_SUCCEEDED(res)) {
|
||||
// attribute:
|
||||
// html text - charset conv then fallback to entity or NCR
|
||||
// plain text - charset conv then fallback to '?'
|
||||
res = aConv->Init(charset,
|
||||
bTEXT_HTML ?
|
||||
nsISaveAsCharset::attr_EntityAfterCharsetConv + nsISaveAsCharset::attr_FallbackDecimalNCR :
|
||||
nsISaveAsCharset::attr_plainTextDefault + nsISaveAsCharset::attr_FallbackQuestionMark,
|
||||
nsIEntityConverter::html40);
|
||||
if (NS_SUCCEEDED(res)) {
|
||||
res = aConv->Convert(inString, outString);
|
||||
}
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
// RICHIE - not sure about this one?? need to see what it did in the old
|
||||
// world.
|
||||
char *
|
||||
nsMsgI18NGetAcceptLanguage(void)
|
||||
{
|
||||
return "en";
|
||||
}
|
||||
49
mozilla/mailnews/base/util/nsMsgI18N.h
Normal file
49
mozilla/mailnews/base/util/nsMsgI18N.h
Normal file
@@ -0,0 +1,49 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 _nsMsgI18N_H_
|
||||
#define _nsMsgI18N_H_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "msgCore.h"
|
||||
|
||||
|
||||
NS_MSG_BASE char *nsMsgI18NEncodeMimePartIIStr(const char *header, const char *charset, PRBool bUseMime);
|
||||
NS_MSG_BASE PRBool nsMsgI18Nstateful_charset(const char *charset);
|
||||
NS_MSG_BASE PRBool nsMsgI18N7bit_data_part(const char *charset, const char *string, const PRUint32 size);
|
||||
NS_MSG_BASE char *nsMsgI18NGetAcceptLanguage(void);
|
||||
|
||||
NS_MSG_BASE const char *msgCompHeaderInternalCharset(void);
|
||||
|
||||
NS_MSG_BASE char * nsMsgI18NGetDefaultMailCharset(void);
|
||||
NS_MSG_BASE nsresult ConvertFromUnicode(const nsString& aCharset,
|
||||
const nsString& inString,
|
||||
char** outCString);
|
||||
NS_MSG_BASE nsresult ConvertToUnicode(const nsString& aCharset,
|
||||
const char* inCString,
|
||||
nsString& outString);
|
||||
|
||||
NS_MSG_BASE nsresult nsMsgI18NDecodeMimePartIIStr(const nsString& header, nsString& charset, nsString& decodedString);
|
||||
|
||||
NS_MSG_BASE const char *nsMsgI18NParseMetaCharset(nsFileSpec* fileSpec);
|
||||
|
||||
NS_MSG_BASE nsresult nsMsgI18NConvertToEntity(const nsString& inString, nsString* outString);
|
||||
|
||||
NS_MSG_BASE nsresult nsMsgI18NSaveAsCharset(const char* contentType, const char* charset, const PRUnichar* inString, char** outString);
|
||||
|
||||
#endif /* _nsMsgI18N_H_ */
|
||||
356
mozilla/mailnews/base/util/nsMsgIdentity.cpp
Normal file
356
mozilla/mailnews/base/util/nsMsgIdentity.cpp
Normal file
@@ -0,0 +1,356 @@
|
||||
/* -*- 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 "msgCore.h" // for pre-compiled headers
|
||||
#include "nsMsgIdentity.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS2(nsMsgIdentity,
|
||||
nsIMsgIdentity,
|
||||
nsIShutdownListener)
|
||||
|
||||
nsMsgIdentity::nsMsgIdentity():
|
||||
m_signature(0),
|
||||
m_vCard(0),
|
||||
m_identityKey(0),
|
||||
m_prefs(0)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsMsgIdentity::~nsMsgIdentity()
|
||||
{
|
||||
PR_FREEIF(m_identityKey);
|
||||
if (m_prefs) nsServiceManager::ReleaseService(kPrefServiceCID,
|
||||
m_prefs,
|
||||
nsnull);
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::getPrefService()
|
||||
{
|
||||
if (m_prefs) return NS_OK;
|
||||
return nsServiceManager::GetService(kPrefServiceCID,
|
||||
nsCOMTypeInfo<nsIPref>::GetIID(),
|
||||
(nsISupports**)&m_prefs,
|
||||
this);
|
||||
}
|
||||
|
||||
|
||||
/* called if the prefs service goes offline */
|
||||
NS_IMETHODIMP
|
||||
nsMsgIdentity::OnShutdown(const nsCID& aClass, nsISupports *service)
|
||||
{
|
||||
if (aClass.Equals(kPrefServiceCID)) {
|
||||
if (m_prefs) nsServiceManager::ReleaseService(kPrefServiceCID, m_prefs);
|
||||
m_prefs = nsnull;
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* accessors for pulling values directly out of preferences
|
||||
* instead of member variables, etc
|
||||
*/
|
||||
|
||||
/* convert an identity key and preference name
|
||||
to mail.identity.<identityKey>.<prefName>
|
||||
*/
|
||||
char *
|
||||
nsMsgIdentity::getPrefName(const char *identityKey,
|
||||
const char *prefName)
|
||||
{
|
||||
return PR_smprintf("mail.identity.%s.%s", identityKey, prefName);
|
||||
}
|
||||
|
||||
// this will be slightly faster than the above, and allows
|
||||
// the "default" identity preference root to be set in one place
|
||||
char *
|
||||
nsMsgIdentity::getDefaultPrefName(const char *fullPrefName)
|
||||
{
|
||||
return PR_smprintf("mail.identity.default.%s", fullPrefName);
|
||||
}
|
||||
|
||||
/* The following are equivalent to the nsIPref's Get/CopyXXXPref
|
||||
except they construct the preference name with the above function
|
||||
*/
|
||||
nsresult
|
||||
nsMsgIdentity::getBoolPref(const char *prefname,
|
||||
PRBool *val)
|
||||
{
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *fullPrefName = getPrefName(m_identityKey, prefname);
|
||||
rv = m_prefs->GetBoolPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
rv = getDefaultBoolPref(prefname, val);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::getDefaultBoolPref(const char *prefname,
|
||||
PRBool *val) {
|
||||
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *fullPrefName = getDefaultPrefName(prefname);
|
||||
rv = m_prefs->GetBoolPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*val = PR_FALSE;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::setBoolPref(const char *prefname,
|
||||
PRBool val)
|
||||
{
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *prefName = getPrefName(m_identityKey, prefname);
|
||||
rv = m_prefs->SetBoolPref(prefName, val);
|
||||
PR_Free(prefName);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::getCharPref(const char *prefname,
|
||||
char **val)
|
||||
{
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *fullPrefName = getPrefName(m_identityKey, prefname);
|
||||
rv = m_prefs->CopyCharPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
rv = getDefaultCharPref(prefname, val);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::getDefaultCharPref(const char *prefname,
|
||||
char **val)
|
||||
{
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *fullPrefName = getDefaultPrefName(prefname);
|
||||
rv = m_prefs->CopyCharPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*val = nsnull; // null is ok to return here
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::setCharPref(const char *prefname,
|
||||
const char *val)
|
||||
{
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_OK;
|
||||
char *prefName = getPrefName(m_identityKey, prefname);
|
||||
if (val)
|
||||
rv = m_prefs->SetCharPref(prefName, val);
|
||||
else
|
||||
m_prefs->ClearUserPref(prefName);
|
||||
PR_Free(prefName);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::getIntPref(const char *prefname,
|
||||
PRInt32 *val)
|
||||
{
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *fullPrefName = getPrefName(m_identityKey, prefname);
|
||||
rv = m_prefs->GetIntPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
rv = getDefaultIntPref(prefname, val);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::getDefaultIntPref(const char *prefname,
|
||||
PRInt32 *val) {
|
||||
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *fullPrefName = getDefaultPrefName(prefname);
|
||||
rv = m_prefs->GetIntPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*val = 0;
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::setIntPref(const char *prefname,
|
||||
PRInt32 val)
|
||||
{
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *prefName = getPrefName(m_identityKey, prefname);
|
||||
rv = m_prefs->SetIntPref(prefName, val);
|
||||
PR_Free(prefName);
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::SetKey(const char* identityKey)
|
||||
{
|
||||
PR_FREEIF(m_identityKey);
|
||||
m_identityKey = PL_strdup(identityKey);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIdentity::GetIdentityName(char **idName) {
|
||||
if (!idName) return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*idName = nsnull;
|
||||
nsresult rv = getCharPref("identityName",idName);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// there's probably a better way of doing this
|
||||
// thats unicode friendly?
|
||||
if (!(*idName)) {
|
||||
nsXPIDLCString fullName;
|
||||
rv = GetFullName(getter_Copies(fullName));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsXPIDLCString email;
|
||||
rv = GetEmail(getter_Copies(email));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*idName = PR_smprintf("%s <%s>", (const char*)fullName,
|
||||
(const char*)email);
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgIdentity::SetIdentityName(const char *idName) {
|
||||
return setCharPref("identityName", idName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIdentity::ToString(PRUnichar **aResult)
|
||||
{
|
||||
nsString idname("[nsIMsgIdentity: ");
|
||||
idname += m_identityKey;
|
||||
idname += "]";
|
||||
|
||||
*aResult = idname.ToNewUnicode();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* Identity attribute accessors */
|
||||
|
||||
// XXX - these are a COM objects, use NS_ADDREF
|
||||
//NS_IMPL_GETSET(nsMsgIdentity, Signature, nsIMsgSignature*, m_signature);
|
||||
NS_IMETHODIMP
|
||||
nsMsgIdentity::GetSignature(nsIFileSpec **sig) {
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
char *prefName = getPrefName(m_identityKey, "sig_file");
|
||||
rv = m_prefs->GetFilePref(prefName, sig);
|
||||
if (NS_FAILED(rv))
|
||||
*sig = nsnull;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIdentity::SetSignature(nsIFileSpec *sig)
|
||||
{
|
||||
|
||||
nsresult rv = getPrefService();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = NS_OK;
|
||||
char *prefName = getPrefName(m_identityKey, "sig_file");
|
||||
if (sig)
|
||||
rv = m_prefs->SetFilePref(NS_CONST_CAST(const char*,prefName), sig,
|
||||
PR_FALSE);
|
||||
/*
|
||||
else
|
||||
m_prefs->ClearFilePref(prefName);
|
||||
*/
|
||||
PR_Free(prefName);
|
||||
return rv;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMPL_GETSET(nsMsgIdentity, VCard, nsIMsgVCard*, m_vCard);
|
||||
|
||||
NS_IMPL_GETTER_STR(nsMsgIdentity::GetKey, m_identityKey);
|
||||
|
||||
NS_IMPL_IDPREF_STR(FullName, "fullName");
|
||||
NS_IMPL_IDPREF_STR(Email, "useremail");
|
||||
NS_IMPL_IDPREF_STR(ReplyTo, "reply_to");
|
||||
NS_IMPL_IDPREF_STR(Organization, "organization");
|
||||
NS_IMPL_IDPREF_BOOL(ComposeHtml, "compose_html");
|
||||
NS_IMPL_IDPREF_BOOL(AttachVCard, "attach_vcard");
|
||||
NS_IMPL_IDPREF_BOOL(AttachSignature, "attach_signature");
|
||||
|
||||
NS_IMPL_IDPREF_BOOL(DoFcc, "fcc");
|
||||
NS_IMPL_IDPREF_STR(FccFolder, "fcc_folder");
|
||||
|
||||
NS_IMPL_IDPREF_BOOL(BccSelf, "bcc_self");
|
||||
NS_IMPL_IDPREF_BOOL(BccOthers, "bcc_other");
|
||||
NS_IMPL_IDPREF_STR (BccList, "bcc_other_list");
|
||||
|
||||
NS_IMPL_IDPREF_STR (DraftFolder, "draft_folder");
|
||||
NS_IMPL_IDPREF_STR (StationaryFolder, "stationary_folder");
|
||||
NS_IMPL_IDPREF_STR (JunkMailFolder, "spam_folder");
|
||||
|
||||
|
||||
110
mozilla/mailnews/base/util/nsMsgIdentity.h
Normal file
110
mozilla/mailnews/base/util/nsMsgIdentity.h
Normal file
@@ -0,0 +1,110 @@
|
||||
/* -*- 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 nsMsgIdentity_h___
|
||||
#define nsMsgIdentity_h___
|
||||
|
||||
#include "nsIMsgIdentity.h"
|
||||
#include "nsIPref.h"
|
||||
#include "msgCore.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// an identity is an object designed to encapsulate all the information we need
|
||||
// to know about a user identity. I expect this interface to grow and change a lot
|
||||
// as we flesh out our thoughts on multiple identities and what properties go into
|
||||
// these identities.
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
class NS_MSG_BASE nsMsgIdentity : public nsIMsgIdentity,
|
||||
public nsIShutdownListener
|
||||
{
|
||||
public:
|
||||
nsMsgIdentity();
|
||||
virtual ~nsMsgIdentity();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGIDENTITY
|
||||
|
||||
// nsIShutdownListener
|
||||
|
||||
NS_IMETHOD OnShutdown(const nsCID& aClass, nsISupports *service);
|
||||
|
||||
private:
|
||||
nsIMsgSignature* m_signature;
|
||||
nsIMsgVCard* m_vCard;
|
||||
char *m_identityKey;
|
||||
nsIPref *m_prefs;
|
||||
|
||||
protected:
|
||||
nsresult getPrefService();
|
||||
char *getPrefName(const char *identityKey, const char *pref);
|
||||
char *getDefaultPrefName(const char *pref);
|
||||
nsresult getCharPref(const char *pref, char **);
|
||||
nsresult getDefaultCharPref(const char *pref, char **);
|
||||
nsresult setCharPref(const char *pref, const char *);
|
||||
|
||||
nsresult getBoolPref(const char *pref, PRBool *);
|
||||
nsresult getDefaultBoolPref(const char *pref, PRBool *);
|
||||
nsresult setBoolPref(const char *pref, PRBool);
|
||||
|
||||
nsresult getIntPref(const char *pref, PRInt32 *);
|
||||
nsresult getDefaultIntPref(const char *pref, PRInt32 *);
|
||||
nsresult setIntPref(const char *pref, PRInt32);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#define NS_IMPL_IDPREF_STR(_postfix, _prefname) \
|
||||
NS_IMETHODIMP \
|
||||
nsMsgIdentity::Get##_postfix(char **retval) \
|
||||
{ \
|
||||
return getCharPref(_prefname, retval); \
|
||||
} \
|
||||
NS_IMETHODIMP \
|
||||
nsMsgIdentity::Set##_postfix(const char *value) \
|
||||
{ \
|
||||
return setCharPref(_prefname, value);\
|
||||
}
|
||||
|
||||
#define NS_IMPL_IDPREF_BOOL(_postfix, _prefname)\
|
||||
NS_IMETHODIMP \
|
||||
nsMsgIdentity::Get##_postfix(PRBool *retval) \
|
||||
{ \
|
||||
return getBoolPref(_prefname, retval); \
|
||||
} \
|
||||
NS_IMETHODIMP \
|
||||
nsMsgIdentity::Set##_postfix(PRBool value) \
|
||||
{ \
|
||||
return setBoolPref(_prefname, value); \
|
||||
}
|
||||
|
||||
#define NS_IMPL_IDPREF_INT(_postfix, _prefname) \
|
||||
NS_IMETHODIMP \
|
||||
nsMsgIdentity::Get##_postfix(PRInt32 *retval) \
|
||||
{ \
|
||||
return getIntPref(_prefname, retval); \
|
||||
} \
|
||||
NS_IMETHODIMP \
|
||||
nsMsgIdentity::Set##_postfix(PRInt32 value) \
|
||||
{ \
|
||||
return setIntPref(_prefname, value); \
|
||||
}
|
||||
|
||||
|
||||
#endif /* nsMsgIdentity_h___ */
|
||||
603
mozilla/mailnews/base/util/nsMsgIncomingServer.cpp
Normal file
603
mozilla/mailnews/base/util/nsMsgIncomingServer.cpp
Normal file
@@ -0,0 +1,603 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 "nsMsgIncomingServer.h"
|
||||
#include "nscore.h"
|
||||
#include "nsCom.h"
|
||||
#include "plstr.h"
|
||||
#include "prmem.h"
|
||||
#include "prprf.h"
|
||||
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsIPref.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMsgFolder.h"
|
||||
#include "nsIMsgFolderCache.h"
|
||||
#include "nsIMsgFolderCacheElement.h"
|
||||
#include "nsINetSupportDialogService.h"
|
||||
#include "nsIPrompt.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsIRDFService.h"
|
||||
#include "nsIMsgProtocolInfo.h"
|
||||
#include "nsRDFCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kPrefServiceCID, NS_PREF_CID);
|
||||
static NS_DEFINE_CID(kNetSupportDialogCID, NS_NETSUPPORTDIALOG_CID);
|
||||
static NS_DEFINE_CID(kRDFServiceCID, NS_RDFSERVICE_CID);
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsMsgIncomingServer);
|
||||
|
||||
nsMsgIncomingServer::nsMsgIncomingServer():
|
||||
m_prefs(0),
|
||||
m_serverKey(0),
|
||||
m_rootFolder(0)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsMsgIncomingServer);
|
||||
|
||||
NS_INIT_REFCNT();
|
||||
m_serverBusy = PR_FALSE;
|
||||
m_password = "";
|
||||
}
|
||||
|
||||
nsMsgIncomingServer::~nsMsgIncomingServer()
|
||||
{
|
||||
|
||||
MOZ_COUNT_DTOR(nsMsgIncomingServer);
|
||||
|
||||
if (m_prefs) nsServiceManager::ReleaseService(kPrefServiceCID,
|
||||
m_prefs,
|
||||
nsnull);
|
||||
PR_FREEIF(m_serverKey)
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS1(nsMsgIncomingServer, nsIMsgIncomingServer)
|
||||
|
||||
NS_IMPL_GETSET(nsMsgIncomingServer, ServerBusy, PRBool, m_serverBusy)
|
||||
NS_IMPL_GETTER_STR(nsMsgIncomingServer::GetKey, m_serverKey)
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::SetKey(const char * serverKey)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// in order to actually make use of the key, we need the prefs
|
||||
if (!m_prefs)
|
||||
rv = nsServiceManager::GetService(kPrefServiceCID,
|
||||
nsCOMTypeInfo<nsIPref>::GetIID(),
|
||||
(nsISupports**)&m_prefs);
|
||||
|
||||
PR_FREEIF(m_serverKey);
|
||||
m_serverKey = PL_strdup(serverKey);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::SetRootFolder(nsIFolder * aRootFolder)
|
||||
{
|
||||
m_rootFolder = aRootFolder;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetRootFolder(nsIFolder * *aRootFolder)
|
||||
{
|
||||
if (!aRootFolder)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
if (m_rootFolder) {
|
||||
*aRootFolder = m_rootFolder;
|
||||
NS_ADDREF(*aRootFolder);
|
||||
} else {
|
||||
nsresult rv = CreateRootFolder();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aRootFolder = m_rootFolder;
|
||||
NS_IF_ADDREF(*aRootFolder);
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::PerformBiff()
|
||||
{
|
||||
//This had to be implemented in the derived class, but in case someone doesn't implement it
|
||||
//just return not implemented.
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgIncomingServer::WriteToFolderCache(nsIMsgFolderCache *folderCache)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (m_rootFolder)
|
||||
{
|
||||
nsCOMPtr <nsIMsgFolder> msgFolder = do_QueryInterface(m_rootFolder, &rv);
|
||||
if (NS_SUCCEEDED(rv) && msgFolder)
|
||||
rv = msgFolder->WriteToFolderCache(folderCache);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::CloseCachedConnections()
|
||||
{
|
||||
// derived class should override if they cache connections.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetServerURI(char **)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::CreateRootFolder()
|
||||
{
|
||||
nsresult rv;
|
||||
// get the URI from the incoming server
|
||||
nsXPIDLCString serverUri;
|
||||
rv = GetServerURI(getter_Copies(serverUri));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
NS_WITH_SERVICE(nsIRDFService, rdf,
|
||||
kRDFServiceCID, &rv);
|
||||
|
||||
// get the corresponding RDF resource
|
||||
// RDF will create the server resource if it doesn't already exist
|
||||
nsCOMPtr<nsIRDFResource> serverResource;
|
||||
rv = rdf->GetResource(serverUri, getter_AddRefs(serverResource));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
// make incoming server know about its root server folder so we
|
||||
// can find sub-folders given an incoming server.
|
||||
m_rootFolder = do_QueryInterface(serverResource, &rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
char *
|
||||
nsMsgIncomingServer::getPrefName(const char *serverKey,
|
||||
const char *fullPrefName)
|
||||
{
|
||||
return PR_smprintf("mail.server.%s.%s", serverKey, fullPrefName);
|
||||
}
|
||||
|
||||
// this will be slightly faster than the above, and allows
|
||||
// the "default" server preference root to be set in one place
|
||||
char *
|
||||
nsMsgIncomingServer::getDefaultPrefName(const char *fullPrefName)
|
||||
{
|
||||
return PR_smprintf("mail.server.default.%s", fullPrefName);
|
||||
}
|
||||
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::GetBoolValue(const char *prefname,
|
||||
PRBool *val)
|
||||
{
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
nsresult rv = m_prefs->GetBoolPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
rv = getDefaultBoolPref(prefname, val);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::getDefaultBoolPref(const char *prefname,
|
||||
PRBool *val) {
|
||||
|
||||
char *fullPrefName = getDefaultPrefName(prefname);
|
||||
nsresult rv = m_prefs->GetBoolPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*val = PR_FALSE;
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::SetBoolValue(const char *prefname,
|
||||
PRBool val)
|
||||
{
|
||||
nsresult rv;
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
|
||||
PRBool defaultValue;
|
||||
rv = getDefaultBoolPref(prefname, &defaultValue);
|
||||
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
val == defaultValue)
|
||||
m_prefs->ClearUserPref(fullPrefName);
|
||||
else
|
||||
rv = m_prefs->SetBoolPref(fullPrefName, val);
|
||||
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::GetIntValue(const char *prefname,
|
||||
PRInt32 *val)
|
||||
{
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
nsresult rv = m_prefs->GetIntPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
rv = getDefaultIntPref(prefname, val);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::GetFileValue(const char* prefname,
|
||||
nsIFileSpec **spec)
|
||||
{
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
nsresult rv = m_prefs->GetFilePref(fullPrefName, spec);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::SetFileValue(const char* prefname,
|
||||
nsIFileSpec *spec)
|
||||
{
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
nsresult rv = m_prefs->SetFilePref(fullPrefName, spec, PR_FALSE);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::getDefaultIntPref(const char *prefname,
|
||||
PRInt32 *val) {
|
||||
|
||||
char *fullPrefName = getDefaultPrefName(prefname);
|
||||
nsresult rv = m_prefs->GetIntPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*val = 0;
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::SetIntValue(const char *prefname,
|
||||
PRInt32 val)
|
||||
{
|
||||
nsresult rv;
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
|
||||
PRInt32 defaultVal;
|
||||
rv = getDefaultIntPref(prefname, &defaultVal);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && defaultVal == val)
|
||||
m_prefs->ClearUserPref(fullPrefName);
|
||||
else
|
||||
rv = m_prefs->SetIntPref(fullPrefName, val);
|
||||
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::GetCharValue(const char *prefname,
|
||||
char **val)
|
||||
{
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
nsresult rv = m_prefs->CopyCharPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv))
|
||||
rv = getDefaultCharPref(prefname, val);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::getDefaultCharPref(const char *prefname,
|
||||
char **val) {
|
||||
|
||||
char *fullPrefName = getDefaultPrefName(prefname);
|
||||
nsresult rv = m_prefs->CopyCharPref(fullPrefName, val);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
if (NS_FAILED(rv)) {
|
||||
*val = nsnull; // null is ok to return here
|
||||
rv = NS_OK;
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
nsMsgIncomingServer::SetCharValue(const char *prefname,
|
||||
const char * val)
|
||||
{
|
||||
nsresult rv;
|
||||
char *fullPrefName = getPrefName(m_serverKey, prefname);
|
||||
|
||||
if (!val) {
|
||||
m_prefs->ClearUserPref(fullPrefName);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
char *defaultVal=nsnull;
|
||||
rv = getDefaultCharPref(prefname, &defaultVal);
|
||||
|
||||
if (NS_SUCCEEDED(rv) &&
|
||||
PL_strcmp(defaultVal, val) == 0)
|
||||
m_prefs->ClearUserPref(fullPrefName);
|
||||
else
|
||||
rv = m_prefs->SetCharPref(fullPrefName, val);
|
||||
|
||||
PR_FREEIF(defaultVal);
|
||||
PR_Free(fullPrefName);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// pretty name is the display name to show to the user
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetPrettyName(PRUnichar **retval) {
|
||||
|
||||
char *val=nsnull;
|
||||
nsresult rv = GetCharValue("name", &val);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsString prettyName;
|
||||
|
||||
// if there's no name, then just return the hostname
|
||||
if (val) {
|
||||
prettyName = val;
|
||||
} else {
|
||||
|
||||
nsXPIDLCString username;
|
||||
rv = GetUsername(getter_Copies(username));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
if ((const char*)username &&
|
||||
PL_strcmp((const char*)username, "")!=0) {
|
||||
prettyName = username;
|
||||
prettyName += " on ";
|
||||
}
|
||||
|
||||
nsXPIDLCString hostname;
|
||||
rv = GetHostName(getter_Copies(hostname));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
|
||||
prettyName += hostname;
|
||||
}
|
||||
|
||||
*retval = prettyName.ToNewUnicode();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::SetPrettyName(const PRUnichar *value) {
|
||||
// this is lossy. Not sure what to do.
|
||||
nsCString str(value);
|
||||
return SetCharValue("name", str.GetBuffer());
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::ToString(PRUnichar** aResult) {
|
||||
nsString servername("[nsIMsgIncomingServer: ");
|
||||
servername += m_serverKey;
|
||||
servername += "]";
|
||||
|
||||
*aResult = servername.ToNewUnicode();
|
||||
NS_ASSERTION(*aResult, "no server name!");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgIncomingServer::SetPassword(const char * aPassword)
|
||||
{
|
||||
// if remember password is turned on, write the password to preferences
|
||||
// otherwise, just set the password so we remember it for the rest of the current
|
||||
// session.
|
||||
|
||||
PRBool rememberPassword = PR_FALSE;
|
||||
GetRememberPassword(&rememberPassword);
|
||||
|
||||
if (rememberPassword)
|
||||
{
|
||||
SetPrefPassword((char *) aPassword);
|
||||
}
|
||||
|
||||
m_password = aPassword;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgIncomingServer::GetPassword(char ** aPassword)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
PRBool rememberPassword = PR_FALSE;
|
||||
// okay, here's the scoop for this messs...
|
||||
// (1) if we have a password already, go ahead and use it!
|
||||
// (2) if remember password is turned on, try reading in from the prefs and if we have one, go ahead
|
||||
// and use it
|
||||
// (3) otherwise prompt the user for a password and then remember that password in the server
|
||||
|
||||
if (m_password.IsEmpty())
|
||||
{
|
||||
|
||||
// case (2)
|
||||
GetRememberPassword(&rememberPassword);
|
||||
if (rememberPassword)
|
||||
{
|
||||
nsXPIDLCString password;
|
||||
GetPrefPassword(getter_Copies(password));
|
||||
m_password = password;
|
||||
}
|
||||
}
|
||||
|
||||
*aPassword = m_password.ToNewCString();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetPasswordWithUI(const PRUnichar * aPromptMessage, char **aPassword)
|
||||
{
|
||||
|
||||
nsXPIDLCString prefvalue;
|
||||
GetPassword(getter_Copies(prefvalue));
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
if (m_password.IsEmpty()) {
|
||||
// prompt the user for the password
|
||||
NS_WITH_SERVICE(nsIPrompt, dialog, kNetSupportDialogCID, &rv);
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
PRUnichar * uniPassword;
|
||||
PRBool okayValue = PR_TRUE;
|
||||
dialog->PromptPassword(aPromptMessage, &uniPassword, &okayValue);
|
||||
|
||||
if (!okayValue) // if the user pressed cancel, just return NULL;
|
||||
{
|
||||
*aPassword = nsnull;
|
||||
return rv;
|
||||
}
|
||||
|
||||
// we got a password back...so remember it
|
||||
nsCString aCStr(uniPassword);
|
||||
|
||||
SetPassword((const char *) aCStr);
|
||||
} // if we got a prompt dialog
|
||||
} // if the password is empty
|
||||
|
||||
*aPassword = m_password.ToNewCString();
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::SetDefaultLocalPath(nsIFileSpec *aDefaultLocalPath)
|
||||
{
|
||||
nsresult rv;
|
||||
nsXPIDLCString type;
|
||||
GetType(getter_Copies(type));
|
||||
|
||||
nsCAutoString progid(NS_MSGPROTOCOLINFO_PROGID_PREFIX);
|
||||
progid += type;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgProtocolInfo, protocolInfo, progid, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
rv = protocolInfo->SetDefaultLocalPath(aDefaultLocalPath);
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetLocalPath(nsIFileSpec **aLocalPath)
|
||||
{
|
||||
nsresult rv;
|
||||
|
||||
// if the local path has already been set, use it
|
||||
rv = GetFileValue("directory", aLocalPath);
|
||||
if (NS_SUCCEEDED(rv) && *aLocalPath) return rv;
|
||||
|
||||
// otherwise, create the path using. note we are using the
|
||||
// server key instead of the hostname
|
||||
//
|
||||
// TODO: handle the case where they migrated a server of hostname "server4"
|
||||
// and we create a server (with the account wizard) with key "server4"
|
||||
// we'd get a collision.
|
||||
// need to modify the code that creates keys to check for disk collision
|
||||
nsXPIDLCString type;
|
||||
GetType(getter_Copies(type));
|
||||
|
||||
nsCAutoString progid(NS_MSGPROTOCOLINFO_PROGID_PREFIX);
|
||||
progid += type;
|
||||
|
||||
NS_WITH_SERVICE(nsIMsgProtocolInfo, protocolInfo, progid, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIFileSpec> path;
|
||||
rv = protocolInfo->GetDefaultLocalPath(getter_AddRefs(path));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
path->CreateDir();
|
||||
|
||||
nsXPIDLCString key;
|
||||
rv = GetKey(getter_Copies(key));
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = path->AppendRelativeUnixPath(key);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
rv = SetLocalPath(path);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
*aLocalPath = path;
|
||||
NS_ADDREF(*aLocalPath);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::SetLocalPath(nsIFileSpec *spec)
|
||||
{
|
||||
if (spec) {
|
||||
spec->CreateDir();
|
||||
return SetFileValue("directory", spec);
|
||||
}
|
||||
else {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::SetRememberPassword(PRBool value)
|
||||
{
|
||||
if (value)
|
||||
SetPrefPassword(m_password);
|
||||
else
|
||||
SetPrefPassword(nsnull);
|
||||
return SetBoolValue("remember_password", value);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgIncomingServer::GetRememberPassword(PRBool* value)
|
||||
{
|
||||
return GetBoolValue("remember_password", value);
|
||||
}
|
||||
|
||||
// use the convenience macros to implement the accessors
|
||||
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, HostName, "hostname");
|
||||
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, Username, "userName");
|
||||
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, PrefPassword, "password");
|
||||
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, DoBiff, "check_new_mail");
|
||||
NS_IMPL_SERVERPREF_INT(nsMsgIncomingServer, BiffMinutes, "check_time");
|
||||
NS_IMPL_SERVERPREF_STR(nsMsgIncomingServer, Type, "type");
|
||||
|
||||
/* what was this called in 4.x? */
|
||||
// pref("mail.pop3_gets_new_mail", true);
|
||||
|
||||
NS_IMPL_SERVERPREF_BOOL(nsMsgIncomingServer, DownloadOnBiff, "download_on_biff");
|
||||
70
mozilla/mailnews/base/util/nsMsgIncomingServer.h
Normal file
70
mozilla/mailnews/base/util/nsMsgIncomingServer.h
Normal file
@@ -0,0 +1,70 @@
|
||||
/* -*- 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 nsMsgIncomingServer_h__
|
||||
#define nsMsgIncomingServer_h__
|
||||
|
||||
#include "nsIMsgIncomingServer.h"
|
||||
#include "nsIPref.h"
|
||||
#include "msgCore.h"
|
||||
#include "nsIFolder.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
class nsIMsgFolderCache;
|
||||
|
||||
/*
|
||||
* base class for nsIMsgIncomingServer - derive your class from here
|
||||
* if you want to get some free implementation
|
||||
*
|
||||
* this particular implementation is not meant to be used directly.
|
||||
*/
|
||||
|
||||
class NS_MSG_BASE nsMsgIncomingServer : public nsIMsgIncomingServer {
|
||||
public:
|
||||
nsMsgIncomingServer();
|
||||
virtual ~nsMsgIncomingServer();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_DECL_NSIMSGINCOMINGSERVER
|
||||
|
||||
private:
|
||||
nsIPref *m_prefs;
|
||||
char *m_serverKey;
|
||||
nsCString m_password;
|
||||
PRBool m_serverBusy;
|
||||
|
||||
protected:
|
||||
char *getPrefName(const char *serverKey, const char *pref);
|
||||
char *getDefaultPrefName(const char *pref);
|
||||
|
||||
// these are private pref getters and setters for the password
|
||||
// field. Callers should be using Get/Set Password
|
||||
NS_IMETHOD GetPrefPassword(char * *aPassword);
|
||||
NS_IMETHOD SetPrefPassword(const char * aPassword);
|
||||
|
||||
nsCOMPtr <nsIFolder> m_rootFolder;
|
||||
nsresult getDefaultCharPref(const char *pref, char **);
|
||||
nsresult getDefaultBoolPref(const char *pref, PRBool *);
|
||||
nsresult getDefaultIntPref(const char *pref, PRInt32 *);
|
||||
|
||||
nsresult CreateRootFolder();
|
||||
|
||||
};
|
||||
|
||||
#endif // nsMsgIncomingServer_h__
|
||||
1471
mozilla/mailnews/base/util/nsMsgKeySet.cpp
Normal file
1471
mozilla/mailnews/base/util/nsMsgKeySet.cpp
Normal file
File diff suppressed because it is too large
Load Diff
115
mozilla/mailnews/base/util/nsMsgKeySet.h
Normal file
115
mozilla/mailnews/base/util/nsMsgKeySet.h
Normal file
@@ -0,0 +1,115 @@
|
||||
/* -*- 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 _nsMsgKeySet_H_
|
||||
#define _nsMsgKeySet_H_
|
||||
|
||||
#include "msgCore.h"
|
||||
|
||||
// nsMsgKeySet represents a set of articles. Typically, it is the set of
|
||||
// read articles from a .newsrc file, but it can be used for other purposes
|
||||
// too.
|
||||
|
||||
#if 0
|
||||
// If a MSG_NewsHost* is supplied to the creation routine, then that
|
||||
// MSG_NewsHost will be notified whenever a change is made to set.
|
||||
class MSG_NewsHost;
|
||||
#endif
|
||||
|
||||
class NS_MSG_BASE nsMsgKeySet {
|
||||
public:
|
||||
// Creates an empty set.
|
||||
static nsMsgKeySet* Create(/* MSG_NewsHost* host = NULL*/);
|
||||
|
||||
// Creates a set from the list of numbers, as might be found in a
|
||||
// newsrc file.
|
||||
static nsMsgKeySet* Create(const char* str/* , MSG_NewsHost* host = NULL*/);
|
||||
~nsMsgKeySet();
|
||||
|
||||
// FirstNonMember() returns the lowest non-member of the set that is
|
||||
// greater than 0.
|
||||
PRInt32 FirstNonMember();
|
||||
|
||||
// Output() converts to a string representation suitable for writing to a
|
||||
// .newsrc file. (The result must be freed by the caller using delete[].)
|
||||
char* Output();
|
||||
|
||||
// IsMember() returns whether the given article is a member of this set.
|
||||
PRBool IsMember(PRInt32 art);
|
||||
|
||||
// Add() adds the given article to the set. (Returns 1 if a change was
|
||||
// made, 0 if it was already there, and negative on error.)
|
||||
int Add(PRInt32 art);
|
||||
|
||||
// Remove() removes the given article from the set.
|
||||
int Remove(PRInt32 art);
|
||||
|
||||
// AddRange() adds the (inclusive) given range of articles to the set.
|
||||
int AddRange(PRInt32 first, PRInt32 last);
|
||||
|
||||
// CountMissingInRange() takes an inclusive range of articles and returns
|
||||
// the number of articles in that range which are not in the set.
|
||||
PRInt32 CountMissingInRange(PRInt32 start, PRInt32 end);
|
||||
|
||||
// FirstMissingRange() takes an inclusive range and finds the first range
|
||||
// of articles that are not in the set. If none, return zeros.
|
||||
int FirstMissingRange(PRInt32 min, PRInt32 max, PRInt32* first, PRInt32* last);
|
||||
|
||||
|
||||
// LastMissingRange() takes an inclusive range and finds the last range
|
||||
// of articles that are not in the set. If none, return zeros.
|
||||
int LastMissingRange(PRInt32 min, PRInt32 max, PRInt32* first, PRInt32* last);
|
||||
|
||||
PRInt32 GetLastMember();
|
||||
PRInt32 GetFirstMember();
|
||||
void SetLastMember(PRInt32 highWaterMark);
|
||||
// For debugging only...
|
||||
PRInt32 getLength() {return m_length;}
|
||||
|
||||
#ifdef DEBUG
|
||||
static void RunTests();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
nsMsgKeySet(/* MSG_NewsHost* host */);
|
||||
nsMsgKeySet(const char* /* , MSG_NewsHost* host */);
|
||||
PRBool Grow();
|
||||
PRBool Optimize();
|
||||
|
||||
#ifdef DEBUG
|
||||
static void test_decoder(const char*);
|
||||
static void test_adder();
|
||||
static void test_ranges();
|
||||
static void test_member(PRBool with_cache);
|
||||
#endif
|
||||
|
||||
PRInt32 *m_data; /* the numbers composing the `chunks' */
|
||||
PRInt32 m_data_size; /* size of that malloc'ed block */
|
||||
PRInt32 m_length; /* active area */
|
||||
|
||||
PRInt32 m_cached_value; /* a potential set member, or -1 if unset*/
|
||||
PRInt32 m_cached_value_index; /* the index into `data' at which a search
|
||||
to determine whether `cached_value' was
|
||||
a member of the set ended. */
|
||||
#ifdef NEWSRC_DOES_HOST_STUFF
|
||||
MSG_NewsHost* m_host;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
#endif /* _nsMsgKeySet_H_ */
|
||||
384
mozilla/mailnews/base/util/nsMsgLineBuffer.cpp
Normal file
384
mozilla/mailnews/base/util/nsMsgLineBuffer.cpp
Normal file
@@ -0,0 +1,384 @@
|
||||
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "prlog.h"
|
||||
#include "nsMsgLineBuffer.h"
|
||||
|
||||
#include "nsIInputStream.h" // used by nsMsgLineStreamBuffer
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsByteArray);
|
||||
|
||||
nsByteArray::nsByteArray()
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsByteArray);
|
||||
m_buffer = NULL;
|
||||
m_bufferSize = 0;
|
||||
m_bufferPos = 0;
|
||||
}
|
||||
|
||||
nsByteArray::~nsByteArray()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsByteArray);
|
||||
PR_FREEIF(m_buffer);
|
||||
}
|
||||
|
||||
nsresult nsByteArray::GrowBuffer(PRUint32 desired_size, PRUint32 quantum)
|
||||
{
|
||||
if (m_bufferSize < desired_size)
|
||||
{
|
||||
char *new_buf;
|
||||
PRUint32 increment = desired_size - m_bufferSize;
|
||||
if (increment < quantum) /* always grow by a minimum of N bytes */
|
||||
increment = quantum;
|
||||
|
||||
|
||||
new_buf = (m_buffer
|
||||
? (char *) PR_REALLOC (m_buffer, (m_bufferSize + increment))
|
||||
: (char *) PR_MALLOC (m_bufferSize + increment));
|
||||
if (! new_buf)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
m_buffer = new_buf;
|
||||
m_bufferSize += increment;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
nsresult nsByteArray::AppendString(const char *string)
|
||||
{
|
||||
PRUint32 strLength = (string) ? PL_strlen(string) : 0;
|
||||
return AppendBuffer(string, strLength);
|
||||
|
||||
}
|
||||
|
||||
nsresult nsByteArray::AppendBuffer(const char *buffer, PRUint32 length)
|
||||
{
|
||||
nsresult ret = NS_OK;
|
||||
if (m_bufferPos + length > m_bufferSize)
|
||||
ret = GrowBuffer(m_bufferPos + length, 1024);
|
||||
if (ret == NS_OK)
|
||||
{
|
||||
memcpy(m_buffer + m_bufferPos, buffer, length);
|
||||
m_bufferPos += length;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsMsgLineBuffer);
|
||||
|
||||
nsMsgLineBuffer::nsMsgLineBuffer(nsMsgLineBufferHandler *handler, PRBool convertNewlinesP)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsMsgLineBuffer);
|
||||
m_handler = handler;
|
||||
m_convertNewlinesP = convertNewlinesP;
|
||||
m_lookingForCRLF = PR_TRUE;
|
||||
}
|
||||
|
||||
nsMsgLineBuffer::~nsMsgLineBuffer()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsMsgLineBuffer);
|
||||
}
|
||||
|
||||
void
|
||||
nsMsgLineBuffer::SetLookingForCRLF(PRBool b)
|
||||
{
|
||||
m_lookingForCRLF = b;
|
||||
}
|
||||
|
||||
PRInt32 nsMsgLineBuffer::BufferInput(const char *net_buffer, PRInt32 net_buffer_size)
|
||||
{
|
||||
int status = 0;
|
||||
if (m_bufferPos > 0 && m_buffer && m_buffer[m_bufferPos - 1] == CR &&
|
||||
net_buffer_size > 0 && net_buffer[0] != LF) {
|
||||
/* The last buffer ended with a CR. The new buffer does not start
|
||||
with a LF. This old buffer should be shipped out and discarded. */
|
||||
PR_ASSERT(m_bufferSize > m_bufferPos);
|
||||
if (m_bufferSize <= m_bufferPos) return -1;
|
||||
status = ConvertAndSendBuffer();
|
||||
if (status < 0)
|
||||
return status;
|
||||
m_bufferPos = 0;
|
||||
}
|
||||
while (net_buffer_size > 0)
|
||||
{
|
||||
const char *net_buffer_end = net_buffer + net_buffer_size;
|
||||
const char *newline = 0;
|
||||
const char *s;
|
||||
|
||||
|
||||
for (s = net_buffer; s < net_buffer_end; s++)
|
||||
{
|
||||
if (m_lookingForCRLF) {
|
||||
/* Move forward in the buffer until the first newline.
|
||||
Stop when we see CRLF, CR, or LF, or the end of the buffer.
|
||||
*But*, if we see a lone CR at the *very end* of the buffer,
|
||||
treat this as if we had reached the end of the buffer without
|
||||
seeing a line terminator. This is to catch the case of the
|
||||
buffers splitting a CRLF pair, as in "FOO\r\nBAR\r" "\nBAZ\r\n".
|
||||
*/
|
||||
if (*s == CR || *s == LF) {
|
||||
newline = s;
|
||||
if (newline[0] == CR) {
|
||||
if (s == net_buffer_end - 1) {
|
||||
/* CR at end - wait for the next character. */
|
||||
newline = 0;
|
||||
break;
|
||||
}
|
||||
else if (newline[1] == LF) {
|
||||
/* CRLF seen; swallow both. */
|
||||
newline++;
|
||||
}
|
||||
}
|
||||
newline++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
/* if not looking for a CRLF, stop at CR or LF. (for example, when parsing the newsrc file). this fixes #9896, where we'd lose the last line of anything we'd parse that used CR as the line break. */
|
||||
if (*s == CR || *s == LF) {
|
||||
newline = s;
|
||||
newline++;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure room in the net_buffer and append some or all of the current
|
||||
chunk of data to it. */
|
||||
{
|
||||
const char *end = (newline ? newline : net_buffer_end);
|
||||
PRUint32 desired_size = (end - net_buffer) + m_bufferPos + 1;
|
||||
|
||||
if (desired_size >= m_bufferSize)
|
||||
{
|
||||
status = GrowBuffer (desired_size, 1024);
|
||||
if (status < 0)
|
||||
return status;
|
||||
}
|
||||
memcpy (m_buffer + m_bufferPos, net_buffer, (end - net_buffer));
|
||||
m_bufferPos += (end - net_buffer);
|
||||
}
|
||||
|
||||
/* Now m_buffer contains either a complete line, or as complete
|
||||
a line as we have read so far.
|
||||
|
||||
If we have a line, process it, and then remove it from `m_buffer'.
|
||||
Then go around the loop again, until we drain the incoming data.
|
||||
*/
|
||||
if (!newline)
|
||||
return 0;
|
||||
|
||||
status = ConvertAndSendBuffer();
|
||||
if (status < 0) return status;
|
||||
|
||||
net_buffer_size -= (newline - net_buffer);
|
||||
net_buffer = newline;
|
||||
m_bufferPos = 0;
|
||||
}
|
||||
#ifdef DEBUG_bienvenu
|
||||
printf("returning from buffer input m_bufferPos = %ld\n", m_bufferPos);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsMsgLineBuffer::HandleLine(char *line, PRUint32 line_length)
|
||||
{
|
||||
NS_ASSERTION(PR_FALSE, "must override this method if you don't provide a handler");
|
||||
return 0;
|
||||
}
|
||||
|
||||
PRInt32 nsMsgLineBuffer::ConvertAndSendBuffer()
|
||||
{
|
||||
/* Convert the line terminator to the native form.
|
||||
*/
|
||||
|
||||
char *buf = m_buffer;
|
||||
PRInt32 length = m_bufferPos;
|
||||
|
||||
char* newline;
|
||||
|
||||
PR_ASSERT(buf && length > 0);
|
||||
if (!buf || length <= 0)
|
||||
return -1;
|
||||
newline = buf + length;
|
||||
|
||||
PR_ASSERT(newline[-1] == CR || newline[-1] == LF);
|
||||
if (newline[-1] != CR && newline[-1] != LF)
|
||||
return -1;
|
||||
|
||||
if (!m_convertNewlinesP)
|
||||
{
|
||||
}
|
||||
#if (MSG_LINEBREAK_LEN == 1)
|
||||
else if ((newline - buf) >= 2 &&
|
||||
newline[-2] == CR &&
|
||||
newline[-1] == LF)
|
||||
{
|
||||
/* CRLF -> CR or LF */
|
||||
buf [length - 2] = MSG_LINEBREAK[0];
|
||||
length--;
|
||||
}
|
||||
else if (newline > buf + 1 &&
|
||||
newline[-1] != MSG_LINEBREAK[0])
|
||||
{
|
||||
/* CR -> LF or LF -> CR */
|
||||
buf [length - 1] = MSG_LINEBREAK[0];
|
||||
}
|
||||
#else
|
||||
else if (((newline - buf) >= 2 && newline[-2] != CR) ||
|
||||
((newline - buf) >= 1 && newline[-1] != LF))
|
||||
{
|
||||
/* LF -> CRLF or CR -> CRLF */
|
||||
length++;
|
||||
buf[length - 2] = MSG_LINEBREAK[0];
|
||||
buf[length - 1] = MSG_LINEBREAK[1];
|
||||
}
|
||||
#endif
|
||||
|
||||
return (m_handler) ? m_handler->HandleLine(buf, length) : HandleLine(buf, length);
|
||||
}
|
||||
|
||||
// If there's still some data (non CRLF terminated) flush it out
|
||||
PRInt32 nsMsgLineBuffer::FlushLastLine()
|
||||
{
|
||||
char *buf = m_buffer + m_bufferPos;
|
||||
PRInt32 length = m_bufferPos - 1;
|
||||
if (length > 0)
|
||||
return (m_handler) ? m_handler->HandleLine(buf, length) : HandleLine(buf, length);
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// This is a utility class used to efficiently extract lines from an input stream by buffering
|
||||
// read but unprocessed stream data in a buffer.
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsMsgLineStreamBuffer::nsMsgLineStreamBuffer(PRUint32 aBufferSize, const char * aEndOfLineToken,
|
||||
PRBool aAllocateNewLines, PRBool aEatCRLFs)
|
||||
: m_eatCRLFs(aEatCRLFs), m_allocateNewLines(aAllocateNewLines),
|
||||
m_endOfLineToken(aEndOfLineToken)
|
||||
{
|
||||
NS_PRECONDITION(aBufferSize > 0, "invalid buffer size!!!");
|
||||
m_dataBuffer = nsnull;
|
||||
m_startPos = nsnull;
|
||||
|
||||
// used to buffer incoming data by ReadNextLineFromInput
|
||||
if (aBufferSize > 0)
|
||||
{
|
||||
m_dataBuffer = (char *) PR_CALLOC(sizeof(char) * aBufferSize);
|
||||
m_startPos = m_dataBuffer;
|
||||
}
|
||||
|
||||
m_dataBufferSize = aBufferSize;
|
||||
}
|
||||
|
||||
nsMsgLineStreamBuffer::~nsMsgLineStreamBuffer()
|
||||
{
|
||||
PR_FREEIF(m_dataBuffer); // release our buffer...
|
||||
}
|
||||
|
||||
// the design for this method has an inherit bug: if the length of the line is greater than the size of m_dataBufferSize,
|
||||
// then we'll never find the next line because we can't hold the whole line in memory.
|
||||
// aInputStream - the input stream we want to read a line from
|
||||
// aPauseForMoreData is returned as PR_TRUE if the stream does not yet contain a line and we must wait for more
|
||||
// data to come into the stream.
|
||||
|
||||
// Note to people wishing to modify this function: Be *VERY CAREFUL* this is a critical function used by all of
|
||||
// our mail protocols including imap, nntp, and pop. If you screw it up, you could break a lot of stuff.....
|
||||
|
||||
char * nsMsgLineStreamBuffer::ReadNextLine(nsIInputStream * aInputStream, PRUint32 &aNumBytesInLine, PRBool &aPauseForMoreData)
|
||||
{
|
||||
// try to extract a line from m_inputBuffer. If we don't have an entire line,
|
||||
// then read more bytes out from the stream. If the stream is empty then wait
|
||||
// on the monitor for more data to come in.
|
||||
|
||||
NS_PRECONDITION(m_startPos && m_dataBufferSize > 0, "invalid input arguments for read next line from input");
|
||||
|
||||
// initialize out values
|
||||
aPauseForMoreData = PR_FALSE;
|
||||
aNumBytesInLine = 0;
|
||||
char * endOfLine = nsnull;
|
||||
|
||||
PRUint32 numBytesInBuffer = PL_strlen(m_startPos);
|
||||
|
||||
if (numBytesInBuffer > 0) // any data in our internal buffer?
|
||||
endOfLine = PL_strstr(m_startPos, m_endOfLineToken); // see if we already have a line ending...
|
||||
|
||||
// it's possible that we got here before the first time we receive data from the server
|
||||
// so aInputStream will be nsnull...
|
||||
if (!endOfLine && aInputStream) // get some more data from the server
|
||||
{
|
||||
PRUint32 numBytesInStream = 0;
|
||||
PRUint32 numBytesCopied = 0;
|
||||
aInputStream->Available(&numBytesInStream);
|
||||
// if the number of bytes we want to read from the stream, is greater than the number
|
||||
// of bytes left in our buffer, then we need to shift the start pos and its contents
|
||||
// down to the beginning of m_dataBuffer...
|
||||
PRUint32 numFreeBytesInBuffer = (m_dataBuffer + m_dataBufferSize) - (m_startPos + numBytesInBuffer);
|
||||
if (numBytesInStream >= numFreeBytesInBuffer)
|
||||
{
|
||||
nsCRT::memcpy(m_dataBuffer, m_startPos, numBytesInBuffer);
|
||||
m_dataBuffer[numBytesInBuffer] = '\0'; // make sure the end of the buffer is terminated
|
||||
m_startPos = m_dataBuffer; // update the new start position
|
||||
// update the number of free bytes in the buffer
|
||||
numFreeBytesInBuffer = m_dataBufferSize - numBytesInBuffer;
|
||||
}
|
||||
|
||||
PRUint32 numBytesToCopy = PR_MIN(numFreeBytesInBuffer - 1 /* leave one for a null terminator */, numBytesInStream);
|
||||
// read the data into the end of our data buffer
|
||||
if (numBytesToCopy > 0)
|
||||
{
|
||||
aInputStream->Read(m_startPos + numBytesInBuffer, numBytesToCopy, &numBytesCopied);
|
||||
m_startPos[numBytesInBuffer + numBytesCopied] = '\0';
|
||||
}
|
||||
|
||||
// okay, now that we've tried to read in more data from the stream, look for another end of line
|
||||
// character
|
||||
endOfLine = PL_strstr(m_startPos, m_endOfLineToken);
|
||||
|
||||
}
|
||||
|
||||
// okay, now check again for endOfLine.
|
||||
if (endOfLine)
|
||||
{
|
||||
if (!m_eatCRLFs)
|
||||
endOfLine += PL_strlen(m_endOfLineToken); // count for CRLF
|
||||
|
||||
// PR_CALLOC zeros out the allocated line
|
||||
char* newLine = (char*) PR_CALLOC(endOfLine-m_startPos+1);
|
||||
if (!newLine)
|
||||
return nsnull;
|
||||
|
||||
nsCRT::memcpy(newLine, m_startPos, endOfLine-m_startPos); // copy the string into the new line buffer
|
||||
aNumBytesInLine = endOfLine - m_startPos;
|
||||
|
||||
if (m_eatCRLFs)
|
||||
endOfLine += PL_strlen(m_endOfLineToken); // advance past CRLF if we haven't already done so...
|
||||
|
||||
// now we need to update the data buffer to go past the line we just read out.
|
||||
if (PL_strlen(endOfLine) <= 0) // if no more data in the buffer, then just zero out the buffer...
|
||||
m_startPos[0] = '\0';
|
||||
else // advance
|
||||
m_startPos = endOfLine; // move us up to the end of the line
|
||||
return newLine;
|
||||
}
|
||||
|
||||
aPauseForMoreData = PR_TRUE;
|
||||
return nsnull; // if we somehow got here. we don't have another line in the buffer yet...need to wait for more data...
|
||||
}
|
||||
113
mozilla/mailnews/base/util/nsMsgLineBuffer.h
Normal file
113
mozilla/mailnews/base/util/nsMsgLineBuffer.h
Normal 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
#ifndef _nsMsgLineBuffer_H
|
||||
#define _nsMsgLineBuffer_H
|
||||
|
||||
#include "msgCore.h" // precompiled header...
|
||||
|
||||
// I can't believe I have to have this stupid class, but I can't find
|
||||
// anything suitable (nsStrImpl might be, when its done). nsIByteBuffer
|
||||
// would do, if I had a stream for input, which I don't.
|
||||
|
||||
class NS_MSG_BASE nsByteArray
|
||||
{
|
||||
public:
|
||||
nsByteArray();
|
||||
virtual ~nsByteArray();
|
||||
PRUint32 GetSize() {return m_bufferSize;}
|
||||
PRUint32 GetBufferPos() {return m_bufferPos;}
|
||||
nsresult GrowBuffer(PRUint32 desired_size, PRUint32 quantum = 1024);
|
||||
nsresult AppendString(const char *string);
|
||||
nsresult AppendBuffer(const char *buffer, PRUint32 length);
|
||||
void ResetWritePos() {m_bufferPos = 0;}
|
||||
char *GetBuffer() {return m_buffer;}
|
||||
protected:
|
||||
char *m_buffer;
|
||||
PRUint32 m_bufferSize;
|
||||
PRUint32 m_bufferPos; // write Pos in m_buffer - where the next byte should go.
|
||||
};
|
||||
|
||||
|
||||
class NS_MSG_BASE nsMsgLineBufferHandler : public nsByteArray
|
||||
{
|
||||
public:
|
||||
virtual PRInt32 HandleLine(char *line, PRUint32 line_length) = 0;
|
||||
};
|
||||
|
||||
class NS_MSG_BASE nsMsgLineBuffer : public nsByteArray
|
||||
{
|
||||
public:
|
||||
nsMsgLineBuffer(nsMsgLineBufferHandler *handler, PRBool convertNewlinesP);
|
||||
|
||||
virtual ~nsMsgLineBuffer();
|
||||
PRInt32 BufferInput(const char *net_buffer, PRInt32 net_buffer_size);
|
||||
// Not sure why anyone cares, by NNTPHost seems to want to know the buf pos.
|
||||
PRUint32 GetBufferPos() {return m_bufferPos;}
|
||||
|
||||
virtual PRInt32 HandleLine(char *line, PRUint32 line_length);
|
||||
// flush last line, though it won't be CRLF terminated.
|
||||
virtual PRInt32 FlushLastLine();
|
||||
protected:
|
||||
nsMsgLineBuffer(PRBool convertNewlinesP);
|
||||
|
||||
PRInt32 ConvertAndSendBuffer();
|
||||
void SetLookingForCRLF(PRBool b);
|
||||
|
||||
nsMsgLineBufferHandler *m_handler;
|
||||
PRBool m_convertNewlinesP;
|
||||
PRBool m_lookingForCRLF;
|
||||
};
|
||||
|
||||
// I'm adding this utility class here for lack of a better place. This utility class is similar to nsMsgLineBuffer
|
||||
// except it works from an input stream. It is geared towards efficiently parsing new lines out of a stream by storing
|
||||
// read but unprocessed bytes in a buffer. I envision the primary use of this to be our mail protocols such as imap, news and
|
||||
// pop which need to process line by line data being returned in the form of a proxied stream from the server.
|
||||
|
||||
class nsIInputStream;
|
||||
|
||||
class NS_MSG_BASE nsMsgLineStreamBuffer
|
||||
{
|
||||
public:
|
||||
// aBufferSize -- size of the buffer you want us to use for buffering stream data
|
||||
// aEndOfLinetoken -- The delimeter string to be used for determining the end of line. This
|
||||
// allows us to parse platform specific end of line endings by making it
|
||||
// a parameter.
|
||||
// aAllocateNewLines -- PR_TRUE if you want calls to ReadNextLine to allocate new memory for the line.
|
||||
// if false, the char * returned is just a ptr into the buffer. Subsequent calls to
|
||||
// ReadNextLine will alter the data so your ptr only has a life time of a per call.
|
||||
// aEatCRLFs -- PR_TRUE if you don't want to see the CRLFs on the lines returned by ReadNextLine.
|
||||
// PR_FALSE if you do want to see them.
|
||||
nsMsgLineStreamBuffer(PRUint32 aBufferSize, const char * aEndOfLineToken, PRBool aAllocateNewLines, PRBool aEatCRLFs = PR_TRUE); // specify the size of the buffer you want the class to use....
|
||||
virtual ~nsMsgLineStreamBuffer();
|
||||
|
||||
// Caller must free the line returned using PR_Free
|
||||
// aEndOfLinetoken -- delimeter used to denote the end of a line.
|
||||
// aNumBytesInLine -- The number of bytes in the line returned
|
||||
// aPauseForMoreData -- There is not enough data in the stream to make a line at this time...
|
||||
char * ReadNextLine(nsIInputStream * aInputStream, PRUint32 &anumBytesInLine, PRBool &aPauseForMoreData);
|
||||
protected:
|
||||
PRBool m_eatCRLFs;
|
||||
PRBool m_allocateNewLines;
|
||||
char * m_dataBuffer;
|
||||
char * m_startPos;
|
||||
const char * m_endOfLineToken;
|
||||
PRUint32 m_dataBufferSize;
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
399
mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp
Normal file
399
mozilla/mailnews/base/util/nsMsgMailNewsUrl.cpp
Normal file
@@ -0,0 +1,399 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsMsgMailNewsUrl.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsIMsgMailSession.h"
|
||||
#include "nsXPIDLString.h"
|
||||
|
||||
static NS_DEFINE_CID(kUrlListenerManagerCID, NS_URLLISTENERMANAGER_CID);
|
||||
static NS_DEFINE_CID(kStandardUrlCID, NS_STANDARDURL_CID);
|
||||
static NS_DEFINE_CID(kMsgMailSessionCID, NS_MSGMAILSESSION_CID);
|
||||
|
||||
nsMsgMailNewsUrl::nsMsgMailNewsUrl()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
// nsIURI specific state
|
||||
m_errorMessage = nsnull;
|
||||
m_runningUrl = PR_FALSE;
|
||||
m_updatingFolder = PR_FALSE;
|
||||
|
||||
nsComponentManager::CreateInstance(kUrlListenerManagerCID, nsnull, nsCOMTypeInfo<nsIUrlListenerManager>::GetIID(), (void **) getter_AddRefs(m_urlListeners));
|
||||
nsComponentManager::CreateInstance(kStandardUrlCID, nsnull, nsCOMTypeInfo<nsIURL>::GetIID(), (void **) getter_AddRefs(m_baseURL));
|
||||
}
|
||||
|
||||
nsMsgMailNewsUrl::~nsMsgMailNewsUrl()
|
||||
{
|
||||
PR_FREEIF(m_errorMessage);
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsMsgMailNewsUrl);
|
||||
NS_IMPL_RELEASE(nsMsgMailNewsUrl);
|
||||
|
||||
nsresult nsMsgMailNewsUrl::QueryInterface(const nsIID &aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIURI>::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIURI*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIURL>::GetIID())) {
|
||||
*aInstancePtr = (void*) ((nsIURL*)this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsIMsgMailNewsUrl>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void *) ((nsIMsgMailNewsUrl*) this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(nsCOMTypeInfo<nsISupports>::GetIID()))
|
||||
{
|
||||
*aInstancePtr = (void *) ((nsIMsgMailNewsUrl*) this);
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
#if defined(NS_DEBUG)
|
||||
/*
|
||||
* Check for the debug-only interface indicating thread-safety
|
||||
*/
|
||||
static NS_DEFINE_IID(kIsThreadsafeIID, NS_ISTHREADSAFE_IID);
|
||||
if (aIID.Equals(kIsThreadsafeIID)) {
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// Begin nsIMsgMailNewsUrl specific support
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult nsMsgMailNewsUrl::GetUrlState(PRBool * aRunningUrl)
|
||||
{
|
||||
if (aRunningUrl)
|
||||
*aRunningUrl = m_runningUrl;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailNewsUrl::SetUrlState(PRBool aRunningUrl, nsresult aExitCode)
|
||||
{
|
||||
m_runningUrl = aRunningUrl;
|
||||
nsCOMPtr <nsIMsgStatusFeedback> statusFeedback;
|
||||
|
||||
if (NS_SUCCEEDED(GetStatusFeedback(getter_AddRefs(statusFeedback))) && statusFeedback)
|
||||
{
|
||||
if (m_runningUrl)
|
||||
statusFeedback->StartMeteors();
|
||||
else
|
||||
{
|
||||
statusFeedback->ShowProgress(0);
|
||||
statusFeedback->StopMeteors();
|
||||
}
|
||||
}
|
||||
if (m_urlListeners)
|
||||
{
|
||||
if (m_runningUrl)
|
||||
{
|
||||
m_urlListeners->OnStartRunningUrl(this);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_urlListeners->OnStopRunningUrl(this, aExitCode);
|
||||
}
|
||||
}
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailNewsUrl::RegisterListener (nsIUrlListener * aUrlListener)
|
||||
{
|
||||
if (m_urlListeners)
|
||||
m_urlListeners->RegisterListener(aUrlListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailNewsUrl::UnRegisterListener (nsIUrlListener * aUrlListener)
|
||||
{
|
||||
if (m_urlListeners)
|
||||
m_urlListeners->UnRegisterListener(aUrlListener);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailNewsUrl::SetErrorMessage (const char * errorMessage)
|
||||
{
|
||||
// functionality has been moved to nsIMsgStatusFeedback
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
nsresult nsMsgMailNewsUrl::GetErrorMessage (char ** errorMessage)
|
||||
{
|
||||
// functionality has been moved to nsIMsgStatusFeedback
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetServer(nsIMsgIncomingServer ** aIncomingServer)
|
||||
{
|
||||
// mscott --> we could cache a copy of the server here....but if we did, we run
|
||||
// the risk of leaking the server if any single url gets leaked....of course that
|
||||
// shouldn't happen...but it could. so i'm going to look it up every time and
|
||||
// we can look at caching it later.
|
||||
|
||||
nsXPIDLCString host;
|
||||
nsXPIDLCString scheme;
|
||||
|
||||
nsresult rv = GetHost(getter_Copies(host));
|
||||
rv = GetScheme(getter_Copies(scheme));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
NS_WITH_SERVICE(nsIMsgMailSession, session, kMsgMailSessionCID, &rv);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIMsgAccountManager> accountManager;
|
||||
rv = session->GetAccountManager(getter_AddRefs(accountManager));
|
||||
if(NS_FAILED(rv)) return rv;
|
||||
|
||||
nsCOMPtr<nsIMsgIncomingServer> server;
|
||||
rv = accountManager->FindServer(GetUserName(),
|
||||
host,
|
||||
scheme,
|
||||
aIncomingServer);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetStatusFeedback(nsIMsgStatusFeedback *aMsgFeedback)
|
||||
{
|
||||
if (aMsgFeedback)
|
||||
m_statusFeedback = do_QueryInterface(aMsgFeedback);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetStatusFeedback(nsIMsgStatusFeedback **aMsgFeedback)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
// note: it is okay to return a null status feedback and not return an error
|
||||
// it's possible the url really doesn't have status feedback
|
||||
if (!m_statusFeedback)
|
||||
{
|
||||
NS_WITH_SERVICE(nsIMsgMailSession, mailSession, kMsgMailSessionCID, &rv);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
mailSession->GetTemporaryMsgStatusFeedback(getter_AddRefs(m_statusFeedback));
|
||||
}
|
||||
if (aMsgFeedback)
|
||||
{
|
||||
*aMsgFeedback = m_statusFeedback;
|
||||
NS_IF_ADDREF(*aMsgFeedback);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetUpdatingFolder(PRBool *aResult)
|
||||
{
|
||||
if (!aResult)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
*aResult = m_updatingFolder;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetUpdatingFolder(PRBool updatingFolder)
|
||||
{
|
||||
m_updatingFolder = updatingFolder;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// End nsIMsgMailNewsUrl specific support
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
// Begin nsIURI support
|
||||
////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetSpec(char * *aSpec)
|
||||
{
|
||||
return m_baseURL->GetSpec(aSpec);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetSpec(const char * aSpec)
|
||||
{
|
||||
return m_baseURL->SetSpec(aSpec);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetScheme(char * *aScheme)
|
||||
{
|
||||
return m_baseURL->GetScheme(aScheme);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetScheme(const char * aScheme)
|
||||
{
|
||||
return m_baseURL->SetScheme(aScheme);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetPreHost(char * *aPreHost)
|
||||
{
|
||||
return m_baseURL->GetPreHost(aPreHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetPreHost(const char * aPreHost)
|
||||
{
|
||||
return m_baseURL->SetPreHost(aPreHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetHost(char * *aHost)
|
||||
{
|
||||
return m_baseURL->GetHost(aHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetHost(const char * aHost)
|
||||
{
|
||||
return m_baseURL->SetHost(aHost);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetPort(PRInt32 *aPort)
|
||||
{
|
||||
return m_baseURL->GetPort(aPort);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetPort(PRInt32 aPort)
|
||||
{
|
||||
return m_baseURL->SetPort(aPort);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetPath(char * *aPath)
|
||||
{
|
||||
return m_baseURL->GetPath(aPath);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetPath(const char * aPath)
|
||||
{
|
||||
return m_baseURL->SetPath(aPath);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::Equals(nsIURI *other, PRBool *_retval)
|
||||
{
|
||||
return m_baseURL->Equals(other, _retval);
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::Clone(nsIURI **_retval)
|
||||
{
|
||||
return m_baseURL->Clone(_retval);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetRelativePath(const char *i_RelativePath)
|
||||
{
|
||||
return m_baseURL->SetRelativePath(i_RelativePath);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetDirectory(char * *aDirectory)
|
||||
{
|
||||
return m_baseURL->GetDirectory(aDirectory);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetDirectory(const char *aDirectory)
|
||||
{
|
||||
|
||||
return m_baseURL->SetDirectory(aDirectory);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetFileName(char * *aFileName)
|
||||
{
|
||||
return m_baseURL->GetFileName(aFileName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetFileBaseName(char * *aFileBaseName)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetFileBaseName(const char * aFileBaseName)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetFileExtension(char * *aFileExtension)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetFileExtension(const char * aFileExtension)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetFileName(const char * aFileName)
|
||||
{
|
||||
return m_baseURL->SetFileName(aFileName);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetParam(char * *aParam)
|
||||
{
|
||||
return m_baseURL->GetParam(aParam);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetParam(const char *aParam)
|
||||
{
|
||||
return m_baseURL->SetParam(aParam);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetQuery(char * *aQuery)
|
||||
{
|
||||
return m_baseURL->GetQuery(aQuery);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetQuery(const char *aQuery)
|
||||
{
|
||||
return m_baseURL->SetQuery(aQuery);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetRef(char * *aRef)
|
||||
{
|
||||
return m_baseURL->GetRef(aRef);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetRef(const char *aRef)
|
||||
{
|
||||
return m_baseURL->SetRef(aRef);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::GetFilePath(char **o_DirFile)
|
||||
{
|
||||
return m_baseURL->GetFilePath(o_DirFile);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgMailNewsUrl::SetFilePath(const char *i_DirFile)
|
||||
{
|
||||
return m_baseURL->SetFilePath(i_DirFile);
|
||||
}
|
||||
|
||||
66
mozilla/mailnews/base/util/nsMsgMailNewsUrl.h
Normal file
66
mozilla/mailnews/base/util/nsMsgMailNewsUrl.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/* -*- 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 nsMsgMailNewsUrl_h___
|
||||
#define nsMsgMailNewsUrl_h___
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsIUrlListener.h"
|
||||
#include "nsIUrlListenerManager.h"
|
||||
#include "nsIMsgStatusFeedback.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsIMsgMailNewsUrl.h"
|
||||
#include "nsIURL.h"
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////
|
||||
// Okay, I found that all of the mail and news url interfaces needed to support
|
||||
// several common interfaces (in addition to those provided through nsIURI).
|
||||
// So I decided to group them all in this implementation so we don't have to
|
||||
// duplicate the code.
|
||||
//
|
||||
//////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
class NS_MSG_BASE nsMsgMailNewsUrl : public nsIMsgMailNewsUrl
|
||||
{
|
||||
public:
|
||||
nsMsgMailNewsUrl();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
NS_DECL_NSIMSGMAILNEWSURL
|
||||
NS_DECL_NSIURI
|
||||
NS_DECL_NSIURL
|
||||
|
||||
protected:
|
||||
virtual ~nsMsgMailNewsUrl();
|
||||
|
||||
// a helper function I needed from derived urls...
|
||||
virtual const char * GetUserName() = 0;
|
||||
|
||||
nsCOMPtr<nsIURL> m_baseURL;
|
||||
nsCOMPtr<nsIMsgStatusFeedback> m_statusFeedback;
|
||||
char *m_errorMessage;
|
||||
PRBool m_runningUrl;
|
||||
PRBool m_updatingFolder;
|
||||
|
||||
// manager of all of current url listeners....
|
||||
nsCOMPtr<nsIUrlListenerManager> m_urlListeners;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsMsgMailNewsUrl_h___ */
|
||||
369
mozilla/mailnews/base/util/nsMsgProtocol.cpp
Normal file
369
mozilla/mailnews/base/util/nsMsgProtocol.cpp
Normal file
@@ -0,0 +1,369 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 "msgCore.h"
|
||||
#include "nsMsgProtocol.h"
|
||||
#include "nsIMsgMailNewsUrl.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "nsSpecialSystemDirectory.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsIIOService.h"
|
||||
|
||||
static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
||||
static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
|
||||
|
||||
NS_IMPL_ISUPPORTS3(nsMsgProtocol, nsIStreamListener, nsIStreamObserver, nsIChannel)
|
||||
|
||||
nsMsgProtocol::nsMsgProtocol()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
m_flags = 0;
|
||||
m_startPosition = 0;
|
||||
m_readCount = 0;
|
||||
m_socketIsOpen = PR_FALSE;
|
||||
|
||||
m_tempMsgFileSpec = nsSpecialSystemDirectory(nsSpecialSystemDirectory::OS_TemporaryDirectory);
|
||||
m_tempMsgFileSpec += "tempMessage.eml";
|
||||
}
|
||||
|
||||
nsMsgProtocol::~nsMsgProtocol()
|
||||
{}
|
||||
|
||||
nsresult nsMsgProtocol::OpenNetworkSocket(nsIURI * aURL) // open a connection on this url
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsXPIDLCString hostName;
|
||||
PRInt32 port = 0;
|
||||
|
||||
m_readCount = -1; // with socket connections we want to read as much data as arrives
|
||||
m_startPosition = 0;
|
||||
|
||||
NS_WITH_SERVICE(nsISocketTransportService, socketService, kSocketTransportServiceCID, &rv);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && aURL)
|
||||
{
|
||||
aURL->GetPort(&port);
|
||||
aURL->GetHost(getter_Copies(hostName));
|
||||
|
||||
rv = socketService->CreateTransport(hostName, port, nsnull, getter_AddRefs(m_channel));
|
||||
if (NS_SUCCEEDED(rv) && m_channel)
|
||||
{
|
||||
m_socketIsOpen = PR_FALSE;
|
||||
rv = SetupTransportState();
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgProtocol::OpenFileSocket(nsIURI * aURL, const nsFileSpec * aFileSpec, PRUint32 aStartPosition, PRInt32 aReadCount)
|
||||
{
|
||||
// mscott - file needs to be encoded directly into aURL. I should be able to get
|
||||
// rid of this method completely.
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
m_startPosition = aStartPosition;
|
||||
m_readCount = aReadCount;
|
||||
|
||||
NS_WITH_SERVICE(nsIIOService, netService, kIOServiceCID, &rv);
|
||||
if (NS_SUCCEEDED(rv) && aURL)
|
||||
{
|
||||
// extract the file path from the uri...
|
||||
nsXPIDLCString filePath;
|
||||
aURL->GetPath(getter_Copies(filePath));
|
||||
char * urlSpec = PR_smprintf("file://%s", (const char *) filePath);
|
||||
|
||||
rv = netService->NewChannel("Load", urlSpec,
|
||||
nsnull, // null base URI
|
||||
nsnull, // null load group
|
||||
nsnull, // null eventsink getter
|
||||
getter_AddRefs(m_channel));
|
||||
PR_FREEIF(urlSpec);
|
||||
|
||||
if (NS_SUCCEEDED(rv) && m_channel)
|
||||
{
|
||||
m_socketIsOpen = PR_FALSE;
|
||||
// rv = SetupTransportState();
|
||||
}
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgProtocol::SetupTransportState()
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
|
||||
if (!m_socketIsOpen && m_channel)
|
||||
{
|
||||
rv = m_channel->OpenOutputStream(0 /* start position */, getter_AddRefs(m_outputStream));
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv), "unable to create an output stream");
|
||||
// we want to open the stream
|
||||
} // if m_transport
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgProtocol::CloseSocket()
|
||||
{
|
||||
// release all of our socket state
|
||||
m_socketIsOpen = PR_FALSE;
|
||||
m_outputStream = null_nsCOMPtr();
|
||||
m_channel = null_nsCOMPtr();
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/*
|
||||
* Writes the data contained in dataBuffer into the current output stream. It also informs
|
||||
* the transport layer that this data is now available for transmission.
|
||||
* Returns a positive number for success, 0 for failure (not all the bytes were written to the
|
||||
* stream, etc). We need to make another pass through this file to install an error system (mscott)
|
||||
*/
|
||||
|
||||
PRInt32 nsMsgProtocol::SendData(nsIURI * aURL, const char * dataBuffer)
|
||||
{
|
||||
PRUint32 writeCount = 0;
|
||||
PRInt32 status = 0;
|
||||
|
||||
// NS_PRECONDITION(m_outputStream, "oops....we don't have an output stream...how did that happen?");
|
||||
if (dataBuffer && m_outputStream)
|
||||
{
|
||||
status = m_outputStream->Write(dataBuffer, PL_strlen(dataBuffer), &writeCount);
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
// Whenever data arrives from the connection, core netlib notifices the protocol by calling
|
||||
// OnDataAvailable. We then read and process the incoming data from the input stream.
|
||||
NS_IMETHODIMP nsMsgProtocol::OnDataAvailable(nsIChannel * /* aChannel */, nsISupports *ctxt, nsIInputStream *inStr, PRUint32 sourceOffset, PRUint32 count)
|
||||
{
|
||||
// right now, this really just means turn around and churn through the state machine
|
||||
nsCOMPtr<nsIURI> uri = do_QueryInterface(ctxt);
|
||||
return ProcessProtocolState(uri, inStr, sourceOffset, count);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::OnStartRequest(nsIChannel * aChannel, nsISupports *ctxt)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr <nsIMsgMailNewsUrl> aMsgUrl = do_QueryInterface(ctxt, &rv);
|
||||
if (NS_SUCCEEDED(rv) && aMsgUrl)
|
||||
rv = aMsgUrl->SetUrlState(PR_TRUE, NS_OK);
|
||||
|
||||
// if we are set up as a channel, we should notify our channel listener that we are starting...
|
||||
// so pass in ourself as the channel and not the underlying socket or file channel the protocol
|
||||
// happens to be using
|
||||
if (m_channelListener)
|
||||
rv = m_channelListener->OnStartRequest(this, m_channelContext);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
// stop binding is a "notification" informing us that the stream associated with aURL is going away.
|
||||
NS_IMETHODIMP nsMsgProtocol::OnStopRequest(nsIChannel * aChannel, nsISupports *ctxt, nsresult aStatus, const PRUnichar* aMsg)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr <nsIMsgMailNewsUrl> aMsgUrl = do_QueryInterface(ctxt, &rv);
|
||||
if (NS_SUCCEEDED(rv) && aMsgUrl)
|
||||
rv = aMsgUrl->SetUrlState(PR_FALSE, aStatus);
|
||||
|
||||
// if we are set up as a channel, we should notify our channel listener that we are starting...
|
||||
// so pass in ourself as the channel and not the underlying socket or file channel the protocol
|
||||
// happens to be using
|
||||
if (m_channelListener)
|
||||
rv = m_channelListener->OnStopRequest(this, m_channelContext, aStatus, aMsg);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult nsMsgProtocol::LoadUrl(nsIURI * aURL, nsISupports * aConsumer)
|
||||
{
|
||||
// okay now kick us off to the next state...
|
||||
// our first state is a process state so drive the state machine...
|
||||
nsresult rv = NS_OK;
|
||||
nsCOMPtr <nsIMsgMailNewsUrl> aMsgUrl = do_QueryInterface(aURL);
|
||||
|
||||
if (NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = aMsgUrl->SetUrlState(PR_TRUE, NS_OK); // set the url as a url currently being run...
|
||||
|
||||
// if the url is given a stream consumer then we should use it to forward calls to...
|
||||
if (!m_channelListener && aConsumer) // if we don't have a registered listener already
|
||||
{
|
||||
m_channelListener = do_QueryInterface(aConsumer);
|
||||
if (!m_channelContext)
|
||||
m_channelContext = do_QueryInterface(aURL);
|
||||
}
|
||||
|
||||
if (!m_socketIsOpen)
|
||||
{
|
||||
nsCOMPtr<nsISupports> urlSupports = do_QueryInterface(aURL);
|
||||
|
||||
// put us in a state where we are always notified of incoming data
|
||||
m_channel->AsyncRead(m_startPosition, m_readCount, urlSupports ,this /* stream observer */);
|
||||
m_socketIsOpen = PR_TRUE; // mark the channel as open
|
||||
} // if we got an event queue service
|
||||
else // the connection is already open so we should begin processing our new url...
|
||||
rv = ProcessProtocolState(aURL, nsnull, 0, 0);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
// The rest of this file is mostly nsIChannel mumbo jumbo stuff
|
||||
///////////////////////////////////////////////////////////////////////
|
||||
|
||||
nsresult nsMsgProtocol::SetUrl(nsIURI * aURL)
|
||||
{
|
||||
m_url = dont_QueryInterface(aURL);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsresult nsMsgProtocol::SetLoadGroup(nsILoadGroup * aLoadGroup)
|
||||
{
|
||||
m_loadGroup = dont_QueryInterface(aLoadGroup);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::GetURI(nsIURI * *aURI)
|
||||
{
|
||||
nsresult rv = NS_OK;
|
||||
if (aURI)
|
||||
{
|
||||
if (m_url)
|
||||
rv = m_url->QueryInterface(NS_GET_IID(nsIURI), (void **) aURI);
|
||||
else
|
||||
*aURI = nsnull;
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_NULL_POINTER;
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::OpenInputStream(PRUint32 startPosition, PRInt32 readCount, nsIInputStream **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::OpenOutputStream(PRUint32 startPosition, nsIOutputStream **_retval)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::AsyncOpen(nsIStreamObserver *observer, nsISupports* ctxt)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::AsyncRead(PRUint32 startPosition, PRInt32 readCount, nsISupports *ctxt, nsIStreamListener *listener)
|
||||
{
|
||||
// set the stream listener and then load the url
|
||||
m_channelContext = ctxt;
|
||||
m_channelListener = listener;
|
||||
|
||||
// the following load group code is completely bogus....
|
||||
nsresult rv = NS_OK;
|
||||
if (m_loadGroup)
|
||||
{
|
||||
nsCOMPtr<nsILoadGroupListenerFactory> factory;
|
||||
//
|
||||
// Create a load group "proxy" listener...
|
||||
//
|
||||
rv = m_loadGroup->GetGroupListenerFactory(getter_AddRefs(factory));
|
||||
if (factory)
|
||||
{
|
||||
nsCOMPtr<nsIStreamListener> newListener;
|
||||
rv = factory->CreateLoadGroupListener(m_channelListener, getter_AddRefs(newListener));
|
||||
if (NS_SUCCEEDED(rv))
|
||||
m_channelListener = newListener;
|
||||
}
|
||||
} // if aLoadGroup
|
||||
|
||||
return LoadUrl(m_url, nsnull);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::AsyncWrite(nsIInputStream *fromStream, PRUint32 startPosition, PRInt32 writeCount, nsISupports *ctxt, nsIStreamObserver *observer)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::GetLoadAttributes(nsLoadFlags *aLoadAttributes)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::SetLoadAttributes(nsLoadFlags aLoadAttributes)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::GetContentType(char * *aContentType)
|
||||
{
|
||||
*aContentType = nsCRT::strdup("message/rfc822");
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::GetContentLength(PRInt32 * aContentLength)
|
||||
{
|
||||
*aContentLength = -1;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::GetOwner(nsISupports * *aPrincipal)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::SetOwner(nsISupports * aPrincipal)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::GetLoadGroup(nsILoadGroup * *aLoadGroup)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// From nsIRequest
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::IsPending(PRBool *result)
|
||||
{
|
||||
*result = PR_TRUE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::Cancel()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::Suspend()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgProtocol::Resume()
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
108
mozilla/mailnews/base/util/nsMsgProtocol.h
Normal file
108
mozilla/mailnews/base/util/nsMsgProtocol.h
Normal file
@@ -0,0 +1,108 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 nsMsgProtocol_h__
|
||||
#define nsMsgProtocol_h__
|
||||
|
||||
#include "nsIStreamListener.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIOutputStream.h"
|
||||
#include "nsIEventQueue.h"
|
||||
#include "nsIChannel.h"
|
||||
#include "nsIURL.h"
|
||||
#include "nsILoadGroup.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
// This is a helper class used to encapsulate code shared between all of the
|
||||
// mailnews protocol objects (imap, news, pop, smtp, etc.) In particular,
|
||||
// it unifies the core networking code for the protocols. My hope is that
|
||||
// this will make unification with Necko easier as we'll only have to change
|
||||
// this class and not all of the mailnews protocols.
|
||||
class NS_MSG_BASE nsMsgProtocol : public nsIStreamListener, public nsIChannel
|
||||
{
|
||||
public:
|
||||
nsMsgProtocol();
|
||||
virtual ~nsMsgProtocol();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
// nsIChannel support
|
||||
NS_DECL_NSICHANNEL
|
||||
NS_DECL_NSIREQUEST
|
||||
|
||||
NS_DECL_NSISTREAMLISTENER
|
||||
NS_DECL_NSISTREAMOBSERVER
|
||||
|
||||
// LoadUrl -- A protocol typically overrides this function, sets up any local state for the url and
|
||||
// then calls the base class which opens the socket if it needs opened. If the socket is
|
||||
// already opened then we just call ProcessProtocolState to start the churning process.
|
||||
// aConsumer is the consumer for the url. It can be null if this argument is not appropriate
|
||||
virtual nsresult LoadUrl(nsIURI * aURL, nsISupports * aConsumer = nsnull);
|
||||
|
||||
virtual nsresult SetUrl(nsIURI * aURL); // sometimes we want to set the url before we load it
|
||||
virtual nsresult SetLoadGroup(nsILoadGroup * aLoadGroup);
|
||||
|
||||
// Flag manipulators
|
||||
PRBool TestFlag (PRUint32 flag) {return flag & m_flags;}
|
||||
void SetFlag (PRUint32 flag) { m_flags |= flag; }
|
||||
void ClearFlag (PRUint32 flag) { m_flags &= ~flag; }
|
||||
|
||||
protected:
|
||||
// methods for opening and closing a socket with core netlib....
|
||||
// mscott -okay this is lame. I should break this up into a file protocol and a socket based
|
||||
// protocool class instead of cheating and putting both methods here...
|
||||
virtual nsresult OpenNetworkSocket(nsIURI * aURL); // open a connection on this url
|
||||
virtual nsresult OpenFileSocket(nsIURI * aURL, const nsFileSpec * aFileSpec, PRUint32 aStartPosition, PRInt32 aReadCount); // used to open a file socket connection
|
||||
|
||||
// a Protocol typically overrides this method. They free any of their own connection state and then
|
||||
// they call up into the base class to free the generic connection objects
|
||||
virtual nsresult CloseSocket();
|
||||
|
||||
virtual nsresult SetupTransportState(); // private method used by OpenNetworkSocket and OpenFileSocket
|
||||
|
||||
// ProcessProtocolState - This is the function that gets churned by calls to OnDataAvailable.
|
||||
// As data arrives on the socket, OnDataAvailable calls ProcessProtocolState.
|
||||
|
||||
virtual nsresult ProcessProtocolState(nsIURI * url, nsIInputStream * inputStream,
|
||||
PRUint32 sourceOffset, PRUint32 length) = 0;
|
||||
|
||||
// SendData -- Writes the data contained in dataBuffer into the current output stream.
|
||||
// It also informs the transport layer that this data is now available for transmission.
|
||||
// Returns a positive number for success, 0 for failure (not all the bytes were written to the
|
||||
// stream, etc).
|
||||
virtual PRInt32 SendData(nsIURI * aURL, const char * dataBuffer);
|
||||
|
||||
// Ouput stream for writing commands to the socket
|
||||
nsCOMPtr<nsIChannel> m_channel;
|
||||
nsCOMPtr<nsIOutputStream> m_outputStream; // this will be obtained from the transport interface
|
||||
|
||||
PRBool m_socketIsOpen; // mscott: we should look into keeping this state in the nsSocketTransport...
|
||||
// I'm using it to make sure I open the socket the first time a URL is loaded into the connection
|
||||
PRUint32 m_flags; // used to store flag information
|
||||
PRUint32 m_startPosition;
|
||||
PRInt32 m_readCount;
|
||||
|
||||
nsFileSpec m_tempMsgFileSpec; // we currently have a hack where displaying a msg involves writing it to a temp file first
|
||||
|
||||
// the following is a catch all for nsIChannel related data
|
||||
nsCOMPtr<nsIURI> m_url; // the running url
|
||||
nsCOMPtr<nsIStreamListener> m_channelListener;
|
||||
nsCOMPtr<nsISupports> m_channelContext;
|
||||
nsCOMPtr<nsILoadGroup> m_loadGroup;
|
||||
};
|
||||
|
||||
#endif /* nsMsgProtocol_h__ */
|
||||
99
mozilla/mailnews/base/util/nsMsgTxn.cpp
Normal file
99
mozilla/mailnews/base/util/nsMsgTxn.cpp
Normal file
@@ -0,0 +1,99 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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, 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsMsgTxn.h"
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kITransactionIID, NS_ITRANSACTION_IID);
|
||||
|
||||
NS_IMPL_ADDREF(nsMsgTxn)
|
||||
NS_IMPL_RELEASE(nsMsgTxn)
|
||||
|
||||
// note that aEditor is not refcounted
|
||||
nsMsgTxn::nsMsgTxn()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
}
|
||||
|
||||
nsMsgTxn::~nsMsgTxn()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgTxn::Do(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgTxn::GetIsTransient(PRBool *aIsTransient)
|
||||
{
|
||||
if (nsnull!=aIsTransient)
|
||||
*aIsTransient = PR_FALSE;
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgTxn::Merge(PRBool *aDidMerge, nsITransaction *aTransaction)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgTxn::Write(nsIOutputStream *aOutputStream)
|
||||
{
|
||||
return NS_ERROR_NOT_IMPLEMENTED;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgTxn::GetUndoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
*aString="Undo";
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMsgTxn::GetRedoString(nsString *aString)
|
||||
{
|
||||
if (nsnull!=aString)
|
||||
*aString="Redo";
|
||||
else
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
nsMsgTxn::QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (NULL == aInstancePtr) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aInstancePtr = (void*)(nsISupports*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
if (aIID.Equals(kITransactionIID)) {
|
||||
*aInstancePtr = (void*)(nsITransaction*)this;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
*aInstancePtr = 0;
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
57
mozilla/mailnews/base/util/nsMsgTxn.h
Normal file
57
mozilla/mailnews/base/util/nsMsgTxn.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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, 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsMsgTxn_h__
|
||||
#define nsMsgTxn_h__
|
||||
|
||||
#include "nsITransaction.h"
|
||||
#include "msgCore.h"
|
||||
|
||||
#define NS_MESSAGETRANSACTION_IID \
|
||||
{ /* da621b30-1efc-11d3-abe4-00805f8ac968 */ \
|
||||
0xda621b30, 0x1efc, 0x11d3, \
|
||||
{ 0xab, 0xe4, 0x00, 0x80, 0x5f, 0x8a, 0xc9, 0x68 } }
|
||||
/**
|
||||
* base class for all message undo/redo transactions.
|
||||
*/
|
||||
class NS_MSG_BASE nsMsgTxn : public nsITransaction
|
||||
{
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsMsgTxn();
|
||||
virtual ~nsMsgTxn();
|
||||
|
||||
NS_IMETHOD Do(void);
|
||||
|
||||
NS_IMETHOD Undo(void) = 0;
|
||||
|
||||
NS_IMETHOD Redo(void) = 0;
|
||||
|
||||
NS_IMETHOD GetIsTransient(PRBool *aIsTransient);
|
||||
|
||||
NS_IMETHOD Merge(PRBool *aDidMerge, nsITransaction *aTransaction);
|
||||
|
||||
NS_IMETHOD Write(nsIOutputStream *aOutputStream);
|
||||
|
||||
NS_IMETHOD GetUndoString(nsString *aString);
|
||||
|
||||
NS_IMETHOD GetRedoString(nsString *aString);
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
326
mozilla/mailnews/base/util/nsMsgUtils.cpp
Normal file
326
mozilla/mailnews/base/util/nsMsgUtils.cpp
Normal file
@@ -0,0 +1,326 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "msgCore.h"
|
||||
#include "nsIMessage.h"
|
||||
#include "nsIMsgHdr.h"
|
||||
#include "nsMsgUtils.h"
|
||||
#include "nsString.h"
|
||||
#include "nsFileSpec.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsCOMPtr.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIImapUrl.h"
|
||||
#include "nsIMailboxUrl.h"
|
||||
#include "nsINntpUrl.h"
|
||||
#include "nsMsgNewsCID.h"
|
||||
#include "nsMsgLocalCID.h"
|
||||
#include "nsMsgBaseCID.h"
|
||||
#include "nsMsgImapCID.h"
|
||||
|
||||
static NS_DEFINE_CID(kImapUrlCID, NS_IMAPURL_CID);
|
||||
static NS_DEFINE_CID(kCMailboxUrl, NS_MAILBOXURL_CID);
|
||||
static NS_DEFINE_CID(kCNntpUrlCID, NS_NNTPURL_CID);
|
||||
|
||||
#if defined(DEBUG_sspitzer_) || defined(DEBUG_seth_)
|
||||
#define DEBUG_NS_MsgHashIfNecessary 1
|
||||
#endif
|
||||
|
||||
nsresult GetMessageServiceProgIDForURI(const char *uri, nsString &progID)
|
||||
{
|
||||
|
||||
nsresult rv = NS_OK;
|
||||
//Find protocol
|
||||
nsString uriStr = uri;
|
||||
PRInt32 pos = uriStr.FindChar(':');
|
||||
if(pos == -1)
|
||||
return NS_ERROR_FAILURE;
|
||||
nsString protocol;
|
||||
uriStr.Left(protocol, pos);
|
||||
|
||||
//Build message service progid
|
||||
progID = "component://netscape/messenger/messageservice;type=";
|
||||
progID += protocol;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
nsresult GetMessageServiceFromURI(const char *uri, nsIMsgMessageService **messageService)
|
||||
{
|
||||
|
||||
nsAutoString progID;
|
||||
nsresult rv;
|
||||
|
||||
rv = GetMessageServiceProgIDForURI(uri, progID);
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = nsServiceManager::GetService((const char *) nsCAutoString(progID), nsCOMTypeInfo<nsIMsgMessageService>::GetIID(),
|
||||
(nsISupports**)messageService, nsnull);
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult ReleaseMessageServiceFromURI(const char *uri, nsIMsgMessageService *messageService)
|
||||
{
|
||||
nsAutoString progID;
|
||||
nsresult rv;
|
||||
|
||||
rv = GetMessageServiceProgIDForURI(uri, progID);
|
||||
if(NS_SUCCEEDED(rv))
|
||||
rv = nsServiceManager::ReleaseService(nsCAutoString(progID), messageService);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
nsresult CreateStartupUrl(char *uri, nsIURI** aUrl)
|
||||
{
|
||||
nsresult rv = NS_ERROR_NULL_POINTER;
|
||||
if (!uri || !*uri || !aUrl) return rv;
|
||||
*aUrl = nsnull;
|
||||
if (PL_strncasecmp(uri, "imap", 4) == 0)
|
||||
{
|
||||
nsCOMPtr<nsIImapUrl> imapUrl;
|
||||
rv = nsComponentManager::CreateInstance(kImapUrlCID, nsnull,
|
||||
nsIImapUrl::GetIID(),
|
||||
getter_AddRefs(imapUrl));
|
||||
if (NS_SUCCEEDED(rv) && imapUrl)
|
||||
rv = imapUrl->QueryInterface(nsCOMTypeInfo<nsIURI>::GetIID(),
|
||||
(void**) aUrl);
|
||||
}
|
||||
else if (PL_strncasecmp(uri, "mailbox", 7) == 0)
|
||||
{
|
||||
nsCOMPtr<nsIMailboxUrl> mailboxUrl;
|
||||
rv = nsComponentManager::CreateInstance(kCMailboxUrl, nsnull,
|
||||
nsIMailboxUrl::GetIID(),
|
||||
getter_AddRefs(mailboxUrl));
|
||||
if (NS_SUCCEEDED(rv) && mailboxUrl)
|
||||
rv = mailboxUrl->QueryInterface(nsCOMTypeInfo<nsIURI>::GetIID(),
|
||||
(void**) aUrl);
|
||||
}
|
||||
else if (PL_strncasecmp(uri, "news", 4) == 0)
|
||||
{
|
||||
nsCOMPtr<nsINntpUrl> nntpUrl;
|
||||
rv = nsComponentManager::CreateInstance(kCNntpUrlCID, nsnull,
|
||||
nsINntpUrl::GetIID(),
|
||||
getter_AddRefs(nntpUrl));
|
||||
if (NS_SUCCEEDED(rv) && nntpUrl)
|
||||
rv = nntpUrl->QueryInterface(nsCOMTypeInfo<nsIURI>::GetIID(),
|
||||
(void**) aUrl);
|
||||
}
|
||||
if (*aUrl)
|
||||
(*aUrl)->SetSpec(uri);
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsMessageFromMsgHdrEnumerator, nsCOMTypeInfo<nsISimpleEnumerator>::GetIID())
|
||||
|
||||
nsMessageFromMsgHdrEnumerator::nsMessageFromMsgHdrEnumerator(nsISimpleEnumerator *srcEnumerator,
|
||||
nsIMsgFolder *folder)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mSrcEnumerator = dont_QueryInterface(srcEnumerator);
|
||||
mFolder = dont_QueryInterface(folder);
|
||||
|
||||
}
|
||||
|
||||
nsMessageFromMsgHdrEnumerator::~nsMessageFromMsgHdrEnumerator()
|
||||
{
|
||||
//member variables are nsCOMPtr's
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsMessageFromMsgHdrEnumerator::GetNext(nsISupports **aItem)
|
||||
{
|
||||
nsCOMPtr<nsISupports> currentItem;
|
||||
nsCOMPtr<nsIMsgDBHdr> msgDBHdr;
|
||||
nsCOMPtr<nsIMessage> message;
|
||||
nsresult rv;
|
||||
|
||||
rv = mSrcEnumerator->GetNext(getter_AddRefs(currentItem));
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
msgDBHdr = do_QueryInterface(currentItem, &rv);
|
||||
}
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
rv = mFolder->CreateMessageFromMsgDBHdr(msgDBHdr, getter_AddRefs(message));
|
||||
}
|
||||
|
||||
if(NS_SUCCEEDED(rv))
|
||||
{
|
||||
currentItem = do_QueryInterface(message, &rv);
|
||||
*aItem = currentItem;
|
||||
NS_IF_ADDREF(*aItem);
|
||||
}
|
||||
|
||||
NS_ASSERTION(NS_SUCCEEDED(rv),"getnext shouldn't fail");
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsMessageFromMsgHdrEnumerator::HasMoreElements(PRBool *aResult)
|
||||
{
|
||||
return mSrcEnumerator->HasMoreElements(aResult);
|
||||
}
|
||||
|
||||
nsresult NS_NewMessageFromMsgHdrEnumerator(nsISimpleEnumerator *srcEnumerator,
|
||||
nsIMsgFolder *folder,
|
||||
nsMessageFromMsgHdrEnumerator **messageEnumerator)
|
||||
{
|
||||
if(!messageEnumerator)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
*messageEnumerator = new nsMessageFromMsgHdrEnumerator(srcEnumerator, folder);
|
||||
|
||||
if(!messageEnumerator)
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
NS_ADDREF(*messageEnumerator);
|
||||
return NS_OK;
|
||||
|
||||
}
|
||||
|
||||
// Where should this live? It's a utility used to convert a string priority, e.g., "High, Low, Normal" to an enum.
|
||||
// Perhaps we should have an interface that groups together all these utilities...
|
||||
nsresult NS_MsgGetPriorityFromString(const char *priority, nsMsgPriority *outPriority)
|
||||
{
|
||||
if (!outPriority)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
nsMsgPriority retPriority = nsMsgPriorityNormal;
|
||||
|
||||
if (PL_strcasestr(priority, "Normal") != NULL)
|
||||
retPriority = nsMsgPriorityNormal;
|
||||
else if (PL_strcasestr(priority, "Lowest") != NULL)
|
||||
retPriority = nsMsgPriorityLowest;
|
||||
else if (PL_strcasestr(priority, "Highest") != NULL)
|
||||
retPriority = nsMsgPriorityHighest;
|
||||
else if (PL_strcasestr(priority, "High") != NULL ||
|
||||
PL_strcasestr(priority, "Urgent") != NULL)
|
||||
retPriority = nsMsgPriorityHigh;
|
||||
else if (PL_strcasestr(priority, "Low") != NULL ||
|
||||
PL_strcasestr(priority, "Non-urgent") != NULL)
|
||||
retPriority = nsMsgPriorityLow;
|
||||
else if (PL_strcasestr(priority, "1") != NULL)
|
||||
retPriority = nsMsgPriorityHighest;
|
||||
else if (PL_strcasestr(priority, "2") != NULL)
|
||||
retPriority = nsMsgPriorityHigh;
|
||||
else if (PL_strcasestr(priority, "3") != NULL)
|
||||
retPriority = nsMsgPriorityNormal;
|
||||
else if (PL_strcasestr(priority, "4") != NULL)
|
||||
retPriority = nsMsgPriorityLow;
|
||||
else if (PL_strcasestr(priority, "5") != NULL)
|
||||
retPriority = nsMsgPriorityLowest;
|
||||
else
|
||||
retPriority = nsMsgPriorityNormal;
|
||||
*outPriority = retPriority;
|
||||
return NS_OK;
|
||||
//return nsMsgNoPriority;
|
||||
}
|
||||
|
||||
|
||||
nsresult NS_MsgGetUntranslatedPriorityName (nsMsgPriority p, nsString *outName)
|
||||
{
|
||||
if (!outName)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
switch (p)
|
||||
{
|
||||
case nsMsgPriorityNotSet:
|
||||
case nsMsgPriorityNone:
|
||||
*outName = "None";
|
||||
break;
|
||||
case nsMsgPriorityLowest:
|
||||
*outName = "Lowest";
|
||||
break;
|
||||
case nsMsgPriorityLow:
|
||||
*outName = "Low";
|
||||
break;
|
||||
case nsMsgPriorityNormal:
|
||||
*outName = "Normal";
|
||||
break;
|
||||
case nsMsgPriorityHigh:
|
||||
*outName = "High";
|
||||
break;
|
||||
case nsMsgPriorityHighest:
|
||||
*outName = "Highest";
|
||||
break;
|
||||
default:
|
||||
NS_ASSERTION(PR_FALSE, "invalid priority value");
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* this used to be XP_StringHash2 from xp_hash.c */
|
||||
/* phong's linear congruential hash */
|
||||
static PRUint32 StringHash(const char *ubuf)
|
||||
{
|
||||
unsigned char * buf = (unsigned char*) ubuf;
|
||||
PRUint32 h=1;
|
||||
while(*buf) {
|
||||
h = 0x63c63cd9*h + 0x9c39c33d + (int32)*buf;
|
||||
buf++;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
nsresult NS_MsgHashIfNecessary(nsCAutoString &name)
|
||||
{
|
||||
#if defined(XP_WIN16) || defined(XP_OS2)
|
||||
const PRUint32 MAX_LEN = 8;
|
||||
#elif defined(XP_MAC)
|
||||
const PRUint32 MAX_LEN = 25;
|
||||
#elif defined(XP_UNIX) || defined(XP_PC) || defined(XP_BEOS)
|
||||
const PRUint32 MAX_LEN = 55;
|
||||
#else
|
||||
#error need_to_define_your_max_filename_length
|
||||
#endif
|
||||
nsCAutoString str(name);
|
||||
|
||||
#ifdef DEBUG_NS_MsgHashIfNecessary
|
||||
printf("in: %s\n",str.GetBuffer());
|
||||
#endif
|
||||
|
||||
// Given a name, use either that name, if it fits on our
|
||||
// filesystem, or a hashified version of it, if the name is too
|
||||
// long to fit.
|
||||
char hashedname[MAX_LEN + 1];
|
||||
PRBool needshash = PL_strlen(str.GetBuffer()) > MAX_LEN;
|
||||
#if defined(XP_WIN16) || defined(XP_OS2)
|
||||
if (!needshash) {
|
||||
needshash = PL_strchr(str.GetBuffer(), '.') != NULL ||
|
||||
PL_strchr(str.GetBuffer(), ':') != NULL;
|
||||
}
|
||||
#endif
|
||||
PL_strncpy(hashedname, str.GetBuffer(), MAX_LEN + 1);
|
||||
if (needshash) {
|
||||
PR_snprintf(hashedname + MAX_LEN - 8, 9, "%08lx",
|
||||
(unsigned long) StringHash(str.GetBuffer()));
|
||||
}
|
||||
name = hashedname;
|
||||
#ifdef DEBUG_NS_MsgHashIfNecessary
|
||||
printf("out: %s\n",hashedname);
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
67
mozilla/mailnews/base/util/nsMsgUtils.h
Normal file
67
mozilla/mailnews/base/util/nsMsgUtils.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _NSMSGUTILS_H
|
||||
#define _NSMSGUTILS_H
|
||||
|
||||
#include "nsIURL.h"
|
||||
#include "nsIMsgMessageService.h"
|
||||
#include "nsString.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "nsIMsgFolder.h"
|
||||
#include "msgCore.h"
|
||||
#include "nsCOMPtr.h"
|
||||
|
||||
//These are utility functions that can used throughout the mailnews code
|
||||
|
||||
//Utilities for getting a message service.
|
||||
NS_MSG_BASE nsresult GetMessageServiceProgIDForURI(const char *uri, nsString &progID);
|
||||
//Use ReleaseMessageServiceFromURI to release the service.
|
||||
NS_MSG_BASE nsresult GetMessageServiceFromURI(const char *uri, nsIMsgMessageService **messageService);
|
||||
NS_MSG_BASE nsresult ReleaseMessageServiceFromURI(const char *uri, nsIMsgMessageService *messageService);
|
||||
|
||||
NS_MSG_BASE nsresult CreateStartupUrl(char *uri, nsIURI** aUrl);
|
||||
|
||||
//An enumerator for converting nsIMsgHdrs to nsIMessages.
|
||||
class NS_MSG_BASE nsMessageFromMsgHdrEnumerator: public nsISimpleEnumerator
|
||||
{
|
||||
protected:
|
||||
nsCOMPtr<nsISimpleEnumerator> mSrcEnumerator;
|
||||
nsCOMPtr<nsIMsgFolder> mFolder;
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
nsMessageFromMsgHdrEnumerator(nsISimpleEnumerator *srcEnumerator, nsIMsgFolder *folder);
|
||||
nsMessageFromMsgHdrEnumerator(){} //Default constructor that does nothing so nsComPtr will work.
|
||||
virtual ~nsMessageFromMsgHdrEnumerator();
|
||||
|
||||
NS_DECL_NSISIMPLEENUMERATOR
|
||||
};
|
||||
|
||||
NS_MSG_BASE nsresult NS_NewMessageFromMsgHdrEnumerator(nsISimpleEnumerator *srcEnumerator,
|
||||
nsIMsgFolder *folder,
|
||||
nsMessageFromMsgHdrEnumerator **messageEnumerator);
|
||||
|
||||
NS_MSG_BASE nsresult NS_MsgGetPriorityFromString(const char *priority, nsMsgPriority *outPriority);
|
||||
|
||||
NS_MSG_BASE nsresult NS_MsgGetUntranslatedPriorityName (nsMsgPriority p, nsString *outName);
|
||||
|
||||
NS_MSG_BASE nsresult NS_MsgHashIfNecessary(nsCAutoString &name);
|
||||
|
||||
#endif
|
||||
|
||||
71
mozilla/mailnews/base/util/nsNewsSummarySpec.cpp
Normal file
71
mozilla/mailnews/base/util/nsNewsSummarySpec.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsNewsSummarySpec.h"
|
||||
#include "plstr.h"
|
||||
#include "nsString.h"
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsNewsSummarySpec);
|
||||
|
||||
nsNewsSummarySpec::~nsNewsSummarySpec()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsNewsSummarySpec);
|
||||
}
|
||||
|
||||
nsNewsSummarySpec::nsNewsSummarySpec()
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsNewsSummarySpec);
|
||||
}
|
||||
|
||||
nsNewsSummarySpec::nsNewsSummarySpec(const char *folderPath)
|
||||
: nsFileSpec(folderPath)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsNewsSummarySpec);
|
||||
CreateSummaryFileName();
|
||||
}
|
||||
|
||||
nsNewsSummarySpec::nsNewsSummarySpec(const nsFileSpec& inFolderPath)
|
||||
: nsFileSpec(inFolderPath)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsNewsSummarySpec);
|
||||
CreateSummaryFileName();
|
||||
}
|
||||
|
||||
nsNewsSummarySpec::nsNewsSummarySpec(const nsFilePath &inFolderPath) : nsFileSpec(inFolderPath)
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsNewsSummarySpec);
|
||||
CreateSummaryFileName();
|
||||
}
|
||||
|
||||
void nsNewsSummarySpec::SetFolderName(const char *folderPath)
|
||||
{
|
||||
*this = folderPath;
|
||||
}
|
||||
|
||||
void nsNewsSummarySpec::CreateSummaryFileName()
|
||||
{
|
||||
char *leafName = GetLeafName();
|
||||
|
||||
nsCAutoString fullLeafName((const char*)leafName);
|
||||
|
||||
// Append .msf (message summary file)
|
||||
fullLeafName += ".msf";
|
||||
|
||||
SetLeafName(fullLeafName.GetBuffer());
|
||||
PL_strfree(leafName);
|
||||
}
|
||||
45
mozilla/mailnews/base/util/nsNewsSummarySpec.h
Normal file
45
mozilla/mailnews/base/util/nsNewsSummarySpec.h
Normal file
@@ -0,0 +1,45 @@
|
||||
/* -*- 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef _nsNewsSummarySpec_H
|
||||
#define _nsNewsSummarySpec_H
|
||||
|
||||
#include "nsFileSpec.h"
|
||||
#include "msgCore.h"
|
||||
|
||||
// Class to name a summary file for a newsgroup,
|
||||
// given a full folder file spec.
|
||||
// Note this class expects the invoking code to fully specify the folder path.
|
||||
// This class does NOT prepend the local folder directory, or put .sbd on the containing
|
||||
// directory names.
|
||||
class NS_MSG_BASE nsNewsSummarySpec : public nsFileSpec
|
||||
{
|
||||
public:
|
||||
nsNewsSummarySpec();
|
||||
nsNewsSummarySpec(const char *folderPath);
|
||||
nsNewsSummarySpec(const nsFileSpec& inFolderPath);
|
||||
nsNewsSummarySpec(const nsFilePath &inFolderPath);
|
||||
~nsNewsSummarySpec();
|
||||
void SetFolderName(const char *folderPath);
|
||||
|
||||
protected:
|
||||
void CreateSummaryFileName();
|
||||
|
||||
};
|
||||
|
||||
#endif /* _nsNewsSummarySpec_H */
|
||||
277
mozilla/mailnews/base/util/nsUInt32Array.cpp
Normal file
277
mozilla/mailnews/base/util/nsUInt32Array.cpp
Normal file
@@ -0,0 +1,277 @@
|
||||
/* -*- 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 "msgCore.h" // precompiled header...
|
||||
#include "prlog.h"
|
||||
|
||||
#include "MailNewsTypes.h"
|
||||
#include "nsUInt32Array.h"
|
||||
#include "nsQuickSort.h"
|
||||
|
||||
MOZ_DECL_CTOR_COUNTER(nsUInt32Array);
|
||||
|
||||
nsUInt32Array::nsUInt32Array()
|
||||
{
|
||||
MOZ_COUNT_CTOR(nsUInt32Array);
|
||||
m_nSize = 0;
|
||||
m_nMaxSize = 0;
|
||||
m_nGrowBy = 0;
|
||||
m_pData = NULL;
|
||||
}
|
||||
|
||||
nsUInt32Array::~nsUInt32Array()
|
||||
{
|
||||
MOZ_COUNT_DTOR(nsUInt32Array);
|
||||
SetSize(0);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRUint32 nsUInt32Array::GetSize() const
|
||||
{
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
PRBool nsUInt32Array::SetSize(PRUint32 nSize,
|
||||
PRBool adjustGrowth,
|
||||
PRUint32 nGrowBy)
|
||||
{
|
||||
if (adjustGrowth)
|
||||
m_nGrowBy = nGrowBy;
|
||||
|
||||
#ifdef MAX_ARR_ELEMS
|
||||
if (nSize > MAX_ARR_ELEMS);
|
||||
{
|
||||
PR_ASSERT(nSize <= MAX_ARR_ELEMS); // Will fail
|
||||
return PR_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
if (nSize == 0)
|
||||
{
|
||||
// Remove all elements
|
||||
PR_Free(m_pData);
|
||||
m_nSize = 0;
|
||||
m_nMaxSize = 0;
|
||||
m_pData = NULL;
|
||||
}
|
||||
else if (m_pData == NULL)
|
||||
{
|
||||
// Create a new array
|
||||
m_nMaxSize = PR_MAX(8, nSize);
|
||||
m_pData = (PRUint32 *)PR_Calloc(1, m_nMaxSize * sizeof(PRUint32));
|
||||
if (m_pData)
|
||||
m_nSize = nSize;
|
||||
else
|
||||
m_nSize = m_nMaxSize = 0;
|
||||
}
|
||||
else if (nSize <= m_nMaxSize)
|
||||
{
|
||||
// The new size is within the current maximum size, make sure new
|
||||
// elements are to initialized to zero
|
||||
if (nSize > m_nSize)
|
||||
nsCRT::memset(&m_pData[m_nSize], 0, (nSize - m_nSize) * sizeof(PRUint32));
|
||||
|
||||
m_nSize = nSize;
|
||||
}
|
||||
else
|
||||
{
|
||||
// The array needs to grow, figure out how much
|
||||
PRUint32 nMaxSize;
|
||||
nGrowBy = PR_MAX(m_nGrowBy, PR_MIN(1024, PR_MAX(8, m_nSize / 8)));
|
||||
nMaxSize = PR_MAX(nSize, m_nMaxSize + nGrowBy);
|
||||
#ifdef MAX_ARR_ELEMS
|
||||
nMaxSize = PR_MIN(MAX_ARR_ELEMS, nMaxSize);
|
||||
#endif
|
||||
|
||||
PRUint32 *pNewData = (PRUint32 *)PR_Malloc(nMaxSize * sizeof(PRUint32));
|
||||
if (pNewData)
|
||||
{
|
||||
// Copy the data from the old array to the new one
|
||||
nsCRT::memcpy(pNewData, m_pData, m_nSize * sizeof(PRUint32));
|
||||
|
||||
// Zero out the remaining elements
|
||||
nsCRT::memset(&pNewData[m_nSize], 0, (nSize - m_nSize) * sizeof(PRUint32));
|
||||
m_nSize = nSize;
|
||||
m_nMaxSize = nMaxSize;
|
||||
|
||||
// Free the old array
|
||||
PR_Free(m_pData);
|
||||
m_pData = pNewData;
|
||||
}
|
||||
}
|
||||
|
||||
return nSize == m_nSize;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRUint32 &nsUInt32Array::ElementAt(PRUint32 nIndex)
|
||||
{
|
||||
PR_ASSERT(nIndex < m_nSize);
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
PRUint32 nsUInt32Array::GetAt(PRUint32 nIndex) const
|
||||
{
|
||||
PR_ASSERT(nIndex < m_nSize);
|
||||
return m_pData[nIndex];
|
||||
}
|
||||
|
||||
PRUint32 *nsUInt32Array::GetData()
|
||||
{
|
||||
return m_pData;
|
||||
}
|
||||
|
||||
void nsUInt32Array::SetAt(PRUint32 nIndex, PRUint32 newElement)
|
||||
{
|
||||
PR_ASSERT(nIndex < m_nSize);
|
||||
m_pData[nIndex] = newElement;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
PRUint32 nsUInt32Array::Add(PRUint32 newElement)
|
||||
{
|
||||
PRUint32 nIndex = m_nSize;
|
||||
|
||||
#ifdef MAX_ARR_ELEMS
|
||||
if (nIndex >= MAX_ARR_ELEMS)
|
||||
return -1;
|
||||
#endif
|
||||
|
||||
SetAtGrow(nIndex, newElement);
|
||||
return nIndex;
|
||||
}
|
||||
|
||||
PRUint32 nsUInt32Array::Add(PRUint32 *elementPtr, PRUint32 numElements)
|
||||
{
|
||||
if (SetSize(m_nSize + numElements))
|
||||
nsCRT::memcpy(m_pData + m_nSize, elementPtr, numElements * sizeof(PRUint32));
|
||||
|
||||
return m_nSize;
|
||||
}
|
||||
|
||||
PRUint32 *nsUInt32Array::CloneData()
|
||||
{
|
||||
PRUint32 *copyOfData = (PRUint32 *)PR_Malloc(m_nSize * sizeof(PRUint32));
|
||||
if (copyOfData)
|
||||
nsCRT::memcpy(copyOfData, m_pData, m_nSize * sizeof(PRUint32));
|
||||
|
||||
return copyOfData;
|
||||
}
|
||||
|
||||
void nsUInt32Array::InsertAt(PRUint32 nIndex, PRUint32 newElement, PRUint32 nCount)
|
||||
{
|
||||
PR_ASSERT(nCount > 0);
|
||||
|
||||
if (nIndex >= m_nSize)
|
||||
{
|
||||
// If the new element is after the end of the array, grow the array
|
||||
SetSize(nIndex + nCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
// The element is being insert inside the array
|
||||
int nOldSize = m_nSize;
|
||||
SetSize(m_nSize + nCount);
|
||||
|
||||
// Move the data after the insertion point
|
||||
nsCRT::memmove(&m_pData[nIndex + nCount], &m_pData[nIndex],
|
||||
(nOldSize - nIndex) * sizeof(PRUint32));
|
||||
}
|
||||
|
||||
// Insert the new elements
|
||||
PR_ASSERT(nIndex + nCount <= m_nSize);
|
||||
while (nCount--)
|
||||
m_pData[nIndex++] = newElement;
|
||||
}
|
||||
|
||||
void nsUInt32Array::InsertAt(PRUint32 nStartIndex, const nsUInt32Array *pNewArray)
|
||||
{
|
||||
PR_ASSERT(pNewArray != NULL);
|
||||
|
||||
if (pNewArray->GetSize() > 0)
|
||||
{
|
||||
InsertAt(nStartIndex, pNewArray->GetAt(0), pNewArray->GetSize());
|
||||
for (PRUint32 i = 1; i < pNewArray->GetSize(); i++)
|
||||
m_pData[nStartIndex + i] = pNewArray->GetAt(i);
|
||||
}
|
||||
}
|
||||
|
||||
void nsUInt32Array::RemoveAll()
|
||||
{
|
||||
SetSize(0);
|
||||
}
|
||||
|
||||
void nsUInt32Array::RemoveAt(PRUint32 nIndex, PRUint32 nCount)
|
||||
{
|
||||
PR_ASSERT(nIndex + nCount <= m_nSize);
|
||||
|
||||
if (nCount > 0)
|
||||
{
|
||||
// Make sure not to overstep the end of the array
|
||||
int nMoveCount = m_nSize - (nIndex + nCount);
|
||||
if (nCount && nMoveCount)
|
||||
nsCRT::memmove(&m_pData[nIndex], &m_pData[nIndex + nCount],
|
||||
nMoveCount * sizeof(PRUint32));
|
||||
|
||||
m_nSize -= nCount;
|
||||
}
|
||||
}
|
||||
|
||||
void nsUInt32Array::SetAtGrow(PRUint32 nIndex, PRUint32 newElement)
|
||||
{
|
||||
if (nIndex >= m_nSize)
|
||||
SetSize(nIndex+1);
|
||||
m_pData[nIndex] = newElement;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
void nsUInt32Array::CopyArray(nsUInt32Array *oldA)
|
||||
{
|
||||
CopyArray(*oldA);
|
||||
}
|
||||
|
||||
void nsUInt32Array::CopyArray(nsUInt32Array &oldA)
|
||||
{
|
||||
if (m_pData)
|
||||
PR_Free(m_pData);
|
||||
m_nSize = oldA.m_nSize;
|
||||
m_nMaxSize = oldA.m_nMaxSize;
|
||||
m_pData = (PRUint32 *)PR_Malloc(m_nSize * sizeof(PRUint32));
|
||||
if (m_pData)
|
||||
nsCRT::memcpy(m_pData, oldA.m_pData, m_nSize * sizeof(PRUint32));
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static int CompareDWord (const void *v1, const void *v2, void *)
|
||||
{
|
||||
// QuickSort callback to compare array values
|
||||
PRUint32 i1 = *(PRUint32 *)v1;
|
||||
PRUint32 i2 = *(PRUint32 *)v2;
|
||||
return i1 - i2;
|
||||
}
|
||||
|
||||
void nsUInt32Array::QuickSort (int (*compare) (const void *elem1, const void *elem2, void *data))
|
||||
{
|
||||
if (m_nSize > 1)
|
||||
NS_QuickSort(m_pData, m_nSize, sizeof(void*), compare ? compare : CompareDWord, nsnull);
|
||||
}
|
||||
73
mozilla/mailnews/base/util/nsUInt32Array.h
Normal file
73
mozilla/mailnews/base/util/nsUInt32Array.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* 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 _nsUInt32Array_H_
|
||||
#define _nsUInt32Array_H_
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsCRT.h"
|
||||
#include "prmem.h"
|
||||
#include "msgCore.h"
|
||||
|
||||
class NS_MSG_BASE nsUInt32Array
|
||||
{
|
||||
public:
|
||||
// Construction/destruction
|
||||
nsUInt32Array();
|
||||
virtual ~nsUInt32Array();
|
||||
|
||||
// State/attribute member functions
|
||||
PRUint32 GetSize() const;
|
||||
PRBool SetSize(PRUint32 nNewSize, PRBool AdjustGrowth=PR_FALSE, PRUint32 nGrowBy = 0);
|
||||
|
||||
// Accessor member functions
|
||||
PRUint32 &ElementAt(PRUint32 nIndex);
|
||||
PRUint32 GetAt(PRUint32 nIndex) const;
|
||||
PRUint32 *GetData();
|
||||
void SetAt(PRUint32 nIndex, PRUint32 newElement);
|
||||
|
||||
// Insertion/deletion member functions
|
||||
PRUint32 Add(PRUint32 newElement);
|
||||
PRUint32 Add(PRUint32 *elementPtr, PRUint32 numElements);
|
||||
void InsertAt(PRUint32 nIndex, PRUint32 newElement, PRUint32 nCount = 1);
|
||||
void InsertAt(PRUint32 nStartIndex, const nsUInt32Array *pNewArray);
|
||||
void RemoveAll();
|
||||
void RemoveAt(PRUint32 nIndex, PRUint32 nCount = 1);
|
||||
void SetAtGrow(PRUint32 nIndex, PRUint32 newElement);
|
||||
|
||||
// Sorting member functions
|
||||
void QuickSort(int (*compare) (const void *elem1, const void *elem2, void *) = NULL);
|
||||
|
||||
// Overloaded operators
|
||||
PRUint32 operator[](PRUint32 nIndex) const { return GetAt(nIndex); }
|
||||
PRUint32 &operator[](PRUint32 nIndex) { return ElementAt(nIndex); }
|
||||
|
||||
// Miscellaneous member functions
|
||||
PRUint32 *CloneData();
|
||||
void CopyArray(nsUInt32Array *oldA);
|
||||
void CopyArray(nsUInt32Array &oldA);
|
||||
|
||||
protected:
|
||||
// Member data
|
||||
PRUint32 m_nSize;
|
||||
PRUint32 m_nMaxSize;
|
||||
PRUint32 m_nGrowBy;
|
||||
PRUint32* m_pData;
|
||||
};
|
||||
|
||||
|
||||
#endif // _DWordArray_H_
|
||||
Reference in New Issue
Block a user