annotate mcabber/mcabber/xmpp_muc.c @ 1951:1a01a7ef4e43

Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko) Patch merged from isbear's mcabber-experimental repository.
author Mikael Berthe <mikael@lilotux.net>
date Mon, 14 Mar 2011 12:53:27 +0100
parents 26e437e79e60
children 9f443617e96b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
1 /*
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
2 * xmpp_muc.c -- Jabber MUC protocol handling
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
3 *
1729
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1722
diff changeset
4 * Copyright (C) 2008-2010 Frank Zschockelt <mcabber@freakysoft.de>
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1722
diff changeset
5 * Copyright (C) 2005-2010 Mikael Berthe <mikael@lilotux.net>
e6e89b1d7831 Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents: 1722
diff changeset
6 * Copyrigth (C) 2010 Myhailo Danylenko <isbear@ukrposte.net>
1599
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
7 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
8 * This program is free software; you can redistribute it and/or modify
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
9 * it under the terms of the GNU General Public License as published by
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or (at
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
11 * your option) any later version.
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
12 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
13 * This program is distributed in the hope that it will be useful, but
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
16 * General Public License for more details.
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
17 *
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
18 * You should have received a copy of the GNU General Public License
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
19 * along with this program; if not, write to the Free Software
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
21 * USA
dcd5d4c75199 Update/Add headers
Mikael Berthe <mikael@lilotux.net>
parents: 1598
diff changeset
22 */
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
23
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
24 #include <string.h>
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
25 #include <stdlib.h>
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
26
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
27 #include "xmpp_helper.h"
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
28 #include "xmpp_muc.h"
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
29 #include "events.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
30 #include "hooks.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
31 #include "screen.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
32 #include "hbuf.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
33 #include "roster.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
34 #include "commands.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
35 #include "settings.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
36 #include "utils.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
37 #include "histolog.h"
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
38
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
39 extern enum imstatus mystatus;
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
40 extern gchar *mystatusmsg;
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
41
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
42 static GSList *invitations = NULL;
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
43
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
44 static void decline_invitation(event_muc_invitation *invitation, const char *reason)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
45 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
46 // cut and paste from xmpp_room_invite
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
47 LmMessage *m;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
48 LmMessageNode *x, *y;
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
49
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
50 if (!invitation) return;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
51 if (!invitation->to || !invitation->from) return;
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
52
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
53 m = lm_message_new(invitation->to, LM_MESSAGE_TYPE_MESSAGE);
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
54
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
55 x = lm_message_node_add_child(m->node, "x", NULL);
1908
e2def760c6d0 Introduce NS_MUC_{USER,ADMIN,OWNER}
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
56 lm_message_node_set_attribute(x, "xmlns", NS_MUC_USER);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
57
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
58 y = lm_message_node_add_child(x, "decline", NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
59 lm_message_node_set_attribute(y, "to", invitation->from);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
60
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
61 if (reason)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
62 lm_message_node_add_child(y, "reason", reason);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
63
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
64 lm_connection_send(lconnection, m, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
65 lm_message_unref(m);
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
66 }
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
67
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
68 void destroy_event_muc_invitation(event_muc_invitation *invitation)
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
69 {
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
70 invitations = g_slist_remove(invitations, invitation);
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
71 g_free(invitation->to);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
72 g_free(invitation->from);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
73 g_free(invitation->passwd);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
74 g_free(invitation->reason);
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
75 g_free(invitation->evid);
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
76 g_free(invitation);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
77 }
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
78
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
79 // invitation event handler
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
80 // TODO: if event is accepted, check if other events to the same room exist and
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
81 // destroy them? (need invitation registry list for that)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
82 static gboolean evscallback_invitation(guint evcontext, const char *arg, gpointer userdata)
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
83 {
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
84 event_muc_invitation *invitation = userdata;
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
85
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
86 // Sanity check
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
87 if (G_UNLIKELY(!invitation)) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
88 // Shouldn't happen.
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
89 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback.");
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
90 return FALSE;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
91 }
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
92
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
93 if (evcontext == EVS_CONTEXT_TIMEOUT) {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
94 scr_LogPrint(LPRINT_LOGNORM, "Invitation event %s timed out, cancelled.", invitation->to);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
95 return FALSE;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
96 }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
97 if (evcontext == EVS_CONTEXT_CANCEL) {
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
98 scr_LogPrint(LPRINT_LOGNORM, "Invitation event %s cancelled.", invitation->to);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
99 return FALSE;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
100 }
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
101 if (!(evcontext == EVS_CONTEXT_ACCEPT || evcontext == EVS_CONTEXT_REJECT))
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
102 return FALSE;
999
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
103
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
104 // Ok, let's work now
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
105 if (evcontext == EVS_CONTEXT_ACCEPT) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
106 char *nickname = default_muc_nickname(invitation->to);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
107 xmpp_room_join(invitation->to, nickname, invitation->passwd);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
108 g_free(nickname);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
109 } else {
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
110 scr_LogPrint(LPRINT_LOGNORM, "Invitation to %s refused.", invitation->to);
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
111 if (invitation->reply)
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
112 decline_invitation(invitation, arg);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
113 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
114
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
115 return FALSE;
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
116 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
117
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
118 // Join a MUC room
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
119 void xmpp_room_join(const char *room, const char *nickname, const char *passwd)
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
120 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
121 LmMessage *x;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
122 LmMessageNode *y;
643
dd73c3dad815 Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 642
diff changeset
123 gchar *roomid;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
124 GSList *room_elt;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
125
1684
95df4ea512c8 Provide xmpp_is_online()
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1682
diff changeset
126 if (!xmpp_is_online() || !room)
1682
d1e8fb14ce2d Destroy lm connection object on disconnect
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
127 return;
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
128 if (!nickname) return;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
129
643
dd73c3dad815 Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 642
diff changeset
130 roomid = g_strdup_printf("%s/%s", room, nickname);
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
131 if (check_jid_syntax(roomid)) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
132 scr_LogPrint(LPRINT_NORMAL, "<%s/%s> is not a valid Jabber room", room,
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
133 nickname);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
134 g_free(roomid);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
135 return;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
136 }
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
137
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
138 room_elt = roster_find(room, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_ROOM);
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
139 // Add room if it doesn't already exist
649
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 645
diff changeset
140 if (!room_elt) {
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1354
diff changeset
141 room_elt = roster_add_user(room, NULL, NULL, ROSTER_TYPE_ROOM,
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1354
diff changeset
142 sub_none, -1);
649
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 645
diff changeset
143 } else {
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 645
diff changeset
144 // Make sure this is a room (it can be a conversion user->room)
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 645
diff changeset
145 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 645
diff changeset
146 }
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
147 // If insideroom is TRUE, this is a nickname change and we don't care here
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
148 if (!buddy_getinsideroom(room_elt->data)) {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
149 // We're trying to enter a room
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
150 buddy_setnickname(room_elt->data, nickname);
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
151 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
152
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
153 // Send the XML request
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
154 x = lm_message_new_presence(mystatus, roomid, mystatusmsg);
1920
bfa507815e0c Add caps to presence when joining a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 1908
diff changeset
155 xmpp_insert_entity_capabilities(x->node, mystatus); // Entity Caps (XEP-0115)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
156 y = lm_message_node_add_child(x->node, "x", NULL);
1908
e2def760c6d0 Introduce NS_MUC_{USER,ADMIN,OWNER}
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
157 lm_message_node_set_attribute(y, "xmlns", NS_MUC);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
158 if (passwd)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
159 lm_message_node_add_child(y, "password", passwd);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
160
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
161 lm_connection_send(lconnection, x, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
162 lm_message_unref(x);
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
163 g_free(roomid);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
164 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
165
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
166 // Invite a user to a MUC room
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
167 // room syntax: "room@server"
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
168 // reason can be null.
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
169 void xmpp_room_invite(const char *room, const char *fjid, const char *reason)
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
170 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
171 LmMessage *msg;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
172 LmMessageNode *x, *y;
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
173
1684
95df4ea512c8 Provide xmpp_is_online()
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1682
diff changeset
174 if (!xmpp_is_online() || !room || !fjid)
1682
d1e8fb14ce2d Destroy lm connection object on disconnect
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
175 return;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
176
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
177 msg = lm_message_new(room, LM_MESSAGE_TYPE_MESSAGE);
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
178
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
179 x = lm_message_node_add_child(msg->node, "x", NULL);
1908
e2def760c6d0 Introduce NS_MUC_{USER,ADMIN,OWNER}
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
180 lm_message_node_set_attribute(x, "xmlns", NS_MUC_USER);
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
181
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
182 y = lm_message_node_add_child(x, "invite", NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
183 lm_message_node_set_attribute(y, "to", fjid);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
184
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
185 if (reason)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
186 lm_message_node_add_child(y, "reason", reason);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
187
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
188 lm_connection_send(lconnection, msg, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
189 lm_message_unref(msg);
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
190 }
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
191
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
192 int xmpp_room_setattrib(const char *roomid, const char *fjid,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
193 const char *nick, struct role_affil ra,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
194 const char *reason)
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
195 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
196 LmMessage *iq;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
197 LmMessageNode *query, *x;
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
198
1684
95df4ea512c8 Provide xmpp_is_online()
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1682
diff changeset
199 if (!xmpp_is_online() || !roomid)
1682
d1e8fb14ce2d Destroy lm connection object on disconnect
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
200 return 1;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
201 if (!fjid && !nick) return 1;
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
202
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
203 if (check_jid_syntax((char*)roomid)) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
204 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
205 return 1;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
206 }
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
207 if (fjid && check_jid_syntax((char*)fjid)) {
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
208 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", fjid);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
209 return 1;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
210 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
211
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
212 if (ra.type == type_affil && ra.val.affil == affil_outcast && !fjid)
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 569
diff changeset
213 return 1; // Shouldn't happen (jid mandatory when banning)
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
214
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
215 iq = lm_message_new_with_sub_type(roomid, LM_MESSAGE_TYPE_IQ,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
216 LM_MESSAGE_SUB_TYPE_SET);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
217 query = lm_message_node_add_child(iq->node, "query", NULL);
1908
e2def760c6d0 Introduce NS_MUC_{USER,ADMIN,OWNER}
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
218 lm_message_node_set_attribute(query, "xmlns", NS_MUC_ADMIN);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
219 x = lm_message_node_add_child(query, "item", NULL);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
220
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
221 if (fjid) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
222 lm_message_node_set_attribute(x, "jid", fjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
223 } else { // nickname
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
224 lm_message_node_set_attribute(x, "nick", nick);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
225 }
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
226
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
227 if (ra.type == type_affil)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
228 lm_message_node_set_attribute(x, "affiliation", straffil[ra.val.affil]);
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
229 else if (ra.type == type_role)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
230 lm_message_node_set_attribute(x, "role", strrole[ra.val.role]);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
231
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
232 if (reason)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
233 lm_message_node_add_child(x, "reason", reason);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
234
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
235 lm_connection_send(lconnection, iq, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
236 lm_message_unref(iq);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
237
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
238 return 0;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
239 }
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
240
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
241 // Unlock a MUC room
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
242 // room syntax: "room@server"
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
243 void xmpp_room_unlock(const char *room)
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
244 {
1664
2f6bdfa0cb01 Fix room unlocking
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1604
diff changeset
245 LmMessageNode *node;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
246 LmMessage *iq;
1363
32077249de77 Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
247
1684
95df4ea512c8 Provide xmpp_is_online()
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1682
diff changeset
248 if (!xmpp_is_online() || !room)
1682
d1e8fb14ce2d Destroy lm connection object on disconnect
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
249 return;
1363
32077249de77 Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents: 1355
diff changeset
250
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
251 iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
252 LM_MESSAGE_SUB_TYPE_SET);
1664
2f6bdfa0cb01 Fix room unlocking
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1604
diff changeset
253
2f6bdfa0cb01 Fix room unlocking
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1604
diff changeset
254 node = lm_message_node_add_child(iq->node, "query", NULL);
1908
e2def760c6d0 Introduce NS_MUC_{USER,ADMIN,OWNER}
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
255 lm_message_node_set_attribute(node, "xmlns", NS_MUC_OWNER);
1664
2f6bdfa0cb01 Fix room unlocking
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1604
diff changeset
256 node = lm_message_node_add_child(node, "x", NULL);
2f6bdfa0cb01 Fix room unlocking
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1604
diff changeset
257 lm_message_node_set_attributes(node, "xmlns", "jabber:x:data",
2f6bdfa0cb01 Fix room unlocking
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1604
diff changeset
258 "type", "submit", NULL);
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
259
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
260 lm_connection_send(lconnection, iq, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
261 lm_message_unref(iq);
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
262 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
263
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
264 // Destroy a MUC room
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
265 // room syntax: "room@server"
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
266 void xmpp_room_destroy(const char *room, const char *venue, const char *reason)
1104
382972712208 Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents: 1099
diff changeset
267 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
268 LmMessage *iq;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
269 LmMessageNode *query, *x;
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1042
diff changeset
270
1684
95df4ea512c8 Provide xmpp_is_online()
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1682
diff changeset
271 if (!xmpp_is_online() || !room)
1682
d1e8fb14ce2d Destroy lm connection object on disconnect
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1668
diff changeset
272 return;
1484
7b36b91a4388 New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents: 1476
diff changeset
273
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
274 iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
275 LM_MESSAGE_SUB_TYPE_SET);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
276 query = lm_message_node_add_child(iq->node, "query", NULL);
1908
e2def760c6d0 Introduce NS_MUC_{USER,ADMIN,OWNER}
Mikael Berthe <mikael@lilotux.net>
parents: 1899
diff changeset
277 lm_message_node_set_attribute(query, "xmlns", NS_MUC_OWNER);
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
278 x = lm_message_node_add_child(query, "destroy", NULL);
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
279
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
280 if (venue && *venue)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
281 lm_message_node_set_attribute(x, "jid", venue);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
282
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
283 if (reason)
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
284 lm_message_node_add_child(x, "reason", reason);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
285
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
286 lm_connection_send(lconnection, iq, NULL);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
287 lm_message_unref(iq);
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
288 }
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
289
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
290 // muc_get_item_info(...)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
291 // Get room member's information from xmlndata.
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
292 // The variables must be initialized before calling this function,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
293 // because they are not touched if the relevant information is missing.
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
294 static void muc_get_item_info(const char *from, LmMessageNode *xmldata,
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
295 enum imrole *mbrole, enum imaffiliation *mbaffil,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
296 const char **mbjid, const char **mbnick,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
297 const char **actorjid, const char **reason)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
298 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
299 LmMessageNode *y, *z;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
300 const char *p;
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
301
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
302 y = lm_message_node_find_child(xmldata, "item");
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
303 if (!y)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
304 return;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
305
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
306 p = lm_message_node_get_attribute(y, "affiliation");
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
307 if (p) {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
308 if (!strcmp(p, "owner")) *mbaffil = affil_owner;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
309 else if (!strcmp(p, "admin")) *mbaffil = affil_admin;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
310 else if (!strcmp(p, "member")) *mbaffil = affil_member;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
311 else if (!strcmp(p, "outcast")) *mbaffil = affil_outcast;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
312 else if (!strcmp(p, "none")) *mbaffil = affil_none;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
313 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown affiliation \"%s\"",
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
314 from, p);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
315 }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
316 p = lm_message_node_get_attribute(y, "role");
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
317 if (p) {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
318 if (!strcmp(p, "moderator")) *mbrole = role_moderator;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
319 else if (!strcmp(p, "participant")) *mbrole = role_participant;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
320 else if (!strcmp(p, "visitor")) *mbrole = role_visitor;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
321 else if (!strcmp(p, "none")) *mbrole = role_none;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
322 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown role \"%s\"",
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
323 from, p);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
324 }
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
325 *mbjid = lm_message_node_get_attribute(y, "jid");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
326 *mbnick = lm_message_node_get_attribute(y, "nick");
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
327 // For kick/ban, there can be actor and reason tags
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
328 *reason = lm_message_node_get_child_value(y, "reason");
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1898
diff changeset
329 if (*reason && !**reason)
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1898
diff changeset
330 *reason = NULL;
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
331 z = lm_message_node_find_child(y, "actor");
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
332 if (z)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
333 *actorjid = lm_message_node_get_attribute(z, "jid");
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
334 }
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
335
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
336 // muc_handle_join(...)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
337 // Handle a join event in a MUC room.
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
338 // This function will return the new_member value TRUE if somebody else joins
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
339 // the room (and FALSE if _we_ are joining the room).
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
340 static bool muc_handle_join(const GSList *room_elt, const char *rname,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
341 const char *roomjid, const char *ournick,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
342 enum room_printstatus printstatus,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
343 time_t usttime, int log_muc_conf)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
344 {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
345 bool new_member = FALSE; // True if somebody else joins the room (not us)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
346 gchar *mbuf;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
347
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
348 if (!buddy_getinsideroom(room_elt->data)) {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
349 // We weren't inside the room yet. Now we are.
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
350 // However, this could be a presence packet from another room member
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
351
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
352 buddy_setinsideroom(room_elt->data, TRUE);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
353 // Set the message flag unless we're already in the room buffer window
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
354 scr_setmsgflag_if_needed(roomjid, FALSE);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
355 // Add a message to the tracelog file
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
356 mbuf = g_strdup_printf("You have joined %s as \"%s\"", roomjid, ournick);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
357 scr_LogPrint(LPRINT_LOGNORM, "%s", mbuf);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
358 g_free(mbuf);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
359 mbuf = g_strdup_printf("You have joined as \"%s\"", ournick);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
360
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
361 // The 1st presence message could be for another room member
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
362 if (strcmp(ournick, rname)) {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
363 // Display current mbuf and create a new message for the member
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
364 // Note: the usttime timestamp is related to the other member,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
365 // so we use 0 here.
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
366 scr_WriteIncomingMessage(roomjid, mbuf, 0,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
367 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
368 if (log_muc_conf)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
369 hlog_write_message(roomjid, 0, -1, mbuf);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
370 g_free(mbuf);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
371 if (printstatus != status_none)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
372 mbuf = g_strdup_printf("%s has joined", rname);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
373 else
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
374 mbuf = NULL;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
375 new_member = TRUE;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
376 }
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
377 } else {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
378 mbuf = NULL;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
379 if (strcmp(ournick, rname)) {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
380 if (printstatus != status_none)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
381 mbuf = g_strdup_printf("%s has joined", rname);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
382 new_member = TRUE;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
383 }
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
384 }
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
385
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
386 if (mbuf) {
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
387 guint msgflags = HBB_PREFIX_INFO;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
388 if (!settings_opt_get_int("muc_flag_joins"))
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
389 msgflags |= HBB_PREFIX_NOFLAG;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
390 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
391 if (log_muc_conf)
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
392 hlog_write_message(roomjid, 0, -1, mbuf);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
393 g_free(mbuf);
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
394 }
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
395
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
396 return new_member;
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
397 }
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
398
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
399 void handle_muc_presence(const char *from, LmMessageNode *xmldata,
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
400 const char *roomjid, const char *rname,
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
401 enum imstatus ust, const char *ustmsg,
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
402 time_t usttime, char bpprio)
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
403 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
404 LmMessageNode *y;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
405 const char *p;
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
406 char *mbuf;
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
407 const char *ournick;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
408 enum imrole mbrole = role_none;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
409 enum imaffiliation mbaffil = affil_none;
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
410 enum room_printstatus printstatus;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
411 enum room_autowhois autowhois;
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
412 const char *mbjid = NULL, *mbnick = NULL;
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
413 const char *actorjid = NULL, *reason = NULL;
837
7c74eef1d0e0 New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents: 834
diff changeset
414 bool new_member = FALSE; // True if somebody else joins the room (not us)
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
415 guint statuscode = 0;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
416 guint nickchange = 0;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
417 GSList *room_elt;
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
418 int log_muc_conf;
1013
f1a9ca2348e5 Set the msg_flag when we leave a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 1010
diff changeset
419 guint msgflags;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
420
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
421 log_muc_conf = settings_opt_get_int("log_muc_conf");
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
422
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
423 room_elt = roster_find(roomjid, jidsearch, 0);
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
424 if (!room_elt) {
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
425 // Add room if it doesn't already exist
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
426 // It shouldn't happen, there is probably something wrong (server or
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
427 // network issue?)
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1354
diff changeset
428 room_elt = roster_add_user(roomjid, NULL, NULL, ROSTER_TYPE_ROOM,
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1354
diff changeset
429 sub_none, -1);
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
430 scr_LogPrint(LPRINT_LOGNORM, "Strange MUC presence message");
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
431 } else {
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
432 // Make sure this is a room (it can be a conversion user->room)
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
433 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
434 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
435
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
436 // Get room member's information
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
437 muc_get_item_info(from, xmldata, &mbrole, &mbaffil, &mbjid, &mbnick,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
438 &actorjid, &reason);
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
439
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
440 // Get our room nickname
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
441 ournick = buddy_getnickname(room_elt->data);
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
442
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
443 if (!ournick) {
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
444 // It shouldn't happen, probably a server issue
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
445 mbuf = g_strdup_printf("Unexpected groupchat packet!");
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
446
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
447 scr_LogPrint(LPRINT_LOGNORM, "%s", mbuf);
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1282
diff changeset
448 scr_WriteIncomingMessage(roomjid, mbuf, 0, HBB_PREFIX_INFO, 0);
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
449 g_free(mbuf);
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
450 // Send back an unavailable packet
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
451 xmpp_setstatus(offline, roomjid, "", TRUE);
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
452 scr_draw_roster();
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
453 return;
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
454 }
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
455
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
456 // Get the status code
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
457 // 201: a room has been created
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
458 // 301: the user has been banned from the room
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
459 // 303: new room nickname
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
460 // 307: the user has been kicked from the room
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
461 // 321,322,332: the user has been removed from the room
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
462 y = lm_message_node_find_child(xmldata, "status");
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
463 if (y) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
464 p = lm_message_node_get_attribute(y, "code");
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
465 if (p)
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
466 statuscode = atoi(p);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
467 }
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
468
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
469 // Get the room's "print_status" settings
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
470 printstatus = buddy_getprintstatus(room_elt->data);
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
471 if (printstatus == status_default) {
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
472 printstatus = (guint) settings_opt_get_int("muc_print_status");
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
473 if (printstatus > 3)
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
474 printstatus = status_default;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
475 }
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
476
1396
8f9928839a36 Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents: 1395
diff changeset
477 // A new room has been created; accept MUC default config
8f9928839a36 Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents: 1395
diff changeset
478 if (statuscode == 201)
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
479 xmpp_room_unlock(roomjid);
1396
8f9928839a36 Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents: 1395
diff changeset
480
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
481 // Check for nickname change
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
482 if (statuscode == 303 && mbnick) {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
483 mbuf = g_strdup_printf("%s is now known as %s", rname, mbnick);
632
cfab93886a88 MUC: use timestamp when available
Mikael Berthe <mikael@lilotux.net>
parents: 628
diff changeset
484 scr_WriteIncomingMessage(roomjid, mbuf, usttime,
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1282
diff changeset
485 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
1166
c4da23bf8958 Add option 'muc_flag_joins'
Mikael Berthe <mikael@lilotux.net>
parents: 1164
diff changeset
486 if (log_muc_conf)
1342
06441b6cc23a History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents: 1333
diff changeset
487 hlog_write_message(roomjid, 0, -1, mbuf);
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
488 g_free(mbuf);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
489 buddy_resource_setname(room_elt->data, rname, mbnick);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
490 // Maybe it's _our_ nickname...
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
491 if (ournick && !strcmp(rname, ournick))
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
492 buddy_setnickname(room_elt->data, mbnick);
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
493 nickchange = TRUE;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
494 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
495
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
496 // Check for departure/arrival
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
497 if (statuscode != 303 && ust == offline) {
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
498 // Somebody is leaving
586
d8f64e74206c Missing initialization
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
499 enum { leave=0, kick, ban } how = leave;
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
500 bool we_left = FALSE;
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
501
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
502 if (statuscode == 307)
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
503 how = kick;
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
504 else if (statuscode == 301)
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
505 how = ban;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
506
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
507 // If this is a leave, check if it is ourself
864
a7b3409df6bc MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents: 862
diff changeset
508 if (ournick && !strcmp(rname, ournick)) {
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
509 we_left = TRUE; // _We_ have left! (kicked, banned, etc.)
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
510 buddy_setinsideroom(room_elt->data, FALSE);
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
511 buddy_setnickname(room_elt->data, NULL);
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
512 buddy_del_all_resources(room_elt->data);
600
483a87c99990 Free room personal data when receiving the unavailable stanza, not before
Mikael Berthe <mikael@lilotux.net>
parents: 599
diff changeset
513 buddy_settopic(room_elt->data, NULL);
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
514 scr_update_chat_status(FALSE);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
515 update_roster = TRUE;
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
516 }
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
517
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
518 // The message depends on _who_ left, and _how_
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
519 if (how) {
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
520 gchar *mbuf_end;
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
521 gchar *reason_msg = NULL;
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
522 // Forced leave
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
523 if (actorjid) {
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
524 mbuf_end = g_strdup_printf("%s from %s by <%s>.",
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
525 (how == ban ? "banned" : "kicked"),
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
526 roomjid, actorjid);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
527 } else {
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
528 mbuf_end = g_strdup_printf("%s from %s.",
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
529 (how == ban ? "banned" : "kicked"),
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
530 roomjid);
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
531 }
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
532 if (reason)
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
533 reason_msg = g_strdup_printf("\nReason: %s", reason);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
534 if (we_left)
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
535 mbuf = g_strdup_printf("You have been %s%s", mbuf_end,
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
536 reason_msg ? reason_msg : "");
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
537 else
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
538 mbuf = g_strdup_printf("%s has been %s%s", rname, mbuf_end,
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
539 reason_msg ? reason_msg : "");
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
540
1898
e25cec543da1 Fix two MUC issues (reported by VarLog)
Mikael Berthe <mikael@lilotux.net>
parents: 1811
diff changeset
541 g_free(reason_msg);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
542 g_free(mbuf_end);
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
543 } else {
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
544 // Natural leave
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
545 if (we_left) {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
546 LmMessageNode *destroynode = lm_message_node_find_child(xmldata,
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
547 "destroy");
616
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
548 if (destroynode) {
1899
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1898
diff changeset
549 reason = lm_message_node_get_child_value(destroynode, "reason");
decf94827efe More lm_message_node_get_child_value() return value checks
Mikael Berthe <mikael@lilotux.net>
parents: 1898
diff changeset
550 if (reason && *reason) {
616
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
551 mbuf = g_strdup_printf("You have left %s, "
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
552 "the room has been destroyed: %s",
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
553 roomjid, reason);
616
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
554 } else {
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
555 mbuf = g_strdup_printf("You have left %s, "
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
556 "the room has been destroyed", roomjid);
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
557 }
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
558 } else {
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
559 mbuf = g_strdup_printf("You have left %s", roomjid);
616
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
560 }
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
561 } else {
845
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
562 if (ust != offline) {
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
563 // This can happen when a network failure occurs,
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
564 // this isn't an official leave but the user isn't there anymore.
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
565 mbuf = g_strdup_printf("%s has disappeared!", rname);
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
566 ust = offline;
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
567 } else {
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
568 if (ustmsg)
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
569 mbuf = g_strdup_printf("%s has left: %s", rname, ustmsg);
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
570 else
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
571 mbuf = g_strdup_printf("%s has left", rname);
51829325fe21 MUC: Fix a strange bug when a user isn't in a room anymore (network issue)
Mikael Berthe <mikael@lilotux.net>
parents: 842
diff changeset
572 }
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
573 }
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
574 }
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
575
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
576 // Display the mbuf message if we're concerned
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
577 // or if the print_status isn't set to none.
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
578 if (we_left || printstatus != status_none) {
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
579 msgflags = HBB_PREFIX_INFO;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
580 if (!we_left && settings_opt_get_int("muc_flag_joins") != 2)
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
581 msgflags |= HBB_PREFIX_NOFLAG;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
582 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0);
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
583 }
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
584
1166
c4da23bf8958 Add option 'muc_flag_joins'
Mikael Berthe <mikael@lilotux.net>
parents: 1164
diff changeset
585 if (log_muc_conf)
1342
06441b6cc23a History logfile: Use a special code (MI) for local MUC info messages
Mikael Berthe <mikael@lilotux.net>
parents: 1333
diff changeset
586 hlog_write_message(roomjid, 0, -1, mbuf);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
587
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
588 if (we_left) {
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
589 scr_LogPrint(LPRINT_LOGNORM, "%s", mbuf);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
590 g_free(mbuf);
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
591 return;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
592 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
593 g_free(mbuf);
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
594 } else if (buddy_getstatus(room_elt->data, rname) == offline &&
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
595 ust != offline) {
1384
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
596 // Somebody is joining
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
597 new_member = muc_handle_join(room_elt, rname, roomjid, ournick,
f762805b3f42 Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents: 1383
diff changeset
598 printstatus, usttime, log_muc_conf);
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
599 } else {
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
600 // This is a simple member status change
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
601
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
602 if (printstatus == status_all && !nickchange) {
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
603 mbuf = g_strdup_printf("Member status has changed: %s [%c] %s", rname,
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
604 imstatus2char[ust], ((ustmsg) ? ustmsg : ""));
1380
605f9e1f9f76 Add missing PREFIX_NOFLAG flag...
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
605 scr_WriteIncomingMessage(roomjid, mbuf, usttime,
605f9e1f9f76 Add missing PREFIX_NOFLAG flag...
Mikael Berthe <mikael@lilotux.net>
parents: 1379
diff changeset
606 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0);
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
607 g_free(mbuf);
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
608 }
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
609 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
610
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
611 // Sanity check, shouldn't happen...
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
612 if (!rname)
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
613 return;
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
614
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
615 // Update room member status
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
616 roster_setstatus(roomjid, rname, bpprio, ust, ustmsg, usttime,
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
617 mbrole, mbaffil, mbjid);
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
618
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
619 autowhois = buddy_getautowhois(room_elt->data);
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
620 if (autowhois == autowhois_default)
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
621 autowhois = (settings_opt_get_int("muc_auto_whois") ?
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
622 autowhois_on : autowhois_off);
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
623
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
624 if (new_member && autowhois == autowhois_on) {
1938
26e437e79e60 Fix MUC whois / auto_whois
Mikael Berthe <mikael@lilotux.net>
parents: 1920
diff changeset
625 cmd_room_whois(room_elt->data, rname, FALSE);
1377
cd9182f0b5c7 Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents: 1365
diff changeset
626 }
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
627
1780
e4378fbab5d7 Major API cleanup - bump API to 4
Mikael Berthe <mikael@lilotux.net>
parents: 1729
diff changeset
628 scr_draw_roster();
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
629 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
630
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
631 void roompresence(gpointer room, void *presencedata)
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
632 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
633 const char *bjid;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
634 const char *nickname;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
635 char *to;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
636 struct T_presence *pres = presencedata;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
637
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
638 if (!buddy_getinsideroom(room))
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
639 return;
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
640
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
641 bjid = buddy_getjid(room);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
642 if (!bjid) return;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
643 nickname = buddy_getnickname(room);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
644 if (!nickname) return;
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
645
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
646 to = g_strdup_printf("%s/%s", bjid, nickname);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
647 xmpp_setstatus(pres->st, to, pres->msg, TRUE);
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
648 g_free(to);
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
649 }
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
650
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
651 // got_invite(from, to, reason, passwd, reply)
1330
7ba1b6d7ddcd Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
652 // This function should be called when receiving an invitation from user
7ba1b6d7ddcd Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
653 // "from", to enter the room "to". Optional reason and room password can
7ba1b6d7ddcd Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
654 // be provided.
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
655 void got_invite(const char* from, const char *to, const char* reason,
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
656 const char* passwd, gboolean reply)
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
657 {
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
658 GString *sbuf;
1236
f7b35b1c343d Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1215
diff changeset
659 char *barejid;
1237
dcb99f0b5aaa Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents: 1236
diff changeset
660 GSList *room_elt;
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
661
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
662 sbuf = g_string_new("");
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
663 if (reason) {
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
664 g_string_printf(sbuf,
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
665 "Received an invitation to <%s>, from <%s>, reason: %s",
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
666 to, from, reason);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
667 } else {
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
668 g_string_printf(sbuf, "Received an invitation to <%s>, from <%s>",
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
669 to, from);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
670 }
1236
f7b35b1c343d Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1215
diff changeset
671
f7b35b1c343d Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1215
diff changeset
672 barejid = jidtodisp(from);
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1282
diff changeset
673 scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0);
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
674 scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
675
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
676 { // remove any equal older invites
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
677 GSList *iel = invitations;
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
678 while (iel) {
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
679 event_muc_invitation *invitation = iel->data;
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
680 iel = iel -> next;
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
681 if (!g_strcmp0(to, invitation->to) &&
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
682 !g_strcmp0(passwd, invitation->passwd)) {
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
683 scr_LogPrint(LPRINT_DEBUG, "Destroying previous invitation event %s.",
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
684 invitation->evid);
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
685 evs_del(invitation->evid);
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
686 }
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
687 }
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
688 }
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
689
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
690 { // create event
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
691 const char *id;
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
692 char *desc = g_strdup_printf("<%s> invites you to %s", from, to);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
693 event_muc_invitation *invitation;
1722
b18142457ca9 Fix vCard requests in MUC rooms
Mikael Berthe <mikael@lilotux.net>
parents: 1687
diff changeset
694
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
695 invitation = g_new(event_muc_invitation, 1);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
696 invitation->to = g_strdup(to);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
697 invitation->from = g_strdup(from);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
698 invitation->passwd = g_strdup(passwd);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
699 invitation->reason = g_strdup(reason);
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
700 invitation->reply = reply;
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
701 invitation->evid = NULL;
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
702
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
703 invitations = g_slist_append(invitations, invitation);
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
704
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
705 id = evs_new(desc, NULL, 0, evscallback_invitation, invitation,
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
706 (GDestroyNotify)destroy_event_muc_invitation);
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
707 g_free(desc);
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
708 if (id) {
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
709 invitation->evid = g_strdup(id);
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
710 g_string_printf(sbuf, "Please use /event %s accept|reject", id);
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
711 } else
1685
1342df44c814 Improved events interface
Myhailo Danylenko <isbear@ukrpost.net>
parents: 1684
diff changeset
712 g_string_printf(sbuf, "Unable to create a new event!");
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
713 }
1290
e42f48103609 Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1282
diff changeset
714 scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0);
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
715 scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
716 g_string_free(sbuf, TRUE);
1330
7ba1b6d7ddcd Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
717 g_free(barejid);
7ba1b6d7ddcd Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
718
7ba1b6d7ddcd Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
719 // Make sure the MUC room barejid is a room in the roster
7ba1b6d7ddcd Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1311
diff changeset
720 barejid = jidtodisp(to);
1237
dcb99f0b5aaa Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents: 1236
diff changeset
721 room_elt = roster_find(barejid, jidsearch, 0);
dcb99f0b5aaa Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents: 1236
diff changeset
722 if (room_elt)
dcb99f0b5aaa Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents: 1236
diff changeset
723 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
dcb99f0b5aaa Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents: 1236
diff changeset
724
1236
f7b35b1c343d Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents: 1215
diff changeset
725 g_free(barejid);
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
726 }
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
727
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
728
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
729 // Specific MUC message handling (for example invitation processing)
1604
351427ef0b4b Remove #include's of C files
Mikael Berthe <mikael@lilotux.net>
parents: 1599
diff changeset
730 void got_muc_message(const char *from, LmMessageNode *x)
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
731 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
732 LmMessageNode *invite = lm_message_node_get_child(x, "invite");
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
733 if (invite)
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
734 {
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
735 const char *invite_from;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
736 const char *reason = NULL;
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
737 const char *password = NULL;
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
738
1598
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
739 invite_from = lm_message_node_get_attribute(invite, "from");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
740 reason = lm_message_node_get_child_value(invite, "reason");
a087125d8fc8 Replace libjabber with loudmouth
franky
parents: 1592
diff changeset
741 password = lm_message_node_get_child_value(invite, "password");
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
742 if (invite_from)
1951
1a01a7ef4e43 Add support for XEP-0249 / Direct MUC Invitations (Myhailo Danylenko)
Mikael Berthe <mikael@lilotux.net>
parents: 1938
diff changeset
743 got_invite(invite_from, from, reason, password, TRUE);
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
744 }
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
745 // TODO
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
746 // handle status code = 100 ( not anonymous )
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
747 // handle status code = 170 ( changement de config )
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
748 // 10.2.1 Notification of Configuration Changes
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
749 // declined invitation
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
750 }
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
751
1811
e6d355e50d7a Update Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 1780
diff changeset
752 /* vim: set et cindent cinoptions=>2\:2(0 ts=2 sw=2: For Vim users... */