commit 9326a579ede983bd4c0109ca19c45dc2e7f4810d
parent 8fdb8230d9f27694c4de569180e840f8818381c0
Author: lash <dev@holbrook.no>
Date: Tue, 14 May 2024 14:28:10 +0100
WIP correct ledger digest in ledger item put import
Diffstat:
5 files changed, 18 insertions(+), 10 deletions(-)
diff --git a/src/gtk/kee-entry-item-store.c b/src/gtk/kee-entry-item-store.c
@@ -58,9 +58,10 @@ static gpointer kee_entry_item_store_get_item(GListModel *list, guint index) {
store = KEE_ENTRY_ITEM_STORE(list);
o = kee_entry_item_new(store->db, store->ledger, (int)index);
- kee_entry_item_set_resolver(o, store->resolver);
-
- kee_entry_item_apply_list_item_widget(o);
+ if (o != NULL) {
+ kee_entry_item_set_resolver(o, store->resolver);
+ kee_entry_item_apply_list_item_widget(o);
+ }
return o;
}
diff --git a/src/gtk/kee-entry-item.c b/src/gtk/kee-entry-item.c
@@ -60,6 +60,9 @@ KeeEntryItem* kee_entry_item_new(struct db_ctx *db, struct kee_ledger_t *ledger,
o = KEE_ENTRY_ITEM(g_object_new(KEE_TYPE_ENTRY_ITEM, "orientation", GTK_ORIENTATION_VERTICAL, NULL));
o->db = db;
o->item = ledger->last_item;
+ if (o->item == NULL) {
+ return NULL;
+ }
for (i = 0; i < idx; i++) {
o->item = o->item->prev_item;
}
diff --git a/src/gtk/kee-entry-store.c b/src/gtk/kee-entry-store.c
@@ -84,7 +84,6 @@ static gpointer kee_entry_store_get_item(GListModel *list, guint index) {
return o;
}
-
static void kee_entry_store_iface_init(GListModelInterface *ifc) {
ifc->get_item_type = kee_entry_store_get_item_type;
ifc->get_n_items = kee_entry_store_get_n_items;
diff --git a/src/gtk/kee-entry.c b/src/gtk/kee-entry.c
@@ -462,7 +462,10 @@ static int process_entry_ledger(KeeEntry *o) {
memcpy(last_key+1, o->ledger.pubkey_bob, 32);
key_len = 32;
r = db_next(o->db, DbKeyDN, &last_key, &key_len, &last_value, &last_value_length);
- if (r) {
+ if (r == ERR_DB_NOMATCH) {
+ strcpy(last_value, "cn=johndoe");
+ last_value_length = strlen(last_value);
+ } else if (r) {
return ERR_FAIL;
}
r = kee_dn_from_str(&o->bob_dn, last_value, last_value_length);
@@ -484,13 +487,13 @@ static int process_entry_ledger(KeeEntry *o) {
}
}
-
o->state = ENTRYSTATE_LOAD;
kee_entry_init_list_widget(o);
return ERR_OK;
}
+
/// \todo returns 1 on success, investigate why and change if possible!
int kee_entry_modeswitch(KeeEntry *o, enum kee_entry_viewmode_e mode) {
int r;
diff --git a/src/ledger.c b/src/ledger.c
@@ -1002,9 +1002,9 @@ int kee_ledger_item_put(struct kee_ledger_t *ledger, struct db_ctx *db, int idx)
return ERR_FAIL;
}
- memcpy(k, ledger->digest, DIGEST_LENGTH);
+ memcpy(k+1, ledger->digest, DIGEST_LENGTH);
- l = db_key(DbKeyLedgerEntry, &item->time, k, DIGEST_LENGTH);
+ l = db_key(DbKeyLedgerEntry, &item->time, k, DIGEST_LENGTH+1);
if (l == 0) {
return ERR_FAIL;
}
@@ -1015,7 +1015,8 @@ int kee_ledger_item_put(struct kee_ledger_t *ledger, struct db_ctx *db, int idx)
// return ERR_DB_EXISTS;
// }
- c = 928;
+ //c = 928;
+ c = 2048;
r = kee_ledger_item_serialize(item, v, &c, KEE_LEDGER_STATE_FINAL);
if (r) {
return ERR_FAIL;
@@ -1044,7 +1045,7 @@ int kee_ledger_put(struct kee_ledger_t *ledger, struct db_ctx *db) {
v = k + 2048;
k[0] = DbKeyReverse;
- memcpy(((char*)k)+1, ledger->digest, DIGEST_LENGTH);
+ memcpy(k+1, ledger->digest, DIGEST_LENGTH);
l = DIGEST_LENGTH + 1;
//c = 928; // 1024 - 96
c = 2048;
@@ -1101,6 +1102,7 @@ int kee_ledger_put(struct kee_ledger_t *ledger, struct db_ctx *db) {
r = 0;
while (r == 0) {
r = kee_ledger_item_put(ledger, db, i);
+ i++;
}
r = db_finish(db);