Mercurial > hg
annotate mcabber/src/xmpp_muc.c @ 1603:54029aba9452
Allow specifying nickname for bookmark
author | Myhailo Danylenko <isbear@ukrpost.net> |
---|---|
date | Mon, 15 Jun 2009 10:59:31 +0200 |
parents | dcd5d4c75199 |
children | 351427ef0b4b |
rev | line source |
---|---|
1599 | 1 /* |
2 * xmpp_muc.c -- Jabber MUC protocol handling | |
3 * | |
4 * Copyright (C) 2008-2009 Frank Zschockelt <mcabber@freakysoft.de> | |
5 * Copyright (C) 2005-2009 Mikael Berthe <mikael@lilotux.net> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or (at | |
10 * your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, but | |
13 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
15 * General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
20 * USA | |
21 */ | |
29 | 22 |
1598 | 23 static void decline_invitation(event_muc_invitation *invitation, char *reason) |
29 | 24 { |
1598 | 25 // cut and paste from xmpp_room_invite |
26 LmMessage *m; | |
27 LmMessageNode *x, *y; | |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
28 |
1598 | 29 if (!invitation) return; |
30 if (!invitation->to || !invitation->from) return; | |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
31 |
1598 | 32 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
|
33 |
1598 | 34 x = lm_message_node_add_child(m->node, "x", NULL); |
35 lm_message_node_set_attribute(x, "xmlns", | |
36 "http://jabber.org/protocol/muc#user"); | |
444 | 37 |
1598 | 38 y = lm_message_node_add_child(x, "decline", NULL); |
39 lm_message_node_set_attribute(y, "to", invitation->from); | |
29 | 40 |
1598 | 41 if (reason) |
42 lm_message_node_add_child(y, "reason", reason); | |
164 | 43 |
1598 | 44 lm_connection_send(lconnection, m, NULL); |
45 lm_message_unref(m); | |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
46 } |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
47 |
1598 | 48 static int evscallback_invitation(eviqs *evp, guint evcontext) |
35 | 49 { |
1598 | 50 event_muc_invitation *invitation = evp->data; |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
51 |
1598 | 52 // Sanity check |
53 if (!invitation) { | |
54 // Shouldn't happen. | |
55 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); | |
56 return 0; | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
57 } |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
58 |
1598 | 59 if (evcontext == EVS_CONTEXT_TIMEOUT) { |
60 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.", evp->id); | |
61 goto evscallback_invitation_free; | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
62 } |
1598 | 63 if (evcontext == EVS_CONTEXT_CANCEL) { |
64 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id); | |
65 goto evscallback_invitation_free; | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
66 } |
1598 | 67 if (!(evcontext & EVS_CONTEXT_USER)) |
68 goto evscallback_invitation_free; | |
69 // Ok, let's work now. | |
70 // evcontext: 0, 1 == reject, accept | |
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
|
71 |
1598 | 72 if (evcontext & ~EVS_CONTEXT_USER) { |
73 char *nickname = default_muc_nickname(invitation->to); | |
74 xmpp_room_join(invitation->to, nickname, invitation->passwd); | |
75 g_free(nickname); | |
76 } else { | |
77 scr_LogPrint(LPRINT_LOGNORM, "Invitation to %s refused.", invitation->to); | |
78 decline_invitation(invitation, NULL); | |
124 | 79 } |
80 | |
1598 | 81 evscallback_invitation_free: |
82 g_free(invitation->to); | |
83 g_free(invitation->from); | |
84 g_free(invitation->passwd); | |
85 g_free(invitation->reason); | |
86 g_free(invitation); | |
87 evp->data = NULL; | |
88 return 0; | |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
89 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
90 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
91 // Join a MUC room |
1598 | 92 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
|
93 { |
1598 | 94 LmMessage *x; |
95 LmMessageNode *y; | |
643
dd73c3dad815
Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
642
diff
changeset
|
96 gchar *roomid; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
97 GSList *room_elt; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
98 |
1598 | 99 if (!lm_connection_is_authenticated(lconnection) || !room) return; |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
100 if (!nickname) return; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
101 |
643
dd73c3dad815
Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
642
diff
changeset
|
102 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
|
103 if (check_jid_syntax(roomid)) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
104 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
|
105 nickname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
106 g_free(roomid); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
107 return; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
108 } |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
109 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
110 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
|
111 // 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
|
112 if (!room_elt) { |
1355 | 113 room_elt = roster_add_user(room, NULL, NULL, ROSTER_TYPE_ROOM, |
114 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
|
115 } else { |
3ad6675caaf1
MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
645
diff
changeset
|
116 // 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
|
117 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
|
118 } |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
119 // 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
|
120 if (!buddy_getinsideroom(room_elt->data)) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
121 // 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
|
122 buddy_setnickname(room_elt->data, nickname); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
123 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
124 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
125 // Send the XML request |
1598 | 126 x = lm_message_new(roomid, LM_MESSAGE_TYPE_PRESENCE); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
127 |
1598 | 128 x = lm_message_new_presence(mystatus, roomid, mystatusmsg); |
129 y = lm_message_node_add_child(x->node, "x", NULL); | |
130 lm_message_node_set_attribute(y, "xmlns", "http://jabber.org/protocol/muc"); | |
131 if (passwd) | |
132 lm_message_node_add_child(y, "password", passwd); | |
133 | |
134 lm_connection_send(lconnection, x, NULL); | |
135 lm_message_unref(x); | |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
136 g_free(roomid); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
137 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
138 |
1598 | 139 // Invite a user to a MUC room |
449 | 140 // room syntax: "room@server" |
1598 | 141 // reason can be null. |
142 void xmpp_room_invite(const char *room, const char *fjid, const char *reason) | |
449 | 143 { |
1598 | 144 LmMessage *msg; |
145 LmMessageNode *x, *y; | |
449 | 146 |
1598 | 147 if (!lm_connection_is_authenticated(lconnection) || !room || !fjid) return; |
148 | |
149 msg = lm_message_new(room, LM_MESSAGE_TYPE_MESSAGE); | |
449 | 150 |
1598 | 151 x = lm_message_node_add_child(msg->node, "x", NULL); |
152 lm_message_node_set_attribute(x, "xmlns", | |
153 "http://jabber.org/protocol/muc#user"); | |
449 | 154 |
1598 | 155 y = lm_message_node_add_child(x, "invite", NULL); |
156 lm_message_node_set_attribute(y, "to", fjid); | |
157 | |
158 if (reason) | |
159 lm_message_node_add_child(y, "reason", reason); | |
160 | |
161 lm_connection_send(lconnection, msg, NULL); | |
162 lm_message_unref(msg); | |
449 | 163 } |
164 | |
1598 | 165 int xmpp_room_setattrib(const char *roomid, const char *fjid, |
166 const char *nick, struct role_affil ra, | |
167 const char *reason) | |
599 | 168 { |
1598 | 169 LmMessage *iq; |
170 LmMessageNode *query, *x; | |
599 | 171 |
1598 | 172 if (!lm_connection_is_authenticated(lconnection) || !roomid) return 1; |
1058 | 173 if (!fjid && !nick) return 1; |
568 | 174 |
175 if (check_jid_syntax((char*)roomid)) { | |
176 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid); | |
177 return 1; | |
178 } | |
1058 | 179 if (fjid && check_jid_syntax((char*)fjid)) { |
180 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", fjid); | |
568 | 181 return 1; |
182 } | |
183 | |
1058 | 184 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
|
185 return 1; // Shouldn't happen (jid mandatory when banning) |
568 | 186 |
1598 | 187 iq = lm_message_new_with_sub_type(roomid, LM_MESSAGE_TYPE_IQ, |
188 LM_MESSAGE_SUB_TYPE_SET); | |
189 query = lm_message_node_add_child(iq->node, "query", NULL); | |
190 lm_message_node_set_attribute(query, "xmlns", | |
191 "http://jabber.org/protocol/muc#admin"); | |
192 x = lm_message_node_add_child(query, "item", NULL); | |
568 | 193 |
1058 | 194 if (fjid) { |
1598 | 195 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
|
196 } else { // nickname |
1598 | 197 lm_message_node_set_attribute(x, "nick", nick); |
568 | 198 } |
584 | 199 |
200 if (ra.type == type_affil) | |
1598 | 201 lm_message_node_set_attribute(x, "affiliation", straffil[ra.val.affil]); |
584 | 202 else if (ra.type == type_role) |
1598 | 203 lm_message_node_set_attribute(x, "role", strrole[ra.val.role]); |
568 | 204 |
1598 | 205 if (reason) |
206 lm_message_node_add_child(x, "reason", reason); | |
568 | 207 |
1598 | 208 lm_connection_send(lconnection, iq, NULL); |
209 lm_message_unref(iq); | |
568 | 210 |
211 return 0; | |
212 } | |
486 | 213 |
1598 | 214 // Unlock a MUC room |
486 | 215 // room syntax: "room@server" |
1598 | 216 void xmpp_room_unlock(const char *room) |
486 | 217 { |
1598 | 218 LmMessageNode *y, *z; |
219 LmMessage *iq; | |
1363
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
220 |
1598 | 221 if (!lm_connection_is_authenticated(lconnection) || !room) return; |
1363
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
222 |
1598 | 223 iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ, |
224 LM_MESSAGE_SUB_TYPE_SET); | |
225 lm_message_node_set_attribute(iq->node, "xmlns", | |
226 "http://jabber.org/protocol/muc#owner"); | |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
227 |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
228 |
1598 | 229 y = lm_message_node_add_child(iq->node, "query", NULL); |
230 z = lm_message_node_add_child(y, "x", NULL); | |
231 lm_message_node_set_attribute(z, "xmlns", "jabber:x:data"); | |
232 lm_message_node_set_attribute(z, "type", "submit"); | |
1022
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
233 |
1598 | 234 lm_connection_send(lconnection, iq, NULL); |
235 lm_message_unref(iq); | |
1016 | 236 } |
237 | |
1598 | 238 // Destroy a MUC room |
239 // room syntax: "room@server" | |
240 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
|
241 { |
1598 | 242 LmMessage *iq; |
243 LmMessageNode *query, *x; | |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
244 |
1598 | 245 if (!lm_connection_is_authenticated(lconnection) || !room) return; |
1484
7b36b91a4388
New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents:
1476
diff
changeset
|
246 |
1598 | 247 iq = lm_message_new_with_sub_type(room, LM_MESSAGE_TYPE_IQ, |
248 LM_MESSAGE_SUB_TYPE_SET); | |
249 query = lm_message_node_add_child(iq->node, "query", NULL); | |
250 lm_message_node_set_attribute(query, "xmlns", | |
251 "http://jabber.org/protocol/muc#owner"); | |
252 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
|
253 |
1598 | 254 if (venue && *venue) |
255 lm_message_node_set_attribute(x, "jid", venue); | |
31 | 256 |
1598 | 257 if (reason) |
258 lm_message_node_add_child(x, "reason", reason); | |
35 | 259 |
1598 | 260 lm_connection_send(lconnection, iq, NULL); |
261 lm_message_unref(iq); | |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
262 } |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
263 |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
264 // muc_get_item_info(...) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
265 // Get room member's information from xmlndata. |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
266 // The variables must be initialized before calling this function, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
267 // because they are not touched if the relevant information is missing. |
1598 | 268 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
|
269 enum imrole *mbrole, enum imaffiliation *mbaffil, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
270 const char **mbjid, const char **mbnick, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
271 const char **actorjid, const char **reason) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
272 { |
1598 | 273 LmMessageNode *y, *z; |
274 const char *p; | |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
275 |
1598 | 276 y = lm_message_node_find_child(xmldata, "item"); |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
277 if (!y) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
278 return; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
279 |
1598 | 280 p = lm_message_node_get_attribute(y, "affiliation"); |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
281 if (p) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
282 if (!strcmp(p, "owner")) *mbaffil = affil_owner; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
283 else if (!strcmp(p, "admin")) *mbaffil = affil_admin; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
284 else if (!strcmp(p, "member")) *mbaffil = affil_member; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
285 else if (!strcmp(p, "outcast")) *mbaffil = affil_outcast; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
286 else if (!strcmp(p, "none")) *mbaffil = affil_none; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
287 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown affiliation \"%s\"", |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
288 from, p); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
289 } |
1598 | 290 p = lm_message_node_get_attribute(y, "role"); |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
291 if (p) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
292 if (!strcmp(p, "moderator")) *mbrole = role_moderator; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
293 else if (!strcmp(p, "participant")) *mbrole = role_participant; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
294 else if (!strcmp(p, "visitor")) *mbrole = role_visitor; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
295 else if (!strcmp(p, "none")) *mbrole = role_none; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
296 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown role \"%s\"", |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
297 from, p); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
298 } |
1598 | 299 *mbjid = lm_message_node_get_attribute(y, "jid"); |
300 *mbnick = lm_message_node_get_attribute(y, "nick"); | |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
301 // For kick/ban, there can be actor and reason tags |
1598 | 302 *reason = lm_message_node_get_child_value(y, "reason"); |
303 z = lm_message_node_find_child(y, "actor"); | |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
304 if (z) |
1598 | 305 *actorjid = lm_message_node_get_attribute(z, "jid"); |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
306 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
307 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
308 // muc_handle_join(...) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
309 // Handle a join event in a MUC room. |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
310 // 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
|
311 // 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
|
312 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
|
313 const char *roomjid, const char *ournick, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
314 enum room_printstatus printstatus, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
315 time_t usttime, int log_muc_conf) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
316 { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
317 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
|
318 gchar *mbuf; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
319 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
320 if (!buddy_getinsideroom(room_elt->data)) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
321 // 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
|
322 // 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
|
323 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
324 buddy_setinsideroom(room_elt->data, TRUE); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
325 // 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
|
326 scr_setmsgflag_if_needed(roomjid, FALSE); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
327 // Add a message to the tracelog file |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
328 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
|
329 scr_LogPrint(LPRINT_LOGNORM, "%s", mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
330 g_free(mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
331 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
|
332 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
333 // 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
|
334 if (strcmp(ournick, rname)) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
335 // 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
|
336 // 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
|
337 // so we use 0 here. |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
338 scr_WriteIncomingMessage(roomjid, mbuf, 0, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
339 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
340 if (log_muc_conf) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
341 hlog_write_message(roomjid, 0, -1, mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
342 g_free(mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
343 if (printstatus != status_none) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
344 mbuf = g_strdup_printf("%s has joined", rname); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
345 else |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
346 mbuf = NULL; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
347 new_member = TRUE; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
348 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
349 } else { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
350 mbuf = NULL; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
351 if (strcmp(ournick, rname)) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
352 if (printstatus != status_none) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
353 mbuf = g_strdup_printf("%s has joined", rname); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
354 new_member = TRUE; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
355 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
356 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
357 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
358 if (mbuf) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
359 guint msgflags = HBB_PREFIX_INFO; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
360 if (!settings_opt_get_int("muc_flag_joins")) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
361 msgflags |= HBB_PREFIX_NOFLAG; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
362 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
363 if (log_muc_conf) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
364 hlog_write_message(roomjid, 0, -1, mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
365 g_free(mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
366 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
367 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
368 return new_member; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
369 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
370 |
1598 | 371 static void handle_muc_presence(const char *from, LmMessageNode *xmldata, |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
372 const char *roomjid, const char *rname, |
1598 | 373 enum imstatus ust, const char *ustmsg, |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
374 time_t usttime, char bpprio) |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
375 { |
1598 | 376 LmMessageNode *y; |
377 const char *p; | |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
378 char *mbuf; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
379 const char *ournick; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
380 enum imrole mbrole = role_none; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
381 enum imaffiliation mbaffil = affil_none; |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
382 enum room_printstatus printstatus; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
383 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
|
384 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
|
385 const char *actorjid = NULL, *reason = NULL; |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
386 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
|
387 guint statuscode = 0; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
388 guint nickchange = 0; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
389 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
|
390 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
|
391 guint msgflags; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
392 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
393 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
|
394 |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
395 room_elt = roster_find(roomjid, jidsearch, 0); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
396 if (!room_elt) { |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
397 // Add room if it doesn't already exist |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
398 // 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
|
399 // network issue?) |
1355 | 400 room_elt = roster_add_user(roomjid, NULL, NULL, ROSTER_TYPE_ROOM, |
401 sub_none, -1); | |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
402 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
|
403 } else { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
404 // 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
|
405 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
406 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
407 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
408 // Get room member's information |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
409 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
|
410 &actorjid, &reason); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
411 |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
412 // Get our room nickname |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
413 ournick = buddy_getnickname(room_elt->data); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
414 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
415 if (!ournick) { |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
416 // It shouldn't happen, probably a server issue |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
417 mbuf = g_strdup_printf("Unexpected groupchat packet!"); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
418 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
419 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
|
420 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
|
421 g_free(mbuf); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
422 // Send back an unavailable packet |
1598 | 423 xmpp_setstatus(offline, roomjid, "", TRUE); |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
424 scr_DrawRoster(); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
425 return; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
426 } |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
427 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
428 // 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
|
429 // 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
|
430 // 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
|
431 // 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
|
432 // 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
|
433 // 321,322,332: the user has been removed from the room |
1598 | 434 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
|
435 if (y) { |
1598 | 436 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
|
437 if (p) |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
438 statuscode = atoi(p); |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
439 } |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
440 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
441 // Get the room's "print_status" settings |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
442 printstatus = buddy_getprintstatus(room_elt->data); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
443 if (printstatus == status_default) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
444 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
|
445 if (printstatus > 3) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
446 printstatus = status_default; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
447 } |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
448 |
1396
8f9928839a36
Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents:
1395
diff
changeset
|
449 // 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
|
450 if (statuscode == 201) |
1598 | 451 xmpp_room_unlock(roomjid); |
1396
8f9928839a36
Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents:
1395
diff
changeset
|
452 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
453 // 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
|
454 if (statuscode == 303 && mbnick) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
455 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
|
456 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
|
457 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
1166
c4da23bf8958
Add option 'muc_flag_joins'
Mikael Berthe <mikael@lilotux.net>
parents:
1164
diff
changeset
|
458 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
|
459 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
|
460 g_free(mbuf); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
461 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
|
462 // Maybe it's _our_ nickname... |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
463 if (ournick && !strcmp(rname, ournick)) |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
464 buddy_setnickname(room_elt->data, mbnick); |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
465 nickchange = TRUE; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
466 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
467 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
468 // Check for departure/arrival |
1161
45d3b9dda43d
Fix a MUC problem with some servers
Mikael Berthe <mikael@lilotux.net>
parents:
1132
diff
changeset
|
469 if (!mbnick && ust == offline) { |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
470 // Somebody is leaving |
586 | 471 enum { leave=0, kick, ban } how = leave; |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
472 bool we_left = FALSE; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
473 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
474 if (statuscode == 307) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
475 how = kick; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
476 else if (statuscode == 301) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
477 how = ban; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
478 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
479 // 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
|
480 if (ournick && !strcmp(rname, ournick)) { |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
481 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
|
482 buddy_setinsideroom(room_elt->data, FALSE); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
483 buddy_setnickname(room_elt->data, NULL); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
484 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
|
485 buddy_settopic(room_elt->data, NULL); |
721
9cf31c9b1dc4
Use room topic as a description in the chat status line
Mikael Berthe <mikael@lilotux.net>
parents:
713
diff
changeset
|
486 scr_UpdateChatStatus(FALSE); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
487 update_roster = TRUE; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
488 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
489 |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
490 // The message depends on _who_ left, and _how_ |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
491 if (how) { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
492 gchar *mbuf_end; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
493 // Forced leave |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
494 if (actorjid) { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
495 mbuf_end = g_strdup_printf("%s from %s by <%s>.\nReason: %s", |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
496 (how == ban ? "banned" : "kicked"), |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
497 roomjid, actorjid, reason); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
498 } else { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
499 mbuf_end = g_strdup_printf("%s from %s.", |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
500 (how == ban ? "banned" : "kicked"), |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
501 roomjid); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
502 } |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
503 if (we_left) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
504 mbuf = g_strdup_printf("You have been %s", mbuf_end); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
505 else |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
506 mbuf = g_strdup_printf("%s has been %s", rname, mbuf_end); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
507 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
508 g_free(mbuf_end); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
509 } else { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
510 // Natural leave |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
511 if (we_left) { |
1598 | 512 LmMessageNode *destroynode = lm_message_node_find_child(xmldata, |
513 "destroy"); | |
616
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
514 if (destroynode) { |
1598 | 515 if ((reason = lm_message_node_get_child_value(destroynode, |
516 "reason"))) { | |
616
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
517 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
|
518 "the room has been destroyed: %s", |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
519 roomjid, reason); |
616
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
520 } else { |
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
521 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
|
522 "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
|
523 } |
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
524 } else { |
599 | 525 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
|
526 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
527 } 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
|
528 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
|
529 // 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
|
530 // 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
|
531 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
|
532 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
|
533 } 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
|
534 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
|
535 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
|
536 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
|
537 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
|
538 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
539 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
540 } |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
541 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
542 // 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
|
543 // 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
|
544 if (we_left || printstatus != status_none) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
545 msgflags = HBB_PREFIX_INFO; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
546 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
|
547 msgflags |= HBB_PREFIX_NOFLAG; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
548 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
549 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
550 |
1166
c4da23bf8958
Add option 'muc_flag_joins'
Mikael Berthe <mikael@lilotux.net>
parents:
1164
diff
changeset
|
551 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
|
552 hlog_write_message(roomjid, 0, -1, mbuf); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
553 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
554 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
|
555 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
|
556 g_free(mbuf); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
557 return; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
558 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
559 g_free(mbuf); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
560 } 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
|
561 ust != offline) { |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
562 // Somebody is joining |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
563 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
|
564 printstatus, usttime, log_muc_conf); |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
565 } else { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
566 // This is a simple member status change |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
567 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
568 if (printstatus == status_all && !nickchange) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
569 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
|
570 imstatus2char[ust], ((ustmsg) ? ustmsg : "")); |
1380
605f9e1f9f76
Add missing PREFIX_NOFLAG flag...
Mikael Berthe <mikael@lilotux.net>
parents:
1379
diff
changeset
|
571 scr_WriteIncomingMessage(roomjid, mbuf, usttime, |
605f9e1f9f76
Add missing PREFIX_NOFLAG flag...
Mikael Berthe <mikael@lilotux.net>
parents:
1379
diff
changeset
|
572 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
|
573 g_free(mbuf); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
574 } |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
575 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
576 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
577 // Sanity check, shouldn't happen... |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
578 if (!rname) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
579 return; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
580 |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
581 // Update room member status |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
582 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
|
583 mbrole, mbaffil, mbjid); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
584 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
585 autowhois = buddy_getautowhois(room_elt->data); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
586 if (autowhois == autowhois_default) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
587 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
|
588 autowhois_on : autowhois_off); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
589 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
590 if (new_member && autowhois == autowhois_on) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
591 // FIXME: This will fail for some UTF-8 nicknames. |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
592 gchar *joiner_nick = from_utf8(rname); |
1415
317f8d181626
Rename command public functions
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
593 cmd_room_whois(room_elt->data, joiner_nick, FALSE); |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
594 g_free(joiner_nick); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
595 } |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
596 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
597 scr_DrawRoster(); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
598 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
599 |
1598 | 600 static void roompresence(gpointer room, void *presencedata) |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
601 { |
1598 | 602 const char *bjid; |
603 const char *nickname; | |
604 char *to; | |
605 struct T_presence *pres = presencedata; | |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
606 |
1598 | 607 if (!buddy_getinsideroom(room)) |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
608 return; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
609 |
1598 | 610 bjid = buddy_getjid(room); |
611 if (!bjid) return; | |
612 nickname = buddy_getnickname(room); | |
613 if (!nickname) return; | |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
614 |
1598 | 615 to = g_strdup_printf("%s/%s", bjid, nickname); |
616 xmpp_setstatus(pres->st, to, pres->msg, TRUE); | |
617 g_free(to); | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
618 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
619 |
1330
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
620 // got_invite(from, to, reason, passwd) |
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
621 // 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
|
622 // "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
|
623 // be provided. |
1598 | 624 static void got_invite(const char* from, const char *to, const char* reason, |
625 const char* passwd) | |
1128 | 626 { |
627 eviqs *evn; | |
628 event_muc_invitation *invitation; | |
629 GString *sbuf; | |
1236
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
630 char *barejid; |
1237
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
631 GSList *room_elt; |
1128 | 632 |
633 sbuf = g_string_new(""); | |
634 if (reason) { | |
635 g_string_printf(sbuf, | |
636 "Received an invitation to <%s>, from <%s>, reason: %s", | |
637 to, from, reason); | |
638 } else { | |
639 g_string_printf(sbuf, "Received an invitation to <%s>, from <%s>", | |
640 to, from); | |
641 } | |
1236
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
642 |
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
643 barejid = jidtodisp(from); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
644 scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0); |
1128 | 645 scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str); |
646 | |
647 evn = evs_new(EVS_TYPE_INVITATION, EVS_MAX_TIMEOUT); | |
648 if (evn) { | |
649 evn->callback = &evscallback_invitation; | |
650 invitation = g_new(event_muc_invitation, 1); | |
651 invitation->to = g_strdup(to); | |
652 invitation->from = g_strdup(from); | |
653 invitation->passwd = g_strdup(passwd); | |
654 invitation->reason = g_strdup(reason); | |
655 evn->data = invitation; | |
656 evn->desc = g_strdup_printf("<%s> invites you to %s ", from, to); | |
657 g_string_printf(sbuf, "Please use /event %s accept|reject", evn->id); | |
658 } else { | |
659 g_string_printf(sbuf, "Unable to create a new event!"); | |
660 } | |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
661 scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0); |
1128 | 662 scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str); |
663 g_string_free(sbuf, TRUE); | |
1330
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
664 g_free(barejid); |
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
665 |
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
666 // 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
|
667 barejid = jidtodisp(to); |
1237
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
668 room_elt = roster_find(barejid, jidsearch, 0); |
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
669 if (room_elt) |
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
670 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
671 |
1236
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
672 g_free(barejid); |
1128 | 673 } |
674 | |
1598 | 675 |
1128 | 676 // Specific MUC message handling (for example invitation processing) |
1598 | 677 static void got_muc_message(const char *from, LmMessageNode *x) |
1128 | 678 { |
1598 | 679 LmMessageNode *invite = lm_message_node_get_child(x, "invite"); |
1128 | 680 if (invite) |
681 { | |
1598 | 682 const char *invite_from; |
683 const char *reason = NULL; | |
684 const char *password = NULL; | |
1128 | 685 |
1598 | 686 invite_from = lm_message_node_get_attribute(invite, "from"); |
687 reason = lm_message_node_get_child_value(invite, "reason"); | |
688 password = lm_message_node_get_child_value(invite, "password"); | |
1128 | 689 if (invite_from) |
690 got_invite(invite_from, from, reason, password); | |
691 } | |
692 // TODO | |
693 // handle status code = 100 ( not anonymous ) | |
694 // handle status code = 170 ( changement de config ) | |
695 // 10.2.1 Notification of Configuration Changes | |
696 // declined invitation | |
697 } | |
698 | |
1599 | 699 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |