1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Add and use connection_get_barejid()

Instead of connection_get_fulljid() and then creating a Jid from it.
This commit is contained in:
Michael Vetter 2020-05-25 13:04:19 +02:00
parent 4b5711fad5
commit de8975c008
11 changed files with 96 additions and 91 deletions

View File

@ -3431,17 +3431,17 @@ cmd_caps(ProfWin *window, const char *const command, gchar **args)
static void
_send_software_version_iq_to_fulljid(char *request)
{
Jid *myJid = jid_create(connection_get_fulljid());
char *mybarejid = connection_get_barejid();
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, myJid->barejid) == 0) {
} else if (g_strcmp0(jid->barejid, mybarejid) == 0) {
cons_show("Cannot request software version for yourself.");
} else {
iq_send_software_version(jid->fulljid);
}
jid_destroy(myJid);
free(mybarejid);
jid_destroy(jid);
}

View File

@ -84,10 +84,9 @@ cl_ev_connect_account(ProfAccount *account)
void
cl_ev_disconnect(void)
{
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
cons_show("%s logged out successfully.", jidp->barejid);
jid_destroy(jidp);
char *mybarejid = connection_get_barejid();
cons_show("%s logged out successfully.", mybarejid);
free(mybarejid);
ui_close_all_wins();
ev_disconnect_cleanup();

View File

@ -630,11 +630,11 @@ sv_ev_incoming_message(ProfMessage *message)
char *looking_for_jid = message->from_jid->barejid;
if (message->is_mam) {
Jid *my_jid = jid_create(connection_get_fulljid());
if (g_strcmp0(my_jid->barejid, message->from_jid->barejid) == 0) {
char *mybarejid = connection_get_barejid();
if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) {
looking_for_jid = message->to_jid->barejid;
}
jid_destroy(my_jid);
free(mybarejid);
}
chatwin = wins_get_chat(looking_for_jid);

119
src/log.c
View File

@ -290,10 +290,9 @@ void
chat_log_msg_out(const char *const barejid, const char *const msg, const char *const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
_chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
jid_destroy(jidp);
char *mybarejid = connection_get_barejid();
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
free(mybarejid);
}
}
@ -301,16 +300,15 @@ void
chat_log_otr_msg_out(const char *const barejid, const char *const msg, const char *const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *pref_otr_log = prefs_get_string(PREF_OTR_LOG);
if (strcmp(pref_otr_log, "on") == 0) {
_chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
} else if (strcmp(pref_otr_log, "redact") == 0) {
_chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource);
_chat_log_chat(mybarejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource);
}
prefs_free_string(pref_otr_log);
jid_destroy(jidp);
free(mybarejid);
}
}
@ -318,16 +316,15 @@ void
chat_log_pgp_msg_out(const char *const barejid, const char *const msg, const char *const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
if (strcmp(pref_pgp_log, "on") == 0) {
_chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
} else if (strcmp(pref_pgp_log, "redact") == 0) {
_chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource);
_chat_log_chat(mybarejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource);
}
prefs_free_string(pref_pgp_log);
jid_destroy(jidp);
free(mybarejid);
}
}
@ -335,16 +332,15 @@ void
chat_log_omemo_msg_out(const char *const barejid, const char *const msg, const char *const resource)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) {
_chat_log_chat(jidp->barejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
} else if (strcmp(pref_omemo_log, "redact") == 0) {
_chat_log_chat(jidp->barejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource);
_chat_log_chat(mybarejid, barejid, "[redacted]", PROF_OUT_LOG, NULL, resource);
}
prefs_free_string(pref_omemo_log);
jid_destroy(jidp);
free(mybarejid);
}
}
@ -352,24 +348,23 @@ void
chat_log_otr_msg_in(ProfMessage *message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *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) {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
} else {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
}
} else if (strcmp(pref_otr_log, "redact") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
} else {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
}
}
prefs_free_string(pref_otr_log);
jid_destroy(jidp);
free(mybarejid);
}
}
@ -377,24 +372,23 @@ void
chat_log_pgp_msg_in(ProfMessage *message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
if (strcmp(pref_pgp_log, "on") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
} else {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
}
} else if (strcmp(pref_pgp_log, "redact") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
} else {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, NULL);
}
}
prefs_free_string(pref_pgp_log);
jid_destroy(jidp);
free(mybarejid);
}
}
@ -402,24 +396,23 @@ void
chat_log_omemo_msg_in(ProfMessage *message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
} else {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
}
} else if (strcmp(pref_omemo_log, "redact") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
} else {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, "[redacted]", PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
}
}
prefs_free_string(pref_omemo_log);
jid_destroy(jidp);
free(mybarejid);
}
}
@ -427,15 +420,15 @@ void
chat_log_msg_in(ProfMessage *message)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
if (message->type == PROF_MSG_TYPE_MUCPM) {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, message->from_jid->resourcepart);
} else {
_chat_log_chat(jidp->barejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
_chat_log_chat(mybarejid, message->from_jid->barejid, message->plain, PROF_IN_LOG, message->timestamp, NULL);
}
jid_destroy(jidp);
free(mybarejid);
}
}
@ -524,11 +517,10 @@ void
groupchat_log_msg_out(const gchar *const room, const gchar *const msg)
{
if (prefs_get_boolean(PREF_GRLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *mynick = muc_nick(room);
_groupchat_log_chat(jidp->barejid, room, mynick, msg);
jid_destroy(jidp);
_groupchat_log_chat(mybarejid, room, mynick, msg);
free(mybarejid);
}
}
@ -536,10 +528,9 @@ void
groupchat_log_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg)
{
if (prefs_get_boolean(PREF_GRLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
_groupchat_log_chat(jidp->barejid, room, nick, msg);
jid_destroy(jidp);
char *mybarejid = connection_get_barejid();
_groupchat_log_chat(mybarejid, room, nick, msg);
free(mybarejid);
}
}
@ -547,17 +538,18 @@ void
groupchat_log_omemo_msg_out(const gchar *const room, const gchar *const msg)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
char *mynick = muc_nick(room);
if (strcmp(pref_omemo_log, "on") == 0) {
_groupchat_log_chat(jidp->barejid, room, mynick, msg);
_groupchat_log_chat(mybarejid, room, mynick, msg);
} else if (strcmp(pref_omemo_log, "redact") == 0) {
_groupchat_log_chat(jidp->barejid, room, mynick, "[redacted]");
_groupchat_log_chat(mybarejid, room, mynick, "[redacted]");
}
prefs_free_string(pref_omemo_log);
jid_destroy(jidp);
free(mybarejid);
}
}
@ -565,16 +557,17 @@ void
groupchat_log_omemo_msg_in(const gchar *const room, const gchar *const nick, const gchar *const msg)
{
if (prefs_get_boolean(PREF_CHLOG)) {
const char *jid = connection_get_fulljid();
Jid *jidp = jid_create(jid);
char *mybarejid = connection_get_barejid();
char *pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) {
_groupchat_log_chat(jidp->barejid, room, nick, msg);
_groupchat_log_chat(mybarejid, room, nick, msg);
} else if (strcmp(pref_omemo_log, "redact") == 0) {
_groupchat_log_chat(jidp->barejid, room, nick, "[redacted]");
_groupchat_log_chat(mybarejid, room, nick, "[redacted]");
}
prefs_free_string(pref_omemo_log);
jid_destroy(jidp);
free(mybarejid);
}
}

