This commit is contained in:
hshaw 1998-04-13 21:07:10 +00:00
Родитель 98505cde5e
Коммит 2db6787cfc
72 изменённых файлов: 14936 добавлений и 0 удалений

Просмотреть файл

@ -0,0 +1,21 @@
#!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 = ../../..
DIRS = netscape
include $(DEPTH)/config/rules.mk

Просмотреть файл

@ -0,0 +1,25 @@
#!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.
IGNORE_MANIFEST=1
#
DEPTH=..\..\..
DIRS=netscape
include <$(MOZ_SRC)\ns\config\rules.mak>

Просмотреть файл

@ -0,0 +1,21 @@
#!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 = ../../../..
DIRS = softupdate
include $(DEPTH)/config/rules.mk

Просмотреть файл

@ -0,0 +1,25 @@
#!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.
IGNORE_MANIFEST=1
#
DEPTH=..\..\..\..
DIRS=softupdate
include <$(MOZ_SRC)\ns\config\rules.mak>

Просмотреть файл

@ -0,0 +1,171 @@
/* -*- 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.
*/
/*
* FolderSpec.java
*
* 1/3/97 - atotic created the class
*/
package netscape.softupdate ;
import netscape.softupdate.*;
import netscape.security.Target;
/**
* FolderSpec hides directory path from the user of the
* SoftwareUpdate class
* It is not visible to classes outside of the softupdate package,
* because it is expected to change
*
*/
final class FolderSpec {
/* This class must stay final
* If not, an attacker could subclass it, and override GetCapTarget method */
private String urlPath; // Full path to the directory. Used to cache results from GetDirectoryPath
private String folderID; // Unique string specifying a folder
private String versionRegistryPath; // Version registry path of the package
private String userPackageName; // Name of the package presented to the user
/* Error codes */
final static int INVALID_PATH_ERR = -100;
final static int USER_CANCELLED_ERR = -101;
/* Constructor
*/
FolderSpec( String inFolderID , String inVRPath, String inPackageName)
{
urlPath = null;
folderID = inFolderID;
versionRegistryPath = inVRPath;
userPackageName = inPackageName;
}
/*
* GetDirectoryPath
* returns full path to the directory in the standard URL form
*/
String
GetDirectoryPath() throws SoftUpdateException
{
if (urlPath == null)
{
if (folderID.compareTo("User Pick") == 0) // Default package folder
{
// Try the version registry default path first
// urlPath = VersionRegistry.getDefaultDirectory( versionRegistryPath );
// if (urlPath == null)
urlPath = PickDefaultDirectory();
}
else if (folderID.compareTo("Installed") == 0)
{
// Then use the Version Registry path
urlPath = versionRegistryPath;
}
else
// Built-in folder
{
int err = NativeGetDirectoryPath();
if (err != 0)
throw( new SoftUpdateException( folderID, err));
}
}
return urlPath;
}
/**
* Returns full path to a file. Makes sure that the full path is bellow
* this directory (security measure
* @param relativePath relative path
* @return full path to a file
*/
String MakeFullPath(String relativePath) throws SoftUpdateException
{
// Security check. Make sure that we do not have '.. in the name
if ( (GetSecurityTargetID() == SoftwareUpdate.LIMITED_INSTALL) &&
( relativePath.regionMatches(0, "..", 0, 2)))
throw new SoftUpdateException(Strings.error_IllegalPath(), SoftwareUpdate.ILLEGAL_RELATIVE_PATH );
String fullPath = GetDirectoryPath() + GetNativePath ( relativePath );
return fullPath;
}
/* NativeGetDirectoryPath
* gets a platform-specific directory path
* stores it in urlPath
*/
private native int
NativeGetDirectoryPath();
/* GetNativePath
* returns a native equivalent of a XP directory path
*/
private native String
GetNativePath ( String Path );
/* PickDefaultDirectory
* asks the user for the default directory for the package
* stores the choice
*/
private String
PickDefaultDirectory() throws SoftUpdateException
{
urlPath = NativePickDefaultDirectory();
if (urlPath == null)
throw( new SoftUpdateException(folderID, INVALID_PATH_ERR));
return urlPath;
}
/*
* NativePickDefaultDirectory
* Platform-specific implementation of GetDirectoryPath
*/
private native String
NativePickDefaultDirectory() throws SoftUpdateException;
/*
* GetSecurityTarget
* returns security object associated with the directory
*/
netscape.security.Target
GetSecurityTarget()
{
int secID = GetSecurityTargetID();
return netscape.security.Target.findTarget( SoftwareUpdate.targetNames[secID] );
}
private native int
GetSecurityTargetID();
public String toString()
{
String path;
try
{
path = GetDirectoryPath();
}
catch ( Exception e )
{
path = null;
}
return path;
}
}

Просмотреть файл

@ -0,0 +1,118 @@
/* -*- 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.
*/
package netscape.softupdate ;
import java.lang.*;
import netscape.security.PrivilegeManager;
import netscape.security.Target;
import netscape.security.AppletSecurity;
/* InstallFile
* extracts the file to the temporary directory
* on Complete(), copies it to the final location
*/
class InstallExecute extends InstallObject {
private String jarLocation; // Location in the JAR
private String tempFile; // temporary file location
private String args; // command line arguments
private String cmdline; // constructed command-line
/* Constructor
inJarLocation - location inside the JAR file
inZigPtr - pointer to the ZIG *
*/
InstallExecute(SoftwareUpdate inSoftUpdate, String inJarLocation, String inArgs)
{
super(inSoftUpdate);
jarLocation = inJarLocation;
args = inArgs;
/* Request impersonation privileges */
netscape.security.PrivilegeManager privMgr;
Target impersonation, target;
privMgr = AppletSecurity.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
privMgr.enablePrivilege( impersonation );
/* check the security permissions */
target = Target.findTarget( SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] );
/* XXX: we need a way to indicate that a dialog box should appear.*/
privMgr.enablePrivilege( target, softUpdate.GetPrincipal() );
}
/* ExtractFile
* Extracts file out of the JAR archive into the temp directory
*/
protected void ExtractFile() throws SoftUpdateException
{
netscape.security.PrivilegeManager privMgr;
Target impersonation;
Target execTarget;
privMgr = AppletSecurity.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
execTarget = Target.findTarget( SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] );
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( execTarget, softUpdate.GetPrincipal() );
tempFile = softUpdate.ExtractJARFile( jarLocation, null );
if ( args == null || System.getProperty("os.name").startsWith("Mac") )
cmdline = tempFile;
else
cmdline = tempFile+" "+args;
}
/* Complete
* Completes the install by executing the file
* Security hazard: make sure we request the right permissions
*/
protected void Complete() throws SoftUpdateException
{
int err;
Target execTarget;
netscape.security.PrivilegeManager privMgr;
Target impersonation;
privMgr = AppletSecurity.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
privMgr.enablePrivilege( impersonation );
execTarget = Target.findTarget( SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] );
privMgr.enablePrivilege( execTarget, softUpdate.GetPrincipal() );
NativeComplete();
privMgr.revertPrivilege( execTarget );
//
// System.out.println("File executed: " + tempFile);
}
protected void Abort()
{
NativeAbort();
}
private native void NativeComplete() throws SoftUpdateException;
private native void NativeAbort();
public String toString()
{
return Strings.details_ExecuteProgress() + tempFile; // Needs I10n
}
}

Просмотреть файл

@ -0,0 +1,141 @@
/* -*- 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.
*/
package netscape.softupdate ;
import netscape.softupdate.*;
import netscape.util.*;
import java.lang.*;
import netscape.security.PrivilegeManager;
import netscape.security.Target;
import netscape.security.AppletSecurity;
/* InstallFile
* extracts the file to the temporary directory
* on Complete(), copies it to the final location
*/
final class InstallFile extends InstallObject {
private String vrName; // Name of the component
private VersionInfo versionInfo; // Version
private String jarLocation; // Location in the JAR
private String tempFile; // temporary file location
private String finalFile; // final file destination
private netscape.security.Target target; // security target
private boolean force; // whether install is forced
/* 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
*/
InstallFile(SoftwareUpdate inSoftUpdate,
String inVRName,
VersionInfo inVInfo,
String inJarLocation,
FolderSpec folderSpec,
String inPartialPath,
boolean forceInstall) throws SoftUpdateException
{
super(inSoftUpdate);
tempFile = null;
vrName = inVRName;
versionInfo = inVInfo;
jarLocation = inJarLocation;
force = forceInstall;
finalFile = folderSpec.MakeFullPath( inPartialPath );
/* Request impersonation privileges */
netscape.security.PrivilegeManager privMgr;
Target impersonation;
privMgr = AppletSecurity.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
privMgr.enablePrivilege( impersonation );
/* check the security permissions */
target = folderSpec.GetSecurityTarget();
/* XXX: we need a way to indicate that a dialog box should appear. */
privMgr.enablePrivilege( target, softUpdate.GetPrincipal() );
}
/* ExtractFile
* Extracts file out of the JAR archive into the temp directory
*/
protected void ExtractFile() throws SoftUpdateException
{
netscape.security.PrivilegeManager privMgr;
Target impersonation;
privMgr = AppletSecurity.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, softUpdate.GetPrincipal() );
tempFile = softUpdate.ExtractJARFile( jarLocation, finalFile );
}
/* Complete
* Completes the install:
* - move the downloaded file to the final location
* - updates the registry
*/
protected void Complete() throws SoftUpdateException
{
int err;
/* Check the security for our target */
netscape.security.PrivilegeManager privMgr;
Target impersonation;
privMgr = AppletSecurity.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, softUpdate.GetPrincipal() );
err = NativeComplete();
privMgr.revertPrivilege(target);
if ( 0 == err || SoftwareUpdate.REBOOT_NEEDED == err )
{
VersionRegistry.installComponent(vrName, finalFile, versionInfo);
if ( err != 0 )
throw( new SoftUpdateException(finalFile, err));
}
else
throw( new SoftUpdateException(Strings.error_InstallFileUnexpected() + finalFile, err));
// Eventually, put extracted files into proper locations
// System.out.println("File installed: " + finalFile);
}
protected void Abort()
{
NativeAbort();
}
private native void NativeAbort();
private native int NativeComplete();
public String toString()
{
return "Copy file to " + finalFile;
}
}

Просмотреть файл

@ -0,0 +1,53 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
package netscape.softupdate ;
import netscape.softupdate.*;
import netscape.util.*;
import java.lang.*;
/*
* InstallObject
* abstract class for things that get installed
* encapsulates a single action
* The way your subclass is used:
* Constructor should collect all the data needed to perform the action
* Complete() is called to complete the action
* Abort() is called when update is aborted
* You are guaranteed to be called with Complete() or Abort() before finalize
* If your Complete() throws, you'll also get called with an Abort()
*/
abstract class InstallObject {
SoftwareUpdate softUpdate;
InstallObject(SoftwareUpdate inSoftUpdate)
{
softUpdate = (SoftwareUpdate) inSoftUpdate;
}
/* Override with your action */
abstract protected void Complete() throws SoftUpdateException;
/* Override with an explanatory string for the progress dialog */
abstract public String toString();
/* Override with your clean-up function */
abstract protected void Abort();
}

Просмотреть файл

@ -0,0 +1,203 @@
/* -*- 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.
*/
package netscape.softupdate;
import netscape.softupdate.*;
import netscape.util.*;
import java.lang.*;
import netscape.security.PrivilegeManager;
import netscape.security.Target;
import netscape.security.AppletSecurity;
/* InstallFile
* extracts the file to the temporary directory
* on Complete(), copies it to the final location
*/
final class InstallPatch extends InstallObject {
private String vrName; // Registry name of the component
private VersionInfo versionInfo; // Version
private String jarLocation; // Location in the JAR
private String patchURL; // extracted location of diff (xpURL)
private String targetfile; // source and final file (native)
private String patchedfile; // temp name of patched file
/* Constructor
inSoftUpdate - softUpdate object we belong to
inVRName - full path of the registry component
inVInfo - full version info
inJarLocation - location inside the JAR file
folderspec - FolderSpec of target file
inPartialPath - target file on disk relative to folderspec
*/
InstallPatch(SoftwareUpdate inSoftUpdate,
String inVRName,
VersionInfo inVInfo,
String inJarLocation) throws SoftUpdateException
{
super( inSoftUpdate );
vrName = inVRName;
versionInfo = inVInfo;
jarLocation = inJarLocation;
targetfile = VersionRegistry.componentPath( vrName );
if ( targetfile == null )
throw new SoftUpdateException("", SoftwareUpdate.NO_SUCH_COMPONENT);
checkPrivileges();
}
InstallPatch(SoftwareUpdate inSoftUpdate,
String inVRName,
VersionInfo inVInfo,
String inJarLocation,
FolderSpec folderSpec,
String inPartialPath) throws SoftUpdateException
{
super( inSoftUpdate );
vrName = inVRName;
versionInfo = inVInfo;
jarLocation = inJarLocation;
targetfile = folderSpec.MakeFullPath( inPartialPath );
checkPrivileges();
}
private void checkPrivileges()
{
// This won't actually give us these privileges because
// we lose them again as soon as the function returns. But we
// don't really need the privs, we're just checking security
PrivilegeManager privMgr = AppletSecurity.getPrivilegeManager();
Target impersonation =
Target.findTarget( SoftwareUpdate.IMPERSONATOR );
Target priv = Target.findTarget(
SoftwareUpdate.targetNames[ SoftwareUpdate.FULL_INSTALL ] );
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( priv, softUpdate.GetPrincipal() );
}
protected void ApplyPatch() throws SoftUpdateException
{
String srcname;
boolean deleteOldSrc;
checkPrivileges();
patchURL = softUpdate.ExtractJARFile( jarLocation, targetfile );
if ( softUpdate.patchList.containsKey( targetfile ) ) {
srcname = (String)softUpdate.patchList.get( targetfile );
deleteOldSrc = true;
}
else {
srcname = targetfile;
deleteOldSrc = false;
}
patchedfile = NativePatch( srcname, patchURL );
if ( patchedfile != null ) {
softUpdate.patchList.put( targetfile, patchedfile );
}
else {
throw new SoftUpdateException( targetfile + " not patched",
SoftwareUpdate.UNEXPECTED_ERROR );
}
if ( deleteOldSrc ) {
NativeDeleteFile( srcname );
}
}
/* Complete
* Completes the install:
* - move the patched file to the final location
* - updates the registry
*/
protected void Complete() throws SoftUpdateException
{
int err;
checkPrivileges();
String tmp = (String)softUpdate.patchList.get( targetfile );
if ( tmp.compareTo( patchedfile ) == 0 )
{
// the patch has not been superceded--do final replacement
err = NativeReplace( targetfile, patchedfile );
if ( 0 == err || SoftwareUpdate.REBOOT_NEEDED == err )
{
VersionRegistry.installComponent(
vrName, targetfile, versionInfo);
if ( err != 0 )
throw new SoftUpdateException(targetfile, err);
}
else
{
throw new SoftUpdateException(
Strings.error_InstallFileUnexpected() + targetfile, err);
}
}
else
{
// nothing -- old intermediate patched file was
// deleted by superceding patch
}
}
protected void Abort()
{
String tmp = (String)softUpdate.patchList.get( targetfile );
if ( tmp.compareTo( patchedfile ) == 0 )
NativeDeleteFile( patchedfile );
}
private native String NativePatch( String srcfile, String diffURL );
private native int NativeReplace( String target, String tmpfile );
private native void NativeDeleteFile( String file );
public String toString()
{
return "Patch " + targetfile + " (" + versionInfo + ")";
}
}

Просмотреть файл

@ -0,0 +1,54 @@
#!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 = ../../../../..
PACKAGE = netscape/softupdate
JSRCS = FolderSpec.java \
InstallExecute.java \
InstallFile.java \
InstallPatch.java \
InstallObject.java \
ProgressDetails.java \
ProgressMediator.java \
ProgressWindow.java \
RegEntryEnumerator.java \
Registry.java \
RegistryErrors.java \
RegistryException.java \
RegistryNode.java \
RegKeyEnumerator.java \
SoftUpdateException.java \
SoftUpdateResourceBundle.java \
SoftwareUpdate.java \
Strings.java \
SymProgressDetails.java \
SymProgressWindow.java \
Trigger.java \
VersionInfo.java \
VersionRegistry.java \
WinProfile.java \
WinProfileItem.java \
WinReg.java \
WinRegItem.java \
WinRegValue.java \
$(NULL)
include $(DEPTH)/config/rules.mk
JAVA_SOURCEPATH = $(DEPTH)/modules/softupdt/classes

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- 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.
*/
/*
* ProgressWindow
*
*/
package netscape.softupdate ;
import java.awt.* ;
class ProgressDetails extends SymProgressDetails
{
ProgressMediator pm;
public ProgressDetails(ProgressMediator inPm)
{
pm = inPm;
label1.setText("");
btnCancel.setLabel(Strings.getString("s36"));
}
protected void
finalize() throws Throwable {
super.finalize();
if (pm != null)
pm.DetailsHidden();
}
void btnCancel_Clicked(Event event) {
hide();
dispose();
}
public synchronized void hide()
{
super.hide();
if (pm != null)
{
pm.DetailsHidden();
pm = null;
}
}
}

Просмотреть файл

@ -0,0 +1,182 @@
/* -*- 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.
*/
/*
* ProgressMediator.java 4/16/97
* @author atotic
*/
package netscape.softupdate;
/**
* Relays progress messages, and displays status
* in the progress window
*/
class ProgressMediator {
private ProgressWindow progress; // Progress window, guard against null when derefing
private ProgressDetails details; // Details window
private SoftwareUpdate su; // Object whose progress we are monitoring
ProgressMediator( SoftwareUpdate inSu)
{
su = inSu;
progress = null;
details = null;
}
protected void
finalize() throws Throwable
{
CleanUp();
}
/* Hide and dereference all the windows */
private void
CleanUp()
{
if ( progress != null )
{
//ProgressWindow p2 = progress;
progress.hide();
progress.dispose();
}
if ( details != null)
details.btnCancel_Clicked(null);
progress = null;
details = null;
su = null;
}
private void
ShowProgress()
{
if ( su.GetSilent())
return;
if ( progress == null )
progress = new ProgressWindow(this);
progress.toFront();
progress.show();
progress.toFront();
}
/* Shows the details window */
private void
ShowDetails()
{
if ( su.GetSilent())
return;
if (details == null)
{
details = new ProgressDetails(this);
// Text
details.setTitle( Strings.details_WinTitle() + su.GetUserPackageName() );
details.label1.setText(Strings.details_Explain(su.GetUserPackageName()));
// Fill in the current progress of the install
java.util.Enumeration e = su.GetInstallQueue();
while ( e.hasMoreElements() )
{
InstallObject ie = (InstallObject)e.nextElement();
details.detailArea.appendText(ie.toString() + "\n");
}
details.show();
}
details.toFront();
}
protected void
DetailsHidden()
{
details = null;
}
/* ProgressWindow API */
protected void
UserCancelled()
{
if (su != null)
su.UserCancelled();
}
protected void
UserApproved()
{
if (su != null)
su.UserApproved();
}
protected void
MoreInfo()
{
ShowDetails();
}
/* SofwareUpdate API bellow */
protected void
StartInstall()
{
ShowProgress();
if (progress != null)
{
// Set up the text
progress.setTitle(Strings.progress_Title() + su.GetUserPackageName());
progress.status.setText(Strings.progress_GettingReady() + su.GetUserPackageName());
progress.progress.setText("");
// Disable/enable controls
progress.install.disable();
}
}
protected void
ConfirmWithUser()
{
ShowProgress();
if ( progress != null )
{
progress.progress.setText("");
progress.status.setText(Strings.progress_ReadyToInstall1() +
su.GetUserPackageName());
progress.install.enable();
}
else // Give user approval right away if there is no UI
UserApproved();
}
/* Add it to the details list if showing */
protected void
ScheduleForInstall(InstallObject install)
{
String s = install.toString();
if (progress != null) // Display text in progress area
progress.progress.setText(s);
if (details != null)
details.detailArea.appendText(s + "\n");
}
/* SmartUpdate is done */
void
Complete()
{
CleanUp();
}
}

Просмотреть файл

@ -0,0 +1,53 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* ProgressWindow
*
*/
package netscape.softupdate ;
import java.awt.* ;
class ProgressWindow extends SymProgressWindow
{
ProgressMediator pm;
public ProgressWindow(ProgressMediator inPm)
{
pm = inPm;
install.setLabel(Strings.getString("s33"));
cancel.setLabel(Strings.getString("s34"));
info.setLabel(Strings.getString("s35"));
}
void cancel_Clicked(Event event)
{
pm.UserCancelled();
}
void install_Clicked(Event event)
{
pm.UserApproved();
}
void info_Clicked(Event event) {
pm.MoreInfo();
}
}

Просмотреть файл

@ -0,0 +1,59 @@
/* -*- 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.
*/
package netscape.softupdate;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import netscape.security.PrivilegeManager;
/**
* Helper class used to enumerate Registry subkeys
* @see RegistryNode#entries
*/
final class RegEntryEnumerator implements Enumeration {
private String name = "";
private Registry reg = null;
private int key = 0;
private int state = 0;
private String target;
RegEntryEnumerator(Registry registry, int startKey, String targ)
{
reg = registry;
key = startKey;
target = targ;
}
public boolean hasMoreElements() {
PrivilegeManager.checkPrivilegeEnabled( target );
String tmp = regNext(false);
return (tmp != null);
}
public Object nextElement() {
PrivilegeManager.checkPrivilegeEnabled( target );
name = regNext(true);
if (name == null) {
throw new NoSuchElementException("RegEntryEnumerator");
}
return name;
}
private native String regNext(boolean skip);
}

Просмотреть файл

@ -0,0 +1,63 @@
/* -*- 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.
*/
package netscape.softupdate;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import netscape.security.PrivilegeManager;
/**
* Helper class used to enumerate Registry subkeys
* @see RegistryNode#subkeys
*/
final class RegKeyEnumerator implements Enumeration {
private String path = "";
private Registry reg = null;
private int key = 0;
private int state = 0;
private int style = 0;
private String target;
RegKeyEnumerator(Registry registry, int startKey, int enumStyle, String targ)
{
reg = registry;
key = startKey;
style = enumStyle;
target = targ;
}
public boolean hasMoreElements() {
PrivilegeManager.checkPrivilegeEnabled( target );
String tmp = regNext(false);
return (tmp != null);
}
public Object nextElement() {
PrivilegeManager.checkPrivilegeEnabled( target );
path = regNext(true);
if (path == null) {
throw new NoSuchElementException("RegKeyEnumerator");
}
return path;
}
private native String regNext(boolean skip);
}

Просмотреть файл

@ -0,0 +1,293 @@
/* -*- 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.
*/
/*
* Registry.java
*
*/
package netscape.softupdate ;
import java.util.Enumeration;
import java.util.NoSuchElementException;
import netscape.security.PrivilegeManager;
import netscape.security.Principal;
import netscape.security.Target;
import netscape.security.UserTarget;
import netscape.security.ForbiddenTargetException;
/**
* The Registry class is a Java wrapper
* around the Navigator's built-in Cross-Platform Registry.
*
* @version 1.0 97/2/23
* @author Daniel Veditz
*/
public final class Registry implements RegistryErrors {
/*------------------
* constants
*------------------
*/
protected final static int ROOTKEY_USERS = 1;
protected final static int ROOTKEY_COMMON = 2;
protected final static int ROOTKEY_CURRENT_USER = 3;
protected final static int ROOTKEY_PRIVATE = 4;
protected final static int ROOTKEY = 32;
protected final static int ROOTKEY_VERSIONS = 33;
protected final static int PRIVATE_KEY_COMMON = -2;
protected final static int PRIVATE_KEY_USER = -3;
/* the following statics are actually used by RegistryNode objects,
* but that's not a public class--Registry is what people will use.
*/
protected final static int ENUM_NORMAL = 0;
protected final static int ENUM_DESCEND = 1;
public final static int TYPE_STRING = 0x11;
public final static int TYPE_INT_ARRAY = 0x12;
public final static int TYPE_BYTES = 0x13;
private static final String PRIVATE = "PrivateRegistryAccess";
private static final String STANDARD = "StandardRegistryAccess";
private static final String ADMIN = "AdministratorRegistryAccess";
/*
* Private data members
*/
private int hReg = 0;
private String regName;
private String username = null;
/*
* Constructors
*/
/**
* The no-arg constructor refers to standard netscape registry.
*/
public Registry() throws RegistryException {
this("");
}
/**
* Creates a registry object for the named registry and opens it
* (private for now, could be exposed later)
*/
private Registry(String name) throws RegistryException {
regName = name;
// ensure minimal registry privileges
PrivilegeManager.checkPrivilegeEnabled( PRIVATE );
int status = nOpen();
if ( status != REGERR_OK )
throw new RegistryException(status);
}
/*
* Primary methods, wrappers for native calls plus security
*/
/**
* Add a node to the registry
*/
public RegistryNode
addNode(RegistryNode root, String key) throws RegistryException
{
int rootkey;
String roottarg;
if ( root == null ) {
roottarg = ADMIN;
rootkey = ROOTKEY;
}
else {
roottarg = root.getTarget();
rootkey = root.getKey();
}
PrivilegeManager.checkPrivilegeEnabled( roottarg );
int status = nAddKey( rootkey, key );
if ( status != REGERR_OK )
throw new RegistryException(status);
return nGetKey( rootkey, key, roottarg );
}
/**
* Delete a node from the registry
*/
public void
deleteNode(RegistryNode root, String key) throws RegistryException
{
int rootkey;
String roottarg;
if ( root == null ) {
roottarg = ADMIN;
rootkey = ROOTKEY;
}
else {
roottarg = root.getTarget();
rootkey = root.getKey();
}
PrivilegeManager.checkPrivilegeEnabled( roottarg );
int status = nDeleteKey( rootkey, key );
if ( status != REGERR_OK )
throw new RegistryException(status);
}
/**
* Get a node object for further registry manipulation
*/
public RegistryNode
getNode(RegistryNode root, String key) throws RegistryException
{
int rootkey;
String roottarg;
if ( root == null ) {
roottarg = ADMIN;
rootkey = ROOTKEY;
}
else {
roottarg = root.getTarget();
rootkey = root.getKey();
}
PrivilegeManager.checkPrivilegeEnabled( roottarg );
return nGetKey( rootkey, key, roottarg );
}
public Enumeration
children(RegistryNode root, String key) throws RegistryException
{
RegistryNode node = getNode(root, key);
return new RegKeyEnumerator(this, node.getKey(),
ENUM_NORMAL, node.getTarget());
}
public Enumeration
subtree(RegistryNode root, String key) throws RegistryException
{
RegistryNode node = getNode(root, key);
return new RegKeyEnumerator(this, node.getKey(),
ENUM_DESCEND, node.getTarget());
}
/*
* Get starting nodes of varying privileges
*/
public RegistryNode
getSharedNode() throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( STANDARD );
return nGetKey( ROOTKEY_COMMON, "", STANDARD );
}
public RegistryNode
getSharedUserNode() throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( STANDARD );
return nGetKey( ROOTKEY_CURRENT_USER, "", STANDARD );
}
public RegistryNode
getPrivateNode() throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( PRIVATE );
Principal[] p =
PrivilegeManager.getPrivilegeManager().getClassPrincipalsFromStack(1);
if ( p == null ) {
System.out.println("Registry called without principals");
throw new NullPointerException("Registry called without principals");
}
String key = "/"+p[0].getFingerPrint()+"/Common";
int status = nAddKey( ROOTKEY_PRIVATE, key );
if ( status != REGERR_OK )
throw new RegistryException(status);
return nGetKey( ROOTKEY_PRIVATE, key, PRIVATE );
}
public RegistryNode
getPrivateUserNode() throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( PRIVATE );
Principal[] p =
PrivilegeManager.getPrivilegeManager().getClassPrincipalsFromStack(1);
if ( p == null ) {
System.out.println("Registry called without principals");
throw new NullPointerException("Registry called without principals");
}
String key = "/"+p[0].getFingerPrint()+"/Users/"+userName();
int status = nAddKey( ROOTKEY_PRIVATE, key );
if ( status != REGERR_OK )
throw new RegistryException(status);
return nGetKey( ROOTKEY_PRIVATE, key, PRIVATE );
}
/*
* private methods
*/
protected void finalize() throws Throwable {
if ( hReg != 0 )
nClose();
}
private String userName()
{
if ( username == null )
username = nUserName();
return username;
}
/*
* native methods
*/
private native int nOpen();
private native int nClose();
private native int nAddKey(int root, String key);
private native int nDeleteKey(int root, String key);
private native RegistryNode nGetKey(int root, String key, String targ);
private native String nUserName();
}

Просмотреть файл

@ -0,0 +1,51 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
* RegistryErrors
*
* This interface defines the error return codes used by the Registry
* and VersionRegistry classes and related helper classes. Many of these
* errors should never be returned by the Java interface to the registry,
* but the complete list is included just in case...
*/
package netscape.softupdate;
public interface RegistryErrors {
public static final int REGERR_OK = 0;
public static final int REGERR_FAIL = 1;
public static final int REGERR_NOMORE = 2;
public static final int REGERR_NOFIND = 3;
public static final int REGERR_BADREAD = 4;
public static final int REGERR_BADLOCN = 5;
public static final int REGERR_PARAM = 6;
public static final int REGERR_BADMAGIC = 7;
public static final int REGERR_BADCHECK = 8;
public static final int REGERR_NOFILE = 9;
public static final int REGERR_MEMORY = 10;
public static final int REGERR_BUFTOOSMALL = 11;
public static final int REGERR_NAMETOOLONG = 12;
public static final int REGERR_REGVERSION = 13;
public static final int REGERR_DELETED = 14;
public static final int REGERR_BADTYPE = 15;
public static final int REGERR_NOPATH = 16;
public static final int REGERR_BADNAME = 17;
public static final int REGERR_READONLY = 18;
public static final int REGERR_SECURITY = 99;
}

Просмотреть файл

@ -0,0 +1,42 @@
/* -*- 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.
*/
/*
* RegistryException.java
*/
package netscape.softupdate;
/*
* Registry exception class
*/
public class RegistryException extends Exception {
public RegistryException(String message) {
super(message);
}
RegistryException(int err) {
super("Error "+Integer.toString(err));
}
public RegistryException() {
super();
}
}

Просмотреть файл

@ -0,0 +1,131 @@
/* -*- 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.
*/
/*
* RegistryNode.java
*/
package netscape.softupdate ;
import netscape.softupdate.Registry;
import java.util.Enumeration;
import netscape.security.PrivilegeManager;
/**
* The RegistryNode class represents a node in an open registry
*/
public final class RegistryNode implements RegistryErrors {
/*
* Private data members
*/
private Registry reg;
private int key;
private String target;
protected int getKey() { return key; }
protected String getTarget() { return target; }
/**
* The constructor is private so this class can only be created
* by the native method Registry::nGetKey()
*/
private RegistryNode(Registry parent, int rootKey, String targ)
{
reg = parent;
key = rootKey;
target = targ;
}
public Enumeration properties()
{
return new RegEntryEnumerator(reg, key, target);
}
public void
deleteProperty(String name) throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( target );
int status = nDeleteEntry(name);
if (REGERR_OK != status)
throw new RegistryException(status);
}
public int
getPropertyType(String name) throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( target );
int status = nGetEntryType( name );
if ( status < 0 )
throw new RegistryException(-status);
return status;
}
public Object
getProperty(String name) throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( target );
return nGetEntry( name );
}
/* the following ugliness is due to a javah bug that can't
* entirely handle overloaded methods. (The implementations
* are unique, but the native stub redirection isn't.)
*/
public void
setProperty(String name, String value) throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( target );
int status = setEntryS(name, value);
if (status != REGERR_OK)
throw new RegistryException(status);
}
public void
setProperty(String name, int[] value) throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( target );
int status = setEntryI(name, value);
if (status != REGERR_OK)
throw new RegistryException(status);
}
public void
setProperty(String name, byte[] value) throws RegistryException
{
PrivilegeManager.checkPrivilegeEnabled( target );
int status = setEntryB(name, value);
if (status != REGERR_OK)
throw new RegistryException(status);
}
private native int nDeleteEntry(String name);
private native int nGetEntryType(String name);
private native Object nGetEntry(String name);
private native int setEntryS(String name, String value);
private native int setEntryI(String name, int[] value);
private native int setEntryB(String name, byte[] value);
}

Просмотреть файл

@ -0,0 +1,50 @@
/* -*- 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.
*/
/*
* SoftUpdateException.java
*
* 1/7/97 - atotic created the class
*/
package netscape.softupdate;
/*
* FolderSpec exception class
*/
class SoftUpdateException extends Exception {
int err; // error code
/* Constructor
* reason is the error code
*/
SoftUpdateException(String message, int reason)
{
super(message);
err = reason;
if ( (message != null) && ( message.length() > 0 ))
System.out.println(message + " " + String.valueOf(err));
// printStackTrace();
}
int GetError()
{
return err;
}
}

Просмотреть файл

