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 * -----------------------------------------------------------
47 #define FAIMTEST_SCREENNAME "SCREENNAME"
48 #define FAIMTEST_PASSWORD "PASSWORD"
52 int faimtest_parse_oncoming(struct aim_session_t *, struct command_rx_struct *, ...);
53 int faimtest_parse_offgoing(struct aim_session_t *, struct command_rx_struct *, ...);
54 int faimtest_parse_login_phase3d_f(struct aim_session_t *, struct command_rx_struct *, ...);
55 int faimtest_auth_error(struct aim_session_t *, struct command_rx_struct *, ...);
56 int faimtest_parse_authresp(struct aim_session_t *, struct command_rx_struct *, ...);
57 int faimtest_parse_incoming_im(struct aim_session_t *, struct command_rx_struct *command, ...);
58 int faimtest_parse_userinfo(struct aim_session_t *, struct command_rx_struct *command, ...);
59 int faimtest_handleredirect(struct aim_session_t *, struct command_rx_struct *command, ...);
60 int faimtest_authsvrready(struct aim_session_t *, struct command_rx_struct *command, ...);
61 int faimtest_pwdchngdone(struct aim_session_t *, struct command_rx_struct *command, ...);
62 int faimtest_serverready(struct aim_session_t *, struct command_rx_struct *command, ...);
63 int faimtest_parse_misses(struct aim_session_t *, struct command_rx_struct *command, ...);
64 int faimtest_parse_motd(struct aim_session_t *, struct command_rx_struct *command, ...);
65 int faimtest_parse_login(struct aim_session_t *, struct command_rx_struct *command, ...);
69 struct aim_session_t aimsess;
70 struct aim_conn_t *authconn = NULL;
71 int stayconnected = 1;
72 struct client_info_s info = {"FAIMtest (Hi guys!)", 3, 5, 1670, "us", "en"};
74 aim_session_init(&aimsess);
77 * (I used a goto-based loop here because n wanted quick proof
78 * that reconnecting without restarting was actually possible...)
81 authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, FAIM_LOGIN_SERVER);
85 fprintf(stderr, "faimtest: internal connection error while in aim_login. bailing out.\n");
88 else if (authconn->fd == -1)
90 if (authconn->status & AIM_CONN_STATUS_RESOLVERR)
91 fprintf(stderr, "faimtest: could not resolve authorizer name\n");
92 else if (authconn->status & AIM_CONN_STATUS_CONNERR)
93 fprintf(stderr, "faimtest: could not connect to authorizer\n");
99 /* new login code -- not default -- pending new password encryption algo */
100 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0007, faimtest_parse_login, 0);
101 aim_conn_addhandler(&aimsess, authconn, 0x0017, 0x0003, faimtest_parse_authresp, 0);
103 aim_sendconnack(&aimsess, authconn);
104 aim_request_login(&aimsess, authconn, FAIMTEST_SCREENNAME);
106 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_AUTHSUCCESS, faimtest_parse_authresp, 0);
107 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_authsvrready, 0);
108 aim_send_login(&aimsess, authconn, FAIMTEST_SCREENNAME, FAIMTEST_PASSWORD, &info);
113 while (aim_select(&aimsess, NULL) > (struct aim_conn_t *)0)
115 if (aimsess.queue_outgoing)
116 aim_tx_flushqueue(&aimsess);
118 if (aim_get_command(&aimsess) < 0)
120 printf("\afaimtest: connection error!\n");
123 aim_rxdispatch(&aimsess);
127 printf("AIM just decided we didn't need to be here anymore, closing up.,,\n");
129 /* close up all connections, dead or no */
130 aim_logoff(&aimsess);
134 printf("\nTrying to reconnect in 2 seconds...\n");
143 int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
145 switch (command->conn->type)
147 case AIM_CONN_TYPE_BOS:
148 aim_bos_reqrate(sess, command->conn); /* request rate info */
149 aim_bos_ackrateresp(sess, command->conn); /* ack rate info response -- can we say timing? */
150 aim_bos_setprivacyflags(sess, command->conn, 0x00000003);
153 aim_bos_reqpersonalinfo(sess, command->conn);
156 /* Request advertisement service -- see comment in handleredirect */
157 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_ADS);
158 aim_setversions(sess, command->conn);
161 aim_bos_reqrights(sess, command->conn);
162 aim_bos_reqbuddyrights(sess, command->conn);
163 aim_bos_reqlocaterights(sess, command->conn);
164 aim_bos_reqicbmparaminfo(sess, command->conn);
167 /* set group permissions */
168 aim_bos_setgroupperm(sess, command->conn, 0x1f);
169 fprintf(stderr, "faimtest: done with BOS ServerReady\n");
171 case AIM_CONN_TYPE_CHATNAV:
172 fprintf(stderr, "faimtest: chatnav: got server ready\n");
175 fprintf(stderr, "faimtest: unknown connection type on Server Ready\n");
183 This, of course, handles Service Redirects from OSCAR.
185 Should get passed in the following:
186 struct command_rx_struct *command
189 the destination service ID
191 the IP address of the service's server
195 int faimtest_handleredirect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
202 /* this is the new buddy list */
203 char buddies[] = "Buddy1&Buddy2&";
204 /* this is the new profile */
205 char profile[] = "Hello";
207 va_start(ap, command);
208 serviceid = va_arg(ap, int);
209 ip = va_arg(ap, char *);
210 cookie = va_arg(ap, char *);
215 case 0x0005: /* Advertisements */
217 * The craziest explanation yet as to why we finish logging in when
218 * we get the advertisements redirect, of which we don't use anyway....
222 /* send the buddy list and profile (required, even if empty) */
223 aim_bos_setbuddylist(sess, command->conn, buddies);
224 aim_bos_setprofile(sess, command->conn, profile);
226 /* send final login command (required) */
227 aim_bos_clientready(sess, command->conn); /* tell BOS we're ready to go live */
229 /* you should now be ready to go */
230 printf("\nYou are now officially online.\n");
233 case 0x0007: /* Authorizer */
235 struct aim_conn_t *tstconn;
236 /* Open a connection to the Auth */
237 tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
238 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR) )
239 fprintf(stderr, "faimtest: unable to reconnect with authorizer\n");
241 /* Send the cookie to the Auth */
242 aim_auth_sendcookie(sess, tstconn, cookie);
246 case 0x000d: /* ChatNav */
248 struct aim_conn_t *tstconn = NULL;
249 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, ip);
250 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
252 fprintf(stderr, "faimtest: unable to connect to chatnav server\n");
255 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_CTN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
256 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
257 aim_auth_sendcookie(sess, tstconn, cookie);
258 fprintf(stderr, "\achatnav: connected\n");
261 case 0x000e: /* Chat */
264 struct aim_conn_t *tstconn = NULL;
265 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
266 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
268 fprintf(stderr, "faimtest: unable to connect to chat server\n");
271 aim_auth_sendcookie(sess, aim_getconn_type(sess, AIM_CONN_TYPE_CHAT), cookie);
272 fprintf(stderr, "\achat: connected\n");
277 printf("uh oh... got redirect for unknown service 0x%04x!!\n", serviceid);
285 int faimtest_auth_error(struct aim_session_t *sess, struct command_rx_struct *command, ...)
291 va_start(ap, command);
292 printf("Screen name: %s\n", sess->logininfo.screen_name);
293 errorurl = va_arg(ap, char *);
294 printf("Error URL: %s\n", errorurl);
295 errorcode = va_arg(ap, short);
296 printf("Error code: 0x%02x\n", errorcode);
299 aim_conn_close(aim_getconn_type(sess, AIM_CONN_TYPE_AUTH));
306 int faimtest_parse_authresp(struct aim_session_t *sess, struct command_rx_struct *command, ...)
308 struct aim_conn_t *bosconn = NULL;
311 printf("Screen name: %s\n", sess->logininfo.screen_name);
316 if (sess->logininfo.errorcode)
318 printf("Login Error Code 0x%04x\n", sess->logininfo.errorcode);
319 printf("Error URL: %s\n", sess->logininfo.errorurl);
320 aim_conn_close(command->conn);
321 exit(0); /* XXX: should return in order to let the above things get free()'d. */
324 printf("Reg status: %2d\n", sess->logininfo.regstatus);
325 printf("Email: %s\n", sess->logininfo.email);
326 printf("BOS IP: %s\n", sess->logininfo.BOSIP);
328 printf("Closing auth connection...\n");
329 aim_conn_close(command->conn);
330 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP);
333 fprintf(stderr, "faimtest: could not connect to BOS: internal error\n");
335 else if (bosconn->status != 0)
337 fprintf(stderr, "faimtest: could not connect to BOS\n");
341 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0);
342 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_serverready, 0);
343 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0);
344 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0);
345 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, NULL, 0);
346 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0);
347 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0);
348 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
349 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_misses, 0);
350 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0);
351 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_misses, 0);
352 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_misses, 0);
353 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0);
355 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0);
356 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
357 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, faimtest_parse_motd, 0);
358 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie);
363 int faimtest_parse_userinfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
365 struct aim_userinfo_s *userinfo;
366 char *prof_encoding = NULL;
370 va_start(ap, command);
371 userinfo = va_arg(ap, struct aim_userinfo_s *);
372 prof_encoding = va_arg(ap, char *);
373 prof = va_arg(ap, char *);
376 printf("faimtest: userinfo: sn: %s\n", userinfo->sn);
377 printf("faimtest: userinfo: warnlevel: 0x%04x\n", userinfo->warnlevel);
378 printf("faimtest: userinfo: class: 0x%04x = ", userinfo->class);
392 if (userinfo->class & 0x0001)
394 if (userinfo->class & 0x0002)
395 printf("UNKNOWN_BIT2 ");
396 if (userinfo->class & 0x0004)
398 if (userinfo->class & 0x0008)
399 printf("UNKNOWN_BIT4 ");
400 if (userinfo->class & 0x0010)
404 printf("faimtest: userinfo: membersince: %lu\n", userinfo->membersince);
405 printf("faimtest: userinfo: onlinesince: %lu\n", userinfo->onlinesince);
406 printf("faimtest: userinfo: idletime: 0x%04x\n", userinfo->idletime);
408 printf("faimtest: userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
409 printf("faimtest: userinfo: prof: %s\n", prof ? prof : "[none]");
415 * The user-level Incoming ICBM callback.
418 * struct command_rx_struct * command if you feel like doing it yourself
419 * char * srcsn the source name
421 * int warnlevel warning/evil level
422 * int class user class
423 * ulong membersince time_t of date of signup
424 * ulong onsince time_t of date of singon
425 * int idletime min (sec?) idle
426 * u_int icbmflags sets AIM_IMFLAGS_{AWAY,ACK}
429 int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_struct *command, ...)
431 struct aim_userinfo_s *userinfo;
436 u_short flag1, flag2;
438 va_start(ap, command);
439 userinfo = va_arg(ap, struct aim_userinfo_s *);
440 msg = va_arg(ap, char *);
441 icbmflags = va_arg(ap, u_int);
442 flag1 = va_arg(ap, u_short);
443 flag2 = va_arg(ap, u_short);
446 printf("faimtest: icbm: sn = \"%s\"\n", userinfo->sn);
447 printf("faimtest: icbm: warnlevel = 0x%04x\n", userinfo->warnlevel);
448 printf("faimtest: icbm: class = 0x%04x ", userinfo->class);
449 if (userinfo->class & 0x0010)
451 else if (userinfo->class & 0x0001)
453 else if (userinfo->class & 0x0004)
456 printf("(UNKNOWN)\n");
457 printf("faimtest: icbm: membersince = %lu\n", userinfo->membersince);
458 printf("faimtest: icbm: onlinesince = %lu\n", userinfo->onlinesince);
459 printf("faimtest: icbm: idletime = 0x%04x\n", userinfo->idletime);
461 printf("faimtest: icbm: icbmflags = ");
462 if (icbmflags & AIM_IMFLAGS_AWAY)
464 if (icbmflags & AIM_IMFLAGS_ACK)
465 printf("ackrequest ");
468 printf("faimtest: icbm: encoding flags = {%04x, %04x}\n", flag1, flag2);
470 printf("faimtest: icbm: message: %s\n", msg);
474 tmpstr = index(msg, '>');
480 if ( (strlen(tmpstr) >= 10) &&
481 (!strncmp(tmpstr, "disconnect", 10)) )
483 aim_send_im(sess, command->conn, "midendian", 0, "ta ta...");
486 else if (strstr(tmpstr, "goodday"))
488 printf("faimtest: icbm: sending response\n");
489 aim_send_im(sess, command->conn, userinfo->sn, 0, "Good day to you too.");
492 else if (!strncmp(tmpstr, "joinchat", 8))
494 aim_chat_join(sess, command->conn, "GoodDay");
500 printf("faimtest: icbm: starting chat...\n");
501 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
503 aim_bos_setidle(sess, command->conn, 0x0ffffffe);
509 printf("faimtest: icbm: done with ICBM handling\n");
514 int faimtest_authsvrready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
516 printf("faimtest_authsvrready: called (contype: %d)\n", command->conn->type);
518 /* should just be able to tell it we're ready too... */
519 aim_auth_clientready(sess, command->conn);
523 * This is where you'd really begin changing your password.
524 * However, this callback may get called for reasons other
525 * than you wanting to change your password. You should
526 * probably check that before actually doing it.
528 aim_auth_changepasswd(sess, command->conn, "PWD1", "PWD2");
534 int faimtest_pwdchngdone(struct aim_session_t *sess, struct command_rx_struct *command, ...)
536 printf("PASSWORD CHANGE SUCCESSFUL!!!\n");
540 int faimtest_parse_oncoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
542 struct aim_userinfo_s *userinfo;
545 va_start(ap, command);
546 userinfo = va_arg(ap, struct aim_userinfo_s *);
549 printf("\n%s is now online\n", userinfo->sn);
554 int faimtest_parse_offgoing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
559 va_start(ap, command);
560 sn = va_arg(ap, char *);
563 printf("\n%s has left\n", sn);
568 int faimtest_parse_motd(struct aim_session_t *sess, struct command_rx_struct *command, ...)
574 va_start(ap, command);
575 id = va_arg(ap, u_short);
576 msg = va_arg(ap, char *);
579 printf("faimtest: motd: %s\n", msg);
585 * Handles callbacks for: AIM_CB_RATECHANGE, AIM_CB_USERERROR,
586 * AIM_CB_MISSED_IM, and AIM_CB_MISSED_CALL.
588 int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *command, ...)
593 family = aimutil_get16(command->data+0);
594 subtype= aimutil_get16(command->data+2);
599 if (subtype == 0x000a) /* or AIM_CB_RATECHANGE */
600 printf("\n****STOP SENDING/RECIEVING MESSAGES SO FAST!****\n\n");
603 if (subtype == 0x0001) /* or AIM_CB_USERERROR */
605 u_long snacid = 0x00000000;
607 snacid = aimutil_get32(&command->data[6]);
609 printf("Received unknown error in SNAC family 0x0002 (snacid = %08lx)\n", snacid);
613 if (subtype == 0x0001) /* or AIM_CB_MISSED_IM */
614 printf("\n***LAST IM DIDN\'T MAKE IT BECAUSE THE BUDDY IS NOT ONLINE***\n\n");
615 else if (subtype == 0x000a) /* or AIM_CB_MISSED_CALL */
616 printf("You missed some messages from %s because they were sent too fast\n", &(command->data[13]));
624 int faimtest_parse_login(struct aim_session_t *sess, struct command_rx_struct *command, ...)
626 struct client_info_s info = {"FAIMtest (Hi guys!)", 3, 5, 1670, "us", "en"};
627 u_char authcookie[11];
630 for (i = 0; i < (int)command->data[11]; i++)
631 authcookie[i] = command->data[12+i];
632 authcookie[i] = '\0';
634 printf("faimtest: logincookie: %s\n", authcookie);
636 aim_send_login(sess, command->conn, FAIMTEST_SCREENNAME, FAIMTEST_PASSWORD, &info);