annotate mcabber/src/jabglue.c @ 706:934fddc99592

Check for IQ requests timeouts
author Mikael Berthe <mikael@lilotux.net>
date Sat, 18 Feb 2006 15:07:51 +0100
parents ee03b56b93ee
children b5aa7b7afee8
rev   line source
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
1 /*
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
2 * jabglue.c -- Jabber protocol handling
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
3 *
699
ee03b56b93ee Update Copyright (2006)
Mikael Berthe <mikael@lilotux.net>
parents: 695
diff changeset
4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.lilotux.net>
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
5 * Parts come from the centericq project:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
6 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua>
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
7 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or (at
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
11 * your option) any later version.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
12 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
16 * General Public License for more details.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
17 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
21 * USA
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
22 */
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
23
237
c8df64f43625 [/trunk] Changeset 250 by mikael
mikael
parents: 231
diff changeset
24 #define _GNU_SOURCE /* We need glibc for strptime */
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
25 #include "../libjabber/jabber.h"
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
26 #include "jabglue.h"
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
27 #include "jab_priv.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
28 #include "roster.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
29 #include "screen.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
30 #include "hooks.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
31 #include "utils.h"
294
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
32 #include "settings.h"
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
33 #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
34 #include "histolog.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
35
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
36 #define JABBERPORT 5222
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
37 #define JABBERSSLPORT 5223
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
38
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
39 jconn jc;
578
b3ab662757a0 Fix connection issue
Mikael Berthe <mikael@lilotux.net>
parents: 577
diff changeset
40 enum enum_jstate jstate;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
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
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
44 };
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
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
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
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);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
54
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
55 static void logger(jconn j, int io, const char *buf)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
56 {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
57 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
58 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
59
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
60 // jidtodisp(jid)
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
61 // Strips the resource part from the jid
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
62 // 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
63 char *jidtodisp(const char *jid)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
64 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
65 char *ptr;
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
66 char *alias;
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
67
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
68 alias = g_strdup(jid);
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
69
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
70 if ((ptr = strchr(alias, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
71 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
72 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
73 return alias;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
74 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
75
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
76 char *compose_jid(const char *username, const char *servername,
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
77 const char *resource)
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
78 {
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
79 char *jid = g_new(char, 3 +
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
80 strlen(username) + strlen(servername) + strlen(resource));
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
81 strcpy(jid, username);
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
82 if (!strchr(jid, '@')) {
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
83 strcat(jid, "@");
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
84 strcat(jid, servername);
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
85 }
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
86 strcat(jid, "/");
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
87 strcat(jid, resource);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
88 return jid;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
89 }
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
90
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
91 inline unsigned char jb_getonline(void)
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
92 {
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
93 return online;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
94 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
95
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
96 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
97 int ssl, const char *pass)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
98 {
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
99 char *utf8_jid;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
100 if (!port) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
101 if (ssl)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
102 port = JABBERSSLPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
103 else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
104 port = JABBERPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
105 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
106
357
e8adc3c96e68 Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents: 353
diff changeset
107 jb_disconnect();
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
108
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
109 utf8_jid = to_utf8(jid);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
110 if (!utf8_jid) return jc;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
111
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
112 jc = jab_new(utf8_jid, (char*)pass, (char*)server, port, ssl);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
113 g_free(utf8_jid);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
114
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
115 /* 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
116 jab_logger(jc, logger);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
117 jab_packet_handler(jc, &packethandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
118 jab_state_handler(jc, &statehandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
119
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
120 if (jc && jc->user) {
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
121 online = TRUE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
122 jstate = STATE_CONNECTING;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
123 statehandler(0, -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
124 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
125 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
126
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
127 return jc;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
128 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
129
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
130 void jb_disconnect(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
131 {
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
132 if (!jc) return;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
133
668
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
134 if (online) {
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
135 // Announce it to everyone else
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
136 jb_setstatus(offline, NULL, "");
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
137 // End the XML flow
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
138 jb_send_raw("</stream:stream>");
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
139 }
634
f3c05d5fe459 Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 633
diff changeset
140
f3c05d5fe459 Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 633
diff changeset
141 // Announce it to the user
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
142 statehandler(jc, JCONN_STATE_OFF);
416
48e7808c4191 Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents: 411
diff changeset
143
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
144 jab_delete(jc);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
145 jc = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
146 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
147
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
148 inline void jb_reset_keepalive()
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
149 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
150 time(&LastPingTime);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
151 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
152
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
153 void jb_send_raw(const char *str)
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
154 {
461
1d8f5b3a5f2b Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
155 if (jc && online && str)
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
156 jab_send_raw(jc, str);
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
157 }
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
158
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
159 void jb_keepalive()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
160 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
161 if (jc && online)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
162 jab_send_raw(jc, " \t ");
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
163 jb_reset_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
164 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
165
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
166 void jb_set_keepalive_delay(unsigned int delay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
167 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
168 KeepaliveDelay = delay;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
169 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
170
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
171 void jb_main()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
172 {
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
173 time_t now;
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
174 static time_t last_iqs_check = 0;
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
175
406
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
176 if (!online) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
177 safe_usleep(10000);
406
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
178 return;
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
179 }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
180
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
181 if (jc && jc->state == JCONN_STATE_CONNECTING) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
182 safe_usleep(75000);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
183 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
184 return;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
185 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
186
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
187 jab_poll(jc, 50);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
188
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
189 if (jstate == STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
190 if (jc) {
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
191 iqs *iqn;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
192 xmlnode z;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
193
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
194 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
195 iqn->callback = &iqscallback_auth;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
196
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
197 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
198 "username");
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
199 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
200 jab_send(jc, iqn->xmldata);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
201
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
202 jstate = STATE_GETAUTH;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
203 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
204
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
205 if (!jc || jc->state == JCONN_STATE_OFF) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
206 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
207 online = FALSE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
208 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
209 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
210
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
211 if (!jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
212 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
213 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
214 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
215 }
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
216
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
217 time(&now);
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
218
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
219 // Check for IQ requests timeouts
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
220 if (now > last_iqs_check + 20) {
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
221 iqs_check_timeout(now);
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
222 last_iqs_check = now;
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
223 }
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
224
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
225 // Keepalive
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
226 if (KeepaliveDelay) {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
227 if (now > LastPingTime + KeepaliveDelay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
228 jb_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
229 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
230 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
231
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
232 inline enum imstatus jb_getstatus()
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
233 {
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
234 return mystatus;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
235 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
236
519
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
237 inline const char *jb_getstatusmsg()
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
238 {
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
239 return mystatusmsg;
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
240 }
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
241
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
242 static void roompresence(gpointer room, void *presencedata)
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
243 {
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
244 const char *jid;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
245 const char *nickname;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
246 char *to;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
247 struct T_presence *pres = presencedata;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
248
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 651
diff changeset
249 if (!buddy_getinsideroom(room))
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
250 return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
251
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
252 jid = buddy_getjid(room);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
253 if (!jid) return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
254 nickname = buddy_getnickname(room);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
255 if (!nickname) return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
256
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
257 to = g_strdup_printf("%s/%s", jid, nickname);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
258 jb_setstatus(pres->st, to, pres->msg);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
259 g_free(to);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
260 }
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
261
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
262 // presnew(status, recipient, message)
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
263 // Create an xmlnode with default presence attributes
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
264 // Note: the caller must free the node after use
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
265 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
266 const char *msg)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
267 {
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
268 unsigned int prio;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
269 xmlnode x;
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
270 gchar *utf8_recipient = to_utf8(recipient);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
271
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
272 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
273
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
274 if (utf8_recipient) {
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
275 xmlnode_put_attrib(x, "to", utf8_recipient);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
276 g_free(utf8_recipient);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
277 }
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
278
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
279 switch(st) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
280 case away:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
281 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
282 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
283 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
284
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
285 case dontdisturb:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
286 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
287 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
288 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
289
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
290 case freeforchat:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
291 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
292 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
293 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
294
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
295 case notavail:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
296 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
297 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
298 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
299
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
300 case invisible:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
301 xmlnode_put_attrib(x, "type", "invisible");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
302 break;
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
303
118
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
304 case offline:
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
305 xmlnode_put_attrib(x, "type", "unavailable");
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
306 break;
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
307
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
308 default:
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
309 break;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
310 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
311
531
aee9a279a0f3 Allow changing priority on the fly
Mikael Berthe <mikael@lilotux.net>
parents: 527
diff changeset
312 prio = settings_opt_get_int("priority");
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
313 if (prio) {
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
314 char strprio[8];
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
315 snprintf(strprio, 8, "%u", prio);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
316 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
317 strprio, (unsigned) -1);
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
318 }
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
319
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
320 if (msg) {
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
321 gchar *utf8_msg = to_utf8(msg);
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
322 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg,
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
323 (unsigned) -1);
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
324 g_free(utf8_msg);
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
325 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
326
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
327 return x;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
328 }
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
329
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
330 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg)
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
331 {
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
332 xmlnode x;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
333 struct T_presence room_presence;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
334
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
335 if (!online) return;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
336
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
337 if (msg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
338 // The status message has been specified. We'll use it, unless it is
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
339 // "-" which is a special case (option meaning "no status message").
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
340 if (!strcmp(msg, "-"))
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
341 msg = "";
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
342 } else {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
343 // No status message specified; we'll use:
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
344 // a) the default status message (if provided by the user);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
345 // b) the current status message;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
346 // c) no status message (i.e. an empty one).
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
347 msg = settings_get_status_msg(st);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
348 if (!msg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
349 if (mystatusmsg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
350 msg = mystatusmsg;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
351 else
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
352 msg = "";
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
353 }
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
354 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
355
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 671
diff changeset
356 x = presnew(st, recipient, (st != invisible ? msg : NULL));
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
357 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
358 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
359
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
360 // If we didn't change our _global_ status, we are done
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
361 if (recipient) return;
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
362
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
363 // Send presence to chatrooms
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
364 if (st != invisible) {
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
365 room_presence.st = st;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
366 room_presence.msg = msg;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
367 foreach_buddy(ROSTER_TYPE_ROOM, &roompresence, &room_presence);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
368 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
369
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
370 // We'll need to update the roster if we switch to/from offline because
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
371 // we don't know the presences of buddies when offline...
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
372 if (mystatus == offline || st == offline)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
373 update_roster = TRUE;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
374
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 671
diff changeset
375 hk_mystatuschange(0, mystatus, st, (st != invisible ? msg : ""));
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
376 mystatus = st;
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
377 if (msg != mystatusmsg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
378 if (mystatusmsg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
379 g_free(mystatusmsg);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
380 if (*msg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
381 mystatusmsg = g_strdup(msg);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
382 else
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
383 mystatusmsg = NULL;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
384 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
385 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
386
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
387 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
388 const char *subject)
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
389 {
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
390 xmlnode x;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
391 gchar *strtype;
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
392 gchar *utf8_jid;
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
393 gchar *buffer;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
394
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
395 if (!online) return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
396
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
397 if (type == ROSTER_TYPE_ROOM)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
398 strtype = TMSG_GROUPCHAT;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
399 else
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
400 strtype = TMSG_CHAT;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
401
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
402 buffer = to_utf8(text);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
403 utf8_jid = to_utf8(jid); // Resource can require UTF-8
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
404
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
405 x = jutil_msgnew(strtype, utf8_jid, NULL, (char*)buffer);
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
406 if (subject) {
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
407 xmlnode y;
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
408 char *bs = to_utf8(subject);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
409 y = xmlnode_insert_tag(x, "subject");
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
410 xmlnode_insert_cdata(y, bs, (unsigned) -1);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
411 if (bs) g_free(bs);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
412 }
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
413 jab_send(jc, x);
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
414 xmlnode_free(x);
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
415
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
416 if (buffer) g_free(buffer);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
417 if (utf8_jid) g_free(utf8_jid);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
418
114
065d8368c36b [/trunk] Changeset 128 by mikael
mikael
parents: 113
diff changeset
419 jb_reset_keepalive();
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
420 }
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
421
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
422 // jb_subscr_send_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
423 // Allow jid to receive our presence updates
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
424 void jb_subscr_send_auth(const char *jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
425 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
426 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
427 char *utf8_jid = to_utf8(jid);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
428
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
429 x = jutil_presnew(JPACKET__SUBSCRIBED, utf8_jid, NULL);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
430 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
431 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
432 g_free(utf8_jid);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
433 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
434
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
435 // jb_subscr_cancel_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
436 // Cancel jid's subscription to our presence updates
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
437 void jb_subscr_cancel_auth(const char *jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
438 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
439 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
440 char *utf8_jid = to_utf8(jid);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
441
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
442 x = jutil_presnew(JPACKET__UNSUBSCRIBED, utf8_jid, NULL);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
443 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
444 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
445 g_free(utf8_jid);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
446 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
447
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
448 // jb_subscr_request_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
449 // Request a subscription to jid's presence updates
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
450 void jb_subscr_request_auth(const char *jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
451 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
452 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
453 char *utf8_jid = to_utf8(jid);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
454
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
455 x = jutil_presnew(JPACKET__SUBSCRIBE, utf8_jid, NULL);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
456 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
457 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
458 g_free(utf8_jid);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
459 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
460
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
461 // Note: the caller should check the jid is correct
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
462 void jb_addbuddy(const char *jid, const char *name, const char *group)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
463 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
464 xmlnode y, z;
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
465 iqs *iqn;
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
466 char *cleanjid;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
467
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
468 if (!online) return;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
469
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
470 cleanjid = jidtodisp(jid);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
471
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
472 // We don't check if the jabber user already exists in the roster,
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
473 // because it allows to re-ask for notification.
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
474
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
475 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
476 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
477
454399f026fa Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
478 xmlnode_put_attrib(y, "jid", cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
479
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
480 if (name) {
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
481 gchar *name_utf8 = to_utf8(name);
628
454399f026fa Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
482 xmlnode_put_attrib(y, "name", name_utf8);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
483 g_free(name_utf8);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
484 }
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
485
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
486 if (group) {
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
487 char *group_utf8 = to_utf8(group);
628
454399f026fa Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
488 z = xmlnode_insert_tag(y, "group");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
489 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
490 g_free(group_utf8);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
491 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
492
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
493 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
494 iqs_del(iqn->id); // XXX
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
495
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
496 jb_subscr_request_auth(cleanjid);
612
789ec6aed764 Respect RFC 3921 order advice
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
497
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
498 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
499 g_free(cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
500 buddylist_build();
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
501
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
502 update_roster = TRUE;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
503 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
504
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
505 void jb_delbuddy(const char *jid)
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
506 {
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
507 xmlnode x, y, z;
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
508 iqs *iqn;
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
509 char *cleanjid;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
510
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
511 if (!online) return;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
512
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
513 cleanjid = jidtodisp(jid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
514
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
515 // If the current buddy is an agent, unsubscribe from it
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
516 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
517 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
518
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
519 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
520 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
521 y = xmlnode_get_tag(iqn->xmldata, "query");
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
522 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
523 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
524 iqs_del(iqn->id); // XXX
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
525 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
526
611
ad737139a144 Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
527 // Cancel the subscriptions
ad737139a144 Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
528 x = jutil_presnew(JPACKET__UNSUBSCRIBED, cleanjid, 0); // Cancel "from"
ad737139a144 Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
529 jab_send(jc, x);
ad737139a144 Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
530 xmlnode_free(x);
ad737139a144 Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
531 x = jutil_presnew(JPACKET__UNSUBSCRIBE, cleanjid, 0); // Cancel "to"
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
532 jab_send(jc, x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
533 xmlnode_free(x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
534
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
535 // 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
536 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
537 y = xmlnode_get_tag(iqn->xmldata, "query");
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
538 z = xmlnode_insert_tag(y, "item");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
539 xmlnode_put_attrib(z, "jid", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
540 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
541 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
542 iqs_del(iqn->id); // XXX
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
543
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
544 roster_del_user(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
545 g_free(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
546 buddylist_build();
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
547
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
548 update_roster = TRUE;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
549 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
550
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
551 void jb_updatebuddy(const char *jid, const char *name, const char *group)
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
552 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
553 xmlnode y;
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
554 iqs *iqn;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
555 char *cleanjid;
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
556 gchar *name_utf8;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
557
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
558 if (!online) return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
559
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
560 // XXX We should check name's and group's correctness
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
561
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
562 cleanjid = jidtodisp(jid);
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
563 name_utf8 = to_utf8(name);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
564
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_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item");
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
567 xmlnode_put_attrib(y, "jid", cleanjid);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
568 xmlnode_put_attrib(y, "name", name_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
569
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
570 if (group) {
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
571 gchar *group_utf8 = to_utf8(group);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
572 y = xmlnode_insert_tag(y, "group");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
573 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
574 g_free(group_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
575 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
576
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
577 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
578 iqs_del(iqn->id); // XXX
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
579 g_free(name_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
580 g_free(cleanjid);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
581 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
582
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
583 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
584 {
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
585 GSList *resources;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
586 GSList *roster_elt;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
587
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
588 if (reqtype == iqreq_none) return;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
589
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
590 if (strchr(jid, '/')) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
591 // This is a full JID
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
592 if (reqtype == iqreq_version) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
593 request_version(jid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
594 scr_LogPrint(LPRINT_NORMAL, "Sent version request to <%s>", jid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
595 } else if (reqtype == iqreq_time) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
596 request_time(jid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
597 scr_LogPrint(LPRINT_NORMAL, "Sent time request to <%s>", jid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
598 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
599 return;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
600 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
601
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
602 // The resource has not been specified
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
603 roster_elt = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_ROOM);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
604 if (!roster_elt) {
695
c299035ccb9f Fix up jb_request(), when the resource is unknown
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
605 scr_LogPrint(LPRINT_NORMAL, "No known resource for <%s>...", jid);
c299035ccb9f Fix up jb_request(), when the resource is unknown
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
606 request_version(jid); // Let's send a request anyway...
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
607 return;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
608 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
609
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
610 // Send a request to each resource
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
611 resources = buddy_getresources(roster_elt->data);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
612 for ( ; resources ; resources = g_slist_next(resources) ) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
613 gchar *fulljid;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
614 fulljid = g_strdup_printf("%s/%s", jid, (char*)resources->data);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
615 if (reqtype == iqreq_version) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
616 request_version(fulljid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
617 scr_LogPrint(LPRINT_NORMAL, "Sent version request to <%s>", fulljid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
618 } else if (reqtype == iqreq_time) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
619 request_time(fulljid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
620 scr_LogPrint(LPRINT_NORMAL, "Sent time request to <%s>", fulljid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
621 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
622 g_free(fulljid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
623 }
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
624 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
625
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
626 // Join a MUC room
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
627 void jb_room_join(const char *room, const char *nickname)
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
628 {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
629 xmlnode x, y;
643
dd73c3dad815 Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 642
diff changeset
630 gchar *roomid;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
631 GSList *room_elt;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
632
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
633 if (!online || !room) return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
634 if (!nickname) return;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
635
643
dd73c3dad815 Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 642
diff changeset
636 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
637 if (check_jid_syntax(roomid)) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
638 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
639 nickname);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
640 g_free(roomid);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
641 return;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
642 }
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
643
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
644 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
645 // 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
646 if (!room_elt) {
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
647 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
648 } else {
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 645
diff changeset
649 // 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
650 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
651 }
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
652 // 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
653 if (!buddy_getinsideroom(room_elt->data)) {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
654 // 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
655 buddy_setnickname(room_elt->data, nickname);
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
656 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
657
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
658 // Send the XML request
535
b407d19c39ab Set status correctly when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 534
diff changeset
659 x = presnew(mystatus, roomid, mystatusmsg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
660 y = xmlnode_insert_tag(x, "x");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
661 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
662
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
663 jab_send(jc, x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
664 xmlnode_free(x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
665 jb_reset_keepalive();
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
666 g_free(roomid);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
667 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
668
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
669 // Unlock a MUC room
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
670 // room syntax: "room@server"
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
671 void jb_room_unlock(const char *room)
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
672 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
673 xmlnode y, z;
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
674 iqs *iqn;
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
675
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
676 if (!online || !room) return;
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
677
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
678 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
679 "unlock", IQS_DEFAULT_TIMEOUT);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
680 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
681 y = xmlnode_get_tag(iqn->xmldata, "query");
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
682 z = xmlnode_insert_tag(y, "x");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
683 xmlnode_put_attrib(z, "xmlns", "jabber:x:data");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
684 xmlnode_put_attrib(z, "type", "submit");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
685
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
686 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
687 iqs_del(iqn->id); // XXX
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
688 jb_reset_keepalive();
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
689 }
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
690
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
691 // Destroy a MUC room
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
692 // room syntax: "room@server"
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
693 void jb_room_destroy(const char *room, const char *venue, const char *reason)
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
694 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
695 xmlnode y, z;
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
696 iqs *iqn;
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
697
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
698 if (!online || !room) return;
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
699
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
700 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
701 "destroy", IQS_DEFAULT_TIMEOUT);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
702 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
703 y = xmlnode_get_tag(iqn->xmldata, "query");
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
704 z = xmlnode_insert_tag(y, "destroy");
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
705
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
706 if (venue && *venue)
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
707 xmlnode_put_attrib(z, "jid", venue);
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
708
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
709 if (reason) {
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
710 gchar *utf8_reason = to_utf8(reason);
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
711 y = xmlnode_insert_tag(z, "reason");
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
712 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1);
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
713 g_free(utf8_reason);
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
714 }
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
715
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
716 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
717 iqs_del(iqn->id); // XXX
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
718 jb_reset_keepalive();
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
719 }
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
720
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
721 // Change role or affiliation of a MUC user
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
722 // room syntax: "room@server"
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
723 // Either the jid or the nickname must be set (when banning, only the jid is
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
724 // allowed)
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
725 // ra: new role or affiliation
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
726 // (ex. role none for kick, affil outcast for ban...)
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
727 // The reason can be null
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
728 // Return 0 if everything is ok
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
729 int jb_room_setattrib(const char *roomid, const char *jid, const char *nick,
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
730 struct role_affil ra, const char *reason)
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
731 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
732 xmlnode y, z;
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
733 iqs *iqn;
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
734
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
735 if (!online || !roomid) return 1;
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
736 if (!jid && !nick) return 1;
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
737
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
738 if (check_jid_syntax((char*)roomid)) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
739 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", roomid);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
740 return 1;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
741 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
742 if (jid && check_jid_syntax((char*)jid)) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
743 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
744 return 1;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
745 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
746
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
747 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
748 return 1; // Shouldn't happen (jid mandatory when banning)
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
749
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
750 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
751 "roleaffil", IQS_DEFAULT_TIMEOUT);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
752 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
753 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
754 y = xmlnode_get_tag(iqn->xmldata, "query");
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
755 z = xmlnode_insert_tag(y, "item");
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
756
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
757 if (jid) {
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
758 gchar *utf8_jid = to_utf8(jid);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
759 xmlnode_put_attrib(z, "jid", utf8_jid);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
760 if (utf8_jid) g_free(utf8_jid);
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
761 } else { // nick
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
762 gchar *utf8_nickname = to_utf8(nick);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
763 xmlnode_put_attrib(z, "nick", utf8_nickname);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
764 g_free(utf8_nickname);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
765 }
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
766
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
767 if (ra.type == type_affil)
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
768 xmlnode_put_attrib(z, "affiliation", straffil[ra.val.affil]);
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
769 else if (ra.type == type_role)
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
770 xmlnode_put_attrib(z, "role", strrole[ra.val.role]);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
771
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
772 if (reason) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
773 gchar *utf8_reason = to_utf8(reason);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
774 y = xmlnode_insert_tag(z, "reason");
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
775 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
776 g_free(utf8_reason);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
777 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
778
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
779 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
780 iqs_del(iqn->id); // XXX
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
781 jb_reset_keepalive();
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
782
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
783 return 0;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
784 }
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
785
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
786 // Invite a user to a MUC room
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
787 // room syntax: "room@server"
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
788 // reason can be null.
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
789 void jb_room_invite(const char *room, const char *jid, const char *reason)
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
790 {
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
791 xmlnode x, y, z;
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
792 gchar *utf8_jid;
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
793
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
794 if (!online || !room || !jid) return;
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
795
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
796 x = jutil_msgnew(NULL, (char*)room, NULL, NULL);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
797
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
798 y = xmlnode_insert_tag(x, "x");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
799 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
800
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
801 utf8_jid = to_utf8(jid); // Resource can require UTF-8
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
802 z = xmlnode_insert_tag(y, "invite");
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
803 xmlnode_put_attrib(z, "to", utf8_jid);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
804 if (utf8_jid) g_free(utf8_jid);
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
805
569
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
806 if (reason) {
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
807 gchar *utf8_reason = to_utf8(reason);
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
808 y = xmlnode_insert_tag(z, "reason");
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
809 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1);
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
810 g_free(utf8_reason);
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
811 }
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
812
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
813 jab_send(jc, x);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
814 xmlnode_free(x);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
815 jb_reset_keepalive();
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
816 }
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
817
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
818 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
819 const char *enc, time_t timestamp)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
820 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
821 char *jid;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
822 const char *rname;
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
823 gchar *buffer = from_utf8(body);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
824
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
825 jid = jidtodisp(from);
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
826
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
827 if (!buffer && body) {
523
fc6bc26f891e Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents: 521
diff changeset
828 scr_LogPrint(LPRINT_NORMAL, "Decoding of message from <%s> has failed",
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
829 from);
523
fc6bc26f891e Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents: 521
diff changeset
830 scr_LogPrint(LPRINT_LOG, "Decoding of message from <%s> has failed: %s",
fc6bc26f891e Write UTF-9 conversion failures to the tracelog file
Mikael Berthe <mikael@lilotux.net>
parents: 521
diff changeset
831 from, body);
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
832 scr_WriteIncomingMessage(jid, "Cannot display message: "
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
833 "UTF-8 conversion failure",
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
834 0, HBB_PREFIX_ERR | HBB_PREFIX_IN);
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
835 g_free(jid);
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
836 return;
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
837 }
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
838
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
839 rname = strchr(from, '/');
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
840 if (rname) rname++;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
841 hk_message_in(jid, rname, timestamp, buffer, type);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
842 g_free(jid);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
843 g_free(buffer);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
844 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
845
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
846 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
847 {
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
848 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
849
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
850 switch(code) {
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
851 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
852 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
853 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
854 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
855 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
856 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
857 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
858 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
859 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
860 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
861 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
862 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
863 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
864 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
865 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
866 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
867 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
868 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
869 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
870 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
871 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
872 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
873 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
874 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
875 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
876 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
877 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
878 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
879 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
880 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
881 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
882 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
883 default:
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
884 desc = NULL;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
885 }
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
886
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
887 return desc;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
888 }
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
889
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
890 // display_server_error(x)
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
891 // 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
892 // x: error tag xmlnode pointer
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
893 void display_server_error(xmlnode x)
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
894 {
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
895 const char *desc = NULL;
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
896 int code = 0;
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
897 char *s;
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
898 const char *p;
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
899
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
900 /* RFC3920:
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
901 * The <error/> element:
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
902 * 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
903 * 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
904 * 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
905 */
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
906 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
907 if (p)
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
908 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
909
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
910 // For backward compatibility
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
911 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
912 code = atoi(s);
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
913 // Default message
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
914 desc = defaulterrormsg(code);
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
915 }
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
916
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
917 // 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
918 s = xmlnode_get_data(x);
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
919 if (s && *s) desc = s;
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
920
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
921 // 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
922 s = xmlnode_get_tag_data(x, "text");
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
923 if (s && *s) desc = s; // FIXME utf8??
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
924
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
925 scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, desc);
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
926 }
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
927
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
928 static void statehandler(jconn conn, int state)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
929 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
930 static int previous_state = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
931
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
932 scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
933
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
934 switch(state) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
935 case JCONN_STATE_OFF:
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
936 if (previous_state != JCONN_STATE_OFF)
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
937 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server");
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
938
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
939 online = FALSE;
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
940 mystatus = offline;
519
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
941 if (mystatusmsg) {
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
942 g_free(mystatusmsg);
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
943 mystatusmsg = NULL;
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
944 }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
945 roster_free();
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
946 update_roster = TRUE;
598
a3db3ee8b99e Fix some display issues
Mikael Berthe <mikael@lilotux.net>
parents: 590
diff changeset
947 scr_ShowBuddyWindow();
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
948 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
949
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
950 case JCONN_STATE_CONNECTED:
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
951 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
952 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
953
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
954 case JCONN_STATE_AUTH:
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
955 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
956 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
957
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
958 case JCONN_STATE_ON:
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
959 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server "
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
960 "established");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
961 online = TRUE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
962 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
963
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
964 case JCONN_STATE_CONNECTING:
357
e8adc3c96e68 Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents: 353
diff changeset
965 if (previous_state != state)
408
73433860665c Tune previous usleep() change
Mikael Berthe <mikael@lilotux.net>
parents: 407
diff changeset
966 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server");
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
967 break;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
968
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
969 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
970 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
971 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
972 previous_state = state;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
973 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
974
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
975 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
976 {
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
977 xmlnode x;
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
978 char *p;
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
979
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
980 x = xmlnode_get_firstchild(xmldata);
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
981 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
982 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
983 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
984 break;
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
985 }
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
986 }
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
987 return x;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
988 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
989
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
990 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
991 {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
992 xmlnode x;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
993 char *p;
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
994
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
995 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
996 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
997 return from_iso8601(p, 1);
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
998 return 0;
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
999 }
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
1000
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1001 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
1002 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
1003 enum imstatus ust, char *ustmsg,
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 624
diff changeset
1004 time_t usttime, char bpprio)
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1005 {
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1006 xmlnode y;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1007 char *p;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1008 const char *m;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1009 enum imrole mbrole = role_none;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1010 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
1011 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
1012 const char *actorjid = NULL, *reason = NULL;
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1013 unsigned int statuscode = 0;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1014 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
1015 int log_muc_conf;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1016
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1017 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
1018
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1019 room_elt = roster_find(roomjid, jidsearch, 0);
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1020 if (!room_elt) {
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1021 // Add room if it doesn't already exist FIXME shouldn't happen!
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1022 room_elt = roster_add_user(roomjid, NULL, NULL, ROSTER_TYPE_ROOM, sub_none);
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1023 } else {
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1024 // 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
1025 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1026 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1027
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1028 // Get room member's information
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1029 y = xmlnode_get_tag(xmldata, "item");
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1030 if (y) {
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1031 xmlnode z;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1032 p = xmlnode_get_attrib(y, "affiliation");
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1033 if (p) {
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1034 if (!strcmp(p, "owner")) mbaffil = affil_owner;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1035 else if (!strcmp(p, "admin")) mbaffil = affil_admin;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1036 else if (!strcmp(p, "member")) mbaffil = affil_member;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1037 else if (!strcmp(p, "outcast")) mbaffil = affil_outcast;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1038 else if (!strcmp(p, "none")) mbaffil = affil_none;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1039 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
1040 from, p);
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1041 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1042 p = xmlnode_get_attrib(y, "role");
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1043 if (p) {
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1044 if (!strcmp(p, "moderator")) mbrole = role_moderator;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1045 else if (!strcmp(p, "participant")) mbrole = role_participant;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1046 else if (!strcmp(p, "visitor")) mbrole = role_visitor;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1047 else if (!strcmp(p, "none")) mbrole = role_none;
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1048 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
1049 from, p);
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1050 }
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1051 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
1052 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
1053 // 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
1054 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
1055 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
1056 if (z)
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1057 actorjid = xmlnode_get_attrib(z, "jid");
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1058 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1059
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1060 // 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
1061 // 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
1062 // 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
1063 // 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
1064 // 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
1065 // 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
1066 y = xmlnode_get_tag(xmldata, "status");
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1067 if (y) {
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1068 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
1069 if (p)
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1070 statuscode = atoi(p);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1071 }
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1072
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1073 // 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
1074 if (statuscode == 303 && mbnick) {
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1075 gchar *mbuf;
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1076 gchar *newname_noutf8 = from_utf8(mbnick);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1077 if (!newname_noutf8)
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1078 scr_LogPrint(LPRINT_LOG, "Decoding of new nickname has failed: %s",
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1079 mbnick);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1080 mbuf = g_strdup_printf("%s is now known as %s", rname,
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1081 (newname_noutf8 ? newname_noutf8 : "(?)"));
632
cfab93886a88 MUC: use timestamp when available
Mikael Berthe <mikael@lilotux.net>
parents: 628
diff changeset
1082 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
1083 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
1084 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
1085 g_free(mbuf);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1086 if (newname_noutf8) {
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1087 buddy_resource_setname(room_elt->data, rname, newname_noutf8);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1088 m = buddy_getnickname(room_elt->data);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1089 if (m && !strcmp(rname, m))
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1090 buddy_setnickname(room_elt->data, newname_noutf8);
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1091 g_free(newname_noutf8);
579
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 }
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1094
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1095 // 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
1096 if (!mbnick && mbrole == role_none) {
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1097 gchar *mbuf;
586
d8f64e74206c Missing initialization
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1098 enum { leave=0, kick, ban } how = leave;
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1099 bool we_left = FALSE;
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1100
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1101 if (statuscode == 307)
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1102 how = kick;
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1103 else if (statuscode == 301)
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1104 how = ban;
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1105
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1106 // If this is a leave, check if it is ourself
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1107 m = buddy_getnickname(room_elt->data);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1108
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1109 if (m && !strcmp(rname, m)) {
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1110 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
1111 buddy_setinsideroom(room_elt->data, FALSE);
579
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1112 buddy_setnickname(room_elt->data, NULL);
0c67755e0fa7 Introduce a handle_presence_muc() function
Mikael Berthe <mikael@lilotux.net>
parents: 578
diff changeset
1113 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
1114 buddy_settopic(room_elt->data, NULL);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1115 update_roster = TRUE;
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1116 }
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1117
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1118 // The message depends on _who_ left, and _how_
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1119 if (how) {
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1120 gchar *mbuf_end;
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1121 // Forced leave
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1122 if (actorjid) {
587
1b773c760a99 Kick/ban: convert reason to user's locale
Mikael Berthe <mikael@lilotux.net>
parents: 586
diff changeset
1123 gchar *rsn_noutf8 = from_utf8(reason);
589
9942746e8d58 Improve fix from changeset 1b773c760a99
Mikael Berthe <mikael@lilotux.net>
parents: 587
diff changeset
1124 if (!rsn_noutf8 && reason) {
9942746e8d58 Improve fix from changeset 1b773c760a99
Mikael Berthe <mikael@lilotux.net>
parents: 587
diff changeset
1125 scr_LogPrint(LPRINT_NORMAL, "UTF-8 decoding of reason has failed");
9942746e8d58 Improve fix from changeset 1b773c760a99
Mikael Berthe <mikael@lilotux.net>
parents: 587
diff changeset
1126 scr_LogPrint(LPRINT_LOG, "UTF-8 decoding of reason has failed: %s",
9942746e8d58 Improve fix from changeset 1b773c760a99
Mikael Berthe <mikael@lilotux.net>
parents: 587
diff changeset
1127 reason);
9942746e8d58 Improve fix from changeset 1b773c760a99
Mikael Berthe <mikael@lilotux.net>
parents: 587
diff changeset
1128 }
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1129 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
1130 (how == ban ? "banned" : "kicked"),
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1131 roomjid, actorjid,
587
1b773c760a99 Kick/ban: convert reason to user's locale
Mikael Berthe <mikael@lilotux.net>
parents: 586
diff changeset
1132 (rsn_noutf8 ? rsn_noutf8 : "None given"));
1b773c760a99 Kick/ban: convert reason to user's locale
Mikael Berthe <mikael@lilotux.net>
parents: 586
diff changeset
1133 if (rsn_noutf8)
1b773c760a99 Kick/ban: convert reason to user's locale
Mikael Berthe <mikael@lilotux.net>
parents: 586
diff changeset
1134 g_free(rsn_noutf8);
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1135 } else {
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1136 mbuf_end = g_strdup_printf("%s from %s.",
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1137 (how == ban ? "banned" : "kicked"),
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1138 roomjid);
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1139 }
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1140 if (we_left)
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1141 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
1142 else
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1143 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
1144
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1145 g_free(mbuf_end);
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1146 } else {
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1147 // Natural leave
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1148 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
1149 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
1150 if (destroynode) {
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1151 gchar *rsn_noutf8 = NULL;
624
4e882a19077d Fix double UTF-8 decoding
Mikael Berthe <mikael@lilotux.net>
parents: 617
diff changeset
1152 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
1153 rsn_noutf8 = from_utf8(reason);
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1154 if (rsn_noutf8) {
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1155 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
1156 "the room has been destroyed: %s",
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1157 roomjid, rsn_noutf8);
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1158 g_free(rsn_noutf8);
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1159 } else {
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1160 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
1161 "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
1162 }
a61a257ec38b MUC: display reason, if any, when a room has been destroyed
Mikael Berthe <mikael@lilotux.net>
parents: 612
diff changeset
1163 } else {
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1164 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
1165 }
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1166 } else {
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1167 if (ustmsg)
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1168 mbuf = g_strdup_printf("%s has left: %s", rname, ustmsg);
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1169 else
583
32ae027a3238 MUC: clean up departure message code
Mikael Berthe <mikael@lilotux.net>
parents: 581
diff changeset
1170 mbuf = g_strdup_printf("%s has left", rname);
581
ad07c868ff43 Tell the user when he or she has been kicked/banned
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1171 }
583
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<