@ -0,0 +1,79 @@
/* -*- 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.
*/
/* Internationalization of string resources for SoftwareUpdate
*/
package netscape.softupdate;
import java.util.ListResourceBundle;
/**
*/
public class SoftUpdateResourceBundle extends ListResourceBundle {
/**
* Overrides ListResourceBundle
*/
public Object[][] getContents() {
return contents;
}
static final Object[][] contents = {
// Non-Localizable Key // localize these strings
{"s1", "Low"},
{"s2", "Medium"},
{"s3", "High"},
{"s4", "Installing Java software on your computer."},
{"s5", "Installing and running software on your computer. "},
{"s6", "Installing and running software without warning you."},
{"s7", "Reading and writing to a windows .INI file"},
{"s8", "Reading and writing to the Windows Registry: Use extreme caution!"},
{"s9", "SmartUpdate: "},
{"s10", "Getting ready to install "},
{"s11", "Press \"Install\" to install "},
{"s12", ""},
{"s13", "Installing "},
{"s14", " will perform actions listed bellow:"},
{"s15", "Detailed SmartUpdate information: "},
{"s16", "Execute a program:"},
{"s17", "SmartUpdate:"},
{"s18", "Installer script does not have a certificate."},
{"s19", "Installer script had more than one certificate"},
{"s20", "Silent mode was denied."},
{"s21", "Must call StartInstall() to initialize SoftwareUpdate."},
{"s22", "Certificate of the Installer file does not match the certificate of the installed file"},
{"s23", "Package name is null or empty in StartInstall."},
{"s24", "Unexpected error in "},
{"s25", "Bad package name in AddSubcomponent. Did you call StartInstall()?"},
{"s26", "Illegal file path"},
{"s27", "Unexpected error when installing a file"},
{"s28", "Verification failed. 'this' must be passed to SoftwareUpdate constructor."},
{"s29", "SmartUpdate disabled"},
{"s30", "Security integrity check failed."},
{"s31", "Could not get installer name out of the global MIME headers inside the JAR file."},
{"s32", "Extraction of JAR file failed."},
{"s33", "Install"},
{"s34", "Cancel"},
{"s35", "More Info..."},
{"s36", "Close"},
{"s37", "Installing Java class files in the \"Java Download\" directory. This form of access allows new files to be added to this single directory on your computer's main hard disk, potentially replacing other files that have previously been installed in the directory. "},
{"s38", "Installing software on your computer's main hard disk, potentially deleting other files on the hard disk. Each time a program that has this form of access attempts to install software, it must display a dialog box that lets you choose whether to go ahead with the installation. If you go ahead, the installation program can execute any software on your computer. This potentially dangerous form of access is typically requested by an installation program after you have downloaded new software or a new version of software that you have previously installed. You should not grant this form of access unless you are installing or updating software from a reliable source."},
{"s39", "Installing software on your computer's main hard disk without giving you any warning, potentially deleting other files on the hard disk. Any software on the hard disk may be executed in the process. This is an extremely dangerous form of access. It should be granted by system administrators only."},
// stop localizing
};
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,232 @@
/* -*- 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.
*/
//
// Strings.java
// Aleksandar Totic
//
/**
* This class is a repository for all the dialog strings. Currently,
* it hard-codes the US-English strings, but it should eventually be
* linked to the Netscape XP strings library.
*
* @version
* @author atotic
*/
package netscape.softupdate;
import java.util.ResourceBundle;
class Strings {
// Resource bundle
private static ResourceBundle gbundle;
public static ResourceBundle bundle() {
if (gbundle == null)
try {
gbundle = ResourceBundle.getBundle("netscape.softupdate.SoftUpdateResourceBundle");
} catch ( Throwable t)
{
System.err.println("Could not get localized resources:"); // l10n, no need to localize
t.printStackTrace();
System.err.println("Using English Language Default.");
gbundle = new SoftUpdateResourceBundle();
}
return gbundle;
}
public static String getString(String key){
try {
return bundle().getString(key);
} catch ( Throwable t){
System.err.println("Could not get resource " + key + ":");
t.printStackTrace();
return key + "(!)";
}
}
//
// security resources for user targets
//
static String targetRiskLow() {
return getString("s1");
}
static String targetRiskColorLow() {
return "#aaffaa";
}
static String targetRiskMedium() {
return getString("s2");
}
static String targetRiskColorMedium() {
return "#ffffaa";
}
static String targetRiskHigh() {
return getString("s3");
}
static String targetRiskColorHigh() {
return "#ffaaaa";
}
static String targetDesc_LimitedInstall() {
return getString("s4");
}
static String targetUrl_LimitedInstall() {
// XXX: fix the URL.
return "http://iapp16.mcom.com/java/signing/Games.html";
}
static String targetDesc_FullInstall() {
return getString("s5");
}
static String targetUrl_FullInstall() {
// XXX: fix the URL.
return "http://iapp16.mcom.com/java/signing/FileRead.html";
}
static String targetDesc_SilentInstall() {
// XXX: this should be ripped out
return getString("s6");
}
static String targetUrl_SilentInstall() {
// XXX: fix the URL.
return "http://iapp16.mcom.com/java/signing/FileWrite.html";
}
static String targetDesc_WinIni() {
return getString("s7");
}
static String targetUrl_WinIni() {
// XXX: fix the URL.
return "http://iapp16.mcom.com/java/signing/FileWrite.html";
}
static String targetDesc_WinReg() {
return getString("s8");
}
static String targetUrl_WinReg() {
// XXX: fix the URL.
return "http://iapp16.mcom.com/java/signing/FileWrite.html";
}
// PROGRESS WINDOW
static String progress_Title() {
return getString("s9");
}
static String progress_GettingReady() {
return getString("s10");
}
static String progress_ReadyToInstall1() {
return getString("s11");
}
static String progress_ReadyToInstall2() {
return getString("s12");
}
// DETAILS WINDOW
static String details_Explain(String title) {
return getString("s13") + title + getString("s14");
}
static String details_WinTitle() {
return getString("s15");
}
static String details_ExecuteProgress() {
return getString("s16");
}
// ERROR STRINGS
static String error_Prefix()
{
return getString("s17");
}
static String error_NoCertificate() {
return error_Prefix() + getString("s18");
}
static String error_TooManyCertificates() {
return error_Prefix() + getString("s19");
}
static String error_SilentModeDenied() {
return error_Prefix() + getString("s20");
}
static String error_WinProfileMustCallStart() {
return error_Prefix() + getString("s21");
}
static String error_MismatchedCertificate() {
return error_Prefix() + getString("s22");
}
static String error_BadPackageName() {
return error_Prefix() + getString("s23");
}
static String error_Unexpected() {
return error_Prefix() + getString("s24");
}
static String error_BadPackageNameAS() {
return error_Prefix() + getString("s25");
}
static String error_IllegalPath() {
return error_Prefix() + getString("s26");
}
static String error_InstallFileUnexpected() {
return error_Prefix() + getString("s27");
}
static String error_BadJSArgument() {
return error_Prefix() + getString("s28");
}
static String error_SmartUpdateDisabled() {
return error_Prefix() + getString("s29");
}
static String error_NoInstallerFile() {
return "";
}
static String error_VerificationFailed() {
return error_Prefix() + getString("s30");
}
static String error_MissingInstaller() {
return error_Prefix() + getString("s31");
}
static String error_ExtractFailed() {
return error_Prefix() + getString("s32");
}
}

Просмотреть файл

@ -0,0 +1,76 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/*
A basic extension of the java.awt.Window class
*/
package netscape.softupdate;
import java.awt.*;
public class SymProgressDetails extends Frame {
void btnCancel_Clicked(Event event) {
//{{CONNECTION
// Disable the Frame
disable();
//}}
}
public SymProgressDetails() {
//{{INIT_CONTROLS
setLayout(null);
addNotify();
resize(insets().left + insets().right + 562,insets().top + insets().bottom + 326);
setFont(new Font("Dialog", Font.BOLD, 14));
label1 = new java.awt.Label("xxxxxIxxxxxx");
label1.reshape(insets().left + 12,insets().top + 12,536,36);
label1.setFont(new Font("Dialog", Font.PLAIN, 14));
add(label1);
detailArea = new java.awt.TextArea();
detailArea.reshape(insets().left + 12,insets().top + 60,536,216);
add(detailArea);
btnCancel = new java.awt.Button("xxxCxxx");
btnCancel.reshape(insets().left + 464,insets().top + 288,84,26);
add(btnCancel);
setTitle("Untitled");
//}}
//{{INIT_MENUS
//}}
}
public boolean handleEvent(Event event) {
if (event.target == btnCancel && event.id == Event.ACTION_EVENT) {
btnCancel_Clicked(event);
return true;
}
return super.handleEvent(event);
}
//{{DECLARE_CONTROLS
java.awt.Label label1;
java.awt.TextArea detailArea;
java.awt.Button btnCancel;
//}}
//{{DECLARE_MENUS
//}}
}

Просмотреть файл

@ -0,0 +1,92 @@
/* -*- 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.
*/
/*
A basic extension of the java.awt.Window class
*/
package netscape.softupdate;
import java.awt.*;
public class SymProgressWindow extends Frame {
void info_Clicked(Event event) {
}
void cancel_Clicked(Event event) {
}
void install_Clicked(Event event) {
}
public SymProgressWindow() {
//{{INIT_CONTROLS
setLayout(null);
setResizable(false);
addNotify();
resize(insets().left + insets().right + 497,insets().top + insets().bottom + 144);
setFont(new Font("Dialog", Font.BOLD, 12));
status = new java.awt.Label("xxxxxxxxxxxxx");
status.reshape(insets().left + 12,insets().top + 12,472,36);
status.setFont(new Font("Dialog", Font.BOLD, 12));
add(status);
progress = new java.awt.Label("xxxxxxxxxxx");
progress.reshape(insets().left + 12,insets().top + 48,472,40);
progress.setFont(new Font("Courier", Font.PLAIN, 14));
add(progress);
install = new java.awt.Button("xxxxxIxxx");
install.reshape(insets().left + 12,insets().top + 96,108,32);
add(install);
cancel = new java.awt.Button("xxxxxCxxx");
cancel.reshape(insets().left + 132,insets().top + 96,108,32);
add(cancel);
info = new java.awt.Button("xxxxxMxxxxx");
info.reshape(insets().left + 376,insets().top + 96,108,32);
add(info);
setTitle("Untitled");
//}}
//{{INIT_MENUS
//}}
}
public boolean handleEvent(Event event) {
if (event.target == install && event.id == Event.ACTION_EVENT) {
install_Clicked(event);
return true;
}
if (event.target == cancel && event.id == Event.ACTION_EVENT) {
cancel_Clicked(event);
return true;
}
if (event.target == info && event.id == Event.ACTION_EVENT) {
info_Clicked(event);
return true;
}
return super.handleEvent(event);
}
//{{DECLARE_CONTROLS
java.awt.Label status;
java.awt.Label progress;
java.awt.Button install;
java.awt.Button cancel;
java.awt.Button info;
//}}
//{{DECLARE_MENUS
//}}
}

Просмотреть файл

@ -0,0 +1,267 @@
/* -*- 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.
*/
package netscape.softupdate;
/**
* A class for 'triggering' the SmartUpdate and obtaining info
* No instances, all static methods
*/
public class Trigger {
/**
* diff levels are borrowed from the VersionInfo class
*/
public static final int MAJOR_DIFF = 4;
public static final int MINOR_DIFF = 3;
public static final int REL_DIFF = 2;
public static final int BLD_DIFF = 1;
public static final int EQUAL = 0;
/**
* DEFAULT_MODE has UI, triggers conditionally
* @see StartSoftwareUpdate flags argument
*
*/
public static int DEFAULT_MODE = 0;
/**
* FORCE_MODE will install the package regardless of what was installed previously
* @see StartSoftwareUpdate flags argument
*/
public static int FORCE_MODE = 1;
/**
* SILENT_MODE will not display the UI
*/
public static int SILENT_MODE = 2;
/**
* @return true if SmartUpdate is enabled
*/
public static native boolean UpdateEnabled();
/**
* @param componentName version registry name of the component
* @return version of the package. null if not installed, or SmartUpdate disabled
*/
public static VersionInfo GetVersionInfo( String componentName )
{
if (UpdateEnabled())
return VersionRegistry.componentVersion( componentName );
else
return null;
}
/**
* Unconditionally starts the software update
* @param url URL of the JAR file
* @param flags SmartUpdate modifiers (SILENT_INSTALL, FORCE_INSTALL)
* @return false if SmartUpdate did not trigger
*/
public static native boolean StartSoftwareUpdate( String url, int flags );
public static boolean StartSoftwareUpdate( String url )
{
return StartSoftwareUpdate( url, DEFAULT_MODE );
}
/**
* Conditionally starts the software update
* @param url URL of JAR file
* @param componentName name of component in the registry to compare
* the version against. This doesn't have to be the
* registry name of the installed package but could
* instead be a sub-component -- useful because if a
* file doesn't exist then it triggers automatically.
* @param diffLevel Specifies which component of the version must be
* different. If not supplied BLD_DIFF is assumed.
* If the diffLevel is positive the install is triggered
* if the specified version is NEWER (higher) than the
* registered version. If the diffLevel is negative then
* the install is triggered if the specified version is
* OLDER than the registered version. Obviously this
* will only have an effect if FORCE_MODE is also used.
* @param version The version that must be newer (can be a VersionInfo
* object or a string version
* @param flags Same flags as StartSoftwareUpdate (force, silent)
*/
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
int diffLevel,
VersionInfo version,
int flags)
{
try
{
boolean needJar = false;
if ((version == null) || (componentName == null))
needJar = true;
else
{
int stat = VersionRegistry.validateComponent( componentName );
if ( stat == VersionRegistry.REGERR_NOFIND ||
stat == VersionRegistry.REGERR_NOFILE )
{
// either component is not in the registry or it's a file
// node and the physical file is missing
needJar = true;
}
else
{
VersionInfo oldVer =
VersionRegistry.componentVersion( componentName );
if ( oldVer == null )
needJar = true;
else if ( diffLevel < 0 )
needJar = (version.compareTo( oldVer ) <= diffLevel);
else
needJar = (version.compareTo( oldVer ) >= diffLevel);
}
}
if (needJar)
return StartSoftwareUpdate( url, flags );
else
return false;
}
catch(Throwable e)
{
e.printStackTrace();
}
return false;
}
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
VersionInfo version)
{
return ConditionalSoftwareUpdate( url, componentName,
BLD_DIFF, version, DEFAULT_MODE );
}
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
String version)
{
return ConditionalSoftwareUpdate( url, componentName,
BLD_DIFF, new VersionInfo(version), DEFAULT_MODE );
}
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
VersionInfo version,
int flags)
{
return ConditionalSoftwareUpdate( url, componentName,
BLD_DIFF, version, flags );
}
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
String version,
int flags)
{
return ConditionalSoftwareUpdate( url, componentName,
BLD_DIFF, new VersionInfo(version), flags );
}
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
int diffLevel,
VersionInfo version)
{
return ConditionalSoftwareUpdate( url, componentName,
diffLevel, version, DEFAULT_MODE );
}
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
int diffLevel,
String version)
{
return ConditionalSoftwareUpdate( url, componentName,
diffLevel, new VersionInfo(version), DEFAULT_MODE );
}
public static boolean
ConditionalSoftwareUpdate( String url,
String componentName,
int diffLevel,
String version,
int flags)
{
return ConditionalSoftwareUpdate( url, componentName,
diffLevel, new VersionInfo(version), flags );
}
/**
* Validates existence and compares versions
*
* @param regName name of component in the registry to compare
* the version against. This doesn't have to be the
* registry name of an installed package but could
* instead be a sub-component. If the named item
* has a Path property the file must exist or a
* null version is used in the comparison.
* @param version The version to compare against
*/
public static int
CompareVersion( String regName, VersionInfo version )
{
if (!UpdateEnabled())
return EQUAL;
VersionInfo regVersion = GetVersionInfo( regName );
if ( regVersion == null ||
VersionRegistry.validateComponent( regName ) ==
VersionRegistry.REGERR_NOFILE ) {
regVersion = new VersionInfo(0,0,0,0);
}
return regVersion.compareTo( version );
}
public static int
CompareVersion( String regName, String version )
{
return CompareVersion( regName, new VersionInfo( version ) );
}
public static int
CompareVersion( String regName, int maj, int min, int rel, int bld )
{
return CompareVersion( regName, new VersionInfo(maj, min, rel, bld) );
}
}

Просмотреть файл

@ -0,0 +1,148 @@
/* -*- 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.
*/
package netscape.softupdate ;
public class VersionInfo {
public static final int MAJOR_DIFF = 4;
public static final int MINOR_DIFF = 3;
public static final int REL_DIFF = 2;
public static final int BLD_DIFF = 1;
public static final int EQUAL = 0;
/* Equivalent to Version Registry structure fields */
private int major = 0;
private int minor = 0;
private int release = 0;
private int build = 0;
private int check = 0;
public VersionInfo(int maj, int min, int rel, int bld)
{
this(maj, min, rel, bld, 0);
}
public VersionInfo(int maj, int min, int rel, int bld, int checksum)
{
major = maj;
minor = min;
release = rel;
build = bld;
check = checksum;
}
public VersionInfo(String version)
{
int dot = version.indexOf('.');
try {
if ( dot == -1 ) {
major = Integer.parseInt(version);
}
else {
major = Integer.parseInt(version.substring(0,dot));
int prev = dot+1;
dot = version.indexOf('.',prev);
if ( dot == -1 ) {
minor = Integer.parseInt(version.substring(prev));
}
else {
minor = Integer.parseInt(version.substring(prev, dot));
prev = dot+1;
dot = version.indexOf('.',prev);
if ( dot == -1 ) {
release = Integer.parseInt(version.substring(prev));
}
else {
release = Integer.parseInt(version.substring(prev,dot));
if ( version.length() > dot ) {
build = Integer.parseInt(version.substring(dot+1));
}
}
}
}
}
catch (Exception e) {
// parseInt can throw a NumberFormatException--in that case just
// trap the exception so we don't blow away someone's JAR install.
}
}
// Text representation of the version info
public String toString()
{
String vers = String.valueOf(major) + "." +
String.valueOf(minor) + "." +
String.valueOf(release) + "." +
String.valueOf(build);
// vers += ", checksum: " + check;
return vers;
}
/*
* compareTo() -- Compares version info.
* Returns -n, 0, n, where n = {1-4}
*/
public int compareTo(VersionInfo vi)
{
int diff;
if ( vi == null ) {
diff = MAJOR_DIFF;
}
else if ( this.major == vi.major ) {
if ( this.minor == vi.minor ) {
if ( this.release == vi.release ) {
if ( this.build == vi.build )
diff = EQUAL;
else if ( this.build > vi.build )
diff = BLD_DIFF;
else
diff = -BLD_DIFF;
}
else if ( this.release > vi.release )
diff = REL_DIFF;
else
diff = -REL_DIFF;
}
else if ( this. minor > vi.minor )
diff = MINOR_DIFF;
else
diff = -MINOR_DIFF;
}
else if ( this.major > vi.major )
diff = MAJOR_DIFF;
else
diff = -MAJOR_DIFF;
return diff;
}
public int compareTo(String version)
{
return compareTo(new VersionInfo(version));
}
public int compareTo(int maj, int min, int rel, int bld)
{
return compareTo(new VersionInfo(maj, min, rel, bld));
}
}

Просмотреть файл

@ -0,0 +1,150 @@
/* -*- 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.
*/
/*
* VersionRegistry.java
*/
package netscape.softupdate ;
import java.util.Enumeration;
import java.util.NoSuchElementException;
/**
* The VersionRegistry class is a set of static functions that form a wrapper
* around the Navigator's built-in Version Registry. The Version Registry
* represents a hierarchical tree of Navigator "components". Each component
* represents a physical file installed on the disk or a logical grouping of
* other components (e.g. Java). All components should have an associated
* version used to determine when an update is necessary; components that
* represent a physical file will also have the disk location of the file.<p>
*
* Component names passed as arguments can be specified as full paths from
* the VersionRegistry root, or as paths relative to the most recently
* run version of the Navigator. 3rd-party add-ons that work with
* multiple versions of Navigator will probably want to start their
* own sub-tree under the root, independent of the components for the
* Navigator itself.<p>
*
* Because this class is intended to be called from JavaScript in addition
* to Java, errors are indicated through return values rather than exceptions.
*
* It is not yet determined if this class will be public for generic use, or
* only available through the Automatic Software Download feature.
*
* @version 1.0 96/11/16
* @author Daniel Veditz
*/
final class VersionRegistry implements RegistryErrors {
/**
* This class is simply static function wrappers; don't "new" one
*/
private VersionRegistry() {}
/**
* Return the physical disk path for the specified component.
* @param component Registry path of the item to look up in the Registry
* @return The disk path for the specified component; NULL indicates error
* @see VersionRegistry#checkComponent
*/
protected static native String componentPath( String component );
/**
* Return the version information for the specified component.
* @param component Registry path of the item to look up in the Registry
* @return A VersionInfo object for the specified component; NULL indicates error
* @see VersionRegistry#checkComponent
*/
protected static native VersionInfo componentVersion( String component );
protected static native String getDefaultDirectory( String component );
protected static native int setDefaultDirectory( String component, String directory );
protected static native int installComponent( String name, String path,
VersionInfo version );
/**
* Delete component.
* @param component Registry path of the item to delete
* @return Error code
*/
protected static native int deleteComponent( String component );
/**
* Check the status of a named components.
* @param component Registry path of the item to check
* @return Error code. REGERR_OK means the named component was found in
* the registry, the filepath referred to an existing file, and the
* checksum matched the physical file. Other error codes can be used to
* distinguish which of the above was not true.
*/
protected static native int validateComponent( String component );
/**
* verify that the named component is in the registry (light-weight
* version of validateComponent since it does no disk access).
* @param component Registry path of the item to verify
* @return Error code. REGERR_OK means it is in the registry.
* REGERR_NOFIND will usually be the result otherwise.
*/
protected static native int inRegistry( String component );
/**
* Closes the registry file.
* @return Error code
*/
protected static native int close();
/**
* Returns an enumeration of the Version Registry contents. Use the
* enumeration methods of the returned object to fetch individual
* elements sequentially.
*/
protected static Enumeration elements() {
return new VerRegEnumerator();
}
}
/**
* Helper class used to enumerate the Version Registry
* @see VersionRegistry#elements
*/
final class VerRegEnumerator implements Enumeration {
private String path = "";
private int state = 0;
public boolean hasMoreElements() {
int saveState = state;
String tmp = regNext();
state = saveState;
return (tmp != null);
}
public Object nextElement() {
path = regNext();
if (path == null) {
throw new NoSuchElementException("VerRegEnumerator");
}
return "/"+path;
}
private native String regNext();
}

Просмотреть файл

@ -0,0 +1,106 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
package netscape.softupdate;
import netscape.security.UserTarget;
import netscape.security.PrivilegeManager;
import netscape.security.Principal;
import netscape.security.Target;
import netscape.security.UserDialogHelper;
final class WinProfile {
private String filename;
private SoftwareUpdate su;
private Principal principal;
private PrivilegeManager privMgr;
private Target impersonation;
private UserTarget target;
WinProfile( SoftwareUpdate suObj, FolderSpec folder, String file )
throws SoftUpdateException
{
filename = folder.MakeFullPath( file );
su = suObj;
principal = suObj.GetPrincipal();
privMgr = PrivilegeManager.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
target = (UserTarget)Target.findTarget(
SoftwareUpdate.targetNames[SoftwareUpdate.FULL_INSTALL] );
}
/**
* Schedules a write into a windows "ini" file. "Value" can be
* null to delete the value, but we don't support deleting an entire
* section via a null "key". The actual write takes place during
* SoftwareUpdate.FinalizeInstall();
*
* @return false for failure, true for success
*/
public boolean writeString( String section, String key, String value ) {
boolean result;
WinProfileItem item;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
item = new WinProfileItem( this, section, key, value );
su.ScheduleForInstall( item );
result = true;
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = false;
}
return result;
}
/**
* Reads a value from a windows "ini" file. We don't support using
* a null "key" to return a list of keys--you have to know what you want
*
* @return String value from INI, "" if not found, null if error
*/
public String getString( String section, String key ) {
String result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
return nativeGetString( section, key );
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = null;
}
return result;
}
protected String filename() { return filename; }
protected SoftwareUpdate softUpdate() { return su; }
protected int finalWriteString( String section, String key, String value ) {
// do we need another security check here?
return nativeWriteString( section, key, value );
}
private native int nativeWriteString( String section, String key, String value );
private native String nativeGetString( String section, String key );
}

Просмотреть файл

@ -0,0 +1,71 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
package netscape.softupdate ;
import netscape.softupdate.*;
import netscape.util.*;
import java.lang.*;
/**
* WinProfileItem
* Writes a single item into a Windows .INI file.
*/
final class WinProfileItem extends InstallObject {
private WinProfile profile; // initiating profile object
private String section; // Name of section
private String key; // Name of key
private String value; // data to write
WinProfileItem(WinProfile profileObj,
String sectionName,
String keyName,
String val) throws SoftUpdateException
{
super(profileObj.softUpdate());
profile = profileObj;
section = sectionName;
key = keyName;
value = val;
}
/**
* Completes the install:
* - writes the data into the .INI file
*/
protected void Complete() throws SoftUpdateException
{
profile.finalWriteString( section, key, value );
}
float GetInstallOrder()
{
return 4;
}
public String toString()
{
return "Write "+profile.filename()+": ["+section+"] "+key+"="+value;
}
// no need for special clean-up
protected void Abort() {}
}

Просмотреть файл

@ -0,0 +1,234 @@
/* -*- 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.
*/
package netscape.softupdate;
import netscape.security.PrivilegeManager;
import netscape.security.Principal;
import netscape.security.Target;
import netscape.security.UserTarget;
import netscape.security.UserDialogHelper;
final class WinReg {
/* not static because class is not public--users couldn't get to them */
public final int HKEY_CLASSES_ROOT = 0x80000000;
public final int HKEY_CURRENT_USER = 0x80000001;
public final int HKEY_LOCAL_MACHINE = 0x80000002;
public final int HKEY_USERS = 0x80000003;
protected final int CREATE = 1;
protected final int DELETE = 2;
protected final int DELETE_VAL = 3;
protected final int SET_VAL_STRING = 4;
protected final int SET_VAL = 5;
private int rootkey = HKEY_CLASSES_ROOT;
private Principal principal;
private PrivilegeManager privMgr;
private Target impersonation;
private SoftwareUpdate su;
private UserTarget target;
// static final String INI_TARGET = "FullWindowsRegistryAccess";
// static {
// /* create the target */
// target = new UserTarget(
// INI_TARGET,
// PrivilegeManager.getSystemPrincipal(),
// UserDialogHelper.targetRiskHigh(),
// UserDialogHelper.targetRiskColorHigh(),
// Strings.targetDesc_WinReg(),
// Strings.targetUrl_WinReg() );
// target = (UserTarget)target.registerTarget();
// };
WinReg(SoftwareUpdate suObj) {
su = suObj;
principal = suObj.GetPrincipal();
privMgr = PrivilegeManager.getPrivilegeManager();
impersonation = Target.findTarget( SoftwareUpdate.IMPERSONATOR );
target = (UserTarget)Target.findTarget(
SoftwareUpdate.targetNames[ SoftwareUpdate.FULL_INSTALL ] );
}
public void setRootKey(int key) {
rootkey = key;
}
public int createKey(String subkey, String classname) {
int result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
WinRegItem wi = new WinRegItem( this, rootkey, CREATE,
subkey, classname, null );
su.ScheduleForInstall( wi );
result = 0;
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = -1;
}
return result;
}
public int deleteKey(String subkey) {
int result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
WinRegItem wi = new WinRegItem( this, rootkey, DELETE,
subkey, null, null );
su.ScheduleForInstall( wi );
result = 0;
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = -1;
}
return result;
}
public int deleteValue(String subkey, String valname) {
int result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
WinRegItem wi = new WinRegItem( this, rootkey, DELETE_VAL,
subkey, valname, null );
su.ScheduleForInstall( wi );
result = 0;
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = -1;
}
return result;
}
public int setValueString(String subkey, String valname, String value) {
int result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
WinRegItem wi = new WinRegItem( this, rootkey, SET_VAL_STRING,
subkey, valname, (Object)value );
su.ScheduleForInstall( wi );
result = 0;
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = -1;
}
return result;
}
public String getValueString(String subkey, String valname) {
String result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
result = nativeGetValueString( subkey, valname );
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = null;
}
return result;
}
public int setValue(String subkey, String valname, WinRegValue value) {
int result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
WinRegItem wi = new WinRegItem( this, rootkey, SET_VAL,
subkey, valname, (Object)value );
su.ScheduleForInstall( wi );
result = 0;
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = -1;
}
return result; }
public WinRegValue getValue(String subkey, String valname) {
WinRegValue result;
try {
privMgr.enablePrivilege( impersonation );
privMgr.enablePrivilege( target, principal );
result = nativeGetValue( subkey, valname );
}
catch ( Exception e ) {
e.printStackTrace( System.out );
result = null;
}
return result;
}
protected SoftwareUpdate softUpdate() { return su; }
protected int finalCreateKey(int root, String subkey, String classname) {
setRootKey(root);
return nativeCreateKey(subkey, classname);
}
protected int finalDeleteKey(int root, String subkey) {
setRootKey(root);
return nativeDeleteKey(subkey);
}
protected int finalDeleteValue(int root, String subkey, String valname) {
setRootKey(root);
return nativeDeleteValue(subkey, valname);
}
protected int finalSetValueString(int root, String subkey, String valname, String value) {
setRootKey(root);
return nativeSetValueString(subkey, valname, value);
}
protected int finalSetValue(int root, String subkey, String valname, WinRegValue value) {
setRootKey(root);
return nativeSetValue(subkey, valname, value);
}
private native int nativeCreateKey(String subkey, String classname);
private native int nativeDeleteKey(String subkey);
private native int nativeDeleteValue(String subkey, String valname);
private native int nativeSetValueString(String subkey, String valname, String value);
private native String nativeGetValueString(String subkey, String valname);
private native int nativeSetValue(String subkey, String valname, WinRegValue value);
private native WinRegValue nativeGetValue(String subkey, String valname);
}

Просмотреть файл

@ -0,0 +1,135 @@
/* -*- 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.
*/
package netscape.softupdate ;
import netscape.softupdate.*;
import netscape.util.*;
import java.lang.*;
/**
* WinProfileItem
* Writes a single item into a Windows .INI file.
*/
final class WinRegItem extends InstallObject
{
private WinReg reg; // initiating WinReg object
private int rootkey;
private int command;
private String subkey; // Name of section
private String name; // Name of key
private Object value; // data to write
WinRegItem(WinReg regObj,
int root,
int action,
String sub,
String valname,
Object val) throws SoftUpdateException
{
super(regObj.softUpdate());
reg = regObj;
command = action;
rootkey = root;
subkey = sub;
name = valname;
value = val;
}
/**
* Completes the install:
* - writes the data into the .INI file
*/
protected void Complete() throws SoftUpdateException
{
switch (command) {
case reg.CREATE:
reg.finalCreateKey(rootkey, subkey, name);
break;
case reg.DELETE:
reg.finalDeleteKey(rootkey, subkey);
break;
case reg.DELETE_VAL:
reg.finalDeleteValue(rootkey, subkey, name );
break;
case reg.SET_VAL_STRING:
reg.finalSetValueString(rootkey, subkey, name, (String)value);
break;
case reg.SET_VAL:
reg.finalSetValue(rootkey, subkey, name, (WinRegValue)value);
break;
default:
throw new SoftUpdateException("WinRegItem", SoftwareUpdate.INVALID_ARGUMENTS);
}
}
float GetInstallOrder()
{
return 3;
}
public String toString()
{
switch (command) {
case reg.CREATE:
return "Create Registry Key "+keystr(rootkey,subkey,null);
case reg.DELETE:
return "Delete Registry key "+keystr(rootkey,subkey,null);
case reg.DELETE_VAL:
return "Delete Registry value "+keystr(rootkey,subkey,name);
case reg.SET_VAL_STRING:
return "Store Registry value "+keystr(rootkey,subkey,name);
case reg.SET_VAL:
return "Store Registry value "+keystr(rootkey,subkey,name);
default:
return "Unknown "+keystr(rootkey,subkey,name);
}
}
private String keystr(int root, String subkey, String name)
{
String rootstr;
switch (root) {
case reg.HKEY_CLASSES_ROOT:
rootstr = "\\HKEY_CLASSES_ROOT\\";
break;
case reg.HKEY_CURRENT_USER:
rootstr = "\\HKEY_CURRENT_USER\\";
break;
case reg.HKEY_LOCAL_MACHINE:
rootstr = "\\HKEY_LOCAL_MACHINE\\";
break;
case reg.HKEY_USERS:
rootstr = "\\HKEY_USERS\\";
break;
default:
rootstr = "\\#"+root+"\\";
break;
}
if ( name == null )
return rootstr+subkey;
else
return rootstr+subkey+" ["+name+"]";
}
// no need for special clean-up
protected void Abort() {}
}

Просмотреть файл

@ -0,0 +1,42 @@
/* -*- 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.
*/
package netscape.softupdate;
public final class WinRegValue {
public WinRegValue(int datatype, byte[] regdata) {
type = datatype;
data = regdata;
}
public int type;
public byte[] data;
public static final int REG_SZ = 1;
public static final int REG_EXPAND_SZ = 2;
public static final int REG_BINARY = 3;
public static final int REG_DWORD = 4;
public static final int REG_DWORD_LITTLE_ENDIAN = 4;
public static final int REG_DWORD_BIG_ENDIAN = 5;
public static final int REG_LINK = 6;
public static final int REG_MULTI_SZ = 7;
public static final int REG_RESOURCE_LIST = 8;
public static final int REG_FULL_RESOURCE_DESCRIPTOR = 9;
public static final int REG_RESOURCE_REQUIREMENTS_LIST = 10;
}

Просмотреть файл

@ -0,0 +1,56 @@
#!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.
IGNORE_MANIFEST=1
#
JAVA_SOURCEPATH=$(DEPTH)\modules\softupdt\classes
DEPTH=..\..\..\..\..
PACKAGE=netscape\softupdate
JSRCS=FolderSpec.java \
InstallExecute.java \
InstallFile.java \
InstallPatch.java \
InstallObject.java \
ProgressDetails.java \
ProgressMediator.java \
ProgressWindow.java \
RegEntryEnumerator.java \
Registry.java \
RegistryErrors.java \
RegistryException.java \
RegistryNode.java \
RegKeyEnumerator.java \
SoftUpdateException.java \
SoftUpdateResourceBundle.java \
SoftwareUpdate.java \
Strings.java \
SymProgressDetails.java \
SymProgressWindow.java \
Trigger.java \
VersionInfo.java \
VersionRegistry.java \
WinProfile.java \
WinProfileItem.java \
WinReg.java \
WinRegItem.java \
WinRegValue.java
CLASSROOT=y:\ns\modules\softupdt\classes
include <$(MOZ_SRC)\ns\config\rules.mak>

Просмотреть файл

@ -0,0 +1,24 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
MODULE = softupdt
EXPORTS = softupdt.h su_folderspec.h gdiff.h
include $(DEPTH)/config/rules.mk

Просмотреть файл

@ -0,0 +1,92 @@
/* -*- 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
*--------------------------------------------------------------*/
#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
/*--------------------------------------
* 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
#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 ERR_OK 0
#define ERR_ARGS 1
#define ERR_ACCESS 2
#define ERR_MEM 3
#define ERR_HEADER 4
#define ERR_BADDIFF 5
#define ERR_OPCODE 6
#define ERR_OLDFILE 7
#define ERR_CHKSUMTYPE 8
#define ERR_CHECKSUM 9
/*--------------------------------------
* miscellaneous
*------------------------------------*/
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif

Просмотреть файл

@ -0,0 +1,33 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
IGNORE_MANIFEST=1
#
DEPTH=..\..\..
MODULE=softupdt
EXPORTS=softupdt.h su_folderspec.h gdiff.h
#//------------------------------------------------------------------------
#//
#// Makefile to install MODULES/APPLET/INCLUDE header files into the distribution
#// directory.
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>

Просмотреть файл

@ -0,0 +1,54 @@
/* -*- 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 "structs.h"
/* Public */
typedef void (*SoftUpdateCompletionFunction) (int result, void * closure);
XP_BEGIN_PROTOS
/* Flags for start software update */
/* See trigger.java for docs */
#define FORCE_INSTALL 1
#define SILENT_INSTALL 2
/* StartSoftwareUpdate
* performs the update, and calls the callback function with the
*/
extern XP_Bool SU_StartSoftwareUpdate(MWContext * context,
const char * url,
const char * name,
SoftUpdateCompletionFunction f,
void * completionClosure,
int32 flags); /* FORCE_INSTALL, SILENT_INSTALL */
/* SU_NewStream
* Stream decoder for software updates
*/
NET_StreamClass * SU_NewStream (int format_out, void * registration,
URL_Struct * request, MWContext *context);
int PR_CALLBACK JavaGetBoolPref(char *pref_name);
int PR_CALLBACK IsJavaSecurityEnabled();
int PR_CALLBACK IsJavaSecurityDefaultTo30Enabled();
#define AUTOUPDATE_ENABLE_PREF "autoupdate.enabled"
#define CONTENT_ENCODING_HEADER "Content-encoding"
#define INSTALLER_HEADER "Install-Script"
XP_END_PROTOS

Просмотреть файл

