1 | /* |
---|
2 | * Encapsulated ICQ. |
---|
3 | * |
---|
4 | */ |
---|
5 | |
---|
6 | #include <aim.h> |
---|
7 | #include "icq.h" |
---|
8 | |
---|
9 | int aim_icq_reqofflinemsgs(aim_session_t *sess) |
---|
10 | { |
---|
11 | aim_conn_t *conn; |
---|
12 | aim_frame_t *fr; |
---|
13 | aim_snacid_t snacid; |
---|
14 | int bslen; |
---|
15 | |
---|
16 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
---|
17 | return -EINVAL; |
---|
18 | |
---|
19 | bslen = 2 + 4 + 2 + 2; |
---|
20 | |
---|
21 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
---|
22 | return -ENOMEM; |
---|
23 | |
---|
24 | snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
---|
25 | aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
---|
26 | |
---|
27 | /* For simplicity, don't bother using a tlvlist */ |
---|
28 | aimbs_put16(&fr->data, 0x0001); |
---|
29 | aimbs_put16(&fr->data, bslen); |
---|
30 | |
---|
31 | aimbs_putle16(&fr->data, bslen - 2); |
---|
32 | aimbs_putle32(&fr->data, atoi(sess->sn)); |
---|
33 | aimbs_putle16(&fr->data, 0x003c); /* I command thee. */ |
---|
34 | aimbs_putle16(&fr->data, snacid); /* eh. */ |
---|
35 | |
---|
36 | aim_tx_enqueue(sess, fr); |
---|
37 | |
---|
38 | return 0; |
---|
39 | } |
---|
40 | |
---|
41 | int aim_icq_ackofflinemsgs(aim_session_t *sess) |
---|
42 | { |
---|
43 | aim_conn_t *conn; |
---|
44 | aim_frame_t *fr; |
---|
45 | aim_snacid_t snacid; |
---|
46 | int bslen; |
---|
47 | |
---|
48 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
---|
49 | return -EINVAL; |
---|
50 | |
---|
51 | bslen = 2 + 4 + 2 + 2; |
---|
52 | |
---|
53 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
---|
54 | return -ENOMEM; |
---|
55 | |
---|
56 | snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
---|
57 | aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
---|
58 | |
---|
59 | /* For simplicity, don't bother using a tlvlist */ |
---|
60 | aimbs_put16(&fr->data, 0x0001); |
---|
61 | aimbs_put16(&fr->data, bslen); |
---|
62 | |
---|
63 | aimbs_putle16(&fr->data, bslen - 2); |
---|
64 | aimbs_putle32(&fr->data, atoi(sess->sn)); |
---|
65 | aimbs_putle16(&fr->data, 0x003e); /* I command thee. */ |
---|
66 | aimbs_putle16(&fr->data, snacid); /* eh. */ |
---|
67 | |
---|
68 | aim_tx_enqueue(sess, fr); |
---|
69 | |
---|
70 | return 0; |
---|
71 | } |
---|
72 | |
---|
73 | int aim_icq_sendxmlreq(aim_session_t *sess, const char *xml) |
---|
74 | { |
---|
75 | aim_conn_t *conn; |
---|
76 | aim_frame_t *fr; |
---|
77 | aim_snacid_t snacid; |
---|
78 | int bslen; |
---|
79 | |
---|
80 | if (!xml || !strlen(xml)) |
---|
81 | return -EINVAL; |
---|
82 | |
---|
83 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
---|
84 | return -EINVAL; |
---|
85 | |
---|
86 | bslen = 2 + 10 + 2 + strlen(xml) + 1; |
---|
87 | |
---|
88 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
---|
89 | return -ENOMEM; |
---|
90 | |
---|
91 | snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
---|
92 | aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
---|
93 | |
---|
94 | /* For simplicity, don't bother using a tlvlist */ |
---|
95 | aimbs_put16(&fr->data, 0x0001); |
---|
96 | aimbs_put16(&fr->data, bslen); |
---|
97 | |
---|
98 | aimbs_putle16(&fr->data, bslen - 2); |
---|
99 | aimbs_putle32(&fr->data, atoi(sess->sn)); |
---|
100 | aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
---|
101 | aimbs_putle16(&fr->data, snacid); /* eh. */ |
---|
102 | aimbs_putle16(&fr->data, 0x0998); /* shrug. */ |
---|
103 | aimbs_putle16(&fr->data, strlen(xml) + 1); |
---|
104 | aimbs_putraw(&fr->data, (guint8 *)xml, strlen(xml) + 1); |
---|
105 | |
---|
106 | aim_tx_enqueue(sess, fr); |
---|
107 | |
---|
108 | return 0; |
---|
109 | } |
---|
110 | |
---|
111 | int aim_icq_getallinfo(aim_session_t *sess, const char *uin) |
---|
112 | { |
---|
113 | aim_conn_t *conn; |
---|
114 | aim_frame_t *fr; |
---|
115 | aim_snacid_t snacid; |
---|
116 | int bslen; |
---|
117 | struct aim_icq_info *info; |
---|
118 | |
---|
119 | if (!uin || uin[0] < '0' || uin[0] > '9') |
---|
120 | return -EINVAL; |
---|
121 | |
---|
122 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
---|
123 | return -EINVAL; |
---|
124 | |
---|
125 | bslen = 2 + 4 + 2 + 2 + 2 + 4; |
---|
126 | |
---|
127 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
---|
128 | return -ENOMEM; |
---|
129 | |
---|
130 | snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
---|
131 | aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
---|
132 | |
---|
133 | /* For simplicity, don't bother using a tlvlist */ |
---|
134 | aimbs_put16(&fr->data, 0x0001); |
---|
135 | aimbs_put16(&fr->data, bslen); |
---|
136 | |
---|
137 | aimbs_putle16(&fr->data, bslen - 2); |
---|
138 | aimbs_putle32(&fr->data, atoi(sess->sn)); |
---|
139 | aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
---|
140 | aimbs_putle16(&fr->data, snacid); /* eh. */ |
---|
141 | aimbs_putle16(&fr->data, 0x04b2); /* shrug. */ |
---|
142 | aimbs_putle32(&fr->data, atoi(uin)); |
---|
143 | |
---|
144 | aim_tx_enqueue(sess, fr); |
---|
145 | |
---|
146 | /* Keep track of this request and the ICQ number and request ID */ |
---|
147 | info = g_new0(struct aim_icq_info, 1); |
---|
148 | info->reqid = snacid; |
---|
149 | info->uin = atoi(uin); |
---|
150 | info->next = sess->icq_info; |
---|
151 | sess->icq_info = info; |
---|
152 | |
---|
153 | return 0; |
---|
154 | } |
---|
155 | |
---|
156 | int aim_icq_getsimpleinfo(aim_session_t *sess, const char *uin) |
---|
157 | { |
---|
158 | aim_conn_t *conn; |
---|
159 | aim_frame_t *fr; |
---|
160 | aim_snacid_t snacid; |
---|
161 | int bslen; |
---|
162 | |
---|
163 | if (!uin || uin[0] < '0' || uin[0] > '9') |
---|
164 | return -EINVAL; |
---|
165 | |
---|
166 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
---|
167 | return -EINVAL; |
---|
168 | |
---|
169 | bslen = 2 + 4 + 2 + 2 + 2 + 4; |
---|
170 | |
---|
171 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
---|
172 | return -ENOMEM; |
---|
173 | |
---|
174 | snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
---|
175 | aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
---|
176 | |
---|
177 | /* For simplicity, don't bother using a tlvlist */ |
---|
178 | aimbs_put16(&fr->data, 0x0001); |
---|
179 | aimbs_put16(&fr->data, bslen); |
---|
180 | |
---|
181 | aimbs_putle16(&fr->data, bslen - 2); |
---|
182 | aimbs_putle32(&fr->data, atoi(sess->sn)); |
---|
183 | aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
---|
184 | aimbs_putle16(&fr->data, snacid); /* eh. */ |
---|
185 | aimbs_putle16(&fr->data, 0x051f); /* shrug. */ |
---|
186 | aimbs_putle32(&fr->data, atoi(uin)); |
---|
187 | |
---|
188 | aim_tx_enqueue(sess, fr); |
---|
189 | |
---|
190 | return 0; |
---|
191 | } |
---|
192 | |
---|
193 | static void aim_icq_freeinfo(struct aim_icq_info *info) { |
---|
194 | int i; |
---|
195 | |
---|
196 | if (!info) |
---|
197 | return; |
---|
198 | g_free(info->nick); |
---|
199 | g_free(info->first); |
---|
200 | g_free(info->last); |
---|
201 | g_free(info->email); |
---|
202 | g_free(info->homecity); |
---|
203 | g_free(info->homestate); |
---|
204 | g_free(info->homephone); |
---|
205 | g_free(info->homefax); |
---|
206 | g_free(info->homeaddr); |
---|
207 | g_free(info->mobile); |
---|
208 | g_free(info->homezip); |
---|
209 | g_free(info->personalwebpage); |
---|
210 | if (info->email2) |
---|
211 | for (i = 0; i < info->numaddresses; i++) |
---|
212 | g_free(info->email2[i]); |
---|
213 | g_free(info->email2); |
---|
214 | g_free(info->workcity); |
---|
215 | g_free(info->workstate); |
---|
216 | g_free(info->workphone); |
---|
217 | g_free(info->workfax); |
---|
218 | g_free(info->workaddr); |
---|
219 | g_free(info->workzip); |
---|
220 | g_free(info->workcompany); |
---|
221 | g_free(info->workdivision); |
---|
222 | g_free(info->workposition); |
---|
223 | g_free(info->workwebpage); |
---|
224 | g_free(info->info); |
---|
225 | g_free(info); |
---|
226 | } |
---|
227 | |
---|
228 | /** |
---|
229 | * Subtype 0x0003 - Response to 0x0015/0x002, contains an ICQesque packet. |
---|
230 | */ |
---|
231 | static int icqresponse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
232 | { |
---|
233 | int ret = 0; |
---|
234 | aim_tlvlist_t *tl; |
---|
235 | aim_tlv_t *datatlv; |
---|
236 | aim_bstream_t qbs; |
---|
237 | guint32 ouruin; |
---|
238 | guint16 cmdlen, cmd, reqid; |
---|
239 | |
---|
240 | if (!(tl = aim_readtlvchain(bs)) || !(datatlv = aim_gettlv(tl, 0x0001, 1))) { |
---|
241 | aim_freetlvchain(&tl); |
---|
242 | imcb_error(sess->aux_data, "corrupt ICQ response\n"); |
---|
243 | return 0; |
---|
244 | } |
---|
245 | |
---|
246 | aim_bstream_init(&qbs, datatlv->value, datatlv->length); |
---|
247 | |
---|
248 | cmdlen = aimbs_getle16(&qbs); |
---|
249 | ouruin = aimbs_getle32(&qbs); |
---|
250 | cmd = aimbs_getle16(&qbs); |
---|
251 | reqid = aimbs_getle16(&qbs); |
---|
252 | |
---|
253 | if (cmd == 0x0041) { /* offline message */ |
---|
254 | guint16 msglen; |
---|
255 | struct aim_icq_offlinemsg msg; |
---|
256 | aim_rxcallback_t userfunc; |
---|
257 | |
---|
258 | memset(&msg, 0, sizeof(msg)); |
---|
259 | |
---|
260 | msg.sender = aimbs_getle32(&qbs); |
---|
261 | msg.year = aimbs_getle16(&qbs); |
---|
262 | msg.month = aimbs_getle8(&qbs); |
---|
263 | msg.day = aimbs_getle8(&qbs); |
---|
264 | msg.hour = aimbs_getle8(&qbs); |
---|
265 | msg.minute = aimbs_getle8(&qbs); |
---|
266 | msg.type = aimbs_getle16(&qbs); |
---|
267 | msglen = aimbs_getle16(&qbs); |
---|
268 | msg.msg = aimbs_getstr(&qbs, msglen); |
---|
269 | |
---|
270 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG))) |
---|
271 | ret = userfunc(sess, rx, &msg); |
---|
272 | |
---|
273 | g_free(msg.msg); |
---|
274 | |
---|
275 | } else if (cmd == 0x0042) { |
---|
276 | aim_rxcallback_t userfunc; |
---|
277 | |
---|
278 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE))) |
---|
279 | ret = userfunc(sess, rx); |
---|
280 | } else if (cmd == 0x07da) { /* information */ |
---|
281 | guint16 subtype; |
---|
282 | struct aim_icq_info *info; |
---|
283 | aim_rxcallback_t userfunc; |
---|
284 | |
---|
285 | subtype = aimbs_getle16(&qbs); |
---|
286 | aim_bstream_advance(&qbs, 1); /* 0x0a */ |
---|
287 | |
---|
288 | /* find another data from the same request */ |
---|
289 | for (info = sess->icq_info; info && (info->reqid != reqid); info = info->next); |
---|
290 | |
---|
291 | if (!info) { |
---|
292 | info = g_new0(struct aim_icq_info, 1); |
---|
293 | info->reqid = reqid; |
---|
294 | info->next = sess->icq_info; |
---|
295 | sess->icq_info = info; |
---|
296 | } |
---|
297 | |
---|
298 | switch (subtype) { |
---|
299 | case 0x00a0: { /* hide ip status */ |
---|
300 | /* nothing */ |
---|
301 | } break; |
---|
302 | case 0x00aa: { /* password change status */ |
---|
303 | /* nothing */ |
---|
304 | } break; |
---|
305 | case 0x00c8: { /* general and "home" information */ |
---|
306 | info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
307 | info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
308 | info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
309 | info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
310 | info->homecity = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
311 | info->homestate = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
312 | info->homephone = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
313 | info->homefax = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
314 | info->homeaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
315 | info->mobile = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
316 | info->homezip = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
317 | info->homecountry = aimbs_getle16(&qbs); |
---|
318 | /* 0x0a 00 02 00 */ |
---|
319 | /* 1 byte timezone? */ |
---|
320 | /* 1 byte hide email flag? */ |
---|
321 | } break; |
---|
322 | case 0x00dc: { /* personal information */ |
---|
323 | info->age = aimbs_getle8(&qbs); |
---|
324 | info->unknown = aimbs_getle8(&qbs); |
---|
325 | info->gender = aimbs_getle8(&qbs); |
---|
326 | info->personalwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
327 | info->birthyear = aimbs_getle16(&qbs); |
---|
328 | info->birthmonth = aimbs_getle8(&qbs); |
---|
329 | info->birthday = aimbs_getle8(&qbs); |
---|
330 | info->language1 = aimbs_getle8(&qbs); |
---|
331 | info->language2 = aimbs_getle8(&qbs); |
---|
332 | info->language3 = aimbs_getle8(&qbs); |
---|
333 | /* 0x00 00 01 00 00 01 00 00 00 00 00 */ |
---|
334 | } break; |
---|
335 | case 0x00d2: { /* work information */ |
---|
336 | info->workcity = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
337 | info->workstate = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
338 | info->workphone = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
339 | info->workfax = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
340 | info->workaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
341 | info->workzip = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
342 | info->workcountry = aimbs_getle16(&qbs); |
---|
343 | info->workcompany = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
344 | info->workdivision = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
345 | info->workposition = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
346 | aim_bstream_advance(&qbs, 2); /* 0x01 00 */ |
---|
347 | info->workwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
348 | } break; |
---|
349 | case 0x00e6: { /* additional personal information */ |
---|
350 | info->info = aimbs_getstr(&qbs, aimbs_getle16(&qbs)-1); |
---|
351 | } break; |
---|
352 | case 0x00eb: { /* email address(es) */ |
---|
353 | int i; |
---|
354 | info->numaddresses = aimbs_getle16(&qbs); |
---|
355 | info->email2 = g_new0(char *, info->numaddresses); |
---|
356 | for (i = 0; i < info->numaddresses; i++) { |
---|
357 | info->email2[i] = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
358 | if (i+1 != info->numaddresses) |
---|
359 | aim_bstream_advance(&qbs, 1); /* 0x00 */ |
---|
360 | } |
---|
361 | } break; |
---|
362 | case 0x00f0: { /* personal interests */ |
---|
363 | } break; |
---|
364 | case 0x00fa: { /* past background and current organizations */ |
---|
365 | } break; |
---|
366 | case 0x0104: { /* alias info */ |
---|
367 | info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
368 | info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
369 | info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
370 | aim_bstream_advance(&qbs, aimbs_getle16(&qbs)); |
---|
371 | /* email address? */ |
---|
372 | /* Then 0x00 02 00 */ |
---|
373 | } break; |
---|
374 | case 0x010e: { /* unknown */ |
---|
375 | /* 0x00 00 */ |
---|
376 | } break; |
---|
377 | |
---|
378 | case 0x019a: { /* simple info */ |
---|
379 | aim_bstream_advance(&qbs, 2); |
---|
380 | info->uin = aimbs_getle32(&qbs); |
---|
381 | info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
382 | info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
383 | info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
384 | info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
385 | /* Then 0x00 02 00 00 00 00 00 */ |
---|
386 | } break; |
---|
387 | } /* End switch statement */ |
---|
388 | |
---|
389 | |
---|
390 | if (!(snac->flags & 0x0001)) { |
---|
391 | if (subtype != 0x0104) |
---|
392 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_INFO))) |
---|
393 | ret = userfunc(sess, rx, info); |
---|
394 | |
---|
395 | /* Bitlbee - not supported, yet |
---|
396 | if (info->uin && info->nick) |
---|
397 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_ALIAS))) |
---|
398 | ret = userfunc(sess, rx, info); |
---|
399 | */ |
---|
400 | |
---|
401 | if (sess->icq_info == info) { |
---|
402 | sess->icq_info = info->next; |
---|
403 | } else { |
---|
404 | struct aim_icq_info *cur; |
---|
405 | for (cur=sess->icq_info; (cur->next && (cur->next!=info)); cur=cur->next); |
---|
406 | if (cur->next) |
---|
407 | cur->next = cur->next->next; |
---|
408 | } |
---|
409 | aim_icq_freeinfo(info); |
---|
410 | } |
---|
411 | } |
---|
412 | |
---|
413 | aim_freetlvchain(&tl); |
---|
414 | |
---|
415 | return ret; |
---|
416 | } |
---|
417 | |
---|
418 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
419 | { |
---|
420 | |
---|
421 | if (snac->subtype == 0x0003) |
---|
422 | return icqresponse(sess, mod, rx, snac, bs); |
---|
423 | |
---|
424 | return 0; |
---|
425 | } |
---|
426 | |
---|
427 | int icq_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
428 | { |
---|
429 | |
---|
430 | mod->family = 0x0015; |
---|
431 | mod->version = 0x0001; |
---|
432 | mod->toolid = 0x0110; |
---|
433 | mod->toolversion = 0x047c; |
---|
434 | mod->flags = 0; |
---|
435 | strncpy(mod->name, "icq", sizeof(mod->name)); |
---|
436 | mod->snachandler = snachandler; |
---|
437 | |
---|
438 | return 0; |
---|
439 | } |
---|
440 | |
---|
441 | |
---|