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

« back to all changes in this revision

Viewing changes to src/fe-common/xep/fe-vcard.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: fe-vcard.c,v 1.1 2008/08/19 23:57:15 cdidier Exp $
 
3
 *
 
4
 * Copyright (C) 2007 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
#include "module.h"
 
21
#include "levels.h"
 
22
#include "printtext.h"
 
23
#include "signals.h"
 
24
 
 
25
#include "xmpp-servers.h"
 
26
#include "rosters-tools.h"
 
27
#include "tools.h"
 
28
#include "../module-formats.h"
 
29
 
 
30
struct vcard_user_data {
 
31
        XMPP_SERVER_REC *server;
 
32
        const char *jid;
 
33
};
 
34
 
 
35
static void
 
36
func_vcard_value(const char *key, const char *value, struct vcard_user_data *ud)
 
37
{
 
38
        printformat_module(MODULE_NAME, ud->server, ud->jid, MSGLEVEL_CRAP,
 
39
            XMPPTXT_VCARD_VALUE, key, value);
 
40
}
 
41
 
 
42
static void
 
43
func_vcard_subvalue(const char *key, const char *value,
 
44
    struct vcard_user_data *ud)
 
45
{
 
46
        printformat_module(MODULE_NAME, ud->server, ud->jid, MSGLEVEL_CRAP,
 
47
            XMPPTXT_VCARD_SUBVALUE, key, value);
 
48
}
 
49
 
 
50
static void
 
51
sig_vcard(XMPP_SERVER_REC *server, const char *jid, GHashTable *ht)
 
52
{
 
53
        XMPP_ROSTER_USER_REC *user;
 
54
        struct vcard_user_data ud;
 
55
        char *name;
 
56
 
 
57
        user = rosters_find_user(server->roster, jid, NULL, NULL);
 
58
        name = user != NULL && user->name != NULL ?
 
59
            g_strdup(user->name) : xmpp_strip_resource(jid);
 
60
        printformat_module(MODULE_NAME, server, jid, MSGLEVEL_CRAP,
 
61
            XMPPTXT_VCARD, name, jid);
 
62
        g_free(name);
 
63
        ud.server = server;
 
64
        ud.jid = jid;
 
65
        g_hash_table_foreach(ht,
 
66
            (void (*)(gpointer, gpointer, gpointer))func_vcard_value, &ud);
 
67
        printformat_module(MODULE_NAME, server, jid, MSGLEVEL_CRAP,
 
68
            XMPPTXT_END_OF_VCARD);
 
69
}
 
70
 
 
71
void
 
72
fe_vcard_init(void)
 
73
{
 
74
        signal_add("xmpp vcard", sig_vcard);
 
75
}
 
76
 
 
77
void
 
78
fe_vcard_deinit(void)
 
79
{   
 
80
        signal_remove("xmpp vcard", sig_vcard);
 
81
}