kee

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

commit c13637d773ba89919e76df100a806add95c2de7e
parent 72622792a915772e966930afec67527f5f9eb3ac
Author: lash <dev@holbrook.no>
Date:   Wed,  1 May 2024 09:47:55 +0100

Fix lifetime issue in import data from qr scan

Diffstat:
Msrc/gtk/kee-import.c | 25++++++++++++++++---------
Msrc/gtk/kee-menu.c | 1+
Msrc/gtk/ui.c | 8+++++++-
3 files changed, 24 insertions(+), 10 deletions(-)

diff --git a/src/gtk/kee-import.c b/src/gtk/kee-import.c @@ -109,21 +109,25 @@ static void kee_import_handle_import_data_focus(KeeImport *o, const char *data, gtk_widget_activate(o->toggler_text); } -static void kee_import_handle_import_data_text(KeeImport *o, const char *data, GtkTextBuffer *buf) { - gtk_text_buffer_set_text(buf, data, strlen(data)); - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import data %s", data); -} - -static void kee_import_handle_import_data_accept(KeeImport *o, const char *data) { +//static void kee_import_handle_import_data_text(KeeImport *o, const char *data, GtkTextBuffer *buf) { +static void kee_import_handle_import_data_text(KeeImport *o, GString *v, GtkTextBuffer *buf) { GAction *act; GActionMap *am; + char *s; - g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import accept"); + s = (char*)v->str; + //gtk_text_buffer_set_text(buf, data, strlen(data)); + gtk_text_buffer_set_text(buf, s, strlen(s)); + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import data %s", s); am = G_ACTION_MAP(gtk_window_get_application(GTK_WINDOW(o->win))); - act = g_action_map_lookup_action(am, "import_data_accept"); g_simple_action_set_enabled(G_SIMPLE_ACTION(act), true); + g_action_activate(act, NULL); +} + +static void kee_import_handle_import_data_accept(KeeImport *o, const char *data) { + g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "import accept"); } static void kee_import_handle_import_data_check(KeeImport *o, const char *data, GtkActionable *act) { @@ -312,6 +316,7 @@ static gboolean kee_import_scan_code_handler(GstBus *bus, GstMessage *msg, gpoin const gchar *src; const gchar *code; const GstStructure *strctr; + const GString *code_str; KeeImport *import; import = KEE_IMPORT(user_data); @@ -339,9 +344,11 @@ static gboolean kee_import_scan_code_handler(GstBus *bus, GstMessage *msg, gpoin break; } strctr = gst_message_get_structure(msg); + /// \todo remove newline in result code = gst_structure_get_string(strctr, "symbol"); + code_str = g_string_new(code); g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "message %s: %d (%s) - decoded: %s", src, msg->type, gst_message_type_get_name(msg->type), code); - g_signal_emit(import, kee_sigs[KEE_S_IMPORT_DATA], 0, code); + g_signal_emit(import, kee_sigs[KEE_S_IMPORT_DATA], 0, code_str); return false; default: g_log(G_LOG_DOMAIN, G_LOG_LEVEL_INFO, "unhandled message (ext %d): %s", GST_MESSAGE_TYPE_IS_EXTENDED(msg), GST_MESSAGE_TYPE_NAME(msg)); diff --git a/src/gtk/kee-menu.c b/src/gtk/kee-menu.c @@ -86,6 +86,7 @@ KeeMenu* kee_menu_new(GtkApplication *gapp, struct kee_context *ctx) { //gtk_widget_set_visible(butt, false); gtk_actionable_set_action_name(GTK_ACTIONABLE(butt), "win.back"); g_signal_connect(act, "activate", G_CALLBACK(kee_menu_act_back), o); + gtk_widget_set_tooltip_text(butt, "back"); act = g_simple_action_new("import", NULL); g_action_map_add_action(G_ACTION_MAP(o), G_ACTION(act)); diff --git a/src/gtk/ui.c b/src/gtk/ui.c @@ -18,6 +18,7 @@ #include "kee-key.h" #include "kee-transport.h" #include "transport.h" +#include "debug.h" static void ui_handle_unlock(KeeKey *o, KeeMenu *menu) { @@ -34,11 +35,16 @@ static void ui_handle_unlock(KeeKey *o, KeeMenu *menu) { static void ui_handle_import(KeeImport *import, GString *v, KeeMenu *menu) { //GtkWidget *widget; + int r; struct kee_transport_t trans; char *s; s = (char*)v->str; - kee_transport_import(&trans, KEE_TRANSPORT_BASE64, s, strlen(s) + 1); + r = kee_transport_import(&trans, KEE_TRANSPORT_BASE64, s, strlen(s) + 1); + if (r) { + debug_log(DEBUG_INFO, "invalid input for transport"); + return; + } //kee_transport_read(&trans); //switch(kee_transport_cmd(&trans)) {