1
0
Fork 0

Introduce `equals_our_barejid()`

Instead of always repeating the same pattern, introduce a helper function.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2023-12-05 12:59:51 +01:00
parent fdfe3e2ad9
commit bac24601da
9 changed files with 22 additions and 9 deletions

View File

@ -3452,7 +3452,7 @@ _send_software_version_iq_to_fulljid(char* 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, connection_get_barejid()) == 0) {
} else if (equals_our_barejid(jid->barejid)) {
cons_show("Cannot request software version for yourself.");
} else {
iq_send_software_version(jid->fulljid);

View File

@ -629,7 +629,7 @@ sv_ev_incoming_message(ProfMessage* message)
char* looking_for_jid = message->from_jid->barejid;
if (message->is_mam) {
if (g_strcmp0(connection_get_barejid(), 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

@ -378,7 +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
if (g_strcmp0(connection_get_barejid(), 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);
@ -756,7 +756,7 @@ 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
if (!g_strcmp0(connection_get_barejid(), recipients_iter->data)) {
if (equals_our_barejid(recipients_iter->data)) {
if (GPOINTER_TO_INT(device_ids_iter->data) == omemo_ctx.device_id) {
log_debug("[OMEMO][SEND] Skipping %d (my device) ", GPOINTER_TO_INT(device_ids_iter->data));
continue;

View File

@ -759,6 +759,12 @@ 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;
}
char*
connection_get_user(void)
{

View File

@ -101,7 +101,7 @@ static GHashTable* pubsub_event_handlers;
gchar*
get_display_name(const ProfMessage* const message, int* flags)
{
if (g_strcmp0(connection_get_barejid(), message->from_jid->barejid) == 0) {
if (equals_our_barejid(message->from_jid->barejid)) {
return g_strdup("me");
} else {
if (flags)
@ -262,7 +262,7 @@ _message_handler(xmpp_conn_t* const conn, xmpp_stanza_t* const stanza, void* con
const char* const stanza_from = xmpp_stanza_get_from(stanza);
if (stanza_from) {
if (g_strcmp0(connection_get_barejid(), stanza_from) != 0) {
if (!equals_our_barejid(stanza_from)) {
log_warning("Invalid carbon received, from: %s", stanza_from);
msg_stanza = NULL;
} else {
@ -1462,7 +1462,7 @@ _handle_chat(xmpp_stanza_t* const stanza, gboolean is_mam, gboolean is_carbon, c
if (message->plain || message->body || message->encrypted) {
if (is_carbon) {
// if we are the recipient, treat as standard incoming message
if (g_strcmp0(connection_get_barejid(), message->to_jid->barejid) == 0) {
if (equals_our_barejid(message->to_jid->barejid)) {
sv_ev_incoming_carbon(message);
// else treat as a sent message
} else {

View File

@ -882,7 +882,7 @@ 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) {
if (strcmp(jid, connection_get_barejid()) != 0) {
if (!equals_our_barejid(jid)) {
omemo_start_session(jid);
}
}

View File

@ -201,7 +201,7 @@ roster_set_handler(xmpp_stanza_t* const stanza)
// if from attribute exists and it is not current users barejid, ignore push
const char* from = xmpp_stanza_get_from(stanza);
if (from && (strcmp(from, connection_get_barejid()) != 0)) {
if (!equals_our_barejid(from)) {
log_warning("Received alleged roster push from: %s", from);
return;
}

View File

@ -195,6 +195,7 @@ void connection_set_presence_msg(const char* const message);
const char* connection_get_fulljid(void);
const Jid* connection_get_jid(void);
const char* connection_get_barejid(void);
gboolean equals_our_barejid(const char* cmp);
char* connection_get_user(void);
char* connection_create_uuid(void);
void connection_free_uuid(char* uuid);

View File

@ -75,6 +75,12 @@ connection_get_barejid(void)
return mock_ptr_type(char*);
}
gboolean
equals_our_barejid(const char* cmp)
{
return TRUE;
}
char*
connection_get_user(void)
{