annotate mcabber/src/jabglue.c @ 81:0bd578421ce9

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