]>
Commit | Line | Data |
---|---|---|
9de3ca7e | 1 | /* |
2 | * | |
3 | * | |
4 | * | |
5 | * | |
6 | */ | |
7 | ||
a25832e6 | 8 | #include <faim/aim.h> |
9de3ca7e | 9 | |
0c20631f | 10 | |
11 | /* | |
12 | * conn must be a chatnav connection! | |
13 | */ | |
78b3fb13 | 14 | faim_export unsigned long aim_chatnav_reqrights(struct aim_session_t *sess, |
15 | struct aim_conn_t *conn) | |
0c20631f | 16 | { |
1ea867e3 | 17 | aim_genericreq_n(sess, conn, 0x000d, 0x0002); |
0c20631f | 18 | |
1ea867e3 | 19 | return sess->snac_nextid; |
0c20631f | 20 | } |
21 | ||
78b3fb13 | 22 | faim_export unsigned long aim_chatnav_clientready(struct aim_session_t *sess, |
23 | struct aim_conn_t *conn) | |
0c20631f | 24 | { |
5b79dc93 | 25 | struct command_tx_struct *newpacket; |
0c20631f | 26 | int i; |
27 | ||
b69540e3 | 28 | if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 0x20))) |
5b79dc93 | 29 | return -1; |
0c20631f | 30 | |
5b79dc93 | 31 | newpacket->lock = 1; |
0c20631f | 32 | |
5b79dc93 | 33 | i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid); |
0c20631f | 34 | |
5b79dc93 | 35 | i+= aimutil_put16(newpacket->data+i, 0x000d); |
36 | i+= aimutil_put16(newpacket->data+i, 0x0001); | |
0c20631f | 37 | |
5b79dc93 | 38 | i+= aimutil_put16(newpacket->data+i, 0x0004); |
39 | i+= aimutil_put16(newpacket->data+i, 0x0001); | |
0c20631f | 40 | |
5b79dc93 | 41 | i+= aimutil_put16(newpacket->data+i, 0x0001); |
42 | i+= aimutil_put16(newpacket->data+i, 0x0003); | |
0c20631f | 43 | |
5b79dc93 | 44 | i+= aimutil_put16(newpacket->data+i, 0x0004); |
45 | i+= aimutil_put16(newpacket->data+i, 0x0686); | |
46 | ||
47 | aim_tx_enqueue(sess, newpacket); | |
0c20631f | 48 | |
49 | return (sess->snac_nextid++); | |
50 | } | |
51 | ||
52 | /* | |
53 | * Since multiple things can trigger this callback, | |
54 | * we must lookup the snacid to determine the original | |
55 | * snac subtype that was called. | |
56 | */ | |
78b3fb13 | 57 | faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command) |
0c20631f | 58 | { |
59 | struct aim_snac_t *snac; | |
60 | u_long snacid; | |
61 | rxcallback_t userfunc; | |
dad2e696 | 62 | int ret=1; |
0c20631f | 63 | |
64 | snacid = aimutil_get32(command->data+6); | |
65 | snac = aim_remsnac(sess, snacid); | |
66 | ||
67 | if (!snac) | |
68 | { | |
69 | printf("faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snacid); | |
70 | return 1; | |
71 | } | |
72 | ||
73 | if (snac->family != 0x000d) | |
74 | { | |
75 | printf("faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac->family); | |
76 | return 1; | |
77 | } | |
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 | |
139 | printf("faim: class permissions %x\n", classperms); | |
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 | */ | |
232 | userfunc = aim_callhandler(command->conn, 0x000d, 0x0009); | |
233 | if (userfunc) | |
234 | ret = userfunc(sess, | |
235 | command, | |
236 | snac->type, | |
237 | maxrooms, | |
238 | curexchange, | |
239 | exchanges); | |
240 | curexchange--; | |
d9142146 | 241 | while(curexchange >= 0) |
0c20631f | 242 | { |
243 | if (exchanges[curexchange].name) | |
244 | free(exchanges[curexchange].name); | |
245 | if (exchanges[curexchange].charset1) | |
246 | free(exchanges[curexchange].charset1); | |
247 | if (exchanges[curexchange].lang1) | |
248 | free(exchanges[curexchange].lang1); | |
249 | if (exchanges[curexchange].charset2) | |
250 | free(exchanges[curexchange].charset2); | |
251 | if (exchanges[curexchange].lang2) | |
252 | free(exchanges[curexchange].lang2); | |
253 | curexchange--; | |
254 | } | |
255 | free(exchanges); | |
0c20631f | 256 | aim_freetlvchain(&tlvlist); |
dad2e696 | 257 | |
258 | break; | |
0c20631f | 259 | } |
260 | case 0x0003: /* request exchange info */ | |
261 | printf("faim: chatnav_parse_info: resposne to exchange info\n"); | |
dad2e696 | 262 | break; |
0c20631f | 263 | case 0x0004: /* request room info */ |
264 | printf("faim: chatnav_parse_info: response to room info\n"); | |
dad2e696 | 265 | break; |
0c20631f | 266 | case 0x0005: /* request more room info */ |
267 | printf("faim: chatnav_parse_info: response to more room info\n"); | |
dad2e696 | 268 | break; |
0c20631f | 269 | case 0x0006: /* request occupant list */ |
270 | printf("faim: chatnav_parse_info: response to occupant info\n"); | |
dad2e696 | 271 | break; |
0c20631f | 272 | case 0x0007: /* search for a room */ |
273 | printf("faim: chatnav_parse_info: search results\n"); | |
dad2e696 | 274 | break; |
efe9513b | 275 | case 0x0008: { /* create room */ |
276 | /* | |
277 | 000d 0009 0000 0000 0010 | |
278 | ||
279 | 0004 0053 | |
280 | 0004 -- exchange | |
281 | 0c 7a 6f6f 6f6d 7a6f 6f6f 6d34 32 cookie/name | |
282 | 0000 -- instance | |
283 | 02 -- detail level | |
284 | 0007 -- unknown! | |
285 | 006a 000c 7a 6f 6f6f 6d7a 6f6f 6f6d 3432 -- fully qualified name | |
286 | 00c9 0002 0011 -- flags | |
287 | 00ca 0004 39c0 0883 -- create time | |
288 | 00d1 0002 0200 -- max msg len | |
289 | 00d2 0002 0018 -- max occupants | |
290 | 00d3 000c -- name | |
291 | 7a6f 6f6f 6d7a 6f6f 6f6d 3432 | |
292 | 00d5 0001 02 -- creation permission | |
293 | */ | |
294 | struct aim_tlvlist_t *tlvlist, *innerlist; | |
295 | char *ck = NULL, *fqcn = NULL, *name = NULL; | |
296 | unsigned short exchange, instance, unknown, flags, maxmsglen, maxoccupancy; | |
297 | unsigned long createtime = 0; | |
298 | unsigned char createperms; | |
299 | int i, cklen; | |
1ea867e3 | 300 | struct aim_tlv_t *bigblock; |
efe9513b | 301 | |
302 | i = 10; | |
303 | if (!(tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i))) { | |
304 | printf("faim: unable to read top tlv in create room response\n"); | |
305 | break; | |
306 | } | |
307 | ||
308 | if (!(bigblock = aim_gettlv(tlvlist, 0x0004, 1))) { | |
309 | printf("faim: no bigblock in top tlv in create room response\n"); | |
310 | aim_freetlvchain(&tlvlist); | |
311 | break; | |
312 | } | |
313 | i = 0; | |
314 | ||
315 | exchange = aimutil_get16(bigblock->value+i); | |
316 | i += 2; | |
317 | ||
318 | cklen = aimutil_get8(bigblock->value+i); | |
319 | i++; | |
320 | ||
321 | ck = malloc(cklen+1); | |
322 | memcpy(ck, bigblock->value+i, cklen); | |
323 | ck[cklen] = '\0'; | |
324 | i += cklen; | |
325 | ||
326 | instance = aimutil_get16(bigblock->value+i); | |
327 | i += 2; | |
328 | ||
329 | if (aimutil_get8(bigblock->value+i) != 0x02) { | |
330 | printf("faim: unknown detaillevel in create room response (0x%02x)\n", aimutil_get8(bigblock->value+i)); | |
331 | aim_freetlvchain(&tlvlist); | |
332 | free(ck); | |
333 | break; | |
334 | } | |
335 | i += 1; | |
336 | ||
337 | unknown = aimutil_get16(bigblock->value+i); | |
338 | i += 2; | |
339 | ||
340 | if (!(innerlist = aim_readtlvchain(bigblock->value+i, bigblock->length-i))) { | |
341 | printf("faim: unable to read inner tlv chain in create room response\n"); | |
342 | aim_freetlvchain(&tlvlist); | |
343 | free(ck); | |
344 | break; | |
345 | } | |
346 | ||
347 | if (aim_gettlv(innerlist, 0x006a, 1)) | |
348 | fqcn = aim_gettlv_str(innerlist, 0x006a, 1); | |
349 | ||
1ea867e3 | 350 | if (aim_gettlv(innerlist, 0x00c9, 1)) |
351 | flags = aim_gettlv16(innerlist, 0x00c9, 1); | |
efe9513b | 352 | |
1ea867e3 | 353 | if (aim_gettlv(innerlist, 0x00ca, 1)) |
354 | createtime = aim_gettlv32(innerlist, 0x00ca, 1); | |
efe9513b | 355 | |
1ea867e3 | 356 | if (aim_gettlv(innerlist, 0x00d1, 1)) |
357 | maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1); | |
efe9513b | 358 | |
1ea867e3 | 359 | if (aim_gettlv(innerlist, 0x00d2, 1)) |
360 | maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1); | |
efe9513b | 361 | |
362 | if (aim_gettlv(innerlist, 0x00d3, 1)) | |
363 | name = aim_gettlv_str(innerlist, 0x00d3, 1); | |
364 | ||
1ea867e3 | 365 | if (aim_gettlv(innerlist, 0x00d5, 1)) |
366 | createperms = aim_gettlv8(innerlist, 0x00d5, 1); | |
efe9513b | 367 | |
368 | if ((userfunc = aim_callhandler(command->conn, 0x000d, 0x0009))) { | |
9dbda50b | 369 | ret = userfunc(sess, command, snac->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); |
efe9513b | 370 | } |
371 | ||
372 | if (ck) | |
373 | free(ck); | |
374 | if (name) | |
375 | free(name); | |
376 | if (fqcn) | |
377 | free(fqcn); | |
378 | aim_freetlvchain(&innerlist); | |
379 | aim_freetlvchain(&tlvlist); | |
380 | ||
dad2e696 | 381 | break; |
efe9513b | 382 | } |
0c20631f | 383 | default: /* unknown */ |
384 | printf("faim: chatnav_parse_info: unknown request subtype (%04x)\n", snac->type); | |
385 | } | |
386 | ||
dad2e696 | 387 | if (snac && snac->data) |
388 | free(snac->data); | |
389 | if (snac) | |
390 | free(snac); | |
391 | ||
392 | return ret; | |
0c20631f | 393 | } |
394 | ||
78b3fb13 | 395 | faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess, |
396 | struct aim_conn_t *conn, | |
397 | char *name, | |
398 | u_short exchange) | |
0c20631f | 399 | { |
5b79dc93 | 400 | struct command_tx_struct *newpacket; |
0c20631f | 401 | int i; |
0c20631f | 402 | |
b69540e3 | 403 | if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+12+strlen("invite")+strlen(name)))) |
5b79dc93 | 404 | return -1; |
0c20631f | 405 | |
5b79dc93 | 406 | newpacket->lock = 1; |
0c20631f | 407 | |
5b79dc93 | 408 | i = aim_putsnac(newpacket->data, 0x000d, 0x0008, 0x0000, sess->snac_nextid); |
0c20631f | 409 | |
410 | /* exchange */ | |
5b79dc93 | 411 | i+= aimutil_put16(newpacket->data+i, exchange); |
0c20631f | 412 | |
413 | /* room cookie */ | |
5b79dc93 | 414 | i+= aimutil_put8(newpacket->data+i, strlen("invite")); |
415 | i+= aimutil_putstr(newpacket->data+i, "invite", strlen("invite")); | |
0c20631f | 416 | |
417 | /* instance */ | |
5b79dc93 | 418 | i+= aimutil_put16(newpacket->data+i, 0xffff); |
0c20631f | 419 | |
420 | /* detail level */ | |
5b79dc93 | 421 | i+= aimutil_put8(newpacket->data+i, 0x01); |
0c20631f | 422 | |
423 | /* tlvcount */ | |
5b79dc93 | 424 | i+= aimutil_put16(newpacket->data+i, 0x0001); |
0c20631f | 425 | |
426 | /* room name */ | |
5b79dc93 | 427 | i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name); |
0c20631f | 428 | |
1ea867e3 | 429 | aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); |
0c20631f | 430 | |
5b79dc93 | 431 | aim_tx_enqueue(sess, newpacket); |
0c20631f | 432 | |
1ea867e3 | 433 | return sess->snac_nextid; |
0c20631f | 434 | } |