Skip to content

Commit

Permalink
Cleanup jid_destroy to auto_jid
Browse files Browse the repository at this point in the history
Remove unused variables
Apply minor cleanups
  • Loading branch information
H3rnand3zzz committed Jul 7, 2023
1 parent 1d53a1f commit 04c26bf
Show file tree
Hide file tree
Showing 25 changed files with 125 additions and 268 deletions.
48 changes: 15 additions & 33 deletions src/command/cmd_funcs.c
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ cmd_account_default(ProfWin* window, const char* const command, gchar** args)
gboolean
_account_set_jid(char* account_name, char* jid)
{
Jid* jidp = jid_create(jid);
auto_jid Jid* jidp = jid_create(jid);
if (jidp == NULL) {
cons_show("Malformed jid: %s", jid);
} else {
Expand All @@ -684,7 +684,6 @@ _account_set_jid(char* account_name, char* jid)
}
cons_show("");
}
jid_destroy(jidp);

return TRUE;
}
Expand Down Expand Up @@ -1256,7 +1255,7 @@ cmd_sub(ProfWin* window, const char* const command, gchar** args)
jid = chatwin->barejid;
}

Jid* jidp = jid_create(jid);
auto_jid Jid* jidp = jid_create(jid);

if (strcmp(subcmd, "allow") == 0) {
presence_subscription(jidp->barejid, PRESENCE_SUBSCRIBED);
Expand Down Expand Up @@ -1301,8 +1300,6 @@ cmd_sub(ProfWin* window, const char* const command, gchar** args)
cons_bad_cmd_usage(command);
}

jid_destroy(jidp);

return TRUE;
}

Expand Down Expand Up @@ -2200,13 +2197,11 @@ cmd_msg(ProfWin* window, const char* const command, gchar** args)
if (occupant) {
// in case of non-anon muc send regular chatmessage
if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
Jid* jidp = jid_create(occupant->jid);
auto_jid Jid* jidp = jid_create(occupant->jid);

_cmd_msg_chatwin(jidp->barejid, msg);
win_println(window, THEME_DEFAULT, "-", "Starting direct message with occupant \"%s\" from room \"%s\" as \"%s\".", usr, mucwin->roomjid, jidp->barejid);
cons_show("Starting direct message with occupant \"%s\" from room \"%s\" as \"%s\".", usr, mucwin->roomjid, jidp->barejid);

jid_destroy(jidp);
} else {
// otherwise send mucpm
GString* full_jid = g_string_new(mucwin->roomjid);
Expand Down Expand Up @@ -3296,14 +3291,13 @@ cmd_status_get(ProfWin* window, const char* const command, gchar** args)
} else {
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
Jid* jid = jid_create(privatewin->fulljid);
auto_jid Jid* jid = jid_create(privatewin->fulljid);
Occupant* occupant = muc_roster_item(jid->barejid, jid->resourcepart);
if (occupant) {
win_show_occupant(window, occupant);
} else {
win_println(window, THEME_DEFAULT, "-", "Error getting contact info.");
}
jid_destroy(jid);
}
break;
case WIN_CONSOLE:
Expand Down Expand Up @@ -3386,14 +3380,13 @@ cmd_info(ProfWin* window, const char* const command, gchar** args)
} else {
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
Jid* jid = jid_create(privatewin->fulljid);
auto_jid Jid* jid = jid_create(privatewin->fulljid);
Occupant* occupant = muc_roster_item(jid->barejid, jid->resourcepart);
if (occupant) {
win_show_occupant_info(window, jid->barejid, occupant);
} else {
win_println(window, THEME_DEFAULT, "-", "Error getting contact info.");
}
jid_destroy(jid);
}
break;
case WIN_CONSOLE:
Expand Down Expand Up @@ -3428,9 +3421,8 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
occupant = muc_roster_item(mucwin->roomjid, args[0]);
if (occupant) {
Jid* jidp = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
auto_jid Jid* jidp = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
cons_show_caps(jidp->fulljid, occupant->presence);
jid_destroy(jidp);
} else {
cons_show("No such participant \"%s\" in room.", args[0]);
}
Expand All @@ -3441,7 +3433,7 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
case WIN_CHAT:
case WIN_CONSOLE:
if (args[0]) {
Jid* jid = jid_create(args[0]);
auto_jid Jid* jid = jid_create(args[0]);

if (jid->fulljid == NULL) {
cons_show("You must provide a full jid to the /caps command.");
Expand All @@ -3458,7 +3450,6 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
}
}
}
jid_destroy(jid);
} else {
cons_show("You must provide a jid to the /caps command.");
}
Expand All @@ -3469,11 +3460,10 @@ cmd_caps(ProfWin* window, const char* const command, gchar** args)
} else {
ProfPrivateWin* privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
Jid* jid = jid_create(privatewin->fulljid);
auto_jid Jid* jid = jid_create(privatewin->fulljid);
if (jid) {
occupant = muc_roster_item(jid->barejid, jid->resourcepart);
cons_show_caps(jid->resourcepart, occupant->presence);
jid_destroy(jid);
}
}
break;
Expand All @@ -3488,7 +3478,7 @@ static void
_send_software_version_iq_to_fulljid(char* request)
{
auto_char char* mybarejid = connection_get_barejid();
Jid* jid = jid_create(request);
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.");
Expand All @@ -3497,7 +3487,6 @@ _send_software_version_iq_to_fulljid(char* request)
} else {
iq_send_software_version(jid->fulljid);
}
jid_destroy(jid);
}

