about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorPaul Fariello <paul@fariello.eu>2019-03-25 19:07:36 +0140
committerPaul Fariello <paul@fariello.eu>2019-04-10 17:12:31 +0200
commit678bff9169c81ed20c38698e132d7c8c6118763b (patch)
tree67a8993601b5a52ac5c341e5861b29e19e3d2274
parent3d8f47a72416ff4b1ca64bf66071a62e4661d036 (diff)
downloadprofani-tty-678bff9169c81ed20c38698e132d7c8c6118763b.tar.gz
Add fingerprint autocompletion
-rw-r--r--src/command/cmd_ac.c26
-rw-r--r--src/omemo/omemo.c22
-rw-r--r--src/omemo/omemo.h2
3 files changed, 49 insertions, 1 deletions
diff --git a/src/command/cmd_ac.c b/src/command/cmd_ac.c
index 9584543e..c700e51b 100644
--- a/src/command/cmd_ac.c
+++ b/src/command/cmd_ac.c
@@ -57,6 +57,10 @@
 #include "pgp/gpg.h"
 #endif
 
+#ifdef HAVE_OMEMO
+#include "omemo/omemo.h"
+#endif
+
 static char* _sub_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _notify_autocomplete(ProfWin *window, const char *const input, gboolean previous);
 static char* _theme_autocomplete(ProfWin *window, const char *const input, gboolean previous);
@@ -1000,6 +1004,9 @@ cmd_ac_reset(ProfWin *window)
 #ifdef HAVE_LIBGPGME
     p_gpg_autocomplete_key_reset();
 #endif
+#ifdef HAVE_OMEMO
+    omemo_fingerprint_autocomplete_reset();
+#endif
     autocomplete_reset(help_ac);
     autocomplete_reset(help_commands_ac);
     autocomplete_reset(notify_ac);
@@ -2158,6 +2165,25 @@ _omemo_autocomplete(ProfWin *window, const char *const input, gboolean previous)
         return found;
     }
 
+#ifdef HAVE_OMEMO
+    if (window->type == WIN_CHAT) {
+        found = autocomplete_param_with_func(input, "/omemo trust", omemo_fingerprint_autocomplete, previous);
+        if (found) {
+            return found;
+        }
+    } else {
+        found = autocomplete_param_with_func(input, "/omemo trust", roster_contact_autocomplete, previous);
+        if (found) {
+            return found;
+        }
+
+        found = autocomplete_param_no_with_func(input, "/omemo trust", 4, omemo_fingerprint_autocomplete, previous);
+        if (found) {
+            return found;
+        }
+    }
+#endif
+
     found = autocomplete_param_with_ac(input, "/omemo log", omemo_log_ac, TRUE, previous);
     if (found) {
         return found;
diff --git a/src/omemo/omemo.c b/src/omemo/omemo.c
index 01eb6b67..1f48224e 100644
--- a/src/omemo/omemo.c
+++ b/src/omemo/omemo.c
@@ -63,6 +63,7 @@ struct omemo_context_t {
     GString *sessions_filename;
     GKeyFile *sessions_keyfile;
     GHashTable *known_devices;
+    Autocomplete fingerprint_ac;
 };
 
 static omemo_context omemo_ctx;
@@ -163,6 +164,8 @@ omemo_init(void)
     omemo_ctx.device_list = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_list_free);
     omemo_ctx.device_list_handler = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
     omemo_ctx.known_devices = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_free);
+
+    omemo_ctx.fingerprint_ac = autocomplete_new();
 }
 
 void
@@ -1114,6 +1117,18 @@ omemo_key_free(omemo_key_t *key)
     free(key);
 }
 
+char*
+omemo_fingerprint_autocomplete(const char *const search_str, gboolean previous)
+{
+    return autocomplete_complete(omemo_ctx.fingerprint_ac, search_str, FALSE, previous);
+}
+
+void
+omemo_fingerprint_autocomplete_reset(void)
+{
+    autocomplete_reset(omemo_ctx.fingerprint_ac);
+}
+
 static void
 load_identity(void)
 {
@@ -1203,7 +1218,12 @@ cache_device_identity(const char *const jid, uint32_t device_id, ec_public_key *
 
     char *fingerprint = omemo_fingerprint(identity, FALSE);
     log_info("OMEMO: cache identity for %s:%d: %s", jid, device_id, fingerprint);
-    g_hash_table_insert(known_identities, fingerprint, GINT_TO_POINTER(device_id));
+    g_hash_table_insert(known_identities, strdup(fingerprint), GINT_TO_POINTER(device_id));
+
+    char *formatted_fingerprint = omemo_format_fingerprint(fingerprint);
+    autocomplete_add(omemo_ctx.fingerprint_ac, formatted_fingerprint);
+    free(formatted_fingerprint);
+    free(fingerprint);
 }
 
 static void
diff --git a/src/omemo/omemo.h b/src/omemo/omemo.h
index ec48e183..bbd59b77 100644
--- a/src/omemo/omemo.h
+++ b/src/omemo/omemo.h
@@ -38,6 +38,8 @@ void omemo_trust(const char *const jid, const char *const fingerprint);
 void omemo_untrust(const char *const jid, const char *const fingerprint);
 GList *omemo_known_device_identities(const char *const jid);
 gboolean omemo_is_trusted_identity(const char *const jid, const char *const fingerprint);
+char *omemo_fingerprint_autocomplete(const char *const search_str, gboolean previous);
+void omemo_fingerprint_autocomplete_reset(void);
 
 void omemo_start_session(const char *const barejid);
 void omemo_start_muc_sessions(const char *const roomjid);