refactor: Move pgp module to gchar

This commit is contained in:
Michael Vetter
2026-02-27 00:02:11 +01:00
parent 45dc50eccf
commit 20154048e7
6 changed files with 117 additions and 118 deletions

View File

@@ -7316,7 +7316,7 @@ cmd_pgp(ProfWin* window, const char* const command, gchar** args)
account_free(account); account_free(account);
return TRUE; return TRUE;
} }
auto_char char* pubkey = p_gpg_get_pubkey(account->pgp_keyid); auto_gchar gchar* pubkey = p_gpg_get_pubkey(account->pgp_keyid);
if (pubkey == NULL) { if (pubkey == NULL) {
cons_show_error("Couldn't get your PGP public key. Please, check error logs."); cons_show_error("Couldn't get your PGP public key. Please, check error logs.");
account_free(account); account_free(account);

View File

@@ -116,7 +116,7 @@ cl_ev_reconnect(void)
void void
cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs) cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs)
{ {
auto_char char* signed_status = NULL; auto_gchar gchar* signed_status = NULL;
#ifdef HAVE_LIBGPGME #ifdef HAVE_LIBGPGME
ProfAccount* account = accounts_get_account(session_get_account_name()); ProfAccount* account = accounts_get_account(session_get_account_name());

View File

@@ -66,25 +66,25 @@ static GHashTable* pubkeys;
static prof_keyfile_t pubkeys_prof_keyfile; static prof_keyfile_t pubkeys_prof_keyfile;
static GKeyFile* pubkeyfile; static GKeyFile* pubkeyfile;
static char* passphrase; static gchar* passphrase;
static char* passphrase_attempt; static gchar* passphrase_attempt;
static Autocomplete key_ac; static Autocomplete key_ac;
static char* _remove_header_footer(char* str, const char* const footer); static gchar* _remove_header_footer(gchar* str, const char* const footer);
static char* _add_header_footer(const char* const str, const char* const header, const char* const footer); static gchar* _add_header_footer(const gchar* const str, const char* const header, const char* const footer);
static char* _gpgme_data_to_char(gpgme_data_t data); static gchar* _gpgme_data_to_char(gpgme_data_t data);
static void _save_pubkeys(void); static void _save_pubkeys(void);
static ProfPGPKey* _gpgme_key_to_ProfPGPKey(gpgme_key_t key); static ProfPGPKey* _gpgme_key_to_ProfPGPKey(gpgme_key_t key);
static const char* _gpgme_key_get_email(gpgme_key_t key); static const gchar* _gpgme_key_get_email(gpgme_key_t key);
void void
_p_gpg_free_pubkeyid(ProfPGPPubKeyId* pubkeyid) _p_gpg_free_pubkeyid(ProfPGPPubKeyId* pubkeyid)
{ {
if (pubkeyid) { if (pubkeyid) {
free(pubkeyid->id); g_free(pubkeyid->id);
} }
free(pubkeyid); g_free(pubkeyid);
} }
static gpgme_error_t static gpgme_error_t
@@ -95,14 +95,14 @@ _p_gpg_passphrase_cb(void* hook, const char* uid_hint, const char* passphrase_in
} else { } else {
GString* pass_term = g_string_new(""); GString* pass_term = g_string_new("");
auto_char char* password = ui_ask_pgp_passphrase(uid_hint, prev_was_bad); auto_gchar gchar* password = ui_ask_pgp_passphrase(uid_hint, prev_was_bad);
if (password) { if (password) {
g_string_append(pass_term, password); g_string_append(pass_term, password);
} }
g_string_append(pass_term, "\n"); g_string_append(pass_term, "\n");
if (passphrase_attempt) { if (passphrase_attempt) {
free(passphrase_attempt); g_free(passphrase_attempt);
} }
passphrase_attempt = g_string_free(pass_term, FALSE); passphrase_attempt = g_string_free(pass_term, FALSE);
@@ -127,13 +127,11 @@ _p_gpg_close(void)
key_ac = NULL; key_ac = NULL;
if (passphrase) { if (passphrase) {
free(passphrase); GFREE_SET_NULL(passphrase);
passphrase = NULL;
} }
if (passphrase_attempt) { if (passphrase_attempt) {
free(passphrase_attempt); GFREE_SET_NULL(passphrase_attempt);
passphrase_attempt = NULL;
} }
} }
@@ -157,7 +155,7 @@ p_gpg_init(void)
} }
void void
p_gpg_on_connect(const char* const barejid) p_gpg_on_connect(const gchar* const barejid)
{ {
gchar* pubsloc = files_file_in_account_data_path(DIR_PGP, barejid, "pubkeys"); gchar* pubsloc = files_file_in_account_data_path(DIR_PGP, barejid, "pubkeys");
if (!pubsloc) { if (!pubsloc) {
@@ -195,10 +193,10 @@ p_gpg_on_connect(const char* const barejid)
continue; continue;
} }
ProfPGPPubKeyId* pubkeyid = malloc(sizeof(ProfPGPPubKeyId)); ProfPGPPubKeyId* pubkeyid = g_new0(ProfPGPPubKeyId, 1);
pubkeyid->id = strdup(keyid); pubkeyid->id = g_strdup(keyid);
pubkeyid->received = FALSE; pubkeyid->received = FALSE;
g_hash_table_replace(pubkeys, strdup(jid), pubkeyid); g_hash_table_replace(pubkeys, g_strdup(jid), pubkeyid);
gpgme_key_unref(key); gpgme_key_unref(key);
} }
} }
@@ -217,7 +215,7 @@ p_gpg_on_disconnect(void)
} }
gboolean gboolean
p_gpg_addkey(const char* const jid, const char* const keyid) p_gpg_addkey(const gchar* const jid, const gchar* const keyid)
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t error = gpgme_new(&ctx); gpgme_error_t error = gpgme_new(&ctx);
@@ -240,10 +238,10 @@ p_gpg_addkey(const char* const jid, const char* const keyid)
_save_pubkeys(); _save_pubkeys();
// update in memory pubkeys list // update in memory pubkeys list
ProfPGPPubKeyId* pubkeyid = malloc(sizeof(ProfPGPPubKeyId)); ProfPGPPubKeyId* pubkeyid = g_new0(ProfPGPPubKeyId, 1);
pubkeyid->id = strdup(keyid); pubkeyid->id = g_strdup(keyid);
pubkeyid->received = FALSE; pubkeyid->received = FALSE;
g_hash_table_replace(pubkeys, strdup(jid), pubkeyid); g_hash_table_replace(pubkeys, g_strdup(jid), pubkeyid);
gpgme_key_unref(key); gpgme_key_unref(key);
return TRUE; return TRUE;
@@ -252,7 +250,7 @@ p_gpg_addkey(const char* const jid, const char* const keyid)
ProfPGPKey* ProfPGPKey*
p_gpg_key_new(void) p_gpg_key_new(void)
{ {
ProfPGPKey* p_pgpkey = malloc(sizeof(ProfPGPKey)); ProfPGPKey* p_pgpkey = g_new0(ProfPGPKey, 1);
p_pgpkey->id = NULL; p_pgpkey->id = NULL;
p_pgpkey->name = NULL; p_pgpkey->name = NULL;
p_pgpkey->fp = NULL; p_pgpkey->fp = NULL;
@@ -269,10 +267,10 @@ void
p_gpg_free_key(ProfPGPKey* key) p_gpg_free_key(ProfPGPKey* key)
{ {
if (key) { if (key) {
free(key->id); g_free(key->id);
free(key->name); g_free(key->name);
free(key->fp); g_free(key->fp);
free(key); g_free(key);
} }
} }
@@ -295,7 +293,7 @@ GHashTable*
p_gpg_list_keys(void) p_gpg_list_keys(void)
{ {
gpgme_error_t error; gpgme_error_t error;
GHashTable* result = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)p_gpg_free_key); GHashTable* result = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)p_gpg_free_key);
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
error = gpgme_new(&ctx); error = gpgme_new(&ctx);
@@ -313,7 +311,7 @@ p_gpg_list_keys(void)
while (!error) { while (!error) {
ProfPGPKey* p_pgpkey = _gpgme_key_to_ProfPGPKey(key); ProfPGPKey* p_pgpkey = _gpgme_key_to_ProfPGPKey(key);
if (p_pgpkey != NULL) { if (p_pgpkey != NULL) {
g_hash_table_insert(result, strdup(p_pgpkey->name), p_pgpkey); g_hash_table_insert(result, g_strdup(p_pgpkey->name), p_pgpkey);
} }
gpgme_key_unref(key); gpgme_key_unref(key);
@@ -370,7 +368,7 @@ p_gpg_pubkeys(void)
return pubkeys; return pubkeys;
} }
const char* const gchar*
p_gpg_libver(void) p_gpg_libver(void)
{ {
if (libversion == NULL) { if (libversion == NULL) {
@@ -380,14 +378,14 @@ p_gpg_libver(void)
} }
gboolean gboolean
p_gpg_valid_key(const char* const keyid, char** err_str) p_gpg_valid_key(const gchar* const keyid, gchar** err_str)
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t error = gpgme_new(&ctx); gpgme_error_t error = gpgme_new(&ctx);
if (error) { if (error) {
log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error)); log_error("GPG: Failed to create gpgme context. %s %s", gpgme_strsource(error), gpgme_strerror(error));
if (err_str) { if (err_str) {
*err_str = strdup(gpgme_strerror(error)); *err_str = g_strdup(gpgme_strerror(error));
} }
return FALSE; return FALSE;
} }
@@ -398,7 +396,7 @@ p_gpg_valid_key(const char* const keyid, char** err_str)
if (error || key == NULL) { if (error || key == NULL) {
log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error)); log_error("GPG: Failed to get key. %s %s", gpgme_strsource(error), gpgme_strerror(error));
if (err_str) { if (err_str) {
*err_str = strdup(error ? gpgme_strerror(error) : "gpgme didn't return any error, but it didn't return a key"); *err_str = g_strdup(error ? gpgme_strerror(error) : "gpgme didn't return any error, but it didn't return a key");
} }
gpgme_release(ctx); gpgme_release(ctx);
return FALSE; return FALSE;
@@ -410,14 +408,14 @@ p_gpg_valid_key(const char* const keyid, char** err_str)
} }
gboolean gboolean
p_gpg_available(const char* const barejid) p_gpg_available(const gchar* const barejid)
{ {
char* pubkey = g_hash_table_lookup(pubkeys, barejid); gchar* pubkey = g_hash_table_lookup(pubkeys, barejid);
return (pubkey != NULL); return (pubkey != NULL);
} }
void void
p_gpg_verify(const char* const barejid, const char* const sign) p_gpg_verify(const gchar* const barejid, const gchar* const sign)
{ {
if (!sign) { if (!sign) {
return; return;
@@ -431,7 +429,7 @@ p_gpg_verify(const char* const barejid, const char* const sign)
return; return;
} }
auto_char char* sign_with_header_footer = _add_header_footer(sign, PGP_SIGNATURE_HEADER, PGP_SIGNATURE_FOOTER); auto_gchar gchar* sign_with_header_footer = _add_header_footer(sign, PGP_SIGNATURE_HEADER, PGP_SIGNATURE_FOOTER);
gpgme_data_t sign_data; gpgme_data_t sign_data;
gpgme_data_new_from_mem(&sign_data, sign_with_header_footer, strlen(sign_with_header_footer), 1); gpgme_data_new_from_mem(&sign_data, sign_with_header_footer, strlen(sign_with_header_footer), 1);
@@ -457,10 +455,10 @@ p_gpg_verify(const char* const barejid, const char* const sign)
log_debug("Could not find PGP key with ID %s for %s", result->signatures->fpr, barejid); log_debug("Could not find PGP key with ID %s for %s", result->signatures->fpr, barejid);
} else { } else {
log_debug("Fingerprint found for %s: %s ", barejid, key->subkeys->fpr); log_debug("Fingerprint found for %s: %s ", barejid, key->subkeys->fpr);
ProfPGPPubKeyId* pubkeyid = malloc(sizeof(ProfPGPPubKeyId)); ProfPGPPubKeyId* pubkeyid = g_new0(ProfPGPPubKeyId, 1);
pubkeyid->id = strdup(key->subkeys->keyid); pubkeyid->id = g_strdup(key->subkeys->keyid);
pubkeyid->received = TRUE; pubkeyid->received = TRUE;
g_hash_table_replace(pubkeys, strdup(barejid), pubkeyid); g_hash_table_replace(pubkeys, g_strdup(barejid), pubkeyid);
} }
gpgme_key_unref(key); gpgme_key_unref(key);
@@ -470,8 +468,8 @@ p_gpg_verify(const char* const barejid, const char* const sign)
gpgme_release(ctx); gpgme_release(ctx);
} }
char* gchar*
p_gpg_sign(const char* const str, const char* const fp) p_gpg_sign(const gchar* const str, const gchar* const fp)
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t error = gpgme_new(&ctx); gpgme_error_t error = gpgme_new(&ctx);
@@ -507,6 +505,10 @@ p_gpg_sign(const char* const str, const char* const fp)
} else { } else {
str_or_empty = strdup(""); str_or_empty = strdup("");
} }
if (!str_or_empty) {
log_error("GPG: strdup failed");
return NULL;
}
gpgme_data_t str_data; gpgme_data_t str_data;
gpgme_data_new_from_mem(&str_data, str_or_empty, strlen(str_or_empty), 1); gpgme_data_new_from_mem(&str_data, str_or_empty, strlen(str_or_empty), 1);
@@ -524,10 +526,10 @@ p_gpg_sign(const char* const str, const char* const fp)
return NULL; return NULL;
} }
char* result = NULL; gchar* result = NULL;
size_t len = 0; size_t len = 0;
char* signed_str = gpgme_data_release_and_get_mem(signed_data, &len); gchar* signed_str = gpgme_data_release_and_get_mem(signed_data, &len);
if (signed_str) { if (signed_str) {
GString* signed_gstr = g_string_new(""); GString* signed_gstr = g_string_new("");
g_string_append_len(signed_gstr, signed_str, len); g_string_append_len(signed_gstr, signed_str, len);
@@ -537,14 +539,14 @@ p_gpg_sign(const char* const str, const char* const fp)
} }
if (passphrase_attempt) { if (passphrase_attempt) {
passphrase = strdup(passphrase_attempt); passphrase = g_strdup(passphrase_attempt);
} }
return result; return result;
} }
char* gchar*
p_gpg_encrypt(const char* const barejid, const char* const message, const char* const fp) p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp)
{ {
ProfPGPPubKeyId* pubkeyid = g_hash_table_lookup(pubkeys, barejid); ProfPGPPubKeyId* pubkeyid = g_hash_table_lookup(pubkeys, barejid);
if (!pubkeyid) { if (!pubkeyid) {
@@ -618,8 +620,8 @@ p_gpg_encrypt(const char* const barejid, const char* const message, const char*
return result; return result;
} }
char* gchar*
p_gpg_decrypt(const char* const cipher) p_gpg_decrypt(const gchar* const cipher)
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
gpgme_error_t error = gpgme_new(&ctx); gpgme_error_t error = gpgme_new(&ctx);
@@ -631,7 +633,7 @@ p_gpg_decrypt(const char* const cipher)
gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL); gpgme_set_passphrase_cb(ctx, (gpgme_passphrase_cb_t)_p_gpg_passphrase_cb, NULL);
auto_char char* cipher_with_headers = _add_header_footer(cipher, PGP_MESSAGE_HEADER, PGP_MESSAGE_FOOTER); auto_gchar gchar* cipher_with_headers = _add_header_footer(cipher, PGP_MESSAGE_HEADER, PGP_MESSAGE_FOOTER);
gpgme_data_t cipher_data; gpgme_data_t cipher_data;
gpgme_data_new_from_mem(&cipher_data, cipher_with_headers, strlen(cipher_with_headers), 1); gpgme_data_new_from_mem(&cipher_data, cipher_with_headers, strlen(cipher_with_headers), 1);
@@ -657,7 +659,7 @@ p_gpg_decrypt(const char* const cipher)
error = gpgme_get_key(ctx, recipient->keyid, &key, 1); error = gpgme_get_key(ctx, recipient->keyid, &key, 1);
if (!error && key) { if (!error && key) {
const char* addr = _gpgme_key_get_email(key); const gchar* addr = _gpgme_key_get_email(key);
if (addr) { if (addr) {
g_string_append(recipients_str, addr); g_string_append(recipients_str, addr);
} }
@@ -677,7 +679,7 @@ p_gpg_decrypt(const char* const cipher)
gpgme_release(ctx); gpgme_release(ctx);
if (passphrase_attempt) { if (passphrase_attempt) {
passphrase = strdup(passphrase_attempt); passphrase = g_strdup(passphrase_attempt);
} }
return _gpgme_data_to_char(plain_data); return _gpgme_data_to_char(plain_data);
@@ -689,8 +691,8 @@ p_gpg_free_decrypted(char* decrypted)
g_free(decrypted); g_free(decrypted);
} }
char* gchar*
p_gpg_autocomplete_key(const char* const search_str, gboolean previous, void* context) p_gpg_autocomplete_key(const gchar* const search_str, gboolean previous, void* context)
{ {
return autocomplete_complete(key_ac, search_str, TRUE, previous); return autocomplete_complete(key_ac, search_str, TRUE, previous);
} }
@@ -701,8 +703,8 @@ p_gpg_autocomplete_key_reset(void)
autocomplete_reset(key_ac); autocomplete_reset(key_ac);
} }
char* gchar*
p_gpg_format_fp_str(char* fp) p_gpg_format_fp_str(gchar* fp)
{ {
if (!fp) { if (!fp) {
return NULL; return NULL;
@@ -725,12 +727,12 @@ p_gpg_format_fp_str(char* fp)
* *
* @param keyid The key ID for which to retrieve the public key data. * @param keyid The key ID for which to retrieve the public key data.
* If the key ID is empty or NULL, returns NULL. * If the key ID is empty or NULL, returns NULL.
* @return The public key data as a null-terminated char* string allocated using malloc. * @return The public key data as a null-terminated gchar* string allocated using malloc.
* The returned string should be freed by the caller. * The returned string should be freed by the caller.
* Returns NULL on error, and errors are written to the error log. * Returns NULL on error, and errors are written to the error log.
*/ */
char* gchar*
p_gpg_get_pubkey(const char* keyid) p_gpg_get_pubkey(const gchar* keyid)
{ {
if (!keyid || *keyid == '\0') { if (!keyid || *keyid == '\0') {
return NULL; return NULL;
@@ -774,18 +776,18 @@ cleanup:
* @return TRUE if the buffer has the expected header and footer of an armored public key, FALSE otherwise. * @return TRUE if the buffer has the expected header and footer of an armored public key, FALSE otherwise.
*/ */
gboolean gboolean
p_gpg_is_public_key_format(const char* buffer) p_gpg_is_public_key_format(const gchar* buffer)
{ {
if (buffer == NULL || buffer[0] == '\0') { if (buffer == NULL || buffer[0] == '\0') {
return false; return false;
} }
const char* headerPos = strstr(buffer, PGP_PUBLIC_KEY_HEADER); const gchar* headerPos = strstr(buffer, PGP_PUBLIC_KEY_HEADER);
if (headerPos == NULL) { if (headerPos == NULL) {
return false; return false;
} }
const char* footerPos = strstr(buffer, PGP_PUBLIC_KEY_FOOTER); const gchar* footerPos = strstr(buffer, PGP_PUBLIC_KEY_FOOTER);
return (footerPos != NULL && footerPos > headerPos); return (footerPos != NULL && footerPos > headerPos);
} }
@@ -800,7 +802,7 @@ p_gpg_is_public_key_format(const char* buffer)
* by calling p_gpg_free_key() to avoid resource leaks. * by calling p_gpg_free_key() to avoid resource leaks.
*/ */
ProfPGPKey* ProfPGPKey*
p_gpg_import_pubkey(const char* buffer) p_gpg_import_pubkey(const gchar* buffer)
{ {
gpgme_ctx_t ctx; gpgme_ctx_t ctx;
ProfPGPKey* result = NULL; ProfPGPKey* result = NULL;
@@ -870,9 +872,9 @@ _gpgme_key_to_ProfPGPKey(gpgme_key_t key)
ProfPGPKey* p_pgpkey = p_gpg_key_new(); ProfPGPKey* p_pgpkey = p_gpg_key_new();
gpgme_subkey_t sub = key->subkeys; gpgme_subkey_t sub = key->subkeys;
p_pgpkey->id = strdup(sub->keyid); p_pgpkey->id = g_strdup(sub->keyid);
p_pgpkey->name = strdup(key->uids->uid); p_pgpkey->name = g_strdup(key->uids->uid);
p_pgpkey->fp = strdup(sub->fpr); p_pgpkey->fp = g_strdup(sub->fpr);
while (sub) { while (sub) {
if (sub->can_encrypt) if (sub->can_encrypt)
@@ -899,7 +901,7 @@ _gpgme_key_to_ProfPGPKey(gpgme_key_t key)
* @return The first email address found in the key's user IDs, or NULL if none found. * @return The first email address found in the key's user IDs, or NULL if none found.
* The returned string should not be freed as it points to internal gpgme memory. * The returned string should not be freed as it points to internal gpgme memory.
*/ */
static const char* static const gchar*
_gpgme_key_get_email(gpgme_key_t key) _gpgme_key_get_email(gpgme_key_t key)
{ {
if (!key) { if (!key) {
@@ -930,7 +932,7 @@ _gpgme_key_get_email(gpgme_key_t key)
* @return The converted string allocated using malloc, which should be freed by the caller. * @return The converted string allocated using malloc, which should be freed by the caller.
* If an error occurs or the data is empty, NULL is returned and errors are written to the error log. * If an error occurs or the data is empty, NULL is returned and errors are written to the error log.
*/ */
static char* static gchar*
_gpgme_data_to_char(gpgme_data_t data) _gpgme_data_to_char(gpgme_data_t data)
{ {
size_t buffer_size = 0; size_t buffer_size = 0;
@@ -941,16 +943,13 @@ _gpgme_data_to_char(gpgme_data_t data)
return NULL; return NULL;
} }
char* buffer = malloc(buffer_size + 1); gchar* buffer = g_strndup(gpgme_buffer, buffer_size);
memcpy(buffer, gpgme_buffer, buffer_size);
buffer[buffer_size] = '\0';
gpgme_free(gpgme_buffer); gpgme_free(gpgme_buffer);
return buffer; return buffer;
} }
static char* static gchar*
_remove_header_footer(char* str, const char* const footer) _remove_header_footer(gchar* str, const char* const footer)
{ {
int pos = 0; int pos = 0;
int newlines = 0; int newlines = 0;
@@ -966,15 +965,15 @@ _remove_header_footer(char* str, const char* const footer)
} }
} }
char* stripped = strdup(&str[pos]); gchar* stripped = g_strdup(&str[pos]);
char* footer_start = g_strrstr(stripped, footer); gchar* footer_start = g_strrstr(stripped, footer);
footer_start[0] = '\0'; footer_start[0] = '\0';
return stripped; return stripped;
} }
static char* static gchar*
_add_header_footer(const char* const str, const char* const header, const char* const footer) _add_header_footer(const gchar* const str, const char* const header, const char* const footer)
{ {
return g_strdup_printf("%s\n\n%s\n%s", header, str, footer); return g_strdup_printf("%s\n\n%s\n%s", header, str, footer);
} }

View File

@@ -38,9 +38,9 @@
typedef struct pgp_key_t typedef struct pgp_key_t
{ {
char* id; gchar* id;
char* name; gchar* name;
char* fp; gchar* fp;
gboolean encrypt; gboolean encrypt;
gboolean sign; gboolean sign;
gboolean certify; gboolean certify;
@@ -50,31 +50,31 @@ typedef struct pgp_key_t
typedef struct pgp_pubkeyid_t typedef struct pgp_pubkeyid_t
{ {
char* id; gchar* id;
gboolean received; gboolean received;
} ProfPGPPubKeyId; } ProfPGPPubKeyId;
void p_gpg_init(void); void p_gpg_init(void);
void p_gpg_on_connect(const char* const barejid); void p_gpg_on_connect(const gchar* const barejid);
void p_gpg_on_disconnect(void); void p_gpg_on_disconnect(void);
GHashTable* p_gpg_list_keys(void); GHashTable* p_gpg_list_keys(void);
void p_gpg_free_keys(GHashTable* keys); void p_gpg_free_keys(GHashTable* keys);
gboolean p_gpg_addkey(const char* const jid, const char* const keyid); gboolean p_gpg_addkey(const gchar* const jid, const gchar* const keyid);
GHashTable* p_gpg_pubkeys(void); GHashTable* p_gpg_pubkeys(void);
gboolean p_gpg_valid_key(const char* const keyid, char** err_str); gboolean p_gpg_valid_key(const gchar* const keyid, gchar** err_str);
gboolean p_gpg_available(const char* const barejid); gboolean p_gpg_available(const gchar* const barejid);
const char* p_gpg_libver(void); const gchar* p_gpg_libver(void);
char* p_gpg_sign(const char* const str, const char* const fp); gchar* p_gpg_sign(const gchar* const str, const gchar* const fp);
void p_gpg_verify(const char* const barejid, const char* const sign); void p_gpg_verify(const gchar* const barejid, const gchar* const sign);
char* p_gpg_encrypt(const char* const barejid, const char* const message, const char* const fp); gchar* p_gpg_encrypt(const gchar* const barejid, const gchar* const message, const gchar* const fp);
char* p_gpg_decrypt(const char* const cipher); gchar* p_gpg_decrypt(const gchar* const cipher);
void p_gpg_free_decrypted(char* decrypted); void p_gpg_free_decrypted(gchar* decrypted);
char* p_gpg_autocomplete_key(const char* const search_str, gboolean previous, void* context); gchar* p_gpg_autocomplete_key(const gchar* const search_str, gboolean previous, void* context);
void p_gpg_autocomplete_key_reset(void); void p_gpg_autocomplete_key_reset(void);
char* p_gpg_format_fp_str(char* fp); gchar* p_gpg_format_fp_str(gchar* fp);
char* p_gpg_get_pubkey(const char* const keyid); gchar* p_gpg_get_pubkey(const gchar* const keyid);
gboolean p_gpg_is_public_key_format(const char* buffer); gboolean p_gpg_is_public_key_format(const gchar* buffer);
ProfPGPKey* p_gpg_import_pubkey(const char* buffer); ProfPGPKey* p_gpg_import_pubkey(const gchar* buffer);
ProfPGPKey* p_gpg_key_new(void); ProfPGPKey* p_gpg_key_new(void);
void p_gpg_free_key(ProfPGPKey* key); void p_gpg_free_key(ProfPGPKey* key);

View File

@@ -476,7 +476,7 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean
ProfAccount* account = accounts_get_account(session_get_account_name()); ProfAccount* account = accounts_get_account(session_get_account_name());
if (account->pgp_keyid) { if (account->pgp_keyid) {
auto_jid Jid* jidp = jid_create(jid); auto_jid Jid* jidp = jid_create(jid);
auto_char char* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid); auto_gchar gchar* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
if (encrypted) { if (encrypted) {
message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id); message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, "This message is encrypted (XEP-0027)."); xmpp_message_set_body(message, "This message is encrypted (XEP-0027).");

View File

@@ -26,35 +26,35 @@ p_gpg_libver(void)
} }
void void
p_gpg_verify(const char* const barejid, const char* const sign) p_gpg_verify(const gchar* const barejid, const gchar* const sign)
{ {
} }
char* gchar*
p_gpg_sign(const char* const str, const char* const fp) p_gpg_sign(const gchar* const str, const gchar* const fp)
{ {
return NULL; return NULL;
} }
gboolean gboolean
p_gpg_valid_key(const char* const keyid, char** err_str) p_gpg_valid_key(const gchar* const keyid, gchar** err_str)
{ {
return FALSE; return FALSE;
} }
gboolean gboolean
p_gpg_available(const char* const barejid) p_gpg_available(const gchar* const barejid)
{ {
return FALSE; return FALSE;
} }
char* gchar*
p_gpg_decrypt(const char* const cipher) p_gpg_decrypt(const gchar* const cipher)
{ {
return NULL; return NULL;
} }
void void
p_gpg_on_connect(const char* const barejid) p_gpg_on_connect(const gchar* const barejid)
{ {
} }
void void
@@ -63,13 +63,13 @@ p_gpg_on_disconnect(void)
} }
gboolean gboolean
p_gpg_addkey(const char* const jid, const char* const keyid) p_gpg_addkey(const gchar* const jid, const gchar* const keyid)
{ {
return TRUE; return TRUE;
} }
void void
p_gpg_free_decrypted(char* decrypted) p_gpg_free_decrypted(gchar* decrypted)
{ {
} }
@@ -83,32 +83,32 @@ p_gpg_autocomplete_key_reset(void)
{ {
} }
char* gchar*
p_gpg_autocomplete_key(const char* const search_str, gboolean previous, void* context) p_gpg_autocomplete_key(const gchar* const search_str, gboolean previous, void* context)
{ {
return NULL; return NULL;
} }
char* gchar*
p_gpg_format_fp_str(char* fp) p_gpg_format_fp_str(gchar* fp)
{ {
return NULL; return NULL;
} }
char* gchar*
p_gpg_get_pubkey(const char* const keyid) p_gpg_get_pubkey(const gchar* const keyid)
{ {
return NULL; return NULL;
} }
gboolean gboolean
p_gpg_is_public_key_format(const char* buffer) p_gpg_is_public_key_format(const gchar* buffer)
{ {
return TRUE; return TRUE;
} }
ProfPGPKey* ProfPGPKey*
p_gpg_import_pubkey(const char* buffer) p_gpg_import_pubkey(const gchar* buffer)
{ {
return NULL; return NULL;
} }