annotate mcabber/src/jabglue.c @ 114:065d8368c36b

[/trunk] Changeset 128 by mikael * Don't send a keepalive (reset it) when we send a message.
author mikael
date Sun, 24 Apr 2005 20:30:33 +0000
parents 8ac67e951eab
children 1e7e59775f12
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
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
24 #include "../libjabber/jabber.h"
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
25 #include "jabglue.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
26 #include "roster.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
27 #include "screen.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
28 #include "hooks.h"
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
29 #include "utils.h"
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
30
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
31 #define JABBERPORT 5222
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
32 #define JABBERSSLPORT 5223
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
33
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
34 jconn jc;
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
35 time_t LastPingTime;
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
36 unsigned int KeepaliveDelay;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
37 static int s_id = 1; // FIXME which use??
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
38 static int regmode, regdone;
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
39 unsigned char online;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
40
46
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
41 char imstatus2char[imstatus_size] = {
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
42 '_', 'o', 'i', 'f', 'd', 'c', 'n', 'a'
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
43 };
f22e1d120606 [/trunk] Changeset 62 by mikael
mikael
parents: 43
diff changeset
44
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
45 static enum {
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
46 STATE_CONNECTING,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
47 STATE_GETAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
48 STATE_SENDAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
49 STATE_LOGGED
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
50 } jstate;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
51
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
52
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
53 void statehandler(jconn, int);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
54 void packethandler(jconn, jpacket);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
55
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
56 void screen_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
57 {
36
8f1a5e79ca40 [/trunk] Changeset 52 by mikael
mikael
parents: 35
diff changeset
58 scr_LogPrint("%03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
59 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
60
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
61 void file_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
62 {
36
8f1a5e79ca40 [/trunk] Changeset 52 by mikael
mikael
parents: 35
diff changeset
63 ut_WriteLog("%03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
64 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
65
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
66 void big_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
67 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
68 screen_logger(j, io, buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
69 file_logger(j, io, buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
70 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
71
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
72 /*
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
73 static void jidsplit(const char *jid, char **user, char **host,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
74 char **res)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
75 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
76 char *tmp, *ptr;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
77 tmp = strdup(jid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
78
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
79 if ((ptr = strchr(tmp, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
80 *res = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
81 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
82 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
83 *res = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
84
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
85 if ((ptr = strchr(tmp, '@')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
86 *host = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
87 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
88 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
89 *host = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
90
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
91 *user = strdup(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
92 free(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
93 }
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
94 */
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
95
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
96 char *jidtodisp(const char *jid)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
97 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
98 char *ptr;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
99 char *alias = strdup(jid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
100 if ((ptr = strchr(alias, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
101 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
102 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
103 return alias;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
104 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
105
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
106 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
107 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
108 if (!port) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
109 if (ssl)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
110 port = JABBERSSLPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
111 else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
112 port = JABBERPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
113 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
114
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
115 if (jc)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
116 free(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
117
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
118 jc = jab_new((char*)jid, (char*)pass, port, ssl);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
119
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
120 jab_logger(jc, file_logger);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
121 jab_packet_handler(jc, &packethandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
122 jab_state_handler(jc, &statehandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
123
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
124 if (jc->user) {
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
125 online = TRUE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
126 jstate = STATE_CONNECTING;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
127 statehandler(0, -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
128 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
129 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
130
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
131 return jc;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
132 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
133
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
134 void jb_disconnect(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
135 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
136 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
137 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
138
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
139 inline void jb_reset_keepalive()
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
140 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
141 time(&LastPingTime);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
142 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
143
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
144 void jb_keepalive()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
145 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
146 if (jc && online)
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
147 jab_send_raw(jc, " \t ");
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
148 jb_reset_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
149 }
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
150
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
151 void jb_set_keepalive_delay(unsigned int delay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
152 {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
153 KeepaliveDelay = delay;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
154 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
155
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
156 void jb_main()
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
157 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
158 xmlnode x, z;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
159 char *cid;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
160
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
161 if (!online)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
162 return;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
163 if (jc && jc->state == JCONN_STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
164 jab_start(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
165 return;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
166 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
167
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
168 jab_poll(jc, 50);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
169
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
170 if (jstate == STATE_CONNECTING) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
171 if (jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
172 x = jutil_iqnew(JPACKET__GET, NS_AUTH);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
173 cid = jab_getid(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
174 xmlnode_put_attrib(x, "id", cid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
175 // id = atoi(cid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
176
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
177 z = xmlnode_insert_tag(xmlnode_get_tag(x, "query"), "username");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
178 xmlnode_insert_cdata(z, jc->user->user, (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
179 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
180 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
181
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
182 jstate = STATE_GETAUTH;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
183 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
184
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
185 if (!jc || jc->state == JCONN_STATE_OFF) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
186 scr_LogPrint("Unable to connect to the server");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
187 online = FALSE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
188 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
189 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
190
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
191 if (!jc) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
192 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
193 } else if (jc->state == JCONN_STATE_OFF || jc->fd == -1) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
194 statehandler(jc, JCONN_STATE_OFF);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
195 }
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
196
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
197 // Keepalive
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
198 if (KeepaliveDelay) {
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
199 time_t now;
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
200 time(&now);
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
201 if (now > LastPingTime + KeepaliveDelay)
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
202 jb_keepalive();
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
203 }
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
204 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
205
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
206 void setjabberstatus(enum imstatus st, char *msg)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
207 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
208 xmlnode x = jutil_presnew(JPACKET__UNKNOWN, 0, 0);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
209
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
210 switch(st) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
211 case away:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
212 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "away",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
213 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
214 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
215
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
216 case occupied:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
217 case dontdisturb:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
218 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "dnd",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
219 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
220 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
221
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
222 case freeforchat:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
223 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "chat",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
224 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
225 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
226
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
227 case notavail:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
228 xmlnode_insert_cdata(xmlnode_insert_tag(x, "show"), "xa",
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
229 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
230 break;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
231
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
232 case invisible:
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
233 xmlnode_put_attrib(x, "type", "invisible");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
234 break;
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
235
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
236 default:
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
237 break;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
238 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
239
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
240 /* TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
241 if (!add["prio"].empty())
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
242 xmlnode_insert_cdata(xmlnode_insert_tag(x, "priority"),
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
243 add["prio"].c_str(), (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
244 */
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
245
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
246 if (!msg || !*msg) {
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
247 msg = ""; // FIXME
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
248 //msg = imstatus2str(st);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
249 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
250
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
251 xmlnode_insert_cdata(xmlnode_insert_tag(x, "status"), msg,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
252 (unsigned) -1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
253
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
254 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
255 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
256
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
257 //sendvisibility();
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
258
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
259 // XXX logger.putourstatus(proto, getstatus(), ourstatus = st);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
260 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
261
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
262 void jb_send_msg(const char *jid, const char *text)
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
263 {
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
264 xmlnode x = jutil_msgnew(TMSG_CHAT, (char*)jid, 0, (char*)text);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
265 jab_send(jc, x);
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
266 xmlnode_free(x);
114
065d8368c36b [/trunk] Changeset 128 by mikael
mikael
parents: 113
diff changeset
267 jb_reset_keepalive();
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
268 }
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
269
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
270 void postlogin()
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
271 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
272 //int i;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
273
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
274 //flogged = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
275 //ourstatus = available;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
276
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
277 //setautostatus(jhook.manualstatus);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
278
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
279 setjabberstatus(1, "I'm here!");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
280 buddylist_build();
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
281 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
282 for (i = 0; i < clist.count; i++) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
283 c = (icqcontact *) clist.at(i);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
284
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
285 if (c->getdesc().pname == proto)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
286 if (ischannel(c))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
287 if (c->getbasicinfo().requiresauth)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
288 c->setstatus(available);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
289 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
290 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
291
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
292 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
293 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
294 agents.begin()->params[agent::ptRegister].enabled = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
295
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
296 string buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
297 ifstream f(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
298
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
299 if (f.is_open()) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
300 icqcontact *c = clist.get(contactroot);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
301
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
302 c->clear();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
303 icqcontact::basicinfo bi = c->getbasicinfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
304 icqcontact::reginfo ri = c->getreginfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
305
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
306 ri.service = agents.begin()->name;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
307 getstring(f, buf); c->setnick(buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
308 getstring(f, buf); bi.email = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
309 getstring(f, buf); bi.fname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
310 getstring(f, buf); bi.lname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
311 f.close();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
312
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
313 c->setbasicinfo(bi);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
314 c->setreginfo(ri);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
315
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
316 sendupdateuserinfo(*c);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
317 unlink(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
318 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
319 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
320 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
321
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
322 void gotloggedin(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
323 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
324 xmlnode x;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
325
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
326 x = jutil_iqnew(JPACKET__GET, NS_AGENTS);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
327 xmlnode_put_attrib(x, "id", "Agent List");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
328 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
329 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
330
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
331 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
332 xmlnode_put_attrib(x, "id", "Roster");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
333 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
334 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
335 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
336
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
337 void gotroster(xmlnode x)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
338 {
33
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
339 xmlnode y, z;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
340
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
341 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
342 const char *alias = xmlnode_get_attrib(y, "jid");
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
343 //const char *sub = xmlnode_get_attrib(y, "subscription"); // TODO Not used
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
344 const char *name = xmlnode_get_attrib(y, "name");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
345 const char *group = NULL;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
346
33
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
347 z = xmlnode_get_tag(y, "group");
bb9172f2cbf1 [/trunk] Changeset 49 by mikael
mikael
parents: 32
diff changeset
348 if (z) group = xmlnode_get_data(z);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
349
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
350 if (alias) {
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
351 char *buddyname;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
352 if (name)
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
353 buddyname = (char*)name;
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
354 else
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
355 buddyname = jidtodisp(alias);
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
356
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
357 roster_add_user(alias, buddyname, group, ROSTER_TYPE_USER);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
358 if (!name)
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
359 free(buddyname);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
360 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
361 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
362
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
363 postlogin();
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
364 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
365
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
366 void gotmessage(char *type, const char *from, const char *body,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
367 const char *enc)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
368 {
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
369 char *jid;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
370
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
371 /*
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
372 //char *u, *h, *r;
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
373 //jidsplit(from, &u, &h, &r);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
374 // Maybe we should remember the resource?
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
375 if (r)
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
376 scr_LogPrint("There is an extra part in message (resource?): %s", r);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
377 //scr_LogPrint("Msg from <%s>, type=%s", jidtodisp(from), type);
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
378 */
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
379
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
380 jid = jidtodisp(from);
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
381 hk_message_in(jid, 0, body);
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
382 free(jid);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
383 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
384
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
385 void statehandler(jconn conn, int state)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
386 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
387 static int previous_state = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
388
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
389 ut_WriteLog("StateHandler called (state=%d).\n", state);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
390
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
391 switch(state) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
392 case JCONN_STATE_OFF:
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
393
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
394 online = FALSE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
395
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
396 if (previous_state != JCONN_STATE_OFF) {
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
397 scr_LogPrint("+ JCONN_STATE_OFF");
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
398 /*
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
399 jhook.roster.clear();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
400 jhook.agents.clear();
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
401 */
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
402 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
403 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
404
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
405 case JCONN_STATE_CONNECTED:
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
406 scr_LogPrint("+ JCONN_STATE_CONNECTED");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
407 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
408
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
409 case JCONN_STATE_AUTH:
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
410 scr_LogPrint("+ JCONN_STATE_AUTH");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
411 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
412
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
413 case JCONN_STATE_ON:
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
414 scr_LogPrint("+ JCONN_STATE_ON");
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
415 online = TRUE;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
416 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
417
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
418 case JCONN_STATE_CONNECTING:
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
419 scr_LogPrint("+ JCONN_STATE_CONNECTING");
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
420 break;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
421
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
422 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
423 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
424 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
425 previous_state = state;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
426 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
427
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
428 void packethandler(jconn conn, jpacket packet)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
429 {
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
430 char *p, *r;
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
431 xmlnode x, y;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
432 // string from, type, body, enc, ns, id, u, h, s;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
433 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
434 char *ns=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
435 char *id=NULL;
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
436 enum imstatus ust;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
437 // int npos;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
438
112
edb5591e2e64 [/trunk] Changeset 126 by mikael
mikael
parents: 91
diff changeset
439 jb_reset_keepalive(); // reset keepalive delay
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
440 jpacket_reset(packet);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
441
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
442 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
443 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
444
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
445 switch (packet->type) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
446 case JPACKET_MESSAGE:
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
447 {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
448 char *tmp = NULL;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
449 x = xmlnode_get_tag(packet->x, "body");
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
450 p = xmlnode_get_data(x); if (p) body = p;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
451
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
452 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL)
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
453 if ((p = xmlnode_get_data(x)) != NULL) {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
454 tmp = malloc(strlen(body)+strlen(p)+3);
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
455 *tmp = '[';
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
456 strcpy(tmp+1, p);
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
457 strcat(tmp, "]\n");
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
458 strcat(tmp, body);
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
459 body = tmp;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
460 }
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
461
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
462 /* there can be multiple <x> tags. we're looking for one with
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
463 xmlns = jabber:x:encrypted */
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
464
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
465 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
466 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
467 if ((p = xmlnode_get_attrib(x, "xmlns")) &&
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
468 !strcasecmp(p, "jabber:x:encrypted"))
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
469 if ((p = xmlnode_get_data(x)) != NULL) {
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
470 enc = p;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
471 break;
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
472 }
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
473 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
474
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
475 if (body)
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
476 gotmessage(type, from, body, enc);
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
477 if (tmp)
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
478 free(tmp);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
479 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
480 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
481
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
482 case JPACKET_IQ:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
483 if (!strcmp(type, "result")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
484
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
485 if ((p = xmlnode_get_attrib(packet->x, "id")) != NULL) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
486 int iid = atoi(p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
487
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
488 ut_WriteLog("iid = %d\n", iid);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
489 if (iid == s_id) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
490 if (!regmode) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
491 if (jstate == STATE_GETAUTH) {
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
492 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL)
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
493 if (!xmlnode_get_tag(x, "digest")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
494 jc->sid = 0;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
495 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
496
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
497 s_id = atoi(jab_auth(jc));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
498 jstate = STATE_SENDAUTH;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
499 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
500 gotloggedin();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
501 jstate = STATE_LOGGED;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
502 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
503 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
504 regdone = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
505 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
506 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
507 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
508
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
509 if (!strcmp(p, "VCARDreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
510 x = xmlnode_get_firstchild(packet->x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
511 if (!x) x = packet->x;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
512
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
513 //jhook.gotvcard(ic, x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
514 scr_LogPrint("Got VCARD");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
515 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
516 } else if (!strcmp(p, "versionreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
517 // jhook.gotversion(ic, packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
518 scr_LogPrint("Got version");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
519 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
520 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
521 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
522
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
523 if ((x = xmlnode_get_tag(packet->x, "query")) != NULL) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
524 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
525
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
526 if (!strcmp(ns, NS_ROSTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
527 gotroster(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
528 } else if (!strcmp(ns, NS_AGENTS)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
529 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
530 const char *alias = xmlnode_get_attrib(y, "jid");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
531
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
532 if (alias) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
533 const char *name = xmlnode_get_tag_data(y, "name");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
534 const char *desc = xmlnode_get_tag_data(y, "description");
51
85bbc6ed3796 [/trunk] Changeset 67 by mikael
mikael
parents: 46
diff changeset
535 // const char *service = xmlnode_get_tag_data(y, "service"); TODO
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
536 enum agtype atype = unknown;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
537
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
538 if (xmlnode_get_tag(y, "groupchat")) atype = groupchat; else
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
539 if (xmlnode_get_tag(y, "transport")) atype = transport; else
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
540 if (xmlnode_get_tag(y, "search")) atype = search;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
541
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
542 if (alias && name && desc) {
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
543 scr_LogPrint("Agent: %s / %s / %s / type=%d",
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
544 alias, name, desc, atype);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
545
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
546 if (atype == search) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
547 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
548 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
549 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
550 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
551 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
552 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
553
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
554 if (xmlnode_get_tag(y, "register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
555 x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
556 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
557 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
558 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
559 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
560 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
561 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
562 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
563 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
564
37
1441ba37a5c1 [/trunk] Changeset 53 by mikael
mikael
parents: 36
diff changeset
565 /*
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
566 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
567 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
568 _("Default Jabber conference server"), agent::atGroupchat));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
569
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
570 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
571 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
572 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)"";
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
573
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
574 if (!strcmp(id, "Agent info")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
575 // jhook.gotagentinfo(packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
576 scr_LogPrint("Got agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
577 } else if (!strcmp(id, "Lookup")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
578 // jhook.gotsearchresults(packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
579 scr_LogPrint("Got search results");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
580 } else if (!strcmp(id, "Register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
581 x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
582 xmlnode_put_attrib(x, "to", from);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
583 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
584 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
585 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
586 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
587
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
588 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
589 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
590 } else if (!strcmp(type, "set")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
591 } else if (!strcmp(type, "error")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
592 char *name=NULL, *desc=NULL;
52
7d1c22aa2e5f [/trunk] Changeset 68 by mikael
mikael
parents: 51
diff changeset
593 int code = 0;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
594
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
595 x = xmlnode_get_tag(packet->x, "error");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
596 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
597 p = xmlnode_get_attrib(x, "id"); if (p) name = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
598 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
599
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
600 switch(code) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
601 case 401: /* Unauthorized */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
602 case 302: /* Redirect */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
603 case 400: /* Bad request */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
604 case 402: /* Payment Required */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
605 case 403: /* Forbidden */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
606 case 404: /* Not Found */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
607 case 405: /* Not Allowed */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
608 case 406: /* Not Acceptable */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
609 case 407: /* Registration Required */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
610 case 408: /* Request Timeout */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
611 case 409: /* Conflict */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
612 case 500: /* Internal Server Error */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
613 case 501: /* Not Implemented */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
614 case 502: /* Remote Server Error */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
615 case 503: /* Service Unavailable */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
616 case 504: /* Remote Server Timeout */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
617 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
618 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
619 if (!regmode) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
620 face.log(desc.empty() ?
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
621 _("+ [jab] error %d") :
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
622 _("+ [jab] error %d: %s"),
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
623 code, desc.c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
624
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
625 if (!jhook.flogged && code != 501) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
626 close(jc->fd);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
627 jc->fd = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
628 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
629
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
630 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
631 jhook.regerr = desc;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
632
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
633 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
634 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
635 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
636 scr_LogPrint("Error code from server (%d)", code);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
637
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
638 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
639 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
640
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
641 case JPACKET_PRESENCE:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
642 x = xmlnode_get_tag(packet->x, "show");
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
643 ust = available;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
644
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
645 if (x) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
646 p = xmlnode_get_data(x); if (p) ns = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
647
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
648 if (ns) {
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
649 if (!strcmp(ns, "away")) ust = away;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
650 else if (!strcmp(ns, "dnd")) ust = dontdisturb;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
651 else if (!strcmp(ns, "xa")) ust = notavail;
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
652 else if (!strcmp(ns, "chat")) ust = freeforchat;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
653 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
654 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
655
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
656 if (type && !strcmp(type, "unavailable")) {
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
657 ust = offline;
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
658 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
659
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
660 r = jidtodisp(from);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
661 /*
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
662 if (ust != roster_getstatus(r))
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
663 scr_LogPrint("Buddy status has changed: [%c>%c] <%s>",
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
664 imstatus2char[roster_getstatus(r)], imstatus2char[ust], r);
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
665 roster_setstatus(r, ust);
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
666 */
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
667 if (ust != roster_getstatus(r))
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 112
diff changeset
668 hk_statuschange(r, 0, ust);
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
669 free(r);
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
670 buddylist_build();
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 52
diff changeset
671 scr_DrawRoster();
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
672 /*
35
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
673 if (x = xmlnode_get_tag(packet->x, "status"))
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
674 if (p = xmlnode_get_data(x))
a8ceaa3005fd [/trunk] Changeset 51 by mikael
mikael
parents: 33
diff changeset
675 scr_LogPrint("Away msg: %s", p);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
676 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
677 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
678
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
679 case JPACKET_S10N:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
680 scr_LogPrint("Received subscription packet");
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
681 if (type) scr_LogPrint("Type=%s", type);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
682
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
683 if (!strcmp(type, "subscribe")) {
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
684 int isagent;
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
685 r = jidtodisp(from);
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
686 isagent = (roster_gettype(r) & ROSTER_TYPE_AGENT) != 0;
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
687 free(r);
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
688 scr_LogPrint("isagent=%d", isagent); // XXX DBG
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
689 if (!isagent) {
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
690 scr_LogPrint("<%s> wants to subscribe "
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
691 "to your network presence updates", from);
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
692 } else {
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
693 x = jutil_presnew(JPACKET__SUBSCRIBED, from, 0);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
694 jab_send(jc, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
695 xmlnode_free(x);
91
60eac956ce18 [/trunk] Changeset 105 by mikael
mikael
parents: 81
diff changeset
696 }
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
697 } else if (!strcmp(type, "unsubscribe")) {
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
698 x = jutil_presnew(JPACKET__UNSUBSCRIBED, from, 0);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
699 jab_send(jc, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
700 xmlnode_free(x);
43
b8bd163be431 [/trunk] Changeset 59 by mikael
mikael
parents: 41
diff changeset
701 scr_LogPrint("<%s> has unsubscribed to your presence updates", from);
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
702 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
703 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
704
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
705 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
706 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
707 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
708 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
709