View File

@ -373,16 +373,16 @@ omemo_publish_crypto_materials(void)
return;
}
Jid *jid = jid_create(connection_get_fulljid());
char *barejid = connection_get_barejid();
/* Ensure we get our current device list, and it gets updated with our
* device_id */
g_hash_table_insert(omemo_ctx.device_list_handler, strdup(jid->barejid), _handle_own_device_list);
omemo_devicelist_request(jid->barejid);
g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_own_device_list);
omemo_devicelist_request(barejid);
omemo_bundle_publish(true);
jid_destroy(jid);
free(barejid);
}
void

View File

@ -259,13 +259,13 @@ chatwin_incoming_msg(ProfChatWin *chatwin, ProfMessage *message, gboolean win_cr
int num = wins_get_num(window);
char *display_name;
Jid *my_jid = jid_create(connection_get_fulljid());
if (g_strcmp0(my_jid->barejid, message->from_jid->barejid) == 0) {
char *mybarejid = connection_get_barejid();
if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) {
display_name = strdup("me");
} else {
display_name = roster_get_msg_display_name(message->from_jid->barejid, message->from_jid->resourcepart);
}
jid_destroy(my_jid);
free(mybarejid);
gboolean is_current = wins_is_current(window);
gboolean notify = prefs_do_chat_notify(is_current);

View File

@ -411,6 +411,18 @@ connection_get_fulljid(void)
}
}
char*
connection_get_barejid(void) {
const char *jid = connection_get_fulljid();
char *result;
Jid *jidp = jid_create(jid);
result = strdup(jidp->barejid);
jid_destroy(jidp);
return result;
}
void
connection_features_received(const char *const jid)
{

View File

@ -1075,9 +1075,9 @@ _handle_carbons(xmpp_stanza_t *const stanza)
return TRUE;
}
Jid *my_jid = jid_create(connection_get_fulljid());
char *mybarejid = connection_get_barejid();
const char *const stanza_from = xmpp_stanza_get_from(stanza);
if (g_strcmp0(my_jid->barejid, stanza_from) != 0) {
if (g_strcmp0(mybarejid, stanza_from) != 0) {
log_warning("Invalid carbon received, from: %s", stanza_from);
return TRUE;
}
@ -1143,7 +1143,7 @@ _handle_carbons(xmpp_stanza_t *const stanza)
//TODO: now that profmessage has from_jid AND to_jid we should save both. and maybe also add is_carbon so we can decide later on.
if (message->plain || message->encrypted || message->body) {
// if we are the recipient, treat as standard incoming message
if (g_strcmp0(my_jid->barejid, jid_to->barejid) == 0) {
if (g_strcmp0(mybarejid, jid_to->barejid) == 0) {
jid_destroy(jid_to);
message->from_jid = jid_from;
sv_ev_incoming_carbon(message);
@ -1158,7 +1158,7 @@ _handle_carbons(xmpp_stanza_t *const stanza)
out:
message_free(message);
jid_destroy(my_jid);
free(mybarejid);
return TRUE;
}

View File

@ -886,11 +886,11 @@ muc_members_add(const char *const room, const char *const jid)
if (g_hash_table_insert(chat_room->members, strdup(jid), NULL)) {
#ifdef HAVE_OMEMO
if(chat_room->anonymity_type == MUC_ANONYMITY_TYPE_NONANONYMOUS ) {
Jid *our_jid = jid_create(connection_get_fulljid());
if (strcmp(jid, our_jid->barejid) != 0) {
char *our_barejid = connection_get_barejid();
if (strcmp(jid, our_barejid) != 0) {
omemo_start_session(jid);
}
jid_destroy(our_jid);
free(our_barejid);
}
#endif
}

View File

@ -211,14 +211,14 @@ roster_set_handler(xmpp_stanza_t *const stanza)
}
// if from attribute exists and it is not current users barejid, ignore push
Jid *my_jid = jid_create(connection_get_fulljid());
char *mybarejid = connection_get_barejid();
const char *from = xmpp_stanza_get_from(stanza);
if (from && (strcmp(from, my_jid->barejid) != 0)) {
if (from && (strcmp(from, mybarejid) != 0)) {
log_warning("Received alleged roster push from: %s", from);
jid_destroy(my_jid);
free(mybarejid);
return;
}
jid_destroy(my_jid);
free(mybarejid);
const char *barejid = xmpp_stanza_get_attribute(item, STANZA_ATTR_JID);
gchar *barejid_lower = g_utf8_strdown(barejid, -1);

View File

@ -175,6 +175,7 @@ jabber_conn_status_t connection_get_status(void);
char *connection_get_presence_msg(void);
void connection_set_presence_msg(const char *const message);
const char* connection_get_fulljid(void);
char* connection_get_barejid(void);
char* connection_create_uuid(void);
void connection_free_uuid(char *uuid);
#ifdef HAVE_LIBMESODE