]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | /* |
2 | * aim_chat.c | |
3 | * | |
aa6efcfd | 4 | * Routines for the Chat service. |
9de3ca7e | 5 | * |
6 | */ | |
7 | ||
37ee990e | 8 | #define FAIM_INTERNAL |
dd60ff8b | 9 | #include <aim.h> |
9de3ca7e | 10 | |
78b3fb13 | 11 | faim_export char *aim_chat_getname(struct aim_conn_t *conn) |
0c20631f | 12 | { |
13 | if (!conn) | |
14 | return NULL; | |
15 | if (conn->type != AIM_CONN_TYPE_CHAT) | |
16 | return NULL; | |
17 | ||
18 | return (char *)conn->priv; /* yuck ! */ | |
19 | } | |
20 | ||
78b3fb13 | 21 | faim_export struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char *name) |
0c20631f | 22 | { |
040457cc | 23 | struct aim_conn_t *cur; |
24 | ||
25 | faim_mutex_lock(&sess->connlistlock); | |
26 | for (cur = sess->connlist; cur; cur = cur->next) { | |
27 | if (cur->type != AIM_CONN_TYPE_CHAT) | |
28 | continue; | |
9d2a3582 | 29 | if (!cur->priv) { |
646c6b52 | 30 | faimdprintf(sess, 0, "faim: chat: chat connection with no name! (fd = %d)\n", cur->fd); |
9d2a3582 | 31 | continue; |
32 | } | |
040457cc | 33 | if (strcmp((char *)cur->priv, name) == 0) |
34 | break; | |
35 | } | |
36 | faim_mutex_unlock(&sess->connlistlock); | |
0c20631f | 37 | |
040457cc | 38 | return cur; |
0c20631f | 39 | } |
40 | ||
78b3fb13 | 41 | faim_export int aim_chat_attachname(struct aim_conn_t *conn, char *roomname) |
0c20631f | 42 | { |
43 | if (!conn || !roomname) | |
44 | return -1; | |
45 | ||
9d2a3582 | 46 | if (conn->priv) |
47 | free(conn->priv); | |
48 | ||
49 | conn->priv = strdup(roomname); | |
0c20631f | 50 | |
51 | return 0; | |
52 | } | |
53 | ||
9d83220c | 54 | /* XXX convert this to use tlvchains */ |
78b3fb13 | 55 | faim_export unsigned long aim_chat_send_im(struct aim_session_t *sess, |
56 | struct aim_conn_t *conn, | |
57 | char *msg) | |
0c20631f | 58 | { |
59 | ||
60 | int curbyte,i; | |
5b79dc93 | 61 | struct command_tx_struct *newpacket; |
37ee990e | 62 | struct aim_msgcookie_t *cookie; |
0c20631f | 63 | |
64 | if (!sess || !conn || !msg) | |
65 | return 0; | |
66 | ||
646c6b52 | 67 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152))) |
5b79dc93 | 68 | return -1; |
0c20631f | 69 | |
5b79dc93 | 70 | newpacket->lock = 1; /* lock struct */ |
0c20631f | 71 | |
72 | curbyte = 0; | |
5b79dc93 | 73 | curbyte += aim_putsnac(newpacket->data+curbyte, |
0c20631f | 74 | 0x000e, 0x0005, 0x0000, sess->snac_nextid); |
75 | ||
76 | /* | |
77 | * Generate a random message cookie | |
0c20631f | 78 | */ |
79 | for (i=0;i<8;i++) | |
5ac21963 | 80 | curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) rand()); |
0c20631f | 81 | |
37ee990e | 82 | cookie = aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_CHAT, NULL); |
83 | cookie->data = strdup(conn->priv); /* chat hack dependent */ | |
84 | ||
85 | aim_cachecookie(sess, cookie); | |
7392c79f | 86 | |
0c20631f | 87 | /* |
9d83220c | 88 | * Channel ID. |
0c20631f | 89 | */ |
5b79dc93 | 90 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); |
0c20631f | 91 | |
92 | /* | |
93 | * Type 1: Unknown. Blank. | |
94 | */ | |
5b79dc93 | 95 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); |
96 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
0c20631f | 97 | |
98 | /* | |
99 | * Type 6: Unknown. Blank. | |
100 | */ | |
5b79dc93 | 101 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0006); |
102 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
0c20631f | 103 | |
104 | /* | |
105 | * Type 5: Message block. Contains more TLVs. | |
106 | * | |
107 | * This could include other information... We just | |
108 | * put in a message TLV however. | |
109 | * | |
110 | */ | |
5b79dc93 | 111 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); |
112 | curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg)+4); | |
0c20631f | 113 | |
114 | /* | |
115 | * SubTLV: Type 1: Message | |
116 | */ | |
5b79dc93 | 117 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(msg), msg); |
0c20631f | 118 | |
5b79dc93 | 119 | newpacket->commandlen = curbyte; |
0c20631f | 120 | |
5b79dc93 | 121 | newpacket->lock = 0; |
122 | aim_tx_enqueue(sess, newpacket); | |
0c20631f | 123 | |
124 | return (sess->snac_nextid++); | |
125 | } | |
126 | ||
9de3ca7e | 127 | /* |
0c20631f | 128 | * Join a room of name roomname. This is the first |
129 | * step to joining an already created room. It's | |
130 | * basically a Service Request for family 0x000e, | |
131 | * with a little added on to specify the exchange | |
132 | * and room name. | |
9de3ca7e | 133 | * |
134 | */ | |
78b3fb13 | 135 | faim_export unsigned long aim_chat_join(struct aim_session_t *sess, |
136 | struct aim_conn_t *conn, | |
137 | u_short exchange, | |
138 | const char *roomname) | |
9de3ca7e | 139 | { |
5b79dc93 | 140 | struct command_tx_struct *newpacket; |
0c20631f | 141 | int i; |
142 | ||
143 | if (!sess || !conn || !roomname) | |
144 | return 0; | |
9de3ca7e | 145 | |
646c6b52 | 146 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+9+strlen(roomname)+2))) |
5b79dc93 | 147 | return -1; |
a25832e6 | 148 | |
5b79dc93 | 149 | newpacket->lock = 1; |
9de3ca7e | 150 | |
5b79dc93 | 151 | i = aim_putsnac(newpacket->data, 0x0001, 0x0004, 0x0000, sess->snac_nextid); |
9de3ca7e | 152 | |
5b79dc93 | 153 | i+= aimutil_put16(newpacket->data+i, 0x000e); |
0c20631f | 154 | |
155 | /* | |
156 | * this is techinally a TLV, but we can't use normal functions | |
157 | * because we need the extraneous nulls and other weird things. | |
158 | */ | |
5b79dc93 | 159 | i+= aimutil_put16(newpacket->data+i, 0x0001); |
160 | i+= aimutil_put16(newpacket->data+i, 2+1+strlen(roomname)+2); | |
161 | i+= aimutil_put16(newpacket->data+i, exchange); | |
162 | i+= aimutil_put8(newpacket->data+i, strlen(roomname)); | |
9f20a4e3 | 163 | i+= aimutil_putstr(newpacket->data+i, roomname, strlen(roomname)); |
164 | i+= aimutil_put16(newpacket->data+i, 0x0000); /* instance? */ | |
9de3ca7e | 165 | |
0c20631f | 166 | /* |
167 | * Chat hack. | |
168 | * | |
169 | * XXX: A problem occurs here if we request a channel | |
170 | * join but it fails....pendingjoin will be nonnull | |
171 | * even though the channel is never going to get a | |
172 | * redirect! | |
173 | * | |
174 | */ | |
9f20a4e3 | 175 | sess->pendingjoin = strdup(roomname); |
176 | sess->pendingjoinexchange = exchange; | |
0c20631f | 177 | |
5b79dc93 | 178 | newpacket->lock = 0; |
179 | aim_tx_enqueue(sess, newpacket); | |
9de3ca7e | 180 | |
1ea867e3 | 181 | aim_cachesnac(sess, 0x0001, 0x0004, 0x0000, roomname, strlen(roomname)+1); |
9de3ca7e | 182 | |
1ea867e3 | 183 | return sess->snac_nextid; |
0c20631f | 184 | } |
185 | ||
78b3fb13 | 186 | faim_internal int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo) |
0c20631f | 187 | { |
188 | int namelen = 0; | |
189 | int i = 0; | |
190 | ||
191 | if (!buf || !outinfo) | |
192 | return 0; | |
193 | ||
194 | outinfo->exchange = aimutil_get16(buf+i); | |
195 | i += 2; | |
196 | ||
197 | namelen = aimutil_get8(buf+i); | |
198 | i += 1; | |
199 | ||
200 | outinfo->name = (char *)malloc(namelen+1); | |
201 | memcpy(outinfo->name, buf+i, namelen); | |
202 | outinfo->name[namelen] = '\0'; | |
203 | i += namelen; | |
204 | ||
205 | outinfo->instance = aimutil_get16(buf+i); | |
206 | i += 2; | |
207 | ||
208 | return i; | |
78b3fb13 | 209 | } |
0c20631f | 210 | |
00ef5271 | 211 | faim_export unsigned long aim_chat_clientready(struct aim_session_t *sess, |
212 | struct aim_conn_t *conn) | |
213 | { | |
214 | struct command_tx_struct *newpacket; | |
215 | int i; | |
216 | ||
217 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 0x20))) | |
218 | return -1; | |
219 | ||
220 | newpacket->lock = 1; | |
221 | ||
222 | i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid); | |
223 | ||
224 | i+= aimutil_put16(newpacket->data+i, 0x000e); | |
225 | i+= aimutil_put16(newpacket->data+i, 0x0001); | |
226 | ||
227 | i+= aimutil_put16(newpacket->data+i, 0x0004); | |
228 | i+= aimutil_put16(newpacket->data+i, 0x0001); | |
229 | ||
230 | i+= aimutil_put16(newpacket->data+i, 0x0001); | |
231 | i+= aimutil_put16(newpacket->data+i, 0x0003); | |
232 | ||
233 | i+= aimutil_put16(newpacket->data+i, 0x0004); | |
234 | i+= aimutil_put16(newpacket->data+i, 0x0686); | |
235 | ||
236 | newpacket->lock = 0; | |
237 | aim_tx_enqueue(sess, newpacket); | |
238 | ||
239 | return (sess->snac_nextid++); | |
240 | } | |
241 | ||
242 | faim_export int aim_chat_leaveroom(struct aim_session_t *sess, char *name) | |
243 | { | |
244 | struct aim_conn_t *conn; | |
245 | ||
246 | if ((conn = aim_chat_getconn(sess, name))) | |
247 | aim_conn_close(conn); | |
248 | ||
249 | if (!conn) | |
250 | return -1; | |
251 | return 0; | |
252 | } | |
253 | ||
254 | /* | |
255 | * conn must be a BOS connection! | |
256 | */ | |
257 | faim_export unsigned long aim_chat_invite(struct aim_session_t *sess, | |
258 | struct aim_conn_t *conn, | |
259 | char *sn, | |
260 | char *msg, | |
261 | u_short exchange, | |
262 | char *roomname, | |
263 | u_short instance) | |
264 | { | |
265 | struct command_tx_struct *newpacket; | |
266 | int i,curbyte=0; | |
267 | struct aim_msgcookie_t *cookie; | |
268 | struct aim_invite_priv *priv; | |
269 | ||
270 | if (!sess || !conn || !sn || !msg || !roomname) | |
271 | return -1; | |
272 | ||
273 | if (conn->type != AIM_CONN_TYPE_BOS) | |
274 | return -1; | |
275 | ||
276 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 1152+strlen(sn)+strlen(roomname)+strlen(msg)))) | |
277 | return -1; | |
278 | ||
279 | newpacket->lock = 1; | |
280 | ||
281 | curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
282 | ||
283 | /* | |
284 | * Cookie | |
285 | */ | |
286 | for (i=0;i<8;i++) | |
287 | curbyte += aimutil_put8(newpacket->data+curbyte, (u_char)rand()); | |
288 | ||
289 | /* XXX this should get uncached by the unwritten 'invite accept' handler */ | |
290 | if(!(priv = calloc(sizeof(struct aim_invite_priv), 1))) | |
291 | return -1; | |
292 | priv->sn = strdup(sn); | |
293 | priv->roomname = strdup(roomname); | |
294 | priv->exchange = exchange; | |
295 | priv->instance = instance; | |
296 | ||
297 | if(!(cookie = aim_mkcookie(newpacket->data+curbyte-8, AIM_COOKIETYPE_INVITE, priv))) | |
298 | return -1; | |
299 | aim_cachecookie(sess, cookie); | |
300 | ||
301 | /* | |
302 | * Channel (2) | |
303 | */ | |
304 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
305 | ||
306 | /* | |
307 | * Dest sn | |
308 | */ | |
309 | curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn)); | |
310 | curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn)); | |
311 | ||
312 | /* | |
313 | * TLV t(0005) | |
314 | */ | |
315 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
316 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x28+strlen(msg)+0x04+0x03+strlen(roomname)+0x02); | |
317 | ||
318 | /* | |
319 | * Unknown info | |
320 | */ | |
321 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
322 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x3131); | |
323 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x3538); | |
324 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x3446); | |
325 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x4100); | |
326 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x748f); | |
327 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x2420); | |
328 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x6287); | |
329 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x11d1); | |
330 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x8222); | |
331 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x4445); | |
332 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x5354); | |
333 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
334 | ||
335 | /* | |
336 | * TLV t(000a) -- Unknown | |
337 | */ | |
338 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a); | |
339 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
340 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
341 | ||
342 | /* | |
343 | * TLV t(000f) -- Unknown | |
344 | */ | |
345 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f); | |
346 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
347 | ||
348 | /* | |
349 | * TLV t(000c) -- Invitation message | |
350 | */ | |
351 | curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000c, strlen(msg), msg); | |
352 | ||
353 | /* | |
354 | * TLV t(2711) -- Container for room information | |
355 | */ | |
356 | curbyte += aimutil_put16(newpacket->data+curbyte, 0x2711); | |
357 | curbyte += aimutil_put16(newpacket->data+curbyte, 3+strlen(roomname)+2); | |
358 | curbyte += aimutil_put16(newpacket->data+curbyte, exchange); | |
359 | curbyte += aimutil_put8(newpacket->data+curbyte, strlen(roomname)); | |
360 | curbyte += aimutil_putstr(newpacket->data+curbyte, roomname, strlen(roomname)); | |
361 | curbyte += aimutil_put16(newpacket->data+curbyte, instance); | |
362 | ||
363 | newpacket->commandlen = curbyte; | |
364 | newpacket->lock = 0; | |
365 | aim_tx_enqueue(sess, newpacket); | |
366 | ||
367 | return (sess->snac_nextid++); | |
368 | } | |
0c20631f | 369 | |
370 | /* | |
371 | * General room information. Lots of stuff. | |
372 | * | |
373 | * Values I know are in here but I havent attached | |
374 | * them to any of the 'Unknown's: | |
375 | * - Language (English) | |
376 | * | |
aa6efcfd | 377 | * SNAC 000e/0002 |
0c20631f | 378 | */ |
00ef5271 | 379 | static int infoupdate(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) |
0c20631f | 380 | { |
f1a5efe0 | 381 | struct aim_userinfo_s *userinfo = NULL; |
0c20631f | 382 | rxcallback_t userfunc=NULL; |
00ef5271 | 383 | int ret = 0, i = 0; |
0c20631f | 384 | int usercount = 0; |
00ef5271 | 385 | unsigned char detaillevel = 0; |
f1a5efe0 | 386 | char *roomname = NULL; |
0c20631f | 387 | struct aim_chat_roominfo roominfo; |
00ef5271 | 388 | unsigned short tlvcount = 0; |
0c20631f | 389 | struct aim_tlvlist_t *tlvlist; |
f1a5efe0 | 390 | char *roomdesc = NULL; |
aa6efcfd | 391 | unsigned short unknown_c9 = 0; |
392 | unsigned long creationtime = 0; | |
393 | unsigned short maxmsglen = 0; | |
394 | unsigned short unknown_d2 = 0, unknown_d5 = 0; | |
0c20631f | 395 | |
00ef5271 | 396 | i += aim_chat_readroominfo(data+i, &roominfo); |
0c20631f | 397 | |
00ef5271 | 398 | detaillevel = aimutil_get8(data+i); |
0c20631f | 399 | i++; |
aa6efcfd | 400 | |
401 | if (detaillevel != 0x02) { | |
402 | if (detaillevel == 0x01) | |
646c6b52 | 403 | faimdprintf(sess, 0, "faim: chat_roomupdateinfo: detail level 1 not supported\n"); |
aa6efcfd | 404 | else |
646c6b52 | 405 | faimdprintf(sess, 0, "faim: chat_roomupdateinfo: unknown detail level %d\n", detaillevel); |
aa6efcfd | 406 | return 1; |
407 | } | |
0c20631f | 408 | |
00ef5271 | 409 | tlvcount = aimutil_get16(data+i); |
0c20631f | 410 | i += 2; |
411 | ||
412 | /* | |
413 | * Everything else are TLVs. | |
414 | */ | |
00ef5271 | 415 | tlvlist = aim_readtlvchain(data+i, datalen-i); |
0c20631f | 416 | |
417 | /* | |
418 | * TLV type 0x006a is the room name in Human Readable Form. | |
419 | */ | |
420 | if (aim_gettlv(tlvlist, 0x006a, 1)) | |
00ef5271 | 421 | roomname = aim_gettlv_str(tlvlist, 0x006a, 1); |
0c20631f | 422 | |
423 | /* | |
424 | * Type 0x006f: Number of occupants. | |
425 | */ | |
1ea867e3 | 426 | if (aim_gettlv(tlvlist, 0x006f, 1)) |
427 | usercount = aim_gettlv16(tlvlist, 0x006f, 1); | |
0c20631f | 428 | |
429 | /* | |
430 | * Type 0x0073: Occupant list. | |
431 | */ | |
aa6efcfd | 432 | if (aim_gettlv(tlvlist, 0x0073, 1)) { |
433 | int curoccupant = 0; | |
434 | struct aim_tlv_t *tmptlv; | |
435 | ||
436 | tmptlv = aim_gettlv(tlvlist, 0x0073, 1); | |
0c20631f | 437 | |
aa6efcfd | 438 | /* Allocate enough userinfo structs for all occupants */ |
439 | userinfo = calloc(usercount, sizeof(struct aim_userinfo_s)); | |
440 | ||
441 | i = 0; | |
442 | while (curoccupant < usercount) | |
646c6b52 | 443 | i += aim_extractuserinfo(sess, tmptlv->value+i, &userinfo[curoccupant++]); |
aa6efcfd | 444 | } |
0c20631f | 445 | |
446 | /* | |
aa6efcfd | 447 | * Type 0x00c9: Unknown. (2 bytes) |
0c20631f | 448 | */ |
1ea867e3 | 449 | if (aim_gettlv(tlvlist, 0x00c9, 1)) |
450 | unknown_c9 = aim_gettlv16(tlvlist, 0x00c9, 1); | |
0c20631f | 451 | |
452 | /* | |
aa6efcfd | 453 | * Type 0x00ca: Creation time (4 bytes) |
0c20631f | 454 | */ |
1ea867e3 | 455 | if (aim_gettlv(tlvlist, 0x00ca, 1)) |
456 | creationtime = aim_gettlv32(tlvlist, 0x00ca, 1); | |
0c20631f | 457 | |
458 | /* | |
459 | * Type 0x00d1: Maximum Message Length | |
460 | */ | |
1ea867e3 | 461 | if (aim_gettlv(tlvlist, 0x00d1, 1)) |
462 | maxmsglen = aim_gettlv16(tlvlist, 0x00d1, 1); | |
0c20631f | 463 | |
464 | /* | |
aa6efcfd | 465 | * Type 0x00d2: Unknown. (2 bytes) |
0c20631f | 466 | */ |
1ea867e3 | 467 | if (aim_gettlv(tlvlist, 0x00d2, 1)) |
468 | unknown_d2 = aim_gettlv16(tlvlist, 0x00d2, 1); | |
0c20631f | 469 | |
470 | /* | |
471 | * Type 0x00d3: Room Description | |
472 | */ | |
473 | if (aim_gettlv(tlvlist, 0x00d3, 1)) | |
474 | roomdesc = aim_gettlv_str(tlvlist, 0x00d3, 1); | |
475 | ||
476 | /* | |
aa6efcfd | 477 | * Type 0x00d5: Unknown. (1 byte) |
0c20631f | 478 | */ |
1ea867e3 | 479 | if (aim_gettlv(tlvlist, 0x00d5, 1)) |
480 | unknown_d5 = aim_gettlv8(tlvlist, 0x00d5, 1); | |
0c20631f | 481 | |
482 | ||
00ef5271 | 483 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) { |
aa6efcfd | 484 | ret = userfunc(sess, |
00ef5271 | 485 | rx, |
aa6efcfd | 486 | &roominfo, |
487 | roomname, | |
488 | usercount, | |
489 | userinfo, | |
490 | roomdesc, | |
491 | unknown_c9, | |
492 | creationtime, | |
493 | maxmsglen, | |
494 | unknown_d2, | |
495 | unknown_d5); | |
00ef5271 | 496 | } |
497 | ||
0c20631f | 498 | free(roominfo.name); |
499 | free(userinfo); | |
500 | free(roomname); | |
501 | free(roomdesc); | |
502 | aim_freetlvchain(&tlvlist); | |
503 | ||
504 | return ret; | |
505 | } | |
506 | ||
00ef5271 | 507 | static int userlistchange(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) |
0c20631f | 508 | { |
509 | struct aim_userinfo_s *userinfo = NULL; | |
00ef5271 | 510 | rxcallback_t userfunc; |
511 | int i = 0, curcount = 0, ret = 0; | |
0c20631f | 512 | |
00ef5271 | 513 | while (i < datalen) { |
aa6efcfd | 514 | curcount++; |
515 | userinfo = realloc(userinfo, curcount * sizeof(struct aim_userinfo_s)); | |
00ef5271 | 516 | i += aim_extractuserinfo(sess, data+i, &userinfo[curcount-1]); |
aa6efcfd | 517 | } |
0c20631f | 518 | |
00ef5271 | 519 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
520 | ret = userfunc(sess, rx, curcount, userinfo); | |
0c20631f | 521 | |
522 | free(userinfo); | |
523 | ||
524 | return ret; | |
00ef5271 | 525 | } |
0c20631f | 526 | |
527 | /* | |
528 | * We could probably include this in the normal ICBM parsing | |
529 | * code as channel 0x0003, however, since only the start | |
530 | * would be the same, we might as well do it here. | |
9d83220c | 531 | * |
532 | * General outline of this SNAC: | |
533 | * snac | |
534 | * cookie | |
535 | * channel id | |
536 | * tlvlist | |
537 | * unknown | |
538 | * source user info | |
539 | * name | |
540 | * evility | |
541 | * userinfo tlvs | |
542 | * online time | |
543 | * etc | |
544 | * message metatlv | |
545 | * message tlv | |
546 | * message string | |
547 | * possibly others | |
548 | * | |
0c20631f | 549 | */ |
00ef5271 | 550 | static int incomingmsg(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) |
0c20631f | 551 | { |
552 | struct aim_userinfo_s userinfo; | |
553 | rxcallback_t userfunc=NULL; | |
00ef5271 | 554 | int ret = 0, i = 0; |
fd0b7da6 | 555 | unsigned char cookie[8]; |
0c20631f | 556 | int channel; |
557 | struct aim_tlvlist_t *outerlist; | |
558 | char *msg = NULL; | |
fd0b7da6 | 559 | struct aim_msgcookie_t *ck; |
0c20631f | 560 | |
561 | memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s)); | |
562 | ||
0c20631f | 563 | /* |
7392c79f | 564 | * ICBM Cookie. Cache it. |
0c20631f | 565 | */ |
00ef5271 | 566 | memcpy(cookie, data, 8); |
567 | i += 8; | |
0c20631f | 568 | |
fd0b7da6 | 569 | if ((ck = aim_uncachecookie(sess, cookie, AIM_COOKIETYPE_CHAT))) { |
570 | if (ck->data) | |
571 | free(ck->data); | |
572 | free(ck); | |
573 | } | |
7392c79f | 574 | |
0c20631f | 575 | /* |
576 | * Channel ID | |
577 | * | |
578 | * Channels 1 and 2 are implemented in the normal ICBM | |
579 | * parser. | |
580 | * | |
581 | * We only do channel 3 here. | |
582 | * | |
583 | */ | |
00ef5271 | 584 | channel = aimutil_get16(data+i); |
0c20631f | 585 | i += 2; |
586 | ||
aa6efcfd | 587 | if (channel != 0x0003) { |
646c6b52 | 588 | faimdprintf(sess, 0, "faim: chat_incoming: unknown channel! (0x%04x)\n", channel); |
00ef5271 | 589 | return 0; |
aa6efcfd | 590 | } |
0c20631f | 591 | |
592 | /* | |
593 | * Start parsing TLVs right away. | |
594 | */ | |
00ef5271 | 595 | outerlist = aim_readtlvchain(data+8+2, datalen-8-2); |
0c20631f | 596 | |
597 | /* | |
598 | * Type 0x0003: Source User Information | |
599 | */ | |
aa6efcfd | 600 | if (aim_gettlv(outerlist, 0x0003, 1)) { |
601 | struct aim_tlv_t *userinfotlv; | |
602 | ||
603 | userinfotlv = aim_gettlv(outerlist, 0x0003, 1); | |
646c6b52 | 604 | aim_extractuserinfo(sess, userinfotlv->value, &userinfo); |
aa6efcfd | 605 | } |
0c20631f | 606 | |
607 | /* | |
608 | * Type 0x0001: Unknown. | |
609 | */ | |
610 | if (aim_gettlv(outerlist, 0x0001, 1)) | |
611 | ; | |
612 | ||
613 | /* | |
614 | * Type 0x0005: Message Block. Conains more TLVs. | |
615 | */ | |
00ef5271 | 616 | if (aim_gettlv(outerlist, 0x0005, 1)) { |
617 | struct aim_tlvlist_t *innerlist; | |
618 | struct aim_tlv_t *msgblock; | |
0c20631f | 619 | |
00ef5271 | 620 | msgblock = aim_gettlv(outerlist, 0x0005, 1); |
621 | innerlist = aim_readtlvchain(msgblock->value, msgblock->length); | |
0c20631f | 622 | |
00ef5271 | 623 | /* |
624 | * Type 0x0001: Message. | |
625 | */ | |
626 | if (aim_gettlv(innerlist, 0x0001, 1)) | |
627 | msg = aim_gettlv_str(innerlist, 0x0001, 1); | |
0c20631f | 628 | |
00ef5271 | 629 | aim_freetlvchain(&innerlist); |
630 | } | |
631 | ||
632 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
633 | ret = userfunc(sess, rx, &userinfo, msg); | |
0c20631f | 634 | |
0c20631f | 635 | free(msg); |
636 | aim_freetlvchain(&outerlist); | |
637 | ||
638 | return ret; | |
0c20631f | 639 | } |
640 | ||
00ef5271 | 641 | static int snachandler(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) |
0c20631f | 642 | { |
0c20631f | 643 | |
00ef5271 | 644 | if (snac->subtype == 0x0002) |
645 | return infoupdate(sess, mod, rx, snac, data, datalen); | |
646 | else if ((snac->subtype == 0x0003) || (snac->subtype == 0x0004)) | |
647 | return userlistchange(sess, mod, rx, snac, data, datalen); | |
648 | else if (snac->subtype == 0x0006) | |
649 | return incomingmsg(sess, mod, rx, snac, data, datalen); | |
040457cc | 650 | |
040457cc | 651 | return 0; |
0c20631f | 652 | } |
653 | ||
00ef5271 | 654 | faim_internal int chat_modfirst(struct aim_session_t *sess, aim_module_t *mod) |
0c20631f | 655 | { |
0c20631f | 656 | |
00ef5271 | 657 | mod->family = 0x000e; |
658 | mod->version = 0x0000; | |
659 | mod->flags = 0; | |
660 | strncpy(mod->name, "chat", sizeof(mod->name)); | |
661 | mod->snachandler = snachandler; | |
0c20631f | 662 | |
00ef5271 | 663 | return 0; |
9de3ca7e | 664 | } |