]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Mon, 6 Aug 2012 10:19:31 +0000 (12:19 +0200)
committerArvin Schnell <aschnell@suse.de>
Mon, 6 Aug 2012 10:19:31 +0000 (12:19 +0200)
dbus/DBusMessage.cc
dbus/DBusMessage.h
doc/dbus-protocol.txt

index 3f6265cb701428543b87d9fc5e3aa4f6bcd48b00..c806eadd4c96ec7bb81488981c1614d34b2db4a3 100644 (file)
@@ -270,6 +270,56 @@ namespace DBus
        return hoho;
     }
 
+
+    string
+    Hihi::unescape(const string& in)
+    {
+       string out;
+
+       for (string::const_iterator it = in.begin(); it != in.end(); ++it)
+       {
+           if (*it == '\\')
+           {
+               if (++it == in.end())
+                   throw MarshallingException();
+
+               if (*it == '\\')
+               {
+                   out += '\\';
+               }
+               else if (*it == 'x')
+               {
+                   if (++it == in.end())
+                       throw MarshallingException();
+
+                   string t1;
+
+                   if (!isxdigit(*it))
+                       throw MarshallingException();
+                   t1 += *it;
+
+                   if ((it + 1) != in.end() && isxdigit(*(it + 1)))
+                       t1 += *++it;
+
+                   unsigned int t2;
+                   sscanf(t1.c_str(), "%x", &t2);
+                   out.append(1, (unsigned char)(t2));
+               }
+               else
+               {
+                   throw MarshallingException();
+               }
+           }
+           else
+           {
+               out += *it;
+           }
+       }
+
+       return out;
+    }
+
+
     Hihi&
     operator>>(Hihi& hihi, string& data)
     {
@@ -279,16 +329,44 @@ namespace DBus
        const char* p = NULL;
        dbus_message_iter_get_basic(hihi.top(), &p);
        dbus_message_iter_next(hihi.top());
-       data = p;
+       data = hihi.unescape(p);
 
        return hihi;
     }
 
 
+    string
+    Hoho::escape(const string& in)
+    {
+       string out;
+
+       for (string::const_iterator it = in.begin(); it != in.end(); ++it)
+       {
+           if (*it == '\\')
+           {
+               out += "\\\\";
+           }
+           else if ((unsigned char)(*it) > 127)
+           {
+               char s[5];
+               snprintf(s, 5, "\\x%x", (unsigned char)(*it));
+               out += string(s);
+           }
+           else
+           {
+               out += *it;
+           }
+       }
+
+       return out;
+    }
+
+
     Hoho&
     operator<<(Hoho& hoho, const string& data)
     {
-       const char* p = data.c_str();
+       string tmp = hoho.escape(data);
+       const char* p = tmp.c_str();
        dbus_message_iter_append_basic(hoho.top(), DBUS_TYPE_STRING, &p);
 
        return hoho;
index e9e8e6b4412fc8f86d249c15ac6290aa94bc247f..0712c69828bc82675769129c9247ec47c401ac41 100644 (file)
@@ -195,6 +195,8 @@ namespace DBus
        void open_recurse();
        void close_recurse();
 
+       static string unescape(const string&);
+
     };
 
 
@@ -215,6 +217,8 @@ namespace DBus
        void open_dict_entry();
        void close_dict_entry();
 
+       static string escape(const string&);
+
     };
 
 
index 3616fa92a6dce592e85a9625a1831c1a75612897..fbf1d1cc8b5c23b766f1478a09285a693b60bb57 100644 (file)
@@ -54,3 +54,5 @@ method DoUndoStep config-name number1 number2 undo_step
 
 Filenames do not include the subvolume.
 
+Strings are UTF-8. Other characters (e.g. in filenames) must be encoded
+hexadecimal as "\x?" or "\x??". As a consequence "\" must be encoded as "\\".