annotate mcabber/src/jabglue.c @ 31:0f0fbd0c4a7f

[/trunk] Changeset 47 by mikael * Work on libjabber integration.
author mikael
date Mon, 04 Apr 2005 11:51:48 +0000
parents 86837ff0554c
children 1f870e304168
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
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
36 static enum {
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
37 STATE_CONNECTING,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
38 STATE_GETAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
39 STATE_SENDAUTH,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
40 STATE_LOGGED
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
41 } jstate;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
42
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
43
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
44 void statehandler(jconn, int);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
45 void packethandler(jconn, jpacket);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
46
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
47 void screen_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
48 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
49 scr_LogPrint("%.03s: %s", ((io == 0) ? "OUT" : "IN"), buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
50 }
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 file_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
53 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
54 ut_WriteLog("%.03s: %s\n", ((io == 0) ? "OUT" : "IN"), buf);
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 big_logger(jconn j, int io, const char *buf)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
58 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
59 screen_logger(j, io, buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
60 file_logger(j, io, buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
61 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
62
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
63 static void jidsplit(const char *jid, char **user, char **host,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
64 char **res)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
65 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
66 char *tmp, *ptr;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
67 tmp = strdup(jid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
68
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
69 if ((ptr = strchr(tmp, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
70 *res = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
71 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
72 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
73 *res = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
74
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
75 if ((ptr = strchr(tmp, '@')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
76 *host = strdup(ptr+1);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
77 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
78 } else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
79 *host = NULL;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
80
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
81 *user = strdup(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
82 free(tmp);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
83 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
84
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
85 char *jidtodisp(const char *jid)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
86 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
87 char *ptr;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
88 char *alias = strdup(jid);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
89 if ((ptr = strchr(alias, '/')) != NULL) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
90 *ptr = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
91 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
92 return alias;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
93 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
94
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
95 jconn jb_connect(const char *servername, unsigned int port, int ssl,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
96 const char *jid, const char *pass,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
97 const char *resource)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
98 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
99 if (!port) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
100 if (ssl)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
101 port = JABBERSSLPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
102 else
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
103 port = JABBERPORT;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
104 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
105
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
106 if (jc)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
107 free(jc);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
108
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
109 //jc = jab_new(jid, pass, port, ssl);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
110 jc = jab_new("mctest@lilotux.net/mcabber", (char*)pass, (int)port, ssl);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
111
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
112 jab_logger(jc, big_logger);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
113 jab_packet_handler(jc, &packethandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
114 jab_state_handler(jc, &statehandler);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
115
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
116 if (jc->user) {
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
117 //fonline = TRUE;
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
118 scr_LogPrint("+ State_Connecting");
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) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
218 msg = "unknownStatus";
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
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
233 void postlogin()
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
234 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
235 //int i;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
236
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
237 //flogged = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
238 //ourstatus = available;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
239
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
240 //setautostatus(jhook.manualstatus);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
241
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
242 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
243 for (i = 0; i < clist.count; i++) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
244 c = (icqcontact *) clist.at(i);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
245
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
246 if (c->getdesc().pname == proto)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
247 if (ischannel(c))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
248 if (c->getbasicinfo().requiresauth)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
249 c->setstatus(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 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
252
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
253 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
254 agents.insert(agents.begin(), agent("vcard", "Jabber VCard", "", agent::atStandard));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
255 agents.begin()->params[agent::ptRegister].enabled = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
256
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
257 string buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
258 ifstream f(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
259
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
260 if (f.is_open()) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
261 icqcontact *c = clist.get(contactroot);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
262
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
263 c->clear();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
264 icqcontact::basicinfo bi = c->getbasicinfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
265 icqcontact::reginfo ri = c->getreginfo();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
266
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
267 ri.service = agents.begin()->name;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
268 getstring(f, buf); c->setnick(buf);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
269 getstring(f, buf); bi.email = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
270 getstring(f, buf); bi.fname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
271 getstring(f, buf); bi.lname = buf;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
272 f.close();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
273
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
274 c->setbasicinfo(bi);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
275 c->setreginfo(ri);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
276
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
277 sendupdateuserinfo(*c);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
278 unlink(conf.getconfigfname("jabber-infoset").c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
279 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
280 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
281 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
282
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
283 void gotloggedin(void)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
284 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
285 xmlnode x;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
286
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
287 /*
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
288 x = jutil_iqnew(JPACKET__GET, NS_AGENTS);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
289 xmlnode_put_attrib(x, "id", "Agent List");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
290 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
291 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
292 */
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
293
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
294 x = jutil_iqnew(JPACKET__GET, NS_ROSTER);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
295 xmlnode_put_attrib(x, "id", "Roster");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
296 jab_send(jc, x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
297 xmlnode_free(x);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
298 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
299
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
300 void gotroster(xmlnode x)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
301 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
302 xmlnode y; // z;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
303
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
304 for (y = xmlnode_get_tag(x, "item"); y; y = xmlnode_get_nextsibling(y)) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
305 const char *alias = xmlnode_get_attrib(y, "jid");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
306 const char *sub = xmlnode_get_attrib(y, "subscription");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
307 const char *name = xmlnode_get_attrib(y, "name");
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
308 //const char *group = 0;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
309
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
310 //z = xmlnode_get_tag(y, "group");
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
311 //if (z) group = xmlnode_get_data(z);
29
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
312
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
313 if (alias) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
314 char *buddyname = jidtodisp(alias);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
315 if (buddyname) {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
316 scr_LogPrint("New buddy: %s", buddyname);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
317 free(buddyname);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
318 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
319 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
320 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
321
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
322 postlogin();
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
323 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
324
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
325 void gotmessage(char *type, const char *from, const char *body,
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
326 const char *enc)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
327 {
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
328 char *u, *h, *r;
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
329
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
330 jidsplit(from, &u, &h, &r);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
331 if (*r)
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
332 scr_LogPrint("There is an extra part in message: %s", *r);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
333 scr_WriteIncomingMessage(from, body);
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
334 }
86837ff0554c [/trunk] Changeset 45 by mikael
mikael
parents:
diff changeset
335
31
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
336 void statehandler(jconn conn, int state)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
337 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
338 static int previous_state = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
339
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
340 scr_LogPrint("StateHandler called (%d).\n", state);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
341 ut_WriteLog("StateHandler called (%d).\n", state);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
342
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
343 switch(state) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
344 case JCONN_STATE_OFF:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
345 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
346 jhook.flogged = jhook.fonline = FALSE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
347
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
348 if (previous_state != JCONN_STATE_OFF) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
349 logger.putourstatus(jhook.proto, jhook.getstatus(), jhook.ourstatus = offline);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
350 jhook.log(logDisconnected);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
351 jhook.roster.clear();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
352 jhook.agents.clear();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
353 clist.setoffline(jhook.proto);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
354 face.update();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
355 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
356 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
357 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
358
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
359 case JCONN_STATE_CONNECTED:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
360 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
361
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
362 case JCONN_STATE_AUTH:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
363 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
364
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
365 case JCONN_STATE_ON:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
366 // if (regmode) jhook.fonline = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
367 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
368
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
369 default:
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 previous_state = state;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
373 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
374
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
375 void packethandler(jconn conn, jpacket packet)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
376 {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
377 char *p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
378 xmlnode x; // , y;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
379 // string from, type, body, enc, ns, id, u, h, s;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
380 char *from=NULL, *type=NULL, *body=NULL, *enc=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
381 char *ns=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
382 char *id=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
383 // imstatus ust;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
384 // int npos;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
385 // bool isagent;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
386
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
387 scr_LogPrint("Received a packet");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
388 ut_WriteLog("Received a packet\n");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
389
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
390 jpacket_reset(packet);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
391
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
392 p = xmlnode_get_attrib(packet->x, "from"); if (p) from = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
393 p = xmlnode_get_attrib(packet->x, "type"); if (p) type = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
394 //imcontact ic(jidtodisp(from), jhook.proto);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
395
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
396 switch (packet->type) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
397 case JPACKET_MESSAGE:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
398 x = xmlnode_get_tag(packet->x, "body");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
399 p = xmlnode_get_data(x); if (p) body = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
400
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
401 if ((x = xmlnode_get_tag(packet->x, "subject")) != NULL)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
402 if ((p = xmlnode_get_data(x)) != NULL) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
403 char *tmp = malloc(strlen(body)+strlen(p)+3);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
404 strcpy(tmp, p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
405 strcat(tmp, ": ");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
406 strcat(tmp, body);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
407 body = tmp; // XXX check it is free'd later...
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
408 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
409
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
410 /* there can be multiple <x> tags. we're looking for one with
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
411 xmlns = jabber:x:encrypted */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
412
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
413 for (x = xmlnode_get_firstchild(packet->x); x; x = xmlnode_get_nextsibling(x)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
414 if ((p = xmlnode_get_name(x)) && !strcmp(p, "x"))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
415 if ((p = xmlnode_get_attrib(x, "xmlns")) && !strcasecmp(p, "jabber:x:encrypted"))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
416 if ((p = xmlnode_get_data(x)) != NULL) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
417 enc = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
418 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
419 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
420 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
421
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
422 // FIXME:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
423 if (body) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
424 scr_LogPrint("Message received");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
425 scr_LogPrint("Type: %s", type);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
426 gotmessage(type, from, body, enc);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
427 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
428
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
429 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
430
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
431 case JPACKET_IQ:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
432 if (!strcmp(type, "result")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
433 scr_LogPrint("Received a result packet");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
434 ut_WriteLog("Received a result packet\n");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
435
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
436 if (p = xmlnode_get_attrib(packet->x, "id")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
437 int iid = atoi(p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
438
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
439 ut_WriteLog("iid = %d\n", iid);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
440 if (iid == s_id) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
441 if (!regmode) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
442 if (jstate == STATE_GETAUTH) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
443 if (x = xmlnode_get_tag(packet->x, "query"))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
444 if (!xmlnode_get_tag(x, "digest")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
445 jc->sid = 0;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
446 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
447
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
448 s_id = atoi(jab_auth(jc));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
449 jstate = STATE_SENDAUTH;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
450 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
451 gotloggedin();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
452 jstate = STATE_LOGGED;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
453 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
454 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
455 regdone = TRUE;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
456 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
457 return;
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 if (!strcmp(p, "VCARDreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
461 x = xmlnode_get_firstchild(packet->x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
462 if (!x) x = packet->x;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
463
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
464 //jhook.gotvcard(ic, x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
465 scr_LogPrint("Got VCARD");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
466 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
467 } else if (!strcmp(p, "versionreq")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
468 // jhook.gotversion(ic, packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
469 scr_LogPrint("Got version");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
470 return;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
471 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
472 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
473
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
474 if (x = xmlnode_get_tag(packet->x, "query")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
475 p = xmlnode_get_attrib(x, "xmlns"); if (p) ns = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
476
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
477 if (!strcmp(ns, NS_ROSTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
478 gotroster(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
479 } else if (!strcmp(ns, NS_AGENTS)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
480 /* TODO...
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
481 for (y = xmlnode_get_tag(x, "agent"); y; y = xmlnode_get_nextsibling(y)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
482 const char *alias = xmlnode_get_attrib(y, "jid");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
483
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
484 if (alias) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
485 const char *name = xmlnode_get_tag_data(y, "name");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
486 const char *desc = xmlnode_get_tag_data(y, "description");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
487 const char *service = xmlnode_get_tag_data(y, "service");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
488 agent::agent_type atype = agent::atUnknown;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
489
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
490 if (xmlnode_get_tag(y, "groupchat")) atype = agent::atGroupchat; else
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
491 if (xmlnode_get_tag(y, "transport")) atype = agent::atTransport; else
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
492 if (xmlnode_get_tag(y, "search")) atype = agent::atSearch;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
493
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
494 if (alias && name && desc) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
495 jhook.agents.push_back(agent(alias, name, desc, atype));
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 (atype == agent::atSearch) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
498 x = jutil_iqnew (JPACKET__GET, NS_SEARCH);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
499 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
500 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
501 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
502 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
503 }
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 (xmlnode_get_tag(y, "register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
506 x = jutil_iqnew (JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
507 xmlnode_put_attrib(x, "to", alias);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
508 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
509 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
510 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
511 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
512 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
513 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
514 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
515
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
516 if (find(jhook.agents.begin(), jhook.agents.end(), DEFAULT_CONFSERV) == jhook.agents.end())
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
517 jhook.agents.insert(jhook.agents.begin(), agent(DEFAULT_CONFSERV, DEFAULT_CONFSERV,
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
518 _("Default Jabber conference server"), agent::atGroupchat));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
519
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
520 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
521 } else if (!strcmp(ns, NS_SEARCH) || !strcmp(ns, NS_REGISTER)) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
522 p = xmlnode_get_attrib(packet->x, "id"); id = p ? p : (char*)"";
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
523
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
524 if (!strcmp(id, "Agent info")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
525 // jhook.gotagentinfo(packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
526 scr_LogPrint("Got agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
527 } else if (!strcmp(id, "Lookup")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
528 // jhook.gotsearchresults(packet->x); TODO
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
529 scr_LogPrint("Got search results");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
530 } else if (!strcmp(id, "Register")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
531 x = jutil_iqnew(JPACKET__GET, NS_REGISTER);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
532 xmlnode_put_attrib(x, "to", from);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
533 xmlnode_put_attrib(x, "id", "Agent info");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
534 jab_send(conn, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
535 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
536 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
537
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
538 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
539 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
540 } else if (!strcmp(type, "set")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
541 } else if (!strcmp(type, "error")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
542 char *name=NULL, *desc=NULL;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
543 int code;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
544
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
545 x = xmlnode_get_tag(packet->x, "error");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
546 p = xmlnode_get_attrib(x, "code"); if (p) code = atoi(p);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
547 p = xmlnode_get_attrib(x, "id"); if (p) name = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
548 p = xmlnode_get_tag_data(packet->x, "error"); if (p) desc = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
549
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
550 switch(code) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
551 case 401: /* Unauthorized */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
552 case 302: /* Redirect */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
553 case 400: /* Bad request */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
554 case 402: /* Payment Required */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
555 case 403: /* Forbidden */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
556 case 404: /* Not Found */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
557 case 405: /* Not Allowed */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
558 case 406: /* Not Acceptable */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
559 case 407: /* Registration Required */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
560 case 408: /* Request Timeout */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
561 case 409: /* Conflict */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
562 case 500: /* Internal Server Error */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
563 case 501: /* Not Implemented */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
564 case 502: /* Remote Server Error */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
565 case 503: /* Service Unavailable */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
566 case 504: /* Remote Server Timeout */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
567 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
568 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
569 if (!regmode) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
570 face.log(desc.empty() ?
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
571 _("+ [jab] error %d") :
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
572 _("+ [jab] error %d: %s"),
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
573 code, desc.c_str());
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
574
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
575 if (!jhook.flogged && code != 501) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
576 close(jc->fd);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
577 jc->fd = -1;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
578 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
579
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
580 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
581 jhook.regerr = desc;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
582
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
583 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
584 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
585 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
586 scr_LogPrint("Error code from server (%d)", code);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
587
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
588 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
589 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
590
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
591 case JPACKET_PRESENCE:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
592 x = xmlnode_get_tag(packet->x, "show");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
593 //ust = available;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
594
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
595 if (x) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
596 p = xmlnode_get_data(x); if (p) ns = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
597
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
598 if (ns) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
599 scr_LogPrint("New status: %s", ns);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
600 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
601 if (ns == "away") ust = away; else
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
602 if (ns == "dnd") ust = dontdisturb; else
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
603 if (ns == "xa") ust = notavail; else
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
604 if (ns == "chat") ust = freeforchat;
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 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
608
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
609 if (!strcmp(type, "unavailable")) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
610 scr_LogPrint("New status: unavailable/offline");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
611 // XXX
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
612 // ust = offline;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
613 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
614
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
615 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
616 jidsplit(from, u, h, s);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
617 id = u + "@" + h;
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 (clist.get(imcontact((string) "#" + id, jhook.proto))) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
620 if (ust == offline) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
621 vector<string>::iterator im = find(jhook.chatmembers[id].begin(), jhook.chatmembers[id].end(), s);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
622 if (im != jhook.chatmembers[id].end())
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
623 jhook.chatmembers[id].erase(im);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
624
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
625 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
626 jhook.chatmembers[id].push_back(s);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
627
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
628 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
629
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
630 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
631 icqcontact *c = clist.get(ic);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
632
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
633 if (c)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
634 if (c->getstatus() != ust) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
635 if (c->getstatus() == offline)
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
636 jhook.awaymsgs[ic.nickname] = "";
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
637
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
638 logger.putonline(c, c->getstatus(), ust);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
639 c->setstatus(ust);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
640
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
641 if (x = xmlnode_get_tag(packet->x, "status"))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
642 if (p = xmlnode_get_data(x))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
643 jhook.awaymsgs[ic.nickname] = p;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
644
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
645 #ifdef HAVE_GPGME
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
646 if (x = xmlnode_get_tag(packet->x, "x"))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
647 if (p = xmlnode_get_attrib(x, "xmlns"))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
648 if ((string) p == "jabber:x:signed")
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
649 if (p = xmlnode_get_data(x))
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
650 c->setpgpkey(pgp.verify(p, jhook.awaymsgs[ic.nickname]));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
651 #endif
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
652
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
653 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
654 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
655 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
656 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
657
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
658 case JPACKET_S10N:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
659 scr_LogPrint("Received subscription packet");
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
660 /*
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
661 isagent = find(jhook.agents.begin(), jhook.agents.end(), from) != jhook.agents.end();
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
662
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
663 if (type == "subscribe") {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
664 if (!isagent) {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
665 em.store(imauthorization(ic, imevent::incoming,
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
666 imauthorization::Request, _("The user wants to subscribe to your network presence updates")));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
667
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
668 } else {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
669 auto_ptr<char> cfrom(strdup(from.c_str()));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
670 x = jutil_presnew(JPACKET__SUBSCRIBED, cfrom.get(), 0);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
671 jab_send(jc, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
672 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
673 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
674
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
675 } else if (type == "unsubscribe") {
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
676 auto_ptr<char> cfrom(strdup(from.c_str()));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
677 x = jutil_presnew(JPACKET__UNSUBSCRIBED, cfrom.get(), 0);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
678 jab_send(jc, x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
679 xmlnode_free(x);
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
680 em.store(imnotification(ic, _("The user has removed you from his contact list (unsubscribed you, using the Jabber language)")));
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
681
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
682 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
683 */
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
684
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
685 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
686
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
687 default:
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
688 break;
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
689 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
690 }
0f0fbd0c4a7f [/trunk] Changeset 47 by mikael
mikael
parents: 29
diff changeset
691