Mercurial > pidgin
comparison libfaim/chatnav.c @ 1535:1e2cc8c8bf3c
[gaim-migrate @ 1545]
libfaim updates.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Mon, 05 Mar 2001 03:59:32 +0000 |
parents | |
children | 3fe5799b7823 |
comparison
equal
deleted
inserted
replaced
1534:d98b92e3d9ff | 1535:1e2cc8c8bf3c |
---|---|
1 /* | |
2 * Handle ChatNav. | |
3 * | |
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.] | |
7 * | |
8 */ | |
9 | |
10 #define FAIM_INTERNAL | |
11 #include <aim.h> | |
12 | |
13 /* | |
14 * conn must be a chatnav connection! | |
15 */ | |
16 faim_export unsigned long aim_chatnav_reqrights(struct aim_session_t *sess, | |
17 struct aim_conn_t *conn) | |
18 { | |
19 aim_genericreq_n(sess, conn, 0x000d, 0x0002); | |
20 | |
21 return sess->snac_nextid; | |
22 } | |
23 | |
24 faim_export unsigned long aim_chatnav_clientready(struct aim_session_t *sess, | |
25 struct aim_conn_t *conn) | |
26 { | |
27 struct command_tx_struct *newpacket; | |
28 int i; | |
29 | |
30 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 0x20))) | |
31 return -1; | |
32 | |
33 newpacket->lock = 1; | |
34 | |
35 i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid); | |
36 | |
37 i+= aimutil_put16(newpacket->data+i, 0x000d); | |
38 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
39 | |
40 i+= aimutil_put16(newpacket->data+i, 0x0004); | |
41 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
42 | |
43 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
44 i+= aimutil_put16(newpacket->data+i, 0x0003); | |
45 | |
46 i+= aimutil_put16(newpacket->data+i, 0x0004); | |
47 i+= aimutil_put16(newpacket->data+i, 0x0686); | |
48 | |
49 aim_tx_enqueue(sess, newpacket); | |
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 */ | |
59 faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command) | |
60 { | |
61 struct aim_snac_t *snac; | |
62 u_long snacid; | |
63 rxcallback_t userfunc; | |
64 int ret=1; | |
65 | |
66 snacid = aimutil_get32(command->data+6); | |
67 snac = aim_remsnac(sess, snacid); | |
68 | |
69 if (!snac) { | |
70 faimdprintf(sess, 0, "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snacid); | |
71 return 1; | |
72 } | |
73 | |
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 } | |
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; | |
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)) | |
99 maxrooms = aim_gettlv8(tlvlist, 0x0002, 1); | |
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 | |
114 | |
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 | |
131 /* | |
132 * Type 0x0002: Unknown | |
133 */ | |
134 if (aim_gettlv(innerlist, 0x0002, 1)) { | |
135 unsigned short classperms; | |
136 | |
137 classperms = aim_gettlv16(innerlist, 0x0002, 1); | |
138 | |
139 faimdprintf(sess, 1, "faim: class permissions %x\n", classperms); | |
140 } | |
141 | |
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 /* | |
155 * Type 0x00d0: Mandatory Channels? | |
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 /* | |
167 * Type 0x00d2: Maximum Occupancy? | |
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 /* | |
181 * Type 0x00d5: Creation Permissions | |
182 * | |
183 * 0 Creation not allowed | |
184 * 1 Room creation allowed | |
185 * 2 Exchange creation allowed | |
186 * | |
187 */ | |
188 if (aim_gettlv(innerlist, 0x00d5, 1)) { | |
189 unsigned char createperms; | |
190 | |
191 createperms = aim_gettlv8(innerlist, 0x00d5, 1); | |
192 } | |
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; | |
225 | |
226 aim_freetlvchain(&innerlist); | |
227 } | |
228 | |
229 /* | |
230 * Call client. | |
231 */ | |
232 if ((userfunc = aim_callhandler(sess, command->conn, 0x000d, 0x0009))) | |
233 ret = userfunc(sess, command, snac->type, maxrooms, curexchange, exchanges); | |
234 curexchange--; | |
235 while(curexchange >= 0) | |
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); | |
250 aim_freetlvchain(&tlvlist); | |
251 | |
252 break; | |
253 } | |
254 case 0x0003: /* request exchange info */ | |
255 faimdprintf(sess, 0, "chatnav_parse_info: resposne to exchange info\n"); | |
256 break; | |
257 case 0x0004: /* request room info */ | |
258 faimdprintf(sess, 0, "chatnav_parse_info: response to room info\n"); | |
259 break; | |
260 case 0x0005: /* request more room info */ | |
261 faimdprintf(sess, 0, "chatnav_parse_info: response to more room info\n"); | |
262 break; | |
263 case 0x0006: /* request occupant list */ | |
264 faimdprintf(sess, 0, "chatnav_parse_info: response to occupant info\n"); | |
265 break; | |
266 case 0x0007: /* search for a room */ | |
267 faimdprintf(sess, 0, "chatnav_parse_info: search results\n"); | |
268 break; | |
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; | |
290 unsigned short exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0; | |
291 unsigned long createtime = 0; | |
292 unsigned char createperms = 0; | |
293 int i, cklen; | |
294 struct aim_tlv_t *bigblock; | |
295 | |
296 i = 10; | |
297 if (!(tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i))) { | |
298 faimdprintf(sess, 0, "unable to read top tlv in create room response\n"); | |
299 break; | |
300 } | |
301 | |
302 if (!(bigblock = aim_gettlv(tlvlist, 0x0004, 1))) { | |
303 faimdprintf(sess, 0, "no bigblock in top tlv in create room response\n"); | |
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) { | |
324 faimdprintf(sess, 0, "unknown detaillevel in create room response (0x%02x)\n", aimutil_get8(bigblock->value+i)); | |
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))) { | |
335 faimdprintf(sess, 0, "unable to read inner tlv chain in create room response\n"); | |
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 | |
344 if (aim_gettlv(innerlist, 0x00c9, 1)) | |
345 flags = aim_gettlv16(innerlist, 0x00c9, 1); | |
346 | |
347 if (aim_gettlv(innerlist, 0x00ca, 1)) | |
348 createtime = aim_gettlv32(innerlist, 0x00ca, 1); | |
349 | |
350 if (aim_gettlv(innerlist, 0x00d1, 1)) | |
351 maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1); | |
352 | |
353 if (aim_gettlv(innerlist, 0x00d2, 1)) | |
354 maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1); | |
355 | |
356 if (aim_gettlv(innerlist, 0x00d3, 1)) | |
357 name = aim_gettlv_str(innerlist, 0x00d3, 1); | |
358 | |
359 if (aim_gettlv(innerlist, 0x00d5, 1)) | |
360 createperms = aim_gettlv8(innerlist, 0x00d5, 1); | |
361 | |
362 if ((userfunc = aim_callhandler(sess, command->conn, 0x000d, 0x0009))) { | |
363 ret = userfunc(sess, command, snac->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); | |
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 | |
375 break; | |
376 } | |
377 default: /* unknown */ | |
378 faimdprintf(sess, 0, "chatnav_parse_info: unknown request subtype (%04x)\n", snac->type); | |
379 } | |
380 | |
381 if (snac && snac->data) | |
382 free(snac->data); | |
383 if (snac) | |
384 free(snac); | |
385 | |
386 return ret; | |
387 } | |
388 | |
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) | |
393 { | |
394 struct command_tx_struct *newpacket; | |
395 int i; | |
396 | |
397 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+12+strlen("invite")+strlen(name)))) | |
398 return -1; | |
399 | |
400 newpacket->lock = 1; | |
401 | |
402 i = aim_putsnac(newpacket->data, 0x000d, 0x0008, 0x0000, sess->snac_nextid); | |
403 | |
404 /* exchange */ | |
405 i+= aimutil_put16(newpacket->data+i, exchange); | |
406 | |
407 /* room cookie */ | |
408 i+= aimutil_put8(newpacket->data+i, strlen("invite")); | |
409 i+= aimutil_putstr(newpacket->data+i, "invite", strlen("invite")); | |
410 | |
411 /* instance */ | |
412 i+= aimutil_put16(newpacket->data+i, 0xffff); | |
413 | |
414 /* detail level */ | |
415 i+= aimutil_put8(newpacket->data+i, 0x01); | |
416 | |
417 /* tlvcount */ | |
418 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
419 | |
420 /* room name */ | |
421 i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name); | |
422 | |
423 aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); | |
424 | |
425 aim_tx_enqueue(sess, newpacket); | |
426 | |
427 return sess->snac_nextid; | |
428 } |