gboolean
Expand All @@ -3517,9 +3506,8 @@ cmd_software(ProfWin* window, const char* const command, gchar** args)
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
Occupant* occupant = muc_roster_item(mucwin->roomjid, args[0]);
if (occupant) {
Jid* jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
auto_jid Jid* jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
iq_send_software_version(jid->fulljid);
jid_destroy(jid);
} else {
cons_show("No such participant \"%s\" in room.", args[0]);
}
Expand Down Expand Up @@ -3625,7 +3613,7 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
return TRUE;
}

Jid* room_arg = jid_create(args[0]);
auto_jid Jid* room_arg = jid_create(args[0]);
if (room_arg == NULL) {
cons_show_error("Specified room has incorrect format.");
cons_show("");
Expand Down Expand Up @@ -3660,7 +3648,6 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
if (!parsed) {
cons_bad_cmd_usage(command);
cons_show("");
jid_destroy(room_arg);
return TRUE;
}

Expand Down Expand Up @@ -3689,7 +3676,6 @@ cmd_join(ProfWin* window, const char* const command, gchar** args)
ui_switch_to_room(room);
}

jid_destroy(room_arg);
account_free(account);

return TRUE;
Expand Down Expand Up @@ -4886,9 +4872,8 @@ cmd_disco(ProfWin* window, const char* const command, gchar** args)
if (args[1]) {
jid = g_string_append(jid, args[1]);
} else {
Jid* jidp = jid_create(connection_get_fulljid());
auto_jid Jid* jidp = jid_create(connection_get_fulljid());
jid = g_string_append(jid, jidp->domainpart);
jid_destroy(jidp);
}

