[libbluray-devel] IxcRegistryImpl: verify interfaces
hpi1
git at videolan.org
Tue Dec 10 10:24:49 CET 2013
libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Tue Dec 10 10:51:38 2013 +0200| [6c5a7774080d2841b0fe9ebda99ca083c0f49d65] | committer: hpi1
IxcRegistryImpl: verify interfaces
> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=6c5a7774080d2841b0fe9ebda99ca083c0f49d65
---
.../bdj/java/org/videolan/IxcRegistryImpl.java | 58 +++++++++++++++++++-
1 file changed, 56 insertions(+), 2 deletions(-)
diff --git a/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java b/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java
index c3802f3..a9ed8da 100644
--- a/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java
+++ b/src/libbluray/bdj/java/org/videolan/IxcRegistryImpl.java
@@ -152,8 +152,55 @@ public class IxcRegistryImpl {
getAllInterfaces(objClass.getSuperclass(), resultList);
}
+ private static final void verifyRemoteInterfaces(Class remoteClass) throws RemoteException {
+ Class[] remoteInterfaces = remoteClass.getInterfaces();
+ for (int i = 0; i < remoteInterfaces.length; i++) {
+ if (Remote.class.isAssignableFrom(remoteInterfaces[i])) {
+ Method[] remoteMethods = remoteInterfaces[i].getMethods();
+ for (int j = 0; j < remoteMethods.length; j++) {
+ verifyRemoteMethod(remoteMethods[j]);
+ }
+ }
+ }
+ }
+
+ private static final void verifyRemoteMethod(Method remoteMethod) throws RemoteException {
+ Class[] expTypes = remoteMethod.getExceptionTypes();
+ boolean hasRemoteException = false;
+ for (int i = 0; i < expTypes.length; i++) {
+ if (expTypes[i].isAssignableFrom(RemoteException.class)) {
+ hasRemoteException = true;
+ break;
+ }
+ }
+ if (!hasRemoteException) {
+ throw new RemoteException("no RemoteException found from remote method");
+ }
+
+ Class[] paramTypes = remoteMethod.getParameterTypes();
+ for (int i = 0; i < paramTypes.length; i++) {
+ verifyRemoteParameters(paramTypes[i]);
+ }
+ verifyRemoteParameters(remoteMethod.getReturnType());
+ }
+
+ private static final void verifyRemoteParameters(Class parameter) throws RemoteException {
+ if (Remote.class.isAssignableFrom(parameter)) {
+ if (!parameter.isInterface())
+ throw new RemoteException("remote parameter is not an interface");
+ Class[] superInterfaces = parameter.getInterfaces();
+ for (int j = 0; j < superInterfaces.length; j++) {
+ if (!Remote.class.isAssignableFrom(superInterfaces[j]))
+ throw new RemoteException("remote parameter not assignable");
+ }
+ }
+ else if ((!parameter.isPrimitive()) && (!parameter.equals(Void.TYPE)) && (!Serializable.class.isAssignableFrom(parameter))) {
+ throw new RemoteException("invalid parameter");
+ }
+ }
+
private class RemoteObjectInvocationHandler implements InvocationHandler {
- public WrappedRemoteObj remoteObj = null;
+ public IxcRegistryImpl.WrappedRemoteObj remoteObj = null;
public RemoteObjectInvocationHandler(IxcRegistryImpl.WrappedRemoteObj remoteObj) {
TRACE("RemoteInvocationHandler created for " + remoteObj);
@@ -168,7 +215,14 @@ public class IxcRegistryImpl {
TRACE("RemoteInvocationHandler called for " + remoteObj);
- /* TODO: verify interfaces */
+ if (null != args) {
+ /* verify interfaces */
+ for (int i = 0; i < args.length; i++) {
+ if ((null != args[i]) && (Remote.class.isAssignableFrom(args[i].getClass()))) {
+ IxcRegistryImpl.verifyRemoteInterfaces(args[i].getClass());
+ }
+ }
+ }
RemoteMethod remoteMethod = new RemoteMethod(method, remoteObj.context, args);
More information about the libbluray-devel
mailing list