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 "PASS"
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_auth_success(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, ...);
67 struct aim_session_t aimsess;
68 struct client_info_s info = {"FAIMtest (Hi guys!)", 3, 90, 42, "us", "en"};
69 struct aim_conn_t *authconn = NULL;
70 int stayconnected = 1;
72 aim_session_init(&aimsess);
75 * (I used a goto-based loop here because n wanted quick proof
76 * that reconnecting without restarting was actually possible...)
79 authconn = aim_newconn(&aimsess, AIM_CONN_TYPE_AUTH, "127.0.0.1:5190");
83 fprintf(stderr, "faimtest: internal connection error while in aim_login. bailing out.\n");
86 else if (authconn->fd == -1)
88 if (authconn->status & AIM_CONN_STATUS_RESOLVERR)
89 fprintf(stderr, "faimtest: could not resolve authorizer name\n");
90 else if (authconn->status & AIM_CONN_STATUS_CONNERR)
91 fprintf(stderr, "faimtest: could not connect to authorizer\n");
96 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_GEN, AIM_CB_GEN_ERROR, faimtest_auth_error, 0);
97 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_AUTHSUCCESS, faimtest_auth_success, 0);
98 aim_conn_addhandler(&aimsess, authconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_authsvrready, 0);
99 aim_send_login(&aimsess, authconn, FAIMTEST_SCREENNAME, FAIMTEST_PASSWORD, &info);
102 while (aim_select(&aimsess, NULL) > (struct aim_conn_t *)0)
104 if (aimsess.queue_outgoing)
105 aim_tx_flushqueue(&aimsess);
107 if (aim_get_command(&aimsess) < 0)
109 printf("\afaimtest: connection error!\n");
112 aim_rxdispatch(&aimsess);
116 printf("AIM just decided we didn't need to be here anymore, closing up.,,\n");
118 /* close up all connections, dead or no */
119 aim_logoff(&aimsess);
123 printf("\nTrying to reconnect in 2 seconds...\n");
132 int faimtest_serverready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
134 switch (command->conn->type)
136 case AIM_CONN_TYPE_BOS:
137 aim_bos_reqrate(sess, command->conn); /* request rate info */
138 aim_bos_ackrateresp(sess, command->conn); /* ack rate info response -- can we say timing? */
139 aim_bos_setprivacyflags(sess, command->conn, 0x00000003);
142 aim_bos_reqpersonalinfo(sess, command->conn);
145 /* Request advertisement service -- see comment in handleredirect */
146 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_ADS);
149 aim_bos_reqrights(sess, command->conn);
150 aim_bos_reqbuddyrights(sess, command->conn);
151 aim_bos_reqlocaterights(sess, command->conn);
152 aim_bos_reqicbmparaminfo(sess, command->conn);
155 /* set group permissions */
156 aim_bos_setgroupperm(sess, command->conn, 0x1f);
157 fprintf(stderr, "faimtest: done with BOS ServerReady\n");
159 case AIM_CONN_TYPE_CHATNAV:
160 fprintf(stderr, "faimtest: chatnav: got server ready\n");
163 fprintf(stderr, "faimtest: unknown connection type on Server Ready\n");
171 This, of course, handles Service Redirects from OSCAR.
173 Should get passed in the following:
174 struct command_rx_struct *command
177 the destination service ID
179 the IP address of the service's server
183 int faimtest_handleredirect(struct aim_session_t *sess, struct command_rx_struct *command, ...)
190 /* this is the new buddy list */
191 char buddies[] = "Buddy1&Buddy2&";
192 /* this is the new profile */
193 char profile[] = "Hello";
195 va_start(ap, command);
196 serviceid = va_arg(ap, int);
197 ip = va_arg(ap, char *);
198 cookie = va_arg(ap, char *);
203 case 0x0005: /* Advertisements */
205 * The craziest explanation yet as to why we finish logging in when
206 * we get the advertisements redirect, of which we don't use anyway....
210 /* send the buddy list and profile (required, even if empty) */
211 aim_bos_setbuddylist(sess, command->conn, buddies);
212 aim_bos_setprofile(sess, command->conn, profile);
214 /* send final login command (required) */
215 aim_bos_clientready(sess, command->conn); /* tell BOS we're ready to go live */
217 /* you should now be ready to go */
218 printf("\nYou are now officially online.\n");
221 case 0x0007: /* Authorizer */
223 struct aim_conn_t *tstconn;
224 /* Open a connection to the Auth */
225 tstconn = aim_newconn(sess, AIM_CONN_TYPE_AUTH, ip);
226 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR) )
227 fprintf(stderr, "faimtest: unable to reconnect with authorizer\n");
229 /* Send the cookie to the Auth */
230 aim_auth_sendcookie(sess, tstconn, cookie);
234 case 0x000d: /* ChatNav */
236 struct aim_conn_t *tstconn = NULL;
237 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHATNAV, ip);
238 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
240 fprintf(stderr, "faimtest: unable to connect to chatnav server\n");
243 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_CTN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
244 aim_conn_addhandler(sess, tstconn, AIM_CB_FAM_GEN, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
245 aim_auth_sendcookie(sess, tstconn, cookie);
246 fprintf(stderr, "\achatnav: connected\n");
249 case 0x000e: /* Chat */
252 struct aim_conn_t *tstconn = NULL;
253 tstconn = aim_newconn(sess, AIM_CONN_TYPE_CHAT, ip);
254 if ( (tstconn==NULL) || (tstconn->status >= AIM_CONN_STATUS_RESOLVERR))
256 fprintf(stderr, "faimtest: unable to connect to chat server\n");
259 aim_auth_sendcookie(sess, aim_getconn_type(sess, AIM_CONN_TYPE_CHAT), cookie);
260 fprintf(stderr, "\achat: connected\n");
265 printf("uh oh... got redirect for unknown service 0x%04x!!\n", serviceid);
272 int faimtest_auth_error(struct aim_session_t *sess, struct command_rx_struct *command, ...)
278 va_start(ap, command);
279 printf("Screen name: %s\n", sess->logininfo.screen_name);
280 errorurl = va_arg(ap, char *);
281 printf("Error URL: %s\n", errorurl);
282 errorcode = va_arg(ap, short);
283 printf("Error code: 0x%02x\n", errorcode);
286 aim_conn_close(aim_getconn_type(sess, AIM_CONN_TYPE_AUTH));
292 int faimtest_auth_success(struct aim_session_t *sess, struct command_rx_struct *command, ...)
294 struct aim_conn_t *bosconn = NULL;
296 printf("Screen name: %s\n", sess->logininfo.screen_name);
297 printf("Reg status: %2d\n", sess->logininfo.regstatus);
298 printf("Email: %s\n", sess->logininfo.email);
299 printf("Cookie len: %d\n", sizeof(sess->logininfo.cookie));
300 printf("BOS IP: %s\n", sess->logininfo.BOSIP);
302 printf("Closing auth connection...\n");
303 aim_conn_close(command->conn);
304 bosconn = aim_newconn(sess, AIM_CONN_TYPE_BOS, sess->logininfo.BOSIP);
307 fprintf(stderr, "faimtest: could not connect to BOS: internal error\n");
309 else if (bosconn->status != 0)
311 fprintf(stderr, "faimtest: could not connect to BOS\n");
315 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_ACK, AIM_CB_ACK_ACK, NULL, 0);
316 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_SERVERREADY, faimtest_serverready, 0);
317 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATEINFO, NULL, 0);
318 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_REDIRECT, faimtest_handleredirect, 0);
319 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_MOTD, NULL, 0);
320 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_STS, AIM_CB_STS_SETREPORTINTERVAL, NULL, 0);
321 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_ONCOMING, faimtest_parse_oncoming, 0);
322 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_BUD, AIM_CB_BUD_OFFGOING, faimtest_parse_offgoing, 0);
323 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_INCOMING, faimtest_parse_incoming_im, 0);
324 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_ERROR, faimtest_parse_misses, 0);
325 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_MISSEDCALL, faimtest_parse_misses, 0);
326 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_GEN, AIM_CB_GEN_RATECHANGE, faimtest_parse_misses, 0);
327 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_MSG, AIM_CB_MSG_ERROR, faimtest_parse_misses, 0);
328 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_LOC, AIM_CB_LOC_USERINFO, faimtest_parse_userinfo, 0);
330 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_CTN, AIM_CB_CTN_DEFAULT, aim_parse_unknown, 0);
331 aim_conn_addhandler(sess, bosconn, AIM_CB_FAM_SPECIAL, AIM_CB_SPECIAL_DEFAULT, aim_parse_unknown, 0);
332 aim_auth_sendcookie(sess, bosconn, sess->logininfo.cookie);
337 int faimtest_parse_userinfo(struct aim_session_t *sess, struct command_rx_struct *command, ...)
339 struct aim_userinfo_s *userinfo;
340 char *prof_encoding = NULL;
344 va_start(ap, command);
345 userinfo = va_arg(ap, struct aim_userinfo_s *);
346 prof_encoding = va_arg(ap, char *);
347 prof = va_arg(ap, char *);
350 printf("faimtest: userinfo: sn: %s\n", userinfo->sn);
351 printf("faimtest: userinfo: warnlevel: 0x%04x\n", userinfo->warnlevel);
352 printf("faimtest: userinfo: class: 0x%04x = ", userinfo->class);
366 if (userinfo->class & 0x0001)
368 if (userinfo->class & 0x0002)
369 printf("UNKNOWN_BIT2 ");
370 if (userinfo->class & 0x0004)
372 if (userinfo->class & 0x0008)
373 printf("UNKNOWN_BIT4 ");
374 if (userinfo->class & 0x0010)
378 printf("faimtest: userinfo: membersince: %lu\n", userinfo->membersince);
379 printf("faimtest: userinfo: onlinesince: %lu\n", userinfo->onlinesince);
380 printf("faimtest: userinfo: idletime: 0x%04x\n", userinfo->idletime);
382 printf("faimtest: userinfo: profile_encoding: %s\n", prof_encoding ? prof_encoding : "[none]");
383 printf("faimtest: userinfo: prof: %s\n", prof ? prof : "[none]");
389 * The user-level Incoming ICBM callback.
392 * struct command_rx_struct * command if you feel like doing it yourself
393 * char * srcsn the source name
395 * int warnlevel warning/evil level
396 * int class user class
397 * ulong membersince time_t of date of signup
398 * ulong onsince time_t of date of singon
399 * int idletime min (sec?) idle
400 * u_int icbmflags sets AIM_IMFLAGS_{AWAY,ACK}
403 int faimtest_parse_incoming_im(struct aim_session_t *sess, struct command_rx_struct *command, ...)
405 struct aim_userinfo_s *userinfo;
410 u_short flag1, flag2;
412 va_start(ap, command);
413 userinfo = va_arg(ap, struct aim_userinfo_s *);
414 msg = va_arg(ap, char *);
415 icbmflags = va_arg(ap, u_int);
416 flag1 = va_arg(ap, u_short);
417 flag2 = va_arg(ap, u_short);
420 printf("faimtest: icbm: sn = \"%s\"\n", userinfo->sn);
421 printf("faimtest: icbm: warnlevel = 0x%04x\n", userinfo->warnlevel);
422 printf("faimtest: icbm: class = 0x%04x ", userinfo->class);
423 if (userinfo->class & 0x0010)
425 else if (userinfo->class & 0x0001)
427 else if (userinfo->class & 0x0004)
430 printf("(UNKNOWN)\n");
431 printf("faimtest: icbm: membersince = %lu\n", userinfo->membersince);
432 printf("faimtest: icbm: onlinesince = %lu\n", userinfo->onlinesince);
433 printf("faimtest: icbm: idletime = 0x%04x\n", userinfo->idletime);
435 printf("faimtest: icbm: icbmflags = ");
436 if (icbmflags & AIM_IMFLAGS_AWAY)
438 if (icbmflags & AIM_IMFLAGS_ACK)
439 printf("ackrequest ");
442 printf("faimtest: icbm: encoding flags = {%04x, %04x}\n", flag1, flag2);
444 printf("faimtest: icbm: message: %s\n", msg);
448 tmpstr = index(msg, '>');
454 if ( (strlen(tmpstr) >= 10) &&
455 (!strncmp(tmpstr, "disconnect", 10)) )
457 aim_send_im(sess, command->conn, "midendian", 0, "ta ta...");
460 else if (strstr(tmpstr, "goodday"))
462 printf("faimtest: icbm: sending response\n");
463 aim_send_im(sess, command->conn, userinfo->sn, 0, "Good day to you too.");
466 else if (!strncmp(tmpstr, "joinchat", 8))
468 aim_chat_join(sess, command->conn, "GoodDay");
474 printf("faimtest: icbm: starting chat...\n");
475 aim_bos_reqservice(sess, command->conn, AIM_CONN_TYPE_CHATNAV);
477 aim_bos_setidle(sess, command->conn, 0x0ffffffe);
483 printf("faimtest: icbm: done with ICBM handling\n");
488 int faimtest_authsvrready(struct aim_session_t *sess, struct command_rx_struct *command, ...)
490 printf("faimtest_authsvrready: called (contype: %d)\n", command->conn->type);
492 /* should just be able to tell it we're ready too... */
493 aim_auth_clientready(sess, command->conn);
497 * This is where you'd really begin changing your password.
498 * However, this callback may get called for reasons other
499 * than you wanting to change your password. You should
500 * probably check that before actually doing it.
502 aim_auth_changepasswd(sess, command->conn, "PWD1", "PWD2");
508 int faimtest_pwdchngdone(struct aim_session_t *sess, struct command_rx_struct *command, ...)
510 printf("PASSWORD CHANGE SUCCESSFUL!!!\n");
514 int faimtest_parse_oncoming(struct aim_session_t *sess, struct command_rx_struct *command, ...)
516 struct aim_userinfo_s *userinfo;
519 va_start(ap, command);
520 userinfo = va_arg(ap, struct aim_userinfo_s *);
523 printf("\n%s is now online\n", userinfo->sn);
528 int faimtest_parse_offgoing(struct aim_session_t *sess, struct command_rx_struct *command, ...)
533 va_start(ap, command);
534 sn = va_arg(ap, char *);
537 printf("\n%s has left\n", sn);
544 * Handles callbacks for: AIM_CB_RATECHANGE, AIM_CB_USERERROR,
545 * AIM_CB_MISSED_IM, and AIM_CB_MISSED_CALL.
547 int faimtest_parse_misses(struct aim_session_t *sess, struct command_rx_struct *command, ...)
552 family = aimutil_get16(command->data+0);
553 subtype= aimutil_get16(command->data+2);
558 if (subtype == 0x000a) /* or AIM_CB_RATECHANGE */
559 printf("\n****STOP SENDING/RECIEVING MESSAGES SO FAST!****\n\n");
562 if (subtype == 0x0001) /* or AIM_CB_USERERROR */
564 u_long snacid = 0x00000000;
566 snacid = aimutil_get32(&command->data[6]);
568 printf("Received unknown error in SNAC family 0x0002 (snacid = %08lx)\n", snacid);
572 if (subtype == 0x0001) /* or AIM_CB_MISSED_IM */
573 printf("\n***LAST IM DIDN\'T MAKE IT BECAUSE THE BUDDY IS NOT ONLINE***\n\n");
574 else if (subtype == 0x000a) /* or AIM_CB_MISSED_CALL */
575 printf("You missed some messages from %s because they were sent too fast\n", &(command->data[13]));