kee

Offline IOU signer with QR as transport
git clone https://holbrook.no/src/kee
Info | Log | Files | Refs | README | LICENSE

commit 68bd00eb117a41663ffe75c2e38febfee9ceacd2
parent 1743dc6b54511a28ab9d0d6392ef0973a368f7e4
Author: lash <dev@holbrook.no>
Date:   Mon, 22 Apr 2024 22:12:29 +0100

Reinstate entry list subject, remove commented code

Diffstat:
Msrc/db.c | 7-------
Msrc/gtk/kee-entry-item-store.c | 54++++--------------------------------------------------
Msrc/gtk/kee-entry-item.c | 26+-------------------------
Msrc/gtk/kee-entry-store.c | 14+-------------
Msrc/gtk/kee-entry.c | 27++-------------------------
Msrc/gtk/kee-entry.h | 1-
6 files changed, 8 insertions(+), 121 deletions(-)

diff --git a/src/db.c b/src/db.c @@ -160,12 +160,6 @@ int db_next(struct db_ctx *ctx, enum DbKey pfx, char **key, size_t *key_len, cha /// \todo add to else case below start[0] = (char)pfx; ctx->k.mv_size = 1; -// if (!ctx->browsing) { -// if (*key != 0) { -// memcpy(start+1, *key, *key_len); -// ctx->k.mv_size += *key_len; -// } -// } ctx->k.mv_data = start; ctx->browsing = 1; @@ -183,7 +177,6 @@ int db_next(struct db_ctx *ctx, enum DbKey pfx, char **key, size_t *key_len, cha ctx->started = 1; start[0] = (char)*((char*)ctx->k.mv_data); if (start[0] != ctx->current_key) { - //db_reset(ctx); ctx->browsing = 0; return ERR_DB_NOMATCH; } diff --git a/src/gtk/kee-entry-item-store.c b/src/gtk/kee-entry-item-store.c @@ -18,14 +18,7 @@ typedef struct { struct _KeeEntryItemStore { GObject parent; struct db_ctx *db; -// int last_idx; -// int last_state; int last_count; -// char *last; -// char *last_key; -// char *last_digest; -// char *last_value; -// size_t last_value_length; char **ref; char *ref_mem; struct Cadiz *resolver; @@ -48,14 +41,8 @@ static void kee_entry_item_store_class_init(KeeEntryItemStoreClass *kls) { } static void kee_entry_item_store_init(KeeEntryItemStore *o) { -// o->resolver.key_type = CADIZ_KEY_TYPE_ANY; -// o->resolver.locator = malloc(1024); } -//void kee_entry_item_store_set_resolve(KeeEntryItemStore *o, const char *locator) { -// strcpy(o->resolver.locator, locator); -//} - static GType kee_entry_item_store_get_item_type(GListModel *list) { return KEE_TYPE_ENTRY_ITEM; } @@ -68,22 +55,13 @@ static guint kee_entry_item_store_get_n_items(GListModel *list) { static gpointer kee_entry_item_store_get_item(GListModel *list, guint index) { KeeEntryItem *o; KeeEntryItemStore *store; -// -// //kee_entry_load(o, list->db); + 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_store_seek(store, index); - //kee_entry_deserialize(o, store->last_key, 9, store->last_value, store->last_value_length); - //r = kee_entry_item_deserialize(o, store->last_value, store->last_value_length); - //if (r) { - // return NULL; - //} - -// //return o; + kee_entry_item_apply_list_item_widget(o); -// -// return o; + return o; } @@ -98,17 +76,10 @@ KeeEntryItemStore* kee_entry_item_store_new(struct db_ctx *db, struct kee_ledger o = g_object_new(KEE_TYPE_ENTRY_ITEM_STORE, NULL); o->db = db; -// o->last = calloc(4096, 1); -// o->last_digest = o->last + DB_KEY_SIZE_LIMIT; -// o->last_key = o->last; -// o->last_value = o->last_digest + 64; -// o->last_value_length = 1024; o->ledger = ledger; o->resolver = resolver; o->last_count = kee_entry_item_store_seek(o, INT_MAX); -// o->ref_mem = malloc(o->last_count * entry_key_len); -// o->ref = &o->ref_mem; g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "max key index is: %d", o->last_count - 1); return o; } @@ -121,45 +92,30 @@ static int kee_entry_item_store_seek(KeeEntryItemStore *o, int idx) { int r; int i; size_t key_len; - //size_t entry_key_len; - //size_t cmp_key_len; char *mem[4096]; char *last_key; - //char mem[DB_KEY_SIZE_LIMIT]; - //char *cmp_key = (char*)mem; char *entry_key; char *last_value; size_t last_value_length; - //char out[1024]; - //size_t out_len; - //cmp_key_len = 65; - //entry_key_len = 65; - key_len = entry_ref_len; //entry_key_len + 8; + key_len = entry_ref_len; last_key = (char*)mem; entry_key = last_key + 128; last_value = entry_key + 128; *last_key = DbKeyLedgerEntry; - //*cmp_key = DbKeyLedgerEntry; memcpy(last_key+1, o->ledger->digest, key_len - 1); - //memcpy(cmp_key+1, o->ledger->digest, key_len - 1); memcpy(entry_key, last_key, entry_ref_len); - //memcpy(o->last_key, cmp_key, cmp_key_len); i = 0; while (i <= idx) { last_value_length = 2048; r = db_next(o->db, DbKeyLedgerEntry, &last_key, &key_len, &last_value, &last_value_length); - //r = db_next(o->db, DbKeyLedgerEntry, &cmp_key, &key_len, &o->last_value, &o->last_value_length); if (r) { break; } if (memcmp(entry_key, last_key, entry_ref_len)) { - //if (memcmp(cmp_key, o->last_key, cmp_key_len)) { break; } - //out_len = 1024; - //r = kee_entry_item_deserialize(o, last_value, last_value_length); item = kee_ledger_parse_item(o->ledger, last_value, last_value_length); if (item == NULL) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_WARNING, "corrupt entry!"); @@ -167,8 +123,6 @@ static int kee_entry_item_store_seek(KeeEntryItemStore *o, int idx) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "adding entry: %d", i); i++; } - //memcpy(entry_key, last_key, entry_key_len); - //o->alice_credit_balance += o-> } db_rewind(o->db); return i; diff --git a/src/gtk/kee-entry-item.c b/src/gtk/kee-entry-item.c @@ -58,7 +58,6 @@ 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->ledger = ledger; o->item = ledger->last_item; for (i = 0; i < idx; i++) { o->item = o->item->prev_item; @@ -66,34 +65,11 @@ KeeEntryItem* kee_entry_item_new(struct db_ctx *db, struct kee_ledger_t *ledger, return o; } -//int kee_entry_item_deserialize(KeeEntryItem *o, const char *data, size_t data_len) { -// o->item = kee_ledger_parse_item(o->ledger, data, data_len); -// if (o->item == NULL) { -// return ERR_FAIL; -// } -// kee_content_resolve(&o->item->content, o->resolver); -// -// if (o->item->content.flags & KEE_CONTENT_RESOLVED_SUBJECT) { -// strcpy(o->header, o->item->content.subject); -// } else { -// strcpy(o->header, "(no subject)"); -// } -// -// return ERR_OK; -//} - void kee_entry_item_apply_list_item_widget(KeeEntryItem *o) { GtkWidget *widget; - //if (o->state) { - // g_log(G_LOG_DOMAIN, G_LOG_LEVEL_ERROR, "entry must be loaded first"); - // return; - //} - - //sprintf(o->header, "%s [%s]\n%s (%s)", o->ledger.content.subject, o->ledger.uoa, o->bob_dn.cn, o->bob_dn.uid); kee_content_resolve(&o->item->content, o->resolver); - //widget = gtk_label_new(o->item->content.subject); - widget = gtk_label_new("foo"); + widget = gtk_label_new(o->item->content.subject); gtk_box_append(GTK_BOX(o), widget); return; } diff --git a/src/gtk/kee-entry-store.c b/src/gtk/kee-entry-store.c @@ -94,14 +94,7 @@ static int kee_entry_store_seek(KeeEntryStore *o, int idx) { int r; int i; size_t key_len; - //int direction; - - //c = o->last_idx; - //if (idx == c) { - // return; - //} - - //direction = 0; + key_len = 9; o->last_key = o->last; memset(o->last_key, 0, key_len); @@ -147,8 +140,3 @@ void kee_entry_store_finalize(GObject *go) { free(o->resolver.locator); free(o->last); } - - -//void kee_entry_store_foo(KeeEntryStore* o) { -// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "foo db = %p", o->db); -//} diff --git a/src/gtk/kee-entry.c b/src/gtk/kee-entry.c @@ -51,25 +51,7 @@ struct _KeeEntry { }; G_DEFINE_TYPE(KeeEntry, kee_entry, GTK_TYPE_BOX); -// -//static void kee_entry_handle_item_setup(GtkListItemFactory* o, GtkListItem *item) { -// GtkWidget *label; -// -// label = gtk_label_new(NULL); -// gtk_list_item_set_child(item, label); -//} -// -//static void kee_entry_handle_item_bind(GtkListItemFactory *o, GtkListItem *item) { -// GtkWidget *label; -// GtkStringObject *s; -// -// label = gtk_list_item_get_child(item); -// s = gtk_list_item_get_item(item); -// //gtk_label_set_label(GTK_LABEL(label), gtk_string_object_get_string(s)); -// -//} -// -//static void kee_entry_item_handle_setup(GtkListItemFactory* o, GtkListItem *item) { + static void kee_entry_handle_item_setup(GtkListItemFactory* o, GtkListItem *item) { GtkWidget *box; @@ -77,22 +59,17 @@ static void kee_entry_handle_item_setup(GtkListItemFactory* o, GtkListItem *item gtk_list_item_set_child(item, box); } -//static void kee_entry_item_handle_bind(GtkListItemFactory *o, GtkListItem *item) { static void kee_entry_handle_item_bind(GtkListItemFactory *o, GtkListItem *item) { - //GtkWidget *label; GtkWidget *box; GtkWidget *box_item; - //GtkStringObject *s; box = gtk_list_item_get_child(item); - //s = gtk_list_item_get_item(item); box_item = gtk_list_item_get_item(item); g_object_take_ref(G_OBJECT(box_item)); - //gtk_label_set_label(GTK_LABEL(label), gtk_string_object_get_string(s)); - //gtk_label_set_label(GTK_LABEL(label), GTK_LABEL(s)); gtk_box_append(GTK_BOX(box), box_item); } + /// \todo free reference to self from parent box necessary..? static void kee_entry_dispose(GObject *o) { g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "disposing entry"); diff --git a/src/gtk/kee-entry.h b/src/gtk/kee-entry.h @@ -25,7 +25,6 @@ enum KEE_ENTRY_SIGNS { G_DECLARE_FINAL_TYPE(KeeEntry, kee_entry, KEE, ENTRY, GtkBox); int kee_entry_load(KeeEntry *o, struct db_ctx *db, const char *id); -//int kee_entry_deserialize(KeeEntry *o, const char *key, size_t key_len, const char *data, size_t data_len); int kee_entry_deserialize(KeeEntry *o, const char *data, size_t data_len); void kee_entry_apply_list_item_widget(KeeEntry *o); int kee_entry_apply_display_widget(KeeEntry *o);