annotate mcabber/src/jabglue.c @ 1484:7b36b91a4388

New UI message flag (O) when OTR is used When PGP is used, the flag is still '~'. When OTR is used (and PGP is not), the encryption flag is 'O'.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 20 Apr 2008 14:30:25 +0200
parents 77afd831f8f7
children 1ae5fb9b04ca
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 *
1414
366ef500c522 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1413
diff changeset
4 * Copyright (C) 2005-2008 Mikael Berthe <mikael@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"
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
35 #include "pgp.h"
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
36 #include "otr.h"
1448
844410b9b4cc Remove configure option --enable-fifo
Mikael Berthe <mikael@lilotux.net>
parents: 1446
diff changeset
37 #include "fifo.h"
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
38
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
39 #define JABBERPORT 5222
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
40 #define JABBERSSLPORT 5223
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
41
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
42 #define RECONNECTION_TIMEOUT 60L
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
43
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
44 jconn jc;
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
45 guint AutoConnection;
578
b3ab662757a0 Fix connection issue
Mikael Berthe <mikael@lilotux.net>
parents: 577
diff changeset
46 enum enum_jstate jstate;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
47
353
3fe43f6daa5a Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
48 char imstatus2char[imstatus_size+1] = {
1311
0dda8238af21 Implement "/roster display"
Mikael Berthe <mikael@lilotux.net>
parents: 1310
diff changeset
49 '_', 'o', 'f', 'd', 'n', 'a', 'i', '\0'
46
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
50 };
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
51
1378
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
52 static char *imstatus_showmap[] = {
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
53 "",
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
54 "",
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
55 "chat",
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
56 "dnd",
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
57 "xa",
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
58 "away",
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
59 ""
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
60 };
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
61
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
62 static time_t LastPingTime;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
63 static unsigned int KeepaliveDelay;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
64 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
65 static enum imstatus mywantedstatus = available;
577
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
66 static gchar *mystatusmsg;
5c6d364130ee Move IQ Jabber stuff to a separate file
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
67 static unsigned char online;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
68
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
69 static void statehandler(jconn, int);
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
70 static void packethandler(jconn, jpacket);
1128
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
71 static void handle_state_events(char* from, xmlnode xmldata);
ac9c89f6cb51 Support for invitations to muc rooms
misc@mandriva.org
parents: 1104
diff changeset
72
1213
4a7db2870685 Improve Private Storage detection.
Mikael Berthe <mikael@lilotux.net>
parents: 1212
diff changeset
73 static int evscallback_invitation(eviqs *evp, guint evcontext);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
74
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
75
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
76 static void logger(jconn j, int io, const char *buf)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
77 {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
78 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
79 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
80
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
81 // jidtodisp(jid)
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
82 // Strips the resource part from the jid
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
83 // The caller should g_free the result after use.
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
84 char *jidtodisp(const char *fjid)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
85 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
86 char *ptr;
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
87 char *alias;
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
88
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
89 alias = g_strdup(fjid);
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
90
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 960
diff changeset
91 if ((ptr = strchr(alias, JID_RESOURCE_SEPARATOR)) != NULL) {
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
92 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
93 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
94 return alias;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
95 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
96
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
97 char *compose_jid(const char *username, const char *servername,
533
c478e8f7f074 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 532
diff changeset
98 const char *resource)
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
99 {
1383
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
100 char *fjid;
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
101
1385
7ca57f7e313c Fix typo in changeset d9606bd03144
Mikael Berthe <mikael@lilotux.net>
parents: 1384
diff changeset
102 if (!strchr(username, JID_DOMAIN_SEPARATOR)) {
1383
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
103 fjid = g_strdup_printf("%s%c%s%c%s", username,
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
104 JID_DOMAIN_SEPARATOR, servername,
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
105 JID_RESOURCE_SEPARATOR, resource);
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
106 } else {
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
107 fjid = g_strdup_printf("%s%c%s", username,
d9606bd03144 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1381
diff changeset
108 JID_RESOURCE_SEPARATOR, resource);
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
109 }
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
110 return fjid;
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
111 }
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
112
1413
f89844a0448a Remove useless inlines
Mikael Berthe <mikael@lilotux.net>
parents: 1399
diff changeset
113 unsigned char jb_getonline(void)
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
114 {
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
115 return online;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
116 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
117
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
118 jconn jb_connect(const char *fjid, const char *server, unsigned int port,
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
119 int ssl, const char *pass)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
120 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
121 if (!port) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
122 if (ssl)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
123 port = JABBERSSLPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
124 else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
125 port = JABBERPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
126 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
127
357
e8adc3c96e68 Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents: 353
diff changeset
128 jb_disconnect();
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
129
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
130 if (!fjid) return jc;
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
131
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
132 jc = jab_new((char*)fjid, (char*)pass, (char*)server, port, ssl);
29
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 /* 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
135 jab_logger(jc, logger);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
136 jab_packet_handler(jc, &packethandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
137 jab_state_handler(jc, &statehandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
138
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
139 if (jc && jc->user) {
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
140 online = TRUE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
141 jstate = STATE_CONNECTING;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
142 statehandler(0, -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
143 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
144 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
145
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
146 return jc;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
147 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
148
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
149 void jb_disconnect(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
150 {
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
151 if (!jc) return;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
152
668
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
153 if (online) {
1354
c373ff3fe7e1 Add pre-disconnect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1347
diff changeset
154 // Launch pre-disconnect internal hook
c373ff3fe7e1 Add pre-disconnect internal hook
Mikael Berthe <mikael@lilotux.net>
parents: 1347
diff changeset
155 hook_execute_internal("hook-pre-disconnect");
668
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
156 // Announce it to everyone else
1050
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1046
diff changeset
157 jb_setstatus(offline, NULL, "", FALSE);
668
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
158 // End the XML flow
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
159 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
160 /*
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
161 // Free status message
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
162 g_free(mystatusmsg);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
163 mystatusmsg = NULL;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
164 */
668
d0928694c81b Small jb_disconnect() improvement
Mikael Berthe <mikael@lilotux.net>
parents: 655
diff changeset
165 }
634
f3c05d5fe459 Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 633
diff changeset
166
f3c05d5fe459 Send "</stream:stream>" when disconnecting from the server
Mikael Berthe <mikael@lilotux.net>
parents: 633
diff changeset
167 // Announce it to the user
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
168 statehandler(jc, JCONN_STATE_OFF);
416
48e7808c4191 Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents: 411
diff changeset
169
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
170 jab_delete(jc);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
171 jc = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
172 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
173
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
174 inline void jb_reset_keepalive()
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
175 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
176 time(&LastPingTime);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
177 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
178
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
179 void jb_send_raw(const char *str)
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
180 {
461
1d8f5b3a5f2b Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
181 if (jc && online && str)
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
182 jab_send_raw(jc, str);
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
183 }
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
184
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
185 void jb_keepalive()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
186 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
187 if (jc && online)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
188 jab_send_raw(jc, " \t ");
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
189 jb_reset_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
190 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
191
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
192 void jb_set_keepalive_delay(unsigned int delay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
193 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
194 KeepaliveDelay = delay;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
195 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
196
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
197 // check_connection()
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
198 // 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
199 // and if so try to reconnect.
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
200 static void check_connection(void)
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 static time_t disconnection_timestamp = 0L;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
203 time_t now;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
204
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
205 // 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
206 if (!AutoConnection)
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
207 return;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
208
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
209 // Are we totally disconnected?
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
210 if (jc && jc->state != JCONN_STATE_OFF) {
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
211 disconnection_timestamp = 0L;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
212 return;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
213 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
214
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
215 time(&now);
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
216 if (!disconnection_timestamp) {
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
217 disconnection_timestamp = now;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
218 return;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
219 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
220
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
221 // 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
222 if (now > disconnection_timestamp + RECONNECTION_TIMEOUT) {
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
223 mcabber_connect();
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
224 disconnection_timestamp = 0L;
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
225 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
226 }
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
227
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
228 void jb_main()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
229 {
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
230 time_t now;
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
231 fd_set fds;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
232 long tmout;
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
233 struct timeval tv;
1001
dff25377c11f Auto-reconnect after a network/server failure
Mikael Berthe <mikael@lilotux.net>
parents: 999
diff changeset
234 static time_t last_eviqs_check = 0L;
1439
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
235 int maxfd = 0;
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
236 int fifofd;
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
237
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
238 FD_ZERO(&fds);
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
239 FD_SET(0, &fds);
1439
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
240 if (jc && jc->fd > 0) {
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
241 FD_SET(jc->fd, &fds);
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
242 maxfd = jc->fd;
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
243 }
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
244
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
245 fifofd = fifo_get_fd();
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
246 if (fifofd > 0) {
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
247 FD_SET(fifofd, &fds);
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
248 maxfd = MAX(maxfd, fifofd);
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
249 }
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
250
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
251 tv.tv_sec = 60;
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
252 tv.tv_usec = 0;
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
253
1439
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
254 if (!online || (jc && jc->state == JCONN_STATE_CONNECTING)) {
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
255 if (online) {
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
256 // We're connecting and we need to reduce the timeout.
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
257 tv.tv_sec = 0;
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
258 tv.tv_usec = 250000;
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
259 } else {
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
260 tv.tv_sec = 30;
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
261 // Let's first update the screen, we could sleep for a long time...
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
262 scr_DoUpdate();
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
263 }
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
264 // If we're not connected, sleep for a while...
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
265 select(maxfd + 1, &fds, NULL, NULL, &tv);
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
266 if (!online)
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
267 check_connection();
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
268 else
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
269 jab_start(jc);
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
270 return;
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
271 }
fd09c95bc2b5 Wake up less often when not connected to the server
Mikael Berthe <mikael@lilotux.net>
parents: 1435
diff changeset
272
940
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
273 time(&now);
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
274
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
275 if (KeepaliveDelay) {
1399
187985455020 Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents: 1397
diff changeset
276 if (now >= LastPingTime + (time_t)KeepaliveDelay)
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
277 tv.tv_sec = 0;
1399
187985455020 Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents: 1397
diff changeset
278 else
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
279 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
280 }
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
281
991
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
282 // Check auto-away timeout
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
283 tmout = scr_GetAutoAwayTimeout(now);
1399
187985455020 Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents: 1397
diff changeset
284 if (tv.tv_sec > tmout)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
285 tv.tv_sec = tmout;
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
286
991
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
287 #if defined JEP0022 || defined JEP0085
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
288 // Check composing timeout
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
289 tmout = scr_GetChatStatesTimeout(now);
1399
187985455020 Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents: 1397
diff changeset
290 if (tv.tv_sec > tmout)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
291 tv.tv_sec = tmout;
991
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
292 #endif
ef10906691bb Chatstates: add composing timeout
Mikael Berthe <mikael@lilotux.net>
parents: 990
diff changeset
293
940
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
294 if (!tv.tv_sec)
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
295 tv.tv_usec = 350000;
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
296
fc30221b952d Fix an autoaway problem
Mikael Berthe <mikael@lilotux.net>
parents: 939
diff changeset
297 scr_DoUpdate();
1426
a64778f5f26b Implement FIFO named command pipe
Mikael Berthe <mikael@lilotux.net>
parents: 1419
diff changeset
298 if (select(maxfd + 1, &fds, NULL, NULL, &tv) > 0) {
939
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
299 if (FD_ISSET(jc->fd, &fds))
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
300 jab_poll(jc, 0);
12fa2ae6445d Get rid of "busy-waiting" (Christof Meerwald)
Mikael Berthe <mikael@lilotux.net>
parents: 924
diff changeset
301 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
302
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
303 if (jstate == STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
304 if (jc) {
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
305 eviqs *iqn;
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
306 xmlnode z;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
307
686
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
308 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
309 iqn->callback = &iqscallback_auth;
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
310
98de2d166a11 Use the new IQ system for authentication
Mikael Berthe <mikael@lilotux.net>
parents: 684
diff changeset
311 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
312 "username");
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
313 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
314 jab_send(jc, iqn->xmldata);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
315
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
316 jstate = STATE_GETAUTH;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
317 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
318
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
319 if (!jc || jc->state == JCONN_STATE_OFF) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
320 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
321 online = FALSE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
322 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
323 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
324
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
325 if (!jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
326 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
327 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
328 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
329 }
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
330
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
331 time(&now);
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
332
756
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
333 // Check for EV & IQ requests timeouts
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
334 if (now > last_eviqs_check + 20) {
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
335 iqs_check_timeout(now);
756
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
336 evs_check_timeout(now);
12dc6bdff8c1 Check for events timeout
Mikael Berthe <mikael@lilotux.net>
parents: 754
diff changeset
337 last_eviqs_check = now;
706
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
338 }
934fddc99592 Check for IQ requests timeouts
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
339
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
340 // Keepalive
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
341 if (KeepaliveDelay) {
735
2f027806cd48 Some code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 732
diff changeset
342 if (now > LastPingTime + (time_t)KeepaliveDelay)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
343 jb_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
344 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
345 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
346
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
347 inline enum imstatus jb_getstatus()
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
348 {
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
349 return mystatus;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
350 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
351
519
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
352 inline const char *jb_getstatusmsg()
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
353 {
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
354 return mystatusmsg;
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
355 }
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 513
diff changeset
356
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
357 inline void update_last_use(void)
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
358 {
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
359 iqlast = time(NULL);
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
360 }
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
361
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
362 // insert_entity_capabilities(presence_stanza)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
363 // Entity Capabilities (XEP-0115)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
364 static void insert_entity_capabilities(xmlnode x)
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
365 {
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
366 xmlnode y;
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
367 const char *ver = entity_version();
1255
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
368 char *exts, *exts2;
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
369
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
370 exts = NULL;
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
371
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
372 y = xmlnode_insert_tag(x, "c");
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
373 xmlnode_put_attrib(y, "xmlns", NS_CAPS);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
374 xmlnode_put_attrib(y, "node", MCABBER_CAPS_NODE);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
375 xmlnode_put_attrib(y, "ver", ver);
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
376 #ifdef JEP0085
1255
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
377 if (!chatstates_disabled) {
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
378 exts2 = g_strjoin(" ", "csn", exts, NULL);
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
379 g_free(exts);
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
380 exts = exts2;
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
381 }
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
382 #endif
1255
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
383 if (!settings_opt_get_int("iq_last_disable")) {
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
384 exts2 = g_strjoin(" ", "iql", exts, NULL);
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
385 g_free(exts);
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
386 exts = exts2;
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
387 }
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
388 if (exts) {
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
389 xmlnode_put_attrib(y, "ext", exts);
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
390 g_free(exts);
ceada40bbe20 Update Entity Capabilities (add iq:last)
Mikael Berthe <mikael@lilotux.net>
parents: 1254
diff changeset
391 }
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
392 }
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
393
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
394 static void roompresence(gpointer room, void *presencedata)
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
395 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
396 const char *bjid;
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
397 const char *nickname;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
398 char *to;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
399 struct T_presence *pres = presencedata;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
400
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 651
diff changeset
401 if (!buddy_getinsideroom(room))
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
402 return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
403
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
404 bjid = buddy_getjid(room);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
405 if (!bjid) return;
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
406 nickname = buddy_getnickname(room);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
407 if (!nickname) return;
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
408
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
409 to = g_strdup_printf("%s/%s", bjid, nickname);
1050
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1046
diff changeset
410 jb_setstatus(pres->st, to, pres->msg, TRUE);
532
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
411 g_free(to);
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
412 }
2ac8d8e49e81 Send status changes to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 531
diff changeset
413
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
414 // presnew(status, recipient, message)
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
415 // Create an xmlnode with default presence attributes
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
416 // Note: the caller must free the node after use
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
417 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
418 const char *msg)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
419 {
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
420 unsigned int prio;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
421 xmlnode x;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
422
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
423 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
424
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
425 if (recipient) {
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
426 xmlnode_put_attrib(x, "to", recipient);
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
427 }
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
428
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
429 switch(st) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
430 case away:
1378
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
431 case notavail:
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
432 case dontdisturb:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
433 case freeforchat:
1378
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
434 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"),
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
435 imstatus_showmap[st], (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
436 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
437
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
438 case invisible:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
439 xmlnode_put_attrib(x, "type", "invisible");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
440 break;
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
441
118
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
442 case offline:
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
443 xmlnode_put_attrib(x, "type", "unavailable");
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
444 break;
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
445
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
446 default:
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
447 break;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
448 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
449
1419
fb438482b28e New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents: 1415
diff changeset
450 if (st == away || st == notavail)
fb438482b28e New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents: 1415
diff changeset
451 prio = settings_opt_get_int("priority_away");
fb438482b28e New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents: 1415
diff changeset
452 else
fb438482b28e New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents: 1415
diff changeset
453 prio = settings_opt_get_int("priority");
fb438482b28e New option to customize the away/notavail priority (Michael Gehring)
Mikael Berthe <mikael@lilotux.net>
parents: 1415
diff changeset
454
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
455 if (prio) {
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
456 char strprio[8];
842
f74c5c6d2c24 Fix negative priority
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
457 snprintf(strprio, 8, "%d", (int)prio);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
458 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
459 strprio, (unsigned) -1);
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
460 }
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
461
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
462 if (msg)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
463 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg, (unsigned) -1);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
464
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
465 return x;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
466 }
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
467
1050
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1046
diff changeset
468 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg,
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1046
diff changeset
469 int do_not_sign)
534
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
470 {
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
471 xmlnode x;
3569d38f7bbb Add presnew()
Mikael Berthe <mikael@lilotux.net>
parents: 533
diff changeset
472
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
473 if (msg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
474 // 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
475 // "-" which is a special case (option meaning "no status message").
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
476 if (!strcmp(msg, "-"))
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
477 msg = "";
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
478 } else {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
479 // No status message specified; we'll use:
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
480 // a) the default status message (if provided by the user);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
481 // b) the current status message;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
482 // c) no status message (i.e. an empty one).
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
483 msg = settings_get_status_msg(st);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
484 if (!msg) {
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
485 if (mystatusmsg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
486 msg = mystatusmsg;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
487 else
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
488 msg = "";
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
489 }
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
490 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
491
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
492 // 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
493 // (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
494 // 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
495 if (online) {
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
496 const char *s_msg = (st != invisible ? msg : NULL);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
497 x = presnew(st, recipient, s_msg);
1215
80c095886fb5 Entity Capabilities support (XEP-0115)
Mikael Berthe <mikael@lilotux.net>
parents: 1213
diff changeset
498 insert_entity_capabilities(x); // Entity Capabilities (XEP-0115)
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
499 #ifdef HAVE_GPGME
1052
c8a8edd5c50d PGP: Sign empty <status/> presence elements
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
500 if (!do_not_sign && gpg_enabled()) {
c8a8edd5c50d PGP: Sign empty <status/> presence elements
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
501 char *signature;
c8a8edd5c50d PGP: Sign empty <status/> presence elements
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
502 signature = gpg_sign(s_msg ? s_msg : "");
1042
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
503 if (signature) {
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
504 xmlnode y;
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
505 y = xmlnode_insert_tag(x, "x");
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
506 xmlnode_put_attrib(y, "xmlns", NS_SIGNED);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
507 xmlnode_insert_cdata(y, signature, (unsigned) -1);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
508 g_free(signature);
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
509 }
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
510 }
8a395c2cafc4 Initial PGP support (decrypt)
Mikael Berthe <mikael@lilotux.net>
parents: 1023
diff changeset
511 #endif
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
512 jab_send(jc, x);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
513 xmlnode_free(x);
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
514 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
515
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
516 // 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
517 if (recipient) return;
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
518
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
519 if (online) {
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
520 // Send presence to chatrooms
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
521 if (st != invisible) {
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
522 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
523 room_presence.st = st;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
524 room_presence.msg = msg;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
525 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
526 }
1365
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1363
diff changeset
527
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1363
diff changeset
528 // We'll have to update the roster if we switch to/from offline because
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
529 // 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
530 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
531 update_roster = TRUE;
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
532
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
533 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
534 mystatus = st;
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
535 }
1365
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1363
diff changeset
536
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
537 if (st)
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
538 mywantedstatus = st;
1365
c7e709719c43 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1363
diff changeset
539
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
540 if (msg != mystatusmsg) {
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
541 g_free(mystatusmsg);
521
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
542 if (*msg)
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
543 mystatusmsg = g_strdup(msg);
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
544 else
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
545 mystatusmsg = NULL;
cc8c969ab6e5 "/status" changes
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
546 }
713
b5aa7b7afee8 Update status lines
Mikael Berthe <mikael@lilotux.net>
parents: 706
diff changeset
547
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
548 if (!Autoaway)
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
549 update_last_use();
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
550
713
b5aa7b7afee8 Update status lines
Mikael Berthe <mikael@lilotux.net>
parents: 706
diff changeset
551 // Update status line
724
264375fe7159 Fix a roster refresh issue
Mikael Berthe <mikael@lilotux.net>
parents: 721
diff changeset
552 scr_UpdateMainStatus(TRUE);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
553 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
554
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
555 // jb_setprevstatus()
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
556 // 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
557 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
558 {
1050
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1046
diff changeset
559 jb_setstatus(mywantedstatus, NULL, mystatusmsg, FALSE);
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
560 }
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1013
diff changeset
561
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
562 // new_msgid()
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
563 // Generate a new id string. The caller should free it.
1071
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
564 // The caller must free the string when no longer needed.
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
565 static char *new_msgid(void)
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
566 {
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
567 static guint msg_idn;
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
568 time_t now;
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
569 time(&now);
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
570 if (!msg_idn)
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
571 srand(now);
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
572 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
573 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
574 }
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
575
1399
187985455020 Correctly display PGP-encoded messages with a subject
Mikael Berthe <mikael@lilotux.net>
parents: 1397
diff changeset
576 // jb_send_msg(jid, text, type, subject, msgid, *encrypted, type_overwrite)
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
577 // When encrypted is not NULL, the function set *encrypted to 1 if the
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
578 // message has been PGP-encrypted. If encryption enforcement is set and
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
579 // encryption fails, *encrypted is set to -1.
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
580 void jb_send_msg(const char *fjid, const char *text, int type,
1305
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
581 const char *subject, const char *msgid, gint *encrypted,
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
582 const char *type_overwrite)
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
583 {
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
584 xmlnode x;
1305
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
585 const gchar *strtype;
1304
8ada97e5eb75 Fix a gcc warning
Mikael Berthe <mikael@lilotux.net>
parents: 1299
diff changeset
586 #ifdef HAVE_LIBOTR
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
587 int otr_msg = 0;
1304
8ada97e5eb75 Fix a gcc warning
Mikael Berthe <mikael@lilotux.net>
parents: 1299
diff changeset
588 #endif
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
589 #if defined HAVE_GPGME || defined JEP0022 || defined JEP0085
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
590 char *rname, *barejid;
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
591 GSList *sl_buddy;
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
592 #endif
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
593 #if defined JEP0022 || defined JEP0085
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
594 xmlnode event;
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
595 guint use_jep85 = 0;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
596 struct jep0085 *jep85 = NULL;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
597 #endif
1071
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
598 #if defined JEP0022
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
599 gchar *nmsgid = NULL;
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
600 #endif
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
601 gchar *enc = NULL;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
602
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1053
diff changeset
603 if (encrypted)
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
604 *encrypted = 0;
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1053
diff changeset
605
1435
9bf7f3ddff10 Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
606 if (!online)
9bf7f3ddff10 Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
607 return;
9bf7f3ddff10 Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
608
9bf7f3ddff10 Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
609 if (!text && type == ROSTER_TYPE_USER)
9bf7f3ddff10 Do not send a groupchat-style message when changing a MUC room topic
Mikael Berthe <mikael@lilotux.net>
parents: 1426
diff changeset
610 return;
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
611
1305
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
612 if (type_overwrite)
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
613 strtype = type_overwrite;
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
614 else {
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
615 if (type == ROSTER_TYPE_ROOM)
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
616 strtype = TMSG_GROUPCHAT;
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
617 else
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
618 strtype = TMSG_CHAT;
9bc68473f8a3 -n and -f flags to message-sending commands
Michal 'vorner' Vaner <vorner@ucw.cz>
parents: 1304
diff changeset
619 }
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
620
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
621 #if defined HAVE_GPGME || defined HAVE_LIBOTR || defined JEP0022 || defined JEP0085
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
622 rname = strchr(fjid, JID_RESOURCE_SEPARATOR);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
623 barejid = jidtodisp(fjid);
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
624 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
625
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
626 // 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
627 // which hopefully will give us the most likely resource.
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
628 if (rname)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
629 rname++;
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
630
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
631 #ifdef HAVE_LIBOTR
1347
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
632 if (otr_enabled()) {
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
633 if (msgid && strcmp(msgid, "otrinject") == 0)
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
634 msgid = NULL;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
635 else if (type == ROSTER_TYPE_USER) {
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
636 otr_msg = otr_send((char **)&text, barejid);
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
637 if (!text) {
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
638 g_free(barejid);
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
639 if (encrypted)
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
640 *encrypted = -1;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
641 return;
07816313073b Add an option 'otr' to enable OTR support in the configuration file
Mikael Berthe <mikael@lilotux.net>
parents: 1344
diff changeset
642 }
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
643 }
1484
7b36b91a4388 New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents: 1476
diff changeset
644 if (otr_msg && encrypted)
7b36b91a4388 New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents: 1476
diff changeset
645 *encrypted = ENCRYPTED_OTR;
1299
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
646 }
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
647 #endif
3b338a5c01fc OTR support
Frank Zschockelt <mcabber_otr[at]freakysoft.de>
parents: 1290
diff changeset
648
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
649 #ifdef HAVE_GPGME
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
650 if (type == ROSTER_TYPE_USER && sl_buddy && gpg_enabled()) {
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
651 if (!settings_pgp_getdisabled(barejid)) { // not disabled for this contact?
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
652 guint force;
1065
230dca34dbea Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
653 struct pgp_data *res_pgpdata;
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
654 force = settings_pgp_getforce(barejid);
1065
230dca34dbea Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
655 res_pgpdata = buddy_resource_pgp(sl_buddy->data, rname);
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
656 if (force || (res_pgpdata && res_pgpdata->sign_keyid)) {
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
657 /* Remote client has PGP support (we have a signature)
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
658 * OR encryption is enforced (force = TRUE).
1067
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
659 * If the contact has a specific KeyId, we'll use it;
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
660 * if not, we'll use the key used for the signature.
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
661 * Both keys should match, in theory (cf. XEP-0027). */
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
662 const char *key;
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
663 key = settings_pgp_getkeyid(barejid);
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
664 if (!key && res_pgpdata)
1067
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
665 key = res_pgpdata->sign_keyid;
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
666 if (key)
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
667 enc = gpg_encrypt(text, key);
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
668 if (!enc && force) {
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
669 if (encrypted)
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
670 *encrypted = -1;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
671 g_free(barejid);
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
672 return;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1194
diff changeset
673 }
1067
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
674 }
1065
230dca34dbea Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
675 }
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
676 }
1067
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
677 #endif // HAVE_GPGME
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
678
1065
230dca34dbea Extand pgp_data structure
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
679 g_free(barejid);
1067
a5dc85fdebde Add key comparison for signatures & use user-provided PGP keys for encryption
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
680 #endif // HAVE_GPGME || defined JEP0022 || defined JEP0085
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
681
1306
a7d21918234c Fix jb_send_msg() call in OTR
Mikael Berthe <mikael@lilotux.net>
parents: 1305
diff changeset
682 x = jutil_msgnew((char*)strtype, (char*)fjid, NULL,
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
683 (enc ? "This message is PGP-encrypted." : (char*)text));
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
684 if (subject) {
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
685 xmlnode y;
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
686 y = xmlnode_insert_tag(x, "subject");
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
687 xmlnode_insert_cdata(y, subject, (unsigned) -1);
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
688 }
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
689 if (enc) {
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
690 xmlnode y;
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
691 y = xmlnode_insert_tag(x, "x");
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
692 xmlnode_put_attrib(y, "xmlns", NS_ENCRYPTED);
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
693 xmlnode_insert_cdata(y, enc, (unsigned) -1);
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1053
diff changeset
694 if (encrypted)
1484
7b36b91a4388 New UI message flag (O) when OTR is used
Mikael Berthe <mikael@lilotux.net>
parents: 1476
diff changeset
695 *encrypted = ENCRYPTED_PGP;
1044
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
696 g_free(enc);
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
697 }
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
698
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
699 #if defined JEP0022 || defined JEP0085
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
700 // If typing notifications are disabled, we can skip all this stuff...
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
701 if (chatstates_disabled || type == ROSTER_TYPE_ROOM)
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
702 goto jb_send_msg_no_chatstates;
52cfe9bf9840 Encryption support for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
703
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
704 if (sl_buddy)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
705 jep85 = buddy_resource_jep85(sl_buddy->data, rname);
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
706 #endif
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
707
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
708 #ifdef JEP0085
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
709 /* JEP-0085 5.1
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
710 * "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
711 * 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
712 * state notifications to the Contact."
1378
61fc9eddf763 Small code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1377
diff changeset
713 * In our implementation support is initially "unknown", then it's "probed"
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
714 * and can become "ok".
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
715 */
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
716 if (jep85 && (jep85->support == CHATSTATES_SUPPORT_OK ||
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
717 jep85->support == CHATSTATES_SUPPORT_UNKNOWN)) {
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
718 event = xmlnode_insert_tag(x, "active");
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
719 xmlnode_put_attrib(event, "xmlns", NS_CHATSTATES);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
720 if (jep85->support == CHATSTATES_SUPPORT_UNKNOWN)
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
721 jep85->support = CHATSTATES_SUPPORT_PROBED;
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
722 else
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
723 use_jep85 = 1;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
724 jep85->last_state_sent = ROSTER_EVENT_ACTIVE;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
725 }
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
726 #endif
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
727 #ifdef JEP0022
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
728 /* JEP-22
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
729 * 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
730 * If not, we try to fall back to JEP-0022.
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
731 */
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
732 if (!use_jep85) {
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
733 struct jep0022 *jep22 = NULL;
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
734 event = xmlnode_insert_tag(x, "x");
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
735 xmlnode_put_attrib(event, "xmlns", NS_EVENT);
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
736 xmlnode_insert_tag(event, "composing");
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
737
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
738 if (sl_buddy)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
739 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
740 if (jep22)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
741 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
742
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
743 // An id is mandatory when using JEP-0022.
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
744 if (!msgid && (text || subject)) {
1071
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
745 msgid = nmsgid = new_msgid();
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
746 // Let's update last_msgid_sent
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
747 // (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
748 // because this is probably a special message...)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
749 if (jep22) {
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
750 g_free(jep22->last_msgid_sent);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
751 jep22->last_msgid_sent = g_strdup(msgid);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
752 }
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
753 }
987
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
754 }
f47e312560af Improve JEP22 + JEP85 support
Mikael Berthe <mikael@lilotux.net>
parents: 986
diff changeset
755 #endif
986
ed697234bd39 Chat states receival (Alexis Hildebrandt)
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
756
993
0759f4c7da68 Add option 'disable_chatstates'
Mikael Berthe <mikael@lilotux.net>
parents: 992
diff changeset
757 jb_send_msg_no_chatstates:
988
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
758 xmlnode_put_attrib(x, "id", msgid);
6e2bfd1ffded Add ids to message stanzas if needed
Mikael Berthe <mikael@lilotux.net>
parents: 987
diff changeset
759
1254
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
760 if (mystatus != invisible)
401639413340 More jabber:iq:last support... (misc)
Mikael Berthe <mikael@lilotux.net>
parents: 1244
diff changeset
761 update_last_use();
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
762 jab_send(jc, x);
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
763 xmlnode_free(x);
1071
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
764 #if defined JEP0022
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
765 g_free(nmsgid);
866be086cc9b Fix a memory leak in JEP22 handling
Mikael Berthe <mikael@lilotux.net>
parents: 1067
diff changeset
766 #endif
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
767
114
065d8368c36b [/trunk] Changeset 128 by mikael
mikael
parents: 113
diff changeset
768 jb_reset_keepalive();
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
769 }
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
770
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
771
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
772 #ifdef JEP0085
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
773 // jb_send_jep85_chatstate()
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
774 // Send a JEP-85 chatstate.
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
775 static void jb_send_jep85_chatstate(const char *bjid, const char *resname,
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
776 guint state)
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
777 {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
778 xmlnode x;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
779 xmlnode event;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
780 GSList *sl_buddy;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
781 const char *chattag;
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
782 char *rjid, *fjid = NULL;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
783 struct jep0085 *jep85 = NULL;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
784
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
785 if (!online) return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
786
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
787 sl_buddy = roster_find(bjid, jidsearch, ROSTER_TYPE_USER);
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
788
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
789 // If we have a resource name, we use it. Else we use NULL,
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
790 // 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
791 if (sl_buddy)
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
792 jep85 = buddy_resource_jep85(sl_buddy->data, resname);
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
793
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
794 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
795 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
796
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
797 if (state == jep85->last_state_sent)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
798 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
799
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
800 if (state == ROSTER_EVENT_ACTIVE)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
801 chattag = "active";
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
802 else if (state == ROSTER_EVENT_COMPOSING)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
803 chattag = "composing";
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
804 else if (state == ROSTER_EVENT_PAUSED)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
805 chattag = "paused";
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
806 else {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
807 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
808 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
809 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
810
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
811 jep85->last_state_sent = state;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
812
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
813 if (resname)
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
814 fjid = g_strdup_printf("%s/%s", bjid, resname);
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
815
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
816 rjid = resname ? fjid : (char*)bjid;
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
817 x = jutil_msgnew(TMSG_CHAT, rjid, NULL, NULL);
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
818
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
819 event = xmlnode_insert_tag(x, chattag);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
820 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
821
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
822 jab_send(jc, x);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
823 xmlnode_free(x);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
824
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
825 g_free(fjid);
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
826 jb_reset_keepalive();
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
827 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
828 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
829
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
830 #ifdef JEP0022
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
831 // jb_send_jep22_event()
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
832 // Send a JEP-22 message event (delivered, composing...).
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
833 static void jb_send_jep22_event(const char *fjid, guint type)
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
834 {
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
835 xmlnode x;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
836 xmlnode event;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
837 const char *msgid;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
838 char *rname, *barejid;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
839 GSList *sl_buddy;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
840 struct jep0022 *jep22 = NULL;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
841 guint jep22_state;
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
842
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
843 if (!online) return;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
844
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
845 rname = strchr(fjid, JID_RESOURCE_SEPARATOR);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
846 barejid = jidtodisp(fjid);
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
847 sl_buddy = roster_find(barejid, jidsearch, ROSTER_TYPE_USER);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
848 g_free(barejid);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
849
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
850 // 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
851 // which hopefully will give us the most likely resource.
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
852 if (rname)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
853 rname++;
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
854 if (sl_buddy)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
855 jep22 = buddy_resource_jep22(sl_buddy->data, rname);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
856
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
857 if (!jep22)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
858 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
859
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
860 msgid = jep22->last_msgid_rcvd;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
861
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
862 // 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
863 // 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
864 if (type == ROSTER_EVENT_COMPOSING)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
865 jep22_state = ROSTER_EVENT_COMPOSING;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
866 else if (type == ROSTER_EVENT_ACTIVE ||
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
867 type == ROSTER_EVENT_PAUSED)
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
868 jep22_state = ROSTER_EVENT_ACTIVE;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
869 else
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
870 jep22_state = 0; // ROSTER_EVENT_NONE
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
871
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
872 if (jep22_state) {
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
873 // 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
874 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
875 return;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
876 jep22->last_state_sent = jep22_state;
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
877 }
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
878
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
879 x = jutil_msgnew(TMSG_CHAT, (char*)fjid, NULL, NULL);
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
880
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
881 event = xmlnode_insert_tag(x, "x");
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
882 xmlnode_put_attrib(event, "xmlns", NS_EVENT);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
883 if (type == ROSTER_EVENT_DELIVERED)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
884 xmlnode_insert_tag(event, "delivered");
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
885 else if (type == ROSTER_EVENT_COMPOSING)
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
886 xmlnode_insert_tag(event, "composing");
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
887 xmlnode_put_attrib(event, "id", msgid);
989
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
888
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
889 jab_send(jc, x);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
890 xmlnode_free(x);
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
891
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
892 jb_reset_keepalive();
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
893 }
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
894 #endif
859ab76e5093 Send JEP-22 delivered messages
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
895
997
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
896 // jb_send_chatstate(buddy, state)
d0d0cd9e39c4 Cosmetics & comments
Mikael Berthe <mikael@lilotux.net>
parents: 993
diff changeset
897 // 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
898 // 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
899 #if defined JEP0022 || defined JEP0085
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
900 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
901 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
902 const char *bjid;
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
903 #ifdef JEP0085
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
904 GSList *resources, *p_res, *p_next;
1476
77afd831f8f7 Avoid mixed declarations and code
Mikael Berthe <mikael@lilotux.net>
parents: 1448
diff changeset
905 struct jep0085 *jep85 = NULL;
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
906 #endif
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
907 #ifdef JEP0022
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
908 struct jep0022 *jep22;
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
909 #endif
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
910
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
911 bjid = buddy_getjid(buddy);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
912 if (!bjid) return;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
913
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
914 #ifdef JEP0085
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
915 /* Send the chatstate to the last resource (which should have the highest
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
916 priority).
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
917 If chatstate is "active", send an "active" state to all resources
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
918 which do not curently have this state.
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
919 */
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
920 resources = buddy_getresources(buddy);
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
921 for (p_res = resources ; p_res ; p_res = p_next) {
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
922 p_next = g_slist_next(p_res);
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
923 jep85 = buddy_resource_jep85(buddy, p_res->data);
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
924 if (jep85 && jep85->support == CHATSTATES_SUPPORT_OK) {
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
925 // If p_next is NULL, this is the highest (prio) resource, i.e.
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
926 // the one we are probably writing to.
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
927 if (!p_next || (jep85->last_state_sent != ROSTER_EVENT_ACTIVE &&
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
928 chatstate == ROSTER_EVENT_ACTIVE))
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
929 jb_send_jep85_chatstate(bjid, p_res->data, chatstate);
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
930 }
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
931 g_free(p_res->data);
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
932 }
1091
10f9d6fcfeab JEP85: Reset composing/paused state when a resource with higher prio comes up
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
933 g_slist_free(resources);
1099
7804dbac3875 Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents: 1091
diff changeset
934 // If the last resource had chatstates support when can return now,
7804dbac3875 Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents: 1091
diff changeset
935 // we don't want to send a JEP22 event.
7804dbac3875 Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents: 1091
diff changeset
936 if (jep85 && jep85->support == CHATSTATES_SUPPORT_OK)
7804dbac3875 Fix a potential JEP22/85 issue introduced by changeset 10f9d6fcfeab
Mikael Berthe <mikael@lilotux.net>
parents: 1091
diff changeset
937 return;
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
938 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
939 #ifdef JEP0022
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
940 jep22 = buddy_resource_jep22(buddy, NULL);
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
941 if (jep22 && jep22->support == CHATSTATES_SUPPORT_OK) {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
942 jb_send_jep22_event(bjid, chatstate);
990
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
943 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
944 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
945 }
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
946 #endif
35e7913affb7 Send events/chatstates notifications (JEP-22/JEP-85)
Mikael Berthe <mikael@lilotux.net>
parents: 989
diff changeset
947
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
948 // 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
949 // 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
950 // 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
951 #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
952 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
953 {
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
954 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
955 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
956 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
957 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
958
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
959 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
960 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
961 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
962
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
963 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
964 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
965 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
966
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
967 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
968 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
969
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
970 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
971 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
972
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
973 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
974 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
975 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
976 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
977 }
9687ecc59303 Redo chat states detection if we receive a message error packet from a contact
Mikael Berthe <mikael@lilotux.net>
parents: 998
diff changeset
978 #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
979
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
980 // jb_subscr_send_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
981 // Allow jid to receive our presence updates
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
982 void jb_subscr_send_auth(const char *bjid)
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
983 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
984 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
985
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
986 x = jutil_presnew(JPACKET__SUBSCRIBED, (char *)bjid, NULL);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
987 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
988 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
989 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
990
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
991 // jb_subscr_cancel_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
992 // Cancel jid's subscription to our presence updates
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
993 void jb_subscr_cancel_auth(const char *bjid)
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
994 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
995 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
996
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
997 x = jutil_presnew(JPACKET__UNSUBSCRIBED, (char *)bjid, NULL);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
998 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
999 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1000 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1001
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1002 // jb_subscr_request_auth(jid)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1003 // Request a subscription to jid's presence updates
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1004 void jb_subscr_request_auth(const char *bjid)
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1005 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1006 xmlnode x;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1007
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1008 x = jutil_presnew(JPACKET__SUBSCRIBE, (char *)bjid, NULL);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1009 jab_send(jc, x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1010 xmlnode_free(x);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1011 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1012
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1013 // jb_subscr_request_cancel(jid)
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1014 // Request to cancel jour subscription to jid's presence updates
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1015 void jb_subscr_request_cancel(const char *bjid)
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1016 {
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1017 xmlnode x;
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1018
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1019 x = jutil_presnew(JPACKET__UNSUBSCRIBE, (char *)bjid, NULL);
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1020 jab_send(jc, x);
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1021 xmlnode_free(x);
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1022 }
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1023
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
1024 // Note: the caller should check the jid is correct
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1025 void jb_addbuddy(const char *bjid, const char *name, const char *group)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1026 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1027 xmlnode y, z;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
1028 eviqs *iqn;
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
1029 char *cleanjid;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1030
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1031 if (!online) return;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1032
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1033 cleanjid = jidtodisp(bjid); // Stripping resource, just in case...
590
a5707d61e469 Fix a few UTF-8 related issues
Mikael Berthe <mikael@lilotux.net>
parents: 589
diff changeset
1034
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1035 // We don't check if the jabber user already exists in the roster,
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1036 // because it allows to re-ask for notification.
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1037
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1038 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
1039 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
1040
454399f026fa Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1041 xmlnode_put_attrib(y, "jid", cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1042
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1043 if (name)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1044 xmlnode_put_attrib(y, "name", name);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
1045
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1046 if (group) {
628
454399f026fa Fix a bug in jb_addbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1047 z = xmlnode_insert_tag(y, "group");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1048 xmlnode_insert_cdata(z, group, (unsigned) -1);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1049 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1050
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1051 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1052 iqs_del(iqn->id); // XXX
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1053
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 616
diff changeset
1054 jb_subscr_request_auth(cleanjid);
612
789ec6aed764 Respect RFC 3921 order advice
Mikael Berthe <mikael@lilotux.net>
parents: 611
diff changeset
1055
1355
9716cf8a0726 Add on_server flag
Mikael Berthe <mikael@lilotux.net>
parents: 1354
diff changeset
1056 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER, sub_pending, -1);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
1057 g_free(cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1058 buddylist_build();
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1059
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
1060 update_roster = TRUE;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1061 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
1062
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1063 void jb_delbuddy(const char *bjid)
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1064 {
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1065 xmlnode y, z;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
1066 eviqs *iqn;
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1067 char *cleanjid;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1068
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1069 if (!online) return;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1070
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1071 cleanjid = jidtodisp(bjid); // Stripping resource, just in case...
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1072
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1073 // If the current buddy is an agent, unsubscribe from it
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1074 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1075 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1076
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1077 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
1078 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
1079 y = xmlnode_get_tag(iqn->xmldata, "query");
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1080 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
1081 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1082 iqs_del(iqn->id); // XXX
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1083 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1084
611
ad737139a144 Improve subscription management
Mikael Berthe <mikael@lilotux.net>
parents: 610
diff changeset
1085 // Cancel the subscriptions
834
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1086 jb_subscr_cancel_auth(cleanjid); // Cancel "from"
6f913f4fbb2a Use jb_subscr_ in jb_delbuddy()
Mikael Berthe <mikael@lilotux.net>
parents: 823
diff changeset
1087 jb_subscr_request_cancel(cleanjid); // Cancel "to"
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1088
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1089 // 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
1090 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
1091 y = xmlnode_get_tag(iqn->xmldata, "query");
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1092 z = xmlnode_insert_tag(y, "item");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1093 xmlnode_put_attrib(z, "jid", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1094 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
1095 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1096 iqs_del(iqn->id); // XXX
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1097
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1098 roster_del_user(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1099 g_free(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1100 buddylist_build();
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1101
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1102 update_roster = TRUE;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1103 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
1104
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1105 void jb_updatebuddy(const char *bjid, const char *name, const char *group)
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1106 {
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1107 xmlnode y;
745
413e95f3051a Introduce user "events" list
Mikael Berthe <mikael@lilotux.net>
parents: 735
diff changeset
1108 eviqs *iqn;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1109 char *cleanjid;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1110
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1111 if (!online) return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1112
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1113 // XXX We should check name's and group's correctness
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1114
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1115 cleanjid = jidtodisp(bjid); // Stripping resource, just in case...
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1116
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1117 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
1118 y = xmlnode_insert_tag(xmlnode_get_tag(iqn->xmldata, "query"), "item");
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1119 xmlnode_put_attrib(y, "jid", cleanjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1120 xmlnode_put_attrib(y, "name", name);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1121
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1122 if (group) {
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1123 y = xmlnode_insert_tag(y, "group");
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 756
diff changeset
1124 xmlnode_insert_cdata(y, group, (unsigned) -1);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1125 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1126
684
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1127 jab_send(jc, iqn->xmldata);
3282276e7413 Switch IQ packet creation to the new IQ system
Mikael Berthe <mikael@lilotux.net>
parents: 678
diff changeset
1128 iqs_del(iqn->id); // XXX
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1129 g_free(cleanjid);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1130 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
1131
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1132 void jb_request(const char *fjid, enum iqreq_type reqtype)
691
3c0a0a993de8 Implement IQ:time requests
Mikael Berthe <mikael@lilotux.net>
parents: 686
diff changeset
1133 {
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1071
diff changeset
1134 GSList *resources, *p_res;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1135 GSList *roster_elt;
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1136 void (*request_fn)(const char *);
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1137 const char *strreqtype;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1138
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1139 if (reqtype == iqreq_version) {
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1140 request_fn = &request_version;
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1141 strreqtype = "version";
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1142 } else if (reqtype == iqreq_time) {
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1143 request_fn = &request_time;
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1144 strreqtype = "time";
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
1145 } else if (reqtype == iqreq_last) {
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
1146 request_fn = &request_last;
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
1147 strreqtype = "last";
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
1148 } else if (reqtype == iqreq_vcard) {
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
1149 // Special case
793
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1150 } else
898dd706cc5c Fix up /request command
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
1151 return;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1152
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
1153 // vCard request
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
1154 if (reqtype == iqreq_vcard) {
1310
a5336c44d4e2 Allow vcard requests to a full jid
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
1155 request_vcard(fjid);
a5336c44d4e2 Allow vcard requests to a full jid
Mikael Berthe <mikael@lilotux.net>
parents: 1306
diff changeset
1156 scr_LogPrint(LPRINT_NORMAL, "Sent vCard request to <%s>", fjid);
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
1157 return;
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
1158 }
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 1001
diff changeset
1159
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1160 if (strchr(fjid, JID_RESOURCE_SEPARATOR)) {
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1161 // This is a full JID
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1162 (*request_fn)(fjid);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1163 scr_LogPrint(LPRINT_NORMAL, "Sent %s request to <%s>", strreqtype, fjid);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1164 return;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691
diff changeset
1165 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 691