diff options
author | Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com> | 2012-04-22 22:12:19 +0200 |
---|---|---|
committer | Carl-Anton Ingmarsson <ca.ingmarsson@gmail.com> | 2012-08-09 21:06:05 +0200 |
commit | 319c19830c49f8b4c10f40f763db95fe402e38cb (patch) | |
tree | 87969cbe712257395488e0686fd0e29615c04ead /daemon/gvfsafpserver.c | |
parent | 98752a60b30575bc22375626f2c226cfdca04adf (diff) | |
download | gvfs-319c19830c49f8b4c10f40f763db95fe402e38cb.tar.gz |
afp: move map_id function to GVfsAfpServer
also rename the AfpMapIDFunction enum to GVfsAfpMapIDFunction and move it into
gvfsafpserver.h.
Diffstat (limited to 'daemon/gvfsafpserver.c')
-rw-r--r-- | daemon/gvfsafpserver.c | 175 |
1 files changed, 175 insertions, 0 deletions
diff --git a/daemon/gvfsafpserver.c b/daemon/gvfsafpserver.c index 74310403..5b0e248d 100644 --- a/daemon/gvfsafpserver.c +++ b/daemon/gvfsafpserver.c @@ -1559,4 +1559,179 @@ g_vfs_afp_server_fill_info (GVfsAfpServer *server, else set_access_attributes (info, (permissions >> 0) & 0x7); } +} + +typedef struct +{ + GVfsAfpMapIDFunction function; + char *name; +} MapIDData; + +static void +map_id_data_free (MapIDData *mid) +{ + g_free (mid->name); + + g_slice_free (MapIDData, mid); +} + +static void +map_id_cb (GObject *source_object, GAsyncResult *res, gpointer user_data) +{ + GVfsAfpConnection *conn = G_VFS_AFP_CONNECTION (source_object); + GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (user_data); + + GVfsAfpReply *reply; + GError *err = NULL; + + AfpResultCode res_code; + MapIDData *map_data; + + reply = g_vfs_afp_connection_send_command_finish (conn, res, &err); + if (!reply) + { + g_simple_async_result_take_error (simple, err); + g_simple_async_result_complete (simple); + return; + } + + res_code = g_vfs_afp_reply_get_result_code (reply); + if (res_code != AFP_RESULT_NO_ERROR) + { + switch (res_code) + { + case AFP_RESULT_ITEM_NOT_FOUND: + g_simple_async_result_set_error (simple, G_IO_ERROR, G_IO_ERROR_FAILED, + _("ID not found")); + break; + default: + g_simple_async_result_take_error (simple, afp_result_code_to_gerror (res_code)); + break; + } + + g_simple_async_result_complete (simple); + return; + } + + map_data = g_simple_async_result_get_op_res_gpointer (simple); + + if (map_data->function == GVFS_AFP_MAP_ID_FUNCTION_USER_UUID_TO_UTF8_NAME || + map_data->function == GVFS_AFP_MAP_ID_FUNCTION_GROUP_UUID_TO_UTF8_NAME) + { + /* objType */ + g_vfs_afp_reply_read_uint32 (reply, NULL); + /* id */ + g_vfs_afp_reply_read_uint32 (reply, NULL); + } + + if (map_data->function == GVFS_AFP_MAP_ID_FUNCTION_USER_ID_TO_NAME || + map_data->function == GVFS_AFP_MAP_ID_FUNCTION_GROUP_ID_TO_NAME) + { + g_vfs_afp_reply_read_pascal (reply, &map_data->name); + } + else + { + GVfsAfpName *afp_name; + + g_vfs_afp_reply_read_afp_name (reply, FALSE, &afp_name); + map_data->name = g_vfs_afp_name_get_string (afp_name); + g_vfs_afp_name_unref (afp_name); + } + + g_simple_async_result_complete (simple); +} + +/* + * g_vfs_afp_server_map_id: + * + * @server: a #GVfsAfpServer. + * @map_function: a #GVfsAfpMapIDFunction. + * @id: the id to be mapped to a name. + * @cancellable: optional #GCancellable object, %NULL to ignore. + * @callback: callback to call when the request is satisfied. + * @user_data: the data to pass to callback function. + * + * Asynchronously maps a user id, group id or uuid to a name. + */ +void +g_vfs_afp_server_map_id (GVfsAfpServer *server, + GVfsAfpMapIDFunction map_function, + gint64 id, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ + GVfsAfpServerPrivate *priv; + GVfsAfpCommand *comm; + GSimpleAsyncResult *simple; + MapIDData *map_data; + + g_return_if_fail (G_VFS_IS_AFP_SERVER (server)); + + priv = server->priv; + + comm = g_vfs_afp_command_new (AFP_COMMAND_MAP_ID); + + /* SubFunction*/ + g_vfs_afp_command_put_byte (comm, map_function); + + /* ID */ + if (map_function == GVFS_AFP_MAP_ID_FUNCTION_USER_ID_TO_NAME || + map_function == GVFS_AFP_MAP_ID_FUNCTION_GROUP_ID_TO_NAME) + g_vfs_afp_command_put_int32 (comm, id); + else + g_vfs_afp_command_put_int64 (comm, id); + + simple = g_simple_async_result_new (G_OBJECT (server), callback, + user_data, g_vfs_afp_server_map_id); + + map_data = g_slice_new0 (MapIDData); + map_data->function = map_function; + g_simple_async_result_set_op_res_gpointer (simple, map_data, + (GDestroyNotify)map_id_data_free); + + g_vfs_afp_connection_send_command (priv->conn, comm, NULL, + map_id_cb, cancellable, simple); + g_object_unref (comm); +} + +/* + * g_vfs_afp_server_map_id_finish: + * + * @server: a #GVfsAfpServer. + * @result: a #GAsyncResult. + * @map_function: (out) optional out parameter to get the #GVfsAfpMapIDFunction + * which was used, %NULL to ignore. + * @error: a #GError, %NULL to ignore. + * + * Finalizes the asynchronous operation started by + * g_vfs_afp_server_map_id. + * + * Returns: (transfer full): A string with the name of the id or %NULL + * on error. + */ +char * +g_vfs_afp_server_map_id_finish (GVfsAfpServer *server, + GAsyncResult *res, + GVfsAfpMapIDFunction *map_function, + GError **error) +{ + GSimpleAsyncResult *simple; + MapIDData *map_data; + + g_return_val_if_fail (g_simple_async_result_is_valid (res, G_OBJECT (server), + g_vfs_afp_server_map_id), + NULL); + + simple = (GSimpleAsyncResult *)res; + + if (g_simple_async_result_propagate_error (simple, error)) + return NULL; + + map_data = g_simple_async_result_get_op_res_gpointer (simple); + + if (map_function) + *map_function = map_data->function; + + return g_strdup (map_data->name); }
\ No newline at end of file |