source: protocols/jabber/presence.c @ 6266fca

Last change on this file since 6266fca was 6266fca, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-10-02T18:32:21Z

Fixed memory leak in jabber_buddy_ask() and added "handling" of type="error"
<presence/> tags.

  • Property mode set to 100644
File size: 4.2 KB
Line 
1/***************************************************************************\
2*                                                                           *
3*  BitlBee - An IRC to IM gateway                                           *
4*  Jabber module - Handling of presence (tags), etc                         *
5*                                                                           *
6*  Copyright 2006 Wilmer van der Gaast <wilmer@gaast.net>                   *
7*                                                                           *
8*  This program is free software; you can redistribute it and/or modify     *
9*  it under the terms of the GNU General Public License as published by     *
10*  the Free Software Foundation; either version 2 of the License, or        *
11*  (at your option) any later version.                                      *
12*                                                                           *
13*  This program is distributed in the hope that it will be useful,          *
14*  but WITHOUT ANY WARRANTY; without even the implied warranty of           *
15*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the            *
16*  GNU General Public License for more details.                             *
17*                                                                           *
18*  You should have received a copy of the GNU General Public License along  *
19*  with this program; if not, write to the Free Software Foundation, Inc.,  *
20*  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.              *
21*                                                                           *
22\***************************************************************************/
23
24#include "jabber.h"
25
26xt_status jabber_pkt_presence( struct xt_node *node, gpointer data )
27{
28        struct gaim_connection *gc = data;
29        char *from = xt_find_attr( node, "from" );
30        char *type = xt_find_attr( node, "type" );      /* NULL should mean the person is online. */
31        char *s;
32       
33        if( !from )
34                return XT_HANDLED;
35       
36        s = strchr( from, '/' );
37        if( s )
38                *s = 0;
39       
40        if( type == NULL )
41                serv_got_update( gc, from, 1, 0, 0, 0, 0, 0 );
42        else if( strcmp( type, "unavailable" ) == 0 )
43                serv_got_update( gc, from, 0, 0, 0, 0, 0, 0 );
44        else if( strcmp( type, "subscribe" ) == 0 )
45                jabber_buddy_ask( gc, from );
46        else if( strcmp( type, "subscribed" ) == 0 )
47                serv_got_crap( gc, "%s just accepted your authorization request", from );
48        else if( strcmp( type, "unsubscribe" ) == 0 || strcmp( type, "unsubscribed" ) == 0 )
49        {
50                /* Do nothing here. Plenty of control freaks or over-curious
51                   souls get excited when they can see who still has them in
52                   their buddy list and who finally removed them. Somehow I
53                   got the impression that those are the people who get
54                   removed from many buddy lists for "some" reason...
55                   
56                   If you're one of those people, this is your chance to write
57                   your first line of code in C... */
58        }
59        else if( strcmp( type, "error" ) == 0 )
60        {
61                /* What to do with it? */
62        }
63        else
64        {
65                printf( "Received PRES from %s:\n", from );
66                xt_print( node );
67        }
68       
69        if( s )
70                *s = '/';
71       
72        return XT_HANDLED;
73}
74
75/* Whenever presence information is updated, call this function to inform the
76   server. */
77int presence_send_update( struct gaim_connection *gc )
78{
79        struct jabber_data *jd = gc->proto_data;
80        struct xt_node *node;
81        char *show = jd->away_state->code;
82        char *status = jd->away_message;
83        int st;
84       
85        node = jabber_make_packet( "presence", NULL, NULL, NULL );
86        if( show && *show )
87                xt_add_child( node, xt_new_node( "show", show, NULL ) );
88        if( status )
89                xt_add_child( node, xt_new_node( "status", status, NULL ) );
90        /* if( set_getint( &gc->acc->set, "priority" ) != 0 ) */
91        /* Let's just send this every time... */
92                xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) );
93       
94        st = jabber_write_packet( gc, node );
95       
96        xt_free_node( node );
97        return st;
98}
99
100/* Send a subscribe/unsubscribe request to a buddy. */
101int presence_send_request( struct gaim_connection *gc, char *handle, char *request )
102{
103        struct xt_node *node;
104        int st;
105       
106        node = jabber_make_packet( "presence", NULL, NULL, NULL );
107        xt_add_attr( node, "to", handle );
108        xt_add_attr( node, "type", request );
109       
110        st = jabber_write_packet( gc, node );
111       
112        xt_free_node( node );
113        return st;
114}
Note: See TracBrowser for help on using the repository browser.