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