annotate mcabber/src/jabglue.c @ 1023:94d9a3cbb211

Remove useless message Doing /info was noisy with a server without private storage support.
author Mikael Berthe <mikael@lilotux.net>
date Sat, 18 Nov 2006 15:48:49 +0100
parents 4c8d7b558e83
children 8a395c2cafc4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
24 #include "../libjabber/jabber.h"
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
25 #include "jabglue.h"
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
26 #include "jab_priv.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
27 #include "roster.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
28 #include "screen.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
29 #include "hooks.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
30 #include "utils.h"
294
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
31 #include "settings.h"
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
32 #include "hbuf.h"
478
47cfa3779549 MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
33 #include "histolog.h"
837
7c74eef1d0e0 New option "muc_auto_whois"
Mikael Berthe <mikael@lilotux.net>
parents: 834
diff changeset
34 #include "commands.h"
29
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
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
39 #define RECONNECTION_TIMEOUT 60L
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
40
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
41 jconn jc;
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
42 guint AutoConnection;
578
b3ab662757a0 Fix connection issue
Mikael Berthe <mikael@lilotux.net>
parents: 577
diff changeset
43 enum enum_jstate jstate;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
44
353
3fe43f6daa5a Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
45 char imstatus2char[imstatus_size+1] = {
3fe43f6daa5a Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
46 '_', 'o', 'i', 'f', 'd', 'n', 'a', '\0'
46
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
47 };
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
48
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
49 static time_t LastPingTime;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
50 static unsigned int KeepaliveDelay;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
51 static enum imstatus mystatus = offline;
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
52 static enum imstatus mywantedstatus = available;
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
53 static gchar *mystatusmsg;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
54 static unsigned char online;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
55
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
56 static void statehandler(jconn, int);
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
57 static void packethandler(jconn, jpacket);
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
58 void handle_state_events(char* from, xmlnode xmldata);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
59
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
60 static void logger(jconn j, int io, const char *buf)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
61 {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
62 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
63 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
64
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
65 // jidtodisp(jid)
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
66 // Strips the resource part from the jid
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
67 // 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
68 char *jidtodisp(const char *jid)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
69 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
70 char *ptr;
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
71 char *alias;
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
72
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
73 alias = g_strdup(jid);
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
74
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 960
diff changeset
75 if ((ptr = strchr(alias, JID_RESOURCE_SEPARATOR)) != NULL) {
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
76 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
77 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
78 return alias;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
79 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
80
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
81 char *compose_jid(const char *username, const char *servername,
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
82 const char *resource)
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
83 {
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
84 char *jid = g_new(char, 3 +
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
85 strlen(username) + strlen(servername) + strlen(resource));
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
86 strcpy(jid, username);
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 960
diff changeset
87 if (!strchr(jid, JID_DOMAIN_SEPARATOR)) {
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 960
diff changeset
88 strcat(jid, JID_DOMAIN_SEPARATORSTR);
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
89 strcat(jid, servername);
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
90 }
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 960
diff changeset
91 strcat(jid, JID_RESOURCE_SEPARATORSTR);
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
92 strcat(jid, resource);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
93 return jid;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
94 }
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
95
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
96 inline unsigned char jb_getonline(void)
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
97 {
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
98 return online;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
99 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
100
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
101 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
102 int ssl, const char *pass)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
103 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
104 if (!port) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
105 if (ssl)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
106 port = JABBERSSLPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
107 else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
108 port = JABBERPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
109 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
110
357
e8adc3c96e68 Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents: 353
diff changeset
111 jb_disconnect();
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
112
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
113 if (!jid) return jc;
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
114
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
115 jc = jab_new((char*)jid, (char*)pass, (char*)server, port, ssl);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
116
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
117 /* 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
118 jab_logger(jc, logger);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
119 jab_packet_handler(jc, &packethandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
120 jab_state_handler(jc, &statehandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
121
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
122 if (jc && jc->user) {
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
123 online = TRUE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
124 jstate = STATE_CONNECTING;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
125 statehandler(0, -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
126 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
127 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
128
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
129 return jc;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
130 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
131
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
132 void jb_disconnect(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
133 {
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
134 if (!jc) return;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
135
668
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
136 if (online) {
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
137 // Announce it to everyone else
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
138 jb_setstatus(offline, NULL, "");
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
139 // End the XML flow
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
140 jb_send_raw("</stream:stream>");
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
141 /*
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
142 // Free status message
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
143 g_free(mystatusmsg);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
144 mystatusmsg = NULL;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
145 */
668
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
146 }
634
f3c05d5fe459 Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 633
diff changeset
147
f3c05d5fe459 Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 633
diff changeset
148 // Announce it to the user
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
149 statehandler(jc, JCONN_STATE_OFF);
416
48e7808c4191 Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents: 411
diff changeset
150
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
151 jab_delete(jc);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
152 jc = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
153 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
154
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
155 inline void jb_reset_keepalive()
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
156 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
157 time(&LastPingTime);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
158 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
159
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
160 void jb_send_raw(const char *str)
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
161 {
461
1d8f5b3a5f2b Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
162 if (jc && online && str)
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
163 jab_send_raw(jc, str);
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
164 }
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
165
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
166 void jb_keepalive()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
167 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
168 if (jc && online)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
169 jab_send_raw(jc, " \t ");
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
170 jb_reset_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
171 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
172
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
173 void jb_set_keepalive_delay(unsigned int delay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
174 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
175 KeepaliveDelay = delay;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
176 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
177
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
178 // check_connection()
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
179 // Check if we've been disconnected for a while (predefined timeout),
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
180 // and if so try to reconnect.
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
181 static void check_connection(void)
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
182 {
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
183 static time_t disconnection_timestamp = 0L;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
184 time_t now;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
185
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
186 // Maybe we're voluntarily offline...
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
187 if (!AutoConnection)
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
188 return;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
189
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
190 // Are we totally disconnected?
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
191 if (jc && jc->state != JCONN_STATE_OFF) {
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
192 disconnection_timestamp = 0L;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
193 return;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
194 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
195
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
196 time(&now);
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
197 if (!disconnection_timestamp) {
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
198 disconnection_timestamp = now;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
199 return;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
200 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
201
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
202 // If the reconnection_timeout is reached, try to reconnect.
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
203 if (now > disconnection_timestamp + RECONNECTION_TIMEOUT) {
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
204 mcabber_connect();
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
205 disconnection_timestamp = 0L;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
206 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
207 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
208
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
209 void jb_main()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
210 {
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
211 time_t now;
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
212 fd_set fds;
991
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
213 long timeout;
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
214 struct timeval tv;
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
215 static time_t last_eviqs_check = 0L;
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
216
406
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
217 if (!online) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
218 safe_usleep(10000);
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
219 check_connection();
406
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
220 return;
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
221 }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
222
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
223 if (jc && jc->state == JCONN_STATE_CONNECTING) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
224 safe_usleep(75000);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
225 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
226 return;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
227 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
228
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
229 FD_ZERO(&fds);
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
230 FD_SET(0, &fds);
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
231 FD_SET(jc->fd, &fds);
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
232
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
233 tv.tv_sec = 60;
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
234 tv.tv_usec = 0;
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
235
940
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
236 time(&now);
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
237
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
238 if (KeepaliveDelay) {
940
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
239 if (now >= LastPingTime + (time_t)KeepaliveDelay) {
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
240 tv.tv_sec = 0;
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
241 } else {
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
242 tv.tv_sec = LastPingTime + (time_t)KeepaliveDelay - now;
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
243 }
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
244 }
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
245
991
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
246 // Check auto-away timeout
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
247 timeout = scr_GetAutoAwayTimeout(now);
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
248 if (tv.tv_sec > timeout) {
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
249 tv.tv_sec = timeout;
940
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
250 }
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
251
991
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
252 #if defined JEP0022 || defined JEP0085
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
253 // Check composing timeout
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
254 timeout = scr_GetChatStatesTimeout(now);
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
255 if (tv.tv_sec > timeout) {
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
256 tv.tv_sec = timeout;
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
257 }
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
258 #endif
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
259
940
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
260 if (!tv.tv_sec)
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
261 tv.tv_usec = 350000;
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
262
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
263 scr_DoUpdate();
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
264 if (select(jc->fd + 1, &fds, NULL, NULL, &tv) > 0) {
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
265 if (FD_ISSET(jc->fd, &fds))
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
266 jab_poll(jc, 0);
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
267 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
268
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
269 if (jstate == STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
270 if (jc) {
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
271 eviqs *iqn;
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
272 xmlnode z;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
273
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
274 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
275 iqn->callback = &iqscallback_auth;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
276
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
277 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
278 "username");
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
279 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
280 jab_send(jc, iqn->xmldata);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
281
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
282 jstate = STATE_GETAUTH;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
283 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
284
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
285 if (!jc || jc->state == JCONN_STATE_OFF) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
286 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
287 online = FALSE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
288 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
289 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
290
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
291 if (!jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
292 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
293 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
294 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
295 }
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
296
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
297 time(&now);
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
298
756
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
299 // Check for EV & IQ requests timeouts
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
300 if (now > last_eviqs_check + 20) {
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
301 iqs_check_timeout(now);
756
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
302 evs_check_timeout(now);
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
303 last_eviqs_check = now;
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
304 }
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
305
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
306 // Keepalive
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
307 if (KeepaliveDelay) {
735
2f027806cd48 Some code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 732
diff changeset
308 if (now > LastPingTime + (time_t)KeepaliveDelay)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
309 jb_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
310 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
311 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
312
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
313 inline enum imstatus jb_getstatus()
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
314 {
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
315 return mystatus;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
316 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
317
519
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
318 inline const char *jb_getstatusmsg()
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
319 {
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
320 return mystatusmsg;
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
321 }
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
322
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
323 static void roompresence(gpointer room, void *presencedata)
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
324 {
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
325 const char *jid;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
326 const char *nickname;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
327 char *to;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
328 struct T_presence *pres = presencedata;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
329
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 651
diff changeset
330 if (!buddy_getinsideroom(room))
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
331 return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
332
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
333 jid = buddy_getjid(room);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
334 if (!jid) return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
335 nickname = buddy_getnickname(room);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
336 if (!nickname) return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
337
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
338 to = g_strdup_printf("%s/%s", jid, nickname);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
339 jb_setstatus(pres->st, to, pres->msg);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
340 g_free(to);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
341 }
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
342
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
343 // presnew(status, recipient, message)
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
344 // Create an xmlnode with default presence attributes
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
345 // Note: the caller must free the node after use
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
346 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
347 const char *msg)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
348 {
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
349 unsigned int prio;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
350 xmlnode x;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
351
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
352 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
353
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
354 if (recipient) {
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
355 xmlnode_put_attrib(x, "to", recipient);
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
356 }
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
357
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
358 switch(st) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
359 case away:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
360 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
361 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
362 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
363
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
364 case dontdisturb:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
365 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
366 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
367 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
368
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
369 case freeforchat:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
370 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
371 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
372 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
373
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
374 case notavail:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
375 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa",
547
1df26ff0ed8c Break packethandler() out
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
376 (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
377 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
378
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
379 case invisible:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
380 xmlnode_put_attrib(x, "type", "invisible");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
381 break;
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
382
118
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
383 case offline:
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
384 xmlnode_put_attrib(x, "type", "unavailable");
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
385 break;
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
386
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
387 default:
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
388 break;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
389 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
390
531
aee9a279a0f3 Allow changing priority on the fly
Mikael Berthe <mikael@lilotux.net>
parents: 527
diff changeset
391 prio = settings_opt_get_int("priority");
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
392 if (prio) {
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
393 char strprio[8];
842
f74c5c6d2c24 Fix negative priority
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
394 snprintf(strprio, 8, "%d", (int)prio);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
395 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
396 strprio, (unsigned) -1);
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
397 }
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
398
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
399 if (msg)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
400 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg, (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
401
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
402 return x;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
403 }
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
404
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
405 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg)
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
406 {
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
407 xmlnode x;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
408
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
409 if (msg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
410 // 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
411 // "-" which is a special case (option meaning "no status message").
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
412 if (!strcmp(msg, "-"))
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
413 msg = "";
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
414 } else {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
415 // No status message specified; we'll use:
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
416 // a) the default status message (if provided by the user);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
417 // b) the current status message;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
418 // c) no status message (i.e. an empty one).
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
419 msg = settings_get_status_msg(st);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
420 if (!msg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
421 if (mystatusmsg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
422 msg = mystatusmsg;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
423 else
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
424 msg = "";
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
425 }
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
426 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
427
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
428 // Only send the packet if we're online.
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
429 // (But we want to update internal status even when disconnected,
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
430 // in order to avoid some problems during network failures)
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
431 if (online) {
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
432 x = presnew(st, recipient, (st != invisible ? msg : NULL));
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
433 jab_send(jc, x);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
434 xmlnode_free(x);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
435 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
436
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
437 // 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
438 if (recipient) return;
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
439
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
440 if (online) {
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
441 // Send presence to chatrooms
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
442 if (st != invisible) {
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
443 struct T_presence room_presence;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
444 room_presence.st = st;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
445 room_presence.msg = msg;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
446 foreach_buddy(ROSTER_TYPE_ROOM, &roompresence, &room_presence);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
447 }
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
448 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
449
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
450 if (online) {
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
451 // We'll need to update the roster if we switch to/from offline because
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
452 // we don't know the presences of buddies when offline...
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
453 if (mystatus == offline || st == offline)
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
454 update_roster = TRUE;
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
455
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
456 hk_mystatuschange(0, mystatus, st, (st != invisible ? msg : ""));
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
457 mystatus = st;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
458 }
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
459 if (st)
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
460 mywantedstatus = st;
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
461 if (msg != mystatusmsg) {
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
462 g_free(mystatusmsg);
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
463 if (*msg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
464 mystatusmsg = g_strdup(msg);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
465 else
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
466 mystatusmsg = NULL;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
467 }
713
b5aa7b7afee8 Update status lines
Mikael Berthe <mikael@lilotux.net>
parents: 706
diff changeset
468
b5aa7b7afee8 Update status lines
Mikael Berthe <mikael@lilotux.net>
parents: 706
diff changeset
469 // Update status line
724
264375fe7159 Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents: 721
diff changeset
470 scr_UpdateMainStatus(TRUE);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
471 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
472
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
473 // jb_setprevstatus()
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
474 // Set previous status. This wrapper function is used after a disconnection.
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
475 inline void jb_setprevstatus(void)
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
476 {
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
477 jb_setstatus(mywantedstatus, NULL, mystatusmsg);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
478 }
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
479
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
480 // new_msgid()
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
481 // Generate a new id string. The caller should free it.
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
482 static char *new_msgid(void)
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
483 {
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
484 static guint msg_idn;
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
485 time_t now;
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
486 time(&now);
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
487 if (!msg_idn)
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
488 srand(now);
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
489 msg_idn += 1U + (unsigned int) (9.0 * (rand() / (RAND_MAX + 1.0)));
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
490 return g_strdup_printf("%u%d", msg_idn, (int)(now%10L));
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
491 }
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
492
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
493 void jb_send_msg(const char *jid, const char *text, int type,
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
494 const char *subject, const char *msgid)
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
495 {
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
496 xmlnode x;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
497 gchar *strtype;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
498 #if defined JEP0022 || defined JEP0085
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
499 xmlnode event;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
500 char *rname, *barejid;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
501 GSList *sl_buddy;
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
502 guint use_jep85 = 0;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
503 struct jep0085 *jep85 = NULL;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
504 #endif
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
505
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
506 if (!online) return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
507
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
508 if (type == ROSTER_TYPE_ROOM)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
509 strtype = TMSG_GROUPCHAT;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
510 else
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
511 strtype = TMSG_CHAT;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
512
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
513 x = jutil_msgnew(strtype, (char*)jid, NULL, (char*)text);
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
514 if (subject) {
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
515 xmlnode y;
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
516 y = xmlnode_insert_tag(x, "subject");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
517 xmlnode_insert_cdata(y, subject, (unsigned) -1);
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
518 }
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
519
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
520 #if defined JEP0022 || defined JEP0085
993
0759f4c7da68 Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents: 992
diff changeset
521 // If typing notifications are disabled, we can skip all this stuff...
998
f984baa9a789 Do not use JEP-22 in MUC rooms
Mikael Berthe <mikael@lilotux.net>
parents: 997
diff changeset
522 if (chatstates_disabled || type == ROSTER_TYPE_ROOM)
993
0759f4c7da68 Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents: 992
diff changeset
523 goto jb_send_msg_no_chatstates;
0759f4c7da68 Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents: 992
diff changeset
524
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
525 rname = strchr(jid, JID_RESOURCE_SEPARATOR);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
526 barejid = jidtodisp(jid);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
527 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
528 g_free(barejid);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
529
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
530 // If we can get a resource name, we use it. Else we use NULL,
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
531 // which hopefully will give us the most likely resource.
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
532 if (rname)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
533 rname++;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
534 if (sl_buddy)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
535 jep85 = buddy_resource_jep85(sl_buddy->data, rname);
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
536 #endif
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
537
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
538 #ifdef JEP0085
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
539 /* JEP-0085 5.1
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
540 * "Until receiving a reply to the initial content message (or a standalone
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
541 * notification) from the Contact, the User MUST NOT send subsequent chat
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
542 * state notifications to the Contact."
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
543 * In our implementation support is initially "unknown", they it's "probed"
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
544 * and can become "ok".
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
545 */
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
546 if (jep85 && (jep85->support == CHATSTATES_SUPPORT_OK ||
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
547 jep85->support == CHATSTATES_SUPPORT_UNKNOWN)) {
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
548 event = xmlnode_insert_tag(x, "active");
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
549 xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
550 if (jep85->support == CHATSTATES_SUPPORT_UNKNOWN)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
551 jep85->support = CHATSTATES_SUPPORT_PROBED;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
552 else
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
553 use_jep85 = 1;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
554 jep85->last_state_sent = ROSTER_EVENT_ACTIVE;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
555 }
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
556 #endif
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
557 #ifdef JEP0022
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
558 /* JEP-22
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
559 * If the Contact supports JEP-0085, we do not use JEP-0022.
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
560 * If not, we try to fall back to JEP-0022.
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
561 */
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
562 if (!use_jep85) {
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
563 struct jep0022 *jep22 = NULL;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
564 event = xmlnode_insert_tag(x, "x");
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
565 xmlnode_put_attrib(event, "xmlns", NS_EVENT);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
566 xmlnode_insert_tag(event, "composing");
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
567
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
568 if (sl_buddy)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
569 jep22 = buddy_resource_jep22(sl_buddy->data, rname);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
570 if (jep22)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
571 jep22->last_state_sent = ROSTER_EVENT_ACTIVE;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
572
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
573 // An id is mandatory when using JEP-0022.
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
574 if (!msgid && (text || subject)) {
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
575 msgid = new_msgid();
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
576 // Let's update last_msgid_sent
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
577 // (We do not update it when the msgid is provided by the caller,
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
578 // because this is probably a special message...)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
579 if (jep22) {
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
580 g_free(jep22->last_msgid_sent);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
581 jep22->last_msgid_sent = g_strdup(msgid);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
582 }
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
583 }
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
584 }
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
585 #endif
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
586
993
0759f4c7da68 Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents: 992
diff changeset
587 jb_send_msg_no_chatstates:
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
588 xmlnode_put_attrib(x, "id", msgid);
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
589
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
590 jab_send(jc, x);
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
591 xmlnode_free(x);
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
592
114
065d8368c36b [/trunk] Changeset 128 by mikael
mikael
parents: 113
diff changeset
593 jb_reset_keepalive();
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
594 }
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
595
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
596
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
597 #ifdef JEP0085
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
598 // jb_send_jep85_chatstate()
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
599 // Send a JEP-85 chatstate.
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
600 static void jb_send_jep85_chatstate(const char *jid, guint state)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
601 {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
602 xmlnode x;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
603 xmlnode event;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
604 char *rname, *barejid;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
605 GSList *sl_buddy;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
606 const char *chattag;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
607 struct jep0085 *jep85 = NULL;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
608
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
609 if (!online) return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
610
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
611 rname = strchr(jid, JID_RESOURCE_SEPARATOR);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
612 barejid = jidtodisp(jid);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
613 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
614 g_free(barejid);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
615
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
616 // If we can get a resource name, we use it. Else we use NULL,
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
617 // which hopefully will give us the most likely resource.
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
618 if (rname)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
619 rname++;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
620 if (sl_buddy)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
621 jep85 = buddy_resource_jep85(sl_buddy->data, rname);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
622
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
623 if (!jep85 || (jep85->support != CHATSTATES_SUPPORT_OK))
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
624 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
625
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
626 if (state == jep85->last_state_sent)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
627 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
628
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
629 if (state == ROSTER_EVENT_ACTIVE)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
630 chattag = "active";
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
631 else if (state == ROSTER_EVENT_COMPOSING)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
632 chattag = "composing";
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
633 else if (state == ROSTER_EVENT_PAUSED)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
634 chattag = "paused";
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
635 else {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
636 scr_LogPrint(LPRINT_LOGNORM, "Error: unsupported JEP-85 state (%d)", state);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
637 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
638 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
639
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
640 jep85->last_state_sent = state;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
641
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
642 x = jutil_msgnew(TMSG_CHAT, (char*)jid, NULL, NULL);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
643
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
644 event = xmlnode_insert_tag(x, chattag);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
645 xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
646
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
647 jab_send(jc, x);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
648 xmlnode_free(x);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
649
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
650 jb_reset_keepalive();
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
651 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
652 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
653
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
654 #ifdef JEP0022
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
655 // jb_send_jep22_event()
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
656 // Send a JEP-22 message event (delivered, composing...).
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
657 static void jb_send_jep22_event(const char *jid, guint type)
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
658 {
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
659 xmlnode x;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
660 xmlnode event;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
661 const char *msgid;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
662 char *rname, *barejid;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
663 GSList *sl_buddy;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
664 struct jep0022 *jep22 = NULL;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
665 guint jep22_state;
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
666
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
667 if (!online) return;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
668
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
669 rname = strchr(jid, JID_RESOURCE_SEPARATOR);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
670 barejid = jidtodisp(jid);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
671 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
672 g_free(barejid);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
673
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
674 // If we can get a resource name, we use it. Else we use NULL,
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
675 // which hopefully will give us the most likely resource.
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
676 if (rname)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
677 rname++;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
678 if (sl_buddy)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
679 jep22 = buddy_resource_jep22(sl_buddy->data, rname);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
680
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
681 if (!jep22)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
682 return; // XXX Maybe we could try harder (other resources?)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
683
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
684 msgid = jep22->last_msgid_rcvd;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
685
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
686 // For composing events (composing, active, inactive, paused...),
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
687 // JEP22 only has 2 states; we'll use composing and active.
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
688 if (type == ROSTER_EVENT_COMPOSING)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
689 jep22_state = ROSTER_EVENT_COMPOSING;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
690 else if (type == ROSTER_EVENT_ACTIVE ||
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
691 type == ROSTER_EVENT_PAUSED)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
692 jep22_state = ROSTER_EVENT_ACTIVE;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
693 else
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
694 jep22_state = 0; // ROSTER_EVENT_NONE
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
695
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
696 if (jep22_state) {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
697 // Do not re-send a same event
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
698 if (jep22_state == jep22->last_state_sent)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
699 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
700 jep22->last_state_sent = jep22_state;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
701 }
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
702
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
703 x = jutil_msgnew(TMSG_CHAT, (char*)jid, NULL, NULL);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
704
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
705 event = xmlnode_insert_tag(x, "x");
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
706 xmlnode_put_attrib(event, "xmlns", NS_EVENT);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
707 if (type == ROSTER_EVENT_DELIVERED)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
708 xmlnode_insert_tag(event, "delivered");
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
709 else if (type == ROSTER_EVENT_COMPOSING)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
710 xmlnode_insert_tag(event, "composing");
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
711 xmlnode_put_attrib(event, "id", msgid);
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
712
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
713 jab_send(jc, x);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
714 xmlnode_free(x);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
715
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
716 jb_reset_keepalive();
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
717 }
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
718 #endif
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
719
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
720 // jb_send_chatstate(buddy, state)
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
721 // Send a chatstate or event (JEP-22/85) according to the buddy's capabilities.
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
722 // The message is sent to one of the resources with the highest priority.
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
723 #if defined JEP0022 || defined JEP0085
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
724 void jb_send_chatstate(gpointer buddy, guint chatstate)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
725 {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
726 const char *jid;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
727 struct jep0085 *jep85 = NULL;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
728 struct jep0022 *jep22 = NULL;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
729
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
730 jid = buddy_getjid(buddy);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
731 if (!jid) return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
732
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
733 #ifdef JEP0085
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
734 jep85 = buddy_resource_jep85(buddy, NULL);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
735 if (jep85 && jep85->support == CHATSTATES_SUPPORT_OK) {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
736 jb_send_jep85_chatstate(jid, chatstate);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
737 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
738 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
739 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
740 #ifdef JEP0022
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
741 jep22 = buddy_resource_jep22(buddy, NULL);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
742 if (jep22 && jep22->support == CHATSTATES_SUPPORT_OK) {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
743 jb_send_jep22_event(jid, chatstate);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
744 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
745 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
746 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
747 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
748
999
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
749 // chatstates_reset_probed(fulljid)
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
750 // If the JEP has been probed for this contact, set it back to unknown so
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
751 // that we probe it again. The parameter must be a full jid (w/ resource).
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
752 #if defined JEP0022 || defined JEP0085
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
753 static void chatstates_reset_probed(const char *fulljid)
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
754 {
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
755 char *rname, *barejid;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
756 GSList *sl_buddy;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
757 struct jep0085 *jep85;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
758 struct jep0022 *jep22;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
759
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
760 rname = strchr(fulljid, JID_RESOURCE_SEPARATOR);
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
761 if (!rname++)
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
762 return;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
763
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
764 barejid = jidtodisp(fulljid);
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
765 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
766 g_free(barejid);
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
767
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
768 if (!sl_buddy)
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
769 return;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
770
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
771 jep85 = buddy_resource_jep85(sl_buddy->data, rname);
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
772 jep22 = buddy_resource_jep22(sl_buddy->data, rname);
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
773
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
774 if (jep85 && jep85->support == CHATSTATES_SUPPORT_PROBED)
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
775 jep85->support = CHATSTATES_SUPPORT_UNKNOWN;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
776 if (jep22 && jep22->support == CHATSTATES_SUPPORT_PROBED)
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
777 jep22->support = CHATSTATES_SUPPORT_UNKNOWN;
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
778 }
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
779 #endif
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
780
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
781 // jb_subscr_send_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
782 // Allow jid to receive our presence updates
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
783 void jb_subscr_send_auth(const char *jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
784 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
785 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
786
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
787 x = jutil_presnew(JPACKET__SUBSCRIBED, (char *)jid, NULL);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
788 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
789 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
790 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
791
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
792 // jb_subscr_cancel_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
793 // Cancel jid's subscription to our presence updates
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
794 void jb_subscr_cancel_auth(const char *jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
795 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
796 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
797
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
798 x = jutil_presnew(JPACKET__UNSUBSCRIBED, (char *)jid, NULL);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
799 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
800 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
801 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
802
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
803 // jb_subscr_request_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
804 // Request a subscription to jid's presence updates
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
805 void jb_subscr_request_auth(const char *jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
806 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
807 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
808
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
809 x = jutil_presnew(JPACKET__SUBSCRIBE, (char *)jid, NULL);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
810 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
811 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
812 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
813
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
814 // jb_subscr_request_cancel(jid)
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
815 // Request to cancel jour subscription to jid's presence updates
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
816 void jb_subscr_request_cancel(const char *jid)
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
817 {
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
818 xmlnode x;
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
819
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
820 x = jutil_presnew(JPACKET__UNSUBSCRIBE, (char *)jid, NULL);
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
821 jab_send(jc, x);
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
822 xmlnode_free(x);
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
823 }
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
824
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
825 // Note: the caller should check the jid is correct
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
826 void jb_addbuddy(const char *jid, const char *name, const char *group)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
827 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
828 xmlnode y, z;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
829 eviqs *iqn;
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
830 char *cleanjid;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
831
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
832 if (!online) return;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
833
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
834 cleanjid = jidtodisp(jid);
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
835
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
836 // We don't check if the jabber user already exists in the roster,
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
837 // because it allows to re-ask for notification.
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
838
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
839 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
840 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
841
454399f026fa Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
842 xmlnode_put_attrib(y, "jid", cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
843
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
844 if (name)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
845 xmlnode_put_attrib(y, "name", name);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
846
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
847 if (group) {
628
454399f026fa Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
848 z = xmlnode_insert_tag(y, "group");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
849 xmlnode_insert_cdata(z, group, (unsigned) -1);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
850 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
851
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
852 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
853 iqs_del(iqn->id); // XXX
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
854
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
855 jb_subscr_request_auth(cleanjid);
612
789ec6aed764 Respect RFC 3921 order advice
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
856
603
9516db839e08 Store subscription data
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
857 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
858 g_free(cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
859 buddylist_build();
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
860
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
861 update_roster = TRUE;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
862 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
863
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
864 void jb_delbuddy(const char *jid)
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
865 {
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
866 xmlnode y, z;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
867 eviqs *iqn;
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
868 char *cleanjid;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
869
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
870 if (!online) return;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
871
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
872 cleanjid = jidtodisp(jid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
873
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
874 // If the current buddy is an agent, unsubscribe from it
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
875 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
876 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
877
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
878 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
879 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
880 y = xmlnode_get_tag(iqn->xmldata, "query");
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
881 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
882 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
883 iqs_del(iqn->id); // XXX
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
884 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
885
611
ad737139a144 Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
886 // Cancel the subscriptions
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
887 jb_subscr_cancel_auth(cleanjid); // Cancel "from"
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
888 jb_subscr_request_cancel(cleanjid); // Cancel "to"
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
889
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
890 // 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
891 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
892 y = xmlnode_get_tag(iqn->xmldata, "query");
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
893 z = xmlnode_insert_tag(y, "item");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
894 xmlnode_put_attrib(z, "jid", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
895 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
896 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
897 iqs_del(iqn->id); // XXX
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
898
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
899 roster_del_user(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
900 g_free(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
901 buddylist_build();
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
902
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
903 update_roster = TRUE;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
904 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
905
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
906 void jb_updatebuddy(const char *jid, const char *name, const char *group)
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
907 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
908 xmlnode y;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
909 eviqs *iqn;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
910 char *cleanjid;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
911
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
912 if (!online) return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
913
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
914 // XXX We should check name's and group's correctness
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
915
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
916 cleanjid = jidtodisp(jid);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
917
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
918 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
919 y = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item");
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
920 xmlnode_put_attrib(y, "jid", cleanjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
921 xmlnode_put_attrib(y, "name", name);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
922
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
923 if (group) {
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
924 y = xmlnode_insert_tag(y, "group");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
925 xmlnode_insert_cdata(y, group, (unsigned) -1);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
926 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
927
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
928 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
929 iqs_del(iqn->id); // XXX
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
930 g_free(cleanjid);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
931 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
932
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
933 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
934 {
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
935 GSList *resources;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
936 GSList *roster_elt;
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
937 void (*request_fn)(const char *);
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
938 const char *strreqtype;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
939
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
940 if (reqtype == iqreq_version) {
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
941 request_fn = &request_version;
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
942 strreqtype = "version";
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
943 } else if (reqtype == iqreq_time) {
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
944 request_fn = &request_time;
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
945 strreqtype = "time";
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
946 } else if (reqtype == iqreq_last) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
947 request_fn = &request_last;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
948 strreqtype = "last";
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
949 } else if (reqtype == iqreq_vcard) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
950 // Special case
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
951 } else
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
952 return;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
953
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
954 // vCard request
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
955 if (reqtype == iqreq_vcard) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
956 char *bjid = jidtodisp(jid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
957 request_vcard(bjid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
958 scr_LogPrint(LPRINT_NORMAL, "Sent vCard request to <%s>", bjid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
959 g_free(bjid);
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
960 return;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
961 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
962
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 960
diff changeset
963 if (strchr(jid, JID_RESOURCE_SEPARATOR)) {
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
964 // This is a full JID
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
965 (*request_fn)(jid);
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
966 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, jid);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
967 return;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
968 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
969
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
970 // The resource has not been specified
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
971 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
972 if (!roster_elt) {
695
c299035ccb9f Fix up jb_request(), when the resource is unknown
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
973 scr_LogPrint(LPRINT_NORMAL, "No known resource for <%s>...", jid);
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
974 (*request_fn)(jid); // Let's send a request anyway...
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
975 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, jid);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
976 return;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
977 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
978
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
979 // Send a request to each resource
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
980 resources = buddy_getresources(roster_elt->data);
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
981 if (!resources) {
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
982 scr_LogPrint(LPRINT_NORMAL, "No known resource for <%s>...", jid);
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
983 (*request_fn)(jid); // Let's send a request anyway...
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
984 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, jid);
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
985 }
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
986 for ( ; resources ; resources = g_slist_next(resources) ) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
987 gchar *fulljid;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
988 fulljid = g_strdup_printf("%s/%s", jid, (char*)resources->data);
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
989 (*request_fn)(fulljid);
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
990 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fulljid);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
991 g_free(fulljid);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
992 }
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
993 }
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
994
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
995 // Join a MUC room
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 896
diff changeset
996 void jb_room_join(const char *room, const char *nickname, const char *passwd)
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
997 {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
998 xmlnode x, y;
643
dd73c3dad815 Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 642
diff changeset
999 gchar *roomid;
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1000 GSList *room_elt;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1001
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
1002 if (!online || !room) return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
1003 if (!nickname) return;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1004
643
dd73c3dad815 Fix double UTF-8 encoding when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 642
diff changeset
1005 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
1006 if (check_jid_syntax(roomid)) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1007 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
1008 nickname);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1009 g_free(roomid);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1010 return;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1011 }
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1012
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1013 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
1014 // 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
1015 if (!room_elt) {
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1016 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
1017 } else {
3ad6675caaf1 MUC: fix join bug when the conference is in the roster
Mikael Berthe <mikael@lilotux.net>
parents: 645
diff changeset
1018 // 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
1019 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
1020 }
644
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1021 // 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
1022 if (!buddy_getinsideroom(room_elt->data)) {
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1023 // 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
1024 buddy_setnickname(room_elt->data, nickname);
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1025 }
68fb0c1dfb15 MUC: better nickname check when entering a room
Mikael Berthe <mikael@lilotux.net>
parents: 643
diff changeset
1026
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1027 // Send the XML request
535
b407d19c39ab Set status correctly when joining a room
Mikael Berthe <mikael@lilotux.net>
parents: 534
diff changeset
1028 x = presnew(mystatus, roomid, mystatusmsg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1029 y = xmlnode_insert_tag(x, "x");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1030 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc");
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 896
diff changeset
1031 if (passwd) {
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 896
diff changeset
1032 xmlnode_insert_cdata(xmlnode_insert_tag(y, "password"), passwd,
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 896
diff changeset
1033 (unsigned) -1);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 896
diff changeset
1034 }
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1035
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1036 jab_send(jc, x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1037 xmlnode_free(x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1038 jb_reset_keepalive();
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1039 g_free(roomid);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1040 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1041
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1042 // Unlock a MUC room
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1043 // room syntax: "room@server"
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1044 void jb_room_unlock(const char *room)
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1045 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1046 xmlnode y, z;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
1047 eviqs *iqn;
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1048
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
1049 if (!online || !room) return;
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1050
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1051 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
1052 "unlock", IQS_DEFAULT_TIMEOUT);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1053 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
1054 y = xmlnode_get_tag(iqn->xmldata, "query");
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1055 z = xmlnode_insert_tag(y, "x");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1056 xmlnode_put_attrib(z, "xmlns", "jabber:x:data");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1057 xmlnode_put_attrib(z, "type", "submit");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1058
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1059 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1060 iqs_del(iqn->id); // XXX
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1061 jb_reset_keepalive();
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1062 }
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
1063
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1064 // Destroy a MUC room
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1065 // room syntax: "room@server"
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1066 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
1067 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1068 xmlnode y, z;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
1069 eviqs *iqn;
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1070
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1071 if (!online || !room) return;
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1072
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1073 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
1074 "destroy", IQS_DEFAULT_TIMEOUT);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1075 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
1076 y = xmlnode_get_tag(iqn->xmldata, "query");
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1077 z = xmlnode_insert_tag(y, "destroy");
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1078
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1079 if (venue && *venue)
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1080 xmlnode_put_attrib(z, "jid", venue);
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1081
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1082 if (reason) {
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1083 y = xmlnode_insert_tag(z, "reason");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1084 xmlnode_insert_cdata(y, reason, (unsigned) -1);
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1085 }
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1086
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1087 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1088 iqs_del(iqn->id); // XXX
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1089 jb_reset_keepalive();
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1090 }
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
1091
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1092 // Change role or affiliation of a MUC user
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1093 // room syntax: "room@server"
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1094 // 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
1095 // allowed)
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1096 // ra: new role or affiliation
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1097 // (ex. role none for kick, affil outcast for ban...)
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1098 // The reason can be null
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1099 // Return 0 if everything is ok
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1100 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
1101 struct role_affil ra, const char *reason)
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1102 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1103 xmlnode y, z;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
1104 eviqs *iqn;
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1105
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1106 if (!online || !roomid) return 1;
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1107 if (!jid && !nick) return 1;
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1108
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1109 if (check_jid_syntax((char*)roomid)) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1110 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
1111 return 1;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1112 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1113 if (jid && check_jid_syntax((char*)jid)) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1114 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
1115 return 1;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1116 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1117
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1118 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
1119 return 1; // Shouldn't happen (jid mandatory when banning)
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1120
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1121 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
1122 "roleaffil", IQS_DEFAULT_TIMEOUT);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1123 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
1124 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
1125 y = xmlnode_get_tag(iqn->xmldata, "query");
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1126 z = xmlnode_insert_tag(y, "item");
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1127
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1128 if (jid) {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1129 xmlnode_put_attrib(z, "jid", jid);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1130 } else { // nickname
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1131 xmlnode_put_attrib(z, "nick", nick);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1132 }
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1133
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1134 if (ra.type == type_affil)
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1135 xmlnode_put_attrib(z, "affiliation", straffil[ra.val.affil]);
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1136 else if (ra.type == type_role)
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 583
diff changeset
1137 xmlnode_put_attrib(z, "role", strrole[ra.val.role]);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1138
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1139 if (reason) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1140 y = xmlnode_insert_tag(z, "reason");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1141 xmlnode_insert_cdata(y, reason, (unsigned) -1);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1142 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1143
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1144 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1145 iqs_del(iqn->id); // XXX
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1146 jb_reset_keepalive();
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1147
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1148 return 0;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 562
diff changeset
1149 }
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1150
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1151 // Invite a user to a MUC room
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1152 // room syntax: "room@server"
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1153 // reason can be null.
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1154 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
1155 {
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1156 xmlnode x, y, z;
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1157
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1158 if (!online || !room || !jid) return;
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1159
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1160 x = jutil_msgnew(NULL, (char*)room, NULL, NULL);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1161
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1162 y = xmlnode_insert_tag(x, "x");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1163 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1164
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1165 z = xmlnode_insert_tag(y, "invite");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1166 xmlnode_put_attrib(z, "to", jid);
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1167
569
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
1168 if (reason) {
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
1169 y = xmlnode_insert_tag(z, "reason");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1170 xmlnode_insert_cdata(y, reason, (unsigned) -1);
569
69afee8e1232 "/room invite": Do not send epty reason
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
1171 }
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1172
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
1173 jab_send(jc, x);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478