aboutsummaryrefslogtreecommitdiffstats
path: root/protocols/jabber/presence.c
diff options
context:
space:
mode:
authorWilmer van der Gaast <wilmer@gaast.net>2006-10-09 20:19:05 +0200
committerWilmer van der Gaast <wilmer@gaast.net>2006-10-09 20:19:05 +0200
commit6a1128d1333cf79f1ef9fb1f55b1b8fec67caf2a (patch)
tree7942fe056dfecb513fad0fb106011c890d9588ac /protocols/jabber/presence.c
parent861c199fb60fecf5dab96e0ed9d4b0cf0c57822f (diff)
The module now keeps track of all resources available for a buddy. This
means the buddy won't show up offline when one resource goes down (while there are still others available). It also remembers away state information for every separate resource. Later this system will be used to keep track of client capability information (Typing notices, yay...) and who knows what else.
Diffstat (limited to 'protocols/jabber/presence.c')
-rw-r--r--protocols/jabber/presence.c59
1 files changed, 46 insertions, 13 deletions
diff --git a/protocols/jabber/presence.c b/protocols/jabber/presence.c
index 5bef498d..86bdcb1d 100644
--- a/protocols/jabber/presence.c
+++ b/protocols/jabber/presence.c
@@ -28,26 +28,62 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data )
struct gaim_connection *gc = data;
char *from = xt_find_attr( node, "from" );
char *type = xt_find_attr( node, "type" ); /* NULL should mean the person is online. */
- char *s;
+ struct xt_node *c;
if( !from )
return XT_HANDLED;
- s = strchr( from, '/' );
- if( s )
- *s = 0;
-
- /* Will implement better parsing of away states/msgs when we
- finally do those API changes. Which will probably be after
- merging this module into the main tree. */
if( type == NULL )
- serv_got_update( gc, from, 1, 0, 0, 0, 0, 0 );
+ {
+ struct jabber_buddy *bud;
+
+ if( !( bud = jabber_buddy_by_jid( gc, from ) ) )
+ {
+ bud = jabber_buddy_add( gc, from );
+ }
+
+ g_free( bud->away_message );
+ if( ( c = xt_find_node( node->children, "status" ) ) && c->text_len > 0 )
+ bud->away_message = g_strdup( c->text );
+ else
+ bud->away_message = NULL;
+
+ if( ( c = xt_find_node( node->children, "show" ) ) && c->text_len > 0 )
+ bud->away_state = (void*) jabber_away_state_by_code( c->text );
+ else
+ bud->away_state = NULL;
+
+ if( ( c = xt_find_node( node->children, "priority" ) ) && c->text_len > 0 )
+ bud->priority = atoi( c->text );
+ else
+ bud->priority = 0;
+
+ serv_got_update( gc, bud->handle, 1, 0, 0, 0, 0, 0 );
+ }
else if( strcmp( type, "unavailable" ) == 0 )
- serv_got_update( gc, from, 0, 0, 0, 0, 0, 0 );
+ {
+ char *s;
+
+ jabber_buddy_remove( gc, from );
+
+ if( ( s = strchr( from, '/' ) ) )
+ *s = 0;
+
+ /* Only count this as offline if there's no other resource
+ available anymore. */
+ if( jabber_buddy_by_jid( gc, from ) == NULL )
+ serv_got_update( gc, from, 0, 0, 0, 0, 0, 0 );
+
+ *s = '/';
+ }
else if( strcmp( type, "subscribe" ) == 0 )
+ {
jabber_buddy_ask( gc, from );
+ }
else if( strcmp( type, "subscribed" ) == 0 )
+ {
serv_got_crap( gc, "%s just accepted your authorization request", from );
+ }
else if( strcmp( type, "unsubscribe" ) == 0 || strcmp( type, "unsubscribed" ) == 0 )
{
/* Do nothing here. Plenty of control freaks or over-curious
@@ -69,9 +105,6 @@ xt_status jabber_pkt_presence( struct xt_node *node, gpointer data )
xt_print( node );
}
- if( s )
- *s = '/';
-
return XT_HANDLED;
}