Compare commits
1 Commits
tags/start
...
CVS
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c5d6b83e4c |
@@ -1,282 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
#############################################################################
|
||||
# $Id: BB_main.pl,v 1.1.1.1 2000-10-23 20:08:03 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_main.pl
|
||||
#
|
||||
# This is the main control program for the Burst Billing process
|
||||
# It:
|
||||
# 1) Checks the directory setup and permissions.
|
||||
# 2) Archives the log file for the current project.
|
||||
# 3) Launches the Burst Billing program
|
||||
# 4) Runs the monitor program.
|
||||
#
|
||||
# I broke the burst billing and monitor programs out into seperate programs.
|
||||
# This is to handle the event where the burst billing program die's, aborts,
|
||||
# crashes, or whatever - so the main program can run the monitor program afterwards.
|
||||
# Yeah yeah, the main program might crash too, but what can I do...
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
use strict;
|
||||
|
||||
BEGIN {require '../inc/BB_include.pl';}
|
||||
require "$INC_DIR/BB_lib.pl";
|
||||
|
||||
|
||||
##############
|
||||
# Begin Code #
|
||||
##############
|
||||
|
||||
&init_program();
|
||||
|
||||
&run_burst_billing();
|
||||
|
||||
&run_monitor();
|
||||
|
||||
&cleanup_program();
|
||||
|
||||
|
||||
|
||||
###################
|
||||
# Local Functions #
|
||||
###################
|
||||
|
||||
########################################
|
||||
# init_program
|
||||
#
|
||||
# Does program initializations, such as:
|
||||
# - Checking directory permissions
|
||||
# - Archiving the log file
|
||||
# - Opening the new log file
|
||||
########################################
|
||||
sub init_program
|
||||
{
|
||||
&check_if_running();
|
||||
|
||||
&check_directories();
|
||||
|
||||
&check_files();
|
||||
|
||||
&archive_log_file();
|
||||
|
||||
&open_log_file();
|
||||
|
||||
&write_log_file($START_STAMP, "BB_main.pl started");
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# check_if_running
|
||||
#
|
||||
# Checks to see if another copy of the program is running. This is
|
||||
# indicated by the presence of the $IN_PROGRESS_FILE
|
||||
# If it is, the program aborts.
|
||||
#
|
||||
# If it isn't:
|
||||
# 1) The $IN_PROGRESS_FILE is created.
|
||||
# 2) An END routine which removes the $IN_PROGRESS_FILE is evaled. I need
|
||||
# to eval this AFTER the check for the file, otherwise I will remove
|
||||
# the $IN_PROGRESS_FILE for the other program!
|
||||
# Note that this function is not used for contention issues - I'm
|
||||
# fully of aware of the test-and-set race condition.
|
||||
##########################################################################
|
||||
sub check_if_running
|
||||
{
|
||||
my ($ip_fh);
|
||||
|
||||
if ( -f $IN_PROGRESS_FILE )
|
||||
{
|
||||
print STDERR "Another copy of BB_main.pl is currently running\n",
|
||||
"If this is not the case, please remove the ",
|
||||
"$IN_PROGRESS_FILE file and rerun the program.\n",
|
||||
"Aboring program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
|
||||
$ip_fh = new IO::File ">$IN_PROGRESS_FILE";
|
||||
$ip_fh->close();
|
||||
|
||||
eval 'END { &remove_running_file(); }';
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
# check_directories
|
||||
#
|
||||
# Basic sanity check, to make sure all the directories exist and
|
||||
# are writable by this process
|
||||
################################################################
|
||||
sub check_directories
|
||||
{
|
||||
my ($directory);
|
||||
|
||||
foreach $directory ( $BILLING_HOME, $REPORT_HOME, $LOG_DIR, $LOG_ARCHIVE_DIR,
|
||||
$RRD_DIR, $BIN_DIR, $INC_DIR )
|
||||
{
|
||||
if ( ! -d $directory )
|
||||
{
|
||||
print STDERR "ERROR: $directory is not a directory\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
foreach $directory ( $BILLING_HOME, $REPORT_HOME, $LOG_DIR,
|
||||
$LOG_ARCHIVE_DIR )
|
||||
{
|
||||
if ( ! -w $directory )
|
||||
{
|
||||
print STDERR "ERROR: $directory is not writable\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
################################################################
|
||||
# check_files
|
||||
#
|
||||
# Basic sanity check, to make sure all the programs and files exist
|
||||
# before launching sub-process
|
||||
################################################################
|
||||
sub check_files
|
||||
{
|
||||
my ($file);
|
||||
|
||||
foreach $file ( $BURST_ACCOUNTS_FILE )
|
||||
{
|
||||
if ( ! -e $file )
|
||||
{
|
||||
print STDERR "ERROR: $file does not exist\n.",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
elsif ( ! -r $file )
|
||||
{
|
||||
print STDERR "ERROR: $file is not readable.\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
foreach $file ( $BILLING_MODULE, $MONITOR_MODULE )
|
||||
{
|
||||
if ( ! -e "$BIN_DIR/$file" )
|
||||
{
|
||||
print STDERR "ERROR: $BIN_DIR/$file does not exist.\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
if ( (! -r "$BIN_DIR/$file") || (! -x "$BIN_DIR/$file") )
|
||||
{
|
||||
print STDERR "ERROR: $BIN_DIR/$file is not runnable.\n",
|
||||
"Aborting program\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
##############################################################
|
||||
# archive_log_file
|
||||
#
|
||||
# This copies the previous log file into the archive directory
|
||||
# and then cleans up the archive directory.
|
||||
##############################################################
|
||||
sub archive_log_file
|
||||
{
|
||||
if ( &archive_file($LOG_DIR, $LOG_FILE, $LOG_ARCHIVE_DIR, $LOG_FILE, 0) != $OKAY )
|
||||
{
|
||||
print STDERR "Error archiving log file\n";
|
||||
}
|
||||
|
||||
&purge_old_archives($LOG_ARCHIVE_DIR, $MAX_LOG_ARCHIVE_FILES, $LOG_FILE);
|
||||
}
|
||||
|
||||
|
||||
#####################################################################
|
||||
# run_boss_loader
|
||||
#
|
||||
# This function executes the burst_billing program
|
||||
# programs, checks the return codes, and handles errors.
|
||||
#####################################################################
|
||||
sub run_burst_billing
|
||||
{
|
||||
my ($retcode);
|
||||
|
||||
&write_log_file($LOG_INFO, "BB_main.pl starting to run $BILLING_MODULE");
|
||||
&close_log_file();
|
||||
|
||||
$retcode = system("$BIN_DIR/$BILLING_MODULE");
|
||||
$retcode >>= 8;
|
||||
|
||||
&open_log_file();
|
||||
&write_log_file($LOG_INFO, "$BILLING_MODULE returned exit code $retcode");
|
||||
|
||||
if ( ($retcode != $OKAY) &&
|
||||
($retcode != $ERROR_WARNING) )
|
||||
{
|
||||
&write_log_file($LOG_ERROR, "$BILLING_MODULE had some sort of error");
|
||||
}
|
||||
|
||||
return($retcode);
|
||||
}
|
||||
|
||||
|
||||
#########################################################################
|
||||
# run_monitor
|
||||
#
|
||||
# Runs the monitor module.
|
||||
#########################################################################
|
||||
sub run_monitor
|
||||
{
|
||||
my ($retcode);
|
||||
|
||||
&write_log_file($LOG_INFO, "BB_main.pl starting to run $MONITOR_MODULE");
|
||||
&close_log_file();
|
||||
|
||||
$retcode = system("$BIN_DIR/$MONITOR_MODULE");
|
||||
$retcode >>= 8;
|
||||
|
||||
&open_log_file();
|
||||
&write_log_file($LOG_INFO, "$MONITOR_MODULE returned exit code $retcode");
|
||||
|
||||
if ( ($retcode != $OKAY) &&
|
||||
($retcode != $ERROR_WARNING) )
|
||||
{
|
||||
&write_log_file($LOG_ERROR, "$MONITOR_MODULE had some sort of error");
|
||||
}
|
||||
|
||||
return($retcode);
|
||||
}
|
||||
|
||||
|
||||
#####################################################
|
||||
# cleanup_program
|
||||
#
|
||||
# Perform final cleanup before the program terminates
|
||||
#####################################################
|
||||
sub cleanup_program
|
||||
{
|
||||
&write_log_file($END_STAMP, "BOSS_main.pl ended");
|
||||
|
||||
&close_log_file();
|
||||
}
|
||||
|
||||
|
||||
##########################################################################
|
||||
# remove_running_file
|
||||
#
|
||||
# Removes the $IN_PROGRESS_FILE, just before the program exits. Note that
|
||||
# this function is called by the END{} routine, which runs just as the
|
||||
# perl interpreter exits. In this way, I don't have to worry about
|
||||
# something die()ing and not cleaning up this file.
|
||||
##########################################################################
|
||||
sub remove_running_file
|
||||
{
|
||||
unlink $IN_PROGRESS_FILE;
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
#!/usr/bin/perl
|
||||
#############################################################################
|
||||
# $Id: BB_monitor.pl,v 1.1.1.1 2000-10-23 20:08:03 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_monitor.pl
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
#
|
||||
#############################################################################
|
||||
|
||||
#
|
||||
# Not using strict so I can play namespace games
|
||||
# Not using warnings because the Mail and Net modules suck.
|
||||
#
|
||||
|
||||
use IO::File;
|
||||
#
|
||||
# I'm not using Mail::Send becuase the current implementation has a bug
|
||||
# with multiple recipients - sent a patch to Graham.
|
||||
#
|
||||
use Mail::Mailer;
|
||||
#
|
||||
# Have to 'use' this here so I can overwrite the
|
||||
# $Net::SMTP::NetConfig{'smtp_hosts'} = [$MAIL_HOST];
|
||||
#
|
||||
use Net::SMTP;
|
||||
|
||||
BEGIN {require '../inc/BB_include.pl';}
|
||||
require "$INC_DIR/BB_lib.pl";
|
||||
|
||||
|
||||
###########
|
||||
# Globals #
|
||||
###########
|
||||
my $errors = 0;
|
||||
my $warnings = 0;
|
||||
|
||||
|
||||
##############
|
||||
# Begin Code #
|
||||
##############
|
||||
|
||||
&init_program();
|
||||
|
||||
&scan_log_file();
|
||||
|
||||
# if ( $errors || $warnings )
|
||||
&send_email();
|
||||
|
||||
exit($OKAY);
|
||||
|
||||
|
||||
###################
|
||||
# Local Functions #
|
||||
###################
|
||||
|
||||
|
||||
#####################################################################
|
||||
# init_program
|
||||
#
|
||||
# Sets the smtp server to use and the mail from address.
|
||||
# Closes STDOUT and STDERR to prevent junk messages from STMP modules
|
||||
#####################################################################
|
||||
sub init_program
|
||||
{
|
||||
#
|
||||
# Set the SMTP server to use.
|
||||
# This is cheating, but it works.
|
||||
#
|
||||
$Net::SMTP::NetConfig{'smtp_hosts'} = $MAIL_HOSTS;
|
||||
|
||||
#
|
||||
# Set the from address
|
||||
#
|
||||
$ENV{'MAILADDRESS'} = $MAIL_FROM;
|
||||
|
||||
#
|
||||
# Unfortunately, the SMTP modules are noisy in the case of errors.
|
||||
#
|
||||
close(STDOUT);
|
||||
close(STDERR);
|
||||
}
|
||||
|
||||
|
||||
###########################################################
|
||||
# scan_log_file
|
||||
#
|
||||
# Records the number of errors and warnings in the log file
|
||||
###########################################################
|
||||
sub scan_log_file
|
||||
{
|
||||
my ($log_fh, $log_line);
|
||||
|
||||
$log_fh = new IO::File "<$LOG_DIR/$LOG_FILE";
|
||||
return if ( ! $log_fh );
|
||||
|
||||
while ( defined($log_line = <$log_fh>) )
|
||||
{
|
||||
$errors++ if ( $log_line =~ /^\s*$LOG_ERROR/o );
|
||||
$warnings++ if ( $log_line =~ /^\s*$LOG_WARNING/o );
|
||||
}
|
||||
|
||||
$log_fh->close();
|
||||
}
|
||||
|
||||
|
||||
#############################
|
||||
# send_email
|
||||
#
|
||||
# Sends out the summary email
|
||||
#############################
|
||||
sub send_email
|
||||
{
|
||||
my ($mailer, $timestamp);
|
||||
my ($log_fh, $log_line);
|
||||
|
||||
$timestamp = &get_time_stamp();
|
||||
|
||||
$mailer = new Mail::Mailer('smtp');
|
||||
if ( ! $mailer )
|
||||
{
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
|
||||
eval {$mailer->open({
|
||||
'To' => $ERROR_MAIL_TO,
|
||||
'Subject' => "Burst Billing summary for $timestamp",
|
||||
});
|
||||
};
|
||||
if ( $@ )
|
||||
{
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
|
||||
print $mailer "Burst Billing summary for $timestamp\n\n";
|
||||
print $mailer "ERRORS: $errors\n";
|
||||
print $mailer "WARNINGS: $warnings\n";
|
||||
|
||||
print $mailer "Contents of log file:\n\n";
|
||||
|
||||
$log_fh = new IO::File "<$LOG_DIR/$LOG_FILE";
|
||||
if ( $log_fh )
|
||||
{
|
||||
while ( defined($log_line = <$log_fh>) )
|
||||
{
|
||||
if ( ($log_line =~ /^\s*$START_STAMP/o) ||
|
||||
($log_line =~ /^\s*$END_STAMP/o) ||
|
||||
($log_line =~ /^\s*$LOG_INFO/o) ||
|
||||
($log_line =~ /^\s*$LOG_WARNING/o) ||
|
||||
($log_line =~ /^\s*$LOG_ERROR/o) ||
|
||||
($log_line eq "\n") )
|
||||
{
|
||||
print $mailer $log_line;
|
||||
}
|
||||
}
|
||||
$log_fh->close();
|
||||
}
|
||||
|
||||
$mailer->close();
|
||||
}
|
||||
@@ -1,188 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
###########################################################################
|
||||
# $Id: BB_include.pl,v 1.1.1.1 2000-10-23 20:08:18 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_include.pl
|
||||
#
|
||||
# This include file contains global variables used across programs.
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
###########################################################################
|
||||
|
||||
use strict;
|
||||
|
||||
|
||||
######################################################################
|
||||
# Set this variable to 1 only if the failsafe triggers, to temporarily
|
||||
# override it.
|
||||
# TODO: command line switch to over-ride.
|
||||
######################################################################
|
||||
use vars qw{$FAILSAFE_OVERRIDE};
|
||||
$FAILSAFE_OVERRIDE = 0;
|
||||
# $FAILSAFE_OVERRIDE = 1;
|
||||
|
||||
#####################################################################
|
||||
# This controls the maximum number of days we will attempt to recover
|
||||
# data for.
|
||||
#####################################################################
|
||||
use vars qw($MAX_RECOVER_DAYS);
|
||||
$MAX_RECOVER_DAYS = 500;
|
||||
|
||||
|
||||
###############
|
||||
# Directories #
|
||||
###############
|
||||
use vars qw{$BILLING_HOME $RRD_DIR $REPORT_HOME $LOG_DIR $LOG_ARCHIVE_DIR
|
||||
$BIN_DIR $INC_DIR};
|
||||
|
||||
#$BILLING_HOME = "/usr/local/root/apache/cgi-bin/Burstable";
|
||||
$BILLING_HOME = "/home/kevinmc/excite/burst_billing/code";
|
||||
|
||||
$RRD_DIR = "/usr/local/nme/polling/www";
|
||||
|
||||
$REPORT_HOME = "$BILLING_HOME/data";
|
||||
|
||||
$LOG_DIR = "$BILLING_HOME/log";
|
||||
$LOG_ARCHIVE_DIR = "$LOG_DIR/archive";
|
||||
|
||||
$BIN_DIR = "$BILLING_HOME/bin";
|
||||
|
||||
$INC_DIR = "$BILLING_HOME/inc";
|
||||
|
||||
|
||||
##############
|
||||
# File Names #
|
||||
##############
|
||||
use vars qw{$BURST_ACCOUNTS_FILE $LOG_FILE $LAST_RUN_FILE $IN_DATA_FILE $OUT_DATA_FILE
|
||||
$CIRCUIT_HEADER_FILE $IN_PROGRESS_FILE $REPORT_FILE};
|
||||
$BURST_ACCOUNTS_FILE = "$INC_DIR/burst_accounts.txt";
|
||||
|
||||
$LOG_FILE = "log";
|
||||
|
||||
$LAST_RUN_FILE = "lastrun.txt";
|
||||
|
||||
#
|
||||
# Network data is dumped to these files
|
||||
#
|
||||
$IN_DATA_FILE = "in.log";
|
||||
$OUT_DATA_FILE = "out.log";
|
||||
|
||||
#
|
||||
# This contains information about the circuit
|
||||
#
|
||||
$CIRCUIT_HEADER_FILE = "header.txt";
|
||||
|
||||
#
|
||||
# This file is used to mark when this program is running. We don't
|
||||
# want to allow to loads to take place at the same time
|
||||
#
|
||||
$IN_PROGRESS_FILE = "$BILLING_HOME/.running";
|
||||
|
||||
#
|
||||
# The monthly 95/5 report
|
||||
#
|
||||
$REPORT_FILE = "95_5_report.xls";
|
||||
|
||||
|
||||
############
|
||||
# Programs #
|
||||
############
|
||||
use vars qw{$BILLING_MODULE $MONITOR_MODULE};
|
||||
$BILLING_MODULE = "BB_billing.pl";
|
||||
$MONITOR_MODULE = "BB_monitor.pl";
|
||||
|
||||
|
||||
##################
|
||||
# Log File Codes #
|
||||
##################
|
||||
use vars qw{$START_STAMP $END_STAMP $LOG_NOTE $LOG_INFO $LOG_WARNING
|
||||
$LOG_ERROR};
|
||||
$START_STAMP = "START_STAMP";
|
||||
$END_STAMP = "END_STAMP";
|
||||
$LOG_NOTE = "NOTE";
|
||||
#
|
||||
# Info error messages get included in the monitor email. Note messages don't
|
||||
#
|
||||
$LOG_INFO = "INFO";
|
||||
$LOG_WARNING = "WARNING";
|
||||
$LOG_ERROR = "ERROR";
|
||||
|
||||
|
||||
#################################################
|
||||
# Number of archives to keep for each directory #
|
||||
#################################################
|
||||
use vars qw{$MAX_LOG_ARCHIVE_FILES};
|
||||
$MAX_LOG_ARCHIVE_FILES = 10000;
|
||||
|
||||
|
||||
###############
|
||||
# Error Codes #
|
||||
###############
|
||||
use vars qw{$OKAY $ERROR_WARNING $ERROR_CRITICAL};
|
||||
$OKAY = 0;
|
||||
$ERROR_WARNING = 1;
|
||||
$ERROR_CRITICAL = 2;
|
||||
|
||||
|
||||
#################
|
||||
# Email Setting #
|
||||
#################
|
||||
use vars qw{$MAIL_HOSTS $MAIL_FROM $ERROR_MAIL_TO $REPORT_MAIL_TO};
|
||||
$MAIL_HOSTS = ['localhost',
|
||||
'mail.excitehome.net'];
|
||||
$MAIL_FROM = 'burstbilling@excitehome.net';
|
||||
$ERROR_MAIL_TO = ['mccarthy@excitehome.net',
|
||||
'tunacat@yahoo.com',
|
||||
# 'michael@excitehome.net',
|
||||
];
|
||||
|
||||
# $REPORT_MAIL_TO = 'burstbilling@excitehome.net';
|
||||
$REPORT_MAIL_TO = 'mccarthy@excitehome.net';
|
||||
|
||||
|
||||
#####################
|
||||
# Data Error Checking
|
||||
#####################
|
||||
use vars qw{$MAX_ZERO_DATA_PERCENT $MAX_NAN_DATA_PERCENT $MIN_RRD_STEP_SIZE};
|
||||
#
|
||||
# Maximum percentage of 0's to put up with in the data before I log an error
|
||||
# Use values from 0 - 100
|
||||
#
|
||||
$MAX_ZERO_DATA_PERCENT = 50;
|
||||
|
||||
#
|
||||
# Maximum percentage of NaN's to put up with in the data before I log an error
|
||||
# Use values from 0 - 100
|
||||
#
|
||||
$MAX_NAN_DATA_PERCENT = 0;
|
||||
|
||||
#
|
||||
# This is the smallest step size returned by the RRDs - equal to a 5 minute
|
||||
# granularity.
|
||||
#
|
||||
$MIN_RRD_STEP_SIZE = 300;
|
||||
|
||||
|
||||
###############################
|
||||
# Monitor Time List Hash Keys #
|
||||
###############################
|
||||
use vars qw{$MTL_START_EPOCH $MTL_END_EPOCH $MTL_FIRST_OF_MONTH
|
||||
$MTL_YEAR $MTL_MONTH $MTL_MDAY};
|
||||
$MTL_START_EPOCH = 'MTL_START_EPOCH';
|
||||
$MTL_END_EPOCH = 'MTL_END_EPOCH';
|
||||
$MTL_FIRST_OF_MONTH = 'MTL_FIRST_OF_MONTH';
|
||||
$MTL_YEAR = 'MTL_YEAR';
|
||||
$MTL_MONTH = 'MTL_MONTH';
|
||||
$MTL_MDAY = 'MTL_MDAY';
|
||||
|
||||
|
||||
###########################
|
||||
# Circuit Entry Hash Keys #
|
||||
###########################
|
||||
use vars qw{$CIRCUIT_COMPANY_NAME $CIRCUIT_IP_ADDRESS
|
||||
$CIRCUIT_PORT_NAME $CIRCUIT_ID};
|
||||
$CIRCUIT_COMPANY_NAME = 'CIRCUIT_COMPANY_NAME';
|
||||
$CIRCUIT_IP_ADDRESS = 'CIRCUIT_IP_ADDRESS';
|
||||
$CIRCUIT_PORT_NAME = 'CIRCUIT_PORT_NAME';
|
||||
$CIRCUIT_ID = 'CIRCUIT_ID';
|
||||
@@ -1,213 +0,0 @@
|
||||
#!/usr/bin/perl -w
|
||||
#####################################################################
|
||||
# $Id: BB_lib.pl,v 1.1.1.1 2000-10-23 20:08:17 kevin%perldap.org Exp $
|
||||
#
|
||||
# BB_lib.pl
|
||||
#
|
||||
# This file contains functions shared amongst the programs
|
||||
#
|
||||
# History:
|
||||
# Kevin J. McCarthy [10/17/2000] Original Coding
|
||||
#####################################################################
|
||||
|
||||
use strict;
|
||||
|
||||
use DirHandle;
|
||||
use IO::File;
|
||||
use File::Copy;
|
||||
|
||||
BEGIN {require '../inc/BB_include.pl';}
|
||||
|
||||
|
||||
###########
|
||||
# Globals #
|
||||
###########
|
||||
my $LOG_FH;
|
||||
|
||||
|
||||
##################################################################
|
||||
# get_time_stamp
|
||||
#
|
||||
# This returns the current timestamp, in the logfile format.
|
||||
##################################################################
|
||||
sub get_time_stamp
|
||||
{
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
|
||||
|
||||
$mon += 1;
|
||||
$year += 1900;
|
||||
|
||||
$mon = "0" . $mon if ( $mon < 10 );
|
||||
$mday = "0" . $mday if ( $mday < 10 );
|
||||
$hour = "0" . $hour if ( $hour < 10 );
|
||||
$min = "0" . $min if ( $min < 10 );
|
||||
$sec = "0" . $sec if ( $sec < 10 );
|
||||
|
||||
return "$year$mon$mday-$hour$min$sec";
|
||||
}
|
||||
|
||||
|
||||
######################################################
|
||||
# get_file_timestamp
|
||||
#
|
||||
# This returns the 'modification' timestamp of a file,
|
||||
# used for file archving.
|
||||
######################################################
|
||||
sub get_file_timestamp
|
||||
{
|
||||
my ($filename) = @_;
|
||||
|
||||
my ($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size);
|
||||
my ($atime, $mtime, $ctime, $blksize, $blocks);
|
||||
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst);
|
||||
|
||||
($dev, $ino, $mode, $nlink, $uid, $gid, $rdev, $size,
|
||||
$atime, $mtime, $ctime, $blksize, $blocks) = stat $filename;
|
||||
|
||||
($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime);
|
||||
|
||||
$mon += 1;
|
||||
$year += 1900;
|
||||
|
||||
$mon = "0" . $mon if ( $mon < 10 );
|
||||
$mday = "0" . $mday if ( $mday < 10 );
|
||||
$hour = "0" . $hour if ( $hour < 10 );
|
||||
$min = "0" . $min if ( $min < 10 );
|
||||
$sec = "0" . $sec if ( $sec < 10 );
|
||||
|
||||
return "$year$mon$mday-$hour$min$sec";
|
||||
}
|
||||
|
||||
|
||||
###############################################################
|
||||
# archive_file
|
||||
#
|
||||
# This routine moves a file into a backup directory.
|
||||
#
|
||||
# Arguments:
|
||||
# $dir => source directory to archive from
|
||||
# $filename => file to archive
|
||||
# $archive_dir => destination directory to archive to
|
||||
# $archive_filename => destination filename (wihout datestamp -
|
||||
# that is appended automatically)
|
||||
# $copy => optional parameter. If == 1 then the files
|
||||
# are copied, not moved to $archive_dir.
|
||||
# Returns: $OKAY on success
|
||||
###############################################################
|
||||
sub archive_file
|
||||
{
|
||||
my ($dir, $filename, $archive_dir, $archive_filename, $copy) = @_;
|
||||
|
||||
my ($full_filename, $timestamp, $full_archive_filename);
|
||||
|
||||
|
||||
$full_filename = "$dir/$filename";
|
||||
## $timestamp = &get_time_stamp();
|
||||
$timestamp = &get_file_timestamp($full_filename);
|
||||
|
||||
$full_archive_filename = "$archive_dir/$archive_filename.$timestamp";
|
||||
|
||||
if ( -f $full_filename )
|
||||
{
|
||||
if ( defined($copy) && $copy )
|
||||
{
|
||||
if ( ! copy($full_filename, $full_archive_filename) )
|
||||
{
|
||||
return($ERROR_WARNING);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( ! move($full_filename, $full_archive_filename) )
|
||||
{
|
||||
return($ERROR_WARNING);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return($OKAY);
|
||||
}
|
||||
|
||||
|
||||
###########################################################################
|
||||
# purge_old_archives
|
||||
#
|
||||
# This routine deletes old archive files - it sorts the files in the
|
||||
# directory and deletes the oldest files until there are at most $max_files
|
||||
# in the directory
|
||||
###########################################################################
|
||||
sub purge_old_archives
|
||||
{
|
||||
my ($archive_dir, $max_files, $prefix) = @_;
|
||||
|
||||
my ($dirhandle, @allfiles, @delfiles);
|
||||
local($_);
|
||||
|
||||
$dirhandle = new DirHandle $archive_dir;
|
||||
if ( ! $dirhandle )
|
||||
{
|
||||
return ($ERROR_WARNING);
|
||||
}
|
||||
|
||||
@allfiles = grep /^\Q$prefix\E/,
|
||||
reverse sort $dirhandle->read();
|
||||
$dirhandle->close();
|
||||
|
||||
@delfiles = splice @allfiles, $max_files;
|
||||
unlink map {"$archive_dir/$_"} @delfiles;
|
||||
}
|
||||
|
||||
|
||||
###############################
|
||||
# open_log_file
|
||||
#
|
||||
# Opens the log file for append
|
||||
###############################
|
||||
sub open_log_file
|
||||
{
|
||||
$LOG_FH = new IO::File ">>$LOG_DIR/$LOG_FILE";
|
||||
if ( ! $LOG_FH )
|
||||
{
|
||||
print STDERR "Error opening log file\n";
|
||||
exit($ERROR_CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
################
|
||||
# close_log_file
|
||||
################
|
||||
sub close_log_file
|
||||
{
|
||||
$LOG_FH->close();
|
||||
}
|
||||
|
||||
|
||||
##################################
|
||||
# write_log_file
|
||||
#
|
||||
# Writes a message to the log file
|
||||
##################################
|
||||
sub write_log_file
|
||||
{
|
||||
my ($code, $desc) = @_;
|
||||
|
||||
my ($timestamp);
|
||||
|
||||
$timestamp = &get_time_stamp();
|
||||
|
||||
if ( $code eq $START_STAMP )
|
||||
{
|
||||
print $LOG_FH "\n$code<$timestamp>: $desc\n";
|
||||
}
|
||||
elsif ( $code eq $END_STAMP )
|
||||
{
|
||||
print $LOG_FH "$code<$timestamp>: $desc\n\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
print $LOG_FH "\t$code<$timestamp>: $desc\n";
|
||||
}
|
||||
}
|
||||
|
||||
1;
|
||||
@@ -1,71 +0,0 @@
|
||||
Comcast_Online_Towson:209.19.8.1:r1.twsn1.md.home.net:45233
|
||||
Cox_AV:209.218.23.21:w4.rdc2.occa.home.net:44204
|
||||
Cox_AZ:10.252.40.193:w1.rdc1.az.home.net:43195
|
||||
Cox_NE:10.252.136.17:w1.rdc1.ne.home.net:45621
|
||||
Cox_SD:10.252.20.97:w2.rdc1.sdca.home.net:44118
|
||||
Cox_VA:10.252.60.5:w1.rdc1.va.home.net:43711
|
||||
Cox_Fibernet:10.252.64.5:w1.rdc1.ok.home.net:44119
|
||||
Befirst:216.217.177.69:w1.pop1.fl.home.net:46820
|
||||
Internap:216.217.218.129:wbb1.rdc1.wa.home.net:48891
|
||||
Merril_Lynch:10.252.172.1:w1.pop1.nj.home.net:47549
|
||||
Siebel:10.252.9.113:w4.rdc1.sfba.home.net:46653
|
||||
Vertex:10.252.140.1:w1.pop1.ca.home.net:44176
|
||||
COX_COMM:10.252.96.17:w1.pop1.la.home.net:42782
|
||||
FUSION_NETWORKS:10.252.148.53:w1.pop1.fl.home.net:40378
|
||||
ISP_ALLIANCE:10.252.168.17:w1.pop1.ga.home.net:42968
|
||||
Akamai:64.232.139.5:wbb1.pop1.va.home.net:44435
|
||||
MICROCAST:24.7.70.65:c1.cmbrma1.home.net:44698
|
||||
MICROCAST:24.7.70.81:c1.sttlwa1.home.net:44699
|
||||
MICROCAST:24.7.70.77:c1.snfcca1.home.net:44700
|
||||
MICROCAST:24.7.70.69:c2.chcgil1.home.net:44704
|
||||
MICROCAST:24.7.70.85:c2.washdc1.home.net:44702
|
||||
MICROCAST:24.7.70.73:c1.dllstx1.home.net:44703
|
||||
STREAMING_MEDIA:10.253.0.1:wbb1.pop1.va.home.net:45382
|
||||
INTELLISPACE_INTELLIGENT_INTERNET:10.252.156.33:w1.pop1.ny.home.net:44449
|
||||
Speedera:209.219.187.1:wbb1.pop2.ca.home.net:46034
|
||||
Speedera:64.232.139.1:wbb1.pop1.va.home.net:46035
|
||||
IBeam:10.253.64.49:wbb1.pop2.ca.home.net:43891
|
||||
COX_COMM:10.252.168.21:w1.pop1.ga.home.net:44619
|
||||
Apptus:10.253.0.33:wbb1.pop1.va.home.net:46080
|
||||
SADDLEBACK_COLLEGE:10.252.25.109:w1.rdc2.occa.home.net:37266
|
||||
Cox_VA:10.252.60.1:w1.rdc1.va.home.net:37085
|
||||
Cox_AV:209.218.23.21:wbb1.rdc2.occa.home.net:36842
|
||||
SEGASOFT:209.19.34.33:w4.rdc1.sfba.home.net:36658
|
||||
AT&T_NCS_ITS:10.252.1.25:w5.rdc1.nj.home.net:35004
|
||||
LUCENT_TECHNOLOGIES:10.252.0.117:w1.rdc1.nj.home.net:38002
|
||||
BROADCOM:10.252.24.9:w1.rdc2.occa.home.net:38442
|
||||
NETWORK_PLUS:10.252.49.73:w2.pop1.ma.home.net:38786
|
||||
GLOBAL_MUSIC_OUTLET:10.252.27.9:w2.rdc2.occa.home.net:34780
|
||||
SIMPLE_NETWORK_COMM:10.252.144.1:w1.sndgca1.home.net:35837
|
||||
TELEBEAM:209.125.212.9:w1.pop1.pa.home.net:34908
|
||||
INTERTAINER:10.252.24.209:w1.rdc2.occa.home.net:39622
|
||||
INTEL_CORP:10.252.160.9:w1.pop1.or.home.net:38387
|
||||
AT&T_MEDIA_SERVICES:10.252.84.161:w4.rdc1.sfba.home.net:39715
|
||||
NET_CARRIER:209.125.212.13:w1.pop1.pa.home.net:36901
|
||||
COMCAST_ONLINE:216.217.0.1:w3.rdc1.nj.home.net:40728
|
||||
REAL_NETWORKS:216.216.93.5:wbb1.rdc1.wa.home.net:40961
|
||||
INTEL_CORP:10.252.41.13:w2.pop1.az.home.net:38798
|
||||
IDEAL:10.252.56.5:wbb1.pop1.mi.home.net:40235
|
||||
IMALL:10.252.180.17:w1.pop2.ut.home.net:39762
|
||||
PRIME:10.252.25.189:w2.rdc2.occa.home.net:41036
|
||||
ETRACKS.COM:10.252.11.73:w4.rdc1.sfba.home.net:39479
|
||||
NEW_JERSEY_LINKED:10.252.172.5:w1.pop1.nj.home.net:40679
|
||||
AT&T_FIBER_WHOLESALE:10.252.84.245:w4.rdc1.sfba.home.net:39998
|
||||
NORTHPOINT_PVC_IRVINE:10.252.32.165:w3.rdc2.occa.home.net:43108
|
||||
NORTHPOINT_PVC_CHICAGO:10.252.14.149:w3.rdc1.il.home.net:43102
|
||||
NORTHPOINT_PVC_WASHINGTON:10.252.88.21:w1.pop1.dc.home.net:43103
|
||||
NORTHPOINT_PVC_ATLANTA:10.252.168.13:w1.pop1.ga.home.net:43097
|
||||
NORTHPOINT_PVC_NEW_JERSEY:10.252.80.125:w4.rdc1.nj.home.net:43105
|
||||
NORTHPOINT_PVC_FT_LAUD:10.252.148.33:w1.pop1.fl.home.net:43101
|
||||
AIRPOWER_COMM:216.216.30.213:wbb1.rdc2.occa.home.net:42072
|
||||
REAL_NETWORKS:10.252.116.53:w1.pop1.or.home.net:42946
|
||||
AKAMAI:10.253.112.33:wbb1.pop1.il.home.net:44426
|
||||
AKAMAI:10.253.132.33:wbb1.pop1.ny.home.net:44434
|
||||
AKAMAI:10.253.80.33:wbb1.pop2.wa.home.net:44427
|
||||
AKAMAI:10.253.96.33:wbb1.pop1.ca.home.net:44429
|
||||
AKAMAI:10.253.64.37:wbb1.pop2.ca.home.net:44423
|
||||
COX_COMM:10.252.168.9:w1.pop1.ga.home.net:41756
|
||||
STREAMING_MEDIA:10.253.64.33:wbb1.pop2.ca.home.net:45381
|
||||
INTUIT:216.216.48.141:w1.sndgca1.home.net:46576
|
||||
AT&T_UGN_KANSAS:10.252.152.33:w1.pop1.il.home.net:43861
|
||||
WEBUSENET:10.253.64.45:wbb1.pop2.ca.home.net:45791
|
||||
617
mozilla/htmlparser/src/nsAVLTree.cpp
Normal file
@@ -0,0 +1,617 @@
|
||||
/* -*- 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 "nsAVLTree.h"
|
||||
|
||||
|
||||
enum eLean {eLeft,eNeutral,eRight};
|
||||
|
||||
struct NS_COM nsAVLNode {
|
||||
public:
|
||||
|
||||
nsAVLNode(void* aValue) {
|
||||
mLeft=0;
|
||||
mRight=0;
|
||||
mSkew=eNeutral;
|
||||
mValue=aValue;
|
||||
}
|
||||
|
||||
nsAVLNode* mLeft;
|
||||
nsAVLNode* mRight;
|
||||
eLean mSkew;
|
||||
void* mValue;
|
||||
};
|
||||
|
||||
|
||||
/************************************************************
|
||||
Now begin the tree class. Don't forget that the comparison
|
||||
between nodes must occur via the comparitor function,
|
||||
otherwise all you're testing is pointer addresses.
|
||||
************************************************************/
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
nsAVLTree::nsAVLTree(nsAVLNodeComparitor& aComparitor,
|
||||
nsAVLNodeFunctor* aDeallocator) :
|
||||
mComparitor(aComparitor), mDeallocator(aDeallocator) {
|
||||
mRoot=0;
|
||||
mCount=0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
avlDeleteTree(nsAVLNode* aNode){
|
||||
if (aNode) {
|
||||
avlDeleteTree(aNode->mLeft);
|
||||
avlDeleteTree(aNode->mRight);
|
||||
delete aNode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/27/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsAVLTree::~nsAVLTree(){
|
||||
if (mDeallocator) {
|
||||
ForEachDepthFirst(*mDeallocator);
|
||||
}
|
||||
avlDeleteTree(mRoot);
|
||||
}
|
||||
|
||||
|
||||
class CDoesntExist: public nsAVLNodeFunctor {
|
||||
public:
|
||||
CDoesntExist(const nsAVLTree& anotherTree) : mOtherTree(anotherTree) {
|
||||
}
|
||||
virtual void* operator()(void* anItem) {
|
||||
void* result=mOtherTree.FindItem(anItem);
|
||||
if(result)
|
||||
return nsnull;
|
||||
return anItem;
|
||||
}
|
||||
protected:
|
||||
const nsAVLTree& mOtherTree;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method compares two trees (members by identity).
|
||||
* @update gess12/27/98
|
||||
* @param tree to compare against
|
||||
* @return true if they are identical (contain same stuff).
|
||||
*/
|
||||
PRBool nsAVLTree::operator==(const nsAVLTree& aCopy) const{
|
||||
CDoesntExist functor(aCopy);
|
||||
void* theItem=FirstThat(functor);
|
||||
PRBool result=PRBool(!theItem);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/27/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlRotateRight(nsAVLNode*& aRootNode){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
|
||||
ptr2=aRootNode->mRight;
|
||||
if(ptr2->mSkew==eRight) {
|
||||
aRootNode->mRight=ptr2->mLeft;
|
||||
ptr2->mLeft=aRootNode;
|
||||
aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else {
|
||||
ptr3=ptr2->mLeft;
|
||||
ptr2->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=ptr2;
|
||||
aRootNode->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=aRootNode;
|
||||
if(ptr3->mSkew==eLeft)
|
||||
ptr2->mSkew=eRight;
|
||||
else ptr2->mSkew=eNeutral;
|
||||
if(ptr3->mSkew==eRight)
|
||||
aRootNode->mSkew=eLeft;
|
||||
else aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr3;
|
||||
}
|
||||
aRootNode->mSkew=eNeutral;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/27/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlRotateLeft(nsAVLNode*& aRootNode){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
|
||||
ptr2=aRootNode->mLeft;
|
||||
if(ptr2->mSkew==eLeft) {
|
||||
aRootNode->mLeft=ptr2->mRight;
|
||||
ptr2->mRight=aRootNode;
|
||||
aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else {
|
||||
ptr3=ptr2->mRight;
|
||||
ptr2->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=ptr2;
|
||||
aRootNode->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=aRootNode;
|
||||
if(ptr3->mSkew==eRight)
|
||||
ptr2->mSkew=eLeft;
|
||||
else ptr2->mSkew=eNeutral;
|
||||
if(ptr3->mSkew==eLeft)
|
||||
aRootNode->mSkew=eRight;
|
||||
else aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr3;
|
||||
}
|
||||
aRootNode->mSkew=eNeutral;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static eAVLStatus
|
||||
avlInsert(nsAVLNode*& aRootNode, nsAVLNode* aNewNode,
|
||||
nsAVLNodeComparitor& aComparitor) {
|
||||
eAVLStatus result=eAVL_unknown;
|
||||
|
||||
if(!aRootNode) {
|
||||
aRootNode = aNewNode;
|
||||
return eAVL_ok;
|
||||
}
|
||||
|
||||
if(aNewNode==aRootNode->mValue) {
|
||||
return eAVL_duplicate;
|
||||
}
|
||||
|
||||
PRInt32 theCompareResult=aComparitor(aRootNode->mValue,aNewNode->mValue);
|
||||
if(0 < theCompareResult) { //if(anItem<aRootNode->mValue)
|
||||
result=avlInsert(aRootNode->mLeft,aNewNode,aComparitor);
|
||||
if(eAVL_ok==result) {
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
avlRotateLeft(aRootNode);
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eRight:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eLeft;
|
||||
break;
|
||||
} //switch
|
||||
}//if
|
||||
} //if
|
||||
else {
|
||||
result=avlInsert(aRootNode->mRight,aNewNode,aComparitor);
|
||||
if(eAVL_ok==result) {
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eRight:
|
||||
avlRotateRight(aRootNode);
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eRight;
|
||||
break;
|
||||
} //switch
|
||||
}
|
||||
} //if
|
||||
return result;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static void
|
||||
avlBalanceLeft(nsAVLNode*& aRootNode, PRBool& delOk){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
eLean balnc2;
|
||||
eLean balnc3;
|
||||
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
ptr2=aRootNode->mLeft;
|
||||
balnc2=ptr2->mSkew;
|
||||
if(balnc2!=eRight) {
|
||||
aRootNode->mLeft=ptr2->mRight;
|
||||
ptr2->mRight=aRootNode;
|
||||
if(balnc2==eNeutral){
|
||||
aRootNode->mSkew=eLeft;
|
||||
ptr2->mSkew=eRight;
|
||||
delOk=PR_FALSE;
|
||||
}
|
||||
else{
|
||||
aRootNode->mSkew=eNeutral;
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else{
|
||||
ptr3=ptr2->mRight;
|
||||
balnc3=ptr3->mSkew;
|
||||
ptr2->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=ptr2;
|
||||
aRootNode->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=aRootNode;
|
||||
if(balnc3==eRight) {
|
||||
ptr2->mSkew=eLeft;
|
||||
}
|
||||
else {
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
if(balnc3==eLeft) {
|
||||
aRootNode->mSkew=eRight;
|
||||
}
|
||||
else {
|
||||
aRootNode->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr3;
|
||||
ptr3->mSkew=eNeutral;
|
||||
}
|
||||
break;
|
||||
|
||||
case eRight:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
break;
|
||||
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eLeft;
|
||||
delOk=PR_FALSE;
|
||||
break;
|
||||
}//switch
|
||||
return;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static void
|
||||
avlBalanceRight(nsAVLNode*& aRootNode, PRBool& delOk){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
eLean balnc2;
|
||||
eLean balnc3;
|
||||
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
break;
|
||||
|
||||
case eRight:
|
||||
ptr2=aRootNode->mRight;
|
||||
balnc2=ptr2->mSkew;
|
||||
if(balnc2!=eLeft) {
|
||||
aRootNode->mRight=ptr2->mLeft;
|
||||
ptr2->mLeft=aRootNode;
|
||||
if(balnc2==eNeutral){
|
||||
aRootNode->mSkew=eRight;
|
||||
ptr2->mSkew=eLeft;
|
||||
delOk=PR_FALSE;
|
||||
}
|
||||
else{
|
||||
aRootNode->mSkew=eNeutral;
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else{
|
||||
ptr3=ptr2->mLeft;
|
||||
balnc3=ptr3->mSkew;
|
||||
ptr2->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=ptr2;
|
||||
aRootNode->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=aRootNode;
|
||||
if(balnc3==eLeft) {
|
||||
ptr2->mSkew=eRight;
|
||||
}
|
||||
else {
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
if(balnc3==eRight) {
|
||||
aRootNode->mSkew=eLeft;
|
||||
}
|
||||
else {
|
||||
aRootNode->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr3;
|
||||
ptr3->mSkew=eNeutral;
|
||||
}
|
||||
break;
|
||||
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eRight;
|
||||
delOk=PR_FALSE;
|
||||
break;
|
||||
}//switch
|
||||
return;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static eAVLStatus
|
||||
avlRemoveChildren(nsAVLNode*& aRootNode,nsAVLNode*& anotherNode, PRBool& delOk){
|
||||
eAVLStatus result=eAVL_ok;
|
||||
|
||||
if(!anotherNode->mRight){
|
||||
aRootNode->mValue=anotherNode->mValue; //swap
|
||||
anotherNode=anotherNode->mLeft;
|
||||
delOk=PR_TRUE;
|
||||
}
|
||||
else{
|
||||
avlRemoveChildren(aRootNode,anotherNode->mRight,delOk);
|
||||
if(delOk)
|
||||
avlBalanceLeft(anotherNode,delOk);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static eAVLStatus
|
||||
avlRemove(nsAVLNode*& aRootNode, void* anItem, PRBool& delOk,
|
||||
nsAVLNodeComparitor& aComparitor){
|
||||
eAVLStatus result=eAVL_ok;
|
||||
|
||||
if(!aRootNode)
|
||||
delOk=PR_FALSE;
|
||||
else {
|
||||
PRInt32 cmp=aComparitor(anItem,aRootNode->mValue);
|
||||
if(cmp<0){
|
||||
avlRemove(aRootNode->mLeft,anItem,delOk,aComparitor);
|
||||
if(delOk)
|
||||
avlBalanceRight(aRootNode,delOk);
|
||||
}
|
||||
else if(cmp>0){
|
||||
avlRemove(aRootNode->mRight,anItem,delOk,aComparitor);
|
||||
if(delOk)
|
||||
avlBalanceLeft(aRootNode,delOk);
|
||||
}
|
||||
else{ //they match...
|
||||
nsAVLNode* temp=aRootNode;
|
||||
if(!aRootNode->mRight) {
|
||||
aRootNode=aRootNode->mLeft;
|
||||
delOk=PR_TRUE;
|
||||
delete temp;
|
||||
}
|
||||
else if(!aRootNode->mLeft) {
|
||||
aRootNode=aRootNode->mRight;
|
||||
delOk=PR_TRUE;
|
||||
delete temp;
|
||||
}
|
||||
else {
|
||||
avlRemoveChildren(aRootNode,aRootNode->mLeft,delOk);
|
||||
if(delOk)
|
||||
avlBalanceRight(aRootNode,delOk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
eAVLStatus
|
||||
nsAVLTree::AddItem(void* anItem){
|
||||
eAVLStatus result=eAVL_ok;
|
||||
|
||||
nsAVLNode* theNewNode=new nsAVLNode(anItem);
|
||||
result=avlInsert(mRoot,theNewNode,mComparitor);
|
||||
if(eAVL_duplicate!=result)
|
||||
mCount++;
|
||||
else {
|
||||
delete theNewNode;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
void* nsAVLTree::FindItem(void* aValue) const{
|
||||
nsAVLNode* result=mRoot;
|
||||
PRInt32 count=0;
|
||||
while(result) {
|
||||
count++;
|
||||
PRInt32 cmp=mComparitor(aValue,result->mValue);
|
||||
if(0==cmp) {
|
||||
//we matched...
|
||||
break;
|
||||
}
|
||||
else if(0>cmp){
|
||||
//theNode was greater...
|
||||
result=result->mLeft;
|
||||
}
|
||||
else {
|
||||
//aValue is greater...
|
||||
result=result->mRight;
|
||||
}
|
||||
}
|
||||
if(result) {
|
||||
return result->mValue;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAVLStatus
|
||||
nsAVLTree::RemoveItem(void* aValue){
|
||||
PRBool delOk=PR_TRUE;
|
||||
eAVLStatus result=avlRemove(mRoot,aValue,delOk,mComparitor);
|
||||
if(eAVL_ok==result)
|
||||
mCount--;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlForEachDepthFirst(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor){
|
||||
if(aNode) {
|
||||
avlForEachDepthFirst(aNode->mLeft,aFunctor);
|
||||
avlForEachDepthFirst(aNode->mRight,aFunctor);
|
||||
aFunctor(aNode->mValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void
|
||||
nsAVLTree::ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const{
|
||||
::avlForEachDepthFirst(mRoot,aFunctor);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlForEach(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
|
||||
if(aNode) {
|
||||
avlForEach(aNode->mLeft,aFunctor);
|
||||
aFunctor(aNode->mValue);
|
||||
avlForEach(aNode->mRight,aFunctor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void
|
||||
nsAVLTree::ForEach(nsAVLNodeFunctor& aFunctor) const{
|
||||
::avlForEach(mRoot,aFunctor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void*
|
||||
avlFirstThat(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
|
||||
void* result=nsnull;
|
||||
if(aNode) {
|
||||
result = avlFirstThat(aNode->mLeft,aFunctor);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = aFunctor(aNode->mValue);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = avlFirstThat(aNode->mRight,aFunctor);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void*
|
||||
nsAVLTree::FirstThat(nsAVLNodeFunctor& aFunctor) const{
|
||||
return ::avlFirstThat(mRoot,aFunctor);
|
||||
}
|
||||
|
||||
74
mozilla/htmlparser/src/nsAVLTree.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* -*- 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 nsAVLTree_h___
|
||||
#define nsAVLTree_h___
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
enum eAVLStatus {eAVL_unknown,eAVL_ok,eAVL_fail,eAVL_duplicate};
|
||||
|
||||
|
||||
struct nsAVLNode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/26/98
|
||||
* @param anObject1 is the first object to be compared
|
||||
* @param anObject2 is the second object to be compared
|
||||
* @return -1,0,1 if object1 is less, equal, greater than object2
|
||||
*/
|
||||
class NS_COM nsAVLNodeComparitor {
|
||||
public:
|
||||
virtual PRInt32 operator()(void* anItem1,void* anItem2)=0;
|
||||
};
|
||||
|
||||
class NS_COM nsAVLNodeFunctor {
|
||||
public:
|
||||
virtual void* operator()(void* anItem)=0;
|
||||
};
|
||||
|
||||
class NS_COM nsAVLTree {
|
||||
public:
|
||||
nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator);
|
||||
~nsAVLTree(void);
|
||||
|
||||
PRBool operator==(const nsAVLTree& aOther) const;
|
||||
PRInt32 GetCount(void) const {return mCount;}
|
||||
|
||||
//main functions...
|
||||
eAVLStatus AddItem(void* anItem);
|
||||
eAVLStatus RemoveItem(void* anItem);
|
||||
void* FindItem(void* anItem) const;
|
||||
void ForEach(nsAVLNodeFunctor& aFunctor) const;
|
||||
void ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const;
|
||||
void* FirstThat(nsAVLNodeFunctor& aFunctor) const;
|
||||
|
||||
protected:
|
||||
|
||||
nsAVLNode* mRoot;
|
||||
PRInt32 mCount;
|
||||
nsAVLNodeComparitor& mComparitor;
|
||||
nsAVLNodeFunctor* mDeallocator;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsAVLTree_h___ */
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
# KDE Config File
|
||||
[mozilla.lsm]
|
||||
install_location=
|
||||
dist=true
|
||||
install=false
|
||||
type=DATA
|
||||
[Config for BinMakefileAm]
|
||||
ldflags=
|
||||
cxxflags=-O0 -g3 -Wall
|
||||
bin_program=mozilla
|
||||
[po/Makefile.am]
|
||||
sub_dirs=
|
||||
type=po
|
||||
[LFV Groups]
|
||||
Dialogs=*.kdevdlg,
|
||||
Others=*,
|
||||
Translations=*.po,
|
||||
groups=Headers,Sources,Dialogs,Translations,Others,
|
||||
Sources=*.cpp,*.c,*.cc,*.C,*.cxx,*.ec,*.ecpp,*.lxx,*.l++,*.ll,*.l,
|
||||
Headers=*.h,*.hh,*.hxx,*.hpp,*.H,
|
||||
[mozilla.kdevprj]
|
||||
install_location=
|
||||
dist=true
|
||||
install=false
|
||||
type=DATA
|
||||
[mozilla/docs/en/Makefile.am]
|
||||
sub_dirs=
|
||||
type=normal
|
||||
[mozilla/Makefile.am]
|
||||
sub_dirs=
|
||||
type=prog_main
|
||||
[General]
|
||||
makefiles=Makefile.am,mozilla/Makefile.am,mozilla/docs/Makefile.am,mozilla/docs/en/Makefile.am,po/Makefile.am,
|
||||
version_control=CVS
|
||||
author=Heikki Toivonen
|
||||
project_type=normal_empty
|
||||
sub_dir=mozilla/
|
||||
version=0.1
|
||||
project_name=Mozilla
|
||||
email=heikki@netscape.com
|
||||
kdevprj_version=1.2
|
||||
[Makefile.am]
|
||||
files=mozilla.kdevprj,mozilla.lsm,
|
||||
sub_dirs=mozilla,
|
||||
type=normal
|
||||
[mozilla/docs/Makefile.am]
|
||||
sub_dirs=
|
||||
type=normal
|
||||
@@ -1,14 +0,0 @@
|
||||
Begin3
|
||||
Title: Mozilla
|
||||
Version: 0.1
|
||||
Entered-date:
|
||||
Description:
|
||||
Keywords:
|
||||
Author: Heikki Toivonen <heikki@netscape.com>
|
||||
Maintained-by: Heikki Toivonen <heikki@netscape.com>
|
||||
Primary-site:
|
||||
Home-page: http://
|
||||
Original-site:
|
||||
Platforms: Linux and other Unices
|
||||
Copying-policy: GNU Public License
|
||||
End
|
||||
@@ -1,20 +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 Communicator client 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):
|
||||
*/
|
||||
@@ -1,20 +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 Communicator client 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):
|
||||
*/
|
||||
617
mozilla/parser/htmlparser/src/nsAVLTree.cpp
Normal file
@@ -0,0 +1,617 @@
|
||||
/* -*- 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 "nsAVLTree.h"
|
||||
|
||||
|
||||
enum eLean {eLeft,eNeutral,eRight};
|
||||
|
||||
struct NS_COM nsAVLNode {
|
||||
public:
|
||||
|
||||
nsAVLNode(void* aValue) {
|
||||
mLeft=0;
|
||||
mRight=0;
|
||||
mSkew=eNeutral;
|
||||
mValue=aValue;
|
||||
}
|
||||
|
||||
nsAVLNode* mLeft;
|
||||
nsAVLNode* mRight;
|
||||
eLean mSkew;
|
||||
void* mValue;
|
||||
};
|
||||
|
||||
|
||||
/************************************************************
|
||||
Now begin the tree class. Don't forget that the comparison
|
||||
between nodes must occur via the comparitor function,
|
||||
otherwise all you're testing is pointer addresses.
|
||||
************************************************************/
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
nsAVLTree::nsAVLTree(nsAVLNodeComparitor& aComparitor,
|
||||
nsAVLNodeFunctor* aDeallocator) :
|
||||
mComparitor(aComparitor), mDeallocator(aDeallocator) {
|
||||
mRoot=0;
|
||||
mCount=0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
avlDeleteTree(nsAVLNode* aNode){
|
||||
if (aNode) {
|
||||
avlDeleteTree(aNode->mLeft);
|
||||
avlDeleteTree(aNode->mRight);
|
||||
delete aNode;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/27/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
nsAVLTree::~nsAVLTree(){
|
||||
if (mDeallocator) {
|
||||
ForEachDepthFirst(*mDeallocator);
|
||||
}
|
||||
avlDeleteTree(mRoot);
|
||||
}
|
||||
|
||||
|
||||
class CDoesntExist: public nsAVLNodeFunctor {
|
||||
public:
|
||||
CDoesntExist(const nsAVLTree& anotherTree) : mOtherTree(anotherTree) {
|
||||
}
|
||||
virtual void* operator()(void* anItem) {
|
||||
void* result=mOtherTree.FindItem(anItem);
|
||||
if(result)
|
||||
return nsnull;
|
||||
return anItem;
|
||||
}
|
||||
protected:
|
||||
const nsAVLTree& mOtherTree;
|
||||
};
|
||||
|
||||
/**
|
||||
* This method compares two trees (members by identity).
|
||||
* @update gess12/27/98
|
||||
* @param tree to compare against
|
||||
* @return true if they are identical (contain same stuff).
|
||||
*/
|
||||
PRBool nsAVLTree::operator==(const nsAVLTree& aCopy) const{
|
||||
CDoesntExist functor(aCopy);
|
||||
void* theItem=FirstThat(functor);
|
||||
PRBool result=PRBool(!theItem);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/27/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlRotateRight(nsAVLNode*& aRootNode){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
|
||||
ptr2=aRootNode->mRight;
|
||||
if(ptr2->mSkew==eRight) {
|
||||
aRootNode->mRight=ptr2->mLeft;
|
||||
ptr2->mLeft=aRootNode;
|
||||
aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else {
|
||||
ptr3=ptr2->mLeft;
|
||||
ptr2->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=ptr2;
|
||||
aRootNode->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=aRootNode;
|
||||
if(ptr3->mSkew==eLeft)
|
||||
ptr2->mSkew=eRight;
|
||||
else ptr2->mSkew=eNeutral;
|
||||
if(ptr3->mSkew==eRight)
|
||||
aRootNode->mSkew=eLeft;
|
||||
else aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr3;
|
||||
}
|
||||
aRootNode->mSkew=eNeutral;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/27/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlRotateLeft(nsAVLNode*& aRootNode){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
|
||||
ptr2=aRootNode->mLeft;
|
||||
if(ptr2->mSkew==eLeft) {
|
||||
aRootNode->mLeft=ptr2->mRight;
|
||||
ptr2->mRight=aRootNode;
|
||||
aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else {
|
||||
ptr3=ptr2->mRight;
|
||||
ptr2->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=ptr2;
|
||||
aRootNode->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=aRootNode;
|
||||
if(ptr3->mSkew==eRight)
|
||||
ptr2->mSkew=eLeft;
|
||||
else ptr2->mSkew=eNeutral;
|
||||
if(ptr3->mSkew==eLeft)
|
||||
aRootNode->mSkew=eRight;
|
||||
else aRootNode->mSkew=eNeutral;
|
||||
aRootNode=ptr3;
|
||||
}
|
||||
aRootNode->mSkew=eNeutral;
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static eAVLStatus
|
||||
avlInsert(nsAVLNode*& aRootNode, nsAVLNode* aNewNode,
|
||||
nsAVLNodeComparitor& aComparitor) {
|
||||
eAVLStatus result=eAVL_unknown;
|
||||
|
||||
if(!aRootNode) {
|
||||
aRootNode = aNewNode;
|
||||
return eAVL_ok;
|
||||
}
|
||||
|
||||
if(aNewNode==aRootNode->mValue) {
|
||||
return eAVL_duplicate;
|
||||
}
|
||||
|
||||
PRInt32 theCompareResult=aComparitor(aRootNode->mValue,aNewNode->mValue);
|
||||
if(0 < theCompareResult) { //if(anItem<aRootNode->mValue)
|
||||
result=avlInsert(aRootNode->mLeft,aNewNode,aComparitor);
|
||||
if(eAVL_ok==result) {
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
avlRotateLeft(aRootNode);
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eRight:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eLeft;
|
||||
break;
|
||||
} //switch
|
||||
}//if
|
||||
} //if
|
||||
else {
|
||||
result=avlInsert(aRootNode->mRight,aNewNode,aComparitor);
|
||||
if(eAVL_ok==result) {
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eRight:
|
||||
avlRotateRight(aRootNode);
|
||||
result=eAVL_fail;
|
||||
break;
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eRight;
|
||||
break;
|
||||
} //switch
|
||||
}
|
||||
} //if
|
||||
return result;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static void
|
||||
avlBalanceLeft(nsAVLNode*& aRootNode, PRBool& delOk){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
eLean balnc2;
|
||||
eLean balnc3;
|
||||
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
ptr2=aRootNode->mLeft;
|
||||
balnc2=ptr2->mSkew;
|
||||
if(balnc2!=eRight) {
|
||||
aRootNode->mLeft=ptr2->mRight;
|
||||
ptr2->mRight=aRootNode;
|
||||
if(balnc2==eNeutral){
|
||||
aRootNode->mSkew=eLeft;
|
||||
ptr2->mSkew=eRight;
|
||||
delOk=PR_FALSE;
|
||||
}
|
||||
else{
|
||||
aRootNode->mSkew=eNeutral;
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else{
|
||||
ptr3=ptr2->mRight;
|
||||
balnc3=ptr3->mSkew;
|
||||
ptr2->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=ptr2;
|
||||
aRootNode->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=aRootNode;
|
||||
if(balnc3==eRight) {
|
||||
ptr2->mSkew=eLeft;
|
||||
}
|
||||
else {
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
if(balnc3==eLeft) {
|
||||
aRootNode->mSkew=eRight;
|
||||
}
|
||||
else {
|
||||
aRootNode->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr3;
|
||||
ptr3->mSkew=eNeutral;
|
||||
}
|
||||
break;
|
||||
|
||||
case eRight:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
break;
|
||||
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eLeft;
|
||||
delOk=PR_FALSE;
|
||||
break;
|
||||
}//switch
|
||||
return;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static void
|
||||
avlBalanceRight(nsAVLNode*& aRootNode, PRBool& delOk){
|
||||
nsAVLNode* ptr2;
|
||||
nsAVLNode* ptr3;
|
||||
eLean balnc2;
|
||||
eLean balnc3;
|
||||
|
||||
switch(aRootNode->mSkew){
|
||||
case eLeft:
|
||||
aRootNode->mSkew=eNeutral;
|
||||
break;
|
||||
|
||||
case eRight:
|
||||
ptr2=aRootNode->mRight;
|
||||
balnc2=ptr2->mSkew;
|
||||
if(balnc2!=eLeft) {
|
||||
aRootNode->mRight=ptr2->mLeft;
|
||||
ptr2->mLeft=aRootNode;
|
||||
if(balnc2==eNeutral){
|
||||
aRootNode->mSkew=eRight;
|
||||
ptr2->mSkew=eLeft;
|
||||
delOk=PR_FALSE;
|
||||
}
|
||||
else{
|
||||
aRootNode->mSkew=eNeutral;
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr2;
|
||||
}
|
||||
else{
|
||||
ptr3=ptr2->mLeft;
|
||||
balnc3=ptr3->mSkew;
|
||||
ptr2->mLeft=ptr3->mRight;
|
||||
ptr3->mRight=ptr2;
|
||||
aRootNode->mRight=ptr3->mLeft;
|
||||
ptr3->mLeft=aRootNode;
|
||||
if(balnc3==eLeft) {
|
||||
ptr2->mSkew=eRight;
|
||||
}
|
||||
else {
|
||||
ptr2->mSkew=eNeutral;
|
||||
}
|
||||
if(balnc3==eRight) {
|
||||
aRootNode->mSkew=eLeft;
|
||||
}
|
||||
else {
|
||||
aRootNode->mSkew=eNeutral;
|
||||
}
|
||||
aRootNode=ptr3;
|
||||
ptr3->mSkew=eNeutral;
|
||||
}
|
||||
break;
|
||||
|
||||
case eNeutral:
|
||||
aRootNode->mSkew=eRight;
|
||||
delOk=PR_FALSE;
|
||||
break;
|
||||
}//switch
|
||||
return;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static eAVLStatus
|
||||
avlRemoveChildren(nsAVLNode*& aRootNode,nsAVLNode*& anotherNode, PRBool& delOk){
|
||||
eAVLStatus result=eAVL_ok;
|
||||
|
||||
if(!anotherNode->mRight){
|
||||
aRootNode->mValue=anotherNode->mValue; //swap
|
||||
anotherNode=anotherNode->mLeft;
|
||||
delOk=PR_TRUE;
|
||||
}
|
||||
else{
|
||||
avlRemoveChildren(aRootNode,anotherNode->mRight,delOk);
|
||||
if(delOk)
|
||||
avlBalanceLeft(anotherNode,delOk);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
static eAVLStatus
|
||||
avlRemove(nsAVLNode*& aRootNode, void* anItem, PRBool& delOk,
|
||||
nsAVLNodeComparitor& aComparitor){
|
||||
eAVLStatus result=eAVL_ok;
|
||||
|
||||
if(!aRootNode)
|
||||
delOk=PR_FALSE;
|
||||
else {
|
||||
PRInt32 cmp=aComparitor(anItem,aRootNode->mValue);
|
||||
if(cmp<0){
|
||||
avlRemove(aRootNode->mLeft,anItem,delOk,aComparitor);
|
||||
if(delOk)
|
||||
avlBalanceRight(aRootNode,delOk);
|
||||
}
|
||||
else if(cmp>0){
|
||||
avlRemove(aRootNode->mRight,anItem,delOk,aComparitor);
|
||||
if(delOk)
|
||||
avlBalanceLeft(aRootNode,delOk);
|
||||
}
|
||||
else{ //they match...
|
||||
nsAVLNode* temp=aRootNode;
|
||||
if(!aRootNode->mRight) {
|
||||
aRootNode=aRootNode->mLeft;
|
||||
delOk=PR_TRUE;
|
||||
delete temp;
|
||||
}
|
||||
else if(!aRootNode->mLeft) {
|
||||
aRootNode=aRootNode->mRight;
|
||||
delOk=PR_TRUE;
|
||||
delete temp;
|
||||
}
|
||||
else {
|
||||
avlRemoveChildren(aRootNode,aRootNode->mLeft,delOk);
|
||||
if(delOk)
|
||||
avlBalanceRight(aRootNode,delOk);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
eAVLStatus
|
||||
nsAVLTree::AddItem(void* anItem){
|
||||
eAVLStatus result=eAVL_ok;
|
||||
|
||||
nsAVLNode* theNewNode=new nsAVLNode(anItem);
|
||||
result=avlInsert(mRoot,theNewNode,mComparitor);
|
||||
if(eAVL_duplicate!=result)
|
||||
mCount++;
|
||||
else {
|
||||
delete theNewNode;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/** ------------------------------------------------
|
||||
*
|
||||
*
|
||||
* @update gess 4/22/98
|
||||
* @param
|
||||
* @return
|
||||
*/ //----------------------------------------------
|
||||
void* nsAVLTree::FindItem(void* aValue) const{
|
||||
nsAVLNode* result=mRoot;
|
||||
PRInt32 count=0;
|
||||
while(result) {
|
||||
count++;
|
||||
PRInt32 cmp=mComparitor(aValue,result->mValue);
|
||||
if(0==cmp) {
|
||||
//we matched...
|
||||
break;
|
||||
}
|
||||
else if(0>cmp){
|
||||
//theNode was greater...
|
||||
result=result->mLeft;
|
||||
}
|
||||
else {
|
||||
//aValue is greater...
|
||||
result=result->mRight;
|
||||
}
|
||||
}
|
||||
if(result) {
|
||||
return result->mValue;
|
||||
}
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
eAVLStatus
|
||||
nsAVLTree::RemoveItem(void* aValue){
|
||||
PRBool delOk=PR_TRUE;
|
||||
eAVLStatus result=avlRemove(mRoot,aValue,delOk,mComparitor);
|
||||
if(eAVL_ok==result)
|
||||
mCount--;
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlForEachDepthFirst(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor){
|
||||
if(aNode) {
|
||||
avlForEachDepthFirst(aNode->mLeft,aFunctor);
|
||||
avlForEachDepthFirst(aNode->mRight,aFunctor);
|
||||
aFunctor(aNode->mValue);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void
|
||||
nsAVLTree::ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const{
|
||||
::avlForEachDepthFirst(mRoot,aFunctor);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void
|
||||
avlForEach(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
|
||||
if(aNode) {
|
||||
avlForEach(aNode->mLeft,aFunctor);
|
||||
aFunctor(aNode->mValue);
|
||||
avlForEach(aNode->mRight,aFunctor);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void
|
||||
nsAVLTree::ForEach(nsAVLNodeFunctor& aFunctor) const{
|
||||
::avlForEach(mRoot,aFunctor);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
static void*
|
||||
avlFirstThat(nsAVLNode* aNode, nsAVLNodeFunctor& aFunctor) {
|
||||
void* result=nsnull;
|
||||
if(aNode) {
|
||||
result = avlFirstThat(aNode->mLeft,aFunctor);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = aFunctor(aNode->mValue);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = avlFirstThat(aNode->mRight,aFunctor);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess9/11/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void*
|
||||
nsAVLTree::FirstThat(nsAVLNodeFunctor& aFunctor) const{
|
||||
return ::avlFirstThat(mRoot,aFunctor);
|
||||
}
|
||||
|
||||
74
mozilla/parser/htmlparser/src/nsAVLTree.h
Normal file
@@ -0,0 +1,74 @@
|
||||
/* -*- 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 nsAVLTree_h___
|
||||
#define nsAVLTree_h___
|
||||
|
||||
|
||||
#include "nscore.h"
|
||||
|
||||
|
||||
enum eAVLStatus {eAVL_unknown,eAVL_ok,eAVL_fail,eAVL_duplicate};
|
||||
|
||||
|
||||
struct nsAVLNode;
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess12/26/98
|
||||
* @param anObject1 is the first object to be compared
|
||||
* @param anObject2 is the second object to be compared
|
||||
* @return -1,0,1 if object1 is less, equal, greater than object2
|
||||
*/
|
||||
class NS_COM nsAVLNodeComparitor {
|
||||
public:
|
||||
virtual PRInt32 operator()(void* anItem1,void* anItem2)=0;
|
||||
};
|
||||
|
||||
class NS_COM nsAVLNodeFunctor {
|
||||
public:
|
||||
virtual void* operator()(void* anItem)=0;
|
||||
};
|
||||
|
||||
class NS_COM nsAVLTree {
|
||||
public:
|
||||
nsAVLTree(nsAVLNodeComparitor& aComparitor, nsAVLNodeFunctor* aDeallocator);
|
||||
~nsAVLTree(void);
|
||||
|
||||
PRBool operator==(const nsAVLTree& aOther) const;
|
||||
PRInt32 GetCount(void) const {return mCount;}
|
||||
|
||||
//main functions...
|
||||
eAVLStatus AddItem(void* anItem);
|
||||
eAVLStatus RemoveItem(void* anItem);
|
||||
void* FindItem(void* anItem) const;
|
||||
void ForEach(nsAVLNodeFunctor& aFunctor) const;
|
||||
void ForEachDepthFirst(nsAVLNodeFunctor& aFunctor) const;
|
||||
void* FirstThat(nsAVLNodeFunctor& aFunctor) const;
|
||||
|
||||
protected:
|
||||
|
||||
nsAVLNode* mRoot;
|
||||
PRInt32 mCount;
|
||||
nsAVLNodeComparitor& mComparitor;
|
||||
nsAVLNodeFunctor* mDeallocator;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsAVLTree_h___ */
|
||||
|
||||
717
mozilla/string/obsolete/nsStr.cpp
Normal file
@@ -0,0 +1,717 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/******************************************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
This file contains the nsStr data structure.
|
||||
This general purpose buffer management class is used as the basis for our strings.
|
||||
It's benefits include:
|
||||
1. An efficient set of library style functions for manipulating nsStrs
|
||||
2. Support for 1 and 2 byte character strings (which can easily be increased to n)
|
||||
3. Unicode awareness and interoperability.
|
||||
|
||||
*******************************************************************************************/
|
||||
|
||||
#include "nsStr.h"
|
||||
#include "bufferRoutines.h"
|
||||
#include "stdio.h" //only used for printf
|
||||
#include "nsCRT.h"
|
||||
#include "nsDeque.h"
|
||||
|
||||
|
||||
//static const char* kCallFindChar = "For better performance, call FindChar() for targets whose length==1.";
|
||||
//static const char* kCallRFindChar = "For better performance, call RFindChar() for targets whose length==1.";
|
||||
|
||||
static const PRUnichar gCommonEmptyBuffer[1] = {0};
|
||||
|
||||
/**
|
||||
* This method initializes all the members of the nsStr structure
|
||||
*
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,eCharSize aCharSize) {
|
||||
aDest.mStr=(char*)gCommonEmptyBuffer;
|
||||
aDest.mLength=0;
|
||||
aDest.mCapacity=0;
|
||||
aDest.mCharSize=aCharSize;
|
||||
aDest.mOwnsBuffer=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes all the members of the nsStr structure
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer){
|
||||
aDest.mStr=(aCString) ? aCString : (char*)gCommonEmptyBuffer;
|
||||
aDest.mLength=aLength;
|
||||
aDest.mCapacity=aCapacity;
|
||||
aDest.mCharSize=aCharSize;
|
||||
aDest.mOwnsBuffer=aOwnsBuffer;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This member destroys the memory buffer owned by an nsStr object (if it actually owns it)
|
||||
* @update gess10/30/98
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Destroy(nsStr& aDest) {
|
||||
if((aDest.mStr) && (aDest.mStr!=(char*)gCommonEmptyBuffer)) {
|
||||
Free(aDest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
* to grow to a given size. The original contents are not preserved.
|
||||
* @update gess 3/30/98
|
||||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
PRBool nsStr::EnsureCapacity(nsStr& aString,PRUint32 aNewLength) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aString.mCapacity) {
|
||||
result=Realloc(aString,aNewLength);
|
||||
if(aString.mStr)
|
||||
AddNullTerminator(aString);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method gets called when the internal buffer needs
|
||||
* to grow to a given size. The original contents ARE preserved.
|
||||
* @update gess 3/30/98
|
||||
* @param aNewLength -- new capacity of string in charSize units
|
||||
* @return void
|
||||
*/
|
||||
PRBool nsStr::GrowCapacity(nsStr& aDest,PRUint32 aNewLength) {
|
||||
PRBool result=PR_TRUE;
|
||||
if(aNewLength>aDest.mCapacity) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
result=EnsureCapacity(theTempStr,aNewLength);
|
||||
if(result) {
|
||||
if(aDest.mLength) {
|
||||
Append(theTempStr,aDest,0,aDest.mLength);
|
||||
}
|
||||
Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mLength=theTempStr.mLength;
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the contents of aDest with aSource, up to aCount of chars.
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr that gets changed.
|
||||
* @param aSource is where chars are copied from
|
||||
* @param aCount is the number of chars copied from aSource
|
||||
*/
|
||||
void nsStr::Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(&aDest!=&aSource){
|
||||
Truncate(aDest,0);
|
||||
Append(aDest,aSource,anOffset,aCount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method appends the given nsStr to this one. Note that we have to
|
||||
* pay attention to the underlying char-size of both structs.
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aSource is where char are copied from
|
||||
* @aCount is the number of bytes to be copied
|
||||
*/
|
||||
void nsStr::Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount){
|
||||
if(anOffset<aSource.mLength){
|
||||
PRUint32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRUint32 theLength=(anOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-anOffset);
|
||||
if(0<theLength){
|
||||
|
||||
PRBool isBigEnough=PR_TRUE;
|
||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||
isBigEnough=GrowCapacity(aDest,aDest.mLength+theLength);
|
||||
}
|
||||
|
||||
if(isBigEnough) {
|
||||
//now append new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDest.mLength,aSource.mStr,anOffset,theLength);
|
||||
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method inserts up to "aCount" chars from a source nsStr into a dest nsStr.
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr that gets changed
|
||||
* @param aDestOffset is where in aDest the insertion is to occur
|
||||
* @param aSource is where chars are copied from
|
||||
* @param aSrcOffset is where in aSource chars are copied from
|
||||
* @param aCount is the number of chars from aSource to be inserted into aDest
|
||||
*/
|
||||
void nsStr::Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount){
|
||||
//there are a few cases for insert:
|
||||
// 1. You're inserting chars into an empty string (assign)
|
||||
// 2. You're inserting onto the end of a string (append)
|
||||
// 3. You're inserting onto the 1..n-1 pos of a string (the hard case).
|
||||
if(0<aSource.mLength){
|
||||
if(aDest.mLength){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
PRInt32 theRealLen=(aCount<0) ? aSource.mLength : MinInt(aCount,aSource.mLength);
|
||||
PRInt32 theLength=(aSrcOffset+theRealLen<aSource.mLength) ? theRealLen : (aSource.mLength-aSrcOffset);
|
||||
|
||||
if(aSrcOffset<aSource.mLength) {
|
||||
//here's the only new case we have to handle.
|
||||
//chars are really being inserted into our buffer...
|
||||
|
||||
if(aDest.mLength+theLength > aDest.mCapacity) {
|
||||
nsStr theTempStr;
|
||||
nsStr::Initialize(theTempStr,aDest.mCharSize);
|
||||
|
||||
PRBool isBigEnough=EnsureCapacity(theTempStr,aDest.mLength+theLength); //grow the temp buffer to the right size
|
||||
|
||||
if(isBigEnough) {
|
||||
if(aDestOffset) {
|
||||
Append(theTempStr,aDest,0,aDestOffset); //first copy leftmost data...
|
||||
}
|
||||
|
||||
Append(theTempStr,aSource,0,aSource.mLength); //next copy inserted (new) data
|
||||
|
||||
PRUint32 theRemains=aDest.mLength-aDestOffset;
|
||||
if(theRemains) {
|
||||
Append(theTempStr,aDest,aDestOffset,theRemains); //next copy rightmost data
|
||||
}
|
||||
|
||||
Free(aDest);
|
||||
aDest.mStr = theTempStr.mStr;
|
||||
theTempStr.mStr=0; //make sure to null this out so that you don't lose the buffer you just stole...
|
||||
aDest.mCapacity=theTempStr.mCapacity;
|
||||
aDest.mOwnsBuffer=theTempStr.mOwnsBuffer;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
else {
|
||||
//shift the chars right by theDelta...
|
||||
(*gShiftChars[aDest.mCharSize][KSHIFTRIGHT])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
|
||||
//now insert new chars, starting at offset
|
||||
(*gCopyChars[aSource.mCharSize][aDest.mCharSize])(aDest.mStr,aDestOffset,aSource.mStr,aSrcOffset,theLength);
|
||||
}
|
||||
|
||||
//finally, make sure to update the string length...
|
||||
aDest.mLength+=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
|
||||
}//if
|
||||
//else nothing to do!
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount);
|
||||
}
|
||||
else Append(aDest,aSource,0,aCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method deletes up to aCount chars from aDest
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be manipulated
|
||||
* @param aDestOffset is where in aDest deletion is to occur
|
||||
* @param aCount is the number of chars to be deleted in aDest
|
||||
*/
|
||||
void nsStr::Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
|
||||
PRUint32 theDelta=aDest.mLength-aDestOffset;
|
||||
PRUint32 theLength=(theDelta<aCount) ? theDelta : aCount;
|
||||
|
||||
if(aDestOffset+theLength<aDest.mLength) {
|
||||
|
||||
//if you're here, it means we're cutting chars out of the middle of the string...
|
||||
//so shift the chars left by theLength...
|
||||
(*gShiftChars[aDest.mCharSize][KSHIFTLEFT])(aDest.mStr,aDest.mLength,aDestOffset,theLength);
|
||||
aDest.mLength-=theLength;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
else Truncate(aDest,aDestOffset);
|
||||
}//if
|
||||
}
|
||||
|
||||
/**
|
||||
* This method truncates the given nsStr at given offset
|
||||
* @update gess10/30/98
|
||||
* @param aDest is the nsStr to be truncated
|
||||
* @param aDestOffset is where in aDest truncation is to occur
|
||||
*/
|
||||
void nsStr::Truncate(nsStr& aDest,PRUint32 aDestOffset){
|
||||
if(aDestOffset<aDest.mLength){
|
||||
aDest.mLength=aDestOffset;
|
||||
AddNullTerminator(aDest);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This method forces the given string to upper or lowercase
|
||||
* @update gess1/7/99
|
||||
* @param aDest is the string you're going to change
|
||||
* @param aToUpper: if TRUE, then we go uppercase, otherwise we go lowercase
|
||||
* @return
|
||||
*/
|
||||
void nsStr::ChangeCase(nsStr& aDest,PRBool aToUpper) {
|
||||
// somehow UnicharUtil return failed, fallback to the old ascii only code
|
||||
gCaseConverters[aDest.mCharSize](aDest.mStr,aDest.mLength,aToUpper);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
|
||||
if((aDest.mLength>0) && aSet){
|
||||
PRInt32 theIndex=-1;
|
||||
PRInt32 theMax=aDest.mLength;
|
||||
PRInt32 theSetLen=nsCRT::strlen(aSet);
|
||||
|
||||
if(aEliminateLeading) {
|
||||
while(++theIndex<=theMax) {
|
||||
PRUnichar theChar=GetCharAt(aDest,theIndex);
|
||||
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
|
||||
if(kNotFound==thePos)
|
||||
break;
|
||||
}
|
||||
if(0<theIndex) {
|
||||
if(theIndex<theMax) {
|
||||
Delete(aDest,0,theIndex);
|
||||
}
|
||||
else Truncate(aDest,0);
|
||||
}
|
||||
}
|
||||
|
||||
if(aEliminateTrailing) {
|
||||
theIndex=aDest.mLength;
|
||||
PRInt32 theNewLen=theIndex;
|
||||
while(--theIndex>0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,theIndex); //read at end now...
|
||||
PRInt32 thePos=gFindChars[eOneByte](aSet,theSetLen,0,theChar,PR_FALSE);
|
||||
if(kNotFound<thePos)
|
||||
theNewLen=theIndex;
|
||||
else break;
|
||||
}
|
||||
if(theNewLen<theMax) {
|
||||
Truncate(aDest,theNewLen);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing){
|
||||
Trim(aDest,aSet,aEliminateLeading,aEliminateTrailing);
|
||||
PRUint32 aNewLen=gCompressChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
*
|
||||
* @update gess1/7/99
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
void nsStr::StripChars(nsStr& aDest,const char* aSet){
|
||||
if((0<aDest.mLength) && (aSet)) {
|
||||
PRUint32 aNewLen=gStripChars[aDest.mCharSize](aDest.mStr,aDest.mLength,aSet);
|
||||
aDest.mLength=aNewLen;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Searching methods...
|
||||
**************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* This searches aDest for a given substring
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest string to search
|
||||
* @param aTarget is the substring you're trying to find.
|
||||
* @param aIgnorecase indicates case sensitivity of search
|
||||
* @param anOffset tells us where to start the search
|
||||
* @return index in aDest where member of aSet occurs, or -1 if not found
|
||||
*/
|
||||
PRInt32 nsStr::FindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset) {
|
||||
// NS_PRECONDITION(aTarget.mLength!=1,kCallFindChar);
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
|
||||
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
|
||||
PRInt32 theMax=aDest.mLength-aTarget.mLength;
|
||||
PRInt32 index=(0<=anOffset) ? anOffset : 0;
|
||||
|
||||
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
|
||||
PRInt32 theTargetMax=aTarget.mLength;
|
||||
while(index<=theMax) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_TRUE;
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theTargetChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aTarget,theSubIndex)) : GetCharAt(aTarget,theSubIndex);
|
||||
matches=PRBool(theChar==theTargetChar);
|
||||
}
|
||||
if(matches) {
|
||||
result=index;
|
||||
break;
|
||||
}
|
||||
index++;
|
||||
} //while
|
||||
}//if
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This searches aDest for a given character
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest string to search
|
||||
* @param char is the character you're trying to find.
|
||||
* @param aIgnorecase indicates case sensitivity of search
|
||||
* @param anOffset tells us where to start the search
|
||||
* @return index in aDest where member of aSet occurs, or -1 if not found
|
||||
*/
|
||||
PRInt32 nsStr::FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset) {
|
||||
PRInt32 result=kNotFound;
|
||||
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
|
||||
PRUint32 index=(0<=anOffset) ? (PRUint32)anOffset : 0;
|
||||
result=gFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,index,aChar,aIgnoreCase);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This searches aDest for a character found in aSet.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest string to search
|
||||
* @param aSet contains a list of chars to be searched for
|
||||
* @param aIgnorecase indicates case sensitivity of search
|
||||
* @param anOffset tells us where to start the search
|
||||
* @return index in aDest where member of aSet occurs, or -1 if not found
|
||||
*/
|
||||
PRInt32 nsStr::FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
|
||||
//NS_PRECONDITION(aSet.mLength!=1,kCallFindChar);
|
||||
|
||||
PRInt32 index=(0<=anOffset) ? anOffset-1 : -1;
|
||||
PRInt32 thePos;
|
||||
|
||||
//Note that the search is inverted here. We're scanning aDest, one char at a time
|
||||
//but doing the search against the given set. That's why we use 0 as the offset below.
|
||||
if((0<aDest.mLength) && (0<aSet.mLength)){
|
||||
while(++index<(PRInt32)aDest.mLength) {
|
||||
PRUnichar theChar=GetCharAt(aDest,index);
|
||||
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return index;
|
||||
} //while
|
||||
}
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
/**************************************************************
|
||||
Reverse Searching methods...
|
||||
**************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* This searches aDest (in reverse) for a given substring
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest string to search
|
||||
* @param aTarget is the substring you're trying to find.
|
||||
* @param aIgnorecase indicates case sensitivity of search
|
||||
* @param anOffset tells us where to start the search (counting from left)
|
||||
* @return index in aDest where member of aSet occurs, or -1 if not found
|
||||
*/
|
||||
PRInt32 nsStr::RFindSubstr(const nsStr& aDest,const nsStr& aTarget, PRBool aIgnoreCase,PRInt32 anOffset) {
|
||||
//NS_PRECONDITION(aTarget.mLength!=1,kCallRFindChar);
|
||||
|
||||
PRInt32 result=kNotFound;
|
||||
|
||||
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
|
||||
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength-1;
|
||||
|
||||
if((aDest.mLength>=aTarget.mLength) && (aTarget.mLength>0) && (index>=0)){
|
||||
|
||||
nsStr theCopy;
|
||||
nsStr::Initialize(theCopy,eOneByte);
|
||||
nsStr::Assign(theCopy,aTarget,0,aTarget.mLength);
|
||||
if(aIgnoreCase){
|
||||
nsStr::ChangeCase(theCopy,PR_FALSE); //force to lowercase
|
||||
}
|
||||
|
||||
PRInt32 theTargetMax=theCopy.mLength;
|
||||
while(index>=0) {
|
||||
PRInt32 theSubIndex=-1;
|
||||
PRBool matches=PR_FALSE;
|
||||
if(index+theCopy.mLength<=aDest.mLength) {
|
||||
matches=PR_TRUE;
|
||||
while((++theSubIndex<theTargetMax) && (matches)){
|
||||
PRUnichar theDestChar=(aIgnoreCase) ? nsCRT::ToLower(GetCharAt(aDest,index+theSubIndex)) : GetCharAt(aDest,index+theSubIndex);
|
||||
PRUnichar theTargetChar=GetCharAt(theCopy,theSubIndex);
|
||||
matches=PRBool(theDestChar==theTargetChar);
|
||||
} //while
|
||||
} //if
|
||||
if(matches) {
|
||||
result=index;
|
||||
break;
|
||||
}
|
||||
index--;
|
||||
} //while
|
||||
nsStr::Destroy(theCopy);
|
||||
}//if
|
||||
}//if
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* This searches aDest (in reverse) for a given character
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest string to search
|
||||
* @param char is the character you're trying to find.
|
||||
* @param aIgnorecase indicates case sensitivity of search
|
||||
* @param anOffset tells us where to start the search
|
||||
* @return index in aDest where member of aSet occurs, or -1 if not found
|
||||
*/
|
||||
PRInt32 nsStr::RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset) {
|
||||
PRInt32 result=kNotFound;
|
||||
if((0<aDest.mLength) && (anOffset<(PRInt32)aDest.mLength)) {
|
||||
PRUint32 index=(0<=anOffset) ? anOffset : aDest.mLength-1;
|
||||
result=gRFindChars[aDest.mCharSize](aDest.mStr,aDest.mLength,index,aChar,aIgnoreCase);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* This searches aDest (in reverese) for a character found in aSet.
|
||||
*
|
||||
* @update gess 3/25/98
|
||||
* @param aDest string to search
|
||||
* @param aSet contains a list of chars to be searched for
|
||||
* @param aIgnorecase indicates case sensitivity of search
|
||||
* @param anOffset tells us where to start the search
|
||||
* @return index in aDest where member of aSet occurs, or -1 if not found
|
||||
*/
|
||||
PRInt32 nsStr::RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset) {
|
||||
//NS_PRECONDITION(aSet.mLength!=1,kCallRFindChar);
|
||||
|
||||
PRInt32 index=(0<=anOffset) ? anOffset : aDest.mLength;
|
||||
PRInt32 thePos;
|
||||
|
||||
//note that the search is inverted here. We're scanning aDest, one char at a time
|
||||
//but doing the search against the given set. That's why we use 0 as the offset below.
|
||||
if(0<aDest.mLength) {
|
||||
while(--index>=0) {
|
||||
PRUnichar theChar=GetCharAt(aDest,index);
|
||||
thePos=gFindChars[aSet.mCharSize](aSet.mStr,aSet.mLength,0,theChar,aIgnoreCase);
|
||||
if(kNotFound!=thePos)
|
||||
return index;
|
||||
} //while
|
||||
}
|
||||
return kNotFound;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Compare source and dest strings, up to an (optional max) number of chars
|
||||
* @param aDest is the first str to compare
|
||||
* @param aSource is the second str to compare
|
||||
* @param aCount -- if (-1), then we use length of longer string; if (0<aCount) then it gives the max # of chars to compare
|
||||
* @param aIgnorecase tells us whether to search with case sensitivity
|
||||
* @return aDest<aSource=-1;aDest==aSource==0;aDest>aSource=1
|
||||
*/
|
||||
PRInt32 nsStr::Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase) {
|
||||
PRInt32 result=0;
|
||||
|
||||
if(aCount) {
|
||||
PRInt32 minlen=(aSource.mLength<aDest.mLength) ? aSource.mLength : aDest.mLength;
|
||||
|
||||
if(0==minlen) {
|
||||
if ((aDest.mLength == 0) && (aSource.mLength == 0))
|
||||
return 0;
|
||||
if (aDest.mLength == 0)
|
||||
return -1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
PRInt32 maxlen=(aSource.mLength<aDest.mLength) ? aDest.mLength : aSource.mLength;
|
||||
aCount = (aCount<0) ? maxlen : MinInt(aCount,maxlen);
|
||||
result=(*gCompare[aDest.mCharSize][aSource.mCharSize])(aDest.mStr,aSource.mStr,aCount,aIgnoreCase);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
PRBool nsStr::Alloc(nsStr& aDest,PRUint32 aCount) {
|
||||
|
||||
static int mAllocCount=0;
|
||||
mAllocCount++;
|
||||
|
||||
//we're given the acount value in charunits; now scale up to next multiple.
|
||||
PRUint32 theNewCapacity=kDefaultStringSize;
|
||||
while(theNewCapacity<aCount){
|
||||
theNewCapacity<<=1;
|
||||
}
|
||||
|
||||
aDest.mCapacity=theNewCapacity++;
|
||||
PRUint32 theSize=(theNewCapacity<<aDest.mCharSize);
|
||||
aDest.mStr = (char*)nsAllocator::Alloc(theSize);
|
||||
|
||||
PRBool result=PR_FALSE;
|
||||
if(aDest.mStr) {
|
||||
aDest.mOwnsBuffer=1;
|
||||
result=PR_TRUE;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
PRBool nsStr::Free(nsStr& aDest){
|
||||
if(aDest.mStr){
|
||||
if(aDest.mOwnsBuffer){
|
||||
nsAllocator::Free(aDest.mStr);
|
||||
}
|
||||
aDest.mStr=0;
|
||||
aDest.mOwnsBuffer=0;
|
||||
return PR_TRUE;
|
||||
}
|
||||
return PR_FALSE;
|
||||
}
|
||||
|
||||
PRBool nsStr::Realloc(nsStr& aDest,PRUint32 aCount){
|
||||
|
||||
nsStr temp;
|
||||
memcpy(&temp,&aDest,sizeof(aDest));
|
||||
|
||||
PRBool result=Alloc(temp,aCount);
|
||||
if(result) {
|
||||
Free(aDest);
|
||||
aDest.mStr=temp.mStr;
|
||||
aDest.mCapacity=temp.mCapacity;
|
||||
aDest.mOwnsBuffer=temp.mOwnsBuffer;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
CBufDescriptor::CBufDescriptor(char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
|
||||
mBuffer=aString;
|
||||
mCharSize=eOneByte;
|
||||
mStackBased=aStackBased;
|
||||
mIsConst=PR_FALSE;
|
||||
mLength=mCapacity=0;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? strlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
CBufDescriptor::CBufDescriptor(const char* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
|
||||
mBuffer=(char*)aString;
|
||||
mCharSize=eOneByte;
|
||||
mStackBased=aStackBased;
|
||||
mIsConst=PR_TRUE;
|
||||
mLength=mCapacity=0;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? strlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
CBufDescriptor::CBufDescriptor(PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
|
||||
mBuffer=(char*)aString;
|
||||
mCharSize=eTwoByte;
|
||||
mStackBased=aStackBased;
|
||||
mLength=mCapacity=0;
|
||||
mIsConst=PR_FALSE;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
CBufDescriptor::CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength) {
|
||||
mBuffer=(char*)aString;
|
||||
mCharSize=eTwoByte;
|
||||
mStackBased=aStackBased;
|
||||
mLength=mCapacity=0;
|
||||
mIsConst=PR_TRUE;
|
||||
if(aString && aCapacity>1) {
|
||||
mCapacity=aCapacity-1;
|
||||
mLength=(-1==aLength) ? nsCRT::strlen(aString) : aLength;
|
||||
if(mLength>PRInt32(mCapacity))
|
||||
mLength=mCapacity;
|
||||
}
|
||||
}
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
450
mozilla/string/obsolete/nsStr.h
Normal file
@@ -0,0 +1,450 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
1. There are two philosophies to building string classes:
|
||||
A. Hide the underlying buffer & offer API's allow indirect iteration
|
||||
B. Reveal underlying buffer, risk corruption, but gain performance
|
||||
|
||||
We chose the option B for performance reasons.
|
||||
|
||||
2 Our internal buffer always holds capacity+1 bytes.
|
||||
|
||||
The nsStr struct is a simple structure (no methods) that contains
|
||||
the necessary info to be described as a string. This simple struct
|
||||
is manipulated by the static methods provided in this class.
|
||||
(Which effectively makes this a library that works on structs).
|
||||
|
||||
There are also object-based versions called nsString and nsAutoString
|
||||
which use nsStr but makes it look at feel like an object.
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
/***********************************************************************
|
||||
ASSUMPTIONS:
|
||||
|
||||
1. nsStrings and nsAutoString are always null terminated.
|
||||
2. If you try to set a null char (via SetChar()) a new length is set
|
||||
3. nsCStrings can be upsampled into nsString without data loss
|
||||
4. Char searching is faster than string searching. Use char interfaces
|
||||
if your needs will allow it.
|
||||
5. It's easy to use the stack for nsAutostring buffer storage (fast too!).
|
||||
See the CBufDescriptor class in this file.
|
||||
6. It's ONLY ok to provide non-null-terminated buffers to Append() and Insert()
|
||||
provided you specify a 0<n value for the optional count argument.
|
||||
7. Downsampling from nsString to nsCString is lossy -- avoid it if possible!
|
||||
8. Calls to ToNewCString() and ToNewUnicode() should be matched with calls to Recycle().
|
||||
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
/**********************************************************************************
|
||||
|
||||
AND NOW FOR SOME GENERAL DOCUMENTATION ON STRING USAGE...
|
||||
|
||||
The fundamental datatype in the string library is nsStr. It's a structure that
|
||||
provides the buffer storage and meta-info. It also provides a C-style library
|
||||
of functions for direct manipulation (for those of you who prefer K&R to Bjarne).
|
||||
|
||||
Here's a diagram of the class hierarchy:
|
||||
|
||||
nsStr
|
||||
|___nsString
|
||||
| |
|
||||
| ------nsAutoString
|
||||
|
|
||||
|___nsCString
|
||||
|
|
||||
------nsCAutoString
|
||||
|
||||
Why so many string classes? The 4 variants give you the control you need to
|
||||
determine the best class for your purpose. There are 2 dimensions to this
|
||||
flexibility: 1) stack vs. heap; and 2) 1-byte chars vs. 2-byte chars.
|
||||
|
||||
Note: While nsAutoString and nsCAutoString begin life using stack-based storage,
|
||||
they may not stay that way. Like all nsString classes, autostrings will
|
||||
automatically grow to contain the data you provide. When autostrings
|
||||
grow beyond their intrinsic buffer, they switch to heap based allocations.
|
||||
(We avoid alloca to avoid considerable platform difficulties; see the
|
||||
GNU documentation for more details).
|
||||
|
||||
I should also briefly mention that all the string classes use a "memory agent"
|
||||
object to perform memory operations. This class proxies the standard nsAllocator
|
||||
for actual memory calls, but knows the structure of nsStr making heap operations
|
||||
more localized.
|
||||
|
||||
|
||||
CHOOSING A STRING CLASS:
|
||||
|
||||
In order to choose a string class for you purpose, use this handy table:
|
||||
|
||||
heap-based stack-based
|
||||
-----------------------------------
|
||||
ascii data | nsCString nsCAutoString |
|
||||
|----------------------------------
|
||||
unicode data | nsString nsAutoString |
|
||||
-----------------------------------
|
||||
|
||||
|
||||
Note: The i18n folks will stenuously object if we get too carried away with the
|
||||
use of nsCString's that pass interface boundaries. Try to limit your
|
||||
use of these to external interfaces that demand them, or for your own
|
||||
private purposes in cases where they'll never be seen by humans.
|
||||
|
||||
|
||||
PERFORMANCE CONSIDERATIONS:
|
||||
|
||||
Here are a few tricks to know in order to get better string performance:
|
||||
|
||||
1) Try to limit conversions between ascii and unicode; By sticking with nsString
|
||||
wherever possible your code will be i18n-compliant.
|
||||
|
||||
|
||||
2) Preallocating your string buffer cuts down trips to the allocator. So if you
|
||||
have need for an arbitrarily large buffer, pre-size it like this:
|
||||
|
||||
{
|
||||
nsString mBuffer;
|
||||
mBuffer.SetCapacity(aReasonableSize);
|
||||
}
|
||||
|
||||
3) Allocating nsAutoString or nsCAutoString on the heap is memory inefficient
|
||||
(after all, the whole point is to avoid a heap allocation of the buffer).
|
||||
|
||||
|
||||
4) Consider using an autoString to write into your arbitrarily-sized stack buffers, rather
|
||||
than it's own buffers.
|
||||
|
||||
For example, let's say you're going to call printf() to emit pretty-printed debug output
|
||||
of your object. You know from experience that the pretty-printed version of your object
|
||||
exceeds the capacity of an autostring. Ignoring memory considerations, you could simply
|
||||
use nsCString, appending the stringized version of each of your class's data members.
|
||||
This will probably result in calls to the heap manager.
|
||||
|
||||
But there's a way to do this without necessarily having to call the heap manager.
|
||||
All you do is declare a stack based buffer and instruct nsCString to use that instead
|
||||
of it's own internal buffer by using the CBufDescriptor class:
|
||||
|
||||
{
|
||||
char theBuffer[256];
|
||||
CBufDescritor theBufDecriptor( theBuffer, PR_TRUE, sizeof(theBuffer), 0);
|
||||
nsCAutoString s3( theBufDescriptor );
|
||||
s3="HELLO, my name is inigo montoya, you killed my father, prepare to die!.";
|
||||
}
|
||||
|
||||
The assignment statment to s3 will cause the given string to be written to your
|
||||
stack-based buffer via the normal nsString/nsCString interfaces. Cool, huh?
|
||||
Note however that just like any other nsStringXXX use, if you write more data
|
||||
than will fit in the buffer, a visit to the heap manager will be in order.
|
||||
|
||||
|
||||
**********************************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsStr
|
||||
#define _nsStr
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include <string.h>
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
enum eCharSize {eOneByte=0,eTwoByte=1};
|
||||
#define kDefaultCharSize eTwoByte
|
||||
#define kRadix10 (10)
|
||||
#define kRadix16 (16)
|
||||
#define kAutoDetect (100)
|
||||
#define kRadixUnknown (kAutoDetect+1)
|
||||
const PRInt32 kDefaultStringSize = 64;
|
||||
const PRInt32 kNotFound = -1;
|
||||
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
class NS_COM CBufDescriptor {
|
||||
public:
|
||||
CBufDescriptor(char* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
|
||||
CBufDescriptor(const char* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
|
||||
CBufDescriptor(PRUnichar* aString, PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
|
||||
CBufDescriptor(const PRUnichar* aString,PRBool aStackBased,PRUint32 aCapacity,PRInt32 aLength=-1);
|
||||
|
||||
char* mBuffer;
|
||||
eCharSize mCharSize;
|
||||
PRUint32 mCapacity;
|
||||
PRInt32 mLength;
|
||||
PRBool mStackBased;
|
||||
PRBool mIsConst;
|
||||
};
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
struct NS_COM nsStr {
|
||||
|
||||
//----------------------------------------------------------------------------------------
|
||||
|
||||
nsStr() {
|
||||
MOZ_COUNT_CTOR(nsStr);
|
||||
}
|
||||
|
||||
~nsStr() {
|
||||
MOZ_COUNT_DTOR(nsStr);
|
||||
}
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,eCharSize aCharSize);
|
||||
|
||||
/**
|
||||
* This method initializes an nsStr for use
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be initialized
|
||||
* @param aCharSize tells us the requested char size (1 or 2 bytes)
|
||||
*/
|
||||
static void Initialize(nsStr& aDest,char* aCString,PRUint32 aCapacity,PRUint32 aLength,eCharSize aCharSize,PRBool aOwnsBuffer);
|
||||
|
||||
/**
|
||||
* This method destroys the given nsStr, and *MAY*
|
||||
* deallocate it's memory depending on the setting
|
||||
* of the internal mOwnsBUffer flag.
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be manipulated
|
||||
* @param anAgent is the allocator to be used to the nsStr
|
||||
*/
|
||||
static void Destroy(nsStr& aDest);
|
||||
|
||||
/**
|
||||
* These methods are where memory allocation/reallocation occur.
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aString is the nsStr to be manipulated
|
||||
* @param anAgent is the allocator to be used on the nsStr
|
||||
* @return
|
||||
*/
|
||||
static PRBool EnsureCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||
static PRBool GrowCapacity(nsStr& aString,PRUint32 aNewLength);
|
||||
|
||||
/**
|
||||
* These methods are used to append content to the given nsStr
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param anOffset tells us where in source to start copying
|
||||
* @param aCount tells us the (max) # of chars to copy
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Append(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* These methods are used to assign contents of a source string to dest string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param anOffset tells us where in source to start copying
|
||||
* @param aCount tells us the (max) # of chars to copy
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Assign(nsStr& aDest,const nsStr& aSource,PRUint32 anOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* These methods are used to insert content from source string to the dest nsStr
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aDestOffset tells us where in dest to start insertion
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param aSrcOffset tells us where in source to start copying
|
||||
* @param aCount tells us the (max) # of chars to insert
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Insert( nsStr& aDest,PRUint32 aDestOffset,const nsStr& aSource,PRUint32 aSrcOffset,PRInt32 aCount);
|
||||
|
||||
/**
|
||||
* This method deletes chars from the given str.
|
||||
* The given allocator may choose to resize the str as well.
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be deleted from
|
||||
* @param aDestOffset tells us where in dest to start deleting
|
||||
* @param aCount tells us the (max) # of chars to delete
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Delete(nsStr& aDest,PRUint32 aDestOffset,PRUint32 aCount);
|
||||
|
||||
/**
|
||||
* This method is used to truncate the given string.
|
||||
* The given allocator may choose to resize the str as well (but it's not likely).
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param aDestOffset tells us where in dest to start insertion
|
||||
* @param aSource is the buffer to be copied from
|
||||
* @param aSrcOffset tells us where in source to start copying
|
||||
* @param anAgent is the allocator to be used for alloc/free operations
|
||||
*/
|
||||
static void Truncate(nsStr& aDest,PRUint32 aDestOffset);
|
||||
|
||||
/**
|
||||
* This method is used to perform a case conversion on the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be case shifted
|
||||
* @param toUpper tells us to go upper vs. lower
|
||||
*/
|
||||
static void ChangeCase(nsStr& aDest,PRBool aToUpper);
|
||||
|
||||
|
||||
/**
|
||||
* This method trims chars (given in aSet) from the edges of given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to remove from given buffer
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void Trim(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
|
||||
/**
|
||||
* This method compresses duplicate runs of a given char from the given buffer
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aChar is the replacement char
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void CompressSet(nsStr& aDest,const char* aSet,PRBool aEliminateLeading,PRBool aEliminateTrailing);
|
||||
|
||||
/**
|
||||
* This method removes all occurances of chars in given set from aDest
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the buffer to be manipulated
|
||||
* @param aSet tells us which chars to compress from given buffer
|
||||
* @param aChar is the replacement char
|
||||
* @param aEliminateLeading tells us whether to strip chars from the start of the buffer
|
||||
* @param aEliminateTrailing tells us whether to strip chars from the start of the buffer
|
||||
*/
|
||||
static void StripChars(nsStr& aDest,const char* aSet);
|
||||
|
||||
/**
|
||||
* This method compares the data bewteen two nsStr's
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aStr1 is the first buffer to be compared
|
||||
* @param aStr2 is the 2nd buffer to be compared
|
||||
* @param aCount is the number of chars to compare
|
||||
* @param aIgnorecase tells us whether to use a case-sensitive comparison
|
||||
* @return -1,0,1 depending on <,==,>
|
||||
*/
|
||||
static PRInt32 Compare(const nsStr& aDest,const nsStr& aSource,PRInt32 aCount,PRBool aIgnoreCase);
|
||||
|
||||
/**
|
||||
* These methods scan the given string for 1 or more chars in a given direction
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be searched to
|
||||
* @param aSource (or aChar) is the substr we're looking to find
|
||||
* @param aIgnoreCase tells us whether to search in a case-sensitive manner
|
||||
* @param anOffset tells us where in the dest string to start searching
|
||||
* @return the index of the source (substr) in dest, or -1 (kNotFound) if not found.
|
||||
*/
|
||||
static PRInt32 FindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset);
|
||||
static PRInt32 FindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset);
|
||||
static PRInt32 FindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
|
||||
|
||||
static PRInt32 RFindSubstr(const nsStr& aDest,const nsStr& aSource, PRBool aIgnoreCase,PRInt32 anOffset);
|
||||
static PRInt32 RFindChar(const nsStr& aDest,PRUnichar aChar, PRBool aIgnoreCase,PRInt32 anOffset);
|
||||
static PRInt32 RFindCharInSet(const nsStr& aDest,const nsStr& aSet,PRBool aIgnoreCase,PRInt32 anOffset);
|
||||
|
||||
|
||||
PRUint32 mLength;
|
||||
PRUint32 mCapacity;
|
||||
eCharSize mCharSize;
|
||||
PRBool mOwnsBuffer;
|
||||
|
||||
union {
|
||||
char* mStr;
|
||||
PRUnichar* mUStr;
|
||||
};
|
||||
|
||||
private:
|
||||
static PRBool Alloc(nsStr& aString,PRUint32 aCount);
|
||||
static PRBool Realloc(nsStr& aString,PRUint32 aCount);
|
||||
static PRBool Free(nsStr& aString);
|
||||
|
||||
};
|
||||
|
||||
/**************************************************************
|
||||
A couple of tiny helper methods used in the string classes.
|
||||
**************************************************************/
|
||||
|
||||
inline PRInt32 MinInt(PRInt32 anInt1,PRInt32 anInt2){
|
||||
return (anInt1<anInt2) ? anInt1 : anInt2;
|
||||
}
|
||||
|
||||
inline PRInt32 MaxInt(PRInt32 anInt1,PRInt32 anInt2){
|
||||
return (anInt1<anInt2) ? anInt2 : anInt1;
|
||||
}
|
||||
|
||||
inline void AddNullTerminator(nsStr& aDest) {
|
||||
if(eTwoByte==aDest.mCharSize)
|
||||
aDest.mUStr[aDest.mLength]=0;
|
||||
else aDest.mStr[aDest.mLength]=0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the given buffer to the heap manager. Calls allocator::Free()
|
||||
* @return string length
|
||||
*/
|
||||
inline void Recycle( char* aBuffer) { nsAllocator::Free(aBuffer); }
|
||||
inline void Recycle( PRUnichar* aBuffer) { nsAllocator::Free(aBuffer); }
|
||||
|
||||
/**
|
||||
* This method is used to access a given char in the given string
|
||||
*
|
||||
* @update gess 01/04/99
|
||||
* @param aDest is the nsStr to be appended to
|
||||
* @param anIndex tells us where in dest to get the char from
|
||||
* @return the given char, or 0 if anIndex is out of range
|
||||
*/
|
||||
inline PRUnichar GetCharAt(const nsStr& aDest,PRUint32 anIndex){
|
||||
if(anIndex<aDest.mLength) {
|
||||
return (eTwoByte==aDest.mCharSize) ? aDest.mUStr[anIndex] : aDest.mStr[anIndex];
|
||||
}//if
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
1865
mozilla/string/obsolete/nsString.cpp
Normal file
747
mozilla/string/obsolete/nsString.h
Normal file
@@ -0,0 +1,747 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
See nsStr.h for a more general description of string classes.
|
||||
|
||||
This version of the nsString class offers many improvements over the
|
||||
original version:
|
||||
1. Wide and narrow chars
|
||||
2. Allocators
|
||||
3. Much smarter autostrings
|
||||
4. Subsumable strings
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsCString_
|
||||
#define _nsCString_
|
||||
|
||||
#include "nsString2.h"
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <stdio.h>
|
||||
#include "nsStr.h"
|
||||
#include "nsIAtom.h"
|
||||
|
||||
|
||||
class NS_COM nsSubsumeCStr;
|
||||
|
||||
class NS_COM nsCString : public nsStr {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
nsCString();
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsCString(const char* aCString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* This constructor accepts a unichar string
|
||||
* @param aCString is a ptr to a 2-byte cstr
|
||||
*/
|
||||
nsCString(const PRUnichar* aString,PRInt32 aLength=-1);
|
||||
|
||||
/**
|
||||
* This is a copy constructor that accepts an nsStr
|
||||
* @param reference to another nsCString
|
||||
*/
|
||||
nsCString(const nsStr&);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsCString
|
||||
*/
|
||||
nsCString(const nsCString& aString);
|
||||
|
||||
/**
|
||||
* This constructor takes a subsumestr
|
||||
* @param reference to subsumestr
|
||||
*/
|
||||
nsCString(nsSubsumeCStr& aSubsumeStr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
*/
|
||||
virtual ~nsCString();
|
||||
|
||||
/**
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
* @return string length
|
||||
*/
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
||||
|
||||
|
||||
/**
|
||||
* Call this method if you want to force a different string capacity
|
||||
* @update gess7/30/98
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
* @param aLength is new string length.
|
||||
* @return nada
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRInt32 anIndex=0);
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in sorted order.
|
||||
*
|
||||
* @return TRUE if ordered.
|
||||
*/
|
||||
PRBool IsOrdered(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether or not this string has a length of 0
|
||||
*
|
||||
* @return TRUE if empty.
|
||||
*/
|
||||
PRBool IsEmpty(void) const {
|
||||
return PRBool(0==mLength);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
Accessor methods...
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||
*/
|
||||
const char* GetBuffer(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
String creation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new string
|
||||
*/
|
||||
nsSubsumeCStr operator+(const nsCString& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char*.
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeCStr operator+(const char* aCString);
|
||||
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeCStr operator+(PRUnichar aChar);
|
||||
nsSubsumeCStr operator+(char aChar);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase
|
||||
* @update gess 7/27/98
|
||||
*/
|
||||
void ToLowerCase();
|
||||
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase, and
|
||||
* stores them in aOut
|
||||
* @update gess 7/27/98
|
||||
* @param aOut is a string to contain result
|
||||
*/
|
||||
void ToLowerCase(nsCString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts chars in this to uppercase
|
||||
* @update gess 7/27/98
|
||||
*/
|
||||
void ToUpperCase();
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase, and
|
||||
* stores them in a given output string
|
||||
* @update gess 7/27/98
|
||||
* @param aOut is a string to contain result
|
||||
*/
|
||||
void ToUpperCase(nsCString& aString) const;
|
||||
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
* characters found in aSet from this string.
|
||||
*
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsCString& StripChars(const char* aSet);
|
||||
nsCString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsCString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* swaps occurence of 1 string for another
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsCString& ReplaceChar(PRUnichar aOldChar,PRUnichar aNewChar);
|
||||
nsCString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
|
||||
|
||||
PRInt32 CountChar(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
* either end of the underlying string.
|
||||
*
|
||||
* @param aTrimSet -- contains chars to be trimmed from
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsCString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* This method strips whitespace from string.
|
||||
* You can control whether whitespace is yanked from
|
||||
* start and end of string as well.
|
||||
*
|
||||
* @param aEliminateLeading controls stripping of leading ws
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsCString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* This method strips whitespace from string.
|
||||
* You can control whether whitespace is yanked from
|
||||
* start and end of string as well.
|
||||
*
|
||||
* @param aEliminateLeading controls stripping of leading ws
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsCString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**********************************************************************
|
||||
string conversion methods...
|
||||
*********************************************************************/
|
||||
|
||||
operator char*() {return mStr;}
|
||||
operator const char*() const {return (const char*)mStr;}
|
||||
|
||||
/**
|
||||
* This method constructs a new nsCString that is a clone
|
||||
* of this string.
|
||||
*
|
||||
*/
|
||||
nsCString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ISOLatin1 clone of this string
|
||||
* Note that calls to this method should be matched with calls to Recycle().
|
||||
* @return ptr to new isolatin1 string
|
||||
*/
|
||||
char* ToNewCString() const;
|
||||
|
||||
/**
|
||||
* Creates a unicode clone of this string
|
||||
* Note that calls to this method should be matched with calls to Recycle().
|
||||
* @return ptr to new unicode string
|
||||
*/
|
||||
PRUnichar* ToNewUnicode() const;
|
||||
|
||||
/**
|
||||
* Copies data from internal buffer onto given char* buffer
|
||||
* NOTE: This only copies as many chars as will fit in given buffer (clips)
|
||||
* @param aBuf is the buffer where data is stored
|
||||
* @param aBuflength is the max # of chars to move to buffer
|
||||
* @return ptr to given buffer
|
||||
*/
|
||||
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* Perform string to float conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return float rep of string value
|
||||
*/
|
||||
float ToFloat(PRInt32* aErrorCode) const;
|
||||
|
||||
/**
|
||||
* Try to derive the radix from the value contained in this string
|
||||
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
|
||||
*/
|
||||
PRUint32 DetermineRadix(void);
|
||||
|
||||
/**
|
||||
* Perform string to int conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return int rep of string value
|
||||
*/
|
||||
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
String manipulation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Functionally equivalent to assign or operator=
|
||||
*
|
||||
*/
|
||||
nsCString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsCString& SetString(const nsStr& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
|
||||
/**
|
||||
* assign given string to this string
|
||||
* @param aStr: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsCString& Assign(const nsStr& aString,PRInt32 aCount=-1);
|
||||
nsCString& Assign(const char* aString,PRInt32 aCount=-1);
|
||||
nsCString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsCString& Assign(PRUnichar aChar);
|
||||
nsCString& Assign(char aChar);
|
||||
|
||||
/**
|
||||
* here come a bunch of assignment operators...
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsCString& operator=(const nsCString& aString) {return Assign(aString);}
|
||||
nsCString& operator=(const nsStr& aString) {return Assign(aString);}
|
||||
nsCString& operator=(PRUnichar aChar) {return Assign(aChar);}
|
||||
nsCString& operator=(char aChar) {return Assign(aChar);}
|
||||
nsCString& operator=(const char* aCString) {return Assign(aCString);}
|
||||
nsCString& operator=(const PRUnichar* aString) {return Assign(aString);}
|
||||
#ifdef AIX
|
||||
nsCString& operator=(const nsSubsumeCStr& aSubsumeString); // AIX requires a const here
|
||||
#else
|
||||
nsCString& operator=(nsSubsumeCStr& aSubsumeString);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Here's a bunch of methods that append varying types...
|
||||
* @param various...
|
||||
* @return this
|
||||
*/
|
||||
nsCString& operator+=(const nsCString& aString){return Append(aString,aString.mLength);}
|
||||
nsCString& operator+=(const char* aCString) {return Append(aCString);}
|
||||
nsCString& operator+=(PRUnichar aChar){return Append(aChar);}
|
||||
nsCString& operator+=(char aChar){return Append(aChar);}
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
* This version computes the length of your given string
|
||||
*
|
||||
* @param aString is the source to be appended to this
|
||||
* @return number of chars copied
|
||||
*/
|
||||
nsCString& Append(const nsCString& aString) {return Append(aString,aString.mLength);}
|
||||
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
*
|
||||
* @param aString is the source to be appended to this
|
||||
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
|
||||
* @return number of chars copied
|
||||
*/
|
||||
nsCString& Append(const nsCString& aString,PRInt32 aCount);
|
||||
nsCString& Append(const nsStr& aString,PRInt32 aCount=-1);
|
||||
nsCString& Append(const char* aString,PRInt32 aCount=-1);
|
||||
nsCString& Append(PRUnichar aChar);
|
||||
nsCString& Append(char aChar);
|
||||
nsCString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
|
||||
nsCString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the leftmost offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Left(nsCString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the given offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Mid(nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at rightmost char.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Right(nsCString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
* string at str[anOffset].
|
||||
*
|
||||
* @param aCopy -- String to be inserted into this
|
||||
* @param anOffset -- insertion position within this str
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsCString& Insert(const nsCString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
* a specified offset.
|
||||
*
|
||||
* @param aString* to be inserted into this string
|
||||
* @param anOffset is insert pos in str
|
||||
* @return the number of chars inserted into this string
|
||||
*/
|
||||
nsCString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single char into this string at
|
||||
* a specified offset.
|
||||
*
|
||||
* @param character to be inserted into this string
|
||||
* @param anOffset is insert pos in str
|
||||
* @return the number of chars inserted into this string
|
||||
*/
|
||||
nsCString& Insert(PRUnichar aChar,PRUint32 anOffset);
|
||||
nsCString& Insert(char aChar,PRUint32 anOffset);
|
||||
|
||||
/*
|
||||
* This method is used to cut characters in this string
|
||||
* starting at anOffset, continuing for aCount chars.
|
||||
*
|
||||
* @param anOffset -- start pos for cut operation
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsCString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Search for given character within this string.
|
||||
* This method does so by using a binary search,
|
||||
* so your string HAD BETTER BE ORDERED!
|
||||
*
|
||||
* @param aChar is the unicode char to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
|
||||
/**
|
||||
* Search for given substring within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @param aIgnoreCase selects case sensitivity
|
||||
* @param anOffset tells us where in this strig to start searching
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @param anOffset tells us where in this strig to start searching
|
||||
* @param aIgnoreCase selects case sensitivity
|
||||
* @return find pos in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the first character
|
||||
* found in the given charset
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where to start searching in this
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
|
||||
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given string
|
||||
* @param aString is substring to be sought in this
|
||||
* @param aIgnoreCase tells us whether or not to do caseless compare
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @param anOffset tells us where in this strig to start searching
|
||||
* @param aIgnoreCase selects case sensitivity
|
||||
* @return find pos in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
* found in the given string
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where to start searching in this
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
|
||||
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
Comparison methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Compares a given string type to this string.
|
||||
* @update gess 7/27/98
|
||||
* @param S is the string to be compared
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @param aCount tells us how many chars to compare
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator==(const nsStr &aString) const;
|
||||
PRBool operator==(const char* aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods perform a !compare of a given string type to this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsStr &aString) const;
|
||||
PRBool operator!=(const char* aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is < than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsStr &aString) const;
|
||||
PRBool operator<(const char* aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is > than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsStr &S) const;
|
||||
PRBool operator>(const char* aString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is <= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsStr &S) const;
|
||||
PRBool operator<=(const char* aString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is >= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
* The optional length argument just lets us know how long the given string is.
|
||||
* If you provide a length, it is compared to length of this string as an
|
||||
* optimization.
|
||||
*
|
||||
* @param aString -- the string to compare to this
|
||||
* @param aCount -- number of chars in given string you want to compare
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
PRBool EqualsIgnoreCase(const nsStr& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* aString,PRInt32 aCount=-1) const;
|
||||
|
||||
|
||||
static void Recycle(nsCString* aString);
|
||||
static nsCString* CreateString(void);
|
||||
|
||||
};
|
||||
|
||||
extern NS_COM int fputs(const nsCString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsCString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Here comes the AutoString class which uses internal memory
|
||||
(typically found on the stack) for its default buffer.
|
||||
If the buffer needs to grow, it gets reallocated on the heap.
|
||||
**************************************************************/
|
||||
|
||||
class NS_COM nsCAutoString : public nsCString {
|
||||
public:
|
||||
|
||||
nsCAutoString();
|
||||
nsCAutoString(const char* aString,PRInt32 aLength=-1);
|
||||
nsCAutoString(const CBufDescriptor& aBuffer);
|
||||
nsCAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
|
||||
nsCAutoString(const nsStr& aString);
|
||||
nsCAutoString(const nsCAutoString& aString);
|
||||
|
||||
#ifdef AIX
|
||||
nsCAutoString(const nsSubsumeCStr& aSubsumeStr); // AIX requires a const
|
||||
#else
|
||||
nsCAutoString(nsSubsumeCStr& aSubsumeStr);
|
||||
#endif // AIX
|
||||
nsCAutoString(PRUnichar aChar);
|
||||
virtual ~nsCAutoString();
|
||||
|
||||
nsCAutoString& operator=(const nsCString& aString) {nsCString::Assign(aString); return *this;}
|
||||
nsCAutoString& operator=(const char* aCString) {nsCString::Assign(aCString); return *this;}
|
||||
nsCAutoString& operator=(PRUnichar aChar) {nsCString::Assign(aChar); return *this;}
|
||||
nsCAutoString& operator=(char aChar) {nsCString::Assign(aChar); return *this;}
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
* @return string length
|
||||
*/
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
||||
|
||||
char mBuffer[kDefaultStringSize];
|
||||
};
|
||||
|
||||
|
||||
/***************************************************************
|
||||
The subsumestr class is very unusual.
|
||||
It differs from a normal string in that it doesn't use normal
|
||||
copy semantics when another string is assign to this.
|
||||
Instead, it "steals" the contents of the source string.
|
||||
|
||||
This is very handy for returning nsString classes as part of
|
||||
an operator+(...) for example, in that it cuts down the number
|
||||
of copy operations that must occur.
|
||||
|
||||
You should probably not use this class unless you really know
|
||||
what you're doing.
|
||||
***************************************************************/
|
||||
class NS_COM nsSubsumeCStr : public nsCString {
|
||||
public:
|
||||
nsSubsumeCStr(nsStr& aString);
|
||||
nsSubsumeCStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
||||
nsSubsumeCStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
2233
mozilla/string/obsolete/nsString2.cpp
Normal file
840
mozilla/string/obsolete/nsString2.h
Normal file
@@ -0,0 +1,840 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/***********************************************************************
|
||||
MODULE NOTES:
|
||||
|
||||
See nsStr.h for a more general description of string classes.
|
||||
|
||||
This version of the nsString class offers many improvements over the
|
||||
original version:
|
||||
1. Wide and narrow chars
|
||||
2. Allocators
|
||||
3. Much smarter autostrings
|
||||
4. Subsumable strings
|
||||
***********************************************************************/
|
||||
|
||||
|
||||
#ifndef _nsString_
|
||||
#define _nsString_
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nscore.h"
|
||||
#include <stdio.h>
|
||||
#include "nsString.h"
|
||||
#include "nsIAtom.h"
|
||||
#include "nsStr.h"
|
||||
#include "nsCRT.h"
|
||||
|
||||
class nsISizeOfHandler;
|
||||
|
||||
|
||||
#define nsString2 nsString
|
||||
#define nsAutoString2 nsAutoString
|
||||
|
||||
|
||||
class NS_COM nsSubsumeStr;
|
||||
class NS_COM nsString : public nsStr {
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
nsString();
|
||||
|
||||
|
||||
/**
|
||||
* This constructor accepts an isolatin string
|
||||
* @param aCString is a ptr to a 1-byte cstr
|
||||
*/
|
||||
nsString(const char* aCString);
|
||||
|
||||
/**
|
||||
* This constructor accepts a unichar string
|
||||
* @param aCString is a ptr to a 2-byte cstr
|
||||
*/
|
||||
nsString(const PRUnichar* aString);
|
||||
|
||||
/**
|
||||
* This is a copy constructor that accepts an nsStr
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString(const nsStr&);
|
||||
|
||||
/**
|
||||
* This is our copy constructor
|
||||
* @param reference to another nsString
|
||||
*/
|
||||
nsString(const nsString& aString);
|
||||
|
||||
/**
|
||||
* This constructor takes a subsumestr
|
||||
* @param reference to subsumestr
|
||||
*/
|
||||
nsString(nsSubsumeStr& aSubsumeStr);
|
||||
|
||||
/**
|
||||
* Destructor
|
||||
*
|
||||
*/
|
||||
virtual ~nsString();
|
||||
|
||||
/**
|
||||
* Retrieve the length of this string
|
||||
* @return string length
|
||||
*/
|
||||
inline PRInt32 Length() const { return (PRInt32)mLength; }
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
* @return string length
|
||||
*/
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
||||
|
||||
|
||||
/**
|
||||
* Call this method if you want to force a different string length
|
||||
* @update gess7/30/98
|
||||
* @param aLength -- contains new length for mStr
|
||||
* @return
|
||||
*/
|
||||
void SetLength(PRUint32 aLength) {
|
||||
Truncate(aLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new length of the string.
|
||||
* @param aLength is new string length.
|
||||
* @return nada
|
||||
*/
|
||||
void SetCapacity(PRUint32 aLength);
|
||||
|
||||
/**
|
||||
* This method truncates this string to given length.
|
||||
*
|
||||
* @param anIndex -- new length of string
|
||||
* @return nada
|
||||
*/
|
||||
void Truncate(PRInt32 anIndex=0);
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in sorted order.
|
||||
*
|
||||
* @return TRUE if ordered.
|
||||
*/
|
||||
PRBool IsOrdered(void) const;
|
||||
|
||||
/**
|
||||
* Determine whether or not the characters in this
|
||||
* string are in store as 1 or 2 byte (unicode) strings.
|
||||
*
|
||||
* @return TRUE if ordered.
|
||||
*/
|
||||
PRBool IsUnicode(void) const {
|
||||
PRBool result=PRBool(mCharSize==eTwoByte);
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this string has a length of 0
|
||||
*
|
||||
* @return TRUE if empty.
|
||||
*/
|
||||
PRBool IsEmpty(void) const {
|
||||
return PRBool(0==mLength);
|
||||
}
|
||||
|
||||
/**********************************************************************
|
||||
Getters/Setters...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Retrieve const ptr to internal buffer; DO NOT TRY TO FREE IT!
|
||||
*/
|
||||
const char* GetBuffer(void) const;
|
||||
const PRUnichar* GetUnicode(void) const;
|
||||
|
||||
|
||||
/**
|
||||
* Get nth character.
|
||||
*/
|
||||
PRUnichar operator[](PRUint32 anIndex) const;
|
||||
PRUnichar CharAt(PRUint32 anIndex) const;
|
||||
PRUnichar First(void) const;
|
||||
PRUnichar Last(void) const;
|
||||
|
||||
/**
|
||||
* Set nth character.
|
||||
*/
|
||||
PRBool SetCharAt(PRUnichar aChar,PRUint32 anIndex);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
String concatenation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Create a new string by appending given string to this
|
||||
* @param aString -- 2nd string to be appended
|
||||
* @return new subsumable string
|
||||
*/
|
||||
nsSubsumeStr operator+(const nsStr& aString);
|
||||
nsSubsumeStr operator+(const nsString& aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given cstring
|
||||
* @param aCString is a ptr to cstring to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(const char* aCString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given prunichar*.
|
||||
* @param aString is a ptr to UC-string to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(const PRUnichar* aString);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a char to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(char aChar);
|
||||
|
||||
/**
|
||||
* create a new string by adding this to the given char.
|
||||
* @param aChar is a unichar to be added to this
|
||||
* @return newly created string
|
||||
*/
|
||||
nsSubsumeStr operator+(PRUnichar aChar);
|
||||
|
||||
/**********************************************************************
|
||||
Lexomorphic transforms...
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase
|
||||
* @update gess 7/27/98
|
||||
*/
|
||||
void ToLowerCase();
|
||||
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase, and
|
||||
* stores them in aOut
|
||||
* @update gess 7/27/98
|
||||
* @param aOut is a string to contain result
|
||||
*/
|
||||
void ToLowerCase(nsString& aString) const;
|
||||
|
||||
/**
|
||||
* Converts chars in this to uppercase
|
||||
* @update gess 7/27/98
|
||||
*/
|
||||
void ToUpperCase();
|
||||
|
||||
/**
|
||||
* Converts chars in this to lowercase, and
|
||||
* stores them in a given output string
|
||||
* @update gess 7/27/98
|
||||
* @param aOut is a string to contain result
|
||||
*/
|
||||
void ToUpperCase(nsString& aString) const;
|
||||
|
||||
|
||||
/**
|
||||
* This method is used to remove all occurances of the
|
||||
* characters found in aSet from this string.
|
||||
*
|
||||
* @param aSet -- characters to be cut from this
|
||||
* @return *this
|
||||
*/
|
||||
nsString& StripChars(const char* aSet);
|
||||
nsString& StripChar(char aChar);
|
||||
|
||||
/**
|
||||
* This method strips whitespace throughout the string
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString& StripWhitespace();
|
||||
|
||||
/**
|
||||
* swaps occurence of 1 string for another
|
||||
*
|
||||
* @return this
|
||||
*/
|
||||
nsString& ReplaceChar(PRUnichar anOldChar,PRUnichar aNewChar);
|
||||
nsString& ReplaceChar(const char* aSet,PRUnichar aNewChar);
|
||||
|
||||
PRInt32 CountChar(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* This method trims characters found in aTrimSet from
|
||||
* either end of the underlying string.
|
||||
*
|
||||
* @param aTrimSet -- contains chars to be trimmed from
|
||||
* both ends
|
||||
* @return this
|
||||
*/
|
||||
nsString& Trim(const char* aSet,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* This method strips whitespace from string.
|
||||
* You can control whether whitespace is yanked from
|
||||
* start and end of string as well.
|
||||
*
|
||||
* @param aEliminateLeading controls stripping of leading ws
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString& CompressSet(const char* aSet, PRUnichar aChar,PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**
|
||||
* This method strips whitespace from string.
|
||||
* You can control whether whitespace is yanked from
|
||||
* start and end of string as well.
|
||||
*
|
||||
* @param aEliminateLeading controls stripping of leading ws
|
||||
* @param aEliminateTrailing controls stripping of trailing ws
|
||||
* @return this
|
||||
*/
|
||||
nsString& CompressWhitespace( PRBool aEliminateLeading=PR_TRUE,PRBool aEliminateTrailing=PR_TRUE);
|
||||
|
||||
/**********************************************************************
|
||||
string conversion methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* This method constructs a new nsString is a clone of this string.
|
||||
*
|
||||
*/
|
||||
nsString* ToNewString() const;
|
||||
|
||||
/**
|
||||
* Creates an ISOLatin1 clone of this string
|
||||
* Note that calls to this method should be matched with calls to Recycle().
|
||||
* @return ptr to new isolatin1 string
|
||||
*/
|
||||
char* ToNewCString() const;
|
||||
|
||||
/**
|
||||
* Creates an UTF8 clone of this string
|
||||
* Note that calls to this method should be matched with calls to Recycle().
|
||||
* @return ptr to new isolatin1 string
|
||||
*/
|
||||
char* ToNewUTF8String() const;
|
||||
|
||||
/**
|
||||
* Creates a unicode clone of this string
|
||||
* Note that calls to this method should be matched with calls to Recycle().
|
||||
* @return ptr to new unicode string
|
||||
*/
|
||||
PRUnichar* ToNewUnicode() const;
|
||||
|
||||
/**
|
||||
* Copies data from internal buffer onto given char* buffer
|
||||
* NOTE: This only copies as many chars as will fit in given buffer (clips)
|
||||
* @param aBuf is the buffer where data is stored
|
||||
* @param aBuflength is the max # of chars to move to buffer
|
||||
* @return ptr to given buffer
|
||||
*/
|
||||
char* ToCString(char* aBuf,PRUint32 aBufLength,PRUint32 anOffset=0) const;
|
||||
|
||||
/**
|
||||
* Perform string to float conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return float rep of string value
|
||||
*/
|
||||
float ToFloat(PRInt32* aErrorCode) const;
|
||||
|
||||
/**
|
||||
* Try to derive the radix from the value contained in this string
|
||||
* @return kRadix10, kRadix16 or kAutoDetect (meaning unknown)
|
||||
*/
|
||||
PRUint32 DetermineRadix(void);
|
||||
|
||||
/**
|
||||
* Perform string to int conversion.
|
||||
* @param aErrorCode will contain error if one occurs
|
||||
* @return int rep of string value
|
||||
*/
|
||||
PRInt32 ToInteger(PRInt32* aErrorCode,PRUint32 aRadix=kRadix10) const;
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
String manipulation methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Functionally equivalent to assign or operator=
|
||||
*
|
||||
*/
|
||||
nsString& SetString(const char* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsString& SetString(const PRUnichar* aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
nsString& SetString(const nsString& aString,PRInt32 aLength=-1) {return Assign(aString,aLength);}
|
||||
|
||||
/**
|
||||
* assign given string to this string
|
||||
* @param aStr: buffer to be assigned to this
|
||||
* @param alength is the length of the given str (or -1)
|
||||
if you want me to determine its length
|
||||
* @return this
|
||||
*/
|
||||
nsString& Assign(const nsStr& aString,PRInt32 aCount=-1);
|
||||
nsString& Assign(const char* aString,PRInt32 aCount=-1);
|
||||
nsString& Assign(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString& Assign(char aChar);
|
||||
nsString& Assign(PRUnichar aChar);
|
||||
|
||||
/**
|
||||
* here come a bunch of assignment operators...
|
||||
* @param aString: string to be added to this
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator=(const nsString& aString) {return Assign(aString);}
|
||||
nsString& operator=(const nsStr& aString) {return Assign(aString);}
|
||||
nsString& operator=(char aChar) {return Assign(aChar);}
|
||||
nsString& operator=(PRUnichar aChar) {return Assign(aChar);}
|
||||
nsString& operator=(const char* aCString) {return Assign(aCString);}
|
||||
nsString& operator=(const PRUnichar* aString) {return Assign(aString);}
|
||||
#ifdef AIX
|
||||
nsString& operator=(const nsSubsumeStr& aSubsumeString); // AIX requires a const here
|
||||
#else
|
||||
nsString& operator=(nsSubsumeStr& aSubsumeString);
|
||||
#endif
|
||||
|
||||
/**
|
||||
* Here's a bunch of methods that append varying types...
|
||||
* @param various...
|
||||
* @return this
|
||||
*/
|
||||
nsString& operator+=(const nsStr& aString){return Append(aString,aString.mLength);}
|
||||
nsString& operator+=(const nsString& aString){return Append(aString,aString.mLength);}
|
||||
nsString& operator+=(const char* aCString) {return Append(aCString);}
|
||||
//nsString& operator+=(char aChar){return Append(aChar);}
|
||||
nsString& operator+=(const PRUnichar* aUCString) {return Append(aUCString);}
|
||||
nsString& operator+=(PRUnichar aChar){return Append(aChar);}
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
* This version computes the length of your given string
|
||||
*
|
||||
* @param aString is the source to be appended to this
|
||||
* @return number of chars copied
|
||||
*/
|
||||
nsString& Append(const nsStr& aString) {return Append(aString,aString.mLength);}
|
||||
nsString& Append(const nsString& aString) {return Append(aString,aString.mLength);}
|
||||
|
||||
|
||||
/*
|
||||
* Appends n characters from given string to this,
|
||||
*
|
||||
* @param aString is the source to be appended to this
|
||||
* @param aCount -- number of chars to copy; -1 tells us to compute the strlen for you
|
||||
* @return number of chars copied
|
||||
*/
|
||||
nsString& Append(const nsStr& aString,PRInt32 aCount);
|
||||
nsString& Append(const nsString& aString,PRInt32 aCount);
|
||||
nsString& Append(const char* aString,PRInt32 aCount=-1);
|
||||
nsString& Append(const PRUnichar* aString,PRInt32 aCount=-1);
|
||||
nsString& Append(char aChar);
|
||||
nsString& Append(PRUnichar aChar);
|
||||
nsString& Append(PRInt32 aInteger,PRInt32 aRadix=10); //radix=8,10 or 16
|
||||
nsString& Append(float aFloat);
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the leftmost offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Left(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at the given offset.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @param anOffset -- position where copying begins
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Mid(nsString& aCopy,PRUint32 anOffset,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* Copies n characters from this string to given string,
|
||||
* starting at rightmost char.
|
||||
*
|
||||
*
|
||||
* @param aCopy -- Receiving string
|
||||
* @param aCount -- number of chars to copy
|
||||
* @return number of chars copied
|
||||
*/
|
||||
PRUint32 Right(nsString& aCopy,PRInt32 aCount) const;
|
||||
|
||||
/*
|
||||
* This method inserts n chars from given string into this
|
||||
* string at str[anOffset].
|
||||
*
|
||||
* @param aCopy -- String to be inserted into this
|
||||
* @param anOffset -- insertion position within this str
|
||||
* @param aCount -- number of chars to be copied from aCopy
|
||||
* @return number of chars inserted into this.
|
||||
*/
|
||||
nsString& Insert(const nsString& aCopy,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a given string into this string at
|
||||
* a specified offset.
|
||||
*
|
||||
* @param aString* to be inserted into this string
|
||||
* @param anOffset is insert pos in str
|
||||
* @return the number of chars inserted into this string
|
||||
*/
|
||||
nsString& Insert(const char* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
nsString& Insert(const PRUnichar* aChar,PRUint32 anOffset,PRInt32 aCount=-1);
|
||||
|
||||
/**
|
||||
* Insert a single char into this string at
|
||||
* a specified offset.
|
||||
*
|
||||
* @param character to be inserted into this string
|
||||
* @param anOffset is insert pos in str
|
||||
* @return the number of chars inserted into this string
|
||||
*/
|
||||
//nsString& Insert(char aChar,PRUint32 anOffset);
|
||||
nsString& Insert(PRUnichar aChar,PRUint32 anOffset);
|
||||
|
||||
/*
|
||||
* This method is used to cut characters in this string
|
||||
* starting at anOffset, continuing for aCount chars.
|
||||
*
|
||||
* @param anOffset -- start pos for cut operation
|
||||
* @param aCount -- number of chars to be cut
|
||||
* @return *this
|
||||
*/
|
||||
nsString& Cut(PRUint32 anOffset,PRInt32 aCount);
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
Searching methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Search for given character within this string.
|
||||
* This method does so by using a binary search,
|
||||
* so your string HAD BETTER BE ORDERED!
|
||||
*
|
||||
* @param aChar is the unicode char to be found
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 BinarySearch(PRUnichar aChar) const;
|
||||
|
||||
/**
|
||||
* Search for given substring within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @param aIgnoreCase selects case sensitivity
|
||||
* @param anOffset tells us where in this strig to start searching
|
||||
* @return offset in string, or -1 (kNotFound)
|
||||
*/
|
||||
PRInt32 Find(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 Find(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 Find(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 Find(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @param anOffset tells us where in this strig to start searching
|
||||
* @param aIgnoreCase selects case sensitivity
|
||||
* @return find pos in string, or -1 (kNotFound)
|
||||
*/
|
||||
//PRInt32 Find(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 FindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the first character
|
||||
* found in the given charset
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where to start searching in this
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 FindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 FindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 FindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
|
||||
|
||||
|
||||
/**
|
||||
* This methods scans the string backwards, looking for the given string
|
||||
* @param aString is substring to be sought in this
|
||||
* @param aIgnoreCase tells us whether or not to do caseless compare
|
||||
* @param anOffset tells us where in this strig to start searching (counting from left)
|
||||
*/
|
||||
PRInt32 RFind(const char* aCString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFind(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFind(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFind(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
|
||||
/**
|
||||
* Search for given char within this string
|
||||
*
|
||||
* @param aString is substring to be sought in this
|
||||
* @param anOffset tells us where in this strig to start searching (counting from left)
|
||||
* @param aIgnoreCase selects case sensitivity
|
||||
* @return find pos in string, or -1 (kNotFound)
|
||||
*/
|
||||
//PRInt32 RFind(PRUnichar aChar,PRInt32 offset=-1,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
PRInt32 RFindChar(PRUnichar aChar,PRBool aIgnoreCase=PR_FALSE,PRInt32 anOffset=-1) const;
|
||||
|
||||
/**
|
||||
* This method searches this string for the last character
|
||||
* found in the given string
|
||||
* @param aString contains set of chars to be found
|
||||
* @param anOffset tells us where in this strig to start searching (counting from left)
|
||||
* @return -1 if not found, else the offset in this
|
||||
*/
|
||||
PRInt32 RFindCharInSet(const char* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFindCharInSet(const PRUnichar* aString,PRInt32 anOffset=-1) const;
|
||||
PRInt32 RFindCharInSet(const nsStr& aString,PRInt32 anOffset=-1) const;
|
||||
|
||||
|
||||
/**********************************************************************
|
||||
Comparison methods...
|
||||
*********************************************************************/
|
||||
|
||||
/**
|
||||
* Compares a given string type to this string.
|
||||
* @update gess 7/27/98
|
||||
* @param S is the string to be compared
|
||||
* @param aIgnoreCase tells us how to treat case
|
||||
* @param aCount tells us how many chars to compare
|
||||
* @return -1,0,1
|
||||
*/
|
||||
virtual PRInt32 Compare(const nsString& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const nsStr &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
virtual PRInt32 Compare(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
|
||||
/**
|
||||
* These methods compare a given string type to this one
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator==(const nsString &aString) const;
|
||||
PRBool operator==(const nsStr &aString) const;
|
||||
PRBool operator==(const char *aString) const;
|
||||
PRBool operator==(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods perform a !compare of a given string type to this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE
|
||||
*/
|
||||
PRBool operator!=(const nsString &aString) const;
|
||||
PRBool operator!=(const nsStr &aString) const;
|
||||
PRBool operator!=(const char* aString) const;
|
||||
PRBool operator!=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is < than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<(const nsString &aString) const;
|
||||
PRBool operator<(const nsStr &aString) const;
|
||||
PRBool operator<(const char* aString) const;
|
||||
PRBool operator<(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is > than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>(const nsString &aString) const;
|
||||
PRBool operator>(const nsStr &S) const;
|
||||
PRBool operator>(const char* aString) const;
|
||||
PRBool operator>(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is <= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator<=(const nsString &aString) const;
|
||||
PRBool operator<=(const nsStr &S) const;
|
||||
PRBool operator<=(const char* aString) const;
|
||||
PRBool operator<=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* These methods test if a given string is >= than this
|
||||
* @param aString is the string to be compared to this
|
||||
* @return TRUE or FALSE
|
||||
*/
|
||||
PRBool operator>=(const nsString &aString) const;
|
||||
PRBool operator>=(const nsStr &S) const;
|
||||
PRBool operator>=(const char* aString) const;
|
||||
PRBool operator>=(const PRUnichar* aString) const;
|
||||
|
||||
/**
|
||||
* Compare this to given string; note that we compare full strings here.
|
||||
* The optional length argument just lets us know how long the given string is.
|
||||
* If you provide a length, it is compared to length of this string as an
|
||||
* optimization.
|
||||
*
|
||||
* @param aString -- the string to compare to this
|
||||
* @param aCount -- number of chars to be compared.
|
||||
* @return TRUE if equal
|
||||
*/
|
||||
PRBool Equals(const nsString &aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(const nsStr& aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(const char* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(const PRUnichar* aString,PRBool aIgnoreCase=PR_FALSE,PRInt32 aCount=-1) const;
|
||||
PRBool Equals(/*FIX: const */nsIAtom* anAtom,PRBool aIgnoreCase) const;
|
||||
PRBool Equals(const PRUnichar* s1, const PRUnichar* s2,PRBool aIgnoreCase=PR_FALSE) const;
|
||||
|
||||
PRBool EqualsIgnoreCase(const nsString& aString) const;
|
||||
PRBool EqualsIgnoreCase(const char* aString,PRInt32 aCount=-1) const;
|
||||
PRBool EqualsIgnoreCase(/*FIX: const */nsIAtom *aAtom) const;
|
||||
PRBool EqualsIgnoreCase(const PRUnichar* s1, const PRUnichar* s2) const;
|
||||
|
||||
/**
|
||||
* Determine if given buffer is plain ascii
|
||||
*
|
||||
* @param aBuffer -- if null, then we test *this, otherwise we test given buffer
|
||||
* @return TRUE if is all ascii chars or if strlen==0
|
||||
*/
|
||||
PRBool IsASCII(const PRUnichar* aBuffer=0);
|
||||
|
||||
|
||||
/**
|
||||
* Determine if given char is a valid space character
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if is valid space char
|
||||
*/
|
||||
static PRBool IsSpace(PRUnichar ch);
|
||||
|
||||
/**
|
||||
* Determine if given char in valid alpha range
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if in alpha range
|
||||
*/
|
||||
static PRBool IsAlpha(PRUnichar ch);
|
||||
|
||||
/**
|
||||
* Determine if given char is valid digit
|
||||
*
|
||||
* @param aChar is character to be tested
|
||||
* @return TRUE if char is a valid digit
|
||||
*/
|
||||
static PRBool IsDigit(PRUnichar ch);
|
||||
|
||||
static void Recycle(nsString* aString);
|
||||
static nsString* CreateString(void);
|
||||
|
||||
};
|
||||
|
||||
extern NS_COM int fputs(const nsString& aString, FILE* out);
|
||||
//ostream& operator<<(ostream& aStream,const nsString& aString);
|
||||
//virtual void DebugDump(ostream& aStream) const;
|
||||
|
||||
|
||||
/**************************************************************
|
||||
Here comes the AutoString class which uses internal memory
|
||||
(typically found on the stack) for its default buffer.
|
||||
If the buffer needs to grow, it gets reallocated on the heap.
|
||||
**************************************************************/
|
||||
|
||||
class NS_COM nsAutoString : public nsString {
|
||||
public:
|
||||
|
||||
nsAutoString();
|
||||
nsAutoString(const char* aCString,PRInt32 aLength=-1);
|
||||
nsAutoString(const PRUnichar* aString,PRInt32 aLength=-1);
|
||||
|
||||
nsAutoString(const CBufDescriptor& aBuffer);
|
||||
nsAutoString(const nsStr& aString);
|
||||
nsAutoString(const nsAutoString& aString);
|
||||
#ifdef AIX
|
||||
nsAutoString(const nsSubsumeStr& aSubsumeStr); // AIX requires a const
|
||||
#else
|
||||
nsAutoString(nsSubsumeStr& aSubsumeStr);
|
||||
#endif // AIX
|
||||
nsAutoString(PRUnichar aChar);
|
||||
virtual ~nsAutoString();
|
||||
|
||||
nsAutoString& operator=(const nsStr& aString) {nsString::Assign(aString); return *this;}
|
||||
nsAutoString& operator=(const nsAutoString& aString) {nsString::Assign(aString); return *this;}
|
||||
nsAutoString& operator=(const char* aCString) {nsString::Assign(aCString); return *this;}
|
||||
nsAutoString& operator=(char aChar) {nsString::Assign(aChar); return *this;}
|
||||
nsAutoString& operator=(const PRUnichar* aBuffer) {nsString::Assign(aBuffer); return *this;}
|
||||
nsAutoString& operator=(PRUnichar aChar) {nsString::Assign(aChar); return *this;}
|
||||
|
||||
/**
|
||||
* Retrieve the size of this string
|
||||
* @return string length
|
||||
*/
|
||||
virtual void SizeOf(nsISizeOfHandler* aHandler, PRUint32* aResult) const;
|
||||
|
||||
char mBuffer[kDefaultStringSize<<eTwoByte];
|
||||
};
|
||||
|
||||
|
||||
|
||||
/***************************************************************
|
||||
The subsumestr class is very unusual.
|
||||
It differs from a normal string in that it doesn't use normal
|
||||
copy semantics when another string is assign to this.
|
||||
Instead, it "steals" the contents of the source string.
|
||||
|
||||
This is very handy for returning nsString classes as part of
|
||||
an operator+(...) for example, in that it cuts down the number
|
||||
of copy operations that must occur.
|
||||
|
||||
You should probably not use this class unless you really know
|
||||
what you're doing.
|
||||
***************************************************************/
|
||||
class NS_COM nsSubsumeStr : public nsString {
|
||||
public:
|
||||
nsSubsumeStr(nsStr& aString);
|
||||
nsSubsumeStr(PRUnichar* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
||||
nsSubsumeStr(char* aString,PRBool assumeOwnership,PRInt32 aLength=-1);
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
179
mozilla/string/obsolete/nsXPIDLString.cpp
Normal file
@@ -0,0 +1,179 @@
|
||||
/* -*- 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 "nsDebug.h"
|
||||
#include "nsIAllocator.h"
|
||||
#include "nsXPIDLString.h"
|
||||
#include "plstr.h"
|
||||
|
||||
// If the allocator changes, fix it here.
|
||||
#define XPIDL_STRING_ALLOC(__len) ((PRUnichar*) nsAllocator::Alloc((__len) * sizeof(PRUnichar)))
|
||||
#define XPIDL_CSTRING_ALLOC(__len) ((char*) nsAllocator::Alloc((__len) * sizeof(char)))
|
||||
#define XPIDL_FREE(__ptr) (nsAllocator::Free(__ptr))
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLString
|
||||
|
||||
nsXPIDLString::nsXPIDLString()
|
||||
: mBuf(0),
|
||||
mBufOwner(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLString::~nsXPIDLString()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLString::operator const PRUnichar*()
|
||||
{
|
||||
return mBuf;
|
||||
}
|
||||
|
||||
|
||||
PRUnichar*
|
||||
nsXPIDLString::Copy(const PRUnichar* aString)
|
||||
{
|
||||
NS_ASSERTION(aString, "null ptr");
|
||||
if (! aString)
|
||||
return 0;
|
||||
|
||||
PRInt32 len = 0;
|
||||
|
||||
{
|
||||
const PRUnichar* p = aString;
|
||||
while (*p++)
|
||||
len++;
|
||||
}
|
||||
|
||||
PRUnichar* result = XPIDL_STRING_ALLOC(len + 1);
|
||||
if (result) {
|
||||
PRUnichar* q = result;
|
||||
while (*aString) {
|
||||
*q = *aString;
|
||||
q++;
|
||||
aString++;
|
||||
}
|
||||
*q = '\0';
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
PRUnichar**
|
||||
nsXPIDLString::StartAssignmentByValue()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBuf = 0;
|
||||
mBufOwner = PR_TRUE;
|
||||
return &mBuf;
|
||||
}
|
||||
|
||||
|
||||
const PRUnichar**
|
||||
nsXPIDLString::StartAssignmentByReference()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBuf = 0;
|
||||
mBufOwner = PR_FALSE;
|
||||
return (const PRUnichar**) &mBuf;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLCString
|
||||
|
||||
nsXPIDLCString::nsXPIDLCString()
|
||||
: mBuf(0),
|
||||
mBufOwner(PR_FALSE)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString::~nsXPIDLCString()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString& nsXPIDLCString::operator =(const char* aCString)
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBuf = Copy(aCString);
|
||||
mBufOwner = PR_TRUE;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
nsXPIDLCString::operator const char*()
|
||||
{
|
||||
return mBuf;
|
||||
}
|
||||
|
||||
|
||||
char*
|
||||
nsXPIDLCString::Copy(const char* aCString)
|
||||
{
|
||||
NS_ASSERTION(aCString, "null ptr");
|
||||
if (! aCString)
|
||||
return 0;
|
||||
|
||||
PRInt32 len = PL_strlen(aCString);
|
||||
char* result = XPIDL_CSTRING_ALLOC(len + 1);
|
||||
if (result)
|
||||
PL_strcpy(result, aCString);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
char**
|
||||
nsXPIDLCString::StartAssignmentByValue()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBuf = 0;
|
||||
mBufOwner = PR_TRUE;
|
||||
return &mBuf;
|
||||
}
|
||||
|
||||
|
||||
const char**
|
||||
nsXPIDLCString::StartAssignmentByReference()
|
||||
{
|
||||
if (mBufOwner && mBuf)
|
||||
XPIDL_FREE(mBuf);
|
||||
|
||||
mBuf = 0;
|
||||
mBufOwner = PR_FALSE;
|
||||
return (const char**) &mBuf;
|
||||
}
|
||||
|
||||
|
||||
302
mozilla/string/obsolete/nsXPIDLString.h
Normal file
@@ -0,0 +1,302 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
|
||||
A set of string wrapper classes that ease transition to use of XPIDL
|
||||
interfaces. nsXPIDLString and nsXPIDLCString are to XPIDL `wstring'
|
||||
and `string' out params as nsCOMPtr is to generic XPCOM interface
|
||||
pointers. They help you deal with object ownership.
|
||||
|
||||
Consider the following interface:
|
||||
|
||||
interface nsIFoo {
|
||||
attribute string Bar;
|
||||
};
|
||||
|
||||
This will generate the following C++ header file:
|
||||
|
||||
class nsIFoo {
|
||||
NS_IMETHOD SetBar(const PRUnichar* aValue);
|
||||
NS_IMETHOD GetBar(PRUnichar* *aValue);
|
||||
};
|
||||
|
||||
The GetBar() method will allocate a copy of the nsIFoo object's
|
||||
"bar" attribute, and leave you to deal with freeing it:
|
||||
|
||||
nsIFoo* aFoo; // assume we get this somehow
|
||||
PRUnichar* bar;
|
||||
aFoo->GetFoo(&bar);
|
||||
// Use bar here...
|
||||
printf("bar is %s!\n", bar);
|
||||
nsAllocator::Free(bar);
|
||||
|
||||
This makes your life harder, because you need to convolute your code
|
||||
to ensure that you don't leak `bar'.
|
||||
|
||||
Enter nsXPIDLString, which manages the ownership of the allocated
|
||||
string, and automatically destroys it when the nsXPIDLString goes
|
||||
out of scope:
|
||||
|
||||
nsIFoo* aFoo;
|
||||
nsXPIDLString bar;
|
||||
aFoo->GetFoo( getter_Copies(bar) );
|
||||
// Use bar here...
|
||||
printf("bar is %s!\n", (const char*) bar);
|
||||
// no need to remember to nsAllocator::Free().
|
||||
|
||||
Like nsCOMPtr, nsXPIDLString uses some syntactic sugar to make it
|
||||
painfully clear exactly what the code expects. You need to wrap an
|
||||
nsXPIDLString object with either `getter_Copies()' or
|
||||
`getter_Shares()' before passing it to a getter: these tell the
|
||||
nsXPIDLString how ownership is being handled.
|
||||
|
||||
In the case of `getter_Copies()', the callee is allocating a copy
|
||||
(which is usually the case). In the case of `getter_Shares()', the
|
||||
callee is returning a const reference to `the real deal' (this can
|
||||
be done using the [shared] attribute in XPIDL).
|
||||
|
||||
*/
|
||||
|
||||
#ifndef nsXPIDLString_h__
|
||||
#define nsXPIDLString_h__
|
||||
|
||||
#include "nsCom.h"
|
||||
#include "prtypes.h"
|
||||
|
||||
#ifndef __PRUNICHAR__
|
||||
#define __PRUNICHAR__
|
||||
typedef PRUint16 PRUnichar;
|
||||
#endif /* __PRUNICHAR__ */
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLString
|
||||
//
|
||||
// A wrapper for Unicode strings. With the |getter_Copies()| and
|
||||
// |getter_Shares()| helper functions, this can be used instead of
|
||||
// the "naked" |PRUnichar*| interface for |wstring| parameters in
|
||||
// XPIDL interfaces.
|
||||
//
|
||||
|
||||
class NS_COM nsXPIDLString {
|
||||
private:
|
||||
PRUnichar* mBuf;
|
||||
PRBool mBufOwner;
|
||||
|
||||
PRUnichar** StartAssignmentByValue();
|
||||
const PRUnichar** StartAssignmentByReference();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct a new, uninitialized wrapper for a Unicode string.
|
||||
*/
|
||||
nsXPIDLString();
|
||||
|
||||
virtual ~nsXPIDLString();
|
||||
|
||||
/**
|
||||
* Return a reference to the immutable Unicode string.
|
||||
*/
|
||||
operator const PRUnichar*();
|
||||
|
||||
/**
|
||||
* Make a copy of the Unicode string. Use this function in the
|
||||
* callee to ensure that the correct memory allocator is used.
|
||||
*/
|
||||
static PRUnichar* Copy(const PRUnichar* aString);
|
||||
|
||||
// A helper class for assignment-by-value. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterCopies {
|
||||
private:
|
||||
nsXPIDLString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterCopies(nsXPIDLString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator PRUnichar**() {
|
||||
return mXPIDLString.StartAssignmentByValue();
|
||||
}
|
||||
|
||||
friend GetterCopies getter_Copies(nsXPIDLString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterCopies;
|
||||
|
||||
// A helper class for assignment-by-reference. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterShares {
|
||||
private:
|
||||
nsXPIDLString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterShares(nsXPIDLString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator const PRUnichar**() {
|
||||
return mXPIDLString.StartAssignmentByReference();
|
||||
}
|
||||
|
||||
friend GetterShares getter_Shares(nsXPIDLString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterShares;
|
||||
|
||||
private:
|
||||
// not to be implemented
|
||||
nsXPIDLString(nsXPIDLString& /* aXPIDLString */) {}
|
||||
nsXPIDLString& operator =(nsXPIDLString& /* aXPIDLString */) { return *this; }
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLString object that is to
|
||||
* receive an |out| value.
|
||||
*/
|
||||
inline nsXPIDLString::GetterCopies
|
||||
getter_Copies(nsXPIDLString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLString::GetterCopies(aXPIDLString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLString object that is to
|
||||
* receive a |[shared] out| value.
|
||||
*/
|
||||
inline nsXPIDLString::GetterShares
|
||||
getter_Shares(nsXPIDLString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLString::GetterShares(aXPIDLString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// nsXPIDLCString
|
||||
//
|
||||
// A wrapper for Unicode strings. With the |getter_Copies()| and
|
||||
// |getter_Shares()| helper functions, this can be used instead of
|
||||
// the "naked" |char*| interface for |string| parameters in XPIDL
|
||||
// interfaces.
|
||||
//
|
||||
|
||||
class NS_COM nsXPIDLCString {
|
||||
private:
|
||||
char* mBuf;
|
||||
PRBool mBufOwner;
|
||||
|
||||
char** StartAssignmentByValue();
|
||||
const char** StartAssignmentByReference();
|
||||
|
||||
public:
|
||||
/**
|
||||
* Construct a new, uninitialized wrapper for a single-byte string.
|
||||
*/
|
||||
nsXPIDLCString();
|
||||
|
||||
virtual ~nsXPIDLCString();
|
||||
|
||||
/**
|
||||
* Assign a single-byte string to this wrapper. Copies and owns the result.
|
||||
*/
|
||||
nsXPIDLCString& operator =(const char* aString);
|
||||
|
||||
/**
|
||||
* Return a reference to the immutable single-byte string.
|
||||
*/
|
||||
operator const char*();
|
||||
|
||||
/**
|
||||
* Make a copy of the single-byte string. Use this function in the
|
||||
* callee to ensure that the correct memory allocator is used.
|
||||
*/
|
||||
static char* Copy(const char* aString);
|
||||
|
||||
// A helper class for assignment-by-value. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterCopies {
|
||||
private:
|
||||
nsXPIDLCString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterCopies(nsXPIDLCString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator char**() {
|
||||
return mXPIDLString.StartAssignmentByValue();
|
||||
}
|
||||
|
||||
friend GetterCopies getter_Copies(nsXPIDLCString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterCopies;
|
||||
|
||||
// A helper class for assignment-by-reference. This class is an
|
||||
// implementation detail and should not be considered part of the
|
||||
// public interface.
|
||||
class NS_COM GetterShares {
|
||||
private:
|
||||
nsXPIDLCString& mXPIDLString;
|
||||
|
||||
public:
|
||||
GetterShares(nsXPIDLCString& aXPIDLString)
|
||||
: mXPIDLString(aXPIDLString) {}
|
||||
|
||||
operator const char**() {
|
||||
return mXPIDLString.StartAssignmentByReference();
|
||||
}
|
||||
|
||||
friend GetterShares getter_Shares(nsXPIDLCString& aXPIDLString);
|
||||
};
|
||||
|
||||
friend class GetterShares;
|
||||
|
||||
private:
|
||||
// not to be implemented
|
||||
nsXPIDLCString(nsXPIDLCString& /* aXPIDLString */) {}
|
||||
nsXPIDLCString& operator =(nsXPIDLCString& /* aXPIDLCString */) { return *this; }
|
||||
};
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLCString object that is to
|
||||
* receive an |out| value.
|
||||
*/
|
||||
inline nsXPIDLCString::GetterCopies
|
||||
getter_Copies(nsXPIDLCString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLCString::GetterCopies(aXPIDLString);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Use this function to "wrap" the nsXPIDLCString object that is to
|
||||
* receive a |[shared] out| value.
|
||||
*/
|
||||
inline nsXPIDLCString::GetterShares
|
||||
getter_Shares(nsXPIDLCString& aXPIDLString)
|
||||
{
|
||||
return nsXPIDLCString::GetterShares(aXPIDLString);
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // nsXPIDLString_h__
|
||||
@@ -1,14 +0,0 @@
|
||||
AUS Lite
|
||||
--------
|
||||
Great taste, less filling. (tm)
|
||||
|
||||
Installation
|
||||
------------
|
||||
Copy ./inc/config-dist.php to ./inc/config.php. Configure it properly following the comments.
|
||||
Set up the ./data symlink to point to the right location (/opt/aus2/incoming, for example).
|
||||
Referencing ./ with the right parameters will get you the correct XML file.
|
||||
|
||||
NOTE: source files must follow a naming convention:
|
||||
SOURCE_DIR/[product]/[platform]/[locale].txt
|
||||
|
||||
NOTE: adjust the .htaccess file's RewriteBase if you are having problems.
|
||||
@@ -1,8 +0,0 @@
|
||||
# TODO: Replace this with something simpler (Alias).
|
||||
# TODO: Then use PHP to parse path using pathinfo() instead.
|
||||
RewriteEngine On
|
||||
RewriteBase /~morgamic/aus
|
||||
RewriteRule ^update2/(.*)$ index.php?path=$1
|
||||
RewriteRule ^update/(.*)$ index.php?path=$1
|
||||
php_value error_reporting 2047
|
||||
php_value display_errors 1
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* Generic class definition for all AUS objects.
|
||||
*
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
class AUS_Object {
|
||||
|
||||
function AUS_Object() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an object parameter.
|
||||
* @param string $key
|
||||
* @param mixed $val
|
||||
* @param bool $overwrite
|
||||
* @return boolean
|
||||
*/
|
||||
function setVar($key,$val,$overwrite=false) {
|
||||
if (!isset($this->$key) || (isset($this->$key) && $overwrite)) {
|
||||
$this->$key = $val;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* Configuration file.
|
||||
* @package auslite
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
// define('SOURCE_DIR','/home/morgamic/public_html/auslite/source');
|
||||
define('SOURCE_DIR',getcwd().'/data');
|
||||
|
||||
// This is the directory containin channel-specific updates.
|
||||
// Snippets in this directory override normal updates.
|
||||
define('OVERRIDE_DIR',getcwd().'/data/3');
|
||||
|
||||
// Uncomment this line in order to echo text debug information.
|
||||
define('DEBUG',false);
|
||||
|
||||
// Define default for Update blocks.
|
||||
define('UPDATE_TYPE','minor');
|
||||
define('UPDATE_VERSION','1.0+');
|
||||
define('UPDATE_EXTENSION_VERSION','1.0+');
|
||||
|
||||
// These are channels that have access to nightly updates.
|
||||
// All other channels only have access to the OVERRIDE_DIR for update info.
|
||||
$nightlyChannels = array(
|
||||
'nightly'
|
||||
);
|
||||
|
||||
// This hash defines the version->patch relationships.
|
||||
// It determines which patches are associated to which incoming client versions.
|
||||
// @todo replace this with a better datasource that can be easily managed via a GUI.
|
||||
$branchVersions = array(
|
||||
'1.0+' => '1.5',
|
||||
'1.4' => '1.5',
|
||||
'1.4.1'=> '1.5',
|
||||
'1.5' => '1.5',
|
||||
'1.5.0.1' => '1.5.0.1',
|
||||
'1.5.0.2' => '1.5.0.2',
|
||||
'1.5.0.3' => '1.5.0.3',
|
||||
'1.5.0.4' => '1.5.0.4',
|
||||
'1.6a1'=> 'trunk',
|
||||
'2.0'=>'2.0',
|
||||
'2.0a1'=>'2.0',
|
||||
'2.0a2'=>'2.0',
|
||||
'2.0b1'=>'2.0',
|
||||
'2.0b2'=>'2.0',
|
||||
'2.0a3'=>'2.0',
|
||||
'3.0a1'=>'trunk'
|
||||
);
|
||||
?>
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* Initialization script.
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*
|
||||
* This script reads config and includes core libraries.
|
||||
* At no point should this ever output or modify data.
|
||||
*/
|
||||
ini_set('display_errors',1);
|
||||
ini_set('error_reporting',E_ALL);
|
||||
require_once('config.php'); // Read config file.
|
||||
require_once('aus.class.php'); // Generic object definition.
|
||||
require_once('xml.class.php'); // XML class for output generation.
|
||||
require_once('update.class.php'); // Update class for each update.
|
||||
require_once('patch.class.php'); // Patch class for update patches.
|
||||
?>
|
||||
@@ -1,331 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* AUS Patch class.
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*
|
||||
* This class is for handling patch objects.
|
||||
* These carry relevant information about partial or complete patches.
|
||||
*/
|
||||
class Patch extends AUS_Object {
|
||||
|
||||
// Patch metadata.
|
||||
var $type;
|
||||
var $url;
|
||||
var $hashFunction;
|
||||
var $hashValue;
|
||||
var $size;
|
||||
var $build;
|
||||
|
||||
// Array that maps versions onto their respective branches.
|
||||
var $branchVersions;
|
||||
|
||||
// Array the defines which channels are flagged as 'nightly' channels.
|
||||
var $nightlyChannels;
|
||||
|
||||
// Valid patch flag.
|
||||
var $isPatch;
|
||||
|
||||
// Is this patch a complete or partial patch?
|
||||
var $patchType;
|
||||
|
||||
// Update metadata, read from patch file.
|
||||
var $updateType;
|
||||
var $updateVersion;
|
||||
var $updateExtensionVersion;
|
||||
|
||||
// Do we have Update metadata information?
|
||||
var $hasUpdateInfo;
|
||||
var $hasDetailsUrl;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function Patch($branchVersions=array(),$nightlyChannels,$type='complete') {
|
||||
$this->setBranchVersions($branchVersions);
|
||||
$this->setNightlyChannels($nightlyChannels);
|
||||
$this->setVar('isPatch',false);
|
||||
$this->setVar('patchType',$type);
|
||||
$this->setVar('hasUpdateInfo',false);
|
||||
$this->setVar('hasDetailsUrl',false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filepath for the snippet based on product/platform/locale and
|
||||
* SOURCE_DIR, which is set in config.
|
||||
*
|
||||
* @param string $product
|
||||
* @param string $platform
|
||||
* @param string $locale
|
||||
* @param string $version
|
||||
* @param string $build
|
||||
* @param string $buildSource
|
||||
* @param string $channel
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function setPath ($product,$platform,$locale,$version=null,$build,$buildSource,$channel) {
|
||||
switch($buildSource) {
|
||||
case 3:
|
||||
return $this->setVar('path',OVERRIDE_DIR.'/'.$product.'/'.$version.'/'.$platform.'/'.$build.'/'.$locale.'/'.$channel.'/'.$this->patchType.'.txt',true);
|
||||
break;
|
||||
case 2:
|
||||
return $this->setVar('path',SOURCE_DIR.'/'.$buildSource.'/'.$product.'/'.$version.'/'.$platform.'/'.$build.'/'.$locale.'/'.$this->patchType.'.txt',true);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the given file and store its contents in our Patch object.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function setSnippet ($path) {
|
||||
if ($file = explode("\n",file_get_contents($path,true))) {
|
||||
$this->setVar('type',$file[0]);
|
||||
$this->setVar('url',$file[1]);
|
||||
$this->setVar('hashFunction',$file[2]);
|
||||
$this->setVar('hashValue',$file[3]);
|
||||
$this->setVar('size',$file[4]);
|
||||
$this->setVar('build',$file[5]);
|
||||
|
||||
// Attempt to read update information.
|
||||
// @TODO Add ability to set updateType, once it exists in the build snippet.
|
||||
if ($this->isComplete() && isset($file[6]) && isset($file[7])) {
|
||||
$this->setVar('updateVersion',$file[6],true);
|
||||
$this->setVar('updateExtensionVersion',$file[7],true);
|
||||
$this->setVar('hasUpdateInfo',true,true);
|
||||
}
|
||||
|
||||
if ($this->isComplete() && isset($file[8])) {
|
||||
$this->setVar('detailsUrl',$file[8],true);
|
||||
$this->setVar('hasDetailsUrl',true,true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to read and parse the designated source file.
|
||||
* How and where the file is read depends on the client version.
|
||||
*
|
||||
* For more information on why this is a little complicated, see:
|
||||
* https://intranet.mozilla.org/AUS:Version2:Roadmap:Multibranch
|
||||
*
|
||||
* @param string $product
|
||||
* @param string $platform
|
||||
* @param string $locale
|
||||
* @param string $version
|
||||
* @param string $build
|
||||
* @param string $channel
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function findPatch($product,$platform,$locale,$version,$build,$channel=null) {
|
||||
|
||||
// Determine the branch of the client's version.
|
||||
$branchVersion = $this->getBranch($version);
|
||||
|
||||
// If a specific update exists for the specified channel, it takes priority over the branch update.
|
||||
if (!empty($channel) && $this->setPath($product,$platform,$locale,$branchVersion,$build,3,$channel) && file_exists($this->path) && filesize($this->path) > 0) {
|
||||
$this->setSnippet($this->path);
|
||||
$this->setVar('isPatch',true,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, if it is a complete patch and a nightly channel, force the complete update to take the user to the latest build.
|
||||
elseif ($this->isComplete() && $this->isNightlyChannel($channel)) {
|
||||
|
||||
// Get the latest build for this branch.
|
||||
$latestbuild = $this->getLatestBuild($product,$branchVersion,$platform);
|
||||
|
||||
if ($this->setPath($product,$platform,$locale,$branchVersion,$latestbuild,2,$channel) && file_exists($this->path) && filesize($this->path) > 0) {
|
||||
$this->setSnippet($this->path);
|
||||
$this->setVar('isPatch',true,true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Otherwise, check for the partial snippet info. If an update exists, pass it along.
|
||||
elseif ($this->isNightlyChannel($channel) && $this->setPath($product,$platform,$locale,$branchVersion,$build,2,$channel) && file_exists($this->path) && filesize($this->path) > 0) {
|
||||
$this->setSnippet($this->path);
|
||||
$this->setVar('isPatch',true,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Note: Other data sets were made obsolete in 0.6. May incoming/0,1 rest in peace.
|
||||
|
||||
// If we get here, we know for sure that no updates exist for the current request..
|
||||
// Return false by default, which prompts the "no updates" XML output.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare passed build to build in snippet.
|
||||
* Returns true if the snippet build is newer than the client build.
|
||||
*
|
||||
* @param string $build
|
||||
* @return boolean
|
||||
*/
|
||||
function isNewBuild($build) {
|
||||
return ($this->build>$build) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the branch versions array.
|
||||
*
|
||||
* @param array $branchVersions
|
||||
* @return boolean
|
||||
*/
|
||||
function setBranchVersions($branchVersions) {
|
||||
return $this->setVar('branchVersions',$branchVersions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nightly channels array.
|
||||
*
|
||||
* @param array $branchVersions
|
||||
* @return boolean
|
||||
*/
|
||||
function setNightlyChannels($nightlyChannels) {
|
||||
return $this->setVar('nightlyChannels',$nightlyChannels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not the given channel is flagged as nightly.
|
||||
*
|
||||
* @param string $channel
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isNightlyChannel($channel) {
|
||||
return in_array($channel,$this->nightlyChannels);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether or not the incoming version is a product BRANCH.
|
||||
*
|
||||
* @param string $version
|
||||
* @return string|false
|
||||
*/
|
||||
function getBranch($version) {
|
||||
return (isset($this->branchVersions[$version])) ? $this->branchVersions[$version] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not something is Trunk.
|
||||
*
|
||||
* @param string $version
|
||||
* @return boolean
|
||||
*/
|
||||
function isTrunk($version) {
|
||||
return ($version == 'trunk') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this object contain a valid patch file?
|
||||
*/
|
||||
function isPatch() {
|
||||
return $this->isPatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this patch is complete.
|
||||
*/
|
||||
function isComplete() {
|
||||
return ($this->patchType === 'complete') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this patch has a details URL.
|
||||
*/
|
||||
function hasDetailsUrl() {
|
||||
return $this->hasDetailsUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this patch has update information.
|
||||
*/
|
||||
function hasUpdateInfo() {
|
||||
return $this->hasUpdateInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not the to_build matches the latest build for a partial patch.
|
||||
* @param string $build
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isOneStepFromLatest($build) {
|
||||
return ($this->build == $build) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest build for this branch.
|
||||
* @param string $product
|
||||
* @param string $branchVersion
|
||||
* @param string $platform
|
||||
*/
|
||||
function getLatestBuild($product,$branchVersion,$platform) {
|
||||
$files = array();
|
||||
$fp = opendir(SOURCE_DIR.'/2/'.$product.'/'.$branchVersion.'/'.$platform);
|
||||
while (false !== ($filename = readdir($fp))) {
|
||||
if ($filename!='.' && $filename!='..') {
|
||||
$files[] = $filename;
|
||||
}
|
||||
}
|
||||
closedir($fp);
|
||||
|
||||
rsort($files,SORT_NUMERIC);
|
||||
|
||||
return $files[1];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
class Update extends AUS_Object {
|
||||
var $type;
|
||||
var $version;
|
||||
var $extensionVersion;
|
||||
var $build;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
function Update($type=UPDATE_TYPE,$version=UPDATE_VERSION,$extensionVersion=UPDATE_EXTENSION_VERSION) {
|
||||
$this->setType($type);
|
||||
$this->setVersion($version);
|
||||
$this->setExtensionVersion($extensionVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type.
|
||||
* @param string $type
|
||||
*/
|
||||
function setType($type) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set verison.
|
||||
* @param string $type
|
||||
*/
|
||||
function setVersion($version) {
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extensionVersion.
|
||||
* @param string $extensionVersion
|
||||
*/
|
||||
function setExtensionVersion($extensionVersion) {
|
||||
$this->extensionVersion = $extensionVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the build.
|
||||
* @param string $build
|
||||
*/
|
||||
function setBuild($build) {
|
||||
return $this->setVar('build',$build);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the details URL.
|
||||
* @param string $details
|
||||
*/
|
||||
function setDetails($details) {
|
||||
return $this->setVar('details',$details);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type.
|
||||
* @return string
|
||||
*/
|
||||
function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version.
|
||||
* @return string
|
||||
*/
|
||||
function getVersion() {
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension version.
|
||||
* @return string
|
||||
*/
|
||||
function getExtensionVersion() {
|
||||
return $this->extensionVersion;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,143 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
class Xml extends AUS_Object {
|
||||
var $xmlOutput;
|
||||
var $xmlHeader;
|
||||
var $xmlFooter;
|
||||
var $xmlPatchLines;
|
||||
|
||||
/**
|
||||
* Constructor, sets overall header and footer.
|
||||
*/
|
||||
function Xml() {
|
||||
$this->xmlHeader = '<?xml version="1.0"?>'."\n".'<updates>';
|
||||
$this->xmlFooter = "\n".'</updates>';
|
||||
$this->xmlOutput = $this->xmlHeader;
|
||||
$this->xmlPatchLines = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an update block.
|
||||
* @param object $update
|
||||
*/
|
||||
function startUpdate($update) {
|
||||
$type = htmlentities($update->type);
|
||||
$version = htmlentities($update->version);
|
||||
$extensionVersion = htmlentities($update->extensionVersion);
|
||||
$build = htmlentities($update->build);
|
||||
$details = htmlentities($update->details);
|
||||
|
||||
$details_xml = "";
|
||||
if (strlen($details) > 0) {
|
||||
$details_xml = " detailsURL=\"{$details}\"";
|
||||
}
|
||||
|
||||
$this->xmlOutput .= <<<startUpdate
|
||||
|
||||
<update type="{$type}" version="{$version}" extensionVersion="{$extensionVersion}" buildID="{$build}" {$details_xml}>
|
||||
startUpdate;
|
||||
|
||||
/**
|
||||
* @TODO Add buildID attribute to <update> element.
|
||||
*
|
||||
* Right now it is pending QA on the client side, so we will leave it
|
||||
* out for now.
|
||||
*
|
||||
* buildID="{$build}"
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a patch line. This pulls info from a patch object.
|
||||
* @param object $patch
|
||||
*/
|
||||
function setPatchLine($patch) {
|
||||
$type = htmlentities($patch->type);
|
||||
$url = htmlentities($patch->url);
|
||||
$hashFunction = htmlentities($patch->hashFunction);
|
||||
$hashValue = htmlentities($patch->hashValue);
|
||||
$size = htmlentities($patch->size);
|
||||
|
||||
$this->xmlPatchLines .= <<<patchLine
|
||||
|
||||
<patch type="{$type}" URL="{$url}" hashFunction="{$hashFunction}" hashValue="{$hashValue}" size="{$size}"/>
|
||||
patchLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not patchLines have been set.
|
||||
* @return bool
|
||||
*/
|
||||
function hasPatchLine() {
|
||||
return (empty($this->xmlPatchLines)) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* End an update block.
|
||||
*/
|
||||
function endUpdate() {
|
||||
$this->xmlOutput .= <<<endUpdate
|
||||
|
||||
</update>
|
||||
endUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add patchLines to output.
|
||||
*/
|
||||
function drawPatchLines() {
|
||||
$this->xmlOutput .= $this->xmlPatchLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get XML output.
|
||||
* @return $string $this->xmlOutput
|
||||
*/
|
||||
function getOutput() {
|
||||
$this->xmlOutput .= $this->xmlFooter;
|
||||
return $this->xmlOutput;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,217 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* AUS Lite main script.
|
||||
* @package auslite
|
||||
* @subpackage docs
|
||||
* @author Mike Morgan
|
||||
*
|
||||
* This script handles incoming requests, reads the related build
|
||||
* snippet and returns a properly formatted XML file for testing.
|
||||
*/
|
||||
|
||||
// Require config and supporting libraries.
|
||||
require_once('./inc/init.php');
|
||||
|
||||
// Instantiate XML object.
|
||||
$xml = new Xml();
|
||||
|
||||
// Find everything between our CWD and 255 in QUERY_STRING.
|
||||
$rawPath = substr(urldecode($_SERVER['QUERY_STRING']),5,255);
|
||||
|
||||
// Munge he resulting string and store it in $path.
|
||||
$path = explode('/',$rawPath);
|
||||
|
||||
// Determine incoming request and clean inputs.
|
||||
// These are common URL elements, agreed upon in revision 0.
|
||||
$clean = Array();
|
||||
$clean['updateVersion'] = isset($path[0]) ? intval($path[0]) : null;
|
||||
$clean['product'] = isset($path[1]) ? trim($path[1]) : null;
|
||||
$clean['version'] = isset($path[2]) ? urlencode($path[2]) : null;
|
||||
$clean['build'] = isset($path[3]) ? trim($path[3]) : null;
|
||||
$clean['platform'] = isset($path[4]) ? trim($path[4]) : null;
|
||||
$clean['locale'] = isset($path[5]) ? trim($path[5]) : null;
|
||||
|
||||
// For each updateVersion, we will run separate code.
|
||||
switch ($clean['updateVersion']) {
|
||||
|
||||
/*
|
||||
* This is for the second revision of the URL schema, with %CHANNEL% added.
|
||||
* /update2/1/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/update.xml
|
||||
*/
|
||||
case 1:
|
||||
|
||||
// Check for a set channel.
|
||||
$clean['channel'] = isset($path[6]) ? trim($path[6]) : null;
|
||||
|
||||
// Instantiate Update object and set updateVersion.
|
||||
$update = new Update();
|
||||
|
||||
// Instantiate our complete patch.
|
||||
$completePatch = new Patch($branchVersions,$nightlyChannels,'complete');
|
||||
|
||||
// Find our complete patch.
|
||||
$completePatch->findPatch($clean['product'],$clean['platform'],$clean['locale'],$clean['version'],$clean['build'],$clean['channel']);
|
||||
|
||||
// If our complete patch is valid, set the patch line.
|
||||
if ($completePatch->isPatch() && $completePatch->isNewBuild($clean['build'])) {
|
||||
|
||||
// Set our patchLine.
|
||||
$xml->setPatchLine($completePatch);
|
||||
|
||||
// If available, pull update information from the build snippet.
|
||||
// @TODO Add ability to set updateType.
|
||||
if ($completePatch->hasUpdateInfo()) {
|
||||
$update->setVersion($completePatch->updateVersion);
|
||||
$update->setExtensionVersion($completePatch->updateExtensionVersion);
|
||||
$update->setBuild($completePatch->build);
|
||||
}
|
||||
|
||||
if ($completePatch->hasDetailsUrl()) {
|
||||
$update->setDetails($completePatch->detailsUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// We only check for a partial patch if the complete patch was successfully retrieved.
|
||||
if ($completePatch->isPatch()) {
|
||||
|
||||
// Instantiate our partial patch.
|
||||
$partialPatch = new Patch($branchVersions,$nightlyChannels,'partial');
|
||||
$partialPatch->findPatch($clean['product'],$clean['platform'],$clean['locale'],$clean['version'],$clean['build'],$clean['channel']);
|
||||
|
||||
// If our partial patch is valid, set the patch line.
|
||||
// We only want to deliver the partial patch if the destination build for the partial patch is equal to the build in the complete patch (which will always point to the latest).
|
||||
if ($partialPatch->isPatch() && $partialPatch->isNewBuild($clean['build']) && $partialPatch->isOneStepFromLatest($completePatch->build)) {
|
||||
$xml->setPatchLine($partialPatch);
|
||||
}
|
||||
}
|
||||
|
||||
// If we have valid patchLine(s), set up our output.
|
||||
if ($xml->hasPatchLine()) {
|
||||
$xml->startUpdate($update);
|
||||
$xml->drawPatchLines();
|
||||
$xml->endUpdate();
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* This is for the first revision of the URL schema.
|
||||
* /update2/0/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/update.xml
|
||||
*/
|
||||
case 0:
|
||||
default:
|
||||
|
||||
// Instantiate Update object and set updateVersion.
|
||||
$update = new Update();
|
||||
|
||||
// Instantiate Patch object and set Path based on passed args.
|
||||
$patch = new Patch($branchVersions,$nightlyChannels,'complete');
|
||||
|
||||
$patch->findPatch($clean['product'],$clean['platform'],$clean['locale'],$clean['version'],$clean['build'],null);
|
||||
|
||||
if ($patch->isPatch()) {
|
||||
$xml->setPatchLine($patch);
|
||||
}
|
||||
|
||||
// If we have a new build, draw the update block and patch line.
|
||||
// If there is no valid patch file, client will receive no updates by default.
|
||||
if ($xml->hasPatchLine() && $patch->isNewBuild($clean['build'])) {
|
||||
$xml->startUpdate($update);
|
||||
$xml->drawPatchLines();
|
||||
$xml->endUpdate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// If we are debugging output plaintext and exit.
|
||||
if ( defined('DEBUG') && DEBUG == true ) {
|
||||
|
||||
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
|
||||
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
|
||||
echo '<head>'."\n";
|
||||
echo '<title>AUS Debug Information</title>'."\n";
|
||||
echo '</head>'."\n";
|
||||
echo '<body>'."\n";
|
||||
echo '<h1>AUS Debug Information</h1>'."\n";
|
||||
|
||||
echo '<h2>XML Output</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
echo htmlentities($xml->getOutput());
|
||||
echo '</pre>'."\n";
|
||||
|
||||
if (!empty($clean)) {
|
||||
echo '<h2>Inputs</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
print_r($clean);
|
||||
echo '</pre>'."\n";
|
||||
}
|
||||
|
||||
echo '<h2>Patch Objects</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
if (!empty($patch)) {
|
||||
print_r($patch);
|
||||
}
|
||||
if (!empty($completePatch)) {
|
||||
print_r($completePatch);
|
||||
}
|
||||
if (!empty($partialPatch)) {
|
||||
print_r($partialPatch);
|
||||
}
|
||||
echo '</pre>'."\n";
|
||||
|
||||
if (!empty($update)) {
|
||||
echo '<h2>Update Object</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
print_r($update);
|
||||
echo '</pre>'."\n";
|
||||
}
|
||||
|
||||
echo '</body>'."\n";
|
||||
echo '</html>';
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
// Set header and send info.
|
||||
// Default output will be a blank document (no updates available).
|
||||
header('Content-type: text/xml;');
|
||||
echo $xml->getOutput();
|
||||
exit;
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
<update type="minor" version="1.4.1" extensionVersion="1.4.1" buildID="2005100606" >
|
||||
<patch type="complete" URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5b2/update/complete/en-US/firefox-1.5b2.mac.mar" hashFunction="MD5" hashValue="18851d4672da119c1f77168f36031246" size="8775022"/>
|
||||
<patch type="partial" URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5b2/update/partial/en-US/firefox-1.5b1-1.5b2.mac.mar" hashFunction="MD5" hashValue="1ec26f92ac972827082763ec1680602a" size="1112776"/>
|
||||
</update>
|
||||
</updates>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
<update type="minor" version="1.4.1" extensionVersion="1.4.1" buildID="2005100604" >
|
||||
<patch type="complete" URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5b2/update/complete/en-US/firefox-1.5b2.linux-i686.mar" hashFunction="SHA1" hashValue="57ce3fab1b25906a59d1962bdc4a3d56db5ca3e8" size="7948446"/>
|
||||
<patch type="partial" URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5b2/update/partial/en-US/firefox-1.5b1-1.5b2.linux-i686.mar" hashFunction="SHA1" hashValue="f386ef102b7723f417ca7d250bd460321478ae21" size="781040"/>
|
||||
</update>
|
||||
</updates>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
<update type="minor" version="1.4.1" extensionVersion="1.4.1" buildID="2005100614" >
|
||||
<patch type="complete" URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5b2/update/complete/en-US/firefox-1.5b2.win32.mar" hashFunction="SHA1" hashValue="b7ed4485e991b2e19c5d57757ace4a5fd8311db9" size="6306511"/>
|
||||
<patch type="partial" URL="http://ftp.mozilla.org/pub/mozilla.org/firefox/releases/1.5b2/update/partial/en-US/firefox-1.5b1-1.5b2.win32.mar" hashFunction="SHA1" hashValue="e8c61fa7523a34cd8cb5b395e73f5c411ca1a941" size="801010"/>
|
||||
</update>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,3 +0,0 @@
|
||||
<?xml version="1.0"?>
|
||||
<updates>
|
||||
</updates>
|
||||
@@ -1,241 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* AUS sanity check intro page.
|
||||
*
|
||||
* @package aus
|
||||
* @subpackage sanity
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
|
||||
// Read .ini file for config options.
|
||||
$config = parse_ini_file('./sanity.ini',true);
|
||||
|
||||
// Include common functions.
|
||||
require_once('./sanity.inc.php');
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Redirect to log or reports if they have been requested.
|
||||
*/
|
||||
if (!empty($_POST['redirect'])) {
|
||||
$path = (isset($_POST['logs'])) ? './log/' : './reports/';
|
||||
header('Location: '.$path.$_POST['redirect']);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Regenerate control files.
|
||||
*/
|
||||
if (!empty($_POST['control']) && !empty($_POST['controlName'])) {
|
||||
|
||||
// Set destination directory.
|
||||
$dir = $config['sources']['controlFiles'].str_replace(' ','_',$_POST['controlName']);
|
||||
|
||||
// If this directory does not exist, create it.
|
||||
if (!is_dir($dir)) {
|
||||
mkdir($dir);
|
||||
}
|
||||
|
||||
$msg = array('Added control files successfully...');
|
||||
|
||||
// For each test case, grab and store results.
|
||||
foreach ($config['testCases'] as $name=>$url) {
|
||||
$result = trim(file_get_contents($_POST['control'].$url));
|
||||
$file = $dir.'/'.str_replace(' ','_',$name).'.xml';
|
||||
write($file,$result);
|
||||
$msg[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Read log and reports directories.
|
||||
*/
|
||||
|
||||
// Gather possible options for controls.
|
||||
$controls_select = '';
|
||||
$controls = ls($config['sources']['controlFiles'],'/^[^.].*/');
|
||||
foreach ($controls as $dir) {
|
||||
$controls_select .= '<option value="'.$dir.'">'.$dir.'</option>'."\n";
|
||||
}
|
||||
|
||||
// Gather possible targets for select list.
|
||||
$targets_select = '';
|
||||
if (!empty($config['targets']) && is_array($config['targets'])) {
|
||||
foreach ($config['targets'] as $name=>$val) {
|
||||
$targets_select .= '<option value="'.$val.'">'.$name.'</option>';
|
||||
}
|
||||
}
|
||||
|
||||
// Log files from the log directory defined in our config.
|
||||
$logs_select = '';
|
||||
$logs = ls($config['sources']['log'],'/^.*log$/','asc');
|
||||
foreach ($logs as $filename) {
|
||||
$buf = explode('.',$filename);
|
||||
$readable = timify($buf[0]);
|
||||
$logs_select .= '<option value="'.$filename.'">'.$readable.'</option>'."\n";
|
||||
}
|
||||
|
||||
// HTML Reports from the reports directory defined in our config.
|
||||
$reports_select = '';
|
||||
$reports = ls($config['sources']['reports'],'/^.*html$/','asc');
|
||||
foreach ($reports as $filename) {
|
||||
$buf = explode('.',$filename);
|
||||
$readable = timify($buf[0],false);
|
||||
$reports_select .= '<option value="'.$filename.'">'.$readable.'</option>'."\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate HTML.
|
||||
*/
|
||||
$html = '';
|
||||
$html .= <<<HEADER
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>AUS Regression Tests :: mozilla.org</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<meta name="rating" content="General"/>
|
||||
<meta name="robots" content="All"/>
|
||||
<style type="text/css">
|
||||
.control { display: block; float: left; width: 15em; }
|
||||
.test { display: block; float: left; width: 8em; }
|
||||
.msg { color: green; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>AUS Regression Testing</h1>
|
||||
<p>All tests use the defined test cases in <kbd>sanity.ini</kbd>.</p>
|
||||
HEADER;
|
||||
|
||||
// Messages, if any.
|
||||
if (!empty($msg) && is_array($msg)) {
|
||||
$html .= '<ul class="msg">'."\n";
|
||||
foreach ($msg as $li) {
|
||||
$html .= '<li>'.$li.'</li>'."\n";
|
||||
}
|
||||
$html .= '</ul>'."\n";
|
||||
}
|
||||
|
||||
$html .= <<<PAGE
|
||||
<h2>Run a New Test</h2>
|
||||
<p>To begin a test, choose a <kbd>Control</kbd> and a <kbd>Target</kbd> then hit
|
||||
<kbd>Begin Test</kbd>. You will be redirected to a static HTML report.</p>
|
||||
<form action="./sanity.php" method="post">
|
||||
<div>
|
||||
<label for="testControl" class="test">Control</label>
|
||||
<select name="testControl" id="testControl">
|
||||
{$controls_select}
|
||||
</select>
|
||||
</div><br/>
|
||||
<fieldset>
|
||||
<legend>Target</legend>
|
||||
<div>
|
||||
<label for="testTarget" class="test">Defined Target</label>
|
||||
<select name="testTarget" id="testTarget">
|
||||
{$targets_select}
|
||||
</select>
|
||||
</div>
|
||||
<p>-- OR --</p>
|
||||
<div>
|
||||
<label for="testTargetOverride" class="test">Custom Target</label>
|
||||
<input type="text" name="testTargetOverride" id="testTargetOverride" value="" size="77"/>
|
||||
</div>
|
||||
<p><em>Note:</em> If a <kbd>Custom Target</kbd> is defined, it will override any selected <kbd>Defined Targets</kbd>.</p>
|
||||
</fieldset><br/>
|
||||
<div>
|
||||
<input type="submit" name="submit" value="Begin Test »"/>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h2>Generate New Control Files</h2>
|
||||
<form action="./" method="post">
|
||||
<div>
|
||||
<label for="controlName" class="control">Name of control source</label>
|
||||
<input type="text" name="controlName" id="controlName" value="{$config['defaults']['controlName']}" size="77"/>
|
||||
<input type="hidden" name="action" value="control" />
|
||||
</div><br/>
|
||||
<div>
|
||||
<label for="control" class="control">Location of control source</label>
|
||||
<input type="text" name="control" id="control" value="{$config['defaults']['control']}" size="77"/>
|
||||
</div><br/>
|
||||
<div>
|
||||
<input type="submit" name="submit" value="Generate New Control Files »"/>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h2>Logs & Reports</h2>
|
||||
<form action="./" method="post">
|
||||
<h3>Logs</h3>
|
||||
<div>
|
||||
<select name="redirect" id="logs">
|
||||
{$logs_select}
|
||||
</select>
|
||||
<input type="submit" name="logs" value="View Log »"/>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<h3>Reports</h3>
|
||||
<form action="./" method="post">
|
||||
<div>
|
||||
<select name="redirect" id="reports">
|
||||
{$reports_select}
|
||||
</select>
|
||||
<input type="submit" name="reports" value="View Report »"/>
|
||||
</div>
|
||||
</form>
|
||||
PAGE;
|
||||
|
||||
$html .= <<<FOOTER
|
||||
</body>
|
||||
</html>
|
||||
FOOTER;
|
||||
|
||||
echo $html;
|
||||
?>
|
||||
@@ -1,106 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* Common functions
|
||||
*
|
||||
* @package aus
|
||||
* @subpackage sanity
|
||||
*/
|
||||
|
||||
/**
|
||||
* Read a directory and return a sorted array of its contents.
|
||||
* @string $dir path to directory
|
||||
* @string $pattern pattern matching valid filenames
|
||||
* @return array
|
||||
*/
|
||||
function ls($dir,$pattern, $sort='desc') {
|
||||
$files = array();
|
||||
$fp = opendir($dir);
|
||||
while (false !== ($filename = readdir($fp))) {
|
||||
if (preg_match($pattern,$filename)) {
|
||||
$files[] = $filename;
|
||||
}
|
||||
}
|
||||
closedir($fp);
|
||||
|
||||
if ($sort=='asc') {
|
||||
rsort($files);
|
||||
} else {
|
||||
sort($files);
|
||||
}
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a string to a file.
|
||||
* @string $file file
|
||||
* @string $string string
|
||||
*/
|
||||
function write($file,$string) {
|
||||
if ($fp = fopen($file,'w')) {
|
||||
fwrite($fp,$string);
|
||||
fclose($fp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get date.
|
||||
* @param string $datestring
|
||||
* @param boolean $fuzzy
|
||||
* @return string
|
||||
*/
|
||||
function timify($datestring,$fuzzy=true) {
|
||||
$year = substr($datestring,0,4);
|
||||
$month = substr($datestring,4,2);
|
||||
$day = substr($datestring,6,2);
|
||||
|
||||
if (!$fuzzy) {
|
||||
$hour = substr($datestring,8,2);
|
||||
$minute = substr($datestring,10,2);
|
||||
$second = substr($datestring,12,2);
|
||||
|
||||
return date( 'D F j, Y, g:i a', mktime($hour, $minute, $second, $month, $day, $year));
|
||||
} else {
|
||||
|
||||
return date( 'D F j, Y', mktime(0, 0, 0, $month, $day, $year));
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,85 +0,0 @@
|
||||
; ***** BEGIN LICENSE BLOCK *****
|
||||
;
|
||||
; Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
;
|
||||
; The contents of this file are subject to the Mozilla Public License Version
|
||||
; 1.1 (the "License"); you may not use this file except in compliance with
|
||||
; the License. You may obtain a copy of the License at
|
||||
; http://www.mozilla.org/MPL/
|
||||
;
|
||||
; Software distributed under the License is distributed on an "AS IS" basis,
|
||||
; WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
; for the specific language governing rights and limitations under the
|
||||
; License.
|
||||
;
|
||||
; The Original Code is AUS.
|
||||
;
|
||||
; The Initial Developer of the Original Code is Mike Morgan.
|
||||
;
|
||||
; Portions created by the Initial Developer are Copyright (C) 2006
|
||||
; the Initial Developer. All Rights Reserved.
|
||||
;
|
||||
; Contributor(s):
|
||||
; Mike Morgan <morgamic@mozilla.com>
|
||||
;
|
||||
; Alternatively, the contents of this file may be used under the terms of
|
||||
; either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
; the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
; in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
; of those above. If you wish to allow use of your version of this file only
|
||||
; under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
; use your version of this file under the terms of the MPL, indicate your
|
||||
; decision by deleting the provisions above and replace them with the notice
|
||||
; and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
; the provisions above, a recipient may use your version of this file under
|
||||
; the terms of any one of the MPL, the GPL or the LGPL.
|
||||
;
|
||||
; ***** END LICENSE BLOCK *****
|
||||
;
|
||||
; This file defines test cases for AUS.
|
||||
;
|
||||
; Each test case is a URL. Examples:
|
||||
; [testCases]
|
||||
; FooBar = 1/Firefox/1.4/2005090806/Darwin_ppc-gcc3/en-US/beta/update.xml
|
||||
; FOOTOO = 1/Firefox/1.4/2005090806/WINNT_x86-msvc/en-US/beta/update.xml
|
||||
; Zoinks! = 1/Firefox/1.4/2005090805/Linux_x86-gcc3/en-US/beta/update.xml
|
||||
;
|
||||
; The test names lead the test script to look in [files]/testname.xml for the
|
||||
; control source.
|
||||
;
|
||||
; NOTE: Test names with spaces will be written to files with '_'. Example:
|
||||
; Foo Foo Test -> [files]/Foo_Foo_Test.xml
|
||||
;
|
||||
; The test script tests output between a control and a new version of AUS.
|
||||
;
|
||||
; By comparing output, we can test for regressions.
|
||||
;
|
||||
; Explanations for these test-case parameters can be found at:
|
||||
; https://intranet.mozilla.org/AUS:Version2:Test_Cases
|
||||
;
|
||||
;
|
||||
[defaults]
|
||||
control = https://aus2.mozilla.org/update/
|
||||
controlName = AUS2_Prod
|
||||
target = https://aus2-staging.mozilla.org:8711/update/
|
||||
|
||||
[targets]
|
||||
AUS2 Staging = https://aus2-staging.mozilla.org:8711/update/
|
||||
AUS2 Dev = https://aus2-dev.mozilla.org:7777/update/
|
||||
AUS2 Production = https://aus2.mozilla.org/update/
|
||||
morgamic's Patch = "https://update-staging.mozilla.org/~morgamic/aus/update/"
|
||||
|
||||
[sources]
|
||||
controlFiles = /home/morgamic/public_html/sanity/control/
|
||||
reports = /home/morgamic/public_html/sanity/reports/
|
||||
log = /home/morgamic/public_html/sanity/log/
|
||||
|
||||
[testCases]
|
||||
Fx 1.5.0.3 Mac Univ = 1/Firefox/1.5.0.3/2006042618/Darwin_Universal-gcc3/en-US/releasetest/update.xml
|
||||
Fx 3.0a1 Mac PPC 1-off = 1/Firefox/3.0a1/2006052405/Darwin_ppc-gcc3/en-US/nightly/update.xml
|
||||
Fx 3.0a1 Win 1-off = 1/Firefox/3.0a1/2006052404/WINNT_x86-msvc/en-US/nightly/update.xml
|
||||
Fx 3.0a1 Linux 1-off = 1/Firefox/3.0a1/2006052404/Linux_x86-gcc3/en-US/nightly/update.xml
|
||||
Fx 3.0a1 Mac PPC 3-off = 1/Firefox/3.0a1/2006052204/Darwin_ppc-gcc3/en-US/nightly/update.xml
|
||||
Fx 3.0a1 Win 3-off = 1/Firefox/3.0a1/2006052205/WINNT_x86-msvc/en-US/nightly/update.xml
|
||||
Fx 3.0a1 Linux 3-off = 1/Firefox/3.0a1/2006052204/Linux_x86-gcc3/en-US/nightly/update.xml
|
||||
|
||||
@@ -1,216 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* AUS sanity check.
|
||||
*
|
||||
* @package aus
|
||||
* @subpackage sanity
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
|
||||
/**
|
||||
* Process test cases and config file.
|
||||
*/
|
||||
$config = parse_ini_file('./sanity.ini',true);
|
||||
|
||||
// Variables.
|
||||
$results = array(); // Results array.
|
||||
$count = 1; // Test count.
|
||||
$filename = date('YmdHis'); // Date-based filename for log and report file.
|
||||
|
||||
// For each test case, compare output and store results.
|
||||
foreach ($config['testCases'] as $name=>$url) {
|
||||
$time = date('r'); // Time of actual test.
|
||||
|
||||
$control = (!empty($_POST['testControl'])) ? $config['sources']['controlFiles'].$_POST['testControl'].'/'.str_replace(' ','_',$name).'.xml' : $config['sources']['controlFiles'].$config['defaults']['controlName'].'/'.str_replace(' ','_',$name).'.xml';
|
||||
|
||||
$target = (!empty($_POST['testTargetOverride'])) ? $_POST['testTargetOverride'].$url : ((!empty($_POST['testTarget'])) ? $_POST['testTarget'].$url : $config['defaults']['target'].$url);
|
||||
|
||||
$controlResult = trim(file_get_contents($control));
|
||||
$targetResult = trim(file_get_contents($target));
|
||||
|
||||
|
||||
// @TODO Would be nice to diff this instead.
|
||||
// There is a PHP implementation of diff, might try that, time allowing:
|
||||
// http://pear.php.net/package/Text_Diff
|
||||
if ($controlResult == $targetResult) {
|
||||
$result = 'OK';
|
||||
} else {
|
||||
$result = 'FAILED';
|
||||
}
|
||||
|
||||
// Store results.
|
||||
$results[] = array(
|
||||
'count' => $count,
|
||||
'name' => $name,
|
||||
'result' => $result,
|
||||
'controlResult' => $controlResult,
|
||||
'controlURL' => $control,
|
||||
'targetResult' => $targetResult,
|
||||
'targetURL' => $target.$url,
|
||||
'url' => $url,
|
||||
'time' => $time
|
||||
);
|
||||
|
||||
// If using the CLI, output to STDOUT.
|
||||
if (empty($_SERVER['HTTP_HOST'])) {
|
||||
if ($count == 1) {
|
||||
echo 'AUS Regression Test Started '.date('YmdHis').' ...'."\n";
|
||||
}
|
||||
echo "{$count} {$name} {$time} {$result} {$url}\n";
|
||||
}
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
if (empty($_SERVER['HTTP_HOST'])) {
|
||||
echo 'Test Completed. See ./log/'.date('Ymd').'.log for more information, or ./reports/'.date('YmdHis').'.html for an HTML report.'."\n\n";
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Generate HTML for display/write.
|
||||
*/
|
||||
$html = '';
|
||||
$html .= <<<HEADER
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
|
||||
<head>
|
||||
<title>AUS Regression Tests :: mozilla.org</title>
|
||||
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
|
||||
<meta name="rating" content="General"/>
|
||||
<meta name="robots" content="All"/>
|
||||
<style type="text/css" media="all">
|
||||
table { border: 1px solid #666; }
|
||||
td { border: 1px solid #666; white-space: nowrap; }
|
||||
td.xml { white-space: normal; }
|
||||
th { font-weight: bold; background-color: #999; white-space: nowrap; }
|
||||
.row1 { background-color: #ccc; }
|
||||
.row2 { background-color: #eee; }
|
||||
.OK { background-color: #9f9; }
|
||||
.FAILED { background-color: #f99; }
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Regression Test Results</h1>
|
||||
HEADER;
|
||||
|
||||
$html .= <<<TABLETOP
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th nowrap="nowrap">Test Name</th>
|
||||
<th nowrap="nowrap">Time</th>
|
||||
<th nowrap="nowrap">Test Result</th>
|
||||
<th nowrap="nowrap">Params</th>
|
||||
<th nowrap="nowrap">Control ({$control})</th>
|
||||
<th nowrap="nowrap">Result ({$target})</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
TABLETOP;
|
||||
|
||||
foreach ($results as $row) {
|
||||
$controlResultHTML = htmlentities($row['controlResult']);
|
||||
$targetResultHTML = htmlentities($row['targetResult']);
|
||||
|
||||
$class = $row['count']%2;
|
||||
|
||||
|
||||
$html .= <<<TABLEROW
|
||||
<tr class="row{$class}">
|
||||
<td>{$row['count']}</td>
|
||||
<td>{$row['name']}</td>
|
||||
<td>{$row['time']}</td>
|
||||
<td class="{$row['result']}">{$row['result']}</td>
|
||||
<td>{$row['url']}</td>
|
||||
<td class="xml"><pre>{$controlResultHTML}</pre></td>
|
||||
<td class="xml"><pre>{$targetResultHTML}</pre></td>
|
||||
</tr>
|
||||
TABLEROW;
|
||||
}
|
||||
|
||||
$html .= <<<TABLEBOTTOM
|
||||
</tbody>
|
||||
</table>
|
||||
TABLEBOTTOM;
|
||||
|
||||
$html .= <<<FOOTER
|
||||
</body>
|
||||
</html>
|
||||
FOOTER;
|
||||
|
||||
// Write HTML report file.
|
||||
$fp = fopen('./reports/'.$filename.'.html','w+');
|
||||
fwrite($fp, $html);
|
||||
fclose($fp);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Store all results to log file in ./log directory.
|
||||
* Log filenames are date-based.
|
||||
*/
|
||||
$log = '';
|
||||
foreach ($results as $row) {
|
||||
$log .= <<<LINE
|
||||
{$row['count']} {$row['name']} {$row['time']} {$row['result']} {$row['url']}
|
||||
|
||||
LINE;
|
||||
}
|
||||
|
||||
// Write the log file.
|
||||
// Log files will be written per-day.
|
||||
$fp = fopen('./log/'.date('Ymd').'.log', 'a');
|
||||
fwrite($fp, $log);
|
||||
fclose($fp);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* If the request is over HTTP, redirect to HTML report.
|
||||
*/
|
||||
if (!empty($_SERVER['HTTP_HOST']) && !empty($_POST['submit'])) {
|
||||
header('Location: ./reports/'.$filename.'.html');
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
@@ -1,14 +0,0 @@
|
||||
AUS Lite
|
||||
--------
|
||||
Great taste, less filling. (tm)
|
||||
|
||||
Installation
|
||||
------------
|
||||
Copy ./inc/config-dist.php to ./inc/config.php. Configure it properly following the comments.
|
||||
Set up the ./data symlink to point to the right location (/opt/aus2/incoming, for example).
|
||||
Referencing ./ with the right parameters will get you the correct XML file.
|
||||
|
||||
NOTE: source files must follow a naming convention:
|
||||
SOURCE_DIR/[product]/[platform]/[locale].txt
|
||||
|
||||
NOTE: adjust the .htaccess file's RewriteBase if you are having problems.
|
||||
@@ -1,8 +0,0 @@
|
||||
# TODO: Replace this with something simpler (Alias).
|
||||
# TODO: Then use PHP to parse path using pathinfo() instead.
|
||||
RewriteEngine On
|
||||
RewriteBase /~morgamic/aus
|
||||
RewriteRule ^update2/(.*)$ index.php?path=$1
|
||||
RewriteRule ^update/(.*)$ index.php?path=$1
|
||||
php_value error_reporting 2047
|
||||
php_value display_errors 1
|
||||
@@ -1,68 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* Generic class definition for all AUS objects.
|
||||
*
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
class AUS_Object {
|
||||
|
||||
function AUS_Object() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set an object parameter.
|
||||
* @param string $key
|
||||
* @param mixed $val
|
||||
* @param bool $overwrite
|
||||
* @return boolean
|
||||
*/
|
||||
function setVar($key,$val,$overwrite=false) {
|
||||
if (!isset($this->$key) || (isset($this->$key) && $overwrite)) {
|
||||
$this->$key = $val;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,88 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* Configuration file.
|
||||
* @package auslite
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
// define('SOURCE_DIR','/home/morgamic/public_html/auslite/source');
|
||||
define('SOURCE_DIR',getcwd().'/data');
|
||||
|
||||
// This is the directory containin channel-specific updates.
|
||||
// Snippets in this directory override normal updates.
|
||||
define('OVERRIDE_DIR',getcwd().'/data/3');
|
||||
|
||||
// Uncomment this line in order to echo text debug information.
|
||||
define('DEBUG',false);
|
||||
|
||||
// Define default for Update blocks.
|
||||
define('UPDATE_TYPE','minor');
|
||||
define('UPDATE_VERSION','1.0+');
|
||||
define('UPDATE_EXTENSION_VERSION','1.0+');
|
||||
|
||||
// These are channels that have access to nightly updates.
|
||||
// All other channels only have access to the OVERRIDE_DIR for update info.
|
||||
$nightlyChannels = array(
|
||||
'nightly'
|
||||
);
|
||||
|
||||
// This hash defines the version->patch relationships.
|
||||
// It determines which patches are associated to which incoming client versions.
|
||||
// @todo replace this with a better datasource that can be easily managed via a GUI.
|
||||
$branchVersions = array(
|
||||
'1.0+' => '1.5',
|
||||
'1.4' => '1.5',
|
||||
'1.4.1'=> '1.5',
|
||||
'1.5' => '1.5',
|
||||
'1.5.0.1' => '1.5.0.1',
|
||||
'1.5.0.2' => '1.5.0.2',
|
||||
'1.5.0.3' => '1.5.0.3',
|
||||
'1.5.0.4' => '1.5.0.4',
|
||||
'1.6a1'=> 'trunk',
|
||||
'2.0'=>'2.0',
|
||||
'2.0a1'=>'2.0',
|
||||
'2.0a2'=>'2.0',
|
||||
'2.0b1'=>'2.0',
|
||||
'2.0b2'=>'2.0',
|
||||
'2.0a3'=>'2.0',
|
||||
'3.0a1'=>'trunk'
|
||||
);
|
||||
?>
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* Initialization script.
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*
|
||||
* This script reads config and includes core libraries.
|
||||
* At no point should this ever output or modify data.
|
||||
*/
|
||||
ini_set('display_errors',1);
|
||||
ini_set('error_reporting',E_ALL);
|
||||
require_once('config.php'); // Read config file.
|
||||
require_once('aus.class.php'); // Generic object definition.
|
||||
require_once('xml.class.php'); // XML class for output generation.
|
||||
require_once('update.class.php'); // Update class for each update.
|
||||
require_once('patch.class.php'); // Patch class for update patches.
|
||||
?>
|
||||
@@ -1,331 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* AUS Patch class.
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*
|
||||
* This class is for handling patch objects.
|
||||
* These carry relevant information about partial or complete patches.
|
||||
*/
|
||||
class Patch extends AUS_Object {
|
||||
|
||||
// Patch metadata.
|
||||
var $type;
|
||||
var $url;
|
||||
var $hashFunction;
|
||||
var $hashValue;
|
||||
var $size;
|
||||
var $build;
|
||||
|
||||
// Array that maps versions onto their respective branches.
|
||||
var $branchVersions;
|
||||
|
||||
// Array the defines which channels are flagged as 'nightly' channels.
|
||||
var $nightlyChannels;
|
||||
|
||||
// Valid patch flag.
|
||||
var $isPatch;
|
||||
|
||||
// Is this patch a complete or partial patch?
|
||||
var $patchType;
|
||||
|
||||
// Update metadata, read from patch file.
|
||||
var $updateType;
|
||||
var $updateVersion;
|
||||
var $updateExtensionVersion;
|
||||
|
||||
// Do we have Update metadata information?
|
||||
var $hasUpdateInfo;
|
||||
var $hasDetailsUrl;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*/
|
||||
function Patch($branchVersions=array(),$nightlyChannels,$type='complete') {
|
||||
$this->setBranchVersions($branchVersions);
|
||||
$this->setNightlyChannels($nightlyChannels);
|
||||
$this->setVar('isPatch',false);
|
||||
$this->setVar('patchType',$type);
|
||||
$this->setVar('hasUpdateInfo',false);
|
||||
$this->setVar('hasDetailsUrl',false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the filepath for the snippet based on product/platform/locale and
|
||||
* SOURCE_DIR, which is set in config.
|
||||
*
|
||||
* @param string $product
|
||||
* @param string $platform
|
||||
* @param string $locale
|
||||
* @param string $version
|
||||
* @param string $build
|
||||
* @param string $buildSource
|
||||
* @param string $channel
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function setPath ($product,$platform,$locale,$version=null,$build,$buildSource,$channel) {
|
||||
switch($buildSource) {
|
||||
case 3:
|
||||
return $this->setVar('path',OVERRIDE_DIR.'/'.$product.'/'.$version.'/'.$platform.'/'.$build.'/'.$locale.'/'.$channel.'/'.$this->patchType.'.txt',true);
|
||||
break;
|
||||
case 2:
|
||||
return $this->setVar('path',SOURCE_DIR.'/'.$buildSource.'/'.$product.'/'.$version.'/'.$platform.'/'.$build.'/'.$locale.'/'.$this->patchType.'.txt',true);
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the given file and store its contents in our Patch object.
|
||||
*
|
||||
* @param string $path
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function setSnippet ($path) {
|
||||
if ($file = explode("\n",file_get_contents($path,true))) {
|
||||
$this->setVar('type',$file[0]);
|
||||
$this->setVar('url',$file[1]);
|
||||
$this->setVar('hashFunction',$file[2]);
|
||||
$this->setVar('hashValue',$file[3]);
|
||||
$this->setVar('size',$file[4]);
|
||||
$this->setVar('build',$file[5]);
|
||||
|
||||
// Attempt to read update information.
|
||||
// @TODO Add ability to set updateType, once it exists in the build snippet.
|
||||
if ($this->isComplete() && isset($file[6]) && isset($file[7])) {
|
||||
$this->setVar('updateVersion',$file[6],true);
|
||||
$this->setVar('updateExtensionVersion',$file[7],true);
|
||||
$this->setVar('hasUpdateInfo',true,true);
|
||||
}
|
||||
|
||||
if ($this->isComplete() && isset($file[8])) {
|
||||
$this->setVar('detailsUrl',$file[8],true);
|
||||
$this->setVar('hasDetailsUrl',true,true);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to read and parse the designated source file.
|
||||
* How and where the file is read depends on the client version.
|
||||
*
|
||||
* For more information on why this is a little complicated, see:
|
||||
* https://intranet.mozilla.org/AUS:Version2:Roadmap:Multibranch
|
||||
*
|
||||
* @param string $product
|
||||
* @param string $platform
|
||||
* @param string $locale
|
||||
* @param string $version
|
||||
* @param string $build
|
||||
* @param string $channel
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
function findPatch($product,$platform,$locale,$version,$build,$channel=null) {
|
||||
|
||||
// Determine the branch of the client's version.
|
||||
$branchVersion = $this->getBranch($version);
|
||||
|
||||
// If a specific update exists for the specified channel, it takes priority over the branch update.
|
||||
if (!empty($channel) && $this->setPath($product,$platform,$locale,$branchVersion,$build,3,$channel) && file_exists($this->path) && filesize($this->path) > 0) {
|
||||
$this->setSnippet($this->path);
|
||||
$this->setVar('isPatch',true,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Otherwise, if it is a complete patch and a nightly channel, force the complete update to take the user to the latest build.
|
||||
elseif ($this->isComplete() && $this->isNightlyChannel($channel)) {
|
||||
|
||||
// Get the latest build for this branch.
|
||||
$latestbuild = $this->getLatestBuild($product,$branchVersion,$platform);
|
||||
|
||||
if ($this->setPath($product,$platform,$locale,$branchVersion,$latestbuild,2,$channel) && file_exists($this->path) && filesize($this->path) > 0) {
|
||||
$this->setSnippet($this->path);
|
||||
$this->setVar('isPatch',true,true);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Otherwise, check for the partial snippet info. If an update exists, pass it along.
|
||||
elseif ($this->isNightlyChannel($channel) && $this->setPath($product,$platform,$locale,$branchVersion,$build,2,$channel) && file_exists($this->path) && filesize($this->path) > 0) {
|
||||
$this->setSnippet($this->path);
|
||||
$this->setVar('isPatch',true,true);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Note: Other data sets were made obsolete in 0.6. May incoming/0,1 rest in peace.
|
||||
|
||||
// If we get here, we know for sure that no updates exist for the current request..
|
||||
// Return false by default, which prompts the "no updates" XML output.
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare passed build to build in snippet.
|
||||
* Returns true if the snippet build is newer than the client build.
|
||||
*
|
||||
* @param string $build
|
||||
* @return boolean
|
||||
*/
|
||||
function isNewBuild($build) {
|
||||
return ($this->build>$build) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the branch versions array.
|
||||
*
|
||||
* @param array $branchVersions
|
||||
* @return boolean
|
||||
*/
|
||||
function setBranchVersions($branchVersions) {
|
||||
return $this->setVar('branchVersions',$branchVersions);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the nightly channels array.
|
||||
*
|
||||
* @param array $branchVersions
|
||||
* @return boolean
|
||||
*/
|
||||
function setNightlyChannels($nightlyChannels) {
|
||||
return $this->setVar('nightlyChannels',$nightlyChannels);
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not the given channel is flagged as nightly.
|
||||
*
|
||||
* @param string $channel
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isNightlyChannel($channel) {
|
||||
return in_array($channel,$this->nightlyChannels);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Determine whether or not the incoming version is a product BRANCH.
|
||||
*
|
||||
* @param string $version
|
||||
* @return string|false
|
||||
*/
|
||||
function getBranch($version) {
|
||||
return (isset($this->branchVersions[$version])) ? $this->branchVersions[$version] : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not something is Trunk.
|
||||
*
|
||||
* @param string $version
|
||||
* @return boolean
|
||||
*/
|
||||
function isTrunk($version) {
|
||||
return ($version == 'trunk') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Does this object contain a valid patch file?
|
||||
*/
|
||||
function isPatch() {
|
||||
return $this->isPatch;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this patch is complete.
|
||||
*/
|
||||
function isComplete() {
|
||||
return ($this->patchType === 'complete') ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this patch has a details URL.
|
||||
*/
|
||||
function hasDetailsUrl() {
|
||||
return $this->hasDetailsUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not this patch has update information.
|
||||
*/
|
||||
function hasUpdateInfo() {
|
||||
return $this->hasUpdateInfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether or not the to_build matches the latest build for a partial patch.
|
||||
* @param string $build
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
function isOneStepFromLatest($build) {
|
||||
return ($this->build == $build) ? true : false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the latest build for this branch.
|
||||
* @param string $product
|
||||
* @param string $branchVersion
|
||||
* @param string $platform
|
||||
*/
|
||||
function getLatestBuild($product,$branchVersion,$platform) {
|
||||
$files = array();
|
||||
$fp = opendir(SOURCE_DIR.'/2/'.$product.'/'.$branchVersion.'/'.$platform);
|
||||
while (false !== ($filename = readdir($fp))) {
|
||||
if ($filename!='.' && $filename!='..') {
|
||||
$files[] = $filename;
|
||||
}
|
||||
}
|
||||
closedir($fp);
|
||||
|
||||
rsort($files,SORT_NUMERIC);
|
||||
|
||||
return $files[1];
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,124 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
class Update extends AUS_Object {
|
||||
var $type;
|
||||
var $version;
|
||||
var $extensionVersion;
|
||||
var $build;
|
||||
|
||||
/**
|
||||
* Default constructor.
|
||||
*/
|
||||
function Update($type=UPDATE_TYPE,$version=UPDATE_VERSION,$extensionVersion=UPDATE_EXTENSION_VERSION) {
|
||||
$this->setType($type);
|
||||
$this->setVersion($version);
|
||||
$this->setExtensionVersion($extensionVersion);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set type.
|
||||
* @param string $type
|
||||
*/
|
||||
function setType($type) {
|
||||
$this->type = $type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set verison.
|
||||
* @param string $type
|
||||
*/
|
||||
function setVersion($version) {
|
||||
$this->version = $version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set extensionVersion.
|
||||
* @param string $extensionVersion
|
||||
*/
|
||||
function setExtensionVersion($extensionVersion) {
|
||||
$this->extensionVersion = $extensionVersion;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the build.
|
||||
* @param string $build
|
||||
*/
|
||||
function setBuild($build) {
|
||||
return $this->setVar('build',$build);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the details URL.
|
||||
* @param string $details
|
||||
*/
|
||||
function setDetails($details) {
|
||||
return $this->setVar('details',$details);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get type.
|
||||
* @return string
|
||||
*/
|
||||
function getType() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get version.
|
||||
* @return string
|
||||
*/
|
||||
function getVersion() {
|
||||
return $this->version;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get extension version.
|
||||
* @return string
|
||||
*/
|
||||
function getExtensionVersion() {
|
||||
return $this->extensionVersion;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,143 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* @package aus
|
||||
* @subpackage inc
|
||||
* @author Mike Morgan
|
||||
*/
|
||||
class Xml extends AUS_Object {
|
||||
var $xmlOutput;
|
||||
var $xmlHeader;
|
||||
var $xmlFooter;
|
||||
var $xmlPatchLines;
|
||||
|
||||
/**
|
||||
* Constructor, sets overall header and footer.
|
||||
*/
|
||||
function Xml() {
|
||||
$this->xmlHeader = '<?xml version="1.0"?>'."\n".'<updates>';
|
||||
$this->xmlFooter = "\n".'</updates>';
|
||||
$this->xmlOutput = $this->xmlHeader;
|
||||
$this->xmlPatchLines = '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Start an update block.
|
||||
* @param object $update
|
||||
*/
|
||||
function startUpdate($update) {
|
||||
$type = htmlentities($update->type);
|
||||
$version = htmlentities($update->version);
|
||||
$extensionVersion = htmlentities($update->extensionVersion);
|
||||
$build = htmlentities($update->build);
|
||||
$details = htmlentities($update->details);
|
||||
|
||||
$details_xml = "";
|
||||
if (strlen($details) > 0) {
|
||||
$details_xml = " detailsURL=\"{$details}\"";
|
||||
}
|
||||
|
||||
$this->xmlOutput .= <<<startUpdate
|
||||
|
||||
<update type="{$type}" version="{$version}" extensionVersion="{$extensionVersion}" buildID="{$build}" {$details_xml}>
|
||||
startUpdate;
|
||||
|
||||
/**
|
||||
* @TODO Add buildID attribute to <update> element.
|
||||
*
|
||||
* Right now it is pending QA on the client side, so we will leave it
|
||||
* out for now.
|
||||
*
|
||||
* buildID="{$build}"
|
||||
*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a patch line. This pulls info from a patch object.
|
||||
* @param object $patch
|
||||
*/
|
||||
function setPatchLine($patch) {
|
||||
$type = htmlentities($patch->type);
|
||||
$url = htmlentities($patch->url);
|
||||
$hashFunction = htmlentities($patch->hashFunction);
|
||||
$hashValue = htmlentities($patch->hashValue);
|
||||
$size = htmlentities($patch->size);
|
||||
|
||||
$this->xmlPatchLines .= <<<patchLine
|
||||
|
||||
<patch type="{$type}" URL="{$url}" hashFunction="{$hashFunction}" hashValue="{$hashValue}" size="{$size}"/>
|
||||
patchLine;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether or not patchLines have been set.
|
||||
* @return bool
|
||||
*/
|
||||
function hasPatchLine() {
|
||||
return (empty($this->xmlPatchLines)) ? false : true;
|
||||
}
|
||||
|
||||
/**
|
||||
* End an update block.
|
||||
*/
|
||||
function endUpdate() {
|
||||
$this->xmlOutput .= <<<endUpdate
|
||||
|
||||
</update>
|
||||
endUpdate;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add patchLines to output.
|
||||
*/
|
||||
function drawPatchLines() {
|
||||
$this->xmlOutput .= $this->xmlPatchLines;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get XML output.
|
||||
* @return $string $this->xmlOutput
|
||||
*/
|
||||
function getOutput() {
|
||||
$this->xmlOutput .= $this->xmlFooter;
|
||||
return $this->xmlOutput;
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,217 +0,0 @@
|
||||
<?php
|
||||
// ***** BEGIN LICENSE BLOCK *****
|
||||
//
|
||||
// Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
//
|
||||
// The contents of this file are subject to the Mozilla Public License Version
|
||||
// 1.1 (the "License"); you may not use this file except in compliance with
|
||||
// the License. You may obtain a copy of the License at
|
||||
// http://www.mozilla.org/MPL/
|
||||
//
|
||||
// Software distributed under the License is distributed on an "AS IS" basis,
|
||||
// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
||||
// for the specific language governing rights and limitations under the
|
||||
// License.
|
||||
//
|
||||
// The Original Code is AUS.
|
||||
//
|
||||
// The Initial Developer of the Original Code is Mike Morgan.
|
||||
//
|
||||
// Portions created by the Initial Developer are Copyright (C) 2006
|
||||
// the Initial Developer. All Rights Reserved.
|
||||
//
|
||||
// Contributor(s):
|
||||
// Mike Morgan <morgamic@mozilla.com>
|
||||
//
|
||||
// Alternatively, the contents of this file may be used under the terms of
|
||||
// either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
// the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
// in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
// of those above. If you wish to allow use of your version of this file only
|
||||
// under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
// use your version of this file under the terms of the MPL, indicate your
|
||||
// decision by deleting the provisions above and replace them with the notice
|
||||
// and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
// the provisions above, a recipient may use your version of this file under
|
||||
// the terms of any one of the MPL, the GPL or the LGPL.
|
||||
//
|
||||
// ***** END LICENSE BLOCK *****
|
||||
|
||||
/**
|
||||
* AUS Lite main script.
|
||||
* @package auslite
|
||||
* @subpackage docs
|
||||
* @author Mike Morgan
|
||||
*
|
||||
* This script handles incoming requests, reads the related build
|
||||
* snippet and returns a properly formatted XML file for testing.
|
||||
*/
|
||||
|
||||
// Require config and supporting libraries.
|
||||
require_once('./inc/init.php');
|
||||
|
||||
// Instantiate XML object.
|
||||
$xml = new Xml();
|
||||
|
||||
// Find everything between our CWD and 255 in QUERY_STRING.
|
||||
$rawPath = substr(urldecode($_SERVER['QUERY_STRING']),5,255);
|
||||
|
||||
// Munge he resulting string and store it in $path.
|
||||
$path = explode('/',$rawPath);
|
||||
|
||||
// Determine incoming request and clean inputs.
|
||||
// These are common URL elements, agreed upon in revision 0.
|
||||
$clean = Array();
|
||||
$clean['updateVersion'] = isset($path[0]) ? intval($path[0]) : null;
|
||||
$clean['product'] = isset($path[1]) ? trim($path[1]) : null;
|
||||
$clean['version'] = isset($path[2]) ? urlencode($path[2]) : null;
|
||||
$clean['build'] = isset($path[3]) ? trim($path[3]) : null;
|
||||
$clean['platform'] = isset($path[4]) ? trim($path[4]) : null;
|
||||
$clean['locale'] = isset($path[5]) ? trim($path[5]) : null;
|
||||
|
||||
// For each updateVersion, we will run separate code.
|
||||
switch ($clean['updateVersion']) {
|
||||
|
||||
/*
|
||||
* This is for the second revision of the URL schema, with %CHANNEL% added.
|
||||
* /update2/1/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/%CHANNEL%/update.xml
|
||||
*/
|
||||
case 1:
|
||||
|
||||
// Check for a set channel.
|
||||
$clean['channel'] = isset($path[6]) ? trim($path[6]) : null;
|
||||
|
||||
// Instantiate Update object and set updateVersion.
|
||||
$update = new Update();
|
||||
|
||||
// Instantiate our complete patch.
|
||||
$completePatch = new Patch($branchVersions,$nightlyChannels,'complete');
|
||||
|
||||
// Find our complete patch.
|
||||
$completePatch->findPatch($clean['product'],$clean['platform'],$clean['locale'],$clean['version'],$clean['build'],$clean['channel']);
|
||||
|
||||
// If our complete patch is valid, set the patch line.
|
||||
if ($completePatch->isPatch() && $completePatch->isNewBuild($clean['build'])) {
|
||||
|
||||
// Set our patchLine.
|
||||
$xml->setPatchLine($completePatch);
|
||||
|
||||
// If available, pull update information from the build snippet.
|
||||
// @TODO Add ability to set updateType.
|
||||
if ($completePatch->hasUpdateInfo()) {
|
||||
$update->setVersion($completePatch->updateVersion);
|
||||
$update->setExtensionVersion($completePatch->updateExtensionVersion);
|
||||
$update->setBuild($completePatch->build);
|
||||
}
|
||||
|
||||
if ($completePatch->hasDetailsUrl()) {
|
||||
$update->setDetails($completePatch->detailsUrl);
|
||||
}
|
||||
}
|
||||
|
||||
// We only check for a partial patch if the complete patch was successfully retrieved.
|
||||
if ($completePatch->isPatch()) {
|
||||
|
||||
// Instantiate our partial patch.
|
||||
$partialPatch = new Patch($branchVersions,$nightlyChannels,'partial');
|
||||
$partialPatch->findPatch($clean['product'],$clean['platform'],$clean['locale'],$clean['version'],$clean['build'],$clean['channel']);
|
||||
|
||||
// If our partial patch is valid, set the patch line.
|
||||
// We only want to deliver the partial patch if the destination build for the partial patch is equal to the build in the complete patch (which will always point to the latest).
|
||||
if ($partialPatch->isPatch() && $partialPatch->isNewBuild($clean['build']) && $partialPatch->isOneStepFromLatest($completePatch->build)) {
|
||||
$xml->setPatchLine($partialPatch);
|
||||
}
|
||||
}
|
||||
|
||||
// If we have valid patchLine(s), set up our output.
|
||||
if ($xml->hasPatchLine()) {
|
||||
$xml->startUpdate($update);
|
||||
$xml->drawPatchLines();
|
||||
$xml->endUpdate();
|
||||
}
|
||||
break;
|
||||
|
||||
/*
|
||||
* This is for the first revision of the URL schema.
|
||||
* /update2/0/%PRODUCT%/%VERSION%/%BUILD_ID%/%BUILD_TARGET%/%LOCALE%/update.xml
|
||||
*/
|
||||
case 0:
|
||||
default:
|
||||
|
||||
// Instantiate Update object and set updateVersion.
|
||||
$update = new Update();
|
||||
|
||||
// Instantiate Patch object and set Path based on passed args.
|
||||
$patch = new Patch($branchVersions,$nightlyChannels,'complete');
|
||||
|
||||
$patch->findPatch($clean['product'],$clean['platform'],$clean['locale'],$clean['version'],$clean['build'],null);
|
||||
|
||||
if ($patch->isPatch()) {
|
||||
$xml->setPatchLine($patch);
|
||||
}
|
||||
|
||||
// If we have a new build, draw the update block and patch line.
|
||||
// If there is no valid patch file, client will receive no updates by default.
|
||||
if ($xml->hasPatchLine() && $patch->isNewBuild($clean['build'])) {
|
||||
$xml->startUpdate($update);
|
||||
$xml->drawPatchLines();
|
||||
$xml->endUpdate();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// If we are debugging output plaintext and exit.
|
||||
if ( defined('DEBUG') && DEBUG == true ) {
|
||||
|
||||
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n";
|
||||
echo '<html xmlns="http://www.w3.org/1999/xhtml">'."\n";
|
||||
echo '<head>'."\n";
|
||||
echo '<title>AUS Debug Information</title>'."\n";
|
||||
echo '</head>'."\n";
|
||||
echo '<body>'."\n";
|
||||
echo '<h1>AUS Debug Information</h1>'."\n";
|
||||
|
||||
echo '<h2>XML Output</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
echo htmlentities($xml->getOutput());
|
||||
echo '</pre>'."\n";
|
||||
|
||||
if (!empty($clean)) {
|
||||
echo '<h2>Inputs</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
print_r($clean);
|
||||
echo '</pre>'."\n";
|
||||
}
|
||||
|
||||
echo '<h2>Patch Objects</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
if (!empty($patch)) {
|
||||
print_r($patch);
|
||||
}
|
||||
if (!empty($completePatch)) {
|
||||
print_r($completePatch);
|
||||
}
|
||||
if (!empty($partialPatch)) {
|
||||
print_r($partialPatch);
|
||||
}
|
||||
echo '</pre>'."\n";
|
||||
|
||||
if (!empty($update)) {
|
||||
echo '<h2>Update Object</h2>'."\n";
|
||||
echo '<pre>'."\n";
|
||||
print_r($update);
|
||||
echo '</pre>'."\n";
|
||||
}
|
||||
|
||||
echo '</body>'."\n";
|
||||
echo '</html>';
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
// Set header and send info.
|
||||
// Default output will be a blank document (no updates available).
|
||||
header('Content-type: text/xml;');
|
||||
echo $xml->getOutput();
|
||||
exit;
|
||||
?>
|
||||
@@ -1,5 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine on
|
||||
RewriteRule ^$ webroot/ [L]
|
||||
RewriteRule (.*) webroot/$1 [L]
|
||||
</IfModule>
|
||||
@@ -1,48 +0,0 @@
|
||||
Mozilla Firefox Uninstall Survey
|
||||
================================
|
||||
|
||||
|
||||
How To Install
|
||||
--------------
|
||||
|
||||
Assumptions:
|
||||
1) You've got a working database with the appropriate schema
|
||||
2) You've got cake setup on your server already. The code you're looking at now
|
||||
is just what is in the /app/ directory - everything else will have to be on your
|
||||
server already.
|
||||
|
||||
Steps:
|
||||
|
||||
1) Copy config/database.php.default to config/database.php and fill in your database
|
||||
values (if you're only doing production, just fill in the production area).
|
||||
|
||||
2) Edit /webroot/index.php.
|
||||
Define ROOT:
|
||||
If you're installing this in your home directory, ROOT should be:
|
||||
|
||||
DS.'home'.DS.'username'.DS.'public_html'
|
||||
|
||||
Define APP_DIR:
|
||||
ROOT is the parent directory of the app, this is the actual app.
|
||||
Continuing the example above, if people are going to go to:
|
||||
http://server.com/~username/bouncer/ to get to the app, APP_DIR should be:
|
||||
|
||||
bouncer
|
||||
|
||||
Define CAKE_CORE_INCLUDE_PATH:
|
||||
This is the path to the actual cake install on your server. For example:
|
||||
|
||||
DS.'usr'.DS.'local'.DS.'lib'.DS.'php'.DS.'cake'
|
||||
|
||||
3) Edit /webroot/.htaccess. Add a RewriteBase line below the line that says 'RewriteEngine On'.
|
||||
For our example, we would add the line:
|
||||
|
||||
RewriteBase /~username/bouncer
|
||||
|
||||
4) Edit /.htaccess. Add the same RewriteBase line from step 3 directly below the
|
||||
'RewriteEngine On' line.
|
||||
|
||||
|
||||
|
||||
|
||||
Questions? Email clouserw@mozilla.com
|
||||
@@ -1,76 +0,0 @@
|
||||
;<?php die() ?>
|
||||
; SVN FILE: $Id: acl.ini.php,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $
|
||||
;/**
|
||||
; * Short description for file.
|
||||
; *
|
||||
; *
|
||||
; * PHP versions 4 and 5
|
||||
; *
|
||||
; * CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
; * Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
; * 1785 E. Sahara Avenue, Suite 490-204
|
||||
; * Las Vegas, Nevada 89104
|
||||
; *
|
||||
; * Licensed under The MIT License
|
||||
; * Redistributions of files must retain the above copyright notice.
|
||||
; *
|
||||
; * @filesource
|
||||
; * @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
; * @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
; * @package cake
|
||||
; * @subpackage cake.app.config
|
||||
; * @since CakePHP v 0.10.0.1076
|
||||
; * @version $Revision: 1.1.1.1 $
|
||||
; * @modifiedby $LastChangedBy: phpnut $
|
||||
; * @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
; * @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
; */
|
||||
|
||||
; acl.ini.php - Cake ACL Configuration
|
||||
; ---------------------------------------------------------------------
|
||||
; Use this file to specify user permissions.
|
||||
; aco = access control object (something in your application)
|
||||
; aro = access request object (something requesting access)
|
||||
;
|
||||
; User records are added as follows:
|
||||
;
|
||||
; [uid]
|
||||
; groups = group1, group2, group3
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; Group records are added in a similar manner:
|
||||
;
|
||||
; [gid]
|
||||
; allow = aco1, aco2, aco3
|
||||
; deny = aco4, aco5, aco6
|
||||
;
|
||||
; The allow, deny, and groups sections are all optional.
|
||||
; NOTE: groups names *cannot* ever be the same as usernames!
|
||||
;
|
||||
; ACL permissions are checked in the following order:
|
||||
; 1. Check for user denies (and DENY if specified)
|
||||
; 2. Check for user allows (and ALLOW if specified)
|
||||
; 3. Gather user's groups
|
||||
; 4. Check group denies (and DENY if specified)
|
||||
; 5. Check group allows (and ALLOW if specified)
|
||||
; 6. If no aro, aco, or group information is found, DENY
|
||||
;
|
||||
; ---------------------------------------------------------------------
|
||||
|
||||
;-------------------------------------
|
||||
;Users
|
||||
;-------------------------------------
|
||||
|
||||
[username-goes-here]
|
||||
groups = group1, group2
|
||||
deny = aco1, aco2
|
||||
allow = aco3, aco4
|
||||
|
||||
;-------------------------------------
|
||||
;Groups
|
||||
;-------------------------------------
|
||||
|
||||
[groupname-goes-here]
|
||||
deny = aco5, aco6
|
||||
allow = aco7, aco8
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: bootstrap.php,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.10.8.2117
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
*
|
||||
* This file is loaded automatically by the app/webroot/index.php file after the core bootstrap.php is loaded
|
||||
* This is an application wide file to load any function that is not used within a class define.
|
||||
* You can also use this to include or require any files in your application.
|
||||
*
|
||||
*/
|
||||
/**
|
||||
* The settings below can be used to set additional paths to models, views and controllers.
|
||||
* This is related to Ticket #470 (https://trac.cakephp.org/ticket/470)
|
||||
*
|
||||
* $modelPaths = array('full path to models', 'second full path to models', 'etc...');
|
||||
* $viewPaths = array('this path to views', 'second full path to views', 'etc...');
|
||||
* $controllerPaths = array('this path to controllers', 'second full path to controllers', 'etc...');
|
||||
*
|
||||
*/
|
||||
//EOF
|
||||
?>
|
||||
@@ -1,147 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: core.php,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
/**
|
||||
* This is core configuration file.
|
||||
*
|
||||
* Use it to configure core behaviour ofCake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* If you do not have mod rewrite on your system
|
||||
* or if you prefer to use CakePHP pretty urls.
|
||||
* uncomment the line below.
|
||||
* Note: If you do have mod rewrite but prefer the
|
||||
* CakePHP pretty urls, you also have to remove the
|
||||
* .htaccess files
|
||||
* release/.htaccess
|
||||
* release/app/.htaccess
|
||||
* release/app/webroot/.htaccess
|
||||
*/
|
||||
// define ('BASE_URL', env('SCRIPT_NAME'));
|
||||
/**
|
||||
* Set debug level here:
|
||||
* - 0: production
|
||||
* - 1: development
|
||||
* - 2: full debug with sql
|
||||
* - 3: full debug with sql and dump of the current object
|
||||
*
|
||||
* In production, the "flash messages" redirect after a time interval.
|
||||
* With the other debug levels you get to click the "flash message" to continue.
|
||||
*
|
||||
*/
|
||||
define('DEBUG', 2);
|
||||
/**
|
||||
* Turn of caching checking wide.
|
||||
* You must still use the controller var cacheAction inside you controller class.
|
||||
* You can either set it controller wide, or in each controller method.
|
||||
* use var $cacheAction = true; or in the controller method $this->cacheAction = true;
|
||||
*/
|
||||
define('CACHE_CHECK', false);
|
||||
/**
|
||||
* Error constant. Used for differentiating error logging and debugging.
|
||||
* Currently PHP supports LOG_DEBUG
|
||||
*/
|
||||
define('LOG_ERROR', 2);
|
||||
/**
|
||||
* CakePHP includes 3 types of session saves
|
||||
* database or file. Set this to your preferred method.
|
||||
* If you want to use your own save handler place it in
|
||||
* app/config/name.php DO NOT USE file or database as the name.
|
||||
* and use just the name portion below.
|
||||
*
|
||||
* Setting this to cake will save files to /cakedistro/tmp directory
|
||||
* Setting it to php will use the php default save path
|
||||
* Setting it to database will use the database
|
||||
*
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_SAVE', 'php');
|
||||
/**
|
||||
* If using you own table name for storing sessions
|
||||
* set the table name here.
|
||||
* DO NOT INCLUDE PREFIX IF YOU HAVE SET ONE IN database.php
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_TABLE', 'cake_sessions');
|
||||
/**
|
||||
* Set a random string of used in session.
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_STRING', 'DYhG93b0qyJfIxfs2guVoUubWwvniR2G0FgaC9mi');
|
||||
/**
|
||||
* Set the name of session cookie
|
||||
*
|
||||
*/
|
||||
define('CAKE_SESSION_COOKIE', 'CAKEPHP');
|
||||
/**
|
||||
* Set level of Cake security.
|
||||
*
|
||||
*/
|
||||
define('CAKE_SECURITY', 'high');
|
||||
/**
|
||||
* Set Cake Session time out.
|
||||
* If CAKE_SECURITY define is set
|
||||
* high: multiplied by 10
|
||||
* medium: is multiplied by 100
|
||||
* low is: multiplied by 300
|
||||
*
|
||||
* Number below is seconds.
|
||||
*/
|
||||
define('CAKE_SESSION_TIMEOUT', '120');
|
||||
/**
|
||||
* Uncomment the define below to use cake built in admin routes.
|
||||
* You can set this value to anything you want.
|
||||
* All methods related to the admin route should be prefixed with the
|
||||
* name you set CAKE_ADMIN to.
|
||||
* For example: admin_index, admin_edit
|
||||
*/
|
||||
// define('CAKE_ADMIN', 'admin');
|
||||
/**
|
||||
* The define below is used to turn cake built webservices
|
||||
* on or off. Default setting is off.
|
||||
*/
|
||||
define('WEBSERVICES', 'off');
|
||||
/**
|
||||
* Compress output CSS (removing comments, whitespace, repeating tags etc.)
|
||||
* This requires a/var/cache directory to be writable by the web server (caching).
|
||||
* To use, prefix the CSS link URL with '/ccss/' instead of '/css/' or use Controller::cssTag().
|
||||
*/
|
||||
define('COMPRESS_CSS', false);
|
||||
/**
|
||||
* If set to true, helpers would output data instead of returning it.
|
||||
*/
|
||||
define('AUTO_OUTPUT', false);
|
||||
/**
|
||||
* If set to false, session would not automatically be started.
|
||||
*/
|
||||
define('AUTO_SESSION', true);
|
||||
/**
|
||||
* Set the max size of file to use md5() .
|
||||
*/
|
||||
define('MAX_MD5SIZE', (5 * 1024) * 1024);
|
||||
/**
|
||||
* To use Access Control Lists with Cake...
|
||||
*/
|
||||
define('ACL_CLASSNAME', 'DB_ACL');
|
||||
define('ACL_FILENAME', 'dbacl' . DS . 'db_acl');
|
||||
?>
|
||||
@@ -1,74 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: database.php.default,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
/**
|
||||
* This is core configuration file.
|
||||
*
|
||||
* Use it to configure core behaviour ofCake.
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* In this file you set up your database connection details.
|
||||
*
|
||||
* @package cake
|
||||
* @subpackage cake.config
|
||||
*/
|
||||
/**
|
||||
* Database configuration class.
|
||||
* You can specify multiple configurations for production, development and testing.
|
||||
*
|
||||
* driver =>
|
||||
* mysql, postgres, sqlite, adodb-drivername, pear-drivername
|
||||
*
|
||||
* connect =>
|
||||
* MySQL set the connect to either mysql_pconnect of mysql_connect
|
||||
* PostgreSQL set the connect to either pg_pconnect of pg_connect
|
||||
* SQLite set the connect to sqlite_popen sqlite_open
|
||||
* ADOdb set the connect to one of these
|
||||
* (http://phplens.com/adodb/supported.databases.html) and
|
||||
* append it '|p' for persistent connection. (mssql|p for example, or just mssql for not persistent)
|
||||
*
|
||||
* host =>
|
||||
* the host you connect to the database
|
||||
* MySQL 'localhost' to add a port number use 'localhost:port#'
|
||||
* PostgreSQL 'localhost' to add a port number use 'localhost port=5432'
|
||||
*
|
||||
*/
|
||||
class DATABASE_CONFIG
|
||||
{
|
||||
var $default = array('driver' => 'mysql',
|
||||
'connect' => 'mysql_connect',
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'project_name',
|
||||
'prefix' => '');
|
||||
|
||||
var $test = array('driver' => 'mysql',
|
||||
'connect' => 'mysql_connect',
|
||||
'host' => 'localhost',
|
||||
'login' => 'user',
|
||||
'password' => 'password',
|
||||
'database' => 'project_name-test',
|
||||
'prefix' => '');
|
||||
}
|
||||
?>
|
||||
@@ -1,72 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: inflections.php,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
/**
|
||||
* Custom Inflected Words.
|
||||
*
|
||||
* This file is used to hold words that are not matched in the normail Inflector::pluralize() and
|
||||
* Inflector::singularize()
|
||||
*
|
||||
* PHP versions 4 and %
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 1.0.0.2312
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* This is a key => value array of regex used to match words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $pluralRules = array('/(s)tatus$/i' => '\1\2tatuses', '/^(ox)$/i' => '\1\2en', '/([m|l])ouse$/i' => '\1ice');
|
||||
*/
|
||||
$pluralRules = array();
|
||||
/**
|
||||
* This is a key only array of plural words that should not be inflected.
|
||||
* Notice the last comma
|
||||
*
|
||||
* $uninflectedPlural = array('.*[nrlm]ese', '.*deer', '.*fish', '.*measles', '.*ois', '.*pox');
|
||||
*/
|
||||
$uninflectedPlural = array();
|
||||
/**
|
||||
* This is a key => value array of plural irregular words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $irregularPlural = array('atlas' => 'atlases', 'beef' => 'beefs', 'brother' => 'brothers')
|
||||
*/
|
||||
$irregularPlural = array();
|
||||
/**
|
||||
* This is a key => value array of regex used to match words.
|
||||
* If key matches then the value is returned.
|
||||
*
|
||||
* $singularRules = array('/(s)tatuses$/i' => '\1\2tatus', '/(matr)ices$/i' =>'\1ix','/(vert|ind)ices$/i')
|
||||
*/
|
||||
$singularRules = array();
|
||||
/**
|
||||
* This is a key only array of singular words that should not be inflected.
|
||||
* You should not have to change this value below if you do change it use same format
|
||||
* as the $uninflectedPlural above.
|
||||
*/
|
||||
$uninflectedSingular = $uninflectedPlural;
|
||||
/**
|
||||
* This is a key => value array of singular irregular words.
|
||||
* Most of the time this will be a reverse of the above $irregularPlural array
|
||||
* You should not have to change this value below if you do change it use same format
|
||||
*
|
||||
* $irregularSingular = array('atlases' => 'atlas', 'beefs' => 'beef', 'brothers' => 'brother')
|
||||
*/
|
||||
$irregularSingular = array_flip($irregularPlural);
|
||||
?>
|
||||
@@ -1,46 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: routes.php,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* In this file, you set up routes to your controllers and their actions.
|
||||
* Routes are very important mechanism that allows you to freely connect
|
||||
* different urls to chosen controllers and their actions (functions).
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.config
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* Here, we are connecting '/' (base path) to controller called 'Pages',
|
||||
* its action called 'display', and we pass a param to select the view file
|
||||
* to use (in this case, /app/views/pages/home.thtml)...
|
||||
*/
|
||||
$Route->connect('/', array('controller' => 'pages', 'action' => 'display', 'dashboard'));
|
||||
/**
|
||||
* ...and connect the rest of 'Pages' controller's urls.
|
||||
*/
|
||||
$Route->connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));
|
||||
/**
|
||||
* Then we connect url '/test' to our test controller. This is helpfull in
|
||||
* developement.
|
||||
*/
|
||||
$Route->connect('/tests', array('controller' => 'tests', 'action' => 'index'));
|
||||
?>
|
||||
@@ -1,30 +0,0 @@
|
||||
CREATE TABLE `acos` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`model` varchar(255) NOT NULL default '',
|
||||
`object_id` int(11) default NULL,
|
||||
`alias` varchar(255) NOT NULL default '',
|
||||
`lft` int(11) default NULL,
|
||||
`rght` int(11) default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE `aros` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`model` varchar(255) NOT NULL default '',
|
||||
`user_id` int(11) default NULL,
|
||||
`alias` varchar(255) NOT NULL default '',
|
||||
`lft` int(11) default NULL,
|
||||
`rght` int(11) default NULL,
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
|
||||
CREATE TABLE `aros_acos` (
|
||||
`id` int(11) NOT NULL auto_increment,
|
||||
`aro_id` int(11) default NULL,
|
||||
`aco_id` int(11) default NULL,
|
||||
`_create` int(1) NOT NULL default '0',
|
||||
`_read` int(1) NOT NULL default '0',
|
||||
`_update` int(1) NOT NULL default '0',
|
||||
`_delete` int(11) NOT NULL default '0',
|
||||
PRIMARY KEY (`id`)
|
||||
);
|
||||
@@ -1,11 +0,0 @@
|
||||
-- @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
-- @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
-- @since CakePHP v 0.10.8.1997
|
||||
-- @version $Revision: 1.1.1.1 $
|
||||
|
||||
CREATE TABLE cake_sessions (
|
||||
id varchar(255) NOT NULL default '',
|
||||
data text,
|
||||
expires int(11) default NULL,
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
class FilesController extends AppController {
|
||||
var $name = 'Files';
|
||||
var $scaffold;
|
||||
}
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
class LocalesController extends AppController {
|
||||
var $name = 'Locales';
|
||||
var $scaffold;
|
||||
}
|
||||
?>
|
||||
@@ -1,77 +0,0 @@
|
||||
<?php
|
||||
uses('sanitize');
|
||||
|
||||
class MirrorsController extends AppController
|
||||
{
|
||||
var $name = 'Mirrors';
|
||||
var $helpers = array('Html', 'Pagination');
|
||||
var $show;
|
||||
var $sortBy;
|
||||
var $direction;
|
||||
var $page;
|
||||
var $order;
|
||||
var $sanitize;
|
||||
var $scaffold;
|
||||
|
||||
function __construct()
|
||||
{
|
||||
$this->sanitize = &new Sanitize;
|
||||
$this->show = empty($_GET['show'])? '10': $this->sanitize->sql($_GET['show']);
|
||||
$this->sortBy = empty($_GET['sort'])? 'Mirror.mirror_id': $this->sanitize->sql($_GET['sort']);
|
||||
$this->direction = empty($_GET['direction'])? 'desc': $this->sanitize->sql($_GET['direction']);
|
||||
$this->page = empty($_GET['page'])? '1': $this->sanitize->sql($_GET['page']);
|
||||
$this->order = $this->sortBy.' '.strtoupper($this->direction);
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
function index()
|
||||
{
|
||||
$data = $this->Mirror->findAll($criteria=null, $fields=null, $this->order, $this->show, $this->page);
|
||||
|
||||
$paging['style'] = 'html'; //set the style of the links: html or ajax
|
||||
|
||||
foreach ($this->Mirror->_tableInfo->value as $column) {
|
||||
|
||||
// If the sortBy is the same as the current link, we want to switch it.
|
||||
// By default, we don't -- so that when a user changes columns, the order doesn't also reverse.
|
||||
if ($this->sortBy == $column['name']) {
|
||||
switch ($this->direction) {
|
||||
case 'desc':
|
||||
$link_direction = 'asc';
|
||||
break;
|
||||
case 'asc':
|
||||
default:
|
||||
$link_direction = 'desc';
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
$link_direction =& $this->direction;
|
||||
}
|
||||
$paging['headers'][$column['name']] = $this->sanitize->html('/mirrors/?show='.$this->show.'&sort='.$column['name'].'&direction='.$link_direction.'&page='.$this->page);
|
||||
}
|
||||
|
||||
$paging['link'] = $this->sanitize->html('./?show='.$this->show.'&sort='.$this->sortBy.'&direction='.$this->direction.'&page=');
|
||||
$paging['count'] = $this->Mirror->findCount($criteria=null,'1000');
|
||||
$paging['page'] = $this->page;
|
||||
$paging['limit'] = $this->show;
|
||||
$paging['show'] = array('10','25','50','100');
|
||||
|
||||
$this->set('paging',$paging);
|
||||
$this->set('data',$data);
|
||||
}
|
||||
|
||||
function view($id) {
|
||||
$this->Mirror->setId($id);
|
||||
$this->set('data', $this->Mirror->read());
|
||||
}
|
||||
|
||||
function destroy($id) {
|
||||
if (empty($this->params['data'])) {
|
||||
$this->set('data', $this->Mirror->read());
|
||||
$this->render();
|
||||
} elseif ($this->Mirror->del($id)) {
|
||||
$this->flash('Mirror '.$id.' has been deleted.', '/mirrors');
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
class PlatformsController extends AppController {
|
||||
var $name = 'Platforms';
|
||||
var $scaffold;
|
||||
}
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
class RegionsController extends AppController {
|
||||
var $name = 'Regions';
|
||||
var $scaffold;
|
||||
}
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
class TemplatesController extends AppController {
|
||||
var $name = 'Templates';
|
||||
var $scaffold;
|
||||
}
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
class UsersController extends AppController {
|
||||
var $name = 'Users';
|
||||
var $scaffold;
|
||||
}
|
||||
?>
|
||||
@@ -1,26 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: index.php,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
/**
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app
|
||||
* @since CakePHP v 0.10.0.1076
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
require 'webroot' . DIRECTORY_SEPARATOR . 'index.php';
|
||||
?>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?php
|
||||
class File extends AppModel {
|
||||
var $name = 'File';
|
||||
var $primaryKey = 'file_id';
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class Locale extends AppModel {
|
||||
var $name = 'Locale';
|
||||
var $primaryKey = 'lang_id';
|
||||
var $useTable = 'langs';
|
||||
}
|
||||
?>
|
||||
@@ -1,15 +0,0 @@
|
||||
<?php
|
||||
class Mirror extends AppModel
|
||||
{
|
||||
var $name = 'Mirror';
|
||||
var $primaryKey = 'mirror_id';
|
||||
var $hasAndBelongsToMany = array('regions' =>
|
||||
array( 'className' => 'Region',
|
||||
'joinTable' => 'mirror_region_map',
|
||||
'foreignKey' => 'mirror_id',
|
||||
'associationForeignKey' => 'region_id',
|
||||
'order' => 'region_name desc',
|
||||
'uniq' => true )
|
||||
);
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class Platform extends AppModel {
|
||||
var $name = 'Platform';
|
||||
var $primaryKey = 'os_id';
|
||||
var $useTable = 'oss';
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class Region extends AppModel {
|
||||
var $name = 'Region';
|
||||
var $primaryKey = 'region_id';
|
||||
var $displayField = 'region_name';
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class Template extends AppModel {
|
||||
var $name = 'Template';
|
||||
var $primaryKey = 'template_id';
|
||||
var $useTable = 'templates';
|
||||
}
|
||||
?>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?php
|
||||
class User extends AppModel {
|
||||
var $name = 'User';
|
||||
var $primaryKey = 'user_id';
|
||||
var $useTable = 'users';
|
||||
}
|
||||
?>
|
||||
@@ -1,8 +0,0 @@
|
||||
<h1>Dashboard</h1>
|
||||
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Bar</p>
|
||||
@@ -1,211 +0,0 @@
|
||||
<?php
|
||||
class PaginationHelper {
|
||||
|
||||
var $helpers = array('Html','Ajax');
|
||||
var $_pageDetails = array();
|
||||
var $link = '';
|
||||
var $show = array();
|
||||
var $page;
|
||||
var $style;
|
||||
|
||||
/**
|
||||
* Sets the default pagination options.
|
||||
*
|
||||
* @param array $paging an array detailing the page options
|
||||
*/
|
||||
function setPaging($paging)
|
||||
{
|
||||
if(!empty($paging))
|
||||
{
|
||||
|
||||
$this->link = $paging['link'];
|
||||
$this->show = $paging['show'];
|
||||
$this->page = $paging['page'];
|
||||
$this->style = $paging['style'];
|
||||
|
||||
$pageCount = ceil($paging['count'] / $paging['limit'] );
|
||||
|
||||
$this->_pageDetails = array(
|
||||
'page'=>$paging['page'],
|
||||
'recordCount'=>$paging['count'],
|
||||
'pageCount' =>$pageCount,
|
||||
'nextPage'=> ($paging['page'] < $pageCount) ? $paging['page']+1 : '',
|
||||
'previousPage'=> ($paging['page']>1) ? $paging['page']-1 : '',
|
||||
'limit'=>$paging['limit']
|
||||
);
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Displays limits for the query
|
||||
*
|
||||
* @param string $text - text to display before limits
|
||||
* @param string $separator - display a separate between limits
|
||||
*
|
||||
**/
|
||||
function show($text=null, $separator=null)
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if ( !empty($this->_pageDetails['recordCount']) )
|
||||
{
|
||||
$t = '';
|
||||
if(is_array($this->show))
|
||||
{
|
||||
$t = $text.$separator;
|
||||
foreach($this->show as $value)
|
||||
{
|
||||
$link = preg_replace('/show=(.*?)&/','show='.$value.'&',$this->link);
|
||||
if($this->_pageDetails['limit'] == $value)
|
||||
{
|
||||
$t .= '<em>'.$value.'</em>'.$separator;
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$t .= $this->Ajax->linkToRemote($value, array("fallback"=>$this->action."#","url" => $link.$this->_pageDetails['page'],"update" => "ajax_update","method"=>"get")).$separator;
|
||||
}
|
||||
else
|
||||
{
|
||||
$t .= $this->Html->link($value,$link.$this->_pageDetails['page']).$separator;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
|
||||
}
|
||||
/**
|
||||
* Displays current result information
|
||||
*
|
||||
* @param string $text - text to preceeding the number of results
|
||||
*
|
||||
**/
|
||||
function result($text)
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if ( !empty($this->_pageDetails['recordCount']) )
|
||||
{
|
||||
if($this->_pageDetails['recordCount'] > $this->_pageDetails['limit'])
|
||||
{
|
||||
$start_row = $this->_pageDetails['page'] > 1 ? (($this->_pageDetails['page']-1)*$this->_pageDetails['limit'])+1:'1';
|
||||
$end_row = ($this->_pageDetails['recordCount'] < ($start_row + $this->_pageDetails['limit']-1)) ? $this->_pageDetails['recordCount'] : ($start_row + $this->_pageDetails['limit']-1);
|
||||
$t = $text.$start_row.'-'.$end_row.' of '.$this->_pageDetails['recordCount'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $text.$this->_pageDetails['recordCount'];
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Returns a "Google style" list of page numbers
|
||||
*
|
||||
* @param string $separator - defaults to null
|
||||
* @param string $prefix - defaults to null. If set, displays prefix before page links.
|
||||
* @param int $pageSetLength - defaults to 10. Maximum number of pages to show.
|
||||
* @param string $prevLabel - defaults to null. If set, displays previous link.
|
||||
* @param string $nextLabel - defaults to null. If set, displays next link.
|
||||
*
|
||||
**/
|
||||
function pageNumbers($separator=null, $prefix=null, $pageSetLength=10, $prevLabel=null, $nextLabel=null)
|
||||
{
|
||||
|
||||
if (empty($this->_pageDetails) || $this->_pageDetails['pageCount'] == 1) { return false; }
|
||||
|
||||
$t = array();
|
||||
|
||||
$modulo = $this->_pageDetails['page'] % $pageSetLength;
|
||||
if ($modulo)
|
||||
{ // any number > 0
|
||||
$prevSetLastPage = $this->_pageDetails['page'] - $modulo;
|
||||
} else { // 0, last page of set
|
||||
$prevSetLastPage = $this->_pageDetails['page'] - $pageSetLength;
|
||||
}
|
||||
//$nextSetFirstPage = $prevSetLastPage + $pageSetLength + 1;
|
||||
|
||||
if ($prevLabel) $t[] = $this->prevPage($prevLabel);
|
||||
|
||||
// loops through each page number
|
||||
$pageSet = $prevSetLastPage + $pageSetLength;
|
||||
if ($pageSet > $this->_pageDetails['pageCount']) $pageSet = $this->_pageDetails['pageCount'];
|
||||
for ($pageIndex = $prevSetLastPage+1; $pageIndex <= $pageSet; $pageIndex++)
|
||||
{
|
||||
if ($pageIndex == $this->_pageDetails['page'])
|
||||
{
|
||||
$t[] = '<em>'.$pageIndex.'</em>';
|
||||
}
|
||||
else
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$t[] = $this->Ajax->linkToRemote($pageIndex, array("fallback"=>$this->action."#","url" =>$this->link.$pageIndex,"update" => "ajax_update","method"=>"get"));
|
||||
} else {
|
||||
$t[] = $this->Html->link($pageIndex,$this->link.$pageIndex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($nextLabel) $t[] = $this->nextPage($nextLabel);
|
||||
|
||||
$t = implode($separator, $t);
|
||||
|
||||
return $prefix.$t;
|
||||
}
|
||||
/**
|
||||
* Displays a link to the previous page, where the page doesn't exist then
|
||||
* display the $text
|
||||
*
|
||||
* @param string $text - text display: defaults to next
|
||||
*
|
||||
**/
|
||||
function prevPage($text='prev')
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if ( !empty($this->_pageDetails['previousPage']) )
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$t = $this->Ajax->linkToRemote($text, array("fallback"=>$this->action."#","url" => $this->link.$this->_pageDetails['previousPage'],"update" => "ajax_update","method"=>"get"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $this->Html->link($text,$this->link.$this->_pageDetails['previousPage']);
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* Displays a link to the next page, where the page doesn't exist then
|
||||
* display the $text
|
||||
*
|
||||
* @param string $text - text to display: defaults to next
|
||||
*
|
||||
**/
|
||||
function nextPage($text='next')
|
||||
{
|
||||
if (empty($this->_pageDetails)) { return false; }
|
||||
if (!empty($this->_pageDetails['nextPage']))
|
||||
{
|
||||
if($this->style == 'ajax')
|
||||
{
|
||||
$t = $this->Ajax->linkToRemote($text, array("fallback"=>$this->action."#","url" => $this->link.$this->_pageDetails['nextPage'],"update" => "ajax_update","method"=>"get"));
|
||||
}
|
||||
else
|
||||
{
|
||||
$t = $this->Html->link($text,$this->link.$this->_pageDetails['nextPage']);
|
||||
}
|
||||
return $t;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
||||
@@ -1,92 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: default.thtml,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
|
||||
/**
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.cake.libs.view.templates.pages
|
||||
* @since CakePHP v 0.10.0.1076
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
?>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
||||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<title><?php echo $title_for_layout?> :: Bouncer v2.0</title>
|
||||
|
||||
<link rel="icon" href="<?=$this->webroot?>img/bouncer.icon.png" type="image/png" />
|
||||
<?php echo $html->charset('UTF-8')?>
|
||||
<?php echo $html->css('bouncer.screen')?>
|
||||
<?php echo $html->css('bouncer.print')?>
|
||||
</head>
|
||||
<body>
|
||||
<div id="skip-to-nav"><a href="#nav">Skip to Navigation</a></div>
|
||||
<div id="wrapper">
|
||||
<div id="header">
|
||||
<a href="<?=$this->webroot?>">
|
||||
<?php echo $html->image('bouncer.logo.png', array('alt'=>'Bouncer', 'border'=>"0"))?>
|
||||
</a>
|
||||
</div>
|
||||
<hr class="hidden"/>
|
||||
<div id="content">
|
||||
<?php if (isset($this->controller->Session)) $this->controller->Session->flash(); ?>
|
||||
<?php echo $content_for_layout?>
|
||||
</div>
|
||||
<?php echo $cakeDebug;?>
|
||||
<hr class="hidden"/>
|
||||
<div id="nav">
|
||||
<ul>
|
||||
<li><?=$html->link('Dashboard','/')?></li>
|
||||
<li><?=$html->link('Mirrors','/mirrors')?></li>
|
||||
<li><?=$html->link('Regions','/regions')?></li>
|
||||
<li><?=$html->link('Files','/files')?></li>
|
||||
<li><?=$html->link('Platforms','/platforms')?></li>
|
||||
<li><?=$html->link('Locales','/locales')?></li>
|
||||
<li><?=$html->link('Templates','/templates')?></li>
|
||||
<li><?=$html->link('Users','/users')?></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<hr class="hidden"/>
|
||||
<div id="footer">
|
||||
<p class="copyright">
|
||||
© 2006 <a href="http://osuosl.org/">OSU Open Source Lab</a>
|
||||
</p>
|
||||
<p class="buttons">
|
||||
<!--PLEASE USE ONE OF THE POWERED BY CAKEPHP LOGO-->
|
||||
<a href="http://www.cakephp.org/" target="_new">
|
||||
<?php echo $html->image('cake.power.png', array('alt'=>'CakePHP : Rapid Development Framework',
|
||||
'height' => "15",
|
||||
'width' => "80"))?>
|
||||
</a>
|
||||
<a href="http://validator.w3.org/check?uri=referer">
|
||||
<?php echo $html->image('w3c_xhtml10.png', array('alt' => 'Valid XHTML 1.0 Transitional',
|
||||
'height' => "15",
|
||||
'width' => "80"))?>
|
||||
</a>
|
||||
<a href="http://jigsaw.w3.org/css-validator/check/referer">
|
||||
<?php echo $html->image('w3c_css.png', array('alt' => 'Valid CSS!',
|
||||
'height' => "15",
|
||||
'width' => "80"))?>
|
||||
</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
@@ -1,8 +0,0 @@
|
||||
<h1><?php echo $data['Mirror']['mirror_name']; ?></h1>
|
||||
<p><?php echo $data['Mirror']['mirror_baseurl']; ?></p>
|
||||
<p><?php echo $data['Mirror']['mirror_rating']; ?></p>
|
||||
<form action="./mirrors/destroy/<?=$data['Mirror']['mirror_id']?>" method="post">
|
||||
<p>Are you sure you want to delete this mirror?</p>
|
||||
<div><a href="javascript:history.back();">Nevermind</a><input type="submit" value="Yea, I'm sure"/></div>
|
||||
<input type="hidden" name="mirror_id" value="<?=$data['Mirror']['mirror_id']?>"/>
|
||||
</form>
|
||||
@@ -1,46 +0,0 @@
|
||||
<h1>Mirrors</h1>
|
||||
|
||||
<?php if($pagination->setPaging($paging)):?>
|
||||
<div class="pagination">
|
||||
<?php echo $pagination->result('Results: '); ?>
|
||||
<?php echo $pagination->prevPage('Prev'); ?>
|
||||
<?php echo $pagination->pageNumbers(); ?>
|
||||
<?php echo $pagination->nextPage('Next'); ?>
|
||||
</div>
|
||||
<?php endif;?>
|
||||
|
||||
<table class="inav">
|
||||
<tr>
|
||||
<th><?php echo $html->link('ID',$paging['headers']['mirror_id']); ?></th>
|
||||
<th><?php echo $html->link('Name',$paging['headers']['mirror_name']); ?></th>
|
||||
<th><?php echo $html->link('URL',$paging['headers']['mirror_baseurl']); ?></th>
|
||||
<th><?php echo $html->link('Rating',$paging['headers']['mirror_rating']); ?></th>
|
||||
<th><?php echo $html->link('Active',$paging['headers']['mirror_active']); ?></th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
<?php foreach ($data as $mirror): ?>
|
||||
<tr>
|
||||
<td><?php echo $mirror['Mirror']['mirror_id']; ?></td>
|
||||
<td><?php echo $mirror['Mirror']['mirror_name']; ?></td>
|
||||
<td>
|
||||
<?php echo $html->link( $mirror['Mirror']['mirror_baseurl'], "/mirrors/view/{$mirror['Mirror']['mirror_id']}" ); ?>
|
||||
</td>
|
||||
<td><?php echo $mirror['Mirror']['mirror_rating']; ?></td>
|
||||
<td><?php echo ($mirror['Mirror']['mirror_active'])?'On':'Off'; ?></td>
|
||||
<td>
|
||||
<?=$html->link('Edit',"/mirrors/edit/{$mirror['Mirror']['mirror_id']}",'class="action"')?>
|
||||
<?=$html->link('Delete',"/mirrors/destroy/{$mirror['Mirror']['mirror_id']}",'class="action"','Are you sure you want to delete?')?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
|
||||
<?php if($pagination->setPaging($paging)):?>
|
||||
<ul id="page-numbers">
|
||||
<li><?php echo $pagination->show('Show '); ?></li>
|
||||
<li><?php echo $pagination->result('Results: '); ?></li>
|
||||
<li><?php echo $pagination->prevPage('Prev'); ?></li>
|
||||
<li><?php echo $pagination->pageNumbers(); ?></li>
|
||||
<li><?php echo $pagination->nextPage('Next'); ?></li>
|
||||
</ul>
|
||||
<?php endif;?>
|
||||
@@ -1,3 +0,0 @@
|
||||
<h1><?php echo $data['Mirror']['mirror_name']; ?></h1>
|
||||
<p><?php echo $data['Mirror']['mirror_baseurl']; ?></p>
|
||||
<p><?php echo $data['Mirror']['mirror_rating']; ?></p>
|
||||
@@ -1,8 +0,0 @@
|
||||
<h1>Dashboard</h1>
|
||||
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Foo</p>
|
||||
<p>Bar</p>
|
||||
@@ -1,6 +0,0 @@
|
||||
<IfModule mod_rewrite.c>
|
||||
RewriteEngine On
|
||||
RewriteCond %{REQUEST_FILENAME} !-d
|
||||
RewriteCond %{REQUEST_FILENAME} !-f
|
||||
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
|
||||
</IfModule>
|
||||
@@ -1,101 +0,0 @@
|
||||
<?php
|
||||
/* SVN FILE: $Id: css.php,v 1.1.1.1 2006-06-09 18:14:09 mike.morgan%oregonstate.edu Exp $ */
|
||||
/**
|
||||
* Short description for file.
|
||||
*
|
||||
* Long description for file
|
||||
*
|
||||
* PHP versions 4 and 5
|
||||
*
|
||||
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
||||
* Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* 1785 E. Sahara Avenue, Suite 490-204
|
||||
* Las Vegas, Nevada 89104
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistributions of files must retain the above copyright notice.
|
||||
*
|
||||
* @filesource
|
||||
* @copyright Copyright (c) 2006, Cake Software Foundation, Inc.
|
||||
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
||||
* @package cake
|
||||
* @subpackage cake.app.webroot
|
||||
* @since CakePHP v 0.2.9
|
||||
* @version $Revision: 1.1.1.1 $
|
||||
* @modifiedby $LastChangedBy: phpnut $
|
||||
* @lastmodified $Date: 2006-06-09 18:14:09 $
|
||||
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
||||
*/
|
||||
/**
|
||||
* Enter description here...
|
||||
*/
|
||||
require(CONFIGS . 'paths.php');
|
||||
require(CAKE . 'basics.php');
|
||||
require(LIBS . 'folder.php');
|
||||
require(LIBS . 'file.php');
|
||||
require(LIBS . 'legacy.php');
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $name
|
||||
* @return unknown
|
||||
*/
|
||||
function make_clean_css($path, $name) {
|
||||
require(VENDORS . 'csspp' . DS . 'csspp.php');
|
||||
$data =file_get_contents($path);
|
||||
$csspp =new csspp();
|
||||
$output=$csspp->compress($data);
|
||||
$ratio =100 - (round(strlen($output) / strlen($data), 3) * 100);
|
||||
$output=" /* file: $name, ratio: $ratio% */ " . $output;
|
||||
return $output;
|
||||
}
|
||||
/**
|
||||
* Enter description here...
|
||||
*
|
||||
* @param unknown_type $path
|
||||
* @param unknown_type $content
|
||||
* @return unknown
|
||||
*/
|
||||
function write_css_cache($path, $content) {
|
||||
if (!is_dir(dirname($path))) {
|
||||
mkdir(dirname($path));
|
||||
}
|
||||
$cache=new File($path);
|
||||
return $cache->write($content);
|
||||
}
|
||||
|
||||
if (preg_match('|\.\.|', $url) || !preg_match('|^ccss/(.+)$|i', $url, $regs)) {
|
||||
die('Wrong file name.');
|
||||
}
|
||||
|
||||
$filename = 'css/' . $regs[1];
|
||||
$filepath = CSS . $regs[1];
|
||||
$cachepath = CACHE . 'css' . DS . str_replace(array('/','\\'), '-', $regs[1]);
|
||||
|
||||
if (!file_exists($filepath)) {
|
||||
die('Wrong file name.');
|
||||
}
|
||||
|
||||
if (file_exists($cachepath)) {
|
||||
$templateModified=filemtime($filepath);
|
||||
$cacheModified =filemtime($cachepath);
|
||||
|
||||
if ($templateModified > $cacheModified) {
|
||||
$output=make_clean_css($filepath, $filename);
|
||||
write_css_cache($cachepath, $output);
|
||||
} else {
|
||||
$output = file_get_contents($cachepath);
|
||||
}
|
||||
} else {
|
||||
$output=make_clean_css($filepath, $filename);
|
||||
write_css_cache($cachepath, $output);
|
||||
}
|
||||
|
||||
header("Date: " . date("D, j M Y G:i:s ", $templateModified) . 'GMT');
|
||||
header("Content-Type: text/css");
|
||||
header("Expires: " . gmdate("D, j M Y H:i:s", time() + DAY) . " GMT");
|
||||
header("Cache-Control: cache"); // HTTP/1.1
|
||||
header("Pragma: cache"); // HTTP/1.0
|
||||
print $output;
|
||||
?>
|
||||
@@ -1,147 +0,0 @@
|
||||
body {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#skip-to-nav {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#header {
|
||||
background-color: #333;
|
||||
border-bottom: 2px solid #ccc;
|
||||
height: 70px;
|
||||
}
|
||||
|
||||
#content {
|
||||
padding: 0 1em;
|
||||
font-family: verdana, arial, sans-serif;
|
||||
}
|
||||
|
||||
#content h1,h2,h3,h4,h5 {
|
||||
border-bottom: 1px solid #eee;
|
||||
color: #337;
|
||||
font-family: arial, verdana, sans-serif;
|
||||
margin: .2em 0;
|
||||
padding: .2em 0;
|
||||
}
|
||||
|
||||
#content h1 {
|
||||
font-size: 1.5em;
|
||||
}
|
||||
|
||||
#content h2 {
|
||||
font-size: 1.3em;
|
||||
}
|
||||
|
||||
#content h3 {
|
||||
font-size: 1.2em;
|
||||
}
|
||||
|
||||
#content h4 {
|
||||
font-size: 1.0em;
|
||||
}
|
||||
|
||||
#content h5 {
|
||||
font-size: 0.8em;
|
||||
}
|
||||
|
||||
#wrapper {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#nav {
|
||||
position: absolute;
|
||||
right: 10px;
|
||||
top: 2em;
|
||||
}
|
||||
|
||||
#nav ul {
|
||||
list-style-type: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
#nav ul li {
|
||||
float: left;
|
||||
}
|
||||
|
||||
#nav ul li a {
|
||||
background-color: #666;
|
||||
border: 2px inset #000;
|
||||
color: #eee;
|
||||
display: block;
|
||||
font-family: verdana, arial, sans-serif;
|
||||
font-size: small;
|
||||
font-weight: bold;
|
||||
margin: 4px;
|
||||
padding: 2px 5px;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
#nav ul li a:hover {
|
||||
border: 2px outset #000;
|
||||
color: #666;
|
||||
background-color: #eee;
|
||||
}
|
||||
|
||||
#footer {
|
||||
background-color: #333;
|
||||
border-top: 2px solid #ccc;
|
||||
border-bottom: 2px solid #ccc;
|
||||
color: #eee;
|
||||
padding: .6em .4em .4em .4em;
|
||||
}
|
||||
|
||||
#footer a {
|
||||
color: #ccc;
|
||||
}
|
||||
|
||||
.hidden {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.copyright {
|
||||
color: #eee;
|
||||
float: right;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
font-size: x-small;
|
||||
font-family: verdana, arial, sans-serif;
|
||||
}
|
||||
|
||||
.buttons {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
.buttons img {
|
||||
border: none;
|
||||
}
|
||||
|
||||
.inav {
|
||||
background: #eee;
|
||||
border: 1px solid #ccc;
|
||||
padding: .2em;
|
||||
}
|
||||
|
||||
.inav th {
|
||||
background-color: #999;
|
||||
color: blue;
|
||||
font-size: small;
|
||||
font-weight: bold;
|
||||
line-height: 1.6em;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.inav th a {
|
||||
color: blue;
|
||||
display: block;
|
||||
background-color: #999;
|
||||
padding: 0 .5em;
|
||||
}
|
||||
|
||||
.inav th a:hover {
|
||||
background-color: #fff;
|
||||
}
|
||||
@@ -1,268 +0,0 @@
|
||||
*{
|
||||
margin:0;
|
||||
padding:0;
|
||||
}
|
||||
|
||||
body{
|
||||
font-family:verdana,helvetica,arial,sans-serif;
|
||||
font-size:12px;
|
||||
text-align:center;
|
||||
color:#fff;
|
||||
background:#003d4c;
|
||||
}
|
||||
|
||||
/*
|
||||
* General Style Info
|
||||
*/
|
||||
|
||||
a{
|
||||
color:#003d4c;
|
||||
text-decoration:none;
|
||||
}
|
||||
a:hover{
|
||||
color:#003d4c;
|
||||
text-decoration:underline;
|
||||
}
|
||||
|
||||
a img{
|
||||
border:none;
|
||||
}
|
||||
|
||||
h1, h2,h3{
|
||||
font-family:'Gill Sans';
|
||||
font-size:28px;
|
||||
font-weight:normal;
|
||||
}
|
||||
h1{
|
||||
padding:0.5em 0;
|
||||
color:#003d4c;
|
||||
}
|
||||
em {
|
||||
font-size: 12px;
|
||||
}
|
||||
h2{
|
||||
padding-top:0.15em;
|
||||
margin:0.3em 0;
|
||||
color:#e32;
|
||||
}
|
||||
|
||||
h3{
|
||||
font-size:18px;
|
||||
padding-top:0.5em;
|
||||
color:#003d4c;
|
||||
}
|
||||
|
||||
h4{
|
||||
color:#ff9966;
|
||||
font-size:20px;
|
||||
padding-top:0.5em;
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
blockquote{
|
||||
padding: 10px;
|
||||
padding-left: 20px;
|
||||
padding-right: 20px;
|
||||
}
|
||||
|
||||
#content ol, #content ul{
|
||||
margin:0 1em;
|
||||
padding:0 2em;
|
||||
}
|
||||
|
||||
/*
|
||||
* Layout
|
||||
*/
|
||||
|
||||
#container{
|
||||
text-align:left;
|
||||
margin-left:0px;
|
||||
}
|
||||
|
||||
#header{
|
||||
height:200px;
|
||||
background:#003d4c;
|
||||
}
|
||||
|
||||
#header h1{
|
||||
color:#fff;
|
||||
font-family: 'Gill Sans';
|
||||
font-size: 45px;
|
||||
font-weight:normal;
|
||||
}
|
||||
|
||||
#header h1.logo {
|
||||
float:left;
|
||||
}
|
||||
|
||||
#header h1.logo a{
|
||||
display:block;
|
||||
width:226px;
|
||||
height:176px;
|
||||
background: transparent url('images/logo.gif') no-repeat top;
|
||||
}
|
||||
|
||||
#header h1.logo a:hover{
|
||||
background:url('images/logo.gif') no-repeat bottom;
|
||||
}
|
||||
|
||||
#content{
|
||||
width: auto;
|
||||
min-width: 860px;
|
||||
min-height: 720px;
|
||||
padding:15px 20px 50px 20px;
|
||||
margin: 0px 10px 0px 40px;
|
||||
color:#333;
|
||||
background:#fff ;
|
||||
border-right: 6px solid #222;
|
||||
}
|
||||
|
||||
/*
|
||||
* Navigation
|
||||
*/
|
||||
#navigation{
|
||||
float:left;
|
||||
height: 146px;
|
||||
width:710px;
|
||||
background:#003d4c url(images/nav_bg.gif) no-repeat;
|
||||
padding-left: 20px;
|
||||
}
|
||||
#navigation ul{
|
||||
|
||||
}
|
||||
|
||||
#navigation ul li{
|
||||
list-style-type:none;
|
||||
display:inline;
|
||||
}
|
||||
|
||||
#navigation ul li a{
|
||||
font-weight:bold;
|
||||
display:block;
|
||||
float:left;
|
||||
color:#000;
|
||||
}
|
||||
|
||||
#navigation ul li a span{
|
||||
display:block;
|
||||
margin-right:12px;
|
||||
padding:10px 6px 9px 9px;
|
||||
}
|
||||
|
||||
#navigation ul li.active a span{
|
||||
padding:10px 6px 9px 9px;
|
||||
}
|
||||
|
||||
|
||||
|
||||
#navigation ul li a:hover, #navigation ul li.active a{
|
||||
background:url(images/nav_item_bg.gif) no-repeat bottom right;
|
||||
}
|
||||
|
||||
#navigation ul li a:hover span, #navigation ul li.active a span{
|
||||
background:url(images/nav_item_bg.gif) no-repeat bottom left;
|
||||
}
|
||||
|
||||
#footer {
|
||||
color: #fff;
|
||||
background-color: #003d4c;
|
||||
padding: 4px 10px;
|
||||
text-align: right;
|
||||
}
|
||||
#footer a{
|
||||
color: #fff;
|
||||
}
|
||||
.left {
|
||||
float:left;
|
||||
}
|
||||
.right {
|
||||
float:right;
|
||||
}
|
||||
.clear {
|
||||
clear:both;
|
||||
height: 0px;
|
||||
line-height: 0px;
|
||||
}
|
||||
|
||||
|
||||
/* tables */
|
||||
|
||||
table {
|
||||
width: 100%;
|
||||
border: 0px;
|
||||
color:#333;
|
||||
border: 1px solid #ccc;
|
||||
background-color: #fff;
|
||||
clear:both;
|
||||
padding: 0;
|
||||
margin: 0 0 2em 0;
|
||||
white-space: normal;
|
||||
}
|
||||
th {
|
||||
background-color: #ccc;
|
||||
border-top: 1px solid #fff;
|
||||
border-left: 1px solid #fff;
|
||||
border-right: 1px solid #003d4c;
|
||||
border-bottom: 1px solid #003d4c;
|
||||
text-align: center;
|
||||
padding:2px;
|
||||
}
|
||||
table tr td {
|
||||
border-right: 1px solid #ccc;
|
||||
padding:4px 4px;
|
||||
vertical-align:top;
|
||||
text-align: center;
|
||||
}
|
||||
table tr.altRow td {
|
||||
background: #f4f4f4;
|
||||
}
|
||||
|
||||
/* scaffold show */
|
||||
|
||||
|
||||
div.related {
|
||||
clear:both;
|
||||
display:block;
|
||||
}
|
||||
dl {
|
||||
line-height:2em;
|
||||
margin:1em;
|
||||
float:left;
|
||||
width: 400px;
|
||||
}
|
||||
dt {
|
||||
font-weight: bold;
|
||||
vertical-align:top;
|
||||
}
|
||||
dd {
|
||||
margin-left:10em;
|
||||
margin-top:-2em;
|
||||
vertical-align:top;
|
||||
}
|
||||
|
||||
/* scaffold buttons */
|
||||
|
||||
|
||||
.notice {
|
||||
color: #DB8101;
|
||||
background-color: #ddd;
|
||||
display: block;
|
||||
padding: 1em;
|
||||
}
|
||||
.tip {
|
||||
color: #DB8101;
|
||||
background-color: #ddd;
|
||||
display: block;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
|
||||
/* action links */
|
||||
ul.actions {
|
||||
float:left;
|
||||
margin-left: 10px;
|
||||
width: 200px;
|
||||
}
|
||||
li {
|
||||
list-style-image: url("images/arrow.gif");
|
||||
}
|
||||
@@ -1,279 +0,0 @@
|
||||
/* form.css */
|
||||
|
||||
form {
|
||||
margin: 0 4px;
|
||||
font-size: 120%;
|
||||
border-width: 0px 0px 0px 0px;
|
||||
border-style: solid;
|
||||
border-color: #DB8101;
|
||||
}
|
||||
|
||||
form fieldset {
|
||||
font-size: 100%;
|
||||
border-color: #000000;
|
||||
border-width: 1px 0px 0px 0px;
|
||||
border-style: solid none none none;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
form fieldset legend {
|
||||
font-size: 150%;
|
||||
font-weight: normal;
|
||||
color: #000;
|
||||
padding: 0px 5px;
|
||||
}
|
||||
|
||||
label {
|
||||
font-size: 150%;
|
||||
}
|
||||
|
||||
label u {
|
||||
font-style: normal;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
input, select, textarea {
|
||||
font-family: Tahoma, Arial, sans-serif;
|
||||
font-size: 100%;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
textarea {
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
form div {
|
||||
clear: left;
|
||||
display: block;
|
||||
margin: 5px 0px 0px 0px;
|
||||
padding: 1px 3px;
|
||||
}
|
||||
|
||||
form fieldset div.notes {
|
||||
float: right;
|
||||
width: 158px;
|
||||
height: auto;
|
||||
margin: 0px 0px 10px 10px;
|
||||
padding: 5px;
|
||||
border: 1px solid #666;
|
||||
background-color: #ffffe1;
|
||||
color: #666;
|
||||
font-size: 88%;
|
||||
}
|
||||
|
||||
form fieldset div.notes h4 {
|
||||
background-image: url(/images/icon_info.gif);
|
||||
background-repeat: no-repeat;
|
||||
background-position: top left;
|
||||
padding: 3px 0px 3px 27px;
|
||||
border-width: 0px 0px 1px 0px;
|
||||
border-style: solid;
|
||||
border-color: #666;
|
||||
color: #666;
|
||||
font-size: 110%;
|
||||
}
|
||||
|
||||
form fieldset div.notes p {
|
||||
margin: 0em 0em 1.2em 0em;
|
||||
color: #666;
|
||||
}
|
||||
|
||||
form fieldset div.notes p.last {
|
||||
margin: 0em;
|
||||
}
|
||||
|
||||
form div fieldset {
|
||||
clear: none;
|
||||
border-width: 0px 1px 0px 1px;
|
||||
border-style: solid;
|
||||
border-color: #666;
|
||||
margin: 0px 0px 0px 142px;
|
||||
padding: 0px 5px 5px 5px;
|
||||
}
|
||||
|
||||
form div fieldset legend {
|
||||
font-size: 100%;
|
||||
padding: 0px 3px 0px 9px;
|
||||
}
|
||||
|
||||
form div.required fieldset legend {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
form div label {
|
||||
display: block;
|
||||
float: left;
|
||||
width: 200px;
|
||||
background-color: #f4f4f4;
|
||||
font-size: 16px;
|
||||
padding: 3px 5px;
|
||||
margin: 0px 0px 5px 0px;
|
||||
text-align: right;
|
||||
}
|
||||
|
||||
form div.optional label, label.optional {
|
||||
font-weight: normal;
|
||||
}
|
||||
|
||||
form div.required label, label.required {
|
||||
font-weight: bold;
|
||||
}
|
||||
|
||||
form div label.labelCheckbox, form div label.labelRadio {
|
||||
float: none;
|
||||
display: block;
|
||||
margin: 0px 0px 5px 142px;
|
||||
text-align: left;
|
||||
}
|
||||
|
||||
form div fieldset label.labelCheckbox, form div fieldset label.labelRadio {
|
||||
margin: 0px 0px 5px 0px;
|
||||
}
|
||||
p.error {
|
||||
color: #DB8101;
|
||||
background-color: #DBA941;
|
||||
font-size: 14px;
|
||||
padding: 1em;
|
||||
}
|
||||
|
||||
form div input, form div select, form div textarea {
|
||||
padding: 1px 3px;
|
||||
margin: 0px 0px 0px 0px;
|
||||
}
|
||||
|
||||
form div input.inputFile {
|
||||
width: 211px;
|
||||
}
|
||||
|
||||
form div select.selectOne, form div select.selectMultiple {
|
||||
width: 211px;
|
||||
padding: 1px 3px;
|
||||
}
|
||||
|
||||
form div input.inputCheckbox, form div input.inputRadio, input.inputCheckbox, input.inputRadio {
|
||||
display: inline;
|
||||
height: 14px;
|
||||
width: 14px;
|
||||
background-color: transparent;
|
||||
border-width: 0px;
|
||||
}
|
||||
|
||||
form div.submit {
|
||||
padding: 0px 0px 0px 140px;
|
||||
clear:both;
|
||||
display:block;
|
||||
}
|
||||
|
||||
div.submit input {
|
||||
padding: 2px 12px;
|
||||
color: #DB8101;
|
||||
background-color:#ccc;
|
||||
text-decoration: none;
|
||||
border: 1px solid #666;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
text-align:center;
|
||||
text-decoration: none;
|
||||
width: auto;
|
||||
}
|
||||
div.submit input:hover {
|
||||
padding: 2px 12px;
|
||||
color: #fff;
|
||||
background-color:#DB8101;
|
||||
text-decoration: none;
|
||||
border: 1px solid #666;
|
||||
font-size: 14px;
|
||||
font-weight: bold;
|
||||
text-align:center;
|
||||
text-decoration: none;
|
||||
width: auto;
|
||||
}
|
||||
|
||||
form div.submit div input.inputSubmit, form div.submit div input.inputButton {
|
||||
float: right;
|
||||
margin: 0px 0px 0px 5px;
|
||||
}
|
||||
|
||||
form div small {
|
||||
display: block;
|
||||
margin: 0px 0px 5px 142px;
|
||||
padding: 1px 3px;
|
||||
font-size: 88%;
|
||||
}
|
||||
|
||||
/* form.import.css */
|
||||
|
||||
form fieldset legend {
|
||||
line-height: 150%;
|
||||
}
|
||||
|
||||
form input, form select, form textarea {
|
||||
background-color: #fff;
|
||||
}
|
||||
|
||||
div.optional label:before {
|
||||
content: '';
|
||||
}
|
||||
|
||||
div.required label:before {
|
||||
content: '';
|
||||
}
|
||||
|
||||
form div label.labelCheckbox, form div label.labelRadio, label.labelCheckbox, label.labelRadio {
|
||||
display: block;
|
||||
width: 190px;
|
||||
padding: 4px 0px 0px 18px;
|
||||
text-indent: -18px;
|
||||
line-height: 120%;
|
||||
}
|
||||
|
||||
form div label.labelCheckbox input.inputCheckbox, form div label.labelRadio input.inputRadio, label.labelCheckbox input.inputCheckbox, label.labelRadio input.inputRadio {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
form div fieldset input.inputText, form div fieldset input.inputPassword, form div fieldset input.inputFile, form div fieldset textarea.inputTextarea {
|
||||
width: 160px;
|
||||
margin: 0px 0px 0px 18px;
|
||||
}
|
||||
|
||||
form div label.compact {
|
||||
display: inline;
|
||||
width: auto;
|
||||
padding: 4px 10px 0px 0px;
|
||||
text-indent: 0px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
form div.wide label {
|
||||
float: none;
|
||||
display: block;
|
||||
}
|
||||
|
||||
form div label.wide {
|
||||
width: 348px;
|
||||
}
|
||||
|
||||
form div.wide input.inputText, form div.wide input.inputPassword, form div.wide input.inputFile, form div.wide select, form div.wide textarea {
|
||||
width: 344px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
form div.notes p, form div small {
|
||||
line-height: 125%;
|
||||
}
|
||||
|
||||
form div.wide small {
|
||||
margin: 0px 0px 5px 0px;
|
||||
}
|
||||
|
||||
div.date select {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
select.autoWidth {
|
||||
width:auto;
|
||||
}
|
||||
|
||||
option {
|
||||
padding-left:1em;
|
||||
}
|
||||
|
Before Width: | Height: | Size: 62 B |
|
Before Width: | Height: | Size: 109 B |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 874 B |
|
Before Width: | Height: | Size: 531 B |
|
Before Width: | Height: | Size: 4.2 KiB |
|
Before Width: | Height: | Size: 1.4 KiB |