|
@@ -18,11 +18,8 @@
|
|
|
|
|
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
#include <stdio.h>
|
|
#include <stdio.h>
|
|
|
-#include <json-glib/json-glib.h>
|
|
|
|
|
#include <libsoup/soup.h>
|
|
#include <libsoup/soup.h>
|
|
|
-#include "iridium-crypto.h"
|
|
|
|
|
#include "iridium-standard-file.h"
|
|
#include "iridium-standard-file.h"
|
|
|
-#include "iridium-note.h"
|
|
|
|
|
|
|
|
|
|
typedef struct {
|
|
typedef struct {
|
|
|
IridiumStandardFile *client;
|
|
IridiumStandardFile *client;
|
|
@@ -298,8 +295,6 @@ on_sync_response_parsed (GObject *object,
|
|
|
GTask *task;
|
|
GTask *task;
|
|
|
IridiumAuthParams *auth_params;
|
|
IridiumAuthParams *auth_params;
|
|
|
JsonParser *parser;
|
|
JsonParser *parser;
|
|
|
- JsonObject *root;
|
|
|
|
|
- JsonArray *array;
|
|
|
|
|
GList *items = NULL;
|
|
GList *items = NULL;
|
|
|
GError *error = NULL;
|
|
GError *error = NULL;
|
|
|
|
|
|
|
@@ -312,37 +307,7 @@ on_sync_response_parsed (GObject *object,
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- root = json_node_get_object (json_parser_get_root (parser));
|
|
|
|
|
- array = json_object_get_array_member (root, "retrieved_items");
|
|
|
|
|
-
|
|
|
|
|
- for (guint i = 0; i < json_array_get_length (array); i++) {
|
|
|
|
|
- JsonObject *data;
|
|
|
|
|
- GObject *item;
|
|
|
|
|
- const gchar *uuid;
|
|
|
|
|
- const gchar *enc_item_key;
|
|
|
|
|
- const gchar *enc_content;
|
|
|
|
|
- gchar *content;
|
|
|
|
|
-
|
|
|
|
|
- data = json_array_get_object_element (array, i);
|
|
|
|
|
- uuid = json_object_get_string_member (data, "uuid");
|
|
|
|
|
- enc_item_key = json_object_get_string_member (data, "enc_item_key");
|
|
|
|
|
-
|
|
|
|
|
- if (!g_strcmp0 (enc_item_key, ""))
|
|
|
|
|
- continue;
|
|
|
|
|
-
|
|
|
|
|
- enc_content = json_object_get_string_member (data, "content");
|
|
|
|
|
- content = iridium_crypto_decrypt_item (enc_content, auth_params, enc_item_key, uuid);
|
|
|
|
|
-
|
|
|
|
|
- if (content) {
|
|
|
|
|
- item = deserialize_item (data, content);
|
|
|
|
|
-
|
|
|
|
|
- if (item)
|
|
|
|
|
- items = g_list_append (items, item);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- g_free (content);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ items = iridium_standard_file_get_items (parser, auth_params, &error);
|
|
|
g_task_return_pointer (task, items, NULL);
|
|
g_task_return_pointer (task, items, NULL);
|
|
|
g_object_unref (parser);
|
|
g_object_unref (parser);
|
|
|
}
|
|
}
|
|
@@ -380,6 +345,49 @@ iridium_standard_file_load_finish (IridiumStandardFile *client,
|
|
|
return g_task_propagate_pointer (G_TASK (result), error);
|
|
return g_task_propagate_pointer (G_TASK (result), error);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+GList *
|
|
|
|
|
+iridium_standard_file_get_items (JsonParser *parser,
|
|
|
|
|
+ IridiumAuthParams *auth_params,
|
|
|
|
|
+ GError **error)
|
|
|
|
|
+{
|
|
|
|
|
+ JsonObject *root;
|
|
|
|
|
+ JsonArray *array;
|
|
|
|
|
+ GList *items = NULL;
|
|
|
|
|
+
|
|
|
|
|
+ root = json_node_get_object (json_parser_get_root (parser));
|
|
|
|
|
+ array = json_object_get_array_member (root, "retrieved_items");
|
|
|
|
|
+
|
|
|
|
|
+ for (guint i = 0; i < json_array_get_length (array); i++) {
|
|
|
|
|
+ JsonObject *data;
|
|
|
|
|
+ GObject *item;
|
|
|
|
|
+ const gchar *uuid;
|
|
|
|
|
+ const gchar *enc_item_key;
|
|
|
|
|
+ const gchar *enc_content;
|
|
|
|
|
+ gchar *content;
|
|
|
|
|
+
|
|
|
|
|
+ data = json_array_get_object_element (array, i);
|
|
|
|
|
+ uuid = json_object_get_string_member (data, "uuid");
|
|
|
|
|
+ enc_item_key = json_object_get_string_member (data, "enc_item_key");
|
|
|
|
|
+
|
|
|
|
|
+ if (!g_strcmp0 (enc_item_key, ""))
|
|
|
|
|
+ continue;
|
|
|
|
|
+
|
|
|
|
|
+ enc_content = json_object_get_string_member (data, "content");
|
|
|
|
|
+ content = iridium_crypto_decrypt_item (enc_content, auth_params, enc_item_key, uuid);
|
|
|
|
|
+
|
|
|
|
|
+ if (content) {
|
|
|
|
|
+ item = deserialize_item (data, content);
|
|
|
|
|
+
|
|
|
|
|
+ if (item)
|
|
|
|
|
+ items = g_list_append (items, item);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ g_free (content);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return items;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
void
|
|
void
|
|
|
iridium_standard_file_load_async (IridiumStandardFile *client,
|
|
iridium_standard_file_load_async (IridiumStandardFile *client,
|
|
|
GCancellable *cancellable,
|
|
GCancellable *cancellable,
|