Mercurial > pidgin.yaz
annotate libfaim/chatnav.c @ 1839:109cacf1ff97
[gaim-migrate @ 1849]
now we don't require a hash server anymore. but it still has the ability to use one.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 11 May 2001 21:54:27 +0000 |
parents | 3fe5799b7823 |
children | 741842331ceb |
rev | line source |
---|---|
1535 | 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 faim_export unsigned long aim_chatnav_createroom(struct aim_session_t *sess, | |
55 struct aim_conn_t *conn, | |
56 char *name, | |
57 u_short exchange) | |
58 { | |
59 struct command_tx_struct *newpacket; | |
60 int i; | |
61 | |
62 if (!(newpacket = aim_tx_new(sess, conn, AIM_FRAMETYPE_OSCAR, 0x0002, 10+12+strlen("invite")+strlen(name)))) | |
63 return -1; | |
64 | |
65 newpacket->lock = 1; | |
66 | |
67 i = aim_putsnac(newpacket->data, 0x000d, 0x0008, 0x0000, sess->snac_nextid); | |
68 | |
69 /* exchange */ | |
70 i+= aimutil_put16(newpacket->data+i, exchange); | |
71 | |
72 /* room cookie */ | |
73 i+= aimutil_put8(newpacket->data+i, strlen("invite")); | |
74 i+= aimutil_putstr(newpacket->data+i, "invite", strlen("invite")); | |
75 | |
76 /* instance */ | |
77 i+= aimutil_put16(newpacket->data+i, 0xffff); | |
78 | |
79 /* detail level */ | |
80 i+= aimutil_put8(newpacket->data+i, 0x01); | |
81 | |
82 /* tlvcount */ | |
83 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
84 | |
85 /* room name */ | |
86 i+= aim_puttlv_str(newpacket->data+i, 0x00d3, strlen(name), name); | |
87 | |
88 aim_cachesnac(sess, 0x000d, 0x0008, 0x0000, NULL, 0); | |
89 | |
90 aim_tx_enqueue(sess, newpacket); | |
91 | |
92 return sess->snac_nextid; | |
93 } | |
1649 | 94 |
95 static int parseinfo_perms(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen, struct aim_snac_t *snac2) | |
96 { | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
97 aim_rxcallback_t userfunc; |
1649 | 98 int ret = 0; |
99 struct aim_tlvlist_t *tlvlist; | |
100 struct aim_chat_exchangeinfo *exchanges = NULL; | |
101 int curexchange = 0; | |
102 struct aim_tlv_t *exchangetlv; | |
103 unsigned char maxrooms = 0; | |
104 struct aim_tlvlist_t *innerlist; | |
105 | |
106 tlvlist = aim_readtlvchain(data, datalen); | |
107 | |
108 /* | |
109 * Type 0x0002: Maximum concurrent rooms. | |
110 */ | |
111 if (aim_gettlv(tlvlist, 0x0002, 1)) | |
112 maxrooms = aim_gettlv8(tlvlist, 0x0002, 1); | |
113 | |
114 /* | |
115 * Type 0x0003: Exchange information | |
116 * | |
117 * There can be any number of these, each one | |
118 * representing another exchange. | |
119 * | |
120 */ | |
121 curexchange = 0; | |
122 while ((exchangetlv = aim_gettlv(tlvlist, 0x0003, curexchange+1))) { | |
123 curexchange++; | |
124 exchanges = realloc(exchanges, curexchange * sizeof(struct aim_chat_exchangeinfo)); | |
125 /* exchange number */ | |
126 exchanges[curexchange-1].number = aimutil_get16(exchangetlv->value); | |
127 innerlist = aim_readtlvchain(exchangetlv->value+2, exchangetlv->length-2); | |
128 | |
129 /* | |
130 * Type 0x000d: Unknown. | |
131 */ | |
132 if (aim_gettlv(innerlist, 0x000d, 1)) | |
133 ; | |
134 | |
135 /* | |
136 * Type 0x0004: Unknown | |
137 */ | |
138 if (aim_gettlv(innerlist, 0x0004, 1)) | |
139 ; | |
140 | |
141 /* | |
142 * Type 0x0002: Unknown | |
143 */ | |
144 if (aim_gettlv(innerlist, 0x0002, 1)) { | |
145 unsigned short classperms; | |
146 | |
147 classperms = aim_gettlv16(innerlist, 0x0002, 1); | |
148 | |
149 faimdprintf(sess, 1, "faim: class permissions %x\n", classperms); | |
150 } | |
151 | |
152 /* | |
153 * Type 0x00c9: Unknown | |
154 */ | |
155 if (aim_gettlv(innerlist, 0x00c9, 1)) | |
156 ; | |
157 | |
158 /* | |
159 * Type 0x00ca: Creation Date | |
160 */ | |
161 if (aim_gettlv(innerlist, 0x00ca, 1)) | |
162 ; | |
163 | |
164 /* | |
165 * Type 0x00d0: Mandatory Channels? | |
166 */ | |
167 if (aim_gettlv(innerlist, 0x00d0, 1)) | |
168 ; | |
169 | |
170 /* | |
171 * Type 0x00d1: Maximum Message length | |
172 */ | |
173 if (aim_gettlv(innerlist, 0x00d1, 1)) | |
174 ; | |
175 | |
176 /* | |
177 * Type 0x00d2: Maximum Occupancy? | |
178 */ | |
179 if (aim_gettlv(innerlist, 0x00d2, 1)) | |
180 ; | |
181 | |
182 /* | |
183 * Type 0x00d3: Exchange Name | |
184 */ | |
185 if (aim_gettlv(innerlist, 0x00d3, 1)) | |
186 exchanges[curexchange-1].name = aim_gettlv_str(innerlist, 0x00d3, 1); | |
187 else | |
188 exchanges[curexchange-1].name = NULL; | |
189 | |
190 /* | |
191 * Type 0x00d5: Creation Permissions | |
192 * | |
193 * 0 Creation not allowed | |
194 * 1 Room creation allowed | |
195 * 2 Exchange creation allowed | |
196 * | |
197 */ | |
198 if (aim_gettlv(innerlist, 0x00d5, 1)) { | |
199 unsigned char createperms; | |
200 | |
201 createperms = aim_gettlv8(innerlist, 0x00d5, 1); | |
202 } | |
203 | |
204 /* | |
205 * Type 0x00d6: Character Set (First Time) | |
206 */ | |
207 if (aim_gettlv(innerlist, 0x00d6, 1)) | |
208 exchanges[curexchange-1].charset1 = aim_gettlv_str(innerlist, 0x00d6, 1); | |
209 else | |
210 exchanges[curexchange-1].charset1 = NULL; | |
211 | |
212 /* | |
213 * Type 0x00d7: Language (First Time) | |
214 */ | |
215 if (aim_gettlv(innerlist, 0x00d7, 1)) | |
216 exchanges[curexchange-1].lang1 = aim_gettlv_str(innerlist, 0x00d7, 1); | |
217 else | |
218 exchanges[curexchange-1].lang1 = NULL; | |
219 | |
220 /* | |
221 * Type 0x00d8: Character Set (Second Time) | |
222 */ | |
223 if (aim_gettlv(innerlist, 0x00d8, 1)) | |
224 exchanges[curexchange-1].charset2 = aim_gettlv_str(innerlist, 0x00d8, 1); | |
225 else | |
226 exchanges[curexchange-1].charset2 = NULL; | |
227 | |
228 /* | |
229 * Type 0x00d9: Language (Second Time) | |
230 */ | |
231 if (aim_gettlv(innerlist, 0x00d9, 1)) | |
232 exchanges[curexchange-1].lang2 = aim_gettlv_str(innerlist, 0x00d9, 1); | |
233 else | |
234 exchanges[curexchange-1].lang2 = NULL; | |
235 | |
236 aim_freetlvchain(&innerlist); | |
237 } | |
238 | |
239 /* | |
240 * Call client. | |
241 */ | |
242 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
243 ret = userfunc(sess, rx, snac2->type, maxrooms, curexchange, exchanges); | |
244 curexchange--; | |
245 while(curexchange >= 0) { | |
246 free(exchanges[curexchange].name); | |
247 free(exchanges[curexchange].charset1); | |
248 free(exchanges[curexchange].lang1); | |
249 free(exchanges[curexchange].charset2); | |
250 free(exchanges[curexchange].lang2); | |
251 curexchange--; | |
252 } | |
253 free(exchanges); | |
254 aim_freetlvchain(&tlvlist); | |
255 | |
256 return ret; | |
257 } | |
258 | |
259 static int parseinfo_create(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen, struct aim_snac_t *snac2) | |
260 { | |
1839
109cacf1ff97
[gaim-migrate @ 1849]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
1649
diff
changeset
|
261 aim_rxcallback_t userfunc; |
1649 | 262 struct aim_tlvlist_t *tlvlist, *innerlist; |
263 char *ck = NULL, *fqcn = NULL, *name = NULL; | |
264 unsigned short exchange = 0, instance = 0, unknown = 0, flags = 0, maxmsglen = 0, maxoccupancy = 0; | |
265 unsigned long createtime = 0; | |
266 unsigned char createperms = 0; | |
267 int i = 0, cklen; | |
268 struct aim_tlv_t *bigblock; | |
269 int ret = 0; | |
270 | |
271 if (!(tlvlist = aim_readtlvchain(data, datalen))) { | |
272 faimdprintf(sess, 0, "unable to read top tlv in create room response\n"); | |
273 return 0; | |
274 } | |
275 | |
276 if (!(bigblock = aim_gettlv(tlvlist, 0x0004, 1))) { | |
277 faimdprintf(sess, 0, "no bigblock in top tlv in create room response\n"); | |
278 aim_freetlvchain(&tlvlist); | |
279 return 0; | |
280 } | |
281 | |
282 exchange = aimutil_get16(bigblock->value+i); | |
283 i += 2; | |
284 | |
285 cklen = aimutil_get8(bigblock->value+i); | |
286 i++; | |
287 | |
288 ck = malloc(cklen+1); | |
289 memcpy(ck, bigblock->value+i, cklen); | |
290 ck[cklen] = '\0'; | |
291 i += cklen; | |
292 | |
293 instance = aimutil_get16(bigblock->value+i); | |
294 i += 2; | |
295 | |
296 if (aimutil_get8(bigblock->value+i) != 0x02) { | |
297 faimdprintf(sess, 0, "unknown detaillevel in create room response (0x%02x)\n", aimutil_get8(bigblock->value+i)); | |
298 aim_freetlvchain(&tlvlist); | |
299 free(ck); | |
300 return 0; | |
301 } | |
302 i += 1; | |
303 | |
304 unknown = aimutil_get16(bigblock->value+i); | |
305 i += 2; | |
306 | |
307 if (!(innerlist = aim_readtlvchain(bigblock->value+i, bigblock->length-i))) { | |
308 faimdprintf(sess, 0, "unable to read inner tlv chain in create room response\n"); | |
309 aim_freetlvchain(&tlvlist); | |
310 free(ck); | |
311 return 0; | |
312 } | |
313 | |
314 if (aim_gettlv(innerlist, 0x006a, 1)) | |
315 fqcn = aim_gettlv_str(innerlist, 0x006a, 1); | |
316 | |
317 if (aim_gettlv(innerlist, 0x00c9, 1)) | |
318 flags = aim_gettlv16(innerlist, 0x00c9, 1); | |
319 | |
320 if (aim_gettlv(innerlist, 0x00ca, 1)) | |
321 createtime = aim_gettlv32(innerlist, 0x00ca, 1); | |
322 | |
323 if (aim_gettlv(innerlist, 0x00d1, 1)) | |
324 maxmsglen = aim_gettlv16(innerlist, 0x00d1, 1); | |
325 | |
326 if (aim_gettlv(innerlist, 0x00d2, 1)) | |
327 maxoccupancy = aim_gettlv16(innerlist, 0x00d2, 1); | |
328 | |
329 if (aim_gettlv(innerlist, 0x00d3, 1)) | |
330 name = aim_gettlv_str(innerlist, 0x00d3, 1); | |
331 | |
332 if (aim_gettlv(innerlist, 0x00d5, 1)) | |
333 createperms = aim_gettlv8(innerlist, 0x00d5, 1); | |
334 | |
335 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) | |
336 ret = userfunc(sess, rx, snac2->type, fqcn, instance, exchange, flags, createtime, maxmsglen, maxoccupancy, createperms, unknown, name, ck); | |
337 | |
338 free(ck); | |
339 free(name); | |
340 free(fqcn); | |
341 aim_freetlvchain(&innerlist); | |
342 aim_freetlvchain(&tlvlist); | |
343 | |
344 return ret; | |
345 } | |
346 | |
347 /* | |
348 * Since multiple things can trigger this callback, | |
349 * we must lookup the snacid to determine the original | |
350 * snac subtype that was called. | |
351 */ | |
352 static int parseinfo(struct aim_session_t *sess, aim_module_t *mod, struct command_rx_struct *rx, aim_modsnac_t *snac, unsigned char *data, int datalen) | |
353 { | |
354 struct aim_snac_t *snac2; | |
355 int ret = 0; | |
356 | |
357 if (!(snac2 = aim_remsnac(sess, snac->id))) { | |
358 faimdprintf(sess, 0, "faim: chatnav_parse_info: received response to unknown request! (%08lx)\n", snac->id); | |
359 return 0; | |
360 } | |
361 | |
362 if (snac2->family != 0x000d) { | |
363 faimdprintf(sess, 0, "faim: chatnav_parse_info: recieved response that maps to corrupt request! (fam=%04x)\n", snac2->family); | |
364 return 0; | |
365 } | |
366 | |
367 /* | |
368 * We now know what the original SNAC subtype was. | |
369 */ | |
370 if (snac2->type == 0x0002) /* request chat rights */ | |
371 ret = parseinfo_perms(sess, mod, rx, snac, data, datalen, snac2); | |
372 else if (snac2->type == 0x0003) /* request exchange info */ | |
373 faimdprintf(sess, 0, "chatnav_parse_info: resposne to exchange info\n"); | |
374 else if (snac2->type == 0x0004) /* request room info */ | |
375 faimdprintf(sess, 0, "chatnav_parse_info: response to room info\n"); | |
376 else if (snac2->type == 0x0005) /* request more room info */ | |
377 faimdprintf(sess, 0, "chatnav_parse_info: response to more room info\n"); | |
378 else if (snac2->type == 0x0006) /* request occupant list */ | |
379 faimdprintf(sess, 0, "chatnav_parse_info: response to occupant info\n"); | |
380 else if (snac2->type == 0x0007) /* search for a room */ | |
381 faimdprintf(sess, 0, "chatnav_parse_info: search results\n"); | |
382 else if (snac2->type == 0x0008) /* create room */ | |
383 ret = parseinfo_create(sess, mod, rx, snac, data, datalen, snac2); | |
384 else | |
385 faimdprintf(sess, 0, "chatnav_parse_info: unknown request subtype (%04x)\n", snac2->type); | |
386 | |
387 if (snac2) | |
388 free(snac2->data); | |
389 free(snac2); | |
390 | |
391 return ret; | |
392 } | |
393 | |
394 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) | |
395 { | |
396 | |
397 if (snac->subtype == 0x0009) | |
398 return parseinfo(sess, mod, rx, snac, data, datalen); | |
399 | |
400 return 0; | |
401 } | |
402 | |
403 faim_internal int chatnav_modfirst(struct aim_session_t *sess, aim_module_t *mod) | |
404 { | |
405 | |
406 mod->family = 0x000d; | |
407 mod->version = 0x0000; | |
408 mod->flags = 0; | |
409 strncpy(mod->name, "chatnav", sizeof(mod->name)); | |
410 mod->snachandler = snachandler; | |
411 | |
412 return 0; | |
413 } |