| |
1 /* |
| |
2 * Gaim's oscar protocol plugin |
| |
3 * This file is the legal property of its developers. |
| |
4 * Please see the AUTHORS file distributed alongside this file. |
| |
5 * |
| |
6 * This library is free software; you can redistribute it and/or |
| |
7 * modify it under the terms of the GNU Lesser General Public |
| |
8 * License as published by the Free Software Foundation; either |
| |
9 * version 2 of the License, or (at your option) any later version. |
| |
10 * |
| |
11 * This library is distributed in the hope that it will be useful, |
| |
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| |
14 * Lesser General Public License for more details. |
| |
15 * |
| |
16 * You should have received a copy of the GNU Lesser General Public |
| |
17 * License along with this library; if not, write to the Free Software |
| |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| |
19 */ |
| |
20 |
| |
21 /* |
| |
22 * Family 0x0015 - Encapsulated ICQ. |
| |
23 * |
| |
24 */ |
| |
25 |
| |
26 #include "oscar.h" |
| |
27 |
| |
28 int aim_icq_reqofflinemsgs(OscarData *od) |
| |
29 { |
| |
30 FlapConnection *conn; |
| |
31 FlapFrame *frame; |
| |
32 aim_snacid_t snacid; |
| |
33 int bslen; |
| |
34 |
| |
35 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
36 return -EINVAL; |
| |
37 |
| |
38 bslen = 2 + 4 + 2 + 2; |
| |
39 |
| |
40 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
41 |
| |
42 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
43 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
44 |
| |
45 /* For simplicity, don't bother using a tlvlist */ |
| |
46 byte_stream_put16(&frame->data, 0x0001); |
| |
47 byte_stream_put16(&frame->data, bslen); |
| |
48 |
| |
49 byte_stream_putle16(&frame->data, bslen - 2); |
| |
50 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
51 byte_stream_putle16(&frame->data, 0x003c); /* I command thee. */ |
| |
52 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
53 |
| |
54 flap_connection_send(conn, frame); |
| |
55 |
| |
56 return 0; |
| |
57 } |
| |
58 |
| |
59 int aim_icq_ackofflinemsgs(OscarData *od) |
| |
60 { |
| |
61 FlapConnection *conn; |
| |
62 FlapFrame *frame; |
| |
63 aim_snacid_t snacid; |
| |
64 int bslen; |
| |
65 |
| |
66 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
67 return -EINVAL; |
| |
68 |
| |
69 bslen = 2 + 4 + 2 + 2; |
| |
70 |
| |
71 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
72 |
| |
73 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
74 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
75 |
| |
76 /* For simplicity, don't bother using a tlvlist */ |
| |
77 byte_stream_put16(&frame->data, 0x0001); |
| |
78 byte_stream_put16(&frame->data, bslen); |
| |
79 |
| |
80 byte_stream_putle16(&frame->data, bslen - 2); |
| |
81 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
82 byte_stream_putle16(&frame->data, 0x003e); /* I command thee. */ |
| |
83 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
84 |
| |
85 flap_connection_send(conn, frame); |
| |
86 |
| |
87 return 0; |
| |
88 } |
| |
89 |
| |
90 int |
| |
91 aim_icq_setsecurity(OscarData *od, gboolean auth_required, gboolean webaware) |
| |
92 { |
| |
93 FlapConnection *conn; |
| |
94 FlapFrame *frame; |
| |
95 aim_snacid_t snacid; |
| |
96 int bslen; |
| |
97 |
| |
98 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
99 return -EINVAL; |
| |
100 |
| |
101 bslen = 2+4+2+2+2+2+2+1+1+1+1+1+1; |
| |
102 |
| |
103 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
104 |
| |
105 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
106 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
107 |
| |
108 /* For simplicity, don't bother using a tlvlist */ |
| |
109 byte_stream_put16(&frame->data, 0x0001); |
| |
110 byte_stream_put16(&frame->data, bslen); |
| |
111 |
| |
112 byte_stream_putle16(&frame->data, bslen - 2); |
| |
113 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
114 byte_stream_putle16(&frame->data, 0x07d0); /* I command thee. */ |
| |
115 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
116 byte_stream_putle16(&frame->data, 0x0c3a); /* shrug. */ |
| |
117 byte_stream_putle16(&frame->data, 0x030c); |
| |
118 byte_stream_putle16(&frame->data, 0x0001); |
| |
119 byte_stream_putle8(&frame->data, webaware); |
| |
120 byte_stream_putle8(&frame->data, 0xf8); |
| |
121 byte_stream_putle8(&frame->data, 0x02); |
| |
122 byte_stream_putle8(&frame->data, 0x01); |
| |
123 byte_stream_putle8(&frame->data, 0x00); |
| |
124 byte_stream_putle8(&frame->data, !auth_required); |
| |
125 |
| |
126 flap_connection_send(conn, frame); |
| |
127 |
| |
128 return 0; |
| |
129 } |
| |
130 |
| |
131 /** |
| |
132 * Change your ICQ password. |
| |
133 * |
| |
134 * @param od The oscar session |
| |
135 * @param passwd The new password. If this is longer than 8 characters it |
| |
136 * will be truncated. |
| |
137 * @return Return 0 if no errors, otherwise return the error number. |
| |
138 */ |
| |
139 int aim_icq_changepasswd(OscarData *od, const char *passwd) |
| |
140 { |
| |
141 FlapConnection *conn; |
| |
142 FlapFrame *frame; |
| |
143 aim_snacid_t snacid; |
| |
144 int bslen, passwdlen; |
| |
145 |
| |
146 if (!passwd) |
| |
147 return -EINVAL; |
| |
148 |
| |
149 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
150 return -EINVAL; |
| |
151 |
| |
152 passwdlen = strlen(passwd); |
| |
153 if (passwdlen > MAXICQPASSLEN) |
| |
154 passwdlen = MAXICQPASSLEN; |
| |
155 bslen = 2+4+2+2+2+2+passwdlen+1; |
| |
156 |
| |
157 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
158 |
| |
159 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
160 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
161 |
| |
162 /* For simplicity, don't bother using a tlvlist */ |
| |
163 byte_stream_put16(&frame->data, 0x0001); |
| |
164 byte_stream_put16(&frame->data, bslen); |
| |
165 |
| |
166 byte_stream_putle16(&frame->data, bslen - 2); |
| |
167 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
168 byte_stream_putle16(&frame->data, 0x07d0); /* I command thee. */ |
| |
169 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
170 byte_stream_putle16(&frame->data, 0x042e); /* shrug. */ |
| |
171 byte_stream_putle16(&frame->data, passwdlen+1); |
| |
172 byte_stream_putstr(&frame->data, passwd); |
| |
173 byte_stream_putle8(&frame->data, '\0'); |
| |
174 |
| |
175 flap_connection_send(conn, frame); |
| |
176 |
| |
177 return 0; |
| |
178 } |
| |
179 |
| |
180 int aim_icq_getallinfo(OscarData *od, const char *uin) |
| |
181 { |
| |
182 FlapConnection *conn; |
| |
183 FlapFrame *frame; |
| |
184 aim_snacid_t snacid; |
| |
185 int bslen; |
| |
186 struct aim_icq_info *info; |
| |
187 |
| |
188 if (!uin || uin[0] < '0' || uin[0] > '9') |
| |
189 return -EINVAL; |
| |
190 |
| |
191 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
192 return -EINVAL; |
| |
193 |
| |
194 bslen = 2 + 4 + 2 + 2 + 2 + 4; |
| |
195 |
| |
196 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
197 |
| |
198 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
199 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
200 |
| |
201 /* For simplicity, don't bother using a tlvlist */ |
| |
202 byte_stream_put16(&frame->data, 0x0001); |
| |
203 byte_stream_put16(&frame->data, bslen); |
| |
204 |
| |
205 byte_stream_putle16(&frame->data, bslen - 2); |
| |
206 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
207 byte_stream_putle16(&frame->data, 0x07d0); /* I command thee. */ |
| |
208 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
209 byte_stream_putle16(&frame->data, 0x04b2); /* shrug. */ |
| |
210 byte_stream_putle32(&frame->data, atoi(uin)); |
| |
211 |
| |
212 flap_connection_send(conn, frame); |
| |
213 |
| |
214 /* Keep track of this request and the ICQ number and request ID */ |
| |
215 info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info)); |
| |
216 info->reqid = snacid; |
| |
217 info->uin = atoi(uin); |
| |
218 info->next = od->icq_info; |
| |
219 od->icq_info = info; |
| |
220 |
| |
221 return 0; |
| |
222 } |
| |
223 |
| |
224 int aim_icq_getalias(OscarData *od, const char *uin) |
| |
225 { |
| |
226 FlapConnection *conn; |
| |
227 FlapFrame *frame; |
| |
228 aim_snacid_t snacid; |
| |
229 int bslen; |
| |
230 struct aim_icq_info *info; |
| |
231 |
| |
232 if (!uin || uin[0] < '0' || uin[0] > '9') |
| |
233 return -EINVAL; |
| |
234 |
| |
235 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
236 return -EINVAL; |
| |
237 |
| |
238 bslen = 2 + 4 + 2 + 2 + 2 + 4; |
| |
239 |
| |
240 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
241 |
| |
242 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
243 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
244 |
| |
245 /* For simplicity, don't bother using a tlvlist */ |
| |
246 byte_stream_put16(&frame->data, 0x0001); |
| |
247 byte_stream_put16(&frame->data, bslen); |
| |
248 |
| |
249 byte_stream_putle16(&frame->data, bslen - 2); |
| |
250 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
251 byte_stream_putle16(&frame->data, 0x07d0); /* I command thee. */ |
| |
252 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
253 byte_stream_putle16(&frame->data, 0x04ba); /* shrug. */ |
| |
254 byte_stream_putle32(&frame->data, atoi(uin)); |
| |
255 |
| |
256 flap_connection_send(conn, frame); |
| |
257 |
| |
258 /* Keep track of this request and the ICQ number and request ID */ |
| |
259 info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info)); |
| |
260 info->reqid = snacid; |
| |
261 info->uin = atoi(uin); |
| |
262 info->next = od->icq_info; |
| |
263 od->icq_info = info; |
| |
264 |
| |
265 return 0; |
| |
266 } |
| |
267 |
| |
268 int aim_icq_getsimpleinfo(OscarData *od, const char *uin) |
| |
269 { |
| |
270 FlapConnection *conn; |
| |
271 FlapFrame *frame; |
| |
272 aim_snacid_t snacid; |
| |
273 int bslen; |
| |
274 |
| |
275 if (!uin || uin[0] < '0' || uin[0] > '9') |
| |
276 return -EINVAL; |
| |
277 |
| |
278 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
279 return -EINVAL; |
| |
280 |
| |
281 bslen = 2 + 4 + 2 + 2 + 2 + 4; |
| |
282 |
| |
283 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
284 |
| |
285 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
286 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
287 |
| |
288 /* For simplicity, don't bother using a tlvlist */ |
| |
289 byte_stream_put16(&frame->data, 0x0001); |
| |
290 byte_stream_put16(&frame->data, bslen); |
| |
291 |
| |
292 byte_stream_putle16(&frame->data, bslen - 2); |
| |
293 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
294 byte_stream_putle16(&frame->data, 0x07d0); /* I command thee. */ |
| |
295 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
296 byte_stream_putle16(&frame->data, 0x051f); /* shrug. */ |
| |
297 byte_stream_putle32(&frame->data, atoi(uin)); |
| |
298 |
| |
299 flap_connection_send(conn, frame); |
| |
300 |
| |
301 return 0; |
| |
302 } |
| |
303 |
| |
304 #if 0 |
| |
305 int aim_icq_sendxmlreq(OscarData *od, const char *xml) |
| |
306 { |
| |
307 FlapConnection *conn; |
| |
308 FlapFrame *frame; |
| |
309 aim_snacid_t snacid; |
| |
310 int bslen; |
| |
311 |
| |
312 if (!xml || !strlen(xml)) |
| |
313 return -EINVAL; |
| |
314 |
| |
315 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
316 return -EINVAL; |
| |
317 |
| |
318 bslen = 2 + 10 + 2 + strlen(xml) + 1; |
| |
319 |
| |
320 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
321 |
| |
322 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
323 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
324 |
| |
325 /* For simplicity, don't bother using a tlvlist */ |
| |
326 byte_stream_put16(&frame->data, 0x0001); |
| |
327 byte_stream_put16(&frame->data, bslen); |
| |
328 |
| |
329 byte_stream_putle16(&frame->data, bslen - 2); |
| |
330 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
331 byte_stream_putle16(&frame->data, 0x07d0); /* I command thee. */ |
| |
332 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
333 byte_stream_putle16(&frame->data, 0x0998); /* shrug. */ |
| |
334 byte_stream_putle16(&frame->data, strlen(xml) + 1); |
| |
335 byte_stream_putraw(&frame->data, (guint8 *)xml, strlen(xml) + 1); |
| |
336 |
| |
337 flap_connection_send(conn, frame); |
| |
338 |
| |
339 return 0; |
| |
340 } |
| |
341 #endif |
| |
342 |
| |
343 #if 0 |
| |
344 /* |
| |
345 * Send an SMS message. This is the non-US way. The US-way is to IM |
| |
346 * their cell phone number (+19195551234). |
| |
347 * |
| |
348 * We basically construct and send an XML message. The format is: |
| |
349 * <icq_sms_message> |
| |
350 * <destination>full_phone_without_leading_+</destination> |
| |
351 * <text>message</text> |
| |
352 * <codepage>1252</codepage> |
| |
353 * <senders_UIN>self_uin</senders_UIN> |
| |
354 * <senders_name>self_name</senders_name> |
| |
355 * <delivery_receipt>Yes|No</delivery_receipt> |
| |
356 * <time>Wkd, DD Mmm YYYY HH:MM:SS TMZ</time> |
| |
357 * </icq_sms_message> |
| |
358 * |
| |
359 * Yeah hi Peter, whaaaat's happening. If there's any way to use |
| |
360 * a codepage other than 1252 that would be great. Thaaaanks. |
| |
361 */ |
| |
362 int aim_icq_sendsms(OscarData *od, const char *name, const char *msg, const char *alias) |
| |
363 { |
| |
364 FlapConnection *conn; |
| |
365 FlapFrame *frame; |
| |
366 aim_snacid_t snacid; |
| |
367 int bslen, xmllen; |
| |
368 char *xml; |
| |
369 const char *timestr; |
| |
370 time_t t; |
| |
371 struct tm *tm; |
| |
372 |
| |
373 if (!od || !(conn = flap_connection_findbygroup(od, 0x0015))) |
| |
374 return -EINVAL; |
| |
375 |
| |
376 if (!name || !msg || !alias) |
| |
377 return -EINVAL; |
| |
378 |
| |
379 time(&t); |
| |
380 tm = gmtime(&t); |
| |
381 timestr = gaim_utf8_strftime("%a, %d %b %Y %T %Z", tm); |
| |
382 |
| |
383 /* The length of xml included the null terminating character */ |
| |
384 xmllen = 225 + strlen(name) + strlen(msg) + strlen(od->sn) + strlen(alias) + strlen(timestr) + 1; |
| |
385 |
| |
386 xml = g_new(char, xmllen); |
| |
387 snprintf(xml, xmllen, "<icq_sms_message>\n" |
| |
388 "\t<destination>%s</destination>\n" |
| |
389 "\t<text>%s</text>\n" |
| |
390 "\t<codepage>1252</codepage>\n" |
| |
391 "\t<senders_UIN>%s</senders_UIN>\n" |
| |
392 "\t<senders_name>%s</senders_name>\n" |
| |
393 "\t<delivery_receipt>Yes</delivery_receipt>\n" |
| |
394 "\t<time>%s</time>\n" |
| |
395 "</icq_sms_message>\n", |
| |
396 name, msg, od->sn, alias, timestr); |
| |
397 |
| |
398 bslen = 37 + xmllen; |
| |
399 |
| |
400 frame = flap_frame_new(od, 0x02, 10 + 4 + bslen); |
| |
401 |
| |
402 snacid = aim_cachesnac(od, 0x0015, 0x0002, 0x0000, NULL, 0); |
| |
403 aim_putsnac(&frame->data, 0x0015, 0x0002, 0x0000, snacid); |
| |
404 |
| |
405 /* For simplicity, don't bother using a tlvlist */ |
| |
406 byte_stream_put16(&frame->data, 0x0001); |
| |
407 byte_stream_put16(&frame->data, bslen); |
| |
408 |
| |
409 byte_stream_putle16(&frame->data, bslen - 2); |
| |
410 byte_stream_putle32(&frame->data, atoi(od->sn)); |
| |
411 byte_stream_putle16(&frame->data, 0x07d0); /* I command thee. */ |
| |
412 byte_stream_putle16(&frame->data, snacid); /* eh. */ |
| |
413 |
| |
414 /* From libicq200-0.3.2/src/SNAC-SRV.cpp */ |
| |
415 byte_stream_putle16(&frame->data, 0x8214); |
| |
416 byte_stream_put16(&frame->data, 0x0001); |
| |
417 byte_stream_put16(&frame->data, 0x0016); |
| |
418 byte_stream_put32(&frame->data, 0x00000000); |
| |
419 byte_stream_put32(&frame->data, 0x00000000); |
| |
420 byte_stream_put32(&frame->data, 0x00000000); |
| |
421 byte_stream_put32(&frame->data, 0x00000000); |
| |
422 |
| |
423 byte_stream_put16(&frame->data, 0x0000); |
| |
424 byte_stream_put16(&frame->data, xmllen); |
| |
425 byte_stream_putstr(&frame->data, xml); |
| |
426 |
| |
427 flap_connection_send(conn, frame); |
| |
428 |
| |
429 free(xml); |
| |
430 |
| |
431 return 0; |
| |
432 } |
| |
433 #endif |
| |
434 |
| |
435 static void aim_icq_freeinfo(struct aim_icq_info *info) { |
| |
436 int i; |
| |
437 |
| |
438 if (!info) |
| |
439 return; |
| |
440 free(info->nick); |
| |
441 free(info->first); |
| |
442 free(info->last); |
| |
443 free(info->email); |
| |
444 free(info->homecity); |
| |
445 free(info->homestate); |
| |
446 free(info->homephone); |
| |
447 free(info->homefax); |
| |
448 free(info->homeaddr); |
| |
449 free(info->mobile); |
| |
450 free(info->homezip); |
| |
451 free(info->personalwebpage); |
| |
452 if (info->email2) |
| |
453 for (i = 0; i < info->numaddresses; i++) |
| |
454 free(info->email2[i]); |
| |
455 free(info->email2); |
| |
456 free(info->workcity); |
| |
457 free(info->workstate); |
| |
458 free(info->workphone); |
| |
459 free(info->workfax); |
| |
460 free(info->workaddr); |
| |
461 free(info->workzip); |
| |
462 free(info->workcompany); |
| |
463 free(info->workdivision); |
| |
464 free(info->workposition); |
| |
465 free(info->workwebpage); |
| |
466 free(info->info); |
| |
467 free(info); |
| |
468 } |
| |
469 |
| |
470 /** |
| |
471 * Subtype 0x0003 - Response to 0x0015/0x002, contains an ICQesque packet. |
| |
472 */ |
| |
473 static int |
| |
474 icqresponse(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
475 { |
| |
476 int ret = 0; |
| |
477 aim_tlvlist_t *tl; |
| |
478 aim_tlv_t *datatlv; |
| |
479 ByteStream qbs; |
| |
480 guint32 ouruin; |
| |
481 guint16 cmdlen, cmd, reqid; |
| |
482 |
| |
483 if (!(tl = aim_tlvlist_read(bs)) || !(datatlv = aim_tlv_gettlv(tl, 0x0001, 1))) { |
| |
484 aim_tlvlist_free(&tl); |
| |
485 gaim_debug_misc("oscar", "corrupt ICQ response\n"); |
| |
486 return 0; |
| |
487 } |
| |
488 |
| |
489 byte_stream_init(&qbs, datatlv->value, datatlv->length); |
| |
490 |
| |
491 cmdlen = byte_stream_getle16(&qbs); |
| |
492 ouruin = byte_stream_getle32(&qbs); |
| |
493 cmd = byte_stream_getle16(&qbs); |
| |
494 reqid = byte_stream_getle16(&qbs); |
| |
495 |
| |
496 gaim_debug_misc("oscar", "icq response: %d bytes, %ld, 0x%04x, 0x%04x\n", cmdlen, ouruin, cmd, reqid); |
| |
497 |
| |
498 if (cmd == 0x0041) { /* offline message */ |
| |
499 struct aim_icq_offlinemsg msg; |
| |
500 aim_rxcallback_t userfunc; |
| |
501 |
| |
502 memset(&msg, 0, sizeof(msg)); |
| |
503 |
| |
504 msg.sender = byte_stream_getle32(&qbs); |
| |
505 msg.year = byte_stream_getle16(&qbs); |
| |
506 msg.month = byte_stream_getle8(&qbs); |
| |
507 msg.day = byte_stream_getle8(&qbs); |
| |
508 msg.hour = byte_stream_getle8(&qbs); |
| |
509 msg.minute = byte_stream_getle8(&qbs); |
| |
510 msg.type = byte_stream_getle8(&qbs); |
| |
511 msg.flags = byte_stream_getle8(&qbs); |
| |
512 msg.msglen = byte_stream_getle16(&qbs); |
| |
513 msg.msg = byte_stream_getstr(&qbs, msg.msglen); |
| |
514 |
| |
515 if ((userfunc = aim_callhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_OFFLINEMSG))) |
| |
516 ret = userfunc(od, conn, frame, &msg); |
| |
517 |
| |
518 free(msg.msg); |
| |
519 |
| |
520 } else if (cmd == 0x0042) { |
| |
521 aim_rxcallback_t userfunc; |
| |
522 |
| |
523 if ((userfunc = aim_callhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_OFFLINEMSGCOMPLETE))) |
| |
524 ret = userfunc(od, conn, frame); |
| |
525 |
| |
526 } else if (cmd == 0x07da) { /* information */ |
| |
527 guint16 subtype; |
| |
528 struct aim_icq_info *info; |
| |
529 aim_rxcallback_t userfunc; |
| |
530 |
| |
531 subtype = byte_stream_getle16(&qbs); |
| |
532 byte_stream_advance(&qbs, 1); /* 0x0a */ |
| |
533 |
| |
534 /* find other data from the same request */ |
| |
535 for (info = od->icq_info; info && (info->reqid != reqid); info = info->next); |
| |
536 if (!info) { |
| |
537 info = (struct aim_icq_info *)calloc(1, sizeof(struct aim_icq_info)); |
| |
538 info->reqid = reqid; |
| |
539 info->next = od->icq_info; |
| |
540 od->icq_info = info; |
| |
541 } |
| |
542 |
| |
543 switch (subtype) { |
| |
544 case 0x00a0: { /* hide ip status */ |
| |
545 /* nothing */ |
| |
546 } break; |
| |
547 |
| |
548 case 0x00aa: { /* password change status */ |
| |
549 /* nothing */ |
| |
550 } break; |
| |
551 |
| |
552 case 0x00c8: { /* general and "home" information */ |
| |
553 info->nick = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
554 info->first = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
555 info->last = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
556 info->email = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
557 info->homecity = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
558 info->homestate = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
559 info->homephone = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
560 info->homefax = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
561 info->homeaddr = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
562 info->mobile = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
563 info->homezip = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
564 info->homecountry = byte_stream_getle16(&qbs); |
| |
565 /* 0x0a 00 02 00 */ |
| |
566 /* 1 byte timezone? */ |
| |
567 /* 1 byte hide email flag? */ |
| |
568 } break; |
| |
569 |
| |
570 case 0x00dc: { /* personal information */ |
| |
571 info->age = byte_stream_getle8(&qbs); |
| |
572 info->unknown = byte_stream_getle8(&qbs); |
| |
573 info->gender = byte_stream_getle8(&qbs); /* Not specified=0x00, Female=0x01, Male=0x02 */ |
| |
574 info->personalwebpage = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
575 info->birthyear = byte_stream_getle16(&qbs); |
| |
576 info->birthmonth = byte_stream_getle8(&qbs); |
| |
577 info->birthday = byte_stream_getle8(&qbs); |
| |
578 info->language1 = byte_stream_getle8(&qbs); |
| |
579 info->language2 = byte_stream_getle8(&qbs); |
| |
580 info->language3 = byte_stream_getle8(&qbs); |
| |
581 /* 0x00 00 01 00 00 01 00 00 00 00 00 */ |
| |
582 } break; |
| |
583 |
| |
584 case 0x00d2: { /* work information */ |
| |
585 info->workcity = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
586 info->workstate = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
587 info->workphone = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
588 info->workfax = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
589 info->workaddr = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
590 info->workzip = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
591 info->workcountry = byte_stream_getle16(&qbs); |
| |
592 info->workcompany = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
593 info->workdivision = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
594 info->workposition = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
595 byte_stream_advance(&qbs, 2); /* 0x01 00 */ |
| |
596 info->workwebpage = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
597 } break; |
| |
598 |
| |
599 case 0x00e6: { /* additional personal information */ |
| |
600 info->info = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)-1); |
| |
601 } break; |
| |
602 |
| |
603 case 0x00eb: { /* email address(es) */ |
| |
604 int i; |
| |
605 info->numaddresses = byte_stream_getle16(&qbs); |
| |
606 info->email2 = (char **)calloc(info->numaddresses, sizeof(char *)); |
| |
607 for (i = 0; i < info->numaddresses; i++) { |
| |
608 info->email2[i] = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
609 if (i+1 != info->numaddresses) |
| |
610 byte_stream_advance(&qbs, 1); /* 0x00 */ |
| |
611 } |
| |
612 } break; |
| |
613 |
| |
614 case 0x00f0: { /* personal interests */ |
| |
615 } break; |
| |
616 |
| |
617 case 0x00fa: { /* past background and current organizations */ |
| |
618 } break; |
| |
619 |
| |
620 case 0x0104: { /* alias info */ |
| |
621 info->nick = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
622 info->first = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
623 info->last = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
624 byte_stream_advance(&qbs, byte_stream_getle16(&qbs)); /* email address? */ |
| |
625 /* Then 0x00 02 00 */ |
| |
626 } break; |
| |
627 |
| |
628 case 0x010e: { /* unknown */ |
| |
629 /* 0x00 00 */ |
| |
630 } break; |
| |
631 |
| |
632 case 0x019a: { /* simple info */ |
| |
633 byte_stream_advance(&qbs, 2); |
| |
634 info->uin = byte_stream_getle32(&qbs); |
| |
635 info->nick = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
636 info->first = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
637 info->last = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
638 info->email = byte_stream_getstr(&qbs, byte_stream_getle16(&qbs)); |
| |
639 /* Then 0x00 02 00 00 00 00 00 */ |
| |
640 } break; |
| |
641 } /* End switch statement */ |
| |
642 |
| |
643 if (!(snac->flags & 0x0001)) { |
| |
644 if (subtype != 0x0104) |
| |
645 if ((userfunc = aim_callhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_INFO))) |
| |
646 ret = userfunc(od, conn, frame, info); |
| |
647 |
| |
648 if (info->uin && info->nick) |
| |
649 if ((userfunc = aim_callhandler(od, SNAC_FAMILY_ICQ, SNAC_SUBTYPE_ICQ_ALIAS))) |
| |
650 ret = userfunc(od, conn, frame, info); |
| |
651 |
| |
652 if (od->icq_info == info) { |
| |
653 od->icq_info = info->next; |
| |
654 } else { |
| |
655 struct aim_icq_info *cur; |
| |
656 for (cur=od->icq_info; (cur->next && (cur->next!=info)); cur=cur->next); |
| |
657 if (cur->next) |
| |
658 cur->next = cur->next->next; |
| |
659 } |
| |
660 aim_icq_freeinfo(info); |
| |
661 } |
| |
662 } |
| |
663 |
| |
664 aim_tlvlist_free(&tl); |
| |
665 |
| |
666 return ret; |
| |
667 } |
| |
668 |
| |
669 static int |
| |
670 snachandler(OscarData *od, FlapConnection *conn, aim_module_t *mod, FlapFrame *frame, aim_modsnac_t *snac, ByteStream *bs) |
| |
671 { |
| |
672 if (snac->subtype == 0x0003) |
| |
673 return icqresponse(od, conn, mod, frame, snac, bs); |
| |
674 |
| |
675 return 0; |
| |
676 } |
| |
677 |
| |
678 static void |
| |
679 icq_shutdown(OscarData *od, aim_module_t *mod) |
| |
680 { |
| |
681 struct aim_icq_info *del; |
| |
682 |
| |
683 while (od->icq_info) { |
| |
684 del = od->icq_info; |
| |
685 od->icq_info = od->icq_info->next; |
| |
686 aim_icq_freeinfo(del); |
| |
687 } |
| |
688 |
| |
689 return; |
| |
690 } |
| |
691 |
| |
692 int |
| |
693 icq_modfirst(OscarData *od, aim_module_t *mod) |
| |
694 { |
| |
695 mod->family = 0x0015; |
| |
696 mod->version = 0x0001; |
| |
697 mod->toolid = 0x0110; |
| |
698 mod->toolversion = 0x047c; |
| |
699 mod->flags = 0; |
| |
700 strncpy(mod->name, "icq", sizeof(mod->name)); |
| |
701 mod->snachandler = snachandler; |
| |
702 mod->shutdown = icq_shutdown; |
| |
703 |
| |
704 return 0; |
| |
705 } |