Debian Codegraph @

src/fe-common/xep/fe-vcard.c

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Colin DIDIER
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
16 */
17
18 #include "module.h"
19 #include "levels.h"
20 #include "printtext.h"
21 #include "signals.h"
22
23 #include "xmpp-servers.h"
24 #include "rosters-tools.h"
25 #include "tools.h"
26 #include "../module-formats.h"
27
28 struct vcard_user_data {
29 XMPP_SERVER_REC *server;
30 const char *jid;
31 };
32
33 static void
34 func_vcard_value(const char *key, const char *value, struct vcard_user_data *ud)
35 {
36 printformat_module(MODULE_NAME, ud->server, ud->jid, MSGLEVEL_CRAP,
37 XMPPTXT_VCARD_VALUE, key, value);
38 }
39
40 #if 0
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 #endif
51
52 static void
53 sig_vcard(XMPP_SERVER_REC *server, const char *jid, GHashTable *ht)
54 {
55 XMPP_ROSTER_USER_REC *user;
56 struct vcard_user_data ud;
57 char *name;
58
59 user = rosters_find_user(server->roster, jid, NULL, NULL);
60 name = user != NULL && user->name != NULL ?
61 g_strdup(user->name) : xmpp_strip_resource(jid);
62 printformat_module(MODULE_NAME, server, jid, MSGLEVEL_CRAP,
63 XMPPTXT_VCARD, name, jid);
64 g_free(name);
65 ud.server = server;
66 ud.jid = jid;
67 g_hash_table_foreach(ht,
68 (void (*)(gpointer, gpointer, gpointer))func_vcard_value, &ud);
69 printformat_module(MODULE_NAME, server, jid, MSGLEVEL_CRAP,
70 XMPPTXT_END_OF_VCARD);
71 }
72
73 void
74 fe_vcard_init(void)
75 {
76 signal_add("xmpp vcard", sig_vcard);
77 }
78
79 void
80 fe_vcard_deinit(void)
81 {
82 signal_remove("xmpp vcard", sig_vcard);
83 }