soc.2010.detachablepurple: 7c68a82d: Changed the dbus path name of the accoun...
gillux at soc.pidgin.im
gillux at soc.pidgin.im
Fri Jul 16 22:35:46 EDT 2010
----------------------------------------------------------------------
Revision: 7c68a82d985c65c43d04497411a59dea6cb716a4
Parent: 5b3462724abda23a0cbe281274019ca05f81ecff
Author: gillux at soc.pidgin.im
Date: 07/16/10 22:22:29
Branch: im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/7c68a82d985c65c43d04497411a59dea6cb716a4
Changelog:
Changed the dbus path name of the accounts to a more unique and meaningful
name. As dbus path names are quite restrictive, it's now something like :
"/im/pidgin/purple/account/".sanitized(prpl)."/".sanitized(username)
Changes against parent 5b3462724abda23a0cbe281274019ca05f81ecff
patched libpurple/account.c
patched libpurple/dbus-server.c
patched libpurple/dbus-server.h
-------------- next part --------------
============================================================
--- libpurple/account.c 947b0a75e9f388eb9f16b9d4b6959d526b54feb6
+++ libpurple/account.c 43c1303aaa50be688e738471a82358cc6b6669fc
@@ -791,16 +791,19 @@ static char*
}
static char*
-build_dbus_path(const char *username, const char *protocol_id) {
- char* id;
- char* dbus_path;
- guint account_dbus_id;
+build_dbus_path(const char *username, const char *protocol_id)
+{
+ gchar *id;
+ gchar *id2;
- id = g_strjoin(" ", protocol_id, username, NULL);
- account_dbus_id = g_str_hash(id);
+ id = g_strjoin("/", protocol_id, username, NULL);
+ id2 = purple_dbus_sanitize_dbus_path(id);
g_free(id);
- dbus_path = g_strdup_printf("%s/%u", DBUS_ACCOUNT_PATH, account_dbus_id);
- return dbus_path;
+
+ id = g_strjoin("/", DBUS_ACCOUNT_PATH, id2, NULL);
+ g_free(id2);
+
+ return id;
}
PurpleAccount *
============================================================
--- libpurple/dbus-server.c 58292ccd1a423974d69b0e69579bce4d9fc8f88b
+++ libpurple/dbus-server.c 125eec1d615d95ec6d9c0322d2c2fd978c62ac64
@@ -461,6 +461,50 @@ purple_dbus_get_gobj_props(char *interfa
return props_a;
}
+gchar*
+purple_dbus_sanitize_dbus_path(const gchar *str)
+{
+ const gchar* path;
+ gchar *path_valid;
+ gchar *path_valid_parse;
+ guint path_size = 0;
+
+ /* Let's see how many bytes the valid string will take */
+ path = str;
+ while (*path) {
+ if (g_unichar_isalnum(*path) || *path == '/')
+ path_size++;
+ else if (*path < 0x7f)
+ path_size += 4; /* _aXX */
+ else
+ path_size += 6; /* _uNNNN */
+ path = g_utf8_next_char(path);
+ }
+ path_valid = path_valid_parse = g_malloc0(path_size + 1);
+
+ /* Copy each char and sanitize it if needed */
+ path = str;
+ while (*path) {
+ if (g_unichar_isalnum(*path) || *path == '/') {
+ /* Let [A-Za-z0-9/] */
+ *path_valid_parse = *path;
+ path_valid_parse++;
+ } else if (*path < 0x7f) {
+ /* For ASCII chars "_aXX" instead, with X hexadecial */
+ path_valid_parse += sprintf(path_valid_parse,
+ "_a%02x", *path);
+
+ } else {
+ /* For other chars, append "_uNNNN", with N numeric */
+ path_valid_parse += sprintf(path_valid_parse,
+ "_u%04"G_GINT32_FORMAT, *path);
+ }
+ path = g_utf8_next_char(path);
+ }
+
+ return path_valid;
+}
+
/**************************************************************/
/* DBus bindings ... */
/**************************************************************/
============================================================
--- libpurple/dbus-server.h 5859038b15ef078377b6fbf61fc971aed4a5c432
+++ libpurple/dbus-server.h a71515fa2ce59463ba9f91d994a22cf5055697c5
@@ -218,7 +218,19 @@ GPtrArray* purple_dbus_get_gobj_props(ch
GPtrArray* purple_dbus_get_gobj_props(char *interface, const DBusGObjectInfo *infos);
/**
+ * Sanitize a given string so that it can be used as a valid dbus path.
+ * The dbus spec says it have to consist of [A-Za-z0-9_/] chars.
+ * http://dbus.freedesktop.org/doc/dbus-specification.html#message-protocol-marshaling-object-path
+ * The given string MUST be utf8 valid, otherwise results are undefined.
+ *
+ * @param str The string you want to use as a (part of a) dbus path.
+ * @return A new g_alloc() allocated string which can be use as (a part of) a
+ * dbus path.
+ */
+gchar* purple_dbus_sanitize_dbus_path(const gchar *str);
+/**
+
Macro #DBUS_EXPORT expands to nothing. It is used to indicate to the
dbus-analyze-functions.py script that the given function should be
available to other applications through DBUS. If
More information about the Commits
mailing list