1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-10-27 20:30:13 -04:00

add connection_get_jid()

Use a singleton `Jid` inside the connection instead of always re-creating
a `Jid` from the same string.

Signed-off-by: Steffen Jaeckel <jaeckel-floss@eyet-services.de>
This commit is contained in:
Steffen Jaeckel 2023-11-14 14:53:49 +01:00
parent b18b6cbd29
commit 847a86de50
17 changed files with 88 additions and 101 deletions

View File

@ -85,8 +85,7 @@ void
chat_log_msg_out(const char* const barejid, const char* const msg, const char* const resource) chat_log_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { if (prefs_get_boolean(PREF_CHLOG)) {
auto_char char* mybarejid = connection_get_barejid(); _chat_log_chat(connection_get_barejid(), barejid, msg, PROF_OUT_LOG, NULL, resource);
_chat_log_chat(mybarejid, 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) chat_log_otr_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); auto_gchar gchar* pref_otr_log = prefs_get_string(PREF_OTR_LOG);
if (strcmp(pref_otr_log, "on") == 0) { if (strcmp(pref_otr_log, "on") == 0) {
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource); _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) chat_log_pgp_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); auto_gchar gchar* pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
if (strcmp(pref_pgp_log, "on") == 0) { if (strcmp(pref_pgp_log, "on") == 0) {
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource); _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) chat_log_omemo_msg_out(const char* const barejid, const char* const msg, const char* const resource)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) { if (strcmp(pref_omemo_log, "on") == 0) {
_chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource); _chat_log_chat(mybarejid, barejid, msg, PROF_OUT_LOG, NULL, resource);
@ -136,7 +135,7 @@ void
chat_log_otr_msg_in(ProfMessage* message) chat_log_otr_msg_in(ProfMessage* message)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); 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->enc == PROF_MSG_ENC_NONE || (strcmp(pref_otr_log, "on") == 0)) {
if (message->type == PROF_MSG_TYPE_MUCPM) { if (message->type == PROF_MSG_TYPE_MUCPM) {
@ -158,7 +157,7 @@ void
chat_log_pgp_msg_in(ProfMessage* message) chat_log_pgp_msg_in(ProfMessage* message)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); auto_gchar gchar* pref_pgp_log = prefs_get_string(PREF_PGP_LOG);
if (strcmp(pref_pgp_log, "on") == 0) { if (strcmp(pref_pgp_log, "on") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) { if (message->type == PROF_MSG_TYPE_MUCPM) {
@ -180,7 +179,7 @@ void
chat_log_omemo_msg_in(ProfMessage* message) chat_log_omemo_msg_in(ProfMessage* message)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) { if (strcmp(pref_omemo_log, "on") == 0) {
if (message->type == PROF_MSG_TYPE_MUCPM) { if (message->type == PROF_MSG_TYPE_MUCPM) {
@ -202,7 +201,7 @@ void
chat_log_msg_in(ProfMessage* message) chat_log_msg_in(ProfMessage* message)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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) { 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); _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) groupchat_log_msg_out(const gchar* const room, const gchar* const msg)
{ {
if (prefs_get_boolean(PREF_GRLOG)) { if (prefs_get_boolean(PREF_GRLOG)) {
auto_char char* mybarejid = connection_get_barejid();
char* mynick = muc_nick(room); 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) groupchat_log_msg_in(const gchar* const room, const gchar* const nick, const gchar* const msg)
{ {
if (prefs_get_boolean(PREF_GRLOG)) { if (prefs_get_boolean(PREF_GRLOG)) {
auto_char char* mybarejid = connection_get_barejid(); _groupchat_log_chat(connection_get_barejid(), room, nick, msg);
_groupchat_log_chat(mybarejid, room, nick, msg);
} }
} }
@ -327,7 +324,7 @@ void
groupchat_log_omemo_msg_out(const gchar* const room, const gchar* const msg) groupchat_log_omemo_msg_out(const gchar* const room, const gchar* const msg)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
char* mynick = muc_nick(room); 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) groupchat_log_omemo_msg_in(const gchar* const room, const gchar* const nick, const gchar* const msg)
{ {
if (prefs_get_boolean(PREF_CHLOG)) { 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); auto_gchar gchar* pref_omemo_log = prefs_get_string(PREF_OMEMO_LOG);
if (strcmp(pref_omemo_log, "on") == 0) { if (strcmp(pref_omemo_log, "on") == 0) {

View File

@ -3448,12 +3448,11 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
static void static void
_send_software_version_iq_to_fulljid(char* request) _send_software_version_iq_to_fulljid(char* request)
{ {
auto_char char* mybarejid = connection_get_barejid();
auto_jid Jid* jid = jid_create(request); auto_jid Jid* jid = jid_create(request);
if (jid == NULL || jid->fulljid == NULL) { if (jid == NULL || jid->fulljid == NULL) {
cons_show("You must provide a full jid to the /software command."); cons_show("You must provide a full jid to the /software command.");
} else if (g_strcmp0(jid->barejid, mybarejid) == 0) { } else if (g_strcmp0(jid->barejid, connection_get_barejid()) == 0) {
cons_show("Cannot request software version for yourself."); cons_show("Cannot request software version for yourself.");
} else { } else {
iq_send_software_version(jid->fulljid); iq_send_software_version(jid->fulljid);
@ -4842,8 +4841,7 @@ cmd_disco(ProfWin* window, const char* const command, gchar** args)
if (args[1]) { if (args[1]) {
jid = g_string_append(jid, args[1]); jid = g_string_append(jid, args[1]);
} else { } else {
auto_jid Jid* jidp = jid_create(connection_get_fulljid()); jid = g_string_append(jid, connection_get_jid()->domainpart);
jid = g_string_append(jid, jidp->domainpart);
} }
if (g_strcmp0(args[0], "info") == 0) { if (g_strcmp0(args[0], "info") == 0) {
@ -5039,8 +5037,7 @@ cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)
if ((g_strcmp0(args[0], "get") == 0)) { if ((g_strcmp0(args[0], "get") == 0)) {
if (args[1] == NULL) { if (args[1] == NULL) {
auto_jid Jid* jidp = jid_create(connection_get_fulljid()); GString* jid = g_string_new(connection_get_jid()->domainpart);
GString* jid = g_string_new(jidp->domainpart);
iq_last_activity_request(jid->str); iq_last_activity_request(jid->str);

View File

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

View File

@ -86,8 +86,7 @@ cl_ev_connect_account(ProfAccount* account)
void void
cl_ev_disconnect(void) cl_ev_disconnect(void)
{ {
auto_char char* mybarejid = connection_get_barejid(); cons_show("%s logged out successfully.", connection_get_barejid());
cons_show("%s logged out successfully.", mybarejid);
ui_close_all_wins(); ui_close_all_wins();
ev_disconnect_cleanup(); ev_disconnect_cleanup();

View File

@ -630,8 +630,7 @@ sv_ev_incoming_message(ProfMessage* message)
char* looking_for_jid = message->from_jid->barejid; char* looking_for_jid = message->from_jid->barejid;
if (message->is_mam) { if (message->is_mam) {
auto_char char* mybarejid = connection_get_barejid(); if (g_strcmp0(connection_get_barejid(), message->from_jid->barejid) == 0) {
if (g_strcmp0(mybarejid, message->from_jid->barejid) == 0) {
if (message->to_jid) { if (message->to_jid) {
looking_for_jid = message->to_jid->barejid; looking_for_jid = message->to_jid->barejid;
} }

View File

@ -339,7 +339,7 @@ omemo_publish_crypto_materials(void)
static void static void
_acquire_sender_devices_list(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); g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_own_device_list);
omemo_devicelist_request(barejid); omemo_devicelist_request(barejid);
@ -375,8 +375,7 @@ omemo_start_session(const char* const barejid)
log_debug("[OMEMO] missing device list for %s", barejid); log_debug("[OMEMO] missing device list for %s", barejid);
// Own devices are handled by _handle_own_device_list // Own devices are handled by _handle_own_device_list
// We won't add _handle_device_list_start_session for ourself // We won't add _handle_device_list_start_session for ourself
auto_char char* mybarejid = connection_get_barejid(); if (g_strcmp0(connection_get_barejid(), barejid) != 0) {
if (g_strcmp0(mybarejid, barejid) != 0) {
g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_device_list_start_session); g_hash_table_insert(omemo_ctx.device_list_handler, strdup(barejid), _handle_device_list_start_session);
} }
omemo_devicelist_request(barejid); omemo_devicelist_request(barejid);
@ -680,7 +679,7 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
{ {
char* id = NULL; char* id = NULL;
int res; int res;
auto_jid Jid* jid = jid_create(connection_get_fulljid()); const Jid* jid = connection_get_jid();
GList* keys = NULL; GList* keys = NULL;
unsigned char* key; unsigned char* key;
@ -754,15 +753,12 @@ omemo_on_message_send(ProfWin* win, const char* const message, gboolean request_
// Don't encrypt for this device (according to // Don't encrypt for this device (according to
// <https://xmpp.org/extensions/xep-0384.html#encrypt>). // <https://xmpp.org/extensions/xep-0384.html#encrypt>).
// Yourself as recipients in case of MUC // Yourself as recipients in case of MUC
char* mybarejid = connection_get_barejid(); if (!g_strcmp0(connection_get_barejid(), recipients_iter->data)) {
if (!g_strcmp0(mybarejid, recipients_iter->data)) {
if (GPOINTER_TO_INT(device_ids_iter->data) == omemo_ctx.device_id) { 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)); log_debug("[OMEMO][SEND] Skipping %d (my device) ", GPOINTER_TO_INT(device_ids_iter->data));
continue; continue;
} }
} }
free(mybarejid);
log_debug("[OMEMO][SEND] recipients with device id %d for %s", GPOINTER_TO_INT(device_ids_iter->data), recipients_iter->data); 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); res = session_cipher_create(&cipher, omemo_ctx.store, &address, omemo_ctx.signal);
@ -1806,14 +1802,10 @@ out:
char* char*
omemo_qrcode_str() omemo_qrcode_str()
{ {
char* mybarejid = connection_get_barejid(); auto_char char* fingerprint = omemo_own_fingerprint(FALSE);
char* fingerprint = omemo_own_fingerprint(FALSE);
uint32_t sid = omemo_device_id(); uint32_t sid = omemo_device_id();
char* qrstr = g_strdup_printf("xmpp:%s?omemo-sid-%d=%s", mybarejid, sid, fingerprint); char* qrstr = g_strdup_printf("xmpp:%s?omemo-sid-%d=%s", connection_get_barejid(), sid, fingerprint);
free(mybarejid);
free(fingerprint);
return qrstr; return qrstr;
} }

View File

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

View File

@ -427,7 +427,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_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)); auto_char char* display_message = plugins_pre_chat_message_display(myjid->barejid, myjid->resourcepart, strdup(message));
if (request_receipt && id) { if (request_receipt && id) {

View File

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

View File

@ -373,9 +373,8 @@ win_get_title(ProfWin* window)
assert(vcardwin->memcheck == PROFVCARDWIN_MEMCHECK); assert(vcardwin->memcheck == PROFVCARDWIN_MEMCHECK);
GString* title = g_string_new("vCard "); 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) { if (vcardwin->vcard->modified) {
g_string_append(title, " *"); g_string_append(title, " *");

View File

@ -68,6 +68,7 @@ typedef struct prof_conn_t
char* presence_message; char* presence_message;
int priority; int priority;
char* domain; char* domain;
Jid* jid;
GHashTable* available_resources; GHashTable* available_resources;
GHashTable* features_by_jid; GHashTable* features_by_jid;
GHashTable* requested_features; GHashTable* requested_features;
@ -135,6 +136,7 @@ connection_init(void)
conn.conn_last_event = XMPP_CONN_DISCONNECT; conn.conn_last_event = XMPP_CONN_DISCONNECT;
conn.presence_message = NULL; conn.presence_message = NULL;
conn.domain = NULL; conn.domain = NULL;
conn.jid = NULL;
conn.features_by_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.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); 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); g_free(prof_identifier);
prof_identifier = NULL; prof_identifier = NULL;
jid_destroy(conn.jid);
conn.jid = NULL;
} }
void void
@ -724,17 +729,34 @@ connection_get_fulljid(void)
} }
} }
char* const Jid*
connection_get_jid(void)
{
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;
}
const char*
connection_get_barejid(void) connection_get_barejid(void)
{ {
const char* jid = connection_get_fulljid(); return connection_get_jid()->barejid;
if (!jid)
return NULL;
auto_jid Jid* jidp = jid_create(jid);
char* result = strdup(jidp->barejid);
return result;
} }
char* char*
@ -953,9 +975,8 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
log_debug("Connection handler: XMPP_CONN_CONNECT"); log_debug("Connection handler: XMPP_CONN_CONNECT");
conn.conn_status = JABBER_CONNECTED; conn.conn_status = JABBER_CONNECTED;
Jid* my_jid = jid_create(xmpp_conn_get_jid(conn.xmpp_conn)); connection_get_jid();
conn.domain = strdup(my_jid->domainpart); conn.domain = strdup(conn.jid->domainpart);
jid_destroy(my_jid);
connection_clear_data(); connection_clear_data();
conn.features_by_jid = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy); conn.features_by_jid = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);
@ -979,10 +1000,10 @@ _connection_handler(xmpp_conn_t* const xmpp_conn, const xmpp_conn_event_t status
log_debug("Connection handler: XMPP_CONN_RAW_CONNECT"); log_debug("Connection handler: XMPP_CONN_RAW_CONNECT");
conn.conn_status = JABBER_RAW_CONNECTED; conn.conn_status = JABBER_RAW_CONNECTED;
Jid* my_raw_jid = jid_create(xmpp_conn_get_jid(conn.xmpp_conn)); connection_get_jid();
log_debug("jid: %s", xmpp_conn_get_jid(conn.xmpp_conn)); conn.jid = jid_create(xmpp_conn_get_jid(conn.xmpp_conn));
conn.domain = strdup(my_raw_jid->domainpart); log_debug("jid: %s", conn.jid->str);
jid_destroy(my_raw_jid); conn.domain = strdup(conn.jid->domainpart);
connection_clear_data(); connection_clear_data();
conn.features_by_jid = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy); conn.features_by_jid = g_hash_table_new_full(g_str_hash, g_str_equal, free, (GDestroyNotify)g_hash_table_destroy);

View File

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

View File

@ -882,8 +882,7 @@ muc_members_add(const char* const room, const char* const jid)
if (g_hash_table_insert(chat_room->members, strdup(jid), NULL)) { if (g_hash_table_insert(chat_room->members, strdup(jid), NULL)) {
#ifdef HAVE_OMEMO #ifdef HAVE_OMEMO
if (chat_room->anonymity_type == MUC_ANONYMITY_TYPE_NONANONYMOUS) { if (chat_room->anonymity_type == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
auto_char char* our_barejid = connection_get_barejid(); if (strcmp(jid, connection_get_barejid()) != 0) {
if (strcmp(jid, our_barejid) != 0) {
omemo_start_session(jid); omemo_start_session(jid);
} }
} }

View File

@ -87,9 +87,8 @@ omemo_devicelist_configure(void)
{ {
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
auto_char char* id = connection_create_stanza_id(); auto_char char* id = connection_create_stanza_id();
auto_jid Jid* jid = jid_create(connection_get_fulljid());
xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST); xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, connection_get_jid()->barejid, STANZA_NS_OMEMO_DEVICELIST);
iq_id_handler_add(id, _omemo_devicelist_configure_submit, NULL, NULL); iq_id_handler_add(id, _omemo_devicelist_configure_submit, NULL, NULL);
@ -196,9 +195,7 @@ omemo_start_device_session_handle_bundle(xmpp_stanza_t* const stanza, void* cons
} }
if (!from_attr) { if (!from_attr) {
Jid* jid = jid_create(connection_get_fulljid()); from = strdup(connection_get_jid()->barejid);
from = strdup(jid->barejid);
jid_destroy(jid);
} else { } else {
from = strdup(from_attr); from = strdup(from_attr);
} }
@ -608,9 +605,8 @@ _omemo_devicelist_configure_submit(xmpp_stanza_t* const stanza, void* const user
form_set_value(form, "pubsub#access_model", "open"); form_set_value(form, "pubsub#access_model", "open");
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
auto_jid Jid* jid = jid_create(connection_get_fulljid());
auto_char char* id = connection_create_stanza_id(); auto_char char* id = connection_create_stanza_id();
xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, jid->barejid, STANZA_NS_OMEMO_DEVICELIST, form); xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, connection_get_jid()->barejid, STANZA_NS_OMEMO_DEVICELIST, form);
iq_id_handler_add(id, _omemo_devicelist_configure_result, NULL, NULL); iq_id_handler_add(id, _omemo_devicelist_configure_result, NULL, NULL);
@ -633,10 +629,7 @@ _omemo_devicelist_configure_result(xmpp_stanza_t* const stanza, void* const user
log_debug("[OMEMO] node configured"); log_debug("[OMEMO] node configured");
// Try to publish // Try to publish
char* barejid = connection_get_barejid(); omemo_devicelist_request(connection_get_barejid());
omemo_devicelist_request(barejid);
free(barejid);
return 0; return 0;
} }
@ -660,12 +653,11 @@ _omemo_bundle_publish_result(xmpp_stanza_t* const stanza, void* const userdata)
log_debug("[OMEMO] cannot publish bundle with open access model, trying to configure node"); log_debug("[OMEMO] cannot publish bundle with open access model, trying to configure node");
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
auto_jid Jid* jid = jid_create(connection_get_fulljid());
auto_char char* id = connection_create_stanza_id(); auto_char char* id = connection_create_stanza_id();
auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id()); auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id());
log_debug("[OMEMO] node: %s", node); log_debug("[OMEMO] node: %s", node);
xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, jid->barejid, node); xmpp_stanza_t* iq = stanza_create_pubsub_configure_request(ctx, id, connection_get_jid()->barejid, node);
iq_id_handler_add(id, _omemo_bundle_publish_configure, NULL, userdata); iq_id_handler_add(id, _omemo_bundle_publish_configure, NULL, userdata);
@ -700,10 +692,9 @@ _omemo_bundle_publish_configure(xmpp_stanza_t* const stanza, void* const userdat
form_set_value(form, "pubsub#access_model", "open"); form_set_value(form, "pubsub#access_model", "open");
xmpp_ctx_t* const ctx = connection_get_ctx(); xmpp_ctx_t* const ctx = connection_get_ctx();
auto_jid Jid* jid = jid_create(connection_get_fulljid());
auto_char char* id = connection_create_stanza_id(); auto_char char* id = connection_create_stanza_id();
auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id()); auto_gchar gchar* node = g_strdup_printf("%s:%d", STANZA_NS_OMEMO_BUNDLES, omemo_device_id());
xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, jid->barejid, node, form); xmpp_stanza_t* iq = stanza_create_pubsub_configure_submit(ctx, id, connection_get_jid()->barejid, node, form);
iq_id_handler_add(id, _omemo_bundle_publish_configure_result, NULL, userdata); iq_id_handler_add(id, _omemo_bundle_publish_configure_result, NULL, userdata);

View File

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

View File

@ -193,7 +193,8 @@ jabber_conn_status_t connection_get_status(void);
char* connection_get_presence_msg(void); char* connection_get_presence_msg(void);
void connection_set_presence_msg(const char* const message); void connection_set_presence_msg(const char* const message);
const char* connection_get_fulljid(void); const char* connection_get_fulljid(void);
char* connection_get_barejid(void); const Jid* connection_get_jid(void);
const char* connection_get_barejid(void);
char* connection_get_user(void); char* connection_get_user(void);
char* connection_create_uuid(void); char* connection_create_uuid(void);
void connection_free_uuid(char* uuid); void connection_free_uuid(char* uuid);

View File

@ -58,6 +58,11 @@ void
connection_disconnect(void) connection_disconnect(void)
{ {
} }
const Jid*
connection_get_jid(void)
{
return mock_ptr_type(Jid*);
}
const char* const char*
connection_get_fulljid(void) connection_get_fulljid(void)
{ {