]> andersk Git - libfaim.git/blame_incremental - aim_chatnav.c
- Thu Dec 14 03:39:34 UTC 2000
[libfaim.git] / aim_chatnav.c
... / ...
CommitLineData
1/*
2 *
3 *
4 *
5 *
6 */
7
8#include <faim/aim.h>
9
10
11/*
12 * conn must be a chatnav connection!
13 */
14faim_export unsigned long aim_chatnav_reqrights(struct aim_session_t *sess,
15 struct aim_conn_t *conn)
16{
17 aim_genericreq_n(sess, conn, 0x000d, 0x0002);
18
19 return sess->snac_nextid;
20}
21
22faim_export unsigned long aim_chatnav_clientready(struct aim_session_t *sess,
23 struct aim_conn_t *conn)
24{
25 struct command_tx_struct *newpacket;
26 int i;
27
28 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 0x20)))
29 return -1;
30
31 newpacket->lock = 1;
32
33 i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid);
34
35 i+= aimutil_put16(newpacket->data+i, 0x000d);
36 i+= aimutil_put16(newpacket->data+i, 0x0001);
37
38 i+= aimutil_put16(newpacket->data+i, 0x0004);
39 i+= aimutil_put16(newpacket->data+i, 0x0001);
40
41 i+= aimutil_put16(newpacket->data+i, 0x0001);
42 i+= aimutil_put16(newpacket->data+i, 0x0003);
43
44 i+= aimutil_put16(newpacket->data+i, 0x0004);
45 i+= aimutil_put16(newpacket->data+i, 0x0686);
46
47 aim_tx_enqueue(sess, newpacket);
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 */
57faim_internal int aim_chatnav_parse_info(struct aim_session_t *sess, struct command_rx_struct *command)
58{
59 struct aim_snac_t *snac;
60 u_long snacid;
61 rxcallback_t userfunc;
62 int ret=1;
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;
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 printf("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 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--;
241 while(curexchange >= 0)
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);
256 aim_freetlvchain(&tlvlist);
257
258 break;
259 }
260 case 0x0003: /* request exchange info */
261 printf("faim: chatnav_parse_info: resposne to exchange info\n");
262 break;
263 case 0x0004: /* request room info */
264 printf("faim: chatnav_parse_info: response to room info\n");
265 break;
266 case 0x0005: /* request more room info */
267 printf("faim: chatnav_parse_info: response to more room info\n");
268 break;
269 case 0x0006: /* request occupant list */
270 printf("faim: chatnav_parse_info: response to occupant info\n");
271 break;
272 case 0x0007: /* search for a room */
273 printf("faim: chatnav_parse_info: search results\n");
274 break;
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;
300 struct aim_tlv_t *bigblock;
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
350 if (aim_gettlv(innerlist, 0x00c9, 1))
351 flags = aim_gettlv16(innerlist, 0x00c9, 1);
352
353 if (aim_gettlv(innerlist, 0x00ca, 1))
354 createtime = aim_gettlv32(innerlist, 0x00ca, 1);
355
356 if (aim_gettlv(innerlist, 0x00d1, 1))
357 maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1);
358
359 if (aim_gettlv(innerlist, 0x00d2, 1))
360 maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1);
361
362 if (aim_gettlv(innerlist, 0x00d3, 1))
363 name = aim_gettlv_str(innerlist, 0x00d3, 1);
364
365 if (aim_gettlv(innerlist, 0x00d5, 1))
366 createperms = aim_gettlv8(innerlist, 0x00d5, 1);
367
368 if ((userfunc = aim_callhandler(command->conn, 0x000d, 0x0009))) {
369 ret = userfunc(sess, command, snac->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck);
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
381 break;
382 }
383 default: /* unknown */
384 printf("faim: chatnav_parse_info: unknown request subtype (%04x)\n", snac->type);
385 }
386
387 if (snac && snac->data)
388 free(snac->data);
389 if (snac)
390 free(snac);
391
392 return ret;
393}
394
395faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess,
396 struct aim_conn_t *conn,
397 char *name,
398 u_short exchange)
399{
400 struct command_tx_struct *newpacket;
401 int i;
402
403 if (!(newpacket = aim_tx_new(AIM_FRAMETYPE_OSCAR, 0x0002, conn, 10+12+strlen("invite")+strlen(name))))
404 return -1;
405
406 newpacket->lock = 1;
407
408 i = aim_putsnac(newpacket->data, 0x000d, 0x0008, 0x0000, sess->snac_nextid);
409
410 /* exchange */
411 i+= aimutil_put16(newpacket->data+i, exchange);
412
413 /* room cookie */
414 i+= aimutil_put8(newpacket->data+i, strlen("invite"));
415 i+= aimutil_putstr(newpacket->data+i, "invite", strlen("invite"));
416
417 /* instance */
418 i+= aimutil_put16(newpacket->data+i, 0xffff);
419
420 /* detail level */
421 i+= aimutil_put8(newpacket->data+i, 0x01);
422
423 /* tlvcount */
424 i+= aimutil_put16(newpacket->data+i, 0x0001);
425
426 /* room name */
427 i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name);
428
429 aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0);
430
431 aim_tx_enqueue(sess, newpacket);
432
433 return sess->snac_nextid;
434}
This page took 0.121953 seconds and 5 git commands to generate.