annotate mcabber/src/jabglue.c @ 353:3fe43f6daa5a

Make imstatus2char a null-terminated string
author Mikael Berthe <mikael@lilotux.net>
date Fri, 22 Jul 2005 13:01:40 +0100
parents ff6fb51bfd78
children e8adc3c96e68
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
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
3 *
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"
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
30 #include "utf8.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
31 #include "utils.h"
294
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
32 #include "settings.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
33
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
34 #define JABBERPORT 5222
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
35 #define JABBERSSLPORT 5223
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
36
194
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
37 #define JABBER_AGENT_GROUP "Jabber Agents"
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
38
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
39 jconn jc;
311
1d6b16d9c577 Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents: 300
diff changeset
40 static time_t LastPingTime;
1d6b16d9c577 Make some global variables static
Mikael Berthe <mikael@lilotux.net>
parents: 300
diff changeset
41 static unsigned int KeepaliveDelay;
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
42 static unsigned int prio;
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;
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
46 unsigned char online;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
47
353
3fe43f6daa5a Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
48 char imstatus2char[imstatus_size+1] = {
3fe43f6daa5a Make imstatus2char a null-terminated string
Mikael Berthe <mikael@lilotux.net>
parents: 325
diff changeset
49 '_', 'o', 'i', 'f', 'd', 'n', 'a', '\0'
46
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
50 };
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
51
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
52 static enum {
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
53 STATE_CONNECTING,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
54 STATE_GETAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
55 STATE_SENDAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
56 STATE_LOGGED
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
57 } jstate;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
58
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
59
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
60 void statehandler(jconn, int);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
61 void packethandler(jconn, jpacket);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
62
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
63 void screen_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
64 {
36
8f1a5e79ca40 [/trunk] Changeset 52 by mikael
mikael
parents: 35
diff changeset
65 scr_LogPrint("%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
66 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
67
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
68 void file_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
69 {
36
8f1a5e79ca40 [/trunk] Changeset 52 by mikael
mikael
parents: 35
diff changeset
70 ut_WriteLog("%03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
71 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
72
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
73 void big_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
74 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
75 screen_logger(j, io, buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
76 file_logger(j, io, buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
77 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
78
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
79 /*
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
80 static void jidsplit(const char *jid, char **user, char **host,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
81 char **res)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
82 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
83 char *tmp, *ptr;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
84 tmp = strdup(jid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
85
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
86 if ((ptr = strchr(tmp, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
87 *res = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
88 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
89 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
90 *res = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
91
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
92 if ((ptr = strchr(tmp, '@')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
93 *host = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
94 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
95 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
96 *host = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
97
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
98 *user = strdup(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
99 free(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
100 }
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
101 */
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
102
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
103 // jidtodisp(jid)
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
104 // Strips the resource part from the jid
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
105 // The caller should g_free the result after use.
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
106 char *jidtodisp(const char *jid)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
107 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
108 char *ptr;
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
109 char *alias;
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
110
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
111 while ((alias = g_strdup(jid)) == NULL)
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
112 usleep(100);
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
113
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
114 if ((ptr = strchr(alias, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
115 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
116 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
117 return alias;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
118 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
119
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
120 char *compose_jid(const char *username, const char *servername,
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
121 const char *resource)
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
122 {
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
123 char *jid = g_new(char,
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
124 strlen(username)+strlen(servername)+strlen(resource)+3);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
125 strcpy(jid, username);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
126 strcat(jid, "@");
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
127 strcat(jid, servername);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
128 strcat(jid, "/");
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
129 strcat(jid, resource);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
130 return jid;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
131 }
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
132
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
133 jconn jb_connect(const char *jid, unsigned int port, int ssl, const char *pass)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
134 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
135 if (!port) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
136 if (ssl)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
137 port = JABBERSSLPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
138 else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
139 port = JABBERPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
140 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
141
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
142 //if (jc)
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
143 // free(jc); XXX
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
144
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
145 s_id = 1;
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
146 jc = jab_new((char*)jid, (char*)pass, port, ssl);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
147
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
148 /* These 3 functions can deal with a NULL jc, no worry... */
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
149 jab_logger(jc, file_logger);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
150 jab_packet_handler(jc, &packethandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
151 jab_state_handler(jc, &statehandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
152
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
153 if (jc && jc->user) {
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
154 online = TRUE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
155 jstate = STATE_CONNECTING;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
156 statehandler(0, -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
157 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
158 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
159
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
160 return jc;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
161 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
162
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
163 void jb_disconnect(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
164 {
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
165 if (!jc) return;
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
166
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
167 statehandler(jc, JCONN_STATE_OFF);
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
168 jab_delete(jc);
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
169 //free(jc); XXX
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 294
diff changeset
170 jc = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
171 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
172
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
173 inline void jb_reset_keepalive()
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
174 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
175 time(&LastPingTime);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
176 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
177
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
178 void jb_keepalive()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
179 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
180 if (jc && online)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
181 jab_send_raw(jc, " \t ");
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
182 jb_reset_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
183 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
184
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
185 void jb_set_keepalive_delay(unsigned int delay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
186 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
187 KeepaliveDelay = delay;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
188 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
189
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
190 inline void jb_set_priority(unsigned int priority)
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
191 {
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
192 prio = priority;
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
193 }
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
194
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
195 void jb_main()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
196 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
197 xmlnode x, z;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
198 char *cid;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
199
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
200 if (!online) return;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
201
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
202 if (jc && jc->state == JCONN_STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
203 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
204 return;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
205 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
206
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
207 jab_poll(jc, 50);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
208
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
209 if (jstate == STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
210 if (jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
211 x = jutil_iqnew(JPACKET__GET, NS_AUTH);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
212 cid = jab_getid(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
213 xmlnode_put_attrib(x, "id", cid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
214 // id = atoi(cid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
215
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
216 z = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "username");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
217 xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
218 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
219 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
220
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
221 jstate = STATE_GETAUTH;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
222 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
223
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
224 if (!jc || jc->state == JCONN_STATE_OFF) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
225 scr_LogPrint("Unable to connect to the server");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
226 online = FALSE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
227 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
228 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
229
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
230 if (!jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
231 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
232 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
233 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
234 }
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
235
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
236 // Keepalive
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
237 if (KeepaliveDelay) {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
238 time_t now;
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
239 time(&now);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
240 if (now > LastPingTime + KeepaliveDelay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
241 jb_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
242 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
243 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
244
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
245 inline enum imstatus jb_getstatus()
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
246 {
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
247 return mystatus;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
248 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
249
294
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
250 void jb_setstatus(enum imstatus st, const char *msg)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
251 {
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
252 xmlnode x;
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
253 char *utf8_msg;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
254
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
255 if (!online) return;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
256
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
257 x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
258
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
259 switch(st) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
260 case away:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
261 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
262 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
263 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
264
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
265 case dontdisturb:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
266 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
267 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
268 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
269
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
270 case freeforchat:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
271 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
272 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
273 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
274
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
275 case notavail:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
276 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
277 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
278 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
279
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
280 case invisible:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
281 xmlnode_put_attrib(x, "type", "invisible");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
282 break;
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
283
118
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
284 case offline:
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
285 xmlnode_put_attrib(x, "type", "unavailable");
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
286 break;
1e8f646e2c5b [/trunk] Changeset 131 by mikael
mikael
parents: 116
diff changeset
287
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
288 default:
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
289 break;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
290 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
291
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
292 if (prio) {
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
293 char strprio[8];
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
294 snprintf(strprio, 8, "%u", prio);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
295 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
272
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
296 strprio, (unsigned) -1);
7f2e61392b2e Add resource priority option
mikael@matrix
parents: 244
diff changeset
297 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
298
294
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
299 if (!msg)
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
300 msg = settings_get_status_msg(st);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
301
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
302 utf8_msg = utf8_encode(msg);
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
303 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), utf8_msg,
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
304 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
305
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
306 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
307 xmlnode_free(x);
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
308 free(utf8_msg);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
309
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
310 //sendvisibility(); ???
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
311
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
312 // 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
313 // we don't know the presences of buddies when offline...
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
314 if (mystatus == offline || st == offline)
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
315 update_roster = TRUE;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
316
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
317 hk_mystatuschange(0, mystatus, st, msg);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 114
diff changeset
318 mystatus = st;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
319 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
320
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
321 void jb_send_msg(const char *jid, const char *text)
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
322 {
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
323 char *buffer = utf8_encode(text);
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
324 xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)buffer);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
325 jab_send(jc, x);
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
326 xmlnode_free(x);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
327 free(buffer);
114
065d8368c36b [/trunk] Changeset 128 by mikael
mikael
parents: 113
diff changeset
328 jb_reset_keepalive();
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
329 }
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
330
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
331 // Note: the caller should check the jid is correct
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
332 void jb_addbuddy(const char *jid, const char *name, const char *group)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
333 {
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
334 xmlnode x, y, z;
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
335 char *cleanjid;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
336
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
337 if (!online) return;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
338
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
339 // We don't check if the jabber user already exists in the roster,
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
340 // because it allows to re-ask for notification.
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
341
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
342 //x = jutil_presnew(JPACKET__SUBSCRIBE, jid, NULL);
125
1bf1a1233b88 [/trunk] Changeset 138 by mikael
mikael
parents: 124
diff changeset
343 x = jutil_presnew(JPACKET__SUBSCRIBE, (char*)jid, "online");
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
344 jab_send(jc, x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
345 xmlnode_free(x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
346
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
347 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
348 y = xmlnode_get_tag(x, "query");
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
349 z = xmlnode_insert_tag(y, "item");
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
350 xmlnode_put_attrib(z, "jid", jid);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
351
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
352 if (name) {
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
353 char *name_utf8 = utf8_encode(name);
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
354 z = xmlnode_insert_tag(z, "name");
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
355 xmlnode_insert_cdata(z, name_utf8, (unsigned) -1);
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
356 free(name_utf8);
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
357 }
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
358
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
359 if (group) {
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
360 char *group_utf8 = utf8_encode(group);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
361 z = xmlnode_insert_tag(z, "group");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
362 xmlnode_insert_cdata(z, group_utf8, (unsigned) -1);
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
363 free(group_utf8);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
364 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
365
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
366 jab_send(jc, x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
367 xmlnode_free(x);
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
368
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
369 cleanjid = jidtodisp(jid);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
370 roster_add_user(cleanjid, name, group, ROSTER_TYPE_USER);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
371 g_free(cleanjid);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
372 buddylist_build();
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
373
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 241
diff changeset
374 update_roster = TRUE;
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
375 }
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
376
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
377 void jb_delbuddy(const char *jid)
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
378 {
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
379 xmlnode x, y, z;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
380 char *cleanjid;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
381
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
382 if (!online) return;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
383
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
384 cleanjid = jidtodisp(jid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
385
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
386 // If the current buddy is an agent, unsubscribe from it
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
387 if (roster_gettype(cleanjid) == ROSTER_TYPE_AGENT) {
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
388 scr_LogPrint("Unregistering from the %s agent", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
389
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
390 x = jutil_iqnew(JPACKET__SET, NS_REGISTER);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
391 xmlnode_put_attrib(x, "to", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
392 y = xmlnode_get_tag(x, "query");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
393 xmlnode_insert_tag(y, "remove");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
394 jab_send(jc, x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
395 xmlnode_free(x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
396 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
397
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
398 // Unsubscribe this buddy from our presence notification
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
399 x = jutil_presnew(JPACKET__UNSUBSCRIBE, cleanjid, 0);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
400 jab_send(jc, x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
401 xmlnode_free(x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
402
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
403 // Ask for removal from roster
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
404 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
405 y = xmlnode_get_tag(x, "query");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
406 z = xmlnode_insert_tag(y, "item");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
407 xmlnode_put_attrib(z, "jid", cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
408 xmlnode_put_attrib(z, "subscription", "remove");
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
409 jab_send(jc, x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
410 xmlnode_free(x);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
411
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
412 roster_del_user(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
413 g_free(cleanjid);
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
414 buddylist_build();
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
415
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
416 update_roster = TRUE;
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
417 }
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
418
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
419 void jb_updatebuddy(const char *jid, const char *name, const char *group)
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
420 {
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
421 xmlnode x, y;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
422 char *cleanjid;
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
423 char *name_utf8;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
424
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
425 if (!online) return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
426
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
427 // XXX We should check name's and group's correctness
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
428
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
429 cleanjid = jidtodisp(jid);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
430 name_utf8 = utf8_encode(name);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
431
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
432 x = jutil_iqnew(JPACKET__SET, NS_ROSTER);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
433 y = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "item");
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
434 xmlnode_put_attrib(y, "jid", cleanjid);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
435 xmlnode_put_attrib(y, "name", name_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
436
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
437 if (group) {
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
438 char *group_utf8 = utf8_encode(group);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
439 y = xmlnode_insert_tag(y, "group");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
440 xmlnode_insert_cdata(y, group_utf8, (unsigned) -1);
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
441 free(group_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
442 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
443
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
444 jab_send(jc, x);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
445 xmlnode_free(x);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
446 free(name_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
447 g_free(cleanjid);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
448 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 205
diff changeset
449
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
450 void postlogin()
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
451 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
452 //int i;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
453
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
454 //flogged = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
455 //ourstatus = available;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
456
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
457 //setautostatus(jhook.manualstatus);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
458
294
871e53769084 Allow one status message per Jabber status
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
459 jb_setstatus(available, NULL);
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
460 buddylist_build();
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
461 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
462 for (i = 0; i < clist.count; i++) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
463 c = (icqcontact *) clist.at(i);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
464
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
465 if (c->getdesc().pname == proto)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
466 if (ischannel(c))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
467 if (c->getbasicinfo().requiresauth)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
468 c->setstatus(available);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
469 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
470 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
471
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
472 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
473 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
474 agents.begin()->params[agent::ptRegister].enabled = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
475
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
476 string buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
477 ifstream f(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
478
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
479 if (f.is_open()) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
480 icqcontact *c = clist.get(contactroot);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
481
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
482 c->clear();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
483 icqcontact::basicinfo bi = c->getbasicinfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
484 icqcontact::reginfo ri = c->getreginfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
485
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
486 ri.service = agents.begin()->name;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
487 getstring(f, buf); c->setnick(buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
488 getstring(f, buf); bi.email = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
489 getstring(f, buf); bi.fname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
490 getstring(f, buf); bi.lname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
491 f.close();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
492
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
493 c->setbasicinfo(bi);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
494 c->setreginfo(ri);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
495
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
496 sendupdateuserinfo(*c);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
497 unlink(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
498 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
499 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
500 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
501
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
502 void gotloggedin(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
503 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
504 xmlnode x;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
505
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
506 x = jutil_iqnew(JPACKET__GET, NS_AGENTS);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
507 xmlnode_put_attrib(x, "id", "Agent List");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
508 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
509 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
510
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
511 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
512 xmlnode_put_attrib(x, "id", "Roster");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
513 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
514 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
515 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
516
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
517 void gotroster(xmlnode x)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
518 {
33
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
519 xmlnode y, z;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
520
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
521 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
522 const char *alias = xmlnode_get_attrib(y, "jid");
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
523 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
524 const char *name = xmlnode_get_attrib(y, "name");
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
525 char *group = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
526
33
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
527 z = xmlnode_get_tag(y, "group");
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
528 if (z) group = xmlnode_get_data(z);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
529
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
530 if (alias) {
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
531 char *buddyname;
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
532 char *cleanalias = jidtodisp(alias);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
533 char *name_noutf8 = NULL;
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
534 char *group_noutf8 = NULL;
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
535
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
536 if (name) {
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
537 name_noutf8 = utf8_decode(name);
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
538 buddyname = name_noutf8;
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
539 } else
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
540 buddyname = cleanalias;
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
541
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
542 if (group) group_noutf8 = utf8_decode(group);
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
543 roster_add_user(cleanalias, buddyname, group_noutf8, ROSTER_TYPE_USER);
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
544 if (name_noutf8) free(name_noutf8);
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
545 if (group_noutf8) free(group_noutf8);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
546 g_free(cleanalias);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
547 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
548 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
549
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
550 postlogin();
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
551 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
552
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
553 void gotmessage(char *type, const char *from, const char *body,
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
554 const char *enc, time_t timestamp)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
555 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
556 char *jid;
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
557 char *buffer = utf8_decode(body);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
558
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
559 /*
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
560 //char *u, *h, *r;
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
561 //jidsplit(from, &u, &h, &r);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
562 // Maybe we should remember the resource?
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
563 if (r)
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
564 scr_LogPrint("There is an extra part in message (resource?): %s", r);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
565 //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
566 */
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
567
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
568 jid = jidtodisp(from);
325
ff6fb51bfd78 Handle "error" message type
Mikael Berthe <mikael@lilotux.net>
parents: 321
diff changeset
569 hk_message_in(jid, timestamp, buffer, type);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
570 g_free(jid);
213
4fcdbfdf7c20 [/trunk] Changeset 225 by mikael
mikael
parents: 208
diff changeset
571 free(buffer);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
572 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
573
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
574 void statehandler(jconn conn, int state)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
575 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
576 static int previous_state = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
577
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
578 ut_WriteLog("StateHandler called (state=%d).\n", state);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
579
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
580 switch(state) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
581 case JCONN_STATE_OFF:
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
582 if (previous_state != JCONN_STATE_OFF)
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
583 scr_LogPrint("+ JCONN_STATE_OFF");
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
584
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
585 online = FALSE;
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
586 mystatus = offline;
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
587 roster_free();
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 159
diff changeset
588 update_roster = TRUE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
589 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
590
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
591 case JCONN_STATE_CONNECTED:
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
592 scr_LogPrint("+ JCONN_STATE_CONNECTED");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
593 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
594
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
595 case JCONN_STATE_AUTH:
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
596 scr_LogPrint("+ JCONN_STATE_AUTH");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
597 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
598
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
599 case JCONN_STATE_ON:
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
600 scr_LogPrint("+ JCONN_STATE_ON");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
601 online = TRUE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
602 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
603
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
604 case JCONN_STATE_CONNECTING:
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
605 scr_LogPrint("+ JCONN_STATE_CONNECTING");
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
606 break;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
607
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
608 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
609 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
610 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
611 previous_state = state;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
612 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
613
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
614 void packethandler(jconn conn, jpacket packet)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
615 {
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
616 char *p, *r;
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
617 const char *m;
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
618 xmlnode x, y;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
619 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
620 char *ns=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
621 char *id=NULL;
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
622 enum imstatus ust;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
623 // int npos;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
624
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
625 jb_reset_keepalive(); // reset keepalive delay
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
626 jpacket_reset(packet);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
627
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
628 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
629 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
630
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
631 switch (packet->type) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
632 case JPACKET_MESSAGE:
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
633 {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
634 char *tmp = NULL;
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
635 time_t timestamp = 0;
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
636
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
637 x = xmlnode_get_tag(packet->x, "body");
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
638 p = xmlnode_get_data(x); if (p) body = p;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
639
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
640 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL)
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
641 if ((p = xmlnode_get_data(x)) != NULL) {
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
642 tmp = g_new(char, strlen(body)+strlen(p)+4);
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
643 *tmp = '[';
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
644 strcpy(tmp+1, p);
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
645 strcat(tmp, "]\n");
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
646 strcat(tmp, body);
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
647 body = tmp;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
648 }
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
649
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
650 /* there can be multiple <x> tags. we're looking for one with
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
651 xmlns = jabber:x:encrypted */
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
652
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
653 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
654 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
655 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
656 !strcasecmp(p, "jabber:x:encrypted"))
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
657 if ((p = xmlnode_get_data(x)) != NULL) {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
658 enc = p;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
659 break;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
660 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
661 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
662
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
663 // Timestamp?
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
664 if ((x = xmlnode_get_tag(packet->x, "x")) != NULL) {
241
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 237
diff changeset
665 if ((p = xmlnode_get_attrib(x, "stamp")) != NULL)
8584f919d9b9 [/trunk] Changeset 254 by mikael
mikael
parents: 237
diff changeset
666 timestamp = from_iso8601(p, 1);
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
667 }
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
668
165
b4921dbf8709 [/trunk] Changeset 177 by mikael
mikael
parents: 164
diff changeset
669 if (from && body)
223
925bb5fa85ac [/trunk] Changeset 235 by mikael
mikael
parents: 221
diff changeset
670 gotmessage(type, from, body, enc, timestamp);
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
671 if (tmp)
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
672 g_free(tmp);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
673 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
674 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
675
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
676 case JPACKET_IQ:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
677 if (!strcmp(type, "result")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
678
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
679 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
680 int iid = atoi(p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
681
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
682 ut_WriteLog("iid = %d\n", iid);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
683 if (iid == s_id) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
684 if (!regmode) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
685 if (jstate == STATE_GETAUTH) {
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
686 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
687 if (!xmlnode_get_tag(x, "digest")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
688 jc->sid = 0;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
689 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
690
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
691 s_id = atoi(jab_auth(jc));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
692 jstate = STATE_SENDAUTH;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
693 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
694 gotloggedin();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
695 jstate = STATE_LOGGED;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
696 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
697 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
698 regdone = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
699 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
700 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
701 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
702
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
703 if (!strcmp(p, "VCARDreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
704 x = xmlnode_get_firstchild(packet->x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
705 if (!x) x = packet->x;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
706
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
707 //jhook.gotvcard(ic, x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
708 scr_LogPrint("Got VCARD");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
709 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
710 } else if (!strcmp(p, "versionreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
711 // jhook.gotversion(ic, packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
712 scr_LogPrint("Got version");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
713 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
714 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
715 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
716
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
717 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
718 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
719
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
720 if (!strcmp(ns, NS_ROSTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
721 gotroster(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
722 } else if (!strcmp(ns, NS_AGENTS)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
723 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
724 const char *alias = xmlnode_get_attrib(y, "jid");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
725
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
726 if (alias) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
727 const char *name = xmlnode_get_tag_data(y, "name");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
728 const char *desc = xmlnode_get_tag_data(y, "description");
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
729 // const char *service = xmlnode_get_tag_data(y, "service"); TODO
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
730 enum agtype atype = unknown;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
731
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
732 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
733 if (xmlnode_get_tag(y, "transport")) atype = transport; else
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
734 if (xmlnode_get_tag(y, "search")) atype = search;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
735
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
736 if (atype == transport) {
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
737 char *cleanjid = jidtodisp(alias);
194
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
738 roster_add_user(cleanjid, NULL, JABBER_AGENT_GROUP,
a05d5c3876ec [/trunk] Changeset 206 by mikael
mikael
parents: 192
diff changeset
739 ROSTER_TYPE_AGENT);
192
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
740 g_free(cleanjid);
62bc2992216b [/trunk] Changeset 204 by mikael
mikael
parents: 165
diff changeset
741 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
742 if (alias && name && desc) {
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
743 scr_LogPrint("Agent: %s / %s / %s / type=%d",
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
744 alias, name, desc, atype);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
745
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
746 if (atype == search) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
747 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
748 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
749 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
750 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
751 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
752 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
753
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
754 if (xmlnode_get_tag(y, "register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
755 x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
756 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
757 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
758 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
759 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
760 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
761 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
762 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
763 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
764
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
765 /*
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
766 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
767 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
768 _("Default Jabber conference server"), agent::atGroupchat));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
769
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
770 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
771 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
772 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)"";
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
773
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
774 if (!strcmp(id, "Agent info")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
775 // jhook.gotagentinfo(packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
776 scr_LogPrint("Got agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
777 } else if (!strcmp(id, "Lookup")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
778 // jhook.gotsearchresults(packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
779 scr_LogPrint("Got search results");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
780 } else if (!strcmp(id, "Register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
781 x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
782 xmlnode_put_attrib(x, "to", from);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
783 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
784 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
785 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
786 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
787
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
788 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
789 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
790 } else if (!strcmp(type, "set")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
791 } else if (!strcmp(type, "error")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
792 char *name=NULL, *desc=NULL;
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
793 int code = 0;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
794
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
795 x = xmlnode_get_tag(packet->x, "error");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
796 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
797 p = xmlnode_get_attrib(x, "id"); if (p) name = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
798 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
799
231
193c08454aac [/trunk] Changeset 244 by mikael
mikael
parents: 223
diff changeset
800 #if 0
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
801 switch(code) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
802 case 401: /* Unauthorized */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
803 case 302: /* Redirect */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
804 case 400: /* Bad request */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
805 case 402: /* Payment Required */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
806 case 403: /* Forbidden */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
807 case 404: /* Not Found */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
808 case 405: /* Not Allowed */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
809 case 406: /* Not Acceptable */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
810 case 407: /* Registration Required */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
811 case 408: /* Request Timeout */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
812 case 409: /* Conflict */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
813 case 500: /* Internal Server Error */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
814 case 501: /* Not Implemented */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
815 case 502: /* Remote Server Error */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
816 case 503: /* Service Unavailable */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
817 case 504: /* Remote Server Timeout */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
818 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
819 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
820 if (!regmode) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
821 face.log(desc.empty() ?
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
822 _("+ [jab] error %d") :
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
823 _("+ [jab] error %d: %s"),
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
824 code, desc.c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
825
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
826 if (!jhook.flogged && code != 501) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
827 close(jc->fd);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
828 jc->fd = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
829 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
830
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
831 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
832 jhook.regerr = desc;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
833
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
834 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
835 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
836 }
231
193c08454aac [/trunk] Changeset 244 by mikael
mikael
parents: 223
diff changeset
837 #endif
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
838 scr_LogPrint("Error code from server (%d)", code);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
839
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
840 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
841 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
842
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
843 case JPACKET_PRESENCE:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
844 x = xmlnode_get_tag(packet->x, "show");
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
845 ust = available;
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 if (x) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
848 p = xmlnode_get_data(x); if (p) ns = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
849
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
850 if (ns) {
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
851 if (!strcmp(ns, "away")) ust = away;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
852 else if (!strcmp(ns, "dnd")) ust = dontdisturb;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
853 else if (!strcmp(ns, "xa")) ust = notavail;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
854 else if (!strcmp(ns, "chat")) ust = freeforchat;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
855 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
856 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
857
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
858 if (type && !strcmp(type, "unavailable"))
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
859 ust = offline;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
860
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
861 if ((x = xmlnode_get_tag(packet->x, "status")) != NULL)
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
862 p = utf8_decode(xmlnode_get_data(x));
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
863 else
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
864 p = NULL;
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
865
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
866 r = jidtodisp(from);
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
867 // Call hk_statuschange() if status has changed or if the
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
868 // status message is different
319
db45371106a5 Cosmetic change
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
869 m = roster_getstatusmsg(r);
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 311
diff changeset
870 if ((ust != roster_getstatus(r)) || (p && (!m || strcmp(p, m))))
221
73f6ce668ba8 [/trunk] Changeset 233 by mikael
mikael
parents: 213
diff changeset
871 hk_statuschange(r, 0, ust, p);
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
872 g_free(r);
321
59193965f2cb Convert status messages to/from UTF-8
Mikael Berthe <mikael@lilotux.net>
parents: 319
diff changeset
873 if (p) free(p);
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
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
876 case JPACKET_S10N:
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
877 scr_LogPrint("Received (un)subscription packet (type=%s)",
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 194
diff changeset
878 ((type) ? type : ""));
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
879
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
880 if (!strcmp(type, "subscribe")) {
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
881 int isagent;
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
882 r = jidtodisp(from);
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
883 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0;
159
ba51d1737086 [/trunk] Changeset 171 by mikael
mikael
parents: 154
diff changeset
884 g_free(r);
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
885 scr_LogPrint("isagent=%d", isagent); // XXX DBG
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
886 if (!isagent) {
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
887 scr_LogPrint("<%s> wants to subscribe "
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
888 "to your network presence updates", from);
125
1bf1a1233b88 [/trunk] Changeset 138 by mikael
mikael
parents: 124
diff changeset
889 // FIXME we accept everybody...
1bf1a1233b88 [/trunk] Changeset 138 by mikael
mikael
parents: 124
diff changeset
890 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0);
1bf1a1233b88 [/trunk] Changeset 138 by mikael
mikael
parents: 124
diff changeset
891 jab_send(jc, x);
1bf1a1233b88 [/trunk] Changeset 138 by mikael
mikael
parents: 124
diff changeset
892 xmlnode_free(x);
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
893 } else {
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
894 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
895 jab_send(jc, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
896 xmlnode_free(x);
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
897 }
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
898 } else if (!strcmp(type, "unsubscribe")) {
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
899 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
900 jab_send(jc, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
901 xmlnode_free(x);
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
902 scr_LogPrint("<%s> has unsubscribed to your presence updates", from);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
903 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
904 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
905
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
906 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
907 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
908 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
909 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
910