]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | /* |
37ee990e | 2 | * Handle ChatNav. |
9de3ca7e | 3 | * |
37ee990e | 4 | * [The ChatNav(igation) service does various things to keep chat |
5 | * alive. It provides room information, room searching and creating, | |
6 | * as well as giving users the right ("permission") to use chat.] | |
9de3ca7e | 7 | * |
8 | */ | |
9 | ||
37ee990e | 10 | #define FAIM_INTERNAL |
dd60ff8b | 11 | #include <aim.h> |
9de3ca7e | 12 | |
0c20631f | 13 | /* |
14 | * conn must be a chatnav connection! | |
15 | */ | |
78b3fb13 | 16 | faim_export unsigned long aim_chatnav_reqrights(struct aim_session_t *sess, |
17 | struct aim_conn_t *conn) | |
0c20631f | 18 | { |
1ea867e3 | 19 | aim_genericreq_n(sess, conn, 0x000d, 0x0002); |
0c20631f | 20 | |
1ea867e3 | 21 | return sess->snac_nextid; |
0c20631f | 22 | } |
23 | ||
78b3fb13 | 24 | faim_export unsigned long aim_chatnav_clientready(struct aim_session_t *sess, |
25 | struct aim_conn_t *conn) | |
0c20631f | 26 | { |
5b79dc93 | 27 | struct command_tx_struct *newpacket; |
0c20631f | 28 | int i; |
29 | ||
646c6b52 | 30 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 0x20))) |
5b79dc93 | 31 | return -1; |
0c20631f | 32 | |
5b79dc93 | 33 | newpacket->lock = 1; |
0c20631f | 34 | |
5b79dc93 | 35 | i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid); |
0c20631f | 36 | |
5b79dc93 | 37 | i+= aimutil_put16(newpacket->data+i, 0x000d); |
38 | i+= aimutil_put16(newpacket->data+i, 0x0001); | |
0c20631f | 39 | |
5b79dc93 | 40 | i+= aimutil_put16(newpacket->data+i, 0x0004); |
41 | i+= aimutil_put16(newpacket->data+i, 0x0001); | |
0c20631f | 42 | |
5b79dc93 | 43 | i+= aimutil_put16(newpacket->data+i, 0x0001); |
44 | i+= aimutil_put16(newpacket->data+i, 0x0003); | |
0c20631f | 45 | |
5b79dc93 | 46 | i+= aimutil_put16(newpacket->data+i, 0x0004); |
47 | i+= aimutil_put16(newpacket->data+i, 0x0686); | |
48 | ||
49 | aim_tx_enqueue(sess, newpacket); | |
0c20631f | 50 | |
51 | return (sess->snac_nextid++); | |
52 | } | |
53 | ||
54 | /* | |
55 | * Since multiple things can trigger this callback, | |
56 | * we must lookup the snacid to determine the original | |
57 | * snac subtype that was called. | |
58 | */ | |
78b3fb13 | 59 | faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command) |
0c20631f | 60 | { |
61 | struct aim_snac_t *snac; | |
62 | u_long snacid; | |
63 | rxcallback_t userfunc; | |
dad2e696 | 64 | int ret=1; |
0c20631f | 65 | |
66 | snacid = aimutil_get32(command->data+6); | |
67 | snac = aim_remsnac(sess, snacid); | |
68 | ||
646c6b52 | 69 | if (!snac) { |
70 | faimdprintf(sess, 0, "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snacid); | |
71 | return 1; | |
72 | } | |
0c20631f | 73 | |
646c6b52 | 74 | if (snac->family != 0x000d) { |
75 | faimdprintf(sess, 0, "faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac->family); | |
76 | return 1; | |
77 | } | |
0c20631f | 78 | |
79 | /* | |
80 | * We now know what the original SNAC subtype was. | |
81 | */ | |
82 | switch(snac->type) | |
83 | { | |
84 | case 0x0002: /* request chat rights */ | |
85 | { | |
86 | struct aim_tlvlist_t *tlvlist; | |
87 | struct aim_chat_exchangeinfo *exchanges = NULL; | |
88 | int curexchange = 0; | |
89 | struct aim_tlv_t *exchangetlv; | |
90 | u_char maxrooms = 0; | |
0c20631f | 91 | struct aim_tlvlist_t *innerlist; |
92 | ||
93 | tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10); | |
94 | ||
95 | /* | |
96 | * Type 0x0002: Maximum concurrent rooms. | |
97 | */ | |
98 | if (aim_gettlv(tlvlist, 0x0002, 1)) | |
1ea867e3 | 99 | maxrooms = aim_gettlv8(tlvlist, 0x0002, 1); |
0c20631f | 100 | |
101 | /* | |
102 | * Type 0x0003: Exchange information | |
103 | * | |
104 | * There can be any number of these, each one | |
105 | * representing another exchange. | |
106 | * | |
107 | */ | |
108 | curexchange = 0; | |
109 | while ((exchangetlv = aim_gettlv(tlvlist, 0x0003, curexchange+1))) | |
110 | { | |
111 | curexchange++; | |
112 | exchanges = realloc(exchanges, curexchange * sizeof(struct aim_chat_exchangeinfo)); | |
113 | ||
d9142146 | 114 | |
0c20631f | 115 | /* exchange number */ |
116 | exchanges[curexchange-1].number = aimutil_get16(exchangetlv->value); | |
117 | innerlist = aim_readtlvchain(exchangetlv->value+2, exchangetlv->length-2); | |
118 | ||
119 | /* | |
120 | * Type 0x000d: Unknown. | |
121 | */ | |
122 | if (aim_gettlv(innerlist, 0x000d, 1)) | |
123 | ; | |
124 | ||
125 | /* | |
126 | * Type 0x0004: Unknown | |
127 | */ | |
128 | if (aim_gettlv(innerlist, 0x0004, 1)) | |
129 | ; | |
130 | ||
98c88242 | 131 | /* |
132 | * Type 0x0002: Unknown | |
133 | */ | |
134 | if (aim_gettlv(innerlist, 0x0002, 1)) { | |
1ea867e3 | 135 | unsigned short classperms; |
98c88242 | 136 | |
1ea867e3 | 137 | classperms = aim_gettlv16(innerlist, 0x0002, 1); |
98c88242 | 138 | |
646c6b52 | 139 | faimdprintf(sess, 1, "faim: class permissions %x\n", classperms); |
98c88242 | 140 | } |
141 | ||
0c20631f | 142 | /* |
143 | * Type 0x00c9: Unknown | |
144 | */ | |
145 | if (aim_gettlv(innerlist, 0x00c9, 1)) | |
146 | ; | |
147 | ||
148 | /* | |
149 | * Type 0x00ca: Creation Date | |
150 | */ | |
151 | if (aim_gettlv(innerlist, 0x00ca, 1)) | |
152 | ; | |
153 | ||
154 | /* | |
98c88242 | 155 | * Type 0x00d0: Mandatory Channels? |
0c20631f | 156 | */ |
157 | if (aim_gettlv(innerlist, 0x00d0, 1)) | |
158 | ; | |
159 | ||
160 | /* | |
161 | * Type 0x00d1: Maximum Message length | |
162 | */ | |
163 | if (aim_gettlv(innerlist, 0x00d1, 1)) | |
164 | ; | |
165 | ||
166 | /* | |
98c88242 | 167 | * Type 0x00d2: Maximum Occupancy? |
0c20631f | 168 | */ |
169 | if (aim_gettlv(innerlist, 0x00d2, 1)) | |
170 | ; | |
171 | ||
172 | /* | |
173 | * Type 0x00d3: Exchange Name | |
174 | */ | |
175 | if (aim_gettlv(innerlist, 0x00d3, 1)) | |
176 | exchanges[curexchange-1].name = aim_gettlv_str(innerlist, 0x00d3, 1); | |
177 | else | |
178 | exchanges[curexchange-1].name = NULL; | |
179 | ||
180 | /* | |
98c88242 | 181 | * Type 0x00d5: Creation Permissions |
182 | * | |
183 | * 0 Creation not allowed | |
184 | * 1 Room creation allowed | |
185 | * 2 Exchange creation allowed | |
186 | * | |
0c20631f | 187 | */ |
98c88242 | 188 | if (aim_gettlv(innerlist, 0x00d5, 1)) { |
1ea867e3 | 189 | unsigned char createperms; |
98c88242 | 190 | |
1ea867e3 | 191 | createperms = aim_gettlv8(innerlist, 0x00d5, 1); |
98c88242 | 192 | } |
0c20631f | 193 | |
194 | /* | |
195 | * Type 0x00d6: Character Set (First Time) | |
196 | */ | |
197 | if (aim_gettlv(innerlist, 0x00d6, 1)) | |
198 | exchanges[curexchange-1].charset1 = aim_gettlv_str(innerlist, 0x00d6, 1); | |
199 | else | |
200 | exchanges[curexchange-1].charset1 = NULL; | |
201 | ||
202 | /* | |
203 | * Type 0x00d7: Language (First Time) | |
204 | */ | |
205 | if (aim_gettlv(innerlist, 0x00d7, 1)) | |
206 | exchanges[curexchange-1].lang1 = aim_gettlv_str(innerlist, 0x00d7, 1); | |
207 | else | |
208 | exchanges[curexchange-1].lang1 = NULL; | |
209 | ||
210 | /* | |
211 | * Type 0x00d8: Character Set (Second Time) | |
212 | */ | |
213 | if (aim_gettlv(innerlist, 0x00d8, 1)) | |
214 | exchanges[curexchange-1].charset2 = aim_gettlv_str(innerlist, 0x00d8, 1); | |
215 | else | |
216 | exchanges[curexchange-1].charset2 = NULL; | |
217 | ||
218 | /* | |
219 | * Type 0x00d9: Language (Second Time) | |
220 | */ | |
221 | if (aim_gettlv(innerlist, 0x00d9, 1)) | |
222 | exchanges[curexchange-1].lang2 = aim_gettlv_str(innerlist, 0x00d9, 1); | |
223 | else | |
224 | exchanges[curexchange-1].lang2 = NULL; | |
91c55d47 | 225 | |
226 | aim_freetlvchain(&innerlist); | |
0c20631f | 227 | } |
228 | ||
229 | /* | |
230 | * Call client. | |
231 | */ | |
646c6b52 | 232 | if ((userfunc = aim_callhandler(sess, command->conn, 0x000d, 0x0009))) |
233 | ret = userfunc(sess, command, snac->type, maxrooms, curexchange, exchanges); | |
0c20631f | 234 | curexchange--; |
d9142146 | 235 | while(curexchange >= 0) |
0c20631f | 236 | { |
237 | if (exchanges[curexchange].name) | |
238 | free(exchanges[curexchange].name); | |
239 | if (exchanges[curexchange].charset1) | |
240 | free(exchanges[curexchange].charset1); | |
241 | if (exchanges[curexchange].lang1) | |
242 | free(exchanges[curexchange].lang1); | |
243 | if (exchanges[curexchange].charset2) | |
244 | free(exchanges[curexchange].charset2); | |
245 | if (exchanges[curexchange].lang2) | |
246 | free(exchanges[curexchange].lang2); | |
247 | curexchange--; | |
248 | } | |
249 | free(exchanges); | |
0c20631f | 250 | aim_freetlvchain(&tlvlist); |
dad2e696 | 251 | |
252 | break; | |
0c20631f | 253 | } |
254 | case 0x0003: /* request exchange info */ | |
646c6b52 | 255 | faimdprintf(sess, 0, "chatnav_parse_info: resposne to exchange info\n"); |
dad2e696 | 256 | break; |
0c20631f | 257 | case 0x0004: /* request room info */ |
646c6b52 | 258 | faimdprintf(sess, 0, "chatnav_parse_info: response to room info\n"); |
dad2e696 | 259 | break; |
0c20631f | 260 | case 0x0005: /* request more room info */ |
646c6b52 | 261 | faimdprintf(sess, 0, "chatnav_parse_info: response to more room info\n"); |
dad2e696 | 262 | break; |
0c20631f | 263 | case 0x0006: /* request occupant list */ |
646c6b52 | 264 | faimdprintf(sess, 0, "chatnav_parse_info: response to occupant info\n"); |
dad2e696 | 265 | break; |
0c20631f | 266 | case 0x0007: /* search for a room */ |
646c6b52 | 267 | faimdprintf(sess, 0, "chatnav_parse_info: search results\n"); |
dad2e696 | 268 | break; |
efe9513b | 269 | case 0x0008: { /* create room */ |
270 | /* | |
271 | 000d 0009 0000 0000 0010 | |
272 | ||
273 | 0004 0053 | |
274 | 0004 -- exchange | |
275 | 0c 7a 6f6f 6f6d 7a6f 6f6f 6d34 32 cookie/name | |
276 | 0000 -- instance | |
277 | 02 -- detail level | |
278 | 0007 -- unknown! | |
279 | 006a 000c 7a 6f 6f6f 6d7a 6f6f 6f6d 3432 -- fully qualified name | |
280 | 00c9 0002 0011 -- flags | |
281 | 00ca 0004 39c0 0883 -- create time | |
282 | 00d1 0002 0200 -- max msg len | |
283 | 00d2 0002 0018 -- max occupants | |
284 | 00d3 000c -- name | |
285 | 7a6f 6f6f 6d7a 6f6f 6f6d 3432 | |
286 | 00d5 0001 02 -- creation permission | |
287 | */ | |
288 | struct aim_tlvlist_t *tlvlist, *innerlist; | |
289 | char *ck = NULL, *fqcn = NULL, *name = NULL; | |
646c6b52 | 290 | unsigned short exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0; |
efe9513b | 291 | unsigned long createtime = 0; |
646c6b52 | 292 | unsigned char createperms = 0; |
efe9513b | 293 | int i, cklen; |
1ea867e3 | 294 | struct aim_tlv_t *bigblock; |
efe9513b | 295 | |
296 | i = 10; | |
297 | if (!(tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i))) { | |
646c6b52 | 298 | faimdprintf(sess, 0, "unable to read top tlv in create room response\n"); |
efe9513b | 299 | break; |
300 | } | |
301 | ||
302 | if (!(bigblock = aim_gettlv(tlvlist, 0x0004, 1))) { | |
646c6b52 | 303 | faimdprintf(sess, 0, "no bigblock in top tlv in create room response\n"); |
efe9513b | 304 | aim_freetlvchain(&tlvlist); |
305 | break; | |
306 | } | |
307 | i = 0; | |
308 | ||
309 | exchange = aimutil_get16(bigblock->value+i); | |
310 | i += 2; | |
311 | ||
312 | cklen = aimutil_get8(bigblock->value+i); | |
313 | i++; | |
314 | ||
315 | ck = malloc(cklen+1); | |
316 | memcpy(ck, bigblock->value+i, cklen); | |
317 | ck[cklen] = '\0'; | |
318 | i += cklen; | |
319 | ||
320 | instance = aimutil_get16(bigblock->value+i); | |
321 | i += 2; | |
322 | ||
323 | if (aimutil_get8(bigblock->value+i) != 0x02) { | |
646c6b52 | 324 | faimdprintf(sess, 0, "unknown detaillevel in create room response (0x%02x)\n", aimutil_get8(bigblock->value+i)); |
efe9513b | 325 | aim_freetlvchain(&tlvlist); |
326 | free(ck); | |
327 | break; | |
328 | } | |
329 | i += 1; | |
330 | ||
331 | unknown = aimutil_get16(bigblock->value+i); | |
332 | i += 2; | |
333 | ||
334 | if (!(innerlist = aim_readtlvchain(bigblock->value+i, bigblock->length-i))) { | |
646c6b52 | 335 | faimdprintf(sess, 0, "unable to read inner tlv chain in create room response\n"); |
efe9513b | 336 | aim_freetlvchain(&tlvlist); |
337 | free(ck); | |
338 | break; | |
339 | } | |
340 | ||
341 | if (aim_gettlv(innerlist, 0x006a, 1)) | |
342 | fqcn = aim_gettlv_str(innerlist, 0x006a, 1); | |
343 | ||
1ea867e3 | 344 | if (aim_gettlv(innerlist, 0x00c9, 1)) |
345 | flags = aim_gettlv16(innerlist, 0x00c9, 1); | |
efe9513b | 346 | |
1ea867e3 | 347 | if (aim_gettlv(innerlist, 0x00ca, 1)) |
348 | createtime = aim_gettlv32(innerlist, 0x00ca, 1); | |
efe9513b | 349 | |
1ea867e3 | 350 | if (aim_gettlv(innerlist, 0x00d1, 1)) |
351 | maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1); | |
efe9513b | 352 | |
1ea867e3 | 353 | if (aim_gettlv(innerlist, 0x00d2, 1)) |
354 | maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1); | |
efe9513b | 355 | |
356 | if (aim_gettlv(innerlist, 0x00d3, 1)) | |
357 | name = aim_gettlv_str(innerlist, 0x00d3, 1); | |
358 | ||
1ea867e3 | 359 | if (aim_gettlv(innerlist, 0x00d5, 1)) |
360 | createperms = aim_gettlv8(innerlist, 0x00d5, 1); | |
efe9513b | 361 | |
646c6b52 | 362 | if ((userfunc = aim_callhandler(sess, command->conn, 0x000d, 0x0009))) { |
9dbda50b | 363 | ret = userfunc(sess, command, snac->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); |
efe9513b | 364 | } |
365 | ||
366 | if (ck) | |
367 | free(ck); | |
368 | if (name) | |
369 | free(name); | |
370 | if (fqcn) | |
371 | free(fqcn); | |
372 | aim_freetlvchain(&innerlist); | |
373 | aim_freetlvchain(&tlvlist); | |
374 | ||
dad2e696 | 375 | break; |
efe9513b | 376 | } |
0c20631f | 377 | default: /* unknown */ |
646c6b52 | 378 | faimdprintf(sess, 0, "chatnav_parse_info: unknown request subtype (%04x)\n", snac->type); |
0c20631f | 379 | } |
380 | ||
dad2e696 | 381 | if (snac && snac->data) |
382 | free(snac->data); | |
383 | if (snac) | |
384 | free(snac); | |
385 | ||
386 | return ret; | |
0c20631f | 387 | } |
388 | ||
78b3fb13 | 389 | faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess, |
390 | struct aim_conn_t *conn, | |
391 | char *name, | |
392 | u_short exchange) | |
0c20631f | 393 | { |
5b79dc93 | 394 | struct command_tx_struct *newpacket; |
0c20631f | 395 | int i; |
0c20631f | 396 | |
646c6b52 | 397 | if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+12+strlen("invite")+strlen(name)))) |
5b79dc93 | 398 | return -1; |
0c20631f | 399 | |
5b79dc93 | 400 | newpacket->lock = 1; |
0c20631f | 401 | |
5b79dc93 | 402 | i = aim_putsnac(newpacket->data, 0x000d, 0x0008, 0x0000, sess->snac_nextid); |
0c20631f | 403 | |
404 | /* exchange */ | |
5b79dc93 | 405 | i+= aimutil_put16(newpacket->data+i, exchange); |
0c20631f | 406 | |
407 | /* room cookie */ | |
5b79dc93 | 408 | i+= aimutil_put8(newpacket->data+i, strlen("invite")); |
409 | i+= aimutil_putstr(newpacket->data+i, "invite", strlen("invite")); | |
0c20631f | 410 | |
411 | /* instance */ | |
5b79dc93 | 412 | i+= aimutil_put16(newpacket->data+i, 0xffff); |
0c20631f | 413 | |
414 | /* detail level */ | |
5b79dc93 | 415 | i+= aimutil_put8(newpacket->data+i, 0x01); |
0c20631f | 416 | |
417 | /* tlvcount */ | |
5b79dc93 | 418 | i+= aimutil_put16(newpacket->data+i, 0x0001); |
0c20631f | 419 | |
420 | /* room name */ | |
5b79dc93 | 421 | i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name); |
0c20631f | 422 | |
1ea867e3 | 423 | aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); |
0c20631f | 424 | |
5b79dc93 | 425 | aim_tx_enqueue(sess, newpacket); |
0c20631f | 426 | |
1ea867e3 | 427 | return sess->snac_nextid; |
0c20631f | 428 | } |