[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] emacs/lisp/net dbus.el
From: |
Michael Albinus |
Subject: |
[Emacs-diffs] emacs/lisp/net dbus.el |
Date: |
Wed, 26 Nov 2008 06:09:45 +0000 |
CVSROOT: /sources/emacs
Module name: emacs
Changes by: Michael Albinus <albinus> 08/11/26 06:09:45
Modified files:
lisp/net : dbus.el
Log message:
* 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'.
CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/emacs/lisp/net/dbus.el?cvsroot=emacs&r1=1.23&r2=1.24
Patches:
Index: dbus.el
===================================================================
RCS file: /sources/emacs/emacs/lisp/net/dbus.el,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- dbus.el 12 Oct 2008 20:07:06 -0000 1.23
+++ dbus.el 26 Nov 2008 06:09:44 -0000 1.24
@@ -242,6 +242,55 @@
"NameOwnerChanged" 'dbus-name-owner-changed-handler))
+;;; D-Bus type conversion.
+
+(defun dbus-string-to-byte-array (string)
+ "Transforms STRING to list (:array :byte c1 :byte c2 ...).
+STRING shall be UTF8 coded."
+ (let (result)
+ (dolist (elt (string-to-list string) (append '(:array) result))
+ (setq result (append result (list :byte elt))))))
+
+(defun dbus-byte-array-to-string (byte-array)
+ "Transforms BYTE-ARRAY into UTF8 coded string.
+BYTE-ARRAY must be a list of structure (c1 c2 ...)."
+ (apply 'string byte-array))
+
+(defun dbus-escape-as-identifier (string)
+ "Escape an arbitrary STRING so it follows the rules for a C identifier.
+The escaped string can be used as object path component, interface element
+component, bus name component or member name in D-Bus.
+
+The escaping consists of replacing all non-alphanumerics, and the
+first character if it's a digit, with an underscore and two
+lower-case hex digits:
+
+ \"0123abc_xyz\\x01\\xff\" -> \"_30123abc_5fxyz_01_ff\"
+
+i.e. similar to URI encoding, but with \"_\" taking the role of \"%\",
+and a smaller allowed set. As a special case, \"\" is escaped to
+\"_\".
+
+Returns the escaped string. Algorithm taken from
+telepathy-glib's `tp-escape-as-identifier'."
+ (if (zerop (length string))
+ "_"
+ (replace-regexp-in-string
+ "^[0-9]\\|[^A-Za-z0-9]"
+ (lambda (x) (format "_%2x" (aref x 0)))
+ string)))
+
+(defun dbus-unescape-from-identifier (string)
+ "Retrieve the original string from the encoded STRING.
+STRING must have been coded with `dbus-escape-as-identifier'"
+ (if (string-equal string "_")
+ ""
+ (replace-regexp-in-string
+ "_.."
+ (lambda (x) (format "%c" (string-to-number (substring x 1) 16)))
+ string)))
+
+
;;; D-Bus events.
(defun dbus-check-event (event)
@@ -312,7 +361,7 @@
;; Return a message when it is a message call.
(when (= dbus-message-type-method-call (nth 2 event))
(dbus-ignore-errors
- (dbus-method-return-internal
+ (apply 'dbus-method-return-internal
(nth 1 event) (nth 3 event) (nth 4 event) result))))
;; Error handling.
(dbus-error
- [Emacs-diffs] emacs/lisp/net dbus.el,
Michael Albinus <=