[f06894d] | 1 | /***************************************************************************\ |
---|
| 2 | * * |
---|
| 3 | * BitlBee - An IRC to IM gateway * |
---|
[21167d2] | 4 | * Jabber module - Handling of message(s) (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_message( struct xt_node *node, gpointer data ) |
---|
| 27 | { |
---|
[0da65d5] | 28 | struct im_connection *ic = data; |
---|
[f06894d] | 29 | char *from = xt_find_attr( node, "from" ); |
---|
[dd788bb] | 30 | char *type = xt_find_attr( node, "type" ); |
---|
[f0071b7] | 31 | struct xt_node *body = xt_find_node( node->children, "body" ), *c; |
---|
[788a1af] | 32 | char *s; |
---|
[f06894d] | 33 | |
---|
[f0071b7] | 34 | if( type && strcmp( type, "error" ) == 0 ) |
---|
| 35 | { |
---|
| 36 | /* Handle type=error packet. */ |
---|
| 37 | } |
---|
| 38 | else if( type && strcmp( type, "groupchat" ) == 0 ) |
---|
| 39 | { |
---|
| 40 | /* TODO! */ |
---|
| 41 | } |
---|
| 42 | else /* "chat", "normal", "headline", no-type or whatever. Should all be pretty similar. */ |
---|
[dd788bb] | 43 | { |
---|
[a21a8ac] | 44 | struct jabber_buddy *bud = NULL; |
---|
[f0071b7] | 45 | GString *fullmsg = g_string_new( "" ); |
---|
[dd788bb] | 46 | |
---|
[f0071b7] | 47 | if( ( s = strchr( from, '/' ) ) ) |
---|
[a21a8ac] | 48 | { |
---|
[0da65d5] | 49 | if( ( bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ) ) ) |
---|
[f0071b7] | 50 | bud->last_act = time( NULL ); |
---|
| 51 | else |
---|
| 52 | *s = 0; /* We need to generate a bare JID now. */ |
---|
[a21a8ac] | 53 | } |
---|
[dd788bb] | 54 | |
---|
[62d0c14] | 55 | if( type && strcmp( type, "headline" ) == 0 ) |
---|
[f0071b7] | 56 | { |
---|
| 57 | c = xt_find_node( node->children, "subject" ); |
---|
| 58 | g_string_append_printf( fullmsg, "Headline: %s\n", c && c->text_len > 0 ? c->text : "" ); |
---|
| 59 | |
---|
| 60 | /* <x xmlns="jabber:x:oob"><url>http://....</url></x> can contain a URL, it seems. */ |
---|
| 61 | for( c = node->children; c; c = c->next ) |
---|
| 62 | { |
---|
| 63 | struct xt_node *url; |
---|
| 64 | |
---|
| 65 | if( ( url = xt_find_node( c->children, "url" ) ) && url->text_len > 0 ) |
---|
| 66 | g_string_append_printf( fullmsg, "URL: %s\n", url->text ); |
---|
| 67 | } |
---|
| 68 | } |
---|
| 69 | else if( ( c = xt_find_node( node->children, "subject" ) ) && c->text_len > 0 ) |
---|
| 70 | { |
---|
| 71 | g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Message with subject: %s >>\n", c->text ); |
---|
| 72 | } |
---|
| 73 | |
---|
| 74 | if( body && body->text_len > 0 ) /* Could be just a typing notification. */ |
---|
| 75 | fullmsg = g_string_append( fullmsg, body->text ); |
---|
[dd788bb] | 76 | |
---|
[f0071b7] | 77 | if( fullmsg->len > 0 ) |
---|
[9624fdf] | 78 | imcb_buddy_msg( ic, bud ? bud->bare_jid : from, fullmsg->str, 0, 0 ); |
---|
[f0071b7] | 79 | |
---|
| 80 | g_string_free( fullmsg, TRUE ); |
---|
[a21a8ac] | 81 | |
---|
[788a1af] | 82 | /* Handling of incoming typing notifications. */ |
---|
[a21a8ac] | 83 | if( xt_find_node( node->children, "composing" ) ) |
---|
| 84 | { |
---|
[788a1af] | 85 | bud->flags |= JBFLAG_DOES_XEP85; |
---|
[9624fdf] | 86 | imcb_buddy_typing( ic, bud ? bud->bare_jid : from, OPT_TYPING ); |
---|
[a21a8ac] | 87 | } |
---|
[788a1af] | 88 | /* No need to send a "stopped typing" signal when there's a message. */ |
---|
| 89 | else if( xt_find_node( node->children, "active" ) && ( body == NULL ) ) |
---|
[a21a8ac] | 90 | { |
---|
[788a1af] | 91 | bud->flags |= JBFLAG_DOES_XEP85; |
---|
[9624fdf] | 92 | imcb_buddy_typing( ic, bud ? bud->bare_jid : from, 0 ); |
---|
[a21a8ac] | 93 | } |
---|
[788a1af] | 94 | else if( xt_find_node( node->children, "paused" ) ) |
---|
| 95 | { |
---|
| 96 | bud->flags |= JBFLAG_DOES_XEP85; |
---|
[9624fdf] | 97 | imcb_buddy_typing( ic, bud ? bud->bare_jid : from, OPT_THINKING ); |
---|
[788a1af] | 98 | } |
---|
| 99 | |
---|
| 100 | if( s ) |
---|
| 101 | *s = '/'; /* And convert it back to a full JID. */ |
---|
[dd788bb] | 102 | } |
---|
[f06894d] | 103 | |
---|
| 104 | return XT_HANDLED; |
---|
| 105 | } |
---|