Mercurial > pidgin
annotate libfaim/aim_chat.c @ 319:cea40691706c
[gaim-migrate @ 329]
A few good oscar changes before release.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 02 Jun 2000 19:45:16 +0000 |
parents | 8cdc4ab449ec |
children | 9d258a0aa560 |
rev | line source |
---|---|
2 | 1 /* |
2 * aim_chat.c | |
3 * | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
4 * Routines for the Chat service. |
2 | 5 * |
6 */ | |
7 | |
283
0f14e6d8a51b
[gaim-migrate @ 293]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
8 #include <faim/aim.h> |
237 | 9 |
10 char *aim_chat_getname(struct aim_conn_t *conn) | |
11 { | |
12 if (!conn) | |
13 return NULL; | |
14 if (conn->type != AIM_CONN_TYPE_CHAT) | |
15 return NULL; | |
16 | |
17 return (char *)conn->priv; /* yuck ! */ | |
18 } | |
19 | |
20 struct aim_conn_t *aim_chat_getconn(struct aim_session_t *sess, char *name) | |
21 { | |
22 int i; | |
23 | |
24 for (i=0;i<AIM_CONN_MAX;i++) | |
25 { | |
26 if (sess->conns[i].type == AIM_CONN_TYPE_CHAT) | |
27 { | |
28 if (sess->conns[i].priv) | |
29 if (!strcmp((char *)sess->conns[i].priv, name)) | |
30 { | |
31 return &sess->conns[i]; | |
32 } | |
33 } | |
34 } | |
35 return NULL; | |
36 } | |
37 | |
38 int aim_chat_attachname(struct aim_conn_t *conn, char *roomname) | |
39 { | |
40 if (!conn || !roomname) | |
41 return -1; | |
42 | |
43 conn->priv = malloc(strlen(roomname)+1); | |
44 strcpy(conn->priv, roomname); | |
45 | |
46 return 0; | |
47 } | |
48 | |
49 u_long aim_chat_send_im(struct aim_session_t *sess, | |
50 struct aim_conn_t *conn, | |
51 char *msg) | |
52 { | |
53 | |
54 int curbyte,i; | |
55 struct command_tx_struct *newpacket; | |
56 | |
57 if (!sess || !conn || !msg) | |
58 return 0; | |
59 | |
60 if (!(newpacket = aim_tx_new(0x0002, conn, 1152))) | |
61 return -1; | |
62 | |
63 newpacket->lock = 1; /* lock struct */ | |
64 | |
65 curbyte = 0; | |
66 curbyte += aim_putsnac(newpacket->data+curbyte, | |
67 0x000e, 0x0005, 0x0000, sess->snac_nextid); | |
68 | |
69 /* | |
70 * Generate a random message cookie | |
71 */ | |
72 for (i=0;i<8;i++) | |
73 curbyte += aimutil_put8(newpacket->data+curbyte, (u_char) random()); | |
74 | |
75 /* | |
76 * metaTLV start. -- i assume this is a metaTLV. it could be the | |
77 * channel ID though. | |
78 */ | |
79 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0003); | |
80 | |
81 /* | |
82 * Type 1: Unknown. Blank. | |
83 */ | |
84 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
85 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
86 | |
87 /* | |
88 * Type 6: Unknown. Blank. | |
89 */ | |
90 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0006); | |
91 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
92 | |
93 /* | |
94 * Type 5: Message block. Contains more TLVs. | |
95 * | |
96 * This could include other information... We just | |
97 * put in a message TLV however. | |
98 * | |
99 */ | |
100 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
101 curbyte += aimutil_put16(newpacket->data+curbyte, strlen(msg)+4); | |
102 | |
103 /* | |
104 * SubTLV: Type 1: Message | |
105 */ | |
106 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x0001, strlen(msg), msg); | |
107 | |
108 newpacket->commandlen = curbyte; | |
109 | |
110 newpacket->lock = 0; | |
111 aim_tx_enqueue(sess, newpacket); | |
112 | |
113 return (sess->snac_nextid++); | |
114 } | |
2 | 115 |
116 /* | |
237 | 117 * Join a room of name roomname. This is the first |
118 * step to joining an already created room. It's | |
119 * basically a Service Request for family 0x000e, | |
120 * with a little added on to specify the exchange | |
121 * and room name. | |
2 | 122 * |
123 */ | |
237 | 124 u_long aim_chat_join(struct aim_session_t *sess, |
125 struct aim_conn_t *conn, | |
126 u_short exchange, | |
127 const char *roomname) | |
2 | 128 { |
237 | 129 struct command_tx_struct *newpacket; |
130 int i; | |
131 | |
132 if (!sess || !conn || !roomname) | |
133 return 0; | |
2 | 134 |
237 | 135 if (!(newpacket = aim_tx_new(0x0002, conn, 10+9+strlen(roomname)+2))) |
136 return -1; | |
2 | 137 |
237 | 138 newpacket->lock = 1; |
139 | |
140 i = aim_putsnac(newpacket->data, 0x0001, 0x0004, 0x0000, sess->snac_nextid); | |
2 | 141 |
237 | 142 i+= aimutil_put16(newpacket->data+i, 0x000e); |
2 | 143 |
237 | 144 /* |
145 * this is techinally a TLV, but we can't use normal functions | |
146 * because we need the extraneous nulls and other weird things. | |
147 */ | |
148 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
149 i+= aimutil_put16(newpacket->data+i, 2+1+strlen(roomname)+2); | |
150 i+= aimutil_put16(newpacket->data+i, exchange); | |
151 i+= aimutil_put8(newpacket->data+i, strlen(roomname)); | |
152 memcpy(newpacket->data+i, roomname, strlen(roomname)); | |
153 i+= strlen(roomname); | |
154 //i+= aimutil_putstr(newpacket->data+i, roomname, strlen(roomname)); | |
155 i+= aimutil_put16(newpacket->data+i, 0x0000); | |
2 | 156 |
237 | 157 /* |
158 * Chat hack. | |
159 * | |
160 * XXX: A problem occurs here if we request a channel | |
161 * join but it fails....pendingjoin will be nonnull | |
162 * even though the channel is never going to get a | |
163 * redirect! | |
164 * | |
165 */ | |
166 sess->pendingjoin = (char *)malloc(strlen(roomname)+1); | |
167 strcpy(sess->pendingjoin, roomname); | |
2 | 168 |
237 | 169 newpacket->lock = 0; |
170 aim_tx_enqueue(sess, newpacket); | |
2 | 171 |
237 | 172 #if 0 |
2 | 173 { |
174 struct aim_snac_t snac; | |
175 | |
237 | 176 snac.id = sess->snac_nextid; |
2 | 177 snac.family = 0x0001; |
178 snac.type = 0x0004; | |
179 snac.flags = 0x0000; | |
180 | |
237 | 181 snac.data = malloc(strlen(roomname)+1); |
182 strcpy(snac.data, roomname); | |
2 | 183 |
237 | 184 aim_newsnac(sess, &snac); |
2 | 185 } |
186 | |
237 | 187 #endif |
188 return (sess->snac_nextid++); | |
189 } | |
190 | |
191 int aim_chat_readroominfo(u_char *buf, struct aim_chat_roominfo *outinfo) | |
192 { | |
193 int namelen = 0; | |
194 int i = 0; | |
195 | |
196 if (!buf || !outinfo) | |
197 return 0; | |
198 | |
199 outinfo->exchange = aimutil_get16(buf+i); | |
200 i += 2; | |
201 | |
202 namelen = aimutil_get8(buf+i); | |
203 i += 1; | |
204 | |
205 outinfo->name = (char *)malloc(namelen+1); | |
206 memcpy(outinfo->name, buf+i, namelen); | |
207 outinfo->name[namelen] = '\0'; | |
208 i += namelen; | |
209 | |
210 outinfo->instance = aimutil_get16(buf+i); | |
211 i += 2; | |
212 | |
213 return i; | |
214 }; | |
215 | |
216 | |
217 /* | |
218 * General room information. Lots of stuff. | |
219 * | |
220 * Values I know are in here but I havent attached | |
221 * them to any of the 'Unknown's: | |
222 * - Language (English) | |
223 * | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
224 * SNAC 000e/0002 |
237 | 225 */ |
226 int aim_chat_parse_infoupdate(struct aim_session_t *sess, | |
227 struct command_rx_struct *command) | |
228 { | |
229 struct aim_userinfo_s *userinfo = NULL; | |
230 rxcallback_t userfunc=NULL; | |
231 int ret = 1, i = 0; | |
232 int usercount = 0; | |
233 u_char detaillevel = 0; | |
234 char *roomname = NULL; | |
235 struct aim_chat_roominfo roominfo; | |
236 u_short tlvcount = 0; | |
237 struct aim_tlvlist_t *tlvlist; | |
238 char *roomdesc = NULL; | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
239 struct aim_tlv_t *tmptlv; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
240 unsigned short unknown_c9 = 0; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
241 unsigned long creationtime = 0; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
242 unsigned short maxmsglen = 0; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
243 unsigned short unknown_d2 = 0, unknown_d5 = 0; |
237 | 244 |
245 i = 10; | |
246 i += aim_chat_readroominfo(command->data+i, &roominfo); | |
247 | |
248 detaillevel = aimutil_get8(command->data+i); | |
249 i++; | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
250 |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
251 if (detaillevel != 0x02) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
252 if (detaillevel == 0x01) |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
253 printf("faim: chat_roomupdateinfo: detail level 2 not supported\n"); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
254 else |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
255 printf("faim: chat_roomupdateinfo: unknown detail level %d\n", detaillevel); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
256 return 1; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
257 } |
237 | 258 |
259 tlvcount = aimutil_get16(command->data+i); | |
260 i += 2; | |
261 | |
262 /* | |
263 * Everything else are TLVs. | |
264 */ | |
265 tlvlist = aim_readtlvchain(command->data+i, command->commandlen-i); | |
266 | |
267 /* | |
268 * TLV type 0x006a is the room name in Human Readable Form. | |
269 */ | |
270 if (aim_gettlv(tlvlist, 0x006a, 1)) | |
271 roomname = aim_gettlv_str(tlvlist, 0x006a, 1); | |
272 | |
273 /* | |
274 * Type 0x006f: Number of occupants. | |
275 */ | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
276 if (aim_gettlv(tlvlist, 0x006f, 1)) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
277 struct aim_tlv_t *tmptlv; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
278 tmptlv = aim_gettlv(tlvlist, 0x006f, 1); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
279 |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
280 usercount = aimutil_get16(tmptlv->value); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
281 } |
237 | 282 |
283 /* | |
284 * Type 0x0073: Occupant list. | |
285 */ | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
286 if (aim_gettlv(tlvlist, 0x0073, 1)) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
287 int curoccupant = 0; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
288 struct aim_tlv_t *tmptlv; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
289 |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
290 tmptlv = aim_gettlv(tlvlist, 0x0073, 1); |
237 | 291 |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
292 /* Allocate enough userinfo structs for all occupants */ |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
293 userinfo = calloc(usercount, sizeof(struct aim_userinfo_s)); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
294 |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
295 i = 0; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
296 while (curoccupant < usercount) |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
297 i += aim_extractuserinfo(tmptlv->value+i, &userinfo[curoccupant++]); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
298 } |
237 | 299 |
300 /* | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
301 * Type 0x00c9: Unknown. (2 bytes) |
237 | 302 */ |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
303 if ((tmptlv = aim_gettlv(tlvlist, 0x00c9, 1))) |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
304 unknown_c9 = aimutil_get16(tmptlv->value); |
237 | 305 |
306 /* | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
307 * Type 0x00ca: Creation time (4 bytes) |
237 | 308 */ |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
309 if ((tmptlv = aim_gettlv(tlvlist, 0x00ca, 1))) |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
310 creationtime = aimutil_get32(tmptlv->value); |
237 | 311 |
312 /* | |
313 * Type 0x00d1: Maximum Message Length | |
314 */ | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
315 if ((tmptlv = aim_gettlv(tlvlist, 0x00d1, 1))) |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
316 maxmsglen = aimutil_get16(tmptlv->value); |
237 | 317 |
318 /* | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
319 * Type 0x00d2: Unknown. (2 bytes) |
237 | 320 */ |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
321 if ((tmptlv = aim_gettlv(tlvlist, 0x00d2, 1))) |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
322 unknown_d2 = aimutil_get16(tmptlv->value);; |
237 | 323 |
324 /* | |
325 * Type 0x00d3: Room Description | |
326 */ | |
327 if (aim_gettlv(tlvlist, 0x00d3, 1)) | |
328 roomdesc = aim_gettlv_str(tlvlist, 0x00d3, 1); | |
329 | |
330 /* | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
331 * Type 0x00d5: Unknown. (1 byte) |
237 | 332 */ |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
333 if ((tmptlv = aim_gettlv(tlvlist, 0x00d5, 1))) |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
334 unknown_d5 = aimutil_get8(tmptlv->value);; |
237 | 335 |
336 | |
337 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE); | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
338 if (userfunc) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
339 ret = userfunc(sess, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
340 command, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
341 &roominfo, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
342 roomname, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
343 usercount, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
344 userinfo, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
345 roomdesc, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
346 unknown_c9, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
347 creationtime, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
348 maxmsglen, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
349 unknown_d2, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
350 unknown_d5); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
351 } |
237 | 352 free(roominfo.name); |
353 free(userinfo); | |
354 free(roomname); | |
355 free(roomdesc); | |
356 aim_freetlvchain(&tlvlist); | |
357 | |
358 return ret; | |
2 | 359 } |
237 | 360 |
361 int aim_chat_parse_joined(struct aim_session_t *sess, | |
362 struct command_rx_struct *command) | |
363 { | |
364 struct aim_userinfo_s *userinfo = NULL; | |
365 rxcallback_t userfunc=NULL; | |
366 int i = 10, curcount = 0, ret = 1; | |
367 | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
368 while (i < command->commandlen) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
369 curcount++; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
370 userinfo = realloc(userinfo, curcount * sizeof(struct aim_userinfo_s)); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
371 i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
372 } |
237 | 373 |
374 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN); | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
375 if (userfunc) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
376 ret = userfunc(sess, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
377 command, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
378 curcount, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
379 userinfo); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
380 } |
237 | 381 |
382 free(userinfo); | |
383 | |
384 return ret; | |
385 } | |
386 | |
387 int aim_chat_parse_leave(struct aim_session_t *sess, | |
388 struct command_rx_struct *command) | |
389 { | |
390 | |
391 struct aim_userinfo_s *userinfo = NULL; | |
392 rxcallback_t userfunc=NULL; | |
393 int i = 10, curcount = 0, ret = 1; | |
394 | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
395 while (i < command->commandlen) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
396 curcount++; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
397 userinfo = realloc(userinfo, curcount * sizeof(struct aim_userinfo_s)); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
398 i += aim_extractuserinfo(command->data+i, &userinfo[curcount-1]); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
399 } |
237 | 400 |
401 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE); | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
402 if (userfunc) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
403 ret = userfunc(sess, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
404 command, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
405 curcount, |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
406 userinfo); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
407 } |
237 | 408 |
409 free(userinfo); | |
410 | |
411 return ret; | |
412 } | |
413 | |
414 /* | |
415 * We could probably include this in the normal ICBM parsing | |
416 * code as channel 0x0003, however, since only the start | |
417 * would be the same, we might as well do it here. | |
418 */ | |
419 int aim_chat_parse_incoming(struct aim_session_t *sess, | |
420 struct command_rx_struct *command) | |
421 { | |
422 struct aim_userinfo_s userinfo; | |
423 rxcallback_t userfunc=NULL; | |
424 int ret = 1, i = 0, z = 0; | |
425 u_char cookie[8]; | |
426 int channel; | |
427 struct aim_tlvlist_t *outerlist; | |
428 char *msg = NULL; | |
429 | |
430 memset(&userinfo, 0x00, sizeof(struct aim_userinfo_s)); | |
431 | |
432 i = 10; /* skip snac */ | |
433 | |
434 /* | |
435 * ICBM Cookie. Ignore it. | |
436 */ | |
437 for (z=0; z<8; z++,i++) | |
438 cookie[z] = command->data[i]; | |
439 | |
440 /* | |
441 * Channel ID | |
442 * | |
443 * Channels 1 and 2 are implemented in the normal ICBM | |
444 * parser. | |
445 * | |
446 * We only do channel 3 here. | |
447 * | |
448 */ | |
449 channel = aimutil_get16(command->data+i); | |
450 i += 2; | |
451 | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
452 if (channel != 0x0003) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
453 printf("faim: chat_incoming: unknown channel! (0x%04x)\n", channel); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
454 return 1; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
455 } |
237 | 456 |
457 /* | |
458 * Start parsing TLVs right away. | |
459 */ | |
460 outerlist = aim_readtlvchain(command->data+i, command->commandlen-i); | |
461 | |
462 /* | |
463 * Type 0x0003: Source User Information | |
464 */ | |
316
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
465 if (aim_gettlv(outerlist, 0x0003, 1)) { |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
466 struct aim_tlv_t *userinfotlv; |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
467 |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
468 userinfotlv = aim_gettlv(outerlist, 0x0003, 1); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
469 aim_extractuserinfo(userinfotlv->value, &userinfo); |
8cdc4ab449ec
[gaim-migrate @ 326]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
283
diff
changeset
|
470 } |
237 | 471 |
472 /* | |
473 * Type 0x0001: Unknown. | |
474 */ | |
475 if (aim_gettlv(outerlist, 0x0001, 1)) | |
476 ; | |
477 | |
478 /* | |
479 * Type 0x0005: Message Block. Conains more TLVs. | |
480 */ | |
481 if (aim_gettlv(outerlist, 0x0005, 1)) | |
482 { | |
483 struct aim_tlvlist_t *innerlist; | |
484 struct aim_tlv_t *msgblock; | |
485 | |
486 msgblock = aim_gettlv(outerlist, 0x0005, 1); | |
487 innerlist = aim_readtlvchain(msgblock->value, msgblock->length); | |
488 | |
489 /* | |
490 * Type 0x0001: Message. | |
491 */ | |
492 if (aim_gettlv(innerlist, 0x0001, 1)) | |
493 msg = aim_gettlv_str(innerlist, 0x0001, 1); | |
494 | |
495 aim_freetlvchain(&innerlist); | |
496 } | |
497 | |
498 userfunc = aim_callhandler(command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG); | |
499 if (userfunc) | |
500 { | |
501 ret = userfunc(sess, | |
502 command, | |
503 &userinfo, | |
504 msg); | |
505 } | |
506 free(msg); | |
507 aim_freetlvchain(&outerlist); | |
508 | |
509 return ret; | |
510 } | |
511 | |
512 u_long aim_chat_clientready(struct aim_session_t *sess, | |
513 struct aim_conn_t *conn) | |
514 { | |
515 struct command_tx_struct *newpacket; | |
516 int i; | |
517 | |
518 if (!(newpacket = aim_tx_new(0x0002, conn, 0x20))) | |
519 return -1; | |
520 | |
521 newpacket->lock = 1; | |
522 | |
523 i = aim_putsnac(newpacket->data, 0x0001, 0x0002, 0x0000, sess->snac_nextid); | |
524 | |
525 i+= aimutil_put16(newpacket->data+i, 0x000e); | |
526 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
527 | |
528 i+= aimutil_put16(newpacket->data+i, 0x0004); | |
529 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
530 | |
531 i+= aimutil_put16(newpacket->data+i, 0x0001); | |
532 i+= aimutil_put16(newpacket->data+i, 0x0003); | |
533 | |
534 i+= aimutil_put16(newpacket->data+i, 0x0004); | |
535 i+= aimutil_put16(newpacket->data+i, 0x0686); | |
536 | |
537 newpacket->lock = 0; | |
538 aim_tx_enqueue(sess, newpacket); | |
539 | |
540 return (sess->snac_nextid++); | |
541 } | |
542 | |
543 int aim_chat_leaveroom(struct aim_session_t *sess, char *name) | |
544 { | |
545 int i; | |
546 | |
547 for (i=0;i<AIM_CONN_MAX;i++) | |
548 { | |
549 if (sess->conns[i].type == AIM_CONN_TYPE_CHAT) | |
550 { | |
551 if (sess->conns[i].priv) | |
552 if (!strcmp((char *)sess->conns[i].priv, name)) | |
553 { | |
554 aim_conn_close(&sess->conns[i]); | |
555 return 0; | |
556 } | |
557 } | |
558 } | |
559 return -1; | |
560 } | |
561 | |
562 /* | |
563 * conn must be a BOS connection! | |
564 */ | |
565 u_long aim_chat_invite(struct aim_session_t *sess, | |
566 struct aim_conn_t *conn, | |
567 char *sn, | |
568 char *msg, | |
569 u_short exchange, | |
570 char *roomname, | |
571 u_short instance) | |
572 { | |
573 struct command_tx_struct *newpacket; | |
574 int i,curbyte=0; | |
575 | |
576 if (!sess || !conn || !sn || !msg || !roomname) | |
577 return 0; | |
578 | |
579 if (!(newpacket = aim_tx_new(0x0002, conn, 1152+strlen(sn)+strlen(roomname)+strlen(msg)))) | |
580 return -1; | |
581 | |
582 newpacket->lock = 1; | |
583 | |
584 curbyte = aim_putsnac(newpacket->data, 0x0004, 0x0006, 0x0000, sess->snac_nextid); | |
585 | |
586 /* | |
587 * Cookie | |
588 */ | |
589 for (i=0;i<8;i++) | |
590 curbyte += aimutil_put8(newpacket->data+curbyte, (u_char)rand()); | |
591 | |
592 /* | |
593 * Channel (2) | |
594 */ | |
595 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
596 | |
597 /* | |
598 * Dest sn | |
599 */ | |
600 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(sn)); | |
601 curbyte += aimutil_putstr(newpacket->data+curbyte, sn, strlen(sn)); | |
602 | |
603 /* | |
604 * TLV t(0005) | |
605 */ | |
606 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0005); | |
607 curbyte += aimutil_put16(newpacket->data+curbyte, 0x28+strlen(msg)+0x04+0x03+strlen(roomname)+0x02); | |
608 | |
609 /* | |
610 * Unknown info | |
611 */ | |
612 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
613 curbyte += aimutil_put16(newpacket->data+curbyte, 0x3131); | |
614 curbyte += aimutil_put16(newpacket->data+curbyte, 0x3538); | |
615 curbyte += aimutil_put16(newpacket->data+curbyte, 0x3446); | |
616 curbyte += aimutil_put16(newpacket->data+curbyte, 0x4100); | |
617 curbyte += aimutil_put16(newpacket->data+curbyte, 0x748f); | |
618 curbyte += aimutil_put16(newpacket->data+curbyte, 0x2420); | |
619 curbyte += aimutil_put16(newpacket->data+curbyte, 0x6287); | |
620 curbyte += aimutil_put16(newpacket->data+curbyte, 0x11d1); | |
621 curbyte += aimutil_put16(newpacket->data+curbyte, 0x8222); | |
622 curbyte += aimutil_put16(newpacket->data+curbyte, 0x4445); | |
623 curbyte += aimutil_put16(newpacket->data+curbyte, 0x5354); | |
624 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
625 | |
626 /* | |
627 * TLV t(000a) -- Unknown | |
628 */ | |
629 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000a); | |
630 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0002); | |
631 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0001); | |
632 | |
633 /* | |
634 * TLV t(000f) -- Unknown | |
635 */ | |
636 curbyte += aimutil_put16(newpacket->data+curbyte, 0x000f); | |
637 curbyte += aimutil_put16(newpacket->data+curbyte, 0x0000); | |
638 | |
639 /* | |
640 * TLV t(000c) -- Invitation message | |
641 */ | |
642 curbyte += aim_puttlv_str(newpacket->data+curbyte, 0x000c, strlen(msg), msg); | |
643 | |
644 /* | |
645 * TLV t(2711) -- Container for room information | |
646 */ | |
647 curbyte += aimutil_put16(newpacket->data+curbyte, 0x2711); | |
648 curbyte += aimutil_put16(newpacket->data+curbyte, 3+strlen(roomname)+2); | |
649 curbyte += aimutil_put16(newpacket->data+curbyte, exchange); | |
650 curbyte += aimutil_put8(newpacket->data+curbyte, strlen(roomname)); | |
651 curbyte += aimutil_putstr(newpacket->data+curbyte, roomname, strlen(roomname)); | |
652 curbyte += aimutil_put16(newpacket->data+curbyte, instance); | |
653 | |
654 newpacket->commandlen = curbyte; | |
655 newpacket->lock = 0; | |
656 aim_tx_enqueue(sess, newpacket); | |
657 | |
658 return (sess->snac_nextid++); | |
659 } |