diff options
-rw-r--r-- | CreateInterface.sh | 2 | ||||
-rw-r--r-- | DBusDaemon.sgml | 123 | ||||
-rw-r--r-- | DBusDaemon.sh | 7 | ||||
-rw-r--r-- | DBusViewer.sh | 2 | ||||
-rw-r--r-- | ListDBus.sh | 2 | ||||
-rw-r--r-- | Makefile | 29 | ||||
-rw-r--r-- | changelog | 1 | ||||
-rw-r--r-- | org/freedesktop/dbus/Message.java | 23 | ||||
-rw-r--r-- | org/freedesktop/dbus/bin/DBusDaemon.java | 269 | ||||
-rw-r--r-- | org/freedesktop/dbus/test/test_low_level.java | 4 |
10 files changed, 446 insertions, 16 deletions
diff --git a/CreateInterface.sh b/CreateInterface.sh index 54d3531..4fea83e 100644 --- a/CreateInterface.sh +++ b/CreateInterface.sh @@ -4,4 +4,4 @@ JARPATH=%JARPATH% JAVAUNIXLIBPATH=%DJAVAUNIXLIBPATH% JAVAUNIXJARPATH=%DJAVAUNIXJARPATH% -java -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JARPATH/dbus.jar org.freedesktop.dbus.CreateInterface "$@" +java -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-enable.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar org.freedesktop.dbus.bin.CreateInterface "$@" diff --git a/DBusDaemon.sgml b/DBusDaemon.sgml new file mode 100644 index 0000000..c2cdbde --- /dev/null +++ b/DBusDaemon.sgml @@ -0,0 +1,123 @@ +<!doctype refentry PUBLIC "-//OASIS//DTD DocBook V4.1//EN" [ + +<!-- Process this file with docbook-to-man to generate an nroff manual + page: `docbook-to-man manpage.sgml > manpage.1'. You may view + the manual page with: `docbook-to-man manpage.sgml | nroff -man | + less'. A typical entry in a Makefile or Makefile.am is: + +manpage.1: manpage.sgml + docbook-to-man $< > $@ + + + The docbook-to-man binary is found in the docbook-to-man package. + Please remember that if you create the nroff version in one of the + debian/rules file targets (such as build), you will need to include + docbook-to-man in your Build-Depends control field. + + --> + + <!-- Fill in your name for FIRSTNAME and SURNAME. --> + <!ENTITY dhfirstname "<firstname>Matthew</firstname>"> + <!ENTITY dhsurname "<surname>Johnson</surname>"> + <!-- Please adjust the date whenever revising the manpage. --> + <!ENTITY dhdate "<date>January 10, 2006</date>"> + <!-- SECTION should be 1-8, maybe w/ subsection other parameters are + allowed: see man(7), man(1). --> + <!ENTITY dhsection "<manvolnum>1</manvolnum>"> + <!ENTITY dhemail "<email><debian@matthew.ath.cx></email>"> + <!ENTITY dhusername "Matthew Johnson"> + <!ENTITY dhucpackage "<refentrytitle>DBUS-JAVA</refentrytitle>"> + <!ENTITY dhpackage "DBusDaemon"> + + <!ENTITY debian "<productname>Debian</productname>"> + <!ENTITY gnu "<acronym>GNU</acronym>"> + <!ENTITY gpl "&gnu; <acronym>GPL</acronym>"> +]> + +<refentry> + <refentryinfo> + <address> + &dhemail; + </address> + <author> + &dhfirstname; + &dhsurname; + </author> + <copyright> + <year>2006</year> + <holder>&dhusername;</holder> + </copyright> + &dhdate; + </refentryinfo> + <refmeta> + &dhucpackage; + + &dhsection; + </refmeta> + <refnamediv> + <refname>&dhpackage;</refname> + + <refpurpose>Runs a D-Bus Daemon</refpurpose> + </refnamediv> + <refsynopsisdiv> + <cmdsynopsis> + <command>&dhpackage;</command> + + </cmdsynopsis> + </refsynopsisdiv> + <refsect1> + <title>DESCRIPTION</title> + + <para>This manual page documents briefly the + <command>&dhpackage;</command> command.</para> + + <para><command>&dhpackage;</command> provides a D-Bus daemon for applications to communicate. + </para> + + + </refsect1> + <refsect1> + <title>OPTIONS</title> + + <para>These programs follow the usual &gnu; command line syntax, + with long options starting with two dashes (`-'). A summary of + options is included below. + </para> + + <variablelist> + </variablelist> + </refsect1> + <refsect1> + <title>AUTHOR</title> + + <para>This manual page was written by &dhusername; &dhemail;. Permission is + granted to copy, distribute and/or modify this document under + the terms of the &gnu; General Public License, Version 2 as + published by the Free Software Foundation. + </para> + <para> + On Debian systems, the complete text of the GNU General Public + License can be found in /usr/share/common-licenses/GPL. + </para> + + </refsect1> +</refentry> + +<!-- Keep this comment at the end of the file +Local variables: +mode: sgml +sgml-omittag:t +sgml-shorttag:t +sgml-minimize-attributes:nil +sgml-always-quote-attributes:t +sgml-indent-step:2 +sgml-indent-data:t +sgml-parent-document:nil +sgml-default-dtd-file:nil +sgml-exposed-tags:nil +sgml-local-catalogs:nil +sgml-local-ecat-files:nil +End: +--> + + diff --git a/DBusDaemon.sh b/DBusDaemon.sh new file mode 100644 index 0000000..d5b2633 --- /dev/null +++ b/DBusDaemon.sh @@ -0,0 +1,7 @@ +#!/bin/sh -- + +JARPATH=%JARPATH% +JAVAUNIXLIBPATH=%DJAVAUNIXLIBPATH% +JAVAUNIXJARPATH=%DJAVAUNIXJARPATH% + +java -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-enable.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar org.freedesktop.dbus.bin.DBusDaemon "$@" diff --git a/DBusViewer.sh b/DBusViewer.sh index 36a2d11..a03f719 100644 --- a/DBusViewer.sh +++ b/DBusViewer.sh @@ -4,4 +4,4 @@ JARPATH=%JARPATH% JAVAUNIXLIBPATH=%DJAVAUNIXLIBPATH% JAVAUNIXJARPATH=%DJAVAUNIXJARPATH% -java -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JARPATH/dbus.jar org.freedesktop.dbus.viewer.DBusViewer "$@" +java -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-enable.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar org.freedesktop.dbus.bin.viewer.DBusViewer "$@" diff --git a/ListDBus.sh b/ListDBus.sh index 048c0ac..91dd764 100644 --- a/ListDBus.sh +++ b/ListDBus.sh @@ -4,4 +4,4 @@ JARPATH=%JARPATH% JAVAUNIXLIBPATH=%DJAVAUNIXLIBPATH% JAVAUNIXJARPATH=%DJAVAUNIXJARPATH% -java -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JARPATH/dbus.jar org.freedesktop.dbus.ListDBus "$@" +java -Djava.library.path=$JAVAUNIXLIBPATH -cp $JAVAUNIXJARPATH/unix.jar:$JAVAUNIXJARPATH/debug-enable.jar:$JAVAUNIXJARPATH/hexdump.jar:$JARPATH/dbus.jar org.freedesktop.dbus.bin.ListDBus "$@" @@ -43,7 +43,7 @@ DEBUG=disable VERSION = 2.0 RELEASEVERSION = 2.0 -all: libdbus-java-$(VERSION).jar dbus-java-viewer-$(VERSION).jar bin/ListDBus bin/CreateInterface bin/DBusViewer +all: libdbus-java-$(VERSION).jar dbus-java-viewer-$(VERSION).jar bin/DBusDaemon bin/ListDBus bin/CreateInterface bin/DBusViewer clean: rm -rf doc bin classes @@ -105,6 +105,9 @@ doc/api/index.html: $(SRCDIR)/*.java $(SRCDIR)/dbus/*.java .doc bin/%: %.sh .bin sed 's,\%JARPATH\%,$(JARPREFIX),;s,\%JAVAUNIXJARPATH\%,$(JAVAUNIXJARDIR),;s,\%JAVAUNIXLIBPATH\%,$(JAVAUNIXLIBDIR),' < $< > $@ +rundaemon: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar + $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.bin.DBusDaemon + testrun: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-test-$(VERSION).jar org.freedesktop.dbus.test.test @@ -135,13 +138,13 @@ profilerun: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar viewer: libdbus-java-$(VERSION).jar dbus-java-viewer-$(VERSION).jar $(JAVA) $(JFLAGS) $(CPFLAG) $(CLASSPATH):$(JAVAUNIXJARDIR)/unix.jar:$(JAVAUNIXJARDIR)/hexdump.jar:$(JAVAUNIXJARDIR)/debug-$(DEBUG).jar:libdbus-java-$(VERSION).jar:dbus-java-viewer-$(VERSION).jar org.freedesktop.dbus.viewer.DBusViewer +#dbus-daemon --config-file=tmp-session.conf --print-pid --print-address=5 --fork >pid 5>address ; \ + low-level: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar - ( PASS=false; \ - dbus-daemon --config-file=tmp-session.conf --print-pid --print-address=5 --fork >pid 5>address ; \ + ( $(MAKE) -s rundaemon >address & \ + sleep 1; \ export DBUS_SESSION_BUS_ADDRESS=$$(cat address) ;\ - $(MAKE) low-level-run ; \ - kill $$(cat pid) ) - + $(MAKE) low-level-run ) check: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar ( PASS=false; \ @@ -186,12 +189,12 @@ profile: libdbus-java-$(VERSION).jar dbus-java-test-$(VERSION).jar uninstall: rm -f $(DESTDIR)$(JARPREFIX)/dbus.jar $(DESTDIR)$(JARPREFIX)/dbus-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-viewer.jar $(DESTDIR)$(JARPREFIX)/dbus-viewer-$(VERSION).jar rm -rf $(DESTDIR)$(DOCPREFIX) - rm -f $(DESTDIR)$(MANPREFIX)/CreateInterface.1 $(DESTDIR)$(MANPREFIX)/ListDBus.1 $(DESTDIR)$(MANPREFIX)/DBusViewer.1 - rm -f $(DESTDIR)$(BINPREFIX)/CreateInterface $(DESTDIR)$(BINPREFIX)/ListDBus $(DESTDIR)$(BINPREFIX)/DBusViewer + rm -f $(DESTDIR)$(MANPREFIX)/CreateInterface.1 $(DESTDIR)$(MANPREFIX)/ListDBus.1 $(DESTDIR)$(MANPREFIX)/DBusViewer.1 $(DESTDIR)$(MANPREFIX)/DBusDaemon.1 + rm -f $(DESTDIR)$(BINPREFIX)/CreateInterface $(DESTDIR)$(BINPREFIX)/ListDBus $(DESTDIR)$(BINPREFIX)/DBusViewer $(DESTDIR)$(BINPREFIX)/DBusDaemon install: install-bin install-man -install-bin: dbus-java-viewer-$(VERSION).jar libdbus-java-$(VERSION).jar bin/CreateInterface bin/ListDBus bin/DBusViewer +install-bin: dbus-java-viewer-$(VERSION).jar libdbus-java-$(VERSION).jar bin/CreateInterface bin/ListDBus bin/DBusViewer bin/DBusDaemon install -d $(DESTDIR)$(JARPREFIX) install -m 644 libdbus-java-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-$(VERSION).jar install -m 644 dbus-java-viewer-$(VERSION).jar $(DESTDIR)$(JARPREFIX)/dbus-viewer-$(VERSION).jar @@ -201,8 +204,9 @@ install-bin: dbus-java-viewer-$(VERSION).jar libdbus-java-$(VERSION).jar bin/Cre install bin/DBusViewer $(DESTDIR)$(BINPREFIX) install bin/CreateInterface $(DESTDIR)$(BINPREFIX) install bin/ListDBus $(DESTDIR)$(BINPREFIX) + install bin/DBusDaemon $(DESTDIR)$(BINPREFIX) -install-man: CreateInterface.1 ListDBus.1 DBusViewer.1 changelog AUTHORS COPYING README INSTALL +install-man: CreateInterface.1 ListDBus.1 DBusDaemon.1 DBusViewer.1 changelog AUTHORS COPYING README INSTALL install -d $(DESTDIR)$(DOCPREFIX) install -m 644 changelog $(DESTDIR)$(DOCPREFIX) install -m 644 COPYING $(DESTDIR)$(DOCPREFIX) @@ -212,6 +216,7 @@ install-man: CreateInterface.1 ListDBus.1 DBusViewer.1 changelog AUTHORS COPYING install -d $(DESTDIR)$(MANPREFIX) install -m 644 CreateInterface.1 $(DESTDIR)$(MANPREFIX)/CreateInterface.1 install -m 644 ListDBus.1 $(DESTDIR)$(MANPREFIX)/ListDBus.1 + install -m 644 DBusDaemon.1 $(DESTDIR)$(MANPREFIX)/DBusDaemon.1 install -m 644 DBusViewer.1 $(DESTDIR)$(MANPREFIX)/DBusViewer.1 install-doc: doc @@ -226,7 +231,7 @@ install-doc: doc cp -a doc/api/* $(DESTDIR)$(DOCPREFIX)/api dist: .dist -.dist: 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 +.dist: dbus-java.tex Makefile org tmp-session.conf CreateInterface.sgml DBusDaemon.sgml ListDBus.sgml DBusViewer.sgml changelog AUTHORS COPYING README INSTALL CreateInterface.sh DBusDaemon.sh ListDBus.sh DBusViewer.sh mkdir -p libdbus-java-$(VERSION) cp -fa $^ libdbus-java-$(VERSION) touch .dist @@ -242,7 +247,7 @@ libdbus-java-$(VERSION): .dist libdbus-java-$(VERSION).tar.gz: .dist tar zcf $@ libdbus-java-$(VERSION) -libdbus-java-$(RELEASEVERSION).tar.gz: 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 +libdbus-java-$(RELEASEVERSION).tar.gz: dbus-java.tex Makefile org tmp-session.conf CreateInterface.sgml DBusDaemon.sgml ListDBus.sgml DBusViewer.sgml changelog AUTHORS COPYING README INSTALL CreateInterface.sh ListDBus.sh DBusViewer.sh DBusDaemon.sh mkdir -p libdbus-java-$(RELEASEVERSION)/ cp -fa $^ libdbus-java-$(RELEASEVERSION)/ tar zcf $@ libdbus-java-$(RELEASEVERSION) @@ -25,6 +25,7 @@ Version 2.0: * add DBus.Peer interface to standard introspection data * Document peer to peer and low level. * Fix TCP and SHA-1 auth + * fix wrapper scripts with new depends Version 1.13: diff --git a/org/freedesktop/dbus/Message.java b/org/freedesktop/dbus/Message.java index c21f54c..3ffe80e 100644 --- a/org/freedesktop/dbus/Message.java +++ b/org/freedesktop/dbus/Message.java @@ -138,6 +138,7 @@ public class Message protected byte protover; private Object[] args; private byte[] body; + private long bodylen = 0; private int preallocated = 0; private int paofs = 0; private byte[] pabuf; @@ -207,6 +208,7 @@ public class Message wiredata[2] = body; this.body = body; bufferuse = 3; + bodylen = ((Number) extract(Message.ArgumentType.UINT32_STRING, msg, 4)[0]).longValue(); serial = ((Number) extract(Message.ArgumentType.UINT32_STRING, msg, 8)[0]).longValue(); bytecounter = msg.length+headers.length+body.length; if (Debug.debug) Debug.print(Debug.VERBOSE, headers); @@ -1073,4 +1075,25 @@ public class Message return args; } protected void setArgs(Object[] args) { this.args = args; } + /** + * Warning, do not use this method unless you really know what you are doing. + */ + public void setSource(String source) throws DBusException + { + if (null != body) { + wiredata = new byte[BUFFERINCREMENT][]; + preallocate(12); + append("yyyyuu", big, type, flags, protover, bodylen, serial); + headers.put(HeaderField.SENDER, source); + Object[][] newhead = new Object[headers.size()][]; + int i = 0; + for (Byte b: headers.keySet()) { + newhead[i] = new Object[2]; + newhead[i][0] = b; + newhead[i][1] = headers.get(b); + } + append("a(yv)", (Object) newhead); + appendBytes(body); + } + } } diff --git a/org/freedesktop/dbus/bin/DBusDaemon.java b/org/freedesktop/dbus/bin/DBusDaemon.java new file mode 100644 index 0000000..36d1d5d --- /dev/null +++ b/org/freedesktop/dbus/bin/DBusDaemon.java @@ -0,0 +1,269 @@ +/* + D-Bus Java Implementation + Copyright (c) 2005-2006 Matthew Johnson + + This program is free software; you can redistribute it and/or modify it + under the terms of either the GNU General Public License Version 2 or the + Academic Free Licence Version 2.1. + + Full licence texts are included in the COPYING file with this program. +*/ +package org.freedesktop.dbus.bin; + +import org.freedesktop.DBus; +import org.freedesktop.dbus.AbstractConnection; +import org.freedesktop.dbus.BusAddress; +import org.freedesktop.dbus.DBusSignal; +import org.freedesktop.dbus.DirectConnection; +import org.freedesktop.dbus.Error; +import org.freedesktop.dbus.Message; +import org.freedesktop.dbus.MessageReader; +import org.freedesktop.dbus.MessageWriter; +import org.freedesktop.dbus.MethodCall; +import org.freedesktop.dbus.MethodReturn; +import org.freedesktop.dbus.Transport; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.Vector; + +import cx.ath.matthew.debug.Debug; +import cx.ath.matthew.unix.UnixServerSocket; +import cx.ath.matthew.unix.UnixSocket; +import cx.ath.matthew.unix.UnixSocketAddress; + +/** + * A replacement DBusDaemon + */ +public class DBusDaemon extends Thread +{ + static class Connstruct + { + public UnixSocket sock; + public MessageReader min; + public MessageWriter mout; + public String unique; + public Connstruct(UnixSocket sock) + { + this.sock = sock; + min = new MessageReader(sock.getInputStream()); + mout = new MessageWriter(sock.getOutputStream()); + } + } + private Vector<Connstruct> conns = new Vector<Connstruct>(); + private HashMap<String, Connstruct> names = new HashMap<String, Connstruct>(); + private HashMap<Connstruct, Queue<Message>> queues = new HashMap<Connstruct, Queue<Message>>(); + private boolean _run = true; + private int next_unique = 0; + private Object unique_lock = new Object(); + public DBusDaemon() + { + } + private void send(Connstruct c, Message m) + { + // send to all connections + if (null == c) { + Map<Connstruct, Queue<Message>> local; + synchronized (queues) { + local = (Map<Connstruct, Queue<Message>>) queues.clone(); + } + for (Queue<Message> q: local.values()) { + synchronized (q) { + q.offer(m); + } + } + } else { + Queue<Message> q; + synchronized (queues) { + q = queues.get(c); + } + synchronized (q) { + q.offer(m); + } + } + } + private void serverHandleMessage(Connstruct c, Message m) throws DBusException + { + if (!(m instanceof MethodCall)) return; + if ("Hello".equals(m.getName())) { + synchronized (c) { + if (null != c.unique) { + send(c, new Error(c.unique, "org.freedesktop.DBus.Error.AccessDenied", m.getSerial(), "s", "Connection has already sent a Hello message")); + return; + } + + synchronized (unique_lock) { + c.unique = ":1."+(++next_unique); + } + } + synchronized (names) { + names.put(c.unique, c); + } + send(c, new MethodReturn((MethodCall) m, "s", c.unique)); + send(c, new DBus.NameAcquired("/org/freedesktop/DBus", c.unique)); + send(null, new DBus.NameOwnerChanged("/org/freedesktop/DBus", c.unique, "", c.unique)); + } + else if ("ListNames".equals(m.getName())) { + String[] ns; + synchronized (names) { + ns = names.keySet().toArray(new String[0]); + } + send(c, new MethodReturn((MethodCall) m, "as", (Object) ns)); + } + else if ("RequestName".equals(m.getName())) { + Object[] args = m.getParameters(); + if (null == args || args.length < 2 || !(args[0] instanceof String)) { + send(c,new Error(c.unique, "org.freedesktop.DBus.Error.GeneralError", m.getSerial(), "s", "RequestName arguments invalid")); + return; + } + boolean exists = false; + synchronized (names) { + if (!(exists = names.keySet().contains((String) args[0]))) + names.put((String) args[0], c); + } + if (exists) { + send(c, new MethodReturn((MethodCall) m, "u", DBus.DBUS_REQUEST_NAME_REPLY_EXISTS)); + return; + } + send(c, new MethodReturn((MethodCall) m, "s", DBus.DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER)); + send(c, new DBus.NameAcquired("/org/freedesktop/DBus", (String) args[0])); + send(null, new DBus.NameOwnerChanged("/org/freedesktop/DBus", (String) args[0], "", c.unique)); + } + + // send an error + else { + send(c,new Error(c.unique, "org.freedesktop.DBus.Error.UnknownMethod", m.getSerial(), "s", "This service does not support the "+m.getName()+" Method")); + } + } + private List<Connstruct> findSignalMatches(DBusSignal sig) + { + } + public void run() + { + while (_run) { + List<Connstruct> local; + synchronized (conns) { + local = (List<Connstruct>) conns.clone(); + } + for (Connstruct c: local) try { + Message m = c.min.readMessage(); + + // check if we have a message + if (null != m) { + + // check if they have hello'd + if (null == c.unique + && (!(m instanceof MethodCall) + || !"org.freedesktop.DBus".equals(m.getDestination()) + || !"Hello".equals(m.getName()))) { + send(c,new Error(null, "org.freedesktop.DBus.Error.AccessDenied", m.getSerial(), "s", "You must send a Hello message")); + } else { + + try { + m.setSource(c.unique); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + send(c,new Error(null, "org.freedesktop.DBus.Error.GeneralError", m.getSerial(), "s", "Sending message failed")); + } + + if ("org.freedesktop.DBus".equals(m.getDestination())) { + serverHandleMessage(c, m); + } + + if (m instanceof DBusSignal) { + List<Connstruct> list = findSignalMatches((DBusSignal) m); + for (Connstruct d: list) + send(d, m); + } else { + Connstruct dest = names.get(m.getDestination()); + + if (null == dest) { + send(c, new Error(null, "org.freedesktop.DBus.Error.ServiceUnknown", m.getSerial(), "s", "The name `"+m.getDestination()+"'does not exist")); + } else + send(dest, m); + } + } + } + Queue<Message> q; + synchronized (queues) { + q = queues.get(c); + } + synchronized (q) { + while (q.size() > 0) { + Message tosend = q.poll(); + c.mout.writeMessage(tosend); + } + } + } + catch (IOException IOe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, IOe); + removeConnection(c); + } + catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + } + } + private void removeConnection(Connstruct c) + { + c.sock.close(); + synchronized(conns) { + conns.remove(c); + } + synchronized (queues) { + queues.remove(c); + } + synchronized(names) { + for (String name: names.keySet()) + if (names.get(name) == c) { + names.remove(name); + try { + send(null, new DBus.NameOwnerChanged("/org/freedesktop/DBus", name, c.unique, "")); + } catch (DBusException DBe) { + if (Debug.debug && AbstractConnection.EXCEPTION_DEBUG) Debug.print(Debug.ERR, DBe); + } + } + } + } + public void addSock(UnixSocket us) + { + Connstruct c = new Connstruct(us); + synchronized (conns) { + conns.add(c); + } + synchronized (queues) { + queues.put(c, new LinkedList<Message>()); + } + } + public static void syntax() + { + System.out.println("Syntax: DBusDaemon [--help] [-h]"); + System.exit(1); + } + public static void main(String args[]) throws Exception + { + boolean owners = false; + boolean users = false; + + for (String a: args) + if ("--help".equals(a)) syntax(); + else if ("-h".equals(a)) syntax(); + else syntax(); + + String addr = DirectConnection.createDynamicSession(); + BusAddress address = new BusAddress(addr); + UnixServerSocket uss = new UnixServerSocket(new UnixSocketAddress(address.getParameter("abstract"), true)); + DBusDaemon d = new DBusDaemon(); + d.start(); + while (true) { + UnixSocket s = uss.accept(); + if ((new Transport.SASL()).auth(Transport.SASL.MODE_SERVER, Transport.SASL.AUTH_EXTERNAL, address.getParameter("guid"), s.getOutputStream(), s.getInputStream())) + d.addSock(s); + else + s.close(); + } + } +} diff --git a/org/freedesktop/dbus/test/test_low_level.java b/org/freedesktop/dbus/test/test_low_level.java index f1b1123..47b1301 100644 --- a/org/freedesktop/dbus/test/test_low_level.java +++ b/org/freedesktop/dbus/test/test_low_level.java @@ -12,7 +12,9 @@ public class test_low_level public static void main(String[] args) throws Exception { Debug.setHexDump(true); - BusAddress address = new BusAddress(System.getenv("DBUS_SESSION_BUS_ADDRESS")); + String addr = System.getenv("DBUS_SESSION_BUS_ADDRESS"); + Debug.print(addr); + BusAddress address = new BusAddress(addr); Debug.print(address); Transport conn = new Transport(address); |