Skip to content

Commit

Permalink
Merge pull request #1981 from profanity-im/minor-improvements
Browse files Browse the repository at this point in the history
Minor improvements
  • Loading branch information
jubalh authored Jun 19, 2024
2 parents 8a62d8e + 3b099e9 commit b6c2aa5
Show file tree
Hide file tree
Showing 15 changed files with 24 additions and 49 deletions.
9 changes: 3 additions & 6 deletions src/command/cmd_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -943,8 +943,7 @@ _account_set_presence_priority(char* account_name, char* presence, char* priorit

jabber_conn_status_t conn_status = connection_get_status();
if (conn_status == JABBER_CONNECTED) {
char* connected_account = session_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(connected_account);
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
if (presence_type == last_presence) {
cl_ev_presence_send(last_presence, 0);
}
Expand Down Expand Up @@ -3560,8 +3559,7 @@ 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);
ProfAccount* account = accounts_get_account(session_get_account_name());
if (account && account->muc_service) {
char* uuid = connection_create_uuid();
auto_gchar gchar* room_str = g_strdup_printf("private-chat-%s@%s", uuid, account->muc_service);
Expand All @@ -3587,8 +3585,7 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
auto_gchar gchar* room = NULL;
char* nick = NULL;
char* passwd = NULL;
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());

// full room jid supplied (room@server)
if (room_arg->localpart) {
Expand Down
3 changes: 1 addition & 2 deletions src/event/client_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,7 @@ cl_ev_presence_send(const resource_presence_t presence_type, const int idle_secs
auto_char char* signed_status = NULL;

#ifdef HAVE_LIBGPGME
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());
if (account->pgp_keyid) {
signed_status = p_gpg_sign(connection_get_presence_msg(), account->pgp_keyid);
}
Expand Down
8 changes: 3 additions & 5 deletions src/event/server_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ sv_ev_roster_received(void)
ui_show_roster();
}

char* account_name = session_get_account_name();
const char* account_name = session_get_account_name();

#ifdef HAVE_LIBGPGME
// check pgp key valid if specified
Expand Down Expand Up @@ -275,8 +275,7 @@ sv_ev_room_history(ProfMessage* message)
if (prefs_get_boolean(PREF_NOTIFY_ROOM_OFFLINE)) {
// check if this message was sent while we were offline.
// if so, treat it as a new message rather than a history event.
char* account_name = session_get_account_name();
auto_gchar gchar* last_activity = accounts_get_last_activity(account_name);
auto_gchar gchar* last_activity = accounts_get_last_activity(session_get_account_name());
int msg_is_new = 0;

if (last_activity) {
Expand Down Expand Up @@ -1302,8 +1301,7 @@ sv_ev_bookmark_autojoin(Bookmark* bookmark)
if (bookmark->nick) {
nick = strdup(bookmark->nick);
} else {
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());
nick = strdup(account->muc_nick);
account_free(account);
}
Expand Down
9 changes: 3 additions & 6 deletions src/omemo/omemo.c
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ omemo_on_disconnect(void)
free_keyfile(&omemo_ctx.identity);

signal_protocol_store_context_destroy(omemo_ctx.store);
ec_public_key* pub = ratchet_identity_key_pair_get_public(omemo_ctx.identity_key_pair);
ec_private_key* priv = ratchet_identity_key_pair_get_private(omemo_ctx.identity_key_pair);
ratchet_identity_key_pair_destroy((signal_type_base*)omemo_ctx.identity_key_pair);
ec_private_key_destroy((signal_type_base*)priv);
ec_public_key_destroy((signal_type_base*)pub);

signal_context_destroy(omemo_ctx.signal);
memset(&omemo_ctx, 0, sizeof(omemo_ctx));
Expand Down Expand Up @@ -1365,8 +1361,7 @@ gboolean
omemo_automatic_start(const char* const recipient)
{
gboolean result = FALSE;
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());
prof_omemopolicy_t policy;

if (account->omemo_policy) {
Expand Down Expand Up @@ -1471,6 +1466,8 @@ _load_identity(void)
ec_private_key* private_key;
curve_decode_private_point(&private_key, identity_key_private, identity_key_private_len, omemo_ctx.signal);
ratchet_identity_key_pair_create(&omemo_ctx.identity_key_pair, public_key, private_key);
ec_private_key_destroy((signal_type_base*)private_key);
ec_public_key_destroy((signal_type_base*)public_key);

char** keys = NULL;
int i;
Expand Down
3 changes: 1 addition & 2 deletions src/otr/otr.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,7 @@ otr_get_their_fingerprint(const char* const recipient)
prof_otrpolicy_t
otr_get_policy(const char* const recipient)
{
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());
// check contact specific setting
if (g_list_find_custom(account->otr_manual, recipient, (GCompareFunc)g_strcmp0)) {
account_free(account);
Expand Down
3 changes: 1 addition & 2 deletions src/plugins/plugins.c
Original file line number Diff line number Diff line change
Expand Up @@ -313,8 +313,7 @@ plugins_unload(const char* const name)
caps_reset_ver();
// resend presence to update server's disco info data for this client
if (connection_get_status() == JABBER_CONNECTED) {
char* account_name = session_get_account_name();
resource_presence_t last_presence = accounts_get_last_presence(account_name);
resource_presence_t last_presence = accounts_get_last_presence(session_get_account_name());
cl_ev_presence_send(last_presence, 0);
}
return TRUE;
Expand Down
6 changes: 2 additions & 4 deletions src/ui/chatwin.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ gboolean
_pgp_automatic_start(const char* const recipient)
{
gboolean result = FALSE;
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());

if (g_list_find_custom(account->pgp_enabled, recipient, (GCompareFunc)g_strcmp0)) {
result = TRUE;
Expand All @@ -82,8 +81,7 @@ gboolean
_ox_automatic_start(const char* const recipient)
{
gboolean result = FALSE;
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());

if (g_list_find_custom(account->ox_enabled, recipient, (GCompareFunc)g_strcmp0)) {
result = TRUE;
Expand Down
3 changes: 1 addition & 2 deletions src/ui/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -2885,8 +2885,7 @@ cons_privacy_setting(void)
}

if (connection_get_status() == JABBER_CONNECTED) {
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());

if (account->client) {
cons_show("Client name (/account set <account> clientid) : %s", account->client);
Expand Down
3 changes: 1 addition & 2 deletions src/xmpp/bookmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,7 @@ bookmark_join(const char* jid)
return FALSE;
}

char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());
if (!muc_active(bookmark->barejid)) {
char* nick = bookmark->nick;
if (!nick) {
Expand Down
10 changes: 1 addition & 9 deletions src/xmpp/jid.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,15 +164,7 @@ char*
create_fulljid(const char* const barejid, const char* const resource)
{
auto_gchar gchar* barejidlower = g_utf8_strdown(barejid, -1);
GString* full_jid = g_string_new(barejidlower);
g_string_append(full_jid, "/");
g_string_append(full_jid, resource);

char* result = strdup(full_jid->str);

g_string_free(full_jid, TRUE);

return result;
return g_strdup_printf("%s/%s", barejidlower, resource);
}

/*
Expand Down
6 changes: 2 additions & 4 deletions src/xmpp/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -477,8 +477,7 @@ message_send_chat_pgp(const char* const barejid, const char* const msg, gboolean

xmpp_stanza_t* message = NULL;
#ifdef HAVE_LIBGPGME
char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());
if (account->pgp_keyid) {
auto_jid Jid* jidp = jid_create(jid);
auto_char char* encrypted = p_gpg_encrypt(jidp->barejid, msg, account->pgp_keyid);
Expand Down Expand Up @@ -540,8 +539,7 @@ message_send_chat_ox(const char* const barejid, const char* const msg, gboolean

xmpp_stanza_t* message = NULL;

char* account_name = session_get_account_name();
ProfAccount* account = accounts_get_account(account_name);
ProfAccount* account = accounts_get_account(session_get_account_name());

message = xmpp_message_new(ctx, STANZA_TYPE_CHAT, jid, id);
xmpp_message_set_body(message, "This message is encrypted (XEP-0373: OpenPGP for XMPP).");
Expand Down
2 changes: 1 addition & 1 deletion src/xmpp/presence.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ presence_send(const resource_presence_t presence_type, const int idle, char* sig
last = STANZA_TEXT_ONLINE;
}

char* account = session_get_account_name();
const char* account = session_get_account_name();
accounts_set_last_presence(account, last);
accounts_set_last_status(account, msg);
}
Expand Down
4 changes: 2 additions & 2 deletions src/xmpp/session.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ session_process_events(void)
}
}

char*
const char*
session_get_account_name(void)
{
return saved_account.name;
Expand Down Expand Up @@ -417,7 +417,7 @@ session_check_autoaway(void)
int away_time_ms = away_time * 60000;
int xa_time_ms = xa_time * 60000;

char* account = session_get_account_name();
const char* account = session_get_account_name();
resource_presence_t curr_presence = accounts_get_last_presence(account);
auto_char char* curr_status = accounts_get_last_status(account);

Expand Down
2 changes: 1 addition & 1 deletion src/xmpp/xmpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ jabber_conn_status_t session_connect_with_account(const ProfAccount* const accou
void session_disconnect(void);
void session_shutdown(void);
void session_process_events(void);
char* session_get_account_name(void);
const char* session_get_account_name(void);
void session_reconnect_now(void);

void connection_disconnect(void);
Expand Down
2 changes: 1 addition & 1 deletion tests/unittests/xmpp/stub_xmpp.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ connection_get_presence_msg(void)
return mock_ptr_type(const char*);
}

char*
const char*
session_get_account_name(void)
{
return mock_ptr_type(char*);
Expand Down

0 comments on commit b6c2aa5

Please sign in to comment.