[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; |
---|
[e35d1a1] | 32 | struct jabber_buddy *bud = NULL; |
---|
[1aa74f55] | 33 | char *s, *room = NULL, *reason = NULL; |
---|
[f06894d] | 34 | |
---|
[e35d1a1] | 35 | if( !from ) |
---|
| 36 | return XT_HANDLED; /* Consider this packet corrupted. */ |
---|
| 37 | |
---|
| 38 | bud = jabber_buddy_by_jid( ic, from, GET_BUDDY_EXACT ); |
---|
| 39 | |
---|
[f0071b7] | 40 | if( type && strcmp( type, "error" ) == 0 ) |
---|
| 41 | { |
---|
| 42 | /* Handle type=error packet. */ |
---|
| 43 | } |
---|
[e35d1a1] | 44 | else if( type && from && strcmp( type, "groupchat" ) == 0 ) |
---|
[f0071b7] | 45 | { |
---|
[e35d1a1] | 46 | jabber_chat_pkt_message( ic, bud, node ); |
---|
[f0071b7] | 47 | } |
---|
| 48 | else /* "chat", "normal", "headline", no-type or whatever. Should all be pretty similar. */ |
---|
[dd788bb] | 49 | { |
---|
[f0071b7] | 50 | GString *fullmsg = g_string_new( "" ); |
---|
[5ec4129] | 51 | |
---|
| 52 | for( c = node->children; ( c = xt_find_node( c, "x" ) ); c = c->next ) |
---|
| 53 | { |
---|
[1aa74f55] | 54 | char *ns = xt_find_attr( c, "xmlns" ); |
---|
| 55 | struct xt_node *inv; |
---|
[5ec4129] | 56 | |
---|
[90ba416] | 57 | if( ns && strcmp( ns, XMLNS_MUC_USER ) == 0 && |
---|
[5ec4129] | 58 | ( inv = xt_find_node( c->children, "invite" ) ) ) |
---|
| 59 | { |
---|
[1aa74f55] | 60 | /* This is an invitation. Set some vars which |
---|
| 61 | will be passed to imcb_chat_invite() below. */ |
---|
[5ec4129] | 62 | room = from; |
---|
[daae10f] | 63 | if( ( from = xt_find_attr( inv, "from" ) ) == NULL ) |
---|
| 64 | from = room; |
---|
[1aa74f55] | 65 | if( ( inv = xt_find_node( inv->children, "reason" ) ) && inv->text_len > 0 ) |
---|
| 66 | reason = inv->text; |
---|
[5ec4129] | 67 | } |
---|
| 68 | } |
---|
[dd788bb] | 69 | |
---|
[f0071b7] | 70 | if( ( s = strchr( from, '/' ) ) ) |
---|
[a21a8ac] | 71 | { |
---|
[e35d1a1] | 72 | if( bud ) |
---|
[b9f8b87] | 73 | { |
---|
[76c85b4c] | 74 | bud->last_msg = time( NULL ); |
---|
[daae10f] | 75 | from = bud->ext_jid ? bud->ext_jid : bud->bare_jid; |
---|
[b9f8b87] | 76 | } |
---|
[f0071b7] | 77 | else |
---|
| 78 | *s = 0; /* We need to generate a bare JID now. */ |
---|
[a21a8ac] | 79 | } |
---|
[dd788bb] | 80 | |
---|
[62d0c14] | 81 | if( type && strcmp( type, "headline" ) == 0 ) |
---|
[f0071b7] | 82 | { |
---|
[c4bc92a] | 83 | if( ( c = xt_find_node( node->children, "subject" ) ) && c->text_len > 0 ) |
---|
| 84 | g_string_append_printf( fullmsg, "Headline: %s\n", c->text ); |
---|
[f0071b7] | 85 | |
---|
| 86 | /* <x xmlns="jabber:x:oob"><url>http://....</url></x> can contain a URL, it seems. */ |
---|
| 87 | for( c = node->children; c; c = c->next ) |
---|
| 88 | { |
---|
| 89 | struct xt_node *url; |
---|
| 90 | |
---|
| 91 | if( ( url = xt_find_node( c->children, "url" ) ) && url->text_len > 0 ) |
---|
| 92 | g_string_append_printf( fullmsg, "URL: %s\n", url->text ); |
---|
| 93 | } |
---|
| 94 | } |
---|
[31dbb90a] | 95 | else if( ( c = xt_find_node( node->children, "subject" ) ) && c->text_len > 0 && |
---|
| 96 | ( !bud || !( bud->flags & JBFLAG_HIDE_SUBJECT ) ) ) |
---|
[f0071b7] | 97 | { |
---|
| 98 | g_string_append_printf( fullmsg, "<< \002BitlBee\002 - Message with subject: %s >>\n", c->text ); |
---|
[31dbb90a] | 99 | if( bud ) |
---|
| 100 | bud->flags |= JBFLAG_HIDE_SUBJECT; |
---|
| 101 | } |
---|
| 102 | else if( bud && !c ) |
---|
| 103 | { |
---|
| 104 | /* Yeah, possibly we're hiding changes to this field now. But nobody uses |
---|
| 105 | this for anything useful anyway, except GMail when people reply to an |
---|
| 106 | e-mail via chat, repeating the same subject all the time. I don't want |
---|
| 107 | to have to remember full subject strings for everyone. */ |
---|
| 108 | bud->flags &= ~JBFLAG_HIDE_SUBJECT; |
---|
[f0071b7] | 109 | } |
---|
| 110 | |
---|
| 111 | if( body && body->text_len > 0 ) /* Could be just a typing notification. */ |
---|
| 112 | fullmsg = g_string_append( fullmsg, body->text ); |
---|
[dd788bb] | 113 | |
---|
[f0071b7] | 114 | if( fullmsg->len > 0 ) |
---|
[b9f8b87] | 115 | imcb_buddy_msg( ic, from, fullmsg->str, |
---|
[43671b9] | 116 | 0, jabber_get_timestamp( node ) ); |
---|
[1aa74f55] | 117 | if( room ) |
---|
| 118 | imcb_chat_invite( ic, room, from, reason ); |
---|
[f0071b7] | 119 | |
---|
| 120 | g_string_free( fullmsg, TRUE ); |
---|
[a21a8ac] | 121 | |
---|
[788a1af] | 122 | /* Handling of incoming typing notifications. */ |
---|
[82135c7] | 123 | if( bud == NULL ) |
---|
| 124 | { |
---|
| 125 | /* Can't handle these for unknown buddies. */ |
---|
| 126 | } |
---|
| 127 | else if( xt_find_node( node->children, "composing" ) ) |
---|
[a21a8ac] | 128 | { |
---|
[788a1af] | 129 | bud->flags |= JBFLAG_DOES_XEP85; |
---|
[b9f8b87] | 130 | imcb_buddy_typing( ic, from, OPT_TYPING ); |
---|
[a21a8ac] | 131 | } |
---|
[788a1af] | 132 | /* No need to send a "stopped typing" signal when there's a message. */ |
---|
| 133 | else if( xt_find_node( node->children, "active" ) && ( body == NULL ) ) |
---|
[a21a8ac] | 134 | { |
---|
[788a1af] | 135 | bud->flags |= JBFLAG_DOES_XEP85; |
---|
[b9f8b87] | 136 | imcb_buddy_typing( ic, from, 0 ); |
---|
[a21a8ac] | 137 | } |
---|
[788a1af] | 138 | else if( xt_find_node( node->children, "paused" ) ) |
---|
| 139 | { |
---|
| 140 | bud->flags |= JBFLAG_DOES_XEP85; |
---|
[b9f8b87] | 141 | imcb_buddy_typing( ic, from, OPT_THINKING ); |
---|
[788a1af] | 142 | } |
---|
| 143 | |
---|
| 144 | if( s ) |
---|
| 145 | *s = '/'; /* And convert it back to a full JID. */ |
---|
[dd788bb] | 146 | } |
---|
[f06894d] | 147 | |
---|
| 148 | return XT_HANDLED; |
---|
| 149 | } |
---|