annotate mcabber/src/jabglue.c @ 46:f22e1d120606

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