@ -0,0 +1,89 @@
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Netscape Public License
* Version 1.0 (the "NPL"); you may not use this file except in
* compliance with the NPL. You may obtain a copy of the NPL at
* http://www.mozilla.org/NPL/
*
* Software distributed under the NPL is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
* for the specific language governing rights and limitations under the
* NPL.
*
* The Initial Developer of this code under the NPL is Netscape
* Communications Corporation. Portions created by Netscape are
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
* Reserved.
*/
/* su_folderspec.h
* public stuff for su_folderspec.c
*/
/* su_DirSpecID
* enums for different folder types
*/
#include "xp_mcom.h"
typedef enum su_DirSpecID {
/* Common folders */
eBadFolder,
ePluginFolder, /* where the plugins are */
eProgramFolder, /* Where the netscape program is */
ePackageFolder, /* Default application folder */
eTemporaryFolder, /* Temporary */
eCommunicatorFolder,/* Communicator */
eInstalledFolder, /* Already installed component */
eCurrentUserFolder, /* Navigator's current user */
eNetHelpFolder,
eOSDriveFolder,
eFileURLFolder,
/* Java folders */
eJavaBinFolder,
eJavaClassesFolder,
eJavaDownloadFolder,
/* Windows folders */
eWin_WindowsFolder,
eWin_SystemFolder,
eWin_System16Folder,
/* Macintosh folders */
eMac_SystemFolder,
eMac_DesktopFolder,
eMac_TrashFolder,
eMac_StartupFolder,
eMac_ShutdownFolder,
eMac_AppleMenuFolder,
eMac_ControlPanelFolder,
eMac_ExtensionFolder,
eMac_FontsFolder,
eMac_PreferencesFolder,
/* Unix folders */
eUnix_LocalFolder,
eUnix_LibFolder
} su_DirSpecID;
typedef enum su_SecurityLevel {
eOneFolderAccess,
eAllFolderAccess
} su_SecurityLevel;
XP_BEGIN_PROTOS
/* FE_GetDirectoryPath
* given a directory id, returns full path in native format
* and ends with the platform specific directory separator ('/',':','\\')
*/
char * FE_GetDirectoryPath( su_DirSpecID folderID );
int FE_ReplaceExistingFile(char *, XP_FileType, char *, XP_FileType, XP_Bool);
#ifdef WIN32
BOOL WFE_IsMoveFileExBroken();
#endif
XP_END_PROTOS

Просмотреть файл

@ -0,0 +1,16 @@
//
// Common defines for both debug & non-debug versions of the JavaRuntime
//
#define MOZILLA_CLIENT 1
#define MOCHAFILE 1
#define COMPILER 0
#define JAVA 1
#define MOCHA 1
#define EDITOR 1
#define LAYERS 1
#define VERSION_NUMBER "4_0b0"
#define ZIP_NAME "java"##VERSION_NUMBER
#include "NSCrossProductDefines.h"
#include "IDE_Options.h"

Просмотреть файл

@ -0,0 +1,8 @@
//
// Debug specific defines for the JavaRuntime
//
#define DEBUG 1
#define TRACING 1
#include "Client.Prefix.h"

Просмотреть файл

@ -0,0 +1,5 @@
//
// Non-debug specific defines for the JavaRuntime
//
#include "Client.Prefix.h"

Двоичные данные
modules/softupdt/macbuild/SoftUpdatePPC.prj Normal file

Двоичный файл не отображается.

Двоичные данные
modules/softupdt/macbuild/SoftUpdatePPCDebug.prj Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,5 @@
void SU_Initialize(void) {}
void VR_Initialize(void) {}
void JavaGetBoolPref(void) {}
void IsJavaSecurityDefaultTo30Enabled(void) {}
void IsJavaSecurityEnabled(void) {}

Двоичные данные
modules/softupdt/macbuild/SoftUpdateStubsPPC.mcp Normal file

Двоичный файл не отображается.

Просмотреть файл

@ -0,0 +1,31 @@
#!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=..\..
DIRS=classes src include
include <$(MOZ_SRC)\ns\config\rules.mak>
build_classes:
cd $(MOZ_SRC)\ns\modules\softupdt
$(NMAKE) -f makefile.win
cd $(MOZ_SRC)\ns\sun-java\classsrc
$(NMAKE) -f makefile.win java40.jar
cd $(MOZ_SRC)\ns\cmd\winfe\mkfiles32
$(NMAKE) -f mozilla.mak

Просмотреть файл

@ -0,0 +1,108 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../..
MODULE = softupdate
LIBRARY_NAME = softupdate
REQUIRES = softupdt js java net dbm nspr img util layer pref jar security applet lay style libreg
JRI_GEN = netscape.softupdate.FolderSpec \
netscape.softupdate.InstallObject \
netscape.softupdate.InstallFile \
netscape.softupdate.InstallPatch \
netscape.softupdate.InstallExecute \
netscape.softupdate.Registry \
netscape.softupdate.RegistryNode \
netscape.softupdate.RegistryException \
netscape.softupdate.RegKeyEnumerator \
netscape.softupdate.RegEntryEnumerator \
netscape.softupdate.SoftwareUpdate \
netscape.softupdate.SoftUpdateException \
netscape.softupdate.Strings \
netscape.softupdate.Trigger \
netscape.softupdate.VersionInfo \
netscape.softupdate.VersionRegistry \
netscape.softupdate.VerRegEnumerator \
$(NULL)
CSRCS = softupdt.c \
su_trigger.c \
su_folderspec.c \
su_instl.c \
su_nodl.c \
vr_java.c \
$(NULL)
ifneq ($(subst /,_,$(shell uname -s)),OS2)
CSRCS += su_unix.c
else
CSRCS += os2updt.c su_wjava.c
CPPSRCS += su_win.cpp
JRI_GEN += netscape.softupdate.WinReg netscape.softupdate.WinProfile netscape.softupdate.WinRegValue
endif
EXPORTS = ../include/softupdt.h \
$(JRI_GEN_DIR)/netscape_softupdate_InstallFile.h \
$(JRI_GEN_DIR)/netscape_softupdate_InstallObject.h \
$(JRI_GEN_DIR)/netscape_softupdate_SoftwareUpdate.h \
$(JRI_GEN_DIR)/netscape_softupdate_SoftUpdateException.h \
$(JRI_GEN_DIR)/netscape_softupdate_VersionInfo.h \
$(JRI_GEN_DIR)/netscape_softupdate_VersionRegistry.h \
$(JRI_GEN_DIR)/netscape_softupdate_VerRegEnumerator.h \
$(JRI_GEN_DIR)/netscape_softupdate_Registry.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegistryNode.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegistryException.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegKeyEnumerator.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegEntryEnumerator.h \
$(JRI_GEN_DIR)/netscape_softupdate_Strings.h \
$(JRI_GEN_DIR)/netscape_softupdate_Trigger.h \
$(JRI_GEN_DIR)/netscape_softupdate_FolderSpec.h \
$(NULL)
include $(DEPTH)/config/rules.mk
ifeq ($(OS_ARCH),OS2)
INCLUDES += -I$(DEPTH)/cmd/os2fe/nfc/include -I$(DEPTH)/cmd/os2fe
endif
$(OBJDIR)/su_folderspec.o: $(JRI_GEN_DIR)/netscape_softupdate_FolderSpec.c \
$(JRI_GEN_DIR)/netscape_softupdate_SoftwareUpdate.h
$(OBJDIR)/su_instl.o: $(JRI_GEN_DIR)/netscape_softupdate_InstallFile.c \
$(JRI_GEN_DIR)/netscape_softupdate_InstallObject.c \
$(JRI_GEN_DIR)/netscape_softupdate_InstallExecute.c \
$(JRI_GEN_DIR)/netscape_softupdate_InstallPatch.c \
$(JRI_GEN_DIR)/netscape_softupdate_SoftwareUpdate.h \
$(JRI_GEN_DIR)/netscape_softupdate_SoftUpdateException.h \
$(JRI_GEN_DIR)/netscape_softupdate_Strings.h
$(OBJDIR)/su_trigger.o: $(JRI_GEN_DIR)/netscape_softupdate_Trigger.c \
$(JRI_GEN_DIR)/netscape_softupdate_SoftUpdateException.c \
$(JRI_GEN_DIR)/netscape_softupdate_SoftwareUpdate.c \
$(JRI_GEN_DIR)/netscape_softupdate_Strings.c
$(OBJDIR)/vr_java.o: $(JRI_GEN_DIR)/netscape_softupdate_VersionInfo.h \
$(JRI_GEN_DIR)/netscape_softupdate_VersionRegistry.h \
$(JRI_GEN_DIR)/netscape_softupdate_VerRegEnumerator.h \
$(JRI_GEN_DIR)/netscape_softupdate_Registry.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegistryNode.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegistryException.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegKeyEnumerator.h \
$(JRI_GEN_DIR)/netscape_softupdate_RegEntryEnumerator.h

Просмотреть файл

@ -0,0 +1,205 @@
#!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.
#//------------------------------------------------------------------------
#//
#// Makefile to build
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH= ..\..\..
IGNORE_MANIFEST=1
!if "$(MOZ_BITS)" == "16"
DIRS= nsinit
!else
DIRS= nsdiff nspatch
!endif
!ifndef MAKE_OBJ_TYPE
MAKE_OBJ_TYPE=EXE
!endif
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
LIBNAME=softup$(MOZ_BITS)
PDBFILE=$(LIBNAME).pdb
#//------------------------------------------------------------------------
#//
#// Define the files necessary to build the target (ie. OBJS)
#//
#//------------------------------------------------------------------------
OBJS= \
.\$(OBJDIR)\softupdt.obj \
.\$(OBJDIR)\su_folderspec.obj \
.\$(OBJDIR)\su_instl.obj \
.\$(OBJDIR)\su_trigger.obj \
.\$(OBJDIR)\su_win.obj \
.\$(OBJDIR)\vr_java.obj \
!if "$(MOZ_BITS)" == "16"
.\$(OBJDIR)\su_nodl.obj \
!endif
.\$(OBJDIR)\su_wjava.obj \
$(NULL)
JRI_GEN= \
netscape.softupdate.FolderSpec \
netscape.softupdate.InstallObject \
netscape.softupdate.InstallFile \
netscape.softupdate.InstallPatch \
netscape.softupdate.InstallExecute \
netscape.softupdate.Registry \
netscape.softupdate.RegistryNode \
netscape.softupdate.RegistryException \
netscape.softupdate.RegKeyEnumerator \
netscape.softupdate.RegEntryEnumerator \
netscape.softupdate.SoftwareUpdate \
netscape.softupdate.SoftUpdateException \
netscape.softupdate.Strings \
netscape.softupdate.Trigger \
netscape.softupdate.VersionInfo \
netscape.softupdate.VersionRegistry \
netscape.softupdate.VerRegEnumerator \
netscape.softupdate.WinProfile \
netscape.softupdate.WinReg \
netscape.softupdate.WinRegValue \
$(NULL)
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
LIBRARY= .\$(OBJDIR)\$(LIBNAME).lib
#//------------------------------------------------------------------------
#//
#// Define any local options for the make tools
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
#//
#//------------------------------------------------------------------------
LINCS= $(LINCS) -I_jri \
-I../include \
-I$(DEPTH)/lib/libnet \
-I$(DEPTH)/lib/layout \
-I$(DEPTH)/lib/libjar \
-I$(DEPTH)/lib/libstyle \
-I$(DEPTH)/cmd/winfe \
$(NULL)
#//
#// For Win16 the following directories have been collapsed into
#// ns/dist/public/win16 to conserve command-line argument space...
#//
!if "$(MOZ_BITS)" == "32"
LINCS= $(LINCS) \
-I$(PUBLIC)/softupdt \
-I$(PUBLIC)/libreg \
-I$(PUBLIC)/applet \
-I$(PUBLIC)/java \
-I$(PUBLIC)/nspr \
-I$(PUBLIC)/js \
-I$(PUBLIC)/dbm \
-I$(PUBLIC)/security \
-I$(PUBLIC)/pref/ \
-I$(PUBLIC)/libfont/ \
-I$(PUBLIC)/jtools/ \
-I$(PUBLIC)/winfont/ \
-I$(PUBLIC)/rdf \
-I$(PUBLIC)/java \
-I$(PUBLIC)/applet \
-I$(PUBLIC)/rdf \
$(NULL)
!endif
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>
CFLAGS=$(CFLAGS) -DMOZILLA_CLIENT
!if "$(MOZ_BITS)" == "32"
PUBLIC_HEADER_DIR=$(PUBLIC)\softupdt
!else
PUBLIC_HEADER_DIR=$(PUBLIC)\win16
!endif
export::
$(MAKE_INSTALL) _jri\netscape_softupdate_InstallObject.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_SoftwareUpdate.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_SoftUpdateException.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_Strings.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_VersionInfo.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_Trigger.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_FolderSpec.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_VersionRegistry.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_VerRegEnumerator.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_WinProfile.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_WinReg.h $(PUBLIC_HEADER_DIR)
$(MAKE_INSTALL) _jri\netscape_softupdate_WinRegValue.h $(PUBLIC_HEADER_DIR)
install:: $(LIBRARY)
$(MAKE_INSTALL) $(LIBRARY) $(DIST)\lib
clobber::
$(RM_R) _jri
.\$(OBJDIR)\su_folderspec.obj: \
$(JRI_GEN_DIR)\netscape_softupdate_FolderSpec.c \
$(JRI_GEN_DIR)/netscape_softupdate_SoftwareUpdate.h \
.\$(OBJDIR)\su_instl.obj: \
$(JRI_GEN_DIR)\netscape_softupdate_InstallFile.c \
$(JRI_GEN_DIR)\netscape_softupdate_InstallExecute.c \
$(JRI_GEN_DIR)\netscape_softupdate_InstallObject.c \
$(JRI_GEN_DIR)\netscape_softupdate_InstallPatch.c \
$(JRI_GEN_DIR)/netscape_softupdate_SoftwareUpdate.h \
$(JRI_GEN_DIR)/netscape_softupdate_SoftUpdateException.h \
$(JRI_GEN_DIR)\netscape_softupdate_Strings.h
.\$(OBJDIR)\su_trigger.obj: \
$(JRI_GEN_DIR)\netscape_softupdate_Trigger.c \
$(JRI_GEN_DIR)\netscape_softupdate_SoftUpdateException.c \
$(JRI_GEN_DIR)\netscape_softupdate_SoftwareUpdate.c \
$(JRI_GEN_DIR)\netscape_softupdate_Strings.c
.\$(OBJDIR)\su_wjava.obj: \
$(JRI_GEN_DIR)\netscape_softupdate_WinProfile.c \
$(JRI_GEN_DIR)\netscape_softupdate_WinReg.c \
$(JRI_GEN_DIR)\netscape_softupdate_WinRegValue.c

Просмотреть файл

@ -0,0 +1,33 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
REQUIRES = softupdt
CSRCS = nsdiff.c
PROGRAM = nsdiff$(BIN_SUFFIX)
include $(DEPTH)/config/rules.mk
symbols:
@echo "CSRCS = $(CSRCS)"
@echo "OBJS = $(OBJS)"
@echo "PROGRAM = $(PROGRAM)"
@echo "LIBRARY = $(LIBRARY)"
@echo "TARGETS = $(TARGETS)"

Просмотреть файл

@ -0,0 +1,66 @@
#!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.
IGNORE_MANIFEST=1
#
#VERBOSE = 1
DEPTH=..\..\..\..
#cannot define PROGRAM in manifest compatibly with NT and UNIX
PROGRAM= .\$(OBJDIR)\nsdiff.exe
include <$(DEPTH)\config\config.mak>
# let manifest generate C_OBJS, it will prepend ./$(OBJDIR)/
# rules.mak will append C_OBJS onto OBJS.
# OBJS = $(CSRCS:.c=.obj)
PDBFILE = nsdiff.pdb
MAPFILE = nsdiff.map
REQUIRES=softupdt
CSRCS=nsdiff.c
C_OBJS=.\$(OBJDIR)\nsdiff.obj
!if "$(MOZ_BITS)" != "16"
LINCS=-I$(XPDIST)\public\softupdt
!endif
include <$(DEPTH)\config\rules.mak>
INSTALL = $(MAKE_INSTALL)
objs: $(OBJS)
programs: $(PROGRAM)
install:: $(TARGETS)
$(INSTALL) $(TARGETS) $(DIST)/bin
symbols:
@echo "CSRCS = $(CSRCS)"
@echo "INCS = $(INCS)"
@echo "OBJS = $(OBJS)"
@echo "LIBRARY = $(LIBRARY)"
@echo "PROGRAM = $(PROGRAM)"
@echo "TARGETS = $(TARGETS)"
@echo "DIST = $(DIST)"
@echo "VERSION_NUMBER = $(VERSION_NUMBER)"
@echo "WINFE = $(WINFE)"
@echo "DBM_LIB = $(DBM_LIB)"
@echo "INSTALL = $(INSTALL)"

Просмотреть файл

@ -0,0 +1,952 @@
/* -*- 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.
*/
/*--------------------------------------------------------------------
* NSDiff
*
* A binary file diffing utility that creates diffs in GDIFF format
*
* nsdiff [-b"blocksize"] [-o"outfile"] oldfile newfile
*
* Blocksize defaults to 32.
* The outfile defaults to "newfile" with a .GDF extension
*
*------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include "gdiff.h"
/*--------------------------------------
* constants
*------------------------------------*/
#define IGNORE_SIZE 7
#define DEFAULT_BLOCKSIZE 32
#define FILENAMESIZE 513
#define OLDBUFSIZE 0x1FFF
#define MAXBUFSIZE 0xFFFF /* more requires long adds, wasting space */
#define CHKMOD 65536
#define HTBLSIZE 65521
#define destroyFdata(fd) { if ((fd)->data != NULL) free((fd)->data); }
/*--------------------------------------
* types
*------------------------------------*/
typedef unsigned long uint32;
typedef long int32;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned char uchar;
typedef unsigned char BOOL;
typedef struct hnode {
uint32 chksum; /* true checksum of the block */
uint32 offset; /* offset into old file */
struct hnode *next; /* next node in collision list */
} HNODE, *HPTR;
typedef struct filedata {
uint32 filepos; /* fileposition of start of buffer */
int32 offset; /* current position in the buffer */
int32 unwritten; /* the start of the unwritten buffer */
uint32 datalen; /* actual amount of data in buffer */
uint32 bufsize; /* the physical size of the memory buffer */
uchar * data; /* a "bufsize" memory block for data */
FILE * file; /* file handle */
BOOL bDoAdds; /* If true check for "add" data before reading */
} FILEDATA;
/*--------------------------------------
* prototypes
*------------------------------------*/
void add( uchar *data, uint32 count, FILE *outf );
void adddata( FILEDATA *fd );
void copy( uint32 offset, uint32 count, FILE *outf );
uint32 checksum( uchar *buffer, uint32 offset, uint32 count );
HPTR *chunkOldFile( FILE *fh, uint32 blocksize );
void cleanup( void );
uint32 compareFdata( FILEDATA *oldfd, uint32 oldpos, FILEDATA *newfd );
void diff( FILE *oldf, FILE *newf, FILE *outf );
uint32 getChecksum( FILEDATA *fd );
BOOL getFdata( FILEDATA *fdata, uint32 position );
BOOL initFdata( FILEDATA *fdata, FILE *file, uint32 bufsize, BOOL bDoAdds );
BOOL moreFdata( FILEDATA *fdata );
int openFiles( void );
void readFdata( FILEDATA *fdata, uint32 position );
void usage( void );
BOOL validateArgs( int argc, char *argv[] );
void writeHeader( FILE *outf );
/*--------------------------------------
* Global data
*------------------------------------*/
char *oldname = NULL,
*newname = NULL,
*outname = NULL;
FILE *oldfile,
*newfile,
*outfile;
uint32 blocksize = DEFAULT_BLOCKSIZE;
HPTR *htbl;
/* for hashing stats */
uint32 slotsused = 0,
blockshashed = 0,
blocksfound = 0,
hashhits = 0,
partialmatch = 0,
cmpfailed = 0;
/*--------------------------------------
* main
*------------------------------------*/
int main( int argc, char *argv[] )
{
int err;
/* Parse command line */
if ( !validateArgs( argc, argv ) ) {
err = ERR_ARGS;
}
else {
err = openFiles();
}
/* Calculate block checksums in old file */
if ( err == ERR_OK ) {
htbl = chunkOldFile( oldfile, blocksize );
if ( htbl == NULL )
err = ERR_MEM;
}
/* Do the diff */
if ( err == ERR_OK ) {
writeHeader( outfile );
diff( oldfile, newfile, outfile );
}
/* Cleanup */
cleanup();
/* Report status */
if ( err == ERR_OK ) {
fprintf( stderr, "\nHashed %ld blocks into %ld slots (out of %ld)\n",
blockshashed, slotsused, HTBLSIZE );
fprintf( stderr, "Blocks found: %ld\n", blocksfound );
fprintf( stderr, "Hashtable hits: %ld\n", hashhits );
fprintf( stderr, "memcmps failed: %ld\n", cmpfailed );
fprintf( stderr, "partial matches: %ld\n", partialmatch );
}
else {
switch (err) {
case ERR_ARGS:
fprintf( stderr, "Invalid arguments\n" );
usage();
break;
case ERR_ACCESS:
fprintf( stderr, "Error opening file\n" );
break;
case ERR_MEM:
fprintf( stderr, "Insufficient memory\n" );
break;
default:
fprintf( stderr, "Unknown error %d\n", err );
break;
}
}
return (err);
}
/*--------------------------------------
* add
*------------------------------------*/
void add( uchar *data, uint32 count, FILE *outf )
{
uchar numbuf[5];
#ifdef DEBUG
fprintf( stderr, "Adding %ld bytes\n", count );
#endif
if ( count == 0 )
return;
if ( count <= ADD8MAX ) {
numbuf[0] = (uchar)count;
fwrite( numbuf, 1, 1, outf );
}
else if ( count <= 0xFFFF ) {
numbuf[0] = ADD16;
numbuf[1] = (uchar)( count >> 8 );
numbuf[2] = (uchar)( count & 0x00FF );
fwrite( numbuf, 1, 3, outf );
}
else {
numbuf[0] = ADD32;
numbuf[1] = (uchar)( count >> 24 );
numbuf[2] = (uchar)( ( count >> 16 ) & 0x00FF );
numbuf[3] = (uchar)( ( count >> 8 ) & 0x00FF );
numbuf[4] = (uchar)( count & 0x00FF );
fwrite( numbuf, 1, 5, outf );
}
fwrite( data, 1, count, outf );
}
/*--------------------------------------
* copy
*------------------------------------*/
void copy( uint32 offset, uint32 count, FILE *outf )
{
uchar numbuf[9];
#ifdef DEBUG
fprintf( stderr, "Copying %ld bytes from offset %ld\n", count, offset );
#endif
if ( count == 0 )
return;
if ( offset <= 0xFFFF ) {
numbuf[1] = (uchar)( offset >> 8 );
numbuf[2] = (uchar)( offset & 0x00FF );
if ( count <= 0xFF ) {
numbuf[0] = COPY16BYTE;
numbuf[3] = (uchar)( count & 0xFF );
fwrite( numbuf, 1, 4, outf );
}
else if ( count <= 0xFFFF ) {
numbuf[0] = COPY16SHORT;
numbuf[3] = (uchar)( count >> 8 );
numbuf[4] = (uchar)( count & 0x00FF );
fwrite( numbuf, 1, 5, outf );
}
else {
numbuf[0] = COPY16LONG;
numbuf[3] = (uchar)( count >> 24 );
numbuf[4] = (uchar)( ( count >> 16 ) & 0x00FF );
numbuf[5] = (uchar)( ( count >> 8 ) & 0x00FF );
numbuf[6] = (uchar)( count & 0x00FF );
fwrite( numbuf, 1, 7, outf );
}
}
else {
numbuf[1] = (uchar)( offset >> 24 );
numbuf[2] = (uchar)( ( offset >> 16 ) & 0x00FF );
numbuf[3] = (uchar)( ( offset >> 8 ) & 0x00FF );
numbuf[4] = (uchar)( offset & 0x00FF );
if ( count <= 0xFF ) {
numbuf[0] = COPY32BYTE;
numbuf[5] = (uchar)( count & 0xFF );
fwrite( numbuf, 1, 6, outf );
}
else if ( count <= 0xFFFF ) {
numbuf[0] = COPY32SHORT;
numbuf[5] = (uchar)( count >> 8 );
numbuf[6] = (uchar)( count & 0x00FF );
fwrite( numbuf, 1, 7, outf );
}
else {
numbuf[0] = COPY32LONG;
numbuf[5] = (uchar)( count >> 24 );
numbuf[6] = (uchar)( ( count >> 16 ) & 0x00FF );
numbuf[7] = (uchar)( ( count >> 8 ) & 0x00FF );
numbuf[8] = (uchar)( count & 0x00FF );
fwrite( numbuf, 1, 9, outf );
}
}
}
/*--------------------------------------
* checksum
*------------------------------------*/
uint32 checksum( uchar *buffer, uint32 offset, uint32 count )
{
uint32 i,
s1 = 0,
s2 = 0;
for ( i=0; i < count; i++ ) {
s1 = ( s1 + buffer[ offset+i ] ) % CHKMOD ;
s2 = ( s2 + s1 ) % CHKMOD ;
}
return ( (s2 << 16) + s1 );
}
/*--------------------------------------
* chunkOldFile
*------------------------------------*/
HPTR *chunkOldFile( FILE *fh, uint32 blocksize )
{
HPTR *table;
HPTR node;
HPTR tmp;
uchar *buffer;
uint32 filepos;
uint32 bufsize;
uint32 bytesRead;
uint32 chksum;
uint32 hash;
uint32 i;
bufsize = ( MAXBUFSIZE / blocksize ) * blocksize ;
#ifdef DEBUG
fprintf( stderr, "bufsize: %ld, tblsize: %ld\n", bufsize, HTBLSIZE*sizeof(HPTR) );
#endif
table = (HPTR*)malloc( HTBLSIZE * sizeof(HPTR) );
buffer = (uchar*)malloc( bufsize );
if ( table == NULL || buffer == NULL) {
fprintf( stderr, "Out of memory\n" );
if ( table != NULL )
free( table );
}
else {
memset( table, 0, HTBLSIZE * sizeof(HPTR) );
filepos = 0;
do {
bytesRead = fread( buffer, 1, bufsize, fh );
#ifdef DEBUG
fprintf( stderr, "read %ld bytes\n", bytesRead );
#endif
i = 0;
while ( i < bytesRead ) {
blockshashed++;
node = (HPTR)malloc( sizeof(HNODE) );
if ( node != NULL ) {
if ( blocksize <= bytesRead-i )
chksum = checksum( buffer, i, blocksize );
else
chksum = checksum( buffer, i, bytesRead-i );
hash = chksum % HTBLSIZE;
node->chksum = chksum;
node->offset = filepos + i;
node->next = NULL;
tmp = table[hash];
if (tmp == NULL) {
slotsused++;
table[hash] = node;
}
else {
#ifdef FRONTHASH
node->next = tmp;
table[hash] = node;
#else
while (tmp->next != NULL)
tmp = tmp->next;
tmp->next = node;
#endif
}
}
else {
fprintf( stderr, "Out of memory\n" );
}
i += blocksize;
}
filepos += bytesRead;
} while ( bytesRead > 0 );
}
/* reset file to beginning for comparison */
fseek( fh, 0, SEEK_SET );
if ( buffer != NULL )
free(buffer);
return (table);
}
/*--------------------------------------
* cleanup
*------------------------------------*/
void cleanup()
{
long i;
HPTR tmp;
if ( oldfile != NULL )
fclose( oldfile );
if ( newfile != NULL )
fclose( newfile );
if ( outfile != NULL )
fclose( outfile );
if ( htbl != NULL ) {
for ( i=HTBLSIZE-1; i >= 0; i-- ) {
while ( htbl[i] != NULL ) {
tmp = htbl[i]->next;
free( htbl[i] );
htbl[i] = tmp;
}
}
free( htbl );
}
}
#ifndef OLDDIFF
/*--------------------------------------
* diff
*------------------------------------*/
void diff( FILE *oldf, FILE *newf, FILE *outf )
{
FILEDATA oldfd,
newfd;
uint32 rChk,
match,
tmpfilepos,
tmpoffset,
hash;
HPTR node;
if ( !initFdata( &oldfd, oldf, OLDBUFSIZE, FALSE ) ||
!initFdata( &newfd, newf, MAXBUFSIZE, TRUE ) )
{
fprintf( stderr, "Out of memory!\n" );
goto bail;
}
outerloop:
while ( moreFdata( &newfd ) ) {
rChk = getChecksum( &newfd );
hash = rChk % HTBLSIZE;
node = htbl[hash];
while( node != NULL ) {
hashhits++;
/* compare checksums to see if this might be a match */
if ( rChk == node->chksum ) {
/* might be a match, compare actual bits */
tmpfilepos = newfd.filepos;
tmpoffset = newfd.offset;
match = compareFdata( &oldfd, node->offset, &newfd );
if ( match > IGNORE_SIZE ) {
blocksfound++;
if ( match < blocksize )
partialmatch++;
/* add any unmatched bytes from new file */
if ( newfd.offset > newfd.unwritten )
adddata( &newfd );
/* copy the matched block from old file */
copy( node->offset, match, outf );
/* skip the copied bytes */
newfd.offset = tmpfilepos+tmpoffset + match - newfd.filepos;
newfd.unwritten = newfd.offset;
/* don't increment offset in loop, this is the new start */
goto outerloop; /* "continue outerloop" */
}
else {
/* match failed */
cmpfailed++;
node = node->next;
if ( tmpfilepos != newfd.filepos ) {
/* file buffer was moved during failed compare */
readFdata( &newfd, tmpfilepos+tmpoffset );
}
}
}
else {
/* can't be a match */
node = node->next;
}
} /* while (node!=NULL) */
/* examine next byte */
newfd.offset++;
} /* while( modeFdata() ) */
/* check for final unmatched data */
if ( newfd.offset > newfd.unwritten ) {
assert( 0 ); /* this should be taken care of in moreFdata now */
adddata( &newfd );
}
/* Terminate the GDIFF file */
fwrite( GDIFF_EOF, 1, 1, outf );
bail:
destroyFdata( &oldfd );
destroyFdata( &newfd );
}
BOOL initFdata( FILEDATA *fdata, FILE *file, uint32 bufsize, BOOL bDoAdds )
{
fdata->filepos = 0;
fdata->offset = 0;
fdata->unwritten= 0;
fdata->datalen = 0;
fdata->data = (uchar*)malloc(bufsize);
fdata->bufsize = bufsize;
fdata->file = file;
fdata->bDoAdds = bDoAdds;
if ( fdata->data == NULL )
return (FALSE);
readFdata( fdata, 0 );
return (TRUE);
}
BOOL moreFdata( FILEDATA *fd )
{
if ( fd->offset < fd->datalen ) {
/* pointer still in buffer */
return (TRUE);
}
else {
readFdata( fd, (fd->filepos + fd->offset) );
if (fd->offset >= fd->datalen) {
/* no more data */
return (FALSE);
}
else
return (TRUE);
}
}
BOOL getFdata( FILEDATA *fd, uint32 position )
{
if ( (position >= fd->filepos) && (position < (fd->filepos+fd->datalen)) ) {
/* the position is available in the current buffer */
return (TRUE);
}
else {
/* try to get the position into the buffer */
readFdata( fd, position );
}
if ( position >= (fd->filepos + fd->datalen) ) {
/* position still not in buffer: not enough data */
return (FALSE);
}
return (TRUE);
}
void readFdata( FILEDATA *fd, uint32 position )
{
if ( fd->bDoAdds && (fd->offset > fd->unwritten) ) {
add( fd->data + fd->unwritten, fd->offset - fd->unwritten, outfile );
}
if ( position != (fd->filepos + fd->datalen) ) {
/* it's not just the next read so we must seek to it */
fseek( fd->file, position, SEEK_SET );
/* assert that in newfile we move byte by byte */
assert( !fd->bDoAdds || position == fd->filepos+fd->offset );
}
fd->datalen = fread( fd->data, 1, fd->bufsize, fd->file );
fd->filepos = position;
fd->offset = 0;
fd->unwritten = 0;
#ifdef DEBUG
fprintf(stderr,"Read %ld %s bytes\n",fd->datalen, fd->bDoAdds?"NEW":"old");
#endif
}
void adddata( FILEDATA *fd )
{
uint32 chunksize;
assert( fd->offset <= fd->datalen ); /* must be in the buffer */
chunksize = fd->offset - fd->unwritten;
if ( chunksize > 0 ) {
add( fd->data + fd->unwritten, chunksize, outfile );
fd->unwritten = fd->offset;
}
}
uint32 compareFdata( FILEDATA *oldfd, uint32 oldpos, FILEDATA *newfd )
{
int32 oldoffset, newoffset;
uint32 count = 0;
if ( getFdata( oldfd, oldpos ) && (newfd->offset < newfd->datalen) ) {
oldoffset = oldpos - oldfd->filepos;
newoffset = newfd->offset;
while ( *(oldfd->data + oldoffset) == *(newfd->data + newoffset) ) {
oldoffset++;
newoffset++;
count++;
if ( oldoffset >= oldfd->datalen ) {
readFdata( oldfd, oldfd->filepos + oldoffset );
oldoffset = 0;
if ( oldfd->datalen == 0 ) {
/* out of data */
break;
}
}
if ( newoffset >= newfd->datalen ) {
if ( newfd->datalen != newfd->bufsize ) {
/* we're at EOF, don't read more */
break;
}
else {
readFdata( newfd, newfd->filepos + newoffset );
newoffset = 0;
if ( newfd->datalen == 0 ) {
/* Hm, at EOF after all */
break;
}
}
}
}
}
return count;
}
uint32 getChecksum( FILEDATA *fd )
{
/* XXX Need to implement a rolling checksum */
uint32 remaining;
assert( fd->offset < fd->datalen ); /* must be in buffer */
remaining = fd->datalen - fd->offset;
if ( remaining >= blocksize ) {
/* plenty of room to calculate */
return checksum( fd->data, fd->offset, blocksize );
}
else {
/* fewer than 'blocksize' bytes remain in buffer */
if ( fd->datalen == fd->bufsize ) {
/* there should be more file to read */
readFdata( fd, fd->filepos + fd->offset );
remaining = fd->datalen;
}
if ( remaining < blocksize )
return checksum( fd->data, fd->offset, remaining );
else
return checksum( fd->data, fd->offset, blocksize );
}
}
#else /* !NEWDIFF, i.e. old buggy diff */
/*--------------------------------------
* diff
*------------------------------------*/
void diff( FILE *oldf, FILE *newf, FILE *outf )
{
uchar *olddata,
*newdata;
uint32 rChk,
i,
unwritten,
hash,
maxShifts,
oldbytes,
bytesRead;
HPTR node;
olddata = (uchar*)malloc(blocksize);
newdata = (uchar*)malloc(MAXBUFSIZE);
if (olddata == NULL || newdata == NULL ) {
fprintf( stderr, "Out of memory!\n" );
goto bail;
}
do {
bytesRead = fread( newdata, 1, MAXBUFSIZE, newf );
if ( bytesRead >= blocksize )
maxShifts = (bytesRead - blocksize + 1);
else
maxShifts = 0;
#ifdef DEBUG
fprintf( stderr, "read %ld new bytes\n", bytesRead );
#endif
unwritten = 0;
for ( i=0; i < maxShifts ; i++ ) {
/* wastefully slow, convert to rolling checksum */
rChk = checksum( newdata, i, blocksize );
hash = rChk % HTBLSIZE;
node = htbl[hash];
while( node != NULL ) {
hashhits++;
/* compare checksums to see if this might really be a match */
if ( rChk != node->chksum ) {
/* can't be a match */
node = node->next;
}
else {
/* might be a match, compare actual bits */
fseek( oldf, node->offset, SEEK_SET );
oldbytes = fread( olddata, 1, blocksize, oldf );
if ( memcmp( olddata, newdata+i, oldbytes ) != 0 ) {
cmpfailed++;
node = node->next;
}
else {
blocksfound++;
/* add any unmatched bytes from new file */
if ( i > unwritten )
add( newdata+unwritten, i-unwritten, outf );
/* copy the matched block from old file */
copy( node->offset, oldbytes, outf );
/* skip the copied bytes */
unwritten = (i + oldbytes);
/* "i" gets one less, the "for" increments it */
i = unwritten - 1;
/* done with this hash entry */
node = NULL;
}
}
}
}
/* prepare to read another block */
if ( unwritten < i ) {
/* add the unmatched data */
add( newdata+unwritten, i-unwritten, outf );
}
#if 0
if ( i < bytesRead ) {
/* shift filepointer back so uncompared data isn't missed */
fseek( newf, (i - bytesRead), SEEK_CUR );
}
#endif
} while ( bytesRead > 0 );
/* Terminate the GDIFF file */
fwrite( GDIFF_EOF, 1, 1, outf );
bail:
if ( olddata != NULL )
free( olddata );
if (newdata != NULL )
free( newdata );
}
#endif /* NEWDIFF */
/*--------------------------------------
* openFiles
*------------------------------------*/
int openFiles()
{
char namebuf[FILENAMESIZE];
oldfile = fopen( oldname, "rb" );
if ( oldfile == NULL ) {
fprintf( stderr, "Can't open %s for reading\n", oldname );
return ERR_ACCESS;
}
newfile = fopen( newname, "rb" );
if ( newfile == NULL ) {
fprintf( stderr, "Can't open %s for reading\n", newname );
return ERR_ACCESS;
}
if ( outname == NULL || *outname == '\0' ) {
strcpy( namebuf, newname );
strcat( namebuf, ".gdf" );
outname = namebuf;
}
outfile = fopen( outname, "wb" );
if ( outfile == NULL ) {
fprintf( stderr, "Can't open %s for writing\n", outname );
return ERR_ACCESS;
}
return ERR_OK;
}
/*--------------------------------------
* usage
*------------------------------------*/
void usage ()
{
fprintf( stderr, "\n NSDiff [-b#] [-o\"outfile\"] oldfile newfile\n\n" );
fprintf( stderr, " -b size of blocks to compare in bytes, " \
"default %d\n", DEFAULT_BLOCKSIZE );
fprintf( stderr, " -o name of output diff file\n\n" );
}
/*--------------------------------------
* validateArgs
*------------------------------------*/
BOOL validateArgs( int argc, char *argv[] )
{
int i;
for ( i = 1; i < argc; i++ ) {
if ( *argv[i] == '-' ) {
switch (*(argv[i]+1)) {
case 'b':
blocksize = atoi( argv[i]+2 );
break;
case 'o':
outname = argv[i]+2;
break;
default:
fprintf( stderr, "Unknown option %s\n", argv[i] );
return (FALSE);
}
}
else if ( oldname == NULL ) {
oldname = argv[i];
}
else if ( newname == NULL ) {
newname = argv[i];
}
else {
fprintf( stderr, "Too many arguments\n" );
return (FALSE);
}
}
#ifdef DEBUG
fprintf( stderr, "Blocksize: %d\n", blocksize );
fprintf( stderr, "Old file: %s\n", oldname );
fprintf( stderr, "New file: %s\n", newname );
fprintf( stderr, "diff file: %s\n", outname );
#endif
/* validate arguments */
if ( blocksize <= IGNORE_SIZE || blocksize > MAXBUFSIZE ) {
fprintf( stderr, "Invalid blocksize: %d\n", blocksize );
return (FALSE);
}
if ( oldname == NULL || newname == NULL ) {
fprintf( stderr, "Old and new file name parameters are required.\n" );
return (FALSE);
}
return (TRUE);
}
/*--------------------------------------
* writeHeader
*------------------------------------*/
void writeHeader( FILE *outf )
{
fwrite( "\xd1\xff\xd1\xff\05\0\0\0\0\0\0", 1, 11, outf );
}

Просмотреть файл

@ -0,0 +1,86 @@
#!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.
IGNORE_MANIFEST=1
#//------------------------------------------------------------------------
#//
#// Makefile to build
#//
#//------------------------------------------------------------------------
#//------------------------------------------------------------------------
#//
#// Specify the depth of the current directory relative to the
#// root of NS
#//
#//------------------------------------------------------------------------
DEPTH= ..\..\..\..
!if "$(MOZ_BITS)" == "32"
!ERROR NSINIT is Win16 only
!endif
!ifndef MAKE_OBJ_TYPE
MAKE_OBJ_TYPE=EXE
!endif
#//------------------------------------------------------------------------
#//
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
#//
#//------------------------------------------------------------------------
EXENAME= nsinit
MAPFILE= $(EXENAME).map
#//------------------------------------------------------------------------
#//
#// Define the files necessary to build the target (ie. OBJS)
#//
#//------------------------------------------------------------------------
OBJS= \
.\$(OBJDIR)\nsinit.obj \
$(NULL)
#//------------------------------------------------------------------------
#//
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
#// (these must be defined before the common makefiles are included)
#//
#//------------------------------------------------------------------------
PROGRAM= .\$(OBJDIR)\$(EXENAME).exe
#//------------------------------------------------------------------------
#//
#// Define any local options for the make tools
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
#//
#//------------------------------------------------------------------------
#LINCS= $(LINCS) \
# $(NULL)
#//------------------------------------------------------------------------
#//
#// Include the common makefile rules
#//
#//------------------------------------------------------------------------
include <$(DEPTH)/config/rules.mak>
install:: $(PROGRAM)
$(MAKE_INSTALL) $(PROGRAM) $(DIST)\bin

Просмотреть файл

