#13795: Initial commit for sflphone-android

includes: libexpat libyaml libdbus-c++ commoncpp ccrtp
          libdbus (from android-4.0.4 sources)

TODO:
- git ignores "/jni/sflphone", sflphone repo should be cloned.
- sflphone-android only needs daemon directory. Ideally it should be possible
to clone it without cloning the whole sflphone project.
into sfl-android (commit 6a0fa7a "#13961: Fix cipher handling" has been used here)
- add pjsip-android project as a git submodule
- sflphone-android needs pjsip android project. Ideally daemon git repository
should not embed pjsip. Instead pjsip should be clone from official repositories.

Considering this, structure should have three distincts git repos:

sflphone-android/.git
sflphone-android/jni/ccrtp-1.8.0-android
sflphone-android/jni/commoncpp2-1.8.1-android
sflphone-android/jni/dbus
sflphone-android/jni/libdbus-c++-0.9.0-android
sflphone-android/jni/libexpat
sflphone-android/jni/libyaml

sflphone-android/jni/sflphone-daemon/.git
sflphone-android/jni/sflphone-daemon/src/audio
sflphone-android/jni/sflphone-daemon/src/config
sflphone-android/jni/sflphone-daemon/src/dbus
sflphone-android/jni/sflphone-daemon/src/history
sflphone-android/jni/sflphone-daemon/src/hooks
sflphone-android/jni/sflphone-daemon/src/iax
sflphone-android/jni/sflphone-daemon/src/sip
sflphone-android/jni/sflphone-daemon/src/video

sflphone-android/jni/pjsip-android/.git

