~ubuntu-branches/ubuntu/jaunty/irssi-plugin-xmpp/jaunty

« back to all changes in this revision

Viewing changes to src/core/xmpp-protocol.c

  • Committer: Bazaar Package Importer
  • Author(s): David Ammouial
  • Date: 2008-06-23 16:03:33 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 lenny)
  • Revision ID: james.westby@ubuntu.com-20080623160333-3wwbzgtzwznjjvrf
Tags: 0.13+cvs20080610-1
* New CVS snapshot:
  - New features and bugfixes.
  - Fix ignoring of messages without a type attribute (Closes: #477989).
* Depend on irssi >=0.8.12 (Closes: #469923).
* Add FAQ and MUC to documentation files (Closes: #485595).
* debian/rules: install help files in irssi help directory.
* debian/rules: Remove useless "make -n" command in build-stamp rule.
* Bump Standards-Version to 3.8.0 (no changes needed). 
* debian/control: Add "Enhances: irssi".

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * $Id: xmpp-protocol.c,v 1.46 2008/01/07 07:29:13 errtu Exp $
 
2
 * $Id: xmpp-protocol.c,v 1.55 2008/04/26 11:01:11 errtu Exp $
3
3
 *
4
4
 * Copyright (C) 2007 Colin DIDIER
5
5
 *
6
6
 * This program is free software; you can redistribute it and/or modify
7
 
 * it under the terms of the GNU General Public License as published by
8
 
 * the Free Software Foundation; either version 2 of the License, or
9
 
 * (at your option) any later version.
 
7
 * it under the terms of the GNU General Public License version 2 as
 
8
 * published by the Free Software Foundation.
10
9
 *
11
10
 * This program is distributed in the hope that it will be useful,
12
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
42
41
{
43
42
        LmMessage *msg;
44
43
        LmMessageNode *child;
45
 
        XMPP_ROSTER_USER_REC *user;
46
44
        XMPP_ROSTER_RESOURCE_REC *resource;
47
 
        char *jid, *res, *jid_recoded, *message_recoded;
 
45
        char *jid, *jid_recoded, *message_recoded;
48
46
 
49
47
        g_return_if_fail(IS_XMPP_SERVER(server));
50
48
        g_return_if_fail(dest != NULL);
61
59
        lm_message_node_add_child(msg->node, "body", message_recoded);
62
60
        g_free(message_recoded);
63
61
 
64
 
        if (jid == NULL || !xmpp_have_resource(jid))
65
 
                goto send;
66
 
 
67
 
        user = xmpp_rosters_find_user(server->roster, jid, NULL);
68
 
        if (user == NULL)
69
 
                goto send;
70
 
 
71
 
        res = xmpp_strip_resource(jid);
72
 
        resource = xmpp_rosters_find_resource(user, res);
73
 
        if (resource == NULL)
74
 
                goto send;
75
 
        g_free(res);
76
 
        
77
 
        /* stop composing */
78
 
        if (resource->composing_id != NULL) {
 
62
        xmpp_rosters_find_user(server->roster, jid, NULL, &resource);
 
63
        if (resource != NULL && resource->composing_id != NULL) {
79
64
                child = lm_message_node_add_child(msg->node, "x", NULL);
80
65
                lm_message_node_set_attribute(child, XMLNS, XMLNS_EVENT);
81
66
                lm_message_node_add_child(child, "id", resource->composing_id);
82
67
                g_free_and_null(resource->composing_id);
83
68
        }
84
69
 
85
 
send:
86
70
        lm_send(server, msg, NULL);
87
71
        lm_message_unref(msg);
88
72
 
330
314
 
331
315
                break;
332
316
 
 
317
        case LM_MESSAGE_SUB_TYPE_NOT_SET:
 
318
                if ((child = lm_tools_message_node_find(msg->node,
 
319
                    "x", XMLNS, XMLNS_MUC)) != NULL) {
 
320
 
 
321
                        /* invite */
 
322
                        if ((child = lm_message_node_get_child(child,
 
323
                            "invite")) != NULL) {
 
324
                                char *room, *by, *password, *reason;
 
325
                                const char *to;
 
326
 
 
327
                                room = by = NULL;
 
328
 
 
329
                                subchild = lm_message_node_get_child(
 
330
                                    child->parent, "password");
 
331
                                password = subchild == NULL ? NULL :
 
332
                                    xmpp_recode_in(subchild->value);
 
333
 
 
334
                                subchild = lm_message_node_get_child(
 
335
                                    child, "reason");
 
336
                                reason = subchild == NULL ? NULL :
 
337
                                    xmpp_recode_in(subchild->value);
 
338
 
 
339
                                to = lm_message_node_get_attribute(child,
 
340
                                     "to");
 
341
                                if (to != NULL) {
 
342
                                        room = xmpp_recode_in(to);
 
343
                                        signal_emit("xmpp invite", 5, server,
 
344
                                            room, jid, password, reason);
 
345
                                        g_free(room);
 
346
                                }
 
347
 
 
348
                                g_free(reason); 
 
349
                                g_free(password);
 
350
                        }
 
351
                }
 
352
 
333
353
        case LM_MESSAGE_SUB_TYPE_HEADLINE:
334
354
        case LM_MESSAGE_SUB_TYPE_NORMAL:
335
355
        case LM_MESSAGE_SUB_TYPE_CHAT:
 
356
        /* rfc3921.txt states in 2.1.1. Types of Message:
 
357
         *   if an application receives a message with no 'type' attribute or the
 
358
         *   application does not understand the value of the 'type' attribute
 
359
         *   provided, it MUST consider the message to be of type "normal"
 
360
         * Thus default belongs here, whre LM_MESSAGE_SUB_TYPE_NORMAL is
 
361
         */
 
362
        default:
336
363
                /* XEP-0022: Message Events */
337
364
                child = lm_message_node_get_child(msg->node, "x");
338
365
                if (child != NULL) {
388
415
                                            GINT_TO_POINTER(SEND_TARGET_NICK));
389
416
                        } else {
390
417
                                if (g_ascii_strncasecmp(text, "/me ", 4) == 0)
391
 
                                        signal_emit("message xmpp action", 5, server,
392
 
                                            text+4, jid, jid,
 
418
                                        signal_emit("message xmpp action", 5,
 
419
                                            server, text+4, jid, jid,
393
420
                                            GINT_TO_POINTER(SEND_TARGET_NICK));
394
421
                                else
395
422
                                        signal_emit("message private", 4, server,
433
460
                if (child != NULL && child->value != NULL) {
434
461
                        XMPP_CHANNEL_REC *channel;
435
462
                        char *channel_name, *nick;
 
463
                        gboolean own, action;
436
464
 
437
465
                        channel_name = xmpp_extract_channel(jid);
438
466
                        nick =  xmpp_extract_resource(jid);
 
467
                        if (nick == NULL) {
 
468
                                g_free(channel_name);
 
469
                                goto out;
 
470
                        }
 
471
 
 
472
                        channel = xmpp_channel_find(server, channel_name);
 
473
                        own = channel != NULL
 
474
                            && strcmp(nick, channel->nick) == 0 ? TRUE : FALSE;
 
475
 
 
476
                        text = xmpp_recode_in(child->value);
 
477
                        action = g_ascii_strncasecmp(text, "/me ", 4) == 0 ?
 
478
                            TRUE : FALSE;
439
479
                        stamp = get_timestamp(msg->node);
440
480
 
441
 
                        /* it's my own message, so ignore it */
442
 
                        channel = xmpp_channel_find(server, channel_name);
443
 
                        if (stamp == NULL && (channel == NULL
444
 
                            || nick == NULL || (channel != NULL
445
 
                            && strcmp(nick, channel->nick) == 0))) {
446
 
                                g_free(channel_name);
447
 
                                g_free(nick);
448
 
                                goto out;
449
 
                        }
450
 
 
451
 
                        text = xmpp_recode_in(child->value);
452
 
 
453
481
                        if (stamp != NULL) {
454
 
                                if (g_ascii_strncasecmp(text, "/me ", 4) == 0)
 
482
                                if (action)
455
483
                                        signal_emit(
456
484
                                            "message xmpp history action", 6,
457
485
                                            server, text+4, nick, channel_name,
462
490
                                            server, text, nick, channel_name,
463
491
                                            stamp,
464
492
                                            GINT_TO_POINTER(SEND_TARGET_CHANNEL));
 
493
                        } else if (own) {
 
494
                                if (action)
 
495
                                        signal_emit("message xmpp own_action", 4,
 
496
                                            server, text+4, channel_name,
 
497
                                            GINT_TO_POINTER(SEND_TARGET_CHANNEL));
 
498
                                else
 
499
                                        signal_emit("message xmpp own_public", 3,
 
500
                                            server, text, channel_name);
465
501
                        } else {
466
 
                                if (g_ascii_strncasecmp(text, "/me ", 4) == 0)
 
502
                                if (action)
467
503
                                        signal_emit("message xmpp action", 5,
468
504
                                            server, text+4, nick, channel_name,
469
505
                                            GINT_TO_POINTER(SEND_TARGET_CHANNEL));
480
516
                }
481
517
 
482
518
                break;
483
 
 
484
 
        default:
485
 
                break;
486
519
        }
487
520
 
488
521
out: