comparison mcabber/mcabber/xmpp_s10n.c @ 1668:41c26b7d2890

Install mcabber headers * Change mcabber headers naming scheme * Move 'src/' -> 'mcabber/' * Add missing include <mcabber/config.h>'s * Create and install clean config.h version in 'include/' * Move "dirty" config.h version to 'mcabber/' * Add $(top_srcdir) to compiler include path * Update modules HOWTO
author Myhailo Danylenko <isbear@ukrpost.net>
date Mon, 18 Jan 2010 15:36:19 +0200
parents mcabber/src/xmpp_s10n.c@351427ef0b4b
children 1342df44c814
comparison
equal deleted inserted replaced
1667:8af0e0ad20ad 1668:41c26b7d2890
1 /*
2 * xmpp_s10n.c -- Jabber presence subscription handling
3 *
4 * Copyright (C) 2008-2009 Frank Zschockelt <mcabber@freakysoft.de>
5 * Copyright (C) 2005-2009 Mikael Berthe <mikael@lilotux.net>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or (at
10 * your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 */
22
23 #include "xmpp_helper.h"
24 #include "events.h"
25 #include "screen.h"
26 #include "hbuf.h"
27 #include "settings.h"
28
29 // xmpp_send_s10n(jid, subtype)
30 // Send a s10n message with the passed subtype
31 void xmpp_send_s10n(const char *bjid, LmMessageSubType type)
32 {
33 LmMessage *x = lm_message_new_with_sub_type(bjid,
34 LM_MESSAGE_TYPE_PRESENCE,
35 type);
36 lm_connection_send(lconnection, x, NULL);
37 lm_message_unref(x);
38 }
39
40 int evscallback_subscription(eviqs *evp, guint evcontext)
41 {
42 char *barejid;
43 char *buf;
44
45 if (evcontext == EVS_CONTEXT_TIMEOUT) {
46 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.",
47 evp->id);
48 return 0;
49 }
50 if (evcontext == EVS_CONTEXT_CANCEL) {
51 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id);
52 return 0;
53 }
54 if (!(evcontext & EVS_CONTEXT_USER))
55 return 0;
56
57 // Sanity check
58 if (!evp->data) {
59 // Shouldn't happen, data should be set to the barejid.
60 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
61 return 0;
62 }
63
64 // Ok, let's work now.
65 // evcontext: 0, 1 == reject, accept
66
67 barejid = evp->data;
68
69 if (evcontext & ~EVS_CONTEXT_USER) {
70 // Accept subscription request
71 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_SUBSCRIBED);
72 buf = g_strdup_printf("<%s> is allowed to receive your presence updates",
73 barejid);
74 } else {
75 // Reject subscription request
76 xmpp_send_s10n(barejid, LM_MESSAGE_SUB_TYPE_UNSUBSCRIBED);
77 buf = g_strdup_printf("<%s> won't receive your presence updates", barejid);
78 if (settings_opt_get_int("delete_on_reject")) {
79 // Remove the buddy from the roster if there is no current subscription
80 if (roster_getsubscription(barejid) == sub_none)
81 xmpp_delbuddy(barejid);
82 }
83 }
84 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0);
85 scr_LogPrint(LPRINT_LOGNORM, "%s", buf);
86 g_free(buf);
87 return 0;
88 }
89
90 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */