aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Albinus2008-11-26 06:09:44 +0000
committerMichael Albinus2008-11-26 06:09:44 +0000
commit82697a456dec3ec1d625edb622d65494d5a8f8f2 (patch)
tree297d5bfbc14fb5d80a11e739f9989874765e91fe
parent1d7e9a015e4dd3434ddbd37a3c24971e0afcc09f (diff)
downloademacs-82697a456dec3ec1d625edb622d65494d5a8f8f2.tar.gz
emacs-82697a456dec3ec1d625edb622d65494d5a8f8f2.zip
* net/dbus.el (dbus-string-to-byte-array)
(dbus-byte-array-to-string, dbus-escape-as-identifier) (dbus-unescape-from-identifier): New defuns. (dbus-handle-event): The result of a message call is a list of arguments, which must be expanded when passing to `dbus-method-return-internal'.
-rw-r--r--lisp/net/dbus.el51
1 files changed, 50 insertions, 1 deletions
diff --git a/lisp/net/dbus.el b/lisp/net/dbus.el
index 53eb4b57070..5c7e719e305 100644
--- a/lisp/net/dbus.el
+++ b/lisp/net/dbus.el
@@ -242,6 +242,55 @@ usage: (dbus-name-owner-changed-handler service old-owner new-owner)"
242 "NameOwnerChanged" 'dbus-name-owner-changed-handler)) 242 "NameOwnerChanged" 'dbus-name-owner-changed-handler))
243 243
244 244
245;;; D-Bus type conversion.
246
247(defun dbus-string-to-byte-array (string)
248 "Transforms STRING to list (:array :byte c1 :byte c2 ...).
249STRING shall be UTF8 coded."
250 (let (result)
251 (dolist (elt (string-to-list string) (append '(:array) result))
252 (setq result (append result (list :byte elt))))))
253
254(defun dbus-byte-array-to-string (byte-array)
255 "Transforms BYTE-ARRAY into UTF8 coded string.
256BYTE-ARRAY must be a list of structure (c1 c2 ...)."
257 (apply 'string byte-array))
258
259(defun dbus-escape-as-identifier (string)
260 "Escape an arbitrary STRING so it follows the rules for a C identifier.
261The escaped string can be used as object path component, interface element
262component, bus name component or member name in D-Bus.
263
264The escaping consists of replacing all non-alphanumerics, and the
265first character if it's a digit, with an underscore and two
266lower-case hex digits:
267
268 \"0123abc_xyz\\x01\\xff\" -> \"_30123abc_5fxyz_01_ff\"
269
270i.e. similar to URI encoding, but with \"_\" taking the role of \"%\",
271and a smaller allowed set. As a special case, \"\" is escaped to
272\"_\".
273
274Returns the escaped string. Algorithm taken from
275telepathy-glib's `tp-escape-as-identifier'."
276 (if (zerop (length string))
277 "_"
278 (replace-regexp-in-string
279 "^[0-9]\\|[^A-Za-z0-9]"
280 (lambda (x) (format "_%2x" (aref x 0)))
281 string)))
282
283(defun dbus-unescape-from-identifier (string)
284 "Retrieve the original string from the encoded STRING.
285STRING must have been coded with `dbus-escape-as-identifier'"
286 (if (string-equal string "_")
287 ""
288 (replace-regexp-in-string
289 "_.."
290 (lambda (x) (format "%c" (string-to-number (substring x 1) 16)))
291 string)))
292
293
245;;; D-Bus events. 294;;; D-Bus events.
246 295
247(defun dbus-check-event (event) 296(defun dbus-check-event (event)
@@ -312,7 +361,7 @@ If the HANDLER returns an `dbus-error', it is propagated as return message."
312 ;; Return a message when it is a message call. 361 ;; Return a message when it is a message call.
313 (when (= dbus-message-type-method-call (nth 2 event)) 362 (when (= dbus-message-type-method-call (nth 2 event))
314 (dbus-ignore-errors 363 (dbus-ignore-errors
315 (dbus-method-return-internal 364 (apply 'dbus-method-return-internal
316 (nth 1 event) (nth 3 event) (nth 4 event) result)))) 365 (nth 1 event) (nth 3 event) (nth 4 event) result))))
317 ;; Error handling. 366 ;; Error handling.
318 (dbus-error 367 (dbus-error