CVS info: $Revision: 1.7 $ $Date: 2008/01/02 15:12:47 $ $State: Exp $ $Locker: $
Remote Tea
Remote Tea Project Home Page on SourceForge.
You already guessed it: minor update/maintenance release.
OncRpcException.RPC_CANNOTREGISTER
will now be thrown if the local portmapper
denies port registration.This is again a minor update/maintenance release.
This is a minor update/maintenance release.
build.xml
Ant script to include also exactly this
build file in the source code zip which gets uploaded to Source Forge.It has been a long time since the previous release ... but yes, I finally managed to pick up the patches sent and rolled them into the new release. Many things changed in the meantime so I'm glad I got this release out of the door at all. My new employer throws all kind of really interesting tasks at me, so RemoteTea is now a really low profile project to me. If volunteers will step forward to maintain RemoteTea I would be glad to welcome them aboard the RemoteTea project.
-bean
to jrpcgen
for generating accessors (setters and getters)
for all elements in a structure. Option -bean
also implies
-ser
. This feature bases on a patch from Ralph Neff.jrpcgen
now also accepts .x files without a
program section. In this case no stub classes are generated, but
Java source code files for all structures, enums, et cetera are still
generated. This feature bases on a patch from Bialas Krzysztof.jrpcgen.jar
.This release marks my movement from the website of the good old
Chair of Process Control Engineering to Sourceforge. Since
Remote Tea
has now quite some users, it was time to put the
project on its own feet. Let's see where this will lead to.
helloto the new Eclipse project files. With the switch to Eclipse we now have a free IDE for a free ONC/RPC package and if you use ClassPath and an appropriate VM, then the whole thing is free.
EclipseIDE, but also other
smart asses.
OncRpcClient
class now has a pair of accessors
setCharacterEncoding(encoding)
and
getCharacterEncoding()
. Similiar, OncRpcServerStub
gives control over character encoding on the server side.todowork done, so that jrpcgen now emits more useful information in the javadoc tags for remote procedure parameters and results.
call$
and of type
OncRpcCallInformation
.NullPointerExceptions
. Many thanks to Michael Smith for
hunting down this one. Classes concerned are
OncRpcTcpConnectionServerTransport
,
OncRpcTcpServerTransport
and
OncRpcUdpServerTransport
.main
and jrpcgen stumbled
on an error. This allows jrpcgen to be
used in classic make projects. The Apache Ant is not affected by
this behavior.OncRpcTcpServerTransport
and
OncRpcUdpServerTransport
. It accepts now a local
binding address. The server socket is then bound only to this/these
local address(es). In addition, jrpcgen now emits source code for server
stubs with an additional constructor which accepts the additional
binding address.OncRpcTcpSocketHelper.connect()
to accept a negative
timeout that signals to use the particular implementation-specific
timeout value.OncRpcTcpClient
,
which accepts a timeout parameter (in milliseconds) as its last
argument. This constructor can be used to limit the connection
attempt period and finally makes the timeout functionality available
which has been implemented in the 0.95.1 release. It is important
to note that the timeout specified as the parameter to the
constructor does not apply to later ONC/RPC calls. These are
controlled as usual through the existing timeout-related
accessors.OncRpcPortmapClient
a stand-alone class,
which is not derived from OncRpcUdpClient
any
more. This now allows applications to contact the portmapper either
using UDP/IP or TCP/IP (HTTP not yet supported).OncRpcConstants
(I had forgotten to do so for the
previous releases...).After a long time (and a Ph.D. thesis on metamodelling for communication in operational process control engineering now written and on its way) I've finally managed to get a new RemoteTea release out of the door.
The socket helper object features a connect
method
which can execute timeout-controlled connection establishment. In
case the current VM Remote Tea is running on does not provide a
proper implementation, Remote Tea resorts to the following
algorithm:
connect
method creates a new thread
which in turn tries to connect to the given port at the given host
(an instance of the local class Connectiator
is
responsible for this).connect
method. In case
the Connectiator does not succeed within the timeout period, an
IOException
is thrown by the connect
method.getIOException
method then either returns null
or an
IOException
.XdrDecodingStream.xdrDecodeLong()
, where unwanted sign
extension messed up 64 bit wide integers (XDR hypers).featurein
XdrTcpDecodingStream.fill()
, which caused invalid
header decoding if the fragment length was larger than
227.XdrTcpDecodingStream
semantics of
the fill
method were slightly changed to return also in
case of empty trailing record (lastFragment
attribute
must be true
). All methods directly calling
fill
have been adapted (at least I hope
so).XdrHttpDecodingStream
, for which
patches were kindly offered by the austrian internet
chamoises.org.acplt.oncrpc.ant.JrpcgenTask
, kindly provided by
Jean-Francois Daune. This also involved some small changes to jrpcgen in order to make it available as a
task.test caseto
demo.x
.serialVersionUID
using the
SHA-1 algorithm. (My thanks to the GNU classpath project for
providing the SHA-1 algorithm, please see
Jrpcgen.SHA.java
for license details).Strings
as empty strings (""). Note
that this may lead to lazy programming; better make explicitly
sure that every member of a struct gets initialized properly
before encoding the struct.OncRpcTcpServerTransport.TransportList
).InetAddress.getLocalHost
. The code now uses
InetAdress.getByName("127.0.0.1")
. Yeah, write once,
does not work anywhere.client.call
method which
expects an additional (procedure/protocol) version number as its
second argument. This method is necessary so several versions can
coexists peacefully in one client and can be called
simultaneously. As before, if you do not specify a version in the
call to client.call
the defaultversion is used as specified in the constructor. Please note that
OncRpcClient
-derived classes must now implement the
overloaded call
method expecting four parameters:
procedure number, version number, parameters, and result (this only
applies to those who want to implement their own ONC/RPC clients for
different transports than those already provided).OncRpcServerStub
methods public
(instead of protected), to give derived server classes more control
over the way they spin up and down.OncRpcTcpSocket
. So much for almost not
testing the release. To fix this stupid design bug the classes
OncRpcTcpSocket
and OncRpcUdpSocket
were
moved to OncRpcTcpSocketHelper
and
OncRpcUdpSocketHelper
. They now merely support
Socket
and DatagramSocket
instead of
inheriting from them. This avoids the endless reflection method
invocation loop, but is still cheaper in terms of method invocation
performance than a wrapper class.AUTH_NONE
on
the server side in OncRpcServerAuth.xdrNew
when
recycling the AUTH_NONE
handler singleton.transports
field within
class OncRpcServerStub
. Registering with the portmapper
as well as dispatching calls is now done within the
run()
method (note: without any parameters). You need
to change your code accordingly by inserting a call to
run()
, otherwise the server will not start.
MyServer myserver = new MyServer(); myserver.run();
java, some files were moved. The JBuilder project files have been moved to the
projects/
subdirectory.demo.x
example now tests some pathological
cases.addElement
instead of
add
when adding objects to a
Vector
.readme-first/
which should be more obvious to
first-time users of the RemoteTea source code and does not clobber
the projects/
directory any more.NullPointerException
in
OncRpcTcpClient
and OncRpcUdpClient
when
checking for rejected credentials and I thought Java had no
pointers.unsigned
in addition to unsigned int
(compatibility with rpcgen
). Handling of octal numbers
added (okay, it is still a valid number format). Fixed bug in the
code generation of desciminated unions using booleans. Support for
more than one program definition within the same x-file. In this
case the source code files generated for the client and server stubs
are named
<x-filename><program-id>Client.java
and
<x-filename><program-id>Server.java
,
respectively.Tea TunnelApache DSO module, which
untunnelscalls and forwards them to the appropriate ONC/RPC server using direct TCP/IP or UDP/IP connections (or non-connections in the case of UDP/IP).
org.acplt.oncrpc.web
containing helper classes for HTTP client connections
(HttpClientConnection
), and base64 encoding and
decoding (Base64
), as well as some other
stuff.OncRpcHttpClient
, which
stands in the tradition of OncRpcClient
and implements
sending ONC/RPC calls through HTTP tunnels. Also added
XdrHttpDecodingStream
, which can pull base64 encoded
data from a web server and provide the decoded data through the
usual decoding XDR stream interface.XdrEncodingStream.xdrEncodeByteFixedVector()
which
falsely encoded length information about the following array of
characters. I should take more care when doing Italian code
recycling
using copy & pasta...OncRpcTcpClient.call()
which
caused XDR buffer underflows when receiving the next reply after the
previous reply has been rejected by an ONC/RPC server.org.acplt.oncrpc
to put it in sync with (de-)
serializing fixed-size vectors and dynamic and fixed vectors of
characters.AUTH_UNIX
authentication. For this to
achieve quite some additions and changes were necessary
luckily, old applications will not be broken, as the changes are
deep within the RemoteTea package:
OncRpcClientAuth
,
OncRpcClientAuthNone
and
OncRpcClientAuthUnix
were added.OncRpcReplyMessage
and OncRpcCallMessage
are now both abstract. This was necessary because ONC/RPC protocol
issues make it necessary to handle authentication through
so-called authentication protocol handling objects different on
the client side than on the server side. Additional classes now
handle sending calls and receiving replies on the client side
(OncRpcClientCallMessage
and
OncRpcClientReplyMessage
respectively), as well as on
the server side (OncRpcServerCallMessage
and
OncRpcServerReplyMessage
). According to their needs,
these new classes only declare those encoding and decoding methods
which are really needed. In consequence, the base class
OncRpcCallMessage
has lost its XdrAble
interface completely.OncRpcUdpClient
and OncRpcTcpClient
,
as well as to the base class
OncRpcClient
.callMessage.auth
attribute
of the OncRpcCallInformation
delivered with each
incomming ONC/RPC call. See
tests.org.acplt.oncrpc.ServerTest.java
for an
example.AUTH_DES
is still not supported, as
this needs quite some things to be done and I don't have full
information about the AUTH_DES
protocol.
XdrBufferEncodingStream
and
XdrBufferDecodingStream
for encoding and decoding XDR
data from and to a fixed-size buffer. These classes comes in handy
when dealing with shorthand credentials.XdrDynamicOpaque
to handle
variable-sized vectors of bytes.org.acplt.oncrpc.apps.jrpcgen
, because it's an
application belonging very tight to ONC/RPC.OncRpcConstants.REMOTETEA_VERSION_PREVERSION
, which
indicates preversions if not zero.char<>
as a
series of characters, each one sitting happily in its very own XDR
int (that is, four bytes), the two methods
XdrDecodingStream.xdrDecodeBytes()
and
XdrEncodingStream.xdrEncodeBytes()
were renamed to
XdrDecodingStream.xdrDecodeByteVector()
and
XdrEncodingStream.xdrEncodeByteVector()
as well as
their semantics changed accordingly.XdrDecodingStream.xdrDecodeDynamicOpaque()
,
XdrEncodingStream.xdrEncodeDynamicOpaque()
,
XdrDecodingStream.xdrDecodeByteFixedVector()
and
XdrEncodingStream.xdrEncodeByteFixedVector()
.XdrDecodingStream
and XdrEncodingStream
finally final
. Maybe this helps Java compilers improve
code speed. Maybe.XdrDecodingStream
and
XdrEncodingStream
.readBuffer()
to class
XdrTcpDecodingStream
. This fixes problems when reading
from a TCP/IP stream and not all bytes wanted are immediately
available, thus stream.read()
returning not all bytes
at once (shame on me for not reading the java.io documentation
attentive enough).optional datain ONC/RPC babble. Also added a new test case to the demo.x file.
broadcastCall
of method
in class OncRpcUdpClient
.Read The Source, Luke!) to find out what syntax and grammar rpcgen does in fact use. Please give it a try and report problems. Note that there is no preprocessor step.
xdrDecodeOpaque(int)
and
xdrDecodeOpaque(byte[],int,int)
. This cures the bug
where a XDR string being the last piece of information in a RPC call
or reply could not be read successfully.org.acplt.oncrpc.OncRpcConstants
, which
contains versioning information.Remote Teafrom the ACPLTea package. As the ONC/RPC implementation is pretty functional the version number was changed to reflect this.
CVS info: $Revision: 1.1 $ $Date: 2003/08/14 11:33:03 $ $State: Exp $ $Locker: $
The whole release shebang is summarized in our Change Log.
As always, the most current information about the Remote Tea Java Library, as well as updates, can be found on the web at the Remote Tea ONC/RPC Home Page.
The Remote Tea Java Library is licensed under the terms of the GNU Library General Public License (LGPL).
Rationale: while the LGPL does not restrict the use of my packages even in commercial applications, I am ensuring this way that modifications to the source code must be given back to the comunity. If you use my packages in commercial applications, you must either include the source code of the Remote Tea ONC/RPC Java Library or provide the source code to your customers on request. The details can be found in the LGPL terms.
The directory structure is as follows. Due to the transition to the Eclipse IDE and Ant not everything is currently in place and perfect shape.
javadoc/
: Remote Tea
ONC/RPC documentationsrc/
: source code of the Remote Tea ONC/RPC
Java Library.
src/org/acplt/oncrpc
contains the source
code of the various packages.src/org/acplt/oncrpc/apps
contains
applications, in this case only the jrpcgen rpc protocol compiler in the
jrpcgen/
subdirectory.src/tests
contains test code.src/tests/org/acplt/oncrpc/jrpcgen
contains
an example of how to use the jrpcgen
rpc protocol
compiler. To generate source code from the x-file, run:
java -jar jrpcgen.jar -p tests.org.acplt.oncrpc.jrpcgen -nobackup demo.x
classes/
: will receive the compiled Java
bytecode. After running the Ant build.xml
makefile with
target jar, this directory will also contain two jar files called
classes/oncrpc.jar
and
classes/jrpcgen.jar
.The Remote Tea
ONC/RPC Java package is currently being
developed and tested using Eclipse on a JDK 1.4.2 (Windows).
Those who like to compile the sources by themselves might want to
use either the Eclipse .project
file or the Ant makefile
build.xml
(this is not really functional yet), both are
located in the root directory of this package.
The Remote Tea
Java Package has been written by Harald
Albrecht (harald@plt.rwth-aachen.de).
© 1999, 2003 Chair of Process Control Engineering,
Aachen University of Technology,
52064 Aachen, Germany
The Remote Tea library is a complete open source implementation of * the ONC/RPC standard, developped by the Chair of Process Control * Engineering of University of Aachen, Germany. *
Remote Tea can be found at * * http://www.plt.rwth-aachen.de/ks/english/remotetea.html. * *
The task attributes are: *
OncRpcEmbeddedPortmap
provides an embeddable
* portmap service, which is automatically started in its own thread if
* the (operating) system does not already provide the portmap service.
* If an embedded portmap service is started it will stop only after the
* last ONC/RPC program has been deregistered.
*
* @version $Revision: 1.2 $ $Date: 2003/08/14 08:00:08 $ $State: Exp $ $Locker: $
* @author Harald Albrecht
*/
public class OncRpcEmbeddedPortmap {
/**
* Constructs an embeddable portmap service of class
* OncRpcEmbeddedPortmap
and starts the service if no
* other (external) portmap service is available. This constructor is
* the same as OncRpcEmbeddedPortmap
calling with a
* timeout of 3 seconds.
*
* The constructor starts the portmap service in its own thread and
* then returns.
*
* @see OncRpcEmbeddedPortmap#embeddedPortmapInUse
*/
public OncRpcEmbeddedPortmap()
throws OncRpcException, IOException {
this(3000);
}
/**
* Constructs an embeddable portmap service of class
* OncRpcEmbeddedPortmap
and starts the service if no
* other (external) portmap service is available.
*
*
The constructor starts the portmap service in its own thread and
* then returns.
*
* @param checkTimeout timeout in milliseconds to wait before assuming
* that no portmap service is currently available.
*
* @see OncRpcEmbeddedPortmap#embeddedPortmapInUse
*/
public OncRpcEmbeddedPortmap(int checkTimeout)
throws OncRpcException, IOException {
if ( !isPortmapRunning(checkTimeout) ) {
embeddedPortmap = new embeddedjportmap();
embeddedPortmapThread = new OncRpcEmbeddedPortmapThread(embeddedPortmap);
embeddedPortmap.serviceThread = embeddedPortmapThread;
// Do not make portmap thread a daemon, otherwise it would be
// simply terminated when an application using it finishes.
// embeddedPortmapThread.setDaemon(true);
embeddedPortmapThread.start();
}
}
/**
* Indicates whether a portmap service (regardless whether it's supplied
* by the operating system or an embedded portmap service) is currently
* running. This method will check for 3 seconds for an answer from a
* portmap before assuming that no one exists.
*
* @return true
, if a portmap service (either external or
* embedded) is running and can be contacted.
*/
public static boolean isPortmapRunning() {
return isPortmapRunning(3000);
}
/**
* Indicates whether a portmap service (regardless whether it's supplied
* by the operating system or an embedded portmap service) is currently
* running.
*
* @param checkTimeout timeout in milliseconds to wait before assuming
* that no portmap service is currently available.
*
* @return true
, if a portmap service (either external or
* embedded) is running and can be contacted.
*/
public static boolean isPortmapRunning(int checkTimeout) {
boolean available = false;
try {
OncRpcPortmapClient portmap =
new OncRpcPortmapClient(InetAddress.getByName("127.0.0.1"));
portmap.getOncRpcClient().setTimeout(checkTimeout);
portmap.ping();
available = true;
} catch ( OncRpcException e ) {
} catch ( IOException e ) {
}
return available;
}
/**
* Indicates whether the embedded portmap service is in use.
*
* @return true
, if embedded portmap service is currently
* used.
*/
public boolean embeddedPortmapInUse() {
return embeddedPortmapThread != null;
}
/**
* Returns the thread object running the embedded portmap service.
*
* @return Thread object or null
if no embedded portmap
* service has been started.
*/
public Thread getEmbeddedPortmapServiceThread() {
return embeddedPortmapThread;
}
/**
* Returns object implementing the embedded portmap service.
*
* @return Embedded portmap object or null
if no
* embedded portmap service has been started.
*/
public jportmap getEmbeddedPortmap() {
return embeddedPortmap;
}
/**
* Stop the embedded portmap service if it is running. Normaly you should
* not use this method except you need to force the embedded portmap
* service to terminate. Under normal conditions the thread responsible
* for the embedded portmap service will terminate automatically after the
* last ONC/RPC program has been deregistered.
*
*
This method
* just signals the portmap thread to stop processing ONC/RPC portmap
* calls and to terminate itself after it has cleaned up after itself.
*/
public void shutdown() {
OncRpcServerStub portmap = embeddedPortmap;
if ( portmap != null ) {
portmap.stopRpcProcessing();
}
}
/**
* Portmap object acting as embedded portmap service or null
* if no embedded portmap service is necessary because the operating
* system already supplies one or another portmapper is already running.
*/
protected embeddedjportmap embeddedPortmap;
/**
* References thread object running the embedded portmap service.
*/
protected Thread embeddedPortmapThread;
/**
* Extend the portmap service so that it automatically takes itself out
* of service when the last ONC/RPC programs is deregistered.
*/
class embeddedjportmap extends jportmap {
/**
* Creates a new instance of an embeddable portmap service.
*/
public embeddedjportmap() throws IOException, OncRpcException { }
/**
* Thread running the embedded portmap service.
*/
protected Thread serviceThread;
/**
* Deregister all port settings for a particular (program, version) for
* all transports (TCP, UDP, ...). This method basically falls back to
* the implementation provided by the jrpcgen
superclass,
* but checks whether there are other ONC/RPC programs registered. If
* not, it signals itself to shut down the portmap service.
*
* @param params (program, version) to deregister. The protocol and port
* fields are not used.
*
* @return true
if deregistration succeeded.
*/
XdrBoolean unsetPort(OncRpcServerIdent params) {
XdrBoolean ok = super.unsetPort(params);
if ( ok.booleanValue() ) {
//
// Check for registered programs other than PMAP_PROGRAM.
//
boolean onlyPmap = true;
int size = servers.size();
for ( int idx = 0; idx < size; ++idx ) {
if ( ((OncRpcServerIdent)servers.elementAt(idx)).program
!= PMAP_PROGRAM ) {
onlyPmap = false;
break;
}
}
//
// If only portmap-related entries are left, then shut down this
// portmap service.
//
if ( onlyPmap && (serviceThread != null) ) {
stopRpcProcessing();
}
}
return ok;
}
}
/**
* The class OncRpcEmbeddedPortmapThread
implements a thread
* which will run an embedded portmap service.
*/
class OncRpcEmbeddedPortmapThread extends Thread {
/**
* Construct a new embedded portmap service thread and associate
* it with the portmap object to be used as the service. The service
* is not started yet.
*/
public OncRpcEmbeddedPortmapThread(embeddedjportmap portmap) {
super("embedded portmap service thread");
this.portmap = portmap;
}
/**
* Run the embedded portmap service thread, starting dispatching
* of all portmap transports until we get the signal to shut down.
*/
public void run() {
try {
portmap.run(portmap.transports);
} catch ( Exception e ) {
}
portmap.close(portmap.transports);
portmap.serviceThread = null;
}
/**
* The embedded portmap service object this thread belongs to. The
* service object implements the ONC/RPC dispatcher and the individual
* remote procedures for a portmapper).
*/
private embeddedjportmap portmap;
}
}
// End of OncRpcEmbeddedPortmap.java
remotetea-1.0.7/src/org/acplt/oncrpc/apps/jportmap/jportmap.java 0000644 0053747 0000341 00000035576 07716652732 026122 0 ustar picca instrumentation /*
* $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jportmap/jportmap.java,v 1.2 2003/08/14 11:26:50 haraldalbrecht Exp $
*
* Copyright (c) 2001
* Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
* D-52064 Aachen, Germany.
* All rights reserved.
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Library General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this program (see the file COPYING.LIB for more
* details); if not, write to the Free Software Foundation, Inc.,
* 675 Mass Ave, Cambridge, MA 02139, USA.
*/
package org.acplt.oncrpc.apps.jportmap;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Vector;
import org.acplt.oncrpc.*;
import org.acplt.oncrpc.server.*;
/**
* The class jportmap
implements a Java-based ONC/RPC port mapper,
* speaking the widely deployed protocol version 2.
*
*
This class can be either used stand-alone (a static main
is
* provided for this purpose) or as part of an application. In this case you
* should check first for another portmap already running before starting your
* own one.
*
* @version $Revision: 1.2 $ $Date: 2003/08/14 11:26:50 $ $State: Exp $ $Locker: $
* @author Harald Albrecht
*/
public class jportmap extends OncRpcServerStub
implements OncRpcDispatchable {
/**
* Create a new portmap instance, create the transport registration
* information and UDP and TCP-based transports, which will be bound
* later to port 111. The constructor does not start the dispatcher loop.
*/
public jportmap()
throws OncRpcException, IOException {
//
// We only need to register one {progam, version}.
//
info = new OncRpcServerTransportRegistrationInfo [] {
new OncRpcServerTransportRegistrationInfo(PMAP_PROGRAM, PMAP_VERSION)
};
//
// We support both UDP and TCP-based transports for ONC/RPC portmap
// calls, and these transports are bound to the well-known port 111.
//
transports = new OncRpcServerTransport [] {
new OncRpcUdpServerTransport(this, PMAP_PORT, info, 32768),
new OncRpcTcpServerTransport(this, PMAP_PORT, info, 32768)
};
//
// Finally, we add ourself to the list of registered ONC/RPC servers.
// This is just a convenience.
//
servers.addElement(new OncRpcServerIdent(
PMAP_PROGRAM, PMAP_VERSION, OncRpcProtocols.ONCRPC_TCP, PMAP_PORT));
servers.addElement(new OncRpcServerIdent(
PMAP_PROGRAM, PMAP_VERSION, OncRpcProtocols.ONCRPC_UDP, PMAP_PORT));
//
// Determine all local IP addresses assigned to this host.
// Once again, take care of broken JDKs, which can not handle
// InetAdress.getLocalHost() properly. Sigh.
//
try {
InetAddress loopback = InetAddress.getByName("127.0.0.1");
InetAddress [] addrs = InetAddress.getAllByName("127.0.0.1");
//
// Check whether the loopback address is already included in
// the address list for this host. If not, add it to the list.
//
boolean loopbackIncluded = false;
for ( int idx = 0; idx < addrs.length; ++idx ) {
if ( addrs[idx].equals(loopback) ) {
loopbackIncluded = true;
break;
}
}
if ( loopbackIncluded ) {
locals = addrs;
} else {
locals = new InetAddress[addrs.length + 1];
locals[0] = loopback;
System.arraycopy(addrs, 0, locals, 1, addrs.length);
}
} catch ( UnknownHostException e ) {
//
// Trouble getting all addresses for this host (which might
// have been caused by some dumb security manager -- yeah, as
// if managers were not dumb by definition), so fall back to
// allowing only the loopback address.
//
locals = new InetAddress[1];
locals[0] = InetAddress.getByName("127.0.0.1");
}
}
/**
* Lookup port for (program, version, protocol). If no suitable
* registration entry if found and an entry with another version, but the
* same program and version number is found, this is returned instead.
* This is compatible with the way Sun's portmap implementation works.
*
* @param params server identification (program, version, protocol) to
* look up. The port field is not used.
*
* @return port number where server listens for incomming ONC/RPC calls,
* or 0
, if no server is registered for (program, protocol).
*/
OncRpcGetPortResult getPort(OncRpcServerIdent params) {
OncRpcServerIdent ident = null;
OncRpcGetPortResult result = new OncRpcGetPortResult();
int size = servers.size();
for ( int idx = 0; idx < size; ++idx ) {
OncRpcServerIdent svr = (OncRpcServerIdent) servers.get(idx);
if ( (svr.program == params.program)
&& (svr.protocol == params.protocol) ) {
//
// (program, protocol) already matches. If it has the same
// version, then we're done. Otherwise we remember this
// entry for possible later usage and search further through
// the list.
//
if ( svr.version == params.version ) {
result.port = svr.port;
return result;
}
ident = svr;
}
}
//
// Return port of "best" match, if one was found at all, otherwise
// just return 0, which indicates an invalid UDP/TCP port.
//
if ( ident == null ) {
result.port = 0;
} else {
result.port = ident.port;
}
return result;
}
/**
* Register a port number for a particular (program, version, protocol).
* Note that a caller can not register the same (program, version,
* protocol) for another port. In this case we return false. Thus, a
* caller first needs to deregister any old entries which it whishes to
* update. Always add new registration entries to the end of the list
* (vector).
*
* @param params (program, version, protocol, port) to register.
*
* @return true
if registration succeeded.
*/
XdrBoolean setPort(OncRpcServerIdent params) {
if ( params.program != PMAP_PROGRAM ) {
//
// Only accept registration attempts for anything other than
// the portmapper. We do not want clients to play tricks on us.
//
int size = servers.size();
for ( int idx = 0; idx < size; ++idx ) {
OncRpcServerIdent svr = (OncRpcServerIdent) servers.get(idx);
if ( (svr.program == params.program)
&& (svr.version == params.version)
&& (svr.protocol == params.protocol) ) {
//
// In case (program, version, protocol) is already
// registered only accept, if the port stays the same.
// This will silently accept double registrations (i.e.,
// due to duplicated UDP calls).
//
return new XdrBoolean(svr.port == params.port);
}
}
//
// Add new registration entry to end of the list.
//
servers.addElement(params);
return new XdrBoolean(true);
}
return new XdrBoolean(false);
}
/**
* Deregister all port settings for a particular (program, version) for
* all transports (TCP, UDP, ...). While these are strange semantics,
* they are compatible with Sun's portmap implementation.
*
* @param params (program, version) to deregister. The protocol and port
* fields are not used.
*
* @return true
if deregistration succeeded.
*/
XdrBoolean unsetPort(OncRpcServerIdent params) {
boolean ok = false;
if ( params.program != PMAP_PROGRAM ) {
//
// Only allow clients to deregister ONC/RPC servers other than
// the portmap entries.
//
int size = servers.size();
for ( int idx = size - 1; idx >= 0; --idx ) {
OncRpcServerIdent svr = (OncRpcServerIdent) servers.get(idx);
if ( (svr.program == params.program)
&& (svr.version == params.version) ) {
servers.removeElementAt(idx);
ok = true;
}
}
}
return new XdrBoolean(ok);
}
/**
* Return list of registered ONC/RPC servers.
*
* @return list of ONC/RPC server descriptions (program, version,
* protocol, port).
*/
OncRpcDumpResult listServers() {
OncRpcDumpResult result = new OncRpcDumpResult();
result.servers = servers;
return result;
}
/**
* Checks whether the address given belongs to one of the local
* addresses of this host.
*
* @param addr IP address to check.
*
* @return true
if address specified belongs to one of the
* local addresses of this host.
*/
boolean isLocalAddress(InetAddress addr) {
int size = locals.length;
for ( int idx = 0; idx < size; ++idx ) {
if ( addr.equals(locals[idx]) ) {
return true;
}
}
return false;
}
/**
* Dispatch incomming ONC/RPC calls to the individual handler functions.
* The CALLIT method is currently unimplemented.
*
* @param call The ONC/RPC call, with references to the transport and
* XDR streams to use for retrieving parameters and sending replies.
* @param program the portmap's program number, 100000
* @param version the portmap's protocol version, 2
* @param procedure the procedure to call.
*
* @throws OncRpcException if an ONC/RPC error occurs.
* @throws IOException if an I/O error occurs.
*/
public void dispatchOncRpcCall(OncRpcCallInformation call,
int program, int version, int procedure)
throws OncRpcException, IOException {
//
// Make sure it's the right program and version that we can handle.
// (defensive programming)
//
if ( program == PMAP_PROGRAM ) {
if ( version == PMAP_VERSION ) {
switch ( procedure ) {
case 0: { // handle NULL call.
call.retrieveCall(XdrVoid.XDR_VOID);
call.reply(XdrVoid.XDR_VOID);
break;
}
case OncRpcPortmapServices.PMAP_GETPORT: { // handle port query
OncRpcServerIdent params = new OncRpcServerIdent();
call.retrieveCall(params);
OncRpcGetPortResult result = getPort(params);
call.reply(result);
break;
}
case OncRpcPortmapServices.PMAP_SET: { // handle port registration
//
// ensure that no remote client tries to register
//
OncRpcServerIdent params = new OncRpcServerIdent();
call.retrieveCall(params);
XdrBoolean result;
if ( isLocalAddress(call.peerAddress) ) {
result = setPort(params);
} else {
result = new XdrBoolean(false);
}
call.reply(result);
break;
}
case OncRpcPortmapServices.PMAP_UNSET: { // handle port deregistration
OncRpcServerIdent params = new OncRpcServerIdent();
call.retrieveCall(params);
XdrBoolean result;
if ( isLocalAddress(call.peerAddress) ) {
result = unsetPort(params);
} else {
result = new XdrBoolean(false);
}
call.reply(result);
break;
}
case OncRpcPortmapServices.PMAP_DUMP: { // list all registrations
call.retrieveCall(XdrVoid.XDR_VOID);
OncRpcDumpResult result = listServers();
call.reply(result);
break;
}
default: // unknown/unimplemented procedure
call.failProcedureUnavailable();
}
} else {
call.failProgramMismatch(PMAP_VERSION, PMAP_VERSION);
}
} else {
call.failProgramUnavailable();
}
}
/**
* List of IP addresses assigned to this host. Will be filled later
* by constructor.
*/
public InetAddress [] locals = null;
/**
* The list of registrated servers.
*/
public Vector servers = new Vector();
/**
* Create an instance of an ONC/RPC portmapper and run it. As we have
* to bootstrap the ONC/RPC port information chain, we do not use the
* usual overloaded run()
method without any parameters,
* but instead supply it the transports to handle. Registration and
* deregistration is not necessary and not possible.
*/
public static void main(String[] args) {
try {
jportmap pmap = new jportmap();
pmap.run(pmap.transports);
pmap.close(pmap.transports);
} catch ( OncRpcException e ) {
e.printStackTrace(System.out);
} catch ( IOException e ) {
e.printStackTrace(System.out);
}
}
/**
* Well-known port where the portmap process can be found on Internet hosts.
*/
public static final int PMAP_PORT = 111;
/**
* Program number of the portmapper as defined in RFC 1832.
*/
public static final int PMAP_PROGRAM = 100000;
/**
* Program version number of the portmapper as defined in RFC 1832.
*/
public static final int PMAP_VERSION = 2;
}
// End of jportmap.java
remotetea-1.0.7/src/org/acplt/oncrpc/apps/jportmap/package.html 0000644 0053747 0000341 00000003413 10627063130 025644 0 ustar picca instrumentation
This package implements a Java-based ONC/RPC portmap compatible with Sun's portmap, protocol version 2.
In case you really do not want to use a native portmap designed for
your particular operating system, you can use jportmap
as
a substitute (nod, nod...). I must be (beep) writing a Java-based portmap.
There is also an embeddable portmap service available as class
OncRpcEmbeddedPortmap
.
This can be used to make sure that a portmap service is always available, even
if the operating system does not provide one or it is not installed or not
enabled.
This package is part of the Remote Tea Java ONC/RPC Library package. (c) 2001, 2006 Harald Albrecht.
This library is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with this program (see the file COPYING.LIB for more details); if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |