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

Removed wins_get_current_* functions

This commit is contained in:
James Booth 2015-06-17 19:49:55 +01:00
parent a798dc5618
commit e00a03f916
7 changed files with 139 additions and 185 deletions

View File

@ -1810,7 +1810,8 @@ cmd_reset_autocomplete(ProfWin *window)
autocomplete_reset(receipts_ac);
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
PContact contact = roster_get_contact(chatwin->barejid);
if (contact) {
p_contact_resource_ac_reset(contact);
@ -1818,13 +1819,15 @@ cmd_reset_autocomplete(ProfWin *window)
}
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
muc_autocomplete_reset(mucwin->roomjid);
muc_jid_autocomplete_reset(mucwin->roomjid);
}
if (window->type == WIN_MUC_CONFIG) {
ProfMucConfWin *confwin = wins_get_current_muc_conf();
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
if (confwin->form) {
form_reset_autocompleters(confwin->form);
}
@ -1938,7 +1941,8 @@ _cmd_complete_parameters(ProfWin *window, const char * const input)
// autocomplete nickname in chat rooms
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
if (nick_ac) {
gchar *nick_choices[] = { "/msg", "/info", "/caps", "/status", "/software" } ;
@ -2477,7 +2481,8 @@ _resource_autocomplete(ProfWin *window, const char * const input)
char *found = NULL;
if (window->type == WIN_CHAT) {
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
PContact contact = roster_get_contact(chatwin->barejid);
if (contact) {
Autocomplete ac = p_contact_resource_ac(contact);
@ -2705,7 +2710,8 @@ _kick_autocomplete(ProfWin *window, const char * const input)
char *result = NULL;
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);
if (nick_ac) {
@ -2725,7 +2731,8 @@ _ban_autocomplete(ProfWin *window, const char * const input)
char *result = NULL;
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid);
if (jid_ac) {
@ -2745,7 +2752,8 @@ _affiliation_autocomplete(ProfWin *window, const char * const input)
char *result = NULL;
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
gboolean parse_result;
Autocomplete jid_ac = muc_roster_jid_ac(mucwin->roomjid);
@ -2792,7 +2800,8 @@ _role_autocomplete(ProfWin *window, const char * const input)
char *result = NULL;
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
gboolean parse_result;
Autocomplete nick_ac = muc_roster_ac(mucwin->roomjid);

View File

@ -108,19 +108,22 @@ cmd_execute_default(ProfWin *window, const char * inp)
switch (window->type) {
case WIN_CHAT:
{
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
cl_ev_send_msg(chatwin, inp);
break;
}
case WIN_PRIVATE:
{
ProfPrivateWin *privatewin = wins_get_current_private();
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
cl_ev_send_priv_msg(privatewin, inp);
break;
}
case WIN_MUC:
{
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
cl_ev_send_muc_msg(mucwin, inp);
break;
}
@ -600,7 +603,8 @@ cmd_sub(ProfWin *window, gchar **args, struct cmd_help_t help)
}
if (jid == NULL) {
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
jid = chatwin->barejid;
}
@ -968,7 +972,8 @@ _who_room(ProfWin *window, gchar **args, struct cmd_help_t help)
return;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
// presence filter
if (args[0] == NULL ||
@ -1316,7 +1321,8 @@ cmd_msg(ProfWin *window, gchar **args, struct cmd_help_t help)
// send private message when in MUC room
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
if (muc_roster_contains_nick(mucwin->roomjid, usr)) {
GString *full_jid = g_string_new(mucwin->roomjid);
g_string_append(full_jid, "/");
@ -1789,7 +1795,8 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help)
{
case WIN_MUC:
if (usr) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
Occupant *occupant = muc_roster_item(mucwin->roomjid, usr);
if (occupant) {
win_show_occupant(window, occupant);
@ -1804,7 +1811,8 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help)
if (usr) {
ui_current_print_line("No parameter required when in chat.");
} else {
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
PContact pcontact = roster_get_contact(chatwin->barejid);
if (pcontact) {
win_show_contact(window, pcontact);
@ -1817,7 +1825,8 @@ cmd_status(ProfWin *window, gchar **args, struct cmd_help_t help)
if (usr) {
ui_current_print_line("No parameter required when in chat.");
} else {
ProfPrivateWin *privatewin = wins_get_current_private();
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
Jid *jid = jid_create(privatewin->fulljid);
Occupant *occupant = muc_roster_item(jid->barejid, jid->resourcepart);
if (occupant) {
@ -1863,7 +1872,8 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help)
{
case WIN_MUC:
if (usr) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
Occupant *occupant = muc_roster_item(mucwin->roomjid, usr);
if (occupant) {
win_show_occupant_info(window, mucwin->roomjid, occupant);
@ -1871,7 +1881,8 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help)
ui_current_print_line("No such occupant \"%s\" in room.", usr);
}
} else {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
iq_room_info_request(mucwin->roomjid, TRUE);
ui_show_room_info(mucwin);
return TRUE;
@ -1881,7 +1892,8 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help)
if (usr) {
ui_current_print_line("No parameter required when in chat.");
} else {
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
PContact pcontact = roster_get_contact(chatwin->barejid);
if (pcontact) {
win_show_info(window, pcontact);
@ -1894,7 +1906,8 @@ cmd_info(ProfWin *window, gchar **args, struct cmd_help_t help)
if (usr) {
ui_current_print_line("No parameter required when in chat.");
} else {
ProfPrivateWin *privatewin = wins_get_current_private();
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
Jid *jid = jid_create(privatewin->fulljid);
Occupant *occupant = muc_roster_item(jid->barejid, jid->resourcepart);
if (occupant) {
@ -1944,7 +1957,8 @@ cmd_caps(ProfWin *window, gchar **args, struct cmd_help_t help)
{
case WIN_MUC:
if (args[0]) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
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]);
@ -1986,7 +2000,8 @@ cmd_caps(ProfWin *window, gchar **args, struct cmd_help_t help)
if (args[0]) {
cons_show("No parameter needed to /caps when in private chat.");
} else {
ProfPrivateWin *privatewin = wins_get_current_private();
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
Jid *jid = jid_create(privatewin->fulljid);
if (jid) {
occupant = muc_roster_item(jid->barejid, jid->resourcepart);
@ -2018,7 +2033,8 @@ cmd_software(ProfWin *window, gchar **args, struct cmd_help_t help)
{
case WIN_MUC:
if (args[0]) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
occupant = muc_roster_item(mucwin->roomjid, args[0]);
if (occupant) {
Jid *jid = jid_create_from_bare_and_resource(mucwin->roomjid, args[0]);
@ -2050,7 +2066,8 @@ cmd_software(ProfWin *window, gchar **args, struct cmd_help_t help)
if (args[0]) {
cons_show("No parameter needed to /software when in private chat.");
} else {
ProfPrivateWin *privatewin = wins_get_current_private();
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
iq_send_software_version(privatewin->fulljid);
}
break;
@ -2180,7 +2197,8 @@ cmd_invite(ProfWin *window, gchar **args, struct cmd_help_t help)
usr_jid = contact;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
message_send_invite(mucwin->roomjid, usr_jid, reason);
if (reason) {
cons_show("Room invite sent, contact: %s, room: %s, reason: \"%s\".",
@ -2456,7 +2474,8 @@ cmd_form(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucConfWin *confwin = wins_get_current_muc_conf();
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
if (g_strcmp0(args[0], "show") == 0) {
ui_show_form(confwin);
@ -2521,7 +2540,8 @@ cmd_kick(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
char *nick = args[0];
if (nick) {
@ -2553,7 +2573,8 @@ cmd_ban(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
char *jid = args[0];
if (jid) {
@ -2580,7 +2601,8 @@ cmd_subject(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
if (args[0] == NULL) {
char *subject = muc_subject(mucwin->roomjid);
@ -2643,7 +2665,8 @@ cmd_affiliation(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
if (g_strcmp0(cmd, "list") == 0) {
if (!affiliation) {
@ -2711,7 +2734,8 @@ cmd_role(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
if (g_strcmp0(cmd, "list") == 0) {
if (!role) {
@ -2769,7 +2793,8 @@ cmd_room(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
int num = wins_get_num(window);
int ui_index = num;
@ -2870,7 +2895,8 @@ cmd_occupants(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
if (g_strcmp0(args[0], "show") == 0) {
if (g_strcmp0(args[1], "jid") == 0) {
@ -2927,7 +2953,8 @@ cmd_bookmark(ProfWin *window, gchar **args, struct cmd_help_t help)
gchar *cmd = args[0];
if (window->type == WIN_MUC && cmd == NULL) {
// default to current nickname, password, and autojoin "on"
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
char *nick = muc_nick(mucwin->roomjid);
char *password = muc_password(mucwin->roomjid);
gboolean added = bookmark_add(mucwin->roomjid, nick, password, "on");
@ -3068,7 +3095,8 @@ cmd_nick(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
char *nick = args[0];
presence_change_room_nick(mucwin->roomjid, nick);
@ -3171,19 +3199,22 @@ cmd_tiny(ProfWin *window, gchar **args, struct cmd_help_t help)
switch (window->type){
case WIN_CHAT:
{
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
cl_ev_send_msg(chatwin, tiny);
break;
}
case WIN_PRIVATE:
{
ProfPrivateWin *privatewin = wins_get_current_private();
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
cl_ev_send_priv_msg(privatewin, tiny);
break;
}
case WIN_MUC:
{
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
cl_ev_send_muc_msg(mucwin, tiny);
break;
}
@ -4182,7 +4213,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE;
@ -4234,7 +4266,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode == PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
return TRUE;
@ -4256,7 +4289,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE;
@ -4272,7 +4306,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE;
@ -4288,7 +4323,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE;
@ -4304,7 +4340,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE;
@ -4332,7 +4369,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE;
@ -4347,7 +4385,8 @@ cmd_otr(ProfWin *window, gchar **args, struct cmd_help_t help)
return TRUE;
}
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
if (chatwin->enc_mode != PROF_ENC_OTR) {
ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
return TRUE;

View File

@ -34,6 +34,7 @@
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
@ -666,7 +667,8 @@ char *
muc_autocomplete(ProfWin *window, const char * const input)
{
if (window->type == WIN_MUC) {
ProfMucWin *mucwin = wins_get_current_muc();
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
ChatRoom *chat_room = g_hash_table_lookup(rooms, mucwin->roomjid);
if (chat_room && chat_room->nick_ac) {

View File

@ -41,6 +41,7 @@
#include <signal.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <glib.h>
@ -134,7 +135,8 @@ prof_handle_activity(void)
ProfWin *current = wins_get_current();
if ((status == JABBER_CONNECTED) && (current->type == WIN_CHAT)) {
ProfChatWin *chatwin = wins_get_current_chat();
ProfChatWin *chatwin = (ProfChatWin*)current;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
chat_state_handle_typing(chatwin->barejid, chatwin->state);
}
}

View File

@ -167,74 +167,6 @@ wins_get_current(void)
}
}
ProfChatWin *
wins_get_current_chat(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfChatWin *chatwin = (ProfChatWin*)window;
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
return chatwin;
} else {
return NULL;
}
} else {
return NULL;
}
}
ProfMucWin *
wins_get_current_muc(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfMucWin *mucwin = (ProfMucWin*)window;
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
return mucwin;
} else {
return NULL;
}
} else {
return NULL;
}
}
ProfPrivateWin *
wins_get_current_private(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfPrivateWin *privatewin = (ProfPrivateWin*)window;
assert(privatewin->memcheck == PROFPRIVATEWIN_MEMCHECK);
return privatewin;
} else {
return NULL;
}
} else {
return NULL;
}
}
ProfMucConfWin *
wins_get_current_muc_conf(void)
{
if (windows) {
ProfWin *window = g_hash_table_lookup(windows, GINT_TO_POINTER(current));
if (window) {
ProfMucConfWin *confwin = (ProfMucConfWin*)window;
assert(confwin->memcheck == PROFCONFWIN_MEMCHECK);
return confwin;
} else {
return NULL;
}
} else {
return NULL;
}
}
GList *
wins_get_nums(void)
{

View File

@ -53,10 +53,6 @@ ProfPrivateWin *wins_get_private(const char * const fulljid);
ProfXMLWin * wins_get_xmlconsole(void);
ProfWin * wins_get_current(void);
ProfChatWin * wins_get_current_chat(void);
ProfMucWin * wins_get_current_muc(void);
ProfPrivateWin * wins_get_current_private(void);
ProfMucConfWin * wins_get_current_muc_conf(void);
void wins_set_current_by_num(int i);

View File

@ -423,30 +423,23 @@ void cmd_otr_theirfp_shows_message_when_in_private(void **state)
void cmd_otr_theirfp_shows_message_when_non_otr_chat_window(void **state)
{
char *recipient = "someuser@someserver.com";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "theirfp", NULL };
ProfWin window;
window.type = WIN_CHAT;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
will_return(jabber_get_connection_status, JABBER_CONNECTED);
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
chatwin->barejid = strdup(recipient);
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
will_return(win_create_chat, &chatwin->window);
wins_init();
wins_new_chat(recipient);
wins_set_current_by_num(2);
expect_ui_current_print_formatted_line('!', 0, "You are not currently in an OTR session.");
gboolean result = cmd_otr(&window, args, *help);
gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help);
assert_true(result);
free(help);
wins_close_current();
}
void cmd_otr_theirfp_shows_fingerprint(void **state)
@ -458,32 +451,27 @@ void cmd_otr_theirfp_shows_fingerprint(void **state)
GString *message = g_string_new(recipient);
g_string_append(message, "'s OTR fingerprint: ");
g_string_append(message, fingerprint);
ProfWin window;
window.type = WIN_CHAT;
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
chatwin->barejid = strdup(recipient);
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
chatwin->enc_mode = PROF_ENC_OTR;
will_return(win_create_chat, &chatwin->window);
wins_init();
wins_new_chat(recipient);
wins_set_current_by_num(2);
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_OTR;
will_return(jabber_get_connection_status, JABBER_CONNECTED);
expect_string(otr_get_their_fingerprint, recipient, chatwin->barejid);
expect_string(otr_get_their_fingerprint, recipient, recipient);
will_return(otr_get_their_fingerprint, strdup(fingerprint));
expect_ui_current_print_formatted_line('!', 0, message->str);
gboolean result = cmd_otr(&window, args, *help);
gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help);
assert_true(result);
g_string_free(message, TRUE);
free(help);
wins_close_current();
}
static void
@ -524,28 +512,23 @@ void cmd_otr_start_shows_message_when_already_started(void **state)
char *recipient = "someone@server.org";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
ProfWin window;
window.type = WIN_CHAT;
will_return(jabber_get_connection_status, JABBER_CONNECTED);
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
chatwin->barejid = strdup(recipient);
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
chatwin->enc_mode = PROF_ENC_OTR;
will_return(win_create_chat, &chatwin->window);
wins_init();
wins_new_chat(recipient);
wins_set_current_by_num(2);
ProfWin window;
window.type = WIN_CHAT;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_OTR;
expect_ui_current_print_formatted_line('!', 0, "You are already in an OTR session.");
gboolean result = cmd_otr(&window, args, *help);
gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help);
assert_true(result);
free(help);
wins_close_current();
}
void cmd_otr_start_shows_message_when_no_key(void **state)
@ -553,29 +536,24 @@ void cmd_otr_start_shows_message_when_no_key(void **state)
char *recipient = "someone@server.org";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
ProfWin window;
window.type = WIN_CHAT;
will_return(jabber_get_connection_status, JABBER_CONNECTED);
will_return(otr_key_loaded, FALSE);
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
chatwin->barejid = strdup(recipient);
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
chatwin->enc_mode = PROF_ENC_NONE;
will_return(win_create_chat, &chatwin->window);
wins_init();
wins_new_chat(recipient);
wins_set_current_by_num(2);
ProfWin window;
window.type = WIN_CHAT;
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_NONE;
expect_ui_current_print_formatted_line('!', 0, "You have not generated or loaded a private key, use '/otr gen'");
gboolean result = cmd_otr(&window, args, *help);
gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help);
assert_true(result);
free(help);
wins_close_current();
}
void
@ -585,30 +563,26 @@ cmd_otr_start_sends_otr_query_message_to_current_recipeint(void **state)
char *query_message = "?OTR?";
CommandHelp *help = malloc(sizeof(CommandHelp));
gchar *args[] = { "start", NULL };
ProfWin window;
window.type = WIN_CHAT;
ProfChatWin *chatwin = malloc(sizeof(ProfChatWin));
chatwin->barejid = strdup(recipient);
chatwin->memcheck = PROFCHATWIN_MEMCHECK;
will_return(win_create_chat, &chatwin->window);
wins_init();
wins_new_chat(recipient);
wins_set_current_by_num(2);
ProfChatWin chatwin;
chatwin.window = window;
chatwin.barejid = recipient;
chatwin.memcheck = PROFCHATWIN_MEMCHECK;
chatwin.enc_mode = PROF_ENC_NONE;
will_return(jabber_get_connection_status, JABBER_CONNECTED);
will_return(otr_key_loaded, TRUE);
will_return(otr_start_query, query_message);
expect_string(message_send_chat_encrypted, barejid, chatwin->barejid);
expect_string(message_send_chat_encrypted, barejid, recipient);
expect_string(message_send_chat_encrypted, msg, query_message);
gboolean result = cmd_otr(&window, args, *help);
gboolean result = cmd_otr((ProfWin*)&chatwin, args, *help);
assert_true(result);
free(help);
wins_close_current();
}
#else