--- a/mcabber/src/hooks.c Thu Dec 15 00:14:56 2005 +0100
+++ b/mcabber/src/hooks.c Thu Dec 15 12:52:37 2005 +0100
@@ -67,7 +67,7 @@
roster_usr = roster_find(jid, jidsearch, 0);
if (!roster_usr) {
new_guy = TRUE;
- roster_usr = roster_add_user(jid, NULL, NULL, rtype);
+ roster_usr = roster_add_user(jid, NULL, NULL, rtype, sub_none);
if (!roster_usr) { // Shouldn't happen...
scr_LogPrint(LPRINT_LOGNORM, "ERROR: unable to add buddy!");
if (bmsg) g_free(bmsg);
--- a/mcabber/src/jab_iq.c Thu Dec 15 00:14:56 2005 +0100
+++ b/mcabber/src/jab_iq.c Thu Dec 15 12:52:37 2005 +0100
@@ -21,11 +21,13 @@
* USA
*/
+#include <glib.h>
+
#include "jabglue.h"
#include "jab_priv.h"
#include "roster.h"
#include "utils.h"
-#include "logprint.h"
+#include "screen.h"
int s_id; // XXX
@@ -47,9 +49,11 @@
static void gotroster(xmlnode x)
{
xmlnode y;
- const char *jid, *name, *group;
+ const char *jid, *name, *group, *sub;
char *buddyname;
char *cleanalias;
+ enum subscr esub;
+ int need_refresh = FALSE;
for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
gchar *name_noutf8 = NULL;
@@ -57,7 +61,7 @@
jid = xmlnode_get_attrib(y, "jid");
name = xmlnode_get_attrib(y, "name");
- //sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used
+ sub = xmlnode_get_attrib(y, "subscription");
group = xmlnode_get_tag_data(y, "group");
@@ -66,6 +70,23 @@
buddyname = cleanalias = jidtodisp(jid);
+ esub = sub_none;
+ if (sub) {
+ if (!strcmp(sub, "to")) esub = sub_to;
+ else if (!strcmp(sub, "from")) esub = sub_from;
+ else if (!strcmp(sub, "both")) esub = sub_both;
+ else if (!strcmp(sub, "remove")) esub = sub_remove;
+ }
+
+ if (esub == sub_remove) {
+ roster_del_user(cleanalias);
+ scr_LogPrint(LPRINT_LOGNORM, "Buddy <%s> has been removed "
+ "from the roster", cleanalias);
+ g_free(cleanalias);
+ need_refresh = TRUE;
+ continue;
+ }
+
if (name) {
name_noutf8 = from_utf8(name);
if (name_noutf8)
@@ -82,15 +103,18 @@
group);
}
- roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER);
+ roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER,
+ esub);
+
if (name_noutf8) g_free(name_noutf8);
if (group_noutf8) g_free(group_noutf8);
g_free(cleanalias);
}
- // Post-login stuff
- jb_setstatus(available, NULL, NULL);
buddylist_build();
+ update_roster = TRUE;
+ if (need_refresh)
+ scr_ShowBuddyWindow();
}
static void gotagents(jconn conn, xmlnode x)
@@ -120,7 +144,7 @@
if (atype == transport) {
char *cleanjid = jidtodisp(alias);
roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP,
- ROSTER_TYPE_AGENT);
+ ROSTER_TYPE_AGENT, sub_none);
g_free(cleanjid);
}
if (alias && name && desc) {
@@ -193,6 +217,9 @@
if (!strcmp(ns, NS_ROSTER)) {
gotroster(x);
+
+ // Post-login stuff FIXME shouldn't be there
+ jb_setstatus(available, NULL, NULL);
} else if (!strcmp(ns, NS_AGENTS)) {
gotagents(conn, x);
} else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
--- a/mcabber/src/jabglue.c Thu Dec 15 00:14:56 2005 +0100
+++ b/mcabber/src/jabglue.c Thu Dec 15 12:52:37 2005 +0100
@@ -450,7 +450,7 @@
jab_send(jc, x);
xmlnode_free(x);
- roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER);
+ roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending);
g_free(cleanjid);
buddylist_build();
@@ -883,7 +883,7 @@
room_elt = roster_find(roomjid, jidsearch, 0);
if (!room_elt) {
// Add room if it doesn't already exist
- room_elt = roster_add_user(roomjid, NULL, NULL, ROSTER_TYPE_ROOM);
+ room_elt = roster_add_user(roomjid, NULL, NULL, ROSTER_TYPE_ROOM, sub_none);
} else {
// Make sure this is a room (it can be a conversion user->room)
buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
@@ -1227,19 +1227,15 @@
{
xmlnode x;
- scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet "
- "(type=%s)", ((type) ? type : ""));
-
if (!strcmp(type, "subscribe")) {
char *r;
int isagent;
r = jidtodisp(from);
isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0;
g_free(r);
- //scr_LogPrint(LPRINT_LOGNORM, "isagent=%d", isagent); // XXX DBG
+ scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe "
+ "to your network presence updates", from);
if (!isagent) {
- scr_LogPrint(LPRINT_LOGNORM, "<%s> wants to subscribe "
- "to your network presence updates", from);
// FIXME we accept everybody...
x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0);
jab_send(jc, x);
@@ -1255,6 +1251,16 @@
xmlnode_free(x);
scr_LogPrint(LPRINT_LOGNORM, "<%s> has unsubscribed to "
"your presence updates", from);
+ } else if (!strcmp(type, "subscribed")) {
+ scr_LogPrint(LPRINT_LOGNORM, "<%s> has subscribed to your presence "
+ "updates", from);
+ } else if (!strcmp(type, "unsubscribed")) {
+ scr_LogPrint(LPRINT_LOGNORM, "<%s> has unsubscribed from your presence "
+ "updates", from);
+ } else {
+ scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet from <%s>"
+ " (type=%s)", from, (type ? type : ""));
+
}
}
--- a/mcabber/src/roster.c Thu Dec 15 00:14:56 2005 +0100
+++ b/mcabber/src/roster.c Thu Dec 15 12:52:37 2005 +0100
@@ -259,7 +259,7 @@
// Returns a pointer to the new user, or existing user with that name
GSList *roster_add_user(const char *jid, const char *name, const char *group,
- guint type)
+ guint type, enum subscr esub)
{
roster *roster_usr;
roster *my_group;
@@ -294,8 +294,9 @@
roster_usr->name = g_strdup(str);
g_free(str);
}
- roster_usr->type = type;
- roster_usr->list = slist; // (my_group SList element)
+ roster_usr->type = type;
+ roster_usr->subscription = esub;
+ roster_usr->list = slist; // (my_group SList element)
// #4 Insert node (sorted)
my_group->list = g_slist_insert_sorted(my_group->list, roster_usr,
(GCompareFunc)&roster_compare_name);
@@ -402,7 +403,7 @@
ROSTER_TYPE_USER|ROSTER_TYPE_ROOM|ROSTER_TYPE_AGENT);
// If we can't find it, we add it
if (sl_user == NULL)
- sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER);
+ sl_user = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_USER, sub_none);
// If there is no resource name, we can leave now
if (!resname) return;
@@ -728,8 +729,8 @@
*sl_group = g_slist_remove(*sl_group, rosterdata);
// Add the buddy to its new group; actually we "clone" this buddy...
- sl_clone = roster_add_user(roster_usr->jid, roster_usr->name,
- newgroupname, roster_usr->type);
+ sl_clone = roster_add_user(roster_usr->jid, roster_usr->name, newgroupname,
+ roster_usr->type, roster_usr->subscription);
roster_clone = (roster*)sl_clone->data;
roster_clone->subscription = roster_usr->subscription;
roster_clone->flags = roster_usr->flags;
@@ -876,6 +877,12 @@
return roster_usr->type;
}
+guint buddy_getsubscription(gpointer rosterdata)
+{
+ roster *roster_usr = rosterdata;
+ return roster_usr->subscription;
+}
+
enum imstatus buddy_getstatus(gpointer rosterdata, const char *resname)
{
roster *roster_usr = rosterdata;
--- a/mcabber/src/roster.h Thu Dec 15 00:14:56 2005 +0100
+++ b/mcabber/src/roster.h Thu Dec 15 12:52:37 2005 +0100
@@ -36,10 +36,12 @@
extern char *straffil[]; // Should match enum above
enum subscr {
- sub_none,
- sub_to,
- sub_from,
- sub_both
+ sub_none = 0,
+ sub_pending = 1,
+ sub_to = 1 << 2,
+ sub_from = 1 << 3,
+ sub_both = sub_to|sub_from,
+ sub_remove = 1 << 4
};
enum findwhat {
@@ -79,7 +81,7 @@
// Prototypes...
GSList *roster_add_group(const char *name);
GSList *roster_add_user(const char *jid, const char *name, const char *group,
- guint type);
+ guint type, enum subscr esub);
GSList *roster_find(const char *jidname, enum findwhat type, guint roster_type);
void roster_del_user(const char *jid);
void roster_free(void);
@@ -108,6 +110,7 @@
const char *buddy_gettopic(gpointer rosterdata);
void buddy_settype(gpointer rosterdata, guint type);
guint buddy_gettype(gpointer rosterdata);
+guint buddy_getsubscription(gpointer rosterdata);
void buddy_setgroup(gpointer rosterdata, char *newgroupname);
const char *buddy_getgroupname(gpointer rosterdata);
gpointer buddy_getgroup(gpointer rosterdata);
--- a/mcabber/src/screen.c Thu Dec 15 00:14:56 2005 +0100
+++ b/mcabber/src/screen.c Thu Dec 15 12:52:37 2005 +0100
@@ -978,7 +978,8 @@
ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM);
// Create it if necessary
if (!roster_elt)
- roster_elt = roster_add_user(barejid, NULL, NULL, ROSTER_TYPE_USER);
+ roster_elt = roster_add_user(barejid, NULL, NULL, ROSTER_TYPE_USER,
+ sub_none);
// Set a lock to see it in the buddylist
buddy_setflags(BUDDATA(roster_elt), ROSTER_FLAG_LOCK, TRUE);
buddylist_build();