Mercurial > hg
annotate mcabber/src/jabglue.c @ 986:ed697234bd39
Chat states receival (Alexis Hildebrandt)
Patch from Alexis Hildebrandt, slightly modified
(mostly coding style updates).
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 29 Oct 2006 11:43:00 +0100 |
parents | 5b01de4ac5e1 |
children | f47e312560af |
rev | line source |
---|---|
29 | 1 /* |
2 * jabglue.c -- Jabber protocol handling | |
393 | 3 * |
699 | 4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.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" |
29 | 35 |
36 #define JABBERPORT 5222 | |
37 #define JABBERSSLPORT 5223 | |
38 | |
39 jconn jc; | |
578 | 40 enum enum_jstate jstate; |
29 | 41 |
353
3fe43f6daa5a
Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
42 char imstatus2char[imstatus_size+1] = { |
3fe43f6daa5a
Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents:
325
diff
changeset
|
43 '_', 'o', 'i', 'f', 'd', 'n', 'a', '\0' |
46 | 44 }; |
45 | |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
46 static time_t LastPingTime; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
47 static unsigned int KeepaliveDelay; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
48 static enum imstatus mystatus = offline; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
49 static gchar *mystatusmsg; |
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
50 static unsigned char online; |
29 | 51 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
52 static void statehandler(jconn, int); |
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
53 static void packethandler(jconn, jpacket); |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
54 void handle_state_events(char* from, xmlnode xmldata); |
31 | 55 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
56 static void logger(jconn j, int io, const char *buf) |
31 | 57 { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
58 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf); |
31 | 59 } |
60 | |
192 | 61 // jidtodisp(jid) |
62 // Strips the resource part from the jid | |
63 // The caller should g_free the result after use. | |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
64 char *jidtodisp(const char *jid) |
29 | 65 { |
66 char *ptr; | |
165 | 67 char *alias; |
68 | |
438
b44be19d6229
Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents:
436
diff
changeset
|
69 alias = g_strdup(jid); |
165 | 70 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
71 if ((ptr = strchr(alias, JID_RESOURCE_SEPARATOR)) != NULL) { |
29 | 72 *ptr = 0; |
73 } | |
74 return alias; | |
75 } | |
76 | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
77 char *compose_jid(const char *username, const char *servername, |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
78 const char *resource) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
79 { |
393 | 80 char *jid = g_new(char, 3 + |
81 strlen(username) + strlen(servername) + strlen(resource)); | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
82 strcpy(jid, username); |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
83 if (!strchr(jid, JID_DOMAIN_SEPARATOR)) { |
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
84 strcat(jid, JID_DOMAIN_SEPARATORSTR); |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
85 strcat(jid, servername); |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
86 } |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
87 strcat(jid, JID_RESOURCE_SEPARATORSTR); |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
88 strcat(jid, resource); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
89 return jid; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
90 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
91 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
92 inline unsigned char jb_getonline(void) |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
93 { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
94 return online; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
95 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
96 |
403
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
97 jconn jb_connect(const char *jid, const char *server, unsigned int port, |
17aa60c6dc63
Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents:
393
diff
changeset
|
98 int ssl, const char *pass) |
29 | 99 { |
100 if (!port) { | |
101 if (ssl) | |
102 port = JABBERSSLPORT; | |
103 else | |
104 port = JABBERPORT; | |
105 } | |
106 | |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
107 jb_disconnect(); |
29 | 108 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
109 if (!jid) return jc; |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
110 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
111 jc = jab_new((char*)jid, (char*)pass, (char*)server, port, ssl); |
29 | 112 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
113 /* 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
|
114 jab_logger(jc, logger); |
29 | 115 jab_packet_handler(jc, &packethandler); |
116 jab_state_handler(jc, &statehandler); | |
117 | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
118 if (jc && jc->user) { |
112 | 119 online = TRUE; |
29 | 120 jstate = STATE_CONNECTING; |
121 statehandler(0, -1); | |
122 jab_start(jc); | |
123 } | |
124 | |
125 return jc; | |
126 } | |
127 | |
128 void jb_disconnect(void) | |
129 { | |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
130 if (!jc) return; |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
131 |
668
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
132 if (online) { |
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
133 // Announce it to everyone else |
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
134 jb_setstatus(offline, NULL, ""); |
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
135 // End the XML flow |
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
136 jb_send_raw("</stream:stream>"); |
d0928694c81b
Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents:
655
diff
changeset
|
137 } |
634
f3c05d5fe459
Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
633
diff
changeset
|
138 |
f3c05d5fe459
Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents:
633
diff
changeset
|
139 // Announce it to the user |
29 | 140 statehandler(jc, JCONN_STATE_OFF); |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
411
diff
changeset
|
141 |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
142 jab_delete(jc); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
294
diff
changeset
|
143 jc = NULL; |
29 | 144 } |
145 | |
112 | 146 inline void jb_reset_keepalive() |
147 { | |
148 time(&LastPingTime); | |
149 } | |
150 | |
436 | 151 void jb_send_raw(const char *str) |
152 { | |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
449
diff
changeset
|
153 if (jc && online && str) |
436 | 154 jab_send_raw(jc, str); |
155 } | |
156 | |
29 | 157 void jb_keepalive() |
158 { | |
113 | 159 if (jc && online) |
112 | 160 jab_send_raw(jc, " \t "); |
161 jb_reset_keepalive(); | |
162 } | |
163 | |
164 void jb_set_keepalive_delay(unsigned int delay) | |
165 { | |
166 KeepaliveDelay = delay; | |
29 | 167 } |
168 | |
169 void jb_main() | |
170 { | |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
171 time_t now; |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
172 fd_set fds; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
173 long autoaway_timeout; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
174 struct timeval tv; |
756
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
175 static time_t last_eviqs_check = 0; |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
176 |
406 | 177 if (!online) { |
419 | 178 safe_usleep(10000); |
406 | 179 return; |
180 } | |
164 | 181 |
29 | 182 if (jc && jc->state == JCONN_STATE_CONNECTING) { |
419 | 183 safe_usleep(75000); |
29 | 184 jab_start(jc); |
185 return; | |
186 } | |
187 | |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
188 FD_ZERO(&fds); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
189 FD_SET(0, &fds); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
190 FD_SET(jc->fd, &fds); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
191 |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
192 tv.tv_sec = 60; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
193 tv.tv_usec = 0; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
194 |
940 | 195 time(&now); |
196 | |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
197 if (KeepaliveDelay) { |
940 | 198 if (now >= LastPingTime + (time_t)KeepaliveDelay) { |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
199 tv.tv_sec = 0; |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
200 } else { |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
201 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
|
202 } |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
203 } |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
204 |
940 | 205 autoaway_timeout = scr_GetAutoAwayTimeout(now); |
206 if (tv.tv_sec > autoaway_timeout) { | |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
207 tv.tv_sec = autoaway_timeout; |
940 | 208 } |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
209 |
940 | 210 if (!tv.tv_sec) |
211 tv.tv_usec = 350000; | |
212 | |
213 scr_DoUpdate(); | |
939
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
214 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
|
215 if (FD_ISSET(jc->fd, &fds)) |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
216 jab_poll(jc, 0); |
12fa2ae6445d
Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
217 } |
29 | 218 |
219 if (jstate == STATE_CONNECTING) { | |
220 if (jc) { | |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
221 eviqs *iqn; |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
222 xmlnode z; |
29 | 223 |
686
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
224 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
|
225 iqn->callback = &iqscallback_auth; |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
226 |
98de2d166a11
Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents:
684
diff
changeset
|
227 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
|
228 "username"); |
29 | 229 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
|
230 jab_send(jc, iqn->xmldata); |
29 | 231 |
232 jstate = STATE_GETAUTH; | |
233 } | |
234 | |
235 if (!jc || jc->state == JCONN_STATE_OFF) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
236 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server"); |
112 | 237 online = FALSE; |
29 | 238 } |
239 } | |
240 | |
241 if (!jc) { | |
242 statehandler(jc, JCONN_STATE_OFF); | |
243 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) { | |
244 statehandler(jc, JCONN_STATE_OFF); | |
245 } | |
112 | 246 |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
247 time(&now); |
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
248 |
756
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
249 // Check for EV & IQ requests timeouts |
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
250 if (now > last_eviqs_check + 20) { |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
251 iqs_check_timeout(now); |
756
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
252 evs_check_timeout(now); |
12dc6bdff8c1
Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents:
754
diff
changeset
|
253 last_eviqs_check = now; |
706
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
254 } |
934fddc99592
Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
255 |
112 | 256 // Keepalive |
257 if (KeepaliveDelay) { | |
735 | 258 if (now > LastPingTime + (time_t)KeepaliveDelay) |
112 | 259 jb_keepalive(); |
260 } | |
29 | 261 } |
262 | |
116 | 263 inline enum imstatus jb_getstatus() |
264 { | |
265 return mystatus; | |
266 } | |
267 | |
519
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
268 inline const char *jb_getstatusmsg() |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
269 { |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
270 return mystatusmsg; |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
271 } |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
272 |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
273 static void roompresence(gpointer room, void *presencedata) |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
274 { |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
275 const char *jid; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
276 const char *nickname; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
277 char *to; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
278 struct T_presence *pres = presencedata; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
279 |
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
651
diff
changeset
|
280 if (!buddy_getinsideroom(room)) |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
281 return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
282 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
283 jid = buddy_getjid(room); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
284 if (!jid) return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
285 nickname = buddy_getnickname(room); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
286 if (!nickname) return; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
287 |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
288 to = g_strdup_printf("%s/%s", jid, nickname); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
289 jb_setstatus(pres->st, to, pres->msg); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
290 g_free(to); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
291 } |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
292 |
534 | 293 // presnew(status, recipient, message) |
294 // Create an xmlnode with default presence attributes | |
295 // Note: the caller must free the node after use | |
296 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
|
297 const char *msg) |
29 | 298 { |
534 | 299 unsigned int prio; |
116 | 300 xmlnode x; |
301 | |
302 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0); | |
29 | 303 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
304 if (recipient) { |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
305 xmlnode_put_attrib(x, "to", recipient); |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
306 } |
444 | 307 |
29 | 308 switch(st) { |
309 case away: | |
310 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away", | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
311 (unsigned) -1); |
29 | 312 break; |
313 | |
314 case dontdisturb: | |
315 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd", | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
316 (unsigned) -1); |
29 | 317 break; |
318 | |
319 case freeforchat: | |
320 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat", | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
321 (unsigned) -1); |
29 | 322 break; |
323 | |
324 case notavail: | |
325 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa", | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
326 (unsigned) -1); |
29 | 327 break; |
328 | |
329 case invisible: | |
330 xmlnode_put_attrib(x, "type", "invisible"); | |
331 break; | |
51 | 332 |
118 | 333 case offline: |
334 xmlnode_put_attrib(x, "type", "unavailable"); | |
335 break; | |
336 | |
51 | 337 default: |
338 break; | |
29 | 339 } |
340 | |
531
aee9a279a0f3
Allow changing priority on the fly
Mikael Berthe <mikael@lilotux.net>
parents:
527
diff
changeset
|
341 prio = settings_opt_get_int("priority"); |
272 | 342 if (prio) { |
343 char strprio[8]; | |
842 | 344 snprintf(strprio, 8, "%d", (int)prio); |
29 | 345 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"), |
534 | 346 strprio, (unsigned) -1); |
347 } | |
348 | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
349 if (msg) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
350 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg, (unsigned) -1); |
29 | 351 |
534 | 352 return x; |
353 } | |
354 | |
355 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg) | |
356 { | |
357 xmlnode x; | |
358 | |
359 if (!online) return; | |
360 | |
521 | 361 if (msg) { |
362 // The status message has been specified. We'll use it, unless it is | |
363 // "-" which is a special case (option meaning "no status message"). | |
364 if (!strcmp(msg, "-")) | |
365 msg = ""; | |
366 } else { | |
367 // No status message specified; we'll use: | |
368 // a) the default status message (if provided by the user); | |
369 // b) the current status message; | |
370 // c) no status message (i.e. an empty one). | |
371 msg = settings_get_status_msg(st); | |
372 if (!msg) { | |
373 if (mystatusmsg) | |
374 msg = mystatusmsg; | |
375 else | |
376 msg = ""; | |
377 } | |
378 } | |
29 | 379 |
677
633a0522bd37
Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents:
671
diff
changeset
|
380 x = presnew(st, recipient, (st != invisible ? msg : NULL)); |
29 | 381 jab_send(jc, x); |
382 xmlnode_free(x); | |
383 | |
444 | 384 // If we didn't change our _global_ status, we are done |
385 if (recipient) return; | |
386 | |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
387 // Send presence to chatrooms |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
388 if (st != invisible) { |
861 | 389 struct T_presence room_presence; |
532
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
390 room_presence.st = st; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
391 room_presence.msg = msg; |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
392 foreach_buddy(ROSTER_TYPE_ROOM, &roompresence, &room_presence); |
2ac8d8e49e81
Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents:
531
diff
changeset
|
393 } |
29 | 394 |
164 | 395 // We'll need to update the roster if we switch to/from offline because |
396 // we don't know the presences of buddies when offline... | |
397 if (mystatus == offline || st == offline) | |
398 update_roster = TRUE; | |
399 | |
677
633a0522bd37
Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents:
671
diff
changeset
|
400 hk_mystatuschange(0, mystatus, st, (st != invisible ? msg : "")); |
116 | 401 mystatus = st; |
521 | 402 if (msg != mystatusmsg) { |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
403 g_free(mystatusmsg); |
521 | 404 if (*msg) |
405 mystatusmsg = g_strdup(msg); | |
406 else | |
407 mystatusmsg = NULL; | |
408 } | |
713 | 409 |
410 // Update status line | |
724
264375fe7159
Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents:
721
diff
changeset
|
411 scr_UpdateMainStatus(TRUE); |
29 | 412 } |
413 | |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
414 void jb_send_msg(const char *jid, const char *text, int type, |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
415 const char *subject) |
35 | 416 { |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
417 xmlnode x; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
418 gchar *strtype; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
419 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
420 if (!online) return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
421 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
422 if (type == ROSTER_TYPE_ROOM) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
423 strtype = TMSG_GROUPCHAT; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
424 else |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
425 strtype = TMSG_CHAT; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
426 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
427 x = jutil_msgnew(strtype, (char*)jid, NULL, (char*)text); |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
428 if (subject) { |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
429 xmlnode y; |
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
430 y = xmlnode_insert_tag(x, "subject"); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
431 xmlnode_insert_cdata(y, subject, (unsigned) -1); |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
474
diff
changeset
|
432 } |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
433 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
434 // TODO: insert event notifications request |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
435 #undef USE_JEP_85 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
436 #ifdef USE_JEP_85 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
437 #define NS_CHAT_STATES "http://jabber.org/features/chatstates" |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
438 // JEP-85 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
439 xmlnode event = xmlnode_insert_tag(x, "composing"); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
440 xmlnode_put_attrib(event, "xmlns", NS_CHAT_STATES); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
441 #else |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
442 // JEP-22 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
443 xmlnode event = xmlnode_insert_tag(x, "x"); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
444 xmlnode_put_attrib(event, "xmlns", NS_EVENT); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
445 xmlnode_insert_tag(event, "composing"); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
446 #endif |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
447 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
448 |
35 | 449 jab_send(jc, x); |
450 xmlnode_free(x); | |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
451 |
114 | 452 jb_reset_keepalive(); |
35 | 453 } |
454 | |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
455 // jb_subscr_send_auth(jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
456 // Allow jid to receive our presence updates |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
457 void jb_subscr_send_auth(const char *jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
458 { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
459 xmlnode x; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
460 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
461 x = jutil_presnew(JPACKET__SUBSCRIBED, (char *)jid, NULL); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
462 jab_send(jc, x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
463 xmlnode_free(x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
464 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
465 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
466 // jb_subscr_cancel_auth(jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
467 // Cancel jid's subscription to our presence updates |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
468 void jb_subscr_cancel_auth(const char *jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
469 { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
470 xmlnode x; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
471 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
472 x = jutil_presnew(JPACKET__UNSUBSCRIBED, (char *)jid, NULL); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
473 jab_send(jc, x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
474 xmlnode_free(x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
475 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
476 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
477 // jb_subscr_request_auth(jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
478 // Request a subscription to jid's presence updates |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
479 void jb_subscr_request_auth(const char *jid) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
480 { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
481 xmlnode x; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
482 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
483 x = jutil_presnew(JPACKET__SUBSCRIBE, (char *)jid, NULL); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
484 jab_send(jc, x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
485 xmlnode_free(x); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
486 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
487 |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
488 // jb_subscr_request_cancel(jid) |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
489 // Request to cancel jour subscription to jid's presence updates |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
490 void jb_subscr_request_cancel(const char *jid) |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
491 { |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
492 xmlnode x; |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
493 |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
494 x = jutil_presnew(JPACKET__UNSUBSCRIBE, (char *)jid, NULL); |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
495 jab_send(jc, x); |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
496 xmlnode_free(x); |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
497 } |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
498 |
213 | 499 // Note: the caller should check the jid is correct |
244 | 500 void jb_addbuddy(const char *jid, const char *name, const char *group) |
124 | 501 { |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
502 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
503 eviqs *iqn; |
192 | 504 char *cleanjid; |
124 | 505 |
208 | 506 if (!online) return; |
124 | 507 |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
508 cleanjid = jidtodisp(jid); |
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
509 |
124 | 510 // We don't check if the jabber user already exists in the roster, |
511 // because it allows to re-ask for notification. | |
512 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
513 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
|
514 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
|
515 |
454399f026fa
Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
516 xmlnode_put_attrib(y, "jid", cleanjid); |
124 | 517 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
518 if (name) |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
519 xmlnode_put_attrib(y, "name", name); |
244 | 520 |
124 | 521 if (group) { |
628
454399f026fa
Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
522 z = xmlnode_insert_tag(y, "group"); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
523 xmlnode_insert_cdata(z, group, (unsigned) -1); |
124 | 524 } |
525 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
526 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
527 iqs_del(iqn->id); // XXX |
124 | 528 |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
529 jb_subscr_request_auth(cleanjid); |
612
789ec6aed764
Respect RFC 3921 order advice
Mikael Berthe <mikael@lilotux.net>
parents:
611
diff
changeset
|
530 |
603 | 531 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending); |
192 | 532 g_free(cleanjid); |
124 | 533 buddylist_build(); |
534 | |
244 | 535 update_roster = TRUE; |
124 | 536 } |
537 | |
205 | 538 void jb_delbuddy(const char *jid) |
539 { | |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
540 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
541 eviqs *iqn; |
205 | 542 char *cleanjid; |
543 | |
544 if (!online) return; | |
545 | |
546 cleanjid = jidtodisp(jid); | |
547 | |
548 // If the current buddy is an agent, unsubscribe from it | |
549 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
550 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid); |
205 | 551 |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
552 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
|
553 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
|
554 y = xmlnode_get_tag(iqn->xmldata, "query"); |
205 | 555 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
|
556 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
557 iqs_del(iqn->id); // XXX |
205 | 558 } |
559 | |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
560 // Cancel the subscriptions |
834
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
561 jb_subscr_cancel_auth(cleanjid); // Cancel "from" |
6f913f4fbb2a
Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents:
823
diff
changeset
|
562 jb_subscr_request_cancel(cleanjid); // Cancel "to" |
205 | 563 |
564 // 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
|
565 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
|
566 y = xmlnode_get_tag(iqn->xmldata, "query"); |
205 | 567 z = xmlnode_insert_tag(y, "item"); |
568 xmlnode_put_attrib(z, "jid", cleanjid); | |
569 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
|
570 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
571 iqs_del(iqn->id); // XXX |
205 | 572 |
573 roster_del_user(cleanjid); | |
574 g_free(cleanjid); | |
575 buddylist_build(); | |
576 | |
577 update_roster = TRUE; | |
578 } | |
579 | |
208 | 580 void jb_updatebuddy(const char *jid, const char *name, const char *group) |
581 { | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
582 xmlnode y; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
583 eviqs *iqn; |
208 | 584 char *cleanjid; |
585 | |
586 if (!online) return; | |
587 | |
588 // XXX We should check name's and group's correctness | |
589 | |
590 cleanjid = jidtodisp(jid); | |
591 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
592 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
|
593 y = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item"); |
208 | 594 xmlnode_put_attrib(y, "jid", cleanjid); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
595 xmlnode_put_attrib(y, "name", name); |
208 | 596 |
597 if (group) { | |
598 y = xmlnode_insert_tag(y, "group"); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
599 xmlnode_insert_cdata(y, group, (unsigned) -1); |
208 | 600 } |
601 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
602 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
603 iqs_del(iqn->id); // XXX |
208 | 604 g_free(cleanjid); |
605 } | |
606 | |
693 | 607 void jb_request(const char *jid, enum iqreq_type reqtype) |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
608 { |
693 | 609 GSList *resources; |
610 GSList *roster_elt; | |
793 | 611 void (*request_fn)(const char *); |
612 const char *strreqtype; | |
693 | 613 |
793 | 614 if (reqtype == iqreq_version) { |
615 request_fn = &request_version; | |
616 strreqtype = "version"; | |
617 } else if (reqtype == iqreq_time) { | |
618 request_fn = &request_time; | |
619 strreqtype = "time"; | |
620 } else | |
621 return; | |
693 | 622 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
623 if (strchr(jid, JID_RESOURCE_SEPARATOR)) { |
693 | 624 // This is a full JID |
793 | 625 (*request_fn)(jid); |
626 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, jid); | |
693 | 627 return; |
628 } | |
629 | |
630 // The resource has not been specified | |
631 roster_elt = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_ROOM); | |
632 if (!roster_elt) { | |
695
c299035ccb9f
Fix up jb_request(), when the resource is unknown
Mikael Berthe <mikael@lilotux.net>
parents:
693
diff
changeset
|
633 scr_LogPrint(LPRINT_NORMAL, "No known resource for <%s>...", jid); |
793 | 634 (*request_fn)(jid); // Let's send a request anyway... |
635 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, jid); | |
693 | 636 return; |
637 } | |
638 | |
639 // Send a request to each resource | |
640 resources = buddy_getresources(roster_elt->data); | |
793 | 641 if (!resources) { |
642 scr_LogPrint(LPRINT_NORMAL, "No known resource for <%s>...", jid); | |
643 (*request_fn)(jid); // Let's send a request anyway... | |
644 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, jid); | |
645 } | |
693 | 646 for ( ; resources ; resources = g_slist_next(resources) ) { |
647 gchar *fulljid; | |
648 fulljid = g_strdup_printf("%s/%s", jid, (char*)resources->data); | |
793 | 649 (*request_fn)(fulljid); |
650 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fulljid); | |
693 | 651 g_free(fulljid); |
652 } | |
691
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
653 } |
3c0a0a993de8
Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents:
686
diff
changeset
|
654 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
655 // Join a MUC room |
900
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
656 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
|
657 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
658 xmlnode x, y; |
643
dd73c3dad815
Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
642
diff
changeset
|
659 gchar *roomid; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
660 GSList *room_elt; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
661 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
662 if (!online || !room) return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
663 if (!nickname) return; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
664 |
643
dd73c3dad815
Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
642
diff
changeset
|
665 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
|
666 if (check_jid_syntax(roomid)) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
667 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
|
668 nickname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
669 g_free(roomid); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
670 return; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
671 } |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
672 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
673 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
|
674 // 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
|
675 if (!room_elt) { |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
676 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
|
677 } else { |
3ad6675caaf1
MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents:
645
diff
changeset
|
678 // 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
|
679 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
|
680 } |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
681 // 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
|
682 if (!buddy_getinsideroom(room_elt->data)) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
683 // 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
|
684 buddy_setnickname(room_elt->data, nickname); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
685 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
686 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
687 // Send the XML request |
535
b407d19c39ab
Set status correctly when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
534
diff
changeset
|
688 x = presnew(mystatus, roomid, mystatusmsg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
689 y = xmlnode_insert_tag(x, "x"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
690 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
|
691 if (passwd) { |
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
692 xmlnode_insert_cdata(xmlnode_insert_tag(y, "password"), passwd, |
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
693 (unsigned) -1); |
b41684465283
MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents:
896
diff
changeset
|
694 } |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
695 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
696 jab_send(jc, x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
697 xmlnode_free(x); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
698 jb_reset_keepalive(); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
699 g_free(roomid); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
700 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
701 |
449 | 702 // Unlock a MUC room |
703 // room syntax: "room@server" | |
704 void jb_room_unlock(const char *room) | |
705 { | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
706 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
707 eviqs *iqn; |
449 | 708 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
709 if (!online || !room) return; |
449 | 710 |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
711 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
|
712 "unlock", IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
713 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
|
714 y = xmlnode_get_tag(iqn->xmldata, "query"); |
449 | 715 z = xmlnode_insert_tag(y, "x"); |
716 xmlnode_put_attrib(z, "xmlns", "jabber:x:data"); | |
717 xmlnode_put_attrib(z, "type", "submit"); | |
718 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
719 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
720 iqs_del(iqn->id); // XXX |
449 | 721 jb_reset_keepalive(); |
722 } | |
723 | |
599 | 724 // Destroy a MUC room |
725 // room syntax: "room@server" | |
726 void jb_room_destroy(const char *room, const char *venue, const char *reason) | |
727 { | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
728 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
729 eviqs *iqn; |
599 | 730 |
731 if (!online || !room) return; | |
732 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
733 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
|
734 "destroy", IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
735 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
|
736 y = xmlnode_get_tag(iqn->xmldata, "query"); |
599 | 737 z = xmlnode_insert_tag(y, "destroy"); |
738 | |
739 if (venue && *venue) | |
740 xmlnode_put_attrib(z, "jid", venue); | |
741 | |
742 if (reason) { | |
743 y = xmlnode_insert_tag(z, "reason"); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
744 xmlnode_insert_cdata(y, reason, (unsigned) -1); |
599 | 745 } |
746 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
747 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
748 iqs_del(iqn->id); // XXX |
599 | 749 jb_reset_keepalive(); |
750 } | |
751 | |
584 | 752 // Change role or affiliation of a MUC user |
568 | 753 // room syntax: "room@server" |
754 // Either the jid or the nickname must be set (when banning, only the jid is | |
755 // allowed) | |
584 | 756 // ra: new role or affiliation |
757 // (ex. role none for kick, affil outcast for ban...) | |
568 | 758 // The reason can be null |
759 // Return 0 if everything is ok | |
584 | 760 int jb_room_setattrib(const char *roomid, const char *jid, const char *nick, |
761 struct role_affil ra, const char *reason) | |
568 | 762 { |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
763 xmlnode y, z; |
745
413e95f3051a
Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents:
735
diff
changeset
|
764 eviqs *iqn; |
568 | 765 |
766 if (!online || !roomid) return 1; | |
584 | 767 if (!jid && !nick) return 1; |
568 | 768 |
769 if (check_jid_syntax((char*)roomid)) { | |
770 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid); | |
771 return 1; | |
772 } | |
773 if (jid && check_jid_syntax((char*)jid)) { | |
774 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid); | |
775 return 1; | |
776 } | |
777 | |
584 | 778 if (ra.type == type_affil && ra.val.affil == affil_outcast && !jid) |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
569
diff
changeset
|
779 return 1; // Shouldn't happen (jid mandatory when banning) |
568 | 780 |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
781 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
|
782 "roleaffil", IQS_DEFAULT_TIMEOUT); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
783 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
|
784 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
|
785 y = xmlnode_get_tag(iqn->xmldata, "query"); |
568 | 786 z = xmlnode_insert_tag(y, "item"); |
787 | |
584 | 788 if (jid) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
789 xmlnode_put_attrib(z, "jid", jid); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
790 } else { // nickname |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
791 xmlnode_put_attrib(z, "nick", nick); |
568 | 792 } |
584 | 793 |
794 if (ra.type == type_affil) | |
795 xmlnode_put_attrib(z, "affiliation", straffil[ra.val.affil]); | |
796 else if (ra.type == type_role) | |
797 xmlnode_put_attrib(z, "role", strrole[ra.val.role]); | |
568 | 798 |
799 if (reason) { | |
800 y = xmlnode_insert_tag(z, "reason"); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
801 xmlnode_insert_cdata(y, reason, (unsigned) -1); |
568 | 802 } |
803 | |
684
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
804 jab_send(jc, iqn->xmldata); |
3282276e7413
Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents:
678
diff
changeset
|
805 iqs_del(iqn->id); // XXX |
568 | 806 jb_reset_keepalive(); |
807 | |
808 return 0; | |
809 } | |
486 | 810 |
811 // Invite a user to a MUC room | |
812 // room syntax: "room@server" | |
813 // reason can be null. | |
814 void jb_room_invite(const char *room, const char *jid, const char *reason) | |
815 { | |
816 xmlnode x, y, z; | |
817 | |
818 if (!online || !room || !jid) return; | |
819 | |
820 x = jutil_msgnew(NULL, (char*)room, NULL, NULL); | |
821 | |
822 y = xmlnode_insert_tag(x, "x"); | |
823 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user"); | |
824 | |
825 z = xmlnode_insert_tag(y, "invite"); | |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
826 xmlnode_put_attrib(z, "to", jid); |
486 | 827 |
569
69afee8e1232
"/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents:
568
diff
changeset
|
828 if (reason) { |
69afee8e1232
"/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents:
568
diff
changeset
|
829 y = xmlnode_insert_tag(z, "reason"); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
830 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
|
831 } |
486 | 832 |
833 jab_send(jc, x); | |
834 xmlnode_free(x); | |
835 jb_reset_keepalive(); | |
836 } | |
837 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
838 static void gotmessage(char *type, const char *from, const char *body, |
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
839 const char *enc, time_t timestamp) |
29 | 840 { |
113 | 841 char *jid; |
956
819396bebdf5
Do not block system messages when block_unsubscribed is set
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
842 const char *rname, *s; |
29 | 843 |
441
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
844 jid = jidtodisp(from); |
51b8f10cfeb8
Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
845 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
846 rname = strchr(from, JID_RESOURCE_SEPARATOR); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
444
diff
changeset
|
847 if (rname) rname++; |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
848 |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
849 // Check for unexpected groupchat messages |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
850 // 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
|
851 // 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
|
852 // a type unavailable. |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
853 if (type && !strcmp(type, "groupchat") && !roster_getnickname(jid)) { |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
854 // It shouldn't happen, probably a server issue |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
855 GSList *room_elt; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
856 char *mbuf; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
857 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
858 mbuf = g_strdup_printf("Unexpected groupchat packet!"); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
859 scr_LogPrint(LPRINT_LOGNORM, "%s", mbuf); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
860 scr_WriteIncomingMessage(jid, mbuf, 0, HBB_PREFIX_INFO); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
861 g_free(mbuf); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
862 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
863 // Send back an unavailable packet |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
864 jb_setstatus(offline, jid, ""); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
865 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
866 // MUC |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
867 // Make sure this is a room (it can be a conversion user->room) |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
868 room_elt = roster_find(jid, jidsearch, 0); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
869 if (!room_elt) { |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
870 room_elt = roster_add_user(jid, NULL, NULL, ROSTER_TYPE_ROOM, sub_none); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
871 } else { |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
872 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
873 } |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
874 |
896 | 875 g_free(jid); |
876 | |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
877 buddylist_build(); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
878 scr_DrawRoster(); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
879 return; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
880 } |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
881 |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
882 // 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
|
883 // 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
|
884 // System messages (from our server) are allowed. |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
885 if (!settings_opt_get_int("block_unsubscribed") || |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
886 (roster_getsubscription(jid) & sub_from) || |
956
819396bebdf5
Do not block system messages when block_unsubscribed is set
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
887 (type && strcmp(type, "chat")) || |
819396bebdf5
Do not block system messages when block_unsubscribed is set
Mikael Berthe <mikael@lilotux.net>
parents:
940
diff
changeset
|
888 ((s = settings_opt_get("server")) != NULL && !strcasecmp(jid, s))) { |
819
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
889 hk_message_in(jid, rname, timestamp, body, type); |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
890 } else { |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
891 scr_LogPrint(LPRINT_LOGNORM, "Blocked a message from <%s>", jid); |
c2d7d9dd4193
New option 'block_unsubscribed'
Mikael Berthe <mikael@lilotux.net>
parents:
818
diff
changeset
|
892 } |
192 | 893 g_free(jid); |
29 | 894 } |
895 | |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
896 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
|
897 { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
898 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
|
899 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
900 switch(code) { |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
901 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
|
902 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
903 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
|
904 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
905 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
|
906 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
907 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
|
908 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
909 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
|
910 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
911 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
|
912 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
913 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
|
914 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
915 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
|
916 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
917 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
|
918 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
919 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
|
920 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
921 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
|
922 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
923 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
|
924 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
925 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
|
926 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
927 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
|
928 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
929 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
|
930 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
931 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
|
932 break; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
933 default: |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
934 desc = NULL; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
935 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
936 |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
937 return desc; |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
938 } |
04a0b450380b
Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents:
419
diff
changeset
|
939 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
940 // display_server_error(x) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
941 // 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
|
942 // x: error tag xmlnode pointer |
577
5c6d364130ee
Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents:
576
diff
changeset
|
943 void display_server_error(xmlnode x) |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
944 { |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
945 const char *desc = NULL; |
862
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
946 char *sdesc; |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
947 int code = 0; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
948 char *s; |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
949 const char *p; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
950 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
951 /* RFC3920: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
952 * The <error/> element: |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
953 * 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
|
954 * 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
|
955 * 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
|
956 */ |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
957 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
|
958 if (p) |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
959 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
|
960 |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
961 // For backward compatibility |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
962 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
|
963 code = atoi(s); |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
964 // Default message |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
965 desc = defaulterrormsg(code); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
966 } |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
967 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
968 // 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
|
969 s = xmlnode_get_data(x); |
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
970 if (s && *s) desc = s; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
971 |
430
d03663d2e7d9
Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents:
426
diff
changeset
|
972 // 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
|
973 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
|
974 if (s && *s) desc = s; |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
975 |
862
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
976 // Strip trailing newlines |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
977 sdesc = g_strdup(desc); |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
978 for (s = sdesc; *s; s++) ; |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
979 if (s > sdesc) |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
980 s--; |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
981 while (s >= sdesc && (*s == '\n' || *s == '\r')) |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
982 *s-- = '\0'; |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
983 |
5ed97fc7afa0
Strip trailing empty lines from error messages
Mikael Berthe <mikael@lilotux.net>
parents:
861
diff
changeset
|
984 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
|
985 g_free(sdesc); |
426
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
986 } |
2706ef3e25a7
Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents:
421
diff
changeset
|
987 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
988 static void statehandler(jconn conn, int state) |
31 | 989 { |
990 static int previous_state = -1; | |
991 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
992 scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state); |
31 | 993 |
994 switch(state) { | |
995 case JCONN_STATE_OFF: | |
192 | 996 if (previous_state != JCONN_STATE_OFF) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
997 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server"); |
37 | 998 |
112 | 999 online = FALSE; |
159 | 1000 mystatus = offline; |
519
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
1001 if (mystatusmsg) { |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
1002 g_free(mystatusmsg); |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
1003 mystatusmsg = NULL; |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
513
diff
changeset
|
1004 } |
164 | 1005 roster_free(); |
1006 update_roster = TRUE; | |
865
cee8d6be04e1
Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents:
864
diff
changeset
|
1007 scr_UpdateBuddyWindow(); |
31 | 1008 break; |
1009 | |
1010 case JCONN_STATE_CONNECTED: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1011 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server"); |
31 | 1012 break; |
1013 | |
1014 case JCONN_STATE_AUTH: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1015 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server"); |
31 | 1016 break; |
1017 | |
1018 case JCONN_STATE_ON: | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1019 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
1020 "established"); |
112 | 1021 online = TRUE; |
31 | 1022 break; |
1023 | |
35 | 1024 case JCONN_STATE_CONNECTING: |
357
e8adc3c96e68
Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents:
353
diff
changeset
|
1025 if (previous_state != state) |
408
73433860665c
Tune previous usleep() change
Mikael Berthe <mikael@lilotux.net>
parents:
407
diff
changeset
|
1026 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server"); |
35 | 1027 break; |
1028 | |
31 | 1029 default: |
1030 break; | |
1031 } | |
1032 previous_state = state; | |
1033 } | |
1034 | |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1035 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
|
1036 { |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1037 xmlnode x; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1038 char *p; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1039 |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1040 x = xmlnode_get_firstchild(xmldata); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1041 for ( ; x; x = xmlnode_get_nextsibling(x)) { |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1042 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x")) |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1043 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcmp(p, xmlns)) { |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1044 break; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1045 } |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1046 } |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1047 return x; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1048 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1049 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1050 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
|
1051 { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1052 xmlnode x; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1053 char *p; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1054 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1055 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
|
1056 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
|
1057 return from_iso8601(p, 1); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1058 return 0; |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1059 } |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1060 |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1061 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
|
1062 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
|
1063 enum imstatus ust, char *ustmsg, |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1064 time_t usttime, char bpprio) |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1065 { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1066 xmlnode y; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1067 char *p; |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1068 char *mbuf; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1069 const char *ournick; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1070 enum imrole mbrole = role_none; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1071 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
|
1072 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
|
1073 const char *actorjid = NULL, *reason = NULL; |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1074 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
|
1075 unsigned int statuscode = 0; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1076 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
|
1077 int log_muc_conf; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1078 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1079 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
|
1080 |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1081 room_elt = roster_find(roomjid, jidsearch, 0); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1082 if (!room_elt) { |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1083 // Add room if it doesn't already exist |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1084 // 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
|
1085 // network issue?) |
603 | 1086 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
|
1087 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
|
1088 } else { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1089 // 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
|
1090 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1091 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1092 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1093 // Get room member's information |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1094 y = xmlnode_get_tag(xmldata, "item"); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1095 if (y) { |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1096 xmlnode z; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1097 p = xmlnode_get_attrib(y, "affiliation"); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1098 if (p) { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1099 if (!strcmp(p, "owner")) mbaffil = affil_owner; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1100 else if (!strcmp(p, "admin")) mbaffil = affil_admin; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1101 else if (!strcmp(p, "member")) mbaffil = affil_member; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1102 else if (!strcmp(p, "outcast")) mbaffil = affil_outcast; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1103 else if (!strcmp(p, "none")) mbaffil = affil_none; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1104 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
|
1105 from, p); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1106 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1107 p = xmlnode_get_attrib(y, "role"); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1108 if (p) { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1109 if (!strcmp(p, "moderator")) mbrole = role_moderator; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1110 else if (!strcmp(p, "participant")) mbrole = role_participant; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1111 else if (!strcmp(p, "visitor")) mbrole = role_visitor; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1112 else if (!strcmp(p, "none")) mbrole = role_none; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1113 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
|
1114 from, p); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1115 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1116 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
|
1117 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
|
1118 // 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
|
1119 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
|
1120 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
|
1121 if (z) |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1122 actorjid = xmlnode_get_attrib(z, "jid"); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1123 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1124 |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1125 // Get our room nickname |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1126 ournick = buddy_getnickname(room_elt->data); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1127 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1128 if (!ournick) { |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1129 // It shouldn't happen, probably a server issue |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1130 mbuf = g_strdup_printf("Unexpected groupchat packet!"); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1131 |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1132 scr_LogPrint(LPRINT_LOGNORM, "%s", mbuf); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1133 scr_WriteIncomingMessage(roomjid, mbuf, 0, HBB_PREFIX_INFO); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1134 g_free(mbuf); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1135 // Send back an unavailable packet |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1136 jb_setstatus(offline, roomjid, ""); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1137 buddylist_build(); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1138 scr_DrawRoster(); |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1139 return; |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1140 } |
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1141 |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1142 // 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
|
1143 // 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
|
1144 // 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
|
1145 // 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
|
1146 // 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
|
1147 // 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
|
1148 y = xmlnode_get_tag(xmldata, "status"); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1149 if (y) { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1150 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
|
1151 if (p) |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1152 statuscode = atoi(p); |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1153 } |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1154 |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1155 // 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
|
1156 if (statuscode == 303 && mbnick) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1157 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
|
1158 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
|
1159 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1160 if (log_muc_conf) hlog_write_message(roomjid, 0, FALSE, mbuf); |
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1161 g_free(mbuf); |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1162 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
|
1163 // Maybe it's _our_ nickname... |
864
a7b3409df6bc
MUC: Work around user server restart
Mikael Berthe <mikael@lilotux.net>
parents:
862
diff
changeset
|
1164 if (ournick && !strcmp(rname, ournick)) |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1165 buddy_setnickname(room_elt->data, mbnick); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1166 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1167 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1168 // Check for departure/arrival |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1169 if (!mbnick && mbrole == role_none) { |
586 | 1170 enum { leave=0, kick, ban } how = leave; |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1171 bool we_left = FALSE; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1172 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1173 if (statuscode == 307) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1174 how = kick; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1175 else if (statuscode == 301) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1176 how = ban; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1177 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1178 // 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
|
1179 if (ournick && !strcmp(rname, ournick)) { |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1180 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
|
1181 buddy_setinsideroom(room_elt->data, FALSE); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1182 buddy_setnickname(room_elt->data, NULL); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1183 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
|
1184 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
|
1185 scr_UpdateChatStatus(FALSE); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1186 update_roster = TRUE; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1187 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1188 |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1189 // The message depends on _who_ left, and _how_ |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1190 if (how) { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1191 gchar *mbuf_end; |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1192 // Forced leave |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1193 if (actorjid) { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1194 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
|
1195 (how == ban ? "banned" : "kicked"), |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1196 roomjid, actorjid, reason); |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1197 } else { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1198 mbuf_end = g_strdup_printf("%s from %s.", |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1199 (how == ban ? "banned" : "kicked"), |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1200 roomjid); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1201 } |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1202 if (we_left) |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1203 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
|
1204 else |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1205 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
|
1206 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1207 g_free(mbuf_end); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1208 } else { |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1209 // Natural leave |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1210 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
|
1211 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
|
1212 if (destroynode) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1213 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
|
1214 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
|
1215 "the room has been destroyed: %s", |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1216 roomjid, reason); |
616
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
1217 } else { |
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
1218 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
|
1219 "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
|
1220 } |
a61a257ec38b
MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents:
612
diff
changeset
|
1221 } else { |
599 | 1222 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
|
1223 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1224 } 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
|
1225 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
|
1226 // 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
|
1227 // 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
|
1228 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
|
1229 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
|
1230 } 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
|
1231 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
|
1232 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
|
1233 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
|
1234 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
|
1235 } |
581
ad07c868ff43
Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents:
580
diff
changeset
|
1236 } |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1237 } |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1238 |
632
cfab93886a88
MUC: use timestamp when available
Mikael Berthe <mikael@lilotux.net>
parents:
628
diff
changeset
|
1239 scr_WriteIncomingMessage(roomjid, mbuf, usttime, |
583
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1240 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1241 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1242 if (log_muc_conf) hlog_write_message(roomjid, 0, FALSE, mbuf); |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1243 |
32ae027a3238
MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents:
581
diff
changeset
|
1244 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
|
1245 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
|
1246 g_free(mbuf); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1247 return; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1248 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1249 g_free(mbuf); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1250 } 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
|
1251 ust != offline) { |
645
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1252 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1253 if (!buddy_getinsideroom(room_elt->data)) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1254 // 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
|
1255 // 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
|
1256 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1257 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
|
1258 // 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
|
1259 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
|
1260 // 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
|
1261 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
|
1262 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
|
1263 g_free(mbuf); |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1264 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
|
1265 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1266 // 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
|
1267 if (strcmp(ournick, rname)) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1268 // 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
|
1269 // 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
|
1270 // so we use 0 here. |
936df057dda0
MUC: Fix a timestamp issue when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
649
diff
changeset
|
1271 scr_WriteIncomingMessage(roomjid, mbuf, 0, |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1272 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1273 if (log_muc_conf) hlog_write_message(roomjid, 0, FALSE, mbuf); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1274 g_free(mbuf); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1275 mbuf = g_strdup_printf("%s has joined", rname); |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1276 new_member = TRUE; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1277 } |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1278 } else { |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1279 if (strcmp(ournick, rname)) { |
645
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1280 mbuf = g_strdup_printf("%s has joined", rname); |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1281 new_member = TRUE; |
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1282 } else |
645
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1283 mbuf = NULL; |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1284 } |
645
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1285 |
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1286 if (mbuf) { |
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1287 scr_WriteIncomingMessage(roomjid, mbuf, usttime, |
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1288 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); |
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1289 if (log_muc_conf) hlog_write_message(roomjid, 0, FALSE, mbuf); |
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1290 g_free(mbuf); |
d26a1c9611db
Small handle_presence_muc() update
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1291 } |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1292 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1293 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1294 // Update room member status |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
1295 if (rname) { |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1296 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
|
1297 mbrole, mbaffil, mbjid); |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1298 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
|
1299 // FIXME: This will fail for some UTF-8 nicknames. |
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1300 gchar *joiner_nick = from_utf8(rname); |
960
90ff94f0fbbb
Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents:
956
diff
changeset
|
1301 room_whois(room_elt->data, joiner_nick, FALSE); |
837
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1302 g_free(joiner_nick); |
7c74eef1d0e0
New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents:
834
diff
changeset
|
1303 } |
590
a5707d61e469
Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents:
589
diff
changeset
|
1304 } else |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1305 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
|
1306 |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1307 buddylist_build(); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1308 scr_DrawRoster(); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1309 } |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1310 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1311 static void handle_packet_presence(jconn conn, char *type, char *from, |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1312 xmlnode xmldata) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1313 { |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1314 char *p, *r; |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1315 char *ustmsg; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1316 const char *rname; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1317 enum imstatus ust; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1318 char bpprio; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1319 time_t timestamp = 0; |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1320 xmlnode muc_packet; |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1321 |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
1322 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
|
1323 if (rname) rname++; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1324 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1325 r = jidtodisp(from); |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1326 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1327 // Check for MUC presence packet |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1328 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
|
1329 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1330 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
|
1331 xmlnode x; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1332 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1333 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1334 display_server_error(x); |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1335 |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1336 // 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
|
1337 // 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
|
1338 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
|
1339 if (atoi(p) == 409) { |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1340 // 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
|
1341 // 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
|
1342 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
|
1343 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
|
1344 buddy_setnickname(room_elt->data, NULL); |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1345 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1346 } |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1347 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1348 g_free(r); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1349 return; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1350 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1351 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1352 p = xmlnode_get_tag_data(xmldata, "priority"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1353 if (p && *p) bpprio = (gchar)atoi(p); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1354 else bpprio = 0; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1355 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1356 ust = available; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1357 p = xmlnode_get_tag_data(xmldata, "show"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1358 if (p) { |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1359 if (!strcmp(p, "away")) ust = away; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1360 else if (!strcmp(p, "dnd")) ust = dontdisturb; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1361 else if (!strcmp(p, "xa")) ust = notavail; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1362 else if (!strcmp(p, "chat")) ust = freeforchat; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1363 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1364 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1365 if (type && !strcmp(type, "unavailable")) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1366 ust = offline; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1367 |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1368 ustmsg = xmlnode_get_tag_data(xmldata, "status"); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1369 |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1370 // Timestamp? |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1371 timestamp = xml_get_timestamp(xmldata); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1372 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1373 if (muc_packet) { |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1374 // 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
|
1375 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
|
1376 ust, ustmsg, timestamp, bpprio); |
579
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1377 } else { |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1378 // 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
|
1379 // 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
|
1380 // status message is different |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1381 const char *m = roster_getstatusmsg(r, rname); |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1382 if ((ust != roster_getstatus(r, rname)) || |
0c67755e0fa7
Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents:
578
diff
changeset
|
1383 (!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
|
1384 hk_statuschange(r, rname, bpprio, timestamp, ust, ustmsg); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1385 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1386 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1387 g_free(r); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1388 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1389 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1390 static void handle_packet_message(jconn conn, char *type, char *from, |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1391 xmlnode xmldata) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1392 { |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1393 char *p, *r, *s; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1394 xmlnode x; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1395 char *body=NULL; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1396 char *enc = NULL; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1397 char *tmp = NULL; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1398 time_t timestamp = 0; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1399 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1400 body = xmlnode_get_tag_data(xmldata, "body"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1401 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1402 p = xmlnode_get_tag_data(xmldata, "subject"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1403 if (p != NULL) { |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1404 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
|
1405 GSList *roombuddy; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1406 gchar *mbuf; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1407 gchar *subj = p; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1408 // Get the room (s) and the nickname (r) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1409 s = g_strdup(from); |
977
5b01de4ac5e1
Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents:
960
diff
changeset
|
1410 r = strchr(s, JID_RESOURCE_SEPARATOR); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1411 if (r) *r++ = 0; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1412 else r = s; |
549
448e299e45da
MUC: "/room topic" shows the current room topic
Mikael Berthe <mikael@lilotux.net>
parents:
547
diff
changeset
|
1413 // Set the new topic |
448e299e45da
MUC: "/room topic" shows the current room topic
Mikael Berthe <mikael@lilotux.net>
parents:
547
diff
changeset
|
1414 roombuddy = roster_find(s, jidsearch, 0); |
448e299e45da
MUC: "/room topic" shows the current room topic
Mikael Berthe <mikael@lilotux.net>
parents:
547
diff
changeset
|
1415 if (roombuddy) |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1416 buddy_settopic(roombuddy->data, subj); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1417 // Display inside the room window |
560
64cb4de94972
Better topic attribution
Mikael Berthe <mikael@lilotux.net>
parents:
549
diff
changeset
|
1418 if (r == s) { |
64cb4de94972
Better topic attribution
Mikael Berthe <mikael@lilotux.net>
parents:
549
diff
changeset
|
1419 // 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
|
1420 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
|
1421 } else { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1422 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
|
1423 } |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1424 scr_WriteIncomingMessage(s, mbuf, 0, |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1425 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1426 if (settings_opt_get_int("log_muc_conf")) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1427 hlog_write_message(s, 0, FALSE, mbuf); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1428 g_free(s); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1429 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
|
1430 // 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
|
1431 scr_UpdateChatStatus(TRUE); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1432 } else { // Chat message |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1433 tmp = g_new(char, (body ? strlen(body) : 0) + strlen(p) + 4); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1434 *tmp = '['; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1435 strcpy(tmp+1, p); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1436 strcat(tmp, "]\n"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1437 if (body) strcat(tmp, body); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1438 body = tmp; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1439 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1440 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1441 |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1442 handle_state_events(from, xmldata); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1443 |
644
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1444 // Not used yet... |
68fb0c1dfb15
MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents:
643
diff
changeset
|
1445 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
|
1446 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
|
1447 enc = p; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1448 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1449 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1450 // Timestamp? |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
624
diff
changeset
|
1451 timestamp = xml_get_timestamp(xmldata); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1452 |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1453 if (type && !strcmp(type, TMSG_ERROR)) { |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1454 if ((x = xmlnode_get_tag(xmldata, TMSG_ERROR)) != NULL) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1455 display_server_error(x); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1456 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1457 if (from && body) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1458 gotmessage(type, from, body, enc, timestamp); |
774
46304b773a44
Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents:
772
diff
changeset
|
1459 g_free(tmp); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1460 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1461 |
986
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1462 void handle_state_events(char* from, xmlnode xmldata) |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1463 { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1464 xmlnode x = NULL; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1465 char *rname = strchr(from, JID_RESOURCE_SEPARATOR) + 1; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1466 char *jid = jidtodisp(from); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1467 GSList *slist = roster_find(jid, jidsearch, ROSTER_TYPE_USER); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1468 if (slist == NULL) return; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1469 int jep85 = 0; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1470 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1471 guint events = buddy_resource_getevents(slist->data, rname); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1472 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1473 x = xml_get_xmlns(xmldata, NS_EVENT); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1474 if (x == NULL) { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1475 x = xmldata; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1476 jep85 = 1; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1477 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1478 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1479 xmlnode tag = xmlnode_get_tag(x, "composing"); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1480 if (tag != NULL) { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1481 events |= ROSTER_EVENT_COMPOSING; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1482 } else if (!jep85) { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1483 events &= ~ROSTER_EVENT_COMPOSING; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1484 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1485 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1486 if (jep85) { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1487 tag = xmlnode_get_tag(x, "paused"); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1488 if (tag != NULL) { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1489 events &= ~ROSTER_EVENT_COMPOSING; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1490 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1491 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1492 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1493 // clear composing and set new message event |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1494 // if message contains message body |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1495 if (xmlnode_get_tag_data(xmldata, "body") != NULL) { |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1496 events |= ROSTER_EVENT_MSG; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1497 events &= ~ROSTER_EVENT_COMPOSING; |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1498 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1499 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1500 buddy_resource_setevents(slist->data, rname, events); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1501 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1502 scr_UpdateBuddyWindow(); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1503 scr_DrawRoster(); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1504 |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1505 g_free(jid); |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1506 } |
ed697234bd39
Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents:
977
diff
changeset
|
1507 |
752 | 1508 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
|
1509 { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1510 char *barejid; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1511 char *buf; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1512 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1513 if (evcontext == EVS_CONTEXT_TIMEOUT) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1514 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
|
1515 evp->id); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1516 return; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1517 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1518 if (evcontext == EVS_CONTEXT_CANCEL) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1519 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
|
1520 return; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1521 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1522 if (!(evcontext & EVS_CONTEXT_USER)) |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1523 return; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1524 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1525 // Sanity check |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1526 if (!evp->data) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1527 // 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
|
1528 scr_LogPrint(LPRINT_LOGNORM, "Error in evs callback."); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1529 return; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1530 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1531 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1532 // Ok, let's work now. |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1533 // evcontext: 0, 1 == reject, accept |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1534 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1535 barejid = evp->data; |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1536 |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1537 if (evcontext & ~EVS_CONTEXT_USER) { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1538 // Accept subscription request |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1539 jb_subscr_send_auth(barejid); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1540 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
|
1541 barejid); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1542 } else { |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1543 // Reject subscription request |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1544 jb_subscr_cancel_auth(barejid); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1545 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
|
1546 if (settings_opt_get_int("delete_on_reject")) { |
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
1547 // 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
|
1548 if (roster_getsubscription(barejid) == sub_none) |
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
1549 jb_delbuddy(barejid); |
19c615fd071e
New option "delete_on_reject"
Mikael Berthe <mikael@lilotux.net>
parents:
819
diff
changeset
|
1550 } |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1551 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1552 scr_WriteIncomingMessage(barejid, buf, 0, HBB_PREFIX_INFO); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1553 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1554 g_free(buf); |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1555 } |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1556 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1557 static void handle_packet_s10n(jconn conn, char *type, char *from, |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1558 xmlnode xmldata) |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1559 { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1560 char *r; |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1561 char *buf; |
818
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
1562 int newbuddy; |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1563 |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1564 r = jidtodisp(from); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1565 |
818
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
1566 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
|
1567 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1568 if (!strcmp(type, "subscribe")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1569 /* The sender wishes to subscribe to our presence */ |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1570 char *msg; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1571 int isagent; |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1572 eviqs *evn; |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1573 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1574 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0; |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1575 msg = xmlnode_get_tag_data(xmldata, "status"); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1576 |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1577 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
|
1578 from); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1579 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1580 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1581 g_free(buf); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1582 |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1583 if (msg) { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1584 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
|
1585 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
|
1586 replace_nl_with_dots(buf); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1587 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1588 g_free(buf); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1589 } |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1590 |
749
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1591 // Create a new event item |
6c633adaae10
Use events system for subscription requests
Mikael Berthe <mikael@lilotux.net>
parents:
745
diff
changeset
|
1592 evn = evs_new(EVS_TYPE_SUBSCRIPTION, EVS_MAX_TIMEOUT); |
751
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
1593 if (evn) { |
752 | 1594 evn->callback = &evscallback_subscription; |
751
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
1595 evn->data = g_strdup(r); |
754
5b962b978573
Add event description when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
752
diff
changeset
|
1596 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
|
1597 "presence updates", r); |
751
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
1598 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
|
1599 } else { |
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
1600 buf = g_strdup_printf("Unable to create a new event!"); |
4a7271e69694
Avoid reusing events ids
Mikael Berthe <mikael@lilotux.net>
parents:
749
diff
changeset
|
1601 } |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1602 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1603 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1604 g_free(buf); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1605 } else if (!strcmp(type, "unsubscribe")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1606 /* The sender is unsubscribing from our presence */ |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
616
diff
changeset
|
1607 jb_subscr_cancel_auth(from); |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1608 buf = g_strdup_printf("<%s> is unsubscribing from your " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1609 "presence updates", from); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1610 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1611 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1612 g_free(buf); |
603 | 1613 } else if (!strcmp(type, "subscribed")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1614 /* The sender has allowed us to receive their presence */ |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1615 buf = g_strdup_printf("<%s> has allowed you to receive their " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1616 "presence updates", from); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1617 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1618 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1619 g_free(buf); |
603 | 1620 } else if (!strcmp(type, "unsubscribed")) { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1621 /* The subscription request has been denied or a previously-granted |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1622 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
|
1623 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
|
1624 update_roster = TRUE; |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1625 buf = g_strdup_printf("<%s> has cancelled your subscription to " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1626 "their presence updates", from); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1627 scr_WriteIncomingMessage(r, buf, 0, HBB_PREFIX_INFO); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1628 scr_LogPrint(LPRINT_LOGNORM, "%s", buf); |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1629 g_free(buf); |
603 | 1630 } else { |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1631 scr_LogPrint(LPRINT_LOGNORM, "Received unrecognized packet from <%s>, " |
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1632 "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
|
1633 newbuddy = FALSE; |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
1634 } |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
1635 |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
1636 if (newbuddy) { |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
1637 buddylist_build(); |
55cd45481a07
Fix a buddylist bug when receiving a subscription request
Mikael Berthe <mikael@lilotux.net>
parents:
793
diff
changeset
|
1638 update_roster = TRUE; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1639 } |
611
ad737139a144
Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents:
610
diff
changeset
|
1640 g_free(r); |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1641 } |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1642 |
533
c478e8f7f074
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
532
diff
changeset
|
1643 static void packethandler(jconn conn, jpacket packet) |
31 | 1644 { |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1645 char *p; |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1646 /* |
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1647 char *r, *s; |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1648 const char *m; |
772
464be13343a9
Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents:
756
diff
changeset
|
1649 */ |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1650 char *from=NULL, *type=NULL; |
31 | 1651 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1652 jb_reset_keepalive(); // reset keepalive timeout |
31 | 1653 jpacket_reset(packet); |
1654 | |
671
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
1655 if (!packet->type) { |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
1656 scr_LogPrint(LPRINT_LOG, "Packet type = 0"); |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
1657 return; |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
1658 } |
c5da36fd437a
Do not process packet if type = 0
Mikael Berthe <mikael@lilotux.net>
parents:
668
diff
changeset
|
1659 |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1660 p = xmlnode_get_attrib(packet->x, "type"); |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1661 if (p) type = p; |
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1662 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1663 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
|
1664 if (p) from = p; |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1665 |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1666 if (!from && packet->type != JPACKET_IQ) { |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1667 scr_LogPrint(LPRINT_LOGNORM, "Error in packet (could be UTF8-related)"); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1668 return; |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
468
diff
changeset
|
1669 } |
31 | 1670 |
1671 switch (packet->type) { | |
1672 case JPACKET_MESSAGE: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1673 handle_packet_message(conn, type, from, packet->x); |
31 | 1674 break; |
1675 | |
1676 case JPACKET_IQ: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1677 handle_packet_iq(conn, type, from, packet->x); |
31 | 1678 break; |
1679 | |
1680 case JPACKET_PRESENCE: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1681 handle_packet_presence(conn, type, from, packet->x); |
31 | 1682 break; |
1683 | |
1684 case JPACKET_S10N: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1685 handle_packet_s10n(conn, type, from, packet->x); |
31 | 1686 break; |
1687 | |
1688 default: | |
547
1df26ff0ed8c
Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
1689 scr_LogPrint(LPRINT_LOG, "Unhandled packet type (%d)", packet->type); |
31 | 1690 } |
1691 } | |
1692 | |
580 | 1693 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |