Added roster struct, create and destroy roster on connect/disconnect
This commit is contained in:
@@ -2599,7 +2599,20 @@ cmd_autocomplete(ProfWin *window, const char *const input)
|
||||
void
|
||||
cmd_reset_autocomplete(ProfWin *window)
|
||||
{
|
||||
roster_reset_search_attempts();
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
roster_reset_search_attempts();
|
||||
|
||||
if (window->type == WIN_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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
muc_invites_reset_ac();
|
||||
accounts_reset_all_search();
|
||||
accounts_reset_enabled_search();
|
||||
@@ -2692,15 +2705,6 @@ cmd_reset_autocomplete(ProfWin *window)
|
||||
script_show_ac = NULL;
|
||||
}
|
||||
|
||||
if (window->type == WIN_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);
|
||||
}
|
||||
}
|
||||
|
||||
if (window->type == WIN_MUC) {
|
||||
ProfMucWin *mucwin = (ProfMucWin*)window;
|
||||
assert(mucwin->memcheck == PROFMUCWIN_MEMCHECK);
|
||||
@@ -2836,6 +2840,8 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
|
||||
int i;
|
||||
char *result = NULL;
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
|
||||
// autocomplete boolean settings
|
||||
gchar *boolean_choices[] = { "/beep", "/intype", "/states", "/outtype",
|
||||
"/flash", "/splash", "/chlog", "/grlog", "/history", "/vercheck",
|
||||
@@ -2869,7 +2875,7 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
|
||||
}
|
||||
|
||||
// otherwise autocomplete using roster
|
||||
} else {
|
||||
} else if (conn_status == JABBER_CONNECTED) {
|
||||
gchar *contact_choices[] = { "/msg", "/info", "/status" };
|
||||
// Remove quote character before and after names when doing autocomplete
|
||||
char *unquoted = strip_arg_quotes(input);
|
||||
@@ -2891,9 +2897,11 @@ _cmd_complete_parameters(ProfWin *window, const char *const input)
|
||||
}
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_func(input, "/invite", roster_contact_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
result = autocomplete_param_with_func(input, "/invite", roster_contact_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
gchar *invite_choices[] = { "/decline", "/join" };
|
||||
@@ -3014,15 +3022,18 @@ _who_autocomplete(ProfWin *window, const char *const input)
|
||||
return result;
|
||||
}
|
||||
} else {
|
||||
int i = 0;
|
||||
gchar *group_commands[] = { "/who any", "/who online", "/who offline",
|
||||
"/who chat", "/who away", "/who xa", "/who dnd", "/who available",
|
||||
"/who unavailable" };
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
int i = 0;
|
||||
gchar *group_commands[] = { "/who any", "/who online", "/who offline",
|
||||
"/who chat", "/who away", "/who xa", "/who dnd", "/who available",
|
||||
"/who unavailable" };
|
||||
|
||||
for (i = 0; i < ARRAY_SIZE(group_commands); i++) {
|
||||
result = autocomplete_param_with_func(input, group_commands[i], roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
for (i = 0; i < ARRAY_SIZE(group_commands); i++) {
|
||||
result = autocomplete_param_with_func(input, group_commands[i], roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3055,18 +3066,23 @@ _roster_autocomplete(ProfWin *window, const char *const input)
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/roster nick", roster_barejid_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/roster clearnick", roster_barejid_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/roster remove", roster_barejid_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
result = autocomplete_param_with_func(input, "/roster nick", roster_barejid_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/roster clearnick", roster_barejid_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/roster remove", roster_barejid_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result = autocomplete_param_with_ac(input, "/roster remove_all", roster_remove_all_ac, TRUE);
|
||||
if (result) {
|
||||
return result;
|
||||
@@ -3119,27 +3135,32 @@ static char*
|
||||
_group_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
char *result = NULL;
|
||||
result = autocomplete_param_with_func(input, "/group show", roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
result = autocomplete_param_with_func(input, "/group show", roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_no_with_func(input, "/group add", 4, roster_contact_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_no_with_func(input, "/group remove", 4, roster_contact_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/group add", roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/group remove", roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
result = autocomplete_param_no_with_func(input, "/group add", 4, roster_contact_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_no_with_func(input, "/group remove", 4, roster_contact_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/group add", roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_func(input, "/group remove", roster_group_autocomplete);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
result = autocomplete_param_with_ac(input, "/group", group_ac, TRUE);
|
||||
if (result) {
|
||||
return result;
|
||||
@@ -3361,9 +3382,13 @@ _otr_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
char *found = NULL;
|
||||
|
||||
found = autocomplete_param_with_func(input, "/otr start", roster_contact_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
found = autocomplete_param_with_func(input, "/otr start", roster_contact_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
found = autocomplete_param_with_ac(input, "/otr log", otr_log_ac, TRUE);
|
||||
@@ -3372,24 +3397,25 @@ _otr_autocomplete(ProfWin *window, const char *const input)
|
||||
}
|
||||
|
||||
// /otr policy always user@server.com
|
||||
gboolean result;
|
||||
gchar **args = parse_args(input, 3, 3, &result);
|
||||
if (result && (strcmp(args[0], "policy") == 0)) {
|
||||
GString *beginning = g_string_new("/otr ");
|
||||
g_string_append(beginning, args[0]);
|
||||
g_string_append(beginning, " ");
|
||||
g_string_append(beginning, args[1]);
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
gboolean result;
|
||||
gchar **args = parse_args(input, 3, 3, &result);
|
||||
if (result && (strcmp(args[0], "policy") == 0)) {
|
||||
GString *beginning = g_string_new("/otr ");
|
||||
g_string_append(beginning, args[0]);
|
||||
g_string_append(beginning, " ");
|
||||
g_string_append(beginning, args[1]);
|
||||
|
||||
found = autocomplete_param_with_func(input, beginning->str, roster_contact_autocomplete);
|
||||
g_string_free(beginning, TRUE);
|
||||
if (found) {
|
||||
g_strfreev(args);
|
||||
return found;
|
||||
found = autocomplete_param_with_func(input, beginning->str, roster_contact_autocomplete);
|
||||
g_string_free(beginning, TRUE);
|
||||
if (found) {
|
||||
g_strfreev(args);
|
||||
return found;
|
||||
}
|
||||
}
|
||||
g_strfreev(args);
|
||||
}
|
||||
|
||||
g_strfreev(args);
|
||||
|
||||
found = autocomplete_param_with_ac(input, "/otr policy", otr_policy_ac, TRUE);
|
||||
if (found) {
|
||||
return found;
|
||||
@@ -3408,9 +3434,13 @@ _pgp_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
char *found = NULL;
|
||||
|
||||
found = autocomplete_param_with_func(input, "/pgp start", roster_contact_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
found = autocomplete_param_with_func(input, "/pgp start", roster_contact_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
found = autocomplete_param_with_ac(input, "/pgp log", pgp_log_ac, TRUE);
|
||||
@@ -3438,9 +3468,11 @@ _pgp_autocomplete(ProfWin *window, const char *const input)
|
||||
g_strfreev(args);
|
||||
#endif
|
||||
|
||||
found = autocomplete_param_with_func(input, "/pgp setkey", roster_barejid_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
found = autocomplete_param_with_func(input, "/pgp setkey", roster_barejid_autocomplete);
|
||||
if (found) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
found = autocomplete_param_with_ac(input, "/pgp", pgp_ac, TRUE);
|
||||
@@ -3529,7 +3561,8 @@ _resource_autocomplete(ProfWin *window, const char *const input)
|
||||
{
|
||||
char *found = NULL;
|
||||
|
||||
if (window->type == WIN_CHAT) {
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED && window->type == WIN_CHAT) {
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
|
||||
@@ -2309,6 +2309,13 @@ cmd_resource(ProfWin *window, const char *const command, gchar **args)
|
||||
cons_show("Resource can only be changed in chat windows.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
cons_show("You are not currently connected.");
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
ProfChatWin *chatwin = (ProfChatWin*)window;
|
||||
|
||||
if (g_strcmp0(cmd, "set") == 0) {
|
||||
|
||||
@@ -74,7 +74,7 @@ cl_ev_disconnect(void)
|
||||
cons_show("%s logged out successfully.", jid);
|
||||
|
||||
jabber_disconnect();
|
||||
roster_clear();
|
||||
roster_destroy();
|
||||
muc_invites_clear();
|
||||
chat_sessions_clear();
|
||||
tlscerts_clear_current();
|
||||
|
||||
@@ -64,6 +64,8 @@ sv_ev_login_account_success(char *account_name, int secured)
|
||||
{
|
||||
ProfAccount *account = accounts_get_account(account_name);
|
||||
|
||||
roster_create();
|
||||
|
||||
#ifdef HAVE_LIBOTR
|
||||
otr_on_connect(account);
|
||||
#endif
|
||||
@@ -150,7 +152,7 @@ sv_ev_lost_connection(void)
|
||||
{
|
||||
cons_show_error("Lost connection.");
|
||||
|
||||
roster_clear();
|
||||
roster_destroy();
|
||||
muc_invites_clear();
|
||||
chat_sessions_clear();
|
||||
ui_disconnected();
|
||||
@@ -168,8 +170,7 @@ sv_ev_failed_login(void)
|
||||
}
|
||||
|
||||
void
|
||||
sv_ev_room_invite(jabber_invite_t invite_type,
|
||||
const char *const invitor, const char *const room,
|
||||
sv_ev_room_invite(jabber_invite_t invite_type, const char *const invitor, const char *const room,
|
||||
const char *const reason, const char *const password)
|
||||
{
|
||||
if (!muc_active(room) && !muc_invites_contain(room)) {
|
||||
|
||||
@@ -84,9 +84,13 @@ cb_policy(void *opdata, ConnContext *context)
|
||||
}
|
||||
|
||||
static int
|
||||
cb_is_logged_in(void *opdata, const char *accountname,
|
||||
const char *protocol, const char *recipient)
|
||||
cb_is_logged_in(void *opdata, const char *accountname, const char *protocol, const char *recipient)
|
||||
{
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
return PRESENCE_OFFLINE;
|
||||
}
|
||||
|
||||
PContact contact = roster_get_contact(recipient);
|
||||
|
||||
// not in roster
|
||||
|
||||
@@ -337,7 +337,6 @@ _init(char *log_level)
|
||||
jabber_init();
|
||||
cmd_init();
|
||||
log_info("Initialising contact list");
|
||||
roster_init();
|
||||
muc_init();
|
||||
tlscerts_init();
|
||||
scripts_init();
|
||||
@@ -361,10 +360,13 @@ _shutdown(void)
|
||||
ui_clear_win_title();
|
||||
}
|
||||
}
|
||||
ui_close_all_wins();
|
||||
jabber_disconnect();
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
cl_ev_disconnect();
|
||||
}
|
||||
|
||||
jabber_shutdown();
|
||||
roster_free();
|
||||
muc_close();
|
||||
caps_close();
|
||||
ui_close();
|
||||
|
||||
@@ -34,6 +34,8 @@
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
#include <glib.h>
|
||||
#include <assert.h>
|
||||
|
||||
@@ -44,24 +46,28 @@
|
||||
#include "tools/autocomplete.h"
|
||||
#include "config/preferences.h"
|
||||
|
||||
// nicknames
|
||||
static Autocomplete name_ac;
|
||||
typedef struct prof_roster_t {
|
||||
// contacts, indexed on barejid
|
||||
GHashTable *contacts;
|
||||
|
||||
// barejids
|
||||
static Autocomplete barejid_ac;
|
||||
// nicknames
|
||||
Autocomplete name_ac;
|
||||
|
||||
// fulljids
|
||||
static Autocomplete fulljid_ac;
|
||||
// barejids
|
||||
Autocomplete barejid_ac;
|
||||
|
||||
// groups
|
||||
static Autocomplete groups_ac;
|
||||
GHashTable *group_count;
|
||||
// fulljids
|
||||
Autocomplete fulljid_ac;
|
||||
|
||||
// contacts, indexed on barejid
|
||||
static GHashTable *contacts;
|
||||
// nickname to barejid map
|
||||
GHashTable *name_to_barejid;
|
||||
|
||||
// nickname to jid map
|
||||
static GHashTable *name_to_barejid;
|
||||
// groups
|
||||
Autocomplete groups_ac;
|
||||
GHashTable *group_count;
|
||||
} ProfRoster;
|
||||
|
||||
static ProfRoster *roster = NULL;
|
||||
|
||||
static gboolean _key_equals(void *key1, void *key2);
|
||||
static gboolean _datetimes_equal(GDateTime *dt1, GDateTime *dt2);
|
||||
@@ -71,23 +77,42 @@ static gint _compare_name(PContact a, PContact b);
|
||||
static gint _compare_presence(PContact a, PContact b);
|
||||
|
||||
void
|
||||
roster_clear(void)
|
||||
roster_create(void)
|
||||
{
|
||||
autocomplete_clear(name_ac);
|
||||
autocomplete_clear(barejid_ac);
|
||||
autocomplete_clear(fulljid_ac);
|
||||
autocomplete_clear(groups_ac);
|
||||
g_hash_table_destroy(contacts);
|
||||
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free, (GDestroyNotify)p_contact_free);
|
||||
g_hash_table_destroy(name_to_barejid);
|
||||
name_to_barejid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
g_hash_table_destroy(group_count);
|
||||
group_count = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
assert(roster == NULL);
|
||||
|
||||
roster = malloc(sizeof(ProfRoster));
|
||||
roster->contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free, (GDestroyNotify)p_contact_free);
|
||||
roster->name_ac = autocomplete_new();
|
||||
roster->barejid_ac = autocomplete_new();
|
||||
roster->fulljid_ac = autocomplete_new();
|
||||
roster->name_to_barejid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
roster->groups_ac = autocomplete_new();
|
||||
roster->group_count = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
roster_destroy(void)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
g_hash_table_destroy(roster->contacts);
|
||||
autocomplete_free(roster->name_ac);
|
||||
autocomplete_free(roster->barejid_ac);
|
||||
autocomplete_free(roster->fulljid_ac);
|
||||
g_hash_table_destroy(roster->name_to_barejid);
|
||||
autocomplete_free(roster->groups_ac);
|
||||
g_hash_table_destroy(roster->group_count);
|
||||
|
||||
free(roster);
|
||||
roster = NULL;
|
||||
}
|
||||
|
||||
gboolean
|
||||
roster_update_presence(const char *const barejid, Resource *resource, GDateTime *last_activity)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
assert(barejid != NULL);
|
||||
assert(resource != NULL);
|
||||
|
||||
@@ -100,7 +125,7 @@ roster_update_presence(const char *const barejid, Resource *resource, GDateTime
|
||||
}
|
||||
p_contact_set_presence(contact, resource);
|
||||
Jid *jid = jid_create_from_bare_and_resource(barejid, resource->name);
|
||||
autocomplete_add(fulljid_ac, jid->fulljid);
|
||||
autocomplete_add(roster->fulljid_ac, jid->fulljid);
|
||||
jid_destroy(jid);
|
||||
|
||||
return TRUE;
|
||||
@@ -109,8 +134,10 @@ roster_update_presence(const char *const barejid, Resource *resource, GDateTime
|
||||
PContact
|
||||
roster_get_contact(const char *const barejid)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
gchar *barejidlower = g_utf8_strdown(barejid, -1);
|
||||
PContact contact = g_hash_table_lookup(contacts, barejidlower);
|
||||
PContact contact = g_hash_table_lookup(roster->contacts, barejidlower);
|
||||
g_free(barejidlower);
|
||||
|
||||
return contact;
|
||||
@@ -119,6 +146,8 @@ roster_get_contact(const char *const barejid)
|
||||
char*
|
||||
roster_get_msg_display_name(const char *const barejid, const char *const resource)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GString *result = g_string_new("");
|
||||
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
@@ -146,6 +175,8 @@ roster_get_msg_display_name(const char *const barejid, const char *const resourc
|
||||
gboolean
|
||||
roster_contact_offline(const char *const barejid, const char *const resource, const char *const status)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
|
||||
if (contact == NULL) {
|
||||
@@ -157,7 +188,7 @@ roster_contact_offline(const char *const barejid, const char *const resource, co
|
||||
gboolean result = p_contact_remove_resource(contact, resource);
|
||||
if (result == TRUE) {
|
||||
Jid *jid = jid_create_from_bare_and_resource(barejid, resource);
|
||||
autocomplete_remove(fulljid_ac, jid->fulljid);
|
||||
autocomplete_remove(roster->fulljid_ac, jid->fulljid);
|
||||
jid_destroy(jid);
|
||||
}
|
||||
|
||||
@@ -168,36 +199,19 @@ roster_contact_offline(const char *const barejid, const char *const resource, co
|
||||
void
|
||||
roster_reset_search_attempts(void)
|
||||
{
|
||||
autocomplete_reset(name_ac);
|
||||
autocomplete_reset(barejid_ac);
|
||||
autocomplete_reset(fulljid_ac);
|
||||
autocomplete_reset(groups_ac);
|
||||
}
|
||||
assert(roster != NULL);
|
||||
|
||||
void
|
||||
roster_init(void)
|
||||
{
|
||||
name_ac = autocomplete_new();
|
||||
barejid_ac = autocomplete_new();
|
||||
fulljid_ac = autocomplete_new();
|
||||
groups_ac = autocomplete_new();
|
||||
contacts = g_hash_table_new_full(g_str_hash, (GEqualFunc)_key_equals, g_free, (GDestroyNotify)p_contact_free);
|
||||
name_to_barejid = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free);
|
||||
group_count = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, NULL);
|
||||
}
|
||||
|
||||
void
|
||||
roster_free(void)
|
||||
{
|
||||
autocomplete_free(name_ac);
|
||||
autocomplete_free(barejid_ac);
|
||||
autocomplete_free(fulljid_ac);
|
||||
autocomplete_free(groups_ac);
|
||||
autocomplete_reset(roster->name_ac);
|
||||
autocomplete_reset(roster->barejid_ac);
|
||||
autocomplete_reset(roster->fulljid_ac);
|
||||
autocomplete_reset(roster->groups_ac);
|
||||
}
|
||||
|
||||
void
|
||||
roster_change_name(PContact contact, const char *const new_name)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
assert(contact != NULL);
|
||||
|
||||
const char *current_name = NULL;
|
||||
@@ -214,9 +228,11 @@ roster_change_name(PContact contact, const char *const new_name)
|
||||
void
|
||||
roster_remove(const char *const name, const char *const barejid)
|
||||
{
|
||||
autocomplete_remove(barejid_ac, barejid);
|
||||
autocomplete_remove(name_ac, name);
|
||||
g_hash_table_remove(name_to_barejid, name);
|
||||
assert(roster != NULL);
|
||||
|
||||
autocomplete_remove(roster->barejid_ac, barejid);
|
||||
autocomplete_remove(roster->name_ac, name);
|
||||
g_hash_table_remove(roster->name_to_barejid, name);
|
||||
|
||||
// remove each fulljid
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
@@ -226,7 +242,7 @@ roster_remove(const char *const name, const char *const barejid)
|
||||
GString *fulljid = g_string_new(strdup(barejid));
|
||||
g_string_append(fulljid, "/");
|
||||
g_string_append(fulljid, resources->data);
|
||||
autocomplete_remove(fulljid_ac, fulljid->str);
|
||||
autocomplete_remove(roster->fulljid_ac, fulljid->str);
|
||||
g_string_free(fulljid, TRUE);
|
||||
resources = g_list_next(resources);
|
||||
}
|
||||
@@ -236,14 +252,14 @@ roster_remove(const char *const name, const char *const barejid)
|
||||
GSList *curr = groups;
|
||||
while (curr) {
|
||||
gchar *group = curr->data;
|
||||
if (g_hash_table_contains(group_count, group)) {
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(group_count, group));
|
||||
if (g_hash_table_contains(roster->group_count, group)) {
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, group));
|
||||
count--;
|
||||
if (count < 1) {
|
||||
g_hash_table_remove(group_count, group);
|
||||
autocomplete_remove(groups_ac, group);
|
||||
g_hash_table_remove(roster->group_count, group);
|
||||
autocomplete_remove(roster->groups_ac, group);
|
||||
} else {
|
||||
g_hash_table_insert(group_count, strdup(group), GINT_TO_POINTER(count));
|
||||
g_hash_table_insert(roster->group_count, strdup(group), GINT_TO_POINTER(count));
|
||||
}
|
||||
}
|
||||
curr = g_slist_next(curr);
|
||||
@@ -251,13 +267,15 @@ roster_remove(const char *const name, const char *const barejid)
|
||||
}
|
||||
|
||||
// remove the contact
|
||||
g_hash_table_remove(contacts, barejid);
|
||||
g_hash_table_remove(roster->contacts, barejid);
|
||||
}
|
||||
|
||||
void
|
||||
roster_update(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
|
||||
gboolean pending_out)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
assert(contact != NULL);
|
||||
|
||||
@@ -281,14 +299,14 @@ roster_update(const char *const barejid, const char *const name, GSList *groups,
|
||||
if (!p_contact_in_group(contact, new_group)) {
|
||||
|
||||
// group doesn't yet exist
|
||||
if (!g_hash_table_contains(group_count, new_group)) {
|
||||
g_hash_table_insert(group_count, strdup(new_group), GINT_TO_POINTER(1));
|
||||
autocomplete_add(groups_ac, curr_new_group->data);
|
||||
if (!g_hash_table_contains(roster->group_count, new_group)) {
|
||||
g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(1));
|
||||
autocomplete_add(roster->groups_ac, curr_new_group->data);
|
||||
|
||||
// increment count
|
||||
} else {
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(group_count, new_group));
|
||||
g_hash_table_insert(group_count, strdup(new_group), GINT_TO_POINTER(count + 1));
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, new_group));
|
||||
g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(count + 1));
|
||||
}
|
||||
}
|
||||
curr_new_group = g_slist_next(curr_new_group);
|
||||
@@ -300,14 +318,14 @@ roster_update(const char *const barejid, const char *const name, GSList *groups,
|
||||
char *old_group = curr_old_group->data;
|
||||
// removed from group
|
||||
if (!g_slist_find_custom(groups, old_group, (GCompareFunc)g_strcmp0)) {
|
||||
if (g_hash_table_contains(group_count, old_group)) {
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(group_count, old_group));
|
||||
if (g_hash_table_contains(roster->group_count, old_group)) {
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, old_group));
|
||||
count--;
|
||||
if (count < 1) {
|
||||
g_hash_table_remove(group_count, old_group);
|
||||
autocomplete_remove(groups_ac, old_group);
|
||||
g_hash_table_remove(roster->group_count, old_group);
|
||||
autocomplete_remove(roster->groups_ac, old_group);
|
||||
} else {
|
||||
g_hash_table_insert(group_count, strdup(old_group), GINT_TO_POINTER(count));
|
||||
g_hash_table_insert(roster->group_count, strdup(old_group), GINT_TO_POINTER(count));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -322,31 +340,32 @@ gboolean
|
||||
roster_add(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
|
||||
gboolean pending_out)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
PContact contact = roster_get_contact(barejid);
|
||||
if (contact) {
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
contact = p_contact_new(barejid, name, groups, subscription, NULL,
|
||||
pending_out);
|
||||
contact = p_contact_new(barejid, name, groups, subscription, NULL, pending_out);
|
||||
|
||||
// add groups
|
||||
GSList *curr_new_group = groups;
|
||||
while (curr_new_group) {
|
||||
char *new_group = curr_new_group->data;
|
||||
if (g_hash_table_contains(group_count, new_group)) {
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(group_count, new_group));
|
||||
g_hash_table_insert(group_count, strdup(new_group), GINT_TO_POINTER(count + 1));
|
||||
if (g_hash_table_contains(roster->group_count, new_group)) {
|
||||
int count = GPOINTER_TO_INT(g_hash_table_lookup(roster->group_count, new_group));
|
||||
g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(count + 1));
|
||||
} else {
|
||||
g_hash_table_insert(group_count, strdup(new_group), GINT_TO_POINTER(1));
|
||||
autocomplete_add(groups_ac, new_group);
|
||||
g_hash_table_insert(roster->group_count, strdup(new_group), GINT_TO_POINTER(1));
|
||||
autocomplete_add(roster->groups_ac, new_group);
|
||||
}
|
||||
|
||||
curr_new_group = g_slist_next(curr_new_group);
|
||||
}
|
||||
|
||||
g_hash_table_insert(contacts, strdup(barejid), contact);
|
||||
autocomplete_add(barejid_ac, barejid);
|
||||
g_hash_table_insert(roster->contacts, strdup(barejid), contact);
|
||||
autocomplete_add(roster->barejid_ac, barejid);
|
||||
_add_name_and_barejid(name, barejid);
|
||||
|
||||
return TRUE;
|
||||
@@ -355,8 +374,10 @@ roster_add(const char *const barejid, const char *const name, GSList *groups, co
|
||||
char*
|
||||
roster_barejid_from_name(const char *const name)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
if (name) {
|
||||
return g_hash_table_lookup(name_to_barejid, name);
|
||||
return g_hash_table_lookup(roster->name_to_barejid, name);
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
@@ -365,12 +386,14 @@ roster_barejid_from_name(const char *const name)
|
||||
GSList*
|
||||
roster_get_contacts_by_presence(const char *const presence)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GSList *result = NULL;
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
gpointer value;
|
||||
|
||||
g_hash_table_iter_init(&iter, contacts);
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
PContact contact = (PContact)value;
|
||||
if (g_strcmp0(p_contact_presence(contact), presence) == 0) {
|
||||
@@ -385,6 +408,8 @@ roster_get_contacts_by_presence(const char *const presence)
|
||||
GSList*
|
||||
roster_get_contacts(roster_ord_t order, gboolean include_offline)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GSList *result = NULL;
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
@@ -397,7 +422,7 @@ roster_get_contacts(roster_ord_t order, gboolean include_offline)
|
||||
cmp_func = (GCompareFunc) _compare_name;
|
||||
}
|
||||
|
||||
g_hash_table_iter_init(&iter, contacts);
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
PContact contact = value;
|
||||
const char *presence = p_contact_presence(contact);
|
||||
@@ -415,12 +440,14 @@ roster_get_contacts(roster_ord_t order, gboolean include_offline)
|
||||
GSList*
|
||||
roster_get_contacts_online(void)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GSList *result = NULL;
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
gpointer value;
|
||||
|
||||
g_hash_table_iter_init(&iter, contacts);
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
if(strcmp(p_contact_presence(value), "offline"))
|
||||
result = g_slist_insert_sorted(result, value, (GCompareFunc)_compare_name);
|
||||
@@ -433,11 +460,13 @@ roster_get_contacts_online(void)
|
||||
gboolean
|
||||
roster_has_pending_subscriptions(void)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
gpointer value;
|
||||
|
||||
g_hash_table_iter_init(&iter, contacts);
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
PContact contact = (PContact) value;
|
||||
if (p_contact_pending_out(contact)) {
|
||||
@@ -451,18 +480,24 @@ roster_has_pending_subscriptions(void)
|
||||
char*
|
||||
roster_contact_autocomplete(const char *const search_str)
|
||||
{
|
||||
return autocomplete_complete(name_ac, search_str, TRUE);
|
||||
assert(roster != NULL);
|
||||
|
||||
return autocomplete_complete(roster->name_ac, search_str, TRUE);
|
||||
}
|
||||
|
||||
char*
|
||||
roster_fulljid_autocomplete(const char *const search_str)
|
||||
{
|
||||
return autocomplete_complete(fulljid_ac, search_str, TRUE);
|
||||
assert(roster != NULL);
|
||||
|
||||
return autocomplete_complete(roster->fulljid_ac, search_str, TRUE);
|
||||
}
|
||||
|
||||
GSList*
|
||||
roster_get_nogroup(roster_ord_t order, gboolean include_offline)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GSList *result = NULL;
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
@@ -475,7 +510,7 @@ roster_get_nogroup(roster_ord_t order, gboolean include_offline)
|
||||
cmp_func = (GCompareFunc) _compare_name;
|
||||
}
|
||||
|
||||
g_hash_table_iter_init(&iter, contacts);
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
PContact contact = value;
|
||||
const char *presence = p_contact_presence(contact);
|
||||
@@ -496,6 +531,8 @@ roster_get_nogroup(roster_ord_t order, gboolean include_offline)
|
||||
GSList*
|
||||
roster_get_group(const char *const group, roster_ord_t order, gboolean include_offline)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
GSList *result = NULL;
|
||||
GHashTableIter iter;
|
||||
gpointer key;
|
||||
@@ -508,7 +545,7 @@ roster_get_group(const char *const group, roster_ord_t order, gboolean include_o
|
||||
cmp_func = (GCompareFunc) _compare_name;
|
||||
}
|
||||
|
||||
g_hash_table_iter_init(&iter, contacts);
|
||||
g_hash_table_iter_init(&iter, roster->contacts);
|
||||
while (g_hash_table_iter_next(&iter, &key, &value)) {
|
||||
PContact contact = value;
|
||||
const char *presence = p_contact_presence(contact);
|
||||
@@ -533,19 +570,25 @@ roster_get_group(const char *const group, roster_ord_t order, gboolean include_o
|
||||
GSList*
|
||||
roster_get_groups(void)
|
||||
{
|
||||
return autocomplete_create_list(groups_ac);
|
||||
assert(roster != NULL);
|
||||
|
||||
return autocomplete_create_list(roster->groups_ac);
|
||||
}
|
||||
|
||||
char*
|
||||
roster_group_autocomplete(const char *const search_str)
|
||||
{
|
||||
return autocomplete_complete(groups_ac, search_str, TRUE);
|
||||
assert(roster != NULL);
|
||||
|
||||
return autocomplete_complete(roster->groups_ac, search_str, TRUE);
|
||||
}
|
||||
|
||||
char*
|
||||
roster_barejid_autocomplete(const char *const search_str)
|
||||
{
|
||||
return autocomplete_complete(barejid_ac, search_str, TRUE);
|
||||
assert(roster != NULL);
|
||||
|
||||
return autocomplete_complete(roster->barejid_ac, search_str, TRUE);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -574,15 +617,17 @@ _datetimes_equal(GDateTime *dt1, GDateTime *dt2)
|
||||
static void
|
||||
_replace_name(const char *const current_name, const char *const new_name, const char *const barejid)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
// current handle exists already
|
||||
if (current_name) {
|
||||
autocomplete_remove(name_ac, current_name);
|
||||
g_hash_table_remove(name_to_barejid, current_name);
|
||||
autocomplete_remove(roster->name_ac, current_name);
|
||||
g_hash_table_remove(roster->name_to_barejid, current_name);
|
||||
_add_name_and_barejid(new_name, barejid);
|
||||
// no current handle
|
||||
} else if (new_name) {
|
||||
autocomplete_remove(name_ac, barejid);
|
||||
g_hash_table_remove(name_to_barejid, barejid);
|
||||
autocomplete_remove(roster->name_ac, barejid);
|
||||
g_hash_table_remove(roster->name_to_barejid, barejid);
|
||||
_add_name_and_barejid(new_name, barejid);
|
||||
}
|
||||
}
|
||||
@@ -590,12 +635,14 @@ _replace_name(const char *const current_name, const char *const new_name, const
|
||||
static void
|
||||
_add_name_and_barejid(const char *const name, const char *const barejid)
|
||||
{
|
||||
assert(roster != NULL);
|
||||
|
||||
if (name) {
|
||||
autocomplete_add(name_ac, name);
|
||||
g_hash_table_insert(name_to_barejid, strdup(name), strdup(barejid));
|
||||
autocomplete_add(roster->name_ac, name);
|
||||
g_hash_table_insert(roster->name_to_barejid, strdup(name), strdup(barejid));
|
||||
} else {
|
||||
autocomplete_add(name_ac, barejid);
|
||||
g_hash_table_insert(name_to_barejid, strdup(barejid), strdup(barejid));
|
||||
autocomplete_add(roster->name_ac, barejid);
|
||||
g_hash_table_insert(roster->name_to_barejid, strdup(barejid), strdup(barejid));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -50,8 +50,8 @@ gboolean roster_update_presence(const char *const barejid, Resource *resource, G
|
||||
PContact roster_get_contact(const char *const barejid);
|
||||
gboolean roster_contact_offline(const char *const barejid, const char *const resource, const char *const status);
|
||||
void roster_reset_search_attempts(void);
|
||||
void roster_init(void);
|
||||
void roster_free(void);
|
||||
void roster_create(void);
|
||||
void roster_destroy(void);
|
||||
void roster_change_name(PContact contact, const char *const new_name);
|
||||
void roster_remove(const char *const name, const char *const barejid);
|
||||
void roster_update(const char *const barejid, const char *const name, GSList *groups, const char *const subscription,
|
||||
|
||||
@@ -362,13 +362,18 @@ chatwin_get_string(ProfChatWin *chatwin)
|
||||
|
||||
GString *res = g_string_new("Chat ");
|
||||
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact == NULL) {
|
||||
g_string_append(res, chatwin->barejid);
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact == NULL) {
|
||||
g_string_append(res, chatwin->barejid);
|
||||
} else {
|
||||
const char *display_name = p_contact_name_or_jid(contact);
|
||||
g_string_append(res, display_name);
|
||||
g_string_append_printf(res, " - %s", p_contact_presence(contact));
|
||||
}
|
||||
} else {
|
||||
const char *display_name = p_contact_name_or_jid(contact);
|
||||
g_string_append(res, display_name);
|
||||
g_string_append_printf(res, " - %s", p_contact_presence(contact));
|
||||
g_string_append(res, chatwin->barejid);
|
||||
}
|
||||
|
||||
if (chatwin->unread > 0) {
|
||||
|
||||
@@ -746,8 +746,7 @@ cons_show_status(const char *const barejid)
|
||||
}
|
||||
|
||||
void
|
||||
cons_show_room_invite(const char *const invitor, const char * const room,
|
||||
const char *const reason)
|
||||
cons_show_room_invite(const char *const invitor, const char * const room, const char *const reason)
|
||||
{
|
||||
char *display_from = NULL;
|
||||
PContact contact = roster_get_contact(invitor);
|
||||
|
||||
@@ -466,6 +466,11 @@ rosterwin_roster(void)
|
||||
return;
|
||||
}
|
||||
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status != JABBER_CONNECTED) {
|
||||
return;
|
||||
}
|
||||
|
||||
ProfLayoutSplit *layout = (ProfLayoutSplit*)console->layout;
|
||||
assert(layout->memcheck == LAYOUT_SPLIT_MEMCHECK);
|
||||
|
||||
|
||||
@@ -403,15 +403,18 @@ _show_contact_presence(ProfChatWin *chatwin)
|
||||
theme_item_t presence_colour = THEME_TITLE_OFFLINE;
|
||||
const char *presence = "offline";
|
||||
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact) {
|
||||
if (resource) {
|
||||
Resource *resourcep = p_contact_get_resource(contact, resource);
|
||||
if (resourcep) {
|
||||
presence = string_from_resource_presence(resourcep->presence);
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact) {
|
||||
if (resource) {
|
||||
Resource *resourcep = p_contact_get_resource(contact, resource);
|
||||
if (resourcep) {
|
||||
presence = string_from_resource_presence(resourcep->presence);
|
||||
}
|
||||
} else {
|
||||
presence = p_contact_presence(contact);
|
||||
}
|
||||
} else {
|
||||
presence = p_contact_presence(contact);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -248,10 +248,15 @@ win_get_title(ProfWin *window)
|
||||
if (window->type == WIN_CHAT) {
|
||||
ProfChatWin *chatwin = (ProfChatWin*) window;
|
||||
assert(chatwin->memcheck == PROFCHATWIN_MEMCHECK);
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact) {
|
||||
const char *name = p_contact_name_or_jid(contact);
|
||||
return strdup(name);
|
||||
jabber_conn_status_t conn_status = jabber_get_connection_status();
|
||||
if (conn_status == JABBER_CONNECTED) {
|
||||
PContact contact = roster_get_contact(chatwin->barejid);
|
||||
if (contact) {
|
||||
const char *name = p_contact_name_or_jid(contact);
|
||||
return strdup(name);
|
||||
} else {
|
||||
return strdup(chatwin->barejid);
|
||||
}
|
||||
} else {
|
||||
return strdup(chatwin->barejid);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user