Mercurial > pidgin.yaz
annotate libfaim/aim_rxhandlers.c @ 269:46b6b894bc48
[gaim-migrate @ 279]
File transfer and proxies and libfaim and other updates.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 26 May 2000 00:59:58 +0000 |
parents | 1eeece1c7b7b |
children | 501e09c51cbc |
rev | line source |
---|---|
237 | 1 /* |
2 * aim_rxhandlers.c | |
3 * | |
4 * This file contains most all of the incoming packet handlers, along | |
5 * with aim_rxdispatch(), the Rx dispatcher. Queue/list management is | |
6 * actually done in aim_rxqueue.c. | |
7 * | |
258
1eeece1c7b7b
[gaim-migrate @ 268]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
8 * Changes by Eric Warmenhoven, Wed May 24 09:33:38 UTC 2000: |
1eeece1c7b7b
[gaim-migrate @ 268]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
9 * - there were some "bleck" printf's i changed to faimdprintf's. |
1eeece1c7b7b
[gaim-migrate @ 268]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
10 * |
237 | 11 */ |
12 | |
13 #include <aim.h> | |
2 | 14 |
15 /* | |
237 | 16 * Bleck functions get called when there's no non-bleck functions |
17 * around to cleanup the mess... | |
2 | 18 */ |
237 | 19 int bleck(struct aim_session_t *sess,struct command_rx_struct *workingPtr, ...) |
20 { | |
21 u_short family; | |
22 u_short subtype; | |
2 | 23 |
237 | 24 u_short maxf; |
25 u_short maxs; | |
2 | 26 |
237 | 27 /* XXX: this is ugly. and big just for debugging. */ |
28 char *literals[14][25] = { | |
29 {"Invalid", | |
30 NULL | |
31 }, | |
32 {"General", | |
33 "Invalid", | |
34 "Error", | |
35 "Client Ready", | |
36 "Server Ready", | |
37 "Service Request", | |
38 "Redirect", | |
39 "Rate Information Request", | |
40 "Rate Information", | |
41 "Rate Information Ack", | |
42 NULL, | |
43 "Rate Information Change", | |
44 "Server Pause", | |
45 NULL, | |
46 "Server Resume", | |
47 "Request Personal User Information", | |
48 "Personal User Information", | |
49 "Evil Notification", | |
50 NULL, | |
51 "Migration notice", | |
52 "Message of the Day", | |
53 "Set Privacy Flags", | |
54 "Well Known URL", | |
55 "NOP" | |
56 }, | |
57 {"Location", | |
58 "Invalid", | |
59 "Error", | |
60 "Request Rights", | |
61 "Rights Information", | |
62 "Set user information", | |
63 "Request User Information", | |
64 "User Information", | |
65 "Watcher Sub Request", | |
66 "Watcher Notification" | |
67 }, | |
68 {"Buddy List Management", | |
69 "Invalid", | |
70 "Error", | |
71 "Request Rights", | |
72 "Rights Information", | |
73 "Add Buddy", | |
74 "Remove Buddy", | |
75 "Watcher List Query", | |
76 "Watcher List Response", | |
77 "Watcher SubRequest", | |
78 "Watcher Notification", | |
79 "Reject Notification", | |
80 "Oncoming Buddy", | |
81 "Offgoing Buddy" | |
82 }, | |
83 {"Messeging", | |
84 "Invalid", | |
85 "Error", | |
86 "Add ICBM Parameter", | |
87 "Remove ICBM Parameter", | |
88 "Request Parameter Information", | |
89 "Parameter Information", | |
90 "Outgoing Message", | |
91 "Incoming Message", | |
92 "Evil Request", | |
93 "Evil Reply", | |
94 "Missed Calls", | |
95 "Message Error", | |
96 "Host Ack" | |
97 }, | |
98 {"Advertisements", | |
99 "Invalid", | |
100 "Error", | |
101 "Request Ad", | |
102 "Ad Data (GIFs)" | |
103 }, | |
104 {"Invitation / Client-to-Client", | |
105 "Invalid", | |
106 "Error", | |
107 "Invite a Friend", | |
108 "Invitation Ack" | |
109 }, | |
110 {"Administrative", | |
111 "Invalid", | |
112 "Error", | |
113 "Information Request", | |
114 "Information Reply", | |
115 "Information Change Request", | |
116 "Information Chat Reply", | |
117 "Account Confirm Request", | |
118 "Account Confirm Reply", | |
119 "Account Delete Request", | |
120 "Account Delete Reply" | |
121 }, | |
122 {"Popups", | |
123 "Invalid", | |
124 "Error", | |
125 "Display Popup" | |
126 }, | |
127 {"BOS", | |
128 "Invalid", | |
129 "Error", | |
130 "Request Rights", | |
131 "Rights Response", | |
132 "Set group permission mask", | |
133 "Add permission list entries", | |
134 "Delete permission list entries", | |
135 "Add deny list entries", | |
136 "Delete deny list entries", | |
137 "Server Error" | |
138 }, | |
139 {"User Lookup", | |
140 "Invalid", | |
141 "Error", | |
142 "Search Request", | |
143 "Search Response" | |
144 }, | |
145 {"Stats", | |
146 "Invalid", | |
147 "Error", | |
148 "Set minimum report interval", | |
149 "Report Events" | |
150 }, | |
151 {"Translate", | |
152 "Invalid", | |
153 "Error", | |
154 "Translate Request", | |
155 "Translate Reply", | |
156 }, | |
157 {"Chat Navigation", | |
158 "Invalid", | |
159 "Error", | |
160 "Request rights", | |
161 "Request Exchange Information", | |
162 "Request Room Information", | |
163 "Request Occupant List", | |
164 "Search for Room", | |
165 "Outgoing Message", | |
166 "Incoming Message", | |
167 "Evil Request", | |
168 "Evil Reply", | |
169 "Chat Error", | |
170 } | |
171 }; | |
2 | 172 |
237 | 173 maxf = sizeof(literals) / sizeof(literals[0]); |
174 maxs = sizeof(literals[0]) / sizeof(literals[0][0]); | |
175 | |
176 family = aimutil_get16(workingPtr->data+0); | |
177 subtype= aimutil_get16(workingPtr->data+2); | |
178 | |
179 if((family < maxf) && (subtype+1 < maxs) && (literals[family][subtype] != NULL)) | |
258
1eeece1c7b7b
[gaim-migrate @ 268]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
180 faimdprintf(1, "bleck: null handler for %04x/%04x (%s)\n", family, subtype, literals[family][subtype+1]); |
237 | 181 else |
258
1eeece1c7b7b
[gaim-migrate @ 268]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
237
diff
changeset
|
182 faimdprintf(1, "bleck: null handler for %04x/%04x (no literal)\n",family,subtype); |
237 | 183 |
2 | 184 return 1; |
185 } | |
186 | |
237 | 187 int aim_conn_addhandler(struct aim_session_t *sess, |
188 struct aim_conn_t *conn, | |
189 u_short family, | |
190 u_short type, | |
191 rxcallback_t newhandler, | |
192 u_short flags) | |
193 { | |
194 struct aim_rxcblist_t *new,*cur; | |
195 | |
196 if (!conn) | |
197 return -1; | |
198 | |
199 faimdprintf(1, "aim_conn_addhandler: adding for %04x/%04x\n", family, type); | |
200 | |
201 new = (struct aim_rxcblist_t *)calloc(1, sizeof(struct aim_rxcblist_t)); | |
202 new->family = family; | |
203 new->type = type; | |
204 new->flags = flags; | |
205 if (!newhandler) | |
206 new->handler = &bleck; | |
207 else | |
208 new->handler = newhandler; | |
209 new->next = NULL; | |
210 | |
211 cur = conn->handlerlist; | |
212 if (!cur) | |
213 conn->handlerlist = new; | |
214 else | |
215 { | |
216 while (cur->next) | |
217 cur = cur->next; | |
218 cur->next = new; | |
219 } | |
220 | |
221 return 0; | |
222 } | |
223 | |
224 int aim_clearhandlers(struct aim_conn_t *conn) | |
225 { | |
226 struct aim_rxcblist_t *cur,*tmp; | |
227 if (!conn) | |
228 return -1; | |
2 | 229 |
237 | 230 cur = conn->handlerlist; |
231 while(cur) | |
232 { | |
233 tmp = cur->next; | |
234 free(cur); | |
235 cur = tmp; | |
236 } | |
237 return 0; | |
238 } | |
2 | 239 |
237 | 240 rxcallback_t aim_callhandler(struct aim_conn_t *conn, |
241 u_short family, | |
242 u_short type) | |
2 | 243 { |
237 | 244 struct aim_rxcblist_t *cur; |
245 | |
246 if (!conn) | |
247 return NULL; | |
248 | |
249 faimdprintf(1, "aim_callhandler: calling for %04x/%04x\n", family, type); | |
2 | 250 |
237 | 251 cur = conn->handlerlist; |
252 while(cur) | |
2 | 253 { |
237 | 254 if ( (cur->family == family) && (cur->type == type) ) |
255 return cur->handler; | |
256 cur = cur->next; | |
2 | 257 } |
237 | 258 |
259 if (type==0xffff) | |
260 return NULL; | |
261 return aim_callhandler(conn, family, 0xffff); | |
262 } | |
263 | |
264 int aim_callhandler_noparam(struct aim_session_t *sess, | |
265 struct aim_conn_t *conn, | |
266 u_short family, | |
267 u_short type, | |
268 struct command_rx_struct *ptr) | |
269 { | |
270 rxcallback_t userfunc = NULL; | |
271 userfunc = aim_callhandler(conn, family, type); | |
272 if (userfunc) | |
273 return userfunc(sess, ptr); | |
274 return 1; /* XXX */ | |
2 | 275 } |
276 | |
277 /* | |
278 aim_rxdispatch() | |
279 | |
280 Basically, heres what this should do: | |
281 1) Determine correct packet handler for this packet | |
282 2) Mark the packet handled (so it can be dequeued in purge_queue()) | |
283 3) Send the packet to the packet handler | |
284 4) Go to next packet in the queue and start over | |
285 5) When done, run purge_queue() to purge handled commands | |
286 | |
287 Note that any unhandlable packets should probably be left in the | |
288 queue. This is the best way to prevent data loss. This means | |
289 that a single packet may get looked at by this function multiple | |
290 times. This is more good than bad! This behavior may change. | |
291 | |
292 Aren't queue's fun? | |
293 | |
294 TODO: Get rid of all the ugly if's. | |
295 TODO: Clean up. | |
296 TODO: More support for mid-level handlers. | |
297 TODO: Allow for NULL handlers. | |
298 | |
299 */ | |
237 | 300 int aim_rxdispatch(struct aim_session_t *sess) |
2 | 301 { |
302 int i = 0; | |
303 struct command_rx_struct *workingPtr = NULL; | |
304 | |
237 | 305 if (sess->queue_incoming == NULL) { |
306 faimdprintf(1, "parse_generic: incoming packet queue empty.\n"); | |
307 return 0; | |
308 } else { | |
309 workingPtr = sess->queue_incoming; | |
310 for (i = 0; workingPtr != NULL; workingPtr = workingPtr->next, i++) { | |
311 /* | |
312 * XXX: This is still fairly ugly. | |
313 */ | |
314 if (workingPtr->handled) | |
315 continue; | |
316 | |
317 switch(workingPtr->conn->type) { | |
318 case -1: | |
319 /* | |
320 * This can happen if we have a queued command | |
321 * that was recieved after a connection has | |
322 * been terminated. In which case, the handler | |
323 * list has been cleared, and there's nothing we | |
324 * can do for it. We can only cancel it. | |
325 */ | |
326 workingPtr->handled = 1; | |
327 break; | |
328 case AIM_CONN_TYPE_AUTH: { | |
329 u_long head; | |
330 | |
331 head = aimutil_get32(workingPtr->data); | |
332 if (head == 0x00000001) { | |
333 faimdprintf(1, "got connection ack on auth line\n"); | |
334 workingPtr->handled = 1; | |
335 } else { | |
336 u_short family,subtype; | |
337 | |
338 family = aimutil_get16(workingPtr->data); | |
339 subtype = aimutil_get16(workingPtr->data+2); | |
340 | |
341 switch (family) { | |
342 /* New login protocol */ | |
343 #ifdef SNACLOGIN | |
344 case 0x0017: | |
345 if (subtype == 0x0001) | |
346 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0017, 0x0001, workingPtr); | |
347 else if (subtype == 0x0003) | |
348 workingPtr->handled = aim_authparse(sess, workingPtr); | |
349 else if (subtype == 0x0007) | |
350 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0017, 0x0007, workingPtr); | |
351 else | |
352 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0017, 0xffff, workingPtr); | |
353 break; | |
354 #else | |
355 /* XXX: this isnt foolproof */ | |
356 case 0x0001: | |
357 if (subtype == 0x0003) | |
358 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, workingPtr); | |
359 else | |
360 workingPtr->handled = aim_authparse(sess, workingPtr); | |
361 break; | |
362 case 0x0007: | |
363 if (subtype == 0x0005) | |
364 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_ADM, AIM_CB_ADM_INFOCHANGE_REPLY, workingPtr); | |
365 break; | |
366 default: | |
367 /* Old login protocol */ | |
368 /* any user callbacks will be called from here */ | |
369 workingPtr->handled = aim_authparse(sess, workingPtr); | |
2 | 370 #endif |
237 | 371 } |
2 | 372 } |
237 | 373 break; |
374 } | |
375 case AIM_CONN_TYPE_BOS: { | |
376 u_short family; | |
377 u_short subtype; | |
378 | |
379 family = aimutil_get16(workingPtr->data); | |
380 subtype = aimutil_get16(workingPtr->data+2); | |
381 | |
382 switch (family) { | |
383 case 0x0000: /* not really a family, but it works */ | |
384 if (subtype == 0x0001) | |
385 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0000, 0x0001, workingPtr); | |
386 else | |
387 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_UNKNOWN, workingPtr); | |
388 break; | |
389 case 0x0001: /* Family: General */ | |
390 switch (subtype) { | |
391 case 0x0001: | |
392 workingPtr->handled = aim_parse_generalerrs(sess, workingPtr); | |
393 break; | |
394 case 0x0003: | |
395 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x0003, workingPtr); | |
396 break; | |
397 case 0x0005: | |
398 workingPtr->handled = aim_handleredirect_middle(sess, workingPtr); | |
399 break; | |
400 case 0x0007: | |
401 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x0007, workingPtr); | |
402 break; | |
403 case 0x000a: | |
404 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x000a, workingPtr); | |
405 break; | |
406 case 0x000f: | |
407 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x000f, workingPtr); | |
408 break; | |
409 case 0x0013: | |
410 workingPtr->handled = aim_parsemotd_middle(sess, workingPtr); | |
411 break; | |
412 default: | |
413 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_GEN, AIM_CB_GEN_DEFAULT, workingPtr); | |
414 break; | |
415 } | |
416 case 0x0002: /* Family: Location */ | |
417 switch (subtype) { | |
418 case 0x0001: | |
419 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0002, 0x0001, workingPtr); | |
420 break; | |
421 case 0x0003: | |
422 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0002, 0x0003, workingPtr); | |
423 break; | |
424 case 0x0006: | |
425 workingPtr->handled = aim_parse_userinfo_middle(sess, workingPtr); | |
426 break; | |
427 default: | |
428 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_LOC, AIM_CB_LOC_DEFAULT, workingPtr); | |
429 break; | |
430 } | |
431 case 0x0003: /* Family: Buddy List */ | |
432 switch (subtype) { | |
433 case 0x0001: | |
434 workingPtr->handled = aim_parse_generalerrs(sess, workingPtr); | |
435 break; | |
436 case 0x0003: | |
437 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0003, 0x0003, workingPtr); | |
438 break; | |
439 case 0x000b: /* oncoming buddy */ | |
440 workingPtr->handled = aim_parse_oncoming_middle(sess, workingPtr); | |
441 break; | |
442 case 0x000c: /* offgoing buddy */ | |
443 workingPtr->handled = aim_parse_offgoing_middle(sess, workingPtr); | |
444 break; | |
445 default: | |
446 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_BUD, AIM_CB_BUD_DEFAULT, workingPtr); | |
447 } | |
448 break; | |
449 case 0x0004: /* Family: Messeging */ | |
450 switch (subtype) { | |
451 case 0x0001: | |
452 workingPtr->handled = aim_parse_msgerror_middle(sess, workingPtr); | |
453 break; | |
454 case 0x0005: | |
455 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0004, 0x0005, workingPtr); | |
456 break; | |
457 case 0x0007: | |
458 workingPtr->handled = aim_parse_incoming_im_middle(sess, workingPtr); | |
459 break; | |
460 case 0x000a: | |
461 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0004, 0x000a, workingPtr); | |
462 break; | |
463 default: | |
464 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_MSG, AIM_CB_MSG_DEFAULT, workingPtr); | |
465 } | |
466 break; | |
467 case 0x0009: | |
468 if (subtype == 0x0001) | |
469 workingPtr->handled = aim_parse_generalerrs(sess, workingPtr); | |
470 else if (subtype == 0x0003) | |
471 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0009, 0x0003, workingPtr); | |
472 else | |
473 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_BOS, AIM_CB_BOS_DEFAULT, workingPtr); | |
474 break; | |
475 case 0x000a: /* Family: User lookup */ | |
476 switch (subtype) { | |
477 case 0x0001: | |
478 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x000a, 0x0001, workingPtr); | |
479 break; | |
480 case 0x0003: | |
481 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x000a, 0x0003, workingPtr); | |
482 break; | |
483 default: | |
484 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_LOK, AIM_CB_LOK_DEFAULT, workingPtr); | |
485 } | |
486 break; | |
487 case 0x000b: | |
488 if (subtype == 0x0001) | |
489 workingPtr->handled = aim_parse_generalerrs(sess, workingPtr); | |
490 else if (subtype == 0x0002) | |
491 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x000b, 0x0002, workingPtr); | |
492 else | |
493 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_STS, AIM_CB_STS_DEFAULT, workingPtr); | |
494 break; | |
495 default: | |
496 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_UNKNOWN, workingPtr); | |
497 break; | |
498 } | |
499 break; | |
500 } | |
501 case AIM_CONN_TYPE_CHATNAV: { | |
502 u_short family; | |
503 u_short subtype; | |
504 family = aimutil_get16(workingPtr->data); | |
505 subtype= aimutil_get16(workingPtr->data+2); | |
506 | |
507 if ((family == 0x0002) && (subtype == 0x0006)) { | |
508 workingPtr->handled = 1; | |
509 aim_conn_setstatus(workingPtr->conn, AIM_CONN_STATUS_READY); | |
510 } else if ((family == 0x000d) && (subtype == 0x0009)) { | |
511 workingPtr->handled = aim_chatnav_parse_info(sess, workingPtr); | |
512 } else { | |
513 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, family, subtype, workingPtr); | |
514 } | |
515 break; | |
516 } | |
517 case AIM_CONN_TYPE_CHAT: { | |
518 u_short family, subtype; | |
519 | |
520 family = aimutil_get16(workingPtr->data); | |
521 subtype= aimutil_get16(workingPtr->data+2); | |
522 | |
523 if ((family == 0x0000) && (subtype == 0x00001)) | |
524 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0000, 0x0001, workingPtr); | |
525 else if (family == 0x0001) { | |
526 if (subtype == 0x0001) | |
527 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x0001, workingPtr); | |
528 else if (subtype == 0x0003) | |
529 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x0003, workingPtr); | |
530 else if (subtype == 0x0007) | |
531 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, 0x0001, 0x0007, workingPtr); | |
532 else | |
533 printf("Chat: unknown snac %04x/%04x\n", family, subtype); | |
534 } else if (family == 0x000e) { | |
535 if (subtype == 0x0002) | |
536 workingPtr->handled = aim_chat_parse_infoupdate(sess, workingPtr); | |
537 else if (subtype == 0x0003) | |
538 workingPtr->handled = aim_chat_parse_joined(sess, workingPtr); | |
539 else if (subtype == 0x0004) | |
540 workingPtr->handled = aim_chat_parse_leave(sess, workingPtr); | |
541 else if (subtype == 0x0006) | |
542 workingPtr->handled = aim_chat_parse_incoming(sess, workingPtr); | |
543 else | |
544 printf("Chat: unknown snac %04x/%04x\n", family, subtype); | |
545 } else { | |
546 printf("Chat: unknown snac %04x/%04x\n", family, subtype); | |
547 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_DEFAULT, workingPtr); | |
548 } | |
549 break; | |
550 } | |
551 default: | |
552 printf("\ninternal error: unknown connection type (very bad.) (type = %d, fd = %d, channel = %02x, commandlen = %02x)\n\n", workingPtr->conn->type, workingPtr->conn->fd, workingPtr->type, workingPtr->commandlen); | |
553 workingPtr->handled = aim_callhandler_noparam(sess, workingPtr->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_UNKNOWN, workingPtr); | |
554 break; | |
555 } | |
2 | 556 } |
237 | 557 } |
2 | 558 |
237 | 559 /* |
560 * This doesn't have to be called here. It could easily be done | |
561 * by a seperate thread or something. It's an administrative operation, | |
562 * and can take a while. Though the less you call it the less memory | |
563 * you'll have :) | |
564 */ | |
565 aim_purge_rxqueue(sess); | |
2 | 566 |
567 return 0; | |
568 } | |
569 | |
237 | 570 int aim_parsemotd_middle(struct aim_session_t *sess, |
571 struct command_rx_struct *command, ...) | |
2 | 572 { |
237 | 573 rxcallback_t userfunc = NULL; |
574 char *msg; | |
575 int ret=1; | |
576 struct aim_tlvlist_t *tlvlist; | |
577 u_short id; | |
578 | |
579 /* | |
580 * Dunno. | |
581 */ | |
582 id = aimutil_get16(command->data+10); | |
583 | |
584 /* | |
585 * TLVs follow | |
586 */ | |
587 tlvlist = aim_readtlvchain(command->data+12, command->commandlen-12); | |
588 | |
589 msg = aim_gettlv_str(tlvlist, 0x000b, 1); | |
590 | |
591 userfunc = aim_callhandler(command->conn, 0x0001, 0x0013); | |
592 if (userfunc) | |
593 ret = userfunc(sess, command, id, msg); | |
594 | |
595 aim_freetlvchain(&tlvlist); | |
596 | |
597 return ret; | |
598 | |
599 } | |
2 | 600 |
237 | 601 int aim_handleredirect_middle(struct aim_session_t *sess, |
602 struct command_rx_struct *command, ...) | |
603 { | |
604 struct aim_tlv_t *tmptlv = NULL; | |
605 int serviceid = 0x00; | |
606 char cookie[AIM_COOKIELEN]; | |
607 char *ip = NULL; | |
608 rxcallback_t userfunc = NULL; | |
609 struct aim_tlvlist_t *tlvlist; | |
610 int ret = 1; | |
611 | |
612 if (!(tlvlist = aim_readtlvchain(command->data+10, command->commandlen-10))) | |
2 | 613 { |
237 | 614 printf("libfaim: major bug: unable to read tlvchain from redirect\n"); |
615 return ret; | |
616 } | |
617 | |
618 if (!(tmptlv = aim_gettlv(tlvlist, 0x000d, 1))) | |
619 { | |
620 printf("libfaim: major bug: no service ID in tlvchain from redirect\n"); | |
621 aim_freetlvchain(&tlvlist); | |
622 return ret; | |
2 | 623 } |
237 | 624 serviceid = aimutil_get16(tmptlv->value); |
625 | |
626 if (!(ip = aim_gettlv_str(tlvlist, 0x0005, 1))) | |
627 { | |
628 printf("libfaim: major bug: no IP in tlvchain from redirect (service 0x%02x)\n", serviceid); | |
629 aim_freetlvchain(&tlvlist); | |
630 return ret; | |
631 } | |
632 | |
633 if (!(tmptlv = aim_gettlv(tlvlist, 0x0006, 1))) | |
2 | 634 { |
237 | 635 printf("libfaim: major bug: no cookie in tlvchain from redirect (service 0x%02x)\n", serviceid); |
636 aim_freetlvchain(&tlvlist); | |
637 return ret; | |
638 } | |
639 memcpy(cookie, tmptlv->value, AIM_COOKIELEN); | |
640 | |
641 if (serviceid == AIM_CONN_TYPE_CHAT) | |
642 { | |
643 /* | |
644 * Chat hack. | |
645 * | |
646 */ | |
647 userfunc = aim_callhandler(command->conn, 0x0001, 0x0005); | |
648 if (userfunc) | |
649 ret = userfunc(sess, command, serviceid, ip, cookie, sess->pendingjoin); | |
650 free(sess->pendingjoin); | |
651 sess->pendingjoin = NULL; | |
2 | 652 } |
653 else | |
654 { | |
237 | 655 userfunc = aim_callhandler(command->conn, 0x0001, 0x0005); |
656 if (userfunc) | |
657 ret = userfunc(sess, command, serviceid, ip, cookie); | |
658 } | |
2 | 659 |
237 | 660 /* |
661 * XXX: Is there a leak here? Where does IP get freed? | |
662 */ | |
663 aim_freetlvchain(&tlvlist); | |
2 | 664 |
237 | 665 return ret; |
2 | 666 } |
667 | |
237 | 668 int aim_parse_unknown(struct aim_session_t *sess, |
669 struct command_rx_struct *command, ...) | |
2 | 670 { |
237 | 671 u_int i = 0; |
2 | 672 |
237 | 673 faimdprintf(1, "\nRecieved unknown packet:"); |
2 | 674 |
675 for (i = 0; i < command->commandlen; i++) | |
676 { | |
677 if ((i % 8) == 0) | |
678 printf("\n\t"); | |
679 | |
680 printf("0x%2x ", command->data[i]); | |
681 } | |
682 | |
683 printf("\n\n"); | |
684 | |
685 return 1; | |
686 } | |
687 | |
688 | |
689 /* | |
690 * aim_parse_generalerrs() | |
691 * | |
692 * Middle handler for 0x0001 snac of each family. | |
693 * | |
694 */ | |
237 | 695 int aim_parse_generalerrs(struct aim_session_t *sess, |
696 struct command_rx_struct *command, ...) | |
2 | 697 { |
698 u_short family; | |
699 u_short subtype; | |
237 | 700 |
701 family = aimutil_get16(command->data+0); | |
702 subtype= aimutil_get16(command->data+2); | |
2 | 703 |
704 switch(family) | |
705 { | |
706 default: | |
707 /* Unknown family */ | |
237 | 708 return aim_callhandler_noparam(sess, command->conn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_UNKNOWN, command); |
2 | 709 } |
710 | |
711 return 1; | |
712 } | |
713 | |
714 | |
715 |