[f06894d] | 1 | /***************************************************************************\ |
---|
| 2 | * * |
---|
| 3 | * BitlBee - An IRC to IM gateway * |
---|
[21167d2] | 4 | * Jabber module - Handling of presence (tags), etc * |
---|
[f06894d] | 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 | |
---|
| 26 | xt_status jabber_pkt_presence( struct xt_node *node, gpointer data ) |
---|
| 27 | { |
---|
[4a0614e] | 28 | struct gaim_connection *gc = data; |
---|
[f06894d] | 29 | char *from = xt_find_attr( node, "from" ); |
---|
[4a0614e] | 30 | char *type = xt_find_attr( node, "type" ); /* NULL should mean the person is online. */ |
---|
| 31 | char *s; |
---|
[f06894d] | 32 | |
---|
[4a0614e] | 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 |
---|
| 45 | { |
---|
| 46 | printf( "Received PRES from %s:\n", from ); |
---|
| 47 | xt_print( node ); |
---|
| 48 | } |
---|
| 49 | |
---|
| 50 | if( s ) |
---|
| 51 | *s = '/'; |
---|
[f06894d] | 52 | |
---|
| 53 | return XT_HANDLED; |
---|
| 54 | } |
---|
| 55 | |
---|
[172a73f1] | 56 | /* Whenever presence information is updated, call this function to inform the |
---|
| 57 | server. */ |
---|
| 58 | int presence_send_update( struct gaim_connection *gc ) |
---|
[deff040] | 59 | { |
---|
[172a73f1] | 60 | struct jabber_data *jd = gc->proto_data; |
---|
[deff040] | 61 | struct xt_node *node; |
---|
[172a73f1] | 62 | char *show = jd->away_state->code; |
---|
| 63 | char *status = jd->away_message; |
---|
[deff040] | 64 | int st; |
---|
| 65 | |
---|
[172a73f1] | 66 | node = jabber_make_packet( "presence", NULL, NULL, NULL ); |
---|
[5e202b0] | 67 | if( show && *show ) |
---|
[deff040] | 68 | xt_add_child( node, xt_new_node( "show", show, NULL ) ); |
---|
| 69 | if( status ) |
---|
| 70 | xt_add_child( node, xt_new_node( "status", status, NULL ) ); |
---|
[172a73f1] | 71 | /* if( set_getint( &gc->acc->set, "priority" ) != 0 ) */ |
---|
| 72 | /* Let's just send this every time... */ |
---|
| 73 | xt_add_child( node, xt_new_node( "priority", set_getstr( &gc->acc->set, "priority" ), NULL ) ); |
---|
[deff040] | 74 | |
---|
| 75 | st = jabber_write_packet( gc, node ); |
---|
| 76 | |
---|
| 77 | xt_free_node( node ); |
---|
| 78 | return st; |
---|
| 79 | } |
---|
[cfbb3a6] | 80 | |
---|
| 81 | /* Send a subscribe/unsubscribe request to a buddy. */ |
---|
| 82 | int presence_send_request( struct gaim_connection *gc, char *handle, char *request ) |
---|
| 83 | { |
---|
| 84 | struct xt_node *node; |
---|
| 85 | int st; |
---|
| 86 | |
---|
| 87 | node = jabber_make_packet( "presence", NULL, NULL, NULL ); |
---|
| 88 | xt_add_attr( node, "to", handle ); |
---|
| 89 | xt_add_attr( node, "type", request ); |
---|
| 90 | |
---|
| 91 | st = jabber_write_packet( gc, node ); |
---|
| 92 | |
---|
| 93 | xt_free_node( node ); |
---|
| 94 | return st; |
---|
| 95 | } |
---|