Signed-off-by: Emeric Vigier <emeric.vigier@savoirfairelinux.com>
diff --git a/jni/dbus/tools/.gitignore b/jni/dbus/tools/.gitignore
new file mode 100644
index 0000000..234cef9
--- /dev/null
+++ b/jni/dbus/tools/.gitignore
@@ -0,0 +1,20 @@
+.deps
+.libs
+Makefile
+Makefile.in
+*.lo
+*.la
+dbus-send
+dbus-monitor
+dbus-cleanup-sockets
+dbus-launch
+dbus-uuidgen
+*.bb
+*.bbg
+*.gcov
+*.da
+dbus-viewer
+dbus-glib-bindings.h
+run-with-tmp-session-bus.conf
+print-introspect
+dbus-bus-introspect.xml
diff --git a/jni/dbus/tools/Android.mk b/jni/dbus/tools/Android.mk
new file mode 100644
index 0000000..2527f3e
--- /dev/null
+++ b/jni/dbus/tools/Android.mk
@@ -0,0 +1,51 @@
+LOCAL_PATH := $(call my-dir)
+
+# common
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := dbus-print-message.c
+LOCAL_C_INCLUDES += $(call include-path-for, dbus) \
+                    $(LOCAL_PATH)/..
+LOCAL_SHARED_LIBRARIES += libdbus
+LOCAL_CFLAGS += \
+	-DDBUS_COMPILATION \
+	-DDBUS_MACHINE_UUID_FILE=\"/etc/machine-id\"
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE := libdbus-tools-common
+include $(BUILD_SHARED_LIBRARY)
+
+# dbus-monitor
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := dbus-monitor.c
+LOCAL_C_INCLUDES += $(call include-path-for, dbus) \
+                    $(LOCAL_PATH)/..
+LOCAL_SHARED_LIBRARIES += libdbus
+LOCAL_STATIC_LIBRARIES += libdbus-tools-common
+LOCAL_CFLAGS += \
+	-DDBUS_COMPILATION \
+	-DDBUS_MACHINE_UUID_FILE=\"/etc/machine-id\"
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE := dbus-monitor
+include $(BUILD_EXECUTABLE)
+
+# dbus-send
+
+include $(CLEAR_VARS)
+
+LOCAL_SRC_FILES := dbus-send.c
+LOCAL_C_INCLUDES += $(call include-path-for, dbus) \
+                    $(LOCAL_PATH)/..
+LOCAL_SHARED_LIBRARIES += libdbus
+LOCAL_STATIC_LIBRARIES += libdbus-tools-common
+LOCAL_CFLAGS += \
+	-DDBUS_COMPILATION \
+	-DDBUS_MACHINE_UUID_FILE=\"/etc/machine-id\"
+LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
+LOCAL_MODULE_TAGS := eng
+LOCAL_MODULE := dbus-send
+include $(BUILD_EXECUTABLE)
diff --git a/jni/dbus/tools/Makefile.am b/jni/dbus/tools/Makefile.am
new file mode 100644
index 0000000..271c150
--- /dev/null
+++ b/jni/dbus/tools/Makefile.am
@@ -0,0 +1,58 @@
+configdir=$(sysconfdir)/dbus-1
+
+INCLUDES=-I$(top_srcdir) $(DBUS_CLIENT_CFLAGS) $(DBUS_X_CFLAGS) -DDBUS_LOCALEDIR=\"@EXPANDED_DATADIR@/locale\" -DDBUS_COMPILATION -DDBUS_MACHINE_UUID_FILE=\""$(localstatedir)/lib/dbus/machine-id"\"
+
+extra_bin_programs=
+if DBUS_UNIX
+extra_bin_programs += dbus-cleanup-sockets dbus-uuidgen
+endif
+
+bin_PROGRAMS=dbus-launch dbus-send dbus-monitor $(extra_bin_programs)
+
+dbus_send_SOURCES=				\
+	dbus-print-message.c			\
+	dbus-print-message.h			\
+	dbus-send.c
+
+dbus_monitor_SOURCES=				\
+	dbus-monitor.c				\
+	dbus-print-message.c			\
+	dbus-print-message.h
+
+if DBUS_WIN
+dbus_launch_SOURCES=				\
+	dbus-launch-win.c			\
+	dbus-launch.h
+else
+dbus_launch_SOURCES=				\
+	dbus-launch.c				\
+	dbus-launch-x11.c			\
+	dbus-launch.h
+endif
+
+dbus_cleanup_sockets_SOURCES=			\
+	dbus-cleanup-sockets.c
+
+dbus_uuidgen_SOURCES=				\
+	dbus-uuidgen.c
+
+dbus_send_LDADD= $(top_builddir)/dbus/libdbus-1.la $(DBUS_CLIENT_LIBS)
+dbus_send_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+dbus_monitor_LDADD= $(top_builddir)/dbus/libdbus-1.la $(DBUS_CLIENT_LIBS)
+dbus_monitor_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+dbus_uuidgen_LDADD= $(top_builddir)/dbus/libdbus-1.la $(DBUS_CLIENT_LIBS)
+dbus_uuidgen_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+dbus_launch_LDADD= $(DBUS_X_LIBS) $(DBUS_CLIENT_LIBS)
+dbus_launch_LDFLAGS=@R_DYNAMIC_LDFLAG@
+
+man_MANS = dbus-send.1 dbus-monitor.1 dbus-launch.1 dbus-cleanup-sockets.1 dbus-uuidgen.1
+EXTRA_DIST = $(man_MANS) run-with-tmp-session-bus.sh strtoll.c strtoull.c
+CLEANFILES = 				\
+	run-with-tmp-session-bus.conf
+
+#create the /var/lib/data directory for dbus-uuidgen
+localstatelibdir = $(localstatedir)/lib/dbus
+localstatelib_DATA =
diff --git a/jni/dbus/tools/NOTICE b/jni/dbus/tools/NOTICE
new file mode 100644
index 0000000..a91ca1d
--- /dev/null
+++ b/jni/dbus/tools/NOTICE
@@ -0,0 +1,551 @@
+D-Bus is licensed to you under your choice of the Academic Free
+License version 2.1, or the GNU General Public License version 2.
+Both licenses are included here. Some of the standalone binaries are
+under the GPL only; in particular, but not limited to,
+tools/dbus-cleanup-sockets.c and test/decode-gcov.c. Each source code
+file is marked with the proper copyright information - if you find a
+file that isn't marked please bring it to our attention.
+
+
+The Academic Free License
+v. 2.1
+
+This Academic Free License (the "License") applies to any original work of authorship (the "Original Work") whose owner (the "Licensor") has placed the following notice immediately following the copyright notice for the Original Work:
+
+Licensed under the Academic Free License version 2.1
+
+1) Grant of Copyright License. Licensor hereby grants You a
+world-wide, royalty-free, non-exclusive, perpetual, sublicenseable
+license to do the following:
+
+a) to reproduce the Original Work in copies;
+
+b) to prepare derivative works ("Derivative Works") based upon the Original Work;
+
+c) to distribute copies of the Original Work and Derivative Works to the public;
+
+d) to perform the Original Work publicly; and
+
+e) to display the Original Work publicly.
+
+2) Grant of Patent License. Licensor hereby grants You a world-wide,
+royalty-free, non-exclusive, perpetual, sublicenseable license, under
+patent claims owned or controlled by the Licensor that are embodied in
+the Original Work as furnished by the Licensor, to make, use, sell and
+offer for sale the Original Work and Derivative Works.
+
+3) Grant of Source Code License. The term "Source Code" means the
+preferred form of the Original Work for making modifications to it and
+all available documentation describing how to modify the Original
+Work. Licensor hereby agrees to provide a machine-readable copy of the
+Source Code of the Original Work along with each copy of the Original
+Work that Licensor distributes. Licensor reserves the right to satisfy
+this obligation by placing a machine-readable copy of the Source Code
+in an information repository reasonably calculated to permit
+inexpensive and convenient access by You for as long as Licensor
+continues to distribute the Original Work, and by publishing the
+address of that information repository in a notice immediately
+following the copyright notice that applies to the Original Work.
+
+4) Exclusions From License Grant. Neither the names of Licensor, nor
+the names of any contributors to the Original Work, nor any of their
+trademarks or service marks, may be used to endorse or promote
+products derived from this Original Work without express prior written
+permission of the Licensor. Nothing in this License shall be deemed to
+grant any rights to trademarks, copyrights, patents, trade secrets or
+any other intellectual property of Licensor except as expressly stated
+herein. No patent license is granted to make, use, sell or offer to
+sell embodiments of any patent claims other than the licensed claims
+defined in Section 2. No right is granted to the trademarks of
+Licensor even if such marks are included in the Original Work. Nothing
+in this License shall be interpreted to prohibit Licensor from
+licensing under different terms from this License any Original Work
+that Licensor otherwise would have a right to license.
+
+5) This section intentionally omitted.
+
+6) Attribution Rights. You must retain, in the Source Code of any
+Derivative Works that You create, all copyright, patent or trademark
+notices from the Source Code of the Original Work, as well as any
+notices of licensing and any descriptive text identified therein as an
+"Attribution Notice." You must cause the Source Code for any
+Derivative Works that You create to carry a prominent Attribution
+Notice reasonably calculated to inform recipients that You have
+modified the Original Work.
+
+7) Warranty of Provenance and Disclaimer of Warranty. Licensor
+warrants that the copyright in and to the Original Work and the patent
+rights granted herein by Licensor are owned by the Licensor or are
+sublicensed to You under the terms of this License with the permission
+of the contributor(s) of those copyrights and patent rights. Except as
+expressly stated in the immediately proceeding sentence, the Original
+Work is provided under this License on an "AS IS" BASIS and WITHOUT
+WARRANTY, either express or implied, including, without limitation,
+the warranties of NON-INFRINGEMENT, MERCHANTABILITY or FITNESS FOR A
+PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY OF THE ORIGINAL
+WORK IS WITH YOU. This DISCLAIMER OF WARRANTY constitutes an essential
+part of this License. No license to Original Work is granted hereunder
+except under this disclaimer.
+
+8) Limitation of Liability. Under no circumstances and under no legal
+theory, whether in tort (including negligence), contract, or
+otherwise, shall the Licensor be liable to any person for any direct,
+indirect, special, incidental, or consequential damages of any
+character arising as a result of this License or the use of the
+Original Work including, without limitation, damages for loss of
+goodwill, work stoppage, computer failure or malfunction, or any and
+all other commercial damages or losses. This limitation of liability
+shall not apply to liability for death or personal injury resulting
+from Licensor's negligence to the extent applicable law prohibits such
+limitation. Some jurisdictions do not allow the exclusion or
+limitation of incidental or consequential damages, so this exclusion
+and limitation may not apply to You.
+
+9) Acceptance and Termination. If You distribute copies of the
+Original Work or a Derivative Work, You must make a reasonable effort
+under the circumstances to obtain the express assent of recipients to
+the terms of this License. Nothing else but this License (or another
+written agreement between Licensor and You) grants You permission to
+create Derivative Works based upon the Original Work or to exercise
+any of the rights granted in Section 1 herein, and any attempt to do
+so except under the terms of this License (or another written
+agreement between Licensor and You) is expressly prohibited by
+U.S. copyright law, the equivalent laws of other countries, and by
+international treaty. Therefore, by exercising any of the rights
+granted to You in Section 1 herein, You indicate Your acceptance of
+this License and all of its terms and conditions.
+
+10) Termination for Patent Action. This License shall terminate
+automatically and You may no longer exercise any of the rights granted
+to You by this License as of the date You commence an action,
+including a cross-claim or counterclaim, against Licensor or any
+licensee alleging that the Original Work infringes a patent. This
+termination provision shall not apply for an action alleging patent
+infringement by combinations of the Original Work with other software
+or hardware.
+
+11) Jurisdiction, Venue and Governing Law. Any action or suit relating
+to this License may be brought only in the courts of a jurisdiction
+wherein the Licensor resides or in which Licensor conducts its primary
+business, and under the laws of that jurisdiction excluding its
+conflict-of-law provisions. The application of the United Nations
+Convention on Contracts for the International Sale of Goods is
+expressly excluded. Any use of the Original Work outside the scope of
+this License or after its termination shall be subject to the
+requirements and penalties of the U.S. Copyright Act, 17 U.S.C. § 101
+et seq., the equivalent laws of other countries, and international
+treaty. This section shall survive the termination of this License.
+
+12) Attorneys Fees. In any action to enforce the terms of this License
+or seeking damages relating thereto, the prevailing party shall be
+entitled to recover its costs and expenses, including, without
+limitation, reasonable attorneys' fees and costs incurred in
+connection with such action, including any appeal of such action. This
+section shall survive the termination of this License.
+
+13) Miscellaneous. This License represents the complete agreement
+concerning the subject matter hereof. If any provision of this License
+is held to be unenforceable, such provision shall be reformed only to
+the extent necessary to make it enforceable.
+
+14) Definition of "You" in This License. "You" throughout this
+License, whether in upper or lower case, means an individual or a
+legal entity exercising rights under, and complying with all of the
+terms of, this License. For legal entities, "You" includes any entity
+that controls, is controlled by, or is under common control with
+you. For purposes of this definition, "control" means (i) the power,
+direct or indirect, to cause the direction or management of such
+entity, whether by contract or otherwise, or (ii) ownership of fifty
+percent (50%) or more of the outstanding shares, or (iii) beneficial
+ownership of such entity.
+
+15) Right to Use. You may use the Original Work in all ways not
+otherwise restricted or conditioned by this License or by law, and
+Licensor promises not to interfere with or be responsible for such
+uses by You.
+
+This license is Copyright (C) 2003-2004 Lawrence E. Rosen. All rights
+reserved. Permission is hereby granted to copy and distribute this
+license without modification. This license may not be modified without
+the express written permission of its copyright owner.
+
+
+-- 
+END OF ACADEMIC FREE LICENSE. The following is intended to describe the essential 
+differences between the Academic Free License (AFL) version 1.0 and other 
+open source licenses:
+
+The Academic Free License is similar to the BSD, MIT, UoI/NCSA and Apache 
+licenses in many respects but it is intended to solve a few problems with 
+those licenses.
+    
+* The AFL is written so as to make it clear what software is being 
+licensed (by the inclusion of a statement following the copyright notice 
+in the software). This way, the license functions better than a template 
+license. The BSD, MIT and UoI/NCSA licenses apply to unidentified software.
+    
+* The AFL contains a complete copyright grant to the software. The BSD 
+and Apache licenses are vague and incomplete in that respect.
+    
+* The AFL contains a complete patent grant to the software. The BSD, MIT, 
+UoI/NCSA and Apache licenses rely on an implied patent license and contain 
+no explicit patent grant.
+    
+* The AFL makes it clear that no trademark rights are granted to the 
+licensor's trademarks. The Apache license contains such a provision, but the 
+BSD, MIT and UoI/NCSA licenses do not.
+    
+* The AFL includes the warranty by the licensor that it either owns the 
+copyright or that it is distributing the software under a license. None of 
+the other licenses contain that warranty. All other warranties are disclaimed, 
+as is the case for the other licenses.
+
+* The AFL is itself copyrighted (with the right granted to copy and distribute 
+without modification). This ensures that the owner of the copyright to the 
+license will control changes. The Apache license contains a copyright notice, 
+but the BSD, MIT and UoI/NCSA licenses do not. 
+--
+START OF GNU GENERAL PUBLIC LICENSE
+--
+
+		    GNU GENERAL PUBLIC LICENSE
+		       Version 2, June 1991
+
+ Copyright (C) 1989, 1991 Free Software Foundation, Inc.
+ 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+			    Preamble
+
+  The licenses for most software are designed to take away your
+freedom to share and change it.  By contrast, the GNU General Public
+License is intended to guarantee your freedom to share and change free
+software--to make sure the software is free for all its users.  This
+General Public License applies to most of the Free Software
+Foundation's software and to any other program whose authors commit to
+using it.  (Some other Free Software Foundation software is covered by
+the GNU Library General Public License instead.)  You can apply it to
+your programs, too.
+
+  When we speak of free software, we are referring to freedom, not
+price.  Our General Public Licenses are designed to make sure that you
+have the freedom to distribute copies of free software (and charge for
+this service if you wish), that you receive source code or can get it
+if you want it, that you can change the software or use pieces of it
+in new free programs; and that you know you can do these things.
+
+  To protect your rights, we need to make restrictions that forbid
+anyone to deny you these rights or to ask you to surrender the rights.
+These restrictions translate to certain responsibilities for you if you
+distribute copies of the software, or if you modify it.
+
+  For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must give the recipients all the rights that
+you have.  You must make sure that they, too, receive or can get the
+source code.  And you must show them these terms so they know their
+rights.
+
+  We protect your rights with two steps: (1) copyright the software, and
+(2) offer you this license which gives you legal permission to copy,
+distribute and/or modify the software.
+
+  Also, for each author's protection and ours, we want to make certain
+that everyone understands that there is no warranty for this free
+software.  If the software is modified by someone else and passed on, we
+want its recipients to know that what they have is not the original, so
+that any problems introduced by others will not reflect on the original
+authors' reputations.
+
+  Finally, any free program is threatened constantly by software
+patents.  We wish to avoid the danger that redistributors of a free
+program will individually obtain patent licenses, in effect making the
+program proprietary.  To prevent this, we have made it clear that any
+patent must be licensed for everyone's free use or not licensed at all.
+
+  The precise terms and conditions for copying, distribution and
+modification follow.
+
+		    GNU GENERAL PUBLIC LICENSE
+   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
+
+  0. This License applies to any program or other work which contains
+a notice placed by the copyright holder saying it may be distributed
+under the terms of this General Public License.  The "Program", below,
+refers to any such program or work, and a "work based on the Program"
+means either the Program or any derivative work under copyright law:
+that is to say, a work containing the Program or a portion of it,
+either verbatim or with modifications and/or translated into another
+language.  (Hereinafter, translation is included without limitation in
+the term "modification".)  Each licensee is addressed as "you".
+
+Activities other than copying, distribution and modification are not
+covered by this License; they are outside its scope.  The act of
+running the Program is not restricted, and the output from the Program
+is covered only if its contents constitute a work based on the
+Program (independent of having been made by running the Program).
+Whether that is true depends on what the Program does.
+
+  1. You may copy and distribute verbatim copies of the Program's
+source code as you receive it, in any medium, provided that you
+conspicuously and appropriately publish on each copy an appropriate
+copyright notice and disclaimer of warranty; keep intact all the
+notices that refer to this License and to the absence of any warranty;
+and give any other recipients of the Program a copy of this License
+along with the Program.
+
+You may charge a fee for the physical act of transferring a copy, and
+you may at your option offer warranty protection in exchange for a fee.
+
+  2. You may modify your copy or copies of the Program or any portion
+of it, thus forming a work based on the Program, and copy and
+distribute such modifications or work under the terms of Section 1
+above, provided that you also meet all of these conditions:
+
+    a) You must cause the modified files to carry prominent notices
+    stating that you changed the files and the date of any change.
+
+    b) You must cause any work that you distribute or publish, that in
+    whole or in part contains or is derived from the Program or any
+    part thereof, to be licensed as a whole at no charge to all third
+    parties under the terms of this License.
+
+    c) If the modified program normally reads commands interactively
+    when run, you must cause it, when started running for such
+    interactive use in the most ordinary way, to print or display an
+    announcement including an appropriate copyright notice and a
+    notice that there is no warranty (or else, saying that you provide
+    a warranty) and that users may redistribute the program under
+    these conditions, and telling the user how to view a copy of this
+    License.  (Exception: if the Program itself is interactive but
+    does not normally print such an announcement, your work based on
+    the Program is not required to print an announcement.)
+
+These requirements apply to the modified work as a whole.  If
+identifiable sections of that work are not derived from the Program,
+and can be reasonably considered independent and separate works in
+themselves, then this License, and its terms, do not apply to those
+sections when you distribute them as separate works.  But when you
+distribute the same sections as part of a whole which is a work based
+on the Program, the distribution of the whole must be on the terms of
+this License, whose permissions for other licensees extend to the
+entire whole, and thus to each and every part regardless of who wrote it.
+
+Thus, it is not the intent of this section to claim rights or contest
+your rights to work written entirely by you; rather, the intent is to
+exercise the right to control the distribution of derivative or
+collective works based on the Program.
+
+In addition, mere aggregation of another work not based on the Program
+with the Program (or with a work based on the Program) on a volume of
+a storage or distribution medium does not bring the other work under
+the scope of this License.
+
+  3. You may copy and distribute the Program (or a work based on it,
+under Section 2) in object code or executable form under the terms of
+Sections 1 and 2 above provided that you also do one of the following:
+
+    a) Accompany it with the complete corresponding machine-readable
+    source code, which must be distributed under the terms of Sections
+    1 and 2 above on a medium customarily used for software interchange; or,
+
+    b) Accompany it with a written offer, valid for at least three
+    years, to give any third party, for a charge no more than your
+    cost of physically performing source distribution, a complete
+    machine-readable copy of the corresponding source code, to be
+    distributed under the terms of Sections 1 and 2 above on a medium
+    customarily used for software interchange; or,
+
+    c) Accompany it with the information you received as to the offer
+    to distribute corresponding source code.  (This alternative is
+    allowed only for noncommercial distribution and only if you
+    received the program in object code or executable form with such
+    an offer, in accord with Subsection b above.)
+
+The source code for a work means the preferred form of the work for
+making modifications to it.  For an executable work, complete source
+code means all the source code for all modules it contains, plus any
+associated interface definition files, plus the scripts used to
+control compilation and installation of the executable.  However, as a
+special exception, the source code distributed need not include
+anything that is normally distributed (in either source or binary
+form) with the major components (compiler, kernel, and so on) of the
+operating system on which the executable runs, unless that component
+itself accompanies the executable.
+
+If distribution of executable or object code is made by offering
+access to copy from a designated place, then offering equivalent
+access to copy the source code from the same place counts as
+distribution of the source code, even though third parties are not
+compelled to copy the source along with the object code.
+
+  4. You may not copy, modify, sublicense, or distribute the Program
+except as expressly provided under this License.  Any attempt
+otherwise to copy, modify, sublicense or distribute the Program is
+void, and will automatically terminate your rights under this License.
+However, parties who have received copies, or rights, from you under
+this License will not have their licenses terminated so long as such
+parties remain in full compliance.
+
+  5. You are not required to accept this License, since you have not
+signed it.  However, nothing else grants you permission to modify or
+distribute the Program or its derivative works.  These actions are
+prohibited by law if you do not accept this License.  Therefore, by
+modifying or distributing the Program (or any work based on the
+Program), you indicate your acceptance of this License to do so, and
+all its terms and conditions for copying, distributing or modifying
+the Program or works based on it.
+
+  6. Each time you redistribute the Program (or any work based on the
+Program), the recipient automatically receives a license from the
+original licensor to copy, distribute or modify the Program subject to
+these terms and conditions.  You may not impose any further
+restrictions on the recipients' exercise of the rights granted herein.
+You are not responsible for enforcing compliance by third parties to
+this License.
+
+  7. If, as a consequence of a court judgment or allegation of patent
+infringement or for any other reason (not limited to patent issues),
+conditions are imposed on you (whether by court order, agreement or
+otherwise) that contradict the conditions of this License, they do not
+excuse you from the conditions of this License.  If you cannot
+distribute so as to satisfy simultaneously your obligations under this
+License and any other pertinent obligations, then as a consequence you
+may not distribute the Program at all.  For example, if a patent
+license would not permit royalty-free redistribution of the Program by
+all those who receive copies directly or indirectly through you, then
+the only way you could satisfy both it and this License would be to
+refrain entirely from distribution of the Program.
+
+If any portion of this section is held invalid or unenforceable under
+any particular circumstance, the balance of the section is intended to
+apply and the section as a whole is intended to apply in other
+circumstances.
+
+It is not the purpose of this section to induce you to infringe any
+patents or other property right claims or to contest validity of any
+such claims; this section has the sole purpose of protecting the
+integrity of the free software distribution system, which is
+implemented by public license practices.  Many people have made
+generous contributions to the wide range of software distributed
+through that system in reliance on consistent application of that
+system; it is up to the author/donor to decide if he or she is willing
+to distribute software through any other system and a licensee cannot
+impose that choice.
+
+This section is intended to make thoroughly clear what is believed to
+be a consequence of the rest of this License.
+
+  8. If the distribution and/or use of the Program is restricted in
+certain countries either by patents or by copyrighted interfaces, the
+original copyright holder who places the Program under this License
+may add an explicit geographical distribution limitation excluding
+those countries, so that distribution is permitted only in or among
+countries not thus excluded.  In such case, this License incorporates
+the limitation as if written in the body of this License.
+
+  9. The Free Software Foundation may publish revised and/or new versions
+of the General Public License from time to time.  Such new versions will
+be similar in spirit to the present version, but may differ in detail to
+address new problems or concerns.
+
+Each version is given a distinguishing version number.  If the Program
+specifies a version number of this License which applies to it and "any
+later version", you have the option of following the terms and conditions
+either of that version or of any later version published by the Free
+Software Foundation.  If the Program does not specify a version number of
+this License, you may choose any version ever published by the Free Software
+Foundation.
+
+  10. If you wish to incorporate parts of the Program into other free
+programs whose distribution conditions are different, write to the author
+to ask for permission.  For software which is copyrighted by the Free
+Software Foundation, write to the Free Software Foundation; we sometimes
+make exceptions for this.  Our decision will be guided by the two goals
+of preserving the free status of all derivatives of our free software and
+of promoting the sharing and reuse of software generally.
+
+			    NO WARRANTY
+
+  11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
+FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW.  EXCEPT WHEN
+OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
+PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
+OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.  THE ENTIRE RISK AS
+TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU.  SHOULD THE
+PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
+REPAIR OR CORRECTION.
+
+  12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
+WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
+REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
+INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
+OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
+TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
+YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
+PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGES.
+
+		     END OF TERMS AND CONDITIONS
+
+	    How to Apply These Terms to Your New Programs
+
+  If you develop a new program, and you want it to be of the greatest
+possible use to the public, the best way to achieve this is to make it
+free software which everyone can redistribute and change under these terms.
+
+  To do so, attach the following notices to the program.  It is safest
+to attach them to the start of each source file to most effectively
+convey the exclusion of warranty; and each file should have at least
+the "copyright" line and a pointer to where the full notice is found.
+
+    <one line to give the program's name and a brief idea of what it does.>
+    Copyright (C) <year>  <name of author>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+
+Also add information on how to contact you by electronic and paper mail.
+
+If the program is interactive, make it output a short notice like this
+when it starts in an interactive mode:
+
+    Gnomovision version 69, Copyright (C) year name of author
+    Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+    This is free software, and you are welcome to redistribute it
+    under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License.  Of course, the commands you use may
+be called something other than `show w' and `show c'; they could even be
+mouse-clicks or menu items--whatever suits your program.
+
+You should also get your employer (if you work as a programmer) or your
+school, if any, to sign a "copyright disclaimer" for the program, if
+necessary.  Here is a sample; alter the names:
+
+  Yoyodyne, Inc., hereby disclaims all copyright interest in the program
+  `Gnomovision' (which makes passes at compilers) written by James Hacker.
+
+  <signature of Ty Coon>, 1 April 1989
+  Ty Coon, President of Vice
+
+This General Public License does not permit incorporating your program into
+proprietary programs.  If your program is a subroutine library, you may
+consider it more useful to permit linking proprietary applications with the
+library.  If this is what you want to do, use the GNU Library General
+Public License instead of this License.
diff --git a/jni/dbus/tools/dbus-cleanup-sockets.1 b/jni/dbus/tools/dbus-cleanup-sockets.1
new file mode 100644
index 0000000..ca669f4
--- /dev/null
+++ b/jni/dbus/tools/dbus-cleanup-sockets.1
@@ -0,0 +1,43 @@
+.\" 
+.\" dbus-cleanup-sockets manual page.
+.\" Copyright (C) 2003 Red Hat, Inc.
+.\"
+.TH dbus-cleanup-sockets 1
+.SH NAME
+dbus-cleanup-sockets \- clean up leftover sockets in a directory
+.SH SYNOPSIS
+.PP
+.B dbus-cleanup-sockets [DIRECTORY]
+
+.SH DESCRIPTION
+
+The \fIdbus-cleanup-sockets\fP command cleans up unused D-Bus
+connection sockets. See http://www.freedesktop.org/software/dbus/ for
+more information about the big picture.
+
+.PP
+If given no arguments, \fIdbus-cleanup-sockets\fP cleans up sockets 
+in the standard default socket directory for the
+per-user-login-session message bus; this is usually /tmp. 
+Optionally, you can pass a different directory on the command line.
+
+.PP
+On Linux, this program is essentially useless, because D-Bus defaults
+to using "abstract sockets" that exist only in memory and don't have a
+corresponding file in /tmp. 
+
+.PP
+On most other flavors of UNIX, it's possible for the socket files to
+leak when programs using D-Bus exit abnormally or without closing
+their D-Bus connections. Thus, it might be interesting to run
+dbus-cleanup-sockets in a cron job to mop up any leaked sockets.
+Or you can just ignore the leaked sockets, they aren't really hurting
+anything, other than cluttering the output of "ls /tmp"
+
+.SH AUTHOR
+dbus-cleanup-sockets was adapted by Havoc Pennington from
+linc-cleanup-sockets written by Michael Meeks.
+
+.SH BUGS
+Please send bug reports to the D-Bus mailing list or bug tracker,
+see http://www.freedesktop.org/software/dbus/
diff --git a/jni/dbus/tools/dbus-cleanup-sockets.c b/jni/dbus/tools/dbus-cleanup-sockets.c
new file mode 100644
index 0000000..487c4b0
--- /dev/null
+++ b/jni/dbus/tools/dbus-cleanup-sockets.c
@@ -0,0 +1,431 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-cleanup-sockets.c  dbus-cleanup-sockets utility
+ *
+ * Copyright (C) 2003 Red Hat, Inc.
+ * Copyright (C) 2002 Michael Meeks
+ *
+ * Note that this file is NOT licensed under the Academic Free License,
+ * as it is based on linc-cleanup-sockets which is LGPL.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+#include <config.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <dirent.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifndef TRUE
+#define TRUE (1)
+#endif
+
+#ifndef FALSE
+#define FALSE (0)
+#endif
+
+#ifndef NULL
+#define NULL ((void*) 0)
+#endif
+
+static void*
+xmalloc (size_t bytes)
+{
+  void *mem;
+
+  if (bytes == 0)
+    return NULL;
+
+  mem = malloc (bytes);
+
+  if (mem == NULL)
+    {
+      fprintf (stderr, "Allocation of %d bytes failed\n",
+               (int) bytes);
+      exit (1);
+    }
+
+  return mem;
+}
+
+static void*
+xrealloc (void *old, size_t bytes)
+{
+  void *mem;
+
+  if (bytes == 0)
+    {
+      free (old);
+      return NULL;
+    }
+
+  mem = realloc (old, bytes);
+
+  if (mem == NULL)
+    {
+      fprintf (stderr, "Reallocation of %d bytes failed\n",
+               (int) bytes);
+      exit (1);
+    }
+
+  return mem;
+}
+
+#ifdef AF_UNIX
+
+typedef enum
+  {
+    SOCKET_UNKNOWN,
+    SOCKET_FAILED_TO_HANDLE,
+    SOCKET_DEAD,
+    SOCKET_ALIVE,
+    SOCKET_UNLINKED
+  } SocketStatus;
+
+static int alive_count = 0;
+static int cleaned_count = 0;
+static int unhandled_count = 0;
+
+typedef struct
+{
+  char *name;
+  int   fd;
+  SocketStatus status;
+  int   n_retries;
+} SocketEntry;
+
+static SocketEntry*
+socket_entry_new (const char *dir,
+                  const char *fname)
+{
+  SocketEntry *se;
+  int len;
+
+  se = xmalloc (sizeof (SocketEntry));
+
+  len = strlen (dir) + strlen (fname) + 2; /* 2 = nul and '/' */
+  se->name = xmalloc (len);
+
+  strcpy (se->name, dir);
+  strcat (se->name, "/");
+  strcat (se->name, fname);
+
+  se->fd = -1;
+
+  se->status = SOCKET_UNKNOWN;
+
+  se->n_retries = 0;
+
+  return se;
+}
+
+#if 0
+static void
+free_socket_entry (SocketEntry *se)
+{
+  free (se->name);
+  if (se->fd >= 0)
+    close (se->fd);
+  free (se);
+}
+#endif
+
+static void
+read_sockets (const char    *dir,
+              SocketEntry ***entries_p,
+              int           *n_entries_p)
+{
+  DIR   *dirh;
+  struct dirent *dent;
+  SocketEntry **entries;
+  int n_entries;
+  int allocated;
+
+  n_entries = 0;
+  allocated = 2;
+  entries = xmalloc (sizeof (SocketEntry*) * allocated);
+
+  dirh = opendir (dir);
+  if (dirh == NULL)
+    {
+      fprintf (stderr, "Failed to open directory %s: %s\n",
+               dir, strerror (errno));
+      exit (1);
+    }
+
+  while ((dent = readdir (dirh)))
+    {
+      SocketEntry *se;
+
+      if (strncmp (dent->d_name, "dbus-", 5) != 0)
+        continue;
+
+      se = socket_entry_new (dir, dent->d_name);
+
+      if (n_entries == allocated)
+        {
+          allocated *= 2;
+          entries = xrealloc (entries, sizeof (SocketEntry*) * allocated);
+        }
+
+      entries[n_entries] = se;
+      n_entries += 1;
+    }
+
+  closedir (dirh);
+
+  *entries_p = entries;
+  *n_entries_p = n_entries;
+}
+
+static SocketStatus
+open_socket (SocketEntry *se)
+{
+  int ret;
+  struct sockaddr_un saddr;
+
+  if (se->n_retries > 5)
+    {
+      fprintf (stderr, "Warning: giving up on socket %s after several retries; unable to determine socket's status\n",
+               se->name);
+      return SOCKET_FAILED_TO_HANDLE;
+    }
+
+  se->n_retries += 1;
+
+  se->fd = socket (AF_UNIX, SOCK_STREAM, 0);
+  if (se->fd < 0)
+    {
+      fprintf (stderr, "Warning: failed to open a socket to use for connecting: %s\n",
+               strerror (errno));
+      return SOCKET_UNKNOWN;
+    }
+
+  if (fcntl (se->fd, F_SETFL, O_NONBLOCK) < 0)
+    {
+      fprintf (stderr, "Warning: failed set socket %s nonblocking: %s\n",
+               se->name, strerror (errno));
+      return SOCKET_UNKNOWN;
+    }
+
+
+  memset (&saddr, '\0', sizeof (saddr)); /* nul-terminates the sun_path */
+
+  saddr.sun_family = AF_UNIX;
+  strncpy (saddr.sun_path, se->name, sizeof (saddr.sun_path) - 1);
+
+  do
+    {
+      ret = connect (se->fd, (struct sockaddr*) &saddr, sizeof (saddr));
+    }
+  while (ret < 0 && errno == EINTR);
+
+  if (ret >= 0)
+    return SOCKET_ALIVE;
+  else
+    {
+      switch (errno)
+        {
+        case EINPROGRESS:
+        case EAGAIN:
+          return SOCKET_UNKNOWN;
+        case ECONNREFUSED:
+          return SOCKET_DEAD;
+        default:
+          fprintf (stderr, "Warning: unexpected error connecting to socket %s: %s\n",
+                   se->name, strerror (errno));
+          return SOCKET_FAILED_TO_HANDLE;
+        }
+    }
+}
+
+static int
+handle_sockets (SocketEntry **entries,
+                int           n_entries)
+{
+  int i;
+  int n_unknown;
+
+  n_unknown = 0;
+
+  i = 0;
+  while (i < n_entries)
+    {
+      SocketEntry *se;
+      SocketStatus status;
+
+      se = entries[i];
+      ++i;
+
+      if (se->fd >= 0)
+        {
+          fprintf (stderr, "Internal error, socket has fd  kept open while status = %d\n",
+                   se->status);
+          exit (1);
+        }
+
+      if (se->status != SOCKET_UNKNOWN)
+        continue;
+
+      status = open_socket (se);
+
+      switch (status)
+        {
+        case SOCKET_DEAD:
+          cleaned_count += 1;
+          if (unlink (se->name) < 0)
+            {
+              fprintf (stderr, "Warning: Failed to delete %s: %s\n",
+                       se->name, strerror (errno));
+
+              se->status = SOCKET_FAILED_TO_HANDLE;
+            }
+          else
+            se->status = SOCKET_UNLINKED;
+          break;
+
+        case SOCKET_ALIVE:
+          alive_count += 1;
+          /* FALL THRU */
+
+        case SOCKET_FAILED_TO_HANDLE:
+        case SOCKET_UNKNOWN:
+          se->status = status;
+          break;
+
+        case SOCKET_UNLINKED:
+          fprintf (stderr, "Bad status from open_socket(), should not happen\n");
+          exit (1);
+          break;
+        }
+
+      if (se->fd >= 0)
+        {
+          close (se->fd);
+          se->fd = -1;
+        }
+
+      if (se->status == SOCKET_UNKNOWN)
+        n_unknown += 1;
+    }
+
+  return n_unknown == 0;
+}
+
+static void
+clean_dir (const char *dir)
+{
+  SocketEntry **entries;
+  int n_entries;
+
+  read_sockets (dir, &entries, &n_entries);
+
+  /* open_socket() will fail conclusively after
+   * several retries, so this loop is guaranteed
+   * to terminate eventually
+   */
+  while (!handle_sockets (entries, n_entries))
+    {
+      fprintf (stderr, "Unable to determine state of some sockets, retrying in 2 seconds\n");
+      sleep (2);
+    }
+
+  unhandled_count += (n_entries - alive_count - cleaned_count);
+}
+
+#endif /* AF_UNIX */
+
+static void
+usage (int ecode)
+{
+  fprintf (stderr, "dbus-cleanup-sockets [--version] [--help] <socketdir>\n");
+  exit (ecode);
+}
+
+static void
+version (void)
+{
+  printf ("D-Bus Socket Cleanup Utility %s\n"
+          "Copyright (C) 2003 Red Hat, Inc.\n"
+          "Copyright (C) 2002 Michael Meeks\n"
+          "This is free software; see the source for copying conditions.\n"
+          "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+          VERSION);
+  exit (0);
+}
+
+int
+main (int argc, char **argv)
+{
+  int i;
+  int saw_doubledash;
+  const char *dirname;
+
+  saw_doubledash = FALSE;
+  dirname = NULL;
+  i = 1;
+  while (i < argc)
+    {
+      const char *arg = argv[i];
+
+      if (strcmp (arg, "--help") == 0 ||
+          strcmp (arg, "-h") == 0 ||
+          strcmp (arg, "-?") == 0)
+        usage (0);
+      else if (strcmp (arg, "--version") == 0)
+        version ();
+      else if (!saw_doubledash)
+	{
+          if (strcmp (arg, "--") == 0)
+            saw_doubledash = TRUE;
+          else if (*arg == '-')
+            usage (1);
+	}
+      else
+        {
+          if (dirname != NULL)
+            {
+              fprintf (stderr, "dbus-cleanup-sockets only supports a single directory name\n");
+              exit (1);
+            }
+
+          dirname = arg;
+        }
+
+      ++i;
+    }
+
+  /* Default to session socket dir, usually /tmp */
+  if (dirname == NULL)
+    dirname = DBUS_SESSION_SOCKET_DIR;
+
+#ifdef AF_UNIX
+  clean_dir (dirname);
+
+  printf ("Cleaned up %d sockets in %s; %d sockets are still in use; %d in unknown state\n",
+          cleaned_count, dirname, alive_count, unhandled_count);
+#else
+  printf ("This system does not support UNIX domain sockets, so dbus-cleanup-sockets does nothing\n");
+#endif
+
+  return 0;
+}
diff --git a/jni/dbus/tools/dbus-launch-win.c b/jni/dbus/tools/dbus-launch-win.c
new file mode 100644
index 0000000..ea4bf0d
--- /dev/null
+++ b/jni/dbus/tools/dbus-launch-win.c
@@ -0,0 +1,170 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-launch-win.c  dbus-launch utility
+ *
+ * Copyright (C) 2007 Ralf Habacker <ralf.habacker@freenet.de>
+ *
+ * Licensed under the Academic Free License version 2.1
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#ifndef UNICODE
+#define UNICODE 1
+#endif
+#include <windows.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+/* Save string functions.  Instead of figuring out the exact _MSC_VER
+   that work, override for everybody.  */
+
+#define errno_t int
+#define wcscat_s my_wcscat_s
+#define wcscpy_s my_wcscpy_s
+
+static errno_t
+wcscat_s (wchar_t *dest, size_t size, wchar_t *src) 
+{
+  assert (sizeof (wchar_t) * (wcslen (dest) + wcslen (src) + 1) <= size);
+  wcscat (dest, src);
+  return 0;
+}
+
+
+static errno_t
+wcscpy_s (wchar_t *dest, size_t size, wchar_t *src)
+{
+  assert (sizeof (wchar_t) * (wcslen (src) + 1) <= size);
+  wcscpy (dest, src);
+  return 0;
+}
+
+/* TODO (tl): This Windows version of dbus-launch is curretly rather
+ * pointless as it doesn't take the same command-line options as the
+ * UNIX dbus-launch does. A main point of the dbus-launch command is
+ * to pass it for instance a --config-file option to make the started
+ * dbus-daemon use that config file.
+ * 
+ * This version also doesn't print out any information, which is a
+ * main point of the UNIX one. It should at least support the
+ * --sh-syntax option, and maybe also a --cmd-syntax to print out the
+ * variable settings in cmd.exe syntax?
+ * 
+ * NOTE (rh): The main task of dbus-launch is (from the man page) to start 
+ * a session bus and this is archieved by the current implemention. 
+ * 
+ * Additional on windows the session bus starting in not integrated 
+ * into the logon process, so there is no need for any --syntax option. 
+ * In fact (at least for kde on windows) the session bus is autostarted 
+ * with the first application requesting a session bus. 
+ *
+ */
+
+#define AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE 1
+
+#define DIM(x) (sizeof(x) / sizeof(x[0]))
+#define WCSTRINGIFY_(x) L ## x
+#define WCSTRINGIFY(x) WCSTRINGIFY_(x)
+
+int
+main (int argc, char **argv)
+{
+  wchar_t dbusDaemonPath[MAX_PATH * 2 + 1];
+  wchar_t command[MAX_PATH * 2 + 1];
+  wchar_t *p;
+  wchar_t *daemon_name;
+  int result;
+  int showConsole = 0;
+#ifdef DBUS_WINCE
+  char *s = NULL;
+#else
+  char *s = getenv("DBUS_VERBOSE");
+#endif
+  int verbose = s && *s != '\0' ? 1 : 0;
+
+  PROCESS_INFORMATION pi;
+  STARTUPINFOW si;
+  BOOL inherit = TRUE;
+  DWORD flags = 0;
+
+#ifdef AUTO_ACTIVATE_CONSOLE_WHEN_VERBOSE_MODE
+  if (verbose)
+      showConsole = 1; 
+#endif
+  GetModuleFileNameW (NULL, dbusDaemonPath, DIM (dbusDaemonPath));
+  
+  daemon_name = WCSTRINGIFY(DBUS_DAEMON_NAME) L".exe";
+  
+  if ((p = wcsrchr (dbusDaemonPath, L'\\'))) 
+    {
+      p[1] = L'\0';
+      wcscat_s (dbusDaemonPath, sizeof (dbusDaemonPath), daemon_name);
+    }
+  else 
+    {
+      if (verbose)
+          fprintf (stderr, "error: could not extract path from current "
+                   "applications module filename\n");
+      return 1;
+    } 
+
+#ifdef DBUS_WINCE
+   /* Windows CE has a different interpretation of cmdline: Start with argv[1].  */
+   wcscpy_s (command, sizeof (command), L"--session");
+   if (verbose)
+     fprintf (stderr, "%ls %ls\n", dbusDaemonPath, command);
+#else
+   command[0] = L'\0';
+   /* Windows CE has a different interpretation of cmdline: Start with argv[1].  */
+   wcscpy_s (command, sizeof (command), dbusDaemonPath);
+   wcscat_s (command, sizeof (command), L" --session");
+   if (verbose)
+     fprintf (stderr, "%ls\n", command);
+#endif
+  
+  memset (&si, 0, sizeof (si));
+  memset (&pi, 0, sizeof (pi));
+  si.cb = sizeof (si);
+  
+  if (verbose)
+    flags |= CREATE_NEW_CONSOLE;
+
+#ifdef DBUS_WINCE
+  inherit = FALSE;
+#else
+  flags |= NORMAL_PRIORITY_CLASS;
+  if (!verbose)
+    flags |= DETACHED_PROCESS;
+#endif
+
+  result = CreateProcessW (dbusDaemonPath, command, 0, 0,
+                           inherit, flags, 0, 0, &si, &pi);
+
+  if (result == 0) 
+    {
+      if (verbose)
+        fprintf (stderr, "Could not start " DBUS_DAEMON_NAME ". error=%d\n",
+                 GetLastError ());
+      return 4;
+    }
+   
+  CloseHandle (pi.hProcess);
+  CloseHandle (pi.hThread);
+
+  return 0;
+}
diff --git a/jni/dbus/tools/dbus-launch-x11.c b/jni/dbus/tools/dbus-launch-x11.c
new file mode 100644
index 0000000..fe49222
--- /dev/null
+++ b/jni/dbus/tools/dbus-launch-x11.c
@@ -0,0 +1,467 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-launch.h  dbus-launch utility
+ *
+ * Copyright (C) 2006 Thiago Macieira <thiago@kde.org>
+ *
+ * Licensed under the Academic Free License version 2.1
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include "dbus-launch.h"
+
+#ifdef DBUS_BUILD_X11
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <pwd.h>
+#include <X11/Xlib.h>
+#include <X11/Xatom.h>
+
+Display *xdisplay = NULL;
+static Atom selection_atom;
+static Atom address_atom;
+static Atom pid_atom;
+
+static int
+x_io_error_handler (Display *xdisplay)
+{
+  verbose ("X IO error\n");
+  kill_bus_and_exit (0);
+  return 0;
+}
+
+static void
+remove_prefix (char *s,
+               char *prefix)
+{
+  int plen;
+
+  plen = strlen (prefix);
+
+  if (strncmp (s, prefix, plen) == 0)
+    {
+      memmove (s, s + plen, strlen (s) - plen + 1);
+    }
+}
+
+static const char*
+get_homedir (void)
+{
+  const char *home;
+  
+  home = getenv ("HOME");
+  if (home == NULL)
+    {
+      /* try from the user database */
+      struct passwd *user = getpwuid (getuid());
+      if (user != NULL)
+        home = user->pw_dir;
+    }
+
+  if (home == NULL)
+    {
+      fprintf (stderr, "Can't get user home directory\n");
+      exit (1);
+    }
+
+  return home;
+}
+
+#define DBUS_DIR ".dbus"
+#define DBUS_SESSION_BUS_DIR "session-bus"
+
+static char *
+get_session_file (void)
+{
+  static const char prefix[] = "/" DBUS_DIR "/" DBUS_SESSION_BUS_DIR "/";
+  const char *machine;
+  const char *home;
+  char *display;
+  char *result;
+  char *p;
+
+  machine = get_machine_uuid ();
+  if (machine == NULL)
+    return NULL;
+
+  display = xstrdup (getenv ("DISPLAY"));
+  if (display == NULL)
+    {
+      verbose ("X11 integration disabled because X11 is not running\n");
+      return NULL;
+    }
+
+  /* remove the screen part of the display name */
+  p = strrchr (display, ':');
+  if (p != NULL)
+    {
+      for ( ; *p; ++p)
+        {
+          if (*p == '.')
+            {
+              *p = '\0';
+              break;
+            }
+        }
+    }
+
+  /* Note that we leave the hostname in the display most of the
+   * time. The idea is that we want to be per-(machine,display,user)
+   * triplet to be extra-sure we get a bus we can connect to. Ideally
+   * we'd recognize when the hostname matches the machine we're on in
+   * all cases; we do try to drop localhost and localhost.localdomain
+   * as a special common case so that alternate spellings of DISPLAY
+   * don't result in extra bus instances.
+   *
+   * We also kill the ":" if there's nothing in front of it. This
+   * avoids an ugly double underscore in the filename.
+   */
+  remove_prefix (display, "localhost.localdomain:");
+  remove_prefix (display, "localhost:");
+  remove_prefix (display, ":");
+
+  /* replace the : in the display with _ if the : is still there.
+   * use _ instead of - since it can't be in hostnames.
+   */
+  for (p = display; *p; ++p)
+    {
+      if (*p == ':')
+        *p = '_';
+    }
+  
+  home = get_homedir ();
+  
+  result = malloc (strlen (home) + strlen (prefix) + strlen (machine) +
+                   strlen (display) + 2);
+  if (result == NULL)
+    {
+      /* out of memory */
+      free (display);
+      return NULL;
+    }
+
+  strcpy (result, home);
+  strcat (result, prefix);
+  strcat (result, machine);
+  strcat (result, "-");
+  strcat (result, display);
+  free (display);
+
+  verbose ("session file: %s\n", result);
+  return result;
+}
+
+static void
+ensure_session_directory (void)
+{
+  const char *home;
+  char *dir;
+  
+  home = get_homedir ();
+
+  /* be sure we have space for / and nul */
+  dir = malloc (strlen (home) + strlen (DBUS_DIR) + strlen (DBUS_SESSION_BUS_DIR) + 3);
+  if (dir == NULL)
+    {
+      fprintf (stderr, "no memory\n");
+      exit (1);
+    }
+  
+  strcpy (dir, home);
+  strcat (dir, "/");
+  strcat (dir, DBUS_DIR);
+
+  if (mkdir (dir, 0700) < 0)
+    {
+      /* only print a warning here, writing the session file itself will fail later */
+      if (errno != EEXIST)
+        fprintf (stderr, "Unable to create %s\n", dir);
+    }
+
+  strcat (dir, "/");
+  strcat (dir, DBUS_SESSION_BUS_DIR);
+
+  if (mkdir (dir, 0700) < 0)
+    {
+      /* only print a warning here, writing the session file itself will fail later */
+      if (errno != EEXIST)
+        fprintf (stderr, "Unable to create %s\n", dir);
+    }
+  
+  free (dir);
+}
+
+static Display *
+open_x11 (void)
+{
+  if (xdisplay != NULL)
+    return xdisplay;
+
+  xdisplay = XOpenDisplay (NULL);
+  if (xdisplay != NULL)
+    {
+      verbose ("Connected to X11 display '%s'\n", DisplayString (xdisplay));
+      XSetIOErrorHandler (x_io_error_handler);
+    }
+  return xdisplay;
+}
+
+static int
+init_x_atoms (Display *display)
+{
+  static const char selection_prefix[] = "_DBUS_SESSION_BUS_SELECTION_";
+  static const char address_prefix[] = "_DBUS_SESSION_BUS_ADDRESS";
+  static const char pid_prefix[] = "_DBUS_SESSION_BUS_PID";
+  static int init = FALSE;
+  char *atom_name;
+  const char *machine;
+  char *user_name;
+  struct passwd *user;
+
+  if (init)
+    return TRUE;
+
+  machine = get_machine_uuid ();
+  if (machine == NULL)
+    return FALSE;
+
+  user = getpwuid (getuid ());
+  if (user == NULL)
+    {
+      verbose ("Could not determine the user informations; aborting X11 integration.\n");
+      return FALSE;
+    }
+  user_name = xstrdup(user->pw_name);
+
+  atom_name = malloc (strlen (machine) + strlen (user_name) + 2 +
+                      MAX (strlen (selection_prefix),
+                           MAX (strlen (address_prefix),
+                                strlen (pid_prefix))));
+  if (atom_name == NULL)
+    {
+      verbose ("Could not create X11 atoms; aborting X11 integration.\n");
+      free (user_name);
+      return FALSE;
+    }
+
+  /* create the selection atom */
+  strcpy (atom_name, selection_prefix);
+  strcat (atom_name, user_name);
+  strcat (atom_name, "_");
+  strcat (atom_name, machine);
+  selection_atom = XInternAtom (display, atom_name, FALSE);
+
+  /* create the address property atom */
+  strcpy (atom_name, address_prefix);
+  address_atom = XInternAtom (display, atom_name, FALSE);
+
+  /* create the PID property atom */
+  strcpy (atom_name, pid_prefix);
+  pid_atom = XInternAtom (display, atom_name, FALSE);
+
+  free (atom_name);
+  free (user_name);
+  init = TRUE;
+  return TRUE;
+}
+
+/*
+ * Gets the daemon address from the X11 display.
+ * Returns FALSE if there was an error. Returning
+ * TRUE does not mean the address exists.
+ */
+int
+x11_get_address (char **paddress, pid_t *pid, long *wid)
+{
+  Atom type;
+  Window owner;
+  int format;
+  unsigned long items;
+  unsigned long after;
+  char *data;
+
+  *paddress = NULL;
+
+  /* locate the selection owner */
+  owner = XGetSelectionOwner (xdisplay, selection_atom);
+  if (owner == None)
+    return TRUE;                /* no owner */
+  if (wid != NULL)
+    *wid = (long) owner;
+
+  /* get the bus address */
+  XGetWindowProperty (xdisplay, owner, address_atom, 0, 1024, False,
+                      XA_STRING, &type, &format, &items, &after,
+                      (unsigned char **) &data);
+  if (type == None || after != 0 || data == NULL || format != 8)
+    return FALSE;               /* error */
+
+  *paddress = xstrdup (data);
+  XFree (data);
+
+  /* get the PID */
+  if (pid != NULL)
+    {
+      *pid = 0;
+      XGetWindowProperty (xdisplay, owner, pid_atom, 0, sizeof pid, False,
+                          XA_CARDINAL, &type, &format, &items, &after,
+                          (unsigned char **) &data);
+      if (type != None && after == 0 && data != NULL && format == 32)
+        *pid = (pid_t) *(long*) data;
+      XFree (data);
+    }
+
+  return TRUE;                  /* success */
+}
+
+/*
+ * Saves the address in the X11 display. Returns 0 on success.
+ * If an error occurs, returns -1. If the selection already exists,
+ * returns 1. (i.e. another daemon is already running)
+ */
+static Window
+set_address_in_x11(char *address, pid_t pid)
+{
+  char *current_address;
+  Window wid = None;
+  unsigned long pid32; /* Xlib property functions want _long_ not 32-bit for format "32" */
+  
+  /* lock the X11 display to make sure we're doing this atomically */
+  XGrabServer (xdisplay);
+
+  if (!x11_get_address (&current_address, NULL, NULL))
+    {
+      /* error! */
+      goto out;
+    }
+
+  if (current_address != NULL)
+    {
+      /* someone saved the address in the meantime */
+      free (current_address);
+      goto out;
+    }
+
+  /* Create our window */
+  wid = XCreateWindow (xdisplay, RootWindow (xdisplay, 0), -20, -20, 10, 10,
+                       0, CopyFromParent, InputOnly, CopyFromParent,
+                       0, NULL);
+  verbose ("Created window %d\n", wid);
+
+  /* Save the property in the window */
+  XChangeProperty (xdisplay, wid, address_atom, XA_STRING, 8, PropModeReplace,
+                   (unsigned char *)address, strlen (address));
+  pid32 = pid;
+  XChangeProperty (xdisplay, wid, pid_atom, XA_CARDINAL, 32, PropModeReplace,
+                   (unsigned char *)&pid32, 1);
+
+  /* Now grab the selection */
+  XSetSelectionOwner (xdisplay, selection_atom, wid, CurrentTime);
+
+ out:
+  /* Ungrab the server to let other people use it too */
+  XUngrabServer (xdisplay);
+
+  /* And make sure that the ungrab gets sent to X11 */
+  XFlush (xdisplay);
+
+  return wid;
+}
+
+/*
+ * Saves the session address in session file. Returns TRUE on
+ * success, FALSE if an error occurs.
+ */
+static int
+set_address_in_file (char *address, pid_t pid, Window wid)
+{
+  char *session_file;
+  FILE *f;
+
+  ensure_session_directory ();
+  session_file = get_session_file();
+  if (session_file == NULL)
+    return FALSE;
+
+  f = fopen (session_file, "w");
+  if (f == NULL)
+    return FALSE;               /* some kind of error */
+  fprintf (f,
+           "# This file allows processes on the machine with id %s using \n"
+           "# display %s to find the D-Bus session bus with the below address.\n"
+           "# If the DBUS_SESSION_BUS_ADDRESS environment variable is set, it will\n"
+           "# be used rather than this file.\n"
+           "# See \"man dbus-launch\" for more details.\n"
+           "DBUS_SESSION_BUS_ADDRESS=%s\n"
+           "DBUS_SESSION_BUS_PID=%ld\n"
+           "DBUS_SESSION_BUS_WINDOWID=%ld\n",
+           get_machine_uuid (),
+           getenv ("DISPLAY"),
+           address, (long)pid, (long)wid);
+
+  fclose (f);
+  free (session_file);
+
+  return TRUE;
+}
+
+int
+x11_save_address (char *address, pid_t pid, long *wid)
+{
+  Window id = set_address_in_x11 (address, pid);
+  if (id != None)
+    {
+      if (!set_address_in_file (address, pid, id))
+        return FALSE;
+
+      if (wid != NULL)
+        *wid = (long) id;
+      return TRUE;
+    }
+  return FALSE;
+}
+
+int
+x11_init (void)
+{
+  return open_x11 () != NULL && init_x_atoms (xdisplay);
+}
+
+void
+x11_handle_event (void)
+{
+  if (xdisplay != NULL)
+    {      
+      while (XPending (xdisplay))
+        {
+          XEvent ignored;
+          XNextEvent (xdisplay, &ignored);
+        }
+    }
+}  
+
+#else
+void dummy_dbus_launch_x11 (void);
+
+void dummy_dbus_launch_x11 (void) { }
+#endif
diff --git a/jni/dbus/tools/dbus-launch.1 b/jni/dbus/tools/dbus-launch.1
new file mode 100644
index 0000000..0ea1949
--- /dev/null
+++ b/jni/dbus/tools/dbus-launch.1
@@ -0,0 +1,183 @@
+.\" 
+.\" dbus-launch manual page.
+.\" Copyright (C) 2003 Red Hat, Inc.
+.\"
+.TH dbus-launch 1
+.SH NAME
+dbus-launch \- Utility to start a message bus from a shell script
+.SH SYNOPSIS
+.PP
+.B dbus-launch [\-\-version] [\-\-sh-syntax] [\-\-csh-syntax] [\-\-auto-syntax] [\-\-exit-with-session] [\-\-autolaunch=MACHINEID] [\-\-config-file=FILENAME] [PROGRAM] [ARGS...]
+
+.SH DESCRIPTION
+
+The \fIdbus-launch\fP command is used to start a session bus 
+instance of \fIdbus-daemon\fP from a shell script.
+It would normally be called from a user's login
+scripts. Unlike the daemon itself, \fIdbus-launch\fP exits, so
+backticks or the $() construct can be used to read information from
+\fIdbus-launch\fP.
+
+With no arguments, \fIdbus-launch\fP will launch a session bus
+instance and print the address and pid of that instance to standard
+output.
+
+You may specify a program to be run; in this case, \fIdbus-launch\fP
+will launch a session bus instance, set the appropriate environment
+variables so the specified program can find the bus, and then execute the
+specified program, with the specified arguments.  See below for
+examples.
+
+If you launch a program, \fIdbus-launch\fP will not print the
+information about the new bus to standard output.
+
+When \fIdbus-launch\fP prints bus information to standard output, by
+default it is in a simple key-value pairs format. However, you may 
+request several alternate syntaxes using the \-\-sh-syntax, \-\-csh-syntax,
+\-\-binary-syntax, or
+\-\-auto-syntax options. Several of these cause \fIdbus-launch\fP to emit shell code
+to set up the environment.
+
+With the \-\-auto-syntax option, \fIdbus-launch\fP looks at the value
+of the SHELL environment variable to determine which shell syntax
+should be used.  If SHELL ends in "csh", then csh-compatible code is
+emitted; otherwise Bourne shell code is emitted.  Instead of passing
+\-\-auto-syntax, you may explicity specify a particular one by using
+\-\-sh-syntax for Bourne syntax, or \-\-csh-syntax for csh syntax.
+In scripts, it's more robust to avoid \-\-auto-syntax and you hopefully
+know which shell your script is written in.
+
+.PP
+See http://www.freedesktop.org/software/dbus/ for more information
+about D-Bus. See also the man page for \fIdbus-daemon\fP.
+
+.PP
+Here is an example of how to use \fIdbus-launch\fP with an 
+sh-compatible shell to start the per-session bus daemon:
+.nf
+
+  ## test for an existing bus daemon, just to be safe
+  if test -z "$DBUS_SESSION_BUS_ADDRESS" ; then
+      ## if not found, launch a new one
+      eval `dbus-launch --sh-syntax --exit-with-session`
+      echo "D-Bus per-session daemon address is: $DBUS_SESSION_BUS_ADDRESS"
+  fi
+
+.fi
+You might run something like that in your login scripts.
+
+.PP
+Another way to use \fIdbus-launch\fP is to run your main session
+program, like so:
+.nf
+
+dbus-launch gnome-session
+
+.fi
+The above would likely be appropriate for ~/.xsession or ~/.Xclients.
+
+.SH AUTOMATIC LAUNCHING
+
+.PP
+If DBUS_SESSION_BUS_ADDRESS is not set for a process that tries to use
+D-Bus, by default the process will attempt to invoke dbus-launch with
+the --autolaunch option to start up a new session bus or find the 
+existing bus address on the X display or in a file in
+~/.dbus/session-bus/
+
+.PP
+Whenever an autolaunch occurs, the application that had to
+start a new bus will be in its own little world; it can effectively
+end up starting a whole new session if it tries to use a lot of 
+bus services. This can be suboptimal or even totally broken, depending
+on the app and what it tries to do.
+
+.PP
+There are two common reasons for autolaunch. One is ssh to a remote
+machine. The ideal fix for that would be forwarding of
+DBUS_SESSION_BUS_ADDRESS in the same way that DISPLAY is forwarded.
+In the meantime, you can edit the session.conf config file to 
+have your session bus listen on TCP, and manually set
+DBUS_SESSION_BUS_ADDRESS, if you like.
+
+.PP
+The second common reason for autolaunch is an su to another user, and
+display of X applications running as the second user on the display
+belonging to the first user. Perhaps the ideal fix in this case
+would be to allow the second user to connect to the session bus of the
+first user, just as they can connect to the first user's display.
+However, a mechanism for that has not been coded.
+
+.PP
+You can always avoid autolaunch by manually setting
+DBUS_SESSION_BUS_ADDRESS. Autolaunch happens because the default
+address if none is set is "autolaunch:", so if any other address is
+set there will be no autolaunch. You can however include autolaunch in
+an explicit session bus address as a fallback, for example
+DBUS_SESSION_BUS_ADDRESS="something:,autolaunch:" - in that case if
+the first address doesn't work, processes will autolaunch. (The bus
+address variable contains a comma-separated list of addresses to try.)
+
+.PP
+The --autolaunch option is considered an internal implementation
+detail of libdbus, and in fact there are plans to change it. There's
+no real reason to use it outside of the libdbus implementation anyhow.
+
+.SH OPTIONS
+The following options are supported:
+.TP
+.I "--auto-syntax"
+Choose \-\-csh-syntax or \-\-sh-syntax based on the SHELL environment variable.
+
+.I "--binary-syntax"
+Write to stdout a nul-terminated bus address, then the bus PID as a
+binary integer of size sizeof(pid_t), then the bus X window ID as a
+binary integer of size sizeof(long). Integers are in the machine's
+byte order, not network byte order or any other canonical byte order.
+
+.TP
+.I "--close-stderr"
+Close the standard error output stream before starting the D-Bus
+daemon. This is useful if you want to capture dbus-launch error
+messages but you don't want dbus-daemon to keep the stream open to
+your application.
+
+.TP
+.I "--config-file=FILENAME"
+Pass \-\-config-file=FILENAME to the bus daemon, instead of passing it 
+the \-\-session argument. See the man page for dbus-daemon
+
+.TP
+.I "--csh-syntax"
+Emit csh compatible code to set up environment variables.
+
+.TP
+.I "--exit-with-session"
+If this option is provided, a persistent "babysitter" process will be 
+created that watches stdin for HUP and tries to connect to the X
+server. If this process gets a HUP on stdin or loses its X connection,
+it kills the message bus daemon.
+
+.TP
+.I "--autolaunch=MACHINEID"
+This option implies that \fIdbus-launch\fP should scan for a
+previously-started session and reuse the values found there. If no
+session is found, it will start a new session. The
+\-\-exit-with-session option is implied if \-\-autolaunch is given.
+This option is for the exclusive use of libdbus, you do not want to
+use it manually. It may change in the future.
+
+.TP
+.I "--sh-syntax"
+Emit Bourne-shell compatible code to set up environment variables.
+
+.TP
+.I "--version"
+Print the version of dbus-launch
+
+.SH AUTHOR
+See http://www.freedesktop.org/software/dbus/doc/AUTHORS
+
+.SH BUGS
+Please send bug reports to the D-Bus mailing list or bug tracker,
+see http://www.freedesktop.org/software/dbus/
diff --git a/jni/dbus/tools/dbus-launch.c b/jni/dbus/tools/dbus-launch.c
new file mode 100644
index 0000000..6fa9c92
--- /dev/null
+++ b/jni/dbus/tools/dbus-launch.c
@@ -0,0 +1,1216 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-launch.c  dbus-launch utility
+ *
+ * Copyright (C) 2003, 2006 Red Hat, Inc.
+ * Copyright (C) 2006 Thiago Macieira <thiago@kde.org>
+ *
+ * Licensed under the Academic Free License version 2.1
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include "dbus-launch.h"
+#include <stdlib.h>
+#include <ctype.h>
+#include <unistd.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/wait.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <signal.h>
+#include <stdarg.h>
+#include <sys/select.h>
+#include <time.h>
+
+#ifdef DBUS_BUILD_X11
+#include <X11/Xlib.h>
+extern Display *xdisplay;
+#endif
+
+static char* machine_uuid = NULL;
+
+const char*
+get_machine_uuid (void)
+{
+  return machine_uuid;
+}
+
+static void
+save_machine_uuid (const char *uuid_arg)
+{
+  if (strlen (uuid_arg) != 32)
+    {
+      fprintf (stderr, "machine ID '%s' looks like it's the wrong length, should be 32 hex digits",
+               uuid_arg);
+      exit (1);
+    }
+
+  machine_uuid = xstrdup (uuid_arg);
+}
+
+#define UUID_MAXLEN 40
+/* Read the machine uuid from file if needed. Returns TRUE if machine_uuid is
+ * set after this function */
+static int
+read_machine_uuid_if_needed (void)
+{
+  FILE *f;
+  char uuid[UUID_MAXLEN];
+  size_t len;
+  int ret = FALSE;
+
+  if (machine_uuid != NULL)
+    return TRUE;
+
+  f = fopen (DBUS_MACHINE_UUID_FILE, "r");
+  if (f == NULL)
+    return FALSE;
+
+  if (fgets (uuid, UUID_MAXLEN, f) == NULL)
+    goto out;
+
+  len = strlen (uuid);
+  if (len < 32)
+    goto out;
+
+  /* rstrip the read uuid */
+  while (len > 31 && isspace(uuid[len - 1]))
+    len--;
+
+  if (len != 32)
+    goto out;
+
+  uuid[len] = '\0';
+  machine_uuid = xstrdup (uuid);
+  verbose ("UID: %s\n", machine_uuid);
+  ret = TRUE;
+
+out:
+  fclose(f);
+  return ret;
+}
+
+
+void
+verbose (const char *format,
+         ...)
+{
+  va_list args;
+  static int verbose = TRUE;
+  static int verbose_initted = FALSE;
+  
+  /* things are written a bit oddly here so that
+   * in the non-verbose case we just have the one
+   * conditional and return immediately.
+   */
+  if (!verbose)
+    return;
+  
+  if (!verbose_initted)
+    {
+      verbose = getenv ("DBUS_VERBOSE") != NULL;
+      verbose_initted = TRUE;
+      if (!verbose)
+        return;
+    }
+
+  fprintf (stderr, "%lu: ", (unsigned long) getpid ());
+  
+  va_start (args, format);
+  vfprintf (stderr, format, args);
+  va_end (args);
+}
+
+static void
+usage (int ecode)
+{
+  fprintf (stderr, "dbus-launch [--version] [--help] [--sh-syntax] [--csh-syntax] [--auto-syntax] [--exit-with-session]\n");
+  exit (ecode);
+}
+
+static void
+version (void)
+{
+  printf ("D-Bus Message Bus Launcher %s\n"
+          "Copyright (C) 2003 Red Hat, Inc.\n"
+          "This is free software; see the source for copying conditions.\n"
+          "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+          VERSION);
+  exit (0);
+}
+
+char *
+xstrdup (const char *str)
+{
+  int len;
+  char *copy;
+  
+  if (str == NULL)
+    return NULL;
+  
+  len = strlen (str);
+
+  copy = malloc (len + 1);
+  if (copy == NULL)
+    return NULL;
+
+  memcpy (copy, str, len + 1);
+  
+  return copy;
+}
+
+typedef enum
+{
+  READ_STATUS_OK,    /**< Read succeeded */
+  READ_STATUS_ERROR, /**< Some kind of error */
+  READ_STATUS_EOF    /**< EOF returned */
+} ReadStatus;
+
+static ReadStatus
+read_line (int        fd,
+           char      *buf,
+           size_t     maxlen)
+{
+  size_t bytes = 0;
+  ReadStatus retval;
+
+  memset (buf, '\0', maxlen);
+  maxlen -= 1; /* ensure nul term */
+  
+  retval = READ_STATUS_OK;
+  
+  while (TRUE)
+    {
+      ssize_t chunk;    
+      size_t to_read;
+      
+    again:
+      to_read = maxlen - bytes;
+
+      if (to_read == 0)
+        break;
+      
+      chunk = read (fd,
+                    buf + bytes,
+                    to_read);
+      if (chunk < 0 && errno == EINTR)
+        goto again;
+          
+      if (chunk < 0)
+        {
+          retval = READ_STATUS_ERROR;
+          break;
+        }
+      else if (chunk == 0)
+        {
+          retval = READ_STATUS_EOF;
+          break; /* EOF */
+        }
+      else /* chunk > 0 */
+	bytes += chunk;
+    }
+
+  if (retval == READ_STATUS_EOF &&
+      bytes > 0)
+    retval = READ_STATUS_OK;
+  
+  /* whack newline */
+  if (retval != READ_STATUS_ERROR &&
+      bytes > 0 &&
+      buf[bytes-1] == '\n')
+    buf[bytes-1] = '\0';
+  
+  return retval;
+}
+
+static ReadStatus
+read_pid (int        fd,
+          pid_t     *buf)
+{
+  size_t bytes = 0;
+  ReadStatus retval;
+
+  retval = READ_STATUS_OK;
+  
+  while (TRUE)
+    {
+      ssize_t chunk;    
+      size_t to_read;
+      
+    again:
+      to_read = sizeof (pid_t) - bytes;
+
+      if (to_read == 0)
+        break;
+      
+      chunk = read (fd,
+                    ((char*)buf) + bytes,
+                    to_read);
+      if (chunk < 0 && errno == EINTR)
+        goto again;
+          
+      if (chunk < 0)
+        {
+          retval = READ_STATUS_ERROR;
+          break;
+        }
+      else if (chunk == 0)
+        {
+          retval = READ_STATUS_EOF;
+          break; /* EOF */
+        }
+      else /* chunk > 0 */
+	bytes += chunk;
+    }
+
+  return retval;
+}
+
+static void
+do_write (int fd, const void *buf, size_t count)
+{
+  size_t bytes_written;
+  int ret;
+  
+  bytes_written = 0;
+  
+ again:
+  
+  ret = write (fd, ((const char*)buf) + bytes_written, count - bytes_written);
+
+  if (ret < 0)
+    {
+      if (errno == EINTR)
+        goto again;
+      else
+        {
+          fprintf (stderr, "Failed to write data to pipe! %s\n",
+                   strerror (errno));
+          exit (1); /* give up, we suck */
+        }
+    }
+  else
+    bytes_written += ret;
+  
+  if (bytes_written < count)
+    goto again;
+}
+
+static void
+write_pid (int   fd,
+           pid_t pid)
+{
+  do_write (fd, &pid, sizeof (pid));
+}
+
+static int
+do_waitpid (pid_t pid)
+{
+  int ret;
+  
+ again:
+  ret = waitpid (pid, NULL, 0);
+
+  if (ret < 0 &&
+      errno == EINTR)
+    goto again;
+
+  return ret;
+}
+
+static pid_t bus_pid_to_kill = -1;
+
+static void
+kill_bus(void)
+{
+  verbose ("Killing message bus and exiting babysitter\n");
+  kill (bus_pid_to_kill, SIGTERM);
+  sleep (3);
+  kill (bus_pid_to_kill, SIGKILL);
+}
+
+void
+kill_bus_and_exit (int exitcode)
+{
+  /* in case these point to any NFS mounts, get rid of them immediately */
+  close (0);
+  close (1);
+  close (2);
+
+  kill_bus();
+
+  exit (exitcode);
+}
+
+static void
+print_variables (const char *bus_address, pid_t bus_pid, long bus_wid,
+		 int c_shell_syntax, int bourne_shell_syntax,
+		 int binary_syntax)
+{
+  if (binary_syntax)
+    {
+      do_write (1, bus_address, strlen (bus_address) + 1);
+      do_write (1, &bus_pid, sizeof bus_pid);
+      do_write (1, &bus_wid, sizeof bus_wid);
+      return;
+    }
+  else if (c_shell_syntax)
+    {
+      printf ("setenv DBUS_SESSION_BUS_ADDRESS '%s';\n", bus_address);	
+      printf ("set DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid);
+      if (bus_wid)
+        printf ("set DBUS_SESSION_BUS_WINDOWID=%ld;\n", (long) bus_wid);
+      fflush (stdout);
+    }
+  else if (bourne_shell_syntax)
+    {
+      printf ("DBUS_SESSION_BUS_ADDRESS='%s';\n", bus_address);
+      printf ("export DBUS_SESSION_BUS_ADDRESS;\n");
+      printf ("DBUS_SESSION_BUS_PID=%ld;\n", (long) bus_pid);
+      if (bus_wid)
+        printf ("DBUS_SESSION_BUS_WINDOWID=%ld;\n", (long) bus_wid);
+      fflush (stdout);
+    }
+  else
+    {
+      printf ("DBUS_SESSION_BUS_ADDRESS=%s\n", bus_address);
+      printf ("DBUS_SESSION_BUS_PID=%ld\n", (long) bus_pid);
+      if (bus_wid)
+	printf ("DBUS_SESSION_BUS_WINDOWID=%ld\n", (long) bus_wid);
+      fflush (stdout);
+    }
+}
+
+static int got_sighup = FALSE;
+
+static void
+signal_handler (int sig)
+{
+  switch (sig)
+    {
+#ifdef SIGHUP
+    case SIGHUP:
+#endif
+    case SIGINT:
+    case SIGTERM:
+      got_sighup = TRUE;
+      break;
+    }
+}
+
+static void
+kill_bus_when_session_ends (void)
+{
+  int tty_fd;
+  int x_fd;
+  fd_set read_set;
+  fd_set err_set;
+  struct sigaction act;
+  sigset_t empty_mask;
+  
+  /* install SIGHUP handler */
+  got_sighup = FALSE;
+  sigemptyset (&empty_mask);
+  act.sa_handler = signal_handler;
+  act.sa_mask    = empty_mask;
+  act.sa_flags   = 0;
+  sigaction (SIGHUP,  &act, NULL);
+  sigaction (SIGTERM,  &act, NULL);
+  sigaction (SIGINT,  &act, NULL);
+  
+#ifdef DBUS_BUILD_X11
+  x11_init();
+  if (xdisplay != NULL)
+    {
+      x_fd = ConnectionNumber (xdisplay);
+    }
+  else
+    x_fd = -1;
+#else
+  x_fd = -1;
+#endif
+
+  if (isatty (0))
+    tty_fd = 0;
+  else
+    tty_fd = -1;
+
+  if (tty_fd >= 0)
+    verbose ("stdin isatty(), monitoring it\n");
+  else
+    verbose ("stdin was not a TTY, not monitoring it\n");  
+  
+  if (tty_fd < 0 && x_fd < 0)
+    {
+      fprintf (stderr, "No terminal on standard input and no X display; cannot attach message bus to session lifetime\n");
+      exit (1);
+    }
+  
+  while (TRUE)
+    {
+#ifdef DBUS_BUILD_X11
+      /* Dump events on the floor, and let
+       * IO error handler run if we lose
+       * the X connection. It's important to
+       * run this before going into select() since
+       * we might have queued outgoing messages or
+       * events.
+       */
+      x11_handle_event ();
+#endif
+      
+      FD_ZERO (&read_set);
+      FD_ZERO (&err_set);
+
+      if (tty_fd >= 0)
+        {
+          FD_SET (tty_fd, &read_set);
+          FD_SET (tty_fd, &err_set);
+        }
+
+      if (x_fd >= 0)
+        {
+          FD_SET (x_fd, &read_set);
+          FD_SET (x_fd, &err_set);
+        }
+
+      select (MAX (tty_fd, x_fd) + 1,
+              &read_set, NULL, &err_set, NULL);
+
+      if (got_sighup)
+        {
+          verbose ("Got SIGHUP, exiting\n");
+          kill_bus_and_exit (0);
+        }
+      
+#ifdef DBUS_BUILD_X11
+      /* Events will be processed before we select again
+       */
+      if (x_fd >= 0)
+        verbose ("X fd condition reading = %d error = %d\n",
+                 FD_ISSET (x_fd, &read_set),
+                 FD_ISSET (x_fd, &err_set));
+#endif
+
+      if (tty_fd >= 0)
+        {
+          if (FD_ISSET (tty_fd, &read_set))
+            {
+              int bytes_read;
+              char discard[512];
+
+              verbose ("TTY ready for reading\n");
+              
+              bytes_read = read (tty_fd, discard, sizeof (discard));
+
+              verbose ("Read %d bytes from TTY errno = %d\n",
+                       bytes_read, errno);
+              
+              if (bytes_read == 0)
+                kill_bus_and_exit (0); /* EOF */
+              else if (bytes_read < 0 && errno != EINTR)
+                {
+                  /* This shouldn't happen I don't think; to avoid
+                   * spinning on the fd forever we exit.
+                   */
+                  fprintf (stderr, "dbus-launch: error reading from stdin: %s\n",
+                           strerror (errno));
+                  kill_bus_and_exit (0);
+                }
+            }
+          else if (FD_ISSET (tty_fd, &err_set))
+            {
+              verbose ("TTY has error condition\n");
+              
+              kill_bus_and_exit (0);
+            }
+        }
+    }
+}
+
+static void
+babysit (int   exit_with_session,
+         pid_t child_pid,
+         int   read_bus_pid_fd)  /* read pid from here */
+{
+  int ret;
+  int dev_null_fd;
+  const char *s;
+
+  verbose ("babysitting, exit_with_session = %d, child_pid = %ld, read_bus_pid_fd = %d\n",
+           exit_with_session, (long) child_pid, read_bus_pid_fd);
+  
+  /* We chdir ("/") since we are persistent and daemon-like, and fork
+   * again so dbus-launch can reap the parent.  However, we don't
+   * setsid() or close fd 0 because the idea is to remain attached
+   * to the tty and the X server in order to kill the message bus
+   * when the session ends.
+   */
+
+  if (chdir ("/") < 0)
+    {
+      fprintf (stderr, "Could not change to root directory: %s\n",
+               strerror (errno));
+      exit (1);
+    }
+
+  /* Close stdout/stderr so we don't block an "eval" or otherwise
+   * lock up. stdout is still chaining through to dbus-launch
+   * and in turn to the parent shell.
+   */
+  dev_null_fd = open ("/dev/null", O_RDWR);
+  if (dev_null_fd >= 0)
+    {
+      if (!exit_with_session)
+        dup2 (dev_null_fd, 0);
+      dup2 (dev_null_fd, 1);
+      s = getenv ("DBUS_DEBUG_OUTPUT");
+      if (s == NULL || *s == '\0')
+        dup2 (dev_null_fd, 2);
+    }
+  else
+    {
+      fprintf (stderr, "Failed to open /dev/null: %s\n",
+               strerror (errno));
+      /* continue, why not */
+    }
+  
+  ret = fork ();
+
+  if (ret < 0)
+    {
+      fprintf (stderr, "fork() failed in babysitter: %s\n",
+               strerror (errno));
+      exit (1);
+    }
+
+  if (ret > 0)
+    {
+      /* Parent reaps pre-fork part of bus daemon, then exits and is
+       * reaped so the babysitter isn't a zombie
+       */
+
+      verbose ("=== Babysitter's intermediate parent continues again\n");
+      
+      if (do_waitpid (child_pid) < 0)
+        {
+          /* shouldn't happen */
+          fprintf (stderr, "Failed waitpid() waiting for bus daemon's parent\n");
+          exit (1);
+        }
+
+      verbose ("Babysitter's intermediate parent exiting\n");
+      
+      exit (0);
+    }
+
+  /* Child continues */
+  verbose ("=== Babysitter process created\n");
+
+  verbose ("Reading PID from bus\n");
+      
+  switch (read_pid (read_bus_pid_fd, &bus_pid_to_kill))
+    {
+    case READ_STATUS_OK:
+      break;
+    case READ_STATUS_EOF:
+      fprintf (stderr, "EOF in dbus-launch reading PID from bus daemon\n");
+      exit (1);
+      break;
+    case READ_STATUS_ERROR:
+      fprintf (stderr, "Error in dbus-launch reading PID from bus daemon: %s\n",
+	       strerror (errno));
+      exit (1);
+      break;
+    }
+
+  verbose ("Got PID %ld from daemon\n",
+           (long) bus_pid_to_kill);
+  
+  if (exit_with_session)
+    {
+      /* Bus is now started and launcher has needed info;
+       * we connect to X display and tty and wait to
+       * kill bus if requested.
+       */
+      
+      kill_bus_when_session_ends ();
+    }
+
+  verbose ("Babysitter exiting\n");
+  
+  exit (0);
+}
+
+static void
+do_close_stderr (void)
+{
+  int fd;
+
+  fflush (stderr);
+
+  /* dbus-launch is a Unix-only program, so we can rely on /dev/null being there.
+   * We're including unistd.h and we're dealing with sh/csh launch sequences...
+   */
+  fd = open ("/dev/null", O_RDWR);
+  if (fd == -1)
+    {
+      fprintf (stderr, "Internal error: cannot open /dev/null: %s", strerror (errno));
+      exit (1);
+    }
+
+  close (2);
+  if (dup2 (fd, 2) == -1)
+    {
+      /* error; we can't report an error anymore... */
+      exit (1);
+    }
+  close (fd);
+}
+
+static void
+pass_info (const char *runprog, const char *bus_address, pid_t bus_pid,
+           long bus_wid, int c_shell_syntax, int bourne_shell_syntax,
+           int binary_syntax,
+           int argc, char **argv, int remaining_args)
+{
+  if (runprog)
+    {
+      char *envvar;
+      char **args;
+      int i;
+
+      envvar = malloc (strlen ("DBUS_SESSION_BUS_ADDRESS=") +
+          strlen (bus_address) + 1);
+      args = malloc (sizeof (char *) * ((argc-remaining_args)+2));
+
+      if (envvar == NULL || args == NULL)
+        goto oom;
+
+     args[0] = xstrdup (runprog);
+      if (!args[0])
+        goto oom;
+     for (i = 1; i <= (argc-remaining_args); i++)
+      {
+        size_t len = strlen (argv[remaining_args+i-1])+1;
+        args[i] = malloc (len);
+        if (!args[i])
+          goto oom;
+        strncpy (args[i], argv[remaining_args+i-1], len);
+       }
+     args[i] = NULL;
+
+     strcpy (envvar, "DBUS_SESSION_BUS_ADDRESS=");
+     strcat (envvar, bus_address);
+     putenv (envvar);
+
+     execvp (runprog, args);
+     fprintf (stderr, "Couldn't exec %s: %s\n", runprog, strerror (errno));
+     exit (1);
+    }
+   else
+    {
+      print_variables (bus_address, bus_pid, bus_wid, c_shell_syntax,
+         bourne_shell_syntax, binary_syntax);
+    }
+  verbose ("dbus-launch exiting\n");
+
+  fflush (stdout);
+  fflush (stderr);
+  close (1);
+  close (2);
+  exit (0);
+oom:
+  fprintf (stderr, "Out of memory!");
+  exit (1);
+}
+
+#define READ_END  0
+#define WRITE_END 1
+
+int
+main (int argc, char **argv)
+{
+  const char *prev_arg;
+  const char *shname;
+  const char *runprog = NULL;
+  int remaining_args = 0;
+  int exit_with_session;
+  int binary_syntax = FALSE;
+  int c_shell_syntax = FALSE;
+  int bourne_shell_syntax = FALSE;
+  int auto_shell_syntax = FALSE;
+  int autolaunch = FALSE;
+  int requires_arg = FALSE;
+  int close_stderr = FALSE;
+  int i;
+  int ret;
+  int bus_pid_to_launcher_pipe[2];
+  int bus_pid_to_babysitter_pipe[2];
+  int bus_address_to_launcher_pipe[2];
+  char *config_file;
+  
+  exit_with_session = FALSE;
+  config_file = NULL;
+  
+  prev_arg = NULL;
+  i = 1;
+  while (i < argc)
+    {
+      const char *arg = argv[i];
+ 
+      if (strcmp (arg, "--help") == 0 ||
+          strcmp (arg, "-h") == 0 ||
+          strcmp (arg, "-?") == 0)
+        usage (0);
+      else if (strcmp (arg, "--auto-syntax") == 0)
+        auto_shell_syntax = TRUE;
+      else if (strcmp (arg, "-c") == 0 ||
+               strcmp (arg, "--csh-syntax") == 0)
+        c_shell_syntax = TRUE;
+      else if (strcmp (arg, "-s") == 0 ||
+               strcmp (arg, "--sh-syntax") == 0)
+        bourne_shell_syntax = TRUE;
+      else if (strcmp (arg, "--binary-syntax") == 0)
+        binary_syntax = TRUE;
+      else if (strcmp (arg, "--version") == 0)
+        version ();
+      else if (strcmp (arg, "--exit-with-session") == 0)
+        exit_with_session = TRUE;
+      else if (strcmp (arg, "--close-stderr") == 0)
+        close_stderr = TRUE;
+      else if (strstr (arg, "--autolaunch=") == arg)
+        {
+          const char *s;
+
+          if (autolaunch)
+            {
+              fprintf (stderr, "--autolaunch given twice\n");
+              exit (1);
+            }
+          
+          autolaunch = TRUE;
+
+          s = strchr (arg, '=');
+          ++s;
+
+          save_machine_uuid (s);
+        }
+      else if (prev_arg &&
+               strcmp (prev_arg, "--autolaunch") == 0)
+        {
+          if (autolaunch)
+            {
+              fprintf (stderr, "--autolaunch given twice\n");
+              exit (1);
+            }
+          
+          autolaunch = TRUE;
+
+          save_machine_uuid (arg);
+	  requires_arg = FALSE;
+        }
+      else if (strcmp (arg, "--autolaunch") == 0)
+	requires_arg = TRUE;
+      else if (strstr (arg, "--config-file=") == arg)
+        {
+          const char *file;
+
+          if (config_file != NULL)
+            {
+              fprintf (stderr, "--config-file given twice\n");
+              exit (1);
+            }
+          
+          file = strchr (arg, '=');
+          ++file;
+
+          config_file = xstrdup (file);
+        }
+      else if (prev_arg &&
+               strcmp (prev_arg, "--config-file") == 0)
+        {
+          if (config_file != NULL)
+            {
+              fprintf (stderr, "--config-file given twice\n");
+              exit (1);
+            }
+
+          config_file = xstrdup (arg);
+	  requires_arg = FALSE;
+        }
+      else if (strcmp (arg, "--config-file") == 0)
+	requires_arg = TRUE;
+      else if (arg[0] == '-')
+        {
+          if (strcmp (arg, "--") != 0)
+            {
+              fprintf (stderr, "Option `%s' is unknown.\n", arg);
+              exit (1);
+            }
+          else
+            {
+              runprog = argv[i+1];
+              remaining_args = i+2;
+              break;
+            }
+        }
+      else
+	{
+	  runprog = arg;
+	  remaining_args = i+1;
+	  break;
+	}
+      
+      prev_arg = arg;
+      
+      ++i;
+    }
+  if (requires_arg)
+    {
+      fprintf (stderr, "Option `%s' requires an argument.\n", prev_arg);
+      exit (1);
+    }
+
+  if (auto_shell_syntax)
+    {
+      if ((shname = getenv ("SHELL")) != NULL)
+       {
+         if (!strncmp (shname + strlen (shname) - 3, "csh", 3))
+           c_shell_syntax = TRUE;
+         else
+           bourne_shell_syntax = TRUE;
+       }
+      else
+       bourne_shell_syntax = TRUE;
+    }  
+
+  if (exit_with_session)
+    verbose ("--exit-with-session enabled\n");
+
+  if (autolaunch)
+    {      
+#ifndef DBUS_BUILD_X11
+      fprintf (stderr, "Autolaunch requested, but X11 support not compiled in.\n"
+	       "Cannot continue.\n");
+      exit (1);
+#else
+      char *address;
+      pid_t pid;
+      long wid;
+      
+      if (get_machine_uuid () == NULL)
+        {
+          fprintf (stderr, "Machine UUID not provided as arg to --autolaunch\n");
+          exit (1);
+        }
+
+      verbose ("Autolaunch enabled (using X11).\n");
+      if (!exit_with_session)
+	{
+	  verbose ("--exit-with-session automatically enabled\n");
+	  exit_with_session = TRUE;
+	}
+
+      if (!x11_init ())
+	{
+	  fprintf (stderr, "Autolaunch error: X11 initialization failed.\n");
+	  exit (1);
+	}
+
+      if (!x11_get_address (&address, &pid, &wid))
+	{
+	  fprintf (stderr, "Autolaunch error: X11 communication error.\n");
+	  exit (1);
+	}
+
+      if (address != NULL)
+	{
+	  verbose ("dbus-daemon is already running. Returning existing parameters.\n");
+	  pass_info (runprog, address, pid, wid, c_shell_syntax,
+			   bourne_shell_syntax, binary_syntax, argc, argv, remaining_args);
+	  exit (0);
+	}
+    }
+   else if (read_machine_uuid_if_needed())
+    {
+      x11_init();
+#endif
+    }
+
+
+  if (pipe (bus_pid_to_launcher_pipe) < 0 ||
+      pipe (bus_address_to_launcher_pipe) < 0 ||
+      pipe (bus_pid_to_babysitter_pipe) < 0)
+    {
+      fprintf (stderr,
+               "Failed to create pipe: %s\n",
+               strerror (errno));
+      exit (1);
+    }
+
+  ret = fork ();
+  if (ret < 0)
+    {
+      fprintf (stderr, "Failed to fork: %s\n",
+               strerror (errno));
+      exit (1);
+    }
+
+  if (ret == 0)
+    {
+      /* Child */
+#define MAX_FD_LEN 64
+      char write_pid_fd_as_string[MAX_FD_LEN];
+      char write_address_fd_as_string[MAX_FD_LEN];
+
+#ifdef DBUS_BUILD_X11
+      xdisplay = NULL;
+#endif
+
+      if (close_stderr)
+	do_close_stderr ();
+
+      verbose ("=== Babysitter's intermediate parent created\n");
+
+      /* Fork once more to create babysitter */
+      
+      ret = fork ();
+      if (ret < 0)
+        {
+          fprintf (stderr, "Failed to fork: %s\n",
+                   strerror (errno));
+          exit (1);
+        }
+      
+      if (ret > 0)
+        {
+          /* In babysitter */
+          verbose ("=== Babysitter's intermediate parent continues\n");
+          
+          close (bus_pid_to_launcher_pipe[READ_END]);
+	  close (bus_pid_to_launcher_pipe[WRITE_END]);
+          close (bus_address_to_launcher_pipe[READ_END]);
+          close (bus_address_to_launcher_pipe[WRITE_END]);
+          close (bus_pid_to_babysitter_pipe[WRITE_END]);
+
+          /* babysit() will fork *again*
+           * and will also reap the pre-forked bus
+           * daemon
+           */
+          babysit (exit_with_session, ret,
+                   bus_pid_to_babysitter_pipe[READ_END]);
+          exit (0);
+        }
+
+      verbose ("=== Bus exec process created\n");
+      
+      /* Now we are the bus process (well, almost;
+       * dbus-daemon itself forks again)
+       */
+      close (bus_pid_to_launcher_pipe[READ_END]);
+      close (bus_address_to_launcher_pipe[READ_END]);
+      close (bus_pid_to_babysitter_pipe[READ_END]);
+      close (bus_pid_to_babysitter_pipe[WRITE_END]);
+
+      sprintf (write_pid_fd_as_string,
+               "%d", bus_pid_to_launcher_pipe[WRITE_END]);
+
+      sprintf (write_address_fd_as_string,
+               "%d", bus_address_to_launcher_pipe[WRITE_END]);
+
+      verbose ("Calling exec()\n");
+ 
+#ifdef DBUS_BUILD_TESTS 
+      /* exec from testdir */
+      if (getenv("DBUS_USE_TEST_BINARY") != NULL)
+        {
+          execl (TEST_BUS_BINARY,
+                 TEST_BUS_BINARY,
+                 "--fork",
+                 "--print-pid", write_pid_fd_as_string,
+                 "--print-address", write_address_fd_as_string,
+                 config_file ? "--config-file" : "--session",
+                 config_file, /* has to be last in this varargs list */
+                 NULL); 
+
+          fprintf (stderr,
+                   "Failed to execute test message bus daemon %s: %s. Will try again with the system path.\n",
+                   TEST_BUS_BINARY, strerror (errno));
+        }
+ #endif /* DBUS_BUILD_TESTS */
+
+      execl (DBUS_DAEMONDIR"/dbus-daemon",
+             DBUS_DAEMONDIR"/dbus-daemon",
+             "--fork",
+             "--print-pid", write_pid_fd_as_string,
+             "--print-address", write_address_fd_as_string,
+             config_file ? "--config-file" : "--session",
+             config_file, /* has to be last in this varargs list */
+             NULL);
+
+      fprintf (stderr,
+               "Failed to execute message bus daemon %s: %s.  Will try again without full path.\n",
+               DBUS_DAEMONDIR"/dbus-daemon", strerror (errno));
+      
+      /*
+       * If it failed, try running without full PATH.  Note this is needed
+       * because the build process builds the run-with-tmp-session-bus.conf
+       * file and the dbus-daemon will not be in the install location during
+       * build time.
+       */
+      execlp ("dbus-daemon",
+              "dbus-daemon",
+              "--fork",
+              "--print-pid", write_pid_fd_as_string,
+              "--print-address", write_address_fd_as_string,
+              config_file ? "--config-file" : "--session",
+              config_file, /* has to be last in this varargs list */
+              NULL);
+
+      fprintf (stderr,
+               "Failed to execute message bus daemon: %s\n",
+               strerror (errno));
+      exit (1);
+    }
+  else
+    {
+      /* Parent */
+#define MAX_PID_LEN 64
+      pid_t bus_pid;  
+      char bus_address[MAX_ADDR_LEN];
+      char buf[MAX_PID_LEN];
+      char *end;
+      long wid = 0;
+      long val;
+      int ret2;
+
+      verbose ("=== Parent dbus-launch continues\n");
+      
+      close (bus_pid_to_launcher_pipe[WRITE_END]);
+      close (bus_address_to_launcher_pipe[WRITE_END]);
+      close (bus_pid_to_babysitter_pipe[READ_END]);
+
+      verbose ("Waiting for babysitter's intermediate parent\n");
+      
+      /* Immediately reap parent of babysitter
+       * (which was created just for us to reap)
+       */
+      if (do_waitpid (ret) < 0)
+        {
+          fprintf (stderr, "Failed to waitpid() for babysitter intermediate process: %s\n",
+                   strerror (errno));
+          exit (1);
+        }
+
+      verbose ("Reading address from bus\n");
+      
+      /* Read the pipe data, print, and exit */
+      switch (read_line (bus_address_to_launcher_pipe[READ_END],
+                         bus_address, MAX_ADDR_LEN))
+        {
+        case READ_STATUS_OK:
+          break;
+        case READ_STATUS_EOF:
+          fprintf (stderr, "EOF in dbus-launch reading address from bus daemon\n");
+          exit (1);
+          break;
+        case READ_STATUS_ERROR:
+          fprintf (stderr, "Error in dbus-launch reading address from bus daemon: %s\n",
+                   strerror (errno));
+          exit (1);
+          break;
+        }
+        
+      close (bus_address_to_launcher_pipe[READ_END]);
+
+      verbose ("Reading PID from daemon\n");
+      /* Now read data */
+      switch (read_line (bus_pid_to_launcher_pipe[READ_END], buf, MAX_PID_LEN))
+	{
+	case READ_STATUS_OK:
+	  break;
+	case READ_STATUS_EOF:
+	  fprintf (stderr, "EOF reading PID from bus daemon\n");
+	  exit (1);
+	  break;
+	case READ_STATUS_ERROR:
+	  fprintf (stderr, "Error reading PID from bus daemon: %s\n",
+		   strerror (errno));
+	  exit (1);
+	  break;
+	}
+
+      end = NULL;
+      val = strtol (buf, &end, 0);
+      if (buf == end || end == NULL)
+	{
+	  fprintf (stderr, "Failed to parse bus PID \"%s\": %s\n",
+		   buf, strerror (errno));
+	  exit (1);
+	}
+
+      bus_pid = val;
+
+      close (bus_pid_to_launcher_pipe[READ_END]);
+
+#ifdef DBUS_BUILD_X11
+      if (xdisplay != NULL)
+        {
+          verbose("Saving x11 address\n");
+          ret2 = x11_save_address (bus_address, bus_pid, &wid);
+          /* Only get an existing dbus session when autolaunching */
+          if (autolaunch)
+            {
+              if (ret2 == 0)
+                {
+                  char *address = NULL;
+                  /* another window got added. Return its address */
+                  bus_pid_to_kill = bus_pid;
+                  if (x11_get_address (&address, &bus_pid, &wid)
+                       && address != NULL)
+                    {
+                      verbose ("dbus-daemon is already running. Returning existing parameters.\n");
+                      /* Kill the old bus */
+                      kill_bus();
+                      pass_info (runprog, address, bus_pid, wid,
+                         c_shell_syntax, bourne_shell_syntax, binary_syntax,
+                         argc, argv, remaining_args);
+                    }
+                  }
+              if (ret2 < 0)
+                {
+                  fprintf (stderr, "Error saving bus information.\n");
+                  bus_pid_to_kill = bus_pid;
+                  kill_bus_and_exit (1);
+                }
+            }
+        }
+#endif
+
+      /* Forward the pid to the babysitter */
+      write_pid (bus_pid_to_babysitter_pipe[WRITE_END], bus_pid);
+      close (bus_pid_to_babysitter_pipe[WRITE_END]);
+
+       pass_info (runprog, bus_address, bus_pid, wid, c_shell_syntax,
+              bourne_shell_syntax, binary_syntax, argc, argv, remaining_args);
+    }
+
+  return 0;
+}
diff --git a/jni/dbus/tools/dbus-launch.h b/jni/dbus/tools/dbus-launch.h
new file mode 100644
index 0000000..8220bb8
--- /dev/null
+++ b/jni/dbus/tools/dbus-launch.h
@@ -0,0 +1,57 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-launch.h  dbus-launch utility
+ *
+ * Copyright (C) 2006 Thiago Macieira <thiago@kde.org>
+ *
+ * Licensed under the Academic Free License version 2.1
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifndef DBUS_LAUNCH_H
+#define DBUS_LAUNCH_H
+
+#include <sys/types.h>
+
+#ifndef TRUE
+#define TRUE (1)
+#endif
+
+#ifndef FALSE
+#define FALSE (0)
+#endif
+
+#undef  MAX
+#define MAX(a, b)  (((a) > (b)) ? (a) : (b))
+
+#define MAX_ADDR_LEN 512
+
+/* defined in dbus-launch.c */
+void verbose (const char *format, ...);
+char *xstrdup (const char *str);
+void kill_bus_and_exit (int exitcode);
+
+const char* get_machine_uuid (void);
+
+#ifdef DBUS_BUILD_X11
+/* defined in dbus-launch-x11.c */
+int x11_init (void);
+int x11_get_address (char **paddress, pid_t *pid, long *wid);
+int x11_save_address (char *address, pid_t pid, long *wid);
+void x11_handle_event (void);
+#endif
+
+#endif
diff --git a/jni/dbus/tools/dbus-monitor.1 b/jni/dbus/tools/dbus-monitor.1
new file mode 100644
index 0000000..c24c14d
--- /dev/null
+++ b/jni/dbus/tools/dbus-monitor.1
@@ -0,0 +1,78 @@
+.\" 
+.\" dbus-monitor manual page.
+.\" Copyright (C) 2003 Red Hat, Inc.
+.\"
+.TH dbus-monitor 1
+.SH NAME
+dbus-monitor \- debug probe to print message bus messages
+.SH SYNOPSIS
+.PP
+.B dbus-monitor
+[\-\-system | \-\-session | \-\-address ADDRESS] [\-\-profile | \-\-monitor]
+[watch expressions]
+
+.SH DESCRIPTION
+
+The \fIdbus-monitor\fP command is used to monitor messages going
+through a D-Bus message bus.  See
+http://www.freedesktop.org/software/dbus/ for more information about
+the big picture.
+
+.PP
+There are two well-known message buses: the systemwide message bus
+(installed on many systems as the "messagebus" service) and the
+per-user-login-session message bus (started each time a user logs in).
+The \-\-system and \-\-session options direct \fIdbus-monitor\fP to
+monitor the system or session buses respectively.  If neither is
+specified, \fIdbus-monitor\fP monitors the session bus.
+
+.PP
+\fIdbus-monitor\fP has two different output modes, the 'classic'-style
+monitoring mode and profiling mode. The profiling format is a compact
+format with a single line per message and microsecond-resolution timing
+information. The \-\-profile and \-\-monitor options select the profiling
+and monitoring output format respectively. If neither is specified,
+\fIdbus-monitor\fP uses the monitoring output format.
+
+.PP
+In order to get \fIdbus-monitor\fP to see the messages you are interested
+in, you should specify a set of watch expressions as you would expect to
+be passed to the \fIdbus_bus_add_match\fP function.
+
+.PP 
+The message bus configuration may keep \fIdbus-monitor\fP from seeing
+all messages, especially if you run the monitor as a non-root user.
+
+.SH OPTIONS
+.TP
+.I "--system"
+Monitor the system message bus.
+.TP
+.I "--session"
+Monitor the session message bus.  (This is the default.)
+.TP
+.I "--address ADDRESS"
+Monitor an arbitrary message bus given at ADDRESS.
+.TP
+.I "--profile"
+Use the profiling output format.
+.TP
+.I "--monitor"
+Use the monitoring output format.  (This is the default.)
+
+.SH EXAMPLE
+Here is an example of using dbus-monitor to watch for the gnome typing
+monitor to say things
+.nf
+
+  dbus-monitor "type='signal',sender='org.gnome.TypingMonitor',interface='org.gnome.TypingMonitor'"
+
+.fi
+
+.SH AUTHOR
+dbus-monitor was written by Philip Blundell.
+The profiling output mode was added by Olli Salli.
+
+.SH BUGS
+Please send bug reports to the D-Bus mailing list or bug tracker,
+see http://www.freedesktop.org/software/dbus/
diff --git a/jni/dbus/tools/dbus-monitor.c b/jni/dbus/tools/dbus-monitor.c
new file mode 100644
index 0000000..d20faa5
--- /dev/null
+++ b/jni/dbus/tools/dbus-monitor.c
@@ -0,0 +1,377 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-monitor.c  Utility program to monitor messages on the bus
+ *
+ * Copyright (C) 2003 Philip Blundell <philb@gnu.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef DBUS_WIN
+#include <winsock2.h>
+#undef interface
+#else
+#include <sys/time.h>
+#endif
+
+#include <time.h>
+
+#include "dbus-print-message.h"
+
+#ifdef DBUS_WIN
+
+/* gettimeofday is not defined on windows */
+#define DBUS_SECONDS_SINCE_1601 11644473600LL
+#define DBUS_USEC_IN_SEC        1000000LL
+
+#ifdef DBUS_WINCE
+
+#ifndef _IOLBF
+#define _IOLBF 0x40
+#endif
+#ifndef _IONBF
+#define _IONBF 0x04
+#endif
+
+void
+GetSystemTimeAsFileTime (LPFILETIME ftp)
+{
+  SYSTEMTIME st;
+  GetSystemTime (&st);
+  SystemTimeToFileTime (&st, ftp);
+}
+#endif
+
+static int
+gettimeofday (struct timeval *__p,
+	      void *__t)
+{
+  union {
+      unsigned long long ns100; /*time since 1 Jan 1601 in 100ns units */
+      FILETIME           ft;
+    } now;
+
+  GetSystemTimeAsFileTime (&now.ft);
+  __p->tv_usec = (long) ((now.ns100 / 10LL) % DBUS_USEC_IN_SEC);
+  __p->tv_sec  = (long)(((now.ns100 / 10LL) / DBUS_SECONDS_SINCE_1601) - DBUS_SECONDS_SINCE_1601);
+
+  return 0;
+}
+#endif
+
+static DBusHandlerResult
+monitor_filter_func (DBusConnection     *connection,
+		     DBusMessage        *message,
+		     void               *user_data)
+{
+  print_message (message, FALSE);
+  
+  if (dbus_message_is_signal (message,
+                              DBUS_INTERFACE_LOCAL,
+                              "Disconnected"))
+    exit (0);
+  
+  /* Conceptually we want this to be
+   * DBUS_HANDLER_RESULT_NOT_YET_HANDLED, but this raises
+   * some problems.  See bug 1719.
+   */
+  return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+#define PROFILE_TIMED_FORMAT "%s\t%lu\t%lu"
+#define TRAP_NULL_STRING(str) ((str) ? (str) : "<none>")
+
+typedef enum
+{
+  PROFILE_ATTRIBUTE_FLAG_SERIAL = 1,
+  PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL = 2,
+  PROFILE_ATTRIBUTE_FLAG_SENDER = 4,
+  PROFILE_ATTRIBUTE_FLAG_DESTINATION = 8,
+  PROFILE_ATTRIBUTE_FLAG_PATH = 16,
+  PROFILE_ATTRIBUTE_FLAG_INTERFACE = 32,
+  PROFILE_ATTRIBUTE_FLAG_MEMBER = 64,
+  PROFILE_ATTRIBUTE_FLAG_ERROR_NAME = 128
+} ProfileAttributeFlags;
+
+static void
+profile_print_with_attrs (const char *type, DBusMessage *message,
+  struct timeval *t, ProfileAttributeFlags attrs)
+{
+  printf (PROFILE_TIMED_FORMAT, type, t->tv_sec, t->tv_usec);
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_SERIAL)
+    printf ("\t%u", dbus_message_get_serial (message));
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL)
+    printf ("\t%u", dbus_message_get_reply_serial (message));
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_SENDER)
+    printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_sender (message)));
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_DESTINATION)
+    printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_destination (message)));
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_PATH)
+    printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_path (message)));
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_INTERFACE)
+    printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_interface (message)));
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_MEMBER)
+    printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_member (message)));
+
+  if (attrs & PROFILE_ATTRIBUTE_FLAG_ERROR_NAME)
+    printf ("\t%s", TRAP_NULL_STRING (dbus_message_get_error_name (message)));
+
+  printf ("\n");
+}
+
+static void
+print_message_profile (DBusMessage *message)
+{
+  struct timeval t;
+
+  if (gettimeofday (&t, NULL) < 0)
+    {
+      printf ("un\n");
+      return;
+    }
+
+  switch (dbus_message_get_type (message))
+    {
+      case DBUS_MESSAGE_TYPE_METHOD_CALL:
+	profile_print_with_attrs ("mc", message, &t,
+	  PROFILE_ATTRIBUTE_FLAG_SERIAL |
+	  PROFILE_ATTRIBUTE_FLAG_SENDER |
+	  PROFILE_ATTRIBUTE_FLAG_PATH |
+	  PROFILE_ATTRIBUTE_FLAG_INTERFACE |
+	  PROFILE_ATTRIBUTE_FLAG_MEMBER);
+	break;
+      case DBUS_MESSAGE_TYPE_METHOD_RETURN:
+	profile_print_with_attrs ("mr", message, &t,
+	  PROFILE_ATTRIBUTE_FLAG_SERIAL |
+	  PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+	  PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
+	break;
+      case DBUS_MESSAGE_TYPE_ERROR:
+	profile_print_with_attrs ("err", message, &t,
+	  PROFILE_ATTRIBUTE_FLAG_SERIAL |
+	  PROFILE_ATTRIBUTE_FLAG_DESTINATION |
+	  PROFILE_ATTRIBUTE_FLAG_REPLY_SERIAL);
+	break;
+      case DBUS_MESSAGE_TYPE_SIGNAL:
+	profile_print_with_attrs ("sig", message, &t,
+	  PROFILE_ATTRIBUTE_FLAG_SERIAL |
+	  PROFILE_ATTRIBUTE_FLAG_PATH |
+	  PROFILE_ATTRIBUTE_FLAG_INTERFACE |
+	  PROFILE_ATTRIBUTE_FLAG_MEMBER);
+	break;
+      default:
+	printf (PROFILE_TIMED_FORMAT "\n", "tun", t.tv_sec, t.tv_usec);
+	break;
+    }
+}
+
+static DBusHandlerResult
+profile_filter_func (DBusConnection	*connection,
+		     DBusMessage	*message,
+		     void		*user_data)
+{
+  print_message_profile (message);
+
+  if (dbus_message_is_signal (message,
+                              DBUS_INTERFACE_LOCAL,
+                              "Disconnected"))
+    exit (0);
+
+  return DBUS_HANDLER_RESULT_HANDLED;
+}
+
+static void
+usage (char *name, int ecode)
+{
+  fprintf (stderr, "Usage: %s [--system | --session | --address ADDRESS] [--monitor | --profile ] [watch expressions]\n", name);
+  exit (ecode);
+}
+
+static dbus_bool_t sigint_received = FALSE;
+
+static void
+sigint_handler (int signum)
+{
+  sigint_received = TRUE;
+}
+
+int
+main (int argc, char *argv[])
+{
+  DBusConnection *connection;
+  DBusError error;
+  DBusBusType type = DBUS_BUS_SESSION;
+  DBusHandleMessageFunction filter_func = monitor_filter_func;
+  char *address = NULL;
+  
+  int i = 0, j = 0, numFilters = 0;
+  char **filters = NULL;
+
+  /* Set stdout to be unbuffered; this is basically so that if people
+   * do dbus-monitor > file, then send SIGINT via Control-C, they
+   * don't lose the last chunk of messages.
+   */
+
+#ifdef DBUS_WIN
+  setvbuf (stdout, NULL, _IONBF, 0);
+#else
+  setvbuf (stdout, NULL, _IOLBF, 0);
+#endif
+
+  for (i = 1; i < argc; i++)
+    {
+      char *arg = argv[i];
+
+      if (!strcmp (arg, "--system"))
+	type = DBUS_BUS_SYSTEM;
+      else if (!strcmp (arg, "--session"))
+	type = DBUS_BUS_SESSION;
+      else if (!strcmp (arg, "--address"))
+	{
+	  if (i+1 < argc)
+	    {
+	      address = argv[i+1];
+	      i++;
+	    }
+	  else
+	    usage (argv[0], 1);
+	}
+      else if (!strcmp (arg, "--help"))
+	usage (argv[0], 0);
+      else if (!strcmp (arg, "--monitor"))
+	filter_func = monitor_filter_func;
+      else if (!strcmp (arg, "--profile"))
+	filter_func = profile_filter_func;
+      else if (!strcmp (arg, "--"))
+	continue;
+      else if (arg[0] == '-')
+	usage (argv[0], 1);
+      else {
+	numFilters++;
+       filters = (char **)realloc(filters, numFilters * sizeof(char *));
+	filters[j] = (char *)malloc((strlen(arg) + 1) * sizeof(char *));
+	snprintf(filters[j], strlen(arg) + 1, "%s", arg);
+	j++;
+      }
+    }
+
+  dbus_error_init (&error);
+  
+  if (address != NULL)
+    {
+      connection = dbus_connection_open (address, &error);
+      if (connection)
+        {
+          if (!dbus_bus_register (connection, &error))
+      	    {
+              fprintf (stderr, "Failed to register connection to bus at %s: %s\n",
+      	               address, error.message);
+              dbus_error_free (&error);
+              exit (1);
+      	    }
+        }
+    }
+  else
+    connection = dbus_bus_get (type, &error);
+  if (connection == NULL)
+    {
+      const char *where;
+      if (address != NULL)
+        where = address;
+      else
+        {
+          switch (type)
+            {
+            case DBUS_BUS_SYSTEM:
+              where = "system bus";
+              break;
+            case DBUS_BUS_SESSION:
+              where = "session bus";
+              break;
+            default:
+              where = "";
+            }
+        }
+      fprintf (stderr, "Failed to open connection to %s: %s\n",
+               where,
+               error.message);
+      dbus_error_free (&error);
+      exit (1);
+    }
+
+  if (numFilters)
+    {
+      for (i = 0; i < j; i++)
+        {
+          dbus_bus_add_match (connection, filters[i], &error);
+          if (dbus_error_is_set (&error))
+            {
+              fprintf (stderr, "Failed to setup match \"%s\": %s\n",
+                       filters[i], error.message);
+              dbus_error_free (&error);
+              exit (1);
+            }
+	  free(filters[i]);
+        }
+    }
+  else
+    {
+      dbus_bus_add_match (connection,
+		          "type='signal'",
+		          &error);
+      if (dbus_error_is_set (&error))
+        goto lose;
+      dbus_bus_add_match (connection,
+		          "type='method_call'",
+		          &error);
+      if (dbus_error_is_set (&error))
+        goto lose;
+      dbus_bus_add_match (connection,
+		          "type='method_return'",
+		          &error);
+      if (dbus_error_is_set (&error))
+        goto lose;
+      dbus_bus_add_match (connection,
+		          "type='error'",
+		          &error);
+      if (dbus_error_is_set (&error))
+        goto lose;
+    }
+
+  if (!dbus_connection_add_filter (connection, filter_func, NULL, NULL)) {
+    fprintf (stderr, "Couldn't add filter!\n");
+    exit (1);
+  }
+
+  while (dbus_connection_read_write_dispatch(connection, -1))
+    ;
+  exit (0);
+ lose:
+  fprintf (stderr, "Error: %s\n", error.message);
+  exit (1);
+}
+
diff --git a/jni/dbus/tools/dbus-print-message.c b/jni/dbus/tools/dbus-print-message.c
new file mode 100644
index 0000000..75d00ac
--- /dev/null
+++ b/jni/dbus/tools/dbus-print-message.c
@@ -0,0 +1,409 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-print-message.h  Utility function to print out a message
+ *
+ * Copyright (C) 2003 Philip Blundell <philb@gnu.org>
+ * Copyright (C) 2003 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include "dbus-print-message.h"
+
+#include <stdlib.h>
+#include "config.h"
+
+static const char*
+type_to_name (int message_type)
+{
+  switch (message_type)
+    {
+    case DBUS_MESSAGE_TYPE_SIGNAL:
+      return "signal";
+    case DBUS_MESSAGE_TYPE_METHOD_CALL:
+      return "method call";
+    case DBUS_MESSAGE_TYPE_METHOD_RETURN:
+      return "method return";
+    case DBUS_MESSAGE_TYPE_ERROR:
+      return "error";
+    default:
+      return "(unknown message type)";
+    }
+}
+
+#define INDENT 3
+
+static void
+indent (int depth)
+{
+  while (depth-- > 0)
+    printf ("   "); /* INDENT spaces. */
+}
+
+static void
+print_hex (unsigned char *bytes, unsigned int len, int depth)
+{
+  unsigned int i, columns;
+
+  printf ("array of bytes [\n");
+
+  indent (depth + 1);
+
+  /* Each byte takes 3 cells (two hexits, and a space), except the last one. */
+  columns = (80 - ((depth + 1) * INDENT)) / 3;
+
+  if (columns < 8)
+    columns = 8;
+
+  i = 0;
+
+  while (i < len)
+    {
+      printf ("%02x", bytes[i]);
+      i++;
+
+      if (i != len)
+        {
+          if (i % columns == 0)
+            {
+              printf ("\n");
+              indent (depth + 1);
+            }
+          else
+            {
+              printf (" ");
+            }
+        }
+    }
+
+  printf ("\n");
+  indent (depth);
+  printf ("]\n");
+}
+
+#define DEFAULT_SIZE 100
+
+static void
+print_ay (DBusMessageIter *iter, int depth)
+{
+  /* Not using DBusString because it's not public API. It's 2009, and I'm
+   * manually growing a string chunk by chunk.
+   */
+  unsigned char *bytes = malloc (DEFAULT_SIZE + 1);
+  unsigned int len = 0;
+  unsigned int max = DEFAULT_SIZE;
+  dbus_bool_t all_ascii = TRUE;
+  int current_type;
+
+  while ((current_type = dbus_message_iter_get_arg_type (iter))
+          != DBUS_TYPE_INVALID)
+    {
+      unsigned char val;
+
+      dbus_message_iter_get_basic (iter, &val);
+      bytes[len] = val;
+      len++;
+
+      if (val < 32 || val > 126)
+        all_ascii = FALSE;
+
+      if (len == max)
+        {
+          max *= 2;
+          bytes = realloc (bytes, max + 1);
+        }
+
+      dbus_message_iter_next (iter);
+    }
+
+  if (all_ascii)
+    {
+      bytes[len] = '\0';
+      printf ("array of bytes \"%s\"\n", bytes);
+    }
+  else
+    {
+      print_hex (bytes, len, depth);
+    }
+
+  free (bytes);
+}
+
+static void
+print_iter (DBusMessageIter *iter, dbus_bool_t literal, int depth)
+{
+  do
+    {
+      int type = dbus_message_iter_get_arg_type (iter);
+
+      if (type == DBUS_TYPE_INVALID)
+	break;
+      
+      indent(depth);
+
+      switch (type)
+	{
+	case DBUS_TYPE_STRING:
+	  {
+	    char *val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    if (!literal)
+	      printf ("string \"");
+	    printf ("%s", val);
+	    if (!literal)
+	      printf ("\"\n");
+	    break;
+	  }
+
+	case DBUS_TYPE_SIGNATURE:
+	  {
+	    char *val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    if (!literal)
+	      printf ("signature \"");
+	    printf ("%s", val);
+	    if (!literal)
+	      printf ("\"\n");
+	    break;
+	  }
+
+	case DBUS_TYPE_OBJECT_PATH:
+	  {
+	    char *val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    if (!literal)
+	      printf ("object path \"");
+	    printf ("%s", val);
+	    if (!literal)
+	      printf ("\"\n");
+	    break;
+	  }
+
+	case DBUS_TYPE_INT16:
+	  {
+	    dbus_int16_t val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    printf ("int16 %d\n", val);
+	    break;
+	  }
+
+	case DBUS_TYPE_UINT16:
+	  {
+	    dbus_uint16_t val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    printf ("uint16 %u\n", val);
+	    break;
+	  }
+
+	case DBUS_TYPE_INT32:
+	  {
+	    dbus_int32_t val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    printf ("int32 %d\n", val);
+	    break;
+	  }
+
+	case DBUS_TYPE_UINT32:
+	  {
+	    dbus_uint32_t val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    printf ("uint32 %u\n", val);
+	    break;
+	  }
+
+	case DBUS_TYPE_INT64:
+	  {
+	    dbus_int64_t val;
+	    dbus_message_iter_get_basic (iter, &val);
+#ifdef DBUS_INT64_PRINTF_MODIFIER
+        printf ("int64 %" DBUS_INT64_PRINTF_MODIFIER "d\n", val);
+#else
+        printf ("int64 (omitted)\n");
+#endif
+	    break;
+	  }
+
+	case DBUS_TYPE_UINT64:
+	  {
+	    dbus_uint64_t val;
+	    dbus_message_iter_get_basic (iter, &val);
+#ifdef DBUS_INT64_PRINTF_MODIFIER
+        printf ("uint64 %" DBUS_INT64_PRINTF_MODIFIER "u\n", val);
+#else
+        printf ("uint64 (omitted)\n");
+#endif
+	    break;
+	  }
+
+	case DBUS_TYPE_DOUBLE:
+	  {
+	    double val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    printf ("double %g\n", val);
+	    break;
+	  }
+
+	case DBUS_TYPE_BYTE:
+	  {
+	    unsigned char val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    printf ("byte %d\n", val);
+	    break;
+	  }
+
+	case DBUS_TYPE_BOOLEAN:
+	  {
+	    dbus_bool_t val;
+	    dbus_message_iter_get_basic (iter, &val);
+	    printf ("boolean %s\n", val ? "true" : "false");
+	    break;
+	  }
+
+	case DBUS_TYPE_VARIANT:
+	  {
+	    DBusMessageIter subiter;
+
+	    dbus_message_iter_recurse (iter, &subiter);
+
+	    printf ("variant ");
+	    print_iter (&subiter, literal, depth+1);
+	    break;
+	  }
+	case DBUS_TYPE_ARRAY:
+	  {
+	    int current_type;
+	    DBusMessageIter subiter;
+
+	    dbus_message_iter_recurse (iter, &subiter);
+
+	    current_type = dbus_message_iter_get_arg_type (&subiter);
+
+	    if (current_type == DBUS_TYPE_BYTE)
+	      {
+		print_ay (&subiter, depth);
+		break;
+	      }
+
+	    printf("array [\n");
+	    while (current_type != DBUS_TYPE_INVALID)
+	      {
+		print_iter (&subiter, literal, depth+1);
+
+		dbus_message_iter_next (&subiter);
+		current_type = dbus_message_iter_get_arg_type (&subiter);
+
+		if (current_type != DBUS_TYPE_INVALID)
+		  printf (",");
+	      }
+	    indent(depth);
+	    printf("]\n");
+	    break;
+	  }
+	case DBUS_TYPE_DICT_ENTRY:
+	  {
+	    DBusMessageIter subiter;
+
+	    dbus_message_iter_recurse (iter, &subiter);
+
+	    printf("dict entry(\n");
+	    print_iter (&subiter, literal, depth+1);
+	    dbus_message_iter_next (&subiter);
+	    print_iter (&subiter, literal, depth+1);
+	    indent(depth);
+	    printf(")\n");
+	    break;
+	  }
+	    
+	case DBUS_TYPE_STRUCT:
+	  {
+	    int current_type;
+	    DBusMessageIter subiter;
+
+	    dbus_message_iter_recurse (iter, &subiter);
+
+	    printf("struct {\n");
+	    while ((current_type = dbus_message_iter_get_arg_type (&subiter)) != DBUS_TYPE_INVALID)
+	      {
+		print_iter (&subiter, literal, depth+1);
+		dbus_message_iter_next (&subiter);
+		if (dbus_message_iter_get_arg_type (&subiter) != DBUS_TYPE_INVALID)
+		  printf (",");
+	      }
+	    indent(depth);
+	    printf("}\n");
+	    break;
+	  }
+	    
+	default:
+	  printf (" (dbus-monitor too dumb to decipher arg type '%c')\n", type);
+	  break;
+	}
+    } while (dbus_message_iter_next (iter));
+}
+
+void
+print_message (DBusMessage *message, dbus_bool_t literal)
+{
+  DBusMessageIter iter;
+  const char *sender;
+  const char *destination;
+  int message_type;
+
+  message_type = dbus_message_get_type (message);
+  sender = dbus_message_get_sender (message);
+  destination = dbus_message_get_destination (message);
+  
+  if (!literal)
+    {
+      printf ("%s sender=%s -> dest=%s",
+	      type_to_name (message_type),
+	      sender ? sender : "(null sender)",
+	      destination ? destination : "(null destination)");
+  
+      switch (message_type)
+	{
+	case DBUS_MESSAGE_TYPE_METHOD_CALL:
+	case DBUS_MESSAGE_TYPE_SIGNAL:
+	  printf (" serial=%u path=%s; interface=%s; member=%s\n",
+                  dbus_message_get_serial (message),
+		  dbus_message_get_path (message),
+		  dbus_message_get_interface (message),
+		  dbus_message_get_member (message));
+	  break;
+      
+	case DBUS_MESSAGE_TYPE_METHOD_RETURN:
+	  printf (" reply_serial=%u\n",
+          dbus_message_get_reply_serial (message));
+	  break;
+
+	case DBUS_MESSAGE_TYPE_ERROR:
+	  printf (" error_name=%s reply_serial=%u\n",
+		  dbus_message_get_error_name (message),
+          dbus_message_get_reply_serial (message));
+	  break;
+
+	default:
+	  printf ("\n");
+	  break;
+	}
+    }
+
+  dbus_message_iter_init (message, &iter);
+  print_iter (&iter, literal, 1);
+  fflush (stdout);
+  
+}
+
diff --git a/jni/dbus/tools/dbus-print-message.h b/jni/dbus/tools/dbus-print-message.h
new file mode 100644
index 0000000..26700d8
--- /dev/null
+++ b/jni/dbus/tools/dbus-print-message.h
@@ -0,0 +1,31 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-print-message.h  Utility function to print out a message
+ *
+ * Copyright (C) 2003 Philip Blundell <philb@gnu.org>
+ * Copyright (C) 2003 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+#ifndef DBUS_PRINT_MESSAGE_H
+#define DBUS_PRINT_MESSAGE_H
+
+#include <stdio.h>
+#include <string.h>
+#include <dbus/dbus.h>
+
+void print_message (DBusMessage *message, dbus_bool_t literal);
+
+#endif /* DBUS_PRINT_MESSAGE_H */
diff --git a/jni/dbus/tools/dbus-send.1 b/jni/dbus/tools/dbus-send.1
new file mode 100644
index 0000000..4878c3d
--- /dev/null
+++ b/jni/dbus/tools/dbus-send.1
@@ -0,0 +1,95 @@
+.\" 
+.\" dbus-send manual page.
+.\" Copyright (C) 2003 Red Hat, Inc.
+.\"
+.TH dbus-send 1
+.SH NAME
+dbus-send \- Send a message to a message bus
+.SH SYNOPSIS
+.PP
+.B dbus-send
+[\-\-system | \-\-session] [\-\-dest=NAME] [\-\-print-reply]
+[\-\-type=TYPE] <destination object path> <message name> [contents ...]
+
+.SH DESCRIPTION
+
+The \fIdbus-send\fP command is used to send a message to a D-Bus message
+bus. See http://www.freedesktop.org/software/dbus/ for more 
+information about the big picture.
+
+.PP
+There are two well-known message buses: the systemwide message bus 
+(installed on many systems as the "messagebus" service) and the 
+per-user-login-session message bus (started each time a user logs in).
+The \-\-system and \-\-session options direct \fIdbus-send\fP to send
+messages to the system or session buses respectively.  If neither is
+specified, \fIdbus-send\fP sends to the session bus.
+
+.PP 
+Nearly all uses of \fIdbus-send\fP must provide the \-\-dest argument
+which is the name of a connection on the bus to send the message to. If
+\-\-dest is omitted, no destination is set.
+
+.PP
+The object path and the name of the message to send must always be
+specified. Following arguments, if any, are the message contents
+(message arguments).  These are given as type-specified values and 
+may include containers (arrays, dicts, and variants) as described below.
+
+.nf
+<contents>   ::= <item> | <container> [ <item> | <container>...]
+<item>       ::= <type>:<value>
+<container>  ::= <array> | <dict> | <variant>
+<array>      ::= array:<type>:<value>[,<value>...] 
+<dict>       ::= dict:<type>:<type>:<key>,<value>[,<key>,<value>...]
+<variant>    ::= variant:<type>:<value>
+<type>       ::= string | int16 | uint 16 | int32 | uint32 | int64 | uint64 | double | byte | boolean | objpath
+.fi
+
+D-Bus supports more types than these, but \fIdbus-send\fP currently
+does not.  Also, \fIdbus-send\fP does not permit empty containers
+or nested containers (e.g. arrays of variants).
+
+.PP
+Here is an example invocation:
+.nf
+
+  dbus-send \-\-dest=org.freedesktop.ExampleName               \\
+            /org/freedesktop/sample/object/name              \\
+            org.freedesktop.ExampleInterface.ExampleMethod   \\
+            int32:47 string:'hello world' double:65.32       \\
+            array:string:"1st item","next item","last item"  \\
+            dict:string:int32:"one",1,"two",2,"three",3      \\
+            variant:int32:-8                                 \\
+            objpath:/org/freedesktop/sample/object/name 
+
+.fi
+
+Note that the interface is separated from a method or signal 
+name by a dot, though in the actual protocol the interface
+and the interface member are separate fields.
+
+.SH OPTIONS
+The following options are supported:
+.TP
+.I "--dest=NAME"
+Specify the name of the connection to receive the message.
+.TP
+.I "--print-reply"
+Block for a reply to the message sent, and print any reply received.
+.TP
+.I "--system"
+Send to the system message bus.
+.TP
+.I "--session"
+Send to the session message bus.  (This is the default.)
+.TP
+.I "--type=TYPE"
+Specify "method_call" or "signal" (defaults to "signal").
+
+.SH AUTHOR
+dbus-send was written by Philip Blundell.
+
+.SH BUGS
+Please send bug reports to the D-Bus mailing list or bug tracker,
+see http://www.freedesktop.org/software/dbus/
diff --git a/jni/dbus/tools/dbus-send.c b/jni/dbus/tools/dbus-send.c
new file mode 100644
index 0000000..c7d5090
--- /dev/null
+++ b/jni/dbus/tools/dbus-send.c
@@ -0,0 +1,544 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-send.c  Utility program to send messages from the command line
+ *
+ * Copyright (C) 2003 Philip Blundell <philb@gnu.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dbus/dbus.h>
+
+#ifndef HAVE_STRTOLL
+#undef strtoll
+#define strtoll mystrtoll
+#include "strtoll.c"
+#endif
+
+#ifndef HAVE_STRTOULL
+#undef strtoull
+#define strtoull mystrtoull
+#include "strtoull.c"
+#endif
+
+#ifdef DBUS_WINCE
+#ifndef strdup
+#define strdup _strdup
+#endif
+#endif
+
+#include "dbus-print-message.h"
+
+static const char *appname;
+
+static void
+usage (int ecode)
+{
+  fprintf (stderr, "Usage: %s [--help] [--system | --session | --address=ADDRESS] [--dest=NAME] [--type=TYPE] [--print-reply=(literal)] [--reply-timeout=MSEC] <destination object path> <message name> [contents ...]\n", appname);
+  exit (ecode);
+}
+
+static void
+append_arg (DBusMessageIter *iter, int type, const char *value)
+{
+  dbus_uint16_t uint16;
+  dbus_int16_t int16;
+  dbus_uint32_t uint32;
+  dbus_int32_t int32;
+  dbus_uint64_t uint64;
+  dbus_int64_t int64;
+  double d;
+  unsigned char byte;
+  dbus_bool_t v_BOOLEAN;
+  
+  /* FIXME - we are ignoring OOM returns on all these functions */
+  switch (type)
+    {
+    case DBUS_TYPE_BYTE:
+      byte = strtoul (value, NULL, 0);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_BYTE, &byte);
+      break;
+
+    case DBUS_TYPE_DOUBLE:
+      d = strtod (value, NULL);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_DOUBLE, &d);
+      break;
+
+    case DBUS_TYPE_INT16:
+      int16 = strtol (value, NULL, 0);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_INT16, &int16);
+      break;
+
+    case DBUS_TYPE_UINT16:
+      uint16 = strtoul (value, NULL, 0);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT16, &uint16);
+      break;
+
+    case DBUS_TYPE_INT32:
+      int32 = strtol (value, NULL, 0);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_INT32, &int32);
+      break;
+
+    case DBUS_TYPE_UINT32:
+      uint32 = strtoul (value, NULL, 0);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT32, &uint32);
+      break;
+
+    case DBUS_TYPE_INT64:
+      int64 = strtoll (value, NULL, 0);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_INT64, &int64);
+      break;
+
+    case DBUS_TYPE_UINT64:
+      uint64 = strtoull (value, NULL, 0);
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_UINT64, &uint64);
+      break;
+
+    case DBUS_TYPE_STRING:
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_STRING, &value);
+      break;
+
+    case DBUS_TYPE_OBJECT_PATH:
+      dbus_message_iter_append_basic (iter, DBUS_TYPE_OBJECT_PATH, &value);
+      break;
+
+    case DBUS_TYPE_BOOLEAN:
+      if (strcmp (value, "true") == 0)
+	{
+	  v_BOOLEAN = TRUE;
+	  dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
+	}
+      else if (strcmp (value, "false") == 0)
+	{
+	  v_BOOLEAN = FALSE;
+	  dbus_message_iter_append_basic (iter, DBUS_TYPE_BOOLEAN, &v_BOOLEAN);
+	}
+      else
+	{
+	  fprintf (stderr, "%s: Expected \"true\" or \"false\" instead of \"%s\"\n", appname, value);
+	  exit (1);
+	}
+      break;
+
+    default:
+      fprintf (stderr, "%s: Unsupported data type %c\n", appname, (char) type);
+      exit (1);
+    }
+}
+
+static void
+append_array (DBusMessageIter *iter, int type, const char *value)
+{
+  const char *val;
+  char *dupval = strdup (value);
+
+  val = strtok (dupval, ",");
+  while (val != NULL)
+    {
+      append_arg (iter, type, val);
+      val = strtok (NULL, ",");
+    }
+  free (dupval);
+}
+
+static void
+append_dict (DBusMessageIter *iter, int keytype, int valtype, const char *value)
+{
+  const char *val;
+  char *dupval = strdup (value);
+
+  val = strtok (dupval, ",");
+  while (val != NULL)
+    {
+      DBusMessageIter subiter;
+      
+      dbus_message_iter_open_container (iter,
+					DBUS_TYPE_DICT_ENTRY,
+					NULL,
+					&subiter);
+
+      append_arg (&subiter, keytype, val);
+      val = strtok (NULL, ",");
+      if (val == NULL)
+	{
+	  fprintf (stderr, "%s: Malformed dictionary\n", appname);
+	  exit (1);
+	}
+      append_arg (&subiter, valtype, val);
+
+      dbus_message_iter_close_container (iter, &subiter);
+      val = strtok (NULL, ",");
+    } 
+  free (dupval);
+}
+
+static int
+type_from_name (const char *arg)
+{
+  int type;
+  if (!strcmp (arg, "string"))
+    type = DBUS_TYPE_STRING;
+  else if (!strcmp (arg, "int16"))
+    type = DBUS_TYPE_INT16;
+  else if (!strcmp (arg, "uint16"))
+    type = DBUS_TYPE_UINT16;
+  else if (!strcmp (arg, "int32"))
+    type = DBUS_TYPE_INT32;
+  else if (!strcmp (arg, "uint32"))
+    type = DBUS_TYPE_UINT32;
+  else if (!strcmp (arg, "int64"))
+    type = DBUS_TYPE_INT64;
+  else if (!strcmp (arg, "uint64"))
+    type = DBUS_TYPE_UINT64;
+  else if (!strcmp (arg, "double"))
+    type = DBUS_TYPE_DOUBLE;
+  else if (!strcmp (arg, "byte"))
+    type = DBUS_TYPE_BYTE;
+  else if (!strcmp (arg, "boolean"))
+    type = DBUS_TYPE_BOOLEAN;
+  else if (!strcmp (arg, "objpath"))
+    type = DBUS_TYPE_OBJECT_PATH;
+  else
+    {
+      fprintf (stderr, "%s: Unknown type \"%s\"\n", appname, arg);
+      exit (1);
+    }
+  return type;
+}
+
+int
+main (int argc, char *argv[])
+{
+  DBusConnection *connection;
+  DBusError error;
+  DBusMessage *message;
+  int print_reply;
+  int print_reply_literal;
+  int reply_timeout;
+  DBusMessageIter iter;
+  int i;
+  DBusBusType type = DBUS_BUS_SESSION;
+  const char *dest = NULL;
+  const char *name = NULL;
+  const char *path = NULL;
+  int message_type = DBUS_MESSAGE_TYPE_SIGNAL;
+  const char *type_str = NULL;
+  const char *address = NULL;
+  int session_or_system = FALSE;
+
+  appname = argv[0];
+  
+  if (argc < 3)
+    usage (1);
+
+  print_reply = FALSE;
+  print_reply_literal = FALSE;
+  reply_timeout = -1;
+  
+  for (i = 1; i < argc && name == NULL; i++)
+    {
+      char *arg = argv[i];
+
+      if (strcmp (arg, "--system") == 0)
+        {
+	  type = DBUS_BUS_SYSTEM;
+          session_or_system = TRUE;
+        }
+      else if (strcmp (arg, "--session") == 0)
+        {
+	  type = DBUS_BUS_SESSION;
+          session_or_system = TRUE;
+        }
+      else if (strstr (arg, "--address") == arg)
+        {
+          address = strchr (arg, '=');
+
+          if (address == NULL) 
+            {
+              fprintf (stderr, "\"--address=\" requires an ADDRESS\n");
+              usage (1);
+            }
+          else
+            {
+              address = address + 1;
+            }
+        }
+      else if (strncmp (arg, "--print-reply", 13) == 0)
+	{
+	  print_reply = TRUE;
+	  message_type = DBUS_MESSAGE_TYPE_METHOD_CALL;
+	  if (*(arg + 13) != '\0')
+	    print_reply_literal = TRUE;
+	}
+      else if (strstr (arg, "--reply-timeout=") == arg)
+	{
+	  reply_timeout = strtol (strchr (arg, '=') + 1,
+				  NULL, 10);
+	}
+      else if (strstr (arg, "--dest=") == arg)
+	dest = strchr (arg, '=') + 1;
+      else if (strstr (arg, "--type=") == arg)
+	type_str = strchr (arg, '=') + 1;
+      else if (!strcmp(arg, "--help"))
+	usage (0);
+      else if (arg[0] == '-')
+	usage (1);
+      else if (path == NULL)
+        path = arg;
+      else if (name == NULL)
+        name = arg;
+      else
+        usage (1);
+    }
+
+  if (name == NULL)
+    usage (1);
+
+  if (session_or_system &&
+      (address != NULL))
+    {
+      fprintf (stderr, "\"--address\" may not be used with \"--system\" or \"--session\"\n");
+      usage (1);
+    }
+
+  if (type_str != NULL)
+    {
+      message_type = dbus_message_type_from_string (type_str);
+      if (!(message_type == DBUS_MESSAGE_TYPE_METHOD_CALL ||
+            message_type == DBUS_MESSAGE_TYPE_SIGNAL))
+        {
+          fprintf (stderr, "Message type \"%s\" is not supported\n",
+                   type_str);
+          exit (1);
+        }
+    }
+  
+  dbus_error_init (&error);
+
+  if (address != NULL)
+    {
+      connection = dbus_connection_open (address, &error);
+    }
+  else
+    {
+      connection = dbus_bus_get (type, &error);
+    }
+
+  if (connection == NULL)
+    {
+      fprintf (stderr, "Failed to open connection to \"%s\" message bus: %s\n",
+               (address != NULL) ? address :
+                 ((type == DBUS_BUS_SYSTEM) ? "system" : "session"),
+               error.message);
+      dbus_error_free (&error);
+      exit (1);
+    }
+
+  if (message_type == DBUS_MESSAGE_TYPE_METHOD_CALL)
+    {
+      char *last_dot;
+
+      last_dot = strrchr (name, '.');
+      if (last_dot == NULL)
+        {
+          fprintf (stderr, "Must use org.mydomain.Interface.Method notation, no dot in \"%s\"\n",
+                   name);
+          exit (1);
+        }
+      *last_dot = '\0';
+      
+      message = dbus_message_new_method_call (NULL,
+                                              path,
+                                              name,
+                                              last_dot + 1);
+      dbus_message_set_auto_start (message, TRUE);
+    }
+  else if (message_type == DBUS_MESSAGE_TYPE_SIGNAL)
+    {
+      char *last_dot;
+
+      last_dot = strrchr (name, '.');
+      if (last_dot == NULL)
+        {
+          fprintf (stderr, "Must use org.mydomain.Interface.Signal notation, no dot in \"%s\"\n",
+                   name);
+          exit (1);
+        }
+      *last_dot = '\0';
+      
+      message = dbus_message_new_signal (path, name, last_dot + 1);
+    }
+  else
+    {
+      fprintf (stderr, "Internal error, unknown message type\n");
+      exit (1);
+    }
+
+  if (message == NULL)
+    {
+      fprintf (stderr, "Couldn't allocate D-Bus message\n");
+      exit (1);
+    }
+
+  if (dest && !dbus_message_set_destination (message, dest))
+    {
+      fprintf (stderr, "Not enough memory\n");
+      exit (1);
+    }
+  
+  dbus_message_iter_init_append (message, &iter);
+
+  while (i < argc)
+    {
+      char *arg;
+      char *c;
+      int type;
+      int secondary_type;
+      int container_type;
+      DBusMessageIter *target_iter;
+      DBusMessageIter container_iter;
+
+      type = DBUS_TYPE_INVALID;
+      arg = argv[i++];
+      c = strchr (arg, ':');
+
+      if (c == NULL)
+	{
+	  fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
+	  exit (1);
+	}
+
+      *(c++) = 0;
+
+      container_type = DBUS_TYPE_INVALID;
+
+      if (strcmp (arg, "variant") == 0)
+	container_type = DBUS_TYPE_VARIANT;
+      else if (strcmp (arg, "array") == 0)
+	container_type = DBUS_TYPE_ARRAY;
+      else if (strcmp (arg, "dict") == 0)
+	container_type = DBUS_TYPE_DICT_ENTRY;
+
+      if (container_type != DBUS_TYPE_INVALID)
+	{
+	  arg = c;
+	  c = strchr (arg, ':');
+	  if (c == NULL)
+	    {
+	      fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
+	      exit (1);
+	    }
+	  *(c++) = 0;
+	}
+
+      if (arg[0] == 0)
+	type = DBUS_TYPE_STRING;
+      else
+	type = type_from_name (arg);
+
+      if (container_type == DBUS_TYPE_DICT_ENTRY)
+	{
+	  char sig[5];
+	  arg = c;
+	  c = strchr (c, ':');
+	  if (c == NULL)
+	    {
+	      fprintf (stderr, "%s: Data item \"%s\" is badly formed\n", argv[0], arg);
+	      exit (1);
+	    }
+	  *(c++) = 0;
+	  secondary_type = type_from_name (arg);
+	  sig[0] = DBUS_DICT_ENTRY_BEGIN_CHAR;
+	  sig[1] = type;
+	  sig[2] = secondary_type;
+	  sig[3] = DBUS_DICT_ENTRY_END_CHAR;
+	  sig[4] = '\0';
+	  dbus_message_iter_open_container (&iter,
+					    DBUS_TYPE_ARRAY,
+					    sig,
+					    &container_iter);
+	  target_iter = &container_iter;
+	}
+      else if (container_type != DBUS_TYPE_INVALID)
+	{
+	  char sig[2];
+	  sig[0] = type;
+	  sig[1] = '\0';
+	  dbus_message_iter_open_container (&iter,
+					    container_type,
+					    sig,
+					    &container_iter);
+	  target_iter = &container_iter;
+	}
+      else
+	target_iter = &iter;
+
+      if (container_type == DBUS_TYPE_ARRAY)
+	{
+	  append_array (target_iter, type, c);
+	}
+      else if (container_type == DBUS_TYPE_DICT_ENTRY)
+	{
+	  append_dict (target_iter, type, secondary_type, c);
+	}
+      else
+	append_arg (target_iter, type, c);
+
+      if (container_type != DBUS_TYPE_INVALID)
+	{
+	  dbus_message_iter_close_container (&iter,
+					     &container_iter);
+	}
+    }
+
+  if (print_reply)
+    {
+      DBusMessage *reply;
+
+      dbus_error_init (&error);
+      reply = dbus_connection_send_with_reply_and_block (connection,
+                                                         message, reply_timeout,
+                                                         &error);
+      if (dbus_error_is_set (&error))
+        {
+          fprintf (stderr, "Error %s: %s\n",
+		   error.name,
+                   error.message);
+          exit (1);
+        }
+
+      if (reply)
+        {
+          print_message (reply, print_reply_literal);
+          dbus_message_unref (reply);
+        }
+    }
+  else
+    {
+      dbus_connection_send (connection, message, NULL);
+      dbus_connection_flush (connection);
+    }
+
+  dbus_message_unref (message);
+
+  dbus_connection_unref (connection);
+
+  exit (0);
+}
diff --git a/jni/dbus/tools/dbus-uuidgen.1 b/jni/dbus/tools/dbus-uuidgen.1
new file mode 100644
index 0000000..480fd18
--- /dev/null
+++ b/jni/dbus/tools/dbus-uuidgen.1
@@ -0,0 +1,89 @@
+.\" 
+.\" dbus-uuidgen manual page.
+.\" Copyright (C) 2006 Red Hat, Inc.
+.\"
+.TH dbus-uuidgen 1
+.SH NAME
+dbus-uuidgen \- Utility to generate UUIDs
+.SH SYNOPSIS
+.PP
+.B dbus-uuidgen [\-\-version] [\-\-ensure[=FILENAME]] [\-\-get[=FILENAME]]
+
+.SH DESCRIPTION
+
+The \fIdbus-uuidgen\fP command generates or reads a universally unique ID.
+
+.PP
+Note that the D-Bus UUID has no relationship to RFC 4122 and does not generate
+UUIDs compatible with that spec. Many systems have a separate command
+for that (often called "uuidgen").
+
+.PP
+See http://www.freedesktop.org/software/dbus/ for more information
+about D-Bus.
+
+.PP
+The primary usage of \fIdbus-uuidgen\fP is to run in the post-install
+script of a D-Bus package like this:
+.nf
+  dbus-uuidgen --ensure
+.fi
+
+.PP
+This will ensure that /var/lib/dbus/machine-id exists and has the uuid in it.
+It won't overwrite an existing uuid, since this id should remain fixed
+for a single machine until the next reboot at least.
+
+.PP
+The important properties of the machine UUID are that 1) it remains
+unchanged until the next reboot and 2) it is different for any two 
+running instances of the OS kernel. That is, if two processes see the 
+same UUID, they should also see the same shared memory, UNIX domain
+sockets, local X displays, localhost.localdomain resolution, process
+IDs, and so forth.
+
+.PP
+If you run \fIdbus-uuidgen\fP with no options it just prints a new uuid made
+up out of thin air.
+
+.PP
+If you run it with --get, it prints the machine UUID by default, or
+the UUID in the specified file if you specify a file.
+
+.PP
+If you try to change an existing machine-id on a running system, it will
+probably result in bad things happening. Don't try to change this file. Also,
+don't make it the same on two different systems; it needs to be different
+anytime there are two different kernels running.
+
+.PP
+The UUID should be different on two different virtual machines,
+because there are two different kernels.
+
+.SH OPTIONS
+The following options are supported:
+.TP
+.I "--get[=FILENAME]"
+If a filename is not given, defaults to localstatedir/lib/dbus/machine-id
+(localstatedir is usually /var). If this file exists and is valid, the
+uuid in the file is printed on stdout. Otherwise, the command exits 
+with a nonzero status.
+
+.TP
+.I "--ensure[=FILENAME]"
+If a filename is not given, defaults to localstatedir/lib/dbus/machine-id
+(localstatedir is usually /var). If this file exists then it will be
+validated, and a failure code returned if it contains the wrong thing.
+If the file does not exist, it will be created with a new uuid in it.
+On success, prints no output.
+
+.TP
+.I "--version"
+Print the version of dbus-uuidgen
+
+.SH AUTHOR
+See http://www.freedesktop.org/software/dbus/doc/AUTHORS
+
+.SH BUGS
+Please send bug reports to the D-Bus mailing list or bug tracker,
+see http://www.freedesktop.org/software/dbus/
diff --git a/jni/dbus/tools/dbus-uuidgen.c b/jni/dbus/tools/dbus-uuidgen.c
new file mode 100644
index 0000000..c8ba1cf
--- /dev/null
+++ b/jni/dbus/tools/dbus-uuidgen.c
@@ -0,0 +1,161 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-uuidgen.c  Utility program to create UUIDs
+ *
+ * Copyright (C) 2006 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#include <config.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include <dbus/dbus-uuidgen.h>
+#include <dbus/dbus.h>
+
+static void
+usage (char *name, int ecode)
+{
+  if (name == NULL)
+    name = "dbus-uuidgen";
+  
+  fprintf (stderr, "Usage: %s [--ensure[=FILENAME]] [--get[=FILENAME]]\n", name);
+  exit (ecode);
+}
+
+static void
+version (void)
+{
+  printf ("D-Bus UUID Generator %s\n"
+          "Copyright (C) 2006 Red Hat, Inc.\n"
+          "This is free software; see the source for copying conditions.\n"
+          "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+          VERSION);
+  exit (0);
+}
+
+static dbus_bool_t
+get_arg (const char  *arg,
+         const char  *option,
+         const char **value_p)
+{
+  const char *fn;
+
+  if (strlen(arg) < strlen(option))
+    return FALSE;
+  
+  fn = arg + strlen(option);
+
+  if (!(*fn == '=' || *fn == ' ' || *fn == '\0'))
+    {
+      usage (NULL, 1);
+    }
+  
+  if (*fn == '=')
+    ++fn;
+  
+  while (*fn == ' ' && *fn != '\0')
+    ++fn;
+  
+  if (*fn != '\0')
+    {
+      *value_p = fn;
+      return TRUE;
+    }
+
+  return FALSE;
+}
+
+int
+main (int argc, char *argv[])
+{
+  int i;
+  const char *filename;
+  dbus_bool_t ensure_uuid;
+  dbus_bool_t get_uuid;
+  DBusError error;
+
+  ensure_uuid = FALSE;
+  get_uuid = FALSE;
+  
+  filename = NULL;
+
+  for (i = 1; i < argc; i++)
+    {
+      char *arg = argv[i];
+
+      if (strncmp (arg, "--ensure", strlen("--ensure")) == 0)
+        {
+          get_arg (arg, "--ensure", &filename);
+          ensure_uuid = TRUE;
+        }
+      else if (strncmp (arg, "--get", strlen("--get")) == 0)
+        {
+          get_arg (arg, "--get", &filename);
+          get_uuid = TRUE;
+        }
+      else if (strcmp (arg, "--help") == 0)
+	usage (argv[0], 0);
+      else if (strcmp (arg, "--version") == 0)
+        version ();
+      else
+        usage (argv[0], 1);
+    }
+
+  if (get_uuid && ensure_uuid)
+    {
+      fprintf (stderr, "Can't specify both --get and --ensure\n");
+      exit (1);
+    }
+
+  dbus_error_init (&error);
+  
+  if (get_uuid || ensure_uuid)
+    {
+      char *uuid;
+      if (dbus_internal_do_not_use_get_uuid (filename, &uuid, ensure_uuid, &error))
+        {
+          if (get_uuid) /* print nothing on --ensure */
+            printf ("%s\n", uuid);
+          dbus_free (uuid);
+        }
+    }
+  else
+    {
+      char *uuid;
+      if (dbus_internal_do_not_use_create_uuid (&uuid))
+        {
+          printf ("%s\n", uuid);
+          dbus_free (uuid);
+        }
+      else
+        {
+          dbus_set_error (&error, DBUS_ERROR_NO_MEMORY, "No memory");
+        }
+    }
+
+  if (dbus_error_is_set (&error))
+    {
+      fprintf (stderr, "%s\n", error.message);
+      dbus_error_free (&error);
+      exit (1);
+    }
+  else
+    {
+      exit (0);
+    }
+}
diff --git a/jni/dbus/tools/dbus-viewer.c b/jni/dbus/tools/dbus-viewer.c
new file mode 100644
index 0000000..2fd2847
--- /dev/null
+++ b/jni/dbus/tools/dbus-viewer.c
@@ -0,0 +1,617 @@
+/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
+/* dbus-viewer.c Graphical D-Bus frontend utility
+ *
+ * Copyright (C) 2003 Red Hat, Inc.
+ *
+ * Licensed under the Academic Free License version 2.1
+ * 
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+#include <config.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <gtk/gtk.h>
+#include "dbus-tree-view.h"
+#include "dbus-names-model.h"
+#include <glib/dbus-gparser.h>
+#include <glib/dbus-gutils.h>
+#include <dbus/dbus-glib.h>
+#include <glib/gi18n.h>
+
+static void
+show_error_dialog (GtkWindow *transient_parent,
+                   GtkWidget **weak_ptr,
+                   const char *message_format,
+                   ...)
+{
+  char *message;
+  va_list args;
+
+  if (message_format)
+    {
+      va_start (args, message_format);
+      message = g_strdup_vprintf (message_format, args);
+      va_end (args);
+    }
+  else
+    message = NULL;
+
+  if (weak_ptr == NULL || *weak_ptr == NULL)
+    {
+      GtkWidget *dialog;
+      dialog = gtk_message_dialog_new (transient_parent,
+                                       GTK_DIALOG_DESTROY_WITH_PARENT,
+                                       GTK_MESSAGE_ERROR,
+                                       GTK_BUTTONS_CLOSE,
+                                       message);
+
+      g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (gtk_widget_destroy), NULL);
+
+      if (weak_ptr != NULL)
+        {
+          *weak_ptr = dialog;
+          g_object_add_weak_pointer (G_OBJECT (dialog), (void**)weak_ptr);
+        }
+
+      gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+      
+      gtk_widget_show_all (dialog);
+    }
+  else 
+    {
+      g_return_if_fail (GTK_IS_MESSAGE_DIALOG (*weak_ptr));
+
+      gtk_label_set_text (GTK_LABEL (GTK_MESSAGE_DIALOG (*weak_ptr)->label), message);
+
+      gtk_window_present (GTK_WINDOW (*weak_ptr));
+    }
+}
+
+typedef struct
+{
+  DBusGConnection *connection;
+  
+  GtkWidget *window;
+  GtkWidget *treeview;
+  GtkWidget *name_menu;
+
+  GtkTreeModel *names_model;
+
+  GtkWidget *error_dialog;
+  
+} TreeWindow;
+
+
+static void
+tree_window_set_node (TreeWindow *w,
+                      NodeInfo   *node)
+{
+  char **path;
+  const char *name;
+
+  name = node_info_get_name (node);
+  if (name == NULL ||
+      name[0] != '/')
+    {
+      g_printerr (_("Assuming root node is at path /, since no absolute path is specified"));
+      name = "/";
+    }
+
+  path = _dbus_gutils_split_path (name);
+  
+  dbus_tree_view_update (GTK_TREE_VIEW (w->treeview),
+                         (const char**) path,
+                         node);
+
+  g_strfreev (path);
+}
+
+typedef struct
+{
+  DBusGConnection *connection;
+  char *service_name;
+  GError *error;
+  NodeInfo *node;
+  TreeWindow *window; /* Not touched from child thread */
+} LoadFromServiceData;
+
+static gboolean
+load_child_nodes (const char *service_name,
+                  NodeInfo   *parent,
+                  GString    *path,
+                  GError    **error)
+{
+  DBusGConnection *connection;
+  GSList *tmp;
+  
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+  if (connection == NULL)
+    return FALSE;
+  
+  tmp = node_info_get_nodes (parent);
+  while (tmp != NULL)
+    {
+      DBusGProxy *proxy;
+      char *data;
+      NodeInfo *child;
+      NodeInfo *complete_child;
+      int save_len;
+
+      complete_child = NULL;
+      
+      child = tmp->data;
+
+      save_len = path->len;
+
+      if (save_len > 1)
+        g_string_append (path, "/");
+      g_string_append (path, base_info_get_name ((BaseInfo*)child));
+
+      if (*service_name == ':')
+        {
+          proxy = dbus_g_proxy_new_for_name (connection,
+                                             service_name,
+                                             path->str,
+                                             DBUS_INTERFACE_INTROSPECTABLE);
+          g_assert (proxy != NULL);
+        }
+      else
+        {
+          proxy = dbus_g_proxy_new_for_name_owner (connection,
+                                                   service_name,
+                                                   path->str,
+                                                   DBUS_INTERFACE_INTROSPECTABLE,
+                                                   error);
+          if (proxy == NULL)
+            goto done;
+        }
+  
+      if (!dbus_g_proxy_call (proxy, "Introspect", error,
+                              G_TYPE_INVALID,
+			      G_TYPE_STRING, &data,
+			      G_TYPE_INVALID))
+	  goto done;
+      
+      complete_child = description_load_from_string (data, -1, error);
+      g_free (data);
+      if (complete_child == NULL)
+        {
+          g_printerr ("%s\n", data);
+          goto done;
+        }
+      
+    done:
+      g_object_unref (proxy);
+
+      if (complete_child == NULL)
+        return FALSE;
+
+      /* change complete_child's name to relative */
+      base_info_set_name ((BaseInfo*)complete_child,
+                          base_info_get_name ((BaseInfo*)child));
+      
+      /* Stitch in complete_child rather than child */
+      node_info_replace_node (parent, child, complete_child);
+      node_info_unref (complete_child); /* ref still held by parent */
+      
+      /* Now recurse */
+      if (!load_child_nodes (service_name, complete_child, path, error))
+        return FALSE;
+
+      /* restore path */
+      g_string_set_size (path, save_len);
+      
+      tmp = tmp->next;
+    }
+
+  return TRUE;
+}
+
+static gboolean
+load_from_service_complete_idle (void *data)
+{
+  /* Called in main thread */
+  GThread *thread = data;
+  LoadFromServiceData *d;
+  NodeInfo *node;
+
+  d = g_thread_join (thread);
+
+  node = d->node;
+  
+  if (d->error)
+    {
+      g_assert (d->node == NULL);
+      show_error_dialog (GTK_WINDOW (d->window->window), &d->window->error_dialog,
+                         _("Unable to load \"%s\": %s\n"),
+                         d->service_name, d->error->message);
+      g_error_free (d->error);
+    }
+  else
+    {
+      g_assert (d->error == NULL);
+
+      tree_window_set_node (d->window, node);
+      node_info_unref (node);
+    }
+
+  g_free (d->service_name);
+  dbus_g_connection_unref (d->connection);
+  g_free (d);
+
+  return FALSE;
+}
+
+static void*
+load_from_service_thread_func (void *thread_data)
+{  
+  DBusGProxy *root_proxy;
+  const char *data;
+  NodeInfo *node;
+  GString *path;
+  LoadFromServiceData *lfsd;
+
+  lfsd = thread_data;
+
+  node = NULL;
+  path = NULL;
+ 
+#if 1
+  /* this will end up autolaunching the service when we introspect it */
+  root_proxy = dbus_g_proxy_new_for_name (lfsd->connection,
+                                          lfsd->service_name,
+                                          "/",
+                                          DBUS_INTERFACE_INTROSPECTABLE);
+  g_assert (root_proxy != NULL);
+#else
+  /* this will be an error if the service doesn't exist */
+  root_proxy = dbus_g_proxy_new_for_name_owner (lfsd->connection,
+                                                lfsd->service_name,
+                                                "/",
+                                                DBUS_INTERFACE_INTROSPECTABLE,
+                                                &lfsd->error);
+  if (root_proxy == NULL)
+    {
+      g_printerr ("Failed to get owner of '%s'\n", lfsd->service_name);
+      return lfsd->data;
+    }
+#endif
+  
+  if (!dbus_g_proxy_call (root_proxy, "Introspect", &lfsd->error,
+			  G_TYPE_INVALID,
+			  G_TYPE_STRING, &data,
+			  G_TYPE_INVALID))
+    {
+      g_printerr ("Failed to Introspect() %s\n",
+		  dbus_g_proxy_get_bus_name (root_proxy));
+      goto out;
+    }
+
+  node = description_load_from_string (data, -1, &lfsd->error);
+
+  /* g_print ("%s\n", data); */
+  
+  if (node == NULL)
+    goto out;
+
+  base_info_set_name ((BaseInfo*)node, "/");
+
+  path = g_string_new ("/");
+  
+  if (!load_child_nodes (dbus_g_proxy_get_bus_name (root_proxy),
+                         node, path, &lfsd->error))
+    {
+      node_info_unref (node);
+      node = NULL;
+      goto out;
+    }
+  
+ out:
+  g_object_unref (root_proxy);
+
+  if (path)
+    g_string_free (path, TRUE);
+
+  lfsd->node = node;
+  g_assert (lfsd->node || lfsd->error);
+  g_assert (lfsd->node == NULL || lfsd->error == NULL);
+
+  /* Add idle to main thread that will join us back */
+  g_idle_add (load_from_service_complete_idle, g_thread_self ());
+  
+  return lfsd;
+}
+
+static void
+start_load_from_service (TreeWindow      *w,
+                         DBusGConnection *connection,
+                         const char      *service_name)
+{
+  LoadFromServiceData *d;
+
+  d = g_new0 (LoadFromServiceData, 1);
+  
+  d->connection = dbus_g_connection_ref (connection);
+  d->service_name = g_strdup (service_name);
+  d->error = NULL;
+  d->node = NULL;
+  d->window = w;
+  
+  g_thread_create (load_from_service_thread_func, d, TRUE, NULL);
+}
+
+static void
+tree_window_set_service (TreeWindow *w,
+                         const char *service_name)
+{
+  start_load_from_service (w, w->connection, service_name);
+}
+
+static void
+name_combo_changed_callback (GtkComboBox *combo,
+                             TreeWindow  *w)
+{
+  GtkTreeIter iter;
+
+  if (gtk_combo_box_get_active_iter (combo, &iter))
+    {
+      GtkTreeModel *model;
+      char *text;
+
+      model = gtk_combo_box_get_model (combo);
+      gtk_tree_model_get (model, &iter, 0, &text, -1);
+
+      if (text)
+        {
+          tree_window_set_service (w, text);
+          g_free (text);
+        }
+    }
+}
+
+static void
+window_closed_callback (GtkWidget  *window,
+                        TreeWindow *w)
+{
+  g_assert (window == w->window);
+  w->window = NULL;
+  gtk_main_quit ();
+}
+
+static TreeWindow*
+tree_window_new (DBusGConnection *connection,
+                 GtkTreeModel    *names_model)
+{
+  TreeWindow *w;
+  GtkWidget *sw;
+  GtkWidget *vbox;
+  GtkWidget *hbox;
+  GtkWidget *combo;
+
+  /* Should use glade, blah */
+  
+  w = g_new0 (TreeWindow, 1);
+  w->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+  gtk_window_set_title (GTK_WINDOW (w->window), "D-Bus Viewer");
+  gtk_window_set_default_size (GTK_WINDOW (w->window), 400, 500);
+
+  g_signal_connect (w->window, "destroy", G_CALLBACK (window_closed_callback),
+                    w);
+  gtk_container_set_border_width (GTK_CONTAINER (w->window), 6);
+
+  vbox = gtk_vbox_new (FALSE, 6);
+  gtk_container_add (GTK_CONTAINER (w->window), vbox);
+
+  /* Create names option menu */
+  if (connection)
+    {
+      GtkCellRenderer *cell;
+
+      w->connection = connection;
+      
+      w->names_model = names_model;
+
+      combo = gtk_combo_box_new_with_model (w->names_model);
+
+      cell = gtk_cell_renderer_text_new ();
+      gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), cell, TRUE);
+      gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (combo), cell,
+                                      "text", 0,
+                                      NULL);
+      
+      gtk_box_pack_start (GTK_BOX (vbox), combo, FALSE, FALSE, 0);
+
+      g_signal_connect (combo, "changed",
+                        G_CALLBACK (name_combo_changed_callback),
+                        w);
+    }
+  
+  /* Create tree view */
+  hbox = gtk_hbox_new (FALSE, 6);
+  gtk_container_add (GTK_CONTAINER (vbox), hbox);
+  
+  sw = gtk_scrolled_window_new (NULL, NULL);
+  gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
+                                  GTK_POLICY_AUTOMATIC,
+                                  GTK_POLICY_AUTOMATIC);
+
+  gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0);
+
+  w->treeview = dbus_tree_view_new ();
+
+  gtk_container_add (GTK_CONTAINER (sw), w->treeview);
+
+  /* Show everything */
+  gtk_widget_show_all (w->window);
+
+  return w;
+}
+
+static void
+usage (int ecode)
+{
+  fprintf (stderr, "dbus-viewer [--version] [--help]\n");
+  exit (ecode);
+}
+
+static void
+version (void)
+{
+  printf ("D-Bus Message Bus Viewer %s\n"
+          "Copyright (C) 2003 Red Hat, Inc.\n"
+          "This is free software; see the source for copying conditions.\n"
+          "There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
+          VERSION);
+  exit (0);
+}
+
+int
+main (int argc, char **argv)
+{
+  int i;
+  GSList *files;
+  gboolean end_of_args;
+  GSList *tmp;
+  gboolean services;
+  DBusGConnection *connection;
+  GError *error;
+  GtkTreeModel *names_model;
+
+  g_thread_init (NULL);
+  dbus_g_thread_init ();
+  
+  bindtextdomain (GETTEXT_PACKAGE, DBUS_LOCALEDIR);
+  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
+  textdomain (GETTEXT_PACKAGE);
+  
+  gtk_init (&argc, &argv);
+
+  services = FALSE;
+  end_of_args = FALSE;
+  files = NULL;
+  i = 1;
+  while (i < argc)
+    {
+      const char *arg = argv[i];
+
+      if (!end_of_args)
+        {
+          if (strcmp (arg, "--help") == 0 ||
+              strcmp (arg, "-h") == 0 ||
+              strcmp (arg, "-?") == 0)
+            usage (0);
+          else if (strcmp (arg, "--version") == 0)
+            version ();
+          else if (strcmp (arg, "--services") == 0)
+            services = TRUE;
+          else if (arg[0] == '-' &&
+                   arg[1] == '-' &&
+                   arg[2] == '\0')
+            end_of_args = TRUE;
+          else if (arg[0] == '-')
+            {
+              usage (1);
+            }
+          else
+            {
+              files = g_slist_prepend (files, (char*) arg);
+            }
+        }
+      else
+        files = g_slist_prepend (files, (char*) arg);
+      
+      ++i;
+    }
+
+  if (services || files == NULL)
+    {
+      error = NULL;
+      connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+      if (connection == NULL)
+        {
+          g_printerr ("Could not open bus connection: %s\n",
+                      error->message);
+          g_error_free (error);
+          exit (1);
+        }
+
+      g_assert (connection == dbus_g_bus_get (DBUS_BUS_SESSION, NULL));
+
+      names_model = names_model_new (connection);
+    }
+  else
+    {
+      connection = NULL;
+      names_model = NULL;
+    }
+
+  if (files == NULL)
+    {
+      TreeWindow *w;
+
+      w = tree_window_new (connection, names_model);
+    }
+  
+  files = g_slist_reverse (files);
+
+  tmp = files;
+  while (tmp != NULL)
+    {
+      const char *filename;
+      TreeWindow *w;
+
+      filename = tmp->data;
+      
+      if (services)
+        {
+          w = tree_window_new (connection, names_model);
+          tree_window_set_service (w, filename);
+        }
+      else
+        {
+          NodeInfo *node;
+          
+          error = NULL;
+          node = description_load_from_file (filename,
+                                             &error);
+          
+          if (node == NULL)
+            {
+              g_assert (error != NULL);
+              show_error_dialog (NULL, NULL,
+                                 _("Unable to load \"%s\": %s\n"),
+                                 filename, error->message);
+              g_error_free (error);
+            }
+          else
+            {
+              w = tree_window_new (connection, names_model);
+              tree_window_set_node (w, node);
+              node_info_unref (node);
+            }
+        }
+      
+      tmp = tmp->next;
+    }
+
+  gtk_main ();
+  
+  return 0;
+}
+
diff --git a/jni/dbus/tools/run-with-tmp-session-bus.sh b/jni/dbus/tools/run-with-tmp-session-bus.sh
new file mode 100644
index 0000000..982184a
--- /dev/null
+++ b/jni/dbus/tools/run-with-tmp-session-bus.sh
@@ -0,0 +1,76 @@
+#! /bin/bash
+
+SCRIPTNAME=$0
+WRAPPED_SCRIPT=$1
+shift
+
+die() 
+{
+    if ! test -z "$DBUS_SESSION_BUS_PID" ; then
+        echo "killing message bus "$DBUS_SESSION_BUS_PID >&2
+        kill -9 $DBUS_SESSION_BUS_PID
+    fi
+    echo $SCRIPTNAME: $* >&2
+    exit 1
+}
+
+if test -z "$DBUS_TOP_BUILDDIR" ; then
+    die "Must set DBUS_TOP_BUILDDIR"
+fi
+
+## convenient to be able to ctrl+C without leaking the message bus process
+trap 'die "Received SIGINT"' INT
+
+CONFIG_FILE=./run-with-tmp-session-bus.conf
+SERVICE_DIR="$DBUS_TOP_BUILDDIR/test/data/valid-service-files"
+ESCAPED_SERVICE_DIR=`echo $SERVICE_DIR | sed -e 's/\//\\\\\\//g'`
+echo "escaped service dir is: $ESCAPED_SERVICE_DIR" >&2
+
+if test -z "$SOURCE_CONFIG_FILE"; then
+    SOURCE_CONFIG_FILE="$DBUS_TOP_BUILDDIR/bus/session.conf";
+fi
+## create a configuration file based on the standard session.conf
+cat $SOURCE_CONFIG_FILE |  \
+    sed -e 's/<standard_session_servicedirs.*$/<servicedir>'$ESCAPED_SERVICE_DIR'<\/servicedir>/g' |  \
+    sed -e 's/<include.*$//g'                \
+  > $CONFIG_FILE
+
+echo "Created configuration file $CONFIG_FILE" >&2
+
+if ! test -e "$DBUS_TOP_BUILDDIR"/bus/dbus-daemon ; then
+    die "$DBUS_TOP_BUILDDIR/bus/dbus-daemon does not exist"
+fi
+
+PATH="$DBUS_TOP_BUILDDIR"/bus:$PATH
+export PATH
+
+## the libtool script found by the path search should already do this, but
+LD_LIBRARY_PATH=$DBUS_TOP_BUILDDIR/dbus/.libs:$LD_LIBRARY_PATH
+export LD_LIBRARY_PATH
+unset DBUS_SESSION_BUS_ADDRESS
+unset DBUS_SESSION_BUS_PID
+
+echo "Running $DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE" >&2
+
+DBUS_USE_TEST_BINARY=1 
+export DBUS_USE_TEST_BINARY
+eval `$DBUS_TOP_BUILDDIR/tools/dbus-launch --sh-syntax --config-file=$CONFIG_FILE`
+
+if test -z "$DBUS_SESSION_BUS_PID" ; then
+    die "Failed to launch message bus for test script to run"
+fi
+
+echo "Started bus pid $DBUS_SESSION_BUS_PID at $DBUS_SESSION_BUS_ADDRESS" >&2
+
+# Execute wrapped script
+echo "Running $WRAPPED_SCRIPT $@" >&2
+$WRAPPED_SCRIPT "$@" || die "script \"$WRAPPED_SCRIPT\" failed"
+
+kill -TERM $DBUS_SESSION_BUS_PID || die "Message bus vanished! should not have happened" && echo "Killed daemon $DBUS_SESSION_BUS_PID" >&2
+
+sleep 2
+
+## be sure it really died 
+kill -9 $DBUS_SESSION_BUS_PID > /dev/null 2>&1 || true
+
+exit 0
diff --git a/jni/dbus/tools/strtoll.c b/jni/dbus/tools/strtoll.c
new file mode 100644
index 0000000..e4f5770
--- /dev/null
+++ b/jni/dbus/tools/strtoll.c
@@ -0,0 +1,166 @@
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <limits.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stdlib.h>
+#ifdef DBUS_WINCE
+#include <windows.h>
+#endif
+
+#ifndef isspace
+#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
+#endif
+
+/* Minimum and maximum values a `signed long long int' can hold.  */
+#ifndef LLONG_MAX
+#   define LLONG_MAX	9223372036854775807LL
+#endif
+
+#ifndef LLONG_MIN
+#   define LLONG_MIN	(-LLONG_MAX - 1LL)
+#endif
+/* Maximum value an `unsigned long long int' can hold.  (Minimum is 0.)  */
+#ifndef ULLONG_MAX
+#   define ULLONG_MAX	18446744073709551615ULL
+#endif
+/*
+ * Convert a string to a long long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+long long strtoll (const char*, char **, int);
+
+long long
+strtoll(const char * nptr, char ** endptr, int base)
+{
+	const char *s;
+	unsigned long long acc;
+	char c;
+	unsigned long long cutoff;
+	int neg, any, cutlim;
+
+	/*
+	 * Skip white space and pick up leading +/- sign if any.
+	 * If base is 0, allow 0x for hex and 0 for octal, else
+	 * assume decimal; if base is already 16, allow 0x.
+	 */
+	s = nptr;
+	do {
+		c = *s++;
+	} while (isspace((unsigned char)c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    ((s[1] >= '0' && s[1] <= '9') ||
+	    (s[1] >= 'A' && s[1] <= 'F') ||
+	    (s[1] >= 'a' && s[1] <= 'f'))) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	/*
+	 * Compute the cutoff value between legal numbers and illegal
+	 * numbers.  That is the largest legal value, divided by the
+	 * base.  An input number that is greater than this value, if
+	 * followed by a legal input character, is too big.  One that
+	 * is equal to this value may be valid or not; the limit
+	 * between valid and invalid numbers is then based on the last
+	 * digit.  For instance, if the range for quads is
+	 * [-9223372036854775808..9223372036854775807] and the input base
+	 * is 10, cutoff will be set to 922337203685477580 and cutlim to
+	 * either 7 (neg==0) or 8 (neg==1), meaning that if we have
+	 * accumulated a value > 922337203685477580, or equal but the
+	 * next digit is > 7 (or 8), the number is too big, and we will
+	 * return a range error.
+	 *
+	 * Set 'any' if any `digits' consumed; make it negative to indicate
+	 * overflow.
+	 */
+	cutoff = neg ? (unsigned long long)-(LLONG_MIN + LLONG_MAX) + LLONG_MAX
+	    : LLONG_MAX;
+	cutlim = cutoff % base;
+	cutoff /= base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = neg ? LLONG_MIN : LLONG_MAX;
+#ifdef DBUS_WINCE
+		SetLastError (ERROR_ARITHMETIC_OVERFLOW);
+#else
+		errno = ERANGE;
+#endif
+	} else if (!any) {
+noconv:
+#ifdef DBUS_WINCE
+		SetLastError (ERROR_INVALID_PARAMETER);
+#else
+		errno = EINVAL;
+#endif
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}
+
diff --git a/jni/dbus/tools/strtoull.c b/jni/dbus/tools/strtoull.c
new file mode 100644
index 0000000..459c509
--- /dev/null
+++ b/jni/dbus/tools/strtoull.c
@@ -0,0 +1,144 @@
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+
+#include <limits.h>
+#ifdef HAVE_ERRNO_H
+#include <errno.h>
+#endif
+#include <stdlib.h>
+#ifdef DBUS_WINCE
+#include <windows.h>
+#endif
+
+#ifndef isspace
+#define isspace(c) ((c) == ' ' || (c) == '\t' || (c) == '\r' || (c) == '\n')
+#endif
+
+/* Minimum and maximum values a `signed long long int' can hold.  */
+#ifndef LLONG_MAX
+#   define LLONG_MAX	9223372036854775807LL
+#endif
+
+#ifndef LLONG_MIN
+#   define LLONG_MIN	(-LLONG_MAX - 1LL)
+#endif
+/* Maximum value an `unsigned long long int' can hold.  (Minimum is 0.)  */
+#ifndef ULLONG_MAX
+#   define ULLONG_MAX	18446744073709551615ULL
+#endif
+
+/*
+ * Convert a string to an unsigned long long integer.
+ *
+ * Assumes that the upper and lower case
+ * alphabets and digits are each contiguous.
+ */
+unsigned long long strtoull (const char *, char **, int);
+
+unsigned long long
+strtoull(const char * nptr, char ** endptr, int base)
+{
+	const char *s;
+	unsigned long long acc;
+	char c;
+	unsigned long long cutoff;
+	int neg, any, cutlim;
+
+	/*
+	 * See strtoq for comments as to the logic used.
+	 */
+	s = nptr;
+	do {
+		c = *s++;
+	} while (isspace((unsigned char)c));
+	if (c == '-') {
+		neg = 1;
+		c = *s++;
+	} else {
+		neg = 0;
+		if (c == '+')
+			c = *s++;
+	}
+	if ((base == 0 || base == 16) &&
+	    c == '0' && (*s == 'x' || *s == 'X') &&
+	    ((s[1] >= '0' && s[1] <= '9') ||
+	    (s[1] >= 'A' && s[1] <= 'F') ||
+	    (s[1] >= 'a' && s[1] <= 'f'))) {
+		c = s[1];
+		s += 2;
+		base = 16;
+	}
+	if (base == 0)
+		base = c == '0' ? 8 : 10;
+	acc = any = 0;
+	if (base < 2 || base > 36)
+		goto noconv;
+
+	cutoff = ULLONG_MAX / base;
+	cutlim = ULLONG_MAX % base;
+	for ( ; ; c = *s++) {
+		if (c >= '0' && c <= '9')
+			c -= '0';
+		else if (c >= 'A' && c <= 'Z')
+			c -= 'A' - 10;
+		else if (c >= 'a' && c <= 'z')
+			c -= 'a' - 10;
+		else
+			break;
+		if (c >= base)
+			break;
+		if (any < 0 || acc > cutoff || (acc == cutoff && c > cutlim))
+			any = -1;
+		else {
+			any = 1;
+			acc *= base;
+			acc += c;
+		}
+	}
+	if (any < 0) {
+		acc = ULLONG_MAX;
+#ifdef DBUS_WINCE
+		SetLastError (ERROR_ARITHMETIC_OVERFLOW);
+#else
+		errno = ERANGE;
+#endif
+	} else if (!any) {
+noconv:
+#ifdef DBUS_WINCE
+		SetLastError (ERROR_INVALID_PARAMETER);
+#else
+		errno = EINVAL;
+#endif
+	} else if (neg)
+		acc = -acc;
+	if (endptr != NULL)
+		*endptr = (char *)(any ? s - 1 : nptr);
+	return (acc);
+}