annotate mcabber/src/jabglue.c @ 29:86837ff0554c

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