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_auth_error(struct aim_session_t *, struct command_rx_struct *, ...);
53 int faimtest_parse_authresp(struct aim_session_t *, struct command_rx_struct *, ...);
54 int faimtest_parse_incoming_im(struct aim_session_t *, struct command_rx_struct *command, ...);
55 int faimtest_parse_userinfo(struct aim_session_t *, struct command_rx_struct *command, ...);
56 int faimtest_handleredirect(struct aim_session_t *, struct command_rx_struct *command, ...);
57 int faimtest_authsvrready(struct aim_session_t *, struct command_rx_struct *command, ...);
58 int faimtest_pwdchngdone(struct aim_session_t *, struct command_rx_struct *command, ...);
59 int faimtest_serverready(struct aim_session_t *, struct command_rx_struct *command, ...);
60 int faimtest_parse_misses(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, ...);
64 static char *screenname,*password;
68 struct aim_session_t aimsess;
69 struct aim_conn_t *authconn = NULL;
70 int stayconnected = 1;
71 struct client_info_s info = {"FAIMtest (Hi guys!)", 3, 5, 1670, "us", "en"};
73 aim_session_init(&aimsess);
75 if ( !(screenname = getenv("SCREENNAME")) ||
76 !(password = getenv("PASSWORD")))
78 printf("Must specify SCREENAME and PASSWORD in environment.\n");
83 * (I used a goto-based loop here because n wanted quick proof
84 * that reconnecting without restarting was actually possible...)
87 authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, FAIM_LOGIN_SERVER);
91 fprintf(stderr, "faimtest: internal connection error while in aim_login. bailing out.\n");
94 else if (authconn->fd == -1)
96 if (authconn->status & AIM_CONN_STATUS_RESOLVERR)
97 fprintf(stderr, "faimtest: could not resolve authorizer name\n");
98 else if (authconn->status & AIM_CONN_STATUS_CONNERR)
99 fprintf(stderr, "faimtest: could not connect to authorizer\n");
105 /* new login code -- not default -- pending new password encryption algo */
106 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0007, faimtest_parse_login, 0);
107 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0003, faimtest_parse_authresp, 0);
109 aim_sendconnack(&aimsess, authconn);
110 aim_request_login(&aimsess, authconn, FAIMTEST_SCREENNAME);
112 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_AUTHSUCCESS, faimtest_parse_authresp, 0);
113 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_authsvrready, 0);
114 aim_send_login(&aimsess, authconn, screenname, password, &info);
119 while (aim_select(&aimsess, NULL) > (struct aim_conn_t *)0)
121 if (aimsess.queue_outgoing)
122 aim_tx_flushqueue(&aimsess);
124 if (aim_get_command(&aimsess) < 0)
126 printf("\afaimtest: connection error!\n");
129 aim_rxdispatch(&aimsess);
133 printf("AIM just decided we didn't need to be here anymore, closing up.,,\n");
135 /* close up all connections, dead or no */
136 aim_logoff(&aimsess);
140 printf("\nTrying to reconnect in 2 seconds...\n");
149 int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
151 switch (command->conn->type)
153 case AIM_CONN_TYPE_BOS:
155 aim_bos_reqrate(sess, command->conn); /* request rate info */
156 aim_bos_ackrateresp(sess, command->conn); /* ack rate info response -- can we say timing? */
157 aim_bos_setprivacyflags(sess, command->conn, 0x00000003);
160 aim_bos_reqpersonalinfo(sess, command->conn);
163 /* Request advertisement service -- see comment in handleredirect */
164 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_ADS);
165 aim_setversions(sess, command->conn);
168 aim_bos_reqrights(sess, command->conn);
169 aim_bos_reqbuddyrights(sess, command->conn);
170 aim_bos_reqlocaterights(sess, command->conn);
171 aim_bos_reqicbmparaminfo(sess, command->conn);
174 /* set group permissions */
175 aim_bos_setgroupperm(sess, command->conn, 0x1f);
176 fprintf(stderr, "faimtest: done with BOS ServerReady\n");
178 case AIM_CONN_TYPE_CHATNAV:
179 fprintf(stderr, "faimtest: chatnav: got server ready\n");
182 fprintf(stderr, "faimtest: unknown connection type on Server Ready\n");
190 This, of course, handles Service Redirects from OSCAR.
192 Should get passed in the following:
193 struct command_rx_struct *command
196 the destination service ID
198 the IP address of the service's server
202 int faimtest_handleredirect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
209 /* this is the new buddy list */
210 char buddies[] = "Buddy1&Buddy2&";
211 /* this is the new profile */
212 char profile[] = "Hello";
214 va_start(ap, command);
215 serviceid = va_arg(ap, int);
216 ip = va_arg(ap, char *);
217 cookie = va_arg(ap, char *);
222 case 0x0005: /* Advertisements */
224 * The craziest explanation yet as to why we finish logging in when
225 * we get the advertisements redirect, of which we don't use anyway....
229 /* send the buddy list and profile (required, even if empty) */
230 aim_bos_setbuddylist(sess, command->conn, buddies);
231 aim_bos_setprofile(sess, command->conn, profile);
233 /* send final login command (required) */
234 aim_bos_clientready(sess, command->conn); /* tell BOS we're ready to go live */
236 /* you should now be ready to go */
237 printf("\nYou are now officially online.\n");
240 case 0x0007: /* Authorizer */
242 struct aim_conn_t *tstconn;
243 /* Open a connection to the Auth */
244 tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
245 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR) )
246 fprintf(stderr, "faimtest: unable to reconnect with authorizer\n");
248 /* Send the cookie to the Auth */
249 aim_auth_sendcookie(sess, tstconn, cookie);
253 case 0x000d: /* ChatNav */
255 struct aim_conn_t *tstconn = NULL;
256 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, ip);
257 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
259 fprintf(stderr, "faimtest: unable to connect to chatnav server\n");
262 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_CTN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
263 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
264 aim_auth_sendcookie(sess, tstconn, cookie);
265 fprintf(stderr, "\achatnav: connected\n");
268 case 0x000e: /* Chat */
271 struct aim_conn_t *tstconn = NULL;
272 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
273 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
275 fprintf(stderr, "faimtest: unable to connect to chat server\n");
278 aim_auth_sendcookie(sess, aim_getconn_type(sess, AIM_CONN_TYPE_CHAT), cookie);
279 fprintf(stderr, "\achat: connected\n");
284 printf("uh oh... got redirect for unknown service 0x%04x!!\n", serviceid);
292 int faimtest_auth_error(struct aim_session_t *sess, struct command_rx_struct *command, ...)
298 va_start(ap, command);
299 printf("Screen name: %s\n", sess->logininfo.screen_name);
300 errorurl = va_arg(ap, char *);
301 printf("Error URL: %s\n", errorurl);
302 errorcode = va_arg(ap, short);
303 printf("Error code: 0x%02x\n", errorcode);
306 aim_conn_close(aim_getconn_type(sess, AIM_CONN_TYPE_AUTH));
313 int faimtest_parse_authresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
315 struct aim_conn_t *bosconn = NULL;
318 printf("Screen name: %s\n", sess->logininfo.screen_name);
323 if (sess->logininfo.errorcode)
325 printf("Login Error Code 0x%04x\n", sess->logininfo.errorcode);
326 printf("Error URL: %s\n", sess->logininfo.errorurl);
327 aim_conn_close(command->conn);
328 exit(0); /* XXX: should return in order to let the above things get free()'d. */
331 printf("Reg status: %2d\n", sess->logininfo.regstatus);
332 printf("Email: %s\n", sess->logininfo.email);
333 printf("BOS IP: %s\n", sess->logininfo.BOSIP);
335 printf("Closing auth connection...\n");
336 aim_conn_close(command->conn);
337 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP);
340 fprintf(stderr, "faimtest: could not connect to BOS: internal error\n");
342 else if (bosconn->status != 0)
344 fprintf(stderr, "faimtest: could not connect to BOS\n");
348 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0);
349 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_serverready, 0);
350 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0);
351 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0);
352 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, NULL, 0);
353 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0);
354 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0);
355 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
356 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_misses, 0);
357 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0);
358 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_misses, 0);
359 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_misses, 0);
360 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0);
362 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0);
363 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
364 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, faimtest_parse_motd, 0);
365 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie);
370 int faimtest_parse_userinfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
372 struct aim_userinfo_s *userinfo;
373 char *prof_encoding = NULL;
377 va_start(ap, command);
378 userinfo = va_arg(ap, struct aim_userinfo_s *);
379 prof_encoding = va_arg(ap, char *);
380 prof = va_arg(ap, char *);
383 printf("faimtest: userinfo: sn: %s\n", userinfo->sn);
384 printf("faimtest: userinfo: warnlevel: 0x%04x\n", userinfo->warnlevel);
385 printf("faimtest: userinfo: class: 0x%04x = ", userinfo->class);
399 if (userinfo->class & 0x0001)
401 if (userinfo->class & 0x0002)
402 printf("UNKNOWN_BIT2 ");
403 if (userinfo->class & 0x0004)
405 if (userinfo->class & 0x0008)
406 printf("UNKNOWN_BIT4 ");
407 if (userinfo->class & 0x0010)
411 printf("faimtest: userinfo: membersince: %lu\n", userinfo->membersince);
412 printf("faimtest: userinfo: onlinesince: %lu\n", userinfo->onlinesince);
413 printf("faimtest: userinfo: idletime: 0x%04x\n", userinfo->idletime);
415 printf("faimtest: userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
416 printf("faimtest: userinfo: prof: %s\n", prof ? prof : "[none]");
422 * The user-level Incoming ICBM callback.
425 * struct command_rx_struct * command if you feel like doing it yourself
426 * char * srcsn the source name
428 * int warnlevel warning/evil level
429 * int class user class
430 * ulong membersince time_t of date of signup
431 * ulong onsince time_t of date of singon
432 * int idletime min (sec?) idle
433 * u_int icbmflags sets AIM_IMFLAGS_{AWAY,ACK}
436 int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_struct *command, ...)
441 va_start(ap, command);
442 channel = va_arg(ap, int);
445 * Channel 1: Standard Message
449 struct aim_userinfo_s *userinfo;
453 u_short flag1, flag2;
455 userinfo = va_arg(ap, struct aim_userinfo_s *);
456 msg = va_arg(ap, char *);
457 icbmflags = va_arg(ap, u_int);
458 flag1 = va_arg(ap, u_short);
459 flag2 = va_arg(ap, u_short);
462 printf("faimtest: icbm: sn = \"%s\"\n", userinfo->sn);
463 printf("faimtest: icbm: warnlevel = 0x%04x\n", userinfo->warnlevel);
464 printf("faimtest: icbm: class = 0x%04x ", userinfo->class);
465 if (userinfo->class & 0x0010)
467 if (userinfo->class & 0x0001)
469 if (userinfo->class & 0x0004)
472 printf("faimtest: icbm: membersince = %lu\n", userinfo->membersince);
473 printf("faimtest: icbm: onlinesince = %lu\n", userinfo->onlinesince);
474 printf("faimtest: icbm: idletime = 0x%04x\n", userinfo->idletime);
476 printf("faimtest: icbm: icbmflags = ");
477 if (icbmflags & AIM_IMFLAGS_AWAY)
479 if (icbmflags & AIM_IMFLAGS_ACK)
480 printf("ackrequest ");
483 printf("faimtest: icbm: encoding flags = {%04x, %04x}\n", flag1, flag2);
485 printf("faimtest: icbm: message: %s\n", msg);
489 tmpstr = index(msg, '>');
495 if ( (strlen(tmpstr) >= 10) &&
496 (!strncmp(tmpstr, "disconnect", 10)) )
498 aim_send_im(sess, command->conn, "midendian", 0, "ta ta...");
501 else if (strstr(tmpstr, "goodday"))
503 printf("faimtest: icbm: sending response\n");
504 aim_send_im(sess, command->conn, userinfo->sn, 0, "Good day to you too.");
507 else if (!strncmp(tmpstr, "joinchat", 8))
509 aim_chat_join(sess, command->conn, "GoodDay");
515 printf("faimtest: icbm: starting chat...\n");
516 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
518 aim_bos_setidle(sess, command->conn, 0x0ffffffe);
525 * Channel 2: Chat Invitation
527 else if (channel == 2)
529 struct aim_userinfo_s *userinfo;
530 char *roomname,*msg,*encoding,*lang;
531 u_short exchange, instance;
533 userinfo = va_arg(ap, struct aim_userinfo_s *);
534 roomname = va_arg(ap, char *);
535 msg = va_arg(ap, char *);
536 encoding = va_arg(ap, char *);
537 lang = va_arg(ap, char *);
538 exchange = va_arg(ap, u_short);
539 instance = va_arg(ap, u_short);
542 printf("faimtest: chat invitation: source sn = %s\n", userinfo->sn);
543 printf("faimtest: chat invitation: \twarnlevel = 0x%04x\n", userinfo->warnlevel);
544 printf("faimtest: chat invitation: \tclass = 0x%04x ", userinfo->class);
545 if (userinfo->class & 0x0010)
547 if (userinfo->class & 0x0001)
549 if (userinfo->class & 0x0004)
552 /* we dont get membersince on chat invites! */
553 printf("faimtest: chat invitation: \tonlinesince = %lu\n", userinfo->onlinesince);
554 printf("faimtest: chat invitation: \tidletime = 0x%04x\n", userinfo->idletime);
556 printf("faimtest: chat invitation: message = %s\n", msg);
557 printf("faimtest: chat invitation: room name = %s\n", roomname);
558 printf("faimtest: chat invitation: encoding = %s\n", encoding);
559 printf("faimtest: chat invitation: language = %s\n", lang);
560 printf("faimtest: chat invitation: exchange = 0x%04x\n", exchange);
561 printf("faimtest: chat invitation: instance = 0x%04x\n", instance);
564 printf("faimtest does not support channels > 2 (chan = %02x)\n", channel);
565 printf("faimtest: icbm: done with ICBM handling\n");
570 int faimtest_authsvrready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
572 printf("faimtest_authsvrready: called (contype: %d)\n", command->conn->type);
574 /* should just be able to tell it we're ready too... */
575 aim_auth_clientready(sess, command->conn);
579 * This is where you'd really begin changing your password.
580 * However, this callback may get called for reasons other
581 * than you wanting to change your password. You should
582 * probably check that before actually doing it.
584 aim_auth_changepasswd(sess, command->conn, "PWD1", "PWD2");
590 int faimtest_pwdchngdone(struct aim_session_t *sess, struct command_rx_struct *command, ...)
592 printf("PASSWORD CHANGE SUCCESSFUL!!!\n");
596 int faimtest_parse_oncoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
598 struct aim_userinfo_s *userinfo;
601 va_start(ap, command);
602 userinfo = va_arg(ap, struct aim_userinfo_s *);
605 printf("\n%s is now online\n", userinfo->sn);
610 int faimtest_parse_offgoing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
615 va_start(ap, command);
616 sn = va_arg(ap, char *);
619 printf("\n%s has left\n", sn);
624 int faimtest_parse_motd(struct aim_session_t *sess, struct command_rx_struct *command, ...)
630 va_start(ap, command);
631 id = va_arg(ap, u_short);
632 msg = va_arg(ap, char *);
635 printf("faimtest: motd: %s\n", msg);
641 * Handles callbacks for: AIM_CB_RATECHANGE, AIM_CB_USERERROR,
642 * AIM_CB_MISSED_IM, and AIM_CB_MISSED_CALL.
644 int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *command, ...)
649 family = aimutil_get16(command->data+0);
650 subtype= aimutil_get16(command->data+2);
655 if (subtype == 0x000a) /* or AIM_CB_RATECHANGE */
656 printf("\n****STOP SENDING/RECIEVING MESSAGES SO FAST!****\n\n");
659 if (subtype == 0x0001) /* or AIM_CB_USERERROR */
661 u_long snacid = 0x00000000;
663 snacid = aimutil_get32(&command->data[6]);
665 printf("Received unknown error in SNAC family 0x0002 (snacid = %08lx)\n", snacid);
669 if (subtype == 0x0001) /* or AIM_CB_MISSED_IM */
670 printf("\n***LAST IM DIDN\'T MAKE IT BECAUSE THE BUDDY IS NOT ONLINE***\n\n");
671 else if (subtype == 0x000a) /* or AIM_CB_MISSED_CALL */
672 printf("You missed some messages from %s because they were sent too fast\n", &(command->data[13]));
680 int faimtest_parse_login(struct aim_session_t *sess, struct command_rx_struct *command, ...)
682 struct client_info_s info = {"FAIMtest (Hi guys!)", 3, 5, 1670, "us", "en"};
683 u_char authcookie[11];
686 for (i = 0; i < (int)command->data[11]; i++)
687 authcookie[i] = command->data[12+i];
688 authcookie[i] = '\0';
690 printf("faimtest: logincookie: %s\n", authcookie);
692 aim_send_login(sess, command->conn, FAIMTEST_SCREENNAME, FAIMTEST_PASSWORD, &info);