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_getallinfo(aim_session_t *sess, const char *uin) |
---|
74 | { |
---|
75 | aim_conn_t *conn; |
---|
76 | aim_frame_t *fr; |
---|
77 | aim_snacid_t snacid; |
---|
78 | int bslen; |
---|
79 | struct aim_icq_info *info; |
---|
80 | |
---|
81 | if (!uin || uin[0] < '0' || uin[0] > '9') |
---|
82 | return -EINVAL; |
---|
83 | |
---|
84 | if (!sess || !(conn = aim_conn_findbygroup(sess, 0x0015))) |
---|
85 | return -EINVAL; |
---|
86 | |
---|
87 | bslen = 2 + 4 + 2 + 2 + 2 + 4; |
---|
88 | |
---|
89 | if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10 + 4 + bslen))) |
---|
90 | return -ENOMEM; |
---|
91 | |
---|
92 | snacid = aim_cachesnac(sess, 0x0015, 0x0002, 0x0000, NULL, 0); |
---|
93 | aim_putsnac(&fr->data, 0x0015, 0x0002, 0x0000, snacid); |
---|
94 | |
---|
95 | /* For simplicity, don't bother using a tlvlist */ |
---|
96 | aimbs_put16(&fr->data, 0x0001); |
---|
97 | aimbs_put16(&fr->data, bslen); |
---|
98 | |
---|
99 | aimbs_putle16(&fr->data, bslen - 2); |
---|
100 | aimbs_putle32(&fr->data, atoi(sess->sn)); |
---|
101 | aimbs_putle16(&fr->data, 0x07d0); /* I command thee. */ |
---|
102 | aimbs_putle16(&fr->data, snacid); /* eh. */ |
---|
103 | aimbs_putle16(&fr->data, 0x04b2); /* shrug. */ |
---|
104 | aimbs_putle32(&fr->data, atoi(uin)); |
---|
105 | |
---|
106 | aim_tx_enqueue(sess, fr); |
---|
107 | |
---|
108 | /* Keep track of this request and the ICQ number and request ID */ |
---|
109 | info = g_new0(struct aim_icq_info, 1); |
---|
110 | info->reqid = snacid; |
---|
111 | info->uin = atoi(uin); |
---|
112 | info->next = sess->icq_info; |
---|
113 | sess->icq_info = info; |
---|
114 | |
---|
115 | return 0; |
---|
116 | } |
---|
117 | |
---|
118 | static void aim_icq_freeinfo(struct aim_icq_info *info) { |
---|
119 | int i; |
---|
120 | |
---|
121 | if (!info) |
---|
122 | return; |
---|
123 | g_free(info->nick); |
---|
124 | g_free(info->first); |
---|
125 | g_free(info->last); |
---|
126 | g_free(info->email); |
---|
127 | g_free(info->homecity); |
---|
128 | g_free(info->homestate); |
---|
129 | g_free(info->homephone); |
---|
130 | g_free(info->homefax); |
---|
131 | g_free(info->homeaddr); |
---|
132 | g_free(info->mobile); |
---|
133 | g_free(info->homezip); |
---|
134 | g_free(info->personalwebpage); |
---|
135 | if (info->email2) |
---|
136 | for (i = 0; i < info->numaddresses; i++) |
---|
137 | g_free(info->email2[i]); |
---|
138 | g_free(info->email2); |
---|
139 | g_free(info->workcity); |
---|
140 | g_free(info->workstate); |
---|
141 | g_free(info->workphone); |
---|
142 | g_free(info->workfax); |
---|
143 | g_free(info->workaddr); |
---|
144 | g_free(info->workzip); |
---|
145 | g_free(info->workcompany); |
---|
146 | g_free(info->workdivision); |
---|
147 | g_free(info->workposition); |
---|
148 | g_free(info->workwebpage); |
---|
149 | g_free(info->info); |
---|
150 | g_free(info); |
---|
151 | } |
---|
152 | |
---|
153 | /** |
---|
154 | * Subtype 0x0003 - Response to 0x0015/0x002, contains an ICQesque packet. |
---|
155 | */ |
---|
156 | static int icqresponse(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
157 | { |
---|
158 | int ret = 0; |
---|
159 | aim_tlvlist_t *tl; |
---|
160 | aim_tlv_t *datatlv; |
---|
161 | aim_bstream_t qbs; |
---|
162 | guint16 cmd, reqid; |
---|
163 | |
---|
164 | if (!(tl = aim_readtlvchain(bs)) || !(datatlv = aim_gettlv(tl, 0x0001, 1))) { |
---|
165 | aim_freetlvchain(&tl); |
---|
166 | imcb_error(sess->aux_data, "corrupt ICQ response\n"); |
---|
167 | return 0; |
---|
168 | } |
---|
169 | |
---|
170 | aim_bstream_init(&qbs, datatlv->value, datatlv->length); |
---|
171 | |
---|
172 | aimbs_getle16(&qbs); /* cmdlen */ |
---|
173 | aimbs_getle32(&qbs); /* ouruin */ |
---|
174 | cmd = aimbs_getle16(&qbs); |
---|
175 | reqid = aimbs_getle16(&qbs); |
---|
176 | |
---|
177 | if (cmd == 0x0041) { /* offline message */ |
---|
178 | guint16 msglen; |
---|
179 | struct aim_icq_offlinemsg msg; |
---|
180 | aim_rxcallback_t userfunc; |
---|
181 | |
---|
182 | memset(&msg, 0, sizeof(msg)); |
---|
183 | |
---|
184 | msg.sender = aimbs_getle32(&qbs); |
---|
185 | msg.year = aimbs_getle16(&qbs); |
---|
186 | msg.month = aimbs_getle8(&qbs); |
---|
187 | msg.day = aimbs_getle8(&qbs); |
---|
188 | msg.hour = aimbs_getle8(&qbs); |
---|
189 | msg.minute = aimbs_getle8(&qbs); |
---|
190 | msg.type = aimbs_getle16(&qbs); |
---|
191 | msglen = aimbs_getle16(&qbs); |
---|
192 | msg.msg = aimbs_getstr(&qbs, msglen); |
---|
193 | |
---|
194 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSG))) |
---|
195 | ret = userfunc(sess, rx, &msg); |
---|
196 | |
---|
197 | g_free(msg.msg); |
---|
198 | |
---|
199 | } else if (cmd == 0x0042) { |
---|
200 | aim_rxcallback_t userfunc; |
---|
201 | |
---|
202 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_OFFLINEMSGCOMPLETE))) |
---|
203 | ret = userfunc(sess, rx); |
---|
204 | } else if (cmd == 0x07da) { /* information */ |
---|
205 | guint16 subtype; |
---|
206 | struct aim_icq_info *info; |
---|
207 | aim_rxcallback_t userfunc; |
---|
208 | |
---|
209 | subtype = aimbs_getle16(&qbs); |
---|
210 | aim_bstream_advance(&qbs, 1); /* 0x0a */ |
---|
211 | |
---|
212 | /* find another data from the same request */ |
---|
213 | for (info = sess->icq_info; info && (info->reqid != reqid); info = info->next); |
---|
214 | |
---|
215 | if (!info) { |
---|
216 | info = g_new0(struct aim_icq_info, 1); |
---|
217 | info->reqid = reqid; |
---|
218 | info->next = sess->icq_info; |
---|
219 | sess->icq_info = info; |
---|
220 | } |
---|
221 | |
---|
222 | switch (subtype) { |
---|
223 | case 0x00a0: { /* hide ip status */ |
---|
224 | /* nothing */ |
---|
225 | } break; |
---|
226 | case 0x00aa: { /* password change status */ |
---|
227 | /* nothing */ |
---|
228 | } break; |
---|
229 | case 0x00c8: { /* general and "home" information */ |
---|
230 | info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
231 | info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
232 | info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
233 | info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
234 | info->homecity = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
235 | info->homestate = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
236 | info->homephone = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
237 | info->homefax = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
238 | info->homeaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
239 | info->mobile = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
240 | info->homezip = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
241 | info->homecountry = aimbs_getle16(&qbs); |
---|
242 | /* 0x0a 00 02 00 */ |
---|
243 | /* 1 byte timezone? */ |
---|
244 | /* 1 byte hide email flag? */ |
---|
245 | } break; |
---|
246 | case 0x00dc: { /* personal information */ |
---|
247 | info->age = aimbs_getle8(&qbs); |
---|
248 | info->unknown = aimbs_getle8(&qbs); |
---|
249 | info->gender = aimbs_getle8(&qbs); |
---|
250 | info->personalwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
251 | info->birthyear = aimbs_getle16(&qbs); |
---|
252 | info->birthmonth = aimbs_getle8(&qbs); |
---|
253 | info->birthday = aimbs_getle8(&qbs); |
---|
254 | info->language1 = aimbs_getle8(&qbs); |
---|
255 | info->language2 = aimbs_getle8(&qbs); |
---|
256 | info->language3 = aimbs_getle8(&qbs); |
---|
257 | /* 0x00 00 01 00 00 01 00 00 00 00 00 */ |
---|
258 | } break; |
---|
259 | case 0x00d2: { /* work information */ |
---|
260 | info->workcity = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
261 | info->workstate = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
262 | info->workphone = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
263 | info->workfax = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
264 | info->workaddr = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
265 | info->workzip = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
266 | info->workcountry = aimbs_getle16(&qbs); |
---|
267 | info->workcompany = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
268 | info->workdivision = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
269 | info->workposition = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
270 | aim_bstream_advance(&qbs, 2); /* 0x01 00 */ |
---|
271 | info->workwebpage = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
272 | } break; |
---|
273 | case 0x00e6: { /* additional personal information */ |
---|
274 | info->info = aimbs_getstr(&qbs, aimbs_getle16(&qbs)-1); |
---|
275 | } break; |
---|
276 | case 0x00eb: { /* email address(es) */ |
---|
277 | int i; |
---|
278 | info->numaddresses = aimbs_getle16(&qbs); |
---|
279 | info->email2 = g_new0(char *, info->numaddresses); |
---|
280 | for (i = 0; i < info->numaddresses; i++) { |
---|
281 | info->email2[i] = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
282 | if (i+1 != info->numaddresses) |
---|
283 | aim_bstream_advance(&qbs, 1); /* 0x00 */ |
---|
284 | } |
---|
285 | } break; |
---|
286 | case 0x00f0: { /* personal interests */ |
---|
287 | } break; |
---|
288 | case 0x00fa: { /* past background and current organizations */ |
---|
289 | } break; |
---|
290 | case 0x0104: { /* alias info */ |
---|
291 | info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
292 | info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
293 | info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
294 | aim_bstream_advance(&qbs, aimbs_getle16(&qbs)); |
---|
295 | /* email address? */ |
---|
296 | /* Then 0x00 02 00 */ |
---|
297 | } break; |
---|
298 | case 0x010e: { /* unknown */ |
---|
299 | /* 0x00 00 */ |
---|
300 | } break; |
---|
301 | |
---|
302 | case 0x019a: { /* simple info */ |
---|
303 | aim_bstream_advance(&qbs, 2); |
---|
304 | info->uin = aimbs_getle32(&qbs); |
---|
305 | info->nick = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
306 | info->first = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
307 | info->last = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
308 | info->email = aimbs_getstr(&qbs, aimbs_getle16(&qbs)); |
---|
309 | /* Then 0x00 02 00 00 00 00 00 */ |
---|
310 | } break; |
---|
311 | } /* End switch statement */ |
---|
312 | |
---|
313 | |
---|
314 | if (!(snac->flags & 0x0001)) { |
---|
315 | if (subtype != 0x0104) |
---|
316 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_INFO))) |
---|
317 | ret = userfunc(sess, rx, info); |
---|
318 | |
---|
319 | /* Bitlbee - not supported, yet |
---|
320 | if (info->uin && info->nick) |
---|
321 | if ((userfunc = aim_callhandler(sess, rx->conn, AIM_CB_FAM_ICQ, AIM_CB_ICQ_ALIAS))) |
---|
322 | ret = userfunc(sess, rx, info); |
---|
323 | */ |
---|
324 | |
---|
325 | if (sess->icq_info == info) { |
---|
326 | sess->icq_info = info->next; |
---|
327 | } else { |
---|
328 | struct aim_icq_info *cur; |
---|
329 | for (cur=sess->icq_info; (cur->next && (cur->next!=info)); cur=cur->next); |
---|
330 | if (cur->next) |
---|
331 | cur->next = cur->next->next; |
---|
332 | } |
---|
333 | aim_icq_freeinfo(info); |
---|
334 | } |
---|
335 | } |
---|
336 | |
---|
337 | aim_freetlvchain(&tl); |
---|
338 | |
---|
339 | return ret; |
---|
340 | } |
---|
341 | |
---|
342 | static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs) |
---|
343 | { |
---|
344 | |
---|
345 | if (snac->subtype == 0x0003) |
---|
346 | return icqresponse(sess, mod, rx, snac, bs); |
---|
347 | |
---|
348 | return 0; |
---|
349 | } |
---|
350 | |
---|
351 | int icq_modfirst(aim_session_t *sess, aim_module_t *mod) |
---|
352 | { |
---|
353 | |
---|
354 | mod->family = 0x0015; |
---|
355 | mod->version = 0x0001; |
---|
356 | mod->toolid = 0x0110; |
---|
357 | mod->toolversion = 0x047c; |
---|
358 | mod->flags = 0; |
---|
359 | strncpy(mod->name, "icq", sizeof(mod->name)); |
---|
360 | mod->snachandler = snachandler; |
---|
361 | |
---|
362 | return 0; |
---|
363 | } |
---|
364 | |
---|
365 | |
---|