Encoding misc things into object paths

Simon McVittie simon.mcvittie at collabora.co.uk
Sat Jul 19 04:51:27 PDT 2008

On Sat, 19 Jul 2008 at 04:47:00 -0400, Colin Walters wrote:
> Don't try to create a human-readable string for the object as the
> restrictions on names in the object path will likely trip you up.  This has
> happened now with both HAL and NetworkManager.  Or if you do, be really sure
> you URL quote it everywhere.

In Telepathy we deliberately create human-readable strings to make
debugging easier. We have a function tp_escape_as_identifier() (see
telepathy-glib/util.c in telepathy-glib, available from
http://darcs.collabora.co.uk/ or
http://telepathy.freedesktop.org/releases/telepathy-glib/) which
performs the name-mangling. It's basically like URL quoting but more so:

the empty string -> "_" (special-cased)
[A-Za-z] -> themselves
[0-9] -> _30 to _39 if at the beginning of the string
[0-9] -> themselves if not at the beginning of the string
anything else -> _xx where xx is its lower-case hex representation (%02x)

This is a reversible encoding, so it preserves uniqueness (although
we've never actually written a function to decode it, since whenever
these strings appear in our API, we don't offer any API guarantees about

The result (assuming it's not too long) is a valid C identifier,
object-path component, bus-name component, and member name, and is
reasonably comprehensible when it appears in debug logs or dbus-monitor or
telepathy-inspector output.

telepathy-glib is LGPL 2.1+, so you're welcome to copy the code from util.c
under those terms.

There's also a Python implementation of the same algorithm somewhere
in the tools/ directory of telepathy-glib (we use it to mangle D-Bus
signatures into C function names in generated code).

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 155 bytes
Desc: Digital signature
Url : http://lists.freedesktop.org/archives/dbus/attachments/20080719/4254098e/attachment.pgp 

More information about the dbus mailing list