annotate mcabber/src/jabglue.c @ 513:d40c434fff46

Add HBB_PREFIX_NOFLAG A line with this attribute won't trigger a notification flag. This patch adds use of it for joins, leaves, nickname changes and topic changes.
author Mikael Berthe <mikael@lilotux.net>
date Sun, 13 Nov 2005 22:15:19 +0100
parents 16dd9b91702f
children 5c338d31de56
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 *
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net>
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
5 * Parts come from the centericq project:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
6 * Copyright (C) 2002-2005 by Konstantin Klyagin <konst@konst.org.ua>
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
7 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or (at
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
11 * your option) any later version.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
12 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful, but
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
16 * General Public License for more details.
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
17 *
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
21 * USA
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
22 */
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
23
237
c8df64f43625 [/trunk] Changeset 250 by mikael
mikael
parents: 231
diff changeset
24 #define _GNU_SOURCE /* We need glibc for strptime */
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
25 #include "../libjabber/jabber.h"
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
26 #include "jabglue.h"
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"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
34
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
35 #define JABBERPORT 5222
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
36 #define JABBERSSLPORT 5223
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
37
194
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
38 #define JABBER_AGENT_GROUP "Jabber Agents"
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
39
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
40 jconn jc;
311
1d6b16d9c577 Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents: 300
diff changeset
41 static time_t LastPingTime;
1d6b16d9c577 Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents: 300
diff changeset
42 static unsigned int KeepaliveDelay;
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
43 static unsigned int prio;
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
44 static int s_id;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
45 static int regmode, regdone;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
46 static enum imstatus mystatus = offline;
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
47 static unsigned char online;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
48
353
3fe43f6daa5a Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
49 char imstatus2char[imstatus_size+1] = {
3fe43f6daa5a Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
50 '_', 'o', 'i', 'f', 'd', 'n', 'a', '\0'
46
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
51 };
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
52
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
53 static enum {
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
54 STATE_CONNECTING,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
55 STATE_GETAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
56 STATE_SENDAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
57 STATE_LOGGED
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
58 } jstate;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
59
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
60
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
61 void statehandler(jconn, int);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
62 void packethandler(jconn, jpacket);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
63
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
64 static void logger(jconn j, int io, const char *buf)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
65 {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
66 scr_LogPrint(LPRINT_DEBUG, "%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
67 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
68
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
69 /*
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
70 static void jidsplit(const char *jid, char **user, char **host,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
71 char **res)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
72 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
73 char *tmp, *ptr;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
74 tmp = strdup(jid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
75
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
76 if ((ptr = strchr(tmp, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
77 *res = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
78 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
79 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
80 *res = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
81
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
82 if ((ptr = strchr(tmp, '@')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
83 *host = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
84 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
85 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
86 *host = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
87
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
88 *user = strdup(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
89 free(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
90 }
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
91 */
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
92
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
93 // jidtodisp(jid)
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
94 // Strips the resource part from the jid
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
95 // The caller should g_free the result after use.
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
96 char *jidtodisp(const char *jid)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
97 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
98 char *ptr;
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
99 char *alias;
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
100
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
101 alias = g_strdup(jid);
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
102
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
103 if ((ptr = strchr(alias, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
104 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
105 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
106 return alias;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
107 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
108
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
109 char *compose_jid(const char *username, const char *servername,
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
110 const char *resource)
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
111 {
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
112 char *jid = g_new(char, 3 +
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 387
diff changeset
113 strlen(username) + strlen(servername) + strlen(resource));
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
114 strcpy(jid, username);
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
115 if (!strchr(jid, '@')) {
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
116 strcat(jid, "@");
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
117 strcat(jid, servername);
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
118 }
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
119 strcat(jid, "/");
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
120 strcat(jid, resource);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
121 return jid;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
122 }
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
123
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
124 inline unsigned char jb_getonline(void)
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
125 {
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
126 return online;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
127 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
128
403
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
129 jconn jb_connect(const char *jid, const char *server, unsigned int port,
17aa60c6dc63 Allow a different server name than the jid domain name
Mikael Berthe <mikael@lilotux.net>
parents: 393
diff changeset
130 int ssl, const char *pass)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
131 {
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
132 char *utf8_jid;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
133 if (!port) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
134 if (ssl)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
135 port = JABBERSSLPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
136 else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
137 port = JABBERPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
138 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
139
357
e8adc3c96e68 Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents: 353
diff changeset
140 jb_disconnect();
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
141
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
142 utf8_jid = to_utf8(jid);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
143 if (!utf8_jid) return jc;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
144
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
145 s_id = 1;
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
146 jc = jab_new(utf8_jid, (char*)pass, (char*)server, port, ssl);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
147 g_free(utf8_jid);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
148
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
149 /* 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
150 jab_logger(jc, logger);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
151 jab_packet_handler(jc, &packethandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
152 jab_state_handler(jc, &statehandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
153
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
154 if (jc && jc->user) {
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
155 online = TRUE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
156 jstate = STATE_CONNECTING;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
157 statehandler(0, -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
158 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
159 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
160
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
161 return jc;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
162 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
163
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
164 void jb_disconnect(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
165 {
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
166 if (!jc) return;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
167
416
48e7808c4191 Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents: 411
diff changeset
168 // announce it to everyone else
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
169 jb_setstatus(offline, NULL, "");
416
48e7808c4191 Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents: 411
diff changeset
170
48e7808c4191 Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents: 411
diff changeset
171 // announce it to the user
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
172 statehandler(jc, JCONN_STATE_OFF);
416
48e7808c4191 Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents: 411
diff changeset
173
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
174 jab_delete(jc);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
175 //free(jc); XXX
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
176 jc = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
177 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
178
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
179 inline void jb_reset_keepalive()
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
180 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
181 time(&LastPingTime);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
182 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
183
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
184 void jb_send_raw(const char *str)
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
185 {
461
1d8f5b3a5f2b Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
186 if (jc && online && str)
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
187 jab_send_raw(jc, str);
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
188 }
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 430
diff changeset
189
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
190 void jb_keepalive()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
191 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
192 if (jc && online)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
193 jab_send_raw(jc, " \t ");
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
194 jb_reset_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
195 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
196
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
197 void jb_set_keepalive_delay(unsigned int delay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
198 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
199 KeepaliveDelay = delay;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
200 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
201
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
202 inline void jb_set_priority(unsigned int priority)
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
203 {
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
204 prio = priority;
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
205 }
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
206
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
207 void jb_main()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
208 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
209 xmlnode x, z;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
210 char *cid;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
211
406
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
212 if (!online) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
213 safe_usleep(10000);
406
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
214 return;
a9dd91e08eb3 Add usleep() calls
Mikael Berthe <mikael@lilotux.net>
parents: 403
diff changeset
215 }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
216
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
217 if (jc && jc->state == JCONN_STATE_CONNECTING) {
419
2f9852610cf4 Small code review
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
218 safe_usleep(75000);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
219 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
220 return;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
221 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
222
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
223 jab_poll(jc, 50);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
224
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
225 if (jstate == STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
226 if (jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
227 x = jutil_iqnew(JPACKET__GET, NS_AUTH);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
228 cid = jab_getid(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
229 xmlnode_put_attrib(x, "id", cid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
230 // id = atoi(cid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
231
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
232 z = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "username");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
233 xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
234 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
235 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
236
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
237 jstate = STATE_GETAUTH;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
238 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
239
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
240 if (!jc || jc->state == JCONN_STATE_OFF) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
241 scr_LogPrint(LPRINT_LOGNORM, "Unable to connect to the server");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
242 online = FALSE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
243 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
244 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
245
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
246 if (!jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
247 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
248 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
249 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
250 }
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
251
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
252 // Keepalive
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
253 if (KeepaliveDelay) {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
254 time_t now;
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
255 time(&now);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
256 if (now > LastPingTime + KeepaliveDelay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
257 jb_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
258 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
259 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
260
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
261 inline enum imstatus jb_getstatus()
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
262 {
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
263 return mystatus;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
264 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
265
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
266 void jb_setstatus(enum imstatus st, const char *recipient, const char *msg)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
267 {
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
268 xmlnode x;
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
269 gchar *utf8_msg;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
270
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
271 if (!online) return;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
272
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
273 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
274
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
275 if (recipient)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
276 xmlnode_put_attrib(x, "to", recipient);
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
277
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
278 switch(st) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
279 case away:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
280 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
281 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
282 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
283
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
284 case dontdisturb:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
285 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
286 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
287 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
288
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
289 case freeforchat:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
290 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
291 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
292 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
293
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
294 case notavail:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
295 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
296 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
297 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
298
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
299 case invisible:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
300 xmlnode_put_attrib(x, "type", "invisible");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
301 break;
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
302
118
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
303 case offline:
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
304 xmlnode_put_attrib(x, "type", "unavailable");
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
305 break;
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
306
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
307 default:
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
308 break;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
309 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
310
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
311 if (prio) {
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
312 char strprio[8];
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
313 snprintf(strprio, 8, "%u", prio);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
314 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
315 strprio, (unsigned) -1);
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
316 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
317
294
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
318 if (!msg)
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
319 msg = settings_get_status_msg(st);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
320
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
321 utf8_msg = to_utf8(msg);
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
322 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg,
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
323 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
324
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
325 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
326 xmlnode_free(x);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
327 g_free(utf8_msg);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
328
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
329 // 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
330 if (recipient) return;
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
331
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
332 // Buddy per buddy invisibility handling
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
333 //sendvisibility();
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
334
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
335 // We'll need to update the roster if we switch to/from offline because
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
336 // we don't know the presences of buddies when offline...
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
337 if (mystatus == offline || st == offline)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
338 update_roster = TRUE;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
339
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
340 hk_mystatuschange(0, mystatus, st, msg);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
341 mystatus = st;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
342 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
343
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
344 void jb_send_msg(const char *jid, const char *text, int type,
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
345 const char *subject)
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
346 {
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
347 xmlnode x;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
348 gchar *strtype;
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
349 gchar *buffer = to_utf8(text);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
350
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
351 if (!online) return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
352
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
353 if (type == ROSTER_TYPE_ROOM)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
354 strtype = TMSG_GROUPCHAT;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
355 else
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
356 strtype = TMSG_CHAT;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
357
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
358 x = jutil_msgnew(strtype, (char*)jid, NULL, (char*)buffer);
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
359 if (subject) {
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
360 xmlnode y;
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
361 char *bs = to_utf8(subject);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
362 y = xmlnode_insert_tag(x, "subject");
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
363 xmlnode_insert_cdata(y, bs, (unsigned) -1);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
364 if (bs) g_free(bs);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
365 }
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
366 jab_send(jc, x);
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
367 xmlnode_free(x);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
368 g_free(buffer);
114
065d8368c36b [/trunk] Changeset 128 by mikael
mikael
parents: 113
diff changeset
369 jb_reset_keepalive();
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
370 }
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
371
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
372 // Note: the caller should check the jid is correct
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
373 void jb_addbuddy(const char *jid, const char *name, const char *group)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
374 {
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
375 xmlnode x, y, z;
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
376 char *cleanjid;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
377
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
378 if (!online) return;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
379
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
380 // We don't check if the jabber user already exists in the roster,
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
381 // because it allows to re-ask for notification.
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
382
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
383 //x = jutil_presnew(JPACKET__SUBSCRIBE, jid, NULL);
125
1bf1a1233b88 [/trunk] Changeset 138 by mikael
mikael
parents: 124
diff changeset
384 x = jutil_presnew(JPACKET__SUBSCRIBE, (char*)jid, "online");
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
385 jab_send(jc, x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
386 xmlnode_free(x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
387
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
388 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
389 y = xmlnode_get_tag(x, "query");
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
390 z = xmlnode_insert_tag(y, "item");
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
391 xmlnode_put_attrib(z, "jid", jid);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
392
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
393 if (name) {
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
394 gchar *name_utf8 = to_utf8(name);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
395 z = xmlnode_insert_tag(z, "name");
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
396 xmlnode_insert_cdata(z, name_utf8, (unsigned) -1);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
397 g_free(name_utf8);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
398 }
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
399
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
400 if (group) {
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
401 char *group_utf8 = to_utf8(group);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
402 z = xmlnode_insert_tag(z, "group");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
403 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
404 g_free(group_utf8);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
405 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
406
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
407 jab_send(jc, x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
408 xmlnode_free(x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
409
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
410 cleanjid = jidtodisp(jid);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
411 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
412 g_free(cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
413 buddylist_build();
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
414
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
415 update_roster = TRUE;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
416 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
417
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
418 void jb_delbuddy(const char *jid)
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
419 {
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
420 xmlnode x, y, z;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
421 char *cleanjid;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
422
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
423 if (!online) return;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
424
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
425 cleanjid = jidtodisp(jid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
426
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
427 // If the current buddy is an agent, unsubscribe from it
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
428 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
429 scr_LogPrint(LPRINT_LOGNORM, "Unregistering from the %s agent", cleanjid);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
430
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
431 x = jutil_iqnew(JPACKET__SET, NS_REGISTER);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
432 xmlnode_put_attrib(x, "to", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
433 y = xmlnode_get_tag(x, "query");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
434 xmlnode_insert_tag(y, "remove");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
435 jab_send(jc, x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
436 xmlnode_free(x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
437 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
438
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
439 // Unsubscribe this buddy from our presence notification
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
440 x = jutil_presnew(JPACKET__UNSUBSCRIBE, cleanjid, 0);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
441 jab_send(jc, x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
442 xmlnode_free(x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
443
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
444 // Ask for removal from roster
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
445 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
446 y = xmlnode_get_tag(x, "query");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
447 z = xmlnode_insert_tag(y, "item");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
448 xmlnode_put_attrib(z, "jid", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
449 xmlnode_put_attrib(z, "subscription", "remove");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
450 jab_send(jc, x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
451 xmlnode_free(x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
452
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
453 roster_del_user(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
454 g_free(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
455 buddylist_build();
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
456
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
457 update_roster = TRUE;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
458 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
459
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
460 void jb_updatebuddy(const char *jid, const char *name, const char *group)
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
461 {
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
462 xmlnode x, y;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
463 char *cleanjid;
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
464 gchar *name_utf8;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
465
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
466 if (!online) return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
467
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
468 // XXX We should check name's and group's correctness
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
469
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
470 cleanjid = jidtodisp(jid);
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
471 name_utf8 = to_utf8(name);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
472
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
473 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
474 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
475 xmlnode_put_attrib(y, "jid", cleanjid);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
476 xmlnode_put_attrib(y, "name", name_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
477
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
478 if (group) {
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
479 gchar *group_utf8 = to_utf8(group);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
480 y = xmlnode_insert_tag(y, "group");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
481 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
482 g_free(group_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
483 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
484
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
485 jab_send(jc, x);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
486 xmlnode_free(x);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
487 g_free(name_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
488 g_free(cleanjid);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
489 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
490
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
491 // Join a MUC room
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
492 void jb_room_join(const char *room, const char *nickname)
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
493 {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
494 xmlnode x, y;
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
495 gchar *roomid, *utf8_nickname;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
496
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
497 if (!online || !room) return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
498 if (!nickname) return;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
499
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
500 utf8_nickname = to_utf8(nickname);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
501 roomid = g_strdup_printf("%s/%s", room, utf8_nickname);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
502 g_free(utf8_nickname);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
503 if (check_jid_syntax(roomid)) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
504 scr_LogPrint(LPRINT_NORMAL, "<%s/%s> is not a valid Jabber room", room,
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
505 nickname);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
506 g_free(roomid);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
507 return;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
508 }
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
509
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
510 // Send the XML request
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
511 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
512 xmlnode_put_attrib(x, "from", jid_full(jc->user));
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
513 xmlnode_put_attrib(x, "to", roomid);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
514 y = xmlnode_insert_tag(x, "x");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
515 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
516
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
517 jab_send(jc, x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
518 xmlnode_free(x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
519 jb_reset_keepalive();
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
520 g_free(roomid);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
521 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
522
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
523 // Unlock a MUC room
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
524 // room syntax: "room@server"
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
525 void jb_room_unlock(const char *room)
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
526 {
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
527 xmlnode x, y, z;
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
528
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
529 if (!online || !room) return;
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
530
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
531 x = jutil_iqnew(JPACKET__SET, "http://jabber.org/protocol/muc#owner");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
532 xmlnode_put_attrib(x, "id", "unlock1"); // XXX
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
533 xmlnode_put_attrib(x, "to", room);
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
534 y = xmlnode_get_tag(x, "query");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
535 z = xmlnode_insert_tag(y, "x");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
536 xmlnode_put_attrib(z, "xmlns", "jabber:x:data");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
537 xmlnode_put_attrib(z, "type", "submit");
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
538
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
539 jab_send(jc, x);
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
540 xmlnode_free(x);
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
541 jb_reset_keepalive();
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
542 }
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
543
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
544
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
545 // Invite a user to a MUC room
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
546 // room syntax: "room@server"
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
547 // reason can be null.
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
548 void jb_room_invite(const char *room, const char *jid, const char *reason)
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
549 {
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
550 xmlnode x, y, z;
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
551 gchar *utf8_reason;
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
552
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
553 if (!online || !room || !jid) return;
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
554
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
555 if (!reason) reason = "";
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
556
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
557 x = jutil_msgnew(NULL, (char*)room, NULL, NULL);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
558
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
559 y = xmlnode_insert_tag(x, "x");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
560 xmlnode_put_attrib(y, "xmlns", "http://jabber.org/protocol/muc#user");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
561
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
562 z = xmlnode_insert_tag(y, "invite");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
563 xmlnode_put_attrib(z, "to", jid);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
564
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
565 utf8_reason = to_utf8(reason);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
566 y = xmlnode_insert_tag(z, "reason");
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
567 xmlnode_insert_cdata(y, utf8_reason, (unsigned) -1);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
568 g_free(utf8_reason);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
569
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
570 jab_send(jc, x);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
571 xmlnode_free(x);
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
572 jb_reset_keepalive();
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
573 }
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 478
diff changeset
574
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
575 void postlogin()
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
576 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
577 //int i;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
578
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
579 //flogged = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
580 //ourstatus = available;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
581
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
582 //setautostatus(jhook.manualstatus);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
583
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 441
diff changeset
584 jb_setstatus(available, NULL, NULL);
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
585 buddylist_build();
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
586 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
587 for (i = 0; i < clist.count; i++) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
588 c = (icqcontact *) clist.at(i);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
589
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
590 if (c->getdesc().pname == proto)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
591 if (ischannel(c))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
592 if (c->getbasicinfo().requiresauth)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
593 c->setstatus(available);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
594 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
595 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
596
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
597 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
598 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
599 agents.begin()->params[agent::ptRegister].enabled = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
600
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
601 string buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
602 ifstream f(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
603
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
604 if (f.is_open()) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
605 icqcontact *c = clist.get(contactroot);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
606
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
607 c->clear();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
608 icqcontact::basicinfo bi = c->getbasicinfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
609 icqcontact::reginfo ri = c->getreginfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
610
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
611 ri.service = agents.begin()->name;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
612 getstring(f, buf); c->setnick(buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
613 getstring(f, buf); bi.email = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
614 getstring(f, buf); bi.fname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
615 getstring(f, buf); bi.lname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
616 f.close();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
617
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
618 c->setbasicinfo(bi);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
619 c->setreginfo(ri);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
620
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
621 sendupdateuserinfo(*c);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
622 unlink(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
623 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
624 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
625 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
626
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
627 void gotloggedin(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
628 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
629 xmlnode x;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
630
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
631 x = jutil_iqnew(JPACKET__GET, NS_AGENTS);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
632 xmlnode_put_attrib(x, "id", "Agent List");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
633 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
634 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
635
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
636 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
637 xmlnode_put_attrib(x, "id", "Roster");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
638 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
639 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
640 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
641
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
642 void gotroster(xmlnode x)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
643 {
33
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
644 xmlnode y, z;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
645
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
646 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
647 const char *alias = xmlnode_get_attrib(y, "jid");
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
648 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
649 const char *name = xmlnode_get_attrib(y, "name");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
650 char *group = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
651
33
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
652 z = xmlnode_get_tag(y, "group");
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
653 if (z) group = xmlnode_get_data(z);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
654
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
655 if (alias) {
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
656 char *buddyname;
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
657 char *cleanalias = jidtodisp(alias);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
658 gchar *name_noutf8 = NULL;
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
659 gchar *group_noutf8 = NULL;
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
660
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
661 buddyname = cleanalias;
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
662 if (name) {
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
663 name_noutf8 = from_utf8(name);
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
664 if (name_noutf8) buddyname = name_noutf8;
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
665 }
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
666
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
667 if (group)
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
668 group_noutf8 = from_utf8(group);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
669
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
670 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
671 if (name_noutf8) g_free(name_noutf8);
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
672 if (group_noutf8) g_free(group_noutf8);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
673 g_free(cleanalias);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
674 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
675 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
676
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
677 postlogin();
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
678 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
679
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
680 void gotmessage(char *type, const char *from, const char *body,
489
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
681 const char *enc, time_t timestamp)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
682 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
683 char *jid;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
684 const char *rname;
387
2bbeef7b4fdd Do non UTF8-encode/decode null pointers
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
685 gchar *buffer = from_utf8(body);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
686
441
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
687 jid = jidtodisp(from);
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
688
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
689 if (!buffer && body) {
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
690 scr_LogPrint(LPRINT_LOGNORM, "Decoding of message from <%s> has failed",
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
691 from);
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
692 scr_WriteIncomingMessage(jid, "Cannot display message: "
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
693 "UTF-8 conversion failure",
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
694 0, HBB_PREFIX_ERR | HBB_PREFIX_IN);
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
695 g_free(jid);
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
696 return;
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
697 }
51b8f10cfeb8 Handle g_locale_from_utf8() failures
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
698
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
699 rname = strchr(from, '/');
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
700 if (rname) rname++;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
701 hk_message_in(jid, rname, timestamp, buffer, type);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
702 g_free(jid);
383
39c5da51b387 Remove utf8 files, use Glib
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
703 g_free(buffer);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
704 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
705
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
706 const char *defaulterrormsg(int code)
420
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
707 {
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
708 const char *desc;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
709
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
710 switch(code) {
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
711 case 401: desc = "Unauthorized";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
712 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
713 case 302: desc = "Redirect";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
714 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
715 case 400: desc = "Bad request";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
716 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
717 case 402: desc = "Payment Required";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
718 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
719 case 403: desc = "Forbidden";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
720 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
721 case 404: desc = "Not Found";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
722 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
723 case 405: desc = "Not Allowed";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
724 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
725 case 406: desc = "Not Acceptable";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
726 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
727 case 407: desc = "Registration Required";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
728 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
729 case 408: desc = "Request Timeout";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
730 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
731 case 409: desc = "Conflict";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
732 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
733 case 500: desc = "Internal Server Error";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
734 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
735 case 501: desc = "Not Implemented";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
736 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
737 case 502: desc = "Remote Server Error";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
738 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
739 case 503: desc = "Service Unavailable";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
740 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
741 case 504: desc = "Remote Server Timeout";
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
742 break;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
743 default:
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
744 desc = NULL;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
745 }
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
746
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
747 return desc;
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
748 }
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
749
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
750 // display_server_error(x)
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
751 // Display the error to the user
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
752 // x: error tag xmlnode pointer
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
753 void display_server_error(xmlnode x)
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
754 {
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
755 const char *desc = NULL;
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
756 int code = 0;
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
757 char *s;
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
758 const char *p;
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
759
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
760 /* RFC3920:
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
761 * The <error/> element:
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
762 * o MUST contain a child element corresponding to one of the defined
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
763 * stanza error conditions specified below; this element MUST be
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
764 * qualified by the 'urn:ietf:params:xml:ns:xmpp-stanzas' namespace.
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
765 */
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
766 p = xmlnode_get_name(xmlnode_get_firstchild(x));
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
767 if (p)
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
768 scr_LogPrint(LPRINT_LOGNORM, "Received error packet [%s]", p);
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
769
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
770 // For backward compatibility
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
771 if ((s = xmlnode_get_attrib(x, "code")) != NULL) {
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
772 code = atoi(s);
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
773 // Default message
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
774 desc = defaulterrormsg(code);
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
775 }
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
776
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
777 // Error tag data is better, if available
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
778 s = xmlnode_get_data(x);
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
779 if (s && *s) desc = s;
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
780
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
781 // And sometimes there is a text message
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
782 s = xmlnode_get_tag_data(x, "text");
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
783 if (s && *s) desc = s; // FIXME utf8??
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
784
430
d03663d2e7d9 Display error messages as specified in RFC3920 (9.3)
Mikael Berthe <mikael@lilotux.net>
parents: 426
diff changeset
785 scr_LogPrint(LPRINT_LOGNORM, "Error code from server: %d %s", code, desc);
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
786 }
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
787
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
788 void statehandler(jconn conn, int state)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
789 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
790 static int previous_state = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
791
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
792 scr_LogPrint(LPRINT_DEBUG, "StateHandler called (state=%d).", state);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
793
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
794 switch(state) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
795 case JCONN_STATE_OFF:
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
796 if (previous_state != JCONN_STATE_OFF)
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
797 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Not connected to the server");
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
798
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
799 online = FALSE;
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
800 mystatus = offline;
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
801 roster_free();
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
802 update_roster = TRUE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
803 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
804
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
805 case JCONN_STATE_CONNECTED:
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
806 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connected to the server");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
807 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
808
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
809 case JCONN_STATE_AUTH:
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
810 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Authenticating to the server");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
811 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
812
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
813 case JCONN_STATE_ON:
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
814 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Communication with the server "
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
815 "established");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
816 online = TRUE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
817 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
818
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
819 case JCONN_STATE_CONNECTING:
357
e8adc3c96e68 Better messages for server connection states
Mikael Berthe <mikael@lilotux.net>
parents: 353
diff changeset
820 if (previous_state != state)
408
73433860665c Tune previous usleep() change
Mikael Berthe <mikael@lilotux.net>
parents: 407
diff changeset
821 scr_LogPrint(LPRINT_LOGNORM, "[Jabber] Connecting to the server");
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
822 break;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
823
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
824 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
825 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
826 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
827 previous_state = state;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
828 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
829
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
830 void packethandler(jconn conn, jpacket packet)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
831 {
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
832 char *p, *r, *s;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
833 const char *m, *rname;
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
834 xmlnode x, y;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
835 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
836 char *ns=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
837 char *id=NULL;
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
838 enum imstatus ust;
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
839 char bpprio;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
840
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
841 jb_reset_keepalive(); // reset keepalive timeout
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
842 jpacket_reset(packet);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
843
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
844 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
845 p = xmlnode_get_attrib(packet->x, "from");
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
846 if (p) { // Convert from UTF8
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
847 // We need to be careful because from_utf8() can fail on some chars
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
848 // Thus we only convert the resource part
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
849 from = g_new0(char, strlen(p)+1);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
850 strcpy(from, p);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
851 r = strchr(from, '/');
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
852 m = strchr(p, '/');
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
853 if (m++) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
854 s = from_utf8(m);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
855 if (s) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
856 // The length should be enough because from_utf should only
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
857 // reduce the string length
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
858 strcpy(r+1, s);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
859 g_free(s);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
860 } else {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
861 *(r+1) = 0;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
862 scr_LogPrint(LPRINT_LOGNORM, "Decoding of message sender has failed");
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
863 }
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
864 }
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
865 }
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
866
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
867 if (!from && packet->type != JPACKET_IQ) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
868 scr_LogPrint(LPRINT_LOGNORM, "Error in packet (could be UTF8-related)");
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
869 return;
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
870 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
871
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
872 switch (packet->type) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
873 case JPACKET_MESSAGE:
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
874 {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
875 char *tmp = NULL;
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
876 time_t timestamp = 0;
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
877
473
c024d1d5d350 Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents: 472
diff changeset
878 body = xmlnode_get_tag_data(packet->x, "body");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
879
473
c024d1d5d350 Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents: 472
diff changeset
880 p = xmlnode_get_tag_data(packet->x, "subject");
c024d1d5d350 Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents: 472
diff changeset
881 if (p != NULL) {
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
882 if (type && !strcmp(type, TMSG_GROUPCHAT)) { // Room topic
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
883 gchar *mbuf;
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
884 gchar *subj_noutf8 = from_utf8(p);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
885 // Get the room (s) and the nickname (r)
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
886 s = g_strdup(from);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
887 r = strchr(s, '/');
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
888 if (r) *r++ = 0;
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
889 else r = s;
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
890 // Display inside the room window
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
891 mbuf = g_strdup_printf("%s has set the topic to: %s", r,
489
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
892 (subj_noutf8 ? subj_noutf8 : "(?)"));
513
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
893 scr_WriteIncomingMessage(s, mbuf, 0,
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
894 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG);
478
47cfa3779549 MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
895 if (settings_opt_get_int("log_muc_conf"))
47cfa3779549 MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
896 hlog_write_message(s, 0, FALSE, mbuf);
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
897 if (subj_noutf8) g_free(subj_noutf8);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
898 g_free(s);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
899 g_free(mbuf);
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 474
diff changeset
900 } else { // Chat message
473
c024d1d5d350 Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents: 472
diff changeset
901 tmp = g_new(char, (body ? strlen(body) : 0) + strlen(p) + 4);
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
902 *tmp = '[';
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
903 strcpy(tmp+1, p);
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
904 strcat(tmp, "]\n");
473
c024d1d5d350 Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents: 472
diff changeset
905 if (body) strcat(tmp, body);
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
906 body = tmp;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
907 }
473
c024d1d5d350 Fix segfault when receiving a message stanza with no body tag
Mikael Berthe <mikael@lilotux.net>
parents: 472
diff changeset
908 }
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
909
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
910 /* there can be multiple <x> tags. we're looking for one with
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
911 xmlns = jabber:x:encrypted */
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
912
420
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
913 x = xmlnode_get_firstchild(packet->x);
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
914 for ( ; x; x = xmlnode_get_nextsibling(x)) {
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
915 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
916 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
917 !strcasecmp(p, "jabber:x:encrypted"))
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
918 if ((p = xmlnode_get_data(x)) != NULL) {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
919 enc = p;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
920 break;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
921 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
922 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
923
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
924 // Timestamp?
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
925 if ((x = xmlnode_get_tag(packet->x, "x")) != NULL) {
241
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 237
diff changeset
926 if ((p = xmlnode_get_attrib(x, "stamp")) != NULL)
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 237
diff changeset
927 timestamp = from_iso8601(p, 1);
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
928 }
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
929
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
930 if (type && !strcmp(type, TMSG_ERROR)) {
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
931 if ((x = xmlnode_get_tag(packet->x, TMSG_ERROR)) != NULL)
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
932 display_server_error(x);
420
04a0b450380b Display error code/message when receiving a message packet with "error" type
Mikael Berthe <mikael@lilotux.net>
parents: 419
diff changeset
933 }
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
934 if (from && body)
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
935 gotmessage(type, from, body, enc, timestamp);
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
936 if (tmp)
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
937 g_free(tmp);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
938 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
939 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
940
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
941 case JPACKET_IQ:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
942 if (!strcmp(type, "result")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
943
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
944 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
945 int iid = atoi(p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
946
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
947 scr_LogPrint(LPRINT_DEBUG, "iid = %d", iid);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
948 if (iid == s_id) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
949 if (!regmode) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
950 if (jstate == STATE_GETAUTH) {
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
951 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
952 if (!xmlnode_get_tag(x, "digest")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
953 jc->sid = 0;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
954 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
955
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
956 s_id = atoi(jab_auth(jc));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
957 jstate = STATE_SENDAUTH;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
958 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
959 gotloggedin();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
960 jstate = STATE_LOGGED;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
961 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
962 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
963 regdone = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
964 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
965 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
966 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
967
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
968 if (!strcmp(p, "VCARDreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
969 x = xmlnode_get_firstchild(packet->x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
970 if (!x) x = packet->x;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
971
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
972 //jhook.gotvcard(ic, x); TODO
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
973 scr_LogPrint(LPRINT_LOGNORM, "Got VCARD");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
974 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
975 } else if (!strcmp(p, "versionreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
976 // jhook.gotversion(ic, packet->x); TODO
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
977 scr_LogPrint(LPRINT_LOGNORM, "Got version");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
978 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
979 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
980 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
981
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
982 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
983 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
984
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
985 if (!strcmp(ns, NS_ROSTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
986 gotroster(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
987 } else if (!strcmp(ns, NS_AGENTS)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
988 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
989 const char *alias = xmlnode_get_attrib(y, "jid");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
990
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
991 if (alias) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
992 const char *name = xmlnode_get_tag_data(y, "name");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
993 const char *desc = xmlnode_get_tag_data(y, "description");
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
994 // TODO
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
995 // const char *service = xmlnode_get_tag_data(y, "service");
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
996 enum agtype atype = unknown;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
997
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
998 if (xmlnode_get_tag(y, TMSG_GROUPCHAT)) atype = groupchat;
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
999 else if (xmlnode_get_tag(y, "transport")) atype = transport;
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1000 else if (xmlnode_get_tag(y, "search")) atype = search;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1001
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
1002 if (atype == transport) {
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
1003 char *cleanjid = jidtodisp(alias);
194
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
1004 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP,
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
1005 ROSTER_TYPE_AGENT);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
1006 g_free(cleanjid);
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
1007 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1008 if (alias && name && desc) {
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1009 scr_LogPrint(LPRINT_LOGNORM,
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1010 "Agent: %s / %s / %s / type=%d",
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
1011 alias, name, desc, atype);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1012
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
1013 if (atype == search) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1014 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1015 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1016 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1017 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1018 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1019 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1020
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1021 if (xmlnode_get_tag(y, "register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1022 x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1023 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1024 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1025 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1026 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1027 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1028 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1029 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1030 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1031
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
1032 /*
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1033 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1034 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1035 _("Default Jabber conference server"), agent::atGroupchat));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1036
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1037 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1038 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1039 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)"";
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1040
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1041 if (!strcmp(id, "Agent info")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1042 // jhook.gotagentinfo(packet->x); TODO
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1043 scr_LogPrint(LPRINT_LOGNORM, "Got agent info");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1044 } else if (!strcmp(id, "Lookup")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1045 // jhook.gotsearchresults(packet->x); TODO
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1046 scr_LogPrint(LPRINT_LOGNORM, "Got search results");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1047 } else if (!strcmp(id, "Register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1048 x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1049 xmlnode_put_attrib(x, "to", from);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1050 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1051 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1052 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1053 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1054
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1055 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1056 }
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1057 } else if (!strcmp(type, "get")) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1058 p = xmlnode_get_attrib(packet->x, "id");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1059 if (p) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1060 xmlnode z;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1061
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1062 id = p;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1063 x = xmlnode_new_tag("iq");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1064 xmlnode_put_attrib(x, "type", "result");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1065 xmlnode_put_attrib(x, "to", from);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1066 xmlnode_put_attrib(x, "id", id);
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1067 xmlnode_put_attrib(x, "type", TMSG_ERROR);
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1068 y = xmlnode_insert_tag(x, TMSG_ERROR);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1069 xmlnode_put_attrib(y, "code", "503");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1070 xmlnode_put_attrib(y, "type", "cancel");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1071 z = xmlnode_insert_tag(y, "feature-not-implemented");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1072 xmlnode_put_attrib(z, "xmlns",
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1073 "urn:ietf:params:xml:ns:xmpp-stanzas");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1074 jab_send(conn, x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1075 xmlnode_free(x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1076 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1077 } else if (!strcmp(type, "set")) {
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1078 /* FIXME: send error */
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1079 } else if (!strcmp(type, TMSG_ERROR)) {
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1080 if ((x = xmlnode_get_tag(packet->x, TMSG_ERROR)) != NULL)
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
1081 display_server_error(x);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1082 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1083 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1084
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1085 case JPACKET_PRESENCE:
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
1086 r = jidtodisp(from);
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1087 if (type && !strcmp(type, TMSG_ERROR)) {
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
1088 scr_LogPrint(LPRINT_LOGNORM, "Error presence packet from <%s>", r);
474
27efa1e2671a Minor code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 473
diff changeset
1089 if ((x = xmlnode_get_tag(packet->x, TMSG_ERROR)) != NULL)
426
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
1090 display_server_error(x);
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
1091 g_free(r);
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
1092 break;
2706ef3e25a7 Better handling of server error codes/messages
Mikael Berthe <mikael@lilotux.net>
parents: 421
diff changeset
1093 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1094
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1095 p = xmlnode_get_tag_data(packet->x, "priority");
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1096 if (p && *p) bpprio = (gchar)atoi(p);
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1097 else bpprio = 0;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1098
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1099 ust = available;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1100 p = xmlnode_get_tag_data(packet->x, "show");
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1101 if (p) {
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1102 if (!strcmp(p, "away")) ust = away;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1103 else if (!strcmp(p, "dnd")) ust = dontdisturb;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1104 else if (!strcmp(p, "xa")) ust = notavail;
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1105 else if (!strcmp(p, "chat")) ust = freeforchat;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1106 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1107
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
1108 if (type && !strcmp(type, "unavailable"))
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
1109 ust = offline;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1110
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
1111 if ((x = xmlnode_get_tag(packet->x, "status")) != NULL)
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1112 s = from_utf8(xmlnode_get_data(x));
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
1113 else
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1114 s = NULL;
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
1115
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
1116 // Call hk_statuschange() if status has changed or if the
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
1117 // status message is different
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1118 rname = strchr(from, '/');
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1119 if (rname) rname++;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1120
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1121 // Check for MUC presence packet
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1122 // There can be multiple <x> tags!!
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1123 x = xmlnode_get_firstchild(packet->x);
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1124 for ( ; x; x = xmlnode_get_nextsibling(x)) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1125 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1126 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1127 !strcasecmp(p, "http://jabber.org/protocol/muc#user"))
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1128 break;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1129 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1130 if (x) { // This is a MUC presence message
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1131 enum imrole mbrole = role_none;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1132 const char *mbrjid = NULL;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1133 const char *mbnewnick = NULL;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1134 GSList *room_elt;
478
47cfa3779549 MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1135 int log_muc_conf = settings_opt_get_int("log_muc_conf");
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1136
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1137 // Add room if it doesn't already exist
489
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
1138 room_elt = roster_find(r, jidsearch, 0);
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
1139 if (!room_elt)
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
1140 room_elt = roster_add_user(r, NULL, NULL, ROSTER_TYPE_ROOM);
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
1141 else // Make sure this is a room (it can be a conversion user->room)
21ab22a60bcb Auto-convert a roster item to "room" type when receiving a groupchat message
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
1142 buddy_settype(room_elt->data, ROSTER_TYPE_ROOM);
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1143
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1144 // Get room member's information
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1145 y = xmlnode_get_tag(x, "item");
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1146 if (y) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1147 p = xmlnode_get_attrib(y, "role");
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1148 if (p) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1149 if (!strcmp(p, "moderator")) mbrole = role_moderator;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1150 else if (!strcmp(p, "participant")) mbrole = role_participant;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1151 else if (!strcmp(p, "visitor")) mbrole = role_visitor;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1152 else if (!strcmp(p, "none")) mbrole = role_none;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1153 else scr_LogPrint(LPRINT_LOGNORM, "<%s>: Unknown role \"%s\"",
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1154 from, p);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1155 }
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1156 p = xmlnode_get_attrib(y, "jid");
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1157 if (p) mbrjid = p;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1158 p = xmlnode_get_attrib(y, "nick");
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1159 if (p) mbnewnick = p;
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1160 }
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1161
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1162 // Check for nickname change
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1163 y = xmlnode_get_tag(x, "status");
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1164 if (y && mbnewnick) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1165 p = xmlnode_get_attrib(y, "code");
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1166 if (p && !strcmp(p, "303")) {
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1167 gchar *mbuf;
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1168 gchar *newname_noutf8 = from_utf8(mbnewnick);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1169 mbuf = g_strdup_printf("%s is now known as %s", rname,
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1170 (newname_noutf8 ? newname_noutf8 : "(?)"));
513
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
1171 scr_WriteIncomingMessage(r, mbuf, 0,
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
1172 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG);
478
47cfa3779549 MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1173 if (log_muc_conf) hlog_write_message(r, 0, FALSE, mbuf);
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1174 g_free(mbuf);
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1175 if (newname_noutf8) {
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1176 buddy_resource_setname(room_elt->data, rname, newname_noutf8);
470
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1177 m = buddy_getnickname(room_elt->data);
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1178 if (m && !strcmp(rname, m))
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1179 buddy_setnickname(room_elt->data, newname_noutf8);
469
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1180 g_free(newname_noutf8);
a926523d2392 Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents: 468
diff changeset
1181 }
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1182 }
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1183 }
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1184
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1185 // Check for departure/arrival
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1186 if (!mbnewnick && mbrole == role_none) {
507
16dd9b91702f MUC: display buddy's departure message, if any
Mikael Berthe <mikael@lilotux.net>
parents: 493
diff changeset
1187 gchar *mbuf;
16dd9b91702f MUC: display buddy's departure message, if any
Mikael Berthe <mikael@lilotux.net>
parents: 493
diff changeset
1188 if (s) mbuf = g_strdup_printf("%s has left: %s", rname, s);
16dd9b91702f MUC: display buddy's departure message, if any
Mikael Berthe <mikael@lilotux.net>
parents: 493
diff changeset
1189 else mbuf = g_strdup_printf("%s has left", rname);
513
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
1190 scr_WriteIncomingMessage(r, mbuf, 0,
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
1191 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG);
478
47cfa3779549 MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1192 if (log_muc_conf) hlog_write_message(r, 0, FALSE, mbuf);
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1193 g_free(mbuf);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1194 } else if (buddy_getstatus(room_elt->data, rname) == offline &&
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1195 ust != offline) {
470
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1196 gchar *mbuf;
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1197 if (buddy_getnickname(room_elt->data) == NULL) {
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1198 buddy_setnickname(room_elt->data, rname);
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1199 mbuf = g_strdup_printf("You have joined as \"%s\"", rname);
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1200 } else {
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1201 mbuf = g_strdup_printf("%s has joined", rname);
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
1202 }
513
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
1203 scr_WriteIncomingMessage(r, mbuf, 0,
d40c434fff46 Add HBB_PREFIX_NOFLAG
Mikael Berthe <mikael@lilotux.net>
parents: 507
diff changeset
1204 HBB_PREFIX_INFO|HBB_PREFIX_NOFLAG);
478
47cfa3779549 MUC: log join/nick/leave/topic if log_muc_conf is set
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1205 if (log_muc_conf) hlog_write_message(r, 0, FALSE, mbuf);
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1206 g_free(mbuf);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1207 }
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1208
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1209 // Update room member status
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1210 if (rname)
493
dba5de0b89bc Update message status for conference occupants
Mikael Berthe <mikael@lilotux.net>
parents: 489
diff changeset
1211 roster_setstatus(r, rname, bpprio, ust, s, mbrole, mbrjid);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1212 else
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1213 scr_LogPrint(LPRINT_LOGNORM, "MUC DBG: no rname!"); /* DBG */
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1214
468
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1215 g_free(r);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1216 if (s) g_free(s);
644b8bf9ca4d Improve MUC presence messages handling
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
1217
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1218 buddylist_build();
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1219 scr_DrawRoster();
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1220 break;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1221 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1222
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1223 // Not a MUC message, so this is a regular buddy...
438
b44be19d6229 Handle multiple resources for the same buddy
Mikael Berthe <mikael@lilotux.net>
parents: 436
diff changeset
1224 m = roster_getstatusmsg(r, rname);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1225 if ((ust != roster_getstatus(r, rname)) || (s && (!m || strcmp(s, m))))
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1226 hk_statuschange(r, rname, bpprio, 0, ust, s);
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
1227 g_free(r);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
1228 if (s) g_free(s);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1229 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1230
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1231 case JPACKET_S10N:
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1232 scr_LogPrint(LPRINT_LOGNORM, "Received (un)subscription packet "
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1233 "(type=%s)", ((type) ? type : ""));
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
1234
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
1235 if (!strcmp(type, "subscribe")) {
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
1236 int isagent;
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
1237 r = jidtodisp(from);
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
1238 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0;
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
1239 g_free(r);
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1240 scr_LogPrint(LPRINT_LOGNORM, "isagent=%d", isagent); // XXX DBG
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
1241 if (!isagent) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff