soc.2010.detachablepurple: abe8d3be: Basically wrapped the request_authorize ...
gillux at soc.pidgin.im
gillux at soc.pidgin.im
Sat Jul 31 01:35:58 EDT 2010
----------------------------------------------------------------------
Revision: abe8d3bed00bc83438a18800b40fa538a71ea4e2
Parent: 535b89550cc586eab898d7f6ed2636c7b67e1bb0
Author: gillux at soc.pidgin.im
Date: 07/30/10 00:11:38
Branch: im.pidgin.soc.2010.detachablepurple
URL: http://d.pidgin.im/viewmtn/revision/info/abe8d3bed00bc83438a18800b40fa538a71ea4e2
Changelog:
Basically wrapped the request_authorize account uiop. The daemon can send
a RequestAuthorize signal, and a client may answer it using the existing
RunRequest method. Note the logic of this code is not multiclient yet, but
works for a 1:1 detachable sessions context.
Changes against parent 535b89550cc586eab898d7f6ed2636c7b67e1bb0
patched libpurple/account-dbus.c
patched libpurple/dbus-prototypes/account.xml
patched libpurple/marshallers.list
patched purpled/purpled-account.c
-------------- next part --------------
============================================================
--- libpurple/marshallers.list c8758ea42a367d3e73fc8a62aa1886f446cba2b8
+++ libpurple/marshallers.list b9acaa6e0fa6b897e7da8bf33ac343f89f3e199a
@@ -18,3 +18,5 @@ VOID:STRING,STRING,STRING,STRING
VOID:UINT64,BOXED
# Marshaller for the NotifyAdded and RequestAdd dbus signal
VOID:STRING,STRING,STRING,STRING
+# Marshaller for the RequestAuthorize dbus signal
+VOID:STRING,STRING,STRING,STRING,BOOLEAN,UINT
============================================================
--- libpurple/account-dbus.c b61288b14dcd6c391f6cdb31aee49557fab1b509
+++ libpurple/account-dbus.c ea6719cd5930a846ebe3fb29baec9f592905565a
@@ -36,6 +36,55 @@ request_add_cb(DBusGProxy *proxy, const
purple_account_request_add(account, remote_user, id, alias, message);
}
+/**
+ * Callback called on the client when the user accepted an auth request.
+ * It runs the RunRequest method on the daemon, with the original request id,
+ * and the request choice number 0 (authorized).
+ */
+static void
+request_remote_client_auth_cb(void *user_data)
+{
+ guint request_id = GPOINTER_TO_INT(user_data);
+ g_return_if_fail(request_id != 0);
+ purple_callback_run_request_RPC(request_id, 0);
+}
+
+/**
+ * Callback called on the client when the user denied an auth request.
+ * It runs the RunRequest method on the daemon, with the original request id,
+ * and the request choice number 1 (denied).
+ */
+static void
+request_remote_client_deny_cb(void *user_data)
+{
+ guint request_id = GPOINTER_TO_INT(user_data);
+ g_return_if_fail(request_id != 0);
+ purple_callback_run_request_RPC(request_id, 1);
+}
+
+/**
+ * Callback, called when we receive a dbus "RequestAuthorize" signal.
+ */
+static void
+request_authorize_cb(DBusGProxy *proxy, const char *remote_user,
+ const char *id, const char *alias, const char *message,
+ gboolean on_list, guint request_id, gpointer data)
+{
+ void *h;
+ PurpleAccount* account = PURPLE_ACCOUNT(
+ purple_dbus_get_gobject_by_path(dbus_g_proxy_get_path(proxy)));
+
+ g_return_if_fail(account != NULL);
+
+ /* This calls the local request_authorize account uiop, with our
+ * own auth/deny callbacks defined above. */
+ h = purple_account_request_authorization(account, remote_user, id,
+ alias, message, on_list,
+ request_remote_client_auth_cb,
+ request_remote_client_deny_cb,
+ GINT_TO_POINTER(request_id));
+}
+
static char*
build_dbus_path(const char *username, const char *protocol_id)
{
@@ -74,6 +123,12 @@ purple_account_class_dbus_init(void)
purple_smarshal_VOID__STRING_STRING_STRING_STRING,
G_TYPE_NONE, 4, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING);
+ g_signal_new("request_authorize",
+ PURPLE_TYPE_ACCOUNT, G_SIGNAL_RUN_LAST, 0, NULL, NULL,
+ purple_smarshal_VOID__STRING_STRING_STRING_STRING_BOOLEAN_UINT,
+ G_TYPE_NONE, 6,
+ G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+ G_TYPE_BOOLEAN, G_TYPE_UINT);
}
/* In remote mode we need to register the marshallers
* we will use to receive the signals sent by the daemon */
@@ -83,7 +138,11 @@ purple_account_class_dbus_init(void)
purple_smarshal_VOID__STRING_STRING_STRING_STRING,
G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING,
G_TYPE_STRING, G_TYPE_STRING, G_TYPE_INVALID);
-
+ /* Marshaller for the RequestAuthorize dbus signal */
+ dbus_g_object_register_marshaller(
+ purple_smarshal_VOID__STRING_STRING_STRING_STRING_BOOLEAN_UINT,
+ G_TYPE_NONE, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_UINT, G_TYPE_INVALID);
}
}
@@ -113,6 +172,14 @@ purple_account_dbus_init(PurpleAccount *
dbus_g_proxy_connect_signal(proxy, "RequestAdd",
G_CALLBACK(request_add_cb),
account, NULL);
+ dbus_g_proxy_add_signal(proxy, "RequestAuthorize",
+ G_TYPE_STRING, G_TYPE_STRING,
+ G_TYPE_STRING, G_TYPE_STRING,
+ G_TYPE_BOOLEAN, G_TYPE_UINT,
+ G_TYPE_INVALID);
+ dbus_g_proxy_connect_signal(proxy, "RequestAuthorize",
+ G_CALLBACK(request_authorize_cb),
+ account, NULL);
}
}
============================================================
--- libpurple/dbus-prototypes/account.xml 5a9b4dbdcb29375dc1efae35b66e31b51ce07b56
+++ libpurple/dbus-prototypes/account.xml c1d45804b0d90321fbc8d1694f0dbfb394e2c001
@@ -39,5 +39,13 @@
<arg type="s" name="alias" />
<arg type="s" name="message" />
</signal>
+ <signal name="RequestAuthorize">
+ <arg type="s" name="remote_user" />
+ <arg type="s" name="id" />
+ <arg type="s" name="alias" />
+ <arg type="s" name="message" />
+ <arg type="b" name="on_list" />
+ <arg type="u" name="request_id" />
+ </signal>
</interface>
</node>
============================================================
--- purpled/purpled-account.c 3c4eec33cde3fd0622f138a75c92bda5712ae1e4
+++ purpled/purpled-account.c c9ae5fad090fa0906cec1c21e57bfb1ffc256ca4
@@ -21,6 +21,8 @@
#include "internal.h"
#include "account.h"
+#include "dbus-callback.h"
+#include "nullmarshaller.h"
#include "purpled-account.h"
/**
@@ -49,12 +51,46 @@ purpled_account_request_add(PurpleAccoun
remote_user, id, alias, message);
}
+/**
+ * PurpleAccountUiOps.request_authorize daemon iuop.
+ * Sends the RequestAuthorize dbus signal and return a unique request id
+ * as the ui_handle.
+ */
+static void *
+purpled_account_request_authorize(PurpleAccount *account,
+ const char *remote_user, const char *id,
+ const char *alias, const char *message,
+ gboolean on_list,
+ PurpleAccountRequestAuthorizationCb auth_cb,
+ PurpleAccountRequestAuthorizationCb deny_cb,
+ void *data)
+{
+ guint req_id;
+ GClosure *auth_closure;
+ GClosure *deny_closure;
+
+ /* Store the callbacks for later call, by a RunRequest dbus method on
+ * the PurpleDBusCallback object */
+ auth_closure = g_cclosure_new(G_CALLBACK(auth_cb), data, NULL);
+ deny_closure = g_cclosure_new(G_CALLBACK(deny_cb), data, NULL);
+ g_closure_set_marshal(auth_closure, purpled_nullmarshaller);
+ g_closure_set_marshal(deny_closure, purpled_nullmarshaller);
+ req_id = purple_callback_register_req(2, auth_closure, deny_closure);
+ g_return_val_if_fail(req_id > 0, NULL);
+
+ /* Send the RequestAuthorize dbus signal with this new request id */
+ g_signal_emit_by_name(account, "request_authorize", remote_user, id,
+ alias, message, on_list, req_id);
+
+ return GINT_TO_POINTER(req_id);
+}
+
static PurpleAccountUiOps purpled_account_ui_ops =
{
purpled_account_notify_added, /* notify_added */
NULL, /* status_changed */
purpled_account_request_add, /* request_add */
- NULL, /* request_authorize */
+ purpled_account_request_authorize, /* request_authorize */
NULL, /* close_account_request */
NULL, /* _purple_reserved1 */
NULL, /* _purple_reserved2 */
More information about the Commits
mailing list