@ -0,0 +1,249 @@
/* -*- 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 <stdio.h>
#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <malloc.h>
#include <windows.h>
#define BSIZE 16384
#define KSIZE 1024
#define COPYSIZE 32000
#define OK 1
#define ERROR 0
#ifdef DEBUG_dveditz
#define DBG(msg) MessageBox((HWND)NULL, (msg), "NS-Init Debug message", 0);
#else
#define DBG(msg) ((void)0)
#endif
//--- Macros for readability ---
#define SECTION "Rename"
#define INIFILE "WININIT.INI"
#define GetRenameString(key, buf, bufsize) \
GetPrivateProfileString( SECTION, (key), "", (buf), (bufsize), INIFILE)
#define DeleteRenameString(key) \
WritePrivateProfileString( SECTION, (key), NULL, INIFILE )
// returns buf filled with null separated list of key names
// terminated by a double null.
#define GetRenameKeys(buf, bufsize) \
GetRenameString( NULL, (buf), (bufsize) )
//--- prototypes ---
int FileReplace( LPCSTR src, LPCSTR dest );
int RenameFile( LPCSTR src, LPCSTR dest );
char *copybuf;
int PASCAL WinMain(HINSTANCE hinst, HINSTANCE hPrevInst,
LPSTR lpCmdLine, int nCmdShow)
{
char *Buff;
char *Src;
Buff = (char*)malloc(BSIZE);
Src = (char*)malloc(KSIZE);
copybuf = (char*)malloc(COPYSIZE);
if ( Buff == NULL || Src == NULL || copybuf == NULL )
return -1;
// extract all the keys
if ( GetRenameKeys( Buff, BSIZE) ) {
char *pDest = Buff;
// for each key do the specified file swap
while ( *pDest ) {
if ( GetRenameString( pDest, Src, KSIZE) ) {
if ( FileReplace( Src, pDest) ) {
DeleteRenameString( pDest );
}
}
// get the next key
pDest += strlen(pDest)+1;
}
}
// if there are no more keys left in the WININIT.INI [Rename] section then
// take the utility out of the WIN.INI run list. We re-check the INI file
// (rather than set a flag) because buff may not have been big enough.
if ( 0 == GetRenameKeys( Buff, BSIZE ) ) {
DBG("[Rename] section empty");
if ( GetProfileString( "Windows", "Run", "", Buff, BSIZE ) ) {
int namelen, taillen;
char *pName, *pTail;
DBG(Buff);
namelen = GetModuleFileName( hinst, Src, KSIZE );
strupr(Src);
strupr(Buff);
pName = strstr( Buff, Src );
if ( pName != NULL ) {
if ( *(pName+namelen) == '\0' ) {
// there are no trailing commands: chop off the end
while( pName > Buff && *pName != ',' ) {
pName--;
}
*pName = '\0';
}
else {
pTail = pName+namelen;
while( *pTail && *pTail == ' ' )
pTail++;
if ( *pTail == ',' )
pTail++;
taillen = strlen(pTail)+1; // copy '\0' too
memmove( pName, pTail, taillen );
}
DBG(Buff);
WriteProfileString( "Windows", "Run", Buff );
}
}
}
free(Buff);
free(Src);
free(copybuf);
return 0;
}
int FileReplace ( LPCSTR Src, LPCSTR Dest )
{
char buf[KSIZE];
struct stat st;
int status;
#ifdef DEBUG_dveditz
sprintf (buf,"Renaming %s to %s\n", Src, Dest);
DBG(buf);
#endif
if ( stat( Src, &st ) != 0 ) {
DBG("Missing sourcefile");
// Srcfile is missing, nothing to do
return OK;
}
if ( stricmp( Dest, "NUL" ) == 0 ) {
// special case: delete Srcfile
// (part of MS spec for WININIT.INI -- ASD won't generate these)
DBG("Special delete case");
return ( 0 == unlink( Src ) );
}
if ( stat( Dest, &st ) != 0 ) {
DBG("Dest doesn't exist");
// Dest doesn't exist
status = RenameFile( Src, Dest );
}
else {
if ( NULL == tmpnam(buf) || !RenameFile( Dest, buf ) ) {
DBG("tmpfile error");
status = ERROR;
}
else {
status = RenameFile( Src, Dest );
if ( status == OK ) {
DBG("rename success");
unlink(buf);
}
else {
// put old file back
DBG("rename failure");
RenameFile( buf, Dest );
}
}
}
return status;
}
int RenameFile ( LPCSTR in, LPCSTR out)
{
FILE *ifp, *ofp;
int rbytes, wbytes;
int status = OK;
if (!in || !out)
return ERROR;
// try a rename first
if ( 0 == rename( in, out ) )
return OK;
else if ( errno != EXDEV )
return ERROR;
// can't rename across drives so do ugly copy
DBG("trying copy");
ifp = fopen (in, "rb");
if (ifp == NULL) {
return ERROR;
}
ofp = fopen (out, "wb");
if (ofp == NULL) {
fclose (ifp);
return ERROR;
}
while ((rbytes = fread (copybuf, 1, COPYSIZE, ifp)) > 0) {
if ((rbytes < COPYSIZE) && (ferror(ifp) != 0)) {
DBG("Read error");
status = ERROR;
break;
}
if ( (wbytes = fwrite (copybuf, 1, rbytes, ofp)) < rbytes ) {
DBG("Write error");
status = ERROR;
break;
}
}
fclose (ofp);
fclose (ifp);
if ( status == ERROR )
unlink(out);
else
unlink(in);
return status;
}

Просмотреть файл

@ -0,0 +1,33 @@
#!gmake
#
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL. You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation. Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
# Reserved.
DEPTH = ../../../..
REQUIRES = softupdt
CSRCS = nspatch.c
PROGRAM = nspatch$(BIN_SUFFIX)
include $(DEPTH)/config/rules.mk
symbols:
@echo "CSRCS = $(CSRCS)"
@echo "OBJS = $(OBJS)"
@echo "PROGRAM = $(PROGRAM)"
@echo "LIBRARY = $(LIBRARY)"
@echo "TARGETS = $(TARGETS)"

Просмотреть файл

@ -0,0 +1,66 @@
#!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.
IGNORE_MANIFEST=1
#
#VERBOSE = 1
DEPTH=..\..\..\..
#cannot define PROGRAM in manifest compatibly with NT and UNIX
PROGRAM= .\$(OBJDIR)\nspatch.exe
include <$(DEPTH)\config\config.mak>
# let manifest generate C_OBJS, it will prepend ./$(OBJDIR)/
# rules.mak will append C_OBJS onto OBJS.
# OBJS = $(CSRCS:.c=.obj)
PDBFILE = nspatch.pdb
MAPFILE = nspatch.map
REQUIRES=softupdt
CSRCS=nspatch.c
C_OBJS=.\$(OBJDIR)\nspatch.obj
!if "$(MOZ_BITS)" != "16"
LINCS=-I$(XPDIST)\public\softupdt
!endif
include <$(DEPTH)\config\rules.mak>
INSTALL = $(MAKE_INSTALL)
objs: $(OBJS)
programs: $(PROGRAM)
install:: $(TARGETS)
$(INSTALL) $(TARGETS) $(DIST)/bin
symbols:
@echo "CSRCS = $(CSRCS)"
@echo "INCS = $(INCS)"
@echo "OBJS = $(OBJS)"
@echo "LIBRARY = $(LIBRARY)"
@echo "PROGRAM = $(PROGRAM)"
@echo "TARGETS = $(TARGETS)"
@echo "DIST = $(DIST)"
@echo "VERSION_NUMBER = $(VERSION_NUMBER)"
@echo "WINFE = $(WINFE)"
@echo "DBM_LIB = $(DBM_LIB)"
@echo "INSTALL = $(INSTALL)"

Просмотреть файл

@ -0,0 +1,600 @@
/* -*- 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.
*/
/*--------------------------------------------------------------------
* NSPatch
*
* Applies GDIFF binary patches
*
* nspatch [-o"outfile"] oldfile newfile
*
* The outfile defaults console
*
*------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gdiff.h"
/*--------------------------------------
* constants
*------------------------------------*/
#define BUFSIZE 32768
#define OPSIZE 1
#define MAXCMDSIZE 12
#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)) )
/*--------------------------------------
* types
*------------------------------------*/
typedef unsigned long uint32;
typedef long int32;
typedef unsigned short uint16;
typedef short int16;
typedef unsigned char uchar;
typedef unsigned char BOOL;
/*--------------------------------------
* prototypes
*------------------------------------*/
int add( uint32 count );
void cleanup( void );
int copy( uint32 position, uint32 count );
int doPatch( void );
int getcmd( uchar *buffer, uint32 length );
char openFiles( void );
int parseHeader( void );
int parseAppdata( void );
void usage( void );
char validateArgs( int argc, char *argv[] );
int validateNewFile( void );
int validateOldFile( void );
/*--------------------------------------
* Global data
*------------------------------------*/
char *oldname = NULL,
*difname = NULL,
*outname = NULL;
uchar *databuf;
FILE *oldfile,
*diffile,
*outfile;
uchar checksumType;
uchar *oldChecksum = NULL,
*finalChecksum = NULL;
/*--------------------------------------
* main
*------------------------------------*/
int main( int argc, char *argv[] )
{
int err;
/* Parse command line */
if ( !validateArgs( argc, argv ) ) {
err = ERR_ARGS;
}
else {
err = openFiles();
}
/* Process the patchfile */
if ( err == ERR_OK ) {
err = doPatch();
}
/* Cleanup */
cleanup();
/* Report status */
if ( err == ERR_OK ) {
}
else {
switch (err) {
case ERR_ARGS:
fprintf( stderr, "Invalid arguments\n" );
usage();
break;
case ERR_ACCESS:
fprintf( stderr, "Error opening file\n" );
break;
case ERR_MEM:
fprintf( stderr, "Insufficient memory\n" );
break;
default:
fprintf( stderr, "Unexpected error %d\n", err );
break;
}
}
return (err);
}
/*--------------------------------------
* add
*------------------------------------*/
int add( uint32 count )
{
int err = ERR_OK;
uint32 nRead;
uint32 chunksize;
while ( count > 0 ) {
chunksize = ( count > BUFSIZE) ? BUFSIZE : count;
nRead = fread( databuf, 1, chunksize, diffile );
if ( nRead != chunksize ) {
err = ERR_BADDIFF;
break;
}
fwrite( databuf, 1, chunksize, outfile );
count -= chunksize;
}
return (err);
}
/*--------------------------------------
* cleanup
*------------------------------------*/
void cleanup()
{
if ( oldfile != NULL )
fclose( oldfile );
if ( diffile != NULL )
fclose( diffile );
if ( outfile != NULL /* && outfile != stdout */ )
fclose( outfile );
if ( oldChecksum != NULL )
free( oldChecksum );
if ( finalChecksum != NULL )
free( finalChecksum );
}
/*--------------------------------------
* copy
*------------------------------------*/
int copy( uint32 position, uint32 count )
{
int err = ERR_OK;
uint32 nRead;
uint32 chunksize;
fseek( oldfile, position, SEEK_SET );
while ( count > 0 ) {
chunksize = (count > BUFSIZE) ? BUFSIZE : count;
nRead = fread( databuf, 1, chunksize, oldfile );
if ( nRead != chunksize ) {
err = ERR_OLDFILE;
break;
}
fwrite( databuf, 1, chunksize, outfile );
count -= chunksize;
}
return (err);
}
/*--------------------------------------
* doPatch
*------------------------------------*/
int doPatch()
{
int err;
int done;
uchar opcode;
uchar cmdbuf[MAXCMDSIZE];
databuf = (uchar*)malloc(BUFSIZE);
if ( databuf == NULL ) {
err = ERR_MEM;
goto fail;
}
err = parseHeader();
if (err != ERR_OK)
goto fail;
err = validateOldFile();
if ( err != ERR_OK )
goto fail;
err = parseAppdata();
if ( err != ERR_OK )
goto fail;
/* apply patch */
done = feof(diffile);
while ( !done ) {
err = getcmd( &opcode, OPSIZE );
if ( err != ERR_OK )
break;
switch (opcode)
{
case ENDDIFF:
done = TRUE;
break;
case ADD16:
err = getcmd( cmdbuf, ADD16SIZE );
if ( err == ERR_OK ) {
err = add( getshort( cmdbuf ) );
}
break;
case ADD32:
err = getcmd( cmdbuf, ADD32SIZE );
if ( err == ERR_OK ) {
err = add( getlong( cmdbuf ) );
}
break;
case COPY16BYTE:
err = getcmd( cmdbuf, COPY16BYTESIZE );
if ( err == ERR_OK ) {
err = copy( getshort(cmdbuf), *(cmdbuf+sizeof(short)) );
}
break;
case COPY16SHORT:
err = getcmd( cmdbuf, COPY16SHORTSIZE );
if ( err == ERR_OK ) {
err = copy(getshort(cmdbuf),getshort(cmdbuf+sizeof(short)));
}
break;
case COPY16LONG:
err = getcmd( cmdbuf, COPY16LONGSIZE );
if ( err == ERR_OK ) {
err = copy(getshort(cmdbuf),getlong(cmdbuf+sizeof(short)));
}
break;
case COPY32BYTE:
err = getcmd( cmdbuf, COPY32BYTESIZE );
if ( err == ERR_OK ) {
err = copy( getlong(cmdbuf), *(cmdbuf+sizeof(long)) );
}
break;
case COPY32SHORT:
err = getcmd( cmdbuf, COPY32SHORTSIZE );
if ( err == ERR_OK ) {
err = copy( getlong(cmdbuf),getshort(cmdbuf+sizeof(long)) );
}
break;
case COPY32LONG:
err = getcmd( cmdbuf, COPY32LONGSIZE );
if ( err == ERR_OK ) {
err = copy( getlong(cmdbuf), getlong(cmdbuf+sizeof(long)) );
}
break;
case COPY64:
/* we don't support 64-bit file positioning yet */
err = ERR_OPCODE;
break;
default:
err = add( opcode );
break;
}
if ( err != ERR_OK )
done = TRUE;
}
if ( err == ERR_OK ) {
err = validateNewFile();
}
/* return status */
fail:
if ( databuf != NULL )
free( databuf );
return (err);
}
/*--------------------------------------
* getcmd
*------------------------------------*/
int getcmd( uchar *buffer, uint32 length )
{
uint32 bytesRead;
bytesRead = fread( buffer, 1, length, diffile );
if ( bytesRead != length )
return ERR_BADDIFF;
return ERR_OK;
}
/*--------------------------------------
* openFiles
*------------------------------------*/
char openFiles()
{
oldfile = fopen( oldname, "rb" );
if ( oldfile == NULL ) {
fprintf( stderr, "Can't open %s for reading\n", oldname );
return ERR_ACCESS;
}
diffile = fopen( difname, "rb" );
if ( diffile == NULL ) {
fprintf( stderr, "Can't open %s for reading\n", difname );
return ERR_ACCESS;
}
if ( outname == NULL || *outname == '\0' ) {
outfile = stdout;
}
else {
outfile = fopen( outname, "wb" );
}
if ( outfile == NULL ) {
fprintf( stderr, "Can't open %s for writing\n", outname );
return ERR_ACCESS;
}
return ERR_OK;
}
/*--------------------------------------
* parseHeader
*------------------------------------*/
int parseHeader( void )
{
int err = ERR_OK;
uint32 cslen;
uint32 oldcslen;
uint32 newcslen;
uint32 nRead;
uchar header[GDIFF_HEADERSIZE];
nRead = fread( header, 1, GDIFF_HEADERSIZE, diffile );
if ( nRead != GDIFF_HEADERSIZE ) {
err = ERR_HEADER;
}
else if (memcmp( header, GDIFF_MAGIC, GDIFF_MAGIC_LEN ) != 0 ) {
err = ERR_HEADER;
}
else if ( header[GDIFF_VER_POS] != GDIFF_VER ) {
err = ERR_HEADER;
}
else {
checksumType = header[GDIFF_CS_POS];
cslen = header[GDIFF_CSLEN_POS];
if ( checksumType > 0 ) {
err = ERR_CHKSUMTYPE;
}
else if ( cslen > 0 ) {
oldcslen = cslen / 2;
newcslen = cslen - oldcslen;
oldChecksum = (uchar*)malloc(oldcslen);
finalChecksum = (uchar*)malloc(newcslen);
if ( oldChecksum != NULL || finalChecksum != NULL ) {
nRead = fread( oldChecksum, 1, oldcslen, diffile );
if ( nRead == oldcslen ) {
nRead = fread( finalChecksum, 1, newcslen, diffile );
if ( nRead != newcslen ) {
err = ERR_HEADER;
}
}
else {
err = ERR_HEADER;
}
}
else {
err = ERR_MEM;
}
}
}
return (err);
}
/*--------------------------------------
* parseAppdata
*------------------------------------*/
int parseAppdata( void )
{
int err = ERR_OK;
uint32 nRead;
uint32 appdataSize;
uchar lenbuf[GDIFF_APPDATALEN];
nRead = fread( lenbuf, 1, GDIFF_APPDATALEN, diffile );
if ( nRead != GDIFF_APPDATALEN ) {
err = ERR_HEADER;
}
else {
appdataSize = getlong(lenbuf);
if ( appdataSize > 0 ) {
/* we currently don't know about appdata, so skip it */
fseek( diffile, appdataSize, SEEK_CUR );
}
}
return (err);
}
/*--------------------------------------
* usage
*------------------------------------*/
void usage ()
{
fprintf( stderr, "\n NSPatch [-o\"outfile\"] oldfile diff\n\n" );
fprintf( stderr, " -o name of patched output file\n\n" );
}
/*--------------------------------------
* validateArgs
*------------------------------------*/
char validateArgs( int argc, char *argv[] )
{
int i;
for ( i = 1; i < argc; i++ ) {
if ( *argv[i] == '-' ) {
switch (*(argv[i]+1)) {
case 'o':
outname = argv[i]+2;
break;
default:
fprintf( stderr, "Unknown option %s\n", argv[i] );
return (FALSE);
}
}
else if ( oldname == NULL ) {
oldname = argv[i];
}
else if ( difname == NULL ) {
difname = argv[i];
}
else {
fprintf( stderr, "Too many arguments\n" );
return (FALSE);
}
}
#ifdef DEBUG
fprintf( stderr, "Old file: %s\n", oldname );
fprintf( stderr, "Diff file: %s\n", difname );
fprintf( stderr, "output file: %s\n", outname );
#endif
/* validate arguments */
if ( oldname == NULL || difname == NULL ) {
fprintf( stderr, "Old and diff file name parameters are required.\n" );
return (FALSE);
}
return TRUE;
}
/*--------------------------------------
* validateNewFile
*------------------------------------*/
int validateNewFile()
{
if ( checksumType > 0 )
return ERR_CHKSUMTYPE;
else
return ERR_OK;
}
/*--------------------------------------
* validateOldFile
*------------------------------------*/
int validateOldFile()
{
if ( checksumType > 0 )
return ERR_CHKSUMTYPE;
else
return ERR_OK;
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -0,0 +1,161 @@
/* -*- 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.
*/
/*****************************************************************************
* *
* Module Name : OS2UPDT.H *
* *
* *
* Description : Include file for SU_WIN.C *
* *
* *
*****************************************************************************/
/* ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· */
/* º Various program defines º */
/* ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ */
/* String processing definitions */
//XP_OS2#define CR (CHAR) '\r'
//XP_OS2#define LF (CHAR) '\n'
// #define EOFFILE (CHAR) '\032' //P1D
#define EOFFILE (CHAR) '\x1A' //P1A
#define BLANK (CHAR) ' '
//XP_OS2#define TAB (CHAR) '\t'
#define EQUAL (CHAR) '='
#define COLON (CHAR) ':'
#define SEMICOLON (CHAR) ';'
#define ZEND (CHAR) '\0'
//XP_OS2#define CRLF "\r\n"
// #define EOFLINE "\r\n\032" //P1D
#define EOFLINE "\r\n\x1A" //P1A
#define BLANK_TAB " \t"
//#define BLANK_TAB_EOFLINE " \t\r\n\032" //P1D
//#define SEMIC_EOFLINE ";\r\n\032" //P1D
#define BLANK_TAB_EOFLINE " \t\r\n\x1A" /* P1A */
#define SEMIC_EOFLINE ";\r\n\x1A" /* P1A */
//XP_OS2#define MAXPATHLEN 260
#define DASD_FLAG 0
#define INHERIT 0x08
#define WRITE_THRU 0
#define FAIL_FLAG 0
#define SHARE_FLAG 0x10
#define ACCESS_FLAG 0x02
/* ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· */
/* º Various program defines º */
/* ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ */
#define CONFIGSYS "C:\\CONFIG.SYS"
#define FOUR_K 4*1024
#define SEG_SIZE (ULONG)65536
#define NORM 0x00
#define OS2HPFS "\\OS2\\HPFS.IFS"
#define WOS2HPFS "\\OS2\\BOOT\\HPFS.IFS"
#define OS2FAT "DISKCACHE"
#define ODI2NDILINE "ODI2NDI.OS2"
#define INT15 "INT15.SYS"
#define CPQPART "CPQPART.SYS"
#define CPQREDIR "CPQREDIR.FLT"
#define OS2CDROM "OS2CDROM.DMD"
#define DOSSYS "DOS.SYS"
#define MOUSESYS "MOUSE.SYS"
#define TESTCFG "TESTCFG.SYS"
#define INT15 "INT15.SYS"
#define CPQPART "CPQPART.SYS"
#define NOSWAP "NOSWAP"
/* ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· */
/* º Configuration routine defines º */
/* ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ */
/*ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿*/
/*³ Type of the configuration line³*/
/*ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ*/
/* Example: */
#define CSYS_COMMAND 200 /* BUFFERS=60 */
#define CSYS_EV 201 /* SET PROMPT=$i[$p] */
#define CSYS_PATH_EV 202 /* SET HELP=C:\OS2\HELP;E:\EPM */
#define CSYS_PATH 203 /* SET PATH=C:\OS2;C:\MUGLIB; */
#define CSYS_DPATH 204 /* SET DPATH=C:\OS2;C:\MUGLIB\DLL; */
#define CSYS_LIBPATH 205 /* LIBPATH=C:\OS2\DLL; */
#define CSYS_DEVICE 206 /* DEVICE=C:\OS2\EGA.SYS */
#define CSYS_RUN 207 /* RUN=C:\CMLIB\ACSTRSYS.EXE */
#define CSYS_IFS 208 /* IFS=C:\OS2\HPFS.IFS /CACHE:64 */
#define CSYS_PROTSHELL 209 /* PROTSHELL=C:\SECURESH.EXE */
#define CSYS_BOOKSHELF 210 /* SET BOOKSHELF=C:\OS2;C:\BOOK; */
#define CSYS_AUTOSTART 211 /* SET AUTOSTART=PROGRAMS, */
#define CSYS_20 212 /* 20=NETWRKSTA.200 */
#define CSYS_HELP 213 /* 20=NETWRKSTA.200 */
#define CSYS_DISKCACHE 214
#define CSYS_CALL 215 /* CALL=C:\XXX... */
#define CSYS_REM 216 /* REM ANYTHING */
#define CSYS_SET 217 /* SET ANYTHING no '=' used */
#define CSYS_BASEDEV 218
#define CSYS_MEMMAN 219
/*ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿*/
/*³ CsysUpdate insert positions ³*/
/*ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ*/
/* These constants represent update*/
/* locations within CONFIG.SYS. */
/* An update location is specified */
/* as either one of these constants*/
/* or an actual pointer within the */
/* buffer. Note that the constants*/
/* can't be misconstrued as buffer */
/* pointers since the selector is 0*/
/* */
/* Update as the: */
#define CSYS_FIRST (PSZ) 0x0000FFFF /* First line in CONFIG.SYS */
#define CSYS_LAST (PSZ) 0x0000FFFE /* Last line in CONFIG.SYS */
#define CSYS_FIRST_TYPE (PSZ) 0x0000FFFD /* First or last DEVICE, RUN, or*/
#define CSYS_LAST_TYPE (PSZ) 0x0000FFFC /* IFS (depends on type) */
/* ÖÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ· */
/* º Forward Function Declarations º */
/* ÓÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄĽ */
#ifdef __cplusplus
extern "C" {
#endif
VOID StripFrontWhite(char *);
char *NextLine(char *);
VOID CopyLine(char *, char *);
ULONG InsertString(char *, char *, char *);
/* Steve's Functions */
CHAR *ScootString(CHAR *, SHORT);
CHAR *CopyNBytes(CHAR *, CHAR *, USHORT);
USHORT StringLength(CHAR *);
ULONG ReadFileToBuffer(char *, char **,ULONG *);
ULONG WriteBufferToFile(char *, char **);
ULONG search_file_drive(char *, char *);
PSZ FAR CsysQuery (PSZ, USHORT, PSZ, PSZ);
PSZ FAR CsysUpdate (PSZ, USHORT, PSZ, PSZ, PSZ);
PSZ FAR CsysDelete (PSZ, USHORT, PSZ, PSZ);
ULONG WriteLockFileDDToConfig (PSZ pszListFile);
ULONG WriteLockFileRenameEntry(PSZ final, PSZ current, PSZ listfile);
/*ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿*/
/*³ Routines used locally ³*/
/*ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ*/
VOID FAR BuildAssignment (USHORT, PSZ, PSZ);
VOID FAR FormatLine (PSZ, PSZ);
#ifdef __cplusplus
}
#endif

Просмотреть файл

@ -0,0 +1,881 @@
/* -*- 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 "softupdt.h"
#define NEW_FE_CONTEXT_FUNCS
#include "zig.h"
#include "net.h"
#include "libevent.h"
#include "prefapi.h"
#include "prprf.h"
#include "mkutils.h"
#include "fe_proto.h"
#include "prthread.h"
#include "xpgetstr.h"
#include "prmon.h"
extern int MK_OUT_OF_MEMORY;
#define MOCHA_CONTEXT_PREFIX "autoinstall:"
/* error codes */
#define su_ErrInvalidArgs -1
#define su_ErrUnknownInstaller -2
#define su_ErrInternalError -3
#define su_ErrBadScript -4
#define su_JarError -5
/* xp_string defines */
extern int SU_NOT_A_JAR_FILE;
extern int SU_SECURITY_CHECK;
extern int SU_INSTALL_FILE_HEADER;
extern int SU_INSTALL_FILE_MISSING;
/* structs */
/* su_DownloadStream
* keeps track of all SU specific data needed for the stream
*/
typedef struct su_DownloadStream_struct {
XP_File fFile;
char * fJarFile; /* xpURL location of the downloaded file */
URL_Struct * fURL;
MWContext * fContext;
SoftUpdateCompletionFunction fCompletion;
void * fCompletionClosure;
int32 fFlags; /* download flags */
} su_DownloadStream;
/* su_URLFeData
* passes data between the trigger and the stream
*/
typedef struct su_URLFeData_struct {
SoftUpdateCompletionFunction fCompletion;
void * fCompletionClosure;
int32 fFlags; /* download flags */
} su_URLFeData;
static char * EncodeSoftUpJSArgs(const char * fileName, XP_Bool silent, XP_Bool force);
/* Stream callbacks */
int su_HandleProcess (NET_StreamClass *stream, const char *buffer, int32 buffLen);
void su_HandleComplete (NET_StreamClass *stream);
void su_HandleAbort (NET_StreamClass *stream, int reason);
unsigned int su_HandleWriteReady (NET_StreamClass *stream);
/* Completion routine for stream handler. Deletes su_DownloadStream */
void su_CompleteSoftwareUpdate(MWContext * context,
SoftUpdateCompletionFunction f,
void * completionClosure,
int result,
su_DownloadStream* realStream);
void su_NetExitProc(URL_Struct* url, int result, MWContext * context);
void su_HandleCompleteJavaScript (su_DownloadStream* realStream);
/* Completion routine for SU_StartSoftwareUpdate */
void su_CompleteSoftwareUpdate(MWContext * context,
SoftUpdateCompletionFunction f,
void * completionClosure,
int result,
su_DownloadStream* realStream)
{
/* Notify the trigger */
if ( f != NULL )
f(result, completionClosure);
/* Clean up */
if (realStream)
{
if ( realStream->fJarFile )
{
result = XP_FileRemove( realStream->fJarFile, xpURL );
XP_FREE( realStream->fJarFile );
}
XP_FREE( realStream);
}
}
/* a struct to hold the arguments */
struct su_startCallback_
{
char * url;
char * name;
SoftUpdateCompletionFunction f;
void * completionClosure;
int32 flags;
MWContext * context;
} ;
typedef struct su_startCallback_ su_startCallback;
XP_Bool QInsert( su_startCallback * Item );
su_startCallback * QGetItem(void);
void SU_InitMonitor(void);
void SU_DestroyMonitor(void);
/*
* This struct represents one entry in a queue setup to hold download
* requests if there are more than one.
*/
typedef struct su_QItem
{
struct su_QItem * next;
struct su_QItem * prev;
su_startCallback * QItem;
} su_QItem;
XP_Bool DnLoadInProgress = FALSE;
PRMonitor * su_monitor = NULL;
void SU_InitMonitor(void)
{
su_monitor = PR_NewMonitor();
XP_ASSERT( su_monitor != NULL );
}
void SU_DestroyMonitor(void)
{
if ( su_monitor != NULL )
{
PR_DestroyMonitor(su_monitor);
su_monitor = NULL;
}
}
/*
* Queue maintanence is done here
*/
su_QItem * Qhead = NULL;
su_QItem * Qtail = NULL;
XP_Bool QInsert( su_startCallback * Item )
{
su_QItem *p = XP_ALLOC( sizeof (su_QItem));
if (p == NULL)
return FALSE;
p->QItem = Item;
p->next = Qhead;
p->prev = NULL;
if (Qhead != NULL)
Qhead->prev = p;
Qhead = p;
if (Qtail == NULL) /* First Item inserted in Q? */
Qtail = p;
return TRUE;
}
su_startCallback *QGetItem(void)
{
su_QItem *Qtemp = Qtail;
if (Qtemp != NULL)
{
su_startCallback *p = NULL;
Qtail = Qtemp->prev;
if (Qtail == NULL) /* Last Item deleted from Q? */
Qhead = NULL;
else
Qtail->next = NULL;
p = Qtemp->QItem;
XP_FREE(Qtemp);
return p;
}
return NULL;
}
/*
* timer callback to start the network download of a JAR file
*/
PRIVATE void
su_FE_timer_callback( void * data)
{
su_startCallback * c;
URL_Struct * urlS = NULL;
su_URLFeData * fe_data = NULL;
XP_Bool errFound = TRUE;
c = (su_startCallback*)data;
if (c->context == NULL)
{
su_CompleteSoftwareUpdate(c->context, c->f, c->completionClosure, su_ErrInternalError, NULL);
goto done;
}
if (c->url == NULL)
{
su_CompleteSoftwareUpdate(c->context, c->f, c->completionClosure, su_ErrInvalidArgs, NULL);
goto done;
}
urlS = NET_CreateURLStruct(c->url, NET_DONT_RELOAD);
if (urlS == NULL)
{
su_CompleteSoftwareUpdate(c->context, c->f, c->completionClosure, MK_OUT_OF_MEMORY, NULL);
goto done;
}
/* fe_data holds the arguments that need to be passed
* to our download stream
*/
fe_data = XP_ALLOC(sizeof(su_URLFeData));
if (fe_data == NULL)
{
su_CompleteSoftwareUpdate(c->context, c->f, c->completionClosure, MK_OUT_OF_MEMORY, NULL);
NET_FreeURLStruct(urlS);
goto done;
}
fe_data->fCompletion = c->f;
fe_data->fCompletionClosure = c->completionClosure;
fe_data->fFlags = c->flags;
urlS->fe_data = fe_data;
urlS->must_cache = TRUE; /* This is needed for partial caching */
errFound = FALSE;
NET_GetURL(urlS, FO_CACHE_AND_SOFTUPDATE, c->context, su_NetExitProc);
done:
if (errFound)
{
/* pops next item from queue or sets download flag to false */
su_NetExitProc(NULL, 0, NULL);
}
if (c->url)
XP_FREE( c->url);
if (c->name)
XP_FREE( c->name);
XP_FREE( c );
}
/* NET_GetURL exit procedure */
void su_NetExitProc(URL_Struct* url, int result, MWContext * context)
{
su_startCallback * c;
PR_EnterMonitor(su_monitor);
if (c = QGetItem())
{
FE_SetTimeout( su_FE_timer_callback, c, 1 );
}
else
{
DnLoadInProgress = FALSE;
}
PR_ExitMonitor(su_monitor);
}
#ifdef XP_MAC
#pragma export on
#endif
/* SU_StartSoftwareUpdate
* Main public interface to software update
*/
PUBLIC XP_Bool
SU_StartSoftwareUpdate(MWContext * context,
const char * url,
const char * name,
SoftUpdateCompletionFunction f,
void * completionClosure,
int32 flags)
{
URL_Struct * urlS = NULL;
su_URLFeData * fe_data = NULL;
XP_Bool enabled;
/* Better safe than sorry */
PREF_GetBoolPref( AUTOUPDATE_ENABLE_PREF, &enabled);
if (!enabled)
return FALSE;
/* if we do not have a context, create one */
if ( context == NULL )
{
return FALSE;
}
/* Need to process this on a timer because netlib is not reentrant */
{
su_startCallback * varHolder;
varHolder = XP_ALLOC( sizeof (su_startCallback));
if (varHolder == NULL)
{
su_CompleteSoftwareUpdate(context, f, completionClosure, MK_OUT_OF_MEMORY, NULL);
return FALSE;
}
varHolder->url = url ? XP_STRDUP( url ) : NULL;
varHolder->name = name ? XP_STRDUP( name ) : NULL;
varHolder->f = f;
varHolder->context = context;
varHolder->completionClosure = completionClosure;
varHolder->flags = flags;
PR_EnterMonitor(su_monitor);
if ( DnLoadInProgress )
{
if (!QInsert( varHolder ))
{ /* cleanup */
su_CompleteSoftwareUpdate(context, f, completionClosure, MK_OUT_OF_MEMORY, NULL);
if (varHolder->url)
XP_FREE( varHolder->url);
if (varHolder->name)
XP_FREE( varHolder->name);
XP_FREE( varHolder );
return FALSE;
}
}
else
{
DnLoadInProgress = TRUE;
FE_SetTimeout( su_FE_timer_callback, varHolder, 1 );
}
PR_ExitMonitor(su_monitor);
return TRUE;
}
}
/* New stream callback */
/* creates the stream, and a opens up a temporary file */
NET_StreamClass * SU_NewStream (int format_out, void * registration,
URL_Struct * request, MWContext *context)
{
su_DownloadStream * streamData = NULL;
su_URLFeData * fe_data = NULL;
NET_StreamClass * stream = NULL;
SoftUpdateCompletionFunction completion = NULL;
void * completionClosure = NULL;
int32 flags = 0;
short result = 0;
XP_Bool isJar;
/* Initialize the stream data by data passed in the URL*/
fe_data = (su_URLFeData *) request->fe_data;
if ( fe_data != NULL )
{
completion = fe_data->fCompletion;
completionClosure = fe_data->fCompletionClosure;
flags = fe_data->fFlags;
}
/* Make sure that we are loading a Java archive
Strictly, we should accept only APPLICATION_JAVAARCHIVE,\
but I know that many servers will be misconfigured
so we'll try to deal with text/plain, and octet-stream
So, the logic is:
Anything but HTML is OK. Netlib will only trigger us
with the correct MIME type, and when we are using triggers
this is the right thing to do. HTML is usually an error message
from the server.
*/
if (request->content_type)
{
if ( XP_STRCMP( APPLICATION_JAVAARCHIVE, request->content_type) == 0) /* Exact match */
isJar = TRUE;
else if ( XP_STRCMP( TEXT_HTML, request->content_type) == 0)
isJar = FALSE;
else
isJar = TRUE;
}
else
isJar = TRUE; /* Assume we have JAR if no content type */
/* If we got the wrong MIME type... */
if (isJar == FALSE)
{
if (context)
FE_Alert(context, XP_GetString(SU_NOT_A_JAR_FILE));
goto fail;
}
/* Create all the structs */
streamData = XP_CALLOC(sizeof(su_DownloadStream), 1);
if (streamData == NULL)
{
result = MK_OUT_OF_MEMORY;
goto fail;
}
stream = NET_NewStream (NULL,
su_HandleProcess,
su_HandleComplete,
su_HandleAbort,
su_HandleWriteReady,
streamData,
context);
if (stream == NULL)
{
result = MK_OUT_OF_MEMORY;
goto fail;
}
streamData->fURL = request;
streamData->fContext = context;
streamData->fCompletion = completion;
streamData->fCompletionClosure = completionClosure;
streamData->fFlags = flags;
if (request->fe_data)
{
XP_FREE( request->fe_data);
request->fe_data = NULL;
}
/* Here we jump through few hoops to get the file name in xpURL kind */
streamData->fJarFile = WH_TempName( xpURL, NULL );
if (streamData->fJarFile == NULL)
{
result = su_ErrInternalError;
goto fail;
}
streamData->fFile = XP_FileOpen( streamData->fJarFile, xpURL, XP_FILE_WRITE_BIN );
if ( streamData->fFile == 0)
{
result = su_ErrInternalError;
goto fail;
}
/* return the stream */
return stream;
fail:
if (stream != NULL)
XP_FREE( stream );
su_CompleteSoftwareUpdate( context, completion, completionClosure, result, streamData );
return NULL;
}
#ifdef XP_MAC
#pragma export reset
#endif
/* su_HandleProcess
* stream method, writes to disk
*/
int su_HandleProcess (NET_StreamClass *stream, const char *buffer, int32 buffLen)
{
void *streamData=stream->data_object;
return XP_FileWrite( buffer, buffLen, ((su_DownloadStream*)streamData)->fFile );
}
/* su_HandleAbort
* Clean up
*/
void su_HandleAbort (NET_StreamClass *stream, int reason)
{
void *streamData=stream->data_object;
su_DownloadStream* realStream = (su_DownloadStream*)stream->data_object;
/* Close the files */
if (realStream->fFile)
XP_FileClose(realStream->fFile);
/* Report the result */
su_CompleteSoftwareUpdate(realStream->fContext,
realStream->fCompletion, realStream->fCompletionClosure, reason, realStream);
}
unsigned int su_HandleWriteReady (NET_StreamClass *stream)
{
return USHRT_MAX; /* Returning -1 causes errors when loading local file */
}
/* su_HandleComplete
* Clean up
*/
void su_HandleComplete (NET_StreamClass *stream)
{
su_DownloadStream* realStream = (su_DownloadStream*)stream->data_object;
if (realStream->fFile)
XP_FileClose(realStream->fFile);
su_HandleCompleteJavaScript( realStream );
}
/* This is called when Mocha is done with evaluation */
static void
su_mocha_eval_exit_fn(void * data, char * str, size_t len, char * wysiwyg_url,
char * base_href, Bool valid)
{
short result = 0;
su_DownloadStream* realStream = (su_DownloadStream*) data;
MWContext *context = realStream->fContext;
if (valid == FALSE)
result = su_ErrBadScript;
if (str)
XP_FREE( str );
su_CompleteSoftwareUpdate( context,
realStream->fCompletion, realStream->fCompletionClosure, 0, realStream );
FE_DestroyWindow(context);
}
/* su_ReadFileIntoBuffer
* given a file name, reads it into buffer
* returns an error code
*/
static short su_ReadFileIntoBuffer(char * fileName, void ** buffer, unsigned long * bufferSize)
{
XP_File file;
XP_StatStruct st;
short result = 0;
if ( XP_Stat( fileName, &st, xpURL ) != 0 )
{
result = su_ErrInternalError;
goto fail;
}
*bufferSize = st.st_size;
*buffer = XP_ALLOC( st.st_size );
if (*buffer == NULL)
{
result = MK_OUT_OF_MEMORY;
goto fail;
}
file = XP_FileOpen( fileName, xpURL, XP_FILE_READ_BIN );
if ( file == 0 )
{
result = su_ErrInternalError;
goto fail;
}
if ( XP_FileRead( *buffer, *bufferSize, file ) != *bufferSize )
{
result = su_ErrInternalError;
XP_FileClose( file );
goto fail;
}
XP_FileClose( file );
return result;
fail:
if (*buffer != NULL)
XP_FREE( * buffer);
*buffer = NULL;
return result;
}
/* Encodes the args in the format
* MOCHA_CONTEXT_PREFIX<File>CR<silent>CR<force>
* Booleans are encoded as T or F.
* DecodeSoftUpJSArgs is in lm_softup.c
*/
static char *
EncodeSoftUpJSArgs(const char * fileName, XP_Bool force, XP_Bool silent )
{
char * s;
int32 length;
if (fileName == NULL)
return NULL;
length = XP_STRLEN(fileName) +
XP_STRLEN(MOCHA_CONTEXT_PREFIX) + 5; /* 2 booleans and a CR */
s = XP_ALLOC(length);
if (s != NULL)
{
s[0] = 0;
XP_STRCAT(s, MOCHA_CONTEXT_PREFIX);
XP_STRCAT(s, fileName);
s[length - 5] = CR;
s[length - 4] = silent ? 'T' : 'F';
s[length - 3] = CR;
s[length - 2] = force ? 'T' : 'F';
s[length - 1] = 0;
}
return s;
}
/* su_HandleCompleteJavaScript
* Reads in the mocha script out of the Jar file
* Executes the script
*/
void su_HandleCompleteJavaScript (su_DownloadStream* realStream)
{
short result = 0;
void * buffer = NULL;
unsigned long bufferSize;
char * installerJarName = NULL;
char * installerFileNameURL = NULL;
char * codebase = NULL;
int32 urlLen;
unsigned long fileNameLength;
ZIG * jarData = NULL;
char s[255];
char * jsScope = NULL;
ETEvalStuff * stuff = NULL;
/* Initialize the JAR file */
jarData = SOB_new();
if ( jarData == NULL)
{
result = MK_OUT_OF_MEMORY;
goto fail;
}
SOB_set_context (jarData, realStream->fContext);
result = SOB_pass_archive( ZIG_F_GUESS,
realStream->fJarFile,
realStream->fURL->address,
jarData);
if (result < 0)
{
char *errMsg = SOB_get_error(result);
PR_snprintf(s, 255, XP_GetString(SU_SECURITY_CHECK), (errMsg?errMsg:"") );
FE_Alert(realStream->fContext, s);
result = su_JarError;
goto fail;
}
/* Get the installer file name */
result = SOB_get_metainfo( jarData, NULL, INSTALLER_HEADER, (void**)&installerJarName, &fileNameLength);
if (result < 0)
{
FE_Alert(realStream->fContext, XP_GetString(SU_INSTALL_FILE_HEADER));
result = su_JarError;
goto fail;
}
installerJarName[fileNameLength] = 0; /* Terminate the string */
/* Need a temporary file name that is the xpURL form */
installerFileNameURL = WH_TempName( xpURL, NULL );
if ( installerFileNameURL == NULL)
{
result = su_JarError;
goto fail;
}
/* Extract the script out */
result = SOB_verified_extract( jarData, installerJarName, installerFileNameURL);
if (result < 0)
{
PR_snprintf(s, 255, XP_GetString(SU_INSTALL_FILE_MISSING), installerJarName);
FE_Alert(realStream->fContext, s);
result = su_JarError;
goto fail;
}
/* Read the file in */
result = su_ReadFileIntoBuffer( installerFileNameURL, &buffer, &bufferSize);
XP_FileRemove( installerFileNameURL, xpURL);
if (result < 0)
{
result = su_JarError;
goto fail;
}
/* Temporary hack to pass the zig data */
/* close the archive */
SOB_destroy( jarData);
jarData = NULL;
{
Chrome chrome;
MWContext * context;
JSPrincipals *principals;
/* For security reasons, installer JavaScript has to execute inside a
special context. This context is created by ET_EvaluateBuffer as a JS object
of type SoftUpdate. the arguments to the object are passed in the string,
jsScope
*/
jsScope = EncodeSoftUpJSArgs(realStream->fJarFile,
((realStream->fFlags & FORCE_INSTALL) != 0),
((realStream->fFlags & SILENT_INSTALL) != 0));
if (jsScope == NULL)
goto fail;
XP_BZERO(&chrome, sizeof(Chrome));
chrome.location_is_chrome = TRUE;
chrome.l_hint = -3000;
chrome.t_hint = -3000;
chrome.type = MWContextDialog;
context = FE_MakeNewWindow(realStream->fContext, NULL, NULL, &chrome);
if (context == NULL)
goto fail;
urlLen = XP_STRLEN(realStream->fURL->address);
codebase = XP_ALLOC( urlLen + XP_STRLEN(installerJarName) + 2 );
if ( codebase == NULL)
goto fail;
XP_STRCPY( codebase, realStream->fURL->address );
codebase[urlLen] = '/';
XP_STRCPY( codebase+urlLen+1, installerJarName );
principals = LM_NewJSPrincipals(realStream->fURL, installerJarName, codebase );
if (principals == NULL) {
FE_DestroyWindow(context);
goto fail;
}
/* Execute the mocha script, result will be reported in the callback */
realStream->fContext = context;
stuff = (ETEvalStuff *) XP_NEW_ZAP(ETEvalStuff);
if (!stuff) {
FE_DestroyWindow(context);
goto fail;
}
stuff->len = bufferSize;
stuff->line_no = 1;
stuff->scope_to = jsScope;
stuff->want_result = JS_TRUE;
stuff->data = realStream;
stuff->version = JSVERSION_DEFAULT;
stuff->principals = principals;
ET_EvaluateScript(context, buffer, stuff, su_mocha_eval_exit_fn);
}
goto done;
fail:
if (jarData != NULL)
SOB_destroy( jarData);
su_CompleteSoftwareUpdate( realStream->fContext,
realStream->fCompletion, realStream->fCompletionClosure, result, realStream );
/* drop through */
done:
XP_FREEIF(jsScope);
XP_FREEIF(codebase);
if ( installerFileNameURL )
XP_FREE( installerFileNameURL );
/* Should we purge stuff from the disk cache here? */
}
/* XXX: Move JavaGetBoolPref to lj_init.c.
* Delete IsJavaSecurityEnabled and IsJavaSecurityDefaultTo30Enabled functions
* XXX: Cache all security preferences while we are running on mozilla
* thread. Hack for 4.0
*/
#define MAX_PREF 20
struct {
char *pref_name;
XP_Bool value;
} cachePref[MAX_PREF];
static int free_idx=0;
static XP_Bool locked = FALSE;
static void AddPrefToCache(char *pref_name, XP_Bool value)
{
if (!pref_name)
return;
if (free_idx >= MAX_PREF) {
XP_ASSERT(FALSE); /* Implement dynamic growth of preferences */
return;
}
cachePref[free_idx].pref_name = XP_STRDUP(pref_name);
cachePref[free_idx].value = value;
free_idx++;
}
static XP_Bool GetPreference(char *pref_name, XP_Bool *pref_value)
{
int idx = 0;
*pref_value = FALSE;
if (!pref_name)
return FALSE;
for (; idx < free_idx; idx++) {
if (XP_STRCMP(cachePref[idx].pref_name, pref_name) == 0) {
*pref_value = cachePref[idx].value;
locked = TRUE;
return TRUE;
}
}
if (locked) {
XP_ASSERT(FALSE); /* Implement dynamic growth of preferences */
return FALSE;
}
if (PREF_GetBoolPref(pref_name, pref_value) >=0) {
AddPrefToCache(pref_name, *pref_value);
return TRUE;
}
return FALSE;
}
#ifdef XP_MAC
#pragma export on
#endif
int PR_CALLBACK JavaGetBoolPref(char * pref_name)
{
XP_Bool pref;
int ret_val;
GetPreference(pref_name, &pref);
ret_val = pref;
return ret_val;
}
int PR_CALLBACK IsJavaSecurityEnabled()
{
XP_Bool pref;
int ret_val;
GetPreference("signed.applets.codebase_principal_support", &pref);
ret_val = !pref;
return ret_val;
}
int PR_CALLBACK IsJavaSecurityDefaultTo30Enabled()
{
return JavaGetBoolPref("signed.applets.local_classes_have_30_powers");
}
#ifdef XP_MAC
#pragma export reset
#endif

Просмотреть файл

@ -0,0 +1,489 @@
/* -*- 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.
*/
/* Implements a simple AppleSingle decoder, as described in RFC1740 */
/* http://andrew2.andrew.cmu.edu/rfc/rfc1740.html */
/* Code is a bit ugly-looking (not pure C++ style */
/* Apologies to the Mac guys, but I have a feeling that this file might be */
/* cross-product in the future */
/* xp */
#include "su_aplsn.h"
#include "xp_file.h"
#include "xp_mcom.h"
/* Mac */
#include "ufilemgr.h"
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=mac68k
#endif
/* struct definitions from RFC1740 */
typedef struct ASHeader /* header portion of AppleSingle */
{
/* AppleSingle = 0x00051600; AppleDouble = 0x00051607 */
uint32 magicNum; /* internal file type tag */
uint32 versionNum; /* format version: 2 = 0x00020000 */
uint8 filler[16]; /* filler, currently all bits 0 */
uint16 numEntries; /* number of entries which follow */
} ASHeader ; /* ASHeader */
typedef struct ASEntry /* one AppleSingle entry descriptor */
{
uint32 entryID; /* entry type: see list, 0 invalid */
uint32 entryOffset; /* offset, in octets, from beginning */
/* of file to this entry's data */
uint32 entryLength; /* length of data in octets */
} ASEntry; /* ASEntry */
typedef struct ASFinderInfo
{
FInfo ioFlFndrInfo; /* PBGetFileInfo() or PBGetCatInfo() */
FXInfo ioFlXFndrInfo; /* PBGetCatInfo() (HFS only) */
} ASFinderInfo; /* ASFinderInfo */
typedef struct ASMacInfo /* entry ID 10, Macintosh file information */
{
uint8 filler[3]; /* filler, currently all bits 0 */
uint8 ioFlAttrib; /* PBGetFileInfo() or PBGetCatInfo() */
} ASMacInfo;
typedef struct ASFileDates /* entry ID 8, file dates info */
{
int32 create; /* file creation date/time */
int32 modify; /* last modification date/time */
int32 backup; /* last backup date/time */
int32 access; /* last access date/time */
} ASFileDates; /* ASFileDates */
/* entryID list */
#define AS_DATA 1 /* data fork */
#define AS_RESOURCE 2 /* resource fork */
#define AS_REALNAME 3 /* File's name on home file system */
#define AS_COMMENT 4 /* standard Mac comment */
#define AS_ICONBW 5 /* Mac black & white icon */
#define AS_ICONCOLOR 6 /* Mac color icon */
/* 7 /* not used */
#define AS_FILEDATES 8 /* file dates; create, modify, etc */
#define AS_FINDERINFO 9 /* Mac Finder info & extended info */
#define AS_MACINFO 10 /* Mac file info, attributes, etc */
#define AS_PRODOSINFO 11 /* Pro-DOS file info, attrib., etc */
#define AS_MSDOSINFO 12 /* MS-DOS file info, attributes, etc */
#define AS_AFPNAME 13 /* Short name on AFP server */
#define AS_AFPINFO 14 /* AFP file info, attrib., etc */
#define AS_AFPDIRID 15 /* AFP directory ID */
#if PRAGMA_ALIGN_SUPPORTED
#pragma options align=reset
#endif
/* su_EntryToMacFile
* Blasts the bytes specified in the entry to already opened Mac file
*/
static int
su_EntryToMacFile( ASEntry inEntry, XP_File inFile, uint16 inRefNum)
{
#define BUFFER_SIZE 8192
char buffer[BUFFER_SIZE];
size_t totalRead = 0, bytesRead;
OSErr err;
if ( XP_FileSeek( inFile, inEntry.entryOffset, SEEK_SET) != 0 )
return -1 ;
while ( totalRead < inEntry.entryLength )
{
// Should we yield in here?
bytesRead = XP_FileRead( buffer, BUFFER_SIZE, inFile );
if ( bytesRead <= 0 )
return -1;
long bytesToWrite = totalRead + bytesRead > inEntry.entryLength ?
inEntry.entryLength - totalRead :
bytesRead;
totalRead += bytesRead;
err = FSWrite(inRefNum, &bytesToWrite, buffer);
if (err != noErr)
return err;
}
return 0;
}
/* su_ProcessDataFork
* blast the data fork to the disk
* returns 0 on success
*/
static int
su_ProcessDataFork( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
int16 refNum;
OSErr err;
/* Setup the files */
err = FSpOpenDF (ioSpec, fsWrPerm, &refNum);
if ( err == noErr )
err = su_EntryToMacFile( inEntry, inFile, refNum );
FSClose( refNum );
return err;
}
/* su_ProcessDataFork
* blast the resource fork to the disk
* returns 0 on success
*/
static int
su_ProcessResourceFork( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
int16 refNum;
OSErr err;
err = FSpOpenRF (ioSpec, fsWrPerm, &refNum);
if ( err == noErr )
err = su_EntryToMacFile( inEntry, inFile, refNum );
FSClose( refNum );
return err;
}
/* su_ProcessRealName
* Renames the file to its real name
*/
static int
su_ProcessRealName( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
Str255 newName;
OSErr err;
if ( inEntry.entryLength > 32 ) /* Max file name length for the Mac */
return -1;
if ( XP_FileSeek( inFile, inEntry.entryOffset, SEEK_SET) != 0 )
return -1 ;
if ( XP_FileRead( &newName[1], inEntry.entryLength, inFile ) != inEntry.entryLength )
return -1;
newName[0] = inEntry.entryLength;
err = FSpRename(ioSpec, newName);
if (err == noErr)
XP_MEMCPY( ioSpec->name, newName, 32 );
return err;
}
/* su_ProcessComment
* Sets the file comment
*/
static int
su_ProcessComment( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
Str255 newComment;
if ( inEntry.entryLength > 32 ) /* Max file name length for the Mac */
return -1;
if ( XP_FileSeek( inFile, inEntry.entryOffset, SEEK_SET) != 0 )
return -1 ;
if ( XP_FileRead( &newComment[1], inEntry.entryLength, inFile ) != inEntry.entryLength )
return -1;
newComment[0] = inEntry.entryLength;
CFileMgr::FileSetComment(*ioSpec, newComment );
return 0;
}
/* su_ProcessComment
* Sets the modification dates
*/
static int
su_ProcessFileDates( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
ASFileDates dates;
OSErr err;
if ( inEntry.entryLength != sizeof(dates) ) /* Max file name length for the Mac */
return -1;
if ( XP_FileSeek( inFile, inEntry.entryOffset, SEEK_SET) != 0 )
return -1 ;
if ( XP_FileRead( &dates, inEntry.entryLength, inFile ) != inEntry.entryLength )
return -1;
Str31 name;
XP_MEMCPY(name, ioSpec->name, ioSpec->name[0] + 1);
CInfoPBRec pb;
pb.hFileInfo.ioNamePtr = name;
pb.hFileInfo.ioVRefNum = ioSpec->vRefNum;
pb.hFileInfo.ioDirID = ioSpec->parID;
pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
err = PBGetCatInfoSync(&pb);
if ( err != noErr )
return -1;
#define YR_2000_SECONDS 3029572800
pb.hFileInfo.ioFlCrDat = dates.create + 3029572800;
pb.hFileInfo.ioFlMdDat = dates.modify + 3029572800;
pb.hFileInfo.ioFlBkDat = dates.backup + 3029572800;
/* Not sure if mac has the last access time */
XP_MEMCPY(name, ioSpec->name, ioSpec->name[0] + 1);
pb.hFileInfo.ioNamePtr = name;
pb.hFileInfo.ioVRefNum = ioSpec->vRefNum;
pb.hFileInfo.ioDirID = ioSpec->parID;
pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
err = PBSetCatInfoSync(&pb);
return err;
}
/* su_ProcessFinderInfo
* Sets the Finder info
*/
static int
su_ProcessFinderInfo( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
ASFinderInfo info;
OSErr err;
if (inEntry.entryLength != sizeof( ASFinderInfo ))
return -1;
if ( XP_FileSeek( inFile, inEntry.entryOffset, SEEK_SET) != 0 )
return -1 ;
if ( XP_FileRead( &info, sizeof(info), inFile) != inEntry.entryLength )
return -1;
err = FSpSetFInfo(ioSpec, &info.ioFlFndrInfo);
if ( err != noErr )
return -1;
Str31 name;
XP_MEMCPY(name, ioSpec->name, ioSpec->name[0] + 1);
CInfoPBRec pb;
pb.hFileInfo.ioNamePtr = name;
pb.hFileInfo.ioVRefNum = ioSpec->vRefNum;
pb.hFileInfo.ioDirID = ioSpec->parID;
pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
err = PBGetCatInfoSync(&pb);
if ( err != noErr )
return -1;
pb.hFileInfo.ioNamePtr = name;
pb.hFileInfo.ioVRefNum = ioSpec->vRefNum;
pb.hFileInfo.ioDirID = ioSpec->parID;
pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
pb.hFileInfo.ioFlXFndrInfo = info.ioFlXFndrInfo;
err = PBSetCatInfoSync(&pb);
return err;
}
/* su_ProcessMacInfo
* Sets the Finder info
*/
static int
su_ProcessMacInfo( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
ASMacInfo info;
OSErr err;
if (inEntry.entryLength != sizeof( ASMacInfo ))
return -1;
if ( XP_FileSeek( inFile, inEntry.entryOffset, SEEK_SET) != 0 )
return -1 ;
if ( XP_FileRead( &info, sizeof(info), inFile) != inEntry.entryLength )
return -1;
Str31 name;
XP_MEMCPY(name, ioSpec->name, ioSpec->name[0] + 1);
CInfoPBRec pb;
pb.hFileInfo.ioNamePtr = name;
pb.hFileInfo.ioVRefNum = ioSpec->vRefNum;
pb.hFileInfo.ioDirID = ioSpec->parID;
pb.hFileInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */
err = PBGetCatInfoSync(&pb);
if ( err != noErr )
return -1;
pb.hFileInfo.ioNamePtr = name;
pb.hFileInfo.ioVRefNum = ioSpec->vRefNum;
pb.hFileInfo.ioDirID = ioSpec->parID;
pb.hFileInfo.ioFlAttrib = info.ioFlAttrib;
err = PBSetCatInfoSync(&pb);
return err;
}
static int
su_ProcessASEntry( ASEntry inEntry, XP_File inFile, FSSpec * ioSpec )
{
switch (inEntry.entryID)
{
case AS_DATA:
return su_ProcessDataFork( inEntry, inFile, ioSpec );
break;
case AS_RESOURCE:
return su_ProcessResourceFork( inEntry, inFile, ioSpec );
break;
case AS_REALNAME:
su_ProcessRealName( inEntry, inFile, ioSpec );
return 0; // Ignore these errors in ASD
case AS_COMMENT:
return su_ProcessComment( inEntry, inFile, ioSpec );
break;
case AS_ICONBW:
// return su_ProcessIconBW( inEntry, inFile, ioSpec );
break;
case AS_ICONCOLOR:
// return su_ProcessIconColor( inEntry, inFile, ioSpec );
break;
case AS_FILEDATES:
return su_ProcessFileDates( inEntry, inFile, ioSpec );
break;
case AS_FINDERINFO:
return su_ProcessFinderInfo( inEntry, inFile, ioSpec );
break;
case AS_MACINFO:
return su_ProcessMacInfo( inEntry, inFile, ioSpec );
break;
case AS_PRODOSINFO:
case AS_MSDOSINFO:
case AS_AFPNAME:
case AS_AFPINFO:
case AS_AFPDIRID:
default:
return 0;
}
return 0;
}
int
SU_DecodeAppleSingle(const char * inSrc, char ** dst)
{
XP_File inFile = NULL;
FSSpec outFileSpec;
size_t bytesRead;
ASHeader header;
OSErr err;
if ( (inSrc == NULL) || (dst == NULL))
return -1;
*dst = NULL;
XP_MEMSET(&outFileSpec, sizeof(outFileSpec), 0);
inFile = XP_FileOpen(inSrc, xpURL, XP_FILE_READ_BIN);
if (inFile == 0)
goto fail;
/* Header validity check */
{
bytesRead = XP_FileRead(&header, sizeof(ASHeader), inFile );
if ( bytesRead != sizeof(ASHeader))
goto fail;
if ( header.magicNum != 0x00051600 )
goto fail;
if ( header.versionNum != 0x00020000 )
goto fail;
if ( header.numEntries == 0 ) /* nothing in this file ? */
goto fail;
}
/* Create a new file spec, right next to the old file */
{
char * temp = WH_FileName( inSrc, xpURL );
if ( temp == NULL )
goto fail;
c2pstr( temp );
err = FSMakeFSSpec(0, 0, (unsigned char *) temp, &outFileSpec);
if ( err != noErr )
goto fail;
XP_FREE(temp);
err = CFileMgr::UniqueFileSpec( outFileSpec, "decode", outFileSpec);
if ( err != noErr )
goto fail;
err = FSpCreate( &outFileSpec, 'MOSS', '????', 0);
if ( err != noErr )
goto fail;
}
/* Loop through the entries, processing each */
/* Set the time/date stamps last, because otherwise they'll be destroyed
when we write */
{
Boolean hasDateEntry = FALSE;
ASEntry dateEntry;
for ( int i=0; i < header.numEntries; i++ )
{
ASEntry entry;
size_t offset = sizeof( ASHeader ) + sizeof( ASEntry ) * i;
if ( XP_FileSeek( inFile, offset, SEEK_SET ) != 0 )
goto fail;
if ( XP_FileRead( &entry, sizeof( entry ), inFile ) != sizeof( entry ))
goto fail;
if ( entry.entryID == AS_FILEDATES )
{
hasDateEntry = TRUE;
dateEntry = entry;
}
else
err = su_ProcessASEntry( entry, inFile, &outFileSpec );
if ( err != 0)
goto fail;
}
if ( hasDateEntry )
err = su_ProcessASEntry( dateEntry, inFile, &outFileSpec );
if ( err != 0)
goto fail;
}
/* Return the new file specs in xpURL form */
{
char * temp = CFileMgr::GetURLFromFileSpec(outFileSpec);
if ( temp == NULL )
goto fail;
*dst = XP_STRDUP(&temp[XP_STRLEN("file://")]);
XP_FREE(temp);
if (*dst == NULL)
goto fail;
}
XP_FileClose( inFile);
return 0;
fail:
if ( inFile )
XP_FileClose( inFile);
FSpDelete(&outFileSpec);
if (*dst)
XP_FREE( *dst);
*dst = NULL;
return -1;
}

Просмотреть файл

@ -0,0 +1,37 @@
/* -*- 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.
*/
/* su_aplsn.h */
/* SU_DecodeAppleSingle
* Decodes an AppleSingle disk file
* Arguments:
* src - file path in XP_FILE_URL_PATH format
* dst - returns the path of the extracted file. NULL if err
* Returns an error on failure
*/
#include "xp_core.h"
#define APPLESINGLE_MIME_TYPE "application/applefile"
XP_BEGIN_PROTOS
int SU_DecodeAppleSingle(const char * inSrc, char ** dst);
XP_END_PROTOS

Просмотреть файл

@ -0,0 +1,406 @@
/* -*- 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.
*/
/* su_trigger.c
* netscape.softupdate.FolderSpec.java
* native methods
* created by atotic, 1/6/97
*/
#include "xp_mcom.h"
#include "jri.h"
#include "su_folderspec.h"
/* #include "prthread.h" */
#include "fe_proto.h"
#include "xp_str.h"
#include "prefapi.h"
#include "proto.h"
#include "prthread.h"
#include "prprf.h"
#include "fe_proto.h"
#include "xpgetstr.h"
#define IMPLEMENT_netscape_softupdate_FolderSpec
#define IMPLEMENT_netscape_softupdate_SoftwareUpdate
#ifndef XP_MAC
#include "_jri/netscape_softupdate_FolderSpec.c"
#include "_jri/netscape_softupdate_SoftwareUpdate.h"
#else
#include "n_softupdate_FolderSpec.c"
#include "n_softupdate_SoftwareUpdate.h"
#endif
#ifndef MAX_PATH
#if defined(XP_WIN) || defined(XP_OS2)
#define MAX_PATH _MAX_PATH
#endif
#ifdef XP_UNIX
#ifdef NSPR20
#include "md/prosdep.h"
#else
#include "prosdep.h"
#endif
#if defined(HPUX) || defined(SCO)
/*
** HPUX: PATH_MAX is defined in <limits.h> to be 1023, but they
** recommend that it not be used, and that pathconf() be
** used to determine the maximum at runtime.
** SCO: This is what MAXPATHLEN is set to in <arpa/ftp.h> and
** NL_MAXPATHLEN in <nl_types.h>. PATH_MAX is defined in
** <limits.h> to be 256, but the comments in that file
** claim the setting is wrong.
*/
#define MAX_PATH 1024
#else
#define MAX_PATH PATH_MAX
#endif
#endif
#endif
extern int SU_INSTALL_ASK_FOR_DIRECTORY;
/* Standard Java initialization for native classes */
void
FolderSpecInitialize(JRIEnv * env)
{
use_netscape_softupdate_FolderSpec( env );
}
/* Makes sure that the path ends with a slash (or other platform end character)
* @return alloc'd new path that ends with a slash
*/
static char *
AppendSlashToDirPath(char * dirPath)
{
char pathSeparator; /* Gross, but harmless */
int32 newLen;
char * newPath;
#ifdef XP_WIN
pathSeparator = '\\';
#elif defined(XP_MAC)
pathSeparator = ':';
#else /* XP_UNIX */
pathSeparator = '/';
#endif
newLen = XP_STRLEN(dirPath) + 2;
newPath = (char*)XP_ALLOC(newLen);
if (newPath)
{
newPath[0] = 0;
XP_STRCAT(newPath, dirPath);
/* Append the slash if missing */
if (newPath[newLen - 3] != pathSeparator)
{
newPath[newLen - 2] = pathSeparator;
newPath[newLen - 1] = 0;
}
}
return newPath;
}
/* su_PickDirTimer
* keeps track of all SU specific data needed for the stream
*/
typedef struct su_PickDirTimer_struct {
MWContext * context;
char * fileName;
char * prompt;
XP_Bool done;
} su_PickDirTimer;
/* Callback for FE_PromptForFileName */
PR_STATIC_CALLBACK(void)
GetDirectoryPathCallbackFunction(MWContext *context,
char *file_name,
void *closure)
{
su_PickDirTimer *t = (su_PickDirTimer*)closure;
if (file_name)
{
char * newName = WH_FileName(file_name, xpURL);
if ( newName )
t->fileName = AppendSlashToDirPath(newName);
XP_FREEIF(newName);
XP_FREE(file_name);
}
t->done = TRUE;
}
/* Callback for the timer set by FE_SetTimer */
PR_STATIC_CALLBACK(void)
pickDirectoryCallback(void * a)
{
su_PickDirTimer *t = (su_PickDirTimer *)a;
int err;
err = FE_PromptForFileName (t->context, t->prompt, NULL, FALSE, TRUE,
GetDirectoryPathCallbackFunction, a );
if ( err != 0) /* callback will not run */
t->done = TRUE;
}
/* NativePickDefaultDirectory
* Asks the user where he'd like to install the package
*/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_FolderSpec_NativePickDefaultDirectory(
JRIEnv* env,
struct netscape_softupdate_FolderSpec* self)
{
struct java_lang_String * jPackageName, * newName= NULL;
su_PickDirTimer callback;
char * packageName;
char prompt[200];
callback.context = XP_FindSomeContext();
callback.fileName = NULL;
callback.done = FALSE;
/* Get the name of the package to prompt for */
jPackageName = get_netscape_softupdate_FolderSpec_userPackageName( env, self);
packageName = (char*)JRI_GetStringPlatformChars( env, jPackageName, "", 0 );
if (packageName)
{
/* In Java thread now, and need to call FE_PromptForFileName
* from the main thread
* post an event on a timer, and busy-wait until it completes.
*/
PR_snprintf(prompt, 200, XP_GetString(SU_INSTALL_ASK_FOR_DIRECTORY), packageName);
callback.prompt = prompt;
FE_SetTimeout( pickDirectoryCallback, &callback, 1 );
while (!callback.done) /* Busy loop for now */
PR_Yield(); /* java_lang_Thread_yield(WHAT?); */
}
if (callback.fileName != NULL)
{
newName = JRI_NewStringPlatform(env, callback.fileName, XP_STRLEN( callback.fileName), "", 0);
XP_FREE( callback.fileName);
}
return newName;
}
/*
*Directory manipulation
*/
/* Entry for the DirectoryTable[] */
struct su_DirectoryTable
{
char * directoryName; /* The formal directory name */
su_SecurityLevel securityLevel; /* Security level */
su_DirSpecID folderEnum; /* Directory ID */
};
/* DirectoryTable holds the info about build-in directories:
* Text name, security level, enum
*/
static struct su_DirectoryTable DirectoryTable[] =
{
{"Plugins", eAllFolderAccess, ePluginFolder},
{"Program", eAllFolderAccess, eProgramFolder},
{"Communicator", eAllFolderAccess, eCommunicatorFolder},
{"User Pick", eAllFolderAccess, ePackageFolder},
{"Temporary", eAllFolderAccess, eTemporaryFolder},
{"Installed", eAllFolderAccess, eInstalledFolder},
{"Current User", eAllFolderAccess, eCurrentUserFolder},
{"NetHelp", eAllFolderAccess, eNetHelpFolder},
{"OS Drive", eAllFolderAccess, eOSDriveFolder},
{"File URL", eAllFolderAccess, eFileURLFolder},
{"Netscape Java Bin", eAllFolderAccess, eJavaBinFolder},
{"Netscape Java Classes", eAllFolderAccess, eJavaClassesFolder},
{"Java Download", eOneFolderAccess, eJavaDownloadFolder},
{"Win System", eAllFolderAccess, eWin_SystemFolder},
{"Win System16", eAllFolderAccess, eWin_System16Folder},
{"Windows", eAllFolderAccess, eWin_WindowsFolder},
{"Mac System", eAllFolderAccess, eMac_SystemFolder},
{"Mac Desktop", eAllFolderAccess, eMac_DesktopFolder},
{"Mac Trash", eAllFolderAccess, eMac_TrashFolder},
{"Mac Startup", eAllFolderAccess, eMac_StartupFolder},
{"Mac Shutdown", eAllFolderAccess, eMac_ShutdownFolder},
{"Mac Apple Menu", eAllFolderAccess, eMac_AppleMenuFolder},
{"Mac Control Panel", eAllFolderAccess, eMac_ControlPanelFolder},
{"Mac Extension", eAllFolderAccess, eMac_ExtensionFolder},
{"Mac Fonts", eAllFolderAccess, eMac_FontsFolder},
{"Mac Preferences", eAllFolderAccess, eMac_PreferencesFolder},
{"Unix Local", eAllFolderAccess, eUnix_LocalFolder},
{"Unix Lib", eAllFolderAccess, eUnix_LibFolder},
{"", eAllFolderAccess, eBadFolder} /* Termination line */
};
/* MapNameToEnum
* maps name from the directory table to its enum */
static su_DirSpecID MapNameToEnum(const char * name)
{
int i = 0;
XP_ASSERT( name );
if ( name == NULL)
return eBadFolder;
while ( DirectoryTable[i].directoryName[0] != 0 )
{
if ( strcmp(name, DirectoryTable[i].directoryName) == 0 )
return DirectoryTable[i].folderEnum;
i++;
}
return eBadFolder;
}
/**
* GetNativePickPath -- return a native path equivalent of a XP path
*/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_FolderSpec_GetNativePath (JRIEnv* env,
struct netscape_softupdate_FolderSpec* self,
struct java_lang_String *a)
{
struct java_lang_String * nativePath = NULL;
char *xpPath, *p;
char pathSeparator;
#define XP_PATH_SEPARATOR '/'
#ifdef XP_WIN
pathSeparator = '\\';
#elif defined(XP_MAC)
pathSeparator = ':';
#else /* XP_UNIX */
pathSeparator = '/';
#endif
p = xpPath = (char *) JRI_GetStringUTFChars (env, a); /* UTF OK */
/*
* Traverse XP path and replace XP_PATH_SEPARATOR with
* the platform native equivalent
*/
if ( p == NULL )
{
xpPath = "";
}
else
{
while ( *p )
{
if ( *p == XP_PATH_SEPARATOR )
*p = pathSeparator;
++p;
}
}
nativePath = JRI_NewStringUTF(env, xpPath, XP_STRLEN( xpPath)); /* UTF OK */
return nativePath;
}
/*
* NativeGetDirectoryPath
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_FolderSpec_NativeGetDirectoryPath(JRIEnv* env,
struct netscape_softupdate_FolderSpec* self)
{
su_DirSpecID folderID;
char * folderName;
char * folderPath = NULL;
struct java_lang_String * jFolderName;
/* Get the name of the package to prompt for */
jFolderName = get_netscape_softupdate_FolderSpec_folderID( env, self);
folderName = (char*)JRI_GetStringUTFChars( env, jFolderName ); /* UTF OK */
folderID = MapNameToEnum(folderName);
switch (folderID)
{
case eBadFolder:
return netscape_softupdate_FolderSpec_INVALID_PATH_ERR;
case eCurrentUserFolder:
{
char dir[MAX_PATH];
int len = MAX_PATH;
if ( PREF_GetCharPref("profile.directory", dir, &len) == PREF_NOERROR)
{
char * platformDir = WH_FileName(dir, xpURL);
if (platformDir)
folderPath = AppendSlashToDirPath(platformDir);
XP_FREEIF(platformDir);
}
}
break;
default:
/* Get the FE path */
folderPath = FE_GetDirectoryPath( folderID);
break;
}
/* Store it in the object */
if (folderPath != NULL)
{
struct java_lang_String * jFolderPath;
jFolderPath = JRI_NewStringPlatform(env, folderPath, strlen( folderPath), "", 0);
if ( jFolderPath != NULL)
set_netscape_softupdate_FolderSpec_urlPath(env, self, jFolderPath);
XP_FREE(folderPath);
return 0;
}
return netscape_softupdate_FolderSpec_INVALID_PATH_ERR;
}
JRI_PUBLIC_API(jint)
native_netscape_softupdate_FolderSpec_GetSecurityTargetID(JRIEnv* env,
struct netscape_softupdate_FolderSpec* self)
{
su_DirSpecID folderID;
char * folderName;
struct java_lang_String * jFolderName;
/* Get the name of the package to prompt for */
jFolderName = get_netscape_softupdate_FolderSpec_folderID( env, self);
folderName = (char*)JRI_GetStringUTFChars( env, jFolderName ); /* UTF OK */
folderID = MapNameToEnum(folderName);
switch (DirectoryTable[folderID].securityLevel)
{
case eOneFolderAccess:
return netscape_softupdate_SoftwareUpdate_LIMITED_INSTALL;
case eAllFolderAccess:
return netscape_softupdate_SoftwareUpdate_FULL_INSTALL;
default:
return -1;
}
return -1;
}

