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

« back to all changes in this revision

Viewing changes to src/core/xep/oob.c

  • Committer: Bazaar Package Importer
  • Author(s): David Ammouial
  • Date: 2009-05-12 12:14:44 UTC
  • mfrom: (1.1.3 upstream) (2.1.2 sid)
  • Revision ID: james.westby@ubuntu.com-20090512121444-5jeho5h3zsy4oij7
Tags: 0.13+cvs20090406-1
* New CVS snapshot, built against irssi-dev 0.8.13:
  - New features and bugfixes.
  - Fix segfault when successfully identified (Closes: #521227).
  - Fix build error (Closes: #527697)
* Depend on irssi >=0.8.13, build-depend on irssi-dev >=0.8.13.
* Bump Standards-Version to 3.8.1 (no changes needed).
* Add INTERNAL to documentation files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: oob.c,v 1.3 2009/04/03 11:21:35 cdidier Exp $
 
3
 *
 
4
 * Copyright (C) 2007,2008,2009 Colin DIDIER
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License version 2 as
 
8
 * published by the Free Software Foundation.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License along
 
16
 * with this program; if not, write to the Free Software Foundation, Inc.,
 
17
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 
18
 */
 
19
 
 
20
/*
 
21
 * XEP-0066: Out of Band Data
 
22
 */
 
23
 
 
24
#include "module.h"
 
25
#include "signals.h"
 
26
 
 
27
#include "xmpp-servers.h"
 
28
#include "tools.h"
 
29
#include "disco.h"
 
30
 
 
31
#define XMLNS_OOB_X     "jabber:x:oob"
 
32
#define XMLNS_OOB_IQ    "jabber:iq:oob"
 
33
 
 
34
static void
 
35
sig_recv_x(XMPP_SERVER_REC *server, LmMessage *lmsg, const int type,
 
36
    const char *id, const char *from, const char *to)
 
37
{
 
38
        LmMessageNode *node, *child;
 
39
        const char *url, *desc;
 
40
        char *url_recoded, *desc_recoded, *str;
 
41
 
 
42
        node = lm_find_node(lmsg->node, "x", XMLNS, XMLNS_OOB_X);
 
43
        if (node != NULL) {
 
44
                child = lm_message_node_get_child(node, "url");
 
45
                if (child == NULL || child->value == NULL)
 
46
                        return;
 
47
                url = child->value;
 
48
                child = lm_message_node_get_child(node, "desc");
 
49
                desc = child != NULL ? child->value : NULL;
 
50
                url_recoded = xmpp_recode_in(url);
 
51
                if (desc != NULL) {
 
52
                        desc_recoded = xmpp_recode_in(desc);
 
53
                        str = g_strconcat(desc_recoded, ": ", url_recoded);
 
54
                        g_free(url_recoded);
 
55
                        g_free(desc_recoded);
 
56
                } else
 
57
                        str = url_recoded;
 
58
                signal_emit("message private", 4, server, str, from, from);
 
59
                g_free(str);
 
60
        }
 
61
}
 
62
 
 
63
void
 
64
oob_init(void)
 
65
{
 
66
        disco_add_feature(XMLNS_OOB_X);
 
67
        signal_add("xmpp recv message", sig_recv_x);
 
68
        signal_add("xmpp recv presence", sig_recv_x);
 
69
}
 
70
 
 
71
void
 
72
oob_deinit(void)
 
73
{
 
74
        signal_remove("xmpp recv message", sig_recv_x);
 
75
        signal_remove("xmpp recv presence", sig_recv_x);
 
76
}