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