annotate mcabber/src/jabglue.c @ 549:448e299e45da

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