commit 0d0494c06fb3ad986e49a124788286a7a3dce465
parent c13637d773ba89919e76df100a806add95c2de7e
Author: lash <dev@holbrook.no>
Date: Thu, 2 May 2024 08:20:37 +0100
Enable transport import from QR
Diffstat:
4 files changed, 66 insertions(+), 9 deletions(-)
diff --git a/src/gtk/kee-import.c b/src/gtk/kee-import.c
@@ -8,6 +8,8 @@
#include "camera.h"
#include "scan.h"
#include "err.h"
+#include "transport.h"
+
typedef struct {
} KeeImportPrivate;
@@ -126,13 +128,32 @@ static void kee_import_handle_import_data_text(KeeImport *o, GString *v, GtkText
g_action_activate(act, NULL);
}
-static void kee_import_handle_import_data_accept(KeeImport *o, const char *data) {
+static void kee_import_handle_import_data_accept(KeeImport *o, GString *v, GtkStack *stack) {
+ int r;
+ char *s;
+ size_t c;
+ struct kee_transport_t trans;
+ char b[1024];
+
+ s = (char*)v->str;
+
+ c = strlen(s) + 1;
+ r = kee_transport_import(&trans, KEE_TRANSPORT_BASE64, s, c);
+ if (r) {
+ return;
+ }
+
+ c = 1024;
+ r = kee_transport_read(&trans, b, &c);
+ if (r) {
+ return;
+ }
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) {
- g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "checking import data");
-}
+//static void kee_import_handle_import_data_check(KeeImport *o, const char *data, GtkActionable *act) {
+// g_log(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG, "checking import data");
+//}
static void kee_import_handle_scan_select(GActionGroup *act, char *action_name, gpointer user_data, GtkStack *stack) {
GVariant *v;
@@ -227,10 +248,10 @@ static GtkWidget* kee_import_build_import_text(KeeImport *o, GtkStack *stack) {
gtk_box_append(GTK_BOX(box), butt);
g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_text), gtk_text_view_get_buffer(txt));
- g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_accept), NULL);
+ g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_accept), stack);
g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_focus), stack);
- g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_check), butt);
- g_signal_connect(butt, "clicked", G_CALLBACK(kee_import_handle_import_data_check), butt);
+ //g_signal_connect(o, "data_available", G_CALLBACK(kee_import_handle_import_data_check), butt);
+ //g_signal_connect(butt, "clicked", G_CALLBACK(kee_import_handle_import_data_check), butt);
return box;
}
diff --git a/src/tests/transport.c b/src/tests/transport.c
@@ -128,6 +128,30 @@ int test_msg() {
return 0;
}
+int test_obj() {
+ int r;
+ char *p;
+ char b[1024];
+ char out[1024];
+ size_t out_len;
+ size_t c;
+
+ p = (char*)b;
+ strcpy(p, "eNpjMmhiLDJonMTDUlqcwsDEwgykWBQYCAAWBR21LdkZ/4/1/5ztaiNr4Ggi7KRbkNK8f8HP");
+ p += strlen(b);
+ *p = 0x0a;
+ p++;
+ strcpy(p, "rriOpLTn61gcGCgEBo23KDeEiRHoJwF1IIMlBeRuig2k3ARGRgYWBgYA8BQXsQ==");
+ c = strlen(b);
+
+ out_len = 1024;
+ r = unpack(b, c, out, &out_len);
+ if (r) {
+ return 1;
+ }
+ return 0;
+}
+
int main() {
int r;
@@ -143,5 +167,9 @@ int main() {
if (r) {
return 1;
}
+ r = test_obj();
+ if (r) {
+ return 1;
+ }
return 0;
}
diff --git a/src/transport.c b/src/transport.c
@@ -128,16 +128,18 @@ int pack(char *in, size_t in_len, char *out, size_t *out_len) {
int unpack(char *in, size_t in_len, char *out, size_t *out_len) {
int r;
char *buf;
+ size_t c;
buf = malloc(*out_len);
- r = unpack_decode(in, in_len, buf, out_len);
+ c = *out_len;
+ r = unpack_decode(in, in_len, buf, &c);
if (r) {
free(buf);
return ERR_FAIL;
}
- r = unpack_decompress(buf, *out_len, out, out_len);
+ r = unpack_decompress(buf, c, out, out_len);
if (r) {
free(buf);
return ERR_FAIL;
diff --git a/src/wire.h b/src/wire.h
@@ -0,0 +1,6 @@
+#ifndef KEE_WIRE_H_
+#define KEE_WIRE_H_
+
+extern const asn1_static_node schema_entry_asn1_tab[];
+
+#endif