Просмотреть файл

@ -0,0 +1,390 @@
/* -*- 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.
*/
/* su_instl.c
* netscape.softupdate.InstallFile.java
* native implementation
*/
/* The following two includes are unnecessary, but prevent
* IS_LITTLE_ENDIAN warnings */
#include "xp_mcom.h"
#include "jri.h"
#define IMPLEMENT_netscape_softupdate_InstallFile
#ifndef XP_MAC
#include "_jri/netscape_softupdate_InstallFile.c"
#else
#include "n_softupdate_InstallFile.c"
#endif
#define IMPLEMENT_netscape_softupdate_InstallExecute
#ifndef XP_MAC
#include "_jri/netscape_softupdate_InstallExecute.c"
#else
#include "n_softupdate_InstallExecute.c"
#endif
#define IMPLEMENT_netscape_softupdate_InstallPatch
#ifndef XP_MAC
#include "_jri/netscape_softupdate_InstallPatch.c"
#else
#include "n_softupdate_InstallPatch.c"
#endif
#define IMPLEMENT_netscape_softupdate_SoftUpdateException
#ifndef XP_MAC
#include "_jri/netscape_softupdate_SoftUpdateException.h"
#else
#include "n_s_SoftUpdateException.h"
#endif
#define IMPLEMENT_netscape_softupdate_Strings
#ifndef XP_MAC
#include "_jri/netscape_softupdate_Strings.h"
#else
#include "netscape_softupdate_Strings.h"
#endif
#ifdef XP_PC
#define IMPLEMENT_netscape_softupdate_SoftwareUpdate
#define IMPLEMENT_netscape_softupdate_InstallObject
#include "_jri/netscape_softupdate_SoftwareUpdate.h"
#include "_jri/netscape_softupdate_InstallObject.c"
#endif
#include "zig.h"
#include "xp_file.h"
#include "su_folderspec.h"
#include "su_instl.h"
#include "fe_proto.h"
extern int MK_OUT_OF_MEMORY;
static XP_Bool rebootShown = FALSE;
#ifdef XP_WIN16
static XP_Bool utilityScheduled = FALSE;
#endif
#ifdef NO_ERROR
#undef NO_ERROR
#endif
#define NO_ERROR 0
/* Standard Java initialization for native methods classes
*/
void InstallFileInitialize(JRIEnv * env)
{
use_netscape_softupdate_InstallFile( env );
use_netscape_softupdate_InstallExecute( env );
#ifdef XP_PC
use_netscape_softupdate_InstallObject( env );
#endif
}
/* NativeComplete
* copies the file to its final location
* Tricky, we need to create the directories
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_InstallFile_NativeComplete(JRIEnv* env,
struct netscape_softupdate_InstallFile* self)
{
char * currentName;
char * finalName = NULL;
char * finalNamePlatform;
struct java_lang_String * currentNameJava;
struct java_lang_String * finalNameJava;
int result;
/* Get the names */
currentNameJava = get_netscape_softupdate_InstallFile_tempFile( env, self);
currentName = (char*)JRI_GetStringPlatformChars( env, currentNameJava, "", 0);
finalNameJava = get_netscape_softupdate_InstallFile_finalFile( env, self);
finalNamePlatform = (char*)JRI_GetStringPlatformChars( env, finalNameJava, "", 0);
finalName = XP_PlatformFileToURL(finalNamePlatform);
if ( (currentName != NULL) &&
(finalName != NULL) &&
( XP_STRCMP(finalName, currentName) == 0))
return 0; /* No need to rename, they are the same */
if (finalName != NULL)
{
char * temp = XP_STRDUP(&finalName[7]);
XP_FREEIF(finalName);
finalName = temp;
if (finalName) {
XP_StatStruct s;
if ( XP_Stat( finalName, &s, xpURL ) != 0 ) {
/* Target file doesn't exist, try to rename file
*/
result = XP_FileRename(currentName, xpURL, finalName, xpURL);
}
else {
/* Target exists, can't trust XP_FileRename--do platform
* specific stuff in FE_ReplaceExistingFile()
*/
result = -1;
}
}
else
return -1;
}
else
return -1;
if (result != 0)
{
XP_StatStruct s;
if ( XP_Stat( finalName, &s, xpURL ) == 0 )
/* File already exists, need to remove the original */
{
XP_Bool force = get_netscape_softupdate_InstallFile_force(env, self);
result = FE_ReplaceExistingFile(currentName, xpURL, finalName, xpURL, force);
if ( result == REBOOT_NEEDED ) {
#ifdef XP_WIN16
if (!utilityScheduled) {
utilityScheduled = TRUE;
FE_ScheduleRenameUtility();
}
#endif
}
}
else
/* Directory might not exist, check and create if necessary */
{
char separator;
char * end;
separator = '/';
end = XP_STRRCHR(finalName, separator);
if (end)
{
end[0] = 0;
result = XP_MakeDirectoryR( finalName, xpURL);
end[0] = separator;
if ( 0 == result )
result = XP_FileRename(currentName, xpURL, finalName, xpURL);
}
}
#ifdef XP_UNIX
/* Last try, can't rename() across file systems on UNIX */
if ( -1 == result )
{
result = FE_CopyFile(currentName, finalName);
}
#endif
}
XP_FREEIF(finalName);
return result;
}
/* Removes the temporary file */
JRI_PUBLIC_API(void)
native_netscape_softupdate_InstallFile_NativeAbort(JRIEnv* env,
struct netscape_softupdate_InstallFile* self)
{
char * currentName;
struct java_lang_String * currentNameJava;
int result;
/* Get the names */
currentNameJava = get_netscape_softupdate_InstallFile_tempFile( env, self);
currentName = (char*)JRI_GetStringPlatformChars( env, currentNameJava, "", 0);
result = XP_FileRemove(currentName, xpURL);
XP_ASSERT(result == 0);
}
/*---------------------------------------
*
* InstallExecute native methods
*
*---------------------------------------*/
/* Executes the extracted binary
*/
JRI_PUBLIC_API(void)
native_netscape_softupdate_InstallExecute_NativeComplete(JRIEnv* env,
struct netscape_softupdate_InstallExecute* self)
{
char * cmdline;
char * filename;
int32 err;
filename = (char*)JRI_GetStringPlatformChars(
env,
get_netscape_softupdate_InstallExecute_tempFile( env, self ),
"",
0 );
cmdline = (char*)JRI_GetStringPlatformChars(
env,
get_netscape_softupdate_InstallExecute_cmdline( env, self ),
"",
0 );
err = FE_ExecuteFile( filename, cmdline );
XP_ASSERT( err == 0 );
if ( err != 0 )
{
struct netscape_softupdate_SoftUpdateException* e;
struct java_lang_String * errStr;
errStr = netscape_softupdate_Strings_error_0005fUnexpected(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
err);
return;
}
}
/* Removes the temporary file */
JRI_PUBLIC_API(void)
native_netscape_softupdate_InstallExecute_NativeAbort(JRIEnv* env,
struct netscape_softupdate_InstallExecute* self)
{
char * currentName;
struct java_lang_String * currentNameJava;
int result;
/* Get the names */
currentNameJava = get_netscape_softupdate_InstallExecute_tempFile(env,self);
currentName = (char*)JRI_GetStringPlatformChars(env, currentNameJava,"",0);
result = XP_FileRemove(currentName, xpURL);
XP_ASSERT(result == 0);
}
/*---------------------------------------
*
* InstallPatch native methods
*
*---------------------------------------*/
/*** private native NativePatch (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; ***/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_InstallPatch_NativePatch(JRIEnv* env,
struct netscape_softupdate_InstallPatch* self,
struct java_lang_String *jSrcFile,
struct java_lang_String *jDiffURL)
{
return NULL;
}
/*** private native NativeReplace (Ljava/lang/String;Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_InstallPatch_NativeReplace(JRIEnv* env,
struct netscape_softupdate_InstallPatch* self,
struct java_lang_String *jTargetfile,
struct java_lang_String *jNewfile)
{
char * targetfile = NULL;
char * newfile = NULL;
char * targetURL = NULL;
char * newURL = NULL;
char * pTarget;
char * pNew;
int err = SU_SUCCESS;
targetfile = (char*)JRI_GetStringPlatformChars( env, jTargetfile, "", 0 );
newfile = (char*)JRI_GetStringPlatformChars( env, jNewfile, "", 0 );
if ( targetfile != NULL && newfile != NULL )
{
targetURL = XP_PlatformFileToURL( targetfile );
newURL = XP_PlatformFileToURL( newfile );
if ( targetURL != NULL && newURL != NULL )
{
XP_StatStruct st;
pTarget = targetURL+7;
pNew = newURL+7;
if ( XP_Stat( pTarget, &st, xpURL ) == SU_SUCCESS ) {
/* file still exists */
err = FE_ReplaceExistingFile( pNew, xpURL, pTarget, xpURL, 0 );
#ifdef XP_WIN16
if ( err == REBOOT_NEEDED && !utilityScheduled) {
utilityScheduled = TRUE;
FE_ScheduleRenameUtility();
}
#endif
}
else {
/* someone got rid of the target file? */
/* can do simple rename, but assert */
err = XP_FileRename( pNew, xpURL, pTarget, xpURL );
XP_ASSERT( err == SU_SUCCESS );
XP_ASSERT(0);
}
}
else {
err = -1;
}
}
else {
err = -1;
}
XP_FREEIF( targetURL );
XP_FREEIF( newURL );
return (err);
}
/*** private native NativeDeleteFile (Ljava/lang/String;)V ***/
JRI_PUBLIC_API(void)
native_netscape_softupdate_InstallPatch_NativeDeleteFile(JRIEnv* env,
struct netscape_softupdate_InstallPatch* self,
struct java_lang_String *jFilename)
{
char * filename = NULL;
char * fnameURL = NULL;
filename = (char*)JRI_GetStringPlatformChars( env, jFilename, "", 0 );
XP_ASSERT( filename );
if ( filename != NULL ) {
fnameURL = XP_PlatformFileToURL( filename );
XP_ASSERT( fnameURL );
XP_FileRemove( fnameURL+7, xpURL );
}
if ( fnameURL != NULL )
XP_FREE( fnameURL );
}

Просмотреть файл

@ -0,0 +1,44 @@
/* -*- 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.
*/
/* su_instl.h
*
* created by atotic, 1/22/97
*/
#include "xp_mcom.h"
#define REBOOT_NEEDED 999
#define SU_SUCCESS 0
XP_BEGIN_PROTOS
/* Immediately executes the file
* returns errors if encountered
*/
int FE_ExecuteFile( const char * filename, const char * cmdline );
#ifdef XP_PC
void PR_CALLBACK SU_AlertCallback(void *dummy);
void FE_ScheduleRenameUtility(void);
#endif
#ifdef XP_UNIX
int FE_CopyFile (const char *in, const char *out);
#endif
XP_END_PROTOS

Просмотреть файл

@ -0,0 +1,257 @@
/* -*- Mode: C++; tab-width: 4; tabs-indent-mode: nil -*-
* 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.
*/
/* su_mac.c
* Mac specific softupdate routines
*/
#include "xp_mcom.h"
#include "su_instl.h"
#include "su_folderspec.h"
#include "xp_str.h"
#include "net.h"
#include <Folders.h>
// MacFE
#include "ufilemgr.h"
#include "uprefd.h"
#include "macutil.h"
#include "macfeprefs.h"
/* Given a system folder enum, returns a full path, in the URL form */
char * GetDirectoryPathFromSystemEnum(OSType folder)
{
OSErr err;
short vRefNum;
long dirID;
FSSpec folderSpec;
err = FindFolder(kOnSystemDisk,folder,true,&vRefNum,&dirID);
if (err != noErr)
return NULL;
err = CFileMgr::FolderSpecFromFolderID( vRefNum, dirID, folderSpec);
if (err != noErr)
return NULL;
return CFileMgr::PathNameFromFSSpec(folderSpec, true);
}
extern OSErr FindNetscapeFolder(FSSpec* outSpec);
extern OSErr FindPluginFolder(FSSpec * spec, Boolean create);
extern "C" OSErr ConvertUnixPathToMacPath(const char *, char **);
/* Returns the URL format folder path */
#ifdef XP_MAC
#pragma export on
#endif
char * FE_GetDirectoryPath( su_DirSpecID folderID)
{
char * path = NULL;
OSErr err;
switch( folderID)
{
case ePluginFolder:
{
FSSpec spec;
if ( FindPluginFolder(&spec, true) != noErr )
return NULL;
path = CFileMgr::PathNameFromFSSpec(spec, true);
}
break;
case eProgramFolder:
case eCommunicatorFolder:
{
FSSpec spec= CPrefs::GetFolderSpec(CPrefs::NetscapeFolder);
path = CFileMgr::PathNameFromFSSpec(spec, true);
}
break;
case ePackageFolder:
path = NULL;
case eTemporaryFolder:
path = GetDirectoryPathFromSystemEnum(kTemporaryFolderType);
break;
case eMac_SystemFolder:
path = GetDirectoryPathFromSystemEnum(kSystemFolderType);
break;
case eMac_DesktopFolder:
path = GetDirectoryPathFromSystemEnum(kDesktopFolderType);
break;
case eMac_TrashFolder:
path = GetDirectoryPathFromSystemEnum(kTrashFolderType);
break;
case eMac_StartupFolder:
path = GetDirectoryPathFromSystemEnum(kStartupFolderType);
break;
case eMac_ShutdownFolder:
path = GetDirectoryPathFromSystemEnum(kShutdownFolderType);
break;
case eMac_AppleMenuFolder:
path = GetDirectoryPathFromSystemEnum(kAppleMenuFolderType);
break;
case eMac_ControlPanelFolder:
path = GetDirectoryPathFromSystemEnum(kControlPanelFolderType);
break;
case eMac_ExtensionFolder:
path = GetDirectoryPathFromSystemEnum(kExtensionFolderType);
break;
case eMac_FontsFolder:
path = GetDirectoryPathFromSystemEnum(kFontsFolderType);
break;
case eMac_PreferencesFolder:
path = GetDirectoryPathFromSystemEnum(kPreferencesFolderType);
break;
case eJavaBinFolder:
err = ConvertUnixPathToMacPath("/usr/local/netscape/RequiredGuts/Java/Bin", &path);
if (err != noErr)
path = NULL;
break;
case eJavaClassesFolder:
err = ConvertUnixPathToMacPath("/usr/local/netscape/RequiredGuts/Java/Lib", &path);
if (err != noErr)
path = NULL;
break;
case eJavaDownloadFolder:
{
FSSpec spec;
if ( FindJavaDownloadsFolder(&spec) != noErr )
return NULL;
path = CFileMgr::PathNameFromFSSpec(spec, true);
}
break;
// Directories that do not make sense on the Mac
case eWin_SystemFolder:
case eWin_WindowsFolder:
case eNetHelpFolder:
case eOSDriveFolder:
case eFileURLFolder:
path = NULL;
default:
XP_ASSERT(false);
path = NULL;
}
if (path) // Unescape the path, because we'll be passing it to XP_FileOpen as xpURL
{
NET_UnEscape(path);
if (path[XP_STRLEN(path) - 1] != ':') // Append the ending slash if it is not there
{
char * newPath = (char*)XP_ALLOC(XP_STRLEN(path) + 2);
if (newPath)
{
newPath[0] = 0;
XP_STRCAT(newPath, path);
XP_STRCAT(newPath, ":");
}
XP_FREE(path);
path = newPath;
}
}
return path;
}
#ifdef XP_MAC
#pragma export reset
#endif
int FE_ExecuteFile( const char * fileName, const char * cmdline )
{
OSErr err;
FSSpec appSpec;
if ( fileName == NULL )
return -1;
try
{
err = CFileMgr::FSSpecFromLocalUnixPath(fileName, &appSpec, true);
ThrowIfOSErr_(err);
LaunchParamBlockRec launchThis;
launchThis.launchAppSpec = (FSSpecPtr)&appSpec;
launchThis.launchAppParameters = NULL;
/* launch the thing */
launchThis.launchBlockID = extendedBlock;
launchThis.launchEPBLength = extendedBlockLen;
launchThis.launchFileFlags = NULL;
launchThis.launchControlFlags = launchContinue + launchNoFileFlags + launchUseMinimum;
if (!IsFrontApplication())
launchThis.launchControlFlags += launchDontSwitch;
err = LaunchApplication(&launchThis);
ThrowIfOSErr_(err);
}
catch (OSErr err)
{
return -1;
}
return 0;
}
/* Mac technique for replacing the file 'in use'
* Move the file in use to Trash, and copy the new one
*/
int FE_ReplaceExistingFile(char *from, XP_FileType ftype,
char *to, XP_FileType totype,
XP_Bool /* force */) /* We ignore force because we do not check versions */
{
int result;
OSErr err;
FSSpec fileSpec;
short vRefNum;
long dirID;
result = XP_FileRemove( to, totype );
if ( 0 == result )
{
result = XP_FileRename(from, ftype, to, totype);
}
else {
err = CFileMgr::FSSpecFromLocalUnixPath(to, &fileSpec, true);
if (err != noErr)
return -1;
err = FindFolder(fileSpec.vRefNum, kTrashFolderType, true, &vRefNum, &dirID);
if (err != noErr)
return -1;
CMovePBRec pb;
pb.ioCompletion = NULL;
pb.ioNamePtr = (StringPtr)&fileSpec.name;
pb.ioDirID = fileSpec.parID;
pb.ioVRefNum = vRefNum;
pb.ioNewName = NULL;
pb.ioNewDirID = dirID;
err = PBCatMoveSync(&pb);
if ( err != noErr)
return -1;
result = XP_FileRename(from, ftype, to, totype);
}
return result;
}
extern "C" int DiskSpaceAvailable(char *fileSystem, int nBytes);
int DiskSpaceAvailable(char *fileSystem, int nBytes)
{
return nBytes>=0;
}

Просмотреть файл

