1
0
Fork 0

Merge pull request #1942 from profanity-im/minor-improvements

Minor improvements
This commit is contained in:
Michael Vetter 2023-12-14 11:56:27 +01:00 committed by GitHub
commit 605ee6e99a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
36 changed files with 1524 additions and 431 deletions

1327
prof.supp

File diff suppressed because it is too large Load Diff

View File

@ -85,8 +85,7 @@ void
chat_log_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
_chat_log_chat(connection_get_barejid(), barejid, msg, PROF_OUT_LOG, NULL, resource);
}
}
@ -94,7 +93,7 @@ void
chat_log_otr_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG);
if (strcmp(pref_otr_log, "on") == 0) {
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
@ -108,7 +107,7 @@ void
chat_log_pgp_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
if (strcmp(pref_pgp_log, "on") == 0) {
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
@ -122,7 +121,7 @@ void
chat_log_omemo_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) {
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
@ -136,7 +135,7 @@ void
chat_log_otr_msg_in(ProfMessage* message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG);
if (message->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
@ -158,7 +157,7 @@ void
chat_log_pgp_msg_in(ProfMessage* message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
if (strcmp(pref_pgp_log, "on") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
@ -180,7 +179,7 @@ void
chat_log_omemo_msg_in(ProfMessage* message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
@ -202,7 +201,7 @@ void
chat_log_msg_in(ProfMessage* message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
@ -308,9 +307,8 @@ void
groupchat_log_msg_out(const gchar* const room, const gchar* const msg)
{
if (prefs_get_boolean(PREF_GRLOG)) {
auto_char char* mybarejid = connection_get_barejid();
char* mynick = muc_nick(room);
_groupchat_log_chat(mybarejid, room, mynick, msg);
_groupchat_log_chat(connection_get_barejid(), room, mynick, msg);
}
}
@ -318,8 +316,7 @@ void
groupchat_log_msg_in(const gchar* const room, const gchar* const nick, const gchar* const msg)
{
if (prefs_get_boolean(PREF_GRLOG)) {
auto_char char* mybarejid = connection_get_barejid();
_groupchat_log_chat(mybarejid, room, nick, msg);
_groupchat_log_chat(connection_get_barejid(), room, nick, msg);
}
}
@ -327,7 +324,7 @@ void
groupchat_log_omemo_msg_out(const gchar* const room, const gchar* const msg)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
char* mynick = muc_nick(room);
@ -343,7 +340,7 @@ void
groupchat_log_omemo_msg_in(const gchar* const room, const gchar* const nick, const gchar* const msg)
{
if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid();
const char* mybarejid = connection_get_barejid();
auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) {

View File

@ -231,10 +231,8 @@ cmd_process_input(ProfWin* window, char* inp)
void
cmd_execute_connect(ProfWin* window, const char* const account)
{
GString* command = g_string_new("/connect ");
g_string_append(command, account);
cmd_process_input(window, command->str);
g_string_free(command, TRUE);
auto_gchar gchar* command = g_strdup_printf("/connect %s", account);
cmd_process_input(window, command);
}
gboolean
@ -2207,21 +2205,16 @@ cmd_msg(ProfWin* window, const char* const command, gchar** args)
cons_show("Starting direct message with occupant \"%s\" from room \"%s\" as \"%s\".", usr, mucwin->roomjid, jidp->barejid);
} else {
// otherwise send mucpm
GString* full_jid = g_string_new(mucwin->roomjid);
g_string_append(full_jid, "/");
g_string_append(full_jid, usr);
ProfPrivateWin* privwin = wins_get_private(full_jid->str);
auto_gchar gchar* full_jid = g_strdup_printf("%s/%s", mucwin->roomjid, usr);
ProfPrivateWin* privwin = wins_get_private(full_jid);
if (!privwin) {
privwin = (ProfPrivateWin*)wins_new_private(full_jid->str);
privwin = (ProfPrivateWin*)wins_new_private(full_jid);
}
ui_focus_win((ProfWin*)privwin);
if (msg) {
cl_ev_send_priv_msg(privwin, msg, NULL);
}
g_string_free(full_jid, TRUE);
}
} else {
@ -3448,12 +3441,11 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
static void
_send_software_version_iq_to_fulljid(char* request)
{
auto_char char* mybarejid = connection_get_barejid();
auto_jid Jid* jid = jid_create(request);
if (jid == NULL || jid->fulljid == NULL) {
cons_show("You must provide a full jid to the /software command.");
} else if (g_strcmp0(jid->barejid, mybarejid) == 0) {
} else if (equals_our_barejid(jid->barejid)) {
cons_show("Cannot request software version for yourself.");
} else {
iq_send_software_version(jid->fulljid);
@ -3503,10 +3495,8 @@ cmd_software(ProfWin* window, const char* const command, gchar** args)
}
if (resource) {
GString* fulljid = g_string_new(chatwin->barejid);
g_string_append_printf(fulljid, "/%s", resource);
iq_send_software_version(fulljid->str);
g_string_free(fulljid, TRUE);
auto_gchar gchar* fulljid = g_strdup_printf("%s/%s", chatwin->barejid, resource);
iq_send_software_version(fulljid);
} else {
win_println(window, THEME_DEFAULT, "-", "Unknown resource for /software command. See /help resource.");
}
@ -3566,20 +3556,17 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
if (args[0] == NULL) {
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
if (account->muc_service) {
GString* room_str = g_string_new("");
if (account && account->muc_service) {
char* uuid = connection_create_uuid();
g_string_append_printf(room_str, "private-chat-%s@%s", uuid, account->muc_service);
auto_gchar gchar* room_str = g_strdup_printf("private-chat-%s@%s", uuid, account->muc_service);
connection_free_uuid(uuid);
presence_join_room(room_str->str, account->muc_nick, NULL);
muc_join(room_str->str, account->muc_nick, NULL, FALSE);
g_string_free(room_str, TRUE);
account_free(account);
presence_join_room(room_str, account->muc_nick, NULL);
muc_join(room_str, account->muc_nick, NULL, FALSE);
} else {
cons_show("Account MUC service property not found.");
}
account_free(account);
return TRUE;
}
@ -4123,10 +4110,8 @@ cmd_subject(ProfWin* window, const char* const command, gchar** args)
if (args[1]) {
char* old_subject = muc_subject(mucwin->roomjid);
if (old_subject) {
GString* new_subject = g_string_new(args[1]);
g_string_append(new_subject, old_subject);
message_send_groupchat_subject(mucwin->roomjid, new_subject->str);
g_string_free(new_subject, TRUE);
auto_gchar gchar* new_subject = g_strdup_printf("%s%s", args[1], old_subject);
message_send_groupchat_subject(mucwin->roomjid, new_subject);
} else {
win_print(window, THEME_ROOMINFO, "!", "Room does not have a subject, use /subject set <subject>");
}
@ -4140,10 +4125,8 @@ cmd_subject(ProfWin* window, const char* const command, gchar** args)
if (args[1]) {
char* old_subject = muc_subject(mucwin->roomjid);
if (old_subject) {
GString* new_subject = g_string_new(old_subject);
g_string_append(new_subject, args[1]);
message_send_groupchat_subject(mucwin->roomjid, new_subject->str);
g_string_free(new_subject, TRUE);
auto_gchar gchar* new_subject = g_strdup_printf("%s%s", old_subject, args[1]);
message_send_groupchat_subject(mucwin->roomjid, new_subject);
} else {
win_print(window, THEME_ROOMINFO, "!", "Room does not have a subject, use /subject set <subject>");
}
@ -4838,22 +4821,14 @@ cmd_disco(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
GString* jid = g_string_new("");
if (args[1]) {
jid = g_string_append(jid, args[1]);
} else {
auto_jid Jid* jidp = jid_create(connection_get_fulljid());
jid = g_string_append(jid, jidp->domainpart);
}
auto_gchar gchar* jid = g_strdup_printf("%s", args[1] ?: connection_get_jid()->domainpart);
if (g_strcmp0(args[0], "info") == 0) {
iq_disco_info_request(jid->str);
iq_disco_info_request(jid);
} else {
iq_disco_items_request(jid->str);
iq_disco_items_request(jid);
}
g_string_free(jid, TRUE);
return TRUE;
}
@ -5039,18 +5014,11 @@ cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)
if ((g_strcmp0(args[0], "get") == 0)) {
if (args[1] == NULL) {
auto_jid Jid* jidp = jid_create(connection_get_fulljid());
GString* jid = g_string_new(jidp->domainpart);
iq_last_activity_request(jid->str);
g_string_free(jid, TRUE);
return TRUE;
iq_last_activity_request(connection_get_jid()->domainpart);
} else {
iq_last_activity_request(args[1]);
return TRUE;
}
return TRUE;
}
cons_bad_cmd_usage(command);
@ -5095,32 +5063,26 @@ cmd_alias(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
char* alias_p = alias;
GString* ac_value = g_string_new("");
auto_gchar gchar* ac_value = NULL;
if (alias[0] == '/') {
g_string_append(ac_value, alias);
ac_value = g_strdup_printf("%s", alias);
alias_p = &alias[1];
} else {
g_string_append(ac_value, "/");
g_string_append(ac_value, alias);
ac_value = g_strdup_printf("/%s", alias);
}
char* value = args[2];
if (value == NULL) {
cons_bad_cmd_usage(command);
g_string_free(ac_value, TRUE);
return TRUE;
} else if (cmd_ac_exists(ac_value->str)) {
cons_show("Command or alias '%s' already exists.", ac_value->str);
g_string_free(ac_value, TRUE);
return TRUE;
} else if (cmd_ac_exists(ac_value)) {
cons_show("Command or alias '%s' already exists.", ac_value);
} else {
prefs_add_alias(alias_p, value);
cmd_ac_add(ac_value->str);
cmd_ac_add(ac_value);
cmd_ac_add_alias_value(alias_p);
cons_show("Command alias added %s -> %s", ac_value->str, value);
g_string_free(ac_value, TRUE);
return TRUE;
cons_show("Command alias added %s -> %s", ac_value, value);
}
return TRUE;
}
} else if (strcmp(subcmd, "remove") == 0) {
char* alias = args[1];
@ -5135,11 +5097,9 @@ cmd_alias(ProfWin* window, const char* const command, gchar** args)
if (!removed) {
cons_show("No such command alias /%s", alias);
} else {
GString* ac_value = g_string_new("/");
g_string_append(ac_value, alias);
cmd_ac_remove(ac_value->str);
auto_gchar gchar* ac_value = g_strdup_printf("/%s", alias);
cmd_ac_remove(ac_value);
cmd_ac_remove_alias_value(alias);
g_string_free(ac_value, TRUE);
cons_show("Command alias removed -> /%s", alias);
}
return TRUE;
@ -7438,10 +7398,7 @@ cmd_pgp(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
GString* fullstr = g_string_new("Using libgpgme version ");
g_string_append(fullstr, libver);
cons_show("%s", fullstr->str);
g_string_free(fullstr, TRUE);
cons_show("Using libgpgme version %s", libver);
return TRUE;
}
@ -7684,10 +7641,8 @@ cmd_ox(ProfWin* window, const char* const command, gchar** args)
GSList* curr_c = roster_list;
while (!contact && curr_c) {
contact = curr_c->data;
const char* jid = p_contact_barejid(contact);
GString* xmppuri = g_string_new("xmpp:");
g_string_append(xmppuri, jid);
if (g_strcmp0(key->name, xmppuri->str)) {
auto_gchar gchar* xmppuri = g_strdup_printf("xmpp:%s", p_contact_barejid(contact));
if (g_strcmp0(key->name, xmppuri)) {
contact = NULL;
}
curr_c = g_slist_next(curr_c);
@ -8333,7 +8288,7 @@ cmd_command_list(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
char* jid = args[1];
const char* jid = args[1];
if (jid == NULL) {
switch (window->type) {
case WIN_MUC:
@ -8394,7 +8349,7 @@ cmd_command_exec(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
char* jid = args[2];
const char* jid = args[2];
if (jid == NULL) {
switch (window->type) {
case WIN_MUC:
@ -9671,12 +9626,11 @@ cmd_change_password(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}
auto_char char* user = connection_get_user();
auto_char char* passwd = ui_ask_password(false);
auto_char char* confirm_passwd = ui_ask_password(true);
if (g_strcmp0(passwd, confirm_passwd) == 0) {
iq_register_change_password(user, passwd);
iq_register_change_password(connection_get_user(), passwd);
} else {
cons_show("Aborted! The new password and the confirmed password do not match.");
}
@ -10009,13 +9963,8 @@ cmd_vcard_get(ProfWin* window, const char* const command, gchar** args)
vcard_print(ctx, window, jid_occupant->barejid);
} else {
// anon muc: send the vcard request through the MUC's server
GString* full_jid = g_string_new(mucwin->roomjid);
g_string_append(full_jid, "/");
g_string_append(full_jid, user);
vcard_print(ctx, window, full_jid->str);
g_string_free(full_jid, TRUE);
auto_gchar gchar* full_jid = g_strdup_printf("%s/%s", mucwin->roomjid, user);
vcard_print(ctx, window, full_jid);
}
} else {
char* jid = roster_barejid_from_name(user);

View File

@ -652,7 +652,7 @@ format_call_external_argv(const char* template, const char* url, const char* fil
return argv;
}
gchar*
static gchar*
_unique_filename(const char* filename)
{
gchar* unique = g_strdup(filename);
@ -676,7 +676,7 @@ _unique_filename(const char* filename)
return unique;
}
bool
static bool
_has_directory_suffix(const char* path)
{
return (g_str_has_suffix(path, ".")
@ -774,13 +774,6 @@ unique_filename_from_url(const char* url, const char* path)
return unique_filename;
}
void
glib_hash_table_free(GHashTable* hash_table)
{
g_hash_table_remove_all(hash_table);
g_hash_table_unref(hash_table);
}
/* build profanity version string.
* example: 0.13.1dev.master.69d8c1f9
*/

View File

@ -193,7 +193,6 @@ gchar** format_call_external_argv(const char* template, const char* url, const c
gchar* unique_filename_from_url(const char* url, const char* path);
gchar* get_expanded_path(const char* path);
void glib_hash_table_free(GHashTable* hash_table);
char* basename_from_url(const char* url);
gchar* prof_get_version(void);

View File

@ -223,7 +223,7 @@ accounts_get_account(const char* const name)
} else {
jabber_conn_status_t conn_status = connection_get_status();
if (conn_status == JABBER_CONNECTED) {
char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
const char* conf_jid = connection_jid_for_feature(XMPP_FEATURE_MUC);
if (conf_jid) {
muc_service = strdup(conf_jid);
}

View File

@ -235,9 +235,7 @@ log_database_add_incoming(ProfMessage* message)
if (message->to_jid) {
_add_to_db(message, NULL, message->from_jid, message->to_jid);
} else {
auto_jid Jid* myjid = jid_create(connection_get_fulljid());
_add_to_db(message, NULL, message->from_jid, myjid);
_add_to_db(message, NULL, message->from_jid, connection_get_jid());
}
}
@ -253,9 +251,7 @@ _log_database_add_outgoing(char* type, const char* const id, const char* const b
msg->timestamp = g_date_time_new_now_local(); // TODO: get from outside. best to have whole ProfMessage from outside
msg->enc = enc;
auto_jid Jid* myjid = jid_create(connection_get_fulljid());
_add_to_db(msg, type, myjid, msg->from_jid); // TODO: myjid now in profmessage
_add_to_db(msg, type, connection_get_jid(), msg->from_jid); // TODO: myjid now in profmessage
message_free(msg);
}
@ -283,9 +279,8 @@ ProfMessage*
log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_last)
{
sqlite3_stmt* stmt = NULL;
const char* jid = connection_get_fulljid();
auto_jid Jid* myjid = jid_create(jid);
if (!myjid)
const Jid* myjid = connection_get_jid();
if (!myjid->str)
return NULL;
const char* order = is_last ? "DESC" : "ASC";
@ -327,9 +322,8 @@ GSList*
log_database_get_previous_chat(const gchar* const contact_barejid, const char* start_time, char* end_time, gboolean from_start, gboolean flip)
{
sqlite3_stmt* stmt = NULL;
const char* jid = connection_get_fulljid();
auto_jid Jid* myjid = jid_create(jid);
if (!myjid)
const Jid* myjid = connection_get_jid();
if (!myjid->str)
return NULL;
// Flip order when querying older pages

View File

@ -86,8 +86,7 @@ cl_ev_connect_account(ProfAccount* account)
void
cl_ev_disconnect(void)
{
auto_char char* mybarejid = connection_get_barejid();
cons_show("%s logged out successfully.", mybarejid);
cons_show("%s logged out successfully.", connection_get_barejid());
ui_close_all_wins();
ev_disconnect_cleanup();
@ -123,8 +122,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
if (account->pgp_keyid) {
char* msg = connection_get_presence_msg();
signed_status = p_gpg_sign(msg, account->pgp_keyid);
signed_status = p_gpg_sign(connection_get_presence_msg(), account->pgp_keyid);
}
account_free(account);
#endif

View File

@ -190,8 +190,7 @@ sv_ev_roster_received(void)
connection_set_presence_msg(status_message);
cl_ev_presence_send(conn_presence, diff_secs);
const char* fulljid = connection_get_fulljid();
plugins_on_connect(account_name, fulljid);
plugins_on_connect(account_name, connection_get_fulljid());
}
void
@ -630,8 +629,7 @@ sv_ev_incoming_message(ProfMessage* message)
char* looking_for_jid = message->from_jid->barejid;
if (message->is_mam) {
auto_char char* mybarejid = connection_get_barejid();
if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) {
if (equals_our_barejid(message->from_jid->barejid)) {
if (message->to_jid) {
looking_for_jid = message->to_jid->barejid;
}

View File

@ -66,8 +66,6 @@
#define AESGCM_URL_NONCE_LEN (2 * OMEMO_AESGCM_NONCE_LENGTH)
#define AESGCM_URL_KEY_LEN (2 * OMEMO_AESGCM_KEY_LENGTH)
static gboolean loaded;
static void _generate_pre_keys(int count);
static void _generate_signed_pre_key(void);
static gboolean _load_identity(void);
@ -87,10 +85,8 @@ static void _acquire_sender_devices_list(void);
typedef gboolean (*OmemoDeviceListHandler)(const char* const jid, GList* device_list);
struct omemo_context_t
typedef struct omemo_context
{
pthread_mutexattr_t attr;
pthread_mutex_t lock;
signal_context* signal;
uint32_t device_id;
GHashTable* device_list;
@ -108,11 +104,18 @@ struct omemo_context_t
prof_keyfile_t sessions;
prof_keyfile_t knowndevices;
GHashTable* known_devices;
GHashTable* fingerprint_ac;
};
gboolean loaded;
} omemo_context;
static omemo_context omemo_ctx;
static struct omemo_static_data
{
pthread_mutexattr_t attr;
pthread_mutex_t lock;
GHashTable* fingerprint_ac;
} omemo_static_data;
void
omemo_init(void)
{
@ -121,20 +124,21 @@ omemo_init(void)
cons_show("Error initializing OMEMO crypto: gcry_check_version() failed");
}
pthread_mutexattr_init(&omemo_ctx.attr);
pthread_mutexattr_settype(&omemo_ctx.attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&omemo_ctx.lock, &omemo_ctx.attr);
pthread_mutexattr_init(&omemo_static_data.attr);
pthread_mutexattr_settype(&omemo_static_data.attr, PTHREAD_MUTEX_RECURSIVE);
pthread_mutex_init(&omemo_static_data.lock, &omemo_static_data.attr);
omemo_ctx.fingerprint_ac = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)autocomplete_free);
omemo_static_data.fingerprint_ac = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)autocomplete_free);
}
void
omemo_close(void)
{
if (omemo_ctx.fingerprint_ac) {
g_hash_table_destroy(omemo_ctx.fingerprint_ac);
omemo_ctx.fingerprint_ac = NULL;
if (omemo_static_data.fingerprint_ac) {
g_hash_table_destroy(omemo_static_data.fingerprint_ac);
omemo_static_data.fingerprint_ac = NULL;
}
pthread_mutex_destroy(&omemo_static_data.lock);
}
void
@ -181,7 +185,7 @@ omemo_on_connect(ProfAccount* account)
.contains_session_func = contains_session,
.delete_session_func = delete_session,
.delete_all_sessions_func = delete_all_sessions,
.destroy_func = NULL,
.destroy_func = (void (*)(void*))g_hash_table_destroy,
.user_data = omemo_ctx.session_store
};
signal_protocol_store_context_set_session_store(omemo_ctx.store, &session_store);
@ -192,7 +196,7 @@ omemo_on_connect(ProfAccount* account)
.store_pre_key = store_pre_key,
.contains_pre_key = contains_pre_key,
.remove_pre_key = remove_pre_key,
.destroy_func = NULL,
.destroy_func = (void (*)(void*))g_hash_table_destroy,
.user_data = omemo_ctx.pre_key_store
};
signal_protocol_store_context_set_pre_key_store(omemo_ctx.store, &pre_key_store);
@ -203,7 +207,7 @@ omemo_on_connect(ProfAccount* account)
.store_signed_pre_key = store_signed_pre_key,
.contains_signed_pre_key = contains_signed_pre_key,
.remove_signed_pre_key = remove_signed_pre_key,
.destroy_func = NULL,
.destroy_func = (void (*)(void*))g_hash_table_destroy,
.user_data = omemo_ctx.signed_pre_key_store
};
signal_protocol_store_context_set_signed_pre_key_store(omemo_ctx.store, &signed_pre_key_store);
@ -219,10 +223,10 @@ omemo_on_connect(ProfAccount* account)
};
signal_protocol_store_context_set_identity_key_store(omemo_ctx.store, &identity_key_store);
loaded = FALSE;
omemo_ctx.loaded = FALSE;
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)glib_hash_table_free);
omemo_ctx.known_devices = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
auto_gchar gchar* omemo_dir = files_file_in_account_data_path(DIR_OMEMO, account->jid, NULL);
if (!omemo_dir) {
@ -253,15 +257,13 @@ omemo_on_connect(ProfAccount* account)
void
omemo_on_disconnect(void)
{
if (!loaded) {
if (!omemo_ctx.loaded) {
return;
}
glib_hash_table_free(omemo_ctx.signed_pre_key_store);
glib_hash_table_free(omemo_ctx.pre_key_store);
glib_hash_table_free(omemo_ctx.known_devices);
glib_hash_table_free(omemo_ctx.device_list_handler);
glib_hash_table_free(omemo_ctx.device_list);
g_hash_table_destroy(omemo_ctx.known_devices);
g_hash_table_destroy(omemo_ctx.device_list_handler);
g_hash_table_destroy(omemo_ctx.device_list);
free_keyfile(&omemo_ctx.knowndevices);
free_keyfile(&omemo_ctx.sessions);
@ -276,12 +278,13 @@ omemo_on_disconnect(void)
ec_public_key_destroy((signal_type_base*)pub);
signal_context_destroy(omemo_ctx.signal);
memset(&omemo_ctx, 0, sizeof(omemo_ctx));
}
void
omemo_generate_crypto_materials(ProfAccount* account)
{
if (loaded) {
if (omemo_ctx.loaded) {
return;
}
@ -316,7 +319,7 @@ omemo_generate_crypto_materials(ProfAccount* account)
omemo_identity_keyfile_save();
loaded = TRUE;
omemo_ctx.loaded = TRUE;
omemo_publish_crypto_materials();
omemo_start_sessions();
@ -327,7 +330,7 @@ omemo_publish_crypto_materials(void)
{
log_debug("[OMEMO] publish crypto materials");
if (loaded != TRUE) {
if (omemo_ctx.loaded != TRUE) {
cons_show("OMEMO: cannot publish crypto materials before they are generated");
log_error("[OMEMO] cannot publish crypto materials before they are generated");
return;
@ -339,7 +342,7 @@ omemo_publish_crypto_materials(void)
static void
_acquire_sender_devices_list(void)
{
auto_char char* barejid = connection_get_barejid();
const char* barejid = connection_get_barejid();
g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_own_device_list);
omemo_devicelist_request(barejid);
@ -375,8 +378,7 @@ omemo_start_session(const char* const barejid)
log_debug("[OMEMO] missing device list for %s", barejid);
// Own devices are handled by _handle_own_device_list
// We won't add _handle_device_list_start_session for ourself
auto_char char* mybarejid = connection_get_barejid();
if (g_strcmp0(mybarejid, barejid) != 0) {
if (equals_our_barejid(barejid)) {
g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_device_list_start_session);
}
omemo_devicelist_request(barejid);
@ -405,7 +407,7 @@ omemo_start_muc_sessions(const char* const roomjid)
gboolean
omemo_loaded(void)
{
return loaded;
return omemo_ctx.loaded;
}
uint32_t
@ -680,7 +682,7 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
{
char* id = NULL;
int res;
auto_jid Jid* jid = jid_create(connection_get_fulljid());
const Jid* jid = connection_get_jid();
GList* keys = NULL;
unsigned char* key;
@ -754,15 +756,12 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
// Don't encrypt for this device (according to
// <https://xmpp.org/extensions/xep-0384.html#encrypt>).
// Yourself as recipients in case of MUC
char* mybarejid = connection_get_barejid();
if (!g_strcmp0(mybarejid, recipients_iter->data)) {
if (equals_our_barejid(recipients_iter->data)) {
if (GPOINTER_TO_INT(device_ids_iter->data) == omemo_ctx.device_id) {
free(mybarejid);
log_debug("[OMEMO][SEND] Skipping %d (my device) ", GPOINTER_TO_INT(device_ids_iter->data));
continue;
}
}
free(mybarejid);
log_debug("[OMEMO][SEND] recipients with device id %d for %s", GPOINTER_TO_INT(device_ids_iter->data), recipients_iter->data);
res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
@ -1265,15 +1264,13 @@ omemo_untrust(const char* const jid, const char* const fingerprint_formatted)
static void
_lock(void* user_data)
{
omemo_context* ctx = (omemo_context*)user_data;
pthread_mutex_lock(&ctx->lock);
pthread_mutex_lock(&omemo_static_data.lock);
}
static void
_unlock(void* user_data)
{
omemo_context* ctx = (omemo_context*)user_data;
pthread_mutex_unlock(&ctx->lock);
pthread_mutex_unlock(&omemo_static_data.lock);
}
static void
@ -1341,7 +1338,7 @@ omemo_key_free(omemo_key_t* key)
char*
omemo_fingerprint_autocomplete(const char* const search_str, gboolean previous, void* context)
{
Autocomplete ac = g_hash_table_lookup(omemo_ctx.fingerprint_ac, context);
Autocomplete ac = g_hash_table_lookup(omemo_static_data.fingerprint_ac, context);
if (ac != NULL) {
return autocomplete_complete(ac, search_str, FALSE, previous);
} else {
@ -1352,9 +1349,11 @@ omemo_fingerprint_autocomplete(const char* const search_str, gboolean previous,
void
omemo_fingerprint_autocomplete_reset(void)
{
if (!omemo_static_data.fingerprint_ac)
return;
gpointer value;
GHashTableIter iter;
g_hash_table_iter_init(&iter, omemo_ctx.fingerprint_ac);
g_hash_table_iter_init(&iter, omemo_static_data.fingerprint_ac);
while (g_hash_table_iter_next(&iter, NULL, &value)) {
Autocomplete ac = value;
@ -1514,7 +1513,7 @@ _load_identity(void)
_generate_signed_pre_key();
}
loaded = TRUE;
omemo_ctx.loaded = TRUE;
omemo_identity_keyfile_save();
omemo_start_sessions();
@ -1626,10 +1625,10 @@ _cache_device_identity(const char* const jid, uint32_t device_id, ec_public_key*
g_key_file_set_string(omemo_ctx.knowndevices.keyfile, jid, device_id_str, fingerprint);
omemo_known_devices_keyfile_save();
Autocomplete ac = g_hash_table_lookup(omemo_ctx.fingerprint_ac, jid);
Autocomplete ac = g_hash_table_lookup(omemo_static_data.fingerprint_ac, jid);
if (ac == NULL) {
ac = autocomplete_new();
g_hash_table_insert(omemo_ctx.fingerprint_ac, strdup(jid), ac);
g_hash_table_insert(omemo_static_data.fingerprint_ac, strdup(jid), ac);
}
char* formatted_fingerprint = omemo_format_fingerprint(fingerprint);
@ -1806,14 +1805,10 @@ out:
char*
omemo_qrcode_str()
{
char* mybarejid = connection_get_barejid();
char* fingerprint = omemo_own_fingerprint(FALSE);
auto_char char* fingerprint = omemo_own_fingerprint(FALSE);
uint32_t sid = omemo_device_id();
char* qrstr = g_strdup_printf("xmpp:%s?omemo-sid-%d=%s", mybarejid, sid, fingerprint);
free(mybarejid);
free(fingerprint);
char* qrstr = g_strdup_printf("xmpp:%s?omemo-sid-%d=%s", connection_get_barejid(), sid, fingerprint);
return qrstr;
}

View File

@ -51,8 +51,6 @@ typedef enum {
PROF_OMEMOPOLICY_ALWAYS
} prof_omemopolicy_t;
typedef struct omemo_context_t omemo_context;
typedef struct omemo_key
{
unsigned char* data;

View File

@ -43,7 +43,7 @@
GHashTable*
session_store_new(void)
{
return g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)glib_hash_table_free);
return g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
}
GHashTable*
@ -61,7 +61,7 @@ signed_pre_key_store_new(void)
void
identity_key_store_new(identity_key_store_t* identity_key_store)
{
identity_key_store->trusted = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)glib_hash_table_free);
identity_key_store->trusted = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
identity_key_store->private = NULL;
identity_key_store->public = NULL;
}
@ -71,7 +71,7 @@ identity_key_store_destroy(identity_key_store_t* identity_key_store)
{
signal_buffer_bzero_free(identity_key_store->private);
signal_buffer_bzero_free(identity_key_store->public);
glib_hash_table_free(identity_key_store->trusted);
g_hash_table_destroy(identity_key_store->trusted);
}
int

View File

@ -240,7 +240,7 @@ api_get_current_nick(void)
char*
api_get_name_from_roster(const char* barejid)
{
return roster_get_display_name(barejid);
return strdup(roster_get_display_name(barejid));
}
char*

View File

@ -252,9 +252,7 @@ plugins_load(const char* const name, GString* error_message)
if (plugin) {
g_hash_table_insert(plugins, strdup(name), plugin);
if (connection_get_status() == JABBER_CONNECTED) {
const char* account_name = session_get_account_name();
const char* fulljid = connection_get_fulljid();
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, account_name, fulljid);
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, session_get_account_name(), connection_get_fulljid());
} else {
plugin->init_func(plugin, PACKAGE_VERSION, PACKAGE_STATUS, NULL, NULL);
}

View File

@ -452,7 +452,7 @@ python_api_get_name_from_roster(PyObject* self, PyObject* args)
char* barejid_str = python_str_or_unicode_to_string(barejid);
allow_python_threads();
char* name = roster_get_display_name(barejid_str);
char* name = strdup(roster_get_display_name(barejid_str));
free(barejid_str);
disable_python_threads();
if (name) {

View File

@ -56,7 +56,7 @@ get_message_from_editor(gchar* message, gchar** returned_message)
auto_gchar gchar* filename = NULL;
GError* glib_error = NULL;
auto_char char* jid = connection_get_barejid();
const char* jid = connection_get_barejid();
if (jid) {
filename = files_file_in_account_data_path(DIR_EDITOR, jid, "compose.md");
} else {

View File

@ -295,19 +295,7 @@ chatwin_recipient_gone(ProfChatWin* chatwin)
{
assert(chatwin != NULL);
const char* display_usr = NULL;
PContact contact = roster_get_contact(chatwin->barejid);
if (contact) {
if (p_contact_name(contact)) {
display_usr = p_contact_name(contact);
} else {
display_usr = chatwin->barejid;
}
} else {
display_usr = chatwin->barejid;
}
win_println((ProfWin*)chatwin, THEME_GONE, "!", "<- %s has left the conversation.", display_usr);
win_println((ProfWin*)chatwin, THEME_GONE, "!", "<- %s has left the conversation.", roster_get_display_name(chatwin->barejid));
}
void
@ -427,7 +415,7 @@ chatwin_outgoing_msg(ProfChatWin* chatwin, const char* const message, char* id,
auto_char char* enc_char = get_enc_char(enc_mode, chatwin->outgoing_char);
auto_jid Jid* myjid = jid_create(connection_get_fulljid());
const Jid* myjid = connection_get_jid();
auto_char char* display_message = plugins_pre_chat_message_display(myjid->barejid, myjid->resourcepart, strdup(message));
if (request_receipt && id) {

View File

@ -267,20 +267,7 @@ cons_show_tlscert(const TLSCertificate* cert)
void
cons_show_typing(const char* const barejid)
{
ProfWin* console = wins_get_console();
const char* display_usr = NULL;
PContact contact = roster_get_contact(barejid);
if (contact) {
if (p_contact_name(contact)) {
display_usr = p_contact_name(contact);
} else {
display_usr = barejid;
}
} else {
display_usr = barejid;
}
win_println(console, THEME_TYPING, "-", "!! %s is typing a message…", display_usr);
win_println(wins_get_console(), THEME_TYPING, "-", "!! %s is typing a message…", roster_get_display_name(barejid));
cons_alert(NULL);
}
@ -458,8 +445,7 @@ cons_show_login_success(ProfAccount* account, gboolean secured)
{
ProfWin* console = wins_get_console();
const char* fulljid = connection_get_fulljid();
win_print(console, THEME_DEFAULT, "-", "%s logged in successfully, ", fulljid);
win_print(console, THEME_DEFAULT, "-", "%s logged in successfully, ", connection_get_fulljid());
resource_presence_t presence = accounts_get_login_presence(account->name);
const char* presence_str = string_from_resource_presence(presence);
@ -926,17 +912,7 @@ cons_show_status(const char* const barejid)
void
cons_show_room_invite(const char* const invitor, const char* const room, const char* const reason)
{
auto_char char* display_from = NULL;
PContact contact = roster_get_contact(invitor);
if (contact) {
if (p_contact_name(contact)) {
display_from = strdup(p_contact_name(contact));
} else {
display_from = strdup(invitor);
}
} else {
display_from = strdup(invitor);
}
const char* display_from = roster_get_display_name(invitor);
cons_show("");
cons_show("Chat room invite received:");

View File

@ -299,18 +299,7 @@ ui_contact_typing(const char* const barejid, const char* const resource)
is_current = wins_is_current(window);
}
if (!is_current || (is_current && prefs_get_boolean(PREF_NOTIFY_TYPING_CURRENT))) {
PContact contact = roster_get_contact(barejid);
char const* display_usr = NULL;
if (contact) {
if (p_contact_name(contact)) {
display_usr = p_contact_name(contact);
} else {
display_usr = barejid;
}
} else {
display_usr = barejid;
}
notify_typing(display_usr);
notify_typing(roster_get_display_name(barejid));
}
}
}

View File

@ -53,8 +53,7 @@ gchar*
vcardwin_get_string(ProfVcardWin* vcardwin)
{
GString* string = g_string_new("vCard: ");
auto_char char* jid = connection_get_barejid();
g_string_append(string, jid);
g_string_append(string, connection_get_barejid());
if (vcardwin->vcard && vcardwin->vcard->modified) {
g_string_append(string, " (modified)");

View File

@ -373,9 +373,8 @@ win_get_title(ProfWin* window)
assert(vcardwin->memcheck == PROFVCARDWIN_MEMCHECK);
GString* title = g_string_new("vCard ");
auto_char char* jid = connection_get_barejid();
g_string_append(title, jid);
g_string_append(title, connection_get_barejid());
if (vcardwin->vcard->modified) {
g_string_append(title, " *");

View File

@ -68,6 +68,7 @@ typedef struct prof_conn_t
char* presence_message;
int priority;
char* domain;
Jid* jid;
GHashTable* available_resources;
GHashTable* features_by_jid;
GHashTable* requested_features;
@ -135,6 +136,7 @@ connection_init(void)
conn.conn_last_event = XMPP_CONN_DISCONNECT;
conn.presence_message = NULL;
conn.domain = NULL;
conn.jid = NULL;
conn.features_by_jid = NULL;
conn.available_resources = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)resource_destroy);
conn.requested_features = g_hash_table_new_full(g_str_hash, g_str_equal, free, NULL);
@ -562,6 +564,9 @@ connection_disconnect(void)
g_free(prof_identifier);
prof_identifier = NULL;
jid_destroy(conn.jid);
conn.jid = NULL;
}
void
@ -643,7 +648,7 @@ connection_supports(const char* const feature)
return ret;
}
char*
const char*
connection_jid_for_feature(const char* const feature)
{
if (conn.features_by_jid == NULL) {
@ -724,31 +729,46 @@ connection_get_fulljid(void)
}
}
char*
connection_get_barejid(void)
const Jid*
connection_get_jid(void)
{
const char* jid = connection_get_fulljid();
if (!jid)
return NULL;
auto_jid Jid* jidp = jid_create(jid);
char* result = strdup(jidp->barejid);
return result;
static const char* fulljid;
const char* cur_fulljid = connection_get_fulljid();
if (!conn.jid || cur_fulljid != fulljid) {
fulljid = cur_fulljid;
if (conn.jid)
jid_destroy(conn.jid);
conn.jid = jid_create(fulljid);
if (!conn.jid) {
log_error("Could not create connection-wide JID object from \"%s\"", STR_MAYBE_NULL(fulljid));
/* In case we failed to create the jid or we're not yet
* connected (or whatever else could fail) return the
* pointer to a zero-initialized static object, so
* de-referencing that pointer won't fail.
*/
static const Jid jid = { 0 };
return &jid;
}
}
return conn.jid;
}
char*
const char*
connection_get_barejid(void)
{
return connection_get_jid()->barejid;
}
gboolean
equals_our_barejid(const char* cmp)
{
return g_strcmp0(connection_get_jid()->barejid, cmp) == 0;
}
const char*
connection_get_user(void)
{
const char* jid = connection_get_fulljid();
if (!jid)
return NULL;
char* result = strdup(jid);
char* split = strchr(result, '@');
*split = '\0';
return result;
return connection_get_jid()->localpart;
}
void
@ -814,18 +834,16 @@ connection_create_stanza_id(void)
(guchar*)prof_identifier, strlen(prof_identifier),