wip: automatically calculate request id, start implementing whoami

This commit is contained in:
Gergely Polonkai 2019-01-09 09:09:01 +01:00
parent 373d9ace84
commit 80178d5406
2 changed files with 31 additions and 1 deletions

View File

@ -26,6 +26,7 @@ struct _SsbScuttler {
gboolean wrote_goodbye; gboolean wrote_goodbye;
GSocketClient *socket_client; GSocketClient *socket_client;
GSocketConnection *connection; GSocketConnection *connection;
guint request_id;
}; };
typedef enum { typedef enum {
@ -816,11 +817,11 @@ ssb_scuttler_muxrpc_call(SsbScuttler *scuttler,
const gchar *argument, const gchar *argument,
SsbRPCType type, SsbRPCType type,
const gchar *typestr, const gchar *typestr,
int req_id,
GError **error) GError **error)
{ {
gchar *request; gchar *request;
gsize request_len; gsize request_len;
gint req_id;
gboolean is_request = (type == SSB_RPC_ASYNC); gboolean is_request = (type == SSB_RPC_ASYNC);
JsonObject *req_object = json_object_new(); JsonObject *req_object = json_object_new();
JsonNode *req_node = json_node_new(JSON_NODE_OBJECT); JsonNode *req_node = json_node_new(JSON_NODE_OBJECT);
@ -843,6 +844,8 @@ ssb_scuttler_muxrpc_call(SsbScuttler *scuttler,
return; return;
} }
req_id = g_atomic_int_add(&(scuttler->request_id), 1);
if (!ssb_scuttler_send_packet(scuttler, SSB_PACKET_TYPE_JSON, request, request_len, req_id, !is_request, FALSE, &err)) { if (!ssb_scuttler_send_packet(scuttler, SSB_PACKET_TYPE_JSON, request, request_len, req_id, !is_request, FALSE, &err)) {
g_propagate_error(error, err); g_propagate_error(error, err);
@ -939,6 +942,31 @@ ssb_scuttler_class_init(SsbScuttlerClass *klass)
g_object_class_install_properties(gobject_class, PROP_COUNT, ssb_scuttler_properties); g_object_class_install_properties(gobject_class, PROP_COUNT, ssb_scuttler_properties);
} }
void
ssb_scuttler_whoami_async(SsbScuttler *scuttler,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
{
GTask *task;
GError *err = NULL;
g_return_if_fail(SSB_IS_SCUTTLER(scuttler));
g_return_if_fail((cancellable == NULL) || G_IS_CANCELLABLE(cancellable));
task = g_task_new(scuttler, cancellable, callback, user_data);
if (!scuttler->connection) {
g_task_return_new_error(task, SSB_SCUTTLER_ERROR, SSB_SCUTTLER_ERROR_NOTCONNECTED, "Scuttler is not connected");
g_object_unref(task);
return;
}
ssb_scuttler_muxrpc_call(scuttler, "whoami", NULL, SSB_RPC_ASYNC, NULL, &err);
}
static void static void
ssb_scuttler_init(SsbScuttler *scuttler) ssb_scuttler_init(SsbScuttler *scuttler)
{ {
@ -949,6 +977,7 @@ ssb_scuttler_init(SsbScuttler *scuttler)
scuttler->app_key = NULL; scuttler->app_key = NULL;
scuttler->private_key = NULL; scuttler->private_key = NULL;
scuttler->encrypt_key = NULL; scuttler->encrypt_key = NULL;
scuttler->request_id = 0;
} }
SsbScuttler * SsbScuttler *

View File

@ -14,6 +14,7 @@ typedef enum {
SSB_SCUTTLER_ERROR_AUTH, SSB_SCUTTLER_ERROR_AUTH,
SSB_SCUTTLER_ERROR_REQUEST_TOO_LARGE, SSB_SCUTTLER_ERROR_REQUEST_TOO_LARGE,
SSB_SCUTTLER_ERROR_SEND, SSB_SCUTTLER_ERROR_SEND,
SSB_SCUTTLER_ERROR_NOTCONNECTED,
} SsbScuttlerError; } SsbScuttlerError;
G_BEGIN_DECLS G_BEGIN_DECLS