2 * -----------------------------------------------------------
3 * ProtoFAIM: v1.xx.xxplxx
4 * -----------------------------------------------------------
6 * This is ProtoFAIM v1.xx.xxplxx!!! Its nearly completely
7 * different than that ugly thing called v0. This app is
8 * compatible with the latest version of the libfaim library.
11 * ProtoFAIM should only be used for two things...
12 * 1) Testing the libfaim backend.
13 * 2) For reference on the libfaim API when developing clients.
15 * Its very ugly. Probably always will be. Nothing is more
16 * ugly than the backend itself, however.
18 * -----------------------------------------------------------
20 * I'm releasing this code and all it's associated linkage
21 * under the GNU General Public License. For more information,
22 * please refer to http://www.fsf.org. For any questions,
23 * please contact me at the address below.
26 * (c) 1998 Adam Fritzler, PST, afritz@iname.com
28 * The password algorithms
29 * (c) 1998 Brock Wilcox, awwaiid@iname.com
31 * THERE IS NO CODE FROM AOL'S AIM IN THIS CODE, NOR
32 * WAS THERE ANY DISASSEMBLAGE TO DEFINE PROTOCOL. All
33 * information was gained through painstakingly comparing
34 * TCP dumps while the AIM Java client was running. Nothing
35 * more than that, except for a lot of experimenting.
37 * -----------------------------------------------------------
49 int faimtest_parse_oncoming(struct aim_session_t *, struct command_rx_struct *, ...);
50 int faimtest_parse_offgoing(struct aim_session_t *, struct command_rx_struct *, ...);
51 int faimtest_parse_login_phase3d_f(struct aim_session_t *, struct command_rx_struct *, ...);
52 int faimtest_parse_authresp(struct aim_session_t *, struct command_rx_struct *, ...);
53 int faimtest_parse_incoming_im(struct aim_session_t *, struct command_rx_struct *command, ...);
54 int faimtest_parse_userinfo(struct aim_session_t *, struct command_rx_struct *command, ...);
55 int faimtest_handleredirect(struct aim_session_t *, struct command_rx_struct *command, ...);
56 int faimtest_authsvrready(struct aim_session_t *, struct command_rx_struct *command, ...);
57 int faimtest_pwdchngdone(struct aim_session_t *, struct command_rx_struct *command, ...);
58 int faimtest_serverready(struct aim_session_t *, struct command_rx_struct *command, ...);
59 int faimtest_parse_misses(struct aim_session_t *, struct command_rx_struct *command, ...);
60 int faimtest_parse_msgack(struct aim_session_t *, struct command_rx_struct *command, ...);
61 int faimtest_parse_motd(struct aim_session_t *, struct command_rx_struct *command, ...);
62 int faimtest_parse_login(struct aim_session_t *, struct command_rx_struct *command, ...);
63 int faimtest_chatnav_info(struct aim_session_t *, struct command_rx_struct *command, ...);
64 int faimtest_chat_incomingmsg(struct aim_session_t *sess, struct command_rx_struct *command, ...);
65 int faimtest_chat_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
66 int faimtest_chat_leave(struct aim_session_t *sess, struct command_rx_struct *command, ...);
67 int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *command, ...);
68 int faimtest_parse_connerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
69 int faimtest_debugconn_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
71 int faimtest_directim_request(struct aim_session_t *sess, struct command_rx_struct *command, ...);
72 int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...);
73 int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
74 int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...);
75 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...);
76 int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...);
77 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...);
78 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...);
79 int faimtest_parse_msgerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
80 int faimtest_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...);
81 int faimtest_parse_locerr(struct aim_session_t *sess, struct command_rx_struct *command, ...);
83 static char *msgerrreasons[] = {
89 "Service unavailable",
90 "Service not defined",
92 "Not supported by host",
93 "Not supported by client",
98 "Busted SNAC payload",
99 "Insufficient rights",
100 "In local permit/deny",
102 "Too evil (receiver)",
103 "User temporarily unavailable",
109 static int msgerrreasonslen = 25;
111 int faimtest_reportinterval(struct aim_session_t *sess, struct command_rx_struct *command, ...)
114 printf("aim: minimum report interval: %d (seconds?)\n", aimutil_get16(command->data+10));
116 printf("aim: NULL minimum report interval!\n");
120 static char *screenname,*password,*server=NULL;
124 struct aim_session_t aimsess;
125 struct aim_conn_t *authconn = NULL, *waitingconn = NULL;
130 if ( !(screenname = getenv("SCREENNAME")) ||
131 !(password = getenv("PASSWORD")))
133 printf("Must specify SCREENAME and PASSWORD in environment.\n");
137 server = getenv("AUTHSERVER");
139 aim_session_init(&aimsess);
141 authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, server?server:FAIM_LOGIN_SERVER);
143 if (authconn == NULL) {
144 fprintf(stderr, "faimtest: internal connection error while in aim_login. bailing out.\n");
146 } else if (authconn->fd == -1) {
147 if (authconn->status & AIM_CONN_STATUS_RESOLVERR)
148 fprintf(stderr, "faimtest: could not resolve authorizer name\n");
149 else if (authconn->status & AIM_CONN_STATUS_CONNERR)
150 fprintf(stderr, "faimtest: could not connect to authorizer\n");
151 aim_conn_kill(&aimsess, &authconn);
155 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0007, faimtest_parse_login, 0);
156 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0003, faimtest_parse_authresp, 0);
158 aim_sendconnack(&aimsess, authconn);
159 aim_request_login(&aimsess, authconn, screenname);
161 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEBUGCONN_CONNECT, faimtest_debugconn_connect, 0);
163 printf("faimtest: login request sent\n");
166 waitingconn = aim_select(&aimsess, NULL, &selstat);
170 keepgoing = 0; /* fall through and hit the aim_logoff() */
173 case 0: /* no events pending */
176 case 1: /* outgoing data pending */
177 aim_tx_flushqueue(&aimsess);
180 case 2: /* incoming data pending */
181 if (waitingconn->type == AIM_CONN_TYPE_RENDEZVOUS_OUT) {
182 if (aim_handlerendconnect(&aimsess, waitingconn) < 0) {
183 printf("connection error (rend)\n");
186 if (aim_get_command(&aimsess, waitingconn) >= 0) {
187 aim_rxdispatch(&aimsess);
189 printf("connection error\n");
190 aim_conn_kill(&aimsess, &waitingconn);
191 if (!aim_getconn_type(&aimsess, AIM_CONN_TYPE_BOS)) {
192 printf("major connetion error\n");
205 printf("AIM just decided we didn't need to be here anymore, closing up...\n");
207 /* close up all connections, dead or no */
208 aim_logoff(&aimsess);
214 int faimtest_rateresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
217 switch(command->conn->type) {
218 case AIM_CONN_TYPE_BOS: {
219 /* this is the new buddy list */
220 char buddies[] = "Buddy1&Buddy2&ThisHereIsAName2&";
221 /* this is the new profile */
222 char profile[] = "Hello";
224 aim_bos_ackrateresp(sess, command->conn); /* ack rate info response */
225 aim_bos_reqpersonalinfo(sess, command->conn);
226 aim_bos_reqlocaterights(sess, command->conn);
227 aim_bos_setprofile(sess, command->conn, profile, NULL, AIM_CAPS_BUDDYICON | AIM_CAPS_CHAT | AIM_CAPS_VOICE | AIM_CAPS_GETFILE | AIM_CAPS_SENDFILE | AIM_CAPS_IMIMAGE);
228 aim_bos_reqbuddyrights(sess, command->conn);
230 /* send the buddy list and profile (required, even if empty) */
231 aim_bos_setbuddylist(sess, command->conn, buddies);
233 /* dont really know what this does */
234 aim_addicbmparam(sess, command->conn);
235 aim_bos_reqicbmparaminfo(sess, command->conn);
237 aim_bos_reqrights(sess, command->conn);
238 /* set group permissions -- all user classes */
239 aim_bos_setgroupperm(sess, command->conn, AIM_CLASS_ALLUSERS);
240 aim_bos_setprivacyflags(sess, command->conn, AIM_PRIVFLAGS_ALLOWIDLE|AIM_PRIVFLAGS_ALLOWMEMBERSINCE);
246 printf("faimtest: got rate response for unhandled connection type %04x\n", command->conn->type);
253 int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
255 switch (command->conn->type)
257 case AIM_CONN_TYPE_BOS:
259 aim_setversions(sess, command->conn);
260 aim_bos_reqrate(sess, command->conn); /* request rate info */
262 fprintf(stderr, "faimtest: done with BOS ServerReady\n");
265 case AIM_CONN_TYPE_CHATNAV:
266 fprintf(stderr, "faimtest: chatnav: got server ready\n");
267 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CTN, AIM_CB_CTN_INFO, faimtest_chatnav_info, 0);
268 aim_bos_reqrate(sess, command->conn);
269 aim_bos_ackrateresp(sess, command->conn);
270 aim_chatnav_clientready(sess, command->conn);
271 aim_chatnav_reqrights(sess, command->conn);
274 case AIM_CONN_TYPE_CHAT:
275 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERJOIN, faimtest_chat_join, 0);
276 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_USERLEAVE, faimtest_chat_leave, 0);
277 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_ROOMINFOUPDATE, faimtest_chat_infoupdate, 0);
278 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_CHT, AIM_CB_CHT_INCOMINGMSG, faimtest_chat_incomingmsg, 0);
279 aim_bos_reqrate(sess, command->conn);
280 aim_bos_ackrateresp(sess, command->conn);
281 aim_chat_clientready(sess, command->conn);
284 case AIM_CONN_TYPE_RENDEZVOUS: /* this is an overloaded function?? - mid */
285 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
286 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
290 fprintf(stderr, "faimtest: unknown connection type on Server Ready\n");
295 int faimtest_parse_buddyrights(struct aim_session_t *sess, struct command_rx_struct *command, ...)
298 unsigned short maxbuddies, maxwatchers;
300 va_start(ap, command);
301 maxbuddies = va_arg(ap, unsigned short);
302 maxwatchers = va_arg(ap, unsigned short);
305 printf("faimtest: buddy list rights: Max buddies = %d / Max watchers = %d\n", maxbuddies, maxwatchers);
310 int faimtest_bosrights(struct aim_session_t *sess, struct command_rx_struct *command, ...)
312 unsigned short maxpermits, maxdenies;
315 va_start(ap, command);
316 maxpermits = va_arg(ap, unsigned short);
317 maxdenies = va_arg(ap, unsigned short);
320 printf("faimtest: BOS rights: Max permit = %d / Max deny = %d\n", maxpermits, maxdenies);
322 aim_bos_clientready(sess, command->conn);
324 printf("faimtest: officially connected to BOS.\n");
332 This, of course, handles Service Redirects from OSCAR.
334 Should get passed in the following:
335 struct command_rx_struct *command
338 the destination service ID
340 the IP address of the service's server
344 int faimtest_handleredirect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
349 unsigned char *cookie;
351 va_start(ap, command);
352 serviceid = va_arg(ap, int);
353 ip = va_arg(ap, char *);
354 cookie = va_arg(ap, unsigned char *);
358 case 0x0007: /* Authorizer */
360 struct aim_conn_t *tstconn;
361 /* Open a connection to the Auth */
362 tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
363 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR) )
364 fprintf(stderr, "faimtest: unable to reconnect with authorizer\n");
366 /* Send the cookie to the Auth */
367 aim_auth_sendcookie(sess, tstconn, cookie);
371 case 0x000d: /* ChatNav */
373 struct aim_conn_t *tstconn = NULL;
374 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, ip);
375 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR)) {
376 fprintf(stderr, "faimtest: unable to connect to chatnav server\n");
377 if (tstconn) aim_conn_kill(sess, &tstconn);
381 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_CTN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
382 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
384 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
385 aim_auth_sendcookie(sess, tstconn, cookie);
386 fprintf(stderr, "\achatnav: connected\n");
389 case 0x000e: /* Chat */
391 char *roomname = NULL;
392 struct aim_conn_t *tstconn = NULL;
394 roomname = va_arg(ap, char *);
396 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
397 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
399 fprintf(stderr, "faimtest: unable to connect to chat server\n");
400 if (tstconn) aim_conn_kill(sess, &tstconn);
403 printf("faimtest: chat: connected\n");
406 * We must do this to attach the stored name to the connection!
408 aim_chat_attachname(tstconn, roomname);
410 aim_conn_addhandler(sess, tstconn, 0x0001, 0x0003, faimtest_serverready, 0);
411 aim_auth_sendcookie(sess, tstconn, cookie);
415 printf("uh oh... got redirect for unknown service 0x%04x!!\n", serviceid);
424 int faimtest_parse_authresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
426 struct aim_conn_t *bosconn = NULL;
429 printf("Screen name: %s\n", sess->logininfo.screen_name);
434 if (sess->logininfo.errorcode)
436 printf("Login Error Code 0x%04x\n", sess->logininfo.errorcode);
437 printf("Error URL: %s\n", sess->logininfo.errorurl);
438 aim_conn_kill(sess, &command->conn);
439 exit(0); /* XXX: should return in order to let the above things get free()'d. */
442 printf("Reg status: %2d\n", sess->logininfo.regstatus);
443 printf("Email: %s\n", sess->logininfo.email);
444 printf("BOS IP: %s\n", sess->logininfo.BOSIP);
446 printf("Closing auth connection...\n");
447 aim_conn_kill(sess, &command->conn);
448 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP);
449 if (bosconn == NULL) {
450 fprintf(stderr, "faimtest: could not connect to BOS: internal error\n");
451 } else if (bosconn->status != 0) {
452 fprintf(stderr, "faimtest: could not connect to BOS\n");
453 aim_conn_kill(sess, &bosconn);
455 aim_conn_addhandler(sess, bosconn, 0x0009, 0x0003, faimtest_bosrights, 0);
456 aim_conn_addhandler(sess, bosconn, 0x0001, 0x0007, faimtest_rateresp, 0); /* rate info */
457 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0);
458 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_serverready, 0);
459 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0);
460 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0);
461 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, faimtest_reportinterval, 0);
462 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_RIGHTSINFO, faimtest_parse_buddyrights, 0);
463 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0);
464 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0);
465 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
466 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_locerr, 0);
467 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0);
468 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_ratechange, 0);
469 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_EVIL, faimtest_parse_evilnotify, 0);
470 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_msgerr, 0);
471 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0);
472 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ACK, faimtest_parse_msgack, 0);
474 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0);
475 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
476 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, faimtest_parse_motd, 0);
478 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_CONNERR, faimtest_parse_connerr, 0);
480 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie);
485 int faimtest_parse_userinfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
487 struct aim_userinfo_s *userinfo;
488 char *prof_encoding = NULL;
490 unsigned short inforeq = 0;
493 va_start(ap, command);
494 userinfo = va_arg(ap, struct aim_userinfo_s *);
495 prof_encoding = va_arg(ap, char *);
496 prof = va_arg(ap, char *);
497 inforeq = va_arg(ap, unsigned short);
500 printf("faimtest: userinfo: sn: %s\n", userinfo->sn);
501 printf("faimtest: userinfo: warnlevel: 0x%04x\n", userinfo->warnlevel);
502 printf("faimtest: userinfo: class: 0x%04x = ", userinfo->class);
516 if (userinfo->class & 0x0001)
518 if (userinfo->class & 0x0002)
519 printf("ADMINISTRATOR ");
520 if (userinfo->class & 0x0004)
522 if (userinfo->class & 0x0008)
523 printf("OSCAR_PAY ");
524 if (userinfo->class & 0x0010)
526 if (userinfo->class & 0x0040)
530 printf("faimtest: userinfo: membersince: %lu\n", userinfo->membersince);
531 printf("faimtest: userinfo: onlinesince: %lu\n", userinfo->onlinesince);
532 printf("faimtest: userinfo: idletime: 0x%04x\n", userinfo->idletime);
534 if (inforeq == AIM_GETINFO_GENERALINFO) {
535 printf("faimtest: userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
536 printf("faimtest: userinfo: prof: %s\n", prof ? prof : "[none]");
537 } else if (inforeq == AIM_GETINFO_AWAYMESSAGE) {
538 printf("faimtest: userinfo: awaymsg_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
539 printf("faimtest: userinfo: awaymsg: %s\n", prof ? prof : "[none]");
541 printf("faimtest: userinfo: unknown info request\n");
547 * The user-level Incoming ICBM callback.
550 * struct command_rx_struct * command if you feel like doing it yourself
551 * char * srcsn the source name
553 * int warnlevel warning/evil level
554 * int class user class
555 * ulong membersince time_t of date of signup
556 * ulong onsince time_t of date of singon
557 * int idletime min (sec?) idle
558 * u_int icbmflags sets AIM_IMFLAGS_{AWAY,ACK}
561 int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_struct *command, ...)
566 va_start(ap, command);
567 channel = va_arg(ap, int);
570 * Channel 1: Standard Message
573 struct aim_userinfo_s *userinfo;
577 u_short flag1, flag2;
579 userinfo = va_arg(ap, struct aim_userinfo_s *);
580 msg = va_arg(ap, char *);
581 icbmflags = va_arg(ap, u_int);
582 flag1 = va_arg(ap, u_short);
583 flag2 = va_arg(ap, u_short);
586 printf("faimtest: icbm: sn = \"%s\"\n", userinfo->sn);
587 printf("faimtest: icbm: warnlevel = 0x%04x\n", userinfo->warnlevel);
588 printf("faimtest: icbm: class = 0x%04x ", userinfo->class);
589 if (userinfo->class & 0x0010)
591 if (userinfo->class & 0x0001)
593 if (userinfo->class & 0x0004)
596 printf("faimtest: icbm: membersince = %lu\n", userinfo->membersince);
597 printf("faimtest: icbm: onlinesince = %lu\n", userinfo->onlinesince);
598 printf("faimtest: icbm: idletime = 0x%04x\n", userinfo->idletime);
599 printf("faimtest: icbm: capabilities = 0x%04x\n", userinfo->capabilities);
601 printf("faimtest: icbm: icbmflags = ");
602 if (icbmflags & AIM_IMFLAGS_AWAY)
604 if (icbmflags & AIM_IMFLAGS_ACK)
605 printf("ackrequest ");
608 printf("faimtest: icbm: encoding flags = {%04x, %04x}\n", flag1, flag2);
610 printf("faimtest: icbm: message: %s\n", msg);
615 while (msg[i] == '<') {
617 while (msg[i] != '>')
624 printf("tmpstr = %s\n", tmpstr);
626 if ( (strlen(tmpstr) >= 10) &&
627 (!strncmp(tmpstr, "disconnect", 10)) ) {
628 aim_send_im(sess, command->conn, "midendian", 0, "ta ta...");
630 } else if (strstr(tmpstr, "goodday")) {
631 printf("faimtest: icbm: sending response\n");
632 aim_send_im(sess, command->conn, userinfo->sn, AIM_IMFLAGS_ACK, "Good day to you too.");
633 } else if (strstr(tmpstr, "warnme")) {
634 printf("faimtest: icbm: sending non-anon warning\n");
635 aim_send_warning(sess, command->conn, userinfo->sn, 0);
636 } else if (strstr(tmpstr, "anonwarn")) {
637 printf("faimtest: icbm: sending anon warning\n");
638 aim_send_warning(sess, command->conn, userinfo->sn, AIM_WARN_ANON);
639 } else if (!strncmp(tmpstr, "open chatnav", 12)) {
640 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
641 //aim_chat_join(sess, command->conn, "thishereisaname2_chat85");
642 } else if (!strncmp(tmpstr, "create", 6)) {
643 aim_chatnav_createroom(sess,aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV), (strlen(tmpstr) < 7)?"WorldDomination":tmpstr+7, 0x0004);
644 } else if (!strncmp(tmpstr, "close chatnav", 13)) {
645 struct aim_conn_t *chatnavconn;
646 chatnavconn = aim_getconn_type(sess, AIM_CONN_TYPE_CHATNAV);
647 aim_conn_kill(sess, &chatnavconn);
648 } else if (!strncmp(tmpstr, "join", 4)) {
649 aim_chat_join(sess, command->conn, 0x0004, "worlddomination");
650 } else if (!strncmp(tmpstr, "leave", 5))
651 aim_chat_leaveroom(sess, "worlddomination");
652 else if (!strncmp(tmpstr, "getinfo", 7)) {
653 aim_getinfo(sess, command->conn, "75784102", AIM_GETINFO_GENERALINFO);
654 aim_getinfo(sess, command->conn, "15853637", AIM_GETINFO_AWAYMESSAGE);
655 } else if (!strncmp(tmpstr, "open directim", 13)) {
656 struct aim_conn_t *newconn;
657 newconn = aim_directim_initiate(sess, command->conn, NULL, userinfo->sn);
658 //aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINITIATE, faimtest_directim_initiate, 0);
659 } else if (!strncmp(tmpstr, "reqsendmsg", 10)) {
660 aim_send_im(sess, command->conn, "vaxherder", 0, "sendmsg 7900");
661 } else if (!strncmp(tmpstr, "sendmsg", 7)) {
668 newbuf = malloc(i+1);
669 for (z = 0; z < i; z++) {
670 newbuf[z] = (z % 10)+0x30;
673 aim_send_im(sess, command->conn, userinfo->sn, 0, newbuf);
677 printf("unknown command.\n");
678 aim_add_buddy(sess, command->conn, userinfo->sn);
684 * Channel 2: Rendevous Request
686 else if (channel == 2) {
687 struct aim_userinfo_s *userinfo;
688 unsigned short reqclass;
690 reqclass = va_arg(ap, unsigned short);
692 case AIM_CAPS_VOICE: {
693 userinfo = va_arg(ap, struct aim_userinfo_s *);
696 printf("faimtest: voice invitation: source sn = %s\n", userinfo->sn);
697 printf("faimtest: voice invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
698 printf("faimtest: voice invitation: \tclass = 0x%04x ", userinfo->class);
699 if (userinfo->class & 0x0010)
701 if (userinfo->class & 0x0001)
703 if (userinfo->class & 0x0004)
706 /* we dont get membersince on chat invites! */
707 printf("faimtest: voice invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
708 printf("faimtest: voice invitation: \tidletime = 0x%04x\n", userinfo->idletime);
712 case AIM_CAPS_GETFILE: {
713 printf("faimtset: get file!\n");
716 case AIM_CAPS_SENDFILE: {
717 printf("faimtest: send file!\n");
720 case AIM_CAPS_CHAT: {
721 char *msg,*encoding,*lang;
722 struct aim_chat_roominfo *roominfo;
724 userinfo = va_arg(ap, struct aim_userinfo_s *);
725 roominfo = va_arg(ap, struct aim_chat_roominfo *);
726 msg = va_arg(ap, char *);
727 encoding = va_arg(ap, char *);
728 lang = va_arg(ap, char *);
731 printf("faimtest: chat invitation: source sn = %s\n", userinfo->sn);
732 printf("faimtest: chat invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
733 printf("faimtest: chat invitation: \tclass = 0x%04x ", userinfo->class);
734 if (userinfo->class & 0x0010)
736 if (userinfo->class & 0x0001)
738 if (userinfo->class & 0x0004)
741 /* we dont get membersince on chat invites! */
742 printf("faimtest: chat invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
743 printf("faimtest: chat invitation: \tidletime = 0x%04x\n", userinfo->idletime);
745 printf("faimtest: chat invitation: message = %s\n", msg);
746 printf("faimtest: chat invitation: room name = %s\n", roominfo->name);
747 printf("faimtest: chat invitation: encoding = %s\n", encoding);
748 printf("faimtest: chat invitation: language = %s\n", lang);
749 printf("faimtest: chat invitation: exchange = 0x%04x\n", roominfo->exchange);
750 printf("faimtest: chat invitation: instance = 0x%04x\n", roominfo->instance);
751 printf("faimtest: chat invitiation: autojoining %s...\n", roominfo->name);
753 * Automatically join room...
755 aim_chat_join(sess, command->conn, 0x0004, roominfo->name);
758 case AIM_CAPS_IMIMAGE: {
759 struct aim_directim_priv *priv;
760 struct aim_conn_t *newconn;
762 printf("faimtest: icbm: rendezvous imimage\n");
764 userinfo = va_arg(ap, struct aim_userinfo_s *);
765 priv = va_arg(ap, struct aim_directim_priv *);
768 printf("faimtest: OFT: DirectIM: request from %s (%s)\n", userinfo->sn, priv->ip);
770 if (!(newconn = aim_directim_connect(sess, command->conn, priv))) {
771 printf("faimtest: icbm: imimage: could not connect\n");
774 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
775 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
776 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, faimtest_directim_typing, 0);
778 aim_send_im_direct(sess, newconn, "goodday");
780 printf("faimtest: OFT: DirectIM: connected to %s\n", userinfo->sn);
785 printf("faimtest: icbm: unknown reqclass (%d)\n", reqclass);
788 printf("faimtest does not support channels > 2 (chan = %02x)\n", channel);
789 printf("faimtest: icbm: done with ICBM handling\n");
795 int faimtest_directim_initiate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
798 struct aim_directim_priv *priv;
799 struct aim_conn_t *newconn;
801 ap = va_start(ap, command);
802 newconn = va_arg(ap, struct aim_conn_t *);
805 priv = (struct aim_directim_priv *)newconn->priv;
807 printf("faimtest: OFT: DirectIM: intitiate success to %s\n", priv->ip);
809 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMINCOMING, faimtest_directim_incoming, 0);
810 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMDISCONNECT, faimtest_directim_disconnect, 0);
811 aim_conn_addhandler(sess, newconn, AIM_CB_FAM_OFT, AIM_CB_OFT_DIRECTIMTYPING, faimtest_directim_typing, 0);
813 aim_send_im_direct(sess, newconn, "goodday");
815 printf("faimtest: OFT: DirectIM: connected to %s\n", priv->sn);
821 int faimtest_directim_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
824 struct aim_directim_priv *priv;
826 ap = va_start(ap, command);
827 priv = va_arg(ap, struct aim_directim_priv *);
831 printf("faimtest: directim_connect\n");
836 int faimtest_directim_incoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
839 char *sn = NULL, *msg = NULL;
840 struct aim_conn_t *conn;
842 ap = va_start(ap, command);
843 conn = va_arg(ap, struct aim_conn_t *);
844 sn = va_arg(ap, char *);
845 msg = va_arg(ap, char *);
848 printf("faimtest: Directim from %s: %s\n", sn, msg);
849 if (!strncmp(msg, "sendmsg", 7)) {
856 newbuf = malloc(i+1);
857 for (z = 0; z < i; z++) {
858 newbuf[z] = (z % 10)+0x30;
861 aim_send_im_direct(sess, conn, newbuf);
864 } else if (!strncmp(msg, "goodday", 7)) {
865 aim_send_im_direct(sess, conn, "Good day to you, too");
868 snprintf(newmsg, sizeof(newmsg), "unknown (%s)\n", msg);
869 aim_send_im_direct(sess, conn, newmsg);
874 int faimtest_directim_disconnect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
876 printf("faimtest: directim_disconnect\n");
880 int faimtest_directim_typing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
885 ap = va_start(ap, command);
886 sn = va_arg(ap, char *);
889 printf("faimtest: ohmigod! %s has started typing (DirectIM). He's going to send you a message! *squeal*\n", sn);
893 int faimtest_authsvrready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
895 printf("faimtest_authsvrready: called (contype: %d)\n", command->conn->type);
897 /* should just be able to tell it we're ready too... */
898 aim_auth_clientready(sess, command->conn);
902 * This is where you'd really begin changing your password.
903 * However, this callback may get called for reasons other
904 * than you wanting to change your password. You should
905 * probably check that before actually doing it.
907 aim_auth_changepasswd(sess, command->conn, "PWD1", "PWD2");
913 int faimtest_pwdchngdone(struct aim_session_t *sess, struct command_rx_struct *command, ...)
915 printf("PASSWORD CHANGE SUCCESSFUL!!!\n");
919 int faimtest_parse_oncoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
921 struct aim_userinfo_s *userinfo;
924 va_start(ap, command);
925 userinfo = va_arg(ap, struct aim_userinfo_s *);
928 printf("\n%s is now online (class: %04x = %s%s%s%s%s%s%s%s) (caps = 0x%04x)\n",
929 userinfo->sn, userinfo->class,
930 (userinfo->class&AIM_CLASS_TRIAL)?" TRIAL":"",
931 (userinfo->class&AIM_CLASS_ADMINISTRATOR)?" ADMINISTRATOR":"",
932 (userinfo->class&AIM_CLASS_AOL)?" AOL":"",
933 (userinfo->class&AIM_CLASS_OSCAR_PAY)?" OSCAR_PAY":"",
934 (userinfo->class&AIM_CLASS_FREE)?" FREE":"",
935 (userinfo->class&AIM_CLASS_AWAY)?" AWAY":"",
936 (userinfo->class&AIM_CLASS_UNKNOWN40)?" UNKNOWN40":"",
937 (userinfo->class&AIM_CLASS_UNKNOWN80)?" UNKNOWN80":"",
938 userinfo->capabilities);
942 int faimtest_parse_offgoing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
947 va_start(ap, command);
948 sn = va_arg(ap, char *);
951 printf("\n%s has left\n", sn);
956 int faimtest_parse_motd(struct aim_session_t *sess, struct command_rx_struct *command, ...)
958 static char *codes[] = {
963 "Top o' the world!"};
964 static int codeslen = 5;
970 va_start(ap, command);
971 id = va_arg(ap, unsigned short);
972 msg = va_arg(ap, char *);
975 printf("faimtest: motd: %s (%d / %s)\n", msg, id,
976 (id < codeslen)?codes[id]:"unknown");
981 int faimtest_parse_msgerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
985 unsigned short reason;
987 va_start(ap, command);
988 destsn = va_arg(ap, char *);
989 reason = va_arg(ap, unsigned short);
992 printf("faimtest: message to %s bounced (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
997 int faimtest_parse_locerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1001 unsigned short reason;
1003 va_start(ap, command);
1004 destsn = va_arg(ap, char *);
1005 reason = va_arg(ap, unsigned short);
1008 printf("faimtest: user information for %s unavailable (reason 0x%04x: %s)\n", destsn, reason, (reason<msgerrreasonslen)?msgerrreasons[reason]:"unknown");
1014 * Handles callbacks for AIM_CB_MISSED_CALL.
1016 int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1018 static char *missedreasons[] = {
1020 "Message too large"};
1021 static int missedreasonslen = 2;
1024 unsigned short chan, nummissed, reason;
1025 struct aim_userinfo_s *userinfo;
1027 va_start(ap, command);
1028 chan = va_arg(ap, unsigned short);
1029 userinfo = va_arg(ap, struct aim_userinfo_s *);
1030 nummissed = va_arg(ap, unsigned short);
1031 reason = va_arg(ap, unsigned short);
1034 printf("faimtest: missed %d messages from %s (reason %d: %s)\n", nummissed, userinfo->sn, reason, (reason<missedreasonslen)?missedreasons[reason]:"unknown");
1039 int faimtest_parse_login(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1041 struct client_info_s info = {"faimtest (with SNAC login)", 4, 1, 2010, "us", "en", 0x0004, 0x0000, 0x0000004b}; /* 4.1.2010 */
1045 va_start(ap, command);
1046 key = va_arg(ap, char *);
1049 aim_send_login(sess, command->conn, screenname, password, &info, key);
1054 int faimtest_chat_join(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1057 struct aim_userinfo_s *userinfo;
1058 int count = 0, i = 0;
1060 va_start(ap, command);
1061 count = va_arg(ap, int);
1062 userinfo = va_arg(ap, struct aim_userinfo_s *);
1065 printf("faimtest: chat: %s: New occupants have joined:\n", (char *)command->conn->priv);
1067 printf("faimtest: chat: %s: \t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
1072 int faimtest_chat_leave(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1075 struct aim_userinfo_s *userinfo;
1076 int count = 0, i = 0;
1078 va_start(ap, command);
1079 count = va_arg(ap, int);
1080 userinfo = va_arg(ap, struct aim_userinfo_s *);
1083 printf("faimtest: chat: %s: Some occupants have left:\n", (char *)command->conn->priv);
1085 printf("faimtest: chat: %s: \t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
1090 int faimtest_chat_infoupdate(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1093 struct aim_userinfo_s *userinfo;
1094 struct aim_chat_roominfo *roominfo;
1098 unsigned short unknown_c9, unknown_d2, unknown_d5, maxmsglen;
1099 unsigned long creationtime;
1101 va_start(ap, command);
1102 roominfo = va_arg(ap, struct aim_chat_roominfo *);
1103 roomname = va_arg(ap, char *);
1104 usercount= va_arg(ap, int);
1105 userinfo = va_arg(ap, struct aim_userinfo_s *);
1106 roomdesc = va_arg(ap, char *);
1107 unknown_c9 = va_arg(ap, unsigned short);
1108 creationtime = va_arg(ap, unsigned long);
1109 maxmsglen = va_arg(ap, unsigned short);
1110 unknown_d2 = va_arg(ap, unsigned short);
1111 unknown_d5 = va_arg(ap, unsigned short);
1114 printf("faimtest: chat: %s: info update:\n", (char *)command->conn->priv);
1115 printf("faimtest: chat: %s: \tRoominfo: {%04x, %s, %04x}\n",
1116 (char *)command->conn->priv,
1119 roominfo->instance);
1120 printf("faimtest: chat: %s: \tRoomname: %s\n", (char *)command->conn->priv, roomname);
1121 printf("faimtest: chat: %s: \tRoomdesc: %s\n", (char *)command->conn->priv, roomdesc);
1122 printf("faimtest: chat: %s: \tOccupants: (%d)\n", (char *)command->conn->priv, usercount);
1125 while (i < usercount)
1126 printf("faimtest: chat: %s: \t\t%s\n", (char *)command->conn->priv, userinfo[i++].sn);
1128 printf("faimtest: chat: %s: \tUnknown_c9: 0x%04x\n", (char *)command->conn->priv, unknown_c9);
1129 printf("faimtest: chat: %s: \tCreation time: %lu (time_t)\n", (char *)command->conn->priv, creationtime);
1130 printf("faimtest: chat: %s: \tMax message length: %d bytes\n", (char *)command->conn->priv, maxmsglen);
1131 printf("faimtest: chat: %s: \tUnknown_d2: 0x%04x\n", (char *)command->conn->priv, unknown_d2);
1132 printf("faimtest: chat: %s: \tUnknown_d5: 0x%02x\n", (char *)command->conn->priv, unknown_d5);
1137 int faimtest_chat_incomingmsg(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1140 struct aim_userinfo_s *userinfo;
1144 va_start(ap, command);
1145 userinfo = va_arg(ap, struct aim_userinfo_s *);
1146 msg = va_arg(ap, char *);
1149 printf("faimtest: chat: %s: incoming msg from %s: %s\n", (char *)command->conn->priv, userinfo->sn, msg);
1152 * Do an echo for testing purposes. But not for ourselves ("oops!")
1154 if (strcmp(userinfo->sn, sess->logininfo.screen_name) != 0)
1156 sprintf(tmpbuf, "(%s said \"%s\")", userinfo->sn, msg);
1157 aim_chat_send_im(sess, command->conn, tmpbuf);
1163 int faimtest_chatnav_info(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1168 ap = va_start(ap, command);
1169 type = va_arg(ap, u_short);
1176 struct aim_chat_exchangeinfo *exchanges;
1177 int exchangecount,i = 0;
1179 maxrooms = va_arg(ap, u_char);
1180 exchangecount = va_arg(ap, int);
1181 exchanges = va_arg(ap, struct aim_chat_exchangeinfo *);
1184 printf("faimtest: chat info: Chat Rights:\n");
1185 printf("faimtest: chat info: \tMax Concurrent Rooms: %d\n", maxrooms);
1187 printf("faimtest: chat info: \tExchange List: (%d total)\n", exchangecount);
1188 while (i < exchangecount)
1190 printf("faimtest: chat info: \t\t%x: %s (%s/%s)\n",
1191 exchanges[i].number,
1193 exchanges[i].charset1,
1194 exchanges[i].lang1);
1202 printf("faimtest: chatnav info: unknown type (%04x)\n", type);
1207 int faimtest_parse_connerr(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1210 unsigned short code;
1213 ap = va_start(ap, command);
1214 code = va_arg(ap, unsigned short);
1215 msg = va_arg(ap, char *);
1218 printf("faimtest: connerr: Code 0x%04x: %s\n", code, msg);
1219 aim_conn_kill(sess, &command->conn); /* this will break the main loop */
1224 int faimtest_debugconn_connect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1226 printf("faimtest: connecting to an aimdebugd!\n");
1228 /* convert the authorizer connection to a BOS connection */
1229 command->conn->type = AIM_CONN_TYPE_BOS;
1231 aim_conn_addhandler(sess, command->conn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
1233 /* tell the aimddebugd we're ready */
1234 aim_debugconn_sendconnect(sess, command->conn);
1236 /* go right into main loop (don't open a BOS connection, etc) */
1241 * Recieved in response to an IM sent with the AIM_IMFLAGS_ACK option.
1243 int faimtest_parse_msgack(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1246 unsigned short type;
1249 ap = va_start(ap, command);
1250 type = va_arg(ap, unsigned short);
1251 sn = va_arg(ap, char *);
1254 printf("faimtest: msgack: 0x%04x / %s\n", type, sn);
1259 int faimtest_parse_ratechange(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1262 unsigned long newrate;
1264 va_start(ap, command);
1265 newrate = va_arg(ap, unsigned long);
1268 printf("faimtest: ratechange: %lu\n", newrate);
1273 int faimtest_parse_evilnotify(struct aim_session_t *sess, struct command_rx_struct *command, ...)
1278 va_start(ap, command);
1279 sn = va_arg(ap, char *);
1282 printf("faimtest: warning from: %s\n", sn);