Mercurial > hg
annotate mcabber/src/jabglue.c @ 1438:c5d937d5530b
g_hash_table_get_keys() is only in glib >= 2.14
This patch replaces g_hash_table_get_keys() with a foreach loop.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Mon, 25 Feb 2008 21:39:07 +0100 |
parents | 9bf7f3ddff10 |
children | fd09c95bc2b5 |
rev | line source |
---|---|
29 | 1 /* |
2 * jabglue.c -- Jabber protocol handling | |
393 | 3 * |
1414 | 4 * Copyright (C) 2005-2008 Mikael Berthe <mikael@lilotux.net> |
29 | 5 * Parts come from the centericq project: |
6 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or (at | |
11 * your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, but | |
14 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 * General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
21 * USA | |
22 */ | |
23 | |
24 #include "../libjabber/jabber.h" | |
25 #include "jabglue.h" | |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
26 #include "jab_priv.h" |
81 | 27 #include "roster.h" |
29 | 28 #include "screen.h" |
113 | 29 #include "hooks.h" |
29 | 30 #include "utils.h" |
294
871e53769084
Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
31 #include "settings.h" |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
32 #include "hbuf.h" |
478
47cfa3779549
MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents:
475
diff
changeset
|
33 #include "histolog.h" |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
34 #include "commands.h" |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
35 #include "pgp.h" |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
36 #include "otr.h" |
29 | 37 |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
38 #ifdef ENABLE_FIFO |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
39 # include "fifo.h" |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
40 #endif |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
41 |
29 | 42 #define JABBERPORT 5222 |
43 #define JABBERSSLPORT 5223 | |
44 | |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
45 #define RECONNECTION_TIMEOUT 60L |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
46 |
29 | 47 jconn jc; |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
48 guint AutoConnection; |
578 | 49 enum enum_jstate jstate; |
29 | 50 |
353
3fe43f6daa5a
Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
51 char imstatus2char[imstatus_size+1] = { |
1311
0dda8238af21
Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents:
1310
diff
changeset
|
52 '_', 'o', 'f', 'd', 'n', 'a', 'i', '\0' |
46 | 53 }; |
54 | |
1378 | 55 static char *imstatus_showmap[] = { |
56 "", | |
57 "", | |
58 "chat", | |
59 "dnd", | |
60 "xa", | |
61 "away", | |
62 "" | |
63 }; | |
64 | |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
65 static time_t LastPingTime; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
66 static unsigned int KeepaliveDelay; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
67 static enum imstatus mystatus = offline; |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
68 static enum imstatus mywantedstatus = available; |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
69 static gchar *mystatusmsg; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
70 static unsigned char online; |
29 | 71 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
72 static void statehandler(jconn, int); |
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
73 static void packethandler(jconn, jpacket); |
1128 | 74 static void handle_state_events(char* from, xmlnode xmldata); |
75 | |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
76 static int evscallback_invitation(eviqs *evp, guint evcontext); |
31 | 77 |
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
78 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
79 static void logger(jconn j, int io, const char *buf) |
31 | 80 { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
81 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
31 | 82 } |
83 | |
192 | 84 // jidtodisp(jid) |
85 // Strips the resource part from the jid | |
86 // The caller should g_free the result after use. | |
1058 | 87 char *jidtodisp(const char *fjid) |
29 | 88 { |
89 char *ptr; | |
165 | 90 char *alias; |
91 | |
1058 | 92 alias = g_strdup(fjid); |
165 | 93 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
94 if ((ptr = strchr(alias, JID_RESOURCE_SEPARATOR)) != NULL) { |
29 | 95 *ptr = 0; |
96 } | |
97 return alias; | |
98 } | |
99 | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
100 char *compose_jid(const char *username, const char *servername, |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
101 const char *resource) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
102 { |
1383 | 103 char *fjid; |
104 | |
1385
7ca57f7e313c
Fix typo in changeset d9606bd03144
Mikael Berthe <mikael@lilotux.net>
parents:
1384
diff
changeset
|
105 if (!strchr(username, JID_DOMAIN_SEPARATOR)) { |
1383 | 106 fjid = g_strdup_printf("%s%c%s%c%s", username, |
107 JID_DOMAIN_SEPARATOR, servername, | |
108 JID_RESOURCE_SEPARATOR, resource); | |
109 } else { | |
110 fjid = g_strdup_printf("%s%c%s", username, | |
111 JID_RESOURCE_SEPARATOR, resource); | |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
112 } |
1058 | 113 return fjid; |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
114 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
115 |
1413 | 116 unsigned char jb_getonline(void) |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
117 { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
118 return online; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
119 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
120 |
1058 | 121 jconn jb_connect(const char *fjid, const char *server, unsigned int port, |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
122 int ssl, const char *pass) |
29 | 123 { |
124 if (!port) { | |
125 if (ssl) | |
126 port = JABBERSSLPORT; | |
127 else | |
128 port = JABBERPORT; | |
129 } | |
130 | |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
131 jb_disconnect(); |
29 | 132 |
1058 | 133 if (!fjid) return jc; |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
134 |
1058 | 135 jc = jab_new((char*)fjid, (char*)pass, (char*)server, port, ssl); |
29 | 136 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
137 /* These 3 functions can deal with a NULL jc, no worry... */ |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
138 jab_logger(jc, logger); |
29 | 139 jab_packet_handler(jc, &packethandler); |
140 jab_state_handler(jc, &statehandler); | |
141 | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
142 if (jc && jc->user) { |
112 | 143 online = TRUE; |
29 | 144 jstate = STATE_CONNECTING; |
145 statehandler(0, -1); | |
146 jab_start(jc); | |
147 } | |
148 | |
149 return jc; | |
150 } | |
151 | |
152 void jb_disconnect(void) | |
153 { | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
154 if (!jc) return; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
155 |
668
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
156 if (online) { |
1354
c373ff3fe7e1
Add pre-disconnect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1347
diff
changeset
|
157 // Launch pre-disconnect internal hook |
c373ff3fe7e1
Add pre-disconnect internal hook
Mikael Berthe <mikael@lilotux.net>
parents:
1347
diff
changeset
|
158 hook_execute_internal("hook-pre-disconnect"); |
668
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
159 // Announce it to everyone else |
1050
ea71d31a2607
PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
1046
diff
changeset
|
160 jb_setstatus(offline, NULL, "", FALSE); |
668
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
161 // End the XML flow |
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
162 jb_send_raw("</stream:stream>"); |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
163 /* |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
164 // Free status message |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
165 g_free(mystatusmsg); |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
166 mystatusmsg = NULL; |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
167 */ |
668
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
168 } |
634
f3c05d5fe459
Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
633
diff
changeset
|
169 |
f3c05d5fe459
Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
633
diff
changeset
|
170 // Announce it to the user |
29 | 171 statehandler(jc, JCONN_STATE_OFF); |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
172 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
173 jab_delete(jc); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
174 jc = NULL; |
29 | 175 } |
176 | |
112 | 177 inline void jb_reset_keepalive() |
178 { | |
179 time(&LastPingTime); | |
180 } | |
181 | |
436 | 182 void jb_send_raw(const char *str) |
183 { | |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
449
diff
changeset
|
184 if (jc && online && str) |
436 | 185 jab_send_raw(jc, str); |
186 } | |
187 | |
29 | 188 void jb_keepalive() |
189 { | |
113 | 190 if (jc && online) |
112 | 191 jab_send_raw(jc, " \t "); |
192 jb_reset_keepalive(); | |
193 } | |
194 | |
195 void jb_set_keepalive_delay(unsigned int delay) | |
196 { | |
197 KeepaliveDelay = delay; | |
29 | 198 } |
199 | |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
200 // check_connection() |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
201 // Check if we've been disconnected for a while (predefined timeout), |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
202 // and if so try to reconnect. |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
203 static void check_connection(void) |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
204 { |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
205 static time_t disconnection_timestamp = 0L; |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
206 time_t now; |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
207 |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
208 // Maybe we're voluntarily offline... |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
209 if (!AutoConnection) |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
210 return; |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
211 |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
212 // Are we totally disconnected? |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
213 if (jc && jc->state != JCONN_STATE_OFF) { |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
214 disconnection_timestamp = 0L; |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
215 return; |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
216 } |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
217 |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
218 time(&now); |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
219 if (!disconnection_timestamp) { |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
220 disconnection_timestamp = now; |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
221 return; |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
222 } |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
223 |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
224 // If the reconnection_timeout is reached, try to reconnect. |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
225 if (now > disconnection_timestamp + RECONNECTION_TIMEOUT) { |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
226 mcabber_connect(); |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
227 disconnection_timestamp = 0L; |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
228 } |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
229 } |
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
230 |
29 | 231 void jb_main() |
232 { | |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
233 time_t now; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
234 fd_set fds; |
1058 | 235 long tmout; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
236 struct timeval tv; |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
237 static time_t last_eviqs_check = 0L; |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
238 int maxfd; |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
239 #ifdef ENABLE_FIFO |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
240 int fifofd; |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
241 #endif |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
242 |
406 | 243 if (!online) { |
419 | 244 safe_usleep(10000); |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
245 check_connection(); |
406 | 246 return; |
247 } | |
164 | 248 |
29 | 249 if (jc && jc->state == JCONN_STATE_CONNECTING) { |
419 | 250 safe_usleep(75000); |
29 | 251 jab_start(jc); |
252 return; | |
253 } | |
254 | |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
255 FD_ZERO(&fds); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
256 FD_SET(0, &fds); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
257 FD_SET(jc->fd, &fds); |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
258 maxfd = jc->fd; |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
259 |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
260 #ifdef ENABLE_FIFO |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
261 fifofd = fifo_get_fd(); |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
262 if (fifofd > 0) { |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
263 FD_SET(fifofd, &fds); |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
264 maxfd = MAX(maxfd, fifofd); |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
265 } |
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
266 #endif |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
267 |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
268 tv.tv_sec = 60; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
269 tv.tv_usec = 0; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
270 |
940 | 271 time(&now); |
272 | |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
273 if (KeepaliveDelay) { |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
274 if (now >= LastPingTime + (time_t)KeepaliveDelay) |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
275 tv.tv_sec = 0; |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
276 else |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
277 tv.tv_sec = LastPingTime + (time_t)KeepaliveDelay - now; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
278 } |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
279 |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
280 // Check auto-away timeout |
1058 | 281 tmout = scr_GetAutoAwayTimeout(now); |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
282 if (tv.tv_sec > tmout) |
1058 | 283 tv.tv_sec = tmout; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
284 |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
285 #if defined JEP0022 || defined JEP0085 |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
286 // Check composing timeout |
1058 | 287 tmout = scr_GetChatStatesTimeout(now); |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
288 if (tv.tv_sec > tmout) |
1058 | 289 tv.tv_sec = tmout; |
991
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
290 #endif |
ef10906691bb
Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents:
990
diff
changeset
|
291 |
940 | 292 if (!tv.tv_sec) |
293 tv.tv_usec = 350000; | |
294 | |
295 scr_DoUpdate(); | |
1426
a64778f5f26b
Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents:
1419
diff
changeset
|
296 if (select(maxfd + 1, &fds, NULL, NULL, &tv) > 0) { |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
297 if (FD_ISSET(jc->fd, &fds)) |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
298 jab_poll(jc, 0); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
299 } |
29 | 300 |
301 if (jstate == STATE_CONNECTING) { | |
302 if (jc) { | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
303 eviqs *iqn; |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
304 xmlnode z; |
29 | 305 |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
306 iqn = iqs_new(JPACKET__GET, NS_AUTH, "auth", IQS_DEFAULT_TIMEOUT); |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
307 iqn->callback = &iqscallback_auth; |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
308 |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
309 z = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
310 "username"); |
29 | 311 xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1); |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
312 jab_send(jc, iqn->xmldata); |
29 | 313 |
314 jstate = STATE_GETAUTH; | |
315 } | |
316 | |
317 if (!jc || jc->state == JCONN_STATE_OFF) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
318 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server"); |
112 | 319 online = FALSE; |
29 | 320 } |
321 } | |
322 | |
323 if (!jc) { | |
324 statehandler(jc, JCONN_STATE_OFF); | |
325 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) { | |
326 statehandler(jc, JCONN_STATE_OFF); | |
327 } | |
112 | 328 |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
329 time(&now); |
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
330 |
756
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
331 // Check for EV & IQ requests timeouts |
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
332 if (now > last_eviqs_check + 20) { |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
333 iqs_check_timeout(now); |
756
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
334 evs_check_timeout(now); |
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
335 last_eviqs_check = now; |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
336 } |
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
337 |
112 | 338 // Keepalive |
339 if (KeepaliveDelay) { | |
735 | 340 if (now > LastPingTime + (time_t)KeepaliveDelay) |
112 | 341 jb_keepalive(); |
342 } | |
29 | 343 } |
344 | |
116 | 345 inline enum imstatus jb_getstatus() |
346 { | |
347 return mystatus; | |
348 } | |
349 | |
519
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
350 inline const char *jb_getstatusmsg() |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
351 { |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
352 return mystatusmsg; |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
353 } |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
354 |
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
355 inline void update_last_use(void) |
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
356 { |
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
357 iqlast = time(NULL); |
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
358 } |
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
359 |
1215
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
360 // insert_entity_capabilities(presence_stanza) |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
361 // Entity Capabilities (XEP-0115) |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
362 static void insert_entity_capabilities(xmlnode x) |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
363 { |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
364 xmlnode y; |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
365 const char *ver = entity_version(); |
1255
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
366 char *exts, *exts2; |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
367 |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
368 exts = NULL; |
1215
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
369 |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
370 y = xmlnode_insert_tag(x, "c"); |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
371 xmlnode_put_attrib(y, "xmlns", NS_CAPS); |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
372 xmlnode_put_attrib(y, "node", MCABBER_CAPS_NODE); |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
373 xmlnode_put_attrib(y, "ver", ver); |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
374 #ifdef JEP0085 |
1255
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
375 if (!chatstates_disabled) { |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
376 exts2 = g_strjoin(" ", "csn", exts, NULL); |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
377 g_free(exts); |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
378 exts = exts2; |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
379 } |
1215
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
380 #endif |
1255
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
381 if (!settings_opt_get_int("iq_last_disable")) { |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
382 exts2 = g_strjoin(" ", "iql", exts, NULL); |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
383 g_free(exts); |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
384 exts = exts2; |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
385 } |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
386 if (exts) { |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
387 xmlnode_put_attrib(y, "ext", exts); |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
388 g_free(exts); |
ceada40bbe20
Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents:
1254
diff
changeset
|
389 } |
1215
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
390 } |
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
391 |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
392 static void roompresence(gpointer room, void *presencedata) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
393 { |
1058 | 394 const char *bjid; |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
395 const char *nickname; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
396 char *to; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
397 struct T_presence *pres = presencedata; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
398 |
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
651
diff
changeset
|
399 if (!buddy_getinsideroom(room)) |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
400 return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
401 |
1058 | 402 bjid = buddy_getjid(room); |
403 if (!bjid) return; | |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
404 nickname = buddy_getnickname(room); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
405 if (!nickname) return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
406 |
1058 | 407 to = g_strdup_printf("%s/%s", bjid, nickname); |
1050
ea71d31a2607
PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
1046
diff
changeset
|
408 jb_setstatus(pres->st, to, pres->msg, TRUE); |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
409 g_free(to); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
410 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
411 |
534 | 412 // presnew(status, recipient, message) |
413 // Create an xmlnode with default presence attributes | |
414 // Note: the caller must free the node after use | |
415 static xmlnode presnew(enum imstatus st, const char *recipient, | |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
416 const char *msg) |
29 | 417 { |
534 | 418 unsigned int prio; |
116 | 419 xmlnode x; |
420 | |
421 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); | |
29 | 422 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
423 if (recipient) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
424 xmlnode_put_attrib(x, "to", recipient); |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
425 } |
444 | 426 |
29 | 427 switch(st) { |
428 case away: | |
1378 | 429 case notavail: |
29 | 430 case dontdisturb: |
431 case freeforchat: | |
1378 | 432 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), |
433 imstatus_showmap[st], (unsigned) -1); | |
29 | 434 break; |
435 | |
436 case invisible: | |
437 xmlnode_put_attrib(x, "type", "invisible"); | |
438 break; | |
51 | 439 |
118 | 440 case offline: |
441 xmlnode_put_attrib(x, "type", "unavailable"); | |
442 break; | |
443 | |
51 | 444 default: |
445 break; | |
29 | 446 } |
447 | |
1419
fb438482b28e
New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents:
1415
diff
changeset
|
448 if (st == away || st == notavail) |
fb438482b28e
New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents:
1415
diff
changeset
|
449 prio = settings_opt_get_int("priority_away"); |
fb438482b28e
New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents:
1415
diff
changeset
|
450 else |
fb438482b28e
New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents:
1415
diff
changeset
|
451 prio = settings_opt_get_int("priority"); |
fb438482b28e
New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents:
1415
diff
changeset
|
452 |
272 | 453 if (prio) { |
454 char strprio[8]; | |
842 | 455 snprintf(strprio, 8, "%d", (int)prio); |
29 | 456 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), |
534 | 457 strprio, (unsigned) -1); |
458 } | |
459 | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
460 if (msg) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
461 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg, (unsigned) -1); |
29 | 462 |
534 | 463 return x; |
464 } | |
465 | |
1050
ea71d31a2607
PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
1046
diff
changeset
|
466 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg, |
ea71d31a2607
PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
1046
diff
changeset
|
467 int do_not_sign) |
534 | 468 { |
469 xmlnode x; | |
470 | |
521 | 471 if (msg) { |
472 // The status message has been specified. We'll use it, unless it is | |
473 // "-" which is a special case (option meaning "no status message"). | |
474 if (!strcmp(msg, "-")) | |
475 msg = ""; | |
476 } else { | |
477 // No status message specified; we'll use: | |
478 // a) the default status message (if provided by the user); | |
479 // b) the current status message; | |
480 // c) no status message (i.e. an empty one). | |
481 msg = settings_get_status_msg(st); | |
482 if (!msg) { | |
483 if (mystatusmsg) | |
484 msg = mystatusmsg; | |
485 else | |
486 msg = ""; | |
487 } | |
488 } | |
29 | 489 |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
490 // Only send the packet if we're online. |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
491 // (But we want to update internal status even when disconnected, |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
492 // in order to avoid some problems during network failures) |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
493 if (online) { |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
494 const char *s_msg = (st != invisible ? msg : NULL); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
495 x = presnew(st, recipient, s_msg); |
1215
80c095886fb5
Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents:
1213
diff
changeset
|
496 insert_entity_capabilities(x); // Entity Capabilities (XEP-0115) |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
497 #ifdef HAVE_GPGME |
1052
c8a8edd5c50d
PGP: Sign empty <status/> presence elements
Mikael Berthe <mikael@lilotux.net>
parents:
1050
diff
changeset
|
498 if (!do_not_sign && gpg_enabled()) { |
c8a8edd5c50d
PGP: Sign empty <status/> presence elements
Mikael Berthe <mikael@lilotux.net>
parents:
1050
diff
changeset
|
499 char *signature; |
c8a8edd5c50d
PGP: Sign empty <status/> presence elements
Mikael Berthe <mikael@lilotux.net>
parents:
1050
diff
changeset
|
500 signature = gpg_sign(s_msg ? s_msg : ""); |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
501 if (signature) { |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
502 xmlnode y; |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
503 y = xmlnode_insert_tag(x, "x"); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
504 xmlnode_put_attrib(y, "xmlns", NS_SIGNED); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
505 xmlnode_insert_cdata(y, signature, (unsigned) -1); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
506 g_free(signature); |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
507 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
508 } |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
509 #endif |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
510 jab_send(jc, x); |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
511 xmlnode_free(x); |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
512 } |
29 | 513 |
444 | 514 // If we didn't change our _global_ status, we are done |
515 if (recipient) return; | |
516 | |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
517 if (online) { |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
518 // Send presence to chatrooms |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
519 if (st != invisible) { |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
520 struct T_presence room_presence; |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
521 room_presence.st = st; |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
522 room_presence.msg = msg; |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
523 foreach_buddy(ROSTER_TYPE_ROOM, &roompresence, &room_presence); |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
524 } |
1365 | 525 |
526 // We'll have to update the roster if we switch to/from offline because | |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
527 // we don't know the presences of buddies when offline... |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
528 if (mystatus == offline || st == offline) |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
529 update_roster = TRUE; |
164 | 530 |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
531 hk_mystatuschange(0, mystatus, st, (st != invisible ? msg : "")); |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
532 mystatus = st; |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
533 } |
1365 | 534 |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
535 if (st) |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
536 mywantedstatus = st; |
1365 | 537 |
521 | 538 if (msg != mystatusmsg) { |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
539 g_free(mystatusmsg); |
521 | 540 if (*msg) |
541 mystatusmsg = g_strdup(msg); | |
542 else | |
543 mystatusmsg = NULL; | |
544 } | |
713 | 545 |
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
546 if (!Autoaway) |
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
547 update_last_use(); |
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
548 |
713 | 549 // Update status line |
724
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
721
diff
changeset
|
550 scr_UpdateMainStatus(TRUE); |
29 | 551 } |
552 | |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
553 // jb_setprevstatus() |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
554 // Set previous status. This wrapper function is used after a disconnection. |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
555 inline void jb_setprevstatus(void) |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
556 { |
1050
ea71d31a2607
PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
1046
diff
changeset
|
557 jb_setstatus(mywantedstatus, NULL, mystatusmsg, FALSE); |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
558 } |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
559 |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
560 // new_msgid() |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
561 // Generate a new id string. The caller should free it. |
1071
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
562 // The caller must free the string when no longer needed. |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
563 static char *new_msgid(void) |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
564 { |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
565 static guint msg_idn; |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
566 time_t now; |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
567 time(&now); |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
568 if (!msg_idn) |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
569 srand(now); |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
570 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0))); |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
571 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L)); |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
572 } |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
573 |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
574 // jb_send_msg(jid, text, type, subject, msgid, *encrypted, type_overwrite) |
1197 | 575 // When encrypted is not NULL, the function set *encrypted to 1 if the |
576 // message has been PGP-encrypted. If encryption enforcement is set and | |
577 // encryption fails, *encrypted is set to -1. | |
1058 | 578 void jb_send_msg(const char *fjid, const char *text, int type, |
1305
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
579 const char *subject, const char *msgid, gint *encrypted, |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
580 const char *type_overwrite) |
35 | 581 { |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
582 xmlnode x; |
1305
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
583 const gchar *strtype; |
1304 | 584 #ifdef HAVE_LIBOTR |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
585 int otr_msg = 0; |
1304 | 586 #endif |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
587 #if defined HAVE_GPGME || defined JEP0022 || defined JEP0085 |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
588 char *rname, *barejid; |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
589 GSList *sl_buddy; |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
590 #endif |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
591 #if defined JEP0022 || defined JEP0085 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
592 xmlnode event; |
997 | 593 guint use_jep85 = 0; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
594 struct jep0085 *jep85 = NULL; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
595 #endif |
1071
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
596 #if defined JEP0022 |
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
597 gchar *nmsgid = NULL; |
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
598 #endif |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
599 gchar *enc = NULL; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
600 |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1053
diff
changeset
|
601 if (encrypted) |
1197 | 602 *encrypted = 0; |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1053
diff
changeset
|
603 |
1435
9bf7f3ddff10
Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
604 if (!online) |
9bf7f3ddff10
Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
605 return; |
9bf7f3ddff10
Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
606 |
9bf7f3ddff10
Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
607 if (!text && type == ROSTER_TYPE_USER) |
9bf7f3ddff10
Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents:
1426
diff
changeset
|
608 return; |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
609 |
1305
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
610 if (type_overwrite) |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
611 strtype = type_overwrite; |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
612 else { |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
613 if (type == ROSTER_TYPE_ROOM) |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
614 strtype = TMSG_GROUPCHAT; |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
615 else |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
616 strtype = TMSG_CHAT; |
9bc68473f8a3
-n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1304
diff
changeset
|
617 } |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
618 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
619 #if defined HAVE_GPGME || defined HAVE_LIBOTR || defined JEP0022 || defined JEP0085 |
1058 | 620 rname = strchr(fjid, JID_RESOURCE_SEPARATOR); |
621 barejid = jidtodisp(fjid); | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
622 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
623 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
624 // If we can get a resource name, we use it. Else we use NULL, |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
625 // which hopefully will give us the most likely resource. |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
626 if (rname) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
627 rname++; |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
628 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
629 #ifdef HAVE_LIBOTR |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
630 if (otr_enabled()) { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
631 if (msgid && strcmp(msgid, "otrinject") == 0) |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
632 msgid = NULL; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
633 else if (type == ROSTER_TYPE_USER) { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
634 otr_msg = otr_send((char **)&text, barejid); |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
635 if (!text) { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
636 g_free(barejid); |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
637 if (encrypted) |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
638 *encrypted = -1; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
639 return; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
640 } |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
641 } |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
642 if (otr_msg && encrypted) { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
643 *encrypted = 1; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
644 } |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
645 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
646 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
647 |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
648 #ifdef HAVE_GPGME |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
649 if (type == ROSTER_TYPE_USER && sl_buddy && gpg_enabled()) { |
1197 | 650 if (!settings_pgp_getdisabled(barejid)) { // not disabled for this contact? |
651 guint force; | |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
652 struct pgp_data *res_pgpdata; |
1197 | 653 force = settings_pgp_getforce(barejid); |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
654 res_pgpdata = buddy_resource_pgp(sl_buddy->data, rname); |
1197 | 655 if (force || (res_pgpdata && res_pgpdata->sign_keyid)) { |
656 /* Remote client has PGP support (we have a signature) | |
657 * OR encryption is enforced (force = TRUE). | |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
658 * If the contact has a specific KeyId, we'll use it; |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
659 * if not, we'll use the key used for the signature. |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
660 * Both keys should match, in theory (cf. XEP-0027). */ |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
661 const char *key; |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
662 key = settings_pgp_getkeyid(barejid); |
1197 | 663 if (!key && res_pgpdata) |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
664 key = res_pgpdata->sign_keyid; |
1197 | 665 if (key) |
666 enc = gpg_encrypt(text, key); | |
667 if (!enc && force) { | |
668 if (encrypted) | |
669 *encrypted = -1; | |
670 g_free(barejid); | |
671 return; | |
672 } | |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
673 } |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
674 } |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
675 } |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
676 #endif // HAVE_GPGME |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
677 |
1065
230dca34dbea
Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents:
1058
diff
changeset
|
678 g_free(barejid); |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
679 #endif // HAVE_GPGME || defined JEP0022 || defined JEP0085 |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
680 |
1306
a7d21918234c
Fix jb_send_msg() call in OTR
Mikael Berthe <mikael@lilotux.net>
parents:
1305
diff
changeset
|
681 x = jutil_msgnew((char*)strtype, (char*)fjid, NULL, |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
682 (enc ? "This message is PGP-encrypted." : (char*)text)); |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
683 if (subject) { |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
684 xmlnode y; |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
685 y = xmlnode_insert_tag(x, "subject"); |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
686 xmlnode_insert_cdata(y, subject, (unsigned) -1); |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
687 } |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
688 if (enc) { |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
689 xmlnode y; |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
690 y = xmlnode_insert_tag(x, "x"); |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
691 xmlnode_put_attrib(y, "xmlns", NS_ENCRYPTED); |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
692 xmlnode_insert_cdata(y, enc, (unsigned) -1); |
1055
6eb1efea75d0
PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents:
1053
diff
changeset
|
693 if (encrypted) |
1197 | 694 *encrypted = 1; |
1044
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
695 g_free(enc); |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
696 } |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
697 |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
698 #if defined JEP0022 || defined JEP0085 |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
699 // If typing notifications are disabled, we can skip all this stuff... |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
700 if (chatstates_disabled || type == ROSTER_TYPE_ROOM) |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
701 goto jb_send_msg_no_chatstates; |
52cfe9bf9840
Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
1043
diff
changeset
|
702 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
703 if (sl_buddy) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
704 jep85 = buddy_resource_jep85(sl_buddy->data, rname); |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
705 #endif |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
706 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
707 #ifdef JEP0085 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
708 /* JEP-0085 5.1 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
709 * "Until receiving a reply to the initial content message (or a standalone |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
710 * notification) from the Contact, the User MUST NOT send subsequent chat |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
711 * state notifications to the Contact." |
1378 | 712 * In our implementation support is initially "unknown", then it's "probed" |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
713 * and can become "ok". |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
714 */ |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
715 if (jep85 && (jep85->support == CHATSTATES_SUPPORT_OK || |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
716 jep85->support == CHATSTATES_SUPPORT_UNKNOWN)) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
717 event = xmlnode_insert_tag(x, "active"); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
718 xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
719 if (jep85->support == CHATSTATES_SUPPORT_UNKNOWN) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
720 jep85->support = CHATSTATES_SUPPORT_PROBED; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
721 else |
997 | 722 use_jep85 = 1; |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
723 jep85->last_state_sent = ROSTER_EVENT_ACTIVE; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
724 } |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
725 #endif |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
726 #ifdef JEP0022 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
727 /* JEP-22 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
728 * If the Contact supports JEP-0085, we do not use JEP-0022. |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
729 * If not, we try to fall back to JEP-0022. |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
730 */ |
997 | 731 if (!use_jep85) { |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
732 struct jep0022 *jep22 = NULL; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
733 event = xmlnode_insert_tag(x, "x"); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
734 xmlnode_put_attrib(event, "xmlns", NS_EVENT); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
735 xmlnode_insert_tag(event, "composing"); |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
736 |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
737 if (sl_buddy) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
738 jep22 = buddy_resource_jep22(sl_buddy->data, rname); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
739 if (jep22) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
740 jep22->last_state_sent = ROSTER_EVENT_ACTIVE; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
741 |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
742 // An id is mandatory when using JEP-0022. |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
743 if (!msgid && (text || subject)) { |
1071
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
744 msgid = nmsgid = new_msgid(); |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
745 // Let's update last_msgid_sent |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
746 // (We do not update it when the msgid is provided by the caller, |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
747 // because this is probably a special message...) |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
748 if (jep22) { |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
749 g_free(jep22->last_msgid_sent); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
750 jep22->last_msgid_sent = g_strdup(msgid); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
751 } |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
752 } |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
753 } |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
754 #endif |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
755 |
993
0759f4c7da68
Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents:
992
diff
changeset
|
756 jb_send_msg_no_chatstates: |
988
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
757 xmlnode_put_attrib(x, "id", msgid); |
6e2bfd1ffded
Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents:
987
diff
changeset
|
758 |
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
759 if (mystatus != invisible) |
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
760 update_last_use(); |
35 | 761 jab_send(jc, x); |
762 xmlnode_free(x); | |
1071
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
763 #if defined JEP0022 |
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
764 g_free(nmsgid); |
866be086cc9b
Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents:
1067
diff
changeset
|
765 #endif |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
766 |
114 | 767 jb_reset_keepalive(); |
35 | 768 } |
769 | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
770 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
771 #ifdef JEP0085 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
772 // jb_send_jep85_chatstate() |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
773 // Send a JEP-85 chatstate. |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
774 static void jb_send_jep85_chatstate(const char *bjid, const char *resname, |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
775 guint state) |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
776 { |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
777 xmlnode x; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
778 xmlnode event; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
779 GSList *sl_buddy; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
780 const char *chattag; |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
781 char *rjid, *fjid = NULL; |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
782 struct jep0085 *jep85 = NULL; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
783 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
784 if (!online) return; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
785 |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
786 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
787 |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
788 // If we have a resource name, we use it. Else we use NULL, |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
789 // which hopefully will give us the most likely resource. |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
790 if (sl_buddy) |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
791 jep85 = buddy_resource_jep85(sl_buddy->data, resname); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
792 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
793 if (!jep85 || (jep85->support != CHATSTATES_SUPPORT_OK)) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
794 return; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
795 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
796 if (state == jep85->last_state_sent) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
797 return; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
798 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
799 if (state == ROSTER_EVENT_ACTIVE) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
800 chattag = "active"; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
801 else if (state == ROSTER_EVENT_COMPOSING) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
802 chattag = "composing"; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
803 else if (state == ROSTER_EVENT_PAUSED) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
804 chattag = "paused"; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
805 else { |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
806 scr_LogPrint(LPRINT_LOGNORM, "Error: unsupported JEP-85 state (%d)", state); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
807 return; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
808 } |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
809 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
810 jep85->last_state_sent = state; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
811 |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
812 if (resname) |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
813 fjid = g_strdup_printf("%s/%s", bjid, resname); |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
814 |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
815 rjid = resname ? fjid : (char*)bjid; |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
816 x = jutil_msgnew(TMSG_CHAT, rjid, NULL, NULL); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
817 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
818 event = xmlnode_insert_tag(x, chattag); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
819 xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
820 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
821 jab_send(jc, x); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
822 xmlnode_free(x); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
823 |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
824 g_free(fjid); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
825 jb_reset_keepalive(); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
826 } |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
827 #endif |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
828 |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
829 #ifdef JEP0022 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
830 // jb_send_jep22_event() |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
831 // Send a JEP-22 message event (delivered, composing...). |
1058 | 832 static void jb_send_jep22_event(const char *fjid, guint type) |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
833 { |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
834 xmlnode x; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
835 xmlnode event; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
836 const char *msgid; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
837 char *rname, *barejid; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
838 GSList *sl_buddy; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
839 struct jep0022 *jep22 = NULL; |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
840 guint jep22_state; |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
841 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
842 if (!online) return; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
843 |
1058 | 844 rname = strchr(fjid, JID_RESOURCE_SEPARATOR); |
845 barejid = jidtodisp(fjid); | |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
846 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
847 g_free(barejid); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
848 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
849 // If we can get a resource name, we use it. Else we use NULL, |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
850 // which hopefully will give us the most likely resource. |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
851 if (rname) |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
852 rname++; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
853 if (sl_buddy) |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
854 jep22 = buddy_resource_jep22(sl_buddy->data, rname); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
855 |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
856 if (!jep22) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
857 return; // XXX Maybe we could try harder (other resources?) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
858 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
859 msgid = jep22->last_msgid_rcvd; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
860 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
861 // For composing events (composing, active, inactive, paused...), |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
862 // JEP22 only has 2 states; we'll use composing and active. |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
863 if (type == ROSTER_EVENT_COMPOSING) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
864 jep22_state = ROSTER_EVENT_COMPOSING; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
865 else if (type == ROSTER_EVENT_ACTIVE || |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
866 type == ROSTER_EVENT_PAUSED) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
867 jep22_state = ROSTER_EVENT_ACTIVE; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
868 else |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
869 jep22_state = 0; // ROSTER_EVENT_NONE |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
870 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
871 if (jep22_state) { |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
872 // Do not re-send a same event |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
873 if (jep22_state == jep22->last_state_sent) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
874 return; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
875 jep22->last_state_sent = jep22_state; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
876 } |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
877 |
1058 | 878 x = jutil_msgnew(TMSG_CHAT, (char*)fjid, NULL, NULL); |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
879 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
880 event = xmlnode_insert_tag(x, "x"); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
881 xmlnode_put_attrib(event, "xmlns", NS_EVENT); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
882 if (type == ROSTER_EVENT_DELIVERED) |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
883 xmlnode_insert_tag(event, "delivered"); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
884 else if (type == ROSTER_EVENT_COMPOSING) |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
885 xmlnode_insert_tag(event, "composing"); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
886 xmlnode_put_attrib(event, "id", msgid); |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
887 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
888 jab_send(jc, x); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
889 xmlnode_free(x); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
890 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
891 jb_reset_keepalive(); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
892 } |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
893 #endif |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
894 |
997 | 895 // jb_send_chatstate(buddy, state) |
896 // Send a chatstate or event (JEP-22/85) according to the buddy's capabilities. | |
897 // The message is sent to one of the resources with the highest priority. | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
898 #if defined JEP0022 || defined JEP0085 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
899 void jb_send_chatstate(gpointer buddy, guint chatstate) |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
900 { |
1058 | 901 const char *bjid; |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
902 #ifdef JEP0085 |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
903 GSList *resources, *p_res, *p_next; |
1099
7804dbac3875
Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents:
1091
diff
changeset
|
904 struct jep0085 *jep85 = NULL;; |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
905 #endif |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
906 #ifdef JEP0022 |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
907 struct jep0022 *jep22; |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
908 #endif |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
909 |
1058 | 910 bjid = buddy_getjid(buddy); |
911 if (!bjid) return; | |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
912 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
913 #ifdef JEP0085 |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
914 /* Send the chatstate to the last resource (which should have the highest |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
915 priority). |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
916 If chatstate is "active", send an "active" state to all resources |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
917 which do not curently have this state. |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
918 */ |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
919 resources = buddy_getresources(buddy); |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
920 for (p_res = resources ; p_res ; p_res = p_next) { |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
921 p_next = g_slist_next(p_res); |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
922 jep85 = buddy_resource_jep85(buddy, p_res->data); |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
923 if (jep85 && jep85->support == CHATSTATES_SUPPORT_OK) { |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
924 // If p_next is NULL, this is the highest (prio) resource, i.e. |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
925 // the one we are probably writing to. |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
926 if (!p_next || (jep85->last_state_sent != ROSTER_EVENT_ACTIVE && |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
927 chatstate == ROSTER_EVENT_ACTIVE)) |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
928 jb_send_jep85_chatstate(bjid, p_res->data, chatstate); |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
929 } |
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
930 g_free(p_res->data); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
931 } |
1091
10f9d6fcfeab
JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents:
1072
diff
changeset
|
932 g_slist_free(resources); |
1099
7804dbac3875
Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents:
1091
diff
changeset
|
933 // If the last resource had chatstates support when can return now, |
7804dbac3875
Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents:
1091
diff
changeset
|
934 // we don't want to send a JEP22 event. |
7804dbac3875
Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents:
1091
diff
changeset
|
935 if (jep85 && jep85->support == CHATSTATES_SUPPORT_OK) |
7804dbac3875
Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents:
1091
diff
changeset
|
936 return; |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
937 #endif |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
938 #ifdef JEP0022 |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
939 jep22 = buddy_resource_jep22(buddy, NULL); |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
940 if (jep22 && jep22->support == CHATSTATES_SUPPORT_OK) { |
1058 | 941 jb_send_jep22_event(bjid, chatstate); |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
942 } |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
943 #endif |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
944 } |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
945 #endif |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
946 |
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
|
947 // chatstates_reset_probed(fulljid) |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
948 // If the JEP has been probed for this contact, set it back to unknown so |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
949 // that we probe it again. The parameter must be a full jid (w/ resource). |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
950 #if defined JEP0022 || defined JEP0085 |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
951 static void chatstates_reset_probed(const char *fulljid) |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
952 { |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
953 char *rname, *barejid; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
954 GSList *sl_buddy; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
955 struct jep0085 *jep85; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
956 struct jep0022 *jep22; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
957 |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
958 rname = strchr(fulljid, JID_RESOURCE_SEPARATOR); |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
959 if (!rname++) |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
960 return; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
961 |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
962 barejid = jidtodisp(fulljid); |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
963 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
964 g_free(barejid); |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
965 |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
966 if (!sl_buddy) |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
967 return; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
968 |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
969 jep85 = buddy_resource_jep85(sl_buddy->data, rname); |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
970 jep22 = buddy_resource_jep22(sl_buddy->data, rname); |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
971 |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
972 if (jep85 && jep85->support == CHATSTATES_SUPPORT_PROBED) |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
973 jep85->support = CHATSTATES_SUPPORT_UNKNOWN; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
974 if (jep22 && jep22->support == CHATSTATES_SUPPORT_PROBED) |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
975 jep22->support = CHATSTATES_SUPPORT_UNKNOWN; |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
976 } |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
977 #endif |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
978 |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
979 // jb_subscr_send_auth(jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
980 // Allow jid to receive our presence updates |
1058 | 981 void jb_subscr_send_auth(const char *bjid) |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
982 { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
983 xmlnode x; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
984 |
1058 | 985 x = jutil_presnew(JPACKET__SUBSCRIBED, (char *)bjid, NULL); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
986 jab_send(jc, x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
987 xmlnode_free(x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
988 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
989 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
990 // jb_subscr_cancel_auth(jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
991 // Cancel jid's subscription to our presence updates |
1058 | 992 void jb_subscr_cancel_auth(const char *bjid) |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
993 { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
994 xmlnode x; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
995 |
1058 | 996 x = jutil_presnew(JPACKET__UNSUBSCRIBED, (char *)bjid, NULL); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
997 jab_send(jc, x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
998 xmlnode_free(x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
999 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1000 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1001 // jb_subscr_request_auth(jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1002 // Request a subscription to jid's presence updates |
1058 | 1003 void jb_subscr_request_auth(const char *bjid) |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1004 { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1005 xmlnode x; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1006 |
1058 | 1007 x = jutil_presnew(JPACKET__SUBSCRIBE, (char *)bjid, NULL); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1008 jab_send(jc, x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1009 xmlnode_free(x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1010 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1011 |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1012 // jb_subscr_request_cancel(jid) |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1013 // Request to cancel jour subscription to jid's presence updates |
1058 | 1014 void jb_subscr_request_cancel(const char *bjid) |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1015 { |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1016 xmlnode x; |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1017 |
1058 | 1018 x = jutil_presnew(JPACKET__UNSUBSCRIBE, (char *)bjid, NULL); |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1019 jab_send(jc, x); |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1020 xmlnode_free(x); |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1021 } |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1022 |
213 | 1023 // Note: the caller should check the jid is correct |
1058 | 1024 void jb_addbuddy(const char *bjid, const char *name, const char *group) |
124 | 1025 { |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1026 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1027 eviqs *iqn; |
192 | 1028 char *cleanjid; |
124 | 1029 |
208 | 1030 if (!online) return; |
124 | 1031 |
1058 | 1032 cleanjid = jidtodisp(bjid); // Stripping resource, just in case... |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
1033 |
124 | 1034 // We don't check if the jabber user already exists in the roster, |
1035 // because it allows to re-ask for notification. | |
1036 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1037 iqn = iqs_new(JPACKET__SET, NS_ROSTER, NULL, IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1038 y = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item"); |
628
454399f026fa
Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1039 |
454399f026fa
Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1040 xmlnode_put_attrib(y, "jid", cleanjid); |
124 | 1041 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1042 if (name) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1043 xmlnode_put_attrib(y, "name", name); |
244 | 1044 |
124 | 1045 if (group) { |
628
454399f026fa
Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1046 z = xmlnode_insert_tag(y, "group"); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1047 xmlnode_insert_cdata(z, group, (unsigned) -1); |
124 | 1048 } |
1049 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1050 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1051 iqs_del(iqn->id); // XXX |
124 | 1052 |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1053 jb_subscr_request_auth(cleanjid); |
612
789ec6aed764
Respect RFC 3921 order advice
Mikael Berthe <mikael@lilotux.net>
parents:
611
diff
changeset
|
1054 |
1355 | 1055 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending, -1); |
192 | 1056 g_free(cleanjid); |
124 | 1057 buddylist_build(); |
1058 | |
244 | 1059 update_roster = TRUE; |
124 | 1060 } |
1061 | |
1058 | 1062 void jb_delbuddy(const char *bjid) |
205 | 1063 { |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1064 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1065 eviqs *iqn; |
205 | 1066 char *cleanjid; |
1067 | |
1068 if (!online) return; | |
1069 | |
1058 | 1070 cleanjid = jidtodisp(bjid); // Stripping resource, just in case... |
205 | 1071 |
1072 // If the current buddy is an agent, unsubscribe from it | |
1073 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1074 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid); |
205 | 1075 |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1076 iqn = iqs_new(JPACKET__SET, NS_REGISTER, NULL, IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1077 xmlnode_put_attrib(iqn->xmldata, "to", cleanjid); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1078 y = xmlnode_get_tag(iqn->xmldata, "query"); |
205 | 1079 xmlnode_insert_tag(y, "remove"); |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1080 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1081 iqs_del(iqn->id); // XXX |
205 | 1082 } |
1083 | |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1084 // Cancel the subscriptions |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1085 jb_subscr_cancel_auth(cleanjid); // Cancel "from" |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
1086 jb_subscr_request_cancel(cleanjid); // Cancel "to" |
205 | 1087 |
1088 // Ask for removal from roster | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1089 iqn = iqs_new(JPACKET__SET, NS_ROSTER, NULL, IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1090 y = xmlnode_get_tag(iqn->xmldata, "query"); |
205 | 1091 z = xmlnode_insert_tag(y, "item"); |
1092 xmlnode_put_attrib(z, "jid", cleanjid); | |
1093 xmlnode_put_attrib(z, "subscription", "remove"); | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1094 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1095 iqs_del(iqn->id); // XXX |
205 | 1096 |
1097 roster_del_user(cleanjid); | |
1098 g_free(cleanjid); | |
1099 buddylist_build(); | |
1100 | |
1101 update_roster = TRUE; | |
1102 } | |
1103 | |
1058 | 1104 void jb_updatebuddy(const char *bjid, const char *name, const char *group) |
208 | 1105 { |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1106 xmlnode y; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1107 eviqs *iqn; |
208 | 1108 char *cleanjid; |
1109 | |
1110 if (!online) return; | |
1111 | |
1112 // XXX We should check name's and group's correctness | |
1113 | |
1058 | 1114 cleanjid = jidtodisp(bjid); // Stripping resource, just in case... |
208 | 1115 |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1116 iqn = iqs_new(JPACKET__SET, NS_ROSTER, NULL, IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1117 y = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item"); |
208 | 1118 xmlnode_put_attrib(y, "jid", cleanjid); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1119 xmlnode_put_attrib(y, "name", name); |
208 | 1120 |
1121 if (group) { | |
1122 y = xmlnode_insert_tag(y, "group"); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1123 xmlnode_insert_cdata(y, group, (unsigned) -1); |
208 | 1124 } |
1125 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1126 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1127 iqs_del(iqn->id); // XXX |
208 | 1128 g_free(cleanjid); |
1129 } | |
1130 | |
1058 | 1131 void jb_request(const char *fjid, enum iqreq_type reqtype) |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
1132 { |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1071
diff
changeset
|
1133 GSList *resources, *p_res; |
693 | 1134 GSList *roster_elt; |
793 | 1135 void (*request_fn)(const char *); |
1136 const char *strreqtype; | |
693 | 1137 |
793 | 1138 if (reqtype == iqreq_version) { |
1139 request_fn = &request_version; | |
1140 strreqtype = "version"; | |
1141 } else if (reqtype == iqreq_time) { | |
1142 request_fn = &request_time; | |
1143 strreqtype = "time"; | |
1015 | 1144 } else if (reqtype == iqreq_last) { |
1145 request_fn = &request_last; | |
1146 strreqtype = "last"; | |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1001
diff
changeset
|
1147 } else if (reqtype == iqreq_vcard) { |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1001
diff
changeset
|
1148 // Special case |
793 | 1149 } else |
1150 return; | |
693 | 1151 |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1001
diff
changeset
|
1152 // vCard request |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1001
diff
changeset
|
1153 if (reqtype == iqreq_vcard) { |
1310
a5336c44d4e2
Allow vcard requests to a full jid
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
1154 request_vcard(fjid); |
a5336c44d4e2
Allow vcard requests to a full jid
Mikael Berthe <mikael@lilotux.net>
parents:
1306
diff
changeset
|
1155 scr_LogPrint(LPRINT_NORMAL, "Sent vCard request to <%s>", fjid); |
1003
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1001
diff
changeset
|
1156 return; |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1001
diff
changeset
|
1157 } |
c8b1a52b2fd6
Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents:
1001
diff
changeset
|
1158 |
1058 | 1159 if (strchr(fjid, JID_RESOURCE_SEPARATOR)) { |
693 | 1160 // This is a full JID |
1058 | 1161 (*request_fn)(fjid); |
1162 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fjid); | |
693 | 1163 return; |
1164 } | |
1165 | |
1166 // The resource has not been specified | |
1058 | 1167 roster_elt = roster_find(fjid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_ROOM); |
693 | 1168 if (!roster_elt) { |
1058 | 1169 scr_LogPrint(LPRINT_NORMAL, "No known resource for <%s>...", fjid); |
1170 (*request_fn)(fjid); // Let's send a request anyway... | |
1171 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fjid); | |
693 | 1172 return; |
1173 } | |
1174 | |
1175 // Send a request to each resource | |
1176 resources = buddy_getresources(roster_elt->data); | |
793 | 1177 if (!resources) { |
1058 | 1178 scr_LogPrint(LPRINT_NORMAL, "No known resource for <%s>...", fjid); |
1179 (*request_fn)(fjid); // Let's send a request anyway... | |
1180 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fjid); | |
793 | 1181 } |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1071
diff
changeset
|
1182 for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) { |
693 | 1183 gchar *fulljid; |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1071
diff
changeset
|
1184 fulljid = g_strdup_printf("%s/%s", fjid, (char*)p_res->data); |
793 | 1185 (*request_fn)(fulljid); |
1186 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fulljid); | |
693 | 1187 g_free(fulljid); |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1071
diff
changeset
|
1188 g_free(p_res->data); |
693 | 1189 } |
1072
2a3cfb98bd5e
Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents:
1071
diff
changeset
|
1190 g_slist_free(resources); |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
1191 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
1192 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1193 // Join a MUC room |
900
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
1194 void jb_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
|
1195 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1196 xmlnode x, y; |
643
dd73c3dad815
Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
642
diff
changeset
|
1197 gchar *roomid; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1198 GSList *room_elt; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1199 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
1200 if (!online || !room) return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
1201 if (!nickname) return; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1202 |
643
dd73c3dad815
Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
642
diff
changeset
|
1203 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
|
1204 if (check_jid_syntax(roomid)) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1205 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
|
1206 nickname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1207 g_free(roomid); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1208 return; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1209 } |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1210 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1211 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
|
1212 // 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
|
1213 if (!room_elt) { |
1355 | 1214 room_elt = roster_add_user(room, NULL, NULL, ROSTER_TYPE_ROOM, |
1215 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
|
1216 } else { |
3ad6675caaf1
MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
645
diff
changeset
|
1217 // 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
|
1218 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
|
1219 } |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1220 // 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
|
1221 if (!buddy_getinsideroom(room_elt->data)) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1222 // 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
|
1223 buddy_setnickname(room_elt->data, nickname); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1224 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1225 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1226 // Send the XML request |
535
b407d19c39ab
Set status correctly when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
534
diff
changeset
|
1227 x = presnew(mystatus, roomid, mystatusmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1228 y = xmlnode_insert_tag(x, "x"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1229 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc"); |
900
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
1230 if (passwd) { |
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
1231 xmlnode_insert_cdata(xmlnode_insert_tag(y, "password"), passwd, |
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
1232 (unsigned) -1); |
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
1233 } |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1234 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1235 jab_send(jc, x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1236 xmlnode_free(x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1237 jb_reset_keepalive(); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1238 g_free(roomid); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1239 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1240 |
449 | 1241 // Unlock a MUC room |
1242 // room syntax: "room@server" | |
1243 void jb_room_unlock(const char *room) | |
1244 { | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1245 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1246 eviqs *iqn; |
449 | 1247 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
1248 if (!online || !room) return; |
449 | 1249 |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1250 iqn = iqs_new(JPACKET__SET, "http://jabber.org/protocol/muc#owner", |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1251 "unlock", IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1252 xmlnode_put_attrib(iqn->xmldata, "to", room); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1253 y = xmlnode_get_tag(iqn->xmldata, "query"); |
449 | 1254 z = xmlnode_insert_tag(y, "x"); |
1255 xmlnode_put_attrib(z, "xmlns", "jabber:x:data"); | |
1256 xmlnode_put_attrib(z, "type", "submit"); | |
1257 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1258 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1259 iqs_del(iqn->id); // XXX |
449 | 1260 jb_reset_keepalive(); |
1261 } | |
1262 | |
599 | 1263 // Destroy a MUC room |
1264 // room syntax: "room@server" | |
1265 void jb_room_destroy(const char *room, const char *venue, const char *reason) | |
1266 { | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1267 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1268 eviqs *iqn; |
599 | 1269 |
1270 if (!online || !room) return; | |
1271 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1272 iqn = iqs_new(JPACKET__SET, "http://jabber.org/protocol/muc#owner", |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1273 "destroy", IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1274 xmlnode_put_attrib(iqn->xmldata, "to", room); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1275 y = xmlnode_get_tag(iqn->xmldata, "query"); |
599 | 1276 z = xmlnode_insert_tag(y, "destroy"); |
1277 | |
1278 if (venue && *venue) | |
1279 xmlnode_put_attrib(z, "jid", venue); | |
1280 | |
1281 if (reason) { | |
1282 y = xmlnode_insert_tag(z, "reason"); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1283 xmlnode_insert_cdata(y, reason, (unsigned) -1); |
599 | 1284 } |
1285 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1286 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1287 iqs_del(iqn->id); // XXX |
599 | 1288 jb_reset_keepalive(); |
1289 } | |
1290 | |
584 | 1291 // Change role or affiliation of a MUC user |
568 | 1292 // room syntax: "room@server" |
1293 // Either the jid or the nickname must be set (when banning, only the jid is | |
1294 // allowed) | |
584 | 1295 // ra: new role or affiliation |
1296 // (ex. role none for kick, affil outcast for ban...) | |
568 | 1297 // The reason can be null |
1298 // Return 0 if everything is ok | |
1058 | 1299 int jb_room_setattrib(const char *roomid, const char *fjid, const char *nick, |
584 | 1300 struct role_affil ra, const char *reason) |
568 | 1301 { |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1302 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
1303 eviqs *iqn; |
568 | 1304 |
1305 if (!online || !roomid) return 1; | |
1058 | 1306 if (!fjid && !nick) return 1; |
568 | 1307 |
1308 if (check_jid_syntax((char*)roomid)) { | |
1309 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid); | |
1310 return 1; | |
1311 } | |
1058 | 1312 if (fjid && check_jid_syntax((char*)fjid)) { |
1313 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", fjid); | |
568 | 1314 return 1; |
1315 } | |
1316 | |
1058 | 1317 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
|
1318 return 1; // Shouldn't happen (jid mandatory when banning) |
568 | 1319 |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1320 iqn = iqs_new(JPACKET__SET, "http://jabber.org/protocol/muc#admin", |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1321 "roleaffil", IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1322 xmlnode_put_attrib(iqn->xmldata, "to", roomid); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1323 xmlnode_put_attrib(iqn->xmldata, "type", "set"); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1324 y = xmlnode_get_tag(iqn->xmldata, "query"); |
568 | 1325 z = xmlnode_insert_tag(y, "item"); |
1326 | |
1058 | 1327 if (fjid) { |
1328 xmlnode_put_attrib(z, "jid", fjid); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1329 } else { // nickname |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1330 xmlnode_put_attrib(z, "nick", nick); |
568 | 1331 } |
584 | 1332 |
1333 if (ra.type == type_affil) | |
1334 xmlnode_put_attrib(z, "affiliation", straffil[ra.val.affil]); | |
1335 else if (ra.type == type_role) | |
1336 xmlnode_put_attrib(z, "role", strrole[ra.val.role]); | |
568 | 1337 |
1338 if (reason) { | |
1339 y = xmlnode_insert_tag(z, "reason"); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1340 xmlnode_insert_cdata(y, reason, (unsigned) -1); |
568 | 1341 } |
1342 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1343 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
1344 iqs_del(iqn->id); // XXX |
568 | 1345 jb_reset_keepalive(); |
1346 | |
1347 return 0; | |
1348 } | |
486 | 1349 |
1350 // Invite a user to a MUC room | |
1351 // room syntax: "room@server" | |
1352 // reason can be null. | |
1058 | 1353 void jb_room_invite(const char *room, const char *fjid, const char *reason) |
486 | 1354 { |
1355 xmlnode x, y, z; | |
1356 | |
1058 | 1357 if (!online || !room || !fjid) return; |
486 | 1358 |
1359 x = jutil_msgnew(NULL, (char*)room, NULL, NULL); | |
1360 | |
1361 y = xmlnode_insert_tag(x, "x"); | |
1362 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user"); | |
1363 | |
1364 z = xmlnode_insert_tag(y, "invite"); | |
1058 | 1365 xmlnode_put_attrib(z, "to", fjid); |
486 | 1366 |
569
69afee8e1232
"/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents:
568
diff
changeset
|
1367 if (reason) { |
69afee8e1232
"/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents:
568
diff
changeset
|
1368 y = xmlnode_insert_tag(z, "reason"); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1369 xmlnode_insert_cdata(y, reason, (unsigned) -1); |
569
69afee8e1232
"/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents:
568
diff
changeset
|
1370 } |
486 | 1371 |
1372 jab_send(jc, x); | |
1373 xmlnode_free(x); | |
1374 jb_reset_keepalive(); | |
1375 } | |
1376 | |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1377 // jb_is_bookmarked(roomjid) |
1363
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1378 // Return TRUE if there's a bookmark for the given jid. |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1379 guint jb_is_bookmarked(const char *bjid) |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1380 { |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1381 xmlnode x; |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1382 |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1383 if (!bookmarks) |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1384 return FALSE; |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1385 |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1386 // Walk through the storage bookmark tags |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1387 x = xmlnode_get_firstchild(bookmarks); |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1388 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
1397 | 1389 const char *p = xmlnode_get_name(x); |
1363
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1390 // If the node is a conference item, check the jid. |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1391 if (p && !strcmp(p, "conference")) { |
1397 | 1392 const char *fjid = xmlnode_get_attrib(x, "jid"); |
1363
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1393 if (fjid && !strcasecmp(bjid, fjid)) |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1394 return TRUE; |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1395 } |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1396 } |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1397 return FALSE; |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1398 } |
32077249de77
Warn if a MUC room without bookmark is renamed
Mikael Berthe <mikael@lilotux.net>
parents:
1355
diff
changeset
|
1399 |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1400 // jb_get_bookmark_nick(roomjid) |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1401 // Return the room nickname if it is present in a bookmark. |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1402 const char *jb_get_bookmark_nick(const char *bjid) |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1403 { |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1404 xmlnode x; |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1405 |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1406 if (!bookmarks || !bjid) |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1407 return NULL; |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1408 |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1409 // Walk through the storage bookmark tags |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1410 x = xmlnode_get_firstchild(bookmarks); |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1411 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
1397 | 1412 const char *p = xmlnode_get_name(x); |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1413 // If the node is a conference item, check the jid. |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1414 if (p && !strcmp(p, "conference")) { |
1397 | 1415 const char *fjid = xmlnode_get_attrib(x, "jid"); |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1416 if (fjid && !strcasecmp(bjid, fjid)) |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1417 return xmlnode_get_tag_data(x, "nick"); |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1418 } |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1419 } |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1420 return NULL; |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1421 } |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1422 |
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
1423 |
1163
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1424 // jb_get_all_storage_bookmarks() |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1425 // Return a GSList with all storage bookmarks. |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1426 // The caller should g_free the list (not the MUC jids). |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1427 GSList *jb_get_all_storage_bookmarks(void) |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1428 { |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1429 xmlnode x; |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1430 GSList *sl_bookmarks = NULL; |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1431 |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1432 // If we have no bookmarks, probably the server doesn't support them. |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1433 if (!bookmarks) |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1434 return NULL; |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1435 |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1436 // Walk through the storage bookmark tags |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1437 x = xmlnode_get_firstchild(bookmarks); |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1438 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
1397 | 1439 const char *p = xmlnode_get_name(x); |
1163
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1440 // If the node is a conference item, let's add the note to our list. |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1441 if (p && !strcmp(p, "conference")) { |
1397 | 1442 const char *fjid = xmlnode_get_attrib(x, "jid"); |
1163
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1443 if (!fjid) |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1444 continue; |
1164 | 1445 sl_bookmarks = g_slist_append(sl_bookmarks, (char*)fjid); |
1163
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1446 } |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1447 } |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1448 return sl_bookmarks; |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1449 } |
2913310a7be6
Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1161
diff
changeset
|
1450 |
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1451 // jb_set_storage_bookmark(roomid, name, nick, passwd, autojoin, |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1452 // printstatus, autowhois) |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1453 // Update the private storage bookmarks: add a conference room. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1454 // If name is nil, we remove the bookmark. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1455 void jb_set_storage_bookmark(const char *roomid, const char *name, |
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1456 const char *nick, const char *passwd, |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1457 int autojoin, enum room_printstatus pstatus, |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1458 enum room_autowhois awhois) |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1459 { |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1460 xmlnode x; |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1461 bool changed = FALSE; |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1462 |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1463 if (!roomid) |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1464 return; |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1465 |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1466 // If we have no bookmarks, probably the server doesn't support them. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1467 if (!bookmarks) { |
1244
f7b9a00c512d
Make room bookark more verbose, and remove duplicate bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1237
diff
changeset
|
1468 scr_LogPrint(LPRINT_NORMAL, |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1469 "Sorry, your server doesn't seem to support private storage."); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1470 return; |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1471 } |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1472 |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1473 // Walk through the storage tags |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1474 x = xmlnode_get_firstchild(bookmarks); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1475 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
1397 | 1476 const char *p = xmlnode_get_name(x); |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1477 // If the current node is a conference item, see if we have to replace it. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1478 if (p && !strcmp(p, "conference")) { |
1397 | 1479 const char *fjid = xmlnode_get_attrib(x, "jid"); |
1058 | 1480 if (!fjid) |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1481 continue; |
1058 | 1482 if (!strcmp(fjid, roomid)) { |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1483 // We've found a bookmark for this room. Let's hide it and we'll |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1484 // create a new one. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1485 xmlnode_hide(x); |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1486 changed = TRUE; |
1244
f7b9a00c512d
Make room bookark more verbose, and remove duplicate bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1237
diff
changeset
|
1487 if (!name) |
f7b9a00c512d
Make room bookark more verbose, and remove duplicate bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1237
diff
changeset
|
1488 scr_LogPrint(LPRINT_LOGNORM, "Deleting bookmark..."); |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1489 } |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1490 } |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1491 } |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1492 |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1493 // Let's create a node/bookmark for this roomid, if the name is not NULL. |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1494 if (name) { |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1495 x = xmlnode_insert_tag(bookmarks, "conference"); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1496 xmlnode_put_attrib(x, "jid", roomid); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1497 xmlnode_put_attrib(x, "name", name); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1498 xmlnode_put_attrib(x, "autojoin", autojoin ? "1" : "0"); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1499 if (nick) |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1500 xmlnode_insert_cdata(xmlnode_insert_tag(x, "nick"), nick, -1); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1501 if (passwd) |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1502 xmlnode_insert_cdata(xmlnode_insert_tag(x, "password"), passwd, -1); |
1379
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1503 if (pstatus) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1504 xmlnode_insert_cdata(xmlnode_insert_tag(x, "print_status"), |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1505 strprintstatus[pstatus], -1); |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1506 if (awhois) |
74b7621537d7
MUC: Store room settings (print_status, auto_whois) in private storage
Mikael Berthe <mikael@lilotux.net>
parents:
1378
diff
changeset
|
1507 xmlnode_put_attrib(x, "autowhois", (awhois == autowhois_on ? "1" : "0")); |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1508 changed = TRUE; |
1244
f7b9a00c512d
Make room bookark more verbose, and remove duplicate bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1237
diff
changeset
|
1509 scr_LogPrint(LPRINT_LOGNORM, "Updating bookmarks..."); |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1510 } |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1511 |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1512 if (!changed) |
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1513 return; |
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1514 |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1515 if (online) |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1516 send_storage_bookmarks(); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1517 else |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1518 scr_LogPrint(LPRINT_LOGNORM, |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1519 "Warning: you're not connected to the server."); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1520 } |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1521 |
1022
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1522 static struct annotation *parse_storage_rosternote(xmlnode notenode) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1523 { |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1524 const char *p; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1525 struct annotation *note = g_new0(struct annotation, 1); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1526 p = xmlnode_get_attrib(notenode, "cdate"); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1527 if (p) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1528 note->cdate = from_iso8601(p, 1); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1529 p = xmlnode_get_attrib(notenode, "mdate"); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1530 if (p) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1531 note->mdate = from_iso8601(p, 1); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1532 note->text = g_strdup(xmlnode_get_data(notenode)); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1533 note->jid = g_strdup(xmlnode_get_attrib(notenode, "jid")); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1534 return note; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1535 } |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1536 |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1537 // jb_get_all_storage_rosternotes() |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1538 // Return a GSList with all storage annotations. |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1539 // The caller should g_free the list and its contents. |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1540 GSList *jb_get_all_storage_rosternotes(void) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1541 { |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1542 xmlnode x; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1543 GSList *sl_notes = NULL; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1544 |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1545 // If we have no rosternotes, probably the server doesn't support them. |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1546 if (!rosternotes) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1547 return NULL; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1548 |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1549 // Walk through the storage rosternotes tags |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1550 x = xmlnode_get_firstchild(rosternotes); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1551 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1552 const char *p; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1553 struct annotation *note; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1554 p = xmlnode_get_name(x); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1555 |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1556 // We want a note item |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1557 if (!p || strcmp(p, "note")) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1558 continue; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1559 // Just in case, check the jid... |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1560 if (!xmlnode_get_attrib(x, "jid")) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1561 continue; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1562 // Ok, let's add the note to our list |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1563 note = parse_storage_rosternote(x); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1564 sl_notes = g_slist_append(sl_notes, note); |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1565 } |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1566 return sl_notes; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1567 } |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1568 |
1023 | 1569 // jb_get_storage_rosternotes(barejid, silent) |
1019
9d5f6e0ea7b3
XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents:
1018
diff
changeset
|
1570 // Return the annotation associated with this jid. |
1023 | 1571 // If silent is TRUE, no warning is displayed when rosternotes is disabled |
1019
9d5f6e0ea7b3
XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents:
1018
diff
changeset
|
1572 // The caller should g_free the string and structure after use. |
1023 | 1573 struct annotation *jb_get_storage_rosternotes(const char *barejid, int silent) |
1016 | 1574 { |
1575 xmlnode x; | |
1576 | |
1577 if (!barejid) | |
1578 return NULL; | |
1579 | |
1580 // If we have no rosternotes, probably the server doesn't support them. | |
1581 if (!rosternotes) { | |
1023 | 1582 if (!silent) |
1244
f7b9a00c512d
Make room bookark more verbose, and remove duplicate bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1237
diff
changeset
|
1583 scr_LogPrint(LPRINT_NORMAL, "Sorry, " |
1023 | 1584 "your server doesn't seem to support private storage."); |
1016 | 1585 return NULL; |
1586 } | |
1587 | |
1022
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1588 // Walk through the storage rosternotes tags |
1016 | 1589 x = xmlnode_get_firstchild(rosternotes); |
1590 for ( ; x; x = xmlnode_get_nextsibling(x)) { | |
1058 | 1591 const char *fjid; |
1016 | 1592 const char *p; |
1593 p = xmlnode_get_name(x); | |
1022
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1594 // We want a note item |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1595 if (!p || strcmp(p, "note")) |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1596 continue; |
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1597 // Just in case, check the jid... |
1058 | 1598 fjid = xmlnode_get_attrib(x, "jid"); |
1599 if (fjid && !strcmp(fjid, barejid)) // We've found a note for this contact. | |
1022
4c8d7b558e83
Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents:
1019
diff
changeset
|
1600 return parse_storage_rosternote(x); |
1016 | 1601 } |
1602 return NULL; // No note found | |
1603 } | |
1604 | |
1605 // jb_set_storage_rosternotes(barejid, note) | |
1606 // Update the private storage rosternotes: add/delete a note. | |
1607 // If note is nil, we remove the existing note. | |
1608 void jb_set_storage_rosternotes(const char *barejid, const char *note) | |
1609 { | |
1610 xmlnode x; | |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1611 bool changed = FALSE; |
1018 | 1612 const char *cdate = NULL; |
1016 | 1613 |
1614 if (!barejid) | |
1615 return; | |
1616 | |
1617 // If we have no rosternotes, probably the server doesn't support them. | |
1618 if (!rosternotes) { | |
1244
f7b9a00c512d
Make room bookark more verbose, and remove duplicate bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1237
diff
changeset
|
1619 scr_LogPrint(LPRINT_NORMAL, |
1016 | 1620 "Sorry, your server doesn't seem to support private storage."); |
1621 return; | |
1622 } | |
1623 | |
1624 // Walk through the storage tags | |
1625 x = xmlnode_get_firstchild(rosternotes); | |
1626 for ( ; x; x = xmlnode_get_nextsibling(x)) { | |
1397 | 1627 const char *p = xmlnode_get_name(x); |
1016 | 1628 // If the current node is a conference item, see if we have to replace it. |
1629 if (p && !strcmp(p, "note")) { | |
1397 | 1630 const char *fjid = xmlnode_get_attrib(x, "jid"); |
1058 | 1631 if (!fjid) |
1016 | 1632 continue; |
1058 | 1633 if (!strcmp(fjid, barejid)) { |
1016 | 1634 // We've found a note for this jid. Let's hide it and we'll |
1635 // create a new one. | |
1018 | 1636 cdate = xmlnode_get_attrib(x, "cdate"); |
1016 | 1637 xmlnode_hide(x); |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1638 changed = TRUE; |
1016 | 1639 break; |
1640 } | |
1641 } | |
1642 } | |
1643 | |
1644 // Let's create a node for this jid, if the note is not NULL. | |
1645 if (note) { | |
1018 | 1646 char mdate[20]; |
1647 time_t now; | |
1648 time(&now); | |
1649 to_iso8601(mdate, now); | |
1650 if (!cdate) | |
1651 cdate = mdate; | |
1016 | 1652 x = xmlnode_insert_tag(rosternotes, "note"); |
1653 xmlnode_put_attrib(x, "jid", barejid); | |
1018 | 1654 xmlnode_put_attrib(x, "cdate", cdate); |
1655 xmlnode_put_attrib(x, "mdate", mdate); | |
1016 | 1656 xmlnode_insert_cdata(x, note, -1); |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1657 changed = TRUE; |
1016 | 1658 } |
1659 | |
1017
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1660 if (!changed) |
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1661 return; |
41f9a2a4c1de
Only update server private storage data if they've changed
Mikael Berthe <mikael@lilotux.net>
parents:
1016
diff
changeset
|
1662 |
1016 | 1663 if (online) |
1664 send_storage_rosternotes(); | |
1665 else | |
1666 scr_LogPrint(LPRINT_LOGNORM, | |
1667 "Warning: you're not connected to the server."); | |
1668 } | |
1669 | |
1194
03d8fafe8104
Remove a warning when gpgme is disabled
Mikael Berthe <mikael@lilotux.net>
parents:
1166
diff
changeset
|
1670 #ifdef HAVE_GPGME |
1104
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1671 // keys_mismatch(key, expectedkey) |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1672 // Return TRUE if both keys are non-null and "expectedkey" doesn't match |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1673 // the end of "key". |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1674 // If one of the keys is null, return FALSE. |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1675 // If expectedkey is less than 8 bytes long, return TRUE. |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1676 // |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1677 // Example: keys_mismatch("C9940A9BB0B92210", "B0B92210") will return FALSE. |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1678 static bool keys_mismatch(const char *key, const char *expectedkey) |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1679 { |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1680 int lk, lek; |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1681 |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1682 if (!expectedkey || !key) |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1683 return FALSE; |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1684 |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1685 lk = strlen(key); |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1686 lek = strlen(expectedkey); |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1687 |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1688 // If the expectedkey is less than 8 bytes long, this is probably a |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1689 // user mistake so we consider it's a mismatch. |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1690 if (lek < 8) |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1691 return TRUE; |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1692 |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1693 if (lek < lk) |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1694 key += lk - lek; |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1695 |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1696 return strcasecmp(key, expectedkey); |
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1697 } |
1194
03d8fafe8104
Remove a warning when gpgme is disabled
Mikael Berthe <mikael@lilotux.net>
parents:
1166
diff
changeset
|
1698 #endif |
1104
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1699 |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1700 // check_signature(barejid, resourcename, xmldata, text) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1701 // Verify the signature (in xmldata) of "text" for the contact |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1702 // barejid/resourcename. |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1703 // xmldata is the 'jabber:x:signed' stanza. |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1704 // If the key id is found, the contact's PGP data are updated. |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1705 static void check_signature(const char *barejid, const char *rname, |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1706 xmlnode xmldata, const char *text) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1707 { |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1708 #ifdef HAVE_GPGME |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1709 char *p, *key; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1710 GSList *sl_buddy; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1711 struct pgp_data *res_pgpdata; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1712 gpgme_sigsum_t sigsum; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1713 |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1714 // All parameters must be valid |
1045
96be69d3a5fd
Verify signatures for empty status messages
Mikael Berthe <mikael@lilotux.net>
parents:
1044
diff
changeset
|
1715 if (!(xmldata && barejid && rname && text)) |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1716 return; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1717 |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1718 if (!gpg_enabled()) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1719 return; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1720 |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1721 // Get the resource PGP data structure |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1722 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1723 if (!sl_buddy) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1724 return; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1725 res_pgpdata = buddy_resource_pgp(sl_buddy->data, rname); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1726 if (!res_pgpdata) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1727 return; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1728 |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1729 p = xmlnode_get_name(xmldata); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1730 if (!p || strcmp(p, "x")) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1731 return; // We expect "<x xmlns='jabber:x:signed'>" |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1732 |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1733 // Get signature |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1734 p = xmlnode_get_data(xmldata); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1735 if (!p) |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1736 return; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1737 |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1738 key = gpg_verify(p, text, &sigsum); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1739 if (key) { |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1740 const char *expectedkey; |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1741 char *buf; |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1742 g_free(res_pgpdata->sign_keyid); |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1743 res_pgpdata->sign_keyid = key; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1744 res_pgpdata->last_sigsum = sigsum; |
1046
a3748bd3d010
Tell the user when a signature is bad
Mikael Berthe <mikael@lilotux.net>
parents:
1045
diff
changeset
|
1745 if (sigsum & GPGME_SIGSUM_RED) { |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1746 buf = g_strdup_printf("Bad signature from <%s/%s>", barejid, rname); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
1747 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0); |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1748 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1749 g_free(buf); |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1750 } |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1751 // Verify that the key id is the one we expect. |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1752 expectedkey = settings_pgp_getkeyid(barejid); |
1104
382972712208
Allow short key format in check_signature()
Mikael Berthe <mikael@lilotux.net>
parents:
1099
diff
changeset
|
1753 if (keys_mismatch(key, expectedkey)) { |
1067
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1754 buf = g_strdup_printf("Warning: The KeyId from <%s/%s> doesn't match " |
a5dc85fdebde
Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents:
1065
diff
changeset
|
1755 "the key you set up", barejid, rname); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
1756 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0); |
1046
a3748bd3d010
Tell the user when a signature is bad
Mikael Berthe <mikael@lilotux.net>
parents:
1045
diff
changeset
|
1757 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
a3748bd3d010
Tell the user when a signature is bad
Mikael Berthe <mikael@lilotux.net>
parents:
1045
diff
changeset
|
1758 g_free(buf); |
a3748bd3d010
Tell the user when a signature is bad
Mikael Berthe <mikael@lilotux.net>
parents:
1045
diff
changeset
|
1759 } |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1760 } |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1761 #endif |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1762 } |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1763 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
1764 static void gotmessage(char *type, const char *from, const char *body, |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1765 const char *enc, const char *subject, time_t timestamp, |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1766 xmlnode xmldata_signed) |
29 | 1767 { |
1058 | 1768 char *bjid; |
956
819396bebdf5
Do not block system messages when block_unsubscribed is set
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
1769 const char *rname, *s; |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1770 char *decrypted_pgp = NULL; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1771 char *decrypted_otr = NULL; |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
1772 int otr_msg = 0, free_msg = 0; |
29 | 1773 |
1058 | 1774 bjid = jidtodisp(from); |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1775 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
1776 rname = strchr(from, JID_RESOURCE_SEPARATOR); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
1777 if (rname) rname++; |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
1778 |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
1779 #ifdef HAVE_GPGME |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
1780 if (enc && gpg_enabled()) { |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1781 decrypted_pgp = gpg_decrypt(enc); |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1782 if (decrypted_pgp) { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1783 body = decrypted_pgp; |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1784 } |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
1785 } |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
1786 // Check signature of an unencrypted message |
1053 | 1787 if (xmldata_signed && gpg_enabled()) |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1788 check_signature(bjid, rname, xmldata_signed, decrypted_pgp); |
1042
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
1789 #endif |
8a395c2cafc4
Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents:
1023
diff
changeset
|
1790 |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
1791 #ifdef HAVE_LIBOTR |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1792 if (otr_enabled()) { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1793 decrypted_otr = (char*)body; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1794 otr_msg = otr_receive(&decrypted_otr, bjid, &free_msg); |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1795 if (!decrypted_otr) { |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1796 goto gotmessage_return; |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1797 } |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1798 body = decrypted_otr; |
1299
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
1799 } |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
1800 #endif |
3b338a5c01fc
OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents:
1290
diff
changeset
|
1801 |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1802 // Check for unexpected groupchat messages |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1803 // If we receive a groupchat message from a room we're not a member of, |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1804 // this is probably a server issue and the best we can do is to send |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1805 // a type unavailable. |
1058 | 1806 if (type && !strcmp(type, "groupchat") && !roster_getnickname(bjid)) { |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1807 // It shouldn't happen, probably a server issue |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1808 GSList *room_elt; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1809 char *mbuf; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1810 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1811 mbuf = g_strdup_printf("Unexpected groupchat packet!"); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1812 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
|
1813 scr_WriteIncomingMessage(bjid, mbuf, 0, HBB_PREFIX_INFO, 0); |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1814 g_free(mbuf); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1815 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1816 // Send back an unavailable packet |
1058 | 1817 jb_setstatus(offline, bjid, "", TRUE); |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1818 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1819 // MUC |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1820 // Make sure this is a room (it can be a conversion user->room) |
1058 | 1821 room_elt = roster_find(bjid, jidsearch, 0); |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1822 if (!room_elt) { |
1355 | 1823 room_elt = roster_add_user(bjid, NULL, NULL, ROSTER_TYPE_ROOM, |
1824 sub_none, -1); | |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1825 } else { |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1826 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1827 } |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1828 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1829 buddylist_build(); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1830 scr_DrawRoster(); |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1831 goto gotmessage_return; |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1832 } |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1833 |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
1834 // We don't call the message_in hook if 'block_unsubscribed' is true and |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
1835 // this is a regular message from an unsubscribed user. |
956
819396bebdf5
Do not block system messages when block_unsubscribed is set
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
1836 // System messages (from our server) are allowed. |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
1837 if (!settings_opt_get_int("block_unsubscribed") || |
1058 | 1838 (roster_getsubscription(bjid) & sub_from) || |
956
819396bebdf5
Do not block system messages when block_unsubscribed is set
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
1839 (type && strcmp(type, "chat")) || |
1058 | 1840 ((s = settings_opt_get("server")) != NULL && !strcasecmp(bjid, s))) { |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1841 gchar *fullbody = NULL; |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1842 if (subject) { |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1843 if (body) |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1844 fullbody = g_strdup_printf("[%s]\n%s", subject, body); |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1845 else |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1846 fullbody = g_strdup_printf("[%s]\n", subject); |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1847 body = fullbody; |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1848 } |
1058 | 1849 hk_message_in(bjid, rname, timestamp, body, type, |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1850 ((decrypted_pgp || otr_msg) ? TRUE : FALSE)); |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
1851 g_free(fullbody); |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
1852 } else { |
1058 | 1853 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", bjid); |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
1854 } |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1855 |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1856 gotmessage_return: |
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1857 // Clean up and exit |
1058 | 1858 g_free(bjid); |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1859 g_free(decrypted_pgp); |
1333
e30a9d907105
Minor coding style adjustments
Mikael Berthe <mikael@lilotux.net>
parents:
1330
diff
changeset
|
1860 if (free_msg) |
1347
07816313073b
Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents:
1344
diff
changeset
|
1861 g_free(decrypted_otr); |
29 | 1862 } |
1863 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
1864 static const char *defaulterrormsg(int code) |
420
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1865 { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1866 const char *desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1867 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1868 switch(code) { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1869 case 401: desc = "Unauthorized"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1870 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1871 case 302: desc = "Redirect"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1872 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1873 case 400: desc = "Bad request"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1874 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1875 case 402: desc = "Payment Required"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1876 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1877 case 403: desc = "Forbidden"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1878 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1879 case 404: desc = "Not Found"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1880 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1881 case 405: desc = "Not Allowed"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1882 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1883 case 406: desc = "Not Acceptable"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1884 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1885 case 407: desc = "Registration Required"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1886 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1887 case 408: desc = "Request Timeout"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1888 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1889 case 409: desc = "Conflict"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1890 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1891 case 500: desc = "Internal Server Error"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1892 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1893 case 501: desc = "Not Implemented"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1894 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1895 case 502: desc = "Remote Server Error"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1896 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1897 case 503: desc = "Service Unavailable"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1898 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1899 case 504: desc = "Remote Server Timeout"; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1900 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1901 default: |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1902 desc = NULL; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1903 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1904 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1905 return desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1906 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
1907 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1908 // display_server_error(x) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1909 // Display the error to the user |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1910 // x: error tag xmlnode pointer |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
1911 void display_server_error(xmlnode x) |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1912 { |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1913 const char *desc = NULL; |
862
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1914 char *sdesc; |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1915 int code = 0; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1916 char *s; |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1917 const char *p; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1918 |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
1919 if (!x) return; |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
1920 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1921 /* RFC3920: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1922 * The <error/> element: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1923 * o MUST contain a child element corresponding to one of the defined |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1924 * stanza error conditions specified below; this element MUST be |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1925 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace. |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1926 */ |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1927 p = xmlnode_get_name(xmlnode_get_firstchild(x)); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1928 if (p) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1929 scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]", p); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1930 |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1931 // For backward compatibility |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1932 if ((s = xmlnode_get_attrib(x, "code")) != NULL) { |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1933 code = atoi(s); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1934 // Default message |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1935 desc = defaulterrormsg(code); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1936 } |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1937 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1938 // Error tag data is better, if available |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1939 s = xmlnode_get_data(x); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1940 if (s && *s) desc = s; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1941 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1942 // And sometimes there is a text message |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
1943 s = xmlnode_get_tag_data(x, "text"); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1944 if (s && *s) desc = s; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1945 |
1344
44ff580ee388
Fix a potential segfault in display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1343
diff
changeset
|
1946 // If we still have no description, let's give up |
44ff580ee388
Fix a potential segfault in display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1343
diff
changeset
|
1947 if (!desc) |
44ff580ee388
Fix a potential segfault in display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1343
diff
changeset
|
1948 return; |
44ff580ee388
Fix a potential segfault in display_server_error()
Mikael Berthe <mikael@lilotux.net>
parents:
1343
diff
changeset
|
1949 |
862
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1950 // Strip trailing newlines |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1951 sdesc = g_strdup(desc); |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1952 for (s = sdesc; *s; s++) ; |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1953 if (s > sdesc) |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1954 s--; |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1955 while (s >= sdesc && (*s == '\n' || *s == '\r')) |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1956 *s-- = '\0'; |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1957 |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1958 scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, sdesc); |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
1959 g_free(sdesc); |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1960 } |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
1961 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
1962 static void statehandler(jconn conn, int state) |
31 | 1963 { |
1964 static int previous_state = -1; | |
1965 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1966 scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state); |
31 | 1967 |
1968 switch(state) { | |
1969 case JCONN_STATE_OFF: | |
192 | 1970 if (previous_state != JCONN_STATE_OFF) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1971 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server"); |
37 | 1972 |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
1973 // Sometimes the state isn't correctly updated |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
1974 if (jc) |
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
1975 jc->state = JCONN_STATE_OFF; |
112 | 1976 online = FALSE; |
159 | 1977 mystatus = offline; |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1978 // Free bookmarks |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1979 xmlnode_free(bookmarks); |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1980 bookmarks = NULL; |
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1981 // Free roster |
164 | 1982 roster_free(); |
1212
3b21353e4ad3
Free rosternotes data when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
1983 xmlnode_free(rosternotes); |
3b21353e4ad3
Free rosternotes data when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
1984 rosternotes = NULL; |
1008
bbf53cd43fbb
Functions to update room bookmarks
Mikael Berthe <mikael@lilotux.net>
parents:
1003
diff
changeset
|
1985 // Update display |
164 | 1986 update_roster = TRUE; |
865
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
864
diff
changeset
|
1987 scr_UpdateBuddyWindow(); |
31 | 1988 break; |
1989 | |
1990 case JCONN_STATE_CONNECTED: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1991 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server"); |
31 | 1992 break; |
1993 | |
1994 case JCONN_STATE_AUTH: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1995 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server"); |
31 | 1996 break; |
1997 | |
1998 case JCONN_STATE_ON: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1999 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
2000 "established"); |
112 | 2001 online = TRUE; |
1254
401639413340
More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents:
1244
diff
changeset
|
2002 update_last_use(); |
1014
99c5278bf6b8
Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents:
1013
diff
changeset
|
2003 // We set AutoConnection to true after the 1st successful connection |
1381
40095d413da9
Fix compilation on OpenBSD
Mikael Berthe <mikael@lilotux.net>
parents:
1380
diff
changeset
|
2004 AutoConnection = TRUE; |
31 | 2005 break; |
2006 | |
35 | 2007 case JCONN_STATE_CONNECTING: |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
2008 if (previous_state != state) |
408
73433860665c
Tune previous usleep() change
Mikael Berthe <mikael@lilotux.net>
parents:
407
diff
changeset
|
2009 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server"); |
35 | 2010 break; |
2011 | |
31 | 2012 default: |
2013 break; | |
2014 } | |
2015 previous_state = state; | |
2016 } | |
2017 | |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2018 inline static xmlnode xml_get_xmlns(xmlnode xmldata, const char *xmlns) |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2019 { |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2020 xmlnode x; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2021 char *p; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2022 |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2023 x = xmlnode_get_firstchild(xmldata); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2024 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2025 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcmp(p, xmlns)) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2026 break; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2027 } |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2028 return x; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2029 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2030 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2031 static time_t xml_get_timestamp(xmlnode xmldata) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2032 { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2033 xmlnode x; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2034 char *p; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2035 |
1282
d438b56990cd
Implement XEP-0203 (Delayed Delivery)
Mikael Berthe <mikael@lilotux.net>
parents:
1255
diff
changeset
|
2036 x = xml_get_xmlns(xmldata, NS_XMPP_DELAY); |
d438b56990cd
Implement XEP-0203 (Delayed Delivery)
Mikael Berthe <mikael@lilotux.net>
parents:
1255
diff
changeset
|
2037 if (x && !strcmp(xmlnode_get_name(x), "delay") && |
d438b56990cd
Implement XEP-0203 (Delayed Delivery)
Mikael Berthe <mikael@lilotux.net>
parents:
1255
diff
changeset
|
2038 (p = xmlnode_get_attrib(x, "stamp")) != NULL) |
d438b56990cd
Implement XEP-0203 (Delayed Delivery)
Mikael Berthe <mikael@lilotux.net>
parents:
1255
diff
changeset
|
2039 return from_iso8601(p, 1); |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2040 x = xml_get_xmlns(xmldata, NS_DELAY); |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2041 if ((p = xmlnode_get_attrib(x, "stamp")) != NULL) |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2042 return from_iso8601(p, 1); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2043 return 0; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2044 } |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2045 |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2046 // muc_get_item_info(...) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2047 // Get room member's information from xmlndata. |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2048 // The variables must be initialized before calling this function, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2049 // because they are not touched if the relevant information is missing. |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2050 static void muc_get_item_info(const char *from, xmlnode xmldata, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2051 enum imrole *mbrole, enum imaffiliation *mbaffil, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2052 const char **mbjid, const char **mbnick, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2053 const char **actorjid, const char **reason) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2054 { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2055 xmlnode y, z; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2056 char *p; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2057 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2058 y = xmlnode_get_tag(xmldata, "item"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2059 if (!y) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2060 return; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2061 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2062 p = xmlnode_get_attrib(y, "affiliation"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2063 if (p) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2064 if (!strcmp(p, "owner")) *mbaffil = affil_owner; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2065 else if (!strcmp(p, "admin")) *mbaffil = affil_admin; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2066 else if (!strcmp(p, "member")) *mbaffil = affil_member; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2067 else if (!strcmp(p, "outcast")) *mbaffil = affil_outcast; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2068 else if (!strcmp(p, "none")) *mbaffil = affil_none; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2069 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown affiliation \"%s\"", |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2070 from, p); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2071 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2072 p = xmlnode_get_attrib(y, "role"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2073 if (p) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2074 if (!strcmp(p, "moderator")) *mbrole = role_moderator; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2075 else if (!strcmp(p, "participant")) *mbrole = role_participant; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2076 else if (!strcmp(p, "visitor")) *mbrole = role_visitor; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2077 else if (!strcmp(p, "none")) *mbrole = role_none; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2078 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown role \"%s\"", |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2079 from, p); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2080 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2081 *mbjid = xmlnode_get_attrib(y, "jid"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2082 *mbnick = xmlnode_get_attrib(y, "nick"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2083 // For kick/ban, there can be actor and reason tags |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2084 *reason = xmlnode_get_tag_data(y, "reason"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2085 z = xmlnode_get_tag(y, "actor"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2086 if (z) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2087 *actorjid = xmlnode_get_attrib(z, "jid"); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2088 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2089 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2090 // muc_handle_join(...) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2091 // Handle a join event in a MUC room. |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2092 // 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
|
2093 // 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
|
2094 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
|
2095 const char *roomjid, const char *ournick, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2096 enum room_printstatus printstatus, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2097 time_t usttime, int log_muc_conf) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2098 { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2099 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
|
2100 gchar *mbuf; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2101 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2102 if (!buddy_getinsideroom(room_elt->data)) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2103 // 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
|
2104 // 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
|
2105 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2106 buddy_setinsideroom(room_elt->data, TRUE); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2107 // 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
|
2108 scr_setmsgflag_if_needed(roomjid, FALSE); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2109 // Add a message to the tracelog file |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2110 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
|
2111 scr_LogPrint(LPRINT_LOGNORM, "%s", mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2112 g_free(mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2113 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
|
2114 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2115 // 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
|
2116 if (strcmp(ournick, rname)) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2117 // 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
|
2118 // 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
|
2119 // so we use 0 here. |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2120 scr_WriteIncomingMessage(roomjid, mbuf, 0, |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2121 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2122 if (log_muc_conf) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2123 hlog_write_message(roomjid, 0, -1, mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2124 g_free(mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2125 if (printstatus != status_none) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2126 mbuf = g_strdup_printf("%s has joined", rname); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2127 else |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2128 mbuf = NULL; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2129 new_member = TRUE; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2130 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2131 } else { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2132 mbuf = NULL; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2133 if (strcmp(ournick, rname)) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2134 if (printstatus != status_none) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2135 mbuf = g_strdup_printf("%s has joined", rname); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2136 new_member = TRUE; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2137 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2138 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2139 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2140 if (mbuf) { |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2141 guint msgflags = HBB_PREFIX_INFO; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2142 if (!settings_opt_get_int("muc_flag_joins")) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2143 msgflags |= HBB_PREFIX_NOFLAG; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2144 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2145 if (log_muc_conf) |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2146 hlog_write_message(roomjid, 0, -1, mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2147 g_free(mbuf); |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2148 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2149 |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2150 return new_member; |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2151 } |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2152 |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2153 static void handle_presence_muc(const char *from, xmlnode xmldata, |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2154 const char *roomjid, const char *rname, |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2155 enum imstatus ust, char *ustmsg, |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2156 time_t usttime, char bpprio) |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2157 { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2158 xmlnode y; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2159 char *p; |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2160 char *mbuf; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2161 const char *ournick; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2162 enum imrole mbrole = role_none; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2163 enum imaffiliation mbaffil = affil_none; |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2164 enum room_printstatus printstatus; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2165 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
|
2166 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
|
2167 const char *actorjid = NULL, *reason = NULL; |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
2168 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
|
2169 guint statuscode = 0; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2170 guint nickchange = 0; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2171 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
|
2172 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
|
2173 guint msgflags; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2174 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2175 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
|
2176 |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2177 room_elt = roster_find(roomjid, jidsearch, 0); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2178 if (!room_elt) { |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2179 // Add room if it doesn't already exist |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2180 // 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
|
2181 // network issue?) |
1355 | 2182 room_elt = roster_add_user(roomjid, NULL, NULL, ROSTER_TYPE_ROOM, |
2183 sub_none, -1); | |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2184 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
|
2185 } else { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2186 // 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
|
2187 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2188 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2189 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2190 // Get room member's information |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2191 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
|
2192 &actorjid, &reason); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2193 |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2194 // Get our room nickname |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2195 ournick = buddy_getnickname(room_elt->data); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2196 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2197 if (!ournick) { |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2198 // It shouldn't happen, probably a server issue |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2199 mbuf = g_strdup_printf("Unexpected groupchat packet!"); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2200 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2201 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
|
2202 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
|
2203 g_free(mbuf); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2204 // Send back an unavailable packet |
1050
ea71d31a2607
PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
1046
diff
changeset
|
2205 jb_setstatus(offline, roomjid, "", TRUE); |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2206 scr_DrawRoster(); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2207 return; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2208 } |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2209 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2210 // 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
|
2211 // 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
|
2212 // 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
|
2213 // 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
|
2214 // 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
|
2215 // 321,322,332: the user has been removed from the room |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2216 y = xmlnode_get_tag(xmldata, "status"); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2217 if (y) { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2218 p = xmlnode_get_attrib(y, "code"); |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2219 if (p) |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2220 statuscode = atoi(p); |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2221 } |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2222 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2223 // Get the room's "print_status" settings |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2224 printstatus = buddy_getprintstatus(room_elt->data); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2225 if (printstatus == status_default) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2226 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
|
2227 if (printstatus > 3) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2228 printstatus = status_default; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2229 } |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2230 |
1396
8f9928839a36
Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents:
1395
diff
changeset
|
2231 // 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
|
2232 if (statuscode == 201) |
8f9928839a36
Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents:
1395
diff
changeset
|
2233 jb_room_unlock(roomjid); |
8f9928839a36
Automatically unlock new rooms (suggested by Michael Weiser)
Mikael Berthe <mikael@lilotux.net>
parents:
1395
diff
changeset
|
2234 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2235 // 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
|
2236 if (statuscode == 303 && mbnick) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2237 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
|
2238 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
|
2239 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
1166
c4da23bf8958
Add option 'muc_flag_joins'
Mikael Berthe <mikael@lilotux.net>
parents:
1164
diff
changeset
|
2240 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
|
2241 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
|
2242 g_free(mbuf); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2243 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
|
2244 // Maybe it's _our_ nickname... |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
2245 if (ournick && !strcmp(rname, ournick)) |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2246 buddy_setnickname(room_elt->data, mbnick); |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2247 nickchange = TRUE; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2248 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2249 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2250 // Check for departure/arrival |
1161
45d3b9dda43d
Fix a MUC problem with some servers
Mikael Berthe <mikael@lilotux.net>
parents:
1132
diff
changeset
|
2251 if (!mbnick && ust == offline) { |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2252 // Somebody is leaving |
586 | 2253 enum { leave=0, kick, ban } how = leave; |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2254 bool we_left = FALSE; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2255 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2256 if (statuscode == 307) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2257 how = kick; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2258 else if (statuscode == 301) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2259 how = ban; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2260 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2261 // 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
|
2262 if (ournick && !strcmp(rname, ournick)) { |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2263 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
|
2264 buddy_setinsideroom(room_elt->data, FALSE); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2265 buddy_setnickname(room_elt->data, NULL); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2266 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
|
2267 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
|
2268 scr_UpdateChatStatus(FALSE); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2269 update_roster = TRUE; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2270 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2271 |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2272 // The message depends on _who_ left, and _how_ |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2273 if (how) { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2274 gchar *mbuf_end; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2275 // Forced leave |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2276 if (actorjid) { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2277 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
|
2278 (how == ban ? "banned" : "kicked"), |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2279 roomjid, actorjid, reason); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2280 } else { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2281 mbuf_end = g_strdup_printf("%s from %s.", |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2282 (how == ban ? "banned" : "kicked"), |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2283 roomjid); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2284 } |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2285 if (we_left) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2286 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
|
2287 else |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2288 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
|
2289 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2290 g_free(mbuf_end); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2291 } else { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2292 // Natural leave |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2293 if (we_left) { |
616
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
2294 xmlnode destroynode = xmlnode_get_tag(xmldata, "destroy"); |
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
2295 if (destroynode) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2296 if ((reason = xmlnode_get_tag_data(destroynode, "reason"))) { |
616
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
2297 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
|
2298 "the room has been destroyed: %s", |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2299 roomjid, reason); |
616
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
2300 } else { |
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
2301 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
|
2302 "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
|
2303 } |
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
2304 } else { |
599 | 2305 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
|
2306 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2307 } 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
|
2308 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
|
2309 // 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
|
2310 // 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
|
2311 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
|
2312 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
|
2313 } 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
|
2314 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
|
2315 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
|
2316 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
|
2317 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
|
2318 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
2319 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2320 } |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2321 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2322 // 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
|
2323 // 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
|
2324 if (we_left || printstatus != status_none) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2325 msgflags = HBB_PREFIX_INFO; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2326 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
|
2327 msgflags |= HBB_PREFIX_NOFLAG; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2328 scr_WriteIncomingMessage(roomjid, mbuf, usttime, msgflags, 0); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2329 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2330 |
1166
c4da23bf8958
Add option 'muc_flag_joins'
Mikael Berthe <mikael@lilotux.net>
parents:
1164
diff
changeset
|
2331 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
|
2332 hlog_write_message(roomjid, 0, -1, mbuf); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2333 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
2334 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
|
2335 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
|
2336 g_free(mbuf); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2337 return; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2338 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2339 g_free(mbuf); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2340 } 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
|
2341 ust != offline) { |
1384
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2342 // Somebody is joining |
f762805b3f42
Split function handle_presence_muc()
Mikael Berthe <mikael@lilotux.net>
parents:
1383
diff
changeset
|
2343 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
|
2344 printstatus, usttime, log_muc_conf); |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2345 } else { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2346 // This is a simple member status change |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2347 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2348 if (printstatus == status_all && !nickchange) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2349 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
|
2350 imstatus2char[ust], ((ustmsg) ? ustmsg : "")); |
1380
605f9e1f9f76
Add missing PREFIX_NOFLAG flag...
Mikael Berthe <mikael@lilotux.net>
parents:
1379
diff
changeset
|
2351 scr_WriteIncomingMessage(roomjid, mbuf, usttime, |
605f9e1f9f76
Add missing PREFIX_NOFLAG flag...
Mikael Berthe <mikael@lilotux.net>
parents:
1379
diff
changeset
|
2352 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
|
2353 g_free(mbuf); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2354 } |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2355 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2356 |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2357 // Sanity check, shouldn't happen... |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2358 if (!rname) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2359 return; |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2360 |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2361 // Update room member status |
1377
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2362 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
|
2363 mbrole, mbaffil, mbjid); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2364 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2365 autowhois = buddy_getautowhois(room_elt->data); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2366 if (autowhois == autowhois_default) |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2367 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
|
2368 autowhois_on : autowhois_off); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2369 |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2370 if (new_member && autowhois == autowhois_on) { |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2371 // 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
|
2372 gchar *joiner_nick = from_utf8(rname); |
1415
317f8d181626
Rename command public functions
Mikael Berthe <mikael@lilotux.net>
parents:
1414
diff
changeset
|
2373 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
|
2374 g_free(joiner_nick); |
cd9182f0b5c7
Add /room setopt {print_status,auto_whois}
Mikael Berthe <mikael@lilotux.net>
parents:
1365
diff
changeset
|
2375 } |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2376 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2377 scr_DrawRoster(); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2378 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2379 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2380 static void handle_packet_presence(jconn conn, char *type, char *from, |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2381 xmlnode xmldata) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2382 { |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2383 char *p, *r; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2384 char *ustmsg; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2385 const char *rname; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2386 enum imstatus ust; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2387 char bpprio; |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
2388 time_t timestamp = 0L; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2389 xmlnode muc_packet; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2390 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
2391 rname = strchr(from, JID_RESOURCE_SEPARATOR); |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2392 if (rname) rname++; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2393 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2394 r = jidtodisp(from); |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2395 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2396 // Check for MUC presence packet |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2397 muc_packet = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user"); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2398 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2399 if (type && !strcmp(type, TMSG_ERROR)) { |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2400 xmlnode x; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2401 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2402 x = xmlnode_get_tag(xmldata, TMSG_ERROR); |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2403 display_server_error(x); |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2404 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2405 // Let's check it isn't a nickname conflict. |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2406 // XXX Note: We should handle the <conflict/> string condition. |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2407 if ((p = xmlnode_get_attrib(x, "code")) != NULL) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2408 if (atoi(p) == 409) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2409 // 409 = conlict (nickname is in use or registered by another user) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2410 // If we are not inside this room, we should reset the nickname |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2411 GSList *room_elt = roster_find(r, jidsearch, 0); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2412 if (room_elt && !buddy_getinsideroom(room_elt->data)) |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2413 buddy_setnickname(room_elt->data, NULL); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2414 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2415 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2416 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2417 g_free(r); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2418 return; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2419 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2420 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2421 p = xmlnode_get_tag_data(xmldata, "priority"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2422 if (p && *p) bpprio = (gchar)atoi(p); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2423 else bpprio = 0; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2424 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2425 ust = available; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2426 p = xmlnode_get_tag_data(xmldata, "show"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2427 if (p) { |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2428 if (!strcmp(p, "away")) ust = away; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2429 else if (!strcmp(p, "dnd")) ust = dontdisturb; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2430 else if (!strcmp(p, "xa")) ust = notavail; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2431 else if (!strcmp(p, "chat")) ust = freeforchat; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2432 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2433 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2434 if (type && !strcmp(type, "unavailable")) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2435 ust = offline; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2436 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2437 ustmsg = xmlnode_get_tag_data(xmldata, "status"); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2438 |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2439 // Timestamp? |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2440 timestamp = xml_get_timestamp(xmldata); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2441 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2442 if (muc_packet) { |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2443 // This is a MUC presence message |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2444 handle_presence_muc(from, muc_packet, r, rname, |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
2445 ust, ustmsg, timestamp, bpprio); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2446 } else { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2447 // Not a MUC message, so this is a regular buddy... |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2448 // Call hk_statuschange() if status has changed or if the |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2449 // status message is different |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
2450 const char *m; |
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
2451 m = roster_getstatusmsg(r, rname); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2452 if ((ust != roster_getstatus(r, rname)) || |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
2453 (!ustmsg && m && m[0]) || (ustmsg && (!m || strcmp(ustmsg, m)))) |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2454 hk_statuschange(r, rname, bpprio, timestamp, ust, ustmsg); |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
2455 // Presence signature processing |
1045
96be69d3a5fd
Verify signatures for empty status messages
Mikael Berthe <mikael@lilotux.net>
parents:
1044
diff
changeset
|
2456 if (!ustmsg) |
96be69d3a5fd
Verify signatures for empty status messages
Mikael Berthe <mikael@lilotux.net>
parents:
1044
diff
changeset
|
2457 ustmsg = ""; // Some clients omit the <status/> element :-( |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
2458 check_signature(r, rname, xml_get_xmlns(xmldata, NS_SIGNED), ustmsg); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2459 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2460 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2461 g_free(r); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2462 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2463 |
1330
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
2464 // got_invite(from, to, reason, passwd) |
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
2465 // 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
|
2466 // "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
|
2467 // be provided. |
1128 | 2468 static void got_invite(char* from, char *to, char* reason, char* passwd) |
2469 { | |
2470 eviqs *evn; | |
2471 event_muc_invitation *invitation; | |
2472 GString *sbuf; | |
1236
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
2473 char *barejid; |
1237
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
2474 GSList *room_elt; |
1128 | 2475 |
2476 sbuf = g_string_new(""); | |
2477 if (reason) { | |
2478 g_string_printf(sbuf, | |
2479 "Received an invitation to <%s>, from <%s>, reason: %s", | |
2480 to, from, reason); | |
2481 } else { | |
2482 g_string_printf(sbuf, "Received an invitation to <%s>, from <%s>", | |
2483 to, from); | |
2484 } | |
1236
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
2485 |
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
2486 barejid = jidtodisp(from); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2487 scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0); |
1128 | 2488 scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str); |
2489 | |
2490 evn = evs_new(EVS_TYPE_INVITATION, EVS_MAX_TIMEOUT); | |
2491 if (evn) { | |
2492 evn->callback = &evscallback_invitation; | |
2493 invitation = g_new(event_muc_invitation, 1); | |
2494 invitation->to = g_strdup(to); | |
2495 invitation->from = g_strdup(from); | |
2496 invitation->passwd = g_strdup(passwd); | |
2497 invitation->reason = g_strdup(reason); | |
2498 evn->data = invitation; | |
2499 evn->desc = g_strdup_printf("<%s> invites you to %s ", from, to); | |
2500 g_string_printf(sbuf, "Please use /event %s accept|reject", evn->id); | |
2501 } else { | |
2502 g_string_printf(sbuf, "Unable to create a new event!"); | |
2503 } | |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2504 scr_WriteIncomingMessage(barejid, sbuf->str, 0, HBB_PREFIX_INFO, 0); |
1128 | 2505 scr_LogPrint(LPRINT_LOGNORM, "%s", sbuf->str); |
2506 g_string_free(sbuf, TRUE); | |
1330
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
2507 g_free(barejid); |
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
2508 |
7ba1b6d7ddcd
Fix a bug when receiving an invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1311
diff
changeset
|
2509 // 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
|
2510 barejid = jidtodisp(to); |
1237
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
2511 room_elt = roster_find(barejid, jidsearch, 0); |
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
2512 if (room_elt) |
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
2513 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
dcb99f0b5aaa
Small MUC invitation improvement
Mikael Berthe <mikael@lilotux.net>
parents:
1236
diff
changeset
|
2514 |
1236
f7b35b1c343d
Fix a roster bug when receiving a MUC invitation
Mikael Berthe <mikael@lilotux.net>
parents:
1215
diff
changeset
|
2515 g_free(barejid); |
1128 | 2516 } |
2517 | |
2518 // Specific MUC message handling (for example invitation processing) | |
2519 static void got_muc_message(char *from, xmlnode x) | |
2520 { | |
2521 xmlnode invite = xmlnode_get_tag(x, "invite"); | |
2522 if (invite) | |
2523 { | |
2524 char* invite_from; | |
2525 char *reason = NULL; | |
2526 char *password = NULL; | |
2527 xmlnode r; | |
2528 | |
2529 invite_from = xmlnode_get_attrib(invite, "from"); | |
2530 r = xmlnode_get_tag(invite, "reason"); | |
2531 if (r) | |
2532 reason = xmlnode_get_tag_data(r, NULL); | |
2533 r = xmlnode_get_tag(invite, "password"); | |
2534 if (r) | |
2535 password = xmlnode_get_tag_data(r, NULL); | |
2536 if (invite_from) | |
2537 got_invite(invite_from, from, reason, password); | |
2538 } | |
2539 // TODO | |
2540 // handle status code = 100 ( not anonymous ) | |
2541 // handle status code = 170 ( changement de config ) | |
2542 // 10.2.1 Notification of Configuration Changes | |
2543 // declined invitation | |
2544 } | |
2545 | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2546 static void handle_packet_message(jconn conn, char *type, char *from, |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2547 xmlnode xmldata) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2548 { |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2549 char *p, *r, *s; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2550 xmlnode x; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2551 char *body = NULL; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2552 char *enc = NULL; |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2553 char *subject = NULL; |
1001
dff25377c11f
Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents:
999
diff
changeset
|
2554 time_t timestamp = 0L; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2555 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2556 body = xmlnode_get_tag_data(xmldata, "body"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2557 |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2558 x = xml_get_xmlns(xmldata, NS_ENCRYPTED); |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2559 if (x && (p = xmlnode_get_data(x)) != NULL) |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2560 enc = p; |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2561 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2562 p = xmlnode_get_tag_data(xmldata, "subject"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2563 if (p != NULL) { |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2564 if (!type || strcmp(type, TMSG_GROUPCHAT)) { // Chat message |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2565 subject = p; |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2566 } else { // Room topic |
549
448e299e45da
MUC: "/room topic" shows the current room topic
Mikael Berthe <mikael@lilotux.net>
parents:
547
diff
changeset
|
2567 GSList *roombuddy; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2568 gchar *mbuf; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2569 gchar *subj = p; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2570 // Get the room (s) and the nickname (r) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2571 s = g_strdup(from); |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
2572 r = strchr(s, JID_RESOURCE_SEPARATOR); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2573 if (r) *r++ = 0; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2574 else r = s; |
549
448e299e45da
MUC: "/room topic" shows the current room topic
Mikael Berthe <mikael@lilotux.net>
parents:
547
diff
changeset
|
2575 // Set the new topic |
448e299e45da
MUC: "/room topic" shows the current room topic
Mikael Berthe <mikael@lilotux.net>
parents:
547
diff
changeset
|
2576 roombuddy = roster_find(s, jidsearch, 0); |
448e299e45da
MUC: "/room topic" shows the current room topic
Mikael Berthe <mikael@lilotux.net>
parents:
547
diff
changeset
|
2577 if (roombuddy) |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2578 buddy_settopic(roombuddy->data, subj); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2579 // Display inside the room window |
560
64cb4de94972
Better topic attribution
Mikael Berthe <mikael@lilotux.net>
parents:
549
diff
changeset
|
2580 if (r == s) { |
64cb4de94972
Better topic attribution
Mikael Berthe <mikael@lilotux.net>
parents:
549
diff
changeset
|
2581 // No specific resource (this is certainly history) |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2582 mbuf = g_strdup_printf("The topic has been set to: %s", subj); |
560
64cb4de94972
Better topic attribution
Mikael Berthe <mikael@lilotux.net>
parents:
549
diff
changeset
|
2583 } else { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2584 mbuf = g_strdup_printf("%s has set the topic to: %s", r, subj); |
560
64cb4de94972
Better topic attribution
Mikael Berthe <mikael@lilotux.net>
parents:
549
diff
changeset
|
2585 } |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2586 scr_WriteIncomingMessage(s, mbuf, 0, |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2587 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG, 0); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2588 if (settings_opt_get_int("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
|
2589 hlog_write_message(s, 0, -1, mbuf); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2590 g_free(s); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2591 g_free(mbuf); |
732
ab623c2df964
MUC: Update the chat status line when the topic is updated
Mikael Berthe <mikael@lilotux.net>
parents:
724
diff
changeset
|
2592 // The topic is displayed in the chat status line, so refresh now. |
ab623c2df964
MUC: Update the chat status line when the topic is updated
Mikael Berthe <mikael@lilotux.net>
parents:
724
diff
changeset
|
2593 scr_UpdateChatStatus(TRUE); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2594 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2595 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2596 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2597 // Timestamp? |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
2598 timestamp = xml_get_timestamp(xmldata); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2599 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2600 if (type && !strcmp(type, TMSG_ERROR)) { |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2601 x = xmlnode_get_tag(xmldata, TMSG_ERROR); |
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2602 display_server_error(x); |
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
|
2603 #if defined JEP0022 || defined JEP0085 |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
2604 // If the JEP85/22 support is probed, set it back to unknown so that |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
2605 // we probe it again. |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
2606 chatstates_reset_probed(from); |
9687ecc59303
Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents:
998
diff
changeset
|
2607 #endif |
1132
1650056b96fc
Do not use chat states of error messages :)
Mikael Berthe <mikael@lilotux.net>
parents:
1128
diff
changeset
|
2608 } else { |
1650056b96fc
Do not use chat states of error messages :)
Mikael Berthe <mikael@lilotux.net>
parents:
1128
diff
changeset
|
2609 handle_state_events(from, xmldata); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2610 } |
1399
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2611 if (from && (body || subject)) |
187985455020
Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents:
1397
diff
changeset
|
2612 gotmessage(type, from, body, enc, subject, timestamp, |
1043
ebbde723614b
Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents:
1042
diff
changeset
|
2613 xml_get_xmlns(xmldata, NS_SIGNED)); |
1128 | 2614 |
2615 if (from) { | |
2616 x = xml_get_xmlns(xmldata, "http://jabber.org/protocol/muc#user"); | |
2617 if (x && !strcmp(xmlnode_get_name(x), "x")) | |
2618 got_muc_message(from, x); | |
2619 } | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2620 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2621 |
1128 | 2622 static void handle_state_events(char *from, xmlnode xmldata) |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2623 { |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2624 #if defined JEP0022 || defined JEP0085 |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
2625 xmlnode state_ns = NULL; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2626 const char *body; |
1058 | 2627 char *rname, *bjid; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2628 GSList *sl_buddy; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2629 guint events; |
990
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
2630 struct jep0022 *jep22 = NULL; |
35e7913affb7
Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents:
989
diff
changeset
|
2631 struct jep0085 *jep85 = NULL; |
997 | 2632 enum { |
2633 JEP_none, | |
2634 JEP_85, | |
2635 JEP_22 | |
2636 } which_jep = JEP_none; | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2637 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2638 rname = strchr(from, JID_RESOURCE_SEPARATOR); |
1058 | 2639 bjid = jidtodisp(from); |
2640 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER); | |
2641 g_free(bjid); | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2642 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2643 /* XXX Actually that's wrong, since it filters out server "offline" |
997 | 2644 messages (for JEP-0022). This JEP is (almost) deprecated so |
2645 we don't really care. */ | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2646 if (!sl_buddy || !rname++) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2647 return; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2648 } |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2649 |
997 | 2650 /* Let's see chich JEP the contact uses. If possible, we'll use |
2651 JEP-85, if not we'll look for JEP-22 support. */ | |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2652 events = buddy_resource_getevents(sl_buddy->data, rname); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2653 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2654 jep85 = buddy_resource_jep85(sl_buddy->data, rname); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2655 if (jep85) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2656 state_ns = xml_get_xmlns(xmldata, NS_CHATSTATES); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2657 if (state_ns) |
997 | 2658 which_jep = JEP_85; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2659 } |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2660 |
997 | 2661 if (which_jep != JEP_85) { /* Fall back to JEP-0022 */ |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2662 jep22 = buddy_resource_jep22(sl_buddy->data, rname); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2663 if (jep22) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2664 state_ns = xml_get_xmlns(xmldata, NS_EVENT); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2665 if (state_ns) |
997 | 2666 which_jep = JEP_22; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2667 } |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2668 } |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2669 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2670 if (!which_jep) { /* Sender does not use chat states */ |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2671 return; |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2672 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2673 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2674 body = xmlnode_get_tag_data(xmldata, "body"); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2675 |
997 | 2676 if (which_jep == JEP_85) { /* JEP-0085 */ |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2677 const char *p; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2678 jep85->support = CHATSTATES_SUPPORT_OK; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2679 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2680 p = xmlnode_get_name(state_ns); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2681 if (!strcmp(p, "composing")) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2682 jep85->last_state_rcvd = ROSTER_EVENT_COMPOSING; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2683 } else if (!strcmp(p, "active")) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2684 jep85->last_state_rcvd = ROSTER_EVENT_ACTIVE; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2685 } else if (!strcmp(p, "paused")) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2686 jep85->last_state_rcvd = ROSTER_EVENT_PAUSED; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2687 } else if (!strcmp(p, "inactive")) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2688 jep85->last_state_rcvd = ROSTER_EVENT_INACTIVE; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2689 } else if (!strcmp(p, "gone")) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2690 jep85->last_state_rcvd = ROSTER_EVENT_GONE; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2691 } |
992
b37348c2aa79
Chatstates: display "paused" states in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
991
diff
changeset
|
2692 events = jep85->last_state_rcvd; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2693 } else { /* JEP-0022 */ |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2694 #ifdef JEP0022 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2695 const char *msgid; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2696 jep22->support = CHATSTATES_SUPPORT_OK; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2697 jep22->last_state_rcvd = ROSTER_EVENT_NONE; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2698 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2699 msgid = xmlnode_get_attrib(xmldata, "id"); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2700 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2701 if (xmlnode_get_tag(state_ns, "composing")) { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2702 // Clear composing if the message contains a body |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2703 if (body) |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2704 events &= ~ROSTER_EVENT_COMPOSING; |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2705 else |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2706 events |= ROSTER_EVENT_COMPOSING; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2707 jep22->last_state_rcvd |= ROSTER_EVENT_COMPOSING; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2708 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2709 } else { |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2710 events &= ~ROSTER_EVENT_COMPOSING; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2711 } |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2712 |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2713 // Cache the message id |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2714 g_free(jep22->last_msgid_rcvd); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2715 if (msgid) |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2716 jep22->last_msgid_rcvd = g_strdup(msgid); |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2717 else |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2718 jep22->last_msgid_rcvd = NULL; |
989
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2719 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2720 if (xmlnode_get_tag(state_ns, "delivered")) { |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2721 jep22->last_state_rcvd |= ROSTER_EVENT_DELIVERED; |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2722 |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2723 // Do we have to send back an ACK? |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2724 if (body) |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2725 jb_send_jep22_event(from, ROSTER_EVENT_DELIVERED); |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2726 } |
859ab76e5093
Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents:
988
diff
changeset
|
2727 #endif |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2728 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2729 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2730 buddy_resource_setevents(sl_buddy->data, rname, events); |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2731 |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2732 update_roster = TRUE; |
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2733 #endif |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2734 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
2735 |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2736 static int evscallback_subscription(eviqs *evp, guint evcontext) |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2737 { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2738 char *barejid; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2739 char *buf; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2740 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2741 if (evcontext == EVS_CONTEXT_TIMEOUT) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2742 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.", |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2743 evp->id); |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2744 return 0; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2745 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2746 if (evcontext == EVS_CONTEXT_CANCEL) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2747 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id); |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2748 return 0; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2749 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2750 if (!(evcontext & EVS_CONTEXT_USER)) |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2751 return 0; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2752 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2753 // Sanity check |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2754 if (!evp->data) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2755 // Shouldn't happen, data should be set to the barejid. |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2756 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2757 return 0; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2758 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2759 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2760 // Ok, let's work now. |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2761 // evcontext: 0, 1 == reject, accept |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2762 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2763 barejid = evp->data; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2764 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2765 if (evcontext & ~EVS_CONTEXT_USER) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2766 // Accept subscription request |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2767 jb_subscr_send_auth(barejid); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2768 buf = g_strdup_printf("<%s> is allowed to receive your presence updates", |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2769 barejid); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2770 } else { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2771 // Reject subscription request |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2772 jb_subscr_cancel_auth(barejid); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2773 buf = g_strdup_printf("<%s> won't receive your presence updates", barejid); |
823
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
2774 if (settings_opt_get_int("delete_on_reject")) { |
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
2775 // Remove the buddy from the roster if there is no current subscription |
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
2776 if (roster_getsubscription(barejid) == sub_none) |
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
2777 jb_delbuddy(barejid); |
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
2778 } |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2779 } |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2780 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO, 0); |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2781 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2782 g_free(buf); |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2783 return 0; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2784 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2785 |
1128 | 2786 static void decline_invitation(event_muc_invitation *invitation, char *reason) |
2787 { | |
2788 // cut and paste from jb_room_invite | |
2789 xmlnode x,y,z; | |
2790 | |
2791 if (!invitation) return; | |
2792 if (!invitation->to || !invitation->from) return; | |
2793 | |
2794 x = jutil_msgnew(NULL, (char*)invitation->to, NULL, NULL); | |
2795 | |
2796 y = xmlnode_insert_tag(x, "x"); | |
2797 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user"); | |
2798 | |
2799 z = xmlnode_insert_tag(y, "decline"); | |
2800 xmlnode_put_attrib(z, "to", invitation->from); | |
2801 | |
2802 if (reason) { | |
2803 y = xmlnode_insert_tag(z, "reason"); | |
2804 xmlnode_insert_cdata(y, reason, (unsigned) -1); | |
2805 } | |
2806 | |
2807 jab_send(jc, x); | |
2808 xmlnode_free(x); | |
2809 jb_reset_keepalive(); | |
2810 } | |
2811 | |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2812 static int evscallback_invitation(eviqs *evp, guint evcontext) |
1128 | 2813 { |
2814 event_muc_invitation *invitation = evp->data; | |
2815 | |
2816 // Sanity check | |
2817 if (!invitation) { | |
2818 // Shouldn't happen. | |
2819 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); | |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2820 return 0; |
1128 | 2821 } |
2822 | |
2823 if (evcontext == EVS_CONTEXT_TIMEOUT) { | |
2824 scr_LogPrint(LPRINT_LOGNORM, "Event %s timed out, cancelled.", evp->id); | |
2825 goto evscallback_invitation_free; | |
2826 } | |
2827 if (evcontext == EVS_CONTEXT_CANCEL) { | |
2828 scr_LogPrint(LPRINT_LOGNORM, "Event %s cancelled.", evp->id); | |
2829 goto evscallback_invitation_free; | |
2830 } | |
2831 if (!(evcontext & EVS_CONTEXT_USER)) | |
2832 goto evscallback_invitation_free; | |
2833 // Ok, let's work now. | |
2834 // evcontext: 0, 1 == reject, accept | |
2835 | |
2836 if (evcontext & ~EVS_CONTEXT_USER) { | |
1395
d431cd75eb53
Use bookmarked nickname when manually joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
1385
diff
changeset
|
2837 char *nickname = default_muc_nickname(invitation->to); |
1128 | 2838 jb_room_join(invitation->to, nickname, invitation->passwd); |
2839 g_free(nickname); | |
2840 } else { | |
2841 scr_LogPrint(LPRINT_LOGNORM, "Invitation to %s refused.", invitation->to); | |
2842 decline_invitation(invitation, NULL); | |
2843 } | |
2844 | |
2845 evscallback_invitation_free: | |
2846 g_free(invitation->to); | |
2847 g_free(invitation->from); | |
2848 g_free(invitation->passwd); | |
2849 g_free(invitation->reason); | |
2850 g_free(invitation); | |
2851 evp->data = NULL; | |
1213
4a7db2870685
Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents:
1212
diff
changeset
|
2852 return 0; |
1128 | 2853 } |
2854 | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2855 static void handle_packet_s10n(jconn conn, char *type, char *from, |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2856 xmlnode xmldata) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2857 { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2858 char *r; |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2859 char *buf; |
818
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
2860 int newbuddy; |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2861 |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2862 r = jidtodisp(from); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2863 |
818
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
2864 newbuddy = !roster_find(r, jidsearch, 0); |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
2865 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2866 if (!strcmp(type, "subscribe")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2867 /* The sender wishes to subscribe to our presence */ |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2868 char *msg; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2869 int isagent; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2870 eviqs *evn; |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2871 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2872 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2873 msg = xmlnode_get_tag_data(xmldata, "status"); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2874 |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2875 buf = g_strdup_printf("<%s> wants to subscribe to your presence updates", |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2876 from); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2877 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2878 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2879 g_free(buf); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2880 |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2881 if (msg) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2882 buf = g_strdup_printf("<%s> said: %s", from, msg); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2883 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2884 replace_nl_with_dots(buf); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2885 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2886 g_free(buf); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2887 } |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2888 |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2889 // Create a new event item |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
2890 evn = evs_new(EVS_TYPE_SUBSCRIPTION, EVS_MAX_TIMEOUT); |
751
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
2891 if (evn) { |
752 | 2892 evn->callback = &evscallback_subscription; |
751
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
2893 evn->data = g_strdup(r); |
754
5b962b978573
Add event description when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
752
diff
changeset
|
2894 evn->desc = g_strdup_printf("<%s> wants to subscribe to your " |
5b962b978573
Add event description when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
752
diff
changeset
|
2895 "presence updates", r); |
751
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
2896 buf = g_strdup_printf("Please use /event %s accept|reject", evn->id); |
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
2897 } else { |
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
2898 buf = g_strdup_printf("Unable to create a new event!"); |
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
2899 } |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2900 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2901 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2902 g_free(buf); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2903 } else if (!strcmp(type, "unsubscribe")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2904 /* The sender is unsubscribing from our presence */ |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
2905 jb_subscr_cancel_auth(from); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2906 buf = g_strdup_printf("<%s> is unsubscribing from your " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2907 "presence updates", from); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2908 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2909 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2910 g_free(buf); |
603 | 2911 } else if (!strcmp(type, "subscribed")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2912 /* The sender has allowed us to receive their presence */ |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2913 buf = g_strdup_printf("<%s> has allowed you to receive their " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2914 "presence updates", from); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2915 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2916 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2917 g_free(buf); |
603 | 2918 } else if (!strcmp(type, "unsubscribed")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2919 /* The subscription request has been denied or a previously-granted |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2920 subscription has been cancelled */ |
610
0e8247cf2bd1
Consider buddies as offline when they have cancelled our subscription
Mikael Berthe <mikael@lilotux.net>
parents:
609
diff
changeset
|
2921 roster_unsubscribed(from); |
859
cb2a3a1d985f
Make sure we update the roster when a subscription is cancelled
Mikael Berthe <mikael@lilotux.net>
parents:
845
diff
changeset
|
2922 update_roster = TRUE; |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2923 buf = g_strdup_printf("<%s> has cancelled your subscription to " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2924 "their presence updates", from); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1282
diff
changeset
|
2925 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO, 0); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2926 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2927 g_free(buf); |
603 | 2928 } else { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2929 scr_LogPrint(LPRINT_LOGNORM, "Received unrecognized packet from <%s>, " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2930 "type=%s", from, (type ? type : "")); |
818
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
2931 newbuddy = FALSE; |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
2932 } |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
2933 |
1010
54405d09b15a
Add a call to buddylist_build()
Mikael Berthe <mikael@lilotux.net>
parents:
1008
diff
changeset
|
2934 if (newbuddy) |
818
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
2935 update_roster = TRUE; |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
2936 g_free(r); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2937 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2938 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
2939 static void packethandler(jconn conn, jpacket packet) |
31 | 2940 { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2941 char *p; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2942 char *from=NULL, *type=NULL; |
31 | 2943 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
2944 jb_reset_keepalive(); // reset keepalive timeout |
31 | 2945 jpacket_reset(packet); |
2946 | |
671
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
2947 if (!packet->type) { |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
2948 scr_LogPrint(LPRINT_LOG, "Packet type = 0"); |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
2949 return; |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
2950 } |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
2951 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2952 p = xmlnode_get_attrib(packet->x, "type"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2953 if (p) type = p; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2954 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
2955 p = xmlnode_get_attrib(packet->x, "from"); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
2956 if (p) from = p; |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
2957 |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
2958 if (!from && packet->type != JPACKET_IQ) { |
987
f47e312560af
Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents:
986
diff
changeset
|
2959 scr_LogPrint(LPRINT_LOGNORM, "Error in stream packet"); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
2960 return; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
2961 } |
31 | 2962 |
2963 switch (packet->type) { | |
2964 case JPACKET_MESSAGE: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2965 handle_packet_message(conn, type, from, packet->x); |
31 | 2966 break; |
2967 | |
2968 case JPACKET_IQ: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2969 handle_packet_iq(conn, type, from, packet->x); |
31 | 2970 break; |
2971 | |
2972 case JPACKET_PRESENCE: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2973 handle_packet_presence(conn, type, from, packet->x); |
31 | 2974 break; |
2975 | |
2976 case JPACKET_S10N: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2977 handle_packet_s10n(conn, type, from, packet->x); |
31 | 2978 break; |
2979 | |
2980 default: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
2981 scr_LogPrint(LPRINT_LOG, "Unhandled packet type (%d)", packet->type); |
31 | 2982 } |
2983 } | |
2984 | |
580 | 2985 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |