Escaping for paths

Havoc Pennington hp at redhat.com
Wed Jun 21 15:56:09 PDT 2006



Ross Burton wrote:
> 
> I'm not sure bus names would need escaping, but maybe somebody will
> surprise me.
> 

Mugshot uses bus name escaping to get a unique instance for each server 
(server domain name and port in the bus name), which is maybe lame, but 
made sense to me at the time...

The algorithm I used is:

    static const char hexdigits[16] =
         { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
           'A', 'B', 'C', 'D', 'E', 'F' };

    while (*p) {
         if ((*p >= 'a' && *p <= 'z') ||
             (*p >= 'A' && *p <= 'Z') ||
             (*p >= '0' && *p <= '9')) {
             g_string_append_c(str, *p);
         } else {
             g_string_append_c(str, '_');
             g_string_append_c(str, hexdigits[(*p) & 0xf]);
             g_string_append_c(str, hexdigits[(*p) >> 4]);
         }
         ++p;
     }

If that's buggy please let me know ;-)

Havoc


More information about the dbus mailing list