mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added PGP key autocompleter
This commit is contained in:
parent
55c2d1cc21
commit
cb19be2ffc
@ -59,6 +59,9 @@
|
|||||||
#ifdef HAVE_LIBOTR
|
#ifdef HAVE_LIBOTR
|
||||||
#include "otr/otr.h"
|
#include "otr/otr.h"
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef HAVE_LIBGPGME
|
||||||
|
#include "pgp/gpg.h"
|
||||||
|
#endif
|
||||||
#include "profanity.h"
|
#include "profanity.h"
|
||||||
#include "tools/autocomplete.h"
|
#include "tools/autocomplete.h"
|
||||||
#include "tools/parser.h"
|
#include "tools/parser.h"
|
||||||
@ -2242,6 +2245,9 @@ cmd_reset_autocomplete(ProfWin *window)
|
|||||||
accounts_reset_enabled_search();
|
accounts_reset_enabled_search();
|
||||||
prefs_reset_boolean_choice();
|
prefs_reset_boolean_choice();
|
||||||
presence_reset_sub_request_search();
|
presence_reset_sub_request_search();
|
||||||
|
#ifdef HAVE_LIBGPGME
|
||||||
|
p_gpg_autocomplete_key_reset();
|
||||||
|
#endif
|
||||||
autocomplete_reset(help_ac);
|
autocomplete_reset(help_ac);
|
||||||
autocomplete_reset(help_commands_ac);
|
autocomplete_reset(help_commands_ac);
|
||||||
autocomplete_reset(notify_ac);
|
autocomplete_reset(notify_ac);
|
||||||
@ -2983,6 +2989,26 @@ _pgp_autocomplete(ProfWin *window, const char * const input)
|
|||||||
return found;
|
return found;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef HAVE_LIBGPGME
|
||||||
|
gboolean result;
|
||||||
|
gchar **args = parse_args(input, 2, 3, &result);
|
||||||
|
if ((strncmp(input, "/pgp", 4) == 0) && (result == TRUE)) {
|
||||||
|
GString *beginning = g_string_new("/pgp ");
|
||||||
|
g_string_append(beginning, args[0]);
|
||||||
|
if (args[1]) {
|
||||||
|
g_string_append(beginning, " ");
|
||||||
|
g_string_append(beginning, args[1]);
|
||||||
|
}
|
||||||
|
found = autocomplete_param_with_func(input, beginning->str, p_gpg_autocomplete_key);
|
||||||
|
g_string_free(beginning, TRUE);
|
||||||
|
if (found) {
|
||||||
|
g_strfreev(args);
|
||||||
|
return found;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
g_strfreev(args);
|
||||||
|
#endif
|
||||||
|
|
||||||
found = autocomplete_param_with_func(input, "/pgp setkey", roster_barejid_autocomplete);
|
found = autocomplete_param_with_func(input, "/pgp setkey", roster_barejid_autocomplete);
|
||||||
if (found) {
|
if (found) {
|
||||||
return found;
|
return found;
|
||||||
|
@ -47,6 +47,7 @@
|
|||||||
#include "pgp/gpg.h"
|
#include "pgp/gpg.h"
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include "tools/autocomplete.h"
|
||||||
|
|
||||||
#define PGP_SIGNATURE_HEADER "-----BEGIN PGP SIGNATURE-----"
|
#define PGP_SIGNATURE_HEADER "-----BEGIN PGP SIGNATURE-----"
|
||||||
#define PGP_SIGNATURE_FOOTER "-----END PGP SIGNATURE-----"
|
#define PGP_SIGNATURE_FOOTER "-----END PGP SIGNATURE-----"
|
||||||
@ -59,6 +60,8 @@ static GHashTable *pubkeys;
|
|||||||
static gchar *pubsloc;
|
static gchar *pubsloc;
|
||||||
static GKeyFile *pubkeyfile;
|
static GKeyFile *pubkeyfile;
|
||||||
|
|
||||||
|
static Autocomplete key_ac;
|
||||||
|
|
||||||
static char* _remove_header_footer(char *str, const char * const footer);
|
static char* _remove_header_footer(char *str, const char * const footer);
|
||||||
static char* _add_header_footer(const char * const str, const char * const header, const char * const footer);
|
static char* _add_header_footer(const char * const str, const char * const header, const char * const footer);
|
||||||
static void _save_pubkeys(void);
|
static void _save_pubkeys(void);
|
||||||
@ -80,6 +83,10 @@ p_gpg_init(void)
|
|||||||
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
|
gpgme_set_locale(NULL, LC_CTYPE, setlocale(LC_CTYPE, NULL));
|
||||||
|
|
||||||
pubkeys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_p_gpg_free_pubkeyid);
|
pubkeys = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)_p_gpg_free_pubkeyid);
|
||||||
|
|
||||||
|
key_ac = autocomplete_new();
|
||||||
|
GHashTable *keys = p_gpg_list_keys();
|
||||||
|
p_gpg_free_keys(keys);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -97,6 +104,9 @@ p_gpg_close(void)
|
|||||||
|
|
||||||
free(pubsloc);
|
free(pubsloc);
|
||||||
pubsloc = NULL;
|
pubsloc = NULL;
|
||||||
|
|
||||||
|
autocomplete_free(key_ac);
|
||||||
|
key_ac = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -327,6 +337,16 @@ p_gpg_list_keys(void)
|
|||||||
|
|
||||||
gpgme_release(ctx);
|
gpgme_release(ctx);
|
||||||
|
|
||||||
|
autocomplete_clear(key_ac);
|
||||||
|
GList *ids = g_hash_table_get_keys(result);
|
||||||
|
GList *curr = ids;
|
||||||
|
while (curr) {
|
||||||
|
ProfPGPKey *key = g_hash_table_lookup(result, curr->data);
|
||||||
|
autocomplete_add(key_ac, key->id);
|
||||||
|
curr = curr->next;
|
||||||
|
}
|
||||||
|
g_list_free(ids);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -639,6 +659,18 @@ p_gpg_free_decrypted(char *decrypted)
|
|||||||
g_free(decrypted);
|
g_free(decrypted);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char *
|
||||||
|
p_gpg_autocomplete_key(const char * const search_str)
|
||||||
|
{
|
||||||
|
return autocomplete_complete(key_ac, search_str, TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
p_gpg_autocomplete_key_reset(void)
|
||||||
|
{
|
||||||
|
autocomplete_reset(key_ac);
|
||||||
|
}
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
_remove_header_footer(char *str, const char * const footer)
|
_remove_header_footer(char *str, const char * const footer)
|
||||||
{
|
{
|
||||||
|
@ -67,5 +67,7 @@ void p_gpg_verify(const char * const barejid, const char *const sign);
|
|||||||
char* p_gpg_encrypt(const char * const barejid, const char * const message);
|
char* p_gpg_encrypt(const char * const barejid, const char * const message);
|
||||||
char* p_gpg_decrypt(const char * const cipher);
|
char* p_gpg_decrypt(const char * const cipher);
|
||||||
void p_gpg_free_decrypted(char *decrypted);
|
void p_gpg_free_decrypted(char *decrypted);
|
||||||
|
char* p_gpg_autocomplete_key(const char * const search_str);
|
||||||
|
void p_gpg_autocomplete_key_reset(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,3 +54,10 @@ void p_gpg_free_decrypted(char *decrypted) {}
|
|||||||
|
|
||||||
void p_gpg_free_keys(GHashTable *keys) {}
|
void p_gpg_free_keys(GHashTable *keys) {}
|
||||||
|
|
||||||
|
void p_gpg_autocomplete_key_reset(void) {}
|
||||||
|
|
||||||
|
char * p_gpg_autocomplete_key(const char * const search_str)
|
||||||
|
{
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user