source: protocols/jabber/presence.c @ 36e9f62

Last change on this file since 36e9f62 was 36e9f62, checked in by Wilmer van der Gaast <wilmer@…>, at 2006-10-07T17:46:28Z

Added SRV lookups to automatically find out the correct server for a
domain.

  • Property mode set to 100644
File size: 4.3 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        /* Will implement better parsing of away states/msgs when we
41           finally do those API changes. Which will probably be after
42           merging this module into the main tree. */
43        if( type == NULL )
44                serv_got_update( gc, from, 1, 0, 0, 0, 0, 0 );
45        else if( strcmp( type, "unavailable" ) == 0 )
46                serv_got_update( gc, from, 0, 0, 0, 0, 0, 0 );
47        else if( strcmp( type, "subscribe" ) == 0 )
48                jabber_buddy_ask( gc, from );
49        else if( strcmp( type, "subscribed" ) == 0 )
50                serv_got_crap( gc, "%s just accepted your authorization request", from );
51        else if( strcmp( type, "unsubscribe" ) == 0 || strcmp( type, "unsubscribed" ) == 0 )
52        {
53                /* Do nothing here. Plenty of control freaks or over-curious
54                   souls get excited when they can see who still has them in
55                   their buddy list and who finally removed them. Somehow I
56                   got the impression that those are the people who get
57                   removed from many buddy lists for "some" reason...
58                   
59                   If you're one of those people, this is your chance to write
60                   your first line of code in C... */
61        }
62        else if( strcmp( type, "error" ) == 0 )
63        {
64                /* What to do with it? */
65        }
66        else
67        {
68                printf( "Received PRES from %s:\n", from );
69                xt_print( node );
70        }
71       
72        if( s )
73                *s = '/';
74       
75        return XT_HANDLED;
76}
77
78/* Whenever presence information is updated, call this function to inform the
79   server. */
80int presence_send_update( struct gaim_connection *gc )
81{
82        struct jabber_data *jd = gc->proto_data;
83        struct xt_node *node;
84        char *show = jd->away_state->code;
85        char *status = jd->away_message;
86        int st;
87       
88        node = jabber_make_packet( "presence", NULL, NULL, NULL );
89        xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) );
90        if( show && *show )
91                xt_add_child( node, xt_new_node( "show", show, NULL ) );
92        if( status )
93                xt_add_child( node, xt_new_node( "status", status, NULL ) );
94       
95        st = jabber_write_packet( gc, node );
96       
97        xt_free_node( node );
98        return st;
99}
100
101/* Send a subscribe/unsubscribe request to a buddy. */
102int presence_send_request( struct gaim_connection *gc, char *handle, char *request )
103{
104        struct xt_node *node;
105        int st;
106       
107        node = jabber_make_packet( "presence", NULL, NULL, NULL );
108        xt_add_attr( node, "to", handle );
109        xt_add_attr( node, "type", request );
110       
111        st = jabber_write_packet( gc, node );
112       
113        xt_free_node( node );
114        return st;
115}
Note: See TracBrowser for help on using the repository browser.