gpg: refactor

master
bqv 3 years ago
parent a0d1c104e4
commit 8779ca82dc
No known key found for this signature in database
GPG Key ID: 9E2FF3BDEBDFC910

@ -33,8 +33,7 @@ char *account_options[ACCOUNT_NUM_OPTIONS][2] =
{ (char*)"autoconnect", (char*)"" }, { (char*)"autoconnect", (char*)"" },
{ (char*)"resource", (char*)"" }, { (char*)"resource", (char*)"" },
{ (char*)"status", (char*)"probably about to segfault" }, { (char*)"status", (char*)"probably about to segfault" },
{ (char*)"pgp_pubring_path", (char*)"${weechat_data_dir}/pubring.gpg" }, { (char*)"pgp_path", (char*)"" },
{ (char*)"pgp_secring_path", (char*)"${weechat_data_dir}/secring.gpg" },
{ (char*)"pgp_keyid", (char*)"" }, { (char*)"pgp_keyid", (char*)"" },
}; };

@ -23,8 +23,7 @@ enum t_account_option
ACCOUNT_OPTION_AUTOCONNECT, ACCOUNT_OPTION_AUTOCONNECT,
ACCOUNT_OPTION_RESOURCE, ACCOUNT_OPTION_RESOURCE,
ACCOUNT_OPTION_STATUS, ACCOUNT_OPTION_STATUS,
ACCOUNT_OPTION_PGP_PUBRING_PATH, ACCOUNT_OPTION_PGP_PATH,
ACCOUNT_OPTION_PGP_SECRING_PATH,
ACCOUNT_OPTION_PGP_KEYID, ACCOUNT_OPTION_PGP_KEYID,
ACCOUNT_NUM_OPTIONS, ACCOUNT_NUM_OPTIONS,
}; };
@ -63,10 +62,8 @@ enum t_account_option
weechat_config_string(account->options[ACCOUNT_OPTION_RESOURCE]) weechat_config_string(account->options[ACCOUNT_OPTION_RESOURCE])
#define account_status(account) \ #define account_status(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_STATUS]) weechat_config_string(account->options[ACCOUNT_OPTION_STATUS])
#define account_pgp_pubring_path(account) \ #define account_pgp_path(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PGP_PUBRING_PATH]) weechat_config_string(account->options[ACCOUNT_OPTION_PGP_PATH])
#define account_pgp_secring_path(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PGP_SECRING_PATH])
#define account_pgp_keyid(account) \ #define account_pgp_keyid(account) \
weechat_config_string(account->options[ACCOUNT_OPTION_PGP_KEYID]) weechat_config_string(account->options[ACCOUNT_OPTION_PGP_KEYID])

@ -204,27 +204,11 @@ config__account_new_option (struct t_config_file *config_file,
callback_change_data, callback_change_data,
NULL, NULL, NULL); NULL, NULL, NULL);
break; break;
case ACCOUNT_OPTION_PGP_PUBRING_PATH: case ACCOUNT_OPTION_PGP_PATH:
new_option = weechat_config_new_option ( new_option = weechat_config_new_option (
config_file, section, config_file, section,
option_name, "string", option_name, "string",
N_("XMPP Account PGP Public Keyring Path"), N_("XMPP Account PGP Keyring Dir"),
NULL, 0, 0,
default_value, value,
null_value_allowed,
callback_check_value,
callback_check_value_pointer,
callback_check_value_data,
callback_change,
callback_change_pointer,
callback_change_data,
NULL, NULL, NULL);
break;
case ACCOUNT_OPTION_PGP_SECRING_PATH:
new_option = weechat_config_new_option (
config_file, section,
option_name, "string",
N_("XMPP Account PGP Secure Keyring Path"),
NULL, 0, 0, NULL, 0, 0,
default_value, value, default_value, value,
null_value_allowed, null_value_allowed,

@ -1218,11 +1218,7 @@ void connection__handler(xmpp_conn_t *conn, xmpp_conn_event_t status,
xmpp_handler_add(conn, &connection__iq_handler, xmpp_handler_add(conn, &connection__iq_handler,
NULL, "iq", NULL, account); NULL, "iq", NULL, account);
pgp__init(&account->pgp, pgp__init(&account->pgp);
weechat_string_eval_expression(account_pgp_pubring_path(account),
NULL, NULL, NULL),
weechat_string_eval_expression(account_pgp_secring_path(account),
NULL, NULL, NULL));
/* Send initial <presence/> so that we appear online to contacts */ /* Send initial <presence/> so that we appear online to contacts */
children = (xmpp_stanza_t**)malloc(sizeof(*children) * (3 + 1)); children = (xmpp_stanza_t**)malloc(sizeof(*children) * (3 + 1));

@ -19,7 +19,7 @@
const char *PGP_ADVICE = "[PGP encrypted message (XEP-0027)]"; const char *PGP_ADVICE = "[PGP encrypted message (XEP-0027)]";
void pgp__init(struct t_pgp **pgp, const char *pub, const char *sec) void pgp__init(struct t_pgp **pgp)
{ {
struct t_pgp *new_pgp; struct t_pgp *new_pgp;
gpgme_error_t err; gpgme_error_t err;
@ -31,35 +31,37 @@ void pgp__init(struct t_pgp **pgp, const char *pub, const char *sec)
err = gpgme_new(&new_pgp->gpgme); err = gpgme_new(&new_pgp->gpgme);
if (err) { if (err) {
weechat_printf(nullptr, "gpg (error): %s - %s",
gpgme_strsource(err), gpgme_strerror(err));
return; return;
} }
gpgme_set_armor(new_pgp->gpgme, true); gpgme_set_armor(new_pgp->gpgme, true);
err = gpgme_data_new_from_file(&keydata, pub, true); //err = gpgme_data_new_from_file(&keydata, pub, true);
if (err) { //if (err) {
return; // return;
} //}
err = gpgme_op_import(new_pgp->gpgme, keydata); //err = gpgme_op_import(new_pgp->gpgme, keydata);
if (err) { //if (err) {
return; // return;
} //}
gpgme_import_result_t impRes = gpgme_op_import_result(new_pgp->gpgme); //gpgme_import_result_t impRes = gpgme_op_import_result(new_pgp->gpgme);
weechat_printf(nullptr, "(gpg) imported %d keys", impRes->imported); //weechat_printf(nullptr, "(gpg) imported %d keys", impRes->imported);
err = gpgme_data_new_from_file(&keydata, sec, true); //err = gpgme_data_new_from_file(&keydata, sec, true);
if (err) { //if (err) {
return; // return;
} //}
err = gpgme_op_import(new_pgp->gpgme, keydata); //err = gpgme_op_import(new_pgp->gpgme, keydata);
if (err) { //if (err) {
return; // return;
} //}
impRes = gpgme_op_import_result(new_pgp->gpgme); //impRes = gpgme_op_import_result(new_pgp->gpgme);
weechat_printf(nullptr, "(gpg) imported %d secret keys", impRes->imported); //weechat_printf(nullptr, "(gpg) imported %d secret keys", impRes->imported);
*pgp = new_pgp; *pgp = new_pgp;
} }

@ -14,7 +14,7 @@ struct t_pgp
const char *keyid; const char *keyid;
}; };
void pgp__init(struct t_pgp **pgp, const char *pub, const char *sec); void pgp__init(struct t_pgp **pgp);
void pgp__free(struct t_pgp *pgp); void pgp__free(struct t_pgp *pgp);

Loading…
Cancel
Save