From: Dario Z. <ev...@us...> - 2005-03-02 22:39:58
|
Update of /cvsroot/gaim-bnet/gaim-bnet/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19304/src Modified Files: bnet.h buddy.c buddy.h conn.c conn.h proto.c Log Message: Polling and better buddy events code. See the changelog for details. Index: conn.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/conn.h,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** conn.h 18 Feb 2005 09:46:46 -0000 1.9 --- conn.h 2 Mar 2005 22:39:47 -0000 1.10 *************** *** 75,78 **** --- 75,79 ---- gboolean welcome; + guint timer; gboolean fl_listing; gchar *vw_nick; // verbose where - nick Index: conn.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/conn.c,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** conn.c 13 Feb 2005 00:19:49 -0000 1.12 --- conn.c 2 Mar 2005 22:39:47 -0000 1.13 *************** *** 349,352 **** --- 349,354 ---- if (conn->flood_timer) gaim_timeout_remove(conn->flood_timer); + if (conn->timer) + gaim_timeout_remove(conn->timer); g_list_foreach(conn->out_queue, bnet_list_destroy_all, NULL); g_list_free(conn->out_queue); Index: bnet.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/bnet.h,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** bnet.h 7 Feb 2005 15:35:11 -0000 1.11 --- bnet.h 2 Mar 2005 22:39:47 -0000 1.12 *************** *** 33,36 **** --- 33,38 ---- #define BNET_INITIAL_BUFSIZE 1024 + #define BNET_FRIENDLIST_TIMEOUT 45000 + #include <glib.h> #include <string.h> Index: proto.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/proto.c,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** proto.c 18 Feb 2005 09:46:46 -0000 1.24 --- proto.c 2 Mar 2005 22:39:47 -0000 1.25 *************** *** 45,71 **** } ! static void ! bnet_hash_check_buddy(gpointer key, gpointer value, gpointer user_data) { ! BNetConn *conn = BNET_CONN(user_data); ! BNetBuddy *buddy = BNET_BUDDY(value); ! if (buddy->fl_position == -1) { ! if (!buddy->new_entry) { ! /* Consider server list authoritative... if buddy was added by ! * local list and don't exist on server, then delete it ! */ ! GaimBuddy *gb = gaim_find_buddy(conn->account, buddy->name); ! g_return_if_fail(gb); ! gaim_blist_remove_buddy(gb); ! g_hash_table_remove(conn->buddies, buddy->name); ! } else { ! /* Buddy is added manually now... then we should add it to ! * the server list too ! */ ! bnet_conn_send(conn, "/friends add %s\n", buddy->name); ! bnet_conn_send(conn, "/where %s\n", buddy->name); ! } ! } } --- 45,55 ---- } ! static gboolean ! bnet_timeout_get_friendlist(gpointer arg) { ! BNetConn *conn = BNET_CONN(arg); ! bnet_conn_request_friends_list(conn); ! return TRUE; } *************** *** 201,205 **** room = w->data; ! b = bnet_buddy_hard_lookup(conn, nick); g_return_if_fail(b); --- 185,189 ---- room = w->data; ! b = bnet_buddy_lookup(conn, nick); g_return_if_fail(b); *************** *** 233,256 **** conn->welcome = TRUE; } static void ! bnet_proto_info_fl_online(BNetConn *conn, GList *args) { GaimConnection *gc; BNetBuddy *b; - GList *w = args; ! gchar *n, *nick; ! gchar *using, *chan; ! ! gaim_debug_info("bnet", "bnet_proto_info_fl_online\n"); ! n = w->data; ! w = g_list_next(w); ! nick = w->data; ! w = g_list_next(w); ! using = w->data; ! w = g_list_next(w); ! chan = w->data; b = bnet_buddy_hard_lookup(conn, nick); --- 217,237 ---- conn->welcome = TRUE; + + if (!conn->timer) + conn->timer = gaim_timeout_add(BNET_FRIENDLIST_TIMEOUT, + bnet_timeout_get_friendlist, conn); } static void ! bnet_proto_info_fl(BNetConn *conn, gboolean online, gchar *const *info) { GaimConnection *gc; BNetBuddy *b; ! const gchar *n = info[0]; ! const gchar *nick = info[1]; ! const gchar *prod = online ? info[2] : NULL; ! const gchar *location = online ? info[3] : NULL; ! gaim_debug_info("bnet", "bnet_proto_info_fl\n"); b = bnet_buddy_hard_lookup(conn, nick); *************** *** 258,279 **** sscanf(n, "%u", &b->fl_position); ! bnet_buddy_set_info(b, using, chan); gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, TRUE, 0, 0, 0, 0); } static void ! bnet_proto_info_fl_offline(BNetConn *conn, GList *args) { ! GaimConnection *gc; ! BNetBuddy *b; GList *w = args; ! gchar *n, *nick; gaim_debug_info("bnet", "bnet_proto_info_fl_offline\n"); ! n = w->data; w = g_list_next(w); nick = w->data; --- 239,289 ---- sscanf(n, "%u", &b->fl_position); ! bnet_buddy_set_info(b, prod, location); gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, online, 0, 0, 0, 0); } static void ! bnet_proto_info_fl_online(BNetConn *conn, GList *args) { GList *w = args; + gchar *info[4]; ! gaim_debug_info("bnet", "bnet_proto_info_fl_online\n"); ! ! info[0] = w->data; ! w = g_list_next(w); ! info[1] = w->data; ! w = g_list_next(w); ! info[2] = w->data; ! w = g_list_next(w); ! info[3] = w->data; ! ! bnet_proto_info_fl(conn, TRUE, info); ! } ! ! static void ! bnet_proto_info_fl_offline(BNetConn *conn, GList *args) { ! GList *w = args; ! gchar *info[2]; gaim_debug_info("bnet", "bnet_proto_info_fl_offline\n"); ! info[0] = w->data; w = g_list_next(w); + info[1] = w->data; + + bnet_proto_info_fl(conn, FALSE, info); + } + + static void + bnet_proto_info_fl_added(BNetConn *conn, GList *args) { + GList *w = args; + BNetBuddy *b; + + gchar *nick; + + gaim_debug_info("bnet", "bnet_proto_info_fl_added(%s)\n", w->data); + nick = w->data; *************** *** 281,288 **** g_return_if_fail(b); ! sscanf(n, "%u", &b->fl_position); ! gc = gaim_account_get_connection(conn->account); ! serv_got_update(gc, nick, FALSE, 0, 0, 0, 0); } --- 291,312 ---- g_return_if_fail(b); ! bnet_conn_send(conn, "/where %s\n", nick); ! } ! static void ! bnet_proto_info_fl_removed(BNetConn *conn, GList *args) { ! GList *w = args; ! BNetBuddy *b; ! ! gchar *nick; ! ! gaim_debug_info("bnet", "bnet_proto_info_fl_removed(%s)\n", w->data); ! ! nick = w->data; ! ! b = bnet_buddy_lookup(conn, nick); ! g_return_if_fail(b); ! ! bnet_buddies_remove(conn->buddies, b); } *************** *** 352,361 **** } - /* We receive all the server friend list! - * We must compare our buddy list with it and, if those differ, update - * the server one. - */ - g_hash_table_foreach(conn->buddies, bnet_hash_check_buddy, conn); - conn->fl_listing = FALSE; } --- 376,379 ---- *************** *** 437,440 **** --- 455,460 ---- { "$x: $x, using $x in the game $x.", bnet_proto_info_fl_online }, { "$x: $x, offline", bnet_proto_info_fl_offline }, + { "Added $x to your friends list.", bnet_proto_info_fl_added }, + { "Removed $x from your friends list.", bnet_proto_info_fl_removed }, { "$x is using $x in a private channel.", bnet_proto_info_where }, { "$x is using $x in the channel $x.", bnet_proto_info_where }, Index: buddy.c =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/buddy.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** buddy.c 7 Feb 2005 19:51:46 -0000 1.17 --- buddy.c 2 Mar 2005 22:39:47 -0000 1.18 *************** *** 42,45 **** --- 42,54 ---- } + static void + bnet_hash_buddy_removed(gpointer key, gpointer value, gpointer user_data) { + BNetBuddy *buddy = BNET_BUDDY(value); + guint *pos = user_data; + + if (buddy->fl_position > *pos) + buddy->fl_position -= 1; + } + /****************************************************************************** * User API *************** *** 154,158 **** bnet_buddy_add(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group) { BNetConn *conn = BNET_CONN(gc->proto_data); - BNetBuddy *b; const gchar *norm; --- 163,166 ---- *************** *** 162,175 **** if (!g_hash_table_lookup(conn->buddies, norm)) { ! b = bnet_buddy_new(norm, buddy->name); ! if (conn->welcome) ! b->new_entry = TRUE; ! g_hash_table_insert(conn->buddies, b->norm, b); ! } else { ! /* Buddy already exists in local list, remove it */ gaim_blist_remove_buddy(buddy); } ! bnet_conn_request_friends_list(conn); } --- 170,192 ---- if (!g_hash_table_lookup(conn->buddies, norm)) { ! if (conn->welcome) { ! /* Manually added */ ! bnet_conn_send(conn, "/friends add %s\n", buddy->name); ! } } else { ! /* Buddy already exists, remove it */ gaim_blist_remove_buddy(buddy); } ! } ! ! BNetBuddy * ! bnet_buddy_lookup(BNetConn *conn, const gchar *name) { ! const gchar *norm; ! ! g_return_val_if_fail(conn, NULL); ! g_return_val_if_fail(name, NULL); ! ! norm = gaim_normalize(conn->account, name); ! return g_hash_table_lookup(conn->buddies, norm); } *************** *** 181,186 **** const gchar *norm; - gaim_debug_info("bnet", "bnet_buddy_hard_lookup\n"); - g_return_val_if_fail(conn, NULL); g_return_val_if_fail(name, NULL); --- 198,201 ---- *************** *** 189,205 **** if (!(b = g_hash_table_lookup(conn->buddies, norm))) { ! buddy = gaim_buddy_new(conn->account, name, NULL); ! group = gaim_find_group(BNET_DEFAULT_GROUP_NAME); ! if (!group) { ! group = gaim_group_new(BNET_DEFAULT_GROUP_NAME); ! gaim_blist_add_group(group, NULL); ! } ! gaim_blist_add_buddy(buddy, NULL, group, NULL); ! b = bnet_buddy_new(norm, name); ! b->new_entry = TRUE; ! g_hash_table_insert(conn->buddies, b->norm, b); } --- 204,221 ---- if (!(b = g_hash_table_lookup(conn->buddies, norm))) { ! b = bnet_buddy_new(norm, name); ! bnet_buddies_add(conn->buddies, b); ! if (!(buddy = gaim_find_buddy(conn->account, name))) { ! buddy = gaim_buddy_new(conn->account, name, NULL); ! group = gaim_find_group(BNET_DEFAULT_GROUP_NAME); ! if (!group) { ! group = gaim_group_new(BNET_DEFAULT_GROUP_NAME); ! gaim_blist_add_group(group, NULL); ! } ! gaim_blist_add_buddy(buddy, NULL, group, NULL); ! } } *************** *** 213,218 **** gaim_debug_info("bnet", "bnet_buddy_remove\n"); - g_hash_table_remove(conn->buddies, buddy->name); - bnet_conn_send(conn, "/friends remove %s\n", buddy->name); } --- 229,232 ---- *************** *** 220,225 **** void bnet_buddy_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) { ! if(b->present == GAIM_BUDDY_OFFLINE) ! *se = "offline"; } --- 234,260 ---- void bnet_buddy_emblems(GaimBuddy *b, char **se, char **sw, char **nw, char **ne) { ! BNetConn *conn; ! BNetBuddy *bb; ! ! gchar *emblems[4] = { NULL, NULL, NULL, NULL }; ! guint i = 0; ! ! conn = BNET_CONN(b->account->gc->proto_data); ! bb = bnet_buddy_lookup(conn, b->name); ! ! if (!bb) { ! emblems[i++] = "notauthorized"; ! } else { ! if (b->present == GAIM_BUDDY_OFFLINE) { ! emblems[i++] = "offline"; ! } else { ! // TODO: check for away and others ! } ! } ! ! *se = emblems[0]; ! *sw = emblems[1]; ! *nw = emblems[2]; ! *ne = emblems[3]; } *************** *** 237,246 **** switch (b->present) { case GAIM_BUDDY_SIGNING_OFF: break; case GAIM_BUDDY_OFFLINE: g_string_append_printf(ret, ! "\n<b>%s:</b> Offline", _("Status")); break; case GAIM_BUDDY_ONLINE: if (bb->game) g_string_append_printf(ret, --- 272,289 ---- switch (b->present) { case GAIM_BUDDY_SIGNING_OFF: + g_string_append_printf(ret, + "\n<b>%s</b>: %s", _("Status"), _("Signing Offline")); break; + case GAIM_BUDDY_OFFLINE: g_string_append_printf(ret, ! "\n<b>%s</b>: %s", _("Status"), _("Offline")); break; + + case GAIM_BUDDY_SIGNING_ON: case GAIM_BUDDY_ONLINE: + g_string_append_printf(ret, + "\n<b>%s</b>: %s", _("Status"), _("Online")); + if (bb->game) g_string_append_printf(ret, *************** *** 250,256 **** "\n<b>%s:</b> %s", _("Location"), bb->location); break; - case GAIM_BUDDY_SIGNING_ON: - break; } } --- 293,300 ---- "\n<b>%s:</b> %s", _("Location"), bb->location); break; } + } else { + g_string_append_printf(ret, + "\n<b>%s</b>: %s", _("Status"), _("Not present on server")); } *************** *** 285,286 **** --- 329,344 ---- } + void + bnet_buddies_add(GHashTable *buddies, BNetBuddy *buddy) { + g_hash_table_insert(buddies, buddy->norm, buddy); + } + + void + bnet_buddies_remove(GHashTable *buddies, BNetBuddy *buddy) { + guint pos = buddy->fl_position; + + g_hash_table_remove(buddies, buddy->norm); + + if (pos != -1) + g_hash_table_foreach(buddies, bnet_hash_buddy_removed, &pos); + } Index: buddy.h =================================================================== RCS file: /cvsroot/gaim-bnet/gaim-bnet/src/buddy.h,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** buddy.h 4 Feb 2005 20:31:34 -0000 1.10 --- buddy.h 2 Mar 2005 22:39:47 -0000 1.11 *************** *** 66,69 **** --- 66,70 ---- void bnet_buddy_free(BNetBuddy *buddy); void bnet_buddy_add(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); + BNetBuddy *bnet_buddy_lookup(BNetConn *conn, const gchar *name); BNetBuddy *bnet_buddy_hard_lookup(BNetConn *conn, const gchar *name); void bnet_buddy_remove(GaimConnection *gc, GaimBuddy *buddy, GaimGroup *group); *************** *** 74,77 **** --- 75,80 ---- /* Buddies API */ GHashTable *bnet_buddies_new(); + void bnet_buddies_add(GHashTable *buddies, BNetBuddy *buddy); + void bnet_buddies_remove(GHashTable *buddies, BNetBuddy *buddy); #ifdef __cplusplus |