store = new ConcurrentHashMap<>();
11 | private final AtomicInteger requestCounter = new AtomicInteger(0);
12 | private volatile long sleepFor = 1L;
13 |
14 | @Override
15 | public void put_1(RpcCall call$, Key key, Value value) {
16 | String hexKey = bytesToHex(key.data);
17 | store.put(hexKey, value.data);
18 | requestCounter.incrementAndGet();
19 | if (sleepFor > 0) {
20 | try {
21 | Thread.sleep(sleepFor);
22 | } catch (InterruptedException ignored) {}
23 | }
24 | }
25 |
26 | @Override
27 | public Value get_1(RpcCall call$, Key key) {
28 | String hexKey = bytesToHex(key.data);
29 | byte[] value = store.get(hexKey);
30 | Value res = new Value();
31 | if (value != null) {
32 | res.notNull = true;
33 | res.data = value;
34 | }
35 | requestCounter.incrementAndGet();
36 | return res;
37 | }
38 |
39 | public long getSleepFor() {
40 | return sleepFor;
41 | }
42 |
43 | public void setSleepFor(long sleepFor) {
44 | this.sleepFor = sleepFor;
45 | }
46 |
47 | public int getNumRequestsProcessed() {
48 | return requestCounter.get();
49 | }
50 |
51 | public static String bytesToHex(byte[] bytes) {
52 | return BaseEncoding.base16().upperCase().encode(bytes);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenParserException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenParserException.java,v 1.1.1.1 2003/08/13 12:03:46 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | /**
28 | * The JrpcgenParserException class represents a parser
29 | * exception indicating to abort parsing the x-file.
30 | *
31 | * @version $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:46 $ $State: Exp $ $Locker: $
32 | * @author Harald Albrecht
33 | */
34 | class JrpcgenParserException extends RuntimeException {
35 |
36 | /**
37 | * Constructs a JrpcgenParserException with no detail message.
38 | */
39 | public JrpcgenParserException() {
40 | super();
41 | }
42 |
43 | }
44 |
45 | // End of JrpcgenParserException.java
46 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrInt.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcException;
23 | import java.io.IOException;
24 |
25 | public class XdrInt implements XdrAble {
26 |
27 | private int _value;
28 |
29 | public XdrInt() {
30 | }
31 |
32 | public XdrInt(int value) {
33 | _value = value;
34 | }
35 |
36 | /**
37 | * Returns the value of this XdrInt object as an {@code int}.
38 | * @return value of this XdrInt as {@code int}.
39 | */
40 | public int intValue() {
41 | return _value;
42 | }
43 |
44 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
45 | _value = xdr.xdrDecodeInt();
46 | }
47 |
48 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
49 | xdr.xdrEncodeInt(_value);
50 | }
51 | }
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcMessageParserUDP.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.Xdr;
23 | import java.io.IOException;
24 | import org.glassfish.grizzly.Buffer;
25 | import org.glassfish.grizzly.filterchain.BaseFilter;
26 | import org.glassfish.grizzly.filterchain.FilterChainContext;
27 | import org.glassfish.grizzly.filterchain.NextAction;
28 |
29 | /**
30 | * {@code Filter} to receive RPC message over UDP connection.
31 | * According to RFC 1831 RPC message over UDP arrived in a single
32 | * UDP packet.
33 | */
34 | public class RpcMessageParserUDP extends BaseFilter {
35 |
36 | @Override
37 | public NextAction handleRead(FilterChainContext ctx) throws IOException {
38 | Buffer messageBuffer = ctx.getMessage();
39 |
40 | Xdr xdr = new Xdr(messageBuffer, ctx.getMemoryManager());
41 | ctx.setMessage(xdr);
42 |
43 | return ctx.getInvokeAction();
44 | }
45 | }
46 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcAuth.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.XdrAble;
23 | import javax.security.auth.Subject;
24 |
25 | public interface RpcAuth extends XdrAble {
26 |
27 | /**
28 | * Get the authentication flavor. The rfc 1831 defines the following flavors:
29 | *
30 | * AUTH_NONE = 0
31 | * AUTH_SYS = 1
32 | * AUTH_SHORT = 2
33 | *
34 | *
35 | * @return auth flavor.
36 | */
37 | int type();
38 |
39 | /**
40 | * Get authentication verified corresponding to this credentials.
41 | * In case of AUTH_NONE or AUTH_SYS the verifier is empty. Some other
42 | * auth flavors may have non empty verifies ( RPCGSS_SEC contains the CRC
43 | * of RPC header ).
44 | *
45 | * @return verifier.
46 | */
47 | RpcAuthVerifier getVerifier();
48 |
49 | /**
50 | * Get {@link Subject} associated with credentials.
51 | * @return subject.
52 | */
53 | Subject getSubject();
54 | }
55 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcAuthError.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
23 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import java.io.IOException;
26 |
27 | /**
28 | * Server rejects the identity of the caller (AUTH_ERROR).
29 | */
30 | public class RpcAuthError implements XdrAble {
31 |
32 | private int _stat;
33 |
34 | public RpcAuthError() {
35 | }
36 |
37 | public RpcAuthError(int _stat) {
38 | this._stat = _stat;
39 | }
40 |
41 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
42 | _stat = xdr.xdrDecodeInt();
43 | }
44 |
45 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
46 | xdr.xdrEncodeInt(_stat);
47 | }
48 |
49 | public int getStat() {
50 | return _stat;
51 | }
52 |
53 | public void setStat(int _stat) {
54 | this._stat = _stat;
55 | }
56 |
57 | }
58 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/MemoryAllocator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2020 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | /**
23 | * Defines how memory allocation should take place.
24 | *
25 | * For RPC messages smaller than 1KB a HEAP allocator is recommended. A bigger messages
26 | * might benefit from pooled allocators as garbage collect doesn't need to allocate big
27 | * heap regions.
28 | *
29 | * If application requires direct buffers, typically to optimize native IO, a direct allocators
30 | * can be used.
31 | *
32 | * @since 3.2
33 | */
34 | public enum MemoryAllocator {
35 |
36 | /** Use default allocator. Note, that default might change between different version of the library. */
37 | DEFAULT,
38 |
39 | /** Allocator, that uses JVM heap memory. */
40 | HEAP,
41 |
42 | /** Allocator, that uses Direct memory. */
43 | DIRECT,
44 |
45 | /** Heap based allocator, that re-uses previously heap-allocated buffers. */
46 | POOLED_HEAP,
47 |
48 | /** Heap based allocator, that re-uses previously direct-allocated buffers. */
49 | POOLED_DIRECT
50 | }
51 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/MismatchInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.BadXdrOncRpcException;
23 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
24 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
25 | import org.dcache.oncrpc4j.xdr.XdrAble;
26 |
27 | public class MismatchInfo implements XdrAble {
28 |
29 | private int _min;
30 | private int _max;
31 |
32 | public MismatchInfo(int min, int max) {
33 | _min = min;
34 | _max = max;
35 | }
36 |
37 | public MismatchInfo() {}
38 |
39 | @Override
40 | public void xdrEncode(XdrEncodingStream xdr) {
41 | xdr.xdrEncodeInt(_min);
42 | xdr.xdrEncodeInt(_max);
43 | }
44 |
45 | @Override
46 | public void xdrDecode(XdrDecodingStream xdr) throws BadXdrOncRpcException {
47 | _min = xdr.xdrDecodeInt();
48 | _max = xdr.xdrDecodeInt();
49 | }
50 |
51 | @Override
52 | public String toString() {
53 | return String.format("mismatch info: [%d, %d]", _min, _max);
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/net/netid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc.net;
21 |
22 | import java.net.InetSocketAddress;
23 |
24 | public class netid {
25 |
26 | private netid() {}
27 |
28 | public static String toString(int port) {
29 | int port_part[] = new int[2];
30 | port_part[0] = (port & 0xff00) >> 8;
31 | port_part[1] = port & 0x00ff;
32 | return "0.0.0.0." + (0xFF & port_part[0]) + "." + (0xFF & port_part[1]);
33 | }
34 |
35 | public static InetSocketAddress toInetSocketAddress(String str) {
36 |
37 | return InetSocketAddresses.forUaddrString(str);
38 |
39 | }
40 |
41 | public static int getPort(String str) {
42 | return toInetSocketAddress(str).getPort();
43 | }
44 |
45 | public static int idOf(String id) {
46 | switch (id) {
47 | case "tcp":
48 | return IpProtocolType.TCP;
49 | case "udp":
50 | return IpProtocolType.UDP;
51 | default:
52 | return -1;
53 | }
54 | }
55 |
56 | }
57 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/gss/DataBodyPrivacy.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc.gss;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcException;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
26 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
27 |
28 | /**
29 | * RPCGSS_SEC data body for privacy QOS as defined in RFC 2203
30 | */
31 | public class DataBodyPrivacy implements XdrAble {
32 |
33 | byte[] _data;
34 |
35 | public DataBodyPrivacy() {
36 | }
37 |
38 | public DataBodyPrivacy(byte[] data) {
39 | this._data = data;
40 | }
41 |
42 | @Override
43 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
44 | _data = xdr.xdrDecodeDynamicOpaque();
45 | }
46 |
47 | @Override
48 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
49 |
50 | xdr.xdrEncodeDynamicOpaque(_data);
51 | }
52 |
53 | public byte[] getData() {
54 | return _data;
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcCallTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.Xdr;
23 | import org.junit.Test;
24 |
25 | public class RpcCallTest {
26 |
27 | private Xdr _xdr = new Xdr(1024);
28 | private RpcCall _call = new RpcCall(0, _xdr, null);
29 |
30 | @Test(expected=RpcMismatchReply.class)
31 | public void testBadRpcVerion() throws Exception {
32 | _xdr.beginEncoding();
33 |
34 | _xdr.xdrEncodeInt(3); // rpc version
35 | _xdr.endEncoding();
36 |
37 | _xdr.beginDecoding();
38 | _call.accept();
39 |
40 | }
41 |
42 | @Test(expected=RpcAuthException.class)
43 | public void testBadAuthType() throws Exception {
44 | _xdr.beginEncoding();
45 |
46 | _xdr.xdrEncodeInt(2); // rpc version
47 | _xdr.xdrEncodeInt(127); // prog
48 | _xdr.xdrEncodeInt(1); // vers
49 | _xdr.xdrEncodeInt(0); // proc
50 |
51 | _xdr.xdrEncodeInt(100);
52 | _xdr.endEncoding();
53 |
54 | _xdr.beginDecoding();
55 | _call.accept();
56 | }
57 |
58 | }
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/ReplyQueueTest.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.rpc;
2 |
3 | import java.io.EOFException;
4 | import java.net.InetSocketAddress;
5 | import java.net.SocketAddress;
6 | import java.nio.channels.CompletionHandler;
7 | import java.util.concurrent.TimeUnit;
8 | import org.junit.Test;
9 | import org.junit.Before;
10 |
11 | import static org.junit.Assert.assertFalse;
12 | import static org.junit.Assert.assertTrue;
13 | import static org.mockito.ArgumentMatchers.any;
14 | import static org.mockito.Mockito.mock;
15 | import static org.mockito.Mockito.verify;
16 |
17 | public class ReplyQueueTest {
18 |
19 | private ReplyQueue replyQueue;
20 | private SocketAddress addr;
21 | private CompletionHandler handler;
22 |
23 | @Before
24 | public void setUp() {
25 | replyQueue = new ReplyQueue();
26 | addr = mock(InetSocketAddress.class);
27 | handler = mock(CompletionHandler.class);
28 | }
29 |
30 | @Test
31 | public void testRemoveCancel() throws EOFException {
32 |
33 | replyQueue.registerKey(1, addr, handler, 1, TimeUnit.MINUTES);
34 |
35 | assertFalse(replyQueue.getTimeoutQueue().isEmpty());
36 |
37 | replyQueue.get(1);
38 |
39 | assertTrue(replyQueue.getTimeoutQueue().isEmpty());
40 | }
41 |
42 | @Test
43 | public void testInvokeHandlerOnTimeout() throws EOFException, InterruptedException {
44 |
45 | replyQueue.registerKey(1, addr, handler, 1, TimeUnit.NANOSECONDS);
46 |
47 | TimeUnit.SECONDS.sleep(1);
48 | assertTrue(replyQueue.getPendingRequests().isEmpty());
49 | assertTrue(replyQueue.getTimeoutQueue().isEmpty());
50 | verify(handler).failed(any(), any());
51 | }
52 |
53 | @Test
54 | public void testRequestWithoutOnTimeout() throws EOFException, InterruptedException {
55 |
56 | replyQueue.registerKey(1, addr, handler);
57 | assertFalse(replyQueue.getPendingRequests().isEmpty());
58 | assertTrue(replyQueue.getTimeoutQueue().isEmpty());
59 | }
60 |
61 | }
62 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrBoolean.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcException;
23 | import java.io.IOException;
24 |
25 | public class XdrBoolean implements XdrAble {
26 |
27 | public static final XdrBoolean True = new XdrBoolean(true);
28 | public static final XdrBoolean False = new XdrBoolean(false);
29 |
30 | private boolean _value;
31 |
32 | public XdrBoolean() {
33 | }
34 |
35 | public XdrBoolean(boolean value) {
36 | _value = value;
37 | }
38 |
39 | /**
40 | * Returns the value of this XdrBoolean object as a boolean primitive.
41 | * @return the primitive boolean value of this object.
42 | */
43 | public boolean booleanValue() {
44 | return _value;
45 | }
46 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
47 | _value = xdr.xdrDecodeBoolean();
48 | }
49 |
50 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
51 | xdr.xdrEncodeBoolean(_value);
52 | }
53 |
54 | }
55 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/gss/GSSINITargs.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc.gss;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcException;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
26 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
27 |
28 | /**
29 | * The data for a GSS context creation request.
30 | */
31 | public class GSSINITargs implements XdrAble {
32 |
33 | private byte[] _token;
34 |
35 | public byte[] getToken() {
36 | return _token;
37 | }
38 |
39 | public void setToken(byte[] token) {
40 | this._token = token;
41 | }
42 |
43 | public GSSINITargs() {
44 | }
45 |
46 | public GSSINITargs(byte[] token) {
47 | this._token = token;
48 | }
49 |
50 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
51 | _token = xdr.xdrDecodeDynamicOpaque();
52 | }
53 |
54 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
55 | xdr.xdrEncodeDynamicOpaque(_token);
56 | }
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/net/netidTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc.net;
21 |
22 | import org.dcache.oncrpc4j.rpc.net.netid;
23 | import java.net.InetSocketAddress;
24 | import org.junit.Test;
25 | import static org.junit.Assert.*;
26 |
27 | public class netidTest {
28 |
29 | @Test
30 | public void testToInetSocketAddress() throws Exception {
31 | InetSocketAddress expResult = new InetSocketAddress("127.0.0.2", 2052);
32 | InetSocketAddress result = netid.toInetSocketAddress("127.0.0.2.8.4");
33 | assertEquals("address decodeing missmatch", expResult, result);
34 | }
35 |
36 | @Test
37 | public void testToInetSocketAddressIPv6() throws Exception {
38 | InetSocketAddress expResult = new InetSocketAddress("0:0:0:0:0:0:0:0", 2052);
39 | InetSocketAddress result = netid.toInetSocketAddress("0:0:0:0:0:0:0:0.8.4");
40 | assertEquals("address decodeing missmatch", expResult, result);
41 | }
42 |
43 | @Test
44 | public void testGetPort() {
45 | int port = netid.getPort("127.0.0.2.8.4");
46 | assertEquals("port decodeing does not match", 2052, port);
47 | }
48 |
49 | }
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrAble.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcException;
23 | import java.io.IOException;
24 |
25 | /**
26 | * Defines the interface for all classes that should be able to be
27 | * serialized into XDR streams, and deserialized or constructed from
28 | * XDR streams.
29 | */
30 | public interface XdrAble {
31 |
32 | /**
33 | * Decodes -- that is: deserializes -- an object from a XDR stream in
34 | * compliance to RFC 1832.
35 | *
36 | * @param xdr XDR stream from which decoded information is retrieved.
37 | *
38 | * @throws OncRpcException if an ONC/RPC error occurs.
39 | */
40 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException;
41 |
42 | /**
43 | * Encodes -- that is: serializes -- an object into a XDR stream in
44 | * compliance to RFC 1832.
45 | *
46 | * @param xdr XDR stream to which information is sent for encoding.
47 | * @throws OncRpcException if an ONC/RPC error occurs.
48 | */
49 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException;
50 | }
51 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenParamInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenParamInfo.java,v 1.2 2003/08/14 08:09:59 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | /**
28 | * The JrpcgenParamInfo class contains information about the
29 | * data type of a procedure's parameter, as well as the parameter's optional
30 | * name.
31 | *
32 | * @version $Revision: 1.2 $ $Date: 2003/08/14 08:09:59 $ $State: Exp $ $Locker: $
33 | * @author Harald Albrecht
34 | */
35 | class JrpcgenParamInfo {
36 |
37 | /**
38 | *
39 | */
40 | public String parameterType;
41 |
42 | /**
43 | *
44 | */
45 | public String parameterName;
46 |
47 | /**
48 | * Constructs a new JrpcgenParamInfo object containing
49 | * information about ...
50 | *
51 | */
52 | public JrpcgenParamInfo(String parameterType, String parameterName) {
53 | this.parameterType = parameterType;
54 | this.parameterName = parameterName;
55 | }
56 |
57 | }
58 |
59 | // End of JrpcgenParamInfo.java
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/xdr/XdrIntTest.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.xdr;
2 |
3 | import java.io.IOException;
4 | import org.junit.Test;
5 | import static org.junit.Assert.*;
6 |
7 | public class XdrIntTest {
8 |
9 |
10 | @Test
11 | public void testDecode() throws IOException {
12 |
13 | int value = 17;
14 |
15 | XdrInt xInt = new XdrInt();
16 | try(Xdr xdr = new Xdr(8)) {
17 | xdr.beginEncoding();
18 | xdr.xdrEncodeInt(value);
19 |
20 | xdr.endEncoding();
21 |
22 | xdr.beginDecoding();
23 | xInt.xdrDecode(xdr);
24 |
25 | assertEquals("invalid value decode", value, xInt.intValue());
26 |
27 | }
28 | }
29 |
30 | @Test
31 | public void testEncode() throws IOException {
32 |
33 |
34 | XdrInt xInt = new XdrInt(17);
35 | try (Xdr xdr = new Xdr(8)) {
36 | xdr.beginEncoding();
37 | xInt.xdrEncode(xdr);
38 |
39 | xdr.endEncoding();
40 |
41 | xdr.beginDecoding();
42 |
43 | assertEquals("invalid value decoded", xInt.intValue(), xdr.xdrDecodeInt());
44 |
45 | }
46 | }
47 |
48 | @Test
49 | public void testEncodeWellKnown() throws IOException {
50 |
51 | byte[] data = new byte[] {
52 | 0x0, 0x0, 0x0, 0x11 // big endian encoded 17
53 | };
54 |
55 | XdrInt xInt = new XdrInt(17);
56 | try (Xdr xdr = new Xdr(8)) {
57 | xdr.beginEncoding();
58 | xInt.xdrEncode(xdr);
59 |
60 | xdr.endEncoding();
61 | assertArrayEquals(data, xdr.getBytes());
62 | }
63 | }
64 |
65 |
66 | @Test
67 | public void testDecodeWellKnown() throws IOException {
68 |
69 | byte[] data = new byte[]{
70 | 0x0, 0x0, 0x0, 0x11 // big endian encoded 17
71 | };
72 |
73 | try (Xdr xdr = new Xdr(data)) {
74 | xdr.beginDecoding();
75 | XdrInt xInt = new XdrInt();
76 | xInt.xdrDecode(xdr);
77 |
78 | assertEquals(17, xInt.intValue());
79 | }
80 | }
81 |
82 | }
83 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenSymbols.java:
--------------------------------------------------------------------------------
1 |
2 | //----------------------------------------------------
3 | // The following code was generated by CUP v0.10k TUM Edition 20050516
4 | // Fri Nov 11 20:53:50 CET 2005
5 | //----------------------------------------------------
6 |
7 | package org.acplt.oncrpc.apps.jrpcgen;
8 |
9 | /** CUP generated interface containing symbol constants. */
10 | public interface JrpcgenSymbols {
11 | /* terminals */
12 | public static final int SHORT = 24;
13 | public static final int QUADRUPLE = 30;
14 | public static final int LBRACKET = 11;
15 | public static final int CONST = 17;
16 | public static final int CHAR = 23;
17 | public static final int CASE = 20;
18 | public static final int DOUBLE = 29;
19 | public static final int HYPER = 27;
20 | public static final int LPAREN = 7;
21 | public static final int INT = 25;
22 | public static final int STAR = 6;
23 | public static final int RPAREN = 8;
24 | public static final int SEMICOLON = 2;
25 | public static final int BOOL = 31;
26 | public static final int COMMA = 3;
27 | public static final int VERSION = 16;
28 | public static final int TYPEDEF = 18;
29 | public static final int EOF = 0;
30 | public static final int RBRACKET = 12;
31 | public static final int EQUAL = 5;
32 | public static final int error = 1;
33 | public static final int PROGRAM = 15;
34 | public static final int UNSIGNED = 37;
35 | public static final int VOID = 22;
36 | public static final int SWITCH = 19;
37 | public static final int COLON = 4;
38 | public static final int UNION = 36;
39 | public static final int LANGLE = 13;
40 | public static final int LBRACE = 9;
41 | public static final int OPAQUE = 33;
42 | public static final int ENUM = 32;
43 | public static final int DEFAULT = 21;
44 | public static final int FLOAT = 28;
45 | public static final int RANGLE = 14;
46 | public static final int RBRACE = 10;
47 | public static final int LONG = 26;
48 | public static final int STRING = 34;
49 | public static final int STRUCT = 35;
50 | public static final int IDENTIFIER = 39;
51 | public static final int INTEGER_LITERAL = 38;
52 | }
53 |
54 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/test/java/org/dcache/oncrpc4j/rpcgen/BigConstsGenerationTest.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.rpcgen;
2 |
3 | import org.junit.Assert;
4 | import org.junit.Test;
5 |
6 | import java.math.BigInteger;
7 |
8 | /**
9 | * Created by Radai Rosenblatt
10 | */
11 | public class BigConstsGenerationTest {
12 | @Test
13 | public void testBigCostsGeneration() throws Exception{
14 | int maxInt = 0xFFFFFFFF; //unsigned
15 | long maxLong = 0xFFFFFFFFFFFFFFFFL; //unsigned
16 | Assert.assertEquals(Calculator.PLAIN_ZERO, 0);
17 | Assert.assertEquals(Calculator.HEX_ZERO, 0);
18 | //small is within int range
19 | Assert.assertTrue(Calculator.SMALL_CONST <= Integer.MAX_VALUE);
20 | Assert.assertTrue(Calculator.SMALL_CONST >= Integer.MIN_VALUE);
21 | //large is a long above max int
22 | Assert.assertTrue(Calculator.LARGE_CONST >= Integer.MAX_VALUE);
23 | Assert.assertTrue(Calculator.LARGE_CONST <= Long.MAX_VALUE);
24 | //huge us a bigint beyond max long
25 | Assert.assertTrue(Calculator.HUGE_CONST.compareTo(BigInteger.valueOf(Long.MAX_VALUE)) > 0);
26 | //the code below is jdk8's compareUnsigned (back ported because project is jdk7)
27 | //noinspection NumericOverflow
28 | Assert.assertEquals(0, Integer.compare(maxInt + Integer.MIN_VALUE, Calculator.UNSIGNED_INT_OCT_CONST + Integer.MIN_VALUE));
29 | //noinspection NumericOverflow
30 | Assert.assertEquals(0, Integer.compare(maxInt + Integer.MIN_VALUE, Calculator.UNSIGNED_INT_HEX_CONST + Integer.MIN_VALUE));
31 | //noinspection NumericOverflow
32 | Assert.assertEquals(0, Integer.compare(maxInt + Integer.MIN_VALUE, ((int) Calculator.UNSIGNED_INT_DEC_CONST) + Integer.MIN_VALUE));
33 | //noinspection NumericOverflow
34 | Assert.assertEquals(0, Long.compare(maxLong + Long.MIN_VALUE, Calculator.UNSIGNED_LONG_OCT_CONST + Long.MIN_VALUE));
35 | //noinspection NumericOverflow
36 | Assert.assertEquals(0, Long.compare(maxLong + Long.MIN_VALUE, Calculator.UNSIGNED_LONG_HEX_CONST + Long.MIN_VALUE));
37 | Assert.assertEquals(0, Long.compare(maxLong + Long.MIN_VALUE, Calculator.UNSIGNED_LONG_DEC_CONST.longValue() + Long.MIN_VALUE));
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/xdr/XdrLongTest.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.xdr;
2 |
3 | import java.io.IOException;
4 | import org.junit.Test;
5 |
6 | import static org.junit.Assert.*;
7 |
8 | public class XdrLongTest {
9 |
10 | @Test
11 | public void testDecode() throws IOException {
12 |
13 | long value = 2018L;
14 |
15 | XdrLong xLong = new XdrLong();
16 | try(Xdr xdr = new Xdr(8)) {
17 | xdr.beginEncoding();
18 | xdr.xdrEncodeLong(value);
19 |
20 | xdr.endEncoding();
21 | xdr.beginDecoding();
22 | xLong.xdrDecode(xdr);
23 |
24 | assertEquals("invalid value decode", value, xLong.longValue());
25 | }
26 | }
27 |
28 | @Test
29 | public void testEncode() throws IOException {
30 |
31 |
32 | XdrLong xLong = new XdrLong(2018);
33 | try (Xdr xdr = new Xdr(8)) {
34 | xdr.beginEncoding();
35 | xLong.xdrEncode(xdr);
36 |
37 | xdr.endEncoding();
38 | xdr.beginDecoding();
39 |
40 | assertEquals("invalid value decoded", xLong.longValue(), xdr.xdrDecodeLong());
41 | }
42 | }
43 |
44 | @Test
45 | public void testEncodeWellKnown() throws IOException {
46 |
47 | byte[] data = new byte[]{
48 | 0x04, 0x21, 0x0, 0x02,
49 | 0x54, 0x0b, 0x14, 0x11 // big endian encoded 297519060383110161
50 | };
51 |
52 | XdrLong xLong = new XdrLong(297519060383110161L);
53 | try (Xdr xdr = new Xdr(8)) {
54 | xdr.beginEncoding();
55 | xLong.xdrEncode(xdr);
56 |
57 | xdr.endEncoding();
58 | assertArrayEquals(data, xdr.getBytes());
59 | }
60 | }
61 |
62 | @Test
63 | public void testDecodeWellKnown() throws IOException {
64 |
65 | byte[] data = new byte[]{
66 | 0x04, 0x21, 0x0, 0x02,
67 | 0x54, 0x0b, 0x14, 0x11 // big endian encoded 297519060383110161
68 | };
69 |
70 | try (Xdr xdr = new Xdr(data)) {
71 | xdr.beginDecoding();
72 | XdrLong xLong = new XdrLong();
73 | xLong.xdrDecode(xdr);
74 |
75 | assertEquals(297519060383110161L, xLong.longValue());
76 | }
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrVoid.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcException;
23 | import java.io.IOException;
24 |
25 | public class XdrVoid implements XdrAble {
26 |
27 | /**
28 | * Encodes -- that is: serializes -- a void into a XDR stream in
29 | * compliance to RFC 1832.
30 | *
31 | * @throws OncRpcException if an ONC/RPC error occurs.
32 | * @throws IOException if an I/O error occurs.
33 | */
34 | public void xdrEncode(XdrEncodingStream xdr)
35 | throws OncRpcException, IOException
36 | {
37 | }
38 |
39 | /**
40 | * Decodes -- that is: deserializes -- a void from a XDR stream in
41 | * compliance to RFC 1832.
42 | *
43 | * @throws OncRpcException if an ONC/RPC error occurs.
44 | * @throws IOException if an I/O error occurs.
45 | */
46 | public void xdrDecode(XdrDecodingStream xdr)
47 | throws OncRpcException, IOException
48 | {
49 | }
50 |
51 | /**
52 | * Static XdrVoid instance, which can be used in cases
53 | * where no data is to be serialized or deserialized but some ONC/RPC
54 | * function expects a reference to a XDR-able object.
55 | */
56 | public final static XdrVoid XDR_VOID = new XdrVoid();
57 |
58 | }
59 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/gss/DataBodyIntegrity.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc.gss;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcException;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
26 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
27 |
28 | /**
29 | * RPCGSS_SEC data body for integrity QOS as defined in RFC 2203
30 | */
31 | public class DataBodyIntegrity implements XdrAble {
32 |
33 | private byte[] data;
34 | private byte[] checksum;
35 |
36 | public DataBodyIntegrity() {
37 | }
38 |
39 | public DataBodyIntegrity(byte[] data, byte[] checksum) {
40 | this.data = data;
41 | this.checksum = checksum;
42 | }
43 |
44 | @Override
45 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
46 | data = xdr.xdrDecodeDynamicOpaque();
47 | checksum = xdr.xdrDecodeDynamicOpaque();
48 | }
49 |
50 | @Override
51 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
52 | xdr.xdrEncodeDynamicOpaque(data);
53 | xdr.xdrEncodeDynamicOpaque(checksum);
54 | }
55 |
56 | public byte[] getChecksum() {
57 | return checksum;
58 | }
59 |
60 | public byte[] getData() {
61 | return data;
62 | }
63 | }
64 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/util/BytesTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.util;
21 |
22 | import org.junit.Before;
23 | import org.junit.Test;
24 | import static org.junit.Assert.*;
25 |
26 | /**
27 | *
28 | * @author tigran
29 | */
30 | public class BytesTest {
31 |
32 |
33 | private byte[] _b;
34 | @Before
35 | public void setUp() {
36 | _b = new byte[8];
37 | }
38 |
39 | @Test(expected=IllegalArgumentException.class)
40 | public void testPutLongIntoSmall() {
41 | Bytes.putLong(_b, 6, 0);
42 | }
43 |
44 | @Test(expected=IllegalArgumentException.class)
45 | public void testPutIntIntoSmall() {
46 | Bytes.putInt(_b, 6, 0);
47 | }
48 |
49 | @Test
50 | public void testPutLongExact() {
51 | Bytes.putLong(_b, _b.length - 8, 0);
52 | }
53 |
54 | @Test
55 | public void testPutIntExact() {
56 | Bytes.putInt(_b, _b.length - 4, 0);
57 | }
58 |
59 | @Test
60 | public void testPutGetLong() {
61 | long value = 1717;
62 | Bytes.putLong(_b, 0, value);
63 | assertEquals("put/get mismatch", value, Bytes.getLong(_b, 0));
64 | }
65 |
66 | @Test
67 | public void testPutGetInt() {
68 | int value = 1717;
69 | Bytes.putInt(_b, 0, value);
70 | assertEquals("put/get mismatch", value, Bytes.getInt(_b, 0));
71 | }
72 | }
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/grizzly/GrizzlyMemoryManager.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.grizzly;
21 |
22 | import org.glassfish.grizzly.Buffer;
23 | import org.glassfish.grizzly.memory.Buffers;
24 | import org.glassfish.grizzly.memory.CompositeBuffer;
25 | import org.glassfish.grizzly.memory.MemoryManager;
26 |
27 | /**
28 | * Class to manage memory buffer allocation and reallocation
29 | */
30 | public class GrizzlyMemoryManager {
31 |
32 | private static final MemoryManager GRIZZLY_MM =
33 | MemoryManager.DEFAULT_MEMORY_MANAGER;
34 |
35 | // Utility class
36 | private GrizzlyMemoryManager() {}
37 |
38 | public static MemoryManager getDefaultMemoryManager() {
39 | return GRIZZLY_MM;
40 | }
41 |
42 | public static Buffer allocate(int size) {
43 | return GRIZZLY_MM.allocate(size);
44 | }
45 |
46 | public static Buffer reallocate(MemoryManager memoryManager, Buffer oldBuffer, int newSize) {
47 | if (oldBuffer.isComposite()) {
48 | Buffer addon = memoryManager.allocate(newSize-oldBuffer.capacity());
49 | ((CompositeBuffer)oldBuffer).append(addon);
50 | return oldBuffer;
51 | }
52 | return memoryManager.reallocate(oldBuffer, newSize);
53 | }
54 |
55 | public static Buffer wrap(byte[] bytes) {
56 | return Buffers.wrap(GRIZZLY_MM, bytes);
57 | }
58 | }
59 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcAuthVerifier.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
23 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import java.io.IOException;
26 |
27 | /**
28 | * Authentication verifier. Depending of status of credentials the content may
29 | * change ( for example, in case of RPCGSS_SEC contains the checksum of RPC header).
30 | */
31 | public class RpcAuthVerifier implements XdrAble {
32 |
33 | private int _type;
34 | private byte[] _body;
35 |
36 | public RpcAuthVerifier(int type, byte[] body) {
37 | _type = type;
38 | _body = body;
39 | }
40 |
41 | public RpcAuthVerifier(XdrDecodingStream xdr) throws OncRpcException, IOException {
42 | xdrDecode(xdr);
43 | }
44 |
45 | public int getType() {
46 | return _type;
47 | }
48 |
49 | public byte[] getBody() {
50 | return _body;
51 | }
52 |
53 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
54 | _type = xdr.xdrDecodeInt();
55 | _body = xdr.xdrDecodeDynamicOpaque();
56 | }
57 |
58 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
59 | xdr.xdrEncodeInt(_type);
60 | xdr.xdrEncodeDynamicOpaque(_body);
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/oncrpc4j-spring/src/main/java/org/dcache/oncrpc4j/spring/SpringRunner.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.spring;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcSvc;
24 | import org.springframework.beans.BeansException;
25 | import org.springframework.context.ConfigurableApplicationContext;
26 | import org.springframework.context.support.FileSystemXmlApplicationContext;
27 |
28 | public class SpringRunner {
29 |
30 | private SpringRunner() {
31 | // this class it used only to bootstrap the Spring IoC
32 | }
33 |
34 | public static void main(String[] args) throws IOException {
35 | if (args.length != 1) {
36 | System.err.println("Usage: SpringRunner ");
37 | System.exit(1);
38 | }
39 |
40 | ConfigurableApplicationContext context = null;
41 | try {
42 | context = new FileSystemXmlApplicationContext(args[0]);
43 |
44 | OncRpcSvc service = (OncRpcSvc) context.getBean("oncrpcsvc");
45 | service.start();
46 |
47 | System.in.read();
48 | } catch (BeansException e) {
49 | System.err.println("Spring: " + e.getMessage());
50 | System.exit(1);
51 | } finally {
52 | if (context != null) {
53 | context.close();
54 | }
55 | }
56 |
57 | System.exit(0);
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/RpcProtocolFilterTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2022 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.Xdr;
23 | import java.io.IOException;
24 | import org.glassfish.grizzly.Connection;
25 | import org.glassfish.grizzly.filterchain.Filter;
26 | import org.glassfish.grizzly.filterchain.FilterChainContext;
27 | import org.junit.Before;
28 | import org.junit.Test;
29 |
30 | import static org.junit.Assert.*;
31 | import static org.mockito.Mockito.mock;
32 |
33 | /**
34 | *
35 | */
36 | public class RpcProtocolFilterTest {
37 |
38 | private final static int INVOKE = 0;
39 | private final static int STOP = 1;
40 | private Filter filter;
41 | private FilterChainContext mockedContext;
42 |
43 | @Before
44 | public void setUp() {
45 | filter = new RpcProtocolFilter( new ReplyQueue());
46 | mockedContext = FilterChainContext.create(mock(Connection.class));
47 | }
48 |
49 | @Test
50 | public void testSomeMethod() throws IOException {
51 | mockedContext.setMessage( createBadXdr() );
52 | assertEquals(STOP, filter.handleRead(mockedContext).type());
53 | }
54 |
55 | private Xdr createBadXdr() {
56 | Xdr xdr = new Xdr(32);
57 | xdr.beginEncoding();
58 | xdr.xdrEncodeInt(1); // xid
59 | xdr.xdrEncodeInt(2); // type: 0 = call, 1 = reply, x = invalid
60 | return xdr;
61 | }
62 | }
63 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/test/java/org/dcache/oncrpc4j/rpcgen/FutureCalculatorTest.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.rpcgen;
2 |
3 | import org.dcache.oncrpc4j.xdr.XdrLong;
4 | import org.junit.Assert;
5 | import org.junit.Test;
6 |
7 | import java.util.concurrent.Future;
8 | import java.util.concurrent.TimeUnit;
9 | import java.util.concurrent.TimeoutException;
10 |
11 | public class FutureCalculatorTest extends AbstractCalculatorTest {
12 |
13 | @Test
14 | public void testFutureAdd() throws Exception {
15 | long callTime = System.currentTimeMillis();
16 | Future future = client.add_1_future(1, 2, null);
17 | long retTime = System.currentTimeMillis();
18 | Assert.assertNotNull(future);
19 | CalculationResult result = future.get();
20 | long resTime = System.currentTimeMillis();
21 | Assert.assertEquals(3, result.getResult());
22 | //to prove async operation (there's a sleep() server-side)
23 | //call <= start < finish <= res
24 | //ret < finish
25 | Assert.assertTrue(callTime <= result.startMillis);
26 | Assert.assertTrue(result.startMillis < result.finishMillis);
27 | Assert.assertTrue(result.finishMillis <= resTime);
28 | Assert.assertTrue(retTime < result.finishMillis);
29 | }
30 |
31 | @Test
32 | public void testFutureAddSimple() throws Exception {
33 | long callTime = System.nanoTime();
34 | Future future = client.addSimple_1_future(1, 2, null);
35 | long retTime = System.nanoTime();
36 | XdrLong result = future.get();
37 | long resTime = System.nanoTime();
38 | long invocationTime = retTime-callTime;
39 | long waitTime = resTime-retTime;
40 | Assert.assertNotNull(result);
41 | Assert.assertEquals(3, result.longValue());
42 | //not really proof of async, but good enough?
43 | //the condition below is a bit fragile and relies on the fact
44 | //that there's a 10-milli sleep server side and the invocation
45 | //is likely to take much less
46 | Assert.assertTrue(waitTime > invocationTime);
47 | }
48 |
49 | @Test(expected = TimeoutException.class)
50 | public void testFutureAddTimeout() throws Exception {
51 | Future future = client.add_1_future(3, 4, null);
52 | future.get(CalculatorServerImpl.SLEEP_MILLIS / 10, TimeUnit.MILLISECONDS);
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcAccepsStatus.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | /**
23 | * Given that a call message was accepted, the following is the
24 | * status of an attempt to call a remote procedure.
25 | */
26 | public final class RpcAccepsStatus {
27 |
28 | private RpcAccepsStatus(){}
29 |
30 | /**
31 | * RPC executed successfully
32 | */
33 | public static final int SUCCESS = 0;
34 | /**
35 | * Remote hasn't exported program.
36 | */
37 | public static final int PROG_UNAVAIL = 1;
38 | /**
39 | * Remote can't support version #.
40 | */
41 | public static final int PROG_MISMATCH = 2;
42 | /**
43 | * Program can't support procedure.
44 | */
45 | public static final int PROC_UNAVAIL = 3;
46 | /**
47 | * Procedure can't decode params.
48 | */
49 | public static final int GARBAGE_ARGS = 4;
50 | /**
51 | * Undefined system error
52 | */
53 | public static final int SYSTEM = 5;
54 |
55 | public static String toString(int status) {
56 | switch(status) {
57 | case SUCCESS: return "SUCCESS";
58 | case PROG_UNAVAIL: return "PROG_UNAVAIL";
59 | case PROG_MISMATCH: return "PROG_MISMATCH";
60 | case PROC_UNAVAIL: return "PROC_UNAVAIL";
61 | case GARBAGE_ARGS: return "GARBAGE_ARGS";
62 | case SYSTEM: return "SYSTEM";
63 | }
64 | return "UNKNOWN";
65 | }
66 | }
67 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/OncRpcEmbeddedPortmapTest.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.rpc;
2 |
3 | import org.dcache.oncrpc4j.rpc.OncRpcSvc;
4 | import org.dcache.oncrpc4j.rpc.OncRpcClient;
5 | import org.dcache.oncrpc4j.rpc.OncRpcProgram;
6 | import org.dcache.oncrpc4j.rpc.OncRpcSvcBuilder;
7 | import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
8 | import org.dcache.oncrpc4j.xdr.XdrVoid;
9 | import java.io.IOException;
10 | import java.net.InetAddress;
11 | import java.util.Arrays;
12 | import java.util.concurrent.TimeoutException;
13 | import org.dcache.oncrpc4j.portmap.GenericPortmapClient;
14 | import org.dcache.oncrpc4j.portmap.OncPortmapClient;
15 | import org.dcache.oncrpc4j.portmap.OncRpcEmbeddedPortmap;
16 | import org.dcache.oncrpc4j.portmap.rpcb;
17 | import org.junit.After;
18 | import static org.junit.Assert.assertTrue;
19 | import static org.junit.Assume.assumeTrue;
20 | import org.junit.Test;
21 |
22 | /**
23 | * Quick testing for OncRpcEmbeddedPortmap
24 | */
25 | public class OncRpcEmbeddedPortmapTest {
26 | // https://tools.ietf.org/html/draft-ietf-nfsv4-rpc-netid-06
27 | public static final String[] NETID_NAMES = new String[] {"-","ticlts","ticots","ticotsord","tcp","tcp6","udp","udp6","rdma","rdma6","sctp","sctp6"};
28 | private OncRpcEmbeddedPortmap portmap = null;
29 |
30 | @Test
31 | public void testEmbeddedPortmapWithDummyService() throws IOException, OncRpcException, TimeoutException {
32 | portmap = new OncRpcEmbeddedPortmap();
33 | assumeTrue(portmap.isEmbeddedPortmapper()); // skip test if not embedded portmapper
34 |
35 | OncRpcSvc svc = new OncRpcSvcBuilder()
36 | .withTCP()
37 | .withAutoPublish()
38 | .withSameThreadIoStrategy()
39 | .withRpcService(new OncRpcProgram(100017, 1), call -> call.reply(XdrVoid.XDR_VOID))
40 | .build();
41 | svc.start();
42 | // Open portmap and check nedtid content with dump
43 | try ( OncRpcClient rpcClient = new OncRpcClient(InetAddress.getLocalHost(), IpProtocolType.UDP,111) ) {
44 | OncPortmapClient portmapClient = new GenericPortmapClient(rpcClient.connect()); // init portmapper (only v2 atm)
45 | portmapClient.ping();
46 | for ( rpcb current : portmapClient.dump() ) {
47 | assertTrue("NedId value incorrect: "+current.getNetid(), Arrays.asList(NETID_NAMES).contains(current.getNetid()) );
48 | }
49 | }
50 | svc.stop();
51 | }
52 |
53 | @After
54 | public void tearDown() throws IOException {
55 | if ( portmap != null ) {
56 | portmap.shutdown();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/portmap/OncRpcPortmap.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.portmap;
21 |
22 | public class OncRpcPortmap {
23 |
24 | /**
25 | * portmap/rpcbing program number as defined in rfc1833.
26 | */
27 | public static final int PORTMAP_PROGRAMM = 100000;
28 |
29 | /**
30 | * portmap/rpcbing TCP/UDP port number as defined in rfc1833.
31 | */
32 |
33 | public static final int PORTMAP_PORT = 111;
34 | /*
35 | * V2
36 | */
37 | public static final int PORTMAP_V2 = 2;
38 | public static final int PMAPPROC_NULL = 0;
39 | public static final int PMAPPROC_SET = 1;
40 | public static final int PMAPPROC_UNSET = 2;
41 | public static final int PMAPPROC_GETPORT = 3;
42 | public static final int PMAPPROC_DUMP = 4;
43 | public static final int PMAPPROC_CALLIT = 5;
44 |
45 | /*
46 | * V4
47 | */
48 | public static final int PORTMAP_V4 = 4;
49 | public static final int RPCBPROC_SET = 1;
50 | public static final int RPCBPROC_UNSET = 2;
51 | public static final int RPCBPROC_GETADDR = 3;
52 | public static final int RPCBPROC_DUMP = 4;
53 | public static final int RPCBPROC_GETTIME = 6;
54 | public static final int RPCBPROC_UADDR2TADDR = 7;
55 | public static final int RPCBPROC_TADDR2UADDR = 8;
56 | public static final int RPCBPROC_GETVERSADDR = 9;
57 | public static final int RPCBPROC_INDIRECT = 10;
58 | public static final int RPCBPROC_GETADDRLIST = 11;
59 | public static final int RPCBPROC_GETSTAT = 12;
60 | }
61 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/OncRpcProgramTest.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcProgram;
23 | import org.junit.Test;
24 | import static org.junit.Assert.*;
25 |
26 | public class OncRpcProgramTest {
27 |
28 |
29 | @Test
30 | public void testGetNumber() {
31 | int progNum = 15;
32 | int progVers = 17;
33 |
34 | OncRpcProgram program = new OncRpcProgram(progNum, progVers);
35 | assertEquals("Program number miss match", progNum, program.getNumber());
36 | }
37 |
38 | @Test
39 | public void testGetVersion() {
40 | int progNum = 15;
41 | int progVers = 17;
42 |
43 | OncRpcProgram program = new OncRpcProgram(progNum, progVers);
44 | assertEquals("Program version miss match", progVers, program.getVersion());
45 | }
46 |
47 | @Test
48 | public void testEqualsTrue() {
49 | int progNum = 15;
50 | int progVers = 17;
51 |
52 | OncRpcProgram program1 = new OncRpcProgram(progNum, progVers);
53 | OncRpcProgram program2 = new OncRpcProgram(progNum, progVers);
54 | assertEquals("Equals programs not detected", program1, program2);
55 | }
56 |
57 | @Test
58 | public void testNotEqualByProgNumber() {
59 | int progNum = 15;
60 | int progVers = 17;
61 |
62 | OncRpcProgram program1 = new OncRpcProgram(progNum, progVers);
63 | OncRpcProgram program2 = new OncRpcProgram(progNum, progVers + 10);
64 | assertNotEquals("Different programs not detected", program1, program2);
65 | }
66 |
67 | }
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcCredential.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2021 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
23 | import java.io.IOException;
24 | import org.dcache.oncrpc4j.rpc.gss.RpcAuthGss;
25 |
26 | /**
27 | * The RPC call message has two authentication fields - the credential and verifier.
28 | * The verifier may change it's value depending on state of credential (RPCGSS_SEC).
29 | * A reply uses only verifier.
30 | */
31 | public class RpcCredential {
32 |
33 | private RpcCredential() {}
34 |
35 | public static RpcAuth decode(XdrDecodingStream xdr, RpcTransport transport) throws OncRpcException, IOException {
36 |
37 | int authType = xdr.xdrDecodeInt();
38 | RpcAuth credential;
39 | switch (authType) {
40 | case RpcAuthType.UNIX:
41 | credential = new RpcAuthTypeUnix();
42 | break;
43 | case RpcAuthType.NONE:
44 | credential = new RpcAuthTypeNone();
45 | break;
46 | case RpcAuthType.RPCGSS_SEC:
47 | credential = new RpcAuthGss();
48 | break;
49 | case RpcAuthType.TLS:
50 | credential = new RpcAuthTypeTls(RpcAuthTypeTls.STARTTLS_VERIFIER);
51 | transport.startTLS();
52 | break;
53 | default:
54 | throw new RpcAuthException("Unsupported type: " + authType,
55 | new RpcAuthError(RpcAuthStat.AUTH_FAILED));
56 | }
57 | credential.xdrDecode(xdr);
58 | return credential;
59 | }
60 | }
61 |
--------------------------------------------------------------------------------
/oncrpc4j-portmapdaemon/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.dcache
7 | oncrpc4j
8 | 3.5.0-SNAPSHOT
9 |
10 |
11 | ONCRPC4J-based portmap Daemon
12 | http://www.dCache.ORG
13 |
14 | oncrpc4j-portmapdaemon
15 |
16 | 3.6.1
17 |
18 |
19 |
20 |
21 | org.apache.maven.plugins
22 | maven-shade-plugin
23 | ${maven-shade-plugin}
24 |
25 |
26 | package
27 |
28 | shade
29 |
30 |
31 |
32 |
33 | org.dcache.jarpcbind.Main
34 |
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 | org.dcache
46 | oncrpc4j-core
47 | ${project.version}
48 |
49 |
50 | ch.qos.logback
51 | logback-classic
52 |
53 |
54 | junit
55 | junit
56 | test
57 |
58 |
59 | org.mockito
60 | mockito-core
61 | test
62 |
63 |
64 |
65 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrString.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcException;
23 | import java.io.IOException;
24 | import java.util.Objects;
25 |
26 | public class XdrString implements XdrAble {
27 |
28 | private String _value;
29 |
30 | public XdrString() {
31 | }
32 |
33 | public XdrString(String value) {
34 | _value = value;
35 | }
36 |
37 | /**
38 | * Returns the value of this XdrString object as a {@code String}.
39 | * @return value of this XdrString as {@code String}.
40 | */
41 | public String stringValue() {
42 | return _value;
43 | }
44 |
45 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
46 | _value = xdr.xdrDecodeString();
47 | }
48 |
49 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
50 | xdr.xdrEncodeString(_value);
51 | }
52 |
53 | @Override
54 | public String toString() {
55 | return _value;
56 | }
57 |
58 | @Override
59 | public int hashCode() {
60 | return Objects.hashCode(this._value);
61 | }
62 |
63 | @Override
64 | public boolean equals(Object obj) {
65 | if (this == obj) {
66 | return true;
67 | }
68 | if (obj == null) {
69 | return false;
70 | }
71 | if (getClass() != obj.getClass()) {
72 | return false;
73 | }
74 | final XdrString other = (XdrString) obj;
75 | return Objects.equals(this._value, other._value);
76 | }
77 | }
78 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/test/java/org/dcache/oncrpc4j/rpc/TestGitHubIssue56.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.rpc;
2 |
3 | import static org.junit.Assert.*;
4 |
5 | import java.io.IOException;
6 | import java.util.concurrent.TimeoutException;
7 |
8 | import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
9 | import org.dcache.oncrpc4j.portmap.GenericPortmapClient;
10 | import org.dcache.oncrpc4j.portmap.OncRpcPortmap;
11 | import org.dcache.oncrpc4j.portmap.OncRpcbindServer;
12 | import org.junit.Test;
13 |
14 | public class TestGitHubIssue56 {
15 |
16 | @Test
17 | public void DumpTest() throws IOException, TimeoutException {
18 |
19 | OncRpcSvc rpcbindServer = new OncRpcSvcBuilder()
20 | .withTCP()
21 | .withUDP()
22 | .withoutAutoPublish()
23 | .withBindAddress("127.0.0.1")
24 | .withRpcService(new OncRpcProgram(OncRpcPortmap.PORTMAP_PROGRAMM, OncRpcPortmap.PORTMAP_V2), new OncRpcbindServer())
25 | .build();
26 | rpcbindServer.start();
27 | int protoType = IpProtocolType.TCP;
28 | OncRpcClient rpcClient = new OncRpcClient(rpcbindServer.getInetSocketAddress(protoType), protoType);
29 | RpcTransport transport = rpcClient.connect();
30 | GenericPortmapClient portmapClient = new GenericPortmapClient(transport);
31 | assertFalse("Newly started OncRpcbindServer must publish himself", portmapClient.dump().isEmpty());
32 | }
33 |
34 | @Test
35 | public void SetUnsetTest() throws IOException, TimeoutException {
36 |
37 | OncRpcSvc rpcbindServer = new OncRpcSvcBuilder()
38 | .withTCP()
39 | .withUDP()
40 | .withBindAddress("127.0.0.1")
41 | .withoutAutoPublish()
42 | .withRpcService(new OncRpcProgram(OncRpcPortmap.PORTMAP_PROGRAMM, OncRpcPortmap.PORTMAP_V2), new OncRpcbindServer())
43 | .build();
44 | rpcbindServer.start();
45 | int protoType = IpProtocolType.TCP;
46 | OncRpcClient rpcClient = new OncRpcClient(rpcbindServer.getInetSocketAddress(protoType), protoType);
47 | RpcTransport transport = rpcClient.connect();
48 | GenericPortmapClient portmapClient = new GenericPortmapClient(transport);
49 |
50 | int n = portmapClient.dump().size();
51 | assertTrue(portmapClient.setPort(9000001, 1, "tcp", "127.0.0.1.0.234", "superuser"));
52 | assertEquals(n + 1, portmapClient.dump().size());
53 | assertTrue(portmapClient.unsetPort(9000001, 1, "superuser"));
54 | assertEquals(n, portmapClient.dump().size());
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/portmap/pmaplist.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.portmap;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcException;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
26 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
27 |
28 | public class pmaplist implements XdrAble {
29 | private mapping _mapping;
30 | private pmaplist _next;
31 |
32 | public pmaplist() {}
33 |
34 | public void setEntry(mapping mapping) {
35 | _mapping = mapping;
36 | }
37 |
38 | public void setNext(pmaplist next) {
39 | _next = next;
40 | }
41 |
42 | public mapping getEntry() {
43 | return _mapping;
44 | }
45 |
46 | public pmaplist getNext() {
47 | return _next;
48 | }
49 |
50 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
51 | boolean hasMap = xdr.xdrDecodeBoolean();
52 | if(hasMap) {
53 | _mapping = new mapping();
54 | _mapping.xdrDecode(xdr);
55 | _next = new pmaplist();
56 | _next.xdrDecode(xdr);
57 | }else{
58 | _mapping = null;
59 | }
60 | }
61 |
62 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
63 | if (_mapping != null) {
64 | xdr.xdrEncodeBoolean(true);
65 | _mapping.xdrEncode(xdr);
66 | _next.xdrEncode(xdr);
67 | } else {
68 | xdr.xdrEncodeBoolean(false);
69 | }
70 | }
71 |
72 | @Override
73 | public String toString() {
74 | return _mapping + "\n" + (_next != null ? _next : "");
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/portmap/rpcb_list.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.portmap;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcException;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
26 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
27 |
28 | /*
29 | * A list of mappings.
30 | */
31 | public class rpcb_list implements XdrAble{
32 |
33 | private rpcb _rpcbMap;
34 |
35 | public void setNext(rpcb_list next) {
36 | _next = next;
37 | }
38 |
39 | public void setEntry(rpcb rpcbMap) {
40 | _rpcbMap = rpcbMap;
41 | }
42 |
43 | public rpcb getEntry() {
44 | return _rpcbMap;
45 | }
46 |
47 | public rpcb_list getNext() {
48 | return _next;
49 | }
50 |
51 | private rpcb_list _next;
52 |
53 | public rpcb_list() {}
54 |
55 | @Override
56 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
57 | boolean hasMap = xdr.xdrDecodeBoolean();
58 | if(hasMap) {
59 | _rpcbMap = new rpcb();
60 | _rpcbMap.xdrDecode(xdr);
61 | _next = new rpcb_list();
62 | _next.xdrDecode(xdr);
63 | }else{
64 | _rpcbMap = null;
65 | }
66 | }
67 |
68 | @Override
69 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
70 |
71 | if (_rpcbMap != null) {
72 | xdr.xdrEncodeBoolean(true);
73 | _rpcbMap.xdrEncode(xdr);
74 | _next.xdrEncode(xdr);
75 | }else{
76 | xdr.xdrEncodeBoolean(false);
77 | }
78 | }
79 |
80 | @Override
81 | public String toString() {
82 | return _rpcbMap + "\n" + (_next != null? _next: "");
83 | }
84 | }
85 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/portmap/mapping.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.portmap;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
24 | import org.dcache.oncrpc4j.rpc.OncRpcException;
25 | import org.dcache.oncrpc4j.xdr.XdrAble;
26 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
27 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
28 |
29 | public class mapping implements XdrAble {
30 |
31 | private int _prog;
32 | private int _vers;
33 | private int _prot;
34 | private int _port;
35 |
36 | public int getPort() {
37 | return _port;
38 | }
39 |
40 | public int getProg() {
41 | return _prog;
42 | }
43 |
44 | public int getProt() {
45 | return _prot;
46 | }
47 |
48 | public int getVers() {
49 | return _vers;
50 | }
51 |
52 | public mapping() {}
53 |
54 | public mapping(int prog, int vers, int prot, int port) {
55 | _prog = prog;
56 | _vers = vers;
57 | _prot = prot;
58 | _port = port;
59 | }
60 |
61 | @Override
62 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
63 | _prog = xdr.xdrDecodeInt();
64 | _vers = xdr.xdrDecodeInt();
65 | _prot = xdr.xdrDecodeInt();
66 | _port = xdr.xdrDecodeInt();
67 | }
68 |
69 | @Override
70 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
71 | xdr.xdrEncodeInt(_prog);
72 | xdr.xdrEncodeInt(_vers);
73 | xdr.xdrEncodeInt(_prot);
74 | xdr.xdrEncodeInt(_port);
75 | }
76 |
77 | @Override
78 | public String toString() {
79 | return String.format("prog: %d, vers: %d, prot: %s, port: %d",
80 | _prog, _vers, IpProtocolType.toString(_prot), _port);
81 | }
82 | }
83 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcAuthTypeNone.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import org.dcache.oncrpc4j.xdr.XdrAble;
23 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
24 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
25 | import org.slf4j.Logger;
26 | import org.slf4j.LoggerFactory;
27 |
28 | import javax.security.auth.Subject;
29 | import java.io.IOException;
30 |
31 | public class RpcAuthTypeNone implements RpcAuth, XdrAble {
32 |
33 | private final int _type = RpcAuthType.NONE;
34 | private byte[] body;
35 | private RpcAuthVerifier _verifier = new RpcAuthVerifier(RpcAuthType.NONE, new byte[0]);
36 |
37 | private static final Subject _subject;
38 | static {
39 | _subject = new Subject();
40 | _subject.setReadOnly();
41 | }
42 |
43 | private final static Logger _log = LoggerFactory.getLogger(RpcAuthTypeNone.class);
44 |
45 | public RpcAuthTypeNone() {
46 | this(new byte[0]);
47 | }
48 |
49 | public RpcAuthTypeNone(byte[] body) {
50 | this.body = body;
51 | }
52 |
53 | @Override
54 | public Subject getSubject() {
55 | return _subject;
56 | }
57 |
58 | @Override
59 | public int type() {
60 | return _type;
61 | }
62 |
63 | @Override
64 | public RpcAuthVerifier getVerifier() {
65 | return _verifier;
66 | }
67 |
68 | @Override
69 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
70 | body = xdr.xdrDecodeDynamicOpaque();
71 | _verifier = new RpcAuthVerifier(xdr);
72 | }
73 |
74 | @Override
75 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
76 | xdr.xdrEncodeInt(_type);
77 | xdr.xdrEncodeDynamicOpaque(body);
78 | _verifier.xdrEncode(xdr);
79 | }
80 |
81 | }
82 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrEncodingStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import java.nio.ByteBuffer;
23 |
24 | /**
25 | * Defines interface for encoding XDR stream. An encoding
26 | * XDR stream receives data in the form of Java data types and writes it to
27 | * a data sink (for instance, network or memory buffer) in the
28 | * platform-independent XDR format.
29 | */
30 | public interface XdrEncodingStream {
31 |
32 | void beginEncoding();
33 | void endEncoding();
34 | void xdrEncodeInt(int value);
35 | void xdrEncodeIntVector(int[] ints);
36 | void xdrEncodeIntFixedVector(int[] ints, int length);
37 | void xdrEncodeDynamicOpaque(byte [] opaque);
38 | void xdrEncodeOpaque(byte [] opaque, int len);
39 | void xdrEncodeOpaque(byte [] opaque, int offset, int len);
40 | void xdrEncodeBoolean(boolean bool);
41 | void xdrEncodeString(String str);
42 | void xdrEncodeLong(long value);
43 | void xdrEncodeLongVector(long[] longs);
44 | void xdrEncodeLongFixedVector(long[] longs, int length);
45 | void xdrEncodeByteBuffer(ByteBuffer buf);
46 | void xdrEncodeFloat(float value);
47 | void xdrEncodeDouble(double value);
48 | void xdrEncodeFloatVector(float[] value);
49 | void xdrEncodeFloatFixedVector(float[] value, int length);
50 | void xdrEncodeDoubleVector(double[] value);
51 | void xdrEncodeDoubleFixedVector(double[] value, int length);
52 | void xdrEncodeByteVector(byte[] value);
53 | void xdrEncodeByteFixedVector(byte[] value, int length);
54 | void xdrEncodeByte(byte value);
55 | void xdrEncodeShort(short value);
56 | void xdrEncodeShortVector(short[] value);
57 | void xdrEncodeShortFixedVector(short[] value, int length);
58 | /*
59 | * Fake interface for compatibility with Remote Tea RPC library
60 | *
61 | */
62 | }
63 |
--------------------------------------------------------------------------------
/oncrpc4j-core/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.dcache
7 | oncrpc4j
8 | 3.5.0-SNAPSHOT
9 |
10 |
11 | oncrpc4j-core
12 | jar
13 |
14 | ONCRPC4J core component
15 | http://www.dCache.ORG
16 |
17 |
18 |
19 |
20 | maven-jar-plugin
21 |
22 |
23 |
24 | org.dcache.oncrpc4j
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 | org.slf4j
35 | slf4j-api
36 |
37 |
38 | org.glassfish.grizzly
39 | grizzly-framework
40 |
41 |
42 | com.google.guava
43 | guava
44 |
45 |
46 | junit
47 | junit
48 | test
49 |
50 |
51 | org.mockito
52 | mockito-core
53 | test
54 |
55 |
56 | org.hamcrest
57 | hamcrest
58 | test
59 |
60 |
61 | org.bouncycastle
62 | bcprov-jdk15on
63 | test
64 |
65 |
66 | org.bouncycastle
67 | bcprov-ext-jdk15on
68 | test
69 |
70 |
71 | org.bouncycastle
72 | bcpkix-jdk15on
73 | test
74 |
75 |
76 | org.bouncycastle
77 | bctls-jdk15on
78 | test
79 |
80 |
81 |
82 |
83 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrOpaque.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcException;
23 | import com.google.common.io.BaseEncoding;
24 | import java.io.IOException;
25 | import java.util.Arrays;
26 |
27 | /**
28 | * A wrapper class that makes dynamic opaque data suitable for xdr encoding.
29 | * The wrapper provides equals and hashCode methods to make use in collections
30 | * more effective.
31 | */
32 | public class XdrOpaque implements XdrAble {
33 |
34 | private byte[] _opaque;
35 |
36 | public XdrOpaque() {
37 | }
38 |
39 | public XdrOpaque(byte[] opaque) {
40 | _opaque = opaque;
41 | }
42 |
43 | public XdrOpaque(XdrDecodingStream xdr) throws IOException {
44 | xdrDecode(xdr);
45 | }
46 |
47 | public byte[] getOpaque() {
48 | return _opaque;
49 | }
50 |
51 | @Override
52 | public int hashCode() {
53 | return Arrays.hashCode(_opaque);
54 | }
55 |
56 | @Override
57 | public boolean equals(Object o) {
58 | if (o == this) {
59 | return true;
60 | }
61 | if (!(o instanceof XdrOpaque)) {
62 | return false;
63 | }
64 |
65 | return Arrays.equals(_opaque, ((XdrOpaque) o)._opaque);
66 | }
67 |
68 | @Override
69 | public String toString() {
70 | return new StringBuilder()
71 | .append('[')
72 | .append(BaseEncoding.base16().upperCase().encode(_opaque))
73 | .append(']')
74 | .toString();
75 | }
76 |
77 | @Override
78 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
79 | _opaque = xdr.xdrDecodeDynamicOpaque();
80 | }
81 |
82 | @Override
83 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
84 | xdr.xdrEncodeDynamicOpaque(_opaque);
85 | }
86 | }
87 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/OncRpcProgram.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | /**
23 | * Each RPC service has a program number. Because most new protocols evolve,
24 | * a version field of the call message identifies which version of the protocol
25 | * the caller is using. Version numbers enable support of both old and new
26 | * protocols through the same server process.
27 | *
28 | */
29 | public class OncRpcProgram {
30 |
31 | /**
32 | * RPC program number.
33 | */
34 | private final int _number;
35 |
36 | /**
37 | * RPC program version number;
38 | */
39 | private final int _version;
40 |
41 | /**
42 | * Get program number.
43 | * @return program number
44 | */
45 | public int getNumber() {
46 | return _number;
47 | }
48 |
49 | /**
50 | * Get program version.
51 | * @return version number.
52 | */
53 | public int getVersion() {
54 | return _version;
55 | }
56 |
57 | /**
58 | * Construct a new OncRpcProgram for with a given program number and version.
59 | * @param number RPC program number.
60 | * @param version RPC program version.
61 | */
62 | public OncRpcProgram(int number, int version) {
63 | _number = number;
64 | _version = version;
65 | }
66 |
67 | @Override
68 | public boolean equals(Object obj) {
69 |
70 | if (obj == this) return true;
71 |
72 | if ( ! (obj instanceof OncRpcProgram) ) return false;
73 |
74 | final OncRpcProgram other = (OncRpcProgram) obj;
75 |
76 | return (this._number == other._number) &&
77 | (this._version == other._version);
78 | }
79 |
80 | @Override
81 | public int hashCode() {
82 | return _number ^ _version;
83 | }
84 |
85 | @Override
86 | public String toString() {
87 | return "[" + getNumber() + ":" + getVersion() + "]";
88 | }
89 | }
90 |
--------------------------------------------------------------------------------
/oncrpc4j-benchmark/src/main/java/org/dcache/oncrpc4j/benchmarks/RpcPing.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.benchmarks;
2 |
3 | import org.dcache.oncrpc4j.rpc.OncRpcClient;
4 | import org.dcache.oncrpc4j.rpc.OncRpcProgram;
5 | import org.dcache.oncrpc4j.rpc.OncRpcSvc;
6 | import org.dcache.oncrpc4j.rpc.OncRpcSvcBuilder;
7 | import org.dcache.oncrpc4j.rpc.RpcAuthTypeNone;
8 | import org.dcache.oncrpc4j.rpc.RpcCall;
9 | import org.dcache.oncrpc4j.rpc.RpcTransport;
10 | import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
11 | import org.dcache.oncrpc4j.xdr.XdrAble;
12 | import org.dcache.oncrpc4j.xdr.XdrVoid;
13 | import org.openjdk.jmh.annotations.Benchmark;
14 | import org.openjdk.jmh.annotations.BenchmarkMode;
15 | import org.openjdk.jmh.annotations.Mode;
16 | import org.openjdk.jmh.annotations.Scope;
17 | import org.openjdk.jmh.annotations.Setup;
18 | import org.openjdk.jmh.annotations.State;
19 | import org.openjdk.jmh.annotations.TearDown;
20 | import org.openjdk.jmh.runner.Runner;
21 | import org.openjdk.jmh.runner.RunnerException;
22 | import org.openjdk.jmh.runner.options.Options;
23 | import org.openjdk.jmh.runner.options.OptionsBuilder;
24 |
25 | import java.io.IOException;
26 | import java.net.InetSocketAddress;
27 | import java.util.concurrent.ExecutionException;
28 |
29 | @State(Scope.Benchmark)
30 | @BenchmarkMode(Mode.Throughput)
31 | public class RpcPing {
32 |
33 | private static final int PROG_NUMBER = 100017;
34 | private static final int PROG_VERS = 1;
35 | private static final OncRpcProgram prog = new OncRpcProgram(PROG_NUMBER, PROG_VERS);
36 |
37 | private OncRpcSvc svc;
38 | private OncRpcClient rpcClient;
39 | private RpcCall call;
40 |
41 | @Setup
42 | public void setUp() throws IOException {
43 |
44 | svc = new OncRpcSvcBuilder()
45 | .withTCP()
46 | .withoutAutoPublish()
47 | .withPort(0)
48 | .withSameThreadIoStrategy()
49 | .withRpcService(prog, call -> call.reply(XdrVoid.XDR_VOID))
50 | .build();
51 |
52 | svc.start();
53 |
54 | InetSocketAddress socketAddress = svc.getInetSocketAddress(IpProtocolType.TCP);
55 | rpcClient = new OncRpcClient(socketAddress, IpProtocolType.TCP);
56 | RpcTransport transport = rpcClient.connect();
57 | call = new RpcCall(prog.getNumber(), prog.getVersion(), new RpcAuthTypeNone(), transport);
58 | }
59 |
60 | @Benchmark
61 | public XdrAble rpcPingSingle() throws IOException, ExecutionException, InterruptedException {
62 | return call.call(0, XdrVoid.XDR_VOID, XdrVoid.class).get();
63 | }
64 |
65 | @TearDown
66 | public void tearDown() throws IOException {
67 | rpcClient.close();
68 | svc.stop();
69 | }
70 |
71 | public static void main(String[] args) throws RunnerException {
72 | Options opt = new OptionsBuilder()
73 | .include(RpcPing.class.getSimpleName())
74 | .build();
75 |
76 | new Runner(opt).run();
77 | }
78 | }
79 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/gss/JaasConfigGenerator.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc.gss;
21 |
22 | import java.io.IOException;
23 | import java.nio.charset.StandardCharsets;
24 | import java.nio.file.attribute.PosixFilePermissions;
25 | import java.nio.file.Files;
26 | import java.nio.file.Path;
27 | import java.nio.file.attribute.FileAttribute;
28 | import java.nio.file.attribute.PosixFilePermission;
29 | import java.util.EnumSet;
30 | import java.util.Set;
31 |
32 | import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
33 | import static java.nio.file.attribute.PosixFilePermission.OWNER_WRITE;
34 |
35 | /**
36 | * Utility class to generate JAAS configuration file for kerberized service.
37 | *
38 | * @since 2.3
39 | */
40 | class JaasConfigGenerator {
41 |
42 | private static final FileAttribute> OWNER_RW =
43 | PosixFilePermissions.asFileAttribute(EnumSet.of(OWNER_READ, OWNER_WRITE));
44 |
45 | private final static String KRB5_DEBUG = System.getProperty("sun.security.krb5.debug", "false");
46 |
47 | private final static String JAAS_CONFIG_TEMPLATE = "com.sun.security.jgss.accept {\n"
48 | + " com.sun.security.auth.module.Krb5LoginModule required\n"
49 | + " debug=" + KRB5_DEBUG + "\n"
50 | + " principal=\"%s\"\n"
51 | + " doNotPrompt=true\n"
52 | + " useKeyTab=true\n"
53 | + " keyTab=\"%s\"\n"
54 | + " debug=false\n"
55 | + " isInitiator=false\n"
56 | + " storeKey=true;\n"
57 | + "};";
58 |
59 | public static String generateJaasConfig(String servicePrincipal, String keytab) throws IOException {
60 |
61 | Path jaasFile = Files.createTempFile("jaas", ".conf", OWNER_RW);
62 | jaasFile.toFile().deleteOnExit();
63 |
64 | String config = String.format(JAAS_CONFIG_TEMPLATE, servicePrincipal, keytab);
65 | Files.write(jaasFile, config.getBytes(StandardCharsets.UTF_8));
66 |
67 | return jaasFile.toAbsolutePath().toString();
68 | }
69 | }
70 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenStruct.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenStruct.java,v 1.1.1.1 2003/08/13 12:03:47 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | import java.util.Vector;
28 |
29 | /**
30 | * The JrpcgenStruct class represents a single structure defined
31 | * in an rpcgen "x"-file.
32 | *
33 | * @version $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:47 $ $State: Exp $ $Locker: $
34 | * @author Harald Albrecht
35 | */
36 | public class JrpcgenStruct {
37 |
38 | /**
39 | * Structure identifier.
40 | */
41 | public String identifier;
42 |
43 | /**
44 | * Contains elements of structure. The elements are of class
45 | * {@link JrpcgenDeclaration}.
46 | */
47 | public Vector elements;
48 |
49 | /**
50 | * Returns just the identifier.
51 | */
52 | public String toString() {
53 | return identifier;
54 | }
55 |
56 | /**
57 | * Constructs a JrpcgenStruct and sets the identifier and all
58 | * its attribute elements.
59 | *
60 | * @param identifier Identifier to be declared.
61 | * @param elements Vector of atrribute elements of class
62 | * {@link JrpcgenDeclaration}.
63 | */
64 | public JrpcgenStruct(String identifier, Vector elements) {
65 | this.identifier = identifier;
66 | this.elements = elements;
67 | }
68 |
69 | /**
70 | * Dumps the structure together with its attribute elements to
71 | * System.out.
72 | */
73 | public void dump() {
74 | System.out.println("STRUCT " + identifier + ":");
75 |
76 | int size = elements.size();
77 | for ( int idx = 0; idx < size; ++idx ) {
78 | JrpcgenDeclaration d = (JrpcgenDeclaration) elements.elementAt(idx);
79 | System.out.print(" ");
80 | d.dump();
81 | }
82 | System.out.println();
83 | }
84 |
85 | }
86 |
87 | // End of JrpcgenStruct.java
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcAuthTypeTls.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2019 - 2021 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import java.io.IOException;
23 | import java.nio.charset.StandardCharsets;
24 | import javax.security.auth.Subject;
25 |
26 | import org.dcache.oncrpc4j.xdr.XdrAble;
27 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
28 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
29 |
30 |
31 | /**
32 | *
33 | */
34 | public class RpcAuthTypeTls implements RpcAuth, XdrAble {
35 |
36 | public static final RpcAuthVerifier STARTTLS_VERIFIER = new RpcAuthVerifier(RpcAuthType.NONE, "STARTTLS".getBytes(StandardCharsets.US_ASCII));
37 | public static final RpcAuthVerifier EMPTY_VERIFIER = new RpcAuthVerifier(RpcAuthType.NONE, new byte[0]);
38 |
39 | private final RpcAuthVerifier verifier;
40 | private final Subject _subject;
41 |
42 | public RpcAuthTypeTls() {
43 | this(EMPTY_VERIFIER);
44 | }
45 |
46 | public RpcAuthTypeTls(RpcAuthVerifier verifier) {
47 | _subject = new Subject();
48 | _subject.setReadOnly();
49 | this.verifier = verifier;
50 | }
51 |
52 | @Override
53 | public int type() {
54 | return RpcAuthType.TLS;
55 | }
56 |
57 | @Override
58 | public RpcAuthVerifier getVerifier() {
59 | return verifier;
60 | }
61 |
62 | @Override
63 | public Subject getSubject() {
64 | return _subject;
65 | }
66 |
67 | @Override
68 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
69 |
70 | byte[] opaque = xdr.xdrDecodeDynamicOpaque();
71 |
72 | // we are not interested in the content of the verifier, but have to consume it
73 | int type = xdr.xdrDecodeInt();
74 | byte[] rawVerifier = xdr.xdrDecodeDynamicOpaque();
75 | }
76 |
77 | @Override
78 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
79 | xdr.xdrEncodeInt(type());
80 | xdr.xdrEncodeInt(0); // spec: credential size must be zero
81 | verifier.xdrEncode(xdr);
82 | }
83 |
84 | }
85 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenEnum.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenEnum.java,v 1.1.1.1 2003/08/13 12:03:45 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | import java.util.Vector;
28 |
29 | /**
30 | * The JrpcgenEnum class represents a single enumeration
31 | * from an rpcgen "x"-file. It is a "container" for the elements (constants)
32 | * belonging to this enumeration.
33 | *
34 | * @version $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:45 $ $State: Exp $ $Locker: $
35 | * @author Harald Albrecht
36 | */
37 | public class JrpcgenEnum {
38 |
39 | /**
40 | * Enumeration identifier.
41 | */
42 | public String identifier;
43 |
44 | /**
45 | * Contains enumeration elements as well as their values. The elements
46 | * are of class {@link JrpcgenConst}.
47 | */
48 | public Vector enums;
49 |
50 | /**
51 | * Returns the fully qualified identifier.
52 | *
53 | * return fully qualified identifier.
54 | */
55 | public String toString() {
56 | return identifier;
57 | }
58 |
59 | /**
60 | * Constructs a JrpcgenEnum and sets the identifier and all
61 | * its enumeration elements.
62 | *
63 | * @param identifier Identifier to be declared.
64 | * @param enums Vector of enumeration elements of class {@link JrpcgenConst}.
65 | */
66 | public JrpcgenEnum(String identifier, Vector enums) {
67 | this.identifier = identifier;
68 | this.enums = enums;
69 | }
70 |
71 | /**
72 | * Dumps the enumeration together with its elements to
73 | * System.out.
74 | */
75 | public void dump() {
76 | System.out.println("ENUM " + identifier);
77 | int size = enums.size();
78 | for ( int idx = 0; idx < size; ++idx ) {
79 | JrpcgenConst c = (JrpcgenConst) enums.elementAt(idx);
80 | System.out.print(" ");
81 | c.dump();
82 | }
83 | System.out.println();
84 | }
85 |
86 | }
87 |
88 | // End of JrpcgenEnum.java
89 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/gss/GSSINITres.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc.gss;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcException;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
26 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
27 |
28 | /**
29 | *
30 | * @author tigran
31 | */
32 | public class GSSINITres implements XdrAble {
33 |
34 | private byte[] _handle;
35 | private int _gssMajor;
36 | private int _gssMinor;
37 | private int _sequence;
38 | private byte[] _token;
39 |
40 | public int getGssMajor() {
41 | return _gssMajor;
42 | }
43 |
44 | public void setGssMajor(int gssMajor) {
45 | this._gssMajor = gssMajor;
46 | }
47 |
48 | public int getGssMinor() {
49 | return _gssMinor;
50 | }
51 |
52 | public void setGssMinor(int gssMinor) {
53 | this._gssMinor = gssMinor;
54 | }
55 |
56 | public byte[] getHandle() {
57 | return _handle;
58 | }
59 |
60 | public void setHandle(byte[] handle) {
61 | this._handle = handle;
62 | }
63 |
64 | public int getSequence() {
65 | return _sequence;
66 | }
67 |
68 | public void setSequence(int sequence) {
69 | this._sequence = sequence;
70 | }
71 |
72 | public byte[] getToken() {
73 | return _token;
74 | }
75 |
76 | public void setToken(byte[] token) {
77 | this._token = token;
78 | }
79 |
80 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
81 | _handle = xdr.xdrDecodeDynamicOpaque();
82 | _gssMajor = xdr.xdrDecodeInt();
83 | _gssMinor = xdr.xdrDecodeInt();
84 | _sequence = xdr.xdrDecodeInt();
85 | _token = xdr.xdrDecodeDynamicOpaque();
86 | }
87 |
88 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
89 | xdr.xdrEncodeDynamicOpaque(_handle);
90 | xdr.xdrEncodeInt(_gssMajor);
91 | xdr.xdrEncodeInt(_gssMinor);
92 | xdr.xdrEncodeInt(_sequence);
93 | xdr.xdrEncodeDynamicOpaque(_token);
94 | }
95 |
96 | }
97 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/test/java/org/dcache/oncrpc4j/rpcgen/CalculatorServerImpl.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.rpcgen;
2 |
3 | import org.dcache.oncrpc4j.rpc.RpcCall;
4 |
5 | import javax.security.auth.Subject;
6 | import java.security.Principal;
7 | import java.util.ArrayList;
8 | import java.util.HashSet;
9 | import java.util.List;
10 | import java.util.Set;
11 |
12 | public class CalculatorServerImpl extends CalculatorServer {
13 | public static final int SLEEP_MILLIS = 100;
14 | private List methodCalls = new ArrayList<>();
15 |
16 | @Override
17 | public CalculationResult add_1(RpcCall call$, long arg1, long arg2) {
18 | long start = System.currentTimeMillis();
19 | CalculationResult result = new CalculationResult();
20 | result.setStartMillis(start);
21 | result.setResult(arg1 + arg2);
22 | try {
23 | Thread.sleep(SLEEP_MILLIS);
24 | } catch (InterruptedException e) {
25 | //ignore
26 | }
27 | long finish = System.currentTimeMillis();
28 | result.setFinishMillis(finish);
29 | recordAddCall(call$, start, finish, arg1, arg2, result.getResult(), null);
30 | return result;
31 | }
32 |
33 | @Override
34 | public long addSimple_1(RpcCall call$, long arg1, long arg2) {
35 | long start = System.currentTimeMillis();
36 | try {
37 | Thread.sleep(SLEEP_MILLIS);
38 | } catch (InterruptedException e) {
39 | //ignore
40 | }
41 | long result = arg1 + arg2;
42 | long finish = System.currentTimeMillis();
43 | recordAddCall(call$, start, finish, arg1, arg2, result, null);
44 | return result;
45 | }
46 |
47 | private void recordAddCall(RpcCall call, long start, long finish, long arg1, long arg2, long result, Throwable throwable) {
48 | System.err.println(arg1 + " + " + arg2 + " = " + result);
49 | Object[] args = new Object[2];
50 | args[0] = arg1;
51 | args[1] = arg2;
52 | Subject subject = call.getCredential().getSubject();
53 | Set principalNames = new HashSet<>();
54 | for (Principal p : subject.getPrincipals()) {
55 | principalNames.add(p.getName());
56 | }
57 | methodCalls.add(new MethodCall(start, finish, Thread.currentThread().getStackTrace()[1].getMethodName(), args, result, throwable, principalNames, call.getTransport().getRemoteSocketAddress().getPort()));
58 | }
59 |
60 | public List getMethodCalls() {
61 | List calls = this.methodCalls;
62 | this.methodCalls = new ArrayList<>();
63 | return calls;
64 | }
65 |
66 | public void awaitMethodCalls(long timeouts) {
67 | try {
68 | long deadline = System.currentTimeMillis() + timeouts;
69 | while (methodCalls.isEmpty()) {
70 | if (System.currentTimeMillis() > deadline) {
71 | throw new IllegalStateException("no method calls within the " + timeouts + " milli timeout");
72 | }
73 | Thread.sleep(SLEEP_MILLIS);
74 | }
75 | } catch (InterruptedException e) {
76 | throw new IllegalStateException(e);
77 | }
78 | }
79 | }
80 |
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/xdr/XdrDecodingStream.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.xdr;
21 |
22 | import java.nio.ByteBuffer;
23 |
24 | /**
25 | * Defines interface for decoding XDR stream. A decoding
26 | * XDR stream returns data in the form of Java data types which it reads
27 | * from a data source (for instance, network or memory buffer) in the
28 | * platform-independent XDR format.
29 | */
30 | public interface XdrDecodingStream {
31 |
32 |
33 | void beginDecoding();
34 | void endDecoding();
35 | int xdrDecodeInt() throws BadXdrOncRpcException;
36 | int[] xdrDecodeIntVector() throws BadXdrOncRpcException;
37 | int[] xdrDecodeIntFixedVector(int len) throws BadXdrOncRpcException;
38 | byte[] xdrDecodeDynamicOpaque() throws BadXdrOncRpcException;
39 | byte[] xdrDecodeOpaque(int size) throws BadXdrOncRpcException;
40 | void xdrDecodeOpaque(byte[] data, int offset, int len) throws BadXdrOncRpcException;
41 | boolean xdrDecodeBoolean() throws BadXdrOncRpcException;
42 | String xdrDecodeString() throws BadXdrOncRpcException;
43 | long xdrDecodeLong() throws BadXdrOncRpcException;
44 | long[] xdrDecodeLongVector() throws BadXdrOncRpcException;
45 | long[] xdrDecodeLongFixedVector(int len) throws BadXdrOncRpcException;
46 | ByteBuffer xdrDecodeByteBuffer() throws BadXdrOncRpcException;
47 | float xdrDecodeFloat() throws BadXdrOncRpcException;
48 | double xdrDecodeDouble() throws BadXdrOncRpcException;
49 | double[] xdrDecodeDoubleVector() throws BadXdrOncRpcException;
50 | double[] xdrDecodeDoubleFixedVector(int length) throws BadXdrOncRpcException;
51 | float[] xdrDecodeFloatVector() throws BadXdrOncRpcException;
52 | float[] xdrDecodeFloatFixedVector(int length) throws BadXdrOncRpcException;
53 | byte[] xdrDecodeByteVector() throws BadXdrOncRpcException;
54 | byte[] xdrDecodeByteFixedVector(int length) throws BadXdrOncRpcException;
55 | byte xdrDecodeByte() throws BadXdrOncRpcException;
56 | short xdrDecodeShort() throws BadXdrOncRpcException;
57 | short[] xdrDecodeShortVector() throws BadXdrOncRpcException;
58 | short[] xdrDecodeShortFixedVector(int length) throws BadXdrOncRpcException;
59 |
60 | /*
61 | * Fake interface for compatibility with Remote Tea RPC library
62 | *
63 | */
64 | }
65 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/cup_runtime/Symbol.java:
--------------------------------------------------------------------------------
1 | package org.acplt.oncrpc.apps.jrpcgen.cup_runtime;
2 |
3 | /**
4 | * Defines the Symbol class, which is used to represent all terminals
5 | * and nonterminals while parsing. The lexer should pass CUP Symbols
6 | * and CUP returns a Symbol.
7 | *
8 | * @version last updated: 7/3/96
9 | * @author Frank Flannery
10 | */
11 |
12 | /* ****************************************************************
13 | Class Symbol
14 | what the parser expects to receive from the lexer.
15 | the token is identified as follows:
16 | sym: the symbol type
17 | parse_state: the parse state.
18 | value: is the lexical value of type Object
19 | left : is the left position in the original input file
20 | right: is the right position in the original input file
21 | ******************************************************************/
22 | public class Symbol {
23 |
24 | /*******************************
25 | Constructor for l,r values
26 | *******************************/
27 | public Symbol(int id, int l, int r, Object o) {
28 | this(id);
29 | left = l;
30 | right = r;
31 | value = o;
32 | }
33 |
34 | /*******************************
35 | Constructor for no l,r values
36 | ********************************/
37 | public Symbol(int id, Object o) {
38 | this(id, -1, -1, o);
39 | }
40 |
41 | /*****************************
42 | Constructor for no value
43 | ***************************/
44 | public Symbol(int id, int l, int r) {
45 | this(id, l, r, null);
46 | }
47 |
48 | /***********************************
49 | Constructor for no value or l,r
50 | ***********************************/
51 | public Symbol(int sym_num) {
52 | this(sym_num, -1);
53 | left = -1;
54 | right = -1;
55 | value = null;
56 | }
57 |
58 | /***********************************
59 | Constructor to give a start state
60 | ***********************************/
61 | Symbol(int sym_num, int state) {
62 | sym = sym_num;
63 | parse_state = state;
64 | }
65 |
66 | /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
67 | /** The symbol number of the terminal or non terminal being represented */
68 | public int sym;
69 |
70 | /*. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .*/
71 | /** The parse state to be recorded on the parse stack with this symbol.
72 | * This field is for the convenience of the parser and shouldn't be
73 | * modified except by the parser.
74 | */
75 | public int parse_state;
76 | /** This allows us to catch some errors caused by scanners recycling
77 | * symbols. For the use of the parser only. [CSA, 23-Jul-1999] */
78 | boolean used_by_parser = false;
79 | /*******************************
80 | The data passed to parser
81 | *******************************/
82 | public int left, right;
83 | public Object value;
84 |
85 | /*****************************
86 | Printing this token out. (Override for pretty-print).
87 | ****************************/
88 | public String toString() {
89 | return "#" + sym;
90 | }
91 | }
92 |
93 |
94 |
95 |
96 |
97 |
98 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenUnionArm.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenUnionArm.java,v 1.2 2003/08/14 08:09:59 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | /**
28 | * The JrpcgenUnionArm class represents a single union arm defined
29 | * for a particular union in an rpcgen "x"-file.
30 | *
31 | * @version $Revision: 1.2 $ $Date: 2003/08/14 08:09:59 $ $State: Exp $ $Locker: $
32 | * @author Harald Albrecht
33 | */
34 | public class JrpcgenUnionArm {
35 |
36 | /**
37 | * Value for which the descriminated union arm is valid.
38 | */
39 | public String value;
40 |
41 | /**
42 | * Attribute element of descriminated arm (of class
43 | * {@link JrpcgenDeclaration}).
44 | */
45 | public JrpcgenDeclaration element;
46 |
47 | /**
48 | * Constructs a JrpcgenUnionArm and sets decrimated arm's
49 | * value and the associated attribute element.
50 | *
51 | * @param value Value for which descriminated arm is valid.
52 | * @param element Descriminated arm element of class
53 | * {@link JrpcgenDeclaration}.
54 | */
55 | public JrpcgenUnionArm(String value,
56 | JrpcgenDeclaration element) {
57 | this.value = value;
58 | this.element = element;
59 | }
60 |
61 | /**
62 | * Dumps the union arm to System.out.
63 | */
64 | public void dump() {
65 | if ( value == null ) {
66 | if ( element == null ) {
67 | System.out.println(" default: -");
68 | } else if ( element.identifier != null ) {
69 | System.out.print(" default: ");
70 | element.dump();
71 | } else {
72 | System.out.println(" default: void");
73 | }
74 | } else {
75 | if ( element == null ) {
76 | System.out.println(" " + value + ": -");
77 | } else if ( element.identifier != null ) {
78 | System.out.print(" " + value + ": ");
79 | element.dump();
80 | } else {
81 | System.out.println(" " + value + ": void");
82 | }
83 | }
84 | }
85 |
86 | }
87 |
88 | // End of JrpcgenUnionArm.java
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenProcedureInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenProcedureInfo.java,v 1.3 2003/08/14 11:26:50 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | import java.util.Vector;
28 |
29 | /**
30 | * The JrpcgenProcedureInfo class contains information about a
31 | * specific version of an ONC/RPC program as defined in an rpcgen "x"-file.
32 | *
33 | * @version $Revision: 1.3 $ $Date: 2003/08/14 11:26:50 $ $State: Exp $ $Locker: $
34 | * @author Harald Albrecht
35 | */
36 | class JrpcgenProcedureInfo {
37 |
38 | /**
39 | * Procedure number assigned to the procedure of a particular verions of
40 | * an ONC/RPC program. This attribute contains either an integer literal
41 | * or an identifier (which must resolve to an integer).
42 | */
43 | public String procedureNumber;
44 |
45 | /**
46 | * Identifier assigned to the procedure number of an a particular
47 | * procedure of a particular version of an ONC/RPC program.
48 | */
49 | public String procedureId;
50 |
51 | /**
52 | * Type specifier of the result returned by the remote procedure.
53 | */
54 | public String resultType;
55 |
56 | /**
57 | * Parameter(s) to the remote procedure.
58 | */
59 | public Vector parameters;
60 |
61 | /**
62 | * Constructs a new JrpcgenProcedureInfo object containing
63 | * information about a programs' version and a set of procedures
64 | * defined by this program version.
65 | *
66 | * @param procedureId Identifier assigned to the procedure of a particular
67 | * version of an ONC/RPC program.
68 | * @param procedureNumber Procedure number assigned to remote procedure.
69 | * @param resultType Type specifier of result returned by remote procedure.
70 | * @param parameters Type specifier of parameter to the remote procedure.
71 | */
72 | public JrpcgenProcedureInfo(String procedureId, String procedureNumber,
73 | String resultType, Vector parameters) {
74 | this.procedureId = procedureId;
75 | this.procedureNumber = procedureNumber;
76 | this.resultType = resultType;
77 | this.parameters = parameters;
78 | }
79 |
80 | }
81 |
82 | // End of JrpcgenProcedureInfo.java
--------------------------------------------------------------------------------
/oncrpc4j-spring/pom.xml:
--------------------------------------------------------------------------------
1 |
2 | 4.0.0
3 |
4 |
5 | org.dcache
6 | oncrpc4j
7 | 3.5.0-SNAPSHOT
8 |
9 |
10 | oncrpc4j-spring
11 | jar
12 |
13 | Spring integration for ONCRPC4J
14 | http://www.dCache.ORG
15 |
16 |
17 | 2.3
18 |
19 |
20 |
21 |
22 |
23 | org.apache.maven.plugins
24 | maven-assembly-plugin
25 | ${maven-assembly-plugin.version}
26 |
27 |
28 |
29 | attached
30 |
31 | package
32 |
33 |
34 | jar-with-dependencies
35 |
36 |
37 |
38 | org.dcache.xdr.SpringRunner
39 | org.dcache.xdr
40 |
41 |
42 |
43 | development
44 | ${buildNumber}
45 | ${project.url}
46 | ${maven.build.timestamp}
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | org.apache.maven.plugins
55 | maven-jar-plugin
56 |
57 |
58 |
59 | org.dcache.xdr.SpringRunner
60 |
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 | org.springframework
70 | spring-context
71 |
72 |
73 | org.slf4j
74 | slf4j-simple
75 | runtime
76 |
77 |
78 | org.dcache
79 | oncrpc4j-core
80 | ${project.version}
81 |
82 |
83 |
84 |
--------------------------------------------------------------------------------
/oncrpc4j-portmapdaemon/src/main/java/org/dcache/jarpcbind/Main.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.jarpcbind;
21 |
22 | import org.dcache.oncrpc4j.rpc.OncRpcProgram;
23 | import org.dcache.oncrpc4j.rpc.OncRpcSvc;
24 | import org.dcache.oncrpc4j.rpc.OncRpcSvcBuilder;
25 | import org.dcache.oncrpc4j.rpc.RpcDispatchable;
26 | import org.dcache.oncrpc4j.portmap.OncRpcPortmap;
27 | import org.dcache.oncrpc4j.portmap.OncRpcbindServer;
28 | import org.slf4j.Logger;
29 | import org.slf4j.LoggerFactory;
30 |
31 | public class Main {
32 | private static final Logger logger = LoggerFactory.getLogger(Main.class);
33 | private static final Object LOCK = new Object();
34 | private static volatile boolean on = true;
35 | private static volatile Thread mainThread;
36 |
37 | public static void main(String[] args) throws Exception {
38 | mainThread = Thread.currentThread();
39 | logger.info("starting up");
40 | Runtime.getRuntime().addShutdownHook(new Thread() {
41 | @Override
42 | public void run() {
43 | logger.info("interrupt received, shutting down");
44 | synchronized (LOCK) {
45 | on = false;
46 | LOCK.notifyAll();
47 | mainThread.interrupt();
48 | }
49 | try {
50 | mainThread.join();
51 | } catch (InterruptedException e) {
52 | logger.error("interrupted waiting for graceful shutdown", e);
53 | }
54 | logger.info("exiting");
55 | }
56 | });
57 | RpcDispatchable rpcbind = new OncRpcbindServer();
58 | OncRpcSvc server = new OncRpcSvcBuilder()
59 | .withPort(OncRpcPortmap.PORTMAP_PORT)
60 | .withTCP()
61 | .withUDP()
62 | .withSameThreadIoStrategy()
63 | .withoutAutoPublish()
64 | .build();
65 | server.register(new OncRpcProgram(OncRpcPortmap.PORTMAP_PROGRAMM, OncRpcPortmap.PORTMAP_V2), rpcbind);
66 | server.start();
67 | logger.info("up and running");
68 | synchronized (LOCK) {
69 | while (on) {
70 | try {
71 | LOCK.wait();
72 | } catch (InterruptedException e) {
73 | if (on) {
74 | logger.error("spurious interruption", e);
75 | }
76 | }
77 | }
78 | }
79 | logger.info("shutting down");
80 | }
81 | }
82 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenVersionInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenVersionInfo.java,v 1.1.1.1 2003/08/13 12:03:47 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | import java.util.Vector;
28 | import java.io.PrintWriter;
29 |
30 | /**
31 | * The JrpcgenVersionInfo class contains information about a
32 | * specific version of an ONC/RPC program as defined in a rpcgen "x"-file.
33 | *
34 | * @version $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:47 $ $State: Exp $ $Locker: $
35 | * @author Harald Albrecht
36 | */
37 | class JrpcgenVersionInfo {
38 |
39 | /**
40 | * Version number assigned to an ONC/RPC program. This attribute contains
41 | * either an integer literal or an identifier (which must resolve to an
42 | * integer).
43 | */
44 | public String versionNumber;
45 |
46 | /**
47 | * Identifier assigned to the version number of an ONC/RPC program.
48 | */
49 | public String versionId;
50 |
51 | /**
52 | * Set of procedures specified for a particular ONC/RPC program.
53 | * The elements in the set are of class {@link JrpcgenProcedureInfo}.
54 | */
55 | public Vector procedures;
56 |
57 | /**
58 | * Constructs a new JrpcgenVersionInfo object containing
59 | * information about a programs' version and a set of procedures
60 | * defined by this program version.
61 | *
62 | * @param versionId Identifier defined for this version of a
63 | * particular ONC/RPC program.
64 | * @param versionNumber Version number.
65 | * @param procedures Vector of procedures defined for this ONC/RPC program.
66 | */
67 | public JrpcgenVersionInfo(String versionId, String versionNumber,
68 | Vector procedures) {
69 | this.versionId = versionId;
70 | this.versionNumber = versionNumber;
71 | this.procedures = procedures;
72 | }
73 |
74 | /**
75 | * Generates source code to define the version constant belonging to this
76 | * program.
77 | *
78 | * @param out PrintWriter to send source code to.
79 | */
80 | public void dumpConstants(PrintWriter out) {
81 | out.println(" /* ONC/RPC program version number definition */");
82 | out.println(" public final static int "
83 | + versionId + " = " + versionNumber + ";");
84 | }
85 |
86 | }
87 |
88 | // End of JrpcgenVersionInfo.java
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/rpc/RpcTransport.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2019 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.rpc;
21 |
22 | import com.google.common.annotations.Beta;
23 | import java.net.InetSocketAddress;
24 | import java.nio.channels.CompletionHandler;
25 | import org.dcache.oncrpc4j.xdr.Xdr;
26 |
27 | /**
28 | *
29 | * Abstraction for sending reply to clients
30 | *
31 | */
32 | public interface RpcTransport {
33 |
34 | /**
35 | * Send data to remote end point. The handler parameter is a completion
36 | * handler that is invoked when the send operation completes (or fails). The
37 | * result passed to the completion handler is the number of bytes sent.
38 | *
39 | * @param the type of the attachment.
40 | * @param xdr message to send.
41 | * @param attachment the object to attach to the I/O operation; can be null
42 | * @param handler the handler for consuming the result.
43 | */
44 | void send(Xdr xdr, A attachment, CompletionHandler handler);
45 |
46 | ReplyQueue getReplyQueue();
47 |
48 | /**
49 | * Returns is this transport is open and ready.
50 | *
51 | * @return true, if connection is open and ready, or false
52 | * otherwise.
53 | */
54 | boolean isOpen();
55 |
56 | /**
57 | * Get local end point.
58 | *
59 | * @return InetSocketAddress of local socket end point
60 | */
61 | InetSocketAddress getLocalSocketAddress();
62 |
63 | /**
64 | * Get remote end point.
65 | *
66 | * @return InetSocketAddress of remote socket end point.
67 | */
68 | InetSocketAddress getRemoteSocketAddress();
69 |
70 | /**
71 | * Get {@link RpcTransport} for to sent/receive requests in opposite direction.
72 | * The returned transport can be used by servers to send RPC calls to clients and
73 | * can be used by clients to receive RPC calls from servers.
74 | *
75 | * @return {@code RpcTransport} connected to the remote peer.
76 | */
77 | public RpcTransport getPeerTransport();
78 |
79 |
80 | /**
81 | * Enable TLS on this transport.
82 | * @throws RpcAuthException if handshake can't be initialized (due to missing configuration).
83 | * @throws IllegalStateException if TLS is already enabled.
84 | */
85 | @Beta
86 | void startTLS() throws RpcAuthException, IllegalStateException;
87 |
88 | /**
89 | * Check whatever this transport is protected by TLS.
90 | * @return {@code true} if and only if this transport is connected and protected by TLS.
91 | */
92 | @Beta
93 | boolean isTLS();
94 | }
95 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenUnion.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenUnion.java,v 1.1.1.1 2003/08/13 12:03:47 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | import java.util.Vector;
28 |
29 | /**
30 | * The JrpcgenUnion class represents a single union defined
31 | * in an rpcgen "x"-file.
32 | *
33 | * @version $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:47 $ $State: Exp $ $Locker: $
34 | * @author Harald Albrecht
35 | */
36 | public class JrpcgenUnion {
37 |
38 | /**
39 | * Union identifier.
40 | */
41 | public String identifier;
42 |
43 | /**
44 | * {@link JrpcgenDeclaration} of descriminant element (containing its
45 | * identifier and data type).
46 | */
47 | public JrpcgenDeclaration descriminant;
48 |
49 | /**
50 | * Contains arms of union. The arms are of class
51 | * {@link JrpcgenDeclaration}. The keys are the descriminant values.
52 | */
53 | public Vector elements;
54 |
55 | /**
56 | * Returns just the identifier.
57 | */
58 | public String toString() {
59 | return identifier;
60 | }
61 |
62 | /**
63 | * Constructs a JrpcgenUnion and sets the identifier, the
64 | * descrimant element as well as all attribute elements.
65 | *
66 | * @param identifier Identifier to be declared.
67 | * @param descriminant Descriminant element of class
68 | * {@link JrpcgenDeclaration}.
69 | * @param elements Vector of atrribute elements of class
70 | * {@link JrpcgenDeclaration}.
71 | */
72 | public JrpcgenUnion(String identifier, JrpcgenDeclaration descriminant,
73 | Vector elements) {
74 | this.identifier = identifier;
75 | this.descriminant = descriminant;
76 | this.elements = elements;
77 | }
78 |
79 | /**
80 | * Dumps the union together with its attribute elements end the
81 | * descriminant to System.out.
82 | */
83 | public void dump() {
84 | System.out.println("UNION " + identifier + ":");
85 | System.out.println(" switch (" + descriminant.type + " " + descriminant.identifier + ")");
86 |
87 | int size = elements.size();
88 | for ( int idx = 0; idx < size; ++idx ) {
89 | JrpcgenUnionArm a = (JrpcgenUnionArm) elements.elementAt(idx);
90 | System.out.print(" ");
91 | a.dump();
92 | }
93 | System.out.println();
94 | }
95 |
96 | }
97 |
98 | // End of JrpcgenUnion.java
--------------------------------------------------------------------------------
/oncrpc4j-core/src/main/java/org/dcache/oncrpc4j/portmap/rpcb.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright (c) 2009 - 2018 Deutsches Elektronen-Synchroton,
3 | * Member of the Helmholtz Association, (DESY), HAMBURG, GERMANY
4 | *
5 | * This library is free software; you can redistribute it and/or modify
6 | * it under the terms of the GNU Library General Public License as
7 | * published by the Free Software Foundation; either version 2 of the
8 | * License, or (at your option) any later version.
9 | *
10 | * This library is distributed in the hope that it will be useful,
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 | * GNU Library General Public License for more details.
14 | *
15 | * You should have received a copy of the GNU Library General Public
16 | * License along with this program (see the file COPYING.LIB for more
17 | * details); if not, write to the Free Software Foundation, Inc.,
18 | * 675 Mass Ave, Cambridge, MA 02139, USA.
19 | */
20 | package org.dcache.oncrpc4j.portmap;
21 |
22 | import java.io.IOException;
23 | import org.dcache.oncrpc4j.rpc.OncRpcException;
24 | import org.dcache.oncrpc4j.xdr.XdrAble;
25 | import org.dcache.oncrpc4j.xdr.XdrDecodingStream;
26 | import org.dcache.oncrpc4j.xdr.XdrEncodingStream;
27 |
28 | /**
29 | *
30 | * A mapping of (program, version, network ID) to address.
31 | */
32 | public class rpcb implements XdrAble {
33 |
34 | /**
35 | * program number
36 | */
37 | private int _prog;
38 | /**
39 | * version number
40 | */
41 | private int _vers;
42 | /**
43 | * network id
44 | */
45 | private String _netid;
46 | /**
47 | * universal address
48 | */
49 | private String _addr;
50 | /**
51 | * owner of this service
52 | */
53 | private String _owner;
54 |
55 | public rpcb() {}
56 |
57 | public rpcb(int prog, int vers, String netid, String addr, String owner) {
58 | _prog = prog;
59 | _vers = vers;
60 | _netid = netid;
61 | _addr = addr;
62 | _owner = owner;
63 | }
64 |
65 | public int getProg() {
66 | return _prog;
67 | }
68 |
69 | public int getVers() {
70 | return _vers;
71 | }
72 |
73 | public String getNetid() {
74 | return _netid;
75 | }
76 |
77 | public String getOwner() {
78 | return _owner;
79 | }
80 |
81 | public String getAddr() {
82 | return _addr;
83 | }
84 |
85 | public void xdrDecode(XdrDecodingStream xdr) throws OncRpcException, IOException {
86 | _prog = xdr.xdrDecodeInt();
87 | _vers = xdr.xdrDecodeInt();
88 |
89 | _netid = xdr.xdrDecodeString();
90 | _addr = xdr.xdrDecodeString();
91 | _owner = xdr.xdrDecodeString();
92 |
93 | }
94 |
95 | public void xdrEncode(XdrEncodingStream xdr) throws OncRpcException, IOException {
96 | xdr.xdrEncodeInt(_prog);
97 | xdr.xdrEncodeInt(_vers);
98 |
99 | xdr.xdrEncodeString(_netid);
100 | xdr.xdrEncodeString(_addr);
101 | xdr.xdrEncodeString(_owner);
102 | }
103 |
104 | @Override
105 | public String toString() {
106 | return String.format("prog: %d, vers: %d, netid: %s, addr: %s, owner: %s",
107 | _prog, _vers, _netid, _addr, _owner);
108 | }
109 |
110 | boolean match(rpcb query) {
111 | return query._prog == _prog &&
112 | query._vers == _vers &&
113 | query._netid.equals(_netid);
114 | }
115 | }
116 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/main/java/org/acplt/oncrpc/apps/jrpcgen/JrpcgenProgramInfo.java:
--------------------------------------------------------------------------------
1 | /*
2 | * $Header: /cvsroot/remotetea/remotetea/src/org/acplt/oncrpc/apps/jrpcgen/JrpcgenProgramInfo.java,v 1.1.1.1 2003/08/13 12:03:46 haraldalbrecht Exp $
3 | *
4 | * Copyright (c) 1999, 2000
5 | * Lehrstuhl fuer Prozessleittechnik (PLT), RWTH Aachen
6 | * D-52064 Aachen, Germany.
7 | * All rights reserved.
8 | *
9 | * This library is free software; you can redistribute it and/or modify
10 | * it under the terms of the GNU Library General Public License as
11 | * published by the Free Software Foundation; either version 2 of the
12 | * License, or (at your option) any later version.
13 | *
14 | * This library is distributed in the hope that it will be useful,
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 | * GNU Library General Public License for more details.
18 | *
19 | * You should have received a copy of the GNU Library General Public
20 | * License along with this program (see the file COPYING.LIB for more
21 | * details); if not, write to the Free Software Foundation, Inc.,
22 | * 675 Mass Ave, Cambridge, MA 02139, USA.
23 | */
24 |
25 | package org.acplt.oncrpc.apps.jrpcgen;
26 |
27 | import java.util.Vector;
28 | import java.io.PrintWriter;
29 |
30 | /**
31 | * The JrpcgenProgramInfo class contains information about a
32 | * single ONC/RPC program as defined in an rpcgen "x"-file.
33 | *
34 | * @version $Revision: 1.1.1.1 $ $Date: 2003/08/13 12:03:46 $ $State: Exp $ $Locker: $
35 | * @author Harald Albrecht
36 | */
37 | class JrpcgenProgramInfo {
38 |
39 | /**
40 | * Program number assigned to an ONC/RPC program. This attribute contains
41 | * either an integer literal or an identifier (which must resolve to an
42 | * integer).
43 | */
44 | public String programNumber;
45 |
46 | /**
47 | * Identifier assigned to the program number of an ONC/RPC program.
48 | */
49 | public String programId;
50 |
51 | /**
52 | * Set of versions specified for a particular ONC/RPC program.
53 | * The elements in the set are of class {@link JrpcgenVersionInfo}.
54 | */
55 | public Vector versions;
56 |
57 | /**
58 | * Construct a new JrpcgenProgramInfo object containing the
59 | * programs's identifier and number, as well as the versions defined
60 | * for this particular ONC/RPC program.
61 | *
62 | * @param programId Identifier defined for this ONC/RPC program.
63 | * @param programNumber Program number assigned to this ONC/RPC program.
64 | * @param versions Vector of versions defined for this ONC/RPC program.
65 | */
66 | public JrpcgenProgramInfo(String programId, String programNumber,
67 | Vector versions) {
68 | this.programId = programId;
69 | this.programNumber = programNumber;
70 | this.versions = versions;
71 | }
72 |
73 | /**
74 | * Generates source code to define all constants belonging to this
75 | * program.
76 | *
77 | * @param out PrintWriter to send source code to.
78 | */
79 | public void dumpConstants(PrintWriter out) {
80 | out.println(" /* ONC/RPC program number definition */");
81 | out.println(" public final static int "
82 | + programId + " = " + programNumber + ";");
83 |
84 | int size = versions.size();
85 | for ( int idx = 0; idx < size; ++idx ) {
86 | JrpcgenVersionInfo version =
87 | (JrpcgenVersionInfo) versions.elementAt(idx);
88 | version.dumpConstants(out);
89 | }
90 | }
91 |
92 | }
93 |
94 | // End of JrpcgenProgramInfo.java
95 |
--------------------------------------------------------------------------------
/oncrpc4j-benchmark/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 |
6 | org.dcache
7 | oncrpc4j
8 | 3.5.0-SNAPSHOT
9 |
10 |
11 | Set of JMH benchmarks for oncrpc4j
12 | oncrpc4j-benchmarks
13 | jar
14 |
15 |
18 |
19 |
20 | org.openjdk.jmh
21 | jmh-core
22 |
23 |
24 | org.openjdk.jmh
25 | jmh-generator-annprocess
26 |
27 |
28 |
29 | org.bouncycastle
30 | bcprov-jdk15on
31 |
32 |
33 | org.bouncycastle
34 | bcprov-ext-jdk15on
35 |
36 |
37 | org.bouncycastle
38 | bcpkix-jdk15on
39 |
40 |
41 |
42 | org.dcache
43 | oncrpc4j-core
44 | ${project.version}
45 |
46 |
47 | org.slf4j
48 | slf4j-nop
49 | 1.7.36
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 | org.apache.maven.plugins
58 | maven-shade-plugin
59 | 3.6.1
60 |
61 |
62 | package
63 |
64 | shade
65 |
66 |
67 |
68 |
69 | org.openjdk.jmh.Main
70 |
71 |
72 |
73 |
74 |
75 |
79 | *:*
80 |
81 | META-INF/*.SF
82 | META-INF/*.DSA
83 | META-INF/*.RSA
84 |
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/oncrpc4j-rpcgen/src/test/java/org/dcache/oncrpc4j/rpcgen/SyncCalculatorTest.java:
--------------------------------------------------------------------------------
1 | package org.dcache.oncrpc4j.rpcgen;
2 |
3 | import org.dcache.oncrpc4j.rpc.IoStrategy;
4 | import org.dcache.oncrpc4j.rpc.net.IpProtocolType;
5 | import org.dcache.oncrpc4j.rpc.RpcAuthTypeNone;
6 | import org.dcache.oncrpc4j.rpc.RpcAuthTypeUnix;
7 | import org.junit.Assert;
8 | import org.junit.Test;
9 |
10 | import java.net.InetAddress;
11 | import java.net.ServerSocket;
12 | import java.util.Arrays;
13 | import java.util.HashSet;
14 | import java.util.List;
15 | import java.util.concurrent.TimeUnit;
16 | import java.util.concurrent.TimeoutException;
17 |
18 | public class SyncCalculatorTest extends AbstractCalculatorTest {
19 |
20 | @Test
21 | public void testSyncAdd() throws Exception {
22 | CalculationResult result = client.add_1(1, 2, 0, null, null);
23 | Assert.assertNotNull(result);
24 | Assert.assertEquals(3, result.getResult());
25 | }
26 |
27 | @Test
28 | public void testSyncAddSimple() throws Exception {
29 | Assert.assertEquals(3, client.addSimple_1(1, 2, 0, null, null));
30 | }
31 |
32 | @Test(expected = TimeoutException.class)
33 | public void testSyncAddTimeout() throws Exception {
34 | client.add_1(3, 4, CalculatorServerImpl.SLEEP_MILLIS / 10, TimeUnit.MILLISECONDS, null);
35 | }
36 |
37 | @Test
38 | public void testPerCallAuth() throws Exception {
39 | serverImpl.getMethodCalls(); //clear it just in case
40 | client.add_1(5, 6, 0, null, null);
41 | List calls = serverImpl.getMethodCalls();
42 | Assert.assertEquals(1, calls.size());
43 | MethodCall call = calls.get(0);
44 | Assert.assertTrue(call.getPrincipalNames().isEmpty()); //because thats how the super class constructs the client
45 | client.add_1(7, 8, 0, null, new RpcAuthTypeUnix(1, 2, new int[]{3, 4}, 5, "bob"));
46 | calls = serverImpl.getMethodCalls();
47 | Assert.assertEquals(1, calls.size());
48 | call = calls.get(0);
49 | Assert.assertEquals(new HashSet<>(Arrays.asList("1", "2", "3", "4")), call.getPrincipalNames());
50 | }
51 |
52 | @Test
53 | public void testCustomLocalPort() throws Exception {
54 | serverImpl.getMethodCalls(); //clear it just in case
55 | client.add_1(5, 6, 0, null, null);
56 | List calls = serverImpl.getMethodCalls();
57 | Assert.assertEquals(1, calls.size());
58 | MethodCall call = calls.get(0);
59 | int existingClientPort = call.getClientPort();
60 |
61 | int freeLocalPort;
62 | try (ServerSocket s = new ServerSocket(0)) {
63 | freeLocalPort = s.getLocalPort();
64 | }
65 | Assert.assertTrue(existingClientPort != freeLocalPort);
66 |
67 | CalculatorClient customClient = new CalculatorClient(
68 | InetAddress.getByName(address),
69 | port,
70 | new RpcAuthTypeNone(),
71 | Calculator.CALCULATOR,
72 | Calculator.CALCULATORVERS,
73 | IpProtocolType.TCP,
74 | freeLocalPort);
75 |
76 | customClient.add_1(42, -1, 0, null, null);
77 |
78 | calls = serverImpl.getMethodCalls();
79 | Assert.assertEquals(1, calls.size());
80 | call = calls.get(0);
81 | Assert.assertEquals(freeLocalPort, call.getClientPort());
82 | }
83 |
84 | @Test
85 | public void testIoStrategy() throws Exception {
86 | CalculatorClient customClient = new CalculatorClient(
87 | InetAddress.getByName(address),
88 | port,
89 | new RpcAuthTypeNone(),
90 | Calculator.CALCULATOR,
91 | Calculator.CALCULATORVERS,
92 | IpProtocolType.TCP,
93 | 0,
94 | IoStrategy.SAME_THREAD
95 | );
96 |
97 | Assert.assertEquals(41, customClient.add_1(42, -1, 0, null, null).getResult());
98 | }
99 | }
100 |
--------------------------------------------------------------------------------