@ -0,0 +1,136 @@
/* -*- 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 "prtypes.h"
#include "prlink.h"
extern void Java_netscape_softupdate_FolderSpec_GetNativePath_stub();
extern void Java_netscape_softupdate_FolderSpec_GetSecurityTargetID_stub();
extern void Java_netscape_softupdate_FolderSpec_NativeGetDirectoryPath_stub();
extern void Java_netscape_softupdate_FolderSpec_NativePickDefaultDirectory_stub();
extern void Java_netscape_softupdate_InstallExecute_NativeComplete_stub();
extern void Java_netscape_softupdate_InstallFile_NativeComplete_stub();
extern void Java_netscape_softupdate_RegEntryEnumerator_regNext_stub();
extern void Java_netscape_softupdate_RegKeyEnumerator_regNext_stub();
extern void Java_netscape_softupdate_RegistryNode_nDeleteEntry_stub();
extern void Java_netscape_softupdate_RegistryNode_nGetEntryType_stub();
extern void Java_netscape_softupdate_RegistryNode_nGetEntry_stub();
extern void Java_netscape_softupdate_RegistryNode_setEntryB_stub();
extern void Java_netscape_softupdate_RegistryNode_setEntryI_stub();
extern void Java_netscape_softupdate_RegistryNode_setEntryS_stub();
extern void Java_netscape_softupdate_Registry_nAddKey_stub();
extern void Java_netscape_softupdate_Registry_nClose_stub();
extern void Java_netscape_softupdate_Registry_nDeleteKey_stub();
extern void Java_netscape_softupdate_Registry_nGetKey_stub();
extern void Java_netscape_softupdate_Registry_nOpen_stub();
extern void Java_netscape_softupdate_Registry_nUserName_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_CloseJARFile_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_NativeExtractJARFile_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_OpenJARFile_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_VerifyJSObject_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_getCertificates_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_NativeGestalt_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_NativeDeleteFile_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_NativeVerifyDiskspace_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_NativeMakeDirectory_stub();
extern void Java_netscape_softupdate_SoftwareUpdate_ExtractDirEntries_stub();
extern void Java_netscape_softupdate_Trigger_StartSoftwareUpdate_stub();
extern void Java_netscape_softupdate_Trigger_UpdateEnabled_stub();
extern void Java_netscape_softupdate_VerRegEnumerator_regNext_stub();
extern void Java_netscape_softupdate_VersionRegistry_close_stub();
extern void Java_netscape_softupdate_VersionRegistry_componentPath_stub();
extern void Java_netscape_softupdate_VersionRegistry_componentVersion_stub();
extern void Java_netscape_softupdate_VersionRegistry_deleteComponent_stub();
extern void Java_netscape_softupdate_VersionRegistry_getDefaultDirectory_stub();
extern void Java_netscape_softupdate_VersionRegistry_inRegistry_stub();
extern void Java_netscape_softupdate_VersionRegistry_installComponent_stub();
extern void Java_netscape_softupdate_VersionRegistry_setDefaultDirectory_stub();
extern void Java_netscape_softupdate_VersionRegistry_validateComponent_stub();
extern void Java_netscape_softupdate_InstallExecute_NativeAbort_stub();
extern void Java_netscape_softupdate_InstallFile_NativeAbort_stub();
#ifdef XP_PC
extern void Java_netscape_softupdate_WinProfile_nativeWriteString_stub();
extern void Java_netscape_softupdate_WinProfile_nativeGetString_stub();
extern void Java_netscape_softupdate_WinReg_nativeCreateKey_stub();
extern void Java_netscape_softupdate_WinReg_nativeDeleteKey_stub();
extern void Java_netscape_softupdate_WinReg_nativeDeleteValue_stub();
extern void Java_netscape_softupdate_WinReg_nativeSetValueString_stub();
extern void Java_netscape_softupdate_WinReg_nativeGetValueString_stub();
extern void Java_netscape_softupdate_WinReg_nativeSetValue_stub();
extern void Java_netscape_softupdate_WinReg_nativeGetValue_stub();
#endif
PRStaticLinkTable su_nodl_tab[] = {
{ "Java_netscape_softupdate_FolderSpec_GetNativePath_stub", Java_netscape_softupdate_FolderSpec_GetNativePath_stub },
{ "Java_netscape_softupdate_FolderSpec_GetSecurityTargetID_stub", Java_netscape_softupdate_FolderSpec_GetSecurityTargetID_stub },
{ "Java_netscape_softupdate_FolderSpec_NativeGetDirectoryPath_stub", Java_netscape_softupdate_FolderSpec_NativeGetDirectoryPath_stub },
{ "Java_netscape_softupdate_FolderSpec_NativePickDefaultDirectory_stub", Java_netscape_softupdate_FolderSpec_NativePickDefaultDirectory_stub },
{ "Java_netscape_softupdate_InstallExecute_NativeComplete_stub", Java_netscape_softupdate_InstallExecute_NativeComplete_stub },
{ "Java_netscape_softupdate_InstallFile_NativeComplete_stub", Java_netscape_softupdate_InstallFile_NativeComplete_stub },
{ "Java_netscape_softupdate_RegEntryEnumerator_regNext_stub", Java_netscape_softupdate_RegEntryEnumerator_regNext_stub },
{ "Java_netscape_softupdate_RegKeyEnumerator_regNext_stub", Java_netscape_softupdate_RegKeyEnumerator_regNext_stub },
{ "Java_netscape_softupdate_RegistryNode_nDeleteEntry_stub", Java_netscape_softupdate_RegistryNode_nDeleteEntry_stub },
{ "Java_netscape_softupdate_RegistryNode_nGetEntryType_stub", Java_netscape_softupdate_RegistryNode_nGetEntryType_stub },
{ "Java_netscape_softupdate_RegistryNode_nGetEntry_stub", Java_netscape_softupdate_RegistryNode_nGetEntry_stub },
{ "Java_netscape_softupdate_RegistryNode_setEntryB_stub", Java_netscape_softupdate_RegistryNode_setEntryB_stub },
{ "Java_netscape_softupdate_RegistryNode_setEntryI_stub", Java_netscape_softupdate_RegistryNode_setEntryI_stub },
{ "Java_netscape_softupdate_RegistryNode_setEntryS_stub", Java_netscape_softupdate_RegistryNode_setEntryS_stub },
{ "Java_netscape_softupdate_Registry_nAddKey_stub", Java_netscape_softupdate_Registry_nAddKey_stub },
{ "Java_netscape_softupdate_Registry_nClose_stub", Java_netscape_softupdate_Registry_nClose_stub },
{ "Java_netscape_softupdate_Registry_nDeleteKey_stub", Java_netscape_softupdate_Registry_nDeleteKey_stub },
{ "Java_netscape_softupdate_Registry_nGetKey_stub", Java_netscape_softupdate_Registry_nGetKey_stub },
{ "Java_netscape_softupdate_Registry_nOpen_stub", Java_netscape_softupdate_Registry_nOpen_stub },
{ "Java_netscape_softupdate_Registry_nUserName_stub", Java_netscape_softupdate_Registry_nUserName_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_CloseJARFile_stub", Java_netscape_softupdate_SoftwareUpdate_CloseJARFile_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_NativeExtractJARFile_stub", Java_netscape_softupdate_SoftwareUpdate_NativeExtractJARFile_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_OpenJARFile_stub", Java_netscape_softupdate_SoftwareUpdate_OpenJARFile_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_VerifyJSObject_stub", Java_netscape_softupdate_SoftwareUpdate_VerifyJSObject_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_getCertificates_stub", Java_netscape_softupdate_SoftwareUpdate_getCertificates_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_NativeGestalt_stub", Java_netscape_softupdate_SoftwareUpdate_NativeGestalt_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_NativeDeleteFile_stub", Java_netscape_softupdate_SoftwareUpdate_NativeDeleteFile_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_NativeVerifyDiskspace_stub", Java_netscape_softupdate_SoftwareUpdate_NativeVerifyDiskspace_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_NativeMakeDirectory_stub", Java_netscape_softupdate_SoftwareUpdate_NativeMakeDirectory_stub },
{ "Java_netscape_softupdate_SoftwareUpdate_ExtractDirEntries_stub", Java_netscape_softupdate_SoftwareUpdate_ExtractDirEntries_stub },
{ "Java_netscape_softupdate_Trigger_StartSoftwareUpdate_stub", Java_netscape_softupdate_Trigger_StartSoftwareUpdate_stub },
{ "Java_netscape_softupdate_Trigger_UpdateEnabled_stub", Java_netscape_softupdate_Trigger_UpdateEnabled_stub },
{ "Java_netscape_softupdate_VerRegEnumerator_regNext_stub", Java_netscape_softupdate_VerRegEnumerator_regNext_stub },
{ "Java_netscape_softupdate_VersionRegistry_close_stub", Java_netscape_softupdate_VersionRegistry_close_stub },
{ "Java_netscape_softupdate_VersionRegistry_componentPath_stub", Java_netscape_softupdate_VersionRegistry_componentPath_stub },
{ "Java_netscape_softupdate_VersionRegistry_componentVersion_stub", Java_netscape_softupdate_VersionRegistry_componentVersion_stub },
{ "Java_netscape_softupdate_VersionRegistry_deleteComponent_stub", Java_netscape_softupdate_VersionRegistry_deleteComponent_stub },
{ "Java_netscape_softupdate_VersionRegistry_getDefaultDirectory_stub", Java_netscape_softupdate_VersionRegistry_getDefaultDirectory_stub },
{ "Java_netscape_softupdate_VersionRegistry_inRegistry_stub", Java_netscape_softupdate_VersionRegistry_inRegistry_stub },
{ "Java_netscape_softupdate_VersionRegistry_installComponent_stub", Java_netscape_softupdate_VersionRegistry_installComponent_stub },
{ "Java_netscape_softupdate_VersionRegistry_setDefaultDirectory_stub", Java_netscape_softupdate_VersionRegistry_setDefaultDirectory_stub },
{ "Java_netscape_softupdate_VersionRegistry_validateComponent_stub", Java_netscape_softupdate_VersionRegistry_validateComponent_stub },
{ "Java_netscape_softupdate_InstallExecute_NativeAbort_stub", Java_netscape_softupdate_InstallExecute_NativeAbort_stub },
{ "Java_netscape_softupdate_InstallFile_NativeAbort_stub", Java_netscape_softupdate_InstallFile_NativeAbort_stub },
#ifdef XP_PC
{ "Java_netscape_softupdate_WinProfile_nativeWriteString_stub", Java_netscape_softupdate_WinProfile_nativeWriteString_stub },
{ "Java_netscape_softupdate_WinProfile_nativeGetString_stub", Java_netscape_softupdate_WinProfile_nativeGetString_stub },
{ "Java_netscape_softupdate_WinReg_nativeCreateKey_stub", Java_netscape_softupdate_WinReg_nativeCreateKey_stub },
{ "Java_netscape_softupdate_WinReg_nativeDeleteKey_stub", Java_netscape_softupdate_WinReg_nativeDeleteKey_stub },
{ "Java_netscape_softupdate_WinReg_nativeDeleteValue_stub", Java_netscape_softupdate_WinReg_nativeDeleteValue_stub },
{ "Java_netscape_softupdate_WinReg_nativeSetValueString_stub", Java_netscape_softupdate_WinReg_nativeSetValueString_stub },
{ "Java_netscape_softupdate_WinReg_nativeGetValueString_stub", Java_netscape_softupdate_WinReg_nativeGetValueString_stub },
{ "Java_netscape_softupdate_WinReg_nativeSetValue_stub", Java_netscape_softupdate_WinReg_nativeSetValue_stub },
{ "Java_netscape_softupdate_WinReg_nativeGetValue_stub", Java_netscape_softupdate_WinReg_nativeGetValue_stub },
#endif
{ 0, 0, },
};

Просмотреть файл

@ -0,0 +1,605 @@
/* -*- 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.
*/
/* su_trigger.c
* netscape.softupdate.Trigger.java
* native implementation
*/
#define IMPLEMENT_netscape_softupdate_Trigger
#ifndef XP_MAC
#include "_jri/netscape_softupdate_Trigger.c"
#else
#include "netscape_softupdate_Trigger.c"
#endif
#define IMPLEMENT_netscape_softupdate_SoftUpdateException
#ifndef XP_MAC
#include "_jri/netscape_softupdate_SoftUpdateException.c"
#else
#include "n_s_SoftUpdateException.c"
#endif
#define IMPLEMENT_netscape_softupdate_SoftwareUpdate
#ifndef XP_MAC
#include "_jri/netscape_softupdate_SoftwareUpdate.c"
#else
#include "n_softupdate_SoftwareUpdate.c"
#endif
#define IMPLEMENT_netscape_javascript_JSObject /* Only needed because we are calling privates */
#ifndef XP_MAC
#include "netscape_javascript_JSObject.h"
#else
#include "netscape_javascript_JSObject.h"
#endif
#ifndef XP_MAC
#include "_jri/netscape_softupdate_Strings.c"
#else
#include "netscape_softupdate_Strings.c"
#endif
#include "softupdt.h"
#include "zig.h"
#include "prefapi.h"
#include "su_aplsn.h"
#include "proto.h"
#include "jsapi.h"
#include "xp_error.h"
#include "jsjava.h"
extern void FolderSpecInitialize(JRIEnv * env);
extern void InstallFileInitialize(JRIEnv * env);
extern void SUWinSpecificInit( JRIEnv *env );
extern int DiskSpaceAvailable( char *path, int nBytes );
#ifdef XP_MAC
#pragma export on
#endif
void SU_Initialize(JRIEnv * env)
{
use_netscape_softupdate_Trigger( env );
use_netscape_softupdate_SoftwareUpdate( env );
use_netscape_softupdate_Strings( env );
use_netscape_softupdate_SoftUpdateException( env );
FolderSpecInitialize(env);
InstallFileInitialize(env);
#if defined(XP_PC)
SUWinSpecificInit( env );
#endif
}
#ifdef XP_MAC
#pragma export reset
#endif
JRI_PUBLIC_API(jbool)
native_netscape_softupdate_Trigger_UpdateEnabled(
JRIEnv* env,
struct java_lang_Class* clazz)
{
XP_Bool enabled;
PREF_GetBoolPref( AUTOUPDATE_ENABLE_PREF, &enabled);
if (enabled)
return JRITrue;
else
return JRIFalse;
}
JRI_PUBLIC_API(jbool)
native_netscape_softupdate_Trigger_StartSoftwareUpdate(JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String *jurl,
jint flags)
{
char * url = NULL;
url = (char*)JRI_GetStringPlatformChars( env, jurl, "", 0 );
if (url != NULL)
{
/* This is a potential problem */
/* We are grabbing any context, but we really need ours */
/* The problem is that Java does not have access to MWContext */
MWContext * cx;
cx = XP_FindSomeContext();
if (cx)
return SU_StartSoftwareUpdate(cx, url, NULL, NULL, NULL, flags);
else
return FALSE;
}
return FALSE;
}
extern int MK_OUT_OF_MEMORY;
extern JSClass lm_softup_class;
/*** private native VerifyJSObject ()V ***/
/* Check out Java declaration for docs */
JRI_PUBLIC_API(void)
native_netscape_softupdate_SoftwareUpdate_VerifyJSObject(JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
struct netscape_javascript_JSObject *a)
{
/*
Get the object's class, and verify that it is of class SoftUpdate
*/
JSObject * jsobj;
JSClass * jsclass;
jsobj = JSJ_ExtractInternalJSObject(env, (HObject*)a);
jsclass = JS_GetClass(jsobj);
if ( jsclass != &lm_softup_class )
{
struct netscape_softupdate_SoftUpdateException* e;
struct java_lang_String * errStr;
errStr = netscape_softupdate_Strings_error_0005fBadJSArgument(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
-1);
JRI_Throw(env, (struct java_lang_Throwable *)e);
return;
}
}
/*** private native OpenJARFile ()V ***/
JRI_PUBLIC_API(void)
native_netscape_softupdate_SoftwareUpdate_OpenJARFile(JRIEnv* env, struct netscape_softupdate_SoftwareUpdate* self)
{
ZIG * jarData;
char * jarFile;
struct java_lang_String * jjarFile;
int err;
struct java_lang_String * errStr;
struct netscape_softupdate_SoftUpdateException* e;
XP_Bool enabled;
PREF_GetBoolPref( AUTOUPDATE_ENABLE_PREF, &enabled);
if (!enabled)
{
errStr = netscape_softupdate_Strings_error_0005fSmartUpdateDisabled(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
-1);
JRI_Throw(env, (struct java_lang_Throwable *)e);
return;
}
jjarFile = get_netscape_softupdate_SoftwareUpdate_jarName( env, self);
jarFile = (char*)JRI_GetStringPlatformChars( env, jjarFile, "", 0 );
if (jarFile == NULL) return; /* error already signaled */
/* Open and initialize the JAR archive */
jarData = SOB_new();
if ( jarData == NULL )
{
errStr = netscape_softupdate_Strings_error_0005fUnexpected(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
-1);
JRI_Throw(env, (struct java_lang_Throwable *)e);
return;
}
err = SOB_pass_archive( ZIG_F_GUESS,
jarFile,
NULL, /* realStream->fURL->address, */
jarData);
if ( err != 0 )
{
errStr = netscape_softupdate_Strings_error_0005fVerificationFailed(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
err);
JRI_Throw(env, (struct java_lang_Throwable *)e);
return;
}
/* Get the installer file name */
{
char * installerJarName = NULL;
unsigned long fileNameLength;
err = SOB_get_metainfo( jarData, NULL, INSTALLER_HEADER, (void**)&installerJarName, &fileNameLength);
if (err != 0)
{
errStr = netscape_softupdate_Strings_error_0005fMissingInstaller(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
err);
JRI_Throw(env, (struct java_lang_Throwable *)e);
return;
}
set_netscape_softupdate_SoftwareUpdate_installerJarName(env, self,
JRI_NewStringPlatform(env, installerJarName, fileNameLength, "", 0));
}
set_netscape_softupdate_SoftwareUpdate_zigPtr(env, self, (long)jarData);
}
/*** private native CloseJARFile ()V ***/
extern JRI_PUBLIC_API(void)
native_netscape_softupdate_SoftwareUpdate_CloseJARFile(JRIEnv* env, struct netscape_softupdate_SoftwareUpdate* self)
{
ZIG * jarData;
jarData = (ZIG*)get_netscape_softupdate_SoftwareUpdate_zigPtr(env, self);
if (jarData != NULL)
SOB_destroy( jarData);
set_netscape_softupdate_SoftwareUpdate_zigPtr(env, self, 0);
}
#define APPLESINGLE_MAGIC_HACK 1 /* Hack to automatically detect applesingle files until we get tdell to do the right thing */
/* Extracts a JAR target into the directory */
/* Always decodes AppleSingle files */
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_SoftwareUpdate_NativeExtractJARFile(JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
struct java_lang_String *jJarSource,
struct java_lang_String *finalFile)
{
char * tempName = NULL;
char * target = NULL;
struct java_lang_String * tempNameJava = NULL;
int result;
target = (char*)JRI_GetStringPlatformChars( env, finalFile, "", 0 );
if (target)
{
char *fn;
char *end;
char *URLfile = XP_PlatformFileToURL(target);
fn = URLfile+7; /* skip "file://" part */
if ( end = XP_STRRCHR(fn, '/') )
end[1] = 0;
/* Create a temporary location */
tempName = WH_TempName( xpURL, fn );
XP_FREEIF(URLfile);
}
else
tempName = WH_TempName( xpURL, NULL );
if (tempName == NULL)
{
result = MK_OUT_OF_MEMORY;
goto done;
}
{
ZIG * jar;
char * jarPath;
/* Extract the file */
jar = (ZIG *)get_netscape_softupdate_SoftwareUpdate_zigPtr(env, self);
jarPath = (char*)JRI_GetStringPlatformChars( env, jJarSource, "", 0 );
if (jarPath == NULL) {
/* out-of-memory error already signaled */
free(tempName);
return NULL;
}
result = SOB_verified_extract( jar, jarPath, tempName);
if ( result == 0 )
{
/* If we have an applesingle file
decode it to a new file
*/
char * encodingName;
unsigned long encodingNameLength;
XP_Bool isApplesingle = FALSE;
result = SOB_get_metainfo( jar, NULL, CONTENT_ENCODING_HEADER, (void**)&encodingName, &encodingNameLength);
#ifdef APPLESINGLE_MAGIC_HACK
if (result != 0)
{
XP_File f;
uint32 magic;
f = XP_FileOpen(tempName, xpURL, XP_FILE_READ_BIN);
XP_FileRead( &magic, sizeof(magic), f);
XP_FileClose(f);
isApplesingle = (magic == 0x00051600 );
result = 0;
}
#else
isApplesingle = (( result == 0 ) &&
(XP_STRNCMP(APPLESINGLE_MIME_TYPE, encodingName, XP_STRLEN( APPLESINGLE_MIME_TYPE ) == 0)));
#endif
if ( isApplesingle )
/* We have an AppleSingle file */
/* Extract it to the new AppleFile, and get the URL back */
{
char * newTempName = NULL;
#ifdef XP_MAC
result = SU_DecodeAppleSingle(tempName, &newTempName);
if ( result == 0 )
{
XP_FileRemove( tempName, xpURL );
XP_FREE(tempName);
tempName = newTempName;
}
else
XP_FileRemove( tempName, xpURL );
#else
result = 0;
#endif
}
}
else
result = XP_GetError();
}
done:
/* Create the return Java string if everything went OK */
if (tempName && ( result == 0) )
{
tempNameJava = JRI_NewStringPlatform(env, tempName, XP_STRLEN( tempName), "", 0);
if (tempNameJava == NULL)
result = MK_OUT_OF_MEMORY;
XP_FREE(tempName);
}
if ( (result != 0) || (tempNameJava == NULL) )
{
struct netscape_softupdate_SoftUpdateException* e;
struct java_lang_String * errStr;
errStr = netscape_softupdate_Strings_error_0005fExtractFailed(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
result);
JRI_Throw(env, (struct java_lang_Throwable *)e);
return NULL;
}
return tempNameJava;
}
/* getCertificates
* native encapsulation that calls AppletClassLoader.getCertificates
* we cannot call this method from Java because it is private.
* The method cannot be made public because it is a security risk
*/
#ifndef XP_MAC
#include "netscape_applet_AppletClassLoader.h"
#else
#include "n_applet_AppletClassLoader.h"
#endif
/* From java.h (keeping the old hack, until include path is setup correctly on Mac) */
PR_PUBLIC_API(jref)
LJ_GetCertificates(JRIEnv* env, void *zigPtr, char *pathname);
JRI_PUBLIC_API(jref)
native_netscape_softupdate_SoftwareUpdate_getCertificates(JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
jint zigPtr,
struct java_lang_String *name)
{
char* pathname;
if (!name)
return NULL;
pathname = (char *)JRI_GetStringUTFChars(env, name);
if (!pathname)
return NULL;
return LJ_GetCertificates(env, (void *)zigPtr, pathname);
}
#ifdef XP_MAC
#include <Gestalt.h>
#endif
/*** private native NativeGestalt (Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_SoftwareUpdate_NativeGestalt(JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
struct java_lang_String *jselector)
{
#ifdef XP_MAC
OSErr err;
long response;
char * selectorStr;
OSType selector;
selectorStr = (char*)JRI_GetStringPlatformChars( env, jselector, "", 0 );
if ((selectorStr == NULL) ||
(XP_STRLEN(selectorStr) != 4))
{
err = -5550; /* gestaltUnknownErr */
goto fail;
}
XP_MEMCPY(&selector, selectorStr, 4);
err = Gestalt(selector, &response);
if (err == noErr)
return response;
goto fail; /* Drop through to failure */
#else
int32 err;
err = -1;
goto fail;
#endif
fail:
{
struct netscape_softupdate_SoftUpdateException* e;
struct java_lang_String * errStr;
/* Just a random error message, it will never be seen, error code is the only important bit */
errStr = netscape_softupdate_Strings_error_0005fExtractFailed(env,
class_netscape_softupdate_Strings(env));
e = netscape_softupdate_SoftUpdateException_new( env,
class_netscape_softupdate_SoftUpdateException(env),
errStr,
err);
JRI_Throw(env, (struct java_lang_Throwable *)e);
}
return 0;
}
/*** private native ExtractDirEntries (Ljava/lang/String;)[Ljava/lang/String; ***/
JRI_PUBLIC_API(jref)
native_netscape_softupdate_SoftwareUpdate_ExtractDirEntries(
JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
struct java_lang_String * dir)
{
int size = 0;
int len = 0;
int dirlen;
ZIG *zigPtr;
char *Directory;
char *pattern = NULL;
ZIG_Context *context;
SOBITEM *item;
jref StrArray = NULL;
char *buff;
if (!dir)
goto bail;
if ( !(zigPtr = (ZIG *)get_netscape_softupdate_SoftwareUpdate_zigPtr(env, self)) )
goto bail;
if ( !(Directory = (char*)JRI_GetStringPlatformChars( env, dir, "", 0 )) )
goto bail;
dirlen = XP_STRLEN(Directory);
if ( (pattern = XP_ALLOC(dirlen + 3)) == NULL)
goto bail;
XP_STRCPY(pattern, Directory);
XP_STRCPY(pattern+dirlen, "/*");
/* it's either go through the JAR twice (first time just to get a count)
* or go through once and potentially use lots of memory saving all the
* strings. In deference to Win16 and potentially large installs we're
* going to loop through the JAR twice and take the performance hit;
* no one installs very often anyway.
*/
if ((context = SOB_find (zigPtr, pattern, ZIG_MF)) == NULL)
goto bail;
while (SOB_find_next (context, &item) >= 0)
size++;
SOB_find_end (context);
if ( (StrArray = JRI_NewObjectArray(env, size, JRI_FindClass(env, "java/lang/String"), NULL)) == 0)
goto bail;
if ((context = SOB_find (zigPtr, pattern, ZIG_MF)) == NULL)
goto bail;
size = 0;
while (SOB_find_next (context, &item) >= 0)
{
len = XP_STRLEN(item->pathname);
/* subtract length of target directory + slash */
len = len - (dirlen+1);
if ( buff = XP_ALLOC (len+1) )
{
/* Don't copy the search directory part */
XP_STRCPY (buff, (item->pathname)+dirlen+1);
/* XXX -- use intl_makeJavaString() instead? */
JRI_SetObjectArrayElement( env, StrArray, size++,
JRI_NewStringPlatform(env, buff, len, "", 0) );
XP_FREE(buff);
}
}
SOB_find_end (context);
bail:
XP_FREEIF(pattern);
return StrArray;
}
/*** private native NativeDeleteFile (Ljava/lang/String;)I ***/
extern JRI_PUBLIC_API(jint)
native_netscape_softupdate_SoftwareUpdate_NativeDeleteFile(
JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
struct java_lang_String *path)
{
char *fName;
if ( !(fName = (char*)JRI_GetStringPlatformChars( env, path, "", 0 )) )
return -1;
return XP_FileRemove ( fName, xpURL );
}
/*** private native NativeVerifyDiskspace (Ljava/lang/String;I)I ***/
extern JRI_PUBLIC_API(jint)
native_netscape_softupdate_SoftwareUpdate_NativeVerifyDiskspace(
JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
struct java_lang_String *path,
jint nBytes)
{
char *fileSystem;
if ( !(fileSystem = (char*)JRI_GetStringPlatformChars( env, path, "", 0 )) )
return 0;
return DiskSpaceAvailable(fileSystem, (int) nBytes);
}
/*** private native NativeMakeDirectory (Ljava/lang/String;)I ***/
extern JRI_PUBLIC_API(jint)
native_netscape_softupdate_SoftwareUpdate_NativeMakeDirectory(
JRIEnv* env,
struct netscape_softupdate_SoftwareUpdate* self,
struct java_lang_String *path)
{
char *dir;
if ( !(dir = (char*)JRI_GetStringPlatformChars( env, path, "", 0 )) )
return -1;
return XP_MakeDirectoryR ( dir, xpURL );
}

Просмотреть файл

@ -0,0 +1,270 @@
/* -*- 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.
*/
/* su_unix.c
* UNIX specific softupdate routines
*/
#include "xp_mcom.h"
#include "su_folderspec.h"
#include "su_instl.h"
#include "xp_str.h"
#include "NSReg.h"
#define MAXPATHLEN 1024
extern void fe_GetProgramDirectory( char *, int );
extern int FE_DiskSpaceAvailable( char * );
int unlink (const char *);
char * FE_GetDirectoryPath( su_DirSpecID folderID)
{
char *directory = NULL;
char Path[MAXPATHLEN+1];
switch( folderID)
{
case ePluginFolder:
{
if ( getenv (UNIX_GLOBAL_FLAG) )
{
if (directory = getenv("MOZILLA_HOME"))
{
PR_snprintf( Path, MAXPATHLEN, "%s/", directory);
}
else
fe_GetProgramDirectory( Path, MAXPATHLEN-1 );
XP_STRCAT(Path, "plugins/");
}
else
{ /* Use local plugins path: $HOME/.netscape/plugins/ */
char *Home = getenv ( "HOME" );
if (!Home)
Home = "";
else if (!strcmp (Home, "/"))
Home = "";
PR_snprintf(Path, MAXPATHLEN, "%.900s/.netscape/plugins/", Home);
}
directory = XP_STRDUP( Path );
}
break;
case eCommunicatorFolder:
if (directory = getenv("MOZILLA_HOME"))
{
PR_snprintf( Path, MAXPATHLEN, "%s/", directory );
directory = XP_STRDUP( Path );
break;
}
/* fall through */
case eProgramFolder:
{
fe_GetProgramDirectory( Path, MAXPATHLEN-1 );
directory = XP_STRDUP( Path );
}
break;
case eUnix_LocalFolder:
directory = XP_STRDUP( "/usr/local/netscape/" );
break;
case eUnix_LibFolder:
directory = XP_STRDUP( "/usr/local/lib/netscape/" );
break;
case eTemporaryFolder:
{
directory = XP_STRDUP( "/tmp/" );
}
break;
case eJavaBinFolder:
if (directory = getenv("MOZILLA_HOME"))
{
PR_snprintf( Path, MAXPATHLEN, "%s/", directory);
}
else
fe_GetProgramDirectory( Path, MAXPATHLEN-1 );
XP_STRCAT(Path, "java/bin/");
directory = XP_STRDUP( Path );
break;
case eJavaClassesFolder:
if (directory = getenv("MOZILLA_HOME"))
{
PR_snprintf( Path, MAXPATHLEN, "%s/", directory);
}
else
fe_GetProgramDirectory( Path, MAXPATHLEN-1 );
XP_STRCAT(Path, "java/classes/");
directory = XP_STRDUP( Path );
break;
case eJavaDownloadFolder:
{
if ( getenv (UNIX_GLOBAL_FLAG) )
{
if (directory = getenv("MOZILLA_HOME"))
{
PR_snprintf( Path, MAXPATHLEN, "%s/", directory);
}
else
fe_GetProgramDirectory( Path, MAXPATHLEN-1 );
XP_STRCAT(Path, "java/download/");
}
else
{
char *Home = getenv ( "HOME" );
if (!Home)
Home = "";
else if (!strcmp (Home, "/"))
Home = "";
PR_snprintf(Path, MAXPATHLEN, "%.900s/.netscape/java/download/", Home);
}
directory = XP_STRDUP( Path );
}
break;
case eNetHelpFolder:
{
if (directory = getenv("MOZILLA_HOME"))
PR_snprintf( Path, MAXPATHLEN, "%s/", directory);
else
fe_GetProgramDirectory( Path, MAXPATHLEN-1 );
XP_STRCAT(Path, "nethelp/");
directory = XP_STRDUP( Path );
}
break;
case eOSDriveFolder:
case eFileURLFolder:
directory = XP_STRDUP( "/" );
break;
case ePackageFolder:
case eMac_SystemFolder:
case eMac_DesktopFolder:
case eMac_TrashFolder:
case eMac_StartupFolder:
case eMac_ShutdownFolder:
case eMac_AppleMenuFolder:
case eMac_ControlPanelFolder:
case eMac_ExtensionFolder:
case eMac_FontsFolder:
case eMac_PreferencesFolder:
break;
default:
XP_ASSERT(0);
break;
}
return (directory);
}
/* Simple file execution. For now call system() */
int FE_ExecuteFile( const char * filename, const char * cmdline )
{
if ( cmdline == NULL )
return -1;
return(system( cmdline ));
}
/* Crude file copy */
int FE_CopyFile (const char *in, const char *out)
{
char buf [1024];
FILE *ifp, *ofp;
int rbytes, wbytes;
if (!in || !out)
return -1;
ifp = fopen (in, "r");
if (!ifp)
{
unlink(in);
return -1;
}
ofp = fopen (out, "w");
if (!ofp)
{
fclose (ifp);
unlink(in);
return -1;
}
while ((rbytes = fread (buf, 1, sizeof(buf), ifp)) > 0)
{
while (rbytes > 0)
{
if ( (wbytes = fwrite (buf, 1, rbytes, ofp)) < 0 )
{
fclose (ofp);
fclose (ifp);
unlink(in);
unlink(out);
return -1;
}
rbytes -= wbytes;
}
}
fclose (ofp);
fclose (ifp);
unlink(in);
return 0;
}
int FE_ReplaceExistingFile(char *CurrentFname, XP_FileType ctype,
char *FinalFname, XP_FileType ftype, XP_Bool force)
{
int err;
err = XP_FileRemove( FinalFname, ftype );
if ( 0 == err )
{
err = XP_FileRename(CurrentFname, ctype, FinalFname, ftype);
}
return (err);
}
int DiskSpaceAvailable(char *fileSystem, int nBytes)
{
#if 0
struct STATFS fs_buf;
if (STATFS (fileSystem, &fs_buf) < 0)
return 0;
return ((fs_buf.f_bsize*(fs_buf.f_bavail-1)) >= nBytes);
#endif
int Available = FE_DiskSpaceAvailable( fileSystem );
if (Available > 0 )
return (Available >= nBytes);
return 0;
}

Просмотреть файл

@ -0,0 +1,581 @@
/* -*- Mode: C++; tab-width: 4; tabs-indent-mode: nil -*-
*
* 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.
*/
/* su_win.c
* Win specific softupdate routines
*/
#ifdef XP_OS2
#include os2updt.h"
#endif
#include <stdafx.h>
#include "xp_mcom.h"
#include "su_folderspec.h"
#include "su_instl.h"
#include "xp_str.h"
#include "npapi.h"
#include "libevent.h"
#include "fe_proto.h"
#include "xpgetstr.h"
#include <windows.h>
#include "NSReg.h"
#ifdef WIN32
#include <winver.h>
#elif !defined (XP_OS2)
#include <ver.h>
#endif
extern NPError wfe_GetPluginsDirectory(CString& csDirname);
extern "C" char * FE_GetProgramDirectory(char *buffer, int length);
extern "C" int SU_NEED_TO_REBOOT;
extern "C" REGERR fe_DeleteOldFileLater(char * filename);
extern "C" REGERR fe_ReplaceOldFileLater(char *tmpfile, char *target);
XP_Bool fe_FileNeedsUpdate(char *sourceFile, char *targetFile);
#if defined(WIN32) || defined(XP_OS2)
#define su_FileRemove(file,type) XP_FileRemove((file),(type))
#else
int su_FileRemove(char *fname, XP_FileType type);
#endif
char * FE_GetDirectoryPath( su_DirSpecID folderID)
{
char * directory = NULL;
char path[_MAX_PATH];
DWORD dwVersion;
UINT len;
switch( folderID)
{
case ePluginFolder:
{
NPError err;
CString c;
err = wfe_GetPluginsDirectory(c);
if (err == 0) {
c += (TCHAR)'\\';
directory = XP_STRDUP( c );
}
}
break;
case eProgramFolder:
FE_GetProgramDirectory( path, _MAX_PATH );
directory = XP_STRDUP( path );
break;
case ePackageFolder:
break;
case eTemporaryFolder:
{
char* tmpdir = XP_TempDirName();
XP_STRCPY( path, tmpdir );
XP_STRCAT( path, "\\" );
XP_FREEIF(tmpdir);
directory = XP_STRDUP( path );
}
break;
case eCommunicatorFolder:
{
char* p;
FE_GetProgramDirectory( path, _MAX_PATH );
if ( (p = XP_STRRCHR( path, '\\' )) ) *p = '\0';
if ( (p = XP_STRRCHR( path, '\\' )) ) p[1] = '\0';
directory = XP_STRDUP( path );
}
break;
case eWin_System16Folder:
len = GetSystemDirectory( path, _MAX_PATH );
// If Windows NT
#ifndef XP_OS2
dwVersion = GetVersion();
if ( dwVersion < 0x80000000 ) {
// and the last two chars of the system dir are "32"
if ( XP_STRCMP( path+len-2, "32" ) == 0 ) {
// 16-bit system dir is just "System"
len = len - 2;
}
}
#endif
XP_STRCPY( path+len, "\\" );
directory = XP_STRDUP( path );
break;
case eWin_SystemFolder:
len = GetSystemDirectory( path, _MAX_PATH );
XP_STRCPY( path+len, "\\" );
directory = XP_STRDUP( path );
break;
case eWin_WindowsFolder:
len = GetWindowsDirectory( path, _MAX_PATH );
XP_STRCPY( path+len, "\\" );
directory = XP_STRDUP( path );
break;
case eJavaBinFolder:
FE_GetProgramDirectory( path, _MAX_PATH );
directory = PR_smprintf("%sjava\\bin\\", path);
break;
case eJavaClassesFolder:
FE_GetProgramDirectory( path, _MAX_PATH );
directory = PR_smprintf("%sjava\\classes\\", path);
break;
case eJavaDownloadFolder:
FE_GetProgramDirectory( path, _MAX_PATH );
directory = PR_smprintf("%sjava\\download\\", path);
break;
case eNetHelpFolder:
FE_GetProgramDirectory( path, _MAX_PATH );
XP_STRCAT( path, "\\NetHelp\\" );
directory = XP_STRDUP( path );
break;
case eOSDriveFolder:
directory = XP_STRDUP( "C:" );
break;
case eFileURLFolder:
directory = XP_STRDUP( "C:" );
break;
// inapplicable platform specific directories
case eMac_SystemFolder:
case eMac_DesktopFolder:
case eMac_TrashFolder:
case eMac_StartupFolder:
case eMac_ShutdownFolder:
case eMac_AppleMenuFolder:
case eMac_ControlPanelFolder:
case eMac_ExtensionFolder:
case eMac_FontsFolder:
case eMac_PreferencesFolder:
case eUnix_LocalFolder:
case eUnix_LibFolder:
break;
default:
// someone added a new one and didn't take care of it
XP_ASSERT(0);
break;
}
return directory;
}
int FE_ExecuteFile( const char * filename, const char * cmdline )
{
if ( cmdline == NULL || filename == NULL )
return -1;
DWORD hInst = WinExec( cmdline, SW_NORMAL );
fe_DeleteOldFileLater( (char*)filename );
if ( hInst < 32 )
return -1;
else
return 0;
}
/* Template for a delayed "rename" of a file on windows platform, need to:
- Convert filenames to native form
- Add error checking
*/
#ifndef NO_ERROR
#define NO_ERROR 0
#endif
int FE_ReplaceExistingFile(char *CurrentFname, XP_FileType ctype,
char *FinalFname, XP_FileType ftype, XP_Bool force)
{
int err;
char * currentName;
char * finalName;
/* Convert file names to their native format */
currentName = WH_FileName (CurrentFname, ctype);
finalName = WH_FileName (FinalFname, ftype);
if ( currentName == NULL || finalName == NULL ) {
err = -1;
goto cleanup;
}
// replace file if forced or if windows version info is newer
if (force || fe_FileNeedsUpdate( currentName, finalName ) )
{
/* try to delete the existing file */
err = su_FileRemove( FinalFname, ftype );
if ( NO_ERROR == err )
{
err = XP_FileRename(CurrentFname, ctype, FinalFname, ftype);
}
else
{
/* couldn't delete, probably in use. Schedule for later */
DWORD dwVersion, dwWindowsMajorVersion;
char* final = finalName;
char* current = currentName;
#if !defined(XP_WIN16) && !defined (XP_OS2)
/* 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 ( WFE_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;
BOOL nameFound = FALSE;
char tmpname[_MAX_PATH];
strcpy( tmpname, finalName );
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 ) ) {
err = fe_DeleteOldFileLater( tmpname );
}
else {
/* 2nd move failed, put old file back */
MoveFile( tmpname, finalName );
}
}
else {
/* non-executable in use; schedule for later */
err = fe_ReplaceOldFileLater( CurrentFname, FinalFname );
}
}
}
else if ( MoveFileEx(currentName, finalName, MOVEFILE_DELAY_UNTIL_REBOOT) )
{
err = NO_ERROR;
}
}
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 ) {
current = Src;
}
strlen = GetShortPathName( (LPCTSTR) finalName, (LPTSTR) Dest, (DWORD) sizeof(Dest));
if ( strlen > 0 ) {
final = Dest;
}
#endif /* XP_WIN16 && XP_OS2 */
#if XP_OS2
ULONG usRetCode;
usRetCode = WriteLockFileRenameEntry(final,current,"SOFTUPDT.LST");
if (usRetCode == NO_ERROR) {
err = NO_ERROR;
}
#else
if ( WritePrivateProfileString( "Rename", final, current, "WININIT.INI" ) )
err = NO_ERROR;
#endif
#if !defined(XP_WIN16) && !defined(XP_OS2)
}
#endif /* XP_WIN16 */
if ( NO_ERROR == err )
err = REBOOT_NEEDED;
}
} // (force || fe_FileNeedsUpdate( currentName, finalName ))
else {
// file to be installed was older than existing file--clean up
err = XP_FileRemove( CurrentFname, ctype );
}
cleanup:
XP_FREEIF(finalName);
XP_FREEIF(currentName);
return err;
}
void PR_CALLBACK SU_AlertCallback(void * dummy)
{
MWContext * cx;
cx = XP_FindSomeContext();
FE_Alert(cx, XP_GetString(SU_NEED_TO_REBOOT));
}
XP_Bool fe_FileNeedsUpdate(char *sourceFile, char *targetFile)
{
XP_Bool needUpdate;
#if defined XP_OS2
needUpdate = TRUE; //Do not have internal version control so
//assume that files should be replaced as
//in unix version
#else
DWORD targetInfoSize;
DWORD sourceInfoSize;
DWORD bogusHandle;
void *sourceData;
void *targetData;
VS_FIXEDFILEINFO *sourceInfo;
VS_FIXEDFILEINFO *targetInfo;
UINT targIBSize;
UINT srcIBSize;
// always replace old file if it doesn't have version info
targetInfoSize = GetFileVersionInfoSize( targetFile, &bogusHandle );
if (targetInfoSize == 0)
return TRUE;
// if new file doesn't have a version assume it's older than one that does
sourceInfoSize = GetFileVersionInfoSize( sourceFile, &bogusHandle );
if (sourceInfoSize == 0)
return FALSE;
// both files have version info blocks; we must compare them
needUpdate = TRUE;
sourceData = XP_ALLOC(sourceInfoSize);
targetData = XP_ALLOC(targetInfoSize);
if ( (sourceData != NULL) && (targetData != NULL) &&
GetFileVersionInfo(targetFile, NULL, targetInfoSize, targetData) &&
GetFileVersionInfo(sourceFile, NULL, sourceInfoSize, sourceData) &&
VerQueryValue(targetData, "\\", (void**)&targetInfo, &targIBSize) &&
VerQueryValue(sourceData, "\\", (void**)&sourceInfo, &srcIBSize) )
{
DWORD targetMajorVer = targetInfo->dwFileVersionMS;
DWORD targetMinorVer = targetInfo->dwFileVersionLS;
DWORD sourceMajorVer = sourceInfo->dwFileVersionMS;
DWORD sourceMinorVer = sourceInfo->dwFileVersionLS;
// don't replace a file with a newer version
if (targetMajorVer > sourceMajorVer)
{
needUpdate = FALSE;
}
else if (targetMajorVer == sourceMajorVer && targetMinorVer > sourceMinorVer)
{
needUpdate = FALSE;
}
else
needUpdate = TRUE;
}
XP_FREEIF(sourceData);
XP_FREEIF(targetData);
#endif //XP_OS2
return needUpdate;
}
REGERR fe_DeleteOldFileLater(char * filename)
{
RKEY newkey;
REGERR result = -1;
HREG reg;
if ( REGERR_OK == NR_RegOpen("", &reg) ) {
if (REGERR_OK == NR_RegAddKey( reg, ROOTKEY_PRIVATE,
REG_DELETE_LIST_KEY, &newkey) )
{
result = NR_RegSetEntryString( reg, newkey, filename, "" );
}
NR_RegClose(reg);
}
return result;
}
REGERR fe_ReplaceOldFileLater(char *tmpfile, char *target )
{
RKEY newkey;
REGERR err;
HREG reg;
err = NR_RegOpen("", &reg);
if ( err == REGERR_OK ) {
err = NR_RegAddKey( reg, ROOTKEY_PRIVATE, REG_REPLACE_LIST_KEY, &newkey);
if ( err == REGERR_OK ) {
err = NR_RegSetEntryString( reg, newkey, tmpfile, target );
}
NR_RegClose(reg);
}
return err;
}
#if !defined(WIN32) && !defined(XP_OS2)
#define BUFLEN 1024
void FE_ScheduleRenameUtility(void)
{
int cmdlength;
char *folder;
char * buf = (char*)XP_ALLOC(BUFLEN);
if ( buf != NULL ) {
FE_GetProgramDirectory(buf, BUFLEN);
XP_STRCAT(buf, "NSINIT.EXE,");
cmdlength = XP_STRLEN(buf);
if (!GetProfileString("Windows","Run","",(buf+cmdlength),
(BUFLEN-cmdlength)))
{
// no other RUN commands so don't need trailing comma
buf[cmdlength-1] = '\0';
}
WriteProfileString("Windows","Run",buf);
XP_FREE(buf);
}
}
// WIN16 only, Win32 is macro'd to usual XP_FileRemove()
int su_FileRemove(char *fname, XP_FileType type)
{
HMODULE hinst;
char *pFile;
int err = NO_ERROR;
// convert to native filename and see if it's currently running
pFile = WH_FileName( fname, type );
if (pFile != NULL ) {
// Don't try to delete if Windows says it's in use
hinst = GetModuleHandle(pFile);
if ( hinst != NULL ) {
// GetModuleHandle() accepts the full path but matches only on the
// root name. Use GetModuleFileName() to verify a true match
char module[_MAX_PATH];
GetModuleFileName( hinst, module, _MAX_PATH );
if ( stricmp( pFile, module ) == 0 ) {
// they match
err = -1;
}
}
XP_FREE(pFile);
}
if ( err == NO_ERROR ) {
// wasn't in use (or couldn't convert to native filename)
// try to remove the old way
err = XP_FileRemove( fname, type );
}
return err;
}
#endif /* !WIN32 */
#ifdef WIN32
BOOL WFE_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;
}
#endif /* WIN32 */
extern "C" int DiskSpaceAvailable(char *fileSystem, int nBytes)
{
return nBytes>=0;
}

Просмотреть файл

@ -0,0 +1,414 @@
/* -*- 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.
*/
#ifdef XP_PC
#include <windows.h>
#define IMPLEMENT_netscape_softupdate_WinProfile
#define IMPLEMENT_netscape_softupdate_WinReg
#define IMPLEMENT_netscape_softupdate_WinRegValue
#include "_jri/netscape_softupdate_WinProfile.c"
#include "_jri/netscape_softupdate_WinReg.c"
#include "_jri/netscape_softupdate_WinRegValue.c"
#ifdef XP_OS2
#include "registry.h" //from cmd/os2fe/nfc/include/registry.h
#define REG_SZ 0
#endif
#ifndef WIN32
#include "shellapi.h"
#endif
#define STRBUFLEN 1024
/* ------------------------------------------------------------------
* WinProfile native methods
* ------------------------------------------------------------------
*/
void SUWinSpecificInit( JRIEnv *env )
{
use_netscape_softupdate_WinProfile((JRIEnv*)env);
use_netscape_softupdate_WinReg((JRIEnv*)env);
use_netscape_softupdate_WinRegValue((JRIEnv*)env);
}
/*** public native nativeWriteString
(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_WinProfile_nativeWriteString(
JRIEnv* env,
struct netscape_softupdate_WinProfile* self,
struct java_lang_String *section,
struct java_lang_String *key,
struct java_lang_String *value)
{
int success = 0;
char * pApp;
char * pKey;
char * pValue;
char * pFile;
struct java_lang_String *file;
file = get_netscape_softupdate_WinProfile_filename( env, self );
pFile = (char*)JRI_GetStringPlatformChars( env, file, "", 0 );
pApp = (char*)JRI_GetStringPlatformChars( env, section, "", 0 );
pKey = (char*)JRI_GetStringPlatformChars( env, key, "", 0 );
pValue = (char*)JRI_GetStringPlatformChars( env, value, "", 0 );
/* make sure conversions worked */
if ( pApp != NULL && pKey != NULL && pFile != NULL ) {
/* it's OK for pValue to be null only if original param was also NULL */
if ( pValue != NULL || value == NULL ) {
success = WritePrivateProfileString( pApp, pKey, pValue, pFile );
}
}
return success;
}
/*** public native nativeGetString
(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; ***/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_WinProfile_nativeGetString(
JRIEnv* env,
struct netscape_softupdate_WinProfile* self,
struct java_lang_String *section,
struct java_lang_String *key)
{
int numChars;
char * pApp;
char * pKey;
char * pFile;
char valbuf[STRBUFLEN];
struct java_lang_String *file;
struct java_lang_String *value = NULL;
file = get_netscape_softupdate_WinProfile_filename( env, self );
pFile = (char*)JRI_GetStringPlatformChars( env, file, "", 0 );
pApp = (char*)JRI_GetStringPlatformChars( env, section, "", 0 );
pKey = (char*)JRI_GetStringPlatformChars( env, key, "", 0 );
/* make sure conversions worked */
if ( pApp != NULL && pKey != NULL && pFile != NULL ) {
numChars = GetPrivateProfileString( pApp, pKey, "",
valbuf, STRBUFLEN, pFile );
/* if the value fit in the buffer */
if ( numChars < STRBUFLEN ) {
value = JRI_NewStringPlatform( env, valbuf, numChars, "", 0 );
}
}
return value;
}
/* ------------------------------------------------------------------
* WinReg native methods
* ------------------------------------------------------------------
*/
/*** public native createKey (Ljava/lang/String;Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_WinReg_nativeCreateKey(
JRIEnv* env,
struct netscape_softupdate_WinReg* self,
struct java_lang_String *subkey,
struct java_lang_String *classname)
{
char * pSubkey;
char * pClass;
HKEY root, newkey;
LONG result;
LONG disposition;
pSubkey = (char*)JRI_GetStringPlatformChars( env, subkey, "", 0 );
pClass = (char*)JRI_GetStringPlatformChars( env, classname, "", 0 );
#ifdef WIN32
root = (HKEY)get_netscape_softupdate_WinReg_rootkey( env, self );
result = RegCreateKeyEx( root, pSubkey, 0, pClass, REG_OPTION_NON_VOLATILE,
KEY_ALL_ACCESS, NULL, &newkey, &disposition );
#else
result = RegCreateKey( HKEY_CLASSES_ROOT, pSubkey, &newkey );
#endif
if (ERROR_SUCCESS == result ) {
RegCloseKey( newkey );
}
return result;
}
/*** public native deleteKey (Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_WinReg_nativeDeleteKey(
JRIEnv* env,
struct netscape_softupdate_WinReg* self,
struct java_lang_String *subkey)
{
char * pSubkey;
HKEY root;
pSubkey = (char*)JRI_GetStringPlatformChars( env, subkey, "", 0 );
#ifdef WIN32
root = (HKEY)get_netscape_softupdate_WinReg_rootkey( env, self );
#else
root = HKEY_CLASSES_ROOT;
#endif
return RegDeleteKey( root, pSubkey );
}
/*** public native deleteValue (Ljava/lang/String;Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_WinReg_nativeDeleteValue(
JRIEnv* env,
struct netscape_softupdate_WinReg* self,
struct java_lang_String *subkey,
struct java_lang_String *valname)
{
#if defined (WIN32) || defined (XP_OS2)
char * pSubkey;
char * pValue;
HKEY root, newkey;
LONG result;
pSubkey = (char*)JRI_GetStringPlatformChars( env, subkey, "", 0 );
pValue = (char*)JRI_GetStringPlatformChars( env, valname, "", 0 );
root = (HKEY)get_netscape_softupdate_WinReg_rootkey( env, self );
result = RegOpenKeyEx( root, pSubkey, 0, KEY_WRITE, &newkey );
if ( ERROR_SUCCESS == result ) {
result = RegDeleteValue( newkey, pValue );
RegCloseKey( newkey );
}
return result;
#else
return ERROR_INVALID_PARAMETER;
#endif
}
/*** public native setValueString (Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_WinReg_nativeSetValueString(
JRIEnv* env,
struct netscape_softupdate_WinReg* self,
struct java_lang_String *subkey,
struct java_lang_String *valname,
struct java_lang_String *value)
{
char * pSubkey;
char * pName;
char * pValue;
HKEY root;
HKEY newkey;
LONG result;
DWORD length;
pSubkey = (char*)JRI_GetStringPlatformChars( env, subkey, "", 0 );
pValue = (char*)JRI_GetStringPlatformChars( env, value, "", 0 );
length = strlen(pValue);
#ifdef WIN32
pName = (char*)JRI_GetStringPlatformChars( env, valname, "", 0 );
root = (HKEY)get_netscape_softupdate_WinReg_rootkey( env, self );
result = RegOpenKeyEx( root, pSubkey, 0, KEY_ALL_ACCESS, &newkey );
if ( ERROR_SUCCESS == result ) {
result = RegSetValueEx( newkey, pName, 0, REG_SZ, pValue, length );
RegCloseKey( newkey );
}
#else
result = RegSetValue( HKEY_CLASSES_ROOT, pSubkey, REG_SZ, pValue, length );
#endif
return result;
}
/*** public native getValueString (Ljava/lang/String;Ljava/lang/String;)Ljava/lang/String; ***/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_WinReg_nativeGetValueString(
JRIEnv* env,
struct netscape_softupdate_WinReg* self,
struct java_lang_String *subkey,
struct java_lang_String *valname)
{
char * pSubkey;
char * pName;
char valbuf[STRBUFLEN];
HKEY root;
HKEY newkey;
LONG result;
DWORD type = REG_SZ;
DWORD length = STRBUFLEN;
struct java_lang_String *value = NULL;
pSubkey = (char*)JRI_GetStringPlatformChars( env, subkey, "", 0 );
#ifdef WIN32
pName = (char*)JRI_GetStringPlatformChars( env, valname, "", 0 );
root = (HKEY)get_netscape_softupdate_WinReg_rootkey( env, self );
result = RegOpenKeyEx( root, pSubkey, 0, KEY_ALL_ACCESS, &newkey );
if ( ERROR_SUCCESS == result ) {
result = RegQueryValueEx( newkey, pName, NULL, &type, valbuf, &length );
RegCloseKey( newkey );
}
#else
result = RegQueryValue( HKEY_CLASSES_ROOT, pSubkey, valbuf, &length );
#endif
if ( ERROR_SUCCESS == result && type == REG_SZ ) {
value = JRI_NewStringPlatform( env, valbuf, length, "", 0 );
}
return value;
}
/*** public native setValue (Ljava/lang/String;Ljava/lang/String;Lnetscape/softupdate/WinRegValue;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_WinReg_nativeSetValue(
JRIEnv* env,
struct netscape_softupdate_WinReg* self,
struct java_lang_String *subkey,
struct java_lang_String *valname,
struct netscape_softupdate_WinRegValue *value)
{
#if defined (WIN32) || defined (XP_OS2)
char * pSubkey;
char * pName;
char * pValue;
HKEY root;
HKEY newkey;
LONG result;
DWORD length;
DWORD type;
jref data;
pSubkey = (char*)JRI_GetStringPlatformChars( env, subkey, "", 0 );
root = (HKEY)get_netscape_softupdate_WinReg_rootkey( env, self );
result = RegOpenKeyEx( root, pSubkey, 0, KEY_ALL_ACCESS, &newkey );
if ( ERROR_SUCCESS == result ) {
pName = (char*)JRI_GetStringPlatformChars( env, valname, "", 0 );
type = get_netscape_softupdate_WinRegValue_type( env, value );
data = get_netscape_softupdate_WinRegValue_data( env, value );
length = JRI_GetByteArrayLength( env, data );
pValue = JRI_GetByteArrayElements( env, data );
result = RegSetValueEx( newkey, pName, 0, type, pValue, length );
RegCloseKey( newkey );
}
return result;
#else
return ERROR_INVALID_PARAMETER;
#endif
}
/*** public native getValue (Ljava/lang/String;Ljava/lang/String;)Lnetscape/softupdate/WinRegValue; ***/
JRI_PUBLIC_API(struct netscape_softupdate_WinRegValue *)
native_netscape_softupdate_WinReg_nativeGetValue(
JRIEnv* env,
struct netscape_softupdate_WinReg* self,
struct java_lang_String *subkey,
struct java_lang_String *valname)
{
#if defined (WIN32) || defined (XP_OS2)
char * pSubkey;
char * pName;
char valbuf[STRBUFLEN];
HKEY root;
HKEY newkey;
LONG result;
DWORD length=STRBUFLEN;
DWORD type;
jref data;
struct netscape_softupdate_WinRegValue * value = NULL;
pSubkey = (char*)JRI_GetStringPlatformChars( env, subkey, "", 0 );
root = (HKEY)get_netscape_softupdate_WinReg_rootkey( env, self );
result = RegOpenKeyEx( root, pSubkey, 0, KEY_ALL_ACCESS, &newkey );
if ( ERROR_SUCCESS == result ) {
pName = (char*)JRI_GetStringPlatformChars( env, valname, "", 0 );
result = RegQueryValueEx( newkey, pName, NULL, &type, valbuf, &length );
if ( ERROR_SUCCESS == result ) {
data = JRI_NewByteArray( env, length, valbuf );
value = netscape_softupdate_WinRegValue_new(
env,
class_netscape_softupdate_WinRegValue(env),
type,
data );
}
RegCloseKey( newkey );
}
return value;
#else
return NULL;
#endif
}
#endif /* XP_PC */

Просмотреть файл

@ -0,0 +1,905 @@
/* -*- 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 STANDALONE_REGISTRY
/*
* Native implementation for the netscape.softupdate.VersionRegistry,
* netscape.softupdate.Registry classes and helper classes
*/
#define IMPLEMENT_netscape_softupdate_VersionRegistry
#define IMPLEMENT_netscape_softupdate_VerRegEnumerator
#define IMPLEMENT_netscape_softupdate_VersionInfo
#define IMPLEMENT_netscape_softupdate_Registry
#define IMPLEMENT_netscape_softupdate_RegistryNode
#define IMPLEMENT_netscape_softupdate_RegKeyEnumerator
#define IMPLEMENT_netscape_softupdate_RegEntryEnumerator
#define IMPLEMENT_netscape_softupdate_RegistryException
#ifndef XP_MAC
#include "_jri/netscape_softupdate_VersionRegistry.c"
#include "_jri/netscape_softupdate_VerRegEnumerator.c"
#include "_jri/netscape_softupdate_VersionInfo.c"
#include "_jri/netscape_softupdate_Registry.c"
#include "_jri/netscape_softupdate_RegistryNode.c"
#include "_jri/netscape_softupdate_RegKeyEnumerator.c"
#include "_jri/netscape_softupdate_RegEntryEnumerator.c"
#include "_jri/netscape_softupdate_RegistryException.c"
#else
#include "n_softupdate_VersionRegistry.h"
#include "n_softupdate_VerRegEnumerator.h"
#include "n_softupdate_VersionInfo.h"
#include "netscape_softupdate_Registry.h"
#include "n_softupdate_RegistryNode.h"
#include "n_softupdate_RegKeyEnumerator.h"
#include "n_s_RegEntryEnumerator.h"
#include "n_s_RegistryException.h"
#endif
#include "xp_mcom.h"
#include "NSReg.h"
#include "VerReg.h"
#include "prefapi.h"
#ifdef XP_MAC
#pragma export on
#endif
void VR_Initialize(void* env)
{
use_netscape_softupdate_VersionRegistry((JRIEnv*)env);
use_netscape_softupdate_VerRegEnumerator((JRIEnv*)env);
use_netscape_softupdate_VersionInfo((JRIEnv*)env);
use_netscape_softupdate_Registry((JRIEnv*)env);
use_netscape_softupdate_RegistryNode((JRIEnv*)env);
use_netscape_softupdate_RegKeyEnumerator((JRIEnv*)env);
use_netscape_softupdate_RegEntryEnumerator((JRIEnv*)env);
use_netscape_softupdate_RegistryException((JRIEnv*)env);
}
#ifdef XP_MAC
#pragma export reset
#endif
/* ------------------------------------------------------------------
* VersionRegistry native methods
* ------------------------------------------------------------------
*/
/*
* VersionRegistry::componentPath()
*/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_VersionRegistry_componentPath(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component )
{
char* szComponent;
char pathbuf[MAXREGPATHLEN];
REGERR status;
/* (return NULL if an error occurs) */
struct java_lang_String *javaPath = NULL;
/* convert component from a Java string to a C String */
szComponent = (char*)JRI_GetStringUTFChars( env, component );
/* If conversion is successful */
if ( szComponent != NULL ) {
/* get component path from the registry */
status = VR_GetPath( szComponent, MAXREGPATHLEN, pathbuf );
/* if we get a path */
if ( status == REGERR_OK ) {
/* convert native path string to a Java String */
javaPath = JRI_NewStringPlatform( env, pathbuf, XP_STRLEN(pathbuf), "", 0 );
}
}
return (javaPath);
}
/*
* VersionRegistry::getDefaultDirectory()
*/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_VersionRegistry_getDefaultDirectory(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component )
{
char* szComponent = NULL;
char pathbuf[MAXREGPATHLEN];
REGERR status;
/* (return NULL if an error occurs) */
struct java_lang_String *javaPath = NULL;
/* convert component from a Java string to a C String */
if (component)
szComponent = (char*)JRI_GetStringUTFChars( env, component );
/* If conversion is successful */
if ( szComponent != NULL ) {
/* get component path from the registry */
status = VR_GetDefaultDirectory( szComponent, MAXREGPATHLEN, pathbuf );
/* if we get a path */
if ( status == REGERR_OK ) {
/* convert native path string to a Java String */
javaPath = JRI_NewStringPlatform( env, pathbuf, XP_STRLEN(pathbuf), "", 0 );
}
}
return (javaPath);
}
/*
* VersionRegistry::setDefaultDirectory()
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_VersionRegistry_setDefaultDirectory(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component,
struct java_lang_String* directory )
{
char* szComponent;
char* szDirectory;
REGERR status = REGERR_FAIL;
/* convert component from a Java string to a UTF String for registry */
szComponent = (char*)JRI_GetStringUTFChars( env, component );
/* convert directory to a string in the platform charset */
szDirectory = (char*)JRI_GetStringPlatformChars( env, directory, "", 0 );
/* If conversion is successful */
if ( szComponent != NULL && szDirectory != NULL ) {
/* get component path from the registry */
status = VR_SetDefaultDirectory( szComponent, szDirectory );
}
return (status);
}
/*
* VersionRegistry::componentVersion()
*/
JRI_PUBLIC_API(struct netscape_softupdate_VersionInfo *)
native_netscape_softupdate_VersionRegistry_componentVersion(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component )
{
char* szComponent;
REGERR status;
VERSION cVersion;
/* (return NULL if an error occurs) */
struct netscape_softupdate_VersionInfo * javaVersion = NULL;
/* convert component from a Java string to a C String */
szComponent = (char*)JRI_GetStringUTFChars( env, component );
/* if conversion is successful */
if ( szComponent != NULL ) {
/* get component version from the registry */
status = VR_GetVersion( szComponent, &cVersion );
/* if we got the version */
if ( status == REGERR_OK ) {
/* convert to a java VersionInfo structure */
javaVersion = netscape_softupdate_VersionInfo_new_1(
env,
class_netscape_softupdate_VersionInfo(env),
cVersion.major,
cVersion.minor,
cVersion.release,
cVersion.build,
cVersion.check);
}
}
return (javaVersion);
}
/*
* VersionRegistry::installComponent()
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_VersionRegistry_installComponent(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component,
struct java_lang_String* path,
struct netscape_softupdate_VersionInfo* version )
{
char * szComponent = NULL;
char * szPath = NULL;
char * szVersion = NULL;
REGERR status = REGERR_FAIL;
struct java_lang_String *jVersion = NULL;
/* convert java component to UTF for registry name */
szComponent = (char*)JRI_GetStringUTFChars( env, component );
/* convert path to native OS charset */
szPath = (char*)JRI_GetStringPlatformChars( env, path, "", 0 );
if (version != NULL) {
jVersion = netscape_softupdate_VersionInfo_toString( env, version );
szVersion = (char*)JRI_GetStringUTFChars( env, jVersion );
}
/* if java-to-C conversion was successful */
if ( szComponent != NULL ) {
/* call registry with converted data */
/* XXX need to allow Directory installs also, change in Java */
status = VR_Install( szComponent, szPath, szVersion, 0 );
}
return (status);
}
/*
* VersionRegistry::deleteComponent()
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_VersionRegistry_deleteComponent(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component )
{
char* szComponent;
REGERR status = REGERR_FAIL;
/* convert component from a Java string to a C String */
szComponent = (char*)JRI_GetStringUTFChars( env, component );
/* If conversion is successful */
if ( szComponent != NULL ) {
/* delete entry from registry */
status = VR_Remove( szComponent );
}
/* return status */
return (status);
}
/*
* VersionRegistry::validateComponent()
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_VersionRegistry_validateComponent(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component )
{
char* szComponent = (char*)JRI_GetStringUTFChars( env, component );
if ( szComponent == NULL ) {
return REGERR_FAIL;
}
return ( VR_ValidateComponent( szComponent ) );
}
/*
* VersionRegistry::inRegistry()
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_VersionRegistry_inRegistry(
JRIEnv* env,
struct java_lang_Class* clazz,
struct java_lang_String* component )
{
char* szComponent = (char*)JRI_GetStringUTFChars( env, component );
if ( szComponent == NULL ) {
return REGERR_FAIL;
}
return ( VR_InRegistry( szComponent ) );
}
/*
* VersionRegistry::close
*/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_VersionRegistry_close(
JRIEnv* env,
struct java_lang_Class* clazz )
{
return ( VR_Close() );
}
/* ------------------------------------------------------------------
* VerRegEnumerator native methods
* ------------------------------------------------------------------
*/
/*** private native regNext ()Ljava/lang/String; ***/
/*
* VerRegEnumerator::regNext
*/
JRIEnv* tmpEnv = NULL;
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_VerRegEnumerator_regNext(
JRIEnv* env,
struct netscape_softupdate_VerRegEnumerator* self )
{
REGERR status = REGERR_FAIL;
char pathbuf[MAXREGPATHLEN+1] = {0};
char* pszPath = NULL;
struct java_lang_String* javaPath = NULL;
REGENUM state = 0;
tmpEnv = env;
/* convert path to C string */
pszPath = (char*)JRI_GetStringUTFChars( env,
get_netscape_softupdate_VerRegEnumerator_path( env, self ) );
state = get_netscape_softupdate_VerRegEnumerator_state( env, self );
if ( pszPath != NULL ) {
XP_STRCPY( pathbuf, pszPath );
/* Get next path from Registry */
status = VR_Enum( &state, pathbuf, MAXREGPATHLEN );
/* if we got a good path */
if (status == REGERR_OK) {
/* convert new path back to java */
javaPath = JRI_NewStringUTF( tmpEnv, pathbuf, XP_STRLEN(pathbuf) );
set_netscape_softupdate_VerRegEnumerator_state( env, self, state );
}
}
return (javaPath);
}
/* ------------------------------------------------------------------
* Registry native methods
* ------------------------------------------------------------------
*/
/*** private native nOpen ()I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_Registry_nOpen(
JRIEnv* env,
struct netscape_softupdate_Registry* self)
{
char* pFilename;
HREG hReg;
REGERR status = REGERR_FAIL;
struct java_lang_String *filename;
filename = get_netscape_softupdate_Registry_regName( env, self);
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, self );
/* Registry must not be already open */
if ( hReg == NULL ) {
pFilename = (char*)JRI_GetStringPlatformChars( env, filename, "", 0 );
if ( pFilename != NULL ) {
status = NR_RegOpen( pFilename, &hReg );
if ( REGERR_OK == status ) {
set_netscape_softupdate_Registry_hReg( env, self, (jint)hReg );
}
}
}
return (status);
}
/*** private native nClose ()I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_Registry_nClose(
JRIEnv* env,
struct netscape_softupdate_Registry* self)
{
REGERR status = REGERR_FAIL;
HREG hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, self );
/* Registry must not be already closed */
if ( hReg != NULL) {
status = NR_RegClose( hReg );
if ( REGERR_OK == status ) {
set_netscape_softupdate_Registry_hReg( env, self, (jint)NULL );
}
}
return (status);
}
/*** private native nAddKey (ILjava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_Registry_nAddKey(
JRIEnv* env,
struct netscape_softupdate_Registry* self,
jint rootKey,
struct java_lang_String *keyName)
{
char* pKey;
REGERR status = REGERR_FAIL;
HREG hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, self );
pKey = (char*)JRI_GetStringUTFChars( env, keyName );
if ( pKey != NULL ) {
status = NR_RegAddKey( hReg, rootKey, pKey, NULL );
}
return(status);
}
/*** private native nDeleteKey (ILjava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_Registry_nDeleteKey(
JRIEnv* env,
struct netscape_softupdate_Registry* self,
jint rootKey,
struct java_lang_String *keyName)
{
char* pKey;
REGERR status = REGERR_FAIL;
HREG hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, self );
pKey = (char*)JRI_GetStringUTFChars( env, keyName );
if ( pKey != NULL ) {
status = NR_RegDeleteKey( hReg, rootKey, pKey );
}
return(status);
}
/*** private native nGetKey (ILjava/lang/String;)Ljava/lang/Object; ***/
JRI_PUBLIC_API(struct netscape_softupdate_RegistryNode *)
native_netscape_softupdate_Registry_nGetKey(
JRIEnv* env,
struct netscape_softupdate_Registry* self,
jint rootKey,
struct java_lang_String *keyName,
struct java_lang_String *target )
{
char* pKey;
HREG hReg;
RKEY newkey;
REGERR status = REGERR_FAIL;
struct netscape_softupdate_RegistryNode *regKey = NULL;
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, self );
pKey = (char*)JRI_GetStringUTFChars( env, keyName );
if ( pKey != NULL ) {
status = NR_RegGetKey( hReg, rootKey, pKey, &newkey );
if ( REGERR_OK == status ) {
regKey = netscape_softupdate_RegistryNode_new(
env,
class_netscape_softupdate_RegistryNode(env),
self,
newkey,
target);
}
else {
JRI_ThrowNew(env,
class_netscape_softupdate_RegistryException(env),
"");
}
}
return (regKey);
}
/*** private native nUserName ()Ljava/lang/String; ***/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_Registry_nUserName(
JRIEnv* env,
struct netscape_softupdate_Registry* self)
{
char* profName;
int err;
struct java_lang_String *jname = NULL;
err = PREF_CopyDefaultCharPref( "profile.name", &profName );
if (err == PREF_NOERROR ) {
jname = JRI_NewStringPlatform(env, profName, XP_STRLEN(profName),"",0);
}
return jname;
}
/* ------------------------------------------------------------------
* RegistryNode native methods
* ------------------------------------------------------------------
*/
/*** public native deleteEntry (Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_RegistryNode_nDeleteEntry(
JRIEnv* env,
struct netscape_softupdate_RegistryNode* self,
struct java_lang_String *name)
{
char* pName;
HREG hReg;
RKEY key;
REGERR status = REGERR_FAIL;
struct netscape_softupdate_Registry *reg;
reg = get_netscape_softupdate_RegistryNode_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegistryNode_key( env, self );
pName = (char*)JRI_GetStringUTFChars( env, name );
if ( pName != NULL && hReg != NULL ) {
status = NR_RegDeleteEntry( hReg, key, pName );
}
return status;
}
/*** public native setEntry (Ljava/lang/String;Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_RegistryNode_setEntryS(
JRIEnv* env,
struct netscape_softupdate_RegistryNode* self,
struct java_lang_String *name,
struct java_lang_String *value)
{
char* pName;
char* pValue;
HREG hReg;
RKEY key;
REGERR status = REGERR_FAIL;
struct netscape_softupdate_Registry *reg;
reg = get_netscape_softupdate_RegistryNode_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegistryNode_key( env, self );
pName = (char*)JRI_GetStringUTFChars( env, name );
pValue = (char*)JRI_GetStringUTFChars( env, value );
if ( pName != NULL && pValue != NULL && hReg != NULL ) {
status = NR_RegSetEntryString( hReg, key, pName, pValue );
}
return status;
}
/*** public native setEntry (Ljava/lang/String;[I)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_RegistryNode_setEntryI(
JRIEnv* env,
struct netscape_softupdate_RegistryNode* self,
struct java_lang_String *name,
jintArray value)
{
char* pName;
char* pValue = NULL;
uint32 datalen;
HREG hReg;
RKEY key;
REGERR status = REGERR_FAIL;
struct netscape_softupdate_Registry *reg;
reg = get_netscape_softupdate_RegistryNode_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegistryNode_key( env, self );
pName = (char*)JRI_GetStringUTFChars( env, name );
pValue = (char*)JRI_GetIntArrayElements( env, value );
if ( pName != NULL && pValue != NULL && hReg != NULL ) {
datalen = JRI_GetIntArrayLength( env, value );
status = NR_RegSetEntry( hReg, key, pName,
REGTYPE_ENTRY_INT32_ARRAY, pValue, datalen );
}
return status;
}
/*** public native setEntry (Ljava/lang/String;[B)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_RegistryNode_setEntryB(
JRIEnv* env,
struct netscape_softupdate_RegistryNode* self,
struct java_lang_String *name,
jbyteArray value)
{
char* pName = NULL;
char* pValue = NULL;
uint32 datalen;
HREG hReg;
RKEY key;
REGERR status = REGERR_FAIL;
struct netscape_softupdate_Registry *reg;
reg = get_netscape_softupdate_RegistryNode_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegistryNode_key( env, self );
pName = (char*)JRI_GetStringUTFChars( env, name );
pValue = (char*)JRI_GetByteArrayElements( env, value );
if ( pName != NULL && pValue != NULL && hReg != NULL ) {
datalen = JRI_GetByteArrayLength( env, value );
status = NR_RegSetEntry( hReg, key, pName,
REGTYPE_ENTRY_BYTES, pValue, datalen );
}
return status;
}
/*** public native getEntryType (Ljava/lang/String;)I ***/
JRI_PUBLIC_API(jint)
native_netscape_softupdate_RegistryNode_nGetEntryType(
JRIEnv* env,
struct netscape_softupdate_RegistryNode* self,
struct java_lang_String *name)
{
char* pName;
jint type;
HREG hReg;
RKEY key;
REGERR status = REGERR_FAIL;
REGINFO info;
struct netscape_softupdate_Registry *reg;
XP_ASSERT(REGTYPE_ENTRY_STRING_UTF == netscape_softupdate_Registry_TYPE_STRING);
XP_ASSERT(REGTYPE_ENTRY_INT32_ARRAY == netscape_softupdate_Registry_TYPE_INT_ARRAY);
XP_ASSERT(REGTYPE_ENTRY_BYTES == netscape_softupdate_Registry_TYPE_BYTES);
reg = get_netscape_softupdate_RegistryNode_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegistryNode_key( env, self );
pName = (char*)JRI_GetStringUTFChars( env, name );
if ( pName != NULL && hReg != NULL )
{
info.size = sizeof(REGINFO);
status = NR_RegGetEntryInfo( hReg, key, pName, &info );
if ( REGERR_OK == status ) {
type = info.entryType;
}
}
if ( REGERR_OK == status )
return type;
else
return ( -status );
}
/*** public native getEntry (Ljava/lang/String;)Ljava/lang/Object; ***/
JRI_PUBLIC_API(struct java_lang_Object *)
native_netscape_softupdate_RegistryNode_nGetEntry(
JRIEnv* env,
struct netscape_softupdate_RegistryNode* self,
struct java_lang_String *name)
{
char* pName;
void* pValue;
uint32 size;
HREG hReg;
RKEY key;
REGINFO info;
REGERR status = REGERR_FAIL;
struct netscape_softupdate_Registry *reg;
struct java_lang_Object *valObj = NULL;
reg = get_netscape_softupdate_RegistryNode_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegistryNode_key( env, self );
pName = (char*)JRI_GetStringUTFChars( env, name );
if ( pName != NULL && hReg != NULL )
{
info.size = sizeof(REGINFO);
status = NR_RegGetEntryInfo( hReg, key, pName, &info );
if ( REGERR_OK == status )
{
size = info.entryLength;
pValue = XP_ALLOC(size);
if ( pValue != NULL )
{
status = NR_RegGetEntry( hReg, key, pName, pValue, &size );
if ( REGERR_OK == status )
{
switch ( info.entryType )
{
case REGTYPE_ENTRY_STRING_UTF:
valObj = (struct java_lang_Object *)JRI_NewStringUTF(
env,
(char*)pValue,
XP_STRLEN((char*)pValue) );
break;
case REGTYPE_ENTRY_INT32_ARRAY:
valObj = (struct java_lang_Object *)JRI_NewByteArray(
env,
size,
(char*)pValue );
break;
case REGTYPE_ENTRY_BYTES:
default: /* for unknown types we return raw bits */
valObj = (struct java_lang_Object *)JRI_NewByteArray(
env,
size,
(char*)pValue );
break;
}
}
XP_FREE(pValue);
} /* pValue != NULL */
}
}
return valObj;
}
/* ------------------------------------------------------------------
* RegKeyEnumerator native methods
* ------------------------------------------------------------------
*/
/*** private native regNext ()Ljava/lang/String; ***/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_RegKeyEnumerator_regNext(
JRIEnv* env,
struct netscape_softupdate_RegKeyEnumerator* self,
jbool skip)
{
HREG hReg;
RKEY key;
REGERR status = REGERR_FAIL;
REGENUM state = 0;
uint32 style;
char pathbuf[MAXREGPATHLEN+1] = {0};
char* pPath = NULL;
struct netscape_softupdate_Registry *reg;
struct java_lang_String *path;
struct java_lang_String *javaPath = NULL;
reg = get_netscape_softupdate_RegKeyEnumerator_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegKeyEnumerator_key( env, self );
state = get_netscape_softupdate_RegKeyEnumerator_state( env, self );
style = get_netscape_softupdate_RegKeyEnumerator_style( env, self );
/* convert path to C string */
path = get_netscape_softupdate_RegKeyEnumerator_path( env, self );
pPath = (char*)JRI_GetStringUTFChars( env, path );
if ( pPath != NULL ) {
XP_STRCPY( pathbuf, pPath );
/* Get next path from Registry */
status = NR_RegEnumSubkeys( hReg, key, &state, pathbuf,
sizeof(pathbuf), style );
/* if we got a good path */
if (status == REGERR_OK) {
/* convert new path back to java and save state */
javaPath = JRI_NewStringUTF( env, pathbuf, XP_STRLEN(pathbuf) );
if ( skip ) {
set_netscape_softupdate_RegKeyEnumerator_state( env, self, state );
}
}
}
return (javaPath);
}
/* ------------------------------------------------------------------
* RegEntryEnumerator native methods
* ------------------------------------------------------------------
*/
/*** private native regNext ()Ljava/lang/String; ***/
JRI_PUBLIC_API(struct java_lang_String *)
native_netscape_softupdate_RegEntryEnumerator_regNext(
JRIEnv* env,
struct netscape_softupdate_RegEntryEnumerator* self,
jbool skip)
{
HREG hReg;
RKEY key;
REGERR status = REGERR_FAIL;
REGENUM state = 0;
char namebuf[MAXREGPATHLEN+1] = {0};
char* pName = NULL;
struct netscape_softupdate_Registry *reg;
struct java_lang_String *name;
struct java_lang_String *javaName = NULL;
reg = get_netscape_softupdate_RegEntryEnumerator_reg( env, self );
hReg = (HREG)get_netscape_softupdate_Registry_hReg( env, reg );
key = get_netscape_softupdate_RegEntryEnumerator_key( env, self );
state = get_netscape_softupdate_RegEntryEnumerator_state( env, self );
/* convert name to C string */
name = get_netscape_softupdate_RegEntryEnumerator_name( env, self );
pName = (char*)JRI_GetStringUTFChars( env, name );
if ( pName != NULL ) {
XP_STRCPY( namebuf, pName );
/* Get next name from Registry */
status = NR_RegEnumEntries( hReg, key, &state, namebuf,
sizeof(namebuf), NULL );
/* if we got a good name */
if (status == REGERR_OK) {
/* convert new name back to java and save state */
javaName = JRI_NewStringUTF( env, namebuf, XP_STRLEN(namebuf) );
if (skip)
set_netscape_softupdate_RegEntryEnumerator_state( env, self, state );
}
}
return (javaName);
}
#endif /* !STANDALONE_REGISTRY */