summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Johnson <mjj29@hecate.trinhall.cam.ac.uk>2006-12-13 12:28:10 +0000
committerMatthew Johnson <mjj29@hecate.trinhall.cam.ac.uk>2006-12-13 12:28:10 +0000
commit5431ff5e30ff66c7b0cae3b5d6b42cebea021737 (patch)
tree7c729040b3c4c98b0a8091e43a6809c0098d89a1
parent1a0cfae86dbe8c11270df6df395ec23691116def (diff)
add checks and docs for DBusInterface outside package; make dist correctly with new script locations
-rw-r--r--Makefile4
-rw-r--r--changelog4
-rw-r--r--dbus-java.tex4
-rw-r--r--org/freedesktop/dbus/DBusConnection.java19
-rw-r--r--org/freedesktop/dbus/DBusMatchRule.java17
5 files changed, 35 insertions, 13 deletions
diff --git a/Makefile b/Makefile
index 0ea938d..256fcbd 100644
--- a/Makefile
+++ b/Makefile
@@ -231,7 +231,7 @@ install-doc: doc
cp -a doc/api/* $(DESTDIR)$(DOCPREFIX)/api
dist: .dist
-.dist: bin dbus-java.c dbus-java.tex Makefile org tmp-session.conf CreateInterface.sgml ListDBus.sgml DBusViewer.sgml changelog AUTHORS COPYING README INSTALL
+.dist: dbus-java.c dbus-java.tex Makefile org tmp-session.conf CreateInterface.sgml ListDBus.sgml DBusViewer.sgml changelog AUTHORS COPYING README INSTALL CreateInterface.sh ListDBus.sh DBusViewer.sh
mkdir -p libdbus-java-$(VERSION)
cp -fa $^ libdbus-java-$(VERSION)
touch .dist
@@ -247,7 +247,7 @@ libdbus-java-$(VERSION): .dist
libdbus-java-$(VERSION).tar.gz: .dist
tar zcf $@ libdbus-java-$(VERSION)
-libdbus-java-$(RELEASEVERSION).tar.gz: bin dbus-java.c dbus-java.tex Makefile org tmp-session.conf CreateInterface.sgml ListDBus.sgml DBusViewer.sgml changelog AUTHORS COPYING README INSTALL
+libdbus-java-$(RELEASEVERSION).tar.gz: dbus-java.c dbus-java.tex Makefile org tmp-session.conf CreateInterface.sgml ListDBus.sgml DBusViewer.sgml changelog AUTHORS COPYING README INSTALL CreateInterface.sh ListDBus.sh DBusViewer.sh
mkdir -p libdbus-java-$(RELEASEVERSION)/
cp -fa $^ libdbus-java-$(RELEASEVERSION)/
tar zcf $@ libdbus-java-$(RELEASEVERSION)
diff --git a/changelog b/changelog
index e58292c..fd82a48 100644
--- a/changelog
+++ b/changelog
@@ -8,7 +8,9 @@ Version 1.13:
* parameterize /usr/lib as DBUSLIBDIR
Spotted by Roberto Francisco Arroyo Moreno <robfram -at- ugr -dot- es>
* rejig build system to replace variables in wrapper in make stage and
- use DESTDIR properly, hence removing the RUPREFIX stuff.
+ use DESTDIR properly, hence removing the RUNPREFIX stuff.
+ * add checks and documentation for DBusInterfaces not being in a package.
+ Spotted by Henrik Petander <henrik -dot- petander -at- iki -dot- fi>
Version 1.12:
diff --git a/dbus-java.tex b/dbus-java.tex
index f30bd12..84a197b 100644
--- a/dbus-java.tex
+++ b/dbus-java.tex
@@ -205,7 +205,9 @@ if (stuffreply.hasReply()) {
To call methods or expose methods on D-Bus you need to define them with their
exact signature in a Java interface. The full name of this interface must be
-the same as the D-Bus interface they represent.
+the same as the D-Bus interface they represent. In addition, D-Bus interface
+names must contain at least one period. This means that DBusInterfaces cannot
+be declared without being in a package.
For example, if I want to expose methods on the interface {\em
``org.freedesktop.DBus''} I would define a Java interface in the package {\tt
diff --git a/org/freedesktop/dbus/DBusConnection.java b/org/freedesktop/dbus/DBusConnection.java
index 4577fcd..bf9b06d 100644
--- a/org/freedesktop/dbus/DBusConnection.java
+++ b/org/freedesktop/dbus/DBusConnection.java
@@ -122,6 +122,10 @@ class ExportedObject
Map<MethodTuple,Method> m = new HashMap<MethodTuple,Method>();
for (Class i: c.getInterfaces())
if (DBusInterface.class.equals(i)) {
+ // don't let people export things which don't have a
+ // valid D-Bus interface name
+ if (i.getName().equals(i.getSimpleName()))
+ throw new DBusException("DBusInterfaces cannot be declared outside a package");
// add this class's public methods
if (c.getName().length() > DBusConnection.MAX_NAME_LENGTH)
throw new DBusException("Introspected interface name exceeds 255 characters. Cannot export objects of type "+c.getName()+".");
@@ -1207,7 +1211,7 @@ public class DBusConnection
* as the interface the remote object is exporting.
* @return A reference to a remote object.
* @throws ClassCastException If type is not a sub-type of DBusInterface
- * @throws DBusException If busname or objectpath are incorrectly formatted.
+ * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package.
*/
public DBusInterface getPeerRemoteObject(String busname, String objectpath, Class<? extends DBusInterface> type) throws DBusException
{
@@ -1297,7 +1301,7 @@ public class DBusConnection
* returned immediately.
* @return A reference to a remote object.
* @throws ClassCastException If type is not a sub-type of DBusInterface
- * @throws DBusException If busname or objectpath are incorrectly formatted.
+ * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package.
*/
public DBusInterface getPeerRemoteObject(String busname, String objectpath, Class<? extends DBusInterface> type, boolean autostart) throws DBusException
{
@@ -1323,7 +1327,7 @@ public class DBusConnection
* as the interface the remote object is exporting.
* @return A reference to a remote object.
* @throws ClassCastException If type is not a sub-type of DBusInterface
- * @throws DBusException If busname or objectpath are incorrectly formatted.
+ * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package.
*/
public DBusInterface getRemoteObject(String busname, String objectpath, Class<? extends DBusInterface> type) throws DBusException
{
@@ -1345,7 +1349,7 @@ public class DBusConnection
* returned immediately.
* @return A reference to a remote object.
* @throws ClassCastException If type is not a sub-type of DBusInterface
- * @throws DBusException If busname or objectpath are incorrectly formatted.
+ * @throws DBusException If busname or objectpath are incorrectly formatted or type is not in a package.
*/
public DBusInterface getRemoteObject(String busname, String objectpath, Class<? extends DBusInterface> type, boolean autostart) throws DBusException
{
@@ -1361,6 +1365,11 @@ public class DBusConnection
throw new DBusException("Invalid object path ("+objectpath+")");
if (!DBusInterface.class.isAssignableFrom(type)) throw new ClassCastException("Not A DBus Interface");
+
+ // don't let people import things which don't have a
+ // valid D-Bus interface name
+ if (type.getName().equals(type.getSimpleName()))
+ throw new DBusException("DBusInterfaces cannot be declared outside a package");
RemoteObject ro = new RemoteObject(busname, objectpath, type, autostart);
DBusInterface i = (DBusInterface) Proxy.newProxyInstance(type.getClassLoader(),
@@ -1471,7 +1480,7 @@ public class DBusConnection
*/
public <T extends DBusSignal> void addSigHandler(Class<T> type, DBusSigHandler<T> handler) throws DBusException
{
- if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException("Not A DBus Signal");
+ if (!DBusSignal.class.isAssignableFrom(type)) throw new ClassCastException("Not A DBus Signal");
addSigHandler(new DBusMatchRule(type), handler);
}
/**
diff --git a/org/freedesktop/dbus/DBusMatchRule.java b/org/freedesktop/dbus/DBusMatchRule.java
index 1b9f06c..1b3c542 100644
--- a/org/freedesktop/dbus/DBusMatchRule.java
+++ b/org/freedesktop/dbus/DBusMatchRule.java
@@ -24,9 +24,9 @@ class DBusMatchRule
this.iface = iface;
this.member = member;
}
- public DBusMatchRule(DBusExecutionException e)
+ public DBusMatchRule(DBusExecutionException e) throws DBusException
{
- iface = DBusConnection.dollar_pattern.matcher(e.getClass().getName()).replaceAll(".");
+ this(e.getClass());
member = null;
type = "error";
}
@@ -45,9 +45,9 @@ class DBusMatchRule
else if (m instanceof MethodReply)
type = "method_reply";
}
- public DBusMatchRule(Class<? extends DBusInterface> c, String method)
+ public DBusMatchRule(Class<? extends DBusInterface> c, String method) throws DBusException
{
- iface = DBusConnection.dollar_pattern.matcher(c.getName()).replaceAll(".");
+ this(c);
member = method;
type = "method_call";
}
@@ -61,21 +61,30 @@ class DBusMatchRule
{
if (DBusInterface.class.isAssignableFrom(c)) {
iface = DBusConnection.dollar_pattern.matcher(c.getName()).replaceAll(".");
+ if (!iface.matches(".*\\..*"))
+ throw new DBusException("DBusInterfaces must be defined in a package.");
member = null;
type = null;
}
else if (DBusSignal.class.isAssignableFrom(c)) {
iface = DBusConnection.dollar_pattern.matcher(c.getEnclosingClass().getName()).replaceAll(".");
+ // Don't export things which are invalid D-Bus interfaces
+ if (!iface.matches(".*\\..*"))
+ throw new DBusException("DBusInterfaces must be defined in a package.");
member = c.getSimpleName();
type = "signal";
}
else if (DBusErrorMessage.class.isAssignableFrom(c)) {
iface = DBusConnection.dollar_pattern.matcher(c.getName()).replaceAll(".");
+ if (!iface.matches(".*\\..*"))
+ throw new DBusException("DBusInterfaces must be defined in a package.");
member = null;
type = "error";
}
else if (DBusExecutionException.class.isAssignableFrom(c)) {
iface = DBusConnection.dollar_pattern.matcher(c.getClass().getName()).replaceAll(".");
+ if (!iface.matches(".*\\..*"))
+ throw new DBusException("DBusInterfaces must be defined in a package.");
member = null;
type = "error";
}