Compare commits

..

1 Commits

Author SHA1 Message Date
(no author)
83bf2ffa56 This commit was manufactured by cvs2svn to create tag 'release-1_1'.
git-svn-id: svn://10.0.0.236/tags/release-1_1@18221 18797224-902f-48f8-a5cc-f745e15eee43
1999-01-21 23:52:53 +00:00
127 changed files with 12261 additions and 18627 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,298 @@
1999-01-06 Leif Hedstrom <leif@netscape.com>
* Conn.pm (nextEntry): Fixed (tried to fix...) the bug with
missing attributes. I hope this will work, at a minimum I'm sure
it won't hurt. The idea is to keep the case on the attribute type
when requesting the values_len().
1999-01-11 Leif Hedstrom <leif@netscape.com>
* API.xs: Added IF statements around all ldap_value_free() calls.
1999-01-05 Leif Hedstrom <leif@netscape.com>
* Conn.pm (getRes): Ooops, didn't return the appropriate
value... :(
(init): Changed test for LDAP_SUCCESS, to always return 0 or 1.
(close): Dito.
(delete): Dito.
(add): Dito.
(modifyRDN): Dito.
(update): Dito.
(simpleAuth): Dito.
* Entry.pm (NEXTKEY): Don't return the last $key if it's one that
should be hidden.
* Conn.pm (newEntry): New method, to create an empty LDAP::Entry
object. It is properly "tied" into the appropriate object.
1999-01-04 Leif Hedstrom <leif@netscape.com>
* Entry.pm (setDN): Added third optional argument, to enfoce DN
normalization.
(getDN): Dito.
(hasDNValue): Dito.
(matchDNValue): Dito.
* Entry.pm (removeValue): Added support for DN normalization
(optional argument).
(addValue): Dito
(getDN): Dito.
1998-12-31 Leif Hedstrom <leif@netscape.com>
* Entry.pm (DESTROY): Added this method, don't know if it actually
makes any sense at all... :(
* Conn.pm (add): Use _oc_order_ to find a list of attributes, to
avoide calling the TIEHASH methods.
(update): Dito.
(ALL): Clean out some "my" definitions.
* Entry.pm (unRemove): New function, to undo remove opertaions on
an attribute.
(DELETE): Bug-fix, don't undef the attribute, it would prevent us
from updating it properly in the Conn::update() method.
(remove): Dito.
* Conn.pm (nextEntry): Return $obj instead of blessing the %entry
(again).
1998-12-25 Leif Hedstrom <leif@netscape.com>
* Conn.pm (POD): Changed examples from $conn -> $entry.
1998-12-17 Leif Hedstrom <leif@netscape.com>
* Conn.pm (DESTROY): undef the Perl data after doing a
ldap_msgfree(), bug #1964.
(search): Dito.
(searchURL): Dito.
(nextEntry): Changed the order of setting numattr, to make sure
it's zero if we don't find anything.
1998-12-16 Leif Hedstrom <leif@netscape.com>
* Entry.pm (FIRSTKEY): Modified to honor the oc_order.
(NEXTKEY): Dito.
(markModified): Made as an alias for attrModified().
* Conn.pm (nextEntry): Added code to handle internal counters for
number of attributes in oc_order. This is used/needed for the
FIRSTKEY and NEXTKEY methods in the Entry/Tie::Hash object.
* Entry.pm (isAttr): New method, to make sure an attribute name
really is a valid LDAP attribute.
(FIRSTKEY): Now we'll handle each() and keys() properly, whooohoo!
(NEXTKEY): Dito.
1998-12-15 Leif Hedstrom <leif@netscape.com>
* Entry.pm (isDeleted): Added new method, almost identical to isModified().
(EXISTS): New method, to implement the EXISTS functionality.
* API.xs (RET_CPP): Test for NULL pointers, bug #1387.
(RET_BVPP): Dito.
* Utils.pm (ldapArgs): Fixed bug where "-s 0" would not be honored
(I'm an idiot, OK?).
1998-12-14 Leif Hedstrom <leif@netscape.com>
* Conn.pm (getRes): New method, to return the internal result message.
(getLD): Use defined() around test for existence.
1998-12-11 Leif Hedstrom <leif@netscape.com>
* Conn.pm (new): Make sure binddn and bindpasswd are set to the
empty string unless specified.
(init): Make sure certdb is defined before trying to use it.
(setDefaultRebindProc): Added default auth method, unless
explicitly specified.
* Utils.pm (askPassword): Added support for Term::ReadKey.
(askPassword): Moved the eval "use ..." here.
(userCredentials): Removed verbose print statement.
(askPassword): Added an optional argument to print a prompt;
* Conn.pm (setDefaultRebindProc): Added a default "auth" value, if
not provided in the call.
1998-12-04 Leif Hedstrom <leif@netscape.com>
* Makefile.PL: Modified so that "silent" install will actually
echo what options it's setting.
It will now croak() if the SDK dir specified doesn't exist.
* INSTALL: Updated to reflect new v1.1 stuff. Added links to the
FAQ.
* README: Dito. Also changed some of the binary install
information, which might not be useful anyways...
* Makefile.PL: Added "filters" to remove .dll and .sl from shared
libraries when creating link options. I also replaced the code to
put the valid library extensions into a variable (bug #1344).
* Makefile.PL: Fixed some crap with the config parsing, and ENV
handling (for silent installs).
1998-12-03 Leif Hedstrom <leif@netscape.com>
* Conn.pm (update): Bug fix, now we empty the hash array before
examining changed attributes (bug #1385).
* Makefile.PL: Added the "-nolinenumbers" XSUBS options (bug #1329).
1998-09-26 Leif Hedstrom <leif@netscape.com>
* Conn.pm (init): Cleaned out _perror() calls.
(delete): Added support for calling delete() with an Entry::
object as paramter.
(new): Cleaned out some dead code for $ref.
* Entry.pm (setValue): New method, to avoid having to use Perl
assignment statements to set an entire attribute value.
1998-09-18 Leif Hedstrom <leif@netscape.com>
* Conn.pm (init): Changed call to ldapssl_client_init() to pass a
0 value as the handle pointer. This avoids a Perl compiler warning.
1998-09-12 Leif Hedstrom <leif@netscape.com>
* LDIF.pm (readEntries): Changed tests for empty arguments, to use
defined().
* Utils.pm (ldapArgs): Bug fix, we used the wrong option for the
certificate (-P) when checking to set the LDAP port.
(normalizeDN): Chagned tests for empty arguments, to use use defined().
* Entry.pm (STORE): Changed tests for empty arguments, to use
defined().
(DELETE): Dito.
(attrModified): Dito.
(isModified): Dito.
(remove): Dito.
(removeValue): Dito.
(addValue): Dito.
(hasValue): Dito.
(matchValue): Dito.
(setDN): Dito.
(size): Dito.
(exists): Dito.
* Conn.pm (printError): Changed test for $str to see if it's defined.
(delete): Cleaned up code around $dn.
(modifyRDN): Cleaned up testes around $dn and $del.
1998-09-11 Leif Hedstrom <leif@netscape.com>
* Conn.pm (modifyRDN): We now preserve the case of the DN/RDN, but
still treat RDNs as CIS when comparing strings.
1998-09-08 Leif Hedstrom <leif@netscape.com>
* Conn.pm (setDefaultRebindProc): Bug fix, it had the Ldapc:: crap
stil in there... :-(.
(simpleAuth): New method, to do simple authentication rebind.
1998-09-07 Leif Hedstrom <leif@netscape.com>
* Makefile.PL: Changed all <> to <STDIN>, to support command line
arguments for MakeMaker.
1998-09-03 Leif Hedstrom <leif@netscape.com>
* Conn.pm (nextEntry): Fixed bug with case sensitivity.
1998-08-18 Leif Hedstrom <leif@netscape.com>
* Conn.pm (setDefaultRebindProc): It's back!
Officially released PerLDAP v1.0.
1998-08-13 Leif Hedstrom <leif@netscape.com>
* Makefile.PL: Fixed so that automated installs works.
* Conn.pm (update): Fixed narly bug with ldap_modify()...
* All: Cleaned up some hash indexes, to make sure they are
properly quoted, and there are no conflicts to resolve.
* Entry.pm (STORE): Fixed a bug with attribute names not being
properly added to _oc_order_.
(addValue): Dito, added the same code as for STORE.
1998-08-06 Leif Hedstrom <leif@netscape.com>
* Entry.pm (printLDIF): Copied/modified from the Utils.pm library.
(isModified): Added this function, thought it might be useful.
1998-08-03 Leif Hedstrom <leif@netscape.com>
* Conn.pm (modifyRDN): Fixed! It also has an option to take an
"external" DN as an argument, if supplied.
1998-08-02 Leif Hedstrom <leif@netscape.com>
* Conn.pm (getErrorCode): Now takes two optional arguments, to
return the match string, and extra error string. Note that these
two arguments are pointers to strings!
* API.xs(ldap_get_lderrno): Fixed this function, at least it seems
to work now...
* Conn.pm (getLD): Added this function, convenient way to get the
LD from the OO layer.
1998-07-30 Leif Hedstrom <leif@netscape.com>
* Conn.pm (modifyRDN): New method, to rename the RDN of the entry.
* Utils.pm (answer): New function, from LdapUtils.pm.
* Conn.pm (delete): Fixed references to normalizeDN.
* Utils.pm (userCredentials): Added this function, to make it easy
to get credentials when binding as a user.
(normalizeDN): Fixed bugs, because of calling convention...
* Conn.pm (getError): Fixed bug with passing read-only argument.
1998-07-29 Leif Hedstrom <leif@netscape.com>
* Utils.pm (unixCrypt): Moved from my LdapUtils.pm module.
Added askPassword to the export tag.
* Conn.pm (new): Added support for passing a hash array of all the
parameters, as returned by the ldapArgs() function.
* Utils.pm (str2Scope): New function, for converting strings
(subtree) to a numerical scope value (2).
(askPassword): Dito, ask for a password, interactively.
(ldapArgs): Dito, handle common LDAP command line arguments.
* Makefile.PL: Minor change, to do regex match on OS version for
MSWin.
* Entry.pm: Changed all _XXX hash values to also end with a _,
hence making it easier to isolate them (/^_.*_$/).
* Conn.pm (nextEntry): Changed to accept that the attributes are
now arrays, not pointers to arrays. We still consider them as
pointers internally though, it's cleaner API.
* API.pm: Changed to use the native Exporter function to export
tags into EXPORT_OK.
1998-07-22 Leif Hedstrom <leif@netscape.com>
* LDIF.pm (readEntry): Moved from my LdapUtils.pm package.
* Utils.pm (printEntry): Moved from the ::Connection class, and
marked it as "obsolete".
(encodeBase64): Moved from my LdapUtils.pm package.
(decodeBase64): Dito.

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,949 @@
#############################################################################
# $Id: Entry.pm,v 1.10 1999-01-21 23:52:42 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# This package defines an object class to manage one single LDAP
# entry. This entry can either be a newly created one, or one
# retrieved from an LDAP server, using the Mozilla::LDAP::Conn class.
#
#############################################################################
package Mozilla::LDAP::Entry;
use Mozilla::LDAP::Utils qw(normalizeDN);
require Tie::Hash;
@ISA = (Tie::StdHash);
#############################################################################
# Creator, make a new tie hash instance, which will keep track of all
# changes made to the hash array. This is needed so we only update modified
# attributes.
#
sub TIEHASH
{
my $class = shift;
my $self = {};
return bless $self, $class;
}
#############################################################################
# Destructor.
#
#sub DESTROY
#{
#}
#############################################################################
# Store method, to keep track of changes.
#
sub STORE
{
my ($self, $attr, $val) = ($_[$[], lc $_[$[ + 1], $_[$[ + 2]);
return unless (defined($val) && ($val ne ""));
return unless (defined($attr) && ($attr ne ""));
if (defined($self->{$attr}))
{
@{$self->{"_${attr}_save_"}} = @{$self->{$attr}}
unless $self->{"_${attr}_save_"};
}
$self->{$attr} = $val;
$self->{"_${attr}_modified_"} = 1;
# Potentially add the attribute to the OC order list.
if (($attr ne "dn") && !grep(/^$attr$/i, @{$self->{"_oc_order_"}}))
{
push(@{$self->{"_oc_order_"}}, $attr);
$self->{"_oc_numattr_"}++;
}
}
#############################################################################
# Fetch method, this is case insensitive (since LDAP is...).
#
sub FETCH
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return unless defined($self->{$attr});
return if $self->{"_${attr}_deleted_"};
return $self->{$attr};
}
#############################################################################
# Delete method, to keep track of changes. Note that we actually don't
# delete the attribute, just mark it as deleted.
#
sub DELETE
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return unless (defined($attr) && ($attr ne ""));
return unless defined($self->{$attr});
$self->{"_${attr}_deleted_"} = 1;
}
#############################################################################
# See if an attribute/key exists in the entry (could still be undefined).
#
sub EXISTS
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return 0 if $self->{"_${attr}_deleted_"};
return exists $self->{$attr};
}
#############################################################################
# Reset the each()/key() session, and return the first key. This honors
# the oc_order, i.e. the order the attributes were returned in.
#
sub FIRSTKEY
{
my ($self, $idx) = ($_[$[], 0);
my @attrs = @{$self->{"_oc_order_"}};
my $key;
while ($idx < $self->{"_oc_numattr_"})
{
$key = $attrs[$idx++];
next if ($key =~ /^_.+_$/);
next if $self->{"_${key}_deleted_"};
last;
}
$self->{"_oc_keyidx_"} = $idx;
return $key;
}
#############################################################################
# Get the next key, if appropriate.
#
sub NEXTKEY
{
my $self = $_[$[];
my $idx = $self->{"_oc_keyidx_"};
my @attrs = @{$self->{"_oc_order_"}};
my $key;
while ($idx < $self->{"_oc_numattr_"})
{
$key = $attrs[$idx++];
next if ($key =~ /^_.+_$/);
next if $self->{"_${key}_deleted_"};
last;
}
$self->{"_oc_keyidx_"} = $idx;
return if ($key =~ /^_.+_$/);
return if $self->{"_${key}_deleted_"};
return $key;
}
#############################################################################
# Mark an attribute as changed. Normally you shouldn't have to use this,
# unless you're doing something really weird...
#
sub attrModified
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
return 0 if $self->{"_${attr}_deleted_"};
@{$self->{"_${attr}_save_"}} = @{$self->{$attr}}
unless $self->{"_${attr}_save_"};
$self->{"_self_obj_"}->{"_${attr}_modified_"} = 1;
return 1;
}
*markModified = \*attrModified;
#############################################################################
# Ask if a particular attribute has been modified already. Return True or
# false depending on the internal status of the attribute.
#
sub isModified
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
return $self->{"_self_obj_"}->{"_${attr}_modified_"};
}
#############################################################################
# Ask if a particular attribute has been deleted already. Return True or
# false depending on the internal status of the attribute.
#
sub isDeleted
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
return $self->{"_self_obj_"}->{"_${attr}_deleted_"};
}
#############################################################################
# Test if a attribute name is actually a real attribute, and not part of
# the internal structures.
#
sub isAttr
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
return 0 if $self->{"_${attr}_deleted_"};
return ($attr !~ /^_.+_$/);
}
#############################################################################
# Remove an attribute from the entry, basically the same as the DELETE
# method. We also make an alias for "delete" here, just in case (and to be
# somewhat backward compatible).
#
sub remove
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
$self->{"_self_obj_"}->{"_${attr}_deleted_"} = 1;
return 1;
}
*delete = \*remove;
#############################################################################
# Undo a remove(), or set of removeValues() fairly useless, to restore an
# attribute to it's original state. This is fairly useless, but hey...
#
sub unRemove
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
undef $self->{"_self_obj_"}->{"_${attr}_deleted_"};
if (defined $self->{"_${attr}_save_"})
{
@{$self->{$attr}} = @{$self->{"_${attr}_save_"}};
undef @{$selfl->{"_${key}_save_"}};
}
return 1;
}
*unDelete = \*unRemove;
#############################################################################
# Delete a value from an attribute, if it exists. NOTE: If it was the last
# value, we'll actually remove the entire attribute! We should then also
# remove it from the _oc_order_ list...
#
sub removeValue
{
my ($self, $attr, $val, $norm) = ($_[$[], lc $_[$[ + 1], $_[$[ + 2],
$_[$[ + 3]);
my $i = 0;
local $_;
return 0 unless (defined($val) && ($val ne ""));
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
$val = normalizeDN($val) if (defined($norm) && $norm);
@{$self->{"_${attr}_save_"}} = @{$self->{$attr}} unless
defined $self->{"_${attr}_save_"};
foreach (@{$self->{$attr}})
{
$_ = normalizeDN($_) if (defined($norm) && $norm);
if ($_ eq $val)
{
splice(@{$self->{$attr}}, $i, 1);
if ($self->size($attr) > 0)
{
$self->{"_self_obj_"}->{"_${attr}_modified_"} = 1;
}
else
{
$self->{"_self_obj_"}->{"_${attr}_deleted_"} = 1;
}
return 1;
}
$i++;
}
return 0;
}
*deleteValue = \*removeValue;
#############################################################################
# Just like removeValue(), but force the DN normalization of the value.
#
sub removeDNValue
{
my ($self, $attr, $val) = ($_[$[], lc $_[$[ + 1], $_[$[ + 2]);
return $self->removeValue($attr, $val, 1);
}
*deleteDNValue = \*removeDNValue;
#############################################################################
# Add a value to an attribute. The optional third argument indicates that
# we should not enforce the uniqueness on this attibute, thus bypassing
# the test and always add the value.
#
sub addValue
{
my $self = shift;
my ($attr, $val, $force, $norm) = (lc $_[$[], $_[$[ + 1], $_[$[ + 2],
$_[$[ + 3]);
local $_;
return 0 unless (defined($val) && ($val ne ""));
return 0 unless (defined($attr) && ($attr ne ""));
if (!defined($force) || !$force)
{
my $nval = $val;
$nval = normalizeDN($val) if (defined($norm) && $norm);
foreach (@{$self->{$attr}})
{
$_ = normalizeDN($_) if (defined($norm) && $norm);
return 0 if ($_ eq $nval);
}
}
if (defined($self->{$attr}))
{
@{$self->{"_${attr}_save_"}} = @{$self->{$attr}}
unless $self->{"_${attr}_save_"};
}
$self->{"_self_obj_"}->{"_${attr}_modified_"} = 1;
push(@{$self->{$attr}}, $val);
# Potentially add the attribute to the OC order list.
if (($attr ne "dn") && !grep(/^$attr$/i, @{$self->{"_oc_order_"}}))
{
push(@{$self->{"_oc_order_"}}, $attr);
$self->{"_oc_numattr_"}++;
}
return 1;
}
#############################################################################
# Just like addValue(), but force the DN normalization of the value. Note
# that we also have an $norm argument here, to normalize the DN value
# before we add it.
#
sub addDNValue
{
my $self = shift;
my ($attr, $val, $force, $norm) = (lc $_[$[], $_[$[ + 1], $_[$[ + 2],
$_[$[ + 2]);
$val = normalizeDN($val) if (defined($norm) && $norm);
return $self->addValue($attr, $val, $force, 1);
}
#############################################################################
# Set the entire value of an attribute, removing whatever was already set.
# The arguments are the name of the attribute, and then one or more values,
# passed as scalar or an array (not pointer).
#
sub setValue
{
my ($self, $attr) = (shift, lc shift);
my (@vals) = @_;
local $_;
return 0 unless (defined(@vals) && ($#vals >= $[));
return 0 unless (defined($attr) && ($attr ne ""));
$self->{$attr} = [@vals];
return 1;
}
#############################################################################
# Return TRUE or FALSE, if the attribute has the specified value. The
# optional third argument says we should do case insensitive search.
#
sub hasValue
{
my($self, $attr, $val, $nocase, $norm) = @_;
return 0 unless (defined($val) && ($val ne ""));
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
$val = normalizeDN($val) if (defined($norm) && $norm);
if ($nocase)
{
foreach (@{$self->{$attr}})
{
$_ = normalizeDN($_) if (defined($norm) && $norm);
return 1 if /^\Q$val\E$/i;
}
}
else
{
foreach (@{$self->{$attr}})
{
$_ = normalizeDN($_) if (defined($norm) && $norm);
return 1 if /^\Q$val\E$/;
}
}
return 0;
}
#############################################################################
# Just like hasValue(), but force the DN normalization of the value.
#
sub hasDNValue
{
my($self, $attr, $val, $nocase) = @_;
return $self->hasValue($attr, $val, $nocase, 1);
}
#############################################################################
# Return TRUE or FALSE, if the attribute matches the specified regexp. The
# optional third argument says we should do case insensitive search.
#
sub matchValue
{
my($self, $attr, $reg, $nocase) = @_;
return 0 unless (defined($reg) && ($reg ne ""));
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
if ($nocase)
{
foreach (@{$self->{$attr}})
{
$_ = normalizeDN($_);
return 1 if /$reg/i;
}
}
else
{
foreach (@{$self->{$attr}})
{
$_ = normalizeDN($_);
return 1 if /$reg/;
}
}
return 0;
}
#############################################################################
# Just like matchValue(), but force the DN normalization of the values.
#
sub matchDNValue
{
my($self, $attr, $reg, $nocase) = @_;
return $self->matchValue($attr, $reg, $nocase, 1);
}
#############################################################################
# Set the DN of this entry.
#
sub setDN
{
my ($self, $val, $norm) = @_;
return 0 unless (defined($val) && ($val ne ""));
$val = normalizeDN($val) if (defined($norm) && $norm);
$self->{"dn"} = $val;
return 1;
}
#############################################################################
# Get the DN of this entry.
#
sub getDN
{
my ($self, $norm) = @_;
return normalizeDN($self->{"dn"}) if (defined($norm) && $norm);
return $self->{"dn"};
}
#############################################################################
#
# Return the number of elements in an attribute.
#
sub size
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
my @val;
return 0 unless (defined($attr) && ($attr ne ""));
return 0 unless defined($self->{$attr});
@val = @{$self->{$attr}};
return $#val + 1;
}
#############################################################################
#
# Return TRUE if the attribute name is in the LDAP entry.
#
sub exists
{
my ($self, $attr) = ($_[$[], lc $_[$[ + 1]);
return 0 unless (defined($attr) && ($attr ne ""));
return defined($self->{$attr});
}
#############################################################################
# Print an entry, in LDIF format. This is idential to the Utils::printEntry
# function, but this is sort of neat... Note that the support for Base64
# encoding isn't finished.
#
sub printLDIF
{
my ($self, $base64) = @_;
my $attr;
print "dn: ", $self->getDN(),"\n";
foreach $attr (@{$self->{"_oc_order_"}})
{
next if ($attr =~ /^_.+_$/);
next if $self->{"_${attr}_deleted_"};
grep((print "$attr: $_\n"), @{$self->{$attr}});
}
print "\n";
}
#############################################################################
# Mandatory TRUE return value.
#
1;
#############################################################################
# POD documentation...
#
__END__
=head1 NAME
Mozilla::LDAP::Entry.pm - Object class to hold one LDAP entry.
=head1 SYNOPSIS
use Mozilla::LDAP::Conn;
use Mozilla::LDAP::Entry;
=head1 ABSTRACT
The LDAP::Conn object is used to perform LDAP searches, updates, adds and
deletes. All such functions works on LDAP::Entry objects only. All
modifications and additions you'll do to an LDAP entry, will be done
through this object class.
=head1 DESCRIPTION
The LDAP::Entry object class is built on top of the Tie::Hash standard
object class. This gives us several powerful features, the main one being
to keep track of what is changing in the LDAP entry. This makes it very
easy to write LDAP clients that needs to update/modify entries, since
you'll just do the changes, and this object class will take care of the
rest.
We define local functions for STORE, FETCH, DELETE, EXISTS, FIRSTKEY and
NEXTKEY in this object class, and inherit the rest from the super
class. Overloading these specific functions is how we can keep track of
what is changing in the entry, which turns out to be very convenient. We
can also easily "loop" over the attribute types, ignoring internal data,
or deleted attributes.
Most of the methods here either return the requested LDAP value, or a
status code. The status code (either 0 or 1) indicates the failure or
success of a certain operation. 0 (False) meaning the operation failed,
and a return code of 1 (True) means complete success.
One thing to remember is that in LDAP, attribute names are case
insensitive. All methods in this class are aware of this, and will convert
all attribute name arguments to lower case before performing any
operations. This does not mean that the values are case insensitive. On
the contrary, all values are considered case sensitive by this module,
even if the LDAP server itself treats it as a CIS attribute.
=head1 OBJECT CLASS METHODS
The LDAP::Entry class implements many methods you can use to access and
modify LDAP entries. It is strongly recommended that you use this API as
much as possible, and avoid using the internals of the class
directly. Failing to do so may actually break the functionality.
=head2 Creating a new entry
To create a completely new entry, use the B<new> method, for instance
$entry = new Mozilla::LDAP::Entry()
$entry->setDN("uid=leif,ou=people,dc=netscape,dc=com");
$entry->{objectclass} = [ "top", "person", "inetOrgPerson" ];
$entry->addValue("cn", "Leif Hedstrom");
$entry->addValue("sn", "Hedstrom");
$entry->addValue("givenName", "Leif");
$entry->addValue("mail", "leif@netscape.com);
$conn->add($entry);
This is the minimum requirements for an LDAP entry. It must have a DN, and
it must have at least one objectclass. As it turns out, by adding the
I<person> and I<inetOrgPerson> classes, we also must provide some more
attributes, like I<CN> and I<SN>. This is because the object classes have
these attributes marked as "required", and we'd get a schema violation
without those values.
In the example above we use both native API methods to add values, and
setting an attribute entire value set directly. Note that the value set is
a pointer to an array, and not the array itself. In the example above, the
object classes are set using an anonymous array, which the API handles
properly. It's important to be aware that the attribute value list is
indeed a pointer.
Finally, as you can see there's only only one way to add new LDAP entries,
and it's called add(). It normally takes an LDAP::Entry object instance as
argument, but it can also be called with a regular hash array if so
desired.
=head2 Adding and removing attributes and values
This is the main functionality of this module. Use these methods to do any
modifications and updates to your LDAP entries.
=over 13
=item B<attrModified>
This is an internal function, that can be used to force the API to
consider an attribute (value) to have been modified. The only argument is
the name of the attribute. In almost all situation, you never, ever,
should call this. If you do, please contact the developers, and as us to
fix the API. Example
$entry->attrModified("cn");
=item B<isModified>
This is a somewhat more useful method, which will return the internal
modification status of a particular attribute. The argument is the name of
the attribute, and the return value is True or False. If the attribute has
been modified, in any way, we return True (1), otherwise we return False
(0). For example:
if ($entry->isModified("cn")) { # do something }
=item B<isDeleted>
This is almost identical to B<isModified>, except it tests if an attribute
has been deleted. You use it the same way as above, like
if (! $entry->isDeleted("cn")) { # do something }
=item B<isAttr>
This method can be used to decide if an attribute name really is a valid
LDAP attribute in the current entry. Use of this method is fairly limited,
but could potentially be useful. Usage is like previous examples, like
if ($entry->isAttr("cn")) { # do something }
The code section will only be executed if these criterias are true:
1. The name of the attribute is a non-empty string.
2. The name of the attribute does not begin, and end, with an
underscore character (_).
2. The attribute has one or more values in the entry.
=item B<remove>
This will remove the entire attribute, including all it's values, from the
entry. The only argument is the name of the attribute to remove. Let's say
you want to nuke all I<mailAlternateAddress> values (i.e. the entire
attribute should be removed from the entry):
$entry->remove("mailAlternateAddress");
=item B<removeValue>
Remove a value from an attribute, if it exists. Of course, if the
attribute has no such value, we won't try to remove it, and instead return
a False (0) status code. The arguments are the name of the attribute, and
the particular value to remove. Note that values are considered case
sensitive, so make sure you preserve case properly. An example is:
$entry->removeValue("objectclass", "nscpPerson");
=item B<removeDNValue>
This is almost identical to B<removeValue>, except it will normalize the
attribute values before trying to remove them. This is useful if you know
that the attribute is a DN value, but perhaps the values are not cosistent
in all LDAP entries. For example
$dn = "uid=Leif, dc=Netscape, dc=COM";
$entry->removeDNValue("owner", $dn);
will remove the owner "uid=leif,dc=netscape,dc=com", no matter how it's
capitalized and formatted in the entry.
=item B<addValue>
Add a value to an attribute. If the attribute value already exists, or we
couldn't add the value for any other reason, we'll return FALSE (0),
otherwise we return TRUE (1). The first two arguments are the attribute
name, and the value to add.
The optional third argument is a flag, indicating that we want to add the
attribute without checking for duplicates. This is useful if you know the
values are unique already, or if you perhaps want to allow duplicates for
a particular attribute. To add a CN to an existing entry/attribute, do:
$entry->addValue("cn", "Leif Hedstrom");
=item B<addDNValue>
Just like B<addValue>, except this method assume the value is a DN
attribute. For instance
$dn = "uid=Leif, dc=Netscape, dc=COM";
$entry->addDNValue("uniqueMember", $dn);
will only add the DN for "uid=leif" if it does not exist as a DN in the
uniqueMember attribute.
=item B<setValue>
Set the specified attribute to the new value (or values), overwriting
whatever old values it had before. This is a little dangerous, since you
can lose attribute values you didn't intend to remove. Therefore, it's
usually recommended to use B<removeValue()> and B<setValue()>. If you know
exactly what the new values should be like, you can use this method like
$entry->setValue("cn", "Leif Hedstrom", "The Swede");
$entry->setValue("mail", @mailAddresses);
or if it's a single value attribute,
$entry->setValue("uidNumber", "12345");
=item B<hasValue>
Return TRUE or FALSE if the attribute has the specified value. A typical
usage is to see if an entry is of a certain object class, e.g.
if ($entry->hasValue("objectclass", "person", 1)) { # do something }
The (optional) third argument indicates if the string comparison should be
case insensitive or not. The first two arguments are the name and value of
the attribute, as usual.
=item B<hasDNValue>
Exactly like B<hasValue>, except we assume the attribute values are DN
attributes.
=item B<matchValue>
This is very similar to B<hasValue>, except it does a regular expression
match instead of a full string match. It takes the same arguments,
including the optional third argument to specify case insensitive
matching. The usage is identical to the example for hasValue, e.g.
if ($entry->matchValue("objectclass", "pers", 1)) { # do something }
=item B<matchDNValue>
Like B<matchValue>, except the attribute values are considered being DNs.
=item B<setDN>
Set the DN to the specified value. Only do this on new entries, it will
not work well if you try to do this on an existing entry. If you wish to
renamed an entry, use the Mozilla::Conn::modifyRDN method instead.
Eventually we'll provide a complete "rename" method. To set the DN for a
newly created entry, we can do
$entry->setDN("uid=leif,ou=people,dc=netscape,dc=com");
There is an optional third argument, a boolean flag, indicating that we
should normalize the DN before setting it. This will assure a consistent
format of your DNs.
=item B<getDN>
Return the DN for the entry. For instance
print "The DN is: ", $entry->getDN(), "\n";
Just like B<setDN>, this method also has an optional argument, which
indicates we should normalize the DN before returning it to the caller.
=item B<size>
Return the number of values for a particular attribute. For instance
$entry->{cn} = [ "Leif Hedstrom", "The Swede" ];
$numVals = $entry->size("cn");
This will set C<$numVals> to two (2). The only argument is the name of the
attribute, and the return value is the size of the value array.
=item B<exists>
Return TRUE if the specified attribute is defined in the LDAP entry. This
is useful to know if an entry has a particular attribute, regardless of
the value. For instance:
if ($entry->exists("jpegphoto")) { # do something special }
=item B<printLDIF>
Print the entry (on STDOUT) in a format called LDIF (LDAP Data Interchange
Format, RFC xxxx). An example of an LDIF entry is:
dn: uid=leif,ou=people,dc=netscape,dc=com
objectclass: top
objectclass: person
objectclass: inetOrgPerson
uid: leif
cn: Leif Hedstrom
mail: leif@netscape.com
The above would be the result of
$entry->printLDIF();
If you need to write to a file, close STDOUT, and open up a file with that
file handle instead. For more useful LDIF functionality, check out the
Mozilla::LDAP::LDIF.pm module.
=back
=head2 Deleting entries
To delete an LDAP entry from the LDAP server, you have to use the
B<delete> method from the Mozilla::LDAP::Conn module. It will actually
delete any entry, if you provide an legitimate DN.
=head2 Renaming entries
Again, there's no functionality in this object class to rename the entry
(i.e. changing it's DN). For now, there is a way to modify the RDN
component of a DN through the Mozilla::LDAP::Conn module, with
B<modifyRDN>. Eventually we hope to have a complete B<rename> method,
which should be capable of renaming any entry, in any way, including
moving it to a different part of the DIT (Directory Information Tree).
=head1 EXAMPLES
There are plenty of examples to look at, in the examples directory. We are
adding more examples every day (almost).
=head1 INSTALLATION
Installing this package is part of the Makefile supplied in the
package. See the installation procedures which are part of this package.
=head1 AVAILABILITY
This package can be retrieved from a number of places, including:
http://www.mozilla.org/directory/
Your local CPAN server
=head1 CREDITS
Most of this code was developed by Leif Hedstrom, Netscape Communications
Corporation.
=head1 BUGS
None. :)
=head1 SEE ALSO
L<Mozilla::LDAP::Conn>, L<Mozilla::LDAP::API>, and of course L<Perl>.
=cut

View File

@@ -0,0 +1,98 @@
PerLDAP installation instructions
==================================
Building this package is fairly straight forward, but requires some
knowledge about using compilers and compiler tools on your system. If you
are uncomfortable using these tools, we recommend you get one of the
prebuilt binary distributions instead.
Prerequisites
=============
In order to build the module, you'll need
- Perl, version 5.003 or later. We definitely recommend you to use
v5.004 or later.
- An ANSI-C compiler, e.g. gcc-2.x, or Visual C++ 5.0.
- The LDAP client libraries and include files, e.g. the SDK from
Netscape Communications. See the README file for information on
retrieving binaries.
You can download (or CVS checkout) the Directory SDK source, see further
information available on
http://www.mozilla.org/directory/
and the FAQ at
http://www.mozilla.org/directory/faq/perldap-faq.html
Building
========
This package uses the normal Perl5 MakeMaker installation system. To
generate a Makefile appropriate for your platform, run perl on the
provided Makefile.PL script, e.g.
% perl Makefile.PL
You might have to use the command `perl5' or `perl-5.004', depending on
how you installed Perl-5. The script will now ask you a few questions to
find the necessary library and include files. A typical configuration
session is
data 195% perl5 Makefile.PL
PerLDAP - Perl 5 Module for LDAP
================================
Directory containing 'include' and 'lib' directory of the Netscape
LDAP Software Developer Kit (default: /usr): /opt/ldapsdk3
Using LDAPv3 Developer Kit (default: yes)?
Include SSL Support (default: yes)?
Libraries to link with (default: -L/opt/pkg/ldapsdk3/lib -lldapssl30):
Checking if your kit is complete...
Looks good
Writing Makefile for Mozilla::LDAP::API
The important question is where your LDAP SDK is installed, in the example
above the base directory is /opt/ldapsdk3. This directory should have two
subdirectories, named "lib" and "include". If you installed the SDK in the
standard /usr hierarchy, use the default value as provided by the install
script.
Assuming you get no errors or warning, proceed with the build and install:
% make
% make install
That should be it!
Automated Configuration and Installs
====================================
The Makefile.PL script also honors a set of environment variables to make
it possible to do configuration and installs non-interactively. The
variables are
LDAPSDKDIR - Full path to the C SDK base directory
LDAPV3ON - Set to "N" to diable LDAP v3 (on by default)
LDAPSDKSSL - Set to "N" to disable SSL (SSL is default)
With these variables set, you will not be asked any of the questions above
(but it will echo the paramaters). Just run the Makefile.PL script, and
finish the build, e.g.
% perl5 Makefile.PL
% make
% make install

View File

@@ -0,0 +1,274 @@
#############################################################################
# $Id: LDIF.pm,v 1.6 1999-01-21 23:52:42 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Simple routines to read and write LDIF style files. You should open
# the input/output file manually, or use STDIN/STDOUT.
#
#############################################################################
package Mozilla::LDAP::LDIF;
use Mozilla::LDAP::Entry;
use Mozilla::LDAP::Utils(qw(decodeBase64));
#############################################################################
# Creator, the argument (optional) is the file handle.
#
sub new
{
my ($class, $fh) = @_;
my $self = {};
if ($fh)
{
$self->{"_fh_"} = $fh;
$self->{"_canRead_"} = 1;
$self->{"_canWrite_"} = 1;
}
else
{
$self->{"_fh_"} = STDIN;
$self->{"_canRead_"} = 1;
$self->{"_canWrite_"} = 0;
}
return bless $self, $class;
}
#############################################################################
# Destructor, close file descriptors etc. (???)
#
#sub DESTROY
#{
# my $self = shift;
#}
#############################################################################
# Read the next $entry from an ::LDIF object. No arguments
#
sub readOneEntry
{
my ($self) = @_;
my ($attr, $val, $entry, $base64, $fh);
local $_;
return unless $self->{"_canRead_"};
return unless defined($self->{"_fh_"});
# Skip leading empty lines.
$fh = $self->{"_fh_"};
while (<$fh>)
{
chop;
last unless /^\s*$/;
}
return if /^$/; # EOF
$self->{"_canWrite_"} = 0 if $self->{"_canWrite_"};
$entry = new Mozilla::LDAP::Entry();
do
{
# See if it's a continuation line.
if (/^ /o)
{
$val .= substr($_, 1);
}
else
{
if ($val && $attr)
{
if ($attr eq "dn")
{
$entry->setDN($val);
}
else
{
$val = decodeBase64($val) if $base64;
$entry->addValue($attr, "$val", 1);
}
}
($attr, $val) = split(/:\s+/, $_, 2);
$attr = lc $attr;
# Handle base64'ed data.
if ($attr =~ /:$/o)
{
$base64 = 1;
chop($attr);
}
else
{
$base64 = 0;
}
}
$_ = <$fh>;
chop;
} until /^\s*$/;
# Do the last attribute...
if ($attr && ($attr ne "dn"))
{
$val = decodeBase64($val) if $base64;
$entry->addValue($attr, "$val", 1);
}
return $entry;
}
*readEntry = \readOneEntry;
#############################################################################
# Print one entry, to the file handle. Note that we actually use some
# internals from the ::Entry object here, which is a no-no... Also, we need
# to support Base64 encoding of Binary attributes here.
#
sub writeOneEntry
{
my ($self, $entry) = @_;
my ($fh, $attr);
return unless $self->{"_canWrite_"};
$self->{"_canRead_"} = 0 if $self->{"_canRead_"};
$fh = $self->{"_fh_"};
print $fh "dn: ", $entry->getDN(),"\n";
foreach $attr (@{$entry->{"_oc_order_"}})
{
next if ($attr =~ /^_.+_$/);
next if $entry->{"_${attr}_deleted_"};
# TODO: Add support for Binary attributes.
grep((print $fh "$attr: $_\n"), @{$entry->{$attr}});
}
print $fh "\n";
}
*writeEntry = \writeOneEntry;
#############################################################################
# Read multiple entries, and return an array of Entry objects. The argument
# is the number to read, or read them all if not specified.
#
sub readEntries
{
my ($self, $num) = @_;
my $entry;
my (@entries);
return if (defined($num) && ($num ne "") && ($num <= 0));
$num = (-1) unless defined($num);
do
{
$entry = $self->readOneEntry();
push(@entries, $entry) if ($entry);
$num--;
} until (! $entry || $num == 0);
return @entries;
}
#############################################################################
# Write multiple entries, the argument is the array of Entry objects.
#
sub writeEntries
{
my ($self, @entries) = @_;
local $_;
foreach (@entries)
{
$self->writeOneEntry($_);
}
}
#############################################################################
# Mandatory TRUE return value.
#
1;
#############################################################################
# POD documentation...
#
__END__
=head1 NAME
Mozilla::LDAP::LDIF - Read, write and modify LDIF files.
=head1 SYNOPSIS
use Mozilla::LDAP::LDIF;
=head1 ABSTRACT
This package is used to read and write LDIF information from files
(actually, file handles). It can also be used to generate LDIF modify
files from changes made to an entry.
=head1 DESCRIPTION
The LDIF format is a simple, yet useful, text representation of an LDAP
database. The goal of this package is to make it as easy as possible to
read, parse and use LDIF data, possible generated from other information
sources.
=head1 EXAMPLES
There are plenty of examples to look at, in the examples directory. We are
adding more examples every day (almost).
=head1 INSTALLATION
Installing this package is part of the Makefile supplied in the
package. See the installation procedures which are part of this package.
=head1 AVAILABILITY
This package can be retrieved from a number of places, including:
http://www.mozilla.org/directory/
Your local CPAN server
=head1 CREDITS
Most of this code was developed by Leif Hedstrom, Netscape Communications
Corporation.
=head1 BUGS
None. :)
=head1 SEE ALSO
L<Mozilla::LDAP::Conn>, L<Mozilla::LDAP::Entry>, L<Mozilla::LDAP::API>,
and of course L<Perl>.
=cut

View File

@@ -0,0 +1,33 @@
ChangeLog
API.pm
API.xs
MANIFEST
Makefile.PL
constant.h
test.pl
typemap
Entry.pm
Conn.pm
LDIF.pm
Utils.pm
README
INSTALL
MPL-1.0.txt
test_api/search.pl
test_api/write.pl
test_api/api.pl
t/conn.pl
t/entry.pl
t/ChangeLog
examples/ChangeLog
examples/lfinger.pl
examples/qsearch.pl
examples/monitor.pl
examples/ldappasswd.pl
examples/rmentry.pl
examples/tabdump.pl
examples/modattr.pl
examples/rename.pl
examples/psoftsync.pl
examples/changes2ldif.pl
install-bin

View File

@@ -0,0 +1,360 @@
MOZILLA PUBLIC LICENSE
Version 1.0
----------------
1. Definitions.
1.1. ``Contributor'' means each entity that creates or contributes to
the creation of Modifications.
1.2. ``Contributor Version'' means the combination of the Original
Code, prior Modifications used by a Contributor, and the Modifications
made by that particular Contributor.
1.3. ``Covered Code'' means the Original Code or Modifications or the
combination of the Original Code and Modifications, in each case
including portions thereof.
1.4. ``Electronic Distribution Mechanism'' means a mechanism generally
accepted in the software development community for the electronic
transfer of data.
1.5. ``Executable'' means Covered Code in any form other than Source
Code.
1.6. ``Initial Developer'' means the individual or entity identified as
the Initial Developer in the Source Code notice required by Exhibit A.
1.7. ``Larger Work'' means a work which combines Covered Code or
portions thereof with code not governed by the terms of this License.
1.8. ``License'' means this document.
1.9. ``Modifications'' means any addition to or deletion from the
substance or structure of either the Original Code or any previous
Modifications. When Covered Code is released as a series of files, a
Modification is:
A. Any addition to or deletion from the contents of a file
containing Original Code or previous Modifications.
B. Any new file that contains any part of the Original Code or
previous Modifications.
1.10. ``Original Code'' means Source Code of computer software code
which is described in the Source Code notice required by Exhibit A as
Original Code, and which, at the time of its release under this License
is not already Covered Code governed by this License.
1.11. ``Source Code'' means the preferred form of the Covered Code for
making modifications to it, including all modules it contains, plus any
associated interface definition files, scripts used to control
compilation and installation of an Executable, or a list of source code
differential comparisons against either the Original Code or another
well known, available Covered Code of the Contributor's choice. The
Source Code can be in a compressed or archival form, provided the
appropriate decompression or de-archiving software is widely available
for no charge.
1.12. ``You'' means an individual or a legal entity exercising rights
under, and complying with all of the terms of, this License or a future
version of this License issued under Section 6.1. For legal entities,
``You'' includes any entity which controls, is controlled by, or is
under common control with You. For purposes of this definition,
``control'' means (a) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (b) ownership of fifty percent (50%) or more of the
outstanding shares or beneficial ownership of such entity.
2. Source Code License.
2.1. The Initial Developer Grant.
The Initial Developer hereby grants You a world-wide, royalty-free,
non-exclusive license, subject to third party intellectual property
claims:
(a) to use, reproduce, modify, display, perform, sublicense and
distribute the Original Code (or portions thereof) with or without
Modifications, or as part of a Larger Work; and
(b) under patents now or hereafter owned or controlled by Initial
Developer, to make, have made, use and sell (``Utilize'') the
Original Code (or portions thereof), but solely to the extent that
any such patent is reasonably necessary to enable You to Utilize
the Original Code (or portions thereof) and not to any greater
extent that may be necessary to Utilize further Modifications or
combinations.
2.2. Contributor Grant.
Each Contributor hereby grants You a world-wide, royalty-free,
non-exclusive license, subject to third party intellectual property
claims:
(a) to use, reproduce, modify, display, perform, sublicense and
distribute the Modifications created by such Contributor (or
portions thereof) either on an unmodified basis, with other
Modifications, as Covered Code or as part of a Larger Work; and
(b) under patents now or hereafter owned or controlled by
Contributor, to Utilize the Contributor Version (or portions
thereof), but solely to the extent that any such patent is
reasonably necessary to enable You to Utilize the Contributor
Version (or portions thereof), and not to any greater extent that
may be necessary to Utilize further Modifications or combinations.
3. Distribution Obligations.
3.1. Application of License.
The Modifications which You create or to which You contribute are
governed by the terms of this License, including without limitation
Section 2.2. The Source Code version of Covered Code may be distributed
only under the terms of this License or a future version of this
License released under Section 6.1, and You must include a copy of this
License with every copy of the Source Code You distribute. You may not
offer or impose any terms on any Source Code version that alters or
restricts the applicable version of this License or the recipients'
rights hereunder. However, You may include an additional document
offering the additional rights described in Section 3.5.
3.2. Availability of Source Code.
Any Modification which You create or to which You contribute must be
made available in Source Code form under the terms of this License
either on the same media as an Executable version or via an accepted
Electronic Distribution Mechanism to anyone to whom you made an
Executable version available; and if made available via Electronic
Distribution Mechanism, must remain available for at least twelve (12)
months after the date it initially became available, or at least six
(6) months after a subsequent version of that particular Modification
has been made available to such recipients. You are responsible for
ensuring that the Source Code version remains available even if the
Electronic Distribution Mechanism is maintained by a third party.
3.3. Description of Modifications.
You must cause all Covered Code to which you contribute to contain a
file documenting the changes You made to create that Covered Code and
the date of any change. You must include a prominent statement that the
Modification is derived, directly or indirectly, from Original Code
provided by the Initial Developer and including the name of the Initial
Developer in (a) the Source Code, and (b) in any notice in an
Executable version or related documentation in which You describe the
origin or ownership of the Covered Code.
3.4. Intellectual Property Matters
(a) Third Party Claims.
If You have knowledge that a party claims an intellectual property
right in particular functionality or code (or its utilization
under this License), you must include a text file with the source
code distribution titled ``LEGAL'' which describes the claim and
the party making the claim in sufficient detail that a recipient
will know whom to contact. If you obtain such knowledge after You
make Your Modification available as described in Section 3.2, You
shall promptly modify the LEGAL file in all copies You make
available thereafter and shall take other steps (such as notifying
appropriate mailing lists or newsgroups) reasonably calculated to
inform those who received the Covered Code that new knowledge has
been obtained.
(b) Contributor APIs.
If Your Modification is an application programming interface and
You own or control patents which are reasonably necessary to
implement that API, you must also include this information in the
LEGAL file.
3.5. Required Notices.
You must duplicate the notice in Exhibit A in each file of the Source
Code, and this License in any documentation for the Source Code, where
You describe recipients' rights relating to Covered Code. If You
created one or more Modification(s), You may add your name as a
Contributor to the notice described in Exhibit A. If it is not possible
to put such notice in a particular Source Code file due to its
structure, then you must include such notice in a location (such as a
relevant directory file) where a user would be likely to look for such
a notice. You may choose to offer, and to charge a fee for, warranty,
support, indemnity or liability obligations to one or more recipients
of Covered Code. However, You may do so only on Your own behalf, and
not on behalf of the Initial Developer or any Contributor. You must
make it absolutely clear than any such warranty, support, indemnity or
liability obligation is offered by You alone, and You hereby agree to
indemnify the Initial Developer and every Contributor for any liability
incurred by the Initial Developer or such Contributor as a result of
warranty, support, indemnity or liability terms You offer.
3.6. Distribution of Executable Versions.
You may distribute Covered Code in Executable form only if the
requirements of Section 3.1-3.5 have been met for that Covered Code,
and if You include a notice stating that the Source Code version of the
Covered Code is available under the terms of this License, including a
description of how and where You have fulfilled the obligations of
Section 3.2. The notice must be conspicuously included in any notice in
an Executable version, related documentation or collateral in which You
describe recipients' rights relating to the Covered Code. You may
distribute the Executable version of Covered Code under a license of
Your choice, which may contain terms different from this License,
provided that You are in compliance with the terms of this License and
that the license for the Executable version does not attempt to limit
or alter the recipient's rights in the Source Code version from the
rights set forth in this License. If You distribute the Executable
version under a different license You must make it absolutely clear
that any terms which differ from this License are offered by You alone,
not by the Initial Developer or any Contributor. You hereby agree to
indemnify the Initial Developer and every Contributor for any liability
incurred by the Initial Developer or such Contributor as a result of
any such terms You offer.
3.7. Larger Works.
You may create a Larger Work by combining Covered Code with other code
not governed by the terms of this License and distribute the Larger
Work as a single product. In such a case, You must make sure the
requirements of this License are fulfilled for the Covered Code.
4. Inability to Comply Due to Statute or Regulation.
If it is impossible for You to comply with any of the terms of this
License with respect to some or all of the Covered Code due to statute
or regulation then You must: (a) comply with the terms of this License
to the maximum extent possible; and (b) describe the limitations and
the code they affect. Such description must be included in the LEGAL
file described in Section 3.4 and must be included with all
distributions of the Source Code. Except to the extent prohibited by
statute or regulation, such description must be sufficiently detailed
for a recipient of ordinary skill to be able to understand it.
5. Application of this License.
This License applies to code to which the Initial Developer has
attached the notice in Exhibit A, and to related Covered Code.
6. Versions of the License.
6.1. New Versions.
Netscape Communications Corporation (``Netscape'') may publish revised
and/or new versions of the License from time to time. Each version will
be given a distinguishing version number.
6.2. Effect of New Versions.
Once Covered Code has been published under a particular version of the
License, You may always continue to use it under the terms of that
version. You may also choose to use such Covered Code under the terms
of any subsequent version of the License published by Netscape. No one
other than Netscape has the right to modify the terms applicable to
Covered Code created under this License.
6.3. Derivative Works.
If you create or use a modified version of this License (which you may
only do in order to apply it to code which is not already Covered Code
governed by this License), you must (a) rename Your license so that the
phrases ``Mozilla'', ``MOZILLAPL'', ``MOZPL'', ``Netscape'', ``NPL'' or
any confusingly similar phrase do not appear anywhere in your license
and (b) otherwise make it clear that your version of the license
contains terms which differ from the Mozilla Public License and
Netscape Public License. (Filling in the name of the Initial Developer,
Original Code or Contributor in the notice described in Exhibit A shall
not of themselves be deemed to be modifications of this License.)
7. DISCLAIMER OF WARRANTY.
COVERED CODE IS PROVIDED UNDER THIS LICENSE ON AN ``AS IS'' BASIS,
WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
WITHOUT LIMITATION, WARRANTIES THAT THE COVERED CODE IS FREE OF
DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING.
THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED CODE
IS WITH YOU. SHOULD ANY COVERED CODE PROVE DEFECTIVE IN ANY RESPECT,
YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE
COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER
OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF
ANY COVERED CODE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER.
8. TERMINATION.
This License and the rights granted hereunder will terminate
automatically if You fail to comply with terms herein and fail to cure
such breach within 30 days of becoming aware of the breach. All
sublicenses to the Covered Code which are properly granted shall
survive any termination of this License. Provisions which, by their
nature, must remain in effect beyond the termination of this License
shall survive.
9. LIMITATION OF LIABILITY.
UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT
(INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE INITIAL
DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED CODE,
OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO YOU OR ANY OTHER
PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES
OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF
GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND
ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE
BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF
LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY
RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW
PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE
EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THAT
EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU.
10. U.S. GOVERNMENT END USERS.
The Covered Code is a ``commercial item,'' as that term is defined in
48 C.F.R. 2.101 (Oct. 1995), consisting of ``commercial computer
software'' and ``commercial computer software documentation,'' as such
terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48
C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995),
all U.S. Government End Users acquire Covered Code with only those
rights set forth herein.
11. MISCELLANEOUS.
This License represents the complete agreement concerning subject
matter hereof. If any provision of this License is held to be
unenforceable, such provision shall be reformed only to the extent
necessary to make it enforceable. This License shall be governed by
California law provisions (except to the extent applicable law, if any,
provides otherwise), excluding its conflict-of-law provisions. With
respect to disputes in which at least one party is a citizen of, or an
entity chartered or registered to do business in, the United States of
America: (a) unless otherwise agreed in writing, all disputes relating
to this License (excepting any dispute relating to intellectual
property rights) shall be subject to final and binding arbitration,
with the losing party paying all costs of arbitration; (b) any
arbitration relating to this Agreement shall be held in Santa Clara
County, California, under the auspices of JAMS/EndDispute; and (c) any
litigation relating to this Agreement shall be subject to the
jurisdiction of the Federal Courts of the Northern District of
California, with venue lying in Santa Clara County, California, with
the losing party responsible for costs, including without limitation,
court costs and reasonable attorneys fees and expenses. The application
of the United Nations Convention on Contracts for the International
Sale of Goods is expressly excluded. Any law or regulation which
provides that the language of a contract shall be construed against the
drafter shall not apply to this License.
12. RESPONSIBILITY FOR CLAIMS.
Except in cases where another Contributor has failed to comply with
Section 3.4, You are responsible for damages arising, directly or
indirectly, out of Your utilization of rights under this License, based
on the number of copies of Covered Code you made available, the
revenues you received from utilizing such rights, and other relevant
factors. You agree to work with affected parties to distribute
responsibility on an equitable basis.
EXHIBIT A.
``The contents of this file are subject to the Mozilla Public License
Version 1.0 (the "License"); you may not use this file except in
compliance with the License. You may obtain a copy of the License at
http://www.mozilla.org/MPL/
Software distributed under the License is distributed on an "AS IS"
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
License for the specific language governing rights and limitations
under the License.
The Original Code is ______________________________________.
The Initial Developer of the Original Code is ________________________.
Portions created by ______________________ are Copyright (C) ______
_______________________. All Rights Reserved.
Contributor(s): ______________________________________.''

View File

@@ -0,0 +1,173 @@
#############################################################################
# $Id: Makefile.PL,v 1.14 1999-01-21 23:52:42 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# The Makefile "source".
#
#############################################################################
use ExtUtils::MakeMaker;
use Config;
use Carp;
$perlpath = $Config{'perlpath'};
$osname = $Config{'osname'};
$ldapsdk_loc = $ENV{"LDAPSDKDIR"}; # Full Path to C SDK Top-Level
$ldapsdk_ssl = $ENV{"LDAPSDKSSL"}; # N to exclude SSL
$ldapsdk_ver = $ENV{"LDAPV3ON"}; # N to exclude LDAP v3 features
$libexts = "so|sl|a|lib";
print "\nPerLDAP - Perl 5 Module for LDAP\n";
print "================================\n";
$silent = 1;
print "Directory containing 'include' and 'lib' directory of the Netscape\n";
print "LDAP Software Developer Kit (default: /usr): ";
if (!$ldapsdk_loc)
{
$silent = 0;
chomp ($ldapsdk_loc = <STDIN>);
$ldapsdk_loc = "/usr" unless $ldapsdk_loc =~ /\S/;
} else {
print "$ldapsdk_loc\n";
}
croak("Directory $ldapsdk_loc does not exist!") unless -d $ldapsdk_loc;
if ($osname =~ /mswin/i)
{
$dir_sep = "\\";
} else {
$dir_sep = "/";
}
$include_ldap = $ldapsdk_loc . $dir_sep . "include";
$lib_ldap = $ldapsdk_loc . $dir_sep . "lib";
print "Using LDAPv3 Developer Kit (default: yes)? ";
if (!$ldapsdk_ver)
{
$silent = 0;
chomp ($ldapsdk_ver = <STDIN>);
} else {
print "YES\n";
}
$v3_def = "-DLDAPV3" unless ($ldapsdk_ver =~ /^n/i);
print "Include SSL Support (default: yes)? ";
if (!$ldapsdk_ssl)
{
$silent = 0;
chomp ($ldapsdk_ssl = <STDIN>);
} else {
print "YES\n";
}
$ssl_def = "-DUSE_SSL" unless ($ldapsdk_ssl =~ /^n/i);
opendir(DIR,$lib_ldap);
@files = grep{/ldap|lber/} readdir(DIR);
closedir(DIR);
if (!((@ldaplib = grep{/ldapssl.*\.($libexts)$/} @files) && $ssl_def))
{
@ldaplib = grep{/ldap.*\.($libexts)$/} @files;
@lberlib = grep{/lber.*\.($libexts)$/} @files;
}
if ($#ldaplib < 0)
{
die "No LDAP libraries found.";
}
if ($#ldaplib > 0)
{
print "Located multiple libraries:\n";
foreach $alib (@ldaplib)
{
print " - $alib\n";
}
}
$lline_ldap = $ldaplib[0];
$lline_ldap =~ s/^lib//;
$lline_ldap =~ s/\.($libexts)$//;
$lline = "-L$lib_ldap -l$lline_ldap";
if ($#lberlib >= 0 && $lline =~ /ldap$/)
{
$lline_lber = $lberlib[0];
$lline_lber =~ s/^lib//;
$lline_lber =~ s/\.($libexts)$//;
$lline .= " -l$lline_lber";
}
print "Libraries to link with (default: $lline): ";
if (!$silent)
{
chomp ($lib_line = <STDIN>);
$lib_line = $lline unless $lib_line =~ /\S/;
} else {
print "\n";
}
if ($osname =~ /mswin/i)
{
$myextlib = "$lib_ldap\\$ldaplib[0]";
if ($lber_lib)
{
$myextlib .= " $lib_ldap\\$lberlib[0]";
}
} else {
$myextlib = "";
}
@extras = ();
push(@extras,
CAPI => 'TRUE')
if ($] >= 5.005 and $^O eq 'MSWin32'
and $Config{archname} =~ /-object\b/i);
push(@extras,
ABSTRACT => 'Perl methods for LDAP C API calls',
AUTHOR => 'Netscape Communications Corp., Inc. and Clayton Donley')
if ($ExtUtils::MakeMaker::Version >= 5.4301);
WriteMakefile(
'NAME' => 'Mozilla::LDAP::API',
'DISTNAME' => 'PerLDAP',
'VERSION_FROM' => 'API.pm',
($include_ldap ne "/usr/include" ? (
'INC' => "-I$include_ldap",
) : (
'INC' => "",
)),
'LIBS' => [$lib_line],
'MYEXTLIB' => $myextlib,
'DEFINE' => "$v3_def $ssl_def",
'XSOPT' => "-nolinenumbers",
@extras
);

View File

@@ -0,0 +1,183 @@
#############################################################################
# #
# PerLDAP v1.0 - A Perl Developers' Kit for LDAP #
# #
#############################################################################
What is PerLDAP?
================
PerLDAP is a set of modules written in Perl and C that allow developers to
leverage their existing Perl knowledge to easily access and manage LDAP-
enabled directories. PerLDAP makes it very easy to search, add, delete,
and modify directory entries. For example, Perl developers can easily
build web applications to access information stored in a directory or
create directory sync tools between directories and other services.
PerLDAP is an open source development project, the result of a joint effort
between Netscape and Clayton Donley, an open source developer. PerLDAP
currently provides the basic functions to allow Perl users to access and
manipulate directories easily. Based on developer feedback and
involvement, PerLDAP will continue to evolve to include additional
functionality in future releases.
Installing PerLDAP Binaries
===========================
You will first need version 3.0 of the LDAP C SDK from Netscape. This is
available from the DevEdge page at:
http://developer.netscape.com/tech/directory/
You will also need Perl v5.004, available at http://www.perl.com/.
Earlier, or later, versions of Perl will NOT work with these binaries. If
you wish to use v5.005, you will need to compile PerLDAP from source.
On Unix (Solaris Only...HPUX, IRIX, AIX to follow):
1. Be sure that the libraries from the C SDK are installed in locations
referenced by the environment variable LD_LIBRARY_PATH, or one of the
default system lib directories (e.g. /usr/lib). Alternatively you can
later also copy the SDK libraries to the same "site" directory where
Perl installed the PerLDAP libraries.
2. Save the file in a temporary location
3. Unzip the file by entering the command:
gunzip <filename>.tar.gz
4. Untar the resulting tar file by entering the command:
tar xvof <filename>.tar
5. Change to the extract directory:
cd PerLDAP-1.1
6. Execute the following command in as the super-user (root):
perl install-bin
On Windows NT:
1. Put the LDAP C SDK DLL in the same directory as the perl.exe
binary. You can also set your PATH to point to the directory where you
have the C SDK installed. Alternatively, you can put the DLL in the
system32 folder, but avoid that if possible.
2. Save the file in a temporary location
3. Unzip the file by entering the command:
I don't have a tool for creating self-extracting archives...
4. Change to the extract directory:
cd PerLDAP-1.1
5. Execute the following command:
perl install-bin
Compiling the PerLDAP Sources
=============================
The source to PerLDAP is available on the Mozilla site at:
http://www.mozilla.org/directory/
You can either retrieve the .tar file with the source distribution, or use
CVS to checkout the module directly. The name of the CVS module is
PerLDAP, and it checks out the directory
mozilla/directory/perldap
Further instructions for using CVS and Mozilla is available at
http://www.mozilla.org/cvs.html
and an FAQ is at
http://www.mozilla.org/directory/faq/perldap-faq.html
Instructions for building the source can be found in the INSTALL file
in the source distribution.
Getting Started
===============
Documentation for this module is in standard Perl 'pod' format. HTML
versions of this documentation can also be found on the Netscape DevEdge
site at: http://developer.netscape.com/tech/directory/.
Additionally, many good examples can be found in the 'examples' directory.
Modules and Examples Included
=============================
Mozilla::LDAP::API - Low level interface between Perl and the LDAP C API
Mozilla::LDAP::Entry - Perl methods for manipulating entry objects
Mozilla::LDAP::Conn - Perl methods for performing LDAP operations
Mozilla::LDAP::LDIF - Perl methods for utilizing LDIF
Mozilla::LDAP::Utils - Some convenient LDAP related utilities
test_api/search.pl - Tests low level API search calls
test_api/write.pl - Tests low level API write calls
test_api/api.pl - Tests ALL low level LDAPv2 calls
examples/lfinger.pl - LDAP version of the regular Unix finger command.
examples/qsearch.pl - Simple ldapsearch replacement.
examples/monitor.pl - Retrieve status information from an LDAP server.
examples/ldappasswd.pl - Change the LDAP password for a user.
examples/rmentry.pl - Remove an entire entry from the database.
examples/rename.pl - Rename (modRDN) an entry.
examples/tabdump.pl - Dump LDAP information into a tab separated file.
examples/psoftsync.pl - Synchronize LDAP with a PeopleSoft "dump" file.
All examples support the "standard" LDAP command line options, which are
-h hostname LDAP server name
-p port # LDAP port, default is 389 (or 636 for SSL)
-b base DN LDAP Base-DN
-D bind DN LDAP bind DN (connect to server as this "user")
-w bind pswd Password to bind to the server
-P certfile Use SSL, with the publick keys from this file
Note that the examples currently only support Simple Authentication
(passwords), the Client Authentication features (using certificates) will
be used in the next release. All examples also honors the environment
variable LDAP_BASEDN, set it to your systems base DN, e.g.
% setenv LDAP_BASEDN 'dc=netscape,dc=com'
or for Bourne shell
# LDAP_BASEDN='dc=netscape,dc=com'; export LDAP_BASEDN
Reporting problems and bugs
===========================
Address all bug reports and comments to the Mozilla newsgroups at:
news://news.mozilla.org/netscape.public.mozilla.directory
License/Copyright
=================
Portions by Netscape (c) Copyright 1998 Netscape Communications Corp, Inc.
Portions by Clayton Donley (c) Copyright 1998 Clayton Donley
Please read the MPL-1.0.txt file included for information on the Mozilla
Public License, which covers all files in this distribution.
Known Bugs
==========
There are a number of issues still outstanding at the time of release. Most
of these are already in the process of being resolved.
- There is a possible memory leak in the search routines. The OO layer
is also more memory than it should.
- The Rebind operation on NT does NOT work properly when set to a Perl
function. This is being investigated.
- Some of the documentation is incomplete.

View File

@@ -0,0 +1,380 @@
#############################################################################
# $Id: Utils.pm,v 1.11 1999-01-21 23:52:43 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Lots of Useful Little Utilities, for LDAP related operations.
#
#############################################################################
package Mozilla::LDAP::Utils;
use Mozilla::LDAP::API qw(:constant);
use Mozilla::LDAP::Conn;
use vars qw(@ISA %EXPORT_TAGS);
require Exporter;
@ISA = qw(Exporter);
%EXPORT_TAGS = (
all => [qw(normalizeDN
isUrl
printEntry
printentry
encodeBase64
decodeBase64
str2Scope
askPassword
ldapArgs
unixCrypt
userCredentials
answer)]
);
# Add Everything in %EXPORT_TAGS to @EXPORT_OK
Exporter::export_ok_tags('all');
#############################################################################
# Normalize the DN string (first argument), and return the new, normalized,
# string (DN). This is useful to make sure that two syntactically
# identical DNs compare (eq) as the same string.
#
sub normalizeDN
{
my ($dn) = @_;
my (@vals);
return "" unless (defined($dn) && ($dn ne ""));
@vals = Mozilla::LDAP::API::ldap_explode_dn(lc $dn, 0);
return join(",", @vals);
}
#############################################################################
# Checks if a string is a properly formed LDAP URL.
#
sub isURL
{
return ldap_is_ldap_url($_[0]);
}
#############################################################################
# Print an entry, in LDIF format. This is sort of obsolete, we encourage
# you to use the :;LDAP::LDIF class instead.
#
sub printEntry
{
my $entry = $_[0];
my $attr;
local $_;
print "dn: ", $entry->{"dn"},"\n";
foreach $attr (@{$entry->{"_oc_order_"}})
{
next if ($attr =~ /^_.+_$/);
next if $entry->{"_${attr}_deleted_"};
foreach (@{$entry->{$attr}})
{
print "$attr: $_\n";
}
}
print "\n";
}
*printentry = \*printEntry;
#############################################################################
# Perform Base64 encoding, this is based on MIME::Base64.pm, written
# by Gisle Aas <gisle@aas.no>. If possible, use the MIME:: package instead.
#
sub encodeBase64
{
my $res = "";
my $eol = "$_[1]";
my $padding;
pos($_[0]) = 0; # ensure start at the beginning
while ($_[0] =~ /(.{1,45})/gs) {
$res .= substr(pack('u', $1), 1);
chop($res);
}
$res =~ tr|` -_|AA-Za-z0-9+/|; # `# help emacs
$padding = (3 - length($_[0]) % 3) % 3;
$res =~ s/.{$padding}$/'=' x $padding/e if $padding;
if (length $eol) {
$res =~ s/(.{1,76})/$1$eol/g;
}
return $res;
}
#############################################################################
# Perform Base64 decoding, this is based on MIME::Base64.pm, written
# by Gisle Aas <gisle@aas.no>. If possible, use the MIME:: package instead.
#
sub decodeBase64
{
my $str = shift;
my $res = "";
my $len;
$str =~ tr|A-Za-z0-9+=/||cd;
Carp::croak("Base64 decoder requires string length to be a multiple of 4")
if length($str) % 4;
$str =~ s/=+$//; # remove padding
$str =~ tr|A-Za-z0-9+/| -_|; # convert to uuencoded format
while ($str =~ /(.{1,60})/gs)
{
$len = chr(32 + length($1)*3/4);
$res .= unpack("u", $len . $1 ); # uudecode
}
return $res;
}
#############################################################################
# Convert a "human" readable string to an LDAP scope value
#
sub str2Scope
{
my $str = $_[0];
return $str if ($str =~ /^[0-9]+$/);
if ($str =~ /^sub/i)
{
return LDAP_SCOPE_SUBTREE;
}
elsif ($str =~ /^base/i)
{
return LDAP_SCOPE_BASE;
}
elsif ($str =~ /^one/i)
{
return LDAP_SCOPE_ONELEVEL;
}
# Default...
return LDAP_SCOPE_SUBTREE;
}
#############################################################################
# Ask for a password, without displaying it on the TTY.
#
sub askPassword
{
my $prompt = $_[0];
my $hasReadKey = 0;
eval "use Term::ReadKey";
$hasReadKey=1 unless ($@);
print "LDAP password: " if $prompt;
if ($hasReadKey)
{
ReadMode(2);
chop($_ = ReadLine(0));
ReadMode(0);
}
else
{
system('/bin/stty -echo');
chop($_ = <STDIN>);
system('/bin/stty echo');
}
print "\n";
return $_;
}
#############################################################################
# Handle some standard LDAP options, and construct a nice little structure
# that we can use later on. We really should have some appropriate defaults,
# perhaps from an Mozilla::LDAP::Config module.
#
sub ldapArgs
{
my ($bind, $base) = @_;
my %ld;
$main::opt_v = $main::opt_n if defined($main::opt_n);
$main::opt_p = LDAPS_PORT if (!defined($main::opt_p) &&
defined($main::opt_P) &&
($main::opt_P ne ""));
$ld{"host"} = $main::opt_h || "ldap";
$ld{"port"} = $main::opt_p || LDAP_PORT;
$ld{"root"} = $main::opt_b || $base || $ENV{'LDAP_BASEDN'};
$ld{"bind"} = $main::opt_D || $bind || "";
$ld{"pswd"} = $main::opt_w || "";
$ld{"cert"} = $main::opt_P || "";
$ld{"scope"} = (defined($main::opt_s) ? $main::opt_s : LDAP_SCOPE_SUBTREE);
if (($ld{"bind"} ne "") && ($ld{"pswd"} eq ""))
{
$ld{pswd} = askPassword(1);
}
return %ld;
}
#############################################################################
# Create a Unix-type password, using the "crypt" function. A random salt
# is always generated, perhaps it should be an optional argument?
#
sub unixCrypt
{
my $ascii =
"./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
my $salt = substr($ascii, rand(62), 1) . substr($ascii, rand(62), 1);
srand(time ^ $$);
crypt($_[0], $salt);
}
#############################################################################
# Try to find a user to bind as, and possibly ask for the password. Pass
# a pointer to the hash array with LDAP parameters to this function.
#
sub userCredentials
{
my ($ld) = @_;
my ($conn, $entry, $pswd);
if ($ld->{"bind"} eq "")
{
$conn = new Mozilla::LDAP::Conn($ld);
die "Could't connect to LDAP server " . $ld->{"host"} unless $conn;
$search = "(&(objectclass=inetOrgPerson)(uid=$ENV{USER}))";
$entry = $conn->search($ld->{"root"}, "subtree", $search, 0, ("uid"));
return 0 if (!$entry || $conn->nextEntry());
$conn->close();
$ld->{"bind"} = $entry->getDN();
}
if ($ld->{"pswd"} eq "")
{
$ld->{"pswd"} = Mozilla::LDAP::Utils::askPassword(1);
}
}
#############################################################################
# Ask a Y/N question, return "Y" or "N".
#
sub answer
{
die "Default string must be Y or N."
unless (($_[0] eq "Y") || ($_[0] eq "N"));
chop($_ = <STDIN>);
return $_[0] if /^$/;
return "Y" if /^[yY]/;
return "N" if /^[nN]/;
}
#############################################################################
# Mandatory TRUE return value.
#
1;
#############################################################################
# POD documentation...
#
__END__
=head1 NAME
Mozilla::LDAP::Utils.pm - Collection of useful little utilities.
=head1 SYNOPSIS
use Mozilla::LDAP::Utils;
=head1 ABSTRACT
=head1 DESCRIPTION
=head1 OBJECT CLASS METHODS
=over 13
=item B<normalizeDN>
This function will remove all extraneous white spaces in the DN, and also
change all upper case characters to lower case. The only argument is the
DN string to normalize, and the return value is the new, clean DN.
=back
=head1 EXAMPLES
There are plenty of examples to look at, in the examples directory. We are
adding more examples every day (almost).
=head1 INSTALLATION
Installing this package is part of the Makefile supplied in the
package. See the installation procedures which are part of this package.
=head1 AVAILABILITY
This package can be retrieved from a number of places, including:
http://www.mozilla.org/directory/
Your local CPAN server
=head1 CREDITS
Most of this code was developed by Leif Hedstrom, Netscape Communications
Corporation.
=head1 BUGS
None. :)
=head1 SEE ALSO
L<Mozilla::LDAP::Conn>, L<Mozilla::LDAP::Entry>, L<Mozilla::LDAP::API>, and
of course L<Perl>.
=cut

View File

@@ -0,0 +1,954 @@
/*
*******************************************************************************
* $Id: constant.h,v 1.7 1998-08-13 09:14:14 leif Exp $
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.0 (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 PerLDAP. The Initial Developer of the Original
* Code is Netscape Communications Corp. and Clayton Donley. Portions
* created by Netscape are Copyright (C) Netscape Communications
* Corp., portions created by Clayton Donley are Copyright (C) Clayton
* Donley. All Rights Reserved.
*
* Contributor(s):
*
* DESCRIPTION
* Constants.
*
*******************************************************************************/
#ifdef __cplusplus
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
#ifdef __cplusplus
}
#endif
#include <ldap.h>
static int
not_here(s)
char *s;
{
croak("%s not implemented on this architecture", s);
return -1;
}
double
constant(name, arg)
char *name;
int arg;
{
errno = 0;
if (name[0] == 'L' && name[1] == 'D' && name[2] == 'A' && name[3] == 'P'
&& name[4] == '_')
{
switch (name[5]) {
case 'A':
if (strEQ(name, "LDAP_ADMINLIMIT_EXCEEDED"))
#ifdef LDAP_ADMINLIMIT_EXCEEDED
return LDAP_ADMINLIMIT_EXCEEDED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_AFFECTS_MULTIPLE_DSAS"))
#ifdef LDAP_AFFECTS_MULTIPLE_DSAS
return LDAP_AFFECTS_MULTIPLE_DSAS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_ALIAS_DEREF_PROBLEM"))
#ifdef LDAP_ALIAS_DEREF_PROBLEM
return LDAP_ALIAS_DEREF_PROBLEM;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_ALIAS_PROBLEM"))
#ifdef LDAP_ALIAS_PROBLEM
return LDAP_ALIAS_PROBLEM;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_ALREADY_EXISTS"))
#ifdef LDAP_ALREADY_EXISTS
return LDAP_ALREADY_EXISTS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_AUTH_METHOD_NOT_SUPPORTED"))
#ifdef LDAP_AUTH_METHOD_NOT_SUPPORTED
return LDAP_AUTH_METHOD_NOT_SUPPORTED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_AUTH_NONE"))
#ifdef LDAP_AUTH_NONE
return LDAP_AUTH_NONE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_AUTH_SASL"))
#ifdef LDAP_AUTH_SASL
return LDAP_AUTH_SASL;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_AUTH_SIMPLE"))
#ifdef LDAP_AUTH_SIMPLE
return LDAP_AUTH_SIMPLE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_AUTH_UNKNOWN"))
#ifdef LDAP_AUTH_UNKNOWN
return LDAP_AUTH_UNKNOWN;
#else
goto not_there;
#endif
break;
case 'B':
if (strEQ(name, "LDAP_BUSY"))
#ifdef LDAP_BUSY
return LDAP_BUSY;
#else
goto not_there;
#endif
break;
case 'C':
if (strEQ(name, "LDAP_CACHE_CHECK"))
#ifdef LDAP_CACHE_CHECK
return LDAP_CACHE_CHECK;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CACHE_LOCALDB"))
#ifdef LDAP_CACHE_LOCALDB
return LDAP_CACHE_LOCALDB;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CACHE_POPULATE"))
#ifdef LDAP_CACHE_POPULATE
return LDAP_CACHE_POPULATE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CHANGETYPE_ADD"))
#ifdef LDAP_CHANGETYPE_ADD
return LDAP_CHANGETYPE_ADD;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CHANGETYPE_ANY"))
#ifdef LDAP_CHANGETYPE_ANY
return LDAP_CHANGETYPE_ANY;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CHANGETYPE_DELETE"))
#ifdef LDAP_CHANGETYPE_DELETE
return LDAP_CHANGETYPE_DELETE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CHANGETYPE_MODDN"))
#ifdef LDAP_CHANGETYPE_MODDN
return LDAP_CHANGETYPE_MODDN;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CHANGETYPE_MODIFY"))
#ifdef LDAP_CHANGETYPE_MODIFY
return LDAP_CHANGETYPE_MODIFY;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CLIENT_LOOP"))
#ifdef LDAP_CLIENT_LOOP
return LDAP_CLIENT_LOOP;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_COMPARE_FALSE"))
#ifdef LDAP_COMPARE_FALSE
return LDAP_COMPARE_FALSE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_COMPARE_TRUE"))
#ifdef LDAP_COMPARE_TRUE
return LDAP_COMPARE_TRUE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CONFIDENTIALITY_REQUIRED"))
#ifdef LDAP_CONFIDENTIALITY_REQUIRED
return LDAP_CONFIDENTIALITY_REQUIRED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CONNECT_ERROR"))
#ifdef LDAP_CONNECT_ERROR
return LDAP_CONNECT_ERROR;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_CONSTRAINT_VIOLATION"))
#ifdef LDAP_CONSTRAINT_VIOLATION
return LDAP_CONSTRAINT_VIOLATION;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_DECODING_ERROR"))
#ifdef LDAP_DECODING_ERROR
return LDAP_DECODING_ERROR;
#else
goto not_there;
#endif
break;
case 'D':
if (strEQ(name, "LDAP_DEREF_ALWAYS"))
#ifdef LDAP_DEREF_ALWAYS
return LDAP_DEREF_ALWAYS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_DEREF_FINDING"))
#ifdef LDAP_DEREF_FINDING
return LDAP_DEREF_FINDING;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_DEREF_NEVER"))
#ifdef LDAP_DEREF_NEVER
return LDAP_DEREF_NEVER;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_DEREF_SEARCHING"))
#ifdef LDAP_DEREF_SEARCHING
return LDAP_DEREF_SEARCHING;
#else
goto not_there;
#endif
break;
case 'E':
if (strEQ(name, "LDAP_ENCODING_ERROR"))
#ifdef LDAP_ENCODING_ERROR
return LDAP_ENCODING_ERROR;
#else
goto not_there;
#endif
break;
case 'F':
if (strEQ(name, "LDAP_FILTER_ERROR"))
#ifdef LDAP_FILTER_ERROR
return LDAP_FILTER_ERROR;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_FILT_MAXSIZ"))
#ifdef LDAP_FILT_MAXSIZ
return LDAP_FILT_MAXSIZ;
#else
goto not_there;
#endif
break;
case 'I':
if (strEQ(name, "LDAP_INAPPROPRIATE_AUTH"))
#ifdef LDAP_INAPPROPRIATE_AUTH
return LDAP_INAPPROPRIATE_AUTH;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_INAPPROPRIATE_MATCHING"))
#ifdef LDAP_INAPPROPRIATE_MATCHING
return LDAP_INAPPROPRIATE_MATCHING;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_INSUFFICIENT_ACCESS"))
#ifdef LDAP_INSUFFICIENT_ACCESS
return LDAP_INSUFFICIENT_ACCESS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_INVALID_CREDENTIALS"))
#ifdef LDAP_INVALID_CREDENTIALS
return LDAP_INVALID_CREDENTIALS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_INVALID_DN_SYNTAX"))
#ifdef LDAP_INVALID_DN_SYNTAX
return LDAP_INVALID_DN_SYNTAX;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_INVALID_SYNTAX"))
#ifdef LDAP_INVALID_SYNTAX
return LDAP_INVALID_SYNTAX;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_IS_LEAF"))
#ifdef LDAP_IS_LEAF
return LDAP_IS_LEAF;
#else
goto not_there;
#endif
break;
case 'L':
if (strEQ(name, "LDAP_LOCAL_ERROR"))
#ifdef LDAP_LOCAL_ERROR
return LDAP_LOCAL_ERROR;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_LOOP_DETECT"))
#ifdef LDAP_LOOP_DETECT
return LDAP_LOOP_DETECT;
#else
goto not_there;
#endif
break;
case 'M':
if (strEQ(name, "LDAP_MOD_ADD"))
#ifdef LDAP_MOD_ADD
return LDAP_MOD_ADD;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_MOD_BVALUES"))
#ifdef LDAP_MOD_BVALUES
return LDAP_MOD_BVALUES;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_MOD_DELETE"))
#ifdef LDAP_MOD_DELETE
return LDAP_MOD_DELETE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_MOD_REPLACE"))
#ifdef LDAP_MOD_REPLACE
return LDAP_MOD_REPLACE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_MORE_RESULTS_TO_RETURN"))
#ifdef LDAP_MORE_RESULTS_TO_RETURN
return LDAP_MORE_RESULTS_TO_RETURN;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_MSG_ALL"))
#ifdef LDAP_MSG_ALL
return LDAP_MSG_ALL;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_MSG_ONE"))
#ifdef LDAP_MSG_ONE
return LDAP_MSG_ONE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_MSG_RECEIVED"))
#ifdef LDAP_MSG_RECEIVED
return LDAP_MSG_RECEIVED;
#else
goto not_there;
#endif
break;
case 'N':
if (strEQ(name, "LDAP_NAMING_VIOLATION"))
#ifdef LDAP_NAMING_VIOLATION
return LDAP_NAMING_VIOLATION;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NOT_ALLOWED_ON_NONLEAF"))
#ifdef LDAP_NOT_ALLOWED_ON_NONLEAF
return LDAP_NOT_ALLOWED_ON_NONLEAF;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NOT_ALLOWED_ON_RDN"))
#ifdef LDAP_NOT_ALLOWED_ON_RDN
return LDAP_NOT_ALLOWED_ON_RDN;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NOT_SUPPORTED"))
#ifdef LDAP_NOT_SUPPORTED
return LDAP_NOT_SUPPORTED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NO_LIMIT"))
#ifdef LDAP_NO_LIMIT
return LDAP_NO_LIMIT;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NO_MEMORY"))
#ifdef LDAP_NO_MEMORY
return LDAP_NO_MEMORY;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NO_OBJECT_CLASS_MODS"))
#ifdef LDAP_NO_OBJECT_CLASS_MODS
return LDAP_NO_OBJECT_CLASS_MODS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NO_RESULTS_RETURNED"))
#ifdef LDAP_NO_RESULTS_RETURNED
return LDAP_NO_RESULTS_RETURNED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NO_SUCH_ATTRIBUTE"))
#ifdef LDAP_NO_SUCH_ATTRIBUTE
return LDAP_NO_SUCH_ATTRIBUTE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_NO_SUCH_OBJECT"))
#ifdef LDAP_NO_SUCH_OBJECT
return LDAP_NO_SUCH_OBJECT;
#else
goto not_there;
#endif
break;
case 'O':
if (strEQ(name, "LDAP_OBJECT_CLASS_VIOLATION"))
#ifdef LDAP_OBJECT_CLASS_VIOLATION
return LDAP_OBJECT_CLASS_VIOLATION;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPERATIONS_ERROR"))
#ifdef LDAP_OPERATIONS_ERROR
return LDAP_OPERATIONS_ERROR;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_CACHE_ENABLE"))
#ifdef LDAP_OPT_CACHE_ENABLE
return LDAP_OPT_CACHE_ENABLE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_CACHE_FN_PTRS"))
#ifdef LDAP_OPT_CACHE_FN_PTRS
return LDAP_OPT_CACHE_FN_PTRS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_CACHE_STRATEGY"))
#ifdef LDAP_OPT_CACHE_STRATEGY
return LDAP_OPT_CACHE_STRATEGY;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_CLIENT_CONTROLS"))
#ifdef LDAP_OPT_CLIENT_CONTROLS
return LDAP_OPT_CLIENT_CONTROLS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_DEREF"))
#ifdef LDAP_OPT_DEREF
return LDAP_OPT_DEREF;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_DESC"))
#ifdef LDAP_OPT_DESC
return LDAP_OPT_DESC;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_DNS"))
#ifdef LDAP_OPT_DNS
return LDAP_OPT_DNS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_DNS_FN_PTRS"))
#ifdef LDAP_OPT_DNS_FN_PTRS
return LDAP_OPT_DNS_FN_PTRS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_ERROR_NUMBER"))
#ifdef LDAP_OPT_ERROR_NUMBER
return LDAP_OPT_ERROR_NUMBER;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_ERROR_STRING"))
#ifdef LDAP_OPT_ERROR_STRING
return LDAP_OPT_ERROR_STRING;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_HOST_NAME"))
#ifdef LDAP_OPT_HOST_NAME
return LDAP_OPT_HOST_NAME;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_IO_FN_PTRS"))
#ifdef LDAP_OPT_IO_FN_PTRS
return LDAP_OPT_IO_FN_PTRS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_MEMALLOC_FN_PTRS"))
#ifdef LDAP_OPT_MEMALLOC_FN_PTRS
return LDAP_OPT_MEMALLOC_FN_PTRS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_PREFERRED_LANGUAGE"))
#ifdef LDAP_OPT_PREFERRED_LANGUAGE
return LDAP_OPT_PREFERRED_LANGUAGE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_PROTOCOL_VERSION"))
#ifdef LDAP_OPT_PROTOCOL_VERSION
return LDAP_OPT_PROTOCOL_VERSION;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_REBIND_ARG"))
#ifdef LDAP_OPT_REBIND_ARG
return LDAP_OPT_REBIND_ARG;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_REBIND_FN"))
#ifdef LDAP_OPT_REBIND_FN
return LDAP_OPT_REBIND_FN;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_RECONNECT"))
#ifdef LDAP_OPT_RECONNECT
return LDAP_OPT_RECONNECT;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_REFERRALS"))
#ifdef LDAP_OPT_REFERRALS
return LDAP_OPT_REFERRALS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_REFERRAL_HOP_LIMIT"))
#ifdef LDAP_OPT_REFERRAL_HOP_LIMIT
return LDAP_OPT_REFERRAL_HOP_LIMIT;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_RESTART"))
#ifdef LDAP_OPT_RESTART
return LDAP_OPT_RESTART;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_RETURN_REFERRALS"))
#ifdef LDAP_OPT_RETURN_REFERRALS
return LDAP_OPT_RETURN_REFERRALS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_SERVER_CONTROLS"))
#ifdef LDAP_OPT_SERVER_CONTROLS
return LDAP_OPT_SERVER_CONTROLS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_SIZELIMIT"))
#ifdef LDAP_OPT_SIZELIMIT
return LDAP_OPT_SIZELIMIT;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_SSL"))
#ifdef LDAP_OPT_SSL
return LDAP_OPT_SSL;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_THREAD_FN_PTRS"))
#ifdef LDAP_OPT_THREAD_FN_PTRS
return LDAP_OPT_THREAD_FN_PTRS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OPT_TIMELIMIT"))
#ifdef LDAP_OPT_TIMELIMIT
return LDAP_OPT_TIMELIMIT;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_OTHER"))
#ifdef LDAP_OTHER
return LDAP_OTHER;
#else
goto not_there;
#endif
break;
case 'P':
if (strEQ(name, "LDAP_PARAM_ERROR"))
#ifdef LDAP_PARAM_ERROR
return LDAP_PARAM_ERROR;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_PARTIAL_RESULTS"))
#ifdef LDAP_PARTIAL_RESULTS
return LDAP_PARTIAL_RESULTS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_PORT"))
#ifdef LDAP_PORT
return LDAP_PORT;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_PORT_MAX"))
#ifdef LDAP_PORT_MAX
return LDAP_PORT_MAX;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_PROTOCOL_ERROR"))
#ifdef LDAP_PROTOCOL_ERROR
return LDAP_PROTOCOL_ERROR;
#else
goto not_there;
#endif
break;
case 'R':
if (strEQ(name, "LDAP_REFERRAL"))
#ifdef LDAP_REFERRAL
return LDAP_REFERRAL;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_REFERRAL_LIMIT_EXCEEDED"))
#ifdef LDAP_REFERRAL_LIMIT_EXCEEDED
return LDAP_REFERRAL_LIMIT_EXCEEDED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RESULTS_TOO_LARGE"))
#ifdef LDAP_RESULTS_TOO_LARGE
return LDAP_RESULTS_TOO_LARGE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_ADD"))
#ifdef LDAP_RES_ADD
return LDAP_RES_ADD;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_ANY"))
#ifdef LDAP_RES_ANY
return LDAP_RES_ANY;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_BIND"))
#ifdef LDAP_RES_BIND
return LDAP_RES_BIND;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_COMPARE"))
#ifdef LDAP_RES_COMPARE
return LDAP_RES_COMPARE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_DELETE"))
#ifdef LDAP_RES_DELETE
return LDAP_RES_DELETE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_EXTENDED"))
#ifdef LDAP_RES_EXTENDED
return LDAP_RES_EXTENDED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_MODIFY"))
#ifdef LDAP_RES_MODIFY
return LDAP_RES_MODIFY;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_MODRDN"))
#ifdef LDAP_RES_MODRDN
return LDAP_RES_MODRDN;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_RENAME"))
#ifdef LDAP_RES_RENAME
return LDAP_RES_RENAME;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_SEARCH_ENTRY"))
#ifdef LDAP_RES_SEARCH_ENTRY
return LDAP_RES_SEARCH_ENTRY;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_SEARCH_REFERENCE"))
#ifdef LDAP_RES_SEARCH_REFERENCE
return LDAP_RES_SEARCH_REFERENCE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_RES_SEARCH_RESULT"))
#ifdef LDAP_RES_SEARCH_RESULT
return LDAP_RES_SEARCH_RESULT;
#else
goto not_there;
#endif
break;
case 'S':
if (strEQ(name, "LDAP_SASL_BIND_IN_PROGRESS"))
#ifdef LDAP_SASL_BIND_IN_PROGRESS
return LDAP_SASL_BIND_IN_PROGRESS;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SASL_SIMPLE"))
#ifdef LDAP_SASL_SIMPLE
return LDAP_SASL_SIMPLE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SCOPE_BASE"))
#ifdef LDAP_SCOPE_BASE
return LDAP_SCOPE_BASE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SCOPE_ONELEVEL"))
#ifdef LDAP_SCOPE_ONELEVEL
return LDAP_SCOPE_ONELEVEL;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SCOPE_SUBTREE"))
#ifdef LDAP_SCOPE_SUBTREE
return LDAP_SCOPE_SUBTREE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SECURITY_NONE"))
#ifdef LDAP_SECURITY_NONE
return LDAP_SECURITY_NONE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SERVER_DOWN"))
#ifdef LDAP_SERVER_DOWN
return LDAP_SERVER_DOWN;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SIZELIMIT_EXCEEDED"))
#ifdef LDAP_SIZELIMIT_EXCEEDED
return LDAP_SIZELIMIT_EXCEEDED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SORT_CONTROL_MISSING"))
#ifdef LDAP_SORT_CONTROL_MISSING
return LDAP_SORT_CONTROL_MISSING;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_STRONG_AUTH_NOT_SUPPORTED"))
#ifdef LDAP_STRONG_AUTH_NOT_SUPPORTED
return LDAP_STRONG_AUTH_NOT_SUPPORTED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_STRONG_AUTH_REQUIRED"))
#ifdef LDAP_STRONG_AUTH_REQUIRED
return LDAP_STRONG_AUTH_REQUIRED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_SUCCESS"))
#ifdef LDAP_SUCCESS
return LDAP_SUCCESS;
#else
goto not_there;
#endif
break;
case 'T':
if (strEQ(name, "LDAP_TIMELIMIT_EXCEEDED"))
#ifdef LDAP_TIMELIMIT_EXCEEDED
return LDAP_TIMELIMIT_EXCEEDED;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_TIMEOUT"))
#ifdef LDAP_TIMEOUT
return LDAP_TIMEOUT;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_TYPE_OR_VALUE_EXISTS"))
#ifdef LDAP_TYPE_OR_VALUE_EXISTS
return LDAP_TYPE_OR_VALUE_EXISTS;
#else
goto not_there;
#endif
break;
case 'U':
if (strEQ(name, "LDAP_UNAVAILABLE"))
#ifdef LDAP_UNAVAILABLE
return LDAP_UNAVAILABLE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_UNAVAILABLE_CRITICAL_EXTENSION"))
#ifdef LDAP_UNAVAILABLE_CRITICAL_EXTENSION
return LDAP_UNAVAILABLE_CRITICAL_EXTENSION;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_UNDEFINED_TYPE"))
#ifdef LDAP_UNDEFINED_TYPE
return LDAP_UNDEFINED_TYPE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_UNWILLING_TO_PERFORM"))
#ifdef LDAP_UNWILLING_TO_PERFORM
return LDAP_UNWILLING_TO_PERFORM;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_URL_ERR_BADSCOPE"))
#ifdef LDAP_URL_ERR_BADSCOPE
return LDAP_URL_ERR_BADSCOPE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_URL_ERR_MEM"))
#ifdef LDAP_URL_ERR_MEM
return LDAP_URL_ERR_MEM;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_URL_ERR_NODN"))
#ifdef LDAP_URL_ERR_NODN
return LDAP_URL_ERR_NODN;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_URL_ERR_NOTLDAP"))
#ifdef LDAP_URL_ERR_NOTLDAP
return LDAP_URL_ERR_NOTLDAP;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_URL_ERR_PARAM"))
#ifdef LDAP_URL_ERR_PARAM
return LDAP_URL_ERR_PARAM;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_URL_OPT_SECURE"))
#ifdef LDAP_URL_OPT_SECURE
return LDAP_URL_OPT_SECURE;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_USER_CANCELLED"))
#ifdef LDAP_USER_CANCELLED
return LDAP_USER_CANCELLED;
#else
goto not_there;
#endif
break;
case 'V':
if (strEQ(name, "LDAP_VERSION"))
#ifdef LDAP_VERSION
return LDAP_VERSION;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_VERSION1"))
#ifdef LDAP_VERSION1
return LDAP_VERSION1;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_VERSION2"))
#ifdef LDAP_VERSION2
return LDAP_VERSION2;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_VERSION3"))
#ifdef LDAP_VERSION3
return LDAP_VERSION3;
#else
goto not_there;
#endif
if (strEQ(name, "LDAP_VERSION_MAX"))
#ifdef LDAP_VERSION_MAX
return LDAP_VERSION_MAX;
#else
goto not_there;
#endif
break;
}
} else {
if (strEQ(name, "LDAPS_PORT"))
#ifdef LDAPS_PORT
return LDAPS_PORT;
#else
goto not_there;
#endif
}
errno = EINVAL;
return 0;
not_there:
errno = ENOENT;
return 0;
}

View File

@@ -0,0 +1,31 @@
1999-01-05 Leif Hedstrom <leif@netscape.com>
* psoftsync.pl (delAttr): Fixed annoying bug where I missed to
"my" $entry.
1999-01-04 Leif Hedstrom <leif@netscape.com>
* modattr.pl: Bug fixes for handling bad cases better (like
missing attribute, adding empty values etc).
1998-12-11 Leif Hedstrom <leif@netscape.com>
* modattr.pl: Modified slightly to enable the rebind proc.
1998-08-03 Leif Hedstrom <leif@netscape.com>
* psoftsync.pl: New file, also merged in some modules from
LdapUtils.pm, to make sure this works. NOTE: This script currently
doesn't work, since all "modify" operations are horked.
1998-07-30 Leif Hedstrom <leif@netscape.com>
* tabdump.pl: Actually works!
* ldappasswd.pl: Cleaned out some code, and moved it over to the
::Utils module.
1998-07-29 Leif Hedstrom <leif@netscape.com>
* qsearch.pl: First working version.

View File

@@ -0,0 +1,118 @@
#!/usr/bin/perl5
#############################################################################
# $Id: changes2ldif.pl,v 1.2 1999-01-21 23:52:46 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Search the changelog, and produce an LDIF file suitable for ldapmodify
# for instance. This should be merged into LDIF.pm eventually.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
use strict;
no strict "vars";
#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "changes2ldif";
$USAGE = "$APPNAM [-nv] -b base -h host -D bind -w pswd -P cert [min [max]]";
#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('nvb:h:D:p:s:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
$ld{root} = "cn=changelog" if (!defined($ld{root}) || $ld{root} eq "");
#################################################################################
# Instantiate an LDAP object, which also binds to the LDAP server.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
#################################################################################
# Create the search filter.
#
$min = $ARGV[$[];
$max = $ARGV[$[ + 1];
if ($min ne "")
{
if ($max ne "")
{
$search = "(&(changenumber>=$min)(changenumber<=$max))";
}
else
{
$search = "(changenumber>=$min)";
}
}
else
{
$search = "(changenumber=*)";
}
#################################################################################
# Do the searches, and print the results.
#
$entry = $conn->search($ld{root}, "ONE", "$search");
while ($entry)
{
print "dn: ", $entry->{targetdn}[0], "\n";
$type = $entry->{changetype}[0];
print "changetype: $type\n";
if ($type =~ /modify/i)
{
# Should we filter out modifiersname and modifytimestamp ? We do chop
# off the trailing \0 though.
chop($entry->{changes}[0]);
print $entry->{changes}[0], "\n";
}
elsif ($type =~ /add/i)
{
print $entry->{changes}[0], "\n";
}
else
{
print "\n";
}
$entry = $conn->nextEntry;
}
#################################################################################
# Close the connection.
#
$ld{conn}->close if $ld{conn};

View File

@@ -0,0 +1,104 @@
#!/usr/bin/perl5
#############################################################################
# $Id: ldappasswd.pl,v 1.6 1998-08-13 09:13:23 leif Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# This is an LDAP version of the normal passwd/yppasswd command found
# on most Unix systems. Note that this will only use the {crypt}
# encryption/hash algorithm (at this point).
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
#############################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "ldappasswd";
$USAGE = "$APPNAM [-nv] -b base -h host -D bind -w pswd -P cert search ...";
@ATTRIBUTES = ("uid", "userpassword");
#############################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('nvb:s:h:D:w:P:')) {
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
Mozilla::LDAP::Utils::userCredentials(\%ld) unless $opt_n;
#############################################################################
# Ask for the new password, and confirm it's correct.
#
do
{
print "New password: ";
$new = Mozilla::LDAP::Utils::askPassword();
print "New password (again): ";
$new2 = Mozilla::LDAP::Utils::askPassword();
print "Passwords didn't match, try again!\n\n" if ($new ne $new2);
} until ($new eq $new2);
print "\n";
$crypted = Mozilla::LDAP::Utils::unixCrypt("$new");
#############################################################################
# Now do all the searches, one by one. If there are no search criteria, we
# will change the password for the user running the script.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
foreach $search ($#ARGV >= $[ ? @ARGV : $ld{bind})
{
$entry = $conn->search($search, "subtree", "ALL", 0, @ATTRIBUTES);
$entry = $conn->search($ld{root}, "subtree", $search, 0, @ATTRIBUTES)
unless $entry;
print "No such user: $search\n" unless $entry;
while ($entry)
{
$entry->{userpassword} = ["{crypt}" . $crypted];
print "Changing password for: $entry->{dn}\n" if $opt_v;
if (!$opt_n)
{
$conn->update($entry);
$conn->printError() if $conn->getErrorCode();
}
$entry = $conn->nextEntry();
}
}
#############################################################################
# Close the connection.
#
$conn->close if $conn;

View File

@@ -0,0 +1,128 @@
#!/usr/bin/perl5
#############################################################################
# $Id: lfinger.pl,v 1.10 1998-08-13 09:13:08 leif Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# "finger" version using LDAP information (using RFC 2307 objectclass).
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
#############################################################################
# Constants, shouldn't have to edit these... The HIDE mechanism is a very
# Netscape internal specific feature. We use this objectclass to mark some
# entries to be "hidden", and some of our applications will honor this. With
# more recent versions of the Directory Server this can be accomplished more
# effectively with appropriate ACI/ACLs.
#
$APPNAM = "lfinger";
$USAGE = "$APPNAM -m -b base -h host -D bind -w pswd -P cert user_info";
@ATTRIBUTES = ("uid", "cn", "homedirectory", "loginshell", "pager",
"telephonenumber", "facsimiletelephonenumber", "mobile");
$HIDE = "(objectclass=nscphidethis)";
#############################################################################
# Print a "finger" entry.
#
sub printIt
{
my($entry) = @_;
print "Login name: $entry->{uid}[0]";
print " " x (39 - 11 - length($entry->{uid}[0]));
print "In real life: $entry->{cn}[0]\n";
if ($entry->{homedirectory}[0] || $entry->{loginshell}[0])
{
print "Directory: $entry->{homedirectory}[0]";
print " " x (39 - 10 - length($entry->{homedirectory}[0]));
print "Shell: $entry->{loginshell}[0]\n";
}
if ($entry->{telephonenumber}[0] || $entry->{pager}[0])
{
print "Phone: $entry->{telephonenumber}[0]";
print " " x (39 - 6 - length($entry->{telephonenumber}[0]));
print "Pager: $entry->{pager}[0]\n";
}
if ($entry->{mobile}[0] || $entry->{facsimiletelephonenumber}[0])
{
print "Mobile: $entry->{mobile}[0]";
print " " x (39 - 7 - length($entry->{mobile}[0]));
print "Fax: $entry->{facsimiletelephonenumber}[0]\n";
}
print "\n";
}
#############################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('mb:h:D:p:w:P:') || !defined($ARGV[$[]))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
$user=$ARGV[$[];
#############################################################################
# Instantiate an LDAP object, which also binds to the LDAP server.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
#############################################################################
# Ok, lets generate the filter, and do the search!
#
if ($opt_m)
{
$search = "(&(uid=$user)(!$HIDE))";
}
else
{
$search = "(&(|(cn=*$user*)(uid=*$user*)(telephonenumber=*$user*))(!$HIDE))";
}
$entry = $conn->search($ld{root}, "subtree", $search, 0, @ATTRIBUTES);
$conn->printError() if $conn->getErrorCode();
while($entry)
{
printIt($entry);
$entry = $conn->nextEntry();
}
#############################################################################
# Close the connection.
#
$conn->close if $conn;

View File

@@ -0,0 +1,331 @@
#!/usr/bin/perl5
#############################################################################
# $Id: modattr.pl,v 1.8 1999-01-21 23:52:46 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# This script can be used to do a number of different modification
# operations on a script. Like adding/deleting values, or entire
# attributes.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
use strict;
no strict "vars";
#############################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "modattr";
$USAGE = "$APPNAM [-dnvW] -b base -h host -D bind -w pswd -P cert attr=value filter";
#############################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('adnvWb:h:D:p:s:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
Mozilla::LDAP::Utils::userCredentials(\%ld) unless $opt_n;
#############################################################################
# Let's process the changes requested, and commit them unless the "-n"
# option was given.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
$conn->setDefaultRebindProc($ld{bind}, $ld{pswd});
($change, $search) = @ARGV;
if (($change eq "") || ($search eq ""))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
($attr, $value) = split(/=/, $change, 2);
$entry = $conn->search($ld{root}, $ld{scope}, $search);
while ($entry)
{
$changed = 0;
if ($opt_d)
{
if (defined $entry->{$attr})
{
if ($value)
{
$changed = $entry->removeValue($attr, $value);
if ($changed && $opt_v)
{
print "Removed value from ", $entry->getDN(), "\n" if $opt_v;
}
}
else
{
delete $entry->{$attr};
print "Deleted attribute $attr for ", $entry->getDN(), "\n" if $opt_v;
$changed = 1;
}
}
else
{
print "No attribute values for: $attr\n";
}
}
else
{
if (!defined($value) || !$value)
{
print "No value provided for the attribute $attr\n";
}
elsif ($opt_a)
{
$changed = $entry->addValue($attr, $value);
if ($changed && $opt_v)
{
print "Added attribute to ", $entry->getDN(), "\n" if $opt_v;
}
}
else
{
$entry->setValue($attr, $value);
$changed = 1;
print "Set attribute for ", $entry->getDN(), "\n" if $opt_v;
}
}
if ($changed && ! $opt_n)
{
$conn->update($entry);
$conn->printError() if $conn->getErrorCode();
}
$entry = $conn->nextEntry();
}
#############################################################################
# Close the connection.
#
$conn->close if $conn;
#############################################################################
# POD documentation...
#
__END__
=head1 NAME
modattr - Modify an attribute for one or more LDAP entries
=head1 SYNOPSIS
modattr [-adnvW] -b base -h host -D bind DN -w pwd -P cert attr=value filter
=head1 ABSTRACT
This command line utility can be used to modify one attribute for one or
more LDAP entries. As simple as this sounds, this turns out to be a very
common operation. For instance, let's say you want to change "mailHost"
for all users on a machine named I<dredd>, to be I<judge>. With this
script all you have to do is
modattr mailHost=judge '(mailHost=dredd)'
=head1 DESCRIPTION
There are four primary operations that can be made with this utility:
=over 4
=item *
Set an attribute to a (single) specified value.
=item *
Add a value to an attribute (for multi-value attributes).
=item *
Delete a value from an attribute. If it's the last value (or if it's a
single value), this will remove the entire attribute.
=item *
Delete an entire attribute, even if it has multiple values.
=back
The first three requires an option of the form B<attr=value>, while the
last one only takes the name of the attribute as the option. The last
argument is always an LDAP search filter, specifying which entries the
operation should be applied to.
=head1 OPTIONS
All but the first two command line options for this tool are standard LDAP
options, to set parameters for the LDAP connection. The two new options
are I<-a> and I<-d> to add and remove attribute values.
Without either of these two options specified (they are both optional),
the default action is to set the attribute to the specified value. That
will effectively remove any existing values for this attribute.
=over 12
=item -a
Specify that the operation is an I<add>, to add a value to the
attribute. If there is no existing value for this attribute, we'll create
a new attribute, otherwise we add the new value if it's not already there.
=item -d
Delete the attribute value, or the entire attribute if there's no value
specified. As you can see this option has two forms, and it's function
depends on the last arguments. Be careful here, if you forget to specify
the value to delete, you will remove all of them.
=item -h <host>
Name of the LDAP server to connect to.
=item -p <port>
TCP port for the LDAP connection.
=item -b <DN>
Base DN for the search
=item -D <bind>
User (DN) to bind as. We support a few convenience shortcuts here, like
I<root>, I<user> and I<repl>.
=item -w <passwd>
This specifies the password to use when connecting to the LDAP
server. This is strongly discouraged, and without this option the script
will ask for the password interactively.
=item -s <scope>
Search scope, default is I<sub>, the other possible values are I<base> and
I<one>. You can also specify the numeric scopes, I<0>, I<1> or I<2>.
=item -P
Use SSL for the LDAP connection, using the specified cert.db file for
certificate information.
=item -n
Don't do anything, only show the changes that would have been made. This
is very convenient, and can save you from embarrassing mistakes.
=item -v
Verbose output.
=back
The last two arguments are special for this script. The first
argument specifies the attribute (and possibly the value) to operate on,
and the last argument is a properly formed LDAP search filter.
=head1 EXAMPLES
We'll give one example for each of the four operations this script can
currently handle. Since the script itself is quite flexible, you'll
probably find you can use this script for a lot of other applications, or
call it from other scripts. Note that we don't specify any LDAP specific
options here, we assume you have configured your defaults properly.
To set the I<description> attribute for user "leif", you would do
modattr 'description=Company Swede' '(uid=leif)'
The examples shows how to use this command without either of the I<-a> or
the I<-d> argument. To add an e-mail alias (alternate address) to the same
user, you would do
modattr -a 'mailAlternateAddress=theSwede@netscape.com' '(uid=leif)'
To remove an object class from all entries which uses it, you could do
modattr -d 'objectclass=dummyClass' '(objectclass=dummyClass)'
This example is not great, since unless you've assured that no entries
uses any of the attributes in this class, you'll get schema
violations. But don't despair, you can use this tool to clean up all
entries first! To completely remove all usage of an attribute named
I<dummyAttr>, you'd simply do
modattr -d dummyAttr '(dummyAttr=*)'
This shows the final format of this command, notice how we don't specify a
value, to assure that the entire attribute is removed. This is potentially
dangerous, so again be careful.
=head1 INSTALLATION
In order to use this script, you'll need Perl version 5.004 or later, the
LDAP SDK, and also the LDAP Perl module (aka PerLDAP). Once you've installed
these packages, just copy this file to where you keep your admin binaries,
e.g. /usr/local/bin.
In order to get good performance, you should make sure you have indexes on
the attributes you typically use with this script. Our experience has been
that in most cases the standard indexes in the Directory Server are
sufficient, e.g. I<CN>, I<UID> and I<MAIL>.
=head1 AVAILABILITY
This package can be retrieved from a number of places, including:
http://www.mozilla.org/directory/
Your local CPAN server
=head1 CREDITS
This little tool was developed internally at Netscape, by Leif Hedstrom.
=head1 BUGS
None, of course...
=head1 SEE ALSO
L<Mozilla::LDAP::API> and L<Perl>
=cut

View File

@@ -0,0 +1,67 @@
#!/usr/bin/perl5
#############################################################################
# $Id: monitor.pl,v 1.2 1998-08-13 09:12:05 leif Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Ask the directory server for it's monitor entry, to see some
# performance and usage stats.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "monitor";
$USAGE = "$APPNAM [-nv] -b base -h host -D bind -w pswd -P cert";
#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('b:h:D:p:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs("", "cn=monitor");
#################################################################################
# Instantiate an LDAP object, which also binds to the LDAP server, and then
# do the simple search.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
$entry = $conn->search($ld{root}, "base", "objectclass=*");
Mozilla::LDAP::Utils::printEntry($entry)
if ($entry);
#################################################################################
# Close the connection.
#
$conn->close if $conn;

View File

@@ -0,0 +1,615 @@
#!/usr/bin/perl5
#############################################################################
# $Id: psoftsync.pl,v 1.5 1999-01-21 23:52:47 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Synchronise some LDAP info with a PeopleSoft "dump". This "dump" file
# is a "tab" separated file, as generated by an SQL utility on the
# Oracle server.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
#############################################################################
# Local configurations, check these out . Note that SYNCS and ORDER has to
# have the same fields, this is because the hash array doesn't preserve
# the order of it's entries... :-( The "codes" are bit fields, where the
# three LSB are used as
#
# 1 Force the update, even if attribute is empty (i.e. delete it)
# 2 The attribute is the base for a DN (e.g. "manager").
# 4 The attribute should be deleted if the user is not in PeopleSoft.
# 8 Don't warn if the attribute is missing in the Psoft file (-W option).
# 16 Always delete this attribute in the PeopleSoft entry.
# 32 Delete this attribute if the account has "expired".
#
%SYNCS = (
"nscpharold" => 1 + 4,
"uid" => 0,
"" => 0,
"" => 0,
"employeenumber" => 1 + 4 + 32,
"departmentnumber" => 1 + 4,
"" => 0,
"" => 0,
"" => 0,
"manager" => 1 + 2,
"title" => 1 + 4 + 16 + 32,
"ou" => 1 + 4 + 32,
"businesscategory" => 1 + 4 + 32,
"employeetype" => 0,
"nscppersonexpdate" => 1 + 8
);
@ORDER = (
"nscpharold",
"uid",
"",
"",
"employeenumber",
"departmentnumber",
"",
"",
"",
"manager",
"title",
"ou",
"businesscategory",
"employeetype",
"nscppersonexpdate"
);
# This is used for mapping the employeeType attribute into a readable format.
%EMPCODES = (
"A" => "Applicant",
"C" => "Contractor",
"E" => "Employee",
"O" => "OEM Partner",
"T" => "Interim",
"V" => "Vendor"
);
# Expiration policy for other attributes, the EXPDELAY is a convenience
# default setting.
$EXPDELAY = 24 * 7;
%EXPIRES = (
"carlicense" => $EXPDELAY,
"mailautoreplymode" => $EXPDELAY,
"mailautoreplytext" => $EXPDELAY,
"mailforwardingaddress" => $EXPDELAY,
"facsimiletelephonenumber" => $EXPDELAY
);
$NOTYPE = "Unknown";
$DELIMITER = "%%";
$SENDMAIL = "/usr/lib/sendmail";
$SEARCH = "(&(uid=*)(!(objectclass=pseudoAccount)))";
$MAILTO = "leif\@netscape.com";
#$LDAP_DEBUG = 1;
#############################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "psoftsync";
$USAGE = "$APPNAM [-nvW] -b base -h host -D bind -w passwd -P cert PS_file";
@ATTRIBUTES = uniq(@ORDER);
push(@ATTRIBUTES, "objectclass");
$TODAY = `/usr/bin/date '+%Y%m%d'`;
chop($TODAY);
#############################################################################
# Print an error for the PeopleSoft data. Note that we use the "__XXX__" fields
# here, to avoid the problem when an attribute is "expired" or modified.
#
sub psoftError
{
my ($str, $entry) = @_;
print "Error: $str: ";
print $entry->key(), " (";
print $entry->{__employeenumber__}, ", ";
print $entry->{__employeetype__}, ", ";
print $entry->{__departmentnumber__}, ")\n";
}
#############################################################################
# Read in a PeopleSoft file, and create all the entries.
#
sub readDump
{
my ($file) = @_;
my (@info, %entries);
my $val;
if (!open(PSOFT, $file))
{
print "Error: Can't read file $file\n";
exit(1);
}
while (<PSOFT>)
{
next unless /$DELIMITER/;
@info = split(/\s*%%\s*/);
$entry = new PsoftEntry($info[$[]);
foreach $attr (@ORDER)
{
$val = shift(@info);
next if ($attr eq "");
$entry->add($attr, $val, $SYNCS{$attr});
}
#
# Perhaps we should do some sanity checks here on the PeopleSoft data?
#
# Clean up some data if the user has expired ("best before...")
if ($entry->expired($entry->{nscppersonexpdate}))
{
foreach $attr (@ORDER)
{
next unless $attr;
delete($entry->{$attr}) if ($SYNCS{$attr} & 32);
}
}
if ($entry->{uid})
{
$entries{$entry->{uid}} = $entry;
}
elsif ($opt_W)
{
psoftError("No UID", $entry);
}
}
close(PSOFT);
return %entries;
}
#############################################################################
# Make a list "uniq", just like the Unix command.
#
sub uniq { # uniq(elements[])
my %tmp;
grep($tmp{$_}++, @_);
return sort(keys(%tmp));
}
#############################################################################
# Delete an attribute from an entry.
#
sub delAttr { # delAttr(ENTRY, ATTR)
my ($entry, $attr) = @_;
if (defined($entry->{$attr}))
{
$out->write("Deleted $attr for user: $entry->{uid}[0]") if $opt_v;
delete($entry->{$attr});
return 1;
}
return 0;
}
#############################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('nvMWb:h:D:p:s:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
Mozilla::LDAP::Utils::userCredentials(\%ld) unless $opt_n;
$out = new Mail();
if ($opt_M)
{
$out->set("to", $MAILTO);
$out->set("subject", "Hoth: PeopleSoft synchronization report");
}
else
{
$out->echo();
$out->nomail();
}
#############################################################################
# Read in all the PeopleSoft entries, and then instantiate an LDAP object,
# which also binds to the LDAP server.
#
%psoft = readDump(@ARGV[$[]);
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
#############################################################################
# Now process all the users, one by one.
#
$entry = $conn->search($ld{root}, "subtree", $SEARCH, 0, @ATTRIBUTES);
while ($entry)
{
$uid = $entry->{"uid"}[0];
$changed = 0;
$psent = $psoft{$uid};
if (!$psent)
{
print "Error: LDAP user $uid: No entry in PeopleSoft\n" if $opt_W;
foreach $attr (@ORDER)
{
next unless $attr;
$changed += delAttr($entry, $attr) if ($SYNCS{$attr} & 4);
}
if ($entry->{employeetype}[0] ne "$NOTYPE")
{
$entry->{employeetype} = ["$NOTYPE"];
$changed = 1;
$out->write("Set employeeType to $NOTYPE for user: $uid") if $opt_v;
}
}
else
{
$psent->handled(1);
foreach $attr (@ORDER)
{
next unless $attr;
if (!defined($psent->{$attr}) || ($psent->{$attr} eq ""))
{
$changed += delAttr($entry, $attr) if ($SYNCS{$attr} & 1);
}
elsif ($entry->{$attr}[0] ne $psent->{$attr})
{
$entry->{$attr} = [$psent->{$attr}];
$changed = 1;
$out->write("Set $attr to $psent->{$attr} for user: $uid") if $opt_v;
}
}
# Now handle the Expire date special case...
if ($psent->expired() ne "")
{
if ($entry->addValue("objectclass", "nscphidethis"))
{
$changed = 1;
$out->write("Expiring the user: $uid") if $opt_v;
}
# Expire other attributes, IFF the expire is over a certain
# treshhold (e.g. a week).
}
elsif ($entry->removeValue("objectclass", "nscphidethis"))
{
$changed = 1;
$out->write("Enabling the user: $uid") if $opt_v;
}
}
$conn->update($entry) if ($changed && ! $opt_n);
$entry = $conn->nextEntry();
}
#############################################################################
# Close the LDAP connection.
#
$conn->close if $conn;
#############################################################################
# Post process, figure out which PSoft entries have no entry in LDAP.
#
if ($opt_W)
{
foreach (keys(%psoft))
{
$ent=$psoft{$_};
psoftError("No LDAP entry", $ent) unless $ent->handled();
}
}
#############################################################################
# Package to an entry from the PeopleSoft database.
#
package PsoftEntry;
#############################################################################
# Creator.
#
sub new
{
my ($class, $key) = @_;
my $self = {};
bless $self, ref $class || $class;
$self->{__key__} = $key;
return $self;
}
#############################################################################
# Add an attribute/field to the entry.
#
sub add
{
my ($self, $attr, $val, $lev) = @_;
return if ($lev & 16);
$attr = lc $attr;
if ($attr eq "employeetype")
{
if (defined($main::EMPCODES{$val}))
{
$self->{$attr} = $main::EMPCODES{$val};
}
else
{
$self->{$attr} = $main::NOTYPE;
}
$self->{__employeetype__} = $val;
}
elsif (!defined($val) || ($val eq ""))
{
main::psoftError("No attribute $attr", $self)
if ($main::opt_W && ($lev & 1) && !($lev & 8));
}
else
{
$self->{$attr} = ($lev & 2) ? "uid=$val,$main::ld{root}" : $val;
$self->{"__${attr}__"} = $val;
}
}
#############################################################################
# Return the value for an attribute/field.
#
sub get
{
my ($self, $attr) = @_;
return $self->{$attr};
}
#############################################################################
# Mark the entry as "expired". If there is no "date" argument, we'll return
# the current entries expire status.
#
sub expired
{
my ($self, $date) = @_;
if ($date)
{
# Only expire entries with reasonable expire dates...
if (length($date) != 8)
{
main::psoftError("Bad expire date", $self) if $main::opt_W;
return 0;
}
if ($date lt $main::TODAY)
{
$self->{employeetype} = "$main::NOTYPE";
$self->{__expired__} = 1;
return 1;
}
}
return $self->{__expired__};
}
#############################################################################
# Mark the entry as "handled", i.e. it exists in LDAP.
#
sub handled
{
my ($self, $flag) = @_;
$self->{__handled__} = 1 if $flag;
return $self->{__handled__};
}
#############################################################################
# Return the "key" of this entry, typically the name field.
#
sub key
{
my ($self) = @_;
return $self->{__key__};
}
#################################################################################
# This sub-package will send mail to some recipients, IFF there is anything to
# send, or your force it to send. Note that the Subject doesn't qualify it to
# send a message (force it to send if you have to).
#
package Mail;
#################################################################################
# The constructor, which optionally takes the TO, FROM and SUBJECT.
#
sub new
{
my ($class, $to, $from, $subject) = @_;
my $self = {};
bless $self, ref $class || $class;
$self->{to} = $to || "root";
$self->{from} = $from || "ldap";
$self->{subject} = $subject || "Output from LDAP script\n";
@{$self->{message}} = ();
$self->{send} = 0;
$self->{nomail} = 0;
$self->{echo} = 0;
return $self;
}
#################################################################################
# Destructor, which will also send the message, if appropriate.
#
sub DESTROY
{
my ($self) = @_;
if ($self->{send} && !$self->{nomail})
{
$self->send();
$self->{send} = 0;
}
}
#################################################################################
# Set a field for this entry, e.g. From:, To: etc.
#
sub set
{
my ($self, $field, $string) = @_;
if ($field && $string)
{
$field = lc $field;
$self->{$field} = $string;
}
}
#################################################################################
# Add a line to the message, the argument is the string.
#
sub write
{
my ($self, $string) = @_;
if ($string ne "")
{
push(@{$self->{message}}, $string);
print "$string\n" if $self->{echo};
$self->{send}++;
}
}
#################################################################################
# Force the object to send the message, no matter if there's anything in the
# body or not.
#
sub force
{
my ($self) = @_;
$self->{send} = 1;
$self->{nomail} = 0;
}
#################################################################################
# Don't send the mail, this is the oppositte to "force...
#
sub nomail
{
my ($self) = @_;
$self->{send} = 0;
$self->{nomail} = 1;
}
#################################################################################
# Enable echo-mode, where we will also print everything to STDOUT.
#
sub echo
{
my ($self) = @_;
$self->{echo} = 1;
}
#################################################################################
# Actually send the message. This is automatically done by the DESTROY method,
# but we can force it to do it this way.
#
sub send
{
my ($self) = @_;
if ($self->{send} && !$self->{nomail})
{
open(MAILER, "|$main::SENDMAIL -t");
print MAILER "From: $self->{from}\n";
print MAILER "To: $self->{to}\n";
print MAILER "Subject: $self->{subject}\n\n";
foreach (@{$self->{message}})
{
print MAILER "$_\n";
}
print MAILER ".\n";
close(MAILER);
$self->{send} = 0;
}
}

View File

@@ -0,0 +1,98 @@
#!/usr/bin/perl5
#############################################################################
# $Id: qsearch.pl,v 1.8 1999-01-21 23:52:47 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Quick Search, like ldapsearch, but in Perl. Look how simple it is.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
use strict;
no strict "vars";
#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "qsearch";
$USAGE = "$APPNAM -b base -h host -D bind -w pswd -P cert filter [attr...]";
#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('b:h:D:p:s:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
#################################################################################
# Now do all the searches, one by one.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
foreach (@ARGV)
{
if (/\=/)
{
push(@srch, $_);
}
else
{
push(@attr, $_);
}
}
foreach $search (@srch)
{
if ($#attr >= $[)
{
$entry = $conn->search($ld{root}, $ld{scope}, $search, 0, @attr);
}
else
{
$entry = $conn->search($ld{root}, $ld{scope}, "$search");
}
print "Searched for `$search':\n\n";
$conn->printError() if $conn->getErrorCode();
while ($entry)
{
$entry->printLDIF();
$entry = $conn->nextEntry;
}
print "\n";
}
#################################################################################
# Close the connection.
#
$conn->close if $conn;

View File

@@ -0,0 +1,98 @@
#!/usr/bin/perl5
#############################################################################
# $Id: rename.pl,v 1.4 1999-01-21 23:52:47 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Rename an LDAP entry, changing it's DN. Note that currently this only
# works with RDNs.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
#############################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "rename";
$USAGE = "$APPNAM [-nvI] -b base -h host -D bind -w pswd -P cert filter new_rdn";
#############################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('nvIb:h:D:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
Mozilla::LDAP::Utils::userCredentials(\%ld) unless $opt_n;
($search, $rdn) = @ARGV;
if (($search eq "") || ($rdn eq ""))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
#############################################################################
# Instantiate an LDAP object, which also binds to the LDAP server.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
$key = "Y" if $opt_I;
$entry = $conn->search($ld{root}, $ld{scope}, $search, 0, @ATTRIBUTES);
$conn->printError() if $conn->getErrorCode();
if (! $entry || $conn->nextEntry())
{
print "Error: The search did not return exactly one match, abort!\n";
exit;
}
if (! $opt_I)
{
print "Rename ", $entry->getDN(), " with $rdn [N]? ";
$key = Mozilla::LDAP::Utils::answer("N") unless $opt_I;
}
if ($key eq "Y")
{
# Note: I have to explicitly specify the original DN below, since the call
# to nextEntry() above blows the DN away from the ::Conn object.
if (! $opt_n)
{
$conn->modifyRDN($rdn, $entry->getDN());
$conn->printError() if $conn->getErrorCode();
}
print "Renamed $entry->{dn}\n" if $opt_v;
}
#################################################################################
# Close the connection.
#
$conn->close if $conn;

View File

@@ -0,0 +1,94 @@
#!/usr/bin/perl5
#############################################################################
# $Id: rmentry.pl,v 1.4 1999-01-21 23:52:47 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Remove one or several LDAP objects. By default this tool is
# interactive, which can be disabled with the "-I" option (but
# please be careful...).
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "rmentry";
$USAGE = "$APPNAM [-nvI] -b base -h host -D bind -w pswd -P cert filter ...";
@ATTRIBUTES = ("uid");
#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('nvIb:h:D:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
Mozilla::LDAP::Utils::userCredentials(\%ld) unless $opt_n;
#################################################################################
# Do the search, and process all the entries.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
$key = "Y" if $opt_I;
foreach $search (@ARGV)
{
$entry = $conn->search($ld{root}, $ld{scope}, $search, 0, @ATTRIBUTES);
$conn->printError() if $conn->getErrorCode();
while ($entry)
{
if (! $opt_I)
{
print "Delete $entry->{dn} [N]? ";
$key = Mozilla::LDAP::Utils::answer("N") unless $opt_I;
}
if ($key eq "Y")
{
if (! $opt_n)
{
$conn->delete($entry);
$conn->printError() if $conn->getErrorCode();
}
print "Deleted $entry->{dn}\n" if $opt_v;
}
$entry = $conn->nextEntry();
}
}
#################################################################################
# Close the connection.
#
$conn->close if $conn;

View File

@@ -0,0 +1,81 @@
#!/usr/bin/perl5
#############################################################################
# $Id: tabdump.pl,v 1.3 1998-08-13 09:11:10 leif Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Generate a TAB separate "dump" of entries matching the search criteria,
# using the list of attributes specified.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "tabdump";
$USAGE = "$APPNAM [-nv] -b base -h host -D bind -w pswd -P cert attr1,attr2,.. srch";
#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('nvb:h:D:p:s:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs();
$attributes = $ARGV[$[];
$search = $ARGV[$[ + 1];
die "Need to specify a list of attributes and the search filter.\n"
unless ($attributes && $search);
#################################################################################
# Do the searches, and produce the output.
#
$conn = new Mozilla::LDAP::Conn(\%ld);
die "Could't connect to LDAP server $ld{host}" unless $conn;
@attr = split(/,/, $attributes);
$entry = $conn->search($ld{root}, $ld{scope}, $search, 0, @attr);
$conn->printError() if $conn->getErrorCode();
while ($entry)
{
foreach (@attr)
{
print $entry->{$_}[0], "\t";
}
print "\n";
$entry = $conn->nextEntry;
}
#################################################################################
# Close the connection.
#
$conn->close if $conn;

View File

@@ -0,0 +1,59 @@
#!/usr/bin/perl -w
#############################################################################
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Perl Script to Install PerLDAP Binaries without a Makefile.
# For use with the binary distribution of PerLDAP.
#
#############################################################################
use File::Path;
use File::Copy;
use Config;
print "\n##############################################\n";
print "# Installing Netscape PerLDAP v1.0 #\n";
print "##############################################\n\n";
$ARCH_LIB = $Config{'sitearchexp'} . "/auto/Mozilla/LDAP/API";
$PERL_LIB = $Config{'sitelibexp'};
print "Creating Directory '$ARCH_LIB'...\n";
File::Path::mkpath "$ARCH_LIB";
print "Creating Directory '$PERL_LIB/Mozilla/LDAP'...\n";
File::Path::mkpath "$PERL_LIB/Mozilla/LDAP";
print "Copying Architecture Dependent Files...\n";
foreach $file (glob "blib/arch/auto/Mozilla/LDAP/API/*")
{
copy($file,"$ARCH_LIB");
}
print "Copying Module Components...\n";
foreach $file (glob "blib/lib/Mozilla/LDAP/*")
{
copy($file,"$PERL_LIB/Mozilla/LDAP");
}
print "Finished!\n\n";
exit 0;

View File

@@ -0,0 +1,6 @@
1999-01-05 Leif Hedstrom <leif@netscape.com>
* entry.pl: New script, to test all Entry:: methods.
* conn.pl (attributeEQ): Added test for modifyRDN().

View File

@@ -0,0 +1,270 @@
#!/usr/bin/perl5
#############################################################################
# $Id: conn.pl,v 1.2 1999-01-21 23:52:50 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Test most (all?) of the LDAP::Mozilla::Conn methods.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
use Mozilla::LDAP::API;
use strict;
no strict "vars";
#################################################################################
# Configurations, modify these as needed.
#
$BIND = "uid=ldapadmin";
$BASE = "o=Netscape Communications Corp.,c=US";
$PEOPLE = "ou=people";
$GROUPS = "ou=groups";
$UID = "leif-test";
$CN = "test-group-1";
#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "conn.pl";
$USAGE = "$APPNAM -b base -h host -D bind -w pswd -P cert";
#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('b:h:D:p:s:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs($BIND, $BASE);
#################################################################################
# Get an LDAP connection
#
sub getConn
{
my $conn;
if ($main::reuseConn)
{
if (!defined($main::mainConn))
{
$main::mainConn = new Mozilla::LDAP::Conn(\%main::ld);
die "Could't connect to LDAP server $main::ld{host}"
unless $main::mainConn;
}
return $main::mainConn;
}
else
{
$conn = new Mozilla::LDAP::Conn(\%main::ld);
die "Could't connect to LDAP server $main::ld{host}" unless $conn;
}
return $conn;
}
#################################################################################
# Some small help functions...
#
sub dotPrint
{
my $str = shift;
print $str . '.' x (20 - length($str));
}
sub attributeEQ
{
my @a, @b;
my $i;
@a = @{$_[0]};
@b = @{$_[1]};
return 1 if (($#a < 0) && ($#b < 0));
return 0 unless ($#a == $#b);
@a = sort(@a);
@b = sort(@b);
for ($i = 0; $i <= $#a; $i++)
{
return 0 unless ($a[$i] eq $b[$i]);;
}
return 1; # We passed all the tests, we're ok.
}
#################################################################################
# Test adding, deleting and retrieving entries.
#
$filter = "(uid=$UID)";
$conn = getConn();
$nentry = $conn->newEntry();
$nentry->setDN("uid=$UID, $PEOPLE, $BASE");
$nentry->{objectclass} = [ "top", "person", "inetOrgPerson", "mailRecipient" ];
$nentry->addValue("uid", $UID);
$nentry->addValue("sn", "Hedstrom");
$nentry->addValue("givenName", "Leif");
$nentry->addValue("cn", "Leif Hedstrom");
$nentry->addValue("cn", "Leif P. Hedstrom");
$nentry->addValue("cn", "The Swede");
$nentry->addValue("mail", "leif\@ogre.com");
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
$conn->delete($ent->getDN()) if $ent;
dotPrint("Conn/newEntry");
$conn->add($nentry) || print "not ";
print "ok\n";
dotPrint("Conn/delete");
$conn->delete($nentry) || print "not ";
print "ok\n";
dotPrint("Conn/add");
$conn->add($nentry) || print "not ";
print "ok\n";
dotPrint("Conn/delete(DN)");
$conn->delete($nentry->getDN()) || print "not ";
print "ok\n";
$conn->add($nentry) || die "Can't create entry again...\n";
dotPrint("Conn/search");
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
$err = 0;
foreach (keys (%{$nentry}))
{
$err = 1 unless (defined($ent->{$_})
&& attributeEQ($nentry->{$_}, $ent->{$_}));
}
print "not " if $err;
print "ok\n";
$conn->close();
#################################################################################
# Test LDAP URL handling.
#
$conn = getConn();
$url1 = "ldap:///" . $ld{root} . "??sub?$filter";
$url2 = "ldaps:///" . $ld{root} . "??sub?$filter";
$badurl1 = "ldap:" . $ld{root} . "??sub?$filter";
$badurl2 = "http://" . $ld{root} . "??sub?$filter";
dotPrint("Conn/isURL");
print "not " unless ($conn->isURL($url1) && $conn->isURL($url2) &&
!$conn->isURL($badurl2) && !$conn->isURL($badurl1));
print "ok\n";
dotPrint("Conn/searchURL");
$ent = $conn->searchURL($url1);
$err = 0;
foreach (keys (%{$nentry}))
{
$err = 1 unless (defined($ent->{$_})
&& attributeEQ($nentry->{$_}, $ent->{$_}));
}
print "not " if $err;
print "ok\n";
$conn->close();
#################################################################################
# Test some small internal stuff.
#
$conn = getConn();
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
print "Can't locate entry again" unless $ent;
dotPrint("Conn/getLD+getRes");
$err = 0;
$cld = $conn->getLD();
$res = $conn->getRes();
$err = 1 unless $cld;
$err = 1 unless $res;
$count = Mozilla::LDAP::API::ldap_count_entries($cld, $res);
$err = 1 unless ($count == 1);
print "not " if $err;
print "ok\n";
$conn->close();
#################################################################################
# Test the simple authentication method
#
$conn = new Mozilla::LDAP::Conn($ld{host}, $ld{port});
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
die "Can't locate entry again" unless $ent;
dotPrint("Conn/simpleAuth");
$err = 0;
$conn->simpleAuth($ld{bind}, $ld{pswd}) || ($err = 1);
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
$err = 1 unless $ent;
print "not " if $err;
print "ok\n";
$conn->close();
#################################################################################
# Test the modifyRDN functionality
#
$conn = getConn();
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
die "Can't locate entry again" unless $ent;
dotPrint("Conn/modifyRDN");
$err = 0;
$rdn = "uid=$UID-rdn";
$conn->modifyRDN($rdn, $ent->getDN()) || ($err = 1);
$filter = "($rdn)";
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
$err = 1 unless $ent;
print "not " if $err;
print "ok\n";
$conn->delete($ent->getDN()) if $ent;
#################################################################################
# Test error handling (ToDo!)
#

View File

@@ -0,0 +1,150 @@
#!/usr/bin/perl5
#############################################################################
# $Id: entry.pl,v 1.2 1999-01-21 23:52:50 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Test most (all?) of the LDAP::Mozilla::Conn methods.
#
#############################################################################
use Getopt::Std; # To parse command line arguments.
use Mozilla::LDAP::Conn; # Main "OO" layer for LDAP
use Mozilla::LDAP::Utils; # LULU, utilities.
use Mozilla::LDAP::API;
use strict;
no strict "vars";
#################################################################################
# Configurations, modify these as needed.
#
$BIND = "uid=ldapadmin";
$BASE = "o=Netscape Communications Corp.,c=US";
$PEOPLE = "ou=people";
$GROUPS = "ou=groups";
$UID = "leif-test";
$CN = "test-group-1";
#################################################################################
# Constants, shouldn't have to edit these...
#
$APPNAM = "entry.pl";
$USAGE = "$APPNAM -b base -h host -D bind -w pswd -P cert";
#################################################################################
# Check arguments, and configure some parameters accordingly..
#
if (!getopts('b:h:D:p:s:w:P:'))
{
print "usage: $APPNAM $USAGE\n";
exit;
}
%ld = Mozilla::LDAP::Utils::ldapArgs($BIND, $BASE);
#################################################################################
# Get an LDAP connection
#
sub getConn
{
my $conn;
if ($main::reuseConn)
{
if (!defined($main::mainConn))
{
$main::mainConn = new Mozilla::LDAP::Conn(\%main::ld);
die "Could't connect to LDAP server $main::ld{host}"
unless $main::mainConn;
}
return $main::mainConn;
}
else
{
$conn = new Mozilla::LDAP::Conn(\%main::ld);
die "Could't connect to LDAP server $main::ld{host}" unless $conn;
}
return $conn;
}
#################################################################################
# Some small help functions...
#
sub dotPrint
{
my $str = shift;
print $str . '.' x (20 - length($str));
}
sub attributeEQ
{
my @a, @b;
my $i;
@a = @{$_[0]};
@b = @{$_[1]};
return 1 if (($#a < 0) && ($#b < 0));
return 0 unless ($#a == $#b);
@a = sort(@a);
@b = sort(@b);
for ($i = 0; $i <= $#a; $i++)
{
return 0 unless ($a[$i] eq $b[$i]);;
}
return 1; # We passed all the tests, we're ok.
}
#################################################################################
# Setup the test entries.
#
$filter = "(uid=$UID)";
$conn = getConn();
$nentry = $conn->newEntry();
$nentry->setDN("uid=$UID, $PEOPLE, $BASE");
$nentry->{objectclass} = [ "top", "person", "inetOrgPerson", "mailRecipient" ];
$nentry->addValue("uid", $UID);
$nentry->addValue("sn", "Hedstrom");
$nentry->addValue("givenName", "Leif");
$nentry->addValue("cn", "Leif Hedstrom");
$nentry->addValue("cn", "Leif P. Hedstrom");
$nentry->addValue("cn", "The Swede");
$nentry->addValue("description", "Test1");
$nentry->addValue("description", "Test2");
$nentry->addValue("description", "Test3");
$nentry->addValue("description", "Test4");
$nentry->addValue("description", "Test5");
$nentry->addValue("mail", "leif\@ogre.com");
$ent = $conn->search($ld{root}, $ld{scope}, $filter);
$conn->delete($ent->getDN()) if $ent;
$conn->add($nentry);
$conn->close();

View File

@@ -0,0 +1,162 @@
#############################################################################
# $Id: test.pl,v 1.6 1998-08-13 09:14:44 leif Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl test.pl'
#
#############################################################################
######################### We start with some black magic to print on failure.
# Change 1..1 below to 1..last_test_to_print .
# (It may become useful if the test is moved to ./t subdirectory.)
BEGIN { $| = 1; print "1..8\n"; }
END {print "modinit - not ok\n" unless $loaded;}
use Mozilla::LDAP::API qw(:constant :api :ssl);
$loaded = 1;
print "modinit - ok\n";
######################### End of black magic.
$attrs = [];
$ldap_host = $ENV{"LDAPHOST"};
$filter = $ENV{"TESTFILTER"};
$BASEDN = $ENV{"LDAPBASE"};
if (!$ldap_host)
{
print "\nEnter LDAP Server: ";
chomp($ldap_host = <>);
}
if (!$filter)
{
print "Enter Search Filter (ex. uid=abc123): ";
chomp($filter = <>);
}
if (!$BASEDN)
{
print "Enter LDAP Search Base (ex. o=Org, c=US): ";
chomp($BASEDN = <>);
}
print "\n";
##
## Initialize LDAP Connection
##
if (($ld = ldap_init($ldap_host,LDAP_PORT)) == -1)
{
print "open - not ok\n";
exit -1;
}
print "open - ok\n";
##
## Bind as DN, PASSWORD (NULL,NULL) on LDAP connection $ld
##
if (ldap_simple_bind_s($ld,"","") != LDAP_SUCCESS)
{
ldap_perror($ld,"bind_s");
print "bind - not ok\n";
exit -1;
}
print "bind - ok\n";
##
## ldap_search_s - Synchronous Search
##
if (ldap_search_s($ld,$BASEDN,LDAP_SCOPE_SUBTREE,$filter,$attrs,0,$result) != LDAP_SUCCESS)
{
ldap_perror($ld,"search_s");
print "search - not ok\n";
}
print "search - ok\n";
##
## ldap_count_entries - Count Matched Entries
##
if (($count = ldap_count_entries($ld,$result)) == -1)
{
ldap_perror($ld,"count_entry");
print "count - not ok\n";
}
print "count - ok - $count\n";
##
## first_entry - Get First Matched Entry
## next_entry - Get Next Matched Entry
##
for ($ent = ldap_first_entry($ld,$result); $ent; $ent = ldap_next_entry($ld,$ent))
{
##
## ldap_get_dn - Get DN for Matched Entries
##
if (($dn = ldap_get_dn($ld,$ent)) ne "")
{
print "getdn - ok - $dn\n";
} else {
ldap_perror($ld,"get_dn");
print "getdn - not ok\n";
}
for ($attr = ldap_first_attribute($ld,$ent,$ber); $attr; $attr = ldap_next_attribute($ld,$ent,$ber))
{
print "firstatt - ok - $attr\n";
##
## ldap_get_values
##
@vals = ldap_get_values($ld,$ent,$attr);
if ($#vals >= 0)
{
foreach $val (@vals)
{
print "getvals - ok - $val\n";
}
} else {
print "getvals - not ok\n";
}
}
}
##
## Unbind LDAP Connection
##
ldap_unbind($ld);

View File

@@ -0,0 +1,280 @@
#!/usr/bin/perl -w
#############################################################################
# $Id: api.pl,v 1.7 1999-01-21 23:52:52 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# api.pl - Test all LDAPv2 API function
# Author: Clayton Donley <donley@wwa.com>
#
# Performs all API calls directly in order to test for possible issues
# on a particular platform.
#
#############################################################################
use Mozilla::LDAP::API qw(:api :constant);
use strict;
my $BASE = "ou=Test,o=Test,c=US";
my $DN = "cn=Directory Manager";
my $PASS = "abcd1234";
my $HOST = "";
my $PORT = 389;
if (!$HOST)
{
print "Please edit the variables at the top of this file.\n";
exit -1;
}
print "\nPerLDAP API TestSuite\n";
print "\nNote: Failures in earlier tests will cause later tests to fail.\n";
print "\n";
my $howmany = 10;
# Initialize the Connection
{
my $ld = ldap_init($HOST,$PORT);
if ($ld <0)
{
print "init - Failed!\n";
die;
}
print "init - OK\n";
# Set an LDAP Session Option
if (ldap_set_option($ld,LDAP_OPT_PROTOCOL_VERSION,LDAP_VERSION3)
!= LDAP_SUCCESS)
{
print "set_option - Failed!\n";
} else {
print "set_option - OK\n";
}
# Get an LDAP Session Option
my $option;
ldap_get_option($ld,LDAP_OPT_REFERRALS,$option);
if ($option != 1)
{
print "get_option - Failed!\n";
} else {
print "get_option - OK\n";
}
# Anonymous Bind
if (ldap_simple_bind_s($ld,"","") != LDAP_SUCCESS)
{
print "anon_bind - Failed!\n";
} else {
print "anon_bind - OK\n";
}
# Authenticated Simple Bind
if (ldap_simple_bind_s($ld,$DN,$PASS) != LDAP_SUCCESS)
{
print "simple_bind - Failed!\n";
} else {
print "simple_bind - OK\n";
}
# Set Rebind Process
my $rebindproc = sub { return($DN,$PASS,LDAP_AUTH_SIMPLE); };
ldap_set_rebind_proc($ld,$rebindproc);
print "set_rebind - OK\n";
# Add an OrgUnit Entry
my $entry = {
"objectclass" => ["top","organizationalUnit"],
"ou" => "Test",
};
if (ldap_add_s($ld,$BASE,$entry) != LDAP_SUCCESS)
{
print "add_org - Failed!\n";
} else {
print "add_org - OK\n";
}
# Add People
foreach my $number (1..$howmany)
{
$entry = {
"objectclass" => ["top","person"],
"cn" => "Mozilla $number",
"sn" => ["$number"],
};
if (ldap_add_s($ld,"cn=Mozilla $number,$BASE",$entry)
!= LDAP_SUCCESS)
{
print "add_user_$number - Failed!\n";
} else {
print "add_user_$number - OK\n";
}
}
# Modify People
foreach my $number (1..$howmany)
{
$entry = {
"sn" => {"ab",["Test"]},
"telephoneNumber" => {"ab",[123.456]},
# "telephoneNumber" => "800-555-111$number",
};
if (ldap_modify_s($ld,"cn=Mozilla $number,$BASE",$entry)
!= LDAP_SUCCESS)
{
print "mod_user_$number - Failed!\n";
} else {
print "mod_user_$number - OK\n";
}
}
# Search People
my $filter = "(sn=Test)";
my $attrs = ["cn","sn"];
my $res;
if (ldap_search_s($ld,$BASE,LDAP_SCOPE_SUBTREE,$filter,$attrs,0,$res)
!= LDAP_SUCCESS)
{
print "search_user - Failed!\n";
} else {
print "search_user - OK\n";
}
# Count Results
if (ldap_count_entries($ld,$res) != $howmany)
{
print "count_res - Failed!\n";
} else {
print "count_res - OK\n";
}
# Sort Results
if (ldap_sort_entries($ld,$res,"sn") != LDAP_SUCCESS)
{
print "sort_ent - Failed!\n";
} else {
print "sort_ent - OK\n";
}
# Multisort Results
if (ldap_multisort_entries($ld,$res,["sn","telephoneNumber"]) != LDAP_SUCCESS)
{
print "multisort - Failed!\n";
} else {
print "multisort - OK\n";
}
# Get First Entry
my $ent = ldap_first_entry($ld,$res);
if (!$ent)
{
print "first_entry - Failed!\n";
} else {
print "first_entry - OK\n";
}
# Get Next Entry
$ent = ldap_next_entry($ld,$ent);
if (!$ent)
{
print "next_entry - Failed!\n";
} else {
print "next_entry - OK\n";
}
# Get DN
my $dn = ldap_get_dn($ld,$ent);
if (!$dn)
{
print "get_dn - Failed!\n";
} else {
print "get_dn - OK\n";
}
# Get First Attribute
my $ber;
my $attr = ldap_first_attribute($ld,$ent,$ber);
if (!$attr)
{
print "first_attr - Failed!\n";
} else {
print "first_attr - OK\n";
}
# Get Next Attribute
$attr = ldap_next_attribute($ld,$ent,$ber);
if (!$attr)
{
print "next_attr - Failed!\n";
} else {
print "next_attr - OK\n";
}
# Get Attribute Values
my @vals = ldap_get_values($ld,$ent,$attr);
if ($#vals < 0)
{
print "get_values - Failed!\n";
} else {
print "get_values - OK\n";
}
# Free structures pointed to by $ber and $res to prevent memory leak
ldap_ber_free($ber,1);
ldap_msgfree($res);
# Compare Attribute Values
foreach my $number (1..$howmany)
{
if(ldap_compare_s($ld,"cn=Mozilla $number,$BASE","sn",$number)
!= LDAP_COMPARE_TRUE)
{
print "comp_user_$number - Failed!\n";
} else {
print "comp_user_$number - OK\n";
}
}
# Delete Users
foreach my $number (1..$howmany)
{
if (ldap_delete_s($ld,"cn=Mozilla $number,$BASE") != LDAP_SUCCESS)
{
print "del_user_$number - Failed!\n";
} else {
print "del_user_$number - OK\n";
}
}
if (ldap_delete_s($ld,"$BASE") != LDAP_SUCCESS)
{
print "del_org - Failed!\n";
} else {
print "del_org - OK\n";
}
# Unbind
ldap_unbind($ld);
}

View File

@@ -0,0 +1,131 @@
#!/usr/bin/perl
#############################################################################
# $Id: search.pl,v 1.4 1998-08-13 04:40:01 clayton Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerlDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Test the search capabilities of the API, similar to write.pl.
#
#############################################################################
use Mozilla::LDAP::API qw(:api :constant);
use strict;
my $ldap_host = "";
my $BASEDN = "o=Org,c=US";
my $filter = $ARGV[0];
if (!$ldap_host)
{
print "Edit the top portion of this file before continuing.\n";
exit -1;
}
my $attrs = [];
my ($ld,$result,$count);
##
## Initialize LDAP Connection
##
if (($ld = ldap_init($ldap_host,LDAP_PORT)) == -1)
{
die "Can not open LDAP connection to $ldap_host";
}
##
## Bind as DN, PASSWORD (NULL,NULL) on LDAP connection $ld
##
if (ldap_simple_bind_s($ld,"","") != LDAP_SUCCESS)
{
ldap_perror($ld,"bind_s");
die;
}
##
## ldap_search_s - Synchronous Search
##
if (ldap_search_s($ld,$BASEDN,LDAP_SCOPE_SUBTREE,$filter,$attrs,0,$result) != LDAP_SUCCESS)
{
ldap_perror($ld,"search_s");
die;
}
##
## ldap_count_entries - Count Matched Entries
##
if (($count = ldap_count_entries($ld,$result)) == -1)
{
ldap_perror($ld,"count_entry");
die;
}
##
## first_entry - Get First Matched Entry
## next_entry - Get Next Matched Entry
##
for (my $ent = ldap_first_entry($ld,$result); $ent; $ent = ldap_next_entry($ld,$ent))
{
##
## ldap_get_dn - Get DN for Matched Entries
##
my ($dn,$attr,@vals,$val,$ber);
if (($dn = ldap_get_dn($ld,$ent)) ne "")
{
print "dn: $dn\n";
} else {
ldap_perror($ld,"get_dn");
die;
}
for ($attr = ldap_first_attribute($ld,$ent,$ber); $attr; $attr = ldap_next_attribute($ld,$ent,$ber))
{
##
## ldap_get_values
##
@vals = ldap_get_values($ld,$ent,$attr);
if ($#vals >= 0)
{
foreach $val (@vals)
{
print "$attr: $val\n";
}
}
}
ldap_ber_free($ber,0);
}
ldap_msgfree($result);
##
## Unbind LDAP Connection
##
ldap_unbind($ld);

View File

@@ -0,0 +1,110 @@
#!/usr/bin/perl -w
#############################################################################
# $Id: write.pl,v 1.4 1998-08-13 04:40:02 clayton Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerlDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# write.pl - Test of LDAP Modify Operations in Perl5
# Author: Clayton Donley <donley@wwa.com>
#
# This utility is mostly to demonstrate all the write operations
# that can be done with LDAP through this PERL5 module.
#
#############################################################################
use strict;
use Mozilla::LDAP::API qw(:constant :api);
# This is the entry we will be adding. Do not use a pre-existing entry.
my $ENTRYDN = "cn=Test Guy, o=Org, c=US";
# This is the DN and password for an Administrator
my $ROOTDN = "cn=DSManager,o=Org,c=US";
my $ROOTPW = "";
my $ldap_server = "";
if (!$ldap_server)
{
print "Edit the top portion of this file before continuing.\n";
exit -1;
}
my $ld = ldap_init($ldap_server,LDAP_PORT);
if ($ld == -1)
{
die "Connection to LDAP Server Failed";
}
if (ldap_simple_bind_s($ld,$ROOTDN,$ROOTPW) != LDAP_SUCCESS)
{
ldap_perror($ld,"bind_s");
die;
}
my %testwrite = (
"cn" => "Test User",
"sn" => "User",
"givenName" => "Test",
"telephoneNumber" => "8475551212",
"objectClass" => ["top","person","organizationalPerson",
"inetOrgPerson"],
"mail" => "tuser\@my.org",
);
if (ldap_add_s($ld,$ENTRYDN,\%testwrite) != LDAP_SUCCESS)
{
ldap_perror($ld,"add_s");
die;
}
print "Entry Added.\n";
%testwrite = (
"telephoneNumber" => "7085551212",
"mail" => {"a",["Test_User\@my.org"]},
);
if (ldap_modify_s($ld,$ENTRYDN,\%testwrite) != LDAP_SUCCESS)
{
ldap_perror($ld,"modify_s");
die;
}
print "Entry Modified.\n";
#
# Delete the entry for $ENTRYDN
#
if (ldap_delete_s($ld,$ENTRYDN) != LDAP_SUCCESS)
{
ldap_perror($ld,"delete_s");
die;
}
print "Entry Deleted.\n";
# Unbind to LDAP server
ldap_unbind($ld);
exit;

View File

@@ -0,0 +1,70 @@
#############################################################################
# $Id: typemap,v 1.4 1998-08-13 09:15:00 leif Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.0 (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 PerLDAP. The Initial Developer of the Original
# Code is Netscape Communications Corp. and Clayton Donley. Portions
# created by Netscape are Copyright (C) Netscape Communications
# Corp., portions created by Clayton Donley are Copyright (C) Clayton
# Donley. All Rights Reserved.
#
# Contributor(s):
#
# DESCRIPTION
# Typemap to declare XSUB data types.
#
#############################################################################
const int T_IV
char * T_PV
const char * T_PV
char ** T_charptrptr
LDAP * T_PTR
LDAPMessage * T_PTR
LDAPMessage ** T_PTR
BerElement * T_PTR
LDAPControl * T_PTR
LDAPVersion * T_PTR
struct berval T_berval
struct berval ** T_bervalptrptr
FriendlyMap * T_PTR
LDAPsortkey ** T_PTR
LDAPVirtualList * T_PTR
LDAPURLDesc * T_PTR
LDAPControl ** T_PTR
LDAPFiltDesc * T_PTR
LDAPFiltInfo * T_PTR
LDAPMemCache * T_PTR
LDAPMemCache ** T_PTR
struct ldap_thread_fns * T_PTR
LDAPMod ** T_PTR
LDAP_CMP_CALLBACK * T_PTR
LDAP_REBINDPROC_CALLBACK * T_PTR
struct timeval T_timeval
#########
INPUT
T_timeval
$var.tv_sec = atof((char *)SvPV($arg,na));
$var.tv_usec = 0
T_berval
$var.bv_val = (char *)SvPV($arg,na);
$var.bv_len = na
T_charptrptr
$var = (char **)avref2charptrptr($arg)
T_bervalptrptr
$var = (struct berval **)avref2berptrptr($arg)
OUTPUT
T_charptrptr
$arg = charptrptr2avref($var);
T_bervalptrptr
$arg = berptrptr2avref((struct berval **)$var);

View File

@@ -1,39 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
DIRS = public
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -1,30 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH=..
DIRS= public res src
include <$(DEPTH)\config\rules.mak>

View File

@@ -1,33 +0,0 @@
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/NC-rdf#">
<RDF:Bag ID="NC:SoftwareUpdateRoot">
<RDF:li>
<RDF:Bag ID="NC:NewSoftwareToday" NC:title="New Software">
<RDF:li>
<RDF:Description ID="AimUpdate344">
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
<NC:title>AOL AIM</NC:title>
<NC:description>An Instant Message Client</NC:description>
<NC:version>3.4.1.12</NC:version>
<NC:registryKey>/AOL/AIM/</NC:registryKey>
<NC:url>http://home.netscape.com/index.html</NC:url>
</RDF:Description>
</RDF:li>
<RDF:li>
<RDF:Description ID="PGPPlugin345">
<NC:type resource="http://home.netscape.com/NC-rdf#SoftwarePackage" />
<NC:title>PGP Plugin For Mozilla</NC:title>
<NC:description>A high grade encryption plugin</NC:description>
<NC:version>1.1.2.0</NC:version>
<NC:registryKey>/PGP/ROCKS/</NC:registryKey>
<NC:url>http://home.netscape.com/index.html</NC:url>
</RDF:Description>
</RDF:li>
</RDF:Bag>
</RDF:li>
</RDF:Bag>
</RDF:RDF>

View File

@@ -1,57 +0,0 @@
window {
display: block;
}
tree {
display: table;
background-color: #FFFFFF;
border: none;
border-spacing: 0px;
width: 100%;
}
treecol {
display: table-column;
width: 200px;
}
treeitem {
display: table-row;
}
treehead {
display: table-header-group;
}
treebody {
display: table-row-group;
}
treecell {
display: table-cell;
font-family: Verdana, Sans-Serif;
font-size: 8pt;
}
treecell[selectedcell] {
background-color: yellow;
}
treehead treeitem treecell {
background-color: #c0c0c0;
border: outset 1px;
border-color: white #707070 #707070 white;
padding-left: 4px;
}
treeitem[type="http://home.netscape.com/NC-rdf#SoftwarePackage"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/SoftwareUpdatePackage.gif");
}
treeitem[type="http://home.netscape.com/NC-rdf#Folder"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/bookmark-folder-closed.gif");
treeitem[type="http://home.netscape.com/NC-rdf#Folder"][open="true"] > treecell > titledbutton {
list-style-image: url("resource:/res/rdf/bookmark-folder-open.gif");
}

View File

@@ -1,123 +0,0 @@
// the rdf service
var RDF = Components.classes['component://netscape/rdf/rdf-service'].getService();
RDF = RDF.QueryInterface(Components.interfaces.nsIRDFService);
function getAttr(registry,service,attr_name)
{
var attr = registry.GetTarget(service,
RDF.GetResource('http://home.netscape.com/NC-rdf#' + attr_name),
true);
if (attr)
attr = attr.QueryInterface(Components.interfaces.nsIRDFLiteral);
if (attr)
attr = attr.Value;
return attr;
}
function Init()
{
// this is the main rdf file.
var mainRegistry = RDF.GetDataSource('resource://res/rdf/SoftwareUpdates.rdf');
var mainContainer = Components.classes['component://netscape/rdf/container'].createInstance();
mainContainer = mainContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
mainContainer.Init(mainRegistry, RDF.GetResource('NC:SoftwareUpdateDataSources'));
// Now enumerate all of the softwareupdate datasources.
var mainEnumerator = mainContainer.GetElements();
while (mainEnumerator.HasMoreElements())
{
var aDistributor = mainEnumerator.GetNext();
aDistributor = aDistributor.QueryInterface(Components.interfaces.nsIRDFResource);
var distributorContainer = Components.classes['component://netscape/rdf/container'].createInstance();
distributorContainer = distributorContainer.QueryInterface(Components.interfaces.nsIRDFContainer);
var distributorRegistry = RDF.GetDataSource(aDistributor.Value);
var distributorResource = RDF.GetResource('NC:SoftwareUpdateRoot');
distributorContainer.Init(distributorRegistry, distributorResource);
// Now enumerate all of the distributorContainer's packages.
var distributorEnumerator = distributorContainer.GetElements();
while (distributorEnumerator.HasMoreElements())
{
var aPackage = distributorEnumerator.GetNext();
aPackage = aPackage.QueryInterface(Components.interfaces.nsIRDFResource);
// remove any that we do not want.
if (getAttr(distributorRegistry, aPackage, 'title') == "AOL AIM")
{
//distributorContainer.RemoveElement(aPackage, true);
}
}
var tree = document.getElementById('tree');
// Add it to the tree control's composite datasource.
tree.database.AddDataSource(distributorRegistry);
}
// Install all of the stylesheets in the softwareupdate Registry into the
// panel.
// TODO
// XXX hack to force the tree to rebuild
var treebody = document.getElementById('NC:SoftwareUpdateRoot');
treebody.setAttribute('id', 'NC:SoftwareUpdateRoot');
}
function OpenURL(event, node)
{
if (node.getAttribute('type') == "http://home.netscape.com/NC-rdf#SoftwarePackage")
{
url = node.getAttribute('url');
/*window.open(url,'bookmarks');*/
var toolkitCore = XPAppCoresManager.Find("ToolkitCore");
if (!toolkitCore)
{
toolkitCore = new ToolkitCore();
if (toolkitCore)
{
toolkitCore.Init("ToolkitCore");
}
}
if (toolkitCore)
{
toolkitCore.ShowWindow(url,window);
}
dump("OpenURL(" + url + ")\n");
return true;
}
return false;
}
// To get around "window.onload" not working in viewer.
function Boot()
{
var tree = document.getElementById('tree');
if (tree == null) {
setTimeout(Boot, 0);
}
else {
Init();
}
}
setTimeout('Boot()', 0);

View File

@@ -1,30 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet href="resource:/res/rdf/sidebar.css" type="text/css"?>
<?xml-stylesheet href="resource:/res/rdf/SoftwareUpdate.css" type="text/css"?>
<window
xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<html:script src="SoftwareUpdate.js"/>
<tree id="tree"
flex="100%"
datasources="rdf:softwareupdates"
ondblclick="return OpenURL(event, event.target.parentNode);">
<treecol rdf:resource="http://home.netscape.com/NC-rdf#title" />
<treecol rdf:resource="http://home.netscape.com/NC-rdf#description" />
<treecol rdf:resource="http://home.netscape.com/NC-rdf#version" />
<treehead>
<treeitem>
<treecell>Title</treecell>
<treecell>Description</treecell>
<treecell>Version</treecell>
</treeitem>
</treehead>
<treebody id="NC:SoftwareUpdateRoot" rdf:containment="http://home.netscape.com/NC-rdf#child" />
</tree>
</window>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

View File

@@ -1,7 +0,0 @@
<RDF:RDF xmlns:RDF="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:NC="http://home.netscape.com/softwareupdate-schema#">
<RDF:Bag ID="NC:SoftwareUpdateDataSources">
<RDF:li resource="resource:/res/rdf/SoftwareUpdate-Source-1.rdf" />
</RDF:Bag>
</RDF:RDF>

View File

@@ -1,6 +0,0 @@
#
# This is a list of local files which get copied to the mozilla:dist directory
#
nsISoftwareUpdate.h
nsSoftwareUpdateIIDs.h

View File

@@ -1,47 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
XPIDLSRCS = nsIXPInstallProgress.idl
EXPORTS = \
nsIDOMInstallTriggerGlobal.h \
nsIDOMInstallVersion.h \
nsSoftwareUpdateIIDs.h \
nsISoftwareUpdate.h \
$(NULL)
EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk

View File

@@ -1,113 +0,0 @@
interface Install
{
/* IID: { 0x18c2f988, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int BAD_PACKAGE_NAME = -200;
const int UNEXPECTED_ERROR = -201;
const int ACCESS_DENIED = -202;
const int TOO_MANY_CERTIFICATES = -203; /* Installer file must have 1 certificate */
const int NO_INSTALLER_CERTIFICATE = -204; /* Installer file must have a certificate */
const int NO_CERTIFICATE = -205; /* Extracted file is not signed */
const int NO_MATCHING_CERTIFICATE = -206; /* Extracted file does not match installer certificate */
const int UNKNOWN_JAR_FILE = -207; /* JAR file has not been opened */
const int INVALID_ARGUMENTS = -208; /* Bad arguments to a function */
const int ILLEGAL_RELATIVE_PATH = -209; /* Illegal relative path */
const int USER_CANCELLED = -210; /* User cancelled */
const int INSTALL_NOT_STARTED = -211;
const int SILENT_MODE_DENIED = -212;
const int NO_SUCH_COMPONENT = -213; /* no such component in the registry. */
const int FILE_DOES_NOT_EXIST = -214; /* File cannot be deleted as it does not exist */
const int FILE_READ_ONLY = -215; /* File cannot be deleted as it is read only. */
const int FILE_IS_DIRECTORY = -216; /* File cannot be deleted as it is a directory */
const int NETWORK_FILE_IS_IN_USE = -217; /* File on the network is in-use */
const int APPLE_SINGLE_ERR = -218; /* error in AppleSingle unpacking */
const int INVALID_PATH_ERR = -219; /* GetFolder() did not like the folderID */
const int PATCH_BAD_DIFF = -220; /* error in GDIFF patch */
const int PATCH_BAD_CHECKSUM_TARGET = -221; /* source file doesn't checksum */
const int PATCH_BAD_CHECKSUM_RESULT = -222; /* final patched file fails checksum */
const int UNINSTALL_FAILED = -223; /* error while uninstalling a package */
const int GESTALT_UNKNOWN_ERR = -5550;
const int GESTALT_INVALID_ARGUMENT = -5551;
const int SUCCESS = 0;
const int REBOOT_NEEDED = 999;
/* install types */
const int LIMITED_INSTALL = 0;
const int FULL_INSTALL = 1;
const int NO_STATUS_DLG = 2;
const int NO_FINALIZE_DLG = 4;
// these should not be public...
/* message IDs*/
const int SU_INSTALL_FILE_UNEXPECTED_MSG_ID = 0;
const int SU_DETAILS_REPLACE_FILE_MSG_ID = 1;
const int SU_DETAILS_INSTALL_FILE_MSG_ID = 2;
//////////////////////////
readonly attribute wstring UserPackageName;
readonly attribute wstring RegPackageName;
void Install();
void AbortInstall();
long AddDirectory( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring subdir,
in boolean forceMode );
long AddSubcomponent( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring targetName,
in boolean forceMode );
long DeleteComponent( in wstring registryName);
long DeleteFile( in InstallFolder folder,
in wstring relativeFileName );
long DiskSpaceAvailable( in InstallFolder folder );
long Execute(in wstring jarSource, in wstring args);
long FinalizeInstall();
long Gestalt (in wstring selector);
InstallFolder GetComponentFolder( in wstring regName,
in wstring subdirectory);
InstallFolder GetFolder(in wstring targetFolder,
in wstring subdirectory);
long GetLastError();
long GetWinProfile(in InstallFolder folder, in wstring file);
long GetWinRegistry();
long Patch( in wstring regName,
in wstring version,
in wstring jarSource,
in InstallFolder folder,
in wstring targetName );
void ResetError();
void SetPackageFolder( in InstallFolder folder );
long StartInstall( in wstring userPackageName,
in wstring packageName,
in wstring version,
in long flags );
long Uninstall( in wstring packageName);
};

View File

@@ -1,24 +0,0 @@
interface InstallTriggerGlobal
{
/* IID: { 0x18c2f987, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int MAJOR_DIFF = 4;
const int MINOR_DIFF = 3;
const int REL_DIFF = 2;
const int BLD_DIFF = 1;
const int EQUAL = 0;
boolean UpdateEnabled ();
long StartSoftwareUpdate(in wstring URL);
long ConditionalSoftwareUpdate( in wstring URL,
in wstring regName,
in long diffLevel,
in wstring version,
in long mode);
long CompareVersion( in wstring regName, in wstring version );
};

View File

@@ -1,34 +0,0 @@
interface InstallVersion
{
/* IID: { 0x18c2f986, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}} */
const int EQUAL = 0;
const int BLD_DIFF = 1;
const int BLD_DIFF_MINUS = -1;
const int REL_DIFF = 2;
const int REL_DIFF_MINUS = -2;
const int MINOR_DIFF = 3;
const int MINOR_DIFF_MINUS = -3;
const int MAJOR_DIFF = 4;
const int MAJOR_DIFF_MINUS = -4;
attribute int major;
attribute int minor;
attribute int release;
attribute int build;
void InstallVersion();
void init(in wstring versionString);
/*
void init(in int major, in int minor, in int release, in int build);
*/
wstring toString();
/* int compareTo(in wstring version);
int compareTo(in int major, in int minor, in int release, in int build);
*/
int compareTo(in InstallVersion versionObject);
};

View File

@@ -1,36 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
MODULE=xpinstall
DEPTH=..\..
EXPORTS= nsIDOMInstallTriggerGlobal.h \
nsIDOMInstallVersion.h \
nsSoftwareUpdateIIDs.h \
nsISoftwareUpdate.h
XPIDLSRCS = .\nsIXPInstallProgress.idl
include <$(DEPTH)\config\config.mak>
include <$(DEPTH)\config\rules.mak>

View File

@@ -1 +0,0 @@
#error

View File

@@ -1,96 +0,0 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMInstallTriggerGlobal_h__
#define nsIDOMInstallTriggerGlobal_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
#define NS_IDOMINSTALLTRIGGERGLOBAL_IID \
{ 0x18c2f987, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
class nsIDOMInstallTriggerGlobal : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLTRIGGERGLOBAL_IID; return iid; }
enum {
MAJOR_DIFF = 4,
MINOR_DIFF = 3,
REL_DIFF = 2,
BLD_DIFF = 1,
EQUAL = 0
};
NS_IMETHOD UpdateEnabled(PRBool* aReturn)=0;
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)=0;
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)=0;
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)=0;
};
#define NS_DECL_IDOMINSTALLTRIGGERGLOBAL \
NS_IMETHOD UpdateEnabled(PRBool* aReturn); \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn); \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn); \
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn); \
#define NS_FORWARD_IDOMINSTALLTRIGGERGLOBAL(_to) \
NS_IMETHOD UpdateEnabled(PRBool* aReturn) { return _to##UpdateEnabled(aReturn); } \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aFlags, aReturn); } \
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn) { return _to##StartSoftwareUpdate(aURL, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aRegName, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, nsIDOMInstallVersion* aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aMode, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##ConditionalSoftwareUpdate(aURL, aDiffLevel, aVersion, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aMajor, aMinor, aRelease, aBuild, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn) { return _to##CompareVersion(aRegName, aVersion, aReturn); } \
extern nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallTriggerGlobal_h__

View File

@@ -1,107 +0,0 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#ifndef nsIDOMInstallVersion_h__
#define nsIDOMInstallVersion_h__
#include "nsISupports.h"
#include "nsString.h"
#include "nsIScriptContext.h"
class nsIDOMInstallVersion;
#define NS_IDOMINSTALLVERSION_IID \
{ 0x18c2f986, 0xb09f, 0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}}
class nsIDOMInstallVersion : public nsISupports {
public:
static const nsIID& IID() { static nsIID iid = NS_IDOMINSTALLVERSION_IID; return iid; }
enum {
EQUAL = 0,
BLD_DIFF = 1,
BLD_DIFF_MINUS = -1,
REL_DIFF = 2,
REL_DIFF_MINUS = -2,
MINOR_DIFF = 3,
MINOR_DIFF_MINUS = -3,
MAJOR_DIFF = 4,
MAJOR_DIFF_MINUS = -4
};
NS_IMETHOD GetMajor(PRInt32* aMajor)=0;
NS_IMETHOD SetMajor(PRInt32 aMajor)=0;
NS_IMETHOD GetMinor(PRInt32* aMinor)=0;
NS_IMETHOD SetMinor(PRInt32 aMinor)=0;
NS_IMETHOD GetRelease(PRInt32* aRelease)=0;
NS_IMETHOD SetRelease(PRInt32 aRelease)=0;
NS_IMETHOD GetBuild(PRInt32* aBuild)=0;
NS_IMETHOD SetBuild(PRInt32 aBuild)=0;
NS_IMETHOD Init(const nsString& aVersionString)=0;
NS_IMETHOD ToString(nsString& aReturn)=0;
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn)=0;
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)=0;
};
#define NS_DECL_IDOMINSTALLVERSION \
NS_IMETHOD GetMajor(PRInt32* aMajor); \
NS_IMETHOD SetMajor(PRInt32 aMajor); \
NS_IMETHOD GetMinor(PRInt32* aMinor); \
NS_IMETHOD SetMinor(PRInt32 aMinor); \
NS_IMETHOD GetRelease(PRInt32* aRelease); \
NS_IMETHOD SetRelease(PRInt32 aRelease); \
NS_IMETHOD GetBuild(PRInt32* aBuild); \
NS_IMETHOD SetBuild(PRInt32 aBuild); \
NS_IMETHOD Init(const nsString& aVersionString); \
NS_IMETHOD ToString(nsString& aReturn); \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn); \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn); \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn); \
#define NS_FORWARD_IDOMINSTALLVERSION(_to) \
NS_IMETHOD GetMajor(PRInt32* aMajor) { return _to##GetMajor(aMajor); } \
NS_IMETHOD SetMajor(PRInt32 aMajor) { return _to##SetMajor(aMajor); } \
NS_IMETHOD GetMinor(PRInt32* aMinor) { return _to##GetMinor(aMinor); } \
NS_IMETHOD SetMinor(PRInt32 aMinor) { return _to##SetMinor(aMinor); } \
NS_IMETHOD GetRelease(PRInt32* aRelease) { return _to##GetRelease(aRelease); } \
NS_IMETHOD SetRelease(PRInt32 aRelease) { return _to##SetRelease(aRelease); } \
NS_IMETHOD GetBuild(PRInt32* aBuild) { return _to##GetBuild(aBuild); } \
NS_IMETHOD SetBuild(PRInt32 aBuild) { return _to##SetBuild(aBuild); } \
NS_IMETHOD Init(const nsString& aVersionString) { return _to##Init(aVersionString); } \
NS_IMETHOD ToString(nsString& aReturn) { return _to##ToString(aReturn); } \
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersionObject, PRInt32* aReturn) { return _to##CompareTo(aVersionObject, aReturn); } \
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn) { return _to##CompareTo(aString, aReturn); } \
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn) { return _to##CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn); } \
extern nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype);
extern "C" NS_DOM nsresult NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn);
#endif // nsIDOMInstallVersion_h__

View File

@@ -1,85 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsISoftwareUpdate_h__
#define nsISoftwareUpdate_h__
#include "nsISupports.h"
#include "nsIFactory.h"
#include "nsString.h"
#include "nsIXPInstallProgress.h"
#define NS_IXPINSTALLCOMPONENT_PROGID NS_IAPPSHELLCOMPONENT_PROGID "/xpinstall"
#define NS_IXPINSTALLCOMPONENT_CLASSNAME "Mozilla XPInstall Component"
#define NS_ISOFTWAREUPDATE_IID \
{ 0x18c2f992, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53}\
}
class nsISoftwareUpdate : public nsISupports
{
public:
NS_DEFINE_STATIC_IID_ACCESSOR(NS_ISOFTWAREUPDATE_IID)
NS_IMETHOD InstallJar(const nsString& fromURL,
const nsString& localFile,
long flags) = 0;
NS_IMETHOD RegisterNotifier(nsIXPInstallProgress *notifier) = 0;
NS_IMETHOD InstallPending(void) = 0;
/* FIX: these should be in a private interface */
NS_IMETHOD InstallJarCallBack() = 0;
NS_IMETHOD GetTopLevelNotifier(nsIXPInstallProgress **notifier) = 0;
};
class nsSoftwareUpdateFactory : public nsIFactory
{
public:
nsSoftwareUpdateFactory();
virtual ~nsSoftwareUpdateFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif // nsISoftwareUpdate_h__

View File

@@ -1,30 +0,0 @@
/* -*- Mode: IDL; 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 "nsISupports.idl"
[uuid(eea90d40-b059-11d2-915e-c12b696c9333)]
interface nsIXPInstallProgress : nsISupports
{
void BeforeJavascriptEvaluation();
void AfterJavascriptEvaluation();
void InstallStarted([const] in string UIPackageName);
void ItemScheduled([const] in string message );
void InstallFinalization([const] in string message, in long itemNum, in long totNum );
void InstallAborted();
};

View File

@@ -1,93 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsIXPInstallProgressNotifier_h__
#define nsIXPInstallProgressNotifier_h__
class nsIXPInstallProgressNotifier
{
public:
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : BeforeJavascriptEvaluation
// Description : This will be called when prior to the install script being evaluate
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void BeforeJavascriptEvaluation(void) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : AfterJavascriptEvaluation
// Description : This will be called after the install script has being evaluated
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void AfterJavascriptEvaluation(void) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallStarted
// Description : This will be called when StartInstall has been called
// Return type : void
// Argument : char* UIPackageName - User Package Name
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallStarted(const char* UIPackageName) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : ItemScheduled
// Description : This will be called when items are being scheduled
// Return type : Any value returned other than zero, will be treated as an error and the script will be aborted
// Argument : The message that should be displayed to the user
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual long ItemScheduled( const char* message ) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallFinalization
// Description : This will be called when the installation is in its Finalize stage
// Return type : void
// Argument : char* message - The message that should be displayed to the user
// Argument : long itemNum - This is the current item number
// Argument : long totNum - This is the total number of items
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallFinalization( const char* message, long itemNum, long totNum ) = 0;
///////////////////////////////////////////////////////////////////////////////////////////////////////
// Function name : InstallAborted
// Description : This will be called when the install is aborted
// Return type : void
// Argument : void
///////////////////////////////////////////////////////////////////////////////////////////////////////
virtual void InstallAborted(void) = 0;
};
#endif

View File

@@ -1,64 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsSoftwareUpdateIIDs_h___
#define nsSoftwareUpdateIIDs_h___
#define NS_SoftwareUpdate_CID \
{ /* 18c2f989-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f989, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstall_CID \
{ /* 18c2f98b-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98b, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallTrigger_CID \
{ /* 18c2f98d-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98d, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#define NS_SoftwareUpdateInstallVersion_CID \
{ /* 18c2f98f-b09f-11d2-bcde-00805f0e1353 */ \
0x18c2f98f, \
0xb09f, \
0x11d2, \
{0xbc, 0xde, 0x00, 0x80, 0x5f, 0x0e, 0x13, 0x53} \
}
#endif /* nsSoftwareUpdateIIDs_h___ */

View File

@@ -1,3 +0,0 @@
progress.xul
progress.css
progress.html

View File

@@ -1,34 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=../..
topsrcdir = @top_srcdir@
srcdir = @srcdir@
VPATH = @srcdir@
include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/config.mk
include $(topsrcdir)/config/rules.mk
EXPORT_RESOURCE_XPINSTALL = \
$(srcdir)/progress.xul \
$(srcdir)/progress.html \
$(srcdir)/progress.css \
$(NULL)
install::
$(INSTALL) $(EXPORT_RESOURCE_XPINSTALL) $(DIST)/bin/res/xpinstall

View File

@@ -1,31 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH=..\..
IGNORE_MANIFEST=1
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) progress.xul $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.css $(DIST)\bin\res\xpinstall
$(MAKE_INSTALL) progress.html $(DIST)\bin\res\xpinstall
clobber::
rm -f $(DIST)\res\xpinstall\progress.xul
rm -f $(DIST)\res\xpinstall\progress.css
rm -f $(DIST)\res\xpinstall\progress.html

View File

@@ -1,3 +0,0 @@
TD {
font: 10pt sans-serif;
}

View File

@@ -1,16 +0,0 @@
<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<body bgcolor="#C0C0C0" style="overflow:visible; margin: 0px; color-background: rgb(192,192,192);">
<center>
<table BORDER COLS=5 WIDTH="99%" style="color-background:rgb(192,192,192);">
<tr>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="3%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="10%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
<td WIDTH="81%" NOWRAP style="border: 1px inset rgb(192,192,192);">&nbsp</td>
</tr>
</table>
</center>
</body>
</html>

View File

@@ -1,67 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet href="../samples/xul.css" type="text/css"?>
<?xml-stylesheet href="progress.css" type="text/css"?>
<!DOCTYPE window
[
<!ENTITY downloadWindow.title "XPInstall Progress">
<!ENTITY status "Status:">
<!ENTITY cancelButtonTitle "Cancel">
]
>
<window xmlns:html="http://www.w3.org/TR/REC-html40"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="XPInstall Progress"
width="425"
height="225">
<data>
<broadcaster id="data.canceled" type="string" value="false"/>
</data>
<html:script>
function cancelInstall()
{
var cancelData = document.getElementById("data.canceled");
cancelData.setAttribute( "value", "true");
}
</html:script>
<html:center>
<html:table style="width:100%;">
<html:tr>
<html:td align="center">
<html:input id="dialog.uiPackageName" readonly="" style="background-color:lightgray;width:300px;"/>
</html:td>
</html:tr>
<html:tr>
<html:td nowrap="" style="border: 1px rgb(192,192,192);" align="center">
<html:input id="dialog.currentAction" readonly="" style="background-color:lightgray;width:450px;"/>
</html:td>
</html:tr>
<html:tr>
<html:td align="center" width="15%" nowrap="" style="border: 1px rgb(192,192,192);">
<progressmeter id="dialog.progress" mode="undetermined" style="width:300px;height:16px;">
</progressmeter>
</html:td>
</html:tr>
<html:tr>
<html:td align="center" width="3%" nowrap="" style="border: 1px rgb(192,192,192);">
<html:button onclick="cancelInstall()" height="12">
&cancelButtonTitle;
</html:button>
</html:td>
</html:tr>
</html:table>
</html:center>
</window>

View File

@@ -1,61 +0,0 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH = ../..
topsrcdir = @top_srcdir@
VPATH = @srcdir@
srcdir = @srcdir@
include $(DEPTH)/config/autoconf.mk
MODULE = xpinstall
LIBRARY_NAME = xpinstall
IS_COMPONENT = 1
REQUIRES = dom js netlib raptor xpcom
CPPSRCS = \
nsSoftwareUpdate.cpp \
nsInstall.cpp \
nsInstallDelete.cpp \
nsInstallExecute.cpp \
nsInstallFile.cpp \
nsInstallFolder.cpp \
nsInstallPatch.cpp \
nsInstallUninstall.cpp \
nsInstallTrigger.cpp \
nsInstallResources.cpp \
nsJSInstall.cpp \
nsJSInstallTriggerGlobal.cpp\
nsSoftwareUpdateRun.cpp \
nsSoftwareUpdateStream.cpp \
nsTopProgressNotifier.cpp \
nsLoggingProgressNotifier \
ScheduledTasks.cpp \
nsInstallFileOpItem.cpp \
$(NULL)
INCLUDES += -I$(srcdir)/../public
include $(topsrcdir)/config/rules.mk

File diff suppressed because it is too large Load Diff

View File

@@ -1,233 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef SU_PAS_H
#define SU_PAS_H
#include <Errors.h>
#include <Types.h>
#include <Files.h>
#include <Script.h>
#include <Resources.h>
typedef struct PASHeader /* header portion of Patchable AppleSingle */
{
UInt32 magicNum; /* internal file type tag = 0x00244200*/
UInt32 versionNum; /* format version: 1 = 0x00010000 */
UInt8 filler[16]; /* filler */
UInt16 numEntries; /* number of entries which follow */
} PASHeader ;
typedef struct PASEntry /* one Patchable AppleSingle entry descriptor */
{
UInt32 entryID; /* entry type: see list, 0 invalid */
UInt32 entryOffset; /* offset, in bytes, from beginning */
/* of file to this entry's data */
UInt32 entryLength; /* length of data in octets */
} PASEntry;
typedef struct PASMiscInfo
{
short fileHasResFork;
short fileResAttrs;
OSType fileType;
OSType fileCreator;
UInt32 fileFlags;
} PASMiscInfo;
typedef struct PASResFork
{
short NumberOfTypes;
} PASResFork;
typedef struct PASResource
{
short attr;
short attrID;
OSType attrType;
Str255 attrName;
unsigned long length;
} PASResource;
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
#define kCreator 'MOSS'
#define kType 'PASf'
#define PAS_BUFFER_SIZE (1024*512)
#define PAS_MAGIC_NUM (0x00244200)
#define PAS_VERSION (0x00010000)
enum
{
ePas_Data = 1,
ePas_Misc,
ePas_Resource
};
#ifdef __cplusplus
extern "C" {
#endif
/* Prototypes */
OSErr PAS_EncodeFile(FSSpec *inSpec, FSSpec *outSpec);
OSErr PAS_DecodeFile(FSSpec *inSpec, FSSpec *outSpec);
#ifdef __cplusplus
}
#endif
#endif /* SU_PAS_H */

View File

@@ -1,380 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nscore.h"
#include "NSReg.h"
#include "nsFileSpec.h"
#include "nsFileStream.h"
#include "nsInstall.h" // for error codes
#include "prmem.h"
#include "ScheduledTasks.h"
#ifdef _WINDOWS
#include <sys/stat.h>
#include <windows.h>
BOOL WIN32_IsMoveFileExBroken()
{
/* the NT option MOVEFILE_DELAY_UNTIL_REBOOT is broken on
* Windows NT 3.51 Service Pack 4 and NT 4.0 before Service Pack 2
*/
BOOL broken = FALSE;
OSVERSIONINFO osinfo;
// they *all* appear broken--better to have one way that works.
return TRUE;
osinfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
if (GetVersionEx(&osinfo) && osinfo.dwPlatformId == VER_PLATFORM_WIN32_NT)
{
if ( osinfo.dwMajorVersion == 3 && osinfo.dwMinorVersion == 51 )
{
if ( 0 == stricmp(osinfo.szCSDVersion,"Service Pack 4"))
{
broken = TRUE;
}
}
else if ( osinfo.dwMajorVersion == 4 )
{
if (osinfo.szCSDVersion[0] == '\0' ||
(0 == stricmp(osinfo.szCSDVersion,"Service Pack 1")))
{
broken = TRUE;
}
}
}
return broken;
}
PRInt32 DoWindowsReplaceExistingFileStuff(const char* currentName, const char* finalName)
{
PRInt32 err = 0;
char* final = strdup(finalName);
char* current = strdup(currentName);
/* couldn't delete, probably in use. Schedule for later */
DWORD dwVersion, dwWindowsMajorVersion;
/* Get OS version info */
dwVersion = GetVersion();
dwWindowsMajorVersion = (DWORD)(LOBYTE(LOWORD(dwVersion)));
/* Get build numbers for Windows NT or Win32s */
if (dwVersion < 0x80000000) // Windows NT
{
/* On Windows NT */
if ( WIN32_IsMoveFileExBroken() )
{
/* the MOVEFILE_DELAY_UNTIL_REBOOT option doesn't work on
* NT 3.51 SP4 or on NT 4.0 until SP2
*/
struct stat statbuf;
PRBool nameFound = PR_FALSE;
char tmpname[_MAX_PATH];
strncpy( tmpname, finalName, _MAX_PATH );
int len = strlen(tmpname);
while (!nameFound && len < _MAX_PATH )
{
tmpname[len-1] = '~';
tmpname[len] = '\0';
if ( stat(tmpname, &statbuf) != 0 )
nameFound = TRUE;
else
len++;
}
if ( nameFound )
{
if ( MoveFile( finalName, tmpname ) )
{
if ( MoveFile( currentName, finalName ) )
{
DeleteFileNowOrSchedule(nsFileSpec(tmpname));
}
else
{
/* 2nd move failed, put old file back */
MoveFile( tmpname, finalName );
}
}
else
{
/* non-executable in use; schedule for later */
return -1; // let the start registry stuff do our work!
}
}
}
else if ( MoveFileEx(currentName, finalName, MOVEFILE_DELAY_UNTIL_REBOOT) )
{
err = 0;
}
}
else // Windows 95 or Win16
{
/*
* Place an entry in the WININIT.INI file in the Windows directory
* to delete finalName and rename currentName to be finalName at reboot
*/
int strlen;
char Src[_MAX_PATH]; // 8.3 name
char Dest[_MAX_PATH]; // 8.3 name
strlen = GetShortPathName( (LPCTSTR)currentName, (LPTSTR)Src, (DWORD)sizeof(Src) );
if ( strlen > 0 )
{
free(current);
current = strdup(Src);
}
strlen = GetShortPathName( (LPCTSTR) finalName, (LPTSTR) Dest, (DWORD) sizeof(Dest));
if ( strlen > 0 )
{
free(final);
final = strdup(Dest);
}
/* NOTE: use OEM filenames! Even though it looks like a Windows
* .INI file, WININIT.INI is processed under DOS
*/
AnsiToOem( final, final );
AnsiToOem( current, current );
if ( WritePrivateProfileString( "Rename", final, current, "WININIT.INI" ) )
err = 0;
}
free(final);
free(current);
return err;
}
#endif
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename)
{
REGERR result = 0;
filename.Delete(false);
if (filename.Exists())
{
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY, &newkey) )
{
// FIX should be using nsPersistentFileDescriptor!!!
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)filename.GetNativePathCString(), REGTYPE_ENTRY_FILE, nsnull, 0);
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
}
return result;
}
/* tmp file is the bad one that we want to replace with target. */
REGERR ReplaceFileNowOrSchedule(nsFileSpec& replacementFile, nsFileSpec& doomedFile )
{
REGERR result = 0;
if(replacementFile == doomedFile)
{
/* do not have to do anything */
return result;
}
doomedFile.Delete(false);
if (! doomedFile.Exists() )
{
// Now that we have move the existing file, we can move the mExtracedFile into place.
nsFileSpec parentofFinalFile;
doomedFile.GetParent(parentofFinalFile);
result = replacementFile.Move(parentofFinalFile);
if ( NS_SUCCEEDED(result) )
{
char* leafName = doomedFile.GetLeafName();
replacementFile.Rename(leafName);
nsCRT::free(leafName);
}
}
else
{
#ifdef _WINDOWS
if (DoWindowsReplaceExistingFileStuff(replacementFile.GetNativePathCString(), doomedFile.GetNativePathCString()) == 0)
return 0;
#endif
RKEY newkey;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) )
{
result = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey);
if ( result == REGERR_OK )
{
char* replacementFileName = (char*)(const char*)replacementFile.GetNativePathCString();
result = NR_RegSetEntry( reg, newkey, (char*)(const char*)doomedFile.GetNativePathCString(), REGTYPE_ENTRY_FILE, replacementFileName, strlen(replacementFileName));
if (result == REGERR_OK)
result = nsInstall::REBOOT_NEEDED;
}
NR_RegClose(reg);
}
}
return result;
}
void DeleteScheduledFiles(void);
void ReplaceScheduledFiles(void);
extern "C" void PerformScheduledTasks(void *data)
{
DeleteScheduledFiles();
ReplaceScheduledFiles();
}
void DeleteScheduledFiles(void)
{
HREG reg;
if (REGERR_OK == NR_RegOpen("", &reg))
{
RKEY key;
REGENUM state;
/* perform scheduled file deletions and replacements (PC only) */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY,&key))
{
char buf[MAXREGNAMELEN];
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, buf, sizeof(buf), NULL ))
{
nsFileSpec doomedFile(buf);
doomedFile.Delete(PR_FALSE);
if (! doomedFile.Exists())
{
NR_RegDeleteEntry( reg, key, buf );
}
}
/* delete list node if empty */
if (REGERR_NOMORE == NR_RegEnumEntries( reg, key, &state, buf, sizeof(buf), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_DELETE_LIST_KEY);
}
}
NR_RegClose(reg);
}
}
void ReplaceScheduledFiles(void)
{
HREG reg;
if (REGERR_OK == NR_RegOpen("", &reg))
{
RKEY key;
REGENUM state;
/* replace files if any listed */
if (REGERR_OK == NR_RegGetKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &key))
{
char tmpfile[MAXREGNAMELEN];
char target[MAXREGNAMELEN];
state = 0;
while (REGERR_OK == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
{
nsFileSpec replaceFile(tmpfile);
if (! replaceFile.Exists() )
{
NR_RegDeleteEntry( reg, key, tmpfile );
}
else if ( REGERR_OK != NR_RegGetEntryString( reg, key, tmpfile, target, sizeof(target) ) )
{
/* can't read target filename, corruption? */
NR_RegDeleteEntry( reg, key, tmpfile );
}
else
{
nsFileSpec targetFile(target);
targetFile.Delete(PR_FALSE);
if (!targetFile.Exists())
{
nsFileSpec parentofTarget;
targetFile.GetParent(parentofTarget);
nsresult result = replaceFile.Move(parentofTarget);
if ( NS_SUCCEEDED(result) )
{
char* leafName = targetFile.GetLeafName();
replaceFile.Rename(leafName);
nsCRT::free(leafName);
NR_RegDeleteEntry( reg, key, tmpfile );
}
}
}
}
/* delete list node if empty */
if (REGERR_NOMORE == NR_RegEnumEntries(reg, key, &state, tmpfile, sizeof(tmpfile), NULL ))
{
NR_RegDeleteKey(reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY);
}
}
NR_RegClose(reg);
}
}

View File

@@ -1,42 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __SCHEDULEDTASKS_H__
#define __SCHEDULEDTASKS_H__
#include "NSReg.h"
#include "nsFileSpec.h"
REGERR DeleteFileNowOrSchedule(nsFileSpec& filename);
REGERR ReplaceFileNowOrSchedule(nsFileSpec& tmpfile, nsFileSpec& target );
extern "C" void PerformScheduledTasks(void *data);
#endif

View File

@@ -1,135 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*--------------------------------------------------------------
* GDIFF.H
*
* Constants used in processing the GDIFF format
*--------------------------------------------------------------*/
#include "prio.h"
#include "nsFileSpec.h"
#define GDIFF_MAGIC "\xD1\xFF\xD1\xFF"
#define GDIFF_MAGIC_LEN 4
#define GDIFF_VER 5
#define GDIFF_EOF "\0"
#define GDIFF_VER_POS 4
#define GDIFF_CS_POS 5
#define GDIFF_CSLEN_POS 6
#define GDIFF_HEADERSIZE 7
#define GDIFF_APPDATALEN 4
#define GDIFF_CS_NONE 0
#define GDIFF_CS_MD5 1
#define GDIFF_CS_SHA 2
#define GDIFF_CS_CRC32 32
#define CRC32_LEN 4
/*--------------------------------------
* GDIFF opcodes
*------------------------------------*/
#define ENDDIFF 0
#define ADD8MAX 246
#define ADD16 247
#define ADD32 248
#define COPY16BYTE 249
#define COPY16SHORT 250
#define COPY16LONG 251
#define COPY32BYTE 252
#define COPY32SHORT 253
#define COPY32LONG 254
#define COPY64 255
/* instruction sizes */
#define ADD16SIZE 2
#define ADD32SIZE 4
#define COPY16BYTESIZE 3
#define COPY16SHORTSIZE 4
#define COPY16LONGSIZE 6
#define COPY32BYTESIZE 5
#define COPY32SHORTSIZE 6
#define COPY32LONGSIZE 8
#define COPY64SIZE 12
/*--------------------------------------
* error codes
*------------------------------------*/
#define GDIFF_OK 0
#define GDIFF_ERR_UNKNOWN -1
#define GDIFF_ERR_ARGS -2
#define GDIFF_ERR_ACCESS -3
#define GDIFF_ERR_MEM -4
#define GDIFF_ERR_HEADER -5
#define GDIFF_ERR_BADDIFF -6
#define GDIFF_ERR_OPCODE -7
#define GDIFF_ERR_OLDFILE -8
#define GDIFF_ERR_CHKSUMTYPE -9
#define GDIFF_ERR_CHECKSUM -10
#define GDIFF_ERR_CHECKSUM_TARGET -11
#define GDIFF_ERR_CHECKSUM_RESULT -12
/*--------------------------------------
* types
*------------------------------------*/
#ifndef AIX
#ifdef OSF1
#include <sys/types.h>
#else
typedef unsigned char uchar;
#endif
#endif
typedef struct _diffdata {
PRFileDesc* fSrc;
PRFileDesc* fOut;
PRFileDesc* fDiff;
uint8 checksumType;
uint8 checksumLength;
uchar* oldChecksum;
uchar* newChecksum;
PRBool bMacAppleSingle;
PRBool bWin32BoundImage;
uchar* databuf;
uint32 bufsize;
} DIFFDATA;
typedef DIFFDATA* pDIFFDATA;
/*--------------------------------------
* miscellaneous
*------------------------------------*/
#define APPFLAG_W32BOUND "autoinstall:Win32PE"
#define APPFLAG_APPLESINGLE "autoinstall:AppleSingle"
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

View File

@@ -1,111 +0,0 @@
#!nmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "License"); you may not use this file except in
# compliance with the License. You may obtain a copy of the License at
# http://www.mozilla.org/NPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is Mozilla Communicator client code,
# released March 31, 1998.
#
# The Initial Developer of the Original Code is Netscape Communications
# Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
#
# Contributors:
# Daniel Veditz <dveditz@netscape.com>
# Douglas Turner <dougt@netscape.com>
DEPTH=..\..
IGNORE_MANIFEST=1
MAKE_OBJ_TYPE = DLL
MODULE=xpinstall
DLL=.\$(OBJDIR)\$(MODULE).dll
DEFINES=-D_IMPL_NS_DOM -DWIN32_LEAN_AND_MEAN
LCFLAGS = \
$(LCFLAGS) \
$(DEFINES) \
$(NULL)
LINCS= \
-I$(PUBLIC)\xpinstall \
-I$(PUBLIC)\jar \
-I$(PUBLIC)\libreg \
-I$(PUBLIC)\netlib \
-I$(PUBLIC)\xpcom \
-I$(PUBLIC)\pref \
-I$(PUBLIC)\rdf \
-I$(PUBLIC)\js \
-I$(PUBLIC)\dom \
-I$(PUBLIC)\raptor \
-I$(PUBLIC)\nspr2 \
-I$(PUBLIC)\zlib \
-I$(PUBLIC)\xpfe\components \
$(NULL)
LLIBS = \
$(DIST)\lib\jar50.lib \
$(DIST)\lib\libreg32.lib \
$(DIST)\lib\netlib.lib \
$(DIST)\lib\xpcom.lib \
$(DIST)\lib\js3250.lib \
$(DIST)\lib\jsdombase_s.lib \
$(DIST)\lib\jsdomevents_s.lib \
$(DIST)\lib\zlib.lib \
$(DIST)\lib\plc3.lib \
$(LIBNSPR) \
$(NULL)
OBJS = \
.\$(OBJDIR)\nsInstall.obj \
.\$(OBJDIR)\nsInstallTrigger.obj \
.\$(OBJDIR)\nsInstallVersion.obj \
.\$(OBJDIR)\nsInstallFolder.obj \
.\$(OBJDIR)\nsJSInstall.obj \
.\$(OBJDIR)\nsJSInstallTriggerGlobal.obj \
.\$(OBJDIR)\nsJSInstallVersion.obj \
.\$(OBJDIR)\nsSoftwareUpdate.obj \
.\$(OBJDIR)\nsSoftwareUpdateRun.obj \
.\$(OBJDIR)\nsSoftwareUpdateStream.obj \
.\$(OBJDIR)\nsInstallFile.obj \
.\$(OBJDIR)\nsInstallDelete.obj \
.\$(OBJDIR)\nsInstallExecute.obj \
.\$(OBJDIR)\nsInstallPatch.obj \
.\$(OBJDIR)\nsInstallUninstall.obj \
.\$(OBJDIR)\nsInstallResources.obj \
.\$(OBJDIR)\nsTopProgressNotifier.obj \
.\$(OBJDIR)\nsLoggingProgressNotifier.obj\
.\$(OBJDIR)\ScheduledTasks.obj \
.\$(OBJDIR)\nsWinReg.obj \
.\$(OBJDIR)\nsJSWinReg.obj \
.\$(OBJDIR)\nsWinRegItem.obj \
.\$(OBJDIR)\nsWinRegValue.obj \
.\$(OBJDIR)\nsWinProfile.obj \
.\$(OBJDIR)\nsJSWinProfile.obj \
.\$(OBJDIR)\nsWinProfileItem.obj \
.\$(OBJDIR)\nsInstallProgressDialog.obj \
.\$(OBJDIR)\nsInstallFileOpItem.obj \
$(NULL)
include <$(DEPTH)\config\rules.mak>
install:: $(DLL)
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).lib $(DIST)\lib
$(MAKE_INSTALL) .\$(OBJDIR)\$(MODULE).dll $(DIST)\bin\components
clobber::
rm -f $(DIST)\lib\$(MODULE).lib
rm -f $(DIST)\bin\components\$(MODULE).dll

File diff suppressed because it is too large Load Diff

View File

@@ -1,265 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALL_H__
#define __NS_INSTALL_H__
#include "nscore.h"
#include "nsISupports.h"
#include "jsapi.h"
#include "plevent.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsVector.h"
#include "nsHashtable.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstallVersion.h"
#include "nsIXPInstallProgress.h"
class nsInstallInfo
{
public:
nsInstallInfo(const nsString& fromURL, const nsString& localFile, long flags);
nsInstallInfo(nsVector* fromURL, nsVector* localFiles, long flags);
virtual ~nsInstallInfo();
nsString& GetFromURL(PRUint32 index = 0);
nsString& GetLocalFile(PRUint32 index = 0);
void GetArguments(nsString& args, PRUint32 index = 0);
long GetFlags();
PRBool IsMultipleTrigger();
static void DeleteVector(nsVector* vector);
private:
PRBool mMultipleTrigger;
nsresult mError;
long mFlags;
nsVector *mFromURLs;
nsVector *mLocalFiles;
};
class nsInstall
{
friend class nsWinReg;
friend class nsWinProfile;
public:
enum
{
BAD_PACKAGE_NAME = -200,
UNEXPECTED_ERROR = -201,
ACCESS_DENIED = -202,
TOO_MANY_CERTIFICATES = -203,
NO_INSTALLER_CERTIFICATE = -204,
NO_CERTIFICATE = -205,
NO_MATCHING_CERTIFICATE = -206,
UNKNOWN_JAR_FILE = -207,
INVALID_ARGUMENTS = -208,
ILLEGAL_RELATIVE_PATH = -209,
USER_CANCELLED = -210,
INSTALL_NOT_STARTED = -211,
SILENT_MODE_DENIED = -212,
NO_SUCH_COMPONENT = -213,
FILE_DOES_NOT_EXIST = -214,
FILE_READ_ONLY = -215,
FILE_IS_DIRECTORY = -216,
NETWORK_FILE_IS_IN_USE = -217,
APPLE_SINGLE_ERR = -218,
INVALID_PATH_ERR = -219,
PATCH_BAD_DIFF = -220,
PATCH_BAD_CHECKSUM_TARGET = -221,
PATCH_BAD_CHECKSUM_RESULT = -222,
UNINSTALL_FAILED = -223,
GESTALT_UNKNOWN_ERR = -5550,
GESTALT_INVALID_ARGUMENT = -5551,
SUCCESS = 0,
REBOOT_NEEDED = 999,
LIMITED_INSTALL = 0,
FULL_INSTALL = 1,
NO_STATUS_DLG = 2,
NO_FINALIZE_DLG = 4,
INSTALL_FILE_UNEXPECTED_MSG_ID = 0,
DETAILS_REPLACE_FILE_MSG_ID = 1,
DETAILS_INSTALL_FILE_MSG_ID = 2
};
nsInstall();
virtual ~nsInstall();
PRInt32 SetScriptObject(void* aScriptObject);
PRInt32 SaveWinRegPrototype(void* aScriptObject);
PRInt32 SaveWinProfilePrototype(void* aScriptObject);
JSObject* RetrieveWinRegPrototype(void);
JSObject* RetrieveWinProfilePrototype(void);
PRInt32 GetUserPackageName(nsString& aUserPackageName);
PRInt32 GetRegPackageName(nsString& aRegPackageName);
PRInt32 AbortInstall();
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRBool aForceMode, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aSubdir, PRInt32* aReturn);
PRInt32 AddDirectory(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRBool aForceMode, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 AddSubcomponent(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 DeleteComponent(const nsString& aRegistryName, PRInt32* aReturn);
PRInt32 DeleteFile(const nsString& aFolder, const nsString& aRelativeFileName, PRInt32* aReturn);
PRInt32 DiskSpaceAvailable(const nsString& aFolder, PRInt32* aReturn);
PRInt32 Execute(const nsString& aJarSource, const nsString& aArgs, PRInt32* aReturn);
PRInt32 Execute(const nsString& aJarSource, PRInt32* aReturn);
PRInt32 FinalizeInstall(PRInt32* aReturn);
PRInt32 Gestalt(const nsString& aSelector, PRInt32* aReturn);
PRInt32 GetComponentFolder(const nsString& aComponentName, const nsString& aSubdirectory, nsString** aFolder);
PRInt32 GetComponentFolder(const nsString& aComponentName, nsString** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, const nsString& aSubdirectory, nsString** aFolder);
PRInt32 GetFolder(const nsString& aTargetFolder, nsString** aFolder);
PRInt32 GetLastError(PRInt32* aReturn);
PRInt32 GetWinProfile(const nsString& aFolder, const nsString& aFile, JSContext* jscontext, JSClass* WinProfileClass, jsval* aReturn);
PRInt32 GetWinRegistry(JSContext* jscontext, JSClass* WinRegClass, jsval* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aVersion, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 Patch(const nsString& aRegName, const nsString& aJarSource, const nsString& aFolder, const nsString& aTargetName, PRInt32* aReturn);
PRInt32 ResetError();
PRInt32 SetPackageFolder(const nsString& aFolder);
PRInt32 StartInstall(const nsString& aUserPackageName, const nsString& aPackageName, const nsString& aVersion, PRInt32* aReturn);
PRInt32 Uninstall(const nsString& aPackageName, PRInt32* aReturn);
PRInt32 FileOpDirCreate(nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpDirGetParent(nsFileSpec& aTarget, nsFileSpec* aReturn);
PRInt32 FileOpDirRemove(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpDirRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileCopy(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileDelete(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileExists(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileExecute(nsFileSpec& aTarget, nsString& aParams, PRInt32* aReturn);
PRInt32 FileOpFileGetNativeVersion(nsFileSpec& aTarget, nsString* aReturn);
PRInt32 FileOpFileGetDiskSpaceAvailable(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileGetModDate(nsFileSpec& aTarget, nsFileSpec::TimeStamp* aReturn);
PRInt32 FileOpFileGetSize(nsFileSpec& aTarget, PRUint32* aReturn);
PRInt32 FileOpFileIsDirectory(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileIsFile(nsFileSpec& aTarget, PRBool* aReturn);
PRInt32 FileOpFileModDateChanged(nsFileSpec& aTarget, nsFileSpec::TimeStamp& aOldStamp, PRBool* aReturn);
PRInt32 FileOpFileMove(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileRename(nsFileSpec& aSrc, nsFileSpec& aTarget, PRInt32* aReturn);
PRInt32 FileOpFileWinShortcutCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileMacAliasCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 FileOpFileUnixLinkCreate(nsFileSpec& aTarget, PRInt32 aFlags, PRInt32* aReturn);
PRInt32 ExtractFileFromJar(const nsString& aJarfile, nsFileSpec* aSuggestedName, nsFileSpec** aRealName);
void AddPatch(nsHashKey *aKey, nsFileSpec* fileName);
void GetPatch(nsHashKey *aKey, nsFileSpec* fileName);
void GetJarFileLocation(nsString& aFile);
void SetJarFileLocation(const nsString& aFile);
void GetInstallArguments(nsString& args);
void SetInstallArguments(const nsString& args);
private:
JSObject* mScriptObject;
JSObject* mWinRegObject;
JSObject* mWinProfileObject;
nsString mJarFileLocation;
void* mJarFileData;
nsString mInstallArguments;
PRBool mUserCancelled;
PRBool mUninstallPackage;
PRBool mRegisterPackage;
nsString mRegistryPackageName; /* Name of the package we are installing */
nsString mUIName; /* User-readable package name */
nsInstallVersion* mVersionInfo; /* Component version info */
nsVector* mInstalledFiles;
nsHashtable* mPatchList;
nsIXPInstallProgress *mNotifier;
PRInt32 mLastError;
void ParseFlags(int flags);
PRInt32 SanityCheck(void);
void GetTime(nsString &aString);
PRInt32 GetQualifiedRegName(const nsString& name, nsString& qualifiedRegName );
PRInt32 GetQualifiedPackageName( const nsString& name, nsString& qualifiedName );
void CurrentUserNode(nsString& userRegNode);
PRBool BadRegName(const nsString& regName);
PRInt32 SaveError(PRInt32 errcode);
void CleanUp();
PRInt32 OpenJARFile(void);
void CloseJARFile(void);
PRInt32 ExtractDirEntries(const nsString& directory, nsVector *paths);
PRInt32 ScheduleForInstall(nsInstallObject* ob);
};
#endif

View File

@@ -1,235 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "prmem.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstallDelete.h"
#include "nsInstallResources.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((folderSpec == "null") || (inInstall == NULL))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mDeleteStatus = DELETE_FILE;
mFinalFile = nsnull;
mRegistryName = "";
mFinalFile = new nsFileSpec(folderSpec);
*mFinalFile += inPartialPath;
*error = ProcessInstallDelete();
}
nsInstallDelete::nsInstallDelete( nsInstall* inInstall,
const nsString& inComponentName,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if (inInstall == NULL)
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mDeleteStatus = DELETE_COMPONENT;
mFinalFile = nsnull;
mRegistryName = inComponentName;
*error = ProcessInstallDelete();
}
nsInstallDelete::~nsInstallDelete()
{
if (mFinalFile == nsnull)
delete mFinalFile;
}
PRInt32 nsInstallDelete::Prepare()
{
// no set-up necessary
return nsInstall::SUCCESS;
}
PRInt32 nsInstallDelete::Complete()
{
PRInt32 err = nsInstall::SUCCESS;
if (mInstall == NULL)
return nsInstall::INVALID_ARGUMENTS;
if (mDeleteStatus == DELETE_COMPONENT)
{
char* temp = mRegistryName.ToNewCString();
err = VR_Remove(temp);
delete [] temp;
}
if ((mDeleteStatus == DELETE_FILE) || (err == REGERR_OK))
{
err = NativeComplete();
}
else
{
err = nsInstall::UNEXPECTED_ERROR;
}
return err;
}
void nsInstallDelete::Abort()
{
}
char* nsInstallDelete::toString()
{
char* buffer = new char[1024];
if (mDeleteStatus == DELETE_COMPONENT)
{
sprintf( buffer, nsInstallResources::GetDeleteComponentString(), nsAutoCString(mRegistryName));
}
else
{
if (mFinalFile)
sprintf( buffer, nsInstallResources::GetDeleteFileString(), mFinalFile->GetCString());
}
return buffer;
}
PRBool
nsInstallDelete::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallDelete::RegisterPackageNode()
{
return PR_FALSE;
}
PRInt32 nsInstallDelete::ProcessInstallDelete()
{
PRInt32 err;
char* tempCString = nsnull;
if (mDeleteStatus == DELETE_COMPONENT)
{
/* Check if the component is in the registry */
tempCString = mRegistryName.ToNewCString();
err = VR_InRegistry( tempCString );
if (err != REGERR_OK)
{
return err;
}
else
{
char* tempRegistryString;
tempRegistryString = (char*)PR_Calloc(MAXREGPATHLEN, sizeof(char));
err = VR_GetPath( tempCString , MAXREGPATHLEN, tempRegistryString);
if (err == REGERR_OK)
{
if (mFinalFile)
delete mFinalFile;
mFinalFile = new nsFileSpec(tempRegistryString);
}
PR_FREEIF(tempRegistryString);
}
}
if(tempCString)
delete [] tempCString;
if (mFinalFile->Exists())
{
if (mFinalFile->IsFile())
{
err = nsInstall::SUCCESS;
}
else
{
err = nsInstall::FILE_IS_DIRECTORY;
}
}
else
{
err = nsInstall::FILE_DOES_NOT_EXIST;
}
return err;
}
PRInt32 nsInstallDelete::NativeComplete()
{
if (mFinalFile->Exists())
{
if (mFinalFile->IsFile())
{
return DeleteFileNowOrSchedule(*mFinalFile);
}
else
{
return nsInstall::FILE_IS_DIRECTORY;
}
}
return nsInstall::FILE_DOES_NOT_EXIST;
}

View File

@@ -1,78 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallDelete_h__
#define nsInstallDelete_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#define DELETE_COMPONENT 1
#define DELETE_FILE 2
class nsInstallDelete : public nsInstallObject
{
public:
nsInstallDelete( nsInstall* inInstall,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error);
nsInstallDelete( nsInstall* inInstall,
const nsString& ,
PRInt32 *error);
virtual ~nsInstallDelete();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsFileSpec* mFinalFile;
nsString mRegistryName;
PRInt32 mDeleteStatus;
PRInt32 ProcessInstallDelete();
PRInt32 NativeComplete();
};
#endif /* nsInstallDelete_h__ */

View File

@@ -1,136 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "prmem.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "nsInstallExecute.h"
#include "nsInstallResources.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
nsInstallExecute:: nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((inInstall == nsnull) || (inJarLocation == "null"))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mJarLocation = inJarLocation;
mArgs = inArgs;
mExecutableFile = nsnull;
}
nsInstallExecute::~nsInstallExecute()
{
if (mExecutableFile)
delete mExecutableFile;
}
PRInt32 nsInstallExecute::Prepare()
{
if (mInstall == NULL || mJarLocation == "null")
return nsInstall::INVALID_ARGUMENTS;
return mInstall->ExtractFileFromJar(mJarLocation, nsnull, &mExecutableFile);
}
PRInt32 nsInstallExecute::Complete()
{
if (mExecutableFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
nsFileSpec app( *mExecutableFile);
if (!app.Exists())
{
return nsInstall::INVALID_ARGUMENTS;
}
PRInt32 result = app.Execute( mArgs );
DeleteFileNowOrSchedule( app );
return result;
}
void nsInstallExecute::Abort()
{
/* Get the names */
if (mExecutableFile == nsnull)
return;
DeleteFileNowOrSchedule(*mExecutableFile);
}
char* nsInstallExecute::toString()
{
char* buffer = new char[1024];
// if the FileSpec is NULL, just us the in jar file name.
if (mExecutableFile == nsnull)
{
char *tempString = mJarLocation.ToNewCString();
sprintf( buffer, nsInstallResources::GetExecuteString(), tempString);
delete [] tempString;
}
else
{
sprintf( buffer, nsInstallResources::GetExecuteString(), mExecutableFile->GetCString());
}
return buffer;
}
PRBool
nsInstallExecute::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallExecute::RegisterPackageNode()
{
return PR_FALSE;
}

View File

@@ -1,73 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallExecute_h__
#define nsInstallExecute_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
class nsInstallExecute : public nsInstallObject
{
public:
nsInstallExecute( nsInstall* inInstall,
const nsString& inJarLocation,
const nsString& inArgs,
PRInt32 *error);
virtual ~nsInstallExecute();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsString mJarLocation; // Location in the JAR
nsString mArgs; // command line arguments
nsFileSpec *mExecutableFile; // temporary file location
PRInt32 NativeComplete(void);
void NativeAbort(void);
};
#endif /* nsInstallExecute_h__ */

View File

@@ -1,366 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstallFile.h"
#include "nsFileSpec.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "nsInstall.h"
#include "nsIDOMInstallVersion.h"
#include "nsInstallResources.h"
/* Public Methods */
/* Constructor
inInstall - softUpdate object we belong to
inComponentName - full path of the registry component
inVInfo - full version info
inJarLocation - location inside the JAR file
inFinalFileSpec - final location on disk
*/
nsInstallFile::nsInstallFile(nsInstall* inInstall,
const nsString& inComponentName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
PRInt32 *error)
: nsInstallObject(inInstall)
{
mVersionRegistryName = nsnull;
mJarLocation = nsnull;
mExtracedFile = nsnull;
mFinalFile = nsnull;
mVersionInfo = nsnull;
mUpgradeFile = PR_FALSE;
if ((folderSpec == "null") || (inInstall == NULL))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
/* Check for existence of the newer version */
PRBool versionNewer = PR_FALSE; // Is this a newer version
char* qualifiedRegNameString = inComponentName.ToNewCString();
if ( (forceInstall == PR_FALSE ) && (inVInfo != "") && ( VR_ValidateComponent( qualifiedRegNameString ) == 0 ) )
{
nsInstallVersion *newVersion = new nsInstallVersion();
newVersion->Init(inVInfo);
VERSION versionStruct;
VR_GetVersion( qualifiedRegNameString, &versionStruct );
nsInstallVersion* oldVersion = new nsInstallVersion();
oldVersion->Init(versionStruct.major,
versionStruct.minor,
versionStruct.release,
versionStruct.build);
PRInt32 areTheyEqual;
newVersion->CompareTo(oldVersion, &areTheyEqual);
delete oldVersion;
delete newVersion;
if (areTheyEqual == nsIDOMInstallVersion::MAJOR_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::MINOR_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::REL_DIFF_MINUS ||
areTheyEqual == nsIDOMInstallVersion::BLD_DIFF_MINUS )
{
// the file to be installed is OLDER than what is on disk. Return error
delete qualifiedRegNameString;
*error = areTheyEqual;
return;
}
}
delete qualifiedRegNameString;
mFinalFile = new nsFileSpec(folderSpec);
*mFinalFile += inPartialPath;
mReplaceFile = mFinalFile->Exists();
if (mReplaceFile == PR_FALSE)
{
nsFileSpec parent;
mFinalFile->GetParent(parent);
nsFileSpec makeDirs(parent.GetCString(), PR_TRUE);
}
mForceInstall = forceInstall;
mVersionRegistryName = new nsString(inComponentName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = new nsString(inVInfo);
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// determine Child status
if ( regPackageName == "" )
{
// in the "current communicator package" absolute pathnames (start
// with slash) indicate shared files -- all others are children
mChildFile = ( mVersionRegistryName->CharAt(0) != '/' );
}
else
{
// there is no "starts with" api in nsString. LAME!
nsString startsWith;
mVersionRegistryName->Left(startsWith, regPackageName.Length());
if (startsWith.Equals(regPackageName))
{
mChildFile = true;
}
else
{
mChildFile = false;
}
}
}
nsInstallFile::~nsInstallFile()
{
if (mVersionRegistryName)
delete mVersionRegistryName;
if (mJarLocation)
delete mJarLocation;
if (mExtracedFile)
delete mExtracedFile;
if (mFinalFile)
delete mFinalFile;
if (mVersionInfo)
delete mVersionInfo;
}
/* Prepare
* Extracts file out of the JAR archive
*/
PRInt32 nsInstallFile::Prepare()
{
if (mInstall == nsnull || mFinalFile == nsnull || mJarLocation == nsnull )
return nsInstall::INVALID_ARGUMENTS;
return mInstall->ExtractFileFromJar(*mJarLocation, mFinalFile, &mExtracedFile);
}
/* Complete
* Completes the install:
* - move the downloaded file to the final location
* - updates the registry
*/
PRInt32 nsInstallFile::Complete()
{
PRInt32 err;
if (mInstall == nsnull || mVersionRegistryName == nsnull || mFinalFile == nsnull )
{
return nsInstall::INVALID_ARGUMENTS;
}
err = CompleteFileMove();
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
{
err = RegisterInVersionRegistry();
}
return err;
}
void nsInstallFile::Abort()
{
if (mExtracedFile != nsnull)
mExtracedFile->Delete(PR_FALSE);
}
char* nsInstallFile::toString()
{
char* buffer = new char[1024];
if (mFinalFile == nsnull)
{
sprintf( buffer, nsInstallResources::GetInstallFileString(), nsnull);
}
else if (mReplaceFile)
{
// we are replacing this file.
sprintf( buffer, nsInstallResources::GetReplaceFileString(), mFinalFile->GetCString());
}
else
{
sprintf( buffer, nsInstallResources::GetInstallFileString(), mFinalFile->GetCString());
}
return buffer;
}
PRInt32 nsInstallFile::CompleteFileMove()
{
int result = 0;
if (mExtracedFile == nsnull)
{
return -1;
}
if ( *mExtracedFile == *mFinalFile )
{
/* No need to rename, they are the same */
result = 0;
}
else
{
result = ReplaceFileNowOrSchedule(*mExtracedFile, *mFinalFile );
}
return result;
}
PRInt32
nsInstallFile::RegisterInVersionRegistry()
{
int refCount;
nsString regPackageName;
mInstall->GetRegPackageName(regPackageName);
// Register file and log for Uninstall
if (!mChildFile)
{
int found;
if (regPackageName != "")
{
found = VR_UninstallFileExistsInList( (char*)(const char*)nsAutoCString(regPackageName) ,
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
}
else
{
found = VR_UninstallFileExistsInList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
}
if (found != REGERR_OK)
mUpgradeFile = PR_FALSE;
else
mUpgradeFile = PR_TRUE;
}
else if (REGERR_OK == VR_InRegistry( (char*)(const char*)nsAutoCString(*mVersionRegistryName)))
{
mUpgradeFile = PR_TRUE;
}
else
{
mUpgradeFile = PR_FALSE;
}
if ( REGERR_OK != VR_GetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), &refCount ))
{
refCount = 0;
}
VR_Install( (char*)(const char*)nsAutoCString(*mVersionRegistryName),
(char*)(const char*)mFinalFile->GetNativePathCString(), // DO NOT CHANGE THIS.
(char*)(const char*)nsAutoCString(*mVersionInfo),
PR_FALSE );
if (mUpgradeFile)
{
if (refCount == 0)
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
else
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount ); //FIX?? what should the ref count be/
}
else
{
if (refCount != 0)
{
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), refCount + 1 );
}
else
{
if (mReplaceFile)
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 2 );
else
VR_SetRefCount( (char*)(const char*)nsAutoCString(*mVersionRegistryName), 1 );
}
}
if ( !mChildFile && !mUpgradeFile )
{
if (regPackageName != "")
{
VR_UninstallAddFileToList( (char*)(const char*)nsAutoCString(regPackageName),
(char*)(const char*)nsAutoCString(*mVersionRegistryName));
}
else
{
VR_UninstallAddFileToList( "", (char*)(const char*)nsAutoCString(*mVersionRegistryName) );
}
}
return nsInstall::SUCCESS;
}
/* CanUninstall
* InstallFile() installs files which can be uninstalled,
* hence this function returns true.
*/
PRBool
nsInstallFile::CanUninstall()
{
return TRUE;
}
/* RegisterPackageNode
* InstallFile() installs files which need to be registered,
* hence this function returns true.
*/
PRBool
nsInstallFile::RegisterPackageNode()
{
return TRUE;
}

View File

@@ -1,93 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallFile_h__
#define nsInstallFile_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallVersion.h"
class nsInstallFile : public nsInstallObject
{
public:
/*************************************************************
* Public Methods
*
* Constructor
* inSoftUpdate - softUpdate object we belong to
* inComponentName - full path of the registry component
* inVInfo - full version info
* inJarLocation - location inside the JAR file
* inFinalFileSpec - final location on disk
*************************************************************/
nsInstallFile( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRBool forceInstall,
PRInt32 *error);
virtual ~nsInstallFile();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsString* mVersionInfo; /* Version info for this file*/
nsString* mJarLocation; /* Location in the JAR */
nsFileSpec* mExtracedFile; /* temporary file location */
nsFileSpec* mFinalFile; /* final file destination */
nsString* mVersionRegistryName; /* full version path */
PRBool mForceInstall; /* whether install is forced */
PRBool mReplaceFile; /* whether file exists */
PRBool mChildFile; /* whether file is a child */
PRBool mUpgradeFile; /* whether file is an upgrade */
PRInt32 CompleteFileMove();
PRInt32 RegisterInVersionRegistry();
};
#endif /* nsInstallFile_h__ */

View File

@@ -1,38 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallFileOpEnums_h__
#define nsInstallFileOpEnums_h__
typedef enum nsInstallFileOpEnums {
NS_FOP_DIR_CREATE = 0,
NS_FOP_DIR_REMOVE = 1,
NS_FOP_DIR_RENAME = 2,
NS_FOP_FILE_COPY = 3,
NS_FOP_FILE_DELETE = 4,
NS_FOP_FILE_EXECUTE = 5,
NS_FOP_FILE_MOVE = 6,
NS_FOP_FILE_RENAME = 7,
NS_FOP_WIN_SHORTCUT_CREATE = 8,
NS_FOP_MAC_ALIAS_CREATE = 9,
NS_FOP_UNIX_LINK_CREATE = 10,
NS_FOP_FILE_SET_STAT = 11
} nsInstallFileOpEnums;
#endif /* nsInstallFileOpEnums_h__ */

View File

@@ -1,316 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nspr.h"
#include "nsInstall.h"
#include "nsInstallFileOpEnums.h"
#include "nsInstallFileOpItem.h"
/* Public Methods */
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32 aFlags,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = aFlags;
mSrc = nsnull;
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aSrc,
nsFileSpec& aTarget,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = new nsFileSpec(aSrc);
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = nsnull;
mParams = nsnull;
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
nsString& aParams,
PRInt32* aReturn)
:nsInstallObject(aInstallObj)
{
mIObj = aInstallObj;
mCommand = aCommand;
mFlags = 0;
mSrc = nsnull;
mParams = new nsString(aParams);
mTarget = new nsFileSpec(aTarget);
*aReturn = NS_OK;
}
nsInstallFileOpItem::~nsInstallFileOpItem()
{
if(mSrc)
delete mSrc;
if(mTarget)
delete mTarget;
}
PRInt32 nsInstallFileOpItem::Complete()
{
PRInt32 aReturn = NS_OK;
switch(mCommand)
{
case NS_FOP_DIR_CREATE:
NativeFileOpDirCreate(mTarget);
break;
case NS_FOP_DIR_REMOVE:
NativeFileOpDirRemove(mTarget, mFlags);
break;
case NS_FOP_DIR_RENAME:
NativeFileOpDirRename(mSrc, mTarget);
break;
case NS_FOP_FILE_COPY:
NativeFileOpFileCopy(mSrc, mTarget);
break;
case NS_FOP_FILE_DELETE:
NativeFileOpFileDelete(mTarget, mFlags);
break;
case NS_FOP_FILE_EXECUTE:
NativeFileOpFileExecute(mTarget, mParams);
break;
case NS_FOP_FILE_MOVE:
NativeFileOpFileMove(mSrc, mTarget);
break;
case NS_FOP_FILE_RENAME:
NativeFileOpFileRename(mSrc, mTarget);
break;
case NS_FOP_WIN_SHORTCUT_CREATE:
NativeFileOpWinShortcutCreate();
break;
case NS_FOP_MAC_ALIAS_CREATE:
NativeFileOpMacAliasCreate();
break;
case NS_FOP_UNIX_LINK_CREATE:
NativeFileOpUnixLinkCreate();
break;
}
return aReturn;
}
float nsInstallFileOpItem::GetInstallOrder()
{
return 3;
}
char* nsInstallFileOpItem::toString()
{
nsString result;
char* resultCString;
switch(mCommand)
{
case NS_FOP_FILE_COPY:
result = "Copy file: ";
result.Append(mSrc->GetNativePathCString());
result.Append(" to ");
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_DELETE:
result = "Delete file: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_MOVE:
result = "Move file: ";
result.Append(mSrc->GetNativePathCString());
result.Append(" to ");
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_FILE_RENAME:
result = "Rename file: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_DIR_CREATE:
result = "Create Folder: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_DIR_REMOVE:
result = "Remove Folder: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
case NS_FOP_WIN_SHORTCUT_CREATE:
break;
case NS_FOP_MAC_ALIAS_CREATE:
break;
case NS_FOP_UNIX_LINK_CREATE:
break;
case NS_FOP_FILE_SET_STAT:
result = "Set file stat: ";
result.Append(mTarget->GetNativePathCString());
resultCString = result.ToNewCString();
break;
default:
result = "Unkown file operation command!";
resultCString = result.ToNewCString();
break;
}
return resultCString;
}
PRInt32 nsInstallFileOpItem::Prepare()
{
return NULL;
}
void nsInstallFileOpItem::Abort()
{
}
/* Private Methods */
/* CanUninstall
* InstallFileOpItem() does not install any files which can be uninstalled,
* hence this function returns false.
*/
PRBool
nsInstallFileOpItem::CanUninstall()
{
return FALSE;
}
/* RegisterPackageNode
* InstallFileOpItem() does notinstall files which need to be registered,
* hence this function returns false.
*/
PRBool
nsInstallFileOpItem::RegisterPackageNode()
{
return FALSE;
}
//
// File operation functions begin here
//
PRInt32
nsInstallFileOpItem::NativeFileOpDirCreate(nsFileSpec* aTarget)
{
aTarget->CreateDirectory();
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags)
{
aTarget->Delete(aFlags);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Rename(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Copy(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags)
{
aTarget->Delete(aFlags);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams)
{
aTarget->Execute(*aParams);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Move(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget)
{
aSrc->Rename(*aTarget);
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpWinShortcutCreate()
{
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpMacAliasCreate()
{
return NS_OK;
}
PRInt32
nsInstallFileOpItem::NativeFileOpUnixLinkCreate()
{
return NS_OK;
}

View File

@@ -1,111 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallFileOpItem_h__
#define nsInstallFileOpItem_h__
#include "prtypes.h"
#include "nsFileSpec.h"
#include "nsSoftwareUpdate.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
class nsInstallFileOpItem : public nsInstallObject
{
public:
/* Public Fields */
/* Public Methods */
// used by:
// FileOpFileDelete()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32 aFlags,
PRInt32* aReturn);
// used by:
// FileOpDirRemove()
// FileOpDirRename()
// FileOpFileCopy()
// FileOpFileMove()
// FileOpFileRename()
nsInstallFileOpItem(nsInstall* installObj,
PRInt32 aCommand,
nsFileSpec& aSrc,
nsFileSpec& aTarget,
PRInt32* aReturn);
// used by:
// FileOpDirCreate()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
PRInt32* aReturn);
// used by:
// FileOpFileExecute()
nsInstallFileOpItem(nsInstall* aInstallObj,
PRInt32 aCommand,
nsFileSpec& aTarget,
nsString& aParams,
PRInt32* aReturn);
~nsInstallFileOpItem();
PRInt32 Prepare(void);
PRInt32 Complete();
char* toString();
void Abort();
float GetInstallOrder();
/* should these be protected? */
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
/* Private Fields */
nsInstall* mIObj; // initiating Install object
nsFileSpec* mSrc;
nsFileSpec* mTarget;
nsString* mParams;
long mFStat;
PRInt32 mFlags;
PRInt32 mCommand;
/* Private Methods */
PRInt32 NativeFileOpDirCreate(nsFileSpec* aTarget);
PRInt32 NativeFileOpDirRemove(nsFileSpec* aTarget, PRInt32 aFlags);
PRInt32 NativeFileOpDirRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileCopy(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileDelete(nsFileSpec* aTarget, PRInt32 aFlags);
PRInt32 NativeFileOpFileExecute(nsFileSpec* aTarget, nsString* aParams);
PRInt32 NativeFileOpFileMove(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpFileRename(nsFileSpec* aSrc, nsFileSpec* aTarget);
PRInt32 NativeFileOpWinShortcutCreate();
PRInt32 NativeFileOpMacAliasCreate();
PRInt32 NativeFileOpUnixLinkCreate();
};
#endif /* nsInstallFileOpItem_h__ */

View File

@@ -1,336 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nscore.h"
#include "prtypes.h"
#include "nsRepository.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
#include "nsFileLocations.h"
#include "nsIFileLocator.h"
struct DirectoryTable
{
char * directoryName; /* The formal directory name */
PRInt32 folderEnum; /* Directory ID */
};
struct DirectoryTable DirectoryTable[] =
{
{"Plugins", 100 },
{"Program", 101 },
{"Communicator", 102 },
{"User Pick", 103 },
{"Temporary", 104 },
{"Installed", 105 },
{"Current User", 106 },
{"Preferences", 107 },
{"OS Drive", 108 },
{"file:///", 109 },
{"Components", 110 },
{"Chrome", 111 },
{"Win System", 200 },
{"Windows", 201 },
{"Mac System", 300 },
{"Mac Desktop", 301 },
{"Mac Trash", 302 },
{"Mac Startup", 303 },
{"Mac Shutdown", 304 },
{"Mac Apple Menu", 305 },
{"Mac Control Panel", 306 },
{"Mac Extension", 307 },
{"Mac Fonts", 308 },
{"Mac Preferences", 309 },
{"Mac Documents", 310 },
{"Unix Local", 400 },
{"Unix Lib", 401 },
{"", -1 }
};
nsInstallFolder::nsInstallFolder(const nsString& aFolderID)
{
mFileSpec = nsnull;
SetDirectoryPath( aFolderID, "");
}
nsInstallFolder::nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath)
{
mFileSpec = nsnull;
/*
aFolderID can be either a Folder enum in which case we merely pass it to SetDirectoryPath, or
it can be a Directory. If it is the later, it must already exist and of course be a directory
not a file.
*/
nsFileSpec dirCheck(aFolderID);
if ( (dirCheck.Error() == NS_OK) && (dirCheck.IsDirectory()) && (dirCheck.Exists()))
{
nsString tempString = aFolderID;
tempString += aRelativePath;
mFileSpec = new nsFileSpec(tempString);
// make sure that the directory is created.
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
}
else
{
SetDirectoryPath( aFolderID, aRelativePath);
}
}
nsInstallFolder::~nsInstallFolder()
{
if (mFileSpec != nsnull)
delete mFileSpec;
}
void
nsInstallFolder::GetDirectoryPath(nsString& aDirectoryPath)
{
aDirectoryPath = "";
if (mFileSpec != nsnull)
{
// We want the a NATIVE path.
aDirectoryPath.SetString(mFileSpec->GetCString());
}
}
void
nsInstallFolder::SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath)
{
if ( aFolderID.EqualsIgnoreCase("User Pick") )
{
PickDefaultDirectory();
return;
}
else if ( aFolderID.EqualsIgnoreCase("Installed") )
{
mFileSpec = new nsFileSpec(aRelativePath, PR_TRUE); // creates the directories to the relative path.
return;
}
else
{
PRInt32 folderDirSpecID = MapNameToEnum(aFolderID);
switch (folderDirSpecID)
{
case 100: /////////////////////////////////////////////////////////// Plugins
SetAppShellDirectory(nsSpecialFileSpec::App_PluginsDirectory );
break;
case 101: /////////////////////////////////////////////////////////// Program
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
break;
case 102: /////////////////////////////////////////////////////////// Communicator
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_CurrentProcessDirectory ));
break;
case 103: /////////////////////////////////////////////////////////// User Pick
// we should never be here.
mFileSpec = nsnull;
break;
case 104: /////////////////////////////////////////////////////////// Temporary
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_TemporaryDirectory ));
break;
case 105: /////////////////////////////////////////////////////////// Installed
// we should never be here.
mFileSpec = nsnull;
break;
case 106: /////////////////////////////////////////////////////////// Current User
SetAppShellDirectory(nsSpecialFileSpec::App_UserProfileDirectory50 );
break;
case 107: /////////////////////////////////////////////////////////// Preferences
SetAppShellDirectory(nsSpecialFileSpec::App_PrefsDirectory50 );
break;
case 108: /////////////////////////////////////////////////////////// OS Drive
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::OS_DriveDirectory ));
break;
case 109: /////////////////////////////////////////////////////////// File URL
{
nsString tempFileURLString = aFolderID;
tempFileURLString += aRelativePath;
mFileSpec = new nsFileSpec( nsFileURL(tempFileURLString) );
}
break;
case 110: /////////////////////////////////////////////////////////// Components
SetAppShellDirectory(nsSpecialFileSpec::App_ComponentsDirectory );
break;
case 111: /////////////////////////////////////////////////////////// Chrome
SetAppShellDirectory(nsSpecialFileSpec::App_ChromeDirectory );
break;
case 200: /////////////////////////////////////////////////////////// Win System
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_SystemDirectory ));
break;
case 201: /////////////////////////////////////////////////////////// Windows
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Win_WindowsDirectory ));
break;
case 300: /////////////////////////////////////////////////////////// Mac System
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_SystemDirectory ));
break;
case 301: /////////////////////////////////////////////////////////// Mac Desktop
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DesktopDirectory ));
break;
case 302: /////////////////////////////////////////////////////////// Mac Trash
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_TrashDirectory ));
break;
case 303: /////////////////////////////////////////////////////////// Mac Startup
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
break;
case 304: /////////////////////////////////////////////////////////// Mac Shutdown
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_StartupDirectory ));
break;
case 305: /////////////////////////////////////////////////////////// Mac Apple Menu
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_AppleMenuDirectory ));
break;
case 306: /////////////////////////////////////////////////////////// Mac Control Panel
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ControlPanelDirectory ));
break;
case 307: /////////////////////////////////////////////////////////// Mac Extension
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_ExtensionDirectory ));
break;
case 308: /////////////////////////////////////////////////////////// Mac Fonts
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_FontsDirectory ));
break;
case 309: /////////////////////////////////////////////////////////// Mac Preferences
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_PreferencesDirectory ));
break;
case 310: /////////////////////////////////////////////////////////// Mac Documents
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Mac_DocumentsDirectory ));
break;
case 400: /////////////////////////////////////////////////////////// Unix Local
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LocalDirectory ));
break;
case 401: /////////////////////////////////////////////////////////// Unix Lib
mFileSpec = new nsFileSpec( nsSpecialSystemDirectory( nsSpecialSystemDirectory::Unix_LibDirectory ));
break;
case -1:
default:
mFileSpec = nsnull;
return;
}
#ifndef XP_MAC
if (aRelativePath.Length() > 0)
{
nsString tempPath(aRelativePath);
if (aRelativePath.Last() != '/' || aRelativePath.Last() != '\\')
tempPath += '/';
*mFileSpec += tempPath;
}
#endif
// make sure that the directory is created.
nsFileSpec(mFileSpec->GetCString(), PR_TRUE);
}
}
void nsInstallFolder::PickDefaultDirectory()
{
//FIX: Need to put up a dialog here and set mFileSpec
return;
}
/* MapNameToEnum
* maps name from the directory table to its enum */
PRInt32
nsInstallFolder::MapNameToEnum(const nsString& name)
{
int i = 0;
if ( name == "null")
return -1;
while ( DirectoryTable[i].directoryName[0] != 0 )
{
if ( name.EqualsIgnoreCase(DirectoryTable[i].directoryName) )
return DirectoryTable[i].folderEnum;
i++;
}
return -1;
}
static NS_DEFINE_IID(kFileLocatorIID, NS_IFILELOCATOR_IID);
static NS_DEFINE_IID(kFileLocatorCID, NS_FILELOCATOR_CID);
void
nsInstallFolder::SetAppShellDirectory(PRUint32 value)
{
nsIFileLocator * appShellLocator;
nsresult rv = nsComponentManager::CreateInstance(kFileLocatorCID,
nsnull,
kFileLocatorIID,
(void**) &appShellLocator);
if ( NS_SUCCEEDED(rv) )
{
mFileSpec = new nsFileSpec();
appShellLocator->GetFileLocation(value, mFileSpec);
NS_RELEASE(appShellLocator);
}
}

View File

@@ -1,58 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALLFOLDER_H__
#define __NS_INSTALLFOLDER_H__
#include "nscore.h"
#include "prtypes.h"
#include "nsString.h"
#include "nsFileSpec.h"
#include "nsSpecialSystemDirectory.h"
class nsInstallFolder
{
public:
nsInstallFolder(const nsString& aFolderID);
nsInstallFolder(const nsString& aFolderID, const nsString& aRelativePath);
virtual ~nsInstallFolder();
void GetDirectoryPath(nsString& aDirectoryPath);
private:
nsFileSpec* mFileSpec;
void SetDirectoryPath(const nsString& aFolderID, const nsString& aRelativePath);
void PickDefaultDirectory();
PRInt32 MapNameToEnum(const nsString& name);
void SetAppShellDirectory(PRUint32 value);
};
#endif

View File

@@ -1,52 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallObject_h__
#define nsInstallObject_h__
#include "prtypes.h"
class nsInstall;
class nsInstallObject
{
public:
/* Public Methods */
nsInstallObject(nsInstall* inInstall) {mInstall = inInstall; }
/* Override with your set-up action */
virtual PRInt32 Prepare() = 0;
/* Override with your Completion action */
virtual PRInt32 Complete() = 0;
/* Override with an explanatory string for the progress dialog */
virtual char* toString() = 0;
/* Override with your clean-up function */
virtual void Abort() = 0;
/* should these be protected? */
virtual PRBool CanUninstall() = 0;
virtual PRBool RegisterPackageNode() = 0;
protected:
nsInstall* mInstall;
};
#endif /* nsInstallObject_h__ */

View File

@@ -1,986 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#include "nsFileSpec.h"
#include "prmem.h"
#include "nsInstall.h"
#include "nsInstallPatch.h"
#include "nsInstallResources.h"
#include "nsIDOMInstallVersion.h"
#include "zlib.h"
#include "gdiff.h"
#include "VerReg.h"
#include "ScheduledTasks.h"
#include "plstr.h"
#include "xp_file.h" /* for XP_PlatformFileToURL */
#ifdef XP_MAC
#include "PatchableAppleSingle.h"
#endif
#define BUFSIZE 32768
#define OPSIZE 1
#define MAXCMDSIZE 12
#define SRCFILE 0
#define OUTFILE 1
#define getshort(s) (uint16)( ((uchar)*(s) << 8) + ((uchar)*((s)+1)) )
#define getlong(s) \
(uint32)( ((uchar)*(s) << 24) + ((uchar)*((s)+1) << 16 ) + \
((uchar)*((s)+2) << 8) + ((uchar)*((s)+3)) )
static int32 gdiff_parseHeader( pDIFFDATA dd );
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
static int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum );
static int32 gdiff_ApplyPatch( pDIFFDATA dd );
static int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length );
static int32 gdiff_add( pDIFFDATA dd, uint32 count );
static int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count );
static int32 gdiff_validateFile( pDIFFDATA dd, int file );
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
PRInt32 *error)
: nsInstallObject(inInstall)
{
char tempTargetFile[MAXREGPATHLEN];
char* tempVersionString = inVRName.ToNewCString();
PRInt32 err = VR_GetPath(tempVersionString, MAXREGPATHLEN, tempTargetFile );
delete [] tempVersionString;
if (err != REGERR_OK)
{
*error = nsInstall::NO_SUCH_COMPONENT;
return;
}
nsString folderSpec(tempTargetFile);
mPatchFile = nsnull;
mTargetFile = nsnull;
mPatchedFile = nsnull;
mRegistryName = new nsString(inVRName);
mJarLocation = new nsString(inJarLocation);
mTargetFile = new nsFileSpec(folderSpec);
mVersionInfo = new nsInstallVersion();
mVersionInfo->Init(inVInfo);
}
nsInstallPatch::nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if ((inInstall == nsnull) || (inVRName == "null") || (inJarLocation == "null"))
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mPatchFile = nsnull;
mTargetFile = nsnull;
mPatchedFile = nsnull;
mRegistryName = new nsString(inVRName);
mJarLocation = new nsString(inJarLocation);
mVersionInfo = new nsInstallVersion();
mVersionInfo->Init(inVInfo);
mTargetFile = new nsFileSpec(folderSpec);
if(inPartialPath != "null")
*mTargetFile += inPartialPath;
}
nsInstallPatch::~nsInstallPatch()
{
if (mVersionInfo)
delete mVersionInfo;
if (mTargetFile)
delete mTargetFile;
if (mJarLocation)
delete mJarLocation;
if (mRegistryName)
delete mRegistryName;
if (mPatchedFile)
delete mPatchedFile;
if (mPatchFile)
delete mPatchFile;
}
PRInt32 nsInstallPatch::Prepare()
{
PRInt32 err;
PRBool deleteOldSrc;
if (mTargetFile == nsnull)
return nsInstall::INVALID_ARGUMENTS;
if (mTargetFile->Exists())
{
if (mTargetFile->IsFile())
{
err = nsInstall::SUCCESS;
}
else
{
err = nsInstall::FILE_IS_DIRECTORY;
}
}
else
{
err = nsInstall::FILE_DOES_NOT_EXIST;
}
if (err != nsInstall::SUCCESS)
{
return err;
}
err = mInstall->ExtractFileFromJar(*mJarLocation, mTargetFile, &mPatchFile);
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull)
{
deleteOldSrc = PR_TRUE;
}
else
{
fileName = mTargetFile;
deleteOldSrc = PR_FALSE;
}
err = NativePatch( *fileName, // the file to patch
*mPatchFile, // the patch that was extracted from the jarfile
&mPatchedFile); // the new patched file
if (err != nsInstall::SUCCESS)
{
return err;
}
PR_ASSERT(mPatchedFile != nsnull);
mInstall->AddPatch(&ikey, mPatchedFile );
if ( deleteOldSrc )
{
DeleteFileNowOrSchedule(*fileName );
}
return err;
}
PRInt32 nsInstallPatch::Complete()
{
if ((mInstall == nsnull) || (mVersionInfo == nsnull) || (mPatchedFile == nsnull) || (mTargetFile == nsnull))
{
return nsInstall::INVALID_ARGUMENTS;
}
PRInt32 err = nsInstall::SUCCESS;
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
// the patch has not been superceded--do final replacement
err = ReplaceFileNowOrSchedule( *mTargetFile, *mPatchedFile);
if ( 0 == err || nsInstall::REBOOT_NEEDED == err )
{
nsString tempVersionString;
mVersionInfo->ToString(tempVersionString);
char* tempRegName = mRegistryName->ToNewCString();
char* tempVersion = tempVersionString.ToNewCString();
err = VR_Install( tempRegName,
(char*) (const char *) nsNSPRPath(*mTargetFile),
tempVersion,
PR_FALSE );
delete [] tempRegName;
delete [] tempVersion;
}
else
{
err = nsInstall::UNEXPECTED_ERROR;
}
}
else
{
// nothing -- old intermediate patched file was
// deleted by a superceding patch
}
return err;
}
void nsInstallPatch::Abort()
{
nsFileSpec *fileName = nsnull;
nsVoidKey ikey( HashFilePath( nsFilePath(*mTargetFile) ) );
mInstall->GetPatch(&ikey, fileName);
if (fileName != nsnull && (*fileName == *mPatchedFile) )
{
DeleteFileNowOrSchedule( *mPatchedFile );
}
}
char* nsInstallPatch::toString()
{
char* buffer = new char[1024];
// FIX! sprintf( buffer, nsInstallResources::GetPatchFileString(), mPatchedFile->GetCString());
return buffer;
}
PRBool
nsInstallPatch::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallPatch::RegisterPackageNode()
{
return PR_FALSE;
}
PRInt32
nsInstallPatch::NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchFile, nsFileSpec **newFile)
{
DIFFDATA *dd;
PRInt32 status = GDIFF_ERR_MEM;
char *tmpurl = NULL;
char *realfile = PL_strdup(nsNSPRPath(sourceFile)); // needs to be sourceFile!!!
nsFileSpec outFileSpec = sourceFile;
dd = (DIFFDATA *)PR_Calloc( 1, sizeof(DIFFDATA));
if (dd != NULL)
{
dd->databuf = (uchar*)PR_Malloc(BUFSIZE);
if (dd->databuf == NULL)
{
status = GDIFF_ERR_MEM;
goto cleanup;
}
dd->bufsize = BUFSIZE;
// validate patch header & check for special instructions
dd->fDiff = PR_Open (nsNSPRPath(patchFile), PR_RDONLY, 0666);
if (dd->fDiff != NULL)
{
status = gdiff_parseHeader(dd);
} else {
status = GDIFF_ERR_ACCESS;
}
#ifdef dono
#ifdef WIN32
/* unbind Win32 images */
if ( dd->bWin32BoundImage && status == GDIFF_OK ) {
tmpurl = WH_TempName( xpURL, NULL );
if ( tmpurl != NULL ) {
if (su_unbind( srcfile, srctype, tmpurl, xpURL ))
{
PL_strfree(realfile);
realfile = tmpurl;
realtype = xpURL;
}
}
else
status = GDIFF_ERR_MEM;
}
#endif
#endif
#ifdef XP_MAC
if ( dd->bMacAppleSingle && status == GDIFF_OK )
{
// create a tmp file, so that we can AppleSingle the src file
nsSpecialSystemDirectory tempMacFile(nsSpecialSystemDirectory::OS_TemporaryDirectory);
nsString srcName = sourceFile.GetLeafName();
tempMacFile.SetLeafName(srcName);
tempMacFile.MakeUnique();
// Encode!
// Encode src file, and put into temp file
FSSpec sourceSpec = sourceFile.GetFSSpec();
FSSpec tempSpec = tempMacFile.GetFSSpec();
status = PAS_EncodeFile(&sourceSpec, &tempSpec);
if (status == noErr)
{
// set
PL_strfree(realfile);
realfile = PL_strdup(nsNSPRPath(tempMacFile));
}
}
#endif
if (status != NS_OK)
goto cleanup;
// make a unique file at the same location of our source file (FILENAME-ptch.EXT)
nsString patchFileName = "-ptch";
nsString newFileName = sourceFile.GetLeafName();
PRInt32 index;
if ((index = newFileName.RFind(".")) > 0)
{
nsString extention;
nsString fileName;
newFileName.Right(extention, (newFileName.Length() - index) );
newFileName.Left(fileName, (newFileName.Length() - (newFileName.Length() - index)));
newFileName = fileName + patchFileName + extention;
} else {
newFileName += patchFileName;
}
outFileSpec.SetLeafName(newFileName); //????
outFileSpec.MakeUnique();
char *outFile = PL_strdup(nsNSPRPath(outFileSpec));
// apply patch to the source file
dd->fSrc = PR_Open ( realfile, PR_RDONLY, 0666);
dd->fOut = PR_Open ( outFile, PR_RDWR|PR_CREATE_FILE|PR_TRUNCATE, 0666);
if (dd->fSrc != NULL && dd->fOut != NULL)
{
status = gdiff_validateFile (dd, SRCFILE);
// specify why diff failed
if (status == GDIFF_ERR_CHECKSUM)
status = GDIFF_ERR_CHECKSUM_TARGET;
if (status == GDIFF_OK)
status = gdiff_ApplyPatch(dd);
if (status == GDIFF_OK)
status = gdiff_validateFile (dd, OUTFILE);
if (status == GDIFF_ERR_CHECKSUM)
status = GDIFF_ERR_CHECKSUM_RESULT;
if (status == GDIFF_OK)
{
*newFile = &outFileSpec;
if ( outFile != nsnull)
PL_strfree( outFile );
}
} else {
status = GDIFF_ERR_ACCESS;
}
}
#ifdef XP_MAC
if ( dd->bMacAppleSingle && status == GDIFF_OK )
{
// create another file, so that we can decode somewhere
nsFileSpec anotherName = outFileSpec;
anotherName.MakeUnique();
// Close the out file so that we can read it
PR_Close( dd->fOut );
dd->fOut = NULL;
FSSpec outSpec = outFileSpec.GetFSSpec();
FSSpec anotherSpec = anotherName.GetFSSpec();
status = PAS_DecodeFile(&outSpec, &anotherSpec);
if (status != noErr)
{
goto cleanup;
}
nsFileSpec parent;
outFileSpec.GetParent(parent);
outFileSpec.Delete(PR_FALSE);
anotherName.Copy(parent);
*newFile = &anotherName;
}
#endif
cleanup:
if ( dd != NULL )
{
if ( dd->fSrc != nsnull )
PR_Close( dd->fSrc );
if ( dd->fDiff != nsnull )
PR_Close( dd->fDiff );
if ( dd->fOut != nsnull )
{
PR_Close( dd->fOut );
}
if ( status != GDIFF_OK )
//XP_FileRemove( outfile, outtype );
newFile = NULL;
PR_FREEIF( dd->databuf );
PR_FREEIF( dd->oldChecksum );
PR_FREEIF( dd->newChecksum );
PR_DELETE(dd);
}
if ( tmpurl != NULL ) {
//XP_FileRemove( tmpurl, xpURL );
tmpurl = NULL;
PR_DELETE( tmpurl );
}
/* lets map any GDIFF error to nice SU errors */
switch (status)
{
case GDIFF_OK:
break;
case GDIFF_ERR_HEADER:
case GDIFF_ERR_BADDIFF:
case GDIFF_ERR_OPCODE:
case GDIFF_ERR_CHKSUMTYPE:
status = nsInstall::PATCH_BAD_DIFF;
break;
case GDIFF_ERR_CHECKSUM_TARGET:
status = nsInstall::PATCH_BAD_CHECKSUM_TARGET;
break;
case GDIFF_ERR_CHECKSUM_RESULT:
status = nsInstall::PATCH_BAD_CHECKSUM_RESULT;
break;
case GDIFF_ERR_OLDFILE:
case GDIFF_ERR_ACCESS:
case GDIFF_ERR_MEM:
case GDIFF_ERR_UNKNOWN:
default:
status = nsInstall::UNEXPECTED_ERROR;
break;
}
return status;
// return -1; //old return value
}
void*
nsInstallPatch::HashFilePath(const nsFilePath& aPath)
{
PRUint32 rv = 0;
char* cPath = PL_strdup(nsNSPRPath(aPath));
if(cPath != nsnull)
{
char ch;
char* filePath = PL_strdup(cPath);
PRUint32 cnt=0;
while ((ch = *filePath++) != 0)
{
// FYI: rv = rv*37 + ch
rv = ((rv << 5) + (rv << 2) + rv) + ch;
cnt++;
}
for (PRUint32 i=0; i<=cnt; i++)
*filePath--;
PL_strfree(filePath);
}
PL_strfree(cPath);
return (void*)rv;
}
/*---------------------------------------------------------
* gdiff_parseHeader()
*
* reads and validates the GDIFF header info
*---------------------------------------------------------
*/
static
int32 gdiff_parseHeader( pDIFFDATA dd )
{
int32 err = GDIFF_OK;
uint8 cslen;
uint8 oldcslen;
uint8 newcslen;
uint32 nRead;
uchar header[GDIFF_HEADERSIZE];
/* Read the fixed-size part of the header */
nRead = PR_Read (dd->fDiff, header, GDIFF_HEADERSIZE);
if ( nRead != GDIFF_HEADERSIZE ||
memcmp( header, GDIFF_MAGIC, GDIFF_MAGIC_LEN ) != 0 ||
header[GDIFF_VER_POS] != GDIFF_VER )
{
err = GDIFF_ERR_HEADER;
}
else
{
/* get the checksum information */
dd->checksumType = header[GDIFF_CS_POS];
cslen = header[GDIFF_CSLEN_POS];
if ( cslen > 0 )
{
oldcslen = cslen / 2;
newcslen = cslen - oldcslen;
PR_ASSERT( newcslen == oldcslen );
dd->checksumLength = oldcslen;
dd->oldChecksum = (uchar*)PR_MALLOC(oldcslen);
dd->newChecksum = (uchar*)PR_MALLOC(newcslen);
if ( dd->oldChecksum != NULL && dd->newChecksum != NULL )
{
nRead = PR_Read (dd->fDiff, dd->oldChecksum, oldcslen);
if ( nRead == oldcslen )
{
nRead = PR_Read (dd->fDiff, dd->newChecksum, newcslen);
if ( nRead != newcslen ) {
err = GDIFF_ERR_HEADER;
}
}
else {
err = GDIFF_ERR_HEADER;
}
}
else {
err = GDIFF_ERR_MEM;
}
}
/* get application data, if any */
if ( err == GDIFF_OK )
{
uint32 appdataSize;
uchar *buf;
uchar lenbuf[GDIFF_APPDATALEN];
nRead = PR_Read(dd->fDiff, lenbuf, GDIFF_APPDATALEN);
if ( nRead == GDIFF_APPDATALEN )
{
appdataSize = getlong(lenbuf);
if ( appdataSize > 0 )
{
buf = (uchar *)PR_MALLOC( appdataSize );
if ( buf != NULL )
{
nRead = PR_Read (dd->fDiff, buf, appdataSize);
if ( nRead == appdataSize )
{
if ( 0 == memcmp( buf, APPFLAG_W32BOUND, appdataSize ) )
dd->bWin32BoundImage = TRUE;
if ( 0 == memcmp( buf, APPFLAG_APPLESINGLE, appdataSize ) )
dd->bMacAppleSingle = TRUE;
}
else {
err = GDIFF_ERR_HEADER;
}
PR_DELETE( buf );
}
else {
err = GDIFF_ERR_MEM;
}
}
}
else {
err = GDIFF_ERR_HEADER;
}
}
}
return (err);
}
/*---------------------------------------------------------
* gdiff_validateFile()
*
* computes the checksum of the file and compares it to
* the value stored in the GDIFF header
*---------------------------------------------------------
*/
static
int32 gdiff_validateFile( pDIFFDATA dd, int file )
{
int32 result;
PRFileDesc* fh;
uchar* chksum;
/* which file are we dealing with? */
if ( file == SRCFILE ) {
fh = dd->fSrc;
chksum = dd->oldChecksum;
}
else { /* OUTFILE */
fh = dd->fOut;
chksum = dd->newChecksum;
}
/* make sure file's at beginning */
PR_Seek( fh, 0, PR_SEEK_SET );
/* calculate appropriate checksum */
switch (dd->checksumType)
{
case GDIFF_CS_NONE:
result = GDIFF_OK;
break;
case GDIFF_CS_CRC32:
if ( dd->checksumLength == CRC32_LEN )
result = gdiff_valCRC32( dd, fh, getlong(chksum) );
else
result = GDIFF_ERR_HEADER;
break;
case GDIFF_CS_MD5:
case GDIFF_CS_SHA:
default:
/* unsupported checksum type */
result = GDIFF_ERR_CHKSUMTYPE;
break;
}
/* reset file position to beginning and return status */
PR_Seek( fh, 0, PR_SEEK_SET );
return (result);
}
/*---------------------------------------------------------
* gdiff_valCRC32()
*
* computes the checksum of the file and compares it to
* the passed in checksum. Assumes file is positioned at
* beginning.
*---------------------------------------------------------
*/
static
int32 gdiff_valCRC32( pDIFFDATA dd, PRFileDesc* fh, uint32 chksum )
{
uint32 crc;
uint32 nRead;
crc = crc32(0L, Z_NULL, 0);
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
while ( nRead > 0 )
{
crc = crc32( crc, dd->databuf, nRead );
nRead = PR_Read (fh, dd->databuf, dd->bufsize);
}
if ( crc == chksum )
return GDIFF_OK;
else
return GDIFF_ERR_CHECKSUM;
}
/*---------------------------------------------------------
* gdiff_ApplyPatch()
*
* Combines patch data with source file to produce the
* new target file. Assumes all three files have been
* opened, GDIFF header read, and all other setup complete
*
* The GDIFF patch is processed sequentially which random
* access is neccessary for the source file.
*---------------------------------------------------------
*/
static
int32 gdiff_ApplyPatch( pDIFFDATA dd )
{
int32 err;
XP_Bool done;
uint32 position;
uint32 count;
uchar opcode;
uchar cmdbuf[MAXCMDSIZE];
done = FALSE;
while ( !done ) {
err = gdiff_getdiff( dd, &opcode, OPSIZE );
if ( err != GDIFF_OK )
break;
switch (opcode)
{
case ENDDIFF:
done = TRUE;
break;
case ADD16:
err = gdiff_getdiff( dd, cmdbuf, ADD16SIZE );
if ( err == GDIFF_OK ) {
err = gdiff_add( dd, getshort( cmdbuf ) );
}
break;
case ADD32:
err = gdiff_getdiff( dd, cmdbuf, ADD32SIZE );
if ( err == GDIFF_OK ) {
err = gdiff_add( dd, getlong( cmdbuf ) );
}
break;
case COPY16BYTE:
err = gdiff_getdiff( dd, cmdbuf, COPY16BYTESIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = *(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY16SHORT:
err = gdiff_getdiff( dd, cmdbuf, COPY16SHORTSIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = getshort(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY16LONG:
err = gdiff_getdiff( dd, cmdbuf, COPY16LONGSIZE );
if ( err == GDIFF_OK ) {
position = getshort( cmdbuf );
count = getlong(cmdbuf + sizeof(short));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32BYTE:
err = gdiff_getdiff( dd, cmdbuf, COPY32BYTESIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = *(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32SHORT:
err = gdiff_getdiff( dd, cmdbuf, COPY32SHORTSIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = getshort(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY32LONG:
err = gdiff_getdiff( dd, cmdbuf, COPY32LONGSIZE );
if ( err == GDIFF_OK ) {
position = getlong( cmdbuf );
count = getlong(cmdbuf + sizeof(long));
err = gdiff_copy( dd, position, count );
}
break;
case COPY64:
/* we don't support 64-bit file positioning yet */
err = GDIFF_ERR_OPCODE;
break;
default:
err = gdiff_add( dd, opcode );
break;
}
if ( err != GDIFF_OK )
done = TRUE;
}
/* return status */
return (err);
}
/*---------------------------------------------------------
* gdiff_getdiff()
*
* reads the next "length" bytes of the diff into "buffer"
*
* XXX: need a diff buffer to optimize reads!
*---------------------------------------------------------
*/
static
int32 gdiff_getdiff( pDIFFDATA dd, uchar *buffer, uint32 length )
{
uint32 bytesRead;
bytesRead = PR_Read (dd->fDiff, buffer, length);
if ( bytesRead != length )
return GDIFF_ERR_BADDIFF;
return GDIFF_OK;
}
/*---------------------------------------------------------
* gdiff_add()
*
* append "count" bytes from diff file to new file
*---------------------------------------------------------
*/
static
int32 gdiff_add( pDIFFDATA dd, uint32 count )
{
int32 err = GDIFF_OK;
uint32 nRead;
uint32 chunksize;
while ( count > 0 ) {
chunksize = ( count > dd->bufsize) ? dd->bufsize : count;
nRead = PR_Read (dd->fDiff, dd->databuf, chunksize);
if ( nRead != chunksize ) {
err = GDIFF_ERR_BADDIFF;
break;
}
PR_Write (dd->fOut, dd->databuf, chunksize);
count -= chunksize;
}
return (err);
}
/*---------------------------------------------------------
* gdiff_copy()
*
* copy "count" bytes from "position" in source file
*---------------------------------------------------------
*/
static
int32 gdiff_copy( pDIFFDATA dd, uint32 position, uint32 count )
{
int32 err = GDIFF_OK;
uint32 nRead;
uint32 chunksize;
PR_Seek (dd->fSrc, position, PR_SEEK_SET);
while ( count > 0 ) {
chunksize = (count > dd->bufsize) ? dd->bufsize : count;
nRead = PR_Read (dd->fSrc, dd->databuf, chunksize);
if ( nRead != chunksize ) {
err = GDIFF_ERR_OLDFILE;
break;
}
PR_Write (dd->fOut, dd->databuf, chunksize);
count -= chunksize;
}
return (err);
}

View File

@@ -1,79 +0,0 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef nsInstallPatch_h__
#define nsInstallPatch_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
#include "nsInstallFolder.h"
#include "nsInstallVersion.h"
class nsInstallPatch : public nsInstallObject
{
public:
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
const nsString& folderSpec,
const nsString& inPartialPath,
PRInt32 *error);
nsInstallPatch( nsInstall* inInstall,
const nsString& inVRName,
const nsString& inVInfo,
const nsString& inJarLocation,
PRInt32 *error);
virtual ~nsInstallPatch();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsInstallVersion *mVersionInfo;
nsFileSpec *mTargetFile;
nsFileSpec *mPatchFile;
nsFileSpec *mPatchedFile;
nsString *mJarLocation;
nsString *mRegistryName;
PRInt32 NativePatch(const nsFileSpec &sourceFile, const nsFileSpec &patchfile, nsFileSpec **newFile);
void* HashFilePath(const nsFilePath& aPath);
};
#endif /* nsInstallPatch_h__ */

View File

@@ -1,343 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#include "nsIXPInstallProgress.h"
#include "nsInstallProgressDialog.h"
#include "nsIAppShellComponentImpl.h"
#include "nsIServiceManager.h"
#include "nsIDocumentViewer.h"
#include "nsIContent.h"
#include "nsINameSpaceManager.h"
#include "nsIContentViewer.h"
#include "nsIDOMElement.h"
#include "nsINetService.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID( kAppShellServiceCID, NS_APPSHELL_SERVICE_CID );
static NS_DEFINE_IID( kNetServiceCID, NS_NETSERVICE_CID );
// Utility to set element attribute.
static nsresult setAttribute( nsIDOMXULDocument *doc,
const char *id,
const char *name,
const nsString &value ) {
nsresult rv = NS_OK;
if ( doc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
if ( elem ) {
// Set the text attribute.
rv = elem->SetAttribute( name, value );
if ( NS_SUCCEEDED( rv ) ) {
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
// Utility to get element attribute.
static nsresult getAttribute( nsIDOMXULDocument *doc,
const char *id,
const char *name,
nsString &value ) {
nsresult rv = NS_OK;
if ( doc ) {
// Find specified element.
nsCOMPtr<nsIDOMElement> elem;
rv = doc->GetElementById( id, getter_AddRefs( elem ) );
if ( elem ) {
// Set the text attribute.
rv = elem->GetAttribute( name, value );
if ( NS_SUCCEEDED( rv ) ) {
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: SetAttribute failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetElementById failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
} else {
rv = NS_ERROR_NULL_POINTER;
}
return rv;
}
nsInstallProgressDialog::nsInstallProgressDialog()
{
NS_INIT_REFCNT();
mWindow = nsnull;
mDocument = nsnull;
}
nsInstallProgressDialog::~nsInstallProgressDialog()
{
}
NS_IMPL_ADDREF( nsInstallProgressDialog );
NS_IMPL_RELEASE( nsInstallProgressDialog );
NS_IMETHODIMP
nsInstallProgressDialog::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL) {
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if (aIID.Equals(nsIXPInstallProgress::GetIID())) {
*aInstancePtr = (void*) ((nsInstallProgressDialog*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(nsIXULWindowCallbacks::GetIID())) {
*aInstancePtr = (void*) ((nsIXULWindowCallbacks*)this);
NS_ADDREF_THIS();
return NS_OK;
}
if (aIID.Equals(kISupportsIID)) {
*aInstancePtr = (void*) (nsISupports*)((nsIXPInstallProgress*)this);
NS_ADDREF_THIS();
return NS_OK;
}
return NS_ERROR_NO_INTERFACE;
}
NS_IMETHODIMP
nsInstallProgressDialog::BeforeJavascriptEvaluation()
{
nsresult rv = NS_OK;
// Get app shell service.
nsIAppShellService *appShell;
rv = nsServiceManager::GetService( kAppShellServiceCID,
nsIAppShellService::GetIID(),
(nsISupports**)&appShell );
if ( NS_SUCCEEDED( rv ) )
{
// Open "progress" dialog.
nsIURL *url;
rv = NS_NewURL( &url, "resource:/res/xpinstall/progress.xul" );
if ( NS_SUCCEEDED(rv) )
{
nsIWebShellWindow *newWindow;
rv = appShell->CreateTopLevelWindow( nsnull,
url,
PR_TRUE,
newWindow,
nsnull,
this, // callbacks??
0,
0 );
if ( NS_SUCCEEDED( rv ) )
{
mWindow = newWindow;
NS_RELEASE( newWindow );
if (mWindow != nsnull)
mWindow->Show(PR_TRUE);
}
else
{
DEBUG_PRINTF( PR_STDOUT, "Error creating progress dialog, rv=0x%X\n", (int)rv );
}
NS_RELEASE( url );
}
nsServiceManager::ReleaseService( kAppShellServiceCID, appShell );
}
else
{
DEBUG_PRINTF( PR_STDOUT, "Unable to get app shell service, rv=0x%X\n", (int)rv );
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::AfterJavascriptEvaluation()
{
if (mWindow)
{
mWindow->Close();
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallStarted(const char *UIPackageName)
{
setAttribute( mDocument, "dialog.uiPackageName", "value", nsString(UIPackageName) );
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::ItemScheduled(const char *message)
{
PRInt32 maxChars = 40;
nsString theMessage(message);
PRInt32 len = theMessage.Length();
if (len > maxChars)
{
PRInt32 offset = (len/2) - ((len - maxChars)/2);
PRInt32 count = (len - maxChars);
theMessage.Cut(offset, count);
theMessage.Insert(nsString("..."), offset);
}
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
nsString aValue;
getAttribute( mDocument, "data.canceled", "value", aValue );
if (aValue.EqualsIgnoreCase("true"))
return -1;
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum)
{
PRInt32 maxChars = 40;
nsString theMessage(message);
PRInt32 len = theMessage.Length();
if (len > maxChars)
{
PRInt32 offset = (len/2) - ((len - maxChars)/2);
PRInt32 count = (len - maxChars);
theMessage.Cut(offset, count);
theMessage.Insert(nsString("..."), offset);
}
setAttribute( mDocument, "dialog.currentAction", "value", theMessage );
nsresult rv = NS_OK;
char buf[16];
PR_snprintf( buf, sizeof buf, "%lu", totNum );
setAttribute( mDocument, "dialog.progress", "max", buf );
if (totNum != 0)
{
PR_snprintf( buf, sizeof buf, "%lu", ((totNum-itemNum)/totNum) );
}
else
{
PR_snprintf( buf, sizeof buf, "%lu", 0 );
}
setAttribute( mDocument, "dialog.progress", "value", buf );
return NS_OK;
}
NS_IMETHODIMP
nsInstallProgressDialog::InstallAborted()
{
return NS_OK;
}
// Do startup stuff from C++ side.
NS_IMETHODIMP
nsInstallProgressDialog::ConstructBeforeJavaScript(nsIWebShell *aWebShell)
{
nsresult rv = NS_OK;
// Get content viewer from the web shell.
nsCOMPtr<nsIContentViewer> contentViewer;
rv = aWebShell ? aWebShell->GetContentViewer(getter_AddRefs(contentViewer))
: NS_ERROR_NULL_POINTER;
if ( contentViewer ) {
// Up-cast to a document viewer.
nsCOMPtr<nsIDocumentViewer> docViewer( do_QueryInterface( contentViewer, &rv ) );
if ( docViewer ) {
// Get the document from the doc viewer.
nsCOMPtr<nsIDocument> document;
rv = docViewer->GetDocument(*getter_AddRefs(document));
if ( document ) {
// Upcast to XUL document.
mDocument = do_QueryInterface( document, &rv );
if ( ! mDocument )
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDOMXULDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetDocument failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: Upcast to nsIDocumentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
}
else
{
DEBUG_PRINTF( PR_STDOUT, "%s %d: GetContentViewer failed, rv=0x%X\n",
__FILE__, (int)__LINE__, (int)rv );
}
return rv;
}

View File

@@ -1,67 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __nsInstallProgressDialog_h__
#define __nsInstallProgressDialog_h__
#include "nsIXPInstallProgress.h"
#include "nsISupports.h"
#include "nsISupportsUtils.h"
#include "nsCOMPtr.h"
#include "nsIWebShell.h"
#include "nsIWebShellWindow.h"
#include "nsIXULWindowCallbacks.h"
#include "nsIDocument.h"
#include "nsIDOMXULDocument.h"
class nsInstallProgressDialog : public nsIXPInstallProgress, public nsIXULWindowCallbacks
{
public:
nsInstallProgressDialog();
virtual ~nsInstallProgressDialog();
NS_DECL_ISUPPORTS
NS_IMETHOD BeforeJavascriptEvaluation();
NS_IMETHOD AfterJavascriptEvaluation();
NS_IMETHOD InstallStarted(const char *UIPackageName);
NS_IMETHOD ItemScheduled(const char *message);
NS_IMETHOD InstallFinalization(const char *message, PRInt32 itemNum, PRInt32 totNum);
NS_IMETHOD InstallAborted();
// Declare implementations of nsIXULWindowCallbacks interface functions.
NS_IMETHOD ConstructBeforeJavaScript(nsIWebShell *aWebShell);
NS_IMETHOD ConstructAfterJavaScript(nsIWebShell *aWebShell) { return NS_OK; }
private:
nsCOMPtr<nsIDOMXULDocument> mDocument;
nsCOMPtr<nsIWebShellWindow> mWindow;
};
#endif

View File

@@ -1,67 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstallResources.h"
char* nsInstallResources::GetInstallFileString(void)
{
return "Installing: %s";
}
char* nsInstallResources::GetReplaceFileString(void)
{
return "Replacing %s";
}
char* nsInstallResources::GetDeleteFileString(void)
{
return "Deleting file: %s";
}
char* nsInstallResources::GetDeleteComponentString(void)
{
return "Deleting component: %s";
}
char* nsInstallResources::GetExecuteString(void)
{
return "Executing: %s";
}
char* nsInstallResources::GetExecuteWithArgsString(void)
{
return "Executing: %s with argument: %s";
}
char* nsInstallResources::GetPatchFileString(void)
{
return "Patching: %s";
}
char* nsInstallResources::GetUninstallString(void)
{
return "Uninstalling: %s";
}

View File

@@ -1,45 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef __NS_INSTALLRESOURCES_H__
#define __NS_INSTALLRESOURCES_H__
class nsInstallResources
{
public:
static char* GetInstallFileString(void);
static char* GetReplaceFileString(void);
static char* GetDeleteFileString(void);
static char* GetDeleteComponentString(void);
static char* GetExecuteString(void);
static char* GetExecuteWithArgsString(void);
static char* GetPatchFileString(void);
static char* GetUninstallString(void);
};
#endif

View File

@@ -1,359 +0,0 @@
/* -*- 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 "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.
*/
#include "nsSoftwareUpdate.h"
#include "nsSoftwareUpdateStream.h"
#include "nsInstallTrigger.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPref.h"
#include "nsRepository.h"
#include "nsIServiceManager.h"
#include "nsSpecialSystemDirectory.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallTrigger_IID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
static NS_DEFINE_IID(kIInstallTrigger_CID, NS_SoftwareUpdateInstallTrigger_CID);
nsInstallTrigger::nsInstallTrigger()
{
mScriptObject = nsnull;
NS_INIT_REFCNT();
}
nsInstallTrigger::~nsInstallTrigger()
{
}
NS_IMETHODIMP
nsInstallTrigger::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstallTrigger_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstallTriggerGlobal*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallTrigger)
NS_IMPL_RELEASE(nsInstallTrigger)
NS_IMETHODIMP
nsInstallTrigger::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
nsIScriptGlobalObject *global = aContext->GetGlobalObject();
res = NS_NewScriptInstallTriggerGlobal( aContext,
(nsISupports *)(nsIDOMInstallTriggerGlobal*)this,
(nsISupports *)global,
&mScriptObject);
NS_IF_RELEASE(global);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstallTrigger::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
static NS_DEFINE_IID(kPrefsIID, NS_IPREF_IID);
static NS_DEFINE_IID(kPrefsCID, NS_PREF_CID);
NS_IMETHODIMP
nsInstallTrigger::UpdateEnabled(PRBool* aReturn)
{
nsIPref * prefs;
nsresult rv = nsServiceManager::GetService(kPrefsCID,
kPrefsIID,
(nsISupports**) &prefs);
if ( NS_SUCCEEDED(rv) )
{
rv = prefs->GetBoolPref( (const char*) AUTOUPDATE_ENABLE_PREF, aReturn);
if (NS_FAILED(rv))
{
*aReturn = PR_FALSE;
}
NS_RELEASE(prefs);
}
else
{
*aReturn = PR_FALSE; /* no prefs manager. set to false */
}
//FIX!!!!!!!!!!
*aReturn = PR_TRUE;
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn)
{
nsString localFile;
CreateTempFileFromURL(aURL, localFile);
// start the download (this will clean itself up)
nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(aURL, localFile, aFlags);
*aReturn = NS_OK; // maybe we should do something more.
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn)
{
nsString localFile;
CreateTempFileFromURL(aURL, localFile);
// start the download (this will clean itself up)
nsSoftwareUpdateListener *downloader = new nsSoftwareUpdateListener(aURL, localFile, 0);
*aReturn = NS_OK; // maybe we should do something more.
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallTrigger::CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn)
{
return NS_OK;
}
// this will take a nsIUrl, and create a temporary file. If it is local, we just us it.
void
nsInstallTrigger::CreateTempFileFromURL(const nsString& aURL, nsString& tempFileString)
{
// Checking to see if the url is local
if ( aURL.EqualsIgnoreCase("file://", 7) )
{
tempFileString.SetString( nsNSPRPath(nsFileURL(aURL)) );
}
else
{
nsSpecialSystemDirectory tempFile(nsSpecialSystemDirectory::OS_TemporaryDirectory);
PRInt32 result = aURL.RFind("/");
if (result != -1)
{
nsString jarName;
aURL.Right(jarName, (aURL.Length() - result) );
PRInt32 argOffset = jarName.RFind("?");
if (argOffset != -1)
{
// we need to remove ? and everything after it
jarName.Truncate(argOffset);
}
tempFile += jarName;
}
else
{
tempFile += "xpinstall.jar";
}
tempFile.MakeUnique();
tempFileString.SetString( nsNSPRPath( nsFilePath(tempFile) ) );
}
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
nsInstallTriggerFactory::nsInstallTriggerFactory(void)
{
NS_INIT_REFCNT();
}
nsInstallTriggerFactory::~nsInstallTriggerFactory(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMETHODIMP
nsInstallTriggerFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallTriggerFactory);
NS_IMPL_RELEASE(nsInstallTriggerFactory);
NS_IMETHODIMP
nsInstallTriggerFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
*aResult = nsnull;
nsresult rv;
nsInstallTrigger *inst = new nsInstallTrigger();
if (! inst)
return NS_ERROR_OUT_OF_MEMORY;
if (NS_FAILED(rv = inst->QueryInterface(aIID, aResult)))
{
// We didn't get the right interface.
NS_ERROR("didn't support the interface you wanted");
}
return rv;
}
NS_IMETHODIMP
nsInstallTriggerFactory::LockFactory(PRBool aLock)
{
// Not implemented in simplest case.
return NS_OK;
}

View File

@@ -1,72 +0,0 @@
#ifndef __NS_INSTALLTRIGGER_H__
#define __NS_INSTALLTRIGGER_H__
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMInstallTriggerGlobal.h"
#include "nsSoftwareUpdate.h"
#include "prtypes.h"
#include "nsHashtable.h"
#include "nsVector.h"
class nsInstallTrigger: public nsIScriptObjectOwner, public nsIDOMInstallTriggerGlobal
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstallTrigger_CID; return iid; }
nsInstallTrigger();
~nsInstallTrigger();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD UpdateEnabled(PRBool* aReturn);
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32 aFlags, PRInt32* aReturn);
NS_IMETHOD StartSoftwareUpdate(const nsString& aURL, PRInt32* aReturn);
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn);
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, PRInt32 aDiffLevel, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn);
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32 aMode, PRInt32* aReturn);
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32 aMode, PRInt32* aReturn);
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn);
NS_IMETHOD ConditionalSoftwareUpdate(const nsString& aURL, const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn);
NS_IMETHOD CompareVersion(const nsString& aRegName, PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn);
NS_IMETHOD CompareVersion(const nsString& aRegName, const nsString& aVersion, PRInt32* aReturn);
NS_IMETHOD CompareVersion(const nsString& aRegName, nsIDOMInstallVersion* aVersion, PRInt32* aReturn);
private:
void *mScriptObject;
void CreateTempFileFromURL(const nsString& aURL, nsString& tempFileString);
};
class nsInstallTriggerFactory : public nsIFactory
{
public:
nsInstallTriggerFactory();
~nsInstallTriggerFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif

View File

@@ -1,196 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#include "nsInstall.h"
#include "nsInstallUninstall.h"
#include "nsInstallResources.h"
#include "VerReg.h"
#include "prmem.h"
#include "nsFileSpec.h"
#include "ScheduledTasks.h"
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName);
REGERR su_UninstallProcessItem(char *component_path);
nsInstallUninstall::nsInstallUninstall( nsInstall* inInstall,
const nsString& regName,
PRInt32 *error)
: nsInstallObject(inInstall)
{
if (regName == "null")
{
*error = nsInstall::INVALID_ARGUMENTS;
return;
}
mRegName.SetString(regName);
char* userName = (char*)PR_Malloc(MAXREGPATHLEN);
PRInt32 err = VR_GetUninstallUserName( (char*) (const char*) nsAutoCString(regName),
userName,
MAXREGPATHLEN );
mUIName.SetString(userName);
if (err != REGERR_OK)
{
*error = nsInstall::NO_SUCH_COMPONENT;
}
PR_FREEIF(userName);
}
nsInstallUninstall::~nsInstallUninstall()
{
}
PRInt32 nsInstallUninstall::Prepare()
{
// no set-up necessary
return nsInstall::SUCCESS;
}
PRInt32 nsInstallUninstall::Complete()
{
PRInt32 err = nsInstall::SUCCESS;
if (mInstall == NULL)
return nsInstall::INVALID_ARGUMENTS;
err = SU_Uninstall( (char*)(const char*) nsAutoCString(mRegName) );
return err;
}
void nsInstallUninstall::Abort()
{
}
char* nsInstallUninstall::toString()
{
char* buffer = new char[1024];
char* temp = mUIName.ToNewCString();
sprintf( buffer, nsInstallResources::GetUninstallString(), temp);
delete [] temp;
return buffer;
}
PRBool
nsInstallUninstall::CanUninstall()
{
return PR_FALSE;
}
PRBool
nsInstallUninstall::RegisterPackageNode()
{
return PR_FALSE;
}
extern "C" NS_EXPORT PRInt32 SU_Uninstall(char *regPackageName)
{
REGERR status = REGERR_FAIL;
char pathbuf[MAXREGPATHLEN+1] = {0};
char sharedfilebuf[MAXREGPATHLEN+1] = {0};
REGENUM state = 0;
int32 length;
int32 err;
if (regPackageName == NULL)
return REGERR_PARAM;
if (pathbuf == NULL)
return REGERR_PARAM;
/* Get next path from Registry */
status = VR_Enum( regPackageName, &state, pathbuf, MAXREGPATHLEN );
/* if we got a good path */
while (status == REGERR_OK)
{
char component_path[2*MAXREGPATHLEN+1] = {0};
strcat(component_path, regPackageName);
length = strlen(regPackageName);
if (component_path[length - 1] != '/')
strcat(component_path, "/");
strcat(component_path, pathbuf);
err = su_UninstallProcessItem(component_path);
status = VR_Enum( regPackageName, &state, pathbuf, MAXREGPATHLEN );
}
err = VR_Remove(regPackageName);
// there is a problem here. It looks like if the file is refcounted, we still blow away the reg key
// FIX!
state = 0;
status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
while (status == REGERR_OK)
{
err = su_UninstallProcessItem(sharedfilebuf);
err = VR_UninstallDeleteFileFromList(regPackageName, sharedfilebuf);
status = VR_UninstallEnumSharedFiles( regPackageName, &state, sharedfilebuf, MAXREGPATHLEN );
}
err = VR_UninstallDeleteSharedFilesKey(regPackageName);
err = VR_UninstallDestroy(regPackageName);
return err;
}
REGERR su_UninstallProcessItem(char *component_path)
{
int refcount;
int err;
char filepath[MAXREGPATHLEN];
err = VR_GetPath(component_path, sizeof(filepath), filepath);
if ( err == REGERR_OK )
{
err = VR_GetRefCount(component_path, &refcount);
if ( err == REGERR_OK )
{
--refcount;
if (refcount > 0)
err = VR_SetRefCount(component_path, refcount);
else
{
err = VR_Remove(component_path);
DeleteFileNowOrSchedule(nsFileSpec(filepath));
}
}
else
{
/* delete node and file */
err = VR_Remove(component_path);
DeleteFileNowOrSchedule(nsFileSpec(filepath));
}
}
return err;
}

View File

@@ -1,63 +0,0 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "License"); you may not use this file except in
* compliance with the License. You may obtain a copy of the License at
* http://www.mozilla.org/NPL/
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is Mozilla Communicator client code,
* released March 31, 1998.
*
* The Initial Developer of the Original Code is Netscape Communications
* Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*
* Contributors:
* Daniel Veditz <dveditz@netscape.com>
* Douglas Turner <dougt@netscape.com>
*/
#ifndef nsInstallUninstall_h__
#define nsInstallUninstall_h__
#include "prtypes.h"
#include "nsString.h"
#include "nsInstallObject.h"
#include "nsInstall.h"
class nsInstallUninstall : public nsInstallObject
{
public:
nsInstallUninstall( nsInstall* inInstall,
const nsString& regName,
PRInt32 *error);
virtual ~nsInstallUninstall();
PRInt32 Prepare();
PRInt32 Complete();
void Abort();
char* toString();
PRBool CanUninstall();
PRBool RegisterPackageNode();
private:
nsString mRegName; // Registry name of package
nsString mUIName; // User name of package
};
#endif /* nsInstallUninstall_h__ */

View File

@@ -1,399 +0,0 @@
/* -*- 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 "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.
*/
#include "nsSoftwareUpdate.h"
#include "nsInstallVersion.h"
#include "nsIDOMInstallVersion.h"
#include "nscore.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptGlobalObject.h"
#include "prprf.h"
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIInstallVersion_IID, NS_IDOMINSTALLVERSION_IID);
nsInstallVersion::nsInstallVersion()
{
mScriptObject = nsnull;
NS_INIT_REFCNT();
}
nsInstallVersion::~nsInstallVersion()
{
}
NS_IMETHODIMP
nsInstallVersion::QueryInterface(REFNSIID aIID,void** aInstancePtr)
{
if (aInstancePtr == NULL)
{
return NS_ERROR_NULL_POINTER;
}
// Always NULL result, in case of failure
*aInstancePtr = NULL;
if ( aIID.Equals(kIScriptObjectOwnerIID))
{
*aInstancePtr = (void*) ((nsIScriptObjectOwner*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kIInstallVersion_IID) )
{
*aInstancePtr = (void*) ((nsIDOMInstallVersion*)this);
AddRef();
return NS_OK;
}
else if ( aIID.Equals(kISupportsIID) )
{
*aInstancePtr = (void*)(nsISupports*)(nsIScriptObjectOwner*)this;
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallVersion)
NS_IMPL_RELEASE(nsInstallVersion)
NS_IMETHODIMP
nsInstallVersion::GetScriptObject(nsIScriptContext *aContext, void** aScriptObject)
{
NS_PRECONDITION(nsnull != aScriptObject, "null arg");
nsresult res = NS_OK;
if (nsnull == mScriptObject)
{
res = NS_NewScriptInstallVersion(aContext,
(nsISupports *)(nsIDOMInstallVersion*)this,
nsnull,
&mScriptObject);
}
*aScriptObject = mScriptObject;
return res;
}
NS_IMETHODIMP
nsInstallVersion::SetScriptObject(void *aScriptObject)
{
mScriptObject = aScriptObject;
return NS_OK;
}
// this will go away when our constructors can have parameters.
NS_IMETHODIMP
nsInstallVersion::Init(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild)
{
major = aMajor;
minor = aMinor;
release = aRelease;
build = aBuild;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::Init(const nsString& version)
{
PRInt32 errorCode;
PRInt32 aMajor, aMinor, aRelease, aBuild;
major = minor = release = build = 0;
errorCode = nsInstallVersion::StringToVersionNumbers(version, &aMajor, &aMinor, &aRelease, &aBuild);
if (NS_SUCCEEDED(errorCode))
{
Init(aMajor, aMinor, aRelease, aBuild);
}
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetMajor(PRInt32* aMajor)
{
*aMajor = major;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetMajor(PRInt32 aMajor)
{
major = aMajor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetMinor(PRInt32* aMinor)
{
*aMinor = minor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetMinor(PRInt32 aMinor)
{
minor = aMinor;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetRelease(PRInt32* aRelease)
{
*aRelease = release;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetRelease(PRInt32 aRelease)
{
release = aRelease;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::GetBuild(PRInt32* aBuild)
{
*aBuild = build;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::SetBuild(PRInt32 aBuild)
{
build = aBuild;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::CompareTo(nsIDOMInstallVersion* aVersion, PRInt32* aReturn)
{
PRInt32 aMajor, aMinor, aRelease, aBuild;
aVersion->GetMajor(&aMajor);
aVersion->GetMinor(&aMinor);
aVersion->GetRelease(&aRelease);
aVersion->GetBuild(&aBuild);
CompareTo(aMajor, aMinor, aRelease, aBuild, aReturn);
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::CompareTo(const nsString& aAString, PRInt32* aReturn)
{
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn)
{
int diff;
if ( major == aMajor )
{
if ( minor == aMinor )
{
if ( release == aRelease )
{
if ( build == aBuild )
diff = EQUAL;
else if ( build > aBuild )
diff = BLD_DIFF;
else
diff = BLD_DIFF_MINUS;
}
else if ( release > aRelease )
diff = REL_DIFF;
else
diff = REL_DIFF_MINUS;
}
else if ( minor > aMinor )
diff = MINOR_DIFF;
else
diff = MINOR_DIFF_MINUS;
}
else if ( major > aMajor )
diff = MAJOR_DIFF;
else
diff = MAJOR_DIFF_MINUS;
*aReturn = diff;
return NS_OK;
}
NS_IMETHODIMP
nsInstallVersion::ToString(nsString& aReturn)
{
char *result=NULL;
result = PR_sprintf_append(result, "%d.%d.%d.%d", major, minor, release, build);
aReturn = result;
return NS_OK;
}
nsresult
nsInstallVersion::StringToVersionNumbers(const nsString& version, PRInt32 *aMajor, PRInt32 *aMinor, PRInt32 *aRelease, PRInt32 *aBuild)
{
PRInt32 errorCode;
int dot = version.Find('.', 0);
if ( dot == -1 )
{
*aMajor = version.ToInteger(&errorCode);
}
else
{
nsString majorStr;
version.Mid(majorStr, 0, dot);
*aMajor = majorStr.ToInteger(&errorCode);
int prev = dot+1;
dot = version.Find('.',prev);
if ( dot == -1 )
{
nsString minorStr;
version.Mid(minorStr, prev, version.Length() - prev);
*aMinor = minorStr.ToInteger(&errorCode);
}
else
{
nsString minorStr;
version.Mid(minorStr, prev, dot - prev);
*aMinor = minorStr.ToInteger(&errorCode);
prev = dot+1;
dot = version.Find('.',prev);
if ( dot == -1 )
{
nsString releaseStr;
version.Mid(releaseStr, prev, version.Length() - prev);
*aRelease = releaseStr.ToInteger(&errorCode);
}
else
{
nsString releaseStr;
version.Mid(releaseStr, prev, dot - prev);
*aRelease = releaseStr.ToInteger(&errorCode);
prev = dot+1;
if ( version.Length() > dot )
{
nsString buildStr;
version.Mid(buildStr, prev, version.Length() - prev);
*aBuild = buildStr.ToInteger(&errorCode);
}
}
}
}
return errorCode;
}
/////////////////////////////////////////////////////////////////////////
//
/////////////////////////////////////////////////////////////////////////
nsInstallVersionFactory::nsInstallVersionFactory(void)
{
NS_INIT_REFCNT();
}
nsInstallVersionFactory::~nsInstallVersionFactory(void)
{
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
}
NS_IMETHODIMP
nsInstallVersionFactory::QueryInterface(const nsIID &aIID, void **aResult)
{
if (! aResult)
return NS_ERROR_NULL_POINTER;
// Always NULL result, in case of failure
*aResult = nsnull;
if (aIID.Equals(kISupportsIID)) {
*aResult = NS_STATIC_CAST(nsISupports*, this);
AddRef();
return NS_OK;
} else if (aIID.Equals(kIFactoryIID)) {
*aResult = NS_STATIC_CAST(nsIFactory*, this);
AddRef();
return NS_OK;
}
return NS_NOINTERFACE;
}
NS_IMPL_ADDREF(nsInstallVersionFactory);
NS_IMPL_RELEASE(nsInstallVersionFactory);
NS_IMETHODIMP
nsInstallVersionFactory::CreateInstance(nsISupports *aOuter, REFNSIID aIID, void **aResult)
{
if (aResult == NULL)
{
return NS_ERROR_NULL_POINTER;
}
*aResult = NULL;
/* do I have to use iSupports? */
nsInstallVersion *inst = new nsInstallVersion();
if (inst == NULL)
return NS_ERROR_OUT_OF_MEMORY;
nsresult result = inst->QueryInterface(aIID, aResult);
if (NS_FAILED(result))
delete inst;
return result;
}
NS_IMETHODIMP
nsInstallVersionFactory::LockFactory(PRBool aLock)
{
return NS_OK;
}

View File

@@ -1,76 +0,0 @@
#ifndef __NS_INSTALLVERSION_H__
#define __NS_INSTALLVERSION_H__
#include "nscore.h"
#include "nsString.h"
#include "nsIFactory.h"
#include "nsISupports.h"
#include "nsIScriptObjectOwner.h"
#include "nsIDOMInstallVersion.h"
#include "nsSoftwareUpdate.h"
#include "prtypes.h"
class nsInstallVersion: public nsIScriptObjectOwner, public nsIDOMInstallVersion
{
public:
static const nsIID& IID() { static nsIID iid = NS_SoftwareUpdateInstallVersion_CID; return iid; }
nsInstallVersion();
virtual ~nsInstallVersion();
NS_DECL_ISUPPORTS
NS_IMETHOD GetScriptObject(nsIScriptContext *aContext, void** aScriptObject);
NS_IMETHOD SetScriptObject(void* aScriptObject);
NS_IMETHOD Init(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild);
NS_IMETHOD Init(const nsString& aVersionString);
NS_IMETHOD GetMajor(PRInt32* aMajor);
NS_IMETHOD SetMajor(PRInt32 aMajor);
NS_IMETHOD GetMinor(PRInt32* aMinor);
NS_IMETHOD SetMinor(PRInt32 aMinor);
NS_IMETHOD GetRelease(PRInt32* aRelease);
NS_IMETHOD SetRelease(PRInt32 aRelease);
NS_IMETHOD GetBuild(PRInt32* aBuild);
NS_IMETHOD SetBuild(PRInt32 aBuild);
NS_IMETHOD ToString(nsString& aReturn);
NS_IMETHOD CompareTo(nsIDOMInstallVersion* aVersion, PRInt32* aReturn);
NS_IMETHOD CompareTo(const nsString& aString, PRInt32* aReturn);
NS_IMETHOD CompareTo(PRInt32 aMajor, PRInt32 aMinor, PRInt32 aRelease, PRInt32 aBuild, PRInt32* aReturn);
static nsresult StringToVersionNumbers(const nsString& version, PRInt32 *aMajor, PRInt32 *aMinor, PRInt32 *aRelease, PRInt32 *aBuild);
private:
void *mScriptObject;
PRInt32 major;
PRInt32 minor;
PRInt32 release;
PRInt32 build;
};
class nsInstallVersionFactory : public nsIFactory
{
public:
nsInstallVersionFactory();
virtual ~nsInstallVersionFactory();
NS_DECL_ISUPPORTS
NS_IMETHOD CreateInstance(nsISupports *aOuter,
REFNSIID aIID,
void **aResult);
NS_IMETHOD LockFactory(PRBool aLock);
};
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,665 +0,0 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMInstallVersion.h"
#include "nsIDOMInstallTriggerGlobal.h"
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
extern PRBool ConvertJSValToObj(nsISupports** aSupports,
REFNSIID aIID,
const nsString& aTypeName,
JSContext* aContext,
jsval aValue);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIInstallTriggerGlobalIID, NS_IDOMINSTALLTRIGGERGLOBAL_IID);
NS_DEF_PTR(nsIDOMInstallTriggerGlobal);
/***********************************************************************/
//
// InstallTriggerGlobal Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetInstallTriggerGlobalProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallTriggerGlobal *a = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// InstallTriggerGlobal Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetInstallTriggerGlobalProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallTriggerGlobal *a = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case 0:
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// InstallTriggerGlobal finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeInstallTriggerGlobal(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// InstallTriggerGlobal enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallTriggerGlobal(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// InstallTriggerGlobal resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveInstallTriggerGlobal(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method UpdateEnabled
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalUpdateEnabled(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRBool nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->UpdateEnabled(&nativeRet)) {
return JS_FALSE;
}
*rval = BOOLEAN_TO_JSVAL(nativeRet);
}
else {
JS_ReportError(cx, "Function UpdateEnabled requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method StartSoftwareUpdate
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalStartSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
PRInt32 b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 2)
{
// public int StartSoftwareUpdate(String url,
// int flag);
ConvertJSValToStr(b0, cx, argv[0]);
if(!JS_ValueToInt32(cx, argv[1], (int32 *)&b1))
{
JS_ReportError(cx, "2nd parameter must be a number");
return JS_FALSE;
}
if(NS_OK != nativeThis->StartSoftwareUpdate(b0, b1, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else if(argc >= 1)
{
// public int StartSoftwareUpdate(String url);
ConvertJSValToStr(b0, cx, argv[0]);
if(NS_OK != nativeThis->StartSoftwareUpdate(b0, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "Function StartSoftwareUpdate requires 2 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ConditionalSoftwareUpdate
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalConditionalSoftwareUpdate(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
nsAutoString b2str;
PRInt32 b2int;
nsAutoString b3str;
PRInt32 b3int;
PRInt32 b4;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if(argc >= 5)
{
// public int ConditionalSoftwareUpdate(String url,
// String registryName,
// int diffLevel,
// String version, --OR-- VersionInfo version
// int mode);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(!JS_ValueToInt32(cx, argv[2], (int32 *)&b2int))
{
JS_ReportError(cx, "3rd parameter must be a number");
return JS_FALSE;
}
if(!JS_ValueToInt32(cx, argv[4], (int32 *)&b4))
{
JS_ReportError(cx, "5th parameter must be a number");
return JS_FALSE;
}
if(JSVAL_IS_OBJECT(argv[3]))
{
JSObject* jsobj = JSVAL_TO_OBJECT(argv[3]);
JSClass* jsclass = JS_GetClass(cx, jsobj);
if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE))
{
nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj);
if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2int, version, b4, &nativeRet))
{
return JS_FALSE;
}
}
}
else
{
ConvertJSValToStr(b3str, cx, argv[3]);
if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2int, b3str, b4, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
}
else if(argc >= 4)
{
// public int ConditionalSoftwareUpdate(String url,
// String registryName,
// String version, --OR-- VersionInfo version
// int mode);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(!JS_ValueToInt32(cx, argv[3], (int32 *)&b3int))
{
JS_ReportError(cx, "4th parameter must be a number");
return JS_FALSE;
}
if(JSVAL_IS_OBJECT(argv[2]))
{
JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]);
JSClass* jsclass = JS_GetClass(cx, jsobj);
if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE))
{
nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj);
if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, version, b3int, &nativeRet))
{
return JS_FALSE;
}
}
}
else
{
ConvertJSValToStr(b2str, cx, argv[2]);
if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2str, b3int, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
}
else if(argc >= 3)
{
// public int ConditionalSoftwareUpdate(String url,
// String registryName,
// String version); --OR-- VersionInfo version
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
if(JSVAL_IS_OBJECT(argv[2]))
{
JSObject* jsobj = JSVAL_TO_OBJECT(argv[2]);
JSClass* jsclass = JS_GetClass(cx, jsobj);
if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE))
{
nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj);
if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, version, &nativeRet))
{
return JS_FALSE;
}
}
}
else
{
ConvertJSValToStr(b2str, cx, argv[2]);
if(NS_OK != nativeThis->ConditionalSoftwareUpdate(b0, b1, b2str, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "Function ConditionalSoftwareUpdate requires 5 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CompareVersion
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobalCompareVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallTriggerGlobal *nativeThis = (nsIDOMInstallTriggerGlobal*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1str;
PRInt32 b1int;
PRInt32 b2int;
PRInt32 b3int;
PRInt32 b4int;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if(argc >= 5)
{
// public int CompareVersion(String registryName,
// int major,
// int minor,
// int release,
// int build);
ConvertJSValToStr(b0, cx, argv[0]);
if(!JS_ValueToInt32(cx, argv[1], (int32 *)&b1int))
{
JS_ReportError(cx, "2th parameter must be a number");
return JS_FALSE;
}
if(!JS_ValueToInt32(cx, argv[2], (int32 *)&b2int))
{
JS_ReportError(cx, "3th parameter must be a number");
return JS_FALSE;
}
if(!JS_ValueToInt32(cx, argv[3], (int32 *)&b3int))
{
JS_ReportError(cx, "4th parameter must be a number");
return JS_FALSE;
}
if(!JS_ValueToInt32(cx, argv[4], (int32 *)&b4int))
{
JS_ReportError(cx, "5th parameter must be a number");
return JS_FALSE;
}
if(NS_OK != nativeThis->CompareVersion(b0, b1int, b2int, b3int, b4int, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else if(argc >= 2)
{
// public int CompareVersion(String registryName,
// String version); --OR-- VersionInfo version
ConvertJSValToStr(b0, cx, argv[0]);
if(JSVAL_IS_OBJECT(argv[1]))
{
JSObject* jsobj = JSVAL_TO_OBJECT(argv[1]);
JSClass* jsclass = JS_GetClass(cx, jsobj);
if((nsnull != jsclass) && (jsclass->flags & JSCLASS_HAS_PRIVATE))
{
nsIDOMInstallVersion* version = (nsIDOMInstallVersion*)JS_GetPrivate(cx, jsobj);
if(NS_OK != nativeThis->CompareVersion(b0, version, &nativeRet))
{
return JS_FALSE;
}
}
}
else
{
ConvertJSValToStr(b1str, cx, argv[1]);
if(NS_OK != nativeThis->CompareVersion(b0, b1str, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "Function CompareVersion requires 5 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for InstallTriggerGlobal
//
JSClass InstallTriggerGlobalClass = {
"InstallTriggerGlobal",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetInstallTriggerGlobalProperty,
SetInstallTriggerGlobalProperty,
EnumerateInstallTriggerGlobal,
ResolveInstallTriggerGlobal,
JS_ConvertStub,
FinalizeInstallTriggerGlobal
};
//
// InstallTriggerGlobal class properties
//
static JSPropertySpec InstallTriggerGlobalProperties[] =
{
{0}
};
//
// InstallTriggerGlobal class methods
//
static JSFunctionSpec InstallTriggerGlobalMethods[] =
{
{"UpdateEnabled", InstallTriggerGlobalUpdateEnabled, 0},
{"StartSoftwareUpdate", InstallTriggerGlobalStartSoftwareUpdate, 2},
{"ConditionalSoftwareUpdate", InstallTriggerGlobalConditionalSoftwareUpdate, 5},
{"CompareVersion", InstallTriggerGlobalCompareVersion, 5},
{0}
};
//
// InstallTriggerGlobal constructor
//
PR_STATIC_CALLBACK(JSBool)
InstallTriggerGlobal(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
//
// InstallTriggerGlobal class initialization
//
nsresult NS_InitInstallTriggerGlobalClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallTriggerGlobal", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&InstallTriggerGlobalClass, // JSClass
InstallTriggerGlobal, // JSNative ctor
0, // ctor args
InstallTriggerGlobalProperties, // proto props
InstallTriggerGlobalMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
if ((PR_TRUE == JS_LookupProperty(jscontext, global, "InstallTriggerGlobal", &vp)) &&
JSVAL_IS_OBJECT(vp) &&
((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::MAJOR_DIFF);
JS_SetProperty(jscontext, constructor, "MAJOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::MINOR_DIFF);
JS_SetProperty(jscontext, constructor, "MINOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::REL_DIFF);
JS_SetProperty(jscontext, constructor, "REL_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::BLD_DIFF);
JS_SetProperty(jscontext, constructor, "BLD_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallTriggerGlobal::EQUAL);
JS_SetProperty(jscontext, constructor, "EQUAL", &vp);
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new InstallTriggerGlobal JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptInstallTriggerGlobal(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptInstallTriggerGlobal");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMInstallTriggerGlobal *aInstallTriggerGlobal;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitInstallTriggerGlobalClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIInstallTriggerGlobalIID, (void **)&aInstallTriggerGlobal);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &InstallTriggerGlobalClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aInstallTriggerGlobal);
}
else {
NS_RELEASE(aInstallTriggerGlobal);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -1,659 +0,0 @@
/* -*- 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.
*/
/* AUTO-GENERATED. DO NOT EDIT!!! */
#include "jsapi.h"
#include "nsJSUtils.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsIJSScriptObject.h"
#include "nsIScriptObjectOwner.h"
#include "nsIScriptGlobalObject.h"
#include "nsIPtr.h"
#include "nsString.h"
#include "nsIDOMInstallVersion.h"
#include "nsIScriptNameSpaceManager.h"
#include "nsRepository.h"
#include "nsDOMCID.h"
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
extern PRBool ConvertJSValToObj(nsISupports** aSupports,
REFNSIID aIID,
const nsString& aTypeName,
JSContext* aContext,
jsval aValue);
void ConvertJSvalToVersionString(nsString& versionString, JSContext* cx, jsval* argument);
static NS_DEFINE_IID(kIScriptObjectOwnerIID, NS_ISCRIPTOBJECTOWNER_IID);
static NS_DEFINE_IID(kIJSScriptObjectIID, NS_IJSSCRIPTOBJECT_IID);
static NS_DEFINE_IID(kIScriptGlobalObjectIID, NS_ISCRIPTGLOBALOBJECT_IID);
static NS_DEFINE_IID(kIInstallVersionIID, NS_IDOMINSTALLVERSION_IID);
NS_DEF_PTR(nsIDOMInstallVersion);
//
// InstallVersion property ids
//
enum InstallVersion_slots {
INSTALLVERSION_MAJOR = -1,
INSTALLVERSION_MINOR = -2,
INSTALLVERSION_RELEASE = -3,
INSTALLVERSION_BUILD = -4
};
/***********************************************************************/
//
// InstallVersion Properties Getter
//
PR_STATIC_CALLBACK(JSBool)
GetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case INSTALLVERSION_MAJOR:
{
PRInt32 prop;
if (NS_OK == a->GetMajor(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_MINOR:
{
PRInt32 prop;
if (NS_OK == a->GetMinor(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_RELEASE:
{
PRInt32 prop;
if (NS_OK == a->GetRelease(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
case INSTALLVERSION_BUILD:
{
PRInt32 prop;
if (NS_OK == a->GetBuild(&prop)) {
*vp = INT_TO_JSVAL(prop);
}
else {
return JS_FALSE;
}
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectGetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
/***********************************************************************/
//
// InstallVersion Properties Setter
//
PR_STATIC_CALLBACK(JSBool)
SetInstallVersionProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
{
nsIDOMInstallVersion *a = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
// If there's no private data, this must be the prototype, so ignore
if (nsnull == a) {
return JS_TRUE;
}
if (JSVAL_IS_INT(id)) {
switch(JSVAL_TO_INT(id)) {
case INSTALLVERSION_MAJOR:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetMajor(prop);
break;
}
case INSTALLVERSION_MINOR:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetMinor(prop);
break;
}
case INSTALLVERSION_RELEASE:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetRelease(prop);
break;
}
case INSTALLVERSION_BUILD:
{
PRInt32 prop;
int32 temp;
if (JSVAL_IS_NUMBER(*vp) && JS_ValueToInt32(cx, *vp, &temp)) {
prop = (PRInt32)temp;
}
else {
JS_ReportError(cx, "Parameter must be a number");
return JS_FALSE;
}
a->SetBuild(prop);
break;
}
default:
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
}
else {
return nsJSUtils::nsCallJSScriptObjectSetProperty(a, cx, id, vp);
}
return PR_TRUE;
}
//
// InstallVersion finalizer
//
PR_STATIC_CALLBACK(void)
FinalizeInstallVersion(JSContext *cx, JSObject *obj)
{
nsJSUtils::nsGenericFinalize(cx, obj);
}
//
// InstallVersion enumerate
//
PR_STATIC_CALLBACK(JSBool)
EnumerateInstallVersion(JSContext *cx, JSObject *obj)
{
return nsJSUtils::nsGenericEnumerate(cx, obj);
}
//
// InstallVersion resolve
//
PR_STATIC_CALLBACK(JSBool)
ResolveInstallVersion(JSContext *cx, JSObject *obj, jsval id)
{
return nsJSUtils::nsGenericResolve(cx, obj, id);
}
//
// Native method Init
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionInit(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString b0;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 1) {
nsJSUtils::nsConvertJSValToString(b0, cx, argv[0]);
if (NS_OK != nativeThis->Init(b0)) {
return JS_FALSE;
}
*rval = JSVAL_VOID;
}
else {
JS_ReportError(cx, "Function init requires 1 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method ToString
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionToString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
nsAutoString nativeRet;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if (argc >= 0) {
if (NS_OK != nativeThis->ToString(nativeRet)) {
return JS_FALSE;
}
nsJSUtils::nsConvertStringToJSVal(nativeRet, cx, rval);
}
else {
JS_ReportError(cx, "Function toString requires 0 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method CompareTo
//
PR_STATIC_CALLBACK(JSBool)
InstallVersionCompareTo(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsIDOMInstallVersion *nativeThis = (nsIDOMInstallVersion*)JS_GetPrivate(cx, obj);
JSBool rBool = JS_FALSE;
PRInt32 nativeRet;
nsString b0str;
PRInt32 b0int;
PRInt32 b1int;
PRInt32 b2int;
PRInt32 b3int;
nsIDOMInstallVersionPtr versionObj;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if (nsnull == nativeThis) {
return JS_TRUE;
}
if(argc >= 4)
{
// public int CompareTo(int major,
// int minor,
// int release,
// int build);
if(!JSVAL_IS_INT(argv[0]))
{
JS_ReportError(cx, "1st parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[1]))
{
JS_ReportError(cx, "2nd parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[2]))
{
JS_ReportError(cx, "3rd parameter must be a number");
return JS_FALSE;
}
else if(!JSVAL_IS_INT(argv[3]))
{
JS_ReportError(cx, "4th parameter must be a number");
return JS_FALSE;
}
b0int = JSVAL_TO_INT(argv[0]);
b1int = JSVAL_TO_INT(argv[1]);
b2int = JSVAL_TO_INT(argv[2]);
b3int = JSVAL_TO_INT(argv[3]);
if(NS_OK != nativeThis->CompareTo(b0int, b1int, b2int, b3int, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else if(argc >= 1)
{
// public int AddDirectory(String version); --OR-- VersionInfo version
if(JSVAL_IS_OBJECT(argv[0]))
{
if(JS_FALSE == ConvertJSValToObj((nsISupports **)&versionObj,
kIInstallVersionIID,
"InstallVersion",
cx,
argv[0]))
{
return JS_FALSE;
}
if(NS_OK != nativeThis->CompareTo(versionObj, &nativeRet))
{
return JS_FALSE;
}
}
else
{
ConvertJSValToStr(b0str, cx, argv[0]);
if(NS_OK != nativeThis->CompareTo(b0str, &nativeRet))
{
return JS_FALSE;
}
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "Function compareTo requires 4 parameters");
return JS_FALSE;
}
return JS_TRUE;
}
/***********************************************************************/
//
// class for InstallVersion
//
JSClass InstallVersionClass = {
"InstallVersion",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
GetInstallVersionProperty,
SetInstallVersionProperty,
EnumerateInstallVersion,
ResolveInstallVersion,
JS_ConvertStub,
FinalizeInstallVersion
};
//
// InstallVersion class properties
//
static JSPropertySpec InstallVersionProperties[] =
{
{"major", INSTALLVERSION_MAJOR, JSPROP_ENUMERATE},
{"minor", INSTALLVERSION_MINOR, JSPROP_ENUMERATE},
{"release", INSTALLVERSION_RELEASE, JSPROP_ENUMERATE},
{"build", INSTALLVERSION_BUILD, JSPROP_ENUMERATE},
{0}
};
//
// InstallVersion class methods
//
static JSFunctionSpec InstallVersionMethods[] =
{
{"init", InstallVersionInit, 1},
{"toString", InstallVersionToString, 0},
{"compareTo", InstallVersionCompareTo, 1},
{0}
};
//
// InstallVersion constructor
//
PR_STATIC_CALLBACK(JSBool)
InstallVersion(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsresult result;
nsIID classID;
nsIScriptContext* context = (nsIScriptContext*)JS_GetContextPrivate(cx);
nsIScriptNameSpaceManager* manager;
nsIDOMInstallVersion *nativeThis;
nsIScriptObjectOwner *owner = nsnull;
static NS_DEFINE_IID(kIDOMInstallVersionIID, NS_IDOMINSTALLVERSION_IID);
result = context->GetNameSpaceManager(&manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = manager->LookupName("InstallVersion", PR_TRUE, classID);
NS_RELEASE(manager);
if (NS_OK != result) {
return JS_FALSE;
}
result = nsRepository::CreateInstance(classID,
nsnull,
kIDOMInstallVersionIID,
(void **)&nativeThis);
if (NS_OK != result) {
return JS_FALSE;
}
// XXX We should be calling Init() on the instance
result = nativeThis->QueryInterface(kIScriptObjectOwnerIID, (void **)&owner);
if (NS_OK != result) {
NS_RELEASE(nativeThis);
return JS_FALSE;
}
owner->SetScriptObject((void *)obj);
JS_SetPrivate(cx, obj, nativeThis);
NS_RELEASE(owner);
return JS_TRUE;
}
//
// InstallVersion class initialization
//
nsresult NS_InitInstallVersionClass(nsIScriptContext *aContext, void **aPrototype)
{
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
JSObject *proto = nsnull;
JSObject *constructor = nsnull;
JSObject *parent_proto = nsnull;
JSObject *global = JS_GetGlobalObject(jscontext);
jsval vp;
if ((PR_TRUE != JS_LookupProperty(jscontext, global, "InstallVersion", &vp)) ||
!JSVAL_IS_OBJECT(vp) ||
((constructor = JSVAL_TO_OBJECT(vp)) == nsnull) ||
(PR_TRUE != JS_LookupProperty(jscontext, JSVAL_TO_OBJECT(vp), "prototype", &vp)) ||
!JSVAL_IS_OBJECT(vp)) {
proto = JS_InitClass(jscontext, // context
global, // global object
parent_proto, // parent proto
&InstallVersionClass, // JSClass
InstallVersion, // JSNative ctor
0, // ctor args
InstallVersionProperties, // proto props
InstallVersionMethods, // proto funcs
nsnull, // ctor props (static)
nsnull); // ctor funcs (static)
if (nsnull == proto) {
return NS_ERROR_FAILURE;
}
if ((PR_TRUE == JS_LookupProperty(jscontext, global, "InstallVersion", &vp)) &&
JSVAL_IS_OBJECT(vp) &&
((constructor = JSVAL_TO_OBJECT(vp)) != nsnull)) {
vp = INT_TO_JSVAL(nsIDOMInstallVersion::EQUAL);
JS_SetProperty(jscontext, constructor, "EQUAL", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::BLD_DIFF);
JS_SetProperty(jscontext, constructor, "BLD_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::BLD_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "BLD_DIFF_MINUS", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::REL_DIFF);
JS_SetProperty(jscontext, constructor, "REL_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::REL_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "REL_DIFF_MINUS", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::MINOR_DIFF);
JS_SetProperty(jscontext, constructor, "MINOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::MINOR_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "MINOR_DIFF_MINUS", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::MAJOR_DIFF);
JS_SetProperty(jscontext, constructor, "MAJOR_DIFF", &vp);
vp = INT_TO_JSVAL(nsIDOMInstallVersion::MAJOR_DIFF_MINUS);
JS_SetProperty(jscontext, constructor, "MAJOR_DIFF_MINUS", &vp);
}
}
else if ((nsnull != constructor) && JSVAL_IS_OBJECT(vp)) {
proto = JSVAL_TO_OBJECT(vp);
}
else {
return NS_ERROR_FAILURE;
}
if (aPrototype) {
*aPrototype = proto;
}
return NS_OK;
}
//
// Method for creating a new InstallVersion JavaScript object
//
extern "C" NS_DOM nsresult NS_NewScriptInstallVersion(nsIScriptContext *aContext, nsISupports *aSupports, nsISupports *aParent, void **aReturn)
{
NS_PRECONDITION(nsnull != aContext && nsnull != aSupports && nsnull != aReturn, "null argument to NS_NewScriptInstallVersion");
JSObject *proto;
JSObject *parent;
nsIScriptObjectOwner *owner;
JSContext *jscontext = (JSContext *)aContext->GetNativeContext();
nsresult result = NS_OK;
nsIDOMInstallVersion *aInstallVersion;
if (nsnull == aParent) {
parent = nsnull;
}
else if (NS_OK == aParent->QueryInterface(kIScriptObjectOwnerIID, (void**)&owner)) {
if (NS_OK != owner->GetScriptObject(aContext, (void **)&parent)) {
NS_RELEASE(owner);
return NS_ERROR_FAILURE;
}
NS_RELEASE(owner);
}
else {
return NS_ERROR_FAILURE;
}
if (NS_OK != NS_InitInstallVersionClass(aContext, (void **)&proto)) {
return NS_ERROR_FAILURE;
}
result = aSupports->QueryInterface(kIInstallVersionIID, (void **)&aInstallVersion);
if (NS_OK != result) {
return result;
}
// create a js object for this class
*aReturn = JS_NewObject(jscontext, &InstallVersionClass, proto, parent);
if (nsnull != *aReturn) {
// connect the native object to the js object
JS_SetPrivate(jscontext, (JSObject *)*aReturn, aInstallVersion);
}
else {
NS_RELEASE(aInstallVersion);
return NS_ERROR_FAILURE;
}
return NS_OK;
}

View File

@@ -1,207 +0,0 @@
/* -*- 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.
*/
#include "jsapi.h"
#include "nscore.h"
#include "nsIScriptContext.h"
#include "nsString.h"
#include "nsInstall.h"
#include "nsWinProfile.h"
#include "nsJSWinProfile.h"
extern void ConvertJSValToStr(nsString& aString,
JSContext* aContext,
jsval aValue);
extern void ConvertStrToJSVal(const nsString& aProp,
JSContext* aContext,
jsval* aReturn);
extern PRBool ConvertJSValToBool(PRBool* aProp,
JSContext* aContext,
jsval aValue);
extern PRBool ConvertJSValToObj(nsISupports** aSupports,
REFNSIID aIID,
const nsString& aTypeName,
JSContext* aContext,
jsval aValue);
static void PR_CALLBACK WinProfileCleanup(JSContext *cx, JSObject *obj)
{
nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj);
delete nativeThis;
}
/***********************************************************************************/
// Native mothods for WinProfile functions
//
// Native method GetString
//
PR_STATIC_CALLBACK(JSBool)
WinProfileGetString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj);
nsString nativeRet;
nsAutoString b0;
nsAutoString b1;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if(nsnull == nativeThis)
{
return JS_TRUE;
}
if(argc >= 2)
{
// public int getString ( String section,
// String key);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
nativeThis->getString(b0, b1, &nativeRet);
ConvertStrToJSVal(nativeRet, cx, rval);
}
else
{
JS_ReportError(cx, "WinProfile.getString() parameters error");
return JS_FALSE;
}
return JS_TRUE;
}
//
// Native method WriteString
//
PR_STATIC_CALLBACK(JSBool)
WinProfileWriteString(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
nsWinProfile *nativeThis = (nsWinProfile*)JS_GetPrivate(cx, obj);
PRInt32 nativeRet;
nsAutoString b0;
nsAutoString b1;
nsAutoString b2;
*rval = JSVAL_NULL;
// If there's no private data, this must be the prototype, so ignore
if(nsnull == nativeThis)
{
return JS_TRUE;
}
if(argc >= 3)
{
// public int writeString ( String section,
// String key,
// String value);
ConvertJSValToStr(b0, cx, argv[0]);
ConvertJSValToStr(b1, cx, argv[1]);
ConvertJSValToStr(b2, cx, argv[2]);
if(NS_OK != nativeThis->writeString(b0, b1, b2, &nativeRet))
{
return JS_FALSE;
}
*rval = INT_TO_JSVAL(nativeRet);
}
else
{
JS_ReportError(cx, "WinProfile.writeString() parameters error");
return JS_FALSE;
}
return JS_TRUE;
}
//
// WinProfile constructor
//
PR_STATIC_CALLBACK(JSBool)
WinProfile(JSContext *cx, JSObject *obj, uintN argc, jsval *argv, jsval *rval)
{
return JS_FALSE;
}
/***********************************************************************/
//
// class for WinProfile
//
JSClass WinProfileClass = {
"WinProfile",
JSCLASS_HAS_PRIVATE,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_PropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
WinProfileCleanup
};
static JSConstDoubleSpec winprofile_constants[] =
{
{0}
};
//
// WinProfile class methods
//
static JSFunctionSpec WinProfileMethods[] =
{
{"getString", WinProfileGetString, 2},
{"writeString", WinProfileWriteString, 3},
{0}
};
PRInt32
InitWinProfilePrototype(JSContext *jscontext, JSObject *global, JSObject **winProfilePrototype)
{
*winProfilePrototype = JS_InitClass( jscontext, // context
global, // global object
nsnull, // parent proto
&WinProfileClass, // JSClass
nsnull, // JSNative ctor
0, // ctor args
nsnull, // proto props
nsnull, // proto funcs
nsnull, // ctor props (static)
WinProfileMethods); // ctor funcs (static)
if(nsnull == *winProfilePrototype)
{
return NS_ERROR_FAILURE;
}
if(PR_FALSE == JS_DefineConstDoubles(jscontext, *winProfilePrototype, winprofile_constants))
return NS_ERROR_FAILURE;
return NS_OK;
}

View File

@@ -1,25 +0,0 @@
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
#ifndef __NS_JSWINPROTOTYPE_H__
#define __NS_JSWINPROTOTYPE_H__
PRInt32
InitWinProfilePrototype(JSContext *jscontext, JSObject *global, JSObject **winRegPrototype);
#endif

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