if (g_strcmp0(args[0], "info") == 0) {
Expand Down Expand Up @@ -5086,13 +5071,12 @@ cmd_lastactivity(ProfWin* window, const char* const command, gchar** args)

if ((g_strcmp0(args[0], "get") == 0)) {
if (args[1] == NULL) {
Jid* jidp = jid_create(connection_get_fulljid());
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);
jid_destroy(jidp);

return TRUE;
} else {
Expand Down Expand Up @@ -9998,10 +9982,9 @@ cmd_vcard_get(ProfWin* window, const char* const command, gchar** args)
if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
// non-anon muc: get the user's jid and send vcard request to them
Occupant* occupant = muc_roster_item(mucwin->roomjid, user);
Jid* jid_occupant = jid_create(occupant->jid);
auto_jid Jid* jid_occupant = jid_create(occupant->jid);

vcard_print(ctx, window, jid_occupant->barejid);
jid_destroy(jid_occupant);
} else {
// anon muc: send the vcard request through the MUC's server
GString* full_jid = g_string_new(mucwin->roomjid);
Expand Down Expand Up @@ -10067,10 +10050,9 @@ cmd_vcard_photo(ProfWin* window, const char* const command, gchar** args)
if (muc_anonymity_type(mucwin->roomjid) == MUC_ANONYMITY_TYPE_NONANONYMOUS) {
// non-anon muc: get the user's jid and send vcard request to them
Occupant* occupant = muc_roster_item(mucwin->roomjid, user);
Jid* jid_occupant = jid_create(occupant->jid);
auto_jid Jid* jid_occupant = jid_create(occupant->jid);

jid = g_strdup(jid_occupant->barejid);
jid_destroy(jid_occupant);
} else {
// anon muc: send the vcard request through the MUC's server
jid = g_strdup_printf("%s/%s", mucwin->roomjid, user);
Expand Down
3 changes: 1 addition & 2 deletions src/config/account.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,8 @@ account_new(gchar* name, gchar* jid, gchar* password, gchar* eval_password, gboo
new_account->muc_service = muc_service;

if (muc_nick == NULL) {
Jid* jidp = jid_create(new_account->jid);
auto_jid Jid* jidp = jid_create(new_account->jid);
new_account->muc_nick = strdup(jidp->domainpart);
jid_destroy(jidp);
} else {
new_account->muc_nick = muc_nick;
}
Expand Down
13 changes: 3 additions & 10 deletions src/config/accounts.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
// set account name and resource
const char* barejid = account_name;
auto_gchar gchar* resource = jid_random_resource();
Jid* jid = jid_create(account_name);
auto_jid Jid* jid = jid_create(account_name);
if (jid) {
barejid = jid->barejid;
if (jid->resourcepart) {
Expand All @@ -137,7 +137,6 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
}

if (g_key_file_has_group(accounts, account_name)) {
jid_destroy(jid);
return;
}

Expand All @@ -157,16 +156,14 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
g_key_file_set_string(accounts, account_name, "auth.policy", auth_policy);
}

Jid* jidp = jid_create(barejid);
auto_jid Jid* jidp = jid_create(barejid);

if (jidp->localpart == NULL) {
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->domainpart);
} else {
g_key_file_set_string(accounts, account_name, "muc.nick", jidp->localpart);
}

jid_destroy(jidp);

g_key_file_set_string(accounts, account_name, "presence.last", "online");
g_key_file_set_string(accounts, account_name, "presence.login", "online");
g_key_file_set_integer(accounts, account_name, "priority.online", 0);
Expand All @@ -178,8 +175,6 @@ accounts_add(const char* account_name, const char* altdomain, const int port, co
_save_accounts();
autocomplete_add(all_ac, account_name);
autocomplete_add(enabled_ac, account_name);

jid_destroy(jid);
}

int
Expand Down Expand Up @@ -459,7 +454,7 @@ accounts_account_exists(const char* const account_name)
void
accounts_set_jid(const char* const account_name, const char* const value)
{
Jid* jid = jid_create(value);
auto_jid Jid* jid = jid_create(value);
if (jid) {
if (accounts_account_exists(account_name)) {
g_key_file_set_string(accounts, account_name, "jid", jid->barejid);
Expand All @@ -475,8 +470,6 @@ accounts_set_jid(const char* const account_name, const char* const value)

_save_accounts();
}

jid_destroy(jid);
}
}

Expand Down
15 changes: 4 additions & 11 deletions src/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,9 @@ log_database_add_incoming(ProfMessage* message)
if (message->to_jid) {
_add_to_db(message, NULL, message->from_jid, message->to_jid);
} else {
Jid* myjid = jid_create(connection_get_fulljid());
auto_jid Jid* myjid = jid_create(connection_get_fulljid());

_add_to_db(message, NULL, message->from_jid, myjid);

jid_destroy(myjid);
}
}

Expand All @@ -173,11 +171,10 @@ _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;

Jid* myjid = jid_create(connection_get_fulljid());
auto_jid Jid* myjid = jid_create(connection_get_fulljid());

_add_to_db(msg, type, myjid, msg->from_jid); // TODO: myjid now in profmessage

jid_destroy(myjid);
message_free(msg);
}

Expand Down Expand Up @@ -206,7 +203,7 @@ log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_las
sqlite3_stmt* stmt = NULL;
gchar* query;
const char* jid = connection_get_fulljid();
Jid* myjid = jid_create(jid);
auto_jid Jid* myjid = jid_create(jid);
if (!myjid)
return NULL;

Expand All @@ -221,8 +218,6 @@ log_database_get_limits_info(const gchar* const contact_barejid, gboolean is_las
return NULL;
}

jid_destroy(myjid);

int rc = sqlite3_prepare_v2(g_chatlog_database, query, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
log_error("log_database_get_last_info(): unknown SQLite error");
Expand Down Expand Up @@ -252,7 +247,7 @@ log_database_get_previous_chat(const gchar* const contact_barejid, const char* s
{
sqlite3_stmt* stmt = NULL;
const char* jid = connection_get_fulljid();
Jid* myjid = jid_create(jid);
auto_jid Jid* myjid = jid_create(jid);
if (!myjid)
return NULL;

Expand All @@ -270,8 +265,6 @@ log_database_get_previous_chat(const gchar* const contact_barejid, const char* s
return NULL;
}

jid_destroy(myjid);

int rc = sqlite3_prepare_v2(g_chatlog_database, query, -1, &stmt, NULL);
if (rc != SQLITE_OK) {
log_error("log_database_get_previous_chat(): unknown SQLite error");
Expand Down
Loading

0 comments on commit 04c26bf

Please sign in to comment.